viewer.js 421 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2023 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. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. 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;
  32. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  33. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  34. exports.approximateFraction = approximateFraction;
  35. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  36. exports.binarySearchFirstItem = binarySearchFirstItem;
  37. exports.docStyle = void 0;
  38. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  39. exports.getPageSizeInches = getPageSizeInches;
  40. exports.getVisibleElements = getVisibleElements;
  41. exports.isPortraitOrientation = isPortraitOrientation;
  42. exports.isValidRotation = isValidRotation;
  43. exports.isValidScrollMode = isValidScrollMode;
  44. exports.isValidSpreadMode = isValidSpreadMode;
  45. exports.noContextMenuHandler = noContextMenuHandler;
  46. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  47. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  48. exports.parseQueryString = parseQueryString;
  49. exports.removeNullCharacters = removeNullCharacters;
  50. exports.roundToDivide = roundToDivide;
  51. exports.scrollIntoView = scrollIntoView;
  52. exports.watchScroll = watchScroll;
  53. const DEFAULT_SCALE_VALUE = "auto";
  54. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  55. const DEFAULT_SCALE = 1.0;
  56. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  57. const DEFAULT_SCALE_DELTA = 1.1;
  58. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  59. const MIN_SCALE = 0.1;
  60. exports.MIN_SCALE = MIN_SCALE;
  61. const MAX_SCALE = 10.0;
  62. exports.MAX_SCALE = MAX_SCALE;
  63. const UNKNOWN_SCALE = 0;
  64. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  65. const MAX_AUTO_SCALE = 1.25;
  66. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  67. const SCROLLBAR_PADDING = 40;
  68. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  69. const VERTICAL_PADDING = 5;
  70. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  71. const RenderingStates = {
  72. INITIAL: 0,
  73. RUNNING: 1,
  74. PAUSED: 2,
  75. FINISHED: 3
  76. };
  77. exports.RenderingStates = RenderingStates;
  78. const PresentationModeState = {
  79. UNKNOWN: 0,
  80. NORMAL: 1,
  81. CHANGING: 2,
  82. FULLSCREEN: 3
  83. };
  84. exports.PresentationModeState = PresentationModeState;
  85. const SidebarView = {
  86. UNKNOWN: -1,
  87. NONE: 0,
  88. THUMBS: 1,
  89. OUTLINE: 2,
  90. ATTACHMENTS: 3,
  91. LAYERS: 4
  92. };
  93. exports.SidebarView = SidebarView;
  94. const RendererType = {
  95. CANVAS: "canvas",
  96. SVG: "svg"
  97. };
  98. exports.RendererType = RendererType;
  99. const TextLayerMode = {
  100. DISABLE: 0,
  101. ENABLE: 1
  102. };
  103. exports.TextLayerMode = TextLayerMode;
  104. const ScrollMode = {
  105. UNKNOWN: -1,
  106. VERTICAL: 0,
  107. HORIZONTAL: 1,
  108. WRAPPED: 2,
  109. PAGE: 3
  110. };
  111. exports.ScrollMode = ScrollMode;
  112. const SpreadMode = {
  113. UNKNOWN: -1,
  114. NONE: 0,
  115. ODD: 1,
  116. EVEN: 2
  117. };
  118. exports.SpreadMode = SpreadMode;
  119. const AutoPrintRegExp = /\bprint\s*\(/;
  120. exports.AutoPrintRegExp = AutoPrintRegExp;
  121. class OutputScale {
  122. constructor() {
  123. const pixelRatio = window.devicePixelRatio || 1;
  124. this.sx = pixelRatio;
  125. this.sy = pixelRatio;
  126. }
  127. get scaled() {
  128. return this.sx !== 1 || this.sy !== 1;
  129. }
  130. }
  131. exports.OutputScale = OutputScale;
  132. function scrollIntoView(element, spot, scrollMatches = false) {
  133. let parent = element.offsetParent;
  134. if (!parent) {
  135. console.error("offsetParent is not set -- cannot scroll");
  136. return;
  137. }
  138. let offsetY = element.offsetTop + element.clientTop;
  139. let offsetX = element.offsetLeft + element.clientLeft;
  140. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  141. offsetY += parent.offsetTop;
  142. offsetX += parent.offsetLeft;
  143. parent = parent.offsetParent;
  144. if (!parent) {
  145. return;
  146. }
  147. }
  148. if (spot) {
  149. if (spot.top !== undefined) {
  150. offsetY += spot.top;
  151. }
  152. if (spot.left !== undefined) {
  153. offsetX += spot.left;
  154. parent.scrollLeft = offsetX;
  155. }
  156. }
  157. parent.scrollTop = offsetY;
  158. }
  159. function watchScroll(viewAreaElement, callback) {
  160. const debounceScroll = function (evt) {
  161. if (rAF) {
  162. return;
  163. }
  164. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  165. rAF = null;
  166. const currentX = viewAreaElement.scrollLeft;
  167. const lastX = state.lastX;
  168. if (currentX !== lastX) {
  169. state.right = currentX > lastX;
  170. }
  171. state.lastX = currentX;
  172. const currentY = viewAreaElement.scrollTop;
  173. const lastY = state.lastY;
  174. if (currentY !== lastY) {
  175. state.down = currentY > lastY;
  176. }
  177. state.lastY = currentY;
  178. callback(state);
  179. });
  180. };
  181. const state = {
  182. right: true,
  183. down: true,
  184. lastX: viewAreaElement.scrollLeft,
  185. lastY: viewAreaElement.scrollTop,
  186. _eventHandler: debounceScroll
  187. };
  188. let rAF = null;
  189. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  190. return state;
  191. }
  192. function parseQueryString(query) {
  193. const params = new Map();
  194. for (const [key, value] of new URLSearchParams(query)) {
  195. params.set(key.toLowerCase(), value);
  196. }
  197. return params;
  198. }
  199. const NullCharactersRegExp = /\x00/g;
  200. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  201. function removeNullCharacters(str, replaceInvisible = false) {
  202. if (typeof str !== "string") {
  203. console.error(`The argument must be a string.`);
  204. return str;
  205. }
  206. if (replaceInvisible) {
  207. str = str.replace(InvisibleCharactersRegExp, " ");
  208. }
  209. return str.replace(NullCharactersRegExp, "");
  210. }
  211. function binarySearchFirstItem(items, condition, start = 0) {
  212. let minIndex = start;
  213. let maxIndex = items.length - 1;
  214. if (maxIndex < 0 || !condition(items[maxIndex])) {
  215. return items.length;
  216. }
  217. if (condition(items[minIndex])) {
  218. return minIndex;
  219. }
  220. while (minIndex < maxIndex) {
  221. const currentIndex = minIndex + maxIndex >> 1;
  222. const currentItem = items[currentIndex];
  223. if (condition(currentItem)) {
  224. maxIndex = currentIndex;
  225. } else {
  226. minIndex = currentIndex + 1;
  227. }
  228. }
  229. return minIndex;
  230. }
  231. function approximateFraction(x) {
  232. if (Math.floor(x) === x) {
  233. return [x, 1];
  234. }
  235. const xinv = 1 / x;
  236. const limit = 8;
  237. if (xinv > limit) {
  238. return [1, limit];
  239. } else if (Math.floor(xinv) === xinv) {
  240. return [1, xinv];
  241. }
  242. const x_ = x > 1 ? xinv : x;
  243. let a = 0,
  244. b = 1,
  245. c = 1,
  246. d = 1;
  247. while (true) {
  248. const p = a + c,
  249. q = b + d;
  250. if (q > limit) {
  251. break;
  252. }
  253. if (x_ <= p / q) {
  254. c = p;
  255. d = q;
  256. } else {
  257. a = p;
  258. b = q;
  259. }
  260. }
  261. let result;
  262. if (x_ - a / b < c / d - x_) {
  263. result = x_ === x ? [a, b] : [b, a];
  264. } else {
  265. result = x_ === x ? [c, d] : [d, c];
  266. }
  267. return result;
  268. }
  269. function roundToDivide(x, div) {
  270. const r = x % div;
  271. return r === 0 ? x : Math.round(x - r + div);
  272. }
  273. function getPageSizeInches({
  274. view,
  275. userUnit,
  276. rotate
  277. }) {
  278. const [x1, y1, x2, y2] = view;
  279. const changeOrientation = rotate % 180 !== 0;
  280. const width = (x2 - x1) / 72 * userUnit;
  281. const height = (y2 - y1) / 72 * userUnit;
  282. return {
  283. width: changeOrientation ? height : width,
  284. height: changeOrientation ? width : height
  285. };
  286. }
  287. function backtrackBeforeAllVisibleElements(index, views, top) {
  288. if (index < 2) {
  289. return index;
  290. }
  291. let elt = views[index].div;
  292. let pageTop = elt.offsetTop + elt.clientTop;
  293. if (pageTop >= top) {
  294. elt = views[index - 1].div;
  295. pageTop = elt.offsetTop + elt.clientTop;
  296. }
  297. for (let i = index - 2; i >= 0; --i) {
  298. elt = views[i].div;
  299. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  300. break;
  301. }
  302. index = i;
  303. }
  304. return index;
  305. }
  306. function getVisibleElements({
  307. scrollEl,
  308. views,
  309. sortByVisibility = false,
  310. horizontal = false,
  311. rtl = false
  312. }) {
  313. const top = scrollEl.scrollTop,
  314. bottom = top + scrollEl.clientHeight;
  315. const left = scrollEl.scrollLeft,
  316. right = left + scrollEl.clientWidth;
  317. function isElementBottomAfterViewTop(view) {
  318. const element = view.div;
  319. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  320. return elementBottom > top;
  321. }
  322. function isElementNextAfterViewHorizontally(view) {
  323. const element = view.div;
  324. const elementLeft = element.offsetLeft + element.clientLeft;
  325. const elementRight = elementLeft + element.clientWidth;
  326. return rtl ? elementLeft < right : elementRight > left;
  327. }
  328. const visible = [],
  329. ids = new Set(),
  330. numViews = views.length;
  331. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  332. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  333. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  334. }
  335. let lastEdge = horizontal ? right : -1;
  336. for (let i = firstVisibleElementInd; i < numViews; i++) {
  337. const view = views[i],
  338. element = view.div;
  339. const currentWidth = element.offsetLeft + element.clientLeft;
  340. const currentHeight = element.offsetTop + element.clientTop;
  341. const viewWidth = element.clientWidth,
  342. viewHeight = element.clientHeight;
  343. const viewRight = currentWidth + viewWidth;
  344. const viewBottom = currentHeight + viewHeight;
  345. if (lastEdge === -1) {
  346. if (viewBottom >= bottom) {
  347. lastEdge = viewBottom;
  348. }
  349. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  350. break;
  351. }
  352. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  353. continue;
  354. }
  355. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  356. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  357. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  358. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  359. const percent = fractionHeight * fractionWidth * 100 | 0;
  360. visible.push({
  361. id: view.id,
  362. x: currentWidth,
  363. y: currentHeight,
  364. view,
  365. percent,
  366. widthPercent: fractionWidth * 100 | 0
  367. });
  368. ids.add(view.id);
  369. }
  370. const first = visible[0],
  371. last = visible.at(-1);
  372. if (sortByVisibility) {
  373. visible.sort(function (a, b) {
  374. const pc = a.percent - b.percent;
  375. if (Math.abs(pc) > 0.001) {
  376. return -pc;
  377. }
  378. return a.id - b.id;
  379. });
  380. }
  381. return {
  382. first,
  383. last,
  384. views: visible,
  385. ids
  386. };
  387. }
  388. function noContextMenuHandler(evt) {
  389. evt.preventDefault();
  390. }
  391. function normalizeWheelEventDirection(evt) {
  392. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  393. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  394. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  395. delta = -delta;
  396. }
  397. return delta;
  398. }
  399. function normalizeWheelEventDelta(evt) {
  400. const deltaMode = evt.deltaMode;
  401. let delta = normalizeWheelEventDirection(evt);
  402. const MOUSE_PIXELS_PER_LINE = 30;
  403. const MOUSE_LINES_PER_PAGE = 30;
  404. if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
  405. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  406. } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
  407. delta /= MOUSE_LINES_PER_PAGE;
  408. }
  409. return delta;
  410. }
  411. function isValidRotation(angle) {
  412. return Number.isInteger(angle) && angle % 90 === 0;
  413. }
  414. function isValidScrollMode(mode) {
  415. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  416. }
  417. function isValidSpreadMode(mode) {
  418. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  419. }
  420. function isPortraitOrientation(size) {
  421. return size.width <= size.height;
  422. }
  423. const animationStarted = new Promise(function (resolve) {
  424. window.requestAnimationFrame(resolve);
  425. });
  426. exports.animationStarted = animationStarted;
  427. const docStyle = document.documentElement.style;
  428. exports.docStyle = docStyle;
  429. function clamp(v, min, max) {
  430. return Math.min(Math.max(v, min), max);
  431. }
  432. class ProgressBar {
  433. #classList = null;
  434. #disableAutoFetchTimeout = null;
  435. #percent = 0;
  436. #style = null;
  437. #visible = true;
  438. constructor(bar) {
  439. this.#classList = bar.classList;
  440. this.#style = bar.style;
  441. }
  442. get percent() {
  443. return this.#percent;
  444. }
  445. set percent(val) {
  446. this.#percent = clamp(val, 0, 100);
  447. if (isNaN(val)) {
  448. this.#classList.add("indeterminate");
  449. return;
  450. }
  451. this.#classList.remove("indeterminate");
  452. this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
  453. }
  454. setWidth(viewer) {
  455. if (!viewer) {
  456. return;
  457. }
  458. const container = viewer.parentNode;
  459. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  460. if (scrollbarWidth > 0) {
  461. this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  462. }
  463. }
  464. setDisableAutoFetch(delay = 5000) {
  465. if (isNaN(this.#percent)) {
  466. return;
  467. }
  468. if (this.#disableAutoFetchTimeout) {
  469. clearTimeout(this.#disableAutoFetchTimeout);
  470. }
  471. this.show();
  472. this.#disableAutoFetchTimeout = setTimeout(() => {
  473. this.#disableAutoFetchTimeout = null;
  474. this.hide();
  475. }, delay);
  476. }
  477. hide() {
  478. if (!this.#visible) {
  479. return;
  480. }
  481. this.#visible = false;
  482. this.#classList.add("hidden");
  483. }
  484. show() {
  485. if (this.#visible) {
  486. return;
  487. }
  488. this.#visible = true;
  489. this.#classList.remove("hidden");
  490. }
  491. }
  492. exports.ProgressBar = ProgressBar;
  493. function getActiveOrFocusedElement() {
  494. let curRoot = document;
  495. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  496. while (curActiveOrFocused?.shadowRoot) {
  497. curRoot = curActiveOrFocused.shadowRoot;
  498. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  499. }
  500. return curActiveOrFocused;
  501. }
  502. function apiPageLayoutToViewerModes(layout) {
  503. let scrollMode = ScrollMode.VERTICAL,
  504. spreadMode = SpreadMode.NONE;
  505. switch (layout) {
  506. case "SinglePage":
  507. scrollMode = ScrollMode.PAGE;
  508. break;
  509. case "OneColumn":
  510. break;
  511. case "TwoPageLeft":
  512. scrollMode = ScrollMode.PAGE;
  513. case "TwoColumnLeft":
  514. spreadMode = SpreadMode.ODD;
  515. break;
  516. case "TwoPageRight":
  517. scrollMode = ScrollMode.PAGE;
  518. case "TwoColumnRight":
  519. spreadMode = SpreadMode.EVEN;
  520. break;
  521. }
  522. return {
  523. scrollMode,
  524. spreadMode
  525. };
  526. }
  527. function apiPageModeToSidebarView(mode) {
  528. switch (mode) {
  529. case "UseNone":
  530. return SidebarView.NONE;
  531. case "UseThumbs":
  532. return SidebarView.THUMBS;
  533. case "UseOutlines":
  534. return SidebarView.OUTLINE;
  535. case "UseAttachments":
  536. return SidebarView.ATTACHMENTS;
  537. case "UseOC":
  538. return SidebarView.LAYERS;
  539. }
  540. return SidebarView.NONE;
  541. }
  542. /***/ }),
  543. /* 2 */
  544. /***/ ((__unused_webpack_module, exports) => {
  545. Object.defineProperty(exports, "__esModule", ({
  546. value: true
  547. }));
  548. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  549. const compatibilityParams = Object.create(null);
  550. exports.compatibilityParams = compatibilityParams;
  551. {
  552. const userAgent = navigator.userAgent || "";
  553. const platform = navigator.platform || "";
  554. const maxTouchPoints = navigator.maxTouchPoints || 1;
  555. const isAndroid = /Android/.test(userAgent);
  556. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  557. (function checkCanvasSizeLimitation() {
  558. if (isIOS || isAndroid) {
  559. compatibilityParams.maxCanvasPixels = 5242880;
  560. }
  561. })();
  562. }
  563. const OptionKind = {
  564. VIEWER: 0x02,
  565. API: 0x04,
  566. WORKER: 0x08,
  567. PREFERENCE: 0x80
  568. };
  569. exports.OptionKind = OptionKind;
  570. const defaultOptions = {
  571. annotationEditorMode: {
  572. value: 0,
  573. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  574. },
  575. annotationMode: {
  576. value: 2,
  577. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  578. },
  579. cursorToolOnLoad: {
  580. value: 0,
  581. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  582. },
  583. defaultZoomDelay: {
  584. value: 400,
  585. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  586. },
  587. defaultZoomValue: {
  588. value: "",
  589. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  590. },
  591. disableHistory: {
  592. value: false,
  593. kind: OptionKind.VIEWER
  594. },
  595. disablePageLabels: {
  596. value: false,
  597. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  598. },
  599. enablePermissions: {
  600. value: false,
  601. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  602. },
  603. enablePrintAutoRotate: {
  604. value: true,
  605. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  606. },
  607. enableScripting: {
  608. value: true,
  609. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  610. },
  611. externalLinkRel: {
  612. value: "noopener noreferrer nofollow",
  613. kind: OptionKind.VIEWER
  614. },
  615. externalLinkTarget: {
  616. value: 0,
  617. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  618. },
  619. historyUpdateUrl: {
  620. value: false,
  621. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  622. },
  623. ignoreDestinationZoom: {
  624. value: false,
  625. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  626. },
  627. imageResourcesPath: {
  628. value: "./images/",
  629. kind: OptionKind.VIEWER
  630. },
  631. maxCanvasPixels: {
  632. value: 16777216,
  633. kind: OptionKind.VIEWER
  634. },
  635. forcePageColors: {
  636. value: false,
  637. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  638. },
  639. pageColorsBackground: {
  640. value: "Canvas",
  641. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  642. },
  643. pageColorsForeground: {
  644. value: "CanvasText",
  645. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  646. },
  647. pdfBugEnabled: {
  648. value: false,
  649. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  650. },
  651. printResolution: {
  652. value: 150,
  653. kind: OptionKind.VIEWER
  654. },
  655. sidebarViewOnLoad: {
  656. value: -1,
  657. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  658. },
  659. scrollModeOnLoad: {
  660. value: -1,
  661. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  662. },
  663. spreadModeOnLoad: {
  664. value: -1,
  665. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  666. },
  667. textLayerMode: {
  668. value: 1,
  669. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  670. },
  671. useOnlyCssZoom: {
  672. value: false,
  673. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  674. },
  675. viewerCssTheme: {
  676. value: 0,
  677. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  678. },
  679. viewOnLoad: {
  680. value: 0,
  681. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  682. },
  683. cMapPacked: {
  684. value: true,
  685. kind: OptionKind.API
  686. },
  687. cMapUrl: {
  688. value: "../web/cmaps/",
  689. kind: OptionKind.API
  690. },
  691. disableAutoFetch: {
  692. value: false,
  693. kind: OptionKind.API + OptionKind.PREFERENCE
  694. },
  695. disableFontFace: {
  696. value: false,
  697. kind: OptionKind.API + OptionKind.PREFERENCE
  698. },
  699. disableRange: {
  700. value: false,
  701. kind: OptionKind.API + OptionKind.PREFERENCE
  702. },
  703. disableStream: {
  704. value: false,
  705. kind: OptionKind.API + OptionKind.PREFERENCE
  706. },
  707. docBaseUrl: {
  708. value: "",
  709. kind: OptionKind.API
  710. },
  711. enableXfa: {
  712. value: true,
  713. kind: OptionKind.API + OptionKind.PREFERENCE
  714. },
  715. fontExtraProperties: {
  716. value: false,
  717. kind: OptionKind.API
  718. },
  719. isEvalSupported: {
  720. value: true,
  721. kind: OptionKind.API
  722. },
  723. isOffscreenCanvasSupported: {
  724. value: true,
  725. kind: OptionKind.API
  726. },
  727. maxImageSize: {
  728. value: -1,
  729. kind: OptionKind.API
  730. },
  731. pdfBug: {
  732. value: false,
  733. kind: OptionKind.API
  734. },
  735. standardFontDataUrl: {
  736. value: "../web/standard_fonts/",
  737. kind: OptionKind.API
  738. },
  739. verbosity: {
  740. value: 1,
  741. kind: OptionKind.API
  742. },
  743. workerPort: {
  744. value: null,
  745. kind: OptionKind.WORKER
  746. },
  747. workerSrc: {
  748. value: "../build/pdf.worker.js",
  749. kind: OptionKind.WORKER
  750. }
  751. };
  752. {
  753. defaultOptions.defaultUrl = {
  754. value: "compressed.tracemonkey-pldi-09.pdf",
  755. kind: OptionKind.VIEWER
  756. };
  757. defaultOptions.disablePreferences = {
  758. value: false,
  759. kind: OptionKind.VIEWER
  760. };
  761. defaultOptions.locale = {
  762. value: navigator.language || "en-US",
  763. kind: OptionKind.VIEWER
  764. };
  765. defaultOptions.renderer = {
  766. value: "canvas",
  767. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  768. };
  769. defaultOptions.sandboxBundleSrc = {
  770. value: "../build/pdf.sandbox.js",
  771. kind: OptionKind.VIEWER
  772. };
  773. }
  774. const userOptions = Object.create(null);
  775. class AppOptions {
  776. constructor() {
  777. throw new Error("Cannot initialize AppOptions.");
  778. }
  779. static get(name) {
  780. const userOption = userOptions[name];
  781. if (userOption !== undefined) {
  782. return userOption;
  783. }
  784. const defaultOption = defaultOptions[name];
  785. if (defaultOption !== undefined) {
  786. return compatibilityParams[name] ?? defaultOption.value;
  787. }
  788. return undefined;
  789. }
  790. static getAll(kind = null) {
  791. const options = Object.create(null);
  792. for (const name in defaultOptions) {
  793. const defaultOption = defaultOptions[name];
  794. if (kind) {
  795. if ((kind & defaultOption.kind) === 0) {
  796. continue;
  797. }
  798. if (kind === OptionKind.PREFERENCE) {
  799. const value = defaultOption.value,
  800. valueType = typeof value;
  801. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  802. options[name] = value;
  803. continue;
  804. }
  805. throw new Error(`Invalid type for preference: ${name}`);
  806. }
  807. }
  808. const userOption = userOptions[name];
  809. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  810. }
  811. return options;
  812. }
  813. static set(name, value) {
  814. userOptions[name] = value;
  815. }
  816. static setAll(options) {
  817. for (const name in options) {
  818. userOptions[name] = options[name];
  819. }
  820. }
  821. static remove(name) {
  822. delete userOptions[name];
  823. }
  824. static _hasUserOptions() {
  825. return Object.keys(userOptions).length > 0;
  826. }
  827. }
  828. exports.AppOptions = AppOptions;
  829. /***/ }),
  830. /* 3 */
  831. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  832. Object.defineProperty(exports, "__esModule", ({
  833. value: true
  834. }));
  835. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  836. var _ui_utils = __webpack_require__(1);
  837. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  838. const LinkTarget = {
  839. NONE: 0,
  840. SELF: 1,
  841. BLANK: 2,
  842. PARENT: 3,
  843. TOP: 4
  844. };
  845. exports.LinkTarget = LinkTarget;
  846. function addLinkAttributes(link, {
  847. url,
  848. target,
  849. rel,
  850. enabled = true
  851. } = {}) {
  852. if (!url || typeof url !== "string") {
  853. throw new Error('A valid "url" parameter must provided.');
  854. }
  855. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  856. if (enabled) {
  857. link.href = link.title = urlNullRemoved;
  858. } else {
  859. link.href = "";
  860. link.title = `Disabled: ${urlNullRemoved}`;
  861. link.onclick = () => {
  862. return false;
  863. };
  864. }
  865. let targetStr = "";
  866. switch (target) {
  867. case LinkTarget.NONE:
  868. break;
  869. case LinkTarget.SELF:
  870. targetStr = "_self";
  871. break;
  872. case LinkTarget.BLANK:
  873. targetStr = "_blank";
  874. break;
  875. case LinkTarget.PARENT:
  876. targetStr = "_parent";
  877. break;
  878. case LinkTarget.TOP:
  879. targetStr = "_top";
  880. break;
  881. }
  882. link.target = targetStr;
  883. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  884. }
  885. class PDFLinkService {
  886. #pagesRefCache = new Map();
  887. constructor({
  888. eventBus,
  889. externalLinkTarget = null,
  890. externalLinkRel = null,
  891. ignoreDestinationZoom = false
  892. } = {}) {
  893. this.eventBus = eventBus;
  894. this.externalLinkTarget = externalLinkTarget;
  895. this.externalLinkRel = externalLinkRel;
  896. this.externalLinkEnabled = true;
  897. this._ignoreDestinationZoom = ignoreDestinationZoom;
  898. this.baseUrl = null;
  899. this.pdfDocument = null;
  900. this.pdfViewer = null;
  901. this.pdfHistory = null;
  902. }
  903. setDocument(pdfDocument, baseUrl = null) {
  904. this.baseUrl = baseUrl;
  905. this.pdfDocument = pdfDocument;
  906. this.#pagesRefCache.clear();
  907. }
  908. setViewer(pdfViewer) {
  909. this.pdfViewer = pdfViewer;
  910. }
  911. setHistory(pdfHistory) {
  912. this.pdfHistory = pdfHistory;
  913. }
  914. get pagesCount() {
  915. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  916. }
  917. get page() {
  918. return this.pdfViewer.currentPageNumber;
  919. }
  920. set page(value) {
  921. this.pdfViewer.currentPageNumber = value;
  922. }
  923. get rotation() {
  924. return this.pdfViewer.pagesRotation;
  925. }
  926. set rotation(value) {
  927. this.pdfViewer.pagesRotation = value;
  928. }
  929. get isInPresentationMode() {
  930. return this.pdfViewer.isInPresentationMode;
  931. }
  932. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  933. const destRef = explicitDest[0];
  934. let pageNumber;
  935. if (typeof destRef === "object" && destRef !== null) {
  936. pageNumber = this._cachedPageNumber(destRef);
  937. if (!pageNumber) {
  938. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  939. this.cachePageRef(pageIndex + 1, destRef);
  940. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  941. }).catch(() => {
  942. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  943. });
  944. return;
  945. }
  946. } else if (Number.isInteger(destRef)) {
  947. pageNumber = destRef + 1;
  948. } else {
  949. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  950. return;
  951. }
  952. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  953. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  954. return;
  955. }
  956. if (this.pdfHistory) {
  957. this.pdfHistory.pushCurrentPosition();
  958. this.pdfHistory.push({
  959. namedDest,
  960. explicitDest,
  961. pageNumber
  962. });
  963. }
  964. this.pdfViewer.scrollPageIntoView({
  965. pageNumber,
  966. destArray: explicitDest,
  967. ignoreDestinationZoom: this._ignoreDestinationZoom
  968. });
  969. }
  970. async goToDestination(dest) {
  971. if (!this.pdfDocument) {
  972. return;
  973. }
  974. let namedDest, explicitDest;
  975. if (typeof dest === "string") {
  976. namedDest = dest;
  977. explicitDest = await this.pdfDocument.getDestination(dest);
  978. } else {
  979. namedDest = null;
  980. explicitDest = await dest;
  981. }
  982. if (!Array.isArray(explicitDest)) {
  983. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  984. return;
  985. }
  986. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  987. }
  988. goToPage(val) {
  989. if (!this.pdfDocument) {
  990. return;
  991. }
  992. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  993. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  994. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  995. return;
  996. }
  997. if (this.pdfHistory) {
  998. this.pdfHistory.pushCurrentPosition();
  999. this.pdfHistory.pushPage(pageNumber);
  1000. }
  1001. this.pdfViewer.scrollPageIntoView({
  1002. pageNumber
  1003. });
  1004. }
  1005. addLinkAttributes(link, url, newWindow = false) {
  1006. addLinkAttributes(link, {
  1007. url,
  1008. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  1009. rel: this.externalLinkRel,
  1010. enabled: this.externalLinkEnabled
  1011. });
  1012. }
  1013. getDestinationHash(dest) {
  1014. if (typeof dest === "string") {
  1015. if (dest.length > 0) {
  1016. return this.getAnchorUrl("#" + escape(dest));
  1017. }
  1018. } else if (Array.isArray(dest)) {
  1019. const str = JSON.stringify(dest);
  1020. if (str.length > 0) {
  1021. return this.getAnchorUrl("#" + escape(str));
  1022. }
  1023. }
  1024. return this.getAnchorUrl("");
  1025. }
  1026. getAnchorUrl(anchor) {
  1027. return (this.baseUrl || "") + anchor;
  1028. }
  1029. setHash(hash) {
  1030. if (!this.pdfDocument) {
  1031. return;
  1032. }
  1033. let pageNumber, dest;
  1034. if (hash.includes("=")) {
  1035. const params = (0, _ui_utils.parseQueryString)(hash);
  1036. if (params.has("search")) {
  1037. this.eventBus.dispatch("findfromurlhash", {
  1038. source: this,
  1039. query: params.get("search").replace(/"/g, ""),
  1040. phraseSearch: params.get("phrase") === "true"
  1041. });
  1042. }
  1043. if (params.has("page")) {
  1044. pageNumber = params.get("page") | 0 || 1;
  1045. }
  1046. if (params.has("zoom")) {
  1047. const zoomArgs = params.get("zoom").split(",");
  1048. const zoomArg = zoomArgs[0];
  1049. const zoomArgNumber = parseFloat(zoomArg);
  1050. if (!zoomArg.includes("Fit")) {
  1051. dest = [null, {
  1052. name: "XYZ"
  1053. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  1054. } else {
  1055. if (zoomArg === "Fit" || zoomArg === "FitB") {
  1056. dest = [null, {
  1057. name: zoomArg
  1058. }];
  1059. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  1060. dest = [null, {
  1061. name: zoomArg
  1062. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  1063. } else if (zoomArg === "FitR") {
  1064. if (zoomArgs.length !== 5) {
  1065. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  1066. } else {
  1067. dest = [null, {
  1068. name: zoomArg
  1069. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  1070. }
  1071. } else {
  1072. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  1073. }
  1074. }
  1075. }
  1076. if (dest) {
  1077. this.pdfViewer.scrollPageIntoView({
  1078. pageNumber: pageNumber || this.page,
  1079. destArray: dest,
  1080. allowNegativeOffset: true
  1081. });
  1082. } else if (pageNumber) {
  1083. this.page = pageNumber;
  1084. }
  1085. if (params.has("pagemode")) {
  1086. this.eventBus.dispatch("pagemode", {
  1087. source: this,
  1088. mode: params.get("pagemode")
  1089. });
  1090. }
  1091. if (params.has("nameddest")) {
  1092. this.goToDestination(params.get("nameddest"));
  1093. }
  1094. } else {
  1095. dest = unescape(hash);
  1096. try {
  1097. dest = JSON.parse(dest);
  1098. if (!Array.isArray(dest)) {
  1099. dest = dest.toString();
  1100. }
  1101. } catch (ex) {}
  1102. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  1103. this.goToDestination(dest);
  1104. return;
  1105. }
  1106. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  1107. }
  1108. }
  1109. executeNamedAction(action) {
  1110. switch (action) {
  1111. case "GoBack":
  1112. this.pdfHistory?.back();
  1113. break;
  1114. case "GoForward":
  1115. this.pdfHistory?.forward();
  1116. break;
  1117. case "NextPage":
  1118. this.pdfViewer.nextPage();
  1119. break;
  1120. case "PrevPage":
  1121. this.pdfViewer.previousPage();
  1122. break;
  1123. case "LastPage":
  1124. this.page = this.pagesCount;
  1125. break;
  1126. case "FirstPage":
  1127. this.page = 1;
  1128. break;
  1129. default:
  1130. break;
  1131. }
  1132. this.eventBus.dispatch("namedaction", {
  1133. source: this,
  1134. action
  1135. });
  1136. }
  1137. async executeSetOCGState(action) {
  1138. const pdfDocument = this.pdfDocument;
  1139. const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  1140. if (pdfDocument !== this.pdfDocument) {
  1141. return;
  1142. }
  1143. let operator;
  1144. for (const elem of action.state) {
  1145. switch (elem) {
  1146. case "ON":
  1147. case "OFF":
  1148. case "Toggle":
  1149. operator = elem;
  1150. continue;
  1151. }
  1152. switch (operator) {
  1153. case "ON":
  1154. optionalContentConfig.setVisibility(elem, true);
  1155. break;
  1156. case "OFF":
  1157. optionalContentConfig.setVisibility(elem, false);
  1158. break;
  1159. case "Toggle":
  1160. const group = optionalContentConfig.getGroup(elem);
  1161. if (group) {
  1162. optionalContentConfig.setVisibility(elem, !group.visible);
  1163. }
  1164. break;
  1165. }
  1166. }
  1167. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  1168. }
  1169. cachePageRef(pageNum, pageRef) {
  1170. if (!pageRef) {
  1171. return;
  1172. }
  1173. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1174. this.#pagesRefCache.set(refStr, pageNum);
  1175. }
  1176. _cachedPageNumber(pageRef) {
  1177. if (!pageRef) {
  1178. return null;
  1179. }
  1180. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1181. return this.#pagesRefCache.get(refStr) || null;
  1182. }
  1183. isPageVisible(pageNumber) {
  1184. return this.pdfViewer.isPageVisible(pageNumber);
  1185. }
  1186. isPageCached(pageNumber) {
  1187. return this.pdfViewer.isPageCached(pageNumber);
  1188. }
  1189. static #isValidExplicitDestination(dest) {
  1190. if (!Array.isArray(dest)) {
  1191. return false;
  1192. }
  1193. const destLength = dest.length;
  1194. if (destLength < 2) {
  1195. return false;
  1196. }
  1197. const page = dest[0];
  1198. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  1199. return false;
  1200. }
  1201. const zoom = dest[1];
  1202. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  1203. return false;
  1204. }
  1205. let allowNull = true;
  1206. switch (zoom.name) {
  1207. case "XYZ":
  1208. if (destLength !== 5) {
  1209. return false;
  1210. }
  1211. break;
  1212. case "Fit":
  1213. case "FitB":
  1214. return destLength === 2;
  1215. case "FitH":
  1216. case "FitBH":
  1217. case "FitV":
  1218. case "FitBV":
  1219. if (destLength !== 3) {
  1220. return false;
  1221. }
  1222. break;
  1223. case "FitR":
  1224. if (destLength !== 6) {
  1225. return false;
  1226. }
  1227. allowNull = false;
  1228. break;
  1229. default:
  1230. return false;
  1231. }
  1232. for (let i = 2; i < destLength; i++) {
  1233. const param = dest[i];
  1234. if (!(typeof param === "number" || allowNull && param === null)) {
  1235. return false;
  1236. }
  1237. }
  1238. return true;
  1239. }
  1240. }
  1241. exports.PDFLinkService = PDFLinkService;
  1242. class SimpleLinkService {
  1243. constructor() {
  1244. this.externalLinkEnabled = true;
  1245. }
  1246. get pagesCount() {
  1247. return 0;
  1248. }
  1249. get page() {
  1250. return 0;
  1251. }
  1252. set page(value) {}
  1253. get rotation() {
  1254. return 0;
  1255. }
  1256. set rotation(value) {}
  1257. get isInPresentationMode() {
  1258. return false;
  1259. }
  1260. async goToDestination(dest) {}
  1261. goToPage(val) {}
  1262. addLinkAttributes(link, url, newWindow = false) {
  1263. addLinkAttributes(link, {
  1264. url,
  1265. enabled: this.externalLinkEnabled
  1266. });
  1267. }
  1268. getDestinationHash(dest) {
  1269. return "#";
  1270. }
  1271. getAnchorUrl(hash) {
  1272. return "#";
  1273. }
  1274. setHash(hash) {}
  1275. executeNamedAction(action) {}
  1276. executeSetOCGState(action) {}
  1277. cachePageRef(pageNum, pageRef) {}
  1278. isPageVisible(pageNumber) {
  1279. return true;
  1280. }
  1281. isPageCached(pageNumber) {
  1282. return true;
  1283. }
  1284. }
  1285. exports.SimpleLinkService = SimpleLinkService;
  1286. /***/ }),
  1287. /* 4 */
  1288. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1289. Object.defineProperty(exports, "__esModule", ({
  1290. value: true
  1291. }));
  1292. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  1293. var _ui_utils = __webpack_require__(1);
  1294. var _pdfjsLib = __webpack_require__(5);
  1295. var _app_options = __webpack_require__(2);
  1296. var _event_utils = __webpack_require__(6);
  1297. var _pdf_cursor_tools = __webpack_require__(7);
  1298. var _pdf_link_service = __webpack_require__(3);
  1299. var _annotation_editor_params = __webpack_require__(9);
  1300. var _overlay_manager = __webpack_require__(10);
  1301. var _password_prompt = __webpack_require__(11);
  1302. var _pdf_attachment_viewer = __webpack_require__(12);
  1303. var _pdf_document_properties = __webpack_require__(14);
  1304. var _pdf_find_bar = __webpack_require__(15);
  1305. var _pdf_find_controller = __webpack_require__(16);
  1306. var _pdf_history = __webpack_require__(18);
  1307. var _pdf_layer_viewer = __webpack_require__(19);
  1308. var _pdf_outline_viewer = __webpack_require__(20);
  1309. var _pdf_presentation_mode = __webpack_require__(21);
  1310. var _pdf_rendering_queue = __webpack_require__(22);
  1311. var _pdf_scripting_manager = __webpack_require__(23);
  1312. var _pdf_sidebar = __webpack_require__(24);
  1313. var _pdf_sidebar_resizer = __webpack_require__(25);
  1314. var _pdf_thumbnail_viewer = __webpack_require__(26);
  1315. var _pdf_viewer = __webpack_require__(28);
  1316. var _secondary_toolbar = __webpack_require__(38);
  1317. var _toolbar = __webpack_require__(39);
  1318. var _view_history = __webpack_require__(40);
  1319. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  1320. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  1321. const ViewOnLoad = {
  1322. UNKNOWN: -1,
  1323. PREVIOUS: 0,
  1324. INITIAL: 1
  1325. };
  1326. const ViewerCssTheme = {
  1327. AUTOMATIC: 0,
  1328. LIGHT: 1,
  1329. DARK: 2
  1330. };
  1331. class DefaultExternalServices {
  1332. constructor() {
  1333. throw new Error("Cannot initialize DefaultExternalServices.");
  1334. }
  1335. static updateFindControlState(data) {}
  1336. static updateFindMatchesCount(data) {}
  1337. static initPassiveLoading(callbacks) {}
  1338. static reportTelemetry(data) {}
  1339. static createDownloadManager() {
  1340. throw new Error("Not implemented: createDownloadManager");
  1341. }
  1342. static createPreferences() {
  1343. throw new Error("Not implemented: createPreferences");
  1344. }
  1345. static createL10n(options) {
  1346. throw new Error("Not implemented: createL10n");
  1347. }
  1348. static createScripting(options) {
  1349. throw new Error("Not implemented: createScripting");
  1350. }
  1351. static get supportsPinchToZoom() {
  1352. return (0, _pdfjsLib.shadow)(this, "supportsPinchToZoom", true);
  1353. }
  1354. static get supportsIntegratedFind() {
  1355. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  1356. }
  1357. static get supportsDocumentFonts() {
  1358. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  1359. }
  1360. static get supportedMouseWheelZoomModifierKeys() {
  1361. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  1362. ctrlKey: true,
  1363. metaKey: true
  1364. });
  1365. }
  1366. static get isInAutomation() {
  1367. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  1368. }
  1369. static updateEditorStates(data) {
  1370. throw new Error("Not implemented: updateEditorStates");
  1371. }
  1372. }
  1373. exports.DefaultExternalServices = DefaultExternalServices;
  1374. const PDFViewerApplication = {
  1375. initialBookmark: document.location.hash.substring(1),
  1376. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  1377. appConfig: null,
  1378. pdfDocument: null,
  1379. pdfLoadingTask: null,
  1380. printService: null,
  1381. pdfViewer: null,
  1382. pdfThumbnailViewer: null,
  1383. pdfRenderingQueue: null,
  1384. pdfPresentationMode: null,
  1385. pdfDocumentProperties: null,
  1386. pdfLinkService: null,
  1387. pdfHistory: null,
  1388. pdfSidebar: null,
  1389. pdfSidebarResizer: null,
  1390. pdfOutlineViewer: null,
  1391. pdfAttachmentViewer: null,
  1392. pdfLayerViewer: null,
  1393. pdfCursorTools: null,
  1394. pdfScriptingManager: null,
  1395. store: null,
  1396. downloadManager: null,
  1397. overlayManager: null,
  1398. preferences: null,
  1399. toolbar: null,
  1400. secondaryToolbar: null,
  1401. eventBus: null,
  1402. l10n: null,
  1403. annotationEditorParams: null,
  1404. isInitialViewSet: false,
  1405. downloadComplete: false,
  1406. isViewerEmbedded: window.parent !== window,
  1407. url: "",
  1408. baseUrl: "",
  1409. _downloadUrl: "",
  1410. externalServices: DefaultExternalServices,
  1411. _boundEvents: Object.create(null),
  1412. documentInfo: null,
  1413. metadata: null,
  1414. _contentDispositionFilename: null,
  1415. _contentLength: null,
  1416. _saveInProgress: false,
  1417. _wheelUnusedTicks: 0,
  1418. _wheelUnusedFactor: 1,
  1419. _touchUnusedTicks: 0,
  1420. _touchUnusedFactor: 1,
  1421. _PDFBug: null,
  1422. _hasAnnotationEditors: false,
  1423. _title: document.title,
  1424. _printAnnotationStoragePromise: null,
  1425. _touchInfo: null,
  1426. _isCtrlKeyDown: false,
  1427. async initialize(appConfig) {
  1428. this.preferences = this.externalServices.createPreferences();
  1429. this.appConfig = appConfig;
  1430. await this._readPreferences();
  1431. await this._parseHashParameters();
  1432. this._forceCssTheme();
  1433. await this._initializeL10n();
  1434. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  1435. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  1436. }
  1437. await this._initializeViewerComponents();
  1438. this.bindEvents();
  1439. this.bindWindowEvents();
  1440. const appContainer = appConfig.appContainer || document.documentElement;
  1441. this.l10n.translate(appContainer).then(() => {
  1442. this.eventBus.dispatch("localized", {
  1443. source: this
  1444. });
  1445. });
  1446. this._initializedCapability.resolve();
  1447. },
  1448. async _readPreferences() {
  1449. if (_app_options.AppOptions.get("disablePreferences")) {
  1450. return;
  1451. }
  1452. if (_app_options.AppOptions._hasUserOptions()) {
  1453. console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  1454. }
  1455. try {
  1456. _app_options.AppOptions.setAll(await this.preferences.getAll());
  1457. } catch (reason) {
  1458. console.error(`_readPreferences: "${reason?.message}".`);
  1459. }
  1460. },
  1461. async _parseHashParameters() {
  1462. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  1463. return;
  1464. }
  1465. const hash = document.location.hash.substring(1);
  1466. if (!hash) {
  1467. return;
  1468. }
  1469. const {
  1470. mainContainer,
  1471. viewerContainer
  1472. } = this.appConfig,
  1473. params = (0, _ui_utils.parseQueryString)(hash);
  1474. if (params.get("disableworker") === "true") {
  1475. try {
  1476. await loadFakeWorker();
  1477. } catch (ex) {
  1478. console.error(`_parseHashParameters: "${ex.message}".`);
  1479. }
  1480. }
  1481. if (params.has("disablerange")) {
  1482. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  1483. }
  1484. if (params.has("disablestream")) {
  1485. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  1486. }
  1487. if (params.has("disableautofetch")) {
  1488. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  1489. }
  1490. if (params.has("disablefontface")) {
  1491. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  1492. }
  1493. if (params.has("disablehistory")) {
  1494. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  1495. }
  1496. if (params.has("verbosity")) {
  1497. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  1498. }
  1499. if (params.has("textlayer")) {
  1500. switch (params.get("textlayer")) {
  1501. case "off":
  1502. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  1503. break;
  1504. case "visible":
  1505. case "shadow":
  1506. case "hover":
  1507. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  1508. try {
  1509. await loadPDFBug(this);
  1510. this._PDFBug.loadCSS();
  1511. } catch (ex) {
  1512. console.error(`_parseHashParameters: "${ex.message}".`);
  1513. }
  1514. break;
  1515. }
  1516. }
  1517. if (params.has("pdfbug")) {
  1518. _app_options.AppOptions.set("pdfBug", true);
  1519. _app_options.AppOptions.set("fontExtraProperties", true);
  1520. const enabled = params.get("pdfbug").split(",");
  1521. try {
  1522. await loadPDFBug(this);
  1523. this._PDFBug.init({
  1524. OPS: _pdfjsLib.OPS
  1525. }, mainContainer, enabled);
  1526. } catch (ex) {
  1527. console.error(`_parseHashParameters: "${ex.message}".`);
  1528. }
  1529. }
  1530. if (params.has("locale")) {
  1531. _app_options.AppOptions.set("locale", params.get("locale"));
  1532. }
  1533. },
  1534. async _initializeL10n() {
  1535. this.l10n = this.externalServices.createL10n({
  1536. locale: _app_options.AppOptions.get("locale")
  1537. });
  1538. const dir = await this.l10n.getDirection();
  1539. document.getElementsByTagName("html")[0].dir = dir;
  1540. },
  1541. _forceCssTheme() {
  1542. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  1543. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  1544. return;
  1545. }
  1546. try {
  1547. const styleSheet = document.styleSheets[0];
  1548. const cssRules = styleSheet?.cssRules || [];
  1549. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  1550. const rule = cssRules[i];
  1551. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  1552. if (cssTheme === ViewerCssTheme.LIGHT) {
  1553. styleSheet.deleteRule(i);
  1554. return;
  1555. }
  1556. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  1557. if (darkRules?.[1]) {
  1558. styleSheet.deleteRule(i);
  1559. styleSheet.insertRule(darkRules[1], i);
  1560. }
  1561. return;
  1562. }
  1563. }
  1564. } catch (reason) {
  1565. console.error(`_forceCssTheme: "${reason?.message}".`);
  1566. }
  1567. },
  1568. async _initializeViewerComponents() {
  1569. const {
  1570. appConfig,
  1571. externalServices
  1572. } = this;
  1573. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  1574. this.eventBus = eventBus;
  1575. this.overlayManager = new _overlay_manager.OverlayManager();
  1576. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  1577. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  1578. this.pdfRenderingQueue = pdfRenderingQueue;
  1579. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  1580. eventBus,
  1581. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  1582. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  1583. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  1584. });
  1585. this.pdfLinkService = pdfLinkService;
  1586. const downloadManager = externalServices.createDownloadManager();
  1587. this.downloadManager = downloadManager;
  1588. const findController = new _pdf_find_controller.PDFFindController({
  1589. linkService: pdfLinkService,
  1590. eventBus,
  1591. updateMatchesCountOnProgress: true
  1592. });
  1593. this.findController = findController;
  1594. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  1595. eventBus,
  1596. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  1597. scriptingFactory: externalServices,
  1598. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  1599. });
  1600. this.pdfScriptingManager = pdfScriptingManager;
  1601. const container = appConfig.mainContainer,
  1602. viewer = appConfig.viewerContainer;
  1603. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  1604. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  1605. background: _app_options.AppOptions.get("pageColorsBackground"),
  1606. foreground: _app_options.AppOptions.get("pageColorsForeground")
  1607. } : null;
  1608. this.pdfViewer = new _pdf_viewer.PDFViewer({
  1609. container,
  1610. viewer,
  1611. eventBus,
  1612. renderingQueue: pdfRenderingQueue,
  1613. linkService: pdfLinkService,
  1614. downloadManager,
  1615. findController,
  1616. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  1617. renderer: _app_options.AppOptions.get("renderer"),
  1618. l10n: this.l10n,
  1619. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  1620. annotationMode: _app_options.AppOptions.get("annotationMode"),
  1621. annotationEditorMode,
  1622. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  1623. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  1624. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  1625. isOffscreenCanvasSupported: _app_options.AppOptions.get("isOffscreenCanvasSupported"),
  1626. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  1627. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  1628. pageColors
  1629. });
  1630. pdfRenderingQueue.setViewer(this.pdfViewer);
  1631. pdfLinkService.setViewer(this.pdfViewer);
  1632. pdfScriptingManager.setViewer(this.pdfViewer);
  1633. if (appConfig.sidebar?.thumbnailView) {
  1634. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  1635. container: appConfig.sidebar.thumbnailView,
  1636. eventBus,
  1637. renderingQueue: pdfRenderingQueue,
  1638. linkService: pdfLinkService,
  1639. l10n: this.l10n,
  1640. pageColors
  1641. });
  1642. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  1643. }
  1644. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  1645. this.pdfHistory = new _pdf_history.PDFHistory({
  1646. linkService: pdfLinkService,
  1647. eventBus
  1648. });
  1649. pdfLinkService.setHistory(this.pdfHistory);
  1650. }
  1651. if (!this.supportsIntegratedFind && appConfig.findBar) {
  1652. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  1653. }
  1654. if (appConfig.annotationEditorParams) {
  1655. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  1656. this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  1657. } else {
  1658. for (const id of ["editorModeButtons", "editorModeSeparator"]) {
  1659. document.getElementById(id)?.classList.add("hidden");
  1660. }
  1661. }
  1662. }
  1663. if (appConfig.documentProperties) {
  1664. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
  1665. return this._docFilename;
  1666. });
  1667. }
  1668. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  1669. container,
  1670. eventBus,
  1671. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  1672. });
  1673. if (appConfig.toolbar) {
  1674. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  1675. }
  1676. if (appConfig.secondaryToolbar) {
  1677. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, this.externalServices);
  1678. }
  1679. if (this.supportsFullscreen) {
  1680. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  1681. container,
  1682. pdfViewer: this.pdfViewer,
  1683. eventBus
  1684. });
  1685. }
  1686. if (appConfig.passwordOverlay) {
  1687. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  1688. }
  1689. if (appConfig.sidebar?.outlineView) {
  1690. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  1691. container: appConfig.sidebar.outlineView,
  1692. eventBus,
  1693. linkService: pdfLinkService,
  1694. downloadManager
  1695. });
  1696. }
  1697. if (appConfig.sidebar?.attachmentsView) {
  1698. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  1699. container: appConfig.sidebar.attachmentsView,
  1700. eventBus,
  1701. downloadManager
  1702. });
  1703. }
  1704. if (appConfig.sidebar?.layersView) {
  1705. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  1706. container: appConfig.sidebar.layersView,
  1707. eventBus,
  1708. l10n: this.l10n
  1709. });
  1710. }
  1711. if (appConfig.sidebar) {
  1712. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  1713. elements: appConfig.sidebar,
  1714. pdfViewer: this.pdfViewer,
  1715. pdfThumbnailViewer: this.pdfThumbnailViewer,
  1716. eventBus,
  1717. l10n: this.l10n
  1718. });
  1719. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  1720. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  1721. }
  1722. },
  1723. run(config) {
  1724. this.initialize(config).then(webViewerInitialized);
  1725. },
  1726. get initialized() {
  1727. return this._initializedCapability.settled;
  1728. },
  1729. get initializedPromise() {
  1730. return this._initializedCapability.promise;
  1731. },
  1732. zoomIn(steps, scaleFactor) {
  1733. if (this.pdfViewer.isInPresentationMode) {
  1734. return;
  1735. }
  1736. this.pdfViewer.increaseScale({
  1737. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  1738. steps,
  1739. scaleFactor
  1740. });
  1741. },
  1742. zoomOut(steps, scaleFactor) {
  1743. if (this.pdfViewer.isInPresentationMode) {
  1744. return;
  1745. }
  1746. this.pdfViewer.decreaseScale({
  1747. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  1748. steps,
  1749. scaleFactor
  1750. });
  1751. },
  1752. zoomReset() {
  1753. if (this.pdfViewer.isInPresentationMode) {
  1754. return;
  1755. }
  1756. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1757. },
  1758. get pagesCount() {
  1759. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  1760. },
  1761. get page() {
  1762. return this.pdfViewer.currentPageNumber;
  1763. },
  1764. set page(val) {
  1765. this.pdfViewer.currentPageNumber = val;
  1766. },
  1767. get supportsPrinting() {
  1768. return PDFPrintServiceFactory.instance.supportsPrinting;
  1769. },
  1770. get supportsFullscreen() {
  1771. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  1772. },
  1773. get supportsPinchToZoom() {
  1774. return this.externalServices.supportsPinchToZoom;
  1775. },
  1776. get supportsIntegratedFind() {
  1777. return this.externalServices.supportsIntegratedFind;
  1778. },
  1779. get supportsDocumentFonts() {
  1780. return this.externalServices.supportsDocumentFonts;
  1781. },
  1782. get loadingBar() {
  1783. const barElement = document.getElementById("loadingBar");
  1784. const bar = barElement ? new _ui_utils.ProgressBar(barElement) : null;
  1785. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  1786. },
  1787. get supportedMouseWheelZoomModifierKeys() {
  1788. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  1789. },
  1790. initPassiveLoading() {
  1791. throw new Error("Not implemented: initPassiveLoading");
  1792. },
  1793. setTitleUsingUrl(url = "", downloadUrl = null) {
  1794. this.url = url;
  1795. this.baseUrl = url.split("#")[0];
  1796. if (downloadUrl) {
  1797. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  1798. }
  1799. if ((0, _pdfjsLib.isDataScheme)(url)) {
  1800. this._hideViewBookmark();
  1801. }
  1802. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  1803. if (!title) {
  1804. try {
  1805. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  1806. } catch (ex) {
  1807. title = url;
  1808. }
  1809. }
  1810. this.setTitle(title);
  1811. },
  1812. setTitle(title = this._title) {
  1813. this._title = title;
  1814. if (this.isViewerEmbedded) {
  1815. return;
  1816. }
  1817. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  1818. document.title = `${editorIndicator ? "* " : ""}${title}`;
  1819. },
  1820. get _docFilename() {
  1821. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  1822. },
  1823. _hideViewBookmark() {
  1824. const {
  1825. secondaryToolbar
  1826. } = this.appConfig;
  1827. secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
  1828. if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) {
  1829. document.getElementById("viewBookmarkSeparator")?.classList.add("hidden");
  1830. }
  1831. },
  1832. async close() {
  1833. this._unblockDocumentLoadEvent();
  1834. this._hideViewBookmark();
  1835. if (!this.pdfLoadingTask) {
  1836. return;
  1837. }
  1838. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  1839. try {
  1840. await this.save();
  1841. } catch (reason) {}
  1842. }
  1843. const promises = [];
  1844. promises.push(this.pdfLoadingTask.destroy());
  1845. this.pdfLoadingTask = null;
  1846. if (this.pdfDocument) {
  1847. this.pdfDocument = null;
  1848. this.pdfThumbnailViewer?.setDocument(null);
  1849. this.pdfViewer.setDocument(null);
  1850. this.pdfLinkService.setDocument(null);
  1851. this.pdfDocumentProperties?.setDocument(null);
  1852. }
  1853. this.pdfLinkService.externalLinkEnabled = true;
  1854. this.store = null;
  1855. this.isInitialViewSet = false;
  1856. this.downloadComplete = false;
  1857. this.url = "";
  1858. this.baseUrl = "";
  1859. this._downloadUrl = "";
  1860. this.documentInfo = null;
  1861. this.metadata = null;
  1862. this._contentDispositionFilename = null;
  1863. this._contentLength = null;
  1864. this._saveInProgress = false;
  1865. this._hasAnnotationEditors = false;
  1866. promises.push(this.pdfScriptingManager.destroyPromise);
  1867. this.setTitle();
  1868. this.pdfSidebar?.reset();
  1869. this.pdfOutlineViewer?.reset();
  1870. this.pdfAttachmentViewer?.reset();
  1871. this.pdfLayerViewer?.reset();
  1872. this.pdfHistory?.reset();
  1873. this.findBar?.reset();
  1874. this.toolbar?.reset();
  1875. this.secondaryToolbar?.reset();
  1876. this._PDFBug?.cleanup();
  1877. await Promise.all(promises);
  1878. },
  1879. async open(args) {
  1880. let deprecatedArgs = false;
  1881. if (typeof args === "string") {
  1882. args = {
  1883. url: args
  1884. };
  1885. deprecatedArgs = true;
  1886. } else if (args?.byteLength) {
  1887. args = {
  1888. data: args
  1889. };
  1890. deprecatedArgs = true;
  1891. }
  1892. if (deprecatedArgs) {
  1893. console.error("The `PDFViewerApplication.open` signature was updated, please use an object instead.");
  1894. }
  1895. if (this.pdfLoadingTask) {
  1896. await this.close();
  1897. }
  1898. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  1899. for (const key in workerParameters) {
  1900. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  1901. }
  1902. const parameters = Object.create(null);
  1903. if (args.url) {
  1904. if (args.originalUrl) {
  1905. this.setTitleUsingUrl(args.originalUrl, args.url);
  1906. delete args.originalUrl;
  1907. } else {
  1908. this.setTitleUsingUrl(args.url, args.url);
  1909. }
  1910. }
  1911. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  1912. for (const key in apiParameters) {
  1913. let value = apiParameters[key];
  1914. if (key === "docBaseUrl") {}
  1915. parameters[key] = value;
  1916. }
  1917. for (const key in args) {
  1918. parameters[key] = args[key];
  1919. }
  1920. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  1921. this.pdfLoadingTask = loadingTask;
  1922. loadingTask.onPassword = (updateCallback, reason) => {
  1923. if (this.isViewerEmbedded) {
  1924. this._unblockDocumentLoadEvent();
  1925. }
  1926. this.pdfLinkService.externalLinkEnabled = false;
  1927. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  1928. this.passwordPrompt.open();
  1929. };
  1930. loadingTask.onProgress = ({
  1931. loaded,
  1932. total
  1933. }) => {
  1934. this.progress(loaded / total);
  1935. };
  1936. return loadingTask.promise.then(pdfDocument => {
  1937. this.load(pdfDocument);
  1938. }, reason => {
  1939. if (loadingTask !== this.pdfLoadingTask) {
  1940. return undefined;
  1941. }
  1942. let key = "loading_error";
  1943. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  1944. key = "invalid_file_error";
  1945. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  1946. key = "missing_file_error";
  1947. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  1948. key = "unexpected_response_error";
  1949. }
  1950. return this.l10n.get(key).then(msg => {
  1951. this._documentError(msg, {
  1952. message: reason?.message
  1953. });
  1954. throw reason;
  1955. });
  1956. });
  1957. },
  1958. _ensureDownloadComplete() {
  1959. if (this.pdfDocument && this.downloadComplete) {
  1960. return;
  1961. }
  1962. throw new Error("PDF document not downloaded.");
  1963. },
  1964. async download() {
  1965. const url = this._downloadUrl,
  1966. filename = this._docFilename;
  1967. try {
  1968. this._ensureDownloadComplete();
  1969. const data = await this.pdfDocument.getData();
  1970. const blob = new Blob([data], {
  1971. type: "application/pdf"
  1972. });
  1973. await this.downloadManager.download(blob, url, filename);
  1974. } catch (reason) {
  1975. await this.downloadManager.downloadUrl(url, filename);
  1976. }
  1977. },
  1978. async save() {
  1979. if (this._saveInProgress) {
  1980. return;
  1981. }
  1982. this._saveInProgress = true;
  1983. await this.pdfScriptingManager.dispatchWillSave();
  1984. const url = this._downloadUrl,
  1985. filename = this._docFilename;
  1986. try {
  1987. this._ensureDownloadComplete();
  1988. const data = await this.pdfDocument.saveDocument();
  1989. const blob = new Blob([data], {
  1990. type: "application/pdf"
  1991. });
  1992. await this.downloadManager.download(blob, url, filename);
  1993. } catch (reason) {
  1994. console.error(`Error when saving the document: ${reason.message}`);
  1995. await this.download();
  1996. } finally {
  1997. await this.pdfScriptingManager.dispatchDidSave();
  1998. this._saveInProgress = false;
  1999. }
  2000. if (this._hasAnnotationEditors) {
  2001. this.externalServices.reportTelemetry({
  2002. type: "editing",
  2003. data: {
  2004. type: "save"
  2005. }
  2006. });
  2007. }
  2008. },
  2009. downloadOrSave() {
  2010. if (this.pdfDocument?.annotationStorage.size > 0) {
  2011. this.save();
  2012. } else {
  2013. this.download();
  2014. }
  2015. },
  2016. _documentError(message, moreInfo = null) {
  2017. this._unblockDocumentLoadEvent();
  2018. this._otherError(message, moreInfo);
  2019. this.eventBus.dispatch("documenterror", {
  2020. source: this,
  2021. message,
  2022. reason: moreInfo?.message ?? null
  2023. });
  2024. },
  2025. _otherError(message, moreInfo = null) {
  2026. const moreInfoText = [`PDF.js v${_pdfjsLib.version || "?"} (build: ${_pdfjsLib.build || "?"})`];
  2027. if (moreInfo) {
  2028. moreInfoText.push(`Message: ${moreInfo.message}`);
  2029. if (moreInfo.stack) {
  2030. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  2031. } else {
  2032. if (moreInfo.filename) {
  2033. moreInfoText.push(`File: ${moreInfo.filename}`);
  2034. }
  2035. if (moreInfo.lineNumber) {
  2036. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  2037. }
  2038. }
  2039. }
  2040. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  2041. },
  2042. progress(level) {
  2043. if (!this.loadingBar || this.downloadComplete) {
  2044. return;
  2045. }
  2046. const percent = Math.round(level * 100);
  2047. if (percent <= this.loadingBar.percent) {
  2048. return;
  2049. }
  2050. this.loadingBar.percent = percent;
  2051. if (this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch")) {
  2052. this.loadingBar.setDisableAutoFetch();
  2053. }
  2054. },
  2055. load(pdfDocument) {
  2056. this.pdfDocument = pdfDocument;
  2057. pdfDocument.getDownloadInfo().then(({
  2058. length
  2059. }) => {
  2060. this._contentLength = length;
  2061. this.downloadComplete = true;
  2062. this.loadingBar?.hide();
  2063. firstPagePromise.then(() => {
  2064. this.eventBus.dispatch("documentloaded", {
  2065. source: this
  2066. });
  2067. });
  2068. });
  2069. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  2070. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  2071. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  2072. this.toolbar?.setPagesCount(pdfDocument.numPages, false);
  2073. this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
  2074. let baseDocumentUrl;
  2075. baseDocumentUrl = null;
  2076. if (baseDocumentUrl && (0, _pdfjsLib.isDataScheme)(baseDocumentUrl)) {
  2077. baseDocumentUrl = null;
  2078. }
  2079. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  2080. this.pdfDocumentProperties?.setDocument(pdfDocument);
  2081. const pdfViewer = this.pdfViewer;
  2082. pdfViewer.setDocument(pdfDocument);
  2083. const {
  2084. firstPagePromise,
  2085. onePageRendered,
  2086. pagesPromise
  2087. } = pdfViewer;
  2088. this.pdfThumbnailViewer?.setDocument(pdfDocument);
  2089. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  2090. page: null,
  2091. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  2092. scrollLeft: "0",
  2093. scrollTop: "0",
  2094. rotation: null,
  2095. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  2096. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  2097. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  2098. }).catch(() => {
  2099. return Object.create(null);
  2100. });
  2101. firstPagePromise.then(pdfPage => {
  2102. this.loadingBar?.setWidth(this.appConfig.viewerContainer);
  2103. this._initializeAnnotationStorageCallbacks(pdfDocument);
  2104. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  2105. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  2106. this._initializePdfHistory({
  2107. fingerprint: pdfDocument.fingerprints[0],
  2108. viewOnLoad,
  2109. initialDest: openAction?.dest
  2110. });
  2111. const initialBookmark = this.initialBookmark;
  2112. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  2113. let hash = zoom ? `zoom=${zoom}` : null;
  2114. let rotation = null;
  2115. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  2116. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  2117. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  2118. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  2119. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  2120. rotation = parseInt(stored.rotation, 10);
  2121. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2122. sidebarView = stored.sidebarView | 0;
  2123. }
  2124. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  2125. scrollMode = stored.scrollMode | 0;
  2126. }
  2127. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2128. spreadMode = stored.spreadMode | 0;
  2129. }
  2130. }
  2131. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2132. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  2133. }
  2134. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2135. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  2136. spreadMode = modes.spreadMode;
  2137. }
  2138. this.setInitialView(hash, {
  2139. rotation,
  2140. sidebarView,
  2141. scrollMode,
  2142. spreadMode
  2143. });
  2144. this.eventBus.dispatch("documentinit", {
  2145. source: this
  2146. });
  2147. if (!this.isViewerEmbedded) {
  2148. pdfViewer.focus();
  2149. }
  2150. await Promise.race([pagesPromise, new Promise(resolve => {
  2151. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  2152. })]);
  2153. if (!initialBookmark && !hash) {
  2154. return;
  2155. }
  2156. if (pdfViewer.hasEqualPageSizes) {
  2157. return;
  2158. }
  2159. this.initialBookmark = initialBookmark;
  2160. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  2161. this.setInitialView(hash);
  2162. }).catch(() => {
  2163. this.setInitialView();
  2164. }).then(function () {
  2165. pdfViewer.update();
  2166. });
  2167. });
  2168. pagesPromise.then(() => {
  2169. this._unblockDocumentLoadEvent();
  2170. this._initializeAutoPrint(pdfDocument, openActionPromise);
  2171. }, reason => {
  2172. this.l10n.get("loading_error").then(msg => {
  2173. this._documentError(msg, {
  2174. message: reason?.message
  2175. });
  2176. });
  2177. });
  2178. onePageRendered.then(data => {
  2179. this.externalServices.reportTelemetry({
  2180. type: "pageInfo",
  2181. timestamp: data.timestamp
  2182. });
  2183. pdfDocument.getOutline().then(outline => {
  2184. if (pdfDocument !== this.pdfDocument) {
  2185. return;
  2186. }
  2187. this.pdfOutlineViewer?.render({
  2188. outline,
  2189. pdfDocument
  2190. });
  2191. });
  2192. pdfDocument.getAttachments().then(attachments => {
  2193. if (pdfDocument !== this.pdfDocument) {
  2194. return;
  2195. }
  2196. this.pdfAttachmentViewer?.render({
  2197. attachments
  2198. });
  2199. });
  2200. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  2201. if (pdfDocument !== this.pdfDocument) {
  2202. return;
  2203. }
  2204. this.pdfLayerViewer?.render({
  2205. optionalContentConfig,
  2206. pdfDocument
  2207. });
  2208. });
  2209. });
  2210. this._initializePageLabels(pdfDocument);
  2211. this._initializeMetadata(pdfDocument);
  2212. },
  2213. async _scriptingDocProperties(pdfDocument) {
  2214. if (!this.documentInfo) {
  2215. await new Promise(resolve => {
  2216. this.eventBus._on("metadataloaded", resolve, {
  2217. once: true
  2218. });
  2219. });
  2220. if (pdfDocument !== this.pdfDocument) {
  2221. return null;
  2222. }
  2223. }
  2224. if (!this._contentLength) {
  2225. await new Promise(resolve => {
  2226. this.eventBus._on("documentloaded", resolve, {
  2227. once: true
  2228. });
  2229. });
  2230. if (pdfDocument !== this.pdfDocument) {
  2231. return null;
  2232. }
  2233. }
  2234. return {
  2235. ...this.documentInfo,
  2236. baseURL: this.baseUrl,
  2237. filesize: this._contentLength,
  2238. filename: this._docFilename,
  2239. metadata: this.metadata?.getRaw(),
  2240. authors: this.metadata?.get("dc:creator"),
  2241. numPages: this.pagesCount,
  2242. URL: this.url
  2243. };
  2244. },
  2245. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  2246. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  2247. if (pdfDocument !== this.pdfDocument) {
  2248. return;
  2249. }
  2250. let triggerAutoPrint = false;
  2251. if (openAction?.action === "Print") {
  2252. triggerAutoPrint = true;
  2253. }
  2254. if (javaScript) {
  2255. javaScript.some(js => {
  2256. if (!js) {
  2257. return false;
  2258. }
  2259. console.warn("Warning: JavaScript support is not enabled");
  2260. return true;
  2261. });
  2262. if (!triggerAutoPrint) {
  2263. for (const js of javaScript) {
  2264. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  2265. triggerAutoPrint = true;
  2266. break;
  2267. }
  2268. }
  2269. }
  2270. }
  2271. if (triggerAutoPrint) {
  2272. this.triggerPrinting();
  2273. }
  2274. },
  2275. async _initializeMetadata(pdfDocument) {
  2276. const {
  2277. info,
  2278. metadata,
  2279. contentDispositionFilename,
  2280. contentLength
  2281. } = await pdfDocument.getMetadata();
  2282. if (pdfDocument !== this.pdfDocument) {
  2283. return;
  2284. }
  2285. this.documentInfo = info;
  2286. this.metadata = metadata;
  2287. this._contentDispositionFilename ??= contentDispositionFilename;
  2288. this._contentLength ??= contentLength;
  2289. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`);
  2290. let pdfTitle = info.Title;
  2291. const metadataTitle = metadata?.get("dc:title");
  2292. if (metadataTitle) {
  2293. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  2294. pdfTitle = metadataTitle;
  2295. }
  2296. }
  2297. if (pdfTitle) {
  2298. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  2299. } else if (this._contentDispositionFilename) {
  2300. this.setTitle(this._contentDispositionFilename);
  2301. }
  2302. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  2303. if (pdfDocument.loadingParams.enableXfa) {
  2304. console.warn("Warning: XFA Foreground documents are not supported");
  2305. } else {
  2306. console.warn("Warning: XFA support is not enabled");
  2307. }
  2308. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  2309. console.warn("Warning: Interactive form support is not enabled");
  2310. }
  2311. if (info.IsSignaturesPresent) {
  2312. console.warn("Warning: Digital signatures validation is not supported");
  2313. }
  2314. this.eventBus.dispatch("metadataloaded", {
  2315. source: this
  2316. });
  2317. },
  2318. async _initializePageLabels(pdfDocument) {
  2319. const labels = await pdfDocument.getPageLabels();
  2320. if (pdfDocument !== this.pdfDocument) {
  2321. return;
  2322. }
  2323. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  2324. return;
  2325. }
  2326. const numLabels = labels.length;
  2327. let standardLabels = 0,
  2328. emptyLabels = 0;
  2329. for (let i = 0; i < numLabels; i++) {
  2330. const label = labels[i];
  2331. if (label === (i + 1).toString()) {
  2332. standardLabels++;
  2333. } else if (label === "") {
  2334. emptyLabels++;
  2335. } else {
  2336. break;
  2337. }
  2338. }
  2339. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  2340. return;
  2341. }
  2342. const {
  2343. pdfViewer,
  2344. pdfThumbnailViewer,
  2345. toolbar
  2346. } = this;
  2347. pdfViewer.setPageLabels(labels);
  2348. pdfThumbnailViewer?.setPageLabels(labels);
  2349. toolbar?.setPagesCount(numLabels, true);
  2350. toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2351. },
  2352. _initializePdfHistory({
  2353. fingerprint,
  2354. viewOnLoad,
  2355. initialDest = null
  2356. }) {
  2357. if (!this.pdfHistory) {
  2358. return;
  2359. }
  2360. this.pdfHistory.initialize({
  2361. fingerprint,
  2362. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  2363. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  2364. });
  2365. if (this.pdfHistory.initialBookmark) {
  2366. this.initialBookmark = this.pdfHistory.initialBookmark;
  2367. this.initialRotation = this.pdfHistory.initialRotation;
  2368. }
  2369. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  2370. this.initialBookmark = JSON.stringify(initialDest);
  2371. this.pdfHistory.push({
  2372. explicitDest: initialDest,
  2373. pageNumber: null
  2374. });
  2375. }
  2376. },
  2377. _initializeAnnotationStorageCallbacks(pdfDocument) {
  2378. if (pdfDocument !== this.pdfDocument) {
  2379. return;
  2380. }
  2381. const {
  2382. annotationStorage
  2383. } = pdfDocument;
  2384. annotationStorage.onSetModified = () => {
  2385. window.addEventListener("beforeunload", beforeUnload);
  2386. this._annotationStorageModified = true;
  2387. };
  2388. annotationStorage.onResetModified = () => {
  2389. window.removeEventListener("beforeunload", beforeUnload);
  2390. delete this._annotationStorageModified;
  2391. };
  2392. annotationStorage.onAnnotationEditor = typeStr => {
  2393. this._hasAnnotationEditors = !!typeStr;
  2394. this.setTitle();
  2395. if (typeStr) {
  2396. this.externalServices.reportTelemetry({
  2397. type: "editing",
  2398. data: {
  2399. type: typeStr
  2400. }
  2401. });
  2402. }
  2403. };
  2404. },
  2405. setInitialView(storedHash, {
  2406. rotation,
  2407. sidebarView,
  2408. scrollMode,
  2409. spreadMode
  2410. } = {}) {
  2411. const setRotation = angle => {
  2412. if ((0, _ui_utils.isValidRotation)(angle)) {
  2413. this.pdfViewer.pagesRotation = angle;
  2414. }
  2415. };
  2416. const setViewerModes = (scroll, spread) => {
  2417. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  2418. this.pdfViewer.scrollMode = scroll;
  2419. }
  2420. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  2421. this.pdfViewer.spreadMode = spread;
  2422. }
  2423. };
  2424. this.isInitialViewSet = true;
  2425. this.pdfSidebar?.setInitialView(sidebarView);
  2426. setViewerModes(scrollMode, spreadMode);
  2427. if (this.initialBookmark) {
  2428. setRotation(this.initialRotation);
  2429. delete this.initialRotation;
  2430. this.pdfLinkService.setHash(this.initialBookmark);
  2431. this.initialBookmark = null;
  2432. } else if (storedHash) {
  2433. setRotation(rotation);
  2434. this.pdfLinkService.setHash(storedHash);
  2435. }
  2436. this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  2437. this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
  2438. if (!this.pdfViewer.currentScaleValue) {
  2439. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2440. }
  2441. },
  2442. _cleanup() {
  2443. if (!this.pdfDocument) {
  2444. return;
  2445. }
  2446. this.pdfViewer.cleanup();
  2447. this.pdfThumbnailViewer?.cleanup();
  2448. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  2449. },
  2450. forceRendering() {
  2451. this.pdfRenderingQueue.printing = !!this.printService;
  2452. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS;
  2453. this.pdfRenderingQueue.renderHighestPriority();
  2454. },
  2455. beforePrint() {
  2456. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => {
  2457. return this.pdfDocument?.annotationStorage.print;
  2458. });
  2459. if (this.printService) {
  2460. return;
  2461. }
  2462. if (!this.supportsPrinting) {
  2463. this.l10n.get("printing_not_supported").then(msg => {
  2464. this._otherError(msg);
  2465. });
  2466. return;
  2467. }
  2468. if (!this.pdfViewer.pageViewsReady) {
  2469. this.l10n.get("printing_not_ready").then(msg => {
  2470. window.alert(msg);
  2471. });
  2472. return;
  2473. }
  2474. const pagesOverview = this.pdfViewer.getPagesOverview();
  2475. const printContainer = this.appConfig.printContainer;
  2476. const printResolution = _app_options.AppOptions.get("printResolution");
  2477. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  2478. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  2479. this.printService = printService;
  2480. this.forceRendering();
  2481. this.setTitle();
  2482. printService.layout();
  2483. if (this._hasAnnotationEditors) {
  2484. this.externalServices.reportTelemetry({
  2485. type: "editing",
  2486. data: {
  2487. type: "print"
  2488. }
  2489. });
  2490. }
  2491. },
  2492. afterPrint() {
  2493. if (this._printAnnotationStoragePromise) {
  2494. this._printAnnotationStoragePromise.then(() => {
  2495. this.pdfScriptingManager.dispatchDidPrint();
  2496. });
  2497. this._printAnnotationStoragePromise = null;
  2498. }
  2499. if (this.printService) {
  2500. this.printService.destroy();
  2501. this.printService = null;
  2502. this.pdfDocument?.annotationStorage.resetModified();
  2503. }
  2504. this.forceRendering();
  2505. this.setTitle();
  2506. },
  2507. rotatePages(delta) {
  2508. this.pdfViewer.pagesRotation += delta;
  2509. },
  2510. requestPresentationMode() {
  2511. this.pdfPresentationMode?.request();
  2512. },
  2513. triggerPrinting() {
  2514. if (!this.supportsPrinting) {
  2515. return;
  2516. }
  2517. window.print();
  2518. },
  2519. bindEvents() {
  2520. const {
  2521. eventBus,
  2522. _boundEvents
  2523. } = this;
  2524. _boundEvents.beforePrint = this.beforePrint.bind(this);
  2525. _boundEvents.afterPrint = this.afterPrint.bind(this);
  2526. eventBus._on("resize", webViewerResize);
  2527. eventBus._on("hashchange", webViewerHashchange);
  2528. eventBus._on("beforeprint", _boundEvents.beforePrint);
  2529. eventBus._on("afterprint", _boundEvents.afterPrint);
  2530. eventBus._on("pagerender", webViewerPageRender);
  2531. eventBus._on("pagerendered", webViewerPageRendered);
  2532. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  2533. eventBus._on("pagechanging", webViewerPageChanging);
  2534. eventBus._on("scalechanging", webViewerScaleChanging);
  2535. eventBus._on("rotationchanging", webViewerRotationChanging);
  2536. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  2537. eventBus._on("pagemode", webViewerPageMode);
  2538. eventBus._on("namedaction", webViewerNamedAction);
  2539. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  2540. eventBus._on("presentationmode", webViewerPresentationMode);
  2541. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  2542. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  2543. eventBus._on("print", webViewerPrint);
  2544. eventBus._on("download", webViewerDownload);
  2545. eventBus._on("firstpage", webViewerFirstPage);
  2546. eventBus._on("lastpage", webViewerLastPage);
  2547. eventBus._on("nextpage", webViewerNextPage);
  2548. eventBus._on("previouspage", webViewerPreviousPage);
  2549. eventBus._on("zoomin", webViewerZoomIn);
  2550. eventBus._on("zoomout", webViewerZoomOut);
  2551. eventBus._on("zoomreset", webViewerZoomReset);
  2552. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  2553. eventBus._on("scalechanged", webViewerScaleChanged);
  2554. eventBus._on("rotatecw", webViewerRotateCw);
  2555. eventBus._on("rotateccw", webViewerRotateCcw);
  2556. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  2557. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  2558. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  2559. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  2560. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  2561. eventBus._on("documentproperties", webViewerDocumentProperties);
  2562. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  2563. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2564. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  2565. if (_app_options.AppOptions.get("pdfBug")) {
  2566. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  2567. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2568. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2569. }
  2570. eventBus._on("fileinputchange", webViewerFileInputChange);
  2571. eventBus._on("openfile", webViewerOpenFile);
  2572. },
  2573. bindWindowEvents() {
  2574. const {
  2575. eventBus,
  2576. _boundEvents
  2577. } = this;
  2578. function addWindowResolutionChange(evt = null) {
  2579. if (evt) {
  2580. webViewerResolutionChange(evt);
  2581. }
  2582. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  2583. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  2584. once: true
  2585. });
  2586. _boundEvents.removeWindowResolutionChange ||= function () {
  2587. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  2588. _boundEvents.removeWindowResolutionChange = null;
  2589. };
  2590. }
  2591. addWindowResolutionChange();
  2592. _boundEvents.windowResize = () => {
  2593. eventBus.dispatch("resize", {
  2594. source: window
  2595. });
  2596. };
  2597. _boundEvents.windowHashChange = () => {
  2598. eventBus.dispatch("hashchange", {
  2599. source: window,
  2600. hash: document.location.hash.substring(1)
  2601. });
  2602. };
  2603. _boundEvents.windowBeforePrint = () => {
  2604. eventBus.dispatch("beforeprint", {
  2605. source: window
  2606. });
  2607. };
  2608. _boundEvents.windowAfterPrint = () => {
  2609. eventBus.dispatch("afterprint", {
  2610. source: window
  2611. });
  2612. };
  2613. _boundEvents.windowUpdateFromSandbox = event => {
  2614. eventBus.dispatch("updatefromsandbox", {
  2615. source: window,
  2616. detail: event.detail
  2617. });
  2618. };
  2619. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  2620. window.addEventListener("wheel", webViewerWheel, {
  2621. passive: false
  2622. });
  2623. window.addEventListener("touchstart", webViewerTouchStart, {
  2624. passive: false
  2625. });
  2626. window.addEventListener("touchmove", webViewerTouchMove, {
  2627. passive: false
  2628. });
  2629. window.addEventListener("touchend", webViewerTouchEnd, {
  2630. passive: false
  2631. });
  2632. window.addEventListener("click", webViewerClick);
  2633. window.addEventListener("keydown", webViewerKeyDown);
  2634. window.addEventListener("keyup", webViewerKeyUp);
  2635. window.addEventListener("resize", _boundEvents.windowResize);
  2636. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  2637. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2638. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  2639. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2640. },
  2641. unbindEvents() {
  2642. const {
  2643. eventBus,
  2644. _boundEvents
  2645. } = this;
  2646. eventBus._off("resize", webViewerResize);
  2647. eventBus._off("hashchange", webViewerHashchange);
  2648. eventBus._off("beforeprint", _boundEvents.beforePrint);
  2649. eventBus._off("afterprint", _boundEvents.afterPrint);
  2650. eventBus._off("pagerender", webViewerPageRender);
  2651. eventBus._off("pagerendered", webViewerPageRendered);
  2652. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  2653. eventBus._off("pagechanging", webViewerPageChanging);
  2654. eventBus._off("scalechanging", webViewerScaleChanging);
  2655. eventBus._off("rotationchanging", webViewerRotationChanging);
  2656. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  2657. eventBus._off("pagemode", webViewerPageMode);
  2658. eventBus._off("namedaction", webViewerNamedAction);
  2659. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  2660. eventBus._off("presentationmode", webViewerPresentationMode);
  2661. eventBus._off("print", webViewerPrint);
  2662. eventBus._off("download", webViewerDownload);
  2663. eventBus._off("firstpage", webViewerFirstPage);
  2664. eventBus._off("lastpage", webViewerLastPage);
  2665. eventBus._off("nextpage", webViewerNextPage);
  2666. eventBus._off("previouspage", webViewerPreviousPage);
  2667. eventBus._off("zoomin", webViewerZoomIn);
  2668. eventBus._off("zoomout", webViewerZoomOut);
  2669. eventBus._off("zoomreset", webViewerZoomReset);
  2670. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  2671. eventBus._off("scalechanged", webViewerScaleChanged);
  2672. eventBus._off("rotatecw", webViewerRotateCw);
  2673. eventBus._off("rotateccw", webViewerRotateCcw);
  2674. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  2675. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  2676. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  2677. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  2678. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  2679. eventBus._off("documentproperties", webViewerDocumentProperties);
  2680. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  2681. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2682. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  2683. if (_boundEvents.reportPageStatsPDFBug) {
  2684. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2685. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2686. _boundEvents.reportPageStatsPDFBug = null;
  2687. }
  2688. eventBus._off("fileinputchange", webViewerFileInputChange);
  2689. eventBus._off("openfile", webViewerOpenFile);
  2690. _boundEvents.beforePrint = null;
  2691. _boundEvents.afterPrint = null;
  2692. },
  2693. unbindWindowEvents() {
  2694. const {
  2695. _boundEvents
  2696. } = this;
  2697. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  2698. window.removeEventListener("wheel", webViewerWheel, {
  2699. passive: false
  2700. });
  2701. window.removeEventListener("touchstart", webViewerTouchStart, {
  2702. passive: false
  2703. });
  2704. window.removeEventListener("touchmove", webViewerTouchMove, {
  2705. passive: false
  2706. });
  2707. window.removeEventListener("touchend", webViewerTouchEnd, {
  2708. passive: false
  2709. });
  2710. window.removeEventListener("click", webViewerClick);
  2711. window.removeEventListener("keydown", webViewerKeyDown);
  2712. window.removeEventListener("keyup", webViewerKeyUp);
  2713. window.removeEventListener("resize", _boundEvents.windowResize);
  2714. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  2715. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2716. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  2717. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2718. _boundEvents.removeWindowResolutionChange?.();
  2719. _boundEvents.windowResize = null;
  2720. _boundEvents.windowHashChange = null;
  2721. _boundEvents.windowBeforePrint = null;
  2722. _boundEvents.windowAfterPrint = null;
  2723. _boundEvents.windowUpdateFromSandbox = null;
  2724. },
  2725. _accumulateTicks(ticks, prop) {
  2726. if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) {
  2727. this[prop] = 0;
  2728. }
  2729. this[prop] += ticks;
  2730. const wholeTicks = Math.trunc(this[prop]);
  2731. this[prop] -= wholeTicks;
  2732. return wholeTicks;
  2733. },
  2734. _accumulateFactor(previousScale, factor, prop) {
  2735. if (factor === 1) {
  2736. return 1;
  2737. }
  2738. if (this[prop] > 1 && factor < 1 || this[prop] < 1 && factor > 1) {
  2739. this[prop] = 1;
  2740. }
  2741. const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale);
  2742. this[prop] = factor / newFactor;
  2743. return newFactor;
  2744. },
  2745. _centerAtPos(previousScale, x, y) {
  2746. const {
  2747. pdfViewer
  2748. } = this;
  2749. const scaleDiff = pdfViewer.currentScale / previousScale - 1;
  2750. if (scaleDiff !== 0) {
  2751. const [top, left] = pdfViewer.containerTopLeft;
  2752. pdfViewer.container.scrollLeft += (x - left) * scaleDiff;
  2753. pdfViewer.container.scrollTop += (y - top) * scaleDiff;
  2754. }
  2755. },
  2756. _unblockDocumentLoadEvent() {
  2757. document.blockUnblockOnload?.(false);
  2758. this._unblockDocumentLoadEvent = () => {};
  2759. },
  2760. get scriptingReady() {
  2761. return this.pdfScriptingManager.ready;
  2762. }
  2763. };
  2764. exports.PDFViewerApplication = PDFViewerApplication;
  2765. {
  2766. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  2767. var validateFileURL = function (file) {
  2768. if (!file) {
  2769. return;
  2770. }
  2771. try {
  2772. const viewerOrigin = new URL(window.location.href).origin || "null";
  2773. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  2774. return;
  2775. }
  2776. // const fileOrigin = new URL(file, window.location.href).origin;
  2777. // if (fileOrigin !== viewerOrigin) {
  2778. // throw new Error("file origin does not match viewer's");
  2779. // }
  2780. } catch (ex) {
  2781. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2782. PDFViewerApplication._documentError(msg, {
  2783. message: ex?.message
  2784. });
  2785. });
  2786. throw ex;
  2787. }
  2788. };
  2789. }
  2790. async function loadFakeWorker() {
  2791. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  2792. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  2793. }
  2794. async function loadPDFBug(self) {
  2795. const {
  2796. debuggerScriptPath
  2797. } = self.appConfig;
  2798. const {
  2799. PDFBug
  2800. } = await import(debuggerScriptPath);
  2801. self._PDFBug = PDFBug;
  2802. }
  2803. function reportPageStatsPDFBug({
  2804. pageNumber
  2805. }) {
  2806. if (!globalThis.Stats?.enabled) {
  2807. return;
  2808. }
  2809. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2810. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  2811. }
  2812. function webViewerInitialized() {
  2813. const {
  2814. appConfig,
  2815. eventBus
  2816. } = PDFViewerApplication;
  2817. let file;
  2818. const queryString = document.location.search.substring(1);
  2819. const params = (0, _ui_utils.parseQueryString)(queryString);
  2820. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  2821. validateFileURL(file);
  2822. const fileInput = appConfig.openFileInput;
  2823. fileInput.value = null;
  2824. fileInput.addEventListener("change", function (evt) {
  2825. const {
  2826. files
  2827. } = evt.target;
  2828. if (!files || files.length === 0) {
  2829. return;
  2830. }
  2831. eventBus.dispatch("fileinputchange", {
  2832. source: this,
  2833. fileInput: evt.target
  2834. });
  2835. });
  2836. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  2837. evt.preventDefault();
  2838. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  2839. });
  2840. appConfig.mainContainer.addEventListener("drop", function (evt) {
  2841. evt.preventDefault();
  2842. const {
  2843. files
  2844. } = evt.dataTransfer;
  2845. if (!files || files.length === 0) {
  2846. return;
  2847. }
  2848. eventBus.dispatch("fileinputchange", {
  2849. source: this,
  2850. fileInput: evt.dataTransfer
  2851. });
  2852. });
  2853. if (!PDFViewerApplication.supportsDocumentFonts) {
  2854. _app_options.AppOptions.set("disableFontFace", true);
  2855. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  2856. console.warn(msg);
  2857. });
  2858. }
  2859. if (!PDFViewerApplication.supportsPrinting) {
  2860. appConfig.toolbar?.print.classList.add("hidden");
  2861. appConfig.secondaryToolbar?.printButton.classList.add("hidden");
  2862. }
  2863. if (!PDFViewerApplication.supportsFullscreen) {
  2864. appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
  2865. }
  2866. if (PDFViewerApplication.supportsIntegratedFind) {
  2867. appConfig.toolbar?.viewFind.classList.add("hidden");
  2868. }
  2869. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  2870. if (evt.target === this) {
  2871. eventBus.dispatch("resize", {
  2872. source: this
  2873. });
  2874. }
  2875. }, true);
  2876. try {
  2877. if (file) {
  2878. PDFViewerApplication.open({
  2879. url: file
  2880. });
  2881. } else {
  2882. PDFViewerApplication._hideViewBookmark();
  2883. }
  2884. } catch (reason) {
  2885. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2886. PDFViewerApplication._documentError(msg, reason);
  2887. });
  2888. }
  2889. }
  2890. function webViewerPageRender({
  2891. pageNumber
  2892. }) {
  2893. if (pageNumber === PDFViewerApplication.page) {
  2894. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
  2895. }
  2896. }
  2897. function webViewerPageRendered({
  2898. pageNumber,
  2899. error
  2900. }) {
  2901. if (pageNumber === PDFViewerApplication.page) {
  2902. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
  2903. }
  2904. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  2905. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2906. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
  2907. if (pageView && thumbnailView) {
  2908. thumbnailView.setImage(pageView);
  2909. }
  2910. }
  2911. if (error) {
  2912. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  2913. PDFViewerApplication._otherError(msg, error);
  2914. });
  2915. }
  2916. }
  2917. function webViewerPageMode({
  2918. mode
  2919. }) {
  2920. let view;
  2921. switch (mode) {
  2922. case "thumbs":
  2923. view = _ui_utils.SidebarView.THUMBS;
  2924. break;
  2925. case "bookmarks":
  2926. case "outline":
  2927. view = _ui_utils.SidebarView.OUTLINE;
  2928. break;
  2929. case "attachments":
  2930. view = _ui_utils.SidebarView.ATTACHMENTS;
  2931. break;
  2932. case "layers":
  2933. view = _ui_utils.SidebarView.LAYERS;
  2934. break;
  2935. case "none":
  2936. view = _ui_utils.SidebarView.NONE;
  2937. break;
  2938. default:
  2939. console.error('Invalid "pagemode" hash parameter: ' + mode);
  2940. return;
  2941. }
  2942. PDFViewerApplication.pdfSidebar?.switchView(view, true);
  2943. }
  2944. function webViewerNamedAction(evt) {
  2945. switch (evt.action) {
  2946. case "GoToPage":
  2947. PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
  2948. break;
  2949. case "Find":
  2950. if (!PDFViewerApplication.supportsIntegratedFind) {
  2951. PDFViewerApplication?.findBar.toggle();
  2952. }
  2953. break;
  2954. case "Print":
  2955. PDFViewerApplication.triggerPrinting();
  2956. break;
  2957. case "SaveAs":
  2958. PDFViewerApplication.downloadOrSave();
  2959. break;
  2960. }
  2961. }
  2962. function webViewerPresentationModeChanged(evt) {
  2963. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  2964. }
  2965. function webViewerSidebarViewChanged({
  2966. view
  2967. }) {
  2968. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  2969. if (PDFViewerApplication.isInitialViewSet) {
  2970. PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
  2971. }
  2972. }
  2973. function webViewerUpdateViewarea({
  2974. location
  2975. }) {
  2976. if (PDFViewerApplication.isInitialViewSet) {
  2977. PDFViewerApplication.store?.setMultiple({
  2978. page: location.pageNumber,
  2979. zoom: location.scale,
  2980. scrollLeft: location.left,
  2981. scrollTop: location.top,
  2982. rotation: location.rotation
  2983. }).catch(() => {});
  2984. }
  2985. if (PDFViewerApplication.appConfig.secondaryToolbar) {
  2986. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  2987. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  2988. }
  2989. }
  2990. function webViewerScrollModeChanged(evt) {
  2991. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  2992. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  2993. }
  2994. }
  2995. function webViewerSpreadModeChanged(evt) {
  2996. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  2997. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  2998. }
  2999. }
  3000. function webViewerResize() {
  3001. const {
  3002. pdfDocument,
  3003. pdfViewer,
  3004. pdfRenderingQueue
  3005. } = PDFViewerApplication;
  3006. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  3007. return;
  3008. }
  3009. if (!pdfDocument) {
  3010. return;
  3011. }
  3012. const currentScaleValue = pdfViewer.currentScaleValue;
  3013. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  3014. pdfViewer.currentScaleValue = currentScaleValue;
  3015. }
  3016. pdfViewer.update();
  3017. }
  3018. function webViewerHashchange(evt) {
  3019. const hash = evt.hash;
  3020. if (!hash) {
  3021. return;
  3022. }
  3023. if (!PDFViewerApplication.isInitialViewSet) {
  3024. PDFViewerApplication.initialBookmark = hash;
  3025. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  3026. PDFViewerApplication.pdfLinkService.setHash(hash);
  3027. }
  3028. }
  3029. {
  3030. var webViewerFileInputChange = function (evt) {
  3031. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  3032. return;
  3033. }
  3034. const file = evt.fileInput.files[0];
  3035. PDFViewerApplication.open({
  3036. url: URL.createObjectURL(file),
  3037. originalUrl: file.name
  3038. });
  3039. };
  3040. var webViewerOpenFile = function (evt) {
  3041. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  3042. fileInput.click();
  3043. };
  3044. }
  3045. function webViewerPresentationMode() {
  3046. PDFViewerApplication.requestPresentationMode();
  3047. }
  3048. function webViewerSwitchAnnotationEditorMode(evt) {
  3049. PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
  3050. }
  3051. function webViewerSwitchAnnotationEditorParams(evt) {
  3052. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  3053. }
  3054. function webViewerPrint() {
  3055. PDFViewerApplication.triggerPrinting();
  3056. }
  3057. function webViewerDownload() {
  3058. PDFViewerApplication.downloadOrSave();
  3059. }
  3060. function webViewerFirstPage() {
  3061. if (PDFViewerApplication.pdfDocument) {
  3062. PDFViewerApplication.page = 1;
  3063. }
  3064. }
  3065. function webViewerLastPage() {
  3066. if (PDFViewerApplication.pdfDocument) {
  3067. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3068. }
  3069. }
  3070. function webViewerNextPage() {
  3071. PDFViewerApplication.pdfViewer.nextPage();
  3072. }
  3073. function webViewerPreviousPage() {
  3074. PDFViewerApplication.pdfViewer.previousPage();
  3075. }
  3076. function webViewerZoomIn() {
  3077. PDFViewerApplication.zoomIn();
  3078. }
  3079. function webViewerZoomOut() {
  3080. PDFViewerApplication.zoomOut();
  3081. }
  3082. function webViewerZoomReset() {
  3083. PDFViewerApplication.zoomReset();
  3084. }
  3085. function webViewerPageNumberChanged(evt) {
  3086. const pdfViewer = PDFViewerApplication.pdfViewer;
  3087. if (evt.value !== "") {
  3088. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  3089. }
  3090. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  3091. PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  3092. }
  3093. }
  3094. function webViewerScaleChanged(evt) {
  3095. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  3096. }
  3097. function webViewerRotateCw() {
  3098. PDFViewerApplication.rotatePages(90);
  3099. }
  3100. function webViewerRotateCcw() {
  3101. PDFViewerApplication.rotatePages(-90);
  3102. }
  3103. function webViewerOptionalContentConfig(evt) {
  3104. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  3105. }
  3106. function webViewerSwitchScrollMode(evt) {
  3107. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  3108. }
  3109. function webViewerSwitchSpreadMode(evt) {
  3110. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  3111. }
  3112. function webViewerDocumentProperties() {
  3113. PDFViewerApplication.pdfDocumentProperties?.open();
  3114. }
  3115. function webViewerFindFromUrlHash(evt) {
  3116. PDFViewerApplication.eventBus.dispatch("find", {
  3117. source: evt.source,
  3118. type: "",
  3119. query: evt.query,
  3120. phraseSearch: evt.phraseSearch,
  3121. caseSensitive: false,
  3122. entireWord: false,
  3123. highlightAll: true,
  3124. findPrevious: false,
  3125. matchDiacritics: true
  3126. });
  3127. }
  3128. function webViewerUpdateFindMatchesCount({
  3129. matchesCount
  3130. }) {
  3131. if (PDFViewerApplication.supportsIntegratedFind) {
  3132. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  3133. } else {
  3134. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  3135. }
  3136. }
  3137. function webViewerUpdateFindControlState({
  3138. state,
  3139. previous,
  3140. matchesCount,
  3141. rawQuery
  3142. }) {
  3143. if (PDFViewerApplication.supportsIntegratedFind) {
  3144. PDFViewerApplication.externalServices.updateFindControlState({
  3145. result: state,
  3146. findPrevious: previous,
  3147. matchesCount,
  3148. rawQuery
  3149. });
  3150. } else {
  3151. PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount);
  3152. }
  3153. }
  3154. function webViewerScaleChanging(evt) {
  3155. PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
  3156. PDFViewerApplication.pdfViewer.update();
  3157. }
  3158. function webViewerRotationChanging(evt) {
  3159. if (PDFViewerApplication.pdfThumbnailViewer) {
  3160. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  3161. }
  3162. PDFViewerApplication.forceRendering();
  3163. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  3164. }
  3165. function webViewerPageChanging({
  3166. pageNumber,
  3167. pageLabel
  3168. }) {
  3169. PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
  3170. PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
  3171. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  3172. PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
  3173. }
  3174. const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  3175. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING);
  3176. }
  3177. function webViewerResolutionChange(evt) {
  3178. PDFViewerApplication.pdfViewer.refresh();
  3179. }
  3180. function webViewerVisibilityChange(evt) {
  3181. if (document.visibilityState === "visible") {
  3182. setZoomDisabledTimeout();
  3183. }
  3184. }
  3185. let zoomDisabledTimeout = null;
  3186. function setZoomDisabledTimeout() {
  3187. if (zoomDisabledTimeout) {
  3188. clearTimeout(zoomDisabledTimeout);
  3189. }
  3190. zoomDisabledTimeout = setTimeout(function () {
  3191. zoomDisabledTimeout = null;
  3192. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  3193. }
  3194. function webViewerWheel(evt) {
  3195. const {
  3196. pdfViewer,
  3197. supportedMouseWheelZoomModifierKeys,
  3198. supportsPinchToZoom
  3199. } = PDFViewerApplication;
  3200. if (pdfViewer.isInPresentationMode) {
  3201. return;
  3202. }
  3203. const deltaMode = evt.deltaMode;
  3204. let scaleFactor = Math.exp(-evt.deltaY / 100);
  3205. const isPinchToZoom = evt.ctrlKey && !PDFViewerApplication._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && Math.abs(scaleFactor - 1) < 0.05 && evt.deltaZ === 0;
  3206. if (isPinchToZoom || evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  3207. evt.preventDefault();
  3208. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  3209. return;
  3210. }
  3211. const previousScale = pdfViewer.currentScale;
  3212. if (isPinchToZoom && supportsPinchToZoom) {
  3213. scaleFactor = PDFViewerApplication._accumulateFactor(previousScale, scaleFactor, "_wheelUnusedFactor");
  3214. if (scaleFactor < 1) {
  3215. PDFViewerApplication.zoomOut(null, scaleFactor);
  3216. } else if (scaleFactor > 1) {
  3217. PDFViewerApplication.zoomIn(null, scaleFactor);
  3218. } else {
  3219. return;
  3220. }
  3221. } else {
  3222. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  3223. let ticks = 0;
  3224. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  3225. if (Math.abs(delta) >= 1) {
  3226. ticks = Math.sign(delta);
  3227. } else {
  3228. ticks = PDFViewerApplication._accumulateTicks(delta, "_wheelUnusedTicks");
  3229. }
  3230. } else {
  3231. const PIXELS_PER_LINE_SCALE = 30;
  3232. ticks = PDFViewerApplication._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks");
  3233. }
  3234. if (ticks < 0) {
  3235. PDFViewerApplication.zoomOut(-ticks);
  3236. } else if (ticks > 0) {
  3237. PDFViewerApplication.zoomIn(ticks);
  3238. } else {
  3239. return;
  3240. }
  3241. }
  3242. PDFViewerApplication._centerAtPos(previousScale, evt.clientX, evt.clientY);
  3243. } else {
  3244. setZoomDisabledTimeout();
  3245. }
  3246. }
  3247. function webViewerTouchStart(evt) {
  3248. if (PDFViewerApplication.pdfViewer.isInPresentationMode || evt.touches.length < 2) {
  3249. return;
  3250. }
  3251. evt.preventDefault();
  3252. if (evt.touches.length !== 2) {
  3253. PDFViewerApplication._touchInfo = null;
  3254. return;
  3255. }
  3256. let [touch0, touch1] = evt.touches;
  3257. if (touch0.identifier > touch1.identifier) {
  3258. [touch0, touch1] = [touch1, touch0];
  3259. }
  3260. PDFViewerApplication._touchInfo = {
  3261. touch0X: touch0.pageX,
  3262. touch0Y: touch0.pageY,
  3263. touch1X: touch1.pageX,
  3264. touch1Y: touch1.pageY
  3265. };
  3266. }
  3267. function webViewerTouchMove(evt) {
  3268. if (!PDFViewerApplication._touchInfo || evt.touches.length !== 2) {
  3269. return;
  3270. }
  3271. const {
  3272. pdfViewer,
  3273. _touchInfo,
  3274. supportsPinchToZoom
  3275. } = PDFViewerApplication;
  3276. let [touch0, touch1] = evt.touches;
  3277. if (touch0.identifier > touch1.identifier) {
  3278. [touch0, touch1] = [touch1, touch0];
  3279. }
  3280. const {
  3281. pageX: page0X,
  3282. pageY: page0Y
  3283. } = touch0;
  3284. const {
  3285. pageX: page1X,
  3286. pageY: page1Y
  3287. } = touch1;
  3288. const {
  3289. touch0X: pTouch0X,
  3290. touch0Y: pTouch0Y,
  3291. touch1X: pTouch1X,
  3292. touch1Y: pTouch1Y
  3293. } = _touchInfo;
  3294. if (Math.abs(pTouch0X - page0X) <= 1 && Math.abs(pTouch0Y - page0Y) <= 1 && Math.abs(pTouch1X - page1X) <= 1 && Math.abs(pTouch1Y - page1Y) <= 1) {
  3295. return;
  3296. }
  3297. _touchInfo.touch0X = page0X;
  3298. _touchInfo.touch0Y = page0Y;
  3299. _touchInfo.touch1X = page1X;
  3300. _touchInfo.touch1Y = page1Y;
  3301. if (pTouch0X === page0X && pTouch0Y === page0Y) {
  3302. const v1X = pTouch1X - page0X;
  3303. const v1Y = pTouch1Y - page0Y;
  3304. const v2X = page1X - page0X;
  3305. const v2Y = page1Y - page0Y;
  3306. const det = v1X * v2Y - v1Y * v2X;
  3307. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  3308. return;
  3309. }
  3310. } else if (pTouch1X === page1X && pTouch1Y === page1Y) {
  3311. const v1X = pTouch0X - page1X;
  3312. const v1Y = pTouch0Y - page1Y;
  3313. const v2X = page0X - page1X;
  3314. const v2Y = page0Y - page1Y;
  3315. const det = v1X * v2Y - v1Y * v2X;
  3316. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  3317. return;
  3318. }
  3319. } else {
  3320. const diff0X = page0X - pTouch0X;
  3321. const diff1X = page1X - pTouch1X;
  3322. const diff0Y = page0Y - pTouch0Y;
  3323. const diff1Y = page1Y - pTouch1Y;
  3324. const dotProduct = diff0X * diff1X + diff0Y * diff1Y;
  3325. if (dotProduct >= 0) {
  3326. return;
  3327. }
  3328. }
  3329. evt.preventDefault();
  3330. const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1;
  3331. const pDistance = Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1;
  3332. const previousScale = pdfViewer.currentScale;
  3333. if (supportsPinchToZoom) {
  3334. const newScaleFactor = PDFViewerApplication._accumulateFactor(previousScale, distance / pDistance, "_touchUnusedFactor");
  3335. if (newScaleFactor < 1) {
  3336. PDFViewerApplication.zoomOut(null, newScaleFactor);
  3337. } else if (newScaleFactor > 1) {
  3338. PDFViewerApplication.zoomIn(null, newScaleFactor);
  3339. } else {
  3340. return;
  3341. }
  3342. } else {
  3343. const PIXELS_PER_LINE_SCALE = 30;
  3344. const ticks = PDFViewerApplication._accumulateTicks((distance - pDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks");
  3345. if (ticks < 0) {
  3346. PDFViewerApplication.zoomOut(-ticks);
  3347. } else if (ticks > 0) {
  3348. PDFViewerApplication.zoomIn(ticks);
  3349. } else {
  3350. return;
  3351. }
  3352. }
  3353. PDFViewerApplication._centerAtPos(previousScale, (page0X + page1X) / 2, (page0Y + page1Y) / 2);
  3354. }
  3355. function webViewerTouchEnd(evt) {
  3356. if (!PDFViewerApplication._touchInfo) {
  3357. return;
  3358. }
  3359. evt.preventDefault();
  3360. PDFViewerApplication._touchInfo = null;
  3361. PDFViewerApplication._touchUnusedTicks = 0;
  3362. PDFViewerApplication._touchUnusedFactor = 1;
  3363. }
  3364. function webViewerClick(evt) {
  3365. if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
  3366. return;
  3367. }
  3368. const appConfig = PDFViewerApplication.appConfig;
  3369. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) {
  3370. PDFViewerApplication.secondaryToolbar.close();
  3371. }
  3372. }
  3373. function webViewerKeyUp(evt) {
  3374. if (evt.key === "Control") {
  3375. PDFViewerApplication._isCtrlKeyDown = false;
  3376. }
  3377. }
  3378. function webViewerKeyDown(evt) {
  3379. PDFViewerApplication._isCtrlKeyDown = evt.key === "Control";
  3380. if (PDFViewerApplication.overlayManager.active) {
  3381. return;
  3382. }
  3383. const {
  3384. eventBus,
  3385. pdfViewer
  3386. } = PDFViewerApplication;
  3387. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  3388. let handled = false,
  3389. ensureViewerFocused = false;
  3390. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  3391. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  3392. switch (evt.keyCode) {
  3393. case 70:
  3394. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  3395. PDFViewerApplication.findBar?.open();
  3396. handled = true;
  3397. }
  3398. break;
  3399. case 71:
  3400. if (!PDFViewerApplication.supportsIntegratedFind) {
  3401. const {
  3402. state
  3403. } = PDFViewerApplication.findController;
  3404. if (state) {
  3405. const eventState = Object.assign(Object.create(null), state, {
  3406. source: window,
  3407. type: "again",
  3408. findPrevious: cmd === 5 || cmd === 12
  3409. });
  3410. eventBus.dispatch("find", eventState);
  3411. }
  3412. handled = true;
  3413. }
  3414. break;
  3415. case 61:
  3416. case 107:
  3417. case 187:
  3418. case 171:
  3419. if (!isViewerInPresentationMode) {
  3420. PDFViewerApplication.zoomIn();
  3421. }
  3422. handled = true;
  3423. break;
  3424. case 173:
  3425. case 109:
  3426. case 189:
  3427. if (!isViewerInPresentationMode) {
  3428. PDFViewerApplication.zoomOut();
  3429. }
  3430. handled = true;
  3431. break;
  3432. case 48:
  3433. case 96:
  3434. if (!isViewerInPresentationMode) {
  3435. setTimeout(function () {
  3436. PDFViewerApplication.zoomReset();
  3437. });
  3438. handled = false;
  3439. }
  3440. break;
  3441. case 38:
  3442. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3443. PDFViewerApplication.page = 1;
  3444. handled = true;
  3445. ensureViewerFocused = true;
  3446. }
  3447. break;
  3448. case 40:
  3449. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3450. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3451. handled = true;
  3452. ensureViewerFocused = true;
  3453. }
  3454. break;
  3455. }
  3456. }
  3457. if (cmd === 1 || cmd === 8) {
  3458. switch (evt.keyCode) {
  3459. case 83:
  3460. eventBus.dispatch("download", {
  3461. source: window
  3462. });
  3463. handled = true;
  3464. break;
  3465. case 79:
  3466. {
  3467. eventBus.dispatch("openfile", {
  3468. source: window
  3469. });
  3470. handled = true;
  3471. }
  3472. break;
  3473. }
  3474. }
  3475. if (cmd === 3 || cmd === 10) {
  3476. switch (evt.keyCode) {
  3477. case 80:
  3478. PDFViewerApplication.requestPresentationMode();
  3479. handled = true;
  3480. PDFViewerApplication.externalServices.reportTelemetry({
  3481. type: "buttons",
  3482. data: {
  3483. id: "presentationModeKeyboard"
  3484. }
  3485. });
  3486. break;
  3487. case 71:
  3488. if (PDFViewerApplication.appConfig.toolbar) {
  3489. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  3490. handled = true;
  3491. }
  3492. break;
  3493. }
  3494. }
  3495. if (handled) {
  3496. if (ensureViewerFocused && !isViewerInPresentationMode) {
  3497. pdfViewer.focus();
  3498. }
  3499. evt.preventDefault();
  3500. return;
  3501. }
  3502. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  3503. const curElementTagName = curElement?.tagName.toUpperCase();
  3504. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  3505. if (evt.keyCode !== 27) {
  3506. return;
  3507. }
  3508. }
  3509. if (cmd === 0) {
  3510. let turnPage = 0,
  3511. turnOnlyIfPageFit = false;
  3512. switch (evt.keyCode) {
  3513. case 38:
  3514. case 33:
  3515. if (pdfViewer.isVerticalScrollbarEnabled) {
  3516. turnOnlyIfPageFit = true;
  3517. }
  3518. turnPage = -1;
  3519. break;
  3520. case 8:
  3521. if (!isViewerInPresentationMode) {
  3522. turnOnlyIfPageFit = true;
  3523. }
  3524. turnPage = -1;
  3525. break;
  3526. case 37:
  3527. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3528. turnOnlyIfPageFit = true;
  3529. }
  3530. case 75:
  3531. case 80:
  3532. turnPage = -1;
  3533. break;
  3534. case 27:
  3535. if (PDFViewerApplication.secondaryToolbar?.isOpen) {
  3536. PDFViewerApplication.secondaryToolbar.close();
  3537. handled = true;
  3538. }
  3539. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) {
  3540. PDFViewerApplication.findBar.close();
  3541. handled = true;
  3542. }
  3543. break;
  3544. case 40:
  3545. case 34:
  3546. if (pdfViewer.isVerticalScrollbarEnabled) {
  3547. turnOnlyIfPageFit = true;
  3548. }
  3549. turnPage = 1;
  3550. break;
  3551. case 13:
  3552. case 32:
  3553. if (!isViewerInPresentationMode) {
  3554. turnOnlyIfPageFit = true;
  3555. }
  3556. turnPage = 1;
  3557. break;
  3558. case 39:
  3559. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3560. turnOnlyIfPageFit = true;
  3561. }
  3562. case 74:
  3563. case 78:
  3564. turnPage = 1;
  3565. break;
  3566. case 36:
  3567. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3568. PDFViewerApplication.page = 1;
  3569. handled = true;
  3570. ensureViewerFocused = true;
  3571. }
  3572. break;
  3573. case 35:
  3574. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3575. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3576. handled = true;
  3577. ensureViewerFocused = true;
  3578. }
  3579. break;
  3580. case 83:
  3581. PDFViewerApplication.pdfCursorTools?.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  3582. break;
  3583. case 72:
  3584. PDFViewerApplication.pdfCursorTools?.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  3585. break;
  3586. case 82:
  3587. PDFViewerApplication.rotatePages(90);
  3588. break;
  3589. case 115:
  3590. PDFViewerApplication.pdfSidebar?.toggle();
  3591. break;
  3592. }
  3593. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  3594. if (turnPage > 0) {
  3595. pdfViewer.nextPage();
  3596. } else {
  3597. pdfViewer.previousPage();
  3598. }
  3599. handled = true;
  3600. }
  3601. }
  3602. if (cmd === 4) {
  3603. switch (evt.keyCode) {
  3604. case 13:
  3605. case 32:
  3606. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  3607. break;
  3608. }
  3609. pdfViewer.previousPage();
  3610. handled = true;
  3611. break;
  3612. case 82:
  3613. PDFViewerApplication.rotatePages(-90);
  3614. break;
  3615. }
  3616. }
  3617. if (!handled && !isViewerInPresentationMode) {
  3618. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  3619. ensureViewerFocused = true;
  3620. }
  3621. }
  3622. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  3623. pdfViewer.focus();
  3624. }
  3625. if (handled) {
  3626. evt.preventDefault();
  3627. }
  3628. }
  3629. function beforeUnload(evt) {
  3630. evt.preventDefault();
  3631. evt.returnValue = "";
  3632. return false;
  3633. }
  3634. function webViewerAnnotationEditorStatesChanged(data) {
  3635. PDFViewerApplication.externalServices.updateEditorStates(data);
  3636. }
  3637. const PDFPrintServiceFactory = {
  3638. instance: {
  3639. supportsPrinting: false,
  3640. createPrintService() {
  3641. throw new Error("Not implemented: createPrintService");
  3642. }
  3643. }
  3644. };
  3645. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  3646. /***/ }),
  3647. /* 5 */
  3648. /***/ ((module) => {
  3649. let pdfjsLib;
  3650. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3651. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3652. } else {
  3653. pdfjsLib = require("../build/pdf.js");
  3654. }
  3655. module.exports = pdfjsLib;
  3656. /***/ }),
  3657. /* 6 */
  3658. /***/ ((__unused_webpack_module, exports) => {
  3659. Object.defineProperty(exports, "__esModule", ({
  3660. value: true
  3661. }));
  3662. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3663. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3664. const WaitOnType = {
  3665. EVENT: "event",
  3666. TIMEOUT: "timeout"
  3667. };
  3668. exports.WaitOnType = WaitOnType;
  3669. function waitOnEventOrTimeout({
  3670. target,
  3671. name,
  3672. delay = 0
  3673. }) {
  3674. return new Promise(function (resolve, reject) {
  3675. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3676. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3677. }
  3678. function handler(type) {
  3679. if (target instanceof EventBus) {
  3680. target._off(name, eventHandler);
  3681. } else {
  3682. target.removeEventListener(name, eventHandler);
  3683. }
  3684. if (timeout) {
  3685. clearTimeout(timeout);
  3686. }
  3687. resolve(type);
  3688. }
  3689. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3690. if (target instanceof EventBus) {
  3691. target._on(name, eventHandler);
  3692. } else {
  3693. target.addEventListener(name, eventHandler);
  3694. }
  3695. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3696. const timeout = setTimeout(timeoutHandler, delay);
  3697. });
  3698. }
  3699. class EventBus {
  3700. #listeners = Object.create(null);
  3701. on(eventName, listener, options = null) {
  3702. this._on(eventName, listener, {
  3703. external: true,
  3704. once: options?.once
  3705. });
  3706. }
  3707. off(eventName, listener, options = null) {
  3708. this._off(eventName, listener, {
  3709. external: true,
  3710. once: options?.once
  3711. });
  3712. }
  3713. dispatch(eventName, data) {
  3714. const eventListeners = this.#listeners[eventName];
  3715. if (!eventListeners || eventListeners.length === 0) {
  3716. return;
  3717. }
  3718. let externalListeners;
  3719. for (const {
  3720. listener,
  3721. external,
  3722. once
  3723. } of eventListeners.slice(0)) {
  3724. if (once) {
  3725. this._off(eventName, listener);
  3726. }
  3727. if (external) {
  3728. (externalListeners ||= []).push(listener);
  3729. continue;
  3730. }
  3731. listener(data);
  3732. }
  3733. if (externalListeners) {
  3734. for (const listener of externalListeners) {
  3735. listener(data);
  3736. }
  3737. externalListeners = null;
  3738. }
  3739. }
  3740. _on(eventName, listener, options = null) {
  3741. const eventListeners = this.#listeners[eventName] ||= [];
  3742. eventListeners.push({
  3743. listener,
  3744. external: options?.external === true,
  3745. once: options?.once === true
  3746. });
  3747. }
  3748. _off(eventName, listener, options = null) {
  3749. const eventListeners = this.#listeners[eventName];
  3750. if (!eventListeners) {
  3751. return;
  3752. }
  3753. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3754. if (eventListeners[i].listener === listener) {
  3755. eventListeners.splice(i, 1);
  3756. return;
  3757. }
  3758. }
  3759. }
  3760. }
  3761. exports.EventBus = EventBus;
  3762. class AutomationEventBus extends EventBus {
  3763. dispatch(eventName, data) {
  3764. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3765. }
  3766. }
  3767. exports.AutomationEventBus = AutomationEventBus;
  3768. /***/ }),
  3769. /* 7 */
  3770. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3771. Object.defineProperty(exports, "__esModule", ({
  3772. value: true
  3773. }));
  3774. exports.PDFCursorTools = exports.CursorTool = void 0;
  3775. var _pdfjsLib = __webpack_require__(5);
  3776. var _grab_to_pan = __webpack_require__(8);
  3777. var _ui_utils = __webpack_require__(1);
  3778. const CursorTool = {
  3779. SELECT: 0,
  3780. HAND: 1,
  3781. ZOOM: 2
  3782. };
  3783. exports.CursorTool = CursorTool;
  3784. class PDFCursorTools {
  3785. constructor({
  3786. container,
  3787. eventBus,
  3788. cursorToolOnLoad = CursorTool.SELECT
  3789. }) {
  3790. this.container = container;
  3791. this.eventBus = eventBus;
  3792. this.active = CursorTool.SELECT;
  3793. this.previouslyActive = null;
  3794. this.handTool = new _grab_to_pan.GrabToPan({
  3795. element: this.container
  3796. });
  3797. this.#addEventListeners();
  3798. Promise.resolve().then(() => {
  3799. this.switchTool(cursorToolOnLoad);
  3800. });
  3801. }
  3802. get activeTool() {
  3803. return this.active;
  3804. }
  3805. switchTool(tool) {
  3806. if (this.previouslyActive !== null) {
  3807. return;
  3808. }
  3809. if (tool === this.active) {
  3810. return;
  3811. }
  3812. const disableActiveTool = () => {
  3813. switch (this.active) {
  3814. case CursorTool.SELECT:
  3815. break;
  3816. case CursorTool.HAND:
  3817. this.handTool.deactivate();
  3818. break;
  3819. case CursorTool.ZOOM:
  3820. }
  3821. };
  3822. switch (tool) {
  3823. case CursorTool.SELECT:
  3824. disableActiveTool();
  3825. break;
  3826. case CursorTool.HAND:
  3827. disableActiveTool();
  3828. this.handTool.activate();
  3829. break;
  3830. case CursorTool.ZOOM:
  3831. default:
  3832. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3833. return;
  3834. }
  3835. this.active = tool;
  3836. this.#dispatchEvent();
  3837. }
  3838. #dispatchEvent() {
  3839. this.eventBus.dispatch("cursortoolchanged", {
  3840. source: this,
  3841. tool: this.active
  3842. });
  3843. }
  3844. #addEventListeners() {
  3845. this.eventBus._on("switchcursortool", evt => {
  3846. this.switchTool(evt.tool);
  3847. });
  3848. let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
  3849. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  3850. const disableActive = () => {
  3851. const previouslyActive = this.active;
  3852. this.switchTool(CursorTool.SELECT);
  3853. this.previouslyActive ??= previouslyActive;
  3854. };
  3855. const enableActive = () => {
  3856. const previouslyActive = this.previouslyActive;
  3857. if (previouslyActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) {
  3858. this.previouslyActive = null;
  3859. this.switchTool(previouslyActive);
  3860. }
  3861. };
  3862. this.eventBus._on("secondarytoolbarreset", evt => {
  3863. if (this.previouslyActive !== null) {
  3864. annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  3865. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  3866. enableActive();
  3867. }
  3868. });
  3869. this.eventBus._on("annotationeditormodechanged", ({
  3870. mode
  3871. }) => {
  3872. annotationEditorMode = mode;
  3873. if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
  3874. enableActive();
  3875. } else {
  3876. disableActive();
  3877. }
  3878. });
  3879. this.eventBus._on("presentationmodechanged", ({
  3880. state
  3881. }) => {
  3882. presentationModeState = state;
  3883. if (state === _ui_utils.PresentationModeState.NORMAL) {
  3884. enableActive();
  3885. } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
  3886. disableActive();
  3887. }
  3888. });
  3889. }
  3890. }
  3891. exports.PDFCursorTools = PDFCursorTools;
  3892. /***/ }),
  3893. /* 8 */
  3894. /***/ ((__unused_webpack_module, exports) => {
  3895. Object.defineProperty(exports, "__esModule", ({
  3896. value: true
  3897. }));
  3898. exports.GrabToPan = void 0;
  3899. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3900. class GrabToPan {
  3901. constructor(options) {
  3902. this.element = options.element;
  3903. this.document = options.element.ownerDocument;
  3904. if (typeof options.ignoreTarget === "function") {
  3905. this.ignoreTarget = options.ignoreTarget;
  3906. }
  3907. this.onActiveChanged = options.onActiveChanged;
  3908. this.activate = this.activate.bind(this);
  3909. this.deactivate = this.deactivate.bind(this);
  3910. this.toggle = this.toggle.bind(this);
  3911. this._onMouseDown = this.#onMouseDown.bind(this);
  3912. this._onMouseMove = this.#onMouseMove.bind(this);
  3913. this._endPan = this.#endPan.bind(this);
  3914. const overlay = this.overlay = document.createElement("div");
  3915. overlay.className = "grab-to-pan-grabbing";
  3916. }
  3917. activate() {
  3918. if (!this.active) {
  3919. this.active = true;
  3920. this.element.addEventListener("mousedown", this._onMouseDown, true);
  3921. this.element.classList.add(CSS_CLASS_GRAB);
  3922. this.onActiveChanged?.(true);
  3923. }
  3924. }
  3925. deactivate() {
  3926. if (this.active) {
  3927. this.active = false;
  3928. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  3929. this._endPan();
  3930. this.element.classList.remove(CSS_CLASS_GRAB);
  3931. this.onActiveChanged?.(false);
  3932. }
  3933. }
  3934. toggle() {
  3935. if (this.active) {
  3936. this.deactivate();
  3937. } else {
  3938. this.activate();
  3939. }
  3940. }
  3941. ignoreTarget(node) {
  3942. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3943. }
  3944. #onMouseDown(event) {
  3945. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3946. return;
  3947. }
  3948. if (event.originalTarget) {
  3949. try {
  3950. event.originalTarget.tagName;
  3951. } catch (e) {
  3952. return;
  3953. }
  3954. }
  3955. this.scrollLeftStart = this.element.scrollLeft;
  3956. this.scrollTopStart = this.element.scrollTop;
  3957. this.clientXStart = event.clientX;
  3958. this.clientYStart = event.clientY;
  3959. this.document.addEventListener("mousemove", this._onMouseMove, true);
  3960. this.document.addEventListener("mouseup", this._endPan, true);
  3961. this.element.addEventListener("scroll", this._endPan, true);
  3962. event.preventDefault();
  3963. event.stopPropagation();
  3964. const focusedElement = document.activeElement;
  3965. if (focusedElement && !focusedElement.contains(event.target)) {
  3966. focusedElement.blur();
  3967. }
  3968. }
  3969. #onMouseMove(event) {
  3970. this.element.removeEventListener("scroll", this._endPan, true);
  3971. if (!(event.buttons & 1)) {
  3972. this._endPan();
  3973. return;
  3974. }
  3975. const xDiff = event.clientX - this.clientXStart;
  3976. const yDiff = event.clientY - this.clientYStart;
  3977. const scrollTop = this.scrollTopStart - yDiff;
  3978. const scrollLeft = this.scrollLeftStart - xDiff;
  3979. if (this.element.scrollTo) {
  3980. this.element.scrollTo({
  3981. top: scrollTop,
  3982. left: scrollLeft,
  3983. behavior: "instant"
  3984. });
  3985. } else {
  3986. this.element.scrollTop = scrollTop;
  3987. this.element.scrollLeft = scrollLeft;
  3988. }
  3989. if (!this.overlay.parentNode) {
  3990. document.body.append(this.overlay);
  3991. }
  3992. }
  3993. #endPan() {
  3994. this.element.removeEventListener("scroll", this._endPan, true);
  3995. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  3996. this.document.removeEventListener("mouseup", this._endPan, true);
  3997. this.overlay.remove();
  3998. }
  3999. }
  4000. exports.GrabToPan = GrabToPan;
  4001. /***/ }),
  4002. /* 9 */
  4003. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4004. Object.defineProperty(exports, "__esModule", ({
  4005. value: true
  4006. }));
  4007. exports.AnnotationEditorParams = void 0;
  4008. var _pdfjsLib = __webpack_require__(5);
  4009. class AnnotationEditorParams {
  4010. constructor(options, eventBus) {
  4011. this.eventBus = eventBus;
  4012. this.#bindListeners(options);
  4013. }
  4014. #bindListeners({
  4015. editorFreeTextFontSize,
  4016. editorFreeTextColor,
  4017. editorInkColor,
  4018. editorInkThickness,
  4019. editorInkOpacity
  4020. }) {
  4021. editorFreeTextFontSize.addEventListener("input", evt => {
  4022. this.eventBus.dispatch("switchannotationeditorparams", {
  4023. source: this,
  4024. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE,
  4025. value: editorFreeTextFontSize.valueAsNumber
  4026. });
  4027. });
  4028. editorFreeTextColor.addEventListener("input", evt => {
  4029. this.eventBus.dispatch("switchannotationeditorparams", {
  4030. source: this,
  4031. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR,
  4032. value: editorFreeTextColor.value
  4033. });
  4034. });
  4035. editorInkColor.addEventListener("input", evt => {
  4036. this.eventBus.dispatch("switchannotationeditorparams", {
  4037. source: this,
  4038. type: _pdfjsLib.AnnotationEditorParamsType.INK_COLOR,
  4039. value: editorInkColor.value
  4040. });
  4041. });
  4042. editorInkThickness.addEventListener("input", evt => {
  4043. this.eventBus.dispatch("switchannotationeditorparams", {
  4044. source: this,
  4045. type: _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS,
  4046. value: editorInkThickness.valueAsNumber
  4047. });
  4048. });
  4049. editorInkOpacity.addEventListener("input", evt => {
  4050. this.eventBus.dispatch("switchannotationeditorparams", {
  4051. source: this,
  4052. type: _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY,
  4053. value: editorInkOpacity.valueAsNumber
  4054. });
  4055. });
  4056. this.eventBus._on("annotationeditorparamschanged", evt => {
  4057. for (const [type, value] of evt.details) {
  4058. switch (type) {
  4059. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  4060. editorFreeTextFontSize.value = value;
  4061. break;
  4062. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  4063. editorFreeTextColor.value = value;
  4064. break;
  4065. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  4066. editorInkColor.value = value;
  4067. break;
  4068. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  4069. editorInkThickness.value = value;
  4070. break;
  4071. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  4072. editorInkOpacity.value = value;
  4073. break;
  4074. }
  4075. }
  4076. });
  4077. }
  4078. }
  4079. exports.AnnotationEditorParams = AnnotationEditorParams;
  4080. /***/ }),
  4081. /* 10 */
  4082. /***/ ((__unused_webpack_module, exports) => {
  4083. Object.defineProperty(exports, "__esModule", ({
  4084. value: true
  4085. }));
  4086. exports.OverlayManager = void 0;
  4087. class OverlayManager {
  4088. #overlays = new WeakMap();
  4089. #active = null;
  4090. get active() {
  4091. return this.#active;
  4092. }
  4093. async register(dialog, canForceClose = false) {
  4094. if (typeof dialog !== "object") {
  4095. throw new Error("Not enough parameters.");
  4096. } else if (this.#overlays.has(dialog)) {
  4097. throw new Error("The overlay is already registered.");
  4098. }
  4099. this.#overlays.set(dialog, {
  4100. canForceClose
  4101. });
  4102. dialog.addEventListener("cancel", evt => {
  4103. this.#active = null;
  4104. });
  4105. }
  4106. async unregister(dialog) {
  4107. if (!this.#overlays.has(dialog)) {
  4108. throw new Error("The overlay does not exist.");
  4109. } else if (this.#active === dialog) {
  4110. throw new Error("The overlay cannot be removed while it is active.");
  4111. }
  4112. this.#overlays.delete(dialog);
  4113. }
  4114. async open(dialog) {
  4115. if (!this.#overlays.has(dialog)) {
  4116. throw new Error("The overlay does not exist.");
  4117. } else if (this.#active) {
  4118. if (this.#active === dialog) {
  4119. throw new Error("The overlay is already active.");
  4120. } else if (this.#overlays.get(dialog).canForceClose) {
  4121. await this.close();
  4122. } else {
  4123. throw new Error("Another overlay is currently active.");
  4124. }
  4125. }
  4126. this.#active = dialog;
  4127. dialog.showModal();
  4128. }
  4129. async close(dialog = this.#active) {
  4130. if (!this.#overlays.has(dialog)) {
  4131. throw new Error("The overlay does not exist.");
  4132. } else if (!this.#active) {
  4133. throw new Error("The overlay is currently not active.");
  4134. } else if (this.#active !== dialog) {
  4135. throw new Error("Another overlay is currently active.");
  4136. }
  4137. dialog.close();
  4138. this.#active = null;
  4139. }
  4140. }
  4141. exports.OverlayManager = OverlayManager;
  4142. /***/ }),
  4143. /* 11 */
  4144. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4145. Object.defineProperty(exports, "__esModule", ({
  4146. value: true
  4147. }));
  4148. exports.PasswordPrompt = void 0;
  4149. var _pdfjsLib = __webpack_require__(5);
  4150. class PasswordPrompt {
  4151. #activeCapability = null;
  4152. #updateCallback = null;
  4153. #reason = null;
  4154. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  4155. this.dialog = options.dialog;
  4156. this.label = options.label;
  4157. this.input = options.input;
  4158. this.submitButton = options.submitButton;
  4159. this.cancelButton = options.cancelButton;
  4160. this.overlayManager = overlayManager;
  4161. this.l10n = l10n;
  4162. this._isViewerEmbedded = isViewerEmbedded;
  4163. this.submitButton.addEventListener("click", this.#verify.bind(this));
  4164. this.cancelButton.addEventListener("click", this.close.bind(this));
  4165. this.input.addEventListener("keydown", e => {
  4166. if (e.keyCode === 13) {
  4167. this.#verify();
  4168. }
  4169. });
  4170. this.overlayManager.register(this.dialog, true);
  4171. this.dialog.addEventListener("close", this.#cancel.bind(this));
  4172. }
  4173. async open() {
  4174. if (this.#activeCapability) {
  4175. await this.#activeCapability.promise;
  4176. }
  4177. this.#activeCapability = (0, _pdfjsLib.createPromiseCapability)();
  4178. try {
  4179. await this.overlayManager.open(this.dialog);
  4180. } catch (ex) {
  4181. this.#activeCapability = null;
  4182. throw ex;
  4183. }
  4184. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  4185. if (!this._isViewerEmbedded || passwordIncorrect) {
  4186. this.input.focus();
  4187. }
  4188. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  4189. }
  4190. async close() {
  4191. if (this.overlayManager.active === this.dialog) {
  4192. this.overlayManager.close(this.dialog);
  4193. }
  4194. }
  4195. #verify() {
  4196. const password = this.input.value;
  4197. if (password?.length > 0) {
  4198. this.#invokeCallback(password);
  4199. }
  4200. }
  4201. #cancel() {
  4202. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  4203. this.#activeCapability.resolve();
  4204. }
  4205. #invokeCallback(password) {
  4206. if (!this.#updateCallback) {
  4207. return;
  4208. }
  4209. this.close();
  4210. this.input.value = "";
  4211. this.#updateCallback(password);
  4212. this.#updateCallback = null;
  4213. }
  4214. async setUpdateCallback(updateCallback, reason) {
  4215. if (this.#activeCapability) {
  4216. await this.#activeCapability.promise;
  4217. }
  4218. this.#updateCallback = updateCallback;
  4219. this.#reason = reason;
  4220. }
  4221. }
  4222. exports.PasswordPrompt = PasswordPrompt;
  4223. /***/ }),
  4224. /* 12 */
  4225. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4226. Object.defineProperty(exports, "__esModule", ({
  4227. value: true
  4228. }));
  4229. exports.PDFAttachmentViewer = void 0;
  4230. var _pdfjsLib = __webpack_require__(5);
  4231. var _base_tree_viewer = __webpack_require__(13);
  4232. var _event_utils = __webpack_require__(6);
  4233. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4234. constructor(options) {
  4235. super(options);
  4236. this.downloadManager = options.downloadManager;
  4237. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  4238. }
  4239. reset(keepRenderedCapability = false) {
  4240. super.reset();
  4241. this._attachments = null;
  4242. if (!keepRenderedCapability) {
  4243. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4244. }
  4245. this._pendingDispatchEvent = false;
  4246. }
  4247. async _dispatchEvent(attachmentsCount) {
  4248. this._renderedCapability.resolve();
  4249. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4250. this._pendingDispatchEvent = true;
  4251. await (0, _event_utils.waitOnEventOrTimeout)({
  4252. target: this.eventBus,
  4253. name: "annotationlayerrendered",
  4254. delay: 1000
  4255. });
  4256. if (!this._pendingDispatchEvent) {
  4257. return;
  4258. }
  4259. }
  4260. this._pendingDispatchEvent = false;
  4261. this.eventBus.dispatch("attachmentsloaded", {
  4262. source: this,
  4263. attachmentsCount
  4264. });
  4265. }
  4266. _bindLink(element, {
  4267. content,
  4268. filename
  4269. }) {
  4270. element.onclick = () => {
  4271. this.downloadManager.openOrDownloadData(element, content, filename);
  4272. return false;
  4273. };
  4274. }
  4275. render({
  4276. attachments,
  4277. keepRenderedCapability = false
  4278. }) {
  4279. if (this._attachments) {
  4280. this.reset(keepRenderedCapability);
  4281. }
  4282. this._attachments = attachments || null;
  4283. if (!attachments) {
  4284. this._dispatchEvent(0);
  4285. return;
  4286. }
  4287. const names = Object.keys(attachments).sort(function (a, b) {
  4288. return a.toLowerCase().localeCompare(b.toLowerCase());
  4289. });
  4290. const fragment = document.createDocumentFragment();
  4291. let attachmentsCount = 0;
  4292. for (const name of names) {
  4293. const item = attachments[name];
  4294. const content = item.content,
  4295. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true);
  4296. const div = document.createElement("div");
  4297. div.className = "treeItem";
  4298. const element = document.createElement("a");
  4299. this._bindLink(element, {
  4300. content,
  4301. filename
  4302. });
  4303. element.textContent = this._normalizeTextContent(filename);
  4304. div.append(element);
  4305. fragment.append(div);
  4306. attachmentsCount++;
  4307. }
  4308. this._finishRendering(fragment, attachmentsCount);
  4309. }
  4310. #appendAttachment({
  4311. filename,
  4312. content
  4313. }) {
  4314. const renderedPromise = this._renderedCapability.promise;
  4315. renderedPromise.then(() => {
  4316. if (renderedPromise !== this._renderedCapability.promise) {
  4317. return;
  4318. }
  4319. const attachments = this._attachments || Object.create(null);
  4320. for (const name in attachments) {
  4321. if (filename === name) {
  4322. return;
  4323. }
  4324. }
  4325. attachments[filename] = {
  4326. filename,
  4327. content
  4328. };
  4329. this.render({
  4330. attachments,
  4331. keepRenderedCapability: true
  4332. });
  4333. });
  4334. }
  4335. }
  4336. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4337. /***/ }),
  4338. /* 13 */
  4339. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4340. Object.defineProperty(exports, "__esModule", ({
  4341. value: true
  4342. }));
  4343. exports.BaseTreeViewer = void 0;
  4344. var _ui_utils = __webpack_require__(1);
  4345. const TREEITEM_OFFSET_TOP = -100;
  4346. const TREEITEM_SELECTED_CLASS = "selected";
  4347. class BaseTreeViewer {
  4348. constructor(options) {
  4349. if (this.constructor === BaseTreeViewer) {
  4350. throw new Error("Cannot initialize BaseTreeViewer.");
  4351. }
  4352. this.container = options.container;
  4353. this.eventBus = options.eventBus;
  4354. this.reset();
  4355. }
  4356. reset() {
  4357. this._pdfDocument = null;
  4358. this._lastToggleIsShow = true;
  4359. this._currentTreeItem = null;
  4360. this.container.textContent = "";
  4361. this.container.classList.remove("treeWithDeepNesting");
  4362. }
  4363. _dispatchEvent(count) {
  4364. throw new Error("Not implemented: _dispatchEvent");
  4365. }
  4366. _bindLink(element, params) {
  4367. throw new Error("Not implemented: _bindLink");
  4368. }
  4369. _normalizeTextContent(str) {
  4370. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4371. }
  4372. _addToggleButton(div, hidden = false) {
  4373. const toggler = document.createElement("div");
  4374. toggler.className = "treeItemToggler";
  4375. if (hidden) {
  4376. toggler.classList.add("treeItemsHidden");
  4377. }
  4378. toggler.onclick = evt => {
  4379. evt.stopPropagation();
  4380. toggler.classList.toggle("treeItemsHidden");
  4381. if (evt.shiftKey) {
  4382. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4383. this._toggleTreeItem(div, shouldShowAll);
  4384. }
  4385. };
  4386. div.prepend(toggler);
  4387. }
  4388. _toggleTreeItem(root, show = false) {
  4389. this._lastToggleIsShow = show;
  4390. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4391. toggler.classList.toggle("treeItemsHidden", !show);
  4392. }
  4393. }
  4394. _toggleAllTreeItems() {
  4395. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4396. }
  4397. _finishRendering(fragment, count, hasAnyNesting = false) {
  4398. if (hasAnyNesting) {
  4399. this.container.classList.add("treeWithDeepNesting");
  4400. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4401. }
  4402. this.container.append(fragment);
  4403. this._dispatchEvent(count);
  4404. }
  4405. render(params) {
  4406. throw new Error("Not implemented: render");
  4407. }
  4408. _updateCurrentTreeItem(treeItem = null) {
  4409. if (this._currentTreeItem) {
  4410. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4411. this._currentTreeItem = null;
  4412. }
  4413. if (treeItem) {
  4414. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4415. this._currentTreeItem = treeItem;
  4416. }
  4417. }
  4418. _scrollToCurrentTreeItem(treeItem) {
  4419. if (!treeItem) {
  4420. return;
  4421. }
  4422. let currentNode = treeItem.parentNode;
  4423. while (currentNode && currentNode !== this.container) {
  4424. if (currentNode.classList.contains("treeItem")) {
  4425. const toggler = currentNode.firstElementChild;
  4426. toggler?.classList.remove("treeItemsHidden");
  4427. }
  4428. currentNode = currentNode.parentNode;
  4429. }
  4430. this._updateCurrentTreeItem(treeItem);
  4431. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4432. }
  4433. }
  4434. exports.BaseTreeViewer = BaseTreeViewer;
  4435. /***/ }),
  4436. /* 14 */
  4437. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4438. Object.defineProperty(exports, "__esModule", ({
  4439. value: true
  4440. }));
  4441. exports.PDFDocumentProperties = void 0;
  4442. var _pdfjsLib = __webpack_require__(5);
  4443. var _ui_utils = __webpack_require__(1);
  4444. const DEFAULT_FIELD_CONTENT = "-";
  4445. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4446. const US_PAGE_NAMES = {
  4447. "8.5x11": "Letter",
  4448. "8.5x14": "Legal"
  4449. };
  4450. const METRIC_PAGE_NAMES = {
  4451. "297x420": "A3",
  4452. "210x297": "A4"
  4453. };
  4454. function getPageName(size, isPortrait, pageNames) {
  4455. const width = isPortrait ? size.width : size.height;
  4456. const height = isPortrait ? size.height : size.width;
  4457. return pageNames[`${width}x${height}`];
  4458. }
  4459. class PDFDocumentProperties {
  4460. #fieldData = null;
  4461. constructor({
  4462. dialog,
  4463. fields,
  4464. closeButton
  4465. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4466. this.dialog = dialog;
  4467. this.fields = fields;
  4468. this.overlayManager = overlayManager;
  4469. this.l10n = l10n;
  4470. this._fileNameLookup = fileNameLookup;
  4471. this.#reset();
  4472. closeButton.addEventListener("click", this.close.bind(this));
  4473. this.overlayManager.register(this.dialog);
  4474. eventBus._on("pagechanging", evt => {
  4475. this._currentPageNumber = evt.pageNumber;
  4476. });
  4477. eventBus._on("rotationchanging", evt => {
  4478. this._pagesRotation = evt.pagesRotation;
  4479. });
  4480. this._isNonMetricLocale = true;
  4481. l10n.getLanguage().then(locale => {
  4482. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4483. });
  4484. }
  4485. async open() {
  4486. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4487. const currentPageNumber = this._currentPageNumber;
  4488. const pagesRotation = this._pagesRotation;
  4489. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4490. this.#updateUI();
  4491. return;
  4492. }
  4493. const {
  4494. info,
  4495. contentLength
  4496. } = await this.pdfDocument.getMetadata();
  4497. const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([this._fileNameLookup(), this.#parseFileSize(contentLength), this.#parseDate(info.CreationDate), this.#parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
  4498. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4499. }), this.#parseLinearization(info.IsLinearized)]);
  4500. this.#fieldData = Object.freeze({
  4501. fileName,
  4502. fileSize,
  4503. title: info.Title,
  4504. author: info.Author,
  4505. subject: info.Subject,
  4506. keywords: info.Keywords,
  4507. creationDate,
  4508. modificationDate,
  4509. creator: info.Creator,
  4510. producer: info.Producer,
  4511. version: info.PDFFormatVersion,
  4512. pageCount: this.pdfDocument.numPages,
  4513. pageSize,
  4514. linearized: isLinearized,
  4515. _currentPageNumber: currentPageNumber,
  4516. _pagesRotation: pagesRotation
  4517. });
  4518. this.#updateUI();
  4519. const {
  4520. length
  4521. } = await this.pdfDocument.getDownloadInfo();
  4522. if (contentLength === length) {
  4523. return;
  4524. }
  4525. const data = Object.assign(Object.create(null), this.#fieldData);
  4526. data.fileSize = await this.#parseFileSize(length);
  4527. this.#fieldData = Object.freeze(data);
  4528. this.#updateUI();
  4529. }
  4530. async close() {
  4531. this.overlayManager.close(this.dialog);
  4532. }
  4533. setDocument(pdfDocument) {
  4534. if (this.pdfDocument) {
  4535. this.#reset();
  4536. this.#updateUI(true);
  4537. }
  4538. if (!pdfDocument) {
  4539. return;
  4540. }
  4541. this.pdfDocument = pdfDocument;
  4542. this._dataAvailableCapability.resolve();
  4543. }
  4544. #reset() {
  4545. this.pdfDocument = null;
  4546. this.#fieldData = null;
  4547. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4548. this._currentPageNumber = 1;
  4549. this._pagesRotation = 0;
  4550. }
  4551. #updateUI(reset = false) {
  4552. if (reset || !this.#fieldData) {
  4553. for (const id in this.fields) {
  4554. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4555. }
  4556. return;
  4557. }
  4558. if (this.overlayManager.active !== this.dialog) {
  4559. return;
  4560. }
  4561. for (const id in this.fields) {
  4562. const content = this.#fieldData[id];
  4563. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4564. }
  4565. }
  4566. async #parseFileSize(fileSize = 0) {
  4567. const kb = fileSize / 1024,
  4568. mb = kb / 1024;
  4569. if (!kb) {
  4570. return undefined;
  4571. }
  4572. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4573. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4574. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4575. size_b: fileSize.toLocaleString()
  4576. });
  4577. }
  4578. async #parsePageSize(pageSizeInches, pagesRotation) {
  4579. if (!pageSizeInches) {
  4580. return undefined;
  4581. }
  4582. if (pagesRotation % 180 !== 0) {
  4583. pageSizeInches = {
  4584. width: pageSizeInches.height,
  4585. height: pageSizeInches.width
  4586. };
  4587. }
  4588. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4589. let sizeInches = {
  4590. width: Math.round(pageSizeInches.width * 100) / 100,
  4591. height: Math.round(pageSizeInches.height * 100) / 100
  4592. };
  4593. let sizeMillimeters = {
  4594. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4595. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4596. };
  4597. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4598. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4599. const exactMillimeters = {
  4600. width: pageSizeInches.width * 25.4,
  4601. height: pageSizeInches.height * 25.4
  4602. };
  4603. const intMillimeters = {
  4604. width: Math.round(sizeMillimeters.width),
  4605. height: Math.round(sizeMillimeters.height)
  4606. };
  4607. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4608. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4609. if (rawName) {
  4610. sizeInches = {
  4611. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4612. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4613. };
  4614. sizeMillimeters = intMillimeters;
  4615. }
  4616. }
  4617. }
  4618. const [{
  4619. width,
  4620. height
  4621. }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`document_properties_page_size_unit_${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`), this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`)]);
  4622. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4623. width: width.toLocaleString(),
  4624. height: height.toLocaleString(),
  4625. unit,
  4626. name,
  4627. orientation
  4628. });
  4629. }
  4630. async #parseDate(inputDate) {
  4631. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4632. if (!dateObject) {
  4633. return undefined;
  4634. }
  4635. return this.l10n.get("document_properties_date_string", {
  4636. date: dateObject.toLocaleDateString(),
  4637. time: dateObject.toLocaleTimeString()
  4638. });
  4639. }
  4640. #parseLinearization(isLinearized) {
  4641. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4642. }
  4643. }
  4644. exports.PDFDocumentProperties = PDFDocumentProperties;
  4645. /***/ }),
  4646. /* 15 */
  4647. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4648. Object.defineProperty(exports, "__esModule", ({
  4649. value: true
  4650. }));
  4651. exports.PDFFindBar = void 0;
  4652. var _pdf_find_controller = __webpack_require__(16);
  4653. const MATCHES_COUNT_LIMIT = 1000;
  4654. class PDFFindBar {
  4655. constructor(options, eventBus, l10n) {
  4656. this.opened = false;
  4657. this.bar = options.bar;
  4658. this.toggleButton = options.toggleButton;
  4659. this.findField = options.findField;
  4660. this.highlightAll = options.highlightAllCheckbox;
  4661. this.caseSensitive = options.caseSensitiveCheckbox;
  4662. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4663. this.entireWord = options.entireWordCheckbox;
  4664. this.findMsg = options.findMsg;
  4665. this.findResultsCount = options.findResultsCount;
  4666. this.findPreviousButton = options.findPreviousButton;
  4667. this.findNextButton = options.findNextButton;
  4668. this.eventBus = eventBus;
  4669. this.l10n = l10n;
  4670. this.toggleButton.addEventListener("click", () => {
  4671. this.toggle();
  4672. });
  4673. this.findField.addEventListener("input", () => {
  4674. this.dispatchEvent("");
  4675. });
  4676. this.bar.addEventListener("keydown", e => {
  4677. switch (e.keyCode) {
  4678. case 13:
  4679. if (e.target === this.findField) {
  4680. this.dispatchEvent("again", e.shiftKey);
  4681. }
  4682. break;
  4683. case 27:
  4684. this.close();
  4685. break;
  4686. }
  4687. });
  4688. this.findPreviousButton.addEventListener("click", () => {
  4689. this.dispatchEvent("again", true);
  4690. });
  4691. this.findNextButton.addEventListener("click", () => {
  4692. this.dispatchEvent("again", false);
  4693. });
  4694. this.highlightAll.addEventListener("click", () => {
  4695. this.dispatchEvent("highlightallchange");
  4696. });
  4697. this.caseSensitive.addEventListener("click", () => {
  4698. this.dispatchEvent("casesensitivitychange");
  4699. });
  4700. this.entireWord.addEventListener("click", () => {
  4701. this.dispatchEvent("entirewordchange");
  4702. });
  4703. this.matchDiacritics.addEventListener("click", () => {
  4704. this.dispatchEvent("diacriticmatchingchange");
  4705. });
  4706. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4707. }
  4708. reset() {
  4709. this.updateUIState();
  4710. }
  4711. dispatchEvent(type, findPrev = false) {
  4712. this.eventBus.dispatch("find", {
  4713. source: this,
  4714. type,
  4715. query: this.findField.value,
  4716. phraseSearch: true,
  4717. caseSensitive: this.caseSensitive.checked,
  4718. entireWord: this.entireWord.checked,
  4719. highlightAll: this.highlightAll.checked,
  4720. findPrevious: findPrev,
  4721. matchDiacritics: this.matchDiacritics.checked
  4722. });
  4723. }
  4724. updateUIState(state, previous, matchesCount) {
  4725. let findMsg = Promise.resolve("");
  4726. let status = "";
  4727. switch (state) {
  4728. case _pdf_find_controller.FindState.FOUND:
  4729. break;
  4730. case _pdf_find_controller.FindState.PENDING:
  4731. status = "pending";
  4732. break;
  4733. case _pdf_find_controller.FindState.NOT_FOUND:
  4734. findMsg = this.l10n.get("find_not_found");
  4735. status = "notFound";
  4736. break;
  4737. case _pdf_find_controller.FindState.WRAPPED:
  4738. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4739. break;
  4740. }
  4741. this.findField.setAttribute("data-status", status);
  4742. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4743. findMsg.then(msg => {
  4744. this.findMsg.textContent = msg;
  4745. this.#adjustWidth();
  4746. });
  4747. this.updateResultsCount(matchesCount);
  4748. }
  4749. updateResultsCount({
  4750. current = 0,
  4751. total = 0
  4752. } = {}) {
  4753. const limit = MATCHES_COUNT_LIMIT;
  4754. let matchCountMsg = Promise.resolve("");
  4755. if (total > 0) {
  4756. if (total > limit) {
  4757. let key = "find_match_count_limit";
  4758. matchCountMsg = this.l10n.get(key, {
  4759. limit
  4760. });
  4761. } else {
  4762. let key = "find_match_count";
  4763. matchCountMsg = this.l10n.get(key, {
  4764. current,
  4765. total
  4766. });
  4767. }
  4768. }
  4769. matchCountMsg.then(msg => {
  4770. this.findResultsCount.textContent = msg;
  4771. this.#adjustWidth();
  4772. });
  4773. }
  4774. open() {
  4775. if (!this.opened) {
  4776. this.opened = true;
  4777. this.toggleButton.classList.add("toggled");
  4778. this.toggleButton.setAttribute("aria-expanded", "true");
  4779. this.bar.classList.remove("hidden");
  4780. }
  4781. this.findField.select();
  4782. this.findField.focus();
  4783. this.#adjustWidth();
  4784. }
  4785. close() {
  4786. if (!this.opened) {
  4787. return;
  4788. }
  4789. this.opened = false;
  4790. this.toggleButton.classList.remove("toggled");
  4791. this.toggleButton.setAttribute("aria-expanded", "false");
  4792. this.bar.classList.add("hidden");
  4793. this.eventBus.dispatch("findbarclose", {
  4794. source: this
  4795. });
  4796. }
  4797. toggle() {
  4798. if (this.opened) {
  4799. this.close();
  4800. } else {
  4801. this.open();
  4802. }
  4803. }
  4804. #adjustWidth() {
  4805. if (!this.opened) {
  4806. return;
  4807. }
  4808. this.bar.classList.remove("wrapContainers");
  4809. const findbarHeight = this.bar.clientHeight;
  4810. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4811. if (findbarHeight > inputContainerHeight) {
  4812. this.bar.classList.add("wrapContainers");
  4813. }
  4814. }
  4815. }
  4816. exports.PDFFindBar = PDFFindBar;
  4817. /***/ }),
  4818. /* 16 */
  4819. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4820. Object.defineProperty(exports, "__esModule", ({
  4821. value: true
  4822. }));
  4823. exports.PDFFindController = exports.FindState = void 0;
  4824. var _ui_utils = __webpack_require__(1);
  4825. var _pdfjsLib = __webpack_require__(5);
  4826. var _pdf_find_utils = __webpack_require__(17);
  4827. const FindState = {
  4828. FOUND: 0,
  4829. NOT_FOUND: 1,
  4830. WRAPPED: 2,
  4831. PENDING: 3
  4832. };
  4833. exports.FindState = FindState;
  4834. const FIND_TIMEOUT = 250;
  4835. const MATCH_SCROLL_OFFSET_TOP = -50;
  4836. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4837. const CHARACTERS_TO_NORMALIZE = {
  4838. "\u2010": "-",
  4839. "\u2018": "'",
  4840. "\u2019": "'",
  4841. "\u201A": "'",
  4842. "\u201B": "'",
  4843. "\u201C": '"',
  4844. "\u201D": '"',
  4845. "\u201E": '"',
  4846. "\u201F": '"',
  4847. "\u00BC": "1/4",
  4848. "\u00BD": "1/2",
  4849. "\u00BE": "3/4"
  4850. };
  4851. 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]);
  4852. let DIACRITICS_EXCEPTION_STR;
  4853. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4854. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4855. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4856. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4857. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4858. const SYLLABLES_LENGTHS = new Map();
  4859. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4860. const NFKC_CHARS_TO_NORMALIZE = new Map();
  4861. let noSyllablesRegExp = null;
  4862. let withSyllablesRegExp = null;
  4863. function normalize(text) {
  4864. const syllablePositions = [];
  4865. let m;
  4866. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4867. let {
  4868. index
  4869. } = m;
  4870. for (const char of m[0]) {
  4871. let len = SYLLABLES_LENGTHS.get(char);
  4872. if (!len) {
  4873. len = char.normalize("NFD").length;
  4874. SYLLABLES_LENGTHS.set(char, len);
  4875. }
  4876. syllablePositions.push([len, index++]);
  4877. }
  4878. }
  4879. let normalizationRegex;
  4880. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4881. normalizationRegex = noSyllablesRegExp;
  4882. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4883. normalizationRegex = withSyllablesRegExp;
  4884. } else {
  4885. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4886. const toNormalizeWithNFKC = "\u2460-\u2473" + "\u24b6-\u24ff" + "\u3244-\u32bf" + "\u32d0-\u32fe" + "\uff00-\uffef";
  4887. const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
  4888. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
  4889. if (syllablePositions.length === 0) {
  4890. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4891. } else {
  4892. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4893. }
  4894. }
  4895. const rawDiacriticsPositions = [];
  4896. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4897. rawDiacriticsPositions.push([m[0].length, m.index]);
  4898. }
  4899. let normalized = text.normalize("NFD");
  4900. const positions = [[0, 0]];
  4901. let rawDiacriticsIndex = 0;
  4902. let syllableIndex = 0;
  4903. let shift = 0;
  4904. let shiftOrigin = 0;
  4905. let eol = 0;
  4906. let hasDiacritics = false;
  4907. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, i) => {
  4908. i -= shiftOrigin;
  4909. if (p1) {
  4910. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  4911. const jj = replacement.length;
  4912. for (let j = 1; j < jj; j++) {
  4913. positions.push([i - shift + j, shift - j]);
  4914. }
  4915. shift -= jj - 1;
  4916. return replacement;
  4917. }
  4918. if (p2) {
  4919. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  4920. if (!replacement) {
  4921. replacement = p2.normalize("NFKC");
  4922. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  4923. }
  4924. const jj = replacement.length;
  4925. for (let j = 1; j < jj; j++) {
  4926. positions.push([i - shift + j, shift - j]);
  4927. }
  4928. shift -= jj - 1;
  4929. return replacement;
  4930. }
  4931. if (p3) {
  4932. const hasTrailingDashEOL = p3.endsWith("\n");
  4933. const len = hasTrailingDashEOL ? p3.length - 2 : p3.length;
  4934. hasDiacritics = true;
  4935. let jj = len;
  4936. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4937. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4938. ++rawDiacriticsIndex;
  4939. }
  4940. for (let j = 1; j <= jj; j++) {
  4941. positions.push([i - 1 - shift + j, shift - j]);
  4942. }
  4943. shift -= jj;
  4944. shiftOrigin += jj;
  4945. if (hasTrailingDashEOL) {
  4946. i += len - 1;
  4947. positions.push([i - shift + 1, 1 + shift]);
  4948. shift += 1;
  4949. shiftOrigin += 1;
  4950. eol += 1;
  4951. return p3.slice(0, len);
  4952. }
  4953. return p3;
  4954. }
  4955. if (p4) {
  4956. positions.push([i - shift + 1, 1 + shift]);
  4957. shift += 1;
  4958. shiftOrigin += 1;
  4959. eol += 1;
  4960. return p4.charAt(0);
  4961. }
  4962. if (p5) {
  4963. positions.push([i - shift + 1, shift]);
  4964. shiftOrigin += 1;
  4965. eol += 1;
  4966. return p5.charAt(0);
  4967. }
  4968. if (p6) {
  4969. positions.push([i - shift + 1, shift - 1]);
  4970. shift -= 1;
  4971. shiftOrigin += 1;
  4972. eol += 1;
  4973. return " ";
  4974. }
  4975. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  4976. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  4977. ++syllableIndex;
  4978. for (let j = 1; j <= newCharLen; j++) {
  4979. positions.push([i - (shift - j), shift - j]);
  4980. }
  4981. shift -= newCharLen;
  4982. shiftOrigin += newCharLen;
  4983. }
  4984. return p7;
  4985. });
  4986. positions.push([normalized.length, shift]);
  4987. return [normalized, positions, hasDiacritics];
  4988. }
  4989. function getOriginalIndex(diffs, pos, len) {
  4990. if (!diffs) {
  4991. return [pos, len];
  4992. }
  4993. const start = pos;
  4994. const end = pos + len;
  4995. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  4996. if (diffs[i][0] > start) {
  4997. --i;
  4998. }
  4999. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  5000. if (diffs[j][0] > end) {
  5001. --j;
  5002. }
  5003. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  5004. }
  5005. class PDFFindController {
  5006. #updateMatchesCountOnProgress = true;
  5007. #visitedPagesCount = 0;
  5008. constructor({
  5009. linkService,
  5010. eventBus,
  5011. updateMatchesCountOnProgress = true
  5012. }) {
  5013. this._linkService = linkService;
  5014. this._eventBus = eventBus;
  5015. this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
  5016. this.#reset();
  5017. eventBus._on("find", this.#onFind.bind(this));
  5018. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  5019. }
  5020. get highlightMatches() {
  5021. return this._highlightMatches;
  5022. }
  5023. get pageMatches() {
  5024. return this._pageMatches;
  5025. }
  5026. get pageMatchesLength() {
  5027. return this._pageMatchesLength;
  5028. }
  5029. get selected() {
  5030. return this._selected;
  5031. }
  5032. get state() {
  5033. return this._state;
  5034. }
  5035. setDocument(pdfDocument) {
  5036. if (this._pdfDocument) {
  5037. this.#reset();
  5038. }
  5039. if (!pdfDocument) {
  5040. return;
  5041. }
  5042. this._pdfDocument = pdfDocument;
  5043. this._firstPageCapability.resolve();
  5044. }
  5045. #onFind(state) {
  5046. if (!state) {
  5047. return;
  5048. }
  5049. const pdfDocument = this._pdfDocument;
  5050. const {
  5051. type
  5052. } = state;
  5053. if (this._state === null || this.#shouldDirtyMatch(state)) {
  5054. this._dirtyMatch = true;
  5055. }
  5056. this._state = state;
  5057. if (type !== "highlightallchange") {
  5058. this.#updateUIState(FindState.PENDING);
  5059. }
  5060. this._firstPageCapability.promise.then(() => {
  5061. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5062. return;
  5063. }
  5064. this.#extractText();
  5065. const findbarClosed = !this._highlightMatches;
  5066. const pendingTimeout = !!this._findTimeout;
  5067. if (this._findTimeout) {
  5068. clearTimeout(this._findTimeout);
  5069. this._findTimeout = null;
  5070. }
  5071. if (!type) {
  5072. this._findTimeout = setTimeout(() => {
  5073. this.#nextMatch();
  5074. this._findTimeout = null;
  5075. }, FIND_TIMEOUT);
  5076. } else if (this._dirtyMatch) {
  5077. this.#nextMatch();
  5078. } else if (type === "again") {
  5079. this.#nextMatch();
  5080. if (findbarClosed && this._state.highlightAll) {
  5081. this.#updateAllPages();
  5082. }
  5083. } else if (type === "highlightallchange") {
  5084. if (pendingTimeout) {
  5085. this.#nextMatch();
  5086. } else {
  5087. this._highlightMatches = true;
  5088. }
  5089. this.#updateAllPages();
  5090. } else {
  5091. this.#nextMatch();
  5092. }
  5093. });
  5094. }
  5095. scrollMatchIntoView({
  5096. element = null,
  5097. selectedLeft = 0,
  5098. pageIndex = -1,
  5099. matchIndex = -1
  5100. }) {
  5101. if (!this._scrollMatches || !element) {
  5102. return;
  5103. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  5104. return;
  5105. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5106. return;
  5107. }
  5108. this._scrollMatches = false;
  5109. const spot = {
  5110. top: MATCH_SCROLL_OFFSET_TOP,
  5111. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  5112. };
  5113. (0, _ui_utils.scrollIntoView)(element, spot, true);
  5114. }
  5115. #reset() {
  5116. this._highlightMatches = false;
  5117. this._scrollMatches = false;
  5118. this._pdfDocument = null;
  5119. this._pageMatches = [];
  5120. this._pageMatchesLength = [];
  5121. this.#visitedPagesCount = 0;
  5122. this._state = null;
  5123. this._selected = {
  5124. pageIdx: -1,
  5125. matchIdx: -1
  5126. };
  5127. this._offset = {
  5128. pageIdx: null,
  5129. matchIdx: null,
  5130. wrapped: false
  5131. };
  5132. this._extractTextPromises = [];
  5133. this._pageContents = [];
  5134. this._pageDiffs = [];
  5135. this._hasDiacritics = [];
  5136. this._matchesCountTotal = 0;
  5137. this._pagesToSearch = null;
  5138. this._pendingFindMatches = new Set();
  5139. this._resumePageIdx = null;
  5140. this._dirtyMatch = false;
  5141. clearTimeout(this._findTimeout);
  5142. this._findTimeout = null;
  5143. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  5144. }
  5145. get #query() {
  5146. if (this._state.query !== this._rawQuery) {
  5147. this._rawQuery = this._state.query;
  5148. [this._normalizedQuery] = normalize(this._state.query);
  5149. }
  5150. return this._normalizedQuery;
  5151. }
  5152. #shouldDirtyMatch(state) {
  5153. if (state.query !== this._state.query) {
  5154. return true;
  5155. }
  5156. switch (state.type) {
  5157. case "again":
  5158. const pageNumber = this._selected.pageIdx + 1;
  5159. const linkService = this._linkService;
  5160. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  5161. return true;
  5162. }
  5163. return false;
  5164. case "highlightallchange":
  5165. return false;
  5166. }
  5167. return true;
  5168. }
  5169. #isEntireWord(content, startIdx, length) {
  5170. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  5171. if (match) {
  5172. const first = content.charCodeAt(startIdx);
  5173. const limit = match[1].charCodeAt(0);
  5174. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5175. return false;
  5176. }
  5177. }
  5178. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  5179. if (match) {
  5180. const last = content.charCodeAt(startIdx + length - 1);
  5181. const limit = match[1].charCodeAt(0);
  5182. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5183. return false;
  5184. }
  5185. }
  5186. return true;
  5187. }
  5188. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  5189. const matches = this._pageMatches[pageIndex] = [];
  5190. const matchesLength = this._pageMatchesLength[pageIndex] = [];
  5191. if (!query) {
  5192. return;
  5193. }
  5194. const diffs = this._pageDiffs[pageIndex];
  5195. let match;
  5196. while ((match = query.exec(pageContent)) !== null) {
  5197. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  5198. continue;
  5199. }
  5200. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  5201. if (matchLen) {
  5202. matches.push(matchPos);
  5203. matchesLength.push(matchLen);
  5204. }
  5205. }
  5206. }
  5207. #convertToRegExpString(query, hasDiacritics) {
  5208. const {
  5209. matchDiacritics
  5210. } = this._state;
  5211. let isUnicode = false;
  5212. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5213. if (p1) {
  5214. return `[ ]*\\${p1}[ ]*`;
  5215. }
  5216. if (p2) {
  5217. return `[ ]*${p2}[ ]*`;
  5218. }
  5219. if (p3) {
  5220. return "[ ]+";
  5221. }
  5222. if (matchDiacritics) {
  5223. return p4 || p5;
  5224. }
  5225. if (p4) {
  5226. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5227. }
  5228. if (hasDiacritics) {
  5229. isUnicode = true;
  5230. return `${p5}\\p{M}*`;
  5231. }
  5232. return p5;
  5233. });
  5234. const trailingSpaces = "[ ]*";
  5235. if (query.endsWith(trailingSpaces)) {
  5236. query = query.slice(0, query.length - trailingSpaces.length);
  5237. }
  5238. if (matchDiacritics) {
  5239. if (hasDiacritics) {
  5240. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
  5241. isUnicode = true;
  5242. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5243. }
  5244. }
  5245. return [isUnicode, query];
  5246. }
  5247. #calculateMatch(pageIndex) {
  5248. let query = this.#query;
  5249. if (!query) {
  5250. return;
  5251. }
  5252. const {
  5253. caseSensitive,
  5254. entireWord,
  5255. phraseSearch
  5256. } = this._state;
  5257. const pageContent = this._pageContents[pageIndex];
  5258. const hasDiacritics = this._hasDiacritics[pageIndex];
  5259. let isUnicode = false;
  5260. if (phraseSearch) {
  5261. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5262. } else {
  5263. const match = query.match(/\S+/g);
  5264. if (match) {
  5265. query = match.sort().reverse().map(q => {
  5266. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5267. isUnicode ||= isUnicodePart;
  5268. return `(${queryPart})`;
  5269. }).join("|");
  5270. }
  5271. }
  5272. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5273. query = query ? new RegExp(query, flags) : null;
  5274. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  5275. if (this._state.highlightAll) {
  5276. this.#updatePage(pageIndex);
  5277. }
  5278. if (this._resumePageIdx === pageIndex) {
  5279. this._resumePageIdx = null;
  5280. this.#nextPageMatch();
  5281. }
  5282. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5283. this._matchesCountTotal += pageMatchesCount;
  5284. if (this.#updateMatchesCountOnProgress) {
  5285. if (pageMatchesCount > 0) {
  5286. this.#updateUIResultsCount();
  5287. }
  5288. } else if (++this.#visitedPagesCount === this._linkService.pagesCount) {
  5289. this.#updateUIResultsCount();
  5290. }
  5291. }
  5292. #extractText() {
  5293. if (this._extractTextPromises.length > 0) {
  5294. return;
  5295. }
  5296. let promise = Promise.resolve();
  5297. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5298. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  5299. this._extractTextPromises[i] = extractTextCapability.promise;
  5300. promise = promise.then(() => {
  5301. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5302. return pdfPage.getTextContent();
  5303. }).then(textContent => {
  5304. const strBuf = [];
  5305. for (const textItem of textContent.items) {
  5306. strBuf.push(textItem.str);
  5307. if (textItem.hasEOL) {
  5308. strBuf.push("\n");
  5309. }
  5310. }
  5311. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5312. extractTextCapability.resolve();
  5313. }, reason => {
  5314. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5315. this._pageContents[i] = "";
  5316. this._pageDiffs[i] = null;
  5317. this._hasDiacritics[i] = false;
  5318. extractTextCapability.resolve();
  5319. });
  5320. });
  5321. }
  5322. }
  5323. #updatePage(index) {
  5324. if (this._scrollMatches && this._selected.pageIdx === index) {
  5325. this._linkService.page = index + 1;
  5326. }
  5327. this._eventBus.dispatch("updatetextlayermatches", {
  5328. source: this,
  5329. pageIndex: index
  5330. });
  5331. }
  5332. #updateAllPages() {
  5333. this._eventBus.dispatch("updatetextlayermatches", {
  5334. source: this,
  5335. pageIndex: -1
  5336. });
  5337. }
  5338. #nextMatch() {
  5339. const previous = this._state.findPrevious;
  5340. const currentPageIndex = this._linkService.page - 1;
  5341. const numPages = this._linkService.pagesCount;
  5342. this._highlightMatches = true;
  5343. if (this._dirtyMatch) {
  5344. this._dirtyMatch = false;
  5345. this._selected.pageIdx = this._selected.matchIdx = -1;
  5346. this._offset.pageIdx = currentPageIndex;
  5347. this._offset.matchIdx = null;
  5348. this._offset.wrapped = false;
  5349. this._resumePageIdx = null;
  5350. this._pageMatches.length = 0;
  5351. this._pageMatchesLength.length = 0;
  5352. this.#visitedPagesCount = 0;
  5353. this._matchesCountTotal = 0;
  5354. this.#updateAllPages();
  5355. for (let i = 0; i < numPages; i++) {
  5356. if (this._pendingFindMatches.has(i)) {
  5357. continue;
  5358. }
  5359. this._pendingFindMatches.add(i);
  5360. this._extractTextPromises[i].then(() => {
  5361. this._pendingFindMatches.delete(i);
  5362. this.#calculateMatch(i);
  5363. });
  5364. }
  5365. }
  5366. if (!this.#query) {
  5367. this.#updateUIState(FindState.FOUND);
  5368. return;
  5369. }
  5370. if (this._resumePageIdx) {
  5371. return;
  5372. }
  5373. const offset = this._offset;
  5374. this._pagesToSearch = numPages;
  5375. if (offset.matchIdx !== null) {
  5376. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5377. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5378. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5379. this.#updateMatch(true);
  5380. return;
  5381. }
  5382. this.#advanceOffsetPage(previous);
  5383. }
  5384. this.#nextPageMatch();
  5385. }
  5386. #matchesReady(matches) {
  5387. const offset = this._offset;
  5388. const numMatches = matches.length;
  5389. const previous = this._state.findPrevious;
  5390. if (numMatches) {
  5391. offset.matchIdx = previous ? numMatches - 1 : 0;
  5392. this.#updateMatch(true);
  5393. return true;
  5394. }
  5395. this.#advanceOffsetPage(previous);
  5396. if (offset.wrapped) {
  5397. offset.matchIdx = null;
  5398. if (this._pagesToSearch < 0) {
  5399. this.#updateMatch(false);
  5400. return true;
  5401. }
  5402. }
  5403. return false;
  5404. }
  5405. #nextPageMatch() {
  5406. if (this._resumePageIdx !== null) {
  5407. console.error("There can only be one pending page.");
  5408. }
  5409. let matches = null;
  5410. do {
  5411. const pageIdx = this._offset.pageIdx;
  5412. matches = this._pageMatches[pageIdx];
  5413. if (!matches) {
  5414. this._resumePageIdx = pageIdx;
  5415. break;
  5416. }
  5417. } while (!this.#matchesReady(matches));
  5418. }
  5419. #advanceOffsetPage(previous) {
  5420. const offset = this._offset;
  5421. const numPages = this._linkService.pagesCount;
  5422. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5423. offset.matchIdx = null;
  5424. this._pagesToSearch--;
  5425. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5426. offset.pageIdx = previous ? numPages - 1 : 0;
  5427. offset.wrapped = true;
  5428. }
  5429. }
  5430. #updateMatch(found = false) {
  5431. let state = FindState.NOT_FOUND;
  5432. const wrapped = this._offset.wrapped;
  5433. this._offset.wrapped = false;
  5434. if (found) {
  5435. const previousPage = this._selected.pageIdx;
  5436. this._selected.pageIdx = this._offset.pageIdx;
  5437. this._selected.matchIdx = this._offset.matchIdx;
  5438. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5439. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5440. this.#updatePage(previousPage);
  5441. }
  5442. }
  5443. this.#updateUIState(state, this._state.findPrevious);
  5444. if (this._selected.pageIdx !== -1) {
  5445. this._scrollMatches = true;
  5446. this.#updatePage(this._selected.pageIdx);
  5447. }
  5448. }
  5449. #onFindBarClose(evt) {
  5450. const pdfDocument = this._pdfDocument;
  5451. this._firstPageCapability.promise.then(() => {
  5452. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5453. return;
  5454. }
  5455. if (this._findTimeout) {
  5456. clearTimeout(this._findTimeout);
  5457. this._findTimeout = null;
  5458. }
  5459. if (this._resumePageIdx) {
  5460. this._resumePageIdx = null;
  5461. this._dirtyMatch = true;
  5462. }
  5463. this.#updateUIState(FindState.FOUND);
  5464. this._highlightMatches = false;
  5465. this.#updateAllPages();
  5466. });
  5467. }
  5468. #requestMatchesCount() {
  5469. const {
  5470. pageIdx,
  5471. matchIdx
  5472. } = this._selected;
  5473. let current = 0,
  5474. total = this._matchesCountTotal;
  5475. if (matchIdx !== -1) {
  5476. for (let i = 0; i < pageIdx; i++) {
  5477. current += this._pageMatches[i]?.length || 0;
  5478. }
  5479. current += matchIdx + 1;
  5480. }
  5481. if (current < 1 || current > total) {
  5482. current = total = 0;
  5483. }
  5484. return {
  5485. current,
  5486. total
  5487. };
  5488. }
  5489. #updateUIResultsCount() {
  5490. this._eventBus.dispatch("updatefindmatchescount", {
  5491. source: this,
  5492. matchesCount: this.#requestMatchesCount()
  5493. });
  5494. }
  5495. #updateUIState(state, previous = false) {
  5496. if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) {
  5497. return;
  5498. }
  5499. this._eventBus.dispatch("updatefindcontrolstate", {
  5500. source: this,
  5501. state,
  5502. previous,
  5503. matchesCount: this.#requestMatchesCount(),
  5504. rawQuery: this._state?.query ?? null
  5505. });
  5506. }
  5507. }
  5508. exports.PDFFindController = PDFFindController;
  5509. /***/ }),
  5510. /* 17 */
  5511. /***/ ((__unused_webpack_module, exports) => {
  5512. Object.defineProperty(exports, "__esModule", ({
  5513. value: true
  5514. }));
  5515. exports.CharacterType = void 0;
  5516. exports.getCharacterType = getCharacterType;
  5517. const CharacterType = {
  5518. SPACE: 0,
  5519. ALPHA_LETTER: 1,
  5520. PUNCT: 2,
  5521. HAN_LETTER: 3,
  5522. KATAKANA_LETTER: 4,
  5523. HIRAGANA_LETTER: 5,
  5524. HALFWIDTH_KATAKANA_LETTER: 6,
  5525. THAI_LETTER: 7
  5526. };
  5527. exports.CharacterType = CharacterType;
  5528. function isAlphabeticalScript(charCode) {
  5529. return charCode < 0x2e80;
  5530. }
  5531. function isAscii(charCode) {
  5532. return (charCode & 0xff80) === 0;
  5533. }
  5534. function isAsciiAlpha(charCode) {
  5535. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5536. }
  5537. function isAsciiDigit(charCode) {
  5538. return charCode >= 0x30 && charCode <= 0x39;
  5539. }
  5540. function isAsciiSpace(charCode) {
  5541. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5542. }
  5543. function isHan(charCode) {
  5544. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5545. }
  5546. function isKatakana(charCode) {
  5547. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5548. }
  5549. function isHiragana(charCode) {
  5550. return charCode >= 0x3040 && charCode <= 0x309f;
  5551. }
  5552. function isHalfwidthKatakana(charCode) {
  5553. return charCode >= 0xff60 && charCode <= 0xff9f;
  5554. }
  5555. function isThai(charCode) {
  5556. return (charCode & 0xff80) === 0x0e00;
  5557. }
  5558. function getCharacterType(charCode) {
  5559. if (isAlphabeticalScript(charCode)) {
  5560. if (isAscii(charCode)) {
  5561. if (isAsciiSpace(charCode)) {
  5562. return CharacterType.SPACE;
  5563. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5564. return CharacterType.ALPHA_LETTER;
  5565. }
  5566. return CharacterType.PUNCT;
  5567. } else if (isThai(charCode)) {
  5568. return CharacterType.THAI_LETTER;
  5569. } else if (charCode === 0xa0) {
  5570. return CharacterType.SPACE;
  5571. }
  5572. return CharacterType.ALPHA_LETTER;
  5573. }
  5574. if (isHan(charCode)) {
  5575. return CharacterType.HAN_LETTER;
  5576. } else if (isKatakana(charCode)) {
  5577. return CharacterType.KATAKANA_LETTER;
  5578. } else if (isHiragana(charCode)) {
  5579. return CharacterType.HIRAGANA_LETTER;
  5580. } else if (isHalfwidthKatakana(charCode)) {
  5581. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5582. }
  5583. return CharacterType.ALPHA_LETTER;
  5584. }
  5585. /***/ }),
  5586. /* 18 */
  5587. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5588. Object.defineProperty(exports, "__esModule", ({
  5589. value: true
  5590. }));
  5591. exports.PDFHistory = void 0;
  5592. exports.isDestArraysEqual = isDestArraysEqual;
  5593. exports.isDestHashesEqual = isDestHashesEqual;
  5594. var _ui_utils = __webpack_require__(1);
  5595. var _event_utils = __webpack_require__(6);
  5596. const HASH_CHANGE_TIMEOUT = 1000;
  5597. const POSITION_UPDATED_THRESHOLD = 50;
  5598. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5599. function getCurrentHash() {
  5600. return document.location.hash;
  5601. }
  5602. class PDFHistory {
  5603. constructor({
  5604. linkService,
  5605. eventBus
  5606. }) {
  5607. this.linkService = linkService;
  5608. this.eventBus = eventBus;
  5609. this._initialized = false;
  5610. this._fingerprint = "";
  5611. this.reset();
  5612. this._boundEvents = null;
  5613. this.eventBus._on("pagesinit", () => {
  5614. this._isPagesLoaded = false;
  5615. this.eventBus._on("pagesloaded", evt => {
  5616. this._isPagesLoaded = !!evt.pagesCount;
  5617. }, {
  5618. once: true
  5619. });
  5620. });
  5621. }
  5622. initialize({
  5623. fingerprint,
  5624. resetHistory = false,
  5625. updateUrl = false
  5626. }) {
  5627. if (!fingerprint || typeof fingerprint !== "string") {
  5628. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5629. return;
  5630. }
  5631. if (this._initialized) {
  5632. this.reset();
  5633. }
  5634. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5635. this._fingerprint = fingerprint;
  5636. this._updateUrl = updateUrl === true;
  5637. this._initialized = true;
  5638. this._bindEvents();
  5639. const state = window.history.state;
  5640. this._popStateInProgress = false;
  5641. this._blockHashChange = 0;
  5642. this._currentHash = getCurrentHash();
  5643. this._numPositionUpdates = 0;
  5644. this._uid = this._maxUid = 0;
  5645. this._destination = null;
  5646. this._position = null;
  5647. if (!this._isValidState(state, true) || resetHistory) {
  5648. const {
  5649. hash,
  5650. page,
  5651. rotation
  5652. } = this._parseCurrentHash(true);
  5653. if (!hash || reInitialized || resetHistory) {
  5654. this._pushOrReplaceState(null, true);
  5655. return;
  5656. }
  5657. this._pushOrReplaceState({
  5658. hash,
  5659. page,
  5660. rotation
  5661. }, true);
  5662. return;
  5663. }
  5664. const destination = state.destination;
  5665. this._updateInternalState(destination, state.uid, true);
  5666. if (destination.rotation !== undefined) {
  5667. this._initialRotation = destination.rotation;
  5668. }
  5669. if (destination.dest) {
  5670. this._initialBookmark = JSON.stringify(destination.dest);
  5671. this._destination.page = null;
  5672. } else if (destination.hash) {
  5673. this._initialBookmark = destination.hash;
  5674. } else if (destination.page) {
  5675. this._initialBookmark = `page=${destination.page}`;
  5676. }
  5677. }
  5678. reset() {
  5679. if (this._initialized) {
  5680. this._pageHide();
  5681. this._initialized = false;
  5682. this._unbindEvents();
  5683. }
  5684. if (this._updateViewareaTimeout) {
  5685. clearTimeout(this._updateViewareaTimeout);
  5686. this._updateViewareaTimeout = null;
  5687. }
  5688. this._initialBookmark = null;
  5689. this._initialRotation = null;
  5690. }
  5691. push({
  5692. namedDest = null,
  5693. explicitDest,
  5694. pageNumber
  5695. }) {
  5696. if (!this._initialized) {
  5697. return;
  5698. }
  5699. if (namedDest && typeof namedDest !== "string") {
  5700. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5701. return;
  5702. } else if (!Array.isArray(explicitDest)) {
  5703. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5704. return;
  5705. } else if (!this._isValidPage(pageNumber)) {
  5706. if (pageNumber !== null || this._destination) {
  5707. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5708. return;
  5709. }
  5710. }
  5711. const hash = namedDest || JSON.stringify(explicitDest);
  5712. if (!hash) {
  5713. return;
  5714. }
  5715. let forceReplace = false;
  5716. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5717. if (this._destination.page) {
  5718. return;
  5719. }
  5720. forceReplace = true;
  5721. }
  5722. if (this._popStateInProgress && !forceReplace) {
  5723. return;
  5724. }
  5725. this._pushOrReplaceState({
  5726. dest: explicitDest,
  5727. hash,
  5728. page: pageNumber,
  5729. rotation: this.linkService.rotation
  5730. }, forceReplace);
  5731. if (!this._popStateInProgress) {
  5732. this._popStateInProgress = true;
  5733. Promise.resolve().then(() => {
  5734. this._popStateInProgress = false;
  5735. });
  5736. }
  5737. }
  5738. pushPage(pageNumber) {
  5739. if (!this._initialized) {
  5740. return;
  5741. }
  5742. if (!this._isValidPage(pageNumber)) {
  5743. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5744. return;
  5745. }
  5746. if (this._destination?.page === pageNumber) {
  5747. return;
  5748. }
  5749. if (this._popStateInProgress) {
  5750. return;
  5751. }
  5752. this._pushOrReplaceState({
  5753. dest: null,
  5754. hash: `page=${pageNumber}`,
  5755. page: pageNumber,
  5756. rotation: this.linkService.rotation
  5757. });
  5758. if (!this._popStateInProgress) {
  5759. this._popStateInProgress = true;
  5760. Promise.resolve().then(() => {
  5761. this._popStateInProgress = false;
  5762. });
  5763. }
  5764. }
  5765. pushCurrentPosition() {
  5766. if (!this._initialized || this._popStateInProgress) {
  5767. return;
  5768. }
  5769. this._tryPushCurrentPosition();
  5770. }
  5771. back() {
  5772. if (!this._initialized || this._popStateInProgress) {
  5773. return;
  5774. }
  5775. const state = window.history.state;
  5776. if (this._isValidState(state) && state.uid > 0) {
  5777. window.history.back();
  5778. }
  5779. }
  5780. forward() {
  5781. if (!this._initialized || this._popStateInProgress) {
  5782. return;
  5783. }
  5784. const state = window.history.state;
  5785. if (this._isValidState(state) && state.uid < this._maxUid) {
  5786. window.history.forward();
  5787. }
  5788. }
  5789. get popStateInProgress() {
  5790. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5791. }
  5792. get initialBookmark() {
  5793. return this._initialized ? this._initialBookmark : null;
  5794. }
  5795. get initialRotation() {
  5796. return this._initialized ? this._initialRotation : null;
  5797. }
  5798. _pushOrReplaceState(destination, forceReplace = false) {
  5799. const shouldReplace = forceReplace || !this._destination;
  5800. const newState = {
  5801. fingerprint: this._fingerprint,
  5802. uid: shouldReplace ? this._uid : this._uid + 1,
  5803. destination
  5804. };
  5805. this._updateInternalState(destination, newState.uid);
  5806. let newUrl;
  5807. if (this._updateUrl && destination?.hash) {
  5808. const baseUrl = document.location.href.split("#")[0];
  5809. if (!baseUrl.startsWith("file://")) {
  5810. newUrl = `${baseUrl}#${destination.hash}`;
  5811. }
  5812. }
  5813. if (shouldReplace) {
  5814. window.history.replaceState(newState, "", newUrl);
  5815. } else {
  5816. window.history.pushState(newState, "", newUrl);
  5817. }
  5818. }
  5819. _tryPushCurrentPosition(temporary = false) {
  5820. if (!this._position) {
  5821. return;
  5822. }
  5823. let position = this._position;
  5824. if (temporary) {
  5825. position = Object.assign(Object.create(null), this._position);
  5826. position.temporary = true;
  5827. }
  5828. if (!this._destination) {
  5829. this._pushOrReplaceState(position);
  5830. return;
  5831. }
  5832. if (this._destination.temporary) {
  5833. this._pushOrReplaceState(position, true);
  5834. return;
  5835. }
  5836. if (this._destination.hash === position.hash) {
  5837. return;
  5838. }
  5839. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5840. return;
  5841. }
  5842. let forceReplace = false;
  5843. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5844. if (this._destination.dest !== undefined || !this._destination.first) {
  5845. return;
  5846. }
  5847. forceReplace = true;
  5848. }
  5849. this._pushOrReplaceState(position, forceReplace);
  5850. }
  5851. _isValidPage(val) {
  5852. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5853. }
  5854. _isValidState(state, checkReload = false) {
  5855. if (!state) {
  5856. return false;
  5857. }
  5858. if (state.fingerprint !== this._fingerprint) {
  5859. if (checkReload) {
  5860. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5861. return false;
  5862. }
  5863. const [perfEntry] = performance.getEntriesByType("navigation");
  5864. if (perfEntry?.type !== "reload") {
  5865. return false;
  5866. }
  5867. } else {
  5868. return false;
  5869. }
  5870. }
  5871. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5872. return false;
  5873. }
  5874. if (state.destination === null || typeof state.destination !== "object") {
  5875. return false;
  5876. }
  5877. return true;
  5878. }
  5879. _updateInternalState(destination, uid, removeTemporary = false) {
  5880. if (this._updateViewareaTimeout) {
  5881. clearTimeout(this._updateViewareaTimeout);
  5882. this._updateViewareaTimeout = null;
  5883. }
  5884. if (removeTemporary && destination?.temporary) {
  5885. delete destination.temporary;
  5886. }
  5887. this._destination = destination;
  5888. this._uid = uid;
  5889. this._maxUid = Math.max(this._maxUid, uid);
  5890. this._numPositionUpdates = 0;
  5891. }
  5892. _parseCurrentHash(checkNameddest = false) {
  5893. const hash = unescape(getCurrentHash()).substring(1);
  5894. const params = (0, _ui_utils.parseQueryString)(hash);
  5895. const nameddest = params.get("nameddest") || "";
  5896. let page = params.get("page") | 0;
  5897. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5898. page = null;
  5899. }
  5900. return {
  5901. hash,
  5902. page,
  5903. rotation: this.linkService.rotation
  5904. };
  5905. }
  5906. _updateViewarea({
  5907. location
  5908. }) {
  5909. if (this._updateViewareaTimeout) {
  5910. clearTimeout(this._updateViewareaTimeout);
  5911. this._updateViewareaTimeout = null;
  5912. }
  5913. this._position = {
  5914. hash: location.pdfOpenParams.substring(1),
  5915. page: this.linkService.page,
  5916. first: location.pageNumber,
  5917. rotation: location.rotation
  5918. };
  5919. if (this._popStateInProgress) {
  5920. return;
  5921. }
  5922. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5923. this._numPositionUpdates++;
  5924. }
  5925. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5926. this._updateViewareaTimeout = setTimeout(() => {
  5927. if (!this._popStateInProgress) {
  5928. this._tryPushCurrentPosition(true);
  5929. }
  5930. this._updateViewareaTimeout = null;
  5931. }, UPDATE_VIEWAREA_TIMEOUT);
  5932. }
  5933. }
  5934. _popState({
  5935. state
  5936. }) {
  5937. const newHash = getCurrentHash(),
  5938. hashChanged = this._currentHash !== newHash;
  5939. this._currentHash = newHash;
  5940. if (!state) {
  5941. this._uid++;
  5942. const {
  5943. hash,
  5944. page,
  5945. rotation
  5946. } = this._parseCurrentHash();
  5947. this._pushOrReplaceState({
  5948. hash,
  5949. page,
  5950. rotation
  5951. }, true);
  5952. return;
  5953. }
  5954. if (!this._isValidState(state)) {
  5955. return;
  5956. }
  5957. this._popStateInProgress = true;
  5958. if (hashChanged) {
  5959. this._blockHashChange++;
  5960. (0, _event_utils.waitOnEventOrTimeout)({
  5961. target: window,
  5962. name: "hashchange",
  5963. delay: HASH_CHANGE_TIMEOUT
  5964. }).then(() => {
  5965. this._blockHashChange--;
  5966. });
  5967. }
  5968. const destination = state.destination;
  5969. this._updateInternalState(destination, state.uid, true);
  5970. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5971. this.linkService.rotation = destination.rotation;
  5972. }
  5973. if (destination.dest) {
  5974. this.linkService.goToDestination(destination.dest);
  5975. } else if (destination.hash) {
  5976. this.linkService.setHash(destination.hash);
  5977. } else if (destination.page) {
  5978. this.linkService.page = destination.page;
  5979. }
  5980. Promise.resolve().then(() => {
  5981. this._popStateInProgress = false;
  5982. });
  5983. }
  5984. _pageHide() {
  5985. if (!this._destination || this._destination.temporary) {
  5986. this._tryPushCurrentPosition();
  5987. }
  5988. }
  5989. _bindEvents() {
  5990. if (this._boundEvents) {
  5991. return;
  5992. }
  5993. this._boundEvents = {
  5994. updateViewarea: this._updateViewarea.bind(this),
  5995. popState: this._popState.bind(this),
  5996. pageHide: this._pageHide.bind(this)
  5997. };
  5998. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5999. window.addEventListener("popstate", this._boundEvents.popState);
  6000. window.addEventListener("pagehide", this._boundEvents.pageHide);
  6001. }
  6002. _unbindEvents() {
  6003. if (!this._boundEvents) {
  6004. return;
  6005. }
  6006. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  6007. window.removeEventListener("popstate", this._boundEvents.popState);
  6008. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  6009. this._boundEvents = null;
  6010. }
  6011. }
  6012. exports.PDFHistory = PDFHistory;
  6013. function isDestHashesEqual(destHash, pushHash) {
  6014. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  6015. return false;
  6016. }
  6017. if (destHash === pushHash) {
  6018. return true;
  6019. }
  6020. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  6021. if (nameddest === pushHash) {
  6022. return true;
  6023. }
  6024. return false;
  6025. }
  6026. function isDestArraysEqual(firstDest, secondDest) {
  6027. function isEntryEqual(first, second) {
  6028. if (typeof first !== typeof second) {
  6029. return false;
  6030. }
  6031. if (Array.isArray(first) || Array.isArray(second)) {
  6032. return false;
  6033. }
  6034. if (first !== null && typeof first === "object" && second !== null) {
  6035. if (Object.keys(first).length !== Object.keys(second).length) {
  6036. return false;
  6037. }
  6038. for (const key in first) {
  6039. if (!isEntryEqual(first[key], second[key])) {
  6040. return false;
  6041. }
  6042. }
  6043. return true;
  6044. }
  6045. return first === second || Number.isNaN(first) && Number.isNaN(second);
  6046. }
  6047. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  6048. return false;
  6049. }
  6050. if (firstDest.length !== secondDest.length) {
  6051. return false;
  6052. }
  6053. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  6054. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  6055. return false;
  6056. }
  6057. }
  6058. return true;
  6059. }
  6060. /***/ }),
  6061. /* 19 */
  6062. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6063. Object.defineProperty(exports, "__esModule", ({
  6064. value: true
  6065. }));
  6066. exports.PDFLayerViewer = void 0;
  6067. var _base_tree_viewer = __webpack_require__(13);
  6068. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  6069. constructor(options) {
  6070. super(options);
  6071. this.l10n = options.l10n;
  6072. this.eventBus._on("optionalcontentconfigchanged", evt => {
  6073. this.#updateLayers(evt.promise);
  6074. });
  6075. this.eventBus._on("resetlayers", () => {
  6076. this.#updateLayers();
  6077. });
  6078. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  6079. }
  6080. reset() {
  6081. super.reset();
  6082. this._optionalContentConfig = null;
  6083. this._optionalContentHash = null;
  6084. }
  6085. _dispatchEvent(layersCount) {
  6086. this.eventBus.dispatch("layersloaded", {
  6087. source: this,
  6088. layersCount
  6089. });
  6090. }
  6091. _bindLink(element, {
  6092. groupId,
  6093. input
  6094. }) {
  6095. const setVisibility = () => {
  6096. this._optionalContentConfig.setVisibility(groupId, input.checked);
  6097. this._optionalContentHash = this._optionalContentConfig.getHash();
  6098. this.eventBus.dispatch("optionalcontentconfig", {
  6099. source: this,
  6100. promise: Promise.resolve(this._optionalContentConfig)
  6101. });
  6102. };
  6103. element.onclick = evt => {
  6104. if (evt.target === input) {
  6105. setVisibility();
  6106. return true;
  6107. } else if (evt.target !== element) {
  6108. return true;
  6109. }
  6110. input.checked = !input.checked;
  6111. setVisibility();
  6112. return false;
  6113. };
  6114. }
  6115. async _setNestedName(element, {
  6116. name = null
  6117. }) {
  6118. if (typeof name === "string") {
  6119. element.textContent = this._normalizeTextContent(name);
  6120. return;
  6121. }
  6122. element.textContent = await this.l10n.get("additional_layers");
  6123. element.style.fontStyle = "italic";
  6124. }
  6125. _addToggleButton(div, {
  6126. name = null
  6127. }) {
  6128. super._addToggleButton(div, name === null);
  6129. }
  6130. _toggleAllTreeItems() {
  6131. if (!this._optionalContentConfig) {
  6132. return;
  6133. }
  6134. super._toggleAllTreeItems();
  6135. }
  6136. render({
  6137. optionalContentConfig,
  6138. pdfDocument
  6139. }) {
  6140. if (this._optionalContentConfig) {
  6141. this.reset();
  6142. }
  6143. this._optionalContentConfig = optionalContentConfig || null;
  6144. this._pdfDocument = pdfDocument || null;
  6145. const groups = optionalContentConfig?.getOrder();
  6146. if (!groups) {
  6147. this._dispatchEvent(0);
  6148. return;
  6149. }
  6150. this._optionalContentHash = optionalContentConfig.getHash();
  6151. const fragment = document.createDocumentFragment(),
  6152. queue = [{
  6153. parent: fragment,
  6154. groups
  6155. }];
  6156. let layersCount = 0,
  6157. hasAnyNesting = false;
  6158. while (queue.length > 0) {
  6159. const levelData = queue.shift();
  6160. for (const groupId of levelData.groups) {
  6161. const div = document.createElement("div");
  6162. div.className = "treeItem";
  6163. const element = document.createElement("a");
  6164. div.append(element);
  6165. if (typeof groupId === "object") {
  6166. hasAnyNesting = true;
  6167. this._addToggleButton(div, groupId);
  6168. this._setNestedName(element, groupId);
  6169. const itemsDiv = document.createElement("div");
  6170. itemsDiv.className = "treeItems";
  6171. div.append(itemsDiv);
  6172. queue.push({
  6173. parent: itemsDiv,
  6174. groups: groupId.order
  6175. });
  6176. } else {
  6177. const group = optionalContentConfig.getGroup(groupId);
  6178. const input = document.createElement("input");
  6179. this._bindLink(element, {
  6180. groupId,
  6181. input
  6182. });
  6183. input.type = "checkbox";
  6184. input.checked = group.visible;
  6185. const label = document.createElement("label");
  6186. label.textContent = this._normalizeTextContent(group.name);
  6187. label.append(input);
  6188. element.append(label);
  6189. layersCount++;
  6190. }
  6191. levelData.parent.append(div);
  6192. }
  6193. }
  6194. this._finishRendering(fragment, layersCount, hasAnyNesting);
  6195. }
  6196. async #updateLayers(promise = null) {
  6197. if (!this._optionalContentConfig) {
  6198. return;
  6199. }
  6200. const pdfDocument = this._pdfDocument;
  6201. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig());
  6202. if (pdfDocument !== this._pdfDocument) {
  6203. return;
  6204. }
  6205. if (promise) {
  6206. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  6207. return;
  6208. }
  6209. } else {
  6210. this.eventBus.dispatch("optionalcontentconfig", {
  6211. source: this,
  6212. promise: Promise.resolve(optionalContentConfig)
  6213. });
  6214. }
  6215. this.render({
  6216. optionalContentConfig,
  6217. pdfDocument: this._pdfDocument
  6218. });
  6219. }
  6220. }
  6221. exports.PDFLayerViewer = PDFLayerViewer;
  6222. /***/ }),
  6223. /* 20 */
  6224. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6225. Object.defineProperty(exports, "__esModule", ({
  6226. value: true
  6227. }));
  6228. exports.PDFOutlineViewer = void 0;
  6229. var _base_tree_viewer = __webpack_require__(13);
  6230. var _pdfjsLib = __webpack_require__(5);
  6231. var _ui_utils = __webpack_require__(1);
  6232. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  6233. constructor(options) {
  6234. super(options);
  6235. this.linkService = options.linkService;
  6236. this.downloadManager = options.downloadManager;
  6237. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6238. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6239. this.eventBus._on("pagechanging", evt => {
  6240. this._currentPageNumber = evt.pageNumber;
  6241. });
  6242. this.eventBus._on("pagesloaded", evt => {
  6243. this._isPagesLoaded = !!evt.pagesCount;
  6244. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6245. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6246. }
  6247. });
  6248. this.eventBus._on("sidebarviewchanged", evt => {
  6249. this._sidebarView = evt.view;
  6250. });
  6251. }
  6252. reset() {
  6253. super.reset();
  6254. this._outline = null;
  6255. this._pageNumberToDestHashCapability = null;
  6256. this._currentPageNumber = 1;
  6257. this._isPagesLoaded = null;
  6258. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6259. this._currentOutlineItemCapability.resolve(false);
  6260. }
  6261. this._currentOutlineItemCapability = null;
  6262. }
  6263. _dispatchEvent(outlineCount) {
  6264. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  6265. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  6266. this._currentOutlineItemCapability.resolve(false);
  6267. } else if (this._isPagesLoaded !== null) {
  6268. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6269. }
  6270. this.eventBus.dispatch("outlineloaded", {
  6271. source: this,
  6272. outlineCount,
  6273. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6274. });
  6275. }
  6276. _bindLink(element, {
  6277. url,
  6278. newWindow,
  6279. action,
  6280. attachment,
  6281. dest,
  6282. setOCGState
  6283. }) {
  6284. const {
  6285. linkService
  6286. } = this;
  6287. if (url) {
  6288. linkService.addLinkAttributes(element, url, newWindow);
  6289. return;
  6290. }
  6291. if (action) {
  6292. element.href = linkService.getAnchorUrl("");
  6293. element.onclick = () => {
  6294. linkService.executeNamedAction(action);
  6295. return false;
  6296. };
  6297. return;
  6298. }
  6299. if (attachment) {
  6300. element.href = linkService.getAnchorUrl("");
  6301. element.onclick = () => {
  6302. this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename);
  6303. return false;
  6304. };
  6305. return;
  6306. }
  6307. if (setOCGState) {
  6308. element.href = linkService.getAnchorUrl("");
  6309. element.onclick = () => {
  6310. linkService.executeSetOCGState(setOCGState);
  6311. return false;
  6312. };
  6313. return;
  6314. }
  6315. element.href = linkService.getDestinationHash(dest);
  6316. element.onclick = evt => {
  6317. this._updateCurrentTreeItem(evt.target.parentNode);
  6318. if (dest) {
  6319. linkService.goToDestination(dest);
  6320. }
  6321. return false;
  6322. };
  6323. }
  6324. _setStyles(element, {
  6325. bold,
  6326. italic
  6327. }) {
  6328. if (bold) {
  6329. element.style.fontWeight = "bold";
  6330. }
  6331. if (italic) {
  6332. element.style.fontStyle = "italic";
  6333. }
  6334. }
  6335. _addToggleButton(div, {
  6336. count,
  6337. items
  6338. }) {
  6339. let hidden = false;
  6340. if (count < 0) {
  6341. let totalCount = items.length;
  6342. if (totalCount > 0) {
  6343. const queue = [...items];
  6344. while (queue.length > 0) {
  6345. const {
  6346. count: nestedCount,
  6347. items: nestedItems
  6348. } = queue.shift();
  6349. if (nestedCount > 0 && nestedItems.length > 0) {
  6350. totalCount += nestedItems.length;
  6351. queue.push(...nestedItems);
  6352. }
  6353. }
  6354. }
  6355. if (Math.abs(count) === totalCount) {
  6356. hidden = true;
  6357. }
  6358. }
  6359. super._addToggleButton(div, hidden);
  6360. }
  6361. _toggleAllTreeItems() {
  6362. if (!this._outline) {
  6363. return;
  6364. }
  6365. super._toggleAllTreeItems();
  6366. }
  6367. render({
  6368. outline,
  6369. pdfDocument
  6370. }) {
  6371. if (this._outline) {
  6372. this.reset();
  6373. }
  6374. this._outline = outline || null;
  6375. this._pdfDocument = pdfDocument || null;
  6376. if (!outline) {
  6377. this._dispatchEvent(0);
  6378. return;
  6379. }
  6380. const fragment = document.createDocumentFragment();
  6381. const queue = [{
  6382. parent: fragment,
  6383. items: outline
  6384. }];
  6385. let outlineCount = 0,
  6386. hasAnyNesting = false;
  6387. while (queue.length > 0) {
  6388. const levelData = queue.shift();
  6389. for (const item of levelData.items) {
  6390. const div = document.createElement("div");
  6391. div.className = "treeItem";
  6392. const element = document.createElement("a");
  6393. this._bindLink(element, item);
  6394. this._setStyles(element, item);
  6395. element.textContent = this._normalizeTextContent(item.title);
  6396. div.append(element);
  6397. if (item.items.length > 0) {
  6398. hasAnyNesting = true;
  6399. this._addToggleButton(div, item);
  6400. const itemsDiv = document.createElement("div");
  6401. itemsDiv.className = "treeItems";
  6402. div.append(itemsDiv);
  6403. queue.push({
  6404. parent: itemsDiv,
  6405. items: item.items
  6406. });
  6407. }
  6408. levelData.parent.append(div);
  6409. outlineCount++;
  6410. }
  6411. }
  6412. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6413. }
  6414. async _currentOutlineItem() {
  6415. if (!this._isPagesLoaded) {
  6416. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6417. }
  6418. if (!this._outline || !this._pdfDocument) {
  6419. return;
  6420. }
  6421. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6422. if (!pageNumberToDestHash) {
  6423. return;
  6424. }
  6425. this._updateCurrentTreeItem(null);
  6426. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6427. return;
  6428. }
  6429. for (let i = this._currentPageNumber; i > 0; i--) {
  6430. const destHash = pageNumberToDestHash.get(i);
  6431. if (!destHash) {
  6432. continue;
  6433. }
  6434. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6435. if (!linkElement) {
  6436. continue;
  6437. }
  6438. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6439. break;
  6440. }
  6441. }
  6442. async _getPageNumberToDestHash(pdfDocument) {
  6443. if (this._pageNumberToDestHashCapability) {
  6444. return this._pageNumberToDestHashCapability.promise;
  6445. }
  6446. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6447. const pageNumberToDestHash = new Map(),
  6448. pageNumberNesting = new Map();
  6449. const queue = [{
  6450. nesting: 0,
  6451. items: this._outline
  6452. }];
  6453. while (queue.length > 0) {
  6454. const levelData = queue.shift(),
  6455. currentNesting = levelData.nesting;
  6456. for (const {
  6457. dest,
  6458. items
  6459. } of levelData.items) {
  6460. let explicitDest, pageNumber;
  6461. if (typeof dest === "string") {
  6462. explicitDest = await pdfDocument.getDestination(dest);
  6463. if (pdfDocument !== this._pdfDocument) {
  6464. return null;
  6465. }
  6466. } else {
  6467. explicitDest = dest;
  6468. }
  6469. if (Array.isArray(explicitDest)) {
  6470. const [destRef] = explicitDest;
  6471. if (typeof destRef === "object" && destRef !== null) {
  6472. pageNumber = this.linkService._cachedPageNumber(destRef);
  6473. if (!pageNumber) {
  6474. try {
  6475. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6476. if (pdfDocument !== this._pdfDocument) {
  6477. return null;
  6478. }
  6479. this.linkService.cachePageRef(pageNumber, destRef);
  6480. } catch (ex) {}
  6481. }
  6482. } else if (Number.isInteger(destRef)) {
  6483. pageNumber = destRef + 1;
  6484. }
  6485. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6486. const destHash = this.linkService.getDestinationHash(dest);
  6487. pageNumberToDestHash.set(pageNumber, destHash);
  6488. pageNumberNesting.set(pageNumber, currentNesting);
  6489. }
  6490. }
  6491. if (items.length > 0) {
  6492. queue.push({
  6493. nesting: currentNesting + 1,
  6494. items
  6495. });
  6496. }
  6497. }
  6498. }
  6499. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6500. return this._pageNumberToDestHashCapability.promise;
  6501. }
  6502. }
  6503. exports.PDFOutlineViewer = PDFOutlineViewer;
  6504. /***/ }),
  6505. /* 21 */
  6506. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6507. Object.defineProperty(exports, "__esModule", ({
  6508. value: true
  6509. }));
  6510. exports.PDFPresentationMode = void 0;
  6511. var _ui_utils = __webpack_require__(1);
  6512. var _pdfjsLib = __webpack_require__(5);
  6513. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6514. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6515. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6516. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6517. const PAGE_SWITCH_THRESHOLD = 0.1;
  6518. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6519. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6520. class PDFPresentationMode {
  6521. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6522. #args = null;
  6523. constructor({
  6524. container,
  6525. pdfViewer,
  6526. eventBus
  6527. }) {
  6528. this.container = container;
  6529. this.pdfViewer = pdfViewer;
  6530. this.eventBus = eventBus;
  6531. this.contextMenuOpen = false;
  6532. this.mouseScrollTimeStamp = 0;
  6533. this.mouseScrollDelta = 0;
  6534. this.touchSwipeState = null;
  6535. }
  6536. async request() {
  6537. const {
  6538. container,
  6539. pdfViewer
  6540. } = this;
  6541. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6542. return false;
  6543. }
  6544. this.#addFullscreenChangeListeners();
  6545. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6546. const promise = container.requestFullscreen();
  6547. this.#args = {
  6548. pageNumber: pdfViewer.currentPageNumber,
  6549. scaleValue: pdfViewer.currentScaleValue,
  6550. scrollMode: pdfViewer.scrollMode,
  6551. spreadMode: null,
  6552. annotationEditorMode: null
  6553. };
  6554. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6555. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6556. this.#args.spreadMode = pdfViewer.spreadMode;
  6557. }
  6558. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6559. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6560. }
  6561. try {
  6562. await promise;
  6563. pdfViewer.focus();
  6564. return true;
  6565. } catch (reason) {
  6566. this.#removeFullscreenChangeListeners();
  6567. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6568. }
  6569. return false;
  6570. }
  6571. get active() {
  6572. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6573. }
  6574. #mouseWheel(evt) {
  6575. if (!this.active) {
  6576. return;
  6577. }
  6578. evt.preventDefault();
  6579. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6580. const currentTime = Date.now();
  6581. const storedTime = this.mouseScrollTimeStamp;
  6582. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6583. return;
  6584. }
  6585. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6586. this.#resetMouseScrollState();
  6587. }
  6588. this.mouseScrollDelta += delta;
  6589. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6590. const totalDelta = this.mouseScrollDelta;
  6591. this.#resetMouseScrollState();
  6592. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6593. if (success) {
  6594. this.mouseScrollTimeStamp = currentTime;
  6595. }
  6596. }
  6597. }
  6598. #notifyStateChange(state) {
  6599. this.#state = state;
  6600. this.eventBus.dispatch("presentationmodechanged", {
  6601. source: this,
  6602. state
  6603. });
  6604. }
  6605. #enter() {
  6606. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6607. this.container.classList.add(ACTIVE_SELECTOR);
  6608. setTimeout(() => {
  6609. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6610. if (this.#args.spreadMode !== null) {
  6611. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6612. }
  6613. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6614. this.pdfViewer.currentScaleValue = "page-fit";
  6615. if (this.#args.annotationEditorMode !== null) {
  6616. this.pdfViewer.annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  6617. }
  6618. }, 0);
  6619. this.#addWindowListeners();
  6620. this.#showControls();
  6621. this.contextMenuOpen = false;
  6622. window.getSelection().removeAllRanges();
  6623. }
  6624. #exit() {
  6625. const pageNumber = this.pdfViewer.currentPageNumber;
  6626. this.container.classList.remove(ACTIVE_SELECTOR);
  6627. setTimeout(() => {
  6628. this.#removeFullscreenChangeListeners();
  6629. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6630. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6631. if (this.#args.spreadMode !== null) {
  6632. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6633. }
  6634. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6635. this.pdfViewer.currentPageNumber = pageNumber;
  6636. if (this.#args.annotationEditorMode !== null) {
  6637. this.pdfViewer.annotationEditorMode = this.#args.annotationEditorMode;
  6638. }
  6639. this.#args = null;
  6640. }, 0);
  6641. this.#removeWindowListeners();
  6642. this.#hideControls();
  6643. this.#resetMouseScrollState();
  6644. this.contextMenuOpen = false;
  6645. }
  6646. #mouseDown(evt) {
  6647. if (this.contextMenuOpen) {
  6648. this.contextMenuOpen = false;
  6649. evt.preventDefault();
  6650. return;
  6651. }
  6652. if (evt.button !== 0) {
  6653. return;
  6654. }
  6655. if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) {
  6656. return;
  6657. }
  6658. evt.preventDefault();
  6659. if (evt.shiftKey) {
  6660. this.pdfViewer.previousPage();
  6661. } else {
  6662. this.pdfViewer.nextPage();
  6663. }
  6664. }
  6665. #contextMenu() {
  6666. this.contextMenuOpen = true;
  6667. }
  6668. #showControls() {
  6669. if (this.controlsTimeout) {
  6670. clearTimeout(this.controlsTimeout);
  6671. } else {
  6672. this.container.classList.add(CONTROLS_SELECTOR);
  6673. }
  6674. this.controlsTimeout = setTimeout(() => {
  6675. this.container.classList.remove(CONTROLS_SELECTOR);
  6676. delete this.controlsTimeout;
  6677. }, DELAY_BEFORE_HIDING_CONTROLS);
  6678. }
  6679. #hideControls() {
  6680. if (!this.controlsTimeout) {
  6681. return;
  6682. }
  6683. clearTimeout(this.controlsTimeout);
  6684. this.container.classList.remove(CONTROLS_SELECTOR);
  6685. delete this.controlsTimeout;
  6686. }
  6687. #resetMouseScrollState() {
  6688. this.mouseScrollTimeStamp = 0;
  6689. this.mouseScrollDelta = 0;
  6690. }
  6691. #touchSwipe(evt) {
  6692. if (!this.active) {
  6693. return;
  6694. }
  6695. if (evt.touches.length > 1) {
  6696. this.touchSwipeState = null;
  6697. return;
  6698. }
  6699. switch (evt.type) {
  6700. case "touchstart":
  6701. this.touchSwipeState = {
  6702. startX: evt.touches[0].pageX,
  6703. startY: evt.touches[0].pageY,
  6704. endX: evt.touches[0].pageX,
  6705. endY: evt.touches[0].pageY
  6706. };
  6707. break;
  6708. case "touchmove":
  6709. if (this.touchSwipeState === null) {
  6710. return;
  6711. }
  6712. this.touchSwipeState.endX = evt.touches[0].pageX;
  6713. this.touchSwipeState.endY = evt.touches[0].pageY;
  6714. evt.preventDefault();
  6715. break;
  6716. case "touchend":
  6717. if (this.touchSwipeState === null) {
  6718. return;
  6719. }
  6720. let delta = 0;
  6721. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6722. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6723. const absAngle = Math.abs(Math.atan2(dy, dx));
  6724. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6725. delta = dx;
  6726. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6727. delta = dy;
  6728. }
  6729. if (delta > 0) {
  6730. this.pdfViewer.previousPage();
  6731. } else if (delta < 0) {
  6732. this.pdfViewer.nextPage();
  6733. }
  6734. break;
  6735. }
  6736. }
  6737. #addWindowListeners() {
  6738. this.showControlsBind = this.#showControls.bind(this);
  6739. this.mouseDownBind = this.#mouseDown.bind(this);
  6740. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6741. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6742. this.contextMenuBind = this.#contextMenu.bind(this);
  6743. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6744. window.addEventListener("mousemove", this.showControlsBind);
  6745. window.addEventListener("mousedown", this.mouseDownBind);
  6746. window.addEventListener("wheel", this.mouseWheelBind, {
  6747. passive: false
  6748. });
  6749. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6750. window.addEventListener("contextmenu", this.contextMenuBind);
  6751. window.addEventListener("touchstart", this.touchSwipeBind);
  6752. window.addEventListener("touchmove", this.touchSwipeBind);
  6753. window.addEventListener("touchend", this.touchSwipeBind);
  6754. }
  6755. #removeWindowListeners() {
  6756. window.removeEventListener("mousemove", this.showControlsBind);
  6757. window.removeEventListener("mousedown", this.mouseDownBind);
  6758. window.removeEventListener("wheel", this.mouseWheelBind, {
  6759. passive: false
  6760. });
  6761. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6762. window.removeEventListener("contextmenu", this.contextMenuBind);
  6763. window.removeEventListener("touchstart", this.touchSwipeBind);
  6764. window.removeEventListener("touchmove", this.touchSwipeBind);
  6765. window.removeEventListener("touchend", this.touchSwipeBind);
  6766. delete this.showControlsBind;
  6767. delete this.mouseDownBind;
  6768. delete this.mouseWheelBind;
  6769. delete this.resetMouseScrollStateBind;
  6770. delete this.contextMenuBind;
  6771. delete this.touchSwipeBind;
  6772. }
  6773. #fullscreenChange() {
  6774. if (document.fullscreenElement) {
  6775. this.#enter();
  6776. } else {
  6777. this.#exit();
  6778. }
  6779. }
  6780. #addFullscreenChangeListeners() {
  6781. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6782. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6783. }
  6784. #removeFullscreenChangeListeners() {
  6785. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6786. delete this.fullscreenChangeBind;
  6787. }
  6788. }
  6789. exports.PDFPresentationMode = PDFPresentationMode;
  6790. /***/ }),
  6791. /* 22 */
  6792. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6793. Object.defineProperty(exports, "__esModule", ({
  6794. value: true
  6795. }));
  6796. exports.PDFRenderingQueue = void 0;
  6797. var _pdfjsLib = __webpack_require__(5);
  6798. var _ui_utils = __webpack_require__(1);
  6799. const CLEANUP_TIMEOUT = 30000;
  6800. class PDFRenderingQueue {
  6801. constructor() {
  6802. this.pdfViewer = null;
  6803. this.pdfThumbnailViewer = null;
  6804. this.onIdle = null;
  6805. this.highestPriorityPage = null;
  6806. this.idleTimeout = null;
  6807. this.printing = false;
  6808. this.isThumbnailViewEnabled = false;
  6809. }
  6810. setViewer(pdfViewer) {
  6811. this.pdfViewer = pdfViewer;
  6812. }
  6813. setThumbnailViewer(pdfThumbnailViewer) {
  6814. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6815. }
  6816. isHighestPriority(view) {
  6817. return this.highestPriorityPage === view.renderingId;
  6818. }
  6819. hasViewer() {
  6820. return !!this.pdfViewer;
  6821. }
  6822. renderHighestPriority(currentlyVisiblePages) {
  6823. if (this.idleTimeout) {
  6824. clearTimeout(this.idleTimeout);
  6825. this.idleTimeout = null;
  6826. }
  6827. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6828. return;
  6829. }
  6830. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6831. return;
  6832. }
  6833. if (this.printing) {
  6834. return;
  6835. }
  6836. if (this.onIdle) {
  6837. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6838. }
  6839. }
  6840. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6841. const visibleViews = visible.views,
  6842. numVisible = visibleViews.length;
  6843. if (numVisible === 0) {
  6844. return null;
  6845. }
  6846. for (let i = 0; i < numVisible; i++) {
  6847. const view = visibleViews[i].view;
  6848. if (!this.isViewFinished(view)) {
  6849. return view;
  6850. }
  6851. }
  6852. const firstId = visible.first.id,
  6853. lastId = visible.last.id;
  6854. if (lastId - firstId + 1 > numVisible) {
  6855. const visibleIds = visible.ids;
  6856. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6857. const holeId = scrolledDown ? firstId + i : lastId - i;
  6858. if (visibleIds.has(holeId)) {
  6859. continue;
  6860. }
  6861. const holeView = views[holeId - 1];
  6862. if (!this.isViewFinished(holeView)) {
  6863. return holeView;
  6864. }
  6865. }
  6866. }
  6867. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6868. let preRenderView = views[preRenderIndex];
  6869. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6870. return preRenderView;
  6871. }
  6872. if (preRenderExtra) {
  6873. preRenderIndex += scrolledDown ? 1 : -1;
  6874. preRenderView = views[preRenderIndex];
  6875. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6876. return preRenderView;
  6877. }
  6878. }
  6879. return null;
  6880. }
  6881. isViewFinished(view) {
  6882. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6883. }
  6884. renderView(view) {
  6885. switch (view.renderingState) {
  6886. case _ui_utils.RenderingStates.FINISHED:
  6887. return false;
  6888. case _ui_utils.RenderingStates.PAUSED:
  6889. this.highestPriorityPage = view.renderingId;
  6890. view.resume();
  6891. break;
  6892. case _ui_utils.RenderingStates.RUNNING:
  6893. this.highestPriorityPage = view.renderingId;
  6894. break;
  6895. case _ui_utils.RenderingStates.INITIAL:
  6896. this.highestPriorityPage = view.renderingId;
  6897. view.draw().finally(() => {
  6898. this.renderHighestPriority();
  6899. }).catch(reason => {
  6900. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6901. return;
  6902. }
  6903. console.error(`renderView: "${reason}"`);
  6904. });
  6905. break;
  6906. }
  6907. return true;
  6908. }
  6909. }
  6910. exports.PDFRenderingQueue = PDFRenderingQueue;
  6911. /***/ }),
  6912. /* 23 */
  6913. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6914. Object.defineProperty(exports, "__esModule", ({
  6915. value: true
  6916. }));
  6917. exports.PDFScriptingManager = void 0;
  6918. var _ui_utils = __webpack_require__(1);
  6919. var _pdfjsLib = __webpack_require__(5);
  6920. class PDFScriptingManager {
  6921. constructor({
  6922. eventBus,
  6923. sandboxBundleSrc = null,
  6924. scriptingFactory = null,
  6925. docPropertiesLookup = null
  6926. }) {
  6927. this._pdfDocument = null;
  6928. this._pdfViewer = null;
  6929. this._closeCapability = null;
  6930. this._destroyCapability = null;
  6931. this._scripting = null;
  6932. this._ready = false;
  6933. this._eventBus = eventBus;
  6934. this._sandboxBundleSrc = sandboxBundleSrc;
  6935. this._scriptingFactory = scriptingFactory;
  6936. this._docPropertiesLookup = docPropertiesLookup;
  6937. }
  6938. setViewer(pdfViewer) {
  6939. this._pdfViewer = pdfViewer;
  6940. }
  6941. async setDocument(pdfDocument) {
  6942. if (this._pdfDocument) {
  6943. await this._destroyScripting();
  6944. }
  6945. this._pdfDocument = pdfDocument;
  6946. if (!pdfDocument) {
  6947. return;
  6948. }
  6949. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6950. if (!objects && !docActions) {
  6951. await this._destroyScripting();
  6952. return;
  6953. }
  6954. if (pdfDocument !== this._pdfDocument) {
  6955. return;
  6956. }
  6957. try {
  6958. this._scripting = this._createScripting();
  6959. } catch (error) {
  6960. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6961. await this._destroyScripting();
  6962. return;
  6963. }
  6964. this._internalEvents.set("updatefromsandbox", event => {
  6965. if (event?.source !== window) {
  6966. return;
  6967. }
  6968. this._updateFromSandbox(event.detail);
  6969. });
  6970. this._internalEvents.set("dispatcheventinsandbox", event => {
  6971. this._scripting?.dispatchEventInSandbox(event.detail);
  6972. });
  6973. this._internalEvents.set("pagechanging", ({
  6974. pageNumber,
  6975. previous
  6976. }) => {
  6977. if (pageNumber === previous) {
  6978. return;
  6979. }
  6980. this._dispatchPageClose(previous);
  6981. this._dispatchPageOpen(pageNumber);
  6982. });
  6983. this._internalEvents.set("pagerendered", ({
  6984. pageNumber
  6985. }) => {
  6986. if (!this._pageOpenPending.has(pageNumber)) {
  6987. return;
  6988. }
  6989. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6990. return;
  6991. }
  6992. this._dispatchPageOpen(pageNumber);
  6993. });
  6994. this._internalEvents.set("pagesdestroy", async event => {
  6995. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6996. await this._scripting?.dispatchEventInSandbox({
  6997. id: "doc",
  6998. name: "WillClose"
  6999. });
  7000. this._closeCapability?.resolve();
  7001. });
  7002. for (const [name, listener] of this._internalEvents) {
  7003. this._eventBus._on(name, listener);
  7004. }
  7005. try {
  7006. const docProperties = await this._getDocProperties();
  7007. if (pdfDocument !== this._pdfDocument) {
  7008. return;
  7009. }
  7010. await this._scripting.createSandbox({
  7011. objects,
  7012. calculationOrder,
  7013. appInfo: {
  7014. platform: navigator.platform,
  7015. language: navigator.language
  7016. },
  7017. docInfo: {
  7018. ...docProperties,
  7019. actions: docActions
  7020. }
  7021. });
  7022. this._eventBus.dispatch("sandboxcreated", {
  7023. source: this
  7024. });
  7025. } catch (error) {
  7026. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  7027. await this._destroyScripting();
  7028. return;
  7029. }
  7030. await this._scripting?.dispatchEventInSandbox({
  7031. id: "doc",
  7032. name: "Open"
  7033. });
  7034. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  7035. Promise.resolve().then(() => {
  7036. if (pdfDocument === this._pdfDocument) {
  7037. this._ready = true;
  7038. }
  7039. });
  7040. }
  7041. async dispatchWillSave(detail) {
  7042. return this._scripting?.dispatchEventInSandbox({
  7043. id: "doc",
  7044. name: "WillSave"
  7045. });
  7046. }
  7047. async dispatchDidSave(detail) {
  7048. return this._scripting?.dispatchEventInSandbox({
  7049. id: "doc",
  7050. name: "DidSave"
  7051. });
  7052. }
  7053. async dispatchWillPrint(detail) {
  7054. return this._scripting?.dispatchEventInSandbox({
  7055. id: "doc",
  7056. name: "WillPrint"
  7057. });
  7058. }
  7059. async dispatchDidPrint(detail) {
  7060. return this._scripting?.dispatchEventInSandbox({
  7061. id: "doc",
  7062. name: "DidPrint"
  7063. });
  7064. }
  7065. get destroyPromise() {
  7066. return this._destroyCapability?.promise || null;
  7067. }
  7068. get ready() {
  7069. return this._ready;
  7070. }
  7071. get _internalEvents() {
  7072. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  7073. }
  7074. get _pageOpenPending() {
  7075. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  7076. }
  7077. get _visitedPages() {
  7078. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  7079. }
  7080. async _updateFromSandbox(detail) {
  7081. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  7082. const {
  7083. id,
  7084. siblings,
  7085. command,
  7086. value
  7087. } = detail;
  7088. if (!id) {
  7089. switch (command) {
  7090. case "clear":
  7091. console.clear();
  7092. break;
  7093. case "error":
  7094. console.error(value);
  7095. break;
  7096. case "layout":
  7097. {
  7098. if (isInPresentationMode) {
  7099. return;
  7100. }
  7101. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  7102. this._pdfViewer.spreadMode = modes.spreadMode;
  7103. break;
  7104. }
  7105. case "page-num":
  7106. this._pdfViewer.currentPageNumber = value + 1;
  7107. break;
  7108. case "print":
  7109. await this._pdfViewer.pagesPromise;
  7110. this._eventBus.dispatch("print", {
  7111. source: this
  7112. });
  7113. break;
  7114. case "println":
  7115. console.log(value);
  7116. break;
  7117. case "zoom":
  7118. if (isInPresentationMode) {
  7119. return;
  7120. }
  7121. this._pdfViewer.currentScaleValue = value;
  7122. break;
  7123. case "SaveAs":
  7124. this._eventBus.dispatch("download", {
  7125. source: this
  7126. });
  7127. break;
  7128. case "FirstPage":
  7129. this._pdfViewer.currentPageNumber = 1;
  7130. break;
  7131. case "LastPage":
  7132. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  7133. break;
  7134. case "NextPage":
  7135. this._pdfViewer.nextPage();
  7136. break;
  7137. case "PrevPage":
  7138. this._pdfViewer.previousPage();
  7139. break;
  7140. case "ZoomViewIn":
  7141. if (isInPresentationMode) {
  7142. return;
  7143. }
  7144. this._pdfViewer.increaseScale();
  7145. break;
  7146. case "ZoomViewOut":
  7147. if (isInPresentationMode) {
  7148. return;
  7149. }
  7150. this._pdfViewer.decreaseScale();
  7151. break;
  7152. }
  7153. return;
  7154. }
  7155. if (isInPresentationMode) {
  7156. if (detail.focus) {
  7157. return;
  7158. }
  7159. }
  7160. delete detail.id;
  7161. delete detail.siblings;
  7162. const ids = siblings ? [id, ...siblings] : [id];
  7163. for (const elementId of ids) {
  7164. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  7165. if (element) {
  7166. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  7167. detail
  7168. }));
  7169. } else {
  7170. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  7171. }
  7172. }
  7173. }
  7174. async _dispatchPageOpen(pageNumber, initialize = false) {
  7175. const pdfDocument = this._pdfDocument,
  7176. visitedPages = this._visitedPages;
  7177. if (initialize) {
  7178. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  7179. }
  7180. if (!this._closeCapability) {
  7181. return;
  7182. }
  7183. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  7184. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7185. this._pageOpenPending.add(pageNumber);
  7186. return;
  7187. }
  7188. this._pageOpenPending.delete(pageNumber);
  7189. const actionsPromise = (async () => {
  7190. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  7191. if (pdfDocument !== this._pdfDocument) {
  7192. return;
  7193. }
  7194. await this._scripting?.dispatchEventInSandbox({
  7195. id: "page",
  7196. name: "PageOpen",
  7197. pageNumber,
  7198. actions
  7199. });
  7200. })();
  7201. visitedPages.set(pageNumber, actionsPromise);
  7202. }
  7203. async _dispatchPageClose(pageNumber) {
  7204. const pdfDocument = this._pdfDocument,
  7205. visitedPages = this._visitedPages;
  7206. if (!this._closeCapability) {
  7207. return;
  7208. }
  7209. if (this._pageOpenPending.has(pageNumber)) {
  7210. return;
  7211. }
  7212. const actionsPromise = visitedPages.get(pageNumber);
  7213. if (!actionsPromise) {
  7214. return;
  7215. }
  7216. visitedPages.set(pageNumber, null);
  7217. await actionsPromise;
  7218. if (pdfDocument !== this._pdfDocument) {
  7219. return;
  7220. }
  7221. await this._scripting?.dispatchEventInSandbox({
  7222. id: "page",
  7223. name: "PageClose",
  7224. pageNumber
  7225. });
  7226. }
  7227. async _getDocProperties() {
  7228. if (this._docPropertiesLookup) {
  7229. return this._docPropertiesLookup(this._pdfDocument);
  7230. }
  7231. throw new Error("_getDocProperties: Unable to lookup properties.");
  7232. }
  7233. _createScripting() {
  7234. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  7235. if (this._scripting) {
  7236. throw new Error("_createScripting: Scripting already exists.");
  7237. }
  7238. if (this._scriptingFactory) {
  7239. return this._scriptingFactory.createScripting({
  7240. sandboxBundleSrc: this._sandboxBundleSrc
  7241. });
  7242. }
  7243. throw new Error("_createScripting: Cannot create scripting.");
  7244. }
  7245. async _destroyScripting() {
  7246. if (!this._scripting) {
  7247. this._pdfDocument = null;
  7248. this._destroyCapability?.resolve();
  7249. return;
  7250. }
  7251. if (this._closeCapability) {
  7252. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  7253. setTimeout(resolve, 1000);
  7254. })]).catch(reason => {});
  7255. this._closeCapability = null;
  7256. }
  7257. this._pdfDocument = null;
  7258. try {
  7259. await this._scripting.destroySandbox();
  7260. } catch (ex) {}
  7261. for (const [name, listener] of this._internalEvents) {
  7262. this._eventBus._off(name, listener);
  7263. }
  7264. this._internalEvents.clear();
  7265. this._pageOpenPending.clear();
  7266. this._visitedPages.clear();
  7267. this._scripting = null;
  7268. this._ready = false;
  7269. this._destroyCapability?.resolve();
  7270. }
  7271. }
  7272. exports.PDFScriptingManager = PDFScriptingManager;
  7273. /***/ }),
  7274. /* 24 */
  7275. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7276. Object.defineProperty(exports, "__esModule", ({
  7277. value: true
  7278. }));
  7279. exports.PDFSidebar = void 0;
  7280. var _ui_utils = __webpack_require__(1);
  7281. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7282. class PDFSidebar {
  7283. constructor({
  7284. elements,
  7285. pdfViewer,
  7286. pdfThumbnailViewer,
  7287. eventBus,
  7288. l10n
  7289. }) {
  7290. this.isOpen = false;
  7291. this.active = _ui_utils.SidebarView.THUMBS;
  7292. this.isInitialViewSet = false;
  7293. this.isInitialEventDispatched = false;
  7294. this.onToggled = null;
  7295. this.pdfViewer = pdfViewer;
  7296. this.pdfThumbnailViewer = pdfThumbnailViewer;
  7297. this.outerContainer = elements.outerContainer;
  7298. this.sidebarContainer = elements.sidebarContainer;
  7299. this.toggleButton = elements.toggleButton;
  7300. this.thumbnailButton = elements.thumbnailButton;
  7301. this.outlineButton = elements.outlineButton;
  7302. this.attachmentsButton = elements.attachmentsButton;
  7303. this.layersButton = elements.layersButton;
  7304. this.thumbnailView = elements.thumbnailView;
  7305. this.outlineView = elements.outlineView;
  7306. this.attachmentsView = elements.attachmentsView;
  7307. this.layersView = elements.layersView;
  7308. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  7309. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7310. this.eventBus = eventBus;
  7311. this.l10n = l10n;
  7312. this.#addEventListeners();
  7313. }
  7314. reset() {
  7315. this.isInitialViewSet = false;
  7316. this.isInitialEventDispatched = false;
  7317. this.#hideUINotification(true);
  7318. this.switchView(_ui_utils.SidebarView.THUMBS);
  7319. this.outlineButton.disabled = false;
  7320. this.attachmentsButton.disabled = false;
  7321. this.layersButton.disabled = false;
  7322. this._currentOutlineItemButton.disabled = true;
  7323. }
  7324. get visibleView() {
  7325. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  7326. }
  7327. setInitialView(view = _ui_utils.SidebarView.NONE) {
  7328. if (this.isInitialViewSet) {
  7329. return;
  7330. }
  7331. this.isInitialViewSet = true;
  7332. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  7333. this.#dispatchEvent();
  7334. return;
  7335. }
  7336. this.switchView(view, true);
  7337. if (!this.isInitialEventDispatched) {
  7338. this.#dispatchEvent();
  7339. }
  7340. }
  7341. switchView(view, forceOpen = false) {
  7342. const isViewChanged = view !== this.active;
  7343. let shouldForceRendering = false;
  7344. switch (view) {
  7345. case _ui_utils.SidebarView.NONE:
  7346. if (this.isOpen) {
  7347. this.close();
  7348. }
  7349. return;
  7350. case _ui_utils.SidebarView.THUMBS:
  7351. if (this.isOpen && isViewChanged) {
  7352. shouldForceRendering = true;
  7353. }
  7354. break;
  7355. case _ui_utils.SidebarView.OUTLINE:
  7356. if (this.outlineButton.disabled) {
  7357. return;
  7358. }
  7359. break;
  7360. case _ui_utils.SidebarView.ATTACHMENTS:
  7361. if (this.attachmentsButton.disabled) {
  7362. return;
  7363. }
  7364. break;
  7365. case _ui_utils.SidebarView.LAYERS:
  7366. if (this.layersButton.disabled) {
  7367. return;
  7368. }
  7369. break;
  7370. default:
  7371. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7372. return;
  7373. }
  7374. this.active = view;
  7375. const isThumbs = view === _ui_utils.SidebarView.THUMBS,
  7376. isOutline = view === _ui_utils.SidebarView.OUTLINE,
  7377. isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS,
  7378. isLayers = view === _ui_utils.SidebarView.LAYERS;
  7379. this.thumbnailButton.classList.toggle("toggled", isThumbs);
  7380. this.outlineButton.classList.toggle("toggled", isOutline);
  7381. this.attachmentsButton.classList.toggle("toggled", isAttachments);
  7382. this.layersButton.classList.toggle("toggled", isLayers);
  7383. this.thumbnailButton.setAttribute("aria-checked", isThumbs);
  7384. this.outlineButton.setAttribute("aria-checked", isOutline);
  7385. this.attachmentsButton.setAttribute("aria-checked", isAttachments);
  7386. this.layersButton.setAttribute("aria-checked", isLayers);
  7387. this.thumbnailView.classList.toggle("hidden", !isThumbs);
  7388. this.outlineView.classList.toggle("hidden", !isOutline);
  7389. this.attachmentsView.classList.toggle("hidden", !isAttachments);
  7390. this.layersView.classList.toggle("hidden", !isLayers);
  7391. this._outlineOptionsContainer.classList.toggle("hidden", !isOutline);
  7392. if (forceOpen && !this.isOpen) {
  7393. this.open();
  7394. return;
  7395. }
  7396. if (shouldForceRendering) {
  7397. this.#updateThumbnailViewer();
  7398. this.#forceRendering();
  7399. }
  7400. if (isViewChanged) {
  7401. this.#dispatchEvent();
  7402. }
  7403. }
  7404. open() {
  7405. if (this.isOpen) {
  7406. return;
  7407. }
  7408. this.isOpen = true;
  7409. this.toggleButton.classList.add("toggled");
  7410. this.toggleButton.setAttribute("aria-expanded", "true");
  7411. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7412. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7413. this.#updateThumbnailViewer();
  7414. }
  7415. this.#forceRendering();
  7416. this.#dispatchEvent();
  7417. this.#hideUINotification();
  7418. }
  7419. close() {
  7420. if (!this.isOpen) {
  7421. return;
  7422. }
  7423. this.isOpen = false;
  7424. this.toggleButton.classList.remove("toggled");
  7425. this.toggleButton.setAttribute("aria-expanded", "false");
  7426. this.outerContainer.classList.add("sidebarMoving");
  7427. this.outerContainer.classList.remove("sidebarOpen");
  7428. this.#forceRendering();
  7429. this.#dispatchEvent();
  7430. }
  7431. toggle() {
  7432. if (this.isOpen) {
  7433. this.close();
  7434. } else {
  7435. this.open();
  7436. }
  7437. }
  7438. #dispatchEvent() {
  7439. if (this.isInitialViewSet && !this.isInitialEventDispatched) {
  7440. this.isInitialEventDispatched = true;
  7441. }
  7442. this.eventBus.dispatch("sidebarviewchanged", {
  7443. source: this,
  7444. view: this.visibleView
  7445. });
  7446. }
  7447. #forceRendering() {
  7448. if (this.onToggled) {
  7449. this.onToggled();
  7450. } else {
  7451. this.pdfViewer.forceRendering();
  7452. this.pdfThumbnailViewer.forceRendering();
  7453. }
  7454. }
  7455. #updateThumbnailViewer() {
  7456. const {
  7457. pdfViewer,
  7458. pdfThumbnailViewer
  7459. } = this;
  7460. const pagesCount = pdfViewer.pagesCount;
  7461. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  7462. const pageView = pdfViewer.getPageView(pageIndex);
  7463. if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) {
  7464. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  7465. thumbnailView.setImage(pageView);
  7466. }
  7467. }
  7468. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  7469. }
  7470. #showUINotification() {
  7471. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2");
  7472. this.l10n.translate(this.toggleButton);
  7473. if (!this.isOpen) {
  7474. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7475. }
  7476. }
  7477. #hideUINotification(reset = false) {
  7478. if (this.isOpen || reset) {
  7479. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7480. }
  7481. if (reset) {
  7482. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
  7483. this.l10n.translate(this.toggleButton);
  7484. }
  7485. }
  7486. #addEventListeners() {
  7487. this.sidebarContainer.addEventListener("transitionend", evt => {
  7488. if (evt.target === this.sidebarContainer) {
  7489. this.outerContainer.classList.remove("sidebarMoving");
  7490. }
  7491. });
  7492. this.toggleButton.addEventListener("click", () => {
  7493. this.toggle();
  7494. });
  7495. this.thumbnailButton.addEventListener("click", () => {
  7496. this.switchView(_ui_utils.SidebarView.THUMBS);
  7497. });
  7498. this.outlineButton.addEventListener("click", () => {
  7499. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7500. });
  7501. this.outlineButton.addEventListener("dblclick", () => {
  7502. this.eventBus.dispatch("toggleoutlinetree", {
  7503. source: this
  7504. });
  7505. });
  7506. this.attachmentsButton.addEventListener("click", () => {
  7507. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7508. });
  7509. this.layersButton.addEventListener("click", () => {
  7510. this.switchView(_ui_utils.SidebarView.LAYERS);
  7511. });
  7512. this.layersButton.addEventListener("dblclick", () => {
  7513. this.eventBus.dispatch("resetlayers", {
  7514. source: this
  7515. });
  7516. });
  7517. this._currentOutlineItemButton.addEventListener("click", () => {
  7518. this.eventBus.dispatch("currentoutlineitem", {
  7519. source: this
  7520. });
  7521. });
  7522. const onTreeLoaded = (count, button, view) => {
  7523. button.disabled = !count;
  7524. if (count) {
  7525. this.#showUINotification();
  7526. } else if (this.active === view) {
  7527. this.switchView(_ui_utils.SidebarView.THUMBS);
  7528. }
  7529. };
  7530. this.eventBus._on("outlineloaded", evt => {
  7531. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7532. evt.currentOutlineItemPromise.then(enabled => {
  7533. if (!this.isInitialViewSet) {
  7534. return;
  7535. }
  7536. this._currentOutlineItemButton.disabled = !enabled;
  7537. });
  7538. });
  7539. this.eventBus._on("attachmentsloaded", evt => {
  7540. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7541. });
  7542. this.eventBus._on("layersloaded", evt => {
  7543. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7544. });
  7545. this.eventBus._on("presentationmodechanged", evt => {
  7546. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  7547. this.#updateThumbnailViewer();
  7548. }
  7549. });
  7550. }
  7551. }
  7552. exports.PDFSidebar = PDFSidebar;
  7553. /***/ }),
  7554. /* 25 */
  7555. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7556. Object.defineProperty(exports, "__esModule", ({
  7557. value: true
  7558. }));
  7559. exports.PDFSidebarResizer = void 0;
  7560. var _ui_utils = __webpack_require__(1);
  7561. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7562. const SIDEBAR_MIN_WIDTH = 200;
  7563. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7564. class PDFSidebarResizer {
  7565. constructor(options, eventBus, l10n) {
  7566. this.isRTL = false;
  7567. this.sidebarOpen = false;
  7568. this._width = null;
  7569. this._outerContainerWidth = null;
  7570. this._boundEvents = Object.create(null);
  7571. this.outerContainer = options.outerContainer;
  7572. this.resizer = options.resizer;
  7573. this.eventBus = eventBus;
  7574. l10n.getDirection().then(dir => {
  7575. this.isRTL = dir === "rtl";
  7576. });
  7577. this._addEventListeners();
  7578. }
  7579. get outerContainerWidth() {
  7580. return this._outerContainerWidth ||= this.outerContainer.clientWidth;
  7581. }
  7582. _updateWidth(width = 0) {
  7583. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7584. if (width > maxWidth) {
  7585. width = maxWidth;
  7586. }
  7587. if (width < SIDEBAR_MIN_WIDTH) {
  7588. width = SIDEBAR_MIN_WIDTH;
  7589. }
  7590. if (width === this._width) {
  7591. return false;
  7592. }
  7593. this._width = width;
  7594. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7595. return true;
  7596. }
  7597. _mouseMove(evt) {
  7598. let width = evt.clientX;
  7599. if (this.isRTL) {
  7600. width = this.outerContainerWidth - width;
  7601. }
  7602. this._updateWidth(width);
  7603. }
  7604. _mouseUp(evt) {
  7605. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7606. this.eventBus.dispatch("resize", {
  7607. source: this
  7608. });
  7609. const _boundEvents = this._boundEvents;
  7610. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7611. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7612. }
  7613. _addEventListeners() {
  7614. const _boundEvents = this._boundEvents;
  7615. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7616. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7617. this.resizer.addEventListener("mousedown", evt => {
  7618. if (evt.button !== 0) {
  7619. return;
  7620. }
  7621. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7622. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7623. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7624. });
  7625. this.eventBus._on("sidebarviewchanged", evt => {
  7626. this.sidebarOpen = !!evt?.view;
  7627. });
  7628. this.eventBus._on("resize", evt => {
  7629. if (evt?.source !== window) {
  7630. return;
  7631. }
  7632. this._outerContainerWidth = null;
  7633. if (!this._width) {
  7634. return;
  7635. }
  7636. if (!this.sidebarOpen) {
  7637. this._updateWidth(this._width);
  7638. return;
  7639. }
  7640. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7641. const updated = this._updateWidth(this._width);
  7642. Promise.resolve().then(() => {
  7643. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7644. if (updated) {
  7645. this.eventBus.dispatch("resize", {
  7646. source: this
  7647. });
  7648. }
  7649. });
  7650. });
  7651. }
  7652. }
  7653. exports.PDFSidebarResizer = PDFSidebarResizer;
  7654. /***/ }),
  7655. /* 26 */
  7656. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7657. Object.defineProperty(exports, "__esModule", ({
  7658. value: true
  7659. }));
  7660. exports.PDFThumbnailViewer = void 0;
  7661. var _ui_utils = __webpack_require__(1);
  7662. var _pdf_thumbnail_view = __webpack_require__(27);
  7663. const THUMBNAIL_SCROLL_MARGIN = -19;
  7664. const THUMBNAIL_SELECTED_CLASS = "selected";
  7665. class PDFThumbnailViewer {
  7666. constructor({
  7667. container,
  7668. eventBus,
  7669. linkService,
  7670. renderingQueue,
  7671. l10n,
  7672. pageColors
  7673. }) {
  7674. this.container = container;
  7675. this.linkService = linkService;
  7676. this.renderingQueue = renderingQueue;
  7677. this.l10n = l10n;
  7678. this.pageColors = pageColors || null;
  7679. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  7680. if (this.pageColors.background || this.pageColors.foreground) {
  7681. console.warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  7682. }
  7683. this.pageColors = null;
  7684. }
  7685. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7686. this._resetView();
  7687. }
  7688. _scrollUpdated() {
  7689. this.renderingQueue.renderHighestPriority();
  7690. }
  7691. getThumbnail(index) {
  7692. return this._thumbnails[index];
  7693. }
  7694. _getVisibleThumbs() {
  7695. return (0, _ui_utils.getVisibleElements)({
  7696. scrollEl: this.container,
  7697. views: this._thumbnails
  7698. });
  7699. }
  7700. scrollThumbnailIntoView(pageNumber) {
  7701. if (!this.pdfDocument) {
  7702. return;
  7703. }
  7704. const thumbnailView = this._thumbnails[pageNumber - 1];
  7705. if (!thumbnailView) {
  7706. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7707. return;
  7708. }
  7709. if (pageNumber !== this._currentPageNumber) {
  7710. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7711. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7712. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7713. }
  7714. const {
  7715. first,
  7716. last,
  7717. views
  7718. } = this._getVisibleThumbs();
  7719. if (views.length > 0) {
  7720. let shouldScroll = false;
  7721. if (pageNumber <= first.id || pageNumber >= last.id) {
  7722. shouldScroll = true;
  7723. } else {
  7724. for (const {
  7725. id,
  7726. percent
  7727. } of views) {
  7728. if (id !== pageNumber) {
  7729. continue;
  7730. }
  7731. shouldScroll = percent < 100;
  7732. break;
  7733. }
  7734. }
  7735. if (shouldScroll) {
  7736. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7737. top: THUMBNAIL_SCROLL_MARGIN
  7738. });
  7739. }
  7740. }
  7741. this._currentPageNumber = pageNumber;
  7742. }
  7743. get pagesRotation() {
  7744. return this._pagesRotation;
  7745. }
  7746. set pagesRotation(rotation) {
  7747. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7748. throw new Error("Invalid thumbnails rotation angle.");
  7749. }
  7750. if (!this.pdfDocument) {
  7751. return;
  7752. }
  7753. if (this._pagesRotation === rotation) {
  7754. return;
  7755. }
  7756. this._pagesRotation = rotation;
  7757. const updateArgs = {
  7758. rotation
  7759. };
  7760. for (const thumbnail of this._thumbnails) {
  7761. thumbnail.update(updateArgs);
  7762. }
  7763. }
  7764. cleanup() {
  7765. for (const thumbnail of this._thumbnails) {
  7766. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7767. thumbnail.reset();
  7768. }
  7769. }
  7770. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7771. }
  7772. _resetView() {
  7773. this._thumbnails = [];
  7774. this._currentPageNumber = 1;
  7775. this._pageLabels = null;
  7776. this._pagesRotation = 0;
  7777. this.container.textContent = "";
  7778. }
  7779. setDocument(pdfDocument) {
  7780. if (this.pdfDocument) {
  7781. this._cancelRendering();
  7782. this._resetView();
  7783. }
  7784. this.pdfDocument = pdfDocument;
  7785. if (!pdfDocument) {
  7786. return;
  7787. }
  7788. const firstPagePromise = pdfDocument.getPage(1);
  7789. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7790. firstPagePromise.then(firstPdfPage => {
  7791. const pagesCount = pdfDocument.numPages;
  7792. const viewport = firstPdfPage.getViewport({
  7793. scale: 1
  7794. });
  7795. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7796. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7797. container: this.container,
  7798. id: pageNum,
  7799. defaultViewport: viewport.clone(),
  7800. optionalContentConfigPromise,
  7801. linkService: this.linkService,
  7802. renderingQueue: this.renderingQueue,
  7803. l10n: this.l10n,
  7804. pageColors: this.pageColors
  7805. });
  7806. this._thumbnails.push(thumbnail);
  7807. }
  7808. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  7809. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7810. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7811. }).catch(reason => {
  7812. console.error("Unable to initialize thumbnail viewer", reason);
  7813. });
  7814. }
  7815. _cancelRendering() {
  7816. for (const thumbnail of this._thumbnails) {
  7817. thumbnail.cancelRendering();
  7818. }
  7819. }
  7820. setPageLabels(labels) {
  7821. if (!this.pdfDocument) {
  7822. return;
  7823. }
  7824. if (!labels) {
  7825. this._pageLabels = null;
  7826. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7827. this._pageLabels = null;
  7828. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7829. } else {
  7830. this._pageLabels = labels;
  7831. }
  7832. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7833. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7834. }
  7835. }
  7836. async #ensurePdfPageLoaded(thumbView) {
  7837. if (thumbView.pdfPage) {
  7838. return thumbView.pdfPage;
  7839. }
  7840. try {
  7841. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7842. if (!thumbView.pdfPage) {
  7843. thumbView.setPdfPage(pdfPage);
  7844. }
  7845. return pdfPage;
  7846. } catch (reason) {
  7847. console.error("Unable to get page for thumb view", reason);
  7848. return null;
  7849. }
  7850. }
  7851. #getScrollAhead(visible) {
  7852. if (visible.first?.id === 1) {
  7853. return true;
  7854. } else if (visible.last?.id === this._thumbnails.length) {
  7855. return false;
  7856. }
  7857. return this.scroll.down;
  7858. }
  7859. forceRendering() {
  7860. const visibleThumbs = this._getVisibleThumbs();
  7861. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7862. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7863. if (thumbView) {
  7864. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7865. this.renderingQueue.renderView(thumbView);
  7866. });
  7867. return true;
  7868. }
  7869. return false;
  7870. }
  7871. }
  7872. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7873. /***/ }),
  7874. /* 27 */
  7875. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7876. Object.defineProperty(exports, "__esModule", ({
  7877. value: true
  7878. }));
  7879. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7880. var _ui_utils = __webpack_require__(1);
  7881. var _pdfjsLib = __webpack_require__(5);
  7882. const DRAW_UPSCALE_FACTOR = 2;
  7883. const MAX_NUM_SCALING_STEPS = 3;
  7884. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7885. const THUMBNAIL_WIDTH = 98;
  7886. class TempImageFactory {
  7887. static #tempCanvas = null;
  7888. static getCanvas(width, height) {
  7889. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7890. tempCanvas.width = width;
  7891. tempCanvas.height = height;
  7892. const ctx = tempCanvas.getContext("2d", {
  7893. alpha: false
  7894. });
  7895. ctx.save();
  7896. ctx.fillStyle = "rgb(255, 255, 255)";
  7897. ctx.fillRect(0, 0, width, height);
  7898. ctx.restore();
  7899. return [tempCanvas, tempCanvas.getContext("2d")];
  7900. }
  7901. static destroyCanvas() {
  7902. const tempCanvas = this.#tempCanvas;
  7903. if (tempCanvas) {
  7904. tempCanvas.width = 0;
  7905. tempCanvas.height = 0;
  7906. }
  7907. this.#tempCanvas = null;
  7908. }
  7909. }
  7910. exports.TempImageFactory = TempImageFactory;
  7911. class PDFThumbnailView {
  7912. constructor({
  7913. container,
  7914. id,
  7915. defaultViewport,
  7916. optionalContentConfigPromise,
  7917. linkService,
  7918. renderingQueue,
  7919. l10n,
  7920. pageColors
  7921. }) {
  7922. this.id = id;
  7923. this.renderingId = "thumbnail" + id;
  7924. this.pageLabel = null;
  7925. this.pdfPage = null;
  7926. this.rotation = 0;
  7927. this.viewport = defaultViewport;
  7928. this.pdfPageRotate = defaultViewport.rotation;
  7929. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7930. this.pageColors = pageColors || null;
  7931. this.linkService = linkService;
  7932. this.renderingQueue = renderingQueue;
  7933. this.renderTask = null;
  7934. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7935. this.resume = null;
  7936. const pageWidth = this.viewport.width,
  7937. pageHeight = this.viewport.height,
  7938. pageRatio = pageWidth / pageHeight;
  7939. this.canvasWidth = THUMBNAIL_WIDTH;
  7940. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7941. this.scale = this.canvasWidth / pageWidth;
  7942. this.l10n = l10n;
  7943. const anchor = document.createElement("a");
  7944. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7945. this._thumbPageTitle.then(msg => {
  7946. anchor.title = msg;
  7947. });
  7948. anchor.onclick = function () {
  7949. linkService.goToPage(id);
  7950. return false;
  7951. };
  7952. this.anchor = anchor;
  7953. const div = document.createElement("div");
  7954. div.className = "thumbnail";
  7955. div.setAttribute("data-page-number", this.id);
  7956. this.div = div;
  7957. const ring = document.createElement("div");
  7958. ring.className = "thumbnailSelectionRing";
  7959. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7960. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7961. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7962. this.ring = ring;
  7963. div.append(ring);
  7964. anchor.append(div);
  7965. container.append(anchor);
  7966. }
  7967. setPdfPage(pdfPage) {
  7968. this.pdfPage = pdfPage;
  7969. this.pdfPageRotate = pdfPage.rotate;
  7970. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7971. this.viewport = pdfPage.getViewport({
  7972. scale: 1,
  7973. rotation: totalRotation
  7974. });
  7975. this.reset();
  7976. }
  7977. reset() {
  7978. this.cancelRendering();
  7979. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7980. const pageWidth = this.viewport.width,
  7981. pageHeight = this.viewport.height,
  7982. pageRatio = pageWidth / pageHeight;
  7983. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7984. this.scale = this.canvasWidth / pageWidth;
  7985. this.div.removeAttribute("data-loaded");
  7986. const ring = this.ring;
  7987. ring.textContent = "";
  7988. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7989. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7990. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7991. if (this.canvas) {
  7992. this.canvas.width = 0;
  7993. this.canvas.height = 0;
  7994. delete this.canvas;
  7995. }
  7996. if (this.image) {
  7997. this.image.removeAttribute("src");
  7998. delete this.image;
  7999. }
  8000. }
  8001. update({
  8002. rotation = null
  8003. }) {
  8004. if (typeof rotation === "number") {
  8005. this.rotation = rotation;
  8006. }
  8007. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8008. this.viewport = this.viewport.clone({
  8009. scale: 1,
  8010. rotation: totalRotation
  8011. });
  8012. this.reset();
  8013. }
  8014. cancelRendering() {
  8015. if (this.renderTask) {
  8016. this.renderTask.cancel();
  8017. this.renderTask = null;
  8018. }
  8019. this.resume = null;
  8020. }
  8021. _getPageDrawContext(upscaleFactor = 1) {
  8022. const canvas = document.createElement("canvas");
  8023. const ctx = canvas.getContext("2d", {
  8024. alpha: false
  8025. });
  8026. const outputScale = new _ui_utils.OutputScale();
  8027. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  8028. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  8029. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  8030. return {
  8031. ctx,
  8032. canvas,
  8033. transform
  8034. };
  8035. }
  8036. _convertCanvasToImage(canvas) {
  8037. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8038. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  8039. }
  8040. const reducedCanvas = this._reduceImage(canvas);
  8041. const image = document.createElement("img");
  8042. image.className = "thumbnailImage";
  8043. this._thumbPageCanvas.then(msg => {
  8044. image.setAttribute("aria-label", msg);
  8045. });
  8046. image.style.width = this.canvasWidth + "px";
  8047. image.style.height = this.canvasHeight + "px";
  8048. image.src = reducedCanvas.toDataURL();
  8049. this.image = image;
  8050. this.div.setAttribute("data-loaded", true);
  8051. this.ring.append(image);
  8052. reducedCanvas.width = 0;
  8053. reducedCanvas.height = 0;
  8054. }
  8055. draw() {
  8056. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8057. console.error("Must be in new state before drawing");
  8058. return Promise.resolve();
  8059. }
  8060. const {
  8061. pdfPage
  8062. } = this;
  8063. if (!pdfPage) {
  8064. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8065. return Promise.reject(new Error("pdfPage is not loaded"));
  8066. }
  8067. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8068. const finishRenderTask = async (error = null) => {
  8069. if (renderTask === this.renderTask) {
  8070. this.renderTask = null;
  8071. }
  8072. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  8073. return;
  8074. }
  8075. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8076. this._convertCanvasToImage(canvas);
  8077. if (error) {
  8078. throw error;
  8079. }
  8080. };
  8081. const {
  8082. ctx,
  8083. canvas,
  8084. transform
  8085. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  8086. const drawViewport = this.viewport.clone({
  8087. scale: DRAW_UPSCALE_FACTOR * this.scale
  8088. });
  8089. const renderContinueCallback = cont => {
  8090. if (!this.renderingQueue.isHighestPriority(this)) {
  8091. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  8092. this.resume = () => {
  8093. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8094. cont();
  8095. };
  8096. return;
  8097. }
  8098. cont();
  8099. };
  8100. const renderContext = {
  8101. canvasContext: ctx,
  8102. transform,
  8103. viewport: drawViewport,
  8104. optionalContentConfigPromise: this._optionalContentConfigPromise,
  8105. pageColors: this.pageColors
  8106. };
  8107. const renderTask = this.renderTask = pdfPage.render(renderContext);
  8108. renderTask.onContinue = renderContinueCallback;
  8109. const resultPromise = renderTask.promise.then(function () {
  8110. return finishRenderTask(null);
  8111. }, function (error) {
  8112. return finishRenderTask(error);
  8113. });
  8114. resultPromise.finally(() => {
  8115. canvas.width = 0;
  8116. canvas.height = 0;
  8117. const pageCached = this.linkService.isPageCached(this.id);
  8118. if (!pageCached) {
  8119. this.pdfPage?.cleanup();
  8120. }
  8121. });
  8122. return resultPromise;
  8123. }
  8124. setImage(pageView) {
  8125. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8126. return;
  8127. }
  8128. const {
  8129. thumbnailCanvas: canvas,
  8130. pdfPage,
  8131. scale
  8132. } = pageView;
  8133. if (!canvas) {
  8134. return;
  8135. }
  8136. if (!this.pdfPage) {
  8137. this.setPdfPage(pdfPage);
  8138. }
  8139. if (scale < this.scale) {
  8140. return;
  8141. }
  8142. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8143. this._convertCanvasToImage(canvas);
  8144. }
  8145. _reduceImage(img) {
  8146. const {
  8147. ctx,
  8148. canvas
  8149. } = this._getPageDrawContext();
  8150. if (img.width <= 2 * canvas.width) {
  8151. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  8152. return canvas;
  8153. }
  8154. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  8155. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  8156. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  8157. while (reducedWidth > img.width || reducedHeight > img.height) {
  8158. reducedWidth >>= 1;
  8159. reducedHeight >>= 1;
  8160. }
  8161. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  8162. while (reducedWidth > 2 * canvas.width) {
  8163. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  8164. reducedWidth >>= 1;
  8165. reducedHeight >>= 1;
  8166. }
  8167. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  8168. return canvas;
  8169. }
  8170. get _thumbPageTitle() {
  8171. return this.l10n.get("thumb_page_title", {
  8172. page: this.pageLabel ?? this.id
  8173. });
  8174. }
  8175. get _thumbPageCanvas() {
  8176. return this.l10n.get("thumb_page_canvas", {
  8177. page: this.pageLabel ?? this.id
  8178. });
  8179. }
  8180. setPageLabel(label) {
  8181. this.pageLabel = typeof label === "string" ? label : null;
  8182. this._thumbPageTitle.then(msg => {
  8183. this.anchor.title = msg;
  8184. });
  8185. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8186. return;
  8187. }
  8188. this._thumbPageCanvas.then(msg => {
  8189. this.image?.setAttribute("aria-label", msg);
  8190. });
  8191. }
  8192. }
  8193. exports.PDFThumbnailView = PDFThumbnailView;
  8194. /***/ }),
  8195. /* 28 */
  8196. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8197. Object.defineProperty(exports, "__esModule", ({
  8198. value: true
  8199. }));
  8200. exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
  8201. var _pdfjsLib = __webpack_require__(5);
  8202. var _ui_utils = __webpack_require__(1);
  8203. var _l10n_utils = __webpack_require__(29);
  8204. var _pdf_page_view = __webpack_require__(30);
  8205. var _pdf_rendering_queue = __webpack_require__(22);
  8206. var _pdf_link_service = __webpack_require__(3);
  8207. const DEFAULT_CACHE_SIZE = 10;
  8208. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  8209. const PagesCountLimit = {
  8210. FORCE_SCROLL_MODE_PAGE: 15000,
  8211. FORCE_LAZY_PAGE_INIT: 7500,
  8212. PAUSE_EAGER_PAGE_INIT: 250
  8213. };
  8214. exports.PagesCountLimit = PagesCountLimit;
  8215. function isValidAnnotationEditorMode(mode) {
  8216. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  8217. }
  8218. class PDFPageViewBuffer {
  8219. #buf = new Set();
  8220. #size = 0;
  8221. constructor(size) {
  8222. this.#size = size;
  8223. }
  8224. push(view) {
  8225. const buf = this.#buf;
  8226. if (buf.has(view)) {
  8227. buf.delete(view);
  8228. }
  8229. buf.add(view);
  8230. if (buf.size > this.#size) {
  8231. this.#destroyFirstView();
  8232. }
  8233. }
  8234. resize(newSize, idsToKeep = null) {
  8235. this.#size = newSize;
  8236. const buf = this.#buf;
  8237. if (idsToKeep) {
  8238. const ii = buf.size;
  8239. let i = 1;
  8240. for (const view of buf) {
  8241. if (idsToKeep.has(view.id)) {
  8242. buf.delete(view);
  8243. buf.add(view);
  8244. }
  8245. if (++i > ii) {
  8246. break;
  8247. }
  8248. }
  8249. }
  8250. while (buf.size > this.#size) {
  8251. this.#destroyFirstView();
  8252. }
  8253. }
  8254. has(view) {
  8255. return this.#buf.has(view);
  8256. }
  8257. [Symbol.iterator]() {
  8258. return this.#buf.keys();
  8259. }
  8260. #destroyFirstView() {
  8261. const firstView = this.#buf.keys().next().value;
  8262. firstView?.destroy();
  8263. this.#buf.delete(firstView);
  8264. }
  8265. }
  8266. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  8267. class PDFViewer {
  8268. #buffer = null;
  8269. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  8270. #annotationEditorUIManager = null;
  8271. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8272. #containerTopLeft = null;
  8273. #enablePermissions = false;
  8274. #previousContainerHeight = 0;
  8275. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  8276. #scrollModePageState = null;
  8277. #onVisibilityChange = null;
  8278. #scaleTimeoutId = null;
  8279. constructor(options) {
  8280. const viewerVersion = '3.3.122';
  8281. if (_pdfjsLib.version !== viewerVersion) {
  8282. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  8283. }
  8284. this.container = options.container;
  8285. this.viewer = options.viewer || options.container.firstElementChild;
  8286. if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
  8287. throw new Error("Invalid `container` and/or `viewer` option.");
  8288. }
  8289. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  8290. throw new Error("The `container` must be absolutely positioned.");
  8291. }
  8292. this.#resizeObserver.observe(this.container);
  8293. this.eventBus = options.eventBus;
  8294. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8295. this.downloadManager = options.downloadManager || null;
  8296. this.findController = options.findController || null;
  8297. this._scriptingManager = options.scriptingManager || null;
  8298. this.removePageBorders = options.removePageBorders || false;
  8299. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  8300. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8301. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
  8302. this.imageResourcesPath = options.imageResourcesPath || "";
  8303. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8304. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  8305. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  8306. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  8307. this.maxCanvasPixels = options.maxCanvasPixels;
  8308. this.l10n = options.l10n || _l10n_utils.NullL10n;
  8309. this.#enablePermissions = options.enablePermissions || false;
  8310. this.pageColors = options.pageColors || null;
  8311. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  8312. if (this.pageColors.background || this.pageColors.foreground) {
  8313. console.warn("PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  8314. }
  8315. this.pageColors = null;
  8316. }
  8317. this.defaultRenderingQueue = !options.renderingQueue;
  8318. if (this.defaultRenderingQueue) {
  8319. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8320. this.renderingQueue.setViewer(this);
  8321. } else {
  8322. this.renderingQueue = options.renderingQueue;
  8323. }
  8324. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8325. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8326. this._onBeforeDraw = this._onAfterDraw = null;
  8327. this._resetView();
  8328. if (this.removePageBorders) {
  8329. this.viewer.classList.add("removePageBorders");
  8330. }
  8331. this.#updateContainerHeightCss();
  8332. }
  8333. get pagesCount() {
  8334. return this._pages.length;
  8335. }
  8336. getPageView(index) {
  8337. return this._pages[index];
  8338. }
  8339. get pageViewsReady() {
  8340. if (!this._pagesCapability.settled) {
  8341. return false;
  8342. }
  8343. return this._pages.every(function (pageView) {
  8344. return pageView?.pdfPage;
  8345. });
  8346. }
  8347. get renderForms() {
  8348. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8349. }
  8350. get enableScripting() {
  8351. return !!this._scriptingManager;
  8352. }
  8353. get currentPageNumber() {
  8354. return this._currentPageNumber;
  8355. }
  8356. set currentPageNumber(val) {
  8357. if (!Number.isInteger(val)) {
  8358. throw new Error("Invalid page number.");
  8359. }
  8360. if (!this.pdfDocument) {
  8361. return;
  8362. }
  8363. if (!this._setCurrentPageNumber(val, true)) {
  8364. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  8365. }
  8366. }
  8367. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  8368. if (this._currentPageNumber === val) {
  8369. if (resetCurrentPageView) {
  8370. this.#resetCurrentPageView();
  8371. }
  8372. return true;
  8373. }
  8374. if (!(0 < val && val <= this.pagesCount)) {
  8375. return false;
  8376. }
  8377. const previous = this._currentPageNumber;
  8378. this._currentPageNumber = val;
  8379. this.eventBus.dispatch("pagechanging", {
  8380. source: this,
  8381. pageNumber: val,
  8382. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8383. previous
  8384. });
  8385. if (resetCurrentPageView) {
  8386. this.#resetCurrentPageView();
  8387. }
  8388. return true;
  8389. }
  8390. get currentPageLabel() {
  8391. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8392. }
  8393. set currentPageLabel(val) {
  8394. if (!this.pdfDocument) {
  8395. return;
  8396. }
  8397. let page = val | 0;
  8398. if (this._pageLabels) {
  8399. const i = this._pageLabels.indexOf(val);
  8400. if (i >= 0) {
  8401. page = i + 1;
  8402. }
  8403. }
  8404. if (!this._setCurrentPageNumber(page, true)) {
  8405. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8406. }
  8407. }
  8408. get currentScale() {
  8409. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8410. }
  8411. set currentScale(val) {
  8412. if (isNaN(val)) {
  8413. throw new Error("Invalid numeric scale.");
  8414. }
  8415. if (!this.pdfDocument) {
  8416. return;
  8417. }
  8418. this._setScale(val, {
  8419. noScroll: false
  8420. });
  8421. }
  8422. get currentScaleValue() {
  8423. return this._currentScaleValue;
  8424. }
  8425. set currentScaleValue(val) {
  8426. if (!this.pdfDocument) {
  8427. return;
  8428. }
  8429. this._setScale(val, {
  8430. noScroll: false
  8431. });
  8432. }
  8433. get pagesRotation() {
  8434. return this._pagesRotation;
  8435. }
  8436. set pagesRotation(rotation) {
  8437. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8438. throw new Error("Invalid pages rotation angle.");
  8439. }
  8440. if (!this.pdfDocument) {
  8441. return;
  8442. }
  8443. rotation %= 360;
  8444. if (rotation < 0) {
  8445. rotation += 360;
  8446. }
  8447. if (this._pagesRotation === rotation) {
  8448. return;
  8449. }
  8450. this._pagesRotation = rotation;
  8451. const pageNumber = this._currentPageNumber;
  8452. this.refresh(true, {
  8453. rotation
  8454. });
  8455. if (this._currentScaleValue) {
  8456. this._setScale(this._currentScaleValue, {
  8457. noScroll: true
  8458. });
  8459. }
  8460. this.eventBus.dispatch("rotationchanging", {
  8461. source: this,
  8462. pagesRotation: rotation,
  8463. pageNumber
  8464. });
  8465. if (this.defaultRenderingQueue) {
  8466. this.update();
  8467. }
  8468. }
  8469. get firstPagePromise() {
  8470. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8471. }
  8472. get onePageRendered() {
  8473. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8474. }
  8475. get pagesPromise() {
  8476. return this.pdfDocument ? this._pagesCapability.promise : null;
  8477. }
  8478. #layerProperties() {
  8479. const self = this;
  8480. return {
  8481. get annotationEditorUIManager() {
  8482. return self.#annotationEditorUIManager;
  8483. },
  8484. get annotationStorage() {
  8485. return self.pdfDocument?.annotationStorage;
  8486. },
  8487. get downloadManager() {
  8488. return self.downloadManager;
  8489. },
  8490. get enableScripting() {
  8491. return !!self._scriptingManager;
  8492. },
  8493. get fieldObjectsPromise() {
  8494. return self.pdfDocument?.getFieldObjects();
  8495. },
  8496. get findController() {
  8497. return self.findController;
  8498. },
  8499. get hasJSActionsPromise() {
  8500. return self.pdfDocument?.hasJSActions();
  8501. },
  8502. get linkService() {
  8503. return self.linkService;
  8504. }
  8505. };
  8506. }
  8507. #initializePermissions(permissions) {
  8508. const params = {
  8509. annotationEditorMode: this.#annotationEditorMode,
  8510. annotationMode: this.#annotationMode,
  8511. textLayerMode: this.textLayerMode
  8512. };
  8513. if (!permissions) {
  8514. return params;
  8515. }
  8516. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  8517. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  8518. }
  8519. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  8520. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8521. }
  8522. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8523. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8524. }
  8525. return params;
  8526. }
  8527. #onePageRenderedOrForceFetch() {
  8528. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8529. return Promise.resolve();
  8530. }
  8531. const visibilityChangePromise = new Promise(resolve => {
  8532. this.#onVisibilityChange = () => {
  8533. if (document.visibilityState !== "hidden") {
  8534. return;
  8535. }
  8536. resolve();
  8537. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8538. this.#onVisibilityChange = null;
  8539. };
  8540. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8541. });
  8542. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8543. }
  8544. setDocument(pdfDocument) {
  8545. if (this.pdfDocument) {
  8546. this.eventBus.dispatch("pagesdestroy", {
  8547. source: this
  8548. });
  8549. this._cancelRendering();
  8550. this._resetView();
  8551. this.findController?.setDocument(null);
  8552. this._scriptingManager?.setDocument(null);
  8553. if (this.#annotationEditorUIManager) {
  8554. this.#annotationEditorUIManager.destroy();
  8555. this.#annotationEditorUIManager = null;
  8556. }
  8557. }
  8558. this.pdfDocument = pdfDocument;
  8559. if (!pdfDocument) {
  8560. return;
  8561. }
  8562. const pagesCount = pdfDocument.numPages;
  8563. const firstPagePromise = pdfDocument.getPage(1);
  8564. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8565. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8566. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8567. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8568. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8569. this.eventBus.dispatch("scrollmodechanged", {
  8570. source: this,
  8571. mode
  8572. });
  8573. }
  8574. this._pagesCapability.promise.then(() => {
  8575. this.eventBus.dispatch("pagesloaded", {
  8576. source: this,
  8577. pagesCount
  8578. });
  8579. }, () => {});
  8580. this._onBeforeDraw = evt => {
  8581. const pageView = this._pages[evt.pageNumber - 1];
  8582. if (!pageView) {
  8583. return;
  8584. }
  8585. this.#buffer.push(pageView);
  8586. };
  8587. this.eventBus._on("pagerender", this._onBeforeDraw);
  8588. this._onAfterDraw = evt => {
  8589. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8590. return;
  8591. }
  8592. this._onePageRenderedCapability.resolve({
  8593. timestamp: evt.timestamp
  8594. });
  8595. this.eventBus._off("pagerendered", this._onAfterDraw);
  8596. this._onAfterDraw = null;
  8597. if (this.#onVisibilityChange) {
  8598. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8599. this.#onVisibilityChange = null;
  8600. }
  8601. };
  8602. this.eventBus._on("pagerendered", this._onAfterDraw);
  8603. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8604. if (pdfDocument !== this.pdfDocument) {
  8605. return;
  8606. }
  8607. this._firstPageCapability.resolve(firstPdfPage);
  8608. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8609. const {
  8610. annotationEditorMode,
  8611. annotationMode,
  8612. textLayerMode
  8613. } = this.#initializePermissions(permissions);
  8614. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  8615. const mode = annotationEditorMode;
  8616. if (pdfDocument.isPureXfa) {
  8617. console.warn("Warning: XFA-editing is not implemented.");
  8618. } else if (isValidAnnotationEditorMode(mode)) {
  8619. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus, pdfDocument?.annotationStorage);
  8620. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  8621. this.#annotationEditorUIManager.updateMode(mode);
  8622. }
  8623. } else {
  8624. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  8625. }
  8626. }
  8627. const layerProperties = this.#layerProperties.bind(this);
  8628. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8629. const scale = this.currentScale;
  8630. const viewport = firstPdfPage.getViewport({
  8631. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8632. });
  8633. this.viewer.style.setProperty("--scale-factor", viewport.scale);
  8634. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8635. const pageView = new _pdf_page_view.PDFPageView({
  8636. container: viewerElement,
  8637. eventBus: this.eventBus,
  8638. id: pageNum,
  8639. scale,
  8640. defaultViewport: viewport.clone(),
  8641. optionalContentConfigPromise,
  8642. renderingQueue: this.renderingQueue,
  8643. textLayerMode,
  8644. annotationMode,
  8645. imageResourcesPath: this.imageResourcesPath,
  8646. renderer: this.renderer,
  8647. useOnlyCssZoom: this.useOnlyCssZoom,
  8648. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  8649. maxCanvasPixels: this.maxCanvasPixels,
  8650. pageColors: this.pageColors,
  8651. l10n: this.l10n,
  8652. layerProperties
  8653. });
  8654. this._pages.push(pageView);
  8655. }
  8656. const firstPageView = this._pages[0];
  8657. if (firstPageView) {
  8658. firstPageView.setPdfPage(firstPdfPage);
  8659. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8660. }
  8661. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8662. this.#ensurePageViewVisible();
  8663. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8664. this._updateSpreadMode();
  8665. }
  8666. this.#onePageRenderedOrForceFetch().then(async () => {
  8667. this.findController?.setDocument(pdfDocument);
  8668. this._scriptingManager?.setDocument(pdfDocument);
  8669. if (this.#annotationEditorUIManager) {
  8670. this.eventBus.dispatch("annotationeditormodechanged", {
  8671. source: this,
  8672. mode: this.#annotationEditorMode
  8673. });
  8674. }
  8675. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8676. this._pagesCapability.resolve();
  8677. return;
  8678. }
  8679. let getPagesLeft = pagesCount - 1;
  8680. if (getPagesLeft <= 0) {
  8681. this._pagesCapability.resolve();
  8682. return;
  8683. }
  8684. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8685. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8686. const pageView = this._pages[pageNum - 1];
  8687. if (!pageView.pdfPage) {
  8688. pageView.setPdfPage(pdfPage);
  8689. }
  8690. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8691. if (--getPagesLeft === 0) {
  8692. this._pagesCapability.resolve();
  8693. }
  8694. }, reason => {
  8695. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8696. if (--getPagesLeft === 0) {
  8697. this._pagesCapability.resolve();
  8698. }
  8699. });
  8700. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8701. await promise;
  8702. }
  8703. }
  8704. });
  8705. this.eventBus.dispatch("pagesinit", {
  8706. source: this
  8707. });
  8708. pdfDocument.getMetadata().then(({
  8709. info
  8710. }) => {
  8711. if (pdfDocument !== this.pdfDocument) {
  8712. return;
  8713. }
  8714. if (info.Language) {
  8715. this.viewer.lang = info.Language;
  8716. }
  8717. });
  8718. if (this.defaultRenderingQueue) {
  8719. this.update();
  8720. }
  8721. }).catch(reason => {
  8722. console.error("Unable to initialize viewer", reason);
  8723. this._pagesCapability.reject(reason);
  8724. });
  8725. }
  8726. setPageLabels(labels) {
  8727. if (!this.pdfDocument) {
  8728. return;
  8729. }
  8730. if (!labels) {
  8731. this._pageLabels = null;
  8732. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8733. this._pageLabels = null;
  8734. console.error(`setPageLabels: Invalid page labels.`);
  8735. } else {
  8736. this._pageLabels = labels;
  8737. }
  8738. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8739. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8740. }
  8741. }
  8742. _resetView() {
  8743. this._pages = [];
  8744. this._currentPageNumber = 1;
  8745. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8746. this._currentScaleValue = null;
  8747. this._pageLabels = null;
  8748. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8749. this._location = null;
  8750. this._pagesRotation = 0;
  8751. this._optionalContentConfigPromise = null;
  8752. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8753. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8754. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8755. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8756. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8757. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8758. this.#scrollModePageState = {
  8759. previousPageNumber: 1,
  8760. scrollDown: true,
  8761. pages: []
  8762. };
  8763. if (this._onBeforeDraw) {
  8764. this.eventBus._off("pagerender", this._onBeforeDraw);
  8765. this._onBeforeDraw = null;
  8766. }
  8767. if (this._onAfterDraw) {
  8768. this.eventBus._off("pagerendered", this._onAfterDraw);
  8769. this._onAfterDraw = null;
  8770. }
  8771. if (this.#onVisibilityChange) {
  8772. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8773. this.#onVisibilityChange = null;
  8774. }
  8775. this.viewer.textContent = "";
  8776. this._updateScrollMode();
  8777. this.viewer.removeAttribute("lang");
  8778. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  8779. }
  8780. #ensurePageViewVisible() {
  8781. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8782. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8783. }
  8784. const pageNumber = this._currentPageNumber,
  8785. state = this.#scrollModePageState,
  8786. viewer = this.viewer;
  8787. viewer.textContent = "";
  8788. state.pages.length = 0;
  8789. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8790. const pageView = this._pages[pageNumber - 1];
  8791. viewer.append(pageView.div);
  8792. state.pages.push(pageView);
  8793. } else {
  8794. const pageIndexSet = new Set(),
  8795. parity = this._spreadMode - 1;
  8796. if (parity === -1) {
  8797. pageIndexSet.add(pageNumber - 1);
  8798. } else if (pageNumber % 2 !== parity) {
  8799. pageIndexSet.add(pageNumber - 1);
  8800. pageIndexSet.add(pageNumber);
  8801. } else {
  8802. pageIndexSet.add(pageNumber - 2);
  8803. pageIndexSet.add(pageNumber - 1);
  8804. }
  8805. const spread = document.createElement("div");
  8806. spread.className = "spread";
  8807. if (this.isInPresentationMode) {
  8808. const dummyPage = document.createElement("div");
  8809. dummyPage.className = "dummyPage";
  8810. spread.append(dummyPage);
  8811. }
  8812. for (const i of pageIndexSet) {
  8813. const pageView = this._pages[i];
  8814. if (!pageView) {
  8815. continue;
  8816. }
  8817. spread.append(pageView.div);
  8818. state.pages.push(pageView);
  8819. }
  8820. viewer.append(spread);
  8821. }
  8822. state.scrollDown = pageNumber >= state.previousPageNumber;
  8823. state.previousPageNumber = pageNumber;
  8824. }
  8825. _scrollUpdate() {
  8826. if (this.pagesCount === 0) {
  8827. return;
  8828. }
  8829. this.update();
  8830. }
  8831. #scrollIntoView(pageView, pageSpot = null) {
  8832. const {
  8833. div,
  8834. id
  8835. } = pageView;
  8836. if (this._currentPageNumber !== id) {
  8837. this._setCurrentPageNumber(id);
  8838. }
  8839. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8840. this.#ensurePageViewVisible();
  8841. this.update();
  8842. }
  8843. if (!pageSpot && !this.isInPresentationMode) {
  8844. const left = div.offsetLeft + div.clientLeft,
  8845. right = left + div.clientWidth;
  8846. const {
  8847. scrollLeft,
  8848. clientWidth
  8849. } = this.container;
  8850. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8851. pageSpot = {
  8852. left: 0,
  8853. top: 0
  8854. };
  8855. }
  8856. }
  8857. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8858. if (!this._currentScaleValue && this._location) {
  8859. this._location = null;
  8860. }
  8861. }
  8862. #isSameScale(newScale) {
  8863. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8864. }
  8865. _setScaleUpdatePages(newScale, newValue, {
  8866. noScroll = false,
  8867. preset = false,
  8868. drawingDelay = -1
  8869. }) {
  8870. this._currentScaleValue = newValue.toString();
  8871. if (this.#isSameScale(newScale)) {
  8872. if (preset) {
  8873. this.eventBus.dispatch("scalechanging", {
  8874. source: this,
  8875. scale: newScale,
  8876. presetValue: newValue
  8877. });
  8878. }
  8879. return;
  8880. }
  8881. this.viewer.style.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8882. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  8883. this.refresh(true, {
  8884. scale: newScale,
  8885. drawingDelay: postponeDrawing ? drawingDelay : -1
  8886. });
  8887. if (postponeDrawing) {
  8888. this.#scaleTimeoutId = setTimeout(() => {
  8889. this.#scaleTimeoutId = null;
  8890. this.refresh();
  8891. }, drawingDelay);
  8892. }
  8893. this._currentScale = newScale;
  8894. if (!noScroll) {
  8895. let page = this._currentPageNumber,
  8896. dest;
  8897. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8898. page = this._location.pageNumber;
  8899. dest = [null, {
  8900. name: "XYZ"
  8901. }, this._location.left, this._location.top, null];
  8902. }
  8903. this.scrollPageIntoView({
  8904. pageNumber: page,
  8905. destArray: dest,
  8906. allowNegativeOffset: true
  8907. });
  8908. }
  8909. this.eventBus.dispatch("scalechanging", {
  8910. source: this,
  8911. scale: newScale,
  8912. presetValue: preset ? newValue : undefined
  8913. });
  8914. if (this.defaultRenderingQueue) {
  8915. this.update();
  8916. }
  8917. }
  8918. get _pageWidthScaleFactor() {
  8919. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8920. return 2;
  8921. }
  8922. return 1;
  8923. }
  8924. _setScale(value, options) {
  8925. let scale = parseFloat(value);
  8926. if (scale > 0) {
  8927. options.preset = false;
  8928. this._setScaleUpdatePages(scale, value, options);
  8929. } else {
  8930. const currentPage = this._pages[this._currentPageNumber - 1];
  8931. if (!currentPage) {
  8932. return;
  8933. }
  8934. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8935. vPadding = _ui_utils.VERTICAL_PADDING;
  8936. if (this.isInPresentationMode) {
  8937. hPadding = vPadding = 4;
  8938. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8939. hPadding *= 2;
  8940. }
  8941. } else if (this.removePageBorders) {
  8942. hPadding = vPadding = 0;
  8943. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8944. [hPadding, vPadding] = [vPadding, hPadding];
  8945. }
  8946. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8947. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8948. switch (value) {
  8949. case "page-actual":
  8950. scale = 1;
  8951. break;
  8952. case "page-width":
  8953. scale = pageWidthScale;
  8954. break;
  8955. case "page-height":
  8956. scale = pageHeightScale;
  8957. break;
  8958. case "page-fit":
  8959. scale = Math.min(pageWidthScale, pageHeightScale);
  8960. break;
  8961. case "auto":
  8962. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8963. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8964. break;
  8965. default:
  8966. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  8967. return;
  8968. }
  8969. options.preset = true;
  8970. this._setScaleUpdatePages(scale, value, options);
  8971. }
  8972. }
  8973. #resetCurrentPageView() {
  8974. const pageView = this._pages[this._currentPageNumber - 1];
  8975. if (this.isInPresentationMode) {
  8976. this._setScale(this._currentScaleValue, {
  8977. noScroll: true
  8978. });
  8979. }
  8980. this.#scrollIntoView(pageView);
  8981. }
  8982. pageLabelToPageNumber(label) {
  8983. if (!this._pageLabels) {
  8984. return null;
  8985. }
  8986. const i = this._pageLabels.indexOf(label);
  8987. if (i < 0) {
  8988. return null;
  8989. }
  8990. return i + 1;
  8991. }
  8992. scrollPageIntoView({
  8993. pageNumber,
  8994. destArray = null,
  8995. allowNegativeOffset = false,
  8996. ignoreDestinationZoom = false
  8997. }) {
  8998. if (!this.pdfDocument) {
  8999. return;
  9000. }
  9001. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  9002. if (!pageView) {
  9003. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  9004. return;
  9005. }
  9006. if (this.isInPresentationMode || !destArray) {
  9007. this._setCurrentPageNumber(pageNumber, true);
  9008. return;
  9009. }
  9010. let x = 0,
  9011. y = 0;
  9012. let width = 0,
  9013. height = 0,
  9014. widthScale,
  9015. heightScale;
  9016. const changeOrientation = pageView.rotation % 180 !== 0;
  9017. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9018. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9019. let scale = 0;
  9020. switch (destArray[1].name) {
  9021. case "XYZ":
  9022. x = destArray[2];
  9023. y = destArray[3];
  9024. scale = destArray[4];
  9025. x = x !== null ? x : 0;
  9026. y = y !== null ? y : pageHeight;
  9027. break;
  9028. case "Fit":
  9029. case "FitB":
  9030. scale = "page-fit";
  9031. break;
  9032. case "FitH":
  9033. case "FitBH":
  9034. y = destArray[2];
  9035. scale = "page-width";
  9036. if (y === null && this._location) {
  9037. x = this._location.left;
  9038. y = this._location.top;
  9039. } else if (typeof y !== "number" || y < 0) {
  9040. y = pageHeight;
  9041. }
  9042. break;
  9043. case "FitV":
  9044. case "FitBV":
  9045. x = destArray[2];
  9046. width = pageWidth;
  9047. height = pageHeight;
  9048. scale = "page-height";
  9049. break;
  9050. case "FitR":
  9051. x = destArray[2];
  9052. y = destArray[3];
  9053. width = destArray[4] - x;
  9054. height = destArray[5] - y;
  9055. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  9056. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  9057. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9058. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9059. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  9060. break;
  9061. default:
  9062. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  9063. return;
  9064. }
  9065. if (!ignoreDestinationZoom) {
  9066. if (scale && scale !== this._currentScale) {
  9067. this.currentScaleValue = scale;
  9068. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  9069. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  9070. }
  9071. }
  9072. if (scale === "page-fit" && !destArray[4]) {
  9073. this.#scrollIntoView(pageView);
  9074. return;
  9075. }
  9076. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  9077. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  9078. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  9079. if (!allowNegativeOffset) {
  9080. left = Math.max(left, 0);
  9081. top = Math.max(top, 0);
  9082. }
  9083. this.#scrollIntoView(pageView, {
  9084. left,
  9085. top
  9086. });
  9087. }
  9088. _updateLocation(firstPage) {
  9089. const currentScale = this._currentScale;
  9090. const currentScaleValue = this._currentScaleValue;
  9091. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  9092. const pageNumber = firstPage.id;
  9093. const currentPageView = this._pages[pageNumber - 1];
  9094. const container = this.container;
  9095. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  9096. const intLeft = Math.round(topLeft[0]);
  9097. const intTop = Math.round(topLeft[1]);
  9098. let pdfOpenParams = `#page=${pageNumber}`;
  9099. if (!this.isInPresentationMode) {
  9100. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  9101. }
  9102. this._location = {
  9103. pageNumber,
  9104. scale: normalizedScaleValue,
  9105. top: intTop,
  9106. left: intLeft,
  9107. rotation: this._pagesRotation,
  9108. pdfOpenParams
  9109. };
  9110. }
  9111. update() {
  9112. const visible = this._getVisiblePages();
  9113. const visiblePages = visible.views,
  9114. numVisiblePages = visiblePages.length;
  9115. if (numVisiblePages === 0) {
  9116. return;
  9117. }
  9118. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  9119. this.#buffer.resize(newCacheSize, visible.ids);
  9120. this.renderingQueue.renderHighestPriority(visible);
  9121. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  9122. const currentId = this._currentPageNumber;
  9123. let stillFullyVisible = false;
  9124. for (const page of visiblePages) {
  9125. if (page.percent < 100) {
  9126. break;
  9127. }
  9128. if (page.id === currentId && isSimpleLayout) {
  9129. stillFullyVisible = true;
  9130. break;
  9131. }
  9132. }
  9133. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  9134. this._updateLocation(visible.first);
  9135. this.eventBus.dispatch("updateviewarea", {
  9136. source: this,
  9137. location: this._location
  9138. });
  9139. }
  9140. containsElement(element) {
  9141. return this.container.contains(element);
  9142. }
  9143. focus() {
  9144. this.container.focus();
  9145. }
  9146. get _isContainerRtl() {
  9147. return getComputedStyle(this.container).direction === "rtl";
  9148. }
  9149. get isInPresentationMode() {
  9150. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  9151. }
  9152. get isChangingPresentationMode() {
  9153. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  9154. }
  9155. get isHorizontalScrollbarEnabled() {
  9156. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  9157. }
  9158. get isVerticalScrollbarEnabled() {
  9159. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  9160. }
  9161. _getVisiblePages() {
  9162. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  9163. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  9164. rtl = horizontal && this._isContainerRtl;
  9165. return (0, _ui_utils.getVisibleElements)({
  9166. scrollEl: this.container,
  9167. views,
  9168. sortByVisibility: true,
  9169. horizontal,
  9170. rtl
  9171. });
  9172. }
  9173. isPageVisible(pageNumber) {
  9174. if (!this.pdfDocument) {
  9175. return false;
  9176. }
  9177. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  9178. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  9179. return false;
  9180. }
  9181. return this._getVisiblePages().ids.has(pageNumber);
  9182. }
  9183. isPageCached(pageNumber) {
  9184. if (!this.pdfDocument) {
  9185. return false;
  9186. }
  9187. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  9188. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  9189. return false;
  9190. }
  9191. const pageView = this._pages[pageNumber - 1];
  9192. return this.#buffer.has(pageView);
  9193. }
  9194. cleanup() {
  9195. for (const pageView of this._pages) {
  9196. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  9197. pageView.reset();
  9198. }
  9199. }
  9200. }
  9201. _cancelRendering() {
  9202. for (const pageView of this._pages) {
  9203. pageView.cancelRendering();
  9204. }
  9205. }
  9206. async #ensurePdfPageLoaded(pageView) {
  9207. if (pageView.pdfPage) {
  9208. return pageView.pdfPage;
  9209. }
  9210. try {
  9211. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  9212. if (!pageView.pdfPage) {
  9213. pageView.setPdfPage(pdfPage);
  9214. }
  9215. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  9216. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  9217. }
  9218. return pdfPage;
  9219. } catch (reason) {
  9220. console.error("Unable to get page for page view", reason);
  9221. return null;
  9222. }
  9223. }
  9224. #getScrollAhead(visible) {
  9225. if (visible.first?.id === 1) {
  9226. return true;
  9227. } else if (visible.last?.id === this.pagesCount) {
  9228. return false;
  9229. }
  9230. switch (this._scrollMode) {
  9231. case _ui_utils.ScrollMode.PAGE:
  9232. return this.#scrollModePageState.scrollDown;
  9233. case _ui_utils.ScrollMode.HORIZONTAL:
  9234. return this.scroll.right;
  9235. }
  9236. return this.scroll.down;
  9237. }
  9238. forceRendering(currentlyVisiblePages) {
  9239. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9240. const scrollAhead = this.#getScrollAhead(visiblePages);
  9241. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9242. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9243. if (pageView) {
  9244. this.#ensurePdfPageLoaded(pageView).then(() => {
  9245. this.renderingQueue.renderView(pageView);
  9246. });
  9247. return true;
  9248. }
  9249. return false;
  9250. }
  9251. get hasEqualPageSizes() {
  9252. const firstPageView = this._pages[0];
  9253. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  9254. const pageView = this._pages[i];
  9255. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9256. return false;
  9257. }
  9258. }
  9259. return true;
  9260. }
  9261. getPagesOverview() {
  9262. return this._pages.map(pageView => {
  9263. const viewport = pageView.pdfPage.getViewport({
  9264. scale: 1
  9265. });
  9266. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  9267. return {
  9268. width: viewport.width,
  9269. height: viewport.height,
  9270. rotation: viewport.rotation
  9271. };
  9272. }
  9273. return {
  9274. width: viewport.height,
  9275. height: viewport.width,
  9276. rotation: (viewport.rotation - 90) % 360
  9277. };
  9278. });
  9279. }
  9280. get optionalContentConfigPromise() {
  9281. if (!this.pdfDocument) {
  9282. return Promise.resolve(null);
  9283. }
  9284. if (!this._optionalContentConfigPromise) {
  9285. console.error("optionalContentConfigPromise: Not initialized yet.");
  9286. return this.pdfDocument.getOptionalContentConfig();
  9287. }
  9288. return this._optionalContentConfigPromise;
  9289. }
  9290. set optionalContentConfigPromise(promise) {
  9291. if (!(promise instanceof Promise)) {
  9292. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  9293. }
  9294. if (!this.pdfDocument) {
  9295. return;
  9296. }
  9297. if (!this._optionalContentConfigPromise) {
  9298. return;
  9299. }
  9300. this._optionalContentConfigPromise = promise;
  9301. this.refresh(false, {
  9302. optionalContentConfigPromise: promise
  9303. });
  9304. this.eventBus.dispatch("optionalcontentconfigchanged", {
  9305. source: this,
  9306. promise
  9307. });
  9308. }
  9309. get scrollMode() {
  9310. return this._scrollMode;
  9311. }
  9312. set scrollMode(mode) {
  9313. if (this._scrollMode === mode) {
  9314. return;
  9315. }
  9316. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9317. throw new Error(`Invalid scroll mode: ${mode}`);
  9318. }
  9319. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9320. return;
  9321. }
  9322. this._previousScrollMode = this._scrollMode;
  9323. this._scrollMode = mode;
  9324. this.eventBus.dispatch("scrollmodechanged", {
  9325. source: this,
  9326. mode
  9327. });
  9328. this._updateScrollMode(this._currentPageNumber);
  9329. }
  9330. _updateScrollMode(pageNumber = null) {
  9331. const scrollMode = this._scrollMode,
  9332. viewer = this.viewer;
  9333. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9334. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9335. if (!this.pdfDocument || !pageNumber) {
  9336. return;
  9337. }
  9338. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9339. this.#ensurePageViewVisible();
  9340. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9341. this._updateSpreadMode();
  9342. }
  9343. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9344. this._setScale(this._currentScaleValue, {
  9345. noScroll: true
  9346. });
  9347. }
  9348. this._setCurrentPageNumber(pageNumber, true);
  9349. this.update();
  9350. }
  9351. get spreadMode() {
  9352. return this._spreadMode;
  9353. }
  9354. set spreadMode(mode) {
  9355. if (this._spreadMode === mode) {
  9356. return;
  9357. }
  9358. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9359. throw new Error(`Invalid spread mode: ${mode}`);
  9360. }
  9361. this._spreadMode = mode;
  9362. this.eventBus.dispatch("spreadmodechanged", {
  9363. source: this,
  9364. mode
  9365. });
  9366. this._updateSpreadMode(this._currentPageNumber);
  9367. }
  9368. _updateSpreadMode(pageNumber = null) {
  9369. if (!this.pdfDocument) {
  9370. return;
  9371. }
  9372. const viewer = this.viewer,
  9373. pages = this._pages;
  9374. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9375. this.#ensurePageViewVisible();
  9376. } else {
  9377. viewer.textContent = "";
  9378. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9379. for (const pageView of this._pages) {
  9380. viewer.append(pageView.div);
  9381. }
  9382. } else {
  9383. const parity = this._spreadMode - 1;
  9384. let spread = null;
  9385. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9386. if (spread === null) {
  9387. spread = document.createElement("div");
  9388. spread.className = "spread";
  9389. viewer.append(spread);
  9390. } else if (i % 2 === parity) {
  9391. spread = spread.cloneNode(false);
  9392. viewer.append(spread);
  9393. }
  9394. spread.append(pages[i].div);
  9395. }
  9396. }
  9397. }
  9398. if (!pageNumber) {
  9399. return;
  9400. }
  9401. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9402. this._setScale(this._currentScaleValue, {
  9403. noScroll: true
  9404. });
  9405. }
  9406. this._setCurrentPageNumber(pageNumber, true);
  9407. this.update();
  9408. }
  9409. _getPageAdvance(currentPageNumber, previous = false) {
  9410. switch (this._scrollMode) {
  9411. case _ui_utils.ScrollMode.WRAPPED:
  9412. {
  9413. const {
  9414. views
  9415. } = this._getVisiblePages(),
  9416. pageLayout = new Map();
  9417. for (const {
  9418. id,
  9419. y,
  9420. percent,
  9421. widthPercent
  9422. } of views) {
  9423. if (percent === 0 || widthPercent < 100) {
  9424. continue;
  9425. }
  9426. let yArray = pageLayout.get(y);
  9427. if (!yArray) {
  9428. pageLayout.set(y, yArray ||= []);
  9429. }
  9430. yArray.push(id);
  9431. }
  9432. for (const yArray of pageLayout.values()) {
  9433. const currentIndex = yArray.indexOf(currentPageNumber);
  9434. if (currentIndex === -1) {
  9435. continue;
  9436. }
  9437. const numPages = yArray.length;
  9438. if (numPages === 1) {
  9439. break;
  9440. }
  9441. if (previous) {
  9442. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9443. const currentId = yArray[i],
  9444. expectedId = yArray[i + 1] - 1;
  9445. if (currentId < expectedId) {
  9446. return currentPageNumber - expectedId;
  9447. }
  9448. }
  9449. } else {
  9450. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9451. const currentId = yArray[i],
  9452. expectedId = yArray[i - 1] + 1;
  9453. if (currentId > expectedId) {
  9454. return expectedId - currentPageNumber;
  9455. }
  9456. }
  9457. }
  9458. if (previous) {
  9459. const firstId = yArray[0];
  9460. if (firstId < currentPageNumber) {
  9461. return currentPageNumber - firstId + 1;
  9462. }
  9463. } else {
  9464. const lastId = yArray[numPages - 1];
  9465. if (lastId > currentPageNumber) {
  9466. return lastId - currentPageNumber + 1;
  9467. }
  9468. }
  9469. break;
  9470. }
  9471. break;
  9472. }
  9473. case _ui_utils.ScrollMode.HORIZONTAL:
  9474. {
  9475. break;
  9476. }
  9477. case _ui_utils.ScrollMode.PAGE:
  9478. case _ui_utils.ScrollMode.VERTICAL:
  9479. {
  9480. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9481. break;
  9482. }
  9483. const parity = this._spreadMode - 1;
  9484. if (previous && currentPageNumber % 2 !== parity) {
  9485. break;
  9486. } else if (!previous && currentPageNumber % 2 === parity) {
  9487. break;
  9488. }
  9489. const {
  9490. views
  9491. } = this._getVisiblePages(),
  9492. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9493. for (const {
  9494. id,
  9495. percent,
  9496. widthPercent
  9497. } of views) {
  9498. if (id !== expectedId) {
  9499. continue;
  9500. }
  9501. if (percent > 0 && widthPercent === 100) {
  9502. return 2;
  9503. }
  9504. break;
  9505. }
  9506. break;
  9507. }
  9508. }
  9509. return 1;
  9510. }
  9511. nextPage() {
  9512. const currentPageNumber = this._currentPageNumber,
  9513. pagesCount = this.pagesCount;
  9514. if (currentPageNumber >= pagesCount) {
  9515. return false;
  9516. }
  9517. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9518. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9519. return true;
  9520. }
  9521. previousPage() {
  9522. const currentPageNumber = this._currentPageNumber;
  9523. if (currentPageNumber <= 1) {
  9524. return false;
  9525. }
  9526. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9527. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9528. return true;
  9529. }
  9530. increaseScale(options = null) {
  9531. if (typeof options === "number") {
  9532. console.error("The `increaseScale` method-signature was updated, please use an object instead.");
  9533. options = {
  9534. steps: options
  9535. };
  9536. }
  9537. if (!this.pdfDocument) {
  9538. return;
  9539. }
  9540. options ||= Object.create(null);
  9541. let newScale = this._currentScale;
  9542. if (options.scaleFactor > 1) {
  9543. newScale = Math.min(_ui_utils.MAX_SCALE, Math.round(newScale * options.scaleFactor * 100) / 100);
  9544. } else {
  9545. let steps = options.steps ?? 1;
  9546. do {
  9547. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9548. newScale = Math.ceil(newScale * 10) / 10;
  9549. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  9550. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9551. }
  9552. options.noScroll = false;
  9553. this._setScale(newScale, options);
  9554. }
  9555. decreaseScale(options = null) {
  9556. if (typeof options === "number") {
  9557. console.error("The `decreaseScale` method-signature was updated, please use an object instead.");
  9558. options = {
  9559. steps: options
  9560. };
  9561. }
  9562. if (!this.pdfDocument) {
  9563. return;
  9564. }
  9565. options ||= Object.create(null);
  9566. let newScale = this._currentScale;
  9567. if (options.scaleFactor > 0 && options.scaleFactor < 1) {
  9568. newScale = Math.max(_ui_utils.MIN_SCALE, Math.round(newScale * options.scaleFactor * 100) / 100);
  9569. } else {
  9570. let steps = options.steps ?? 1;
  9571. do {
  9572. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9573. newScale = Math.floor(newScale * 10) / 10;
  9574. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  9575. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9576. }
  9577. options.noScroll = false;
  9578. this._setScale(newScale, options);
  9579. }
  9580. #updateContainerHeightCss(height = this.container.clientHeight) {
  9581. if (height !== this.#previousContainerHeight) {
  9582. this.#previousContainerHeight = height;
  9583. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  9584. }
  9585. }
  9586. #resizeObserverCallback(entries) {
  9587. for (const entry of entries) {
  9588. if (entry.target === this.container) {
  9589. this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
  9590. this.#containerTopLeft = null;
  9591. break;
  9592. }
  9593. }
  9594. }
  9595. get containerTopLeft() {
  9596. return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
  9597. }
  9598. get annotationEditorMode() {
  9599. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  9600. }
  9601. set annotationEditorMode(mode) {
  9602. if (!this.#annotationEditorUIManager) {
  9603. throw new Error(`The AnnotationEditor is not enabled.`);
  9604. }
  9605. if (this.#annotationEditorMode === mode) {
  9606. return;
  9607. }
  9608. if (!isValidAnnotationEditorMode(mode)) {
  9609. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  9610. }
  9611. if (!this.pdfDocument) {
  9612. return;
  9613. }
  9614. this.#annotationEditorMode = mode;
  9615. this.eventBus.dispatch("annotationeditormodechanged", {
  9616. source: this,
  9617. mode
  9618. });
  9619. this.#annotationEditorUIManager.updateMode(mode);
  9620. }
  9621. set annotationEditorParams({
  9622. type,
  9623. value
  9624. }) {
  9625. if (!this.#annotationEditorUIManager) {
  9626. throw new Error(`The AnnotationEditor is not enabled.`);
  9627. }
  9628. this.#annotationEditorUIManager.updateParams(type, value);
  9629. }
  9630. refresh(noUpdate = false, updateArgs = Object.create(null)) {
  9631. if (!this.pdfDocument) {
  9632. return;
  9633. }
  9634. for (const pageView of this._pages) {
  9635. pageView.update(updateArgs);
  9636. }
  9637. if (this.#scaleTimeoutId !== null) {
  9638. clearTimeout(this.#scaleTimeoutId);
  9639. this.#scaleTimeoutId = null;
  9640. }
  9641. if (!noUpdate) {
  9642. this.update();
  9643. }
  9644. }
  9645. }
  9646. exports.PDFViewer = PDFViewer;
  9647. /***/ }),
  9648. /* 29 */
  9649. /***/ ((__unused_webpack_module, exports) => {
  9650. Object.defineProperty(exports, "__esModule", ({
  9651. value: true
  9652. }));
  9653. exports.NullL10n = void 0;
  9654. exports.fixupLangCode = fixupLangCode;
  9655. exports.getL10nFallback = getL10nFallback;
  9656. const DEFAULT_L10N_STRINGS = {
  9657. of_pages: "of {{pagesCount}}",
  9658. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9659. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9660. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9661. document_properties_date_string: "{{date}}, {{time}}",
  9662. document_properties_page_size_unit_inches: "in",
  9663. document_properties_page_size_unit_millimeters: "mm",
  9664. document_properties_page_size_orientation_portrait: "portrait",
  9665. document_properties_page_size_orientation_landscape: "landscape",
  9666. document_properties_page_size_name_a3: "A3",
  9667. document_properties_page_size_name_a4: "A4",
  9668. document_properties_page_size_name_letter: "Letter",
  9669. document_properties_page_size_name_legal: "Legal",
  9670. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9671. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9672. document_properties_linearized_yes: "Yes",
  9673. document_properties_linearized_no: "No",
  9674. additional_layers: "Additional Layers",
  9675. page_landmark: "Page {{page}}",
  9676. thumb_page_title: "Page {{page}}",
  9677. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9678. find_reached_top: "Reached top of document, continued from bottom",
  9679. find_reached_bottom: "Reached end of document, continued from top",
  9680. "find_match_count[one]": "{{current}} of {{total}} match",
  9681. "find_match_count[other]": "{{current}} of {{total}} matches",
  9682. "find_match_count_limit[one]": "More than {{limit}} match",
  9683. "find_match_count_limit[other]": "More than {{limit}} matches",
  9684. find_not_found: "Phrase not found",
  9685. page_scale_width: "Page Width",
  9686. page_scale_fit: "Page Fit",
  9687. page_scale_auto: "Automatic Zoom",
  9688. page_scale_actual: "Actual Size",
  9689. page_scale_percent: "{{scale}}%",
  9690. loading: "Loading…",
  9691. loading_error: "An error occurred while loading the PDF.",
  9692. invalid_file_error: "Invalid or corrupted PDF file.",
  9693. missing_file_error: "Missing PDF file.",
  9694. unexpected_response_error: "Unexpected server response.",
  9695. rendering_error: "An error occurred while rendering the page.",
  9696. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9697. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9698. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  9699. free_text2_default_content: "Start typing…",
  9700. editor_free_text2_aria_label: "Text Editor",
  9701. editor_ink2_aria_label: "Draw Editor",
  9702. editor_ink_canvas_aria_label: "User-created image"
  9703. };
  9704. {
  9705. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  9706. }
  9707. function getL10nFallback(key, args) {
  9708. switch (key) {
  9709. case "find_match_count":
  9710. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9711. break;
  9712. case "find_match_count_limit":
  9713. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9714. break;
  9715. }
  9716. return DEFAULT_L10N_STRINGS[key] || "";
  9717. }
  9718. const PARTIAL_LANG_CODES = {
  9719. en: "en-US",
  9720. es: "es-ES",
  9721. fy: "fy-NL",
  9722. ga: "ga-IE",
  9723. gu: "gu-IN",
  9724. hi: "hi-IN",
  9725. hy: "hy-AM",
  9726. nb: "nb-NO",
  9727. ne: "ne-NP",
  9728. nn: "nn-NO",
  9729. pa: "pa-IN",
  9730. pt: "pt-PT",
  9731. sv: "sv-SE",
  9732. zh: "zh-CN"
  9733. };
  9734. function fixupLangCode(langCode) {
  9735. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9736. }
  9737. function formatL10nValue(text, args) {
  9738. if (!args) {
  9739. return text;
  9740. }
  9741. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9742. return name in args ? args[name] : "{{" + name + "}}";
  9743. });
  9744. }
  9745. const NullL10n = {
  9746. async getLanguage() {
  9747. return "en-us";
  9748. },
  9749. async getDirection() {
  9750. return "ltr";
  9751. },
  9752. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9753. return formatL10nValue(fallback, args);
  9754. },
  9755. async translate(element) {}
  9756. };
  9757. exports.NullL10n = NullL10n;
  9758. /***/ }),
  9759. /* 30 */
  9760. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9761. Object.defineProperty(exports, "__esModule", ({
  9762. value: true
  9763. }));
  9764. exports.PDFPageView = void 0;
  9765. var _pdfjsLib = __webpack_require__(5);
  9766. var _ui_utils = __webpack_require__(1);
  9767. var _annotation_editor_layer_builder = __webpack_require__(31);
  9768. var _annotation_layer_builder = __webpack_require__(32);
  9769. var _app_options = __webpack_require__(2);
  9770. var _l10n_utils = __webpack_require__(29);
  9771. var _struct_tree_layer_builder = __webpack_require__(33);
  9772. var _text_accessibility = __webpack_require__(34);
  9773. var _text_highlighter = __webpack_require__(35);
  9774. var _text_layer_builder = __webpack_require__(36);
  9775. var _xfa_layer_builder = __webpack_require__(37);
  9776. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9777. const DEFAULT_LAYER_PROPERTIES = () => {
  9778. return null;
  9779. };
  9780. class PDFPageView {
  9781. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9782. #layerProperties = null;
  9783. #previousRotation = null;
  9784. #renderingState = _ui_utils.RenderingStates.INITIAL;
  9785. #useThumbnailCanvas = {
  9786. initialOptionalContent: true,
  9787. regularAnnotations: true
  9788. };
  9789. constructor(options) {
  9790. const container = options.container;
  9791. const defaultViewport = options.defaultViewport;
  9792. this.id = options.id;
  9793. this.renderingId = "page" + this.id;
  9794. this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
  9795. this.pdfPage = null;
  9796. this.pageLabel = null;
  9797. this.rotation = 0;
  9798. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9799. this.viewport = defaultViewport;
  9800. this.pdfPageRotate = defaultViewport.rotation;
  9801. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9802. this.hasRestrictedScaling = false;
  9803. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9804. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9805. this.imageResourcesPath = options.imageResourcesPath || "";
  9806. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9807. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  9808. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9809. this.pageColors = options.pageColors || null;
  9810. this.eventBus = options.eventBus;
  9811. this.renderingQueue = options.renderingQueue;
  9812. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9813. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9814. this.paintTask = null;
  9815. this.paintedViewportMap = new WeakMap();
  9816. this.resume = null;
  9817. this._renderError = null;
  9818. this._isStandalone = !this.renderingQueue?.hasViewer();
  9819. this._annotationCanvasMap = null;
  9820. this.annotationLayer = null;
  9821. this.annotationEditorLayer = null;
  9822. this.textLayer = null;
  9823. this.zoomLayer = null;
  9824. this.xfaLayer = null;
  9825. this.structTreeLayer = null;
  9826. const div = document.createElement("div");
  9827. div.className = "page";
  9828. div.setAttribute("data-page-number", this.id);
  9829. div.setAttribute("role", "region");
  9830. this.l10n.get("page_landmark", {
  9831. page: this.id
  9832. }).then(msg => {
  9833. div.setAttribute("aria-label", msg);
  9834. });
  9835. this.div = div;
  9836. this.#setDimensions();
  9837. container?.append(div);
  9838. if (this._isStandalone) {
  9839. container?.style.setProperty("--scale-factor", this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  9840. const {
  9841. optionalContentConfigPromise
  9842. } = options;
  9843. if (optionalContentConfigPromise) {
  9844. optionalContentConfigPromise.then(optionalContentConfig => {
  9845. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9846. return;
  9847. }
  9848. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9849. });
  9850. }
  9851. }
  9852. }
  9853. get renderingState() {
  9854. return this.#renderingState;
  9855. }
  9856. set renderingState(state) {
  9857. this.#renderingState = state;
  9858. switch (state) {
  9859. case _ui_utils.RenderingStates.INITIAL:
  9860. case _ui_utils.RenderingStates.PAUSED:
  9861. this.loadingIconDiv?.classList.add("notVisible");
  9862. break;
  9863. case _ui_utils.RenderingStates.RUNNING:
  9864. this.loadingIconDiv?.classList.remove("notVisible");
  9865. break;
  9866. case _ui_utils.RenderingStates.FINISHED:
  9867. if (this.loadingIconDiv) {
  9868. this.loadingIconDiv.remove();
  9869. delete this.loadingIconDiv;
  9870. }
  9871. break;
  9872. }
  9873. }
  9874. #setDimensions() {
  9875. const {
  9876. viewport
  9877. } = this;
  9878. if (this.pdfPage) {
  9879. if (this.#previousRotation === viewport.rotation) {
  9880. return;
  9881. }
  9882. this.#previousRotation = viewport.rotation;
  9883. }
  9884. (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false);
  9885. }
  9886. setPdfPage(pdfPage) {
  9887. this.pdfPage = pdfPage;
  9888. this.pdfPageRotate = pdfPage.rotate;
  9889. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9890. this.viewport = pdfPage.getViewport({
  9891. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9892. rotation: totalRotation
  9893. });
  9894. this.#setDimensions();
  9895. this.reset();
  9896. }
  9897. destroy() {
  9898. this.reset();
  9899. this.pdfPage?.cleanup();
  9900. }
  9901. get _textHighlighter() {
  9902. return (0, _pdfjsLib.shadow)(this, "_textHighlighter", new _text_highlighter.TextHighlighter({
  9903. pageIndex: this.id - 1,
  9904. eventBus: this.eventBus,
  9905. findController: this.#layerProperties().findController
  9906. }));
  9907. }
  9908. async #renderAnnotationLayer() {
  9909. let error = null;
  9910. try {
  9911. await this.annotationLayer.render(this.viewport, "display");
  9912. } catch (ex) {
  9913. console.error(`#renderAnnotationLayer: "${ex}".`);
  9914. error = ex;
  9915. } finally {
  9916. this.eventBus.dispatch("annotationlayerrendered", {
  9917. source: this,
  9918. pageNumber: this.id,
  9919. error
  9920. });
  9921. }
  9922. }
  9923. async #renderAnnotationEditorLayer() {
  9924. let error = null;
  9925. try {
  9926. await this.annotationEditorLayer.render(this.viewport, "display");
  9927. } catch (ex) {
  9928. console.error(`#renderAnnotationEditorLayer: "${ex}".`);
  9929. error = ex;
  9930. } finally {
  9931. this.eventBus.dispatch("annotationeditorlayerrendered", {
  9932. source: this,
  9933. pageNumber: this.id,
  9934. error
  9935. });
  9936. }
  9937. }
  9938. async #renderXfaLayer() {
  9939. let error = null;
  9940. try {
  9941. const result = await this.xfaLayer.render(this.viewport, "display");
  9942. if (result?.textDivs && this._textHighlighter) {
  9943. this.#buildXfaTextContentItems(result.textDivs);
  9944. }
  9945. } catch (ex) {
  9946. console.error(`#renderXfaLayer: "${ex}".`);
  9947. error = ex;
  9948. } finally {
  9949. this.eventBus.dispatch("xfalayerrendered", {
  9950. source: this,
  9951. pageNumber: this.id,
  9952. error
  9953. });
  9954. }
  9955. }
  9956. async #renderTextLayer() {
  9957. const {
  9958. pdfPage,
  9959. textLayer,
  9960. viewport
  9961. } = this;
  9962. if (!textLayer) {
  9963. return;
  9964. }
  9965. let error = null;
  9966. try {
  9967. if (!textLayer.renderingDone) {
  9968. const readableStream = pdfPage.streamTextContent({
  9969. includeMarkedContent: true
  9970. });
  9971. textLayer.setTextContentSource(readableStream);
  9972. }
  9973. await textLayer.render(viewport);
  9974. } catch (ex) {
  9975. if (ex instanceof _pdfjsLib.AbortException) {
  9976. return;
  9977. }
  9978. console.error(`#renderTextLayer: "${ex}".`);
  9979. error = ex;
  9980. }
  9981. this.eventBus.dispatch("textlayerrendered", {
  9982. source: this,
  9983. pageNumber: this.id,
  9984. numTextDivs: textLayer.numTextDivs,
  9985. error
  9986. });
  9987. this.#renderStructTreeLayer();
  9988. }
  9989. async #renderStructTreeLayer() {
  9990. if (!this.textLayer) {
  9991. return;
  9992. }
  9993. this.structTreeLayer ||= new _struct_tree_layer_builder.StructTreeLayerBuilder();
  9994. const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
  9995. const treeDom = this.structTreeLayer?.render(tree);
  9996. if (treeDom) {
  9997. this.canvas?.append(treeDom);
  9998. }
  9999. }
  10000. async #buildXfaTextContentItems(textDivs) {
  10001. const text = await this.pdfPage.getTextContent();
  10002. const items = [];
  10003. for (const item of text.items) {
  10004. items.push(item.str);
  10005. }
  10006. this._textHighlighter.setTextMapping(textDivs, items);
  10007. this._textHighlighter.enable();
  10008. }
  10009. _resetZoomLayer(removeFromDOM = false) {
  10010. if (!this.zoomLayer) {
  10011. return;
  10012. }
  10013. const zoomLayerCanvas = this.zoomLayer.firstChild;
  10014. this.paintedViewportMap.delete(zoomLayerCanvas);
  10015. zoomLayerCanvas.width = 0;
  10016. zoomLayerCanvas.height = 0;
  10017. if (removeFromDOM) {
  10018. this.zoomLayer.remove();
  10019. }
  10020. this.zoomLayer = null;
  10021. }
  10022. reset({
  10023. keepZoomLayer = false,
  10024. keepAnnotationLayer = false,
  10025. keepAnnotationEditorLayer = false,
  10026. keepXfaLayer = false,
  10027. keepTextLayer = false
  10028. } = {}) {
  10029. this.cancelRendering({
  10030. keepAnnotationLayer,
  10031. keepAnnotationEditorLayer,
  10032. keepXfaLayer,
  10033. keepTextLayer
  10034. });
  10035. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  10036. const div = this.div;
  10037. const childNodes = div.childNodes,
  10038. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  10039. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  10040. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  10041. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
  10042. textLayerNode = keepTextLayer && this.textLayer?.div || null;
  10043. for (let i = childNodes.length - 1; i >= 0; i--) {
  10044. const node = childNodes[i];
  10045. switch (node) {
  10046. case zoomLayerNode:
  10047. case annotationLayerNode:
  10048. case annotationEditorLayerNode:
  10049. case xfaLayerNode:
  10050. case textLayerNode:
  10051. case this.loadingIconDiv:
  10052. continue;
  10053. }
  10054. node.remove();
  10055. }
  10056. div.removeAttribute("data-loaded");
  10057. if (annotationLayerNode) {
  10058. this.annotationLayer.hide();
  10059. }
  10060. if (annotationEditorLayerNode) {
  10061. this.annotationEditorLayer.hide();
  10062. }
  10063. if (xfaLayerNode) {
  10064. this.xfaLayer.hide();
  10065. }
  10066. if (textLayerNode) {
  10067. this.textLayer.hide();
  10068. }
  10069. if (!zoomLayerNode) {
  10070. if (this.canvas) {
  10071. this.paintedViewportMap.delete(this.canvas);
  10072. this.canvas.width = 0;
  10073. this.canvas.height = 0;
  10074. delete this.canvas;
  10075. }
  10076. this._resetZoomLayer();
  10077. }
  10078. if (this.svg) {
  10079. this.paintedViewportMap.delete(this.svg);
  10080. delete this.svg;
  10081. }
  10082. if (!this.loadingIconDiv) {
  10083. this.loadingIconDiv = document.createElement("div");
  10084. this.loadingIconDiv.className = "loadingIcon notVisible";
  10085. this.loadingIconDiv.setAttribute("role", "img");
  10086. this.l10n.get("loading").then(msg => {
  10087. this.loadingIconDiv?.setAttribute("aria-label", msg);
  10088. });
  10089. div.append(this.loadingIconDiv);
  10090. }
  10091. }
  10092. update({
  10093. scale = 0,
  10094. rotation = null,
  10095. optionalContentConfigPromise = null,
  10096. drawingDelay = -1
  10097. }) {
  10098. this.scale = scale || this.scale;
  10099. if (typeof rotation === "number") {
  10100. this.rotation = rotation;
  10101. }
  10102. if (optionalContentConfigPromise instanceof Promise) {
  10103. this._optionalContentConfigPromise = optionalContentConfigPromise;
  10104. optionalContentConfigPromise.then(optionalContentConfig => {
  10105. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  10106. return;
  10107. }
  10108. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  10109. });
  10110. }
  10111. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  10112. this.viewport = this.viewport.clone({
  10113. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  10114. rotation: totalRotation
  10115. });
  10116. this.#setDimensions();
  10117. if (this._isStandalone) {
  10118. this.div.parentNode?.style.setProperty("--scale-factor", this.viewport.scale);
  10119. }
  10120. if (this.svg) {
  10121. this.cssTransform({
  10122. target: this.svg,
  10123. redrawAnnotationLayer: true,
  10124. redrawAnnotationEditorLayer: true,
  10125. redrawXfaLayer: true,
  10126. redrawTextLayer: true
  10127. });
  10128. this.eventBus.dispatch("pagerendered", {
  10129. source: this,
  10130. pageNumber: this.id,
  10131. cssTransform: true,
  10132. timestamp: performance.now(),
  10133. error: this._renderError
  10134. });
  10135. return;
  10136. }
  10137. let isScalingRestricted = false;
  10138. if (this.canvas && this.maxCanvasPixels > 0) {
  10139. const outputScale = this.outputScale;
  10140. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  10141. isScalingRestricted = true;
  10142. }
  10143. }
  10144. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  10145. if (this.canvas) {
  10146. if (postponeDrawing || this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  10147. if (postponeDrawing && this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  10148. this.cancelRendering({
  10149. keepZoomLayer: true,
  10150. keepAnnotationLayer: true,
  10151. keepAnnotationEditorLayer: true,
  10152. keepXfaLayer: true,
  10153. keepTextLayer: true,
  10154. cancelExtraDelay: drawingDelay
  10155. });
  10156. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10157. }
  10158. this.cssTransform({
  10159. target: this.canvas,
  10160. redrawAnnotationLayer: true,
  10161. redrawAnnotationEditorLayer: true,
  10162. redrawXfaLayer: true,
  10163. redrawTextLayer: !postponeDrawing,
  10164. hideTextLayer: postponeDrawing
  10165. });
  10166. this.eventBus.dispatch("pagerendered", {
  10167. source: this,
  10168. pageNumber: this.id,
  10169. cssTransform: true,
  10170. timestamp: performance.now(),
  10171. error: this._renderError
  10172. });
  10173. return;
  10174. }
  10175. if (!this.zoomLayer && !this.canvas.hidden) {
  10176. this.zoomLayer = this.canvas.parentNode;
  10177. this.zoomLayer.style.position = "absolute";
  10178. }
  10179. }
  10180. if (this.zoomLayer) {
  10181. this.cssTransform({
  10182. target: this.zoomLayer.firstChild
  10183. });
  10184. }
  10185. this.reset({
  10186. keepZoomLayer: true,
  10187. keepAnnotationLayer: true,
  10188. keepAnnotationEditorLayer: true,
  10189. keepXfaLayer: true,
  10190. keepTextLayer: true
  10191. });
  10192. }
  10193. cancelRendering({
  10194. keepAnnotationLayer = false,
  10195. keepAnnotationEditorLayer = false,
  10196. keepXfaLayer = false,
  10197. keepTextLayer = false,
  10198. cancelExtraDelay = 0
  10199. } = {}) {
  10200. if (this.paintTask) {
  10201. this.paintTask.cancel(cancelExtraDelay);
  10202. this.paintTask = null;
  10203. }
  10204. this.resume = null;
  10205. if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
  10206. this.textLayer.cancel();
  10207. this.textLayer = null;
  10208. }
  10209. if (this.structTreeLayer && !this.textLayer) {
  10210. this.structTreeLayer = null;
  10211. }
  10212. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  10213. this.annotationLayer.cancel();
  10214. this.annotationLayer = null;
  10215. this._annotationCanvasMap = null;
  10216. }
  10217. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  10218. this.annotationEditorLayer.cancel();
  10219. this.annotationEditorLayer = null;
  10220. }
  10221. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  10222. this.xfaLayer.cancel();
  10223. this.xfaLayer = null;
  10224. this._textHighlighter?.disable();
  10225. }
  10226. }
  10227. cssTransform({
  10228. target,
  10229. redrawAnnotationLayer = false,
  10230. redrawAnnotationEditorLayer = false,
  10231. redrawXfaLayer = false,
  10232. redrawTextLayer = false,
  10233. hideTextLayer = false
  10234. }) {
  10235. if (target instanceof HTMLCanvasElement) {
  10236. if (!target.hasAttribute("zooming")) {
  10237. target.setAttribute("zooming", true);
  10238. const {
  10239. style
  10240. } = target;
  10241. style.width = style.height = "";
  10242. }
  10243. } else {
  10244. const div = this.div;
  10245. const {
  10246. width,
  10247. height
  10248. } = this.viewport;
  10249. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  10250. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  10251. }
  10252. const originalViewport = this.paintedViewportMap.get(target);
  10253. if (this.viewport !== originalViewport) {
  10254. const relativeRotation = this.viewport.rotation - originalViewport.rotation;
  10255. const absRotation = Math.abs(relativeRotation);
  10256. let scaleX = 1,
  10257. scaleY = 1;
  10258. if (absRotation === 90 || absRotation === 270) {
  10259. const {
  10260. width,
  10261. height
  10262. } = this.viewport;
  10263. scaleX = height / width;
  10264. scaleY = width / height;
  10265. }
  10266. if (absRotation !== 0) {
  10267. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  10268. }
  10269. }
  10270. if (redrawAnnotationLayer && this.annotationLayer) {
  10271. this.#renderAnnotationLayer();
  10272. }
  10273. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  10274. this.#renderAnnotationEditorLayer();
  10275. }
  10276. if (redrawXfaLayer && this.xfaLayer) {
  10277. this.#renderXfaLayer();
  10278. }
  10279. if (this.textLayer) {
  10280. if (hideTextLayer) {
  10281. this.textLayer.hide();
  10282. } else if (redrawTextLayer) {
  10283. this.#renderTextLayer();
  10284. }
  10285. }
  10286. }
  10287. get width() {
  10288. return this.viewport.width;
  10289. }
  10290. get height() {
  10291. return this.viewport.height;
  10292. }
  10293. getPagePoint(x, y) {
  10294. return this.viewport.convertToPdfPoint(x, y);
  10295. }
  10296. draw() {
  10297. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  10298. console.error("Must be in new state before drawing");
  10299. this.reset();
  10300. }
  10301. const {
  10302. div,
  10303. pdfPage
  10304. } = this;
  10305. if (!pdfPage) {
  10306. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10307. return Promise.reject(new Error("pdfPage is not loaded"));
  10308. }
  10309. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10310. const canvasWrapper = document.createElement("div");
  10311. canvasWrapper.classList.add("canvasWrapper");
  10312. div.append(canvasWrapper);
  10313. if (!this.textLayer && this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
  10314. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  10315. this.textLayer = new _text_layer_builder.TextLayerBuilder({
  10316. highlighter: this._textHighlighter,
  10317. accessibilityManager: this._accessibilityManager,
  10318. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
  10319. });
  10320. div.append(this.textLayer.div);
  10321. }
  10322. if (!this.annotationLayer && this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE) {
  10323. const {
  10324. annotationStorage,
  10325. downloadManager,
  10326. enableScripting,
  10327. fieldObjectsPromise,
  10328. hasJSActionsPromise,
  10329. linkService
  10330. } = this.#layerProperties();
  10331. this._annotationCanvasMap ||= new Map();
  10332. this.annotationLayer = new _annotation_layer_builder.AnnotationLayerBuilder({
  10333. pageDiv: div,
  10334. pdfPage,
  10335. annotationStorage,
  10336. imageResourcesPath: this.imageResourcesPath,
  10337. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  10338. linkService,
  10339. downloadManager,
  10340. l10n: this.l10n,
  10341. enableScripting,
  10342. hasJSActionsPromise,
  10343. fieldObjectsPromise,
  10344. annotationCanvasMap: this._annotationCanvasMap,
  10345. accessibilityManager: this._accessibilityManager
  10346. });
  10347. }
  10348. if (this.xfaLayer?.div) {
  10349. div.append(this.xfaLayer.div);
  10350. }
  10351. let renderContinueCallback = null;
  10352. if (this.renderingQueue) {
  10353. renderContinueCallback = cont => {
  10354. if (!this.renderingQueue.isHighestPriority(this)) {
  10355. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  10356. this.resume = () => {
  10357. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10358. cont();
  10359. };
  10360. return;
  10361. }
  10362. cont();
  10363. };
  10364. }
  10365. const finishPaintTask = async (error = null) => {
  10366. if (paintTask === this.paintTask) {
  10367. this.paintTask = null;
  10368. }
  10369. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  10370. this._renderError = null;
  10371. return;
  10372. }
  10373. this._renderError = error;
  10374. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10375. this._resetZoomLayer(true);
  10376. this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
  10377. this.eventBus.dispatch("pagerendered", {
  10378. source: this,
  10379. pageNumber: this.id,
  10380. cssTransform: false,
  10381. timestamp: performance.now(),
  10382. error: this._renderError
  10383. });
  10384. if (error) {
  10385. throw error;
  10386. }
  10387. };
  10388. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  10389. paintTask.onRenderContinue = renderContinueCallback;
  10390. this.paintTask = paintTask;
  10391. const resultPromise = paintTask.promise.then(() => {
  10392. return finishPaintTask(null).then(async () => {
  10393. this.#renderTextLayer();
  10394. if (this.annotationLayer) {
  10395. await this.#renderAnnotationLayer();
  10396. }
  10397. if (!this.annotationEditorLayer) {
  10398. const {
  10399. annotationEditorUIManager
  10400. } = this.#layerProperties();
  10401. if (!annotationEditorUIManager) {
  10402. return;
  10403. }
  10404. this.annotationEditorLayer = new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  10405. uiManager: annotationEditorUIManager,
  10406. pageDiv: div,
  10407. pdfPage,
  10408. l10n: this.l10n,
  10409. accessibilityManager: this._accessibilityManager
  10410. });
  10411. }
  10412. this.#renderAnnotationEditorLayer();
  10413. });
  10414. }, function (reason) {
  10415. return finishPaintTask(reason);
  10416. });
  10417. if (pdfPage.isPureXfa) {
  10418. if (!this.xfaLayer) {
  10419. const {
  10420. annotationStorage,
  10421. linkService
  10422. } = this.#layerProperties();
  10423. this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({
  10424. pageDiv: div,
  10425. pdfPage,
  10426. annotationStorage,
  10427. linkService
  10428. });
  10429. }
  10430. this.#renderXfaLayer();
  10431. }
  10432. div.setAttribute("data-loaded", true);
  10433. this.eventBus.dispatch("pagerender", {
  10434. source: this,
  10435. pageNumber: this.id
  10436. });
  10437. return resultPromise;
  10438. }
  10439. paintOnCanvas(canvasWrapper) {
  10440. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  10441. const result = {
  10442. promise: renderCapability.promise,
  10443. onRenderContinue(cont) {
  10444. cont();
  10445. },
  10446. cancel(extraDelay = 0) {
  10447. renderTask.cancel(extraDelay);
  10448. },
  10449. get separateAnnots() {
  10450. return renderTask.separateAnnots;
  10451. }
  10452. };
  10453. const viewport = this.viewport;
  10454. const {
  10455. width,
  10456. height
  10457. } = viewport;
  10458. const canvas = document.createElement("canvas");
  10459. canvas.setAttribute("role", "presentation");
  10460. canvas.hidden = true;
  10461. let isCanvasHidden = true;
  10462. const showCanvas = function () {
  10463. if (isCanvasHidden) {
  10464. canvas.hidden = false;
  10465. isCanvasHidden = false;
  10466. }
  10467. };
  10468. canvasWrapper.append(canvas);
  10469. this.canvas = canvas;
  10470. const ctx = canvas.getContext("2d", {
  10471. alpha: false
  10472. });
  10473. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  10474. if (this.useOnlyCssZoom) {
  10475. const actualSizeViewport = viewport.clone({
  10476. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10477. });
  10478. outputScale.sx *= actualSizeViewport.width / width;
  10479. outputScale.sy *= actualSizeViewport.height / height;
  10480. }
  10481. if (this.maxCanvasPixels > 0) {
  10482. const pixelsInViewport = width * height;
  10483. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  10484. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  10485. outputScale.sx = maxScale;
  10486. outputScale.sy = maxScale;
  10487. this.hasRestrictedScaling = true;
  10488. } else {
  10489. this.hasRestrictedScaling = false;
  10490. }
  10491. }
  10492. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  10493. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  10494. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  10495. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  10496. const {
  10497. style
  10498. } = canvas;
  10499. style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  10500. style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  10501. this.paintedViewportMap.set(canvas, viewport);
  10502. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10503. const renderContext = {
  10504. canvasContext: ctx,
  10505. transform,
  10506. viewport,
  10507. annotationMode: this.#annotationMode,
  10508. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10509. annotationCanvasMap: this._annotationCanvasMap,
  10510. pageColors: this.pageColors
  10511. };
  10512. const renderTask = this.pdfPage.render(renderContext);
  10513. renderTask.onContinue = function (cont) {
  10514. showCanvas();
  10515. if (result.onRenderContinue) {
  10516. result.onRenderContinue(cont);
  10517. } else {
  10518. cont();
  10519. }
  10520. };
  10521. renderTask.promise.then(function () {
  10522. showCanvas();
  10523. renderCapability.resolve();
  10524. }, function (error) {
  10525. if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
  10526. showCanvas();
  10527. }
  10528. renderCapability.reject(error);
  10529. });
  10530. return result;
  10531. }
  10532. paintOnSvg(wrapper) {
  10533. let cancelled = false;
  10534. const ensureNotCancelled = () => {
  10535. if (cancelled) {
  10536. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  10537. }
  10538. };
  10539. const pdfPage = this.pdfPage;
  10540. const actualSizeViewport = this.viewport.clone({
  10541. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10542. });
  10543. const promise = pdfPage.getOperatorList({
  10544. annotationMode: this.#annotationMode
  10545. }).then(opList => {
  10546. ensureNotCancelled();
  10547. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  10548. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  10549. ensureNotCancelled();
  10550. this.svg = svg;
  10551. this.paintedViewportMap.set(svg, actualSizeViewport);
  10552. svg.style.width = wrapper.style.width;
  10553. svg.style.height = wrapper.style.height;
  10554. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10555. wrapper.append(svg);
  10556. });
  10557. });
  10558. return {
  10559. promise,
  10560. onRenderContinue(cont) {
  10561. cont();
  10562. },
  10563. cancel() {
  10564. cancelled = true;
  10565. },
  10566. get separateAnnots() {
  10567. return false;
  10568. }
  10569. };
  10570. }
  10571. setPageLabel(label) {
  10572. this.pageLabel = typeof label === "string" ? label : null;
  10573. if (this.pageLabel !== null) {
  10574. this.div.setAttribute("data-page-label", this.pageLabel);
  10575. } else {
  10576. this.div.removeAttribute("data-page-label");
  10577. }
  10578. }
  10579. get thumbnailCanvas() {
  10580. const {
  10581. initialOptionalContent,
  10582. regularAnnotations
  10583. } = this.#useThumbnailCanvas;
  10584. return initialOptionalContent && regularAnnotations ? this.canvas : null;
  10585. }
  10586. }
  10587. exports.PDFPageView = PDFPageView;
  10588. /***/ }),
  10589. /* 31 */
  10590. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10591. Object.defineProperty(exports, "__esModule", ({
  10592. value: true
  10593. }));
  10594. exports.AnnotationEditorLayerBuilder = void 0;
  10595. var _pdfjsLib = __webpack_require__(5);
  10596. var _l10n_utils = __webpack_require__(29);
  10597. class AnnotationEditorLayerBuilder {
  10598. #uiManager;
  10599. constructor(options) {
  10600. this.pageDiv = options.pageDiv;
  10601. this.pdfPage = options.pdfPage;
  10602. this.accessibilityManager = options.accessibilityManager;
  10603. this.l10n = options.l10n || _l10n_utils.NullL10n;
  10604. this.annotationEditorLayer = null;
  10605. this.div = null;
  10606. this._cancelled = false;
  10607. this.#uiManager = options.uiManager;
  10608. }
  10609. async render(viewport, intent = "display") {
  10610. if (intent !== "display") {
  10611. return;
  10612. }
  10613. if (this._cancelled) {
  10614. return;
  10615. }
  10616. const clonedViewport = viewport.clone({
  10617. dontFlip: true
  10618. });
  10619. if (this.div) {
  10620. this.annotationEditorLayer.update({
  10621. viewport: clonedViewport
  10622. });
  10623. this.show();
  10624. return;
  10625. }
  10626. const div = this.div = document.createElement("div");
  10627. div.className = "annotationEditorLayer";
  10628. div.tabIndex = 0;
  10629. this.pageDiv.append(div);
  10630. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  10631. uiManager: this.#uiManager,
  10632. div,
  10633. accessibilityManager: this.accessibilityManager,
  10634. pageIndex: this.pdfPage.pageNumber - 1,
  10635. l10n: this.l10n,
  10636. viewport: clonedViewport
  10637. });
  10638. const parameters = {
  10639. viewport: clonedViewport,
  10640. div,
  10641. annotations: null,
  10642. intent
  10643. };
  10644. this.annotationEditorLayer.render(parameters);
  10645. }
  10646. cancel() {
  10647. this._cancelled = true;
  10648. if (!this.div) {
  10649. return;
  10650. }
  10651. this.pageDiv = null;
  10652. this.annotationEditorLayer.destroy();
  10653. this.div.remove();
  10654. }
  10655. hide() {
  10656. if (!this.div) {
  10657. return;
  10658. }
  10659. this.div.hidden = true;
  10660. }
  10661. show() {
  10662. if (!this.div) {
  10663. return;
  10664. }
  10665. this.div.hidden = false;
  10666. }
  10667. }
  10668. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  10669. /***/ }),
  10670. /* 32 */
  10671. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10672. Object.defineProperty(exports, "__esModule", ({
  10673. value: true
  10674. }));
  10675. exports.AnnotationLayerBuilder = void 0;
  10676. var _pdfjsLib = __webpack_require__(5);
  10677. var _l10n_utils = __webpack_require__(29);
  10678. var _ui_utils = __webpack_require__(1);
  10679. class AnnotationLayerBuilder {
  10680. #numAnnotations = 0;
  10681. #onPresentationModeChanged = null;
  10682. constructor({
  10683. pageDiv,
  10684. pdfPage,
  10685. linkService,
  10686. downloadManager,
  10687. annotationStorage = null,
  10688. imageResourcesPath = "",
  10689. renderForms = true,
  10690. l10n = _l10n_utils.NullL10n,
  10691. enableScripting = false,
  10692. hasJSActionsPromise = null,
  10693. fieldObjectsPromise = null,
  10694. annotationCanvasMap = null,
  10695. accessibilityManager = null
  10696. }) {
  10697. this.pageDiv = pageDiv;
  10698. this.pdfPage = pdfPage;
  10699. this.linkService = linkService;
  10700. this.downloadManager = downloadManager;
  10701. this.imageResourcesPath = imageResourcesPath;
  10702. this.renderForms = renderForms;
  10703. this.l10n = l10n;
  10704. this.annotationStorage = annotationStorage;
  10705. this.enableScripting = enableScripting;
  10706. this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
  10707. this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
  10708. this._annotationCanvasMap = annotationCanvasMap;
  10709. this._accessibilityManager = accessibilityManager;
  10710. this.div = null;
  10711. this._cancelled = false;
  10712. this._eventBus = linkService.eventBus;
  10713. }
  10714. async render(viewport, intent = "display") {
  10715. if (this.div) {
  10716. if (this._cancelled || this.#numAnnotations === 0) {
  10717. return;
  10718. }
  10719. _pdfjsLib.AnnotationLayer.update({
  10720. viewport: viewport.clone({
  10721. dontFlip: true
  10722. }),
  10723. div: this.div,
  10724. annotationCanvasMap: this._annotationCanvasMap
  10725. });
  10726. return;
  10727. }
  10728. const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
  10729. intent
  10730. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  10731. if (this._cancelled) {
  10732. return;
  10733. }
  10734. this.#numAnnotations = annotations.length;
  10735. this.div = document.createElement("div");
  10736. this.div.className = "annotationLayer";
  10737. this.pageDiv.append(this.div);
  10738. if (this.#numAnnotations === 0) {
  10739. this.hide();
  10740. return;
  10741. }
  10742. _pdfjsLib.AnnotationLayer.render({
  10743. viewport: viewport.clone({
  10744. dontFlip: true
  10745. }),
  10746. div: this.div,
  10747. annotations,
  10748. page: this.pdfPage,
  10749. imageResourcesPath: this.imageResourcesPath,
  10750. renderForms: this.renderForms,
  10751. linkService: this.linkService,
  10752. downloadManager: this.downloadManager,
  10753. annotationStorage: this.annotationStorage,
  10754. enableScripting: this.enableScripting,
  10755. hasJSActions,
  10756. fieldObjects,
  10757. annotationCanvasMap: this._annotationCanvasMap,
  10758. accessibilityManager: this._accessibilityManager
  10759. });
  10760. this.l10n.translate(this.div);
  10761. if (this.linkService.isInPresentationMode) {
  10762. this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN);
  10763. }
  10764. if (!this.#onPresentationModeChanged) {
  10765. this.#onPresentationModeChanged = evt => {
  10766. this.#updatePresentationModeState(evt.state);
  10767. };
  10768. this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged);
  10769. }
  10770. }
  10771. cancel() {
  10772. this._cancelled = true;
  10773. if (this.#onPresentationModeChanged) {
  10774. this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged);
  10775. this.#onPresentationModeChanged = null;
  10776. }
  10777. }
  10778. hide() {
  10779. if (!this.div) {
  10780. return;
  10781. }
  10782. this.div.hidden = true;
  10783. }
  10784. #updatePresentationModeState(state) {
  10785. if (!this.div) {
  10786. return;
  10787. }
  10788. let disableFormElements = false;
  10789. switch (state) {
  10790. case _ui_utils.PresentationModeState.FULLSCREEN:
  10791. disableFormElements = true;
  10792. break;
  10793. case _ui_utils.PresentationModeState.NORMAL:
  10794. break;
  10795. default:
  10796. return;
  10797. }
  10798. for (const section of this.div.childNodes) {
  10799. if (section.hasAttribute("data-internal-link")) {
  10800. continue;
  10801. }
  10802. section.inert = disableFormElements;
  10803. }
  10804. }
  10805. }
  10806. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  10807. /***/ }),
  10808. /* 33 */
  10809. /***/ ((__unused_webpack_module, exports) => {
  10810. Object.defineProperty(exports, "__esModule", ({
  10811. value: true
  10812. }));
  10813. exports.StructTreeLayerBuilder = void 0;
  10814. const PDF_ROLE_TO_HTML_ROLE = {
  10815. Document: null,
  10816. DocumentFragment: null,
  10817. Part: "group",
  10818. Sect: "group",
  10819. Div: "group",
  10820. Aside: "note",
  10821. NonStruct: "none",
  10822. P: null,
  10823. H: "heading",
  10824. Title: null,
  10825. FENote: "note",
  10826. Sub: "group",
  10827. Lbl: null,
  10828. Span: null,
  10829. Em: null,
  10830. Strong: null,
  10831. Link: "link",
  10832. Annot: "note",
  10833. Form: "form",
  10834. Ruby: null,
  10835. RB: null,
  10836. RT: null,
  10837. RP: null,
  10838. Warichu: null,
  10839. WT: null,
  10840. WP: null,
  10841. L: "list",
  10842. LI: "listitem",
  10843. LBody: null,
  10844. Table: "table",
  10845. TR: "row",
  10846. TH: "columnheader",
  10847. TD: "cell",
  10848. THead: "columnheader",
  10849. TBody: null,
  10850. TFoot: null,
  10851. Caption: null,
  10852. Figure: "figure",
  10853. Formula: null,
  10854. Artifact: null
  10855. };
  10856. const HEADING_PATTERN = /^H(\d+)$/;
  10857. class StructTreeLayerBuilder {
  10858. #treeDom = undefined;
  10859. get renderingDone() {
  10860. return this.#treeDom !== undefined;
  10861. }
  10862. render(structTree) {
  10863. if (this.#treeDom !== undefined) {
  10864. return this.#treeDom;
  10865. }
  10866. const treeDom = this.#walk(structTree);
  10867. treeDom?.classList.add("structTree");
  10868. return this.#treeDom = treeDom;
  10869. }
  10870. #setAttributes(structElement, htmlElement) {
  10871. if (structElement.alt !== undefined) {
  10872. htmlElement.setAttribute("aria-label", structElement.alt);
  10873. }
  10874. if (structElement.id !== undefined) {
  10875. htmlElement.setAttribute("aria-owns", structElement.id);
  10876. }
  10877. if (structElement.lang !== undefined) {
  10878. htmlElement.setAttribute("lang", structElement.lang);
  10879. }
  10880. }
  10881. #walk(node) {
  10882. if (!node) {
  10883. return null;
  10884. }
  10885. const element = document.createElement("span");
  10886. if ("role" in node) {
  10887. const {
  10888. role
  10889. } = node;
  10890. const match = role.match(HEADING_PATTERN);
  10891. if (match) {
  10892. element.setAttribute("role", "heading");
  10893. element.setAttribute("aria-level", match[1]);
  10894. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10895. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10896. }
  10897. }
  10898. this.#setAttributes(node, element);
  10899. if (node.children) {
  10900. if (node.children.length === 1 && "id" in node.children[0]) {
  10901. this.#setAttributes(node.children[0], element);
  10902. } else {
  10903. for (const kid of node.children) {
  10904. element.append(this.#walk(kid));
  10905. }
  10906. }
  10907. }
  10908. return element;
  10909. }
  10910. }
  10911. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10912. /***/ }),
  10913. /* 34 */
  10914. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10915. Object.defineProperty(exports, "__esModule", ({
  10916. value: true
  10917. }));
  10918. exports.TextAccessibilityManager = void 0;
  10919. var _ui_utils = __webpack_require__(1);
  10920. class TextAccessibilityManager {
  10921. #enabled = false;
  10922. #textChildren = null;
  10923. #textNodes = new Map();
  10924. #waitingElements = new Map();
  10925. setTextMapping(textDivs) {
  10926. this.#textChildren = textDivs;
  10927. }
  10928. static #compareElementPositions(e1, e2) {
  10929. const rect1 = e1.getBoundingClientRect();
  10930. const rect2 = e2.getBoundingClientRect();
  10931. if (rect1.width === 0 && rect1.height === 0) {
  10932. return +1;
  10933. }
  10934. if (rect2.width === 0 && rect2.height === 0) {
  10935. return -1;
  10936. }
  10937. const top1 = rect1.y;
  10938. const bot1 = rect1.y + rect1.height;
  10939. const mid1 = rect1.y + rect1.height / 2;
  10940. const top2 = rect2.y;
  10941. const bot2 = rect2.y + rect2.height;
  10942. const mid2 = rect2.y + rect2.height / 2;
  10943. if (mid1 <= top2 && mid2 >= bot1) {
  10944. return -1;
  10945. }
  10946. if (mid2 <= top1 && mid1 >= bot2) {
  10947. return +1;
  10948. }
  10949. const centerX1 = rect1.x + rect1.width / 2;
  10950. const centerX2 = rect2.x + rect2.width / 2;
  10951. return centerX1 - centerX2;
  10952. }
  10953. enable() {
  10954. if (this.#enabled) {
  10955. throw new Error("TextAccessibilityManager is already enabled.");
  10956. }
  10957. if (!this.#textChildren) {
  10958. throw new Error("Text divs and strings have not been set.");
  10959. }
  10960. this.#enabled = true;
  10961. this.#textChildren = this.#textChildren.slice();
  10962. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  10963. if (this.#textNodes.size > 0) {
  10964. const textChildren = this.#textChildren;
  10965. for (const [id, nodeIndex] of this.#textNodes) {
  10966. const element = document.getElementById(id);
  10967. if (!element) {
  10968. this.#textNodes.delete(id);
  10969. continue;
  10970. }
  10971. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  10972. }
  10973. }
  10974. for (const [element, isRemovable] of this.#waitingElements) {
  10975. this.addPointerInTextLayer(element, isRemovable);
  10976. }
  10977. this.#waitingElements.clear();
  10978. }
  10979. disable() {
  10980. if (!this.#enabled) {
  10981. return;
  10982. }
  10983. this.#waitingElements.clear();
  10984. this.#textChildren = null;
  10985. this.#enabled = false;
  10986. }
  10987. removePointerInTextLayer(element) {
  10988. if (!this.#enabled) {
  10989. this.#waitingElements.delete(element);
  10990. return;
  10991. }
  10992. const children = this.#textChildren;
  10993. if (!children || children.length === 0) {
  10994. return;
  10995. }
  10996. const {
  10997. id
  10998. } = element;
  10999. const nodeIndex = this.#textNodes.get(id);
  11000. if (nodeIndex === undefined) {
  11001. return;
  11002. }
  11003. const node = children[nodeIndex];
  11004. this.#textNodes.delete(id);
  11005. let owns = node.getAttribute("aria-owns");
  11006. if (owns?.includes(id)) {
  11007. owns = owns.split(" ").filter(x => x !== id).join(" ");
  11008. if (owns) {
  11009. node.setAttribute("aria-owns", owns);
  11010. } else {
  11011. node.removeAttribute("aria-owns");
  11012. node.setAttribute("role", "presentation");
  11013. }
  11014. }
  11015. }
  11016. #addIdToAriaOwns(id, node) {
  11017. const owns = node.getAttribute("aria-owns");
  11018. if (!owns?.includes(id)) {
  11019. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  11020. }
  11021. node.removeAttribute("role");
  11022. }
  11023. addPointerInTextLayer(element, isRemovable) {
  11024. const {
  11025. id
  11026. } = element;
  11027. if (!id) {
  11028. return;
  11029. }
  11030. if (!this.#enabled) {
  11031. this.#waitingElements.set(element, isRemovable);
  11032. return;
  11033. }
  11034. if (isRemovable) {
  11035. this.removePointerInTextLayer(element);
  11036. }
  11037. const children = this.#textChildren;
  11038. if (!children || children.length === 0) {
  11039. return;
  11040. }
  11041. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  11042. const nodeIndex = Math.max(0, index - 1);
  11043. this.#addIdToAriaOwns(id, children[nodeIndex]);
  11044. this.#textNodes.set(id, nodeIndex);
  11045. }
  11046. moveElementInDOM(container, element, contentElement, isRemovable) {
  11047. this.addPointerInTextLayer(contentElement, isRemovable);
  11048. if (!container.hasChildNodes()) {
  11049. container.append(element);
  11050. return;
  11051. }
  11052. const children = Array.from(container.childNodes).filter(node => node !== element);
  11053. if (children.length === 0) {
  11054. return;
  11055. }
  11056. const elementToCompare = contentElement || element;
  11057. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  11058. if (index === 0) {
  11059. children[0].before(element);
  11060. } else {
  11061. children[index - 1].after(element);
  11062. }
  11063. }
  11064. }
  11065. exports.TextAccessibilityManager = TextAccessibilityManager;
  11066. /***/ }),
  11067. /* 35 */
  11068. /***/ ((__unused_webpack_module, exports) => {
  11069. Object.defineProperty(exports, "__esModule", ({
  11070. value: true
  11071. }));
  11072. exports.TextHighlighter = void 0;
  11073. class TextHighlighter {
  11074. constructor({
  11075. findController,
  11076. eventBus,
  11077. pageIndex
  11078. }) {
  11079. this.findController = findController;
  11080. this.matches = [];
  11081. this.eventBus = eventBus;
  11082. this.pageIdx = pageIndex;
  11083. this._onUpdateTextLayerMatches = null;
  11084. this.textDivs = null;
  11085. this.textContentItemsStr = null;
  11086. this.enabled = false;
  11087. }
  11088. setTextMapping(divs, texts) {
  11089. this.textDivs = divs;
  11090. this.textContentItemsStr = texts;
  11091. }
  11092. enable() {
  11093. if (!this.textDivs || !this.textContentItemsStr) {
  11094. throw new Error("Text divs and strings have not been set.");
  11095. }
  11096. if (this.enabled) {
  11097. throw new Error("TextHighlighter is already enabled.");
  11098. }
  11099. this.enabled = true;
  11100. if (!this._onUpdateTextLayerMatches) {
  11101. this._onUpdateTextLayerMatches = evt => {
  11102. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  11103. this._updateMatches();
  11104. }
  11105. };
  11106. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11107. }
  11108. this._updateMatches();
  11109. }
  11110. disable() {
  11111. if (!this.enabled) {
  11112. return;
  11113. }
  11114. this.enabled = false;
  11115. if (this._onUpdateTextLayerMatches) {
  11116. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11117. this._onUpdateTextLayerMatches = null;
  11118. }
  11119. this._updateMatches(true);
  11120. }
  11121. _convertMatches(matches, matchesLength) {
  11122. if (!matches) {
  11123. return [];
  11124. }
  11125. const {
  11126. textContentItemsStr
  11127. } = this;
  11128. let i = 0,
  11129. iIndex = 0;
  11130. const end = textContentItemsStr.length - 1;
  11131. const result = [];
  11132. for (let m = 0, mm = matches.length; m < mm; m++) {
  11133. let matchIdx = matches[m];
  11134. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  11135. iIndex += textContentItemsStr[i].length;
  11136. i++;
  11137. }
  11138. if (i === textContentItemsStr.length) {
  11139. console.error("Could not find a matching mapping");
  11140. }
  11141. const match = {
  11142. begin: {
  11143. divIdx: i,
  11144. offset: matchIdx - iIndex
  11145. }
  11146. };
  11147. matchIdx += matchesLength[m];
  11148. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  11149. iIndex += textContentItemsStr[i].length;
  11150. i++;
  11151. }
  11152. match.end = {
  11153. divIdx: i,
  11154. offset: matchIdx - iIndex
  11155. };
  11156. result.push(match);
  11157. }
  11158. return result;
  11159. }
  11160. _renderMatches(matches) {
  11161. if (matches.length === 0) {
  11162. return;
  11163. }
  11164. const {
  11165. findController,
  11166. pageIdx
  11167. } = this;
  11168. const {
  11169. textContentItemsStr,
  11170. textDivs
  11171. } = this;
  11172. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  11173. const selectedMatchIdx = findController.selected.matchIdx;
  11174. const highlightAll = findController.state.highlightAll;
  11175. let prevEnd = null;
  11176. const infinity = {
  11177. divIdx: -1,
  11178. offset: undefined
  11179. };
  11180. function beginText(begin, className) {
  11181. const divIdx = begin.divIdx;
  11182. textDivs[divIdx].textContent = "";
  11183. return appendTextToDiv(divIdx, 0, begin.offset, className);
  11184. }
  11185. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  11186. let div = textDivs[divIdx];
  11187. if (div.nodeType === Node.TEXT_NODE) {
  11188. const span = document.createElement("span");
  11189. div.before(span);
  11190. span.append(div);
  11191. textDivs[divIdx] = span;
  11192. div = span;
  11193. }
  11194. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  11195. const node = document.createTextNode(content);
  11196. if (className) {
  11197. const span = document.createElement("span");
  11198. span.className = `${className} appended`;
  11199. span.append(node);
  11200. div.append(span);
  11201. return className.includes("selected") ? span.offsetLeft : 0;
  11202. }
  11203. div.append(node);
  11204. return 0;
  11205. }
  11206. let i0 = selectedMatchIdx,
  11207. i1 = i0 + 1;
  11208. if (highlightAll) {
  11209. i0 = 0;
  11210. i1 = matches.length;
  11211. } else if (!isSelectedPage) {
  11212. return;
  11213. }
  11214. for (let i = i0; i < i1; i++) {
  11215. const match = matches[i];
  11216. const begin = match.begin;
  11217. const end = match.end;
  11218. const isSelected = isSelectedPage && i === selectedMatchIdx;
  11219. const highlightSuffix = isSelected ? " selected" : "";
  11220. let selectedLeft = 0;
  11221. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  11222. if (prevEnd !== null) {
  11223. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11224. }
  11225. beginText(begin);
  11226. } else {
  11227. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  11228. }
  11229. if (begin.divIdx === end.divIdx) {
  11230. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  11231. } else {
  11232. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  11233. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  11234. textDivs[n0].className = "highlight middle" + highlightSuffix;
  11235. }
  11236. beginText(end, "highlight end" + highlightSuffix);
  11237. }
  11238. prevEnd = end;
  11239. if (isSelected) {
  11240. findController.scrollMatchIntoView({
  11241. element: textDivs[begin.divIdx],
  11242. selectedLeft,
  11243. pageIndex: pageIdx,
  11244. matchIndex: selectedMatchIdx
  11245. });
  11246. }
  11247. }
  11248. if (prevEnd) {
  11249. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11250. }
  11251. }
  11252. _updateMatches(reset = false) {
  11253. if (!this.enabled && !reset) {
  11254. return;
  11255. }
  11256. const {
  11257. findController,
  11258. matches,
  11259. pageIdx
  11260. } = this;
  11261. const {
  11262. textContentItemsStr,
  11263. textDivs
  11264. } = this;
  11265. let clearedUntilDivIdx = -1;
  11266. for (const match of matches) {
  11267. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  11268. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  11269. const div = textDivs[n];
  11270. div.textContent = textContentItemsStr[n];
  11271. div.className = "";
  11272. }
  11273. clearedUntilDivIdx = match.end.divIdx + 1;
  11274. }
  11275. if (!findController?.highlightMatches || reset) {
  11276. return;
  11277. }
  11278. const pageMatches = findController.pageMatches[pageIdx] || null;
  11279. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  11280. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  11281. this._renderMatches(this.matches);
  11282. }
  11283. }
  11284. exports.TextHighlighter = TextHighlighter;
  11285. /***/ }),
  11286. /* 36 */
  11287. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11288. Object.defineProperty(exports, "__esModule", ({
  11289. value: true
  11290. }));
  11291. exports.TextLayerBuilder = void 0;
  11292. var _pdfjsLib = __webpack_require__(5);
  11293. class TextLayerBuilder {
  11294. #rotation = 0;
  11295. #scale = 0;
  11296. #textContentSource = null;
  11297. constructor({
  11298. highlighter = null,
  11299. accessibilityManager = null,
  11300. isOffscreenCanvasSupported = true
  11301. }) {
  11302. this.textContentItemsStr = [];
  11303. this.renderingDone = false;
  11304. this.textDivs = [];
  11305. this.textDivProperties = new WeakMap();
  11306. this.textLayerRenderTask = null;
  11307. this.highlighter = highlighter;
  11308. this.accessibilityManager = accessibilityManager;
  11309. this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
  11310. this.div = document.createElement("div");
  11311. this.div.className = "textLayer";
  11312. this.hide();
  11313. }
  11314. #finishRendering() {
  11315. this.renderingDone = true;
  11316. const endOfContent = document.createElement("div");
  11317. endOfContent.className = "endOfContent";
  11318. this.div.append(endOfContent);
  11319. this.#bindMouse();
  11320. }
  11321. get numTextDivs() {
  11322. return this.textDivs.length;
  11323. }
  11324. async render(viewport) {
  11325. if (!this.#textContentSource) {
  11326. throw new Error('No "textContentSource" parameter specified.');
  11327. }
  11328. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  11329. const {
  11330. rotation
  11331. } = viewport;
  11332. if (this.renderingDone) {
  11333. const mustRotate = rotation !== this.#rotation;
  11334. const mustRescale = scale !== this.#scale;
  11335. if (mustRotate || mustRescale) {
  11336. this.hide();
  11337. (0, _pdfjsLib.updateTextLayer)({
  11338. container: this.div,
  11339. viewport,
  11340. textDivs: this.textDivs,
  11341. textDivProperties: this.textDivProperties,
  11342. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  11343. mustRescale,
  11344. mustRotate
  11345. });
  11346. this.#scale = scale;
  11347. this.#rotation = rotation;
  11348. }
  11349. this.show();
  11350. return;
  11351. }
  11352. this.cancel();
  11353. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  11354. this.accessibilityManager?.setTextMapping(this.textDivs);
  11355. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  11356. textContentSource: this.#textContentSource,
  11357. container: this.div,
  11358. viewport,
  11359. textDivs: this.textDivs,
  11360. textDivProperties: this.textDivProperties,
  11361. textContentItemsStr: this.textContentItemsStr,
  11362. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
  11363. });
  11364. await this.textLayerRenderTask.promise;
  11365. this.#finishRendering();
  11366. this.#scale = scale;
  11367. this.#rotation = rotation;
  11368. this.show();
  11369. this.accessibilityManager?.enable();
  11370. }
  11371. hide() {
  11372. if (!this.div.hidden) {
  11373. this.highlighter?.disable();
  11374. this.div.hidden = true;
  11375. }
  11376. }
  11377. show() {
  11378. if (this.div.hidden && this.renderingDone) {
  11379. this.div.hidden = false;
  11380. this.highlighter?.enable();
  11381. }
  11382. }
  11383. cancel() {
  11384. if (this.textLayerRenderTask) {
  11385. this.textLayerRenderTask.cancel();
  11386. this.textLayerRenderTask = null;
  11387. }
  11388. this.highlighter?.disable();
  11389. this.accessibilityManager?.disable();
  11390. this.textContentItemsStr.length = 0;
  11391. this.textDivs.length = 0;
  11392. this.textDivProperties = new WeakMap();
  11393. }
  11394. setTextContentSource(source) {
  11395. this.cancel();
  11396. this.#textContentSource = source;
  11397. }
  11398. #bindMouse() {
  11399. const {
  11400. div
  11401. } = this;
  11402. div.addEventListener("mousedown", evt => {
  11403. const end = div.querySelector(".endOfContent");
  11404. if (!end) {
  11405. return;
  11406. }
  11407. let adjustTop = evt.target !== div;
  11408. adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  11409. if (adjustTop) {
  11410. const divBounds = div.getBoundingClientRect();
  11411. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  11412. end.style.top = (r * 100).toFixed(2) + "%";
  11413. }
  11414. end.classList.add("active");
  11415. });
  11416. div.addEventListener("mouseup", () => {
  11417. const end = div.querySelector(".endOfContent");
  11418. if (!end) {
  11419. return;
  11420. }
  11421. end.style.top = "";
  11422. end.classList.remove("active");
  11423. });
  11424. }
  11425. }
  11426. exports.TextLayerBuilder = TextLayerBuilder;
  11427. /***/ }),
  11428. /* 37 */
  11429. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11430. Object.defineProperty(exports, "__esModule", ({
  11431. value: true
  11432. }));
  11433. exports.XfaLayerBuilder = void 0;
  11434. var _pdfjsLib = __webpack_require__(5);
  11435. class XfaLayerBuilder {
  11436. constructor({
  11437. pageDiv,
  11438. pdfPage,
  11439. annotationStorage = null,
  11440. linkService,
  11441. xfaHtml = null
  11442. }) {
  11443. this.pageDiv = pageDiv;
  11444. this.pdfPage = pdfPage;
  11445. this.annotationStorage = annotationStorage;
  11446. this.linkService = linkService;
  11447. this.xfaHtml = xfaHtml;
  11448. this.div = null;
  11449. this._cancelled = false;
  11450. }
  11451. async render(viewport, intent = "display") {
  11452. if (intent === "print") {
  11453. const parameters = {
  11454. viewport: viewport.clone({
  11455. dontFlip: true
  11456. }),
  11457. div: this.div,
  11458. xfaHtml: this.xfaHtml,
  11459. annotationStorage: this.annotationStorage,
  11460. linkService: this.linkService,
  11461. intent
  11462. };
  11463. const div = document.createElement("div");
  11464. this.pageDiv.append(div);
  11465. parameters.div = div;
  11466. return _pdfjsLib.XfaLayer.render(parameters);
  11467. }
  11468. const xfaHtml = await this.pdfPage.getXfa();
  11469. if (this._cancelled || !xfaHtml) {
  11470. return {
  11471. textDivs: []
  11472. };
  11473. }
  11474. const parameters = {
  11475. viewport: viewport.clone({
  11476. dontFlip: true
  11477. }),
  11478. div: this.div,
  11479. xfaHtml,
  11480. annotationStorage: this.annotationStorage,
  11481. linkService: this.linkService,
  11482. intent
  11483. };
  11484. if (this.div) {
  11485. return _pdfjsLib.XfaLayer.update(parameters);
  11486. }
  11487. this.div = document.createElement("div");
  11488. this.pageDiv.append(this.div);
  11489. parameters.div = this.div;
  11490. return _pdfjsLib.XfaLayer.render(parameters);
  11491. }
  11492. cancel() {
  11493. this._cancelled = true;
  11494. }
  11495. hide() {
  11496. if (!this.div) {
  11497. return;
  11498. }
  11499. this.div.hidden = true;
  11500. }
  11501. }
  11502. exports.XfaLayerBuilder = XfaLayerBuilder;
  11503. /***/ }),
  11504. /* 38 */
  11505. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11506. Object.defineProperty(exports, "__esModule", ({
  11507. value: true
  11508. }));
  11509. exports.SecondaryToolbar = void 0;
  11510. var _ui_utils = __webpack_require__(1);
  11511. var _pdf_cursor_tools = __webpack_require__(7);
  11512. var _pdf_viewer = __webpack_require__(28);
  11513. class SecondaryToolbar {
  11514. constructor(options, eventBus, externalServices) {
  11515. this.toolbar = options.toolbar;
  11516. this.toggleButton = options.toggleButton;
  11517. this.buttons = [{
  11518. element: options.presentationModeButton,
  11519. eventName: "presentationmode",
  11520. close: true
  11521. }, {
  11522. element: options.printButton,
  11523. eventName: "print",
  11524. close: true
  11525. }, {
  11526. element: options.downloadButton,
  11527. eventName: "download",
  11528. close: true
  11529. }, {
  11530. element: options.viewBookmarkButton,
  11531. eventName: null,
  11532. close: true
  11533. }, {
  11534. element: options.firstPageButton,
  11535. eventName: "firstpage",
  11536. close: true
  11537. }, {
  11538. element: options.lastPageButton,
  11539. eventName: "lastpage",
  11540. close: true
  11541. }, {
  11542. element: options.pageRotateCwButton,
  11543. eventName: "rotatecw",
  11544. close: false
  11545. }, {
  11546. element: options.pageRotateCcwButton,
  11547. eventName: "rotateccw",
  11548. close: false
  11549. }, {
  11550. element: options.cursorSelectToolButton,
  11551. eventName: "switchcursortool",
  11552. eventDetails: {
  11553. tool: _pdf_cursor_tools.CursorTool.SELECT
  11554. },
  11555. close: true
  11556. }, {
  11557. element: options.cursorHandToolButton,
  11558. eventName: "switchcursortool",
  11559. eventDetails: {
  11560. tool: _pdf_cursor_tools.CursorTool.HAND
  11561. },
  11562. close: true
  11563. }, {
  11564. element: options.scrollPageButton,
  11565. eventName: "switchscrollmode",
  11566. eventDetails: {
  11567. mode: _ui_utils.ScrollMode.PAGE
  11568. },
  11569. close: true
  11570. }, {
  11571. element: options.scrollVerticalButton,
  11572. eventName: "switchscrollmode",
  11573. eventDetails: {
  11574. mode: _ui_utils.ScrollMode.VERTICAL
  11575. },
  11576. close: true
  11577. }, {
  11578. element: options.scrollHorizontalButton,
  11579. eventName: "switchscrollmode",
  11580. eventDetails: {
  11581. mode: _ui_utils.ScrollMode.HORIZONTAL
  11582. },
  11583. close: true
  11584. }, {
  11585. element: options.scrollWrappedButton,
  11586. eventName: "switchscrollmode",
  11587. eventDetails: {
  11588. mode: _ui_utils.ScrollMode.WRAPPED
  11589. },
  11590. close: true
  11591. }, {
  11592. element: options.spreadNoneButton,
  11593. eventName: "switchspreadmode",
  11594. eventDetails: {
  11595. mode: _ui_utils.SpreadMode.NONE
  11596. },
  11597. close: true
  11598. }, {
  11599. element: options.spreadOddButton,
  11600. eventName: "switchspreadmode",
  11601. eventDetails: {
  11602. mode: _ui_utils.SpreadMode.ODD
  11603. },
  11604. close: true
  11605. }, {
  11606. element: options.spreadEvenButton,
  11607. eventName: "switchspreadmode",
  11608. eventDetails: {
  11609. mode: _ui_utils.SpreadMode.EVEN
  11610. },
  11611. close: true
  11612. }, {
  11613. element: options.documentPropertiesButton,
  11614. eventName: "documentproperties",
  11615. close: true
  11616. }];
  11617. this.buttons.push({
  11618. element: options.openFileButton,
  11619. eventName: "openfile",
  11620. close: true
  11621. });
  11622. this.items = {
  11623. firstPage: options.firstPageButton,
  11624. lastPage: options.lastPageButton,
  11625. pageRotateCw: options.pageRotateCwButton,
  11626. pageRotateCcw: options.pageRotateCcwButton
  11627. };
  11628. this.eventBus = eventBus;
  11629. this.externalServices = externalServices;
  11630. this.opened = false;
  11631. this.#bindClickListeners();
  11632. this.#bindCursorToolsListener(options);
  11633. this.#bindScrollModeListener(options);
  11634. this.#bindSpreadModeListener(options);
  11635. this.reset();
  11636. }
  11637. get isOpen() {
  11638. return this.opened;
  11639. }
  11640. setPageNumber(pageNumber) {
  11641. this.pageNumber = pageNumber;
  11642. this.#updateUIState();
  11643. }
  11644. setPagesCount(pagesCount) {
  11645. this.pagesCount = pagesCount;
  11646. this.#updateUIState();
  11647. }
  11648. reset() {
  11649. this.pageNumber = 0;
  11650. this.pagesCount = 0;
  11651. this.#updateUIState();
  11652. this.eventBus.dispatch("secondarytoolbarreset", {
  11653. source: this
  11654. });
  11655. }
  11656. #updateUIState() {
  11657. this.items.firstPage.disabled = this.pageNumber <= 1;
  11658. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  11659. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  11660. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  11661. }
  11662. #bindClickListeners() {
  11663. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  11664. for (const {
  11665. element,
  11666. eventName,
  11667. close,
  11668. eventDetails
  11669. } of this.buttons) {
  11670. element.addEventListener("click", evt => {
  11671. if (eventName !== null) {
  11672. const details = {
  11673. source: this
  11674. };
  11675. for (const property in eventDetails) {
  11676. details[property] = eventDetails[property];
  11677. }
  11678. this.eventBus.dispatch(eventName, details);
  11679. }
  11680. if (close) {
  11681. this.close();
  11682. }
  11683. this.externalServices.reportTelemetry({
  11684. type: "buttons",
  11685. data: {
  11686. id: element.id
  11687. }
  11688. });
  11689. });
  11690. }
  11691. }
  11692. #bindCursorToolsListener({
  11693. cursorSelectToolButton,
  11694. cursorHandToolButton
  11695. }) {
  11696. this.eventBus._on("cursortoolchanged", function ({
  11697. tool
  11698. }) {
  11699. const isSelect = tool === _pdf_cursor_tools.CursorTool.SELECT,
  11700. isHand = tool === _pdf_cursor_tools.CursorTool.HAND;
  11701. cursorSelectToolButton.classList.toggle("toggled", isSelect);
  11702. cursorHandToolButton.classList.toggle("toggled", isHand);
  11703. cursorSelectToolButton.setAttribute("aria-checked", isSelect);
  11704. cursorHandToolButton.setAttribute("aria-checked", isHand);
  11705. });
  11706. }
  11707. #bindScrollModeListener({
  11708. scrollPageButton,
  11709. scrollVerticalButton,
  11710. scrollHorizontalButton,
  11711. scrollWrappedButton,
  11712. spreadNoneButton,
  11713. spreadOddButton,
  11714. spreadEvenButton
  11715. }) {
  11716. const scrollModeChanged = ({
  11717. mode
  11718. }) => {
  11719. const isPage = mode === _ui_utils.ScrollMode.PAGE,
  11720. isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
  11721. isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
  11722. isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
  11723. scrollPageButton.classList.toggle("toggled", isPage);
  11724. scrollVerticalButton.classList.toggle("toggled", isVertical);
  11725. scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
  11726. scrollWrappedButton.classList.toggle("toggled", isWrapped);
  11727. scrollPageButton.setAttribute("aria-checked", isPage);
  11728. scrollVerticalButton.setAttribute("aria-checked", isVertical);
  11729. scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
  11730. scrollWrappedButton.setAttribute("aria-checked", isWrapped);
  11731. const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11732. scrollPageButton.disabled = forceScrollModePage;
  11733. scrollVerticalButton.disabled = forceScrollModePage;
  11734. scrollHorizontalButton.disabled = forceScrollModePage;
  11735. scrollWrappedButton.disabled = forceScrollModePage;
  11736. spreadNoneButton.disabled = isHorizontal;
  11737. spreadOddButton.disabled = isHorizontal;
  11738. spreadEvenButton.disabled = isHorizontal;
  11739. };
  11740. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  11741. this.eventBus._on("secondarytoolbarreset", evt => {
  11742. if (evt.source === this) {
  11743. scrollModeChanged({
  11744. mode: _ui_utils.ScrollMode.VERTICAL
  11745. });
  11746. }
  11747. });
  11748. }
  11749. #bindSpreadModeListener({
  11750. spreadNoneButton,
  11751. spreadOddButton,
  11752. spreadEvenButton
  11753. }) {
  11754. function spreadModeChanged({
  11755. mode
  11756. }) {
  11757. const isNone = mode === _ui_utils.SpreadMode.NONE,
  11758. isOdd = mode === _ui_utils.SpreadMode.ODD,
  11759. isEven = mode === _ui_utils.SpreadMode.EVEN;
  11760. spreadNoneButton.classList.toggle("toggled", isNone);
  11761. spreadOddButton.classList.toggle("toggled", isOdd);
  11762. spreadEvenButton.classList.toggle("toggled", isEven);
  11763. spreadNoneButton.setAttribute("aria-checked", isNone);
  11764. spreadOddButton.setAttribute("aria-checked", isOdd);
  11765. spreadEvenButton.setAttribute("aria-checked", isEven);
  11766. }
  11767. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  11768. this.eventBus._on("secondarytoolbarreset", evt => {
  11769. if (evt.source === this) {
  11770. spreadModeChanged({
  11771. mode: _ui_utils.SpreadMode.NONE
  11772. });
  11773. }
  11774. });
  11775. }
  11776. open() {
  11777. if (this.opened) {
  11778. return;
  11779. }
  11780. this.opened = true;
  11781. this.toggleButton.classList.add("toggled");
  11782. this.toggleButton.setAttribute("aria-expanded", "true");
  11783. this.toolbar.classList.remove("hidden");
  11784. }
  11785. close() {
  11786. if (!this.opened) {
  11787. return;
  11788. }
  11789. this.opened = false;
  11790. this.toolbar.classList.add("hidden");
  11791. this.toggleButton.classList.remove("toggled");
  11792. this.toggleButton.setAttribute("aria-expanded", "false");
  11793. }
  11794. toggle() {
  11795. if (this.opened) {
  11796. this.close();
  11797. } else {
  11798. this.open();
  11799. }
  11800. }
  11801. }
  11802. exports.SecondaryToolbar = SecondaryToolbar;
  11803. /***/ }),
  11804. /* 39 */
  11805. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11806. Object.defineProperty(exports, "__esModule", ({
  11807. value: true
  11808. }));
  11809. exports.Toolbar = void 0;
  11810. var _ui_utils = __webpack_require__(1);
  11811. var _pdfjsLib = __webpack_require__(5);
  11812. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  11813. class Toolbar {
  11814. #wasLocalized = false;
  11815. constructor(options, eventBus, l10n) {
  11816. this.toolbar = options.container;
  11817. this.eventBus = eventBus;
  11818. this.l10n = l10n;
  11819. this.buttons = [{
  11820. element: options.previous,
  11821. eventName: "previouspage"
  11822. }, {
  11823. element: options.next,
  11824. eventName: "nextpage"
  11825. }, {
  11826. element: options.zoomIn,
  11827. eventName: "zoomin"
  11828. }, {
  11829. element: options.zoomOut,
  11830. eventName: "zoomout"
  11831. }, {
  11832. element: options.print,
  11833. eventName: "print"
  11834. }, {
  11835. element: options.download,
  11836. eventName: "download"
  11837. }, {
  11838. element: options.editorFreeTextButton,
  11839. eventName: "switchannotationeditormode",
  11840. eventDetails: {
  11841. get mode() {
  11842. const {
  11843. classList
  11844. } = options.editorFreeTextButton;
  11845. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  11846. }
  11847. }
  11848. }, {
  11849. element: options.editorInkButton,
  11850. eventName: "switchannotationeditormode",
  11851. eventDetails: {
  11852. get mode() {
  11853. const {
  11854. classList
  11855. } = options.editorInkButton;
  11856. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  11857. }
  11858. }
  11859. }];
  11860. this.buttons.push({
  11861. element: options.openFile,
  11862. eventName: "openfile"
  11863. });
  11864. this.items = {
  11865. numPages: options.numPages,
  11866. pageNumber: options.pageNumber,
  11867. scaleSelect: options.scaleSelect,
  11868. customScaleOption: options.customScaleOption,
  11869. previous: options.previous,
  11870. next: options.next,
  11871. zoomIn: options.zoomIn,
  11872. zoomOut: options.zoomOut
  11873. };
  11874. this.#bindListeners(options);
  11875. this.reset();
  11876. }
  11877. setPageNumber(pageNumber, pageLabel) {
  11878. this.pageNumber = pageNumber;
  11879. this.pageLabel = pageLabel;
  11880. this.#updateUIState(false);
  11881. }
  11882. setPagesCount(pagesCount, hasPageLabels) {
  11883. this.pagesCount = pagesCount;
  11884. this.hasPageLabels = hasPageLabels;
  11885. this.#updateUIState(true);
  11886. }
  11887. setPageScale(pageScaleValue, pageScale) {
  11888. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11889. this.pageScale = pageScale;
  11890. this.#updateUIState(false);
  11891. }
  11892. reset() {
  11893. this.pageNumber = 0;
  11894. this.pageLabel = null;
  11895. this.hasPageLabels = false;
  11896. this.pagesCount = 0;
  11897. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  11898. this.pageScale = _ui_utils.DEFAULT_SCALE;
  11899. this.#updateUIState(true);
  11900. this.updateLoadingIndicatorState();
  11901. this.eventBus.dispatch("toolbarreset", {
  11902. source: this
  11903. });
  11904. }
  11905. #bindListeners(options) {
  11906. const {
  11907. pageNumber,
  11908. scaleSelect
  11909. } = this.items;
  11910. const self = this;
  11911. for (const {
  11912. element,
  11913. eventName,
  11914. eventDetails
  11915. } of this.buttons) {
  11916. element.addEventListener("click", evt => {
  11917. if (eventName !== null) {
  11918. const details = {
  11919. source: this
  11920. };
  11921. if (eventDetails) {
  11922. for (const property in eventDetails) {
  11923. details[property] = eventDetails[property];
  11924. }
  11925. }
  11926. this.eventBus.dispatch(eventName, details);
  11927. }
  11928. });
  11929. }
  11930. pageNumber.addEventListener("click", function () {
  11931. this.select();
  11932. });
  11933. pageNumber.addEventListener("change", function () {
  11934. self.eventBus.dispatch("pagenumberchanged", {
  11935. source: self,
  11936. value: this.value
  11937. });
  11938. });
  11939. scaleSelect.addEventListener("change", function () {
  11940. if (this.value === "custom") {
  11941. return;
  11942. }
  11943. self.eventBus.dispatch("scalechanged", {
  11944. source: self,
  11945. value: this.value
  11946. });
  11947. });
  11948. scaleSelect.addEventListener("click", function (evt) {
  11949. const target = evt.target;
  11950. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11951. this.blur();
  11952. }
  11953. });
  11954. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  11955. this.eventBus._on("localized", () => {
  11956. this.#wasLocalized = true;
  11957. this.#adjustScaleWidth();
  11958. this.#updateUIState(true);
  11959. });
  11960. this.#bindEditorToolsListener(options);
  11961. }
  11962. #bindEditorToolsListener({
  11963. editorFreeTextButton,
  11964. editorFreeTextParamsToolbar,
  11965. editorInkButton,
  11966. editorInkParamsToolbar
  11967. }) {
  11968. const editorModeChanged = (evt, disableButtons = false) => {
  11969. const editorButtons = [{
  11970. mode: _pdfjsLib.AnnotationEditorType.FREETEXT,
  11971. button: editorFreeTextButton,
  11972. toolbar: editorFreeTextParamsToolbar
  11973. }, {
  11974. mode: _pdfjsLib.AnnotationEditorType.INK,
  11975. button: editorInkButton,
  11976. toolbar: editorInkParamsToolbar
  11977. }];
  11978. for (const {
  11979. mode,
  11980. button,
  11981. toolbar
  11982. } of editorButtons) {
  11983. const checked = mode === evt.mode;
  11984. button.classList.toggle("toggled", checked);
  11985. button.setAttribute("aria-checked", checked);
  11986. button.disabled = disableButtons;
  11987. toolbar?.classList.toggle("hidden", !checked);
  11988. }
  11989. };
  11990. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  11991. this.eventBus._on("toolbarreset", evt => {
  11992. if (evt.source === this) {
  11993. editorModeChanged({
  11994. mode: _pdfjsLib.AnnotationEditorType.NONE
  11995. }, true);
  11996. }
  11997. });
  11998. }
  11999. #updateUIState(resetNumPages = false) {
  12000. if (!this.#wasLocalized) {
  12001. return;
  12002. }
  12003. const {
  12004. pageNumber,
  12005. pagesCount,
  12006. pageScaleValue,
  12007. pageScale,
  12008. items
  12009. } = this;
  12010. if (resetNumPages) {
  12011. if (this.hasPageLabels) {
  12012. items.pageNumber.type = "text";
  12013. } else {
  12014. items.pageNumber.type = "number";
  12015. this.l10n.get("of_pages", {
  12016. pagesCount
  12017. }).then(msg => {
  12018. items.numPages.textContent = msg;
  12019. });
  12020. }
  12021. items.pageNumber.max = pagesCount;
  12022. }
  12023. if (this.hasPageLabels) {
  12024. items.pageNumber.value = this.pageLabel;
  12025. this.l10n.get("page_of_pages", {
  12026. pageNumber,
  12027. pagesCount
  12028. }).then(msg => {
  12029. items.numPages.textContent = msg;
  12030. });
  12031. } else {
  12032. items.pageNumber.value = pageNumber;
  12033. }
  12034. items.previous.disabled = pageNumber <= 1;
  12035. items.next.disabled = pageNumber >= pagesCount;
  12036. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  12037. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  12038. this.l10n.get("page_scale_percent", {
  12039. scale: Math.round(pageScale * 10000) / 100
  12040. }).then(msg => {
  12041. let predefinedValueFound = false;
  12042. for (const option of items.scaleSelect.options) {
  12043. if (option.value !== pageScaleValue) {
  12044. option.selected = false;
  12045. continue;
  12046. }
  12047. option.selected = true;
  12048. predefinedValueFound = true;
  12049. }
  12050. if (!predefinedValueFound) {
  12051. items.customScaleOption.textContent = msg;
  12052. items.customScaleOption.selected = true;
  12053. }
  12054. });
  12055. }
  12056. updateLoadingIndicatorState(loading = false) {
  12057. const {
  12058. pageNumber
  12059. } = this.items;
  12060. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  12061. }
  12062. async #adjustScaleWidth() {
  12063. const {
  12064. items,
  12065. l10n
  12066. } = this;
  12067. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  12068. await _ui_utils.animationStarted;
  12069. const style = getComputedStyle(items.scaleSelect);
  12070. const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width"));
  12071. const canvas = document.createElement("canvas");
  12072. const ctx = canvas.getContext("2d", {
  12073. alpha: false
  12074. });
  12075. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  12076. let maxWidth = 0;
  12077. for (const predefinedValue of await predefinedValuesPromise) {
  12078. const {
  12079. width
  12080. } = ctx.measureText(predefinedValue);
  12081. if (width > maxWidth) {
  12082. maxWidth = width;
  12083. }
  12084. }
  12085. maxWidth += 0.3 * scaleSelectWidth;
  12086. if (maxWidth > scaleSelectWidth) {
  12087. _ui_utils.docStyle.setProperty("--scale-select-width", `${maxWidth}px`);
  12088. }
  12089. canvas.width = 0;
  12090. canvas.height = 0;
  12091. }
  12092. }
  12093. exports.Toolbar = Toolbar;
  12094. /***/ }),
  12095. /* 40 */
  12096. /***/ ((__unused_webpack_module, exports) => {
  12097. Object.defineProperty(exports, "__esModule", ({
  12098. value: true
  12099. }));
  12100. exports.ViewHistory = void 0;
  12101. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  12102. class ViewHistory {
  12103. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  12104. this.fingerprint = fingerprint;
  12105. this.cacheSize = cacheSize;
  12106. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  12107. const database = JSON.parse(databaseStr || "{}");
  12108. let index = -1;
  12109. if (!Array.isArray(database.files)) {
  12110. database.files = [];
  12111. } else {
  12112. while (database.files.length >= this.cacheSize) {
  12113. database.files.shift();
  12114. }
  12115. for (let i = 0, ii = database.files.length; i < ii; i++) {
  12116. const branch = database.files[i];
  12117. if (branch.fingerprint === this.fingerprint) {
  12118. index = i;
  12119. break;
  12120. }
  12121. }
  12122. }
  12123. if (index === -1) {
  12124. index = database.files.push({
  12125. fingerprint: this.fingerprint
  12126. }) - 1;
  12127. }
  12128. this.file = database.files[index];
  12129. this.database = database;
  12130. });
  12131. }
  12132. async _writeToStorage() {
  12133. const databaseStr = JSON.stringify(this.database);
  12134. localStorage.setItem("pdfjs.history", databaseStr);
  12135. }
  12136. async _readFromStorage() {
  12137. return localStorage.getItem("pdfjs.history");
  12138. }
  12139. async set(name, val) {
  12140. await this._initializedPromise;
  12141. this.file[name] = val;
  12142. return this._writeToStorage();
  12143. }
  12144. async setMultiple(properties) {
  12145. await this._initializedPromise;
  12146. for (const name in properties) {
  12147. this.file[name] = properties[name];
  12148. }
  12149. return this._writeToStorage();
  12150. }
  12151. async get(name, defaultValue) {
  12152. await this._initializedPromise;
  12153. const val = this.file[name];
  12154. return val !== undefined ? val : defaultValue;
  12155. }
  12156. async getMultiple(properties) {
  12157. await this._initializedPromise;
  12158. const values = Object.create(null);
  12159. for (const name in properties) {
  12160. const val = this.file[name];
  12161. values[name] = val !== undefined ? val : properties[name];
  12162. }
  12163. return values;
  12164. }
  12165. }
  12166. exports.ViewHistory = ViewHistory;
  12167. /***/ }),
  12168. /* 41 */
  12169. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12170. Object.defineProperty(exports, "__esModule", ({
  12171. value: true
  12172. }));
  12173. exports.GenericCom = void 0;
  12174. var _app = __webpack_require__(4);
  12175. var _preferences = __webpack_require__(42);
  12176. var _download_manager = __webpack_require__(43);
  12177. var _genericl10n = __webpack_require__(44);
  12178. var _generic_scripting = __webpack_require__(46);
  12179. ;
  12180. const GenericCom = {};
  12181. exports.GenericCom = GenericCom;
  12182. class GenericPreferences extends _preferences.BasePreferences {
  12183. async _writeToStorage(prefObj) {
  12184. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  12185. }
  12186. async _readFromStorage(prefObj) {
  12187. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  12188. }
  12189. }
  12190. class GenericExternalServices extends _app.DefaultExternalServices {
  12191. static createDownloadManager() {
  12192. return new _download_manager.DownloadManager();
  12193. }
  12194. static createPreferences() {
  12195. return new GenericPreferences();
  12196. }
  12197. static createL10n({
  12198. locale = "en-US"
  12199. }) {
  12200. return new _genericl10n.GenericL10n(locale);
  12201. }
  12202. static createScripting({
  12203. sandboxBundleSrc
  12204. }) {
  12205. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  12206. }
  12207. }
  12208. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  12209. /***/ }),
  12210. /* 42 */
  12211. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12212. Object.defineProperty(exports, "__esModule", ({
  12213. value: true
  12214. }));
  12215. exports.BasePreferences = void 0;
  12216. var _app_options = __webpack_require__(2);
  12217. class BasePreferences {
  12218. #defaults = Object.freeze({
  12219. "annotationEditorMode": 0,
  12220. "annotationMode": 2,
  12221. "cursorToolOnLoad": 0,
  12222. "defaultZoomDelay": 400,
  12223. "defaultZoomValue": "",
  12224. "disablePageLabels": false,
  12225. "enablePermissions": false,
  12226. "enablePrintAutoRotate": true,
  12227. "enableScripting": true,
  12228. "externalLinkTarget": 0,
  12229. "historyUpdateUrl": false,
  12230. "ignoreDestinationZoom": false,
  12231. "forcePageColors": false,
  12232. "pageColorsBackground": "Canvas",
  12233. "pageColorsForeground": "CanvasText",
  12234. "pdfBugEnabled": false,
  12235. "sidebarViewOnLoad": -1,
  12236. "scrollModeOnLoad": -1,
  12237. "spreadModeOnLoad": -1,
  12238. "textLayerMode": 1,
  12239. "useOnlyCssZoom": false,
  12240. "viewerCssTheme": 0,
  12241. "viewOnLoad": 0,
  12242. "disableAutoFetch": false,
  12243. "disableFontFace": false,
  12244. "disableRange": false,
  12245. "disableStream": false,
  12246. "enableXfa": true,
  12247. "renderer": "canvas"
  12248. });
  12249. #prefs = Object.create(null);
  12250. #initializedPromise = null;
  12251. constructor() {
  12252. if (this.constructor === BasePreferences) {
  12253. throw new Error("Cannot initialize BasePreferences.");
  12254. }
  12255. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  12256. for (const name in this.#defaults) {
  12257. const prefValue = prefs?.[name];
  12258. if (typeof prefValue === typeof this.#defaults[name]) {
  12259. this.#prefs[name] = prefValue;
  12260. }
  12261. }
  12262. });
  12263. }
  12264. async _writeToStorage(prefObj) {
  12265. throw new Error("Not implemented: _writeToStorage");
  12266. }
  12267. async _readFromStorage(prefObj) {
  12268. throw new Error("Not implemented: _readFromStorage");
  12269. }
  12270. async reset() {
  12271. await this.#initializedPromise;
  12272. const prefs = this.#prefs;
  12273. this.#prefs = Object.create(null);
  12274. return this._writeToStorage(this.#defaults).catch(reason => {
  12275. this.#prefs = prefs;
  12276. throw reason;
  12277. });
  12278. }
  12279. async set(name, value) {
  12280. await this.#initializedPromise;
  12281. const defaultValue = this.#defaults[name],
  12282. prefs = this.#prefs;
  12283. if (defaultValue === undefined) {
  12284. throw new Error(`Set preference: "${name}" is undefined.`);
  12285. } else if (value === undefined) {
  12286. throw new Error("Set preference: no value is specified.");
  12287. }
  12288. const valueType = typeof value,
  12289. defaultType = typeof defaultValue;
  12290. if (valueType !== defaultType) {
  12291. if (valueType === "number" && defaultType === "string") {
  12292. value = value.toString();
  12293. } else {
  12294. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  12295. }
  12296. } else {
  12297. if (valueType === "number" && !Number.isInteger(value)) {
  12298. throw new Error(`Set preference: "${value}" must be an integer.`);
  12299. }
  12300. }
  12301. this.#prefs[name] = value;
  12302. return this._writeToStorage(this.#prefs).catch(reason => {
  12303. this.#prefs = prefs;
  12304. throw reason;
  12305. });
  12306. }
  12307. async get(name) {
  12308. await this.#initializedPromise;
  12309. const defaultValue = this.#defaults[name];
  12310. if (defaultValue === undefined) {
  12311. throw new Error(`Get preference: "${name}" is undefined.`);
  12312. }
  12313. return this.#prefs[name] ?? defaultValue;
  12314. }
  12315. async getAll() {
  12316. await this.#initializedPromise;
  12317. const obj = Object.create(null);
  12318. for (const name in this.#defaults) {
  12319. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  12320. }
  12321. return obj;
  12322. }
  12323. }
  12324. exports.BasePreferences = BasePreferences;
  12325. /***/ }),
  12326. /* 43 */
  12327. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12328. Object.defineProperty(exports, "__esModule", ({
  12329. value: true
  12330. }));
  12331. exports.DownloadManager = void 0;
  12332. var _pdfjsLib = __webpack_require__(5);
  12333. ;
  12334. function download(blobUrl, filename) {
  12335. const a = document.createElement("a");
  12336. if (!a.click) {
  12337. throw new Error('DownloadManager: "a.click()" is not supported.');
  12338. }
  12339. a.href = blobUrl;
  12340. a.target = "_parent";
  12341. if ("download" in a) {
  12342. a.download = filename;
  12343. }
  12344. (document.body || document.documentElement).append(a);
  12345. a.click();
  12346. a.remove();
  12347. }
  12348. class DownloadManager {
  12349. #openBlobUrls = new WeakMap();
  12350. downloadUrl(url, filename) {
  12351. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  12352. console.error(`downloadUrl - not a valid URL: ${url}`);
  12353. return;
  12354. }
  12355. download(url + "#pdfjs.action=download", filename);
  12356. }
  12357. downloadData(data, filename, contentType) {
  12358. const blobUrl = URL.createObjectURL(new Blob([data], {
  12359. type: contentType
  12360. }));
  12361. download(blobUrl, filename);
  12362. }
  12363. openOrDownloadData(element, data, filename) {
  12364. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  12365. const contentType = isPdfData ? "application/pdf" : "";
  12366. if (isPdfData) {
  12367. let blobUrl = this.#openBlobUrls.get(element);
  12368. if (!blobUrl) {
  12369. blobUrl = URL.createObjectURL(new Blob([data], {
  12370. type: contentType
  12371. }));
  12372. this.#openBlobUrls.set(element, blobUrl);
  12373. }
  12374. let viewerUrl;
  12375. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  12376. try {
  12377. window.open(viewerUrl);
  12378. return true;
  12379. } catch (ex) {
  12380. console.error(`openOrDownloadData: ${ex}`);
  12381. URL.revokeObjectURL(blobUrl);
  12382. this.#openBlobUrls.delete(element);
  12383. }
  12384. }
  12385. this.downloadData(data, filename, contentType);
  12386. return false;
  12387. }
  12388. download(blob, url, filename) {
  12389. const blobUrl = URL.createObjectURL(blob);
  12390. download(blobUrl, filename);
  12391. }
  12392. }
  12393. exports.DownloadManager = DownloadManager;
  12394. /***/ }),
  12395. /* 44 */
  12396. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12397. Object.defineProperty(exports, "__esModule", ({
  12398. value: true
  12399. }));
  12400. exports.GenericL10n = void 0;
  12401. __webpack_require__(45);
  12402. var _l10n_utils = __webpack_require__(29);
  12403. const webL10n = document.webL10n;
  12404. class GenericL10n {
  12405. constructor(lang) {
  12406. this._lang = lang;
  12407. this._ready = new Promise((resolve, reject) => {
  12408. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  12409. resolve(webL10n);
  12410. });
  12411. });
  12412. }
  12413. async getLanguage() {
  12414. const l10n = await this._ready;
  12415. return l10n.getLanguage();
  12416. }
  12417. async getDirection() {
  12418. const l10n = await this._ready;
  12419. return l10n.getDirection();
  12420. }
  12421. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  12422. const l10n = await this._ready;
  12423. return l10n.get(key, args, fallback);
  12424. }
  12425. async translate(element) {
  12426. const l10n = await this._ready;
  12427. return l10n.translate(element);
  12428. }
  12429. }
  12430. exports.GenericL10n = GenericL10n;
  12431. /***/ }),
  12432. /* 45 */
  12433. /***/ (() => {
  12434. document.webL10n = function (window, document, undefined) {
  12435. var gL10nData = {};
  12436. var gTextData = '';
  12437. var gTextProp = 'textContent';
  12438. var gLanguage = '';
  12439. var gMacros = {};
  12440. var gReadyState = 'loading';
  12441. var gAsyncResourceLoading = true;
  12442. function getL10nResourceLinks() {
  12443. return document.querySelectorAll('link[type="application/l10n"]');
  12444. }
  12445. function getL10nDictionary() {
  12446. var script = document.querySelector('script[type="application/l10n"]');
  12447. return script ? JSON.parse(script.innerHTML) : null;
  12448. }
  12449. function getTranslatableChildren(element) {
  12450. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  12451. }
  12452. function getL10nAttributes(element) {
  12453. if (!element) return {};
  12454. var l10nId = element.getAttribute('data-l10n-id');
  12455. var l10nArgs = element.getAttribute('data-l10n-args');
  12456. var args = {};
  12457. if (l10nArgs) {
  12458. try {
  12459. args = JSON.parse(l10nArgs);
  12460. } catch (e) {
  12461. console.warn('could not parse arguments for #' + l10nId);
  12462. }
  12463. }
  12464. return {
  12465. id: l10nId,
  12466. args: args
  12467. };
  12468. }
  12469. function xhrLoadText(url, onSuccess, onFailure) {
  12470. onSuccess = onSuccess || function _onSuccess(data) {};
  12471. onFailure = onFailure || function _onFailure() {};
  12472. var xhr = new XMLHttpRequest();
  12473. xhr.open('GET', url, gAsyncResourceLoading);
  12474. if (xhr.overrideMimeType) {
  12475. xhr.overrideMimeType('text/plain; charset=utf-8');
  12476. }
  12477. xhr.onreadystatechange = function () {
  12478. if (xhr.readyState == 4) {
  12479. if (xhr.status == 200 || xhr.status === 0) {
  12480. onSuccess(xhr.responseText);
  12481. } else {
  12482. onFailure();
  12483. }
  12484. }
  12485. };
  12486. xhr.onerror = onFailure;
  12487. xhr.ontimeout = onFailure;
  12488. try {
  12489. xhr.send(null);
  12490. } catch (e) {
  12491. onFailure();
  12492. }
  12493. }
  12494. function parseResource(href, lang, successCallback, failureCallback) {
  12495. var baseURL = href.replace(/[^\/]*$/, '') || './';
  12496. function evalString(text) {
  12497. if (text.lastIndexOf('\\') < 0) return text;
  12498. 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, "'");
  12499. }
  12500. function parseProperties(text, parsedPropertiesCallback) {
  12501. var dictionary = {};
  12502. var reBlank = /^\s*|\s*$/;
  12503. var reComment = /^\s*#|^\s*$/;
  12504. var reSection = /^\s*\[(.*)\]\s*$/;
  12505. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  12506. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  12507. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  12508. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  12509. var currentLang = '*';
  12510. var genericLang = lang.split('-', 1)[0];
  12511. var skipLang = false;
  12512. var match = '';
  12513. function nextEntry() {
  12514. while (true) {
  12515. if (!entries.length) {
  12516. parsedRawLinesCallback();
  12517. return;
  12518. }
  12519. var line = entries.shift();
  12520. if (reComment.test(line)) continue;
  12521. if (extendedSyntax) {
  12522. match = reSection.exec(line);
  12523. if (match) {
  12524. currentLang = match[1].toLowerCase();
  12525. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  12526. continue;
  12527. } else if (skipLang) {
  12528. continue;
  12529. }
  12530. match = reImport.exec(line);
  12531. if (match) {
  12532. loadImport(baseURL + match[1], nextEntry);
  12533. return;
  12534. }
  12535. }
  12536. var tmp = line.match(reSplit);
  12537. if (tmp && tmp.length == 3) {
  12538. dictionary[tmp[1]] = evalString(tmp[2]);
  12539. }
  12540. }
  12541. }
  12542. nextEntry();
  12543. }
  12544. function loadImport(url, callback) {
  12545. xhrLoadText(url, function (content) {
  12546. parseRawLines(content, false, callback);
  12547. }, function () {
  12548. console.warn(url + ' not found.');
  12549. callback();
  12550. });
  12551. }
  12552. parseRawLines(text, true, function () {
  12553. parsedPropertiesCallback(dictionary);
  12554. });
  12555. }
  12556. xhrLoadText(href, function (response) {
  12557. gTextData += response;
  12558. parseProperties(response, function (data) {
  12559. for (var key in data) {
  12560. var id,
  12561. prop,
  12562. index = key.lastIndexOf('.');
  12563. if (index > 0) {
  12564. id = key.substring(0, index);
  12565. prop = key.substring(index + 1);
  12566. } else {
  12567. id = key;
  12568. prop = gTextProp;
  12569. }
  12570. if (!gL10nData[id]) {
  12571. gL10nData[id] = {};
  12572. }
  12573. gL10nData[id][prop] = data[key];
  12574. }
  12575. if (successCallback) {
  12576. successCallback();
  12577. }
  12578. });
  12579. }, failureCallback);
  12580. }
  12581. function loadLocale(lang, callback) {
  12582. if (lang) {
  12583. lang = lang.toLowerCase();
  12584. }
  12585. callback = callback || function _callback() {};
  12586. clear();
  12587. gLanguage = lang;
  12588. var langLinks = getL10nResourceLinks();
  12589. var langCount = langLinks.length;
  12590. if (langCount === 0) {
  12591. var dict = getL10nDictionary();
  12592. if (dict && dict.locales && dict.default_locale) {
  12593. console.log('using the embedded JSON directory, early way out');
  12594. gL10nData = dict.locales[lang];
  12595. if (!gL10nData) {
  12596. var defaultLocale = dict.default_locale.toLowerCase();
  12597. for (var anyCaseLang in dict.locales) {
  12598. anyCaseLang = anyCaseLang.toLowerCase();
  12599. if (anyCaseLang === lang) {
  12600. gL10nData = dict.locales[lang];
  12601. break;
  12602. } else if (anyCaseLang === defaultLocale) {
  12603. gL10nData = dict.locales[defaultLocale];
  12604. }
  12605. }
  12606. }
  12607. callback();
  12608. } else {
  12609. console.log('no resource to load, early way out');
  12610. }
  12611. gReadyState = 'complete';
  12612. return;
  12613. }
  12614. var onResourceLoaded = null;
  12615. var gResourceCount = 0;
  12616. onResourceLoaded = function () {
  12617. gResourceCount++;
  12618. if (gResourceCount >= langCount) {
  12619. callback();
  12620. gReadyState = 'complete';
  12621. }
  12622. };
  12623. function L10nResourceLink(link) {
  12624. var href = link.href;
  12625. this.load = function (lang, callback) {
  12626. parseResource(href, lang, callback, function () {
  12627. console.warn(href + ' not found.');
  12628. console.warn('"' + lang + '" resource not found');
  12629. gLanguage = '';
  12630. callback();
  12631. });
  12632. };
  12633. }
  12634. for (var i = 0; i < langCount; i++) {
  12635. var resource = new L10nResourceLink(langLinks[i]);
  12636. resource.load(lang, onResourceLoaded);
  12637. }
  12638. }
  12639. function clear() {
  12640. gL10nData = {};
  12641. gTextData = '';
  12642. gLanguage = '';
  12643. }
  12644. function getPluralRules(lang) {
  12645. var locales2rules = {
  12646. 'af': 3,
  12647. 'ak': 4,
  12648. 'am': 4,
  12649. 'ar': 1,
  12650. 'asa': 3,
  12651. 'az': 0,
  12652. 'be': 11,
  12653. 'bem': 3,
  12654. 'bez': 3,
  12655. 'bg': 3,
  12656. 'bh': 4,
  12657. 'bm': 0,
  12658. 'bn': 3,
  12659. 'bo': 0,
  12660. 'br': 20,
  12661. 'brx': 3,
  12662. 'bs': 11,
  12663. 'ca': 3,
  12664. 'cgg': 3,
  12665. 'chr': 3,
  12666. 'cs': 12,
  12667. 'cy': 17,
  12668. 'da': 3,
  12669. 'de': 3,
  12670. 'dv': 3,
  12671. 'dz': 0,
  12672. 'ee': 3,
  12673. 'el': 3,
  12674. 'en': 3,
  12675. 'eo': 3,
  12676. 'es': 3,
  12677. 'et': 3,
  12678. 'eu': 3,
  12679. 'fa': 0,
  12680. 'ff': 5,
  12681. 'fi': 3,
  12682. 'fil': 4,
  12683. 'fo': 3,
  12684. 'fr': 5,
  12685. 'fur': 3,
  12686. 'fy': 3,
  12687. 'ga': 8,
  12688. 'gd': 24,
  12689. 'gl': 3,
  12690. 'gsw': 3,
  12691. 'gu': 3,
  12692. 'guw': 4,
  12693. 'gv': 23,
  12694. 'ha': 3,
  12695. 'haw': 3,
  12696. 'he': 2,
  12697. 'hi': 4,
  12698. 'hr': 11,
  12699. 'hu': 0,
  12700. 'id': 0,
  12701. 'ig': 0,
  12702. 'ii': 0,
  12703. 'is': 3,
  12704. 'it': 3,
  12705. 'iu': 7,
  12706. 'ja': 0,
  12707. 'jmc': 3,
  12708. 'jv': 0,
  12709. 'ka': 0,
  12710. 'kab': 5,
  12711. 'kaj': 3,
  12712. 'kcg': 3,
  12713. 'kde': 0,
  12714. 'kea': 0,
  12715. 'kk': 3,
  12716. 'kl': 3,
  12717. 'km': 0,
  12718. 'kn': 0,
  12719. 'ko': 0,
  12720. 'ksb': 3,
  12721. 'ksh': 21,
  12722. 'ku': 3,
  12723. 'kw': 7,
  12724. 'lag': 18,
  12725. 'lb': 3,
  12726. 'lg': 3,
  12727. 'ln': 4,
  12728. 'lo': 0,
  12729. 'lt': 10,
  12730. 'lv': 6,
  12731. 'mas': 3,
  12732. 'mg': 4,
  12733. 'mk': 16,
  12734. 'ml': 3,
  12735. 'mn': 3,
  12736. 'mo': 9,
  12737. 'mr': 3,
  12738. 'ms': 0,
  12739. 'mt': 15,
  12740. 'my': 0,
  12741. 'nah': 3,
  12742. 'naq': 7,
  12743. 'nb': 3,
  12744. 'nd': 3,
  12745. 'ne': 3,
  12746. 'nl': 3,
  12747. 'nn': 3,
  12748. 'no': 3,
  12749. 'nr': 3,
  12750. 'nso': 4,
  12751. 'ny': 3,
  12752. 'nyn': 3,
  12753. 'om': 3,
  12754. 'or': 3,
  12755. 'pa': 3,
  12756. 'pap': 3,
  12757. 'pl': 13,
  12758. 'ps': 3,
  12759. 'pt': 3,
  12760. 'rm': 3,
  12761. 'ro': 9,
  12762. 'rof': 3,
  12763. 'ru': 11,
  12764. 'rwk': 3,
  12765. 'sah': 0,
  12766. 'saq': 3,
  12767. 'se': 7,
  12768. 'seh': 3,
  12769. 'ses': 0,
  12770. 'sg': 0,
  12771. 'sh': 11,
  12772. 'shi': 19,
  12773. 'sk': 12,
  12774. 'sl': 14,
  12775. 'sma': 7,
  12776. 'smi': 7,
  12777. 'smj': 7,
  12778. 'smn': 7,
  12779. 'sms': 7,
  12780. 'sn': 3,
  12781. 'so': 3,
  12782. 'sq': 3,
  12783. 'sr': 11,
  12784. 'ss': 3,
  12785. 'ssy': 3,
  12786. 'st': 3,
  12787. 'sv': 3,
  12788. 'sw': 3,
  12789. 'syr': 3,
  12790. 'ta': 3,
  12791. 'te': 3,
  12792. 'teo': 3,
  12793. 'th': 0,
  12794. 'ti': 4,
  12795. 'tig': 3,
  12796. 'tk': 3,
  12797. 'tl': 4,
  12798. 'tn': 3,
  12799. 'to': 0,
  12800. 'tr': 0,
  12801. 'ts': 3,
  12802. 'tzm': 22,
  12803. 'uk': 11,
  12804. 'ur': 3,
  12805. 've': 3,
  12806. 'vi': 0,
  12807. 'vun': 3,
  12808. 'wa': 4,
  12809. 'wae': 3,
  12810. 'wo': 0,
  12811. 'xh': 3,
  12812. 'xog': 3,
  12813. 'yo': 0,
  12814. 'zh': 0,
  12815. 'zu': 3
  12816. };
  12817. function isIn(n, list) {
  12818. return list.indexOf(n) !== -1;
  12819. }
  12820. function isBetween(n, start, end) {
  12821. return start <= n && n <= end;
  12822. }
  12823. var pluralRules = {
  12824. '0': function (n) {
  12825. return 'other';
  12826. },
  12827. '1': function (n) {
  12828. if (isBetween(n % 100, 3, 10)) return 'few';
  12829. if (n === 0) return 'zero';
  12830. if (isBetween(n % 100, 11, 99)) return 'many';
  12831. if (n == 2) return 'two';
  12832. if (n == 1) return 'one';
  12833. return 'other';
  12834. },
  12835. '2': function (n) {
  12836. if (n !== 0 && n % 10 === 0) return 'many';
  12837. if (n == 2) return 'two';
  12838. if (n == 1) return 'one';
  12839. return 'other';
  12840. },
  12841. '3': function (n) {
  12842. if (n == 1) return 'one';
  12843. return 'other';
  12844. },
  12845. '4': function (n) {
  12846. if (isBetween(n, 0, 1)) return 'one';
  12847. return 'other';
  12848. },
  12849. '5': function (n) {
  12850. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12851. return 'other';
  12852. },
  12853. '6': function (n) {
  12854. if (n === 0) return 'zero';
  12855. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12856. return 'other';
  12857. },
  12858. '7': function (n) {
  12859. if (n == 2) return 'two';
  12860. if (n == 1) return 'one';
  12861. return 'other';
  12862. },
  12863. '8': function (n) {
  12864. if (isBetween(n, 3, 6)) return 'few';
  12865. if (isBetween(n, 7, 10)) return 'many';
  12866. if (n == 2) return 'two';
  12867. if (n == 1) return 'one';
  12868. return 'other';
  12869. },
  12870. '9': function (n) {
  12871. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12872. if (n == 1) return 'one';
  12873. return 'other';
  12874. },
  12875. '10': function (n) {
  12876. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12877. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12878. return 'other';
  12879. },
  12880. '11': function (n) {
  12881. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12882. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12883. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12884. return 'other';
  12885. },
  12886. '12': function (n) {
  12887. if (isBetween(n, 2, 4)) return 'few';
  12888. if (n == 1) return 'one';
  12889. return 'other';
  12890. },
  12891. '13': function (n) {
  12892. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12893. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12894. if (n == 1) return 'one';
  12895. return 'other';
  12896. },
  12897. '14': function (n) {
  12898. if (isBetween(n % 100, 3, 4)) return 'few';
  12899. if (n % 100 == 2) return 'two';
  12900. if (n % 100 == 1) return 'one';
  12901. return 'other';
  12902. },
  12903. '15': function (n) {
  12904. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12905. if (isBetween(n % 100, 11, 19)) return 'many';
  12906. if (n == 1) return 'one';
  12907. return 'other';
  12908. },
  12909. '16': function (n) {
  12910. if (n % 10 == 1 && n != 11) return 'one';
  12911. return 'other';
  12912. },
  12913. '17': function (n) {
  12914. if (n == 3) return 'few';
  12915. if (n === 0) return 'zero';
  12916. if (n == 6) return 'many';
  12917. if (n == 2) return 'two';
  12918. if (n == 1) return 'one';
  12919. return 'other';
  12920. },
  12921. '18': function (n) {
  12922. if (n === 0) return 'zero';
  12923. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12924. return 'other';
  12925. },
  12926. '19': function (n) {
  12927. if (isBetween(n, 2, 10)) return 'few';
  12928. if (isBetween(n, 0, 1)) return 'one';
  12929. return 'other';
  12930. },
  12931. '20': function (n) {
  12932. 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';
  12933. if (n % 1000000 === 0 && n !== 0) return 'many';
  12934. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12935. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12936. return 'other';
  12937. },
  12938. '21': function (n) {
  12939. if (n === 0) return 'zero';
  12940. if (n == 1) return 'one';
  12941. return 'other';
  12942. },
  12943. '22': function (n) {
  12944. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  12945. return 'other';
  12946. },
  12947. '23': function (n) {
  12948. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  12949. return 'other';
  12950. },
  12951. '24': function (n) {
  12952. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  12953. if (isIn(n, [2, 12])) return 'two';
  12954. if (isIn(n, [1, 11])) return 'one';
  12955. return 'other';
  12956. }
  12957. };
  12958. var index = locales2rules[lang.replace(/-.*$/, '')];
  12959. if (!(index in pluralRules)) {
  12960. console.warn('plural form unknown for [' + lang + ']');
  12961. return function () {
  12962. return 'other';
  12963. };
  12964. }
  12965. return pluralRules[index];
  12966. }
  12967. gMacros.plural = function (str, param, key, prop) {
  12968. var n = parseFloat(param);
  12969. if (isNaN(n)) return str;
  12970. if (prop != gTextProp) return str;
  12971. if (!gMacros._pluralRules) {
  12972. gMacros._pluralRules = getPluralRules(gLanguage);
  12973. }
  12974. var index = '[' + gMacros._pluralRules(n) + ']';
  12975. if (n === 0 && key + '[zero]' in gL10nData) {
  12976. str = gL10nData[key + '[zero]'][prop];
  12977. } else if (n == 1 && key + '[one]' in gL10nData) {
  12978. str = gL10nData[key + '[one]'][prop];
  12979. } else if (n == 2 && key + '[two]' in gL10nData) {
  12980. str = gL10nData[key + '[two]'][prop];
  12981. } else if (key + index in gL10nData) {
  12982. str = gL10nData[key + index][prop];
  12983. } else if (key + '[other]' in gL10nData) {
  12984. str = gL10nData[key + '[other]'][prop];
  12985. }
  12986. return str;
  12987. };
  12988. function getL10nData(key, args, fallback) {
  12989. var data = gL10nData[key];
  12990. if (!data) {
  12991. console.warn('#' + key + ' is undefined.');
  12992. if (!fallback) {
  12993. return null;
  12994. }
  12995. data = fallback;
  12996. }
  12997. var rv = {};
  12998. for (var prop in data) {
  12999. var str = data[prop];
  13000. str = substIndexes(str, args, key, prop);
  13001. str = substArguments(str, args, key);
  13002. rv[prop] = str;
  13003. }
  13004. return rv;
  13005. }
  13006. function substIndexes(str, args, key, prop) {
  13007. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  13008. var reMatch = reIndex.exec(str);
  13009. if (!reMatch || !reMatch.length) return str;
  13010. var macroName = reMatch[1];
  13011. var paramName = reMatch[2];
  13012. var param;
  13013. if (args && paramName in args) {
  13014. param = args[paramName];
  13015. } else if (paramName in gL10nData) {
  13016. param = gL10nData[paramName];
  13017. }
  13018. if (macroName in gMacros) {
  13019. var macro = gMacros[macroName];
  13020. str = macro(str, param, key, prop);
  13021. }
  13022. return str;
  13023. }
  13024. function substArguments(str, args, key) {
  13025. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  13026. return str.replace(reArgs, function (matched_text, arg) {
  13027. if (args && arg in args) {
  13028. return args[arg];
  13029. }
  13030. if (arg in gL10nData) {
  13031. return gL10nData[arg];
  13032. }
  13033. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  13034. return matched_text;
  13035. });
  13036. }
  13037. function translateElement(element) {
  13038. var l10n = getL10nAttributes(element);
  13039. if (!l10n.id) return;
  13040. var data = getL10nData(l10n.id, l10n.args);
  13041. if (!data) {
  13042. console.warn('#' + l10n.id + ' is undefined.');
  13043. return;
  13044. }
  13045. if (data[gTextProp]) {
  13046. if (getChildElementCount(element) === 0) {
  13047. element[gTextProp] = data[gTextProp];
  13048. } else {
  13049. var children = element.childNodes;
  13050. var found = false;
  13051. for (var i = 0, l = children.length; i < l; i++) {
  13052. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  13053. if (found) {
  13054. children[i].nodeValue = '';
  13055. } else {
  13056. children[i].nodeValue = data[gTextProp];
  13057. found = true;
  13058. }
  13059. }
  13060. }
  13061. if (!found) {
  13062. var textNode = document.createTextNode(data[gTextProp]);
  13063. element.prepend(textNode);
  13064. }
  13065. }
  13066. delete data[gTextProp];
  13067. }
  13068. for (var k in data) {
  13069. element[k] = data[k];
  13070. }
  13071. }
  13072. function getChildElementCount(element) {
  13073. if (element.children) {
  13074. return element.children.length;
  13075. }
  13076. if (typeof element.childElementCount !== 'undefined') {
  13077. return element.childElementCount;
  13078. }
  13079. var count = 0;
  13080. for (var i = 0; i < element.childNodes.length; i++) {
  13081. count += element.nodeType === 1 ? 1 : 0;
  13082. }
  13083. return count;
  13084. }
  13085. function translateFragment(element) {
  13086. element = element || document.documentElement;
  13087. var children = getTranslatableChildren(element);
  13088. var elementCount = children.length;
  13089. for (var i = 0; i < elementCount; i++) {
  13090. translateElement(children[i]);
  13091. }
  13092. translateElement(element);
  13093. }
  13094. return {
  13095. get: function (key, args, fallbackString) {
  13096. var index = key.lastIndexOf('.');
  13097. var prop = gTextProp;
  13098. if (index > 0) {
  13099. prop = key.substring(index + 1);
  13100. key = key.substring(0, index);
  13101. }
  13102. var fallback;
  13103. if (fallbackString) {
  13104. fallback = {};
  13105. fallback[prop] = fallbackString;
  13106. }
  13107. var data = getL10nData(key, args, fallback);
  13108. if (data && prop in data) {
  13109. return data[prop];
  13110. }
  13111. return '{{' + key + '}}';
  13112. },
  13113. getData: function () {
  13114. return gL10nData;
  13115. },
  13116. getText: function () {
  13117. return gTextData;
  13118. },
  13119. getLanguage: function () {
  13120. return gLanguage;
  13121. },
  13122. setLanguage: function (lang, callback) {
  13123. loadLocale(lang, function () {
  13124. if (callback) callback();
  13125. });
  13126. },
  13127. getDirection: function () {
  13128. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  13129. var shortCode = gLanguage.split('-', 1)[0];
  13130. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  13131. },
  13132. translate: translateFragment,
  13133. getReadyState: function () {
  13134. return gReadyState;
  13135. },
  13136. ready: function (callback) {
  13137. if (!callback) {
  13138. return;
  13139. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  13140. window.setTimeout(function () {
  13141. callback();
  13142. });
  13143. } else if (document.addEventListener) {
  13144. document.addEventListener('localized', function once() {
  13145. document.removeEventListener('localized', once);
  13146. callback();
  13147. });
  13148. }
  13149. }
  13150. };
  13151. }(window, document);
  13152. /***/ }),
  13153. /* 46 */
  13154. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13155. Object.defineProperty(exports, "__esModule", ({
  13156. value: true
  13157. }));
  13158. exports.GenericScripting = void 0;
  13159. exports.docPropertiesLookup = docPropertiesLookup;
  13160. var _pdfjsLib = __webpack_require__(5);
  13161. async function docPropertiesLookup(pdfDocument) {
  13162. const url = "",
  13163. baseUrl = url.split("#")[0];
  13164. let {
  13165. info,
  13166. metadata,
  13167. contentDispositionFilename,
  13168. contentLength
  13169. } = await pdfDocument.getMetadata();
  13170. if (!contentLength) {
  13171. const {
  13172. length
  13173. } = await pdfDocument.getDownloadInfo();
  13174. contentLength = length;
  13175. }
  13176. return {
  13177. ...info,
  13178. baseURL: baseUrl,
  13179. filesize: contentLength,
  13180. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  13181. metadata: metadata?.getRaw(),
  13182. authors: metadata?.get("dc:creator"),
  13183. numPages: pdfDocument.numPages,
  13184. URL: url
  13185. };
  13186. }
  13187. class GenericScripting {
  13188. constructor(sandboxBundleSrc) {
  13189. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  13190. return window.pdfjsSandbox.QuickJSSandbox();
  13191. });
  13192. }
  13193. async createSandbox(data) {
  13194. const sandbox = await this._ready;
  13195. sandbox.create(data);
  13196. }
  13197. async dispatchEventInSandbox(event) {
  13198. const sandbox = await this._ready;
  13199. setTimeout(() => sandbox.dispatchEvent(event), 0);
  13200. }
  13201. async destroySandbox() {
  13202. const sandbox = await this._ready;
  13203. sandbox.nukeSandbox();
  13204. }
  13205. }
  13206. exports.GenericScripting = GenericScripting;
  13207. /***/ }),
  13208. /* 47 */
  13209. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13210. Object.defineProperty(exports, "__esModule", ({
  13211. value: true
  13212. }));
  13213. exports.PDFPrintService = PDFPrintService;
  13214. var _pdfjsLib = __webpack_require__(5);
  13215. var _app = __webpack_require__(4);
  13216. var _print_utils = __webpack_require__(48);
  13217. let activeService = null;
  13218. let dialog = null;
  13219. let overlayManager = null;
  13220. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  13221. const scratchCanvas = activeService.scratchCanvas;
  13222. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  13223. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  13224. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  13225. const ctx = scratchCanvas.getContext("2d");
  13226. ctx.save();
  13227. ctx.fillStyle = "rgb(255, 255, 255)";
  13228. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  13229. ctx.restore();
  13230. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  13231. const renderContext = {
  13232. canvasContext: ctx,
  13233. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  13234. viewport: pdfPage.getViewport({
  13235. scale: 1,
  13236. rotation: size.rotation
  13237. }),
  13238. intent: "print",
  13239. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  13240. optionalContentConfigPromise,
  13241. printAnnotationStorage
  13242. };
  13243. return pdfPage.render(renderContext).promise;
  13244. });
  13245. }
  13246. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) {
  13247. this.pdfDocument = pdfDocument;
  13248. this.pagesOverview = pagesOverview;
  13249. this.printContainer = printContainer;
  13250. this._printResolution = printResolution || 150;
  13251. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  13252. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  13253. this.l10n = l10n;
  13254. this.currentPage = -1;
  13255. this.scratchCanvas = document.createElement("canvas");
  13256. }
  13257. PDFPrintService.prototype = {
  13258. layout() {
  13259. this.throwIfInactive();
  13260. const body = document.querySelector("body");
  13261. body.setAttribute("data-pdfjsprinting", true);
  13262. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  13263. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  13264. }, this);
  13265. if (!hasEqualPageSizes) {
  13266. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  13267. }
  13268. this.pageStyleSheet = document.createElement("style");
  13269. const pageSize = this.pagesOverview[0];
  13270. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  13271. body.append(this.pageStyleSheet);
  13272. },
  13273. destroy() {
  13274. if (activeService !== this) {
  13275. return;
  13276. }
  13277. this.printContainer.textContent = "";
  13278. const body = document.querySelector("body");
  13279. body.removeAttribute("data-pdfjsprinting");
  13280. if (this.pageStyleSheet) {
  13281. this.pageStyleSheet.remove();
  13282. this.pageStyleSheet = null;
  13283. }
  13284. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  13285. this.scratchCanvas = null;
  13286. activeService = null;
  13287. ensureOverlay().then(function () {
  13288. if (overlayManager.active === dialog) {
  13289. overlayManager.close(dialog);
  13290. }
  13291. });
  13292. },
  13293. renderPages() {
  13294. if (this.pdfDocument.isPureXfa) {
  13295. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  13296. return Promise.resolve();
  13297. }
  13298. const pageCount = this.pagesOverview.length;
  13299. const renderNextPage = (resolve, reject) => {
  13300. this.throwIfInactive();
  13301. if (++this.currentPage >= pageCount) {
  13302. renderProgress(pageCount, pageCount, this.l10n);
  13303. resolve();
  13304. return;
  13305. }
  13306. const index = this.currentPage;
  13307. renderProgress(index, pageCount, this.l10n);
  13308. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  13309. renderNextPage(resolve, reject);
  13310. }, reject);
  13311. };
  13312. return new Promise(renderNextPage);
  13313. },
  13314. useRenderedPage() {
  13315. this.throwIfInactive();
  13316. const img = document.createElement("img");
  13317. const scratchCanvas = this.scratchCanvas;
  13318. if ("toBlob" in scratchCanvas) {
  13319. scratchCanvas.toBlob(function (blob) {
  13320. img.src = URL.createObjectURL(blob);
  13321. });
  13322. } else {
  13323. img.src = scratchCanvas.toDataURL();
  13324. }
  13325. const wrapper = document.createElement("div");
  13326. wrapper.className = "printedPage";
  13327. wrapper.append(img);
  13328. this.printContainer.append(wrapper);
  13329. return new Promise(function (resolve, reject) {
  13330. img.onload = resolve;
  13331. img.onerror = reject;
  13332. });
  13333. },
  13334. performPrint() {
  13335. this.throwIfInactive();
  13336. return new Promise(resolve => {
  13337. setTimeout(() => {
  13338. if (!this.active) {
  13339. resolve();
  13340. return;
  13341. }
  13342. print.call(window);
  13343. setTimeout(resolve, 20);
  13344. }, 0);
  13345. });
  13346. },
  13347. get active() {
  13348. return this === activeService;
  13349. },
  13350. throwIfInactive() {
  13351. if (!this.active) {
  13352. throw new Error("This print request was cancelled or completed.");
  13353. }
  13354. }
  13355. };
  13356. const print = window.print;
  13357. window.print = function () {
  13358. if (activeService) {
  13359. console.warn("Ignored window.print() because of a pending print job.");
  13360. return;
  13361. }
  13362. ensureOverlay().then(function () {
  13363. if (activeService) {
  13364. overlayManager.open(dialog);
  13365. }
  13366. });
  13367. try {
  13368. dispatchEvent("beforeprint");
  13369. } finally {
  13370. if (!activeService) {
  13371. console.error("Expected print service to be initialized.");
  13372. ensureOverlay().then(function () {
  13373. if (overlayManager.active === dialog) {
  13374. overlayManager.close(dialog);
  13375. }
  13376. });
  13377. return;
  13378. }
  13379. const activeServiceOnEntry = activeService;
  13380. activeService.renderPages().then(function () {
  13381. return activeServiceOnEntry.performPrint();
  13382. }).catch(function () {}).then(function () {
  13383. if (activeServiceOnEntry.active) {
  13384. abort();
  13385. }
  13386. });
  13387. }
  13388. };
  13389. function dispatchEvent(eventType) {
  13390. const event = document.createEvent("CustomEvent");
  13391. event.initCustomEvent(eventType, false, false, "custom");
  13392. window.dispatchEvent(event);
  13393. }
  13394. function abort() {
  13395. if (activeService) {
  13396. activeService.destroy();
  13397. dispatchEvent("afterprint");
  13398. }
  13399. }
  13400. function renderProgress(index, total, l10n) {
  13401. dialog ||= document.getElementById("printServiceDialog");
  13402. const progress = Math.round(100 * index / total);
  13403. const progressBar = dialog.querySelector("progress");
  13404. const progressPerc = dialog.querySelector(".relative-progress");
  13405. progressBar.value = progress;
  13406. l10n.get("print_progress_percent", {
  13407. progress
  13408. }).then(msg => {
  13409. progressPerc.textContent = msg;
  13410. });
  13411. }
  13412. window.addEventListener("keydown", function (event) {
  13413. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  13414. window.print();
  13415. event.preventDefault();
  13416. event.stopImmediatePropagation();
  13417. }
  13418. }, true);
  13419. if ("onbeforeprint" in window) {
  13420. const stopPropagationIfNeeded = function (event) {
  13421. if (event.detail !== "custom") {
  13422. event.stopImmediatePropagation();
  13423. }
  13424. };
  13425. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  13426. window.addEventListener("afterprint", stopPropagationIfNeeded);
  13427. }
  13428. let overlayPromise;
  13429. function ensureOverlay() {
  13430. if (!overlayPromise) {
  13431. overlayManager = _app.PDFViewerApplication.overlayManager;
  13432. if (!overlayManager) {
  13433. throw new Error("The overlay manager has not yet been initialized.");
  13434. }
  13435. dialog ||= document.getElementById("printServiceDialog");
  13436. overlayPromise = overlayManager.register(dialog, true);
  13437. document.getElementById("printCancel").onclick = abort;
  13438. dialog.addEventListener("close", abort);
  13439. }
  13440. return overlayPromise;
  13441. }
  13442. _app.PDFPrintServiceFactory.instance = {
  13443. supportsPrinting: true,
  13444. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  13445. if (activeService) {
  13446. throw new Error("The print service is created and active.");
  13447. }
  13448. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  13449. return activeService;
  13450. }
  13451. };
  13452. /***/ }),
  13453. /* 48 */
  13454. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13455. Object.defineProperty(exports, "__esModule", ({
  13456. value: true
  13457. }));
  13458. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  13459. var _pdfjsLib = __webpack_require__(5);
  13460. var _pdf_link_service = __webpack_require__(3);
  13461. var _xfa_layer_builder = __webpack_require__(37);
  13462. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  13463. const xfaHtml = pdfDocument.allXfaHtml;
  13464. const linkService = new _pdf_link_service.SimpleLinkService();
  13465. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  13466. for (const xfaPage of xfaHtml.children) {
  13467. const page = document.createElement("div");
  13468. page.className = "xfaPrintedPage";
  13469. printContainer.append(page);
  13470. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  13471. pageDiv: page,
  13472. pdfPage: null,
  13473. annotationStorage: pdfDocument.annotationStorage,
  13474. linkService,
  13475. xfaHtml: xfaPage
  13476. });
  13477. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  13478. scale
  13479. });
  13480. builder.render(viewport, "print");
  13481. }
  13482. }
  13483. /***/ })
  13484. /******/ ]);
  13485. /************************************************************************/
  13486. /******/ // The module cache
  13487. /******/ var __webpack_module_cache__ = {};
  13488. /******/
  13489. /******/ // The require function
  13490. /******/ function __webpack_require__(moduleId) {
  13491. /******/ // Check if module is in cache
  13492. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  13493. /******/ if (cachedModule !== undefined) {
  13494. /******/ return cachedModule.exports;
  13495. /******/ }
  13496. /******/ // Create a new module (and put it into the cache)
  13497. /******/ var module = __webpack_module_cache__[moduleId] = {
  13498. /******/ // no module.id needed
  13499. /******/ // no module.loaded needed
  13500. /******/ exports: {}
  13501. /******/ };
  13502. /******/
  13503. /******/ // Execute the module function
  13504. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  13505. /******/
  13506. /******/ // Return the exports of the module
  13507. /******/ return module.exports;
  13508. /******/ }
  13509. /******/
  13510. /************************************************************************/
  13511. var __webpack_exports__ = {};
  13512. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  13513. (() => {
  13514. var exports = __webpack_exports__;
  13515. Object.defineProperty(exports, "__esModule", ({
  13516. value: true
  13517. }));
  13518. Object.defineProperty(exports, "PDFViewerApplication", ({
  13519. enumerable: true,
  13520. get: function () {
  13521. return _app.PDFViewerApplication;
  13522. }
  13523. }));
  13524. exports.PDFViewerApplicationConstants = void 0;
  13525. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  13526. enumerable: true,
  13527. get: function () {
  13528. return _app_options.AppOptions;
  13529. }
  13530. }));
  13531. var _ui_utils = __webpack_require__(1);
  13532. var _app_options = __webpack_require__(2);
  13533. var _pdf_link_service = __webpack_require__(3);
  13534. var _app = __webpack_require__(4);
  13535. const pdfjsVersion = '3.3.122';
  13536. const pdfjsBuild = '562045607';
  13537. const AppConstants = {
  13538. LinkTarget: _pdf_link_service.LinkTarget,
  13539. RenderingStates: _ui_utils.RenderingStates,
  13540. ScrollMode: _ui_utils.ScrollMode,
  13541. SpreadMode: _ui_utils.SpreadMode
  13542. };
  13543. exports.PDFViewerApplicationConstants = AppConstants;
  13544. window.PDFViewerApplication = _app.PDFViewerApplication;
  13545. window.PDFViewerApplicationConstants = AppConstants;
  13546. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  13547. ;
  13548. ;
  13549. {
  13550. __webpack_require__(41);
  13551. }
  13552. ;
  13553. {
  13554. __webpack_require__(47);
  13555. }
  13556. function getViewerConfiguration() {
  13557. return {
  13558. appContainer: document.body,
  13559. mainContainer: document.getElementById("viewerContainer"),
  13560. viewerContainer: document.getElementById("viewer"),
  13561. toolbar: {
  13562. container: document.getElementById("toolbarViewer"),
  13563. numPages: document.getElementById("numPages"),
  13564. pageNumber: document.getElementById("pageNumber"),
  13565. scaleSelect: document.getElementById("scaleSelect"),
  13566. customScaleOption: document.getElementById("customScaleOption"),
  13567. previous: document.getElementById("previous"),
  13568. next: document.getElementById("next"),
  13569. zoomIn: document.getElementById("zoomIn"),
  13570. zoomOut: document.getElementById("zoomOut"),
  13571. viewFind: document.getElementById("viewFind"),
  13572. openFile: document.getElementById("openFile"),
  13573. print: document.getElementById("print"),
  13574. editorFreeTextButton: document.getElementById("editorFreeText"),
  13575. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  13576. editorInkButton: document.getElementById("editorInk"),
  13577. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  13578. download: document.getElementById("download")
  13579. },
  13580. secondaryToolbar: {
  13581. toolbar: document.getElementById("secondaryToolbar"),
  13582. toggleButton: document.getElementById("secondaryToolbarToggle"),
  13583. presentationModeButton: document.getElementById("presentationMode"),
  13584. openFileButton: document.getElementById("secondaryOpenFile"),
  13585. printButton: document.getElementById("secondaryPrint"),
  13586. downloadButton: document.getElementById("secondaryDownload"),
  13587. viewBookmarkButton: document.getElementById("viewBookmark"),
  13588. firstPageButton: document.getElementById("firstPage"),
  13589. lastPageButton: document.getElementById("lastPage"),
  13590. pageRotateCwButton: document.getElementById("pageRotateCw"),
  13591. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  13592. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  13593. cursorHandToolButton: document.getElementById("cursorHandTool"),
  13594. scrollPageButton: document.getElementById("scrollPage"),
  13595. scrollVerticalButton: document.getElementById("scrollVertical"),
  13596. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  13597. scrollWrappedButton: document.getElementById("scrollWrapped"),
  13598. spreadNoneButton: document.getElementById("spreadNone"),
  13599. spreadOddButton: document.getElementById("spreadOdd"),
  13600. spreadEvenButton: document.getElementById("spreadEven"),
  13601. documentPropertiesButton: document.getElementById("documentProperties")
  13602. },
  13603. sidebar: {
  13604. outerContainer: document.getElementById("outerContainer"),
  13605. sidebarContainer: document.getElementById("sidebarContainer"),
  13606. toggleButton: document.getElementById("sidebarToggle"),
  13607. thumbnailButton: document.getElementById("viewThumbnail"),
  13608. outlineButton: document.getElementById("viewOutline"),
  13609. attachmentsButton: document.getElementById("viewAttachments"),
  13610. layersButton: document.getElementById("viewLayers"),
  13611. thumbnailView: document.getElementById("thumbnailView"),
  13612. outlineView: document.getElementById("outlineView"),
  13613. attachmentsView: document.getElementById("attachmentsView"),
  13614. layersView: document.getElementById("layersView"),
  13615. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  13616. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  13617. },
  13618. sidebarResizer: {
  13619. outerContainer: document.getElementById("outerContainer"),
  13620. resizer: document.getElementById("sidebarResizer")
  13621. },
  13622. findBar: {
  13623. bar: document.getElementById("findbar"),
  13624. toggleButton: document.getElementById("viewFind"),
  13625. findField: document.getElementById("findInput"),
  13626. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  13627. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  13628. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  13629. entireWordCheckbox: document.getElementById("findEntireWord"),
  13630. findMsg: document.getElementById("findMsg"),
  13631. findResultsCount: document.getElementById("findResultsCount"),
  13632. findPreviousButton: document.getElementById("findPrevious"),
  13633. findNextButton: document.getElementById("findNext")
  13634. },
  13635. passwordOverlay: {
  13636. dialog: document.getElementById("passwordDialog"),
  13637. label: document.getElementById("passwordText"),
  13638. input: document.getElementById("password"),
  13639. submitButton: document.getElementById("passwordSubmit"),
  13640. cancelButton: document.getElementById("passwordCancel")
  13641. },
  13642. documentProperties: {
  13643. dialog: document.getElementById("documentPropertiesDialog"),
  13644. closeButton: document.getElementById("documentPropertiesClose"),
  13645. fields: {
  13646. fileName: document.getElementById("fileNameField"),
  13647. fileSize: document.getElementById("fileSizeField"),
  13648. title: document.getElementById("titleField"),
  13649. author: document.getElementById("authorField"),
  13650. subject: document.getElementById("subjectField"),
  13651. keywords: document.getElementById("keywordsField"),
  13652. creationDate: document.getElementById("creationDateField"),
  13653. modificationDate: document.getElementById("modificationDateField"),
  13654. creator: document.getElementById("creatorField"),
  13655. producer: document.getElementById("producerField"),
  13656. version: document.getElementById("versionField"),
  13657. pageCount: document.getElementById("pageCountField"),
  13658. pageSize: document.getElementById("pageSizeField"),
  13659. linearized: document.getElementById("linearizedField")
  13660. }
  13661. },
  13662. annotationEditorParams: {
  13663. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  13664. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  13665. editorInkColor: document.getElementById("editorInkColor"),
  13666. editorInkThickness: document.getElementById("editorInkThickness"),
  13667. editorInkOpacity: document.getElementById("editorInkOpacity")
  13668. },
  13669. printContainer: document.getElementById("printContainer"),
  13670. openFileInput: document.getElementById("fileInput"),
  13671. debuggerScriptPath: "./debugger.js"
  13672. };
  13673. }
  13674. function webViewerLoad() {
  13675. const config = getViewerConfiguration();
  13676. const event = document.createEvent("CustomEvent");
  13677. event.initCustomEvent("webviewerloaded", true, true, {
  13678. source: window
  13679. });
  13680. try {
  13681. parent.document.dispatchEvent(event);
  13682. } catch (ex) {
  13683. console.error(`webviewerloaded: ${ex}`);
  13684. document.dispatchEvent(event);
  13685. }
  13686. _app.PDFViewerApplication.run(config);
  13687. }
  13688. document.blockUnblockOnload?.(true);
  13689. if (document.readyState === "interactive" || document.readyState === "complete") {
  13690. webViewerLoad();
  13691. } else {
  13692. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  13693. }
  13694. })();
  13695. /******/ })()
  13696. ;
  13697. //# sourceMappingURL=viewer.js.map