viewer.js 501 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2023 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = void 0;
  32. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  33. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  34. exports.approximateFraction = approximateFraction;
  35. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  36. exports.binarySearchFirstItem = binarySearchFirstItem;
  37. exports.docStyle = void 0;
  38. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  39. exports.getPageSizeInches = getPageSizeInches;
  40. exports.getVisibleElements = getVisibleElements;
  41. exports.isPortraitOrientation = isPortraitOrientation;
  42. exports.isValidRotation = isValidRotation;
  43. exports.isValidScrollMode = isValidScrollMode;
  44. exports.isValidSpreadMode = isValidSpreadMode;
  45. exports.noContextMenuHandler = noContextMenuHandler;
  46. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  47. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  48. exports.parseQueryString = parseQueryString;
  49. exports.removeNullCharacters = removeNullCharacters;
  50. exports.roundToDivide = roundToDivide;
  51. exports.scrollIntoView = scrollIntoView;
  52. exports.watchScroll = watchScroll;
  53. const DEFAULT_SCALE_VALUE = "auto";
  54. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  55. const DEFAULT_SCALE = 1.0;
  56. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  57. const DEFAULT_SCALE_DELTA = 1.1;
  58. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  59. const MIN_SCALE = 0.1;
  60. exports.MIN_SCALE = MIN_SCALE;
  61. const MAX_SCALE = 10.0;
  62. exports.MAX_SCALE = MAX_SCALE;
  63. const UNKNOWN_SCALE = 0;
  64. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  65. const MAX_AUTO_SCALE = 1.25;
  66. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  67. const SCROLLBAR_PADDING = 40;
  68. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  69. const VERTICAL_PADDING = 5;
  70. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  71. const RenderingStates = {
  72. INITIAL: 0,
  73. RUNNING: 1,
  74. PAUSED: 2,
  75. FINISHED: 3
  76. };
  77. exports.RenderingStates = RenderingStates;
  78. const PresentationModeState = {
  79. UNKNOWN: 0,
  80. NORMAL: 1,
  81. CHANGING: 2,
  82. FULLSCREEN: 3
  83. };
  84. exports.PresentationModeState = PresentationModeState;
  85. const SidebarView = {
  86. UNKNOWN: -1,
  87. NONE: 0,
  88. THUMBS: 1,
  89. OUTLINE: 2,
  90. ATTACHMENTS: 3,
  91. LAYERS: 4
  92. };
  93. exports.SidebarView = SidebarView;
  94. const RendererType = {
  95. CANVAS: "canvas",
  96. SVG: "svg"
  97. };
  98. exports.RendererType = RendererType;
  99. const TextLayerMode = {
  100. DISABLE: 0,
  101. ENABLE: 1
  102. };
  103. exports.TextLayerMode = TextLayerMode;
  104. const ScrollMode = {
  105. UNKNOWN: -1,
  106. VERTICAL: 0,
  107. HORIZONTAL: 1,
  108. WRAPPED: 2,
  109. PAGE: 3
  110. };
  111. exports.ScrollMode = ScrollMode;
  112. const SpreadMode = {
  113. UNKNOWN: -1,
  114. NONE: 0,
  115. ODD: 1,
  116. EVEN: 2
  117. };
  118. exports.SpreadMode = SpreadMode;
  119. const AutoPrintRegExp = /\bprint\s*\(/;
  120. exports.AutoPrintRegExp = AutoPrintRegExp;
  121. class OutputScale {
  122. constructor() {
  123. const pixelRatio = window.devicePixelRatio || 1;
  124. this.sx = pixelRatio;
  125. this.sy = pixelRatio;
  126. }
  127. get scaled() {
  128. return this.sx !== 1 || this.sy !== 1;
  129. }
  130. }
  131. exports.OutputScale = OutputScale;
  132. function scrollIntoView(element, spot, scrollMatches = false) {
  133. let parent = element.offsetParent;
  134. if (!parent) {
  135. console.error("offsetParent is not set -- cannot scroll");
  136. return;
  137. }
  138. let offsetY = element.offsetTop + element.clientTop;
  139. let offsetX = element.offsetLeft + element.clientLeft;
  140. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  141. offsetY += parent.offsetTop;
  142. offsetX += parent.offsetLeft;
  143. parent = parent.offsetParent;
  144. if (!parent) {
  145. return;
  146. }
  147. }
  148. if (spot) {
  149. if (spot.top !== undefined) {
  150. offsetY += spot.top;
  151. }
  152. if (spot.left !== undefined) {
  153. offsetX += spot.left;
  154. parent.scrollLeft = offsetX;
  155. }
  156. }
  157. parent.scrollTop = offsetY;
  158. }
  159. function watchScroll(viewAreaElement, callback) {
  160. const debounceScroll = function (evt) {
  161. if (rAF) {
  162. return;
  163. }
  164. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  165. rAF = null;
  166. const currentX = viewAreaElement.scrollLeft;
  167. const lastX = state.lastX;
  168. if (currentX !== lastX) {
  169. state.right = currentX > lastX;
  170. }
  171. state.lastX = currentX;
  172. const currentY = viewAreaElement.scrollTop;
  173. const lastY = state.lastY;
  174. if (currentY !== lastY) {
  175. state.down = currentY > lastY;
  176. }
  177. state.lastY = currentY;
  178. callback(state);
  179. });
  180. };
  181. const state = {
  182. right: true,
  183. down: true,
  184. lastX: viewAreaElement.scrollLeft,
  185. lastY: viewAreaElement.scrollTop,
  186. _eventHandler: debounceScroll
  187. };
  188. let rAF = null;
  189. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  190. return state;
  191. }
  192. function parseQueryString(query) {
  193. const params = new Map();
  194. for (const [key, value] of new URLSearchParams(query)) {
  195. params.set(key.toLowerCase(), value);
  196. }
  197. return params;
  198. }
  199. const NullCharactersRegExp = /\x00/g;
  200. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  201. function removeNullCharacters(str, replaceInvisible = false) {
  202. if (typeof str !== "string") {
  203. console.error(`The argument must be a string.`);
  204. return str;
  205. }
  206. if (replaceInvisible) {
  207. str = str.replace(InvisibleCharactersRegExp, " ");
  208. }
  209. return str.replace(NullCharactersRegExp, "");
  210. }
  211. function binarySearchFirstItem(items, condition, start = 0) {
  212. let minIndex = start;
  213. let maxIndex = items.length - 1;
  214. if (maxIndex < 0 || !condition(items[maxIndex])) {
  215. return items.length;
  216. }
  217. if (condition(items[minIndex])) {
  218. return minIndex;
  219. }
  220. while (minIndex < maxIndex) {
  221. const currentIndex = minIndex + maxIndex >> 1;
  222. const currentItem = items[currentIndex];
  223. if (condition(currentItem)) {
  224. maxIndex = currentIndex;
  225. } else {
  226. minIndex = currentIndex + 1;
  227. }
  228. }
  229. return minIndex;
  230. }
  231. function approximateFraction(x) {
  232. if (Math.floor(x) === x) {
  233. return [x, 1];
  234. }
  235. const xinv = 1 / x;
  236. const limit = 8;
  237. if (xinv > limit) {
  238. return [1, limit];
  239. } else if (Math.floor(xinv) === xinv) {
  240. return [1, xinv];
  241. }
  242. const x_ = x > 1 ? xinv : x;
  243. let a = 0,
  244. b = 1,
  245. c = 1,
  246. d = 1;
  247. while (true) {
  248. const p = a + c,
  249. q = b + d;
  250. if (q > limit) {
  251. break;
  252. }
  253. if (x_ <= p / q) {
  254. c = p;
  255. d = q;
  256. } else {
  257. a = p;
  258. b = q;
  259. }
  260. }
  261. let result;
  262. if (x_ - a / b < c / d - x_) {
  263. result = x_ === x ? [a, b] : [b, a];
  264. } else {
  265. result = x_ === x ? [c, d] : [d, c];
  266. }
  267. return result;
  268. }
  269. function roundToDivide(x, div) {
  270. const r = x % div;
  271. return r === 0 ? x : Math.round(x - r + div);
  272. }
  273. function getPageSizeInches({
  274. view,
  275. userUnit,
  276. rotate
  277. }) {
  278. const [x1, y1, x2, y2] = view;
  279. const changeOrientation = rotate % 180 !== 0;
  280. const width = (x2 - x1) / 72 * userUnit;
  281. const height = (y2 - y1) / 72 * userUnit;
  282. return {
  283. width: changeOrientation ? height : width,
  284. height: changeOrientation ? width : height
  285. };
  286. }
  287. function backtrackBeforeAllVisibleElements(index, views, top) {
  288. if (index < 2) {
  289. return index;
  290. }
  291. let elt = views[index].div;
  292. let pageTop = elt.offsetTop + elt.clientTop;
  293. if (pageTop >= top) {
  294. elt = views[index - 1].div;
  295. pageTop = elt.offsetTop + elt.clientTop;
  296. }
  297. for (let i = index - 2; i >= 0; --i) {
  298. elt = views[i].div;
  299. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  300. break;
  301. }
  302. index = i;
  303. }
  304. return index;
  305. }
  306. function getVisibleElements({
  307. scrollEl,
  308. views,
  309. sortByVisibility = false,
  310. horizontal = false,
  311. rtl = false
  312. }) {
  313. const top = scrollEl.scrollTop,
  314. bottom = top + scrollEl.clientHeight;
  315. const left = scrollEl.scrollLeft,
  316. right = left + scrollEl.clientWidth;
  317. function isElementBottomAfterViewTop(view) {
  318. const element = view.div;
  319. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  320. return elementBottom > top;
  321. }
  322. function isElementNextAfterViewHorizontally(view) {
  323. const element = view.div;
  324. const elementLeft = element.offsetLeft + element.clientLeft;
  325. const elementRight = elementLeft + element.clientWidth;
  326. return rtl ? elementLeft < right : elementRight > left;
  327. }
  328. const visible = [],
  329. ids = new Set(),
  330. numViews = views.length;
  331. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  332. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  333. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  334. }
  335. let lastEdge = horizontal ? right : -1;
  336. for (let i = firstVisibleElementInd; i < numViews; i++) {
  337. const view = views[i],
  338. element = view.div;
  339. const currentWidth = element.offsetLeft + element.clientLeft;
  340. const currentHeight = element.offsetTop + element.clientTop;
  341. const viewWidth = element.clientWidth,
  342. viewHeight = element.clientHeight;
  343. const viewRight = currentWidth + viewWidth;
  344. const viewBottom = currentHeight + viewHeight;
  345. if (lastEdge === -1) {
  346. if (viewBottom >= bottom) {
  347. lastEdge = viewBottom;
  348. }
  349. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  350. break;
  351. }
  352. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  353. continue;
  354. }
  355. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  356. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  357. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  358. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  359. const percent = fractionHeight * fractionWidth * 100 | 0;
  360. visible.push({
  361. id: view.id,
  362. x: currentWidth,
  363. y: currentHeight,
  364. view,
  365. percent,
  366. widthPercent: fractionWidth * 100 | 0
  367. });
  368. ids.add(view.id);
  369. }
  370. const first = visible[0],
  371. last = visible.at(-1);
  372. if (sortByVisibility) {
  373. visible.sort(function (a, b) {
  374. const pc = a.percent - b.percent;
  375. if (Math.abs(pc) > 0.001) {
  376. return -pc;
  377. }
  378. return a.id - b.id;
  379. });
  380. }
  381. return {
  382. first,
  383. last,
  384. views: visible,
  385. ids
  386. };
  387. }
  388. function noContextMenuHandler(evt) {
  389. evt.preventDefault();
  390. }
  391. function normalizeWheelEventDirection(evt) {
  392. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  393. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  394. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  395. delta = -delta;
  396. }
  397. return delta;
  398. }
  399. function normalizeWheelEventDelta(evt) {
  400. const deltaMode = evt.deltaMode;
  401. let delta = normalizeWheelEventDirection(evt);
  402. const MOUSE_PIXELS_PER_LINE = 30;
  403. const MOUSE_LINES_PER_PAGE = 30;
  404. if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
  405. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  406. } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
  407. delta /= MOUSE_LINES_PER_PAGE;
  408. }
  409. return delta;
  410. }
  411. function isValidRotation(angle) {
  412. return Number.isInteger(angle) && angle % 90 === 0;
  413. }
  414. function isValidScrollMode(mode) {
  415. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  416. }
  417. function isValidSpreadMode(mode) {
  418. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  419. }
  420. function isPortraitOrientation(size) {
  421. return size.width <= size.height;
  422. }
  423. const animationStarted = new Promise(function (resolve) {
  424. window.requestAnimationFrame(resolve);
  425. });
  426. exports.animationStarted = animationStarted;
  427. const docStyle = document.documentElement.style;
  428. exports.docStyle = docStyle;
  429. function clamp(v, min, max) {
  430. return Math.min(Math.max(v, min), max);
  431. }
  432. class ProgressBar {
  433. #classList = null;
  434. #disableAutoFetchTimeout = null;
  435. #percent = 0;
  436. #style = null;
  437. #visible = true;
  438. constructor(bar) {
  439. this.#classList = bar.classList;
  440. this.#style = bar.style;
  441. }
  442. get percent() {
  443. return this.#percent;
  444. }
  445. set percent(val) {
  446. this.#percent = clamp(val, 0, 100);
  447. if (isNaN(val)) {
  448. this.#classList.add("indeterminate");
  449. return;
  450. }
  451. this.#classList.remove("indeterminate");
  452. this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
  453. }
  454. setWidth(viewer) {
  455. if (!viewer) {
  456. return;
  457. }
  458. const container = viewer.parentNode;
  459. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  460. if (scrollbarWidth > 0) {
  461. this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  462. }
  463. }
  464. setDisableAutoFetch(delay = 5000) {
  465. if (isNaN(this.#percent)) {
  466. return;
  467. }
  468. if (this.#disableAutoFetchTimeout) {
  469. clearTimeout(this.#disableAutoFetchTimeout);
  470. }
  471. this.show();
  472. this.#disableAutoFetchTimeout = setTimeout(() => {
  473. this.#disableAutoFetchTimeout = null;
  474. this.hide();
  475. }, delay);
  476. }
  477. hide() {
  478. if (!this.#visible) {
  479. return;
  480. }
  481. this.#visible = false;
  482. this.#classList.add("hidden");
  483. }
  484. show() {
  485. if (this.#visible) {
  486. return;
  487. }
  488. this.#visible = true;
  489. this.#classList.remove("hidden");
  490. }
  491. }
  492. exports.ProgressBar = ProgressBar;
  493. function getActiveOrFocusedElement() {
  494. let curRoot = document;
  495. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  496. while (curActiveOrFocused?.shadowRoot) {
  497. curRoot = curActiveOrFocused.shadowRoot;
  498. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  499. }
  500. return curActiveOrFocused;
  501. }
  502. function apiPageLayoutToViewerModes(layout) {
  503. let scrollMode = ScrollMode.VERTICAL,
  504. spreadMode = SpreadMode.NONE;
  505. switch (layout) {
  506. case "SinglePage":
  507. scrollMode = ScrollMode.PAGE;
  508. break;
  509. case "OneColumn":
  510. break;
  511. case "TwoPageLeft":
  512. scrollMode = ScrollMode.PAGE;
  513. case "TwoColumnLeft":
  514. spreadMode = SpreadMode.ODD;
  515. break;
  516. case "TwoPageRight":
  517. scrollMode = ScrollMode.PAGE;
  518. case "TwoColumnRight":
  519. spreadMode = SpreadMode.EVEN;
  520. break;
  521. }
  522. return {
  523. scrollMode,
  524. spreadMode
  525. };
  526. }
  527. function apiPageModeToSidebarView(mode) {
  528. switch (mode) {
  529. case "UseNone":
  530. return SidebarView.NONE;
  531. case "UseThumbs":
  532. return SidebarView.THUMBS;
  533. case "UseOutlines":
  534. return SidebarView.OUTLINE;
  535. case "UseAttachments":
  536. return SidebarView.ATTACHMENTS;
  537. case "UseOC":
  538. return SidebarView.LAYERS;
  539. }
  540. return SidebarView.NONE;
  541. }
  542. /***/
  543. }),
  544. /* 2 */
  545. /***/ ((__unused_webpack_module, exports) => {
  546. Object.defineProperty(exports, "__esModule", ({
  547. value: true
  548. }));
  549. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  550. const compatibilityParams = Object.create(null);
  551. exports.compatibilityParams = compatibilityParams;
  552. {
  553. const userAgent = navigator.userAgent || "";
  554. const platform = navigator.platform || "";
  555. const maxTouchPoints = navigator.maxTouchPoints || 1;
  556. const isAndroid = /Android/.test(userAgent);
  557. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  558. (function checkCanvasSizeLimitation() {
  559. if (isIOS || isAndroid) {
  560. compatibilityParams.maxCanvasPixels = 5242880;
  561. }
  562. })();
  563. }
  564. const OptionKind = {
  565. VIEWER: 0x02,
  566. API: 0x04,
  567. WORKER: 0x08,
  568. PREFERENCE: 0x80
  569. };
  570. exports.OptionKind = OptionKind;
  571. const defaultOptions = {
  572. annotationEditorMode: {
  573. value: 0,
  574. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  575. },
  576. annotationMode: {
  577. value: 2,
  578. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  579. },
  580. cursorToolOnLoad: {
  581. value: 0,
  582. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  583. },
  584. defaultZoomDelay: {
  585. value: 400,
  586. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  587. },
  588. defaultZoomValue: {
  589. value: "",
  590. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  591. },
  592. disableHistory: {
  593. value: false,
  594. kind: OptionKind.VIEWER
  595. },
  596. disablePageLabels: {
  597. value: false,
  598. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  599. },
  600. enablePermissions: {
  601. value: false,
  602. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  603. },
  604. enablePrintAutoRotate: {
  605. value: true,
  606. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  607. },
  608. enableScripting: {
  609. value: true,
  610. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  611. },
  612. externalLinkRel: {
  613. value: "noopener noreferrer nofollow",
  614. kind: OptionKind.VIEWER
  615. },
  616. externalLinkTarget: {
  617. value: 0,
  618. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  619. },
  620. historyUpdateUrl: {
  621. value: false,
  622. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  623. },
  624. ignoreDestinationZoom: {
  625. value: false,
  626. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  627. },
  628. imageResourcesPath: {
  629. value: "./images/",
  630. kind: OptionKind.VIEWER
  631. },
  632. maxCanvasPixels: {
  633. value: 16777216,
  634. kind: OptionKind.VIEWER
  635. },
  636. forcePageColors: {
  637. value: false,
  638. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  639. },
  640. pageColorsBackground: {
  641. value: "Canvas",
  642. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  643. },
  644. pageColorsForeground: {
  645. value: "CanvasText",
  646. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  647. },
  648. pdfBugEnabled: {
  649. value: false,
  650. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  651. },
  652. printResolution: {
  653. value: 150,
  654. kind: OptionKind.VIEWER
  655. },
  656. sidebarViewOnLoad: {
  657. value: -1,
  658. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  659. },
  660. scrollModeOnLoad: {
  661. value: -1,
  662. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  663. },
  664. spreadModeOnLoad: {
  665. value: -1,
  666. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  667. },
  668. textLayerMode: {
  669. value: 1,
  670. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  671. },
  672. useOnlyCssZoom: {
  673. value: false,
  674. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  675. },
  676. viewerCssTheme: {
  677. value: 0,
  678. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  679. },
  680. viewOnLoad: {
  681. value: 0,
  682. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  683. },
  684. cMapPacked: {
  685. value: true,
  686. kind: OptionKind.API
  687. },
  688. cMapUrl: {
  689. value: "../web/cmaps/",
  690. kind: OptionKind.API
  691. },
  692. disableAutoFetch: {
  693. value: false,
  694. kind: OptionKind.API + OptionKind.PREFERENCE
  695. },
  696. disableFontFace: {
  697. value: false,
  698. kind: OptionKind.API + OptionKind.PREFERENCE
  699. },
  700. disableRange: {
  701. value: false,
  702. kind: OptionKind.API + OptionKind.PREFERENCE
  703. },
  704. disableStream: {
  705. value: false,
  706. kind: OptionKind.API + OptionKind.PREFERENCE
  707. },
  708. docBaseUrl: {
  709. value: "",
  710. kind: OptionKind.API
  711. },
  712. enableXfa: {
  713. value: true,
  714. kind: OptionKind.API + OptionKind.PREFERENCE
  715. },
  716. fontExtraProperties: {
  717. value: false,
  718. kind: OptionKind.API
  719. },
  720. isEvalSupported: {
  721. value: true,
  722. kind: OptionKind.API
  723. },
  724. isOffscreenCanvasSupported: {
  725. value: true,
  726. kind: OptionKind.API
  727. },
  728. maxImageSize: {
  729. value: -1,
  730. kind: OptionKind.API
  731. },
  732. pdfBug: {
  733. value: false,
  734. kind: OptionKind.API
  735. },
  736. standardFontDataUrl: {
  737. value: "../web/standard_fonts/",
  738. kind: OptionKind.API
  739. },
  740. verbosity: {
  741. value: 1,
  742. kind: OptionKind.API
  743. },
  744. workerPort: {
  745. value: null,
  746. kind: OptionKind.WORKER
  747. },
  748. workerSrc: {
  749. value: "../build/pdf.worker.js",
  750. kind: OptionKind.WORKER
  751. }
  752. };
  753. {
  754. defaultOptions.defaultUrl = {
  755. value: "compressed.tracemonkey-pldi-09.pdf",
  756. kind: OptionKind.VIEWER
  757. };
  758. defaultOptions.disablePreferences = {
  759. value: false,
  760. kind: OptionKind.VIEWER
  761. };
  762. defaultOptions.locale = {
  763. value: navigator.language || "en-US",
  764. kind: OptionKind.VIEWER
  765. };
  766. defaultOptions.renderer = {
  767. value: "canvas",
  768. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  769. };
  770. defaultOptions.sandboxBundleSrc = {
  771. value: "../build/pdf.sandbox.js",
  772. kind: OptionKind.VIEWER
  773. };
  774. }
  775. const userOptions = Object.create(null);
  776. class AppOptions {
  777. constructor() {
  778. throw new Error("Cannot initialize AppOptions.");
  779. }
  780. static get(name) {
  781. const userOption = userOptions[name];
  782. if (userOption !== undefined) {
  783. return userOption;
  784. }
  785. const defaultOption = defaultOptions[name];
  786. if (defaultOption !== undefined) {
  787. return compatibilityParams[name] ?? defaultOption.value;
  788. }
  789. return undefined;
  790. }
  791. static getAll(kind = null) {
  792. const options = Object.create(null);
  793. for (const name in defaultOptions) {
  794. const defaultOption = defaultOptions[name];
  795. if (kind) {
  796. if ((kind & defaultOption.kind) === 0) {
  797. continue;
  798. }
  799. if (kind === OptionKind.PREFERENCE) {
  800. const value = defaultOption.value,
  801. valueType = typeof value;
  802. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  803. options[name] = value;
  804. continue;
  805. }
  806. throw new Error(`Invalid type for preference: ${name}`);
  807. }
  808. }
  809. const userOption = userOptions[name];
  810. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  811. }
  812. return options;
  813. }
  814. static set(name, value) {
  815. userOptions[name] = value;
  816. }
  817. static setAll(options) {
  818. for (const name in options) {
  819. userOptions[name] = options[name];
  820. }
  821. }
  822. static remove(name) {
  823. delete userOptions[name];
  824. }
  825. static _hasUserOptions() {
  826. return Object.keys(userOptions).length > 0;
  827. }
  828. }
  829. exports.AppOptions = AppOptions;
  830. /***/
  831. }),
  832. /* 3 */
  833. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  834. Object.defineProperty(exports, "__esModule", ({
  835. value: true
  836. }));
  837. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  838. var _ui_utils = __webpack_require__(1);
  839. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  840. const LinkTarget = {
  841. NONE: 0,
  842. SELF: 1,
  843. BLANK: 2,
  844. PARENT: 3,
  845. TOP: 4
  846. };
  847. exports.LinkTarget = LinkTarget;
  848. function addLinkAttributes(link, {
  849. url,
  850. target,
  851. rel,
  852. enabled = true
  853. } = {}) {
  854. if (!url || typeof url !== "string") {
  855. throw new Error('A valid "url" parameter must provided.');
  856. }
  857. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  858. if (enabled) {
  859. link.href = link.title = urlNullRemoved;
  860. } else {
  861. link.href = "";
  862. link.title = `Disabled: ${urlNullRemoved}`;
  863. link.onclick = () => {
  864. return false;
  865. };
  866. }
  867. let targetStr = "";
  868. switch (target) {
  869. case LinkTarget.NONE:
  870. break;
  871. case LinkTarget.SELF:
  872. targetStr = "_self";
  873. break;
  874. case LinkTarget.BLANK:
  875. targetStr = "_blank";
  876. break;
  877. case LinkTarget.PARENT:
  878. targetStr = "_parent";
  879. break;
  880. case LinkTarget.TOP:
  881. targetStr = "_top";
  882. break;
  883. }
  884. link.target = targetStr;
  885. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  886. }
  887. class PDFLinkService {
  888. #pagesRefCache = new Map();
  889. constructor({
  890. eventBus,
  891. externalLinkTarget = null,
  892. externalLinkRel = null,
  893. ignoreDestinationZoom = false
  894. } = {}) {
  895. this.eventBus = eventBus;
  896. this.externalLinkTarget = externalLinkTarget;
  897. this.externalLinkRel = externalLinkRel;
  898. this.externalLinkEnabled = true;
  899. this._ignoreDestinationZoom = ignoreDestinationZoom;
  900. this.baseUrl = null;
  901. this.pdfDocument = null;
  902. this.pdfViewer = null;
  903. this.pdfHistory = null;
  904. }
  905. setDocument(pdfDocument, baseUrl = null) {
  906. this.baseUrl = baseUrl;
  907. this.pdfDocument = pdfDocument;
  908. this.#pagesRefCache.clear();
  909. }
  910. setViewer(pdfViewer) {
  911. this.pdfViewer = pdfViewer;
  912. }
  913. setHistory(pdfHistory) {
  914. this.pdfHistory = pdfHistory;
  915. }
  916. get pagesCount() {
  917. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  918. }
  919. get page() {
  920. return this.pdfViewer.currentPageNumber;
  921. }
  922. set page(value) {
  923. this.pdfViewer.currentPageNumber = value;
  924. }
  925. get rotation() {
  926. return this.pdfViewer.pagesRotation;
  927. }
  928. set rotation(value) {
  929. this.pdfViewer.pagesRotation = value;
  930. }
  931. get isInPresentationMode() {
  932. return this.pdfViewer.isInPresentationMode;
  933. }
  934. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  935. const destRef = explicitDest[0];
  936. let pageNumber;
  937. if (typeof destRef === "object" && destRef !== null) {
  938. pageNumber = this._cachedPageNumber(destRef);
  939. if (!pageNumber) {
  940. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  941. this.cachePageRef(pageIndex + 1, destRef);
  942. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  943. }).catch(() => {
  944. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  945. });
  946. return;
  947. }
  948. } else if (Number.isInteger(destRef)) {
  949. pageNumber = destRef + 1;
  950. } else {
  951. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  952. return;
  953. }
  954. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  955. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  956. return;
  957. }
  958. if (this.pdfHistory) {
  959. this.pdfHistory.pushCurrentPosition();
  960. this.pdfHistory.push({
  961. namedDest,
  962. explicitDest,
  963. pageNumber
  964. });
  965. }
  966. this.pdfViewer.scrollPageIntoView({
  967. pageNumber,
  968. destArray: explicitDest,
  969. ignoreDestinationZoom: this._ignoreDestinationZoom
  970. });
  971. }
  972. async goToDestination(dest) {
  973. if (!this.pdfDocument) {
  974. return;
  975. }
  976. let namedDest, explicitDest;
  977. if (typeof dest === "string") {
  978. namedDest = dest;
  979. explicitDest = await this.pdfDocument.getDestination(dest);
  980. } else {
  981. namedDest = null;
  982. explicitDest = await dest;
  983. }
  984. if (!Array.isArray(explicitDest)) {
  985. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  986. return;
  987. }
  988. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  989. }
  990. goToPage(val) {
  991. if (!this.pdfDocument) {
  992. return;
  993. }
  994. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  995. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  996. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  997. return;
  998. }
  999. if (this.pdfHistory) {
  1000. this.pdfHistory.pushCurrentPosition();
  1001. this.pdfHistory.pushPage(pageNumber);
  1002. }
  1003. this.pdfViewer.scrollPageIntoView({
  1004. pageNumber
  1005. });
  1006. }
  1007. addLinkAttributes(link, url, newWindow = false) {
  1008. addLinkAttributes(link, {
  1009. url,
  1010. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  1011. rel: this.externalLinkRel,
  1012. enabled: this.externalLinkEnabled
  1013. });
  1014. }
  1015. getDestinationHash(dest) {
  1016. if (typeof dest === "string") {
  1017. if (dest.length > 0) {
  1018. return this.getAnchorUrl("#" + escape(dest));
  1019. }
  1020. } else if (Array.isArray(dest)) {
  1021. const str = JSON.stringify(dest);
  1022. if (str.length > 0) {
  1023. return this.getAnchorUrl("#" + escape(str));
  1024. }
  1025. }
  1026. return this.getAnchorUrl("");
  1027. }
  1028. getAnchorUrl(anchor) {
  1029. return (this.baseUrl || "") + anchor;
  1030. }
  1031. setHash(hash) {
  1032. if (!this.pdfDocument) {
  1033. return;
  1034. }
  1035. let pageNumber, dest;
  1036. if (hash.includes("=")) {
  1037. const params = (0, _ui_utils.parseQueryString)(hash);
  1038. if (params.has("search")) {
  1039. this.eventBus.dispatch("findfromurlhash", {
  1040. source: this,
  1041. query: params.get("search").replace(/"/g, ""),
  1042. phraseSearch: params.get("phrase") === "true"
  1043. });
  1044. }
  1045. if (params.has("page")) {
  1046. pageNumber = params.get("page") | 0 || 1;
  1047. }
  1048. if (params.has("zoom")) {
  1049. const zoomArgs = params.get("zoom").split(",");
  1050. const zoomArg = zoomArgs[0];
  1051. const zoomArgNumber = parseFloat(zoomArg);
  1052. if (!zoomArg.includes("Fit")) {
  1053. dest = [null, {
  1054. name: "XYZ"
  1055. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  1056. } else {
  1057. if (zoomArg === "Fit" || zoomArg === "FitB") {
  1058. dest = [null, {
  1059. name: zoomArg
  1060. }];
  1061. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  1062. dest = [null, {
  1063. name: zoomArg
  1064. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  1065. } else if (zoomArg === "FitR") {
  1066. if (zoomArgs.length !== 5) {
  1067. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  1068. } else {
  1069. dest = [null, {
  1070. name: zoomArg
  1071. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  1072. }
  1073. } else {
  1074. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  1075. }
  1076. }
  1077. }
  1078. if (dest) {
  1079. this.pdfViewer.scrollPageIntoView({
  1080. pageNumber: pageNumber || this.page,
  1081. destArray: dest,
  1082. allowNegativeOffset: true
  1083. });
  1084. } else if (pageNumber) {
  1085. this.page = pageNumber;
  1086. }
  1087. if (params.has("pagemode")) {
  1088. this.eventBus.dispatch("pagemode", {
  1089. source: this,
  1090. mode: params.get("pagemode")
  1091. });
  1092. }
  1093. if (params.has("nameddest")) {
  1094. this.goToDestination(params.get("nameddest"));
  1095. }
  1096. } else {
  1097. dest = unescape(hash);
  1098. try {
  1099. dest = JSON.parse(dest);
  1100. if (!Array.isArray(dest)) {
  1101. dest = dest.toString();
  1102. }
  1103. } catch (ex) { }
  1104. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  1105. this.goToDestination(dest);
  1106. return;
  1107. }
  1108. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  1109. }
  1110. }
  1111. executeNamedAction(action) {
  1112. switch (action) {
  1113. case "GoBack":
  1114. this.pdfHistory?.back();
  1115. break;
  1116. case "GoForward":
  1117. this.pdfHistory?.forward();
  1118. break;
  1119. case "NextPage":
  1120. this.pdfViewer.nextPage();
  1121. break;
  1122. case "PrevPage":
  1123. this.pdfViewer.previousPage();
  1124. break;
  1125. case "LastPage":
  1126. this.page = this.pagesCount;
  1127. break;
  1128. case "FirstPage":
  1129. this.page = 1;
  1130. break;
  1131. default:
  1132. break;
  1133. }
  1134. this.eventBus.dispatch("namedaction", {
  1135. source: this,
  1136. action
  1137. });
  1138. }
  1139. async executeSetOCGState(action) {
  1140. const pdfDocument = this.pdfDocument;
  1141. const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  1142. if (pdfDocument !== this.pdfDocument) {
  1143. return;
  1144. }
  1145. let operator;
  1146. for (const elem of action.state) {
  1147. switch (elem) {
  1148. case "ON":
  1149. case "OFF":
  1150. case "Toggle":
  1151. operator = elem;
  1152. continue;
  1153. }
  1154. switch (operator) {
  1155. case "ON":
  1156. optionalContentConfig.setVisibility(elem, true);
  1157. break;
  1158. case "OFF":
  1159. optionalContentConfig.setVisibility(elem, false);
  1160. break;
  1161. case "Toggle":
  1162. const group = optionalContentConfig.getGroup(elem);
  1163. if (group) {
  1164. optionalContentConfig.setVisibility(elem, !group.visible);
  1165. }
  1166. break;
  1167. }
  1168. }
  1169. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  1170. }
  1171. cachePageRef(pageNum, pageRef) {
  1172. if (!pageRef) {
  1173. return;
  1174. }
  1175. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1176. this.#pagesRefCache.set(refStr, pageNum);
  1177. }
  1178. _cachedPageNumber(pageRef) {
  1179. if (!pageRef) {
  1180. return null;
  1181. }
  1182. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1183. return this.#pagesRefCache.get(refStr) || null;
  1184. }
  1185. isPageVisible(pageNumber) {
  1186. return this.pdfViewer.isPageVisible(pageNumber);
  1187. }
  1188. isPageCached(pageNumber) {
  1189. return this.pdfViewer.isPageCached(pageNumber);
  1190. }
  1191. static #isValidExplicitDestination(dest) {
  1192. if (!Array.isArray(dest)) {
  1193. return false;
  1194. }
  1195. const destLength = dest.length;
  1196. if (destLength < 2) {
  1197. return false;
  1198. }
  1199. const page = dest[0];
  1200. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  1201. return false;
  1202. }
  1203. const zoom = dest[1];
  1204. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  1205. return false;
  1206. }
  1207. let allowNull = true;
  1208. switch (zoom.name) {
  1209. case "XYZ":
  1210. if (destLength !== 5) {
  1211. return false;
  1212. }
  1213. break;
  1214. case "Fit":
  1215. case "FitB":
  1216. return destLength === 2;
  1217. case "FitH":
  1218. case "FitBH":
  1219. case "FitV":
  1220. case "FitBV":
  1221. if (destLength !== 3) {
  1222. return false;
  1223. }
  1224. break;
  1225. case "FitR":
  1226. if (destLength !== 6) {
  1227. return false;
  1228. }
  1229. allowNull = false;
  1230. break;
  1231. default:
  1232. return false;
  1233. }
  1234. for (let i = 2; i < destLength; i++) {
  1235. const param = dest[i];
  1236. if (!(typeof param === "number" || allowNull && param === null)) {
  1237. return false;
  1238. }
  1239. }
  1240. return true;
  1241. }
  1242. }
  1243. exports.PDFLinkService = PDFLinkService;
  1244. class SimpleLinkService {
  1245. constructor() {
  1246. this.externalLinkEnabled = true;
  1247. }
  1248. get pagesCount() {
  1249. return 0;
  1250. }
  1251. get page() {
  1252. return 0;
  1253. }
  1254. set page(value) { }
  1255. get rotation() {
  1256. return 0;
  1257. }
  1258. set rotation(value) { }
  1259. get isInPresentationMode() {
  1260. return false;
  1261. }
  1262. async goToDestination(dest) { }
  1263. goToPage(val) { }
  1264. addLinkAttributes(link, url, newWindow = false) {
  1265. addLinkAttributes(link, {
  1266. url,
  1267. enabled: this.externalLinkEnabled
  1268. });
  1269. }
  1270. getDestinationHash(dest) {
  1271. return "#";
  1272. }
  1273. getAnchorUrl(hash) {
  1274. return "#";
  1275. }
  1276. setHash(hash) { }
  1277. executeNamedAction(action) { }
  1278. executeSetOCGState(action) { }
  1279. cachePageRef(pageNum, pageRef) { }
  1280. isPageVisible(pageNumber) {
  1281. return true;
  1282. }
  1283. isPageCached(pageNumber) {
  1284. return true;
  1285. }
  1286. }
  1287. exports.SimpleLinkService = SimpleLinkService;
  1288. /***/
  1289. }),
  1290. /* 4 */
  1291. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1292. Object.defineProperty(exports, "__esModule", ({
  1293. value: true
  1294. }));
  1295. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  1296. var _ui_utils = __webpack_require__(1);
  1297. var _pdfjsLib = __webpack_require__(5);
  1298. var _app_options = __webpack_require__(2);
  1299. var _event_utils = __webpack_require__(6);
  1300. var _pdf_cursor_tools = __webpack_require__(7);
  1301. var _pdf_link_service = __webpack_require__(3);
  1302. var _annotation_editor_params = __webpack_require__(9);
  1303. var _overlay_manager = __webpack_require__(10);
  1304. var _password_prompt = __webpack_require__(11);
  1305. var _pdf_attachment_viewer = __webpack_require__(12);
  1306. var _pdf_document_properties = __webpack_require__(14);
  1307. var _pdf_find_bar = __webpack_require__(15);
  1308. var _pdf_find_controller = __webpack_require__(16);
  1309. var _pdf_history = __webpack_require__(18);
  1310. var _pdf_layer_viewer = __webpack_require__(19);
  1311. var _pdf_outline_viewer = __webpack_require__(20);
  1312. var _pdf_presentation_mode = __webpack_require__(21);
  1313. var _pdf_rendering_queue = __webpack_require__(22);
  1314. var _pdf_scripting_manager = __webpack_require__(23);
  1315. var _pdf_sidebar = __webpack_require__(24);
  1316. var _pdf_sidebar_resizer = __webpack_require__(25);
  1317. var _pdf_thumbnail_viewer = __webpack_require__(26);
  1318. var _pdf_viewer = __webpack_require__(28);
  1319. var _secondary_toolbar = __webpack_require__(38);
  1320. var _toolbar = __webpack_require__(39);
  1321. var _view_history = __webpack_require__(40);
  1322. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  1323. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  1324. const ViewOnLoad = {
  1325. UNKNOWN: -1,
  1326. PREVIOUS: 0,
  1327. INITIAL: 1
  1328. };
  1329. const ViewerCssTheme = {
  1330. AUTOMATIC: 0,
  1331. LIGHT: 1,
  1332. DARK: 2
  1333. };
  1334. class DefaultExternalServices {
  1335. constructor() {
  1336. throw new Error("Cannot initialize DefaultExternalServices.");
  1337. }
  1338. static updateFindControlState(data) { }
  1339. static updateFindMatchesCount(data) { }
  1340. static initPassiveLoading(callbacks) { }
  1341. static reportTelemetry(data) { }
  1342. static createDownloadManager() {
  1343. throw new Error("Not implemented: createDownloadManager");
  1344. }
  1345. static createPreferences() {
  1346. throw new Error("Not implemented: createPreferences");
  1347. }
  1348. static createL10n(options) {
  1349. throw new Error("Not implemented: createL10n");
  1350. }
  1351. static createScripting(options) {
  1352. throw new Error("Not implemented: createScripting");
  1353. }
  1354. static get supportsPinchToZoom() {
  1355. return (0, _pdfjsLib.shadow)(this, "supportsPinchToZoom", true);
  1356. }
  1357. static get supportsIntegratedFind() {
  1358. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  1359. }
  1360. static get supportsDocumentFonts() {
  1361. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  1362. }
  1363. static get supportedMouseWheelZoomModifierKeys() {
  1364. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  1365. ctrlKey: true,
  1366. metaKey: true
  1367. });
  1368. }
  1369. static get isInAutomation() {
  1370. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  1371. }
  1372. static updateEditorStates(data) {
  1373. throw new Error("Not implemented: updateEditorStates");
  1374. }
  1375. }
  1376. exports.DefaultExternalServices = DefaultExternalServices;
  1377. const PDFViewerApplication = {
  1378. initialBookmark: document.location.hash.substring(1),
  1379. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  1380. appConfig: null,
  1381. pdfDocument: null,
  1382. pdfLoadingTask: null,
  1383. printService: null,
  1384. pdfViewer: null,
  1385. pdfThumbnailViewer: null,
  1386. pdfRenderingQueue: null,
  1387. pdfPresentationMode: null,
  1388. pdfDocumentProperties: null,
  1389. pdfLinkService: null,
  1390. pdfHistory: null,
  1391. pdfSidebar: null,
  1392. pdfSidebarResizer: null,
  1393. pdfOutlineViewer: null,
  1394. pdfAttachmentViewer: null,
  1395. pdfLayerViewer: null,
  1396. pdfCursorTools: null,
  1397. pdfScriptingManager: null,
  1398. store: null,
  1399. downloadManager: null,
  1400. overlayManager: null,
  1401. preferences: null,
  1402. toolbar: null,
  1403. secondaryToolbar: null,
  1404. eventBus: null,
  1405. l10n: null,
  1406. annotationEditorParams: null,
  1407. isInitialViewSet: false,
  1408. downloadComplete: false,
  1409. isViewerEmbedded: window.parent !== window,
  1410. url: "",
  1411. baseUrl: "",
  1412. _downloadUrl: "",
  1413. externalServices: DefaultExternalServices,
  1414. _boundEvents: Object.create(null),
  1415. documentInfo: null,
  1416. metadata: null,
  1417. _contentDispositionFilename: null,
  1418. _contentLength: null,
  1419. _saveInProgress: false,
  1420. _wheelUnusedTicks: 0,
  1421. _wheelUnusedFactor: 1,
  1422. _touchUnusedTicks: 0,
  1423. _touchUnusedFactor: 1,
  1424. _PDFBug: null,
  1425. _hasAnnotationEditors: false,
  1426. _title: document.title,
  1427. _printAnnotationStoragePromise: null,
  1428. _touchInfo: null,
  1429. _isCtrlKeyDown: false,
  1430. async initialize(appConfig) {
  1431. this.preferences = this.externalServices.createPreferences();
  1432. this.appConfig = appConfig;
  1433. await this._readPreferences();
  1434. await this._parseHashParameters();
  1435. this._forceCssTheme();
  1436. await this._initializeL10n();
  1437. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  1438. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  1439. }
  1440. await this._initializeViewerComponents();
  1441. this.bindEvents();
  1442. this.bindWindowEvents();
  1443. const appContainer = appConfig.appContainer || document.documentElement;
  1444. this.l10n.translate(appContainer).then(() => {
  1445. this.eventBus.dispatch("localized", {
  1446. source: this
  1447. });
  1448. });
  1449. this._initializedCapability.resolve();
  1450. },
  1451. async _readPreferences() {
  1452. if (_app_options.AppOptions.get("disablePreferences")) {
  1453. return;
  1454. }
  1455. if (_app_options.AppOptions._hasUserOptions()) {
  1456. console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  1457. }
  1458. try {
  1459. _app_options.AppOptions.setAll(await this.preferences.getAll());
  1460. } catch (reason) {
  1461. console.error(`_readPreferences: "${reason?.message}".`);
  1462. }
  1463. },
  1464. async _parseHashParameters() {
  1465. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  1466. //return;
  1467. }
  1468. var hash = document.location.hash.substring(1);
  1469. if (!hash) {
  1470. return;
  1471. }
  1472. const {
  1473. mainContainer,
  1474. viewerContainer
  1475. } = this.appConfig,
  1476. params = (0, _ui_utils.parseQueryString)(hash);
  1477. if (params.get("disableworker") === "true") {
  1478. try {
  1479. await loadFakeWorker();
  1480. } catch (ex) {
  1481. console.error(`_parseHashParameters: "${ex.message}".`);
  1482. }
  1483. }
  1484. if (params.has("disablerange")) {
  1485. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  1486. }
  1487. if (params.has("disablestream")) {
  1488. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  1489. }
  1490. if (params.has("disableautofetch")) {
  1491. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  1492. }
  1493. if (params.has("disablefontface")) {
  1494. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  1495. }
  1496. if (params.has("disablehistory")) {
  1497. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  1498. }
  1499. if (params.has("verbosity")) {
  1500. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  1501. }
  1502. if (params.has("textlayer")) {
  1503. switch (params.get("textlayer")) {
  1504. case "off":
  1505. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  1506. break;
  1507. case "visible":
  1508. case "shadow":
  1509. case "hover":
  1510. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  1511. try {
  1512. await loadPDFBug(this);
  1513. this._PDFBug.loadCSS();
  1514. } catch (ex) {
  1515. console.error(`_parseHashParameters: "${ex.message}".`);
  1516. }
  1517. break;
  1518. }
  1519. }
  1520. if (params.has("pdfbug")) {
  1521. _app_options.AppOptions.set("pdfBug", true);
  1522. _app_options.AppOptions.set("fontExtraProperties", true);
  1523. const enabled = params.get("pdfbug").split(",");
  1524. try {
  1525. await loadPDFBug(this);
  1526. this._PDFBug.init({
  1527. OPS: _pdfjsLib.OPS
  1528. }, mainContainer, enabled);
  1529. } catch (ex) {
  1530. console.error(`_parseHashParameters: "${ex.message}".`);
  1531. }
  1532. }
  1533. if (params.has("locale")) {
  1534. _app_options.AppOptions.set("locale", params.get("locale"));
  1535. }
  1536. var locale = new URLSearchParams(window.location.search).get("locale")
  1537. if (locale) {
  1538. _app_options.AppOptions.set("locale", locale);
  1539. }
  1540. },
  1541. async _initializeL10n() {
  1542. /*
  1543. this.l10n = this.externalServices.createL10n({
  1544. locale: _app_options.AppOptions.get("locale")
  1545. });
  1546. const dir = await this.l10n.getDirection();
  1547. document.getElementsByTagName("html")[0].dir = dir;
  1548. */
  1549. var hash = new URLSearchParams(window.location.search).get("locale");
  1550. this.l10n = this.externalServices.createL10n({
  1551. locale: hash || _app_options.AppOptions.get("locale")
  1552. });
  1553. const dir = await this.l10n.getDirection();
  1554. document.getElementsByTagName("html")[0].dir = dir;
  1555. },
  1556. _forceCssTheme() {
  1557. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  1558. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  1559. return;
  1560. }
  1561. try {
  1562. const styleSheet = document.styleSheets[0];
  1563. const cssRules = styleSheet?.cssRules || [];
  1564. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  1565. const rule = cssRules[i];
  1566. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  1567. if (cssTheme === ViewerCssTheme.LIGHT) {
  1568. styleSheet.deleteRule(i);
  1569. return;
  1570. }
  1571. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  1572. if (darkRules?.[1]) {
  1573. styleSheet.deleteRule(i);
  1574. styleSheet.insertRule(darkRules[1], i);
  1575. }
  1576. return;
  1577. }
  1578. }
  1579. } catch (reason) {
  1580. console.error(`_forceCssTheme: "${reason?.message}".`);
  1581. }
  1582. },
  1583. async _initializeViewerComponents() {
  1584. const {
  1585. appConfig,
  1586. externalServices
  1587. } = this;
  1588. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  1589. this.eventBus = eventBus;
  1590. this.overlayManager = new _overlay_manager.OverlayManager();
  1591. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  1592. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  1593. this.pdfRenderingQueue = pdfRenderingQueue;
  1594. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  1595. eventBus,
  1596. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  1597. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  1598. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  1599. });
  1600. this.pdfLinkService = pdfLinkService;
  1601. const downloadManager = externalServices.createDownloadManager();
  1602. this.downloadManager = downloadManager;
  1603. const findController = new _pdf_find_controller.PDFFindController({
  1604. linkService: pdfLinkService,
  1605. eventBus,
  1606. updateMatchesCountOnProgress: true
  1607. });
  1608. this.findController = findController;
  1609. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  1610. eventBus,
  1611. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  1612. scriptingFactory: externalServices,
  1613. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  1614. });
  1615. this.pdfScriptingManager = pdfScriptingManager;
  1616. const container = appConfig.mainContainer,
  1617. viewer = appConfig.viewerContainer;
  1618. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  1619. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  1620. background: _app_options.AppOptions.get("pageColorsBackground"),
  1621. foreground: _app_options.AppOptions.get("pageColorsForeground")
  1622. } : null;
  1623. this.pdfViewer = new _pdf_viewer.PDFViewer({
  1624. container,
  1625. viewer,
  1626. eventBus,
  1627. renderingQueue: pdfRenderingQueue,
  1628. linkService: pdfLinkService,
  1629. downloadManager,
  1630. findController,
  1631. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  1632. renderer: _app_options.AppOptions.get("renderer"),
  1633. l10n: this.l10n,
  1634. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  1635. annotationMode: _app_options.AppOptions.get("annotationMode"),
  1636. annotationEditorMode,
  1637. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  1638. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  1639. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  1640. isOffscreenCanvasSupported: _app_options.AppOptions.get("isOffscreenCanvasSupported"),
  1641. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  1642. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  1643. pageColors
  1644. });
  1645. pdfRenderingQueue.setViewer(this.pdfViewer);
  1646. pdfLinkService.setViewer(this.pdfViewer);
  1647. pdfScriptingManager.setViewer(this.pdfViewer);
  1648. if (appConfig.sidebar?.thumbnailView) {
  1649. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  1650. container: appConfig.sidebar.thumbnailView,
  1651. eventBus,
  1652. renderingQueue: pdfRenderingQueue,
  1653. linkService: pdfLinkService,
  1654. l10n: this.l10n,
  1655. pageColors
  1656. });
  1657. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  1658. }
  1659. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  1660. this.pdfHistory = new _pdf_history.PDFHistory({
  1661. linkService: pdfLinkService,
  1662. eventBus
  1663. });
  1664. pdfLinkService.setHistory(this.pdfHistory);
  1665. }
  1666. if (!this.supportsIntegratedFind && appConfig.findBar) {
  1667. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  1668. }
  1669. if (appConfig.annotationEditorParams) {
  1670. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  1671. this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  1672. } else {
  1673. for (const id of ["editorModeButtons", "editorModeSeparator"]) {
  1674. document.getElementById(id)?.classList.add("hidden");
  1675. }
  1676. }
  1677. }
  1678. if (appConfig.documentProperties) {
  1679. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
  1680. return this._docFilename;
  1681. });
  1682. }
  1683. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  1684. container,
  1685. eventBus,
  1686. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  1687. });
  1688. if (appConfig.toolbar) {
  1689. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  1690. }
  1691. if (appConfig.secondaryToolbar) {
  1692. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, this.externalServices);
  1693. }
  1694. if (this.supportsFullscreen) {
  1695. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  1696. container,
  1697. pdfViewer: this.pdfViewer,
  1698. eventBus
  1699. });
  1700. }
  1701. if (appConfig.passwordOverlay) {
  1702. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  1703. }
  1704. if (appConfig.sidebar?.outlineView) {
  1705. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  1706. container: appConfig.sidebar.outlineView,
  1707. eventBus,
  1708. linkService: pdfLinkService,
  1709. downloadManager
  1710. });
  1711. }
  1712. if (appConfig.sidebar?.attachmentsView) {
  1713. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  1714. container: appConfig.sidebar.attachmentsView,
  1715. eventBus,
  1716. downloadManager
  1717. });
  1718. }
  1719. if (appConfig.sidebar?.layersView) {
  1720. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  1721. container: appConfig.sidebar.layersView,
  1722. eventBus,
  1723. l10n: this.l10n
  1724. });
  1725. }
  1726. if (appConfig.sidebar) {
  1727. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  1728. elements: appConfig.sidebar,
  1729. pdfViewer: this.pdfViewer,
  1730. pdfThumbnailViewer: this.pdfThumbnailViewer,
  1731. eventBus,
  1732. l10n: this.l10n
  1733. });
  1734. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  1735. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  1736. }
  1737. },
  1738. run(config) {
  1739. this.initialize(config).then(webViewerInitialized);
  1740. },
  1741. get initialized() {
  1742. return this._initializedCapability.settled;
  1743. },
  1744. get initializedPromise() {
  1745. return this._initializedCapability.promise;
  1746. },
  1747. zoomIn(steps, scaleFactor) {
  1748. if (this.pdfViewer.isInPresentationMode) {
  1749. return;
  1750. }
  1751. this.pdfViewer.increaseScale({
  1752. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  1753. steps,
  1754. scaleFactor
  1755. });
  1756. },
  1757. zoomOut(steps, scaleFactor) {
  1758. if (this.pdfViewer.isInPresentationMode) {
  1759. return;
  1760. }
  1761. this.pdfViewer.decreaseScale({
  1762. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  1763. steps,
  1764. scaleFactor
  1765. });
  1766. },
  1767. zoomReset() {
  1768. if (this.pdfViewer.isInPresentationMode) {
  1769. return;
  1770. }
  1771. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1772. },
  1773. get pagesCount() {
  1774. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  1775. },
  1776. get page() {
  1777. return this.pdfViewer.currentPageNumber;
  1778. },
  1779. set page(val) {
  1780. this.pdfViewer.currentPageNumber = val;
  1781. },
  1782. get supportsPrinting() {
  1783. return PDFPrintServiceFactory.instance.supportsPrinting;
  1784. },
  1785. get supportsFullscreen() {
  1786. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  1787. },
  1788. get supportsPinchToZoom() {
  1789. return this.externalServices.supportsPinchToZoom;
  1790. },
  1791. get supportsIntegratedFind() {
  1792. return this.externalServices.supportsIntegratedFind;
  1793. },
  1794. get supportsDocumentFonts() {
  1795. return this.externalServices.supportsDocumentFonts;
  1796. },
  1797. get loadingBar() {
  1798. const barElement = document.getElementById("loadingBar");
  1799. const bar = barElement ? new _ui_utils.ProgressBar(barElement) : null;
  1800. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  1801. },
  1802. get supportedMouseWheelZoomModifierKeys() {
  1803. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  1804. },
  1805. initPassiveLoading() {
  1806. throw new Error("Not implemented: initPassiveLoading");
  1807. },
  1808. setTitleUsingUrl(url = "", downloadUrl = null) {
  1809. this.url = url;
  1810. this.baseUrl = url.split("#")[0];
  1811. if (downloadUrl) {
  1812. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  1813. }
  1814. if ((0, _pdfjsLib.isDataScheme)(url)) {
  1815. this._hideViewBookmark();
  1816. }
  1817. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  1818. if (!title) {
  1819. try {
  1820. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  1821. } catch (ex) {
  1822. title = url;
  1823. }
  1824. }
  1825. this.setTitle(title);
  1826. },
  1827. setTitle(title = this._title) {
  1828. this._title = title;
  1829. if (this.isViewerEmbedded) {
  1830. return;
  1831. }
  1832. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  1833. document.title = `${editorIndicator ? "* " : ""}${title}`;
  1834. },
  1835. get _docFilename() {
  1836. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  1837. },
  1838. _hideViewBookmark() {
  1839. const {
  1840. secondaryToolbar
  1841. } = this.appConfig;
  1842. secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
  1843. if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) {
  1844. document.getElementById("viewBookmarkSeparator")?.classList.add("hidden");
  1845. }
  1846. },
  1847. async close() {
  1848. this._unblockDocumentLoadEvent();
  1849. this._hideViewBookmark();
  1850. if (!this.pdfLoadingTask) {
  1851. return;
  1852. }
  1853. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  1854. try {
  1855. await this.save();
  1856. } catch (reason) { }
  1857. }
  1858. const promises = [];
  1859. promises.push(this.pdfLoadingTask.destroy());
  1860. this.pdfLoadingTask = null;
  1861. if (this.pdfDocument) {
  1862. this.pdfDocument = null;
  1863. this.pdfThumbnailViewer?.setDocument(null);
  1864. this.pdfViewer.setDocument(null);
  1865. this.pdfLinkService.setDocument(null);
  1866. this.pdfDocumentProperties?.setDocument(null);
  1867. }
  1868. this.pdfLinkService.externalLinkEnabled = true;
  1869. this.store = null;
  1870. this.isInitialViewSet = false;
  1871. this.downloadComplete = false;
  1872. this.url = "";
  1873. this.baseUrl = "";
  1874. this._downloadUrl = "";
  1875. this.documentInfo = null;
  1876. this.metadata = null;
  1877. this._contentDispositionFilename = null;
  1878. this._contentLength = null;
  1879. this._saveInProgress = false;
  1880. this._hasAnnotationEditors = false;
  1881. promises.push(this.pdfScriptingManager.destroyPromise);
  1882. this.setTitle();
  1883. this.pdfSidebar?.reset();
  1884. this.pdfOutlineViewer?.reset();
  1885. this.pdfAttachmentViewer?.reset();
  1886. this.pdfLayerViewer?.reset();
  1887. this.pdfHistory?.reset();
  1888. this.findBar?.reset();
  1889. this.toolbar?.reset();
  1890. this.secondaryToolbar?.reset();
  1891. this._PDFBug?.cleanup();
  1892. await Promise.all(promises);
  1893. },
  1894. async open(args) {
  1895. let deprecatedArgs = false;
  1896. if (typeof args === "string") {
  1897. args = {
  1898. url: args
  1899. };
  1900. deprecatedArgs = true;
  1901. } else if (args?.byteLength) {
  1902. args = {
  1903. data: args
  1904. };
  1905. deprecatedArgs = true;
  1906. }
  1907. if (deprecatedArgs) {
  1908. console.error("The `PDFViewerApplication.open` signature was updated, please use an object instead.");
  1909. }
  1910. if (this.pdfLoadingTask) {
  1911. await this.close();
  1912. }
  1913. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  1914. for (const key in workerParameters) {
  1915. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  1916. }
  1917. const parameters = Object.create(null);
  1918. if (args.url) {
  1919. if (args.originalUrl) {
  1920. this.setTitleUsingUrl(args.originalUrl, args.url);
  1921. delete args.originalUrl;
  1922. } else {
  1923. this.setTitleUsingUrl(args.url, args.url);
  1924. }
  1925. }
  1926. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  1927. for (const key in apiParameters) {
  1928. let value = apiParameters[key];
  1929. if (key === "docBaseUrl") { }
  1930. parameters[key] = value;
  1931. }
  1932. for (const key in args) {
  1933. parameters[key] = args[key];
  1934. }
  1935. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  1936. this.pdfLoadingTask = loadingTask;
  1937. loadingTask.onPassword = (updateCallback, reason) => {
  1938. if (this.isViewerEmbedded) {
  1939. this._unblockDocumentLoadEvent();
  1940. }
  1941. this.pdfLinkService.externalLinkEnabled = false;
  1942. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  1943. this.passwordPrompt.open();
  1944. };
  1945. loadingTask.onProgress = ({
  1946. loaded,
  1947. total
  1948. }) => {
  1949. this.progress(loaded / total);
  1950. };
  1951. return loadingTask.promise.then(pdfDocument => {
  1952. this.load(pdfDocument);
  1953. }, reason => {
  1954. if (loadingTask !== this.pdfLoadingTask) {
  1955. return undefined;
  1956. }
  1957. let key = "loading_error";
  1958. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  1959. key = "invalid_file_error";
  1960. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  1961. key = "missing_file_error";
  1962. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  1963. key = "unexpected_response_error";
  1964. }
  1965. return this.l10n.get(key).then(msg => {
  1966. this._documentError(msg, {
  1967. message: reason?.message
  1968. });
  1969. throw reason;
  1970. });
  1971. });
  1972. },
  1973. _ensureDownloadComplete() {
  1974. if (this.pdfDocument && this.downloadComplete) {
  1975. return;
  1976. }
  1977. throw new Error("PDF document not downloaded.");
  1978. },
  1979. async download() {
  1980. const url = this._downloadUrl,
  1981. filename = this._docFilename;
  1982. try {
  1983. this._ensureDownloadComplete();
  1984. const data = await this.pdfDocument.getData();
  1985. const blob = new Blob([data], {
  1986. type: "application/pdf"
  1987. });
  1988. await this.downloadManager.download(blob, url, filename);
  1989. } catch (reason) {
  1990. await this.downloadManager.downloadUrl(url, filename);
  1991. }
  1992. },
  1993. async save() {
  1994. if (this._saveInProgress) {
  1995. return;
  1996. }
  1997. this._saveInProgress = true;
  1998. await this.pdfScriptingManager.dispatchWillSave();
  1999. const url = this._downloadUrl,
  2000. filename = this._docFilename;
  2001. try {
  2002. this._ensureDownloadComplete();
  2003. const data = await this.pdfDocument.saveDocument();
  2004. const blob = new Blob([data], {
  2005. type: "application/pdf"
  2006. });
  2007. await this.downloadManager.download(blob, url, filename);
  2008. } catch (reason) {
  2009. console.error(`Error when saving the document: ${reason.message}`);
  2010. await this.download();
  2011. } finally {
  2012. await this.pdfScriptingManager.dispatchDidSave();
  2013. this._saveInProgress = false;
  2014. }
  2015. if (this._hasAnnotationEditors) {
  2016. this.externalServices.reportTelemetry({
  2017. type: "editing",
  2018. data: {
  2019. type: "save"
  2020. }
  2021. });
  2022. }
  2023. },
  2024. downloadOrSave() {
  2025. if (this.pdfDocument?.annotationStorage.size > 0) {
  2026. this.save();
  2027. } else {
  2028. this.download();
  2029. }
  2030. },
  2031. _documentError(message, moreInfo = null) {
  2032. this._unblockDocumentLoadEvent();
  2033. this._otherError(message, moreInfo);
  2034. this.eventBus.dispatch("documenterror", {
  2035. source: this,
  2036. message,
  2037. reason: moreInfo?.message ?? null
  2038. });
  2039. },
  2040. _otherError(message, moreInfo = null) {
  2041. const moreInfoText = [`PDF.js v${_pdfjsLib.version || "?"} (build: ${_pdfjsLib.build || "?"})`];
  2042. if (moreInfo) {
  2043. moreInfoText.push(`Message: ${moreInfo.message}`);
  2044. if (moreInfo.stack) {
  2045. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  2046. } else {
  2047. if (moreInfo.filename) {
  2048. moreInfoText.push(`File: ${moreInfo.filename}`);
  2049. }
  2050. if (moreInfo.lineNumber) {
  2051. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  2052. }
  2053. }
  2054. }
  2055. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  2056. },
  2057. progress(level) {
  2058. if (!this.loadingBar || this.downloadComplete) {
  2059. return;
  2060. }
  2061. const percent = Math.round(level * 100);
  2062. if (percent <= this.loadingBar.percent) {
  2063. return;
  2064. }
  2065. this.loadingBar.percent = percent;
  2066. if (this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch")) {
  2067. this.loadingBar.setDisableAutoFetch();
  2068. }
  2069. },
  2070. load(pdfDocument) {
  2071. this.pdfDocument = pdfDocument;
  2072. pdfDocument.getDownloadInfo().then(({
  2073. length
  2074. }) => {
  2075. this._contentLength = length;
  2076. this.downloadComplete = true;
  2077. this.loadingBar?.hide();
  2078. firstPagePromise.then(() => {
  2079. this.eventBus.dispatch("documentloaded", {
  2080. source: this
  2081. });
  2082. });
  2083. });
  2084. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () { });
  2085. const pageModePromise = pdfDocument.getPageMode().catch(function () { });
  2086. const openActionPromise = pdfDocument.getOpenAction().catch(function () { });
  2087. this.toolbar?.setPagesCount(pdfDocument.numPages, false);
  2088. this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
  2089. let baseDocumentUrl;
  2090. baseDocumentUrl = null;
  2091. if (baseDocumentUrl && (0, _pdfjsLib.isDataScheme)(baseDocumentUrl)) {
  2092. baseDocumentUrl = null;
  2093. }
  2094. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  2095. this.pdfDocumentProperties?.setDocument(pdfDocument);
  2096. const pdfViewer = this.pdfViewer;
  2097. pdfViewer.setDocument(pdfDocument);
  2098. const {
  2099. firstPagePromise,
  2100. onePageRendered,
  2101. pagesPromise
  2102. } = pdfViewer;
  2103. this.pdfThumbnailViewer?.setDocument(pdfDocument);
  2104. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  2105. page: null,
  2106. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  2107. scrollLeft: "0",
  2108. scrollTop: "0",
  2109. rotation: null,
  2110. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  2111. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  2112. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  2113. }).catch(() => {
  2114. return Object.create(null);
  2115. });
  2116. firstPagePromise.then(pdfPage => {
  2117. this.loadingBar?.setWidth(this.appConfig.viewerContainer);
  2118. this._initializeAnnotationStorageCallbacks(pdfDocument);
  2119. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  2120. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  2121. this._initializePdfHistory({
  2122. fingerprint: pdfDocument.fingerprints[0],
  2123. viewOnLoad,
  2124. initialDest: openAction?.dest
  2125. });
  2126. const initialBookmark = this.initialBookmark;
  2127. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  2128. let hash = zoom ? `zoom=${zoom}` : null;
  2129. let rotation = null;
  2130. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  2131. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  2132. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  2133. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  2134. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  2135. rotation = parseInt(stored.rotation, 10);
  2136. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2137. sidebarView = stored.sidebarView | 0;
  2138. }
  2139. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  2140. scrollMode = stored.scrollMode | 0;
  2141. }
  2142. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2143. spreadMode = stored.spreadMode | 0;
  2144. }
  2145. }
  2146. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2147. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  2148. }
  2149. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2150. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  2151. spreadMode = modes.spreadMode;
  2152. }
  2153. this.setInitialView(hash, {
  2154. rotation,
  2155. sidebarView,
  2156. scrollMode,
  2157. spreadMode
  2158. });
  2159. this.eventBus.dispatch("documentinit", {
  2160. source: this
  2161. });
  2162. if (!this.isViewerEmbedded) {
  2163. pdfViewer.focus();
  2164. }
  2165. await Promise.race([pagesPromise, new Promise(resolve => {
  2166. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  2167. })]);
  2168. if (!initialBookmark && !hash) {
  2169. return;
  2170. }
  2171. if (pdfViewer.hasEqualPageSizes) {
  2172. return;
  2173. }
  2174. this.initialBookmark = initialBookmark;
  2175. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  2176. this.setInitialView(hash);
  2177. }).catch(() => {
  2178. this.setInitialView();
  2179. }).then(function () {
  2180. pdfViewer.update();
  2181. });
  2182. });
  2183. pagesPromise.then(() => {
  2184. this._unblockDocumentLoadEvent();
  2185. this._initializeAutoPrint(pdfDocument, openActionPromise);
  2186. }, reason => {
  2187. this.l10n.get("loading_error").then(msg => {
  2188. this._documentError(msg, {
  2189. message: reason?.message
  2190. });
  2191. });
  2192. });
  2193. onePageRendered.then(data => {
  2194. this.externalServices.reportTelemetry({
  2195. type: "pageInfo",
  2196. timestamp: data.timestamp
  2197. });
  2198. pdfDocument.getOutline().then(outline => {
  2199. if (pdfDocument !== this.pdfDocument) {
  2200. return;
  2201. }
  2202. this.pdfOutlineViewer?.render({
  2203. outline,
  2204. pdfDocument
  2205. });
  2206. });
  2207. pdfDocument.getAttachments().then(attachments => {
  2208. if (pdfDocument !== this.pdfDocument) {
  2209. return;
  2210. }
  2211. this.pdfAttachmentViewer?.render({
  2212. attachments
  2213. });
  2214. });
  2215. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  2216. if (pdfDocument !== this.pdfDocument) {
  2217. return;
  2218. }
  2219. this.pdfLayerViewer?.render({
  2220. optionalContentConfig,
  2221. pdfDocument
  2222. });
  2223. });
  2224. });
  2225. this._initializePageLabels(pdfDocument);
  2226. this._initializeMetadata(pdfDocument);
  2227. },
  2228. async _scriptingDocProperties(pdfDocument) {
  2229. if (!this.documentInfo) {
  2230. await new Promise(resolve => {
  2231. this.eventBus._on("metadataloaded", resolve, {
  2232. once: true
  2233. });
  2234. });
  2235. if (pdfDocument !== this.pdfDocument) {
  2236. return null;
  2237. }
  2238. }
  2239. if (!this._contentLength) {
  2240. await new Promise(resolve => {
  2241. this.eventBus._on("documentloaded", resolve, {
  2242. once: true
  2243. });
  2244. });
  2245. if (pdfDocument !== this.pdfDocument) {
  2246. return null;
  2247. }
  2248. }
  2249. return {
  2250. ...this.documentInfo,
  2251. baseURL: this.baseUrl,
  2252. filesize: this._contentLength,
  2253. filename: this._docFilename,
  2254. metadata: this.metadata?.getRaw(),
  2255. authors: this.metadata?.get("dc:creator"),
  2256. numPages: this.pagesCount,
  2257. URL: this.url
  2258. };
  2259. },
  2260. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  2261. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  2262. if (pdfDocument !== this.pdfDocument) {
  2263. return;
  2264. }
  2265. let triggerAutoPrint = false;
  2266. if (openAction?.action === "Print") {
  2267. triggerAutoPrint = true;
  2268. }
  2269. if (javaScript) {
  2270. javaScript.some(js => {
  2271. if (!js) {
  2272. return false;
  2273. }
  2274. console.warn("Warning: JavaScript support is not enabled");
  2275. return true;
  2276. });
  2277. if (!triggerAutoPrint) {
  2278. for (const js of javaScript) {
  2279. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  2280. triggerAutoPrint = true;
  2281. break;
  2282. }
  2283. }
  2284. }
  2285. }
  2286. if (triggerAutoPrint) {
  2287. this.triggerPrinting();
  2288. }
  2289. },
  2290. async _initializeMetadata(pdfDocument) {
  2291. const {
  2292. info,
  2293. metadata,
  2294. contentDispositionFilename,
  2295. contentLength
  2296. } = await pdfDocument.getMetadata();
  2297. if (pdfDocument !== this.pdfDocument) {
  2298. return;
  2299. }
  2300. this.documentInfo = info;
  2301. this.metadata = metadata;
  2302. this._contentDispositionFilename ??= contentDispositionFilename;
  2303. this._contentLength ??= contentLength;
  2304. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`);
  2305. let pdfTitle = info.Title;
  2306. const metadataTitle = metadata?.get("dc:title");
  2307. if (metadataTitle) {
  2308. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  2309. pdfTitle = metadataTitle;
  2310. }
  2311. }
  2312. if (pdfTitle) {
  2313. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  2314. } else if (this._contentDispositionFilename) {
  2315. this.setTitle(this._contentDispositionFilename);
  2316. }
  2317. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  2318. if (pdfDocument.loadingParams.enableXfa) {
  2319. console.warn("Warning: XFA Foreground documents are not supported");
  2320. } else {
  2321. console.warn("Warning: XFA support is not enabled");
  2322. }
  2323. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  2324. console.warn("Warning: Interactive form support is not enabled");
  2325. }
  2326. if (info.IsSignaturesPresent) {
  2327. console.warn("Warning: Digital signatures validation is not supported");
  2328. }
  2329. this.eventBus.dispatch("metadataloaded", {
  2330. source: this
  2331. });
  2332. },
  2333. async _initializePageLabels(pdfDocument) {
  2334. const labels = await pdfDocument.getPageLabels();
  2335. if (pdfDocument !== this.pdfDocument) {
  2336. return;
  2337. }
  2338. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  2339. return;
  2340. }
  2341. const numLabels = labels.length;
  2342. let standardLabels = 0,
  2343. emptyLabels = 0;
  2344. for (let i = 0; i < numLabels; i++) {
  2345. const label = labels[i];
  2346. if (label === (i + 1).toString()) {
  2347. standardLabels++;
  2348. } else if (label === "") {
  2349. emptyLabels++;
  2350. } else {
  2351. break;
  2352. }
  2353. }
  2354. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  2355. return;
  2356. }
  2357. const {
  2358. pdfViewer,
  2359. pdfThumbnailViewer,
  2360. toolbar
  2361. } = this;
  2362. pdfViewer.setPageLabels(labels);
  2363. pdfThumbnailViewer?.setPageLabels(labels);
  2364. toolbar?.setPagesCount(numLabels, true);
  2365. toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2366. },
  2367. _initializePdfHistory({
  2368. fingerprint,
  2369. viewOnLoad,
  2370. initialDest = null
  2371. }) {
  2372. if (!this.pdfHistory) {
  2373. return;
  2374. }
  2375. this.pdfHistory.initialize({
  2376. fingerprint,
  2377. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  2378. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  2379. });
  2380. if (this.pdfHistory.initialBookmark) {
  2381. this.initialBookmark = this.pdfHistory.initialBookmark;
  2382. this.initialRotation = this.pdfHistory.initialRotation;
  2383. }
  2384. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  2385. this.initialBookmark = JSON.stringify(initialDest);
  2386. this.pdfHistory.push({
  2387. explicitDest: initialDest,
  2388. pageNumber: null
  2389. });
  2390. }
  2391. },
  2392. _initializeAnnotationStorageCallbacks(pdfDocument) {
  2393. if (pdfDocument !== this.pdfDocument) {
  2394. return;
  2395. }
  2396. const {
  2397. annotationStorage
  2398. } = pdfDocument;
  2399. annotationStorage.onSetModified = () => {
  2400. window.addEventListener("beforeunload", beforeUnload);
  2401. this._annotationStorageModified = true;
  2402. };
  2403. annotationStorage.onResetModified = () => {
  2404. window.removeEventListener("beforeunload", beforeUnload);
  2405. delete this._annotationStorageModified;
  2406. };
  2407. annotationStorage.onAnnotationEditor = typeStr => {
  2408. this._hasAnnotationEditors = !!typeStr;
  2409. this.setTitle();
  2410. if (typeStr) {
  2411. this.externalServices.reportTelemetry({
  2412. type: "editing",
  2413. data: {
  2414. type: typeStr
  2415. }
  2416. });
  2417. }
  2418. };
  2419. },
  2420. setInitialView(storedHash, {
  2421. rotation,
  2422. sidebarView,
  2423. scrollMode,
  2424. spreadMode
  2425. } = {}) {
  2426. const setRotation = angle => {
  2427. if ((0, _ui_utils.isValidRotation)(angle)) {
  2428. this.pdfViewer.pagesRotation = angle;
  2429. }
  2430. };
  2431. const setViewerModes = (scroll, spread) => {
  2432. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  2433. this.pdfViewer.scrollMode = scroll;
  2434. }
  2435. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  2436. this.pdfViewer.spreadMode = spread;
  2437. }
  2438. };
  2439. this.isInitialViewSet = true;
  2440. this.pdfSidebar?.setInitialView(sidebarView);
  2441. setViewerModes(scrollMode, spreadMode);
  2442. if (this.initialBookmark) {
  2443. setRotation(this.initialRotation);
  2444. delete this.initialRotation;
  2445. this.pdfLinkService.setHash(this.initialBookmark);
  2446. this.initialBookmark = null;
  2447. } else if (storedHash) {
  2448. setRotation(rotation);
  2449. this.pdfLinkService.setHash(storedHash);
  2450. }
  2451. this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  2452. this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
  2453. if (!this.pdfViewer.currentScaleValue) {
  2454. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2455. }
  2456. },
  2457. _cleanup() {
  2458. if (!this.pdfDocument) {
  2459. return;
  2460. }
  2461. this.pdfViewer.cleanup();
  2462. this.pdfThumbnailViewer?.cleanup();
  2463. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  2464. },
  2465. forceRendering() {
  2466. this.pdfRenderingQueue.printing = !!this.printService;
  2467. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS;
  2468. this.pdfRenderingQueue.renderHighestPriority();
  2469. },
  2470. beforePrint() {
  2471. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => { }).then(() => {
  2472. return this.pdfDocument?.annotationStorage.print;
  2473. });
  2474. if (this.printService) {
  2475. return;
  2476. }
  2477. if (!this.supportsPrinting) {
  2478. this.l10n.get("printing_not_supported").then(msg => {
  2479. this._otherError(msg);
  2480. });
  2481. return;
  2482. }
  2483. if (!this.pdfViewer.pageViewsReady) {
  2484. this.l10n.get("printing_not_ready").then(msg => {
  2485. window.alert(msg);
  2486. });
  2487. return;
  2488. }
  2489. const pagesOverview = this.pdfViewer.getPagesOverview();
  2490. const printContainer = this.appConfig.printContainer;
  2491. const printResolution = _app_options.AppOptions.get("printResolution");
  2492. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  2493. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  2494. this.printService = printService;
  2495. this.forceRendering();
  2496. this.setTitle();
  2497. printService.layout();
  2498. if (this._hasAnnotationEditors) {
  2499. this.externalServices.reportTelemetry({
  2500. type: "editing",
  2501. data: {
  2502. type: "print"
  2503. }
  2504. });
  2505. }
  2506. },
  2507. afterPrint() {
  2508. if (this._printAnnotationStoragePromise) {
  2509. this._printAnnotationStoragePromise.then(() => {
  2510. this.pdfScriptingManager.dispatchDidPrint();
  2511. });
  2512. this._printAnnotationStoragePromise = null;
  2513. }
  2514. if (this.printService) {
  2515. this.printService.destroy();
  2516. this.printService = null;
  2517. this.pdfDocument?.annotationStorage.resetModified();
  2518. }
  2519. this.forceRendering();
  2520. this.setTitle();
  2521. },
  2522. rotatePages(delta) {
  2523. this.pdfViewer.pagesRotation += delta;
  2524. },
  2525. requestPresentationMode() {
  2526. this.pdfPresentationMode?.request();
  2527. },
  2528. triggerPrinting() {
  2529. if (!this.supportsPrinting) {
  2530. return;
  2531. }
  2532. window.print();
  2533. },
  2534. bindEvents() {
  2535. const {
  2536. eventBus,
  2537. _boundEvents
  2538. } = this;
  2539. _boundEvents.beforePrint = this.beforePrint.bind(this);
  2540. _boundEvents.afterPrint = this.afterPrint.bind(this);
  2541. eventBus._on("resize", webViewerResize);
  2542. eventBus._on("hashchange", webViewerHashchange);
  2543. eventBus._on("beforeprint", _boundEvents.beforePrint);
  2544. eventBus._on("afterprint", _boundEvents.afterPrint);
  2545. eventBus._on("pagerender", webViewerPageRender);
  2546. eventBus._on("pagerendered", webViewerPageRendered);
  2547. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  2548. eventBus._on("pagechanging", webViewerPageChanging);
  2549. eventBus._on("scalechanging", webViewerScaleChanging);
  2550. eventBus._on("rotationchanging", webViewerRotationChanging);
  2551. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  2552. eventBus._on("pagemode", webViewerPageMode);
  2553. eventBus._on("namedaction", webViewerNamedAction);
  2554. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  2555. eventBus._on("presentationmode", webViewerPresentationMode);
  2556. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  2557. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  2558. eventBus._on("print", webViewerPrint);
  2559. eventBus._on("download", webViewerDownload);
  2560. eventBus._on("firstpage", webViewerFirstPage);
  2561. eventBus._on("lastpage", webViewerLastPage);
  2562. eventBus._on("nextpage", webViewerNextPage);
  2563. eventBus._on("previouspage", webViewerPreviousPage);
  2564. eventBus._on("zoomin", webViewerZoomIn);
  2565. eventBus._on("zoomout", webViewerZoomOut);
  2566. eventBus._on("zoomreset", webViewerZoomReset);
  2567. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  2568. eventBus._on("scalechanged", webViewerScaleChanged);
  2569. eventBus._on("rotatecw", webViewerRotateCw);
  2570. eventBus._on("rotateccw", webViewerRotateCcw);
  2571. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  2572. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  2573. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  2574. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  2575. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  2576. eventBus._on("documentproperties", webViewerDocumentProperties);
  2577. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  2578. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2579. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  2580. if (_app_options.AppOptions.get("pdfBug")) {
  2581. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  2582. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2583. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2584. }
  2585. eventBus._on("fileinputchange", webViewerFileInputChange);
  2586. eventBus._on("openfile", webViewerOpenFile);
  2587. },
  2588. bindWindowEvents() {
  2589. const {
  2590. eventBus,
  2591. _boundEvents
  2592. } = this;
  2593. function addWindowResolutionChange(evt = null) {
  2594. if (evt) {
  2595. webViewerResolutionChange(evt);
  2596. }
  2597. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  2598. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  2599. once: true
  2600. });
  2601. _boundEvents.removeWindowResolutionChange ||= function () {
  2602. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  2603. _boundEvents.removeWindowResolutionChange = null;
  2604. };
  2605. }
  2606. addWindowResolutionChange();
  2607. _boundEvents.windowResize = () => {
  2608. eventBus.dispatch("resize", {
  2609. source: window
  2610. });
  2611. };
  2612. _boundEvents.windowHashChange = () => {
  2613. eventBus.dispatch("hashchange", {
  2614. source: window,
  2615. hash: document.location.hash.substring(1)
  2616. });
  2617. };
  2618. _boundEvents.windowBeforePrint = () => {
  2619. eventBus.dispatch("beforeprint", {
  2620. source: window
  2621. });
  2622. };
  2623. _boundEvents.windowAfterPrint = () => {
  2624. eventBus.dispatch("afterprint", {
  2625. source: window
  2626. });
  2627. };
  2628. _boundEvents.windowUpdateFromSandbox = event => {
  2629. eventBus.dispatch("updatefromsandbox", {
  2630. source: window,
  2631. detail: event.detail
  2632. });
  2633. };
  2634. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  2635. window.addEventListener("wheel", webViewerWheel, {
  2636. passive: false
  2637. });
  2638. window.addEventListener("touchstart", webViewerTouchStart, {
  2639. passive: false
  2640. });
  2641. window.addEventListener("touchmove", webViewerTouchMove, {
  2642. passive: false
  2643. });
  2644. window.addEventListener("touchend", webViewerTouchEnd, {
  2645. passive: false
  2646. });
  2647. window.addEventListener("click", webViewerClick);
  2648. window.addEventListener("keydown", webViewerKeyDown);
  2649. window.addEventListener("keyup", webViewerKeyUp);
  2650. window.addEventListener("resize", _boundEvents.windowResize);
  2651. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  2652. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2653. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  2654. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2655. },
  2656. unbindEvents() {
  2657. const {
  2658. eventBus,
  2659. _boundEvents
  2660. } = this;
  2661. eventBus._off("resize", webViewerResize);
  2662. eventBus._off("hashchange", webViewerHashchange);
  2663. eventBus._off("beforeprint", _boundEvents.beforePrint);
  2664. eventBus._off("afterprint", _boundEvents.afterPrint);
  2665. eventBus._off("pagerender", webViewerPageRender);
  2666. eventBus._off("pagerendered", webViewerPageRendered);
  2667. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  2668. eventBus._off("pagechanging", webViewerPageChanging);
  2669. eventBus._off("scalechanging", webViewerScaleChanging);
  2670. eventBus._off("rotationchanging", webViewerRotationChanging);
  2671. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  2672. eventBus._off("pagemode", webViewerPageMode);
  2673. eventBus._off("namedaction", webViewerNamedAction);
  2674. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  2675. eventBus._off("presentationmode", webViewerPresentationMode);
  2676. eventBus._off("print", webViewerPrint);
  2677. eventBus._off("download", webViewerDownload);
  2678. eventBus._off("firstpage", webViewerFirstPage);
  2679. eventBus._off("lastpage", webViewerLastPage);
  2680. eventBus._off("nextpage", webViewerNextPage);
  2681. eventBus._off("previouspage", webViewerPreviousPage);
  2682. eventBus._off("zoomin", webViewerZoomIn);
  2683. eventBus._off("zoomout", webViewerZoomOut);
  2684. eventBus._off("zoomreset", webViewerZoomReset);
  2685. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  2686. eventBus._off("scalechanged", webViewerScaleChanged);
  2687. eventBus._off("rotatecw", webViewerRotateCw);
  2688. eventBus._off("rotateccw", webViewerRotateCcw);
  2689. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  2690. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  2691. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  2692. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  2693. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  2694. eventBus._off("documentproperties", webViewerDocumentProperties);
  2695. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  2696. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2697. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  2698. if (_boundEvents.reportPageStatsPDFBug) {
  2699. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2700. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2701. _boundEvents.reportPageStatsPDFBug = null;
  2702. }
  2703. eventBus._off("fileinputchange", webViewerFileInputChange);
  2704. eventBus._off("openfile", webViewerOpenFile);
  2705. _boundEvents.beforePrint = null;
  2706. _boundEvents.afterPrint = null;
  2707. },
  2708. unbindWindowEvents() {
  2709. const {
  2710. _boundEvents
  2711. } = this;
  2712. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  2713. window.removeEventListener("wheel", webViewerWheel, {
  2714. passive: false
  2715. });
  2716. window.removeEventListener("touchstart", webViewerTouchStart, {
  2717. passive: false
  2718. });
  2719. window.removeEventListener("touchmove", webViewerTouchMove, {
  2720. passive: false
  2721. });
  2722. window.removeEventListener("touchend", webViewerTouchEnd, {
  2723. passive: false
  2724. });
  2725. window.removeEventListener("click", webViewerClick);
  2726. window.removeEventListener("keydown", webViewerKeyDown);
  2727. window.removeEventListener("keyup", webViewerKeyUp);
  2728. window.removeEventListener("resize", _boundEvents.windowResize);
  2729. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  2730. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2731. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  2732. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2733. _boundEvents.removeWindowResolutionChange?.();
  2734. _boundEvents.windowResize = null;
  2735. _boundEvents.windowHashChange = null;
  2736. _boundEvents.windowBeforePrint = null;
  2737. _boundEvents.windowAfterPrint = null;
  2738. _boundEvents.windowUpdateFromSandbox = null;
  2739. },
  2740. _accumulateTicks(ticks, prop) {
  2741. if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) {
  2742. this[prop] = 0;
  2743. }
  2744. this[prop] += ticks;
  2745. const wholeTicks = Math.trunc(this[prop]);
  2746. this[prop] -= wholeTicks;
  2747. return wholeTicks;
  2748. },
  2749. _accumulateFactor(previousScale, factor, prop) {
  2750. if (factor === 1) {
  2751. return 1;
  2752. }
  2753. if (this[prop] > 1 && factor < 1 || this[prop] < 1 && factor > 1) {
  2754. this[prop] = 1;
  2755. }
  2756. const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale);
  2757. this[prop] = factor / newFactor;
  2758. return newFactor;
  2759. },
  2760. _centerAtPos(previousScale, x, y) {
  2761. const {
  2762. pdfViewer
  2763. } = this;
  2764. const scaleDiff = pdfViewer.currentScale / previousScale - 1;
  2765. if (scaleDiff !== 0) {
  2766. const [top, left] = pdfViewer.containerTopLeft;
  2767. pdfViewer.container.scrollLeft += (x - left) * scaleDiff;
  2768. pdfViewer.container.scrollTop += (y - top) * scaleDiff;
  2769. }
  2770. },
  2771. _unblockDocumentLoadEvent() {
  2772. document.blockUnblockOnload?.(false);
  2773. this._unblockDocumentLoadEvent = () => { };
  2774. },
  2775. get scriptingReady() {
  2776. return this.pdfScriptingManager.ready;
  2777. }
  2778. };
  2779. exports.PDFViewerApplication = PDFViewerApplication;
  2780. {
  2781. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  2782. var validateFileURL = function (file) {
  2783. if (!file) {
  2784. return;
  2785. }
  2786. try {
  2787. const viewerOrigin = new URL(window.location.href).origin || "null";
  2788. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  2789. return;
  2790. }
  2791. // const fileOrigin = new URL(file, window.location.href).origin;
  2792. // if (fileOrigin !== viewerOrigin) {
  2793. // throw new Error("file origin does not match viewer's");
  2794. // }
  2795. } catch (ex) {
  2796. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2797. PDFViewerApplication._documentError(msg, {
  2798. message: ex?.message
  2799. });
  2800. });
  2801. throw ex;
  2802. }
  2803. };
  2804. }
  2805. async function loadFakeWorker() {
  2806. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  2807. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  2808. }
  2809. async function loadPDFBug(self) {
  2810. const {
  2811. debuggerScriptPath
  2812. } = self.appConfig;
  2813. const {
  2814. PDFBug
  2815. } = await import(debuggerScriptPath);
  2816. self._PDFBug = PDFBug;
  2817. }
  2818. function reportPageStatsPDFBug({
  2819. pageNumber
  2820. }) {
  2821. if (!globalThis.Stats?.enabled) {
  2822. return;
  2823. }
  2824. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2825. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  2826. }
  2827. function webViewerInitialized() {
  2828. const {
  2829. appConfig,
  2830. eventBus
  2831. } = PDFViewerApplication;
  2832. let file;
  2833. const queryString = document.location.search.substring(1);
  2834. const params = (0, _ui_utils.parseQueryString)(queryString);
  2835. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  2836. validateFileURL(file);
  2837. const fileInput = appConfig.openFileInput;
  2838. fileInput.value = null;
  2839. fileInput.addEventListener("change", function (evt) {
  2840. const {
  2841. files
  2842. } = evt.target;
  2843. if (!files || files.length === 0) {
  2844. return;
  2845. }
  2846. eventBus.dispatch("fileinputchange", {
  2847. source: this,
  2848. fileInput: evt.target
  2849. });
  2850. });
  2851. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  2852. evt.preventDefault();
  2853. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  2854. });
  2855. appConfig.mainContainer.addEventListener("drop", function (evt) {
  2856. evt.preventDefault();
  2857. const {
  2858. files
  2859. } = evt.dataTransfer;
  2860. if (!files || files.length === 0) {
  2861. return;
  2862. }
  2863. eventBus.dispatch("fileinputchange", {
  2864. source: this,
  2865. fileInput: evt.dataTransfer
  2866. });
  2867. });
  2868. if (!PDFViewerApplication.supportsDocumentFonts) {
  2869. _app_options.AppOptions.set("disableFontFace", true);
  2870. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  2871. console.warn(msg);
  2872. });
  2873. }
  2874. if (!PDFViewerApplication.supportsPrinting) {
  2875. appConfig.toolbar?.print.classList.add("hidden");
  2876. appConfig.secondaryToolbar?.printButton.classList.add("hidden");
  2877. }
  2878. if (!PDFViewerApplication.supportsFullscreen) {
  2879. appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
  2880. }
  2881. if (PDFViewerApplication.supportsIntegratedFind) {
  2882. appConfig.toolbar?.viewFind.classList.add("hidden");
  2883. }
  2884. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  2885. if (evt.target === this) {
  2886. eventBus.dispatch("resize", {
  2887. source: this
  2888. });
  2889. }
  2890. }, true);
  2891. try {
  2892. if (file) {
  2893. PDFViewerApplication.open({
  2894. url: file
  2895. });
  2896. } else {
  2897. PDFViewerApplication._hideViewBookmark();
  2898. }
  2899. } catch (reason) {
  2900. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2901. PDFViewerApplication._documentError(msg, reason);
  2902. });
  2903. }
  2904. }
  2905. function webViewerPageRender({
  2906. pageNumber
  2907. }) {
  2908. if (pageNumber === PDFViewerApplication.page) {
  2909. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
  2910. }
  2911. }
  2912. function webViewerPageRendered({
  2913. pageNumber,
  2914. error
  2915. }) {
  2916. if (pageNumber === PDFViewerApplication.page) {
  2917. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
  2918. }
  2919. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  2920. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2921. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
  2922. if (pageView && thumbnailView) {
  2923. thumbnailView.setImage(pageView);
  2924. }
  2925. }
  2926. if (error) {
  2927. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  2928. PDFViewerApplication._otherError(msg, error);
  2929. });
  2930. }
  2931. }
  2932. function webViewerPageMode({
  2933. mode
  2934. }) {
  2935. let view;
  2936. switch (mode) {
  2937. case "thumbs":
  2938. view = _ui_utils.SidebarView.THUMBS;
  2939. break;
  2940. case "bookmarks":
  2941. case "outline":
  2942. view = _ui_utils.SidebarView.OUTLINE;
  2943. break;
  2944. case "attachments":
  2945. view = _ui_utils.SidebarView.ATTACHMENTS;
  2946. break;
  2947. case "layers":
  2948. view = _ui_utils.SidebarView.LAYERS;
  2949. break;
  2950. case "none":
  2951. view = _ui_utils.SidebarView.NONE;
  2952. break;
  2953. default:
  2954. console.error('Invalid "pagemode" hash parameter: ' + mode);
  2955. return;
  2956. }
  2957. PDFViewerApplication.pdfSidebar?.switchView(view, true);
  2958. }
  2959. function webViewerNamedAction(evt) {
  2960. switch (evt.action) {
  2961. case "GoToPage":
  2962. PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
  2963. break;
  2964. case "Find":
  2965. if (!PDFViewerApplication.supportsIntegratedFind) {
  2966. PDFViewerApplication?.findBar.toggle();
  2967. }
  2968. break;
  2969. case "Print":
  2970. PDFViewerApplication.triggerPrinting();
  2971. break;
  2972. case "SaveAs":
  2973. PDFViewerApplication.downloadOrSave();
  2974. break;
  2975. }
  2976. }
  2977. function webViewerPresentationModeChanged(evt) {
  2978. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  2979. }
  2980. function webViewerSidebarViewChanged({
  2981. view
  2982. }) {
  2983. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  2984. if (PDFViewerApplication.isInitialViewSet) {
  2985. PDFViewerApplication.store?.set("sidebarView", view).catch(() => { });
  2986. }
  2987. }
  2988. function webViewerUpdateViewarea({
  2989. location
  2990. }) {
  2991. if (PDFViewerApplication.isInitialViewSet) {
  2992. PDFViewerApplication.store?.setMultiple({
  2993. page: location.pageNumber,
  2994. zoom: location.scale,
  2995. scrollLeft: location.left,
  2996. scrollTop: location.top,
  2997. rotation: location.rotation
  2998. }).catch(() => { });
  2999. }
  3000. if (PDFViewerApplication.appConfig.secondaryToolbar) {
  3001. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  3002. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  3003. }
  3004. }
  3005. function webViewerScrollModeChanged(evt) {
  3006. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  3007. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => { });
  3008. }
  3009. }
  3010. function webViewerSpreadModeChanged(evt) {
  3011. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  3012. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => { });
  3013. }
  3014. }
  3015. function webViewerResize() {
  3016. const {
  3017. pdfDocument,
  3018. pdfViewer,
  3019. pdfRenderingQueue
  3020. } = PDFViewerApplication;
  3021. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  3022. return;
  3023. }
  3024. if (!pdfDocument) {
  3025. return;
  3026. }
  3027. const currentScaleValue = pdfViewer.currentScaleValue;
  3028. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  3029. pdfViewer.currentScaleValue = currentScaleValue;
  3030. }
  3031. pdfViewer.update();
  3032. }
  3033. function webViewerHashchange(evt) {
  3034. var hash = evt.hash;
  3035. if (!hash) {
  3036. return;
  3037. }
  3038. if (!PDFViewerApplication.isInitialViewSet) {
  3039. PDFViewerApplication.initialBookmark = hash;
  3040. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  3041. PDFViewerApplication.pdfLinkService.setHash(hash);
  3042. }
  3043. }
  3044. {
  3045. var webViewerFileInputChange = function (evt) {
  3046. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  3047. return;
  3048. }
  3049. const file = evt.fileInput.files[0];
  3050. PDFViewerApplication.open({
  3051. url: URL.createObjectURL(file),
  3052. originalUrl: file.name
  3053. });
  3054. };
  3055. var webViewerOpenFile = function (evt) {
  3056. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  3057. fileInput.click();
  3058. };
  3059. }
  3060. function webViewerPresentationMode() {
  3061. PDFViewerApplication.requestPresentationMode();
  3062. }
  3063. function webViewerSwitchAnnotationEditorMode(evt) {
  3064. PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
  3065. }
  3066. function webViewerSwitchAnnotationEditorParams(evt) {
  3067. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  3068. }
  3069. function webViewerPrint() {
  3070. PDFViewerApplication.triggerPrinting();
  3071. }
  3072. function webViewerDownload() {
  3073. PDFViewerApplication.downloadOrSave();
  3074. }
  3075. function webViewerFirstPage() {
  3076. if (PDFViewerApplication.pdfDocument) {
  3077. PDFViewerApplication.page = 1;
  3078. }
  3079. }
  3080. function webViewerLastPage() {
  3081. if (PDFViewerApplication.pdfDocument) {
  3082. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3083. }
  3084. }
  3085. function webViewerNextPage() {
  3086. PDFViewerApplication.pdfViewer.nextPage();
  3087. }
  3088. function webViewerPreviousPage() {
  3089. PDFViewerApplication.pdfViewer.previousPage();
  3090. }
  3091. function webViewerZoomIn() {
  3092. PDFViewerApplication.zoomIn();
  3093. }
  3094. function webViewerZoomOut() {
  3095. PDFViewerApplication.zoomOut();
  3096. }
  3097. function webViewerZoomReset() {
  3098. PDFViewerApplication.zoomReset();
  3099. }
  3100. function webViewerPageNumberChanged(evt) {
  3101. const pdfViewer = PDFViewerApplication.pdfViewer;
  3102. if (evt.value !== "") {
  3103. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  3104. }
  3105. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  3106. PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  3107. }
  3108. }
  3109. function webViewerScaleChanged(evt) {
  3110. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  3111. }
  3112. function webViewerRotateCw() {
  3113. PDFViewerApplication.rotatePages(90);
  3114. }
  3115. function webViewerRotateCcw() {
  3116. PDFViewerApplication.rotatePages(-90);
  3117. }
  3118. function webViewerOptionalContentConfig(evt) {
  3119. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  3120. }
  3121. function webViewerSwitchScrollMode(evt) {
  3122. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  3123. }
  3124. function webViewerSwitchSpreadMode(evt) {
  3125. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  3126. }
  3127. function webViewerDocumentProperties() {
  3128. PDFViewerApplication.pdfDocumentProperties?.open();
  3129. }
  3130. function webViewerFindFromUrlHash(evt) {
  3131. PDFViewerApplication.eventBus.dispatch("find", {
  3132. source: evt.source,
  3133. type: "",
  3134. query: evt.query,
  3135. phraseSearch: evt.phraseSearch,
  3136. caseSensitive: false,
  3137. entireWord: false,
  3138. highlightAll: true,
  3139. findPrevious: false,
  3140. matchDiacritics: true
  3141. });
  3142. }
  3143. function webViewerUpdateFindMatchesCount({
  3144. matchesCount
  3145. }) {
  3146. if (PDFViewerApplication.supportsIntegratedFind) {
  3147. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  3148. } else {
  3149. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  3150. }
  3151. }
  3152. function webViewerUpdateFindControlState({
  3153. state,
  3154. previous,
  3155. matchesCount,
  3156. rawQuery
  3157. }) {
  3158. if (PDFViewerApplication.supportsIntegratedFind) {
  3159. PDFViewerApplication.externalServices.updateFindControlState({
  3160. result: state,
  3161. findPrevious: previous,
  3162. matchesCount,
  3163. rawQuery
  3164. });
  3165. } else {
  3166. PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount);
  3167. }
  3168. }
  3169. function webViewerScaleChanging(evt) {
  3170. PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
  3171. PDFViewerApplication.pdfViewer.update();
  3172. }
  3173. function webViewerRotationChanging(evt) {
  3174. if (PDFViewerApplication.pdfThumbnailViewer) {
  3175. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  3176. }
  3177. PDFViewerApplication.forceRendering();
  3178. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  3179. }
  3180. function webViewerPageChanging({
  3181. pageNumber,
  3182. pageLabel
  3183. }) {
  3184. PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
  3185. PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
  3186. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  3187. PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
  3188. }
  3189. const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  3190. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING);
  3191. }
  3192. function webViewerResolutionChange(evt) {
  3193. PDFViewerApplication.pdfViewer.refresh();
  3194. }
  3195. function webViewerVisibilityChange(evt) {
  3196. if (document.visibilityState === "visible") {
  3197. setZoomDisabledTimeout();
  3198. }
  3199. }
  3200. let zoomDisabledTimeout = null;
  3201. function setZoomDisabledTimeout() {
  3202. if (zoomDisabledTimeout) {
  3203. clearTimeout(zoomDisabledTimeout);
  3204. }
  3205. zoomDisabledTimeout = setTimeout(function () {
  3206. zoomDisabledTimeout = null;
  3207. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  3208. }
  3209. function webViewerWheel(evt) {
  3210. const {
  3211. pdfViewer,
  3212. supportedMouseWheelZoomModifierKeys,
  3213. supportsPinchToZoom
  3214. } = PDFViewerApplication;
  3215. if (pdfViewer.isInPresentationMode) {
  3216. return;
  3217. }
  3218. const deltaMode = evt.deltaMode;
  3219. let scaleFactor = Math.exp(-evt.deltaY / 100);
  3220. const isPinchToZoom = evt.ctrlKey && !PDFViewerApplication._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && Math.abs(scaleFactor - 1) < 0.05 && evt.deltaZ === 0;
  3221. if (isPinchToZoom || evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  3222. evt.preventDefault();
  3223. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  3224. return;
  3225. }
  3226. const previousScale = pdfViewer.currentScale;
  3227. if (isPinchToZoom && supportsPinchToZoom) {
  3228. scaleFactor = PDFViewerApplication._accumulateFactor(previousScale, scaleFactor, "_wheelUnusedFactor");
  3229. if (scaleFactor < 1) {
  3230. PDFViewerApplication.zoomOut(null, scaleFactor);
  3231. } else if (scaleFactor > 1) {
  3232. PDFViewerApplication.zoomIn(null, scaleFactor);
  3233. } else {
  3234. return;
  3235. }
  3236. } else {
  3237. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  3238. let ticks = 0;
  3239. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  3240. if (Math.abs(delta) >= 1) {
  3241. ticks = Math.sign(delta);
  3242. } else {
  3243. ticks = PDFViewerApplication._accumulateTicks(delta, "_wheelUnusedTicks");
  3244. }
  3245. } else {
  3246. const PIXELS_PER_LINE_SCALE = 30;
  3247. ticks = PDFViewerApplication._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks");
  3248. }
  3249. if (ticks < 0) {
  3250. PDFViewerApplication.zoomOut(-ticks);
  3251. } else if (ticks > 0) {
  3252. PDFViewerApplication.zoomIn(ticks);
  3253. } else {
  3254. return;
  3255. }
  3256. }
  3257. PDFViewerApplication._centerAtPos(previousScale, evt.clientX, evt.clientY);
  3258. } else {
  3259. setZoomDisabledTimeout();
  3260. }
  3261. }
  3262. function webViewerTouchStart(evt) {
  3263. if (PDFViewerApplication.pdfViewer.isInPresentationMode || evt.touches.length < 2) {
  3264. return;
  3265. }
  3266. evt.preventDefault();
  3267. if (evt.touches.length !== 2) {
  3268. PDFViewerApplication._touchInfo = null;
  3269. return;
  3270. }
  3271. let [touch0, touch1] = evt.touches;
  3272. if (touch0.identifier > touch1.identifier) {
  3273. [touch0, touch1] = [touch1, touch0];
  3274. }
  3275. PDFViewerApplication._touchInfo = {
  3276. touch0X: touch0.pageX,
  3277. touch0Y: touch0.pageY,
  3278. touch1X: touch1.pageX,
  3279. touch1Y: touch1.pageY
  3280. };
  3281. }
  3282. function webViewerTouchMove(evt) {
  3283. if (!PDFViewerApplication._touchInfo || evt.touches.length !== 2) {
  3284. return;
  3285. }
  3286. const {
  3287. pdfViewer,
  3288. _touchInfo,
  3289. supportsPinchToZoom
  3290. } = PDFViewerApplication;
  3291. let [touch0, touch1] = evt.touches;
  3292. if (touch0.identifier > touch1.identifier) {
  3293. [touch0, touch1] = [touch1, touch0];
  3294. }
  3295. const {
  3296. pageX: page0X,
  3297. pageY: page0Y
  3298. } = touch0;
  3299. const {
  3300. pageX: page1X,
  3301. pageY: page1Y
  3302. } = touch1;
  3303. const {
  3304. touch0X: pTouch0X,
  3305. touch0Y: pTouch0Y,
  3306. touch1X: pTouch1X,
  3307. touch1Y: pTouch1Y
  3308. } = _touchInfo;
  3309. if (Math.abs(pTouch0X - page0X) <= 1 && Math.abs(pTouch0Y - page0Y) <= 1 && Math.abs(pTouch1X - page1X) <= 1 && Math.abs(pTouch1Y - page1Y) <= 1) {
  3310. return;
  3311. }
  3312. _touchInfo.touch0X = page0X;
  3313. _touchInfo.touch0Y = page0Y;
  3314. _touchInfo.touch1X = page1X;
  3315. _touchInfo.touch1Y = page1Y;
  3316. if (pTouch0X === page0X && pTouch0Y === page0Y) {
  3317. const v1X = pTouch1X - page0X;
  3318. const v1Y = pTouch1Y - page0Y;
  3319. const v2X = page1X - page0X;
  3320. const v2Y = page1Y - page0Y;
  3321. const det = v1X * v2Y - v1Y * v2X;
  3322. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  3323. return;
  3324. }
  3325. } else if (pTouch1X === page1X && pTouch1Y === page1Y) {
  3326. const v1X = pTouch0X - page1X;
  3327. const v1Y = pTouch0Y - page1Y;
  3328. const v2X = page0X - page1X;
  3329. const v2Y = page0Y - page1Y;
  3330. const det = v1X * v2Y - v1Y * v2X;
  3331. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  3332. return;
  3333. }
  3334. } else {
  3335. const diff0X = page0X - pTouch0X;
  3336. const diff1X = page1X - pTouch1X;
  3337. const diff0Y = page0Y - pTouch0Y;
  3338. const diff1Y = page1Y - pTouch1Y;
  3339. const dotProduct = diff0X * diff1X + diff0Y * diff1Y;
  3340. if (dotProduct >= 0) {
  3341. return;
  3342. }
  3343. }
  3344. evt.preventDefault();
  3345. const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1;
  3346. const pDistance = Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1;
  3347. const previousScale = pdfViewer.currentScale;
  3348. if (supportsPinchToZoom) {
  3349. const newScaleFactor = PDFViewerApplication._accumulateFactor(previousScale, distance / pDistance, "_touchUnusedFactor");
  3350. if (newScaleFactor < 1) {
  3351. PDFViewerApplication.zoomOut(null, newScaleFactor);
  3352. } else if (newScaleFactor > 1) {
  3353. PDFViewerApplication.zoomIn(null, newScaleFactor);
  3354. } else {
  3355. return;
  3356. }
  3357. } else {
  3358. const PIXELS_PER_LINE_SCALE = 30;
  3359. const ticks = PDFViewerApplication._accumulateTicks((distance - pDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks");
  3360. if (ticks < 0) {
  3361. PDFViewerApplication.zoomOut(-ticks);
  3362. } else if (ticks > 0) {
  3363. PDFViewerApplication.zoomIn(ticks);
  3364. } else {
  3365. return;
  3366. }
  3367. }
  3368. PDFViewerApplication._centerAtPos(previousScale, (page0X + page1X) / 2, (page0Y + page1Y) / 2);
  3369. }
  3370. function webViewerTouchEnd(evt) {
  3371. if (!PDFViewerApplication._touchInfo) {
  3372. return;
  3373. }
  3374. evt.preventDefault();
  3375. PDFViewerApplication._touchInfo = null;
  3376. PDFViewerApplication._touchUnusedTicks = 0;
  3377. PDFViewerApplication._touchUnusedFactor = 1;
  3378. }
  3379. function webViewerClick(evt) {
  3380. if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
  3381. return;
  3382. }
  3383. const appConfig = PDFViewerApplication.appConfig;
  3384. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) {
  3385. PDFViewerApplication.secondaryToolbar.close();
  3386. }
  3387. }
  3388. function webViewerKeyUp(evt) {
  3389. if (evt.key === "Control") {
  3390. PDFViewerApplication._isCtrlKeyDown = false;
  3391. }
  3392. }
  3393. function webViewerKeyDown(evt) {
  3394. PDFViewerApplication._isCtrlKeyDown = evt.key === "Control";
  3395. if (PDFViewerApplication.overlayManager.active) {
  3396. return;
  3397. }
  3398. const {
  3399. eventBus,
  3400. pdfViewer
  3401. } = PDFViewerApplication;
  3402. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  3403. let handled = false,
  3404. ensureViewerFocused = false;
  3405. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  3406. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  3407. switch (evt.keyCode) {
  3408. case 70:
  3409. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  3410. PDFViewerApplication.findBar?.open();
  3411. handled = true;
  3412. }
  3413. break;
  3414. case 71:
  3415. if (!PDFViewerApplication.supportsIntegratedFind) {
  3416. const {
  3417. state
  3418. } = PDFViewerApplication.findController;
  3419. if (state) {
  3420. const eventState = Object.assign(Object.create(null), state, {
  3421. source: window,
  3422. type: "again",
  3423. findPrevious: cmd === 5 || cmd === 12
  3424. });
  3425. eventBus.dispatch("find", eventState);
  3426. }
  3427. handled = true;
  3428. }
  3429. break;
  3430. case 61:
  3431. case 107:
  3432. case 187:
  3433. case 171:
  3434. if (!isViewerInPresentationMode) {
  3435. PDFViewerApplication.zoomIn();
  3436. }
  3437. handled = true;
  3438. break;
  3439. case 173:
  3440. case 109:
  3441. case 189:
  3442. if (!isViewerInPresentationMode) {
  3443. PDFViewerApplication.zoomOut();
  3444. }
  3445. handled = true;
  3446. break;
  3447. case 48:
  3448. case 96:
  3449. if (!isViewerInPresentationMode) {
  3450. setTimeout(function () {
  3451. PDFViewerApplication.zoomReset();
  3452. });
  3453. handled = false;
  3454. }
  3455. break;
  3456. case 38:
  3457. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3458. PDFViewerApplication.page = 1;
  3459. handled = true;
  3460. ensureViewerFocused = true;
  3461. }
  3462. break;
  3463. case 40:
  3464. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3465. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3466. handled = true;
  3467. ensureViewerFocused = true;
  3468. }
  3469. break;
  3470. }
  3471. }
  3472. if (cmd === 1 || cmd === 8) {
  3473. switch (evt.keyCode) {
  3474. case 83:
  3475. eventBus.dispatch("download", {
  3476. source: window
  3477. });
  3478. handled = true;
  3479. break;
  3480. case 79:
  3481. {
  3482. eventBus.dispatch("openfile", {
  3483. source: window
  3484. });
  3485. handled = true;
  3486. }
  3487. break;
  3488. }
  3489. }
  3490. if (cmd === 3 || cmd === 10) {
  3491. switch (evt.keyCode) {
  3492. case 80:
  3493. PDFViewerApplication.requestPresentationMode();
  3494. handled = true;
  3495. PDFViewerApplication.externalServices.reportTelemetry({
  3496. type: "buttons",
  3497. data: {
  3498. id: "presentationModeKeyboard"
  3499. }
  3500. });
  3501. break;
  3502. case 71:
  3503. if (PDFViewerApplication.appConfig.toolbar) {
  3504. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  3505. handled = true;
  3506. }
  3507. break;
  3508. }
  3509. }
  3510. if (handled) {
  3511. if (ensureViewerFocused && !isViewerInPresentationMode) {
  3512. pdfViewer.focus();
  3513. }
  3514. evt.preventDefault();
  3515. return;
  3516. }
  3517. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  3518. const curElementTagName = curElement?.tagName.toUpperCase();
  3519. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  3520. if (evt.keyCode !== 27) {
  3521. return;
  3522. }
  3523. }
  3524. if (cmd === 0) {
  3525. let turnPage = 0,
  3526. turnOnlyIfPageFit = false;
  3527. switch (evt.keyCode) {
  3528. case 38:
  3529. case 33:
  3530. if (pdfViewer.isVerticalScrollbarEnabled) {
  3531. turnOnlyIfPageFit = true;
  3532. }
  3533. turnPage = -1;
  3534. break;
  3535. case 8:
  3536. if (!isViewerInPresentationMode) {
  3537. turnOnlyIfPageFit = true;
  3538. }
  3539. turnPage = -1;
  3540. break;
  3541. case 37:
  3542. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3543. turnOnlyIfPageFit = true;
  3544. }
  3545. case 75:
  3546. case 80:
  3547. turnPage = -1;
  3548. break;
  3549. case 27:
  3550. if (PDFViewerApplication.secondaryToolbar?.isOpen) {
  3551. PDFViewerApplication.secondaryToolbar.close();
  3552. handled = true;
  3553. }
  3554. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) {
  3555. PDFViewerApplication.findBar.close();
  3556. handled = true;
  3557. }
  3558. break;
  3559. case 40:
  3560. case 34:
  3561. if (pdfViewer.isVerticalScrollbarEnabled) {
  3562. turnOnlyIfPageFit = true;
  3563. }
  3564. turnPage = 1;
  3565. break;
  3566. case 13:
  3567. case 32:
  3568. if (!isViewerInPresentationMode) {
  3569. turnOnlyIfPageFit = true;
  3570. }
  3571. turnPage = 1;
  3572. break;
  3573. case 39:
  3574. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3575. turnOnlyIfPageFit = true;
  3576. }
  3577. case 74:
  3578. case 78:
  3579. turnPage = 1;
  3580. break;
  3581. case 36:
  3582. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3583. PDFViewerApplication.page = 1;
  3584. handled = true;
  3585. ensureViewerFocused = true;
  3586. }
  3587. break;
  3588. case 35:
  3589. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3590. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3591. handled = true;
  3592. ensureViewerFocused = true;
  3593. }
  3594. break;
  3595. case 83:
  3596. PDFViewerApplication.pdfCursorTools?.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  3597. break;
  3598. case 72:
  3599. PDFViewerApplication.pdfCursorTools?.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  3600. break;
  3601. case 82:
  3602. PDFViewerApplication.rotatePages(90);
  3603. break;
  3604. case 115:
  3605. PDFViewerApplication.pdfSidebar?.toggle();
  3606. break;
  3607. }
  3608. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  3609. if (turnPage > 0) {
  3610. pdfViewer.nextPage();
  3611. } else {
  3612. pdfViewer.previousPage();
  3613. }
  3614. handled = true;
  3615. }
  3616. }
  3617. if (cmd === 4) {
  3618. switch (evt.keyCode) {
  3619. case 13:
  3620. case 32:
  3621. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  3622. break;
  3623. }
  3624. pdfViewer.previousPage();
  3625. handled = true;
  3626. break;
  3627. case 82:
  3628. PDFViewerApplication.rotatePages(-90);
  3629. break;
  3630. }
  3631. }
  3632. if (!handled && !isViewerInPresentationMode) {
  3633. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  3634. ensureViewerFocused = true;
  3635. }
  3636. }
  3637. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  3638. pdfViewer.focus();
  3639. }
  3640. if (handled) {
  3641. evt.preventDefault();
  3642. }
  3643. }
  3644. function beforeUnload(evt) {
  3645. evt.preventDefault();
  3646. evt.returnValue = "";
  3647. return false;
  3648. }
  3649. function webViewerAnnotationEditorStatesChanged(data) {
  3650. PDFViewerApplication.externalServices.updateEditorStates(data);
  3651. }
  3652. const PDFPrintServiceFactory = {
  3653. instance: {
  3654. supportsPrinting: false,
  3655. createPrintService() {
  3656. throw new Error("Not implemented: createPrintService");
  3657. }
  3658. }
  3659. };
  3660. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  3661. /***/
  3662. }),
  3663. /* 5 */
  3664. /***/ ((module) => {
  3665. let pdfjsLib;
  3666. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3667. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3668. } else {
  3669. pdfjsLib = require("../build/pdf.js");
  3670. }
  3671. module.exports = pdfjsLib;
  3672. /***/
  3673. }),
  3674. /* 6 */
  3675. /***/ ((__unused_webpack_module, exports) => {
  3676. Object.defineProperty(exports, "__esModule", ({
  3677. value: true
  3678. }));
  3679. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3680. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3681. const WaitOnType = {
  3682. EVENT: "event",
  3683. TIMEOUT: "timeout"
  3684. };
  3685. exports.WaitOnType = WaitOnType;
  3686. function waitOnEventOrTimeout({
  3687. target,
  3688. name,
  3689. delay = 0
  3690. }) {
  3691. return new Promise(function (resolve, reject) {
  3692. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3693. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3694. }
  3695. function handler(type) {
  3696. if (target instanceof EventBus) {
  3697. target._off(name, eventHandler);
  3698. } else {
  3699. target.removeEventListener(name, eventHandler);
  3700. }
  3701. if (timeout) {
  3702. clearTimeout(timeout);
  3703. }
  3704. resolve(type);
  3705. }
  3706. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3707. if (target instanceof EventBus) {
  3708. target._on(name, eventHandler);
  3709. } else {
  3710. target.addEventListener(name, eventHandler);
  3711. }
  3712. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3713. const timeout = setTimeout(timeoutHandler, delay);
  3714. });
  3715. }
  3716. class EventBus {
  3717. #listeners = Object.create(null);
  3718. on(eventName, listener, options = null) {
  3719. this._on(eventName, listener, {
  3720. external: true,
  3721. once: options?.once
  3722. });
  3723. }
  3724. off(eventName, listener, options = null) {
  3725. this._off(eventName, listener, {
  3726. external: true,
  3727. once: options?.once
  3728. });
  3729. }
  3730. dispatch(eventName, data) {
  3731. const eventListeners = this.#listeners[eventName];
  3732. if (!eventListeners || eventListeners.length === 0) {
  3733. return;
  3734. }
  3735. let externalListeners;
  3736. for (const {
  3737. listener,
  3738. external,
  3739. once
  3740. } of eventListeners.slice(0)) {
  3741. if (once) {
  3742. this._off(eventName, listener);
  3743. }
  3744. if (external) {
  3745. (externalListeners ||= []).push(listener);
  3746. continue;
  3747. }
  3748. listener(data);
  3749. }
  3750. if (externalListeners) {
  3751. for (const listener of externalListeners) {
  3752. listener(data);
  3753. }
  3754. externalListeners = null;
  3755. }
  3756. }
  3757. _on(eventName, listener, options = null) {
  3758. const eventListeners = this.#listeners[eventName] ||= [];
  3759. eventListeners.push({
  3760. listener,
  3761. external: options?.external === true,
  3762. once: options?.once === true
  3763. });
  3764. }
  3765. _off(eventName, listener, options = null) {
  3766. const eventListeners = this.#listeners[eventName];
  3767. if (!eventListeners) {
  3768. return;
  3769. }
  3770. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3771. if (eventListeners[i].listener === listener) {
  3772. eventListeners.splice(i, 1);
  3773. return;
  3774. }
  3775. }
  3776. }
  3777. }
  3778. exports.EventBus = EventBus;
  3779. class AutomationEventBus extends EventBus {
  3780. dispatch(eventName, data) {
  3781. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3782. }
  3783. }
  3784. exports.AutomationEventBus = AutomationEventBus;
  3785. /***/
  3786. }),
  3787. /* 7 */
  3788. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3789. Object.defineProperty(exports, "__esModule", ({
  3790. value: true
  3791. }));
  3792. exports.PDFCursorTools = exports.CursorTool = void 0;
  3793. var _pdfjsLib = __webpack_require__(5);
  3794. var _grab_to_pan = __webpack_require__(8);
  3795. var _ui_utils = __webpack_require__(1);
  3796. const CursorTool = {
  3797. SELECT: 0,
  3798. HAND: 1,
  3799. ZOOM: 2
  3800. };
  3801. exports.CursorTool = CursorTool;
  3802. class PDFCursorTools {
  3803. constructor({
  3804. container,
  3805. eventBus,
  3806. cursorToolOnLoad = CursorTool.SELECT
  3807. }) {
  3808. this.container = container;
  3809. this.eventBus = eventBus;
  3810. this.active = CursorTool.SELECT;
  3811. this.previouslyActive = null;
  3812. this.handTool = new _grab_to_pan.GrabToPan({
  3813. element: this.container
  3814. });
  3815. this.#addEventListeners();
  3816. Promise.resolve().then(() => {
  3817. this.switchTool(cursorToolOnLoad);
  3818. });
  3819. }
  3820. get activeTool() {
  3821. return this.active;
  3822. }
  3823. switchTool(tool) {
  3824. if (this.previouslyActive !== null) {
  3825. return;
  3826. }
  3827. if (tool === this.active) {
  3828. return;
  3829. }
  3830. const disableActiveTool = () => {
  3831. switch (this.active) {
  3832. case CursorTool.SELECT:
  3833. break;
  3834. case CursorTool.HAND:
  3835. this.handTool.deactivate();
  3836. break;
  3837. case CursorTool.ZOOM:
  3838. }
  3839. };
  3840. switch (tool) {
  3841. case CursorTool.SELECT:
  3842. disableActiveTool();
  3843. break;
  3844. case CursorTool.HAND:
  3845. disableActiveTool();
  3846. this.handTool.activate();
  3847. break;
  3848. case CursorTool.ZOOM:
  3849. default:
  3850. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3851. return;
  3852. }
  3853. this.active = tool;
  3854. this.#dispatchEvent();
  3855. }
  3856. #dispatchEvent() {
  3857. this.eventBus.dispatch("cursortoolchanged", {
  3858. source: this,
  3859. tool: this.active
  3860. });
  3861. }
  3862. #addEventListeners() {
  3863. this.eventBus._on("switchcursortool", evt => {
  3864. this.switchTool(evt.tool);
  3865. });
  3866. let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
  3867. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  3868. const disableActive = () => {
  3869. const previouslyActive = this.active;
  3870. this.switchTool(CursorTool.SELECT);
  3871. this.previouslyActive ??= previouslyActive;
  3872. };
  3873. const enableActive = () => {
  3874. const previouslyActive = this.previouslyActive;
  3875. if (previouslyActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) {
  3876. this.previouslyActive = null;
  3877. this.switchTool(previouslyActive);
  3878. }
  3879. };
  3880. this.eventBus._on("secondarytoolbarreset", evt => {
  3881. if (this.previouslyActive !== null) {
  3882. annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  3883. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  3884. enableActive();
  3885. }
  3886. });
  3887. this.eventBus._on("annotationeditormodechanged", ({
  3888. mode
  3889. }) => {
  3890. annotationEditorMode = mode;
  3891. if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
  3892. enableActive();
  3893. } else {
  3894. disableActive();
  3895. }
  3896. });
  3897. this.eventBus._on("presentationmodechanged", ({
  3898. state
  3899. }) => {
  3900. presentationModeState = state;
  3901. if (state === _ui_utils.PresentationModeState.NORMAL) {
  3902. enableActive();
  3903. } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
  3904. disableActive();
  3905. }
  3906. });
  3907. }
  3908. }
  3909. exports.PDFCursorTools = PDFCursorTools;
  3910. /***/
  3911. }),
  3912. /* 8 */
  3913. /***/ ((__unused_webpack_module, exports) => {
  3914. Object.defineProperty(exports, "__esModule", ({
  3915. value: true
  3916. }));
  3917. exports.GrabToPan = void 0;
  3918. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3919. class GrabToPan {
  3920. constructor(options) {
  3921. this.element = options.element;
  3922. this.document = options.element.ownerDocument;
  3923. if (typeof options.ignoreTarget === "function") {
  3924. this.ignoreTarget = options.ignoreTarget;
  3925. }
  3926. this.onActiveChanged = options.onActiveChanged;
  3927. this.activate = this.activate.bind(this);
  3928. this.deactivate = this.deactivate.bind(this);
  3929. this.toggle = this.toggle.bind(this);
  3930. this._onMouseDown = this.#onMouseDown.bind(this);
  3931. this._onMouseMove = this.#onMouseMove.bind(this);
  3932. this._endPan = this.#endPan.bind(this);
  3933. const overlay = this.overlay = document.createElement("div");
  3934. overlay.className = "grab-to-pan-grabbing";
  3935. }
  3936. activate() {
  3937. if (!this.active) {
  3938. this.active = true;
  3939. this.element.addEventListener("mousedown", this._onMouseDown, true);
  3940. this.element.classList.add(CSS_CLASS_GRAB);
  3941. this.onActiveChanged?.(true);
  3942. }
  3943. }
  3944. deactivate() {
  3945. if (this.active) {
  3946. this.active = false;
  3947. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  3948. this._endPan();
  3949. this.element.classList.remove(CSS_CLASS_GRAB);
  3950. this.onActiveChanged?.(false);
  3951. }
  3952. }
  3953. toggle() {
  3954. if (this.active) {
  3955. this.deactivate();
  3956. } else {
  3957. this.activate();
  3958. }
  3959. }
  3960. ignoreTarget(node) {
  3961. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3962. }
  3963. #onMouseDown(event) {
  3964. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3965. return;
  3966. }
  3967. if (event.originalTarget) {
  3968. try {
  3969. event.originalTarget.tagName;
  3970. } catch (e) {
  3971. return;
  3972. }
  3973. }
  3974. this.scrollLeftStart = this.element.scrollLeft;
  3975. this.scrollTopStart = this.element.scrollTop;
  3976. this.clientXStart = event.clientX;
  3977. this.clientYStart = event.clientY;
  3978. this.document.addEventListener("mousemove", this._onMouseMove, true);
  3979. this.document.addEventListener("mouseup", this._endPan, true);
  3980. this.element.addEventListener("scroll", this._endPan, true);
  3981. event.preventDefault();
  3982. event.stopPropagation();
  3983. const focusedElement = document.activeElement;
  3984. if (focusedElement && !focusedElement.contains(event.target)) {
  3985. focusedElement.blur();
  3986. }
  3987. }
  3988. #onMouseMove(event) {
  3989. this.element.removeEventListener("scroll", this._endPan, true);
  3990. if (!(event.buttons & 1)) {
  3991. this._endPan();
  3992. return;
  3993. }
  3994. const xDiff = event.clientX - this.clientXStart;
  3995. const yDiff = event.clientY - this.clientYStart;
  3996. const scrollTop = this.scrollTopStart - yDiff;
  3997. const scrollLeft = this.scrollLeftStart - xDiff;
  3998. if (this.element.scrollTo) {
  3999. this.element.scrollTo({
  4000. top: scrollTop,
  4001. left: scrollLeft,
  4002. behavior: "instant"
  4003. });
  4004. } else {
  4005. this.element.scrollTop = scrollTop;
  4006. this.element.scrollLeft = scrollLeft;
  4007. }
  4008. if (!this.overlay.parentNode) {
  4009. document.body.append(this.overlay);
  4010. }
  4011. }
  4012. #endPan() {
  4013. this.element.removeEventListener("scroll", this._endPan, true);
  4014. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  4015. this.document.removeEventListener("mouseup", this._endPan, true);
  4016. this.overlay.remove();
  4017. }
  4018. }
  4019. exports.GrabToPan = GrabToPan;
  4020. /***/
  4021. }),
  4022. /* 9 */
  4023. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4024. Object.defineProperty(exports, "__esModule", ({
  4025. value: true
  4026. }));
  4027. exports.AnnotationEditorParams = void 0;
  4028. var _pdfjsLib = __webpack_require__(5);
  4029. class AnnotationEditorParams {
  4030. constructor(options, eventBus) {
  4031. this.eventBus = eventBus;
  4032. this.#bindListeners(options);
  4033. }
  4034. #bindListeners({
  4035. editorFreeTextFontSize,
  4036. editorFreeTextColor,
  4037. editorInkColor,
  4038. editorInkThickness,
  4039. editorInkOpacity
  4040. }) {
  4041. editorFreeTextFontSize.addEventListener("input", evt => {
  4042. this.eventBus.dispatch("switchannotationeditorparams", {
  4043. source: this,
  4044. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE,
  4045. value: editorFreeTextFontSize.valueAsNumber
  4046. });
  4047. });
  4048. editorFreeTextColor.addEventListener("input", evt => {
  4049. this.eventBus.dispatch("switchannotationeditorparams", {
  4050. source: this,
  4051. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR,
  4052. value: editorFreeTextColor.value
  4053. });
  4054. });
  4055. editorInkColor.addEventListener("input", evt => {
  4056. this.eventBus.dispatch("switchannotationeditorparams", {
  4057. source: this,
  4058. type: _pdfjsLib.AnnotationEditorParamsType.INK_COLOR,
  4059. value: editorInkColor.value
  4060. });
  4061. });
  4062. editorInkThickness.addEventListener("input", evt => {
  4063. this.eventBus.dispatch("switchannotationeditorparams", {
  4064. source: this,
  4065. type: _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS,
  4066. value: editorInkThickness.valueAsNumber
  4067. });
  4068. });
  4069. editorInkOpacity.addEventListener("input", evt => {
  4070. this.eventBus.dispatch("switchannotationeditorparams", {
  4071. source: this,
  4072. type: _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY,
  4073. value: editorInkOpacity.valueAsNumber
  4074. });
  4075. });
  4076. this.eventBus._on("annotationeditorparamschanged", evt => {
  4077. for (const [type, value] of evt.details) {
  4078. switch (type) {
  4079. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  4080. editorFreeTextFontSize.value = value;
  4081. break;
  4082. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  4083. editorFreeTextColor.value = value;
  4084. break;
  4085. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  4086. editorInkColor.value = value;
  4087. break;
  4088. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  4089. editorInkThickness.value = value;
  4090. break;
  4091. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  4092. editorInkOpacity.value = value;
  4093. break;
  4094. }
  4095. }
  4096. });
  4097. }
  4098. }
  4099. exports.AnnotationEditorParams = AnnotationEditorParams;
  4100. /***/
  4101. }),
  4102. /* 10 */
  4103. /***/ ((__unused_webpack_module, exports) => {
  4104. Object.defineProperty(exports, "__esModule", ({
  4105. value: true
  4106. }));
  4107. exports.OverlayManager = void 0;
  4108. class OverlayManager {
  4109. #overlays = new WeakMap();
  4110. #active = null;
  4111. get active() {
  4112. return this.#active;
  4113. }
  4114. async register(dialog, canForceClose = false) {
  4115. if (typeof dialog !== "object") {
  4116. throw new Error("Not enough parameters.");
  4117. } else if (this.#overlays.has(dialog)) {
  4118. throw new Error("The overlay is already registered.");
  4119. }
  4120. this.#overlays.set(dialog, {
  4121. canForceClose
  4122. });
  4123. dialog.addEventListener("cancel", evt => {
  4124. this.#active = null;
  4125. });
  4126. }
  4127. async unregister(dialog) {
  4128. if (!this.#overlays.has(dialog)) {
  4129. throw new Error("The overlay does not exist.");
  4130. } else if (this.#active === dialog) {
  4131. throw new Error("The overlay cannot be removed while it is active.");
  4132. }
  4133. this.#overlays.delete(dialog);
  4134. }
  4135. async open(dialog) {
  4136. if (!this.#overlays.has(dialog)) {
  4137. throw new Error("The overlay does not exist.");
  4138. } else if (this.#active) {
  4139. if (this.#active === dialog) {
  4140. throw new Error("The overlay is already active.");
  4141. } else if (this.#overlays.get(dialog).canForceClose) {
  4142. await this.close();
  4143. } else {
  4144. throw new Error("Another overlay is currently active.");
  4145. }
  4146. }
  4147. this.#active = dialog;
  4148. dialog.showModal();
  4149. }
  4150. async close(dialog = this.#active) {
  4151. if (!this.#overlays.has(dialog)) {
  4152. throw new Error("The overlay does not exist.");
  4153. } else if (!this.#active) {
  4154. throw new Error("The overlay is currently not active.");
  4155. } else if (this.#active !== dialog) {
  4156. throw new Error("Another overlay is currently active.");
  4157. }
  4158. dialog.close();
  4159. this.#active = null;
  4160. }
  4161. }
  4162. exports.OverlayManager = OverlayManager;
  4163. /***/
  4164. }),
  4165. /* 11 */
  4166. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4167. Object.defineProperty(exports, "__esModule", ({
  4168. value: true
  4169. }));
  4170. exports.PasswordPrompt = void 0;
  4171. var _pdfjsLib = __webpack_require__(5);
  4172. class PasswordPrompt {
  4173. #activeCapability = null;
  4174. #updateCallback = null;
  4175. #reason = null;
  4176. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  4177. this.dialog = options.dialog;
  4178. this.label = options.label;
  4179. this.input = options.input;
  4180. this.submitButton = options.submitButton;
  4181. this.cancelButton = options.cancelButton;
  4182. this.overlayManager = overlayManager;
  4183. this.l10n = l10n;
  4184. this._isViewerEmbedded = isViewerEmbedded;
  4185. this.submitButton.addEventListener("click", this.#verify.bind(this));
  4186. this.cancelButton.addEventListener("click", this.close.bind(this));
  4187. this.input.addEventListener("keydown", e => {
  4188. if (e.keyCode === 13) {
  4189. this.#verify();
  4190. }
  4191. });
  4192. this.overlayManager.register(this.dialog, true);
  4193. this.dialog.addEventListener("close", this.#cancel.bind(this));
  4194. }
  4195. async open() {
  4196. if (this.#activeCapability) {
  4197. await this.#activeCapability.promise;
  4198. }
  4199. this.#activeCapability = (0, _pdfjsLib.createPromiseCapability)();
  4200. try {
  4201. await this.overlayManager.open(this.dialog);
  4202. } catch (ex) {
  4203. this.#activeCapability = null;
  4204. throw ex;
  4205. }
  4206. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  4207. if (!this._isViewerEmbedded || passwordIncorrect) {
  4208. this.input.focus();
  4209. }
  4210. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  4211. }
  4212. async close() {
  4213. if (this.overlayManager.active === this.dialog) {
  4214. this.overlayManager.close(this.dialog);
  4215. }
  4216. }
  4217. #verify() {
  4218. const password = this.input.value;
  4219. if (password?.length > 0) {
  4220. this.#invokeCallback(password);
  4221. }
  4222. }
  4223. #cancel() {
  4224. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  4225. this.#activeCapability.resolve();
  4226. }
  4227. #invokeCallback(password) {
  4228. if (!this.#updateCallback) {
  4229. return;
  4230. }
  4231. this.close();
  4232. this.input.value = "";
  4233. this.#updateCallback(password);
  4234. this.#updateCallback = null;
  4235. }
  4236. async setUpdateCallback(updateCallback, reason) {
  4237. if (this.#activeCapability) {
  4238. await this.#activeCapability.promise;
  4239. }
  4240. this.#updateCallback = updateCallback;
  4241. this.#reason = reason;
  4242. }
  4243. }
  4244. exports.PasswordPrompt = PasswordPrompt;
  4245. /***/
  4246. }),
  4247. /* 12 */
  4248. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4249. Object.defineProperty(exports, "__esModule", ({
  4250. value: true
  4251. }));
  4252. exports.PDFAttachmentViewer = void 0;
  4253. var _pdfjsLib = __webpack_require__(5);
  4254. var _base_tree_viewer = __webpack_require__(13);
  4255. var _event_utils = __webpack_require__(6);
  4256. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4257. constructor(options) {
  4258. super(options);
  4259. this.downloadManager = options.downloadManager;
  4260. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  4261. }
  4262. reset(keepRenderedCapability = false) {
  4263. super.reset();
  4264. this._attachments = null;
  4265. if (!keepRenderedCapability) {
  4266. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4267. }
  4268. this._pendingDispatchEvent = false;
  4269. }
  4270. async _dispatchEvent(attachmentsCount) {
  4271. this._renderedCapability.resolve();
  4272. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4273. this._pendingDispatchEvent = true;
  4274. await (0, _event_utils.waitOnEventOrTimeout)({
  4275. target: this.eventBus,
  4276. name: "annotationlayerrendered",
  4277. delay: 1000
  4278. });
  4279. if (!this._pendingDispatchEvent) {
  4280. return;
  4281. }
  4282. }
  4283. this._pendingDispatchEvent = false;
  4284. this.eventBus.dispatch("attachmentsloaded", {
  4285. source: this,
  4286. attachmentsCount
  4287. });
  4288. }
  4289. _bindLink(element, {
  4290. content,
  4291. filename
  4292. }) {
  4293. element.onclick = () => {
  4294. this.downloadManager.openOrDownloadData(element, content, filename);
  4295. return false;
  4296. };
  4297. }
  4298. render({
  4299. attachments,
  4300. keepRenderedCapability = false
  4301. }) {
  4302. if (this._attachments) {
  4303. this.reset(keepRenderedCapability);
  4304. }
  4305. this._attachments = attachments || null;
  4306. if (!attachments) {
  4307. this._dispatchEvent(0);
  4308. return;
  4309. }
  4310. const names = Object.keys(attachments).sort(function (a, b) {
  4311. return a.toLowerCase().localeCompare(b.toLowerCase());
  4312. });
  4313. const fragment = document.createDocumentFragment();
  4314. let attachmentsCount = 0;
  4315. for (const name of names) {
  4316. const item = attachments[name];
  4317. const content = item.content,
  4318. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true);
  4319. const div = document.createElement("div");
  4320. div.className = "treeItem";
  4321. const element = document.createElement("a");
  4322. this._bindLink(element, {
  4323. content,
  4324. filename
  4325. });
  4326. element.textContent = this._normalizeTextContent(filename);
  4327. div.append(element);
  4328. fragment.append(div);
  4329. attachmentsCount++;
  4330. }
  4331. this._finishRendering(fragment, attachmentsCount);
  4332. }
  4333. #appendAttachment({
  4334. filename,
  4335. content
  4336. }) {
  4337. const renderedPromise = this._renderedCapability.promise;
  4338. renderedPromise.then(() => {
  4339. if (renderedPromise !== this._renderedCapability.promise) {
  4340. return;
  4341. }
  4342. const attachments = this._attachments || Object.create(null);
  4343. for (const name in attachments) {
  4344. if (filename === name) {
  4345. return;
  4346. }
  4347. }
  4348. attachments[filename] = {
  4349. filename,
  4350. content
  4351. };
  4352. this.render({
  4353. attachments,
  4354. keepRenderedCapability: true
  4355. });
  4356. });
  4357. }
  4358. }
  4359. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4360. /***/
  4361. }),
  4362. /* 13 */
  4363. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4364. Object.defineProperty(exports, "__esModule", ({
  4365. value: true
  4366. }));
  4367. exports.BaseTreeViewer = void 0;
  4368. var _ui_utils = __webpack_require__(1);
  4369. const TREEITEM_OFFSET_TOP = -100;
  4370. const TREEITEM_SELECTED_CLASS = "selected";
  4371. class BaseTreeViewer {
  4372. constructor(options) {
  4373. if (this.constructor === BaseTreeViewer) {
  4374. throw new Error("Cannot initialize BaseTreeViewer.");
  4375. }
  4376. this.container = options.container;
  4377. this.eventBus = options.eventBus;
  4378. this.reset();
  4379. }
  4380. reset() {
  4381. this._pdfDocument = null;
  4382. this._lastToggleIsShow = true;
  4383. this._currentTreeItem = null;
  4384. this.container.textContent = "";
  4385. this.container.classList.remove("treeWithDeepNesting");
  4386. }
  4387. _dispatchEvent(count) {
  4388. throw new Error("Not implemented: _dispatchEvent");
  4389. }
  4390. _bindLink(element, params) {
  4391. throw new Error("Not implemented: _bindLink");
  4392. }
  4393. _normalizeTextContent(str) {
  4394. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4395. }
  4396. _addToggleButton(div, hidden = false) {
  4397. const toggler = document.createElement("div");
  4398. toggler.className = "treeItemToggler";
  4399. if (hidden) {
  4400. toggler.classList.add("treeItemsHidden");
  4401. }
  4402. toggler.onclick = evt => {
  4403. evt.stopPropagation();
  4404. toggler.classList.toggle("treeItemsHidden");
  4405. if (evt.shiftKey) {
  4406. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4407. this._toggleTreeItem(div, shouldShowAll);
  4408. }
  4409. };
  4410. div.prepend(toggler);
  4411. }
  4412. _toggleTreeItem(root, show = false) {
  4413. this._lastToggleIsShow = show;
  4414. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4415. toggler.classList.toggle("treeItemsHidden", !show);
  4416. }
  4417. }
  4418. _toggleAllTreeItems() {
  4419. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4420. }
  4421. _finishRendering(fragment, count, hasAnyNesting = false) {
  4422. if (hasAnyNesting) {
  4423. this.container.classList.add("treeWithDeepNesting");
  4424. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4425. }
  4426. this.container.append(fragment);
  4427. this._dispatchEvent(count);
  4428. }
  4429. render(params) {
  4430. throw new Error("Not implemented: render");
  4431. }
  4432. _updateCurrentTreeItem(treeItem = null) {
  4433. if (this._currentTreeItem) {
  4434. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4435. this._currentTreeItem = null;
  4436. }
  4437. if (treeItem) {
  4438. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4439. this._currentTreeItem = treeItem;
  4440. }
  4441. }
  4442. _scrollToCurrentTreeItem(treeItem) {
  4443. if (!treeItem) {
  4444. return;
  4445. }
  4446. let currentNode = treeItem.parentNode;
  4447. while (currentNode && currentNode !== this.container) {
  4448. if (currentNode.classList.contains("treeItem")) {
  4449. const toggler = currentNode.firstElementChild;
  4450. toggler?.classList.remove("treeItemsHidden");
  4451. }
  4452. currentNode = currentNode.parentNode;
  4453. }
  4454. this._updateCurrentTreeItem(treeItem);
  4455. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4456. }
  4457. }
  4458. exports.BaseTreeViewer = BaseTreeViewer;
  4459. /***/
  4460. }),
  4461. /* 14 */
  4462. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4463. Object.defineProperty(exports, "__esModule", ({
  4464. value: true
  4465. }));
  4466. exports.PDFDocumentProperties = void 0;
  4467. var _pdfjsLib = __webpack_require__(5);
  4468. var _ui_utils = __webpack_require__(1);
  4469. const DEFAULT_FIELD_CONTENT = "-";
  4470. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4471. const US_PAGE_NAMES = {
  4472. "8.5x11": "Letter",
  4473. "8.5x14": "Legal"
  4474. };
  4475. const METRIC_PAGE_NAMES = {
  4476. "297x420": "A3",
  4477. "210x297": "A4"
  4478. };
  4479. function getPageName(size, isPortrait, pageNames) {
  4480. const width = isPortrait ? size.width : size.height;
  4481. const height = isPortrait ? size.height : size.width;
  4482. return pageNames[`${width}x${height}`];
  4483. }
  4484. class PDFDocumentProperties {
  4485. #fieldData = null;
  4486. constructor({
  4487. dialog,
  4488. fields,
  4489. closeButton
  4490. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4491. this.dialog = dialog;
  4492. this.fields = fields;
  4493. this.overlayManager = overlayManager;
  4494. this.l10n = l10n;
  4495. this._fileNameLookup = fileNameLookup;
  4496. this.#reset();
  4497. closeButton.addEventListener("click", this.close.bind(this));
  4498. this.overlayManager.register(this.dialog);
  4499. eventBus._on("pagechanging", evt => {
  4500. this._currentPageNumber = evt.pageNumber;
  4501. });
  4502. eventBus._on("rotationchanging", evt => {
  4503. this._pagesRotation = evt.pagesRotation;
  4504. });
  4505. this._isNonMetricLocale = true;
  4506. l10n.getLanguage().then(locale => {
  4507. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4508. });
  4509. }
  4510. async open() {
  4511. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4512. const currentPageNumber = this._currentPageNumber;
  4513. const pagesRotation = this._pagesRotation;
  4514. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4515. this.#updateUI();
  4516. return;
  4517. }
  4518. const {
  4519. info,
  4520. contentLength
  4521. } = await this.pdfDocument.getMetadata();
  4522. const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([this._fileNameLookup(), this.#parseFileSize(contentLength), this.#parseDate(info.CreationDate), this.#parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
  4523. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4524. }), this.#parseLinearization(info.IsLinearized)]);
  4525. this.#fieldData = Object.freeze({
  4526. fileName,
  4527. fileSize,
  4528. title: info.Title,
  4529. author: info.Author,
  4530. subject: info.Subject,
  4531. keywords: info.Keywords,
  4532. creationDate,
  4533. modificationDate,
  4534. creator: info.Creator,
  4535. producer: info.Producer,
  4536. version: info.PDFFormatVersion,
  4537. pageCount: this.pdfDocument.numPages,
  4538. pageSize,
  4539. linearized: isLinearized,
  4540. _currentPageNumber: currentPageNumber,
  4541. _pagesRotation: pagesRotation
  4542. });
  4543. this.#updateUI();
  4544. const {
  4545. length
  4546. } = await this.pdfDocument.getDownloadInfo();
  4547. if (contentLength === length) {
  4548. return;
  4549. }
  4550. const data = Object.assign(Object.create(null), this.#fieldData);
  4551. data.fileSize = await this.#parseFileSize(length);
  4552. this.#fieldData = Object.freeze(data);
  4553. this.#updateUI();
  4554. }
  4555. async close() {
  4556. this.overlayManager.close(this.dialog);
  4557. }
  4558. setDocument(pdfDocument) {
  4559. if (this.pdfDocument) {
  4560. this.#reset();
  4561. this.#updateUI(true);
  4562. }
  4563. if (!pdfDocument) {
  4564. return;
  4565. }
  4566. this.pdfDocument = pdfDocument;
  4567. this._dataAvailableCapability.resolve();
  4568. }
  4569. #reset() {
  4570. this.pdfDocument = null;
  4571. this.#fieldData = null;
  4572. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4573. this._currentPageNumber = 1;
  4574. this._pagesRotation = 0;
  4575. }
  4576. #updateUI(reset = false) {
  4577. if (reset || !this.#fieldData) {
  4578. for (const id in this.fields) {
  4579. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4580. }
  4581. return;
  4582. }
  4583. if (this.overlayManager.active !== this.dialog) {
  4584. return;
  4585. }
  4586. for (const id in this.fields) {
  4587. const content = this.#fieldData[id];
  4588. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4589. }
  4590. }
  4591. async #parseFileSize(fileSize = 0) {
  4592. const kb = fileSize / 1024,
  4593. mb = kb / 1024;
  4594. if (!kb) {
  4595. return undefined;
  4596. }
  4597. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4598. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4599. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4600. size_b: fileSize.toLocaleString()
  4601. });
  4602. }
  4603. async #parsePageSize(pageSizeInches, pagesRotation) {
  4604. if (!pageSizeInches) {
  4605. return undefined;
  4606. }
  4607. if (pagesRotation % 180 !== 0) {
  4608. pageSizeInches = {
  4609. width: pageSizeInches.height,
  4610. height: pageSizeInches.width
  4611. };
  4612. }
  4613. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4614. let sizeInches = {
  4615. width: Math.round(pageSizeInches.width * 100) / 100,
  4616. height: Math.round(pageSizeInches.height * 100) / 100
  4617. };
  4618. let sizeMillimeters = {
  4619. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4620. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4621. };
  4622. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4623. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4624. const exactMillimeters = {
  4625. width: pageSizeInches.width * 25.4,
  4626. height: pageSizeInches.height * 25.4
  4627. };
  4628. const intMillimeters = {
  4629. width: Math.round(sizeMillimeters.width),
  4630. height: Math.round(sizeMillimeters.height)
  4631. };
  4632. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4633. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4634. if (rawName) {
  4635. sizeInches = {
  4636. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4637. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4638. };
  4639. sizeMillimeters = intMillimeters;
  4640. }
  4641. }
  4642. }
  4643. const [{
  4644. width,
  4645. height
  4646. }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`document_properties_page_size_unit_${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`), this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`)]);
  4647. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4648. width: width.toLocaleString(),
  4649. height: height.toLocaleString(),
  4650. unit,
  4651. name,
  4652. orientation
  4653. });
  4654. }
  4655. async #parseDate(inputDate) {
  4656. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4657. if (!dateObject) {
  4658. return undefined;
  4659. }
  4660. return this.l10n.get("document_properties_date_string", {
  4661. date: dateObject.toLocaleDateString(),
  4662. time: dateObject.toLocaleTimeString()
  4663. });
  4664. }
  4665. #parseLinearization(isLinearized) {
  4666. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4667. }
  4668. }
  4669. exports.PDFDocumentProperties = PDFDocumentProperties;
  4670. /***/
  4671. }),
  4672. /* 15 */
  4673. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4674. Object.defineProperty(exports, "__esModule", ({
  4675. value: true
  4676. }));
  4677. exports.PDFFindBar = void 0;
  4678. var _pdf_find_controller = __webpack_require__(16);
  4679. const MATCHES_COUNT_LIMIT = 1000;
  4680. class PDFFindBar {
  4681. constructor(options, eventBus, l10n) {
  4682. this.opened = false;
  4683. this.bar = options.bar;
  4684. this.toggleButton = options.toggleButton;
  4685. this.findField = options.findField;
  4686. this.highlightAll = options.highlightAllCheckbox;
  4687. this.caseSensitive = options.caseSensitiveCheckbox;
  4688. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4689. this.entireWord = options.entireWordCheckbox;
  4690. this.findMsg = options.findMsg;
  4691. this.findResultsCount = options.findResultsCount;
  4692. this.findPreviousButton = options.findPreviousButton;
  4693. this.findNextButton = options.findNextButton;
  4694. this.eventBus = eventBus;
  4695. this.l10n = l10n;
  4696. this.toggleButton.addEventListener("click", () => {
  4697. this.toggle();
  4698. });
  4699. this.findField.addEventListener("input", () => {
  4700. this.dispatchEvent("");
  4701. });
  4702. this.bar.addEventListener("keydown", e => {
  4703. switch (e.keyCode) {
  4704. case 13:
  4705. if (e.target === this.findField) {
  4706. this.dispatchEvent("again", e.shiftKey);
  4707. }
  4708. break;
  4709. case 27:
  4710. this.close();
  4711. break;
  4712. }
  4713. });
  4714. this.findPreviousButton.addEventListener("click", () => {
  4715. this.dispatchEvent("again", true);
  4716. });
  4717. this.findNextButton.addEventListener("click", () => {
  4718. this.dispatchEvent("again", false);
  4719. });
  4720. this.highlightAll.addEventListener("click", () => {
  4721. this.dispatchEvent("highlightallchange");
  4722. });
  4723. this.caseSensitive.addEventListener("click", () => {
  4724. this.dispatchEvent("casesensitivitychange");
  4725. });
  4726. this.entireWord.addEventListener("click", () => {
  4727. this.dispatchEvent("entirewordchange");
  4728. });
  4729. this.matchDiacritics.addEventListener("click", () => {
  4730. this.dispatchEvent("diacriticmatchingchange");
  4731. });
  4732. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4733. }
  4734. reset() {
  4735. this.updateUIState();
  4736. }
  4737. dispatchEvent(type, findPrev = false) {
  4738. this.eventBus.dispatch("find", {
  4739. source: this,
  4740. type,
  4741. query: this.findField.value,
  4742. phraseSearch: true,
  4743. caseSensitive: this.caseSensitive.checked,
  4744. entireWord: this.entireWord.checked,
  4745. highlightAll: this.highlightAll.checked,
  4746. findPrevious: findPrev,
  4747. matchDiacritics: this.matchDiacritics.checked
  4748. });
  4749. }
  4750. updateUIState(state, previous, matchesCount) {
  4751. let findMsg = Promise.resolve("");
  4752. let status = "";
  4753. switch (state) {
  4754. case _pdf_find_controller.FindState.FOUND:
  4755. break;
  4756. case _pdf_find_controller.FindState.PENDING:
  4757. status = "pending";
  4758. break;
  4759. case _pdf_find_controller.FindState.NOT_FOUND:
  4760. findMsg = this.l10n.get("find_not_found");
  4761. status = "notFound";
  4762. break;
  4763. case _pdf_find_controller.FindState.WRAPPED:
  4764. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4765. break;
  4766. }
  4767. this.findField.setAttribute("data-status", status);
  4768. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4769. findMsg.then(msg => {
  4770. this.findMsg.textContent = msg;
  4771. this.#adjustWidth();
  4772. });
  4773. this.updateResultsCount(matchesCount);
  4774. }
  4775. updateResultsCount({
  4776. current = 0,
  4777. total = 0
  4778. } = {}) {
  4779. const limit = MATCHES_COUNT_LIMIT;
  4780. let matchCountMsg = Promise.resolve("");
  4781. if (total > 0) {
  4782. if (total > limit) {
  4783. let key = "find_match_count_limit";
  4784. matchCountMsg = this.l10n.get(key, {
  4785. limit
  4786. });
  4787. } else {
  4788. let key = "find_match_count";
  4789. matchCountMsg = this.l10n.get(key, {
  4790. current,
  4791. total
  4792. });
  4793. }
  4794. }
  4795. matchCountMsg.then(msg => {
  4796. this.findResultsCount.textContent = msg;
  4797. this.#adjustWidth();
  4798. });
  4799. }
  4800. open() {
  4801. if (!this.opened) {
  4802. this.opened = true;
  4803. this.toggleButton.classList.add("toggled");
  4804. this.toggleButton.setAttribute("aria-expanded", "true");
  4805. this.bar.classList.remove("hidden");
  4806. }
  4807. this.findField.select();
  4808. this.findField.focus();
  4809. this.#adjustWidth();
  4810. }
  4811. close() {
  4812. if (!this.opened) {
  4813. return;
  4814. }
  4815. this.opened = false;
  4816. this.toggleButton.classList.remove("toggled");
  4817. this.toggleButton.setAttribute("aria-expanded", "false");
  4818. this.bar.classList.add("hidden");
  4819. this.eventBus.dispatch("findbarclose", {
  4820. source: this
  4821. });
  4822. }
  4823. toggle() {
  4824. if (this.opened) {
  4825. this.close();
  4826. } else {
  4827. this.open();
  4828. }
  4829. }
  4830. #adjustWidth() {
  4831. if (!this.opened) {
  4832. return;
  4833. }
  4834. this.bar.classList.remove("wrapContainers");
  4835. const findbarHeight = this.bar.clientHeight;
  4836. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4837. if (findbarHeight > inputContainerHeight) {
  4838. this.bar.classList.add("wrapContainers");
  4839. }
  4840. }
  4841. }
  4842. exports.PDFFindBar = PDFFindBar;
  4843. /***/
  4844. }),
  4845. /* 16 */
  4846. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4847. Object.defineProperty(exports, "__esModule", ({
  4848. value: true
  4849. }));
  4850. exports.PDFFindController = exports.FindState = void 0;
  4851. var _ui_utils = __webpack_require__(1);
  4852. var _pdfjsLib = __webpack_require__(5);
  4853. var _pdf_find_utils = __webpack_require__(17);
  4854. const FindState = {
  4855. FOUND: 0,
  4856. NOT_FOUND: 1,
  4857. WRAPPED: 2,
  4858. PENDING: 3
  4859. };
  4860. exports.FindState = FindState;
  4861. const FIND_TIMEOUT = 250;
  4862. const MATCH_SCROLL_OFFSET_TOP = -50;
  4863. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4864. const CHARACTERS_TO_NORMALIZE = {
  4865. "\u2010": "-",
  4866. "\u2018": "'",
  4867. "\u2019": "'",
  4868. "\u201A": "'",
  4869. "\u201B": "'",
  4870. "\u201C": '"',
  4871. "\u201D": '"',
  4872. "\u201E": '"',
  4873. "\u201F": '"',
  4874. "\u00BC": "1/4",
  4875. "\u00BD": "1/2",
  4876. "\u00BE": "3/4"
  4877. };
  4878. 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]);
  4879. let DIACRITICS_EXCEPTION_STR;
  4880. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4881. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4882. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4883. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4884. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4885. const SYLLABLES_LENGTHS = new Map();
  4886. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4887. const NFKC_CHARS_TO_NORMALIZE = new Map();
  4888. let noSyllablesRegExp = null;
  4889. let withSyllablesRegExp = null;
  4890. function normalize(text) {
  4891. const syllablePositions = [];
  4892. let m;
  4893. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4894. let {
  4895. index
  4896. } = m;
  4897. for (const char of m[0]) {
  4898. let len = SYLLABLES_LENGTHS.get(char);
  4899. if (!len) {
  4900. len = char.normalize("NFD").length;
  4901. SYLLABLES_LENGTHS.set(char, len);
  4902. }
  4903. syllablePositions.push([len, index++]);
  4904. }
  4905. }
  4906. let normalizationRegex;
  4907. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4908. normalizationRegex = noSyllablesRegExp;
  4909. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4910. normalizationRegex = withSyllablesRegExp;
  4911. } else {
  4912. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4913. const toNormalizeWithNFKC = "\u2460-\u2473" + "\u24b6-\u24ff" + "\u3244-\u32bf" + "\u32d0-\u32fe" + "\uff00-\uffef";
  4914. const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
  4915. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
  4916. if (syllablePositions.length === 0) {
  4917. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4918. } else {
  4919. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4920. }
  4921. }
  4922. const rawDiacriticsPositions = [];
  4923. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4924. rawDiacriticsPositions.push([m[0].length, m.index]);
  4925. }
  4926. let normalized = text.normalize("NFD");
  4927. const positions = [[0, 0]];
  4928. let rawDiacriticsIndex = 0;
  4929. let syllableIndex = 0;
  4930. let shift = 0;
  4931. let shiftOrigin = 0;
  4932. let eol = 0;
  4933. let hasDiacritics = false;
  4934. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, i) => {
  4935. i -= shiftOrigin;
  4936. if (p1) {
  4937. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  4938. const jj = replacement.length;
  4939. for (let j = 1; j < jj; j++) {
  4940. positions.push([i - shift + j, shift - j]);
  4941. }
  4942. shift -= jj - 1;
  4943. return replacement;
  4944. }
  4945. if (p2) {
  4946. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  4947. if (!replacement) {
  4948. replacement = p2.normalize("NFKC");
  4949. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  4950. }
  4951. const jj = replacement.length;
  4952. for (let j = 1; j < jj; j++) {
  4953. positions.push([i - shift + j, shift - j]);
  4954. }
  4955. shift -= jj - 1;
  4956. return replacement;
  4957. }
  4958. if (p3) {
  4959. const hasTrailingDashEOL = p3.endsWith("\n");
  4960. const len = hasTrailingDashEOL ? p3.length - 2 : p3.length;
  4961. hasDiacritics = true;
  4962. let jj = len;
  4963. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4964. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4965. ++rawDiacriticsIndex;
  4966. }
  4967. for (let j = 1; j <= jj; j++) {
  4968. positions.push([i - 1 - shift + j, shift - j]);
  4969. }
  4970. shift -= jj;
  4971. shiftOrigin += jj;
  4972. if (hasTrailingDashEOL) {
  4973. i += len - 1;
  4974. positions.push([i - shift + 1, 1 + shift]);
  4975. shift += 1;
  4976. shiftOrigin += 1;
  4977. eol += 1;
  4978. return p3.slice(0, len);
  4979. }
  4980. return p3;
  4981. }
  4982. if (p4) {
  4983. positions.push([i - shift + 1, 1 + shift]);
  4984. shift += 1;
  4985. shiftOrigin += 1;
  4986. eol += 1;
  4987. return p4.charAt(0);
  4988. }
  4989. if (p5) {
  4990. positions.push([i - shift + 1, shift]);
  4991. shiftOrigin += 1;
  4992. eol += 1;
  4993. return p5.charAt(0);
  4994. }
  4995. if (p6) {
  4996. positions.push([i - shift + 1, shift - 1]);
  4997. shift -= 1;
  4998. shiftOrigin += 1;
  4999. eol += 1;
  5000. return " ";
  5001. }
  5002. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  5003. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  5004. ++syllableIndex;
  5005. for (let j = 1; j <= newCharLen; j++) {
  5006. positions.push([i - (shift - j), shift - j]);
  5007. }
  5008. shift -= newCharLen;
  5009. shiftOrigin += newCharLen;
  5010. }
  5011. return p7;
  5012. });
  5013. positions.push([normalized.length, shift]);
  5014. return [normalized, positions, hasDiacritics];
  5015. }
  5016. function getOriginalIndex(diffs, pos, len) {
  5017. if (!diffs) {
  5018. return [pos, len];
  5019. }
  5020. const start = pos;
  5021. const end = pos + len;
  5022. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  5023. if (diffs[i][0] > start) {
  5024. --i;
  5025. }
  5026. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  5027. if (diffs[j][0] > end) {
  5028. --j;
  5029. }
  5030. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  5031. }
  5032. class PDFFindController {
  5033. #updateMatchesCountOnProgress = true;
  5034. #visitedPagesCount = 0;
  5035. constructor({
  5036. linkService,
  5037. eventBus,
  5038. updateMatchesCountOnProgress = true
  5039. }) {
  5040. this._linkService = linkService;
  5041. this._eventBus = eventBus;
  5042. this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
  5043. this.#reset();
  5044. eventBus._on("find", this.#onFind.bind(this));
  5045. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  5046. }
  5047. get highlightMatches() {
  5048. return this._highlightMatches;
  5049. }
  5050. get pageMatches() {
  5051. return this._pageMatches;
  5052. }
  5053. get pageMatchesLength() {
  5054. return this._pageMatchesLength;
  5055. }
  5056. get selected() {
  5057. return this._selected;
  5058. }
  5059. get state() {
  5060. return this._state;
  5061. }
  5062. setDocument(pdfDocument) {
  5063. if (this._pdfDocument) {
  5064. this.#reset();
  5065. }
  5066. if (!pdfDocument) {
  5067. return;
  5068. }
  5069. this._pdfDocument = pdfDocument;
  5070. this._firstPageCapability.resolve();
  5071. }
  5072. #onFind(state) {
  5073. if (!state) {
  5074. return;
  5075. }
  5076. const pdfDocument = this._pdfDocument;
  5077. const {
  5078. type
  5079. } = state;
  5080. if (this._state === null || this.#shouldDirtyMatch(state)) {
  5081. this._dirtyMatch = true;
  5082. }
  5083. this._state = state;
  5084. if (type !== "highlightallchange") {
  5085. this.#updateUIState(FindState.PENDING);
  5086. }
  5087. this._firstPageCapability.promise.then(() => {
  5088. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5089. return;
  5090. }
  5091. this.#extractText();
  5092. const findbarClosed = !this._highlightMatches;
  5093. const pendingTimeout = !!this._findTimeout;
  5094. if (this._findTimeout) {
  5095. clearTimeout(this._findTimeout);
  5096. this._findTimeout = null;
  5097. }
  5098. if (!type) {
  5099. this._findTimeout = setTimeout(() => {
  5100. this.#nextMatch();
  5101. this._findTimeout = null;
  5102. }, FIND_TIMEOUT);
  5103. } else if (this._dirtyMatch) {
  5104. this.#nextMatch();
  5105. } else if (type === "again") {
  5106. this.#nextMatch();
  5107. if (findbarClosed && this._state.highlightAll) {
  5108. this.#updateAllPages();
  5109. }
  5110. } else if (type === "highlightallchange") {
  5111. if (pendingTimeout) {
  5112. this.#nextMatch();
  5113. } else {
  5114. this._highlightMatches = true;
  5115. }
  5116. this.#updateAllPages();
  5117. } else {
  5118. this.#nextMatch();
  5119. }
  5120. });
  5121. }
  5122. scrollMatchIntoView({
  5123. element = null,
  5124. selectedLeft = 0,
  5125. pageIndex = -1,
  5126. matchIndex = -1
  5127. }) {
  5128. if (!this._scrollMatches || !element) {
  5129. return;
  5130. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  5131. return;
  5132. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5133. return;
  5134. }
  5135. this._scrollMatches = false;
  5136. const spot = {
  5137. top: MATCH_SCROLL_OFFSET_TOP,
  5138. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  5139. };
  5140. (0, _ui_utils.scrollIntoView)(element, spot, true);
  5141. }
  5142. #reset() {
  5143. this._highlightMatches = false;
  5144. this._scrollMatches = false;
  5145. this._pdfDocument = null;
  5146. this._pageMatches = [];
  5147. this._pageMatchesLength = [];
  5148. this.#visitedPagesCount = 0;
  5149. this._state = null;
  5150. this._selected = {
  5151. pageIdx: -1,
  5152. matchIdx: -1
  5153. };
  5154. this._offset = {
  5155. pageIdx: null,
  5156. matchIdx: null,
  5157. wrapped: false
  5158. };
  5159. this._extractTextPromises = [];
  5160. this._pageContents = [];
  5161. this._pageDiffs = [];
  5162. this._hasDiacritics = [];
  5163. this._matchesCountTotal = 0;
  5164. this._pagesToSearch = null;
  5165. this._pendingFindMatches = new Set();
  5166. this._resumePageIdx = null;
  5167. this._dirtyMatch = false;
  5168. clearTimeout(this._findTimeout);
  5169. this._findTimeout = null;
  5170. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  5171. }
  5172. get #query() {
  5173. if (this._state.query !== this._rawQuery) {
  5174. this._rawQuery = this._state.query;
  5175. [this._normalizedQuery] = normalize(this._state.query);
  5176. }
  5177. return this._normalizedQuery;
  5178. }
  5179. #shouldDirtyMatch(state) {
  5180. if (state.query !== this._state.query) {
  5181. return true;
  5182. }
  5183. switch (state.type) {
  5184. case "again":
  5185. const pageNumber = this._selected.pageIdx + 1;
  5186. const linkService = this._linkService;
  5187. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  5188. return true;
  5189. }
  5190. return false;
  5191. case "highlightallchange":
  5192. return false;
  5193. }
  5194. return true;
  5195. }
  5196. #isEntireWord(content, startIdx, length) {
  5197. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  5198. if (match) {
  5199. const first = content.charCodeAt(startIdx);
  5200. const limit = match[1].charCodeAt(0);
  5201. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5202. return false;
  5203. }
  5204. }
  5205. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  5206. if (match) {
  5207. const last = content.charCodeAt(startIdx + length - 1);
  5208. const limit = match[1].charCodeAt(0);
  5209. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5210. return false;
  5211. }
  5212. }
  5213. return true;
  5214. }
  5215. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  5216. const matches = this._pageMatches[pageIndex] = [];
  5217. const matchesLength = this._pageMatchesLength[pageIndex] = [];
  5218. if (!query) {
  5219. return;
  5220. }
  5221. const diffs = this._pageDiffs[pageIndex];
  5222. let match;
  5223. while ((match = query.exec(pageContent)) !== null) {
  5224. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  5225. continue;
  5226. }
  5227. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  5228. if (matchLen) {
  5229. matches.push(matchPos);
  5230. matchesLength.push(matchLen);
  5231. }
  5232. }
  5233. }
  5234. #convertToRegExpString(query, hasDiacritics) {
  5235. const {
  5236. matchDiacritics
  5237. } = this._state;
  5238. let isUnicode = false;
  5239. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5240. if (p1) {
  5241. return `[ ]*\\${p1}[ ]*`;
  5242. }
  5243. if (p2) {
  5244. return `[ ]*${p2}[ ]*`;
  5245. }
  5246. if (p3) {
  5247. return "[ ]+";
  5248. }
  5249. if (matchDiacritics) {
  5250. return p4 || p5;
  5251. }
  5252. if (p4) {
  5253. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5254. }
  5255. if (hasDiacritics) {
  5256. isUnicode = true;
  5257. return `${p5}\\p{M}*`;
  5258. }
  5259. return p5;
  5260. });
  5261. const trailingSpaces = "[ ]*";
  5262. if (query.endsWith(trailingSpaces)) {
  5263. query = query.slice(0, query.length - trailingSpaces.length);
  5264. }
  5265. if (matchDiacritics) {
  5266. if (hasDiacritics) {
  5267. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
  5268. isUnicode = true;
  5269. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5270. }
  5271. }
  5272. return [isUnicode, query];
  5273. }
  5274. #calculateMatch(pageIndex) {
  5275. let query = this.#query;
  5276. if (!query) {
  5277. return;
  5278. }
  5279. const {
  5280. caseSensitive,
  5281. entireWord,
  5282. phraseSearch
  5283. } = this._state;
  5284. const pageContent = this._pageContents[pageIndex];
  5285. const hasDiacritics = this._hasDiacritics[pageIndex];
  5286. let isUnicode = false;
  5287. if (phraseSearch) {
  5288. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5289. } else {
  5290. const match = query.match(/\S+/g);
  5291. if (match) {
  5292. query = match.sort().reverse().map(q => {
  5293. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5294. isUnicode ||= isUnicodePart;
  5295. return `(${queryPart})`;
  5296. }).join("|");
  5297. }
  5298. }
  5299. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5300. query = query ? new RegExp(query, flags) : null;
  5301. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  5302. if (this._state.highlightAll) {
  5303. this.#updatePage(pageIndex);
  5304. }
  5305. if (this._resumePageIdx === pageIndex) {
  5306. this._resumePageIdx = null;
  5307. this.#nextPageMatch();
  5308. }
  5309. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5310. this._matchesCountTotal += pageMatchesCount;
  5311. if (this.#updateMatchesCountOnProgress) {
  5312. if (pageMatchesCount > 0) {
  5313. this.#updateUIResultsCount();
  5314. }
  5315. } else if (++this.#visitedPagesCount === this._linkService.pagesCount) {
  5316. this.#updateUIResultsCount();
  5317. }
  5318. }
  5319. #extractText() {
  5320. if (this._extractTextPromises.length > 0) {
  5321. return;
  5322. }
  5323. let promise = Promise.resolve();
  5324. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5325. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  5326. this._extractTextPromises[i] = extractTextCapability.promise;
  5327. promise = promise.then(() => {
  5328. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5329. return pdfPage.getTextContent();
  5330. }).then(textContent => {
  5331. const strBuf = [];
  5332. for (const textItem of textContent.items) {
  5333. strBuf.push(textItem.str);
  5334. if (textItem.hasEOL) {
  5335. strBuf.push("\n");
  5336. }
  5337. }
  5338. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5339. extractTextCapability.resolve();
  5340. }, reason => {
  5341. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5342. this._pageContents[i] = "";
  5343. this._pageDiffs[i] = null;
  5344. this._hasDiacritics[i] = false;
  5345. extractTextCapability.resolve();
  5346. });
  5347. });
  5348. }
  5349. }
  5350. #updatePage(index) {
  5351. if (this._scrollMatches && this._selected.pageIdx === index) {
  5352. this._linkService.page = index + 1;
  5353. }
  5354. this._eventBus.dispatch("updatetextlayermatches", {
  5355. source: this,
  5356. pageIndex: index
  5357. });
  5358. }
  5359. #updateAllPages() {
  5360. this._eventBus.dispatch("updatetextlayermatches", {
  5361. source: this,
  5362. pageIndex: -1
  5363. });
  5364. }
  5365. #nextMatch() {
  5366. const previous = this._state.findPrevious;
  5367. const currentPageIndex = this._linkService.page - 1;
  5368. const numPages = this._linkService.pagesCount;
  5369. this._highlightMatches = true;
  5370. if (this._dirtyMatch) {
  5371. this._dirtyMatch = false;
  5372. this._selected.pageIdx = this._selected.matchIdx = -1;
  5373. this._offset.pageIdx = currentPageIndex;
  5374. this._offset.matchIdx = null;
  5375. this._offset.wrapped = false;
  5376. this._resumePageIdx = null;
  5377. this._pageMatches.length = 0;
  5378. this._pageMatchesLength.length = 0;
  5379. this.#visitedPagesCount = 0;
  5380. this._matchesCountTotal = 0;
  5381. this.#updateAllPages();
  5382. for (let i = 0; i < numPages; i++) {
  5383. if (this._pendingFindMatches.has(i)) {
  5384. continue;
  5385. }
  5386. this._pendingFindMatches.add(i);
  5387. this._extractTextPromises[i].then(() => {
  5388. this._pendingFindMatches.delete(i);
  5389. this.#calculateMatch(i);
  5390. });
  5391. }
  5392. }
  5393. if (!this.#query) {
  5394. this.#updateUIState(FindState.FOUND);
  5395. return;
  5396. }
  5397. if (this._resumePageIdx) {
  5398. return;
  5399. }
  5400. const offset = this._offset;
  5401. this._pagesToSearch = numPages;
  5402. if (offset.matchIdx !== null) {
  5403. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5404. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5405. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5406. this.#updateMatch(true);
  5407. return;
  5408. }
  5409. this.#advanceOffsetPage(previous);
  5410. }
  5411. this.#nextPageMatch();
  5412. }
  5413. #matchesReady(matches) {
  5414. const offset = this._offset;
  5415. const numMatches = matches.length;
  5416. const previous = this._state.findPrevious;
  5417. if (numMatches) {
  5418. offset.matchIdx = previous ? numMatches - 1 : 0;
  5419. this.#updateMatch(true);
  5420. return true;
  5421. }
  5422. this.#advanceOffsetPage(previous);
  5423. if (offset.wrapped) {
  5424. offset.matchIdx = null;
  5425. if (this._pagesToSearch < 0) {
  5426. this.#updateMatch(false);
  5427. return true;
  5428. }
  5429. }
  5430. return false;
  5431. }
  5432. #nextPageMatch() {
  5433. if (this._resumePageIdx !== null) {
  5434. console.error("There can only be one pending page.");
  5435. }
  5436. let matches = null;
  5437. do {
  5438. const pageIdx = this._offset.pageIdx;
  5439. matches = this._pageMatches[pageIdx];
  5440. if (!matches) {
  5441. this._resumePageIdx = pageIdx;
  5442. break;
  5443. }
  5444. } while (!this.#matchesReady(matches));
  5445. }
  5446. #advanceOffsetPage(previous) {
  5447. const offset = this._offset;
  5448. const numPages = this._linkService.pagesCount;
  5449. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5450. offset.matchIdx = null;
  5451. this._pagesToSearch--;
  5452. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5453. offset.pageIdx = previous ? numPages - 1 : 0;
  5454. offset.wrapped = true;
  5455. }
  5456. }
  5457. #updateMatch(found = false) {
  5458. let state = FindState.NOT_FOUND;
  5459. const wrapped = this._offset.wrapped;
  5460. this._offset.wrapped = false;
  5461. if (found) {
  5462. const previousPage = this._selected.pageIdx;
  5463. this._selected.pageIdx = this._offset.pageIdx;
  5464. this._selected.matchIdx = this._offset.matchIdx;
  5465. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5466. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5467. this.#updatePage(previousPage);
  5468. }
  5469. }
  5470. this.#updateUIState(state, this._state.findPrevious);
  5471. if (this._selected.pageIdx !== -1) {
  5472. this._scrollMatches = true;
  5473. this.#updatePage(this._selected.pageIdx);
  5474. }
  5475. }
  5476. #onFindBarClose(evt) {
  5477. const pdfDocument = this._pdfDocument;
  5478. this._firstPageCapability.promise.then(() => {
  5479. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5480. return;
  5481. }
  5482. if (this._findTimeout) {
  5483. clearTimeout(this._findTimeout);
  5484. this._findTimeout = null;
  5485. }
  5486. if (this._resumePageIdx) {
  5487. this._resumePageIdx = null;
  5488. this._dirtyMatch = true;
  5489. }
  5490. this.#updateUIState(FindState.FOUND);
  5491. this._highlightMatches = false;
  5492. this.#updateAllPages();
  5493. });
  5494. }
  5495. #requestMatchesCount() {
  5496. const {
  5497. pageIdx,
  5498. matchIdx
  5499. } = this._selected;
  5500. let current = 0,
  5501. total = this._matchesCountTotal;
  5502. if (matchIdx !== -1) {
  5503. for (let i = 0; i < pageIdx; i++) {
  5504. current += this._pageMatches[i]?.length || 0;
  5505. }
  5506. current += matchIdx + 1;
  5507. }
  5508. if (current < 1 || current > total) {
  5509. current = total = 0;
  5510. }
  5511. return {
  5512. current,
  5513. total
  5514. };
  5515. }
  5516. #updateUIResultsCount() {
  5517. this._eventBus.dispatch("updatefindmatchescount", {
  5518. source: this,
  5519. matchesCount: this.#requestMatchesCount()
  5520. });
  5521. }
  5522. #updateUIState(state, previous = false) {
  5523. if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) {
  5524. return;
  5525. }
  5526. this._eventBus.dispatch("updatefindcontrolstate", {
  5527. source: this,
  5528. state,
  5529. previous,
  5530. matchesCount: this.#requestMatchesCount(),
  5531. rawQuery: this._state?.query ?? null
  5532. });
  5533. }
  5534. }
  5535. exports.PDFFindController = PDFFindController;
  5536. /***/
  5537. }),
  5538. /* 17 */
  5539. /***/ ((__unused_webpack_module, exports) => {
  5540. Object.defineProperty(exports, "__esModule", ({
  5541. value: true
  5542. }));
  5543. exports.CharacterType = void 0;
  5544. exports.getCharacterType = getCharacterType;
  5545. const CharacterType = {
  5546. SPACE: 0,
  5547. ALPHA_LETTER: 1,
  5548. PUNCT: 2,
  5549. HAN_LETTER: 3,
  5550. KATAKANA_LETTER: 4,
  5551. HIRAGANA_LETTER: 5,
  5552. HALFWIDTH_KATAKANA_LETTER: 6,
  5553. THAI_LETTER: 7
  5554. };
  5555. exports.CharacterType = CharacterType;
  5556. function isAlphabeticalScript(charCode) {
  5557. return charCode < 0x2e80;
  5558. }
  5559. function isAscii(charCode) {
  5560. return (charCode & 0xff80) === 0;
  5561. }
  5562. function isAsciiAlpha(charCode) {
  5563. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5564. }
  5565. function isAsciiDigit(charCode) {
  5566. return charCode >= 0x30 && charCode <= 0x39;
  5567. }
  5568. function isAsciiSpace(charCode) {
  5569. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5570. }
  5571. function isHan(charCode) {
  5572. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5573. }
  5574. function isKatakana(charCode) {
  5575. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5576. }
  5577. function isHiragana(charCode) {
  5578. return charCode >= 0x3040 && charCode <= 0x309f;
  5579. }
  5580. function isHalfwidthKatakana(charCode) {
  5581. return charCode >= 0xff60 && charCode <= 0xff9f;
  5582. }
  5583. function isThai(charCode) {
  5584. return (charCode & 0xff80) === 0x0e00;
  5585. }
  5586. function getCharacterType(charCode) {
  5587. if (isAlphabeticalScript(charCode)) {
  5588. if (isAscii(charCode)) {
  5589. if (isAsciiSpace(charCode)) {
  5590. return CharacterType.SPACE;
  5591. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5592. return CharacterType.ALPHA_LETTER;
  5593. }
  5594. return CharacterType.PUNCT;
  5595. } else if (isThai(charCode)) {
  5596. return CharacterType.THAI_LETTER;
  5597. } else if (charCode === 0xa0) {
  5598. return CharacterType.SPACE;
  5599. }
  5600. return CharacterType.ALPHA_LETTER;
  5601. }
  5602. if (isHan(charCode)) {
  5603. return CharacterType.HAN_LETTER;
  5604. } else if (isKatakana(charCode)) {
  5605. return CharacterType.KATAKANA_LETTER;
  5606. } else if (isHiragana(charCode)) {
  5607. return CharacterType.HIRAGANA_LETTER;
  5608. } else if (isHalfwidthKatakana(charCode)) {
  5609. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5610. }
  5611. return CharacterType.ALPHA_LETTER;
  5612. }
  5613. /***/
  5614. }),
  5615. /* 18 */
  5616. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5617. Object.defineProperty(exports, "__esModule", ({
  5618. value: true
  5619. }));
  5620. exports.PDFHistory = void 0;
  5621. exports.isDestArraysEqual = isDestArraysEqual;
  5622. exports.isDestHashesEqual = isDestHashesEqual;
  5623. var _ui_utils = __webpack_require__(1);
  5624. var _event_utils = __webpack_require__(6);
  5625. const HASH_CHANGE_TIMEOUT = 1000;
  5626. const POSITION_UPDATED_THRESHOLD = 50;
  5627. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5628. function getCurrentHash() {
  5629. return document.location.hash;
  5630. }
  5631. class PDFHistory {
  5632. constructor({
  5633. linkService,
  5634. eventBus
  5635. }) {
  5636. this.linkService = linkService;
  5637. this.eventBus = eventBus;
  5638. this._initialized = false;
  5639. this._fingerprint = "";
  5640. this.reset();
  5641. this._boundEvents = null;
  5642. this.eventBus._on("pagesinit", () => {
  5643. this._isPagesLoaded = false;
  5644. this.eventBus._on("pagesloaded", evt => {
  5645. this._isPagesLoaded = !!evt.pagesCount;
  5646. }, {
  5647. once: true
  5648. });
  5649. });
  5650. }
  5651. initialize({
  5652. fingerprint,
  5653. resetHistory = false,
  5654. updateUrl = false
  5655. }) {
  5656. if (!fingerprint || typeof fingerprint !== "string") {
  5657. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5658. return;
  5659. }
  5660. if (this._initialized) {
  5661. this.reset();
  5662. }
  5663. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5664. this._fingerprint = fingerprint;
  5665. this._updateUrl = updateUrl === true;
  5666. this._initialized = true;
  5667. this._bindEvents();
  5668. const state = window.history.state;
  5669. this._popStateInProgress = false;
  5670. this._blockHashChange = 0;
  5671. this._currentHash = getCurrentHash();
  5672. this._numPositionUpdates = 0;
  5673. this._uid = this._maxUid = 0;
  5674. this._destination = null;
  5675. this._position = null;
  5676. if (!this._isValidState(state, true) || resetHistory) {
  5677. const {
  5678. hash,
  5679. page,
  5680. rotation
  5681. } = this._parseCurrentHash(true);
  5682. if (!hash || reInitialized || resetHistory) {
  5683. this._pushOrReplaceState(null, true);
  5684. return;
  5685. }
  5686. this._pushOrReplaceState({
  5687. hash,
  5688. page,
  5689. rotation
  5690. }, true);
  5691. return;
  5692. }
  5693. const destination = state.destination;
  5694. this._updateInternalState(destination, state.uid, true);
  5695. if (destination.rotation !== undefined) {
  5696. this._initialRotation = destination.rotation;
  5697. }
  5698. if (destination.dest) {
  5699. this._initialBookmark = JSON.stringify(destination.dest);
  5700. this._destination.page = null;
  5701. } else if (destination.hash) {
  5702. this._initialBookmark = destination.hash;
  5703. } else if (destination.page) {
  5704. this._initialBookmark = `page=${destination.page}`;
  5705. }
  5706. }
  5707. reset() {
  5708. if (this._initialized) {
  5709. this._pageHide();
  5710. this._initialized = false;
  5711. this._unbindEvents();
  5712. }
  5713. if (this._updateViewareaTimeout) {
  5714. clearTimeout(this._updateViewareaTimeout);
  5715. this._updateViewareaTimeout = null;
  5716. }
  5717. this._initialBookmark = null;
  5718. this._initialRotation = null;
  5719. }
  5720. push({
  5721. namedDest = null,
  5722. explicitDest,
  5723. pageNumber
  5724. }) {
  5725. if (!this._initialized) {
  5726. return;
  5727. }
  5728. if (namedDest && typeof namedDest !== "string") {
  5729. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5730. return;
  5731. } else if (!Array.isArray(explicitDest)) {
  5732. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5733. return;
  5734. } else if (!this._isValidPage(pageNumber)) {
  5735. if (pageNumber !== null || this._destination) {
  5736. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5737. return;
  5738. }
  5739. }
  5740. var hash = namedDest || JSON.stringify(explicitDest);
  5741. if (!hash) {
  5742. return;
  5743. }
  5744. let forceReplace = false;
  5745. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5746. if (this._destination.page) {
  5747. return;
  5748. }
  5749. forceReplace = true;
  5750. }
  5751. if (this._popStateInProgress && !forceReplace) {
  5752. return;
  5753. }
  5754. this._pushOrReplaceState({
  5755. dest: explicitDest,
  5756. hash,
  5757. page: pageNumber,
  5758. rotation: this.linkService.rotation
  5759. }, forceReplace);
  5760. if (!this._popStateInProgress) {
  5761. this._popStateInProgress = true;
  5762. Promise.resolve().then(() => {
  5763. this._popStateInProgress = false;
  5764. });
  5765. }
  5766. }
  5767. pushPage(pageNumber) {
  5768. if (!this._initialized) {
  5769. return;
  5770. }
  5771. if (!this._isValidPage(pageNumber)) {
  5772. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5773. return;
  5774. }
  5775. if (this._destination?.page === pageNumber) {
  5776. return;
  5777. }
  5778. if (this._popStateInProgress) {
  5779. return;
  5780. }
  5781. this._pushOrReplaceState({
  5782. dest: null,
  5783. hash: `page=${pageNumber}`,
  5784. page: pageNumber,
  5785. rotation: this.linkService.rotation
  5786. });
  5787. if (!this._popStateInProgress) {
  5788. this._popStateInProgress = true;
  5789. Promise.resolve().then(() => {
  5790. this._popStateInProgress = false;
  5791. });
  5792. }
  5793. }
  5794. pushCurrentPosition() {
  5795. if (!this._initialized || this._popStateInProgress) {
  5796. return;
  5797. }
  5798. this._tryPushCurrentPosition();
  5799. }
  5800. back() {
  5801. if (!this._initialized || this._popStateInProgress) {
  5802. return;
  5803. }
  5804. const state = window.history.state;
  5805. if (this._isValidState(state) && state.uid > 0) {
  5806. window.history.back();
  5807. }
  5808. }
  5809. forward() {
  5810. if (!this._initialized || this._popStateInProgress) {
  5811. return;
  5812. }
  5813. const state = window.history.state;
  5814. if (this._isValidState(state) && state.uid < this._maxUid) {
  5815. window.history.forward();
  5816. }
  5817. }
  5818. get popStateInProgress() {
  5819. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5820. }
  5821. get initialBookmark() {
  5822. return this._initialized ? this._initialBookmark : null;
  5823. }
  5824. get initialRotation() {
  5825. return this._initialized ? this._initialRotation : null;
  5826. }
  5827. _pushOrReplaceState(destination, forceReplace = false) {
  5828. const shouldReplace = forceReplace || !this._destination;
  5829. const newState = {
  5830. fingerprint: this._fingerprint,
  5831. uid: shouldReplace ? this._uid : this._uid + 1,
  5832. destination
  5833. };
  5834. this._updateInternalState(destination, newState.uid);
  5835. let newUrl;
  5836. if (this._updateUrl && destination?.hash) {
  5837. const baseUrl = document.location.href.split("#")[0];
  5838. if (!baseUrl.startsWith("file://")) {
  5839. newUrl = `${baseUrl}#${destination.hash}`;
  5840. }
  5841. }
  5842. if (shouldReplace) {
  5843. window.history.replaceState(newState, "", newUrl);
  5844. } else {
  5845. window.history.pushState(newState, "", newUrl);
  5846. }
  5847. }
  5848. _tryPushCurrentPosition(temporary = false) {
  5849. if (!this._position) {
  5850. return;
  5851. }
  5852. let position = this._position;
  5853. if (temporary) {
  5854. position = Object.assign(Object.create(null), this._position);
  5855. position.temporary = true;
  5856. }
  5857. if (!this._destination) {
  5858. this._pushOrReplaceState(position);
  5859. return;
  5860. }
  5861. if (this._destination.temporary) {
  5862. this._pushOrReplaceState(position, true);
  5863. return;
  5864. }
  5865. if (this._destination.hash === position.hash) {
  5866. return;
  5867. }
  5868. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5869. return;
  5870. }
  5871. let forceReplace = false;
  5872. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5873. if (this._destination.dest !== undefined || !this._destination.first) {
  5874. return;
  5875. }
  5876. forceReplace = true;
  5877. }
  5878. this._pushOrReplaceState(position, forceReplace);
  5879. }
  5880. _isValidPage(val) {
  5881. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5882. }
  5883. _isValidState(state, checkReload = false) {
  5884. if (!state) {
  5885. return false;
  5886. }
  5887. if (state.fingerprint !== this._fingerprint) {
  5888. if (checkReload) {
  5889. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5890. return false;
  5891. }
  5892. const [perfEntry] = performance.getEntriesByType("navigation");
  5893. if (perfEntry?.type !== "reload") {
  5894. return false;
  5895. }
  5896. } else {
  5897. return false;
  5898. }
  5899. }
  5900. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5901. return false;
  5902. }
  5903. if (state.destination === null || typeof state.destination !== "object") {
  5904. return false;
  5905. }
  5906. return true;
  5907. }
  5908. _updateInternalState(destination, uid, removeTemporary = false) {
  5909. if (this._updateViewareaTimeout) {
  5910. clearTimeout(this._updateViewareaTimeout);
  5911. this._updateViewareaTimeout = null;
  5912. }
  5913. if (removeTemporary && destination?.temporary) {
  5914. delete destination.temporary;
  5915. }
  5916. this._destination = destination;
  5917. this._uid = uid;
  5918. this._maxUid = Math.max(this._maxUid, uid);
  5919. this._numPositionUpdates = 0;
  5920. }
  5921. _parseCurrentHash(checkNameddest = false) {
  5922. var hash = unescape(getCurrentHash()).substring(1);
  5923. const params = (0, _ui_utils.parseQueryString)(hash);
  5924. const nameddest = params.get("nameddest") || "";
  5925. let page = params.get("page") | 0;
  5926. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5927. page = null;
  5928. }
  5929. return {
  5930. hash,
  5931. page,
  5932. rotation: this.linkService.rotation
  5933. };
  5934. }
  5935. _updateViewarea({
  5936. location
  5937. }) {
  5938. if (this._updateViewareaTimeout) {
  5939. clearTimeout(this._updateViewareaTimeout);
  5940. this._updateViewareaTimeout = null;
  5941. }
  5942. this._position = {
  5943. hash: location.pdfOpenParams.substring(1),
  5944. page: this.linkService.page,
  5945. first: location.pageNumber,
  5946. rotation: location.rotation
  5947. };
  5948. if (this._popStateInProgress) {
  5949. return;
  5950. }
  5951. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5952. this._numPositionUpdates++;
  5953. }
  5954. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5955. this._updateViewareaTimeout = setTimeout(() => {
  5956. if (!this._popStateInProgress) {
  5957. this._tryPushCurrentPosition(true);
  5958. }
  5959. this._updateViewareaTimeout = null;
  5960. }, UPDATE_VIEWAREA_TIMEOUT);
  5961. }
  5962. }
  5963. _popState({
  5964. state
  5965. }) {
  5966. const newHash = getCurrentHash(),
  5967. hashChanged = this._currentHash !== newHash;
  5968. this._currentHash = newHash;
  5969. if (!state) {
  5970. this._uid++;
  5971. const {
  5972. hash,
  5973. page,
  5974. rotation
  5975. } = this._parseCurrentHash();
  5976. this._pushOrReplaceState({
  5977. hash,
  5978. page,
  5979. rotation
  5980. }, true);
  5981. return;
  5982. }
  5983. if (!this._isValidState(state)) {
  5984. return;
  5985. }
  5986. this._popStateInProgress = true;
  5987. if (hashChanged) {
  5988. this._blockHashChange++;
  5989. (0, _event_utils.waitOnEventOrTimeout)({
  5990. target: window,
  5991. name: "hashchange",
  5992. delay: HASH_CHANGE_TIMEOUT
  5993. }).then(() => {
  5994. this._blockHashChange--;
  5995. });
  5996. }
  5997. const destination = state.destination;
  5998. this._updateInternalState(destination, state.uid, true);
  5999. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  6000. this.linkService.rotation = destination.rotation;
  6001. }
  6002. if (destination.dest) {
  6003. this.linkService.goToDestination(destination.dest);
  6004. } else if (destination.hash) {
  6005. this.linkService.setHash(destination.hash);
  6006. } else if (destination.page) {
  6007. this.linkService.page = destination.page;
  6008. }
  6009. Promise.resolve().then(() => {
  6010. this._popStateInProgress = false;
  6011. });
  6012. }
  6013. _pageHide() {
  6014. if (!this._destination || this._destination.temporary) {
  6015. this._tryPushCurrentPosition();
  6016. }
  6017. }
  6018. _bindEvents() {
  6019. if (this._boundEvents) {
  6020. return;
  6021. }
  6022. this._boundEvents = {
  6023. updateViewarea: this._updateViewarea.bind(this),
  6024. popState: this._popState.bind(this),
  6025. pageHide: this._pageHide.bind(this)
  6026. };
  6027. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  6028. window.addEventListener("popstate", this._boundEvents.popState);
  6029. window.addEventListener("pagehide", this._boundEvents.pageHide);
  6030. }
  6031. _unbindEvents() {
  6032. if (!this._boundEvents) {
  6033. return;
  6034. }
  6035. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  6036. window.removeEventListener("popstate", this._boundEvents.popState);
  6037. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  6038. this._boundEvents = null;
  6039. }
  6040. }
  6041. exports.PDFHistory = PDFHistory;
  6042. function isDestHashesEqual(destHash, pushHash) {
  6043. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  6044. return false;
  6045. }
  6046. if (destHash === pushHash) {
  6047. return true;
  6048. }
  6049. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  6050. if (nameddest === pushHash) {
  6051. return true;
  6052. }
  6053. return false;
  6054. }
  6055. function isDestArraysEqual(firstDest, secondDest) {
  6056. function isEntryEqual(first, second) {
  6057. if (typeof first !== typeof second) {
  6058. return false;
  6059. }
  6060. if (Array.isArray(first) || Array.isArray(second)) {
  6061. return false;
  6062. }
  6063. if (first !== null && typeof first === "object" && second !== null) {
  6064. if (Object.keys(first).length !== Object.keys(second).length) {
  6065. return false;
  6066. }
  6067. for (const key in first) {
  6068. if (!isEntryEqual(first[key], second[key])) {
  6069. return false;
  6070. }
  6071. }
  6072. return true;
  6073. }
  6074. return first === second || Number.isNaN(first) && Number.isNaN(second);
  6075. }
  6076. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  6077. return false;
  6078. }
  6079. if (firstDest.length !== secondDest.length) {
  6080. return false;
  6081. }
  6082. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  6083. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  6084. return false;
  6085. }
  6086. }
  6087. return true;
  6088. }
  6089. /***/
  6090. }),
  6091. /* 19 */
  6092. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6093. Object.defineProperty(exports, "__esModule", ({
  6094. value: true
  6095. }));
  6096. exports.PDFLayerViewer = void 0;
  6097. var _base_tree_viewer = __webpack_require__(13);
  6098. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  6099. constructor(options) {
  6100. super(options);
  6101. this.l10n = options.l10n;
  6102. this.eventBus._on("optionalcontentconfigchanged", evt => {
  6103. this.#updateLayers(evt.promise);
  6104. });
  6105. this.eventBus._on("resetlayers", () => {
  6106. this.#updateLayers();
  6107. });
  6108. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  6109. }
  6110. reset() {
  6111. super.reset();
  6112. this._optionalContentConfig = null;
  6113. this._optionalContentHash = null;
  6114. }
  6115. _dispatchEvent(layersCount) {
  6116. this.eventBus.dispatch("layersloaded", {
  6117. source: this,
  6118. layersCount
  6119. });
  6120. }
  6121. _bindLink(element, {
  6122. groupId,
  6123. input
  6124. }) {
  6125. const setVisibility = () => {
  6126. this._optionalContentConfig.setVisibility(groupId, input.checked);
  6127. this._optionalContentHash = this._optionalContentConfig.getHash();
  6128. this.eventBus.dispatch("optionalcontentconfig", {
  6129. source: this,
  6130. promise: Promise.resolve(this._optionalContentConfig)
  6131. });
  6132. };
  6133. element.onclick = evt => {
  6134. if (evt.target === input) {
  6135. setVisibility();
  6136. return true;
  6137. } else if (evt.target !== element) {
  6138. return true;
  6139. }
  6140. input.checked = !input.checked;
  6141. setVisibility();
  6142. return false;
  6143. };
  6144. }
  6145. async _setNestedName(element, {
  6146. name = null
  6147. }) {
  6148. if (typeof name === "string") {
  6149. element.textContent = this._normalizeTextContent(name);
  6150. return;
  6151. }
  6152. element.textContent = await this.l10n.get("additional_layers");
  6153. element.style.fontStyle = "italic";
  6154. }
  6155. _addToggleButton(div, {
  6156. name = null
  6157. }) {
  6158. super._addToggleButton(div, name === null);
  6159. }
  6160. _toggleAllTreeItems() {
  6161. if (!this._optionalContentConfig) {
  6162. return;
  6163. }
  6164. super._toggleAllTreeItems();
  6165. }
  6166. render({
  6167. optionalContentConfig,
  6168. pdfDocument
  6169. }) {
  6170. if (this._optionalContentConfig) {
  6171. this.reset();
  6172. }
  6173. this._optionalContentConfig = optionalContentConfig || null;
  6174. this._pdfDocument = pdfDocument || null;
  6175. const groups = optionalContentConfig?.getOrder();
  6176. if (!groups) {
  6177. this._dispatchEvent(0);
  6178. return;
  6179. }
  6180. this._optionalContentHash = optionalContentConfig.getHash();
  6181. const fragment = document.createDocumentFragment(),
  6182. queue = [{
  6183. parent: fragment,
  6184. groups
  6185. }];
  6186. let layersCount = 0,
  6187. hasAnyNesting = false;
  6188. while (queue.length > 0) {
  6189. const levelData = queue.shift();
  6190. for (const groupId of levelData.groups) {
  6191. const div = document.createElement("div");
  6192. div.className = "treeItem";
  6193. const element = document.createElement("a");
  6194. div.append(element);
  6195. if (typeof groupId === "object") {
  6196. hasAnyNesting = true;
  6197. this._addToggleButton(div, groupId);
  6198. this._setNestedName(element, groupId);
  6199. const itemsDiv = document.createElement("div");
  6200. itemsDiv.className = "treeItems";
  6201. div.append(itemsDiv);
  6202. queue.push({
  6203. parent: itemsDiv,
  6204. groups: groupId.order
  6205. });
  6206. } else {
  6207. const group = optionalContentConfig.getGroup(groupId);
  6208. const input = document.createElement("input");
  6209. this._bindLink(element, {
  6210. groupId,
  6211. input
  6212. });
  6213. input.type = "checkbox";
  6214. input.checked = group.visible;
  6215. const label = document.createElement("label");
  6216. label.textContent = this._normalizeTextContent(group.name);
  6217. label.append(input);
  6218. element.append(label);
  6219. layersCount++;
  6220. }
  6221. levelData.parent.append(div);
  6222. }
  6223. }
  6224. this._finishRendering(fragment, layersCount, hasAnyNesting);
  6225. }
  6226. async #updateLayers(promise = null) {
  6227. if (!this._optionalContentConfig) {
  6228. return;
  6229. }
  6230. const pdfDocument = this._pdfDocument;
  6231. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig());
  6232. if (pdfDocument !== this._pdfDocument) {
  6233. return;
  6234. }
  6235. if (promise) {
  6236. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  6237. return;
  6238. }
  6239. } else {
  6240. this.eventBus.dispatch("optionalcontentconfig", {
  6241. source: this,
  6242. promise: Promise.resolve(optionalContentConfig)
  6243. });
  6244. }
  6245. this.render({
  6246. optionalContentConfig,
  6247. pdfDocument: this._pdfDocument
  6248. });
  6249. }
  6250. }
  6251. exports.PDFLayerViewer = PDFLayerViewer;
  6252. /***/
  6253. }),
  6254. /* 20 */
  6255. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6256. Object.defineProperty(exports, "__esModule", ({
  6257. value: true
  6258. }));
  6259. exports.PDFOutlineViewer = void 0;
  6260. var _base_tree_viewer = __webpack_require__(13);
  6261. var _pdfjsLib = __webpack_require__(5);
  6262. var _ui_utils = __webpack_require__(1);
  6263. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  6264. constructor(options) {
  6265. super(options);
  6266. this.linkService = options.linkService;
  6267. this.downloadManager = options.downloadManager;
  6268. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6269. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6270. this.eventBus._on("pagechanging", evt => {
  6271. this._currentPageNumber = evt.pageNumber;
  6272. });
  6273. this.eventBus._on("pagesloaded", evt => {
  6274. this._isPagesLoaded = !!evt.pagesCount;
  6275. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6276. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6277. }
  6278. });
  6279. this.eventBus._on("sidebarviewchanged", evt => {
  6280. this._sidebarView = evt.view;
  6281. });
  6282. }
  6283. reset() {
  6284. super.reset();
  6285. this._outline = null;
  6286. this._pageNumberToDestHashCapability = null;
  6287. this._currentPageNumber = 1;
  6288. this._isPagesLoaded = null;
  6289. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6290. this._currentOutlineItemCapability.resolve(false);
  6291. }
  6292. this._currentOutlineItemCapability = null;
  6293. }
  6294. _dispatchEvent(outlineCount) {
  6295. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  6296. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  6297. this._currentOutlineItemCapability.resolve(false);
  6298. } else if (this._isPagesLoaded !== null) {
  6299. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6300. }
  6301. this.eventBus.dispatch("outlineloaded", {
  6302. source: this,
  6303. outlineCount,
  6304. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6305. });
  6306. }
  6307. _bindLink(element, {
  6308. url,
  6309. newWindow,
  6310. action,
  6311. attachment,
  6312. dest,
  6313. setOCGState
  6314. }) {
  6315. const {
  6316. linkService
  6317. } = this;
  6318. if (url) {
  6319. linkService.addLinkAttributes(element, url, newWindow);
  6320. return;
  6321. }
  6322. if (action) {
  6323. element.href = linkService.getAnchorUrl("");
  6324. element.onclick = () => {
  6325. linkService.executeNamedAction(action);
  6326. return false;
  6327. };
  6328. return;
  6329. }
  6330. if (attachment) {
  6331. element.href = linkService.getAnchorUrl("");
  6332. element.onclick = () => {
  6333. this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename);
  6334. return false;
  6335. };
  6336. return;
  6337. }
  6338. if (setOCGState) {
  6339. element.href = linkService.getAnchorUrl("");
  6340. element.onclick = () => {
  6341. linkService.executeSetOCGState(setOCGState);
  6342. return false;
  6343. };
  6344. return;
  6345. }
  6346. element.href = linkService.getDestinationHash(dest);
  6347. element.onclick = evt => {
  6348. this._updateCurrentTreeItem(evt.target.parentNode);
  6349. if (dest) {
  6350. linkService.goToDestination(dest);
  6351. }
  6352. return false;
  6353. };
  6354. }
  6355. _setStyles(element, {
  6356. bold,
  6357. italic
  6358. }) {
  6359. if (bold) {
  6360. element.style.fontWeight = "bold";
  6361. }
  6362. if (italic) {
  6363. element.style.fontStyle = "italic";
  6364. }
  6365. }
  6366. _addToggleButton(div, {
  6367. count,
  6368. items
  6369. }) {
  6370. let hidden = false;
  6371. if (count < 0) {
  6372. let totalCount = items.length;
  6373. if (totalCount > 0) {
  6374. const queue = [...items];
  6375. while (queue.length > 0) {
  6376. const {
  6377. count: nestedCount,
  6378. items: nestedItems
  6379. } = queue.shift();
  6380. if (nestedCount > 0 && nestedItems.length > 0) {
  6381. totalCount += nestedItems.length;
  6382. queue.push(...nestedItems);
  6383. }
  6384. }
  6385. }
  6386. if (Math.abs(count) === totalCount) {
  6387. hidden = true;
  6388. }
  6389. }
  6390. super._addToggleButton(div, hidden);
  6391. }
  6392. _toggleAllTreeItems() {
  6393. if (!this._outline) {
  6394. return;
  6395. }
  6396. super._toggleAllTreeItems();
  6397. }
  6398. render({
  6399. outline,
  6400. pdfDocument
  6401. }) {
  6402. if (this._outline) {
  6403. this.reset();
  6404. }
  6405. this._outline = outline || null;
  6406. this._pdfDocument = pdfDocument || null;
  6407. if (!outline) {
  6408. this._dispatchEvent(0);
  6409. return;
  6410. }
  6411. const fragment = document.createDocumentFragment();
  6412. const queue = [{
  6413. parent: fragment,
  6414. items: outline
  6415. }];
  6416. let outlineCount = 0,
  6417. hasAnyNesting = false;
  6418. while (queue.length > 0) {
  6419. const levelData = queue.shift();
  6420. for (const item of levelData.items) {
  6421. const div = document.createElement("div");
  6422. div.className = "treeItem";
  6423. const element = document.createElement("a");
  6424. this._bindLink(element, item);
  6425. this._setStyles(element, item);
  6426. element.textContent = this._normalizeTextContent(item.title);
  6427. div.append(element);
  6428. if (item.items.length > 0) {
  6429. hasAnyNesting = true;
  6430. this._addToggleButton(div, item);
  6431. const itemsDiv = document.createElement("div");
  6432. itemsDiv.className = "treeItems";
  6433. div.append(itemsDiv);
  6434. queue.push({
  6435. parent: itemsDiv,
  6436. items: item.items
  6437. });
  6438. }
  6439. levelData.parent.append(div);
  6440. outlineCount++;
  6441. }
  6442. }
  6443. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6444. }
  6445. async _currentOutlineItem() {
  6446. if (!this._isPagesLoaded) {
  6447. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6448. }
  6449. if (!this._outline || !this._pdfDocument) {
  6450. return;
  6451. }
  6452. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6453. if (!pageNumberToDestHash) {
  6454. return;
  6455. }
  6456. this._updateCurrentTreeItem(null);
  6457. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6458. return;
  6459. }
  6460. for (let i = this._currentPageNumber; i > 0; i--) {
  6461. const destHash = pageNumberToDestHash.get(i);
  6462. if (!destHash) {
  6463. continue;
  6464. }
  6465. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6466. if (!linkElement) {
  6467. continue;
  6468. }
  6469. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6470. break;
  6471. }
  6472. }
  6473. async _getPageNumberToDestHash(pdfDocument) {
  6474. if (this._pageNumberToDestHashCapability) {
  6475. return this._pageNumberToDestHashCapability.promise;
  6476. }
  6477. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6478. const pageNumberToDestHash = new Map(),
  6479. pageNumberNesting = new Map();
  6480. const queue = [{
  6481. nesting: 0,
  6482. items: this._outline
  6483. }];
  6484. while (queue.length > 0) {
  6485. const levelData = queue.shift(),
  6486. currentNesting = levelData.nesting;
  6487. for (const {
  6488. dest,
  6489. items
  6490. } of levelData.items) {
  6491. let explicitDest, pageNumber;
  6492. if (typeof dest === "string") {
  6493. explicitDest = await pdfDocument.getDestination(dest);
  6494. if (pdfDocument !== this._pdfDocument) {
  6495. return null;
  6496. }
  6497. } else {
  6498. explicitDest = dest;
  6499. }
  6500. if (Array.isArray(explicitDest)) {
  6501. const [destRef] = explicitDest;
  6502. if (typeof destRef === "object" && destRef !== null) {
  6503. pageNumber = this.linkService._cachedPageNumber(destRef);
  6504. if (!pageNumber) {
  6505. try {
  6506. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6507. if (pdfDocument !== this._pdfDocument) {
  6508. return null;
  6509. }
  6510. this.linkService.cachePageRef(pageNumber, destRef);
  6511. } catch (ex) { }
  6512. }
  6513. } else if (Number.isInteger(destRef)) {
  6514. pageNumber = destRef + 1;
  6515. }
  6516. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6517. const destHash = this.linkService.getDestinationHash(dest);
  6518. pageNumberToDestHash.set(pageNumber, destHash);
  6519. pageNumberNesting.set(pageNumber, currentNesting);
  6520. }
  6521. }
  6522. if (items.length > 0) {
  6523. queue.push({
  6524. nesting: currentNesting + 1,
  6525. items
  6526. });
  6527. }
  6528. }
  6529. }
  6530. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6531. return this._pageNumberToDestHashCapability.promise;
  6532. }
  6533. }
  6534. exports.PDFOutlineViewer = PDFOutlineViewer;
  6535. /***/
  6536. }),
  6537. /* 21 */
  6538. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6539. Object.defineProperty(exports, "__esModule", ({
  6540. value: true
  6541. }));
  6542. exports.PDFPresentationMode = void 0;
  6543. var _ui_utils = __webpack_require__(1);
  6544. var _pdfjsLib = __webpack_require__(5);
  6545. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6546. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6547. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6548. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6549. const PAGE_SWITCH_THRESHOLD = 0.1;
  6550. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6551. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6552. class PDFPresentationMode {
  6553. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6554. #args = null;
  6555. constructor({
  6556. container,
  6557. pdfViewer,
  6558. eventBus
  6559. }) {
  6560. this.container = container;
  6561. this.pdfViewer = pdfViewer;
  6562. this.eventBus = eventBus;
  6563. this.contextMenuOpen = false;
  6564. this.mouseScrollTimeStamp = 0;
  6565. this.mouseScrollDelta = 0;
  6566. this.touchSwipeState = null;
  6567. }
  6568. async request() {
  6569. const {
  6570. container,
  6571. pdfViewer
  6572. } = this;
  6573. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6574. return false;
  6575. }
  6576. this.#addFullscreenChangeListeners();
  6577. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6578. const promise = container.requestFullscreen();
  6579. this.#args = {
  6580. pageNumber: pdfViewer.currentPageNumber,
  6581. scaleValue: pdfViewer.currentScaleValue,
  6582. scrollMode: pdfViewer.scrollMode,
  6583. spreadMode: null,
  6584. annotationEditorMode: null
  6585. };
  6586. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6587. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6588. this.#args.spreadMode = pdfViewer.spreadMode;
  6589. }
  6590. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6591. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6592. }
  6593. try {
  6594. await promise;
  6595. pdfViewer.focus();
  6596. return true;
  6597. } catch (reason) {
  6598. this.#removeFullscreenChangeListeners();
  6599. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6600. }
  6601. return false;
  6602. }
  6603. get active() {
  6604. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6605. }
  6606. #mouseWheel(evt) {
  6607. if (!this.active) {
  6608. return;
  6609. }
  6610. evt.preventDefault();
  6611. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6612. const currentTime = Date.now();
  6613. const storedTime = this.mouseScrollTimeStamp;
  6614. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6615. return;
  6616. }
  6617. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6618. this.#resetMouseScrollState();
  6619. }
  6620. this.mouseScrollDelta += delta;
  6621. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6622. const totalDelta = this.mouseScrollDelta;
  6623. this.#resetMouseScrollState();
  6624. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6625. if (success) {
  6626. this.mouseScrollTimeStamp = currentTime;
  6627. }
  6628. }
  6629. }
  6630. #notifyStateChange(state) {
  6631. this.#state = state;
  6632. this.eventBus.dispatch("presentationmodechanged", {
  6633. source: this,
  6634. state
  6635. });
  6636. }
  6637. #enter() {
  6638. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6639. this.container.classList.add(ACTIVE_SELECTOR);
  6640. setTimeout(() => {
  6641. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6642. if (this.#args.spreadMode !== null) {
  6643. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6644. }
  6645. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6646. this.pdfViewer.currentScaleValue = "page-fit";
  6647. if (this.#args.annotationEditorMode !== null) {
  6648. this.pdfViewer.annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  6649. }
  6650. }, 0);
  6651. this.#addWindowListeners();
  6652. this.#showControls();
  6653. this.contextMenuOpen = false;
  6654. window.getSelection().removeAllRanges();
  6655. }
  6656. #exit() {
  6657. const pageNumber = this.pdfViewer.currentPageNumber;
  6658. this.container.classList.remove(ACTIVE_SELECTOR);
  6659. setTimeout(() => {
  6660. this.#removeFullscreenChangeListeners();
  6661. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6662. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6663. if (this.#args.spreadMode !== null) {
  6664. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6665. }
  6666. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6667. this.pdfViewer.currentPageNumber = pageNumber;
  6668. if (this.#args.annotationEditorMode !== null) {
  6669. this.pdfViewer.annotationEditorMode = this.#args.annotationEditorMode;
  6670. }
  6671. this.#args = null;
  6672. }, 0);
  6673. this.#removeWindowListeners();
  6674. this.#hideControls();
  6675. this.#resetMouseScrollState();
  6676. this.contextMenuOpen = false;
  6677. }
  6678. #mouseDown(evt) {
  6679. if (this.contextMenuOpen) {
  6680. this.contextMenuOpen = false;
  6681. evt.preventDefault();
  6682. return;
  6683. }
  6684. if (evt.button !== 0) {
  6685. return;
  6686. }
  6687. if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) {
  6688. return;
  6689. }
  6690. evt.preventDefault();
  6691. if (evt.shiftKey) {
  6692. this.pdfViewer.previousPage();
  6693. } else {
  6694. this.pdfViewer.nextPage();
  6695. }
  6696. }
  6697. #contextMenu() {
  6698. this.contextMenuOpen = true;
  6699. }
  6700. #showControls() {
  6701. if (this.controlsTimeout) {
  6702. clearTimeout(this.controlsTimeout);
  6703. } else {
  6704. this.container.classList.add(CONTROLS_SELECTOR);
  6705. }
  6706. this.controlsTimeout = setTimeout(() => {
  6707. this.container.classList.remove(CONTROLS_SELECTOR);
  6708. delete this.controlsTimeout;
  6709. }, DELAY_BEFORE_HIDING_CONTROLS);
  6710. }
  6711. #hideControls() {
  6712. if (!this.controlsTimeout) {
  6713. return;
  6714. }
  6715. clearTimeout(this.controlsTimeout);
  6716. this.container.classList.remove(CONTROLS_SELECTOR);
  6717. delete this.controlsTimeout;
  6718. }
  6719. #resetMouseScrollState() {
  6720. this.mouseScrollTimeStamp = 0;
  6721. this.mouseScrollDelta = 0;
  6722. }
  6723. #touchSwipe(evt) {
  6724. if (!this.active) {
  6725. return;
  6726. }
  6727. if (evt.touches.length > 1) {
  6728. this.touchSwipeState = null;
  6729. return;
  6730. }
  6731. switch (evt.type) {
  6732. case "touchstart":
  6733. this.touchSwipeState = {
  6734. startX: evt.touches[0].pageX,
  6735. startY: evt.touches[0].pageY,
  6736. endX: evt.touches[0].pageX,
  6737. endY: evt.touches[0].pageY
  6738. };
  6739. break;
  6740. case "touchmove":
  6741. if (this.touchSwipeState === null) {
  6742. return;
  6743. }
  6744. this.touchSwipeState.endX = evt.touches[0].pageX;
  6745. this.touchSwipeState.endY = evt.touches[0].pageY;
  6746. evt.preventDefault();
  6747. break;
  6748. case "touchend":
  6749. if (this.touchSwipeState === null) {
  6750. return;
  6751. }
  6752. let delta = 0;
  6753. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6754. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6755. const absAngle = Math.abs(Math.atan2(dy, dx));
  6756. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6757. delta = dx;
  6758. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6759. delta = dy;
  6760. }
  6761. if (delta > 0) {
  6762. this.pdfViewer.previousPage();
  6763. } else if (delta < 0) {
  6764. this.pdfViewer.nextPage();
  6765. }
  6766. break;
  6767. }
  6768. }
  6769. #addWindowListeners() {
  6770. this.showControlsBind = this.#showControls.bind(this);
  6771. this.mouseDownBind = this.#mouseDown.bind(this);
  6772. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6773. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6774. this.contextMenuBind = this.#contextMenu.bind(this);
  6775. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6776. window.addEventListener("mousemove", this.showControlsBind);
  6777. window.addEventListener("mousedown", this.mouseDownBind);
  6778. window.addEventListener("wheel", this.mouseWheelBind, {
  6779. passive: false
  6780. });
  6781. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6782. window.addEventListener("contextmenu", this.contextMenuBind);
  6783. window.addEventListener("touchstart", this.touchSwipeBind);
  6784. window.addEventListener("touchmove", this.touchSwipeBind);
  6785. window.addEventListener("touchend", this.touchSwipeBind);
  6786. }
  6787. #removeWindowListeners() {
  6788. window.removeEventListener("mousemove", this.showControlsBind);
  6789. window.removeEventListener("mousedown", this.mouseDownBind);
  6790. window.removeEventListener("wheel", this.mouseWheelBind, {
  6791. passive: false
  6792. });
  6793. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6794. window.removeEventListener("contextmenu", this.contextMenuBind);
  6795. window.removeEventListener("touchstart", this.touchSwipeBind);
  6796. window.removeEventListener("touchmove", this.touchSwipeBind);
  6797. window.removeEventListener("touchend", this.touchSwipeBind);
  6798. delete this.showControlsBind;
  6799. delete this.mouseDownBind;
  6800. delete this.mouseWheelBind;
  6801. delete this.resetMouseScrollStateBind;
  6802. delete this.contextMenuBind;
  6803. delete this.touchSwipeBind;
  6804. }
  6805. #fullscreenChange() {
  6806. if (document.fullscreenElement) {
  6807. this.#enter();
  6808. } else {
  6809. this.#exit();
  6810. }
  6811. }
  6812. #addFullscreenChangeListeners() {
  6813. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6814. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6815. }
  6816. #removeFullscreenChangeListeners() {
  6817. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6818. delete this.fullscreenChangeBind;
  6819. }
  6820. }
  6821. exports.PDFPresentationMode = PDFPresentationMode;
  6822. /***/
  6823. }),
  6824. /* 22 */
  6825. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6826. Object.defineProperty(exports, "__esModule", ({
  6827. value: true
  6828. }));
  6829. exports.PDFRenderingQueue = void 0;
  6830. var _pdfjsLib = __webpack_require__(5);
  6831. var _ui_utils = __webpack_require__(1);
  6832. const CLEANUP_TIMEOUT = 30000;
  6833. class PDFRenderingQueue {
  6834. constructor() {
  6835. this.pdfViewer = null;
  6836. this.pdfThumbnailViewer = null;
  6837. this.onIdle = null;
  6838. this.highestPriorityPage = null;
  6839. this.idleTimeout = null;
  6840. this.printing = false;
  6841. this.isThumbnailViewEnabled = false;
  6842. }
  6843. setViewer(pdfViewer) {
  6844. this.pdfViewer = pdfViewer;
  6845. }
  6846. setThumbnailViewer(pdfThumbnailViewer) {
  6847. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6848. }
  6849. isHighestPriority(view) {
  6850. return this.highestPriorityPage === view.renderingId;
  6851. }
  6852. hasViewer() {
  6853. return !!this.pdfViewer;
  6854. }
  6855. renderHighestPriority(currentlyVisiblePages) {
  6856. if (this.idleTimeout) {
  6857. clearTimeout(this.idleTimeout);
  6858. this.idleTimeout = null;
  6859. }
  6860. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6861. return;
  6862. }
  6863. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6864. return;
  6865. }
  6866. if (this.printing) {
  6867. return;
  6868. }
  6869. if (this.onIdle) {
  6870. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6871. }
  6872. }
  6873. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6874. const visibleViews = visible.views,
  6875. numVisible = visibleViews.length;
  6876. if (numVisible === 0) {
  6877. return null;
  6878. }
  6879. for (let i = 0; i < numVisible; i++) {
  6880. const view = visibleViews[i].view;
  6881. if (!this.isViewFinished(view)) {
  6882. return view;
  6883. }
  6884. }
  6885. const firstId = visible.first.id,
  6886. lastId = visible.last.id;
  6887. if (lastId - firstId + 1 > numVisible) {
  6888. const visibleIds = visible.ids;
  6889. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6890. const holeId = scrolledDown ? firstId + i : lastId - i;
  6891. if (visibleIds.has(holeId)) {
  6892. continue;
  6893. }
  6894. const holeView = views[holeId - 1];
  6895. if (!this.isViewFinished(holeView)) {
  6896. return holeView;
  6897. }
  6898. }
  6899. }
  6900. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6901. let preRenderView = views[preRenderIndex];
  6902. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6903. return preRenderView;
  6904. }
  6905. if (preRenderExtra) {
  6906. preRenderIndex += scrolledDown ? 1 : -1;
  6907. preRenderView = views[preRenderIndex];
  6908. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6909. return preRenderView;
  6910. }
  6911. }
  6912. return null;
  6913. }
  6914. isViewFinished(view) {
  6915. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6916. }
  6917. renderView(view) {
  6918. switch (view.renderingState) {
  6919. case _ui_utils.RenderingStates.FINISHED:
  6920. return false;
  6921. case _ui_utils.RenderingStates.PAUSED:
  6922. this.highestPriorityPage = view.renderingId;
  6923. view.resume();
  6924. break;
  6925. case _ui_utils.RenderingStates.RUNNING:
  6926. this.highestPriorityPage = view.renderingId;
  6927. break;
  6928. case _ui_utils.RenderingStates.INITIAL:
  6929. this.highestPriorityPage = view.renderingId;
  6930. view.draw().finally(() => {
  6931. this.renderHighestPriority();
  6932. }).catch(reason => {
  6933. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6934. return;
  6935. }
  6936. console.error(`renderView: "${reason}"`);
  6937. });
  6938. break;
  6939. }
  6940. return true;
  6941. }
  6942. }
  6943. exports.PDFRenderingQueue = PDFRenderingQueue;
  6944. /***/
  6945. }),
  6946. /* 23 */
  6947. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6948. Object.defineProperty(exports, "__esModule", ({
  6949. value: true
  6950. }));
  6951. exports.PDFScriptingManager = void 0;
  6952. var _ui_utils = __webpack_require__(1);
  6953. var _pdfjsLib = __webpack_require__(5);
  6954. class PDFScriptingManager {
  6955. constructor({
  6956. eventBus,
  6957. sandboxBundleSrc = null,
  6958. scriptingFactory = null,
  6959. docPropertiesLookup = null
  6960. }) {
  6961. this._pdfDocument = null;
  6962. this._pdfViewer = null;
  6963. this._closeCapability = null;
  6964. this._destroyCapability = null;
  6965. this._scripting = null;
  6966. this._ready = false;
  6967. this._eventBus = eventBus;
  6968. this._sandboxBundleSrc = sandboxBundleSrc;
  6969. this._scriptingFactory = scriptingFactory;
  6970. this._docPropertiesLookup = docPropertiesLookup;
  6971. }
  6972. setViewer(pdfViewer) {
  6973. this._pdfViewer = pdfViewer;
  6974. }
  6975. async setDocument(pdfDocument) {
  6976. if (this._pdfDocument) {
  6977. await this._destroyScripting();
  6978. }
  6979. this._pdfDocument = pdfDocument;
  6980. if (!pdfDocument) {
  6981. return;
  6982. }
  6983. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6984. if (!objects && !docActions) {
  6985. await this._destroyScripting();
  6986. return;
  6987. }
  6988. if (pdfDocument !== this._pdfDocument) {
  6989. return;
  6990. }
  6991. try {
  6992. this._scripting = this._createScripting();
  6993. } catch (error) {
  6994. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6995. await this._destroyScripting();
  6996. return;
  6997. }
  6998. this._internalEvents.set("updatefromsandbox", event => {
  6999. if (event?.source !== window) {
  7000. return;
  7001. }
  7002. this._updateFromSandbox(event.detail);
  7003. });
  7004. this._internalEvents.set("dispatcheventinsandbox", event => {
  7005. this._scripting?.dispatchEventInSandbox(event.detail);
  7006. });
  7007. this._internalEvents.set("pagechanging", ({
  7008. pageNumber,
  7009. previous
  7010. }) => {
  7011. if (pageNumber === previous) {
  7012. return;
  7013. }
  7014. this._dispatchPageClose(previous);
  7015. this._dispatchPageOpen(pageNumber);
  7016. });
  7017. this._internalEvents.set("pagerendered", ({
  7018. pageNumber
  7019. }) => {
  7020. if (!this._pageOpenPending.has(pageNumber)) {
  7021. return;
  7022. }
  7023. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  7024. return;
  7025. }
  7026. this._dispatchPageOpen(pageNumber);
  7027. });
  7028. this._internalEvents.set("pagesdestroy", async event => {
  7029. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  7030. await this._scripting?.dispatchEventInSandbox({
  7031. id: "doc",
  7032. name: "WillClose"
  7033. });
  7034. this._closeCapability?.resolve();
  7035. });
  7036. for (const [name, listener] of this._internalEvents) {
  7037. this._eventBus._on(name, listener);
  7038. }
  7039. try {
  7040. const docProperties = await this._getDocProperties();
  7041. if (pdfDocument !== this._pdfDocument) {
  7042. return;
  7043. }
  7044. await this._scripting.createSandbox({
  7045. objects,
  7046. calculationOrder,
  7047. appInfo: {
  7048. platform: navigator.platform,
  7049. language: navigator.language
  7050. },
  7051. docInfo: {
  7052. ...docProperties,
  7053. actions: docActions
  7054. }
  7055. });
  7056. this._eventBus.dispatch("sandboxcreated", {
  7057. source: this
  7058. });
  7059. } catch (error) {
  7060. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  7061. await this._destroyScripting();
  7062. return;
  7063. }
  7064. await this._scripting?.dispatchEventInSandbox({
  7065. id: "doc",
  7066. name: "Open"
  7067. });
  7068. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  7069. Promise.resolve().then(() => {
  7070. if (pdfDocument === this._pdfDocument) {
  7071. this._ready = true;
  7072. }
  7073. });
  7074. }
  7075. async dispatchWillSave(detail) {
  7076. return this._scripting?.dispatchEventInSandbox({
  7077. id: "doc",
  7078. name: "WillSave"
  7079. });
  7080. }
  7081. async dispatchDidSave(detail) {
  7082. return this._scripting?.dispatchEventInSandbox({
  7083. id: "doc",
  7084. name: "DidSave"
  7085. });
  7086. }
  7087. async dispatchWillPrint(detail) {
  7088. return this._scripting?.dispatchEventInSandbox({
  7089. id: "doc",
  7090. name: "WillPrint"
  7091. });
  7092. }
  7093. async dispatchDidPrint(detail) {
  7094. return this._scripting?.dispatchEventInSandbox({
  7095. id: "doc",
  7096. name: "DidPrint"
  7097. });
  7098. }
  7099. get destroyPromise() {
  7100. return this._destroyCapability?.promise || null;
  7101. }
  7102. get ready() {
  7103. return this._ready;
  7104. }
  7105. get _internalEvents() {
  7106. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  7107. }
  7108. get _pageOpenPending() {
  7109. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  7110. }
  7111. get _visitedPages() {
  7112. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  7113. }
  7114. async _updateFromSandbox(detail) {
  7115. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  7116. const {
  7117. id,
  7118. siblings,
  7119. command,
  7120. value
  7121. } = detail;
  7122. if (!id) {
  7123. switch (command) {
  7124. case "clear":
  7125. console.clear();
  7126. break;
  7127. case "error":
  7128. console.error(value);
  7129. break;
  7130. case "layout":
  7131. {
  7132. if (isInPresentationMode) {
  7133. return;
  7134. }
  7135. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  7136. this._pdfViewer.spreadMode = modes.spreadMode;
  7137. break;
  7138. }
  7139. case "page-num":
  7140. this._pdfViewer.currentPageNumber = value + 1;
  7141. break;
  7142. case "print":
  7143. await this._pdfViewer.pagesPromise;
  7144. this._eventBus.dispatch("print", {
  7145. source: this
  7146. });
  7147. break;
  7148. case "println":
  7149. console.log(value);
  7150. break;
  7151. case "zoom":
  7152. if (isInPresentationMode) {
  7153. return;
  7154. }
  7155. this._pdfViewer.currentScaleValue = value;
  7156. break;
  7157. case "SaveAs":
  7158. this._eventBus.dispatch("download", {
  7159. source: this
  7160. });
  7161. break;
  7162. case "FirstPage":
  7163. this._pdfViewer.currentPageNumber = 1;
  7164. break;
  7165. case "LastPage":
  7166. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  7167. break;
  7168. case "NextPage":
  7169. this._pdfViewer.nextPage();
  7170. break;
  7171. case "PrevPage":
  7172. this._pdfViewer.previousPage();
  7173. break;
  7174. case "ZoomViewIn":
  7175. if (isInPresentationMode) {
  7176. return;
  7177. }
  7178. this._pdfViewer.increaseScale();
  7179. break;
  7180. case "ZoomViewOut":
  7181. if (isInPresentationMode) {
  7182. return;
  7183. }
  7184. this._pdfViewer.decreaseScale();
  7185. break;
  7186. }
  7187. return;
  7188. }
  7189. if (isInPresentationMode) {
  7190. if (detail.focus) {
  7191. return;
  7192. }
  7193. }
  7194. delete detail.id;
  7195. delete detail.siblings;
  7196. const ids = siblings ? [id, ...siblings] : [id];
  7197. for (const elementId of ids) {
  7198. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  7199. if (element) {
  7200. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  7201. detail
  7202. }));
  7203. } else {
  7204. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  7205. }
  7206. }
  7207. }
  7208. async _dispatchPageOpen(pageNumber, initialize = false) {
  7209. const pdfDocument = this._pdfDocument,
  7210. visitedPages = this._visitedPages;
  7211. if (initialize) {
  7212. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  7213. }
  7214. if (!this._closeCapability) {
  7215. return;
  7216. }
  7217. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  7218. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7219. this._pageOpenPending.add(pageNumber);
  7220. return;
  7221. }
  7222. this._pageOpenPending.delete(pageNumber);
  7223. const actionsPromise = (async () => {
  7224. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  7225. if (pdfDocument !== this._pdfDocument) {
  7226. return;
  7227. }
  7228. await this._scripting?.dispatchEventInSandbox({
  7229. id: "page",
  7230. name: "PageOpen",
  7231. pageNumber,
  7232. actions
  7233. });
  7234. })();
  7235. visitedPages.set(pageNumber, actionsPromise);
  7236. }
  7237. async _dispatchPageClose(pageNumber) {
  7238. const pdfDocument = this._pdfDocument,
  7239. visitedPages = this._visitedPages;
  7240. if (!this._closeCapability) {
  7241. return;
  7242. }
  7243. if (this._pageOpenPending.has(pageNumber)) {
  7244. return;
  7245. }
  7246. const actionsPromise = visitedPages.get(pageNumber);
  7247. if (!actionsPromise) {
  7248. return;
  7249. }
  7250. visitedPages.set(pageNumber, null);
  7251. await actionsPromise;
  7252. if (pdfDocument !== this._pdfDocument) {
  7253. return;
  7254. }
  7255. await this._scripting?.dispatchEventInSandbox({
  7256. id: "page",
  7257. name: "PageClose",
  7258. pageNumber
  7259. });
  7260. }
  7261. async _getDocProperties() {
  7262. if (this._docPropertiesLookup) {
  7263. return this._docPropertiesLookup(this._pdfDocument);
  7264. }
  7265. throw new Error("_getDocProperties: Unable to lookup properties.");
  7266. }
  7267. _createScripting() {
  7268. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  7269. if (this._scripting) {
  7270. throw new Error("_createScripting: Scripting already exists.");
  7271. }
  7272. if (this._scriptingFactory) {
  7273. return this._scriptingFactory.createScripting({
  7274. sandboxBundleSrc: this._sandboxBundleSrc
  7275. });
  7276. }
  7277. throw new Error("_createScripting: Cannot create scripting.");
  7278. }
  7279. async _destroyScripting() {
  7280. if (!this._scripting) {
  7281. this._pdfDocument = null;
  7282. this._destroyCapability?.resolve();
  7283. return;
  7284. }
  7285. if (this._closeCapability) {
  7286. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  7287. setTimeout(resolve, 1000);
  7288. })]).catch(reason => { });
  7289. this._closeCapability = null;
  7290. }
  7291. this._pdfDocument = null;
  7292. try {
  7293. await this._scripting.destroySandbox();
  7294. } catch (ex) { }
  7295. for (const [name, listener] of this._internalEvents) {
  7296. this._eventBus._off(name, listener);
  7297. }
  7298. this._internalEvents.clear();
  7299. this._pageOpenPending.clear();
  7300. this._visitedPages.clear();
  7301. this._scripting = null;
  7302. this._ready = false;
  7303. this._destroyCapability?.resolve();
  7304. }
  7305. }
  7306. exports.PDFScriptingManager = PDFScriptingManager;
  7307. /***/
  7308. }),
  7309. /* 24 */
  7310. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7311. Object.defineProperty(exports, "__esModule", ({
  7312. value: true
  7313. }));
  7314. exports.PDFSidebar = void 0;
  7315. var _ui_utils = __webpack_require__(1);
  7316. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7317. class PDFSidebar {
  7318. constructor({
  7319. elements,
  7320. pdfViewer,
  7321. pdfThumbnailViewer,
  7322. eventBus,
  7323. l10n
  7324. }) {
  7325. this.isOpen = false;
  7326. this.active = _ui_utils.SidebarView.THUMBS;
  7327. this.isInitialViewSet = false;
  7328. this.isInitialEventDispatched = false;
  7329. this.onToggled = null;
  7330. this.pdfViewer = pdfViewer;
  7331. this.pdfThumbnailViewer = pdfThumbnailViewer;
  7332. this.outerContainer = elements.outerContainer;
  7333. this.sidebarContainer = elements.sidebarContainer;
  7334. this.toggleButton = elements.toggleButton;
  7335. this.thumbnailButton = elements.thumbnailButton;
  7336. this.outlineButton = elements.outlineButton;
  7337. this.attachmentsButton = elements.attachmentsButton;
  7338. this.layersButton = elements.layersButton;
  7339. this.thumbnailView = elements.thumbnailView;
  7340. this.outlineView = elements.outlineView;
  7341. this.attachmentsView = elements.attachmentsView;
  7342. this.layersView = elements.layersView;
  7343. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  7344. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7345. this.eventBus = eventBus;
  7346. this.l10n = l10n;
  7347. this.#addEventListeners();
  7348. }
  7349. reset() {
  7350. this.isInitialViewSet = false;
  7351. this.isInitialEventDispatched = false;
  7352. this.#hideUINotification(true);
  7353. this.switchView(_ui_utils.SidebarView.THUMBS);
  7354. this.outlineButton.disabled = false;
  7355. this.attachmentsButton.disabled = false;
  7356. this.layersButton.disabled = false;
  7357. this._currentOutlineItemButton.disabled = true;
  7358. }
  7359. get visibleView() {
  7360. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  7361. }
  7362. setInitialView(view = _ui_utils.SidebarView.NONE) {
  7363. if (this.isInitialViewSet) {
  7364. return;
  7365. }
  7366. this.isInitialViewSet = true;
  7367. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  7368. this.#dispatchEvent();
  7369. return;
  7370. }
  7371. this.switchView(view, true);
  7372. if (!this.isInitialEventDispatched) {
  7373. this.#dispatchEvent();
  7374. }
  7375. }
  7376. switchView(view, forceOpen = false) {
  7377. const isViewChanged = view !== this.active;
  7378. let shouldForceRendering = false;
  7379. switch (view) {
  7380. case _ui_utils.SidebarView.NONE:
  7381. if (this.isOpen) {
  7382. this.close();
  7383. }
  7384. return;
  7385. case _ui_utils.SidebarView.THUMBS:
  7386. if (this.isOpen && isViewChanged) {
  7387. shouldForceRendering = true;
  7388. }
  7389. break;
  7390. case _ui_utils.SidebarView.OUTLINE:
  7391. if (this.outlineButton.disabled) {
  7392. return;
  7393. }
  7394. break;
  7395. case _ui_utils.SidebarView.ATTACHMENTS:
  7396. if (this.attachmentsButton.disabled) {
  7397. return;
  7398. }
  7399. break;
  7400. case _ui_utils.SidebarView.LAYERS:
  7401. if (this.layersButton.disabled) {
  7402. return;
  7403. }
  7404. break;
  7405. default:
  7406. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7407. return;
  7408. }
  7409. this.active = view;
  7410. const isThumbs = view === _ui_utils.SidebarView.THUMBS,
  7411. isOutline = view === _ui_utils.SidebarView.OUTLINE,
  7412. isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS,
  7413. isLayers = view === _ui_utils.SidebarView.LAYERS;
  7414. this.thumbnailButton.classList.toggle("toggled", isThumbs);
  7415. this.outlineButton.classList.toggle("toggled", isOutline);
  7416. this.attachmentsButton.classList.toggle("toggled", isAttachments);
  7417. this.layersButton.classList.toggle("toggled", isLayers);
  7418. this.thumbnailButton.setAttribute("aria-checked", isThumbs);
  7419. this.outlineButton.setAttribute("aria-checked", isOutline);
  7420. this.attachmentsButton.setAttribute("aria-checked", isAttachments);
  7421. this.layersButton.setAttribute("aria-checked", isLayers);
  7422. this.thumbnailView.classList.toggle("hidden", !isThumbs);
  7423. this.outlineView.classList.toggle("hidden", !isOutline);
  7424. this.attachmentsView.classList.toggle("hidden", !isAttachments);
  7425. this.layersView.classList.toggle("hidden", !isLayers);
  7426. this._outlineOptionsContainer.classList.toggle("hidden", !isOutline);
  7427. if (forceOpen && !this.isOpen) {
  7428. this.open();
  7429. return;
  7430. }
  7431. if (shouldForceRendering) {
  7432. this.#updateThumbnailViewer();
  7433. this.#forceRendering();
  7434. }
  7435. if (isViewChanged) {
  7436. this.#dispatchEvent();
  7437. }
  7438. }
  7439. open() {
  7440. if (this.isOpen) {
  7441. return;
  7442. }
  7443. this.isOpen = true;
  7444. this.toggleButton.classList.add("toggled");
  7445. this.toggleButton.setAttribute("aria-expanded", "true");
  7446. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7447. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7448. this.#updateThumbnailViewer();
  7449. }
  7450. this.#forceRendering();
  7451. this.#dispatchEvent();
  7452. this.#hideUINotification();
  7453. }
  7454. close() {
  7455. if (!this.isOpen) {
  7456. return;
  7457. }
  7458. this.isOpen = false;
  7459. this.toggleButton.classList.remove("toggled");
  7460. this.toggleButton.setAttribute("aria-expanded", "false");
  7461. this.outerContainer.classList.add("sidebarMoving");
  7462. this.outerContainer.classList.remove("sidebarOpen");
  7463. this.#forceRendering();
  7464. this.#dispatchEvent();
  7465. }
  7466. toggle() {
  7467. if (this.isOpen) {
  7468. this.close();
  7469. } else {
  7470. this.open();
  7471. }
  7472. }
  7473. #dispatchEvent() {
  7474. if (this.isInitialViewSet && !this.isInitialEventDispatched) {
  7475. this.isInitialEventDispatched = true;
  7476. }
  7477. this.eventBus.dispatch("sidebarviewchanged", {
  7478. source: this,
  7479. view: this.visibleView
  7480. });
  7481. }
  7482. #forceRendering() {
  7483. if (this.onToggled) {
  7484. this.onToggled();
  7485. } else {
  7486. this.pdfViewer.forceRendering();
  7487. this.pdfThumbnailViewer.forceRendering();
  7488. }
  7489. }
  7490. #updateThumbnailViewer() {
  7491. const {
  7492. pdfViewer,
  7493. pdfThumbnailViewer
  7494. } = this;
  7495. const pagesCount = pdfViewer.pagesCount;
  7496. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  7497. const pageView = pdfViewer.getPageView(pageIndex);
  7498. if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) {
  7499. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  7500. thumbnailView.setImage(pageView);
  7501. }
  7502. }
  7503. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  7504. }
  7505. #showUINotification() {
  7506. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2");
  7507. this.l10n.translate(this.toggleButton);
  7508. if (!this.isOpen) {
  7509. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7510. }
  7511. }
  7512. #hideUINotification(reset = false) {
  7513. if (this.isOpen || reset) {
  7514. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7515. }
  7516. if (reset) {
  7517. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
  7518. this.l10n.translate(this.toggleButton);
  7519. }
  7520. }
  7521. #addEventListeners() {
  7522. this.sidebarContainer.addEventListener("transitionend", evt => {
  7523. if (evt.target === this.sidebarContainer) {
  7524. this.outerContainer.classList.remove("sidebarMoving");
  7525. }
  7526. });
  7527. this.toggleButton.addEventListener("click", () => {
  7528. this.toggle();
  7529. });
  7530. this.thumbnailButton.addEventListener("click", () => {
  7531. this.switchView(_ui_utils.SidebarView.THUMBS);
  7532. });
  7533. this.outlineButton.addEventListener("click", () => {
  7534. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7535. });
  7536. this.outlineButton.addEventListener("dblclick", () => {
  7537. this.eventBus.dispatch("toggleoutlinetree", {
  7538. source: this
  7539. });
  7540. });
  7541. this.attachmentsButton.addEventListener("click", () => {
  7542. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7543. });
  7544. this.layersButton.addEventListener("click", () => {
  7545. this.switchView(_ui_utils.SidebarView.LAYERS);
  7546. });
  7547. this.layersButton.addEventListener("dblclick", () => {
  7548. this.eventBus.dispatch("resetlayers", {
  7549. source: this
  7550. });
  7551. });
  7552. this._currentOutlineItemButton.addEventListener("click", () => {
  7553. this.eventBus.dispatch("currentoutlineitem", {
  7554. source: this
  7555. });
  7556. });
  7557. const onTreeLoaded = (count, button, view) => {
  7558. button.disabled = !count;
  7559. if (count) {
  7560. this.#showUINotification();
  7561. } else if (this.active === view) {
  7562. this.switchView(_ui_utils.SidebarView.THUMBS);
  7563. }
  7564. };
  7565. this.eventBus._on("outlineloaded", evt => {
  7566. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7567. evt.currentOutlineItemPromise.then(enabled => {
  7568. if (!this.isInitialViewSet) {
  7569. return;
  7570. }
  7571. this._currentOutlineItemButton.disabled = !enabled;
  7572. });
  7573. });
  7574. this.eventBus._on("attachmentsloaded", evt => {
  7575. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7576. });
  7577. this.eventBus._on("layersloaded", evt => {
  7578. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7579. });
  7580. this.eventBus._on("presentationmodechanged", evt => {
  7581. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  7582. this.#updateThumbnailViewer();
  7583. }
  7584. });
  7585. }
  7586. }
  7587. exports.PDFSidebar = PDFSidebar;
  7588. /***/
  7589. }),
  7590. /* 25 */
  7591. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7592. Object.defineProperty(exports, "__esModule", ({
  7593. value: true
  7594. }));
  7595. exports.PDFSidebarResizer = void 0;
  7596. var _ui_utils = __webpack_require__(1);
  7597. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7598. const SIDEBAR_MIN_WIDTH = 200;
  7599. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7600. class PDFSidebarResizer {
  7601. constructor(options, eventBus, l10n) {
  7602. this.isRTL = false;
  7603. this.sidebarOpen = false;
  7604. this._width = null;
  7605. this._outerContainerWidth = null;
  7606. this._boundEvents = Object.create(null);
  7607. this.outerContainer = options.outerContainer;
  7608. this.resizer = options.resizer;
  7609. this.eventBus = eventBus;
  7610. l10n.getDirection().then(dir => {
  7611. this.isRTL = dir === "rtl";
  7612. });
  7613. this._addEventListeners();
  7614. }
  7615. get outerContainerWidth() {
  7616. return this._outerContainerWidth ||= this.outerContainer.clientWidth;
  7617. }
  7618. _updateWidth(width = 0) {
  7619. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7620. if (width > maxWidth) {
  7621. width = maxWidth;
  7622. }
  7623. if (width < SIDEBAR_MIN_WIDTH) {
  7624. width = SIDEBAR_MIN_WIDTH;
  7625. }
  7626. if (width === this._width) {
  7627. return false;
  7628. }
  7629. this._width = width;
  7630. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7631. return true;
  7632. }
  7633. _mouseMove(evt) {
  7634. let width = evt.clientX;
  7635. if (this.isRTL) {
  7636. width = this.outerContainerWidth - width;
  7637. }
  7638. this._updateWidth(width);
  7639. }
  7640. _mouseUp(evt) {
  7641. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7642. this.eventBus.dispatch("resize", {
  7643. source: this
  7644. });
  7645. const _boundEvents = this._boundEvents;
  7646. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7647. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7648. }
  7649. _addEventListeners() {
  7650. const _boundEvents = this._boundEvents;
  7651. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7652. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7653. this.resizer.addEventListener("mousedown", evt => {
  7654. if (evt.button !== 0) {
  7655. return;
  7656. }
  7657. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7658. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7659. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7660. });
  7661. this.eventBus._on("sidebarviewchanged", evt => {
  7662. this.sidebarOpen = !!evt?.view;
  7663. });
  7664. this.eventBus._on("resize", evt => {
  7665. if (evt?.source !== window) {
  7666. return;
  7667. }
  7668. this._outerContainerWidth = null;
  7669. if (!this._width) {
  7670. return;
  7671. }
  7672. if (!this.sidebarOpen) {
  7673. this._updateWidth(this._width);
  7674. return;
  7675. }
  7676. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7677. const updated = this._updateWidth(this._width);
  7678. Promise.resolve().then(() => {
  7679. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7680. if (updated) {
  7681. this.eventBus.dispatch("resize", {
  7682. source: this
  7683. });
  7684. }
  7685. });
  7686. });
  7687. }
  7688. }
  7689. exports.PDFSidebarResizer = PDFSidebarResizer;
  7690. /***/
  7691. }),
  7692. /* 26 */
  7693. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7694. Object.defineProperty(exports, "__esModule", ({
  7695. value: true
  7696. }));
  7697. exports.PDFThumbnailViewer = void 0;
  7698. var _ui_utils = __webpack_require__(1);
  7699. var _pdf_thumbnail_view = __webpack_require__(27);
  7700. const THUMBNAIL_SCROLL_MARGIN = -19;
  7701. const THUMBNAIL_SELECTED_CLASS = "selected";
  7702. class PDFThumbnailViewer {
  7703. constructor({
  7704. container,
  7705. eventBus,
  7706. linkService,
  7707. renderingQueue,
  7708. l10n,
  7709. pageColors
  7710. }) {
  7711. this.container = container;
  7712. this.linkService = linkService;
  7713. this.renderingQueue = renderingQueue;
  7714. this.l10n = l10n;
  7715. this.pageColors = pageColors || null;
  7716. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  7717. if (this.pageColors.background || this.pageColors.foreground) {
  7718. console.warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  7719. }
  7720. this.pageColors = null;
  7721. }
  7722. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7723. this._resetView();
  7724. }
  7725. _scrollUpdated() {
  7726. this.renderingQueue.renderHighestPriority();
  7727. }
  7728. getThumbnail(index) {
  7729. return this._thumbnails[index];
  7730. }
  7731. _getVisibleThumbs() {
  7732. return (0, _ui_utils.getVisibleElements)({
  7733. scrollEl: this.container,
  7734. views: this._thumbnails
  7735. });
  7736. }
  7737. scrollThumbnailIntoView(pageNumber) {
  7738. if (!this.pdfDocument) {
  7739. return;
  7740. }
  7741. const thumbnailView = this._thumbnails[pageNumber - 1];
  7742. if (!thumbnailView) {
  7743. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7744. return;
  7745. }
  7746. if (pageNumber !== this._currentPageNumber) {
  7747. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7748. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7749. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7750. }
  7751. const {
  7752. first,
  7753. last,
  7754. views
  7755. } = this._getVisibleThumbs();
  7756. if (views.length > 0) {
  7757. let shouldScroll = false;
  7758. if (pageNumber <= first.id || pageNumber >= last.id) {
  7759. shouldScroll = true;
  7760. } else {
  7761. for (const {
  7762. id,
  7763. percent
  7764. } of views) {
  7765. if (id !== pageNumber) {
  7766. continue;
  7767. }
  7768. shouldScroll = percent < 100;
  7769. break;
  7770. }
  7771. }
  7772. if (shouldScroll) {
  7773. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7774. top: THUMBNAIL_SCROLL_MARGIN
  7775. });
  7776. }
  7777. }
  7778. this._currentPageNumber = pageNumber;
  7779. }
  7780. get pagesRotation() {
  7781. return this._pagesRotation;
  7782. }
  7783. set pagesRotation(rotation) {
  7784. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7785. throw new Error("Invalid thumbnails rotation angle.");
  7786. }
  7787. if (!this.pdfDocument) {
  7788. return;
  7789. }
  7790. if (this._pagesRotation === rotation) {
  7791. return;
  7792. }
  7793. this._pagesRotation = rotation;
  7794. const updateArgs = {
  7795. rotation
  7796. };
  7797. for (const thumbnail of this._thumbnails) {
  7798. thumbnail.update(updateArgs);
  7799. }
  7800. }
  7801. cleanup() {
  7802. for (const thumbnail of this._thumbnails) {
  7803. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7804. thumbnail.reset();
  7805. }
  7806. }
  7807. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7808. }
  7809. _resetView() {
  7810. this._thumbnails = [];
  7811. this._currentPageNumber = 1;
  7812. this._pageLabels = null;
  7813. this._pagesRotation = 0;
  7814. this.container.textContent = "";
  7815. }
  7816. setDocument(pdfDocument) {
  7817. if (this.pdfDocument) {
  7818. this._cancelRendering();
  7819. this._resetView();
  7820. }
  7821. this.pdfDocument = pdfDocument;
  7822. if (!pdfDocument) {
  7823. return;
  7824. }
  7825. const firstPagePromise = pdfDocument.getPage(1);
  7826. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7827. firstPagePromise.then(firstPdfPage => {
  7828. const pagesCount = pdfDocument.numPages;
  7829. const viewport = firstPdfPage.getViewport({
  7830. scale: 1
  7831. });
  7832. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7833. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7834. container: this.container,
  7835. id: pageNum,
  7836. defaultViewport: viewport.clone(),
  7837. optionalContentConfigPromise,
  7838. linkService: this.linkService,
  7839. renderingQueue: this.renderingQueue,
  7840. l10n: this.l10n,
  7841. pageColors: this.pageColors
  7842. });
  7843. this._thumbnails.push(thumbnail);
  7844. }
  7845. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  7846. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7847. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7848. }).catch(reason => {
  7849. console.error("Unable to initialize thumbnail viewer", reason);
  7850. });
  7851. }
  7852. _cancelRendering() {
  7853. for (const thumbnail of this._thumbnails) {
  7854. thumbnail.cancelRendering();
  7855. }
  7856. }
  7857. setPageLabels(labels) {
  7858. if (!this.pdfDocument) {
  7859. return;
  7860. }
  7861. if (!labels) {
  7862. this._pageLabels = null;
  7863. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7864. this._pageLabels = null;
  7865. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7866. } else {
  7867. this._pageLabels = labels;
  7868. }
  7869. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7870. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7871. }
  7872. }
  7873. async #ensurePdfPageLoaded(thumbView) {
  7874. if (thumbView.pdfPage) {
  7875. return thumbView.pdfPage;
  7876. }
  7877. try {
  7878. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7879. if (!thumbView.pdfPage) {
  7880. thumbView.setPdfPage(pdfPage);
  7881. }
  7882. return pdfPage;
  7883. } catch (reason) {
  7884. console.error("Unable to get page for thumb view", reason);
  7885. return null;
  7886. }
  7887. }
  7888. #getScrollAhead(visible) {
  7889. if (visible.first?.id === 1) {
  7890. return true;
  7891. } else if (visible.last?.id === this._thumbnails.length) {
  7892. return false;
  7893. }
  7894. return this.scroll.down;
  7895. }
  7896. forceRendering() {
  7897. const visibleThumbs = this._getVisibleThumbs();
  7898. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7899. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7900. if (thumbView) {
  7901. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7902. this.renderingQueue.renderView(thumbView);
  7903. });
  7904. return true;
  7905. }
  7906. return false;
  7907. }
  7908. }
  7909. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7910. /***/
  7911. }),
  7912. /* 27 */
  7913. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7914. Object.defineProperty(exports, "__esModule", ({
  7915. value: true
  7916. }));
  7917. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7918. var _ui_utils = __webpack_require__(1);
  7919. var _pdfjsLib = __webpack_require__(5);
  7920. const DRAW_UPSCALE_FACTOR = 2;
  7921. const MAX_NUM_SCALING_STEPS = 3;
  7922. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7923. const THUMBNAIL_WIDTH = 98;
  7924. class TempImageFactory {
  7925. static #tempCanvas = null;
  7926. static getCanvas(width, height) {
  7927. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7928. tempCanvas.width = width;
  7929. tempCanvas.height = height;
  7930. const ctx = tempCanvas.getContext("2d", {
  7931. alpha: false
  7932. });
  7933. ctx.save();
  7934. ctx.fillStyle = "rgb(255, 255, 255)";
  7935. ctx.fillRect(0, 0, width, height);
  7936. ctx.restore();
  7937. return [tempCanvas, tempCanvas.getContext("2d")];
  7938. }
  7939. static destroyCanvas() {
  7940. const tempCanvas = this.#tempCanvas;
  7941. if (tempCanvas) {
  7942. tempCanvas.width = 0;
  7943. tempCanvas.height = 0;
  7944. }
  7945. this.#tempCanvas = null;
  7946. }
  7947. }
  7948. exports.TempImageFactory = TempImageFactory;
  7949. class PDFThumbnailView {
  7950. constructor({
  7951. container,
  7952. id,
  7953. defaultViewport,
  7954. optionalContentConfigPromise,
  7955. linkService,
  7956. renderingQueue,
  7957. l10n,
  7958. pageColors
  7959. }) {
  7960. this.id = id;
  7961. this.renderingId = "thumbnail" + id;
  7962. this.pageLabel = null;
  7963. this.pdfPage = null;
  7964. this.rotation = 0;
  7965. this.viewport = defaultViewport;
  7966. this.pdfPageRotate = defaultViewport.rotation;
  7967. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7968. this.pageColors = pageColors || null;
  7969. this.linkService = linkService;
  7970. this.renderingQueue = renderingQueue;
  7971. this.renderTask = null;
  7972. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7973. this.resume = null;
  7974. const pageWidth = this.viewport.width,
  7975. pageHeight = this.viewport.height,
  7976. pageRatio = pageWidth / pageHeight;
  7977. this.canvasWidth = THUMBNAIL_WIDTH;
  7978. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7979. this.scale = this.canvasWidth / pageWidth;
  7980. this.l10n = l10n;
  7981. const anchor = document.createElement("a");
  7982. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7983. this._thumbPageTitle.then(msg => {
  7984. anchor.title = msg;
  7985. });
  7986. anchor.onclick = function () {
  7987. linkService.goToPage(id);
  7988. return false;
  7989. };
  7990. this.anchor = anchor;
  7991. const div = document.createElement("div");
  7992. div.className = "thumbnail";
  7993. div.setAttribute("data-page-number", this.id);
  7994. this.div = div;
  7995. const ring = document.createElement("div");
  7996. ring.className = "thumbnailSelectionRing";
  7997. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7998. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7999. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  8000. this.ring = ring;
  8001. div.append(ring);
  8002. anchor.append(div);
  8003. container.append(anchor);
  8004. }
  8005. setPdfPage(pdfPage) {
  8006. this.pdfPage = pdfPage;
  8007. this.pdfPageRotate = pdfPage.rotate;
  8008. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8009. this.viewport = pdfPage.getViewport({
  8010. scale: 1,
  8011. rotation: totalRotation
  8012. });
  8013. this.reset();
  8014. }
  8015. reset() {
  8016. this.cancelRendering();
  8017. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  8018. const pageWidth = this.viewport.width,
  8019. pageHeight = this.viewport.height,
  8020. pageRatio = pageWidth / pageHeight;
  8021. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  8022. this.scale = this.canvasWidth / pageWidth;
  8023. this.div.removeAttribute("data-loaded");
  8024. const ring = this.ring;
  8025. ring.textContent = "";
  8026. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  8027. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  8028. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  8029. if (this.canvas) {
  8030. this.canvas.width = 0;
  8031. this.canvas.height = 0;
  8032. delete this.canvas;
  8033. }
  8034. if (this.image) {
  8035. this.image.removeAttribute("src");
  8036. delete this.image;
  8037. }
  8038. }
  8039. update({
  8040. rotation = null
  8041. }) {
  8042. if (typeof rotation === "number") {
  8043. this.rotation = rotation;
  8044. }
  8045. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8046. this.viewport = this.viewport.clone({
  8047. scale: 1,
  8048. rotation: totalRotation
  8049. });
  8050. this.reset();
  8051. }
  8052. cancelRendering() {
  8053. if (this.renderTask) {
  8054. this.renderTask.cancel();
  8055. this.renderTask = null;
  8056. }
  8057. this.resume = null;
  8058. }
  8059. _getPageDrawContext(upscaleFactor = 1) {
  8060. const canvas = document.createElement("canvas");
  8061. const ctx = canvas.getContext("2d", {
  8062. alpha: false
  8063. });
  8064. const outputScale = new _ui_utils.OutputScale();
  8065. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  8066. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  8067. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  8068. return {
  8069. ctx,
  8070. canvas,
  8071. transform
  8072. };
  8073. }
  8074. _convertCanvasToImage(canvas) {
  8075. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8076. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  8077. }
  8078. const reducedCanvas = this._reduceImage(canvas);
  8079. const image = document.createElement("img");
  8080. image.className = "thumbnailImage";
  8081. this._thumbPageCanvas.then(msg => {
  8082. image.setAttribute("aria-label", msg);
  8083. });
  8084. image.style.width = this.canvasWidth + "px";
  8085. image.style.height = this.canvasHeight + "px";
  8086. image.src = reducedCanvas.toDataURL();
  8087. this.image = image;
  8088. this.div.setAttribute("data-loaded", true);
  8089. this.ring.append(image);
  8090. reducedCanvas.width = 0;
  8091. reducedCanvas.height = 0;
  8092. }
  8093. draw() {
  8094. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8095. console.error("Must be in new state before drawing");
  8096. return Promise.resolve();
  8097. }
  8098. const {
  8099. pdfPage
  8100. } = this;
  8101. if (!pdfPage) {
  8102. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8103. return Promise.reject(new Error("pdfPage is not loaded"));
  8104. }
  8105. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8106. const finishRenderTask = async (error = null) => {
  8107. if (renderTask === this.renderTask) {
  8108. this.renderTask = null;
  8109. }
  8110. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  8111. return;
  8112. }
  8113. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8114. this._convertCanvasToImage(canvas);
  8115. if (error) {
  8116. throw error;
  8117. }
  8118. };
  8119. const {
  8120. ctx,
  8121. canvas,
  8122. transform
  8123. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  8124. const drawViewport = this.viewport.clone({
  8125. scale: DRAW_UPSCALE_FACTOR * this.scale
  8126. });
  8127. const renderContinueCallback = cont => {
  8128. if (!this.renderingQueue.isHighestPriority(this)) {
  8129. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  8130. this.resume = () => {
  8131. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8132. cont();
  8133. };
  8134. return;
  8135. }
  8136. cont();
  8137. };
  8138. const renderContext = {
  8139. canvasContext: ctx,
  8140. transform,
  8141. viewport: drawViewport,
  8142. optionalContentConfigPromise: this._optionalContentConfigPromise,
  8143. pageColors: this.pageColors
  8144. };
  8145. const renderTask = this.renderTask = pdfPage.render(renderContext);
  8146. renderTask.onContinue = renderContinueCallback;
  8147. const resultPromise = renderTask.promise.then(function () {
  8148. return finishRenderTask(null);
  8149. }, function (error) {
  8150. return finishRenderTask(error);
  8151. });
  8152. resultPromise.finally(() => {
  8153. canvas.width = 0;
  8154. canvas.height = 0;
  8155. const pageCached = this.linkService.isPageCached(this.id);
  8156. if (!pageCached) {
  8157. this.pdfPage?.cleanup();
  8158. }
  8159. });
  8160. return resultPromise;
  8161. }
  8162. setImage(pageView) {
  8163. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8164. return;
  8165. }
  8166. const {
  8167. thumbnailCanvas: canvas,
  8168. pdfPage,
  8169. scale
  8170. } = pageView;
  8171. if (!canvas) {
  8172. return;
  8173. }
  8174. if (!this.pdfPage) {
  8175. this.setPdfPage(pdfPage);
  8176. }
  8177. if (scale < this.scale) {
  8178. return;
  8179. }
  8180. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8181. this._convertCanvasToImage(canvas);
  8182. }
  8183. _reduceImage(img) {
  8184. const {
  8185. ctx,
  8186. canvas
  8187. } = this._getPageDrawContext();
  8188. if (img.width <= 2 * canvas.width) {
  8189. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  8190. return canvas;
  8191. }
  8192. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  8193. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  8194. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  8195. while (reducedWidth > img.width || reducedHeight > img.height) {
  8196. reducedWidth >>= 1;
  8197. reducedHeight >>= 1;
  8198. }
  8199. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  8200. while (reducedWidth > 2 * canvas.width) {
  8201. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  8202. reducedWidth >>= 1;
  8203. reducedHeight >>= 1;
  8204. }
  8205. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  8206. return canvas;
  8207. }
  8208. get _thumbPageTitle() {
  8209. return this.l10n.get("thumb_page_title", {
  8210. page: this.pageLabel ?? this.id
  8211. });
  8212. }
  8213. get _thumbPageCanvas() {
  8214. return this.l10n.get("thumb_page_canvas", {
  8215. page: this.pageLabel ?? this.id
  8216. });
  8217. }
  8218. setPageLabel(label) {
  8219. this.pageLabel = typeof label === "string" ? label : null;
  8220. this._thumbPageTitle.then(msg => {
  8221. this.anchor.title = msg;
  8222. });
  8223. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8224. return;
  8225. }
  8226. this._thumbPageCanvas.then(msg => {
  8227. this.image?.setAttribute("aria-label", msg);
  8228. });
  8229. }
  8230. }
  8231. exports.PDFThumbnailView = PDFThumbnailView;
  8232. /***/
  8233. }),
  8234. /* 28 */
  8235. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8236. Object.defineProperty(exports, "__esModule", ({
  8237. value: true
  8238. }));
  8239. exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
  8240. var _pdfjsLib = __webpack_require__(5);
  8241. var _ui_utils = __webpack_require__(1);
  8242. var _l10n_utils = __webpack_require__(29);
  8243. var _pdf_page_view = __webpack_require__(30);
  8244. var _pdf_rendering_queue = __webpack_require__(22);
  8245. var _pdf_link_service = __webpack_require__(3);
  8246. const DEFAULT_CACHE_SIZE = 10;
  8247. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  8248. const PagesCountLimit = {
  8249. FORCE_SCROLL_MODE_PAGE: 15000,
  8250. FORCE_LAZY_PAGE_INIT: 7500,
  8251. PAUSE_EAGER_PAGE_INIT: 250
  8252. };
  8253. exports.PagesCountLimit = PagesCountLimit;
  8254. function isValidAnnotationEditorMode(mode) {
  8255. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  8256. }
  8257. class PDFPageViewBuffer {
  8258. #buf = new Set();
  8259. #size = 0;
  8260. constructor(size) {
  8261. this.#size = size;
  8262. }
  8263. push(view) {
  8264. const buf = this.#buf;
  8265. if (buf.has(view)) {
  8266. buf.delete(view);
  8267. }
  8268. buf.add(view);
  8269. if (buf.size > this.#size) {
  8270. this.#destroyFirstView();
  8271. }
  8272. }
  8273. resize(newSize, idsToKeep = null) {
  8274. this.#size = newSize;
  8275. const buf = this.#buf;
  8276. if (idsToKeep) {
  8277. const ii = buf.size;
  8278. let i = 1;
  8279. for (const view of buf) {
  8280. if (idsToKeep.has(view.id)) {
  8281. buf.delete(view);
  8282. buf.add(view);
  8283. }
  8284. if (++i > ii) {
  8285. break;
  8286. }
  8287. }
  8288. }
  8289. while (buf.size > this.#size) {
  8290. this.#destroyFirstView();
  8291. }
  8292. }
  8293. has(view) {
  8294. return this.#buf.has(view);
  8295. }
  8296. [Symbol.iterator]() {
  8297. return this.#buf.keys();
  8298. }
  8299. #destroyFirstView() {
  8300. const firstView = this.#buf.keys().next().value;
  8301. firstView?.destroy();
  8302. this.#buf.delete(firstView);
  8303. }
  8304. }
  8305. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  8306. class PDFViewer {
  8307. #buffer = null;
  8308. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  8309. #annotationEditorUIManager = null;
  8310. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8311. #containerTopLeft = null;
  8312. #enablePermissions = false;
  8313. #previousContainerHeight = 0;
  8314. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  8315. #scrollModePageState = null;
  8316. #onVisibilityChange = null;
  8317. #scaleTimeoutId = null;
  8318. constructor(options) {
  8319. const viewerVersion = '3.3.122';
  8320. if (_pdfjsLib.version !== viewerVersion) {
  8321. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  8322. }
  8323. this.container = options.container;
  8324. this.viewer = options.viewer || options.container.firstElementChild;
  8325. if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
  8326. throw new Error("Invalid `container` and/or `viewer` option.");
  8327. }
  8328. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  8329. throw new Error("The `container` must be absolutely positioned.");
  8330. }
  8331. this.#resizeObserver.observe(this.container);
  8332. this.eventBus = options.eventBus;
  8333. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8334. this.downloadManager = options.downloadManager || null;
  8335. this.findController = options.findController || null;
  8336. this._scriptingManager = options.scriptingManager || null;
  8337. this.removePageBorders = options.removePageBorders || false;
  8338. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  8339. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8340. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
  8341. this.imageResourcesPath = options.imageResourcesPath || "";
  8342. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8343. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  8344. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  8345. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  8346. this.maxCanvasPixels = options.maxCanvasPixels;
  8347. this.l10n = options.l10n || _l10n_utils.NullL10n;
  8348. this.#enablePermissions = options.enablePermissions || false;
  8349. this.pageColors = options.pageColors || null;
  8350. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  8351. if (this.pageColors.background || this.pageColors.foreground) {
  8352. console.warn("PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  8353. }
  8354. this.pageColors = null;
  8355. }
  8356. this.defaultRenderingQueue = !options.renderingQueue;
  8357. if (this.defaultRenderingQueue) {
  8358. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8359. this.renderingQueue.setViewer(this);
  8360. } else {
  8361. this.renderingQueue = options.renderingQueue;
  8362. }
  8363. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8364. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8365. this._onBeforeDraw = this._onAfterDraw = null;
  8366. this._resetView();
  8367. if (this.removePageBorders) {
  8368. this.viewer.classList.add("removePageBorders");
  8369. }
  8370. this.#updateContainerHeightCss();
  8371. }
  8372. get pagesCount() {
  8373. return this._pages.length;
  8374. }
  8375. getPageView(index) {
  8376. return this._pages[index];
  8377. }
  8378. get pageViewsReady() {
  8379. if (!this._pagesCapability.settled) {
  8380. return false;
  8381. }
  8382. return this._pages.every(function (pageView) {
  8383. return pageView?.pdfPage;
  8384. });
  8385. }
  8386. get renderForms() {
  8387. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8388. }
  8389. get enableScripting() {
  8390. return !!this._scriptingManager;
  8391. }
  8392. get currentPageNumber() {
  8393. return this._currentPageNumber;
  8394. }
  8395. set currentPageNumber(val) {
  8396. if (!Number.isInteger(val)) {
  8397. throw new Error("Invalid page number.");
  8398. }
  8399. if (!this.pdfDocument) {
  8400. return;
  8401. }
  8402. if (!this._setCurrentPageNumber(val, true)) {
  8403. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  8404. }
  8405. }
  8406. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  8407. if (this._currentPageNumber === val) {
  8408. if (resetCurrentPageView) {
  8409. this.#resetCurrentPageView();
  8410. }
  8411. return true;
  8412. }
  8413. if (!(0 < val && val <= this.pagesCount)) {
  8414. return false;
  8415. }
  8416. const previous = this._currentPageNumber;
  8417. this._currentPageNumber = val;
  8418. this.eventBus.dispatch("pagechanging", {
  8419. source: this,
  8420. pageNumber: val,
  8421. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8422. previous
  8423. });
  8424. if (resetCurrentPageView) {
  8425. this.#resetCurrentPageView();
  8426. }
  8427. return true;
  8428. }
  8429. get currentPageLabel() {
  8430. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8431. }
  8432. set currentPageLabel(val) {
  8433. if (!this.pdfDocument) {
  8434. return;
  8435. }
  8436. let page = val | 0;
  8437. if (this._pageLabels) {
  8438. const i = this._pageLabels.indexOf(val);
  8439. if (i >= 0) {
  8440. page = i + 1;
  8441. }
  8442. }
  8443. if (!this._setCurrentPageNumber(page, true)) {
  8444. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8445. }
  8446. }
  8447. get currentScale() {
  8448. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8449. }
  8450. set currentScale(val) {
  8451. if (isNaN(val)) {
  8452. throw new Error("Invalid numeric scale.");
  8453. }
  8454. if (!this.pdfDocument) {
  8455. return;
  8456. }
  8457. this._setScale(val, {
  8458. noScroll: false
  8459. });
  8460. }
  8461. get currentScaleValue() {
  8462. return this._currentScaleValue;
  8463. }
  8464. set currentScaleValue(val) {
  8465. if (!this.pdfDocument) {
  8466. return;
  8467. }
  8468. this._setScale(val, {
  8469. noScroll: false
  8470. });
  8471. }
  8472. get pagesRotation() {
  8473. return this._pagesRotation;
  8474. }
  8475. set pagesRotation(rotation) {
  8476. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8477. throw new Error("Invalid pages rotation angle.");
  8478. }
  8479. if (!this.pdfDocument) {
  8480. return;
  8481. }
  8482. rotation %= 360;
  8483. if (rotation < 0) {
  8484. rotation += 360;
  8485. }
  8486. if (this._pagesRotation === rotation) {
  8487. return;
  8488. }
  8489. this._pagesRotation = rotation;
  8490. const pageNumber = this._currentPageNumber;
  8491. this.refresh(true, {
  8492. rotation
  8493. });
  8494. if (this._currentScaleValue) {
  8495. this._setScale(this._currentScaleValue, {
  8496. noScroll: true
  8497. });
  8498. }
  8499. this.eventBus.dispatch("rotationchanging", {
  8500. source: this,
  8501. pagesRotation: rotation,
  8502. pageNumber
  8503. });
  8504. if (this.defaultRenderingQueue) {
  8505. this.update();
  8506. }
  8507. }
  8508. get firstPagePromise() {
  8509. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8510. }
  8511. get onePageRendered() {
  8512. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8513. }
  8514. get pagesPromise() {
  8515. return this.pdfDocument ? this._pagesCapability.promise : null;
  8516. }
  8517. #layerProperties() {
  8518. const self = this;
  8519. return {
  8520. get annotationEditorUIManager() {
  8521. return self.#annotationEditorUIManager;
  8522. },
  8523. get annotationStorage() {
  8524. return self.pdfDocument?.annotationStorage;
  8525. },
  8526. get downloadManager() {
  8527. return self.downloadManager;
  8528. },
  8529. get enableScripting() {
  8530. return !!self._scriptingManager;
  8531. },
  8532. get fieldObjectsPromise() {
  8533. return self.pdfDocument?.getFieldObjects();
  8534. },
  8535. get findController() {
  8536. return self.findController;
  8537. },
  8538. get hasJSActionsPromise() {
  8539. return self.pdfDocument?.hasJSActions();
  8540. },
  8541. get linkService() {
  8542. return self.linkService;
  8543. }
  8544. };
  8545. }
  8546. #initializePermissions(permissions) {
  8547. const params = {
  8548. annotationEditorMode: this.#annotationEditorMode,
  8549. annotationMode: this.#annotationMode,
  8550. textLayerMode: this.textLayerMode
  8551. };
  8552. if (!permissions) {
  8553. return params;
  8554. }
  8555. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  8556. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  8557. }
  8558. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  8559. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8560. }
  8561. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8562. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8563. }
  8564. return params;
  8565. }
  8566. #onePageRenderedOrForceFetch() {
  8567. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8568. return Promise.resolve();
  8569. }
  8570. const visibilityChangePromise = new Promise(resolve => {
  8571. this.#onVisibilityChange = () => {
  8572. if (document.visibilityState !== "hidden") {
  8573. return;
  8574. }
  8575. resolve();
  8576. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8577. this.#onVisibilityChange = null;
  8578. };
  8579. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8580. });
  8581. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8582. }
  8583. setDocument(pdfDocument) {
  8584. if (this.pdfDocument) {
  8585. this.eventBus.dispatch("pagesdestroy", {
  8586. source: this
  8587. });
  8588. this._cancelRendering();
  8589. this._resetView();
  8590. this.findController?.setDocument(null);
  8591. this._scriptingManager?.setDocument(null);
  8592. if (this.#annotationEditorUIManager) {
  8593. this.#annotationEditorUIManager.destroy();
  8594. this.#annotationEditorUIManager = null;
  8595. }
  8596. }
  8597. this.pdfDocument = pdfDocument;
  8598. if (!pdfDocument) {
  8599. return;
  8600. }
  8601. const pagesCount = pdfDocument.numPages;
  8602. const firstPagePromise = pdfDocument.getPage(1);
  8603. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8604. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8605. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8606. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8607. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8608. this.eventBus.dispatch("scrollmodechanged", {
  8609. source: this,
  8610. mode
  8611. });
  8612. }
  8613. this._pagesCapability.promise.then(() => {
  8614. this.eventBus.dispatch("pagesloaded", {
  8615. source: this,
  8616. pagesCount
  8617. });
  8618. }, () => { });
  8619. this._onBeforeDraw = evt => {
  8620. const pageView = this._pages[evt.pageNumber - 1];
  8621. if (!pageView) {
  8622. return;
  8623. }
  8624. this.#buffer.push(pageView);
  8625. };
  8626. this.eventBus._on("pagerender", this._onBeforeDraw);
  8627. this._onAfterDraw = evt => {
  8628. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8629. return;
  8630. }
  8631. this._onePageRenderedCapability.resolve({
  8632. timestamp: evt.timestamp
  8633. });
  8634. this.eventBus._off("pagerendered", this._onAfterDraw);
  8635. this._onAfterDraw = null;
  8636. if (this.#onVisibilityChange) {
  8637. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8638. this.#onVisibilityChange = null;
  8639. }
  8640. };
  8641. this.eventBus._on("pagerendered", this._onAfterDraw);
  8642. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8643. if (pdfDocument !== this.pdfDocument) {
  8644. return;
  8645. }
  8646. this._firstPageCapability.resolve(firstPdfPage);
  8647. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8648. const {
  8649. annotationEditorMode,
  8650. annotationMode,
  8651. textLayerMode
  8652. } = this.#initializePermissions(permissions);
  8653. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  8654. const mode = annotationEditorMode;
  8655. if (pdfDocument.isPureXfa) {
  8656. console.warn("Warning: XFA-editing is not implemented.");
  8657. } else if (isValidAnnotationEditorMode(mode)) {
  8658. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus, pdfDocument?.annotationStorage);
  8659. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  8660. this.#annotationEditorUIManager.updateMode(mode);
  8661. }
  8662. } else {
  8663. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  8664. }
  8665. }
  8666. const layerProperties = this.#layerProperties.bind(this);
  8667. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8668. const scale = this.currentScale;
  8669. const viewport = firstPdfPage.getViewport({
  8670. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8671. });
  8672. this.viewer.style.setProperty("--scale-factor", viewport.scale);
  8673. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8674. const pageView = new _pdf_page_view.PDFPageView({
  8675. container: viewerElement,
  8676. eventBus: this.eventBus,
  8677. id: pageNum,
  8678. scale,
  8679. defaultViewport: viewport.clone(),
  8680. optionalContentConfigPromise,
  8681. renderingQueue: this.renderingQueue,
  8682. textLayerMode,
  8683. annotationMode,
  8684. imageResourcesPath: this.imageResourcesPath,
  8685. renderer: this.renderer,
  8686. useOnlyCssZoom: this.useOnlyCssZoom,
  8687. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  8688. maxCanvasPixels: this.maxCanvasPixels,
  8689. pageColors: this.pageColors,
  8690. l10n: this.l10n,
  8691. layerProperties
  8692. });
  8693. this._pages.push(pageView);
  8694. }
  8695. const firstPageView = this._pages[0];
  8696. if (firstPageView) {
  8697. firstPageView.setPdfPage(firstPdfPage);
  8698. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8699. }
  8700. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8701. this.#ensurePageViewVisible();
  8702. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8703. this._updateSpreadMode();
  8704. }
  8705. this.#onePageRenderedOrForceFetch().then(async () => {
  8706. this.findController?.setDocument(pdfDocument);
  8707. this._scriptingManager?.setDocument(pdfDocument);
  8708. if (this.#annotationEditorUIManager) {
  8709. this.eventBus.dispatch("annotationeditormodechanged", {
  8710. source: this,
  8711. mode: this.#annotationEditorMode
  8712. });
  8713. }
  8714. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8715. this._pagesCapability.resolve();
  8716. return;
  8717. }
  8718. let getPagesLeft = pagesCount - 1;
  8719. if (getPagesLeft <= 0) {
  8720. this._pagesCapability.resolve();
  8721. return;
  8722. }
  8723. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8724. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8725. const pageView = this._pages[pageNum - 1];
  8726. if (!pageView.pdfPage) {
  8727. pageView.setPdfPage(pdfPage);
  8728. }
  8729. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8730. if (--getPagesLeft === 0) {
  8731. this._pagesCapability.resolve();
  8732. }
  8733. }, reason => {
  8734. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8735. if (--getPagesLeft === 0) {
  8736. this._pagesCapability.resolve();
  8737. }
  8738. });
  8739. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8740. await promise;
  8741. }
  8742. }
  8743. });
  8744. this.eventBus.dispatch("pagesinit", {
  8745. source: this
  8746. });
  8747. pdfDocument.getMetadata().then(({
  8748. info
  8749. }) => {
  8750. if (pdfDocument !== this.pdfDocument) {
  8751. return;
  8752. }
  8753. if (info.Language) {
  8754. this.viewer.lang = info.Language;
  8755. }
  8756. });
  8757. if (this.defaultRenderingQueue) {
  8758. this.update();
  8759. }
  8760. }).catch(reason => {
  8761. console.error("Unable to initialize viewer", reason);
  8762. this._pagesCapability.reject(reason);
  8763. });
  8764. }
  8765. setPageLabels(labels) {
  8766. if (!this.pdfDocument) {
  8767. return;
  8768. }
  8769. if (!labels) {
  8770. this._pageLabels = null;
  8771. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8772. this._pageLabels = null;
  8773. console.error(`setPageLabels: Invalid page labels.`);
  8774. } else {
  8775. this._pageLabels = labels;
  8776. }
  8777. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8778. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8779. }
  8780. }
  8781. _resetView() {
  8782. this._pages = [];
  8783. this._currentPageNumber = 1;
  8784. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8785. this._currentScaleValue = null;
  8786. this._pageLabels = null;
  8787. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8788. this._location = null;
  8789. this._pagesRotation = 0;
  8790. this._optionalContentConfigPromise = null;
  8791. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8792. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8793. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8794. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8795. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8796. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8797. this.#scrollModePageState = {
  8798. previousPageNumber: 1,
  8799. scrollDown: true,
  8800. pages: []
  8801. };
  8802. if (this._onBeforeDraw) {
  8803. this.eventBus._off("pagerender", this._onBeforeDraw);
  8804. this._onBeforeDraw = null;
  8805. }
  8806. if (this._onAfterDraw) {
  8807. this.eventBus._off("pagerendered", this._onAfterDraw);
  8808. this._onAfterDraw = null;
  8809. }
  8810. if (this.#onVisibilityChange) {
  8811. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8812. this.#onVisibilityChange = null;
  8813. }
  8814. this.viewer.textContent = "";
  8815. this._updateScrollMode();
  8816. this.viewer.removeAttribute("lang");
  8817. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  8818. }
  8819. #ensurePageViewVisible() {
  8820. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8821. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8822. }
  8823. const pageNumber = this._currentPageNumber,
  8824. state = this.#scrollModePageState,
  8825. viewer = this.viewer;
  8826. viewer.textContent = "";
  8827. state.pages.length = 0;
  8828. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8829. const pageView = this._pages[pageNumber - 1];
  8830. viewer.append(pageView.div);
  8831. state.pages.push(pageView);
  8832. } else {
  8833. const pageIndexSet = new Set(),
  8834. parity = this._spreadMode - 1;
  8835. if (parity === -1) {
  8836. pageIndexSet.add(pageNumber - 1);
  8837. } else if (pageNumber % 2 !== parity) {
  8838. pageIndexSet.add(pageNumber - 1);
  8839. pageIndexSet.add(pageNumber);
  8840. } else {
  8841. pageIndexSet.add(pageNumber - 2);
  8842. pageIndexSet.add(pageNumber - 1);
  8843. }
  8844. const spread = document.createElement("div");
  8845. spread.className = "spread";
  8846. if (this.isInPresentationMode) {
  8847. const dummyPage = document.createElement("div");
  8848. dummyPage.className = "dummyPage";
  8849. spread.append(dummyPage);
  8850. }
  8851. for (const i of pageIndexSet) {
  8852. const pageView = this._pages[i];
  8853. if (!pageView) {
  8854. continue;
  8855. }
  8856. spread.append(pageView.div);
  8857. state.pages.push(pageView);
  8858. }
  8859. viewer.append(spread);
  8860. }
  8861. state.scrollDown = pageNumber >= state.previousPageNumber;
  8862. state.previousPageNumber = pageNumber;
  8863. }
  8864. _scrollUpdate() {
  8865. if (this.pagesCount === 0) {
  8866. return;
  8867. }
  8868. this.update();
  8869. }
  8870. #scrollIntoView(pageView, pageSpot = null) {
  8871. const {
  8872. div,
  8873. id
  8874. } = pageView;
  8875. if (this._currentPageNumber !== id) {
  8876. this._setCurrentPageNumber(id);
  8877. }
  8878. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8879. this.#ensurePageViewVisible();
  8880. this.update();
  8881. }
  8882. if (!pageSpot && !this.isInPresentationMode) {
  8883. const left = div.offsetLeft + div.clientLeft,
  8884. right = left + div.clientWidth;
  8885. const {
  8886. scrollLeft,
  8887. clientWidth
  8888. } = this.container;
  8889. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8890. pageSpot = {
  8891. left: 0,
  8892. top: 0
  8893. };
  8894. }
  8895. }
  8896. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8897. if (!this._currentScaleValue && this._location) {
  8898. this._location = null;
  8899. }
  8900. }
  8901. #isSameScale(newScale) {
  8902. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8903. }
  8904. _setScaleUpdatePages(newScale, newValue, {
  8905. noScroll = false,
  8906. preset = false,
  8907. drawingDelay = -1
  8908. }) {
  8909. this._currentScaleValue = newValue.toString();
  8910. if (this.#isSameScale(newScale)) {
  8911. if (preset) {
  8912. this.eventBus.dispatch("scalechanging", {
  8913. source: this,
  8914. scale: newScale,
  8915. presetValue: newValue
  8916. });
  8917. }
  8918. return;
  8919. }
  8920. this.viewer.style.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8921. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  8922. this.refresh(true, {
  8923. scale: newScale,
  8924. drawingDelay: postponeDrawing ? drawingDelay : -1
  8925. });
  8926. if (postponeDrawing) {
  8927. this.#scaleTimeoutId = setTimeout(() => {
  8928. this.#scaleTimeoutId = null;
  8929. this.refresh();
  8930. }, drawingDelay);
  8931. }
  8932. this._currentScale = newScale;
  8933. if (!noScroll) {
  8934. let page = this._currentPageNumber,
  8935. dest;
  8936. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8937. page = this._location.pageNumber;
  8938. dest = [null, {
  8939. name: "XYZ"
  8940. }, this._location.left, this._location.top, null];
  8941. }
  8942. this.scrollPageIntoView({
  8943. pageNumber: page,
  8944. destArray: dest,
  8945. allowNegativeOffset: true
  8946. });
  8947. }
  8948. this.eventBus.dispatch("scalechanging", {
  8949. source: this,
  8950. scale: newScale,
  8951. presetValue: preset ? newValue : undefined
  8952. });
  8953. if (this.defaultRenderingQueue) {
  8954. this.update();
  8955. }
  8956. }
  8957. get _pageWidthScaleFactor() {
  8958. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8959. return 2;
  8960. }
  8961. return 1;
  8962. }
  8963. _setScale(value, options) {
  8964. let scale = parseFloat(value);
  8965. if (scale > 0) {
  8966. options.preset = false;
  8967. this._setScaleUpdatePages(scale, value, options);
  8968. } else {
  8969. const currentPage = this._pages[this._currentPageNumber - 1];
  8970. if (!currentPage) {
  8971. return;
  8972. }
  8973. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8974. vPadding = _ui_utils.VERTICAL_PADDING;
  8975. if (this.isInPresentationMode) {
  8976. hPadding = vPadding = 4;
  8977. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8978. hPadding *= 2;
  8979. }
  8980. } else if (this.removePageBorders) {
  8981. hPadding = vPadding = 0;
  8982. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8983. [hPadding, vPadding] = [vPadding, hPadding];
  8984. }
  8985. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8986. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8987. switch (value) {
  8988. case "page-actual":
  8989. scale = 1;
  8990. break;
  8991. case "page-width":
  8992. scale = pageWidthScale;
  8993. break;
  8994. case "page-height":
  8995. scale = pageHeightScale;
  8996. break;
  8997. case "page-fit":
  8998. scale = Math.min(pageWidthScale, pageHeightScale);
  8999. break;
  9000. case "auto":
  9001. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  9002. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  9003. break;
  9004. default:
  9005. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  9006. return;
  9007. }
  9008. options.preset = true;
  9009. this._setScaleUpdatePages(scale, value, options);
  9010. }
  9011. }
  9012. #resetCurrentPageView() {
  9013. const pageView = this._pages[this._currentPageNumber - 1];
  9014. if (this.isInPresentationMode) {
  9015. this._setScale(this._currentScaleValue, {
  9016. noScroll: true
  9017. });
  9018. }
  9019. this.#scrollIntoView(pageView);
  9020. }
  9021. pageLabelToPageNumber(label) {
  9022. if (!this._pageLabels) {
  9023. return null;
  9024. }
  9025. const i = this._pageLabels.indexOf(label);
  9026. if (i < 0) {
  9027. return null;
  9028. }
  9029. return i + 1;
  9030. }
  9031. scrollPageIntoView({
  9032. pageNumber,
  9033. destArray = null,
  9034. allowNegativeOffset = false,
  9035. ignoreDestinationZoom = false
  9036. }) {
  9037. if (!this.pdfDocument) {
  9038. return;
  9039. }
  9040. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  9041. if (!pageView) {
  9042. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  9043. return;
  9044. }
  9045. if (this.isInPresentationMode || !destArray) {
  9046. this._setCurrentPageNumber(pageNumber, true);
  9047. return;
  9048. }
  9049. let x = 0,
  9050. y = 0;
  9051. let width = 0,
  9052. height = 0,
  9053. widthScale,
  9054. heightScale;
  9055. const changeOrientation = pageView.rotation % 180 !== 0;
  9056. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9057. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9058. let scale = 0;
  9059. switch (destArray[1].name) {
  9060. case "XYZ":
  9061. x = destArray[2];
  9062. y = destArray[3];
  9063. scale = destArray[4];
  9064. x = x !== null ? x : 0;
  9065. y = y !== null ? y : pageHeight;
  9066. break;
  9067. case "Fit":
  9068. case "FitB":
  9069. scale = "page-fit";
  9070. break;
  9071. case "FitH":
  9072. case "FitBH":
  9073. y = destArray[2];
  9074. scale = "page-width";
  9075. if (y === null && this._location) {
  9076. x = this._location.left;
  9077. y = this._location.top;
  9078. } else if (typeof y !== "number" || y < 0) {
  9079. y = pageHeight;
  9080. }
  9081. break;
  9082. case "FitV":
  9083. case "FitBV":
  9084. x = destArray[2];
  9085. width = pageWidth;
  9086. height = pageHeight;
  9087. scale = "page-height";
  9088. break;
  9089. case "FitR":
  9090. x = destArray[2];
  9091. y = destArray[3];
  9092. width = destArray[4] - x;
  9093. height = destArray[5] - y;
  9094. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  9095. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  9096. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9097. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9098. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  9099. break;
  9100. default:
  9101. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  9102. return;
  9103. }
  9104. if (!ignoreDestinationZoom) {
  9105. if (scale && scale !== this._currentScale) {
  9106. this.currentScaleValue = scale;
  9107. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  9108. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  9109. }
  9110. }
  9111. if (scale === "page-fit" && !destArray[4]) {
  9112. this.#scrollIntoView(pageView);
  9113. return;
  9114. }
  9115. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  9116. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  9117. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  9118. if (!allowNegativeOffset) {
  9119. left = Math.max(left, 0);
  9120. top = Math.max(top, 0);
  9121. }
  9122. this.#scrollIntoView(pageView, {
  9123. left,
  9124. top
  9125. });
  9126. }
  9127. _updateLocation(firstPage) {
  9128. const currentScale = this._currentScale;
  9129. const currentScaleValue = this._currentScaleValue;
  9130. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  9131. const pageNumber = firstPage.id;
  9132. const currentPageView = this._pages[pageNumber - 1];
  9133. const container = this.container;
  9134. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  9135. const intLeft = Math.round(topLeft[0]);
  9136. const intTop = Math.round(topLeft[1]);
  9137. let pdfOpenParams = `#page=${pageNumber}`;
  9138. if (!this.isInPresentationMode) {
  9139. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  9140. }
  9141. this._location = {
  9142. pageNumber,
  9143. scale: normalizedScaleValue,
  9144. top: intTop,
  9145. left: intLeft,
  9146. rotation: this._pagesRotation,
  9147. pdfOpenParams
  9148. };
  9149. }
  9150. update() {
  9151. const visible = this._getVisiblePages();
  9152. const visiblePages = visible.views,
  9153. numVisiblePages = visiblePages.length;
  9154. if (numVisiblePages === 0) {
  9155. return;
  9156. }
  9157. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  9158. this.#buffer.resize(newCacheSize, visible.ids);
  9159. this.renderingQueue.renderHighestPriority(visible);
  9160. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  9161. const currentId = this._currentPageNumber;
  9162. let stillFullyVisible = false;
  9163. for (const page of visiblePages) {
  9164. if (page.percent < 100) {
  9165. break;
  9166. }
  9167. if (page.id === currentId && isSimpleLayout) {
  9168. stillFullyVisible = true;
  9169. break;
  9170. }
  9171. }
  9172. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  9173. this._updateLocation(visible.first);
  9174. this.eventBus.dispatch("updateviewarea", {
  9175. source: this,
  9176. location: this._location
  9177. });
  9178. }
  9179. containsElement(element) {
  9180. return this.container.contains(element);
  9181. }
  9182. focus() {
  9183. this.container.focus();
  9184. }
  9185. get _isContainerRtl() {
  9186. return getComputedStyle(this.container).direction === "rtl";
  9187. }
  9188. get isInPresentationMode() {
  9189. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  9190. }
  9191. get isChangingPresentationMode() {
  9192. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  9193. }
  9194. get isHorizontalScrollbarEnabled() {
  9195. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  9196. }
  9197. get isVerticalScrollbarEnabled() {
  9198. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  9199. }
  9200. _getVisiblePages() {
  9201. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  9202. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  9203. rtl = horizontal && this._isContainerRtl;
  9204. return (0, _ui_utils.getVisibleElements)({
  9205. scrollEl: this.container,
  9206. views,
  9207. sortByVisibility: true,
  9208. horizontal,
  9209. rtl
  9210. });
  9211. }
  9212. isPageVisible(pageNumber) {
  9213. if (!this.pdfDocument) {
  9214. return false;
  9215. }
  9216. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  9217. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  9218. return false;
  9219. }
  9220. return this._getVisiblePages().ids.has(pageNumber);
  9221. }
  9222. isPageCached(pageNumber) {
  9223. if (!this.pdfDocument) {
  9224. return false;
  9225. }
  9226. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  9227. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  9228. return false;
  9229. }
  9230. const pageView = this._pages[pageNumber - 1];
  9231. return this.#buffer.has(pageView);
  9232. }
  9233. cleanup() {
  9234. for (const pageView of this._pages) {
  9235. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  9236. pageView.reset();
  9237. }
  9238. }
  9239. }
  9240. _cancelRendering() {
  9241. for (const pageView of this._pages) {
  9242. pageView.cancelRendering();
  9243. }
  9244. }
  9245. async #ensurePdfPageLoaded(pageView) {
  9246. if (pageView.pdfPage) {
  9247. return pageView.pdfPage;
  9248. }
  9249. try {
  9250. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  9251. if (!pageView.pdfPage) {
  9252. pageView.setPdfPage(pdfPage);
  9253. }
  9254. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  9255. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  9256. }
  9257. return pdfPage;
  9258. } catch (reason) {
  9259. console.error("Unable to get page for page view", reason);
  9260. return null;
  9261. }
  9262. }
  9263. #getScrollAhead(visible) {
  9264. if (visible.first?.id === 1) {
  9265. return true;
  9266. } else if (visible.last?.id === this.pagesCount) {
  9267. return false;
  9268. }
  9269. switch (this._scrollMode) {
  9270. case _ui_utils.ScrollMode.PAGE:
  9271. return this.#scrollModePageState.scrollDown;
  9272. case _ui_utils.ScrollMode.HORIZONTAL:
  9273. return this.scroll.right;
  9274. }
  9275. return this.scroll.down;
  9276. }
  9277. forceRendering(currentlyVisiblePages) {
  9278. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9279. const scrollAhead = this.#getScrollAhead(visiblePages);
  9280. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9281. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9282. if (pageView) {
  9283. this.#ensurePdfPageLoaded(pageView).then(() => {
  9284. this.renderingQueue.renderView(pageView);
  9285. });
  9286. return true;
  9287. }
  9288. return false;
  9289. }
  9290. get hasEqualPageSizes() {
  9291. const firstPageView = this._pages[0];
  9292. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  9293. const pageView = this._pages[i];
  9294. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9295. return false;
  9296. }
  9297. }
  9298. return true;
  9299. }
  9300. getPagesOverview() {
  9301. return this._pages.map(pageView => {
  9302. const viewport = pageView.pdfPage.getViewport({
  9303. scale: 1
  9304. });
  9305. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  9306. return {
  9307. width: viewport.width,
  9308. height: viewport.height,
  9309. rotation: viewport.rotation
  9310. };
  9311. }
  9312. return {
  9313. width: viewport.height,
  9314. height: viewport.width,
  9315. rotation: (viewport.rotation - 90) % 360
  9316. };
  9317. });
  9318. }
  9319. get optionalContentConfigPromise() {
  9320. if (!this.pdfDocument) {
  9321. return Promise.resolve(null);
  9322. }
  9323. if (!this._optionalContentConfigPromise) {
  9324. console.error("optionalContentConfigPromise: Not initialized yet.");
  9325. return this.pdfDocument.getOptionalContentConfig();
  9326. }
  9327. return this._optionalContentConfigPromise;
  9328. }
  9329. set optionalContentConfigPromise(promise) {
  9330. if (!(promise instanceof Promise)) {
  9331. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  9332. }
  9333. if (!this.pdfDocument) {
  9334. return;
  9335. }
  9336. if (!this._optionalContentConfigPromise) {
  9337. return;
  9338. }
  9339. this._optionalContentConfigPromise = promise;
  9340. this.refresh(false, {
  9341. optionalContentConfigPromise: promise
  9342. });
  9343. this.eventBus.dispatch("optionalcontentconfigchanged", {
  9344. source: this,
  9345. promise
  9346. });
  9347. }
  9348. get scrollMode() {
  9349. return this._scrollMode;
  9350. }
  9351. set scrollMode(mode) {
  9352. if (this._scrollMode === mode) {
  9353. return;
  9354. }
  9355. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9356. throw new Error(`Invalid scroll mode: ${mode}`);
  9357. }
  9358. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9359. return;
  9360. }
  9361. this._previousScrollMode = this._scrollMode;
  9362. this._scrollMode = mode;
  9363. this.eventBus.dispatch("scrollmodechanged", {
  9364. source: this,
  9365. mode
  9366. });
  9367. this._updateScrollMode(this._currentPageNumber);
  9368. }
  9369. _updateScrollMode(pageNumber = null) {
  9370. const scrollMode = this._scrollMode,
  9371. viewer = this.viewer;
  9372. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9373. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9374. if (!this.pdfDocument || !pageNumber) {
  9375. return;
  9376. }
  9377. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9378. this.#ensurePageViewVisible();
  9379. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9380. this._updateSpreadMode();
  9381. }
  9382. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9383. this._setScale(this._currentScaleValue, {
  9384. noScroll: true
  9385. });
  9386. }
  9387. this._setCurrentPageNumber(pageNumber, true);
  9388. this.update();
  9389. }
  9390. get spreadMode() {
  9391. return this._spreadMode;
  9392. }
  9393. set spreadMode(mode) {
  9394. if (this._spreadMode === mode) {
  9395. return;
  9396. }
  9397. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9398. throw new Error(`Invalid spread mode: ${mode}`);
  9399. }
  9400. this._spreadMode = mode;
  9401. this.eventBus.dispatch("spreadmodechanged", {
  9402. source: this,
  9403. mode
  9404. });
  9405. this._updateSpreadMode(this._currentPageNumber);
  9406. }
  9407. _updateSpreadMode(pageNumber = null) {
  9408. if (!this.pdfDocument) {
  9409. return;
  9410. }
  9411. const viewer = this.viewer,
  9412. pages = this._pages;
  9413. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9414. this.#ensurePageViewVisible();
  9415. } else {
  9416. viewer.textContent = "";
  9417. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9418. for (const pageView of this._pages) {
  9419. viewer.append(pageView.div);
  9420. }
  9421. } else {
  9422. const parity = this._spreadMode - 1;
  9423. let spread = null;
  9424. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9425. if (spread === null) {
  9426. spread = document.createElement("div");
  9427. spread.className = "spread";
  9428. viewer.append(spread);
  9429. } else if (i % 2 === parity) {
  9430. spread = spread.cloneNode(false);
  9431. viewer.append(spread);
  9432. }
  9433. spread.append(pages[i].div);
  9434. }
  9435. }
  9436. }
  9437. if (!pageNumber) {
  9438. return;
  9439. }
  9440. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9441. this._setScale(this._currentScaleValue, {
  9442. noScroll: true
  9443. });
  9444. }
  9445. this._setCurrentPageNumber(pageNumber, true);
  9446. this.update();
  9447. }
  9448. _getPageAdvance(currentPageNumber, previous = false) {
  9449. switch (this._scrollMode) {
  9450. case _ui_utils.ScrollMode.WRAPPED:
  9451. {
  9452. const {
  9453. views
  9454. } = this._getVisiblePages(),
  9455. pageLayout = new Map();
  9456. for (const {
  9457. id,
  9458. y,
  9459. percent,
  9460. widthPercent
  9461. } of views) {
  9462. if (percent === 0 || widthPercent < 100) {
  9463. continue;
  9464. }
  9465. let yArray = pageLayout.get(y);
  9466. if (!yArray) {
  9467. pageLayout.set(y, yArray ||= []);
  9468. }
  9469. yArray.push(id);
  9470. }
  9471. for (const yArray of pageLayout.values()) {
  9472. const currentIndex = yArray.indexOf(currentPageNumber);
  9473. if (currentIndex === -1) {
  9474. continue;
  9475. }
  9476. const numPages = yArray.length;
  9477. if (numPages === 1) {
  9478. break;
  9479. }
  9480. if (previous) {
  9481. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9482. const currentId = yArray[i],
  9483. expectedId = yArray[i + 1] - 1;
  9484. if (currentId < expectedId) {
  9485. return currentPageNumber - expectedId;
  9486. }
  9487. }
  9488. } else {
  9489. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9490. const currentId = yArray[i],
  9491. expectedId = yArray[i - 1] + 1;
  9492. if (currentId > expectedId) {
  9493. return expectedId - currentPageNumber;
  9494. }
  9495. }
  9496. }
  9497. if (previous) {
  9498. const firstId = yArray[0];
  9499. if (firstId < currentPageNumber) {
  9500. return currentPageNumber - firstId + 1;
  9501. }
  9502. } else {
  9503. const lastId = yArray[numPages - 1];
  9504. if (lastId > currentPageNumber) {
  9505. return lastId - currentPageNumber + 1;
  9506. }
  9507. }
  9508. break;
  9509. }
  9510. break;
  9511. }
  9512. case _ui_utils.ScrollMode.HORIZONTAL:
  9513. {
  9514. break;
  9515. }
  9516. case _ui_utils.ScrollMode.PAGE:
  9517. case _ui_utils.ScrollMode.VERTICAL:
  9518. {
  9519. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9520. break;
  9521. }
  9522. const parity = this._spreadMode - 1;
  9523. if (previous && currentPageNumber % 2 !== parity) {
  9524. break;
  9525. } else if (!previous && currentPageNumber % 2 === parity) {
  9526. break;
  9527. }
  9528. const {
  9529. views
  9530. } = this._getVisiblePages(),
  9531. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9532. for (const {
  9533. id,
  9534. percent,
  9535. widthPercent
  9536. } of views) {
  9537. if (id !== expectedId) {
  9538. continue;
  9539. }
  9540. if (percent > 0 && widthPercent === 100) {
  9541. return 2;
  9542. }
  9543. break;
  9544. }
  9545. break;
  9546. }
  9547. }
  9548. return 1;
  9549. }
  9550. nextPage() {
  9551. const currentPageNumber = this._currentPageNumber,
  9552. pagesCount = this.pagesCount;
  9553. if (currentPageNumber >= pagesCount) {
  9554. return false;
  9555. }
  9556. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9557. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9558. return true;
  9559. }
  9560. previousPage() {
  9561. const currentPageNumber = this._currentPageNumber;
  9562. if (currentPageNumber <= 1) {
  9563. return false;
  9564. }
  9565. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9566. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9567. return true;
  9568. }
  9569. increaseScale(options = null) {
  9570. if (typeof options === "number") {
  9571. console.error("The `increaseScale` method-signature was updated, please use an object instead.");
  9572. options = {
  9573. steps: options
  9574. };
  9575. }
  9576. if (!this.pdfDocument) {
  9577. return;
  9578. }
  9579. options ||= Object.create(null);
  9580. let newScale = this._currentScale;
  9581. if (options.scaleFactor > 1) {
  9582. newScale = Math.min(_ui_utils.MAX_SCALE, Math.round(newScale * options.scaleFactor * 100) / 100);
  9583. } else {
  9584. let steps = options.steps ?? 1;
  9585. do {
  9586. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9587. newScale = Math.ceil(newScale * 10) / 10;
  9588. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  9589. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9590. }
  9591. options.noScroll = false;
  9592. this._setScale(newScale, options);
  9593. }
  9594. decreaseScale(options = null) {
  9595. if (typeof options === "number") {
  9596. console.error("The `decreaseScale` method-signature was updated, please use an object instead.");
  9597. options = {
  9598. steps: options
  9599. };
  9600. }
  9601. if (!this.pdfDocument) {
  9602. return;
  9603. }
  9604. options ||= Object.create(null);
  9605. let newScale = this._currentScale;
  9606. if (options.scaleFactor > 0 && options.scaleFactor < 1) {
  9607. newScale = Math.max(_ui_utils.MIN_SCALE, Math.round(newScale * options.scaleFactor * 100) / 100);
  9608. } else {
  9609. let steps = options.steps ?? 1;
  9610. do {
  9611. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9612. newScale = Math.floor(newScale * 10) / 10;
  9613. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  9614. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9615. }
  9616. options.noScroll = false;
  9617. this._setScale(newScale, options);
  9618. }
  9619. #updateContainerHeightCss(height = this.container.clientHeight) {
  9620. if (height !== this.#previousContainerHeight) {
  9621. this.#previousContainerHeight = height;
  9622. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  9623. }
  9624. }
  9625. #resizeObserverCallback(entries) {
  9626. for (const entry of entries) {
  9627. if (entry.target === this.container) {
  9628. this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
  9629. this.#containerTopLeft = null;
  9630. break;
  9631. }
  9632. }
  9633. }
  9634. get containerTopLeft() {
  9635. return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
  9636. }
  9637. get annotationEditorMode() {
  9638. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  9639. }
  9640. set annotationEditorMode(mode) {
  9641. if (!this.#annotationEditorUIManager) {
  9642. throw new Error(`The AnnotationEditor is not enabled.`);
  9643. }
  9644. if (this.#annotationEditorMode === mode) {
  9645. return;
  9646. }
  9647. if (!isValidAnnotationEditorMode(mode)) {
  9648. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  9649. }
  9650. if (!this.pdfDocument) {
  9651. return;
  9652. }
  9653. this.#annotationEditorMode = mode;
  9654. this.eventBus.dispatch("annotationeditormodechanged", {
  9655. source: this,
  9656. mode
  9657. });
  9658. this.#annotationEditorUIManager.updateMode(mode);
  9659. }
  9660. set annotationEditorParams({
  9661. type,
  9662. value
  9663. }) {
  9664. if (!this.#annotationEditorUIManager) {
  9665. throw new Error(`The AnnotationEditor is not enabled.`);
  9666. }
  9667. this.#annotationEditorUIManager.updateParams(type, value);
  9668. }
  9669. refresh(noUpdate = false, updateArgs = Object.create(null)) {
  9670. if (!this.pdfDocument) {
  9671. return;
  9672. }
  9673. for (const pageView of this._pages) {
  9674. pageView.update(updateArgs);
  9675. }
  9676. if (this.#scaleTimeoutId !== null) {
  9677. clearTimeout(this.#scaleTimeoutId);
  9678. this.#scaleTimeoutId = null;
  9679. }
  9680. if (!noUpdate) {
  9681. this.update();
  9682. }
  9683. }
  9684. }
  9685. exports.PDFViewer = PDFViewer;
  9686. /***/
  9687. }),
  9688. /* 29 */
  9689. /***/ ((__unused_webpack_module, exports) => {
  9690. Object.defineProperty(exports, "__esModule", ({
  9691. value: true
  9692. }));
  9693. exports.NullL10n = void 0;
  9694. exports.fixupLangCode = fixupLangCode;
  9695. exports.getL10nFallback = getL10nFallback;
  9696. const DEFAULT_L10N_STRINGS = {
  9697. of_pages: "of {{pagesCount}}",
  9698. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9699. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9700. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9701. document_properties_date_string: "{{date}}, {{time}}",
  9702. document_properties_page_size_unit_inches: "in",
  9703. document_properties_page_size_unit_millimeters: "mm",
  9704. document_properties_page_size_orientation_portrait: "portrait",
  9705. document_properties_page_size_orientation_landscape: "landscape",
  9706. document_properties_page_size_name_a3: "A3",
  9707. document_properties_page_size_name_a4: "A4",
  9708. document_properties_page_size_name_letter: "Letter",
  9709. document_properties_page_size_name_legal: "Legal",
  9710. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9711. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9712. document_properties_linearized_yes: "Yes",
  9713. document_properties_linearized_no: "No",
  9714. additional_layers: "Additional Layers",
  9715. page_landmark: "Page {{page}}",
  9716. thumb_page_title: "Page {{page}}",
  9717. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9718. find_reached_top: "Reached top of document, continued from bottom",
  9719. find_reached_bottom: "Reached end of document, continued from top",
  9720. "find_match_count[one]": "{{current}} of {{total}} match",
  9721. "find_match_count[other]": "{{current}} of {{total}} matches",
  9722. "find_match_count_limit[one]": "More than {{limit}} match",
  9723. "find_match_count_limit[other]": "More than {{limit}} matches",
  9724. find_not_found: "Phrase not found",
  9725. page_scale_width: "Page Width",
  9726. page_scale_fit: "Page Fit",
  9727. page_scale_auto: "Automatic Zoom",
  9728. page_scale_actual: "Actual Size",
  9729. page_scale_percent: "{{scale}}%",
  9730. loading: "Loading…",
  9731. loading_error: "An error occurred while loading the PDF.",
  9732. invalid_file_error: "Invalid or corrupted PDF file.",
  9733. missing_file_error: "Missing PDF file.",
  9734. unexpected_response_error: "Unexpected server response.",
  9735. rendering_error: "An error occurred while rendering the page.",
  9736. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9737. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9738. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  9739. free_text2_default_content: "Start typing…",
  9740. editor_free_text2_aria_label: "Text Editor",
  9741. editor_ink2_aria_label: "Draw Editor",
  9742. editor_ink_canvas_aria_label: "User-created image"
  9743. };
  9744. {
  9745. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  9746. }
  9747. function getL10nFallback(key, args) {
  9748. switch (key) {
  9749. case "find_match_count":
  9750. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9751. break;
  9752. case "find_match_count_limit":
  9753. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9754. break;
  9755. }
  9756. return DEFAULT_L10N_STRINGS[key] || "";
  9757. }
  9758. const PARTIAL_LANG_CODES = {
  9759. en: "en-US",
  9760. es: "es-ES",
  9761. fy: "fy-NL",
  9762. ga: "ga-IE",
  9763. gu: "gu-IN",
  9764. hi: "hi-IN",
  9765. hy: "hy-AM",
  9766. nb: "nb-NO",
  9767. ne: "ne-NP",
  9768. nn: "nn-NO",
  9769. pa: "pa-IN",
  9770. pt: "pt-PT",
  9771. sv: "sv-SE",
  9772. zh: "zh-CN"
  9773. };
  9774. function fixupLangCode(langCode) {
  9775. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9776. }
  9777. function formatL10nValue(text, args) {
  9778. if (!args) {
  9779. return text;
  9780. }
  9781. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9782. return name in args ? args[name] : "{{" + name + "}}";
  9783. });
  9784. }
  9785. const NullL10n = {
  9786. async getLanguage() {
  9787. return "en-us";
  9788. },
  9789. async getDirection() {
  9790. return "ltr";
  9791. },
  9792. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9793. return formatL10nValue(fallback, args);
  9794. },
  9795. async translate(element) { }
  9796. };
  9797. exports.NullL10n = NullL10n;
  9798. /***/
  9799. }),
  9800. /* 30 */
  9801. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9802. Object.defineProperty(exports, "__esModule", ({
  9803. value: true
  9804. }));
  9805. exports.PDFPageView = void 0;
  9806. var _pdfjsLib = __webpack_require__(5);
  9807. var _ui_utils = __webpack_require__(1);
  9808. var _annotation_editor_layer_builder = __webpack_require__(31);
  9809. var _annotation_layer_builder = __webpack_require__(32);
  9810. var _app_options = __webpack_require__(2);
  9811. var _l10n_utils = __webpack_require__(29);
  9812. var _struct_tree_layer_builder = __webpack_require__(33);
  9813. var _text_accessibility = __webpack_require__(34);
  9814. var _text_highlighter = __webpack_require__(35);
  9815. var _text_layer_builder = __webpack_require__(36);
  9816. var _xfa_layer_builder = __webpack_require__(37);
  9817. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9818. const DEFAULT_LAYER_PROPERTIES = () => {
  9819. return null;
  9820. };
  9821. class PDFPageView {
  9822. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9823. #layerProperties = null;
  9824. #previousRotation = null;
  9825. #renderingState = _ui_utils.RenderingStates.INITIAL;
  9826. #useThumbnailCanvas = {
  9827. initialOptionalContent: true,
  9828. regularAnnotations: true
  9829. };
  9830. constructor(options) {
  9831. const container = options.container;
  9832. const defaultViewport = options.defaultViewport;
  9833. this.id = options.id;
  9834. this.renderingId = "page" + this.id;
  9835. this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
  9836. this.pdfPage = null;
  9837. this.pageLabel = null;
  9838. this.rotation = 0;
  9839. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9840. this.viewport = defaultViewport;
  9841. this.pdfPageRotate = defaultViewport.rotation;
  9842. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9843. this.hasRestrictedScaling = false;
  9844. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9845. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9846. this.imageResourcesPath = options.imageResourcesPath || "";
  9847. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9848. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  9849. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9850. this.pageColors = options.pageColors || null;
  9851. this.eventBus = options.eventBus;
  9852. this.renderingQueue = options.renderingQueue;
  9853. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9854. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9855. this.paintTask = null;
  9856. this.paintedViewportMap = new WeakMap();
  9857. this.resume = null;
  9858. this._renderError = null;
  9859. this._isStandalone = !this.renderingQueue?.hasViewer();
  9860. this._annotationCanvasMap = null;
  9861. this.annotationLayer = null;
  9862. this.annotationEditorLayer = null;
  9863. this.textLayer = null;
  9864. this.zoomLayer = null;
  9865. this.xfaLayer = null;
  9866. this.structTreeLayer = null;
  9867. const div = document.createElement("div");
  9868. div.className = "page";
  9869. div.setAttribute("data-page-number", this.id);
  9870. div.setAttribute("role", "region");
  9871. this.l10n.get("page_landmark", {
  9872. page: this.id
  9873. }).then(msg => {
  9874. div.setAttribute("aria-label", msg);
  9875. });
  9876. this.div = div;
  9877. this.#setDimensions();
  9878. container?.append(div);
  9879. if (this._isStandalone) {
  9880. container?.style.setProperty("--scale-factor", this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  9881. const {
  9882. optionalContentConfigPromise
  9883. } = options;
  9884. if (optionalContentConfigPromise) {
  9885. optionalContentConfigPromise.then(optionalContentConfig => {
  9886. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9887. return;
  9888. }
  9889. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9890. });
  9891. }
  9892. }
  9893. }
  9894. get renderingState() {
  9895. return this.#renderingState;
  9896. }
  9897. set renderingState(state) {
  9898. this.#renderingState = state;
  9899. switch (state) {
  9900. case _ui_utils.RenderingStates.INITIAL:
  9901. case _ui_utils.RenderingStates.PAUSED:
  9902. this.loadingIconDiv?.classList.add("notVisible");
  9903. break;
  9904. case _ui_utils.RenderingStates.RUNNING:
  9905. this.loadingIconDiv?.classList.remove("notVisible");
  9906. break;
  9907. case _ui_utils.RenderingStates.FINISHED:
  9908. if (this.loadingIconDiv) {
  9909. this.loadingIconDiv.remove();
  9910. delete this.loadingIconDiv;
  9911. }
  9912. break;
  9913. }
  9914. }
  9915. #setDimensions() {
  9916. const {
  9917. viewport
  9918. } = this;
  9919. if (this.pdfPage) {
  9920. if (this.#previousRotation === viewport.rotation) {
  9921. return;
  9922. }
  9923. this.#previousRotation = viewport.rotation;
  9924. }
  9925. (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false);
  9926. }
  9927. setPdfPage(pdfPage) {
  9928. this.pdfPage = pdfPage;
  9929. this.pdfPageRotate = pdfPage.rotate;
  9930. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9931. this.viewport = pdfPage.getViewport({
  9932. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9933. rotation: totalRotation
  9934. });
  9935. this.#setDimensions();
  9936. this.reset();
  9937. }
  9938. destroy() {
  9939. this.reset();
  9940. this.pdfPage?.cleanup();
  9941. }
  9942. get _textHighlighter() {
  9943. return (0, _pdfjsLib.shadow)(this, "_textHighlighter", new _text_highlighter.TextHighlighter({
  9944. pageIndex: this.id - 1,
  9945. eventBus: this.eventBus,
  9946. findController: this.#layerProperties().findController
  9947. }));
  9948. }
  9949. async #renderAnnotationLayer() {
  9950. let error = null;
  9951. try {
  9952. await this.annotationLayer.render(this.viewport, "display");
  9953. } catch (ex) {
  9954. console.error(`#renderAnnotationLayer: "${ex}".`);
  9955. error = ex;
  9956. } finally {
  9957. this.eventBus.dispatch("annotationlayerrendered", {
  9958. source: this,
  9959. pageNumber: this.id,
  9960. error
  9961. });
  9962. }
  9963. }
  9964. async #renderAnnotationEditorLayer() {
  9965. let error = null;
  9966. try {
  9967. await this.annotationEditorLayer.render(this.viewport, "display");
  9968. } catch (ex) {
  9969. console.error(`#renderAnnotationEditorLayer: "${ex}".`);
  9970. error = ex;
  9971. } finally {
  9972. this.eventBus.dispatch("annotationeditorlayerrendered", {
  9973. source: this,
  9974. pageNumber: this.id,
  9975. error
  9976. });
  9977. }
  9978. }
  9979. async #renderXfaLayer() {
  9980. let error = null;
  9981. try {
  9982. const result = await this.xfaLayer.render(this.viewport, "display");
  9983. if (result?.textDivs && this._textHighlighter) {
  9984. this.#buildXfaTextContentItems(result.textDivs);
  9985. }
  9986. } catch (ex) {
  9987. console.error(`#renderXfaLayer: "${ex}".`);
  9988. error = ex;
  9989. } finally {
  9990. this.eventBus.dispatch("xfalayerrendered", {
  9991. source: this,
  9992. pageNumber: this.id,
  9993. error
  9994. });
  9995. }
  9996. }
  9997. async #renderTextLayer() {
  9998. const {
  9999. pdfPage,
  10000. textLayer,
  10001. viewport
  10002. } = this;
  10003. if (!textLayer) {
  10004. return;
  10005. }
  10006. let error = null;
  10007. try {
  10008. if (!textLayer.renderingDone) {
  10009. const readableStream = pdfPage.streamTextContent({
  10010. includeMarkedContent: true
  10011. });
  10012. textLayer.setTextContentSource(readableStream);
  10013. }
  10014. await textLayer.render(viewport);
  10015. } catch (ex) {
  10016. if (ex instanceof _pdfjsLib.AbortException) {
  10017. return;
  10018. }
  10019. console.error(`#renderTextLayer: "${ex}".`);
  10020. error = ex;
  10021. }
  10022. this.eventBus.dispatch("textlayerrendered", {
  10023. source: this,
  10024. pageNumber: this.id,
  10025. numTextDivs: textLayer.numTextDivs,
  10026. error
  10027. });
  10028. this.#renderStructTreeLayer();
  10029. }
  10030. async #renderStructTreeLayer() {
  10031. if (!this.textLayer) {
  10032. return;
  10033. }
  10034. this.structTreeLayer ||= new _struct_tree_layer_builder.StructTreeLayerBuilder();
  10035. const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
  10036. const treeDom = this.structTreeLayer?.render(tree);
  10037. if (treeDom) {
  10038. this.canvas?.append(treeDom);
  10039. }
  10040. }
  10041. async #buildXfaTextContentItems(textDivs) {
  10042. const text = await this.pdfPage.getTextContent();
  10043. const items = [];
  10044. for (const item of text.items) {
  10045. items.push(item.str);
  10046. }
  10047. this._textHighlighter.setTextMapping(textDivs, items);
  10048. this._textHighlighter.enable();
  10049. }
  10050. _resetZoomLayer(removeFromDOM = false) {
  10051. if (!this.zoomLayer) {
  10052. return;
  10053. }
  10054. const zoomLayerCanvas = this.zoomLayer.firstChild;
  10055. this.paintedViewportMap.delete(zoomLayerCanvas);
  10056. zoomLayerCanvas.width = 0;
  10057. zoomLayerCanvas.height = 0;
  10058. if (removeFromDOM) {
  10059. this.zoomLayer.remove();
  10060. }
  10061. this.zoomLayer = null;
  10062. }
  10063. reset({
  10064. keepZoomLayer = false,
  10065. keepAnnotationLayer = false,
  10066. keepAnnotationEditorLayer = false,
  10067. keepXfaLayer = false,
  10068. keepTextLayer = false
  10069. } = {}) {
  10070. this.cancelRendering({
  10071. keepAnnotationLayer,
  10072. keepAnnotationEditorLayer,
  10073. keepXfaLayer,
  10074. keepTextLayer
  10075. });
  10076. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  10077. const div = this.div;
  10078. const childNodes = div.childNodes,
  10079. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  10080. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  10081. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  10082. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
  10083. textLayerNode = keepTextLayer && this.textLayer?.div || null;
  10084. for (let i = childNodes.length - 1; i >= 0; i--) {
  10085. const node = childNodes[i];
  10086. switch (node) {
  10087. case zoomLayerNode:
  10088. case annotationLayerNode:
  10089. case annotationEditorLayerNode:
  10090. case xfaLayerNode:
  10091. case textLayerNode:
  10092. case this.loadingIconDiv:
  10093. continue;
  10094. }
  10095. node.remove();
  10096. }
  10097. div.removeAttribute("data-loaded");
  10098. if (annotationLayerNode) {
  10099. this.annotationLayer.hide();
  10100. }
  10101. if (annotationEditorLayerNode) {
  10102. this.annotationEditorLayer.hide();
  10103. }
  10104. if (xfaLayerNode) {
  10105. this.xfaLayer.hide();
  10106. }
  10107. if (textLayerNode) {
  10108. this.textLayer.hide();
  10109. }
  10110. if (!zoomLayerNode) {
  10111. if (this.canvas) {
  10112. this.paintedViewportMap.delete(this.canvas);
  10113. this.canvas.width = 0;
  10114. this.canvas.height = 0;
  10115. delete this.canvas;
  10116. }
  10117. this._resetZoomLayer();
  10118. }
  10119. if (this.svg) {
  10120. this.paintedViewportMap.delete(this.svg);
  10121. delete this.svg;
  10122. }
  10123. if (!this.loadingIconDiv) {
  10124. this.loadingIconDiv = document.createElement("div");
  10125. this.loadingIconDiv.className = "loadingIcon notVisible";
  10126. this.loadingIconDiv.setAttribute("role", "img");
  10127. this.l10n.get("loading").then(msg => {
  10128. this.loadingIconDiv?.setAttribute("aria-label", msg);
  10129. });
  10130. div.append(this.loadingIconDiv);
  10131. }
  10132. }
  10133. update({
  10134. scale = 0,
  10135. rotation = null,
  10136. optionalContentConfigPromise = null,
  10137. drawingDelay = -1
  10138. }) {
  10139. this.scale = scale || this.scale;
  10140. if (typeof rotation === "number") {
  10141. this.rotation = rotation;
  10142. }
  10143. if (optionalContentConfigPromise instanceof Promise) {
  10144. this._optionalContentConfigPromise = optionalContentConfigPromise;
  10145. optionalContentConfigPromise.then(optionalContentConfig => {
  10146. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  10147. return;
  10148. }
  10149. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  10150. });
  10151. }
  10152. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  10153. this.viewport = this.viewport.clone({
  10154. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  10155. rotation: totalRotation
  10156. });
  10157. this.#setDimensions();
  10158. if (this._isStandalone) {
  10159. this.div.parentNode?.style.setProperty("--scale-factor", this.viewport.scale);
  10160. }
  10161. if (this.svg) {
  10162. this.cssTransform({
  10163. target: this.svg,
  10164. redrawAnnotationLayer: true,
  10165. redrawAnnotationEditorLayer: true,
  10166. redrawXfaLayer: true,
  10167. redrawTextLayer: true
  10168. });
  10169. this.eventBus.dispatch("pagerendered", {
  10170. source: this,
  10171. pageNumber: this.id,
  10172. cssTransform: true,
  10173. timestamp: performance.now(),
  10174. error: this._renderError
  10175. });
  10176. return;
  10177. }
  10178. let isScalingRestricted = false;
  10179. if (this.canvas && this.maxCanvasPixels > 0) {
  10180. const outputScale = this.outputScale;
  10181. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  10182. isScalingRestricted = true;
  10183. }
  10184. }
  10185. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  10186. if (this.canvas) {
  10187. if (postponeDrawing || this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  10188. if (postponeDrawing && this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  10189. this.cancelRendering({
  10190. keepZoomLayer: true,
  10191. keepAnnotationLayer: true,
  10192. keepAnnotationEditorLayer: true,
  10193. keepXfaLayer: true,
  10194. keepTextLayer: true,
  10195. cancelExtraDelay: drawingDelay
  10196. });
  10197. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10198. }
  10199. this.cssTransform({
  10200. target: this.canvas,
  10201. redrawAnnotationLayer: true,
  10202. redrawAnnotationEditorLayer: true,
  10203. redrawXfaLayer: true,
  10204. redrawTextLayer: !postponeDrawing,
  10205. hideTextLayer: postponeDrawing
  10206. });
  10207. this.eventBus.dispatch("pagerendered", {
  10208. source: this,
  10209. pageNumber: this.id,
  10210. cssTransform: true,
  10211. timestamp: performance.now(),
  10212. error: this._renderError
  10213. });
  10214. return;
  10215. }
  10216. if (!this.zoomLayer && !this.canvas.hidden) {
  10217. this.zoomLayer = this.canvas.parentNode;
  10218. this.zoomLayer.style.position = "absolute";
  10219. }
  10220. }
  10221. if (this.zoomLayer) {
  10222. this.cssTransform({
  10223. target: this.zoomLayer.firstChild
  10224. });
  10225. }
  10226. this.reset({
  10227. keepZoomLayer: true,
  10228. keepAnnotationLayer: true,
  10229. keepAnnotationEditorLayer: true,
  10230. keepXfaLayer: true,
  10231. keepTextLayer: true
  10232. });
  10233. }
  10234. cancelRendering({
  10235. keepAnnotationLayer = false,
  10236. keepAnnotationEditorLayer = false,
  10237. keepXfaLayer = false,
  10238. keepTextLayer = false,
  10239. cancelExtraDelay = 0
  10240. } = {}) {
  10241. if (this.paintTask) {
  10242. this.paintTask.cancel(cancelExtraDelay);
  10243. this.paintTask = null;
  10244. }
  10245. this.resume = null;
  10246. if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
  10247. this.textLayer.cancel();
  10248. this.textLayer = null;
  10249. }
  10250. if (this.structTreeLayer && !this.textLayer) {
  10251. this.structTreeLayer = null;
  10252. }
  10253. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  10254. this.annotationLayer.cancel();
  10255. this.annotationLayer = null;
  10256. this._annotationCanvasMap = null;
  10257. }
  10258. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  10259. this.annotationEditorLayer.cancel();
  10260. this.annotationEditorLayer = null;
  10261. }
  10262. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  10263. this.xfaLayer.cancel();
  10264. this.xfaLayer = null;
  10265. this._textHighlighter?.disable();
  10266. }
  10267. }
  10268. cssTransform({
  10269. target,
  10270. redrawAnnotationLayer = false,
  10271. redrawAnnotationEditorLayer = false,
  10272. redrawXfaLayer = false,
  10273. redrawTextLayer = false,
  10274. hideTextLayer = false
  10275. }) {
  10276. if (target instanceof HTMLCanvasElement) {
  10277. if (!target.hasAttribute("zooming")) {
  10278. target.setAttribute("zooming", true);
  10279. const {
  10280. style
  10281. } = target;
  10282. style.width = style.height = "";
  10283. }
  10284. } else {
  10285. const div = this.div;
  10286. const {
  10287. width,
  10288. height
  10289. } = this.viewport;
  10290. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  10291. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  10292. }
  10293. const originalViewport = this.paintedViewportMap.get(target);
  10294. if (this.viewport !== originalViewport) {
  10295. const relativeRotation = this.viewport.rotation - originalViewport.rotation;
  10296. const absRotation = Math.abs(relativeRotation);
  10297. let scaleX = 1,
  10298. scaleY = 1;
  10299. if (absRotation === 90 || absRotation === 270) {
  10300. const {
  10301. width,
  10302. height
  10303. } = this.viewport;
  10304. scaleX = height / width;
  10305. scaleY = width / height;
  10306. }
  10307. if (absRotation !== 0) {
  10308. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  10309. }
  10310. }
  10311. if (redrawAnnotationLayer && this.annotationLayer) {
  10312. this.#renderAnnotationLayer();
  10313. }
  10314. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  10315. this.#renderAnnotationEditorLayer();
  10316. }
  10317. if (redrawXfaLayer && this.xfaLayer) {
  10318. this.#renderXfaLayer();
  10319. }
  10320. if (this.textLayer) {
  10321. if (hideTextLayer) {
  10322. this.textLayer.hide();
  10323. } else if (redrawTextLayer) {
  10324. this.#renderTextLayer();
  10325. }
  10326. }
  10327. }
  10328. get width() {
  10329. return this.viewport.width;
  10330. }
  10331. get height() {
  10332. return this.viewport.height;
  10333. }
  10334. getPagePoint(x, y) {
  10335. return this.viewport.convertToPdfPoint(x, y);
  10336. }
  10337. draw() {
  10338. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  10339. console.error("Must be in new state before drawing");
  10340. this.reset();
  10341. }
  10342. const {
  10343. div,
  10344. pdfPage
  10345. } = this;
  10346. if (!pdfPage) {
  10347. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10348. return Promise.reject(new Error("pdfPage is not loaded"));
  10349. }
  10350. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10351. const canvasWrapper = document.createElement("div");
  10352. canvasWrapper.classList.add("canvasWrapper");
  10353. div.append(canvasWrapper);
  10354. if (!this.textLayer && this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
  10355. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  10356. this.textLayer = new _text_layer_builder.TextLayerBuilder({
  10357. highlighter: this._textHighlighter,
  10358. accessibilityManager: this._accessibilityManager,
  10359. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
  10360. });
  10361. div.append(this.textLayer.div);
  10362. }
  10363. if (!this.annotationLayer && this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE) {
  10364. const {
  10365. annotationStorage,
  10366. downloadManager,
  10367. enableScripting,
  10368. fieldObjectsPromise,
  10369. hasJSActionsPromise,
  10370. linkService
  10371. } = this.#layerProperties();
  10372. this._annotationCanvasMap ||= new Map();
  10373. this.annotationLayer = new _annotation_layer_builder.AnnotationLayerBuilder({
  10374. pageDiv: div,
  10375. pdfPage,
  10376. annotationStorage,
  10377. imageResourcesPath: this.imageResourcesPath,
  10378. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  10379. linkService,
  10380. downloadManager,
  10381. l10n: this.l10n,
  10382. enableScripting,
  10383. hasJSActionsPromise,
  10384. fieldObjectsPromise,
  10385. annotationCanvasMap: this._annotationCanvasMap,
  10386. accessibilityManager: this._accessibilityManager
  10387. });
  10388. }
  10389. if (this.xfaLayer?.div) {
  10390. div.append(this.xfaLayer.div);
  10391. }
  10392. let renderContinueCallback = null;
  10393. if (this.renderingQueue) {
  10394. renderContinueCallback = cont => {
  10395. if (!this.renderingQueue.isHighestPriority(this)) {
  10396. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  10397. this.resume = () => {
  10398. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10399. cont();
  10400. };
  10401. return;
  10402. }
  10403. cont();
  10404. };
  10405. }
  10406. const finishPaintTask = async (error = null) => {
  10407. if (paintTask === this.paintTask) {
  10408. this.paintTask = null;
  10409. }
  10410. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  10411. this._renderError = null;
  10412. return;
  10413. }
  10414. this._renderError = error;
  10415. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10416. this._resetZoomLayer(true);
  10417. this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
  10418. this.eventBus.dispatch("pagerendered", {
  10419. source: this,
  10420. pageNumber: this.id,
  10421. cssTransform: false,
  10422. timestamp: performance.now(),
  10423. error: this._renderError
  10424. });
  10425. if (error) {
  10426. throw error;
  10427. }
  10428. };
  10429. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  10430. paintTask.onRenderContinue = renderContinueCallback;
  10431. this.paintTask = paintTask;
  10432. const resultPromise = paintTask.promise.then(() => {
  10433. return finishPaintTask(null).then(async () => {
  10434. this.#renderTextLayer();
  10435. if (this.annotationLayer) {
  10436. await this.#renderAnnotationLayer();
  10437. }
  10438. if (!this.annotationEditorLayer) {
  10439. const {
  10440. annotationEditorUIManager
  10441. } = this.#layerProperties();
  10442. if (!annotationEditorUIManager) {
  10443. return;
  10444. }
  10445. this.annotationEditorLayer = new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  10446. uiManager: annotationEditorUIManager,
  10447. pageDiv: div,
  10448. pdfPage,
  10449. l10n: this.l10n,
  10450. accessibilityManager: this._accessibilityManager
  10451. });
  10452. }
  10453. this.#renderAnnotationEditorLayer();
  10454. });
  10455. }, function (reason) {
  10456. return finishPaintTask(reason);
  10457. });
  10458. if (pdfPage.isPureXfa) {
  10459. if (!this.xfaLayer) {
  10460. const {
  10461. annotationStorage,
  10462. linkService
  10463. } = this.#layerProperties();
  10464. this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({
  10465. pageDiv: div,
  10466. pdfPage,
  10467. annotationStorage,
  10468. linkService
  10469. });
  10470. }
  10471. this.#renderXfaLayer();
  10472. }
  10473. div.setAttribute("data-loaded", true);
  10474. this.eventBus.dispatch("pagerender", {
  10475. source: this,
  10476. pageNumber: this.id
  10477. });
  10478. return resultPromise;
  10479. }
  10480. paintOnCanvas(canvasWrapper) {
  10481. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  10482. const result = {
  10483. promise: renderCapability.promise,
  10484. onRenderContinue(cont) {
  10485. cont();
  10486. },
  10487. cancel(extraDelay = 0) {
  10488. renderTask.cancel(extraDelay);
  10489. },
  10490. get separateAnnots() {
  10491. return renderTask.separateAnnots;
  10492. }
  10493. };
  10494. const viewport = this.viewport;
  10495. const {
  10496. width,
  10497. height
  10498. } = viewport;
  10499. const canvas = document.createElement("canvas");
  10500. canvas.setAttribute("role", "presentation");
  10501. canvas.hidden = true;
  10502. let isCanvasHidden = true;
  10503. const showCanvas = function () {
  10504. if (isCanvasHidden) {
  10505. canvas.hidden = false;
  10506. isCanvasHidden = false;
  10507. }
  10508. };
  10509. canvasWrapper.append(canvas);
  10510. this.canvas = canvas;
  10511. const ctx = canvas.getContext("2d", {
  10512. alpha: false
  10513. });
  10514. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  10515. if (this.useOnlyCssZoom) {
  10516. const actualSizeViewport = viewport.clone({
  10517. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10518. });
  10519. outputScale.sx *= actualSizeViewport.width / width;
  10520. outputScale.sy *= actualSizeViewport.height / height;
  10521. }
  10522. if (this.maxCanvasPixels > 0) {
  10523. const pixelsInViewport = width * height;
  10524. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  10525. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  10526. outputScale.sx = maxScale;
  10527. outputScale.sy = maxScale;
  10528. this.hasRestrictedScaling = true;
  10529. } else {
  10530. this.hasRestrictedScaling = false;
  10531. }
  10532. }
  10533. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  10534. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  10535. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  10536. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  10537. const {
  10538. style
  10539. } = canvas;
  10540. style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  10541. style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  10542. this.paintedViewportMap.set(canvas, viewport);
  10543. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10544. const renderContext = {
  10545. canvasContext: ctx,
  10546. transform,
  10547. viewport,
  10548. annotationMode: this.#annotationMode,
  10549. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10550. annotationCanvasMap: this._annotationCanvasMap,
  10551. pageColors: this.pageColors
  10552. };
  10553. const renderTask = this.pdfPage.render(renderContext);
  10554. renderTask.onContinue = function (cont) {
  10555. showCanvas();
  10556. if (result.onRenderContinue) {
  10557. result.onRenderContinue(cont);
  10558. } else {
  10559. cont();
  10560. }
  10561. };
  10562. renderTask.promise.then(function () {
  10563. showCanvas();
  10564. renderCapability.resolve();
  10565. }, function (error) {
  10566. if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
  10567. showCanvas();
  10568. }
  10569. renderCapability.reject(error);
  10570. });
  10571. return result;
  10572. }
  10573. paintOnSvg(wrapper) {
  10574. let cancelled = false;
  10575. const ensureNotCancelled = () => {
  10576. if (cancelled) {
  10577. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  10578. }
  10579. };
  10580. const pdfPage = this.pdfPage;
  10581. const actualSizeViewport = this.viewport.clone({
  10582. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10583. });
  10584. const promise = pdfPage.getOperatorList({
  10585. annotationMode: this.#annotationMode
  10586. }).then(opList => {
  10587. ensureNotCancelled();
  10588. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  10589. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  10590. ensureNotCancelled();
  10591. this.svg = svg;
  10592. this.paintedViewportMap.set(svg, actualSizeViewport);
  10593. svg.style.width = wrapper.style.width;
  10594. svg.style.height = wrapper.style.height;
  10595. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10596. wrapper.append(svg);
  10597. });
  10598. });
  10599. return {
  10600. promise,
  10601. onRenderContinue(cont) {
  10602. cont();
  10603. },
  10604. cancel() {
  10605. cancelled = true;
  10606. },
  10607. get separateAnnots() {
  10608. return false;
  10609. }
  10610. };
  10611. }
  10612. setPageLabel(label) {
  10613. this.pageLabel = typeof label === "string" ? label : null;
  10614. if (this.pageLabel !== null) {
  10615. this.div.setAttribute("data-page-label", this.pageLabel);
  10616. } else {
  10617. this.div.removeAttribute("data-page-label");
  10618. }
  10619. }
  10620. get thumbnailCanvas() {
  10621. const {
  10622. initialOptionalContent,
  10623. regularAnnotations
  10624. } = this.#useThumbnailCanvas;
  10625. return initialOptionalContent && regularAnnotations ? this.canvas : null;
  10626. }
  10627. }
  10628. exports.PDFPageView = PDFPageView;
  10629. /***/
  10630. }),
  10631. /* 31 */
  10632. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10633. Object.defineProperty(exports, "__esModule", ({
  10634. value: true
  10635. }));
  10636. exports.AnnotationEditorLayerBuilder = void 0;
  10637. var _pdfjsLib = __webpack_require__(5);
  10638. var _l10n_utils = __webpack_require__(29);
  10639. class AnnotationEditorLayerBuilder {
  10640. #uiManager;
  10641. constructor(options) {
  10642. this.pageDiv = options.pageDiv;
  10643. this.pdfPage = options.pdfPage;
  10644. this.accessibilityManager = options.accessibilityManager;
  10645. this.l10n = options.l10n || _l10n_utils.NullL10n;
  10646. this.annotationEditorLayer = null;
  10647. this.div = null;
  10648. this._cancelled = false;
  10649. this.#uiManager = options.uiManager;
  10650. }
  10651. async render(viewport, intent = "display") {
  10652. if (intent !== "display") {
  10653. return;
  10654. }
  10655. if (this._cancelled) {
  10656. return;
  10657. }
  10658. const clonedViewport = viewport.clone({
  10659. dontFlip: true
  10660. });
  10661. if (this.div) {
  10662. this.annotationEditorLayer.update({
  10663. viewport: clonedViewport
  10664. });
  10665. this.show();
  10666. return;
  10667. }
  10668. const div = this.div = document.createElement("div");
  10669. div.className = "annotationEditorLayer";
  10670. div.tabIndex = 0;
  10671. this.pageDiv.append(div);
  10672. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  10673. uiManager: this.#uiManager,
  10674. div,
  10675. accessibilityManager: this.accessibilityManager,
  10676. pageIndex: this.pdfPage.pageNumber - 1,
  10677. l10n: this.l10n,
  10678. viewport: clonedViewport
  10679. });
  10680. const parameters = {
  10681. viewport: clonedViewport,
  10682. div,
  10683. annotations: null,
  10684. intent
  10685. };
  10686. this.annotationEditorLayer.render(parameters);
  10687. }
  10688. cancel() {
  10689. this._cancelled = true;
  10690. if (!this.div) {
  10691. return;
  10692. }
  10693. this.pageDiv = null;
  10694. this.annotationEditorLayer.destroy();
  10695. this.div.remove();
  10696. }
  10697. hide() {
  10698. if (!this.div) {
  10699. return;
  10700. }
  10701. this.div.hidden = true;
  10702. }
  10703. show() {
  10704. if (!this.div) {
  10705. return;
  10706. }
  10707. this.div.hidden = false;
  10708. }
  10709. }
  10710. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  10711. /***/
  10712. }),
  10713. /* 32 */
  10714. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10715. Object.defineProperty(exports, "__esModule", ({
  10716. value: true
  10717. }));
  10718. exports.AnnotationLayerBuilder = void 0;
  10719. var _pdfjsLib = __webpack_require__(5);
  10720. var _l10n_utils = __webpack_require__(29);
  10721. var _ui_utils = __webpack_require__(1);
  10722. class AnnotationLayerBuilder {
  10723. #numAnnotations = 0;
  10724. #onPresentationModeChanged = null;
  10725. constructor({
  10726. pageDiv,
  10727. pdfPage,
  10728. linkService,
  10729. downloadManager,
  10730. annotationStorage = null,
  10731. imageResourcesPath = "",
  10732. renderForms = true,
  10733. l10n = _l10n_utils.NullL10n,
  10734. enableScripting = false,
  10735. hasJSActionsPromise = null,
  10736. fieldObjectsPromise = null,
  10737. annotationCanvasMap = null,
  10738. accessibilityManager = null
  10739. }) {
  10740. this.pageDiv = pageDiv;
  10741. this.pdfPage = pdfPage;
  10742. this.linkService = linkService;
  10743. this.downloadManager = downloadManager;
  10744. this.imageResourcesPath = imageResourcesPath;
  10745. this.renderForms = renderForms;
  10746. this.l10n = l10n;
  10747. this.annotationStorage = annotationStorage;
  10748. this.enableScripting = enableScripting;
  10749. this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
  10750. this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
  10751. this._annotationCanvasMap = annotationCanvasMap;
  10752. this._accessibilityManager = accessibilityManager;
  10753. this.div = null;
  10754. this._cancelled = false;
  10755. this._eventBus = linkService.eventBus;
  10756. }
  10757. async render(viewport, intent = "display") {
  10758. if (this.div) {
  10759. if (this._cancelled || this.#numAnnotations === 0) {
  10760. return;
  10761. }
  10762. _pdfjsLib.AnnotationLayer.update({
  10763. viewport: viewport.clone({
  10764. dontFlip: true
  10765. }),
  10766. div: this.div,
  10767. annotationCanvasMap: this._annotationCanvasMap
  10768. });
  10769. return;
  10770. }
  10771. const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
  10772. intent
  10773. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  10774. if (this._cancelled) {
  10775. return;
  10776. }
  10777. this.#numAnnotations = annotations.length;
  10778. this.div = document.createElement("div");
  10779. this.div.className = "annotationLayer";
  10780. this.pageDiv.append(this.div);
  10781. if (this.#numAnnotations === 0) {
  10782. this.hide();
  10783. return;
  10784. }
  10785. _pdfjsLib.AnnotationLayer.render({
  10786. viewport: viewport.clone({
  10787. dontFlip: true
  10788. }),
  10789. div: this.div,
  10790. annotations,
  10791. page: this.pdfPage,
  10792. imageResourcesPath: this.imageResourcesPath,
  10793. renderForms: this.renderForms,
  10794. linkService: this.linkService,
  10795. downloadManager: this.downloadManager,
  10796. annotationStorage: this.annotationStorage,
  10797. enableScripting: this.enableScripting,
  10798. hasJSActions,
  10799. fieldObjects,
  10800. annotationCanvasMap: this._annotationCanvasMap,
  10801. accessibilityManager: this._accessibilityManager
  10802. });
  10803. this.l10n.translate(this.div);
  10804. if (this.linkService.isInPresentationMode) {
  10805. this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN);
  10806. }
  10807. if (!this.#onPresentationModeChanged) {
  10808. this.#onPresentationModeChanged = evt => {
  10809. this.#updatePresentationModeState(evt.state);
  10810. };
  10811. this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged);
  10812. }
  10813. }
  10814. cancel() {
  10815. this._cancelled = true;
  10816. if (this.#onPresentationModeChanged) {
  10817. this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged);
  10818. this.#onPresentationModeChanged = null;
  10819. }
  10820. }
  10821. hide() {
  10822. if (!this.div) {
  10823. return;
  10824. }
  10825. this.div.hidden = true;
  10826. }
  10827. #updatePresentationModeState(state) {
  10828. if (!this.div) {
  10829. return;
  10830. }
  10831. let disableFormElements = false;
  10832. switch (state) {
  10833. case _ui_utils.PresentationModeState.FULLSCREEN:
  10834. disableFormElements = true;
  10835. break;
  10836. case _ui_utils.PresentationModeState.NORMAL:
  10837. break;
  10838. default:
  10839. return;
  10840. }
  10841. for (const section of this.div.childNodes) {
  10842. if (section.hasAttribute("data-internal-link")) {
  10843. continue;
  10844. }
  10845. section.inert = disableFormElements;
  10846. }
  10847. }
  10848. }
  10849. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  10850. /***/
  10851. }),
  10852. /* 33 */
  10853. /***/ ((__unused_webpack_module, exports) => {
  10854. Object.defineProperty(exports, "__esModule", ({
  10855. value: true
  10856. }));
  10857. exports.StructTreeLayerBuilder = void 0;
  10858. const PDF_ROLE_TO_HTML_ROLE = {
  10859. Document: null,
  10860. DocumentFragment: null,
  10861. Part: "group",
  10862. Sect: "group",
  10863. Div: "group",
  10864. Aside: "note",
  10865. NonStruct: "none",
  10866. P: null,
  10867. H: "heading",
  10868. Title: null,
  10869. FENote: "note",
  10870. Sub: "group",
  10871. Lbl: null,
  10872. Span: null,
  10873. Em: null,
  10874. Strong: null,
  10875. Link: "link",
  10876. Annot: "note",
  10877. Form: "form",
  10878. Ruby: null,
  10879. RB: null,
  10880. RT: null,
  10881. RP: null,
  10882. Warichu: null,
  10883. WT: null,
  10884. WP: null,
  10885. L: "list",
  10886. LI: "listitem",
  10887. LBody: null,
  10888. Table: "table",
  10889. TR: "row",
  10890. TH: "columnheader",
  10891. TD: "cell",
  10892. THead: "columnheader",
  10893. TBody: null,
  10894. TFoot: null,
  10895. Caption: null,
  10896. Figure: "figure",
  10897. Formula: null,
  10898. Artifact: null
  10899. };
  10900. const HEADING_PATTERN = /^H(\d+)$/;
  10901. class StructTreeLayerBuilder {
  10902. #treeDom = undefined;
  10903. get renderingDone() {
  10904. return this.#treeDom !== undefined;
  10905. }
  10906. render(structTree) {
  10907. if (this.#treeDom !== undefined) {
  10908. return this.#treeDom;
  10909. }
  10910. const treeDom = this.#walk(structTree);
  10911. treeDom?.classList.add("structTree");
  10912. return this.#treeDom = treeDom;
  10913. }
  10914. #setAttributes(structElement, htmlElement) {
  10915. if (structElement.alt !== undefined) {
  10916. htmlElement.setAttribute("aria-label", structElement.alt);
  10917. }
  10918. if (structElement.id !== undefined) {
  10919. htmlElement.setAttribute("aria-owns", structElement.id);
  10920. }
  10921. if (structElement.lang !== undefined) {
  10922. htmlElement.setAttribute("lang", structElement.lang);
  10923. }
  10924. }
  10925. #walk(node) {
  10926. if (!node) {
  10927. return null;
  10928. }
  10929. const element = document.createElement("span");
  10930. if ("role" in node) {
  10931. const {
  10932. role
  10933. } = node;
  10934. const match = role.match(HEADING_PATTERN);
  10935. if (match) {
  10936. element.setAttribute("role", "heading");
  10937. element.setAttribute("aria-level", match[1]);
  10938. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10939. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10940. }
  10941. }
  10942. this.#setAttributes(node, element);
  10943. if (node.children) {
  10944. if (node.children.length === 1 && "id" in node.children[0]) {
  10945. this.#setAttributes(node.children[0], element);
  10946. } else {
  10947. for (const kid of node.children) {
  10948. element.append(this.#walk(kid));
  10949. }
  10950. }
  10951. }
  10952. return element;
  10953. }
  10954. }
  10955. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10956. /***/
  10957. }),
  10958. /* 34 */
  10959. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10960. Object.defineProperty(exports, "__esModule", ({
  10961. value: true
  10962. }));
  10963. exports.TextAccessibilityManager = void 0;
  10964. var _ui_utils = __webpack_require__(1);
  10965. class TextAccessibilityManager {
  10966. #enabled = false;
  10967. #textChildren = null;
  10968. #textNodes = new Map();
  10969. #waitingElements = new Map();
  10970. setTextMapping(textDivs) {
  10971. this.#textChildren = textDivs;
  10972. }
  10973. static #compareElementPositions(e1, e2) {
  10974. const rect1 = e1.getBoundingClientRect();
  10975. const rect2 = e2.getBoundingClientRect();
  10976. if (rect1.width === 0 && rect1.height === 0) {
  10977. return +1;
  10978. }
  10979. if (rect2.width === 0 && rect2.height === 0) {
  10980. return -1;
  10981. }
  10982. const top1 = rect1.y;
  10983. const bot1 = rect1.y + rect1.height;
  10984. const mid1 = rect1.y + rect1.height / 2;
  10985. const top2 = rect2.y;
  10986. const bot2 = rect2.y + rect2.height;
  10987. const mid2 = rect2.y + rect2.height / 2;
  10988. if (mid1 <= top2 && mid2 >= bot1) {
  10989. return -1;
  10990. }
  10991. if (mid2 <= top1 && mid1 >= bot2) {
  10992. return +1;
  10993. }
  10994. const centerX1 = rect1.x + rect1.width / 2;
  10995. const centerX2 = rect2.x + rect2.width / 2;
  10996. return centerX1 - centerX2;
  10997. }
  10998. enable() {
  10999. if (this.#enabled) {
  11000. throw new Error("TextAccessibilityManager is already enabled.");
  11001. }
  11002. if (!this.#textChildren) {
  11003. throw new Error("Text divs and strings have not been set.");
  11004. }
  11005. this.#enabled = true;
  11006. this.#textChildren = this.#textChildren.slice();
  11007. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  11008. if (this.#textNodes.size > 0) {
  11009. const textChildren = this.#textChildren;
  11010. for (const [id, nodeIndex] of this.#textNodes) {
  11011. const element = document.getElementById(id);
  11012. if (!element) {
  11013. this.#textNodes.delete(id);
  11014. continue;
  11015. }
  11016. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  11017. }
  11018. }
  11019. for (const [element, isRemovable] of this.#waitingElements) {
  11020. this.addPointerInTextLayer(element, isRemovable);
  11021. }
  11022. this.#waitingElements.clear();
  11023. }
  11024. disable() {
  11025. if (!this.#enabled) {
  11026. return;
  11027. }
  11028. this.#waitingElements.clear();
  11029. this.#textChildren = null;
  11030. this.#enabled = false;
  11031. }
  11032. removePointerInTextLayer(element) {
  11033. if (!this.#enabled) {
  11034. this.#waitingElements.delete(element);
  11035. return;
  11036. }
  11037. const children = this.#textChildren;
  11038. if (!children || children.length === 0) {
  11039. return;
  11040. }
  11041. const {
  11042. id
  11043. } = element;
  11044. const nodeIndex = this.#textNodes.get(id);
  11045. if (nodeIndex === undefined) {
  11046. return;
  11047. }
  11048. const node = children[nodeIndex];
  11049. this.#textNodes.delete(id);
  11050. let owns = node.getAttribute("aria-owns");
  11051. if (owns?.includes(id)) {
  11052. owns = owns.split(" ").filter(x => x !== id).join(" ");
  11053. if (owns) {
  11054. node.setAttribute("aria-owns", owns);
  11055. } else {
  11056. node.removeAttribute("aria-owns");
  11057. node.setAttribute("role", "presentation");
  11058. }
  11059. }
  11060. }
  11061. #addIdToAriaOwns(id, node) {
  11062. const owns = node.getAttribute("aria-owns");
  11063. if (!owns?.includes(id)) {
  11064. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  11065. }
  11066. node.removeAttribute("role");
  11067. }
  11068. addPointerInTextLayer(element, isRemovable) {
  11069. const {
  11070. id
  11071. } = element;
  11072. if (!id) {
  11073. return;
  11074. }
  11075. if (!this.#enabled) {
  11076. this.#waitingElements.set(element, isRemovable);
  11077. return;
  11078. }
  11079. if (isRemovable) {
  11080. this.removePointerInTextLayer(element);
  11081. }
  11082. const children = this.#textChildren;
  11083. if (!children || children.length === 0) {
  11084. return;
  11085. }
  11086. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  11087. const nodeIndex = Math.max(0, index - 1);
  11088. this.#addIdToAriaOwns(id, children[nodeIndex]);
  11089. this.#textNodes.set(id, nodeIndex);
  11090. }
  11091. moveElementInDOM(container, element, contentElement, isRemovable) {
  11092. this.addPointerInTextLayer(contentElement, isRemovable);
  11093. if (!container.hasChildNodes()) {
  11094. container.append(element);
  11095. return;
  11096. }
  11097. const children = Array.from(container.childNodes).filter(node => node !== element);
  11098. if (children.length === 0) {
  11099. return;
  11100. }
  11101. const elementToCompare = contentElement || element;
  11102. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  11103. if (index === 0) {
  11104. children[0].before(element);
  11105. } else {
  11106. children[index - 1].after(element);
  11107. }
  11108. }
  11109. }
  11110. exports.TextAccessibilityManager = TextAccessibilityManager;
  11111. /***/
  11112. }),
  11113. /* 35 */
  11114. /***/ ((__unused_webpack_module, exports) => {
  11115. Object.defineProperty(exports, "__esModule", ({
  11116. value: true
  11117. }));
  11118. exports.TextHighlighter = void 0;
  11119. class TextHighlighter {
  11120. constructor({
  11121. findController,
  11122. eventBus,
  11123. pageIndex
  11124. }) {
  11125. this.findController = findController;
  11126. this.matches = [];
  11127. this.eventBus = eventBus;
  11128. this.pageIdx = pageIndex;
  11129. this._onUpdateTextLayerMatches = null;
  11130. this.textDivs = null;
  11131. this.textContentItemsStr = null;
  11132. this.enabled = false;
  11133. }
  11134. setTextMapping(divs, texts) {
  11135. this.textDivs = divs;
  11136. this.textContentItemsStr = texts;
  11137. }
  11138. enable() {
  11139. if (!this.textDivs || !this.textContentItemsStr) {
  11140. throw new Error("Text divs and strings have not been set.");
  11141. }
  11142. if (this.enabled) {
  11143. throw new Error("TextHighlighter is already enabled.");
  11144. }
  11145. this.enabled = true;
  11146. if (!this._onUpdateTextLayerMatches) {
  11147. this._onUpdateTextLayerMatches = evt => {
  11148. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  11149. this._updateMatches();
  11150. }
  11151. };
  11152. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11153. }
  11154. this._updateMatches();
  11155. }
  11156. disable() {
  11157. if (!this.enabled) {
  11158. return;
  11159. }
  11160. this.enabled = false;
  11161. if (this._onUpdateTextLayerMatches) {
  11162. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11163. this._onUpdateTextLayerMatches = null;
  11164. }
  11165. this._updateMatches(true);
  11166. }
  11167. _convertMatches(matches, matchesLength) {
  11168. if (!matches) {
  11169. return [];
  11170. }
  11171. const {
  11172. textContentItemsStr
  11173. } = this;
  11174. let i = 0,
  11175. iIndex = 0;
  11176. const end = textContentItemsStr.length - 1;
  11177. const result = [];
  11178. for (let m = 0, mm = matches.length; m < mm; m++) {
  11179. let matchIdx = matches[m];
  11180. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  11181. iIndex += textContentItemsStr[i].length;
  11182. i++;
  11183. }
  11184. if (i === textContentItemsStr.length) {
  11185. console.error("Could not find a matching mapping");
  11186. }
  11187. const match = {
  11188. begin: {
  11189. divIdx: i,
  11190. offset: matchIdx - iIndex
  11191. }
  11192. };
  11193. matchIdx += matchesLength[m];
  11194. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  11195. iIndex += textContentItemsStr[i].length;
  11196. i++;
  11197. }
  11198. match.end = {
  11199. divIdx: i,
  11200. offset: matchIdx - iIndex
  11201. };
  11202. result.push(match);
  11203. }
  11204. return result;
  11205. }
  11206. _renderMatches(matches) {
  11207. if (matches.length === 0) {
  11208. return;
  11209. }
  11210. const {
  11211. findController,
  11212. pageIdx
  11213. } = this;
  11214. const {
  11215. textContentItemsStr,
  11216. textDivs
  11217. } = this;
  11218. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  11219. const selectedMatchIdx = findController.selected.matchIdx;
  11220. const highlightAll = findController.state.highlightAll;
  11221. let prevEnd = null;
  11222. const infinity = {
  11223. divIdx: -1,
  11224. offset: undefined
  11225. };
  11226. function beginText(begin, className) {
  11227. const divIdx = begin.divIdx;
  11228. textDivs[divIdx].textContent = "";
  11229. return appendTextToDiv(divIdx, 0, begin.offset, className);
  11230. }
  11231. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  11232. let div = textDivs[divIdx];
  11233. if (div.nodeType === Node.TEXT_NODE) {
  11234. const span = document.createElement("span");
  11235. div.before(span);
  11236. span.append(div);
  11237. textDivs[divIdx] = span;
  11238. div = span;
  11239. }
  11240. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  11241. const node = document.createTextNode(content);
  11242. if (className) {
  11243. const span = document.createElement("span");
  11244. span.className = `${className} appended`;
  11245. span.append(node);
  11246. div.append(span);
  11247. return className.includes("selected") ? span.offsetLeft : 0;
  11248. }
  11249. div.append(node);
  11250. return 0;
  11251. }
  11252. let i0 = selectedMatchIdx,
  11253. i1 = i0 + 1;
  11254. if (highlightAll) {
  11255. i0 = 0;
  11256. i1 = matches.length;
  11257. } else if (!isSelectedPage) {
  11258. return;
  11259. }
  11260. for (let i = i0; i < i1; i++) {
  11261. const match = matches[i];
  11262. const begin = match.begin;
  11263. const end = match.end;
  11264. const isSelected = isSelectedPage && i === selectedMatchIdx;
  11265. const highlightSuffix = isSelected ? " selected" : "";
  11266. let selectedLeft = 0;
  11267. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  11268. if (prevEnd !== null) {
  11269. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11270. }
  11271. beginText(begin);
  11272. } else {
  11273. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  11274. }
  11275. if (begin.divIdx === end.divIdx) {
  11276. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  11277. } else {
  11278. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  11279. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  11280. textDivs[n0].className = "highlight middle" + highlightSuffix;
  11281. }
  11282. beginText(end, "highlight end" + highlightSuffix);
  11283. }
  11284. prevEnd = end;
  11285. if (isSelected) {
  11286. findController.scrollMatchIntoView({
  11287. element: textDivs[begin.divIdx],
  11288. selectedLeft,
  11289. pageIndex: pageIdx,
  11290. matchIndex: selectedMatchIdx
  11291. });
  11292. }
  11293. }
  11294. if (prevEnd) {
  11295. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11296. }
  11297. }
  11298. _updateMatches(reset = false) {
  11299. if (!this.enabled && !reset) {
  11300. return;
  11301. }
  11302. const {
  11303. findController,
  11304. matches,
  11305. pageIdx
  11306. } = this;
  11307. const {
  11308. textContentItemsStr,
  11309. textDivs
  11310. } = this;
  11311. let clearedUntilDivIdx = -1;
  11312. for (const match of matches) {
  11313. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  11314. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  11315. const div = textDivs[n];
  11316. div.textContent = textContentItemsStr[n];
  11317. div.className = "";
  11318. }
  11319. clearedUntilDivIdx = match.end.divIdx + 1;
  11320. }
  11321. if (!findController?.highlightMatches || reset) {
  11322. return;
  11323. }
  11324. const pageMatches = findController.pageMatches[pageIdx] || null;
  11325. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  11326. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  11327. this._renderMatches(this.matches);
  11328. }
  11329. }
  11330. exports.TextHighlighter = TextHighlighter;
  11331. /***/
  11332. }),
  11333. /* 36 */
  11334. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11335. Object.defineProperty(exports, "__esModule", ({
  11336. value: true
  11337. }));
  11338. exports.TextLayerBuilder = void 0;
  11339. var _pdfjsLib = __webpack_require__(5);
  11340. class TextLayerBuilder {
  11341. #rotation = 0;
  11342. #scale = 0;
  11343. #textContentSource = null;
  11344. constructor({
  11345. highlighter = null,
  11346. accessibilityManager = null,
  11347. isOffscreenCanvasSupported = true
  11348. }) {
  11349. this.textContentItemsStr = [];
  11350. this.renderingDone = false;
  11351. this.textDivs = [];
  11352. this.textDivProperties = new WeakMap();
  11353. this.textLayerRenderTask = null;
  11354. this.highlighter = highlighter;
  11355. this.accessibilityManager = accessibilityManager;
  11356. this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
  11357. this.div = document.createElement("div");
  11358. this.div.className = "textLayer";
  11359. this.hide();
  11360. }
  11361. #finishRendering() {
  11362. this.renderingDone = true;
  11363. const endOfContent = document.createElement("div");
  11364. endOfContent.className = "endOfContent";
  11365. this.div.append(endOfContent);
  11366. this.#bindMouse();
  11367. }
  11368. get numTextDivs() {
  11369. return this.textDivs.length;
  11370. }
  11371. async render(viewport) {
  11372. if (!this.#textContentSource) {
  11373. throw new Error('No "textContentSource" parameter specified.');
  11374. }
  11375. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  11376. const {
  11377. rotation
  11378. } = viewport;
  11379. if (this.renderingDone) {
  11380. const mustRotate = rotation !== this.#rotation;
  11381. const mustRescale = scale !== this.#scale;
  11382. if (mustRotate || mustRescale) {
  11383. this.hide();
  11384. (0, _pdfjsLib.updateTextLayer)({
  11385. container: this.div,
  11386. viewport,
  11387. textDivs: this.textDivs,
  11388. textDivProperties: this.textDivProperties,
  11389. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  11390. mustRescale,
  11391. mustRotate
  11392. });
  11393. this.#scale = scale;
  11394. this.#rotation = rotation;
  11395. }
  11396. this.show();
  11397. return;
  11398. }
  11399. this.cancel();
  11400. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  11401. this.accessibilityManager?.setTextMapping(this.textDivs);
  11402. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  11403. textContentSource: this.#textContentSource,
  11404. container: this.div,
  11405. viewport,
  11406. textDivs: this.textDivs,
  11407. textDivProperties: this.textDivProperties,
  11408. textContentItemsStr: this.textContentItemsStr,
  11409. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
  11410. });
  11411. await this.textLayerRenderTask.promise;
  11412. this.#finishRendering();
  11413. this.#scale = scale;
  11414. this.#rotation = rotation;
  11415. this.show();
  11416. this.accessibilityManager?.enable();
  11417. }
  11418. hide() {
  11419. if (!this.div.hidden) {
  11420. this.highlighter?.disable();
  11421. this.div.hidden = true;
  11422. }
  11423. }
  11424. show() {
  11425. if (this.div.hidden && this.renderingDone) {
  11426. this.div.hidden = false;
  11427. this.highlighter?.enable();
  11428. }
  11429. }
  11430. cancel() {
  11431. if (this.textLayerRenderTask) {
  11432. this.textLayerRenderTask.cancel();
  11433. this.textLayerRenderTask = null;
  11434. }
  11435. this.highlighter?.disable();
  11436. this.accessibilityManager?.disable();
  11437. this.textContentItemsStr.length = 0;
  11438. this.textDivs.length = 0;
  11439. this.textDivProperties = new WeakMap();
  11440. }
  11441. setTextContentSource(source) {
  11442. this.cancel();
  11443. this.#textContentSource = source;
  11444. }
  11445. #bindMouse() {
  11446. const {
  11447. div
  11448. } = this;
  11449. div.addEventListener("mousedown", evt => {
  11450. const end = div.querySelector(".endOfContent");
  11451. if (!end) {
  11452. return;
  11453. }
  11454. let adjustTop = evt.target !== div;
  11455. adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  11456. if (adjustTop) {
  11457. const divBounds = div.getBoundingClientRect();
  11458. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  11459. end.style.top = (r * 100).toFixed(2) + "%";
  11460. }
  11461. end.classList.add("active");
  11462. });
  11463. div.addEventListener("mouseup", () => {
  11464. const end = div.querySelector(".endOfContent");
  11465. if (!end) {
  11466. return;
  11467. }
  11468. end.style.top = "";
  11469. end.classList.remove("active");
  11470. });
  11471. }
  11472. }
  11473. exports.TextLayerBuilder = TextLayerBuilder;
  11474. /***/
  11475. }),
  11476. /* 37 */
  11477. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11478. Object.defineProperty(exports, "__esModule", ({
  11479. value: true
  11480. }));
  11481. exports.XfaLayerBuilder = void 0;
  11482. var _pdfjsLib = __webpack_require__(5);
  11483. class XfaLayerBuilder {
  11484. constructor({
  11485. pageDiv,
  11486. pdfPage,
  11487. annotationStorage = null,
  11488. linkService,
  11489. xfaHtml = null
  11490. }) {
  11491. this.pageDiv = pageDiv;
  11492. this.pdfPage = pdfPage;
  11493. this.annotationStorage = annotationStorage;
  11494. this.linkService = linkService;
  11495. this.xfaHtml = xfaHtml;
  11496. this.div = null;
  11497. this._cancelled = false;
  11498. }
  11499. async render(viewport, intent = "display") {
  11500. if (intent === "print") {
  11501. const parameters = {
  11502. viewport: viewport.clone({
  11503. dontFlip: true
  11504. }),
  11505. div: this.div,
  11506. xfaHtml: this.xfaHtml,
  11507. annotationStorage: this.annotationStorage,
  11508. linkService: this.linkService,
  11509. intent
  11510. };
  11511. const div = document.createElement("div");
  11512. this.pageDiv.append(div);
  11513. parameters.div = div;
  11514. return _pdfjsLib.XfaLayer.render(parameters);
  11515. }
  11516. const xfaHtml = await this.pdfPage.getXfa();
  11517. if (this._cancelled || !xfaHtml) {
  11518. return {
  11519. textDivs: []
  11520. };
  11521. }
  11522. const parameters = {
  11523. viewport: viewport.clone({
  11524. dontFlip: true
  11525. }),
  11526. div: this.div,
  11527. xfaHtml,
  11528. annotationStorage: this.annotationStorage,
  11529. linkService: this.linkService,
  11530. intent
  11531. };
  11532. if (this.div) {
  11533. return _pdfjsLib.XfaLayer.update(parameters);
  11534. }
  11535. this.div = document.createElement("div");
  11536. this.pageDiv.append(this.div);
  11537. parameters.div = this.div;
  11538. return _pdfjsLib.XfaLayer.render(parameters);
  11539. }
  11540. cancel() {
  11541. this._cancelled = true;
  11542. }
  11543. hide() {
  11544. if (!this.div) {
  11545. return;
  11546. }
  11547. this.div.hidden = true;
  11548. }
  11549. }
  11550. exports.XfaLayerBuilder = XfaLayerBuilder;
  11551. /***/
  11552. }),
  11553. /* 38 */
  11554. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11555. Object.defineProperty(exports, "__esModule", ({
  11556. value: true
  11557. }));
  11558. exports.SecondaryToolbar = void 0;
  11559. var _ui_utils = __webpack_require__(1);
  11560. var _pdf_cursor_tools = __webpack_require__(7);
  11561. var _pdf_viewer = __webpack_require__(28);
  11562. class SecondaryToolbar {
  11563. constructor(options, eventBus, externalServices) {
  11564. this.toolbar = options.toolbar;
  11565. this.toggleButton = options.toggleButton;
  11566. this.buttons = [{
  11567. element: options.presentationModeButton,
  11568. eventName: "presentationmode",
  11569. close: true
  11570. }, {
  11571. element: options.printButton,
  11572. eventName: "print",
  11573. close: true
  11574. }, {
  11575. element: options.downloadButton,
  11576. eventName: "download",
  11577. close: true
  11578. }, {
  11579. element: options.viewBookmarkButton,
  11580. eventName: null,
  11581. close: true
  11582. }, {
  11583. element: options.firstPageButton,
  11584. eventName: "firstpage",
  11585. close: true
  11586. }, {
  11587. element: options.lastPageButton,
  11588. eventName: "lastpage",
  11589. close: true
  11590. }, {
  11591. element: options.pageRotateCwButton,
  11592. eventName: "rotatecw",
  11593. close: false
  11594. }, {
  11595. element: options.pageRotateCcwButton,
  11596. eventName: "rotateccw",
  11597. close: false
  11598. }, {
  11599. element: options.cursorSelectToolButton,
  11600. eventName: "switchcursortool",
  11601. eventDetails: {
  11602. tool: _pdf_cursor_tools.CursorTool.SELECT
  11603. },
  11604. close: true
  11605. }, {
  11606. element: options.cursorHandToolButton,
  11607. eventName: "switchcursortool",
  11608. eventDetails: {
  11609. tool: _pdf_cursor_tools.CursorTool.HAND
  11610. },
  11611. close: true
  11612. }, {
  11613. element: options.scrollPageButton,
  11614. eventName: "switchscrollmode",
  11615. eventDetails: {
  11616. mode: _ui_utils.ScrollMode.PAGE
  11617. },
  11618. close: true
  11619. }, {
  11620. element: options.scrollVerticalButton,
  11621. eventName: "switchscrollmode",
  11622. eventDetails: {
  11623. mode: _ui_utils.ScrollMode.VERTICAL
  11624. },
  11625. close: true
  11626. }, {
  11627. element: options.scrollHorizontalButton,
  11628. eventName: "switchscrollmode",
  11629. eventDetails: {
  11630. mode: _ui_utils.ScrollMode.HORIZONTAL
  11631. },
  11632. close: true
  11633. }, {
  11634. element: options.scrollWrappedButton,
  11635. eventName: "switchscrollmode",
  11636. eventDetails: {
  11637. mode: _ui_utils.ScrollMode.WRAPPED
  11638. },
  11639. close: true
  11640. }, {
  11641. element: options.spreadNoneButton,
  11642. eventName: "switchspreadmode",
  11643. eventDetails: {
  11644. mode: _ui_utils.SpreadMode.NONE
  11645. },
  11646. close: true
  11647. }, {
  11648. element: options.spreadOddButton,
  11649. eventName: "switchspreadmode",
  11650. eventDetails: {
  11651. mode: _ui_utils.SpreadMode.ODD
  11652. },
  11653. close: true
  11654. }, {
  11655. element: options.spreadEvenButton,
  11656. eventName: "switchspreadmode",
  11657. eventDetails: {
  11658. mode: _ui_utils.SpreadMode.EVEN
  11659. },
  11660. close: true
  11661. }, {
  11662. element: options.documentPropertiesButton,
  11663. eventName: "documentproperties",
  11664. close: true
  11665. }];
  11666. this.buttons.push({
  11667. element: options.openFileButton,
  11668. eventName: "openfile",
  11669. close: true
  11670. });
  11671. this.items = {
  11672. firstPage: options.firstPageButton,
  11673. lastPage: options.lastPageButton,
  11674. pageRotateCw: options.pageRotateCwButton,
  11675. pageRotateCcw: options.pageRotateCcwButton
  11676. };
  11677. this.eventBus = eventBus;
  11678. this.externalServices = externalServices;
  11679. this.opened = false;
  11680. this.#bindClickListeners();
  11681. this.#bindCursorToolsListener(options);
  11682. this.#bindScrollModeListener(options);
  11683. this.#bindSpreadModeListener(options);
  11684. this.reset();
  11685. }
  11686. get isOpen() {
  11687. return this.opened;
  11688. }
  11689. setPageNumber(pageNumber) {
  11690. this.pageNumber = pageNumber;
  11691. this.#updateUIState();
  11692. }
  11693. setPagesCount(pagesCount) {
  11694. this.pagesCount = pagesCount;
  11695. this.#updateUIState();
  11696. }
  11697. reset() {
  11698. this.pageNumber = 0;
  11699. this.pagesCount = 0;
  11700. this.#updateUIState();
  11701. this.eventBus.dispatch("secondarytoolbarreset", {
  11702. source: this
  11703. });
  11704. }
  11705. #updateUIState() {
  11706. this.items.firstPage.disabled = this.pageNumber <= 1;
  11707. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  11708. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  11709. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  11710. }
  11711. #bindClickListeners() {
  11712. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  11713. for (const {
  11714. element,
  11715. eventName,
  11716. close,
  11717. eventDetails
  11718. } of this.buttons) {
  11719. element.addEventListener("click", evt => {
  11720. if (eventName !== null) {
  11721. const details = {
  11722. source: this
  11723. };
  11724. for (const property in eventDetails) {
  11725. details[property] = eventDetails[property];
  11726. }
  11727. this.eventBus.dispatch(eventName, details);
  11728. }
  11729. if (close) {
  11730. this.close();
  11731. }
  11732. this.externalServices.reportTelemetry({
  11733. type: "buttons",
  11734. data: {
  11735. id: element.id
  11736. }
  11737. });
  11738. });
  11739. }
  11740. }
  11741. #bindCursorToolsListener({
  11742. cursorSelectToolButton,
  11743. cursorHandToolButton
  11744. }) {
  11745. this.eventBus._on("cursortoolchanged", function ({
  11746. tool
  11747. }) {
  11748. const isSelect = tool === _pdf_cursor_tools.CursorTool.SELECT,
  11749. isHand = tool === _pdf_cursor_tools.CursorTool.HAND;
  11750. cursorSelectToolButton.classList.toggle("toggled", isSelect);
  11751. cursorHandToolButton.classList.toggle("toggled", isHand);
  11752. cursorSelectToolButton.setAttribute("aria-checked", isSelect);
  11753. cursorHandToolButton.setAttribute("aria-checked", isHand);
  11754. });
  11755. }
  11756. #bindScrollModeListener({
  11757. scrollPageButton,
  11758. scrollVerticalButton,
  11759. scrollHorizontalButton,
  11760. scrollWrappedButton,
  11761. spreadNoneButton,
  11762. spreadOddButton,
  11763. spreadEvenButton
  11764. }) {
  11765. const scrollModeChanged = ({
  11766. mode
  11767. }) => {
  11768. const isPage = mode === _ui_utils.ScrollMode.PAGE,
  11769. isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
  11770. isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
  11771. isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
  11772. scrollPageButton.classList.toggle("toggled", isPage);
  11773. scrollVerticalButton.classList.toggle("toggled", isVertical);
  11774. scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
  11775. scrollWrappedButton.classList.toggle("toggled", isWrapped);
  11776. scrollPageButton.setAttribute("aria-checked", isPage);
  11777. scrollVerticalButton.setAttribute("aria-checked", isVertical);
  11778. scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
  11779. scrollWrappedButton.setAttribute("aria-checked", isWrapped);
  11780. const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11781. scrollPageButton.disabled = forceScrollModePage;
  11782. scrollVerticalButton.disabled = forceScrollModePage;
  11783. scrollHorizontalButton.disabled = forceScrollModePage;
  11784. scrollWrappedButton.disabled = forceScrollModePage;
  11785. spreadNoneButton.disabled = isHorizontal;
  11786. spreadOddButton.disabled = isHorizontal;
  11787. spreadEvenButton.disabled = isHorizontal;
  11788. };
  11789. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  11790. this.eventBus._on("secondarytoolbarreset", evt => {
  11791. if (evt.source === this) {
  11792. scrollModeChanged({
  11793. mode: _ui_utils.ScrollMode.VERTICAL
  11794. });
  11795. }
  11796. });
  11797. }
  11798. #bindSpreadModeListener({
  11799. spreadNoneButton,
  11800. spreadOddButton,
  11801. spreadEvenButton
  11802. }) {
  11803. function spreadModeChanged({
  11804. mode
  11805. }) {
  11806. const isNone = mode === _ui_utils.SpreadMode.NONE,
  11807. isOdd = mode === _ui_utils.SpreadMode.ODD,
  11808. isEven = mode === _ui_utils.SpreadMode.EVEN;
  11809. spreadNoneButton.classList.toggle("toggled", isNone);
  11810. spreadOddButton.classList.toggle("toggled", isOdd);
  11811. spreadEvenButton.classList.toggle("toggled", isEven);
  11812. spreadNoneButton.setAttribute("aria-checked", isNone);
  11813. spreadOddButton.setAttribute("aria-checked", isOdd);
  11814. spreadEvenButton.setAttribute("aria-checked", isEven);
  11815. }
  11816. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  11817. this.eventBus._on("secondarytoolbarreset", evt => {
  11818. if (evt.source === this) {
  11819. spreadModeChanged({
  11820. mode: _ui_utils.SpreadMode.NONE
  11821. });
  11822. }
  11823. });
  11824. }
  11825. open() {
  11826. if (this.opened) {
  11827. return;
  11828. }
  11829. this.opened = true;
  11830. this.toggleButton.classList.add("toggled");
  11831. this.toggleButton.setAttribute("aria-expanded", "true");
  11832. this.toolbar.classList.remove("hidden");
  11833. }
  11834. close() {
  11835. if (!this.opened) {
  11836. return;
  11837. }
  11838. this.opened = false;
  11839. this.toolbar.classList.add("hidden");
  11840. this.toggleButton.classList.remove("toggled");
  11841. this.toggleButton.setAttribute("aria-expanded", "false");
  11842. }
  11843. toggle() {
  11844. if (this.opened) {
  11845. this.close();
  11846. } else {
  11847. this.open();
  11848. }
  11849. }
  11850. }
  11851. exports.SecondaryToolbar = SecondaryToolbar;
  11852. /***/
  11853. }),
  11854. /* 39 */
  11855. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11856. Object.defineProperty(exports, "__esModule", ({
  11857. value: true
  11858. }));
  11859. exports.Toolbar = void 0;
  11860. var _ui_utils = __webpack_require__(1);
  11861. var _pdfjsLib = __webpack_require__(5);
  11862. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  11863. class Toolbar {
  11864. #wasLocalized = false;
  11865. constructor(options, eventBus, l10n) {
  11866. this.toolbar = options.container;
  11867. this.eventBus = eventBus;
  11868. this.l10n = l10n;
  11869. this.buttons = [{
  11870. element: options.previous,
  11871. eventName: "previouspage"
  11872. }, {
  11873. element: options.next,
  11874. eventName: "nextpage"
  11875. }, {
  11876. element: options.zoomIn,
  11877. eventName: "zoomin"
  11878. }, {
  11879. element: options.zoomOut,
  11880. eventName: "zoomout"
  11881. }, {
  11882. element: options.print,
  11883. eventName: "print"
  11884. }, {
  11885. element: options.download,
  11886. eventName: "download"
  11887. }, {
  11888. element: options.editorFreeTextButton,
  11889. eventName: "switchannotationeditormode",
  11890. eventDetails: {
  11891. get mode() {
  11892. const {
  11893. classList
  11894. } = options.editorFreeTextButton;
  11895. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  11896. }
  11897. }
  11898. }, {
  11899. element: options.editorInkButton,
  11900. eventName: "switchannotationeditormode",
  11901. eventDetails: {
  11902. get mode() {
  11903. const {
  11904. classList
  11905. } = options.editorInkButton;
  11906. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  11907. }
  11908. }
  11909. }];
  11910. this.buttons.push({
  11911. element: options.openFile,
  11912. eventName: "openfile"
  11913. });
  11914. this.items = {
  11915. numPages: options.numPages,
  11916. pageNumber: options.pageNumber,
  11917. scaleSelect: options.scaleSelect,
  11918. customScaleOption: options.customScaleOption,
  11919. previous: options.previous,
  11920. next: options.next,
  11921. zoomIn: options.zoomIn,
  11922. zoomOut: options.zoomOut
  11923. };
  11924. this.#bindListeners(options);
  11925. this.reset();
  11926. }
  11927. setPageNumber(pageNumber, pageLabel) {
  11928. this.pageNumber = pageNumber;
  11929. this.pageLabel = pageLabel;
  11930. this.#updateUIState(false);
  11931. }
  11932. setPagesCount(pagesCount, hasPageLabels) {
  11933. this.pagesCount = pagesCount;
  11934. this.hasPageLabels = hasPageLabels;
  11935. this.#updateUIState(true);
  11936. }
  11937. setPageScale(pageScaleValue, pageScale) {
  11938. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11939. this.pageScale = pageScale;
  11940. this.#updateUIState(false);
  11941. }
  11942. reset() {
  11943. this.pageNumber = 0;
  11944. this.pageLabel = null;
  11945. this.hasPageLabels = false;
  11946. this.pagesCount = 0;
  11947. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  11948. this.pageScale = _ui_utils.DEFAULT_SCALE;
  11949. this.#updateUIState(true);
  11950. this.updateLoadingIndicatorState();
  11951. this.eventBus.dispatch("toolbarreset", {
  11952. source: this
  11953. });
  11954. }
  11955. #bindListeners(options) {
  11956. const {
  11957. pageNumber,
  11958. scaleSelect
  11959. } = this.items;
  11960. const self = this;
  11961. for (const {
  11962. element,
  11963. eventName,
  11964. eventDetails
  11965. } of this.buttons) {
  11966. element.addEventListener("click", evt => {
  11967. if (eventName !== null) {
  11968. const details = {
  11969. source: this
  11970. };
  11971. if (eventDetails) {
  11972. for (const property in eventDetails) {
  11973. details[property] = eventDetails[property];
  11974. }
  11975. }
  11976. this.eventBus.dispatch(eventName, details);
  11977. }
  11978. });
  11979. }
  11980. pageNumber.addEventListener("click", function () {
  11981. this.select();
  11982. });
  11983. pageNumber.addEventListener("change", function () {
  11984. self.eventBus.dispatch("pagenumberchanged", {
  11985. source: self,
  11986. value: this.value
  11987. });
  11988. });
  11989. scaleSelect.addEventListener("change", function () {
  11990. if (this.value === "custom") {
  11991. return;
  11992. }
  11993. self.eventBus.dispatch("scalechanged", {
  11994. source: self,
  11995. value: this.value
  11996. });
  11997. });
  11998. scaleSelect.addEventListener("click", function (evt) {
  11999. const target = evt.target;
  12000. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  12001. this.blur();
  12002. }
  12003. });
  12004. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  12005. this.eventBus._on("localized", () => {
  12006. this.#wasLocalized = true;
  12007. this.#adjustScaleWidth();
  12008. this.#updateUIState(true);
  12009. });
  12010. this.#bindEditorToolsListener(options);
  12011. }
  12012. #bindEditorToolsListener({
  12013. editorFreeTextButton,
  12014. editorFreeTextParamsToolbar,
  12015. editorInkButton,
  12016. editorInkParamsToolbar
  12017. }) {
  12018. const editorModeChanged = (evt, disableButtons = false) => {
  12019. const editorButtons = [{
  12020. mode: _pdfjsLib.AnnotationEditorType.FREETEXT,
  12021. button: editorFreeTextButton,
  12022. toolbar: editorFreeTextParamsToolbar
  12023. }, {
  12024. mode: _pdfjsLib.AnnotationEditorType.INK,
  12025. button: editorInkButton,
  12026. toolbar: editorInkParamsToolbar
  12027. }];
  12028. for (const {
  12029. mode,
  12030. button,
  12031. toolbar
  12032. } of editorButtons) {
  12033. const checked = mode === evt.mode;
  12034. button.classList.toggle("toggled", checked);
  12035. button.setAttribute("aria-checked", checked);
  12036. button.disabled = disableButtons;
  12037. toolbar?.classList.toggle("hidden", !checked);
  12038. }
  12039. };
  12040. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  12041. this.eventBus._on("toolbarreset", evt => {
  12042. if (evt.source === this) {
  12043. editorModeChanged({
  12044. mode: _pdfjsLib.AnnotationEditorType.NONE
  12045. }, true);
  12046. }
  12047. });
  12048. }
  12049. #updateUIState(resetNumPages = false) {
  12050. if (!this.#wasLocalized) {
  12051. return;
  12052. }
  12053. const {
  12054. pageNumber,
  12055. pagesCount,
  12056. pageScaleValue,
  12057. pageScale,
  12058. items
  12059. } = this;
  12060. if (resetNumPages) {
  12061. if (this.hasPageLabels) {
  12062. items.pageNumber.type = "text";
  12063. } else {
  12064. items.pageNumber.type = "number";
  12065. this.l10n.get("of_pages", {
  12066. pagesCount
  12067. }).then(msg => {
  12068. items.numPages.textContent = msg;
  12069. });
  12070. }
  12071. items.pageNumber.max = pagesCount;
  12072. }
  12073. if (this.hasPageLabels) {
  12074. items.pageNumber.value = this.pageLabel;
  12075. this.l10n.get("page_of_pages", {
  12076. pageNumber,
  12077. pagesCount
  12078. }).then(msg => {
  12079. items.numPages.textContent = msg;
  12080. });
  12081. } else {
  12082. items.pageNumber.value = pageNumber;
  12083. }
  12084. items.previous.disabled = pageNumber <= 1;
  12085. items.next.disabled = pageNumber >= pagesCount;
  12086. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  12087. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  12088. this.l10n.get("page_scale_percent", {
  12089. scale: Math.round(pageScale * 10000) / 100
  12090. }).then(msg => {
  12091. let predefinedValueFound = false;
  12092. for (const option of items.scaleSelect.options) {
  12093. if (option.value !== pageScaleValue) {
  12094. option.selected = false;
  12095. continue;
  12096. }
  12097. option.selected = true;
  12098. predefinedValueFound = true;
  12099. }
  12100. if (!predefinedValueFound) {
  12101. items.customScaleOption.textContent = msg;
  12102. items.customScaleOption.selected = true;
  12103. }
  12104. });
  12105. }
  12106. updateLoadingIndicatorState(loading = false) {
  12107. const {
  12108. pageNumber
  12109. } = this.items;
  12110. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  12111. }
  12112. async #adjustScaleWidth() {
  12113. const {
  12114. items,
  12115. l10n
  12116. } = this;
  12117. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  12118. await _ui_utils.animationStarted;
  12119. const style = getComputedStyle(items.scaleSelect);
  12120. const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width"));
  12121. const canvas = document.createElement("canvas");
  12122. const ctx = canvas.getContext("2d", {
  12123. alpha: false
  12124. });
  12125. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  12126. let maxWidth = 0;
  12127. for (const predefinedValue of await predefinedValuesPromise) {
  12128. const {
  12129. width
  12130. } = ctx.measureText(predefinedValue);
  12131. if (width > maxWidth) {
  12132. maxWidth = width;
  12133. }
  12134. }
  12135. maxWidth += 0.3 * scaleSelectWidth;
  12136. if (maxWidth > scaleSelectWidth) {
  12137. _ui_utils.docStyle.setProperty("--scale-select-width", `${maxWidth}px`);
  12138. }
  12139. canvas.width = 0;
  12140. canvas.height = 0;
  12141. }
  12142. }
  12143. exports.Toolbar = Toolbar;
  12144. /***/
  12145. }),
  12146. /* 40 */
  12147. /***/ ((__unused_webpack_module, exports) => {
  12148. Object.defineProperty(exports, "__esModule", ({
  12149. value: true
  12150. }));
  12151. exports.ViewHistory = void 0;
  12152. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  12153. class ViewHistory {
  12154. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  12155. this.fingerprint = fingerprint;
  12156. this.cacheSize = cacheSize;
  12157. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  12158. const database = JSON.parse(databaseStr || "{}");
  12159. let index = -1;
  12160. if (!Array.isArray(database.files)) {
  12161. database.files = [];
  12162. } else {
  12163. while (database.files.length >= this.cacheSize) {
  12164. database.files.shift();
  12165. }
  12166. for (let i = 0, ii = database.files.length; i < ii; i++) {
  12167. const branch = database.files[i];
  12168. if (branch.fingerprint === this.fingerprint) {
  12169. index = i;
  12170. break;
  12171. }
  12172. }
  12173. }
  12174. if (index === -1) {
  12175. index = database.files.push({
  12176. fingerprint: this.fingerprint
  12177. }) - 1;
  12178. }
  12179. this.file = database.files[index];
  12180. this.database = database;
  12181. });
  12182. }
  12183. async _writeToStorage() {
  12184. const databaseStr = JSON.stringify(this.database);
  12185. localStorage.setItem("pdfjs.history", databaseStr);
  12186. }
  12187. async _readFromStorage() {
  12188. return localStorage.getItem("pdfjs.history");
  12189. }
  12190. async set(name, val) {
  12191. await this._initializedPromise;
  12192. this.file[name] = val;
  12193. return this._writeToStorage();
  12194. }
  12195. async setMultiple(properties) {
  12196. await this._initializedPromise;
  12197. for (const name in properties) {
  12198. this.file[name] = properties[name];
  12199. }
  12200. return this._writeToStorage();
  12201. }
  12202. async get(name, defaultValue) {
  12203. await this._initializedPromise;
  12204. const val = this.file[name];
  12205. return val !== undefined ? val : defaultValue;
  12206. }
  12207. async getMultiple(properties) {
  12208. await this._initializedPromise;
  12209. const values = Object.create(null);
  12210. for (const name in properties) {
  12211. const val = this.file[name];
  12212. values[name] = val !== undefined ? val : properties[name];
  12213. }
  12214. return values;
  12215. }
  12216. }
  12217. exports.ViewHistory = ViewHistory;
  12218. /***/
  12219. }),
  12220. /* 41 */
  12221. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12222. Object.defineProperty(exports, "__esModule", ({
  12223. value: true
  12224. }));
  12225. exports.GenericCom = void 0;
  12226. var _app = __webpack_require__(4);
  12227. var _preferences = __webpack_require__(42);
  12228. var _download_manager = __webpack_require__(43);
  12229. var _genericl10n = __webpack_require__(44);
  12230. var _generic_scripting = __webpack_require__(46);
  12231. ;
  12232. const GenericCom = {};
  12233. exports.GenericCom = GenericCom;
  12234. class GenericPreferences extends _preferences.BasePreferences {
  12235. async _writeToStorage(prefObj) {
  12236. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  12237. }
  12238. async _readFromStorage(prefObj) {
  12239. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  12240. }
  12241. }
  12242. class GenericExternalServices extends _app.DefaultExternalServices {
  12243. static createDownloadManager() {
  12244. return new _download_manager.DownloadManager();
  12245. }
  12246. static createPreferences() {
  12247. return new GenericPreferences();
  12248. }
  12249. static createL10n({
  12250. locale = "en-US"
  12251. }) {
  12252. return new _genericl10n.GenericL10n(locale);
  12253. }
  12254. static createScripting({
  12255. sandboxBundleSrc
  12256. }) {
  12257. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  12258. }
  12259. }
  12260. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  12261. /***/
  12262. }),
  12263. /* 42 */
  12264. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12265. Object.defineProperty(exports, "__esModule", ({
  12266. value: true
  12267. }));
  12268. exports.BasePreferences = void 0;
  12269. var _app_options = __webpack_require__(2);
  12270. class BasePreferences {
  12271. #defaults = Object.freeze({
  12272. "annotationEditorMode": 0,
  12273. "annotationMode": 2,
  12274. "cursorToolOnLoad": 0,
  12275. "defaultZoomDelay": 400,
  12276. "defaultZoomValue": "",
  12277. "disablePageLabels": false,
  12278. "enablePermissions": false,
  12279. "enablePrintAutoRotate": true,
  12280. "enableScripting": true,
  12281. "externalLinkTarget": 0,
  12282. "historyUpdateUrl": false,
  12283. "ignoreDestinationZoom": false,
  12284. "forcePageColors": false,
  12285. "pageColorsBackground": "Canvas",
  12286. "pageColorsForeground": "CanvasText",
  12287. "pdfBugEnabled": false,
  12288. "sidebarViewOnLoad": -1,
  12289. "scrollModeOnLoad": -1,
  12290. "spreadModeOnLoad": -1,
  12291. "textLayerMode": 1,
  12292. "useOnlyCssZoom": false,
  12293. "viewerCssTheme": 0,
  12294. "viewOnLoad": 0,
  12295. "disableAutoFetch": false,
  12296. "disableFontFace": false,
  12297. "disableRange": false,
  12298. "disableStream": false,
  12299. "enableXfa": true,
  12300. "renderer": "canvas"
  12301. });
  12302. #prefs = Object.create(null);
  12303. #initializedPromise = null;
  12304. constructor() {
  12305. if (this.constructor === BasePreferences) {
  12306. throw new Error("Cannot initialize BasePreferences.");
  12307. }
  12308. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  12309. for (const name in this.#defaults) {
  12310. const prefValue = prefs?.[name];
  12311. if (typeof prefValue === typeof this.#defaults[name]) {
  12312. this.#prefs[name] = prefValue;
  12313. }
  12314. }
  12315. });
  12316. }
  12317. async _writeToStorage(prefObj) {
  12318. throw new Error("Not implemented: _writeToStorage");
  12319. }
  12320. async _readFromStorage(prefObj) {
  12321. throw new Error("Not implemented: _readFromStorage");
  12322. }
  12323. async reset() {
  12324. await this.#initializedPromise;
  12325. const prefs = this.#prefs;
  12326. this.#prefs = Object.create(null);
  12327. return this._writeToStorage(this.#defaults).catch(reason => {
  12328. this.#prefs = prefs;
  12329. throw reason;
  12330. });
  12331. }
  12332. async set(name, value) {
  12333. await this.#initializedPromise;
  12334. const defaultValue = this.#defaults[name],
  12335. prefs = this.#prefs;
  12336. if (defaultValue === undefined) {
  12337. throw new Error(`Set preference: "${name}" is undefined.`);
  12338. } else if (value === undefined) {
  12339. throw new Error("Set preference: no value is specified.");
  12340. }
  12341. const valueType = typeof value,
  12342. defaultType = typeof defaultValue;
  12343. if (valueType !== defaultType) {
  12344. if (valueType === "number" && defaultType === "string") {
  12345. value = value.toString();
  12346. } else {
  12347. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  12348. }
  12349. } else {
  12350. if (valueType === "number" && !Number.isInteger(value)) {
  12351. throw new Error(`Set preference: "${value}" must be an integer.`);
  12352. }
  12353. }
  12354. this.#prefs[name] = value;
  12355. return this._writeToStorage(this.#prefs).catch(reason => {
  12356. this.#prefs = prefs;
  12357. throw reason;
  12358. });
  12359. }
  12360. async get(name) {
  12361. await this.#initializedPromise;
  12362. const defaultValue = this.#defaults[name];
  12363. if (defaultValue === undefined) {
  12364. throw new Error(`Get preference: "${name}" is undefined.`);
  12365. }
  12366. return this.#prefs[name] ?? defaultValue;
  12367. }
  12368. async getAll() {
  12369. await this.#initializedPromise;
  12370. const obj = Object.create(null);
  12371. for (const name in this.#defaults) {
  12372. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  12373. }
  12374. return obj;
  12375. }
  12376. }
  12377. exports.BasePreferences = BasePreferences;
  12378. /***/
  12379. }),
  12380. /* 43 */
  12381. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12382. Object.defineProperty(exports, "__esModule", ({
  12383. value: true
  12384. }));
  12385. exports.DownloadManager = void 0;
  12386. var _pdfjsLib = __webpack_require__(5);
  12387. ;
  12388. function download(blobUrl, filename) {
  12389. const a = document.createElement("a");
  12390. if (!a.click) {
  12391. throw new Error('DownloadManager: "a.click()" is not supported.');
  12392. }
  12393. a.href = blobUrl;
  12394. a.target = "_parent";
  12395. if ("download" in a) {
  12396. a.download = filename;
  12397. }
  12398. (document.body || document.documentElement).append(a);
  12399. a.click();
  12400. a.remove();
  12401. }
  12402. class DownloadManager {
  12403. #openBlobUrls = new WeakMap();
  12404. downloadUrl(url, filename) {
  12405. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  12406. console.error(`downloadUrl - not a valid URL: ${url}`);
  12407. return;
  12408. }
  12409. download(url + "#pdfjs.action=download", filename);
  12410. }
  12411. downloadData(data, filename, contentType) {
  12412. const blobUrl = URL.createObjectURL(new Blob([data], {
  12413. type: contentType
  12414. }));
  12415. download(blobUrl, filename);
  12416. }
  12417. openOrDownloadData(element, data, filename) {
  12418. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  12419. const contentType = isPdfData ? "application/pdf" : "";
  12420. if (isPdfData) {
  12421. let blobUrl = this.#openBlobUrls.get(element);
  12422. if (!blobUrl) {
  12423. blobUrl = URL.createObjectURL(new Blob([data], {
  12424. type: contentType
  12425. }));
  12426. this.#openBlobUrls.set(element, blobUrl);
  12427. }
  12428. let viewerUrl;
  12429. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  12430. try {
  12431. window.open(viewerUrl);
  12432. return true;
  12433. } catch (ex) {
  12434. console.error(`openOrDownloadData: ${ex}`);
  12435. URL.revokeObjectURL(blobUrl);
  12436. this.#openBlobUrls.delete(element);
  12437. }
  12438. }
  12439. this.downloadData(data, filename, contentType);
  12440. return false;
  12441. }
  12442. download(blob, url, filename) {
  12443. const blobUrl = URL.createObjectURL(blob);
  12444. download(blobUrl, filename);
  12445. }
  12446. }
  12447. exports.DownloadManager = DownloadManager;
  12448. /***/
  12449. }),
  12450. /* 44 */
  12451. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12452. Object.defineProperty(exports, "__esModule", ({
  12453. value: true
  12454. }));
  12455. exports.GenericL10n = void 0;
  12456. __webpack_require__(45);
  12457. var _l10n_utils = __webpack_require__(29);
  12458. const webL10n = document.webL10n;
  12459. class GenericL10n {
  12460. constructor(lang) {
  12461. this._lang = lang;
  12462. this._ready = new Promise((resolve, reject) => {
  12463. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  12464. resolve(webL10n);
  12465. });
  12466. });
  12467. }
  12468. async getLanguage() {
  12469. const l10n = await this._ready;
  12470. return l10n.getLanguage();
  12471. }
  12472. async getDirection() {
  12473. const l10n = await this._ready;
  12474. return l10n.getDirection();
  12475. }
  12476. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  12477. const l10n = await this._ready;
  12478. return l10n.get(key, args, fallback);
  12479. }
  12480. async translate(element) {
  12481. const l10n = await this._ready;
  12482. return l10n.translate(element);
  12483. }
  12484. }
  12485. exports.GenericL10n = GenericL10n;
  12486. /***/
  12487. }),
  12488. /* 45 */
  12489. /***/ (() => {
  12490. document.webL10n = function (window, document, undefined) {
  12491. var gL10nData = {};
  12492. var gTextData = '';
  12493. var gTextProp = 'textContent';
  12494. var gLanguage = '';
  12495. var gMacros = {};
  12496. var gReadyState = 'loading';
  12497. var gAsyncResourceLoading = true;
  12498. function getL10nResourceLinks() {
  12499. return document.querySelectorAll('link[type="application/l10n"]');
  12500. }
  12501. function getL10nDictionary() {
  12502. var script = document.querySelector('script[type="application/l10n"]');
  12503. return script ? JSON.parse(script.innerHTML) : null;
  12504. }
  12505. function getTranslatableChildren(element) {
  12506. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  12507. }
  12508. function getL10nAttributes(element) {
  12509. if (!element) return {};
  12510. var l10nId = element.getAttribute('data-l10n-id');
  12511. var l10nArgs = element.getAttribute('data-l10n-args');
  12512. var args = {};
  12513. if (l10nArgs) {
  12514. try {
  12515. args = JSON.parse(l10nArgs);
  12516. } catch (e) {
  12517. console.warn('could not parse arguments for #' + l10nId);
  12518. }
  12519. }
  12520. return {
  12521. id: l10nId,
  12522. args: args
  12523. };
  12524. }
  12525. function xhrLoadText(url, onSuccess, onFailure) {
  12526. onSuccess = onSuccess || function _onSuccess(data) { };
  12527. onFailure = onFailure || function _onFailure() { };
  12528. var xhr = new XMLHttpRequest();
  12529. xhr.open('GET', url, gAsyncResourceLoading);
  12530. if (xhr.overrideMimeType) {
  12531. xhr.overrideMimeType('text/plain; charset=utf-8');
  12532. }
  12533. xhr.onreadystatechange = function () {
  12534. if (xhr.readyState == 4) {
  12535. if (xhr.status == 200 || xhr.status === 0) {
  12536. onSuccess(xhr.responseText);
  12537. } else {
  12538. onFailure();
  12539. }
  12540. }
  12541. };
  12542. xhr.onerror = onFailure;
  12543. xhr.ontimeout = onFailure;
  12544. try {
  12545. xhr.send(null);
  12546. } catch (e) {
  12547. onFailure();
  12548. }
  12549. }
  12550. function parseResource(href, lang, successCallback, failureCallback) {
  12551. var baseURL = href.replace(/[^\/]*$/, '') || './';
  12552. function evalString(text) {
  12553. if (text.lastIndexOf('\\') < 0) return text;
  12554. 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, "'");
  12555. }
  12556. function parseProperties(text, parsedPropertiesCallback) {
  12557. var dictionary = {};
  12558. var reBlank = /^\s*|\s*$/;
  12559. var reComment = /^\s*#|^\s*$/;
  12560. var reSection = /^\s*\[(.*)\]\s*$/;
  12561. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  12562. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  12563. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  12564. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  12565. var currentLang = '*';
  12566. var genericLang = lang.split('-', 1)[0];
  12567. var skipLang = false;
  12568. var match = '';
  12569. function nextEntry() {
  12570. while (true) {
  12571. if (!entries.length) {
  12572. parsedRawLinesCallback();
  12573. return;
  12574. }
  12575. var line = entries.shift();
  12576. if (reComment.test(line)) continue;
  12577. if (extendedSyntax) {
  12578. match = reSection.exec(line);
  12579. if (match) {
  12580. currentLang = match[1].toLowerCase();
  12581. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  12582. continue;
  12583. } else if (skipLang) {
  12584. continue;
  12585. }
  12586. match = reImport.exec(line);
  12587. if (match) {
  12588. loadImport(baseURL + match[1], nextEntry);
  12589. return;
  12590. }
  12591. }
  12592. var tmp = line.match(reSplit);
  12593. if (tmp && tmp.length == 3) {
  12594. dictionary[tmp[1]] = evalString(tmp[2]);
  12595. }
  12596. }
  12597. }
  12598. nextEntry();
  12599. }
  12600. function loadImport(url, callback) {
  12601. xhrLoadText(url, function (content) {
  12602. parseRawLines(content, false, callback);
  12603. }, function () {
  12604. console.warn(url + ' not found.');
  12605. callback();
  12606. });
  12607. }
  12608. parseRawLines(text, true, function () {
  12609. parsedPropertiesCallback(dictionary);
  12610. });
  12611. }
  12612. xhrLoadText(href, function (response) {
  12613. gTextData += response;
  12614. parseProperties(response, function (data) {
  12615. for (var key in data) {
  12616. var id,
  12617. prop,
  12618. index = key.lastIndexOf('.');
  12619. if (index > 0) {
  12620. id = key.substring(0, index);
  12621. prop = key.substring(index + 1);
  12622. } else {
  12623. id = key;
  12624. prop = gTextProp;
  12625. }
  12626. if (!gL10nData[id]) {
  12627. gL10nData[id] = {};
  12628. }
  12629. gL10nData[id][prop] = data[key];
  12630. }
  12631. if (successCallback) {
  12632. successCallback();
  12633. }
  12634. });
  12635. }, failureCallback);
  12636. }
  12637. function loadLocale(lang, callback) {
  12638. if (lang) {
  12639. lang = lang.toLowerCase();
  12640. }
  12641. callback = callback || function _callback() { };
  12642. clear();
  12643. gLanguage = lang;
  12644. var langLinks = getL10nResourceLinks();
  12645. var langCount = langLinks.length;
  12646. if (langCount === 0) {
  12647. var dict = getL10nDictionary();
  12648. if (dict && dict.locales && dict.default_locale) {
  12649. console.log('using the embedded JSON directory, early way out');
  12650. gL10nData = dict.locales[lang];
  12651. if (!gL10nData) {
  12652. var defaultLocale = dict.default_locale.toLowerCase();
  12653. for (var anyCaseLang in dict.locales) {
  12654. anyCaseLang = anyCaseLang.toLowerCase();
  12655. if (anyCaseLang === lang) {
  12656. gL10nData = dict.locales[lang];
  12657. break;
  12658. } else if (anyCaseLang === defaultLocale) {
  12659. gL10nData = dict.locales[defaultLocale];
  12660. }
  12661. }
  12662. }
  12663. callback();
  12664. } else {
  12665. console.log('no resource to load, early way out');
  12666. }
  12667. gReadyState = 'complete';
  12668. return;
  12669. }
  12670. var onResourceLoaded = null;
  12671. var gResourceCount = 0;
  12672. onResourceLoaded = function () {
  12673. gResourceCount++;
  12674. if (gResourceCount >= langCount) {
  12675. callback();
  12676. gReadyState = 'complete';
  12677. }
  12678. };
  12679. function L10nResourceLink(link) {
  12680. var href = link.href;
  12681. this.load = function (lang, callback) {
  12682. parseResource(href, lang, callback, function () {
  12683. console.warn(href + ' not found.');
  12684. console.warn('"' + lang + '" resource not found');
  12685. gLanguage = '';
  12686. callback();
  12687. });
  12688. };
  12689. }
  12690. for (var i = 0; i < langCount; i++) {
  12691. var resource = new L10nResourceLink(langLinks[i]);
  12692. resource.load(lang, onResourceLoaded);
  12693. }
  12694. }
  12695. function clear() {
  12696. gL10nData = {};
  12697. gTextData = '';
  12698. gLanguage = '';
  12699. }
  12700. function getPluralRules(lang) {
  12701. var locales2rules = {
  12702. 'af': 3,
  12703. 'ak': 4,
  12704. 'am': 4,
  12705. 'ar': 1,
  12706. 'asa': 3,
  12707. 'az': 0,
  12708. 'be': 11,
  12709. 'bem': 3,
  12710. 'bez': 3,
  12711. 'bg': 3,
  12712. 'bh': 4,
  12713. 'bm': 0,
  12714. 'bn': 3,
  12715. 'bo': 0,
  12716. 'br': 20,
  12717. 'brx': 3,
  12718. 'bs': 11,
  12719. 'ca': 3,
  12720. 'cgg': 3,
  12721. 'chr': 3,
  12722. 'cs': 12,
  12723. 'cy': 17,
  12724. 'da': 3,
  12725. 'de': 3,
  12726. 'dv': 3,
  12727. 'dz': 0,
  12728. 'ee': 3,
  12729. 'el': 3,
  12730. 'en': 3,
  12731. 'eo': 3,
  12732. 'es': 3,
  12733. 'et': 3,
  12734. 'eu': 3,
  12735. 'fa': 0,
  12736. 'ff': 5,
  12737. 'fi': 3,
  12738. 'fil': 4,
  12739. 'fo': 3,
  12740. 'fr': 5,
  12741. 'fur': 3,
  12742. 'fy': 3,
  12743. 'ga': 8,
  12744. 'gd': 24,
  12745. 'gl': 3,
  12746. 'gsw': 3,
  12747. 'gu': 3,
  12748. 'guw': 4,
  12749. 'gv': 23,
  12750. 'ha': 3,
  12751. 'haw': 3,
  12752. 'he': 2,
  12753. 'hi': 4,
  12754. 'hr': 11,
  12755. 'hu': 0,
  12756. 'id': 0,
  12757. 'ig': 0,
  12758. 'ii': 0,
  12759. 'is': 3,
  12760. 'it': 3,
  12761. 'iu': 7,
  12762. 'ja': 0,
  12763. 'jmc': 3,
  12764. 'jv': 0,
  12765. 'ka': 0,
  12766. 'kab': 5,
  12767. 'kaj': 3,
  12768. 'kcg': 3,
  12769. 'kde': 0,
  12770. 'kea': 0,
  12771. 'kk': 3,
  12772. 'kl': 3,
  12773. 'km': 0,
  12774. 'kn': 0,
  12775. 'ko': 0,
  12776. 'ksb': 3,
  12777. 'ksh': 21,
  12778. 'ku': 3,
  12779. 'kw': 7,
  12780. 'lag': 18,
  12781. 'lb': 3,
  12782. 'lg': 3,
  12783. 'ln': 4,
  12784. 'lo': 0,
  12785. 'lt': 10,
  12786. 'lv': 6,
  12787. 'mas': 3,
  12788. 'mg': 4,
  12789. 'mk': 16,
  12790. 'ml': 3,
  12791. 'mn': 3,
  12792. 'mo': 9,
  12793. 'mr': 3,
  12794. 'ms': 0,
  12795. 'mt': 15,
  12796. 'my': 0,
  12797. 'nah': 3,
  12798. 'naq': 7,
  12799. 'nb': 3,
  12800. 'nd': 3,
  12801. 'ne': 3,
  12802. 'nl': 3,
  12803. 'nn': 3,
  12804. 'no': 3,
  12805. 'nr': 3,
  12806. 'nso': 4,
  12807. 'ny': 3,
  12808. 'nyn': 3,
  12809. 'om': 3,
  12810. 'or': 3,
  12811. 'pa': 3,
  12812. 'pap': 3,
  12813. 'pl': 13,
  12814. 'ps': 3,
  12815. 'pt': 3,
  12816. 'rm': 3,
  12817. 'ro': 9,
  12818. 'rof': 3,
  12819. 'ru': 11,
  12820. 'rwk': 3,
  12821. 'sah': 0,
  12822. 'saq': 3,
  12823. 'se': 7,
  12824. 'seh': 3,
  12825. 'ses': 0,
  12826. 'sg': 0,
  12827. 'sh': 11,
  12828. 'shi': 19,
  12829. 'sk': 12,
  12830. 'sl': 14,
  12831. 'sma': 7,
  12832. 'smi': 7,
  12833. 'smj': 7,
  12834. 'smn': 7,
  12835. 'sms': 7,
  12836. 'sn': 3,
  12837. 'so': 3,
  12838. 'sq': 3,
  12839. 'sr': 11,
  12840. 'ss': 3,
  12841. 'ssy': 3,
  12842. 'st': 3,
  12843. 'sv': 3,
  12844. 'sw': 3,
  12845. 'syr': 3,
  12846. 'ta': 3,
  12847. 'te': 3,
  12848. 'teo': 3,
  12849. 'th': 0,
  12850. 'ti': 4,
  12851. 'tig': 3,
  12852. 'tk': 3,
  12853. 'tl': 4,
  12854. 'tn': 3,
  12855. 'to': 0,
  12856. 'tr': 0,
  12857. 'ts': 3,
  12858. 'tzm': 22,
  12859. 'uk': 11,
  12860. 'ur': 3,
  12861. 've': 3,
  12862. 'vi': 0,
  12863. 'vun': 3,
  12864. 'wa': 4,
  12865. 'wae': 3,
  12866. 'wo': 0,
  12867. 'xh': 3,
  12868. 'xog': 3,
  12869. 'yo': 0,
  12870. 'zh': 0,
  12871. 'zu': 3
  12872. };
  12873. function isIn(n, list) {
  12874. return list.indexOf(n) !== -1;
  12875. }
  12876. function isBetween(n, start, end) {
  12877. return start <= n && n <= end;
  12878. }
  12879. var pluralRules = {
  12880. '0': function (n) {
  12881. return 'other';
  12882. },
  12883. '1': function (n) {
  12884. if (isBetween(n % 100, 3, 10)) return 'few';
  12885. if (n === 0) return 'zero';
  12886. if (isBetween(n % 100, 11, 99)) return 'many';
  12887. if (n == 2) return 'two';
  12888. if (n == 1) return 'one';
  12889. return 'other';
  12890. },
  12891. '2': function (n) {
  12892. if (n !== 0 && n % 10 === 0) return 'many';
  12893. if (n == 2) return 'two';
  12894. if (n == 1) return 'one';
  12895. return 'other';
  12896. },
  12897. '3': function (n) {
  12898. if (n == 1) return 'one';
  12899. return 'other';
  12900. },
  12901. '4': function (n) {
  12902. if (isBetween(n, 0, 1)) return 'one';
  12903. return 'other';
  12904. },
  12905. '5': function (n) {
  12906. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12907. return 'other';
  12908. },
  12909. '6': function (n) {
  12910. if (n === 0) return 'zero';
  12911. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12912. return 'other';
  12913. },
  12914. '7': function (n) {
  12915. if (n == 2) return 'two';
  12916. if (n == 1) return 'one';
  12917. return 'other';
  12918. },
  12919. '8': function (n) {
  12920. if (isBetween(n, 3, 6)) return 'few';
  12921. if (isBetween(n, 7, 10)) return 'many';
  12922. if (n == 2) return 'two';
  12923. if (n == 1) return 'one';
  12924. return 'other';
  12925. },
  12926. '9': function (n) {
  12927. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12928. if (n == 1) return 'one';
  12929. return 'other';
  12930. },
  12931. '10': function (n) {
  12932. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12933. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12934. return 'other';
  12935. },
  12936. '11': function (n) {
  12937. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12938. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12939. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12940. return 'other';
  12941. },
  12942. '12': function (n) {
  12943. if (isBetween(n, 2, 4)) return 'few';
  12944. if (n == 1) return 'one';
  12945. return 'other';
  12946. },
  12947. '13': function (n) {
  12948. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12949. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12950. if (n == 1) return 'one';
  12951. return 'other';
  12952. },
  12953. '14': function (n) {
  12954. if (isBetween(n % 100, 3, 4)) return 'few';
  12955. if (n % 100 == 2) return 'two';
  12956. if (n % 100 == 1) return 'one';
  12957. return 'other';
  12958. },
  12959. '15': function (n) {
  12960. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12961. if (isBetween(n % 100, 11, 19)) return 'many';
  12962. if (n == 1) return 'one';
  12963. return 'other';
  12964. },
  12965. '16': function (n) {
  12966. if (n % 10 == 1 && n != 11) return 'one';
  12967. return 'other';
  12968. },
  12969. '17': function (n) {
  12970. if (n == 3) return 'few';
  12971. if (n === 0) return 'zero';
  12972. if (n == 6) return 'many';
  12973. if (n == 2) return 'two';
  12974. if (n == 1) return 'one';
  12975. return 'other';
  12976. },
  12977. '18': function (n) {
  12978. if (n === 0) return 'zero';
  12979. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12980. return 'other';
  12981. },
  12982. '19': function (n) {
  12983. if (isBetween(n, 2, 10)) return 'few';
  12984. if (isBetween(n, 0, 1)) return 'one';
  12985. return 'other';
  12986. },
  12987. '20': function (n) {
  12988. 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';
  12989. if (n % 1000000 === 0 && n !== 0) return 'many';
  12990. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12991. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12992. return 'other';
  12993. },
  12994. '21': function (n) {
  12995. if (n === 0) return 'zero';
  12996. if (n == 1) return 'one';
  12997. return 'other';
  12998. },
  12999. '22': function (n) {
  13000. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  13001. return 'other';
  13002. },
  13003. '23': function (n) {
  13004. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  13005. return 'other';
  13006. },
  13007. '24': function (n) {
  13008. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  13009. if (isIn(n, [2, 12])) return 'two';
  13010. if (isIn(n, [1, 11])) return 'one';
  13011. return 'other';
  13012. }
  13013. };
  13014. var index = locales2rules[lang.replace(/-.*$/, '')];
  13015. if (!(index in pluralRules)) {
  13016. console.warn('plural form unknown for [' + lang + ']');
  13017. return function () {
  13018. return 'other';
  13019. };
  13020. }
  13021. return pluralRules[index];
  13022. }
  13023. gMacros.plural = function (str, param, key, prop) {
  13024. var n = parseFloat(param);
  13025. if (isNaN(n)) return str;
  13026. if (prop != gTextProp) return str;
  13027. if (!gMacros._pluralRules) {
  13028. gMacros._pluralRules = getPluralRules(gLanguage);
  13029. }
  13030. var index = '[' + gMacros._pluralRules(n) + ']';
  13031. if (n === 0 && key + '[zero]' in gL10nData) {
  13032. str = gL10nData[key + '[zero]'][prop];
  13033. } else if (n == 1 && key + '[one]' in gL10nData) {
  13034. str = gL10nData[key + '[one]'][prop];
  13035. } else if (n == 2 && key + '[two]' in gL10nData) {
  13036. str = gL10nData[key + '[two]'][prop];
  13037. } else if (key + index in gL10nData) {
  13038. str = gL10nData[key + index][prop];
  13039. } else if (key + '[other]' in gL10nData) {
  13040. str = gL10nData[key + '[other]'][prop];
  13041. }
  13042. return str;
  13043. };
  13044. function getL10nData(key, args, fallback) {
  13045. var data = gL10nData[key];
  13046. if (!data) {
  13047. console.warn('#' + key + ' is undefined.');
  13048. if (!fallback) {
  13049. return null;
  13050. }
  13051. data = fallback;
  13052. }
  13053. var rv = {};
  13054. for (var prop in data) {
  13055. var str = data[prop];
  13056. str = substIndexes(str, args, key, prop);
  13057. str = substArguments(str, args, key);
  13058. rv[prop] = str;
  13059. }
  13060. return rv;
  13061. }
  13062. function substIndexes(str, args, key, prop) {
  13063. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  13064. var reMatch = reIndex.exec(str);
  13065. if (!reMatch || !reMatch.length) return str;
  13066. var macroName = reMatch[1];
  13067. var paramName = reMatch[2];
  13068. var param;
  13069. if (args && paramName in args) {
  13070. param = args[paramName];
  13071. } else if (paramName in gL10nData) {
  13072. param = gL10nData[paramName];
  13073. }
  13074. if (macroName in gMacros) {
  13075. var macro = gMacros[macroName];
  13076. str = macro(str, param, key, prop);
  13077. }
  13078. return str;
  13079. }
  13080. function substArguments(str, args, key) {
  13081. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  13082. return str.replace(reArgs, function (matched_text, arg) {
  13083. if (args && arg in args) {
  13084. return args[arg];
  13085. }
  13086. if (arg in gL10nData) {
  13087. return gL10nData[arg];
  13088. }
  13089. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  13090. return matched_text;
  13091. });
  13092. }
  13093. function translateElement(element) {
  13094. var l10n = getL10nAttributes(element);
  13095. if (!l10n.id) return;
  13096. var data = getL10nData(l10n.id, l10n.args);
  13097. if (!data) {
  13098. console.warn('#' + l10n.id + ' is undefined.');
  13099. return;
  13100. }
  13101. if (data[gTextProp]) {
  13102. if (getChildElementCount(element) === 0) {
  13103. element[gTextProp] = data[gTextProp];
  13104. } else {
  13105. var children = element.childNodes;
  13106. var found = false;
  13107. for (var i = 0, l = children.length; i < l; i++) {
  13108. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  13109. if (found) {
  13110. children[i].nodeValue = '';
  13111. } else {
  13112. children[i].nodeValue = data[gTextProp];
  13113. found = true;
  13114. }
  13115. }
  13116. }
  13117. if (!found) {
  13118. var textNode = document.createTextNode(data[gTextProp]);
  13119. element.prepend(textNode);
  13120. }
  13121. }
  13122. delete data[gTextProp];
  13123. }
  13124. for (var k in data) {
  13125. element[k] = data[k];
  13126. }
  13127. }
  13128. function getChildElementCount(element) {
  13129. if (element.children) {
  13130. return element.children.length;
  13131. }
  13132. if (typeof element.childElementCount !== 'undefined') {
  13133. return element.childElementCount;
  13134. }
  13135. var count = 0;
  13136. for (var i = 0; i < element.childNodes.length; i++) {
  13137. count += element.nodeType === 1 ? 1 : 0;
  13138. }
  13139. return count;
  13140. }
  13141. function translateFragment(element) {
  13142. element = element || document.documentElement;
  13143. var children = getTranslatableChildren(element);
  13144. var elementCount = children.length;
  13145. for (var i = 0; i < elementCount; i++) {
  13146. translateElement(children[i]);
  13147. }
  13148. translateElement(element);
  13149. }
  13150. return {
  13151. get: function (key, args, fallbackString) {
  13152. var index = key.lastIndexOf('.');
  13153. var prop = gTextProp;
  13154. if (index > 0) {
  13155. prop = key.substring(index + 1);
  13156. key = key.substring(0, index);
  13157. }
  13158. var fallback;
  13159. if (fallbackString) {
  13160. fallback = {};
  13161. fallback[prop] = fallbackString;
  13162. }
  13163. var data = getL10nData(key, args, fallback);
  13164. if (data && prop in data) {
  13165. return data[prop];
  13166. }
  13167. return '{{' + key + '}}';
  13168. },
  13169. getData: function () {
  13170. return gL10nData;
  13171. },
  13172. getText: function () {
  13173. return gTextData;
  13174. },
  13175. getLanguage: function () {
  13176. return gLanguage;
  13177. },
  13178. setLanguage: function (lang, callback) {
  13179. loadLocale(lang, function () {
  13180. if (callback) callback();
  13181. });
  13182. },
  13183. getDirection: function () {
  13184. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  13185. var shortCode = gLanguage.split('-', 1)[0];
  13186. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  13187. },
  13188. translate: translateFragment,
  13189. getReadyState: function () {
  13190. return gReadyState;
  13191. },
  13192. ready: function (callback) {
  13193. if (!callback) {
  13194. return;
  13195. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  13196. window.setTimeout(function () {
  13197. callback();
  13198. });
  13199. } else if (document.addEventListener) {
  13200. document.addEventListener('localized', function once() {
  13201. document.removeEventListener('localized', once);
  13202. callback();
  13203. });
  13204. }
  13205. }
  13206. };
  13207. }(window, document);
  13208. /***/
  13209. }),
  13210. /* 46 */
  13211. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13212. Object.defineProperty(exports, "__esModule", ({
  13213. value: true
  13214. }));
  13215. exports.GenericScripting = void 0;
  13216. exports.docPropertiesLookup = docPropertiesLookup;
  13217. var _pdfjsLib = __webpack_require__(5);
  13218. async function docPropertiesLookup(pdfDocument) {
  13219. const url = "",
  13220. baseUrl = url.split("#")[0];
  13221. let {
  13222. info,
  13223. metadata,
  13224. contentDispositionFilename,
  13225. contentLength
  13226. } = await pdfDocument.getMetadata();
  13227. if (!contentLength) {
  13228. const {
  13229. length
  13230. } = await pdfDocument.getDownloadInfo();
  13231. contentLength = length;
  13232. }
  13233. return {
  13234. ...info,
  13235. baseURL: baseUrl,
  13236. filesize: contentLength,
  13237. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  13238. metadata: metadata?.getRaw(),
  13239. authors: metadata?.get("dc:creator"),
  13240. numPages: pdfDocument.numPages,
  13241. URL: url
  13242. };
  13243. }
  13244. class GenericScripting {
  13245. constructor(sandboxBundleSrc) {
  13246. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  13247. return window.pdfjsSandbox.QuickJSSandbox();
  13248. });
  13249. }
  13250. async createSandbox(data) {
  13251. const sandbox = await this._ready;
  13252. sandbox.create(data);
  13253. }
  13254. async dispatchEventInSandbox(event) {
  13255. const sandbox = await this._ready;
  13256. setTimeout(() => sandbox.dispatchEvent(event), 0);
  13257. }
  13258. async destroySandbox() {
  13259. const sandbox = await this._ready;
  13260. sandbox.nukeSandbox();
  13261. }
  13262. }
  13263. exports.GenericScripting = GenericScripting;
  13264. /***/
  13265. }),
  13266. /* 47 */
  13267. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13268. Object.defineProperty(exports, "__esModule", ({
  13269. value: true
  13270. }));
  13271. exports.PDFPrintService = PDFPrintService;
  13272. var _pdfjsLib = __webpack_require__(5);
  13273. var _app = __webpack_require__(4);
  13274. var _print_utils = __webpack_require__(48);
  13275. let activeService = null;
  13276. let dialog = null;
  13277. let overlayManager = null;
  13278. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  13279. const scratchCanvas = activeService.scratchCanvas;
  13280. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  13281. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  13282. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  13283. const ctx = scratchCanvas.getContext("2d");
  13284. ctx.save();
  13285. ctx.fillStyle = "rgb(255, 255, 255)";
  13286. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  13287. ctx.restore();
  13288. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  13289. const renderContext = {
  13290. canvasContext: ctx,
  13291. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  13292. viewport: pdfPage.getViewport({
  13293. scale: 1,
  13294. rotation: size.rotation
  13295. }),
  13296. intent: "print",
  13297. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  13298. optionalContentConfigPromise,
  13299. printAnnotationStorage
  13300. };
  13301. return pdfPage.render(renderContext).promise;
  13302. });
  13303. }
  13304. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) {
  13305. this.pdfDocument = pdfDocument;
  13306. this.pagesOverview = pagesOverview;
  13307. this.printContainer = printContainer;
  13308. this._printResolution = printResolution || 150;
  13309. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  13310. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  13311. this.l10n = l10n;
  13312. this.currentPage = -1;
  13313. this.scratchCanvas = document.createElement("canvas");
  13314. }
  13315. PDFPrintService.prototype = {
  13316. layout() {
  13317. this.throwIfInactive();
  13318. const body = document.querySelector("body");
  13319. body.setAttribute("data-pdfjsprinting", true);
  13320. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  13321. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  13322. }, this);
  13323. if (!hasEqualPageSizes) {
  13324. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  13325. }
  13326. this.pageStyleSheet = document.createElement("style");
  13327. const pageSize = this.pagesOverview[0];
  13328. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  13329. body.append(this.pageStyleSheet);
  13330. },
  13331. destroy() {
  13332. if (activeService !== this) {
  13333. return;
  13334. }
  13335. this.printContainer.textContent = "";
  13336. const body = document.querySelector("body");
  13337. body.removeAttribute("data-pdfjsprinting");
  13338. if (this.pageStyleSheet) {
  13339. this.pageStyleSheet.remove();
  13340. this.pageStyleSheet = null;
  13341. }
  13342. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  13343. this.scratchCanvas = null;
  13344. activeService = null;
  13345. ensureOverlay().then(function () {
  13346. if (overlayManager.active === dialog) {
  13347. overlayManager.close(dialog);
  13348. }
  13349. });
  13350. },
  13351. renderPages() {
  13352. if (this.pdfDocument.isPureXfa) {
  13353. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  13354. return Promise.resolve();
  13355. }
  13356. const pageCount = this.pagesOverview.length;
  13357. const renderNextPage = (resolve, reject) => {
  13358. this.throwIfInactive();
  13359. if (++this.currentPage >= pageCount) {
  13360. renderProgress(pageCount, pageCount, this.l10n);
  13361. resolve();
  13362. return;
  13363. }
  13364. const index = this.currentPage;
  13365. renderProgress(index, pageCount, this.l10n);
  13366. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  13367. renderNextPage(resolve, reject);
  13368. }, reject);
  13369. };
  13370. return new Promise(renderNextPage);
  13371. },
  13372. useRenderedPage() {
  13373. this.throwIfInactive();
  13374. const img = document.createElement("img");
  13375. const scratchCanvas = this.scratchCanvas;
  13376. if ("toBlob" in scratchCanvas) {
  13377. scratchCanvas.toBlob(function (blob) {
  13378. img.src = URL.createObjectURL(blob);
  13379. });
  13380. } else {
  13381. img.src = scratchCanvas.toDataURL();
  13382. }
  13383. const wrapper = document.createElement("div");
  13384. wrapper.className = "printedPage";
  13385. wrapper.append(img);
  13386. this.printContainer.append(wrapper);
  13387. return new Promise(function (resolve, reject) {
  13388. img.onload = resolve;
  13389. img.onerror = reject;
  13390. });
  13391. },
  13392. performPrint() {
  13393. this.throwIfInactive();
  13394. return new Promise(resolve => {
  13395. setTimeout(() => {
  13396. if (!this.active) {
  13397. resolve();
  13398. return;
  13399. }
  13400. print.call(window);
  13401. setTimeout(resolve, 20);
  13402. }, 0);
  13403. });
  13404. },
  13405. get active() {
  13406. return this === activeService;
  13407. },
  13408. throwIfInactive() {
  13409. if (!this.active) {
  13410. throw new Error("This print request was cancelled or completed.");
  13411. }
  13412. }
  13413. };
  13414. const print = window.print;
  13415. window.print = function () {
  13416. if (activeService) {
  13417. console.warn("Ignored window.print() because of a pending print job.");
  13418. return;
  13419. }
  13420. ensureOverlay().then(function () {
  13421. if (activeService) {
  13422. overlayManager.open(dialog);
  13423. }
  13424. });
  13425. try {
  13426. dispatchEvent("beforeprint");
  13427. } finally {
  13428. if (!activeService) {
  13429. console.error("Expected print service to be initialized.");
  13430. ensureOverlay().then(function () {
  13431. if (overlayManager.active === dialog) {
  13432. overlayManager.close(dialog);
  13433. }
  13434. });
  13435. return;
  13436. }
  13437. const activeServiceOnEntry = activeService;
  13438. activeService.renderPages().then(function () {
  13439. return activeServiceOnEntry.performPrint();
  13440. }).catch(function () { }).then(function () {
  13441. if (activeServiceOnEntry.active) {
  13442. abort();
  13443. }
  13444. });
  13445. }
  13446. };
  13447. function dispatchEvent(eventType) {
  13448. const event = document.createEvent("CustomEvent");
  13449. event.initCustomEvent(eventType, false, false, "custom");
  13450. window.dispatchEvent(event);
  13451. }
  13452. function abort() {
  13453. if (activeService) {
  13454. activeService.destroy();
  13455. dispatchEvent("afterprint");
  13456. }
  13457. }
  13458. function renderProgress(index, total, l10n) {
  13459. dialog ||= document.getElementById("printServiceDialog");
  13460. const progress = Math.round(100 * index / total);
  13461. const progressBar = dialog.querySelector("progress");
  13462. const progressPerc = dialog.querySelector(".relative-progress");
  13463. progressBar.value = progress;
  13464. l10n.get("print_progress_percent", {
  13465. progress
  13466. }).then(msg => {
  13467. progressPerc.textContent = msg;
  13468. });
  13469. }
  13470. window.addEventListener("keydown", function (event) {
  13471. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  13472. window.print();
  13473. event.preventDefault();
  13474. event.stopImmediatePropagation();
  13475. }
  13476. }, true);
  13477. if ("onbeforeprint" in window) {
  13478. const stopPropagationIfNeeded = function (event) {
  13479. if (event.detail !== "custom") {
  13480. event.stopImmediatePropagation();
  13481. }
  13482. };
  13483. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  13484. window.addEventListener("afterprint", stopPropagationIfNeeded);
  13485. }
  13486. let overlayPromise;
  13487. function ensureOverlay() {
  13488. if (!overlayPromise) {
  13489. overlayManager = _app.PDFViewerApplication.overlayManager;
  13490. if (!overlayManager) {
  13491. throw new Error("The overlay manager has not yet been initialized.");
  13492. }
  13493. dialog ||= document.getElementById("printServiceDialog");
  13494. overlayPromise = overlayManager.register(dialog, true);
  13495. document.getElementById("printCancel").onclick = abort;
  13496. dialog.addEventListener("close", abort);
  13497. }
  13498. return overlayPromise;
  13499. }
  13500. _app.PDFPrintServiceFactory.instance = {
  13501. supportsPrinting: true,
  13502. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  13503. if (activeService) {
  13504. throw new Error("The print service is created and active.");
  13505. }
  13506. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  13507. return activeService;
  13508. }
  13509. };
  13510. /***/
  13511. }),
  13512. /* 48 */
  13513. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13514. Object.defineProperty(exports, "__esModule", ({
  13515. value: true
  13516. }));
  13517. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  13518. var _pdfjsLib = __webpack_require__(5);
  13519. var _pdf_link_service = __webpack_require__(3);
  13520. var _xfa_layer_builder = __webpack_require__(37);
  13521. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  13522. const xfaHtml = pdfDocument.allXfaHtml;
  13523. const linkService = new _pdf_link_service.SimpleLinkService();
  13524. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  13525. for (const xfaPage of xfaHtml.children) {
  13526. const page = document.createElement("div");
  13527. page.className = "xfaPrintedPage";
  13528. printContainer.append(page);
  13529. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  13530. pageDiv: page,
  13531. pdfPage: null,
  13532. annotationStorage: pdfDocument.annotationStorage,
  13533. linkService,
  13534. xfaHtml: xfaPage
  13535. });
  13536. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  13537. scale
  13538. });
  13539. builder.render(viewport, "print");
  13540. }
  13541. }
  13542. /***/
  13543. })
  13544. /******/]);
  13545. /************************************************************************/
  13546. /******/ // The module cache
  13547. /******/ var __webpack_module_cache__ = {};
  13548. /******/
  13549. /******/ // The require function
  13550. /******/ function __webpack_require__(moduleId) {
  13551. /******/ // Check if module is in cache
  13552. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  13553. /******/ if (cachedModule !== undefined) {
  13554. /******/ return cachedModule.exports;
  13555. /******/
  13556. }
  13557. /******/ // Create a new module (and put it into the cache)
  13558. /******/ var module = __webpack_module_cache__[moduleId] = {
  13559. /******/ // no module.id needed
  13560. /******/ // no module.loaded needed
  13561. /******/ exports: {}
  13562. /******/
  13563. };
  13564. /******/
  13565. /******/ // Execute the module function
  13566. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  13567. /******/
  13568. /******/ // Return the exports of the module
  13569. /******/ return module.exports;
  13570. /******/
  13571. }
  13572. /******/
  13573. /************************************************************************/
  13574. var __webpack_exports__ = {};
  13575. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  13576. (() => {
  13577. var exports = __webpack_exports__;
  13578. Object.defineProperty(exports, "__esModule", ({
  13579. value: true
  13580. }));
  13581. Object.defineProperty(exports, "PDFViewerApplication", ({
  13582. enumerable: true,
  13583. get: function () {
  13584. return _app.PDFViewerApplication;
  13585. }
  13586. }));
  13587. exports.PDFViewerApplicationConstants = void 0;
  13588. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  13589. enumerable: true,
  13590. get: function () {
  13591. return _app_options.AppOptions;
  13592. }
  13593. }));
  13594. var _ui_utils = __webpack_require__(1);
  13595. var _app_options = __webpack_require__(2);
  13596. var _pdf_link_service = __webpack_require__(3);
  13597. var _app = __webpack_require__(4);
  13598. const pdfjsVersion = '3.3.122';
  13599. const pdfjsBuild = '562045607';
  13600. const AppConstants = {
  13601. LinkTarget: _pdf_link_service.LinkTarget,
  13602. RenderingStates: _ui_utils.RenderingStates,
  13603. ScrollMode: _ui_utils.ScrollMode,
  13604. SpreadMode: _ui_utils.SpreadMode
  13605. };
  13606. exports.PDFViewerApplicationConstants = AppConstants;
  13607. window.PDFViewerApplication = _app.PDFViewerApplication;
  13608. window.PDFViewerApplicationConstants = AppConstants;
  13609. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  13610. ;
  13611. ;
  13612. {
  13613. __webpack_require__(41);
  13614. }
  13615. ;
  13616. {
  13617. __webpack_require__(47);
  13618. }
  13619. function getViewerConfiguration() {
  13620. return {
  13621. appContainer: document.body,
  13622. mainContainer: document.getElementById("viewerContainer"),
  13623. viewerContainer: document.getElementById("viewer"),
  13624. toolbar: {
  13625. container: document.getElementById("toolbarViewer"),
  13626. numPages: document.getElementById("numPages"),
  13627. pageNumber: document.getElementById("pageNumber"),
  13628. scaleSelect: document.getElementById("scaleSelect"),
  13629. customScaleOption: document.getElementById("customScaleOption"),
  13630. previous: document.getElementById("previous"),
  13631. next: document.getElementById("next"),
  13632. zoomIn: document.getElementById("zoomIn"),
  13633. zoomOut: document.getElementById("zoomOut"),
  13634. viewFind: document.getElementById("viewFind"),
  13635. openFile: document.getElementById("openFile"),
  13636. print: document.getElementById("print"),
  13637. editorFreeTextButton: document.getElementById("editorFreeText"),
  13638. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  13639. editorInkButton: document.getElementById("editorInk"),
  13640. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  13641. download: document.getElementById("download")
  13642. },
  13643. secondaryToolbar: {
  13644. toolbar: document.getElementById("secondaryToolbar"),
  13645. toggleButton: document.getElementById("secondaryToolbarToggle"),
  13646. presentationModeButton: document.getElementById("presentationMode"),
  13647. openFileButton: document.getElementById("secondaryOpenFile"),
  13648. printButton: document.getElementById("secondaryPrint"),
  13649. downloadButton: document.getElementById("secondaryDownload"),
  13650. viewBookmarkButton: document.getElementById("viewBookmark"),
  13651. firstPageButton: document.getElementById("firstPage"),
  13652. lastPageButton: document.getElementById("lastPage"),
  13653. pageRotateCwButton: document.getElementById("pageRotateCw"),
  13654. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  13655. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  13656. cursorHandToolButton: document.getElementById("cursorHandTool"),
  13657. scrollPageButton: document.getElementById("scrollPage"),
  13658. scrollVerticalButton: document.getElementById("scrollVertical"),
  13659. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  13660. scrollWrappedButton: document.getElementById("scrollWrapped"),
  13661. spreadNoneButton: document.getElementById("spreadNone"),
  13662. spreadOddButton: document.getElementById("spreadOdd"),
  13663. spreadEvenButton: document.getElementById("spreadEven"),
  13664. documentPropertiesButton: document.getElementById("documentProperties")
  13665. },
  13666. sidebar: {
  13667. outerContainer: document.getElementById("outerContainer"),
  13668. sidebarContainer: document.getElementById("sidebarContainer"),
  13669. toggleButton: document.getElementById("sidebarToggle"),
  13670. thumbnailButton: document.getElementById("viewThumbnail"),
  13671. outlineButton: document.getElementById("viewOutline"),
  13672. attachmentsButton: document.getElementById("viewAttachments"),
  13673. layersButton: document.getElementById("viewLayers"),
  13674. thumbnailView: document.getElementById("thumbnailView"),
  13675. outlineView: document.getElementById("outlineView"),
  13676. attachmentsView: document.getElementById("attachmentsView"),
  13677. layersView: document.getElementById("layersView"),
  13678. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  13679. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  13680. },
  13681. sidebarResizer: {
  13682. outerContainer: document.getElementById("outerContainer"),
  13683. resizer: document.getElementById("sidebarResizer")
  13684. },
  13685. findBar: {
  13686. bar: document.getElementById("findbar"),
  13687. toggleButton: document.getElementById("viewFind"),
  13688. findField: document.getElementById("findInput"),
  13689. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  13690. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  13691. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  13692. entireWordCheckbox: document.getElementById("findEntireWord"),
  13693. findMsg: document.getElementById("findMsg"),
  13694. findResultsCount: document.getElementById("findResultsCount"),
  13695. findPreviousButton: document.getElementById("findPrevious"),
  13696. findNextButton: document.getElementById("findNext")
  13697. },
  13698. passwordOverlay: {
  13699. dialog: document.getElementById("passwordDialog"),
  13700. label: document.getElementById("passwordText"),
  13701. input: document.getElementById("password"),
  13702. submitButton: document.getElementById("passwordSubmit"),
  13703. cancelButton: document.getElementById("passwordCancel")
  13704. },
  13705. documentProperties: {
  13706. dialog: document.getElementById("documentPropertiesDialog"),
  13707. closeButton: document.getElementById("documentPropertiesClose"),
  13708. fields: {
  13709. fileName: document.getElementById("fileNameField"),
  13710. fileSize: document.getElementById("fileSizeField"),
  13711. title: document.getElementById("titleField"),
  13712. author: document.getElementById("authorField"),
  13713. subject: document.getElementById("subjectField"),
  13714. keywords: document.getElementById("keywordsField"),
  13715. creationDate: document.getElementById("creationDateField"),
  13716. modificationDate: document.getElementById("modificationDateField"),
  13717. creator: document.getElementById("creatorField"),
  13718. producer: document.getElementById("producerField"),
  13719. version: document.getElementById("versionField"),
  13720. pageCount: document.getElementById("pageCountField"),
  13721. pageSize: document.getElementById("pageSizeField"),
  13722. linearized: document.getElementById("linearizedField")
  13723. }
  13724. },
  13725. annotationEditorParams: {
  13726. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  13727. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  13728. editorInkColor: document.getElementById("editorInkColor"),
  13729. editorInkThickness: document.getElementById("editorInkThickness"),
  13730. editorInkOpacity: document.getElementById("editorInkOpacity")
  13731. },
  13732. printContainer: document.getElementById("printContainer"),
  13733. openFileInput: document.getElementById("fileInput"),
  13734. debuggerScriptPath: "./debugger.js"
  13735. };
  13736. }
  13737. function webViewerLoad() {
  13738. const config = getViewerConfiguration();
  13739. const event = document.createEvent("CustomEvent");
  13740. event.initCustomEvent("webviewerloaded", true, true, {
  13741. source: window
  13742. });
  13743. try {
  13744. parent.document.dispatchEvent(event);
  13745. } catch (ex) {
  13746. console.error(`webviewerloaded: ${ex}`);
  13747. document.dispatchEvent(event);
  13748. }
  13749. _app.PDFViewerApplication.run(config);
  13750. }
  13751. document.blockUnblockOnload?.(true);
  13752. if (document.readyState === "interactive" || document.readyState === "complete") {
  13753. webViewerLoad();
  13754. } else {
  13755. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  13756. }
  13757. })();
  13758. /******/
  13759. })()
  13760. ;
  13761. //# sourceMappingURL=viewer.js.map