pdf_viewer.js 222 KB

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