viewer.js 416 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. /******/ (() => { // 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. let delta = normalizeWheelEventDirection(evt);
  401. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  402. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  403. const MOUSE_PIXELS_PER_LINE = 30;
  404. const MOUSE_LINES_PER_PAGE = 30;
  405. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  406. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  407. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  408. delta /= MOUSE_LINES_PER_PAGE;
  409. }
  410. return delta;
  411. }
  412. function isValidRotation(angle) {
  413. return Number.isInteger(angle) && angle % 90 === 0;
  414. }
  415. function isValidScrollMode(mode) {
  416. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  417. }
  418. function isValidSpreadMode(mode) {
  419. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  420. }
  421. function isPortraitOrientation(size) {
  422. return size.width <= size.height;
  423. }
  424. const animationStarted = new Promise(function (resolve) {
  425. window.requestAnimationFrame(resolve);
  426. });
  427. exports.animationStarted = animationStarted;
  428. const docStyle = document.documentElement.style;
  429. exports.docStyle = docStyle;
  430. function clamp(v, min, max) {
  431. return Math.min(Math.max(v, min), max);
  432. }
  433. class ProgressBar {
  434. #classList = null;
  435. #percent = 0;
  436. #visible = true;
  437. constructor(id) {
  438. const bar = document.getElementById(id);
  439. this.#classList = bar.classList;
  440. }
  441. get percent() {
  442. return this.#percent;
  443. }
  444. set percent(val) {
  445. this.#percent = clamp(val, 0, 100);
  446. if (isNaN(val)) {
  447. this.#classList.add("indeterminate");
  448. return;
  449. }
  450. this.#classList.remove("indeterminate");
  451. docStyle.setProperty("--progressBar-percent", `${this.#percent}%`);
  452. }
  453. setWidth(viewer) {
  454. if (!viewer) {
  455. return;
  456. }
  457. const container = viewer.parentNode;
  458. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  459. if (scrollbarWidth > 0) {
  460. docStyle.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  461. }
  462. }
  463. hide() {
  464. if (!this.#visible) {
  465. return;
  466. }
  467. this.#visible = false;
  468. this.#classList.add("hidden");
  469. }
  470. show() {
  471. if (this.#visible) {
  472. return;
  473. }
  474. this.#visible = true;
  475. this.#classList.remove("hidden");
  476. }
  477. }
  478. exports.ProgressBar = ProgressBar;
  479. function getActiveOrFocusedElement() {
  480. let curRoot = document;
  481. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  482. while (curActiveOrFocused?.shadowRoot) {
  483. curRoot = curActiveOrFocused.shadowRoot;
  484. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  485. }
  486. return curActiveOrFocused;
  487. }
  488. function apiPageLayoutToViewerModes(layout) {
  489. let scrollMode = ScrollMode.VERTICAL,
  490. spreadMode = SpreadMode.NONE;
  491. switch (layout) {
  492. case "SinglePage":
  493. scrollMode = ScrollMode.PAGE;
  494. break;
  495. case "OneColumn":
  496. break;
  497. case "TwoPageLeft":
  498. scrollMode = ScrollMode.PAGE;
  499. case "TwoColumnLeft":
  500. spreadMode = SpreadMode.ODD;
  501. break;
  502. case "TwoPageRight":
  503. scrollMode = ScrollMode.PAGE;
  504. case "TwoColumnRight":
  505. spreadMode = SpreadMode.EVEN;
  506. break;
  507. }
  508. return {
  509. scrollMode,
  510. spreadMode
  511. };
  512. }
  513. function apiPageModeToSidebarView(mode) {
  514. switch (mode) {
  515. case "UseNone":
  516. return SidebarView.NONE;
  517. case "UseThumbs":
  518. return SidebarView.THUMBS;
  519. case "UseOutlines":
  520. return SidebarView.OUTLINE;
  521. case "UseAttachments":
  522. return SidebarView.ATTACHMENTS;
  523. case "UseOC":
  524. return SidebarView.LAYERS;
  525. }
  526. return SidebarView.NONE;
  527. }
  528. /***/ }),
  529. /* 2 */
  530. /***/ ((__unused_webpack_module, exports) => {
  531. Object.defineProperty(exports, "__esModule", ({
  532. value: true
  533. }));
  534. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  535. const compatibilityParams = Object.create(null);
  536. exports.compatibilityParams = compatibilityParams;
  537. {
  538. const userAgent = navigator.userAgent || "";
  539. const platform = navigator.platform || "";
  540. const maxTouchPoints = navigator.maxTouchPoints || 1;
  541. const isAndroid = /Android/.test(userAgent);
  542. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  543. (function checkCanvasSizeLimitation() {
  544. if (isIOS || isAndroid) {
  545. compatibilityParams.maxCanvasPixels = 5242880;
  546. }
  547. })();
  548. }
  549. const OptionKind = {
  550. VIEWER: 0x02,
  551. API: 0x04,
  552. WORKER: 0x08,
  553. PREFERENCE: 0x80
  554. };
  555. exports.OptionKind = OptionKind;
  556. const defaultOptions = {
  557. annotationEditorMode: {
  558. value: 0,
  559. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  560. },
  561. annotationMode: {
  562. value: 2,
  563. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  564. },
  565. cursorToolOnLoad: {
  566. value: 0,
  567. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  568. },
  569. defaultZoomValue: {
  570. value: "",
  571. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  572. },
  573. disableHistory: {
  574. value: false,
  575. kind: OptionKind.VIEWER
  576. },
  577. disablePageLabels: {
  578. value: false,
  579. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  580. },
  581. enablePermissions: {
  582. value: false,
  583. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  584. },
  585. enablePrintAutoRotate: {
  586. value: true,
  587. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  588. },
  589. enableScripting: {
  590. value: true,
  591. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  592. },
  593. externalLinkRel: {
  594. value: "noopener noreferrer nofollow",
  595. kind: OptionKind.VIEWER
  596. },
  597. externalLinkTarget: {
  598. value: 0,
  599. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  600. },
  601. historyUpdateUrl: {
  602. value: false,
  603. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  604. },
  605. ignoreDestinationZoom: {
  606. value: false,
  607. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  608. },
  609. imageResourcesPath: {
  610. value: "./images/",
  611. kind: OptionKind.VIEWER
  612. },
  613. maxCanvasPixels: {
  614. value: 16777216,
  615. kind: OptionKind.VIEWER
  616. },
  617. forcePageColors: {
  618. value: false,
  619. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  620. },
  621. pageColorsBackground: {
  622. value: "Canvas",
  623. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  624. },
  625. pageColorsForeground: {
  626. value: "CanvasText",
  627. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  628. },
  629. pdfBugEnabled: {
  630. value: false,
  631. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  632. },
  633. printResolution: {
  634. value: 150,
  635. kind: OptionKind.VIEWER
  636. },
  637. sidebarViewOnLoad: {
  638. value: -1,
  639. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  640. },
  641. scrollModeOnLoad: {
  642. value: -1,
  643. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  644. },
  645. spreadModeOnLoad: {
  646. value: -1,
  647. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  648. },
  649. textLayerMode: {
  650. value: 1,
  651. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  652. },
  653. useOnlyCssZoom: {
  654. value: false,
  655. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  656. },
  657. viewerCssTheme: {
  658. value: 0,
  659. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  660. },
  661. viewOnLoad: {
  662. value: 0,
  663. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  664. },
  665. cMapPacked: {
  666. value: true,
  667. kind: OptionKind.API
  668. },
  669. cMapUrl: {
  670. value: "../web/cmaps/",
  671. kind: OptionKind.API
  672. },
  673. disableAutoFetch: {
  674. value: false,
  675. kind: OptionKind.API + OptionKind.PREFERENCE
  676. },
  677. disableFontFace: {
  678. value: false,
  679. kind: OptionKind.API + OptionKind.PREFERENCE
  680. },
  681. disableRange: {
  682. value: false,
  683. kind: OptionKind.API + OptionKind.PREFERENCE
  684. },
  685. disableStream: {
  686. value: false,
  687. kind: OptionKind.API + OptionKind.PREFERENCE
  688. },
  689. docBaseUrl: {
  690. value: "",
  691. kind: OptionKind.API
  692. },
  693. enableXfa: {
  694. value: true,
  695. kind: OptionKind.API + OptionKind.PREFERENCE
  696. },
  697. fontExtraProperties: {
  698. value: false,
  699. kind: OptionKind.API
  700. },
  701. isEvalSupported: {
  702. value: true,
  703. kind: OptionKind.API
  704. },
  705. isOffscreenCanvasSupported: {
  706. value: true,
  707. kind: OptionKind.API
  708. },
  709. maxImageSize: {
  710. value: -1,
  711. kind: OptionKind.API
  712. },
  713. pdfBug: {
  714. value: false,
  715. kind: OptionKind.API
  716. },
  717. standardFontDataUrl: {
  718. value: "../web/standard_fonts/",
  719. kind: OptionKind.API
  720. },
  721. verbosity: {
  722. value: 1,
  723. kind: OptionKind.API
  724. },
  725. workerPort: {
  726. value: null,
  727. kind: OptionKind.WORKER
  728. },
  729. workerSrc: {
  730. value: "../build/pdf.worker.js",
  731. kind: OptionKind.WORKER
  732. }
  733. };
  734. {
  735. defaultOptions.defaultUrl = {
  736. value: "Pig.pdf",
  737. kind: OptionKind.VIEWER
  738. };
  739. defaultOptions.disablePreferences = {
  740. value: false,
  741. kind: OptionKind.VIEWER
  742. };
  743. defaultOptions.locale = {
  744. value: navigator.language || "en-US",
  745. kind: OptionKind.VIEWER
  746. };
  747. defaultOptions.renderer = {
  748. value: "canvas",
  749. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  750. };
  751. defaultOptions.sandboxBundleSrc = {
  752. value: "../build/pdf.sandbox.js",
  753. kind: OptionKind.VIEWER
  754. };
  755. }
  756. const userOptions = Object.create(null);
  757. class AppOptions {
  758. constructor() {
  759. throw new Error("Cannot initialize AppOptions.");
  760. }
  761. static get(name) {
  762. const userOption = userOptions[name];
  763. if (userOption !== undefined) {
  764. return userOption;
  765. }
  766. const defaultOption = defaultOptions[name];
  767. if (defaultOption !== undefined) {
  768. return compatibilityParams[name] ?? defaultOption.value;
  769. }
  770. return undefined;
  771. }
  772. static getAll(kind = null) {
  773. const options = Object.create(null);
  774. for (const name in defaultOptions) {
  775. const defaultOption = defaultOptions[name];
  776. if (kind) {
  777. if ((kind & defaultOption.kind) === 0) {
  778. continue;
  779. }
  780. if (kind === OptionKind.PREFERENCE) {
  781. const value = defaultOption.value,
  782. valueType = typeof value;
  783. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  784. options[name] = value;
  785. continue;
  786. }
  787. throw new Error(`Invalid type for preference: ${name}`);
  788. }
  789. }
  790. const userOption = userOptions[name];
  791. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  792. }
  793. return options;
  794. }
  795. static set(name, value) {
  796. userOptions[name] = value;
  797. }
  798. static setAll(options) {
  799. for (const name in options) {
  800. userOptions[name] = options[name];
  801. }
  802. }
  803. static remove(name) {
  804. delete userOptions[name];
  805. }
  806. static _hasUserOptions() {
  807. return Object.keys(userOptions).length > 0;
  808. }
  809. }
  810. exports.AppOptions = AppOptions;
  811. /***/ }),
  812. /* 3 */
  813. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  814. Object.defineProperty(exports, "__esModule", ({
  815. value: true
  816. }));
  817. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  818. var _ui_utils = __webpack_require__(1);
  819. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  820. const LinkTarget = {
  821. NONE: 0,
  822. SELF: 1,
  823. BLANK: 2,
  824. PARENT: 3,
  825. TOP: 4
  826. };
  827. exports.LinkTarget = LinkTarget;
  828. function addLinkAttributes(link, {
  829. url,
  830. target,
  831. rel,
  832. enabled = true
  833. } = {}) {
  834. if (!url || typeof url !== "string") {
  835. throw new Error('A valid "url" parameter must provided.');
  836. }
  837. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  838. if (enabled) {
  839. link.href = link.title = urlNullRemoved;
  840. } else {
  841. link.href = "";
  842. link.title = `Disabled: ${urlNullRemoved}`;
  843. link.onclick = () => {
  844. return false;
  845. };
  846. }
  847. let targetStr = "";
  848. switch (target) {
  849. case LinkTarget.NONE:
  850. break;
  851. case LinkTarget.SELF:
  852. targetStr = "_self";
  853. break;
  854. case LinkTarget.BLANK:
  855. targetStr = "_blank";
  856. break;
  857. case LinkTarget.PARENT:
  858. targetStr = "_parent";
  859. break;
  860. case LinkTarget.TOP:
  861. targetStr = "_top";
  862. break;
  863. }
  864. link.target = targetStr;
  865. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  866. }
  867. class PDFLinkService {
  868. #pagesRefCache = new Map();
  869. constructor({
  870. eventBus,
  871. externalLinkTarget = null,
  872. externalLinkRel = null,
  873. ignoreDestinationZoom = false
  874. } = {}) {
  875. this.eventBus = eventBus;
  876. this.externalLinkTarget = externalLinkTarget;
  877. this.externalLinkRel = externalLinkRel;
  878. this.externalLinkEnabled = true;
  879. this._ignoreDestinationZoom = ignoreDestinationZoom;
  880. this.baseUrl = null;
  881. this.pdfDocument = null;
  882. this.pdfViewer = null;
  883. this.pdfHistory = null;
  884. }
  885. setDocument(pdfDocument, baseUrl = null) {
  886. this.baseUrl = baseUrl;
  887. this.pdfDocument = pdfDocument;
  888. this.#pagesRefCache.clear();
  889. }
  890. setViewer(pdfViewer) {
  891. this.pdfViewer = pdfViewer;
  892. }
  893. setHistory(pdfHistory) {
  894. this.pdfHistory = pdfHistory;
  895. }
  896. get pagesCount() {
  897. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  898. }
  899. get page() {
  900. return this.pdfViewer.currentPageNumber;
  901. }
  902. set page(value) {
  903. this.pdfViewer.currentPageNumber = value;
  904. }
  905. get rotation() {
  906. return this.pdfViewer.pagesRotation;
  907. }
  908. set rotation(value) {
  909. this.pdfViewer.pagesRotation = value;
  910. }
  911. get isInPresentationMode() {
  912. return this.pdfViewer.isInPresentationMode;
  913. }
  914. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  915. const destRef = explicitDest[0];
  916. let pageNumber;
  917. if (typeof destRef === "object" && destRef !== null) {
  918. pageNumber = this._cachedPageNumber(destRef);
  919. if (!pageNumber) {
  920. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  921. this.cachePageRef(pageIndex + 1, destRef);
  922. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  923. }).catch(() => {
  924. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  925. });
  926. return;
  927. }
  928. } else if (Number.isInteger(destRef)) {
  929. pageNumber = destRef + 1;
  930. } else {
  931. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  932. return;
  933. }
  934. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  935. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  936. return;
  937. }
  938. if (this.pdfHistory) {
  939. this.pdfHistory.pushCurrentPosition();
  940. this.pdfHistory.push({
  941. namedDest,
  942. explicitDest,
  943. pageNumber
  944. });
  945. }
  946. this.pdfViewer.scrollPageIntoView({
  947. pageNumber,
  948. destArray: explicitDest,
  949. ignoreDestinationZoom: this._ignoreDestinationZoom
  950. });
  951. }
  952. async goToDestination(dest) {
  953. if (!this.pdfDocument) {
  954. return;
  955. }
  956. let namedDest, explicitDest;
  957. if (typeof dest === "string") {
  958. namedDest = dest;
  959. explicitDest = await this.pdfDocument.getDestination(dest);
  960. } else {
  961. namedDest = null;
  962. explicitDest = await dest;
  963. }
  964. if (!Array.isArray(explicitDest)) {
  965. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  966. return;
  967. }
  968. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  969. }
  970. goToPage(val) {
  971. if (!this.pdfDocument) {
  972. return;
  973. }
  974. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  975. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  976. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  977. return;
  978. }
  979. if (this.pdfHistory) {
  980. this.pdfHistory.pushCurrentPosition();
  981. this.pdfHistory.pushPage(pageNumber);
  982. }
  983. this.pdfViewer.scrollPageIntoView({
  984. pageNumber
  985. });
  986. }
  987. addLinkAttributes(link, url, newWindow = false) {
  988. addLinkAttributes(link, {
  989. url,
  990. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  991. rel: this.externalLinkRel,
  992. enabled: this.externalLinkEnabled
  993. });
  994. }
  995. getDestinationHash(dest) {
  996. if (typeof dest === "string") {
  997. if (dest.length > 0) {
  998. return this.getAnchorUrl("#" + escape(dest));
  999. }
  1000. } else if (Array.isArray(dest)) {
  1001. const str = JSON.stringify(dest);
  1002. if (str.length > 0) {
  1003. return this.getAnchorUrl("#" + escape(str));
  1004. }
  1005. }
  1006. return this.getAnchorUrl("");
  1007. }
  1008. getAnchorUrl(anchor) {
  1009. return (this.baseUrl || "") + anchor;
  1010. }
  1011. setHash(hash) {
  1012. if (!this.pdfDocument) {
  1013. return;
  1014. }
  1015. let pageNumber, dest;
  1016. if (hash.includes("=")) {
  1017. const params = (0, _ui_utils.parseQueryString)(hash);
  1018. if (params.has("search")) {
  1019. this.eventBus.dispatch("findfromurlhash", {
  1020. source: this,
  1021. query: params.get("search").replace(/"/g, ""),
  1022. phraseSearch: params.get("phrase") === "true"
  1023. });
  1024. }
  1025. if (params.has("page")) {
  1026. pageNumber = params.get("page") | 0 || 1;
  1027. }
  1028. if (params.has("zoom")) {
  1029. const zoomArgs = params.get("zoom").split(",");
  1030. const zoomArg = zoomArgs[0];
  1031. const zoomArgNumber = parseFloat(zoomArg);
  1032. if (!zoomArg.includes("Fit")) {
  1033. dest = [null, {
  1034. name: "XYZ"
  1035. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  1036. } else {
  1037. if (zoomArg === "Fit" || zoomArg === "FitB") {
  1038. dest = [null, {
  1039. name: zoomArg
  1040. }];
  1041. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  1042. dest = [null, {
  1043. name: zoomArg
  1044. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  1045. } else if (zoomArg === "FitR") {
  1046. if (zoomArgs.length !== 5) {
  1047. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  1048. } else {
  1049. dest = [null, {
  1050. name: zoomArg
  1051. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  1052. }
  1053. } else {
  1054. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  1055. }
  1056. }
  1057. }
  1058. if (dest) {
  1059. this.pdfViewer.scrollPageIntoView({
  1060. pageNumber: pageNumber || this.page,
  1061. destArray: dest,
  1062. allowNegativeOffset: true
  1063. });
  1064. } else if (pageNumber) {
  1065. this.page = pageNumber;
  1066. }
  1067. if (params.has("pagemode")) {
  1068. this.eventBus.dispatch("pagemode", {
  1069. source: this,
  1070. mode: params.get("pagemode")
  1071. });
  1072. }
  1073. if (params.has("nameddest")) {
  1074. this.goToDestination(params.get("nameddest"));
  1075. }
  1076. } else {
  1077. dest = unescape(hash);
  1078. try {
  1079. dest = JSON.parse(dest);
  1080. if (!Array.isArray(dest)) {
  1081. dest = dest.toString();
  1082. }
  1083. } catch (ex) {}
  1084. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  1085. this.goToDestination(dest);
  1086. return;
  1087. }
  1088. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  1089. }
  1090. }
  1091. executeNamedAction(action) {
  1092. switch (action) {
  1093. case "GoBack":
  1094. this.pdfHistory?.back();
  1095. break;
  1096. case "GoForward":
  1097. this.pdfHistory?.forward();
  1098. break;
  1099. case "NextPage":
  1100. this.pdfViewer.nextPage();
  1101. break;
  1102. case "PrevPage":
  1103. this.pdfViewer.previousPage();
  1104. break;
  1105. case "LastPage":
  1106. this.page = this.pagesCount;
  1107. break;
  1108. case "FirstPage":
  1109. this.page = 1;
  1110. break;
  1111. default:
  1112. break;
  1113. }
  1114. this.eventBus.dispatch("namedaction", {
  1115. source: this,
  1116. action
  1117. });
  1118. }
  1119. async executeSetOCGState(action) {
  1120. const pdfDocument = this.pdfDocument;
  1121. const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  1122. if (pdfDocument !== this.pdfDocument) {
  1123. return;
  1124. }
  1125. let operator;
  1126. for (const elem of action.state) {
  1127. switch (elem) {
  1128. case "ON":
  1129. case "OFF":
  1130. case "Toggle":
  1131. operator = elem;
  1132. continue;
  1133. }
  1134. switch (operator) {
  1135. case "ON":
  1136. optionalContentConfig.setVisibility(elem, true);
  1137. break;
  1138. case "OFF":
  1139. optionalContentConfig.setVisibility(elem, false);
  1140. break;
  1141. case "Toggle":
  1142. const group = optionalContentConfig.getGroup(elem);
  1143. if (group) {
  1144. optionalContentConfig.setVisibility(elem, !group.visible);
  1145. }
  1146. break;
  1147. }
  1148. }
  1149. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  1150. }
  1151. cachePageRef(pageNum, pageRef) {
  1152. if (!pageRef) {
  1153. return;
  1154. }
  1155. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1156. this.#pagesRefCache.set(refStr, pageNum);
  1157. }
  1158. _cachedPageNumber(pageRef) {
  1159. if (!pageRef) {
  1160. return null;
  1161. }
  1162. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1163. return this.#pagesRefCache.get(refStr) || null;
  1164. }
  1165. isPageVisible(pageNumber) {
  1166. return this.pdfViewer.isPageVisible(pageNumber);
  1167. }
  1168. isPageCached(pageNumber) {
  1169. return this.pdfViewer.isPageCached(pageNumber);
  1170. }
  1171. static #isValidExplicitDestination(dest) {
  1172. if (!Array.isArray(dest)) {
  1173. return false;
  1174. }
  1175. const destLength = dest.length;
  1176. if (destLength < 2) {
  1177. return false;
  1178. }
  1179. const page = dest[0];
  1180. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  1181. return false;
  1182. }
  1183. const zoom = dest[1];
  1184. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  1185. return false;
  1186. }
  1187. let allowNull = true;
  1188. switch (zoom.name) {
  1189. case "XYZ":
  1190. if (destLength !== 5) {
  1191. return false;
  1192. }
  1193. break;
  1194. case "Fit":
  1195. case "FitB":
  1196. return destLength === 2;
  1197. case "FitH":
  1198. case "FitBH":
  1199. case "FitV":
  1200. case "FitBV":
  1201. if (destLength !== 3) {
  1202. return false;
  1203. }
  1204. break;
  1205. case "FitR":
  1206. if (destLength !== 6) {
  1207. return false;
  1208. }
  1209. allowNull = false;
  1210. break;
  1211. default:
  1212. return false;
  1213. }
  1214. for (let i = 2; i < destLength; i++) {
  1215. const param = dest[i];
  1216. if (!(typeof param === "number" || allowNull && param === null)) {
  1217. return false;
  1218. }
  1219. }
  1220. return true;
  1221. }
  1222. }
  1223. exports.PDFLinkService = PDFLinkService;
  1224. class SimpleLinkService {
  1225. constructor() {
  1226. this.externalLinkEnabled = true;
  1227. }
  1228. get pagesCount() {
  1229. return 0;
  1230. }
  1231. get page() {
  1232. return 0;
  1233. }
  1234. set page(value) {}
  1235. get rotation() {
  1236. return 0;
  1237. }
  1238. set rotation(value) {}
  1239. get isInPresentationMode() {
  1240. return false;
  1241. }
  1242. async goToDestination(dest) {}
  1243. goToPage(val) {}
  1244. addLinkAttributes(link, url, newWindow = false) {
  1245. addLinkAttributes(link, {
  1246. url,
  1247. enabled: this.externalLinkEnabled
  1248. });
  1249. }
  1250. getDestinationHash(dest) {
  1251. return "#";
  1252. }
  1253. getAnchorUrl(hash) {
  1254. return "#";
  1255. }
  1256. setHash(hash) {}
  1257. executeNamedAction(action) {}
  1258. executeSetOCGState(action) {}
  1259. cachePageRef(pageNum, pageRef) {}
  1260. isPageVisible(pageNumber) {
  1261. return true;
  1262. }
  1263. isPageCached(pageNumber) {
  1264. return true;
  1265. }
  1266. }
  1267. exports.SimpleLinkService = SimpleLinkService;
  1268. /***/ }),
  1269. /* 4 */
  1270. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1271. Object.defineProperty(exports, "__esModule", ({
  1272. value: true
  1273. }));
  1274. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  1275. var _ui_utils = __webpack_require__(1);
  1276. var _pdfjsLib = __webpack_require__(5);
  1277. var _app_options = __webpack_require__(2);
  1278. var _event_utils = __webpack_require__(6);
  1279. var _pdf_cursor_tools = __webpack_require__(7);
  1280. var _pdf_link_service = __webpack_require__(3);
  1281. var _annotation_editor_params = __webpack_require__(9);
  1282. var _overlay_manager = __webpack_require__(10);
  1283. var _password_prompt = __webpack_require__(11);
  1284. var _pdf_attachment_viewer = __webpack_require__(12);
  1285. var _pdf_document_properties = __webpack_require__(14);
  1286. var _pdf_find_bar = __webpack_require__(15);
  1287. var _pdf_find_controller = __webpack_require__(16);
  1288. var _pdf_history = __webpack_require__(18);
  1289. var _pdf_layer_viewer = __webpack_require__(19);
  1290. var _pdf_outline_viewer = __webpack_require__(20);
  1291. var _pdf_presentation_mode = __webpack_require__(21);
  1292. var _pdf_rendering_queue = __webpack_require__(22);
  1293. var _pdf_scripting_manager = __webpack_require__(23);
  1294. var _pdf_sidebar = __webpack_require__(24);
  1295. var _pdf_sidebar_resizer = __webpack_require__(25);
  1296. var _pdf_thumbnail_viewer = __webpack_require__(26);
  1297. var _pdf_viewer = __webpack_require__(28);
  1298. var _secondary_toolbar = __webpack_require__(38);
  1299. var _toolbar = __webpack_require__(39);
  1300. var _view_history = __webpack_require__(40);
  1301. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  1302. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  1303. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  1304. const ViewOnLoad = {
  1305. UNKNOWN: -1,
  1306. PREVIOUS: 0,
  1307. INITIAL: 1
  1308. };
  1309. const ViewerCssTheme = {
  1310. AUTOMATIC: 0,
  1311. LIGHT: 1,
  1312. DARK: 2
  1313. };
  1314. const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
  1315. const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
  1316. class DefaultExternalServices {
  1317. constructor() {
  1318. throw new Error("Cannot initialize DefaultExternalServices.");
  1319. }
  1320. static updateFindControlState(data) {}
  1321. static updateFindMatchesCount(data) {}
  1322. static initPassiveLoading(callbacks) {}
  1323. static reportTelemetry(data) {}
  1324. static createDownloadManager(options) {
  1325. throw new Error("Not implemented: createDownloadManager");
  1326. }
  1327. static createPreferences() {
  1328. throw new Error("Not implemented: createPreferences");
  1329. }
  1330. static createL10n(options) {
  1331. throw new Error("Not implemented: createL10n");
  1332. }
  1333. static createScripting(options) {
  1334. throw new Error("Not implemented: createScripting");
  1335. }
  1336. static get supportsIntegratedFind() {
  1337. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  1338. }
  1339. static get supportsDocumentFonts() {
  1340. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  1341. }
  1342. static get supportedMouseWheelZoomModifierKeys() {
  1343. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  1344. ctrlKey: true,
  1345. metaKey: true
  1346. });
  1347. }
  1348. static get isInAutomation() {
  1349. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  1350. }
  1351. static updateEditorStates(data) {
  1352. throw new Error("Not implemented: updateEditorStates");
  1353. }
  1354. }
  1355. exports.DefaultExternalServices = DefaultExternalServices;
  1356. const PDFViewerApplication = {
  1357. initialBookmark: document.location.hash.substring(1),
  1358. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  1359. appConfig: null,
  1360. pdfDocument: null,
  1361. pdfLoadingTask: null,
  1362. printService: null,
  1363. pdfViewer: null,
  1364. pdfThumbnailViewer: null,
  1365. pdfRenderingQueue: null,
  1366. pdfPresentationMode: null,
  1367. pdfDocumentProperties: null,
  1368. pdfLinkService: null,
  1369. pdfHistory: null,
  1370. pdfSidebar: null,
  1371. pdfSidebarResizer: null,
  1372. pdfOutlineViewer: null,
  1373. pdfAttachmentViewer: null,
  1374. pdfLayerViewer: null,
  1375. pdfCursorTools: null,
  1376. pdfScriptingManager: null,
  1377. store: null,
  1378. downloadManager: null,
  1379. overlayManager: null,
  1380. preferences: null,
  1381. toolbar: null,
  1382. secondaryToolbar: null,
  1383. eventBus: null,
  1384. l10n: null,
  1385. annotationEditorParams: null,
  1386. isInitialViewSet: false,
  1387. downloadComplete: false,
  1388. isViewerEmbedded: window.parent !== window,
  1389. url: "",
  1390. baseUrl: "",
  1391. _downloadUrl: "",
  1392. externalServices: DefaultExternalServices,
  1393. _boundEvents: Object.create(null),
  1394. documentInfo: null,
  1395. metadata: null,
  1396. _contentDispositionFilename: null,
  1397. _contentLength: null,
  1398. _saveInProgress: false,
  1399. _docStats: null,
  1400. _wheelUnusedTicks: 0,
  1401. _PDFBug: null,
  1402. _hasAnnotationEditors: false,
  1403. _title: document.title,
  1404. _printAnnotationStoragePromise: null,
  1405. async initialize(appConfig) {
  1406. this.preferences = this.externalServices.createPreferences();
  1407. this.appConfig = appConfig;
  1408. await this._readPreferences();
  1409. await this._parseHashParameters();
  1410. this._forceCssTheme();
  1411. await this._initializeL10n();
  1412. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  1413. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  1414. }
  1415. await this._initializeViewerComponents();
  1416. this.bindEvents();
  1417. this.bindWindowEvents();
  1418. const appContainer = appConfig.appContainer || document.documentElement;
  1419. this.l10n.translate(appContainer).then(() => {
  1420. this.eventBus.dispatch("localized", {
  1421. source: this
  1422. });
  1423. });
  1424. this._initializedCapability.resolve();
  1425. },
  1426. async _readPreferences() {
  1427. if (_app_options.AppOptions.get("disablePreferences")) {
  1428. return;
  1429. }
  1430. if (_app_options.AppOptions._hasUserOptions()) {
  1431. console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  1432. }
  1433. try {
  1434. _app_options.AppOptions.setAll(await this.preferences.getAll());
  1435. } catch (reason) {
  1436. console.error(`_readPreferences: "${reason?.message}".`);
  1437. }
  1438. },
  1439. async _parseHashParameters() {
  1440. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  1441. return;
  1442. }
  1443. const hash = document.location.hash.substring(1);
  1444. if (!hash) {
  1445. return;
  1446. }
  1447. const {
  1448. mainContainer,
  1449. viewerContainer
  1450. } = this.appConfig,
  1451. params = (0, _ui_utils.parseQueryString)(hash);
  1452. if (params.get("disableworker") === "true") {
  1453. try {
  1454. await loadFakeWorker();
  1455. } catch (ex) {
  1456. console.error(`_parseHashParameters: "${ex.message}".`);
  1457. }
  1458. }
  1459. if (params.has("disablerange")) {
  1460. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  1461. }
  1462. if (params.has("disablestream")) {
  1463. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  1464. }
  1465. if (params.has("disableautofetch")) {
  1466. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  1467. }
  1468. if (params.has("disablefontface")) {
  1469. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  1470. }
  1471. if (params.has("disablehistory")) {
  1472. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  1473. }
  1474. if (params.has("verbosity")) {
  1475. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  1476. }
  1477. if (params.has("textlayer")) {
  1478. switch (params.get("textlayer")) {
  1479. case "off":
  1480. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  1481. break;
  1482. case "visible":
  1483. case "shadow":
  1484. case "hover":
  1485. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  1486. try {
  1487. await loadPDFBug(this);
  1488. this._PDFBug.loadCSS();
  1489. } catch (ex) {
  1490. console.error(`_parseHashParameters: "${ex.message}".`);
  1491. }
  1492. break;
  1493. }
  1494. }
  1495. if (params.has("pdfbug")) {
  1496. _app_options.AppOptions.set("pdfBug", true);
  1497. _app_options.AppOptions.set("fontExtraProperties", true);
  1498. const enabled = params.get("pdfbug").split(",");
  1499. try {
  1500. await loadPDFBug(this);
  1501. this._PDFBug.init({
  1502. OPS: _pdfjsLib.OPS
  1503. }, mainContainer, enabled);
  1504. } catch (ex) {
  1505. console.error(`_parseHashParameters: "${ex.message}".`);
  1506. }
  1507. }
  1508. if (params.has("locale")) {
  1509. _app_options.AppOptions.set("locale", params.get("locale"));
  1510. }
  1511. },
  1512. async _initializeL10n() {
  1513. this.l10n = this.externalServices.createL10n({
  1514. locale: _app_options.AppOptions.get("locale")
  1515. });
  1516. const dir = await this.l10n.getDirection();
  1517. document.getElementsByTagName("html")[0].dir = dir;
  1518. },
  1519. _forceCssTheme() {
  1520. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  1521. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  1522. return;
  1523. }
  1524. try {
  1525. const styleSheet = document.styleSheets[0];
  1526. const cssRules = styleSheet?.cssRules || [];
  1527. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  1528. const rule = cssRules[i];
  1529. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  1530. if (cssTheme === ViewerCssTheme.LIGHT) {
  1531. styleSheet.deleteRule(i);
  1532. return;
  1533. }
  1534. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  1535. if (darkRules?.[1]) {
  1536. styleSheet.deleteRule(i);
  1537. styleSheet.insertRule(darkRules[1], i);
  1538. }
  1539. return;
  1540. }
  1541. }
  1542. } catch (reason) {
  1543. console.error(`_forceCssTheme: "${reason?.message}".`);
  1544. }
  1545. },
  1546. async _initializeViewerComponents() {
  1547. const {
  1548. appConfig,
  1549. externalServices
  1550. } = this;
  1551. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  1552. this.eventBus = eventBus;
  1553. this.overlayManager = new _overlay_manager.OverlayManager();
  1554. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  1555. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  1556. this.pdfRenderingQueue = pdfRenderingQueue;
  1557. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  1558. eventBus,
  1559. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  1560. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  1561. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  1562. });
  1563. this.pdfLinkService = pdfLinkService;
  1564. const downloadManager = externalServices.createDownloadManager();
  1565. this.downloadManager = downloadManager;
  1566. const findController = new _pdf_find_controller.PDFFindController({
  1567. linkService: pdfLinkService,
  1568. eventBus
  1569. });
  1570. this.findController = findController;
  1571. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  1572. eventBus,
  1573. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  1574. scriptingFactory: externalServices,
  1575. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  1576. });
  1577. this.pdfScriptingManager = pdfScriptingManager;
  1578. const container = appConfig.mainContainer,
  1579. viewer = appConfig.viewerContainer;
  1580. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  1581. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  1582. background: _app_options.AppOptions.get("pageColorsBackground"),
  1583. foreground: _app_options.AppOptions.get("pageColorsForeground")
  1584. } : null;
  1585. this.pdfViewer = new _pdf_viewer.PDFViewer({
  1586. container,
  1587. viewer,
  1588. eventBus,
  1589. renderingQueue: pdfRenderingQueue,
  1590. linkService: pdfLinkService,
  1591. downloadManager,
  1592. findController,
  1593. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  1594. renderer: _app_options.AppOptions.get("renderer"),
  1595. l10n: this.l10n,
  1596. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  1597. annotationMode: _app_options.AppOptions.get("annotationMode"),
  1598. annotationEditorMode,
  1599. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  1600. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  1601. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  1602. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  1603. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  1604. pageColors
  1605. });
  1606. pdfRenderingQueue.setViewer(this.pdfViewer);
  1607. pdfLinkService.setViewer(this.pdfViewer);
  1608. pdfScriptingManager.setViewer(this.pdfViewer);
  1609. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  1610. container: appConfig.sidebar.thumbnailView,
  1611. eventBus,
  1612. renderingQueue: pdfRenderingQueue,
  1613. linkService: pdfLinkService,
  1614. l10n: this.l10n,
  1615. pageColors
  1616. });
  1617. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  1618. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  1619. this.pdfHistory = new _pdf_history.PDFHistory({
  1620. linkService: pdfLinkService,
  1621. eventBus
  1622. });
  1623. pdfLinkService.setHistory(this.pdfHistory);
  1624. }
  1625. if (!this.supportsIntegratedFind) {
  1626. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  1627. }
  1628. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  1629. this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  1630. } else {
  1631. for (const element of [document.getElementById("editorModeButtons"), document.getElementById("editorModeSeparator")]) {
  1632. element.hidden = true;
  1633. }
  1634. }
  1635. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
  1636. return this._docFilename;
  1637. });
  1638. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  1639. container,
  1640. eventBus,
  1641. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  1642. });
  1643. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  1644. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, this.externalServices);
  1645. if (this.supportsFullscreen) {
  1646. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  1647. container,
  1648. pdfViewer: this.pdfViewer,
  1649. eventBus
  1650. });
  1651. }
  1652. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  1653. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  1654. container: appConfig.sidebar.outlineView,
  1655. eventBus,
  1656. linkService: pdfLinkService,
  1657. downloadManager
  1658. });
  1659. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  1660. container: appConfig.sidebar.attachmentsView,
  1661. eventBus,
  1662. downloadManager
  1663. });
  1664. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  1665. container: appConfig.sidebar.layersView,
  1666. eventBus,
  1667. l10n: this.l10n
  1668. });
  1669. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  1670. elements: appConfig.sidebar,
  1671. pdfViewer: this.pdfViewer,
  1672. pdfThumbnailViewer: this.pdfThumbnailViewer,
  1673. eventBus,
  1674. l10n: this.l10n
  1675. });
  1676. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  1677. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  1678. },
  1679. run(config) {
  1680. this.initialize(config).then(webViewerInitialized);
  1681. },
  1682. get initialized() {
  1683. return this._initializedCapability.settled;
  1684. },
  1685. get initializedPromise() {
  1686. return this._initializedCapability.promise;
  1687. },
  1688. zoomIn(steps) {
  1689. if (this.pdfViewer.isInPresentationMode) {
  1690. return;
  1691. }
  1692. this.pdfViewer.increaseScale(steps);
  1693. },
  1694. zoomOut(steps) {
  1695. if (this.pdfViewer.isInPresentationMode) {
  1696. return;
  1697. }
  1698. this.pdfViewer.decreaseScale(steps);
  1699. },
  1700. zoomReset() {
  1701. if (this.pdfViewer.isInPresentationMode) {
  1702. return;
  1703. }
  1704. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1705. },
  1706. get pagesCount() {
  1707. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  1708. },
  1709. get page() {
  1710. return this.pdfViewer.currentPageNumber;
  1711. },
  1712. set page(val) {
  1713. this.pdfViewer.currentPageNumber = val;
  1714. },
  1715. get supportsPrinting() {
  1716. return PDFPrintServiceFactory.instance.supportsPrinting;
  1717. },
  1718. get supportsFullscreen() {
  1719. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  1720. },
  1721. get supportsIntegratedFind() {
  1722. return this.externalServices.supportsIntegratedFind;
  1723. },
  1724. get supportsDocumentFonts() {
  1725. return this.externalServices.supportsDocumentFonts;
  1726. },
  1727. get loadingBar() {
  1728. const bar = new _ui_utils.ProgressBar("loadingBar");
  1729. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  1730. },
  1731. get supportedMouseWheelZoomModifierKeys() {
  1732. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  1733. },
  1734. initPassiveLoading() {
  1735. throw new Error("Not implemented: initPassiveLoading");
  1736. },
  1737. setTitleUsingUrl(url = "", downloadUrl = null) {
  1738. this.url = url;
  1739. this.baseUrl = url.split("#")[0];
  1740. if (downloadUrl) {
  1741. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  1742. }
  1743. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  1744. if (!title) {
  1745. try {
  1746. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  1747. } catch (ex) {
  1748. title = url;
  1749. }
  1750. }
  1751. this.setTitle(title);
  1752. },
  1753. setTitle(title = this._title) {
  1754. this._title = title;
  1755. if (this.isViewerEmbedded) {
  1756. return;
  1757. }
  1758. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  1759. document.title = `${editorIndicator ? "* " : ""}${title}`;
  1760. },
  1761. get _docFilename() {
  1762. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  1763. },
  1764. _hideViewBookmark() {
  1765. this.appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
  1766. },
  1767. async close() {
  1768. this._unblockDocumentLoadEvent();
  1769. this._hideViewBookmark();
  1770. if (!this.pdfLoadingTask) {
  1771. return;
  1772. }
  1773. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  1774. try {
  1775. await this.save();
  1776. } catch (reason) {}
  1777. }
  1778. const promises = [];
  1779. promises.push(this.pdfLoadingTask.destroy());
  1780. this.pdfLoadingTask = null;
  1781. if (this.pdfDocument) {
  1782. this.pdfDocument = null;
  1783. this.pdfThumbnailViewer.setDocument(null);
  1784. this.pdfViewer.setDocument(null);
  1785. this.pdfLinkService.setDocument(null);
  1786. this.pdfDocumentProperties.setDocument(null);
  1787. }
  1788. this.pdfLinkService.externalLinkEnabled = true;
  1789. this.store = null;
  1790. this.isInitialViewSet = false;
  1791. this.downloadComplete = false;
  1792. this.url = "";
  1793. this.baseUrl = "";
  1794. this._downloadUrl = "";
  1795. this.documentInfo = null;
  1796. this.metadata = null;
  1797. this._contentDispositionFilename = null;
  1798. this._contentLength = null;
  1799. this._saveInProgress = false;
  1800. this._docStats = null;
  1801. this._hasAnnotationEditors = false;
  1802. promises.push(this.pdfScriptingManager.destroyPromise);
  1803. this.setTitle();
  1804. this.pdfSidebar.reset();
  1805. this.pdfOutlineViewer.reset();
  1806. this.pdfAttachmentViewer.reset();
  1807. this.pdfLayerViewer.reset();
  1808. this.pdfHistory?.reset();
  1809. this.findBar?.reset();
  1810. this.toolbar.reset();
  1811. this.secondaryToolbar.reset();
  1812. this._PDFBug?.cleanup();
  1813. await Promise.all(promises);
  1814. },
  1815. async open(file, args) {
  1816. if (this.pdfLoadingTask) {
  1817. await this.close();
  1818. }
  1819. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  1820. for (const key in workerParameters) {
  1821. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  1822. }
  1823. const parameters = Object.create(null);
  1824. if (typeof file === "string") {
  1825. if (pdfIsEncrypt === 1) {
  1826. const go = new Go();
  1827. const wasmResult = await WebAssembly.instantiateStreaming(
  1828. // fetch("/wasm/libgetpdf.wasm"),
  1829. // fetch("https://gaoyixia.oss-cn-hangzhou.aliyuncs.com/wenjian/libgetpdf.wasm"),
  1830. fetch("https://gaoyixia.oss-cn-hangzhou.aliyuncs.com/libgetpdf.wasm"),
  1831. go.importObject
  1832. )
  1833. go.run(wasmResult.instance);
  1834. console.log(GetVersion());
  1835. parameters.data = await ReadPdf(file);
  1836. } else {
  1837. this.setTitleUsingUrl(file, file);
  1838. parameters.url = file;
  1839. }
  1840. } else if (file && "byteLength" in file) {
  1841. parameters.data = file;
  1842. } else if (file.url && file.originalUrl) {
  1843. this.setTitleUsingUrl(file.originalUrl, file.url);
  1844. parameters.url = file.url;
  1845. }
  1846. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  1847. for (const key in apiParameters) {
  1848. let value = apiParameters[key];
  1849. if (key === "docBaseUrl" && !value) {}
  1850. parameters[key] = value;
  1851. }
  1852. if (args) {
  1853. for (const key in args) {
  1854. parameters[key] = args[key];
  1855. }
  1856. }
  1857. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  1858. this.pdfLoadingTask = loadingTask;
  1859. loadingTask.onPassword = (updateCallback, reason) => {
  1860. if (this.isViewerEmbedded) {
  1861. this._unblockDocumentLoadEvent();
  1862. }
  1863. this.pdfLinkService.externalLinkEnabled = false;
  1864. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  1865. this.passwordPrompt.open();
  1866. };
  1867. loadingTask.onProgress = ({
  1868. loaded,
  1869. total
  1870. }) => {
  1871. this.progress(loaded / total);
  1872. };
  1873. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  1874. return loadingTask.promise.then(pdfDocument => {
  1875. this.load(pdfDocument);
  1876. }, reason => {
  1877. if (loadingTask !== this.pdfLoadingTask) {
  1878. return undefined;
  1879. }
  1880. let key = "loading_error";
  1881. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  1882. key = "invalid_file_error";
  1883. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  1884. key = "missing_file_error";
  1885. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  1886. key = "unexpected_response_error";
  1887. }
  1888. return this.l10n.get(key).then(msg => {
  1889. this._documentError(msg, {
  1890. message: reason?.message
  1891. });
  1892. throw reason;
  1893. });
  1894. });
  1895. },
  1896. _ensureDownloadComplete() {
  1897. if (this.pdfDocument && this.downloadComplete) {
  1898. return;
  1899. }
  1900. throw new Error("PDF document not downloaded.");
  1901. },
  1902. async download() {
  1903. const url = this._downloadUrl,
  1904. filename = this._docFilename;
  1905. try {
  1906. this._ensureDownloadComplete();
  1907. const data = await this.pdfDocument.getData();
  1908. const blob = new Blob([data], {
  1909. type: "application/pdf"
  1910. });
  1911. await this.downloadManager.download(blob, url, filename);
  1912. } catch (reason) {
  1913. await this.downloadManager.downloadUrl(url, filename);
  1914. }
  1915. },
  1916. async save() {
  1917. if (this._saveInProgress) {
  1918. return;
  1919. }
  1920. this._saveInProgress = true;
  1921. await this.pdfScriptingManager.dispatchWillSave();
  1922. const url = this._downloadUrl,
  1923. filename = this._docFilename;
  1924. try {
  1925. this._ensureDownloadComplete();
  1926. const data = await this.pdfDocument.saveDocument();
  1927. const blob = new Blob([data], {
  1928. type: "application/pdf"
  1929. });
  1930. await this.downloadManager.download(blob, url, filename);
  1931. } catch (reason) {
  1932. console.error(`Error when saving the document: ${reason.message}`);
  1933. await this.download();
  1934. } finally {
  1935. await this.pdfScriptingManager.dispatchDidSave();
  1936. this._saveInProgress = false;
  1937. }
  1938. if (this._hasAnnotationEditors) {
  1939. this.externalServices.reportTelemetry({
  1940. type: "editing",
  1941. data: {
  1942. type: "save"
  1943. }
  1944. });
  1945. }
  1946. },
  1947. downloadOrSave() {
  1948. if (this.pdfDocument?.annotationStorage.size > 0) {
  1949. this.save();
  1950. } else {
  1951. this.download();
  1952. }
  1953. },
  1954. fallback(featureId) {
  1955. this.externalServices.reportTelemetry({
  1956. type: "unsupportedFeature",
  1957. featureId
  1958. });
  1959. },
  1960. _documentError(message, moreInfo = null) {
  1961. this._unblockDocumentLoadEvent();
  1962. this._otherError(message, moreInfo);
  1963. this.eventBus.dispatch("documenterror", {
  1964. source: this,
  1965. message,
  1966. reason: moreInfo?.message ?? null
  1967. });
  1968. },
  1969. _otherError(message, moreInfo = null) {
  1970. const moreInfoText = [`PDF.js v${_pdfjsLib.version || "?"} (build: ${_pdfjsLib.build || "?"})`];
  1971. if (moreInfo) {
  1972. moreInfoText.push(`Message: ${moreInfo.message}`);
  1973. if (moreInfo.stack) {
  1974. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  1975. } else {
  1976. if (moreInfo.filename) {
  1977. moreInfoText.push(`File: ${moreInfo.filename}`);
  1978. }
  1979. if (moreInfo.lineNumber) {
  1980. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  1981. }
  1982. }
  1983. }
  1984. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  1985. this.fallback();
  1986. },
  1987. progress(level) {
  1988. if (this.downloadComplete) {
  1989. return;
  1990. }
  1991. const percent = Math.round(level * 100);
  1992. if (percent <= this.loadingBar.percent) {
  1993. return;
  1994. }
  1995. this.loadingBar.percent = percent;
  1996. const disableAutoFetch = this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch");
  1997. if (!disableAutoFetch || isNaN(percent)) {
  1998. return;
  1999. }
  2000. if (this.disableAutoFetchLoadingBarTimeout) {
  2001. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  2002. this.disableAutoFetchLoadingBarTimeout = null;
  2003. }
  2004. this.loadingBar.show();
  2005. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  2006. this.loadingBar.hide();
  2007. this.disableAutoFetchLoadingBarTimeout = null;
  2008. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  2009. },
  2010. load(pdfDocument) {
  2011. this.pdfDocument = pdfDocument;
  2012. pdfDocument.getDownloadInfo().then(({
  2013. length
  2014. }) => {
  2015. this._contentLength = length;
  2016. this.downloadComplete = true;
  2017. this.loadingBar.hide();
  2018. firstPagePromise.then(() => {
  2019. this.eventBus.dispatch("documentloaded", {
  2020. source: this
  2021. });
  2022. });
  2023. });
  2024. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  2025. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  2026. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  2027. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  2028. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  2029. let baseDocumentUrl;
  2030. baseDocumentUrl = null;
  2031. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  2032. this.pdfDocumentProperties.setDocument(pdfDocument);
  2033. const pdfViewer = this.pdfViewer;
  2034. pdfViewer.setDocument(pdfDocument);
  2035. const {
  2036. firstPagePromise,
  2037. onePageRendered,
  2038. pagesPromise
  2039. } = pdfViewer;
  2040. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  2041. pdfThumbnailViewer.setDocument(pdfDocument);
  2042. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  2043. page: null,
  2044. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  2045. scrollLeft: "0",
  2046. scrollTop: "0",
  2047. rotation: null,
  2048. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  2049. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  2050. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  2051. }).catch(() => {
  2052. return Object.create(null);
  2053. });
  2054. firstPagePromise.then(pdfPage => {
  2055. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  2056. this._initializeAnnotationStorageCallbacks(pdfDocument);
  2057. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  2058. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  2059. this._initializePdfHistory({
  2060. fingerprint: pdfDocument.fingerprints[0],
  2061. viewOnLoad,
  2062. initialDest: openAction?.dest
  2063. });
  2064. const initialBookmark = this.initialBookmark;
  2065. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  2066. let hash = zoom ? `zoom=${zoom}` : null;
  2067. let rotation = null;
  2068. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  2069. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  2070. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  2071. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  2072. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  2073. rotation = parseInt(stored.rotation, 10);
  2074. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2075. sidebarView = stored.sidebarView | 0;
  2076. }
  2077. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  2078. scrollMode = stored.scrollMode | 0;
  2079. }
  2080. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2081. spreadMode = stored.spreadMode | 0;
  2082. }
  2083. }
  2084. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2085. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  2086. }
  2087. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2088. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  2089. spreadMode = modes.spreadMode;
  2090. }
  2091. this.setInitialView(hash, {
  2092. rotation,
  2093. sidebarView,
  2094. scrollMode,
  2095. spreadMode
  2096. });
  2097. this.eventBus.dispatch("documentinit", {
  2098. source: this
  2099. });
  2100. if (!this.isViewerEmbedded) {
  2101. pdfViewer.focus();
  2102. }
  2103. await Promise.race([pagesPromise, new Promise(resolve => {
  2104. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  2105. })]);
  2106. if (!initialBookmark && !hash) {
  2107. return;
  2108. }
  2109. if (pdfViewer.hasEqualPageSizes) {
  2110. return;
  2111. }
  2112. this.initialBookmark = initialBookmark;
  2113. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  2114. this.setInitialView(hash);
  2115. }).catch(() => {
  2116. this.setInitialView();
  2117. }).then(function () {
  2118. pdfViewer.update();
  2119. });
  2120. });
  2121. pagesPromise.then(() => {
  2122. this._unblockDocumentLoadEvent();
  2123. this._initializeAutoPrint(pdfDocument, openActionPromise);
  2124. }, reason => {
  2125. this.l10n.get("loading_error").then(msg => {
  2126. this._documentError(msg, {
  2127. message: reason?.message
  2128. });
  2129. });
  2130. });
  2131. onePageRendered.then(data => {
  2132. this.externalServices.reportTelemetry({
  2133. type: "pageInfo",
  2134. timestamp: data.timestamp
  2135. });
  2136. pdfDocument.getOutline().then(outline => {
  2137. if (pdfDocument !== this.pdfDocument) {
  2138. return;
  2139. }
  2140. this.pdfOutlineViewer.render({
  2141. outline,
  2142. pdfDocument
  2143. });
  2144. });
  2145. pdfDocument.getAttachments().then(attachments => {
  2146. if (pdfDocument !== this.pdfDocument) {
  2147. return;
  2148. }
  2149. this.pdfAttachmentViewer.render({
  2150. attachments
  2151. });
  2152. });
  2153. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  2154. if (pdfDocument !== this.pdfDocument) {
  2155. return;
  2156. }
  2157. this.pdfLayerViewer.render({
  2158. optionalContentConfig,
  2159. pdfDocument
  2160. });
  2161. });
  2162. });
  2163. this._initializePageLabels(pdfDocument);
  2164. this._initializeMetadata(pdfDocument);
  2165. },
  2166. async _scriptingDocProperties(pdfDocument) {
  2167. if (!this.documentInfo) {
  2168. await new Promise(resolve => {
  2169. this.eventBus._on("metadataloaded", resolve, {
  2170. once: true
  2171. });
  2172. });
  2173. if (pdfDocument !== this.pdfDocument) {
  2174. return null;
  2175. }
  2176. }
  2177. if (!this._contentLength) {
  2178. await new Promise(resolve => {
  2179. this.eventBus._on("documentloaded", resolve, {
  2180. once: true
  2181. });
  2182. });
  2183. if (pdfDocument !== this.pdfDocument) {
  2184. return null;
  2185. }
  2186. }
  2187. return {
  2188. ...this.documentInfo,
  2189. baseURL: this.baseUrl,
  2190. filesize: this._contentLength,
  2191. filename: this._docFilename,
  2192. metadata: this.metadata?.getRaw(),
  2193. authors: this.metadata?.get("dc:creator"),
  2194. numPages: this.pagesCount,
  2195. URL: this.url
  2196. };
  2197. },
  2198. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  2199. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  2200. if (pdfDocument !== this.pdfDocument) {
  2201. return;
  2202. }
  2203. let triggerAutoPrint = false;
  2204. if (openAction?.action === "Print") {
  2205. triggerAutoPrint = true;
  2206. }
  2207. if (javaScript) {
  2208. javaScript.some(js => {
  2209. if (!js) {
  2210. return false;
  2211. }
  2212. console.warn("Warning: JavaScript support is not enabled");
  2213. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  2214. return true;
  2215. });
  2216. if (!triggerAutoPrint) {
  2217. for (const js of javaScript) {
  2218. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  2219. triggerAutoPrint = true;
  2220. break;
  2221. }
  2222. }
  2223. }
  2224. }
  2225. if (triggerAutoPrint) {
  2226. this.triggerPrinting();
  2227. }
  2228. },
  2229. async _initializeMetadata(pdfDocument) {
  2230. const {
  2231. info,
  2232. metadata,
  2233. contentDispositionFilename,
  2234. contentLength
  2235. } = await pdfDocument.getMetadata();
  2236. if (pdfDocument !== this.pdfDocument) {
  2237. return;
  2238. }
  2239. this.documentInfo = info;
  2240. this.metadata = metadata;
  2241. this._contentDispositionFilename ??= contentDispositionFilename;
  2242. this._contentLength ??= contentLength;
  2243. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`);
  2244. let pdfTitle = info.Title;
  2245. const metadataTitle = metadata?.get("dc:title");
  2246. if (metadataTitle) {
  2247. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  2248. pdfTitle = metadataTitle;
  2249. }
  2250. }
  2251. if (pdfTitle) {
  2252. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  2253. } else if (this._contentDispositionFilename) {
  2254. this.setTitle(this._contentDispositionFilename);
  2255. }
  2256. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  2257. if (pdfDocument.loadingParams.enableXfa) {
  2258. console.warn("Warning: XFA Foreground documents are not supported");
  2259. } else {
  2260. console.warn("Warning: XFA support is not enabled");
  2261. }
  2262. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  2263. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  2264. console.warn("Warning: Interactive form support is not enabled");
  2265. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  2266. }
  2267. if (info.IsSignaturesPresent) {
  2268. console.warn("Warning: Digital signatures validation is not supported");
  2269. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  2270. }
  2271. let versionId = "other";
  2272. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  2273. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  2274. }
  2275. let generatorId = "other";
  2276. if (info.Producer) {
  2277. const producer = info.Producer.toLowerCase();
  2278. KNOWN_GENERATORS.some(function (generator) {
  2279. if (!producer.includes(generator)) {
  2280. return false;
  2281. }
  2282. generatorId = generator.replace(/[ .-]/g, "_");
  2283. return true;
  2284. });
  2285. }
  2286. let formType = null;
  2287. if (info.IsXFAPresent) {
  2288. formType = "xfa";
  2289. } else if (info.IsAcroFormPresent) {
  2290. formType = "acroform";
  2291. }
  2292. this.externalServices.reportTelemetry({
  2293. type: "documentInfo",
  2294. version: versionId,
  2295. generator: generatorId,
  2296. formType
  2297. });
  2298. this.eventBus.dispatch("metadataloaded", {
  2299. source: this
  2300. });
  2301. },
  2302. async _initializePageLabels(pdfDocument) {
  2303. const labels = await pdfDocument.getPageLabels();
  2304. if (pdfDocument !== this.pdfDocument) {
  2305. return;
  2306. }
  2307. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  2308. return;
  2309. }
  2310. const numLabels = labels.length;
  2311. let standardLabels = 0,
  2312. emptyLabels = 0;
  2313. for (let i = 0; i < numLabels; i++) {
  2314. const label = labels[i];
  2315. if (label === (i + 1).toString()) {
  2316. standardLabels++;
  2317. } else if (label === "") {
  2318. emptyLabels++;
  2319. } else {
  2320. break;
  2321. }
  2322. }
  2323. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  2324. return;
  2325. }
  2326. const {
  2327. pdfViewer,
  2328. pdfThumbnailViewer,
  2329. toolbar
  2330. } = this;
  2331. pdfViewer.setPageLabels(labels);
  2332. pdfThumbnailViewer.setPageLabels(labels);
  2333. toolbar.setPagesCount(numLabels, true);
  2334. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2335. },
  2336. _initializePdfHistory({
  2337. fingerprint,
  2338. viewOnLoad,
  2339. initialDest = null
  2340. }) {
  2341. if (!this.pdfHistory) {
  2342. return;
  2343. }
  2344. this.pdfHistory.initialize({
  2345. fingerprint,
  2346. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  2347. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  2348. });
  2349. if (this.pdfHistory.initialBookmark) {
  2350. this.initialBookmark = this.pdfHistory.initialBookmark;
  2351. this.initialRotation = this.pdfHistory.initialRotation;
  2352. }
  2353. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  2354. this.initialBookmark = JSON.stringify(initialDest);
  2355. this.pdfHistory.push({
  2356. explicitDest: initialDest,
  2357. pageNumber: null
  2358. });
  2359. }
  2360. },
  2361. _initializeAnnotationStorageCallbacks(pdfDocument) {
  2362. if (pdfDocument !== this.pdfDocument) {
  2363. return;
  2364. }
  2365. const {
  2366. annotationStorage
  2367. } = pdfDocument;
  2368. annotationStorage.onSetModified = () => {
  2369. window.addEventListener("beforeunload", beforeUnload);
  2370. this._annotationStorageModified = true;
  2371. };
  2372. annotationStorage.onResetModified = () => {
  2373. window.removeEventListener("beforeunload", beforeUnload);
  2374. delete this._annotationStorageModified;
  2375. };
  2376. annotationStorage.onAnnotationEditor = typeStr => {
  2377. this._hasAnnotationEditors = !!typeStr;
  2378. this.setTitle();
  2379. if (typeStr) {
  2380. this.externalServices.reportTelemetry({
  2381. type: "editing",
  2382. data: {
  2383. type: typeStr
  2384. }
  2385. });
  2386. }
  2387. };
  2388. },
  2389. setInitialView(storedHash, {
  2390. rotation,
  2391. sidebarView,
  2392. scrollMode,
  2393. spreadMode
  2394. } = {}) {
  2395. const setRotation = angle => {
  2396. if ((0, _ui_utils.isValidRotation)(angle)) {
  2397. this.pdfViewer.pagesRotation = angle;
  2398. }
  2399. };
  2400. const setViewerModes = (scroll, spread) => {
  2401. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  2402. this.pdfViewer.scrollMode = scroll;
  2403. }
  2404. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  2405. this.pdfViewer.spreadMode = spread;
  2406. }
  2407. };
  2408. this.isInitialViewSet = true;
  2409. this.pdfSidebar.setInitialView(sidebarView);
  2410. setViewerModes(scrollMode, spreadMode);
  2411. if (this.initialBookmark) {
  2412. setRotation(this.initialRotation);
  2413. delete this.initialRotation;
  2414. this.pdfLinkService.setHash(this.initialBookmark);
  2415. this.initialBookmark = null;
  2416. } else if (storedHash) {
  2417. setRotation(rotation);
  2418. this.pdfLinkService.setHash(storedHash);
  2419. }
  2420. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  2421. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  2422. if (!this.pdfViewer.currentScaleValue) {
  2423. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2424. }
  2425. },
  2426. _cleanup() {
  2427. if (!this.pdfDocument) {
  2428. return;
  2429. }
  2430. this.pdfViewer.cleanup();
  2431. this.pdfThumbnailViewer.cleanup();
  2432. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  2433. },
  2434. forceRendering() {
  2435. this.pdfRenderingQueue.printing = !!this.printService;
  2436. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS;
  2437. this.pdfRenderingQueue.renderHighestPriority();
  2438. },
  2439. beforePrint() {
  2440. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => {
  2441. return this.pdfDocument?.annotationStorage.print;
  2442. });
  2443. if (this.printService) {
  2444. return;
  2445. }
  2446. if (!this.supportsPrinting) {
  2447. this.l10n.get("printing_not_supported").then(msg => {
  2448. this._otherError(msg);
  2449. });
  2450. return;
  2451. }
  2452. if (!this.pdfViewer.pageViewsReady) {
  2453. this.l10n.get("printing_not_ready").then(msg => {
  2454. window.alert(msg);
  2455. });
  2456. return;
  2457. }
  2458. const pagesOverview = this.pdfViewer.getPagesOverview();
  2459. const printContainer = this.appConfig.printContainer;
  2460. const printResolution = _app_options.AppOptions.get("printResolution");
  2461. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  2462. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  2463. this.printService = printService;
  2464. this.forceRendering();
  2465. this.setTitle();
  2466. printService.layout();
  2467. this.externalServices.reportTelemetry({
  2468. type: "print"
  2469. });
  2470. if (this._hasAnnotationEditors) {
  2471. this.externalServices.reportTelemetry({
  2472. type: "editing",
  2473. data: {
  2474. type: "print"
  2475. }
  2476. });
  2477. }
  2478. },
  2479. afterPrint() {
  2480. if (this._printAnnotationStoragePromise) {
  2481. this._printAnnotationStoragePromise.then(() => {
  2482. this.pdfScriptingManager.dispatchDidPrint();
  2483. });
  2484. this._printAnnotationStoragePromise = null;
  2485. }
  2486. if (this.printService) {
  2487. this.printService.destroy();
  2488. this.printService = null;
  2489. this.pdfDocument?.annotationStorage.resetModified();
  2490. }
  2491. this.forceRendering();
  2492. this.setTitle();
  2493. },
  2494. rotatePages(delta) {
  2495. this.pdfViewer.pagesRotation += delta;
  2496. },
  2497. requestPresentationMode() {
  2498. this.pdfPresentationMode?.request();
  2499. },
  2500. triggerPrinting() {
  2501. if (!this.supportsPrinting) {
  2502. return;
  2503. }
  2504. window.print();
  2505. },
  2506. bindEvents() {
  2507. const {
  2508. eventBus,
  2509. _boundEvents
  2510. } = this;
  2511. _boundEvents.beforePrint = this.beforePrint.bind(this);
  2512. _boundEvents.afterPrint = this.afterPrint.bind(this);
  2513. eventBus._on("resize", webViewerResize);
  2514. eventBus._on("hashchange", webViewerHashchange);
  2515. eventBus._on("beforeprint", _boundEvents.beforePrint);
  2516. eventBus._on("afterprint", _boundEvents.afterPrint);
  2517. eventBus._on("pagerendered", webViewerPageRendered);
  2518. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  2519. eventBus._on("pagechanging", webViewerPageChanging);
  2520. eventBus._on("scalechanging", webViewerScaleChanging);
  2521. eventBus._on("rotationchanging", webViewerRotationChanging);
  2522. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  2523. eventBus._on("pagemode", webViewerPageMode);
  2524. eventBus._on("namedaction", webViewerNamedAction);
  2525. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  2526. eventBus._on("presentationmode", webViewerPresentationMode);
  2527. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  2528. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  2529. eventBus._on("print", webViewerPrint);
  2530. eventBus._on("download", webViewerDownload);
  2531. eventBus._on("firstpage", webViewerFirstPage);
  2532. eventBus._on("lastpage", webViewerLastPage);
  2533. eventBus._on("nextpage", webViewerNextPage);
  2534. eventBus._on("previouspage", webViewerPreviousPage);
  2535. eventBus._on("zoomin", webViewerZoomIn);
  2536. eventBus._on("zoomout", webViewerZoomOut);
  2537. eventBus._on("zoomreset", webViewerZoomReset);
  2538. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  2539. eventBus._on("scalechanged", webViewerScaleChanged);
  2540. eventBus._on("rotatecw", webViewerRotateCw);
  2541. eventBus._on("rotateccw", webViewerRotateCcw);
  2542. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  2543. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  2544. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  2545. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  2546. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  2547. eventBus._on("documentproperties", webViewerDocumentProperties);
  2548. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  2549. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2550. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  2551. if (_app_options.AppOptions.get("pdfBug")) {
  2552. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  2553. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2554. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2555. }
  2556. eventBus._on("fileinputchange", webViewerFileInputChange);
  2557. eventBus._on("openfile", webViewerOpenFile);
  2558. },
  2559. bindWindowEvents() {
  2560. const {
  2561. eventBus,
  2562. _boundEvents
  2563. } = this;
  2564. function addWindowResolutionChange(evt = null) {
  2565. if (evt) {
  2566. webViewerResolutionChange(evt);
  2567. }
  2568. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  2569. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  2570. once: true
  2571. });
  2572. _boundEvents.removeWindowResolutionChange ||= function () {
  2573. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  2574. _boundEvents.removeWindowResolutionChange = null;
  2575. };
  2576. }
  2577. addWindowResolutionChange();
  2578. _boundEvents.windowResize = () => {
  2579. eventBus.dispatch("resize", {
  2580. source: window
  2581. });
  2582. };
  2583. _boundEvents.windowHashChange = () => {
  2584. eventBus.dispatch("hashchange", {
  2585. source: window,
  2586. hash: document.location.hash.substring(1)
  2587. });
  2588. };
  2589. _boundEvents.windowBeforePrint = () => {
  2590. eventBus.dispatch("beforeprint", {
  2591. source: window
  2592. });
  2593. };
  2594. _boundEvents.windowAfterPrint = () => {
  2595. eventBus.dispatch("afterprint", {
  2596. source: window
  2597. });
  2598. };
  2599. _boundEvents.windowUpdateFromSandbox = event => {
  2600. eventBus.dispatch("updatefromsandbox", {
  2601. source: window,
  2602. detail: event.detail
  2603. });
  2604. };
  2605. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  2606. window.addEventListener("wheel", webViewerWheel, {
  2607. passive: false
  2608. });
  2609. window.addEventListener("touchstart", webViewerTouchStart, {
  2610. passive: false
  2611. });
  2612. window.addEventListener("click", webViewerClick);
  2613. // window.addEventListener("keydown", webViewerKeyDown);
  2614. window.addEventListener("resize", _boundEvents.windowResize);
  2615. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  2616. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2617. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  2618. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2619. },
  2620. unbindEvents() {
  2621. const {
  2622. eventBus,
  2623. _boundEvents
  2624. } = this;
  2625. eventBus._off("resize", webViewerResize);
  2626. eventBus._off("hashchange", webViewerHashchange);
  2627. eventBus._off("beforeprint", _boundEvents.beforePrint);
  2628. eventBus._off("afterprint", _boundEvents.afterPrint);
  2629. eventBus._off("pagerendered", webViewerPageRendered);
  2630. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  2631. eventBus._off("pagechanging", webViewerPageChanging);
  2632. eventBus._off("scalechanging", webViewerScaleChanging);
  2633. eventBus._off("rotationchanging", webViewerRotationChanging);
  2634. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  2635. eventBus._off("pagemode", webViewerPageMode);
  2636. eventBus._off("namedaction", webViewerNamedAction);
  2637. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  2638. eventBus._off("presentationmode", webViewerPresentationMode);
  2639. eventBus._off("print", webViewerPrint);
  2640. eventBus._off("download", webViewerDownload);
  2641. eventBus._off("firstpage", webViewerFirstPage);
  2642. eventBus._off("lastpage", webViewerLastPage);
  2643. eventBus._off("nextpage", webViewerNextPage);
  2644. eventBus._off("previouspage", webViewerPreviousPage);
  2645. eventBus._off("zoomin", webViewerZoomIn);
  2646. eventBus._off("zoomout", webViewerZoomOut);
  2647. eventBus._off("zoomreset", webViewerZoomReset);
  2648. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  2649. eventBus._off("scalechanged", webViewerScaleChanged);
  2650. eventBus._off("rotatecw", webViewerRotateCw);
  2651. eventBus._off("rotateccw", webViewerRotateCcw);
  2652. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  2653. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  2654. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  2655. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  2656. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  2657. eventBus._off("documentproperties", webViewerDocumentProperties);
  2658. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  2659. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2660. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  2661. if (_boundEvents.reportPageStatsPDFBug) {
  2662. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2663. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2664. _boundEvents.reportPageStatsPDFBug = null;
  2665. }
  2666. eventBus._off("fileinputchange", webViewerFileInputChange);
  2667. eventBus._off("openfile", webViewerOpenFile);
  2668. _boundEvents.beforePrint = null;
  2669. _boundEvents.afterPrint = null;
  2670. },
  2671. unbindWindowEvents() {
  2672. const {
  2673. _boundEvents
  2674. } = this;
  2675. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  2676. window.removeEventListener("wheel", webViewerWheel, {
  2677. passive: false
  2678. });
  2679. window.removeEventListener("touchstart", webViewerTouchStart, {
  2680. passive: false
  2681. });
  2682. window.removeEventListener("click", webViewerClick);
  2683. // window.removeEventListener("keydown", webViewerKeyDown);
  2684. window.removeEventListener("resize", _boundEvents.windowResize);
  2685. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  2686. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2687. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  2688. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2689. _boundEvents.removeWindowResolutionChange?.();
  2690. _boundEvents.windowResize = null;
  2691. _boundEvents.windowHashChange = null;
  2692. _boundEvents.windowBeforePrint = null;
  2693. _boundEvents.windowAfterPrint = null;
  2694. _boundEvents.windowUpdateFromSandbox = null;
  2695. },
  2696. accumulateWheelTicks(ticks) {
  2697. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  2698. this._wheelUnusedTicks = 0;
  2699. }
  2700. this._wheelUnusedTicks += ticks;
  2701. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  2702. this._wheelUnusedTicks -= wholeTicks;
  2703. return wholeTicks;
  2704. },
  2705. _unblockDocumentLoadEvent() {
  2706. document.blockUnblockOnload?.(false);
  2707. this._unblockDocumentLoadEvent = () => {};
  2708. },
  2709. _reportDocumentStatsTelemetry() {
  2710. const {
  2711. stats
  2712. } = this.pdfDocument;
  2713. if (stats !== this._docStats) {
  2714. this._docStats = stats;
  2715. this.externalServices.reportTelemetry({
  2716. type: "documentStats",
  2717. stats
  2718. });
  2719. }
  2720. },
  2721. get scriptingReady() {
  2722. return this.pdfScriptingManager.ready;
  2723. }
  2724. };
  2725. exports.PDFViewerApplication = PDFViewerApplication;
  2726. {
  2727. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  2728. var validateFileURL = function (file) {
  2729. if (!file) {
  2730. return;
  2731. }
  2732. try {
  2733. const viewerOrigin = new URL(window.location.href).origin || "null";
  2734. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  2735. return;
  2736. }
  2737. const fileOrigin = new URL(file, window.location.href).origin;
  2738. // if (fileOrigin !== viewerOrigin) {
  2739. // throw new Error("file origin does not match viewer's");
  2740. // }
  2741. } catch (ex) {
  2742. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2743. PDFViewerApplication._documentError(msg, {
  2744. message: ex?.message
  2745. });
  2746. });
  2747. throw ex;
  2748. }
  2749. };
  2750. }
  2751. async function loadFakeWorker() {
  2752. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  2753. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  2754. }
  2755. async function loadPDFBug(self) {
  2756. const {
  2757. debuggerScriptPath
  2758. } = self.appConfig;
  2759. const {
  2760. PDFBug
  2761. } = await import(debuggerScriptPath);
  2762. self._PDFBug = PDFBug;
  2763. }
  2764. function reportPageStatsPDFBug({
  2765. pageNumber
  2766. }) {
  2767. if (!globalThis.Stats?.enabled) {
  2768. return;
  2769. }
  2770. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2771. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  2772. }
  2773. function webViewerInitialized() {
  2774. const {
  2775. appConfig,
  2776. eventBus
  2777. } = PDFViewerApplication;
  2778. let file;
  2779. const queryString = document.location.search.substring(1);
  2780. const params = (0, _ui_utils.parseQueryString)(queryString);
  2781. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  2782. validateFileURL(file);
  2783. const fileInput = appConfig.openFileInput;
  2784. fileInput.value = null;
  2785. fileInput.addEventListener("change", function (evt) {
  2786. const {
  2787. files
  2788. } = evt.target;
  2789. if (!files || files.length === 0) {
  2790. return;
  2791. }
  2792. eventBus.dispatch("fileinputchange", {
  2793. source: this,
  2794. fileInput: evt.target
  2795. });
  2796. });
  2797. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  2798. evt.preventDefault();
  2799. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  2800. });
  2801. appConfig.mainContainer.addEventListener("drop", function (evt) {
  2802. evt.preventDefault();
  2803. const {
  2804. files
  2805. } = evt.dataTransfer;
  2806. if (!files || files.length === 0) {
  2807. return;
  2808. }
  2809. eventBus.dispatch("fileinputchange", {
  2810. source: this,
  2811. fileInput: evt.dataTransfer
  2812. });
  2813. });
  2814. if (!PDFViewerApplication.supportsDocumentFonts) {
  2815. _app_options.AppOptions.set("disableFontFace", true);
  2816. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  2817. console.warn(msg);
  2818. });
  2819. }
  2820. if (!PDFViewerApplication.supportsPrinting) {
  2821. appConfig.toolbar.print.classList.add("hidden");
  2822. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  2823. }
  2824. if (!PDFViewerApplication.supportsFullscreen) {
  2825. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  2826. }
  2827. if (PDFViewerApplication.supportsIntegratedFind) {
  2828. appConfig.toolbar.viewFind.classList.add("hidden");
  2829. }
  2830. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  2831. if (evt.target === this) {
  2832. eventBus.dispatch("resize", {
  2833. source: this
  2834. });
  2835. }
  2836. }, true);
  2837. try {
  2838. if (file) {
  2839. PDFViewerApplication.open(file);
  2840. } else {
  2841. PDFViewerApplication._hideViewBookmark();
  2842. }
  2843. } catch (reason) {
  2844. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2845. PDFViewerApplication._documentError(msg, reason);
  2846. });
  2847. }
  2848. }
  2849. function webViewerPageRendered({
  2850. pageNumber,
  2851. error
  2852. }) {
  2853. if (pageNumber === PDFViewerApplication.page) {
  2854. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  2855. }
  2856. if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
  2857. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2858. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  2859. if (pageView && thumbnailView) {
  2860. thumbnailView.setImage(pageView);
  2861. }
  2862. }
  2863. if (error) {
  2864. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  2865. PDFViewerApplication._otherError(msg, error);
  2866. });
  2867. }
  2868. PDFViewerApplication._reportDocumentStatsTelemetry();
  2869. }
  2870. function webViewerPageMode({
  2871. mode
  2872. }) {
  2873. let view;
  2874. switch (mode) {
  2875. case "thumbs":
  2876. view = _ui_utils.SidebarView.THUMBS;
  2877. break;
  2878. case "bookmarks":
  2879. case "outline":
  2880. view = _ui_utils.SidebarView.OUTLINE;
  2881. break;
  2882. case "attachments":
  2883. view = _ui_utils.SidebarView.ATTACHMENTS;
  2884. break;
  2885. case "layers":
  2886. view = _ui_utils.SidebarView.LAYERS;
  2887. break;
  2888. case "none":
  2889. view = _ui_utils.SidebarView.NONE;
  2890. break;
  2891. default:
  2892. console.error('Invalid "pagemode" hash parameter: ' + mode);
  2893. return;
  2894. }
  2895. PDFViewerApplication.pdfSidebar.switchView(view, true);
  2896. }
  2897. function webViewerNamedAction(evt) {
  2898. switch (evt.action) {
  2899. case "GoToPage":
  2900. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2901. break;
  2902. case "Find":
  2903. if (!PDFViewerApplication.supportsIntegratedFind) {
  2904. PDFViewerApplication.findBar.toggle();
  2905. }
  2906. break;
  2907. case "Print":
  2908. PDFViewerApplication.triggerPrinting();
  2909. break;
  2910. case "SaveAs":
  2911. PDFViewerApplication.downloadOrSave();
  2912. break;
  2913. }
  2914. }
  2915. function webViewerPresentationModeChanged(evt) {
  2916. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  2917. }
  2918. function webViewerSidebarViewChanged({
  2919. view
  2920. }) {
  2921. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  2922. if (PDFViewerApplication.isInitialViewSet) {
  2923. PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
  2924. }
  2925. }
  2926. function webViewerUpdateViewarea({
  2927. location
  2928. }) {
  2929. if (PDFViewerApplication.isInitialViewSet) {
  2930. PDFViewerApplication.store?.setMultiple({
  2931. page: location.pageNumber,
  2932. zoom: location.scale,
  2933. scrollLeft: location.left,
  2934. scrollTop: location.top,
  2935. rotation: location.rotation
  2936. }).catch(() => {});
  2937. }
  2938. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  2939. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  2940. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  2941. const loading = currentPage?.renderingState !== _ui_utils.RenderingStates.FINISHED;
  2942. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  2943. }
  2944. function webViewerScrollModeChanged(evt) {
  2945. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  2946. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  2947. }
  2948. }
  2949. function webViewerSpreadModeChanged(evt) {
  2950. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  2951. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  2952. }
  2953. }
  2954. function webViewerResize() {
  2955. const {
  2956. pdfDocument,
  2957. pdfViewer,
  2958. pdfRenderingQueue
  2959. } = PDFViewerApplication;
  2960. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  2961. return;
  2962. }
  2963. pdfViewer.updateContainerHeightCss();
  2964. if (!pdfDocument) {
  2965. return;
  2966. }
  2967. const currentScaleValue = pdfViewer.currentScaleValue;
  2968. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  2969. pdfViewer.currentScaleValue = currentScaleValue;
  2970. }
  2971. pdfViewer.update();
  2972. }
  2973. function webViewerHashchange(evt) {
  2974. const hash = evt.hash;
  2975. if (!hash) {
  2976. return;
  2977. }
  2978. if (!PDFViewerApplication.isInitialViewSet) {
  2979. PDFViewerApplication.initialBookmark = hash;
  2980. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  2981. PDFViewerApplication.pdfLinkService.setHash(hash);
  2982. }
  2983. }
  2984. {
  2985. var webViewerFileInputChange = function (evt) {
  2986. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2987. return;
  2988. }
  2989. const file = evt.fileInput.files[0];
  2990. let url = URL.createObjectURL(file);
  2991. if (file.name) {
  2992. url = {
  2993. url,
  2994. originalUrl: file.name
  2995. };
  2996. }
  2997. PDFViewerApplication.open(url);
  2998. };
  2999. var webViewerOpenFile = function (evt) {
  3000. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  3001. fileInput.click();
  3002. };
  3003. }
  3004. function webViewerPresentationMode() {
  3005. PDFViewerApplication.requestPresentationMode();
  3006. }
  3007. function webViewerSwitchAnnotationEditorMode(evt) {
  3008. PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
  3009. }
  3010. function webViewerSwitchAnnotationEditorParams(evt) {
  3011. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  3012. }
  3013. function webViewerPrint() {
  3014. PDFViewerApplication.triggerPrinting();
  3015. }
  3016. function webViewerDownload() {
  3017. PDFViewerApplication.downloadOrSave();
  3018. }
  3019. function webViewerFirstPage() {
  3020. if (PDFViewerApplication.pdfDocument) {
  3021. PDFViewerApplication.page = 1;
  3022. }
  3023. }
  3024. function webViewerLastPage() {
  3025. if (PDFViewerApplication.pdfDocument) {
  3026. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3027. }
  3028. }
  3029. function webViewerNextPage() {
  3030. PDFViewerApplication.pdfViewer.nextPage();
  3031. }
  3032. function webViewerPreviousPage() {
  3033. PDFViewerApplication.pdfViewer.previousPage();
  3034. }
  3035. function webViewerZoomIn() {
  3036. PDFViewerApplication.zoomIn();
  3037. }
  3038. function webViewerZoomOut() {
  3039. PDFViewerApplication.zoomOut();
  3040. }
  3041. function webViewerZoomReset() {
  3042. PDFViewerApplication.zoomReset();
  3043. }
  3044. function webViewerPageNumberChanged(evt) {
  3045. const pdfViewer = PDFViewerApplication.pdfViewer;
  3046. if (evt.value !== "") {
  3047. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  3048. }
  3049. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  3050. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  3051. }
  3052. }
  3053. function webViewerScaleChanged(evt) {
  3054. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  3055. }
  3056. function webViewerRotateCw() {
  3057. PDFViewerApplication.rotatePages(90);
  3058. }
  3059. function webViewerRotateCcw() {
  3060. PDFViewerApplication.rotatePages(-90);
  3061. }
  3062. function webViewerOptionalContentConfig(evt) {
  3063. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  3064. }
  3065. function webViewerSwitchScrollMode(evt) {
  3066. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  3067. }
  3068. function webViewerSwitchSpreadMode(evt) {
  3069. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  3070. }
  3071. function webViewerDocumentProperties() {
  3072. PDFViewerApplication.pdfDocumentProperties.open();
  3073. }
  3074. function webViewerFindFromUrlHash(evt) {
  3075. PDFViewerApplication.eventBus.dispatch("find", {
  3076. source: evt.source,
  3077. type: "",
  3078. query: evt.query,
  3079. phraseSearch: evt.phraseSearch,
  3080. caseSensitive: false,
  3081. entireWord: false,
  3082. highlightAll: true,
  3083. findPrevious: false,
  3084. matchDiacritics: true
  3085. });
  3086. }
  3087. function webViewerUpdateFindMatchesCount({
  3088. matchesCount
  3089. }) {
  3090. if (PDFViewerApplication.supportsIntegratedFind) {
  3091. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  3092. } else {
  3093. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  3094. }
  3095. }
  3096. function webViewerUpdateFindControlState({
  3097. state,
  3098. previous,
  3099. matchesCount,
  3100. rawQuery
  3101. }) {
  3102. if (PDFViewerApplication.supportsIntegratedFind) {
  3103. PDFViewerApplication.externalServices.updateFindControlState({
  3104. result: state,
  3105. findPrevious: previous,
  3106. matchesCount,
  3107. rawQuery
  3108. });
  3109. } else {
  3110. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  3111. }
  3112. }
  3113. function webViewerScaleChanging(evt) {
  3114. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  3115. PDFViewerApplication.pdfViewer.update();
  3116. }
  3117. function webViewerRotationChanging(evt) {
  3118. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  3119. PDFViewerApplication.forceRendering();
  3120. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  3121. }
  3122. function webViewerPageChanging({
  3123. pageNumber,
  3124. pageLabel
  3125. }) {
  3126. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  3127. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  3128. if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
  3129. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  3130. }
  3131. }
  3132. function webViewerResolutionChange(evt) {
  3133. PDFViewerApplication.pdfViewer.refresh();
  3134. }
  3135. function webViewerVisibilityChange(evt) {
  3136. if (document.visibilityState === "visible") {
  3137. setZoomDisabledTimeout();
  3138. }
  3139. }
  3140. let zoomDisabledTimeout = null;
  3141. function setZoomDisabledTimeout() {
  3142. if (zoomDisabledTimeout) {
  3143. clearTimeout(zoomDisabledTimeout);
  3144. }
  3145. zoomDisabledTimeout = setTimeout(function () {
  3146. zoomDisabledTimeout = null;
  3147. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  3148. }
  3149. function webViewerWheel(evt) {
  3150. const {
  3151. pdfViewer,
  3152. supportedMouseWheelZoomModifierKeys
  3153. } = PDFViewerApplication;
  3154. if (pdfViewer.isInPresentationMode) {
  3155. return;
  3156. }
  3157. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  3158. evt.preventDefault();
  3159. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  3160. return;
  3161. }
  3162. const deltaMode = evt.deltaMode;
  3163. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  3164. const previousScale = pdfViewer.currentScale;
  3165. let ticks = 0;
  3166. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  3167. if (Math.abs(delta) >= 1) {
  3168. ticks = Math.sign(delta);
  3169. } else {
  3170. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  3171. }
  3172. } else {
  3173. const PIXELS_PER_LINE_SCALE = 30;
  3174. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  3175. }
  3176. if (ticks < 0) {
  3177. PDFViewerApplication.zoomOut(-ticks);
  3178. } else if (ticks > 0) {
  3179. PDFViewerApplication.zoomIn(ticks);
  3180. }
  3181. const currentScale = pdfViewer.currentScale;
  3182. if (previousScale !== currentScale) {
  3183. const scaleCorrectionFactor = currentScale / previousScale - 1;
  3184. const rect = pdfViewer.container.getBoundingClientRect();
  3185. const dx = evt.clientX - rect.left;
  3186. const dy = evt.clientY - rect.top;
  3187. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  3188. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  3189. }
  3190. } else {
  3191. setZoomDisabledTimeout();
  3192. }
  3193. }
  3194. function webViewerTouchStart(evt) {
  3195. if (evt.touches.length > 1) {
  3196. evt.preventDefault();
  3197. }
  3198. }
  3199. function webViewerClick(evt) {
  3200. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  3201. return;
  3202. }
  3203. const appConfig = PDFViewerApplication.appConfig;
  3204. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  3205. PDFViewerApplication.secondaryToolbar.close();
  3206. }
  3207. }
  3208. function webViewerKeyDown(evt) {
  3209. if (PDFViewerApplication.overlayManager.active) {
  3210. return;
  3211. }
  3212. const {
  3213. eventBus,
  3214. pdfViewer
  3215. } = PDFViewerApplication;
  3216. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  3217. let handled = false,
  3218. ensureViewerFocused = false;
  3219. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  3220. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  3221. switch (evt.keyCode) {
  3222. case 70:
  3223. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  3224. PDFViewerApplication.findBar.open();
  3225. handled = true;
  3226. }
  3227. break;
  3228. case 71:
  3229. if (!PDFViewerApplication.supportsIntegratedFind) {
  3230. const {
  3231. state
  3232. } = PDFViewerApplication.findController;
  3233. if (state) {
  3234. const eventState = Object.assign(Object.create(null), state, {
  3235. source: window,
  3236. type: "again",
  3237. findPrevious: cmd === 5 || cmd === 12
  3238. });
  3239. eventBus.dispatch("find", eventState);
  3240. }
  3241. handled = true;
  3242. }
  3243. break;
  3244. case 61:
  3245. case 107:
  3246. case 187:
  3247. case 171:
  3248. if (!isViewerInPresentationMode) {
  3249. PDFViewerApplication.zoomIn();
  3250. }
  3251. handled = true;
  3252. break;
  3253. case 173:
  3254. case 109:
  3255. case 189:
  3256. if (!isViewerInPresentationMode) {
  3257. PDFViewerApplication.zoomOut();
  3258. }
  3259. handled = true;
  3260. break;
  3261. case 48:
  3262. case 96:
  3263. if (!isViewerInPresentationMode) {
  3264. setTimeout(function () {
  3265. PDFViewerApplication.zoomReset();
  3266. });
  3267. handled = false;
  3268. }
  3269. break;
  3270. case 38:
  3271. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3272. PDFViewerApplication.page = 1;
  3273. handled = true;
  3274. ensureViewerFocused = true;
  3275. }
  3276. break;
  3277. case 40:
  3278. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3279. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3280. handled = true;
  3281. ensureViewerFocused = true;
  3282. }
  3283. break;
  3284. }
  3285. }
  3286. if (cmd === 1 || cmd === 8) {
  3287. switch (evt.keyCode) {
  3288. case 83:
  3289. eventBus.dispatch("download", {
  3290. source: window
  3291. });
  3292. handled = true;
  3293. break;
  3294. case 79:
  3295. {
  3296. eventBus.dispatch("openfile", {
  3297. source: window
  3298. });
  3299. handled = true;
  3300. }
  3301. break;
  3302. }
  3303. }
  3304. if (cmd === 3 || cmd === 10) {
  3305. switch (evt.keyCode) {
  3306. case 80:
  3307. PDFViewerApplication.requestPresentationMode();
  3308. handled = true;
  3309. PDFViewerApplication.externalServices.reportTelemetry({
  3310. type: "buttons",
  3311. data: {
  3312. id: "presentationModeKeyboard"
  3313. }
  3314. });
  3315. break;
  3316. case 71:
  3317. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  3318. handled = true;
  3319. break;
  3320. }
  3321. }
  3322. if (handled) {
  3323. if (ensureViewerFocused && !isViewerInPresentationMode) {
  3324. pdfViewer.focus();
  3325. }
  3326. evt.preventDefault();
  3327. return;
  3328. }
  3329. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  3330. const curElementTagName = curElement?.tagName.toUpperCase();
  3331. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  3332. if (evt.keyCode !== 27) {
  3333. return;
  3334. }
  3335. }
  3336. if (cmd === 0) {
  3337. let turnPage = 0,
  3338. turnOnlyIfPageFit = false;
  3339. switch (evt.keyCode) {
  3340. case 38:
  3341. case 33:
  3342. if (pdfViewer.isVerticalScrollbarEnabled) {
  3343. turnOnlyIfPageFit = true;
  3344. }
  3345. turnPage = -1;
  3346. break;
  3347. case 8:
  3348. if (!isViewerInPresentationMode) {
  3349. turnOnlyIfPageFit = true;
  3350. }
  3351. turnPage = -1;
  3352. break;
  3353. case 37:
  3354. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3355. turnOnlyIfPageFit = true;
  3356. }
  3357. case 75:
  3358. case 80:
  3359. turnPage = -1;
  3360. break;
  3361. case 27:
  3362. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  3363. PDFViewerApplication.secondaryToolbar.close();
  3364. handled = true;
  3365. }
  3366. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  3367. PDFViewerApplication.findBar.close();
  3368. handled = true;
  3369. }
  3370. break;
  3371. case 40:
  3372. case 34:
  3373. if (pdfViewer.isVerticalScrollbarEnabled) {
  3374. turnOnlyIfPageFit = true;
  3375. }
  3376. turnPage = 1;
  3377. break;
  3378. case 13:
  3379. case 32:
  3380. if (!isViewerInPresentationMode) {
  3381. turnOnlyIfPageFit = true;
  3382. }
  3383. turnPage = 1;
  3384. break;
  3385. case 39:
  3386. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3387. turnOnlyIfPageFit = true;
  3388. }
  3389. case 74:
  3390. case 78:
  3391. turnPage = 1;
  3392. break;
  3393. case 36:
  3394. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3395. PDFViewerApplication.page = 1;
  3396. handled = true;
  3397. ensureViewerFocused = true;
  3398. }
  3399. break;
  3400. case 35:
  3401. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3402. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3403. handled = true;
  3404. ensureViewerFocused = true;
  3405. }
  3406. break;
  3407. case 83:
  3408. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  3409. break;
  3410. case 72:
  3411. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  3412. break;
  3413. case 82:
  3414. PDFViewerApplication.rotatePages(90);
  3415. break;
  3416. case 115:
  3417. PDFViewerApplication.pdfSidebar.toggle();
  3418. break;
  3419. }
  3420. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  3421. if (turnPage > 0) {
  3422. pdfViewer.nextPage();
  3423. } else {
  3424. pdfViewer.previousPage();
  3425. }
  3426. handled = true;
  3427. }
  3428. }
  3429. if (cmd === 4) {
  3430. switch (evt.keyCode) {
  3431. case 13:
  3432. case 32:
  3433. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  3434. break;
  3435. }
  3436. pdfViewer.previousPage();
  3437. handled = true;
  3438. break;
  3439. case 82:
  3440. PDFViewerApplication.rotatePages(-90);
  3441. break;
  3442. }
  3443. }
  3444. if (!handled && !isViewerInPresentationMode) {
  3445. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  3446. ensureViewerFocused = true;
  3447. }
  3448. }
  3449. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  3450. pdfViewer.focus();
  3451. }
  3452. if (handled) {
  3453. evt.preventDefault();
  3454. }
  3455. }
  3456. function beforeUnload(evt) {
  3457. evt.preventDefault();
  3458. evt.returnValue = "";
  3459. return false;
  3460. }
  3461. function webViewerAnnotationEditorStatesChanged(data) {
  3462. PDFViewerApplication.externalServices.updateEditorStates(data);
  3463. }
  3464. const PDFPrintServiceFactory = {
  3465. instance: {
  3466. supportsPrinting: false,
  3467. createPrintService() {
  3468. throw new Error("Not implemented: createPrintService");
  3469. }
  3470. }
  3471. };
  3472. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  3473. /***/ }),
  3474. /* 5 */
  3475. /***/ ((module) => {
  3476. let pdfjsLib;
  3477. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3478. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3479. } else {
  3480. pdfjsLib = require("../build/pdf.js");
  3481. }
  3482. module.exports = pdfjsLib;
  3483. /***/ }),
  3484. /* 6 */
  3485. /***/ ((__unused_webpack_module, exports) => {
  3486. Object.defineProperty(exports, "__esModule", ({
  3487. value: true
  3488. }));
  3489. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3490. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3491. const WaitOnType = {
  3492. EVENT: "event",
  3493. TIMEOUT: "timeout"
  3494. };
  3495. exports.WaitOnType = WaitOnType;
  3496. function waitOnEventOrTimeout({
  3497. target,
  3498. name,
  3499. delay = 0
  3500. }) {
  3501. return new Promise(function (resolve, reject) {
  3502. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3503. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3504. }
  3505. function handler(type) {
  3506. if (target instanceof EventBus) {
  3507. target._off(name, eventHandler);
  3508. } else {
  3509. target.removeEventListener(name, eventHandler);
  3510. }
  3511. if (timeout) {
  3512. clearTimeout(timeout);
  3513. }
  3514. resolve(type);
  3515. }
  3516. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3517. if (target instanceof EventBus) {
  3518. target._on(name, eventHandler);
  3519. } else {
  3520. target.addEventListener(name, eventHandler);
  3521. }
  3522. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3523. const timeout = setTimeout(timeoutHandler, delay);
  3524. });
  3525. }
  3526. class EventBus {
  3527. #listeners = Object.create(null);
  3528. on(eventName, listener, options = null) {
  3529. this._on(eventName, listener, {
  3530. external: true,
  3531. once: options?.once
  3532. });
  3533. }
  3534. off(eventName, listener, options = null) {
  3535. this._off(eventName, listener, {
  3536. external: true,
  3537. once: options?.once
  3538. });
  3539. }
  3540. dispatch(eventName, data) {
  3541. const eventListeners = this.#listeners[eventName];
  3542. if (!eventListeners || eventListeners.length === 0) {
  3543. return;
  3544. }
  3545. let externalListeners;
  3546. for (const {
  3547. listener,
  3548. external,
  3549. once
  3550. } of eventListeners.slice(0)) {
  3551. if (once) {
  3552. this._off(eventName, listener);
  3553. }
  3554. if (external) {
  3555. (externalListeners ||= []).push(listener);
  3556. continue;
  3557. }
  3558. listener(data);
  3559. }
  3560. if (externalListeners) {
  3561. for (const listener of externalListeners) {
  3562. listener(data);
  3563. }
  3564. externalListeners = null;
  3565. }
  3566. }
  3567. _on(eventName, listener, options = null) {
  3568. const eventListeners = this.#listeners[eventName] ||= [];
  3569. eventListeners.push({
  3570. listener,
  3571. external: options?.external === true,
  3572. once: options?.once === true
  3573. });
  3574. }
  3575. _off(eventName, listener, options = null) {
  3576. const eventListeners = this.#listeners[eventName];
  3577. if (!eventListeners) {
  3578. return;
  3579. }
  3580. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3581. if (eventListeners[i].listener === listener) {
  3582. eventListeners.splice(i, 1);
  3583. return;
  3584. }
  3585. }
  3586. }
  3587. }
  3588. exports.EventBus = EventBus;
  3589. class AutomationEventBus extends EventBus {
  3590. dispatch(eventName, data) {
  3591. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3592. }
  3593. }
  3594. exports.AutomationEventBus = AutomationEventBus;
  3595. /***/ }),
  3596. /* 7 */
  3597. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3598. Object.defineProperty(exports, "__esModule", ({
  3599. value: true
  3600. }));
  3601. exports.PDFCursorTools = exports.CursorTool = void 0;
  3602. var _pdfjsLib = __webpack_require__(5);
  3603. var _grab_to_pan = __webpack_require__(8);
  3604. var _ui_utils = __webpack_require__(1);
  3605. const CursorTool = {
  3606. SELECT: 0,
  3607. HAND: 1,
  3608. ZOOM: 2
  3609. };
  3610. exports.CursorTool = CursorTool;
  3611. class PDFCursorTools {
  3612. constructor({
  3613. container,
  3614. eventBus,
  3615. cursorToolOnLoad = CursorTool.SELECT
  3616. }) {
  3617. this.container = container;
  3618. this.eventBus = eventBus;
  3619. this.active = CursorTool.SELECT;
  3620. this.previouslyActive = null;
  3621. this.handTool = new _grab_to_pan.GrabToPan({
  3622. element: this.container
  3623. });
  3624. this.#addEventListeners();
  3625. Promise.resolve().then(() => {
  3626. this.switchTool(cursorToolOnLoad);
  3627. });
  3628. }
  3629. get activeTool() {
  3630. return this.active;
  3631. }
  3632. switchTool(tool) {
  3633. if (this.previouslyActive !== null) {
  3634. return;
  3635. }
  3636. if (tool === this.active) {
  3637. return;
  3638. }
  3639. const disableActiveTool = () => {
  3640. switch (this.active) {
  3641. case CursorTool.SELECT:
  3642. break;
  3643. case CursorTool.HAND:
  3644. this.handTool.deactivate();
  3645. break;
  3646. case CursorTool.ZOOM:
  3647. }
  3648. };
  3649. switch (tool) {
  3650. case CursorTool.SELECT:
  3651. disableActiveTool();
  3652. break;
  3653. case CursorTool.HAND:
  3654. disableActiveTool();
  3655. this.handTool.activate();
  3656. break;
  3657. case CursorTool.ZOOM:
  3658. default:
  3659. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3660. return;
  3661. }
  3662. this.active = tool;
  3663. this.#dispatchEvent();
  3664. }
  3665. #dispatchEvent() {
  3666. this.eventBus.dispatch("cursortoolchanged", {
  3667. source: this,
  3668. tool: this.active
  3669. });
  3670. }
  3671. #addEventListeners() {
  3672. this.eventBus._on("switchcursortool", evt => {
  3673. this.switchTool(evt.tool);
  3674. });
  3675. let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
  3676. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  3677. const disableActive = () => {
  3678. const previouslyActive = this.active;
  3679. this.switchTool(CursorTool.SELECT);
  3680. this.previouslyActive ??= previouslyActive;
  3681. };
  3682. const enableActive = () => {
  3683. const previouslyActive = this.previouslyActive;
  3684. if (previouslyActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) {
  3685. this.previouslyActive = null;
  3686. this.switchTool(previouslyActive);
  3687. }
  3688. };
  3689. this.eventBus._on("secondarytoolbarreset", evt => {
  3690. if (this.previouslyActive !== null) {
  3691. annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  3692. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  3693. enableActive();
  3694. }
  3695. });
  3696. this.eventBus._on("annotationeditormodechanged", ({
  3697. mode
  3698. }) => {
  3699. annotationEditorMode = mode;
  3700. if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
  3701. enableActive();
  3702. } else {
  3703. disableActive();
  3704. }
  3705. });
  3706. this.eventBus._on("presentationmodechanged", ({
  3707. state
  3708. }) => {
  3709. presentationModeState = state;
  3710. if (state === _ui_utils.PresentationModeState.NORMAL) {
  3711. enableActive();
  3712. } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
  3713. disableActive();
  3714. }
  3715. });
  3716. }
  3717. }
  3718. exports.PDFCursorTools = PDFCursorTools;
  3719. /***/ }),
  3720. /* 8 */
  3721. /***/ ((__unused_webpack_module, exports) => {
  3722. Object.defineProperty(exports, "__esModule", ({
  3723. value: true
  3724. }));
  3725. exports.GrabToPan = void 0;
  3726. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3727. class GrabToPan {
  3728. constructor(options) {
  3729. this.element = options.element;
  3730. this.document = options.element.ownerDocument;
  3731. if (typeof options.ignoreTarget === "function") {
  3732. this.ignoreTarget = options.ignoreTarget;
  3733. }
  3734. this.onActiveChanged = options.onActiveChanged;
  3735. this.activate = this.activate.bind(this);
  3736. this.deactivate = this.deactivate.bind(this);
  3737. this.toggle = this.toggle.bind(this);
  3738. this._onMouseDown = this.#onMouseDown.bind(this);
  3739. this._onMouseMove = this.#onMouseMove.bind(this);
  3740. this._endPan = this.#endPan.bind(this);
  3741. const overlay = this.overlay = document.createElement("div");
  3742. overlay.className = "grab-to-pan-grabbing";
  3743. }
  3744. activate() {
  3745. if (!this.active) {
  3746. this.active = true;
  3747. this.element.addEventListener("mousedown", this._onMouseDown, true);
  3748. this.element.classList.add(CSS_CLASS_GRAB);
  3749. this.onActiveChanged?.(true);
  3750. }
  3751. }
  3752. deactivate() {
  3753. if (this.active) {
  3754. this.active = false;
  3755. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  3756. this._endPan();
  3757. this.element.classList.remove(CSS_CLASS_GRAB);
  3758. this.onActiveChanged?.(false);
  3759. }
  3760. }
  3761. toggle() {
  3762. if (this.active) {
  3763. this.deactivate();
  3764. } else {
  3765. this.activate();
  3766. }
  3767. }
  3768. ignoreTarget(node) {
  3769. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3770. }
  3771. #onMouseDown(event) {
  3772. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3773. return;
  3774. }
  3775. if (event.originalTarget) {
  3776. try {
  3777. event.originalTarget.tagName;
  3778. } catch (e) {
  3779. return;
  3780. }
  3781. }
  3782. this.scrollLeftStart = this.element.scrollLeft;
  3783. this.scrollTopStart = this.element.scrollTop;
  3784. this.clientXStart = event.clientX;
  3785. this.clientYStart = event.clientY;
  3786. this.document.addEventListener("mousemove", this._onMouseMove, true);
  3787. this.document.addEventListener("mouseup", this._endPan, true);
  3788. this.element.addEventListener("scroll", this._endPan, true);
  3789. event.preventDefault();
  3790. event.stopPropagation();
  3791. const focusedElement = document.activeElement;
  3792. if (focusedElement && !focusedElement.contains(event.target)) {
  3793. focusedElement.blur();
  3794. }
  3795. }
  3796. #onMouseMove(event) {
  3797. this.element.removeEventListener("scroll", this._endPan, true);
  3798. if (!(event.buttons & 1)) {
  3799. this._endPan();
  3800. return;
  3801. }
  3802. const xDiff = event.clientX - this.clientXStart;
  3803. const yDiff = event.clientY - this.clientYStart;
  3804. const scrollTop = this.scrollTopStart - yDiff;
  3805. const scrollLeft = this.scrollLeftStart - xDiff;
  3806. if (this.element.scrollTo) {
  3807. this.element.scrollTo({
  3808. top: scrollTop,
  3809. left: scrollLeft,
  3810. behavior: "instant"
  3811. });
  3812. } else {
  3813. this.element.scrollTop = scrollTop;
  3814. this.element.scrollLeft = scrollLeft;
  3815. }
  3816. if (!this.overlay.parentNode) {
  3817. document.body.append(this.overlay);
  3818. }
  3819. }
  3820. #endPan() {
  3821. this.element.removeEventListener("scroll", this._endPan, true);
  3822. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  3823. this.document.removeEventListener("mouseup", this._endPan, true);
  3824. this.overlay.remove();
  3825. }
  3826. }
  3827. exports.GrabToPan = GrabToPan;
  3828. /***/ }),
  3829. /* 9 */
  3830. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3831. Object.defineProperty(exports, "__esModule", ({
  3832. value: true
  3833. }));
  3834. exports.AnnotationEditorParams = void 0;
  3835. var _pdfjsLib = __webpack_require__(5);
  3836. class AnnotationEditorParams {
  3837. constructor(options, eventBus) {
  3838. this.eventBus = eventBus;
  3839. this.#bindListeners(options);
  3840. }
  3841. #bindListeners({
  3842. editorFreeTextFontSize,
  3843. editorFreeTextColor,
  3844. editorInkColor,
  3845. editorInkThickness,
  3846. editorInkOpacity
  3847. }) {
  3848. editorFreeTextFontSize.addEventListener("input", evt => {
  3849. this.eventBus.dispatch("switchannotationeditorparams", {
  3850. source: this,
  3851. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE,
  3852. value: editorFreeTextFontSize.valueAsNumber
  3853. });
  3854. });
  3855. editorFreeTextColor.addEventListener("input", evt => {
  3856. this.eventBus.dispatch("switchannotationeditorparams", {
  3857. source: this,
  3858. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR,
  3859. value: editorFreeTextColor.value
  3860. });
  3861. });
  3862. editorInkColor.addEventListener("input", evt => {
  3863. this.eventBus.dispatch("switchannotationeditorparams", {
  3864. source: this,
  3865. type: _pdfjsLib.AnnotationEditorParamsType.INK_COLOR,
  3866. value: editorInkColor.value
  3867. });
  3868. });
  3869. editorInkThickness.addEventListener("input", evt => {
  3870. this.eventBus.dispatch("switchannotationeditorparams", {
  3871. source: this,
  3872. type: _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS,
  3873. value: editorInkThickness.valueAsNumber
  3874. });
  3875. });
  3876. editorInkOpacity.addEventListener("input", evt => {
  3877. this.eventBus.dispatch("switchannotationeditorparams", {
  3878. source: this,
  3879. type: _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY,
  3880. value: editorInkOpacity.valueAsNumber
  3881. });
  3882. });
  3883. this.eventBus._on("annotationeditorparamschanged", evt => {
  3884. for (const [type, value] of evt.details) {
  3885. switch (type) {
  3886. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  3887. editorFreeTextFontSize.value = value;
  3888. break;
  3889. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  3890. editorFreeTextColor.value = value;
  3891. break;
  3892. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  3893. editorInkColor.value = value;
  3894. break;
  3895. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  3896. editorInkThickness.value = value;
  3897. break;
  3898. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  3899. editorInkOpacity.value = value;
  3900. break;
  3901. }
  3902. }
  3903. });
  3904. }
  3905. }
  3906. exports.AnnotationEditorParams = AnnotationEditorParams;
  3907. /***/ }),
  3908. /* 10 */
  3909. /***/ ((__unused_webpack_module, exports) => {
  3910. Object.defineProperty(exports, "__esModule", ({
  3911. value: true
  3912. }));
  3913. exports.OverlayManager = void 0;
  3914. class OverlayManager {
  3915. #overlays = new WeakMap();
  3916. #active = null;
  3917. get active() {
  3918. return this.#active;
  3919. }
  3920. async register(dialog, canForceClose = false) {
  3921. if (typeof dialog !== "object") {
  3922. throw new Error("Not enough parameters.");
  3923. } else if (this.#overlays.has(dialog)) {
  3924. throw new Error("The overlay is already registered.");
  3925. }
  3926. this.#overlays.set(dialog, {
  3927. canForceClose
  3928. });
  3929. dialog.addEventListener("cancel", evt => {
  3930. this.#active = null;
  3931. });
  3932. }
  3933. async unregister(dialog) {
  3934. if (!this.#overlays.has(dialog)) {
  3935. throw new Error("The overlay does not exist.");
  3936. } else if (this.#active === dialog) {
  3937. throw new Error("The overlay cannot be removed while it is active.");
  3938. }
  3939. this.#overlays.delete(dialog);
  3940. }
  3941. async open(dialog) {
  3942. if (!this.#overlays.has(dialog)) {
  3943. throw new Error("The overlay does not exist.");
  3944. } else if (this.#active) {
  3945. if (this.#active === dialog) {
  3946. throw new Error("The overlay is already active.");
  3947. } else if (this.#overlays.get(dialog).canForceClose) {
  3948. await this.close();
  3949. } else {
  3950. throw new Error("Another overlay is currently active.");
  3951. }
  3952. }
  3953. this.#active = dialog;
  3954. dialog.showModal();
  3955. }
  3956. async close(dialog = this.#active) {
  3957. if (!this.#overlays.has(dialog)) {
  3958. throw new Error("The overlay does not exist.");
  3959. } else if (!this.#active) {
  3960. throw new Error("The overlay is currently not active.");
  3961. } else if (this.#active !== dialog) {
  3962. throw new Error("Another overlay is currently active.");
  3963. }
  3964. dialog.close();
  3965. this.#active = null;
  3966. }
  3967. }
  3968. exports.OverlayManager = OverlayManager;
  3969. /***/ }),
  3970. /* 11 */
  3971. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3972. Object.defineProperty(exports, "__esModule", ({
  3973. value: true
  3974. }));
  3975. exports.PasswordPrompt = void 0;
  3976. var _pdfjsLib = __webpack_require__(5);
  3977. class PasswordPrompt {
  3978. #activeCapability = null;
  3979. #updateCallback = null;
  3980. #reason = null;
  3981. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3982. this.dialog = options.dialog;
  3983. this.label = options.label;
  3984. this.input = options.input;
  3985. this.submitButton = options.submitButton;
  3986. this.cancelButton = options.cancelButton;
  3987. this.overlayManager = overlayManager;
  3988. this.l10n = l10n;
  3989. this._isViewerEmbedded = isViewerEmbedded;
  3990. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3991. this.cancelButton.addEventListener("click", this.close.bind(this));
  3992. this.input.addEventListener("keydown", e => {
  3993. if (e.keyCode === 13) {
  3994. this.#verify();
  3995. }
  3996. });
  3997. this.overlayManager.register(this.dialog, true);
  3998. this.dialog.addEventListener("close", this.#cancel.bind(this));
  3999. }
  4000. async open() {
  4001. if (this.#activeCapability) {
  4002. await this.#activeCapability.promise;
  4003. }
  4004. this.#activeCapability = (0, _pdfjsLib.createPromiseCapability)();
  4005. try {
  4006. await this.overlayManager.open(this.dialog);
  4007. } catch (ex) {
  4008. this.#activeCapability = null;
  4009. throw ex;
  4010. }
  4011. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  4012. if (!this._isViewerEmbedded || passwordIncorrect) {
  4013. this.input.focus();
  4014. }
  4015. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  4016. }
  4017. async close() {
  4018. if (this.overlayManager.active === this.dialog) {
  4019. this.overlayManager.close(this.dialog);
  4020. }
  4021. }
  4022. #verify() {
  4023. const password = this.input.value;
  4024. if (password?.length > 0) {
  4025. this.#invokeCallback(password);
  4026. }
  4027. }
  4028. #cancel() {
  4029. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  4030. this.#activeCapability.resolve();
  4031. }
  4032. #invokeCallback(password) {
  4033. if (!this.#updateCallback) {
  4034. return;
  4035. }
  4036. this.close();
  4037. this.input.value = "";
  4038. this.#updateCallback(password);
  4039. this.#updateCallback = null;
  4040. }
  4041. async setUpdateCallback(updateCallback, reason) {
  4042. if (this.#activeCapability) {
  4043. await this.#activeCapability.promise;
  4044. }
  4045. this.#updateCallback = updateCallback;
  4046. this.#reason = reason;
  4047. }
  4048. }
  4049. exports.PasswordPrompt = PasswordPrompt;
  4050. /***/ }),
  4051. /* 12 */
  4052. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4053. Object.defineProperty(exports, "__esModule", ({
  4054. value: true
  4055. }));
  4056. exports.PDFAttachmentViewer = void 0;
  4057. var _pdfjsLib = __webpack_require__(5);
  4058. var _base_tree_viewer = __webpack_require__(13);
  4059. var _event_utils = __webpack_require__(6);
  4060. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4061. constructor(options) {
  4062. super(options);
  4063. this.downloadManager = options.downloadManager;
  4064. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  4065. }
  4066. reset(keepRenderedCapability = false) {
  4067. super.reset();
  4068. this._attachments = null;
  4069. if (!keepRenderedCapability) {
  4070. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4071. }
  4072. this._pendingDispatchEvent = false;
  4073. }
  4074. async _dispatchEvent(attachmentsCount) {
  4075. this._renderedCapability.resolve();
  4076. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4077. this._pendingDispatchEvent = true;
  4078. await (0, _event_utils.waitOnEventOrTimeout)({
  4079. target: this.eventBus,
  4080. name: "annotationlayerrendered",
  4081. delay: 1000
  4082. });
  4083. if (!this._pendingDispatchEvent) {
  4084. return;
  4085. }
  4086. }
  4087. this._pendingDispatchEvent = false;
  4088. this.eventBus.dispatch("attachmentsloaded", {
  4089. source: this,
  4090. attachmentsCount
  4091. });
  4092. }
  4093. _bindLink(element, {
  4094. content,
  4095. filename
  4096. }) {
  4097. element.onclick = () => {
  4098. this.downloadManager.openOrDownloadData(element, content, filename);
  4099. return false;
  4100. };
  4101. }
  4102. render({
  4103. attachments,
  4104. keepRenderedCapability = false
  4105. }) {
  4106. if (this._attachments) {
  4107. this.reset(keepRenderedCapability);
  4108. }
  4109. this._attachments = attachments || null;
  4110. if (!attachments) {
  4111. this._dispatchEvent(0);
  4112. return;
  4113. }
  4114. const names = Object.keys(attachments).sort(function (a, b) {
  4115. return a.toLowerCase().localeCompare(b.toLowerCase());
  4116. });
  4117. const fragment = document.createDocumentFragment();
  4118. let attachmentsCount = 0;
  4119. for (const name of names) {
  4120. const item = attachments[name];
  4121. const content = item.content,
  4122. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true);
  4123. const div = document.createElement("div");
  4124. div.className = "treeItem";
  4125. const element = document.createElement("a");
  4126. this._bindLink(element, {
  4127. content,
  4128. filename
  4129. });
  4130. element.textContent = this._normalizeTextContent(filename);
  4131. div.append(element);
  4132. fragment.append(div);
  4133. attachmentsCount++;
  4134. }
  4135. this._finishRendering(fragment, attachmentsCount);
  4136. }
  4137. #appendAttachment({
  4138. filename,
  4139. content
  4140. }) {
  4141. const renderedPromise = this._renderedCapability.promise;
  4142. renderedPromise.then(() => {
  4143. if (renderedPromise !== this._renderedCapability.promise) {
  4144. return;
  4145. }
  4146. const attachments = this._attachments || Object.create(null);
  4147. for (const name in attachments) {
  4148. if (filename === name) {
  4149. return;
  4150. }
  4151. }
  4152. attachments[filename] = {
  4153. filename,
  4154. content
  4155. };
  4156. this.render({
  4157. attachments,
  4158. keepRenderedCapability: true
  4159. });
  4160. });
  4161. }
  4162. }
  4163. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4164. /***/ }),
  4165. /* 13 */
  4166. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4167. Object.defineProperty(exports, "__esModule", ({
  4168. value: true
  4169. }));
  4170. exports.BaseTreeViewer = void 0;
  4171. var _ui_utils = __webpack_require__(1);
  4172. const TREEITEM_OFFSET_TOP = -100;
  4173. const TREEITEM_SELECTED_CLASS = "selected";
  4174. class BaseTreeViewer {
  4175. constructor(options) {
  4176. if (this.constructor === BaseTreeViewer) {
  4177. throw new Error("Cannot initialize BaseTreeViewer.");
  4178. }
  4179. this.container = options.container;
  4180. this.eventBus = options.eventBus;
  4181. this.reset();
  4182. }
  4183. reset() {
  4184. this._pdfDocument = null;
  4185. this._lastToggleIsShow = true;
  4186. this._currentTreeItem = null;
  4187. this.container.textContent = "";
  4188. this.container.classList.remove("treeWithDeepNesting");
  4189. }
  4190. _dispatchEvent(count) {
  4191. throw new Error("Not implemented: _dispatchEvent");
  4192. }
  4193. _bindLink(element, params) {
  4194. throw new Error("Not implemented: _bindLink");
  4195. }
  4196. _normalizeTextContent(str) {
  4197. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4198. }
  4199. _addToggleButton(div, hidden = false) {
  4200. const toggler = document.createElement("div");
  4201. toggler.className = "treeItemToggler";
  4202. if (hidden) {
  4203. toggler.classList.add("treeItemsHidden");
  4204. }
  4205. toggler.onclick = evt => {
  4206. evt.stopPropagation();
  4207. toggler.classList.toggle("treeItemsHidden");
  4208. if (evt.shiftKey) {
  4209. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4210. this._toggleTreeItem(div, shouldShowAll);
  4211. }
  4212. };
  4213. div.prepend(toggler);
  4214. }
  4215. _toggleTreeItem(root, show = false) {
  4216. this._lastToggleIsShow = show;
  4217. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4218. toggler.classList.toggle("treeItemsHidden", !show);
  4219. }
  4220. }
  4221. _toggleAllTreeItems() {
  4222. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4223. }
  4224. _finishRendering(fragment, count, hasAnyNesting = false) {
  4225. if (hasAnyNesting) {
  4226. this.container.classList.add("treeWithDeepNesting");
  4227. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4228. }
  4229. this.container.append(fragment);
  4230. this._dispatchEvent(count);
  4231. }
  4232. render(params) {
  4233. throw new Error("Not implemented: render");
  4234. }
  4235. _updateCurrentTreeItem(treeItem = null) {
  4236. if (this._currentTreeItem) {
  4237. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4238. this._currentTreeItem = null;
  4239. }
  4240. if (treeItem) {
  4241. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4242. this._currentTreeItem = treeItem;
  4243. }
  4244. }
  4245. _scrollToCurrentTreeItem(treeItem) {
  4246. if (!treeItem) {
  4247. return;
  4248. }
  4249. let currentNode = treeItem.parentNode;
  4250. while (currentNode && currentNode !== this.container) {
  4251. if (currentNode.classList.contains("treeItem")) {
  4252. const toggler = currentNode.firstElementChild;
  4253. toggler?.classList.remove("treeItemsHidden");
  4254. }
  4255. currentNode = currentNode.parentNode;
  4256. }
  4257. this._updateCurrentTreeItem(treeItem);
  4258. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4259. }
  4260. }
  4261. exports.BaseTreeViewer = BaseTreeViewer;
  4262. /***/ }),
  4263. /* 14 */
  4264. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4265. Object.defineProperty(exports, "__esModule", ({
  4266. value: true
  4267. }));
  4268. exports.PDFDocumentProperties = void 0;
  4269. var _pdfjsLib = __webpack_require__(5);
  4270. var _ui_utils = __webpack_require__(1);
  4271. const DEFAULT_FIELD_CONTENT = "-";
  4272. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4273. const US_PAGE_NAMES = {
  4274. "8.5x11": "Letter",
  4275. "8.5x14": "Legal"
  4276. };
  4277. const METRIC_PAGE_NAMES = {
  4278. "297x420": "A3",
  4279. "210x297": "A4"
  4280. };
  4281. function getPageName(size, isPortrait, pageNames) {
  4282. const width = isPortrait ? size.width : size.height;
  4283. const height = isPortrait ? size.height : size.width;
  4284. return pageNames[`${width}x${height}`];
  4285. }
  4286. class PDFDocumentProperties {
  4287. #fieldData = null;
  4288. constructor({
  4289. dialog,
  4290. fields,
  4291. closeButton
  4292. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4293. this.dialog = dialog;
  4294. this.fields = fields;
  4295. this.overlayManager = overlayManager;
  4296. this.l10n = l10n;
  4297. this._fileNameLookup = fileNameLookup;
  4298. this.#reset();
  4299. closeButton.addEventListener("click", this.close.bind(this));
  4300. this.overlayManager.register(this.dialog);
  4301. eventBus._on("pagechanging", evt => {
  4302. this._currentPageNumber = evt.pageNumber;
  4303. });
  4304. eventBus._on("rotationchanging", evt => {
  4305. this._pagesRotation = evt.pagesRotation;
  4306. });
  4307. this._isNonMetricLocale = true;
  4308. l10n.getLanguage().then(locale => {
  4309. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4310. });
  4311. }
  4312. async open() {
  4313. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4314. const currentPageNumber = this._currentPageNumber;
  4315. const pagesRotation = this._pagesRotation;
  4316. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4317. this.#updateUI();
  4318. return;
  4319. }
  4320. const {
  4321. info,
  4322. contentLength
  4323. } = await this.pdfDocument.getMetadata();
  4324. 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 => {
  4325. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4326. }), this.#parseLinearization(info.IsLinearized)]);
  4327. this.#fieldData = Object.freeze({
  4328. fileName,
  4329. fileSize,
  4330. title: info.Title,
  4331. author: info.Author,
  4332. subject: info.Subject,
  4333. keywords: info.Keywords,
  4334. creationDate,
  4335. modificationDate,
  4336. creator: info.Creator,
  4337. producer: info.Producer,
  4338. version: info.PDFFormatVersion,
  4339. pageCount: this.pdfDocument.numPages,
  4340. pageSize,
  4341. linearized: isLinearized,
  4342. _currentPageNumber: currentPageNumber,
  4343. _pagesRotation: pagesRotation
  4344. });
  4345. this.#updateUI();
  4346. const {
  4347. length
  4348. } = await this.pdfDocument.getDownloadInfo();
  4349. if (contentLength === length) {
  4350. return;
  4351. }
  4352. const data = Object.assign(Object.create(null), this.#fieldData);
  4353. data.fileSize = await this.#parseFileSize(length);
  4354. this.#fieldData = Object.freeze(data);
  4355. this.#updateUI();
  4356. }
  4357. async close() {
  4358. this.overlayManager.close(this.dialog);
  4359. }
  4360. setDocument(pdfDocument) {
  4361. if (this.pdfDocument) {
  4362. this.#reset();
  4363. this.#updateUI(true);
  4364. }
  4365. if (!pdfDocument) {
  4366. return;
  4367. }
  4368. this.pdfDocument = pdfDocument;
  4369. this._dataAvailableCapability.resolve();
  4370. }
  4371. #reset() {
  4372. this.pdfDocument = null;
  4373. this.#fieldData = null;
  4374. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4375. this._currentPageNumber = 1;
  4376. this._pagesRotation = 0;
  4377. }
  4378. #updateUI(reset = false) {
  4379. if (reset || !this.#fieldData) {
  4380. for (const id in this.fields) {
  4381. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4382. }
  4383. return;
  4384. }
  4385. if (this.overlayManager.active !== this.dialog) {
  4386. return;
  4387. }
  4388. for (const id in this.fields) {
  4389. const content = this.#fieldData[id];
  4390. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4391. }
  4392. }
  4393. async #parseFileSize(fileSize = 0) {
  4394. const kb = fileSize / 1024,
  4395. mb = kb / 1024;
  4396. if (!kb) {
  4397. return undefined;
  4398. }
  4399. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4400. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4401. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4402. size_b: fileSize.toLocaleString()
  4403. });
  4404. }
  4405. async #parsePageSize(pageSizeInches, pagesRotation) {
  4406. if (!pageSizeInches) {
  4407. return undefined;
  4408. }
  4409. if (pagesRotation % 180 !== 0) {
  4410. pageSizeInches = {
  4411. width: pageSizeInches.height,
  4412. height: pageSizeInches.width
  4413. };
  4414. }
  4415. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4416. let sizeInches = {
  4417. width: Math.round(pageSizeInches.width * 100) / 100,
  4418. height: Math.round(pageSizeInches.height * 100) / 100
  4419. };
  4420. let sizeMillimeters = {
  4421. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4422. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4423. };
  4424. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4425. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4426. const exactMillimeters = {
  4427. width: pageSizeInches.width * 25.4,
  4428. height: pageSizeInches.height * 25.4
  4429. };
  4430. const intMillimeters = {
  4431. width: Math.round(sizeMillimeters.width),
  4432. height: Math.round(sizeMillimeters.height)
  4433. };
  4434. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4435. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4436. if (rawName) {
  4437. sizeInches = {
  4438. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4439. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4440. };
  4441. sizeMillimeters = intMillimeters;
  4442. }
  4443. }
  4444. }
  4445. const [{
  4446. width,
  4447. height
  4448. }, 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"}`)]);
  4449. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4450. width: width.toLocaleString(),
  4451. height: height.toLocaleString(),
  4452. unit,
  4453. name,
  4454. orientation
  4455. });
  4456. }
  4457. async #parseDate(inputDate) {
  4458. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4459. if (!dateObject) {
  4460. return undefined;
  4461. }
  4462. return this.l10n.get("document_properties_date_string", {
  4463. date: dateObject.toLocaleDateString(),
  4464. time: dateObject.toLocaleTimeString()
  4465. });
  4466. }
  4467. #parseLinearization(isLinearized) {
  4468. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4469. }
  4470. }
  4471. exports.PDFDocumentProperties = PDFDocumentProperties;
  4472. /***/ }),
  4473. /* 15 */
  4474. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4475. Object.defineProperty(exports, "__esModule", ({
  4476. value: true
  4477. }));
  4478. exports.PDFFindBar = void 0;
  4479. var _pdf_find_controller = __webpack_require__(16);
  4480. const MATCHES_COUNT_LIMIT = 1000;
  4481. class PDFFindBar {
  4482. constructor(options, eventBus, l10n) {
  4483. this.opened = false;
  4484. this.bar = options.bar;
  4485. this.toggleButton = options.toggleButton;
  4486. this.findField = options.findField;
  4487. this.highlightAll = options.highlightAllCheckbox;
  4488. this.caseSensitive = options.caseSensitiveCheckbox;
  4489. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4490. this.entireWord = options.entireWordCheckbox;
  4491. this.findMsg = options.findMsg;
  4492. this.findResultsCount = options.findResultsCount;
  4493. this.findPreviousButton = options.findPreviousButton;
  4494. this.findNextButton = options.findNextButton;
  4495. this.eventBus = eventBus;
  4496. this.l10n = l10n;
  4497. this.toggleButton.addEventListener("click", () => {
  4498. this.toggle();
  4499. });
  4500. this.findField.addEventListener("input", () => {
  4501. this.dispatchEvent("");
  4502. });
  4503. this.bar.addEventListener("keydown", e => {
  4504. switch (e.keyCode) {
  4505. case 13:
  4506. if (e.target === this.findField) {
  4507. this.dispatchEvent("again", e.shiftKey);
  4508. }
  4509. break;
  4510. case 27:
  4511. this.close();
  4512. break;
  4513. }
  4514. });
  4515. this.findPreviousButton.addEventListener("click", () => {
  4516. this.dispatchEvent("again", true);
  4517. });
  4518. this.findNextButton.addEventListener("click", () => {
  4519. this.dispatchEvent("again", false);
  4520. });
  4521. this.highlightAll.addEventListener("click", () => {
  4522. this.dispatchEvent("highlightallchange");
  4523. });
  4524. this.caseSensitive.addEventListener("click", () => {
  4525. this.dispatchEvent("casesensitivitychange");
  4526. });
  4527. this.entireWord.addEventListener("click", () => {
  4528. this.dispatchEvent("entirewordchange");
  4529. });
  4530. this.matchDiacritics.addEventListener("click", () => {
  4531. this.dispatchEvent("diacriticmatchingchange");
  4532. });
  4533. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4534. }
  4535. reset() {
  4536. this.updateUIState();
  4537. }
  4538. dispatchEvent(type, findPrev = false) {
  4539. this.eventBus.dispatch("find", {
  4540. source: this,
  4541. type,
  4542. query: this.findField.value,
  4543. phraseSearch: true,
  4544. caseSensitive: this.caseSensitive.checked,
  4545. entireWord: this.entireWord.checked,
  4546. highlightAll: this.highlightAll.checked,
  4547. findPrevious: findPrev,
  4548. matchDiacritics: this.matchDiacritics.checked
  4549. });
  4550. }
  4551. updateUIState(state, previous, matchesCount) {
  4552. let findMsg = Promise.resolve("");
  4553. let status = "";
  4554. switch (state) {
  4555. case _pdf_find_controller.FindState.FOUND:
  4556. break;
  4557. case _pdf_find_controller.FindState.PENDING:
  4558. status = "pending";
  4559. break;
  4560. case _pdf_find_controller.FindState.NOT_FOUND:
  4561. findMsg = this.l10n.get("find_not_found");
  4562. status = "notFound";
  4563. break;
  4564. case _pdf_find_controller.FindState.WRAPPED:
  4565. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4566. break;
  4567. }
  4568. this.findField.setAttribute("data-status", status);
  4569. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4570. findMsg.then(msg => {
  4571. this.findMsg.textContent = msg;
  4572. this.#adjustWidth();
  4573. });
  4574. this.updateResultsCount(matchesCount);
  4575. }
  4576. updateResultsCount({
  4577. current = 0,
  4578. total = 0
  4579. } = {}) {
  4580. const limit = MATCHES_COUNT_LIMIT;
  4581. let matchCountMsg = Promise.resolve("");
  4582. if (total > 0) {
  4583. if (total > limit) {
  4584. let key = "find_match_count_limit";
  4585. matchCountMsg = this.l10n.get(key, {
  4586. limit
  4587. });
  4588. } else {
  4589. let key = "find_match_count";
  4590. matchCountMsg = this.l10n.get(key, {
  4591. current,
  4592. total
  4593. });
  4594. }
  4595. }
  4596. matchCountMsg.then(msg => {
  4597. this.findResultsCount.textContent = msg;
  4598. this.#adjustWidth();
  4599. });
  4600. }
  4601. open() {
  4602. if (!this.opened) {
  4603. this.opened = true;
  4604. this.toggleButton.classList.add("toggled");
  4605. this.toggleButton.setAttribute("aria-expanded", "true");
  4606. this.bar.classList.remove("hidden");
  4607. }
  4608. this.findField.select();
  4609. this.findField.focus();
  4610. this.#adjustWidth();
  4611. }
  4612. close() {
  4613. if (!this.opened) {
  4614. return;
  4615. }
  4616. this.opened = false;
  4617. this.toggleButton.classList.remove("toggled");
  4618. this.toggleButton.setAttribute("aria-expanded", "false");
  4619. this.bar.classList.add("hidden");
  4620. this.eventBus.dispatch("findbarclose", {
  4621. source: this
  4622. });
  4623. }
  4624. toggle() {
  4625. if (this.opened) {
  4626. this.close();
  4627. } else {
  4628. this.open();
  4629. }
  4630. }
  4631. #adjustWidth() {
  4632. if (!this.opened) {
  4633. return;
  4634. }
  4635. this.bar.classList.remove("wrapContainers");
  4636. const findbarHeight = this.bar.clientHeight;
  4637. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4638. if (findbarHeight > inputContainerHeight) {
  4639. this.bar.classList.add("wrapContainers");
  4640. }
  4641. }
  4642. }
  4643. exports.PDFFindBar = PDFFindBar;
  4644. /***/ }),
  4645. /* 16 */
  4646. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4647. Object.defineProperty(exports, "__esModule", ({
  4648. value: true
  4649. }));
  4650. exports.PDFFindController = exports.FindState = void 0;
  4651. var _ui_utils = __webpack_require__(1);
  4652. var _pdfjsLib = __webpack_require__(5);
  4653. var _pdf_find_utils = __webpack_require__(17);
  4654. const FindState = {
  4655. FOUND: 0,
  4656. NOT_FOUND: 1,
  4657. WRAPPED: 2,
  4658. PENDING: 3
  4659. };
  4660. exports.FindState = FindState;
  4661. const FIND_TIMEOUT = 250;
  4662. const MATCH_SCROLL_OFFSET_TOP = -50;
  4663. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4664. const CHARACTERS_TO_NORMALIZE = {
  4665. "\u2010": "-",
  4666. "\u2018": "'",
  4667. "\u2019": "'",
  4668. "\u201A": "'",
  4669. "\u201B": "'",
  4670. "\u201C": '"',
  4671. "\u201D": '"',
  4672. "\u201E": '"',
  4673. "\u201F": '"',
  4674. "\u00BC": "1/4",
  4675. "\u00BD": "1/2",
  4676. "\u00BE": "3/4"
  4677. };
  4678. 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]);
  4679. let DIACRITICS_EXCEPTION_STR;
  4680. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4681. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4682. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4683. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4684. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4685. const SYLLABLES_LENGTHS = new Map();
  4686. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4687. const NFKC_CHARS_TO_NORMALIZE = new Map();
  4688. let noSyllablesRegExp = null;
  4689. let withSyllablesRegExp = null;
  4690. function normalize(text) {
  4691. const syllablePositions = [];
  4692. let m;
  4693. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4694. let {
  4695. index
  4696. } = m;
  4697. for (const char of m[0]) {
  4698. let len = SYLLABLES_LENGTHS.get(char);
  4699. if (!len) {
  4700. len = char.normalize("NFD").length;
  4701. SYLLABLES_LENGTHS.set(char, len);
  4702. }
  4703. syllablePositions.push([len, index++]);
  4704. }
  4705. }
  4706. let normalizationRegex;
  4707. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4708. normalizationRegex = noSyllablesRegExp;
  4709. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4710. normalizationRegex = withSyllablesRegExp;
  4711. } else {
  4712. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4713. const toNormalizeWithNFKC = "\u2460-\u2473" + "\u24b6-\u24ff" + "\u3244-\u32bf" + "\u32d0-\u32fe" + "\uff00-\uffef";
  4714. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(\\p{Ideographic}\\n)|(\\n)`;
  4715. if (syllablePositions.length === 0) {
  4716. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4717. } else {
  4718. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4719. }
  4720. }
  4721. const rawDiacriticsPositions = [];
  4722. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4723. rawDiacriticsPositions.push([m[0].length, m.index]);
  4724. }
  4725. let normalized = text.normalize("NFD");
  4726. const positions = [[0, 0]];
  4727. let rawDiacriticsIndex = 0;
  4728. let syllableIndex = 0;
  4729. let shift = 0;
  4730. let shiftOrigin = 0;
  4731. let eol = 0;
  4732. let hasDiacritics = false;
  4733. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, i) => {
  4734. i -= shiftOrigin;
  4735. if (p1) {
  4736. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  4737. const jj = replacement.length;
  4738. for (let j = 1; j < jj; j++) {
  4739. positions.push([i - shift + j, shift - j]);
  4740. }
  4741. shift -= jj - 1;
  4742. return replacement;
  4743. }
  4744. if (p2) {
  4745. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  4746. if (!replacement) {
  4747. replacement = p2.normalize("NFKC");
  4748. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  4749. }
  4750. const jj = replacement.length;
  4751. for (let j = 1; j < jj; j++) {
  4752. positions.push([i - shift + j, shift - j]);
  4753. }
  4754. shift -= jj - 1;
  4755. return replacement;
  4756. }
  4757. if (p3) {
  4758. const hasTrailingDashEOL = p3.endsWith("\n");
  4759. const len = hasTrailingDashEOL ? p3.length - 2 : p3.length;
  4760. hasDiacritics = true;
  4761. let jj = len;
  4762. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4763. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4764. ++rawDiacriticsIndex;
  4765. }
  4766. for (let j = 1; j <= jj; j++) {
  4767. positions.push([i - 1 - shift + j, shift - j]);
  4768. }
  4769. shift -= jj;
  4770. shiftOrigin += jj;
  4771. if (hasTrailingDashEOL) {
  4772. i += len - 1;
  4773. positions.push([i - shift + 1, 1 + shift]);
  4774. shift += 1;
  4775. shiftOrigin += 1;
  4776. eol += 1;
  4777. return p3.slice(0, len);
  4778. }
  4779. return p3;
  4780. }
  4781. if (p4) {
  4782. positions.push([i - shift + 1, 1 + shift]);
  4783. shift += 1;
  4784. shiftOrigin += 1;
  4785. eol += 1;
  4786. return p4.charAt(0);
  4787. }
  4788. if (p5) {
  4789. positions.push([i - shift + 1, shift]);
  4790. shiftOrigin += 1;
  4791. eol += 1;
  4792. return p5.charAt(0);
  4793. }
  4794. if (p6) {
  4795. positions.push([i - shift + 1, shift - 1]);
  4796. shift -= 1;
  4797. shiftOrigin += 1;
  4798. eol += 1;
  4799. return " ";
  4800. }
  4801. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  4802. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  4803. ++syllableIndex;
  4804. for (let j = 1; j <= newCharLen; j++) {
  4805. positions.push([i - (shift - j), shift - j]);
  4806. }
  4807. shift -= newCharLen;
  4808. shiftOrigin += newCharLen;
  4809. }
  4810. return p7;
  4811. });
  4812. positions.push([normalized.length, shift]);
  4813. return [normalized, positions, hasDiacritics];
  4814. }
  4815. function getOriginalIndex(diffs, pos, len) {
  4816. if (!diffs) {
  4817. return [pos, len];
  4818. }
  4819. const start = pos;
  4820. const end = pos + len;
  4821. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  4822. if (diffs[i][0] > start) {
  4823. --i;
  4824. }
  4825. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  4826. if (diffs[j][0] > end) {
  4827. --j;
  4828. }
  4829. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  4830. }
  4831. class PDFFindController {
  4832. constructor({
  4833. linkService,
  4834. eventBus
  4835. }) {
  4836. this._linkService = linkService;
  4837. this._eventBus = eventBus;
  4838. this.#reset();
  4839. eventBus._on("find", this.#onFind.bind(this));
  4840. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  4841. }
  4842. get highlightMatches() {
  4843. return this._highlightMatches;
  4844. }
  4845. get pageMatches() {
  4846. return this._pageMatches;
  4847. }
  4848. get pageMatchesLength() {
  4849. return this._pageMatchesLength;
  4850. }
  4851. get selected() {
  4852. return this._selected;
  4853. }
  4854. get state() {
  4855. return this._state;
  4856. }
  4857. setDocument(pdfDocument) {
  4858. if (this._pdfDocument) {
  4859. this.#reset();
  4860. }
  4861. if (!pdfDocument) {
  4862. return;
  4863. }
  4864. this._pdfDocument = pdfDocument;
  4865. this._firstPageCapability.resolve();
  4866. }
  4867. #onFind(state) {
  4868. if (!state) {
  4869. return;
  4870. }
  4871. const pdfDocument = this._pdfDocument;
  4872. const {
  4873. type
  4874. } = state;
  4875. if (this._state === null || this.#shouldDirtyMatch(state)) {
  4876. this._dirtyMatch = true;
  4877. }
  4878. this._state = state;
  4879. if (type !== "highlightallchange") {
  4880. this.#updateUIState(FindState.PENDING);
  4881. }
  4882. this._firstPageCapability.promise.then(() => {
  4883. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4884. return;
  4885. }
  4886. this.#extractText();
  4887. const findbarClosed = !this._highlightMatches;
  4888. const pendingTimeout = !!this._findTimeout;
  4889. if (this._findTimeout) {
  4890. clearTimeout(this._findTimeout);
  4891. this._findTimeout = null;
  4892. }
  4893. if (!type) {
  4894. this._findTimeout = setTimeout(() => {
  4895. this.#nextMatch();
  4896. this._findTimeout = null;
  4897. }, FIND_TIMEOUT);
  4898. } else if (this._dirtyMatch) {
  4899. this.#nextMatch();
  4900. } else if (type === "again") {
  4901. this.#nextMatch();
  4902. if (findbarClosed && this._state.highlightAll) {
  4903. this.#updateAllPages();
  4904. }
  4905. } else if (type === "highlightallchange") {
  4906. if (pendingTimeout) {
  4907. this.#nextMatch();
  4908. } else {
  4909. this._highlightMatches = true;
  4910. }
  4911. this.#updateAllPages();
  4912. } else {
  4913. this.#nextMatch();
  4914. }
  4915. });
  4916. }
  4917. scrollMatchIntoView({
  4918. element = null,
  4919. selectedLeft = 0,
  4920. pageIndex = -1,
  4921. matchIndex = -1
  4922. }) {
  4923. if (!this._scrollMatches || !element) {
  4924. return;
  4925. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4926. return;
  4927. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4928. return;
  4929. }
  4930. this._scrollMatches = false;
  4931. const spot = {
  4932. top: MATCH_SCROLL_OFFSET_TOP,
  4933. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  4934. };
  4935. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4936. }
  4937. #reset() {
  4938. this._highlightMatches = false;
  4939. this._scrollMatches = false;
  4940. this._pdfDocument = null;
  4941. this._pageMatches = [];
  4942. this._pageMatchesLength = [];
  4943. this._state = null;
  4944. this._selected = {
  4945. pageIdx: -1,
  4946. matchIdx: -1
  4947. };
  4948. this._offset = {
  4949. pageIdx: null,
  4950. matchIdx: null,
  4951. wrapped: false
  4952. };
  4953. this._extractTextPromises = [];
  4954. this._pageContents = [];
  4955. this._pageDiffs = [];
  4956. this._hasDiacritics = [];
  4957. this._matchesCountTotal = 0;
  4958. this._pagesToSearch = null;
  4959. this._pendingFindMatches = new Set();
  4960. this._resumePageIdx = null;
  4961. this._dirtyMatch = false;
  4962. clearTimeout(this._findTimeout);
  4963. this._findTimeout = null;
  4964. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4965. }
  4966. get #query() {
  4967. if (this._state.query !== this._rawQuery) {
  4968. this._rawQuery = this._state.query;
  4969. [this._normalizedQuery] = normalize(this._state.query);
  4970. }
  4971. return this._normalizedQuery;
  4972. }
  4973. #shouldDirtyMatch(state) {
  4974. if (state.query !== this._state.query) {
  4975. return true;
  4976. }
  4977. switch (state.type) {
  4978. case "again":
  4979. const pageNumber = this._selected.pageIdx + 1;
  4980. const linkService = this._linkService;
  4981. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4982. return true;
  4983. }
  4984. return false;
  4985. case "highlightallchange":
  4986. return false;
  4987. }
  4988. return true;
  4989. }
  4990. #isEntireWord(content, startIdx, length) {
  4991. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  4992. if (match) {
  4993. const first = content.charCodeAt(startIdx);
  4994. const limit = match[1].charCodeAt(0);
  4995. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4996. return false;
  4997. }
  4998. }
  4999. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  5000. if (match) {
  5001. const last = content.charCodeAt(startIdx + length - 1);
  5002. const limit = match[1].charCodeAt(0);
  5003. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5004. return false;
  5005. }
  5006. }
  5007. return true;
  5008. }
  5009. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  5010. const matches = [],
  5011. matchesLength = [];
  5012. const diffs = this._pageDiffs[pageIndex];
  5013. let match;
  5014. while ((match = query.exec(pageContent)) !== null) {
  5015. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  5016. continue;
  5017. }
  5018. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  5019. if (matchLen) {
  5020. matches.push(matchPos);
  5021. matchesLength.push(matchLen);
  5022. }
  5023. }
  5024. this._pageMatches[pageIndex] = matches;
  5025. this._pageMatchesLength[pageIndex] = matchesLength;
  5026. }
  5027. #convertToRegExpString(query, hasDiacritics) {
  5028. const {
  5029. matchDiacritics
  5030. } = this._state;
  5031. let isUnicode = false;
  5032. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5033. if (p1) {
  5034. return `[ ]*\\${p1}[ ]*`;
  5035. }
  5036. if (p2) {
  5037. return `[ ]*${p2}[ ]*`;
  5038. }
  5039. if (p3) {
  5040. return "[ ]+";
  5041. }
  5042. if (matchDiacritics) {
  5043. return p4 || p5;
  5044. }
  5045. if (p4) {
  5046. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5047. }
  5048. if (hasDiacritics) {
  5049. isUnicode = true;
  5050. return `${p5}\\p{M}*`;
  5051. }
  5052. return p5;
  5053. });
  5054. const trailingSpaces = "[ ]*";
  5055. if (query.endsWith(trailingSpaces)) {
  5056. query = query.slice(0, query.length - trailingSpaces.length);
  5057. }
  5058. if (matchDiacritics) {
  5059. if (hasDiacritics) {
  5060. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
  5061. isUnicode = true;
  5062. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5063. }
  5064. }
  5065. return [isUnicode, query];
  5066. }
  5067. #calculateMatch(pageIndex) {
  5068. let query = this.#query;
  5069. if (query.length === 0) {
  5070. return;
  5071. }
  5072. const {
  5073. caseSensitive,
  5074. entireWord,
  5075. phraseSearch
  5076. } = this._state;
  5077. const pageContent = this._pageContents[pageIndex];
  5078. const hasDiacritics = this._hasDiacritics[pageIndex];
  5079. let isUnicode = false;
  5080. if (phraseSearch) {
  5081. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5082. } else {
  5083. const match = query.match(/\S+/g);
  5084. if (match) {
  5085. query = match.sort().reverse().map(q => {
  5086. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5087. isUnicode ||= isUnicodePart;
  5088. return `(${queryPart})`;
  5089. }).join("|");
  5090. }
  5091. }
  5092. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5093. query = new RegExp(query, flags);
  5094. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  5095. if (this._state.highlightAll) {
  5096. this.#updatePage(pageIndex);
  5097. }
  5098. if (this._resumePageIdx === pageIndex) {
  5099. this._resumePageIdx = null;
  5100. this.#nextPageMatch();
  5101. }
  5102. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5103. if (pageMatchesCount > 0) {
  5104. this._matchesCountTotal += pageMatchesCount;
  5105. this.#updateUIResultsCount();
  5106. }
  5107. }
  5108. #extractText() {
  5109. if (this._extractTextPromises.length > 0) {
  5110. return;
  5111. }
  5112. let promise = Promise.resolve();
  5113. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5114. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  5115. this._extractTextPromises[i] = extractTextCapability.promise;
  5116. promise = promise.then(() => {
  5117. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5118. return pdfPage.getTextContent();
  5119. }).then(textContent => {
  5120. const strBuf = [];
  5121. for (const textItem of textContent.items) {
  5122. strBuf.push(textItem.str);
  5123. if (textItem.hasEOL) {
  5124. strBuf.push("\n");
  5125. }
  5126. }
  5127. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5128. extractTextCapability.resolve();
  5129. }, reason => {
  5130. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5131. this._pageContents[i] = "";
  5132. this._pageDiffs[i] = null;
  5133. this._hasDiacritics[i] = false;
  5134. extractTextCapability.resolve();
  5135. });
  5136. });
  5137. }
  5138. }
  5139. #updatePage(index) {
  5140. if (this._scrollMatches && this._selected.pageIdx === index) {
  5141. this._linkService.page = index + 1;
  5142. }
  5143. this._eventBus.dispatch("updatetextlayermatches", {
  5144. source: this,
  5145. pageIndex: index
  5146. });
  5147. }
  5148. #updateAllPages() {
  5149. this._eventBus.dispatch("updatetextlayermatches", {
  5150. source: this,
  5151. pageIndex: -1
  5152. });
  5153. }
  5154. #nextMatch() {
  5155. const previous = this._state.findPrevious;
  5156. const currentPageIndex = this._linkService.page - 1;
  5157. const numPages = this._linkService.pagesCount;
  5158. this._highlightMatches = true;
  5159. if (this._dirtyMatch) {
  5160. this._dirtyMatch = false;
  5161. this._selected.pageIdx = this._selected.matchIdx = -1;
  5162. this._offset.pageIdx = currentPageIndex;
  5163. this._offset.matchIdx = null;
  5164. this._offset.wrapped = false;
  5165. this._resumePageIdx = null;
  5166. this._pageMatches.length = 0;
  5167. this._pageMatchesLength.length = 0;
  5168. this._matchesCountTotal = 0;
  5169. this.#updateAllPages();
  5170. for (let i = 0; i < numPages; i++) {
  5171. if (this._pendingFindMatches.has(i)) {
  5172. continue;
  5173. }
  5174. this._pendingFindMatches.add(i);
  5175. this._extractTextPromises[i].then(() => {
  5176. this._pendingFindMatches.delete(i);
  5177. this.#calculateMatch(i);
  5178. });
  5179. }
  5180. }
  5181. if (this.#query === "") {
  5182. this.#updateUIState(FindState.FOUND);
  5183. return;
  5184. }
  5185. if (this._resumePageIdx) {
  5186. return;
  5187. }
  5188. const offset = this._offset;
  5189. this._pagesToSearch = numPages;
  5190. if (offset.matchIdx !== null) {
  5191. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5192. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5193. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5194. this.#updateMatch(true);
  5195. return;
  5196. }
  5197. this.#advanceOffsetPage(previous);
  5198. }
  5199. this.#nextPageMatch();
  5200. }
  5201. #matchesReady(matches) {
  5202. const offset = this._offset;
  5203. const numMatches = matches.length;
  5204. const previous = this._state.findPrevious;
  5205. if (numMatches) {
  5206. offset.matchIdx = previous ? numMatches - 1 : 0;
  5207. this.#updateMatch(true);
  5208. return true;
  5209. }
  5210. this.#advanceOffsetPage(previous);
  5211. if (offset.wrapped) {
  5212. offset.matchIdx = null;
  5213. if (this._pagesToSearch < 0) {
  5214. this.#updateMatch(false);
  5215. return true;
  5216. }
  5217. }
  5218. return false;
  5219. }
  5220. #nextPageMatch() {
  5221. if (this._resumePageIdx !== null) {
  5222. console.error("There can only be one pending page.");
  5223. }
  5224. let matches = null;
  5225. do {
  5226. const pageIdx = this._offset.pageIdx;
  5227. matches = this._pageMatches[pageIdx];
  5228. if (!matches) {
  5229. this._resumePageIdx = pageIdx;
  5230. break;
  5231. }
  5232. } while (!this.#matchesReady(matches));
  5233. }
  5234. #advanceOffsetPage(previous) {
  5235. const offset = this._offset;
  5236. const numPages = this._linkService.pagesCount;
  5237. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5238. offset.matchIdx = null;
  5239. this._pagesToSearch--;
  5240. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5241. offset.pageIdx = previous ? numPages - 1 : 0;
  5242. offset.wrapped = true;
  5243. }
  5244. }
  5245. #updateMatch(found = false) {
  5246. let state = FindState.NOT_FOUND;
  5247. const wrapped = this._offset.wrapped;
  5248. this._offset.wrapped = false;
  5249. if (found) {
  5250. const previousPage = this._selected.pageIdx;
  5251. this._selected.pageIdx = this._offset.pageIdx;
  5252. this._selected.matchIdx = this._offset.matchIdx;
  5253. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5254. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5255. this.#updatePage(previousPage);
  5256. }
  5257. }
  5258. this.#updateUIState(state, this._state.findPrevious);
  5259. if (this._selected.pageIdx !== -1) {
  5260. this._scrollMatches = true;
  5261. this.#updatePage(this._selected.pageIdx);
  5262. }
  5263. }
  5264. #onFindBarClose(evt) {
  5265. const pdfDocument = this._pdfDocument;
  5266. this._firstPageCapability.promise.then(() => {
  5267. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5268. return;
  5269. }
  5270. if (this._findTimeout) {
  5271. clearTimeout(this._findTimeout);
  5272. this._findTimeout = null;
  5273. }
  5274. if (this._resumePageIdx) {
  5275. this._resumePageIdx = null;
  5276. this._dirtyMatch = true;
  5277. }
  5278. this.#updateUIState(FindState.FOUND);
  5279. this._highlightMatches = false;
  5280. this.#updateAllPages();
  5281. });
  5282. }
  5283. #requestMatchesCount() {
  5284. const {
  5285. pageIdx,
  5286. matchIdx
  5287. } = this._selected;
  5288. let current = 0,
  5289. total = this._matchesCountTotal;
  5290. if (matchIdx !== -1) {
  5291. for (let i = 0; i < pageIdx; i++) {
  5292. current += this._pageMatches[i]?.length || 0;
  5293. }
  5294. current += matchIdx + 1;
  5295. }
  5296. if (current < 1 || current > total) {
  5297. current = total = 0;
  5298. }
  5299. return {
  5300. current,
  5301. total
  5302. };
  5303. }
  5304. #updateUIResultsCount() {
  5305. this._eventBus.dispatch("updatefindmatchescount", {
  5306. source: this,
  5307. matchesCount: this.#requestMatchesCount()
  5308. });
  5309. }
  5310. #updateUIState(state, previous = false) {
  5311. this._eventBus.dispatch("updatefindcontrolstate", {
  5312. source: this,
  5313. state,
  5314. previous,
  5315. matchesCount: this.#requestMatchesCount(),
  5316. rawQuery: this._state?.query ?? null
  5317. });
  5318. }
  5319. }
  5320. exports.PDFFindController = PDFFindController;
  5321. /***/ }),
  5322. /* 17 */
  5323. /***/ ((__unused_webpack_module, exports) => {
  5324. Object.defineProperty(exports, "__esModule", ({
  5325. value: true
  5326. }));
  5327. exports.CharacterType = void 0;
  5328. exports.getCharacterType = getCharacterType;
  5329. const CharacterType = {
  5330. SPACE: 0,
  5331. ALPHA_LETTER: 1,
  5332. PUNCT: 2,
  5333. HAN_LETTER: 3,
  5334. KATAKANA_LETTER: 4,
  5335. HIRAGANA_LETTER: 5,
  5336. HALFWIDTH_KATAKANA_LETTER: 6,
  5337. THAI_LETTER: 7
  5338. };
  5339. exports.CharacterType = CharacterType;
  5340. function isAlphabeticalScript(charCode) {
  5341. return charCode < 0x2e80;
  5342. }
  5343. function isAscii(charCode) {
  5344. return (charCode & 0xff80) === 0;
  5345. }
  5346. function isAsciiAlpha(charCode) {
  5347. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5348. }
  5349. function isAsciiDigit(charCode) {
  5350. return charCode >= 0x30 && charCode <= 0x39;
  5351. }
  5352. function isAsciiSpace(charCode) {
  5353. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5354. }
  5355. function isHan(charCode) {
  5356. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5357. }
  5358. function isKatakana(charCode) {
  5359. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5360. }
  5361. function isHiragana(charCode) {
  5362. return charCode >= 0x3040 && charCode <= 0x309f;
  5363. }
  5364. function isHalfwidthKatakana(charCode) {
  5365. return charCode >= 0xff60 && charCode <= 0xff9f;
  5366. }
  5367. function isThai(charCode) {
  5368. return (charCode & 0xff80) === 0x0e00;
  5369. }
  5370. function getCharacterType(charCode) {
  5371. if (isAlphabeticalScript(charCode)) {
  5372. if (isAscii(charCode)) {
  5373. if (isAsciiSpace(charCode)) {
  5374. return CharacterType.SPACE;
  5375. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5376. return CharacterType.ALPHA_LETTER;
  5377. }
  5378. return CharacterType.PUNCT;
  5379. } else if (isThai(charCode)) {
  5380. return CharacterType.THAI_LETTER;
  5381. } else if (charCode === 0xa0) {
  5382. return CharacterType.SPACE;
  5383. }
  5384. return CharacterType.ALPHA_LETTER;
  5385. }
  5386. if (isHan(charCode)) {
  5387. return CharacterType.HAN_LETTER;
  5388. } else if (isKatakana(charCode)) {
  5389. return CharacterType.KATAKANA_LETTER;
  5390. } else if (isHiragana(charCode)) {
  5391. return CharacterType.HIRAGANA_LETTER;
  5392. } else if (isHalfwidthKatakana(charCode)) {
  5393. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5394. }
  5395. return CharacterType.ALPHA_LETTER;
  5396. }
  5397. /***/ }),
  5398. /* 18 */
  5399. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5400. Object.defineProperty(exports, "__esModule", ({
  5401. value: true
  5402. }));
  5403. exports.PDFHistory = void 0;
  5404. exports.isDestArraysEqual = isDestArraysEqual;
  5405. exports.isDestHashesEqual = isDestHashesEqual;
  5406. var _ui_utils = __webpack_require__(1);
  5407. var _event_utils = __webpack_require__(6);
  5408. const HASH_CHANGE_TIMEOUT = 1000;
  5409. const POSITION_UPDATED_THRESHOLD = 50;
  5410. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5411. function getCurrentHash() {
  5412. return document.location.hash;
  5413. }
  5414. class PDFHistory {
  5415. constructor({
  5416. linkService,
  5417. eventBus
  5418. }) {
  5419. this.linkService = linkService;
  5420. this.eventBus = eventBus;
  5421. this._initialized = false;
  5422. this._fingerprint = "";
  5423. this.reset();
  5424. this._boundEvents = null;
  5425. this.eventBus._on("pagesinit", () => {
  5426. this._isPagesLoaded = false;
  5427. this.eventBus._on("pagesloaded", evt => {
  5428. this._isPagesLoaded = !!evt.pagesCount;
  5429. }, {
  5430. once: true
  5431. });
  5432. });
  5433. }
  5434. initialize({
  5435. fingerprint,
  5436. resetHistory = false,
  5437. updateUrl = false
  5438. }) {
  5439. if (!fingerprint || typeof fingerprint !== "string") {
  5440. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5441. return;
  5442. }
  5443. if (this._initialized) {
  5444. this.reset();
  5445. }
  5446. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5447. this._fingerprint = fingerprint;
  5448. this._updateUrl = updateUrl === true;
  5449. this._initialized = true;
  5450. this._bindEvents();
  5451. const state = window.history.state;
  5452. this._popStateInProgress = false;
  5453. this._blockHashChange = 0;
  5454. this._currentHash = getCurrentHash();
  5455. this._numPositionUpdates = 0;
  5456. this._uid = this._maxUid = 0;
  5457. this._destination = null;
  5458. this._position = null;
  5459. if (!this._isValidState(state, true) || resetHistory) {
  5460. const {
  5461. hash,
  5462. page,
  5463. rotation
  5464. } = this._parseCurrentHash(true);
  5465. if (!hash || reInitialized || resetHistory) {
  5466. this._pushOrReplaceState(null, true);
  5467. return;
  5468. }
  5469. this._pushOrReplaceState({
  5470. hash,
  5471. page,
  5472. rotation
  5473. }, true);
  5474. return;
  5475. }
  5476. const destination = state.destination;
  5477. this._updateInternalState(destination, state.uid, true);
  5478. if (destination.rotation !== undefined) {
  5479. this._initialRotation = destination.rotation;
  5480. }
  5481. if (destination.dest) {
  5482. this._initialBookmark = JSON.stringify(destination.dest);
  5483. this._destination.page = null;
  5484. } else if (destination.hash) {
  5485. this._initialBookmark = destination.hash;
  5486. } else if (destination.page) {
  5487. this._initialBookmark = `page=${destination.page}`;
  5488. }
  5489. }
  5490. reset() {
  5491. if (this._initialized) {
  5492. this._pageHide();
  5493. this._initialized = false;
  5494. this._unbindEvents();
  5495. }
  5496. if (this._updateViewareaTimeout) {
  5497. clearTimeout(this._updateViewareaTimeout);
  5498. this._updateViewareaTimeout = null;
  5499. }
  5500. this._initialBookmark = null;
  5501. this._initialRotation = null;
  5502. }
  5503. push({
  5504. namedDest = null,
  5505. explicitDest,
  5506. pageNumber
  5507. }) {
  5508. if (!this._initialized) {
  5509. return;
  5510. }
  5511. if (namedDest && typeof namedDest !== "string") {
  5512. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5513. return;
  5514. } else if (!Array.isArray(explicitDest)) {
  5515. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5516. return;
  5517. } else if (!this._isValidPage(pageNumber)) {
  5518. if (pageNumber !== null || this._destination) {
  5519. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5520. return;
  5521. }
  5522. }
  5523. const hash = namedDest || JSON.stringify(explicitDest);
  5524. if (!hash) {
  5525. return;
  5526. }
  5527. let forceReplace = false;
  5528. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5529. if (this._destination.page) {
  5530. return;
  5531. }
  5532. forceReplace = true;
  5533. }
  5534. if (this._popStateInProgress && !forceReplace) {
  5535. return;
  5536. }
  5537. this._pushOrReplaceState({
  5538. dest: explicitDest,
  5539. hash,
  5540. page: pageNumber,
  5541. rotation: this.linkService.rotation
  5542. }, forceReplace);
  5543. if (!this._popStateInProgress) {
  5544. this._popStateInProgress = true;
  5545. Promise.resolve().then(() => {
  5546. this._popStateInProgress = false;
  5547. });
  5548. }
  5549. }
  5550. pushPage(pageNumber) {
  5551. if (!this._initialized) {
  5552. return;
  5553. }
  5554. if (!this._isValidPage(pageNumber)) {
  5555. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5556. return;
  5557. }
  5558. if (this._destination?.page === pageNumber) {
  5559. return;
  5560. }
  5561. if (this._popStateInProgress) {
  5562. return;
  5563. }
  5564. this._pushOrReplaceState({
  5565. dest: null,
  5566. hash: `page=${pageNumber}`,
  5567. page: pageNumber,
  5568. rotation: this.linkService.rotation
  5569. });
  5570. if (!this._popStateInProgress) {
  5571. this._popStateInProgress = true;
  5572. Promise.resolve().then(() => {
  5573. this._popStateInProgress = false;
  5574. });
  5575. }
  5576. }
  5577. pushCurrentPosition() {
  5578. if (!this._initialized || this._popStateInProgress) {
  5579. return;
  5580. }
  5581. this._tryPushCurrentPosition();
  5582. }
  5583. back() {
  5584. if (!this._initialized || this._popStateInProgress) {
  5585. return;
  5586. }
  5587. const state = window.history.state;
  5588. if (this._isValidState(state) && state.uid > 0) {
  5589. window.history.back();
  5590. }
  5591. }
  5592. forward() {
  5593. if (!this._initialized || this._popStateInProgress) {
  5594. return;
  5595. }
  5596. const state = window.history.state;
  5597. if (this._isValidState(state) && state.uid < this._maxUid) {
  5598. window.history.forward();
  5599. }
  5600. }
  5601. get popStateInProgress() {
  5602. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5603. }
  5604. get initialBookmark() {
  5605. return this._initialized ? this._initialBookmark : null;
  5606. }
  5607. get initialRotation() {
  5608. return this._initialized ? this._initialRotation : null;
  5609. }
  5610. _pushOrReplaceState(destination, forceReplace = false) {
  5611. const shouldReplace = forceReplace || !this._destination;
  5612. const newState = {
  5613. fingerprint: this._fingerprint,
  5614. uid: shouldReplace ? this._uid : this._uid + 1,
  5615. destination
  5616. };
  5617. this._updateInternalState(destination, newState.uid);
  5618. let newUrl;
  5619. if (this._updateUrl && destination?.hash) {
  5620. const baseUrl = document.location.href.split("#")[0];
  5621. if (!baseUrl.startsWith("file://")) {
  5622. newUrl = `${baseUrl}#${destination.hash}`;
  5623. }
  5624. }
  5625. if (shouldReplace) {
  5626. window.history.replaceState(newState, "", newUrl);
  5627. } else {
  5628. window.history.pushState(newState, "", newUrl);
  5629. }
  5630. }
  5631. _tryPushCurrentPosition(temporary = false) {
  5632. if (!this._position) {
  5633. return;
  5634. }
  5635. let position = this._position;
  5636. if (temporary) {
  5637. position = Object.assign(Object.create(null), this._position);
  5638. position.temporary = true;
  5639. }
  5640. if (!this._destination) {
  5641. this._pushOrReplaceState(position);
  5642. return;
  5643. }
  5644. if (this._destination.temporary) {
  5645. this._pushOrReplaceState(position, true);
  5646. return;
  5647. }
  5648. if (this._destination.hash === position.hash) {
  5649. return;
  5650. }
  5651. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5652. return;
  5653. }
  5654. let forceReplace = false;
  5655. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5656. if (this._destination.dest !== undefined || !this._destination.first) {
  5657. return;
  5658. }
  5659. forceReplace = true;
  5660. }
  5661. this._pushOrReplaceState(position, forceReplace);
  5662. }
  5663. _isValidPage(val) {
  5664. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5665. }
  5666. _isValidState(state, checkReload = false) {
  5667. if (!state) {
  5668. return false;
  5669. }
  5670. if (state.fingerprint !== this._fingerprint) {
  5671. if (checkReload) {
  5672. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5673. return false;
  5674. }
  5675. const [perfEntry] = performance.getEntriesByType("navigation");
  5676. if (perfEntry?.type !== "reload") {
  5677. return false;
  5678. }
  5679. } else {
  5680. return false;
  5681. }
  5682. }
  5683. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5684. return false;
  5685. }
  5686. if (state.destination === null || typeof state.destination !== "object") {
  5687. return false;
  5688. }
  5689. return true;
  5690. }
  5691. _updateInternalState(destination, uid, removeTemporary = false) {
  5692. if (this._updateViewareaTimeout) {
  5693. clearTimeout(this._updateViewareaTimeout);
  5694. this._updateViewareaTimeout = null;
  5695. }
  5696. if (removeTemporary && destination?.temporary) {
  5697. delete destination.temporary;
  5698. }
  5699. this._destination = destination;
  5700. this._uid = uid;
  5701. this._maxUid = Math.max(this._maxUid, uid);
  5702. this._numPositionUpdates = 0;
  5703. }
  5704. _parseCurrentHash(checkNameddest = false) {
  5705. const hash = unescape(getCurrentHash()).substring(1);
  5706. const params = (0, _ui_utils.parseQueryString)(hash);
  5707. const nameddest = params.get("nameddest") || "";
  5708. let page = params.get("page") | 0;
  5709. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5710. page = null;
  5711. }
  5712. return {
  5713. hash,
  5714. page,
  5715. rotation: this.linkService.rotation
  5716. };
  5717. }
  5718. _updateViewarea({
  5719. location
  5720. }) {
  5721. if (this._updateViewareaTimeout) {
  5722. clearTimeout(this._updateViewareaTimeout);
  5723. this._updateViewareaTimeout = null;
  5724. }
  5725. this._position = {
  5726. hash: location.pdfOpenParams.substring(1),
  5727. page: this.linkService.page,
  5728. first: location.pageNumber,
  5729. rotation: location.rotation
  5730. };
  5731. if (this._popStateInProgress) {
  5732. return;
  5733. }
  5734. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5735. this._numPositionUpdates++;
  5736. }
  5737. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5738. this._updateViewareaTimeout = setTimeout(() => {
  5739. if (!this._popStateInProgress) {
  5740. this._tryPushCurrentPosition(true);
  5741. }
  5742. this._updateViewareaTimeout = null;
  5743. }, UPDATE_VIEWAREA_TIMEOUT);
  5744. }
  5745. }
  5746. _popState({
  5747. state
  5748. }) {
  5749. const newHash = getCurrentHash(),
  5750. hashChanged = this._currentHash !== newHash;
  5751. this._currentHash = newHash;
  5752. if (!state) {
  5753. this._uid++;
  5754. const {
  5755. hash,
  5756. page,
  5757. rotation
  5758. } = this._parseCurrentHash();
  5759. this._pushOrReplaceState({
  5760. hash,
  5761. page,
  5762. rotation
  5763. }, true);
  5764. return;
  5765. }
  5766. if (!this._isValidState(state)) {
  5767. return;
  5768. }
  5769. this._popStateInProgress = true;
  5770. if (hashChanged) {
  5771. this._blockHashChange++;
  5772. (0, _event_utils.waitOnEventOrTimeout)({
  5773. target: window,
  5774. name: "hashchange",
  5775. delay: HASH_CHANGE_TIMEOUT
  5776. }).then(() => {
  5777. this._blockHashChange--;
  5778. });
  5779. }
  5780. const destination = state.destination;
  5781. this._updateInternalState(destination, state.uid, true);
  5782. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5783. this.linkService.rotation = destination.rotation;
  5784. }
  5785. if (destination.dest) {
  5786. this.linkService.goToDestination(destination.dest);
  5787. } else if (destination.hash) {
  5788. this.linkService.setHash(destination.hash);
  5789. } else if (destination.page) {
  5790. this.linkService.page = destination.page;
  5791. }
  5792. Promise.resolve().then(() => {
  5793. this._popStateInProgress = false;
  5794. });
  5795. }
  5796. _pageHide() {
  5797. if (!this._destination || this._destination.temporary) {
  5798. this._tryPushCurrentPosition();
  5799. }
  5800. }
  5801. _bindEvents() {
  5802. if (this._boundEvents) {
  5803. return;
  5804. }
  5805. this._boundEvents = {
  5806. updateViewarea: this._updateViewarea.bind(this),
  5807. popState: this._popState.bind(this),
  5808. pageHide: this._pageHide.bind(this)
  5809. };
  5810. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5811. window.addEventListener("popstate", this._boundEvents.popState);
  5812. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5813. }
  5814. _unbindEvents() {
  5815. if (!this._boundEvents) {
  5816. return;
  5817. }
  5818. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5819. window.removeEventListener("popstate", this._boundEvents.popState);
  5820. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5821. this._boundEvents = null;
  5822. }
  5823. }
  5824. exports.PDFHistory = PDFHistory;
  5825. function isDestHashesEqual(destHash, pushHash) {
  5826. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5827. return false;
  5828. }
  5829. if (destHash === pushHash) {
  5830. return true;
  5831. }
  5832. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  5833. if (nameddest === pushHash) {
  5834. return true;
  5835. }
  5836. return false;
  5837. }
  5838. function isDestArraysEqual(firstDest, secondDest) {
  5839. function isEntryEqual(first, second) {
  5840. if (typeof first !== typeof second) {
  5841. return false;
  5842. }
  5843. if (Array.isArray(first) || Array.isArray(second)) {
  5844. return false;
  5845. }
  5846. if (first !== null && typeof first === "object" && second !== null) {
  5847. if (Object.keys(first).length !== Object.keys(second).length) {
  5848. return false;
  5849. }
  5850. for (const key in first) {
  5851. if (!isEntryEqual(first[key], second[key])) {
  5852. return false;
  5853. }
  5854. }
  5855. return true;
  5856. }
  5857. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5858. }
  5859. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5860. return false;
  5861. }
  5862. if (firstDest.length !== secondDest.length) {
  5863. return false;
  5864. }
  5865. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5866. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5867. return false;
  5868. }
  5869. }
  5870. return true;
  5871. }
  5872. /***/ }),
  5873. /* 19 */
  5874. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5875. Object.defineProperty(exports, "__esModule", ({
  5876. value: true
  5877. }));
  5878. exports.PDFLayerViewer = void 0;
  5879. var _base_tree_viewer = __webpack_require__(13);
  5880. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5881. constructor(options) {
  5882. super(options);
  5883. this.l10n = options.l10n;
  5884. this.eventBus._on("optionalcontentconfigchanged", evt => {
  5885. this.#updateLayers(evt.promise);
  5886. });
  5887. this.eventBus._on("resetlayers", () => {
  5888. this.#updateLayers();
  5889. });
  5890. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5891. }
  5892. reset() {
  5893. super.reset();
  5894. this._optionalContentConfig = null;
  5895. this._optionalContentHash = null;
  5896. }
  5897. _dispatchEvent(layersCount) {
  5898. this.eventBus.dispatch("layersloaded", {
  5899. source: this,
  5900. layersCount
  5901. });
  5902. }
  5903. _bindLink(element, {
  5904. groupId,
  5905. input
  5906. }) {
  5907. const setVisibility = () => {
  5908. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5909. this._optionalContentHash = this._optionalContentConfig.getHash();
  5910. this.eventBus.dispatch("optionalcontentconfig", {
  5911. source: this,
  5912. promise: Promise.resolve(this._optionalContentConfig)
  5913. });
  5914. };
  5915. element.onclick = evt => {
  5916. if (evt.target === input) {
  5917. setVisibility();
  5918. return true;
  5919. } else if (evt.target !== element) {
  5920. return true;
  5921. }
  5922. input.checked = !input.checked;
  5923. setVisibility();
  5924. return false;
  5925. };
  5926. }
  5927. async _setNestedName(element, {
  5928. name = null
  5929. }) {
  5930. if (typeof name === "string") {
  5931. element.textContent = this._normalizeTextContent(name);
  5932. return;
  5933. }
  5934. element.textContent = await this.l10n.get("additional_layers");
  5935. element.style.fontStyle = "italic";
  5936. }
  5937. _addToggleButton(div, {
  5938. name = null
  5939. }) {
  5940. super._addToggleButton(div, name === null);
  5941. }
  5942. _toggleAllTreeItems() {
  5943. if (!this._optionalContentConfig) {
  5944. return;
  5945. }
  5946. super._toggleAllTreeItems();
  5947. }
  5948. render({
  5949. optionalContentConfig,
  5950. pdfDocument
  5951. }) {
  5952. if (this._optionalContentConfig) {
  5953. this.reset();
  5954. }
  5955. this._optionalContentConfig = optionalContentConfig || null;
  5956. this._pdfDocument = pdfDocument || null;
  5957. const groups = optionalContentConfig?.getOrder();
  5958. if (!groups) {
  5959. this._dispatchEvent(0);
  5960. return;
  5961. }
  5962. this._optionalContentHash = optionalContentConfig.getHash();
  5963. const fragment = document.createDocumentFragment(),
  5964. queue = [{
  5965. parent: fragment,
  5966. groups
  5967. }];
  5968. let layersCount = 0,
  5969. hasAnyNesting = false;
  5970. while (queue.length > 0) {
  5971. const levelData = queue.shift();
  5972. for (const groupId of levelData.groups) {
  5973. const div = document.createElement("div");
  5974. div.className = "treeItem";
  5975. const element = document.createElement("a");
  5976. div.append(element);
  5977. if (typeof groupId === "object") {
  5978. hasAnyNesting = true;
  5979. this._addToggleButton(div, groupId);
  5980. this._setNestedName(element, groupId);
  5981. const itemsDiv = document.createElement("div");
  5982. itemsDiv.className = "treeItems";
  5983. div.append(itemsDiv);
  5984. queue.push({
  5985. parent: itemsDiv,
  5986. groups: groupId.order
  5987. });
  5988. } else {
  5989. const group = optionalContentConfig.getGroup(groupId);
  5990. const input = document.createElement("input");
  5991. this._bindLink(element, {
  5992. groupId,
  5993. input
  5994. });
  5995. input.type = "checkbox";
  5996. input.checked = group.visible;
  5997. const label = document.createElement("label");
  5998. label.textContent = this._normalizeTextContent(group.name);
  5999. label.append(input);
  6000. element.append(label);
  6001. layersCount++;
  6002. }
  6003. levelData.parent.append(div);
  6004. }
  6005. }
  6006. this._finishRendering(fragment, layersCount, hasAnyNesting);
  6007. }
  6008. async #updateLayers(promise = null) {
  6009. if (!this._optionalContentConfig) {
  6010. return;
  6011. }
  6012. const pdfDocument = this._pdfDocument;
  6013. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig());
  6014. if (pdfDocument !== this._pdfDocument) {
  6015. return;
  6016. }
  6017. if (promise) {
  6018. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  6019. return;
  6020. }
  6021. } else {
  6022. this.eventBus.dispatch("optionalcontentconfig", {
  6023. source: this,
  6024. promise: Promise.resolve(optionalContentConfig)
  6025. });
  6026. }
  6027. this.render({
  6028. optionalContentConfig,
  6029. pdfDocument: this._pdfDocument
  6030. });
  6031. }
  6032. }
  6033. exports.PDFLayerViewer = PDFLayerViewer;
  6034. /***/ }),
  6035. /* 20 */
  6036. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6037. Object.defineProperty(exports, "__esModule", ({
  6038. value: true
  6039. }));
  6040. exports.PDFOutlineViewer = void 0;
  6041. var _base_tree_viewer = __webpack_require__(13);
  6042. var _pdfjsLib = __webpack_require__(5);
  6043. var _ui_utils = __webpack_require__(1);
  6044. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  6045. constructor(options) {
  6046. super(options);
  6047. this.linkService = options.linkService;
  6048. this.downloadManager = options.downloadManager;
  6049. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6050. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6051. this.eventBus._on("pagechanging", evt => {
  6052. this._currentPageNumber = evt.pageNumber;
  6053. });
  6054. this.eventBus._on("pagesloaded", evt => {
  6055. this._isPagesLoaded = !!evt.pagesCount;
  6056. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6057. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6058. }
  6059. console.log('加载结束');
  6060. window.parent.postMessage('encry-pdf-loaded');
  6061. });
  6062. this.eventBus._on("sidebarviewchanged", evt => {
  6063. this._sidebarView = evt.view;
  6064. });
  6065. }
  6066. reset() {
  6067. super.reset();
  6068. this._outline = null;
  6069. this._pageNumberToDestHashCapability = null;
  6070. this._currentPageNumber = 1;
  6071. this._isPagesLoaded = null;
  6072. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6073. this._currentOutlineItemCapability.resolve(false);
  6074. }
  6075. this._currentOutlineItemCapability = null;
  6076. }
  6077. _dispatchEvent(outlineCount) {
  6078. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  6079. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  6080. this._currentOutlineItemCapability.resolve(false);
  6081. } else if (this._isPagesLoaded !== null) {
  6082. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6083. }
  6084. this.eventBus.dispatch("outlineloaded", {
  6085. source: this,
  6086. outlineCount,
  6087. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6088. });
  6089. }
  6090. _bindLink(element, {
  6091. url,
  6092. newWindow,
  6093. action,
  6094. attachment,
  6095. dest,
  6096. setOCGState
  6097. }) {
  6098. const {
  6099. linkService
  6100. } = this;
  6101. if (url) {
  6102. linkService.addLinkAttributes(element, url, newWindow);
  6103. return;
  6104. }
  6105. if (action) {
  6106. element.href = linkService.getAnchorUrl("");
  6107. element.onclick = () => {
  6108. linkService.executeNamedAction(action);
  6109. return false;
  6110. };
  6111. return;
  6112. }
  6113. if (attachment) {
  6114. element.href = linkService.getAnchorUrl("");
  6115. element.onclick = () => {
  6116. this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename);
  6117. return false;
  6118. };
  6119. return;
  6120. }
  6121. if (setOCGState) {
  6122. element.href = linkService.getAnchorUrl("");
  6123. element.onclick = () => {
  6124. linkService.executeSetOCGState(setOCGState);
  6125. return false;
  6126. };
  6127. return;
  6128. }
  6129. element.href = linkService.getDestinationHash(dest);
  6130. element.onclick = evt => {
  6131. this._updateCurrentTreeItem(evt.target.parentNode);
  6132. if (dest) {
  6133. linkService.goToDestination(dest);
  6134. }
  6135. return false;
  6136. };
  6137. }
  6138. _setStyles(element, {
  6139. bold,
  6140. italic
  6141. }) {
  6142. if (bold) {
  6143. element.style.fontWeight = "bold";
  6144. }
  6145. if (italic) {
  6146. element.style.fontStyle = "italic";
  6147. }
  6148. }
  6149. _addToggleButton(div, {
  6150. count,
  6151. items
  6152. }) {
  6153. let hidden = false;
  6154. if (count < 0) {
  6155. let totalCount = items.length;
  6156. if (totalCount > 0) {
  6157. const queue = [...items];
  6158. while (queue.length > 0) {
  6159. const {
  6160. count: nestedCount,
  6161. items: nestedItems
  6162. } = queue.shift();
  6163. if (nestedCount > 0 && nestedItems.length > 0) {
  6164. totalCount += nestedItems.length;
  6165. queue.push(...nestedItems);
  6166. }
  6167. }
  6168. }
  6169. if (Math.abs(count) === totalCount) {
  6170. hidden = true;
  6171. }
  6172. }
  6173. super._addToggleButton(div, hidden);
  6174. }
  6175. _toggleAllTreeItems() {
  6176. if (!this._outline) {
  6177. return;
  6178. }
  6179. super._toggleAllTreeItems();
  6180. }
  6181. render({
  6182. outline,
  6183. pdfDocument
  6184. }) {
  6185. if (this._outline) {
  6186. this.reset();
  6187. }
  6188. this._outline = outline || null;
  6189. this._pdfDocument = pdfDocument || null;
  6190. if (!outline) {
  6191. this._dispatchEvent(0);
  6192. return;
  6193. }
  6194. const fragment = document.createDocumentFragment();
  6195. const queue = [{
  6196. parent: fragment,
  6197. items: outline
  6198. }];
  6199. let outlineCount = 0,
  6200. hasAnyNesting = false;
  6201. while (queue.length > 0) {
  6202. const levelData = queue.shift();
  6203. for (const item of levelData.items) {
  6204. const div = document.createElement("div");
  6205. div.className = "treeItem";
  6206. const element = document.createElement("a");
  6207. this._bindLink(element, item);
  6208. this._setStyles(element, item);
  6209. element.textContent = this._normalizeTextContent(item.title);
  6210. div.append(element);
  6211. if (item.items.length > 0) {
  6212. hasAnyNesting = true;
  6213. this._addToggleButton(div, item);
  6214. const itemsDiv = document.createElement("div");
  6215. itemsDiv.className = "treeItems";
  6216. div.append(itemsDiv);
  6217. queue.push({
  6218. parent: itemsDiv,
  6219. items: item.items
  6220. });
  6221. }
  6222. levelData.parent.append(div);
  6223. outlineCount++;
  6224. }
  6225. }
  6226. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6227. }
  6228. async _currentOutlineItem() {
  6229. if (!this._isPagesLoaded) {
  6230. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6231. }
  6232. if (!this._outline || !this._pdfDocument) {
  6233. return;
  6234. }
  6235. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6236. if (!pageNumberToDestHash) {
  6237. return;
  6238. }
  6239. this._updateCurrentTreeItem(null);
  6240. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6241. return;
  6242. }
  6243. for (let i = this._currentPageNumber; i > 0; i--) {
  6244. const destHash = pageNumberToDestHash.get(i);
  6245. if (!destHash) {
  6246. continue;
  6247. }
  6248. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6249. if (!linkElement) {
  6250. continue;
  6251. }
  6252. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6253. break;
  6254. }
  6255. }
  6256. async _getPageNumberToDestHash(pdfDocument) {
  6257. if (this._pageNumberToDestHashCapability) {
  6258. return this._pageNumberToDestHashCapability.promise;
  6259. }
  6260. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6261. const pageNumberToDestHash = new Map(),
  6262. pageNumberNesting = new Map();
  6263. const queue = [{
  6264. nesting: 0,
  6265. items: this._outline
  6266. }];
  6267. while (queue.length > 0) {
  6268. const levelData = queue.shift(),
  6269. currentNesting = levelData.nesting;
  6270. for (const {
  6271. dest,
  6272. items
  6273. } of levelData.items) {
  6274. let explicitDest, pageNumber;
  6275. if (typeof dest === "string") {
  6276. explicitDest = await pdfDocument.getDestination(dest);
  6277. if (pdfDocument !== this._pdfDocument) {
  6278. return null;
  6279. }
  6280. } else {
  6281. explicitDest = dest;
  6282. }
  6283. if (Array.isArray(explicitDest)) {
  6284. const [destRef] = explicitDest;
  6285. if (typeof destRef === "object" && destRef !== null) {
  6286. pageNumber = this.linkService._cachedPageNumber(destRef);
  6287. if (!pageNumber) {
  6288. try {
  6289. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6290. if (pdfDocument !== this._pdfDocument) {
  6291. return null;
  6292. }
  6293. this.linkService.cachePageRef(pageNumber, destRef);
  6294. } catch (ex) {}
  6295. }
  6296. } else if (Number.isInteger(destRef)) {
  6297. pageNumber = destRef + 1;
  6298. }
  6299. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6300. const destHash = this.linkService.getDestinationHash(dest);
  6301. pageNumberToDestHash.set(pageNumber, destHash);
  6302. pageNumberNesting.set(pageNumber, currentNesting);
  6303. }
  6304. }
  6305. if (items.length > 0) {
  6306. queue.push({
  6307. nesting: currentNesting + 1,
  6308. items
  6309. });
  6310. }
  6311. }
  6312. }
  6313. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6314. return this._pageNumberToDestHashCapability.promise;
  6315. }
  6316. }
  6317. exports.PDFOutlineViewer = PDFOutlineViewer;
  6318. /***/ }),
  6319. /* 21 */
  6320. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6321. Object.defineProperty(exports, "__esModule", ({
  6322. value: true
  6323. }));
  6324. exports.PDFPresentationMode = void 0;
  6325. var _ui_utils = __webpack_require__(1);
  6326. var _pdfjsLib = __webpack_require__(5);
  6327. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6328. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6329. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6330. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6331. const PAGE_SWITCH_THRESHOLD = 0.1;
  6332. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6333. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6334. class PDFPresentationMode {
  6335. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6336. #args = null;
  6337. constructor({
  6338. container,
  6339. pdfViewer,
  6340. eventBus
  6341. }) {
  6342. this.container = container;
  6343. this.pdfViewer = pdfViewer;
  6344. this.eventBus = eventBus;
  6345. this.contextMenuOpen = false;
  6346. this.mouseScrollTimeStamp = 0;
  6347. this.mouseScrollDelta = 0;
  6348. this.touchSwipeState = null;
  6349. }
  6350. async request() {
  6351. const {
  6352. container,
  6353. pdfViewer
  6354. } = this;
  6355. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6356. return false;
  6357. }
  6358. this.#addFullscreenChangeListeners();
  6359. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6360. const promise = container.requestFullscreen();
  6361. this.#args = {
  6362. pageNumber: pdfViewer.currentPageNumber,
  6363. scaleValue: pdfViewer.currentScaleValue,
  6364. scrollMode: pdfViewer.scrollMode,
  6365. spreadMode: null,
  6366. annotationEditorMode: null
  6367. };
  6368. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6369. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6370. this.#args.spreadMode = pdfViewer.spreadMode;
  6371. }
  6372. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6373. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6374. }
  6375. try {
  6376. await promise;
  6377. pdfViewer.focus();
  6378. return true;
  6379. } catch (reason) {
  6380. this.#removeFullscreenChangeListeners();
  6381. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6382. }
  6383. return false;
  6384. }
  6385. get active() {
  6386. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6387. }
  6388. #mouseWheel(evt) {
  6389. if (!this.active) {
  6390. return;
  6391. }
  6392. evt.preventDefault();
  6393. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6394. const currentTime = Date.now();
  6395. const storedTime = this.mouseScrollTimeStamp;
  6396. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6397. return;
  6398. }
  6399. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6400. this.#resetMouseScrollState();
  6401. }
  6402. this.mouseScrollDelta += delta;
  6403. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6404. const totalDelta = this.mouseScrollDelta;
  6405. this.#resetMouseScrollState();
  6406. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6407. if (success) {
  6408. this.mouseScrollTimeStamp = currentTime;
  6409. }
  6410. }
  6411. }
  6412. #notifyStateChange(state) {
  6413. this.#state = state;
  6414. this.eventBus.dispatch("presentationmodechanged", {
  6415. source: this,
  6416. state
  6417. });
  6418. }
  6419. #enter() {
  6420. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6421. this.container.classList.add(ACTIVE_SELECTOR);
  6422. setTimeout(() => {
  6423. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6424. if (this.#args.spreadMode !== null) {
  6425. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6426. }
  6427. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6428. this.pdfViewer.currentScaleValue = "page-fit";
  6429. if (this.#args.annotationEditorMode !== null) {
  6430. this.pdfViewer.annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  6431. }
  6432. }, 0);
  6433. this.#addWindowListeners();
  6434. this.#showControls();
  6435. this.contextMenuOpen = false;
  6436. window.getSelection().removeAllRanges();
  6437. }
  6438. #exit() {
  6439. const pageNumber = this.pdfViewer.currentPageNumber;
  6440. this.container.classList.remove(ACTIVE_SELECTOR);
  6441. setTimeout(() => {
  6442. this.#removeFullscreenChangeListeners();
  6443. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6444. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6445. if (this.#args.spreadMode !== null) {
  6446. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6447. }
  6448. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6449. this.pdfViewer.currentPageNumber = pageNumber;
  6450. if (this.#args.annotationEditorMode !== null) {
  6451. this.pdfViewer.annotationEditorMode = this.#args.annotationEditorMode;
  6452. }
  6453. this.#args = null;
  6454. }, 0);
  6455. this.#removeWindowListeners();
  6456. this.#hideControls();
  6457. this.#resetMouseScrollState();
  6458. this.contextMenuOpen = false;
  6459. }
  6460. #mouseDown(evt) {
  6461. if (this.contextMenuOpen) {
  6462. this.contextMenuOpen = false;
  6463. evt.preventDefault();
  6464. return;
  6465. }
  6466. if (evt.button !== 0) {
  6467. return;
  6468. }
  6469. if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) {
  6470. return;
  6471. }
  6472. evt.preventDefault();
  6473. if (evt.shiftKey) {
  6474. this.pdfViewer.previousPage();
  6475. } else {
  6476. this.pdfViewer.nextPage();
  6477. }
  6478. }
  6479. #contextMenu() {
  6480. this.contextMenuOpen = true;
  6481. }
  6482. #showControls() {
  6483. if (this.controlsTimeout) {
  6484. clearTimeout(this.controlsTimeout);
  6485. } else {
  6486. this.container.classList.add(CONTROLS_SELECTOR);
  6487. }
  6488. this.controlsTimeout = setTimeout(() => {
  6489. this.container.classList.remove(CONTROLS_SELECTOR);
  6490. delete this.controlsTimeout;
  6491. }, DELAY_BEFORE_HIDING_CONTROLS);
  6492. }
  6493. #hideControls() {
  6494. if (!this.controlsTimeout) {
  6495. return;
  6496. }
  6497. clearTimeout(this.controlsTimeout);
  6498. this.container.classList.remove(CONTROLS_SELECTOR);
  6499. delete this.controlsTimeout;
  6500. }
  6501. #resetMouseScrollState() {
  6502. this.mouseScrollTimeStamp = 0;
  6503. this.mouseScrollDelta = 0;
  6504. }
  6505. #touchSwipe(evt) {
  6506. if (!this.active) {
  6507. return;
  6508. }
  6509. if (evt.touches.length > 1) {
  6510. this.touchSwipeState = null;
  6511. return;
  6512. }
  6513. switch (evt.type) {
  6514. case "touchstart":
  6515. this.touchSwipeState = {
  6516. startX: evt.touches[0].pageX,
  6517. startY: evt.touches[0].pageY,
  6518. endX: evt.touches[0].pageX,
  6519. endY: evt.touches[0].pageY
  6520. };
  6521. break;
  6522. case "touchmove":
  6523. if (this.touchSwipeState === null) {
  6524. return;
  6525. }
  6526. this.touchSwipeState.endX = evt.touches[0].pageX;
  6527. this.touchSwipeState.endY = evt.touches[0].pageY;
  6528. evt.preventDefault();
  6529. break;
  6530. case "touchend":
  6531. if (this.touchSwipeState === null) {
  6532. return;
  6533. }
  6534. let delta = 0;
  6535. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6536. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6537. const absAngle = Math.abs(Math.atan2(dy, dx));
  6538. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6539. delta = dx;
  6540. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6541. delta = dy;
  6542. }
  6543. if (delta > 0) {
  6544. this.pdfViewer.previousPage();
  6545. } else if (delta < 0) {
  6546. this.pdfViewer.nextPage();
  6547. }
  6548. break;
  6549. }
  6550. }
  6551. #addWindowListeners() {
  6552. this.showControlsBind = this.#showControls.bind(this);
  6553. this.mouseDownBind = this.#mouseDown.bind(this);
  6554. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6555. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6556. this.contextMenuBind = this.#contextMenu.bind(this);
  6557. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6558. window.addEventListener("mousemove", this.showControlsBind);
  6559. window.addEventListener("mousedown", this.mouseDownBind);
  6560. window.addEventListener("wheel", this.mouseWheelBind, {
  6561. passive: false
  6562. });
  6563. // window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6564. window.addEventListener("contextmenu", this.contextMenuBind);
  6565. window.addEventListener("touchstart", this.touchSwipeBind);
  6566. window.addEventListener("touchmove", this.touchSwipeBind);
  6567. window.addEventListener("touchend", this.touchSwipeBind);
  6568. }
  6569. #removeWindowListeners() {
  6570. window.removeEventListener("mousemove", this.showControlsBind);
  6571. window.removeEventListener("mousedown", this.mouseDownBind);
  6572. window.removeEventListener("wheel", this.mouseWheelBind, {
  6573. passive: false
  6574. });
  6575. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6576. window.removeEventListener("contextmenu", this.contextMenuBind);
  6577. window.removeEventListener("touchstart", this.touchSwipeBind);
  6578. window.removeEventListener("touchmove", this.touchSwipeBind);
  6579. window.removeEventListener("touchend", this.touchSwipeBind);
  6580. delete this.showControlsBind;
  6581. delete this.mouseDownBind;
  6582. delete this.mouseWheelBind;
  6583. delete this.resetMouseScrollStateBind;
  6584. delete this.contextMenuBind;
  6585. delete this.touchSwipeBind;
  6586. }
  6587. #fullscreenChange() {
  6588. if (document.fullscreenElement) {
  6589. this.#enter();
  6590. } else {
  6591. this.#exit();
  6592. }
  6593. }
  6594. #addFullscreenChangeListeners() {
  6595. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6596. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6597. }
  6598. #removeFullscreenChangeListeners() {
  6599. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6600. delete this.fullscreenChangeBind;
  6601. }
  6602. }
  6603. exports.PDFPresentationMode = PDFPresentationMode;
  6604. /***/ }),
  6605. /* 22 */
  6606. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6607. Object.defineProperty(exports, "__esModule", ({
  6608. value: true
  6609. }));
  6610. exports.PDFRenderingQueue = void 0;
  6611. var _pdfjsLib = __webpack_require__(5);
  6612. var _ui_utils = __webpack_require__(1);
  6613. const CLEANUP_TIMEOUT = 30000;
  6614. class PDFRenderingQueue {
  6615. constructor() {
  6616. this.pdfViewer = null;
  6617. this.pdfThumbnailViewer = null;
  6618. this.onIdle = null;
  6619. this.highestPriorityPage = null;
  6620. this.idleTimeout = null;
  6621. this.printing = false;
  6622. this.isThumbnailViewEnabled = false;
  6623. }
  6624. setViewer(pdfViewer) {
  6625. this.pdfViewer = pdfViewer;
  6626. }
  6627. setThumbnailViewer(pdfThumbnailViewer) {
  6628. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6629. }
  6630. isHighestPriority(view) {
  6631. return this.highestPriorityPage === view.renderingId;
  6632. }
  6633. hasViewer() {
  6634. return !!this.pdfViewer;
  6635. }
  6636. renderHighestPriority(currentlyVisiblePages) {
  6637. if (this.idleTimeout) {
  6638. clearTimeout(this.idleTimeout);
  6639. this.idleTimeout = null;
  6640. }
  6641. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6642. return;
  6643. }
  6644. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6645. return;
  6646. }
  6647. if (this.printing) {
  6648. return;
  6649. }
  6650. if (this.onIdle) {
  6651. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6652. }
  6653. }
  6654. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6655. const visibleViews = visible.views,
  6656. numVisible = visibleViews.length;
  6657. if (numVisible === 0) {
  6658. return null;
  6659. }
  6660. for (let i = 0; i < numVisible; i++) {
  6661. const view = visibleViews[i].view;
  6662. if (!this.isViewFinished(view)) {
  6663. return view;
  6664. }
  6665. }
  6666. const firstId = visible.first.id,
  6667. lastId = visible.last.id;
  6668. if (lastId - firstId + 1 > numVisible) {
  6669. const visibleIds = visible.ids;
  6670. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6671. const holeId = scrolledDown ? firstId + i : lastId - i;
  6672. if (visibleIds.has(holeId)) {
  6673. continue;
  6674. }
  6675. const holeView = views[holeId - 1];
  6676. if (!this.isViewFinished(holeView)) {
  6677. return holeView;
  6678. }
  6679. }
  6680. }
  6681. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6682. let preRenderView = views[preRenderIndex];
  6683. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6684. return preRenderView;
  6685. }
  6686. if (preRenderExtra) {
  6687. preRenderIndex += scrolledDown ? 1 : -1;
  6688. preRenderView = views[preRenderIndex];
  6689. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6690. return preRenderView;
  6691. }
  6692. }
  6693. return null;
  6694. }
  6695. isViewFinished(view) {
  6696. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6697. }
  6698. renderView(view) {
  6699. switch (view.renderingState) {
  6700. case _ui_utils.RenderingStates.FINISHED:
  6701. return false;
  6702. case _ui_utils.RenderingStates.PAUSED:
  6703. this.highestPriorityPage = view.renderingId;
  6704. view.resume();
  6705. break;
  6706. case _ui_utils.RenderingStates.RUNNING:
  6707. this.highestPriorityPage = view.renderingId;
  6708. break;
  6709. case _ui_utils.RenderingStates.INITIAL:
  6710. this.highestPriorityPage = view.renderingId;
  6711. view.draw().finally(() => {
  6712. this.renderHighestPriority();
  6713. }).catch(reason => {
  6714. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6715. return;
  6716. }
  6717. console.error(`renderView: "${reason}"`);
  6718. });
  6719. break;
  6720. }
  6721. return true;
  6722. }
  6723. }
  6724. exports.PDFRenderingQueue = PDFRenderingQueue;
  6725. /***/ }),
  6726. /* 23 */
  6727. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6728. Object.defineProperty(exports, "__esModule", ({
  6729. value: true
  6730. }));
  6731. exports.PDFScriptingManager = void 0;
  6732. var _ui_utils = __webpack_require__(1);
  6733. var _pdfjsLib = __webpack_require__(5);
  6734. class PDFScriptingManager {
  6735. constructor({
  6736. eventBus,
  6737. sandboxBundleSrc = null,
  6738. scriptingFactory = null,
  6739. docPropertiesLookup = null
  6740. }) {
  6741. this._pdfDocument = null;
  6742. this._pdfViewer = null;
  6743. this._closeCapability = null;
  6744. this._destroyCapability = null;
  6745. this._scripting = null;
  6746. this._mouseState = Object.create(null);
  6747. this._ready = false;
  6748. this._eventBus = eventBus;
  6749. this._sandboxBundleSrc = sandboxBundleSrc;
  6750. this._scriptingFactory = scriptingFactory;
  6751. this._docPropertiesLookup = docPropertiesLookup;
  6752. }
  6753. setViewer(pdfViewer) {
  6754. this._pdfViewer = pdfViewer;
  6755. }
  6756. async setDocument(pdfDocument) {
  6757. if (this._pdfDocument) {
  6758. await this._destroyScripting();
  6759. }
  6760. this._pdfDocument = pdfDocument;
  6761. if (!pdfDocument) {
  6762. return;
  6763. }
  6764. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6765. if (!objects && !docActions) {
  6766. await this._destroyScripting();
  6767. return;
  6768. }
  6769. if (pdfDocument !== this._pdfDocument) {
  6770. return;
  6771. }
  6772. try {
  6773. this._scripting = this._createScripting();
  6774. } catch (error) {
  6775. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6776. await this._destroyScripting();
  6777. return;
  6778. }
  6779. this._internalEvents.set("updatefromsandbox", event => {
  6780. if (event?.source !== window) {
  6781. return;
  6782. }
  6783. this._updateFromSandbox(event.detail);
  6784. });
  6785. this._internalEvents.set("dispatcheventinsandbox", event => {
  6786. this._scripting?.dispatchEventInSandbox(event.detail);
  6787. });
  6788. this._internalEvents.set("pagechanging", ({
  6789. pageNumber,
  6790. previous
  6791. }) => {
  6792. if (pageNumber === previous) {
  6793. return;
  6794. }
  6795. this._dispatchPageClose(previous);
  6796. this._dispatchPageOpen(pageNumber);
  6797. });
  6798. this._internalEvents.set("pagerendered", ({
  6799. pageNumber
  6800. }) => {
  6801. if (!this._pageOpenPending.has(pageNumber)) {
  6802. return;
  6803. }
  6804. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6805. return;
  6806. }
  6807. this._dispatchPageOpen(pageNumber);
  6808. });
  6809. this._internalEvents.set("pagesdestroy", async event => {
  6810. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6811. await this._scripting?.dispatchEventInSandbox({
  6812. id: "doc",
  6813. name: "WillClose"
  6814. });
  6815. this._closeCapability?.resolve();
  6816. });
  6817. this._domEvents.set("mousedown", event => {
  6818. this._mouseState.isDown = true;
  6819. });
  6820. this._domEvents.set("mouseup", event => {
  6821. this._mouseState.isDown = false;
  6822. });
  6823. for (const [name, listener] of this._internalEvents) {
  6824. this._eventBus._on(name, listener);
  6825. }
  6826. for (const [name, listener] of this._domEvents) {
  6827. window.addEventListener(name, listener, true);
  6828. }
  6829. try {
  6830. const docProperties = await this._getDocProperties();
  6831. if (pdfDocument !== this._pdfDocument) {
  6832. return;
  6833. }
  6834. await this._scripting.createSandbox({
  6835. objects,
  6836. calculationOrder,
  6837. appInfo: {
  6838. platform: navigator.platform,
  6839. language: navigator.language
  6840. },
  6841. docInfo: {
  6842. ...docProperties,
  6843. actions: docActions
  6844. }
  6845. });
  6846. this._eventBus.dispatch("sandboxcreated", {
  6847. source: this
  6848. });
  6849. } catch (error) {
  6850. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6851. await this._destroyScripting();
  6852. return;
  6853. }
  6854. await this._scripting?.dispatchEventInSandbox({
  6855. id: "doc",
  6856. name: "Open"
  6857. });
  6858. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6859. Promise.resolve().then(() => {
  6860. if (pdfDocument === this._pdfDocument) {
  6861. this._ready = true;
  6862. }
  6863. });
  6864. }
  6865. async dispatchWillSave(detail) {
  6866. return this._scripting?.dispatchEventInSandbox({
  6867. id: "doc",
  6868. name: "WillSave"
  6869. });
  6870. }
  6871. async dispatchDidSave(detail) {
  6872. return this._scripting?.dispatchEventInSandbox({
  6873. id: "doc",
  6874. name: "DidSave"
  6875. });
  6876. }
  6877. async dispatchWillPrint(detail) {
  6878. return this._scripting?.dispatchEventInSandbox({
  6879. id: "doc",
  6880. name: "WillPrint"
  6881. });
  6882. }
  6883. async dispatchDidPrint(detail) {
  6884. return this._scripting?.dispatchEventInSandbox({
  6885. id: "doc",
  6886. name: "DidPrint"
  6887. });
  6888. }
  6889. get mouseState() {
  6890. return this._mouseState;
  6891. }
  6892. get destroyPromise() {
  6893. return this._destroyCapability?.promise || null;
  6894. }
  6895. get ready() {
  6896. return this._ready;
  6897. }
  6898. get _internalEvents() {
  6899. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6900. }
  6901. get _domEvents() {
  6902. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6903. }
  6904. get _pageOpenPending() {
  6905. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6906. }
  6907. get _visitedPages() {
  6908. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6909. }
  6910. async _updateFromSandbox(detail) {
  6911. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6912. const {
  6913. id,
  6914. siblings,
  6915. command,
  6916. value
  6917. } = detail;
  6918. if (!id) {
  6919. switch (command) {
  6920. case "clear":
  6921. console.clear();
  6922. break;
  6923. case "error":
  6924. console.error(value);
  6925. break;
  6926. case "layout":
  6927. if (isInPresentationMode) {
  6928. return;
  6929. }
  6930. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  6931. this._pdfViewer.spreadMode = modes.spreadMode;
  6932. break;
  6933. case "page-num":
  6934. this._pdfViewer.currentPageNumber = value + 1;
  6935. break;
  6936. case "print":
  6937. await this._pdfViewer.pagesPromise;
  6938. this._eventBus.dispatch("print", {
  6939. source: this
  6940. });
  6941. break;
  6942. case "println":
  6943. console.log(value);
  6944. break;
  6945. case "zoom":
  6946. if (isInPresentationMode) {
  6947. return;
  6948. }
  6949. this._pdfViewer.currentScaleValue = value;
  6950. break;
  6951. case "SaveAs":
  6952. this._eventBus.dispatch("download", {
  6953. source: this
  6954. });
  6955. break;
  6956. case "FirstPage":
  6957. this._pdfViewer.currentPageNumber = 1;
  6958. break;
  6959. case "LastPage":
  6960. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  6961. break;
  6962. case "NextPage":
  6963. this._pdfViewer.nextPage();
  6964. break;
  6965. case "PrevPage":
  6966. this._pdfViewer.previousPage();
  6967. break;
  6968. case "ZoomViewIn":
  6969. if (isInPresentationMode) {
  6970. return;
  6971. }
  6972. this._pdfViewer.increaseScale();
  6973. break;
  6974. case "ZoomViewOut":
  6975. if (isInPresentationMode) {
  6976. return;
  6977. }
  6978. this._pdfViewer.decreaseScale();
  6979. break;
  6980. }
  6981. return;
  6982. }
  6983. if (isInPresentationMode) {
  6984. if (detail.focus) {
  6985. return;
  6986. }
  6987. }
  6988. delete detail.id;
  6989. delete detail.siblings;
  6990. const ids = siblings ? [id, ...siblings] : [id];
  6991. for (const elementId of ids) {
  6992. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  6993. if (element) {
  6994. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6995. detail
  6996. }));
  6997. } else {
  6998. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6999. }
  7000. }
  7001. }
  7002. async _dispatchPageOpen(pageNumber, initialize = false) {
  7003. const pdfDocument = this._pdfDocument,
  7004. visitedPages = this._visitedPages;
  7005. if (initialize) {
  7006. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  7007. }
  7008. if (!this._closeCapability) {
  7009. return;
  7010. }
  7011. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  7012. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7013. this._pageOpenPending.add(pageNumber);
  7014. return;
  7015. }
  7016. this._pageOpenPending.delete(pageNumber);
  7017. const actionsPromise = (async () => {
  7018. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  7019. if (pdfDocument !== this._pdfDocument) {
  7020. return;
  7021. }
  7022. await this._scripting?.dispatchEventInSandbox({
  7023. id: "page",
  7024. name: "PageOpen",
  7025. pageNumber,
  7026. actions
  7027. });
  7028. })();
  7029. visitedPages.set(pageNumber, actionsPromise);
  7030. }
  7031. async _dispatchPageClose(pageNumber) {
  7032. const pdfDocument = this._pdfDocument,
  7033. visitedPages = this._visitedPages;
  7034. if (!this._closeCapability) {
  7035. return;
  7036. }
  7037. if (this._pageOpenPending.has(pageNumber)) {
  7038. return;
  7039. }
  7040. const actionsPromise = visitedPages.get(pageNumber);
  7041. if (!actionsPromise) {
  7042. return;
  7043. }
  7044. visitedPages.set(pageNumber, null);
  7045. await actionsPromise;
  7046. if (pdfDocument !== this._pdfDocument) {
  7047. return;
  7048. }
  7049. await this._scripting?.dispatchEventInSandbox({
  7050. id: "page",
  7051. name: "PageClose",
  7052. pageNumber
  7053. });
  7054. }
  7055. async _getDocProperties() {
  7056. if (this._docPropertiesLookup) {
  7057. return this._docPropertiesLookup(this._pdfDocument);
  7058. }
  7059. throw new Error("_getDocProperties: Unable to lookup properties.");
  7060. }
  7061. _createScripting() {
  7062. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  7063. if (this._scripting) {
  7064. throw new Error("_createScripting: Scripting already exists.");
  7065. }
  7066. if (this._scriptingFactory) {
  7067. return this._scriptingFactory.createScripting({
  7068. sandboxBundleSrc: this._sandboxBundleSrc
  7069. });
  7070. }
  7071. throw new Error("_createScripting: Cannot create scripting.");
  7072. }
  7073. async _destroyScripting() {
  7074. if (!this._scripting) {
  7075. this._pdfDocument = null;
  7076. this._destroyCapability?.resolve();
  7077. return;
  7078. }
  7079. if (this._closeCapability) {
  7080. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  7081. setTimeout(resolve, 1000);
  7082. })]).catch(reason => {});
  7083. this._closeCapability = null;
  7084. }
  7085. this._pdfDocument = null;
  7086. try {
  7087. await this._scripting.destroySandbox();
  7088. } catch (ex) {}
  7089. for (const [name, listener] of this._internalEvents) {
  7090. this._eventBus._off(name, listener);
  7091. }
  7092. this._internalEvents.clear();
  7093. for (const [name, listener] of this._domEvents) {
  7094. window.removeEventListener(name, listener, true);
  7095. }
  7096. this._domEvents.clear();
  7097. this._pageOpenPending.clear();
  7098. this._visitedPages.clear();
  7099. this._scripting = null;
  7100. delete this._mouseState.isDown;
  7101. this._ready = false;
  7102. this._destroyCapability?.resolve();
  7103. }
  7104. }
  7105. exports.PDFScriptingManager = PDFScriptingManager;
  7106. /***/ }),
  7107. /* 24 */
  7108. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7109. Object.defineProperty(exports, "__esModule", ({
  7110. value: true
  7111. }));
  7112. exports.PDFSidebar = void 0;
  7113. var _ui_utils = __webpack_require__(1);
  7114. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7115. class PDFSidebar {
  7116. constructor({
  7117. elements,
  7118. pdfViewer,
  7119. pdfThumbnailViewer,
  7120. eventBus,
  7121. l10n
  7122. }) {
  7123. this.isOpen = false;
  7124. this.active = _ui_utils.SidebarView.THUMBS;
  7125. this.isInitialViewSet = false;
  7126. this.isInitialEventDispatched = false;
  7127. this.onToggled = null;
  7128. this.pdfViewer = pdfViewer;
  7129. this.pdfThumbnailViewer = pdfThumbnailViewer;
  7130. this.outerContainer = elements.outerContainer;
  7131. this.sidebarContainer = elements.sidebarContainer;
  7132. this.sidebarContainerMask = elements.sidebarContainerMask;
  7133. this.toggleButton = elements.toggleButton;
  7134. this.thumbnailButton = elements.thumbnailButton;
  7135. this.outlineButton = elements.outlineButton;
  7136. this.attachmentsButton = elements.attachmentsButton;
  7137. this.layersButton = elements.layersButton;
  7138. this.thumbnailView = elements.thumbnailView;
  7139. this.outlineView = elements.outlineView;
  7140. this.attachmentsView = elements.attachmentsView;
  7141. this.layersView = elements.layersView;
  7142. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  7143. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7144. this.eventBus = eventBus;
  7145. this.l10n = l10n;
  7146. this.#addEventListeners();
  7147. }
  7148. reset() {
  7149. this.isInitialViewSet = false;
  7150. this.isInitialEventDispatched = false;
  7151. this.#hideUINotification(true);
  7152. this.switchView(_ui_utils.SidebarView.THUMBS);
  7153. this.outlineButton.disabled = false;
  7154. this.attachmentsButton.disabled = false;
  7155. this.layersButton.disabled = false;
  7156. this._currentOutlineItemButton.disabled = true;
  7157. }
  7158. get visibleView() {
  7159. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  7160. }
  7161. setInitialView(view = _ui_utils.SidebarView.NONE) {
  7162. if (this.isInitialViewSet) {
  7163. return;
  7164. }
  7165. this.isInitialViewSet = true;
  7166. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  7167. this.#dispatchEvent();
  7168. return;
  7169. }
  7170. this.switchView(view, true);
  7171. if (!this.isInitialEventDispatched) {
  7172. this.#dispatchEvent();
  7173. }
  7174. }
  7175. switchView(view, forceOpen = false) {
  7176. const isViewChanged = view !== this.active;
  7177. let shouldForceRendering = false;
  7178. switch (view) {
  7179. case _ui_utils.SidebarView.NONE:
  7180. if (this.isOpen) {
  7181. this.close();
  7182. }
  7183. return;
  7184. case _ui_utils.SidebarView.THUMBS:
  7185. if (this.isOpen && isViewChanged) {
  7186. shouldForceRendering = true;
  7187. }
  7188. break;
  7189. case _ui_utils.SidebarView.OUTLINE:
  7190. if (this.outlineButton.disabled) {
  7191. return;
  7192. }
  7193. break;
  7194. case _ui_utils.SidebarView.ATTACHMENTS:
  7195. if (this.attachmentsButton.disabled) {
  7196. return;
  7197. }
  7198. break;
  7199. case _ui_utils.SidebarView.LAYERS:
  7200. if (this.layersButton.disabled) {
  7201. return;
  7202. }
  7203. break;
  7204. default:
  7205. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7206. return;
  7207. }
  7208. this.active = view;
  7209. const isThumbs = view === _ui_utils.SidebarView.THUMBS,
  7210. isOutline = view === _ui_utils.SidebarView.OUTLINE,
  7211. isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS,
  7212. isLayers = view === _ui_utils.SidebarView.LAYERS;
  7213. this.thumbnailButton.classList.toggle("toggled", isThumbs);
  7214. this.outlineButton.classList.toggle("toggled", isOutline);
  7215. this.attachmentsButton.classList.toggle("toggled", isAttachments);
  7216. this.layersButton.classList.toggle("toggled", isLayers);
  7217. this.thumbnailButton.setAttribute("aria-checked", isThumbs);
  7218. this.outlineButton.setAttribute("aria-checked", isOutline);
  7219. this.attachmentsButton.setAttribute("aria-checked", isAttachments);
  7220. this.layersButton.setAttribute("aria-checked", isLayers);
  7221. this.thumbnailView.classList.toggle("hidden", !isThumbs);
  7222. this.outlineView.classList.toggle("hidden", !isOutline);
  7223. this.attachmentsView.classList.toggle("hidden", !isAttachments);
  7224. this.layersView.classList.toggle("hidden", !isLayers);
  7225. this._outlineOptionsContainer.classList.toggle("hidden", !isOutline);
  7226. if (forceOpen && !this.isOpen) {
  7227. this.open();
  7228. return;
  7229. }
  7230. if (shouldForceRendering) {
  7231. this.#updateThumbnailViewer();
  7232. this.#forceRendering();
  7233. }
  7234. if (isViewChanged) {
  7235. this.#dispatchEvent();
  7236. }
  7237. }
  7238. open() {
  7239. if (this.isOpen) {
  7240. return;
  7241. }
  7242. this.isOpen = true;
  7243. this.toggleButton.classList.add("toggled");
  7244. this.toggleButton.setAttribute("aria-expanded", "true");
  7245. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7246. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7247. this.#updateThumbnailViewer();
  7248. }
  7249. this.#forceRendering();
  7250. this.#dispatchEvent();
  7251. this.#hideUINotification();
  7252. }
  7253. close() {
  7254. if (!this.isOpen) {
  7255. return;
  7256. }
  7257. this.isOpen = false;
  7258. this.toggleButton.classList.remove("toggled");
  7259. this.toggleButton.setAttribute("aria-expanded", "false");
  7260. this.outerContainer.classList.add("sidebarMoving");
  7261. this.outerContainer.classList.remove("sidebarOpen");
  7262. this.#forceRendering();
  7263. this.#dispatchEvent();
  7264. }
  7265. toggle() {
  7266. if (this.isOpen) {
  7267. this.close();
  7268. } else {
  7269. this.open();
  7270. }
  7271. }
  7272. #dispatchEvent() {
  7273. if (this.isInitialViewSet && !this.isInitialEventDispatched) {
  7274. this.isInitialEventDispatched = true;
  7275. }
  7276. this.eventBus.dispatch("sidebarviewchanged", {
  7277. source: this,
  7278. view: this.visibleView
  7279. });
  7280. }
  7281. #forceRendering() {
  7282. if (this.onToggled) {
  7283. this.onToggled();
  7284. } else {
  7285. this.pdfViewer.forceRendering();
  7286. this.pdfThumbnailViewer.forceRendering();
  7287. }
  7288. }
  7289. #updateThumbnailViewer() {
  7290. const {
  7291. pdfViewer,
  7292. pdfThumbnailViewer
  7293. } = this;
  7294. const pagesCount = pdfViewer.pagesCount;
  7295. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  7296. const pageView = pdfViewer.getPageView(pageIndex);
  7297. if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) {
  7298. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  7299. thumbnailView.setImage(pageView);
  7300. }
  7301. }
  7302. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  7303. }
  7304. #showUINotification() {
  7305. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2");
  7306. this.l10n.translate(this.toggleButton);
  7307. if (!this.isOpen) {
  7308. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7309. }
  7310. }
  7311. #hideUINotification(reset = false) {
  7312. if (this.isOpen || reset) {
  7313. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7314. }
  7315. if (reset) {
  7316. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
  7317. this.l10n.translate(this.toggleButton);
  7318. }
  7319. }
  7320. #addEventListeners() {
  7321. this.sidebarContainer.addEventListener("transitionend", evt => {
  7322. if (evt.target === this.sidebarContainer) {
  7323. this.outerContainer.classList.remove("sidebarMoving");
  7324. }
  7325. });
  7326. this.sidebarContainerMask.addEventListener("click", () => {
  7327. this.close();
  7328. });
  7329. this.toggleButton.addEventListener("click", () => {
  7330. this.toggle();
  7331. });
  7332. this.thumbnailButton.addEventListener("click", () => {
  7333. this.switchView(_ui_utils.SidebarView.THUMBS);
  7334. });
  7335. this.outlineButton.addEventListener("click", () => {
  7336. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7337. });
  7338. this.outlineButton.addEventListener("dblclick", () => {
  7339. this.eventBus.dispatch("toggleoutlinetree", {
  7340. source: this
  7341. });
  7342. });
  7343. this.attachmentsButton.addEventListener("click", () => {
  7344. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7345. });
  7346. this.layersButton.addEventListener("click", () => {
  7347. this.switchView(_ui_utils.SidebarView.LAYERS);
  7348. });
  7349. this.layersButton.addEventListener("dblclick", () => {
  7350. this.eventBus.dispatch("resetlayers", {
  7351. source: this
  7352. });
  7353. });
  7354. this._currentOutlineItemButton.addEventListener("click", () => {
  7355. this.eventBus.dispatch("currentoutlineitem", {
  7356. source: this
  7357. });
  7358. });
  7359. const onTreeLoaded = (count, button, view) => {
  7360. button.disabled = !count;
  7361. if (count) {
  7362. this.#showUINotification();
  7363. } else if (this.active === view) {
  7364. this.switchView(_ui_utils.SidebarView.THUMBS);
  7365. }
  7366. };
  7367. this.eventBus._on("outlineloaded", evt => {
  7368. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7369. evt.currentOutlineItemPromise.then(enabled => {
  7370. if (!this.isInitialViewSet) {
  7371. return;
  7372. }
  7373. this._currentOutlineItemButton.disabled = !enabled;
  7374. });
  7375. });
  7376. this.eventBus._on("attachmentsloaded", evt => {
  7377. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7378. });
  7379. this.eventBus._on("layersloaded", evt => {
  7380. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7381. });
  7382. this.eventBus._on("presentationmodechanged", evt => {
  7383. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  7384. this.#updateThumbnailViewer();
  7385. }
  7386. });
  7387. }
  7388. }
  7389. exports.PDFSidebar = PDFSidebar;
  7390. /***/ }),
  7391. /* 25 */
  7392. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7393. Object.defineProperty(exports, "__esModule", ({
  7394. value: true
  7395. }));
  7396. exports.PDFSidebarResizer = void 0;
  7397. var _ui_utils = __webpack_require__(1);
  7398. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7399. const SIDEBAR_MIN_WIDTH = 200;
  7400. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7401. class PDFSidebarResizer {
  7402. constructor(options, eventBus, l10n) {
  7403. this.isRTL = false;
  7404. this.sidebarOpen = false;
  7405. this._width = null;
  7406. this._outerContainerWidth = null;
  7407. this._boundEvents = Object.create(null);
  7408. this.outerContainer = options.outerContainer;
  7409. this.resizer = options.resizer;
  7410. this.eventBus = eventBus;
  7411. l10n.getDirection().then(dir => {
  7412. this.isRTL = dir === "rtl";
  7413. });
  7414. this._addEventListeners();
  7415. }
  7416. get outerContainerWidth() {
  7417. return this._outerContainerWidth ||= this.outerContainer.clientWidth;
  7418. }
  7419. _updateWidth(width = 0) {
  7420. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7421. if (width > maxWidth) {
  7422. width = maxWidth;
  7423. }
  7424. if (width < SIDEBAR_MIN_WIDTH) {
  7425. width = SIDEBAR_MIN_WIDTH;
  7426. }
  7427. if (width === this._width) {
  7428. return false;
  7429. }
  7430. this._width = width;
  7431. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7432. return true;
  7433. }
  7434. _mouseMove(evt) {
  7435. let width = evt.clientX;
  7436. if (this.isRTL) {
  7437. width = this.outerContainerWidth - width;
  7438. }
  7439. this._updateWidth(width);
  7440. }
  7441. _mouseUp(evt) {
  7442. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7443. this.eventBus.dispatch("resize", {
  7444. source: this
  7445. });
  7446. const _boundEvents = this._boundEvents;
  7447. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7448. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7449. }
  7450. _addEventListeners() {
  7451. const _boundEvents = this._boundEvents;
  7452. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7453. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7454. this.resizer.addEventListener("mousedown", evt => {
  7455. if (evt.button !== 0) {
  7456. return;
  7457. }
  7458. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7459. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7460. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7461. });
  7462. this.eventBus._on("sidebarviewchanged", evt => {
  7463. this.sidebarOpen = !!evt?.view;
  7464. });
  7465. this.eventBus._on("resize", evt => {
  7466. if (evt?.source !== window) {
  7467. return;
  7468. }
  7469. this._outerContainerWidth = null;
  7470. if (!this._width) {
  7471. return;
  7472. }
  7473. if (!this.sidebarOpen) {
  7474. this._updateWidth(this._width);
  7475. return;
  7476. }
  7477. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7478. const updated = this._updateWidth(this._width);
  7479. Promise.resolve().then(() => {
  7480. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7481. if (updated) {
  7482. this.eventBus.dispatch("resize", {
  7483. source: this
  7484. });
  7485. }
  7486. });
  7487. });
  7488. }
  7489. }
  7490. exports.PDFSidebarResizer = PDFSidebarResizer;
  7491. /***/ }),
  7492. /* 26 */
  7493. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7494. Object.defineProperty(exports, "__esModule", ({
  7495. value: true
  7496. }));
  7497. exports.PDFThumbnailViewer = void 0;
  7498. var _ui_utils = __webpack_require__(1);
  7499. var _pdf_thumbnail_view = __webpack_require__(27);
  7500. const THUMBNAIL_SCROLL_MARGIN = -19;
  7501. const THUMBNAIL_SELECTED_CLASS = "selected";
  7502. class PDFThumbnailViewer {
  7503. constructor({
  7504. container,
  7505. eventBus,
  7506. linkService,
  7507. renderingQueue,
  7508. l10n,
  7509. pageColors
  7510. }) {
  7511. this.container = container;
  7512. this.linkService = linkService;
  7513. this.renderingQueue = renderingQueue;
  7514. this.l10n = l10n;
  7515. this.pageColors = pageColors || null;
  7516. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  7517. if (this.pageColors.background || this.pageColors.foreground) {
  7518. console.warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  7519. }
  7520. this.pageColors = null;
  7521. }
  7522. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7523. this._resetView();
  7524. }
  7525. _scrollUpdated() {
  7526. this.renderingQueue.renderHighestPriority();
  7527. }
  7528. getThumbnail(index) {
  7529. return this._thumbnails[index];
  7530. }
  7531. _getVisibleThumbs() {
  7532. return (0, _ui_utils.getVisibleElements)({
  7533. scrollEl: this.container,
  7534. views: this._thumbnails
  7535. });
  7536. }
  7537. scrollThumbnailIntoView(pageNumber) {
  7538. if (!this.pdfDocument) {
  7539. return;
  7540. }
  7541. const thumbnailView = this._thumbnails[pageNumber - 1];
  7542. if (!thumbnailView) {
  7543. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7544. return;
  7545. }
  7546. if (pageNumber !== this._currentPageNumber) {
  7547. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7548. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7549. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7550. }
  7551. const {
  7552. first,
  7553. last,
  7554. views
  7555. } = this._getVisibleThumbs();
  7556. if (views.length > 0) {
  7557. let shouldScroll = false;
  7558. if (pageNumber <= first.id || pageNumber >= last.id) {
  7559. shouldScroll = true;
  7560. } else {
  7561. for (const {
  7562. id,
  7563. percent
  7564. } of views) {
  7565. if (id !== pageNumber) {
  7566. continue;
  7567. }
  7568. shouldScroll = percent < 100;
  7569. break;
  7570. }
  7571. }
  7572. if (shouldScroll) {
  7573. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7574. top: THUMBNAIL_SCROLL_MARGIN
  7575. });
  7576. }
  7577. }
  7578. this._currentPageNumber = pageNumber;
  7579. }
  7580. get pagesRotation() {
  7581. return this._pagesRotation;
  7582. }
  7583. set pagesRotation(rotation) {
  7584. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7585. throw new Error("Invalid thumbnails rotation angle.");
  7586. }
  7587. if (!this.pdfDocument) {
  7588. return;
  7589. }
  7590. if (this._pagesRotation === rotation) {
  7591. return;
  7592. }
  7593. this._pagesRotation = rotation;
  7594. const updateArgs = {
  7595. rotation
  7596. };
  7597. for (const thumbnail of this._thumbnails) {
  7598. thumbnail.update(updateArgs);
  7599. }
  7600. }
  7601. cleanup() {
  7602. for (const thumbnail of this._thumbnails) {
  7603. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7604. thumbnail.reset();
  7605. }
  7606. }
  7607. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7608. }
  7609. _resetView() {
  7610. this._thumbnails = [];
  7611. this._currentPageNumber = 1;
  7612. this._pageLabels = null;
  7613. this._pagesRotation = 0;
  7614. this.container.textContent = "";
  7615. }
  7616. setDocument(pdfDocument) {
  7617. if (this.pdfDocument) {
  7618. this._cancelRendering();
  7619. this._resetView();
  7620. }
  7621. this.pdfDocument = pdfDocument;
  7622. if (!pdfDocument) {
  7623. return;
  7624. }
  7625. const firstPagePromise = pdfDocument.getPage(1);
  7626. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7627. firstPagePromise.then(firstPdfPage => {
  7628. const pagesCount = pdfDocument.numPages;
  7629. const viewport = firstPdfPage.getViewport({
  7630. scale: 1
  7631. });
  7632. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7633. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7634. container: this.container,
  7635. id: pageNum,
  7636. defaultViewport: viewport.clone(),
  7637. optionalContentConfigPromise,
  7638. linkService: this.linkService,
  7639. renderingQueue: this.renderingQueue,
  7640. l10n: this.l10n,
  7641. pageColors: this.pageColors
  7642. });
  7643. this._thumbnails.push(thumbnail);
  7644. }
  7645. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  7646. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7647. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7648. }).catch(reason => {
  7649. console.error("Unable to initialize thumbnail viewer", reason);
  7650. });
  7651. }
  7652. _cancelRendering() {
  7653. for (const thumbnail of this._thumbnails) {
  7654. thumbnail.cancelRendering();
  7655. }
  7656. }
  7657. setPageLabels(labels) {
  7658. if (!this.pdfDocument) {
  7659. return;
  7660. }
  7661. if (!labels) {
  7662. this._pageLabels = null;
  7663. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7664. this._pageLabels = null;
  7665. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7666. } else {
  7667. this._pageLabels = labels;
  7668. }
  7669. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7670. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7671. }
  7672. }
  7673. async #ensurePdfPageLoaded(thumbView) {
  7674. if (thumbView.pdfPage) {
  7675. return thumbView.pdfPage;
  7676. }
  7677. try {
  7678. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7679. if (!thumbView.pdfPage) {
  7680. thumbView.setPdfPage(pdfPage);
  7681. }
  7682. return pdfPage;
  7683. } catch (reason) {
  7684. console.error("Unable to get page for thumb view", reason);
  7685. return null;
  7686. }
  7687. }
  7688. #getScrollAhead(visible) {
  7689. if (visible.first?.id === 1) {
  7690. return true;
  7691. } else if (visible.last?.id === this._thumbnails.length) {
  7692. return false;
  7693. }
  7694. return this.scroll.down;
  7695. }
  7696. forceRendering() {
  7697. const visibleThumbs = this._getVisibleThumbs();
  7698. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7699. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7700. if (thumbView) {
  7701. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7702. this.renderingQueue.renderView(thumbView);
  7703. });
  7704. return true;
  7705. }
  7706. return false;
  7707. }
  7708. }
  7709. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7710. /***/ }),
  7711. /* 27 */
  7712. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7713. Object.defineProperty(exports, "__esModule", ({
  7714. value: true
  7715. }));
  7716. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7717. var _ui_utils = __webpack_require__(1);
  7718. var _pdfjsLib = __webpack_require__(5);
  7719. const DRAW_UPSCALE_FACTOR = 2;
  7720. const MAX_NUM_SCALING_STEPS = 3;
  7721. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7722. const THUMBNAIL_WIDTH = 98;
  7723. class TempImageFactory {
  7724. static #tempCanvas = null;
  7725. static getCanvas(width, height) {
  7726. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7727. tempCanvas.width = width;
  7728. tempCanvas.height = height;
  7729. const ctx = tempCanvas.getContext("2d", {
  7730. alpha: false
  7731. });
  7732. ctx.save();
  7733. ctx.fillStyle = "rgb(255, 255, 255)";
  7734. ctx.fillRect(0, 0, width, height);
  7735. ctx.restore();
  7736. return [tempCanvas, tempCanvas.getContext("2d")];
  7737. }
  7738. static destroyCanvas() {
  7739. const tempCanvas = this.#tempCanvas;
  7740. if (tempCanvas) {
  7741. tempCanvas.width = 0;
  7742. tempCanvas.height = 0;
  7743. }
  7744. this.#tempCanvas = null;
  7745. }
  7746. }
  7747. exports.TempImageFactory = TempImageFactory;
  7748. class PDFThumbnailView {
  7749. constructor({
  7750. container,
  7751. id,
  7752. defaultViewport,
  7753. optionalContentConfigPromise,
  7754. linkService,
  7755. renderingQueue,
  7756. l10n,
  7757. pageColors
  7758. }) {
  7759. this.id = id;
  7760. this.renderingId = "thumbnail" + id;
  7761. this.pageLabel = null;
  7762. this.pdfPage = null;
  7763. this.rotation = 0;
  7764. this.viewport = defaultViewport;
  7765. this.pdfPageRotate = defaultViewport.rotation;
  7766. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7767. this.pageColors = pageColors || null;
  7768. this.linkService = linkService;
  7769. this.renderingQueue = renderingQueue;
  7770. this.renderTask = null;
  7771. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7772. this.resume = null;
  7773. const pageWidth = this.viewport.width,
  7774. pageHeight = this.viewport.height,
  7775. pageRatio = pageWidth / pageHeight;
  7776. this.canvasWidth = THUMBNAIL_WIDTH;
  7777. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7778. this.scale = this.canvasWidth / pageWidth;
  7779. this.l10n = l10n;
  7780. const anchor = document.createElement("a");
  7781. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7782. this._thumbPageTitle.then(msg => {
  7783. anchor.title = msg;
  7784. });
  7785. anchor.onclick = function () {
  7786. linkService.goToPage(id);
  7787. return false;
  7788. };
  7789. this.anchor = anchor;
  7790. const div = document.createElement("div");
  7791. div.className = "thumbnail";
  7792. div.setAttribute("data-page-number", this.id);
  7793. this.div = div;
  7794. const ring = document.createElement("div");
  7795. ring.className = "thumbnailSelectionRing";
  7796. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7797. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7798. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7799. this.ring = ring;
  7800. div.append(ring);
  7801. anchor.append(div);
  7802. container.append(anchor);
  7803. }
  7804. setPdfPage(pdfPage) {
  7805. this.pdfPage = pdfPage;
  7806. this.pdfPageRotate = pdfPage.rotate;
  7807. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7808. this.viewport = pdfPage.getViewport({
  7809. scale: 1,
  7810. rotation: totalRotation
  7811. });
  7812. this.reset();
  7813. }
  7814. reset() {
  7815. this.cancelRendering();
  7816. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7817. const pageWidth = this.viewport.width,
  7818. pageHeight = this.viewport.height,
  7819. pageRatio = pageWidth / pageHeight;
  7820. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7821. this.scale = this.canvasWidth / pageWidth;
  7822. this.div.removeAttribute("data-loaded");
  7823. const ring = this.ring;
  7824. ring.textContent = "";
  7825. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7826. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7827. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7828. if (this.canvas) {
  7829. this.canvas.width = 0;
  7830. this.canvas.height = 0;
  7831. delete this.canvas;
  7832. }
  7833. if (this.image) {
  7834. this.image.removeAttribute("src");
  7835. delete this.image;
  7836. }
  7837. }
  7838. update({
  7839. rotation = null
  7840. }) {
  7841. if (typeof rotation === "number") {
  7842. this.rotation = rotation;
  7843. }
  7844. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7845. this.viewport = this.viewport.clone({
  7846. scale: 1,
  7847. rotation: totalRotation
  7848. });
  7849. this.reset();
  7850. }
  7851. cancelRendering() {
  7852. if (this.renderTask) {
  7853. this.renderTask.cancel();
  7854. this.renderTask = null;
  7855. }
  7856. this.resume = null;
  7857. }
  7858. _getPageDrawContext(upscaleFactor = 1) {
  7859. const canvas = document.createElement("canvas");
  7860. const ctx = canvas.getContext("2d", {
  7861. alpha: false
  7862. });
  7863. const outputScale = new _ui_utils.OutputScale();
  7864. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7865. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7866. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7867. return {
  7868. ctx,
  7869. canvas,
  7870. transform
  7871. };
  7872. }
  7873. _convertCanvasToImage(canvas) {
  7874. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7875. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  7876. }
  7877. const reducedCanvas = this._reduceImage(canvas);
  7878. const image = document.createElement("img");
  7879. image.className = "thumbnailImage";
  7880. this._thumbPageCanvas.then(msg => {
  7881. image.setAttribute("aria-label", msg);
  7882. });
  7883. image.style.width = this.canvasWidth + "px";
  7884. image.style.height = this.canvasHeight + "px";
  7885. image.src = reducedCanvas.toDataURL();
  7886. this.image = image;
  7887. this.div.setAttribute("data-loaded", true);
  7888. this.ring.append(image);
  7889. reducedCanvas.width = 0;
  7890. reducedCanvas.height = 0;
  7891. }
  7892. draw() {
  7893. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7894. console.error("Must be in new state before drawing");
  7895. return Promise.resolve();
  7896. }
  7897. const {
  7898. pdfPage
  7899. } = this;
  7900. if (!pdfPage) {
  7901. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7902. return Promise.reject(new Error("pdfPage is not loaded"));
  7903. }
  7904. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7905. const finishRenderTask = async (error = null) => {
  7906. if (renderTask === this.renderTask) {
  7907. this.renderTask = null;
  7908. }
  7909. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7910. return;
  7911. }
  7912. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7913. this._convertCanvasToImage(canvas);
  7914. if (error) {
  7915. throw error;
  7916. }
  7917. };
  7918. const {
  7919. ctx,
  7920. canvas,
  7921. transform
  7922. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7923. const drawViewport = this.viewport.clone({
  7924. scale: DRAW_UPSCALE_FACTOR * this.scale
  7925. });
  7926. const renderContinueCallback = cont => {
  7927. if (!this.renderingQueue.isHighestPriority(this)) {
  7928. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  7929. this.resume = () => {
  7930. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7931. cont();
  7932. };
  7933. return;
  7934. }
  7935. cont();
  7936. };
  7937. const renderContext = {
  7938. canvasContext: ctx,
  7939. transform,
  7940. viewport: drawViewport,
  7941. optionalContentConfigPromise: this._optionalContentConfigPromise,
  7942. pageColors: this.pageColors
  7943. };
  7944. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7945. renderTask.onContinue = renderContinueCallback;
  7946. const resultPromise = renderTask.promise.then(function () {
  7947. return finishRenderTask(null);
  7948. }, function (error) {
  7949. return finishRenderTask(error);
  7950. });
  7951. resultPromise.finally(() => {
  7952. canvas.width = 0;
  7953. canvas.height = 0;
  7954. const pageCached = this.linkService.isPageCached(this.id);
  7955. if (!pageCached) {
  7956. this.pdfPage?.cleanup();
  7957. }
  7958. });
  7959. return resultPromise;
  7960. }
  7961. setImage(pageView) {
  7962. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7963. return;
  7964. }
  7965. const {
  7966. thumbnailCanvas: canvas,
  7967. pdfPage,
  7968. scale
  7969. } = pageView;
  7970. if (!canvas) {
  7971. return;
  7972. }
  7973. if (!this.pdfPage) {
  7974. this.setPdfPage(pdfPage);
  7975. }
  7976. if (scale < this.scale) {
  7977. return;
  7978. }
  7979. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7980. this._convertCanvasToImage(canvas);
  7981. }
  7982. _reduceImage(img) {
  7983. const {
  7984. ctx,
  7985. canvas
  7986. } = this._getPageDrawContext();
  7987. if (img.width <= 2 * canvas.width) {
  7988. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7989. return canvas;
  7990. }
  7991. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7992. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7993. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7994. while (reducedWidth > img.width || reducedHeight > img.height) {
  7995. reducedWidth >>= 1;
  7996. reducedHeight >>= 1;
  7997. }
  7998. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7999. while (reducedWidth > 2 * canvas.width) {
  8000. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  8001. reducedWidth >>= 1;
  8002. reducedHeight >>= 1;
  8003. }
  8004. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  8005. return canvas;
  8006. }
  8007. get _thumbPageTitle() {
  8008. return this.l10n.get("thumb_page_title", {
  8009. page: this.pageLabel ?? this.id
  8010. });
  8011. }
  8012. get _thumbPageCanvas() {
  8013. return this.l10n.get("thumb_page_canvas", {
  8014. page: this.pageLabel ?? this.id
  8015. });
  8016. }
  8017. setPageLabel(label) {
  8018. this.pageLabel = typeof label === "string" ? label : null;
  8019. this._thumbPageTitle.then(msg => {
  8020. this.anchor.title = msg;
  8021. });
  8022. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8023. return;
  8024. }
  8025. this._thumbPageCanvas.then(msg => {
  8026. this.image?.setAttribute("aria-label", msg);
  8027. });
  8028. }
  8029. }
  8030. exports.PDFThumbnailView = PDFThumbnailView;
  8031. /***/ }),
  8032. /* 28 */
  8033. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8034. Object.defineProperty(exports, "__esModule", ({
  8035. value: true
  8036. }));
  8037. exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
  8038. var _pdfjsLib = __webpack_require__(5);
  8039. var _ui_utils = __webpack_require__(1);
  8040. var _annotation_editor_layer_builder = __webpack_require__(29);
  8041. var _annotation_layer_builder = __webpack_require__(31);
  8042. var _l10n_utils = __webpack_require__(30);
  8043. var _pdf_page_view = __webpack_require__(32);
  8044. var _pdf_rendering_queue = __webpack_require__(22);
  8045. var _pdf_link_service = __webpack_require__(3);
  8046. var _struct_tree_layer_builder = __webpack_require__(34);
  8047. var _text_highlighter = __webpack_require__(35);
  8048. var _text_layer_builder = __webpack_require__(36);
  8049. var _xfa_layer_builder = __webpack_require__(37);
  8050. const DEFAULT_CACHE_SIZE = 10;
  8051. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  8052. const PagesCountLimit = {
  8053. FORCE_SCROLL_MODE_PAGE: 15000,
  8054. FORCE_LAZY_PAGE_INIT: 7500,
  8055. PAUSE_EAGER_PAGE_INIT: 250
  8056. };
  8057. exports.PagesCountLimit = PagesCountLimit;
  8058. function isValidAnnotationEditorMode(mode) {
  8059. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  8060. }
  8061. class PDFPageViewBuffer {
  8062. #buf = new Set();
  8063. #size = 0;
  8064. constructor(size) {
  8065. this.#size = size;
  8066. }
  8067. push(view) {
  8068. const buf = this.#buf;
  8069. if (buf.has(view)) {
  8070. buf.delete(view);
  8071. }
  8072. buf.add(view);
  8073. if (buf.size > this.#size) {
  8074. this.#destroyFirstView();
  8075. }
  8076. }
  8077. resize(newSize, idsToKeep = null) {
  8078. this.#size = newSize;
  8079. const buf = this.#buf;
  8080. if (idsToKeep) {
  8081. const ii = buf.size;
  8082. let i = 1;
  8083. for (const view of buf) {
  8084. if (idsToKeep.has(view.id)) {
  8085. buf.delete(view);
  8086. buf.add(view);
  8087. }
  8088. if (++i > ii) {
  8089. break;
  8090. }
  8091. }
  8092. }
  8093. while (buf.size > this.#size) {
  8094. this.#destroyFirstView();
  8095. }
  8096. }
  8097. has(view) {
  8098. return this.#buf.has(view);
  8099. }
  8100. [Symbol.iterator]() {
  8101. return this.#buf.keys();
  8102. }
  8103. #destroyFirstView() {
  8104. const firstView = this.#buf.keys().next().value;
  8105. firstView?.destroy();
  8106. this.#buf.delete(firstView);
  8107. }
  8108. }
  8109. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  8110. class PDFViewer {
  8111. #buffer = null;
  8112. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  8113. #annotationEditorUIManager = null;
  8114. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8115. #enablePermissions = false;
  8116. #previousContainerHeight = 0;
  8117. #scrollModePageState = null;
  8118. #onVisibilityChange = null;
  8119. constructor(options) {
  8120. const viewerVersion = '3.1.81';
  8121. if (_pdfjsLib.version !== viewerVersion) {
  8122. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  8123. }
  8124. this.container = options.container;
  8125. this.viewer = options.viewer || options.container.firstElementChild;
  8126. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  8127. throw new Error("Invalid `container` and/or `viewer` option.");
  8128. }
  8129. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  8130. throw new Error("The `container` must be absolutely positioned.");
  8131. }
  8132. this.eventBus = options.eventBus;
  8133. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8134. this.downloadManager = options.downloadManager || null;
  8135. this.findController = options.findController || null;
  8136. this._scriptingManager = options.scriptingManager || null;
  8137. this.removePageBorders = options.removePageBorders || false;
  8138. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  8139. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8140. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
  8141. this.imageResourcesPath = options.imageResourcesPath || "";
  8142. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8143. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  8144. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  8145. this.maxCanvasPixels = options.maxCanvasPixels;
  8146. this.l10n = options.l10n || _l10n_utils.NullL10n;
  8147. this.#enablePermissions = options.enablePermissions || false;
  8148. this.pageColors = options.pageColors || null;
  8149. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  8150. if (this.pageColors.background || this.pageColors.foreground) {
  8151. console.warn("PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  8152. }
  8153. this.pageColors = null;
  8154. }
  8155. this.defaultRenderingQueue = !options.renderingQueue;
  8156. if (this.defaultRenderingQueue) {
  8157. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8158. this.renderingQueue.setViewer(this);
  8159. } else {
  8160. this.renderingQueue = options.renderingQueue;
  8161. }
  8162. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8163. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8164. this._onBeforeDraw = this._onAfterDraw = null;
  8165. this._resetView();
  8166. if (this.removePageBorders) {
  8167. this.viewer.classList.add("removePageBorders");
  8168. }
  8169. this.updateContainerHeightCss();
  8170. }
  8171. get pagesCount() {
  8172. return this._pages.length;
  8173. }
  8174. getPageView(index) {
  8175. return this._pages[index];
  8176. }
  8177. get pageViewsReady() {
  8178. if (!this._pagesCapability.settled) {
  8179. return false;
  8180. }
  8181. return this._pages.every(function (pageView) {
  8182. return pageView?.pdfPage;
  8183. });
  8184. }
  8185. get renderForms() {
  8186. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8187. }
  8188. get enableScripting() {
  8189. return !!this._scriptingManager;
  8190. }
  8191. get currentPageNumber() {
  8192. return this._currentPageNumber;
  8193. }
  8194. set currentPageNumber(val) {
  8195. if (!Number.isInteger(val)) {
  8196. throw new Error("Invalid page number.");
  8197. }
  8198. if (!this.pdfDocument) {
  8199. return;
  8200. }
  8201. if (!this._setCurrentPageNumber(val, true)) {
  8202. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  8203. }
  8204. }
  8205. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  8206. if (this._currentPageNumber === val) {
  8207. if (resetCurrentPageView) {
  8208. this.#resetCurrentPageView();
  8209. }
  8210. return true;
  8211. }
  8212. if (!(0 < val && val <= this.pagesCount)) {
  8213. return false;
  8214. }
  8215. const previous = this._currentPageNumber;
  8216. this._currentPageNumber = val;
  8217. this.eventBus.dispatch("pagechanging", {
  8218. source: this,
  8219. pageNumber: val,
  8220. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8221. previous
  8222. });
  8223. if (resetCurrentPageView) {
  8224. this.#resetCurrentPageView();
  8225. }
  8226. return true;
  8227. }
  8228. get currentPageLabel() {
  8229. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8230. }
  8231. set currentPageLabel(val) {
  8232. if (!this.pdfDocument) {
  8233. return;
  8234. }
  8235. let page = val | 0;
  8236. if (this._pageLabels) {
  8237. const i = this._pageLabels.indexOf(val);
  8238. if (i >= 0) {
  8239. page = i + 1;
  8240. }
  8241. }
  8242. if (!this._setCurrentPageNumber(page, true)) {
  8243. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8244. }
  8245. }
  8246. get currentScale() {
  8247. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8248. }
  8249. set currentScale(val) {
  8250. if (isNaN(val)) {
  8251. throw new Error("Invalid numeric scale.");
  8252. }
  8253. if (!this.pdfDocument) {
  8254. return;
  8255. }
  8256. this._setScale(val, false);
  8257. }
  8258. get currentScaleValue() {
  8259. return this._currentScaleValue;
  8260. }
  8261. set currentScaleValue(val) {
  8262. if (!this.pdfDocument) {
  8263. return;
  8264. }
  8265. this._setScale(val, false);
  8266. }
  8267. get pagesRotation() {
  8268. return this._pagesRotation;
  8269. }
  8270. set pagesRotation(rotation) {
  8271. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8272. throw new Error("Invalid pages rotation angle.");
  8273. }
  8274. if (!this.pdfDocument) {
  8275. return;
  8276. }
  8277. rotation %= 360;
  8278. if (rotation < 0) {
  8279. rotation += 360;
  8280. }
  8281. if (this._pagesRotation === rotation) {
  8282. return;
  8283. }
  8284. this._pagesRotation = rotation;
  8285. const pageNumber = this._currentPageNumber;
  8286. const updateArgs = {
  8287. rotation
  8288. };
  8289. for (const pageView of this._pages) {
  8290. pageView.update(updateArgs);
  8291. }
  8292. if (this._currentScaleValue) {
  8293. this._setScale(this._currentScaleValue, true);
  8294. }
  8295. this.eventBus.dispatch("rotationchanging", {
  8296. source: this,
  8297. pagesRotation: rotation,
  8298. pageNumber
  8299. });
  8300. if (this.defaultRenderingQueue) {
  8301. this.update();
  8302. }
  8303. }
  8304. get firstPagePromise() {
  8305. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8306. }
  8307. get onePageRendered() {
  8308. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8309. }
  8310. get pagesPromise() {
  8311. return this.pdfDocument ? this._pagesCapability.promise : null;
  8312. }
  8313. #initializePermissions(permissions) {
  8314. const params = {
  8315. annotationEditorMode: this.#annotationEditorMode,
  8316. annotationMode: this.#annotationMode,
  8317. textLayerMode: this.textLayerMode
  8318. };
  8319. if (!permissions) {
  8320. return params;
  8321. }
  8322. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  8323. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  8324. }
  8325. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  8326. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8327. }
  8328. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8329. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8330. }
  8331. return params;
  8332. }
  8333. #onePageRenderedOrForceFetch() {
  8334. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8335. return Promise.resolve();
  8336. }
  8337. const visibilityChangePromise = new Promise(resolve => {
  8338. this.#onVisibilityChange = () => {
  8339. if (document.visibilityState !== "hidden") {
  8340. return;
  8341. }
  8342. resolve();
  8343. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8344. this.#onVisibilityChange = null;
  8345. };
  8346. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8347. });
  8348. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8349. }
  8350. setDocument(pdfDocument) {
  8351. if (this.pdfDocument) {
  8352. this.eventBus.dispatch("pagesdestroy", {
  8353. source: this
  8354. });
  8355. this._cancelRendering();
  8356. this._resetView();
  8357. this.findController?.setDocument(null);
  8358. this._scriptingManager?.setDocument(null);
  8359. if (this.#annotationEditorUIManager) {
  8360. this.#annotationEditorUIManager.destroy();
  8361. this.#annotationEditorUIManager = null;
  8362. }
  8363. }
  8364. this.pdfDocument = pdfDocument;
  8365. if (!pdfDocument) {
  8366. return;
  8367. }
  8368. const isPureXfa = pdfDocument.isPureXfa;
  8369. const pagesCount = pdfDocument.numPages;
  8370. const firstPagePromise = pdfDocument.getPage(1);
  8371. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8372. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8373. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8374. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8375. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8376. this.eventBus.dispatch("scrollmodechanged", {
  8377. source: this,
  8378. mode
  8379. });
  8380. }
  8381. this._pagesCapability.promise.then(() => {
  8382. this.eventBus.dispatch("pagesloaded", {
  8383. source: this,
  8384. pagesCount
  8385. });
  8386. }, () => {});
  8387. this._onBeforeDraw = evt => {
  8388. const pageView = this._pages[evt.pageNumber - 1];
  8389. if (!pageView) {
  8390. return;
  8391. }
  8392. this.#buffer.push(pageView);
  8393. };
  8394. this.eventBus._on("pagerender", this._onBeforeDraw);
  8395. this._onAfterDraw = evt => {
  8396. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8397. return;
  8398. }
  8399. this._onePageRenderedCapability.resolve({
  8400. timestamp: evt.timestamp
  8401. });
  8402. this.eventBus._off("pagerendered", this._onAfterDraw);
  8403. this._onAfterDraw = null;
  8404. if (this.#onVisibilityChange) {
  8405. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8406. this.#onVisibilityChange = null;
  8407. }
  8408. };
  8409. this.eventBus._on("pagerendered", this._onAfterDraw);
  8410. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8411. if (pdfDocument !== this.pdfDocument) {
  8412. return;
  8413. }
  8414. this._firstPageCapability.resolve(firstPdfPage);
  8415. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8416. const {
  8417. annotationEditorMode,
  8418. annotationMode,
  8419. textLayerMode
  8420. } = this.#initializePermissions(permissions);
  8421. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  8422. const mode = annotationEditorMode;
  8423. if (isPureXfa) {
  8424. console.warn("Warning: XFA-editing is not implemented.");
  8425. } else if (isValidAnnotationEditorMode(mode)) {
  8426. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus);
  8427. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  8428. this.#annotationEditorUIManager.updateMode(mode);
  8429. }
  8430. } else {
  8431. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  8432. }
  8433. }
  8434. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8435. const scale = this.currentScale;
  8436. const viewport = firstPdfPage.getViewport({
  8437. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8438. });
  8439. const textLayerFactory = textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !isPureXfa ? this : null;
  8440. const annotationLayerFactory = annotationMode !== _pdfjsLib.AnnotationMode.DISABLE ? this : null;
  8441. const xfaLayerFactory = isPureXfa ? this : null;
  8442. const annotationEditorLayerFactory = this.#annotationEditorUIManager ? this : null;
  8443. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8444. const pageView = new _pdf_page_view.PDFPageView({
  8445. container: viewerElement,
  8446. eventBus: this.eventBus,
  8447. id: pageNum,
  8448. scale,
  8449. defaultViewport: viewport.clone(),
  8450. optionalContentConfigPromise,
  8451. renderingQueue: this.renderingQueue,
  8452. textLayerFactory,
  8453. textLayerMode,
  8454. annotationLayerFactory,
  8455. annotationMode,
  8456. xfaLayerFactory,
  8457. annotationEditorLayerFactory,
  8458. textHighlighterFactory: this,
  8459. structTreeLayerFactory: this,
  8460. imageResourcesPath: this.imageResourcesPath,
  8461. renderer: this.renderer,
  8462. useOnlyCssZoom: this.useOnlyCssZoom,
  8463. maxCanvasPixels: this.maxCanvasPixels,
  8464. pageColors: this.pageColors,
  8465. l10n: this.l10n
  8466. });
  8467. this._pages.push(pageView);
  8468. }
  8469. const firstPageView = this._pages[0];
  8470. if (firstPageView) {
  8471. firstPageView.setPdfPage(firstPdfPage);
  8472. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8473. }
  8474. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8475. this.#ensurePageViewVisible();
  8476. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8477. this._updateSpreadMode();
  8478. }
  8479. this.#onePageRenderedOrForceFetch().then(async () => {
  8480. this.findController?.setDocument(pdfDocument);
  8481. this._scriptingManager?.setDocument(pdfDocument);
  8482. if (this.#annotationEditorUIManager) {
  8483. this.eventBus.dispatch("annotationeditormodechanged", {
  8484. source: this,
  8485. mode: this.#annotationEditorMode
  8486. });
  8487. }
  8488. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8489. this._pagesCapability.resolve();
  8490. return;
  8491. }
  8492. let getPagesLeft = pagesCount - 1;
  8493. if (getPagesLeft <= 0) {
  8494. this._pagesCapability.resolve();
  8495. return;
  8496. }
  8497. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8498. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8499. const pageView = this._pages[pageNum - 1];
  8500. if (!pageView.pdfPage) {
  8501. pageView.setPdfPage(pdfPage);
  8502. }
  8503. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8504. if (--getPagesLeft === 0) {
  8505. this._pagesCapability.resolve();
  8506. }
  8507. }, reason => {
  8508. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8509. if (--getPagesLeft === 0) {
  8510. this._pagesCapability.resolve();
  8511. }
  8512. });
  8513. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8514. await promise;
  8515. }
  8516. }
  8517. });
  8518. this.eventBus.dispatch("pagesinit", {
  8519. source: this
  8520. });
  8521. pdfDocument.getMetadata().then(({
  8522. info
  8523. }) => {
  8524. if (pdfDocument !== this.pdfDocument) {
  8525. return;
  8526. }
  8527. if (info.Language) {
  8528. this.viewer.lang = info.Language;
  8529. }
  8530. });
  8531. if (this.defaultRenderingQueue) {
  8532. this.update();
  8533. }
  8534. }).catch(reason => {
  8535. console.error("Unable to initialize viewer", reason);
  8536. this._pagesCapability.reject(reason);
  8537. });
  8538. }
  8539. setPageLabels(labels) {
  8540. if (!this.pdfDocument) {
  8541. return;
  8542. }
  8543. if (!labels) {
  8544. this._pageLabels = null;
  8545. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8546. this._pageLabels = null;
  8547. console.error(`setPageLabels: Invalid page labels.`);
  8548. } else {
  8549. this._pageLabels = labels;
  8550. }
  8551. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8552. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8553. }
  8554. }
  8555. _resetView() {
  8556. this._pages = [];
  8557. this._currentPageNumber = 1;
  8558. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8559. this._currentScaleValue = null;
  8560. this._pageLabels = null;
  8561. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8562. this._location = null;
  8563. this._pagesRotation = 0;
  8564. this._optionalContentConfigPromise = null;
  8565. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8566. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8567. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8568. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8569. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8570. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8571. this.#scrollModePageState = {
  8572. previousPageNumber: 1,
  8573. scrollDown: true,
  8574. pages: []
  8575. };
  8576. if (this._onBeforeDraw) {
  8577. this.eventBus._off("pagerender", this._onBeforeDraw);
  8578. this._onBeforeDraw = null;
  8579. }
  8580. if (this._onAfterDraw) {
  8581. this.eventBus._off("pagerendered", this._onAfterDraw);
  8582. this._onAfterDraw = null;
  8583. }
  8584. if (this.#onVisibilityChange) {
  8585. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8586. this.#onVisibilityChange = null;
  8587. }
  8588. this.viewer.textContent = "";
  8589. this._updateScrollMode();
  8590. this.viewer.removeAttribute("lang");
  8591. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  8592. }
  8593. #ensurePageViewVisible() {
  8594. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8595. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8596. }
  8597. const pageNumber = this._currentPageNumber,
  8598. state = this.#scrollModePageState,
  8599. viewer = this.viewer;
  8600. viewer.textContent = "";
  8601. state.pages.length = 0;
  8602. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8603. const pageView = this._pages[pageNumber - 1];
  8604. viewer.append(pageView.div);
  8605. state.pages.push(pageView);
  8606. } else {
  8607. const pageIndexSet = new Set(),
  8608. parity = this._spreadMode - 1;
  8609. if (parity === -1) {
  8610. pageIndexSet.add(pageNumber - 1);
  8611. } else if (pageNumber % 2 !== parity) {
  8612. pageIndexSet.add(pageNumber - 1);
  8613. pageIndexSet.add(pageNumber);
  8614. } else {
  8615. pageIndexSet.add(pageNumber - 2);
  8616. pageIndexSet.add(pageNumber - 1);
  8617. }
  8618. const spread = document.createElement("div");
  8619. spread.className = "spread";
  8620. if (this.isInPresentationMode) {
  8621. const dummyPage = document.createElement("div");
  8622. dummyPage.className = "dummyPage";
  8623. spread.append(dummyPage);
  8624. }
  8625. for (const i of pageIndexSet) {
  8626. const pageView = this._pages[i];
  8627. if (!pageView) {
  8628. continue;
  8629. }
  8630. spread.append(pageView.div);
  8631. state.pages.push(pageView);
  8632. }
  8633. viewer.append(spread);
  8634. }
  8635. state.scrollDown = pageNumber >= state.previousPageNumber;
  8636. state.previousPageNumber = pageNumber;
  8637. }
  8638. _scrollUpdate() {
  8639. if (this.pagesCount === 0) {
  8640. return;
  8641. }
  8642. this.update();
  8643. }
  8644. #scrollIntoView(pageView, pageSpot = null) {
  8645. const {
  8646. div,
  8647. id
  8648. } = pageView;
  8649. if (this._currentPageNumber !== id) {
  8650. this._setCurrentPageNumber(id);
  8651. }
  8652. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8653. this.#ensurePageViewVisible();
  8654. this.update();
  8655. }
  8656. if (!pageSpot && !this.isInPresentationMode) {
  8657. const left = div.offsetLeft + div.clientLeft,
  8658. right = left + div.clientWidth;
  8659. const {
  8660. scrollLeft,
  8661. clientWidth
  8662. } = this.container;
  8663. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8664. pageSpot = {
  8665. left: 0,
  8666. top: 0
  8667. };
  8668. }
  8669. }
  8670. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8671. if (!this._currentScaleValue && this._location) {
  8672. this._location = null;
  8673. }
  8674. }
  8675. #isSameScale(newScale) {
  8676. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8677. }
  8678. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8679. this._currentScaleValue = newValue.toString();
  8680. if (this.#isSameScale(newScale)) {
  8681. if (preset) {
  8682. this.eventBus.dispatch("scalechanging", {
  8683. source: this,
  8684. scale: newScale,
  8685. presetValue: newValue
  8686. });
  8687. }
  8688. return;
  8689. }
  8690. _ui_utils.docStyle.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8691. const updateArgs = {
  8692. scale: newScale
  8693. };
  8694. for (const pageView of this._pages) {
  8695. pageView.update(updateArgs);
  8696. }
  8697. this._currentScale = newScale;
  8698. if (!noScroll) {
  8699. let page = this._currentPageNumber,
  8700. dest;
  8701. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8702. page = this._location.pageNumber;
  8703. dest = [null, {
  8704. name: "XYZ"
  8705. }, this._location.left, this._location.top, null];
  8706. }
  8707. this.scrollPageIntoView({
  8708. pageNumber: page,
  8709. destArray: dest,
  8710. allowNegativeOffset: true
  8711. });
  8712. }
  8713. this.eventBus.dispatch("scalechanging", {
  8714. source: this,
  8715. scale: newScale,
  8716. presetValue: preset ? newValue : undefined
  8717. });
  8718. if (this.defaultRenderingQueue) {
  8719. this.update();
  8720. }
  8721. this.updateContainerHeightCss();
  8722. }
  8723. get _pageWidthScaleFactor() {
  8724. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8725. return 2;
  8726. }
  8727. return 1;
  8728. }
  8729. _setScale(value, noScroll = false) {
  8730. let scale = parseFloat(value);
  8731. if (scale > 0) {
  8732. this._setScaleUpdatePages(scale, value, noScroll, false);
  8733. } else {
  8734. const currentPage = this._pages[this._currentPageNumber - 1];
  8735. if (!currentPage) {
  8736. return;
  8737. }
  8738. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8739. vPadding = _ui_utils.VERTICAL_PADDING;
  8740. if (this.isInPresentationMode) {
  8741. hPadding = vPadding = 4;
  8742. } else if (this.removePageBorders) {
  8743. hPadding = vPadding = 0;
  8744. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8745. [hPadding, vPadding] = [vPadding, hPadding];
  8746. }
  8747. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8748. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8749. switch (value) {
  8750. case "page-actual":
  8751. scale = 1;
  8752. break;
  8753. case "page-width":
  8754. scale = pageWidthScale;
  8755. break;
  8756. case "page-height":
  8757. scale = pageHeightScale;
  8758. break;
  8759. case "page-fit":
  8760. scale = Math.min(pageWidthScale, pageHeightScale);
  8761. break;
  8762. case "auto":
  8763. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8764. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8765. break;
  8766. default:
  8767. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  8768. return;
  8769. }
  8770. this._setScaleUpdatePages(scale, value, noScroll, true);
  8771. }
  8772. }
  8773. #resetCurrentPageView() {
  8774. const pageView = this._pages[this._currentPageNumber - 1];
  8775. if (this.isInPresentationMode) {
  8776. this._setScale(this._currentScaleValue, true);
  8777. }
  8778. this.#scrollIntoView(pageView);
  8779. }
  8780. pageLabelToPageNumber(label) {
  8781. if (!this._pageLabels) {
  8782. return null;
  8783. }
  8784. const i = this._pageLabels.indexOf(label);
  8785. if (i < 0) {
  8786. return null;
  8787. }
  8788. return i + 1;
  8789. }
  8790. scrollPageIntoView({
  8791. pageNumber,
  8792. destArray = null,
  8793. allowNegativeOffset = false,
  8794. ignoreDestinationZoom = false
  8795. }) {
  8796. if (!this.pdfDocument) {
  8797. return;
  8798. }
  8799. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8800. if (!pageView) {
  8801. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  8802. return;
  8803. }
  8804. if (this.isInPresentationMode || !destArray) {
  8805. this._setCurrentPageNumber(pageNumber, true);
  8806. return;
  8807. }
  8808. let x = 0,
  8809. y = 0;
  8810. let width = 0,
  8811. height = 0,
  8812. widthScale,
  8813. heightScale;
  8814. const changeOrientation = pageView.rotation % 180 !== 0;
  8815. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8816. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8817. let scale = 0;
  8818. switch (destArray[1].name) {
  8819. case "XYZ":
  8820. x = destArray[2];
  8821. y = destArray[3];
  8822. scale = destArray[4];
  8823. x = x !== null ? x : 0;
  8824. y = y !== null ? y : pageHeight;
  8825. break;
  8826. case "Fit":
  8827. case "FitB":
  8828. scale = "page-fit";
  8829. break;
  8830. case "FitH":
  8831. case "FitBH":
  8832. y = destArray[2];
  8833. scale = "page-width";
  8834. if (y === null && this._location) {
  8835. x = this._location.left;
  8836. y = this._location.top;
  8837. } else if (typeof y !== "number" || y < 0) {
  8838. y = pageHeight;
  8839. }
  8840. break;
  8841. case "FitV":
  8842. case "FitBV":
  8843. x = destArray[2];
  8844. width = pageWidth;
  8845. height = pageHeight;
  8846. scale = "page-height";
  8847. break;
  8848. case "FitR":
  8849. x = destArray[2];
  8850. y = destArray[3];
  8851. width = destArray[4] - x;
  8852. height = destArray[5] - y;
  8853. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8854. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8855. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8856. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8857. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8858. break;
  8859. default:
  8860. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  8861. return;
  8862. }
  8863. if (!ignoreDestinationZoom) {
  8864. if (scale && scale !== this._currentScale) {
  8865. this.currentScaleValue = scale;
  8866. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8867. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8868. }
  8869. }
  8870. if (scale === "page-fit" && !destArray[4]) {
  8871. this.#scrollIntoView(pageView);
  8872. return;
  8873. }
  8874. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8875. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8876. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8877. if (!allowNegativeOffset) {
  8878. left = Math.max(left, 0);
  8879. top = Math.max(top, 0);
  8880. }
  8881. this.#scrollIntoView(pageView, {
  8882. left,
  8883. top
  8884. });
  8885. }
  8886. _updateLocation(firstPage) {
  8887. const currentScale = this._currentScale;
  8888. const currentScaleValue = this._currentScaleValue;
  8889. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8890. const pageNumber = firstPage.id;
  8891. const currentPageView = this._pages[pageNumber - 1];
  8892. const container = this.container;
  8893. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8894. const intLeft = Math.round(topLeft[0]);
  8895. const intTop = Math.round(topLeft[1]);
  8896. let pdfOpenParams = `#page=${pageNumber}`;
  8897. if (!this.isInPresentationMode) {
  8898. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  8899. }
  8900. this._location = {
  8901. pageNumber,
  8902. scale: normalizedScaleValue,
  8903. top: intTop,
  8904. left: intLeft,
  8905. rotation: this._pagesRotation,
  8906. pdfOpenParams
  8907. };
  8908. }
  8909. update() {
  8910. const visible = this._getVisiblePages();
  8911. const visiblePages = visible.views,
  8912. numVisiblePages = visiblePages.length;
  8913. if (numVisiblePages === 0) {
  8914. return;
  8915. }
  8916. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8917. this.#buffer.resize(newCacheSize, visible.ids);
  8918. this.renderingQueue.renderHighestPriority(visible);
  8919. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  8920. const currentId = this._currentPageNumber;
  8921. let stillFullyVisible = false;
  8922. for (const page of visiblePages) {
  8923. if (page.percent < 100) {
  8924. break;
  8925. }
  8926. if (page.id === currentId && isSimpleLayout) {
  8927. stillFullyVisible = true;
  8928. break;
  8929. }
  8930. }
  8931. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  8932. this._updateLocation(visible.first);
  8933. this.eventBus.dispatch("updateviewarea", {
  8934. source: this,
  8935. location: this._location
  8936. });
  8937. }
  8938. containsElement(element) {
  8939. return this.container.contains(element);
  8940. }
  8941. focus() {
  8942. this.container.focus();
  8943. }
  8944. get _isContainerRtl() {
  8945. return getComputedStyle(this.container).direction === "rtl";
  8946. }
  8947. get isInPresentationMode() {
  8948. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8949. }
  8950. get isChangingPresentationMode() {
  8951. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8952. }
  8953. get isHorizontalScrollbarEnabled() {
  8954. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8955. }
  8956. get isVerticalScrollbarEnabled() {
  8957. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8958. }
  8959. _getVisiblePages() {
  8960. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  8961. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  8962. rtl = horizontal && this._isContainerRtl;
  8963. return (0, _ui_utils.getVisibleElements)({
  8964. scrollEl: this.container,
  8965. views,
  8966. sortByVisibility: true,
  8967. horizontal,
  8968. rtl
  8969. });
  8970. }
  8971. isPageVisible(pageNumber) {
  8972. if (!this.pdfDocument) {
  8973. return false;
  8974. }
  8975. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8976. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  8977. return false;
  8978. }
  8979. return this._getVisiblePages().ids.has(pageNumber);
  8980. }
  8981. isPageCached(pageNumber) {
  8982. if (!this.pdfDocument) {
  8983. return false;
  8984. }
  8985. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8986. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  8987. return false;
  8988. }
  8989. const pageView = this._pages[pageNumber - 1];
  8990. return this.#buffer.has(pageView);
  8991. }
  8992. cleanup() {
  8993. for (const pageView of this._pages) {
  8994. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8995. pageView.reset();
  8996. }
  8997. }
  8998. }
  8999. _cancelRendering() {
  9000. for (const pageView of this._pages) {
  9001. pageView.cancelRendering();
  9002. }
  9003. }
  9004. async #ensurePdfPageLoaded(pageView) {
  9005. if (pageView.pdfPage) {
  9006. return pageView.pdfPage;
  9007. }
  9008. try {
  9009. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  9010. if (!pageView.pdfPage) {
  9011. pageView.setPdfPage(pdfPage);
  9012. }
  9013. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  9014. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  9015. }
  9016. return pdfPage;
  9017. } catch (reason) {
  9018. console.error("Unable to get page for page view", reason);
  9019. return null;
  9020. }
  9021. }
  9022. #getScrollAhead(visible) {
  9023. if (visible.first?.id === 1) {
  9024. return true;
  9025. } else if (visible.last?.id === this.pagesCount) {
  9026. return false;
  9027. }
  9028. switch (this._scrollMode) {
  9029. case _ui_utils.ScrollMode.PAGE:
  9030. return this.#scrollModePageState.scrollDown;
  9031. case _ui_utils.ScrollMode.HORIZONTAL:
  9032. return this.scroll.right;
  9033. }
  9034. return this.scroll.down;
  9035. }
  9036. #toggleLoadingIconSpinner(visibleIds) {
  9037. for (const id of visibleIds) {
  9038. const pageView = this._pages[id - 1];
  9039. pageView?.toggleLoadingIconSpinner(true);
  9040. }
  9041. for (const pageView of this.#buffer) {
  9042. if (visibleIds.has(pageView.id)) {
  9043. continue;
  9044. }
  9045. pageView.toggleLoadingIconSpinner(false);
  9046. }
  9047. }
  9048. forceRendering(currentlyVisiblePages) {
  9049. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9050. const scrollAhead = this.#getScrollAhead(visiblePages);
  9051. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9052. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9053. this.#toggleLoadingIconSpinner(visiblePages.ids);
  9054. if (pageView) {
  9055. this.#ensurePdfPageLoaded(pageView).then(() => {
  9056. this.renderingQueue.renderView(pageView);
  9057. });
  9058. return true;
  9059. }
  9060. return false;
  9061. }
  9062. createTextLayerBuilder({
  9063. textLayerDiv,
  9064. pageIndex,
  9065. viewport,
  9066. eventBus,
  9067. highlighter,
  9068. accessibilityManager = null
  9069. }) {
  9070. return new _text_layer_builder.TextLayerBuilder({
  9071. textLayerDiv,
  9072. eventBus,
  9073. pageIndex,
  9074. viewport,
  9075. highlighter,
  9076. accessibilityManager
  9077. });
  9078. }
  9079. createTextHighlighter({
  9080. pageIndex,
  9081. eventBus
  9082. }) {
  9083. return new _text_highlighter.TextHighlighter({
  9084. eventBus,
  9085. pageIndex,
  9086. findController: this.isInPresentationMode ? null : this.findController
  9087. });
  9088. }
  9089. createAnnotationLayerBuilder({
  9090. pageDiv,
  9091. pdfPage,
  9092. annotationStorage = this.pdfDocument?.annotationStorage,
  9093. imageResourcesPath = "",
  9094. renderForms = true,
  9095. l10n = _l10n_utils.NullL10n,
  9096. enableScripting = this.enableScripting,
  9097. hasJSActionsPromise = this.pdfDocument?.hasJSActions(),
  9098. mouseState = this._scriptingManager?.mouseState,
  9099. fieldObjectsPromise = this.pdfDocument?.getFieldObjects(),
  9100. annotationCanvasMap = null,
  9101. accessibilityManager = null
  9102. }) {
  9103. return new _annotation_layer_builder.AnnotationLayerBuilder({
  9104. pageDiv,
  9105. pdfPage,
  9106. annotationStorage,
  9107. imageResourcesPath,
  9108. renderForms,
  9109. linkService: this.linkService,
  9110. downloadManager: this.downloadManager,
  9111. l10n,
  9112. enableScripting,
  9113. hasJSActionsPromise,
  9114. mouseState,
  9115. fieldObjectsPromise,
  9116. annotationCanvasMap,
  9117. accessibilityManager
  9118. });
  9119. }
  9120. createAnnotationEditorLayerBuilder({
  9121. uiManager = this.#annotationEditorUIManager,
  9122. pageDiv,
  9123. pdfPage,
  9124. accessibilityManager = null,
  9125. l10n,
  9126. annotationStorage = this.pdfDocument?.annotationStorage
  9127. }) {
  9128. return new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  9129. uiManager,
  9130. pageDiv,
  9131. pdfPage,
  9132. annotationStorage,
  9133. accessibilityManager,
  9134. l10n
  9135. });
  9136. }
  9137. createXfaLayerBuilder({
  9138. pageDiv,
  9139. pdfPage,
  9140. annotationStorage = this.pdfDocument?.annotationStorage
  9141. }) {
  9142. return new _xfa_layer_builder.XfaLayerBuilder({
  9143. pageDiv,
  9144. pdfPage,
  9145. annotationStorage,
  9146. linkService: this.linkService
  9147. });
  9148. }
  9149. createStructTreeLayerBuilder({
  9150. pdfPage
  9151. }) {
  9152. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  9153. pdfPage
  9154. });
  9155. }
  9156. get hasEqualPageSizes() {
  9157. const firstPageView = this._pages[0];
  9158. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  9159. const pageView = this._pages[i];
  9160. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9161. return false;
  9162. }
  9163. }
  9164. return true;
  9165. }
  9166. getPagesOverview() {
  9167. return this._pages.map(pageView => {
  9168. const viewport = pageView.pdfPage.getViewport({
  9169. scale: 1
  9170. });
  9171. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  9172. return {
  9173. width: viewport.width,
  9174. height: viewport.height,
  9175. rotation: viewport.rotation
  9176. };
  9177. }
  9178. return {
  9179. width: viewport.height,
  9180. height: viewport.width,
  9181. rotation: (viewport.rotation - 90) % 360
  9182. };
  9183. });
  9184. }
  9185. get optionalContentConfigPromise() {
  9186. if (!this.pdfDocument) {
  9187. return Promise.resolve(null);
  9188. }
  9189. if (!this._optionalContentConfigPromise) {
  9190. console.error("optionalContentConfigPromise: Not initialized yet.");
  9191. return this.pdfDocument.getOptionalContentConfig();
  9192. }
  9193. return this._optionalContentConfigPromise;
  9194. }
  9195. set optionalContentConfigPromise(promise) {
  9196. if (!(promise instanceof Promise)) {
  9197. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  9198. }
  9199. if (!this.pdfDocument) {
  9200. return;
  9201. }
  9202. if (!this._optionalContentConfigPromise) {
  9203. return;
  9204. }
  9205. this._optionalContentConfigPromise = promise;
  9206. const updateArgs = {
  9207. optionalContentConfigPromise: promise
  9208. };
  9209. for (const pageView of this._pages) {
  9210. pageView.update(updateArgs);
  9211. }
  9212. this.update();
  9213. this.eventBus.dispatch("optionalcontentconfigchanged", {
  9214. source: this,
  9215. promise
  9216. });
  9217. }
  9218. get scrollMode() {
  9219. return this._scrollMode;
  9220. }
  9221. set scrollMode(mode) {
  9222. if (this._scrollMode === mode) {
  9223. return;
  9224. }
  9225. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9226. throw new Error(`Invalid scroll mode: ${mode}`);
  9227. }
  9228. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9229. return;
  9230. }
  9231. this._previousScrollMode = this._scrollMode;
  9232. this._scrollMode = mode;
  9233. this.eventBus.dispatch("scrollmodechanged", {
  9234. source: this,
  9235. mode
  9236. });
  9237. this._updateScrollMode(this._currentPageNumber);
  9238. }
  9239. _updateScrollMode(pageNumber = null) {
  9240. const scrollMode = this._scrollMode,
  9241. viewer = this.viewer;
  9242. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9243. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9244. if (!this.pdfDocument || !pageNumber) {
  9245. return;
  9246. }
  9247. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9248. this.#ensurePageViewVisible();
  9249. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9250. this._updateSpreadMode();
  9251. }
  9252. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9253. this._setScale(this._currentScaleValue, true);
  9254. }
  9255. this._setCurrentPageNumber(pageNumber, true);
  9256. this.update();
  9257. }
  9258. get spreadMode() {
  9259. return this._spreadMode;
  9260. }
  9261. set spreadMode(mode) {
  9262. if (this._spreadMode === mode) {
  9263. return;
  9264. }
  9265. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9266. throw new Error(`Invalid spread mode: ${mode}`);
  9267. }
  9268. this._spreadMode = mode;
  9269. this.eventBus.dispatch("spreadmodechanged", {
  9270. source: this,
  9271. mode
  9272. });
  9273. this._updateSpreadMode(this._currentPageNumber);
  9274. }
  9275. _updateSpreadMode(pageNumber = null) {
  9276. if (!this.pdfDocument) {
  9277. return;
  9278. }
  9279. const viewer = this.viewer,
  9280. pages = this._pages;
  9281. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9282. this.#ensurePageViewVisible();
  9283. } else {
  9284. viewer.textContent = "";
  9285. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9286. for (const pageView of this._pages) {
  9287. viewer.append(pageView.div);
  9288. }
  9289. } else {
  9290. const parity = this._spreadMode - 1;
  9291. let spread = null;
  9292. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9293. if (spread === null) {
  9294. spread = document.createElement("div");
  9295. spread.className = "spread";
  9296. viewer.append(spread);
  9297. } else if (i % 2 === parity) {
  9298. spread = spread.cloneNode(false);
  9299. viewer.append(spread);
  9300. }
  9301. spread.append(pages[i].div);
  9302. }
  9303. }
  9304. }
  9305. if (!pageNumber) {
  9306. return;
  9307. }
  9308. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9309. this._setScale(this._currentScaleValue, true);
  9310. }
  9311. this._setCurrentPageNumber(pageNumber, true);
  9312. this.update();
  9313. }
  9314. _getPageAdvance(currentPageNumber, previous = false) {
  9315. switch (this._scrollMode) {
  9316. case _ui_utils.ScrollMode.WRAPPED:
  9317. {
  9318. const {
  9319. views
  9320. } = this._getVisiblePages(),
  9321. pageLayout = new Map();
  9322. for (const {
  9323. id,
  9324. y,
  9325. percent,
  9326. widthPercent
  9327. } of views) {
  9328. if (percent === 0 || widthPercent < 100) {
  9329. continue;
  9330. }
  9331. let yArray = pageLayout.get(y);
  9332. if (!yArray) {
  9333. pageLayout.set(y, yArray ||= []);
  9334. }
  9335. yArray.push(id);
  9336. }
  9337. for (const yArray of pageLayout.values()) {
  9338. const currentIndex = yArray.indexOf(currentPageNumber);
  9339. if (currentIndex === -1) {
  9340. continue;
  9341. }
  9342. const numPages = yArray.length;
  9343. if (numPages === 1) {
  9344. break;
  9345. }
  9346. if (previous) {
  9347. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9348. const currentId = yArray[i],
  9349. expectedId = yArray[i + 1] - 1;
  9350. if (currentId < expectedId) {
  9351. return currentPageNumber - expectedId;
  9352. }
  9353. }
  9354. } else {
  9355. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9356. const currentId = yArray[i],
  9357. expectedId = yArray[i - 1] + 1;
  9358. if (currentId > expectedId) {
  9359. return expectedId - currentPageNumber;
  9360. }
  9361. }
  9362. }
  9363. if (previous) {
  9364. const firstId = yArray[0];
  9365. if (firstId < currentPageNumber) {
  9366. return currentPageNumber - firstId + 1;
  9367. }
  9368. } else {
  9369. const lastId = yArray[numPages - 1];
  9370. if (lastId > currentPageNumber) {
  9371. return lastId - currentPageNumber + 1;
  9372. }
  9373. }
  9374. break;
  9375. }
  9376. break;
  9377. }
  9378. case _ui_utils.ScrollMode.HORIZONTAL:
  9379. {
  9380. break;
  9381. }
  9382. case _ui_utils.ScrollMode.PAGE:
  9383. case _ui_utils.ScrollMode.VERTICAL:
  9384. {
  9385. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9386. break;
  9387. }
  9388. const parity = this._spreadMode - 1;
  9389. if (previous && currentPageNumber % 2 !== parity) {
  9390. break;
  9391. } else if (!previous && currentPageNumber % 2 === parity) {
  9392. break;
  9393. }
  9394. const {
  9395. views
  9396. } = this._getVisiblePages(),
  9397. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9398. for (const {
  9399. id,
  9400. percent,
  9401. widthPercent
  9402. } of views) {
  9403. if (id !== expectedId) {
  9404. continue;
  9405. }
  9406. if (percent > 0 && widthPercent === 100) {
  9407. return 2;
  9408. }
  9409. break;
  9410. }
  9411. break;
  9412. }
  9413. }
  9414. return 1;
  9415. }
  9416. nextPage() {
  9417. const currentPageNumber = this._currentPageNumber,
  9418. pagesCount = this.pagesCount;
  9419. if (currentPageNumber >= pagesCount) {
  9420. return false;
  9421. }
  9422. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9423. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9424. return true;
  9425. }
  9426. previousPage() {
  9427. const currentPageNumber = this._currentPageNumber;
  9428. if (currentPageNumber <= 1) {
  9429. return false;
  9430. }
  9431. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9432. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9433. return true;
  9434. }
  9435. increaseScale(steps = 1) {
  9436. let newScale = this._currentScale;
  9437. do {
  9438. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9439. newScale = Math.ceil(newScale * 10) / 10;
  9440. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  9441. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9442. this.currentScaleValue = newScale;
  9443. }
  9444. decreaseScale(steps = 1) {
  9445. let newScale = this._currentScale;
  9446. do {
  9447. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9448. newScale = Math.floor(newScale * 10) / 10;
  9449. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  9450. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9451. this.currentScaleValue = newScale;
  9452. }
  9453. updateContainerHeightCss() {
  9454. const height = this.container.clientHeight;
  9455. if (height !== this.#previousContainerHeight) {
  9456. this.#previousContainerHeight = height;
  9457. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  9458. }
  9459. }
  9460. get annotationEditorMode() {
  9461. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  9462. }
  9463. set annotationEditorMode(mode) {
  9464. if (!this.#annotationEditorUIManager) {
  9465. throw new Error(`The AnnotationEditor is not enabled.`);
  9466. }
  9467. if (this.#annotationEditorMode === mode) {
  9468. return;
  9469. }
  9470. if (!isValidAnnotationEditorMode(mode)) {
  9471. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  9472. }
  9473. if (!this.pdfDocument) {
  9474. return;
  9475. }
  9476. this.#annotationEditorMode = mode;
  9477. this.eventBus.dispatch("annotationeditormodechanged", {
  9478. source: this,
  9479. mode
  9480. });
  9481. this.#annotationEditorUIManager.updateMode(mode);
  9482. }
  9483. set annotationEditorParams({
  9484. type,
  9485. value
  9486. }) {
  9487. if (!this.#annotationEditorUIManager) {
  9488. throw new Error(`The AnnotationEditor is not enabled.`);
  9489. }
  9490. this.#annotationEditorUIManager.updateParams(type, value);
  9491. }
  9492. refresh() {
  9493. if (!this.pdfDocument) {
  9494. return;
  9495. }
  9496. const updateArgs = {};
  9497. for (const pageView of this._pages) {
  9498. pageView.update(updateArgs);
  9499. }
  9500. this.update();
  9501. }
  9502. }
  9503. exports.PDFViewer = PDFViewer;
  9504. /***/ }),
  9505. /* 29 */
  9506. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9507. Object.defineProperty(exports, "__esModule", ({
  9508. value: true
  9509. }));
  9510. exports.AnnotationEditorLayerBuilder = void 0;
  9511. var _pdfjsLib = __webpack_require__(5);
  9512. var _l10n_utils = __webpack_require__(30);
  9513. class AnnotationEditorLayerBuilder {
  9514. #uiManager;
  9515. constructor(options) {
  9516. this.pageDiv = options.pageDiv;
  9517. this.pdfPage = options.pdfPage;
  9518. this.annotationStorage = options.annotationStorage || null;
  9519. this.accessibilityManager = options.accessibilityManager;
  9520. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9521. this.annotationEditorLayer = null;
  9522. this.div = null;
  9523. this._cancelled = false;
  9524. this.#uiManager = options.uiManager;
  9525. }
  9526. async render(viewport, intent = "display") {
  9527. if (intent !== "display") {
  9528. return;
  9529. }
  9530. if (this._cancelled) {
  9531. return;
  9532. }
  9533. const clonedViewport = viewport.clone({
  9534. dontFlip: true
  9535. });
  9536. if (this.div) {
  9537. this.annotationEditorLayer.update({
  9538. viewport: clonedViewport
  9539. });
  9540. this.show();
  9541. return;
  9542. }
  9543. this.div = document.createElement("div");
  9544. this.div.className = "annotationEditorLayer";
  9545. this.div.tabIndex = 0;
  9546. this.pageDiv.append(this.div);
  9547. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  9548. uiManager: this.#uiManager,
  9549. div: this.div,
  9550. annotationStorage: this.annotationStorage,
  9551. accessibilityManager: this.accessibilityManager,
  9552. pageIndex: this.pdfPage._pageIndex,
  9553. l10n: this.l10n,
  9554. viewport: clonedViewport
  9555. });
  9556. const parameters = {
  9557. viewport: clonedViewport,
  9558. div: this.div,
  9559. annotations: null,
  9560. intent
  9561. };
  9562. this.annotationEditorLayer.render(parameters);
  9563. }
  9564. cancel() {
  9565. this._cancelled = true;
  9566. this.destroy();
  9567. }
  9568. hide() {
  9569. if (!this.div) {
  9570. return;
  9571. }
  9572. this.div.hidden = true;
  9573. }
  9574. show() {
  9575. if (!this.div) {
  9576. return;
  9577. }
  9578. this.div.hidden = false;
  9579. }
  9580. destroy() {
  9581. if (!this.div) {
  9582. return;
  9583. }
  9584. this.pageDiv = null;
  9585. this.annotationEditorLayer.destroy();
  9586. this.div.remove();
  9587. }
  9588. }
  9589. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  9590. /***/ }),
  9591. /* 30 */
  9592. /***/ ((__unused_webpack_module, exports) => {
  9593. Object.defineProperty(exports, "__esModule", ({
  9594. value: true
  9595. }));
  9596. exports.NullL10n = void 0;
  9597. exports.fixupLangCode = fixupLangCode;
  9598. exports.getL10nFallback = getL10nFallback;
  9599. const DEFAULT_L10N_STRINGS = {
  9600. of_pages: "of {{pagesCount}}",
  9601. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9602. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9603. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9604. document_properties_date_string: "{{date}}, {{time}}",
  9605. document_properties_page_size_unit_inches: "in",
  9606. document_properties_page_size_unit_millimeters: "mm",
  9607. document_properties_page_size_orientation_portrait: "portrait",
  9608. document_properties_page_size_orientation_landscape: "landscape",
  9609. document_properties_page_size_name_a3: "A3",
  9610. document_properties_page_size_name_a4: "A4",
  9611. document_properties_page_size_name_letter: "Letter",
  9612. document_properties_page_size_name_legal: "Legal",
  9613. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9614. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9615. document_properties_linearized_yes: "Yes",
  9616. document_properties_linearized_no: "No",
  9617. additional_layers: "Additional Layers",
  9618. page_landmark: "Page {{page}}",
  9619. thumb_page_title: "Page {{page}}",
  9620. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9621. find_reached_top: "Reached top of document, continued from bottom",
  9622. find_reached_bottom: "Reached end of document, continued from top",
  9623. "find_match_count[one]": "{{current}} of {{total}} match",
  9624. "find_match_count[other]": "{{current}} of {{total}} matches",
  9625. "find_match_count_limit[one]": "More than {{limit}} match",
  9626. "find_match_count_limit[other]": "More than {{limit}} matches",
  9627. find_not_found: "Phrase not found",
  9628. page_scale_width: "Page Width",
  9629. page_scale_fit: "Page Fit",
  9630. page_scale_auto: "Automatic Zoom",
  9631. page_scale_actual: "Actual Size",
  9632. page_scale_percent: "{{scale}}%",
  9633. loading: "Loading…",
  9634. loading_error: "An error occurred while loading the PDF.",
  9635. invalid_file_error: "Invalid or corrupted PDF file.",
  9636. missing_file_error: "Missing PDF file.",
  9637. unexpected_response_error: "Unexpected server response.",
  9638. rendering_error: "An error occurred while rendering the page.",
  9639. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9640. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9641. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  9642. free_text2_default_content: "Start typing…",
  9643. editor_free_text2_aria_label: "Text Editor",
  9644. editor_ink2_aria_label: "Draw Editor",
  9645. editor_ink_canvas_aria_label: "User-created image"
  9646. };
  9647. {
  9648. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  9649. }
  9650. function getL10nFallback(key, args) {
  9651. switch (key) {
  9652. case "find_match_count":
  9653. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9654. break;
  9655. case "find_match_count_limit":
  9656. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9657. break;
  9658. }
  9659. return DEFAULT_L10N_STRINGS[key] || "";
  9660. }
  9661. const PARTIAL_LANG_CODES = {
  9662. en: "en-US",
  9663. es: "es-ES",
  9664. fy: "fy-NL",
  9665. ga: "ga-IE",
  9666. gu: "gu-IN",
  9667. hi: "hi-IN",
  9668. hy: "hy-AM",
  9669. nb: "nb-NO",
  9670. ne: "ne-NP",
  9671. nn: "nn-NO",
  9672. pa: "pa-IN",
  9673. pt: "pt-PT",
  9674. sv: "sv-SE",
  9675. zh: "zh-CN"
  9676. };
  9677. function fixupLangCode(langCode) {
  9678. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9679. }
  9680. function formatL10nValue(text, args) {
  9681. if (!args) {
  9682. return text;
  9683. }
  9684. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9685. return name in args ? args[name] : "{{" + name + "}}";
  9686. });
  9687. }
  9688. const NullL10n = {
  9689. async getLanguage() {
  9690. return "en-us";
  9691. },
  9692. async getDirection() {
  9693. return "ltr";
  9694. },
  9695. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9696. return formatL10nValue(fallback, args);
  9697. },
  9698. async translate(element) {}
  9699. };
  9700. exports.NullL10n = NullL10n;
  9701. /***/ }),
  9702. /* 31 */
  9703. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9704. Object.defineProperty(exports, "__esModule", ({
  9705. value: true
  9706. }));
  9707. exports.AnnotationLayerBuilder = void 0;
  9708. var _pdfjsLib = __webpack_require__(5);
  9709. var _l10n_utils = __webpack_require__(30);
  9710. var _ui_utils = __webpack_require__(1);
  9711. class AnnotationLayerBuilder {
  9712. #onPresentationModeChanged = null;
  9713. constructor({
  9714. pageDiv,
  9715. pdfPage,
  9716. linkService,
  9717. downloadManager,
  9718. annotationStorage = null,
  9719. imageResourcesPath = "",
  9720. renderForms = true,
  9721. l10n = _l10n_utils.NullL10n,
  9722. enableScripting = false,
  9723. hasJSActionsPromise = null,
  9724. fieldObjectsPromise = null,
  9725. mouseState = null,
  9726. annotationCanvasMap = null,
  9727. accessibilityManager = null
  9728. }) {
  9729. this.pageDiv = pageDiv;
  9730. this.pdfPage = pdfPage;
  9731. this.linkService = linkService;
  9732. this.downloadManager = downloadManager;
  9733. this.imageResourcesPath = imageResourcesPath;
  9734. this.renderForms = renderForms;
  9735. this.l10n = l10n;
  9736. this.annotationStorage = annotationStorage;
  9737. this.enableScripting = enableScripting;
  9738. this._hasJSActionsPromise = hasJSActionsPromise;
  9739. this._fieldObjectsPromise = fieldObjectsPromise;
  9740. this._mouseState = mouseState;
  9741. this._annotationCanvasMap = annotationCanvasMap;
  9742. this._accessibilityManager = accessibilityManager;
  9743. this.div = null;
  9744. this._cancelled = false;
  9745. this._eventBus = linkService.eventBus;
  9746. }
  9747. async render(viewport, intent = "display") {
  9748. const [annotations, hasJSActions = false, fieldObjects = null] = await Promise.all([this.pdfPage.getAnnotations({
  9749. intent
  9750. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  9751. if (this._cancelled || annotations.length === 0) {
  9752. return;
  9753. }
  9754. const parameters = {
  9755. viewport: viewport.clone({
  9756. dontFlip: true
  9757. }),
  9758. div: this.div,
  9759. annotations,
  9760. page: this.pdfPage,
  9761. imageResourcesPath: this.imageResourcesPath,
  9762. renderForms: this.renderForms,
  9763. linkService: this.linkService,
  9764. downloadManager: this.downloadManager,
  9765. annotationStorage: this.annotationStorage,
  9766. enableScripting: this.enableScripting,
  9767. hasJSActions,
  9768. fieldObjects,
  9769. mouseState: this._mouseState,
  9770. annotationCanvasMap: this._annotationCanvasMap,
  9771. accessibilityManager: this._accessibilityManager
  9772. };
  9773. if (this.div) {
  9774. _pdfjsLib.AnnotationLayer.update(parameters);
  9775. } else {
  9776. this.div = document.createElement("div");
  9777. this.div.className = "annotationLayer";
  9778. this.pageDiv.append(this.div);
  9779. parameters.div = this.div;
  9780. _pdfjsLib.AnnotationLayer.render(parameters);
  9781. this.l10n.translate(this.div);
  9782. if (this.linkService.isInPresentationMode) {
  9783. this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN);
  9784. }
  9785. if (!this.#onPresentationModeChanged) {
  9786. this.#onPresentationModeChanged = evt => {
  9787. this.#updatePresentationModeState(evt.state);
  9788. };
  9789. this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged);
  9790. }
  9791. }
  9792. }
  9793. cancel() {
  9794. this._cancelled = true;
  9795. if (this.#onPresentationModeChanged) {
  9796. this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged);
  9797. this.#onPresentationModeChanged = null;
  9798. }
  9799. }
  9800. hide() {
  9801. if (!this.div) {
  9802. return;
  9803. }
  9804. this.div.hidden = true;
  9805. }
  9806. #updatePresentationModeState(state) {
  9807. if (!this.div) {
  9808. return;
  9809. }
  9810. let disableFormElements = false;
  9811. switch (state) {
  9812. case _ui_utils.PresentationModeState.FULLSCREEN:
  9813. disableFormElements = true;
  9814. break;
  9815. case _ui_utils.PresentationModeState.NORMAL:
  9816. break;
  9817. default:
  9818. return;
  9819. }
  9820. for (const section of this.div.childNodes) {
  9821. if (section.hasAttribute("data-internal-link")) {
  9822. continue;
  9823. }
  9824. section.inert = disableFormElements;
  9825. }
  9826. }
  9827. }
  9828. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  9829. /***/ }),
  9830. /* 32 */
  9831. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9832. Object.defineProperty(exports, "__esModule", ({
  9833. value: true
  9834. }));
  9835. exports.PDFPageView = void 0;
  9836. var _pdfjsLib = __webpack_require__(5);
  9837. var _ui_utils = __webpack_require__(1);
  9838. var _app_options = __webpack_require__(2);
  9839. var _l10n_utils = __webpack_require__(30);
  9840. var _text_accessibility = __webpack_require__(33);
  9841. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9842. class PDFPageView {
  9843. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9844. #useThumbnailCanvas = {
  9845. initialOptionalContent: true,
  9846. regularAnnotations: true
  9847. };
  9848. constructor(options) {
  9849. const container = options.container;
  9850. const defaultViewport = options.defaultViewport;
  9851. this.id = options.id;
  9852. this.renderingId = "page" + this.id;
  9853. this.pdfPage = null;
  9854. this.pageLabel = null;
  9855. this.rotation = 0;
  9856. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9857. this.viewport = defaultViewport;
  9858. this.pdfPageRotate = defaultViewport.rotation;
  9859. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9860. this.hasRestrictedScaling = false;
  9861. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9862. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9863. this.imageResourcesPath = options.imageResourcesPath || "";
  9864. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9865. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9866. this.pageColors = options.pageColors || null;
  9867. this.eventBus = options.eventBus;
  9868. this.renderingQueue = options.renderingQueue;
  9869. this.textLayerFactory = options.textLayerFactory;
  9870. this.annotationLayerFactory = options.annotationLayerFactory;
  9871. this.annotationEditorLayerFactory = options.annotationEditorLayerFactory;
  9872. this.xfaLayerFactory = options.xfaLayerFactory;
  9873. this.textHighlighter = options.textHighlighterFactory?.createTextHighlighter({
  9874. pageIndex: this.id - 1,
  9875. eventBus: this.eventBus
  9876. });
  9877. this.structTreeLayerFactory = options.structTreeLayerFactory;
  9878. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9879. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9880. this.paintTask = null;
  9881. this.paintedViewportMap = new WeakMap();
  9882. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9883. this.resume = null;
  9884. this._renderError = null;
  9885. this._isStandalone = !this.renderingQueue?.hasViewer();
  9886. this._annotationCanvasMap = null;
  9887. this.annotationLayer = null;
  9888. this.annotationEditorLayer = null;
  9889. this.textLayer = null;
  9890. this.zoomLayer = null;
  9891. this.xfaLayer = null;
  9892. this.structTreeLayer = null;
  9893. const div = document.createElement("div");
  9894. div.className = "page";
  9895. div.style.width = Math.floor(this.viewport.width) + "px";
  9896. div.style.height = Math.floor(this.viewport.height) + "px";
  9897. div.setAttribute("data-page-number", this.id);
  9898. div.setAttribute("role", "region");
  9899. this.l10n.get("page_landmark", {
  9900. page: this.id
  9901. }).then(msg => {
  9902. div.setAttribute("aria-label", msg);
  9903. });
  9904. this.div = div;
  9905. container?.append(div);
  9906. if (this._isStandalone) {
  9907. const {
  9908. optionalContentConfigPromise
  9909. } = options;
  9910. if (optionalContentConfigPromise) {
  9911. optionalContentConfigPromise.then(optionalContentConfig => {
  9912. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9913. return;
  9914. }
  9915. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9916. });
  9917. }
  9918. }
  9919. }
  9920. setPdfPage(pdfPage) {
  9921. this.pdfPage = pdfPage;
  9922. this.pdfPageRotate = pdfPage.rotate;
  9923. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9924. this.viewport = pdfPage.getViewport({
  9925. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9926. rotation: totalRotation
  9927. });
  9928. this.reset();
  9929. }
  9930. destroy() {
  9931. this.reset();
  9932. this.pdfPage?.cleanup();
  9933. }
  9934. async _renderAnnotationLayer() {
  9935. let error = null;
  9936. try {
  9937. await this.annotationLayer.render(this.viewport, "display");
  9938. } catch (ex) {
  9939. console.error(`_renderAnnotationLayer: "${ex}".`);
  9940. error = ex;
  9941. } finally {
  9942. this.eventBus.dispatch("annotationlayerrendered", {
  9943. source: this,
  9944. pageNumber: this.id,
  9945. error
  9946. });
  9947. }
  9948. }
  9949. async _renderAnnotationEditorLayer() {
  9950. let error = null;
  9951. try {
  9952. await this.annotationEditorLayer.render(this.viewport, "display");
  9953. } catch (ex) {
  9954. console.error(`_renderAnnotationEditorLayer: "${ex}".`);
  9955. error = ex;
  9956. } finally {
  9957. this.eventBus.dispatch("annotationeditorlayerrendered", {
  9958. source: this,
  9959. pageNumber: this.id,
  9960. error
  9961. });
  9962. }
  9963. }
  9964. async _renderXfaLayer() {
  9965. let error = null;
  9966. try {
  9967. const result = await this.xfaLayer.render(this.viewport, "display");
  9968. if (result?.textDivs && this.textHighlighter) {
  9969. this._buildXfaTextContentItems(result.textDivs);
  9970. }
  9971. } catch (ex) {
  9972. console.error(`_renderXfaLayer: "${ex}".`);
  9973. error = ex;
  9974. } finally {
  9975. this.eventBus.dispatch("xfalayerrendered", {
  9976. source: this,
  9977. pageNumber: this.id,
  9978. error
  9979. });
  9980. }
  9981. }
  9982. async _buildXfaTextContentItems(textDivs) {
  9983. const text = await this.pdfPage.getTextContent();
  9984. const items = [];
  9985. for (const item of text.items) {
  9986. items.push(item.str);
  9987. }
  9988. this.textHighlighter.setTextMapping(textDivs, items);
  9989. this.textHighlighter.enable();
  9990. }
  9991. _resetZoomLayer(removeFromDOM = false) {
  9992. if (!this.zoomLayer) {
  9993. return;
  9994. }
  9995. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9996. this.paintedViewportMap.delete(zoomLayerCanvas);
  9997. zoomLayerCanvas.width = 0;
  9998. zoomLayerCanvas.height = 0;
  9999. if (removeFromDOM) {
  10000. this.zoomLayer.remove();
  10001. }
  10002. this.zoomLayer = null;
  10003. }
  10004. reset({
  10005. keepZoomLayer = false,
  10006. keepAnnotationLayer = false,
  10007. keepAnnotationEditorLayer = false,
  10008. keepXfaLayer = false
  10009. } = {}) {
  10010. this.cancelRendering({
  10011. keepAnnotationLayer,
  10012. keepAnnotationEditorLayer,
  10013. keepXfaLayer
  10014. });
  10015. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  10016. const div = this.div;
  10017. div.style.width = Math.floor(this.viewport.width) + "px";
  10018. div.style.height = Math.floor(this.viewport.height) + "px";
  10019. const childNodes = div.childNodes,
  10020. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  10021. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  10022. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  10023. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null;
  10024. for (let i = childNodes.length - 1; i >= 0; i--) {
  10025. const node = childNodes[i];
  10026. switch (node) {
  10027. case zoomLayerNode:
  10028. case annotationLayerNode:
  10029. case annotationEditorLayerNode:
  10030. case xfaLayerNode:
  10031. continue;
  10032. }
  10033. node.remove();
  10034. }
  10035. div.removeAttribute("data-loaded");
  10036. if (annotationLayerNode) {
  10037. this.annotationLayer.hide();
  10038. }
  10039. if (annotationEditorLayerNode) {
  10040. this.annotationEditorLayer.hide();
  10041. } else {
  10042. this.annotationEditorLayer?.destroy();
  10043. }
  10044. if (xfaLayerNode) {
  10045. this.xfaLayer.hide();
  10046. }
  10047. if (!zoomLayerNode) {
  10048. if (this.canvas) {
  10049. this.paintedViewportMap.delete(this.canvas);
  10050. this.canvas.width = 0;
  10051. this.canvas.height = 0;
  10052. delete this.canvas;
  10053. }
  10054. this._resetZoomLayer();
  10055. }
  10056. if (this.svg) {
  10057. this.paintedViewportMap.delete(this.svg);
  10058. delete this.svg;
  10059. }
  10060. this.loadingIconDiv = document.createElement("div");
  10061. this.loadingIconDiv.className = "loadingIcon notVisible";
  10062. if (this._isStandalone) {
  10063. this.toggleLoadingIconSpinner(true);
  10064. }
  10065. this.loadingIconDiv.setAttribute("role", "img");
  10066. this.l10n.get("loading").then(msg => {
  10067. this.loadingIconDiv?.setAttribute("aria-label", msg);
  10068. });
  10069. div.append(this.loadingIconDiv);
  10070. }
  10071. update({
  10072. scale = 0,
  10073. rotation = null,
  10074. optionalContentConfigPromise = null
  10075. }) {
  10076. this.scale = scale || this.scale;
  10077. if (typeof rotation === "number") {
  10078. this.rotation = rotation;
  10079. }
  10080. if (optionalContentConfigPromise instanceof Promise) {
  10081. this._optionalContentConfigPromise = optionalContentConfigPromise;
  10082. optionalContentConfigPromise.then(optionalContentConfig => {
  10083. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  10084. return;
  10085. }
  10086. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  10087. });
  10088. }
  10089. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  10090. this.viewport = this.viewport.clone({
  10091. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  10092. rotation: totalRotation
  10093. });
  10094. if (this._isStandalone) {
  10095. _ui_utils.docStyle.setProperty("--scale-factor", this.viewport.scale);
  10096. }
  10097. if (this.svg) {
  10098. this.cssTransform({
  10099. target: this.svg,
  10100. redrawAnnotationLayer: true,
  10101. redrawAnnotationEditorLayer: true,
  10102. redrawXfaLayer: true
  10103. });
  10104. this.eventBus.dispatch("pagerendered", {
  10105. source: this,
  10106. pageNumber: this.id,
  10107. cssTransform: true,
  10108. timestamp: performance.now(),
  10109. error: this._renderError
  10110. });
  10111. return;
  10112. }
  10113. let isScalingRestricted = false;
  10114. if (this.canvas && this.maxCanvasPixels > 0) {
  10115. const outputScale = this.outputScale;
  10116. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  10117. isScalingRestricted = true;
  10118. }
  10119. }
  10120. if (this.canvas) {
  10121. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  10122. this.cssTransform({
  10123. target: this.canvas,
  10124. redrawAnnotationLayer: true,
  10125. redrawAnnotationEditorLayer: true,
  10126. redrawXfaLayer: 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. if (!this.zoomLayer && !this.canvas.hidden) {
  10138. this.zoomLayer = this.canvas.parentNode;
  10139. this.zoomLayer.style.position = "absolute";
  10140. }
  10141. }
  10142. if (this.zoomLayer) {
  10143. this.cssTransform({
  10144. target: this.zoomLayer.firstChild
  10145. });
  10146. }
  10147. this.reset({
  10148. keepZoomLayer: true,
  10149. keepAnnotationLayer: true,
  10150. keepAnnotationEditorLayer: true,
  10151. keepXfaLayer: true
  10152. });
  10153. }
  10154. cancelRendering({
  10155. keepAnnotationLayer = false,
  10156. keepAnnotationEditorLayer = false,
  10157. keepXfaLayer = false
  10158. } = {}) {
  10159. if (this.paintTask) {
  10160. this.paintTask.cancel();
  10161. this.paintTask = null;
  10162. }
  10163. this.resume = null;
  10164. if (this.textLayer) {
  10165. this.textLayer.cancel();
  10166. this.textLayer = null;
  10167. }
  10168. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  10169. this.annotationLayer.cancel();
  10170. this.annotationLayer = null;
  10171. this._annotationCanvasMap = null;
  10172. }
  10173. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  10174. this.annotationEditorLayer.cancel();
  10175. this.annotationEditorLayer = null;
  10176. }
  10177. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  10178. this.xfaLayer.cancel();
  10179. this.xfaLayer = null;
  10180. this.textHighlighter?.disable();
  10181. }
  10182. if (this._onTextLayerRendered) {
  10183. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  10184. this._onTextLayerRendered = null;
  10185. }
  10186. }
  10187. cssTransform({
  10188. target,
  10189. redrawAnnotationLayer = false,
  10190. redrawAnnotationEditorLayer = false,
  10191. redrawXfaLayer = false
  10192. }) {
  10193. const width = this.viewport.width;
  10194. const height = this.viewport.height;
  10195. const div = this.div;
  10196. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  10197. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  10198. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  10199. const absRotation = Math.abs(relativeRotation);
  10200. let scaleX = 1,
  10201. scaleY = 1;
  10202. if (absRotation === 90 || absRotation === 270) {
  10203. scaleX = height / width;
  10204. scaleY = width / height;
  10205. }
  10206. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  10207. if (this.textLayer) {
  10208. const textLayerViewport = this.textLayer.viewport;
  10209. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  10210. const textAbsRotation = Math.abs(textRelativeRotation);
  10211. let scale = width / textLayerViewport.width;
  10212. if (textAbsRotation === 90 || textAbsRotation === 270) {
  10213. scale = width / textLayerViewport.height;
  10214. }
  10215. const textLayerDiv = this.textLayer.textLayerDiv;
  10216. let transX, transY;
  10217. switch (textAbsRotation) {
  10218. case 0:
  10219. transX = transY = 0;
  10220. break;
  10221. case 90:
  10222. transX = 0;
  10223. transY = "-" + textLayerDiv.style.height;
  10224. break;
  10225. case 180:
  10226. transX = "-" + textLayerDiv.style.width;
  10227. transY = "-" + textLayerDiv.style.height;
  10228. break;
  10229. case 270:
  10230. transX = "-" + textLayerDiv.style.width;
  10231. transY = 0;
  10232. break;
  10233. default:
  10234. console.error("Bad rotation value.");
  10235. break;
  10236. }
  10237. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  10238. textLayerDiv.style.transformOrigin = "0% 0%";
  10239. }
  10240. if (redrawAnnotationLayer && this.annotationLayer) {
  10241. this._renderAnnotationLayer();
  10242. }
  10243. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  10244. this._renderAnnotationEditorLayer();
  10245. }
  10246. if (redrawXfaLayer && this.xfaLayer) {
  10247. this._renderXfaLayer();
  10248. }
  10249. }
  10250. get width() {
  10251. return this.viewport.width;
  10252. }
  10253. get height() {
  10254. return this.viewport.height;
  10255. }
  10256. getPagePoint(x, y) {
  10257. return this.viewport.convertToPdfPoint(x, y);
  10258. }
  10259. toggleLoadingIconSpinner(viewVisible = false) {
  10260. this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
  10261. }
  10262. draw() {
  10263. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  10264. console.error("Must be in new state before drawing");
  10265. this.reset();
  10266. }
  10267. const {
  10268. div,
  10269. pdfPage
  10270. } = this;
  10271. if (!pdfPage) {
  10272. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10273. if (this.loadingIconDiv) {
  10274. this.loadingIconDiv.remove();
  10275. delete this.loadingIconDiv;
  10276. }
  10277. return Promise.reject(new Error("pdfPage is not loaded"));
  10278. }
  10279. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10280. const canvasWrapper = document.createElement("div");
  10281. canvasWrapper.style.width = div.style.width;
  10282. canvasWrapper.style.height = div.style.height;
  10283. canvasWrapper.classList.add("canvasWrapper");
  10284. const lastDivBeforeTextDiv = this.annotationLayer?.div || this.annotationEditorLayer?.div;
  10285. if (lastDivBeforeTextDiv) {
  10286. lastDivBeforeTextDiv.before(canvasWrapper);
  10287. } else {
  10288. div.append(canvasWrapper);
  10289. }
  10290. let textLayer = null;
  10291. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  10292. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  10293. const textLayerDiv = document.createElement("div");
  10294. textLayerDiv.className = "textLayer";
  10295. textLayerDiv.style.width = canvasWrapper.style.width;
  10296. textLayerDiv.style.height = canvasWrapper.style.height;
  10297. // if (lastDivBeforeTextDiv) {
  10298. // lastDivBeforeTextDiv.before(textLayerDiv);
  10299. // } else {
  10300. // div.append(textLayerDiv);
  10301. // }
  10302. //---------------------水印开始---------------------
  10303. const fontSize = parseInt(canvasWrapper.style.width) / 12;
  10304. var cover = document.createElement('div');
  10305. cover.className = "cover";
  10306. cover.style.height = fontSize + 'px';
  10307. cover.style.lineHeight = fontSize + 'px';
  10308. cover.style.position = 'absolute';
  10309. cover.style.left = '50%';
  10310. cover.style.top = `calc(50% - ${fontSize}px)`;
  10311. cover.style.display = 'flex';
  10312. cover.style.alignItems = 'center';
  10313. cover.style.justifyContent = 'center';
  10314. cover.style.transform = 'translateX(-50%)';
  10315. cover.style.pointerEvents = 'none' // 取消所有事件
  10316. let c = document.createElement('div')
  10317. c.className = "cover"
  10318. c.style.width = 'max-content';
  10319. c.style.fontSize = fontSize + 'px';
  10320. c.style.transform = "rotateZ(315deg)";
  10321. c.style.color = "rgba(0, 0, 0, 0.20)";
  10322. c.style.fontWeight = 'bold';
  10323. c.innerText = watermarkText;
  10324. c.style.pointerEvents = 'none' // 取消所有事件
  10325. cover.appendChild(c);
  10326. if (this.annotationLayer?.div) {
  10327. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  10328. div.appendChild(cover);
  10329. } else {
  10330. div.appendChild(textLayerDiv);
  10331. div.appendChild(cover);
  10332. }
  10333. //---------------------水印结束---------------------
  10334. textLayer = this.textLayerFactory.createTextLayerBuilder({
  10335. textLayerDiv,
  10336. pageIndex: this.id - 1,
  10337. viewport: this.viewport,
  10338. eventBus: this.eventBus,
  10339. highlighter: this.textHighlighter,
  10340. accessibilityManager: this._accessibilityManager
  10341. });
  10342. }
  10343. this.textLayer = textLayer;
  10344. if (this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE && this.annotationLayerFactory) {
  10345. this._annotationCanvasMap ||= new Map();
  10346. this.annotationLayer ||= this.annotationLayerFactory.createAnnotationLayerBuilder({
  10347. pageDiv: div,
  10348. pdfPage,
  10349. imageResourcesPath: this.imageResourcesPath,
  10350. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  10351. l10n: this.l10n,
  10352. annotationCanvasMap: this._annotationCanvasMap,
  10353. accessibilityManager: this._accessibilityManager
  10354. });
  10355. }
  10356. if (this.xfaLayer?.div) {
  10357. div.append(this.xfaLayer.div);
  10358. }
  10359. let renderContinueCallback = null;
  10360. if (this.renderingQueue) {
  10361. renderContinueCallback = cont => {
  10362. if (!this.renderingQueue.isHighestPriority(this)) {
  10363. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  10364. this.resume = () => {
  10365. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10366. cont();
  10367. };
  10368. return;
  10369. }
  10370. cont();
  10371. };
  10372. }
  10373. const finishPaintTask = async (error = null) => {
  10374. if (paintTask === this.paintTask) {
  10375. this.paintTask = null;
  10376. }
  10377. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  10378. this._renderError = null;
  10379. return;
  10380. }
  10381. this._renderError = error;
  10382. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10383. if (this.loadingIconDiv) {
  10384. this.loadingIconDiv.remove();
  10385. delete this.loadingIconDiv;
  10386. }
  10387. this._resetZoomLayer(true);
  10388. this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
  10389. this.eventBus.dispatch("pagerendered", {
  10390. source: this,
  10391. pageNumber: this.id,
  10392. cssTransform: false,
  10393. timestamp: performance.now(),
  10394. error: this._renderError
  10395. });
  10396. if (error) {
  10397. throw error;
  10398. }
  10399. };
  10400. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  10401. paintTask.onRenderContinue = renderContinueCallback;
  10402. this.paintTask = paintTask;
  10403. const resultPromise = paintTask.promise.then(() => {
  10404. return finishPaintTask(null).then(() => {
  10405. if (textLayer) {
  10406. const readableStream = pdfPage.streamTextContent({
  10407. includeMarkedContent: true
  10408. });
  10409. textLayer.setTextContentStream(readableStream);
  10410. textLayer.render();
  10411. }
  10412. if (this.annotationLayer) {
  10413. this._renderAnnotationLayer().then(() => {
  10414. if (this.annotationEditorLayerFactory) {
  10415. this.annotationEditorLayer ||= this.annotationEditorLayerFactory.createAnnotationEditorLayerBuilder({
  10416. pageDiv: div,
  10417. pdfPage,
  10418. l10n: this.l10n,
  10419. accessibilityManager: this._accessibilityManager
  10420. });
  10421. this._renderAnnotationEditorLayer();
  10422. }
  10423. });
  10424. }
  10425. });
  10426. }, function (reason) {
  10427. return finishPaintTask(reason);
  10428. });
  10429. if (this.xfaLayerFactory) {
  10430. this.xfaLayer ||= this.xfaLayerFactory.createXfaLayerBuilder({
  10431. pageDiv: div,
  10432. pdfPage
  10433. });
  10434. this._renderXfaLayer();
  10435. }
  10436. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  10437. this._onTextLayerRendered = event => {
  10438. if (event.pageNumber !== this.id) {
  10439. return;
  10440. }
  10441. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  10442. this._onTextLayerRendered = null;
  10443. if (!this.canvas) {
  10444. return;
  10445. }
  10446. this.pdfPage.getStructTree().then(tree => {
  10447. if (!tree) {
  10448. return;
  10449. }
  10450. if (!this.canvas) {
  10451. return;
  10452. }
  10453. const treeDom = this.structTreeLayer.render(tree);
  10454. treeDom.classList.add("structTree");
  10455. this.canvas.append(treeDom);
  10456. });
  10457. };
  10458. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  10459. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder({
  10460. pdfPage
  10461. });
  10462. }
  10463. div.setAttribute("data-loaded", true);
  10464. this.eventBus.dispatch("pagerender", {
  10465. source: this,
  10466. pageNumber: this.id
  10467. });
  10468. return resultPromise;
  10469. }
  10470. paintOnCanvas(canvasWrapper) {
  10471. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  10472. const result = {
  10473. promise: renderCapability.promise,
  10474. onRenderContinue(cont) {
  10475. cont();
  10476. },
  10477. cancel() {
  10478. renderTask.cancel();
  10479. },
  10480. get separateAnnots() {
  10481. return renderTask.separateAnnots;
  10482. }
  10483. };
  10484. const viewport = this.viewport;
  10485. const canvas = document.createElement("canvas");
  10486. canvas.setAttribute("role", "presentation");
  10487. canvas.hidden = true;
  10488. let isCanvasHidden = true;
  10489. const showCanvas = function () {
  10490. if (isCanvasHidden) {
  10491. canvas.hidden = false;
  10492. isCanvasHidden = false;
  10493. }
  10494. };
  10495. canvasWrapper.append(canvas);
  10496. this.canvas = canvas;
  10497. const ctx = canvas.getContext("2d", {
  10498. alpha: false
  10499. });
  10500. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  10501. if (this.useOnlyCssZoom) {
  10502. const actualSizeViewport = viewport.clone({
  10503. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10504. });
  10505. outputScale.sx *= actualSizeViewport.width / viewport.width;
  10506. outputScale.sy *= actualSizeViewport.height / viewport.height;
  10507. }
  10508. if (this.maxCanvasPixels > 0) {
  10509. const pixelsInViewport = viewport.width * viewport.height;
  10510. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  10511. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  10512. outputScale.sx = maxScale;
  10513. outputScale.sy = maxScale;
  10514. this.hasRestrictedScaling = true;
  10515. } else {
  10516. this.hasRestrictedScaling = false;
  10517. }
  10518. }
  10519. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  10520. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  10521. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  10522. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  10523. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  10524. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  10525. this.paintedViewportMap.set(canvas, viewport);
  10526. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10527. const renderContext = {
  10528. canvasContext: ctx,
  10529. transform,
  10530. viewport: this.viewport,
  10531. annotationMode: this.#annotationMode,
  10532. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10533. annotationCanvasMap: this._annotationCanvasMap,
  10534. pageColors: this.pageColors
  10535. };
  10536. const renderTask = this.pdfPage.render(renderContext);
  10537. renderTask.onContinue = function (cont) {
  10538. showCanvas();
  10539. if (result.onRenderContinue) {
  10540. result.onRenderContinue(cont);
  10541. } else {
  10542. cont();
  10543. }
  10544. };
  10545. renderTask.promise.then(function () {
  10546. showCanvas();
  10547. renderCapability.resolve();
  10548. }, function (error) {
  10549. showCanvas();
  10550. renderCapability.reject(error);
  10551. });
  10552. return result;
  10553. }
  10554. paintOnSvg(wrapper) {
  10555. let cancelled = false;
  10556. const ensureNotCancelled = () => {
  10557. if (cancelled) {
  10558. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  10559. }
  10560. };
  10561. const pdfPage = this.pdfPage;
  10562. const actualSizeViewport = this.viewport.clone({
  10563. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10564. });
  10565. const promise = pdfPage.getOperatorList({
  10566. annotationMode: this.#annotationMode
  10567. }).then(opList => {
  10568. ensureNotCancelled();
  10569. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  10570. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  10571. ensureNotCancelled();
  10572. this.svg = svg;
  10573. this.paintedViewportMap.set(svg, actualSizeViewport);
  10574. svg.style.width = wrapper.style.width;
  10575. svg.style.height = wrapper.style.height;
  10576. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10577. wrapper.append(svg);
  10578. });
  10579. });
  10580. return {
  10581. promise,
  10582. onRenderContinue(cont) {
  10583. cont();
  10584. },
  10585. cancel() {
  10586. cancelled = true;
  10587. },
  10588. get separateAnnots() {
  10589. return false;
  10590. }
  10591. };
  10592. }
  10593. setPageLabel(label) {
  10594. this.pageLabel = typeof label === "string" ? label : null;
  10595. if (this.pageLabel !== null) {
  10596. this.div.setAttribute("data-page-label", this.pageLabel);
  10597. } else {
  10598. this.div.removeAttribute("data-page-label");
  10599. }
  10600. }
  10601. get thumbnailCanvas() {
  10602. const {
  10603. initialOptionalContent,
  10604. regularAnnotations
  10605. } = this.#useThumbnailCanvas;
  10606. return initialOptionalContent && regularAnnotations ? this.canvas : null;
  10607. }
  10608. }
  10609. exports.PDFPageView = PDFPageView;
  10610. /***/ }),
  10611. /* 33 */
  10612. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10613. Object.defineProperty(exports, "__esModule", ({
  10614. value: true
  10615. }));
  10616. exports.TextAccessibilityManager = void 0;
  10617. var _ui_utils = __webpack_require__(1);
  10618. class TextAccessibilityManager {
  10619. #enabled = false;
  10620. #textChildren = null;
  10621. #textNodes = new Map();
  10622. #waitingElements = new Map();
  10623. setTextMapping(textDivs) {
  10624. this.#textChildren = textDivs;
  10625. }
  10626. static #compareElementPositions(e1, e2) {
  10627. const rect1 = e1.getBoundingClientRect();
  10628. const rect2 = e2.getBoundingClientRect();
  10629. if (rect1.width === 0 && rect1.height === 0) {
  10630. return +1;
  10631. }
  10632. if (rect2.width === 0 && rect2.height === 0) {
  10633. return -1;
  10634. }
  10635. const top1 = rect1.y;
  10636. const bot1 = rect1.y + rect1.height;
  10637. const mid1 = rect1.y + rect1.height / 2;
  10638. const top2 = rect2.y;
  10639. const bot2 = rect2.y + rect2.height;
  10640. const mid2 = rect2.y + rect2.height / 2;
  10641. if (mid1 <= top2 && mid2 >= bot1) {
  10642. return -1;
  10643. }
  10644. if (mid2 <= top1 && mid1 >= bot2) {
  10645. return +1;
  10646. }
  10647. const centerX1 = rect1.x + rect1.width / 2;
  10648. const centerX2 = rect2.x + rect2.width / 2;
  10649. return centerX1 - centerX2;
  10650. }
  10651. enable() {
  10652. if (this.#enabled) {
  10653. throw new Error("TextAccessibilityManager is already enabled.");
  10654. }
  10655. if (!this.#textChildren) {
  10656. throw new Error("Text divs and strings have not been set.");
  10657. }
  10658. this.#enabled = true;
  10659. this.#textChildren = this.#textChildren.slice();
  10660. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  10661. if (this.#textNodes.size > 0) {
  10662. const textChildren = this.#textChildren;
  10663. for (const [id, nodeIndex] of this.#textNodes) {
  10664. const element = document.getElementById(id);
  10665. if (!element) {
  10666. this.#textNodes.delete(id);
  10667. continue;
  10668. }
  10669. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  10670. }
  10671. }
  10672. for (const [element, isRemovable] of this.#waitingElements) {
  10673. this.addPointerInTextLayer(element, isRemovable);
  10674. }
  10675. this.#waitingElements.clear();
  10676. }
  10677. disable() {
  10678. if (!this.#enabled) {
  10679. return;
  10680. }
  10681. this.#waitingElements.clear();
  10682. this.#textChildren = null;
  10683. this.#enabled = false;
  10684. }
  10685. removePointerInTextLayer(element) {
  10686. if (!this.#enabled) {
  10687. this.#waitingElements.delete(element);
  10688. return;
  10689. }
  10690. const children = this.#textChildren;
  10691. if (!children || children.length === 0) {
  10692. return;
  10693. }
  10694. const {
  10695. id
  10696. } = element;
  10697. const nodeIndex = this.#textNodes.get(id);
  10698. if (nodeIndex === undefined) {
  10699. return;
  10700. }
  10701. const node = children[nodeIndex];
  10702. this.#textNodes.delete(id);
  10703. let owns = node.getAttribute("aria-owns");
  10704. if (owns?.includes(id)) {
  10705. owns = owns.split(" ").filter(x => x !== id).join(" ");
  10706. if (owns) {
  10707. node.setAttribute("aria-owns", owns);
  10708. } else {
  10709. node.removeAttribute("aria-owns");
  10710. node.setAttribute("role", "presentation");
  10711. }
  10712. }
  10713. }
  10714. #addIdToAriaOwns(id, node) {
  10715. const owns = node.getAttribute("aria-owns");
  10716. if (!owns?.includes(id)) {
  10717. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  10718. }
  10719. node.removeAttribute("role");
  10720. }
  10721. addPointerInTextLayer(element, isRemovable) {
  10722. const {
  10723. id
  10724. } = element;
  10725. if (!id) {
  10726. return;
  10727. }
  10728. if (!this.#enabled) {
  10729. this.#waitingElements.set(element, isRemovable);
  10730. return;
  10731. }
  10732. if (isRemovable) {
  10733. this.removePointerInTextLayer(element);
  10734. }
  10735. const children = this.#textChildren;
  10736. if (!children || children.length === 0) {
  10737. return;
  10738. }
  10739. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  10740. const nodeIndex = Math.max(0, index - 1);
  10741. this.#addIdToAriaOwns(id, children[nodeIndex]);
  10742. this.#textNodes.set(id, nodeIndex);
  10743. }
  10744. moveElementInDOM(container, element, contentElement, isRemovable) {
  10745. this.addPointerInTextLayer(contentElement, isRemovable);
  10746. if (!container.hasChildNodes()) {
  10747. container.append(element);
  10748. return;
  10749. }
  10750. const children = Array.from(container.childNodes).filter(node => node !== element);
  10751. if (children.length === 0) {
  10752. return;
  10753. }
  10754. const elementToCompare = contentElement || element;
  10755. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  10756. if (index === 0) {
  10757. children[0].before(element);
  10758. } else {
  10759. children[index - 1].after(element);
  10760. }
  10761. }
  10762. }
  10763. exports.TextAccessibilityManager = TextAccessibilityManager;
  10764. /***/ }),
  10765. /* 34 */
  10766. /***/ ((__unused_webpack_module, exports) => {
  10767. Object.defineProperty(exports, "__esModule", ({
  10768. value: true
  10769. }));
  10770. exports.StructTreeLayerBuilder = void 0;
  10771. const PDF_ROLE_TO_HTML_ROLE = {
  10772. Document: null,
  10773. DocumentFragment: null,
  10774. Part: "group",
  10775. Sect: "group",
  10776. Div: "group",
  10777. Aside: "note",
  10778. NonStruct: "none",
  10779. P: null,
  10780. H: "heading",
  10781. Title: null,
  10782. FENote: "note",
  10783. Sub: "group",
  10784. Lbl: null,
  10785. Span: null,
  10786. Em: null,
  10787. Strong: null,
  10788. Link: "link",
  10789. Annot: "note",
  10790. Form: "form",
  10791. Ruby: null,
  10792. RB: null,
  10793. RT: null,
  10794. RP: null,
  10795. Warichu: null,
  10796. WT: null,
  10797. WP: null,
  10798. L: "list",
  10799. LI: "listitem",
  10800. LBody: null,
  10801. Table: "table",
  10802. TR: "row",
  10803. TH: "columnheader",
  10804. TD: "cell",
  10805. THead: "columnheader",
  10806. TBody: null,
  10807. TFoot: null,
  10808. Caption: null,
  10809. Figure: "figure",
  10810. Formula: null,
  10811. Artifact: null
  10812. };
  10813. const HEADING_PATTERN = /^H(\d+)$/;
  10814. class StructTreeLayerBuilder {
  10815. constructor({
  10816. pdfPage
  10817. }) {
  10818. this.pdfPage = pdfPage;
  10819. }
  10820. render(structTree) {
  10821. return this._walk(structTree);
  10822. }
  10823. _setAttributes(structElement, htmlElement) {
  10824. if (structElement.alt !== undefined) {
  10825. htmlElement.setAttribute("aria-label", structElement.alt);
  10826. }
  10827. if (structElement.id !== undefined) {
  10828. htmlElement.setAttribute("aria-owns", structElement.id);
  10829. }
  10830. if (structElement.lang !== undefined) {
  10831. htmlElement.setAttribute("lang", structElement.lang);
  10832. }
  10833. }
  10834. _walk(node) {
  10835. if (!node) {
  10836. return null;
  10837. }
  10838. const element = document.createElement("span");
  10839. if ("role" in node) {
  10840. const {
  10841. role
  10842. } = node;
  10843. const match = role.match(HEADING_PATTERN);
  10844. if (match) {
  10845. element.setAttribute("role", "heading");
  10846. element.setAttribute("aria-level", match[1]);
  10847. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10848. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10849. }
  10850. }
  10851. this._setAttributes(node, element);
  10852. if (node.children) {
  10853. if (node.children.length === 1 && "id" in node.children[0]) {
  10854. this._setAttributes(node.children[0], element);
  10855. } else {
  10856. for (const kid of node.children) {
  10857. element.append(this._walk(kid));
  10858. }
  10859. }
  10860. }
  10861. return element;
  10862. }
  10863. }
  10864. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10865. /***/ }),
  10866. /* 35 */
  10867. /***/ ((__unused_webpack_module, exports) => {
  10868. Object.defineProperty(exports, "__esModule", ({
  10869. value: true
  10870. }));
  10871. exports.TextHighlighter = void 0;
  10872. class TextHighlighter {
  10873. constructor({
  10874. findController,
  10875. eventBus,
  10876. pageIndex
  10877. }) {
  10878. this.findController = findController;
  10879. this.matches = [];
  10880. this.eventBus = eventBus;
  10881. this.pageIdx = pageIndex;
  10882. this._onUpdateTextLayerMatches = null;
  10883. this.textDivs = null;
  10884. this.textContentItemsStr = null;
  10885. this.enabled = false;
  10886. }
  10887. setTextMapping(divs, texts) {
  10888. this.textDivs = divs;
  10889. this.textContentItemsStr = texts;
  10890. }
  10891. enable() {
  10892. if (!this.textDivs || !this.textContentItemsStr) {
  10893. throw new Error("Text divs and strings have not been set.");
  10894. }
  10895. if (this.enabled) {
  10896. throw new Error("TextHighlighter is already enabled.");
  10897. }
  10898. this.enabled = true;
  10899. if (!this._onUpdateTextLayerMatches) {
  10900. this._onUpdateTextLayerMatches = evt => {
  10901. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  10902. this._updateMatches();
  10903. }
  10904. };
  10905. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10906. }
  10907. this._updateMatches();
  10908. }
  10909. disable() {
  10910. if (!this.enabled) {
  10911. return;
  10912. }
  10913. this.enabled = false;
  10914. if (this._onUpdateTextLayerMatches) {
  10915. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10916. this._onUpdateTextLayerMatches = null;
  10917. }
  10918. }
  10919. _convertMatches(matches, matchesLength) {
  10920. if (!matches) {
  10921. return [];
  10922. }
  10923. const {
  10924. textContentItemsStr
  10925. } = this;
  10926. let i = 0,
  10927. iIndex = 0;
  10928. const end = textContentItemsStr.length - 1;
  10929. const result = [];
  10930. for (let m = 0, mm = matches.length; m < mm; m++) {
  10931. let matchIdx = matches[m];
  10932. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  10933. iIndex += textContentItemsStr[i].length;
  10934. i++;
  10935. }
  10936. if (i === textContentItemsStr.length) {
  10937. console.error("Could not find a matching mapping");
  10938. }
  10939. const match = {
  10940. begin: {
  10941. divIdx: i,
  10942. offset: matchIdx - iIndex
  10943. }
  10944. };
  10945. matchIdx += matchesLength[m];
  10946. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  10947. iIndex += textContentItemsStr[i].length;
  10948. i++;
  10949. }
  10950. match.end = {
  10951. divIdx: i,
  10952. offset: matchIdx - iIndex
  10953. };
  10954. result.push(match);
  10955. }
  10956. return result;
  10957. }
  10958. _renderMatches(matches) {
  10959. if (matches.length === 0) {
  10960. return;
  10961. }
  10962. const {
  10963. findController,
  10964. pageIdx
  10965. } = this;
  10966. const {
  10967. textContentItemsStr,
  10968. textDivs
  10969. } = this;
  10970. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  10971. const selectedMatchIdx = findController.selected.matchIdx;
  10972. const highlightAll = findController.state.highlightAll;
  10973. let prevEnd = null;
  10974. const infinity = {
  10975. divIdx: -1,
  10976. offset: undefined
  10977. };
  10978. function beginText(begin, className) {
  10979. const divIdx = begin.divIdx;
  10980. textDivs[divIdx].textContent = "";
  10981. return appendTextToDiv(divIdx, 0, begin.offset, className);
  10982. }
  10983. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  10984. let div = textDivs[divIdx];
  10985. if (div.nodeType === Node.TEXT_NODE) {
  10986. const span = document.createElement("span");
  10987. div.before(span);
  10988. span.append(div);
  10989. textDivs[divIdx] = span;
  10990. div = span;
  10991. }
  10992. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  10993. const node = document.createTextNode(content);
  10994. if (className) {
  10995. const span = document.createElement("span");
  10996. span.className = `${className} appended`;
  10997. span.append(node);
  10998. div.append(span);
  10999. return className.includes("selected") ? span.offsetLeft : 0;
  11000. }
  11001. div.append(node);
  11002. return 0;
  11003. }
  11004. let i0 = selectedMatchIdx,
  11005. i1 = i0 + 1;
  11006. if (highlightAll) {
  11007. i0 = 0;
  11008. i1 = matches.length;
  11009. } else if (!isSelectedPage) {
  11010. return;
  11011. }
  11012. for (let i = i0; i < i1; i++) {
  11013. const match = matches[i];
  11014. const begin = match.begin;
  11015. const end = match.end;
  11016. const isSelected = isSelectedPage && i === selectedMatchIdx;
  11017. const highlightSuffix = isSelected ? " selected" : "";
  11018. let selectedLeft = 0;
  11019. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  11020. if (prevEnd !== null) {
  11021. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11022. }
  11023. beginText(begin);
  11024. } else {
  11025. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  11026. }
  11027. if (begin.divIdx === end.divIdx) {
  11028. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  11029. } else {
  11030. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  11031. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  11032. textDivs[n0].className = "highlight middle" + highlightSuffix;
  11033. }
  11034. beginText(end, "highlight end" + highlightSuffix);
  11035. }
  11036. prevEnd = end;
  11037. if (isSelected) {
  11038. findController.scrollMatchIntoView({
  11039. element: textDivs[begin.divIdx],
  11040. selectedLeft,
  11041. pageIndex: pageIdx,
  11042. matchIndex: selectedMatchIdx
  11043. });
  11044. }
  11045. }
  11046. if (prevEnd) {
  11047. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11048. }
  11049. }
  11050. _updateMatches() {
  11051. if (!this.enabled) {
  11052. return;
  11053. }
  11054. const {
  11055. findController,
  11056. matches,
  11057. pageIdx
  11058. } = this;
  11059. const {
  11060. textContentItemsStr,
  11061. textDivs
  11062. } = this;
  11063. let clearedUntilDivIdx = -1;
  11064. for (const match of matches) {
  11065. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  11066. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  11067. const div = textDivs[n];
  11068. div.textContent = textContentItemsStr[n];
  11069. div.className = "";
  11070. }
  11071. clearedUntilDivIdx = match.end.divIdx + 1;
  11072. }
  11073. if (!findController?.highlightMatches) {
  11074. return;
  11075. }
  11076. const pageMatches = findController.pageMatches[pageIdx] || null;
  11077. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  11078. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  11079. this._renderMatches(this.matches);
  11080. }
  11081. }
  11082. exports.TextHighlighter = TextHighlighter;
  11083. /***/ }),
  11084. /* 36 */
  11085. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11086. Object.defineProperty(exports, "__esModule", ({
  11087. value: true
  11088. }));
  11089. exports.TextLayerBuilder = void 0;
  11090. var _pdfjsLib = __webpack_require__(5);
  11091. class TextLayerBuilder {
  11092. constructor({
  11093. textLayerDiv,
  11094. eventBus,
  11095. pageIndex,
  11096. viewport,
  11097. highlighter = null,
  11098. accessibilityManager = null
  11099. }) {
  11100. this.textLayerDiv = textLayerDiv;
  11101. this.eventBus = eventBus;
  11102. this.textContent = null;
  11103. this.textContentItemsStr = [];
  11104. this.textContentStream = null;
  11105. this.renderingDone = false;
  11106. this.pageNumber = pageIndex + 1;
  11107. this.viewport = viewport;
  11108. this.textDivs = [];
  11109. this.textLayerRenderTask = null;
  11110. this.highlighter = highlighter;
  11111. this.accessibilityManager = accessibilityManager;
  11112. this.#bindMouse();
  11113. }
  11114. #finishRendering() {
  11115. this.renderingDone = true;
  11116. const endOfContent = document.createElement("div");
  11117. endOfContent.className = "endOfContent";
  11118. this.textLayerDiv.append(endOfContent);
  11119. this.eventBus.dispatch("textlayerrendered", {
  11120. source: this,
  11121. pageNumber: this.pageNumber,
  11122. numTextDivs: this.textDivs.length
  11123. });
  11124. }
  11125. render(timeout = 0) {
  11126. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  11127. return;
  11128. }
  11129. this.cancel();
  11130. this.textDivs.length = 0;
  11131. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  11132. this.accessibilityManager?.setTextMapping(this.textDivs);
  11133. const textLayerFrag = document.createDocumentFragment();
  11134. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  11135. textContent: this.textContent,
  11136. textContentStream: this.textContentStream,
  11137. container: textLayerFrag,
  11138. viewport: this.viewport,
  11139. textDivs: this.textDivs,
  11140. textContentItemsStr: this.textContentItemsStr,
  11141. timeout
  11142. });
  11143. this.textLayerRenderTask.promise.then(() => {
  11144. this.textLayerDiv.append(textLayerFrag);
  11145. this.#finishRendering();
  11146. this.highlighter?.enable();
  11147. this.accessibilityManager?.enable();
  11148. }, function (reason) {});
  11149. }
  11150. cancel() {
  11151. if (this.textLayerRenderTask) {
  11152. this.textLayerRenderTask.cancel();
  11153. this.textLayerRenderTask = null;
  11154. }
  11155. this.highlighter?.disable();
  11156. this.accessibilityManager?.disable();
  11157. }
  11158. setTextContentStream(readableStream) {
  11159. this.cancel();
  11160. this.textContentStream = readableStream;
  11161. }
  11162. setTextContent(textContent) {
  11163. this.cancel();
  11164. this.textContent = textContent;
  11165. }
  11166. #bindMouse() {
  11167. const div = this.textLayerDiv;
  11168. div.addEventListener("mousedown", evt => {
  11169. const end = div.querySelector(".endOfContent");
  11170. if (!end) {
  11171. return;
  11172. }
  11173. let adjustTop = evt.target !== div;
  11174. adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  11175. if (adjustTop) {
  11176. const divBounds = div.getBoundingClientRect();
  11177. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  11178. end.style.top = (r * 100).toFixed(2) + "%";
  11179. }
  11180. end.classList.add("active");
  11181. });
  11182. div.addEventListener("mouseup", () => {
  11183. const end = div.querySelector(".endOfContent");
  11184. if (!end) {
  11185. return;
  11186. }
  11187. end.style.top = "";
  11188. end.classList.remove("active");
  11189. });
  11190. }
  11191. }
  11192. exports.TextLayerBuilder = TextLayerBuilder;
  11193. /***/ }),
  11194. /* 37 */
  11195. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11196. Object.defineProperty(exports, "__esModule", ({
  11197. value: true
  11198. }));
  11199. exports.XfaLayerBuilder = void 0;
  11200. var _pdfjsLib = __webpack_require__(5);
  11201. class XfaLayerBuilder {
  11202. constructor({
  11203. pageDiv,
  11204. pdfPage,
  11205. annotationStorage = null,
  11206. linkService,
  11207. xfaHtml = null
  11208. }) {
  11209. this.pageDiv = pageDiv;
  11210. this.pdfPage = pdfPage;
  11211. this.annotationStorage = annotationStorage;
  11212. this.linkService = linkService;
  11213. this.xfaHtml = xfaHtml;
  11214. this.div = null;
  11215. this._cancelled = false;
  11216. }
  11217. render(viewport, intent = "display") {
  11218. if (intent === "print") {
  11219. const parameters = {
  11220. viewport: viewport.clone({
  11221. dontFlip: true
  11222. }),
  11223. div: this.div,
  11224. xfaHtml: this.xfaHtml,
  11225. annotationStorage: this.annotationStorage,
  11226. linkService: this.linkService,
  11227. intent
  11228. };
  11229. const div = document.createElement("div");
  11230. this.pageDiv.append(div);
  11231. parameters.div = div;
  11232. const result = _pdfjsLib.XfaLayer.render(parameters);
  11233. return Promise.resolve(result);
  11234. }
  11235. return this.pdfPage.getXfa().then(xfaHtml => {
  11236. if (this._cancelled || !xfaHtml) {
  11237. return {
  11238. textDivs: []
  11239. };
  11240. }
  11241. const parameters = {
  11242. viewport: viewport.clone({
  11243. dontFlip: true
  11244. }),
  11245. div: this.div,
  11246. xfaHtml,
  11247. annotationStorage: this.annotationStorage,
  11248. linkService: this.linkService,
  11249. intent
  11250. };
  11251. if (this.div) {
  11252. return _pdfjsLib.XfaLayer.update(parameters);
  11253. }
  11254. this.div = document.createElement("div");
  11255. this.pageDiv.append(this.div);
  11256. parameters.div = this.div;
  11257. return _pdfjsLib.XfaLayer.render(parameters);
  11258. }).catch(error => {
  11259. console.error(error);
  11260. });
  11261. }
  11262. cancel() {
  11263. this._cancelled = true;
  11264. }
  11265. hide() {
  11266. if (!this.div) {
  11267. return;
  11268. }
  11269. this.div.hidden = true;
  11270. }
  11271. }
  11272. exports.XfaLayerBuilder = XfaLayerBuilder;
  11273. /***/ }),
  11274. /* 38 */
  11275. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11276. Object.defineProperty(exports, "__esModule", ({
  11277. value: true
  11278. }));
  11279. exports.SecondaryToolbar = void 0;
  11280. var _ui_utils = __webpack_require__(1);
  11281. var _pdf_cursor_tools = __webpack_require__(7);
  11282. var _pdf_viewer = __webpack_require__(28);
  11283. class SecondaryToolbar {
  11284. constructor(options, eventBus, externalServices) {
  11285. this.toolbar = options.toolbar;
  11286. this.toggleButton = options.toggleButton;
  11287. this.buttons = [{
  11288. element: options.presentationModeButton,
  11289. eventName: "presentationmode",
  11290. close: true
  11291. }, {
  11292. element: options.printButton,
  11293. eventName: "print",
  11294. close: true
  11295. }, {
  11296. element: options.downloadButton,
  11297. eventName: "download",
  11298. close: true
  11299. }, {
  11300. element: options.viewBookmarkButton,
  11301. eventName: null,
  11302. close: true
  11303. }, {
  11304. element: options.firstPageButton,
  11305. eventName: "firstpage",
  11306. close: true
  11307. }, {
  11308. element: options.lastPageButton,
  11309. eventName: "lastpage",
  11310. close: true
  11311. }, {
  11312. element: options.pageRotateCwButton,
  11313. eventName: "rotatecw",
  11314. close: false
  11315. }, {
  11316. element: options.pageRotateCcwButton,
  11317. eventName: "rotateccw",
  11318. close: false
  11319. }, {
  11320. element: options.cursorSelectToolButton,
  11321. eventName: "switchcursortool",
  11322. eventDetails: {
  11323. tool: _pdf_cursor_tools.CursorTool.SELECT
  11324. },
  11325. close: true
  11326. }, {
  11327. element: options.cursorHandToolButton,
  11328. eventName: "switchcursortool",
  11329. eventDetails: {
  11330. tool: _pdf_cursor_tools.CursorTool.HAND
  11331. },
  11332. close: true
  11333. }, {
  11334. element: options.scrollPageButton,
  11335. eventName: "switchscrollmode",
  11336. eventDetails: {
  11337. mode: _ui_utils.ScrollMode.PAGE
  11338. },
  11339. close: true
  11340. }, {
  11341. element: options.scrollVerticalButton,
  11342. eventName: "switchscrollmode",
  11343. eventDetails: {
  11344. mode: _ui_utils.ScrollMode.VERTICAL
  11345. },
  11346. close: true
  11347. }, {
  11348. element: options.scrollHorizontalButton,
  11349. eventName: "switchscrollmode",
  11350. eventDetails: {
  11351. mode: _ui_utils.ScrollMode.HORIZONTAL
  11352. },
  11353. close: true
  11354. }, {
  11355. element: options.scrollWrappedButton,
  11356. eventName: "switchscrollmode",
  11357. eventDetails: {
  11358. mode: _ui_utils.ScrollMode.WRAPPED
  11359. },
  11360. close: true
  11361. }, {
  11362. element: options.spreadNoneButton,
  11363. eventName: "switchspreadmode",
  11364. eventDetails: {
  11365. mode: _ui_utils.SpreadMode.NONE
  11366. },
  11367. close: true
  11368. }, {
  11369. element: options.spreadOddButton,
  11370. eventName: "switchspreadmode",
  11371. eventDetails: {
  11372. mode: _ui_utils.SpreadMode.ODD
  11373. },
  11374. close: true
  11375. }, {
  11376. element: options.spreadEvenButton,
  11377. eventName: "switchspreadmode",
  11378. eventDetails: {
  11379. mode: _ui_utils.SpreadMode.EVEN
  11380. },
  11381. close: true
  11382. }, {
  11383. element: options.documentPropertiesButton,
  11384. eventName: "documentproperties",
  11385. close: true
  11386. }];
  11387. this.buttons.push({
  11388. element: options.openFileButton,
  11389. eventName: "openfile",
  11390. close: true
  11391. });
  11392. this.items = {
  11393. firstPage: options.firstPageButton,
  11394. lastPage: options.lastPageButton,
  11395. pageRotateCw: options.pageRotateCwButton,
  11396. pageRotateCcw: options.pageRotateCcwButton
  11397. };
  11398. this.eventBus = eventBus;
  11399. this.externalServices = externalServices;
  11400. this.opened = false;
  11401. this.#bindClickListeners();
  11402. this.#bindCursorToolsListener(options);
  11403. this.#bindScrollModeListener(options);
  11404. this.#bindSpreadModeListener(options);
  11405. this.reset();
  11406. }
  11407. get isOpen() {
  11408. return this.opened;
  11409. }
  11410. setPageNumber(pageNumber) {
  11411. this.pageNumber = pageNumber;
  11412. this.#updateUIState();
  11413. }
  11414. setPagesCount(pagesCount) {
  11415. this.pagesCount = pagesCount;
  11416. this.#updateUIState();
  11417. }
  11418. reset() {
  11419. this.pageNumber = 0;
  11420. this.pagesCount = 0;
  11421. this.#updateUIState();
  11422. this.eventBus.dispatch("secondarytoolbarreset", {
  11423. source: this
  11424. });
  11425. }
  11426. #updateUIState() {
  11427. this.items.firstPage.disabled = this.pageNumber <= 1;
  11428. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  11429. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  11430. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  11431. }
  11432. #bindClickListeners() {
  11433. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  11434. for (const {
  11435. element,
  11436. eventName,
  11437. close,
  11438. eventDetails
  11439. } of this.buttons) {
  11440. element.addEventListener("click", evt => {
  11441. if (eventName !== null) {
  11442. const details = {
  11443. source: this
  11444. };
  11445. for (const property in eventDetails) {
  11446. details[property] = eventDetails[property];
  11447. }
  11448. this.eventBus.dispatch(eventName, details);
  11449. }
  11450. if (close) {
  11451. this.close();
  11452. }
  11453. this.externalServices.reportTelemetry({
  11454. type: "buttons",
  11455. data: {
  11456. id: element.id
  11457. }
  11458. });
  11459. });
  11460. }
  11461. }
  11462. #bindCursorToolsListener({
  11463. cursorSelectToolButton,
  11464. cursorHandToolButton
  11465. }) {
  11466. this.eventBus._on("cursortoolchanged", function ({
  11467. tool
  11468. }) {
  11469. const isSelect = tool === _pdf_cursor_tools.CursorTool.SELECT,
  11470. isHand = tool === _pdf_cursor_tools.CursorTool.HAND;
  11471. cursorSelectToolButton.classList.toggle("toggled", isSelect);
  11472. cursorHandToolButton.classList.toggle("toggled", isHand);
  11473. cursorSelectToolButton.setAttribute("aria-checked", isSelect);
  11474. cursorHandToolButton.setAttribute("aria-checked", isHand);
  11475. });
  11476. }
  11477. #bindScrollModeListener({
  11478. scrollPageButton,
  11479. scrollVerticalButton,
  11480. scrollHorizontalButton,
  11481. scrollWrappedButton,
  11482. spreadNoneButton,
  11483. spreadOddButton,
  11484. spreadEvenButton
  11485. }) {
  11486. const scrollModeChanged = ({
  11487. mode
  11488. }) => {
  11489. const isPage = mode === _ui_utils.ScrollMode.PAGE,
  11490. isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
  11491. isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
  11492. isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
  11493. scrollPageButton.classList.toggle("toggled", isPage);
  11494. scrollVerticalButton.classList.toggle("toggled", isVertical);
  11495. scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
  11496. scrollWrappedButton.classList.toggle("toggled", isWrapped);
  11497. scrollPageButton.setAttribute("aria-checked", isPage);
  11498. scrollVerticalButton.setAttribute("aria-checked", isVertical);
  11499. scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
  11500. scrollWrappedButton.setAttribute("aria-checked", isWrapped);
  11501. const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11502. scrollPageButton.disabled = forceScrollModePage;
  11503. scrollVerticalButton.disabled = forceScrollModePage;
  11504. scrollHorizontalButton.disabled = forceScrollModePage;
  11505. scrollWrappedButton.disabled = forceScrollModePage;
  11506. spreadNoneButton.disabled = isHorizontal;
  11507. spreadOddButton.disabled = isHorizontal;
  11508. spreadEvenButton.disabled = isHorizontal;
  11509. };
  11510. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  11511. this.eventBus._on("secondarytoolbarreset", evt => {
  11512. if (evt.source === this) {
  11513. scrollModeChanged({
  11514. mode: _ui_utils.ScrollMode.VERTICAL
  11515. });
  11516. }
  11517. });
  11518. }
  11519. #bindSpreadModeListener({
  11520. spreadNoneButton,
  11521. spreadOddButton,
  11522. spreadEvenButton
  11523. }) {
  11524. function spreadModeChanged({
  11525. mode
  11526. }) {
  11527. const isNone = mode === _ui_utils.SpreadMode.NONE,
  11528. isOdd = mode === _ui_utils.SpreadMode.ODD,
  11529. isEven = mode === _ui_utils.SpreadMode.EVEN;
  11530. spreadNoneButton.classList.toggle("toggled", isNone);
  11531. spreadOddButton.classList.toggle("toggled", isOdd);
  11532. spreadEvenButton.classList.toggle("toggled", isEven);
  11533. spreadNoneButton.setAttribute("aria-checked", isNone);
  11534. spreadOddButton.setAttribute("aria-checked", isOdd);
  11535. spreadEvenButton.setAttribute("aria-checked", isEven);
  11536. }
  11537. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  11538. this.eventBus._on("secondarytoolbarreset", evt => {
  11539. if (evt.source === this) {
  11540. spreadModeChanged({
  11541. mode: _ui_utils.SpreadMode.NONE
  11542. });
  11543. }
  11544. });
  11545. }
  11546. open() {
  11547. if (this.opened) {
  11548. return;
  11549. }
  11550. this.opened = true;
  11551. this.toggleButton.classList.add("toggled");
  11552. this.toggleButton.setAttribute("aria-expanded", "true");
  11553. this.toolbar.classList.remove("hidden");
  11554. }
  11555. close() {
  11556. if (!this.opened) {
  11557. return;
  11558. }
  11559. this.opened = false;
  11560. this.toolbar.classList.add("hidden");
  11561. this.toggleButton.classList.remove("toggled");
  11562. this.toggleButton.setAttribute("aria-expanded", "false");
  11563. }
  11564. toggle() {
  11565. if (this.opened) {
  11566. this.close();
  11567. } else {
  11568. this.open();
  11569. }
  11570. }
  11571. }
  11572. exports.SecondaryToolbar = SecondaryToolbar;
  11573. /***/ }),
  11574. /* 39 */
  11575. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11576. Object.defineProperty(exports, "__esModule", ({
  11577. value: true
  11578. }));
  11579. exports.Toolbar = void 0;
  11580. var _ui_utils = __webpack_require__(1);
  11581. var _pdfjsLib = __webpack_require__(5);
  11582. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  11583. class Toolbar {
  11584. #wasLocalized = false;
  11585. constructor(options, eventBus, l10n) {
  11586. this.toolbar = options.container;
  11587. this.eventBus = eventBus;
  11588. this.l10n = l10n;
  11589. this.buttons = [{
  11590. element: options.previous,
  11591. eventName: "previouspage"
  11592. }, {
  11593. element: options.next,
  11594. eventName: "nextpage"
  11595. }, {
  11596. element: options.zoomIn,
  11597. eventName: "zoomin"
  11598. }, {
  11599. element: options.zoomOut,
  11600. eventName: "zoomout"
  11601. }, {
  11602. element: options.print,
  11603. eventName: "print"
  11604. }, {
  11605. element: options.download,
  11606. eventName: "download"
  11607. }, {
  11608. element: options.editorFreeTextButton,
  11609. eventName: "switchannotationeditormode",
  11610. eventDetails: {
  11611. get mode() {
  11612. const {
  11613. classList
  11614. } = options.editorFreeTextButton;
  11615. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  11616. }
  11617. }
  11618. }, {
  11619. element: options.editorInkButton,
  11620. eventName: "switchannotationeditormode",
  11621. eventDetails: {
  11622. get mode() {
  11623. const {
  11624. classList
  11625. } = options.editorInkButton;
  11626. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  11627. }
  11628. }
  11629. }];
  11630. this.buttons.push({
  11631. element: options.openFile,
  11632. eventName: "openfile"
  11633. });
  11634. this.items = {
  11635. numPages: options.numPages,
  11636. pageNumber: options.pageNumber,
  11637. scaleSelect: options.scaleSelect,
  11638. customScaleOption: options.customScaleOption,
  11639. previous: options.previous,
  11640. next: options.next,
  11641. zoomIn: options.zoomIn,
  11642. zoomOut: options.zoomOut
  11643. };
  11644. this.#bindListeners(options);
  11645. this.reset();
  11646. }
  11647. setPageNumber(pageNumber, pageLabel) {
  11648. this.pageNumber = pageNumber;
  11649. this.pageLabel = pageLabel;
  11650. this.#updateUIState(false);
  11651. }
  11652. setPagesCount(pagesCount, hasPageLabels) {
  11653. this.pagesCount = pagesCount;
  11654. this.hasPageLabels = hasPageLabels;
  11655. this.#updateUIState(true);
  11656. }
  11657. setPageScale(pageScaleValue, pageScale) {
  11658. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11659. this.pageScale = pageScale;
  11660. this.#updateUIState(false);
  11661. }
  11662. reset() {
  11663. this.pageNumber = 0;
  11664. this.pageLabel = null;
  11665. this.hasPageLabels = false;
  11666. this.pagesCount = 0;
  11667. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  11668. this.pageScale = _ui_utils.DEFAULT_SCALE;
  11669. this.#updateUIState(true);
  11670. this.updateLoadingIndicatorState();
  11671. this.eventBus.dispatch("toolbarreset", {
  11672. source: this
  11673. });
  11674. }
  11675. #bindListeners(options) {
  11676. const {
  11677. pageNumber,
  11678. scaleSelect
  11679. } = this.items;
  11680. const self = this;
  11681. for (const {
  11682. element,
  11683. eventName,
  11684. eventDetails
  11685. } of this.buttons) {
  11686. element.addEventListener("click", evt => {
  11687. if (eventName !== null) {
  11688. const details = {
  11689. source: this
  11690. };
  11691. if (eventDetails) {
  11692. for (const property in eventDetails) {
  11693. details[property] = eventDetails[property];
  11694. }
  11695. }
  11696. this.eventBus.dispatch(eventName, details);
  11697. }
  11698. });
  11699. }
  11700. pageNumber.addEventListener("click", function () {
  11701. this.select();
  11702. });
  11703. pageNumber.addEventListener("change", function () {
  11704. self.eventBus.dispatch("pagenumberchanged", {
  11705. source: self,
  11706. value: this.value
  11707. });
  11708. });
  11709. scaleSelect.addEventListener("change", function () {
  11710. if (this.value === "custom") {
  11711. return;
  11712. }
  11713. self.eventBus.dispatch("scalechanged", {
  11714. source: self,
  11715. value: this.value
  11716. });
  11717. });
  11718. scaleSelect.addEventListener("click", function (evt) {
  11719. const target = evt.target;
  11720. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11721. this.blur();
  11722. }
  11723. });
  11724. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  11725. this.eventBus._on("localized", () => {
  11726. this.#wasLocalized = true;
  11727. this.#adjustScaleWidth();
  11728. this.#updateUIState(true);
  11729. });
  11730. this.#bindEditorToolsListener(options);
  11731. }
  11732. #bindEditorToolsListener({
  11733. editorFreeTextButton,
  11734. editorFreeTextParamsToolbar,
  11735. editorInkButton,
  11736. editorInkParamsToolbar
  11737. }) {
  11738. const editorModeChanged = (evt, disableButtons = false) => {
  11739. const editorButtons = [{
  11740. mode: _pdfjsLib.AnnotationEditorType.FREETEXT,
  11741. button: editorFreeTextButton,
  11742. toolbar: editorFreeTextParamsToolbar
  11743. }, {
  11744. mode: _pdfjsLib.AnnotationEditorType.INK,
  11745. button: editorInkButton,
  11746. toolbar: editorInkParamsToolbar
  11747. }];
  11748. for (const {
  11749. mode,
  11750. button,
  11751. toolbar
  11752. } of editorButtons) {
  11753. const checked = mode === evt.mode;
  11754. button.classList.toggle("toggled", checked);
  11755. button.setAttribute("aria-checked", checked);
  11756. button.disabled = disableButtons;
  11757. toolbar?.classList.toggle("hidden", !checked);
  11758. }
  11759. };
  11760. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  11761. this.eventBus._on("toolbarreset", evt => {
  11762. if (evt.source === this) {
  11763. editorModeChanged({
  11764. mode: _pdfjsLib.AnnotationEditorType.NONE
  11765. }, true);
  11766. }
  11767. });
  11768. }
  11769. #updateUIState(resetNumPages = false) {
  11770. if (!this.#wasLocalized) {
  11771. return;
  11772. }
  11773. const {
  11774. pageNumber,
  11775. pagesCount,
  11776. pageScaleValue,
  11777. pageScale,
  11778. items
  11779. } = this;
  11780. if (resetNumPages) {
  11781. if (this.hasPageLabels) {
  11782. items.pageNumber.type = "text";
  11783. } else {
  11784. items.pageNumber.type = "number";
  11785. this.l10n.get("of_pages", {
  11786. pagesCount
  11787. }).then(msg => {
  11788. items.numPages.textContent = msg;
  11789. });
  11790. }
  11791. items.pageNumber.max = pagesCount;
  11792. }
  11793. if (this.hasPageLabels) {
  11794. items.pageNumber.value = this.pageLabel;
  11795. this.l10n.get("page_of_pages", {
  11796. pageNumber,
  11797. pagesCount
  11798. }).then(msg => {
  11799. items.numPages.textContent = msg;
  11800. });
  11801. } else {
  11802. items.pageNumber.value = pageNumber;
  11803. }
  11804. items.previous.disabled = pageNumber <= 1;
  11805. items.next.disabled = pageNumber >= pagesCount;
  11806. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  11807. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  11808. this.l10n.get("page_scale_percent", {
  11809. scale: Math.round(pageScale * 10000) / 100
  11810. }).then(msg => {
  11811. let predefinedValueFound = false;
  11812. for (const option of items.scaleSelect.options) {
  11813. if (option.value !== pageScaleValue) {
  11814. option.selected = false;
  11815. continue;
  11816. }
  11817. option.selected = true;
  11818. predefinedValueFound = true;
  11819. }
  11820. if (!predefinedValueFound) {
  11821. items.customScaleOption.textContent = msg;
  11822. items.customScaleOption.selected = true;
  11823. }
  11824. });
  11825. }
  11826. updateLoadingIndicatorState(loading = false) {
  11827. const {
  11828. pageNumber
  11829. } = this.items;
  11830. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  11831. }
  11832. async #adjustScaleWidth() {
  11833. const {
  11834. items,
  11835. l10n
  11836. } = this;
  11837. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  11838. await _ui_utils.animationStarted;
  11839. const style = getComputedStyle(items.scaleSelect);
  11840. const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width"));
  11841. const canvas = document.createElement("canvas");
  11842. const ctx = canvas.getContext("2d", {
  11843. alpha: false
  11844. });
  11845. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  11846. let maxWidth = 0;
  11847. for (const predefinedValue of await predefinedValuesPromise) {
  11848. const {
  11849. width
  11850. } = ctx.measureText(predefinedValue);
  11851. if (width > maxWidth) {
  11852. maxWidth = width;
  11853. }
  11854. }
  11855. maxWidth += 0.3 * scaleSelectWidth;
  11856. if (maxWidth > scaleSelectWidth) {
  11857. _ui_utils.docStyle.setProperty("--scale-select-width", `${maxWidth}px`);
  11858. }
  11859. canvas.width = 0;
  11860. canvas.height = 0;
  11861. }
  11862. }
  11863. exports.Toolbar = Toolbar;
  11864. /***/ }),
  11865. /* 40 */
  11866. /***/ ((__unused_webpack_module, exports) => {
  11867. Object.defineProperty(exports, "__esModule", ({
  11868. value: true
  11869. }));
  11870. exports.ViewHistory = void 0;
  11871. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  11872. class ViewHistory {
  11873. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  11874. this.fingerprint = fingerprint;
  11875. this.cacheSize = cacheSize;
  11876. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  11877. const database = JSON.parse(databaseStr || "{}");
  11878. let index = -1;
  11879. if (!Array.isArray(database.files)) {
  11880. database.files = [];
  11881. } else {
  11882. while (database.files.length >= this.cacheSize) {
  11883. database.files.shift();
  11884. }
  11885. for (let i = 0, ii = database.files.length; i < ii; i++) {
  11886. const branch = database.files[i];
  11887. if (branch.fingerprint === this.fingerprint) {
  11888. index = i;
  11889. break;
  11890. }
  11891. }
  11892. }
  11893. if (index === -1) {
  11894. index = database.files.push({
  11895. fingerprint: this.fingerprint
  11896. }) - 1;
  11897. }
  11898. this.file = database.files[index];
  11899. this.database = database;
  11900. });
  11901. }
  11902. async _writeToStorage() {
  11903. const databaseStr = JSON.stringify(this.database);
  11904. localStorage.setItem("pdfjs.history", databaseStr);
  11905. }
  11906. async _readFromStorage() {
  11907. return localStorage.getItem("pdfjs.history");
  11908. }
  11909. async set(name, val) {
  11910. await this._initializedPromise;
  11911. this.file[name] = val;
  11912. return this._writeToStorage();
  11913. }
  11914. async setMultiple(properties) {
  11915. await this._initializedPromise;
  11916. for (const name in properties) {
  11917. this.file[name] = properties[name];
  11918. }
  11919. return this._writeToStorage();
  11920. }
  11921. async get(name, defaultValue) {
  11922. await this._initializedPromise;
  11923. const val = this.file[name];
  11924. return val !== undefined ? val : defaultValue;
  11925. }
  11926. async getMultiple(properties) {
  11927. await this._initializedPromise;
  11928. const values = Object.create(null);
  11929. for (const name in properties) {
  11930. const val = this.file[name];
  11931. values[name] = val !== undefined ? val : properties[name];
  11932. }
  11933. return values;
  11934. }
  11935. }
  11936. exports.ViewHistory = ViewHistory;
  11937. /***/ }),
  11938. /* 41 */
  11939. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11940. Object.defineProperty(exports, "__esModule", ({
  11941. value: true
  11942. }));
  11943. exports.GenericCom = void 0;
  11944. var _app = __webpack_require__(4);
  11945. var _preferences = __webpack_require__(42);
  11946. var _download_manager = __webpack_require__(43);
  11947. var _genericl10n = __webpack_require__(44);
  11948. var _generic_scripting = __webpack_require__(46);
  11949. ;
  11950. const GenericCom = {};
  11951. exports.GenericCom = GenericCom;
  11952. class GenericPreferences extends _preferences.BasePreferences {
  11953. async _writeToStorage(prefObj) {
  11954. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  11955. }
  11956. async _readFromStorage(prefObj) {
  11957. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  11958. }
  11959. }
  11960. class GenericExternalServices extends _app.DefaultExternalServices {
  11961. static createDownloadManager(options) {
  11962. return new _download_manager.DownloadManager();
  11963. }
  11964. static createPreferences() {
  11965. return new GenericPreferences();
  11966. }
  11967. static createL10n({
  11968. locale = "en-US"
  11969. }) {
  11970. return new _genericl10n.GenericL10n(locale);
  11971. }
  11972. static createScripting({
  11973. sandboxBundleSrc
  11974. }) {
  11975. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  11976. }
  11977. }
  11978. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  11979. /***/ }),
  11980. /* 42 */
  11981. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11982. Object.defineProperty(exports, "__esModule", ({
  11983. value: true
  11984. }));
  11985. exports.BasePreferences = void 0;
  11986. var _app_options = __webpack_require__(2);
  11987. class BasePreferences {
  11988. #defaults = Object.freeze({
  11989. "annotationEditorMode": 0,
  11990. "annotationMode": 2,
  11991. "cursorToolOnLoad": 0,
  11992. "defaultZoomValue": "",
  11993. "disablePageLabels": false,
  11994. "enablePermissions": false,
  11995. "enablePrintAutoRotate": true,
  11996. "enableScripting": true,
  11997. "externalLinkTarget": 0,
  11998. "historyUpdateUrl": false,
  11999. "ignoreDestinationZoom": false,
  12000. "forcePageColors": false,
  12001. "pageColorsBackground": "Canvas",
  12002. "pageColorsForeground": "CanvasText",
  12003. "pdfBugEnabled": false,
  12004. "sidebarViewOnLoad": -1,
  12005. "scrollModeOnLoad": -1,
  12006. "spreadModeOnLoad": -1,
  12007. "textLayerMode": 1,
  12008. "useOnlyCssZoom": false,
  12009. "viewerCssTheme": 1,
  12010. "viewOnLoad": 0,
  12011. "disableAutoFetch": false,
  12012. "disableFontFace": false,
  12013. "disableRange": false,
  12014. "disableStream": false,
  12015. "enableXfa": true,
  12016. "renderer": "canvas"
  12017. });
  12018. #prefs = Object.create(null);
  12019. #initializedPromise = null;
  12020. constructor() {
  12021. if (this.constructor === BasePreferences) {
  12022. throw new Error("Cannot initialize BasePreferences.");
  12023. }
  12024. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  12025. for (const name in this.#defaults) {
  12026. const prefValue = prefs?.[name];
  12027. if (typeof prefValue === typeof this.#defaults[name]) {
  12028. this.#prefs[name] = prefValue;
  12029. }
  12030. }
  12031. });
  12032. }
  12033. async _writeToStorage(prefObj) {
  12034. throw new Error("Not implemented: _writeToStorage");
  12035. }
  12036. async _readFromStorage(prefObj) {
  12037. throw new Error("Not implemented: _readFromStorage");
  12038. }
  12039. async reset() {
  12040. await this.#initializedPromise;
  12041. const prefs = this.#prefs;
  12042. this.#prefs = Object.create(null);
  12043. return this._writeToStorage(this.#defaults).catch(reason => {
  12044. this.#prefs = prefs;
  12045. throw reason;
  12046. });
  12047. }
  12048. async set(name, value) {
  12049. await this.#initializedPromise;
  12050. const defaultValue = this.#defaults[name],
  12051. prefs = this.#prefs;
  12052. if (defaultValue === undefined) {
  12053. throw new Error(`Set preference: "${name}" is undefined.`);
  12054. } else if (value === undefined) {
  12055. throw new Error("Set preference: no value is specified.");
  12056. }
  12057. const valueType = typeof value,
  12058. defaultType = typeof defaultValue;
  12059. if (valueType !== defaultType) {
  12060. if (valueType === "number" && defaultType === "string") {
  12061. value = value.toString();
  12062. } else {
  12063. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  12064. }
  12065. } else {
  12066. if (valueType === "number" && !Number.isInteger(value)) {
  12067. throw new Error(`Set preference: "${value}" must be an integer.`);
  12068. }
  12069. }
  12070. this.#prefs[name] = value;
  12071. return this._writeToStorage(this.#prefs).catch(reason => {
  12072. this.#prefs = prefs;
  12073. throw reason;
  12074. });
  12075. }
  12076. async get(name) {
  12077. await this.#initializedPromise;
  12078. const defaultValue = this.#defaults[name];
  12079. if (defaultValue === undefined) {
  12080. throw new Error(`Get preference: "${name}" is undefined.`);
  12081. }
  12082. return this.#prefs[name] ?? defaultValue;
  12083. }
  12084. async getAll() {
  12085. await this.#initializedPromise;
  12086. const obj = Object.create(null);
  12087. for (const name in this.#defaults) {
  12088. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  12089. }
  12090. return obj;
  12091. }
  12092. }
  12093. exports.BasePreferences = BasePreferences;
  12094. /***/ }),
  12095. /* 43 */
  12096. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12097. Object.defineProperty(exports, "__esModule", ({
  12098. value: true
  12099. }));
  12100. exports.DownloadManager = void 0;
  12101. var _pdfjsLib = __webpack_require__(5);
  12102. ;
  12103. function download(blobUrl, filename) {
  12104. const a = document.createElement("a");
  12105. if (!a.click) {
  12106. throw new Error('DownloadManager: "a.click()" is not supported.');
  12107. }
  12108. a.href = blobUrl;
  12109. a.target = "_parent";
  12110. if ("download" in a) {
  12111. a.download = filename;
  12112. }
  12113. (document.body || document.documentElement).append(a);
  12114. a.click();
  12115. a.remove();
  12116. }
  12117. class DownloadManager {
  12118. #openBlobUrls = new WeakMap();
  12119. downloadUrl(url, filename) {
  12120. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  12121. console.error(`downloadUrl - not a valid URL: ${url}`);
  12122. return;
  12123. }
  12124. download(url + "#pdfjs.action=download", filename);
  12125. }
  12126. downloadData(data, filename, contentType) {
  12127. const blobUrl = URL.createObjectURL(new Blob([data], {
  12128. type: contentType
  12129. }));
  12130. download(blobUrl, filename);
  12131. }
  12132. openOrDownloadData(element, data, filename) {
  12133. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  12134. const contentType = isPdfData ? "application/pdf" : "";
  12135. if (isPdfData) {
  12136. let blobUrl = this.#openBlobUrls.get(element);
  12137. if (!blobUrl) {
  12138. blobUrl = URL.createObjectURL(new Blob([data], {
  12139. type: contentType
  12140. }));
  12141. this.#openBlobUrls.set(element, blobUrl);
  12142. }
  12143. let viewerUrl;
  12144. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  12145. try {
  12146. window.open(viewerUrl);
  12147. return true;
  12148. } catch (ex) {
  12149. console.error(`openOrDownloadData: ${ex}`);
  12150. URL.revokeObjectURL(blobUrl);
  12151. this.#openBlobUrls.delete(element);
  12152. }
  12153. }
  12154. this.downloadData(data, filename, contentType);
  12155. return false;
  12156. }
  12157. download(blob, url, filename) {
  12158. const blobUrl = URL.createObjectURL(blob);
  12159. download(blobUrl, filename);
  12160. }
  12161. }
  12162. exports.DownloadManager = DownloadManager;
  12163. /***/ }),
  12164. /* 44 */
  12165. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12166. Object.defineProperty(exports, "__esModule", ({
  12167. value: true
  12168. }));
  12169. exports.GenericL10n = void 0;
  12170. __webpack_require__(45);
  12171. var _l10n_utils = __webpack_require__(30);
  12172. const webL10n = document.webL10n;
  12173. class GenericL10n {
  12174. constructor(lang) {
  12175. this._lang = lang;
  12176. this._ready = new Promise((resolve, reject) => {
  12177. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  12178. resolve(webL10n);
  12179. });
  12180. });
  12181. }
  12182. async getLanguage() {
  12183. const l10n = await this._ready;
  12184. return l10n.getLanguage();
  12185. }
  12186. async getDirection() {
  12187. const l10n = await this._ready;
  12188. return l10n.getDirection();
  12189. }
  12190. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  12191. const l10n = await this._ready;
  12192. return l10n.get(key, args, fallback);
  12193. }
  12194. async translate(element) {
  12195. const l10n = await this._ready;
  12196. return l10n.translate(element);
  12197. }
  12198. }
  12199. exports.GenericL10n = GenericL10n;
  12200. /***/ }),
  12201. /* 45 */
  12202. /***/ (() => {
  12203. document.webL10n = function (window, document, undefined) {
  12204. var gL10nData = {};
  12205. var gTextData = '';
  12206. var gTextProp = 'textContent';
  12207. var gLanguage = '';
  12208. var gMacros = {};
  12209. var gReadyState = 'loading';
  12210. var gAsyncResourceLoading = true;
  12211. function getL10nResourceLinks() {
  12212. return document.querySelectorAll('link[type="application/l10n"]');
  12213. }
  12214. function getL10nDictionary() {
  12215. var script = document.querySelector('script[type="application/l10n"]');
  12216. return script ? JSON.parse(script.innerHTML) : null;
  12217. }
  12218. function getTranslatableChildren(element) {
  12219. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  12220. }
  12221. function getL10nAttributes(element) {
  12222. if (!element) return {};
  12223. var l10nId = element.getAttribute('data-l10n-id');
  12224. var l10nArgs = element.getAttribute('data-l10n-args');
  12225. var args = {};
  12226. if (l10nArgs) {
  12227. try {
  12228. args = JSON.parse(l10nArgs);
  12229. } catch (e) {
  12230. console.warn('could not parse arguments for #' + l10nId);
  12231. }
  12232. }
  12233. return {
  12234. id: l10nId,
  12235. args: args
  12236. };
  12237. }
  12238. function xhrLoadText(url, onSuccess, onFailure) {
  12239. onSuccess = onSuccess || function _onSuccess(data) {};
  12240. onFailure = onFailure || function _onFailure() {};
  12241. var xhr = new XMLHttpRequest();
  12242. xhr.open('GET', url, gAsyncResourceLoading);
  12243. if (xhr.overrideMimeType) {
  12244. xhr.overrideMimeType('text/plain; charset=utf-8');
  12245. }
  12246. xhr.onreadystatechange = function () {
  12247. if (xhr.readyState == 4) {
  12248. if (xhr.status == 200 || xhr.status === 0) {
  12249. onSuccess(xhr.responseText);
  12250. } else {
  12251. onFailure();
  12252. }
  12253. }
  12254. };
  12255. xhr.onerror = onFailure;
  12256. xhr.ontimeout = onFailure;
  12257. try {
  12258. xhr.send(null);
  12259. } catch (e) {
  12260. onFailure();
  12261. }
  12262. }
  12263. function parseResource(href, lang, successCallback, failureCallback) {
  12264. var baseURL = href.replace(/[^\/]*$/, '') || './';
  12265. function evalString(text) {
  12266. if (text.lastIndexOf('\\') < 0) return text;
  12267. 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, "'");
  12268. }
  12269. function parseProperties(text, parsedPropertiesCallback) {
  12270. var dictionary = {};
  12271. var reBlank = /^\s*|\s*$/;
  12272. var reComment = /^\s*#|^\s*$/;
  12273. var reSection = /^\s*\[(.*)\]\s*$/;
  12274. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  12275. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  12276. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  12277. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  12278. var currentLang = '*';
  12279. var genericLang = lang.split('-', 1)[0];
  12280. var skipLang = false;
  12281. var match = '';
  12282. function nextEntry() {
  12283. while (true) {
  12284. if (!entries.length) {
  12285. parsedRawLinesCallback();
  12286. return;
  12287. }
  12288. var line = entries.shift();
  12289. if (reComment.test(line)) continue;
  12290. if (extendedSyntax) {
  12291. match = reSection.exec(line);
  12292. if (match) {
  12293. currentLang = match[1].toLowerCase();
  12294. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  12295. continue;
  12296. } else if (skipLang) {
  12297. continue;
  12298. }
  12299. match = reImport.exec(line);
  12300. if (match) {
  12301. loadImport(baseURL + match[1], nextEntry);
  12302. return;
  12303. }
  12304. }
  12305. var tmp = line.match(reSplit);
  12306. if (tmp && tmp.length == 3) {
  12307. dictionary[tmp[1]] = evalString(tmp[2]);
  12308. }
  12309. }
  12310. }
  12311. nextEntry();
  12312. }
  12313. function loadImport(url, callback) {
  12314. xhrLoadText(url, function (content) {
  12315. parseRawLines(content, false, callback);
  12316. }, function () {
  12317. console.warn(url + ' not found.');
  12318. callback();
  12319. });
  12320. }
  12321. parseRawLines(text, true, function () {
  12322. parsedPropertiesCallback(dictionary);
  12323. });
  12324. }
  12325. xhrLoadText(href, function (response) {
  12326. gTextData += response;
  12327. parseProperties(response, function (data) {
  12328. for (var key in data) {
  12329. var id,
  12330. prop,
  12331. index = key.lastIndexOf('.');
  12332. if (index > 0) {
  12333. id = key.substring(0, index);
  12334. prop = key.substring(index + 1);
  12335. } else {
  12336. id = key;
  12337. prop = gTextProp;
  12338. }
  12339. if (!gL10nData[id]) {
  12340. gL10nData[id] = {};
  12341. }
  12342. gL10nData[id][prop] = data[key];
  12343. }
  12344. if (successCallback) {
  12345. successCallback();
  12346. }
  12347. });
  12348. }, failureCallback);
  12349. }
  12350. function loadLocale(lang, callback) {
  12351. if (lang) {
  12352. lang = lang.toLowerCase();
  12353. }
  12354. callback = callback || function _callback() {};
  12355. clear();
  12356. gLanguage = lang;
  12357. var langLinks = getL10nResourceLinks();
  12358. var langCount = langLinks.length;
  12359. if (langCount === 0) {
  12360. var dict = getL10nDictionary();
  12361. if (dict && dict.locales && dict.default_locale) {
  12362. console.log('using the embedded JSON directory, early way out');
  12363. gL10nData = dict.locales[lang];
  12364. if (!gL10nData) {
  12365. var defaultLocale = dict.default_locale.toLowerCase();
  12366. for (var anyCaseLang in dict.locales) {
  12367. anyCaseLang = anyCaseLang.toLowerCase();
  12368. if (anyCaseLang === lang) {
  12369. gL10nData = dict.locales[lang];
  12370. break;
  12371. } else if (anyCaseLang === defaultLocale) {
  12372. gL10nData = dict.locales[defaultLocale];
  12373. }
  12374. }
  12375. }
  12376. callback();
  12377. } else {
  12378. console.log('no resource to load, early way out');
  12379. }
  12380. gReadyState = 'complete';
  12381. return;
  12382. }
  12383. var onResourceLoaded = null;
  12384. var gResourceCount = 0;
  12385. onResourceLoaded = function () {
  12386. gResourceCount++;
  12387. if (gResourceCount >= langCount) {
  12388. callback();
  12389. gReadyState = 'complete';
  12390. }
  12391. };
  12392. function L10nResourceLink(link) {
  12393. var href = link.href;
  12394. this.load = function (lang, callback) {
  12395. parseResource(href, lang, callback, function () {
  12396. console.warn(href + ' not found.');
  12397. console.warn('"' + lang + '" resource not found');
  12398. gLanguage = '';
  12399. callback();
  12400. });
  12401. };
  12402. }
  12403. for (var i = 0; i < langCount; i++) {
  12404. var resource = new L10nResourceLink(langLinks[i]);
  12405. resource.load(lang, onResourceLoaded);
  12406. }
  12407. }
  12408. function clear() {
  12409. gL10nData = {};
  12410. gTextData = '';
  12411. gLanguage = '';
  12412. }
  12413. function getPluralRules(lang) {
  12414. var locales2rules = {
  12415. 'af': 3,
  12416. 'ak': 4,
  12417. 'am': 4,
  12418. 'ar': 1,
  12419. 'asa': 3,
  12420. 'az': 0,
  12421. 'be': 11,
  12422. 'bem': 3,
  12423. 'bez': 3,
  12424. 'bg': 3,
  12425. 'bh': 4,
  12426. 'bm': 0,
  12427. 'bn': 3,
  12428. 'bo': 0,
  12429. 'br': 20,
  12430. 'brx': 3,
  12431. 'bs': 11,
  12432. 'ca': 3,
  12433. 'cgg': 3,
  12434. 'chr': 3,
  12435. 'cs': 12,
  12436. 'cy': 17,
  12437. 'da': 3,
  12438. 'de': 3,
  12439. 'dv': 3,
  12440. 'dz': 0,
  12441. 'ee': 3,
  12442. 'el': 3,
  12443. 'en': 3,
  12444. 'eo': 3,
  12445. 'es': 3,
  12446. 'et': 3,
  12447. 'eu': 3,
  12448. 'fa': 0,
  12449. 'ff': 5,
  12450. 'fi': 3,
  12451. 'fil': 4,
  12452. 'fo': 3,
  12453. 'fr': 5,
  12454. 'fur': 3,
  12455. 'fy': 3,
  12456. 'ga': 8,
  12457. 'gd': 24,
  12458. 'gl': 3,
  12459. 'gsw': 3,
  12460. 'gu': 3,
  12461. 'guw': 4,
  12462. 'gv': 23,
  12463. 'ha': 3,
  12464. 'haw': 3,
  12465. 'he': 2,
  12466. 'hi': 4,
  12467. 'hr': 11,
  12468. 'hu': 0,
  12469. 'id': 0,
  12470. 'ig': 0,
  12471. 'ii': 0,
  12472. 'is': 3,
  12473. 'it': 3,
  12474. 'iu': 7,
  12475. 'ja': 0,
  12476. 'jmc': 3,
  12477. 'jv': 0,
  12478. 'ka': 0,
  12479. 'kab': 5,
  12480. 'kaj': 3,
  12481. 'kcg': 3,
  12482. 'kde': 0,
  12483. 'kea': 0,
  12484. 'kk': 3,
  12485. 'kl': 3,
  12486. 'km': 0,
  12487. 'kn': 0,
  12488. 'ko': 0,
  12489. 'ksb': 3,
  12490. 'ksh': 21,
  12491. 'ku': 3,
  12492. 'kw': 7,
  12493. 'lag': 18,
  12494. 'lb': 3,
  12495. 'lg': 3,
  12496. 'ln': 4,
  12497. 'lo': 0,
  12498. 'lt': 10,
  12499. 'lv': 6,
  12500. 'mas': 3,
  12501. 'mg': 4,
  12502. 'mk': 16,
  12503. 'ml': 3,
  12504. 'mn': 3,
  12505. 'mo': 9,
  12506. 'mr': 3,
  12507. 'ms': 0,
  12508. 'mt': 15,
  12509. 'my': 0,
  12510. 'nah': 3,
  12511. 'naq': 7,
  12512. 'nb': 3,
  12513. 'nd': 3,
  12514. 'ne': 3,
  12515. 'nl': 3,
  12516. 'nn': 3,
  12517. 'no': 3,
  12518. 'nr': 3,
  12519. 'nso': 4,
  12520. 'ny': 3,
  12521. 'nyn': 3,
  12522. 'om': 3,
  12523. 'or': 3,
  12524. 'pa': 3,
  12525. 'pap': 3,
  12526. 'pl': 13,
  12527. 'ps': 3,
  12528. 'pt': 3,
  12529. 'rm': 3,
  12530. 'ro': 9,
  12531. 'rof': 3,
  12532. 'ru': 11,
  12533. 'rwk': 3,
  12534. 'sah': 0,
  12535. 'saq': 3,
  12536. 'se': 7,
  12537. 'seh': 3,
  12538. 'ses': 0,
  12539. 'sg': 0,
  12540. 'sh': 11,
  12541. 'shi': 19,
  12542. 'sk': 12,
  12543. 'sl': 14,
  12544. 'sma': 7,
  12545. 'smi': 7,
  12546. 'smj': 7,
  12547. 'smn': 7,
  12548. 'sms': 7,
  12549. 'sn': 3,
  12550. 'so': 3,
  12551. 'sq': 3,
  12552. 'sr': 11,
  12553. 'ss': 3,
  12554. 'ssy': 3,
  12555. 'st': 3,
  12556. 'sv': 3,
  12557. 'sw': 3,
  12558. 'syr': 3,
  12559. 'ta': 3,
  12560. 'te': 3,
  12561. 'teo': 3,
  12562. 'th': 0,
  12563. 'ti': 4,
  12564. 'tig': 3,
  12565. 'tk': 3,
  12566. 'tl': 4,
  12567. 'tn': 3,
  12568. 'to': 0,
  12569. 'tr': 0,
  12570. 'ts': 3,
  12571. 'tzm': 22,
  12572. 'uk': 11,
  12573. 'ur': 3,
  12574. 've': 3,
  12575. 'vi': 0,
  12576. 'vun': 3,
  12577. 'wa': 4,
  12578. 'wae': 3,
  12579. 'wo': 0,
  12580. 'xh': 3,
  12581. 'xog': 3,
  12582. 'yo': 0,
  12583. 'zh': 0,
  12584. 'zu': 3
  12585. };
  12586. function isIn(n, list) {
  12587. return list.indexOf(n) !== -1;
  12588. }
  12589. function isBetween(n, start, end) {
  12590. return start <= n && n <= end;
  12591. }
  12592. var pluralRules = {
  12593. '0': function (n) {
  12594. return 'other';
  12595. },
  12596. '1': function (n) {
  12597. if (isBetween(n % 100, 3, 10)) return 'few';
  12598. if (n === 0) return 'zero';
  12599. if (isBetween(n % 100, 11, 99)) return 'many';
  12600. if (n == 2) return 'two';
  12601. if (n == 1) return 'one';
  12602. return 'other';
  12603. },
  12604. '2': function (n) {
  12605. if (n !== 0 && n % 10 === 0) return 'many';
  12606. if (n == 2) return 'two';
  12607. if (n == 1) return 'one';
  12608. return 'other';
  12609. },
  12610. '3': function (n) {
  12611. if (n == 1) return 'one';
  12612. return 'other';
  12613. },
  12614. '4': function (n) {
  12615. if (isBetween(n, 0, 1)) return 'one';
  12616. return 'other';
  12617. },
  12618. '5': function (n) {
  12619. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12620. return 'other';
  12621. },
  12622. '6': function (n) {
  12623. if (n === 0) return 'zero';
  12624. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12625. return 'other';
  12626. },
  12627. '7': function (n) {
  12628. if (n == 2) return 'two';
  12629. if (n == 1) return 'one';
  12630. return 'other';
  12631. },
  12632. '8': function (n) {
  12633. if (isBetween(n, 3, 6)) return 'few';
  12634. if (isBetween(n, 7, 10)) return 'many';
  12635. if (n == 2) return 'two';
  12636. if (n == 1) return 'one';
  12637. return 'other';
  12638. },
  12639. '9': function (n) {
  12640. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12641. if (n == 1) return 'one';
  12642. return 'other';
  12643. },
  12644. '10': function (n) {
  12645. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12646. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12647. return 'other';
  12648. },
  12649. '11': function (n) {
  12650. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12651. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12652. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12653. return 'other';
  12654. },
  12655. '12': function (n) {
  12656. if (isBetween(n, 2, 4)) return 'few';
  12657. if (n == 1) return 'one';
  12658. return 'other';
  12659. },
  12660. '13': function (n) {
  12661. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12662. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12663. if (n == 1) return 'one';
  12664. return 'other';
  12665. },
  12666. '14': function (n) {
  12667. if (isBetween(n % 100, 3, 4)) return 'few';
  12668. if (n % 100 == 2) return 'two';
  12669. if (n % 100 == 1) return 'one';
  12670. return 'other';
  12671. },
  12672. '15': function (n) {
  12673. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12674. if (isBetween(n % 100, 11, 19)) return 'many';
  12675. if (n == 1) return 'one';
  12676. return 'other';
  12677. },
  12678. '16': function (n) {
  12679. if (n % 10 == 1 && n != 11) return 'one';
  12680. return 'other';
  12681. },
  12682. '17': function (n) {
  12683. if (n == 3) return 'few';
  12684. if (n === 0) return 'zero';
  12685. if (n == 6) return 'many';
  12686. if (n == 2) return 'two';
  12687. if (n == 1) return 'one';
  12688. return 'other';
  12689. },
  12690. '18': function (n) {
  12691. if (n === 0) return 'zero';
  12692. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12693. return 'other';
  12694. },
  12695. '19': function (n) {
  12696. if (isBetween(n, 2, 10)) return 'few';
  12697. if (isBetween(n, 0, 1)) return 'one';
  12698. return 'other';
  12699. },
  12700. '20': function (n) {
  12701. 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';
  12702. if (n % 1000000 === 0 && n !== 0) return 'many';
  12703. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12704. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12705. return 'other';
  12706. },
  12707. '21': function (n) {
  12708. if (n === 0) return 'zero';
  12709. if (n == 1) return 'one';
  12710. return 'other';
  12711. },
  12712. '22': function (n) {
  12713. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  12714. return 'other';
  12715. },
  12716. '23': function (n) {
  12717. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  12718. return 'other';
  12719. },
  12720. '24': function (n) {
  12721. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  12722. if (isIn(n, [2, 12])) return 'two';
  12723. if (isIn(n, [1, 11])) return 'one';
  12724. return 'other';
  12725. }
  12726. };
  12727. var index = locales2rules[lang.replace(/-.*$/, '')];
  12728. if (!(index in pluralRules)) {
  12729. console.warn('plural form unknown for [' + lang + ']');
  12730. return function () {
  12731. return 'other';
  12732. };
  12733. }
  12734. return pluralRules[index];
  12735. }
  12736. gMacros.plural = function (str, param, key, prop) {
  12737. var n = parseFloat(param);
  12738. if (isNaN(n)) return str;
  12739. if (prop != gTextProp) return str;
  12740. if (!gMacros._pluralRules) {
  12741. gMacros._pluralRules = getPluralRules(gLanguage);
  12742. }
  12743. var index = '[' + gMacros._pluralRules(n) + ']';
  12744. if (n === 0 && key + '[zero]' in gL10nData) {
  12745. str = gL10nData[key + '[zero]'][prop];
  12746. } else if (n == 1 && key + '[one]' in gL10nData) {
  12747. str = gL10nData[key + '[one]'][prop];
  12748. } else if (n == 2 && key + '[two]' in gL10nData) {
  12749. str = gL10nData[key + '[two]'][prop];
  12750. } else if (key + index in gL10nData) {
  12751. str = gL10nData[key + index][prop];
  12752. } else if (key + '[other]' in gL10nData) {
  12753. str = gL10nData[key + '[other]'][prop];
  12754. }
  12755. return str;
  12756. };
  12757. function getL10nData(key, args, fallback) {
  12758. var data = gL10nData[key];
  12759. if (!data) {
  12760. console.warn('#' + key + ' is undefined.');
  12761. if (!fallback) {
  12762. return null;
  12763. }
  12764. data = fallback;
  12765. }
  12766. var rv = {};
  12767. for (var prop in data) {
  12768. var str = data[prop];
  12769. str = substIndexes(str, args, key, prop);
  12770. str = substArguments(str, args, key);
  12771. rv[prop] = str;
  12772. }
  12773. return rv;
  12774. }
  12775. function substIndexes(str, args, key, prop) {
  12776. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  12777. var reMatch = reIndex.exec(str);
  12778. if (!reMatch || !reMatch.length) return str;
  12779. var macroName = reMatch[1];
  12780. var paramName = reMatch[2];
  12781. var param;
  12782. if (args && paramName in args) {
  12783. param = args[paramName];
  12784. } else if (paramName in gL10nData) {
  12785. param = gL10nData[paramName];
  12786. }
  12787. if (macroName in gMacros) {
  12788. var macro = gMacros[macroName];
  12789. str = macro(str, param, key, prop);
  12790. }
  12791. return str;
  12792. }
  12793. function substArguments(str, args, key) {
  12794. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  12795. return str.replace(reArgs, function (matched_text, arg) {
  12796. if (args && arg in args) {
  12797. return args[arg];
  12798. }
  12799. if (arg in gL10nData) {
  12800. return gL10nData[arg];
  12801. }
  12802. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  12803. return matched_text;
  12804. });
  12805. }
  12806. function translateElement(element) {
  12807. var l10n = getL10nAttributes(element);
  12808. if (!l10n.id) return;
  12809. var data = getL10nData(l10n.id, l10n.args);
  12810. if (!data) {
  12811. console.warn('#' + l10n.id + ' is undefined.');
  12812. return;
  12813. }
  12814. if (data[gTextProp]) {
  12815. if (getChildElementCount(element) === 0) {
  12816. element[gTextProp] = data[gTextProp];
  12817. } else {
  12818. var children = element.childNodes;
  12819. var found = false;
  12820. for (var i = 0, l = children.length; i < l; i++) {
  12821. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  12822. if (found) {
  12823. children[i].nodeValue = '';
  12824. } else {
  12825. children[i].nodeValue = data[gTextProp];
  12826. found = true;
  12827. }
  12828. }
  12829. }
  12830. if (!found) {
  12831. var textNode = document.createTextNode(data[gTextProp]);
  12832. element.prepend(textNode);
  12833. }
  12834. }
  12835. delete data[gTextProp];
  12836. }
  12837. for (var k in data) {
  12838. element[k] = data[k];
  12839. }
  12840. }
  12841. function getChildElementCount(element) {
  12842. if (element.children) {
  12843. return element.children.length;
  12844. }
  12845. if (typeof element.childElementCount !== 'undefined') {
  12846. return element.childElementCount;
  12847. }
  12848. var count = 0;
  12849. for (var i = 0; i < element.childNodes.length; i++) {
  12850. count += element.nodeType === 1 ? 1 : 0;
  12851. }
  12852. return count;
  12853. }
  12854. function translateFragment(element) {
  12855. element = element || document.documentElement;
  12856. var children = getTranslatableChildren(element);
  12857. var elementCount = children.length;
  12858. for (var i = 0; i < elementCount; i++) {
  12859. translateElement(children[i]);
  12860. }
  12861. translateElement(element);
  12862. }
  12863. return {
  12864. get: function (key, args, fallbackString) {
  12865. var index = key.lastIndexOf('.');
  12866. var prop = gTextProp;
  12867. if (index > 0) {
  12868. prop = key.substring(index + 1);
  12869. key = key.substring(0, index);
  12870. }
  12871. var fallback;
  12872. if (fallbackString) {
  12873. fallback = {};
  12874. fallback[prop] = fallbackString;
  12875. }
  12876. var data = getL10nData(key, args, fallback);
  12877. if (data && prop in data) {
  12878. return data[prop];
  12879. }
  12880. return '{{' + key + '}}';
  12881. },
  12882. getData: function () {
  12883. return gL10nData;
  12884. },
  12885. getText: function () {
  12886. return gTextData;
  12887. },
  12888. getLanguage: function () {
  12889. return gLanguage;
  12890. },
  12891. setLanguage: function (lang, callback) {
  12892. loadLocale(lang, function () {
  12893. if (callback) callback();
  12894. });
  12895. },
  12896. getDirection: function () {
  12897. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  12898. var shortCode = gLanguage.split('-', 1)[0];
  12899. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  12900. },
  12901. translate: translateFragment,
  12902. getReadyState: function () {
  12903. return gReadyState;
  12904. },
  12905. ready: function (callback) {
  12906. if (!callback) {
  12907. return;
  12908. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  12909. window.setTimeout(function () {
  12910. callback();
  12911. });
  12912. } else if (document.addEventListener) {
  12913. document.addEventListener('localized', function once() {
  12914. document.removeEventListener('localized', once);
  12915. callback();
  12916. });
  12917. }
  12918. }
  12919. };
  12920. }(window, document);
  12921. /***/ }),
  12922. /* 46 */
  12923. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12924. Object.defineProperty(exports, "__esModule", ({
  12925. value: true
  12926. }));
  12927. exports.GenericScripting = void 0;
  12928. exports.docPropertiesLookup = docPropertiesLookup;
  12929. var _pdfjsLib = __webpack_require__(5);
  12930. async function docPropertiesLookup(pdfDocument) {
  12931. const url = "",
  12932. baseUrl = url.split("#")[0];
  12933. let {
  12934. info,
  12935. metadata,
  12936. contentDispositionFilename,
  12937. contentLength
  12938. } = await pdfDocument.getMetadata();
  12939. if (!contentLength) {
  12940. const {
  12941. length
  12942. } = await pdfDocument.getDownloadInfo();
  12943. contentLength = length;
  12944. }
  12945. return {
  12946. ...info,
  12947. baseURL: baseUrl,
  12948. filesize: contentLength,
  12949. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  12950. metadata: metadata?.getRaw(),
  12951. authors: metadata?.get("dc:creator"),
  12952. numPages: pdfDocument.numPages,
  12953. URL: url
  12954. };
  12955. }
  12956. class GenericScripting {
  12957. constructor(sandboxBundleSrc) {
  12958. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  12959. return window.pdfjsSandbox.QuickJSSandbox();
  12960. });
  12961. }
  12962. async createSandbox(data) {
  12963. const sandbox = await this._ready;
  12964. sandbox.create(data);
  12965. }
  12966. async dispatchEventInSandbox(event) {
  12967. const sandbox = await this._ready;
  12968. setTimeout(() => sandbox.dispatchEvent(event), 0);
  12969. }
  12970. async destroySandbox() {
  12971. const sandbox = await this._ready;
  12972. sandbox.nukeSandbox();
  12973. }
  12974. }
  12975. exports.GenericScripting = GenericScripting;
  12976. /***/ }),
  12977. /* 47 */
  12978. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12979. Object.defineProperty(exports, "__esModule", ({
  12980. value: true
  12981. }));
  12982. exports.PDFPrintService = PDFPrintService;
  12983. var _pdfjsLib = __webpack_require__(5);
  12984. var _app = __webpack_require__(4);
  12985. var _print_utils = __webpack_require__(48);
  12986. let activeService = null;
  12987. let dialog = null;
  12988. let overlayManager = null;
  12989. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  12990. const scratchCanvas = activeService.scratchCanvas;
  12991. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  12992. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  12993. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  12994. const ctx = scratchCanvas.getContext("2d");
  12995. ctx.save();
  12996. ctx.fillStyle = "rgb(255, 255, 255)";
  12997. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  12998. ctx.restore();
  12999. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  13000. const renderContext = {
  13001. canvasContext: ctx,
  13002. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  13003. viewport: pdfPage.getViewport({
  13004. scale: 1,
  13005. rotation: size.rotation
  13006. }),
  13007. intent: "print",
  13008. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  13009. optionalContentConfigPromise,
  13010. printAnnotationStorage
  13011. };
  13012. return pdfPage.render(renderContext).promise;
  13013. });
  13014. }
  13015. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) {
  13016. this.pdfDocument = pdfDocument;
  13017. this.pagesOverview = pagesOverview;
  13018. this.printContainer = printContainer;
  13019. this._printResolution = printResolution || 150;
  13020. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  13021. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  13022. this.l10n = l10n;
  13023. this.currentPage = -1;
  13024. this.scratchCanvas = document.createElement("canvas");
  13025. }
  13026. PDFPrintService.prototype = {
  13027. layout() {
  13028. this.throwIfInactive();
  13029. const body = document.querySelector("body");
  13030. body.setAttribute("data-pdfjsprinting", true);
  13031. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  13032. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  13033. }, this);
  13034. if (!hasEqualPageSizes) {
  13035. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  13036. }
  13037. this.pageStyleSheet = document.createElement("style");
  13038. const pageSize = this.pagesOverview[0];
  13039. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  13040. body.append(this.pageStyleSheet);
  13041. },
  13042. destroy() {
  13043. if (activeService !== this) {
  13044. return;
  13045. }
  13046. this.printContainer.textContent = "";
  13047. const body = document.querySelector("body");
  13048. body.removeAttribute("data-pdfjsprinting");
  13049. if (this.pageStyleSheet) {
  13050. this.pageStyleSheet.remove();
  13051. this.pageStyleSheet = null;
  13052. }
  13053. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  13054. this.scratchCanvas = null;
  13055. activeService = null;
  13056. ensureOverlay().then(function () {
  13057. if (overlayManager.active === dialog) {
  13058. overlayManager.close(dialog);
  13059. }
  13060. });
  13061. },
  13062. renderPages() {
  13063. if (this.pdfDocument.isPureXfa) {
  13064. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  13065. return Promise.resolve();
  13066. }
  13067. const pageCount = this.pagesOverview.length;
  13068. const renderNextPage = (resolve, reject) => {
  13069. this.throwIfInactive();
  13070. if (++this.currentPage >= pageCount) {
  13071. renderProgress(pageCount, pageCount, this.l10n);
  13072. resolve();
  13073. return;
  13074. }
  13075. const index = this.currentPage;
  13076. renderProgress(index, pageCount, this.l10n);
  13077. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  13078. renderNextPage(resolve, reject);
  13079. }, reject);
  13080. };
  13081. return new Promise(renderNextPage);
  13082. },
  13083. useRenderedPage() {
  13084. this.throwIfInactive();
  13085. const img = document.createElement("img");
  13086. const scratchCanvas = this.scratchCanvas;
  13087. if ("toBlob" in scratchCanvas) {
  13088. scratchCanvas.toBlob(function (blob) {
  13089. img.src = URL.createObjectURL(blob);
  13090. });
  13091. } else {
  13092. img.src = scratchCanvas.toDataURL();
  13093. }
  13094. const wrapper = document.createElement("div");
  13095. wrapper.className = "printedPage";
  13096. wrapper.append(img);
  13097. this.printContainer.append(wrapper);
  13098. return new Promise(function (resolve, reject) {
  13099. img.onload = resolve;
  13100. img.onerror = reject;
  13101. });
  13102. },
  13103. performPrint() {
  13104. this.throwIfInactive();
  13105. return new Promise(resolve => {
  13106. setTimeout(() => {
  13107. if (!this.active) {
  13108. resolve();
  13109. return;
  13110. }
  13111. print.call(window);
  13112. setTimeout(resolve, 20);
  13113. }, 0);
  13114. });
  13115. },
  13116. get active() {
  13117. return this === activeService;
  13118. },
  13119. throwIfInactive() {
  13120. if (!this.active) {
  13121. throw new Error("This print request was cancelled or completed.");
  13122. }
  13123. }
  13124. };
  13125. const print = window.print;
  13126. window.print = function () {
  13127. if (activeService) {
  13128. console.warn("Ignored window.print() because of a pending print job.");
  13129. return;
  13130. }
  13131. ensureOverlay().then(function () {
  13132. if (activeService) {
  13133. overlayManager.open(dialog);
  13134. }
  13135. });
  13136. try {
  13137. dispatchEvent("beforeprint");
  13138. } finally {
  13139. if (!activeService) {
  13140. console.error("Expected print service to be initialized.");
  13141. ensureOverlay().then(function () {
  13142. if (overlayManager.active === dialog) {
  13143. overlayManager.close(dialog);
  13144. }
  13145. });
  13146. return;
  13147. }
  13148. const activeServiceOnEntry = activeService;
  13149. activeService.renderPages().then(function () {
  13150. return activeServiceOnEntry.performPrint();
  13151. }).catch(function () {}).then(function () {
  13152. if (activeServiceOnEntry.active) {
  13153. abort();
  13154. }
  13155. });
  13156. }
  13157. };
  13158. function dispatchEvent(eventType) {
  13159. const event = document.createEvent("CustomEvent");
  13160. event.initCustomEvent(eventType, false, false, "custom");
  13161. window.dispatchEvent(event);
  13162. }
  13163. function abort() {
  13164. if (activeService) {
  13165. activeService.destroy();
  13166. dispatchEvent("afterprint");
  13167. }
  13168. }
  13169. function renderProgress(index, total, l10n) {
  13170. dialog ||= document.getElementById("printServiceDialog");
  13171. const progress = Math.round(100 * index / total);
  13172. const progressBar = dialog.querySelector("progress");
  13173. const progressPerc = dialog.querySelector(".relative-progress");
  13174. progressBar.value = progress;
  13175. l10n.get("print_progress_percent", {
  13176. progress
  13177. }).then(msg => {
  13178. progressPerc.textContent = msg;
  13179. });
  13180. }
  13181. // window.addEventListener("keydown", function (event) {
  13182. // if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  13183. // window.print();
  13184. // event.preventDefault();
  13185. // event.stopImmediatePropagation();
  13186. // }
  13187. // }, true);
  13188. if ("onbeforeprint" in window) {
  13189. const stopPropagationIfNeeded = function (event) {
  13190. if (event.detail !== "custom") {
  13191. event.stopImmediatePropagation();
  13192. }
  13193. };
  13194. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  13195. window.addEventListener("afterprint", stopPropagationIfNeeded);
  13196. }
  13197. let overlayPromise;
  13198. function ensureOverlay() {
  13199. if (!overlayPromise) {
  13200. overlayManager = _app.PDFViewerApplication.overlayManager;
  13201. if (!overlayManager) {
  13202. throw new Error("The overlay manager has not yet been initialized.");
  13203. }
  13204. dialog ||= document.getElementById("printServiceDialog");
  13205. overlayPromise = overlayManager.register(dialog, true);
  13206. document.getElementById("printCancel").onclick = abort;
  13207. dialog.addEventListener("close", abort);
  13208. }
  13209. return overlayPromise;
  13210. }
  13211. _app.PDFPrintServiceFactory.instance = {
  13212. supportsPrinting: true,
  13213. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  13214. if (activeService) {
  13215. throw new Error("The print service is created and active.");
  13216. }
  13217. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  13218. return activeService;
  13219. }
  13220. };
  13221. /***/ }),
  13222. /* 48 */
  13223. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13224. Object.defineProperty(exports, "__esModule", ({
  13225. value: true
  13226. }));
  13227. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  13228. var _pdfjsLib = __webpack_require__(5);
  13229. var _pdf_link_service = __webpack_require__(3);
  13230. var _xfa_layer_builder = __webpack_require__(37);
  13231. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  13232. const xfaHtml = pdfDocument.allXfaHtml;
  13233. const linkService = new _pdf_link_service.SimpleLinkService();
  13234. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  13235. for (const xfaPage of xfaHtml.children) {
  13236. const page = document.createElement("div");
  13237. page.className = "xfaPrintedPage";
  13238. printContainer.append(page);
  13239. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  13240. pageDiv: page,
  13241. pdfPage: null,
  13242. annotationStorage: pdfDocument.annotationStorage,
  13243. linkService,
  13244. xfaHtml: xfaPage
  13245. });
  13246. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  13247. scale
  13248. });
  13249. builder.render(viewport, "print");
  13250. }
  13251. }
  13252. /***/ })
  13253. /******/ ]);
  13254. /************************************************************************/
  13255. /******/ // The module cache
  13256. /******/ var __webpack_module_cache__ = {};
  13257. /******/
  13258. /******/ // The require function
  13259. /******/ function __webpack_require__(moduleId) {
  13260. /******/ // Check if module is in cache
  13261. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  13262. /******/ if (cachedModule !== undefined) {
  13263. /******/ return cachedModule.exports;
  13264. /******/ }
  13265. /******/ // Create a new module (and put it into the cache)
  13266. /******/ var module = __webpack_module_cache__[moduleId] = {
  13267. /******/ // no module.id needed
  13268. /******/ // no module.loaded needed
  13269. /******/ exports: {}
  13270. /******/ };
  13271. /******/
  13272. /******/ // Execute the module function
  13273. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  13274. /******/
  13275. /******/ // Return the exports of the module
  13276. /******/ return module.exports;
  13277. /******/ }
  13278. /******/
  13279. /************************************************************************/
  13280. var __webpack_exports__ = {};
  13281. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  13282. (() => {
  13283. var exports = __webpack_exports__;
  13284. Object.defineProperty(exports, "__esModule", ({
  13285. value: true
  13286. }));
  13287. Object.defineProperty(exports, "PDFViewerApplication", ({
  13288. enumerable: true,
  13289. get: function () {
  13290. return _app.PDFViewerApplication;
  13291. }
  13292. }));
  13293. exports.PDFViewerApplicationConstants = void 0;
  13294. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  13295. enumerable: true,
  13296. get: function () {
  13297. return _app_options.AppOptions;
  13298. }
  13299. }));
  13300. var _ui_utils = __webpack_require__(1);
  13301. var _app_options = __webpack_require__(2);
  13302. var _pdf_link_service = __webpack_require__(3);
  13303. var _app = __webpack_require__(4);
  13304. const pdfjsVersion = '3.1.81';
  13305. const pdfjsBuild = '0766898d5';
  13306. const AppConstants = {
  13307. LinkTarget: _pdf_link_service.LinkTarget,
  13308. RenderingStates: _ui_utils.RenderingStates,
  13309. ScrollMode: _ui_utils.ScrollMode,
  13310. SpreadMode: _ui_utils.SpreadMode
  13311. };
  13312. exports.PDFViewerApplicationConstants = AppConstants;
  13313. window.PDFViewerApplication = _app.PDFViewerApplication;
  13314. window.PDFViewerApplicationConstants = AppConstants;
  13315. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  13316. ;
  13317. ;
  13318. {
  13319. __webpack_require__(41);
  13320. }
  13321. ;
  13322. {
  13323. __webpack_require__(47);
  13324. }
  13325. function getViewerConfiguration() {
  13326. return {
  13327. appContainer: document.body,
  13328. mainContainer: document.getElementById("viewerContainer"),
  13329. viewerContainer: document.getElementById("viewer"),
  13330. toolbar: {
  13331. container: document.getElementById("toolbarViewer"),
  13332. numPages: document.getElementById("numPages"),
  13333. pageNumber: document.getElementById("pageNumber"),
  13334. scaleSelect: document.getElementById("scaleSelect"),
  13335. customScaleOption: document.getElementById("customScaleOption"),
  13336. previous: document.getElementById("previous"),
  13337. next: document.getElementById("next"),
  13338. zoomIn: document.getElementById("zoomIn"),
  13339. zoomOut: document.getElementById("zoomOut"),
  13340. viewFind: document.getElementById("viewFind"),
  13341. openFile: document.getElementById("openFile"),
  13342. print: document.getElementById("print"),
  13343. editorFreeTextButton: document.getElementById("editorFreeText"),
  13344. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  13345. editorInkButton: document.getElementById("editorInk"),
  13346. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  13347. download: document.getElementById("download")
  13348. },
  13349. secondaryToolbar: {
  13350. toolbar: document.getElementById("secondaryToolbar"),
  13351. toggleButton: document.getElementById("secondaryToolbarToggle"),
  13352. presentationModeButton: document.getElementById("presentationMode"),
  13353. openFileButton: document.getElementById("secondaryOpenFile"),
  13354. printButton: document.getElementById("secondaryPrint"),
  13355. downloadButton: document.getElementById("secondaryDownload"),
  13356. viewBookmarkButton: document.getElementById("viewBookmark"),
  13357. firstPageButton: document.getElementById("firstPage"),
  13358. lastPageButton: document.getElementById("lastPage"),
  13359. pageRotateCwButton: document.getElementById("pageRotateCw"),
  13360. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  13361. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  13362. cursorHandToolButton: document.getElementById("cursorHandTool"),
  13363. scrollPageButton: document.getElementById("scrollPage"),
  13364. scrollVerticalButton: document.getElementById("scrollVertical"),
  13365. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  13366. scrollWrappedButton: document.getElementById("scrollWrapped"),
  13367. spreadNoneButton: document.getElementById("spreadNone"),
  13368. spreadOddButton: document.getElementById("spreadOdd"),
  13369. spreadEvenButton: document.getElementById("spreadEven"),
  13370. documentPropertiesButton: document.getElementById("documentProperties")
  13371. },
  13372. sidebar: {
  13373. outerContainer: document.getElementById("outerContainer"),
  13374. sidebarContainer: document.getElementById("sidebarContainer"),
  13375. sidebarContainerMask: document.getElementById("sidebarContainerMask"),
  13376. toggleButton: document.getElementById("sidebarToggle"),
  13377. thumbnailButton: document.getElementById("viewThumbnail"),
  13378. outlineButton: document.getElementById("viewOutline"),
  13379. attachmentsButton: document.getElementById("viewAttachments"),
  13380. layersButton: document.getElementById("viewLayers"),
  13381. thumbnailView: document.getElementById("thumbnailView"),
  13382. outlineView: document.getElementById("outlineView"),
  13383. attachmentsView: document.getElementById("attachmentsView"),
  13384. layersView: document.getElementById("layersView"),
  13385. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  13386. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  13387. },
  13388. sidebarResizer: {
  13389. outerContainer: document.getElementById("outerContainer"),
  13390. resizer: document.getElementById("sidebarResizer")
  13391. },
  13392. findBar: {
  13393. bar: document.getElementById("findbar"),
  13394. toggleButton: document.getElementById("viewFind"),
  13395. findField: document.getElementById("findInput"),
  13396. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  13397. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  13398. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  13399. entireWordCheckbox: document.getElementById("findEntireWord"),
  13400. findMsg: document.getElementById("findMsg"),
  13401. findResultsCount: document.getElementById("findResultsCount"),
  13402. findPreviousButton: document.getElementById("findPrevious"),
  13403. findNextButton: document.getElementById("findNext")
  13404. },
  13405. passwordOverlay: {
  13406. dialog: document.getElementById("passwordDialog"),
  13407. label: document.getElementById("passwordText"),
  13408. input: document.getElementById("password"),
  13409. submitButton: document.getElementById("passwordSubmit"),
  13410. cancelButton: document.getElementById("passwordCancel")
  13411. },
  13412. documentProperties: {
  13413. dialog: document.getElementById("documentPropertiesDialog"),
  13414. closeButton: document.getElementById("documentPropertiesClose"),
  13415. fields: {
  13416. fileName: document.getElementById("fileNameField"),
  13417. fileSize: document.getElementById("fileSizeField"),
  13418. title: document.getElementById("titleField"),
  13419. author: document.getElementById("authorField"),
  13420. subject: document.getElementById("subjectField"),
  13421. keywords: document.getElementById("keywordsField"),
  13422. creationDate: document.getElementById("creationDateField"),
  13423. modificationDate: document.getElementById("modificationDateField"),
  13424. creator: document.getElementById("creatorField"),
  13425. producer: document.getElementById("producerField"),
  13426. version: document.getElementById("versionField"),
  13427. pageCount: document.getElementById("pageCountField"),
  13428. pageSize: document.getElementById("pageSizeField"),
  13429. linearized: document.getElementById("linearizedField")
  13430. }
  13431. },
  13432. annotationEditorParams: {
  13433. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  13434. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  13435. editorInkColor: document.getElementById("editorInkColor"),
  13436. editorInkThickness: document.getElementById("editorInkThickness"),
  13437. editorInkOpacity: document.getElementById("editorInkOpacity")
  13438. },
  13439. printContainer: document.getElementById("printContainer"),
  13440. openFileInput: document.getElementById("fileInput"),
  13441. debuggerScriptPath: "./debugger.js"
  13442. };
  13443. }
  13444. function webViewerLoad() {
  13445. const config = getViewerConfiguration();
  13446. const event = document.createEvent("CustomEvent");
  13447. event.initCustomEvent("webviewerloaded", true, true, {
  13448. source: window
  13449. });
  13450. try {
  13451. parent.document.dispatchEvent(event);
  13452. } catch (ex) {
  13453. console.error(`webviewerloaded: ${ex}`);
  13454. document.dispatchEvent(event);
  13455. }
  13456. _app.PDFViewerApplication.run(config);
  13457. }
  13458. document.blockUnblockOnload?.(true);
  13459. if (document.readyState === "interactive" || document.readyState === "complete") {
  13460. webViewerLoad();
  13461. } else {
  13462. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  13463. }
  13464. })();
  13465. /******/ })()
  13466. ;
  13467. //# sourceMappingURL=viewer.js.map