2
0

pdf_viewer.js 223 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 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. })(globalThis, () => {
  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.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  42. var _ui_utils = __w_pdfjs_require__(2);
  43. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  44. const LinkTarget = {
  45. NONE: 0,
  46. SELF: 1,
  47. BLANK: 2,
  48. PARENT: 3,
  49. TOP: 4
  50. };
  51. exports.LinkTarget = LinkTarget;
  52. function addLinkAttributes(link, {
  53. url,
  54. target,
  55. rel,
  56. enabled = true
  57. } = {}) {
  58. if (!url || typeof url !== "string") {
  59. throw new Error('A valid "url" parameter must provided.');
  60. }
  61. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  62. if (enabled) {
  63. link.href = link.title = urlNullRemoved;
  64. } else {
  65. link.href = "";
  66. link.title = `Disabled: ${urlNullRemoved}`;
  67. link.onclick = () => {
  68. return false;
  69. };
  70. }
  71. let targetStr = "";
  72. switch (target) {
  73. case LinkTarget.NONE:
  74. break;
  75. case LinkTarget.SELF:
  76. targetStr = "_self";
  77. break;
  78. case LinkTarget.BLANK:
  79. targetStr = "_blank";
  80. break;
  81. case LinkTarget.PARENT:
  82. targetStr = "_parent";
  83. break;
  84. case LinkTarget.TOP:
  85. targetStr = "_top";
  86. break;
  87. }
  88. link.target = targetStr;
  89. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  90. }
  91. class PDFLinkService {
  92. #pagesRefCache = new Map();
  93. constructor({
  94. eventBus,
  95. externalLinkTarget = null,
  96. externalLinkRel = null,
  97. ignoreDestinationZoom = false
  98. } = {}) {
  99. this.eventBus = eventBus;
  100. this.externalLinkTarget = externalLinkTarget;
  101. this.externalLinkRel = externalLinkRel;
  102. this.externalLinkEnabled = true;
  103. this._ignoreDestinationZoom = ignoreDestinationZoom;
  104. this.baseUrl = null;
  105. this.pdfDocument = null;
  106. this.pdfViewer = null;
  107. this.pdfHistory = null;
  108. }
  109. setDocument(pdfDocument, baseUrl = null) {
  110. this.baseUrl = baseUrl;
  111. this.pdfDocument = pdfDocument;
  112. this.#pagesRefCache.clear();
  113. }
  114. setViewer(pdfViewer) {
  115. this.pdfViewer = pdfViewer;
  116. }
  117. setHistory(pdfHistory) {
  118. this.pdfHistory = pdfHistory;
  119. }
  120. get pagesCount() {
  121. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  122. }
  123. get page() {
  124. return this.pdfViewer.currentPageNumber;
  125. }
  126. set page(value) {
  127. this.pdfViewer.currentPageNumber = value;
  128. }
  129. get rotation() {
  130. return this.pdfViewer.pagesRotation;
  131. }
  132. set rotation(value) {
  133. this.pdfViewer.pagesRotation = value;
  134. }
  135. get isInPresentationMode() {
  136. return this.pdfViewer.isInPresentationMode;
  137. }
  138. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  139. const destRef = explicitDest[0];
  140. let pageNumber;
  141. if (typeof destRef === "object" && destRef !== null) {
  142. pageNumber = this._cachedPageNumber(destRef);
  143. if (!pageNumber) {
  144. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  145. this.cachePageRef(pageIndex + 1, destRef);
  146. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  147. }).catch(() => {
  148. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  149. });
  150. return;
  151. }
  152. } else if (Number.isInteger(destRef)) {
  153. pageNumber = destRef + 1;
  154. } else {
  155. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  156. return;
  157. }
  158. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  159. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  160. return;
  161. }
  162. if (this.pdfHistory) {
  163. this.pdfHistory.pushCurrentPosition();
  164. this.pdfHistory.push({
  165. namedDest,
  166. explicitDest,
  167. pageNumber
  168. });
  169. }
  170. this.pdfViewer.scrollPageIntoView({
  171. pageNumber,
  172. destArray: explicitDest,
  173. ignoreDestinationZoom: this._ignoreDestinationZoom
  174. });
  175. }
  176. async goToDestination(dest) {
  177. if (!this.pdfDocument) {
  178. return;
  179. }
  180. let namedDest, explicitDest;
  181. if (typeof dest === "string") {
  182. namedDest = dest;
  183. explicitDest = await this.pdfDocument.getDestination(dest);
  184. } else {
  185. namedDest = null;
  186. explicitDest = await dest;
  187. }
  188. if (!Array.isArray(explicitDest)) {
  189. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  190. return;
  191. }
  192. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  193. }
  194. goToPage(val) {
  195. if (!this.pdfDocument) {
  196. return;
  197. }
  198. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  199. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  200. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  201. return;
  202. }
  203. if (this.pdfHistory) {
  204. this.pdfHistory.pushCurrentPosition();
  205. this.pdfHistory.pushPage(pageNumber);
  206. }
  207. this.pdfViewer.scrollPageIntoView({
  208. pageNumber
  209. });
  210. }
  211. addLinkAttributes(link, url, newWindow = false) {
  212. addLinkAttributes(link, {
  213. url,
  214. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  215. rel: this.externalLinkRel,
  216. enabled: this.externalLinkEnabled
  217. });
  218. }
  219. getDestinationHash(dest) {
  220. if (typeof dest === "string") {
  221. if (dest.length > 0) {
  222. return this.getAnchorUrl("#" + escape(dest));
  223. }
  224. } else if (Array.isArray(dest)) {
  225. const str = JSON.stringify(dest);
  226. if (str.length > 0) {
  227. return this.getAnchorUrl("#" + escape(str));
  228. }
  229. }
  230. return this.getAnchorUrl("");
  231. }
  232. getAnchorUrl(anchor) {
  233. return (this.baseUrl || "") + anchor;
  234. }
  235. setHash(hash) {
  236. if (!this.pdfDocument) {
  237. return;
  238. }
  239. let pageNumber, dest;
  240. if (hash.includes("=")) {
  241. const params = (0, _ui_utils.parseQueryString)(hash);
  242. if (params.has("search")) {
  243. this.eventBus.dispatch("findfromurlhash", {
  244. source: this,
  245. query: params.get("search").replace(/"/g, ""),
  246. phraseSearch: params.get("phrase") === "true"
  247. });
  248. }
  249. if (params.has("page")) {
  250. pageNumber = params.get("page") | 0 || 1;
  251. }
  252. if (params.has("zoom")) {
  253. const zoomArgs = params.get("zoom").split(",");
  254. const zoomArg = zoomArgs[0];
  255. const zoomArgNumber = parseFloat(zoomArg);
  256. if (!zoomArg.includes("Fit")) {
  257. dest = [null, {
  258. name: "XYZ"
  259. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  260. } else {
  261. if (zoomArg === "Fit" || zoomArg === "FitB") {
  262. dest = [null, {
  263. name: zoomArg
  264. }];
  265. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  266. dest = [null, {
  267. name: zoomArg
  268. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  269. } else if (zoomArg === "FitR") {
  270. if (zoomArgs.length !== 5) {
  271. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  272. } else {
  273. dest = [null, {
  274. name: zoomArg
  275. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  276. }
  277. } else {
  278. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  279. }
  280. }
  281. }
  282. if (dest) {
  283. this.pdfViewer.scrollPageIntoView({
  284. pageNumber: pageNumber || this.page,
  285. destArray: dest,
  286. allowNegativeOffset: true
  287. });
  288. } else if (pageNumber) {
  289. this.page = pageNumber;
  290. }
  291. if (params.has("pagemode")) {
  292. this.eventBus.dispatch("pagemode", {
  293. source: this,
  294. mode: params.get("pagemode")
  295. });
  296. }
  297. if (params.has("nameddest")) {
  298. this.goToDestination(params.get("nameddest"));
  299. }
  300. } else {
  301. dest = unescape(hash);
  302. try {
  303. dest = JSON.parse(dest);
  304. if (!Array.isArray(dest)) {
  305. dest = dest.toString();
  306. }
  307. } catch (ex) {}
  308. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  309. this.goToDestination(dest);
  310. return;
  311. }
  312. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  313. }
  314. }
  315. executeNamedAction(action) {
  316. switch (action) {
  317. case "GoBack":
  318. this.pdfHistory?.back();
  319. break;
  320. case "GoForward":
  321. this.pdfHistory?.forward();
  322. break;
  323. case "NextPage":
  324. this.pdfViewer.nextPage();
  325. break;
  326. case "PrevPage":
  327. this.pdfViewer.previousPage();
  328. break;
  329. case "LastPage":
  330. this.page = this.pagesCount;
  331. break;
  332. case "FirstPage":
  333. this.page = 1;
  334. break;
  335. default:
  336. break;
  337. }
  338. this.eventBus.dispatch("namedaction", {
  339. source: this,
  340. action
  341. });
  342. }
  343. async executeSetOCGState(action) {
  344. const pdfDocument = this.pdfDocument;
  345. const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  346. if (pdfDocument !== this.pdfDocument) {
  347. return;
  348. }
  349. let operator;
  350. for (const elem of action.state) {
  351. switch (elem) {
  352. case "ON":
  353. case "OFF":
  354. case "Toggle":
  355. operator = elem;
  356. continue;
  357. }
  358. switch (operator) {
  359. case "ON":
  360. optionalContentConfig.setVisibility(elem, true);
  361. break;
  362. case "OFF":
  363. optionalContentConfig.setVisibility(elem, false);
  364. break;
  365. case "Toggle":
  366. const group = optionalContentConfig.getGroup(elem);
  367. if (group) {
  368. optionalContentConfig.setVisibility(elem, !group.visible);
  369. }
  370. break;
  371. }
  372. }
  373. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  374. }
  375. cachePageRef(pageNum, pageRef) {
  376. if (!pageRef) {
  377. return;
  378. }
  379. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  380. this.#pagesRefCache.set(refStr, pageNum);
  381. }
  382. _cachedPageNumber(pageRef) {
  383. if (!pageRef) {
  384. return null;
  385. }
  386. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  387. return this.#pagesRefCache.get(refStr) || null;
  388. }
  389. isPageVisible(pageNumber) {
  390. return this.pdfViewer.isPageVisible(pageNumber);
  391. }
  392. isPageCached(pageNumber) {
  393. return this.pdfViewer.isPageCached(pageNumber);
  394. }
  395. static #isValidExplicitDestination(dest) {
  396. if (!Array.isArray(dest)) {
  397. return false;
  398. }
  399. const destLength = dest.length;
  400. if (destLength < 2) {
  401. return false;
  402. }
  403. const page = dest[0];
  404. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  405. return false;
  406. }
  407. const zoom = dest[1];
  408. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  409. return false;
  410. }
  411. let allowNull = true;
  412. switch (zoom.name) {
  413. case "XYZ":
  414. if (destLength !== 5) {
  415. return false;
  416. }
  417. break;
  418. case "Fit":
  419. case "FitB":
  420. return destLength === 2;
  421. case "FitH":
  422. case "FitBH":
  423. case "FitV":
  424. case "FitBV":
  425. if (destLength !== 3) {
  426. return false;
  427. }
  428. break;
  429. case "FitR":
  430. if (destLength !== 6) {
  431. return false;
  432. }
  433. allowNull = false;
  434. break;
  435. default:
  436. return false;
  437. }
  438. for (let i = 2; i < destLength; i++) {
  439. const param = dest[i];
  440. if (!(typeof param === "number" || allowNull && param === null)) {
  441. return false;
  442. }
  443. }
  444. return true;
  445. }
  446. }
  447. exports.PDFLinkService = PDFLinkService;
  448. class SimpleLinkService {
  449. constructor() {
  450. this.externalLinkEnabled = true;
  451. }
  452. get pagesCount() {
  453. return 0;
  454. }
  455. get page() {
  456. return 0;
  457. }
  458. set page(value) {}
  459. get rotation() {
  460. return 0;
  461. }
  462. set rotation(value) {}
  463. get isInPresentationMode() {
  464. return false;
  465. }
  466. async goToDestination(dest) {}
  467. goToPage(val) {}
  468. addLinkAttributes(link, url, newWindow = false) {
  469. addLinkAttributes(link, {
  470. url,
  471. enabled: this.externalLinkEnabled
  472. });
  473. }
  474. getDestinationHash(dest) {
  475. return "#";
  476. }
  477. getAnchorUrl(hash) {
  478. return "#";
  479. }
  480. setHash(hash) {}
  481. executeNamedAction(action) {}
  482. executeSetOCGState(action) {}
  483. cachePageRef(pageNum, pageRef) {}
  484. isPageVisible(pageNumber) {
  485. return true;
  486. }
  487. isPageCached(pageNumber) {
  488. return true;
  489. }
  490. }
  491. exports.SimpleLinkService = SimpleLinkService;
  492. /***/ }),
  493. /* 2 */
  494. /***/ ((__unused_webpack_module, exports) => {
  495. Object.defineProperty(exports, "__esModule", ({
  496. value: true
  497. }));
  498. exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = void 0;
  499. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  500. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  501. exports.approximateFraction = approximateFraction;
  502. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  503. exports.binarySearchFirstItem = binarySearchFirstItem;
  504. exports.docStyle = void 0;
  505. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  506. exports.getPageSizeInches = getPageSizeInches;
  507. exports.getVisibleElements = getVisibleElements;
  508. exports.isPortraitOrientation = isPortraitOrientation;
  509. exports.isValidRotation = isValidRotation;
  510. exports.isValidScrollMode = isValidScrollMode;
  511. exports.isValidSpreadMode = isValidSpreadMode;
  512. exports.noContextMenuHandler = noContextMenuHandler;
  513. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  514. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  515. exports.parseQueryString = parseQueryString;
  516. exports.removeNullCharacters = removeNullCharacters;
  517. exports.roundToDivide = roundToDivide;
  518. exports.scrollIntoView = scrollIntoView;
  519. exports.watchScroll = watchScroll;
  520. const DEFAULT_SCALE_VALUE = "auto";
  521. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  522. const DEFAULT_SCALE = 1.0;
  523. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  524. const DEFAULT_SCALE_DELTA = 1.1;
  525. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  526. const MIN_SCALE = 0.1;
  527. exports.MIN_SCALE = MIN_SCALE;
  528. const MAX_SCALE = 10.0;
  529. exports.MAX_SCALE = MAX_SCALE;
  530. const UNKNOWN_SCALE = 0;
  531. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  532. const MAX_AUTO_SCALE = 1.25;
  533. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  534. const SCROLLBAR_PADDING = 40;
  535. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  536. const VERTICAL_PADDING = 5;
  537. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  538. const RenderingStates = {
  539. INITIAL: 0,
  540. RUNNING: 1,
  541. PAUSED: 2,
  542. FINISHED: 3
  543. };
  544. exports.RenderingStates = RenderingStates;
  545. const PresentationModeState = {
  546. UNKNOWN: 0,
  547. NORMAL: 1,
  548. CHANGING: 2,
  549. FULLSCREEN: 3
  550. };
  551. exports.PresentationModeState = PresentationModeState;
  552. const SidebarView = {
  553. UNKNOWN: -1,
  554. NONE: 0,
  555. THUMBS: 1,
  556. OUTLINE: 2,
  557. ATTACHMENTS: 3,
  558. LAYERS: 4
  559. };
  560. exports.SidebarView = SidebarView;
  561. const RendererType = {
  562. CANVAS: "canvas",
  563. SVG: "svg"
  564. };
  565. exports.RendererType = RendererType;
  566. const TextLayerMode = {
  567. DISABLE: 0,
  568. ENABLE: 1
  569. };
  570. exports.TextLayerMode = TextLayerMode;
  571. const ScrollMode = {
  572. UNKNOWN: -1,
  573. VERTICAL: 0,
  574. HORIZONTAL: 1,
  575. WRAPPED: 2,
  576. PAGE: 3
  577. };
  578. exports.ScrollMode = ScrollMode;
  579. const SpreadMode = {
  580. UNKNOWN: -1,
  581. NONE: 0,
  582. ODD: 1,
  583. EVEN: 2
  584. };
  585. exports.SpreadMode = SpreadMode;
  586. const AutoPrintRegExp = /\bprint\s*\(/;
  587. exports.AutoPrintRegExp = AutoPrintRegExp;
  588. class OutputScale {
  589. constructor() {
  590. const pixelRatio = window.devicePixelRatio || 1;
  591. this.sx = pixelRatio;
  592. this.sy = pixelRatio;
  593. }
  594. get scaled() {
  595. return this.sx !== 1 || this.sy !== 1;
  596. }
  597. }
  598. exports.OutputScale = OutputScale;
  599. function scrollIntoView(element, spot, scrollMatches = false) {
  600. let parent = element.offsetParent;
  601. if (!parent) {
  602. console.error("offsetParent is not set -- cannot scroll");
  603. return;
  604. }
  605. let offsetY = element.offsetTop + element.clientTop;
  606. let offsetX = element.offsetLeft + element.clientLeft;
  607. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  608. offsetY += parent.offsetTop;
  609. offsetX += parent.offsetLeft;
  610. parent = parent.offsetParent;
  611. if (!parent) {
  612. return;
  613. }
  614. }
  615. if (spot) {
  616. if (spot.top !== undefined) {
  617. offsetY += spot.top;
  618. }
  619. if (spot.left !== undefined) {
  620. offsetX += spot.left;
  621. parent.scrollLeft = offsetX;
  622. }
  623. }
  624. parent.scrollTop = offsetY;
  625. }
  626. function watchScroll(viewAreaElement, callback) {
  627. const debounceScroll = function (evt) {
  628. if (rAF) {
  629. return;
  630. }
  631. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  632. rAF = null;
  633. const currentX = viewAreaElement.scrollLeft;
  634. const lastX = state.lastX;
  635. if (currentX !== lastX) {
  636. state.right = currentX > lastX;
  637. }
  638. state.lastX = currentX;
  639. const currentY = viewAreaElement.scrollTop;
  640. const lastY = state.lastY;
  641. if (currentY !== lastY) {
  642. state.down = currentY > lastY;
  643. }
  644. state.lastY = currentY;
  645. callback(state);
  646. });
  647. };
  648. const state = {
  649. right: true,
  650. down: true,
  651. lastX: viewAreaElement.scrollLeft,
  652. lastY: viewAreaElement.scrollTop,
  653. _eventHandler: debounceScroll
  654. };
  655. let rAF = null;
  656. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  657. return state;
  658. }
  659. function parseQueryString(query) {
  660. const params = new Map();
  661. for (const [key, value] of new URLSearchParams(query)) {
  662. params.set(key.toLowerCase(), value);
  663. }
  664. return params;
  665. }
  666. const NullCharactersRegExp = /\x00/g;
  667. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  668. function removeNullCharacters(str, replaceInvisible = false) {
  669. if (typeof str !== "string") {
  670. console.error(`The argument must be a string.`);
  671. return str;
  672. }
  673. if (replaceInvisible) {
  674. str = str.replace(InvisibleCharactersRegExp, " ");
  675. }
  676. return str.replace(NullCharactersRegExp, "");
  677. }
  678. function binarySearchFirstItem(items, condition, start = 0) {
  679. let minIndex = start;
  680. let maxIndex = items.length - 1;
  681. if (maxIndex < 0 || !condition(items[maxIndex])) {
  682. return items.length;
  683. }
  684. if (condition(items[minIndex])) {
  685. return minIndex;
  686. }
  687. while (minIndex < maxIndex) {
  688. const currentIndex = minIndex + maxIndex >> 1;
  689. const currentItem = items[currentIndex];
  690. if (condition(currentItem)) {
  691. maxIndex = currentIndex;
  692. } else {
  693. minIndex = currentIndex + 1;
  694. }
  695. }
  696. return minIndex;
  697. }
  698. function approximateFraction(x) {
  699. if (Math.floor(x) === x) {
  700. return [x, 1];
  701. }
  702. const xinv = 1 / x;
  703. const limit = 8;
  704. if (xinv > limit) {
  705. return [1, limit];
  706. } else if (Math.floor(xinv) === xinv) {
  707. return [1, xinv];
  708. }
  709. const x_ = x > 1 ? xinv : x;
  710. let a = 0,
  711. b = 1,
  712. c = 1,
  713. d = 1;
  714. while (true) {
  715. const p = a + c,
  716. q = b + d;
  717. if (q > limit) {
  718. break;
  719. }
  720. if (x_ <= p / q) {
  721. c = p;
  722. d = q;
  723. } else {
  724. a = p;
  725. b = q;
  726. }
  727. }
  728. let result;
  729. if (x_ - a / b < c / d - x_) {
  730. result = x_ === x ? [a, b] : [b, a];
  731. } else {
  732. result = x_ === x ? [c, d] : [d, c];
  733. }
  734. return result;
  735. }
  736. function roundToDivide(x, div) {
  737. const r = x % div;
  738. return r === 0 ? x : Math.round(x - r + div);
  739. }
  740. function getPageSizeInches({
  741. view,
  742. userUnit,
  743. rotate
  744. }) {
  745. const [x1, y1, x2, y2] = view;
  746. const changeOrientation = rotate % 180 !== 0;
  747. const width = (x2 - x1) / 72 * userUnit;
  748. const height = (y2 - y1) / 72 * userUnit;
  749. return {
  750. width: changeOrientation ? height : width,
  751. height: changeOrientation ? width : height
  752. };
  753. }
  754. function backtrackBeforeAllVisibleElements(index, views, top) {
  755. if (index < 2) {
  756. return index;
  757. }
  758. let elt = views[index].div;
  759. let pageTop = elt.offsetTop + elt.clientTop;
  760. if (pageTop >= top) {
  761. elt = views[index - 1].div;
  762. pageTop = elt.offsetTop + elt.clientTop;
  763. }
  764. for (let i = index - 2; i >= 0; --i) {
  765. elt = views[i].div;
  766. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  767. break;
  768. }
  769. index = i;
  770. }
  771. return index;
  772. }
  773. function getVisibleElements({
  774. scrollEl,
  775. views,
  776. sortByVisibility = false,
  777. horizontal = false,
  778. rtl = false
  779. }) {
  780. const top = scrollEl.scrollTop,
  781. bottom = top + scrollEl.clientHeight;
  782. const left = scrollEl.scrollLeft,
  783. right = left + scrollEl.clientWidth;
  784. function isElementBottomAfterViewTop(view) {
  785. const element = view.div;
  786. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  787. return elementBottom > top;
  788. }
  789. function isElementNextAfterViewHorizontally(view) {
  790. const element = view.div;
  791. const elementLeft = element.offsetLeft + element.clientLeft;
  792. const elementRight = elementLeft + element.clientWidth;
  793. return rtl ? elementLeft < right : elementRight > left;
  794. }
  795. const visible = [],
  796. ids = new Set(),
  797. numViews = views.length;
  798. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  799. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  800. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  801. }
  802. let lastEdge = horizontal ? right : -1;
  803. for (let i = firstVisibleElementInd; i < numViews; i++) {
  804. const view = views[i],
  805. element = view.div;
  806. const currentWidth = element.offsetLeft + element.clientLeft;
  807. const currentHeight = element.offsetTop + element.clientTop;
  808. const viewWidth = element.clientWidth,
  809. viewHeight = element.clientHeight;
  810. const viewRight = currentWidth + viewWidth;
  811. const viewBottom = currentHeight + viewHeight;
  812. if (lastEdge === -1) {
  813. if (viewBottom >= bottom) {
  814. lastEdge = viewBottom;
  815. }
  816. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  817. break;
  818. }
  819. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  820. continue;
  821. }
  822. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  823. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  824. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  825. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  826. const percent = fractionHeight * fractionWidth * 100 | 0;
  827. visible.push({
  828. id: view.id,
  829. x: currentWidth,
  830. y: currentHeight,
  831. view,
  832. percent,
  833. widthPercent: fractionWidth * 100 | 0
  834. });
  835. ids.add(view.id);
  836. }
  837. const first = visible[0],
  838. last = visible.at(-1);
  839. if (sortByVisibility) {
  840. visible.sort(function (a, b) {
  841. const pc = a.percent - b.percent;
  842. if (Math.abs(pc) > 0.001) {
  843. return -pc;
  844. }
  845. return a.id - b.id;
  846. });
  847. }
  848. return {
  849. first,
  850. last,
  851. views: visible,
  852. ids
  853. };
  854. }
  855. function noContextMenuHandler(evt) {
  856. evt.preventDefault();
  857. }
  858. function normalizeWheelEventDirection(evt) {
  859. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  860. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  861. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  862. delta = -delta;
  863. }
  864. return delta;
  865. }
  866. function normalizeWheelEventDelta(evt) {
  867. let delta = normalizeWheelEventDirection(evt);
  868. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  869. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  870. const MOUSE_PIXELS_PER_LINE = 30;
  871. const MOUSE_LINES_PER_PAGE = 30;
  872. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  873. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  874. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  875. delta /= MOUSE_LINES_PER_PAGE;
  876. }
  877. return delta;
  878. }
  879. function isValidRotation(angle) {
  880. return Number.isInteger(angle) && angle % 90 === 0;
  881. }
  882. function isValidScrollMode(mode) {
  883. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  884. }
  885. function isValidSpreadMode(mode) {
  886. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  887. }
  888. function isPortraitOrientation(size) {
  889. return size.width <= size.height;
  890. }
  891. const animationStarted = new Promise(function (resolve) {
  892. window.requestAnimationFrame(resolve);
  893. });
  894. exports.animationStarted = animationStarted;
  895. const docStyle = document.documentElement.style;
  896. exports.docStyle = docStyle;
  897. function clamp(v, min, max) {
  898. return Math.min(Math.max(v, min), max);
  899. }
  900. class ProgressBar {
  901. #classList = null;
  902. #percent = 0;
  903. #visible = true;
  904. constructor(bar) {
  905. this.#classList = bar.classList;
  906. }
  907. get percent() {
  908. return this.#percent;
  909. }
  910. set percent(val) {
  911. this.#percent = clamp(val, 0, 100);
  912. if (isNaN(val)) {
  913. this.#classList.add("indeterminate");
  914. return;
  915. }
  916. this.#classList.remove("indeterminate");
  917. docStyle.setProperty("--progressBar-percent", `${this.#percent}%`);
  918. }
  919. setWidth(viewer) {
  920. if (!viewer) {
  921. return;
  922. }
  923. const container = viewer.parentNode;
  924. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  925. if (scrollbarWidth > 0) {
  926. docStyle.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  927. }
  928. }
  929. hide() {
  930. if (!this.#visible) {
  931. return;
  932. }
  933. this.#visible = false;
  934. this.#classList.add("hidden");
  935. }
  936. show() {
  937. if (this.#visible) {
  938. return;
  939. }
  940. this.#visible = true;
  941. this.#classList.remove("hidden");
  942. }
  943. }
  944. exports.ProgressBar = ProgressBar;
  945. function getActiveOrFocusedElement() {
  946. let curRoot = document;
  947. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  948. while (curActiveOrFocused?.shadowRoot) {
  949. curRoot = curActiveOrFocused.shadowRoot;
  950. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  951. }
  952. return curActiveOrFocused;
  953. }
  954. function apiPageLayoutToViewerModes(layout) {
  955. let scrollMode = ScrollMode.VERTICAL,
  956. spreadMode = SpreadMode.NONE;
  957. switch (layout) {
  958. case "SinglePage":
  959. scrollMode = ScrollMode.PAGE;
  960. break;
  961. case "OneColumn":
  962. break;
  963. case "TwoPageLeft":
  964. scrollMode = ScrollMode.PAGE;
  965. case "TwoColumnLeft":
  966. spreadMode = SpreadMode.ODD;
  967. break;
  968. case "TwoPageRight":
  969. scrollMode = ScrollMode.PAGE;
  970. case "TwoColumnRight":
  971. spreadMode = SpreadMode.EVEN;
  972. break;
  973. }
  974. return {
  975. scrollMode,
  976. spreadMode
  977. };
  978. }
  979. function apiPageModeToSidebarView(mode) {
  980. switch (mode) {
  981. case "UseNone":
  982. return SidebarView.NONE;
  983. case "UseThumbs":
  984. return SidebarView.THUMBS;
  985. case "UseOutlines":
  986. return SidebarView.OUTLINE;
  987. case "UseAttachments":
  988. return SidebarView.ATTACHMENTS;
  989. case "UseOC":
  990. return SidebarView.LAYERS;
  991. }
  992. return SidebarView.NONE;
  993. }
  994. /***/ }),
  995. /* 3 */
  996. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  997. Object.defineProperty(exports, "__esModule", ({
  998. value: true
  999. }));
  1000. exports.AnnotationLayerBuilder = void 0;
  1001. var _pdfjsLib = __w_pdfjs_require__(4);
  1002. var _l10n_utils = __w_pdfjs_require__(5);
  1003. var _ui_utils = __w_pdfjs_require__(2);
  1004. class AnnotationLayerBuilder {
  1005. #numAnnotations = 0;
  1006. #onPresentationModeChanged = null;
  1007. constructor({
  1008. pageDiv,
  1009. pdfPage,
  1010. linkService,
  1011. downloadManager,
  1012. annotationStorage = null,
  1013. imageResourcesPath = "",
  1014. renderForms = true,
  1015. l10n = _l10n_utils.NullL10n,
  1016. enableScripting = false,
  1017. hasJSActionsPromise = null,
  1018. fieldObjectsPromise = null,
  1019. annotationCanvasMap = null,
  1020. accessibilityManager = null
  1021. }) {
  1022. this.pageDiv = pageDiv;
  1023. this.pdfPage = pdfPage;
  1024. this.linkService = linkService;
  1025. this.downloadManager = downloadManager;
  1026. this.imageResourcesPath = imageResourcesPath;
  1027. this.renderForms = renderForms;
  1028. this.l10n = l10n;
  1029. this.annotationStorage = annotationStorage;
  1030. this.enableScripting = enableScripting;
  1031. this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
  1032. this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
  1033. this._annotationCanvasMap = annotationCanvasMap;
  1034. this._accessibilityManager = accessibilityManager;
  1035. this.div = null;
  1036. this._cancelled = false;
  1037. this._eventBus = linkService.eventBus;
  1038. }
  1039. async render(viewport, intent = "display") {
  1040. if (this.div) {
  1041. if (this._cancelled || this.#numAnnotations === 0) {
  1042. return;
  1043. }
  1044. _pdfjsLib.AnnotationLayer.update({
  1045. viewport: viewport.clone({
  1046. dontFlip: true
  1047. }),
  1048. div: this.div,
  1049. annotationCanvasMap: this._annotationCanvasMap
  1050. });
  1051. return;
  1052. }
  1053. const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
  1054. intent
  1055. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  1056. if (this._cancelled) {
  1057. return;
  1058. }
  1059. this.#numAnnotations = annotations.length;
  1060. this.div = document.createElement("div");
  1061. this.div.className = "annotationLayer";
  1062. this.pageDiv.append(this.div);
  1063. if (this.#numAnnotations === 0) {
  1064. this.hide();
  1065. return;
  1066. }
  1067. _pdfjsLib.AnnotationLayer.render({
  1068. viewport: viewport.clone({
  1069. dontFlip: true
  1070. }),
  1071. div: this.div,
  1072. annotations,
  1073. page: this.pdfPage,
  1074. imageResourcesPath: this.imageResourcesPath,
  1075. renderForms: this.renderForms,
  1076. linkService: this.linkService,
  1077. downloadManager: this.downloadManager,
  1078. annotationStorage: this.annotationStorage,
  1079. enableScripting: this.enableScripting,
  1080. hasJSActions,
  1081. fieldObjects,
  1082. annotationCanvasMap: this._annotationCanvasMap,
  1083. accessibilityManager: this._accessibilityManager
  1084. });
  1085. this.l10n.translate(this.div);
  1086. if (this.linkService.isInPresentationMode) {
  1087. this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN);
  1088. }
  1089. if (!this.#onPresentationModeChanged) {
  1090. this.#onPresentationModeChanged = evt => {
  1091. this.#updatePresentationModeState(evt.state);
  1092. };
  1093. this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged);
  1094. }
  1095. }
  1096. cancel() {
  1097. this._cancelled = true;
  1098. if (this.#onPresentationModeChanged) {
  1099. this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged);
  1100. this.#onPresentationModeChanged = null;
  1101. }
  1102. }
  1103. hide() {
  1104. if (!this.div) {
  1105. return;
  1106. }
  1107. this.div.hidden = true;
  1108. }
  1109. #updatePresentationModeState(state) {
  1110. if (!this.div) {
  1111. return;
  1112. }
  1113. let disableFormElements = false;
  1114. switch (state) {
  1115. case _ui_utils.PresentationModeState.FULLSCREEN:
  1116. disableFormElements = true;
  1117. break;
  1118. case _ui_utils.PresentationModeState.NORMAL:
  1119. break;
  1120. default:
  1121. return;
  1122. }
  1123. for (const section of this.div.childNodes) {
  1124. if (section.hasAttribute("data-internal-link")) {
  1125. continue;
  1126. }
  1127. section.inert = disableFormElements;
  1128. }
  1129. }
  1130. }
  1131. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  1132. /***/ }),
  1133. /* 4 */
  1134. /***/ ((module) => {
  1135. let pdfjsLib;
  1136. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  1137. pdfjsLib = window["pdfjs-dist/build/pdf"];
  1138. } else {
  1139. pdfjsLib = require("../build/pdf.js");
  1140. }
  1141. module.exports = pdfjsLib;
  1142. /***/ }),
  1143. /* 5 */
  1144. /***/ ((__unused_webpack_module, exports) => {
  1145. Object.defineProperty(exports, "__esModule", ({
  1146. value: true
  1147. }));
  1148. exports.NullL10n = void 0;
  1149. exports.fixupLangCode = fixupLangCode;
  1150. exports.getL10nFallback = getL10nFallback;
  1151. const DEFAULT_L10N_STRINGS = {
  1152. of_pages: "of {{pagesCount}}",
  1153. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  1154. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  1155. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  1156. document_properties_date_string: "{{date}}, {{time}}",
  1157. document_properties_page_size_unit_inches: "in",
  1158. document_properties_page_size_unit_millimeters: "mm",
  1159. document_properties_page_size_orientation_portrait: "portrait",
  1160. document_properties_page_size_orientation_landscape: "landscape",
  1161. document_properties_page_size_name_a3: "A3",
  1162. document_properties_page_size_name_a4: "A4",
  1163. document_properties_page_size_name_letter: "Letter",
  1164. document_properties_page_size_name_legal: "Legal",
  1165. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  1166. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  1167. document_properties_linearized_yes: "Yes",
  1168. document_properties_linearized_no: "No",
  1169. additional_layers: "Additional Layers",
  1170. page_landmark: "Page {{page}}",
  1171. thumb_page_title: "Page {{page}}",
  1172. thumb_page_canvas: "Thumbnail of Page {{page}}",
  1173. find_reached_top: "Reached top of document, continued from bottom",
  1174. find_reached_bottom: "Reached end of document, continued from top",
  1175. "find_match_count[one]": "{{current}} of {{total}} match",
  1176. "find_match_count[other]": "{{current}} of {{total}} matches",
  1177. "find_match_count_limit[one]": "More than {{limit}} match",
  1178. "find_match_count_limit[other]": "More than {{limit}} matches",
  1179. find_not_found: "Phrase not found",
  1180. page_scale_width: "Page Width",
  1181. page_scale_fit: "Page Fit",
  1182. page_scale_auto: "Automatic Zoom",
  1183. page_scale_actual: "Actual Size",
  1184. page_scale_percent: "{{scale}}%",
  1185. loading: "Loading…",
  1186. loading_error: "An error occurred while loading the PDF.",
  1187. invalid_file_error: "Invalid or corrupted PDF file.",
  1188. missing_file_error: "Missing PDF file.",
  1189. unexpected_response_error: "Unexpected server response.",
  1190. rendering_error: "An error occurred while rendering the page.",
  1191. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  1192. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  1193. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  1194. free_text2_default_content: "Start typing…",
  1195. editor_free_text2_aria_label: "Text Editor",
  1196. editor_ink2_aria_label: "Draw Editor",
  1197. editor_ink_canvas_aria_label: "User-created image"
  1198. };
  1199. {
  1200. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  1201. }
  1202. function getL10nFallback(key, args) {
  1203. switch (key) {
  1204. case "find_match_count":
  1205. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  1206. break;
  1207. case "find_match_count_limit":
  1208. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  1209. break;
  1210. }
  1211. return DEFAULT_L10N_STRINGS[key] || "";
  1212. }
  1213. const PARTIAL_LANG_CODES = {
  1214. en: "en-US",
  1215. es: "es-ES",
  1216. fy: "fy-NL",
  1217. ga: "ga-IE",
  1218. gu: "gu-IN",
  1219. hi: "hi-IN",
  1220. hy: "hy-AM",
  1221. nb: "nb-NO",
  1222. ne: "ne-NP",
  1223. nn: "nn-NO",
  1224. pa: "pa-IN",
  1225. pt: "pt-PT",
  1226. sv: "sv-SE",
  1227. zh: "zh-CN"
  1228. };
  1229. function fixupLangCode(langCode) {
  1230. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  1231. }
  1232. function formatL10nValue(text, args) {
  1233. if (!args) {
  1234. return text;
  1235. }
  1236. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  1237. return name in args ? args[name] : "{{" + name + "}}";
  1238. });
  1239. }
  1240. const NullL10n = {
  1241. async getLanguage() {
  1242. return "en-us";
  1243. },
  1244. async getDirection() {
  1245. return "ltr";
  1246. },
  1247. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  1248. return formatL10nValue(fallback, args);
  1249. },
  1250. async translate(element) {}
  1251. };
  1252. exports.NullL10n = NullL10n;
  1253. /***/ }),
  1254. /* 6 */
  1255. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1256. Object.defineProperty(exports, "__esModule", ({
  1257. value: true
  1258. }));
  1259. exports.DownloadManager = void 0;
  1260. var _pdfjsLib = __w_pdfjs_require__(4);
  1261. ;
  1262. function download(blobUrl, filename) {
  1263. const a = document.createElement("a");
  1264. if (!a.click) {
  1265. throw new Error('DownloadManager: "a.click()" is not supported.');
  1266. }
  1267. a.href = blobUrl;
  1268. a.target = "_parent";
  1269. if ("download" in a) {
  1270. a.download = filename;
  1271. }
  1272. (document.body || document.documentElement).append(a);
  1273. a.click();
  1274. a.remove();
  1275. }
  1276. class DownloadManager {
  1277. #openBlobUrls = new WeakMap();
  1278. downloadUrl(url, filename) {
  1279. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  1280. console.error(`downloadUrl - not a valid URL: ${url}`);
  1281. return;
  1282. }
  1283. download(url + "#pdfjs.action=download", filename);
  1284. }
  1285. downloadData(data, filename, contentType) {
  1286. const blobUrl = URL.createObjectURL(new Blob([data], {
  1287. type: contentType
  1288. }));
  1289. download(blobUrl, filename);
  1290. }
  1291. openOrDownloadData(element, data, filename) {
  1292. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  1293. const contentType = isPdfData ? "application/pdf" : "";
  1294. if (isPdfData) {
  1295. let blobUrl = this.#openBlobUrls.get(element);
  1296. if (!blobUrl) {
  1297. blobUrl = URL.createObjectURL(new Blob([data], {
  1298. type: contentType
  1299. }));
  1300. this.#openBlobUrls.set(element, blobUrl);
  1301. }
  1302. let viewerUrl;
  1303. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  1304. try {
  1305. window.open(viewerUrl);
  1306. return true;
  1307. } catch (ex) {
  1308. console.error(`openOrDownloadData: ${ex}`);
  1309. URL.revokeObjectURL(blobUrl);
  1310. this.#openBlobUrls.delete(element);
  1311. }
  1312. }
  1313. this.downloadData(data, filename, contentType);
  1314. return false;
  1315. }
  1316. download(blob, url, filename) {
  1317. const blobUrl = URL.createObjectURL(blob);
  1318. download(blobUrl, filename);
  1319. }
  1320. }
  1321. exports.DownloadManager = DownloadManager;
  1322. /***/ }),
  1323. /* 7 */
  1324. /***/ ((__unused_webpack_module, exports) => {
  1325. Object.defineProperty(exports, "__esModule", ({
  1326. value: true
  1327. }));
  1328. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  1329. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  1330. const WaitOnType = {
  1331. EVENT: "event",
  1332. TIMEOUT: "timeout"
  1333. };
  1334. exports.WaitOnType = WaitOnType;
  1335. function waitOnEventOrTimeout({
  1336. target,
  1337. name,
  1338. delay = 0
  1339. }) {
  1340. return new Promise(function (resolve, reject) {
  1341. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  1342. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  1343. }
  1344. function handler(type) {
  1345. if (target instanceof EventBus) {
  1346. target._off(name, eventHandler);
  1347. } else {
  1348. target.removeEventListener(name, eventHandler);
  1349. }
  1350. if (timeout) {
  1351. clearTimeout(timeout);
  1352. }
  1353. resolve(type);
  1354. }
  1355. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  1356. if (target instanceof EventBus) {
  1357. target._on(name, eventHandler);
  1358. } else {
  1359. target.addEventListener(name, eventHandler);
  1360. }
  1361. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  1362. const timeout = setTimeout(timeoutHandler, delay);
  1363. });
  1364. }
  1365. class EventBus {
  1366. #listeners = Object.create(null);
  1367. on(eventName, listener, options = null) {
  1368. this._on(eventName, listener, {
  1369. external: true,
  1370. once: options?.once
  1371. });
  1372. }
  1373. off(eventName, listener, options = null) {
  1374. this._off(eventName, listener, {
  1375. external: true,
  1376. once: options?.once
  1377. });
  1378. }
  1379. dispatch(eventName, data) {
  1380. const eventListeners = this.#listeners[eventName];
  1381. if (!eventListeners || eventListeners.length === 0) {
  1382. return;
  1383. }
  1384. let externalListeners;
  1385. for (const {
  1386. listener,
  1387. external,
  1388. once
  1389. } of eventListeners.slice(0)) {
  1390. if (once) {
  1391. this._off(eventName, listener);
  1392. }
  1393. if (external) {
  1394. (externalListeners ||= []).push(listener);
  1395. continue;
  1396. }
  1397. listener(data);
  1398. }
  1399. if (externalListeners) {
  1400. for (const listener of externalListeners) {
  1401. listener(data);
  1402. }
  1403. externalListeners = null;
  1404. }
  1405. }
  1406. _on(eventName, listener, options = null) {
  1407. const eventListeners = this.#listeners[eventName] ||= [];
  1408. eventListeners.push({
  1409. listener,
  1410. external: options?.external === true,
  1411. once: options?.once === true
  1412. });
  1413. }
  1414. _off(eventName, listener, options = null) {
  1415. const eventListeners = this.#listeners[eventName];
  1416. if (!eventListeners) {
  1417. return;
  1418. }
  1419. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  1420. if (eventListeners[i].listener === listener) {
  1421. eventListeners.splice(i, 1);
  1422. return;
  1423. }
  1424. }
  1425. }
  1426. }
  1427. exports.EventBus = EventBus;
  1428. class AutomationEventBus extends EventBus {
  1429. dispatch(eventName, data) {
  1430. throw new Error("Not implemented: AutomationEventBus.dispatch");
  1431. }
  1432. }
  1433. exports.AutomationEventBus = AutomationEventBus;
  1434. /***/ }),
  1435. /* 8 */
  1436. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1437. Object.defineProperty(exports, "__esModule", ({
  1438. value: true
  1439. }));
  1440. exports.GenericL10n = void 0;
  1441. __w_pdfjs_require__(9);
  1442. var _l10n_utils = __w_pdfjs_require__(5);
  1443. const webL10n = document.webL10n;
  1444. class GenericL10n {
  1445. constructor(lang) {
  1446. this._lang = lang;
  1447. this._ready = new Promise((resolve, reject) => {
  1448. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  1449. resolve(webL10n);
  1450. });
  1451. });
  1452. }
  1453. async getLanguage() {
  1454. const l10n = await this._ready;
  1455. return l10n.getLanguage();
  1456. }
  1457. async getDirection() {
  1458. const l10n = await this._ready;
  1459. return l10n.getDirection();
  1460. }
  1461. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  1462. const l10n = await this._ready;
  1463. return l10n.get(key, args, fallback);
  1464. }
  1465. async translate(element) {
  1466. const l10n = await this._ready;
  1467. return l10n.translate(element);
  1468. }
  1469. }
  1470. exports.GenericL10n = GenericL10n;
  1471. /***/ }),
  1472. /* 9 */
  1473. /***/ (() => {
  1474. document.webL10n = function (window, document, undefined) {
  1475. var gL10nData = {};
  1476. var gTextData = '';
  1477. var gTextProp = 'textContent';
  1478. var gLanguage = '';
  1479. var gMacros = {};
  1480. var gReadyState = 'loading';
  1481. var gAsyncResourceLoading = true;
  1482. function getL10nResourceLinks() {
  1483. return document.querySelectorAll('link[type="application/l10n"]');
  1484. }
  1485. function getL10nDictionary() {
  1486. var script = document.querySelector('script[type="application/l10n"]');
  1487. return script ? JSON.parse(script.innerHTML) : null;
  1488. }
  1489. function getTranslatableChildren(element) {
  1490. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  1491. }
  1492. function getL10nAttributes(element) {
  1493. if (!element) return {};
  1494. var l10nId = element.getAttribute('data-l10n-id');
  1495. var l10nArgs = element.getAttribute('data-l10n-args');
  1496. var args = {};
  1497. if (l10nArgs) {
  1498. try {
  1499. args = JSON.parse(l10nArgs);
  1500. } catch (e) {
  1501. console.warn('could not parse arguments for #' + l10nId);
  1502. }
  1503. }
  1504. return {
  1505. id: l10nId,
  1506. args: args
  1507. };
  1508. }
  1509. function xhrLoadText(url, onSuccess, onFailure) {
  1510. onSuccess = onSuccess || function _onSuccess(data) {};
  1511. onFailure = onFailure || function _onFailure() {};
  1512. var xhr = new XMLHttpRequest();
  1513. xhr.open('GET', url, gAsyncResourceLoading);
  1514. if (xhr.overrideMimeType) {
  1515. xhr.overrideMimeType('text/plain; charset=utf-8');
  1516. }
  1517. xhr.onreadystatechange = function () {
  1518. if (xhr.readyState == 4) {
  1519. if (xhr.status == 200 || xhr.status === 0) {
  1520. onSuccess(xhr.responseText);
  1521. } else {
  1522. onFailure();
  1523. }
  1524. }
  1525. };
  1526. xhr.onerror = onFailure;
  1527. xhr.ontimeout = onFailure;
  1528. try {
  1529. xhr.send(null);
  1530. } catch (e) {
  1531. onFailure();
  1532. }
  1533. }
  1534. function parseResource(href, lang, successCallback, failureCallback) {
  1535. var baseURL = href.replace(/[^\/]*$/, '') || './';
  1536. function evalString(text) {
  1537. if (text.lastIndexOf('\\') < 0) return text;
  1538. 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, "'");
  1539. }
  1540. function parseProperties(text, parsedPropertiesCallback) {
  1541. var dictionary = {};
  1542. var reBlank = /^\s*|\s*$/;
  1543. var reComment = /^\s*#|^\s*$/;
  1544. var reSection = /^\s*\[(.*)\]\s*$/;
  1545. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  1546. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  1547. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  1548. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  1549. var currentLang = '*';
  1550. var genericLang = lang.split('-', 1)[0];
  1551. var skipLang = false;
  1552. var match = '';
  1553. function nextEntry() {
  1554. while (true) {
  1555. if (!entries.length) {
  1556. parsedRawLinesCallback();
  1557. return;
  1558. }
  1559. var line = entries.shift();
  1560. if (reComment.test(line)) continue;
  1561. if (extendedSyntax) {
  1562. match = reSection.exec(line);
  1563. if (match) {
  1564. currentLang = match[1].toLowerCase();
  1565. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  1566. continue;
  1567. } else if (skipLang) {
  1568. continue;
  1569. }
  1570. match = reImport.exec(line);
  1571. if (match) {
  1572. loadImport(baseURL + match[1], nextEntry);
  1573. return;
  1574. }
  1575. }
  1576. var tmp = line.match(reSplit);
  1577. if (tmp && tmp.length == 3) {
  1578. dictionary[tmp[1]] = evalString(tmp[2]);
  1579. }
  1580. }
  1581. }
  1582. nextEntry();
  1583. }
  1584. function loadImport(url, callback) {
  1585. xhrLoadText(url, function (content) {
  1586. parseRawLines(content, false, callback);
  1587. }, function () {
  1588. console.warn(url + ' not found.');
  1589. callback();
  1590. });
  1591. }
  1592. parseRawLines(text, true, function () {
  1593. parsedPropertiesCallback(dictionary);
  1594. });
  1595. }
  1596. xhrLoadText(href, function (response) {
  1597. gTextData += response;
  1598. parseProperties(response, function (data) {
  1599. for (var key in data) {
  1600. var id,
  1601. prop,
  1602. index = key.lastIndexOf('.');
  1603. if (index > 0) {
  1604. id = key.substring(0, index);
  1605. prop = key.substring(index + 1);
  1606. } else {
  1607. id = key;
  1608. prop = gTextProp;
  1609. }
  1610. if (!gL10nData[id]) {
  1611. gL10nData[id] = {};
  1612. }
  1613. gL10nData[id][prop] = data[key];
  1614. }
  1615. if (successCallback) {
  1616. successCallback();
  1617. }
  1618. });
  1619. }, failureCallback);
  1620. }
  1621. function loadLocale(lang, callback) {
  1622. if (lang) {
  1623. lang = lang.toLowerCase();
  1624. }
  1625. callback = callback || function _callback() {};
  1626. clear();
  1627. gLanguage = lang;
  1628. var langLinks = getL10nResourceLinks();
  1629. var langCount = langLinks.length;
  1630. if (langCount === 0) {
  1631. var dict = getL10nDictionary();
  1632. if (dict && dict.locales && dict.default_locale) {
  1633. console.log('using the embedded JSON directory, early way out');
  1634. gL10nData = dict.locales[lang];
  1635. if (!gL10nData) {
  1636. var defaultLocale = dict.default_locale.toLowerCase();
  1637. for (var anyCaseLang in dict.locales) {
  1638. anyCaseLang = anyCaseLang.toLowerCase();
  1639. if (anyCaseLang === lang) {
  1640. gL10nData = dict.locales[lang];
  1641. break;
  1642. } else if (anyCaseLang === defaultLocale) {
  1643. gL10nData = dict.locales[defaultLocale];
  1644. }
  1645. }
  1646. }
  1647. callback();
  1648. } else {
  1649. console.log('no resource to load, early way out');
  1650. }
  1651. gReadyState = 'complete';
  1652. return;
  1653. }
  1654. var onResourceLoaded = null;
  1655. var gResourceCount = 0;
  1656. onResourceLoaded = function () {
  1657. gResourceCount++;
  1658. if (gResourceCount >= langCount) {
  1659. callback();
  1660. gReadyState = 'complete';
  1661. }
  1662. };
  1663. function L10nResourceLink(link) {
  1664. var href = link.href;
  1665. this.load = function (lang, callback) {
  1666. parseResource(href, lang, callback, function () {
  1667. console.warn(href + ' not found.');
  1668. console.warn('"' + lang + '" resource not found');
  1669. gLanguage = '';
  1670. callback();
  1671. });
  1672. };
  1673. }
  1674. for (var i = 0; i < langCount; i++) {
  1675. var resource = new L10nResourceLink(langLinks[i]);
  1676. resource.load(lang, onResourceLoaded);
  1677. }
  1678. }
  1679. function clear() {
  1680. gL10nData = {};
  1681. gTextData = '';
  1682. gLanguage = '';
  1683. }
  1684. function getPluralRules(lang) {
  1685. var locales2rules = {
  1686. 'af': 3,
  1687. 'ak': 4,
  1688. 'am': 4,
  1689. 'ar': 1,
  1690. 'asa': 3,
  1691. 'az': 0,
  1692. 'be': 11,
  1693. 'bem': 3,
  1694. 'bez': 3,
  1695. 'bg': 3,
  1696. 'bh': 4,
  1697. 'bm': 0,
  1698. 'bn': 3,
  1699. 'bo': 0,
  1700. 'br': 20,
  1701. 'brx': 3,
  1702. 'bs': 11,
  1703. 'ca': 3,
  1704. 'cgg': 3,
  1705. 'chr': 3,
  1706. 'cs': 12,
  1707. 'cy': 17,
  1708. 'da': 3,
  1709. 'de': 3,
  1710. 'dv': 3,
  1711. 'dz': 0,
  1712. 'ee': 3,
  1713. 'el': 3,
  1714. 'en': 3,
  1715. 'eo': 3,
  1716. 'es': 3,
  1717. 'et': 3,
  1718. 'eu': 3,
  1719. 'fa': 0,
  1720. 'ff': 5,
  1721. 'fi': 3,
  1722. 'fil': 4,
  1723. 'fo': 3,
  1724. 'fr': 5,
  1725. 'fur': 3,
  1726. 'fy': 3,
  1727. 'ga': 8,
  1728. 'gd': 24,
  1729. 'gl': 3,
  1730. 'gsw': 3,
  1731. 'gu': 3,
  1732. 'guw': 4,
  1733. 'gv': 23,
  1734. 'ha': 3,
  1735. 'haw': 3,
  1736. 'he': 2,
  1737. 'hi': 4,
  1738. 'hr': 11,
  1739. 'hu': 0,
  1740. 'id': 0,
  1741. 'ig': 0,
  1742. 'ii': 0,
  1743. 'is': 3,
  1744. 'it': 3,
  1745. 'iu': 7,
  1746. 'ja': 0,
  1747. 'jmc': 3,
  1748. 'jv': 0,
  1749. 'ka': 0,
  1750. 'kab': 5,
  1751. 'kaj': 3,
  1752. 'kcg': 3,
  1753. 'kde': 0,
  1754. 'kea': 0,
  1755. 'kk': 3,
  1756. 'kl': 3,
  1757. 'km': 0,
  1758. 'kn': 0,
  1759. 'ko': 0,
  1760. 'ksb': 3,
  1761. 'ksh': 21,
  1762. 'ku': 3,
  1763. 'kw': 7,
  1764. 'lag': 18,
  1765. 'lb': 3,
  1766. 'lg': 3,
  1767. 'ln': 4,
  1768. 'lo': 0,
  1769. 'lt': 10,
  1770. 'lv': 6,
  1771. 'mas': 3,
  1772. 'mg': 4,
  1773. 'mk': 16,
  1774. 'ml': 3,
  1775. 'mn': 3,
  1776. 'mo': 9,
  1777. 'mr': 3,
  1778. 'ms': 0,
  1779. 'mt': 15,
  1780. 'my': 0,
  1781. 'nah': 3,
  1782. 'naq': 7,
  1783. 'nb': 3,
  1784. 'nd': 3,
  1785. 'ne': 3,
  1786. 'nl': 3,
  1787. 'nn': 3,
  1788. 'no': 3,
  1789. 'nr': 3,
  1790. 'nso': 4,
  1791. 'ny': 3,
  1792. 'nyn': 3,
  1793. 'om': 3,
  1794. 'or': 3,
  1795. 'pa': 3,
  1796. 'pap': 3,
  1797. 'pl': 13,
  1798. 'ps': 3,
  1799. 'pt': 3,
  1800. 'rm': 3,
  1801. 'ro': 9,
  1802. 'rof': 3,
  1803. 'ru': 11,
  1804. 'rwk': 3,
  1805. 'sah': 0,
  1806. 'saq': 3,
  1807. 'se': 7,
  1808. 'seh': 3,
  1809. 'ses': 0,
  1810. 'sg': 0,
  1811. 'sh': 11,
  1812. 'shi': 19,
  1813. 'sk': 12,
  1814. 'sl': 14,
  1815. 'sma': 7,
  1816. 'smi': 7,
  1817. 'smj': 7,
  1818. 'smn': 7,
  1819. 'sms': 7,
  1820. 'sn': 3,
  1821. 'so': 3,
  1822. 'sq': 3,
  1823. 'sr': 11,
  1824. 'ss': 3,
  1825. 'ssy': 3,
  1826. 'st': 3,
  1827. 'sv': 3,
  1828. 'sw': 3,
  1829. 'syr': 3,
  1830. 'ta': 3,
  1831. 'te': 3,
  1832. 'teo': 3,
  1833. 'th': 0,
  1834. 'ti': 4,
  1835. 'tig': 3,
  1836. 'tk': 3,
  1837. 'tl': 4,
  1838. 'tn': 3,
  1839. 'to': 0,
  1840. 'tr': 0,
  1841. 'ts': 3,
  1842. 'tzm': 22,
  1843. 'uk': 11,
  1844. 'ur': 3,
  1845. 've': 3,
  1846. 'vi': 0,
  1847. 'vun': 3,
  1848. 'wa': 4,
  1849. 'wae': 3,
  1850. 'wo': 0,
  1851. 'xh': 3,
  1852. 'xog': 3,
  1853. 'yo': 0,
  1854. 'zh': 0,
  1855. 'zu': 3
  1856. };
  1857. function isIn(n, list) {
  1858. return list.indexOf(n) !== -1;
  1859. }
  1860. function isBetween(n, start, end) {
  1861. return start <= n && n <= end;
  1862. }
  1863. var pluralRules = {
  1864. '0': function (n) {
  1865. return 'other';
  1866. },
  1867. '1': function (n) {
  1868. if (isBetween(n % 100, 3, 10)) return 'few';
  1869. if (n === 0) return 'zero';
  1870. if (isBetween(n % 100, 11, 99)) return 'many';
  1871. if (n == 2) return 'two';
  1872. if (n == 1) return 'one';
  1873. return 'other';
  1874. },
  1875. '2': function (n) {
  1876. if (n !== 0 && n % 10 === 0) return 'many';
  1877. if (n == 2) return 'two';
  1878. if (n == 1) return 'one';
  1879. return 'other';
  1880. },
  1881. '3': function (n) {
  1882. if (n == 1) return 'one';
  1883. return 'other';
  1884. },
  1885. '4': function (n) {
  1886. if (isBetween(n, 0, 1)) return 'one';
  1887. return 'other';
  1888. },
  1889. '5': function (n) {
  1890. if (isBetween(n, 0, 2) && n != 2) return 'one';
  1891. return 'other';
  1892. },
  1893. '6': function (n) {
  1894. if (n === 0) return 'zero';
  1895. if (n % 10 == 1 && n % 100 != 11) return 'one';
  1896. return 'other';
  1897. },
  1898. '7': function (n) {
  1899. if (n == 2) return 'two';
  1900. if (n == 1) return 'one';
  1901. return 'other';
  1902. },
  1903. '8': function (n) {
  1904. if (isBetween(n, 3, 6)) return 'few';
  1905. if (isBetween(n, 7, 10)) return 'many';
  1906. if (n == 2) return 'two';
  1907. if (n == 1) return 'one';
  1908. return 'other';
  1909. },
  1910. '9': function (n) {
  1911. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  1912. if (n == 1) return 'one';
  1913. return 'other';
  1914. },
  1915. '10': function (n) {
  1916. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  1917. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  1918. return 'other';
  1919. },
  1920. '11': function (n) {
  1921. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  1922. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  1923. if (n % 10 == 1 && n % 100 != 11) return 'one';
  1924. return 'other';
  1925. },
  1926. '12': function (n) {
  1927. if (isBetween(n, 2, 4)) return 'few';
  1928. if (n == 1) return 'one';
  1929. return 'other';
  1930. },
  1931. '13': function (n) {
  1932. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  1933. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  1934. if (n == 1) return 'one';
  1935. return 'other';
  1936. },
  1937. '14': function (n) {
  1938. if (isBetween(n % 100, 3, 4)) return 'few';
  1939. if (n % 100 == 2) return 'two';
  1940. if (n % 100 == 1) return 'one';
  1941. return 'other';
  1942. },
  1943. '15': function (n) {
  1944. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  1945. if (isBetween(n % 100, 11, 19)) return 'many';
  1946. if (n == 1) return 'one';
  1947. return 'other';
  1948. },
  1949. '16': function (n) {
  1950. if (n % 10 == 1 && n != 11) return 'one';
  1951. return 'other';
  1952. },
  1953. '17': function (n) {
  1954. if (n == 3) return 'few';
  1955. if (n === 0) return 'zero';
  1956. if (n == 6) return 'many';
  1957. if (n == 2) return 'two';
  1958. if (n == 1) return 'one';
  1959. return 'other';
  1960. },
  1961. '18': function (n) {
  1962. if (n === 0) return 'zero';
  1963. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  1964. return 'other';
  1965. },
  1966. '19': function (n) {
  1967. if (isBetween(n, 2, 10)) return 'few';
  1968. if (isBetween(n, 0, 1)) return 'one';
  1969. return 'other';
  1970. },
  1971. '20': function (n) {
  1972. 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';
  1973. if (n % 1000000 === 0 && n !== 0) return 'many';
  1974. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  1975. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  1976. return 'other';
  1977. },
  1978. '21': function (n) {
  1979. if (n === 0) return 'zero';
  1980. if (n == 1) return 'one';
  1981. return 'other';
  1982. },
  1983. '22': function (n) {
  1984. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  1985. return 'other';
  1986. },
  1987. '23': function (n) {
  1988. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  1989. return 'other';
  1990. },
  1991. '24': function (n) {
  1992. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  1993. if (isIn(n, [2, 12])) return 'two';
  1994. if (isIn(n, [1, 11])) return 'one';
  1995. return 'other';
  1996. }
  1997. };
  1998. var index = locales2rules[lang.replace(/-.*$/, '')];
  1999. if (!(index in pluralRules)) {
  2000. console.warn('plural form unknown for [' + lang + ']');
  2001. return function () {
  2002. return 'other';
  2003. };
  2004. }
  2005. return pluralRules[index];
  2006. }
  2007. gMacros.plural = function (str, param, key, prop) {
  2008. var n = parseFloat(param);
  2009. if (isNaN(n)) return str;
  2010. if (prop != gTextProp) return str;
  2011. if (!gMacros._pluralRules) {
  2012. gMacros._pluralRules = getPluralRules(gLanguage);
  2013. }
  2014. var index = '[' + gMacros._pluralRules(n) + ']';
  2015. if (n === 0 && key + '[zero]' in gL10nData) {
  2016. str = gL10nData[key + '[zero]'][prop];
  2017. } else if (n == 1 && key + '[one]' in gL10nData) {
  2018. str = gL10nData[key + '[one]'][prop];
  2019. } else if (n == 2 && key + '[two]' in gL10nData) {
  2020. str = gL10nData[key + '[two]'][prop];
  2021. } else if (key + index in gL10nData) {
  2022. str = gL10nData[key + index][prop];
  2023. } else if (key + '[other]' in gL10nData) {
  2024. str = gL10nData[key + '[other]'][prop];
  2025. }
  2026. return str;
  2027. };
  2028. function getL10nData(key, args, fallback) {
  2029. var data = gL10nData[key];
  2030. if (!data) {
  2031. console.warn('#' + key + ' is undefined.');
  2032. if (!fallback) {
  2033. return null;
  2034. }
  2035. data = fallback;
  2036. }
  2037. var rv = {};
  2038. for (var prop in data) {
  2039. var str = data[prop];
  2040. str = substIndexes(str, args, key, prop);
  2041. str = substArguments(str, args, key);
  2042. rv[prop] = str;
  2043. }
  2044. return rv;
  2045. }
  2046. function substIndexes(str, args, key, prop) {
  2047. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  2048. var reMatch = reIndex.exec(str);
  2049. if (!reMatch || !reMatch.length) return str;
  2050. var macroName = reMatch[1];
  2051. var paramName = reMatch[2];
  2052. var param;
  2053. if (args && paramName in args) {
  2054. param = args[paramName];
  2055. } else if (paramName in gL10nData) {
  2056. param = gL10nData[paramName];
  2057. }
  2058. if (macroName in gMacros) {
  2059. var macro = gMacros[macroName];
  2060. str = macro(str, param, key, prop);
  2061. }
  2062. return str;
  2063. }
  2064. function substArguments(str, args, key) {
  2065. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  2066. return str.replace(reArgs, function (matched_text, arg) {
  2067. if (args && arg in args) {
  2068. return args[arg];
  2069. }
  2070. if (arg in gL10nData) {
  2071. return gL10nData[arg];
  2072. }
  2073. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  2074. return matched_text;
  2075. });
  2076. }
  2077. function translateElement(element) {
  2078. var l10n = getL10nAttributes(element);
  2079. if (!l10n.id) return;
  2080. var data = getL10nData(l10n.id, l10n.args);
  2081. if (!data) {
  2082. console.warn('#' + l10n.id + ' is undefined.');
  2083. return;
  2084. }
  2085. if (data[gTextProp]) {
  2086. if (getChildElementCount(element) === 0) {
  2087. element[gTextProp] = data[gTextProp];
  2088. } else {
  2089. var children = element.childNodes;
  2090. var found = false;
  2091. for (var i = 0, l = children.length; i < l; i++) {
  2092. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  2093. if (found) {
  2094. children[i].nodeValue = '';
  2095. } else {
  2096. children[i].nodeValue = data[gTextProp];
  2097. found = true;
  2098. }
  2099. }
  2100. }
  2101. if (!found) {
  2102. var textNode = document.createTextNode(data[gTextProp]);
  2103. element.prepend(textNode);
  2104. }
  2105. }
  2106. delete data[gTextProp];
  2107. }
  2108. for (var k in data) {
  2109. element[k] = data[k];
  2110. }
  2111. }
  2112. function getChildElementCount(element) {
  2113. if (element.children) {
  2114. return element.children.length;
  2115. }
  2116. if (typeof element.childElementCount !== 'undefined') {
  2117. return element.childElementCount;
  2118. }
  2119. var count = 0;
  2120. for (var i = 0; i < element.childNodes.length; i++) {
  2121. count += element.nodeType === 1 ? 1 : 0;
  2122. }
  2123. return count;
  2124. }
  2125. function translateFragment(element) {
  2126. element = element || document.documentElement;
  2127. var children = getTranslatableChildren(element);
  2128. var elementCount = children.length;
  2129. for (var i = 0; i < elementCount; i++) {
  2130. translateElement(children[i]);
  2131. }
  2132. translateElement(element);
  2133. }
  2134. return {
  2135. get: function (key, args, fallbackString) {
  2136. var index = key.lastIndexOf('.');
  2137. var prop = gTextProp;
  2138. if (index > 0) {
  2139. prop = key.substring(index + 1);
  2140. key = key.substring(0, index);
  2141. }
  2142. var fallback;
  2143. if (fallbackString) {
  2144. fallback = {};
  2145. fallback[prop] = fallbackString;
  2146. }
  2147. var data = getL10nData(key, args, fallback);
  2148. if (data && prop in data) {
  2149. return data[prop];
  2150. }
  2151. return '{{' + key + '}}';
  2152. },
  2153. getData: function () {
  2154. return gL10nData;
  2155. },
  2156. getText: function () {
  2157. return gTextData;
  2158. },
  2159. getLanguage: function () {
  2160. return gLanguage;
  2161. },
  2162. setLanguage: function (lang, callback) {
  2163. loadLocale(lang, function () {
  2164. if (callback) callback();
  2165. });
  2166. },
  2167. getDirection: function () {
  2168. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  2169. var shortCode = gLanguage.split('-', 1)[0];
  2170. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  2171. },
  2172. translate: translateFragment,
  2173. getReadyState: function () {
  2174. return gReadyState;
  2175. },
  2176. ready: function (callback) {
  2177. if (!callback) {
  2178. return;
  2179. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  2180. window.setTimeout(function () {
  2181. callback();
  2182. });
  2183. } else if (document.addEventListener) {
  2184. document.addEventListener('localized', function once() {
  2185. document.removeEventListener('localized', once);
  2186. callback();
  2187. });
  2188. }
  2189. }
  2190. };
  2191. }(window, document);
  2192. /***/ }),
  2193. /* 10 */
  2194. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2195. Object.defineProperty(exports, "__esModule", ({
  2196. value: true
  2197. }));
  2198. exports.PDFFindController = exports.FindState = void 0;
  2199. var _ui_utils = __w_pdfjs_require__(2);
  2200. var _pdfjsLib = __w_pdfjs_require__(4);
  2201. var _pdf_find_utils = __w_pdfjs_require__(11);
  2202. const FindState = {
  2203. FOUND: 0,
  2204. NOT_FOUND: 1,
  2205. WRAPPED: 2,
  2206. PENDING: 3
  2207. };
  2208. exports.FindState = FindState;
  2209. const FIND_TIMEOUT = 250;
  2210. const MATCH_SCROLL_OFFSET_TOP = -50;
  2211. const MATCH_SCROLL_OFFSET_LEFT = -400;
  2212. const CHARACTERS_TO_NORMALIZE = {
  2213. "\u2010": "-",
  2214. "\u2018": "'",
  2215. "\u2019": "'",
  2216. "\u201A": "'",
  2217. "\u201B": "'",
  2218. "\u201C": '"',
  2219. "\u201D": '"',
  2220. "\u201E": '"',
  2221. "\u201F": '"',
  2222. "\u00BC": "1/4",
  2223. "\u00BD": "1/2",
  2224. "\u00BE": "3/4"
  2225. };
  2226. const DIACRITICS_EXCEPTION = new Set([0x3099, 0x309a, 0x094d, 0x09cd, 0x0a4d, 0x0acd, 0x0b4d, 0x0bcd, 0x0c4d, 0x0ccd, 0x0d3b, 0x0d3c, 0x0d4d, 0x0dca, 0x0e3a, 0x0eba, 0x0f84, 0x1039, 0x103a, 0x1714, 0x1734, 0x17d2, 0x1a60, 0x1b44, 0x1baa, 0x1bab, 0x1bf2, 0x1bf3, 0x2d7f, 0xa806, 0xa82c, 0xa8c4, 0xa953, 0xa9c0, 0xaaf6, 0xabed, 0x0c56, 0x0f71, 0x0f72, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f80, 0x0f74]);
  2227. let DIACRITICS_EXCEPTION_STR;
  2228. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  2229. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  2230. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  2231. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  2232. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  2233. const SYLLABLES_LENGTHS = new Map();
  2234. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  2235. const NFKC_CHARS_TO_NORMALIZE = new Map();
  2236. let noSyllablesRegExp = null;
  2237. let withSyllablesRegExp = null;
  2238. function normalize(text) {
  2239. const syllablePositions = [];
  2240. let m;
  2241. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  2242. let {
  2243. index
  2244. } = m;
  2245. for (const char of m[0]) {
  2246. let len = SYLLABLES_LENGTHS.get(char);
  2247. if (!len) {
  2248. len = char.normalize("NFD").length;
  2249. SYLLABLES_LENGTHS.set(char, len);
  2250. }
  2251. syllablePositions.push([len, index++]);
  2252. }
  2253. }
  2254. let normalizationRegex;
  2255. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  2256. normalizationRegex = noSyllablesRegExp;
  2257. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  2258. normalizationRegex = withSyllablesRegExp;
  2259. } else {
  2260. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  2261. const toNormalizeWithNFKC = "\u2460-\u2473" + "\u24b6-\u24ff" + "\u3244-\u32bf" + "\u32d0-\u32fe" + "\uff00-\uffef";
  2262. const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
  2263. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
  2264. if (syllablePositions.length === 0) {
  2265. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  2266. } else {
  2267. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  2268. }
  2269. }
  2270. const rawDiacriticsPositions = [];
  2271. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  2272. rawDiacriticsPositions.push([m[0].length, m.index]);
  2273. }
  2274. let normalized = text.normalize("NFD");
  2275. const positions = [[0, 0]];
  2276. let rawDiacriticsIndex = 0;
  2277. let syllableIndex = 0;
  2278. let shift = 0;
  2279. let shiftOrigin = 0;
  2280. let eol = 0;
  2281. let hasDiacritics = false;
  2282. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, i) => {
  2283. i -= shiftOrigin;
  2284. if (p1) {
  2285. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  2286. const jj = replacement.length;
  2287. for (let j = 1; j < jj; j++) {
  2288. positions.push([i - shift + j, shift - j]);
  2289. }
  2290. shift -= jj - 1;
  2291. return replacement;
  2292. }
  2293. if (p2) {
  2294. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  2295. if (!replacement) {
  2296. replacement = p2.normalize("NFKC");
  2297. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  2298. }
  2299. const jj = replacement.length;
  2300. for (let j = 1; j < jj; j++) {
  2301. positions.push([i - shift + j, shift - j]);
  2302. }
  2303. shift -= jj - 1;
  2304. return replacement;
  2305. }
  2306. if (p3) {
  2307. const hasTrailingDashEOL = p3.endsWith("\n");
  2308. const len = hasTrailingDashEOL ? p3.length - 2 : p3.length;
  2309. hasDiacritics = true;
  2310. let jj = len;
  2311. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  2312. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  2313. ++rawDiacriticsIndex;
  2314. }
  2315. for (let j = 1; j <= jj; j++) {
  2316. positions.push([i - 1 - shift + j, shift - j]);
  2317. }
  2318. shift -= jj;
  2319. shiftOrigin += jj;
  2320. if (hasTrailingDashEOL) {
  2321. i += len - 1;
  2322. positions.push([i - shift + 1, 1 + shift]);
  2323. shift += 1;
  2324. shiftOrigin += 1;
  2325. eol += 1;
  2326. return p3.slice(0, len);
  2327. }
  2328. return p3;
  2329. }
  2330. if (p4) {
  2331. positions.push([i - shift + 1, 1 + shift]);
  2332. shift += 1;
  2333. shiftOrigin += 1;
  2334. eol += 1;
  2335. return p4.charAt(0);
  2336. }
  2337. if (p5) {
  2338. positions.push([i - shift + 1, shift]);
  2339. shiftOrigin += 1;
  2340. eol += 1;
  2341. return p5.charAt(0);
  2342. }
  2343. if (p6) {
  2344. positions.push([i - shift + 1, shift - 1]);
  2345. shift -= 1;
  2346. shiftOrigin += 1;
  2347. eol += 1;
  2348. return " ";
  2349. }
  2350. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  2351. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  2352. ++syllableIndex;
  2353. for (let j = 1; j <= newCharLen; j++) {
  2354. positions.push([i - (shift - j), shift - j]);
  2355. }
  2356. shift -= newCharLen;
  2357. shiftOrigin += newCharLen;
  2358. }
  2359. return p7;
  2360. });
  2361. positions.push([normalized.length, shift]);
  2362. return [normalized, positions, hasDiacritics];
  2363. }
  2364. function getOriginalIndex(diffs, pos, len) {
  2365. if (!diffs) {
  2366. return [pos, len];
  2367. }
  2368. const start = pos;
  2369. const end = pos + len;
  2370. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  2371. if (diffs[i][0] > start) {
  2372. --i;
  2373. }
  2374. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  2375. if (diffs[j][0] > end) {
  2376. --j;
  2377. }
  2378. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  2379. }
  2380. class PDFFindController {
  2381. constructor({
  2382. linkService,
  2383. eventBus
  2384. }) {
  2385. this._linkService = linkService;
  2386. this._eventBus = eventBus;
  2387. this.#reset();
  2388. eventBus._on("find", this.#onFind.bind(this));
  2389. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  2390. }
  2391. get highlightMatches() {
  2392. return this._highlightMatches;
  2393. }
  2394. get pageMatches() {
  2395. return this._pageMatches;
  2396. }
  2397. get pageMatchesLength() {
  2398. return this._pageMatchesLength;
  2399. }
  2400. get selected() {
  2401. return this._selected;
  2402. }
  2403. get state() {
  2404. return this._state;
  2405. }
  2406. setDocument(pdfDocument) {
  2407. if (this._pdfDocument) {
  2408. this.#reset();
  2409. }
  2410. if (!pdfDocument) {
  2411. return;
  2412. }
  2413. this._pdfDocument = pdfDocument;
  2414. this._firstPageCapability.resolve();
  2415. }
  2416. #onFind(state) {
  2417. if (!state) {
  2418. return;
  2419. }
  2420. const pdfDocument = this._pdfDocument;
  2421. const {
  2422. type
  2423. } = state;
  2424. if (this._state === null || this.#shouldDirtyMatch(state)) {
  2425. this._dirtyMatch = true;
  2426. }
  2427. this._state = state;
  2428. if (type !== "highlightallchange") {
  2429. this.#updateUIState(FindState.PENDING);
  2430. }
  2431. this._firstPageCapability.promise.then(() => {
  2432. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  2433. return;
  2434. }
  2435. this.#extractText();
  2436. const findbarClosed = !this._highlightMatches;
  2437. const pendingTimeout = !!this._findTimeout;
  2438. if (this._findTimeout) {
  2439. clearTimeout(this._findTimeout);
  2440. this._findTimeout = null;
  2441. }
  2442. if (!type) {
  2443. this._findTimeout = setTimeout(() => {
  2444. this.#nextMatch();
  2445. this._findTimeout = null;
  2446. }, FIND_TIMEOUT);
  2447. } else if (this._dirtyMatch) {
  2448. this.#nextMatch();
  2449. } else if (type === "again") {
  2450. this.#nextMatch();
  2451. if (findbarClosed && this._state.highlightAll) {
  2452. this.#updateAllPages();
  2453. }
  2454. } else if (type === "highlightallchange") {
  2455. if (pendingTimeout) {
  2456. this.#nextMatch();
  2457. } else {
  2458. this._highlightMatches = true;
  2459. }
  2460. this.#updateAllPages();
  2461. } else {
  2462. this.#nextMatch();
  2463. }
  2464. });
  2465. }
  2466. scrollMatchIntoView({
  2467. element = null,
  2468. selectedLeft = 0,
  2469. pageIndex = -1,
  2470. matchIndex = -1
  2471. }) {
  2472. if (!this._scrollMatches || !element) {
  2473. return;
  2474. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  2475. return;
  2476. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  2477. return;
  2478. }
  2479. this._scrollMatches = false;
  2480. const spot = {
  2481. top: MATCH_SCROLL_OFFSET_TOP,
  2482. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  2483. };
  2484. (0, _ui_utils.scrollIntoView)(element, spot, true);
  2485. }
  2486. #reset() {
  2487. this._highlightMatches = false;
  2488. this._scrollMatches = false;
  2489. this._pdfDocument = null;
  2490. this._pageMatches = [];
  2491. this._pageMatchesLength = [];
  2492. this._state = null;
  2493. this._selected = {
  2494. pageIdx: -1,
  2495. matchIdx: -1
  2496. };
  2497. this._offset = {
  2498. pageIdx: null,
  2499. matchIdx: null,
  2500. wrapped: false
  2501. };
  2502. this._extractTextPromises = [];
  2503. this._pageContents = [];
  2504. this._pageDiffs = [];
  2505. this._hasDiacritics = [];
  2506. this._matchesCountTotal = 0;
  2507. this._pagesToSearch = null;
  2508. this._pendingFindMatches = new Set();
  2509. this._resumePageIdx = null;
  2510. this._dirtyMatch = false;
  2511. clearTimeout(this._findTimeout);
  2512. this._findTimeout = null;
  2513. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  2514. }
  2515. get #query() {
  2516. if (this._state.query !== this._rawQuery) {
  2517. this._rawQuery = this._state.query;
  2518. [this._normalizedQuery] = normalize(this._state.query);
  2519. }
  2520. return this._normalizedQuery;
  2521. }
  2522. #shouldDirtyMatch(state) {
  2523. if (state.query !== this._state.query) {
  2524. return true;
  2525. }
  2526. switch (state.type) {
  2527. case "again":
  2528. const pageNumber = this._selected.pageIdx + 1;
  2529. const linkService = this._linkService;
  2530. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  2531. return true;
  2532. }
  2533. return false;
  2534. case "highlightallchange":
  2535. return false;
  2536. }
  2537. return true;
  2538. }
  2539. #isEntireWord(content, startIdx, length) {
  2540. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  2541. if (match) {
  2542. const first = content.charCodeAt(startIdx);
  2543. const limit = match[1].charCodeAt(0);
  2544. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  2545. return false;
  2546. }
  2547. }
  2548. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  2549. if (match) {
  2550. const last = content.charCodeAt(startIdx + length - 1);
  2551. const limit = match[1].charCodeAt(0);
  2552. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  2553. return false;
  2554. }
  2555. }
  2556. return true;
  2557. }
  2558. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  2559. const matches = [],
  2560. matchesLength = [];
  2561. const diffs = this._pageDiffs[pageIndex];
  2562. let match;
  2563. while ((match = query.exec(pageContent)) !== null) {
  2564. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  2565. continue;
  2566. }
  2567. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  2568. if (matchLen) {
  2569. matches.push(matchPos);
  2570. matchesLength.push(matchLen);
  2571. }
  2572. }
  2573. this._pageMatches[pageIndex] = matches;
  2574. this._pageMatchesLength[pageIndex] = matchesLength;
  2575. }
  2576. #convertToRegExpString(query, hasDiacritics) {
  2577. const {
  2578. matchDiacritics
  2579. } = this._state;
  2580. let isUnicode = false;
  2581. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  2582. if (p1) {
  2583. return `[ ]*\\${p1}[ ]*`;
  2584. }
  2585. if (p2) {
  2586. return `[ ]*${p2}[ ]*`;
  2587. }
  2588. if (p3) {
  2589. return "[ ]+";
  2590. }
  2591. if (matchDiacritics) {
  2592. return p4 || p5;
  2593. }
  2594. if (p4) {
  2595. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  2596. }
  2597. if (hasDiacritics) {
  2598. isUnicode = true;
  2599. return `${p5}\\p{M}*`;
  2600. }
  2601. return p5;
  2602. });
  2603. const trailingSpaces = "[ ]*";
  2604. if (query.endsWith(trailingSpaces)) {
  2605. query = query.slice(0, query.length - trailingSpaces.length);
  2606. }
  2607. if (matchDiacritics) {
  2608. if (hasDiacritics) {
  2609. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
  2610. isUnicode = true;
  2611. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  2612. }
  2613. }
  2614. return [isUnicode, query];
  2615. }
  2616. #calculateMatch(pageIndex) {
  2617. let query = this.#query;
  2618. if (query.length === 0) {
  2619. return;
  2620. }
  2621. const {
  2622. caseSensitive,
  2623. entireWord,
  2624. phraseSearch
  2625. } = this._state;
  2626. const pageContent = this._pageContents[pageIndex];
  2627. const hasDiacritics = this._hasDiacritics[pageIndex];
  2628. let isUnicode = false;
  2629. if (phraseSearch) {
  2630. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  2631. } else {
  2632. const match = query.match(/\S+/g);
  2633. if (match) {
  2634. query = match.sort().reverse().map(q => {
  2635. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  2636. isUnicode ||= isUnicodePart;
  2637. return `(${queryPart})`;
  2638. }).join("|");
  2639. }
  2640. }
  2641. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  2642. query = new RegExp(query, flags);
  2643. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  2644. if (this._state.highlightAll) {
  2645. this.#updatePage(pageIndex);
  2646. }
  2647. if (this._resumePageIdx === pageIndex) {
  2648. this._resumePageIdx = null;
  2649. this.#nextPageMatch();
  2650. }
  2651. const pageMatchesCount = this._pageMatches[pageIndex].length;
  2652. if (pageMatchesCount > 0) {
  2653. this._matchesCountTotal += pageMatchesCount;
  2654. this.#updateUIResultsCount();
  2655. }
  2656. }
  2657. #extractText() {
  2658. if (this._extractTextPromises.length > 0) {
  2659. return;
  2660. }
  2661. let promise = Promise.resolve();
  2662. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  2663. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  2664. this._extractTextPromises[i] = extractTextCapability.promise;
  2665. promise = promise.then(() => {
  2666. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  2667. return pdfPage.getTextContent();
  2668. }).then(textContent => {
  2669. const strBuf = [];
  2670. for (const textItem of textContent.items) {
  2671. strBuf.push(textItem.str);
  2672. if (textItem.hasEOL) {
  2673. strBuf.push("\n");
  2674. }
  2675. }
  2676. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  2677. extractTextCapability.resolve();
  2678. }, reason => {
  2679. console.error(`Unable to get text content for page ${i + 1}`, reason);
  2680. this._pageContents[i] = "";
  2681. this._pageDiffs[i] = null;
  2682. this._hasDiacritics[i] = false;
  2683. extractTextCapability.resolve();
  2684. });
  2685. });
  2686. }
  2687. }
  2688. #updatePage(index) {
  2689. if (this._scrollMatches && this._selected.pageIdx === index) {
  2690. this._linkService.page = index + 1;
  2691. }
  2692. this._eventBus.dispatch("updatetextlayermatches", {
  2693. source: this,
  2694. pageIndex: index
  2695. });
  2696. }
  2697. #updateAllPages() {
  2698. this._eventBus.dispatch("updatetextlayermatches", {
  2699. source: this,
  2700. pageIndex: -1
  2701. });
  2702. }
  2703. #nextMatch() {
  2704. const previous = this._state.findPrevious;
  2705. const currentPageIndex = this._linkService.page - 1;
  2706. const numPages = this._linkService.pagesCount;
  2707. this._highlightMatches = true;
  2708. if (this._dirtyMatch) {
  2709. this._dirtyMatch = false;
  2710. this._selected.pageIdx = this._selected.matchIdx = -1;
  2711. this._offset.pageIdx = currentPageIndex;
  2712. this._offset.matchIdx = null;
  2713. this._offset.wrapped = false;
  2714. this._resumePageIdx = null;
  2715. this._pageMatches.length = 0;
  2716. this._pageMatchesLength.length = 0;
  2717. this._matchesCountTotal = 0;
  2718. this.#updateAllPages();
  2719. for (let i = 0; i < numPages; i++) {
  2720. if (this._pendingFindMatches.has(i)) {
  2721. continue;
  2722. }
  2723. this._pendingFindMatches.add(i);
  2724. this._extractTextPromises[i].then(() => {
  2725. this._pendingFindMatches.delete(i);
  2726. this.#calculateMatch(i);
  2727. });
  2728. }
  2729. }
  2730. if (this.#query === "") {
  2731. this.#updateUIState(FindState.FOUND);
  2732. return;
  2733. }
  2734. if (this._resumePageIdx) {
  2735. return;
  2736. }
  2737. const offset = this._offset;
  2738. this._pagesToSearch = numPages;
  2739. if (offset.matchIdx !== null) {
  2740. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  2741. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  2742. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  2743. this.#updateMatch(true);
  2744. return;
  2745. }
  2746. this.#advanceOffsetPage(previous);
  2747. }
  2748. this.#nextPageMatch();
  2749. }
  2750. #matchesReady(matches) {
  2751. const offset = this._offset;
  2752. const numMatches = matches.length;
  2753. const previous = this._state.findPrevious;
  2754. if (numMatches) {
  2755. offset.matchIdx = previous ? numMatches - 1 : 0;
  2756. this.#updateMatch(true);
  2757. return true;
  2758. }
  2759. this.#advanceOffsetPage(previous);
  2760. if (offset.wrapped) {
  2761. offset.matchIdx = null;
  2762. if (this._pagesToSearch < 0) {
  2763. this.#updateMatch(false);
  2764. return true;
  2765. }
  2766. }
  2767. return false;
  2768. }
  2769. #nextPageMatch() {
  2770. if (this._resumePageIdx !== null) {
  2771. console.error("There can only be one pending page.");
  2772. }
  2773. let matches = null;
  2774. do {
  2775. const pageIdx = this._offset.pageIdx;
  2776. matches = this._pageMatches[pageIdx];
  2777. if (!matches) {
  2778. this._resumePageIdx = pageIdx;
  2779. break;
  2780. }
  2781. } while (!this.#matchesReady(matches));
  2782. }
  2783. #advanceOffsetPage(previous) {
  2784. const offset = this._offset;
  2785. const numPages = this._linkService.pagesCount;
  2786. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  2787. offset.matchIdx = null;
  2788. this._pagesToSearch--;
  2789. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  2790. offset.pageIdx = previous ? numPages - 1 : 0;
  2791. offset.wrapped = true;
  2792. }
  2793. }
  2794. #updateMatch(found = false) {
  2795. let state = FindState.NOT_FOUND;
  2796. const wrapped = this._offset.wrapped;
  2797. this._offset.wrapped = false;
  2798. if (found) {
  2799. const previousPage = this._selected.pageIdx;
  2800. this._selected.pageIdx = this._offset.pageIdx;
  2801. this._selected.matchIdx = this._offset.matchIdx;
  2802. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  2803. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  2804. this.#updatePage(previousPage);
  2805. }
  2806. }
  2807. this.#updateUIState(state, this._state.findPrevious);
  2808. if (this._selected.pageIdx !== -1) {
  2809. this._scrollMatches = true;
  2810. this.#updatePage(this._selected.pageIdx);
  2811. }
  2812. }
  2813. #onFindBarClose(evt) {
  2814. const pdfDocument = this._pdfDocument;
  2815. this._firstPageCapability.promise.then(() => {
  2816. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  2817. return;
  2818. }
  2819. if (this._findTimeout) {
  2820. clearTimeout(this._findTimeout);
  2821. this._findTimeout = null;
  2822. }
  2823. if (this._resumePageIdx) {
  2824. this._resumePageIdx = null;
  2825. this._dirtyMatch = true;
  2826. }
  2827. this.#updateUIState(FindState.FOUND);
  2828. this._highlightMatches = false;
  2829. this.#updateAllPages();
  2830. });
  2831. }
  2832. #requestMatchesCount() {
  2833. const {
  2834. pageIdx,
  2835. matchIdx
  2836. } = this._selected;
  2837. let current = 0,
  2838. total = this._matchesCountTotal;
  2839. if (matchIdx !== -1) {
  2840. for (let i = 0; i < pageIdx; i++) {
  2841. current += this._pageMatches[i]?.length || 0;
  2842. }
  2843. current += matchIdx + 1;
  2844. }
  2845. if (current < 1 || current > total) {
  2846. current = total = 0;
  2847. }
  2848. return {
  2849. current,
  2850. total
  2851. };
  2852. }
  2853. #updateUIResultsCount() {
  2854. this._eventBus.dispatch("updatefindmatchescount", {
  2855. source: this,
  2856. matchesCount: this.#requestMatchesCount()
  2857. });
  2858. }
  2859. #updateUIState(state, previous = false) {
  2860. this._eventBus.dispatch("updatefindcontrolstate", {
  2861. source: this,
  2862. state,
  2863. previous,
  2864. matchesCount: this.#requestMatchesCount(),
  2865. rawQuery: this._state?.query ?? null
  2866. });
  2867. }
  2868. }
  2869. exports.PDFFindController = PDFFindController;
  2870. /***/ }),
  2871. /* 11 */
  2872. /***/ ((__unused_webpack_module, exports) => {
  2873. Object.defineProperty(exports, "__esModule", ({
  2874. value: true
  2875. }));
  2876. exports.CharacterType = void 0;
  2877. exports.getCharacterType = getCharacterType;
  2878. const CharacterType = {
  2879. SPACE: 0,
  2880. ALPHA_LETTER: 1,
  2881. PUNCT: 2,
  2882. HAN_LETTER: 3,
  2883. KATAKANA_LETTER: 4,
  2884. HIRAGANA_LETTER: 5,
  2885. HALFWIDTH_KATAKANA_LETTER: 6,
  2886. THAI_LETTER: 7
  2887. };
  2888. exports.CharacterType = CharacterType;
  2889. function isAlphabeticalScript(charCode) {
  2890. return charCode < 0x2e80;
  2891. }
  2892. function isAscii(charCode) {
  2893. return (charCode & 0xff80) === 0;
  2894. }
  2895. function isAsciiAlpha(charCode) {
  2896. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  2897. }
  2898. function isAsciiDigit(charCode) {
  2899. return charCode >= 0x30 && charCode <= 0x39;
  2900. }
  2901. function isAsciiSpace(charCode) {
  2902. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  2903. }
  2904. function isHan(charCode) {
  2905. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  2906. }
  2907. function isKatakana(charCode) {
  2908. return charCode >= 0x30a0 && charCode <= 0x30ff;
  2909. }
  2910. function isHiragana(charCode) {
  2911. return charCode >= 0x3040 && charCode <= 0x309f;
  2912. }
  2913. function isHalfwidthKatakana(charCode) {
  2914. return charCode >= 0xff60 && charCode <= 0xff9f;
  2915. }
  2916. function isThai(charCode) {
  2917. return (charCode & 0xff80) === 0x0e00;
  2918. }
  2919. function getCharacterType(charCode) {
  2920. if (isAlphabeticalScript(charCode)) {
  2921. if (isAscii(charCode)) {
  2922. if (isAsciiSpace(charCode)) {
  2923. return CharacterType.SPACE;
  2924. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  2925. return CharacterType.ALPHA_LETTER;
  2926. }
  2927. return CharacterType.PUNCT;
  2928. } else if (isThai(charCode)) {
  2929. return CharacterType.THAI_LETTER;
  2930. } else if (charCode === 0xa0) {
  2931. return CharacterType.SPACE;
  2932. }
  2933. return CharacterType.ALPHA_LETTER;
  2934. }
  2935. if (isHan(charCode)) {
  2936. return CharacterType.HAN_LETTER;
  2937. } else if (isKatakana(charCode)) {
  2938. return CharacterType.KATAKANA_LETTER;
  2939. } else if (isHiragana(charCode)) {
  2940. return CharacterType.HIRAGANA_LETTER;
  2941. } else if (isHalfwidthKatakana(charCode)) {
  2942. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  2943. }
  2944. return CharacterType.ALPHA_LETTER;
  2945. }
  2946. /***/ }),
  2947. /* 12 */
  2948. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2949. Object.defineProperty(exports, "__esModule", ({
  2950. value: true
  2951. }));
  2952. exports.PDFHistory = void 0;
  2953. exports.isDestArraysEqual = isDestArraysEqual;
  2954. exports.isDestHashesEqual = isDestHashesEqual;
  2955. var _ui_utils = __w_pdfjs_require__(2);
  2956. var _event_utils = __w_pdfjs_require__(7);
  2957. const HASH_CHANGE_TIMEOUT = 1000;
  2958. const POSITION_UPDATED_THRESHOLD = 50;
  2959. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  2960. function getCurrentHash() {
  2961. return document.location.hash;
  2962. }
  2963. class PDFHistory {
  2964. constructor({
  2965. linkService,
  2966. eventBus
  2967. }) {
  2968. this.linkService = linkService;
  2969. this.eventBus = eventBus;
  2970. this._initialized = false;
  2971. this._fingerprint = "";
  2972. this.reset();
  2973. this._boundEvents = null;
  2974. this.eventBus._on("pagesinit", () => {
  2975. this._isPagesLoaded = false;
  2976. this.eventBus._on("pagesloaded", evt => {
  2977. this._isPagesLoaded = !!evt.pagesCount;
  2978. }, {
  2979. once: true
  2980. });
  2981. });
  2982. }
  2983. initialize({
  2984. fingerprint,
  2985. resetHistory = false,
  2986. updateUrl = false
  2987. }) {
  2988. if (!fingerprint || typeof fingerprint !== "string") {
  2989. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  2990. return;
  2991. }
  2992. if (this._initialized) {
  2993. this.reset();
  2994. }
  2995. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  2996. this._fingerprint = fingerprint;
  2997. this._updateUrl = updateUrl === true;
  2998. this._initialized = true;
  2999. this._bindEvents();
  3000. const state = window.history.state;
  3001. this._popStateInProgress = false;
  3002. this._blockHashChange = 0;
  3003. this._currentHash = getCurrentHash();
  3004. this._numPositionUpdates = 0;
  3005. this._uid = this._maxUid = 0;
  3006. this._destination = null;
  3007. this._position = null;
  3008. if (!this._isValidState(state, true) || resetHistory) {
  3009. const {
  3010. hash,
  3011. page,
  3012. rotation
  3013. } = this._parseCurrentHash(true);
  3014. if (!hash || reInitialized || resetHistory) {
  3015. this._pushOrReplaceState(null, true);
  3016. return;
  3017. }
  3018. this._pushOrReplaceState({
  3019. hash,
  3020. page,
  3021. rotation
  3022. }, true);
  3023. return;
  3024. }
  3025. const destination = state.destination;
  3026. this._updateInternalState(destination, state.uid, true);
  3027. if (destination.rotation !== undefined) {
  3028. this._initialRotation = destination.rotation;
  3029. }
  3030. if (destination.dest) {
  3031. this._initialBookmark = JSON.stringify(destination.dest);
  3032. this._destination.page = null;
  3033. } else if (destination.hash) {
  3034. this._initialBookmark = destination.hash;
  3035. } else if (destination.page) {
  3036. this._initialBookmark = `page=${destination.page}`;
  3037. }
  3038. }
  3039. reset() {
  3040. if (this._initialized) {
  3041. this._pageHide();
  3042. this._initialized = false;
  3043. this._unbindEvents();
  3044. }
  3045. if (this._updateViewareaTimeout) {
  3046. clearTimeout(this._updateViewareaTimeout);
  3047. this._updateViewareaTimeout = null;
  3048. }
  3049. this._initialBookmark = null;
  3050. this._initialRotation = null;
  3051. }
  3052. push({
  3053. namedDest = null,
  3054. explicitDest,
  3055. pageNumber
  3056. }) {
  3057. if (!this._initialized) {
  3058. return;
  3059. }
  3060. if (namedDest && typeof namedDest !== "string") {
  3061. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  3062. return;
  3063. } else if (!Array.isArray(explicitDest)) {
  3064. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  3065. return;
  3066. } else if (!this._isValidPage(pageNumber)) {
  3067. if (pageNumber !== null || this._destination) {
  3068. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  3069. return;
  3070. }
  3071. }
  3072. const hash = namedDest || JSON.stringify(explicitDest);
  3073. if (!hash) {
  3074. return;
  3075. }
  3076. let forceReplace = false;
  3077. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  3078. if (this._destination.page) {
  3079. return;
  3080. }
  3081. forceReplace = true;
  3082. }
  3083. if (this._popStateInProgress && !forceReplace) {
  3084. return;
  3085. }
  3086. this._pushOrReplaceState({
  3087. dest: explicitDest,
  3088. hash,
  3089. page: pageNumber,
  3090. rotation: this.linkService.rotation
  3091. }, forceReplace);
  3092. if (!this._popStateInProgress) {
  3093. this._popStateInProgress = true;
  3094. Promise.resolve().then(() => {
  3095. this._popStateInProgress = false;
  3096. });
  3097. }
  3098. }
  3099. pushPage(pageNumber) {
  3100. if (!this._initialized) {
  3101. return;
  3102. }
  3103. if (!this._isValidPage(pageNumber)) {
  3104. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  3105. return;
  3106. }
  3107. if (this._destination?.page === pageNumber) {
  3108. return;
  3109. }
  3110. if (this._popStateInProgress) {
  3111. return;
  3112. }
  3113. this._pushOrReplaceState({
  3114. dest: null,
  3115. hash: `page=${pageNumber}`,
  3116. page: pageNumber,
  3117. rotation: this.linkService.rotation
  3118. });
  3119. if (!this._popStateInProgress) {
  3120. this._popStateInProgress = true;
  3121. Promise.resolve().then(() => {
  3122. this._popStateInProgress = false;
  3123. });
  3124. }
  3125. }
  3126. pushCurrentPosition() {
  3127. if (!this._initialized || this._popStateInProgress) {
  3128. return;
  3129. }
  3130. this._tryPushCurrentPosition();
  3131. }
  3132. back() {
  3133. if (!this._initialized || this._popStateInProgress) {
  3134. return;
  3135. }
  3136. const state = window.history.state;
  3137. if (this._isValidState(state) && state.uid > 0) {
  3138. window.history.back();
  3139. }
  3140. }
  3141. forward() {
  3142. if (!this._initialized || this._popStateInProgress) {
  3143. return;
  3144. }
  3145. const state = window.history.state;
  3146. if (this._isValidState(state) && state.uid < this._maxUid) {
  3147. window.history.forward();
  3148. }
  3149. }
  3150. get popStateInProgress() {
  3151. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  3152. }
  3153. get initialBookmark() {
  3154. return this._initialized ? this._initialBookmark : null;
  3155. }
  3156. get initialRotation() {
  3157. return this._initialized ? this._initialRotation : null;
  3158. }
  3159. _pushOrReplaceState(destination, forceReplace = false) {
  3160. const shouldReplace = forceReplace || !this._destination;
  3161. const newState = {
  3162. fingerprint: this._fingerprint,
  3163. uid: shouldReplace ? this._uid : this._uid + 1,
  3164. destination
  3165. };
  3166. this._updateInternalState(destination, newState.uid);
  3167. let newUrl;
  3168. if (this._updateUrl && destination?.hash) {
  3169. const baseUrl = document.location.href.split("#")[0];
  3170. if (!baseUrl.startsWith("file://")) {
  3171. newUrl = `${baseUrl}#${destination.hash}`;
  3172. }
  3173. }
  3174. if (shouldReplace) {
  3175. window.history.replaceState(newState, "", newUrl);
  3176. } else {
  3177. window.history.pushState(newState, "", newUrl);
  3178. }
  3179. }
  3180. _tryPushCurrentPosition(temporary = false) {
  3181. if (!this._position) {
  3182. return;
  3183. }
  3184. let position = this._position;
  3185. if (temporary) {
  3186. position = Object.assign(Object.create(null), this._position);
  3187. position.temporary = true;
  3188. }
  3189. if (!this._destination) {
  3190. this._pushOrReplaceState(position);
  3191. return;
  3192. }
  3193. if (this._destination.temporary) {
  3194. this._pushOrReplaceState(position, true);
  3195. return;
  3196. }
  3197. if (this._destination.hash === position.hash) {
  3198. return;
  3199. }
  3200. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  3201. return;
  3202. }
  3203. let forceReplace = false;
  3204. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  3205. if (this._destination.dest !== undefined || !this._destination.first) {
  3206. return;
  3207. }
  3208. forceReplace = true;
  3209. }
  3210. this._pushOrReplaceState(position, forceReplace);
  3211. }
  3212. _isValidPage(val) {
  3213. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  3214. }
  3215. _isValidState(state, checkReload = false) {
  3216. if (!state) {
  3217. return false;
  3218. }
  3219. if (state.fingerprint !== this._fingerprint) {
  3220. if (checkReload) {
  3221. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  3222. return false;
  3223. }
  3224. const [perfEntry] = performance.getEntriesByType("navigation");
  3225. if (perfEntry?.type !== "reload") {
  3226. return false;
  3227. }
  3228. } else {
  3229. return false;
  3230. }
  3231. }
  3232. if (!Number.isInteger(state.uid) || state.uid < 0) {
  3233. return false;
  3234. }
  3235. if (state.destination === null || typeof state.destination !== "object") {
  3236. return false;
  3237. }
  3238. return true;
  3239. }
  3240. _updateInternalState(destination, uid, removeTemporary = false) {
  3241. if (this._updateViewareaTimeout) {
  3242. clearTimeout(this._updateViewareaTimeout);
  3243. this._updateViewareaTimeout = null;
  3244. }
  3245. if (removeTemporary && destination?.temporary) {
  3246. delete destination.temporary;
  3247. }
  3248. this._destination = destination;
  3249. this._uid = uid;
  3250. this._maxUid = Math.max(this._maxUid, uid);
  3251. this._numPositionUpdates = 0;
  3252. }
  3253. _parseCurrentHash(checkNameddest = false) {
  3254. const hash = unescape(getCurrentHash()).substring(1);
  3255. const params = (0, _ui_utils.parseQueryString)(hash);
  3256. const nameddest = params.get("nameddest") || "";
  3257. let page = params.get("page") | 0;
  3258. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  3259. page = null;
  3260. }
  3261. return {
  3262. hash,
  3263. page,
  3264. rotation: this.linkService.rotation
  3265. };
  3266. }
  3267. _updateViewarea({
  3268. location
  3269. }) {
  3270. if (this._updateViewareaTimeout) {
  3271. clearTimeout(this._updateViewareaTimeout);
  3272. this._updateViewareaTimeout = null;
  3273. }
  3274. this._position = {
  3275. hash: location.pdfOpenParams.substring(1),
  3276. page: this.linkService.page,
  3277. first: location.pageNumber,
  3278. rotation: location.rotation
  3279. };
  3280. if (this._popStateInProgress) {
  3281. return;
  3282. }
  3283. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  3284. this._numPositionUpdates++;
  3285. }
  3286. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  3287. this._updateViewareaTimeout = setTimeout(() => {
  3288. if (!this._popStateInProgress) {
  3289. this._tryPushCurrentPosition(true);
  3290. }
  3291. this._updateViewareaTimeout = null;
  3292. }, UPDATE_VIEWAREA_TIMEOUT);
  3293. }
  3294. }
  3295. _popState({
  3296. state
  3297. }) {
  3298. const newHash = getCurrentHash(),
  3299. hashChanged = this._currentHash !== newHash;
  3300. this._currentHash = newHash;
  3301. if (!state) {
  3302. this._uid++;
  3303. const {
  3304. hash,
  3305. page,
  3306. rotation
  3307. } = this._parseCurrentHash();
  3308. this._pushOrReplaceState({
  3309. hash,
  3310. page,
  3311. rotation
  3312. }, true);
  3313. return;
  3314. }
  3315. if (!this._isValidState(state)) {
  3316. return;
  3317. }
  3318. this._popStateInProgress = true;
  3319. if (hashChanged) {
  3320. this._blockHashChange++;
  3321. (0, _event_utils.waitOnEventOrTimeout)({
  3322. target: window,
  3323. name: "hashchange",
  3324. delay: HASH_CHANGE_TIMEOUT
  3325. }).then(() => {
  3326. this._blockHashChange--;
  3327. });
  3328. }
  3329. const destination = state.destination;
  3330. this._updateInternalState(destination, state.uid, true);
  3331. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  3332. this.linkService.rotation = destination.rotation;
  3333. }
  3334. if (destination.dest) {
  3335. this.linkService.goToDestination(destination.dest);
  3336. } else if (destination.hash) {
  3337. this.linkService.setHash(destination.hash);
  3338. } else if (destination.page) {
  3339. this.linkService.page = destination.page;
  3340. }
  3341. Promise.resolve().then(() => {
  3342. this._popStateInProgress = false;
  3343. });
  3344. }
  3345. _pageHide() {
  3346. if (!this._destination || this._destination.temporary) {
  3347. this._tryPushCurrentPosition();
  3348. }
  3349. }
  3350. _bindEvents() {
  3351. if (this._boundEvents) {
  3352. return;
  3353. }
  3354. this._boundEvents = {
  3355. updateViewarea: this._updateViewarea.bind(this),
  3356. popState: this._popState.bind(this),
  3357. pageHide: this._pageHide.bind(this)
  3358. };
  3359. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  3360. window.addEventListener("popstate", this._boundEvents.popState);
  3361. window.addEventListener("pagehide", this._boundEvents.pageHide);
  3362. }
  3363. _unbindEvents() {
  3364. if (!this._boundEvents) {
  3365. return;
  3366. }
  3367. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  3368. window.removeEventListener("popstate", this._boundEvents.popState);
  3369. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  3370. this._boundEvents = null;
  3371. }
  3372. }
  3373. exports.PDFHistory = PDFHistory;
  3374. function isDestHashesEqual(destHash, pushHash) {
  3375. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  3376. return false;
  3377. }
  3378. if (destHash === pushHash) {
  3379. return true;
  3380. }
  3381. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  3382. if (nameddest === pushHash) {
  3383. return true;
  3384. }
  3385. return false;
  3386. }
  3387. function isDestArraysEqual(firstDest, secondDest) {
  3388. function isEntryEqual(first, second) {
  3389. if (typeof first !== typeof second) {
  3390. return false;
  3391. }
  3392. if (Array.isArray(first) || Array.isArray(second)) {
  3393. return false;
  3394. }
  3395. if (first !== null && typeof first === "object" && second !== null) {
  3396. if (Object.keys(first).length !== Object.keys(second).length) {
  3397. return false;
  3398. }
  3399. for (const key in first) {
  3400. if (!isEntryEqual(first[key], second[key])) {
  3401. return false;
  3402. }
  3403. }
  3404. return true;
  3405. }
  3406. return first === second || Number.isNaN(first) && Number.isNaN(second);
  3407. }
  3408. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  3409. return false;
  3410. }
  3411. if (firstDest.length !== secondDest.length) {
  3412. return false;
  3413. }
  3414. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  3415. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  3416. return false;
  3417. }
  3418. }
  3419. return true;
  3420. }
  3421. /***/ }),
  3422. /* 13 */
  3423. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3424. Object.defineProperty(exports, "__esModule", ({
  3425. value: true
  3426. }));
  3427. exports.PDFPageView = void 0;
  3428. var _pdfjsLib = __w_pdfjs_require__(4);
  3429. var _ui_utils = __w_pdfjs_require__(2);
  3430. var _annotation_editor_layer_builder = __w_pdfjs_require__(14);
  3431. var _annotation_layer_builder = __w_pdfjs_require__(3);
  3432. var _app_options = __w_pdfjs_require__(15);
  3433. var _l10n_utils = __w_pdfjs_require__(5);
  3434. var _struct_tree_layer_builder = __w_pdfjs_require__(16);
  3435. var _text_accessibility = __w_pdfjs_require__(17);
  3436. var _text_highlighter = __w_pdfjs_require__(18);
  3437. var _text_layer_builder = __w_pdfjs_require__(19);
  3438. var _xfa_layer_builder = __w_pdfjs_require__(20);
  3439. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  3440. const DEFAULT_LAYER_PROPERTIES = () => {
  3441. return {
  3442. annotationEditorUIManager: null,
  3443. annotationStorage: null,
  3444. downloadManager: null,
  3445. enableScripting: false,
  3446. fieldObjectsPromise: null,
  3447. findController: null,
  3448. hasJSActionsPromise: null,
  3449. get linkService() {
  3450. const {
  3451. SimpleLinkService
  3452. } = __w_pdfjs_require__(1);
  3453. return new SimpleLinkService();
  3454. }
  3455. };
  3456. };
  3457. class PDFPageView {
  3458. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  3459. #layerProperties = null;
  3460. #previousRotation = null;
  3461. #renderingState = _ui_utils.RenderingStates.INITIAL;
  3462. #useThumbnailCanvas = {
  3463. initialOptionalContent: true,
  3464. regularAnnotations: true
  3465. };
  3466. constructor(options) {
  3467. const container = options.container;
  3468. const defaultViewport = options.defaultViewport;
  3469. this.id = options.id;
  3470. this.renderingId = "page" + this.id;
  3471. this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
  3472. this.pdfPage = null;
  3473. this.pageLabel = null;
  3474. this.rotation = 0;
  3475. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  3476. this.viewport = defaultViewport;
  3477. this.pdfPageRotate = defaultViewport.rotation;
  3478. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  3479. this.hasRestrictedScaling = false;
  3480. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  3481. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  3482. this.imageResourcesPath = options.imageResourcesPath || "";
  3483. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  3484. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  3485. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  3486. this.pageColors = options.pageColors || null;
  3487. this.eventBus = options.eventBus;
  3488. this.renderingQueue = options.renderingQueue;
  3489. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  3490. this.l10n = options.l10n || _l10n_utils.NullL10n;
  3491. this.paintTask = null;
  3492. this.paintedViewportMap = new WeakMap();
  3493. this.resume = null;
  3494. this._renderError = null;
  3495. this._isStandalone = !this.renderingQueue?.hasViewer();
  3496. this._annotationCanvasMap = null;
  3497. this.annotationLayer = null;
  3498. this.annotationEditorLayer = null;
  3499. this.textLayer = null;
  3500. this.zoomLayer = null;
  3501. this.xfaLayer = null;
  3502. this.structTreeLayer = null;
  3503. const div = document.createElement("div");
  3504. div.className = "page";
  3505. div.setAttribute("data-page-number", this.id);
  3506. div.setAttribute("role", "region");
  3507. this.l10n.get("page_landmark", {
  3508. page: this.id
  3509. }).then(msg => {
  3510. div.setAttribute("aria-label", msg);
  3511. });
  3512. this.div = div;
  3513. this.#setDimensions();
  3514. container?.append(div);
  3515. if (this._isStandalone) {
  3516. _ui_utils.docStyle.setProperty("--scale-factor", this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  3517. const {
  3518. optionalContentConfigPromise
  3519. } = options;
  3520. if (optionalContentConfigPromise) {
  3521. optionalContentConfigPromise.then(optionalContentConfig => {
  3522. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  3523. return;
  3524. }
  3525. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  3526. });
  3527. }
  3528. }
  3529. }
  3530. get renderingState() {
  3531. return this.#renderingState;
  3532. }
  3533. set renderingState(state) {
  3534. this.#renderingState = state;
  3535. switch (state) {
  3536. case _ui_utils.RenderingStates.INITIAL:
  3537. case _ui_utils.RenderingStates.PAUSED:
  3538. this.loadingIconDiv?.classList.add("notVisible");
  3539. break;
  3540. case _ui_utils.RenderingStates.RUNNING:
  3541. this.loadingIconDiv?.classList.remove("notVisible");
  3542. break;
  3543. case _ui_utils.RenderingStates.FINISHED:
  3544. if (this.loadingIconDiv) {
  3545. this.loadingIconDiv.remove();
  3546. delete this.loadingIconDiv;
  3547. }
  3548. break;
  3549. }
  3550. }
  3551. #setDimensions() {
  3552. const {
  3553. viewport
  3554. } = this;
  3555. if (this.pdfPage) {
  3556. if (this.#previousRotation === viewport.rotation) {
  3557. return;
  3558. }
  3559. this.#previousRotation = viewport.rotation;
  3560. }
  3561. (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false);
  3562. }
  3563. setPdfPage(pdfPage) {
  3564. this.pdfPage = pdfPage;
  3565. this.pdfPageRotate = pdfPage.rotate;
  3566. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  3567. this.viewport = pdfPage.getViewport({
  3568. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  3569. rotation: totalRotation
  3570. });
  3571. this.#setDimensions();
  3572. this.reset();
  3573. }
  3574. destroy() {
  3575. this.reset();
  3576. this.pdfPage?.cleanup();
  3577. }
  3578. get _textHighlighter() {
  3579. return (0, _pdfjsLib.shadow)(this, "_textHighlighter", new _text_highlighter.TextHighlighter({
  3580. pageIndex: this.id - 1,
  3581. eventBus: this.eventBus,
  3582. findController: this.#layerProperties().findController
  3583. }));
  3584. }
  3585. async #renderAnnotationLayer() {
  3586. let error = null;
  3587. try {
  3588. await this.annotationLayer.render(this.viewport, "display");
  3589. } catch (ex) {
  3590. console.error(`#renderAnnotationLayer: "${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 #renderAnnotationEditorLayer() {
  3601. let error = null;
  3602. try {
  3603. await this.annotationEditorLayer.render(this.viewport, "display");
  3604. } catch (ex) {
  3605. console.error(`#renderAnnotationEditorLayer: "${ex}".`);
  3606. error = ex;
  3607. } finally {
  3608. this.eventBus.dispatch("annotationeditorlayerrendered", {
  3609. source: this,
  3610. pageNumber: this.id,
  3611. error
  3612. });
  3613. }
  3614. }
  3615. async #renderXfaLayer() {
  3616. let error = null;
  3617. try {
  3618. const result = await this.xfaLayer.render(this.viewport, "display");
  3619. if (result?.textDivs && this._textHighlighter) {
  3620. this.#buildXfaTextContentItems(result.textDivs);
  3621. }
  3622. } catch (ex) {
  3623. console.error(`#renderXfaLayer: "${ex}".`);
  3624. error = ex;
  3625. } finally {
  3626. this.eventBus.dispatch("xfalayerrendered", {
  3627. source: this,
  3628. pageNumber: this.id,
  3629. error
  3630. });
  3631. }
  3632. }
  3633. async #renderTextLayer() {
  3634. const {
  3635. pdfPage,
  3636. textLayer,
  3637. viewport
  3638. } = this;
  3639. if (!textLayer) {
  3640. return;
  3641. }
  3642. let error = null;
  3643. try {
  3644. if (!textLayer.renderingDone) {
  3645. const readableStream = pdfPage.streamTextContent({
  3646. includeMarkedContent: true
  3647. });
  3648. textLayer.setTextContentSource(readableStream);
  3649. }
  3650. await textLayer.render(viewport);
  3651. } catch (ex) {
  3652. if (ex instanceof _pdfjsLib.AbortException) {
  3653. return;
  3654. }
  3655. console.error(`#renderTextLayer: "${ex}".`);
  3656. error = ex;
  3657. }
  3658. this.eventBus.dispatch("textlayerrendered", {
  3659. source: this,
  3660. pageNumber: this.id,
  3661. numTextDivs: textLayer.numTextDivs,
  3662. error
  3663. });
  3664. this.#renderStructTreeLayer();
  3665. }
  3666. async #renderStructTreeLayer() {
  3667. if (!this.textLayer) {
  3668. return;
  3669. }
  3670. this.structTreeLayer ||= new _struct_tree_layer_builder.StructTreeLayerBuilder();
  3671. const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
  3672. const treeDom = this.structTreeLayer?.render(tree);
  3673. if (treeDom) {
  3674. this.canvas?.append(treeDom);
  3675. }
  3676. }
  3677. async #buildXfaTextContentItems(textDivs) {
  3678. const text = await this.pdfPage.getTextContent();
  3679. const items = [];
  3680. for (const item of text.items) {
  3681. items.push(item.str);
  3682. }
  3683. this._textHighlighter.setTextMapping(textDivs, items);
  3684. this._textHighlighter.enable();
  3685. }
  3686. _resetZoomLayer(removeFromDOM = false) {
  3687. if (!this.zoomLayer) {
  3688. return;
  3689. }
  3690. const zoomLayerCanvas = this.zoomLayer.firstChild;
  3691. this.paintedViewportMap.delete(zoomLayerCanvas);
  3692. zoomLayerCanvas.width = 0;
  3693. zoomLayerCanvas.height = 0;
  3694. if (removeFromDOM) {
  3695. this.zoomLayer.remove();
  3696. }
  3697. this.zoomLayer = null;
  3698. }
  3699. reset({
  3700. keepZoomLayer = false,
  3701. keepAnnotationLayer = false,
  3702. keepAnnotationEditorLayer = false,
  3703. keepXfaLayer = false,
  3704. keepTextLayer = false
  3705. } = {}) {
  3706. this.cancelRendering({
  3707. keepAnnotationLayer,
  3708. keepAnnotationEditorLayer,
  3709. keepXfaLayer,
  3710. keepTextLayer
  3711. });
  3712. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  3713. const div = this.div;
  3714. const childNodes = div.childNodes,
  3715. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  3716. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  3717. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  3718. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
  3719. textLayerNode = keepTextLayer && this.textLayer?.div || null;
  3720. for (let i = childNodes.length - 1; i >= 0; i--) {
  3721. const node = childNodes[i];
  3722. switch (node) {
  3723. case zoomLayerNode:
  3724. case annotationLayerNode:
  3725. case annotationEditorLayerNode:
  3726. case xfaLayerNode:
  3727. case textLayerNode:
  3728. case this.loadingIconDiv:
  3729. continue;
  3730. }
  3731. node.remove();
  3732. }
  3733. div.removeAttribute("data-loaded");
  3734. if (annotationLayerNode) {
  3735. this.annotationLayer.hide();
  3736. }
  3737. if (annotationEditorLayerNode) {
  3738. this.annotationEditorLayer.hide();
  3739. }
  3740. if (xfaLayerNode) {
  3741. this.xfaLayer.hide();
  3742. }
  3743. if (textLayerNode) {
  3744. this.textLayer.hide();
  3745. }
  3746. if (!zoomLayerNode) {
  3747. if (this.canvas) {
  3748. this.paintedViewportMap.delete(this.canvas);
  3749. this.canvas.width = 0;
  3750. this.canvas.height = 0;
  3751. delete this.canvas;
  3752. }
  3753. this._resetZoomLayer();
  3754. }
  3755. if (this.svg) {
  3756. this.paintedViewportMap.delete(this.svg);
  3757. delete this.svg;
  3758. }
  3759. if (!this.loadingIconDiv) {
  3760. this.loadingIconDiv = document.createElement("div");
  3761. this.loadingIconDiv.className = "loadingIcon notVisible";
  3762. this.loadingIconDiv.setAttribute("role", "img");
  3763. this.l10n.get("loading").then(msg => {
  3764. this.loadingIconDiv?.setAttribute("aria-label", msg);
  3765. });
  3766. div.append(this.loadingIconDiv);
  3767. }
  3768. }
  3769. update({
  3770. scale = 0,
  3771. rotation = null,
  3772. optionalContentConfigPromise = null,
  3773. drawingDelay = -1
  3774. }) {
  3775. this.scale = scale || this.scale;
  3776. if (typeof rotation === "number") {
  3777. this.rotation = rotation;
  3778. }
  3779. if (optionalContentConfigPromise instanceof Promise) {
  3780. this._optionalContentConfigPromise = optionalContentConfigPromise;
  3781. optionalContentConfigPromise.then(optionalContentConfig => {
  3782. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  3783. return;
  3784. }
  3785. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  3786. });
  3787. }
  3788. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  3789. this.viewport = this.viewport.clone({
  3790. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  3791. rotation: totalRotation
  3792. });
  3793. this.#setDimensions();
  3794. if (this._isStandalone) {
  3795. _ui_utils.docStyle.setProperty("--scale-factor", this.viewport.scale);
  3796. }
  3797. if (this.svg) {
  3798. this.cssTransform({
  3799. target: this.svg,
  3800. redrawAnnotationLayer: true,
  3801. redrawAnnotationEditorLayer: true,
  3802. redrawXfaLayer: true,
  3803. redrawTextLayer: true
  3804. });
  3805. this.eventBus.dispatch("pagerendered", {
  3806. source: this,
  3807. pageNumber: this.id,
  3808. cssTransform: true,
  3809. timestamp: performance.now(),
  3810. error: this._renderError
  3811. });
  3812. return;
  3813. }
  3814. let isScalingRestricted = false;
  3815. if (this.canvas && this.maxCanvasPixels > 0) {
  3816. const outputScale = this.outputScale;
  3817. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  3818. isScalingRestricted = true;
  3819. }
  3820. }
  3821. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  3822. if (this.canvas) {
  3823. if (postponeDrawing || this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  3824. if (postponeDrawing && this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  3825. this.cancelRendering({
  3826. keepZoomLayer: true,
  3827. keepAnnotationLayer: true,
  3828. keepAnnotationEditorLayer: true,
  3829. keepXfaLayer: true,
  3830. keepTextLayer: true,
  3831. cancelExtraDelay: drawingDelay
  3832. });
  3833. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  3834. }
  3835. this.cssTransform({
  3836. target: this.canvas,
  3837. redrawAnnotationLayer: true,
  3838. redrawAnnotationEditorLayer: true,
  3839. redrawXfaLayer: true,
  3840. redrawTextLayer: !postponeDrawing,
  3841. hideTextLayer: postponeDrawing
  3842. });
  3843. this.eventBus.dispatch("pagerendered", {
  3844. source: this,
  3845. pageNumber: this.id,
  3846. cssTransform: true,
  3847. timestamp: performance.now(),
  3848. error: this._renderError
  3849. });
  3850. return;
  3851. }
  3852. if (!this.zoomLayer && !this.canvas.hidden) {
  3853. this.zoomLayer = this.canvas.parentNode;
  3854. this.zoomLayer.style.position = "absolute";
  3855. }
  3856. }
  3857. if (this.zoomLayer) {
  3858. this.cssTransform({
  3859. target: this.zoomLayer.firstChild
  3860. });
  3861. }
  3862. this.reset({
  3863. keepZoomLayer: true,
  3864. keepAnnotationLayer: true,
  3865. keepAnnotationEditorLayer: true,
  3866. keepXfaLayer: true,
  3867. keepTextLayer: true
  3868. });
  3869. }
  3870. cancelRendering({
  3871. keepAnnotationLayer = false,
  3872. keepAnnotationEditorLayer = false,
  3873. keepXfaLayer = false,
  3874. keepTextLayer = false,
  3875. cancelExtraDelay = 0
  3876. } = {}) {
  3877. if (this.paintTask) {
  3878. this.paintTask.cancel(cancelExtraDelay);
  3879. this.paintTask = null;
  3880. }
  3881. this.resume = null;
  3882. if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
  3883. this.textLayer.cancel();
  3884. this.textLayer = null;
  3885. }
  3886. if (this.structTreeLayer && !this.textLayer) {
  3887. this.structTreeLayer = null;
  3888. }
  3889. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  3890. this.annotationLayer.cancel();
  3891. this.annotationLayer = null;
  3892. this._annotationCanvasMap = null;
  3893. }
  3894. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  3895. this.annotationEditorLayer.cancel();
  3896. this.annotationEditorLayer = null;
  3897. }
  3898. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  3899. this.xfaLayer.cancel();
  3900. this.xfaLayer = null;
  3901. this._textHighlighter?.disable();
  3902. }
  3903. }
  3904. cssTransform({
  3905. target,
  3906. redrawAnnotationLayer = false,
  3907. redrawAnnotationEditorLayer = false,
  3908. redrawXfaLayer = false,
  3909. redrawTextLayer = false,
  3910. hideTextLayer = false
  3911. }) {
  3912. if (target instanceof HTMLCanvasElement) {
  3913. if (!target.hasAttribute("zooming")) {
  3914. target.setAttribute("zooming", true);
  3915. const {
  3916. style
  3917. } = target;
  3918. style.width = style.height = "";
  3919. }
  3920. } else {
  3921. const div = this.div;
  3922. const {
  3923. width,
  3924. height
  3925. } = this.viewport;
  3926. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  3927. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  3928. }
  3929. const originalViewport = this.paintedViewportMap.get(target);
  3930. if (this.viewport !== originalViewport) {
  3931. const relativeRotation = this.viewport.rotation - originalViewport.rotation;
  3932. const absRotation = Math.abs(relativeRotation);
  3933. let scaleX = 1,
  3934. scaleY = 1;
  3935. if (absRotation === 90 || absRotation === 270) {
  3936. const {
  3937. width,
  3938. height
  3939. } = this.viewport;
  3940. scaleX = height / width;
  3941. scaleY = width / height;
  3942. }
  3943. if (absRotation !== 0) {
  3944. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  3945. }
  3946. }
  3947. if (redrawAnnotationLayer && this.annotationLayer) {
  3948. this.#renderAnnotationLayer();
  3949. }
  3950. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  3951. this.#renderAnnotationEditorLayer();
  3952. }
  3953. if (redrawXfaLayer && this.xfaLayer) {
  3954. this.#renderXfaLayer();
  3955. }
  3956. if (this.textLayer) {
  3957. if (hideTextLayer) {
  3958. this.textLayer.hide();
  3959. } else if (redrawTextLayer) {
  3960. this.#renderTextLayer();
  3961. }
  3962. }
  3963. }
  3964. get width() {
  3965. return this.viewport.width;
  3966. }
  3967. get height() {
  3968. return this.viewport.height;
  3969. }
  3970. getPagePoint(x, y) {
  3971. return this.viewport.convertToPdfPoint(x, y);
  3972. }
  3973. draw() {
  3974. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  3975. console.error("Must be in new state before drawing");
  3976. this.reset();
  3977. }
  3978. const {
  3979. div,
  3980. pdfPage
  3981. } = this;
  3982. if (!pdfPage) {
  3983. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  3984. return Promise.reject(new Error("pdfPage is not loaded"));
  3985. }
  3986. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  3987. const canvasWrapper = document.createElement("div");
  3988. canvasWrapper.classList.add("canvasWrapper");
  3989. div.append(canvasWrapper);
  3990. if (!this.textLayer && this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
  3991. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  3992. this.textLayer = new _text_layer_builder.TextLayerBuilder({
  3993. highlighter: this._textHighlighter,
  3994. accessibilityManager: this._accessibilityManager,
  3995. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
  3996. });
  3997. div.append(this.textLayer.div);
  3998. }
  3999. if (!this.annotationLayer && this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE) {
  4000. const {
  4001. annotationStorage,
  4002. downloadManager,
  4003. enableScripting,
  4004. fieldObjectsPromise,
  4005. hasJSActionsPromise,
  4006. linkService
  4007. } = this.#layerProperties();
  4008. this._annotationCanvasMap ||= new Map();
  4009. this.annotationLayer = new _annotation_layer_builder.AnnotationLayerBuilder({
  4010. pageDiv: div,
  4011. pdfPage,
  4012. annotationStorage,
  4013. imageResourcesPath: this.imageResourcesPath,
  4014. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  4015. linkService,
  4016. downloadManager,
  4017. l10n: this.l10n,
  4018. enableScripting,
  4019. hasJSActionsPromise,
  4020. fieldObjectsPromise,
  4021. annotationCanvasMap: this._annotationCanvasMap,
  4022. accessibilityManager: this._accessibilityManager
  4023. });
  4024. }
  4025. if (this.xfaLayer?.div) {
  4026. div.append(this.xfaLayer.div);
  4027. }
  4028. let renderContinueCallback = null;
  4029. if (this.renderingQueue) {
  4030. renderContinueCallback = cont => {
  4031. if (!this.renderingQueue.isHighestPriority(this)) {
  4032. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  4033. this.resume = () => {
  4034. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  4035. cont();
  4036. };
  4037. return;
  4038. }
  4039. cont();
  4040. };
  4041. }
  4042. const finishPaintTask = async (error = null) => {
  4043. if (paintTask === this.paintTask) {
  4044. this.paintTask = null;
  4045. }
  4046. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  4047. this._renderError = null;
  4048. return;
  4049. }
  4050. this._renderError = error;
  4051. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  4052. this._resetZoomLayer(true);
  4053. this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
  4054. this.eventBus.dispatch("pagerendered", {
  4055. source: this,
  4056. pageNumber: this.id,
  4057. cssTransform: false,
  4058. timestamp: performance.now(),
  4059. error: this._renderError
  4060. });
  4061. if (error) {
  4062. throw error;
  4063. }
  4064. };
  4065. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  4066. paintTask.onRenderContinue = renderContinueCallback;
  4067. this.paintTask = paintTask;
  4068. const resultPromise = paintTask.promise.then(() => {
  4069. return finishPaintTask(null).then(async () => {
  4070. this.#renderTextLayer();
  4071. if (this.annotationLayer) {
  4072. await this.#renderAnnotationLayer();
  4073. }
  4074. if (!this.annotationEditorLayer) {
  4075. const {
  4076. annotationEditorUIManager
  4077. } = this.#layerProperties();
  4078. if (!annotationEditorUIManager) {
  4079. return;
  4080. }
  4081. this.annotationEditorLayer = new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  4082. uiManager: annotationEditorUIManager,
  4083. pageDiv: div,
  4084. pdfPage,
  4085. l10n: this.l10n,
  4086. accessibilityManager: this._accessibilityManager
  4087. });
  4088. }
  4089. this.#renderAnnotationEditorLayer();
  4090. });
  4091. }, function (reason) {
  4092. return finishPaintTask(reason);
  4093. });
  4094. if (pdfPage.isPureXfa) {
  4095. if (!this.xfaLayer) {
  4096. const {
  4097. annotationStorage,
  4098. linkService
  4099. } = this.#layerProperties();
  4100. this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({
  4101. pageDiv: div,
  4102. pdfPage,
  4103. annotationStorage,
  4104. linkService
  4105. });
  4106. }
  4107. this.#renderXfaLayer();
  4108. }
  4109. div.setAttribute("data-loaded", true);
  4110. this.eventBus.dispatch("pagerender", {
  4111. source: this,
  4112. pageNumber: this.id
  4113. });
  4114. return resultPromise;
  4115. }
  4116. paintOnCanvas(canvasWrapper) {
  4117. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  4118. const result = {
  4119. promise: renderCapability.promise,
  4120. onRenderContinue(cont) {
  4121. cont();
  4122. },
  4123. cancel(extraDelay = 0) {
  4124. renderTask.cancel(extraDelay);
  4125. },
  4126. get separateAnnots() {
  4127. return renderTask.separateAnnots;
  4128. }
  4129. };
  4130. const viewport = this.viewport;
  4131. const {
  4132. width,
  4133. height
  4134. } = viewport;
  4135. const canvas = document.createElement("canvas");
  4136. canvas.setAttribute("role", "presentation");
  4137. canvas.hidden = true;
  4138. let isCanvasHidden = true;
  4139. const showCanvas = function () {
  4140. if (isCanvasHidden) {
  4141. canvas.hidden = false;
  4142. isCanvasHidden = false;
  4143. }
  4144. };
  4145. canvasWrapper.append(canvas);
  4146. this.canvas = canvas;
  4147. const ctx = canvas.getContext("2d", {
  4148. alpha: false
  4149. });
  4150. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  4151. if (this.useOnlyCssZoom) {
  4152. const actualSizeViewport = viewport.clone({
  4153. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  4154. });
  4155. outputScale.sx *= actualSizeViewport.width / width;
  4156. outputScale.sy *= actualSizeViewport.height / height;
  4157. }
  4158. if (this.maxCanvasPixels > 0) {
  4159. const pixelsInViewport = width * height;
  4160. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  4161. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  4162. outputScale.sx = maxScale;
  4163. outputScale.sy = maxScale;
  4164. this.hasRestrictedScaling = true;
  4165. } else {
  4166. this.hasRestrictedScaling = false;
  4167. }
  4168. }
  4169. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  4170. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  4171. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  4172. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  4173. const {
  4174. style
  4175. } = canvas;
  4176. style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  4177. style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  4178. this.paintedViewportMap.set(canvas, viewport);
  4179. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  4180. const renderContext = {
  4181. canvasContext: ctx,
  4182. transform,
  4183. viewport,
  4184. annotationMode: this.#annotationMode,
  4185. optionalContentConfigPromise: this._optionalContentConfigPromise,
  4186. annotationCanvasMap: this._annotationCanvasMap,
  4187. pageColors: this.pageColors
  4188. };
  4189. const renderTask = this.pdfPage.render(renderContext);
  4190. renderTask.onContinue = function (cont) {
  4191. showCanvas();
  4192. if (result.onRenderContinue) {
  4193. result.onRenderContinue(cont);
  4194. } else {
  4195. cont();
  4196. }
  4197. };
  4198. renderTask.promise.then(function () {
  4199. showCanvas();
  4200. renderCapability.resolve();
  4201. }, function (error) {
  4202. showCanvas();
  4203. renderCapability.reject(error);
  4204. });
  4205. return result;
  4206. }
  4207. paintOnSvg(wrapper) {
  4208. let cancelled = false;
  4209. const ensureNotCancelled = () => {
  4210. if (cancelled) {
  4211. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  4212. }
  4213. };
  4214. const pdfPage = this.pdfPage;
  4215. const actualSizeViewport = this.viewport.clone({
  4216. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  4217. });
  4218. const promise = pdfPage.getOperatorList({
  4219. annotationMode: this.#annotationMode
  4220. }).then(opList => {
  4221. ensureNotCancelled();
  4222. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  4223. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  4224. ensureNotCancelled();
  4225. this.svg = svg;
  4226. this.paintedViewportMap.set(svg, actualSizeViewport);
  4227. svg.style.width = wrapper.style.width;
  4228. svg.style.height = wrapper.style.height;
  4229. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  4230. wrapper.append(svg);
  4231. });
  4232. });
  4233. return {
  4234. promise,
  4235. onRenderContinue(cont) {
  4236. cont();
  4237. },
  4238. cancel() {
  4239. cancelled = true;
  4240. },
  4241. get separateAnnots() {
  4242. return false;
  4243. }
  4244. };
  4245. }
  4246. setPageLabel(label) {
  4247. this.pageLabel = typeof label === "string" ? label : null;
  4248. if (this.pageLabel !== null) {
  4249. this.div.setAttribute("data-page-label", this.pageLabel);
  4250. } else {
  4251. this.div.removeAttribute("data-page-label");
  4252. }
  4253. }
  4254. get thumbnailCanvas() {
  4255. const {
  4256. initialOptionalContent,
  4257. regularAnnotations
  4258. } = this.#useThumbnailCanvas;
  4259. return initialOptionalContent && regularAnnotations ? this.canvas : null;
  4260. }
  4261. }
  4262. exports.PDFPageView = PDFPageView;
  4263. /***/ }),
  4264. /* 14 */
  4265. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4266. Object.defineProperty(exports, "__esModule", ({
  4267. value: true
  4268. }));
  4269. exports.AnnotationEditorLayerBuilder = void 0;
  4270. var _pdfjsLib = __w_pdfjs_require__(4);
  4271. var _l10n_utils = __w_pdfjs_require__(5);
  4272. class AnnotationEditorLayerBuilder {
  4273. #uiManager;
  4274. constructor(options) {
  4275. this.pageDiv = options.pageDiv;
  4276. this.pdfPage = options.pdfPage;
  4277. this.accessibilityManager = options.accessibilityManager;
  4278. this.l10n = options.l10n || _l10n_utils.NullL10n;
  4279. this.annotationEditorLayer = null;
  4280. this.div = null;
  4281. this._cancelled = false;
  4282. this.#uiManager = options.uiManager;
  4283. }
  4284. async render(viewport, intent = "display") {
  4285. if (intent !== "display") {
  4286. return;
  4287. }
  4288. if (this._cancelled) {
  4289. return;
  4290. }
  4291. const clonedViewport = viewport.clone({
  4292. dontFlip: true
  4293. });
  4294. if (this.div) {
  4295. this.annotationEditorLayer.update({
  4296. viewport: clonedViewport
  4297. });
  4298. this.show();
  4299. return;
  4300. }
  4301. const div = this.div = document.createElement("div");
  4302. div.className = "annotationEditorLayer";
  4303. div.tabIndex = 0;
  4304. this.pageDiv.append(div);
  4305. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  4306. uiManager: this.#uiManager,
  4307. div,
  4308. accessibilityManager: this.accessibilityManager,
  4309. pageIndex: this.pdfPage.pageNumber - 1,
  4310. l10n: this.l10n,
  4311. viewport: clonedViewport
  4312. });
  4313. const parameters = {
  4314. viewport: clonedViewport,
  4315. div,
  4316. annotations: null,
  4317. intent
  4318. };
  4319. this.annotationEditorLayer.render(parameters);
  4320. }
  4321. cancel() {
  4322. this._cancelled = true;
  4323. if (!this.div) {
  4324. return;
  4325. }
  4326. this.pageDiv = null;
  4327. this.annotationEditorLayer.destroy();
  4328. this.div.remove();
  4329. }
  4330. hide() {
  4331. if (!this.div) {
  4332. return;
  4333. }
  4334. this.div.hidden = true;
  4335. }
  4336. show() {
  4337. if (!this.div) {
  4338. return;
  4339. }
  4340. this.div.hidden = false;
  4341. }
  4342. }
  4343. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  4344. /***/ }),
  4345. /* 15 */
  4346. /***/ ((__unused_webpack_module, exports) => {
  4347. Object.defineProperty(exports, "__esModule", ({
  4348. value: true
  4349. }));
  4350. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  4351. const compatibilityParams = Object.create(null);
  4352. exports.compatibilityParams = compatibilityParams;
  4353. {
  4354. const userAgent = navigator.userAgent || "";
  4355. const platform = navigator.platform || "";
  4356. const maxTouchPoints = navigator.maxTouchPoints || 1;
  4357. const isAndroid = /Android/.test(userAgent);
  4358. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  4359. (function checkCanvasSizeLimitation() {
  4360. if (isIOS || isAndroid) {
  4361. compatibilityParams.maxCanvasPixels = 5242880;
  4362. }
  4363. })();
  4364. }
  4365. const OptionKind = {
  4366. VIEWER: 0x02,
  4367. API: 0x04,
  4368. WORKER: 0x08,
  4369. PREFERENCE: 0x80
  4370. };
  4371. exports.OptionKind = OptionKind;
  4372. const defaultOptions = {
  4373. annotationEditorMode: {
  4374. value: 0,
  4375. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4376. },
  4377. annotationMode: {
  4378. value: 2,
  4379. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4380. },
  4381. cursorToolOnLoad: {
  4382. value: 0,
  4383. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4384. },
  4385. defaultZoomDelay: {
  4386. value: -1,
  4387. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4388. },
  4389. defaultZoomValue: {
  4390. value: "",
  4391. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4392. },
  4393. disableHistory: {
  4394. value: false,
  4395. kind: OptionKind.VIEWER
  4396. },
  4397. disablePageLabels: {
  4398. value: false,
  4399. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4400. },
  4401. enablePermissions: {
  4402. value: false,
  4403. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4404. },
  4405. enablePrintAutoRotate: {
  4406. value: true,
  4407. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4408. },
  4409. enableScripting: {
  4410. value: true,
  4411. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4412. },
  4413. externalLinkRel: {
  4414. value: "noopener noreferrer nofollow",
  4415. kind: OptionKind.VIEWER
  4416. },
  4417. externalLinkTarget: {
  4418. value: 0,
  4419. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4420. },
  4421. historyUpdateUrl: {
  4422. value: false,
  4423. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4424. },
  4425. ignoreDestinationZoom: {
  4426. value: false,
  4427. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4428. },
  4429. imageResourcesPath: {
  4430. value: "./images/",
  4431. kind: OptionKind.VIEWER
  4432. },
  4433. maxCanvasPixels: {
  4434. value: 16777216,
  4435. kind: OptionKind.VIEWER
  4436. },
  4437. forcePageColors: {
  4438. value: false,
  4439. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4440. },
  4441. pageColorsBackground: {
  4442. value: "Canvas",
  4443. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4444. },
  4445. pageColorsForeground: {
  4446. value: "CanvasText",
  4447. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4448. },
  4449. pdfBugEnabled: {
  4450. value: false,
  4451. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4452. },
  4453. printResolution: {
  4454. value: 150,
  4455. kind: OptionKind.VIEWER
  4456. },
  4457. sidebarViewOnLoad: {
  4458. value: -1,
  4459. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4460. },
  4461. scrollModeOnLoad: {
  4462. value: -1,
  4463. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4464. },
  4465. spreadModeOnLoad: {
  4466. value: -1,
  4467. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4468. },
  4469. textLayerMode: {
  4470. value: 1,
  4471. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4472. },
  4473. useOnlyCssZoom: {
  4474. value: false,
  4475. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4476. },
  4477. viewerCssTheme: {
  4478. value: 0,
  4479. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4480. },
  4481. viewOnLoad: {
  4482. value: 0,
  4483. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4484. },
  4485. cMapPacked: {
  4486. value: true,
  4487. kind: OptionKind.API
  4488. },
  4489. cMapUrl: {
  4490. value: "../web/cmaps/",
  4491. kind: OptionKind.API
  4492. },
  4493. disableAutoFetch: {
  4494. value: false,
  4495. kind: OptionKind.API + OptionKind.PREFERENCE
  4496. },
  4497. disableFontFace: {
  4498. value: false,
  4499. kind: OptionKind.API + OptionKind.PREFERENCE
  4500. },
  4501. disableRange: {
  4502. value: false,
  4503. kind: OptionKind.API + OptionKind.PREFERENCE
  4504. },
  4505. disableStream: {
  4506. value: false,
  4507. kind: OptionKind.API + OptionKind.PREFERENCE
  4508. },
  4509. docBaseUrl: {
  4510. value: "",
  4511. kind: OptionKind.API
  4512. },
  4513. enableXfa: {
  4514. value: true,
  4515. kind: OptionKind.API + OptionKind.PREFERENCE
  4516. },
  4517. fontExtraProperties: {
  4518. value: false,
  4519. kind: OptionKind.API
  4520. },
  4521. isEvalSupported: {
  4522. value: true,
  4523. kind: OptionKind.API
  4524. },
  4525. isOffscreenCanvasSupported: {
  4526. value: true,
  4527. kind: OptionKind.API
  4528. },
  4529. maxImageSize: {
  4530. value: -1,
  4531. kind: OptionKind.API
  4532. },
  4533. pdfBug: {
  4534. value: false,
  4535. kind: OptionKind.API
  4536. },
  4537. standardFontDataUrl: {
  4538. value: "../web/standard_fonts/",
  4539. kind: OptionKind.API
  4540. },
  4541. verbosity: {
  4542. value: 1,
  4543. kind: OptionKind.API
  4544. },
  4545. workerPort: {
  4546. value: null,
  4547. kind: OptionKind.WORKER
  4548. },
  4549. workerSrc: {
  4550. value: "../build/pdf.worker.js",
  4551. kind: OptionKind.WORKER
  4552. }
  4553. };
  4554. {
  4555. defaultOptions.defaultUrl = {
  4556. value: "compressed.tracemonkey-pldi-09.pdf",
  4557. kind: OptionKind.VIEWER
  4558. };
  4559. defaultOptions.disablePreferences = {
  4560. value: false,
  4561. kind: OptionKind.VIEWER
  4562. };
  4563. defaultOptions.locale = {
  4564. value: navigator.language || "en-US",
  4565. kind: OptionKind.VIEWER
  4566. };
  4567. defaultOptions.renderer = {
  4568. value: "canvas",
  4569. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  4570. };
  4571. defaultOptions.sandboxBundleSrc = {
  4572. value: "../build/pdf.sandbox.js",
  4573. kind: OptionKind.VIEWER
  4574. };
  4575. }
  4576. const userOptions = Object.create(null);
  4577. class AppOptions {
  4578. constructor() {
  4579. throw new Error("Cannot initialize AppOptions.");
  4580. }
  4581. static get(name) {
  4582. const userOption = userOptions[name];
  4583. if (userOption !== undefined) {
  4584. return userOption;
  4585. }
  4586. const defaultOption = defaultOptions[name];
  4587. if (defaultOption !== undefined) {
  4588. return compatibilityParams[name] ?? defaultOption.value;
  4589. }
  4590. return undefined;
  4591. }
  4592. static getAll(kind = null) {
  4593. const options = Object.create(null);
  4594. for (const name in defaultOptions) {
  4595. const defaultOption = defaultOptions[name];
  4596. if (kind) {
  4597. if ((kind & defaultOption.kind) === 0) {
  4598. continue;
  4599. }
  4600. if (kind === OptionKind.PREFERENCE) {
  4601. const value = defaultOption.value,
  4602. valueType = typeof value;
  4603. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  4604. options[name] = value;
  4605. continue;
  4606. }
  4607. throw new Error(`Invalid type for preference: ${name}`);
  4608. }
  4609. }
  4610. const userOption = userOptions[name];
  4611. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  4612. }
  4613. return options;
  4614. }
  4615. static set(name, value) {
  4616. userOptions[name] = value;
  4617. }
  4618. static setAll(options) {
  4619. for (const name in options) {
  4620. userOptions[name] = options[name];
  4621. }
  4622. }
  4623. static remove(name) {
  4624. delete userOptions[name];
  4625. }
  4626. static _hasUserOptions() {
  4627. return Object.keys(userOptions).length > 0;
  4628. }
  4629. }
  4630. exports.AppOptions = AppOptions;
  4631. /***/ }),
  4632. /* 16 */
  4633. /***/ ((__unused_webpack_module, exports) => {
  4634. Object.defineProperty(exports, "__esModule", ({
  4635. value: true
  4636. }));
  4637. exports.StructTreeLayerBuilder = void 0;
  4638. const PDF_ROLE_TO_HTML_ROLE = {
  4639. Document: null,
  4640. DocumentFragment: null,
  4641. Part: "group",
  4642. Sect: "group",
  4643. Div: "group",
  4644. Aside: "note",
  4645. NonStruct: "none",
  4646. P: null,
  4647. H: "heading",
  4648. Title: null,
  4649. FENote: "note",
  4650. Sub: "group",
  4651. Lbl: null,
  4652. Span: null,
  4653. Em: null,
  4654. Strong: null,
  4655. Link: "link",
  4656. Annot: "note",
  4657. Form: "form",
  4658. Ruby: null,
  4659. RB: null,
  4660. RT: null,
  4661. RP: null,
  4662. Warichu: null,
  4663. WT: null,
  4664. WP: null,
  4665. L: "list",
  4666. LI: "listitem",
  4667. LBody: null,
  4668. Table: "table",
  4669. TR: "row",
  4670. TH: "columnheader",
  4671. TD: "cell",
  4672. THead: "columnheader",
  4673. TBody: null,
  4674. TFoot: null,
  4675. Caption: null,
  4676. Figure: "figure",
  4677. Formula: null,
  4678. Artifact: null
  4679. };
  4680. const HEADING_PATTERN = /^H(\d+)$/;
  4681. class StructTreeLayerBuilder {
  4682. #treeDom = undefined;
  4683. get renderingDone() {
  4684. return this.#treeDom !== undefined;
  4685. }
  4686. render(structTree) {
  4687. if (this.#treeDom !== undefined) {
  4688. return this.#treeDom;
  4689. }
  4690. const treeDom = this.#walk(structTree);
  4691. treeDom?.classList.add("structTree");
  4692. return this.#treeDom = treeDom;
  4693. }
  4694. #setAttributes(structElement, htmlElement) {
  4695. if (structElement.alt !== undefined) {
  4696. htmlElement.setAttribute("aria-label", structElement.alt);
  4697. }
  4698. if (structElement.id !== undefined) {
  4699. htmlElement.setAttribute("aria-owns", structElement.id);
  4700. }
  4701. if (structElement.lang !== undefined) {
  4702. htmlElement.setAttribute("lang", structElement.lang);
  4703. }
  4704. }
  4705. #walk(node) {
  4706. if (!node) {
  4707. return null;
  4708. }
  4709. const element = document.createElement("span");
  4710. if ("role" in node) {
  4711. const {
  4712. role
  4713. } = node;
  4714. const match = role.match(HEADING_PATTERN);
  4715. if (match) {
  4716. element.setAttribute("role", "heading");
  4717. element.setAttribute("aria-level", match[1]);
  4718. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  4719. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  4720. }
  4721. }
  4722. this.#setAttributes(node, element);
  4723. if (node.children) {
  4724. if (node.children.length === 1 && "id" in node.children[0]) {
  4725. this.#setAttributes(node.children[0], element);
  4726. } else {
  4727. for (const kid of node.children) {
  4728. element.append(this.#walk(kid));
  4729. }
  4730. }
  4731. }
  4732. return element;
  4733. }
  4734. }
  4735. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  4736. /***/ }),
  4737. /* 17 */
  4738. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4739. Object.defineProperty(exports, "__esModule", ({
  4740. value: true
  4741. }));
  4742. exports.TextAccessibilityManager = void 0;
  4743. var _ui_utils = __w_pdfjs_require__(2);
  4744. class TextAccessibilityManager {
  4745. #enabled = false;
  4746. #textChildren = null;
  4747. #textNodes = new Map();
  4748. #waitingElements = new Map();
  4749. setTextMapping(textDivs) {
  4750. this.#textChildren = textDivs;
  4751. }
  4752. static #compareElementPositions(e1, e2) {
  4753. const rect1 = e1.getBoundingClientRect();
  4754. const rect2 = e2.getBoundingClientRect();
  4755. if (rect1.width === 0 && rect1.height === 0) {
  4756. return +1;
  4757. }
  4758. if (rect2.width === 0 && rect2.height === 0) {
  4759. return -1;
  4760. }
  4761. const top1 = rect1.y;
  4762. const bot1 = rect1.y + rect1.height;
  4763. const mid1 = rect1.y + rect1.height / 2;
  4764. const top2 = rect2.y;
  4765. const bot2 = rect2.y + rect2.height;
  4766. const mid2 = rect2.y + rect2.height / 2;
  4767. if (mid1 <= top2 && mid2 >= bot1) {
  4768. return -1;
  4769. }
  4770. if (mid2 <= top1 && mid1 >= bot2) {
  4771. return +1;
  4772. }
  4773. const centerX1 = rect1.x + rect1.width / 2;
  4774. const centerX2 = rect2.x + rect2.width / 2;
  4775. return centerX1 - centerX2;
  4776. }
  4777. enable() {
  4778. if (this.#enabled) {
  4779. throw new Error("TextAccessibilityManager is already enabled.");
  4780. }
  4781. if (!this.#textChildren) {
  4782. throw new Error("Text divs and strings have not been set.");
  4783. }
  4784. this.#enabled = true;
  4785. this.#textChildren = this.#textChildren.slice();
  4786. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  4787. if (this.#textNodes.size > 0) {
  4788. const textChildren = this.#textChildren;
  4789. for (const [id, nodeIndex] of this.#textNodes) {
  4790. const element = document.getElementById(id);
  4791. if (!element) {
  4792. this.#textNodes.delete(id);
  4793. continue;
  4794. }
  4795. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  4796. }
  4797. }
  4798. for (const [element, isRemovable] of this.#waitingElements) {
  4799. this.addPointerInTextLayer(element, isRemovable);
  4800. }
  4801. this.#waitingElements.clear();
  4802. }
  4803. disable() {
  4804. if (!this.#enabled) {
  4805. return;
  4806. }
  4807. this.#waitingElements.clear();
  4808. this.#textChildren = null;
  4809. this.#enabled = false;
  4810. }
  4811. removePointerInTextLayer(element) {
  4812. if (!this.#enabled) {
  4813. this.#waitingElements.delete(element);
  4814. return;
  4815. }
  4816. const children = this.#textChildren;
  4817. if (!children || children.length === 0) {
  4818. return;
  4819. }
  4820. const {
  4821. id
  4822. } = element;
  4823. const nodeIndex = this.#textNodes.get(id);
  4824. if (nodeIndex === undefined) {
  4825. return;
  4826. }
  4827. const node = children[nodeIndex];
  4828. this.#textNodes.delete(id);
  4829. let owns = node.getAttribute("aria-owns");
  4830. if (owns?.includes(id)) {
  4831. owns = owns.split(" ").filter(x => x !== id).join(" ");
  4832. if (owns) {
  4833. node.setAttribute("aria-owns", owns);
  4834. } else {
  4835. node.removeAttribute("aria-owns");
  4836. node.setAttribute("role", "presentation");
  4837. }
  4838. }
  4839. }
  4840. #addIdToAriaOwns(id, node) {
  4841. const owns = node.getAttribute("aria-owns");
  4842. if (!owns?.includes(id)) {
  4843. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  4844. }
  4845. node.removeAttribute("role");
  4846. }
  4847. addPointerInTextLayer(element, isRemovable) {
  4848. const {
  4849. id
  4850. } = element;
  4851. if (!id) {
  4852. return;
  4853. }
  4854. if (!this.#enabled) {
  4855. this.#waitingElements.set(element, isRemovable);
  4856. return;
  4857. }
  4858. if (isRemovable) {
  4859. this.removePointerInTextLayer(element);
  4860. }
  4861. const children = this.#textChildren;
  4862. if (!children || children.length === 0) {
  4863. return;
  4864. }
  4865. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  4866. const nodeIndex = Math.max(0, index - 1);
  4867. this.#addIdToAriaOwns(id, children[nodeIndex]);
  4868. this.#textNodes.set(id, nodeIndex);
  4869. }
  4870. moveElementInDOM(container, element, contentElement, isRemovable) {
  4871. this.addPointerInTextLayer(contentElement, isRemovable);
  4872. if (!container.hasChildNodes()) {
  4873. container.append(element);
  4874. return;
  4875. }
  4876. const children = Array.from(container.childNodes).filter(node => node !== element);
  4877. if (children.length === 0) {
  4878. return;
  4879. }
  4880. const elementToCompare = contentElement || element;
  4881. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  4882. if (index === 0) {
  4883. children[0].before(element);
  4884. } else {
  4885. children[index - 1].after(element);
  4886. }
  4887. }
  4888. }
  4889. exports.TextAccessibilityManager = TextAccessibilityManager;
  4890. /***/ }),
  4891. /* 18 */
  4892. /***/ ((__unused_webpack_module, exports) => {
  4893. Object.defineProperty(exports, "__esModule", ({
  4894. value: true
  4895. }));
  4896. exports.TextHighlighter = void 0;
  4897. class TextHighlighter {
  4898. constructor({
  4899. findController,
  4900. eventBus,
  4901. pageIndex
  4902. }) {
  4903. this.findController = findController;
  4904. this.matches = [];
  4905. this.eventBus = eventBus;
  4906. this.pageIdx = pageIndex;
  4907. this._onUpdateTextLayerMatches = null;
  4908. this.textDivs = null;
  4909. this.textContentItemsStr = null;
  4910. this.enabled = false;
  4911. }
  4912. setTextMapping(divs, texts) {
  4913. this.textDivs = divs;
  4914. this.textContentItemsStr = texts;
  4915. }
  4916. enable() {
  4917. if (!this.textDivs || !this.textContentItemsStr) {
  4918. throw new Error("Text divs and strings have not been set.");
  4919. }
  4920. if (this.enabled) {
  4921. throw new Error("TextHighlighter is already enabled.");
  4922. }
  4923. this.enabled = true;
  4924. if (!this._onUpdateTextLayerMatches) {
  4925. this._onUpdateTextLayerMatches = evt => {
  4926. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  4927. this._updateMatches();
  4928. }
  4929. };
  4930. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  4931. }
  4932. this._updateMatches();
  4933. }
  4934. disable() {
  4935. if (!this.enabled) {
  4936. return;
  4937. }
  4938. this.enabled = false;
  4939. if (this._onUpdateTextLayerMatches) {
  4940. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  4941. this._onUpdateTextLayerMatches = null;
  4942. }
  4943. this._updateMatches(true);
  4944. }
  4945. _convertMatches(matches, matchesLength) {
  4946. if (!matches) {
  4947. return [];
  4948. }
  4949. const {
  4950. textContentItemsStr
  4951. } = this;
  4952. let i = 0,
  4953. iIndex = 0;
  4954. const end = textContentItemsStr.length - 1;
  4955. const result = [];
  4956. for (let m = 0, mm = matches.length; m < mm; m++) {
  4957. let matchIdx = matches[m];
  4958. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  4959. iIndex += textContentItemsStr[i].length;
  4960. i++;
  4961. }
  4962. if (i === textContentItemsStr.length) {
  4963. console.error("Could not find a matching mapping");
  4964. }
  4965. const match = {
  4966. begin: {
  4967. divIdx: i,
  4968. offset: matchIdx - iIndex
  4969. }
  4970. };
  4971. matchIdx += matchesLength[m];
  4972. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  4973. iIndex += textContentItemsStr[i].length;
  4974. i++;
  4975. }
  4976. match.end = {
  4977. divIdx: i,
  4978. offset: matchIdx - iIndex
  4979. };
  4980. result.push(match);
  4981. }
  4982. return result;
  4983. }
  4984. _renderMatches(matches) {
  4985. if (matches.length === 0) {
  4986. return;
  4987. }
  4988. const {
  4989. findController,
  4990. pageIdx
  4991. } = this;
  4992. const {
  4993. textContentItemsStr,
  4994. textDivs
  4995. } = this;
  4996. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  4997. const selectedMatchIdx = findController.selected.matchIdx;
  4998. const highlightAll = findController.state.highlightAll;
  4999. let prevEnd = null;
  5000. const infinity = {
  5001. divIdx: -1,
  5002. offset: undefined
  5003. };
  5004. function beginText(begin, className) {
  5005. const divIdx = begin.divIdx;
  5006. textDivs[divIdx].textContent = "";
  5007. return appendTextToDiv(divIdx, 0, begin.offset, className);
  5008. }
  5009. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  5010. let div = textDivs[divIdx];
  5011. if (div.nodeType === Node.TEXT_NODE) {
  5012. const span = document.createElement("span");
  5013. div.before(span);
  5014. span.append(div);
  5015. textDivs[divIdx] = span;
  5016. div = span;
  5017. }
  5018. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  5019. const node = document.createTextNode(content);
  5020. if (className) {
  5021. const span = document.createElement("span");
  5022. span.className = `${className} appended`;
  5023. span.append(node);
  5024. div.append(span);
  5025. return className.includes("selected") ? span.offsetLeft : 0;
  5026. }
  5027. div.append(node);
  5028. return 0;
  5029. }
  5030. let i0 = selectedMatchIdx,
  5031. i1 = i0 + 1;
  5032. if (highlightAll) {
  5033. i0 = 0;
  5034. i1 = matches.length;
  5035. } else if (!isSelectedPage) {
  5036. return;
  5037. }
  5038. for (let i = i0; i < i1; i++) {
  5039. const match = matches[i];
  5040. const begin = match.begin;
  5041. const end = match.end;
  5042. const isSelected = isSelectedPage && i === selectedMatchIdx;
  5043. const highlightSuffix = isSelected ? " selected" : "";
  5044. let selectedLeft = 0;
  5045. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  5046. if (prevEnd !== null) {
  5047. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  5048. }
  5049. beginText(begin);
  5050. } else {
  5051. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  5052. }
  5053. if (begin.divIdx === end.divIdx) {
  5054. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  5055. } else {
  5056. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  5057. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  5058. textDivs[n0].className = "highlight middle" + highlightSuffix;
  5059. }
  5060. beginText(end, "highlight end" + highlightSuffix);
  5061. }
  5062. prevEnd = end;
  5063. if (isSelected) {
  5064. findController.scrollMatchIntoView({
  5065. element: textDivs[begin.divIdx],
  5066. selectedLeft,
  5067. pageIndex: pageIdx,
  5068. matchIndex: selectedMatchIdx
  5069. });
  5070. }
  5071. }
  5072. if (prevEnd) {
  5073. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  5074. }
  5075. }
  5076. _updateMatches(reset = false) {
  5077. if (!this.enabled && !reset) {
  5078. return;
  5079. }
  5080. const {
  5081. findController,
  5082. matches,
  5083. pageIdx
  5084. } = this;
  5085. const {
  5086. textContentItemsStr,
  5087. textDivs
  5088. } = this;
  5089. let clearedUntilDivIdx = -1;
  5090. for (const match of matches) {
  5091. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  5092. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  5093. const div = textDivs[n];
  5094. div.textContent = textContentItemsStr[n];
  5095. div.className = "";
  5096. }
  5097. clearedUntilDivIdx = match.end.divIdx + 1;
  5098. }
  5099. if (!findController?.highlightMatches || reset) {
  5100. return;
  5101. }
  5102. const pageMatches = findController.pageMatches[pageIdx] || null;
  5103. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  5104. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  5105. this._renderMatches(this.matches);
  5106. }
  5107. }
  5108. exports.TextHighlighter = TextHighlighter;
  5109. /***/ }),
  5110. /* 19 */
  5111. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5112. Object.defineProperty(exports, "__esModule", ({
  5113. value: true
  5114. }));
  5115. exports.TextLayerBuilder = void 0;
  5116. var _pdfjsLib = __w_pdfjs_require__(4);
  5117. class TextLayerBuilder {
  5118. #rotation = 0;
  5119. #scale = 0;
  5120. #textContentSource = null;
  5121. constructor({
  5122. highlighter = null,
  5123. accessibilityManager = null,
  5124. isOffscreenCanvasSupported = true
  5125. }) {
  5126. this.textContentItemsStr = [];
  5127. this.renderingDone = false;
  5128. this.textDivs = [];
  5129. this.textDivProperties = new WeakMap();
  5130. this.textLayerRenderTask = null;
  5131. this.highlighter = highlighter;
  5132. this.accessibilityManager = accessibilityManager;
  5133. this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
  5134. this.div = document.createElement("div");
  5135. this.div.className = "textLayer";
  5136. this.hide();
  5137. }
  5138. #finishRendering() {
  5139. this.renderingDone = true;
  5140. const endOfContent = document.createElement("div");
  5141. endOfContent.className = "endOfContent";
  5142. this.div.append(endOfContent);
  5143. this.#bindMouse();
  5144. }
  5145. get numTextDivs() {
  5146. return this.textDivs.length;
  5147. }
  5148. async render(viewport) {
  5149. if (!this.#textContentSource) {
  5150. throw new Error('No "textContentSource" parameter specified.');
  5151. }
  5152. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  5153. const {
  5154. rotation
  5155. } = viewport;
  5156. if (this.renderingDone) {
  5157. const mustRotate = rotation !== this.#rotation;
  5158. const mustRescale = scale !== this.#scale;
  5159. if (mustRotate || mustRescale) {
  5160. this.hide();
  5161. (0, _pdfjsLib.updateTextLayer)({
  5162. container: this.div,
  5163. viewport,
  5164. textDivs: this.textDivs,
  5165. textDivProperties: this.textDivProperties,
  5166. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  5167. mustRescale,
  5168. mustRotate
  5169. });
  5170. this.#scale = scale;
  5171. this.#rotation = rotation;
  5172. }
  5173. this.show();
  5174. return;
  5175. }
  5176. this.cancel();
  5177. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  5178. this.accessibilityManager?.setTextMapping(this.textDivs);
  5179. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  5180. textContentSource: this.#textContentSource,
  5181. container: this.div,
  5182. viewport,
  5183. textDivs: this.textDivs,
  5184. textDivProperties: this.textDivProperties,
  5185. textContentItemsStr: this.textContentItemsStr,
  5186. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
  5187. });
  5188. await this.textLayerRenderTask.promise;
  5189. this.#finishRendering();
  5190. this.#scale = scale;
  5191. this.#rotation = rotation;
  5192. this.show();
  5193. this.accessibilityManager?.enable();
  5194. }
  5195. hide() {
  5196. if (!this.div.hidden) {
  5197. this.highlighter?.disable();
  5198. this.div.hidden = true;
  5199. }
  5200. }
  5201. show() {
  5202. if (this.div.hidden && this.renderingDone) {
  5203. this.div.hidden = false;
  5204. this.highlighter?.enable();
  5205. }
  5206. }
  5207. cancel() {
  5208. if (this.textLayerRenderTask) {
  5209. this.textLayerRenderTask.cancel();
  5210. this.textLayerRenderTask = null;
  5211. }
  5212. this.highlighter?.disable();
  5213. this.accessibilityManager?.disable();
  5214. this.textContentItemsStr.length = 0;
  5215. this.textDivs.length = 0;
  5216. this.textDivProperties = new WeakMap();
  5217. }
  5218. setTextContentSource(source) {
  5219. this.cancel();
  5220. this.#textContentSource = source;
  5221. }
  5222. #bindMouse() {
  5223. const {
  5224. div
  5225. } = this;
  5226. div.addEventListener("mousedown", evt => {
  5227. const end = div.querySelector(".endOfContent");
  5228. if (!end) {
  5229. return;
  5230. }
  5231. let adjustTop = evt.target !== div;
  5232. adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  5233. if (adjustTop) {
  5234. const divBounds = div.getBoundingClientRect();
  5235. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  5236. end.style.top = (r * 100).toFixed(2) + "%";
  5237. }
  5238. end.classList.add("active");
  5239. });
  5240. div.addEventListener("mouseup", () => {
  5241. const end = div.querySelector(".endOfContent");
  5242. if (!end) {
  5243. return;
  5244. }
  5245. end.style.top = "";
  5246. end.classList.remove("active");
  5247. });
  5248. }
  5249. }
  5250. exports.TextLayerBuilder = TextLayerBuilder;
  5251. /***/ }),
  5252. /* 20 */
  5253. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5254. Object.defineProperty(exports, "__esModule", ({
  5255. value: true
  5256. }));
  5257. exports.XfaLayerBuilder = void 0;
  5258. var _pdfjsLib = __w_pdfjs_require__(4);
  5259. class XfaLayerBuilder {
  5260. constructor({
  5261. pageDiv,
  5262. pdfPage,
  5263. annotationStorage = null,
  5264. linkService,
  5265. xfaHtml = null
  5266. }) {
  5267. this.pageDiv = pageDiv;
  5268. this.pdfPage = pdfPage;
  5269. this.annotationStorage = annotationStorage;
  5270. this.linkService = linkService;
  5271. this.xfaHtml = xfaHtml;
  5272. this.div = null;
  5273. this._cancelled = false;
  5274. }
  5275. async render(viewport, intent = "display") {
  5276. if (intent === "print") {
  5277. const parameters = {
  5278. viewport: viewport.clone({
  5279. dontFlip: true
  5280. }),
  5281. div: this.div,
  5282. xfaHtml: this.xfaHtml,
  5283. annotationStorage: this.annotationStorage,
  5284. linkService: this.linkService,
  5285. intent
  5286. };
  5287. const div = document.createElement("div");
  5288. this.pageDiv.append(div);
  5289. parameters.div = div;
  5290. return _pdfjsLib.XfaLayer.render(parameters);
  5291. }
  5292. const xfaHtml = await this.pdfPage.getXfa();
  5293. if (this._cancelled || !xfaHtml) {
  5294. return {
  5295. textDivs: []
  5296. };
  5297. }
  5298. const parameters = {
  5299. viewport: viewport.clone({
  5300. dontFlip: true
  5301. }),
  5302. div: this.div,
  5303. xfaHtml,
  5304. annotationStorage: this.annotationStorage,
  5305. linkService: this.linkService,
  5306. intent
  5307. };
  5308. if (this.div) {
  5309. return _pdfjsLib.XfaLayer.update(parameters);
  5310. }
  5311. this.div = document.createElement("div");
  5312. this.pageDiv.append(this.div);
  5313. parameters.div = this.div;
  5314. return _pdfjsLib.XfaLayer.render(parameters);
  5315. }
  5316. cancel() {
  5317. this._cancelled = true;
  5318. }
  5319. hide() {
  5320. if (!this.div) {
  5321. return;
  5322. }
  5323. this.div.hidden = true;
  5324. }
  5325. }
  5326. exports.XfaLayerBuilder = XfaLayerBuilder;
  5327. /***/ }),
  5328. /* 21 */
  5329. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5330. Object.defineProperty(exports, "__esModule", ({
  5331. value: true
  5332. }));
  5333. exports.PDFScriptingManager = void 0;
  5334. var _ui_utils = __w_pdfjs_require__(2);
  5335. var _pdfjsLib = __w_pdfjs_require__(4);
  5336. class PDFScriptingManager {
  5337. constructor({
  5338. eventBus,
  5339. sandboxBundleSrc = null,
  5340. scriptingFactory = null,
  5341. docPropertiesLookup = null
  5342. }) {
  5343. this._pdfDocument = null;
  5344. this._pdfViewer = null;
  5345. this._closeCapability = null;
  5346. this._destroyCapability = null;
  5347. this._scripting = null;
  5348. this._ready = false;
  5349. this._eventBus = eventBus;
  5350. this._sandboxBundleSrc = sandboxBundleSrc;
  5351. this._scriptingFactory = scriptingFactory;
  5352. this._docPropertiesLookup = docPropertiesLookup;
  5353. if (!this._scriptingFactory) {
  5354. window.addEventListener("updatefromsandbox", event => {
  5355. this._eventBus.dispatch("updatefromsandbox", {
  5356. source: window,
  5357. detail: event.detail
  5358. });
  5359. });
  5360. }
  5361. }
  5362. setViewer(pdfViewer) {
  5363. this._pdfViewer = pdfViewer;
  5364. }
  5365. async setDocument(pdfDocument) {
  5366. if (this._pdfDocument) {
  5367. await this._destroyScripting();
  5368. }
  5369. this._pdfDocument = pdfDocument;
  5370. if (!pdfDocument) {
  5371. return;
  5372. }
  5373. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  5374. if (!objects && !docActions) {
  5375. await this._destroyScripting();
  5376. return;
  5377. }
  5378. if (pdfDocument !== this._pdfDocument) {
  5379. return;
  5380. }
  5381. try {
  5382. this._scripting = this._createScripting();
  5383. } catch (error) {
  5384. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  5385. await this._destroyScripting();
  5386. return;
  5387. }
  5388. this._internalEvents.set("updatefromsandbox", event => {
  5389. if (event?.source !== window) {
  5390. return;
  5391. }
  5392. this._updateFromSandbox(event.detail);
  5393. });
  5394. this._internalEvents.set("dispatcheventinsandbox", event => {
  5395. this._scripting?.dispatchEventInSandbox(event.detail);
  5396. });
  5397. this._internalEvents.set("pagechanging", ({
  5398. pageNumber,
  5399. previous
  5400. }) => {
  5401. if (pageNumber === previous) {
  5402. return;
  5403. }
  5404. this._dispatchPageClose(previous);
  5405. this._dispatchPageOpen(pageNumber);
  5406. });
  5407. this._internalEvents.set("pagerendered", ({
  5408. pageNumber
  5409. }) => {
  5410. if (!this._pageOpenPending.has(pageNumber)) {
  5411. return;
  5412. }
  5413. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  5414. return;
  5415. }
  5416. this._dispatchPageOpen(pageNumber);
  5417. });
  5418. this._internalEvents.set("pagesdestroy", async event => {
  5419. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  5420. await this._scripting?.dispatchEventInSandbox({
  5421. id: "doc",
  5422. name: "WillClose"
  5423. });
  5424. this._closeCapability?.resolve();
  5425. });
  5426. for (const [name, listener] of this._internalEvents) {
  5427. this._eventBus._on(name, listener);
  5428. }
  5429. try {
  5430. const docProperties = await this._getDocProperties();
  5431. if (pdfDocument !== this._pdfDocument) {
  5432. return;
  5433. }
  5434. await this._scripting.createSandbox({
  5435. objects,
  5436. calculationOrder,
  5437. appInfo: {
  5438. platform: navigator.platform,
  5439. language: navigator.language
  5440. },
  5441. docInfo: {
  5442. ...docProperties,
  5443. actions: docActions
  5444. }
  5445. });
  5446. this._eventBus.dispatch("sandboxcreated", {
  5447. source: this
  5448. });
  5449. } catch (error) {
  5450. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  5451. await this._destroyScripting();
  5452. return;
  5453. }
  5454. await this._scripting?.dispatchEventInSandbox({
  5455. id: "doc",
  5456. name: "Open"
  5457. });
  5458. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  5459. Promise.resolve().then(() => {
  5460. if (pdfDocument === this._pdfDocument) {
  5461. this._ready = true;
  5462. }
  5463. });
  5464. }
  5465. async dispatchWillSave(detail) {
  5466. return this._scripting?.dispatchEventInSandbox({
  5467. id: "doc",
  5468. name: "WillSave"
  5469. });
  5470. }
  5471. async dispatchDidSave(detail) {
  5472. return this._scripting?.dispatchEventInSandbox({
  5473. id: "doc",
  5474. name: "DidSave"
  5475. });
  5476. }
  5477. async dispatchWillPrint(detail) {
  5478. return this._scripting?.dispatchEventInSandbox({
  5479. id: "doc",
  5480. name: "WillPrint"
  5481. });
  5482. }
  5483. async dispatchDidPrint(detail) {
  5484. return this._scripting?.dispatchEventInSandbox({
  5485. id: "doc",
  5486. name: "DidPrint"
  5487. });
  5488. }
  5489. get destroyPromise() {
  5490. return this._destroyCapability?.promise || null;
  5491. }
  5492. get ready() {
  5493. return this._ready;
  5494. }
  5495. get _internalEvents() {
  5496. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  5497. }
  5498. get _pageOpenPending() {
  5499. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  5500. }
  5501. get _visitedPages() {
  5502. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  5503. }
  5504. async _updateFromSandbox(detail) {
  5505. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  5506. const {
  5507. id,
  5508. siblings,
  5509. command,
  5510. value
  5511. } = detail;
  5512. if (!id) {
  5513. switch (command) {
  5514. case "clear":
  5515. console.clear();
  5516. break;
  5517. case "error":
  5518. console.error(value);
  5519. break;
  5520. case "layout":
  5521. {
  5522. if (isInPresentationMode) {
  5523. return;
  5524. }
  5525. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  5526. this._pdfViewer.spreadMode = modes.spreadMode;
  5527. break;
  5528. }
  5529. case "page-num":
  5530. this._pdfViewer.currentPageNumber = value + 1;
  5531. break;
  5532. case "print":
  5533. await this._pdfViewer.pagesPromise;
  5534. this._eventBus.dispatch("print", {
  5535. source: this
  5536. });
  5537. break;
  5538. case "println":
  5539. console.log(value);
  5540. break;
  5541. case "zoom":
  5542. if (isInPresentationMode) {
  5543. return;
  5544. }
  5545. this._pdfViewer.currentScaleValue = value;
  5546. break;
  5547. case "SaveAs":
  5548. this._eventBus.dispatch("download", {
  5549. source: this
  5550. });
  5551. break;
  5552. case "FirstPage":
  5553. this._pdfViewer.currentPageNumber = 1;
  5554. break;
  5555. case "LastPage":
  5556. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  5557. break;
  5558. case "NextPage":
  5559. this._pdfViewer.nextPage();
  5560. break;
  5561. case "PrevPage":
  5562. this._pdfViewer.previousPage();
  5563. break;
  5564. case "ZoomViewIn":
  5565. if (isInPresentationMode) {
  5566. return;
  5567. }
  5568. this._pdfViewer.increaseScale();
  5569. break;
  5570. case "ZoomViewOut":
  5571. if (isInPresentationMode) {
  5572. return;
  5573. }
  5574. this._pdfViewer.decreaseScale();
  5575. break;
  5576. }
  5577. return;
  5578. }
  5579. if (isInPresentationMode) {
  5580. if (detail.focus) {
  5581. return;
  5582. }
  5583. }
  5584. delete detail.id;
  5585. delete detail.siblings;
  5586. const ids = siblings ? [id, ...siblings] : [id];
  5587. for (const elementId of ids) {
  5588. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  5589. if (element) {
  5590. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  5591. detail
  5592. }));
  5593. } else {
  5594. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  5595. }
  5596. }
  5597. }
  5598. async _dispatchPageOpen(pageNumber, initialize = false) {
  5599. const pdfDocument = this._pdfDocument,
  5600. visitedPages = this._visitedPages;
  5601. if (initialize) {
  5602. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  5603. }
  5604. if (!this._closeCapability) {
  5605. return;
  5606. }
  5607. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  5608. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  5609. this._pageOpenPending.add(pageNumber);
  5610. return;
  5611. }
  5612. this._pageOpenPending.delete(pageNumber);
  5613. const actionsPromise = (async () => {
  5614. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  5615. if (pdfDocument !== this._pdfDocument) {
  5616. return;
  5617. }
  5618. await this._scripting?.dispatchEventInSandbox({
  5619. id: "page",
  5620. name: "PageOpen",
  5621. pageNumber,
  5622. actions
  5623. });
  5624. })();
  5625. visitedPages.set(pageNumber, actionsPromise);
  5626. }
  5627. async _dispatchPageClose(pageNumber) {
  5628. const pdfDocument = this._pdfDocument,
  5629. visitedPages = this._visitedPages;
  5630. if (!this._closeCapability) {
  5631. return;
  5632. }
  5633. if (this._pageOpenPending.has(pageNumber)) {
  5634. return;
  5635. }
  5636. const actionsPromise = visitedPages.get(pageNumber);
  5637. if (!actionsPromise) {
  5638. return;
  5639. }
  5640. visitedPages.set(pageNumber, null);
  5641. await actionsPromise;
  5642. if (pdfDocument !== this._pdfDocument) {
  5643. return;
  5644. }
  5645. await this._scripting?.dispatchEventInSandbox({
  5646. id: "page",
  5647. name: "PageClose",
  5648. pageNumber
  5649. });
  5650. }
  5651. async _getDocProperties() {
  5652. if (this._docPropertiesLookup) {
  5653. return this._docPropertiesLookup(this._pdfDocument);
  5654. }
  5655. const {
  5656. docPropertiesLookup
  5657. } = __w_pdfjs_require__(22);
  5658. return docPropertiesLookup(this._pdfDocument);
  5659. }
  5660. _createScripting() {
  5661. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  5662. if (this._scripting) {
  5663. throw new Error("_createScripting: Scripting already exists.");
  5664. }
  5665. if (this._scriptingFactory) {
  5666. return this._scriptingFactory.createScripting({
  5667. sandboxBundleSrc: this._sandboxBundleSrc
  5668. });
  5669. }
  5670. const {
  5671. GenericScripting
  5672. } = __w_pdfjs_require__(22);
  5673. return new GenericScripting(this._sandboxBundleSrc);
  5674. }
  5675. async _destroyScripting() {
  5676. if (!this._scripting) {
  5677. this._pdfDocument = null;
  5678. this._destroyCapability?.resolve();
  5679. return;
  5680. }
  5681. if (this._closeCapability) {
  5682. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  5683. setTimeout(resolve, 1000);
  5684. })]).catch(reason => {});
  5685. this._closeCapability = null;
  5686. }
  5687. this._pdfDocument = null;
  5688. try {
  5689. await this._scripting.destroySandbox();
  5690. } catch (ex) {}
  5691. for (const [name, listener] of this._internalEvents) {
  5692. this._eventBus._off(name, listener);
  5693. }
  5694. this._internalEvents.clear();
  5695. this._pageOpenPending.clear();
  5696. this._visitedPages.clear();
  5697. this._scripting = null;
  5698. this._ready = false;
  5699. this._destroyCapability?.resolve();
  5700. }
  5701. }
  5702. exports.PDFScriptingManager = PDFScriptingManager;
  5703. /***/ }),
  5704. /* 22 */
  5705. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5706. Object.defineProperty(exports, "__esModule", ({
  5707. value: true
  5708. }));
  5709. exports.GenericScripting = void 0;
  5710. exports.docPropertiesLookup = docPropertiesLookup;
  5711. var _pdfjsLib = __w_pdfjs_require__(4);
  5712. async function docPropertiesLookup(pdfDocument) {
  5713. const url = "",
  5714. baseUrl = url.split("#")[0];
  5715. let {
  5716. info,
  5717. metadata,
  5718. contentDispositionFilename,
  5719. contentLength
  5720. } = await pdfDocument.getMetadata();
  5721. if (!contentLength) {
  5722. const {
  5723. length
  5724. } = await pdfDocument.getDownloadInfo();
  5725. contentLength = length;
  5726. }
  5727. return {
  5728. ...info,
  5729. baseURL: baseUrl,
  5730. filesize: contentLength,
  5731. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  5732. metadata: metadata?.getRaw(),
  5733. authors: metadata?.get("dc:creator"),
  5734. numPages: pdfDocument.numPages,
  5735. URL: url
  5736. };
  5737. }
  5738. class GenericScripting {
  5739. constructor(sandboxBundleSrc) {
  5740. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  5741. return window.pdfjsSandbox.QuickJSSandbox();
  5742. });
  5743. }
  5744. async createSandbox(data) {
  5745. const sandbox = await this._ready;
  5746. sandbox.create(data);
  5747. }
  5748. async dispatchEventInSandbox(event) {
  5749. const sandbox = await this._ready;
  5750. setTimeout(() => sandbox.dispatchEvent(event), 0);
  5751. }
  5752. async destroySandbox() {
  5753. const sandbox = await this._ready;
  5754. sandbox.nukeSandbox();
  5755. }
  5756. }
  5757. exports.GenericScripting = GenericScripting;
  5758. /***/ }),
  5759. /* 23 */
  5760. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5761. Object.defineProperty(exports, "__esModule", ({
  5762. value: true
  5763. }));
  5764. exports.PDFSinglePageViewer = void 0;
  5765. var _ui_utils = __w_pdfjs_require__(2);
  5766. var _pdf_viewer = __w_pdfjs_require__(24);
  5767. class PDFSinglePageViewer extends _pdf_viewer.PDFViewer {
  5768. _resetView() {
  5769. super._resetView();
  5770. this._scrollMode = _ui_utils.ScrollMode.PAGE;
  5771. this._spreadMode = _ui_utils.SpreadMode.NONE;
  5772. }
  5773. set scrollMode(mode) {}
  5774. _updateScrollMode() {}
  5775. set spreadMode(mode) {}
  5776. _updateSpreadMode() {}
  5777. }
  5778. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  5779. /***/ }),
  5780. /* 24 */
  5781. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5782. Object.defineProperty(exports, "__esModule", ({
  5783. value: true
  5784. }));
  5785. exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
  5786. var _pdfjsLib = __w_pdfjs_require__(4);
  5787. var _ui_utils = __w_pdfjs_require__(2);
  5788. var _l10n_utils = __w_pdfjs_require__(5);
  5789. var _pdf_page_view = __w_pdfjs_require__(13);
  5790. var _pdf_rendering_queue = __w_pdfjs_require__(25);
  5791. var _pdf_link_service = __w_pdfjs_require__(1);
  5792. const DEFAULT_CACHE_SIZE = 10;
  5793. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  5794. const PagesCountLimit = {
  5795. FORCE_SCROLL_MODE_PAGE: 15000,
  5796. FORCE_LAZY_PAGE_INIT: 7500,
  5797. PAUSE_EAGER_PAGE_INIT: 250
  5798. };
  5799. exports.PagesCountLimit = PagesCountLimit;
  5800. function isValidAnnotationEditorMode(mode) {
  5801. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  5802. }
  5803. class PDFPageViewBuffer {
  5804. #buf = new Set();
  5805. #size = 0;
  5806. constructor(size) {
  5807. this.#size = size;
  5808. }
  5809. push(view) {
  5810. const buf = this.#buf;
  5811. if (buf.has(view)) {
  5812. buf.delete(view);
  5813. }
  5814. buf.add(view);
  5815. if (buf.size > this.#size) {
  5816. this.#destroyFirstView();
  5817. }
  5818. }
  5819. resize(newSize, idsToKeep = null) {
  5820. this.#size = newSize;
  5821. const buf = this.#buf;
  5822. if (idsToKeep) {
  5823. const ii = buf.size;
  5824. let i = 1;
  5825. for (const view of buf) {
  5826. if (idsToKeep.has(view.id)) {
  5827. buf.delete(view);
  5828. buf.add(view);
  5829. }
  5830. if (++i > ii) {
  5831. break;
  5832. }
  5833. }
  5834. }
  5835. while (buf.size > this.#size) {
  5836. this.#destroyFirstView();
  5837. }
  5838. }
  5839. has(view) {
  5840. return this.#buf.has(view);
  5841. }
  5842. [Symbol.iterator]() {
  5843. return this.#buf.keys();
  5844. }
  5845. #destroyFirstView() {
  5846. const firstView = this.#buf.keys().next().value;
  5847. firstView?.destroy();
  5848. this.#buf.delete(firstView);
  5849. }
  5850. }
  5851. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  5852. class PDFViewer {
  5853. #buffer = null;
  5854. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  5855. #annotationEditorUIManager = null;
  5856. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  5857. #containerTopLeft = null;
  5858. #enablePermissions = false;
  5859. #previousContainerHeight = 0;
  5860. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  5861. #scrollModePageState = null;
  5862. #onVisibilityChange = null;
  5863. #scaleTimeoutId = null;
  5864. constructor(options) {
  5865. const viewerVersion = '3.2.146';
  5866. if (_pdfjsLib.version !== viewerVersion) {
  5867. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  5868. }
  5869. this.container = options.container;
  5870. this.#resizeObserver.observe(this.container);
  5871. this.viewer = options.viewer || options.container.firstElementChild;
  5872. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  5873. throw new Error("Invalid `container` and/or `viewer` option.");
  5874. }
  5875. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  5876. throw new Error("The `container` must be absolutely positioned.");
  5877. }
  5878. this.eventBus = options.eventBus;
  5879. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  5880. this.downloadManager = options.downloadManager || null;
  5881. this.findController = options.findController || null;
  5882. this._scriptingManager = options.scriptingManager || null;
  5883. this.removePageBorders = options.removePageBorders || false;
  5884. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  5885. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  5886. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
  5887. this.imageResourcesPath = options.imageResourcesPath || "";
  5888. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  5889. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  5890. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  5891. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  5892. this.maxCanvasPixels = options.maxCanvasPixels;
  5893. this.l10n = options.l10n || _l10n_utils.NullL10n;
  5894. this.#enablePermissions = options.enablePermissions || false;
  5895. this.pageColors = options.pageColors || null;
  5896. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  5897. if (this.pageColors.background || this.pageColors.foreground) {
  5898. console.warn("PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  5899. }
  5900. this.pageColors = null;
  5901. }
  5902. this.defaultRenderingQueue = !options.renderingQueue;
  5903. if (this.defaultRenderingQueue) {
  5904. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  5905. this.renderingQueue.setViewer(this);
  5906. } else {
  5907. this.renderingQueue = options.renderingQueue;
  5908. }
  5909. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  5910. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  5911. this._onBeforeDraw = this._onAfterDraw = null;
  5912. this._resetView();
  5913. if (this.removePageBorders) {
  5914. this.viewer.classList.add("removePageBorders");
  5915. }
  5916. this.#updateContainerHeightCss();
  5917. }
  5918. get pagesCount() {
  5919. return this._pages.length;
  5920. }
  5921. getPageView(index) {
  5922. return this._pages[index];
  5923. }
  5924. get pageViewsReady() {
  5925. if (!this._pagesCapability.settled) {
  5926. return false;
  5927. }
  5928. return this._pages.every(function (pageView) {
  5929. return pageView?.pdfPage;
  5930. });
  5931. }
  5932. get renderForms() {
  5933. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  5934. }
  5935. get enableScripting() {
  5936. return !!this._scriptingManager;
  5937. }
  5938. get currentPageNumber() {
  5939. return this._currentPageNumber;
  5940. }
  5941. set currentPageNumber(val) {
  5942. if (!Number.isInteger(val)) {
  5943. throw new Error("Invalid page number.");
  5944. }
  5945. if (!this.pdfDocument) {
  5946. return;
  5947. }
  5948. if (!this._setCurrentPageNumber(val, true)) {
  5949. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  5950. }
  5951. }
  5952. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  5953. if (this._currentPageNumber === val) {
  5954. if (resetCurrentPageView) {
  5955. this.#resetCurrentPageView();
  5956. }
  5957. return true;
  5958. }
  5959. if (!(0 < val && val <= this.pagesCount)) {
  5960. return false;
  5961. }
  5962. const previous = this._currentPageNumber;
  5963. this._currentPageNumber = val;
  5964. this.eventBus.dispatch("pagechanging", {
  5965. source: this,
  5966. pageNumber: val,
  5967. pageLabel: this._pageLabels?.[val - 1] ?? null,
  5968. previous
  5969. });
  5970. if (resetCurrentPageView) {
  5971. this.#resetCurrentPageView();
  5972. }
  5973. return true;
  5974. }
  5975. get currentPageLabel() {
  5976. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  5977. }
  5978. set currentPageLabel(val) {
  5979. if (!this.pdfDocument) {
  5980. return;
  5981. }
  5982. let page = val | 0;
  5983. if (this._pageLabels) {
  5984. const i = this._pageLabels.indexOf(val);
  5985. if (i >= 0) {
  5986. page = i + 1;
  5987. }
  5988. }
  5989. if (!this._setCurrentPageNumber(page, true)) {
  5990. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  5991. }
  5992. }
  5993. get currentScale() {
  5994. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  5995. }
  5996. set currentScale(val) {
  5997. if (isNaN(val)) {
  5998. throw new Error("Invalid numeric scale.");
  5999. }
  6000. if (!this.pdfDocument) {
  6001. return;
  6002. }
  6003. this._setScale(val, {
  6004. noScroll: false
  6005. });
  6006. }
  6007. get currentScaleValue() {
  6008. return this._currentScaleValue;
  6009. }
  6010. set currentScaleValue(val) {
  6011. if (!this.pdfDocument) {
  6012. return;
  6013. }
  6014. this._setScale(val, {
  6015. noScroll: false
  6016. });
  6017. }
  6018. get pagesRotation() {
  6019. return this._pagesRotation;
  6020. }
  6021. set pagesRotation(rotation) {
  6022. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  6023. throw new Error("Invalid pages rotation angle.");
  6024. }
  6025. if (!this.pdfDocument) {
  6026. return;
  6027. }
  6028. rotation %= 360;
  6029. if (rotation < 0) {
  6030. rotation += 360;
  6031. }
  6032. if (this._pagesRotation === rotation) {
  6033. return;
  6034. }
  6035. this._pagesRotation = rotation;
  6036. const pageNumber = this._currentPageNumber;
  6037. this.refresh(true, {
  6038. rotation
  6039. });
  6040. if (this._currentScaleValue) {
  6041. this._setScale(this._currentScaleValue, {
  6042. noScroll: true
  6043. });
  6044. }
  6045. this.eventBus.dispatch("rotationchanging", {
  6046. source: this,
  6047. pagesRotation: rotation,
  6048. pageNumber
  6049. });
  6050. if (this.defaultRenderingQueue) {
  6051. this.update();
  6052. }
  6053. }
  6054. get firstPagePromise() {
  6055. return this.pdfDocument ? this._firstPageCapability.promise : null;
  6056. }
  6057. get onePageRendered() {
  6058. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  6059. }
  6060. get pagesPromise() {
  6061. return this.pdfDocument ? this._pagesCapability.promise : null;
  6062. }
  6063. #layerProperties() {
  6064. const self = this;
  6065. return {
  6066. get annotationEditorUIManager() {
  6067. return self.#annotationEditorUIManager;
  6068. },
  6069. get annotationStorage() {
  6070. return self.pdfDocument?.annotationStorage;
  6071. },
  6072. get downloadManager() {
  6073. return self.downloadManager;
  6074. },
  6075. get enableScripting() {
  6076. return !!self._scriptingManager;
  6077. },
  6078. get fieldObjectsPromise() {
  6079. return self.pdfDocument?.getFieldObjects();
  6080. },
  6081. get findController() {
  6082. return self.findController;
  6083. },
  6084. get hasJSActionsPromise() {
  6085. return self.pdfDocument?.hasJSActions();
  6086. },
  6087. get linkService() {
  6088. return self.linkService;
  6089. }
  6090. };
  6091. }
  6092. #initializePermissions(permissions) {
  6093. const params = {
  6094. annotationEditorMode: this.#annotationEditorMode,
  6095. annotationMode: this.#annotationMode,
  6096. textLayerMode: this.textLayerMode
  6097. };
  6098. if (!permissions) {
  6099. return params;
  6100. }
  6101. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  6102. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  6103. }
  6104. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  6105. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  6106. }
  6107. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  6108. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  6109. }
  6110. return params;
  6111. }
  6112. #onePageRenderedOrForceFetch() {
  6113. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  6114. return Promise.resolve();
  6115. }
  6116. const visibilityChangePromise = new Promise(resolve => {
  6117. this.#onVisibilityChange = () => {
  6118. if (document.visibilityState !== "hidden") {
  6119. return;
  6120. }
  6121. resolve();
  6122. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  6123. this.#onVisibilityChange = null;
  6124. };
  6125. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  6126. });
  6127. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  6128. }
  6129. setDocument(pdfDocument) {
  6130. if (this.pdfDocument) {
  6131. this.eventBus.dispatch("pagesdestroy", {
  6132. source: this
  6133. });
  6134. this._cancelRendering();
  6135. this._resetView();
  6136. this.findController?.setDocument(null);
  6137. this._scriptingManager?.setDocument(null);
  6138. if (this.#annotationEditorUIManager) {
  6139. this.#annotationEditorUIManager.destroy();
  6140. this.#annotationEditorUIManager = null;
  6141. }
  6142. }
  6143. this.pdfDocument = pdfDocument;
  6144. if (!pdfDocument) {
  6145. return;
  6146. }
  6147. const pagesCount = pdfDocument.numPages;
  6148. const firstPagePromise = pdfDocument.getPage(1);
  6149. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  6150. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  6151. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  6152. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  6153. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  6154. this.eventBus.dispatch("scrollmodechanged", {
  6155. source: this,
  6156. mode
  6157. });
  6158. }
  6159. this._pagesCapability.promise.then(() => {
  6160. this.eventBus.dispatch("pagesloaded", {
  6161. source: this,
  6162. pagesCount
  6163. });
  6164. }, () => {});
  6165. this._onBeforeDraw = evt => {
  6166. const pageView = this._pages[evt.pageNumber - 1];
  6167. if (!pageView) {
  6168. return;
  6169. }
  6170. this.#buffer.push(pageView);
  6171. };
  6172. this.eventBus._on("pagerender", this._onBeforeDraw);
  6173. this._onAfterDraw = evt => {
  6174. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  6175. return;
  6176. }
  6177. this._onePageRenderedCapability.resolve({
  6178. timestamp: evt.timestamp
  6179. });
  6180. this.eventBus._off("pagerendered", this._onAfterDraw);
  6181. this._onAfterDraw = null;
  6182. if (this.#onVisibilityChange) {
  6183. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  6184. this.#onVisibilityChange = null;
  6185. }
  6186. };
  6187. this.eventBus._on("pagerendered", this._onAfterDraw);
  6188. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  6189. if (pdfDocument !== this.pdfDocument) {
  6190. return;
  6191. }
  6192. this._firstPageCapability.resolve(firstPdfPage);
  6193. this._optionalContentConfigPromise = optionalContentConfigPromise;
  6194. const {
  6195. annotationEditorMode,
  6196. annotationMode,
  6197. textLayerMode
  6198. } = this.#initializePermissions(permissions);
  6199. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6200. const mode = annotationEditorMode;
  6201. if (pdfDocument.isPureXfa) {
  6202. console.warn("Warning: XFA-editing is not implemented.");
  6203. } else if (isValidAnnotationEditorMode(mode)) {
  6204. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus, pdfDocument?.annotationStorage);
  6205. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  6206. this.#annotationEditorUIManager.updateMode(mode);
  6207. }
  6208. } else {
  6209. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  6210. }
  6211. }
  6212. const layerProperties = this.#layerProperties.bind(this);
  6213. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  6214. const scale = this.currentScale;
  6215. const viewport = firstPdfPage.getViewport({
  6216. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  6217. });
  6218. _ui_utils.docStyle.setProperty("--scale-factor", viewport.scale);
  6219. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  6220. const pageView = new _pdf_page_view.PDFPageView({
  6221. container: viewerElement,
  6222. eventBus: this.eventBus,
  6223. id: pageNum,
  6224. scale,
  6225. defaultViewport: viewport.clone(),
  6226. optionalContentConfigPromise,
  6227. renderingQueue: this.renderingQueue,
  6228. textLayerMode,
  6229. annotationMode,
  6230. imageResourcesPath: this.imageResourcesPath,
  6231. renderer: this.renderer,
  6232. useOnlyCssZoom: this.useOnlyCssZoom,
  6233. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  6234. maxCanvasPixels: this.maxCanvasPixels,
  6235. pageColors: this.pageColors,
  6236. l10n: this.l10n,
  6237. layerProperties
  6238. });
  6239. this._pages.push(pageView);
  6240. }
  6241. const firstPageView = this._pages[0];
  6242. if (firstPageView) {
  6243. firstPageView.setPdfPage(firstPdfPage);
  6244. this.linkService.cachePageRef(1, firstPdfPage.ref);
  6245. }
  6246. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  6247. this.#ensurePageViewVisible();
  6248. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  6249. this._updateSpreadMode();
  6250. }
  6251. this.#onePageRenderedOrForceFetch().then(async () => {
  6252. this.findController?.setDocument(pdfDocument);
  6253. this._scriptingManager?.setDocument(pdfDocument);
  6254. if (this.#annotationEditorUIManager) {
  6255. this.eventBus.dispatch("annotationeditormodechanged", {
  6256. source: this,
  6257. mode: this.#annotationEditorMode
  6258. });
  6259. }
  6260. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  6261. this._pagesCapability.resolve();
  6262. return;
  6263. }
  6264. let getPagesLeft = pagesCount - 1;
  6265. if (getPagesLeft <= 0) {
  6266. this._pagesCapability.resolve();
  6267. return;
  6268. }
  6269. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  6270. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  6271. const pageView = this._pages[pageNum - 1];
  6272. if (!pageView.pdfPage) {
  6273. pageView.setPdfPage(pdfPage);
  6274. }
  6275. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  6276. if (--getPagesLeft === 0) {
  6277. this._pagesCapability.resolve();
  6278. }
  6279. }, reason => {
  6280. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  6281. if (--getPagesLeft === 0) {
  6282. this._pagesCapability.resolve();
  6283. }
  6284. });
  6285. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  6286. await promise;
  6287. }
  6288. }
  6289. });
  6290. this.eventBus.dispatch("pagesinit", {
  6291. source: this
  6292. });
  6293. pdfDocument.getMetadata().then(({
  6294. info
  6295. }) => {
  6296. if (pdfDocument !== this.pdfDocument) {
  6297. return;
  6298. }
  6299. if (info.Language) {
  6300. this.viewer.lang = info.Language;
  6301. }
  6302. });
  6303. if (this.defaultRenderingQueue) {
  6304. this.update();
  6305. }
  6306. }).catch(reason => {
  6307. console.error("Unable to initialize viewer", reason);
  6308. this._pagesCapability.reject(reason);
  6309. });
  6310. }
  6311. setPageLabels(labels) {
  6312. if (!this.pdfDocument) {
  6313. return;
  6314. }
  6315. if (!labels) {
  6316. this._pageLabels = null;
  6317. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  6318. this._pageLabels = null;
  6319. console.error(`setPageLabels: Invalid page labels.`);
  6320. } else {
  6321. this._pageLabels = labels;
  6322. }
  6323. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  6324. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  6325. }
  6326. }
  6327. _resetView() {
  6328. this._pages = [];
  6329. this._currentPageNumber = 1;
  6330. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  6331. this._currentScaleValue = null;
  6332. this._pageLabels = null;
  6333. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  6334. this._location = null;
  6335. this._pagesRotation = 0;
  6336. this._optionalContentConfigPromise = null;
  6337. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  6338. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  6339. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  6340. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  6341. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  6342. this._spreadMode = _ui_utils.SpreadMode.NONE;
  6343. this.#scrollModePageState = {
  6344. previousPageNumber: 1,
  6345. scrollDown: true,
  6346. pages: []
  6347. };
  6348. if (this._onBeforeDraw) {
  6349. this.eventBus._off("pagerender", this._onBeforeDraw);
  6350. this._onBeforeDraw = null;
  6351. }
  6352. if (this._onAfterDraw) {
  6353. this.eventBus._off("pagerendered", this._onAfterDraw);
  6354. this._onAfterDraw = null;
  6355. }
  6356. if (this.#onVisibilityChange) {
  6357. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  6358. this.#onVisibilityChange = null;
  6359. }
  6360. this.viewer.textContent = "";
  6361. this._updateScrollMode();
  6362. this.viewer.removeAttribute("lang");
  6363. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  6364. }
  6365. #ensurePageViewVisible() {
  6366. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  6367. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  6368. }
  6369. const pageNumber = this._currentPageNumber,
  6370. state = this.#scrollModePageState,
  6371. viewer = this.viewer;
  6372. viewer.textContent = "";
  6373. state.pages.length = 0;
  6374. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  6375. const pageView = this._pages[pageNumber - 1];
  6376. viewer.append(pageView.div);
  6377. state.pages.push(pageView);
  6378. } else {
  6379. const pageIndexSet = new Set(),
  6380. parity = this._spreadMode - 1;
  6381. if (parity === -1) {
  6382. pageIndexSet.add(pageNumber - 1);
  6383. } else if (pageNumber % 2 !== parity) {
  6384. pageIndexSet.add(pageNumber - 1);
  6385. pageIndexSet.add(pageNumber);
  6386. } else {
  6387. pageIndexSet.add(pageNumber - 2);
  6388. pageIndexSet.add(pageNumber - 1);
  6389. }
  6390. const spread = document.createElement("div");
  6391. spread.className = "spread";
  6392. if (this.isInPresentationMode) {
  6393. const dummyPage = document.createElement("div");
  6394. dummyPage.className = "dummyPage";
  6395. spread.append(dummyPage);
  6396. }
  6397. for (const i of pageIndexSet) {
  6398. const pageView = this._pages[i];
  6399. if (!pageView) {
  6400. continue;
  6401. }
  6402. spread.append(pageView.div);
  6403. state.pages.push(pageView);
  6404. }
  6405. viewer.append(spread);
  6406. }
  6407. state.scrollDown = pageNumber >= state.previousPageNumber;
  6408. state.previousPageNumber = pageNumber;
  6409. }
  6410. _scrollUpdate() {
  6411. if (this.pagesCount === 0) {
  6412. return;
  6413. }
  6414. this.update();
  6415. }
  6416. #scrollIntoView(pageView, pageSpot = null) {
  6417. const {
  6418. div,
  6419. id
  6420. } = pageView;
  6421. if (this._currentPageNumber !== id) {
  6422. this._setCurrentPageNumber(id);
  6423. }
  6424. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  6425. this.#ensurePageViewVisible();
  6426. this.update();
  6427. }
  6428. if (!pageSpot && !this.isInPresentationMode) {
  6429. const left = div.offsetLeft + div.clientLeft,
  6430. right = left + div.clientWidth;
  6431. const {
  6432. scrollLeft,
  6433. clientWidth
  6434. } = this.container;
  6435. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  6436. pageSpot = {
  6437. left: 0,
  6438. top: 0
  6439. };
  6440. }
  6441. }
  6442. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  6443. if (!this._currentScaleValue && this._location) {
  6444. this._location = null;
  6445. }
  6446. }
  6447. #isSameScale(newScale) {
  6448. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  6449. }
  6450. _setScaleUpdatePages(newScale, newValue, {
  6451. noScroll = false,
  6452. preset = false,
  6453. drawingDelay = -1
  6454. }) {
  6455. this._currentScaleValue = newValue.toString();
  6456. if (this.#isSameScale(newScale)) {
  6457. if (preset) {
  6458. this.eventBus.dispatch("scalechanging", {
  6459. source: this,
  6460. scale: newScale,
  6461. presetValue: newValue
  6462. });
  6463. }
  6464. return;
  6465. }
  6466. _ui_utils.docStyle.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  6467. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  6468. this.refresh(true, {
  6469. scale: newScale,
  6470. drawingDelay: postponeDrawing ? drawingDelay : -1
  6471. });
  6472. if (postponeDrawing) {
  6473. this.#scaleTimeoutId = setTimeout(() => {
  6474. this.#scaleTimeoutId = null;
  6475. this.refresh();
  6476. }, drawingDelay);
  6477. }
  6478. this._currentScale = newScale;
  6479. if (!noScroll) {
  6480. let page = this._currentPageNumber,
  6481. dest;
  6482. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  6483. page = this._location.pageNumber;
  6484. dest = [null, {
  6485. name: "XYZ"
  6486. }, this._location.left, this._location.top, null];
  6487. }
  6488. this.scrollPageIntoView({
  6489. pageNumber: page,
  6490. destArray: dest,
  6491. allowNegativeOffset: true
  6492. });
  6493. }
  6494. this.eventBus.dispatch("scalechanging", {
  6495. source: this,
  6496. scale: newScale,
  6497. presetValue: preset ? newValue : undefined
  6498. });
  6499. if (this.defaultRenderingQueue) {
  6500. this.update();
  6501. }
  6502. }
  6503. get _pageWidthScaleFactor() {
  6504. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  6505. return 2;
  6506. }
  6507. return 1;
  6508. }
  6509. _setScale(value, options) {
  6510. let scale = parseFloat(value);
  6511. if (scale > 0) {
  6512. options.preset = false;
  6513. this._setScaleUpdatePages(scale, value, options);
  6514. } else {
  6515. const currentPage = this._pages[this._currentPageNumber - 1];
  6516. if (!currentPage) {
  6517. return;
  6518. }
  6519. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  6520. vPadding = _ui_utils.VERTICAL_PADDING;
  6521. if (this.isInPresentationMode) {
  6522. hPadding = vPadding = 4;
  6523. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  6524. hPadding *= 2;
  6525. }
  6526. } else if (this.removePageBorders) {
  6527. hPadding = vPadding = 0;
  6528. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  6529. [hPadding, vPadding] = [vPadding, hPadding];
  6530. }
  6531. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  6532. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  6533. switch (value) {
  6534. case "page-actual":
  6535. scale = 1;
  6536. break;
  6537. case "page-width":
  6538. scale = pageWidthScale;
  6539. break;
  6540. case "page-height":
  6541. scale = pageHeightScale;
  6542. break;
  6543. case "page-fit":
  6544. scale = Math.min(pageWidthScale, pageHeightScale);
  6545. break;
  6546. case "auto":
  6547. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  6548. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  6549. break;
  6550. default:
  6551. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  6552. return;
  6553. }
  6554. options.preset = true;
  6555. this._setScaleUpdatePages(scale, value, options);
  6556. }
  6557. }
  6558. #resetCurrentPageView() {
  6559. const pageView = this._pages[this._currentPageNumber - 1];
  6560. if (this.isInPresentationMode) {
  6561. this._setScale(this._currentScaleValue, {
  6562. noScroll: true
  6563. });
  6564. }
  6565. this.#scrollIntoView(pageView);
  6566. }
  6567. pageLabelToPageNumber(label) {
  6568. if (!this._pageLabels) {
  6569. return null;
  6570. }
  6571. const i = this._pageLabels.indexOf(label);
  6572. if (i < 0) {
  6573. return null;
  6574. }
  6575. return i + 1;
  6576. }
  6577. scrollPageIntoView({
  6578. pageNumber,
  6579. destArray = null,
  6580. allowNegativeOffset = false,
  6581. ignoreDestinationZoom = false
  6582. }) {
  6583. if (!this.pdfDocument) {
  6584. return;
  6585. }
  6586. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  6587. if (!pageView) {
  6588. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  6589. return;
  6590. }
  6591. if (this.isInPresentationMode || !destArray) {
  6592. this._setCurrentPageNumber(pageNumber, true);
  6593. return;
  6594. }
  6595. let x = 0,
  6596. y = 0;
  6597. let width = 0,
  6598. height = 0,
  6599. widthScale,
  6600. heightScale;
  6601. const changeOrientation = pageView.rotation % 180 !== 0;
  6602. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  6603. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  6604. let scale = 0;
  6605. switch (destArray[1].name) {
  6606. case "XYZ":
  6607. x = destArray[2];
  6608. y = destArray[3];
  6609. scale = destArray[4];
  6610. x = x !== null ? x : 0;
  6611. y = y !== null ? y : pageHeight;
  6612. break;
  6613. case "Fit":
  6614. case "FitB":
  6615. scale = "page-fit";
  6616. break;
  6617. case "FitH":
  6618. case "FitBH":
  6619. y = destArray[2];
  6620. scale = "page-width";
  6621. if (y === null && this._location) {
  6622. x = this._location.left;
  6623. y = this._location.top;
  6624. } else if (typeof y !== "number" || y < 0) {
  6625. y = pageHeight;
  6626. }
  6627. break;
  6628. case "FitV":
  6629. case "FitBV":
  6630. x = destArray[2];
  6631. width = pageWidth;
  6632. height = pageHeight;
  6633. scale = "page-height";
  6634. break;
  6635. case "FitR":
  6636. x = destArray[2];
  6637. y = destArray[3];
  6638. width = destArray[4] - x;
  6639. height = destArray[5] - y;
  6640. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  6641. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  6642. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  6643. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  6644. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  6645. break;
  6646. default:
  6647. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  6648. return;
  6649. }
  6650. if (!ignoreDestinationZoom) {
  6651. if (scale && scale !== this._currentScale) {
  6652. this.currentScaleValue = scale;
  6653. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  6654. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  6655. }
  6656. }
  6657. if (scale === "page-fit" && !destArray[4]) {
  6658. this.#scrollIntoView(pageView);
  6659. return;
  6660. }
  6661. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  6662. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  6663. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  6664. if (!allowNegativeOffset) {
  6665. left = Math.max(left, 0);
  6666. top = Math.max(top, 0);
  6667. }
  6668. this.#scrollIntoView(pageView, {
  6669. left,
  6670. top
  6671. });
  6672. }
  6673. _updateLocation(firstPage) {
  6674. const currentScale = this._currentScale;
  6675. const currentScaleValue = this._currentScaleValue;
  6676. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  6677. const pageNumber = firstPage.id;
  6678. const currentPageView = this._pages[pageNumber - 1];
  6679. const container = this.container;
  6680. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  6681. const intLeft = Math.round(topLeft[0]);
  6682. const intTop = Math.round(topLeft[1]);
  6683. let pdfOpenParams = `#page=${pageNumber}`;
  6684. if (!this.isInPresentationMode) {
  6685. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  6686. }
  6687. this._location = {
  6688. pageNumber,
  6689. scale: normalizedScaleValue,
  6690. top: intTop,
  6691. left: intLeft,
  6692. rotation: this._pagesRotation,
  6693. pdfOpenParams
  6694. };
  6695. }
  6696. update() {
  6697. const visible = this._getVisiblePages();
  6698. const visiblePages = visible.views,
  6699. numVisiblePages = visiblePages.length;
  6700. if (numVisiblePages === 0) {
  6701. return;
  6702. }
  6703. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  6704. this.#buffer.resize(newCacheSize, visible.ids);
  6705. this.renderingQueue.renderHighestPriority(visible);
  6706. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  6707. const currentId = this._currentPageNumber;
  6708. let stillFullyVisible = false;
  6709. for (const page of visiblePages) {
  6710. if (page.percent < 100) {
  6711. break;
  6712. }
  6713. if (page.id === currentId && isSimpleLayout) {
  6714. stillFullyVisible = true;
  6715. break;
  6716. }
  6717. }
  6718. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  6719. this._updateLocation(visible.first);
  6720. this.eventBus.dispatch("updateviewarea", {
  6721. source: this,
  6722. location: this._location
  6723. });
  6724. }
  6725. containsElement(element) {
  6726. return this.container.contains(element);
  6727. }
  6728. focus() {
  6729. this.container.focus();
  6730. }
  6731. get _isContainerRtl() {
  6732. return getComputedStyle(this.container).direction === "rtl";
  6733. }
  6734. get isInPresentationMode() {
  6735. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  6736. }
  6737. get isChangingPresentationMode() {
  6738. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  6739. }
  6740. get isHorizontalScrollbarEnabled() {
  6741. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  6742. }
  6743. get isVerticalScrollbarEnabled() {
  6744. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  6745. }
  6746. _getVisiblePages() {
  6747. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  6748. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  6749. rtl = horizontal && this._isContainerRtl;
  6750. return (0, _ui_utils.getVisibleElements)({
  6751. scrollEl: this.container,
  6752. views,
  6753. sortByVisibility: true,
  6754. horizontal,
  6755. rtl
  6756. });
  6757. }
  6758. isPageVisible(pageNumber) {
  6759. if (!this.pdfDocument) {
  6760. return false;
  6761. }
  6762. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  6763. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  6764. return false;
  6765. }
  6766. return this._getVisiblePages().ids.has(pageNumber);
  6767. }
  6768. isPageCached(pageNumber) {
  6769. if (!this.pdfDocument) {
  6770. return false;
  6771. }
  6772. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  6773. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  6774. return false;
  6775. }
  6776. const pageView = this._pages[pageNumber - 1];
  6777. return this.#buffer.has(pageView);
  6778. }
  6779. cleanup() {
  6780. for (const pageView of this._pages) {
  6781. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  6782. pageView.reset();
  6783. }
  6784. }
  6785. }
  6786. _cancelRendering() {
  6787. for (const pageView of this._pages) {
  6788. pageView.cancelRendering();
  6789. }
  6790. }
  6791. async #ensurePdfPageLoaded(pageView) {
  6792. if (pageView.pdfPage) {
  6793. return pageView.pdfPage;
  6794. }
  6795. try {
  6796. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  6797. if (!pageView.pdfPage) {
  6798. pageView.setPdfPage(pdfPage);
  6799. }
  6800. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  6801. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  6802. }
  6803. return pdfPage;
  6804. } catch (reason) {
  6805. console.error("Unable to get page for page view", reason);
  6806. return null;
  6807. }
  6808. }
  6809. #getScrollAhead(visible) {
  6810. if (visible.first?.id === 1) {
  6811. return true;
  6812. } else if (visible.last?.id === this.pagesCount) {
  6813. return false;
  6814. }
  6815. switch (this._scrollMode) {
  6816. case _ui_utils.ScrollMode.PAGE:
  6817. return this.#scrollModePageState.scrollDown;
  6818. case _ui_utils.ScrollMode.HORIZONTAL:
  6819. return this.scroll.right;
  6820. }
  6821. return this.scroll.down;
  6822. }
  6823. forceRendering(currentlyVisiblePages) {
  6824. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  6825. const scrollAhead = this.#getScrollAhead(visiblePages);
  6826. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  6827. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  6828. if (pageView) {
  6829. this.#ensurePdfPageLoaded(pageView).then(() => {
  6830. this.renderingQueue.renderView(pageView);
  6831. });
  6832. return true;
  6833. }
  6834. return false;
  6835. }
  6836. get hasEqualPageSizes() {
  6837. const firstPageView = this._pages[0];
  6838. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  6839. const pageView = this._pages[i];
  6840. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  6841. return false;
  6842. }
  6843. }
  6844. return true;
  6845. }
  6846. getPagesOverview() {
  6847. return this._pages.map(pageView => {
  6848. const viewport = pageView.pdfPage.getViewport({
  6849. scale: 1
  6850. });
  6851. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  6852. return {
  6853. width: viewport.width,
  6854. height: viewport.height,
  6855. rotation: viewport.rotation
  6856. };
  6857. }
  6858. return {
  6859. width: viewport.height,
  6860. height: viewport.width,
  6861. rotation: (viewport.rotation - 90) % 360
  6862. };
  6863. });
  6864. }
  6865. get optionalContentConfigPromise() {
  6866. if (!this.pdfDocument) {
  6867. return Promise.resolve(null);
  6868. }
  6869. if (!this._optionalContentConfigPromise) {
  6870. console.error("optionalContentConfigPromise: Not initialized yet.");
  6871. return this.pdfDocument.getOptionalContentConfig();
  6872. }
  6873. return this._optionalContentConfigPromise;
  6874. }
  6875. set optionalContentConfigPromise(promise) {
  6876. if (!(promise instanceof Promise)) {
  6877. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  6878. }
  6879. if (!this.pdfDocument) {
  6880. return;
  6881. }
  6882. if (!this._optionalContentConfigPromise) {
  6883. return;
  6884. }
  6885. this._optionalContentConfigPromise = promise;
  6886. this.refresh(false, {
  6887. optionalContentConfigPromise: promise
  6888. });
  6889. this.eventBus.dispatch("optionalcontentconfigchanged", {
  6890. source: this,
  6891. promise
  6892. });
  6893. }
  6894. get scrollMode() {
  6895. return this._scrollMode;
  6896. }
  6897. set scrollMode(mode) {
  6898. if (this._scrollMode === mode) {
  6899. return;
  6900. }
  6901. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  6902. throw new Error(`Invalid scroll mode: ${mode}`);
  6903. }
  6904. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  6905. return;
  6906. }
  6907. this._previousScrollMode = this._scrollMode;
  6908. this._scrollMode = mode;
  6909. this.eventBus.dispatch("scrollmodechanged", {
  6910. source: this,
  6911. mode
  6912. });
  6913. this._updateScrollMode(this._currentPageNumber);
  6914. }
  6915. _updateScrollMode(pageNumber = null) {
  6916. const scrollMode = this._scrollMode,
  6917. viewer = this.viewer;
  6918. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  6919. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  6920. if (!this.pdfDocument || !pageNumber) {
  6921. return;
  6922. }
  6923. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  6924. this.#ensurePageViewVisible();
  6925. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  6926. this._updateSpreadMode();
  6927. }
  6928. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  6929. this._setScale(this._currentScaleValue, {
  6930. noScroll: true
  6931. });
  6932. }
  6933. this._setCurrentPageNumber(pageNumber, true);
  6934. this.update();
  6935. }
  6936. get spreadMode() {
  6937. return this._spreadMode;
  6938. }
  6939. set spreadMode(mode) {
  6940. if (this._spreadMode === mode) {
  6941. return;
  6942. }
  6943. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  6944. throw new Error(`Invalid spread mode: ${mode}`);
  6945. }
  6946. this._spreadMode = mode;
  6947. this.eventBus.dispatch("spreadmodechanged", {
  6948. source: this,
  6949. mode
  6950. });
  6951. this._updateSpreadMode(this._currentPageNumber);
  6952. }
  6953. _updateSpreadMode(pageNumber = null) {
  6954. if (!this.pdfDocument) {
  6955. return;
  6956. }
  6957. const viewer = this.viewer,
  6958. pages = this._pages;
  6959. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  6960. this.#ensurePageViewVisible();
  6961. } else {
  6962. viewer.textContent = "";
  6963. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  6964. for (const pageView of this._pages) {
  6965. viewer.append(pageView.div);
  6966. }
  6967. } else {
  6968. const parity = this._spreadMode - 1;
  6969. let spread = null;
  6970. for (let i = 0, ii = pages.length; i < ii; ++i) {
  6971. if (spread === null) {
  6972. spread = document.createElement("div");
  6973. spread.className = "spread";
  6974. viewer.append(spread);
  6975. } else if (i % 2 === parity) {
  6976. spread = spread.cloneNode(false);
  6977. viewer.append(spread);
  6978. }
  6979. spread.append(pages[i].div);
  6980. }
  6981. }
  6982. }
  6983. if (!pageNumber) {
  6984. return;
  6985. }
  6986. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  6987. this._setScale(this._currentScaleValue, {
  6988. noScroll: true
  6989. });
  6990. }
  6991. this._setCurrentPageNumber(pageNumber, true);
  6992. this.update();
  6993. }
  6994. _getPageAdvance(currentPageNumber, previous = false) {
  6995. switch (this._scrollMode) {
  6996. case _ui_utils.ScrollMode.WRAPPED:
  6997. {
  6998. const {
  6999. views
  7000. } = this._getVisiblePages(),
  7001. pageLayout = new Map();
  7002. for (const {
  7003. id,
  7004. y,
  7005. percent,
  7006. widthPercent
  7007. } of views) {
  7008. if (percent === 0 || widthPercent < 100) {
  7009. continue;
  7010. }
  7011. let yArray = pageLayout.get(y);
  7012. if (!yArray) {
  7013. pageLayout.set(y, yArray ||= []);
  7014. }
  7015. yArray.push(id);
  7016. }
  7017. for (const yArray of pageLayout.values()) {
  7018. const currentIndex = yArray.indexOf(currentPageNumber);
  7019. if (currentIndex === -1) {
  7020. continue;
  7021. }
  7022. const numPages = yArray.length;
  7023. if (numPages === 1) {
  7024. break;
  7025. }
  7026. if (previous) {
  7027. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  7028. const currentId = yArray[i],
  7029. expectedId = yArray[i + 1] - 1;
  7030. if (currentId < expectedId) {
  7031. return currentPageNumber - expectedId;
  7032. }
  7033. }
  7034. } else {
  7035. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  7036. const currentId = yArray[i],
  7037. expectedId = yArray[i - 1] + 1;
  7038. if (currentId > expectedId) {
  7039. return expectedId - currentPageNumber;
  7040. }
  7041. }
  7042. }
  7043. if (previous) {
  7044. const firstId = yArray[0];
  7045. if (firstId < currentPageNumber) {
  7046. return currentPageNumber - firstId + 1;
  7047. }
  7048. } else {
  7049. const lastId = yArray[numPages - 1];
  7050. if (lastId > currentPageNumber) {
  7051. return lastId - currentPageNumber + 1;
  7052. }
  7053. }
  7054. break;
  7055. }
  7056. break;
  7057. }
  7058. case _ui_utils.ScrollMode.HORIZONTAL:
  7059. {
  7060. break;
  7061. }
  7062. case _ui_utils.ScrollMode.PAGE:
  7063. case _ui_utils.ScrollMode.VERTICAL:
  7064. {
  7065. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  7066. break;
  7067. }
  7068. const parity = this._spreadMode - 1;
  7069. if (previous && currentPageNumber % 2 !== parity) {
  7070. break;
  7071. } else if (!previous && currentPageNumber % 2 === parity) {
  7072. break;
  7073. }
  7074. const {
  7075. views
  7076. } = this._getVisiblePages(),
  7077. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  7078. for (const {
  7079. id,
  7080. percent,
  7081. widthPercent
  7082. } of views) {
  7083. if (id !== expectedId) {
  7084. continue;
  7085. }
  7086. if (percent > 0 && widthPercent === 100) {
  7087. return 2;
  7088. }
  7089. break;
  7090. }
  7091. break;
  7092. }
  7093. }
  7094. return 1;
  7095. }
  7096. nextPage() {
  7097. const currentPageNumber = this._currentPageNumber,
  7098. pagesCount = this.pagesCount;
  7099. if (currentPageNumber >= pagesCount) {
  7100. return false;
  7101. }
  7102. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  7103. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  7104. return true;
  7105. }
  7106. previousPage() {
  7107. const currentPageNumber = this._currentPageNumber;
  7108. if (currentPageNumber <= 1) {
  7109. return false;
  7110. }
  7111. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  7112. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  7113. return true;
  7114. }
  7115. increaseScale(steps = 1, options = null) {
  7116. let newScale = this._currentScale;
  7117. do {
  7118. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  7119. newScale = Math.ceil(newScale * 10) / 10;
  7120. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  7121. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  7122. options ||= Object.create(null);
  7123. options.noScroll = false;
  7124. this._setScale(newScale, options);
  7125. }
  7126. decreaseScale(steps = 1, options = null) {
  7127. let newScale = this._currentScale;
  7128. do {
  7129. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  7130. newScale = Math.floor(newScale * 10) / 10;
  7131. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  7132. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  7133. options ||= Object.create(null);
  7134. options.noScroll = false;
  7135. this._setScale(newScale, options);
  7136. }
  7137. #updateContainerHeightCss(height = this.container.clientHeight) {
  7138. if (height !== this.#previousContainerHeight) {
  7139. this.#previousContainerHeight = height;
  7140. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  7141. }
  7142. }
  7143. #resizeObserverCallback(entries) {
  7144. for (const entry of entries) {
  7145. if (entry.target === this.container) {
  7146. this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
  7147. this.#containerTopLeft = null;
  7148. break;
  7149. }
  7150. }
  7151. }
  7152. get containerTopLeft() {
  7153. return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
  7154. }
  7155. get annotationEditorMode() {
  7156. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  7157. }
  7158. set annotationEditorMode(mode) {
  7159. if (!this.#annotationEditorUIManager) {
  7160. throw new Error(`The AnnotationEditor is not enabled.`);
  7161. }
  7162. if (this.#annotationEditorMode === mode) {
  7163. return;
  7164. }
  7165. if (!isValidAnnotationEditorMode(mode)) {
  7166. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  7167. }
  7168. if (!this.pdfDocument) {
  7169. return;
  7170. }
  7171. this.#annotationEditorMode = mode;
  7172. this.eventBus.dispatch("annotationeditormodechanged", {
  7173. source: this,
  7174. mode
  7175. });
  7176. this.#annotationEditorUIManager.updateMode(mode);
  7177. }
  7178. set annotationEditorParams({
  7179. type,
  7180. value
  7181. }) {
  7182. if (!this.#annotationEditorUIManager) {
  7183. throw new Error(`The AnnotationEditor is not enabled.`);
  7184. }
  7185. this.#annotationEditorUIManager.updateParams(type, value);
  7186. }
  7187. refresh(noUpdate = false, updateArgs = Object.create(null)) {
  7188. if (!this.pdfDocument) {
  7189. return;
  7190. }
  7191. for (const pageView of this._pages) {
  7192. pageView.update(updateArgs);
  7193. }
  7194. if (this.#scaleTimeoutId !== null) {
  7195. clearTimeout(this.#scaleTimeoutId);
  7196. this.#scaleTimeoutId = null;
  7197. }
  7198. if (!noUpdate) {
  7199. this.update();
  7200. }
  7201. }
  7202. }
  7203. exports.PDFViewer = PDFViewer;
  7204. /***/ }),
  7205. /* 25 */
  7206. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  7207. Object.defineProperty(exports, "__esModule", ({
  7208. value: true
  7209. }));
  7210. exports.PDFRenderingQueue = void 0;
  7211. var _pdfjsLib = __w_pdfjs_require__(4);
  7212. var _ui_utils = __w_pdfjs_require__(2);
  7213. const CLEANUP_TIMEOUT = 30000;
  7214. class PDFRenderingQueue {
  7215. constructor() {
  7216. this.pdfViewer = null;
  7217. this.pdfThumbnailViewer = null;
  7218. this.onIdle = null;
  7219. this.highestPriorityPage = null;
  7220. this.idleTimeout = null;
  7221. this.printing = false;
  7222. this.isThumbnailViewEnabled = false;
  7223. }
  7224. setViewer(pdfViewer) {
  7225. this.pdfViewer = pdfViewer;
  7226. }
  7227. setThumbnailViewer(pdfThumbnailViewer) {
  7228. this.pdfThumbnailViewer = pdfThumbnailViewer;
  7229. }
  7230. isHighestPriority(view) {
  7231. return this.highestPriorityPage === view.renderingId;
  7232. }
  7233. hasViewer() {
  7234. return !!this.pdfViewer;
  7235. }
  7236. renderHighestPriority(currentlyVisiblePages) {
  7237. if (this.idleTimeout) {
  7238. clearTimeout(this.idleTimeout);
  7239. this.idleTimeout = null;
  7240. }
  7241. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  7242. return;
  7243. }
  7244. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  7245. return;
  7246. }
  7247. if (this.printing) {
  7248. return;
  7249. }
  7250. if (this.onIdle) {
  7251. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  7252. }
  7253. }
  7254. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  7255. const visibleViews = visible.views,
  7256. numVisible = visibleViews.length;
  7257. if (numVisible === 0) {
  7258. return null;
  7259. }
  7260. for (let i = 0; i < numVisible; i++) {
  7261. const view = visibleViews[i].view;
  7262. if (!this.isViewFinished(view)) {
  7263. return view;
  7264. }
  7265. }
  7266. const firstId = visible.first.id,
  7267. lastId = visible.last.id;
  7268. if (lastId - firstId + 1 > numVisible) {
  7269. const visibleIds = visible.ids;
  7270. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  7271. const holeId = scrolledDown ? firstId + i : lastId - i;
  7272. if (visibleIds.has(holeId)) {
  7273. continue;
  7274. }
  7275. const holeView = views[holeId - 1];
  7276. if (!this.isViewFinished(holeView)) {
  7277. return holeView;
  7278. }
  7279. }
  7280. }
  7281. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  7282. let preRenderView = views[preRenderIndex];
  7283. if (preRenderView && !this.isViewFinished(preRenderView)) {
  7284. return preRenderView;
  7285. }
  7286. if (preRenderExtra) {
  7287. preRenderIndex += scrolledDown ? 1 : -1;
  7288. preRenderView = views[preRenderIndex];
  7289. if (preRenderView && !this.isViewFinished(preRenderView)) {
  7290. return preRenderView;
  7291. }
  7292. }
  7293. return null;
  7294. }
  7295. isViewFinished(view) {
  7296. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  7297. }
  7298. renderView(view) {
  7299. switch (view.renderingState) {
  7300. case _ui_utils.RenderingStates.FINISHED:
  7301. return false;
  7302. case _ui_utils.RenderingStates.PAUSED:
  7303. this.highestPriorityPage = view.renderingId;
  7304. view.resume();
  7305. break;
  7306. case _ui_utils.RenderingStates.RUNNING:
  7307. this.highestPriorityPage = view.renderingId;
  7308. break;
  7309. case _ui_utils.RenderingStates.INITIAL:
  7310. this.highestPriorityPage = view.renderingId;
  7311. view.draw().finally(() => {
  7312. this.renderHighestPriority();
  7313. }).catch(reason => {
  7314. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  7315. return;
  7316. }
  7317. console.error(`renderView: "${reason}"`);
  7318. });
  7319. break;
  7320. }
  7321. return true;
  7322. }
  7323. }
  7324. exports.PDFRenderingQueue = PDFRenderingQueue;
  7325. /***/ })
  7326. /******/ ]);
  7327. /************************************************************************/
  7328. /******/ // The module cache
  7329. /******/ var __webpack_module_cache__ = {};
  7330. /******/
  7331. /******/ // The require function
  7332. /******/ function __w_pdfjs_require__(moduleId) {
  7333. /******/ // Check if module is in cache
  7334. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  7335. /******/ if (cachedModule !== undefined) {
  7336. /******/ return cachedModule.exports;
  7337. /******/ }
  7338. /******/ // Create a new module (and put it into the cache)
  7339. /******/ var module = __webpack_module_cache__[moduleId] = {
  7340. /******/ // no module.id needed
  7341. /******/ // no module.loaded needed
  7342. /******/ exports: {}
  7343. /******/ };
  7344. /******/
  7345. /******/ // Execute the module function
  7346. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  7347. /******/
  7348. /******/ // Return the exports of the module
  7349. /******/ return module.exports;
  7350. /******/ }
  7351. /******/
  7352. /************************************************************************/
  7353. var __webpack_exports__ = {};
  7354. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  7355. (() => {
  7356. var exports = __webpack_exports__;
  7357. Object.defineProperty(exports, "__esModule", ({
  7358. value: true
  7359. }));
  7360. Object.defineProperty(exports, "AnnotationLayerBuilder", ({
  7361. enumerable: true,
  7362. get: function () {
  7363. return _annotation_layer_builder.AnnotationLayerBuilder;
  7364. }
  7365. }));
  7366. exports.DefaultXfaLayerFactory = exports.DefaultTextLayerFactory = exports.DefaultStructTreeLayerFactory = exports.DefaultAnnotationLayerFactory = void 0;
  7367. Object.defineProperty(exports, "DownloadManager", ({
  7368. enumerable: true,
  7369. get: function () {
  7370. return _download_manager.DownloadManager;
  7371. }
  7372. }));
  7373. Object.defineProperty(exports, "EventBus", ({
  7374. enumerable: true,
  7375. get: function () {
  7376. return _event_utils.EventBus;
  7377. }
  7378. }));
  7379. Object.defineProperty(exports, "GenericL10n", ({
  7380. enumerable: true,
  7381. get: function () {
  7382. return _genericl10n.GenericL10n;
  7383. }
  7384. }));
  7385. Object.defineProperty(exports, "LinkTarget", ({
  7386. enumerable: true,
  7387. get: function () {
  7388. return _pdf_link_service.LinkTarget;
  7389. }
  7390. }));
  7391. Object.defineProperty(exports, "NullL10n", ({
  7392. enumerable: true,
  7393. get: function () {
  7394. return _l10n_utils.NullL10n;
  7395. }
  7396. }));
  7397. Object.defineProperty(exports, "PDFFindController", ({
  7398. enumerable: true,
  7399. get: function () {
  7400. return _pdf_find_controller.PDFFindController;
  7401. }
  7402. }));
  7403. Object.defineProperty(exports, "PDFHistory", ({
  7404. enumerable: true,
  7405. get: function () {
  7406. return _pdf_history.PDFHistory;
  7407. }
  7408. }));
  7409. Object.defineProperty(exports, "PDFLinkService", ({
  7410. enumerable: true,
  7411. get: function () {
  7412. return _pdf_link_service.PDFLinkService;
  7413. }
  7414. }));
  7415. Object.defineProperty(exports, "PDFPageView", ({
  7416. enumerable: true,
  7417. get: function () {
  7418. return _pdf_page_view.PDFPageView;
  7419. }
  7420. }));
  7421. Object.defineProperty(exports, "PDFScriptingManager", ({
  7422. enumerable: true,
  7423. get: function () {
  7424. return _pdf_scripting_manager.PDFScriptingManager;
  7425. }
  7426. }));
  7427. Object.defineProperty(exports, "PDFSinglePageViewer", ({
  7428. enumerable: true,
  7429. get: function () {
  7430. return _pdf_single_page_viewer.PDFSinglePageViewer;
  7431. }
  7432. }));
  7433. Object.defineProperty(exports, "PDFViewer", ({
  7434. enumerable: true,
  7435. get: function () {
  7436. return _pdf_viewer.PDFViewer;
  7437. }
  7438. }));
  7439. Object.defineProperty(exports, "ProgressBar", ({
  7440. enumerable: true,
  7441. get: function () {
  7442. return _ui_utils.ProgressBar;
  7443. }
  7444. }));
  7445. Object.defineProperty(exports, "RenderingStates", ({
  7446. enumerable: true,
  7447. get: function () {
  7448. return _ui_utils.RenderingStates;
  7449. }
  7450. }));
  7451. Object.defineProperty(exports, "ScrollMode", ({
  7452. enumerable: true,
  7453. get: function () {
  7454. return _ui_utils.ScrollMode;
  7455. }
  7456. }));
  7457. Object.defineProperty(exports, "SimpleLinkService", ({
  7458. enumerable: true,
  7459. get: function () {
  7460. return _pdf_link_service.SimpleLinkService;
  7461. }
  7462. }));
  7463. Object.defineProperty(exports, "SpreadMode", ({
  7464. enumerable: true,
  7465. get: function () {
  7466. return _ui_utils.SpreadMode;
  7467. }
  7468. }));
  7469. Object.defineProperty(exports, "StructTreeLayerBuilder", ({
  7470. enumerable: true,
  7471. get: function () {
  7472. return _struct_tree_layer_builder.StructTreeLayerBuilder;
  7473. }
  7474. }));
  7475. Object.defineProperty(exports, "TextLayerBuilder", ({
  7476. enumerable: true,
  7477. get: function () {
  7478. return _text_layer_builder.TextLayerBuilder;
  7479. }
  7480. }));
  7481. Object.defineProperty(exports, "XfaLayerBuilder", ({
  7482. enumerable: true,
  7483. get: function () {
  7484. return _xfa_layer_builder.XfaLayerBuilder;
  7485. }
  7486. }));
  7487. Object.defineProperty(exports, "parseQueryString", ({
  7488. enumerable: true,
  7489. get: function () {
  7490. return _ui_utils.parseQueryString;
  7491. }
  7492. }));
  7493. var _pdf_link_service = __w_pdfjs_require__(1);
  7494. var _ui_utils = __w_pdfjs_require__(2);
  7495. var _annotation_layer_builder = __w_pdfjs_require__(3);
  7496. var _download_manager = __w_pdfjs_require__(6);
  7497. var _event_utils = __w_pdfjs_require__(7);
  7498. var _genericl10n = __w_pdfjs_require__(8);
  7499. var _l10n_utils = __w_pdfjs_require__(5);
  7500. var _pdf_find_controller = __w_pdfjs_require__(10);
  7501. var _pdf_history = __w_pdfjs_require__(12);
  7502. var _pdf_page_view = __w_pdfjs_require__(13);
  7503. var _pdf_scripting_manager = __w_pdfjs_require__(21);
  7504. var _pdf_single_page_viewer = __w_pdfjs_require__(23);
  7505. var _pdf_viewer = __w_pdfjs_require__(24);
  7506. var _struct_tree_layer_builder = __w_pdfjs_require__(16);
  7507. var _text_layer_builder = __w_pdfjs_require__(19);
  7508. var _xfa_layer_builder = __w_pdfjs_require__(20);
  7509. const pdfjsVersion = '3.2.146';
  7510. const pdfjsBuild = '3fd2a3548';
  7511. class DefaultAnnotationLayerFactory {
  7512. constructor() {
  7513. throw new Error("The `DefaultAnnotationLayerFactory` has been removed, " + "please use the `annotationMode` option when initializing " + "the `PDFPageView`-instance to control AnnotationLayer rendering.");
  7514. }
  7515. }
  7516. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  7517. class DefaultStructTreeLayerFactory {
  7518. constructor() {
  7519. throw new Error("The `DefaultStructTreeLayerFactory` has been removed, " + "this functionality is automatically enabled when the TextLayer is used.");
  7520. }
  7521. }
  7522. exports.DefaultStructTreeLayerFactory = DefaultStructTreeLayerFactory;
  7523. class DefaultTextLayerFactory {
  7524. constructor() {
  7525. throw new Error("The `DefaultTextLayerFactory` has been removed, " + "please use the `textLayerMode` option when initializing " + "the `PDFPageView`-instance to control TextLayer rendering.");
  7526. }
  7527. }
  7528. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  7529. class DefaultXfaLayerFactory {
  7530. constructor() {
  7531. throw new Error("The `DefaultXfaLayerFactory` has been removed, " + "please use the `enableXfa` option when calling " + "the `getDocument`-function to control XfaLayer rendering.");
  7532. }
  7533. }
  7534. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;
  7535. })();
  7536. /******/ return __webpack_exports__;
  7537. /******/ })()
  7538. ;
  7539. });
  7540. //# sourceMappingURL=pdf_viewer.js.map