viewer.js 418 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807
  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, __webpack_require__) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.GenericCom = void 0;
  32. var _app = __webpack_require__(2);
  33. var _preferences = __webpack_require__(41);
  34. var _download_manager = __webpack_require__(42);
  35. var _genericl10n = __webpack_require__(43);
  36. var _generic_scripting = __webpack_require__(45);
  37. ;
  38. const GenericCom = {};
  39. exports.GenericCom = GenericCom;
  40. class GenericPreferences extends _preferences.BasePreferences {
  41. async _writeToStorage(prefObj) {
  42. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  43. }
  44. async _readFromStorage(prefObj) {
  45. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  46. }
  47. }
  48. class GenericExternalServices extends _app.DefaultExternalServices {
  49. static createDownloadManager() {
  50. return new _download_manager.DownloadManager();
  51. }
  52. static createPreferences() {
  53. return new GenericPreferences();
  54. }
  55. static createL10n({
  56. locale = "en-US"
  57. }) {
  58. return new _genericl10n.GenericL10n(locale);
  59. }
  60. static createScripting({
  61. sandboxBundleSrc
  62. }) {
  63. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  64. }
  65. }
  66. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  67. /***/ }),
  68. /* 2 */
  69. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  70. Object.defineProperty(exports, "__esModule", ({
  71. value: true
  72. }));
  73. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  74. var _ui_utils = __webpack_require__(3);
  75. var _pdfjsLib = __webpack_require__(4);
  76. var _app_options = __webpack_require__(5);
  77. var _event_utils = __webpack_require__(6);
  78. var _pdf_link_service = __webpack_require__(7);
  79. var _webAnnotation_editor_params = __webpack_require__(8);
  80. var _overlay_manager = __webpack_require__(9);
  81. var _password_prompt = __webpack_require__(10);
  82. var _webPdf_attachment_viewer = __webpack_require__(11);
  83. var _webPdf_cursor_tools = __webpack_require__(13);
  84. var _webPdf_document_properties = __webpack_require__(15);
  85. var _webPdf_find_bar = __webpack_require__(16);
  86. var _pdf_find_controller = __webpack_require__(17);
  87. var _pdf_history = __webpack_require__(19);
  88. var _webPdf_layer_viewer = __webpack_require__(20);
  89. var _webPdf_outline_viewer = __webpack_require__(21);
  90. var _webPdf_presentation_mode = __webpack_require__(22);
  91. var _pdf_rendering_queue = __webpack_require__(23);
  92. var _pdf_scripting_manager = __webpack_require__(24);
  93. var _webPdf_sidebar = __webpack_require__(25);
  94. var _webPdf_thumbnail_viewer = __webpack_require__(26);
  95. var _pdf_viewer = __webpack_require__(28);
  96. var _webSecondary_toolbar = __webpack_require__(38);
  97. var _webToolbar = __webpack_require__(39);
  98. var _view_history = __webpack_require__(40);
  99. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  100. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  101. const ViewOnLoad = {
  102. UNKNOWN: -1,
  103. PREVIOUS: 0,
  104. INITIAL: 1
  105. };
  106. const ViewerCssTheme = {
  107. AUTOMATIC: 0,
  108. LIGHT: 1,
  109. DARK: 2
  110. };
  111. class DefaultExternalServices {
  112. constructor() {
  113. throw new Error("Cannot initialize DefaultExternalServices.");
  114. }
  115. static updateFindControlState(data) {}
  116. static updateFindMatchesCount(data) {}
  117. static initPassiveLoading(callbacks) {}
  118. static reportTelemetry(data) {}
  119. static createDownloadManager() {
  120. throw new Error("Not implemented: createDownloadManager");
  121. }
  122. static createPreferences() {
  123. throw new Error("Not implemented: createPreferences");
  124. }
  125. static createL10n(options) {
  126. throw new Error("Not implemented: createL10n");
  127. }
  128. static createScripting(options) {
  129. throw new Error("Not implemented: createScripting");
  130. }
  131. static get supportsPinchToZoom() {
  132. return (0, _pdfjsLib.shadow)(this, "supportsPinchToZoom", true);
  133. }
  134. static get supportsIntegratedFind() {
  135. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  136. }
  137. static get supportsDocumentFonts() {
  138. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  139. }
  140. static get supportedMouseWheelZoomModifierKeys() {
  141. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  142. ctrlKey: true,
  143. metaKey: true
  144. });
  145. }
  146. static get isInAutomation() {
  147. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  148. }
  149. static updateEditorStates(data) {
  150. throw new Error("Not implemented: updateEditorStates");
  151. }
  152. static get canvasMaxAreaInBytes() {
  153. return (0, _pdfjsLib.shadow)(this, "canvasMaxAreaInBytes", -1);
  154. }
  155. static getNimbusExperimentData() {
  156. return (0, _pdfjsLib.shadow)(this, "getNimbusExperimentData", Promise.resolve(null));
  157. }
  158. }
  159. exports.DefaultExternalServices = DefaultExternalServices;
  160. const PDFViewerApplication = {
  161. initialBookmark: document.location.hash.substring(1),
  162. _initializedCapability: new _pdfjsLib.PromiseCapability(),
  163. appConfig: null,
  164. pdfDocument: null,
  165. pdfLoadingTask: null,
  166. printService: null,
  167. pdfViewer: null,
  168. pdfThumbnailViewer: null,
  169. pdfRenderingQueue: null,
  170. pdfPresentationMode: null,
  171. pdfDocumentProperties: null,
  172. pdfLinkService: null,
  173. pdfHistory: null,
  174. pdfSidebar: null,
  175. pdfOutlineViewer: null,
  176. pdfAttachmentViewer: null,
  177. pdfLayerViewer: null,
  178. pdfCursorTools: null,
  179. pdfScriptingManager: null,
  180. store: null,
  181. downloadManager: null,
  182. overlayManager: null,
  183. preferences: null,
  184. toolbar: null,
  185. secondaryToolbar: null,
  186. eventBus: null,
  187. l10n: null,
  188. annotationEditorParams: null,
  189. isInitialViewSet: false,
  190. downloadComplete: false,
  191. isViewerEmbedded: window.parent !== window,
  192. url: "",
  193. baseUrl: "",
  194. _downloadUrl: "",
  195. externalServices: DefaultExternalServices,
  196. _boundEvents: Object.create(null),
  197. documentInfo: null,
  198. metadata: null,
  199. _contentDispositionFilename: null,
  200. _contentLength: null,
  201. _saveInProgress: false,
  202. _wheelUnusedTicks: 0,
  203. _wheelUnusedFactor: 1,
  204. _touchUnusedTicks: 0,
  205. _touchUnusedFactor: 1,
  206. _PDFBug: null,
  207. _hasAnnotationEditors: false,
  208. _title: document.title,
  209. _printAnnotationStoragePromise: null,
  210. _touchInfo: null,
  211. _isCtrlKeyDown: false,
  212. _nimbusDataPromise: null,
  213. async initialize(appConfig) {
  214. this.preferences = this.externalServices.createPreferences();
  215. this.appConfig = appConfig;
  216. await this._initializeOptions();
  217. this._forceCssTheme();
  218. await this._initializeL10n();
  219. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  220. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  221. }
  222. await this._initializeViewerComponents();
  223. this.bindEvents();
  224. this.bindWindowEvents();
  225. const appContainer = appConfig.appContainer || document.documentElement;
  226. this.l10n.translate(appContainer).then(() => {
  227. this.eventBus.dispatch("localized", {
  228. source: this
  229. });
  230. });
  231. this._initializedCapability.resolve();
  232. },
  233. async _initializeOptions() {
  234. if (_app_options.AppOptions.get("disablePreferences")) {
  235. if (_app_options.AppOptions.get("pdfBugEnabled")) {
  236. await this._parseHashParams();
  237. }
  238. return;
  239. }
  240. if (_app_options.AppOptions._hasUserOptions()) {
  241. console.warn("_initializeOptions: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  242. }
  243. try {
  244. _app_options.AppOptions.setAll(await this.preferences.getAll());
  245. } catch (reason) {
  246. console.error(`_initializeOptions: "${reason.message}".`);
  247. }
  248. if (_app_options.AppOptions.get("pdfBugEnabled")) {
  249. await this._parseHashParams();
  250. }
  251. },
  252. async _parseHashParams() {
  253. const hash = document.location.hash.substring(1);
  254. if (!hash) {
  255. return;
  256. }
  257. const {
  258. mainContainer,
  259. viewerContainer
  260. } = this.appConfig,
  261. params = (0, _ui_utils.parseQueryString)(hash);
  262. if (params.get("disableworker") === "true") {
  263. try {
  264. await loadFakeWorker();
  265. } catch (ex) {
  266. console.error(`_parseHashParams: "${ex.message}".`);
  267. }
  268. }
  269. if (params.has("disablerange")) {
  270. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  271. }
  272. if (params.has("disablestream")) {
  273. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  274. }
  275. if (params.has("disableautofetch")) {
  276. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  277. }
  278. if (params.has("disablefontface")) {
  279. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  280. }
  281. if (params.has("disablehistory")) {
  282. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  283. }
  284. if (params.has("verbosity")) {
  285. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  286. }
  287. if (params.has("textlayer")) {
  288. switch (params.get("textlayer")) {
  289. case "off":
  290. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  291. break;
  292. case "visible":
  293. case "shadow":
  294. case "hover":
  295. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  296. try {
  297. await loadPDFBug(this);
  298. this._PDFBug.loadCSS();
  299. } catch (ex) {
  300. console.error(`_parseHashParams: "${ex.message}".`);
  301. }
  302. break;
  303. }
  304. }
  305. if (params.has("pdfbug")) {
  306. _app_options.AppOptions.set("pdfBug", true);
  307. _app_options.AppOptions.set("fontExtraProperties", true);
  308. const enabled = params.get("pdfbug").split(",");
  309. try {
  310. await loadPDFBug(this);
  311. this._PDFBug.init(mainContainer, enabled);
  312. } catch (ex) {
  313. console.error(`_parseHashParams: "${ex.message}".`);
  314. }
  315. }
  316. if (params.has("locale")) {
  317. _app_options.AppOptions.set("locale", params.get("locale"));
  318. }
  319. },
  320. async _initializeL10n() {
  321. this.l10n = this.externalServices.createL10n({
  322. locale: _app_options.AppOptions.get("locale")
  323. });
  324. const dir = await this.l10n.getDirection();
  325. document.getElementsByTagName("html")[0].dir = dir;
  326. },
  327. _forceCssTheme() {
  328. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  329. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  330. return;
  331. }
  332. try {
  333. const styleSheet = document.styleSheets[0];
  334. const cssRules = styleSheet?.cssRules || [];
  335. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  336. const rule = cssRules[i];
  337. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  338. if (cssTheme === ViewerCssTheme.LIGHT) {
  339. styleSheet.deleteRule(i);
  340. return;
  341. }
  342. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  343. if (darkRules?.[1]) {
  344. styleSheet.deleteRule(i);
  345. styleSheet.insertRule(darkRules[1], i);
  346. }
  347. return;
  348. }
  349. }
  350. } catch (reason) {
  351. console.error(`_forceCssTheme: "${reason?.message}".`);
  352. }
  353. },
  354. async _initializeViewerComponents() {
  355. const {
  356. appConfig,
  357. externalServices,
  358. l10n
  359. } = this;
  360. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  361. this.eventBus = eventBus;
  362. this.overlayManager = new _overlay_manager.OverlayManager();
  363. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  364. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  365. this.pdfRenderingQueue = pdfRenderingQueue;
  366. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  367. eventBus,
  368. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  369. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  370. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  371. });
  372. this.pdfLinkService = pdfLinkService;
  373. const downloadManager = externalServices.createDownloadManager();
  374. this.downloadManager = downloadManager;
  375. const findController = new _pdf_find_controller.PDFFindController({
  376. linkService: pdfLinkService,
  377. eventBus,
  378. updateMatchesCountOnProgress: true
  379. });
  380. this.findController = findController;
  381. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  382. eventBus,
  383. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  384. externalServices,
  385. docProperties: this._scriptingDocProperties.bind(this)
  386. });
  387. this.pdfScriptingManager = pdfScriptingManager;
  388. const container = appConfig.mainContainer,
  389. viewer = appConfig.viewerContainer;
  390. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  391. const isOffscreenCanvasSupported = _app_options.AppOptions.get("isOffscreenCanvasSupported") && _pdfjsLib.FeatureTest.isOffscreenCanvasSupported;
  392. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  393. background: _app_options.AppOptions.get("pageColorsBackground"),
  394. foreground: _app_options.AppOptions.get("pageColorsForeground")
  395. } : null;
  396. const pdfViewer = new _pdf_viewer.PDFViewer({
  397. container,
  398. viewer,
  399. eventBus,
  400. renderingQueue: pdfRenderingQueue,
  401. linkService: pdfLinkService,
  402. downloadManager,
  403. findController,
  404. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  405. l10n,
  406. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  407. annotationMode: _app_options.AppOptions.get("annotationMode"),
  408. annotationEditorMode,
  409. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  410. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  411. isOffscreenCanvasSupported,
  412. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  413. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  414. pageColors
  415. });
  416. this.pdfViewer = pdfViewer;
  417. pdfRenderingQueue.setViewer(pdfViewer);
  418. pdfLinkService.setViewer(pdfViewer);
  419. pdfScriptingManager.setViewer(pdfViewer);
  420. if (appConfig.sidebar?.thumbnailView) {
  421. this.pdfThumbnailViewer = new _webPdf_thumbnail_viewer.PDFThumbnailViewer({
  422. container: appConfig.sidebar.thumbnailView,
  423. eventBus,
  424. renderingQueue: pdfRenderingQueue,
  425. linkService: pdfLinkService,
  426. l10n,
  427. pageColors
  428. });
  429. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  430. }
  431. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  432. this.pdfHistory = new _pdf_history.PDFHistory({
  433. linkService: pdfLinkService,
  434. eventBus
  435. });
  436. pdfLinkService.setHistory(this.pdfHistory);
  437. }
  438. if (!this.supportsIntegratedFind && appConfig.findBar) {
  439. this.findBar = new _webPdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, l10n);
  440. }
  441. if (appConfig.annotationEditorParams) {
  442. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  443. if (_app_options.AppOptions.get("enableStampEditor") && isOffscreenCanvasSupported) {
  444. appConfig.toolbar?.editorStampButton?.classList.remove("hidden");
  445. }
  446. this.annotationEditorParams = new _webAnnotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  447. } else {
  448. for (const id of ["editorModeButtons", "editorModeSeparator"]) {
  449. document.getElementById(id)?.classList.add("hidden");
  450. }
  451. }
  452. }
  453. if (appConfig.documentProperties) {
  454. this.pdfDocumentProperties = new _webPdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, l10n, () => this._docFilename);
  455. }
  456. if (appConfig.secondaryToolbar?.cursorHandToolButton) {
  457. this.pdfCursorTools = new _webPdf_cursor_tools.PDFCursorTools({
  458. container,
  459. eventBus,
  460. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  461. });
  462. }
  463. if (appConfig.toolbar) {
  464. this.toolbar = new _webToolbar.Toolbar(appConfig.toolbar, eventBus, l10n);
  465. }
  466. if (appConfig.secondaryToolbar) {
  467. this.secondaryToolbar = new _webSecondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, externalServices);
  468. }
  469. if (this.supportsFullscreen && appConfig.secondaryToolbar?.presentationModeButton) {
  470. this.pdfPresentationMode = new _webPdf_presentation_mode.PDFPresentationMode({
  471. container,
  472. pdfViewer,
  473. eventBus
  474. });
  475. }
  476. if (appConfig.passwordOverlay) {
  477. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, l10n, this.isViewerEmbedded);
  478. }
  479. if (appConfig.sidebar?.outlineView) {
  480. this.pdfOutlineViewer = new _webPdf_outline_viewer.PDFOutlineViewer({
  481. container: appConfig.sidebar.outlineView,
  482. eventBus,
  483. linkService: pdfLinkService,
  484. downloadManager
  485. });
  486. }
  487. if (appConfig.sidebar?.attachmentsView) {
  488. this.pdfAttachmentViewer = new _webPdf_attachment_viewer.PDFAttachmentViewer({
  489. container: appConfig.sidebar.attachmentsView,
  490. eventBus,
  491. downloadManager
  492. });
  493. }
  494. if (appConfig.sidebar?.layersView) {
  495. this.pdfLayerViewer = new _webPdf_layer_viewer.PDFLayerViewer({
  496. container: appConfig.sidebar.layersView,
  497. eventBus,
  498. l10n
  499. });
  500. }
  501. if (appConfig.sidebar) {
  502. this.pdfSidebar = new _webPdf_sidebar.PDFSidebar({
  503. elements: appConfig.sidebar,
  504. eventBus,
  505. l10n
  506. });
  507. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  508. this.pdfSidebar.onUpdateThumbnails = () => {
  509. for (const pageView of pdfViewer.getCachedPageViews()) {
  510. if (pageView.renderingState === _ui_utils.RenderingStates.FINISHED) {
  511. this.pdfThumbnailViewer.getThumbnail(pageView.id - 1)?.setImage(pageView);
  512. }
  513. }
  514. this.pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  515. };
  516. }
  517. },
  518. async run(config) {
  519. await this.initialize(config);
  520. const {
  521. appConfig,
  522. eventBus
  523. } = this;
  524. let file;
  525. const queryString = document.location.search.substring(1);
  526. const params = (0, _ui_utils.parseQueryString)(queryString);
  527. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  528. validateFileURL(file);
  529. const fileInput = appConfig.openFileInput;
  530. fileInput.value = null;
  531. fileInput.addEventListener("change", function (evt) {
  532. const {
  533. files
  534. } = evt.target;
  535. if (!files || files.length === 0) {
  536. return;
  537. }
  538. eventBus.dispatch("fileinputchange", {
  539. source: this,
  540. fileInput: evt.target
  541. });
  542. });
  543. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  544. evt.preventDefault();
  545. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  546. });
  547. appConfig.mainContainer.addEventListener("drop", function (evt) {
  548. evt.preventDefault();
  549. const {
  550. files
  551. } = evt.dataTransfer;
  552. if (!files || files.length === 0) {
  553. return;
  554. }
  555. eventBus.dispatch("fileinputchange", {
  556. source: this,
  557. fileInput: evt.dataTransfer
  558. });
  559. });
  560. if (!this.supportsDocumentFonts) {
  561. _app_options.AppOptions.set("disableFontFace", true);
  562. this.l10n.get("web_fonts_disabled").then(msg => {
  563. console.warn(msg);
  564. });
  565. }
  566. if (!this.supportsPrinting) {
  567. appConfig.toolbar?.print?.classList.add("hidden");
  568. appConfig.secondaryToolbar?.printButton.classList.add("hidden");
  569. }
  570. if (!this.supportsFullscreen) {
  571. appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
  572. }
  573. if (this.supportsIntegratedFind) {
  574. appConfig.toolbar?.viewFind?.classList.add("hidden");
  575. }
  576. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  577. if (evt.target === this) {
  578. eventBus.dispatch("resize", {
  579. source: this
  580. });
  581. }
  582. }, true);
  583. if (file) {
  584. this.open({
  585. url: file
  586. });
  587. } else {
  588. this._hideViewBookmark();
  589. }
  590. },
  591. get initialized() {
  592. return this._initializedCapability.settled;
  593. },
  594. get initializedPromise() {
  595. return this._initializedCapability.promise;
  596. },
  597. zoomIn(steps, scaleFactor) {
  598. if (this.pdfViewer.isInPresentationMode) {
  599. return;
  600. }
  601. this.pdfViewer.increaseScale({
  602. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  603. steps,
  604. scaleFactor
  605. });
  606. },
  607. zoomOut(steps, scaleFactor) {
  608. if (this.pdfViewer.isInPresentationMode) {
  609. return;
  610. }
  611. this.pdfViewer.decreaseScale({
  612. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  613. steps,
  614. scaleFactor
  615. });
  616. },
  617. zoomReset() {
  618. if (this.pdfViewer.isInPresentationMode) {
  619. return;
  620. }
  621. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  622. },
  623. get pagesCount() {
  624. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  625. },
  626. get page() {
  627. return this.pdfViewer.currentPageNumber;
  628. },
  629. set page(val) {
  630. this.pdfViewer.currentPageNumber = val;
  631. },
  632. get supportsPrinting() {
  633. return PDFPrintServiceFactory.instance.supportsPrinting;
  634. },
  635. get supportsFullscreen() {
  636. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  637. },
  638. get supportsPinchToZoom() {
  639. return this.externalServices.supportsPinchToZoom;
  640. },
  641. get supportsIntegratedFind() {
  642. return this.externalServices.supportsIntegratedFind;
  643. },
  644. get supportsDocumentFonts() {
  645. return this.externalServices.supportsDocumentFonts;
  646. },
  647. get loadingBar() {
  648. const barElement = document.getElementById("loadingBar");
  649. const bar = barElement ? new _ui_utils.ProgressBar(barElement) : null;
  650. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  651. },
  652. get supportedMouseWheelZoomModifierKeys() {
  653. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  654. },
  655. initPassiveLoading(file) {
  656. throw new Error("Not implemented: initPassiveLoading");
  657. },
  658. setTitleUsingUrl(url = "", downloadUrl = null) {
  659. this.url = url;
  660. this.baseUrl = url.split("#")[0];
  661. if (downloadUrl) {
  662. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  663. }
  664. if ((0, _pdfjsLib.isDataScheme)(url)) {
  665. this._hideViewBookmark();
  666. }
  667. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  668. if (!title) {
  669. try {
  670. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  671. } catch {
  672. title = url;
  673. }
  674. }
  675. this.setTitle(title);
  676. },
  677. setTitle(title = this._title) {
  678. this._title = title;
  679. if (this.isViewerEmbedded) {
  680. return;
  681. }
  682. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  683. document.title = `${editorIndicator ? "* " : ""}${title}`;
  684. },
  685. get _docFilename() {
  686. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  687. },
  688. _hideViewBookmark() {
  689. const {
  690. secondaryToolbar
  691. } = this.appConfig;
  692. secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
  693. if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) {
  694. document.getElementById("viewBookmarkSeparator")?.classList.add("hidden");
  695. }
  696. },
  697. async close() {
  698. this._unblockDocumentLoadEvent();
  699. this._hideViewBookmark();
  700. if (!this.pdfLoadingTask) {
  701. return;
  702. }
  703. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  704. try {
  705. await this.save();
  706. } catch {}
  707. }
  708. const promises = [];
  709. promises.push(this.pdfLoadingTask.destroy());
  710. this.pdfLoadingTask = null;
  711. if (this.pdfDocument) {
  712. this.pdfDocument = null;
  713. this.pdfThumbnailViewer?.setDocument(null);
  714. this.pdfViewer.setDocument(null);
  715. this.pdfLinkService.setDocument(null);
  716. this.pdfDocumentProperties?.setDocument(null);
  717. }
  718. this.pdfLinkService.externalLinkEnabled = true;
  719. this.store = null;
  720. this.isInitialViewSet = false;
  721. this.downloadComplete = false;
  722. this.url = "";
  723. this.baseUrl = "";
  724. this._downloadUrl = "";
  725. this.documentInfo = null;
  726. this.metadata = null;
  727. this._contentDispositionFilename = null;
  728. this._contentLength = null;
  729. this._saveInProgress = false;
  730. this._hasAnnotationEditors = false;
  731. promises.push(this.pdfScriptingManager.destroyPromise, this.passwordPrompt.close());
  732. this.setTitle();
  733. this.pdfSidebar?.reset();
  734. this.pdfOutlineViewer?.reset();
  735. this.pdfAttachmentViewer?.reset();
  736. this.pdfLayerViewer?.reset();
  737. this.pdfHistory?.reset();
  738. this.findBar?.reset();
  739. this.toolbar?.reset();
  740. this.secondaryToolbar?.reset();
  741. this._PDFBug?.cleanup();
  742. await Promise.all(promises);
  743. },
  744. async open(args) {
  745. let deprecatedArgs = false;
  746. if (typeof args === "string") {
  747. args = {
  748. url: args
  749. };
  750. deprecatedArgs = true;
  751. } else if (args?.byteLength) {
  752. args = {
  753. data: args
  754. };
  755. deprecatedArgs = true;
  756. }
  757. if (deprecatedArgs) {
  758. console.error("The `PDFViewerApplication.open` signature was updated, please use an object instead.");
  759. }
  760. if (this.pdfLoadingTask) {
  761. await this.close();
  762. }
  763. const workerParams = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  764. Object.assign(_pdfjsLib.GlobalWorkerOptions, workerParams);
  765. if (args.url) {
  766. this.setTitleUsingUrl(args.originalUrl || args.url, args.url);
  767. }
  768. const apiParams = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  769. const params = {
  770. canvasMaxAreaInBytes: this.externalServices.canvasMaxAreaInBytes,
  771. ...apiParams,
  772. ...args
  773. };
  774. const loadingTask = (0, _pdfjsLib.getDocument)(params);
  775. this.pdfLoadingTask = loadingTask;
  776. loadingTask.onPassword = (updateCallback, reason) => {
  777. if (this.isViewerEmbedded) {
  778. this._unblockDocumentLoadEvent();
  779. }
  780. this.pdfLinkService.externalLinkEnabled = false;
  781. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  782. this.passwordPrompt.open();
  783. };
  784. loadingTask.onProgress = ({
  785. loaded,
  786. total
  787. }) => {
  788. this.progress(loaded / total);
  789. };
  790. return loadingTask.promise.then(pdfDocument => {
  791. this.load(pdfDocument);
  792. }, reason => {
  793. if (loadingTask !== this.pdfLoadingTask) {
  794. return undefined;
  795. }
  796. let key = "loading_error";
  797. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  798. key = "invalid_file_error";
  799. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  800. key = "missing_file_error";
  801. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  802. key = "unexpected_response_error";
  803. }
  804. return this.l10n.get(key).then(msg => {
  805. this._documentError(msg, {
  806. message: reason?.message
  807. });
  808. throw reason;
  809. });
  810. });
  811. },
  812. _ensureDownloadComplete() {
  813. if (this.pdfDocument && this.downloadComplete) {
  814. return;
  815. }
  816. throw new Error("PDF document not downloaded.");
  817. },
  818. async download(options = {}) {
  819. const url = this._downloadUrl,
  820. filename = this._docFilename;
  821. try {
  822. this._ensureDownloadComplete();
  823. const data = await this.pdfDocument.getData();
  824. const blob = new Blob([data], {
  825. type: "application/pdf"
  826. });
  827. await this.downloadManager.download(blob, url, filename, options);
  828. } catch {
  829. await this.downloadManager.downloadUrl(url, filename, options);
  830. }
  831. },
  832. async save(options = {}) {
  833. if (this._saveInProgress) {
  834. return;
  835. }
  836. this._saveInProgress = true;
  837. await this.pdfScriptingManager.dispatchWillSave();
  838. const url = this._downloadUrl,
  839. filename = this._docFilename;
  840. try {
  841. this._ensureDownloadComplete();
  842. const data = await this.pdfDocument.saveDocument();
  843. const blob = new Blob([data], {
  844. type: "application/pdf"
  845. });
  846. await this.downloadManager.download(blob, url, filename, options);
  847. } catch (reason) {
  848. console.error(`Error when saving the document: ${reason.message}`);
  849. await this.download(options);
  850. } finally {
  851. await this.pdfScriptingManager.dispatchDidSave();
  852. this._saveInProgress = false;
  853. }
  854. if (this._hasAnnotationEditors) {
  855. this.externalServices.reportTelemetry({
  856. type: "editing",
  857. data: {
  858. type: "save"
  859. }
  860. });
  861. }
  862. },
  863. downloadOrSave(options = {}) {
  864. if (this.pdfDocument?.annotationStorage.size > 0) {
  865. this.save(options);
  866. } else {
  867. this.download(options);
  868. }
  869. },
  870. openInExternalApp() {
  871. this.downloadOrSave({
  872. openInExternalApp: true
  873. });
  874. },
  875. _documentError(message, moreInfo = null) {
  876. this._unblockDocumentLoadEvent();
  877. this._otherError(message, moreInfo);
  878. this.eventBus.dispatch("documenterror", {
  879. source: this,
  880. message,
  881. reason: moreInfo?.message ?? null
  882. });
  883. },
  884. _otherError(message, moreInfo = null) {
  885. const moreInfoText = [`PDF.js v${_pdfjsLib.version || "?"} (build: ${_pdfjsLib.build || "?"})`];
  886. if (moreInfo) {
  887. moreInfoText.push(`Message: ${moreInfo.message}`);
  888. if (moreInfo.stack) {
  889. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  890. } else {
  891. if (moreInfo.filename) {
  892. moreInfoText.push(`File: ${moreInfo.filename}`);
  893. }
  894. if (moreInfo.lineNumber) {
  895. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  896. }
  897. }
  898. }
  899. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  900. },
  901. progress(level) {
  902. if (!this.loadingBar || this.downloadComplete) {
  903. return;
  904. }
  905. const percent = Math.round(level * 100);
  906. if (percent <= this.loadingBar.percent) {
  907. return;
  908. }
  909. this.loadingBar.percent = percent;
  910. if (this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch")) {
  911. this.loadingBar.setDisableAutoFetch();
  912. }
  913. },
  914. load(pdfDocument) {
  915. this.pdfDocument = pdfDocument;
  916. pdfDocument.getDownloadInfo().then(({
  917. length
  918. }) => {
  919. this._contentLength = length;
  920. this.downloadComplete = true;
  921. this.loadingBar?.hide();
  922. firstPagePromise.then(() => {
  923. this.eventBus.dispatch("documentloaded", {
  924. source: this
  925. });
  926. });
  927. });
  928. const pageLayoutPromise = pdfDocument.getPageLayout().catch(() => {});
  929. const pageModePromise = pdfDocument.getPageMode().catch(() => {});
  930. const openActionPromise = pdfDocument.getOpenAction().catch(() => {});
  931. this.toolbar?.setPagesCount(pdfDocument.numPages, false);
  932. this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
  933. this.pdfLinkService.setDocument(pdfDocument);
  934. this.pdfDocumentProperties?.setDocument(pdfDocument);
  935. const pdfViewer = this.pdfViewer;
  936. pdfViewer.setDocument(pdfDocument);
  937. const {
  938. firstPagePromise,
  939. onePageRendered,
  940. pagesPromise
  941. } = pdfViewer;
  942. this.pdfThumbnailViewer?.setDocument(pdfDocument);
  943. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  944. page: null,
  945. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  946. scrollLeft: "0",
  947. scrollTop: "0",
  948. rotation: null,
  949. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  950. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  951. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  952. }).catch(() => {});
  953. firstPagePromise.then(pdfPage => {
  954. this.loadingBar?.setWidth(this.appConfig.viewerContainer);
  955. this._initializeAnnotationStorageCallbacks(pdfDocument);
  956. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  957. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  958. this._initializePdfHistory({
  959. fingerprint: pdfDocument.fingerprints[0],
  960. viewOnLoad,
  961. initialDest: openAction?.dest
  962. });
  963. const initialBookmark = this.initialBookmark;
  964. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  965. let hash = zoom ? `zoom=${zoom}` : null;
  966. let rotation = null;
  967. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  968. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  969. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  970. if (stored?.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  971. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  972. rotation = parseInt(stored.rotation, 10);
  973. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  974. sidebarView = stored.sidebarView | 0;
  975. }
  976. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  977. scrollMode = stored.scrollMode | 0;
  978. }
  979. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  980. spreadMode = stored.spreadMode | 0;
  981. }
  982. }
  983. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  984. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  985. }
  986. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  987. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  988. spreadMode = modes.spreadMode;
  989. }
  990. this.setInitialView(hash, {
  991. rotation,
  992. sidebarView,
  993. scrollMode,
  994. spreadMode
  995. });
  996. this.eventBus.dispatch("documentinit", {
  997. source: this
  998. });
  999. if (!this.isViewerEmbedded) {
  1000. pdfViewer.focus();
  1001. }
  1002. await Promise.race([pagesPromise, new Promise(resolve => {
  1003. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1004. })]);
  1005. if (!initialBookmark && !hash) {
  1006. return;
  1007. }
  1008. if (pdfViewer.hasEqualPageSizes) {
  1009. return;
  1010. }
  1011. this.initialBookmark = initialBookmark;
  1012. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1013. this.setInitialView(hash);
  1014. }).catch(() => {
  1015. this.setInitialView();
  1016. }).then(function () {
  1017. pdfViewer.update();
  1018. });
  1019. });
  1020. pagesPromise.then(() => {
  1021. this._unblockDocumentLoadEvent();
  1022. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1023. }, reason => {
  1024. this.l10n.get("loading_error").then(msg => {
  1025. this._documentError(msg, {
  1026. message: reason?.message
  1027. });
  1028. });
  1029. });
  1030. onePageRendered.then(data => {
  1031. this.externalServices.reportTelemetry({
  1032. type: "pageInfo",
  1033. timestamp: data.timestamp
  1034. });
  1035. if (this.pdfOutlineViewer) {
  1036. pdfDocument.getOutline().then(outline => {
  1037. if (pdfDocument !== this.pdfDocument) {
  1038. return;
  1039. }
  1040. this.pdfOutlineViewer.render({
  1041. outline,
  1042. pdfDocument
  1043. });
  1044. });
  1045. }
  1046. if (this.pdfAttachmentViewer) {
  1047. pdfDocument.getAttachments().then(attachments => {
  1048. if (pdfDocument !== this.pdfDocument) {
  1049. return;
  1050. }
  1051. this.pdfAttachmentViewer.render({
  1052. attachments
  1053. });
  1054. });
  1055. }
  1056. if (this.pdfLayerViewer) {
  1057. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1058. if (pdfDocument !== this.pdfDocument) {
  1059. return;
  1060. }
  1061. this.pdfLayerViewer.render({
  1062. optionalContentConfig,
  1063. pdfDocument
  1064. });
  1065. });
  1066. }
  1067. });
  1068. this._initializePageLabels(pdfDocument);
  1069. this._initializeMetadata(pdfDocument);
  1070. },
  1071. async _scriptingDocProperties(pdfDocument) {
  1072. if (!this.documentInfo) {
  1073. await new Promise(resolve => {
  1074. this.eventBus._on("metadataloaded", resolve, {
  1075. once: true
  1076. });
  1077. });
  1078. if (pdfDocument !== this.pdfDocument) {
  1079. return null;
  1080. }
  1081. }
  1082. if (!this._contentLength) {
  1083. await new Promise(resolve => {
  1084. this.eventBus._on("documentloaded", resolve, {
  1085. once: true
  1086. });
  1087. });
  1088. if (pdfDocument !== this.pdfDocument) {
  1089. return null;
  1090. }
  1091. }
  1092. return {
  1093. ...this.documentInfo,
  1094. baseURL: this.baseUrl,
  1095. filesize: this._contentLength,
  1096. filename: this._docFilename,
  1097. metadata: this.metadata?.getRaw(),
  1098. authors: this.metadata?.get("dc:creator"),
  1099. numPages: this.pagesCount,
  1100. URL: this.url
  1101. };
  1102. },
  1103. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1104. const [openAction, jsActions] = await Promise.all([openActionPromise, this.pdfViewer.enableScripting ? null : pdfDocument.getJSActions()]);
  1105. if (pdfDocument !== this.pdfDocument) {
  1106. return;
  1107. }
  1108. let triggerAutoPrint = openAction?.action === "Print";
  1109. if (jsActions) {
  1110. console.warn("Warning: JavaScript support is not enabled");
  1111. for (const name in jsActions) {
  1112. if (triggerAutoPrint) {
  1113. break;
  1114. }
  1115. switch (name) {
  1116. case "WillClose":
  1117. case "WillSave":
  1118. case "DidSave":
  1119. case "WillPrint":
  1120. case "DidPrint":
  1121. continue;
  1122. }
  1123. triggerAutoPrint = jsActions[name].some(js => _ui_utils.AutoPrintRegExp.test(js));
  1124. }
  1125. }
  1126. if (triggerAutoPrint) {
  1127. this.triggerPrinting();
  1128. }
  1129. },
  1130. async _initializeMetadata(pdfDocument) {
  1131. const {
  1132. info,
  1133. metadata,
  1134. contentDispositionFilename,
  1135. contentLength
  1136. } = await pdfDocument.getMetadata();
  1137. if (pdfDocument !== this.pdfDocument) {
  1138. return;
  1139. }
  1140. this.documentInfo = info;
  1141. this.metadata = metadata;
  1142. this._contentDispositionFilename ??= contentDispositionFilename;
  1143. this._contentLength ??= contentLength;
  1144. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`);
  1145. let pdfTitle = info.Title;
  1146. const metadataTitle = metadata?.get("dc:title");
  1147. if (metadataTitle) {
  1148. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1149. pdfTitle = metadataTitle;
  1150. }
  1151. }
  1152. if (pdfTitle) {
  1153. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  1154. } else if (this._contentDispositionFilename) {
  1155. this.setTitle(this._contentDispositionFilename);
  1156. }
  1157. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1158. if (pdfDocument.loadingParams.enableXfa) {
  1159. console.warn("Warning: XFA Foreground documents are not supported");
  1160. } else {
  1161. console.warn("Warning: XFA support is not enabled");
  1162. }
  1163. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  1164. console.warn("Warning: Interactive form support is not enabled");
  1165. }
  1166. if (info.IsSignaturesPresent) {
  1167. console.warn("Warning: Digital signatures validation is not supported");
  1168. }
  1169. this.eventBus.dispatch("metadataloaded", {
  1170. source: this
  1171. });
  1172. },
  1173. async _initializePageLabels(pdfDocument) {
  1174. const labels = await pdfDocument.getPageLabels();
  1175. if (pdfDocument !== this.pdfDocument) {
  1176. return;
  1177. }
  1178. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1179. return;
  1180. }
  1181. const numLabels = labels.length;
  1182. let standardLabels = 0,
  1183. emptyLabels = 0;
  1184. for (let i = 0; i < numLabels; i++) {
  1185. const label = labels[i];
  1186. if (label === (i + 1).toString()) {
  1187. standardLabels++;
  1188. } else if (label === "") {
  1189. emptyLabels++;
  1190. } else {
  1191. break;
  1192. }
  1193. }
  1194. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  1195. return;
  1196. }
  1197. const {
  1198. pdfViewer,
  1199. pdfThumbnailViewer,
  1200. toolbar
  1201. } = this;
  1202. pdfViewer.setPageLabels(labels);
  1203. pdfThumbnailViewer?.setPageLabels(labels);
  1204. toolbar?.setPagesCount(numLabels, true);
  1205. toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1206. },
  1207. _initializePdfHistory({
  1208. fingerprint,
  1209. viewOnLoad,
  1210. initialDest = null
  1211. }) {
  1212. if (!this.pdfHistory) {
  1213. return;
  1214. }
  1215. this.pdfHistory.initialize({
  1216. fingerprint,
  1217. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1218. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1219. });
  1220. if (this.pdfHistory.initialBookmark) {
  1221. this.initialBookmark = this.pdfHistory.initialBookmark;
  1222. this.initialRotation = this.pdfHistory.initialRotation;
  1223. }
  1224. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1225. this.initialBookmark = JSON.stringify(initialDest);
  1226. this.pdfHistory.push({
  1227. explicitDest: initialDest,
  1228. pageNumber: null
  1229. });
  1230. }
  1231. },
  1232. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1233. if (pdfDocument !== this.pdfDocument) {
  1234. return;
  1235. }
  1236. const {
  1237. annotationStorage
  1238. } = pdfDocument;
  1239. annotationStorage.onSetModified = () => {
  1240. window.addEventListener("beforeunload", beforeUnload);
  1241. this._annotationStorageModified = true;
  1242. };
  1243. annotationStorage.onResetModified = () => {
  1244. window.removeEventListener("beforeunload", beforeUnload);
  1245. delete this._annotationStorageModified;
  1246. };
  1247. annotationStorage.onAnnotationEditor = typeStr => {
  1248. this._hasAnnotationEditors = !!typeStr;
  1249. this.setTitle();
  1250. if (typeStr) {
  1251. this.externalServices.reportTelemetry({
  1252. type: "editing",
  1253. data: {
  1254. type: typeStr
  1255. }
  1256. });
  1257. }
  1258. };
  1259. },
  1260. setInitialView(storedHash, {
  1261. rotation,
  1262. sidebarView,
  1263. scrollMode,
  1264. spreadMode
  1265. } = {}) {
  1266. const setRotation = angle => {
  1267. if ((0, _ui_utils.isValidRotation)(angle)) {
  1268. this.pdfViewer.pagesRotation = angle;
  1269. }
  1270. };
  1271. const setViewerModes = (scroll, spread) => {
  1272. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1273. this.pdfViewer.scrollMode = scroll;
  1274. }
  1275. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1276. this.pdfViewer.spreadMode = spread;
  1277. }
  1278. };
  1279. this.isInitialViewSet = true;
  1280. this.pdfSidebar?.setInitialView(sidebarView);
  1281. setViewerModes(scrollMode, spreadMode);
  1282. if (this.initialBookmark) {
  1283. setRotation(this.initialRotation);
  1284. delete this.initialRotation;
  1285. this.pdfLinkService.setHash(this.initialBookmark);
  1286. this.initialBookmark = null;
  1287. } else if (storedHash) {
  1288. setRotation(rotation);
  1289. this.pdfLinkService.setHash(storedHash);
  1290. }
  1291. this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1292. this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
  1293. if (!this.pdfViewer.currentScaleValue) {
  1294. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1295. }
  1296. },
  1297. _cleanup() {
  1298. if (!this.pdfDocument) {
  1299. return;
  1300. }
  1301. this.pdfViewer.cleanup();
  1302. this.pdfThumbnailViewer?.cleanup();
  1303. this.pdfDocument.cleanup();
  1304. },
  1305. forceRendering() {
  1306. this.pdfRenderingQueue.printing = !!this.printService;
  1307. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS;
  1308. this.pdfRenderingQueue.renderHighestPriority();
  1309. },
  1310. beforePrint() {
  1311. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => {
  1312. return this.pdfDocument?.annotationStorage.print;
  1313. });
  1314. if (this.printService) {
  1315. return;
  1316. }
  1317. if (!this.supportsPrinting) {
  1318. this.l10n.get("printing_not_supported").then(msg => {
  1319. this._otherError(msg);
  1320. });
  1321. return;
  1322. }
  1323. if (!this.pdfViewer.pageViewsReady) {
  1324. this.l10n.get("printing_not_ready").then(msg => {
  1325. window.alert(msg);
  1326. });
  1327. return;
  1328. }
  1329. const pagesOverview = this.pdfViewer.getPagesOverview();
  1330. const printContainer = this.appConfig.printContainer;
  1331. const printResolution = _app_options.AppOptions.get("printResolution");
  1332. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1333. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  1334. this.printService = printService;
  1335. this.forceRendering();
  1336. this.setTitle();
  1337. printService.layout();
  1338. if (this._hasAnnotationEditors) {
  1339. this.externalServices.reportTelemetry({
  1340. type: "editing",
  1341. data: {
  1342. type: "print"
  1343. }
  1344. });
  1345. }
  1346. },
  1347. afterPrint() {
  1348. if (this._printAnnotationStoragePromise) {
  1349. this._printAnnotationStoragePromise.then(() => {
  1350. this.pdfScriptingManager.dispatchDidPrint();
  1351. });
  1352. this._printAnnotationStoragePromise = null;
  1353. }
  1354. if (this.printService) {
  1355. this.printService.destroy();
  1356. this.printService = null;
  1357. this.pdfDocument?.annotationStorage.resetModified();
  1358. }
  1359. this.forceRendering();
  1360. this.setTitle();
  1361. },
  1362. rotatePages(delta) {
  1363. this.pdfViewer.pagesRotation += delta;
  1364. },
  1365. requestPresentationMode() {
  1366. this.pdfPresentationMode?.request();
  1367. },
  1368. triggerPrinting() {
  1369. if (!this.supportsPrinting) {
  1370. return;
  1371. }
  1372. window.print();
  1373. },
  1374. bindEvents() {
  1375. const {
  1376. eventBus,
  1377. _boundEvents
  1378. } = this;
  1379. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1380. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1381. eventBus._on("resize", webViewerResize);
  1382. eventBus._on("hashchange", webViewerHashchange);
  1383. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1384. eventBus._on("afterprint", _boundEvents.afterPrint);
  1385. eventBus._on("pagerender", webViewerPageRender);
  1386. eventBus._on("pagerendered", webViewerPageRendered);
  1387. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1388. eventBus._on("pagechanging", webViewerPageChanging);
  1389. eventBus._on("scalechanging", webViewerScaleChanging);
  1390. eventBus._on("rotationchanging", webViewerRotationChanging);
  1391. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1392. eventBus._on("pagemode", webViewerPageMode);
  1393. eventBus._on("namedaction", webViewerNamedAction);
  1394. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1395. eventBus._on("presentationmode", webViewerPresentationMode);
  1396. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  1397. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  1398. eventBus._on("print", webViewerPrint);
  1399. eventBus._on("download", webViewerDownload);
  1400. eventBus._on("openinexternalapp", webViewerOpenInExternalApp);
  1401. eventBus._on("firstpage", webViewerFirstPage);
  1402. eventBus._on("lastpage", webViewerLastPage);
  1403. eventBus._on("nextpage", webViewerNextPage);
  1404. eventBus._on("previouspage", webViewerPreviousPage);
  1405. eventBus._on("zoomin", webViewerZoomIn);
  1406. eventBus._on("zoomout", webViewerZoomOut);
  1407. eventBus._on("zoomreset", webViewerZoomReset);
  1408. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1409. eventBus._on("scalechanged", webViewerScaleChanged);
  1410. eventBus._on("rotatecw", webViewerRotateCw);
  1411. eventBus._on("rotateccw", webViewerRotateCcw);
  1412. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1413. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1414. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1415. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1416. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1417. eventBus._on("documentproperties", webViewerDocumentProperties);
  1418. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1419. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1420. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1421. if (_app_options.AppOptions.get("pdfBug")) {
  1422. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1423. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1424. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1425. }
  1426. eventBus._on("fileinputchange", webViewerFileInputChange);
  1427. eventBus._on("openfile", webViewerOpenFile);
  1428. },
  1429. bindWindowEvents() {
  1430. const {
  1431. eventBus,
  1432. _boundEvents
  1433. } = this;
  1434. function addWindowResolutionChange(evt = null) {
  1435. if (evt) {
  1436. webViewerResolutionChange(evt);
  1437. }
  1438. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  1439. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  1440. once: true
  1441. });
  1442. _boundEvents.removeWindowResolutionChange ||= function () {
  1443. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  1444. _boundEvents.removeWindowResolutionChange = null;
  1445. };
  1446. }
  1447. addWindowResolutionChange();
  1448. _boundEvents.windowResize = () => {
  1449. eventBus.dispatch("resize", {
  1450. source: window
  1451. });
  1452. };
  1453. _boundEvents.windowHashChange = () => {
  1454. eventBus.dispatch("hashchange", {
  1455. source: window,
  1456. hash: document.location.hash.substring(1)
  1457. });
  1458. };
  1459. _boundEvents.windowBeforePrint = () => {
  1460. eventBus.dispatch("beforeprint", {
  1461. source: window
  1462. });
  1463. };
  1464. _boundEvents.windowAfterPrint = () => {
  1465. eventBus.dispatch("afterprint", {
  1466. source: window
  1467. });
  1468. };
  1469. _boundEvents.windowUpdateFromSandbox = event => {
  1470. eventBus.dispatch("updatefromsandbox", {
  1471. source: window,
  1472. detail: event.detail
  1473. });
  1474. };
  1475. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1476. window.addEventListener("wheel", webViewerWheel, {
  1477. passive: false
  1478. });
  1479. window.addEventListener("touchstart", webViewerTouchStart, {
  1480. passive: false
  1481. });
  1482. window.addEventListener("touchmove", webViewerTouchMove, {
  1483. passive: false
  1484. });
  1485. window.addEventListener("touchend", webViewerTouchEnd, {
  1486. passive: false
  1487. });
  1488. window.addEventListener("click", webViewerClick);
  1489. window.addEventListener("keydown", webViewerKeyDown);
  1490. window.addEventListener("keyup", webViewerKeyUp);
  1491. window.addEventListener("resize", _boundEvents.windowResize);
  1492. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1493. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1494. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1495. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1496. },
  1497. unbindEvents() {
  1498. const {
  1499. eventBus,
  1500. _boundEvents
  1501. } = this;
  1502. eventBus._off("resize", webViewerResize);
  1503. eventBus._off("hashchange", webViewerHashchange);
  1504. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1505. eventBus._off("afterprint", _boundEvents.afterPrint);
  1506. eventBus._off("pagerender", webViewerPageRender);
  1507. eventBus._off("pagerendered", webViewerPageRendered);
  1508. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1509. eventBus._off("pagechanging", webViewerPageChanging);
  1510. eventBus._off("scalechanging", webViewerScaleChanging);
  1511. eventBus._off("rotationchanging", webViewerRotationChanging);
  1512. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1513. eventBus._off("pagemode", webViewerPageMode);
  1514. eventBus._off("namedaction", webViewerNamedAction);
  1515. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1516. eventBus._off("presentationmode", webViewerPresentationMode);
  1517. eventBus._off("print", webViewerPrint);
  1518. eventBus._off("download", webViewerDownload);
  1519. eventBus._off("openinexternalapp", webViewerOpenInExternalApp);
  1520. eventBus._off("firstpage", webViewerFirstPage);
  1521. eventBus._off("lastpage", webViewerLastPage);
  1522. eventBus._off("nextpage", webViewerNextPage);
  1523. eventBus._off("previouspage", webViewerPreviousPage);
  1524. eventBus._off("zoomin", webViewerZoomIn);
  1525. eventBus._off("zoomout", webViewerZoomOut);
  1526. eventBus._off("zoomreset", webViewerZoomReset);
  1527. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1528. eventBus._off("scalechanged", webViewerScaleChanged);
  1529. eventBus._off("rotatecw", webViewerRotateCw);
  1530. eventBus._off("rotateccw", webViewerRotateCcw);
  1531. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1532. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1533. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1534. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1535. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1536. eventBus._off("documentproperties", webViewerDocumentProperties);
  1537. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1538. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1539. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1540. if (_boundEvents.reportPageStatsPDFBug) {
  1541. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1542. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1543. _boundEvents.reportPageStatsPDFBug = null;
  1544. }
  1545. eventBus._off("fileinputchange", webViewerFileInputChange);
  1546. eventBus._off("openfile", webViewerOpenFile);
  1547. _boundEvents.beforePrint = null;
  1548. _boundEvents.afterPrint = null;
  1549. },
  1550. unbindWindowEvents() {
  1551. const {
  1552. _boundEvents
  1553. } = this;
  1554. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1555. window.removeEventListener("wheel", webViewerWheel, {
  1556. passive: false
  1557. });
  1558. window.removeEventListener("touchstart", webViewerTouchStart, {
  1559. passive: false
  1560. });
  1561. window.removeEventListener("touchmove", webViewerTouchMove, {
  1562. passive: false
  1563. });
  1564. window.removeEventListener("touchend", webViewerTouchEnd, {
  1565. passive: false
  1566. });
  1567. window.removeEventListener("click", webViewerClick);
  1568. window.removeEventListener("keydown", webViewerKeyDown);
  1569. window.removeEventListener("keyup", webViewerKeyUp);
  1570. window.removeEventListener("resize", _boundEvents.windowResize);
  1571. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1572. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1573. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1574. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1575. _boundEvents.removeWindowResolutionChange?.();
  1576. _boundEvents.windowResize = null;
  1577. _boundEvents.windowHashChange = null;
  1578. _boundEvents.windowBeforePrint = null;
  1579. _boundEvents.windowAfterPrint = null;
  1580. _boundEvents.windowUpdateFromSandbox = null;
  1581. },
  1582. _accumulateTicks(ticks, prop) {
  1583. if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) {
  1584. this[prop] = 0;
  1585. }
  1586. this[prop] += ticks;
  1587. const wholeTicks = Math.trunc(this[prop]);
  1588. this[prop] -= wholeTicks;
  1589. return wholeTicks;
  1590. },
  1591. _accumulateFactor(previousScale, factor, prop) {
  1592. if (factor === 1) {
  1593. return 1;
  1594. }
  1595. if (this[prop] > 1 && factor < 1 || this[prop] < 1 && factor > 1) {
  1596. this[prop] = 1;
  1597. }
  1598. const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale);
  1599. this[prop] = factor / newFactor;
  1600. return newFactor;
  1601. },
  1602. _centerAtPos(previousScale, x, y) {
  1603. const {
  1604. pdfViewer
  1605. } = this;
  1606. const scaleDiff = pdfViewer.currentScale / previousScale - 1;
  1607. if (scaleDiff !== 0) {
  1608. const [top, left] = pdfViewer.containerTopLeft;
  1609. pdfViewer.container.scrollLeft += (x - left) * scaleDiff;
  1610. pdfViewer.container.scrollTop += (y - top) * scaleDiff;
  1611. }
  1612. },
  1613. _unblockDocumentLoadEvent() {
  1614. document.blockUnblockOnload?.(false);
  1615. this._unblockDocumentLoadEvent = () => {};
  1616. },
  1617. get scriptingReady() {
  1618. return this.pdfScriptingManager.ready;
  1619. }
  1620. };
  1621. exports.PDFViewerApplication = PDFViewerApplication;
  1622. {
  1623. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1624. var validateFileURL = function (file) {
  1625. if (!file) {
  1626. return;
  1627. }
  1628. try {
  1629. const viewerOrigin = new URL(window.location.href).origin || "null";
  1630. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1631. return;
  1632. }
  1633. const fileOrigin = new URL(file, window.location.href).origin;
  1634. // if (fileOrigin !== viewerOrigin) {
  1635. // throw new Error("file origin does not match viewer's");
  1636. // }
  1637. } catch (ex) {
  1638. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1639. PDFViewerApplication._documentError(msg, {
  1640. message: ex?.message
  1641. });
  1642. });
  1643. throw ex;
  1644. }
  1645. };
  1646. }
  1647. async function loadFakeWorker() {
  1648. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  1649. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  1650. }
  1651. async function loadPDFBug(self) {
  1652. const {
  1653. debuggerScriptPath
  1654. } = self.appConfig;
  1655. const {
  1656. PDFBug
  1657. } = await import(debuggerScriptPath);
  1658. self._PDFBug = PDFBug;
  1659. }
  1660. function reportPageStatsPDFBug({
  1661. pageNumber
  1662. }) {
  1663. if (!globalThis.Stats?.enabled) {
  1664. return;
  1665. }
  1666. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1667. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  1668. }
  1669. function webViewerPageRender({
  1670. pageNumber
  1671. }) {
  1672. if (pageNumber === PDFViewerApplication.page) {
  1673. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
  1674. }
  1675. }
  1676. function webViewerPageRendered({
  1677. pageNumber,
  1678. error
  1679. }) {
  1680. if (pageNumber === PDFViewerApplication.page) {
  1681. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
  1682. }
  1683. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  1684. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1685. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
  1686. if (pageView) {
  1687. thumbnailView?.setImage(pageView);
  1688. }
  1689. }
  1690. if (error) {
  1691. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1692. PDFViewerApplication._otherError(msg, error);
  1693. });
  1694. }
  1695. }
  1696. function webViewerPageMode({
  1697. mode
  1698. }) {
  1699. let view;
  1700. switch (mode) {
  1701. case "thumbs":
  1702. view = _ui_utils.SidebarView.THUMBS;
  1703. break;
  1704. case "bookmarks":
  1705. case "outline":
  1706. view = _ui_utils.SidebarView.OUTLINE;
  1707. break;
  1708. case "attachments":
  1709. view = _ui_utils.SidebarView.ATTACHMENTS;
  1710. break;
  1711. case "layers":
  1712. view = _ui_utils.SidebarView.LAYERS;
  1713. break;
  1714. case "none":
  1715. view = _ui_utils.SidebarView.NONE;
  1716. break;
  1717. default:
  1718. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1719. return;
  1720. }
  1721. PDFViewerApplication.pdfSidebar?.switchView(view, true);
  1722. }
  1723. function webViewerNamedAction(evt) {
  1724. switch (evt.action) {
  1725. case "GoToPage":
  1726. PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
  1727. break;
  1728. case "Find":
  1729. if (!PDFViewerApplication.supportsIntegratedFind) {
  1730. PDFViewerApplication?.findBar.toggle();
  1731. }
  1732. break;
  1733. case "Print":
  1734. PDFViewerApplication.triggerPrinting();
  1735. break;
  1736. case "SaveAs":
  1737. PDFViewerApplication.downloadOrSave();
  1738. break;
  1739. }
  1740. }
  1741. function webViewerPresentationModeChanged(evt) {
  1742. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1743. }
  1744. function webViewerSidebarViewChanged({
  1745. view
  1746. }) {
  1747. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  1748. if (PDFViewerApplication.isInitialViewSet) {
  1749. PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
  1750. }
  1751. }
  1752. function webViewerUpdateViewarea({
  1753. location
  1754. }) {
  1755. if (PDFViewerApplication.isInitialViewSet) {
  1756. PDFViewerApplication.store?.setMultiple({
  1757. page: location.pageNumber,
  1758. zoom: location.scale,
  1759. scrollLeft: location.left,
  1760. scrollTop: location.top,
  1761. rotation: location.rotation
  1762. }).catch(() => {});
  1763. }
  1764. if (PDFViewerApplication.appConfig.secondaryToolbar) {
  1765. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1766. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1767. }
  1768. }
  1769. function webViewerScrollModeChanged(evt) {
  1770. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1771. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  1772. }
  1773. }
  1774. function webViewerSpreadModeChanged(evt) {
  1775. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1776. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  1777. }
  1778. }
  1779. function webViewerResize() {
  1780. const {
  1781. pdfDocument,
  1782. pdfViewer,
  1783. pdfRenderingQueue
  1784. } = PDFViewerApplication;
  1785. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  1786. return;
  1787. }
  1788. if (!pdfDocument) {
  1789. return;
  1790. }
  1791. const currentScaleValue = pdfViewer.currentScaleValue;
  1792. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  1793. pdfViewer.currentScaleValue = currentScaleValue;
  1794. }
  1795. pdfViewer.update();
  1796. }
  1797. function webViewerHashchange(evt) {
  1798. const hash = evt.hash;
  1799. if (!hash) {
  1800. return;
  1801. }
  1802. if (!PDFViewerApplication.isInitialViewSet) {
  1803. PDFViewerApplication.initialBookmark = hash;
  1804. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  1805. PDFViewerApplication.pdfLinkService.setHash(hash);
  1806. }
  1807. }
  1808. {
  1809. var webViewerFileInputChange = function (evt) {
  1810. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  1811. return;
  1812. }
  1813. const file = evt.fileInput.files[0];
  1814. PDFViewerApplication.open({
  1815. url: URL.createObjectURL(file),
  1816. originalUrl: file.name
  1817. });
  1818. };
  1819. var webViewerOpenFile = function (evt) {
  1820. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  1821. fileInput.click();
  1822. };
  1823. }
  1824. function webViewerPresentationMode() {
  1825. PDFViewerApplication.requestPresentationMode();
  1826. }
  1827. function webViewerSwitchAnnotationEditorMode(evt) {
  1828. PDFViewerApplication.pdfViewer.annotationEditorMode = evt;
  1829. }
  1830. function webViewerSwitchAnnotationEditorParams(evt) {
  1831. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  1832. }
  1833. function webViewerPrint() {
  1834. PDFViewerApplication.triggerPrinting();
  1835. }
  1836. function webViewerDownload() {
  1837. PDFViewerApplication.downloadOrSave();
  1838. }
  1839. function webViewerOpenInExternalApp() {
  1840. PDFViewerApplication.openInExternalApp();
  1841. }
  1842. function webViewerFirstPage() {
  1843. PDFViewerApplication.page = 1;
  1844. }
  1845. function webViewerLastPage() {
  1846. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1847. }
  1848. function webViewerNextPage() {
  1849. PDFViewerApplication.pdfViewer.nextPage();
  1850. }
  1851. function webViewerPreviousPage() {
  1852. PDFViewerApplication.pdfViewer.previousPage();
  1853. }
  1854. function webViewerZoomIn() {
  1855. PDFViewerApplication.zoomIn();
  1856. }
  1857. function webViewerZoomOut() {
  1858. PDFViewerApplication.zoomOut();
  1859. }
  1860. function webViewerZoomReset() {
  1861. PDFViewerApplication.zoomReset();
  1862. }
  1863. function webViewerPageNumberChanged(evt) {
  1864. const pdfViewer = PDFViewerApplication.pdfViewer;
  1865. if (evt.value !== "") {
  1866. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  1867. }
  1868. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1869. PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1870. }
  1871. }
  1872. function webViewerScaleChanged(evt) {
  1873. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1874. }
  1875. function webViewerRotateCw() {
  1876. PDFViewerApplication.rotatePages(90);
  1877. }
  1878. function webViewerRotateCcw() {
  1879. PDFViewerApplication.rotatePages(-90);
  1880. }
  1881. function webViewerOptionalContentConfig(evt) {
  1882. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  1883. }
  1884. function webViewerSwitchScrollMode(evt) {
  1885. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  1886. }
  1887. function webViewerSwitchSpreadMode(evt) {
  1888. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  1889. }
  1890. function webViewerDocumentProperties() {
  1891. PDFViewerApplication.pdfDocumentProperties?.open();
  1892. }
  1893. function webViewerFindFromUrlHash(evt) {
  1894. PDFViewerApplication.eventBus.dispatch("find", {
  1895. source: evt.source,
  1896. type: "",
  1897. query: evt.query,
  1898. caseSensitive: false,
  1899. entireWord: false,
  1900. highlightAll: true,
  1901. findPrevious: false,
  1902. matchDiacritics: true
  1903. });
  1904. }
  1905. function webViewerUpdateFindMatchesCount({
  1906. matchesCount
  1907. }) {
  1908. if (PDFViewerApplication.supportsIntegratedFind) {
  1909. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  1910. } else {
  1911. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  1912. }
  1913. }
  1914. function webViewerUpdateFindControlState({
  1915. state,
  1916. previous,
  1917. matchesCount,
  1918. rawQuery
  1919. }) {
  1920. if (PDFViewerApplication.supportsIntegratedFind) {
  1921. PDFViewerApplication.externalServices.updateFindControlState({
  1922. result: state,
  1923. findPrevious: previous,
  1924. matchesCount,
  1925. rawQuery
  1926. });
  1927. } else {
  1928. PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount);
  1929. }
  1930. }
  1931. function webViewerScaleChanging(evt) {
  1932. PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
  1933. PDFViewerApplication.pdfViewer.update();
  1934. }
  1935. function webViewerRotationChanging(evt) {
  1936. if (PDFViewerApplication.pdfThumbnailViewer) {
  1937. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  1938. }
  1939. PDFViewerApplication.forceRendering();
  1940. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  1941. }
  1942. function webViewerPageChanging({
  1943. pageNumber,
  1944. pageLabel
  1945. }) {
  1946. PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
  1947. PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
  1948. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  1949. PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
  1950. }
  1951. const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1952. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING);
  1953. }
  1954. function webViewerResolutionChange(evt) {
  1955. PDFViewerApplication.pdfViewer.refresh();
  1956. }
  1957. function webViewerVisibilityChange(evt) {
  1958. if (document.visibilityState === "visible") {
  1959. setZoomDisabledTimeout();
  1960. }
  1961. }
  1962. let zoomDisabledTimeout = null;
  1963. function setZoomDisabledTimeout() {
  1964. if (zoomDisabledTimeout) {
  1965. clearTimeout(zoomDisabledTimeout);
  1966. }
  1967. zoomDisabledTimeout = setTimeout(function () {
  1968. zoomDisabledTimeout = null;
  1969. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  1970. }
  1971. function webViewerWheel(evt) {
  1972. const {
  1973. pdfViewer,
  1974. supportedMouseWheelZoomModifierKeys,
  1975. supportsPinchToZoom
  1976. } = PDFViewerApplication;
  1977. if (pdfViewer.isInPresentationMode) {
  1978. return;
  1979. }
  1980. const deltaMode = evt.deltaMode;
  1981. let scaleFactor = Math.exp(-evt.deltaY / 100);
  1982. const isBuiltInMac = false;
  1983. const isPinchToZoom = evt.ctrlKey && !PDFViewerApplication._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && (Math.abs(scaleFactor - 1) < 0.05 || isBuiltInMac) && evt.deltaZ === 0;
  1984. if (isPinchToZoom || evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  1985. evt.preventDefault();
  1986. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  1987. return;
  1988. }
  1989. const previousScale = pdfViewer.currentScale;
  1990. if (isPinchToZoom && supportsPinchToZoom) {
  1991. scaleFactor = PDFViewerApplication._accumulateFactor(previousScale, scaleFactor, "_wheelUnusedFactor");
  1992. if (scaleFactor < 1) {
  1993. PDFViewerApplication.zoomOut(null, scaleFactor);
  1994. } else if (scaleFactor > 1) {
  1995. PDFViewerApplication.zoomIn(null, scaleFactor);
  1996. } else {
  1997. return;
  1998. }
  1999. } else {
  2000. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2001. let ticks = 0;
  2002. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2003. if (Math.abs(delta) >= 1) {
  2004. ticks = Math.sign(delta);
  2005. } else {
  2006. ticks = PDFViewerApplication._accumulateTicks(delta, "_wheelUnusedTicks");
  2007. }
  2008. } else {
  2009. const PIXELS_PER_LINE_SCALE = 30;
  2010. ticks = PDFViewerApplication._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks");
  2011. }
  2012. if (ticks < 0) {
  2013. PDFViewerApplication.zoomOut(-ticks);
  2014. } else if (ticks > 0) {
  2015. PDFViewerApplication.zoomIn(ticks);
  2016. } else {
  2017. return;
  2018. }
  2019. }
  2020. PDFViewerApplication._centerAtPos(previousScale, evt.clientX, evt.clientY);
  2021. } else {
  2022. setZoomDisabledTimeout();
  2023. }
  2024. }
  2025. function webViewerTouchStart(evt) {
  2026. if (PDFViewerApplication.pdfViewer.isInPresentationMode || evt.touches.length < 2) {
  2027. return;
  2028. }
  2029. evt.preventDefault();
  2030. if (evt.touches.length !== 2) {
  2031. PDFViewerApplication._touchInfo = null;
  2032. return;
  2033. }
  2034. let [touch0, touch1] = evt.touches;
  2035. if (touch0.identifier > touch1.identifier) {
  2036. [touch0, touch1] = [touch1, touch0];
  2037. }
  2038. PDFViewerApplication._touchInfo = {
  2039. touch0X: touch0.pageX,
  2040. touch0Y: touch0.pageY,
  2041. touch1X: touch1.pageX,
  2042. touch1Y: touch1.pageY
  2043. };
  2044. }
  2045. function webViewerTouchMove(evt) {
  2046. if (!PDFViewerApplication._touchInfo || evt.touches.length !== 2) {
  2047. return;
  2048. }
  2049. const {
  2050. pdfViewer,
  2051. _touchInfo,
  2052. supportsPinchToZoom
  2053. } = PDFViewerApplication;
  2054. let [touch0, touch1] = evt.touches;
  2055. if (touch0.identifier > touch1.identifier) {
  2056. [touch0, touch1] = [touch1, touch0];
  2057. }
  2058. const {
  2059. pageX: page0X,
  2060. pageY: page0Y
  2061. } = touch0;
  2062. const {
  2063. pageX: page1X,
  2064. pageY: page1Y
  2065. } = touch1;
  2066. const {
  2067. touch0X: pTouch0X,
  2068. touch0Y: pTouch0Y,
  2069. touch1X: pTouch1X,
  2070. touch1Y: pTouch1Y
  2071. } = _touchInfo;
  2072. if (Math.abs(pTouch0X - page0X) <= 1 && Math.abs(pTouch0Y - page0Y) <= 1 && Math.abs(pTouch1X - page1X) <= 1 && Math.abs(pTouch1Y - page1Y) <= 1) {
  2073. return;
  2074. }
  2075. _touchInfo.touch0X = page0X;
  2076. _touchInfo.touch0Y = page0Y;
  2077. _touchInfo.touch1X = page1X;
  2078. _touchInfo.touch1Y = page1Y;
  2079. if (pTouch0X === page0X && pTouch0Y === page0Y) {
  2080. const v1X = pTouch1X - page0X;
  2081. const v1Y = pTouch1Y - page0Y;
  2082. const v2X = page1X - page0X;
  2083. const v2Y = page1Y - page0Y;
  2084. const det = v1X * v2Y - v1Y * v2X;
  2085. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  2086. return;
  2087. }
  2088. } else if (pTouch1X === page1X && pTouch1Y === page1Y) {
  2089. const v1X = pTouch0X - page1X;
  2090. const v1Y = pTouch0Y - page1Y;
  2091. const v2X = page0X - page1X;
  2092. const v2Y = page0Y - page1Y;
  2093. const det = v1X * v2Y - v1Y * v2X;
  2094. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  2095. return;
  2096. }
  2097. } else {
  2098. const diff0X = page0X - pTouch0X;
  2099. const diff1X = page1X - pTouch1X;
  2100. const diff0Y = page0Y - pTouch0Y;
  2101. const diff1Y = page1Y - pTouch1Y;
  2102. const dotProduct = diff0X * diff1X + diff0Y * diff1Y;
  2103. if (dotProduct >= 0) {
  2104. return;
  2105. }
  2106. }
  2107. evt.preventDefault();
  2108. const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1;
  2109. const pDistance = Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1;
  2110. const previousScale = pdfViewer.currentScale;
  2111. if (supportsPinchToZoom) {
  2112. const newScaleFactor = PDFViewerApplication._accumulateFactor(previousScale, distance / pDistance, "_touchUnusedFactor");
  2113. if (newScaleFactor < 1) {
  2114. PDFViewerApplication.zoomOut(null, newScaleFactor);
  2115. } else if (newScaleFactor > 1) {
  2116. PDFViewerApplication.zoomIn(null, newScaleFactor);
  2117. } else {
  2118. return;
  2119. }
  2120. } else {
  2121. const PIXELS_PER_LINE_SCALE = 30;
  2122. const ticks = PDFViewerApplication._accumulateTicks((distance - pDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks");
  2123. if (ticks < 0) {
  2124. PDFViewerApplication.zoomOut(-ticks);
  2125. } else if (ticks > 0) {
  2126. PDFViewerApplication.zoomIn(ticks);
  2127. } else {
  2128. return;
  2129. }
  2130. }
  2131. PDFViewerApplication._centerAtPos(previousScale, (page0X + page1X) / 2, (page0Y + page1Y) / 2);
  2132. }
  2133. function webViewerTouchEnd(evt) {
  2134. if (!PDFViewerApplication._touchInfo) {
  2135. return;
  2136. }
  2137. evt.preventDefault();
  2138. PDFViewerApplication._touchInfo = null;
  2139. PDFViewerApplication._touchUnusedTicks = 0;
  2140. PDFViewerApplication._touchUnusedFactor = 1;
  2141. }
  2142. function webViewerClick(evt) {
  2143. if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
  2144. return;
  2145. }
  2146. const appConfig = PDFViewerApplication.appConfig;
  2147. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) {
  2148. PDFViewerApplication.secondaryToolbar.close();
  2149. }
  2150. }
  2151. function webViewerKeyUp(evt) {
  2152. if (evt.key === "Control") {
  2153. PDFViewerApplication._isCtrlKeyDown = false;
  2154. }
  2155. }
  2156. function webViewerKeyDown(evt) {
  2157. PDFViewerApplication._isCtrlKeyDown = evt.key === "Control";
  2158. if (PDFViewerApplication.overlayManager.active) {
  2159. return;
  2160. }
  2161. const {
  2162. eventBus,
  2163. pdfViewer
  2164. } = PDFViewerApplication;
  2165. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  2166. let handled = false,
  2167. ensureViewerFocused = false;
  2168. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2169. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2170. switch (evt.keyCode) {
  2171. case 70:
  2172. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2173. PDFViewerApplication.findBar?.open();
  2174. handled = true;
  2175. }
  2176. break;
  2177. case 71:
  2178. if (!PDFViewerApplication.supportsIntegratedFind) {
  2179. const {
  2180. state
  2181. } = PDFViewerApplication.findController;
  2182. if (state) {
  2183. const newState = {
  2184. source: window,
  2185. type: "again",
  2186. findPrevious: cmd === 5 || cmd === 12
  2187. };
  2188. eventBus.dispatch("find", {
  2189. ...state,
  2190. ...newState
  2191. });
  2192. }
  2193. handled = true;
  2194. }
  2195. break;
  2196. case 61:
  2197. case 107:
  2198. case 187:
  2199. case 171:
  2200. PDFViewerApplication.zoomIn();
  2201. handled = true;
  2202. break;
  2203. case 173:
  2204. case 109:
  2205. case 189:
  2206. PDFViewerApplication.zoomOut();
  2207. handled = true;
  2208. break;
  2209. case 48:
  2210. case 96:
  2211. if (!isViewerInPresentationMode) {
  2212. setTimeout(function () {
  2213. PDFViewerApplication.zoomReset();
  2214. });
  2215. handled = false;
  2216. }
  2217. break;
  2218. case 38:
  2219. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2220. PDFViewerApplication.page = 1;
  2221. handled = true;
  2222. ensureViewerFocused = true;
  2223. }
  2224. break;
  2225. case 40:
  2226. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2227. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2228. handled = true;
  2229. ensureViewerFocused = true;
  2230. }
  2231. break;
  2232. }
  2233. }
  2234. if (cmd === 1 || cmd === 8) {
  2235. switch (evt.keyCode) {
  2236. case 83:
  2237. eventBus.dispatch("download", {
  2238. source: window
  2239. });
  2240. handled = true;
  2241. break;
  2242. case 79:
  2243. {
  2244. eventBus.dispatch("openfile", {
  2245. source: window
  2246. });
  2247. handled = true;
  2248. }
  2249. break;
  2250. }
  2251. }
  2252. if (cmd === 3 || cmd === 10) {
  2253. switch (evt.keyCode) {
  2254. case 80:
  2255. PDFViewerApplication.requestPresentationMode();
  2256. handled = true;
  2257. PDFViewerApplication.externalServices.reportTelemetry({
  2258. type: "buttons",
  2259. data: {
  2260. id: "presentationModeKeyboard"
  2261. }
  2262. });
  2263. break;
  2264. case 71:
  2265. if (PDFViewerApplication.appConfig.toolbar) {
  2266. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2267. handled = true;
  2268. }
  2269. break;
  2270. }
  2271. }
  2272. if (handled) {
  2273. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2274. pdfViewer.focus();
  2275. }
  2276. evt.preventDefault();
  2277. return;
  2278. }
  2279. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2280. const curElementTagName = curElement?.tagName.toUpperCase();
  2281. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2282. if (evt.keyCode !== 27) {
  2283. return;
  2284. }
  2285. }
  2286. if (cmd === 0) {
  2287. let turnPage = 0,
  2288. turnOnlyIfPageFit = false;
  2289. switch (evt.keyCode) {
  2290. case 38:
  2291. case 33:
  2292. if (pdfViewer.isVerticalScrollbarEnabled) {
  2293. turnOnlyIfPageFit = true;
  2294. }
  2295. turnPage = -1;
  2296. break;
  2297. case 8:
  2298. if (!isViewerInPresentationMode) {
  2299. turnOnlyIfPageFit = true;
  2300. }
  2301. turnPage = -1;
  2302. break;
  2303. case 37:
  2304. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2305. turnOnlyIfPageFit = true;
  2306. }
  2307. case 75:
  2308. case 80:
  2309. turnPage = -1;
  2310. break;
  2311. case 27:
  2312. if (PDFViewerApplication.secondaryToolbar?.isOpen) {
  2313. PDFViewerApplication.secondaryToolbar.close();
  2314. handled = true;
  2315. }
  2316. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) {
  2317. PDFViewerApplication.findBar.close();
  2318. handled = true;
  2319. }
  2320. break;
  2321. case 40:
  2322. case 34:
  2323. if (pdfViewer.isVerticalScrollbarEnabled) {
  2324. turnOnlyIfPageFit = true;
  2325. }
  2326. turnPage = 1;
  2327. break;
  2328. case 13:
  2329. case 32:
  2330. if (!isViewerInPresentationMode) {
  2331. turnOnlyIfPageFit = true;
  2332. }
  2333. turnPage = 1;
  2334. break;
  2335. case 39:
  2336. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2337. turnOnlyIfPageFit = true;
  2338. }
  2339. case 74:
  2340. case 78:
  2341. turnPage = 1;
  2342. break;
  2343. case 36:
  2344. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2345. PDFViewerApplication.page = 1;
  2346. handled = true;
  2347. ensureViewerFocused = true;
  2348. }
  2349. break;
  2350. case 35:
  2351. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2352. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2353. handled = true;
  2354. ensureViewerFocused = true;
  2355. }
  2356. break;
  2357. case 83:
  2358. PDFViewerApplication.pdfCursorTools?.switchTool(_ui_utils.CursorTool.SELECT);
  2359. break;
  2360. case 72:
  2361. PDFViewerApplication.pdfCursorTools?.switchTool(_ui_utils.CursorTool.HAND);
  2362. break;
  2363. case 82:
  2364. PDFViewerApplication.rotatePages(90);
  2365. break;
  2366. case 115:
  2367. PDFViewerApplication.pdfSidebar?.toggle();
  2368. break;
  2369. }
  2370. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2371. if (turnPage > 0) {
  2372. pdfViewer.nextPage();
  2373. } else {
  2374. pdfViewer.previousPage();
  2375. }
  2376. handled = true;
  2377. }
  2378. }
  2379. if (cmd === 4) {
  2380. switch (evt.keyCode) {
  2381. case 13:
  2382. case 32:
  2383. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2384. break;
  2385. }
  2386. pdfViewer.previousPage();
  2387. handled = true;
  2388. break;
  2389. case 82:
  2390. PDFViewerApplication.rotatePages(-90);
  2391. break;
  2392. }
  2393. }
  2394. if (!handled && !isViewerInPresentationMode) {
  2395. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2396. ensureViewerFocused = true;
  2397. }
  2398. }
  2399. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2400. pdfViewer.focus();
  2401. }
  2402. if (handled) {
  2403. evt.preventDefault();
  2404. }
  2405. }
  2406. function beforeUnload(evt) {
  2407. evt.preventDefault();
  2408. evt.returnValue = "";
  2409. return false;
  2410. }
  2411. function webViewerAnnotationEditorStatesChanged(data) {
  2412. PDFViewerApplication.externalServices.updateEditorStates(data);
  2413. }
  2414. const PDFPrintServiceFactory = {
  2415. instance: {
  2416. supportsPrinting: false,
  2417. createPrintService() {
  2418. throw new Error("Not implemented: createPrintService");
  2419. }
  2420. }
  2421. };
  2422. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2423. /***/ }),
  2424. /* 3 */
  2425. /***/ ((__unused_webpack_module, exports) => {
  2426. Object.defineProperty(exports, "__esModule", ({
  2427. value: true
  2428. }));
  2429. exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = 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.CursorTool = exports.AutoPrintRegExp = void 0;
  2430. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  2431. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2432. exports.approximateFraction = approximateFraction;
  2433. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2434. exports.binarySearchFirstItem = binarySearchFirstItem;
  2435. exports.docStyle = void 0;
  2436. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2437. exports.getPageSizeInches = getPageSizeInches;
  2438. exports.getVisibleElements = getVisibleElements;
  2439. exports.isPortraitOrientation = isPortraitOrientation;
  2440. exports.isValidRotation = isValidRotation;
  2441. exports.isValidScrollMode = isValidScrollMode;
  2442. exports.isValidSpreadMode = isValidSpreadMode;
  2443. exports.noContextMenuHandler = noContextMenuHandler;
  2444. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2445. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2446. exports.parseQueryString = parseQueryString;
  2447. exports.removeNullCharacters = removeNullCharacters;
  2448. exports.roundToDivide = roundToDivide;
  2449. exports.scrollIntoView = scrollIntoView;
  2450. exports.toggleCheckedBtn = toggleCheckedBtn;
  2451. exports.toggleExpandedBtn = toggleExpandedBtn;
  2452. exports.watchScroll = watchScroll;
  2453. const DEFAULT_SCALE_VALUE = "auto";
  2454. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2455. const DEFAULT_SCALE = 1.0;
  2456. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2457. const DEFAULT_SCALE_DELTA = 1.1;
  2458. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  2459. const MIN_SCALE = 0.1;
  2460. exports.MIN_SCALE = MIN_SCALE;
  2461. const MAX_SCALE = 10.0;
  2462. exports.MAX_SCALE = MAX_SCALE;
  2463. const UNKNOWN_SCALE = 0;
  2464. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2465. const MAX_AUTO_SCALE = 1.25;
  2466. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2467. const SCROLLBAR_PADDING = 40;
  2468. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2469. const VERTICAL_PADDING = 5;
  2470. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2471. const RenderingStates = {
  2472. INITIAL: 0,
  2473. RUNNING: 1,
  2474. PAUSED: 2,
  2475. FINISHED: 3
  2476. };
  2477. exports.RenderingStates = RenderingStates;
  2478. const PresentationModeState = {
  2479. UNKNOWN: 0,
  2480. NORMAL: 1,
  2481. CHANGING: 2,
  2482. FULLSCREEN: 3
  2483. };
  2484. exports.PresentationModeState = PresentationModeState;
  2485. const SidebarView = {
  2486. UNKNOWN: -1,
  2487. NONE: 0,
  2488. THUMBS: 1,
  2489. OUTLINE: 2,
  2490. ATTACHMENTS: 3,
  2491. LAYERS: 4
  2492. };
  2493. exports.SidebarView = SidebarView;
  2494. const TextLayerMode = {
  2495. DISABLE: 0,
  2496. ENABLE: 1,
  2497. ENABLE_PERMISSIONS: 2
  2498. };
  2499. exports.TextLayerMode = TextLayerMode;
  2500. const ScrollMode = {
  2501. UNKNOWN: -1,
  2502. VERTICAL: 0,
  2503. HORIZONTAL: 1,
  2504. WRAPPED: 2,
  2505. PAGE: 3
  2506. };
  2507. exports.ScrollMode = ScrollMode;
  2508. const SpreadMode = {
  2509. UNKNOWN: -1,
  2510. NONE: 0,
  2511. ODD: 1,
  2512. EVEN: 2
  2513. };
  2514. exports.SpreadMode = SpreadMode;
  2515. const CursorTool = {
  2516. SELECT: 0,
  2517. HAND: 1,
  2518. ZOOM: 2
  2519. };
  2520. exports.CursorTool = CursorTool;
  2521. const AutoPrintRegExp = /\bprint\s*\(/;
  2522. exports.AutoPrintRegExp = AutoPrintRegExp;
  2523. class OutputScale {
  2524. constructor() {
  2525. const pixelRatio = window.devicePixelRatio || 1;
  2526. this.sx = pixelRatio;
  2527. this.sy = pixelRatio;
  2528. }
  2529. get scaled() {
  2530. return this.sx !== 1 || this.sy !== 1;
  2531. }
  2532. }
  2533. exports.OutputScale = OutputScale;
  2534. function scrollIntoView(element, spot, scrollMatches = false) {
  2535. let parent = element.offsetParent;
  2536. if (!parent) {
  2537. console.error("offsetParent is not set -- cannot scroll");
  2538. return;
  2539. }
  2540. let offsetY = element.offsetTop + element.clientTop;
  2541. let offsetX = element.offsetLeft + element.clientLeft;
  2542. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  2543. offsetY += parent.offsetTop;
  2544. offsetX += parent.offsetLeft;
  2545. parent = parent.offsetParent;
  2546. if (!parent) {
  2547. return;
  2548. }
  2549. }
  2550. if (spot) {
  2551. if (spot.top !== undefined) {
  2552. offsetY += spot.top;
  2553. }
  2554. if (spot.left !== undefined) {
  2555. offsetX += spot.left;
  2556. parent.scrollLeft = offsetX;
  2557. }
  2558. }
  2559. parent.scrollTop = offsetY;
  2560. }
  2561. function watchScroll(viewAreaElement, callback) {
  2562. const debounceScroll = function (evt) {
  2563. if (rAF) {
  2564. return;
  2565. }
  2566. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2567. rAF = null;
  2568. const currentX = viewAreaElement.scrollLeft;
  2569. const lastX = state.lastX;
  2570. if (currentX !== lastX) {
  2571. state.right = currentX > lastX;
  2572. }
  2573. state.lastX = currentX;
  2574. const currentY = viewAreaElement.scrollTop;
  2575. const lastY = state.lastY;
  2576. if (currentY !== lastY) {
  2577. state.down = currentY > lastY;
  2578. }
  2579. state.lastY = currentY;
  2580. callback(state);
  2581. });
  2582. };
  2583. const state = {
  2584. right: true,
  2585. down: true,
  2586. lastX: viewAreaElement.scrollLeft,
  2587. lastY: viewAreaElement.scrollTop,
  2588. _eventHandler: debounceScroll
  2589. };
  2590. let rAF = null;
  2591. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2592. return state;
  2593. }
  2594. function parseQueryString(query) {
  2595. const params = new Map();
  2596. for (const [key, value] of new URLSearchParams(query)) {
  2597. params.set(key.toLowerCase(), value);
  2598. }
  2599. return params;
  2600. }
  2601. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  2602. function removeNullCharacters(str, replaceInvisible = false) {
  2603. if (typeof str !== "string") {
  2604. console.error(`The argument must be a string.`);
  2605. return str;
  2606. }
  2607. if (replaceInvisible) {
  2608. str = str.replaceAll(InvisibleCharactersRegExp, " ");
  2609. }
  2610. return str.replaceAll("\x00", "");
  2611. }
  2612. function binarySearchFirstItem(items, condition, start = 0) {
  2613. let minIndex = start;
  2614. let maxIndex = items.length - 1;
  2615. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2616. return items.length;
  2617. }
  2618. if (condition(items[minIndex])) {
  2619. return minIndex;
  2620. }
  2621. while (minIndex < maxIndex) {
  2622. const currentIndex = minIndex + maxIndex >> 1;
  2623. const currentItem = items[currentIndex];
  2624. if (condition(currentItem)) {
  2625. maxIndex = currentIndex;
  2626. } else {
  2627. minIndex = currentIndex + 1;
  2628. }
  2629. }
  2630. return minIndex;
  2631. }
  2632. function approximateFraction(x) {
  2633. if (Math.floor(x) === x) {
  2634. return [x, 1];
  2635. }
  2636. const xinv = 1 / x;
  2637. const limit = 8;
  2638. if (xinv > limit) {
  2639. return [1, limit];
  2640. } else if (Math.floor(xinv) === xinv) {
  2641. return [1, xinv];
  2642. }
  2643. const x_ = x > 1 ? xinv : x;
  2644. let a = 0,
  2645. b = 1,
  2646. c = 1,
  2647. d = 1;
  2648. while (true) {
  2649. const p = a + c,
  2650. q = b + d;
  2651. if (q > limit) {
  2652. break;
  2653. }
  2654. if (x_ <= p / q) {
  2655. c = p;
  2656. d = q;
  2657. } else {
  2658. a = p;
  2659. b = q;
  2660. }
  2661. }
  2662. let result;
  2663. if (x_ - a / b < c / d - x_) {
  2664. result = x_ === x ? [a, b] : [b, a];
  2665. } else {
  2666. result = x_ === x ? [c, d] : [d, c];
  2667. }
  2668. return result;
  2669. }
  2670. function roundToDivide(x, div) {
  2671. const r = x % div;
  2672. return r === 0 ? x : Math.round(x - r + div);
  2673. }
  2674. function getPageSizeInches({
  2675. view,
  2676. userUnit,
  2677. rotate
  2678. }) {
  2679. const [x1, y1, x2, y2] = view;
  2680. const changeOrientation = rotate % 180 !== 0;
  2681. const width = (x2 - x1) / 72 * userUnit;
  2682. const height = (y2 - y1) / 72 * userUnit;
  2683. return {
  2684. width: changeOrientation ? height : width,
  2685. height: changeOrientation ? width : height
  2686. };
  2687. }
  2688. function backtrackBeforeAllVisibleElements(index, views, top) {
  2689. if (index < 2) {
  2690. return index;
  2691. }
  2692. let elt = views[index].div;
  2693. let pageTop = elt.offsetTop + elt.clientTop;
  2694. if (pageTop >= top) {
  2695. elt = views[index - 1].div;
  2696. pageTop = elt.offsetTop + elt.clientTop;
  2697. }
  2698. for (let i = index - 2; i >= 0; --i) {
  2699. elt = views[i].div;
  2700. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2701. break;
  2702. }
  2703. index = i;
  2704. }
  2705. return index;
  2706. }
  2707. function getVisibleElements({
  2708. scrollEl,
  2709. views,
  2710. sortByVisibility = false,
  2711. horizontal = false,
  2712. rtl = false
  2713. }) {
  2714. const top = scrollEl.scrollTop,
  2715. bottom = top + scrollEl.clientHeight;
  2716. const left = scrollEl.scrollLeft,
  2717. right = left + scrollEl.clientWidth;
  2718. function isElementBottomAfterViewTop(view) {
  2719. const element = view.div;
  2720. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2721. return elementBottom > top;
  2722. }
  2723. function isElementNextAfterViewHorizontally(view) {
  2724. const element = view.div;
  2725. const elementLeft = element.offsetLeft + element.clientLeft;
  2726. const elementRight = elementLeft + element.clientWidth;
  2727. return rtl ? elementLeft < right : elementRight > left;
  2728. }
  2729. const visible = [],
  2730. ids = new Set(),
  2731. numViews = views.length;
  2732. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2733. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2734. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2735. }
  2736. let lastEdge = horizontal ? right : -1;
  2737. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2738. const view = views[i],
  2739. element = view.div;
  2740. const currentWidth = element.offsetLeft + element.clientLeft;
  2741. const currentHeight = element.offsetTop + element.clientTop;
  2742. const viewWidth = element.clientWidth,
  2743. viewHeight = element.clientHeight;
  2744. const viewRight = currentWidth + viewWidth;
  2745. const viewBottom = currentHeight + viewHeight;
  2746. if (lastEdge === -1) {
  2747. if (viewBottom >= bottom) {
  2748. lastEdge = viewBottom;
  2749. }
  2750. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2751. break;
  2752. }
  2753. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2754. continue;
  2755. }
  2756. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2757. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2758. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2759. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2760. const percent = fractionHeight * fractionWidth * 100 | 0;
  2761. visible.push({
  2762. id: view.id,
  2763. x: currentWidth,
  2764. y: currentHeight,
  2765. view,
  2766. percent,
  2767. widthPercent: fractionWidth * 100 | 0
  2768. });
  2769. ids.add(view.id);
  2770. }
  2771. const first = visible[0],
  2772. last = visible.at(-1);
  2773. if (sortByVisibility) {
  2774. visible.sort(function (a, b) {
  2775. const pc = a.percent - b.percent;
  2776. if (Math.abs(pc) > 0.001) {
  2777. return -pc;
  2778. }
  2779. return a.id - b.id;
  2780. });
  2781. }
  2782. return {
  2783. first,
  2784. last,
  2785. views: visible,
  2786. ids
  2787. };
  2788. }
  2789. function noContextMenuHandler(evt) {
  2790. evt.preventDefault();
  2791. }
  2792. function normalizeWheelEventDirection(evt) {
  2793. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2794. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2795. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2796. delta = -delta;
  2797. }
  2798. return delta;
  2799. }
  2800. function normalizeWheelEventDelta(evt) {
  2801. const deltaMode = evt.deltaMode;
  2802. let delta = normalizeWheelEventDirection(evt);
  2803. const MOUSE_PIXELS_PER_LINE = 30;
  2804. const MOUSE_LINES_PER_PAGE = 30;
  2805. if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
  2806. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2807. } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
  2808. delta /= MOUSE_LINES_PER_PAGE;
  2809. }
  2810. return delta;
  2811. }
  2812. function isValidRotation(angle) {
  2813. return Number.isInteger(angle) && angle % 90 === 0;
  2814. }
  2815. function isValidScrollMode(mode) {
  2816. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2817. }
  2818. function isValidSpreadMode(mode) {
  2819. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2820. }
  2821. function isPortraitOrientation(size) {
  2822. return size.width <= size.height;
  2823. }
  2824. const animationStarted = new Promise(function (resolve) {
  2825. window.requestAnimationFrame(resolve);
  2826. });
  2827. exports.animationStarted = animationStarted;
  2828. const docStyle = document.documentElement.style;
  2829. exports.docStyle = docStyle;
  2830. function clamp(v, min, max) {
  2831. return Math.min(Math.max(v, min), max);
  2832. }
  2833. class ProgressBar {
  2834. #classList = null;
  2835. #disableAutoFetchTimeout = null;
  2836. #percent = 0;
  2837. #style = null;
  2838. #visible = true;
  2839. constructor(bar) {
  2840. this.#classList = bar.classList;
  2841. this.#style = bar.style;
  2842. }
  2843. get percent() {
  2844. return this.#percent;
  2845. }
  2846. set percent(val) {
  2847. this.#percent = clamp(val, 0, 100);
  2848. if (isNaN(val)) {
  2849. this.#classList.add("indeterminate");
  2850. return;
  2851. }
  2852. this.#classList.remove("indeterminate");
  2853. this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
  2854. }
  2855. setWidth(viewer) {
  2856. if (!viewer) {
  2857. return;
  2858. }
  2859. const container = viewer.parentNode;
  2860. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  2861. if (scrollbarWidth > 0) {
  2862. this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  2863. }
  2864. }
  2865. setDisableAutoFetch(delay = 5000) {
  2866. if (isNaN(this.#percent)) {
  2867. return;
  2868. }
  2869. if (this.#disableAutoFetchTimeout) {
  2870. clearTimeout(this.#disableAutoFetchTimeout);
  2871. }
  2872. this.show();
  2873. this.#disableAutoFetchTimeout = setTimeout(() => {
  2874. this.#disableAutoFetchTimeout = null;
  2875. this.hide();
  2876. }, delay);
  2877. }
  2878. hide() {
  2879. if (!this.#visible) {
  2880. return;
  2881. }
  2882. this.#visible = false;
  2883. this.#classList.add("hidden");
  2884. }
  2885. show() {
  2886. if (this.#visible) {
  2887. return;
  2888. }
  2889. this.#visible = true;
  2890. this.#classList.remove("hidden");
  2891. }
  2892. }
  2893. exports.ProgressBar = ProgressBar;
  2894. function getActiveOrFocusedElement() {
  2895. let curRoot = document;
  2896. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2897. while (curActiveOrFocused?.shadowRoot) {
  2898. curRoot = curActiveOrFocused.shadowRoot;
  2899. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2900. }
  2901. return curActiveOrFocused;
  2902. }
  2903. function apiPageLayoutToViewerModes(layout) {
  2904. let scrollMode = ScrollMode.VERTICAL,
  2905. spreadMode = SpreadMode.NONE;
  2906. switch (layout) {
  2907. case "SinglePage":
  2908. scrollMode = ScrollMode.PAGE;
  2909. break;
  2910. case "OneColumn":
  2911. break;
  2912. case "TwoPageLeft":
  2913. scrollMode = ScrollMode.PAGE;
  2914. case "TwoColumnLeft":
  2915. spreadMode = SpreadMode.ODD;
  2916. break;
  2917. case "TwoPageRight":
  2918. scrollMode = ScrollMode.PAGE;
  2919. case "TwoColumnRight":
  2920. spreadMode = SpreadMode.EVEN;
  2921. break;
  2922. }
  2923. return {
  2924. scrollMode,
  2925. spreadMode
  2926. };
  2927. }
  2928. function apiPageModeToSidebarView(mode) {
  2929. switch (mode) {
  2930. case "UseNone":
  2931. return SidebarView.NONE;
  2932. case "UseThumbs":
  2933. return SidebarView.THUMBS;
  2934. case "UseOutlines":
  2935. return SidebarView.OUTLINE;
  2936. case "UseAttachments":
  2937. return SidebarView.ATTACHMENTS;
  2938. case "UseOC":
  2939. return SidebarView.LAYERS;
  2940. }
  2941. return SidebarView.NONE;
  2942. }
  2943. function toggleCheckedBtn(button, toggle, view = null) {
  2944. button.classList.toggle("toggled", toggle);
  2945. button.setAttribute("aria-checked", toggle);
  2946. view?.classList.toggle("hidden", !toggle);
  2947. }
  2948. function toggleExpandedBtn(button, toggle, view = null) {
  2949. button.classList.toggle("toggled", toggle);
  2950. button.setAttribute("aria-expanded", toggle);
  2951. view?.classList.toggle("hidden", !toggle);
  2952. }
  2953. /***/ }),
  2954. /* 4 */
  2955. /***/ ((module) => {
  2956. module.exports = globalThis.pdfjsLib;
  2957. /***/ }),
  2958. /* 5 */
  2959. /***/ ((__unused_webpack_module, exports) => {
  2960. Object.defineProperty(exports, "__esModule", ({
  2961. value: true
  2962. }));
  2963. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  2964. const compatibilityParams = Object.create(null);
  2965. exports.compatibilityParams = compatibilityParams;
  2966. {
  2967. const userAgent = navigator.userAgent || "";
  2968. const platform = navigator.platform || "";
  2969. const maxTouchPoints = navigator.maxTouchPoints || 1;
  2970. const isAndroid = /Android/.test(userAgent);
  2971. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  2972. (function checkCanvasSizeLimitation() {
  2973. if (isIOS || isAndroid) {
  2974. compatibilityParams.maxCanvasPixels = 5242880;
  2975. }
  2976. })();
  2977. }
  2978. const OptionKind = {
  2979. VIEWER: 0x02,
  2980. API: 0x04,
  2981. WORKER: 0x08,
  2982. PREFERENCE: 0x80
  2983. };
  2984. exports.OptionKind = OptionKind;
  2985. const defaultOptions = {
  2986. annotationEditorMode: {
  2987. value: 0,
  2988. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2989. },
  2990. annotationMode: {
  2991. value: 2,
  2992. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2993. },
  2994. cursorToolOnLoad: {
  2995. value: 0,
  2996. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2997. },
  2998. defaultZoomDelay: {
  2999. value: 400,
  3000. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3001. },
  3002. defaultZoomValue: {
  3003. value: "",
  3004. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3005. },
  3006. disableHistory: {
  3007. value: false,
  3008. kind: OptionKind.VIEWER
  3009. },
  3010. disablePageLabels: {
  3011. value: false,
  3012. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3013. },
  3014. enablePermissions: {
  3015. value: false,
  3016. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3017. },
  3018. enablePrintAutoRotate: {
  3019. value: true,
  3020. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3021. },
  3022. enableScripting: {
  3023. value: true,
  3024. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3025. },
  3026. enableStampEditor: {
  3027. value: true,
  3028. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3029. },
  3030. externalLinkRel: {
  3031. value: "noopener noreferrer nofollow",
  3032. kind: OptionKind.VIEWER
  3033. },
  3034. externalLinkTarget: {
  3035. value: 0,
  3036. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3037. },
  3038. historyUpdateUrl: {
  3039. value: false,
  3040. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3041. },
  3042. ignoreDestinationZoom: {
  3043. value: false,
  3044. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3045. },
  3046. imageResourcesPath: {
  3047. value: "./images/",
  3048. kind: OptionKind.VIEWER
  3049. },
  3050. maxCanvasPixels: {
  3051. value: 16777216,
  3052. kind: OptionKind.VIEWER
  3053. },
  3054. forcePageColors: {
  3055. value: false,
  3056. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3057. },
  3058. pageColorsBackground: {
  3059. value: "Canvas",
  3060. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3061. },
  3062. pageColorsForeground: {
  3063. value: "CanvasText",
  3064. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3065. },
  3066. pdfBugEnabled: {
  3067. value: false,
  3068. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3069. },
  3070. printResolution: {
  3071. value: 150,
  3072. kind: OptionKind.VIEWER
  3073. },
  3074. sidebarViewOnLoad: {
  3075. value: -1,
  3076. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3077. },
  3078. scrollModeOnLoad: {
  3079. value: -1,
  3080. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3081. },
  3082. spreadModeOnLoad: {
  3083. value: -1,
  3084. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3085. },
  3086. textLayerMode: {
  3087. value: 1,
  3088. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3089. },
  3090. viewerCssTheme: {
  3091. value: 0,
  3092. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3093. },
  3094. viewOnLoad: {
  3095. value: 0,
  3096. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3097. },
  3098. cMapPacked: {
  3099. value: true,
  3100. kind: OptionKind.API
  3101. },
  3102. cMapUrl: {
  3103. value: "../web/cmaps/",
  3104. kind: OptionKind.API
  3105. },
  3106. disableAutoFetch: {
  3107. value: false,
  3108. kind: OptionKind.API + OptionKind.PREFERENCE
  3109. },
  3110. disableFontFace: {
  3111. value: false,
  3112. kind: OptionKind.API + OptionKind.PREFERENCE
  3113. },
  3114. disableRange: {
  3115. value: false,
  3116. kind: OptionKind.API + OptionKind.PREFERENCE
  3117. },
  3118. disableStream: {
  3119. value: false,
  3120. kind: OptionKind.API + OptionKind.PREFERENCE
  3121. },
  3122. docBaseUrl: {
  3123. value: "",
  3124. kind: OptionKind.API
  3125. },
  3126. enableXfa: {
  3127. value: true,
  3128. kind: OptionKind.API + OptionKind.PREFERENCE
  3129. },
  3130. fontExtraProperties: {
  3131. value: false,
  3132. kind: OptionKind.API
  3133. },
  3134. isEvalSupported: {
  3135. value: true,
  3136. kind: OptionKind.API
  3137. },
  3138. isOffscreenCanvasSupported: {
  3139. value: true,
  3140. kind: OptionKind.API
  3141. },
  3142. maxImageSize: {
  3143. value: -1,
  3144. kind: OptionKind.API
  3145. },
  3146. pdfBug: {
  3147. value: false,
  3148. kind: OptionKind.API
  3149. },
  3150. standardFontDataUrl: {
  3151. value: "../web/standard_fonts/",
  3152. kind: OptionKind.API
  3153. },
  3154. verbosity: {
  3155. value: 1,
  3156. kind: OptionKind.API
  3157. },
  3158. workerPort: {
  3159. value: null,
  3160. kind: OptionKind.WORKER
  3161. },
  3162. workerSrc: {
  3163. value: "../build/pdf.worker.js",
  3164. kind: OptionKind.WORKER
  3165. }
  3166. };
  3167. {
  3168. defaultOptions.defaultUrl = {
  3169. value: "compressed.tracemonkey-pldi-09.pdf",
  3170. kind: OptionKind.VIEWER
  3171. };
  3172. defaultOptions.disablePreferences = {
  3173. value: false,
  3174. kind: OptionKind.VIEWER
  3175. };
  3176. defaultOptions.locale = {
  3177. value: navigator.language || "en-US",
  3178. kind: OptionKind.VIEWER
  3179. };
  3180. defaultOptions.sandboxBundleSrc = {
  3181. value: "../build/pdf.sandbox.js",
  3182. kind: OptionKind.VIEWER
  3183. };
  3184. }
  3185. const userOptions = Object.create(null);
  3186. class AppOptions {
  3187. constructor() {
  3188. throw new Error("Cannot initialize AppOptions.");
  3189. }
  3190. static get(name) {
  3191. const userOption = userOptions[name];
  3192. if (userOption !== undefined) {
  3193. return userOption;
  3194. }
  3195. const defaultOption = defaultOptions[name];
  3196. if (defaultOption !== undefined) {
  3197. return compatibilityParams[name] ?? defaultOption.value;
  3198. }
  3199. return undefined;
  3200. }
  3201. static getAll(kind = null) {
  3202. const options = Object.create(null);
  3203. for (const name in defaultOptions) {
  3204. const defaultOption = defaultOptions[name];
  3205. if (kind) {
  3206. if ((kind & defaultOption.kind) === 0) {
  3207. continue;
  3208. }
  3209. if (kind === OptionKind.PREFERENCE) {
  3210. const value = defaultOption.value,
  3211. valueType = typeof value;
  3212. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  3213. options[name] = value;
  3214. continue;
  3215. }
  3216. throw new Error(`Invalid type for preference: ${name}`);
  3217. }
  3218. }
  3219. const userOption = userOptions[name];
  3220. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  3221. }
  3222. return options;
  3223. }
  3224. static set(name, value) {
  3225. userOptions[name] = value;
  3226. }
  3227. static setAll(options) {
  3228. for (const name in options) {
  3229. userOptions[name] = options[name];
  3230. }
  3231. }
  3232. static remove(name) {
  3233. delete userOptions[name];
  3234. }
  3235. }
  3236. exports.AppOptions = AppOptions;
  3237. {
  3238. AppOptions._hasUserOptions = function () {
  3239. return Object.keys(userOptions).length > 0;
  3240. };
  3241. }
  3242. /***/ }),
  3243. /* 6 */
  3244. /***/ ((__unused_webpack_module, exports) => {
  3245. Object.defineProperty(exports, "__esModule", ({
  3246. value: true
  3247. }));
  3248. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3249. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3250. const WaitOnType = {
  3251. EVENT: "event",
  3252. TIMEOUT: "timeout"
  3253. };
  3254. exports.WaitOnType = WaitOnType;
  3255. function waitOnEventOrTimeout({
  3256. target,
  3257. name,
  3258. delay = 0
  3259. }) {
  3260. return new Promise(function (resolve, reject) {
  3261. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3262. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3263. }
  3264. function handler(type) {
  3265. if (target instanceof EventBus) {
  3266. target._off(name, eventHandler);
  3267. } else {
  3268. target.removeEventListener(name, eventHandler);
  3269. }
  3270. if (timeout) {
  3271. clearTimeout(timeout);
  3272. }
  3273. resolve(type);
  3274. }
  3275. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3276. if (target instanceof EventBus) {
  3277. target._on(name, eventHandler);
  3278. } else {
  3279. target.addEventListener(name, eventHandler);
  3280. }
  3281. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3282. const timeout = setTimeout(timeoutHandler, delay);
  3283. });
  3284. }
  3285. class EventBus {
  3286. #listeners = Object.create(null);
  3287. on(eventName, listener, options = null) {
  3288. this._on(eventName, listener, {
  3289. external: true,
  3290. once: options?.once
  3291. });
  3292. }
  3293. off(eventName, listener, options = null) {
  3294. this._off(eventName, listener, {
  3295. external: true,
  3296. once: options?.once
  3297. });
  3298. }
  3299. dispatch(eventName, data) {
  3300. const eventListeners = this.#listeners[eventName];
  3301. if (!eventListeners || eventListeners.length === 0) {
  3302. return;
  3303. }
  3304. let externalListeners;
  3305. for (const {
  3306. listener,
  3307. external,
  3308. once
  3309. } of eventListeners.slice(0)) {
  3310. if (once) {
  3311. this._off(eventName, listener);
  3312. }
  3313. if (external) {
  3314. (externalListeners ||= []).push(listener);
  3315. continue;
  3316. }
  3317. listener(data);
  3318. }
  3319. if (externalListeners) {
  3320. for (const listener of externalListeners) {
  3321. listener(data);
  3322. }
  3323. externalListeners = null;
  3324. }
  3325. }
  3326. _on(eventName, listener, options = null) {
  3327. const eventListeners = this.#listeners[eventName] ||= [];
  3328. eventListeners.push({
  3329. listener,
  3330. external: options?.external === true,
  3331. once: options?.once === true
  3332. });
  3333. }
  3334. _off(eventName, listener, options = null) {
  3335. const eventListeners = this.#listeners[eventName];
  3336. if (!eventListeners) {
  3337. return;
  3338. }
  3339. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3340. if (eventListeners[i].listener === listener) {
  3341. eventListeners.splice(i, 1);
  3342. return;
  3343. }
  3344. }
  3345. }
  3346. }
  3347. exports.EventBus = EventBus;
  3348. class AutomationEventBus extends EventBus {
  3349. dispatch(eventName, data) {
  3350. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3351. }
  3352. }
  3353. exports.AutomationEventBus = AutomationEventBus;
  3354. /***/ }),
  3355. /* 7 */
  3356. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3357. Object.defineProperty(exports, "__esModule", ({
  3358. value: true
  3359. }));
  3360. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  3361. var _ui_utils = __webpack_require__(3);
  3362. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  3363. const LinkTarget = {
  3364. NONE: 0,
  3365. SELF: 1,
  3366. BLANK: 2,
  3367. PARENT: 3,
  3368. TOP: 4
  3369. };
  3370. exports.LinkTarget = LinkTarget;
  3371. function addLinkAttributes(link, {
  3372. url,
  3373. target,
  3374. rel,
  3375. enabled = true
  3376. } = {}) {
  3377. if (!url || typeof url !== "string") {
  3378. throw new Error('A valid "url" parameter must provided.');
  3379. }
  3380. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  3381. if (enabled) {
  3382. link.href = link.title = urlNullRemoved;
  3383. } else {
  3384. link.href = "";
  3385. link.title = `Disabled: ${urlNullRemoved}`;
  3386. link.onclick = () => {
  3387. return false;
  3388. };
  3389. }
  3390. let targetStr = "";
  3391. switch (target) {
  3392. case LinkTarget.NONE:
  3393. break;
  3394. case LinkTarget.SELF:
  3395. targetStr = "_self";
  3396. break;
  3397. case LinkTarget.BLANK:
  3398. targetStr = "_blank";
  3399. break;
  3400. case LinkTarget.PARENT:
  3401. targetStr = "_parent";
  3402. break;
  3403. case LinkTarget.TOP:
  3404. targetStr = "_top";
  3405. break;
  3406. }
  3407. link.target = targetStr;
  3408. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  3409. }
  3410. class PDFLinkService {
  3411. #pagesRefCache = new Map();
  3412. constructor({
  3413. eventBus,
  3414. externalLinkTarget = null,
  3415. externalLinkRel = null,
  3416. ignoreDestinationZoom = false
  3417. } = {}) {
  3418. this.eventBus = eventBus;
  3419. this.externalLinkTarget = externalLinkTarget;
  3420. this.externalLinkRel = externalLinkRel;
  3421. this.externalLinkEnabled = true;
  3422. this._ignoreDestinationZoom = ignoreDestinationZoom;
  3423. this.baseUrl = null;
  3424. this.pdfDocument = null;
  3425. this.pdfViewer = null;
  3426. this.pdfHistory = null;
  3427. }
  3428. setDocument(pdfDocument, baseUrl = null) {
  3429. this.baseUrl = baseUrl;
  3430. this.pdfDocument = pdfDocument;
  3431. this.#pagesRefCache.clear();
  3432. }
  3433. setViewer(pdfViewer) {
  3434. this.pdfViewer = pdfViewer;
  3435. }
  3436. setHistory(pdfHistory) {
  3437. this.pdfHistory = pdfHistory;
  3438. }
  3439. get pagesCount() {
  3440. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  3441. }
  3442. get page() {
  3443. return this.pdfViewer.currentPageNumber;
  3444. }
  3445. set page(value) {
  3446. this.pdfViewer.currentPageNumber = value;
  3447. }
  3448. get rotation() {
  3449. return this.pdfViewer.pagesRotation;
  3450. }
  3451. set rotation(value) {
  3452. this.pdfViewer.pagesRotation = value;
  3453. }
  3454. get isInPresentationMode() {
  3455. return this.pdfViewer.isInPresentationMode;
  3456. }
  3457. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  3458. const destRef = explicitDest[0];
  3459. let pageNumber;
  3460. if (typeof destRef === "object" && destRef !== null) {
  3461. pageNumber = this._cachedPageNumber(destRef);
  3462. if (!pageNumber) {
  3463. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  3464. this.cachePageRef(pageIndex + 1, destRef);
  3465. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  3466. }).catch(() => {
  3467. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  3468. });
  3469. return;
  3470. }
  3471. } else if (Number.isInteger(destRef)) {
  3472. pageNumber = destRef + 1;
  3473. } else {
  3474. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  3475. return;
  3476. }
  3477. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  3478. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  3479. return;
  3480. }
  3481. if (this.pdfHistory) {
  3482. this.pdfHistory.pushCurrentPosition();
  3483. this.pdfHistory.push({
  3484. namedDest,
  3485. explicitDest,
  3486. pageNumber
  3487. });
  3488. }
  3489. this.pdfViewer.scrollPageIntoView({
  3490. pageNumber,
  3491. destArray: explicitDest,
  3492. ignoreDestinationZoom: this._ignoreDestinationZoom
  3493. });
  3494. }
  3495. async goToDestination(dest) {
  3496. if (!this.pdfDocument) {
  3497. return;
  3498. }
  3499. let namedDest, explicitDest;
  3500. if (typeof dest === "string") {
  3501. namedDest = dest;
  3502. explicitDest = await this.pdfDocument.getDestination(dest);
  3503. } else {
  3504. namedDest = null;
  3505. explicitDest = await dest;
  3506. }
  3507. if (!Array.isArray(explicitDest)) {
  3508. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  3509. return;
  3510. }
  3511. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  3512. }
  3513. goToPage(val) {
  3514. if (!this.pdfDocument) {
  3515. return;
  3516. }
  3517. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  3518. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  3519. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  3520. return;
  3521. }
  3522. if (this.pdfHistory) {
  3523. this.pdfHistory.pushCurrentPosition();
  3524. this.pdfHistory.pushPage(pageNumber);
  3525. }
  3526. this.pdfViewer.scrollPageIntoView({
  3527. pageNumber
  3528. });
  3529. }
  3530. addLinkAttributes(link, url, newWindow = false) {
  3531. addLinkAttributes(link, {
  3532. url,
  3533. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  3534. rel: this.externalLinkRel,
  3535. enabled: this.externalLinkEnabled
  3536. });
  3537. }
  3538. getDestinationHash(dest) {
  3539. if (typeof dest === "string") {
  3540. if (dest.length > 0) {
  3541. return this.getAnchorUrl("#" + escape(dest));
  3542. }
  3543. } else if (Array.isArray(dest)) {
  3544. const str = JSON.stringify(dest);
  3545. if (str.length > 0) {
  3546. return this.getAnchorUrl("#" + escape(str));
  3547. }
  3548. }
  3549. return this.getAnchorUrl("");
  3550. }
  3551. getAnchorUrl(anchor) {
  3552. return this.baseUrl ? this.baseUrl + anchor : anchor;
  3553. }
  3554. setHash(hash) {
  3555. if (!this.pdfDocument) {
  3556. return;
  3557. }
  3558. let pageNumber, dest;
  3559. if (hash.includes("=")) {
  3560. const params = (0, _ui_utils.parseQueryString)(hash);
  3561. if (params.has("search")) {
  3562. const query = params.get("search").replaceAll('"', ""),
  3563. phrase = params.get("phrase") === "true";
  3564. this.eventBus.dispatch("findfromurlhash", {
  3565. source: this,
  3566. query: phrase ? query : query.match(/\S+/g)
  3567. });
  3568. }
  3569. if (params.has("page")) {
  3570. pageNumber = params.get("page") | 0 || 1;
  3571. }
  3572. if (params.has("zoom")) {
  3573. const zoomArgs = params.get("zoom").split(",");
  3574. const zoomArg = zoomArgs[0];
  3575. const zoomArgNumber = parseFloat(zoomArg);
  3576. if (!zoomArg.includes("Fit")) {
  3577. dest = [null, {
  3578. name: "XYZ"
  3579. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  3580. } else if (zoomArg === "Fit" || zoomArg === "FitB") {
  3581. dest = [null, {
  3582. name: zoomArg
  3583. }];
  3584. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  3585. dest = [null, {
  3586. name: zoomArg
  3587. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  3588. } else if (zoomArg === "FitR") {
  3589. if (zoomArgs.length !== 5) {
  3590. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  3591. } else {
  3592. dest = [null, {
  3593. name: zoomArg
  3594. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  3595. }
  3596. } else {
  3597. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  3598. }
  3599. }
  3600. if (dest) {
  3601. this.pdfViewer.scrollPageIntoView({
  3602. pageNumber: pageNumber || this.page,
  3603. destArray: dest,
  3604. allowNegativeOffset: true
  3605. });
  3606. } else if (pageNumber) {
  3607. this.page = pageNumber;
  3608. }
  3609. if (params.has("pagemode")) {
  3610. this.eventBus.dispatch("pagemode", {
  3611. source: this,
  3612. mode: params.get("pagemode")
  3613. });
  3614. }
  3615. if (params.has("nameddest")) {
  3616. this.goToDestination(params.get("nameddest"));
  3617. }
  3618. } else {
  3619. dest = unescape(hash);
  3620. try {
  3621. dest = JSON.parse(dest);
  3622. if (!Array.isArray(dest)) {
  3623. dest = dest.toString();
  3624. }
  3625. } catch {}
  3626. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  3627. this.goToDestination(dest);
  3628. return;
  3629. }
  3630. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  3631. }
  3632. }
  3633. executeNamedAction(action) {
  3634. switch (action) {
  3635. case "GoBack":
  3636. this.pdfHistory?.back();
  3637. break;
  3638. case "GoForward":
  3639. this.pdfHistory?.forward();
  3640. break;
  3641. case "NextPage":
  3642. this.pdfViewer.nextPage();
  3643. break;
  3644. case "PrevPage":
  3645. this.pdfViewer.previousPage();
  3646. break;
  3647. case "LastPage":
  3648. this.page = this.pagesCount;
  3649. break;
  3650. case "FirstPage":
  3651. this.page = 1;
  3652. break;
  3653. default:
  3654. break;
  3655. }
  3656. this.eventBus.dispatch("namedaction", {
  3657. source: this,
  3658. action
  3659. });
  3660. }
  3661. async executeSetOCGState(action) {
  3662. const pdfDocument = this.pdfDocument;
  3663. const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  3664. if (pdfDocument !== this.pdfDocument) {
  3665. return;
  3666. }
  3667. let operator;
  3668. for (const elem of action.state) {
  3669. switch (elem) {
  3670. case "ON":
  3671. case "OFF":
  3672. case "Toggle":
  3673. operator = elem;
  3674. continue;
  3675. }
  3676. switch (operator) {
  3677. case "ON":
  3678. optionalContentConfig.setVisibility(elem, true);
  3679. break;
  3680. case "OFF":
  3681. optionalContentConfig.setVisibility(elem, false);
  3682. break;
  3683. case "Toggle":
  3684. const group = optionalContentConfig.getGroup(elem);
  3685. if (group) {
  3686. optionalContentConfig.setVisibility(elem, !group.visible);
  3687. }
  3688. break;
  3689. }
  3690. }
  3691. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  3692. }
  3693. cachePageRef(pageNum, pageRef) {
  3694. if (!pageRef) {
  3695. return;
  3696. }
  3697. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3698. this.#pagesRefCache.set(refStr, pageNum);
  3699. }
  3700. _cachedPageNumber(pageRef) {
  3701. if (!pageRef) {
  3702. return null;
  3703. }
  3704. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3705. return this.#pagesRefCache.get(refStr) || null;
  3706. }
  3707. static #isValidExplicitDestination(dest) {
  3708. if (!Array.isArray(dest)) {
  3709. return false;
  3710. }
  3711. const destLength = dest.length;
  3712. if (destLength < 2) {
  3713. return false;
  3714. }
  3715. const page = dest[0];
  3716. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  3717. return false;
  3718. }
  3719. const zoom = dest[1];
  3720. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  3721. return false;
  3722. }
  3723. let allowNull = true;
  3724. switch (zoom.name) {
  3725. case "XYZ":
  3726. if (destLength !== 5) {
  3727. return false;
  3728. }
  3729. break;
  3730. case "Fit":
  3731. case "FitB":
  3732. return destLength === 2;
  3733. case "FitH":
  3734. case "FitBH":
  3735. case "FitV":
  3736. case "FitBV":
  3737. if (destLength !== 3) {
  3738. return false;
  3739. }
  3740. break;
  3741. case "FitR":
  3742. if (destLength !== 6) {
  3743. return false;
  3744. }
  3745. allowNull = false;
  3746. break;
  3747. default:
  3748. return false;
  3749. }
  3750. for (let i = 2; i < destLength; i++) {
  3751. const param = dest[i];
  3752. if (!(typeof param === "number" || allowNull && param === null)) {
  3753. return false;
  3754. }
  3755. }
  3756. return true;
  3757. }
  3758. }
  3759. exports.PDFLinkService = PDFLinkService;
  3760. class SimpleLinkService {
  3761. constructor() {
  3762. this.externalLinkEnabled = true;
  3763. }
  3764. get pagesCount() {
  3765. return 0;
  3766. }
  3767. get page() {
  3768. return 0;
  3769. }
  3770. set page(value) {}
  3771. get rotation() {
  3772. return 0;
  3773. }
  3774. set rotation(value) {}
  3775. get isInPresentationMode() {
  3776. return false;
  3777. }
  3778. async goToDestination(dest) {}
  3779. goToPage(val) {}
  3780. addLinkAttributes(link, url, newWindow = false) {
  3781. addLinkAttributes(link, {
  3782. url,
  3783. enabled: this.externalLinkEnabled
  3784. });
  3785. }
  3786. getDestinationHash(dest) {
  3787. return "#";
  3788. }
  3789. getAnchorUrl(hash) {
  3790. return "#";
  3791. }
  3792. setHash(hash) {}
  3793. executeNamedAction(action) {}
  3794. executeSetOCGState(action) {}
  3795. cachePageRef(pageNum, pageRef) {}
  3796. }
  3797. exports.SimpleLinkService = SimpleLinkService;
  3798. /***/ }),
  3799. /* 8 */
  3800. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3801. Object.defineProperty(exports, "__esModule", ({
  3802. value: true
  3803. }));
  3804. exports.AnnotationEditorParams = void 0;
  3805. var _pdfjsLib = __webpack_require__(4);
  3806. class AnnotationEditorParams {
  3807. constructor(options, eventBus) {
  3808. this.eventBus = eventBus;
  3809. this.#bindListeners(options);
  3810. }
  3811. #bindListeners({
  3812. editorFreeTextFontSize,
  3813. editorFreeTextColor,
  3814. editorInkColor,
  3815. editorInkThickness,
  3816. editorInkOpacity,
  3817. editorStampAddImage
  3818. }) {
  3819. const dispatchEvent = (typeStr, value) => {
  3820. this.eventBus.dispatch("switchannotationeditorparams", {
  3821. source: this,
  3822. type: _pdfjsLib.AnnotationEditorParamsType[typeStr],
  3823. value
  3824. });
  3825. };
  3826. editorFreeTextFontSize.addEventListener("input", function () {
  3827. dispatchEvent("FREETEXT_SIZE", this.valueAsNumber);
  3828. });
  3829. editorFreeTextColor.addEventListener("input", function () {
  3830. dispatchEvent("FREETEXT_COLOR", this.value);
  3831. });
  3832. editorInkColor.addEventListener("input", function () {
  3833. dispatchEvent("INK_COLOR", this.value);
  3834. });
  3835. editorInkThickness.addEventListener("input", function () {
  3836. dispatchEvent("INK_THICKNESS", this.valueAsNumber);
  3837. });
  3838. editorInkOpacity.addEventListener("input", function () {
  3839. dispatchEvent("INK_OPACITY", this.valueAsNumber);
  3840. });
  3841. editorStampAddImage.addEventListener("click", () => {
  3842. dispatchEvent("CREATE");
  3843. });
  3844. this.eventBus._on("annotationeditorparamschanged", evt => {
  3845. for (const [type, value] of evt.details) {
  3846. switch (type) {
  3847. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  3848. editorFreeTextFontSize.value = value;
  3849. break;
  3850. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  3851. editorFreeTextColor.value = value;
  3852. break;
  3853. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  3854. editorInkColor.value = value;
  3855. break;
  3856. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  3857. editorInkThickness.value = value;
  3858. break;
  3859. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  3860. editorInkOpacity.value = value;
  3861. break;
  3862. }
  3863. }
  3864. });
  3865. }
  3866. }
  3867. exports.AnnotationEditorParams = AnnotationEditorParams;
  3868. /***/ }),
  3869. /* 9 */
  3870. /***/ ((__unused_webpack_module, exports) => {
  3871. Object.defineProperty(exports, "__esModule", ({
  3872. value: true
  3873. }));
  3874. exports.OverlayManager = void 0;
  3875. class OverlayManager {
  3876. #overlays = new WeakMap();
  3877. #active = null;
  3878. get active() {
  3879. return this.#active;
  3880. }
  3881. async register(dialog, canForceClose = false) {
  3882. if (typeof dialog !== "object") {
  3883. throw new Error("Not enough parameters.");
  3884. } else if (this.#overlays.has(dialog)) {
  3885. throw new Error("The overlay is already registered.");
  3886. }
  3887. this.#overlays.set(dialog, {
  3888. canForceClose
  3889. });
  3890. dialog.addEventListener("cancel", evt => {
  3891. this.#active = null;
  3892. });
  3893. }
  3894. async open(dialog) {
  3895. if (!this.#overlays.has(dialog)) {
  3896. throw new Error("The overlay does not exist.");
  3897. } else if (this.#active) {
  3898. if (this.#active === dialog) {
  3899. throw new Error("The overlay is already active.");
  3900. } else if (this.#overlays.get(dialog).canForceClose) {
  3901. await this.close();
  3902. } else {
  3903. throw new Error("Another overlay is currently active.");
  3904. }
  3905. }
  3906. this.#active = dialog;
  3907. dialog.showModal();
  3908. }
  3909. async close(dialog = this.#active) {
  3910. if (!this.#overlays.has(dialog)) {
  3911. throw new Error("The overlay does not exist.");
  3912. } else if (!this.#active) {
  3913. throw new Error("The overlay is currently not active.");
  3914. } else if (this.#active !== dialog) {
  3915. throw new Error("Another overlay is currently active.");
  3916. }
  3917. dialog.close();
  3918. this.#active = null;
  3919. }
  3920. }
  3921. exports.OverlayManager = OverlayManager;
  3922. /***/ }),
  3923. /* 10 */
  3924. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3925. Object.defineProperty(exports, "__esModule", ({
  3926. value: true
  3927. }));
  3928. exports.PasswordPrompt = void 0;
  3929. var _pdfjsLib = __webpack_require__(4);
  3930. class PasswordPrompt {
  3931. #activeCapability = null;
  3932. #updateCallback = null;
  3933. #reason = null;
  3934. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3935. this.dialog = options.dialog;
  3936. this.label = options.label;
  3937. this.input = options.input;
  3938. this.submitButton = options.submitButton;
  3939. this.cancelButton = options.cancelButton;
  3940. this.overlayManager = overlayManager;
  3941. this.l10n = l10n;
  3942. this._isViewerEmbedded = isViewerEmbedded;
  3943. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3944. this.cancelButton.addEventListener("click", this.close.bind(this));
  3945. this.input.addEventListener("keydown", e => {
  3946. if (e.keyCode === 13) {
  3947. this.#verify();
  3948. }
  3949. });
  3950. this.overlayManager.register(this.dialog, true);
  3951. this.dialog.addEventListener("close", this.#cancel.bind(this));
  3952. }
  3953. async open() {
  3954. if (this.#activeCapability) {
  3955. await this.#activeCapability.promise;
  3956. }
  3957. this.#activeCapability = new _pdfjsLib.PromiseCapability();
  3958. try {
  3959. await this.overlayManager.open(this.dialog);
  3960. } catch (ex) {
  3961. this.#activeCapability.resolve();
  3962. throw ex;
  3963. }
  3964. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3965. if (!this._isViewerEmbedded || passwordIncorrect) {
  3966. this.input.focus();
  3967. }
  3968. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3969. }
  3970. async close() {
  3971. if (this.overlayManager.active === this.dialog) {
  3972. this.overlayManager.close(this.dialog);
  3973. }
  3974. }
  3975. #verify() {
  3976. const password = this.input.value;
  3977. if (password?.length > 0) {
  3978. this.#invokeCallback(password);
  3979. }
  3980. }
  3981. #cancel() {
  3982. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  3983. this.#activeCapability.resolve();
  3984. }
  3985. #invokeCallback(password) {
  3986. if (!this.#updateCallback) {
  3987. return;
  3988. }
  3989. this.close();
  3990. this.input.value = "";
  3991. this.#updateCallback(password);
  3992. this.#updateCallback = null;
  3993. }
  3994. async setUpdateCallback(updateCallback, reason) {
  3995. if (this.#activeCapability) {
  3996. await this.#activeCapability.promise;
  3997. }
  3998. this.#updateCallback = updateCallback;
  3999. this.#reason = reason;
  4000. }
  4001. }
  4002. exports.PasswordPrompt = PasswordPrompt;
  4003. /***/ }),
  4004. /* 11 */
  4005. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4006. Object.defineProperty(exports, "__esModule", ({
  4007. value: true
  4008. }));
  4009. exports.PDFAttachmentViewer = void 0;
  4010. var _pdfjsLib = __webpack_require__(4);
  4011. var _base_tree_viewer = __webpack_require__(12);
  4012. var _event_utils = __webpack_require__(6);
  4013. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4014. constructor(options) {
  4015. super(options);
  4016. this.downloadManager = options.downloadManager;
  4017. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  4018. }
  4019. reset(keepRenderedCapability = false) {
  4020. super.reset();
  4021. this._attachments = null;
  4022. if (!keepRenderedCapability) {
  4023. this._renderedCapability = new _pdfjsLib.PromiseCapability();
  4024. }
  4025. this._pendingDispatchEvent = false;
  4026. }
  4027. async _dispatchEvent(attachmentsCount) {
  4028. this._renderedCapability.resolve();
  4029. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4030. this._pendingDispatchEvent = true;
  4031. await (0, _event_utils.waitOnEventOrTimeout)({
  4032. target: this.eventBus,
  4033. name: "annotationlayerrendered",
  4034. delay: 1000
  4035. });
  4036. if (!this._pendingDispatchEvent) {
  4037. return;
  4038. }
  4039. }
  4040. this._pendingDispatchEvent = false;
  4041. this.eventBus.dispatch("attachmentsloaded", {
  4042. source: this,
  4043. attachmentsCount
  4044. });
  4045. }
  4046. _bindLink(element, {
  4047. content,
  4048. filename
  4049. }) {
  4050. element.onclick = () => {
  4051. this.downloadManager.openOrDownloadData(element, content, filename);
  4052. return false;
  4053. };
  4054. }
  4055. render({
  4056. attachments,
  4057. keepRenderedCapability = false
  4058. }) {
  4059. if (this._attachments) {
  4060. this.reset(keepRenderedCapability);
  4061. }
  4062. this._attachments = attachments || null;
  4063. if (!attachments) {
  4064. this._dispatchEvent(0);
  4065. return;
  4066. }
  4067. const fragment = document.createDocumentFragment();
  4068. let attachmentsCount = 0;
  4069. for (const name in attachments) {
  4070. const item = attachments[name];
  4071. const content = item.content,
  4072. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true);
  4073. const div = document.createElement("div");
  4074. div.className = "treeItem";
  4075. const element = document.createElement("a");
  4076. this._bindLink(element, {
  4077. content,
  4078. filename
  4079. });
  4080. element.textContent = this._normalizeTextContent(filename);
  4081. div.append(element);
  4082. fragment.append(div);
  4083. attachmentsCount++;
  4084. }
  4085. this._finishRendering(fragment, attachmentsCount);
  4086. }
  4087. #appendAttachment({
  4088. filename,
  4089. content
  4090. }) {
  4091. const renderedPromise = this._renderedCapability.promise;
  4092. renderedPromise.then(() => {
  4093. if (renderedPromise !== this._renderedCapability.promise) {
  4094. return;
  4095. }
  4096. const attachments = this._attachments || Object.create(null);
  4097. for (const name in attachments) {
  4098. if (filename === name) {
  4099. return;
  4100. }
  4101. }
  4102. attachments[filename] = {
  4103. filename,
  4104. content
  4105. };
  4106. this.render({
  4107. attachments,
  4108. keepRenderedCapability: true
  4109. });
  4110. });
  4111. }
  4112. }
  4113. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4114. /***/ }),
  4115. /* 12 */
  4116. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4117. Object.defineProperty(exports, "__esModule", ({
  4118. value: true
  4119. }));
  4120. exports.BaseTreeViewer = void 0;
  4121. var _ui_utils = __webpack_require__(3);
  4122. const TREEITEM_OFFSET_TOP = -100;
  4123. const TREEITEM_SELECTED_CLASS = "selected";
  4124. class BaseTreeViewer {
  4125. constructor(options) {
  4126. if (this.constructor === BaseTreeViewer) {
  4127. throw new Error("Cannot initialize BaseTreeViewer.");
  4128. }
  4129. this.container = options.container;
  4130. this.eventBus = options.eventBus;
  4131. this.reset();
  4132. }
  4133. reset() {
  4134. this._pdfDocument = null;
  4135. this._lastToggleIsShow = true;
  4136. this._currentTreeItem = null;
  4137. this.container.textContent = "";
  4138. this.container.classList.remove("treeWithDeepNesting");
  4139. }
  4140. _dispatchEvent(count) {
  4141. throw new Error("Not implemented: _dispatchEvent");
  4142. }
  4143. _bindLink(element, params) {
  4144. throw new Error("Not implemented: _bindLink");
  4145. }
  4146. _normalizeTextContent(str) {
  4147. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4148. }
  4149. _addToggleButton(div, hidden = false) {
  4150. const toggler = document.createElement("div");
  4151. toggler.className = "treeItemToggler";
  4152. if (hidden) {
  4153. toggler.classList.add("treeItemsHidden");
  4154. }
  4155. toggler.onclick = evt => {
  4156. evt.stopPropagation();
  4157. toggler.classList.toggle("treeItemsHidden");
  4158. if (evt.shiftKey) {
  4159. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4160. this._toggleTreeItem(div, shouldShowAll);
  4161. }
  4162. };
  4163. div.prepend(toggler);
  4164. }
  4165. _toggleTreeItem(root, show = false) {
  4166. this._lastToggleIsShow = show;
  4167. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4168. toggler.classList.toggle("treeItemsHidden", !show);
  4169. }
  4170. }
  4171. _toggleAllTreeItems() {
  4172. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4173. }
  4174. _finishRendering(fragment, count, hasAnyNesting = false) {
  4175. if (hasAnyNesting) {
  4176. this.container.classList.add("treeWithDeepNesting");
  4177. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4178. }
  4179. this.container.append(fragment);
  4180. this._dispatchEvent(count);
  4181. }
  4182. render(params) {
  4183. throw new Error("Not implemented: render");
  4184. }
  4185. _updateCurrentTreeItem(treeItem = null) {
  4186. if (this._currentTreeItem) {
  4187. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4188. this._currentTreeItem = null;
  4189. }
  4190. if (treeItem) {
  4191. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4192. this._currentTreeItem = treeItem;
  4193. }
  4194. }
  4195. _scrollToCurrentTreeItem(treeItem) {
  4196. if (!treeItem) {
  4197. return;
  4198. }
  4199. let currentNode = treeItem.parentNode;
  4200. while (currentNode && currentNode !== this.container) {
  4201. if (currentNode.classList.contains("treeItem")) {
  4202. const toggler = currentNode.firstElementChild;
  4203. toggler?.classList.remove("treeItemsHidden");
  4204. }
  4205. currentNode = currentNode.parentNode;
  4206. }
  4207. this._updateCurrentTreeItem(treeItem);
  4208. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4209. }
  4210. }
  4211. exports.BaseTreeViewer = BaseTreeViewer;
  4212. /***/ }),
  4213. /* 13 */
  4214. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4215. Object.defineProperty(exports, "__esModule", ({
  4216. value: true
  4217. }));
  4218. exports.PDFCursorTools = void 0;
  4219. var _pdfjsLib = __webpack_require__(4);
  4220. var _ui_utils = __webpack_require__(3);
  4221. var _grab_to_pan = __webpack_require__(14);
  4222. class PDFCursorTools {
  4223. #active = _ui_utils.CursorTool.SELECT;
  4224. #prevActive = null;
  4225. constructor({
  4226. container,
  4227. eventBus,
  4228. cursorToolOnLoad = _ui_utils.CursorTool.SELECT
  4229. }) {
  4230. this.container = container;
  4231. this.eventBus = eventBus;
  4232. this.#addEventListeners();
  4233. Promise.resolve().then(() => {
  4234. this.switchTool(cursorToolOnLoad);
  4235. });
  4236. }
  4237. get activeTool() {
  4238. return this.#active;
  4239. }
  4240. switchTool(tool) {
  4241. if (this.#prevActive !== null) {
  4242. return;
  4243. }
  4244. if (tool === this.#active) {
  4245. return;
  4246. }
  4247. const disableActiveTool = () => {
  4248. switch (this.#active) {
  4249. case _ui_utils.CursorTool.SELECT:
  4250. break;
  4251. case _ui_utils.CursorTool.HAND:
  4252. this._handTool.deactivate();
  4253. break;
  4254. case _ui_utils.CursorTool.ZOOM:
  4255. }
  4256. };
  4257. switch (tool) {
  4258. case _ui_utils.CursorTool.SELECT:
  4259. disableActiveTool();
  4260. break;
  4261. case _ui_utils.CursorTool.HAND:
  4262. disableActiveTool();
  4263. this._handTool.activate();
  4264. break;
  4265. case _ui_utils.CursorTool.ZOOM:
  4266. default:
  4267. console.error(`switchTool: "${tool}" is an unsupported value.`);
  4268. return;
  4269. }
  4270. this.#active = tool;
  4271. this.eventBus.dispatch("cursortoolchanged", {
  4272. source: this,
  4273. tool
  4274. });
  4275. }
  4276. #addEventListeners() {
  4277. this.eventBus._on("switchcursortool", evt => {
  4278. this.switchTool(evt.tool);
  4279. });
  4280. let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
  4281. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  4282. const disableActive = () => {
  4283. const prevActive = this.#active;
  4284. this.switchTool(_ui_utils.CursorTool.SELECT);
  4285. this.#prevActive ??= prevActive;
  4286. };
  4287. const enableActive = () => {
  4288. const prevActive = this.#prevActive;
  4289. if (prevActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) {
  4290. this.#prevActive = null;
  4291. this.switchTool(prevActive);
  4292. }
  4293. };
  4294. this.eventBus._on("secondarytoolbarreset", evt => {
  4295. if (this.#prevActive !== null) {
  4296. annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  4297. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  4298. enableActive();
  4299. }
  4300. });
  4301. this.eventBus._on("annotationeditormodechanged", ({
  4302. mode
  4303. }) => {
  4304. annotationEditorMode = mode;
  4305. if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
  4306. enableActive();
  4307. } else {
  4308. disableActive();
  4309. }
  4310. });
  4311. this.eventBus._on("presentationmodechanged", ({
  4312. state
  4313. }) => {
  4314. presentationModeState = state;
  4315. if (state === _ui_utils.PresentationModeState.NORMAL) {
  4316. enableActive();
  4317. } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
  4318. disableActive();
  4319. }
  4320. });
  4321. }
  4322. get _handTool() {
  4323. return (0, _pdfjsLib.shadow)(this, "_handTool", new _grab_to_pan.GrabToPan({
  4324. element: this.container
  4325. }));
  4326. }
  4327. }
  4328. exports.PDFCursorTools = PDFCursorTools;
  4329. /***/ }),
  4330. /* 14 */
  4331. /***/ ((__unused_webpack_module, exports) => {
  4332. Object.defineProperty(exports, "__esModule", ({
  4333. value: true
  4334. }));
  4335. exports.GrabToPan = void 0;
  4336. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  4337. class GrabToPan {
  4338. constructor({
  4339. element
  4340. }) {
  4341. this.element = element;
  4342. this.document = element.ownerDocument;
  4343. this.activate = this.activate.bind(this);
  4344. this.deactivate = this.deactivate.bind(this);
  4345. this.toggle = this.toggle.bind(this);
  4346. this._onMouseDown = this.#onMouseDown.bind(this);
  4347. this._onMouseMove = this.#onMouseMove.bind(this);
  4348. this._endPan = this.#endPan.bind(this);
  4349. const overlay = this.overlay = document.createElement("div");
  4350. overlay.className = "grab-to-pan-grabbing";
  4351. }
  4352. activate() {
  4353. if (!this.active) {
  4354. this.active = true;
  4355. this.element.addEventListener("mousedown", this._onMouseDown, true);
  4356. this.element.classList.add(CSS_CLASS_GRAB);
  4357. }
  4358. }
  4359. deactivate() {
  4360. if (this.active) {
  4361. this.active = false;
  4362. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  4363. this._endPan();
  4364. this.element.classList.remove(CSS_CLASS_GRAB);
  4365. }
  4366. }
  4367. toggle() {
  4368. if (this.active) {
  4369. this.deactivate();
  4370. } else {
  4371. this.activate();
  4372. }
  4373. }
  4374. ignoreTarget(node) {
  4375. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  4376. }
  4377. #onMouseDown(event) {
  4378. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  4379. return;
  4380. }
  4381. if (event.originalTarget) {
  4382. try {
  4383. event.originalTarget.tagName;
  4384. } catch {
  4385. return;
  4386. }
  4387. }
  4388. this.scrollLeftStart = this.element.scrollLeft;
  4389. this.scrollTopStart = this.element.scrollTop;
  4390. this.clientXStart = event.clientX;
  4391. this.clientYStart = event.clientY;
  4392. this.document.addEventListener("mousemove", this._onMouseMove, true);
  4393. this.document.addEventListener("mouseup", this._endPan, true);
  4394. this.element.addEventListener("scroll", this._endPan, true);
  4395. event.preventDefault();
  4396. event.stopPropagation();
  4397. const focusedElement = document.activeElement;
  4398. if (focusedElement && !focusedElement.contains(event.target)) {
  4399. focusedElement.blur();
  4400. }
  4401. }
  4402. #onMouseMove(event) {
  4403. this.element.removeEventListener("scroll", this._endPan, true);
  4404. if (!(event.buttons & 1)) {
  4405. this._endPan();
  4406. return;
  4407. }
  4408. const xDiff = event.clientX - this.clientXStart;
  4409. const yDiff = event.clientY - this.clientYStart;
  4410. this.element.scrollTo({
  4411. top: this.scrollTopStart - yDiff,
  4412. left: this.scrollLeftStart - xDiff,
  4413. behavior: "instant"
  4414. });
  4415. if (!this.overlay.parentNode) {
  4416. document.body.append(this.overlay);
  4417. }
  4418. }
  4419. #endPan() {
  4420. this.element.removeEventListener("scroll", this._endPan, true);
  4421. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  4422. this.document.removeEventListener("mouseup", this._endPan, true);
  4423. this.overlay.remove();
  4424. }
  4425. }
  4426. exports.GrabToPan = GrabToPan;
  4427. /***/ }),
  4428. /* 15 */
  4429. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4430. Object.defineProperty(exports, "__esModule", ({
  4431. value: true
  4432. }));
  4433. exports.PDFDocumentProperties = void 0;
  4434. var _ui_utils = __webpack_require__(3);
  4435. var _pdfjsLib = __webpack_require__(4);
  4436. const DEFAULT_FIELD_CONTENT = "-";
  4437. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4438. const US_PAGE_NAMES = {
  4439. "8.5x11": "Letter",
  4440. "8.5x14": "Legal"
  4441. };
  4442. const METRIC_PAGE_NAMES = {
  4443. "297x420": "A3",
  4444. "210x297": "A4"
  4445. };
  4446. function getPageName(size, isPortrait, pageNames) {
  4447. const width = isPortrait ? size.width : size.height;
  4448. const height = isPortrait ? size.height : size.width;
  4449. return pageNames[`${width}x${height}`];
  4450. }
  4451. class PDFDocumentProperties {
  4452. #fieldData = null;
  4453. constructor({
  4454. dialog,
  4455. fields,
  4456. closeButton
  4457. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4458. this.dialog = dialog;
  4459. this.fields = fields;
  4460. this.overlayManager = overlayManager;
  4461. this.l10n = l10n;
  4462. this._fileNameLookup = fileNameLookup;
  4463. this.#reset();
  4464. closeButton.addEventListener("click", this.close.bind(this));
  4465. this.overlayManager.register(this.dialog);
  4466. eventBus._on("pagechanging", evt => {
  4467. this._currentPageNumber = evt.pageNumber;
  4468. });
  4469. eventBus._on("rotationchanging", evt => {
  4470. this._pagesRotation = evt.pagesRotation;
  4471. });
  4472. this._isNonMetricLocale = true;
  4473. l10n.getLanguage().then(locale => {
  4474. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4475. });
  4476. }
  4477. async open() {
  4478. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4479. const currentPageNumber = this._currentPageNumber;
  4480. const pagesRotation = this._pagesRotation;
  4481. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4482. this.#updateUI();
  4483. return;
  4484. }
  4485. const {
  4486. info,
  4487. contentLength
  4488. } = await this.pdfDocument.getMetadata();
  4489. 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 => {
  4490. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4491. }), this.#parseLinearization(info.IsLinearized)]);
  4492. this.#fieldData = Object.freeze({
  4493. fileName,
  4494. fileSize,
  4495. title: info.Title,
  4496. author: info.Author,
  4497. subject: info.Subject,
  4498. keywords: info.Keywords,
  4499. creationDate,
  4500. modificationDate,
  4501. creator: info.Creator,
  4502. producer: info.Producer,
  4503. version: info.PDFFormatVersion,
  4504. pageCount: this.pdfDocument.numPages,
  4505. pageSize,
  4506. linearized: isLinearized,
  4507. _currentPageNumber: currentPageNumber,
  4508. _pagesRotation: pagesRotation
  4509. });
  4510. this.#updateUI();
  4511. const {
  4512. length
  4513. } = await this.pdfDocument.getDownloadInfo();
  4514. if (contentLength === length) {
  4515. return;
  4516. }
  4517. const data = Object.assign(Object.create(null), this.#fieldData);
  4518. data.fileSize = await this.#parseFileSize(length);
  4519. this.#fieldData = Object.freeze(data);
  4520. this.#updateUI();
  4521. }
  4522. async close() {
  4523. this.overlayManager.close(this.dialog);
  4524. }
  4525. setDocument(pdfDocument) {
  4526. if (this.pdfDocument) {
  4527. this.#reset();
  4528. this.#updateUI(true);
  4529. }
  4530. if (!pdfDocument) {
  4531. return;
  4532. }
  4533. this.pdfDocument = pdfDocument;
  4534. this._dataAvailableCapability.resolve();
  4535. }
  4536. #reset() {
  4537. this.pdfDocument = null;
  4538. this.#fieldData = null;
  4539. this._dataAvailableCapability = new _pdfjsLib.PromiseCapability();
  4540. this._currentPageNumber = 1;
  4541. this._pagesRotation = 0;
  4542. }
  4543. #updateUI(reset = false) {
  4544. if (reset || !this.#fieldData) {
  4545. for (const id in this.fields) {
  4546. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4547. }
  4548. return;
  4549. }
  4550. if (this.overlayManager.active !== this.dialog) {
  4551. return;
  4552. }
  4553. for (const id in this.fields) {
  4554. const content = this.#fieldData[id];
  4555. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4556. }
  4557. }
  4558. async #parseFileSize(fileSize = 0) {
  4559. const kb = fileSize / 1024,
  4560. mb = kb / 1024;
  4561. if (!kb) {
  4562. return undefined;
  4563. }
  4564. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4565. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4566. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4567. size_b: fileSize.toLocaleString()
  4568. });
  4569. }
  4570. async #parsePageSize(pageSizeInches, pagesRotation) {
  4571. if (!pageSizeInches) {
  4572. return undefined;
  4573. }
  4574. if (pagesRotation % 180 !== 0) {
  4575. pageSizeInches = {
  4576. width: pageSizeInches.height,
  4577. height: pageSizeInches.width
  4578. };
  4579. }
  4580. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4581. let sizeInches = {
  4582. width: Math.round(pageSizeInches.width * 100) / 100,
  4583. height: Math.round(pageSizeInches.height * 100) / 100
  4584. };
  4585. let sizeMillimeters = {
  4586. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4587. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4588. };
  4589. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4590. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4591. const exactMillimeters = {
  4592. width: pageSizeInches.width * 25.4,
  4593. height: pageSizeInches.height * 25.4
  4594. };
  4595. const intMillimeters = {
  4596. width: Math.round(sizeMillimeters.width),
  4597. height: Math.round(sizeMillimeters.height)
  4598. };
  4599. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4600. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4601. if (rawName) {
  4602. sizeInches = {
  4603. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4604. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4605. };
  4606. sizeMillimeters = intMillimeters;
  4607. }
  4608. }
  4609. }
  4610. const [{
  4611. width,
  4612. height
  4613. }, 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"}`)]);
  4614. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4615. width: width.toLocaleString(),
  4616. height: height.toLocaleString(),
  4617. unit,
  4618. name,
  4619. orientation
  4620. });
  4621. }
  4622. async #parseDate(inputDate) {
  4623. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4624. if (!dateObject) {
  4625. return undefined;
  4626. }
  4627. return this.l10n.get("document_properties_date_string", {
  4628. date: dateObject.toLocaleDateString(),
  4629. time: dateObject.toLocaleTimeString()
  4630. });
  4631. }
  4632. #parseLinearization(isLinearized) {
  4633. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4634. }
  4635. }
  4636. exports.PDFDocumentProperties = PDFDocumentProperties;
  4637. /***/ }),
  4638. /* 16 */
  4639. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4640. Object.defineProperty(exports, "__esModule", ({
  4641. value: true
  4642. }));
  4643. exports.PDFFindBar = void 0;
  4644. var _pdf_find_controller = __webpack_require__(17);
  4645. var _ui_utils = __webpack_require__(3);
  4646. const MATCHES_COUNT_LIMIT = 1000;
  4647. class PDFFindBar {
  4648. constructor(options, eventBus, l10n) {
  4649. this.opened = false;
  4650. this.bar = options.bar;
  4651. this.toggleButton = options.toggleButton;
  4652. this.findField = options.findField;
  4653. this.highlightAll = options.highlightAllCheckbox;
  4654. this.caseSensitive = options.caseSensitiveCheckbox;
  4655. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4656. this.entireWord = options.entireWordCheckbox;
  4657. this.findMsg = options.findMsg;
  4658. this.findResultsCount = options.findResultsCount;
  4659. this.findPreviousButton = options.findPreviousButton;
  4660. this.findNextButton = options.findNextButton;
  4661. this.eventBus = eventBus;
  4662. this.l10n = l10n;
  4663. this.toggleButton.addEventListener("click", () => {
  4664. this.toggle();
  4665. });
  4666. this.findField.addEventListener("input", () => {
  4667. this.dispatchEvent("");
  4668. });
  4669. this.bar.addEventListener("keydown", e => {
  4670. switch (e.keyCode) {
  4671. case 13:
  4672. if (e.target === this.findField) {
  4673. this.dispatchEvent("again", e.shiftKey);
  4674. }
  4675. break;
  4676. case 27:
  4677. this.close();
  4678. break;
  4679. }
  4680. });
  4681. this.findPreviousButton.addEventListener("click", () => {
  4682. this.dispatchEvent("again", true);
  4683. });
  4684. this.findNextButton.addEventListener("click", () => {
  4685. this.dispatchEvent("again", false);
  4686. });
  4687. this.highlightAll.addEventListener("click", () => {
  4688. this.dispatchEvent("highlightallchange");
  4689. });
  4690. this.caseSensitive.addEventListener("click", () => {
  4691. this.dispatchEvent("casesensitivitychange");
  4692. });
  4693. this.entireWord.addEventListener("click", () => {
  4694. this.dispatchEvent("entirewordchange");
  4695. });
  4696. this.matchDiacritics.addEventListener("click", () => {
  4697. this.dispatchEvent("diacriticmatchingchange");
  4698. });
  4699. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4700. }
  4701. reset() {
  4702. this.updateUIState();
  4703. }
  4704. dispatchEvent(type, findPrev = false) {
  4705. this.eventBus.dispatch("find", {
  4706. source: this,
  4707. type,
  4708. query: this.findField.value,
  4709. caseSensitive: this.caseSensitive.checked,
  4710. entireWord: this.entireWord.checked,
  4711. highlightAll: this.highlightAll.checked,
  4712. findPrevious: findPrev,
  4713. matchDiacritics: this.matchDiacritics.checked
  4714. });
  4715. }
  4716. updateUIState(state, previous, matchesCount) {
  4717. let findMsg = Promise.resolve("");
  4718. let status = "";
  4719. switch (state) {
  4720. case _pdf_find_controller.FindState.FOUND:
  4721. break;
  4722. case _pdf_find_controller.FindState.PENDING:
  4723. status = "pending";
  4724. break;
  4725. case _pdf_find_controller.FindState.NOT_FOUND:
  4726. findMsg = this.l10n.get("find_not_found");
  4727. status = "notFound";
  4728. break;
  4729. case _pdf_find_controller.FindState.WRAPPED:
  4730. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4731. break;
  4732. }
  4733. this.findField.setAttribute("data-status", status);
  4734. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4735. findMsg.then(msg => {
  4736. this.findMsg.setAttribute("data-status", status);
  4737. this.findMsg.textContent = msg;
  4738. this.#adjustWidth();
  4739. });
  4740. this.updateResultsCount(matchesCount);
  4741. }
  4742. updateResultsCount({
  4743. current = 0,
  4744. total = 0
  4745. } = {}) {
  4746. const limit = MATCHES_COUNT_LIMIT;
  4747. let matchCountMsg = Promise.resolve("");
  4748. if (total > 0) {
  4749. if (total > limit) {
  4750. let key = "find_match_count_limit";
  4751. matchCountMsg = this.l10n.get(key, {
  4752. limit
  4753. });
  4754. } else {
  4755. let key = "find_match_count";
  4756. matchCountMsg = this.l10n.get(key, {
  4757. current,
  4758. total
  4759. });
  4760. }
  4761. }
  4762. matchCountMsg.then(msg => {
  4763. this.findResultsCount.textContent = msg;
  4764. this.#adjustWidth();
  4765. });
  4766. }
  4767. open() {
  4768. if (!this.opened) {
  4769. this.opened = true;
  4770. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true, this.bar);
  4771. }
  4772. this.findField.select();
  4773. this.findField.focus();
  4774. this.#adjustWidth();
  4775. }
  4776. close() {
  4777. if (!this.opened) {
  4778. return;
  4779. }
  4780. this.opened = false;
  4781. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false, this.bar);
  4782. this.eventBus.dispatch("findbarclose", {
  4783. source: this
  4784. });
  4785. }
  4786. toggle() {
  4787. if (this.opened) {
  4788. this.close();
  4789. } else {
  4790. this.open();
  4791. }
  4792. }
  4793. #adjustWidth() {
  4794. if (!this.opened) {
  4795. return;
  4796. }
  4797. this.bar.classList.remove("wrapContainers");
  4798. const findbarHeight = this.bar.clientHeight;
  4799. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4800. if (findbarHeight > inputContainerHeight) {
  4801. this.bar.classList.add("wrapContainers");
  4802. }
  4803. }
  4804. }
  4805. exports.PDFFindBar = PDFFindBar;
  4806. /***/ }),
  4807. /* 17 */
  4808. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4809. Object.defineProperty(exports, "__esModule", ({
  4810. value: true
  4811. }));
  4812. exports.PDFFindController = exports.FindState = void 0;
  4813. var _ui_utils = __webpack_require__(3);
  4814. var _pdf_find_utils = __webpack_require__(18);
  4815. var _pdfjsLib = __webpack_require__(4);
  4816. const FindState = {
  4817. FOUND: 0,
  4818. NOT_FOUND: 1,
  4819. WRAPPED: 2,
  4820. PENDING: 3
  4821. };
  4822. exports.FindState = FindState;
  4823. const FIND_TIMEOUT = 250;
  4824. const MATCH_SCROLL_OFFSET_TOP = -50;
  4825. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4826. const CHARACTERS_TO_NORMALIZE = {
  4827. "\u2010": "-",
  4828. "\u2018": "'",
  4829. "\u2019": "'",
  4830. "\u201A": "'",
  4831. "\u201B": "'",
  4832. "\u201C": '"',
  4833. "\u201D": '"',
  4834. "\u201E": '"',
  4835. "\u201F": '"',
  4836. "\u00BC": "1/4",
  4837. "\u00BD": "1/2",
  4838. "\u00BE": "3/4"
  4839. };
  4840. 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]);
  4841. let DIACRITICS_EXCEPTION_STR;
  4842. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4843. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4844. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4845. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4846. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4847. const SYLLABLES_LENGTHS = new Map();
  4848. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4849. const NFKC_CHARS_TO_NORMALIZE = new Map();
  4850. let noSyllablesRegExp = null;
  4851. let withSyllablesRegExp = null;
  4852. function normalize(text) {
  4853. const syllablePositions = [];
  4854. let m;
  4855. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4856. let {
  4857. index
  4858. } = m;
  4859. for (const char of m[0]) {
  4860. let len = SYLLABLES_LENGTHS.get(char);
  4861. if (!len) {
  4862. len = char.normalize("NFD").length;
  4863. SYLLABLES_LENGTHS.set(char, len);
  4864. }
  4865. syllablePositions.push([len, index++]);
  4866. }
  4867. }
  4868. let normalizationRegex;
  4869. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4870. normalizationRegex = noSyllablesRegExp;
  4871. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4872. normalizationRegex = withSyllablesRegExp;
  4873. } else {
  4874. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4875. const toNormalizeWithNFKC = (0, _pdf_find_utils.getNormalizeWithNFKC)();
  4876. const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
  4877. const HKDiacritics = "(?:\u3099|\u309A)";
  4878. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(${HKDiacritics}\\n)|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
  4879. if (syllablePositions.length === 0) {
  4880. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4881. } else {
  4882. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4883. }
  4884. }
  4885. const rawDiacriticsPositions = [];
  4886. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4887. rawDiacriticsPositions.push([m[0].length, m.index]);
  4888. }
  4889. let normalized = text.normalize("NFD");
  4890. const positions = [[0, 0]];
  4891. let rawDiacriticsIndex = 0;
  4892. let syllableIndex = 0;
  4893. let shift = 0;
  4894. let shiftOrigin = 0;
  4895. let eol = 0;
  4896. let hasDiacritics = false;
  4897. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, p8, i) => {
  4898. i -= shiftOrigin;
  4899. if (p1) {
  4900. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  4901. const jj = replacement.length;
  4902. for (let j = 1; j < jj; j++) {
  4903. positions.push([i - shift + j, shift - j]);
  4904. }
  4905. shift -= jj - 1;
  4906. return replacement;
  4907. }
  4908. if (p2) {
  4909. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  4910. if (!replacement) {
  4911. replacement = p2.normalize("NFKC");
  4912. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  4913. }
  4914. const jj = replacement.length;
  4915. for (let j = 1; j < jj; j++) {
  4916. positions.push([i - shift + j, shift - j]);
  4917. }
  4918. shift -= jj - 1;
  4919. return replacement;
  4920. }
  4921. if (p3) {
  4922. hasDiacritics = true;
  4923. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4924. ++rawDiacriticsIndex;
  4925. } else {
  4926. positions.push([i - 1 - shift + 1, shift - 1]);
  4927. shift -= 1;
  4928. shiftOrigin += 1;
  4929. }
  4930. positions.push([i - shift + 1, shift]);
  4931. shiftOrigin += 1;
  4932. eol += 1;
  4933. return p3.charAt(0);
  4934. }
  4935. if (p4) {
  4936. const hasTrailingDashEOL = p4.endsWith("\n");
  4937. const len = hasTrailingDashEOL ? p4.length - 2 : p4.length;
  4938. hasDiacritics = true;
  4939. let jj = len;
  4940. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4941. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4942. ++rawDiacriticsIndex;
  4943. }
  4944. for (let j = 1; j <= jj; j++) {
  4945. positions.push([i - 1 - shift + j, shift - j]);
  4946. }
  4947. shift -= jj;
  4948. shiftOrigin += jj;
  4949. if (hasTrailingDashEOL) {
  4950. i += len - 1;
  4951. positions.push([i - shift + 1, 1 + shift]);
  4952. shift += 1;
  4953. shiftOrigin += 1;
  4954. eol += 1;
  4955. return p4.slice(0, len);
  4956. }
  4957. return p4;
  4958. }
  4959. if (p5) {
  4960. const len = p5.length - 2;
  4961. positions.push([i - shift + len, 1 + shift]);
  4962. shift += 1;
  4963. shiftOrigin += 1;
  4964. eol += 1;
  4965. return p5.slice(0, -2);
  4966. }
  4967. if (p6) {
  4968. const len = p6.length - 1;
  4969. positions.push([i - shift + len, shift]);
  4970. shiftOrigin += 1;
  4971. eol += 1;
  4972. return p6.slice(0, -1);
  4973. }
  4974. if (p7) {
  4975. positions.push([i - shift + 1, shift - 1]);
  4976. shift -= 1;
  4977. shiftOrigin += 1;
  4978. eol += 1;
  4979. return " ";
  4980. }
  4981. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  4982. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  4983. ++syllableIndex;
  4984. for (let j = 1; j <= newCharLen; j++) {
  4985. positions.push([i - (shift - j), shift - j]);
  4986. }
  4987. shift -= newCharLen;
  4988. shiftOrigin += newCharLen;
  4989. }
  4990. return p8;
  4991. });
  4992. positions.push([normalized.length, shift]);
  4993. return [normalized, positions, hasDiacritics];
  4994. }
  4995. function getOriginalIndex(diffs, pos, len) {
  4996. if (!diffs) {
  4997. return [pos, len];
  4998. }
  4999. const start = pos;
  5000. const end = pos + len - 1;
  5001. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  5002. if (diffs[i][0] > start) {
  5003. --i;
  5004. }
  5005. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  5006. if (diffs[j][0] > end) {
  5007. --j;
  5008. }
  5009. const oldStart = start + diffs[i][1];
  5010. const oldEnd = end + diffs[j][1];
  5011. const oldLen = oldEnd + 1 - oldStart;
  5012. return [oldStart, oldLen];
  5013. }
  5014. class PDFFindController {
  5015. #state = null;
  5016. #updateMatchesCountOnProgress = true;
  5017. #visitedPagesCount = 0;
  5018. constructor({
  5019. linkService,
  5020. eventBus,
  5021. updateMatchesCountOnProgress = true
  5022. }) {
  5023. this._linkService = linkService;
  5024. this._eventBus = eventBus;
  5025. this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
  5026. this.onIsPageVisible = null;
  5027. this.#reset();
  5028. eventBus._on("find", this.#onFind.bind(this));
  5029. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  5030. }
  5031. get highlightMatches() {
  5032. return this._highlightMatches;
  5033. }
  5034. get pageMatches() {
  5035. return this._pageMatches;
  5036. }
  5037. get pageMatchesLength() {
  5038. return this._pageMatchesLength;
  5039. }
  5040. get selected() {
  5041. return this._selected;
  5042. }
  5043. get state() {
  5044. return this.#state;
  5045. }
  5046. setDocument(pdfDocument) {
  5047. if (this._pdfDocument) {
  5048. this.#reset();
  5049. }
  5050. if (!pdfDocument) {
  5051. return;
  5052. }
  5053. this._pdfDocument = pdfDocument;
  5054. this._firstPageCapability.resolve();
  5055. }
  5056. #onFind(state) {
  5057. if (!state) {
  5058. return;
  5059. }
  5060. if (state.phraseSearch === false) {
  5061. console.error("The `phraseSearch`-parameter was removed, please provide " + "an Array of strings in the `query`-parameter instead.");
  5062. if (typeof state.query === "string") {
  5063. state.query = state.query.match(/\S+/g);
  5064. }
  5065. }
  5066. const pdfDocument = this._pdfDocument;
  5067. const {
  5068. type
  5069. } = state;
  5070. if (this.#state === null || this.#shouldDirtyMatch(state)) {
  5071. this._dirtyMatch = true;
  5072. }
  5073. this.#state = state;
  5074. if (type !== "highlightallchange") {
  5075. this.#updateUIState(FindState.PENDING);
  5076. }
  5077. this._firstPageCapability.promise.then(() => {
  5078. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5079. return;
  5080. }
  5081. this.#extractText();
  5082. const findbarClosed = !this._highlightMatches;
  5083. const pendingTimeout = !!this._findTimeout;
  5084. if (this._findTimeout) {
  5085. clearTimeout(this._findTimeout);
  5086. this._findTimeout = null;
  5087. }
  5088. if (!type) {
  5089. this._findTimeout = setTimeout(() => {
  5090. this.#nextMatch();
  5091. this._findTimeout = null;
  5092. }, FIND_TIMEOUT);
  5093. } else if (this._dirtyMatch) {
  5094. this.#nextMatch();
  5095. } else if (type === "again") {
  5096. this.#nextMatch();
  5097. if (findbarClosed && this.#state.highlightAll) {
  5098. this.#updateAllPages();
  5099. }
  5100. } else if (type === "highlightallchange") {
  5101. if (pendingTimeout) {
  5102. this.#nextMatch();
  5103. } else {
  5104. this._highlightMatches = true;
  5105. }
  5106. this.#updateAllPages();
  5107. } else {
  5108. this.#nextMatch();
  5109. }
  5110. });
  5111. }
  5112. scrollMatchIntoView({
  5113. element = null,
  5114. selectedLeft = 0,
  5115. pageIndex = -1,
  5116. matchIndex = -1
  5117. }) {
  5118. if (!this._scrollMatches || !element) {
  5119. return;
  5120. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  5121. return;
  5122. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5123. return;
  5124. }
  5125. this._scrollMatches = false;
  5126. const spot = {
  5127. top: MATCH_SCROLL_OFFSET_TOP,
  5128. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  5129. };
  5130. (0, _ui_utils.scrollIntoView)(element, spot, true);
  5131. }
  5132. #reset() {
  5133. this._highlightMatches = false;
  5134. this._scrollMatches = false;
  5135. this._pdfDocument = null;
  5136. this._pageMatches = [];
  5137. this._pageMatchesLength = [];
  5138. this.#visitedPagesCount = 0;
  5139. this.#state = null;
  5140. this._selected = {
  5141. pageIdx: -1,
  5142. matchIdx: -1
  5143. };
  5144. this._offset = {
  5145. pageIdx: null,
  5146. matchIdx: null,
  5147. wrapped: false
  5148. };
  5149. this._extractTextPromises = [];
  5150. this._pageContents = [];
  5151. this._pageDiffs = [];
  5152. this._hasDiacritics = [];
  5153. this._matchesCountTotal = 0;
  5154. this._pagesToSearch = null;
  5155. this._pendingFindMatches = new Set();
  5156. this._resumePageIdx = null;
  5157. this._dirtyMatch = false;
  5158. clearTimeout(this._findTimeout);
  5159. this._findTimeout = null;
  5160. this._firstPageCapability = new _pdfjsLib.PromiseCapability();
  5161. }
  5162. get #query() {
  5163. const {
  5164. query
  5165. } = this.#state;
  5166. if (typeof query === "string") {
  5167. if (query !== this._rawQuery) {
  5168. this._rawQuery = query;
  5169. [this._normalizedQuery] = normalize(query);
  5170. }
  5171. return this._normalizedQuery;
  5172. }
  5173. return (query || []).filter(q => !!q).map(q => normalize(q)[0]);
  5174. }
  5175. #shouldDirtyMatch(state) {
  5176. const newQuery = state.query,
  5177. prevQuery = this.#state.query;
  5178. const newType = typeof newQuery,
  5179. prevType = typeof prevQuery;
  5180. if (newType !== prevType) {
  5181. return true;
  5182. }
  5183. if (newType === "string") {
  5184. if (newQuery !== prevQuery) {
  5185. return true;
  5186. }
  5187. } else if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) {
  5188. return true;
  5189. }
  5190. switch (state.type) {
  5191. case "again":
  5192. const pageNumber = this._selected.pageIdx + 1;
  5193. const linkService = this._linkService;
  5194. return pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !(this.onIsPageVisible?.(pageNumber) ?? true);
  5195. case "highlightallchange":
  5196. return false;
  5197. }
  5198. return true;
  5199. }
  5200. #isEntireWord(content, startIdx, length) {
  5201. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  5202. if (match) {
  5203. const first = content.charCodeAt(startIdx);
  5204. const limit = match[1].charCodeAt(0);
  5205. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5206. return false;
  5207. }
  5208. }
  5209. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  5210. if (match) {
  5211. const last = content.charCodeAt(startIdx + length - 1);
  5212. const limit = match[1].charCodeAt(0);
  5213. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5214. return false;
  5215. }
  5216. }
  5217. return true;
  5218. }
  5219. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  5220. const matches = this._pageMatches[pageIndex] = [];
  5221. const matchesLength = this._pageMatchesLength[pageIndex] = [];
  5222. if (!query) {
  5223. return;
  5224. }
  5225. const diffs = this._pageDiffs[pageIndex];
  5226. let match;
  5227. while ((match = query.exec(pageContent)) !== null) {
  5228. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  5229. continue;
  5230. }
  5231. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  5232. if (matchLen) {
  5233. matches.push(matchPos);
  5234. matchesLength.push(matchLen);
  5235. }
  5236. }
  5237. }
  5238. #convertToRegExpString(query, hasDiacritics) {
  5239. const {
  5240. matchDiacritics
  5241. } = this.#state;
  5242. let isUnicode = false;
  5243. query = query.replaceAll(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5244. if (p1) {
  5245. return `[ ]*\\${p1}[ ]*`;
  5246. }
  5247. if (p2) {
  5248. return `[ ]*${p2}[ ]*`;
  5249. }
  5250. if (p3) {
  5251. return "[ ]+";
  5252. }
  5253. if (matchDiacritics) {
  5254. return p4 || p5;
  5255. }
  5256. if (p4) {
  5257. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5258. }
  5259. if (hasDiacritics) {
  5260. isUnicode = true;
  5261. return `${p5}\\p{M}*`;
  5262. }
  5263. return p5;
  5264. });
  5265. const trailingSpaces = "[ ]*";
  5266. if (query.endsWith(trailingSpaces)) {
  5267. query = query.slice(0, query.length - trailingSpaces.length);
  5268. }
  5269. if (matchDiacritics) {
  5270. if (hasDiacritics) {
  5271. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
  5272. isUnicode = true;
  5273. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5274. }
  5275. }
  5276. return [isUnicode, query];
  5277. }
  5278. #calculateMatch(pageIndex) {
  5279. let query = this.#query;
  5280. if (query.length === 0) {
  5281. return;
  5282. }
  5283. const {
  5284. caseSensitive,
  5285. entireWord
  5286. } = this.#state;
  5287. const pageContent = this._pageContents[pageIndex];
  5288. const hasDiacritics = this._hasDiacritics[pageIndex];
  5289. let isUnicode = false;
  5290. if (typeof query === "string") {
  5291. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5292. } else {
  5293. query = query.sort().reverse().map(q => {
  5294. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5295. isUnicode ||= isUnicodePart;
  5296. return `(${queryPart})`;
  5297. }).join("|");
  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. const textOptions = {
  5325. disableNormalization: true
  5326. };
  5327. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5328. const extractTextCapability = new _pdfjsLib.PromiseCapability();
  5329. this._extractTextPromises[i] = extractTextCapability.promise;
  5330. promise = promise.then(() => {
  5331. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5332. return pdfPage.getTextContent(textOptions);
  5333. }).then(textContent => {
  5334. const strBuf = [];
  5335. for (const textItem of textContent.items) {
  5336. strBuf.push(textItem.str);
  5337. if (textItem.hasEOL) {
  5338. strBuf.push("\n");
  5339. }
  5340. }
  5341. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5342. extractTextCapability.resolve();
  5343. }, reason => {
  5344. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5345. this._pageContents[i] = "";
  5346. this._pageDiffs[i] = null;
  5347. this._hasDiacritics[i] = false;
  5348. extractTextCapability.resolve();
  5349. });
  5350. });
  5351. }
  5352. }
  5353. #updatePage(index) {
  5354. if (this._scrollMatches && this._selected.pageIdx === index) {
  5355. this._linkService.page = index + 1;
  5356. }
  5357. this._eventBus.dispatch("updatetextlayermatches", {
  5358. source: this,
  5359. pageIndex: index
  5360. });
  5361. }
  5362. #updateAllPages() {
  5363. this._eventBus.dispatch("updatetextlayermatches", {
  5364. source: this,
  5365. pageIndex: -1
  5366. });
  5367. }
  5368. #nextMatch() {
  5369. const previous = this.#state.findPrevious;
  5370. const currentPageIndex = this._linkService.page - 1;
  5371. const numPages = this._linkService.pagesCount;
  5372. this._highlightMatches = true;
  5373. if (this._dirtyMatch) {
  5374. this._dirtyMatch = false;
  5375. this._selected.pageIdx = this._selected.matchIdx = -1;
  5376. this._offset.pageIdx = currentPageIndex;
  5377. this._offset.matchIdx = null;
  5378. this._offset.wrapped = false;
  5379. this._resumePageIdx = null;
  5380. this._pageMatches.length = 0;
  5381. this._pageMatchesLength.length = 0;
  5382. this.#visitedPagesCount = 0;
  5383. this._matchesCountTotal = 0;
  5384. this.#updateAllPages();
  5385. for (let i = 0; i < numPages; i++) {
  5386. if (this._pendingFindMatches.has(i)) {
  5387. continue;
  5388. }
  5389. this._pendingFindMatches.add(i);
  5390. this._extractTextPromises[i].then(() => {
  5391. this._pendingFindMatches.delete(i);
  5392. this.#calculateMatch(i);
  5393. });
  5394. }
  5395. }
  5396. const query = this.#query;
  5397. if (query.length === 0) {
  5398. this.#updateUIState(FindState.FOUND);
  5399. return;
  5400. }
  5401. if (this._resumePageIdx) {
  5402. return;
  5403. }
  5404. const offset = this._offset;
  5405. this._pagesToSearch = numPages;
  5406. if (offset.matchIdx !== null) {
  5407. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5408. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5409. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5410. this.#updateMatch(true);
  5411. return;
  5412. }
  5413. this.#advanceOffsetPage(previous);
  5414. }
  5415. this.#nextPageMatch();
  5416. }
  5417. #matchesReady(matches) {
  5418. const offset = this._offset;
  5419. const numMatches = matches.length;
  5420. const previous = this.#state.findPrevious;
  5421. if (numMatches) {
  5422. offset.matchIdx = previous ? numMatches - 1 : 0;
  5423. this.#updateMatch(true);
  5424. return true;
  5425. }
  5426. this.#advanceOffsetPage(previous);
  5427. if (offset.wrapped) {
  5428. offset.matchIdx = null;
  5429. if (this._pagesToSearch < 0) {
  5430. this.#updateMatch(false);
  5431. return true;
  5432. }
  5433. }
  5434. return false;
  5435. }
  5436. #nextPageMatch() {
  5437. if (this._resumePageIdx !== null) {
  5438. console.error("There can only be one pending page.");
  5439. }
  5440. let matches = null;
  5441. do {
  5442. const pageIdx = this._offset.pageIdx;
  5443. matches = this._pageMatches[pageIdx];
  5444. if (!matches) {
  5445. this._resumePageIdx = pageIdx;
  5446. break;
  5447. }
  5448. } while (!this.#matchesReady(matches));
  5449. }
  5450. #advanceOffsetPage(previous) {
  5451. const offset = this._offset;
  5452. const numPages = this._linkService.pagesCount;
  5453. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5454. offset.matchIdx = null;
  5455. this._pagesToSearch--;
  5456. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5457. offset.pageIdx = previous ? numPages - 1 : 0;
  5458. offset.wrapped = true;
  5459. }
  5460. }
  5461. #updateMatch(found = false) {
  5462. let state = FindState.NOT_FOUND;
  5463. const wrapped = this._offset.wrapped;
  5464. this._offset.wrapped = false;
  5465. if (found) {
  5466. const previousPage = this._selected.pageIdx;
  5467. this._selected.pageIdx = this._offset.pageIdx;
  5468. this._selected.matchIdx = this._offset.matchIdx;
  5469. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5470. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5471. this.#updatePage(previousPage);
  5472. }
  5473. }
  5474. this.#updateUIState(state, this.#state.findPrevious);
  5475. if (this._selected.pageIdx !== -1) {
  5476. this._scrollMatches = true;
  5477. this.#updatePage(this._selected.pageIdx);
  5478. }
  5479. }
  5480. #onFindBarClose(evt) {
  5481. const pdfDocument = this._pdfDocument;
  5482. this._firstPageCapability.promise.then(() => {
  5483. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5484. return;
  5485. }
  5486. if (this._findTimeout) {
  5487. clearTimeout(this._findTimeout);
  5488. this._findTimeout = null;
  5489. }
  5490. if (this._resumePageIdx) {
  5491. this._resumePageIdx = null;
  5492. this._dirtyMatch = true;
  5493. }
  5494. this.#updateUIState(FindState.FOUND);
  5495. this._highlightMatches = false;
  5496. this.#updateAllPages();
  5497. });
  5498. }
  5499. #requestMatchesCount() {
  5500. const {
  5501. pageIdx,
  5502. matchIdx
  5503. } = this._selected;
  5504. let current = 0,
  5505. total = this._matchesCountTotal;
  5506. if (matchIdx !== -1) {
  5507. for (let i = 0; i < pageIdx; i++) {
  5508. current += this._pageMatches[i]?.length || 0;
  5509. }
  5510. current += matchIdx + 1;
  5511. }
  5512. if (current < 1 || current > total) {
  5513. current = total = 0;
  5514. }
  5515. return {
  5516. current,
  5517. total
  5518. };
  5519. }
  5520. #updateUIResultsCount() {
  5521. this._eventBus.dispatch("updatefindmatchescount", {
  5522. source: this,
  5523. matchesCount: this.#requestMatchesCount()
  5524. });
  5525. }
  5526. #updateUIState(state, previous = false) {
  5527. if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) {
  5528. return;
  5529. }
  5530. this._eventBus.dispatch("updatefindcontrolstate", {
  5531. source: this,
  5532. state,
  5533. previous,
  5534. matchesCount: this.#requestMatchesCount(),
  5535. rawQuery: this.#state?.query ?? null
  5536. });
  5537. }
  5538. }
  5539. exports.PDFFindController = PDFFindController;
  5540. /***/ }),
  5541. /* 18 */
  5542. /***/ ((__unused_webpack_module, exports) => {
  5543. Object.defineProperty(exports, "__esModule", ({
  5544. value: true
  5545. }));
  5546. exports.CharacterType = void 0;
  5547. exports.getCharacterType = getCharacterType;
  5548. exports.getNormalizeWithNFKC = getNormalizeWithNFKC;
  5549. const CharacterType = {
  5550. SPACE: 0,
  5551. ALPHA_LETTER: 1,
  5552. PUNCT: 2,
  5553. HAN_LETTER: 3,
  5554. KATAKANA_LETTER: 4,
  5555. HIRAGANA_LETTER: 5,
  5556. HALFWIDTH_KATAKANA_LETTER: 6,
  5557. THAI_LETTER: 7
  5558. };
  5559. exports.CharacterType = CharacterType;
  5560. function isAlphabeticalScript(charCode) {
  5561. return charCode < 0x2e80;
  5562. }
  5563. function isAscii(charCode) {
  5564. return (charCode & 0xff80) === 0;
  5565. }
  5566. function isAsciiAlpha(charCode) {
  5567. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5568. }
  5569. function isAsciiDigit(charCode) {
  5570. return charCode >= 0x30 && charCode <= 0x39;
  5571. }
  5572. function isAsciiSpace(charCode) {
  5573. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5574. }
  5575. function isHan(charCode) {
  5576. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5577. }
  5578. function isKatakana(charCode) {
  5579. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5580. }
  5581. function isHiragana(charCode) {
  5582. return charCode >= 0x3040 && charCode <= 0x309f;
  5583. }
  5584. function isHalfwidthKatakana(charCode) {
  5585. return charCode >= 0xff60 && charCode <= 0xff9f;
  5586. }
  5587. function isThai(charCode) {
  5588. return (charCode & 0xff80) === 0x0e00;
  5589. }
  5590. function getCharacterType(charCode) {
  5591. if (isAlphabeticalScript(charCode)) {
  5592. if (isAscii(charCode)) {
  5593. if (isAsciiSpace(charCode)) {
  5594. return CharacterType.SPACE;
  5595. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5596. return CharacterType.ALPHA_LETTER;
  5597. }
  5598. return CharacterType.PUNCT;
  5599. } else if (isThai(charCode)) {
  5600. return CharacterType.THAI_LETTER;
  5601. } else if (charCode === 0xa0) {
  5602. return CharacterType.SPACE;
  5603. }
  5604. return CharacterType.ALPHA_LETTER;
  5605. }
  5606. if (isHan(charCode)) {
  5607. return CharacterType.HAN_LETTER;
  5608. } else if (isKatakana(charCode)) {
  5609. return CharacterType.KATAKANA_LETTER;
  5610. } else if (isHiragana(charCode)) {
  5611. return CharacterType.HIRAGANA_LETTER;
  5612. } else if (isHalfwidthKatakana(charCode)) {
  5613. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5614. }
  5615. return CharacterType.ALPHA_LETTER;
  5616. }
  5617. let NormalizeWithNFKC;
  5618. function getNormalizeWithNFKC() {
  5619. NormalizeWithNFKC ||= ` ¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰꟲ-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`;
  5620. return NormalizeWithNFKC;
  5621. }
  5622. /***/ }),
  5623. /* 19 */
  5624. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5625. Object.defineProperty(exports, "__esModule", ({
  5626. value: true
  5627. }));
  5628. exports.PDFHistory = void 0;
  5629. exports.isDestArraysEqual = isDestArraysEqual;
  5630. exports.isDestHashesEqual = isDestHashesEqual;
  5631. var _ui_utils = __webpack_require__(3);
  5632. var _event_utils = __webpack_require__(6);
  5633. const HASH_CHANGE_TIMEOUT = 1000;
  5634. const POSITION_UPDATED_THRESHOLD = 50;
  5635. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5636. function getCurrentHash() {
  5637. return document.location.hash;
  5638. }
  5639. class PDFHistory {
  5640. constructor({
  5641. linkService,
  5642. eventBus
  5643. }) {
  5644. this.linkService = linkService;
  5645. this.eventBus = eventBus;
  5646. this._initialized = false;
  5647. this._fingerprint = "";
  5648. this.reset();
  5649. this._boundEvents = null;
  5650. this.eventBus._on("pagesinit", () => {
  5651. this._isPagesLoaded = false;
  5652. this.eventBus._on("pagesloaded", evt => {
  5653. this._isPagesLoaded = !!evt.pagesCount;
  5654. }, {
  5655. once: true
  5656. });
  5657. });
  5658. }
  5659. initialize({
  5660. fingerprint,
  5661. resetHistory = false,
  5662. updateUrl = false
  5663. }) {
  5664. if (!fingerprint || typeof fingerprint !== "string") {
  5665. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5666. return;
  5667. }
  5668. if (this._initialized) {
  5669. this.reset();
  5670. }
  5671. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5672. this._fingerprint = fingerprint;
  5673. this._updateUrl = updateUrl === true;
  5674. this._initialized = true;
  5675. this._bindEvents();
  5676. const state = window.history.state;
  5677. this._popStateInProgress = false;
  5678. this._blockHashChange = 0;
  5679. this._currentHash = getCurrentHash();
  5680. this._numPositionUpdates = 0;
  5681. this._uid = this._maxUid = 0;
  5682. this._destination = null;
  5683. this._position = null;
  5684. if (!this._isValidState(state, true) || resetHistory) {
  5685. const {
  5686. hash,
  5687. page,
  5688. rotation
  5689. } = this._parseCurrentHash(true);
  5690. if (!hash || reInitialized || resetHistory) {
  5691. this._pushOrReplaceState(null, true);
  5692. return;
  5693. }
  5694. this._pushOrReplaceState({
  5695. hash,
  5696. page,
  5697. rotation
  5698. }, true);
  5699. return;
  5700. }
  5701. const destination = state.destination;
  5702. this._updateInternalState(destination, state.uid, true);
  5703. if (destination.rotation !== undefined) {
  5704. this._initialRotation = destination.rotation;
  5705. }
  5706. if (destination.dest) {
  5707. this._initialBookmark = JSON.stringify(destination.dest);
  5708. this._destination.page = null;
  5709. } else if (destination.hash) {
  5710. this._initialBookmark = destination.hash;
  5711. } else if (destination.page) {
  5712. this._initialBookmark = `page=${destination.page}`;
  5713. }
  5714. }
  5715. reset() {
  5716. if (this._initialized) {
  5717. this._pageHide();
  5718. this._initialized = false;
  5719. this._unbindEvents();
  5720. }
  5721. if (this._updateViewareaTimeout) {
  5722. clearTimeout(this._updateViewareaTimeout);
  5723. this._updateViewareaTimeout = null;
  5724. }
  5725. this._initialBookmark = null;
  5726. this._initialRotation = null;
  5727. }
  5728. push({
  5729. namedDest = null,
  5730. explicitDest,
  5731. pageNumber
  5732. }) {
  5733. if (!this._initialized) {
  5734. return;
  5735. }
  5736. if (namedDest && typeof namedDest !== "string") {
  5737. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5738. return;
  5739. } else if (!Array.isArray(explicitDest)) {
  5740. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5741. return;
  5742. } else if (!this._isValidPage(pageNumber)) {
  5743. if (pageNumber !== null || this._destination) {
  5744. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5745. return;
  5746. }
  5747. }
  5748. const hash = namedDest || JSON.stringify(explicitDest);
  5749. if (!hash) {
  5750. return;
  5751. }
  5752. let forceReplace = false;
  5753. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5754. if (this._destination.page) {
  5755. return;
  5756. }
  5757. forceReplace = true;
  5758. }
  5759. if (this._popStateInProgress && !forceReplace) {
  5760. return;
  5761. }
  5762. this._pushOrReplaceState({
  5763. dest: explicitDest,
  5764. hash,
  5765. page: pageNumber,
  5766. rotation: this.linkService.rotation
  5767. }, forceReplace);
  5768. if (!this._popStateInProgress) {
  5769. this._popStateInProgress = true;
  5770. Promise.resolve().then(() => {
  5771. this._popStateInProgress = false;
  5772. });
  5773. }
  5774. }
  5775. pushPage(pageNumber) {
  5776. if (!this._initialized) {
  5777. return;
  5778. }
  5779. if (!this._isValidPage(pageNumber)) {
  5780. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5781. return;
  5782. }
  5783. if (this._destination?.page === pageNumber) {
  5784. return;
  5785. }
  5786. if (this._popStateInProgress) {
  5787. return;
  5788. }
  5789. this._pushOrReplaceState({
  5790. dest: null,
  5791. hash: `page=${pageNumber}`,
  5792. page: pageNumber,
  5793. rotation: this.linkService.rotation
  5794. });
  5795. if (!this._popStateInProgress) {
  5796. this._popStateInProgress = true;
  5797. Promise.resolve().then(() => {
  5798. this._popStateInProgress = false;
  5799. });
  5800. }
  5801. }
  5802. pushCurrentPosition() {
  5803. if (!this._initialized || this._popStateInProgress) {
  5804. return;
  5805. }
  5806. this._tryPushCurrentPosition();
  5807. }
  5808. back() {
  5809. if (!this._initialized || this._popStateInProgress) {
  5810. return;
  5811. }
  5812. const state = window.history.state;
  5813. if (this._isValidState(state) && state.uid > 0) {
  5814. window.history.back();
  5815. }
  5816. }
  5817. forward() {
  5818. if (!this._initialized || this._popStateInProgress) {
  5819. return;
  5820. }
  5821. const state = window.history.state;
  5822. if (this._isValidState(state) && state.uid < this._maxUid) {
  5823. window.history.forward();
  5824. }
  5825. }
  5826. get popStateInProgress() {
  5827. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5828. }
  5829. get initialBookmark() {
  5830. return this._initialized ? this._initialBookmark : null;
  5831. }
  5832. get initialRotation() {
  5833. return this._initialized ? this._initialRotation : null;
  5834. }
  5835. _pushOrReplaceState(destination, forceReplace = false) {
  5836. const shouldReplace = forceReplace || !this._destination;
  5837. const newState = {
  5838. fingerprint: this._fingerprint,
  5839. uid: shouldReplace ? this._uid : this._uid + 1,
  5840. destination
  5841. };
  5842. this._updateInternalState(destination, newState.uid);
  5843. let newUrl;
  5844. if (this._updateUrl && destination?.hash) {
  5845. const baseUrl = document.location.href.split("#")[0];
  5846. if (!baseUrl.startsWith("file://")) {
  5847. newUrl = `${baseUrl}#${destination.hash}`;
  5848. }
  5849. }
  5850. if (shouldReplace) {
  5851. window.history.replaceState(newState, "", newUrl);
  5852. } else {
  5853. window.history.pushState(newState, "", newUrl);
  5854. }
  5855. }
  5856. _tryPushCurrentPosition(temporary = false) {
  5857. if (!this._position) {
  5858. return;
  5859. }
  5860. let position = this._position;
  5861. if (temporary) {
  5862. position = Object.assign(Object.create(null), this._position);
  5863. position.temporary = true;
  5864. }
  5865. if (!this._destination) {
  5866. this._pushOrReplaceState(position);
  5867. return;
  5868. }
  5869. if (this._destination.temporary) {
  5870. this._pushOrReplaceState(position, true);
  5871. return;
  5872. }
  5873. if (this._destination.hash === position.hash) {
  5874. return;
  5875. }
  5876. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5877. return;
  5878. }
  5879. let forceReplace = false;
  5880. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5881. if (this._destination.dest !== undefined || !this._destination.first) {
  5882. return;
  5883. }
  5884. forceReplace = true;
  5885. }
  5886. this._pushOrReplaceState(position, forceReplace);
  5887. }
  5888. _isValidPage(val) {
  5889. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5890. }
  5891. _isValidState(state, checkReload = false) {
  5892. if (!state) {
  5893. return false;
  5894. }
  5895. if (state.fingerprint !== this._fingerprint) {
  5896. if (checkReload) {
  5897. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5898. return false;
  5899. }
  5900. const [perfEntry] = performance.getEntriesByType("navigation");
  5901. if (perfEntry?.type !== "reload") {
  5902. return false;
  5903. }
  5904. } else {
  5905. return false;
  5906. }
  5907. }
  5908. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5909. return false;
  5910. }
  5911. if (state.destination === null || typeof state.destination !== "object") {
  5912. return false;
  5913. }
  5914. return true;
  5915. }
  5916. _updateInternalState(destination, uid, removeTemporary = false) {
  5917. if (this._updateViewareaTimeout) {
  5918. clearTimeout(this._updateViewareaTimeout);
  5919. this._updateViewareaTimeout = null;
  5920. }
  5921. if (removeTemporary && destination?.temporary) {
  5922. delete destination.temporary;
  5923. }
  5924. this._destination = destination;
  5925. this._uid = uid;
  5926. this._maxUid = Math.max(this._maxUid, uid);
  5927. this._numPositionUpdates = 0;
  5928. }
  5929. _parseCurrentHash(checkNameddest = false) {
  5930. const hash = unescape(getCurrentHash()).substring(1);
  5931. const params = (0, _ui_utils.parseQueryString)(hash);
  5932. const nameddest = params.get("nameddest") || "";
  5933. let page = params.get("page") | 0;
  5934. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5935. page = null;
  5936. }
  5937. return {
  5938. hash,
  5939. page,
  5940. rotation: this.linkService.rotation
  5941. };
  5942. }
  5943. _updateViewarea({
  5944. location
  5945. }) {
  5946. if (this._updateViewareaTimeout) {
  5947. clearTimeout(this._updateViewareaTimeout);
  5948. this._updateViewareaTimeout = null;
  5949. }
  5950. this._position = {
  5951. hash: location.pdfOpenParams.substring(1),
  5952. page: this.linkService.page,
  5953. first: location.pageNumber,
  5954. rotation: location.rotation
  5955. };
  5956. if (this._popStateInProgress) {
  5957. return;
  5958. }
  5959. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5960. this._numPositionUpdates++;
  5961. }
  5962. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5963. this._updateViewareaTimeout = setTimeout(() => {
  5964. if (!this._popStateInProgress) {
  5965. this._tryPushCurrentPosition(true);
  5966. }
  5967. this._updateViewareaTimeout = null;
  5968. }, UPDATE_VIEWAREA_TIMEOUT);
  5969. }
  5970. }
  5971. _popState({
  5972. state
  5973. }) {
  5974. const newHash = getCurrentHash(),
  5975. hashChanged = this._currentHash !== newHash;
  5976. this._currentHash = newHash;
  5977. if (!state) {
  5978. this._uid++;
  5979. const {
  5980. hash,
  5981. page,
  5982. rotation
  5983. } = this._parseCurrentHash();
  5984. this._pushOrReplaceState({
  5985. hash,
  5986. page,
  5987. rotation
  5988. }, true);
  5989. return;
  5990. }
  5991. if (!this._isValidState(state)) {
  5992. return;
  5993. }
  5994. this._popStateInProgress = true;
  5995. if (hashChanged) {
  5996. this._blockHashChange++;
  5997. (0, _event_utils.waitOnEventOrTimeout)({
  5998. target: window,
  5999. name: "hashchange",
  6000. delay: HASH_CHANGE_TIMEOUT
  6001. }).then(() => {
  6002. this._blockHashChange--;
  6003. });
  6004. }
  6005. const destination = state.destination;
  6006. this._updateInternalState(destination, state.uid, true);
  6007. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  6008. this.linkService.rotation = destination.rotation;
  6009. }
  6010. if (destination.dest) {
  6011. this.linkService.goToDestination(destination.dest);
  6012. } else if (destination.hash) {
  6013. this.linkService.setHash(destination.hash);
  6014. } else if (destination.page) {
  6015. this.linkService.page = destination.page;
  6016. }
  6017. Promise.resolve().then(() => {
  6018. this._popStateInProgress = false;
  6019. });
  6020. }
  6021. _pageHide() {
  6022. if (!this._destination || this._destination.temporary) {
  6023. this._tryPushCurrentPosition();
  6024. }
  6025. }
  6026. _bindEvents() {
  6027. if (this._boundEvents) {
  6028. return;
  6029. }
  6030. this._boundEvents = {
  6031. updateViewarea: this._updateViewarea.bind(this),
  6032. popState: this._popState.bind(this),
  6033. pageHide: this._pageHide.bind(this)
  6034. };
  6035. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  6036. window.addEventListener("popstate", this._boundEvents.popState);
  6037. window.addEventListener("pagehide", this._boundEvents.pageHide);
  6038. }
  6039. _unbindEvents() {
  6040. if (!this._boundEvents) {
  6041. return;
  6042. }
  6043. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  6044. window.removeEventListener("popstate", this._boundEvents.popState);
  6045. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  6046. this._boundEvents = null;
  6047. }
  6048. }
  6049. exports.PDFHistory = PDFHistory;
  6050. function isDestHashesEqual(destHash, pushHash) {
  6051. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  6052. return false;
  6053. }
  6054. if (destHash === pushHash) {
  6055. return true;
  6056. }
  6057. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  6058. if (nameddest === pushHash) {
  6059. return true;
  6060. }
  6061. return false;
  6062. }
  6063. function isDestArraysEqual(firstDest, secondDest) {
  6064. function isEntryEqual(first, second) {
  6065. if (typeof first !== typeof second) {
  6066. return false;
  6067. }
  6068. if (Array.isArray(first) || Array.isArray(second)) {
  6069. return false;
  6070. }
  6071. if (first !== null && typeof first === "object" && second !== null) {
  6072. if (Object.keys(first).length !== Object.keys(second).length) {
  6073. return false;
  6074. }
  6075. for (const key in first) {
  6076. if (!isEntryEqual(first[key], second[key])) {
  6077. return false;
  6078. }
  6079. }
  6080. return true;
  6081. }
  6082. return first === second || Number.isNaN(first) && Number.isNaN(second);
  6083. }
  6084. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  6085. return false;
  6086. }
  6087. if (firstDest.length !== secondDest.length) {
  6088. return false;
  6089. }
  6090. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  6091. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  6092. return false;
  6093. }
  6094. }
  6095. return true;
  6096. }
  6097. /***/ }),
  6098. /* 20 */
  6099. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6100. Object.defineProperty(exports, "__esModule", ({
  6101. value: true
  6102. }));
  6103. exports.PDFLayerViewer = void 0;
  6104. var _base_tree_viewer = __webpack_require__(12);
  6105. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  6106. constructor(options) {
  6107. super(options);
  6108. this.l10n = options.l10n;
  6109. this.eventBus._on("optionalcontentconfigchanged", evt => {
  6110. this.#updateLayers(evt.promise);
  6111. });
  6112. this.eventBus._on("resetlayers", () => {
  6113. this.#updateLayers();
  6114. });
  6115. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  6116. }
  6117. reset() {
  6118. super.reset();
  6119. this._optionalContentConfig = null;
  6120. this._optionalContentHash = null;
  6121. }
  6122. _dispatchEvent(layersCount) {
  6123. this.eventBus.dispatch("layersloaded", {
  6124. source: this,
  6125. layersCount
  6126. });
  6127. }
  6128. _bindLink(element, {
  6129. groupId,
  6130. input
  6131. }) {
  6132. const setVisibility = () => {
  6133. this._optionalContentConfig.setVisibility(groupId, input.checked);
  6134. this._optionalContentHash = this._optionalContentConfig.getHash();
  6135. this.eventBus.dispatch("optionalcontentconfig", {
  6136. source: this,
  6137. promise: Promise.resolve(this._optionalContentConfig)
  6138. });
  6139. };
  6140. element.onclick = evt => {
  6141. if (evt.target === input) {
  6142. setVisibility();
  6143. return true;
  6144. } else if (evt.target !== element) {
  6145. return true;
  6146. }
  6147. input.checked = !input.checked;
  6148. setVisibility();
  6149. return false;
  6150. };
  6151. }
  6152. async _setNestedName(element, {
  6153. name = null
  6154. }) {
  6155. if (typeof name === "string") {
  6156. element.textContent = this._normalizeTextContent(name);
  6157. return;
  6158. }
  6159. element.textContent = await this.l10n.get("additional_layers");
  6160. element.style.fontStyle = "italic";
  6161. }
  6162. _addToggleButton(div, {
  6163. name = null
  6164. }) {
  6165. super._addToggleButton(div, name === null);
  6166. }
  6167. _toggleAllTreeItems() {
  6168. if (!this._optionalContentConfig) {
  6169. return;
  6170. }
  6171. super._toggleAllTreeItems();
  6172. }
  6173. render({
  6174. optionalContentConfig,
  6175. pdfDocument
  6176. }) {
  6177. if (this._optionalContentConfig) {
  6178. this.reset();
  6179. }
  6180. this._optionalContentConfig = optionalContentConfig || null;
  6181. this._pdfDocument = pdfDocument || null;
  6182. const groups = optionalContentConfig?.getOrder();
  6183. if (!groups) {
  6184. this._dispatchEvent(0);
  6185. return;
  6186. }
  6187. this._optionalContentHash = optionalContentConfig.getHash();
  6188. const fragment = document.createDocumentFragment(),
  6189. queue = [{
  6190. parent: fragment,
  6191. groups
  6192. }];
  6193. let layersCount = 0,
  6194. hasAnyNesting = false;
  6195. while (queue.length > 0) {
  6196. const levelData = queue.shift();
  6197. for (const groupId of levelData.groups) {
  6198. const div = document.createElement("div");
  6199. div.className = "treeItem";
  6200. const element = document.createElement("a");
  6201. div.append(element);
  6202. if (typeof groupId === "object") {
  6203. hasAnyNesting = true;
  6204. this._addToggleButton(div, groupId);
  6205. this._setNestedName(element, groupId);
  6206. const itemsDiv = document.createElement("div");
  6207. itemsDiv.className = "treeItems";
  6208. div.append(itemsDiv);
  6209. queue.push({
  6210. parent: itemsDiv,
  6211. groups: groupId.order
  6212. });
  6213. } else {
  6214. const group = optionalContentConfig.getGroup(groupId);
  6215. const input = document.createElement("input");
  6216. this._bindLink(element, {
  6217. groupId,
  6218. input
  6219. });
  6220. input.type = "checkbox";
  6221. input.checked = group.visible;
  6222. const label = document.createElement("label");
  6223. label.textContent = this._normalizeTextContent(group.name);
  6224. label.append(input);
  6225. element.append(label);
  6226. layersCount++;
  6227. }
  6228. levelData.parent.append(div);
  6229. }
  6230. }
  6231. this._finishRendering(fragment, layersCount, hasAnyNesting);
  6232. }
  6233. async #updateLayers(promise = null) {
  6234. if (!this._optionalContentConfig) {
  6235. return;
  6236. }
  6237. const pdfDocument = this._pdfDocument;
  6238. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig());
  6239. if (pdfDocument !== this._pdfDocument) {
  6240. return;
  6241. }
  6242. if (promise) {
  6243. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  6244. return;
  6245. }
  6246. } else {
  6247. this.eventBus.dispatch("optionalcontentconfig", {
  6248. source: this,
  6249. promise: Promise.resolve(optionalContentConfig)
  6250. });
  6251. }
  6252. this.render({
  6253. optionalContentConfig,
  6254. pdfDocument: this._pdfDocument
  6255. });
  6256. }
  6257. }
  6258. exports.PDFLayerViewer = PDFLayerViewer;
  6259. /***/ }),
  6260. /* 21 */
  6261. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6262. Object.defineProperty(exports, "__esModule", ({
  6263. value: true
  6264. }));
  6265. exports.PDFOutlineViewer = void 0;
  6266. var _base_tree_viewer = __webpack_require__(12);
  6267. var _pdfjsLib = __webpack_require__(4);
  6268. var _ui_utils = __webpack_require__(3);
  6269. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  6270. constructor(options) {
  6271. super(options);
  6272. this.linkService = options.linkService;
  6273. this.downloadManager = options.downloadManager;
  6274. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6275. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6276. this.eventBus._on("pagechanging", evt => {
  6277. this._currentPageNumber = evt.pageNumber;
  6278. });
  6279. this.eventBus._on("pagesloaded", evt => {
  6280. this._isPagesLoaded = !!evt.pagesCount;
  6281. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6282. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6283. }
  6284. });
  6285. this.eventBus._on("sidebarviewchanged", evt => {
  6286. this._sidebarView = evt.view;
  6287. });
  6288. }
  6289. reset() {
  6290. super.reset();
  6291. this._outline = null;
  6292. this._pageNumberToDestHashCapability = null;
  6293. this._currentPageNumber = 1;
  6294. this._isPagesLoaded = null;
  6295. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6296. this._currentOutlineItemCapability.resolve(false);
  6297. }
  6298. this._currentOutlineItemCapability = null;
  6299. }
  6300. _dispatchEvent(outlineCount) {
  6301. this._currentOutlineItemCapability = new _pdfjsLib.PromiseCapability();
  6302. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  6303. this._currentOutlineItemCapability.resolve(false);
  6304. } else if (this._isPagesLoaded !== null) {
  6305. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6306. }
  6307. this.eventBus.dispatch("outlineloaded", {
  6308. source: this,
  6309. outlineCount,
  6310. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6311. });
  6312. }
  6313. _bindLink(element, {
  6314. url,
  6315. newWindow,
  6316. action,
  6317. attachment,
  6318. dest,
  6319. setOCGState
  6320. }) {
  6321. const {
  6322. linkService
  6323. } = this;
  6324. if (url) {
  6325. linkService.addLinkAttributes(element, url, newWindow);
  6326. return;
  6327. }
  6328. if (action) {
  6329. element.href = linkService.getAnchorUrl("");
  6330. element.onclick = () => {
  6331. linkService.executeNamedAction(action);
  6332. return false;
  6333. };
  6334. return;
  6335. }
  6336. if (attachment) {
  6337. element.href = linkService.getAnchorUrl("");
  6338. element.onclick = () => {
  6339. this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename);
  6340. return false;
  6341. };
  6342. return;
  6343. }
  6344. if (setOCGState) {
  6345. element.href = linkService.getAnchorUrl("");
  6346. element.onclick = () => {
  6347. linkService.executeSetOCGState(setOCGState);
  6348. return false;
  6349. };
  6350. return;
  6351. }
  6352. element.href = linkService.getDestinationHash(dest);
  6353. element.onclick = evt => {
  6354. this._updateCurrentTreeItem(evt.target.parentNode);
  6355. if (dest) {
  6356. linkService.goToDestination(dest);
  6357. }
  6358. return false;
  6359. };
  6360. }
  6361. _setStyles(element, {
  6362. bold,
  6363. italic
  6364. }) {
  6365. if (bold) {
  6366. element.style.fontWeight = "bold";
  6367. }
  6368. if (italic) {
  6369. element.style.fontStyle = "italic";
  6370. }
  6371. }
  6372. _addToggleButton(div, {
  6373. count,
  6374. items
  6375. }) {
  6376. let hidden = false;
  6377. if (count < 0) {
  6378. let totalCount = items.length;
  6379. if (totalCount > 0) {
  6380. const queue = [...items];
  6381. while (queue.length > 0) {
  6382. const {
  6383. count: nestedCount,
  6384. items: nestedItems
  6385. } = queue.shift();
  6386. if (nestedCount > 0 && nestedItems.length > 0) {
  6387. totalCount += nestedItems.length;
  6388. queue.push(...nestedItems);
  6389. }
  6390. }
  6391. }
  6392. if (Math.abs(count) === totalCount) {
  6393. hidden = true;
  6394. }
  6395. }
  6396. super._addToggleButton(div, hidden);
  6397. }
  6398. _toggleAllTreeItems() {
  6399. if (!this._outline) {
  6400. return;
  6401. }
  6402. super._toggleAllTreeItems();
  6403. }
  6404. render({
  6405. outline,
  6406. pdfDocument
  6407. }) {
  6408. if (this._outline) {
  6409. this.reset();
  6410. }
  6411. this._outline = outline || null;
  6412. this._pdfDocument = pdfDocument || null;
  6413. if (!outline) {
  6414. this._dispatchEvent(0);
  6415. return;
  6416. }
  6417. const fragment = document.createDocumentFragment();
  6418. const queue = [{
  6419. parent: fragment,
  6420. items: outline
  6421. }];
  6422. let outlineCount = 0,
  6423. hasAnyNesting = false;
  6424. while (queue.length > 0) {
  6425. const levelData = queue.shift();
  6426. for (const item of levelData.items) {
  6427. const div = document.createElement("div");
  6428. div.className = "treeItem";
  6429. const element = document.createElement("a");
  6430. this._bindLink(element, item);
  6431. this._setStyles(element, item);
  6432. element.textContent = this._normalizeTextContent(item.title);
  6433. div.append(element);
  6434. if (item.items.length > 0) {
  6435. hasAnyNesting = true;
  6436. this._addToggleButton(div, item);
  6437. const itemsDiv = document.createElement("div");
  6438. itemsDiv.className = "treeItems";
  6439. div.append(itemsDiv);
  6440. queue.push({
  6441. parent: itemsDiv,
  6442. items: item.items
  6443. });
  6444. }
  6445. levelData.parent.append(div);
  6446. outlineCount++;
  6447. }
  6448. }
  6449. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6450. }
  6451. async _currentOutlineItem() {
  6452. if (!this._isPagesLoaded) {
  6453. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6454. }
  6455. if (!this._outline || !this._pdfDocument) {
  6456. return;
  6457. }
  6458. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6459. if (!pageNumberToDestHash) {
  6460. return;
  6461. }
  6462. this._updateCurrentTreeItem(null);
  6463. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6464. return;
  6465. }
  6466. for (let i = this._currentPageNumber; i > 0; i--) {
  6467. const destHash = pageNumberToDestHash.get(i);
  6468. if (!destHash) {
  6469. continue;
  6470. }
  6471. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6472. if (!linkElement) {
  6473. continue;
  6474. }
  6475. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6476. break;
  6477. }
  6478. }
  6479. async _getPageNumberToDestHash(pdfDocument) {
  6480. if (this._pageNumberToDestHashCapability) {
  6481. return this._pageNumberToDestHashCapability.promise;
  6482. }
  6483. this._pageNumberToDestHashCapability = new _pdfjsLib.PromiseCapability();
  6484. const pageNumberToDestHash = new Map(),
  6485. pageNumberNesting = new Map();
  6486. const queue = [{
  6487. nesting: 0,
  6488. items: this._outline
  6489. }];
  6490. while (queue.length > 0) {
  6491. const levelData = queue.shift(),
  6492. currentNesting = levelData.nesting;
  6493. for (const {
  6494. dest,
  6495. items
  6496. } of levelData.items) {
  6497. let explicitDest, pageNumber;
  6498. if (typeof dest === "string") {
  6499. explicitDest = await pdfDocument.getDestination(dest);
  6500. if (pdfDocument !== this._pdfDocument) {
  6501. return null;
  6502. }
  6503. } else {
  6504. explicitDest = dest;
  6505. }
  6506. if (Array.isArray(explicitDest)) {
  6507. const [destRef] = explicitDest;
  6508. if (typeof destRef === "object" && destRef !== null) {
  6509. pageNumber = this.linkService._cachedPageNumber(destRef);
  6510. if (!pageNumber) {
  6511. try {
  6512. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6513. if (pdfDocument !== this._pdfDocument) {
  6514. return null;
  6515. }
  6516. this.linkService.cachePageRef(pageNumber, destRef);
  6517. } catch {}
  6518. }
  6519. } else if (Number.isInteger(destRef)) {
  6520. pageNumber = destRef + 1;
  6521. }
  6522. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6523. const destHash = this.linkService.getDestinationHash(dest);
  6524. pageNumberToDestHash.set(pageNumber, destHash);
  6525. pageNumberNesting.set(pageNumber, currentNesting);
  6526. }
  6527. }
  6528. if (items.length > 0) {
  6529. queue.push({
  6530. nesting: currentNesting + 1,
  6531. items
  6532. });
  6533. }
  6534. }
  6535. }
  6536. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6537. return this._pageNumberToDestHashCapability.promise;
  6538. }
  6539. }
  6540. exports.PDFOutlineViewer = PDFOutlineViewer;
  6541. /***/ }),
  6542. /* 22 */
  6543. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6544. Object.defineProperty(exports, "__esModule", ({
  6545. value: true
  6546. }));
  6547. exports.PDFPresentationMode = void 0;
  6548. var _ui_utils = __webpack_require__(3);
  6549. var _pdfjsLib = __webpack_require__(4);
  6550. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6551. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6552. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6553. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6554. const PAGE_SWITCH_THRESHOLD = 0.1;
  6555. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6556. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6557. class PDFPresentationMode {
  6558. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6559. #args = null;
  6560. constructor({
  6561. container,
  6562. pdfViewer,
  6563. eventBus
  6564. }) {
  6565. this.container = container;
  6566. this.pdfViewer = pdfViewer;
  6567. this.eventBus = eventBus;
  6568. this.contextMenuOpen = false;
  6569. this.mouseScrollTimeStamp = 0;
  6570. this.mouseScrollDelta = 0;
  6571. this.touchSwipeState = null;
  6572. }
  6573. async request() {
  6574. const {
  6575. container,
  6576. pdfViewer
  6577. } = this;
  6578. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6579. return false;
  6580. }
  6581. this.#addFullscreenChangeListeners();
  6582. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6583. const promise = container.requestFullscreen();
  6584. this.#args = {
  6585. pageNumber: pdfViewer.currentPageNumber,
  6586. scaleValue: pdfViewer.currentScaleValue,
  6587. scrollMode: pdfViewer.scrollMode,
  6588. spreadMode: null,
  6589. annotationEditorMode: null
  6590. };
  6591. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6592. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6593. this.#args.spreadMode = pdfViewer.spreadMode;
  6594. }
  6595. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6596. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6597. }
  6598. try {
  6599. await promise;
  6600. pdfViewer.focus();
  6601. return true;
  6602. } catch {
  6603. this.#removeFullscreenChangeListeners();
  6604. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6605. }
  6606. return false;
  6607. }
  6608. get active() {
  6609. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6610. }
  6611. #mouseWheel(evt) {
  6612. if (!this.active) {
  6613. return;
  6614. }
  6615. evt.preventDefault();
  6616. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6617. const currentTime = Date.now();
  6618. const storedTime = this.mouseScrollTimeStamp;
  6619. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6620. return;
  6621. }
  6622. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6623. this.#resetMouseScrollState();
  6624. }
  6625. this.mouseScrollDelta += delta;
  6626. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6627. const totalDelta = this.mouseScrollDelta;
  6628. this.#resetMouseScrollState();
  6629. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6630. if (success) {
  6631. this.mouseScrollTimeStamp = currentTime;
  6632. }
  6633. }
  6634. }
  6635. #notifyStateChange(state) {
  6636. this.#state = state;
  6637. this.eventBus.dispatch("presentationmodechanged", {
  6638. source: this,
  6639. state
  6640. });
  6641. }
  6642. #enter() {
  6643. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6644. this.container.classList.add(ACTIVE_SELECTOR);
  6645. setTimeout(() => {
  6646. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6647. if (this.#args.spreadMode !== null) {
  6648. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6649. }
  6650. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6651. this.pdfViewer.currentScaleValue = "page-fit";
  6652. if (this.#args.annotationEditorMode !== null) {
  6653. this.pdfViewer.annotationEditorMode = {
  6654. mode: _pdfjsLib.AnnotationEditorType.NONE
  6655. };
  6656. }
  6657. }, 0);
  6658. this.#addWindowListeners();
  6659. this.#showControls();
  6660. this.contextMenuOpen = false;
  6661. window.getSelection().removeAllRanges();
  6662. }
  6663. #exit() {
  6664. const pageNumber = this.pdfViewer.currentPageNumber;
  6665. this.container.classList.remove(ACTIVE_SELECTOR);
  6666. setTimeout(() => {
  6667. this.#removeFullscreenChangeListeners();
  6668. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6669. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6670. if (this.#args.spreadMode !== null) {
  6671. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6672. }
  6673. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6674. this.pdfViewer.currentPageNumber = pageNumber;
  6675. if (this.#args.annotationEditorMode !== null) {
  6676. this.pdfViewer.annotationEditorMode = {
  6677. mode: this.#args.annotationEditorMode
  6678. };
  6679. }
  6680. this.#args = null;
  6681. }, 0);
  6682. this.#removeWindowListeners();
  6683. this.#hideControls();
  6684. this.#resetMouseScrollState();
  6685. this.contextMenuOpen = false;
  6686. }
  6687. #mouseDown(evt) {
  6688. if (this.contextMenuOpen) {
  6689. this.contextMenuOpen = false;
  6690. evt.preventDefault();
  6691. return;
  6692. }
  6693. if (evt.button !== 0) {
  6694. return;
  6695. }
  6696. if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) {
  6697. return;
  6698. }
  6699. evt.preventDefault();
  6700. if (evt.shiftKey) {
  6701. this.pdfViewer.previousPage();
  6702. } else {
  6703. this.pdfViewer.nextPage();
  6704. }
  6705. }
  6706. #contextMenu() {
  6707. this.contextMenuOpen = true;
  6708. }
  6709. #showControls() {
  6710. if (this.controlsTimeout) {
  6711. clearTimeout(this.controlsTimeout);
  6712. } else {
  6713. this.container.classList.add(CONTROLS_SELECTOR);
  6714. }
  6715. this.controlsTimeout = setTimeout(() => {
  6716. this.container.classList.remove(CONTROLS_SELECTOR);
  6717. delete this.controlsTimeout;
  6718. }, DELAY_BEFORE_HIDING_CONTROLS);
  6719. }
  6720. #hideControls() {
  6721. if (!this.controlsTimeout) {
  6722. return;
  6723. }
  6724. clearTimeout(this.controlsTimeout);
  6725. this.container.classList.remove(CONTROLS_SELECTOR);
  6726. delete this.controlsTimeout;
  6727. }
  6728. #resetMouseScrollState() {
  6729. this.mouseScrollTimeStamp = 0;
  6730. this.mouseScrollDelta = 0;
  6731. }
  6732. #touchSwipe(evt) {
  6733. if (!this.active) {
  6734. return;
  6735. }
  6736. if (evt.touches.length > 1) {
  6737. this.touchSwipeState = null;
  6738. return;
  6739. }
  6740. switch (evt.type) {
  6741. case "touchstart":
  6742. this.touchSwipeState = {
  6743. startX: evt.touches[0].pageX,
  6744. startY: evt.touches[0].pageY,
  6745. endX: evt.touches[0].pageX,
  6746. endY: evt.touches[0].pageY
  6747. };
  6748. break;
  6749. case "touchmove":
  6750. if (this.touchSwipeState === null) {
  6751. return;
  6752. }
  6753. this.touchSwipeState.endX = evt.touches[0].pageX;
  6754. this.touchSwipeState.endY = evt.touches[0].pageY;
  6755. evt.preventDefault();
  6756. break;
  6757. case "touchend":
  6758. if (this.touchSwipeState === null) {
  6759. return;
  6760. }
  6761. let delta = 0;
  6762. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6763. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6764. const absAngle = Math.abs(Math.atan2(dy, dx));
  6765. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6766. delta = dx;
  6767. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6768. delta = dy;
  6769. }
  6770. if (delta > 0) {
  6771. this.pdfViewer.previousPage();
  6772. } else if (delta < 0) {
  6773. this.pdfViewer.nextPage();
  6774. }
  6775. break;
  6776. }
  6777. }
  6778. #addWindowListeners() {
  6779. this.showControlsBind = this.#showControls.bind(this);
  6780. this.mouseDownBind = this.#mouseDown.bind(this);
  6781. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6782. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6783. this.contextMenuBind = this.#contextMenu.bind(this);
  6784. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6785. window.addEventListener("mousemove", this.showControlsBind);
  6786. window.addEventListener("mousedown", this.mouseDownBind);
  6787. window.addEventListener("wheel", this.mouseWheelBind, {
  6788. passive: false
  6789. });
  6790. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6791. window.addEventListener("contextmenu", this.contextMenuBind);
  6792. window.addEventListener("touchstart", this.touchSwipeBind);
  6793. window.addEventListener("touchmove", this.touchSwipeBind);
  6794. window.addEventListener("touchend", this.touchSwipeBind);
  6795. }
  6796. #removeWindowListeners() {
  6797. window.removeEventListener("mousemove", this.showControlsBind);
  6798. window.removeEventListener("mousedown", this.mouseDownBind);
  6799. window.removeEventListener("wheel", this.mouseWheelBind, {
  6800. passive: false
  6801. });
  6802. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6803. window.removeEventListener("contextmenu", this.contextMenuBind);
  6804. window.removeEventListener("touchstart", this.touchSwipeBind);
  6805. window.removeEventListener("touchmove", this.touchSwipeBind);
  6806. window.removeEventListener("touchend", this.touchSwipeBind);
  6807. delete this.showControlsBind;
  6808. delete this.mouseDownBind;
  6809. delete this.mouseWheelBind;
  6810. delete this.resetMouseScrollStateBind;
  6811. delete this.contextMenuBind;
  6812. delete this.touchSwipeBind;
  6813. }
  6814. #fullscreenChange() {
  6815. if (document.fullscreenElement) {
  6816. this.#enter();
  6817. } else {
  6818. this.#exit();
  6819. }
  6820. }
  6821. #addFullscreenChangeListeners() {
  6822. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6823. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6824. }
  6825. #removeFullscreenChangeListeners() {
  6826. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6827. delete this.fullscreenChangeBind;
  6828. }
  6829. }
  6830. exports.PDFPresentationMode = PDFPresentationMode;
  6831. /***/ }),
  6832. /* 23 */
  6833. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6834. Object.defineProperty(exports, "__esModule", ({
  6835. value: true
  6836. }));
  6837. exports.PDFRenderingQueue = void 0;
  6838. var _pdfjsLib = __webpack_require__(4);
  6839. var _ui_utils = __webpack_require__(3);
  6840. const CLEANUP_TIMEOUT = 30000;
  6841. class PDFRenderingQueue {
  6842. constructor() {
  6843. this.pdfViewer = null;
  6844. this.pdfThumbnailViewer = null;
  6845. this.onIdle = null;
  6846. this.highestPriorityPage = null;
  6847. this.idleTimeout = null;
  6848. this.printing = false;
  6849. this.isThumbnailViewEnabled = false;
  6850. Object.defineProperty(this, "hasViewer", {
  6851. value: () => !!this.pdfViewer
  6852. });
  6853. }
  6854. setViewer(pdfViewer) {
  6855. this.pdfViewer = pdfViewer;
  6856. }
  6857. setThumbnailViewer(pdfThumbnailViewer) {
  6858. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6859. }
  6860. isHighestPriority(view) {
  6861. return this.highestPriorityPage === view.renderingId;
  6862. }
  6863. renderHighestPriority(currentlyVisiblePages) {
  6864. if (this.idleTimeout) {
  6865. clearTimeout(this.idleTimeout);
  6866. this.idleTimeout = null;
  6867. }
  6868. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6869. return;
  6870. }
  6871. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6872. return;
  6873. }
  6874. if (this.printing) {
  6875. return;
  6876. }
  6877. if (this.onIdle) {
  6878. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6879. }
  6880. }
  6881. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6882. const visibleViews = visible.views,
  6883. numVisible = visibleViews.length;
  6884. if (numVisible === 0) {
  6885. return null;
  6886. }
  6887. for (let i = 0; i < numVisible; i++) {
  6888. const view = visibleViews[i].view;
  6889. if (!this.isViewFinished(view)) {
  6890. return view;
  6891. }
  6892. }
  6893. const firstId = visible.first.id,
  6894. lastId = visible.last.id;
  6895. if (lastId - firstId + 1 > numVisible) {
  6896. const visibleIds = visible.ids;
  6897. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6898. const holeId = scrolledDown ? firstId + i : lastId - i;
  6899. if (visibleIds.has(holeId)) {
  6900. continue;
  6901. }
  6902. const holeView = views[holeId - 1];
  6903. if (!this.isViewFinished(holeView)) {
  6904. return holeView;
  6905. }
  6906. }
  6907. }
  6908. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6909. let preRenderView = views[preRenderIndex];
  6910. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6911. return preRenderView;
  6912. }
  6913. if (preRenderExtra) {
  6914. preRenderIndex += scrolledDown ? 1 : -1;
  6915. preRenderView = views[preRenderIndex];
  6916. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6917. return preRenderView;
  6918. }
  6919. }
  6920. return null;
  6921. }
  6922. isViewFinished(view) {
  6923. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6924. }
  6925. renderView(view) {
  6926. switch (view.renderingState) {
  6927. case _ui_utils.RenderingStates.FINISHED:
  6928. return false;
  6929. case _ui_utils.RenderingStates.PAUSED:
  6930. this.highestPriorityPage = view.renderingId;
  6931. view.resume();
  6932. break;
  6933. case _ui_utils.RenderingStates.RUNNING:
  6934. this.highestPriorityPage = view.renderingId;
  6935. break;
  6936. case _ui_utils.RenderingStates.INITIAL:
  6937. this.highestPriorityPage = view.renderingId;
  6938. view.draw().finally(() => {
  6939. this.renderHighestPriority();
  6940. }).catch(reason => {
  6941. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6942. return;
  6943. }
  6944. console.error(`renderView: "${reason}"`);
  6945. });
  6946. break;
  6947. }
  6948. return true;
  6949. }
  6950. }
  6951. exports.PDFRenderingQueue = PDFRenderingQueue;
  6952. /***/ }),
  6953. /* 24 */
  6954. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6955. Object.defineProperty(exports, "__esModule", ({
  6956. value: true
  6957. }));
  6958. exports.PDFScriptingManager = void 0;
  6959. var _ui_utils = __webpack_require__(3);
  6960. var _pdfjsLib = __webpack_require__(4);
  6961. class PDFScriptingManager {
  6962. #closeCapability = null;
  6963. #destroyCapability = null;
  6964. #docProperties = null;
  6965. #eventBus = null;
  6966. #externalServices = null;
  6967. #pdfDocument = null;
  6968. #pdfViewer = null;
  6969. #ready = false;
  6970. #sandboxBundleSrc = null;
  6971. #scripting = null;
  6972. #willPrintCapability = null;
  6973. constructor({
  6974. eventBus,
  6975. sandboxBundleSrc = null,
  6976. externalServices = null,
  6977. docProperties = null
  6978. }) {
  6979. this.#eventBus = eventBus;
  6980. this.#sandboxBundleSrc = sandboxBundleSrc;
  6981. this.#externalServices = externalServices;
  6982. this.#docProperties = docProperties;
  6983. }
  6984. setViewer(pdfViewer) {
  6985. this.#pdfViewer = pdfViewer;
  6986. }
  6987. async setDocument(pdfDocument) {
  6988. if (this.#pdfDocument) {
  6989. await this.#destroyScripting();
  6990. }
  6991. this.#pdfDocument = pdfDocument;
  6992. if (!pdfDocument) {
  6993. return;
  6994. }
  6995. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6996. if (!objects && !docActions) {
  6997. await this.#destroyScripting();
  6998. return;
  6999. }
  7000. if (pdfDocument !== this.#pdfDocument) {
  7001. return;
  7002. }
  7003. try {
  7004. this.#scripting = this.#initScripting();
  7005. } catch (error) {
  7006. console.error(`setDocument: "${error.message}".`);
  7007. await this.#destroyScripting();
  7008. return;
  7009. }
  7010. this._internalEvents.set("updatefromsandbox", event => {
  7011. if (event?.source === window) {
  7012. this.#updateFromSandbox(event.detail);
  7013. }
  7014. });
  7015. this._internalEvents.set("dispatcheventinsandbox", event => {
  7016. this.#scripting?.dispatchEventInSandbox(event.detail);
  7017. });
  7018. this._internalEvents.set("pagechanging", ({
  7019. pageNumber,
  7020. previous
  7021. }) => {
  7022. if (pageNumber === previous) {
  7023. return;
  7024. }
  7025. this.#dispatchPageClose(previous);
  7026. this.#dispatchPageOpen(pageNumber);
  7027. });
  7028. this._internalEvents.set("pagerendered", ({
  7029. pageNumber
  7030. }) => {
  7031. if (!this._pageOpenPending.has(pageNumber)) {
  7032. return;
  7033. }
  7034. if (pageNumber !== this.#pdfViewer.currentPageNumber) {
  7035. return;
  7036. }
  7037. this.#dispatchPageOpen(pageNumber);
  7038. });
  7039. this._internalEvents.set("pagesdestroy", async () => {
  7040. await this.#dispatchPageClose(this.#pdfViewer.currentPageNumber);
  7041. await this.#scripting?.dispatchEventInSandbox({
  7042. id: "doc",
  7043. name: "WillClose"
  7044. });
  7045. this.#closeCapability?.resolve();
  7046. });
  7047. for (const [name, listener] of this._internalEvents) {
  7048. this.#eventBus._on(name, listener);
  7049. }
  7050. try {
  7051. const docProperties = await this.#docProperties(pdfDocument);
  7052. if (pdfDocument !== this.#pdfDocument) {
  7053. return;
  7054. }
  7055. await this.#scripting.createSandbox({
  7056. objects,
  7057. calculationOrder,
  7058. appInfo: {
  7059. platform: navigator.platform,
  7060. language: navigator.language
  7061. },
  7062. docInfo: {
  7063. ...docProperties,
  7064. actions: docActions
  7065. }
  7066. });
  7067. this.#eventBus.dispatch("sandboxcreated", {
  7068. source: this
  7069. });
  7070. } catch (error) {
  7071. console.error(`setDocument: "${error.message}".`);
  7072. await this.#destroyScripting();
  7073. return;
  7074. }
  7075. await this.#scripting?.dispatchEventInSandbox({
  7076. id: "doc",
  7077. name: "Open"
  7078. });
  7079. await this.#dispatchPageOpen(this.#pdfViewer.currentPageNumber, true);
  7080. Promise.resolve().then(() => {
  7081. if (pdfDocument === this.#pdfDocument) {
  7082. this.#ready = true;
  7083. }
  7084. });
  7085. }
  7086. async dispatchWillSave() {
  7087. return this.#scripting?.dispatchEventInSandbox({
  7088. id: "doc",
  7089. name: "WillSave"
  7090. });
  7091. }
  7092. async dispatchDidSave() {
  7093. return this.#scripting?.dispatchEventInSandbox({
  7094. id: "doc",
  7095. name: "DidSave"
  7096. });
  7097. }
  7098. async dispatchWillPrint() {
  7099. if (!this.#scripting) {
  7100. return;
  7101. }
  7102. await this.#willPrintCapability?.promise;
  7103. this.#willPrintCapability = new _pdfjsLib.PromiseCapability();
  7104. try {
  7105. await this.#scripting.dispatchEventInSandbox({
  7106. id: "doc",
  7107. name: "WillPrint"
  7108. });
  7109. } catch (ex) {
  7110. this.#willPrintCapability.resolve();
  7111. this.#willPrintCapability = null;
  7112. throw ex;
  7113. }
  7114. await this.#willPrintCapability.promise;
  7115. }
  7116. async dispatchDidPrint() {
  7117. return this.#scripting?.dispatchEventInSandbox({
  7118. id: "doc",
  7119. name: "DidPrint"
  7120. });
  7121. }
  7122. get destroyPromise() {
  7123. return this.#destroyCapability?.promise || null;
  7124. }
  7125. get ready() {
  7126. return this.#ready;
  7127. }
  7128. get _internalEvents() {
  7129. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  7130. }
  7131. get _pageOpenPending() {
  7132. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  7133. }
  7134. get _visitedPages() {
  7135. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  7136. }
  7137. async #updateFromSandbox(detail) {
  7138. const pdfViewer = this.#pdfViewer;
  7139. const isInPresentationMode = pdfViewer.isInPresentationMode || pdfViewer.isChangingPresentationMode;
  7140. const {
  7141. id,
  7142. siblings,
  7143. command,
  7144. value
  7145. } = detail;
  7146. if (!id) {
  7147. switch (command) {
  7148. case "clear":
  7149. console.clear();
  7150. break;
  7151. case "error":
  7152. console.error(value);
  7153. break;
  7154. case "layout":
  7155. if (!isInPresentationMode) {
  7156. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  7157. pdfViewer.spreadMode = modes.spreadMode;
  7158. }
  7159. break;
  7160. case "page-num":
  7161. pdfViewer.currentPageNumber = value + 1;
  7162. break;
  7163. case "print":
  7164. await pdfViewer.pagesPromise;
  7165. this.#eventBus.dispatch("print", {
  7166. source: this
  7167. });
  7168. break;
  7169. case "println":
  7170. console.log(value);
  7171. break;
  7172. case "zoom":
  7173. if (!isInPresentationMode) {
  7174. pdfViewer.currentScaleValue = value;
  7175. }
  7176. break;
  7177. case "SaveAs":
  7178. this.#eventBus.dispatch("download", {
  7179. source: this
  7180. });
  7181. break;
  7182. case "FirstPage":
  7183. pdfViewer.currentPageNumber = 1;
  7184. break;
  7185. case "LastPage":
  7186. pdfViewer.currentPageNumber = pdfViewer.pagesCount;
  7187. break;
  7188. case "NextPage":
  7189. pdfViewer.nextPage();
  7190. break;
  7191. case "PrevPage":
  7192. pdfViewer.previousPage();
  7193. break;
  7194. case "ZoomViewIn":
  7195. if (!isInPresentationMode) {
  7196. pdfViewer.increaseScale();
  7197. }
  7198. break;
  7199. case "ZoomViewOut":
  7200. if (!isInPresentationMode) {
  7201. pdfViewer.decreaseScale();
  7202. }
  7203. break;
  7204. case "WillPrintFinished":
  7205. this.#willPrintCapability?.resolve();
  7206. this.#willPrintCapability = null;
  7207. break;
  7208. }
  7209. return;
  7210. }
  7211. if (isInPresentationMode && detail.focus) {
  7212. return;
  7213. }
  7214. delete detail.id;
  7215. delete detail.siblings;
  7216. const ids = siblings ? [id, ...siblings] : [id];
  7217. for (const elementId of ids) {
  7218. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  7219. if (element) {
  7220. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  7221. detail
  7222. }));
  7223. } else {
  7224. this.#pdfDocument?.annotationStorage.setValue(elementId, detail);
  7225. }
  7226. }
  7227. }
  7228. async #dispatchPageOpen(pageNumber, initialize = false) {
  7229. const pdfDocument = this.#pdfDocument,
  7230. visitedPages = this._visitedPages;
  7231. if (initialize) {
  7232. this.#closeCapability = new _pdfjsLib.PromiseCapability();
  7233. }
  7234. if (!this.#closeCapability) {
  7235. return;
  7236. }
  7237. const pageView = this.#pdfViewer.getPageView(pageNumber - 1);
  7238. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7239. this._pageOpenPending.add(pageNumber);
  7240. return;
  7241. }
  7242. this._pageOpenPending.delete(pageNumber);
  7243. const actionsPromise = (async () => {
  7244. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  7245. if (pdfDocument !== this.#pdfDocument) {
  7246. return;
  7247. }
  7248. await this.#scripting?.dispatchEventInSandbox({
  7249. id: "page",
  7250. name: "PageOpen",
  7251. pageNumber,
  7252. actions
  7253. });
  7254. })();
  7255. visitedPages.set(pageNumber, actionsPromise);
  7256. }
  7257. async #dispatchPageClose(pageNumber) {
  7258. const pdfDocument = this.#pdfDocument,
  7259. visitedPages = this._visitedPages;
  7260. if (!this.#closeCapability) {
  7261. return;
  7262. }
  7263. if (this._pageOpenPending.has(pageNumber)) {
  7264. return;
  7265. }
  7266. const actionsPromise = visitedPages.get(pageNumber);
  7267. if (!actionsPromise) {
  7268. return;
  7269. }
  7270. visitedPages.set(pageNumber, null);
  7271. await actionsPromise;
  7272. if (pdfDocument !== this.#pdfDocument) {
  7273. return;
  7274. }
  7275. await this.#scripting?.dispatchEventInSandbox({
  7276. id: "page",
  7277. name: "PageClose",
  7278. pageNumber
  7279. });
  7280. }
  7281. #initScripting() {
  7282. this.#destroyCapability = new _pdfjsLib.PromiseCapability();
  7283. if (this.#scripting) {
  7284. throw new Error("#initScripting: Scripting already exists.");
  7285. }
  7286. return this.#externalServices.createScripting({
  7287. sandboxBundleSrc: this.#sandboxBundleSrc
  7288. });
  7289. }
  7290. async #destroyScripting() {
  7291. if (!this.#scripting) {
  7292. this.#pdfDocument = null;
  7293. this.#destroyCapability?.resolve();
  7294. return;
  7295. }
  7296. if (this.#closeCapability) {
  7297. await Promise.race([this.#closeCapability.promise, new Promise(resolve => {
  7298. setTimeout(resolve, 1000);
  7299. })]).catch(() => {});
  7300. this.#closeCapability = null;
  7301. }
  7302. this.#pdfDocument = null;
  7303. try {
  7304. await this.#scripting.destroySandbox();
  7305. } catch {}
  7306. this.#willPrintCapability?.reject(new Error("Scripting destroyed."));
  7307. this.#willPrintCapability = null;
  7308. for (const [name, listener] of this._internalEvents) {
  7309. this.#eventBus._off(name, listener);
  7310. }
  7311. this._internalEvents.clear();
  7312. this._pageOpenPending.clear();
  7313. this._visitedPages.clear();
  7314. this.#scripting = null;
  7315. this.#ready = false;
  7316. this.#destroyCapability?.resolve();
  7317. }
  7318. }
  7319. exports.PDFScriptingManager = PDFScriptingManager;
  7320. /***/ }),
  7321. /* 25 */
  7322. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7323. Object.defineProperty(exports, "__esModule", ({
  7324. value: true
  7325. }));
  7326. exports.PDFSidebar = void 0;
  7327. var _ui_utils = __webpack_require__(3);
  7328. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7329. const SIDEBAR_MIN_WIDTH = 200;
  7330. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7331. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7332. class PDFSidebar {
  7333. #isRTL = false;
  7334. #mouseMoveBound = this.#mouseMove.bind(this);
  7335. #mouseUpBound = this.#mouseUp.bind(this);
  7336. #outerContainerWidth = null;
  7337. #width = null;
  7338. constructor({
  7339. elements,
  7340. eventBus,
  7341. l10n
  7342. }) {
  7343. this.isOpen = false;
  7344. this.active = _ui_utils.SidebarView.THUMBS;
  7345. this.isInitialViewSet = false;
  7346. this.isInitialEventDispatched = false;
  7347. this.onToggled = null;
  7348. this.onUpdateThumbnails = null;
  7349. this.outerContainer = elements.outerContainer;
  7350. this.sidebarContainer = elements.sidebarContainer;
  7351. this.toggleButton = elements.toggleButton;
  7352. this.resizer = elements.resizer;
  7353. this.thumbnailButton = elements.thumbnailButton;
  7354. this.outlineButton = elements.outlineButton;
  7355. this.attachmentsButton = elements.attachmentsButton;
  7356. this.layersButton = elements.layersButton;
  7357. this.thumbnailView = elements.thumbnailView;
  7358. this.outlineView = elements.outlineView;
  7359. this.attachmentsView = elements.attachmentsView;
  7360. this.layersView = elements.layersView;
  7361. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  7362. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7363. this.eventBus = eventBus;
  7364. this.l10n = l10n;
  7365. l10n.getDirection().then(dir => {
  7366. this.#isRTL = dir === "rtl";
  7367. });
  7368. this.#addEventListeners();
  7369. }
  7370. reset() {
  7371. this.isInitialViewSet = false;
  7372. this.isInitialEventDispatched = false;
  7373. this.#hideUINotification(true);
  7374. this.switchView(_ui_utils.SidebarView.THUMBS);
  7375. this.outlineButton.disabled = false;
  7376. this.attachmentsButton.disabled = false;
  7377. this.layersButton.disabled = false;
  7378. this._currentOutlineItemButton.disabled = true;
  7379. }
  7380. get visibleView() {
  7381. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  7382. }
  7383. setInitialView(view = _ui_utils.SidebarView.NONE) {
  7384. if (this.isInitialViewSet) {
  7385. return;
  7386. }
  7387. this.isInitialViewSet = true;
  7388. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  7389. this.#dispatchEvent();
  7390. return;
  7391. }
  7392. this.switchView(view, true);
  7393. if (!this.isInitialEventDispatched) {
  7394. this.#dispatchEvent();
  7395. }
  7396. }
  7397. switchView(view, forceOpen = false) {
  7398. const isViewChanged = view !== this.active;
  7399. let forceRendering = false;
  7400. switch (view) {
  7401. case _ui_utils.SidebarView.NONE:
  7402. if (this.isOpen) {
  7403. this.close();
  7404. }
  7405. return;
  7406. case _ui_utils.SidebarView.THUMBS:
  7407. if (this.isOpen && isViewChanged) {
  7408. forceRendering = true;
  7409. }
  7410. break;
  7411. case _ui_utils.SidebarView.OUTLINE:
  7412. if (this.outlineButton.disabled) {
  7413. return;
  7414. }
  7415. break;
  7416. case _ui_utils.SidebarView.ATTACHMENTS:
  7417. if (this.attachmentsButton.disabled) {
  7418. return;
  7419. }
  7420. break;
  7421. case _ui_utils.SidebarView.LAYERS:
  7422. if (this.layersButton.disabled) {
  7423. return;
  7424. }
  7425. break;
  7426. default:
  7427. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7428. return;
  7429. }
  7430. this.active = view;
  7431. (0, _ui_utils.toggleCheckedBtn)(this.thumbnailButton, view === _ui_utils.SidebarView.THUMBS, this.thumbnailView);
  7432. (0, _ui_utils.toggleCheckedBtn)(this.outlineButton, view === _ui_utils.SidebarView.OUTLINE, this.outlineView);
  7433. (0, _ui_utils.toggleCheckedBtn)(this.attachmentsButton, view === _ui_utils.SidebarView.ATTACHMENTS, this.attachmentsView);
  7434. (0, _ui_utils.toggleCheckedBtn)(this.layersButton, view === _ui_utils.SidebarView.LAYERS, this.layersView);
  7435. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  7436. if (forceOpen && !this.isOpen) {
  7437. this.open();
  7438. return;
  7439. }
  7440. if (forceRendering) {
  7441. this.onUpdateThumbnails();
  7442. this.onToggled();
  7443. }
  7444. if (isViewChanged) {
  7445. this.#dispatchEvent();
  7446. }
  7447. }
  7448. open() {
  7449. if (this.isOpen) {
  7450. return;
  7451. }
  7452. this.isOpen = true;
  7453. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true);
  7454. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7455. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7456. this.onUpdateThumbnails();
  7457. }
  7458. this.onToggled();
  7459. this.#dispatchEvent();
  7460. this.#hideUINotification();
  7461. }
  7462. close() {
  7463. if (!this.isOpen) {
  7464. return;
  7465. }
  7466. this.isOpen = false;
  7467. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false);
  7468. this.outerContainer.classList.add("sidebarMoving");
  7469. this.outerContainer.classList.remove("sidebarOpen");
  7470. this.onToggled();
  7471. this.#dispatchEvent();
  7472. }
  7473. toggle() {
  7474. if (this.isOpen) {
  7475. this.close();
  7476. } else {
  7477. this.open();
  7478. }
  7479. }
  7480. #dispatchEvent() {
  7481. if (this.isInitialViewSet) {
  7482. this.isInitialEventDispatched ||= true;
  7483. }
  7484. this.eventBus.dispatch("sidebarviewchanged", {
  7485. source: this,
  7486. view: this.visibleView
  7487. });
  7488. }
  7489. #showUINotification() {
  7490. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2");
  7491. this.l10n.translate(this.toggleButton);
  7492. if (!this.isOpen) {
  7493. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7494. }
  7495. }
  7496. #hideUINotification(reset = false) {
  7497. if (this.isOpen || reset) {
  7498. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7499. }
  7500. if (reset) {
  7501. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
  7502. this.l10n.translate(this.toggleButton);
  7503. }
  7504. }
  7505. #addEventListeners() {
  7506. this.sidebarContainer.addEventListener("transitionend", evt => {
  7507. if (evt.target === this.sidebarContainer) {
  7508. this.outerContainer.classList.remove("sidebarMoving");
  7509. }
  7510. });
  7511. this.toggleButton.addEventListener("click", () => {
  7512. this.toggle();
  7513. });
  7514. this.thumbnailButton.addEventListener("click", () => {
  7515. this.switchView(_ui_utils.SidebarView.THUMBS);
  7516. });
  7517. this.outlineButton.addEventListener("click", () => {
  7518. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7519. });
  7520. this.outlineButton.addEventListener("dblclick", () => {
  7521. this.eventBus.dispatch("toggleoutlinetree", {
  7522. source: this
  7523. });
  7524. });
  7525. this.attachmentsButton.addEventListener("click", () => {
  7526. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7527. });
  7528. this.layersButton.addEventListener("click", () => {
  7529. this.switchView(_ui_utils.SidebarView.LAYERS);
  7530. });
  7531. this.layersButton.addEventListener("dblclick", () => {
  7532. this.eventBus.dispatch("resetlayers", {
  7533. source: this
  7534. });
  7535. });
  7536. this._currentOutlineItemButton.addEventListener("click", () => {
  7537. this.eventBus.dispatch("currentoutlineitem", {
  7538. source: this
  7539. });
  7540. });
  7541. const onTreeLoaded = (count, button, view) => {
  7542. button.disabled = !count;
  7543. if (count) {
  7544. this.#showUINotification();
  7545. } else if (this.active === view) {
  7546. this.switchView(_ui_utils.SidebarView.THUMBS);
  7547. }
  7548. };
  7549. this.eventBus._on("outlineloaded", evt => {
  7550. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7551. evt.currentOutlineItemPromise.then(enabled => {
  7552. if (!this.isInitialViewSet) {
  7553. return;
  7554. }
  7555. this._currentOutlineItemButton.disabled = !enabled;
  7556. });
  7557. });
  7558. this.eventBus._on("attachmentsloaded", evt => {
  7559. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7560. });
  7561. this.eventBus._on("layersloaded", evt => {
  7562. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7563. });
  7564. this.eventBus._on("presentationmodechanged", evt => {
  7565. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  7566. this.onUpdateThumbnails();
  7567. }
  7568. });
  7569. this.resizer.addEventListener("mousedown", evt => {
  7570. if (evt.button !== 0) {
  7571. return;
  7572. }
  7573. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7574. window.addEventListener("mousemove", this.#mouseMoveBound);
  7575. window.addEventListener("mouseup", this.#mouseUpBound);
  7576. });
  7577. this.eventBus._on("resize", evt => {
  7578. if (evt.source !== window) {
  7579. return;
  7580. }
  7581. this.#outerContainerWidth = null;
  7582. if (!this.#width) {
  7583. return;
  7584. }
  7585. if (!this.isOpen) {
  7586. this.#updateWidth(this.#width);
  7587. return;
  7588. }
  7589. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7590. const updated = this.#updateWidth(this.#width);
  7591. Promise.resolve().then(() => {
  7592. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7593. if (updated) {
  7594. this.eventBus.dispatch("resize", {
  7595. source: this
  7596. });
  7597. }
  7598. });
  7599. });
  7600. }
  7601. get outerContainerWidth() {
  7602. return this.#outerContainerWidth ||= this.outerContainer.clientWidth;
  7603. }
  7604. #updateWidth(width = 0) {
  7605. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7606. if (width > maxWidth) {
  7607. width = maxWidth;
  7608. }
  7609. if (width < SIDEBAR_MIN_WIDTH) {
  7610. width = SIDEBAR_MIN_WIDTH;
  7611. }
  7612. if (width === this.#width) {
  7613. return false;
  7614. }
  7615. this.#width = width;
  7616. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7617. return true;
  7618. }
  7619. #mouseMove(evt) {
  7620. let width = evt.clientX;
  7621. if (this.#isRTL) {
  7622. width = this.outerContainerWidth - width;
  7623. }
  7624. this.#updateWidth(width);
  7625. }
  7626. #mouseUp(evt) {
  7627. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7628. this.eventBus.dispatch("resize", {
  7629. source: this
  7630. });
  7631. window.removeEventListener("mousemove", this.#mouseMoveBound);
  7632. window.removeEventListener("mouseup", this.#mouseUpBound);
  7633. }
  7634. }
  7635. exports.PDFSidebar = PDFSidebar;
  7636. /***/ }),
  7637. /* 26 */
  7638. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7639. Object.defineProperty(exports, "__esModule", ({
  7640. value: true
  7641. }));
  7642. exports.PDFThumbnailViewer = void 0;
  7643. var _ui_utils = __webpack_require__(3);
  7644. var _pdf_thumbnail_view = __webpack_require__(27);
  7645. const THUMBNAIL_SCROLL_MARGIN = -19;
  7646. const THUMBNAIL_SELECTED_CLASS = "selected";
  7647. class PDFThumbnailViewer {
  7648. constructor({
  7649. container,
  7650. eventBus,
  7651. linkService,
  7652. renderingQueue,
  7653. l10n,
  7654. pageColors
  7655. }) {
  7656. this.container = container;
  7657. this.eventBus = eventBus;
  7658. this.linkService = linkService;
  7659. this.renderingQueue = renderingQueue;
  7660. this.l10n = l10n;
  7661. this.pageColors = pageColors || null;
  7662. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7663. this._resetView();
  7664. }
  7665. _scrollUpdated() {
  7666. this.renderingQueue.renderHighestPriority();
  7667. }
  7668. getThumbnail(index) {
  7669. return this._thumbnails[index];
  7670. }
  7671. _getVisibleThumbs() {
  7672. return (0, _ui_utils.getVisibleElements)({
  7673. scrollEl: this.container,
  7674. views: this._thumbnails
  7675. });
  7676. }
  7677. scrollThumbnailIntoView(pageNumber) {
  7678. if (!this.pdfDocument) {
  7679. return;
  7680. }
  7681. const thumbnailView = this._thumbnails[pageNumber - 1];
  7682. if (!thumbnailView) {
  7683. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7684. return;
  7685. }
  7686. if (pageNumber !== this._currentPageNumber) {
  7687. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7688. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7689. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7690. }
  7691. const {
  7692. first,
  7693. last,
  7694. views
  7695. } = this._getVisibleThumbs();
  7696. if (views.length > 0) {
  7697. let shouldScroll = false;
  7698. if (pageNumber <= first.id || pageNumber >= last.id) {
  7699. shouldScroll = true;
  7700. } else {
  7701. for (const {
  7702. id,
  7703. percent
  7704. } of views) {
  7705. if (id !== pageNumber) {
  7706. continue;
  7707. }
  7708. shouldScroll = percent < 100;
  7709. break;
  7710. }
  7711. }
  7712. if (shouldScroll) {
  7713. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7714. top: THUMBNAIL_SCROLL_MARGIN
  7715. });
  7716. }
  7717. }
  7718. this._currentPageNumber = pageNumber;
  7719. }
  7720. get pagesRotation() {
  7721. return this._pagesRotation;
  7722. }
  7723. set pagesRotation(rotation) {
  7724. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7725. throw new Error("Invalid thumbnails rotation angle.");
  7726. }
  7727. if (!this.pdfDocument) {
  7728. return;
  7729. }
  7730. if (this._pagesRotation === rotation) {
  7731. return;
  7732. }
  7733. this._pagesRotation = rotation;
  7734. const updateArgs = {
  7735. rotation
  7736. };
  7737. for (const thumbnail of this._thumbnails) {
  7738. thumbnail.update(updateArgs);
  7739. }
  7740. }
  7741. cleanup() {
  7742. for (const thumbnail of this._thumbnails) {
  7743. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7744. thumbnail.reset();
  7745. }
  7746. }
  7747. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7748. }
  7749. _resetView() {
  7750. this._thumbnails = [];
  7751. this._currentPageNumber = 1;
  7752. this._pageLabels = null;
  7753. this._pagesRotation = 0;
  7754. this.container.textContent = "";
  7755. }
  7756. setDocument(pdfDocument) {
  7757. if (this.pdfDocument) {
  7758. this._cancelRendering();
  7759. this._resetView();
  7760. }
  7761. this.pdfDocument = pdfDocument;
  7762. if (!pdfDocument) {
  7763. return;
  7764. }
  7765. const firstPagePromise = pdfDocument.getPage(1);
  7766. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7767. firstPagePromise.then(firstPdfPage => {
  7768. const pagesCount = pdfDocument.numPages;
  7769. const viewport = firstPdfPage.getViewport({
  7770. scale: 1
  7771. });
  7772. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7773. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7774. container: this.container,
  7775. eventBus: this.eventBus,
  7776. id: pageNum,
  7777. defaultViewport: viewport.clone(),
  7778. optionalContentConfigPromise,
  7779. linkService: this.linkService,
  7780. renderingQueue: this.renderingQueue,
  7781. l10n: this.l10n,
  7782. pageColors: this.pageColors
  7783. });
  7784. this._thumbnails.push(thumbnail);
  7785. }
  7786. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  7787. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7788. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7789. }).catch(reason => {
  7790. console.error("Unable to initialize thumbnail viewer", reason);
  7791. });
  7792. }
  7793. _cancelRendering() {
  7794. for (const thumbnail of this._thumbnails) {
  7795. thumbnail.cancelRendering();
  7796. }
  7797. }
  7798. setPageLabels(labels) {
  7799. if (!this.pdfDocument) {
  7800. return;
  7801. }
  7802. if (!labels) {
  7803. this._pageLabels = null;
  7804. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7805. this._pageLabels = null;
  7806. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7807. } else {
  7808. this._pageLabels = labels;
  7809. }
  7810. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7811. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7812. }
  7813. }
  7814. async #ensurePdfPageLoaded(thumbView) {
  7815. if (thumbView.pdfPage) {
  7816. return thumbView.pdfPage;
  7817. }
  7818. try {
  7819. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7820. if (!thumbView.pdfPage) {
  7821. thumbView.setPdfPage(pdfPage);
  7822. }
  7823. return pdfPage;
  7824. } catch (reason) {
  7825. console.error("Unable to get page for thumb view", reason);
  7826. return null;
  7827. }
  7828. }
  7829. #getScrollAhead(visible) {
  7830. if (visible.first?.id === 1) {
  7831. return true;
  7832. } else if (visible.last?.id === this._thumbnails.length) {
  7833. return false;
  7834. }
  7835. return this.scroll.down;
  7836. }
  7837. forceRendering() {
  7838. const visibleThumbs = this._getVisibleThumbs();
  7839. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7840. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7841. if (thumbView) {
  7842. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7843. this.renderingQueue.renderView(thumbView);
  7844. });
  7845. return true;
  7846. }
  7847. return false;
  7848. }
  7849. }
  7850. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7851. /***/ }),
  7852. /* 27 */
  7853. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7854. Object.defineProperty(exports, "__esModule", ({
  7855. value: true
  7856. }));
  7857. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7858. var _ui_utils = __webpack_require__(3);
  7859. var _pdfjsLib = __webpack_require__(4);
  7860. const DRAW_UPSCALE_FACTOR = 2;
  7861. const MAX_NUM_SCALING_STEPS = 3;
  7862. const THUMBNAIL_WIDTH = 98;
  7863. class TempImageFactory {
  7864. static #tempCanvas = null;
  7865. static getCanvas(width, height) {
  7866. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7867. tempCanvas.width = width;
  7868. tempCanvas.height = height;
  7869. const ctx = tempCanvas.getContext("2d", {
  7870. alpha: false
  7871. });
  7872. ctx.save();
  7873. ctx.fillStyle = "rgb(255, 255, 255)";
  7874. ctx.fillRect(0, 0, width, height);
  7875. ctx.restore();
  7876. return [tempCanvas, tempCanvas.getContext("2d")];
  7877. }
  7878. static destroyCanvas() {
  7879. const tempCanvas = this.#tempCanvas;
  7880. if (tempCanvas) {
  7881. tempCanvas.width = 0;
  7882. tempCanvas.height = 0;
  7883. }
  7884. this.#tempCanvas = null;
  7885. }
  7886. }
  7887. exports.TempImageFactory = TempImageFactory;
  7888. class PDFThumbnailView {
  7889. constructor({
  7890. container,
  7891. eventBus,
  7892. id,
  7893. defaultViewport,
  7894. optionalContentConfigPromise,
  7895. linkService,
  7896. renderingQueue,
  7897. l10n,
  7898. pageColors
  7899. }) {
  7900. this.id = id;
  7901. this.renderingId = "thumbnail" + id;
  7902. this.pageLabel = null;
  7903. this.pdfPage = null;
  7904. this.rotation = 0;
  7905. this.viewport = defaultViewport;
  7906. this.pdfPageRotate = defaultViewport.rotation;
  7907. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7908. this.pageColors = pageColors || null;
  7909. this.eventBus = eventBus;
  7910. this.linkService = linkService;
  7911. this.renderingQueue = renderingQueue;
  7912. this.renderTask = null;
  7913. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7914. this.resume = null;
  7915. this.l10n = l10n;
  7916. const anchor = document.createElement("a");
  7917. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7918. this._thumbPageTitle.then(msg => {
  7919. anchor.title = msg;
  7920. });
  7921. anchor.onclick = function () {
  7922. linkService.goToPage(id);
  7923. return false;
  7924. };
  7925. this.anchor = anchor;
  7926. const div = document.createElement("div");
  7927. div.className = "thumbnail";
  7928. div.setAttribute("data-page-number", this.id);
  7929. this.div = div;
  7930. this.#updateDims();
  7931. const img = document.createElement("div");
  7932. img.className = "thumbnailImage";
  7933. this._placeholderImg = img;
  7934. div.append(img);
  7935. anchor.append(div);
  7936. container.append(anchor);
  7937. }
  7938. #updateDims() {
  7939. const {
  7940. width,
  7941. height
  7942. } = this.viewport;
  7943. const ratio = width / height;
  7944. this.canvasWidth = THUMBNAIL_WIDTH;
  7945. this.canvasHeight = this.canvasWidth / ratio | 0;
  7946. this.scale = this.canvasWidth / width;
  7947. const {
  7948. style
  7949. } = this.div;
  7950. style.setProperty("--thumbnail-width", `${this.canvasWidth}px`);
  7951. style.setProperty("--thumbnail-height", `${this.canvasHeight}px`);
  7952. }
  7953. setPdfPage(pdfPage) {
  7954. this.pdfPage = pdfPage;
  7955. this.pdfPageRotate = pdfPage.rotate;
  7956. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7957. this.viewport = pdfPage.getViewport({
  7958. scale: 1,
  7959. rotation: totalRotation
  7960. });
  7961. this.reset();
  7962. }
  7963. reset() {
  7964. this.cancelRendering();
  7965. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7966. this.div.removeAttribute("data-loaded");
  7967. this.image?.replaceWith(this._placeholderImg);
  7968. this.#updateDims();
  7969. if (this.image) {
  7970. this.image.removeAttribute("src");
  7971. delete this.image;
  7972. }
  7973. }
  7974. update({
  7975. rotation = null
  7976. }) {
  7977. if (typeof rotation === "number") {
  7978. this.rotation = rotation;
  7979. }
  7980. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7981. this.viewport = this.viewport.clone({
  7982. scale: 1,
  7983. rotation: totalRotation
  7984. });
  7985. this.reset();
  7986. }
  7987. cancelRendering() {
  7988. if (this.renderTask) {
  7989. this.renderTask.cancel();
  7990. this.renderTask = null;
  7991. }
  7992. this.resume = null;
  7993. }
  7994. _getPageDrawContext(upscaleFactor = 1) {
  7995. const canvas = document.createElement("canvas");
  7996. const ctx = canvas.getContext("2d", {
  7997. alpha: false
  7998. });
  7999. const outputScale = new _ui_utils.OutputScale();
  8000. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  8001. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  8002. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  8003. return {
  8004. ctx,
  8005. canvas,
  8006. transform
  8007. };
  8008. }
  8009. _convertCanvasToImage(canvas) {
  8010. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8011. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  8012. }
  8013. const reducedCanvas = this._reduceImage(canvas);
  8014. const image = document.createElement("img");
  8015. image.className = "thumbnailImage";
  8016. this._thumbPageCanvas.then(msg => {
  8017. image.setAttribute("aria-label", msg);
  8018. });
  8019. image.src = reducedCanvas.toDataURL();
  8020. this.image = image;
  8021. this.div.setAttribute("data-loaded", true);
  8022. this._placeholderImg.replaceWith(image);
  8023. reducedCanvas.width = 0;
  8024. reducedCanvas.height = 0;
  8025. }
  8026. async #finishRenderTask(renderTask, canvas, error = null) {
  8027. if (renderTask === this.renderTask) {
  8028. this.renderTask = null;
  8029. }
  8030. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  8031. return;
  8032. }
  8033. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8034. this._convertCanvasToImage(canvas);
  8035. if (error) {
  8036. throw error;
  8037. }
  8038. }
  8039. async draw() {
  8040. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8041. console.error("Must be in new state before drawing");
  8042. return undefined;
  8043. }
  8044. const {
  8045. pdfPage
  8046. } = this;
  8047. if (!pdfPage) {
  8048. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8049. throw new Error("pdfPage is not loaded");
  8050. }
  8051. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8052. const {
  8053. ctx,
  8054. canvas,
  8055. transform
  8056. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  8057. const drawViewport = this.viewport.clone({
  8058. scale: DRAW_UPSCALE_FACTOR * this.scale
  8059. });
  8060. const renderContinueCallback = cont => {
  8061. if (!this.renderingQueue.isHighestPriority(this)) {
  8062. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  8063. this.resume = () => {
  8064. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8065. cont();
  8066. };
  8067. return;
  8068. }
  8069. cont();
  8070. };
  8071. const renderContext = {
  8072. canvasContext: ctx,
  8073. transform,
  8074. viewport: drawViewport,
  8075. optionalContentConfigPromise: this._optionalContentConfigPromise,
  8076. pageColors: this.pageColors
  8077. };
  8078. const renderTask = this.renderTask = pdfPage.render(renderContext);
  8079. renderTask.onContinue = renderContinueCallback;
  8080. const resultPromise = renderTask.promise.then(() => this.#finishRenderTask(renderTask, canvas), error => this.#finishRenderTask(renderTask, canvas, error));
  8081. resultPromise.finally(() => {
  8082. canvas.width = 0;
  8083. canvas.height = 0;
  8084. this.eventBus.dispatch("thumbnailrendered", {
  8085. source: this,
  8086. pageNumber: this.id,
  8087. pdfPage: this.pdfPage
  8088. });
  8089. });
  8090. return resultPromise;
  8091. }
  8092. setImage(pageView) {
  8093. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8094. return;
  8095. }
  8096. const {
  8097. thumbnailCanvas: canvas,
  8098. pdfPage,
  8099. scale
  8100. } = pageView;
  8101. if (!canvas) {
  8102. return;
  8103. }
  8104. if (!this.pdfPage) {
  8105. this.setPdfPage(pdfPage);
  8106. }
  8107. if (scale < this.scale) {
  8108. return;
  8109. }
  8110. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8111. this._convertCanvasToImage(canvas);
  8112. }
  8113. _reduceImage(img) {
  8114. const {
  8115. ctx,
  8116. canvas
  8117. } = this._getPageDrawContext();
  8118. if (img.width <= 2 * canvas.width) {
  8119. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  8120. return canvas;
  8121. }
  8122. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  8123. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  8124. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  8125. while (reducedWidth > img.width || reducedHeight > img.height) {
  8126. reducedWidth >>= 1;
  8127. reducedHeight >>= 1;
  8128. }
  8129. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  8130. while (reducedWidth > 2 * canvas.width) {
  8131. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  8132. reducedWidth >>= 1;
  8133. reducedHeight >>= 1;
  8134. }
  8135. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  8136. return canvas;
  8137. }
  8138. get _thumbPageTitle() {
  8139. return this.l10n.get("thumb_page_title", {
  8140. page: this.pageLabel ?? this.id
  8141. });
  8142. }
  8143. get _thumbPageCanvas() {
  8144. return this.l10n.get("thumb_page_canvas", {
  8145. page: this.pageLabel ?? this.id
  8146. });
  8147. }
  8148. setPageLabel(label) {
  8149. this.pageLabel = typeof label === "string" ? label : null;
  8150. this._thumbPageTitle.then(msg => {
  8151. this.anchor.title = msg;
  8152. });
  8153. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8154. return;
  8155. }
  8156. this._thumbPageCanvas.then(msg => {
  8157. this.image?.setAttribute("aria-label", msg);
  8158. });
  8159. }
  8160. }
  8161. exports.PDFThumbnailView = PDFThumbnailView;
  8162. /***/ }),
  8163. /* 28 */
  8164. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8165. Object.defineProperty(exports, "__esModule", ({
  8166. value: true
  8167. }));
  8168. exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
  8169. var _pdfjsLib = __webpack_require__(4);
  8170. var _ui_utils = __webpack_require__(3);
  8171. var _l10n_utils = __webpack_require__(29);
  8172. var _pdf_page_view = __webpack_require__(30);
  8173. var _pdf_rendering_queue = __webpack_require__(23);
  8174. var _pdf_link_service = __webpack_require__(7);
  8175. const DEFAULT_CACHE_SIZE = 10;
  8176. const PagesCountLimit = {
  8177. FORCE_SCROLL_MODE_PAGE: 15000,
  8178. FORCE_LAZY_PAGE_INIT: 7500,
  8179. PAUSE_EAGER_PAGE_INIT: 250
  8180. };
  8181. exports.PagesCountLimit = PagesCountLimit;
  8182. function isValidAnnotationEditorMode(mode) {
  8183. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  8184. }
  8185. class PDFPageViewBuffer {
  8186. #buf = new Set();
  8187. #size = 0;
  8188. constructor(size) {
  8189. this.#size = size;
  8190. }
  8191. push(view) {
  8192. const buf = this.#buf;
  8193. if (buf.has(view)) {
  8194. buf.delete(view);
  8195. }
  8196. buf.add(view);
  8197. if (buf.size > this.#size) {
  8198. this.#destroyFirstView();
  8199. }
  8200. }
  8201. resize(newSize, idsToKeep = null) {
  8202. this.#size = newSize;
  8203. const buf = this.#buf;
  8204. if (idsToKeep) {
  8205. const ii = buf.size;
  8206. let i = 1;
  8207. for (const view of buf) {
  8208. if (idsToKeep.has(view.id)) {
  8209. buf.delete(view);
  8210. buf.add(view);
  8211. }
  8212. if (++i > ii) {
  8213. break;
  8214. }
  8215. }
  8216. }
  8217. while (buf.size > this.#size) {
  8218. this.#destroyFirstView();
  8219. }
  8220. }
  8221. has(view) {
  8222. return this.#buf.has(view);
  8223. }
  8224. [Symbol.iterator]() {
  8225. return this.#buf.keys();
  8226. }
  8227. #destroyFirstView() {
  8228. const firstView = this.#buf.keys().next().value;
  8229. firstView?.destroy();
  8230. this.#buf.delete(firstView);
  8231. }
  8232. }
  8233. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  8234. class PDFViewer {
  8235. #buffer = null;
  8236. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  8237. #annotationEditorUIManager = null;
  8238. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8239. #containerTopLeft = null;
  8240. #copyCallbackBound = null;
  8241. #enablePermissions = false;
  8242. #getAllTextInProgress = false;
  8243. #hiddenCopyElement = null;
  8244. #interruptCopyCondition = false;
  8245. #previousContainerHeight = 0;
  8246. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  8247. #scrollModePageState = null;
  8248. #onVisibilityChange = null;
  8249. #scaleTimeoutId = null;
  8250. #textLayerMode = _ui_utils.TextLayerMode.ENABLE;
  8251. constructor(options) {
  8252. const viewerVersion = '3.10.111';
  8253. if (_pdfjsLib.version !== viewerVersion) {
  8254. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  8255. }
  8256. this.container = options.container;
  8257. this.viewer = options.viewer || options.container.firstElementChild;
  8258. if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
  8259. throw new Error("Invalid `container` and/or `viewer` option.");
  8260. }
  8261. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  8262. throw new Error("The `container` must be absolutely positioned.");
  8263. }
  8264. this.#resizeObserver.observe(this.container);
  8265. this.eventBus = options.eventBus;
  8266. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8267. this.downloadManager = options.downloadManager || null;
  8268. this.findController = options.findController || null;
  8269. if (this.findController) {
  8270. this.findController.onIsPageVisible = pageNumber => this._getVisiblePages().ids.has(pageNumber);
  8271. }
  8272. this._scriptingManager = options.scriptingManager || null;
  8273. this.#textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  8274. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8275. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
  8276. this.imageResourcesPath = options.imageResourcesPath || "";
  8277. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8278. this.removePageBorders = options.removePageBorders || false;
  8279. if (options.useOnlyCssZoom) {
  8280. console.error("useOnlyCssZoom was removed, please use `maxCanvasPixels = 0` instead.");
  8281. options.maxCanvasPixels = 0;
  8282. }
  8283. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  8284. this.maxCanvasPixels = options.maxCanvasPixels;
  8285. this.l10n = options.l10n || _l10n_utils.NullL10n;
  8286. this.#enablePermissions = options.enablePermissions || false;
  8287. this.pageColors = options.pageColors || null;
  8288. this.defaultRenderingQueue = !options.renderingQueue;
  8289. if (this.defaultRenderingQueue) {
  8290. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8291. this.renderingQueue.setViewer(this);
  8292. } else {
  8293. this.renderingQueue = options.renderingQueue;
  8294. }
  8295. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8296. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8297. this._onBeforeDraw = this._onAfterDraw = null;
  8298. this._resetView();
  8299. if (this.removePageBorders) {
  8300. this.viewer.classList.add("removePageBorders");
  8301. }
  8302. this.#updateContainerHeightCss();
  8303. this.eventBus._on("thumbnailrendered", ({
  8304. pageNumber,
  8305. pdfPage
  8306. }) => {
  8307. const pageView = this._pages[pageNumber - 1];
  8308. if (!this.#buffer.has(pageView)) {
  8309. pdfPage?.cleanup();
  8310. }
  8311. });
  8312. }
  8313. get pagesCount() {
  8314. return this._pages.length;
  8315. }
  8316. getPageView(index) {
  8317. return this._pages[index];
  8318. }
  8319. getCachedPageViews() {
  8320. return new Set(this.#buffer);
  8321. }
  8322. get pageViewsReady() {
  8323. return this._pagesCapability.settled && this._pages.every(pageView => pageView?.pdfPage);
  8324. }
  8325. get renderForms() {
  8326. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8327. }
  8328. get enableScripting() {
  8329. return !!this._scriptingManager;
  8330. }
  8331. get currentPageNumber() {
  8332. return this._currentPageNumber;
  8333. }
  8334. set currentPageNumber(val) {
  8335. if (!Number.isInteger(val)) {
  8336. throw new Error("Invalid page number.");
  8337. }
  8338. if (!this.pdfDocument) {
  8339. return;
  8340. }
  8341. if (!this._setCurrentPageNumber(val, true)) {
  8342. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  8343. }
  8344. }
  8345. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  8346. if (this._currentPageNumber === val) {
  8347. if (resetCurrentPageView) {
  8348. this.#resetCurrentPageView();
  8349. }
  8350. return true;
  8351. }
  8352. if (!(0 < val && val <= this.pagesCount)) {
  8353. return false;
  8354. }
  8355. const previous = this._currentPageNumber;
  8356. this._currentPageNumber = val;
  8357. this.eventBus.dispatch("pagechanging", {
  8358. source: this,
  8359. pageNumber: val,
  8360. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8361. previous
  8362. });
  8363. if (resetCurrentPageView) {
  8364. this.#resetCurrentPageView();
  8365. }
  8366. return true;
  8367. }
  8368. get currentPageLabel() {
  8369. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8370. }
  8371. set currentPageLabel(val) {
  8372. if (!this.pdfDocument) {
  8373. return;
  8374. }
  8375. let page = val | 0;
  8376. if (this._pageLabels) {
  8377. const i = this._pageLabels.indexOf(val);
  8378. if (i >= 0) {
  8379. page = i + 1;
  8380. }
  8381. }
  8382. if (!this._setCurrentPageNumber(page, true)) {
  8383. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8384. }
  8385. }
  8386. get currentScale() {
  8387. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8388. }
  8389. set currentScale(val) {
  8390. if (isNaN(val)) {
  8391. throw new Error("Invalid numeric scale.");
  8392. }
  8393. if (!this.pdfDocument) {
  8394. return;
  8395. }
  8396. this.#setScale(val, {
  8397. noScroll: false
  8398. });
  8399. }
  8400. get currentScaleValue() {
  8401. return this._currentScaleValue;
  8402. }
  8403. set currentScaleValue(val) {
  8404. if (!this.pdfDocument) {
  8405. return;
  8406. }
  8407. this.#setScale(val, {
  8408. noScroll: false
  8409. });
  8410. }
  8411. get pagesRotation() {
  8412. return this._pagesRotation;
  8413. }
  8414. set pagesRotation(rotation) {
  8415. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8416. throw new Error("Invalid pages rotation angle.");
  8417. }
  8418. if (!this.pdfDocument) {
  8419. return;
  8420. }
  8421. rotation %= 360;
  8422. if (rotation < 0) {
  8423. rotation += 360;
  8424. }
  8425. if (this._pagesRotation === rotation) {
  8426. return;
  8427. }
  8428. this._pagesRotation = rotation;
  8429. const pageNumber = this._currentPageNumber;
  8430. this.refresh(true, {
  8431. rotation
  8432. });
  8433. if (this._currentScaleValue) {
  8434. this.#setScale(this._currentScaleValue, {
  8435. noScroll: true
  8436. });
  8437. }
  8438. this.eventBus.dispatch("rotationchanging", {
  8439. source: this,
  8440. pagesRotation: rotation,
  8441. pageNumber
  8442. });
  8443. if (this.defaultRenderingQueue) {
  8444. this.update();
  8445. }
  8446. }
  8447. get firstPagePromise() {
  8448. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8449. }
  8450. get onePageRendered() {
  8451. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8452. }
  8453. get pagesPromise() {
  8454. return this.pdfDocument ? this._pagesCapability.promise : null;
  8455. }
  8456. #layerProperties() {
  8457. const self = this;
  8458. return {
  8459. get annotationEditorUIManager() {
  8460. return self.#annotationEditorUIManager;
  8461. },
  8462. get annotationStorage() {
  8463. return self.pdfDocument?.annotationStorage;
  8464. },
  8465. get downloadManager() {
  8466. return self.downloadManager;
  8467. },
  8468. get enableScripting() {
  8469. return !!self._scriptingManager;
  8470. },
  8471. get fieldObjectsPromise() {
  8472. return self.pdfDocument?.getFieldObjects();
  8473. },
  8474. get findController() {
  8475. return self.findController;
  8476. },
  8477. get hasJSActionsPromise() {
  8478. return self.pdfDocument?.hasJSActions();
  8479. },
  8480. get linkService() {
  8481. return self.linkService;
  8482. }
  8483. };
  8484. }
  8485. #initializePermissions(permissions) {
  8486. const params = {
  8487. annotationEditorMode: this.#annotationEditorMode,
  8488. annotationMode: this.#annotationMode,
  8489. textLayerMode: this.#textLayerMode
  8490. };
  8491. if (!permissions) {
  8492. return params;
  8493. }
  8494. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY) && this.#textLayerMode === _ui_utils.TextLayerMode.ENABLE) {
  8495. params.textLayerMode = _ui_utils.TextLayerMode.ENABLE_PERMISSIONS;
  8496. }
  8497. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  8498. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8499. }
  8500. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8501. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8502. }
  8503. return params;
  8504. }
  8505. #onePageRenderedOrForceFetch() {
  8506. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8507. return Promise.resolve();
  8508. }
  8509. const visibilityChangePromise = new Promise(resolve => {
  8510. this.#onVisibilityChange = () => {
  8511. if (document.visibilityState !== "hidden") {
  8512. return;
  8513. }
  8514. resolve();
  8515. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8516. this.#onVisibilityChange = null;
  8517. };
  8518. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8519. });
  8520. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8521. }
  8522. async getAllText() {
  8523. const texts = [];
  8524. const buffer = [];
  8525. for (let pageNum = 1, pagesCount = this.pdfDocument.numPages; pageNum <= pagesCount; ++pageNum) {
  8526. if (this.#interruptCopyCondition) {
  8527. return null;
  8528. }
  8529. buffer.length = 0;
  8530. const page = await this.pdfDocument.getPage(pageNum);
  8531. const {
  8532. items
  8533. } = await page.getTextContent();
  8534. for (const item of items) {
  8535. if (item.str) {
  8536. buffer.push(item.str);
  8537. }
  8538. if (item.hasEOL) {
  8539. buffer.push("\n");
  8540. }
  8541. }
  8542. texts.push((0, _ui_utils.removeNullCharacters)(buffer.join("")));
  8543. }
  8544. return texts.join("\n");
  8545. }
  8546. #copyCallback(textLayerMode, event) {
  8547. const selection = document.getSelection();
  8548. const {
  8549. focusNode,
  8550. anchorNode
  8551. } = selection;
  8552. if (anchorNode && focusNode && selection.containsNode(this.#hiddenCopyElement)) {
  8553. if (this.#getAllTextInProgress || textLayerMode === _ui_utils.TextLayerMode.ENABLE_PERMISSIONS) {
  8554. event.preventDefault();
  8555. event.stopPropagation();
  8556. return;
  8557. }
  8558. this.#getAllTextInProgress = true;
  8559. const savedCursor = this.container.style.cursor;
  8560. this.container.style.cursor = "wait";
  8561. const interruptCopy = ev => this.#interruptCopyCondition = ev.key === "Escape";
  8562. window.addEventListener("keydown", interruptCopy);
  8563. this.getAllText().then(async text => {
  8564. if (text !== null) {
  8565. await navigator.clipboard.writeText(text);
  8566. }
  8567. }).catch(reason => {
  8568. console.warn(`Something goes wrong when extracting the text: ${reason.message}`);
  8569. }).finally(() => {
  8570. this.#getAllTextInProgress = false;
  8571. this.#interruptCopyCondition = false;
  8572. window.removeEventListener("keydown", interruptCopy);
  8573. this.container.style.cursor = savedCursor;
  8574. });
  8575. event.preventDefault();
  8576. event.stopPropagation();
  8577. }
  8578. }
  8579. setDocument(pdfDocument) {
  8580. if (this.pdfDocument) {
  8581. this.eventBus.dispatch("pagesdestroy", {
  8582. source: this
  8583. });
  8584. this._cancelRendering();
  8585. this._resetView();
  8586. this.findController?.setDocument(null);
  8587. this._scriptingManager?.setDocument(null);
  8588. if (this.#annotationEditorUIManager) {
  8589. this.#annotationEditorUIManager.destroy();
  8590. this.#annotationEditorUIManager = null;
  8591. }
  8592. }
  8593. this.pdfDocument = pdfDocument;
  8594. if (!pdfDocument) {
  8595. return;
  8596. }
  8597. const pagesCount = pdfDocument.numPages;
  8598. const firstPagePromise = pdfDocument.getPage(1);
  8599. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8600. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8601. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8602. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8603. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8604. this.eventBus.dispatch("scrollmodechanged", {
  8605. source: this,
  8606. mode
  8607. });
  8608. }
  8609. this._pagesCapability.promise.then(() => {
  8610. this.eventBus.dispatch("pagesloaded", {
  8611. source: this,
  8612. pagesCount
  8613. });
  8614. }, () => {});
  8615. this._onBeforeDraw = evt => {
  8616. const pageView = this._pages[evt.pageNumber - 1];
  8617. if (!pageView) {
  8618. return;
  8619. }
  8620. this.#buffer.push(pageView);
  8621. };
  8622. this.eventBus._on("pagerender", this._onBeforeDraw);
  8623. this._onAfterDraw = evt => {
  8624. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8625. return;
  8626. }
  8627. this._onePageRenderedCapability.resolve({
  8628. timestamp: evt.timestamp
  8629. });
  8630. this.eventBus._off("pagerendered", this._onAfterDraw);
  8631. this._onAfterDraw = null;
  8632. if (this.#onVisibilityChange) {
  8633. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8634. this.#onVisibilityChange = null;
  8635. }
  8636. };
  8637. this.eventBus._on("pagerendered", this._onAfterDraw);
  8638. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8639. if (pdfDocument !== this.pdfDocument) {
  8640. return;
  8641. }
  8642. this._firstPageCapability.resolve(firstPdfPage);
  8643. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8644. const {
  8645. annotationEditorMode,
  8646. annotationMode,
  8647. textLayerMode
  8648. } = this.#initializePermissions(permissions);
  8649. if (textLayerMode !== _ui_utils.TextLayerMode.DISABLE) {
  8650. const element = this.#hiddenCopyElement = document.createElement("div");
  8651. element.id = "hiddenCopyElement";
  8652. this.viewer.before(element);
  8653. }
  8654. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  8655. const mode = annotationEditorMode;
  8656. if (pdfDocument.isPureXfa) {
  8657. console.warn("Warning: XFA-editing is not implemented.");
  8658. } else if (isValidAnnotationEditorMode(mode)) {
  8659. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.viewer, this.eventBus, pdfDocument, this.pageColors);
  8660. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  8661. this.#annotationEditorUIManager.updateMode(mode);
  8662. }
  8663. } else {
  8664. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  8665. }
  8666. }
  8667. const layerProperties = this.#layerProperties.bind(this);
  8668. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8669. const scale = this.currentScale;
  8670. const viewport = firstPdfPage.getViewport({
  8671. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8672. });
  8673. this.viewer.style.setProperty("--scale-factor", viewport.scale);
  8674. if (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas") {
  8675. this.viewer.style.setProperty("--hcm-highligh-filter", pdfDocument.filterFactory.addHighlightHCMFilter("CanvasText", "Canvas", "HighlightText", "Highlight"));
  8676. }
  8677. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8678. const pageView = new _pdf_page_view.PDFPageView({
  8679. container: viewerElement,
  8680. eventBus: this.eventBus,
  8681. id: pageNum,
  8682. scale,
  8683. defaultViewport: viewport.clone(),
  8684. optionalContentConfigPromise,
  8685. renderingQueue: this.renderingQueue,
  8686. textLayerMode,
  8687. annotationMode,
  8688. imageResourcesPath: this.imageResourcesPath,
  8689. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  8690. maxCanvasPixels: this.maxCanvasPixels,
  8691. pageColors: this.pageColors,
  8692. l10n: this.l10n,
  8693. layerProperties
  8694. });
  8695. this._pages.push(pageView);
  8696. }
  8697. const firstPageView = this._pages[0];
  8698. if (firstPageView) {
  8699. firstPageView.setPdfPage(firstPdfPage);
  8700. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8701. }
  8702. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8703. this.#ensurePageViewVisible();
  8704. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8705. this._updateSpreadMode();
  8706. }
  8707. this.#onePageRenderedOrForceFetch().then(async () => {
  8708. this.findController?.setDocument(pdfDocument);
  8709. this._scriptingManager?.setDocument(pdfDocument);
  8710. if (this.#hiddenCopyElement) {
  8711. this.#copyCallbackBound = this.#copyCallback.bind(this, textLayerMode);
  8712. document.addEventListener("copy", this.#copyCallbackBound);
  8713. }
  8714. if (this.#annotationEditorUIManager) {
  8715. this.eventBus.dispatch("annotationeditormodechanged", {
  8716. source: this,
  8717. mode: this.#annotationEditorMode
  8718. });
  8719. }
  8720. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8721. this._pagesCapability.resolve();
  8722. return;
  8723. }
  8724. let getPagesLeft = pagesCount - 1;
  8725. if (getPagesLeft <= 0) {
  8726. this._pagesCapability.resolve();
  8727. return;
  8728. }
  8729. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8730. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8731. const pageView = this._pages[pageNum - 1];
  8732. if (!pageView.pdfPage) {
  8733. pageView.setPdfPage(pdfPage);
  8734. }
  8735. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8736. if (--getPagesLeft === 0) {
  8737. this._pagesCapability.resolve();
  8738. }
  8739. }, reason => {
  8740. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8741. if (--getPagesLeft === 0) {
  8742. this._pagesCapability.resolve();
  8743. }
  8744. });
  8745. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8746. await promise;
  8747. }
  8748. }
  8749. });
  8750. this.eventBus.dispatch("pagesinit", {
  8751. source: this
  8752. });
  8753. pdfDocument.getMetadata().then(({
  8754. info
  8755. }) => {
  8756. if (pdfDocument !== this.pdfDocument) {
  8757. return;
  8758. }
  8759. if (info.Language) {
  8760. this.viewer.lang = info.Language;
  8761. }
  8762. });
  8763. if (this.defaultRenderingQueue) {
  8764. this.update();
  8765. }
  8766. }).catch(reason => {
  8767. console.error("Unable to initialize viewer", reason);
  8768. this._pagesCapability.reject(reason);
  8769. });
  8770. }
  8771. setPageLabels(labels) {
  8772. if (!this.pdfDocument) {
  8773. return;
  8774. }
  8775. if (!labels) {
  8776. this._pageLabels = null;
  8777. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8778. this._pageLabels = null;
  8779. console.error(`setPageLabels: Invalid page labels.`);
  8780. } else {
  8781. this._pageLabels = labels;
  8782. }
  8783. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8784. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8785. }
  8786. }
  8787. _resetView() {
  8788. this._pages = [];
  8789. this._currentPageNumber = 1;
  8790. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8791. this._currentScaleValue = null;
  8792. this._pageLabels = null;
  8793. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8794. this._location = null;
  8795. this._pagesRotation = 0;
  8796. this._optionalContentConfigPromise = null;
  8797. this._firstPageCapability = new _pdfjsLib.PromiseCapability();
  8798. this._onePageRenderedCapability = new _pdfjsLib.PromiseCapability();
  8799. this._pagesCapability = new _pdfjsLib.PromiseCapability();
  8800. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8801. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8802. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8803. this.#scrollModePageState = {
  8804. previousPageNumber: 1,
  8805. scrollDown: true,
  8806. pages: []
  8807. };
  8808. if (this._onBeforeDraw) {
  8809. this.eventBus._off("pagerender", this._onBeforeDraw);
  8810. this._onBeforeDraw = null;
  8811. }
  8812. if (this._onAfterDraw) {
  8813. this.eventBus._off("pagerendered", this._onAfterDraw);
  8814. this._onAfterDraw = null;
  8815. }
  8816. if (this.#onVisibilityChange) {
  8817. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8818. this.#onVisibilityChange = null;
  8819. }
  8820. this.viewer.textContent = "";
  8821. this._updateScrollMode();
  8822. this.viewer.removeAttribute("lang");
  8823. if (this.#hiddenCopyElement) {
  8824. document.removeEventListener("copy", this.#copyCallbackBound);
  8825. this.#copyCallbackBound = null;
  8826. this.#hiddenCopyElement.remove();
  8827. this.#hiddenCopyElement = null;
  8828. }
  8829. }
  8830. #ensurePageViewVisible() {
  8831. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8832. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8833. }
  8834. const pageNumber = this._currentPageNumber,
  8835. state = this.#scrollModePageState,
  8836. viewer = this.viewer;
  8837. viewer.textContent = "";
  8838. state.pages.length = 0;
  8839. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8840. const pageView = this._pages[pageNumber - 1];
  8841. viewer.append(pageView.div);
  8842. state.pages.push(pageView);
  8843. } else {
  8844. const pageIndexSet = new Set(),
  8845. parity = this._spreadMode - 1;
  8846. if (parity === -1) {
  8847. pageIndexSet.add(pageNumber - 1);
  8848. } else if (pageNumber % 2 !== parity) {
  8849. pageIndexSet.add(pageNumber - 1);
  8850. pageIndexSet.add(pageNumber);
  8851. } else {
  8852. pageIndexSet.add(pageNumber - 2);
  8853. pageIndexSet.add(pageNumber - 1);
  8854. }
  8855. const spread = document.createElement("div");
  8856. spread.className = "spread";
  8857. if (this.isInPresentationMode) {
  8858. const dummyPage = document.createElement("div");
  8859. dummyPage.className = "dummyPage";
  8860. spread.append(dummyPage);
  8861. }
  8862. for (const i of pageIndexSet) {
  8863. const pageView = this._pages[i];
  8864. if (!pageView) {
  8865. continue;
  8866. }
  8867. spread.append(pageView.div);
  8868. state.pages.push(pageView);
  8869. }
  8870. viewer.append(spread);
  8871. }
  8872. state.scrollDown = pageNumber >= state.previousPageNumber;
  8873. state.previousPageNumber = pageNumber;
  8874. }
  8875. _scrollUpdate() {
  8876. if (this.pagesCount === 0) {
  8877. return;
  8878. }
  8879. this.update();
  8880. }
  8881. #scrollIntoView(pageView, pageSpot = null) {
  8882. const {
  8883. div,
  8884. id
  8885. } = pageView;
  8886. if (this._currentPageNumber !== id) {
  8887. this._setCurrentPageNumber(id);
  8888. }
  8889. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8890. this.#ensurePageViewVisible();
  8891. this.update();
  8892. }
  8893. if (!pageSpot && !this.isInPresentationMode) {
  8894. const left = div.offsetLeft + div.clientLeft,
  8895. right = left + div.clientWidth;
  8896. const {
  8897. scrollLeft,
  8898. clientWidth
  8899. } = this.container;
  8900. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8901. pageSpot = {
  8902. left: 0,
  8903. top: 0
  8904. };
  8905. }
  8906. }
  8907. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8908. if (!this._currentScaleValue && this._location) {
  8909. this._location = null;
  8910. }
  8911. }
  8912. #isSameScale(newScale) {
  8913. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8914. }
  8915. #setScaleUpdatePages(newScale, newValue, {
  8916. noScroll = false,
  8917. preset = false,
  8918. drawingDelay = -1
  8919. }) {
  8920. this._currentScaleValue = newValue.toString();
  8921. if (this.#isSameScale(newScale)) {
  8922. if (preset) {
  8923. this.eventBus.dispatch("scalechanging", {
  8924. source: this,
  8925. scale: newScale,
  8926. presetValue: newValue
  8927. });
  8928. }
  8929. return;
  8930. }
  8931. this.viewer.style.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8932. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  8933. this.refresh(true, {
  8934. scale: newScale,
  8935. drawingDelay: postponeDrawing ? drawingDelay : -1
  8936. });
  8937. if (postponeDrawing) {
  8938. this.#scaleTimeoutId = setTimeout(() => {
  8939. this.#scaleTimeoutId = null;
  8940. this.refresh();
  8941. }, drawingDelay);
  8942. }
  8943. this._currentScale = newScale;
  8944. if (!noScroll) {
  8945. let page = this._currentPageNumber,
  8946. dest;
  8947. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8948. page = this._location.pageNumber;
  8949. dest = [null, {
  8950. name: "XYZ"
  8951. }, this._location.left, this._location.top, null];
  8952. }
  8953. this.scrollPageIntoView({
  8954. pageNumber: page,
  8955. destArray: dest,
  8956. allowNegativeOffset: true
  8957. });
  8958. }
  8959. this.eventBus.dispatch("scalechanging", {
  8960. source: this,
  8961. scale: newScale,
  8962. presetValue: preset ? newValue : undefined
  8963. });
  8964. if (this.defaultRenderingQueue) {
  8965. this.update();
  8966. }
  8967. }
  8968. get #pageWidthScaleFactor() {
  8969. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8970. return 2;
  8971. }
  8972. return 1;
  8973. }
  8974. #setScale(value, options) {
  8975. let scale = parseFloat(value);
  8976. if (scale > 0) {
  8977. options.preset = false;
  8978. this.#setScaleUpdatePages(scale, value, options);
  8979. } else {
  8980. const currentPage = this._pages[this._currentPageNumber - 1];
  8981. if (!currentPage) {
  8982. return;
  8983. }
  8984. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8985. vPadding = _ui_utils.VERTICAL_PADDING;
  8986. if (this.isInPresentationMode) {
  8987. hPadding = vPadding = 4;
  8988. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8989. hPadding *= 2;
  8990. }
  8991. } else if (this.removePageBorders) {
  8992. hPadding = vPadding = 0;
  8993. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8994. [hPadding, vPadding] = [vPadding, hPadding];
  8995. }
  8996. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor;
  8997. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8998. switch (value) {
  8999. case "page-actual":
  9000. scale = 1;
  9001. break;
  9002. case "page-width":
  9003. scale = pageWidthScale;
  9004. break;
  9005. case "page-height":
  9006. scale = pageHeightScale;
  9007. break;
  9008. case "page-fit":
  9009. scale = Math.min(pageWidthScale, pageHeightScale);
  9010. break;
  9011. case "auto":
  9012. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  9013. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  9014. break;
  9015. default:
  9016. console.error(`#setScale: "${value}" is an unknown zoom value.`);
  9017. return;
  9018. }
  9019. options.preset = true;
  9020. this.#setScaleUpdatePages(scale, value, options);
  9021. }
  9022. }
  9023. #resetCurrentPageView() {
  9024. const pageView = this._pages[this._currentPageNumber - 1];
  9025. if (this.isInPresentationMode) {
  9026. this.#setScale(this._currentScaleValue, {
  9027. noScroll: true
  9028. });
  9029. }
  9030. this.#scrollIntoView(pageView);
  9031. }
  9032. pageLabelToPageNumber(label) {
  9033. if (!this._pageLabels) {
  9034. return null;
  9035. }
  9036. const i = this._pageLabels.indexOf(label);
  9037. if (i < 0) {
  9038. return null;
  9039. }
  9040. return i + 1;
  9041. }
  9042. scrollPageIntoView({
  9043. pageNumber,
  9044. destArray = null,
  9045. allowNegativeOffset = false,
  9046. ignoreDestinationZoom = false
  9047. }) {
  9048. if (!this.pdfDocument) {
  9049. return;
  9050. }
  9051. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  9052. if (!pageView) {
  9053. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  9054. return;
  9055. }
  9056. if (this.isInPresentationMode || !destArray) {
  9057. this._setCurrentPageNumber(pageNumber, true);
  9058. return;
  9059. }
  9060. let x = 0,
  9061. y = 0;
  9062. let width = 0,
  9063. height = 0,
  9064. widthScale,
  9065. heightScale;
  9066. const changeOrientation = pageView.rotation % 180 !== 0;
  9067. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9068. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9069. let scale = 0;
  9070. switch (destArray[1].name) {
  9071. case "XYZ":
  9072. x = destArray[2];
  9073. y = destArray[3];
  9074. scale = destArray[4];
  9075. x = x !== null ? x : 0;
  9076. y = y !== null ? y : pageHeight;
  9077. break;
  9078. case "Fit":
  9079. case "FitB":
  9080. scale = "page-fit";
  9081. break;
  9082. case "FitH":
  9083. case "FitBH":
  9084. y = destArray[2];
  9085. scale = "page-width";
  9086. if (y === null && this._location) {
  9087. x = this._location.left;
  9088. y = this._location.top;
  9089. } else if (typeof y !== "number" || y < 0) {
  9090. y = pageHeight;
  9091. }
  9092. break;
  9093. case "FitV":
  9094. case "FitBV":
  9095. x = destArray[2];
  9096. width = pageWidth;
  9097. height = pageHeight;
  9098. scale = "page-height";
  9099. break;
  9100. case "FitR":
  9101. x = destArray[2];
  9102. y = destArray[3];
  9103. width = destArray[4] - x;
  9104. height = destArray[5] - y;
  9105. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  9106. vPadding = _ui_utils.VERTICAL_PADDING;
  9107. if (this.removePageBorders) {
  9108. hPadding = vPadding = 0;
  9109. }
  9110. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9111. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9112. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  9113. break;
  9114. default:
  9115. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  9116. return;
  9117. }
  9118. if (!ignoreDestinationZoom) {
  9119. if (scale && scale !== this._currentScale) {
  9120. this.currentScaleValue = scale;
  9121. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  9122. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  9123. }
  9124. }
  9125. if (scale === "page-fit" && !destArray[4]) {
  9126. this.#scrollIntoView(pageView);
  9127. return;
  9128. }
  9129. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  9130. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  9131. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  9132. if (!allowNegativeOffset) {
  9133. left = Math.max(left, 0);
  9134. top = Math.max(top, 0);
  9135. }
  9136. this.#scrollIntoView(pageView, {
  9137. left,
  9138. top
  9139. });
  9140. }
  9141. _updateLocation(firstPage) {
  9142. const currentScale = this._currentScale;
  9143. const currentScaleValue = this._currentScaleValue;
  9144. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  9145. const pageNumber = firstPage.id;
  9146. const currentPageView = this._pages[pageNumber - 1];
  9147. const container = this.container;
  9148. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  9149. const intLeft = Math.round(topLeft[0]);
  9150. const intTop = Math.round(topLeft[1]);
  9151. let pdfOpenParams = `#page=${pageNumber}`;
  9152. if (!this.isInPresentationMode) {
  9153. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  9154. }
  9155. this._location = {
  9156. pageNumber,
  9157. scale: normalizedScaleValue,
  9158. top: intTop,
  9159. left: intLeft,
  9160. rotation: this._pagesRotation,
  9161. pdfOpenParams
  9162. };
  9163. }
  9164. update() {
  9165. const visible = this._getVisiblePages();
  9166. const visiblePages = visible.views,
  9167. numVisiblePages = visiblePages.length;
  9168. if (numVisiblePages === 0) {
  9169. return;
  9170. }
  9171. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  9172. this.#buffer.resize(newCacheSize, visible.ids);
  9173. this.renderingQueue.renderHighestPriority(visible);
  9174. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  9175. const currentId = this._currentPageNumber;
  9176. let stillFullyVisible = false;
  9177. for (const page of visiblePages) {
  9178. if (page.percent < 100) {
  9179. break;
  9180. }
  9181. if (page.id === currentId && isSimpleLayout) {
  9182. stillFullyVisible = true;
  9183. break;
  9184. }
  9185. }
  9186. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  9187. this._updateLocation(visible.first);
  9188. this.eventBus.dispatch("updateviewarea", {
  9189. source: this,
  9190. location: this._location
  9191. });
  9192. }
  9193. containsElement(element) {
  9194. return this.container.contains(element);
  9195. }
  9196. focus() {
  9197. this.container.focus();
  9198. }
  9199. get _isContainerRtl() {
  9200. return getComputedStyle(this.container).direction === "rtl";
  9201. }
  9202. get isInPresentationMode() {
  9203. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  9204. }
  9205. get isChangingPresentationMode() {
  9206. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  9207. }
  9208. get isHorizontalScrollbarEnabled() {
  9209. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  9210. }
  9211. get isVerticalScrollbarEnabled() {
  9212. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  9213. }
  9214. _getVisiblePages() {
  9215. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  9216. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  9217. rtl = horizontal && this._isContainerRtl;
  9218. return (0, _ui_utils.getVisibleElements)({
  9219. scrollEl: this.container,
  9220. views,
  9221. sortByVisibility: true,
  9222. horizontal,
  9223. rtl
  9224. });
  9225. }
  9226. cleanup() {
  9227. for (const pageView of this._pages) {
  9228. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  9229. pageView.reset();
  9230. }
  9231. }
  9232. }
  9233. _cancelRendering() {
  9234. for (const pageView of this._pages) {
  9235. pageView.cancelRendering();
  9236. }
  9237. }
  9238. async #ensurePdfPageLoaded(pageView) {
  9239. if (pageView.pdfPage) {
  9240. return pageView.pdfPage;
  9241. }
  9242. try {
  9243. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  9244. if (!pageView.pdfPage) {
  9245. pageView.setPdfPage(pdfPage);
  9246. }
  9247. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  9248. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  9249. }
  9250. return pdfPage;
  9251. } catch (reason) {
  9252. console.error("Unable to get page for page view", reason);
  9253. return null;
  9254. }
  9255. }
  9256. #getScrollAhead(visible) {
  9257. if (visible.first?.id === 1) {
  9258. return true;
  9259. } else if (visible.last?.id === this.pagesCount) {
  9260. return false;
  9261. }
  9262. switch (this._scrollMode) {
  9263. case _ui_utils.ScrollMode.PAGE:
  9264. return this.#scrollModePageState.scrollDown;
  9265. case _ui_utils.ScrollMode.HORIZONTAL:
  9266. return this.scroll.right;
  9267. }
  9268. return this.scroll.down;
  9269. }
  9270. forceRendering(currentlyVisiblePages) {
  9271. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9272. const scrollAhead = this.#getScrollAhead(visiblePages);
  9273. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9274. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9275. if (pageView) {
  9276. this.#ensurePdfPageLoaded(pageView).then(() => {
  9277. this.renderingQueue.renderView(pageView);
  9278. });
  9279. return true;
  9280. }
  9281. return false;
  9282. }
  9283. get hasEqualPageSizes() {
  9284. const firstPageView = this._pages[0];
  9285. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  9286. const pageView = this._pages[i];
  9287. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9288. return false;
  9289. }
  9290. }
  9291. return true;
  9292. }
  9293. getPagesOverview() {
  9294. let initialOrientation;
  9295. return this._pages.map(pageView => {
  9296. const viewport = pageView.pdfPage.getViewport({
  9297. scale: 1
  9298. });
  9299. const orientation = (0, _ui_utils.isPortraitOrientation)(viewport);
  9300. if (initialOrientation === undefined) {
  9301. initialOrientation = orientation;
  9302. } else if (this.enablePrintAutoRotate && orientation !== initialOrientation) {
  9303. return {
  9304. width: viewport.height,
  9305. height: viewport.width,
  9306. rotation: (viewport.rotation - 90) % 360
  9307. };
  9308. }
  9309. return {
  9310. width: viewport.width,
  9311. height: viewport.height,
  9312. rotation: viewport.rotation
  9313. };
  9314. });
  9315. }
  9316. get optionalContentConfigPromise() {
  9317. if (!this.pdfDocument) {
  9318. return Promise.resolve(null);
  9319. }
  9320. if (!this._optionalContentConfigPromise) {
  9321. console.error("optionalContentConfigPromise: Not initialized yet.");
  9322. return this.pdfDocument.getOptionalContentConfig();
  9323. }
  9324. return this._optionalContentConfigPromise;
  9325. }
  9326. set optionalContentConfigPromise(promise) {
  9327. if (!(promise instanceof Promise)) {
  9328. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  9329. }
  9330. if (!this.pdfDocument) {
  9331. return;
  9332. }
  9333. if (!this._optionalContentConfigPromise) {
  9334. return;
  9335. }
  9336. this._optionalContentConfigPromise = promise;
  9337. this.refresh(false, {
  9338. optionalContentConfigPromise: promise
  9339. });
  9340. this.eventBus.dispatch("optionalcontentconfigchanged", {
  9341. source: this,
  9342. promise
  9343. });
  9344. }
  9345. get scrollMode() {
  9346. return this._scrollMode;
  9347. }
  9348. set scrollMode(mode) {
  9349. if (this._scrollMode === mode) {
  9350. return;
  9351. }
  9352. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9353. throw new Error(`Invalid scroll mode: ${mode}`);
  9354. }
  9355. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9356. return;
  9357. }
  9358. this._previousScrollMode = this._scrollMode;
  9359. this._scrollMode = mode;
  9360. this.eventBus.dispatch("scrollmodechanged", {
  9361. source: this,
  9362. mode
  9363. });
  9364. this._updateScrollMode(this._currentPageNumber);
  9365. }
  9366. _updateScrollMode(pageNumber = null) {
  9367. const scrollMode = this._scrollMode,
  9368. viewer = this.viewer;
  9369. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9370. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9371. if (!this.pdfDocument || !pageNumber) {
  9372. return;
  9373. }
  9374. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9375. this.#ensurePageViewVisible();
  9376. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9377. this._updateSpreadMode();
  9378. }
  9379. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9380. this.#setScale(this._currentScaleValue, {
  9381. noScroll: true
  9382. });
  9383. }
  9384. this._setCurrentPageNumber(pageNumber, true);
  9385. this.update();
  9386. }
  9387. get spreadMode() {
  9388. return this._spreadMode;
  9389. }
  9390. set spreadMode(mode) {
  9391. if (this._spreadMode === mode) {
  9392. return;
  9393. }
  9394. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9395. throw new Error(`Invalid spread mode: ${mode}`);
  9396. }
  9397. this._spreadMode = mode;
  9398. this.eventBus.dispatch("spreadmodechanged", {
  9399. source: this,
  9400. mode
  9401. });
  9402. this._updateSpreadMode(this._currentPageNumber);
  9403. }
  9404. _updateSpreadMode(pageNumber = null) {
  9405. if (!this.pdfDocument) {
  9406. return;
  9407. }
  9408. const viewer = this.viewer,
  9409. pages = this._pages;
  9410. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9411. this.#ensurePageViewVisible();
  9412. } else {
  9413. viewer.textContent = "";
  9414. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9415. for (const pageView of this._pages) {
  9416. viewer.append(pageView.div);
  9417. }
  9418. } else {
  9419. const parity = this._spreadMode - 1;
  9420. let spread = null;
  9421. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9422. if (spread === null) {
  9423. spread = document.createElement("div");
  9424. spread.className = "spread";
  9425. viewer.append(spread);
  9426. } else if (i % 2 === parity) {
  9427. spread = spread.cloneNode(false);
  9428. viewer.append(spread);
  9429. }
  9430. spread.append(pages[i].div);
  9431. }
  9432. }
  9433. }
  9434. if (!pageNumber) {
  9435. return;
  9436. }
  9437. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9438. this.#setScale(this._currentScaleValue, {
  9439. noScroll: true
  9440. });
  9441. }
  9442. this._setCurrentPageNumber(pageNumber, true);
  9443. this.update();
  9444. }
  9445. _getPageAdvance(currentPageNumber, previous = false) {
  9446. switch (this._scrollMode) {
  9447. case _ui_utils.ScrollMode.WRAPPED:
  9448. {
  9449. const {
  9450. views
  9451. } = this._getVisiblePages(),
  9452. pageLayout = new Map();
  9453. for (const {
  9454. id,
  9455. y,
  9456. percent,
  9457. widthPercent
  9458. } of views) {
  9459. if (percent === 0 || widthPercent < 100) {
  9460. continue;
  9461. }
  9462. let yArray = pageLayout.get(y);
  9463. if (!yArray) {
  9464. pageLayout.set(y, yArray ||= []);
  9465. }
  9466. yArray.push(id);
  9467. }
  9468. for (const yArray of pageLayout.values()) {
  9469. const currentIndex = yArray.indexOf(currentPageNumber);
  9470. if (currentIndex === -1) {
  9471. continue;
  9472. }
  9473. const numPages = yArray.length;
  9474. if (numPages === 1) {
  9475. break;
  9476. }
  9477. if (previous) {
  9478. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9479. const currentId = yArray[i],
  9480. expectedId = yArray[i + 1] - 1;
  9481. if (currentId < expectedId) {
  9482. return currentPageNumber - expectedId;
  9483. }
  9484. }
  9485. } else {
  9486. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9487. const currentId = yArray[i],
  9488. expectedId = yArray[i - 1] + 1;
  9489. if (currentId > expectedId) {
  9490. return expectedId - currentPageNumber;
  9491. }
  9492. }
  9493. }
  9494. if (previous) {
  9495. const firstId = yArray[0];
  9496. if (firstId < currentPageNumber) {
  9497. return currentPageNumber - firstId + 1;
  9498. }
  9499. } else {
  9500. const lastId = yArray[numPages - 1];
  9501. if (lastId > currentPageNumber) {
  9502. return lastId - currentPageNumber + 1;
  9503. }
  9504. }
  9505. break;
  9506. }
  9507. break;
  9508. }
  9509. case _ui_utils.ScrollMode.HORIZONTAL:
  9510. {
  9511. break;
  9512. }
  9513. case _ui_utils.ScrollMode.PAGE:
  9514. case _ui_utils.ScrollMode.VERTICAL:
  9515. {
  9516. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9517. break;
  9518. }
  9519. const parity = this._spreadMode - 1;
  9520. if (previous && currentPageNumber % 2 !== parity) {
  9521. break;
  9522. } else if (!previous && currentPageNumber % 2 === parity) {
  9523. break;
  9524. }
  9525. const {
  9526. views
  9527. } = this._getVisiblePages(),
  9528. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9529. for (const {
  9530. id,
  9531. percent,
  9532. widthPercent
  9533. } of views) {
  9534. if (id !== expectedId) {
  9535. continue;
  9536. }
  9537. if (percent > 0 && widthPercent === 100) {
  9538. return 2;
  9539. }
  9540. break;
  9541. }
  9542. break;
  9543. }
  9544. }
  9545. return 1;
  9546. }
  9547. nextPage() {
  9548. const currentPageNumber = this._currentPageNumber,
  9549. pagesCount = this.pagesCount;
  9550. if (currentPageNumber >= pagesCount) {
  9551. return false;
  9552. }
  9553. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9554. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9555. return true;
  9556. }
  9557. previousPage() {
  9558. const currentPageNumber = this._currentPageNumber;
  9559. if (currentPageNumber <= 1) {
  9560. return false;
  9561. }
  9562. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9563. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9564. return true;
  9565. }
  9566. increaseScale({
  9567. drawingDelay,
  9568. scaleFactor,
  9569. steps
  9570. } = {}) {
  9571. if (!this.pdfDocument) {
  9572. return;
  9573. }
  9574. let newScale = this._currentScale;
  9575. if (scaleFactor > 1) {
  9576. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  9577. } else {
  9578. steps ??= 1;
  9579. do {
  9580. newScale = Math.ceil((newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
  9581. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9582. }
  9583. this.#setScale(Math.min(_ui_utils.MAX_SCALE, newScale), {
  9584. noScroll: false,
  9585. drawingDelay
  9586. });
  9587. }
  9588. decreaseScale({
  9589. drawingDelay,
  9590. scaleFactor,
  9591. steps
  9592. } = {}) {
  9593. if (!this.pdfDocument) {
  9594. return;
  9595. }
  9596. let newScale = this._currentScale;
  9597. if (scaleFactor > 0 && scaleFactor < 1) {
  9598. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  9599. } else {
  9600. steps ??= 1;
  9601. do {
  9602. newScale = Math.floor((newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
  9603. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9604. }
  9605. this.#setScale(Math.max(_ui_utils.MIN_SCALE, newScale), {
  9606. noScroll: false,
  9607. drawingDelay
  9608. });
  9609. }
  9610. #updateContainerHeightCss(height = this.container.clientHeight) {
  9611. if (height !== this.#previousContainerHeight) {
  9612. this.#previousContainerHeight = height;
  9613. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  9614. }
  9615. }
  9616. #resizeObserverCallback(entries) {
  9617. for (const entry of entries) {
  9618. if (entry.target === this.container) {
  9619. this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
  9620. this.#containerTopLeft = null;
  9621. break;
  9622. }
  9623. }
  9624. }
  9625. get containerTopLeft() {
  9626. return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
  9627. }
  9628. get annotationEditorMode() {
  9629. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  9630. }
  9631. set annotationEditorMode({
  9632. mode,
  9633. editId = null
  9634. }) {
  9635. if (!this.#annotationEditorUIManager) {
  9636. throw new Error(`The AnnotationEditor is not enabled.`);
  9637. }
  9638. if (this.#annotationEditorMode === mode) {
  9639. return;
  9640. }
  9641. if (!isValidAnnotationEditorMode(mode)) {
  9642. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  9643. }
  9644. if (!this.pdfDocument) {
  9645. return;
  9646. }
  9647. this.#annotationEditorMode = mode;
  9648. this.eventBus.dispatch("annotationeditormodechanged", {
  9649. source: this,
  9650. mode
  9651. });
  9652. this.#annotationEditorUIManager.updateMode(mode, editId);
  9653. }
  9654. set annotationEditorParams({
  9655. type,
  9656. value
  9657. }) {
  9658. if (!this.#annotationEditorUIManager) {
  9659. throw new Error(`The AnnotationEditor is not enabled.`);
  9660. }
  9661. this.#annotationEditorUIManager.updateParams(type, value);
  9662. }
  9663. refresh(noUpdate = false, updateArgs = Object.create(null)) {
  9664. if (!this.pdfDocument) {
  9665. return;
  9666. }
  9667. for (const pageView of this._pages) {
  9668. pageView.update(updateArgs);
  9669. }
  9670. if (this.#scaleTimeoutId !== null) {
  9671. clearTimeout(this.#scaleTimeoutId);
  9672. this.#scaleTimeoutId = null;
  9673. }
  9674. if (!noUpdate) {
  9675. this.update();
  9676. }
  9677. }
  9678. }
  9679. exports.PDFViewer = PDFViewer;
  9680. /***/ }),
  9681. /* 29 */
  9682. /***/ ((__unused_webpack_module, exports) => {
  9683. Object.defineProperty(exports, "__esModule", ({
  9684. value: true
  9685. }));
  9686. exports.NullL10n = void 0;
  9687. exports.getL10nFallback = getL10nFallback;
  9688. const DEFAULT_L10N_STRINGS = {
  9689. of_pages: "of {{pagesCount}}",
  9690. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9691. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9692. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9693. document_properties_date_string: "{{date}}, {{time}}",
  9694. document_properties_page_size_unit_inches: "in",
  9695. document_properties_page_size_unit_millimeters: "mm",
  9696. document_properties_page_size_orientation_portrait: "portrait",
  9697. document_properties_page_size_orientation_landscape: "landscape",
  9698. document_properties_page_size_name_a3: "A3",
  9699. document_properties_page_size_name_a4: "A4",
  9700. document_properties_page_size_name_letter: "Letter",
  9701. document_properties_page_size_name_legal: "Legal",
  9702. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9703. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9704. document_properties_linearized_yes: "Yes",
  9705. document_properties_linearized_no: "No",
  9706. additional_layers: "Additional Layers",
  9707. page_landmark: "Page {{page}}",
  9708. thumb_page_title: "Page {{page}}",
  9709. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9710. find_reached_top: "Reached top of document, continued from bottom",
  9711. find_reached_bottom: "Reached end of document, continued from top",
  9712. "find_match_count[one]": "{{current}} of {{total}} match",
  9713. "find_match_count[other]": "{{current}} of {{total}} matches",
  9714. "find_match_count_limit[one]": "More than {{limit}} match",
  9715. "find_match_count_limit[other]": "More than {{limit}} matches",
  9716. find_not_found: "Phrase not found",
  9717. page_scale_width: "Page Width",
  9718. page_scale_fit: "Page Fit",
  9719. page_scale_auto: "Automatic Zoom",
  9720. page_scale_actual: "Actual Size",
  9721. page_scale_percent: "{{scale}}%",
  9722. loading_error: "An error occurred while loading the PDF.",
  9723. invalid_file_error: "Invalid or corrupted PDF file.",
  9724. missing_file_error: "Missing PDF file.",
  9725. unexpected_response_error: "Unexpected server response.",
  9726. rendering_error: "An error occurred while rendering the page.",
  9727. annotation_date_string: "{{date}}, {{time}}",
  9728. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9729. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9730. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  9731. free_text2_default_content: "Start typing…",
  9732. editor_free_text2_aria_label: "Text Editor",
  9733. editor_ink2_aria_label: "Draw Editor",
  9734. editor_ink_canvas_aria_label: "User-created image"
  9735. };
  9736. {
  9737. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  9738. }
  9739. function getL10nFallback(key, args) {
  9740. switch (key) {
  9741. case "find_match_count":
  9742. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9743. break;
  9744. case "find_match_count_limit":
  9745. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9746. break;
  9747. }
  9748. return DEFAULT_L10N_STRINGS[key] || "";
  9749. }
  9750. function formatL10nValue(text, args) {
  9751. if (!args) {
  9752. return text;
  9753. }
  9754. return text.replaceAll(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9755. return name in args ? args[name] : "{{" + name + "}}";
  9756. });
  9757. }
  9758. const NullL10n = {
  9759. async getLanguage() {
  9760. return "en-us";
  9761. },
  9762. async getDirection() {
  9763. return "ltr";
  9764. },
  9765. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9766. return formatL10nValue(fallback, args);
  9767. },
  9768. async translate(element) {}
  9769. };
  9770. exports.NullL10n = NullL10n;
  9771. /***/ }),
  9772. /* 30 */
  9773. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9774. Object.defineProperty(exports, "__esModule", ({
  9775. value: true
  9776. }));
  9777. exports.PDFPageView = void 0;
  9778. var _pdfjsLib = __webpack_require__(4);
  9779. var _ui_utils = __webpack_require__(3);
  9780. var _annotation_editor_layer_builder = __webpack_require__(31);
  9781. var _annotation_layer_builder = __webpack_require__(32);
  9782. var _app_options = __webpack_require__(5);
  9783. var _l10n_utils = __webpack_require__(29);
  9784. var _pdf_link_service = __webpack_require__(7);
  9785. var _struct_tree_layer_builder = __webpack_require__(33);
  9786. var _text_accessibility = __webpack_require__(34);
  9787. var _text_highlighter = __webpack_require__(35);
  9788. var _text_layer_builder = __webpack_require__(36);
  9789. var _xfa_layer_builder = __webpack_require__(37);
  9790. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9791. const DEFAULT_LAYER_PROPERTIES = () => {
  9792. return null;
  9793. };
  9794. class PDFPageView {
  9795. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9796. #hasRestrictedScaling = false;
  9797. #layerProperties = null;
  9798. #loadingId = null;
  9799. #previousRotation = null;
  9800. #renderError = null;
  9801. #renderingState = _ui_utils.RenderingStates.INITIAL;
  9802. #textLayerMode = _ui_utils.TextLayerMode.ENABLE;
  9803. #useThumbnailCanvas = {
  9804. directDrawing: true,
  9805. initialOptionalContent: true,
  9806. regularAnnotations: true
  9807. };
  9808. #viewportMap = new WeakMap();
  9809. constructor(options) {
  9810. const container = options.container;
  9811. const defaultViewport = options.defaultViewport;
  9812. this.id = options.id;
  9813. this.renderingId = "page" + this.id;
  9814. this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
  9815. this.pdfPage = null;
  9816. this.pageLabel = null;
  9817. this.rotation = 0;
  9818. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9819. this.viewport = defaultViewport;
  9820. this.pdfPageRotate = defaultViewport.rotation;
  9821. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9822. this.#textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9823. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9824. this.imageResourcesPath = options.imageResourcesPath || "";
  9825. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  9826. this.maxCanvasPixels = options.maxCanvasPixels ?? MAX_CANVAS_PIXELS;
  9827. this.pageColors = options.pageColors || null;
  9828. this.eventBus = options.eventBus;
  9829. this.renderingQueue = options.renderingQueue;
  9830. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9831. this.renderTask = null;
  9832. this.resume = null;
  9833. this._isStandalone = !this.renderingQueue?.hasViewer();
  9834. this._container = container;
  9835. if (options.useOnlyCssZoom) {
  9836. console.error("useOnlyCssZoom was removed, please use `maxCanvasPixels = 0` instead.");
  9837. this.maxCanvasPixels = 0;
  9838. }
  9839. this._annotationCanvasMap = null;
  9840. this.annotationLayer = null;
  9841. this.annotationEditorLayer = null;
  9842. this.textLayer = null;
  9843. this.zoomLayer = null;
  9844. this.xfaLayer = null;
  9845. this.structTreeLayer = null;
  9846. const div = document.createElement("div");
  9847. div.className = "page";
  9848. div.setAttribute("data-page-number", this.id);
  9849. div.setAttribute("role", "region");
  9850. this.l10n.get("page_landmark", {
  9851. page: this.id
  9852. }).then(msg => {
  9853. div.setAttribute("aria-label", msg);
  9854. });
  9855. this.div = div;
  9856. this.#setDimensions();
  9857. container?.append(div);
  9858. if (this._isStandalone) {
  9859. container?.style.setProperty("--scale-factor", this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  9860. const {
  9861. optionalContentConfigPromise
  9862. } = options;
  9863. if (optionalContentConfigPromise) {
  9864. optionalContentConfigPromise.then(optionalContentConfig => {
  9865. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9866. return;
  9867. }
  9868. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9869. });
  9870. }
  9871. }
  9872. }
  9873. get renderingState() {
  9874. return this.#renderingState;
  9875. }
  9876. set renderingState(state) {
  9877. if (state === this.#renderingState) {
  9878. return;
  9879. }
  9880. this.#renderingState = state;
  9881. if (this.#loadingId) {
  9882. clearTimeout(this.#loadingId);
  9883. this.#loadingId = null;
  9884. }
  9885. switch (state) {
  9886. case _ui_utils.RenderingStates.PAUSED:
  9887. this.div.classList.remove("loading");
  9888. break;
  9889. case _ui_utils.RenderingStates.RUNNING:
  9890. this.div.classList.add("loadingIcon");
  9891. this.#loadingId = setTimeout(() => {
  9892. this.div.classList.add("loading");
  9893. this.#loadingId = null;
  9894. }, 0);
  9895. break;
  9896. case _ui_utils.RenderingStates.INITIAL:
  9897. case _ui_utils.RenderingStates.FINISHED:
  9898. this.div.classList.remove("loadingIcon", "loading");
  9899. break;
  9900. }
  9901. }
  9902. #setDimensions() {
  9903. const {
  9904. viewport
  9905. } = this;
  9906. if (this.pdfPage) {
  9907. if (this.#previousRotation === viewport.rotation) {
  9908. return;
  9909. }
  9910. this.#previousRotation = viewport.rotation;
  9911. }
  9912. (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false);
  9913. }
  9914. setPdfPage(pdfPage) {
  9915. if (this._isStandalone && (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas")) {
  9916. this._container?.style.setProperty("--hcm-highligh-filter", pdfPage.filterFactory.addHighlightHCMFilter("CanvasText", "Canvas", "HighlightText", "Highlight"));
  9917. }
  9918. this.pdfPage = pdfPage;
  9919. this.pdfPageRotate = pdfPage.rotate;
  9920. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9921. this.viewport = pdfPage.getViewport({
  9922. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9923. rotation: totalRotation
  9924. });
  9925. this.#setDimensions();
  9926. this.reset();
  9927. }
  9928. destroy() {
  9929. this.reset();
  9930. this.pdfPage?.cleanup();
  9931. }
  9932. get _textHighlighter() {
  9933. return (0, _pdfjsLib.shadow)(this, "_textHighlighter", new _text_highlighter.TextHighlighter({
  9934. pageIndex: this.id - 1,
  9935. eventBus: this.eventBus,
  9936. findController: this.#layerProperties().findController
  9937. }));
  9938. }
  9939. async #renderAnnotationLayer() {
  9940. let error = null;
  9941. try {
  9942. await this.annotationLayer.render(this.viewport, "display");
  9943. } catch (ex) {
  9944. console.error(`#renderAnnotationLayer: "${ex}".`);
  9945. error = ex;
  9946. } finally {
  9947. this.eventBus.dispatch("annotationlayerrendered", {
  9948. source: this,
  9949. pageNumber: this.id,
  9950. error
  9951. });
  9952. }
  9953. }
  9954. async #renderAnnotationEditorLayer() {
  9955. let error = null;
  9956. try {
  9957. await this.annotationEditorLayer.render(this.viewport, "display");
  9958. } catch (ex) {
  9959. console.error(`#renderAnnotationEditorLayer: "${ex}".`);
  9960. error = ex;
  9961. } finally {
  9962. this.eventBus.dispatch("annotationeditorlayerrendered", {
  9963. source: this,
  9964. pageNumber: this.id,
  9965. error
  9966. });
  9967. }
  9968. }
  9969. async #renderXfaLayer() {
  9970. let error = null;
  9971. try {
  9972. const result = await this.xfaLayer.render(this.viewport, "display");
  9973. if (result?.textDivs && this._textHighlighter) {
  9974. this.#buildXfaTextContentItems(result.textDivs);
  9975. }
  9976. } catch (ex) {
  9977. console.error(`#renderXfaLayer: "${ex}".`);
  9978. error = ex;
  9979. } finally {
  9980. this.eventBus.dispatch("xfalayerrendered", {
  9981. source: this,
  9982. pageNumber: this.id,
  9983. error
  9984. });
  9985. }
  9986. }
  9987. async #renderTextLayer() {
  9988. const {
  9989. pdfPage,
  9990. textLayer,
  9991. viewport
  9992. } = this;
  9993. if (!textLayer) {
  9994. return;
  9995. }
  9996. let error = null;
  9997. try {
  9998. if (!textLayer.renderingDone) {
  9999. const readableStream = pdfPage.streamTextContent({
  10000. includeMarkedContent: true,
  10001. disableNormalization: true
  10002. });
  10003. textLayer.setTextContentSource(readableStream);
  10004. }
  10005. await textLayer.render(viewport);
  10006. } catch (ex) {
  10007. if (ex instanceof _pdfjsLib.AbortException) {
  10008. return;
  10009. }
  10010. console.error(`#renderTextLayer: "${ex}".`);
  10011. error = ex;
  10012. }
  10013. this.eventBus.dispatch("textlayerrendered", {
  10014. source: this,
  10015. pageNumber: this.id,
  10016. numTextDivs: textLayer.numTextDivs,
  10017. error
  10018. });
  10019. this.#renderStructTreeLayer();
  10020. }
  10021. async #renderStructTreeLayer() {
  10022. if (!this.textLayer) {
  10023. return;
  10024. }
  10025. this.structTreeLayer ||= new _struct_tree_layer_builder.StructTreeLayerBuilder();
  10026. const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
  10027. const treeDom = this.structTreeLayer?.render(tree);
  10028. if (treeDom) {
  10029. this.canvas?.append(treeDom);
  10030. }
  10031. this.structTreeLayer?.show();
  10032. }
  10033. async #buildXfaTextContentItems(textDivs) {
  10034. const text = await this.pdfPage.getTextContent();
  10035. const items = [];
  10036. for (const item of text.items) {
  10037. items.push(item.str);
  10038. }
  10039. this._textHighlighter.setTextMapping(textDivs, items);
  10040. this._textHighlighter.enable();
  10041. }
  10042. _resetZoomLayer(removeFromDOM = false) {
  10043. if (!this.zoomLayer) {
  10044. return;
  10045. }
  10046. const zoomLayerCanvas = this.zoomLayer.firstChild;
  10047. this.#viewportMap.delete(zoomLayerCanvas);
  10048. zoomLayerCanvas.width = 0;
  10049. zoomLayerCanvas.height = 0;
  10050. if (removeFromDOM) {
  10051. this.zoomLayer.remove();
  10052. }
  10053. this.zoomLayer = null;
  10054. }
  10055. reset({
  10056. keepZoomLayer = false,
  10057. keepAnnotationLayer = false,
  10058. keepAnnotationEditorLayer = false,
  10059. keepXfaLayer = false,
  10060. keepTextLayer = false
  10061. } = {}) {
  10062. this.cancelRendering({
  10063. keepAnnotationLayer,
  10064. keepAnnotationEditorLayer,
  10065. keepXfaLayer,
  10066. keepTextLayer
  10067. });
  10068. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  10069. const div = this.div;
  10070. const childNodes = div.childNodes,
  10071. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  10072. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  10073. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  10074. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
  10075. textLayerNode = keepTextLayer && this.textLayer?.div || null;
  10076. for (let i = childNodes.length - 1; i >= 0; i--) {
  10077. const node = childNodes[i];
  10078. switch (node) {
  10079. case zoomLayerNode:
  10080. case annotationLayerNode:
  10081. case annotationEditorLayerNode:
  10082. case xfaLayerNode:
  10083. case textLayerNode:
  10084. continue;
  10085. }
  10086. node.remove();
  10087. }
  10088. div.removeAttribute("data-loaded");
  10089. if (annotationLayerNode) {
  10090. this.annotationLayer.hide();
  10091. }
  10092. if (annotationEditorLayerNode) {
  10093. this.annotationEditorLayer.hide();
  10094. }
  10095. if (xfaLayerNode) {
  10096. this.xfaLayer.hide();
  10097. }
  10098. if (textLayerNode) {
  10099. this.textLayer.hide();
  10100. }
  10101. this.structTreeLayer?.hide();
  10102. if (!zoomLayerNode) {
  10103. if (this.canvas) {
  10104. this.#viewportMap.delete(this.canvas);
  10105. this.canvas.width = 0;
  10106. this.canvas.height = 0;
  10107. delete this.canvas;
  10108. }
  10109. this._resetZoomLayer();
  10110. }
  10111. }
  10112. update({
  10113. scale = 0,
  10114. rotation = null,
  10115. optionalContentConfigPromise = null,
  10116. drawingDelay = -1
  10117. }) {
  10118. this.scale = scale || this.scale;
  10119. if (typeof rotation === "number") {
  10120. this.rotation = rotation;
  10121. }
  10122. if (optionalContentConfigPromise instanceof Promise) {
  10123. this._optionalContentConfigPromise = optionalContentConfigPromise;
  10124. optionalContentConfigPromise.then(optionalContentConfig => {
  10125. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  10126. return;
  10127. }
  10128. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  10129. });
  10130. }
  10131. this.#useThumbnailCanvas.directDrawing = true;
  10132. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  10133. this.viewport = this.viewport.clone({
  10134. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  10135. rotation: totalRotation
  10136. });
  10137. this.#setDimensions();
  10138. if (this._isStandalone) {
  10139. this._container?.style.setProperty("--scale-factor", this.viewport.scale);
  10140. }
  10141. if (this.canvas) {
  10142. let onlyCssZoom = false;
  10143. if (this.#hasRestrictedScaling) {
  10144. if (this.maxCanvasPixels === 0) {
  10145. onlyCssZoom = true;
  10146. } else if (this.maxCanvasPixels > 0) {
  10147. const {
  10148. width,
  10149. height
  10150. } = this.viewport;
  10151. const {
  10152. sx,
  10153. sy
  10154. } = this.outputScale;
  10155. onlyCssZoom = (Math.floor(width) * sx | 0) * (Math.floor(height) * sy | 0) > this.maxCanvasPixels;
  10156. }
  10157. }
  10158. const postponeDrawing = !onlyCssZoom && drawingDelay >= 0 && drawingDelay < 1000;
  10159. if (postponeDrawing || onlyCssZoom) {
  10160. if (postponeDrawing && this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  10161. this.cancelRendering({
  10162. keepZoomLayer: true,
  10163. keepAnnotationLayer: true,
  10164. keepAnnotationEditorLayer: true,
  10165. keepXfaLayer: true,
  10166. keepTextLayer: true,
  10167. cancelExtraDelay: drawingDelay
  10168. });
  10169. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10170. this.#useThumbnailCanvas.directDrawing = false;
  10171. }
  10172. this.cssTransform({
  10173. target: this.canvas,
  10174. redrawAnnotationLayer: true,
  10175. redrawAnnotationEditorLayer: true,
  10176. redrawXfaLayer: true,
  10177. redrawTextLayer: !postponeDrawing,
  10178. hideTextLayer: postponeDrawing
  10179. });
  10180. if (postponeDrawing) {
  10181. return;
  10182. }
  10183. this.eventBus.dispatch("pagerendered", {
  10184. source: this,
  10185. pageNumber: this.id,
  10186. cssTransform: true,
  10187. timestamp: performance.now(),
  10188. error: this.#renderError
  10189. });
  10190. return;
  10191. }
  10192. if (!this.zoomLayer && !this.canvas.hidden) {
  10193. this.zoomLayer = this.canvas.parentNode;
  10194. this.zoomLayer.style.position = "absolute";
  10195. }
  10196. }
  10197. if (this.zoomLayer) {
  10198. this.cssTransform({
  10199. target: this.zoomLayer.firstChild
  10200. });
  10201. }
  10202. this.reset({
  10203. keepZoomLayer: true,
  10204. keepAnnotationLayer: true,
  10205. keepAnnotationEditorLayer: true,
  10206. keepXfaLayer: true,
  10207. keepTextLayer: true
  10208. });
  10209. }
  10210. cancelRendering({
  10211. keepAnnotationLayer = false,
  10212. keepAnnotationEditorLayer = false,
  10213. keepXfaLayer = false,
  10214. keepTextLayer = false,
  10215. cancelExtraDelay = 0
  10216. } = {}) {
  10217. if (this.renderTask) {
  10218. this.renderTask.cancel(cancelExtraDelay);
  10219. this.renderTask = null;
  10220. }
  10221. this.resume = null;
  10222. if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
  10223. this.textLayer.cancel();
  10224. this.textLayer = null;
  10225. }
  10226. if (this.structTreeLayer && !this.textLayer) {
  10227. this.structTreeLayer = null;
  10228. }
  10229. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  10230. this.annotationLayer.cancel();
  10231. this.annotationLayer = null;
  10232. this._annotationCanvasMap = null;
  10233. }
  10234. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  10235. this.annotationEditorLayer.cancel();
  10236. this.annotationEditorLayer = null;
  10237. }
  10238. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  10239. this.xfaLayer.cancel();
  10240. this.xfaLayer = null;
  10241. this._textHighlighter?.disable();
  10242. }
  10243. }
  10244. cssTransform({
  10245. target,
  10246. redrawAnnotationLayer = false,
  10247. redrawAnnotationEditorLayer = false,
  10248. redrawXfaLayer = false,
  10249. redrawTextLayer = false,
  10250. hideTextLayer = false
  10251. }) {
  10252. if (!target.hasAttribute("zooming")) {
  10253. target.setAttribute("zooming", true);
  10254. const {
  10255. style
  10256. } = target;
  10257. style.width = style.height = "";
  10258. }
  10259. const originalViewport = this.#viewportMap.get(target);
  10260. if (this.viewport !== originalViewport) {
  10261. const relativeRotation = this.viewport.rotation - originalViewport.rotation;
  10262. const absRotation = Math.abs(relativeRotation);
  10263. let scaleX = 1,
  10264. scaleY = 1;
  10265. if (absRotation === 90 || absRotation === 270) {
  10266. const {
  10267. width,
  10268. height
  10269. } = this.viewport;
  10270. scaleX = height / width;
  10271. scaleY = width / height;
  10272. }
  10273. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  10274. }
  10275. if (redrawAnnotationLayer && this.annotationLayer) {
  10276. this.#renderAnnotationLayer();
  10277. }
  10278. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  10279. this.#renderAnnotationEditorLayer();
  10280. }
  10281. if (redrawXfaLayer && this.xfaLayer) {
  10282. this.#renderXfaLayer();
  10283. }
  10284. if (this.textLayer) {
  10285. if (hideTextLayer) {
  10286. this.textLayer.hide();
  10287. this.structTreeLayer?.hide();
  10288. } else if (redrawTextLayer) {
  10289. this.#renderTextLayer();
  10290. }
  10291. }
  10292. }
  10293. get width() {
  10294. return this.viewport.width;
  10295. }
  10296. get height() {
  10297. return this.viewport.height;
  10298. }
  10299. getPagePoint(x, y) {
  10300. return this.viewport.convertToPdfPoint(x, y);
  10301. }
  10302. async #finishRenderTask(renderTask, error = null) {
  10303. if (renderTask === this.renderTask) {
  10304. this.renderTask = null;
  10305. }
  10306. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  10307. this.#renderError = null;
  10308. return;
  10309. }
  10310. this.#renderError = error;
  10311. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10312. this._resetZoomLayer(true);
  10313. this.#useThumbnailCanvas.regularAnnotations = !renderTask.separateAnnots;
  10314. this.eventBus.dispatch("pagerendered", {
  10315. source: this,
  10316. pageNumber: this.id,
  10317. cssTransform: false,
  10318. timestamp: performance.now(),
  10319. error: this.#renderError
  10320. });
  10321. if (error) {
  10322. throw error;
  10323. }
  10324. }
  10325. async draw() {
  10326. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  10327. console.error("Must be in new state before drawing");
  10328. this.reset();
  10329. }
  10330. const {
  10331. div,
  10332. l10n,
  10333. pageColors,
  10334. pdfPage,
  10335. viewport
  10336. } = this;
  10337. if (!pdfPage) {
  10338. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10339. throw new Error("pdfPage is not loaded");
  10340. }
  10341. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10342. const canvasWrapper = document.createElement("div");
  10343. canvasWrapper.classList.add("canvasWrapper");
  10344. div.append(canvasWrapper);
  10345. if (!this.textLayer && this.#textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
  10346. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  10347. this.textLayer = new _text_layer_builder.TextLayerBuilder({
  10348. highlighter: this._textHighlighter,
  10349. accessibilityManager: this._accessibilityManager,
  10350. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  10351. enablePermissions: this.#textLayerMode === _ui_utils.TextLayerMode.ENABLE_PERMISSIONS
  10352. });
  10353. div.append(this.textLayer.div);
  10354. }
  10355. if (!this.annotationLayer && this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE) {
  10356. const {
  10357. annotationStorage,
  10358. downloadManager,
  10359. enableScripting,
  10360. fieldObjectsPromise,
  10361. hasJSActionsPromise,
  10362. linkService
  10363. } = this.#layerProperties();
  10364. this._annotationCanvasMap ||= new Map();
  10365. this.annotationLayer = new _annotation_layer_builder.AnnotationLayerBuilder({
  10366. pageDiv: div,
  10367. pdfPage,
  10368. annotationStorage,
  10369. imageResourcesPath: this.imageResourcesPath,
  10370. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  10371. linkService,
  10372. downloadManager,
  10373. l10n,
  10374. enableScripting,
  10375. hasJSActionsPromise,
  10376. fieldObjectsPromise,
  10377. annotationCanvasMap: this._annotationCanvasMap,
  10378. accessibilityManager: this._accessibilityManager
  10379. });
  10380. }
  10381. const renderContinueCallback = cont => {
  10382. showCanvas?.(false);
  10383. if (this.renderingQueue && !this.renderingQueue.isHighestPriority(this)) {
  10384. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  10385. this.resume = () => {
  10386. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10387. cont();
  10388. };
  10389. return;
  10390. }
  10391. cont();
  10392. };
  10393. const {
  10394. width,
  10395. height
  10396. } = viewport;
  10397. const canvas = document.createElement("canvas");
  10398. canvas.setAttribute("role", "presentation");
  10399. canvas.hidden = true;
  10400. const hasHCM = !!(pageColors?.background && pageColors?.foreground);
  10401. let showCanvas = isLastShow => {
  10402. if (!hasHCM || isLastShow) {
  10403. canvas.hidden = false;
  10404. showCanvas = null;
  10405. }
  10406. };
  10407. canvasWrapper.append(canvas);
  10408. this.canvas = canvas;
  10409. const ctx = canvas.getContext("2d", {
  10410. alpha: false
  10411. });
  10412. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  10413. if (this.maxCanvasPixels === 0) {
  10414. const invScale = 1 / this.scale;
  10415. outputScale.sx *= invScale;
  10416. outputScale.sy *= invScale;
  10417. this.#hasRestrictedScaling = true;
  10418. } else if (this.maxCanvasPixels > 0) {
  10419. const pixelsInViewport = width * height;
  10420. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  10421. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  10422. outputScale.sx = maxScale;
  10423. outputScale.sy = maxScale;
  10424. this.#hasRestrictedScaling = true;
  10425. } else {
  10426. this.#hasRestrictedScaling = false;
  10427. }
  10428. }
  10429. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  10430. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  10431. canvas.width = (0, _ui_utils.roundToDivide)(width * outputScale.sx, sfx[0]);
  10432. canvas.height = (0, _ui_utils.roundToDivide)(height * outputScale.sy, sfy[0]);
  10433. const {
  10434. style
  10435. } = canvas;
  10436. style.width = (0, _ui_utils.roundToDivide)(width, sfx[1]) + "px";
  10437. style.height = (0, _ui_utils.roundToDivide)(height, sfy[1]) + "px";
  10438. this.#viewportMap.set(canvas, viewport);
  10439. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10440. const renderContext = {
  10441. canvasContext: ctx,
  10442. transform,
  10443. viewport,
  10444. annotationMode: this.#annotationMode,
  10445. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10446. annotationCanvasMap: this._annotationCanvasMap,
  10447. pageColors
  10448. };
  10449. const renderTask = this.renderTask = this.pdfPage.render(renderContext);
  10450. renderTask.onContinue = renderContinueCallback;
  10451. const resultPromise = renderTask.promise.then(async () => {
  10452. showCanvas?.(true);
  10453. await this.#finishRenderTask(renderTask);
  10454. this.#renderTextLayer();
  10455. if (this.annotationLayer) {
  10456. await this.#renderAnnotationLayer();
  10457. }
  10458. if (!this.annotationEditorLayer) {
  10459. const {
  10460. annotationEditorUIManager
  10461. } = this.#layerProperties();
  10462. if (!annotationEditorUIManager) {
  10463. return;
  10464. }
  10465. this.annotationEditorLayer = new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  10466. uiManager: annotationEditorUIManager,
  10467. pageDiv: div,
  10468. pdfPage,
  10469. l10n,
  10470. accessibilityManager: this._accessibilityManager,
  10471. annotationLayer: this.annotationLayer?.annotationLayer
  10472. });
  10473. }
  10474. this.#renderAnnotationEditorLayer();
  10475. }, error => {
  10476. if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
  10477. showCanvas?.(true);
  10478. }
  10479. return this.#finishRenderTask(renderTask, error);
  10480. });
  10481. if (pdfPage.isPureXfa) {
  10482. if (!this.xfaLayer) {
  10483. const {
  10484. annotationStorage,
  10485. linkService
  10486. } = this.#layerProperties();
  10487. this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({
  10488. pageDiv: div,
  10489. pdfPage,
  10490. annotationStorage,
  10491. linkService
  10492. });
  10493. } else if (this.xfaLayer.div) {
  10494. div.append(this.xfaLayer.div);
  10495. }
  10496. this.#renderXfaLayer();
  10497. }
  10498. div.setAttribute("data-loaded", true);
  10499. this.eventBus.dispatch("pagerender", {
  10500. source: this,
  10501. pageNumber: this.id
  10502. });
  10503. return resultPromise;
  10504. }
  10505. setPageLabel(label) {
  10506. this.pageLabel = typeof label === "string" ? label : null;
  10507. if (this.pageLabel !== null) {
  10508. this.div.setAttribute("data-page-label", this.pageLabel);
  10509. } else {
  10510. this.div.removeAttribute("data-page-label");
  10511. }
  10512. }
  10513. get thumbnailCanvas() {
  10514. const {
  10515. directDrawing,
  10516. initialOptionalContent,
  10517. regularAnnotations
  10518. } = this.#useThumbnailCanvas;
  10519. return directDrawing && initialOptionalContent && regularAnnotations ? this.canvas : null;
  10520. }
  10521. }
  10522. exports.PDFPageView = PDFPageView;
  10523. /***/ }),
  10524. /* 31 */
  10525. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10526. Object.defineProperty(exports, "__esModule", ({
  10527. value: true
  10528. }));
  10529. exports.AnnotationEditorLayerBuilder = void 0;
  10530. var _pdfjsLib = __webpack_require__(4);
  10531. var _l10n_utils = __webpack_require__(29);
  10532. class AnnotationEditorLayerBuilder {
  10533. #annotationLayer = null;
  10534. #uiManager;
  10535. constructor(options) {
  10536. this.pageDiv = options.pageDiv;
  10537. this.pdfPage = options.pdfPage;
  10538. this.accessibilityManager = options.accessibilityManager;
  10539. this.l10n = options.l10n || _l10n_utils.NullL10n;
  10540. this.annotationEditorLayer = null;
  10541. this.div = null;
  10542. this._cancelled = false;
  10543. this.#uiManager = options.uiManager;
  10544. this.#annotationLayer = options.annotationLayer || null;
  10545. }
  10546. async render(viewport, intent = "display") {
  10547. if (intent !== "display") {
  10548. return;
  10549. }
  10550. if (this._cancelled) {
  10551. return;
  10552. }
  10553. const clonedViewport = viewport.clone({
  10554. dontFlip: true
  10555. });
  10556. if (this.div) {
  10557. this.annotationEditorLayer.update({
  10558. viewport: clonedViewport
  10559. });
  10560. this.show();
  10561. return;
  10562. }
  10563. const div = this.div = document.createElement("div");
  10564. div.className = "annotationEditorLayer";
  10565. div.tabIndex = 0;
  10566. div.hidden = true;
  10567. this.pageDiv.append(div);
  10568. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  10569. uiManager: this.#uiManager,
  10570. div,
  10571. accessibilityManager: this.accessibilityManager,
  10572. pageIndex: this.pdfPage.pageNumber - 1,
  10573. l10n: this.l10n,
  10574. viewport: clonedViewport,
  10575. annotationLayer: this.#annotationLayer
  10576. });
  10577. const parameters = {
  10578. viewport: clonedViewport,
  10579. div,
  10580. annotations: null,
  10581. intent
  10582. };
  10583. this.annotationEditorLayer.render(parameters);
  10584. this.show();
  10585. }
  10586. cancel() {
  10587. this._cancelled = true;
  10588. if (!this.div) {
  10589. return;
  10590. }
  10591. this.pageDiv = null;
  10592. this.annotationEditorLayer.destroy();
  10593. this.div.remove();
  10594. }
  10595. hide() {
  10596. if (!this.div) {
  10597. return;
  10598. }
  10599. this.div.hidden = true;
  10600. }
  10601. show() {
  10602. if (!this.div || this.annotationEditorLayer.isEmpty) {
  10603. return;
  10604. }
  10605. this.div.hidden = false;
  10606. }
  10607. }
  10608. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  10609. /***/ }),
  10610. /* 32 */
  10611. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10612. Object.defineProperty(exports, "__esModule", ({
  10613. value: true
  10614. }));
  10615. exports.AnnotationLayerBuilder = void 0;
  10616. var _pdfjsLib = __webpack_require__(4);
  10617. var _l10n_utils = __webpack_require__(29);
  10618. var _ui_utils = __webpack_require__(3);
  10619. class AnnotationLayerBuilder {
  10620. #onPresentationModeChanged = null;
  10621. constructor({
  10622. pageDiv,
  10623. pdfPage,
  10624. linkService,
  10625. downloadManager,
  10626. annotationStorage = null,
  10627. imageResourcesPath = "",
  10628. renderForms = true,
  10629. l10n = _l10n_utils.NullL10n,
  10630. enableScripting = false,
  10631. hasJSActionsPromise = null,
  10632. fieldObjectsPromise = null,
  10633. annotationCanvasMap = null,
  10634. accessibilityManager = null
  10635. }) {
  10636. this.pageDiv = pageDiv;
  10637. this.pdfPage = pdfPage;
  10638. this.linkService = linkService;
  10639. this.downloadManager = downloadManager;
  10640. this.imageResourcesPath = imageResourcesPath;
  10641. this.renderForms = renderForms;
  10642. this.l10n = l10n;
  10643. this.annotationStorage = annotationStorage;
  10644. this.enableScripting = enableScripting;
  10645. this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
  10646. this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
  10647. this._annotationCanvasMap = annotationCanvasMap;
  10648. this._accessibilityManager = accessibilityManager;
  10649. this.annotationLayer = null;
  10650. this.div = null;
  10651. this._cancelled = false;
  10652. this._eventBus = linkService.eventBus;
  10653. }
  10654. async render(viewport, intent = "display") {
  10655. if (this.div) {
  10656. if (this._cancelled || !this.annotationLayer) {
  10657. return;
  10658. }
  10659. this.annotationLayer.update({
  10660. viewport: viewport.clone({
  10661. dontFlip: true
  10662. })
  10663. });
  10664. return;
  10665. }
  10666. const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
  10667. intent
  10668. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  10669. if (this._cancelled) {
  10670. return;
  10671. }
  10672. const div = this.div = document.createElement("div");
  10673. div.className = "annotationLayer";
  10674. this.pageDiv.append(div);
  10675. if (annotations.length === 0) {
  10676. this.hide();
  10677. return;
  10678. }
  10679. this.annotationLayer = new _pdfjsLib.AnnotationLayer({
  10680. div,
  10681. accessibilityManager: this._accessibilityManager,
  10682. annotationCanvasMap: this._annotationCanvasMap,
  10683. l10n: this.l10n,
  10684. page: this.pdfPage,
  10685. viewport: viewport.clone({
  10686. dontFlip: true
  10687. })
  10688. });
  10689. await this.annotationLayer.render({
  10690. annotations,
  10691. imageResourcesPath: this.imageResourcesPath,
  10692. renderForms: this.renderForms,
  10693. linkService: this.linkService,
  10694. downloadManager: this.downloadManager,
  10695. annotationStorage: this.annotationStorage,
  10696. enableScripting: this.enableScripting,
  10697. hasJSActions,
  10698. fieldObjects
  10699. });
  10700. if (this.linkService.isInPresentationMode) {
  10701. this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN);
  10702. }
  10703. if (!this.#onPresentationModeChanged) {
  10704. this.#onPresentationModeChanged = evt => {
  10705. this.#updatePresentationModeState(evt.state);
  10706. };
  10707. this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged);
  10708. }
  10709. }
  10710. cancel() {
  10711. this._cancelled = true;
  10712. if (this.#onPresentationModeChanged) {
  10713. this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged);
  10714. this.#onPresentationModeChanged = null;
  10715. }
  10716. }
  10717. hide() {
  10718. if (!this.div) {
  10719. return;
  10720. }
  10721. this.div.hidden = true;
  10722. }
  10723. #updatePresentationModeState(state) {
  10724. if (!this.div) {
  10725. return;
  10726. }
  10727. let disableFormElements = false;
  10728. switch (state) {
  10729. case _ui_utils.PresentationModeState.FULLSCREEN:
  10730. disableFormElements = true;
  10731. break;
  10732. case _ui_utils.PresentationModeState.NORMAL:
  10733. break;
  10734. default:
  10735. return;
  10736. }
  10737. for (const section of this.div.childNodes) {
  10738. if (section.hasAttribute("data-internal-link")) {
  10739. continue;
  10740. }
  10741. section.inert = disableFormElements;
  10742. }
  10743. }
  10744. }
  10745. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  10746. /***/ }),
  10747. /* 33 */
  10748. /***/ ((__unused_webpack_module, exports) => {
  10749. Object.defineProperty(exports, "__esModule", ({
  10750. value: true
  10751. }));
  10752. exports.StructTreeLayerBuilder = void 0;
  10753. const PDF_ROLE_TO_HTML_ROLE = {
  10754. Document: null,
  10755. DocumentFragment: null,
  10756. Part: "group",
  10757. Sect: "group",
  10758. Div: "group",
  10759. Aside: "note",
  10760. NonStruct: "none",
  10761. P: null,
  10762. H: "heading",
  10763. Title: null,
  10764. FENote: "note",
  10765. Sub: "group",
  10766. Lbl: null,
  10767. Span: null,
  10768. Em: null,
  10769. Strong: null,
  10770. Link: "link",
  10771. Annot: "note",
  10772. Form: "form",
  10773. Ruby: null,
  10774. RB: null,
  10775. RT: null,
  10776. RP: null,
  10777. Warichu: null,
  10778. WT: null,
  10779. WP: null,
  10780. L: "list",
  10781. LI: "listitem",
  10782. LBody: null,
  10783. Table: "table",
  10784. TR: "row",
  10785. TH: "columnheader",
  10786. TD: "cell",
  10787. THead: "columnheader",
  10788. TBody: null,
  10789. TFoot: null,
  10790. Caption: null,
  10791. Figure: "figure",
  10792. Formula: null,
  10793. Artifact: null
  10794. };
  10795. const HEADING_PATTERN = /^H(\d+)$/;
  10796. class StructTreeLayerBuilder {
  10797. #treeDom = undefined;
  10798. get renderingDone() {
  10799. return this.#treeDom !== undefined;
  10800. }
  10801. render(structTree) {
  10802. if (this.#treeDom !== undefined) {
  10803. return this.#treeDom;
  10804. }
  10805. const treeDom = this.#walk(structTree);
  10806. treeDom?.classList.add("structTree");
  10807. return this.#treeDom = treeDom;
  10808. }
  10809. hide() {
  10810. if (this.#treeDom && !this.#treeDom.hidden) {
  10811. this.#treeDom.hidden = true;
  10812. }
  10813. }
  10814. show() {
  10815. if (this.#treeDom?.hidden) {
  10816. this.#treeDom.hidden = false;
  10817. }
  10818. }
  10819. #setAttributes(structElement, htmlElement) {
  10820. if (structElement.alt !== undefined) {
  10821. htmlElement.setAttribute("aria-label", structElement.alt);
  10822. }
  10823. if (structElement.id !== undefined) {
  10824. htmlElement.setAttribute("aria-owns", structElement.id);
  10825. }
  10826. if (structElement.lang !== undefined) {
  10827. htmlElement.setAttribute("lang", structElement.lang);
  10828. }
  10829. }
  10830. #walk(node) {
  10831. if (!node) {
  10832. return null;
  10833. }
  10834. const element = document.createElement("span");
  10835. if ("role" in node) {
  10836. const {
  10837. role
  10838. } = node;
  10839. const match = role.match(HEADING_PATTERN);
  10840. if (match) {
  10841. element.setAttribute("role", "heading");
  10842. element.setAttribute("aria-level", match[1]);
  10843. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10844. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10845. }
  10846. }
  10847. this.#setAttributes(node, element);
  10848. if (node.children) {
  10849. if (node.children.length === 1 && "id" in node.children[0]) {
  10850. this.#setAttributes(node.children[0], element);
  10851. } else {
  10852. for (const kid of node.children) {
  10853. element.append(this.#walk(kid));
  10854. }
  10855. }
  10856. }
  10857. return element;
  10858. }
  10859. }
  10860. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10861. /***/ }),
  10862. /* 34 */
  10863. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10864. Object.defineProperty(exports, "__esModule", ({
  10865. value: true
  10866. }));
  10867. exports.TextAccessibilityManager = void 0;
  10868. var _ui_utils = __webpack_require__(3);
  10869. class TextAccessibilityManager {
  10870. #enabled = false;
  10871. #textChildren = null;
  10872. #textNodes = new Map();
  10873. #waitingElements = new Map();
  10874. setTextMapping(textDivs) {
  10875. this.#textChildren = textDivs;
  10876. }
  10877. static #compareElementPositions(e1, e2) {
  10878. const rect1 = e1.getBoundingClientRect();
  10879. const rect2 = e2.getBoundingClientRect();
  10880. if (rect1.width === 0 && rect1.height === 0) {
  10881. return +1;
  10882. }
  10883. if (rect2.width === 0 && rect2.height === 0) {
  10884. return -1;
  10885. }
  10886. const top1 = rect1.y;
  10887. const bot1 = rect1.y + rect1.height;
  10888. const mid1 = rect1.y + rect1.height / 2;
  10889. const top2 = rect2.y;
  10890. const bot2 = rect2.y + rect2.height;
  10891. const mid2 = rect2.y + rect2.height / 2;
  10892. if (mid1 <= top2 && mid2 >= bot1) {
  10893. return -1;
  10894. }
  10895. if (mid2 <= top1 && mid1 >= bot2) {
  10896. return +1;
  10897. }
  10898. const centerX1 = rect1.x + rect1.width / 2;
  10899. const centerX2 = rect2.x + rect2.width / 2;
  10900. return centerX1 - centerX2;
  10901. }
  10902. enable() {
  10903. if (this.#enabled) {
  10904. throw new Error("TextAccessibilityManager is already enabled.");
  10905. }
  10906. if (!this.#textChildren) {
  10907. throw new Error("Text divs and strings have not been set.");
  10908. }
  10909. this.#enabled = true;
  10910. this.#textChildren = this.#textChildren.slice();
  10911. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  10912. if (this.#textNodes.size > 0) {
  10913. const textChildren = this.#textChildren;
  10914. for (const [id, nodeIndex] of this.#textNodes) {
  10915. const element = document.getElementById(id);
  10916. if (!element) {
  10917. this.#textNodes.delete(id);
  10918. continue;
  10919. }
  10920. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  10921. }
  10922. }
  10923. for (const [element, isRemovable] of this.#waitingElements) {
  10924. this.addPointerInTextLayer(element, isRemovable);
  10925. }
  10926. this.#waitingElements.clear();
  10927. }
  10928. disable() {
  10929. if (!this.#enabled) {
  10930. return;
  10931. }
  10932. this.#waitingElements.clear();
  10933. this.#textChildren = null;
  10934. this.#enabled = false;
  10935. }
  10936. removePointerInTextLayer(element) {
  10937. if (!this.#enabled) {
  10938. this.#waitingElements.delete(element);
  10939. return;
  10940. }
  10941. const children = this.#textChildren;
  10942. if (!children || children.length === 0) {
  10943. return;
  10944. }
  10945. const {
  10946. id
  10947. } = element;
  10948. const nodeIndex = this.#textNodes.get(id);
  10949. if (nodeIndex === undefined) {
  10950. return;
  10951. }
  10952. const node = children[nodeIndex];
  10953. this.#textNodes.delete(id);
  10954. let owns = node.getAttribute("aria-owns");
  10955. if (owns?.includes(id)) {
  10956. owns = owns.split(" ").filter(x => x !== id).join(" ");
  10957. if (owns) {
  10958. node.setAttribute("aria-owns", owns);
  10959. } else {
  10960. node.removeAttribute("aria-owns");
  10961. node.setAttribute("role", "presentation");
  10962. }
  10963. }
  10964. }
  10965. #addIdToAriaOwns(id, node) {
  10966. const owns = node.getAttribute("aria-owns");
  10967. if (!owns?.includes(id)) {
  10968. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  10969. }
  10970. node.removeAttribute("role");
  10971. }
  10972. addPointerInTextLayer(element, isRemovable) {
  10973. const {
  10974. id
  10975. } = element;
  10976. if (!id) {
  10977. return;
  10978. }
  10979. if (!this.#enabled) {
  10980. this.#waitingElements.set(element, isRemovable);
  10981. return;
  10982. }
  10983. if (isRemovable) {
  10984. this.removePointerInTextLayer(element);
  10985. }
  10986. const children = this.#textChildren;
  10987. if (!children || children.length === 0) {
  10988. return;
  10989. }
  10990. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  10991. const nodeIndex = Math.max(0, index - 1);
  10992. this.#addIdToAriaOwns(id, children[nodeIndex]);
  10993. this.#textNodes.set(id, nodeIndex);
  10994. }
  10995. moveElementInDOM(container, element, contentElement, isRemovable) {
  10996. this.addPointerInTextLayer(contentElement, isRemovable);
  10997. if (!container.hasChildNodes()) {
  10998. container.append(element);
  10999. return;
  11000. }
  11001. const children = Array.from(container.childNodes).filter(node => node !== element);
  11002. if (children.length === 0) {
  11003. return;
  11004. }
  11005. const elementToCompare = contentElement || element;
  11006. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  11007. if (index === 0) {
  11008. children[0].before(element);
  11009. } else {
  11010. children[index - 1].after(element);
  11011. }
  11012. }
  11013. }
  11014. exports.TextAccessibilityManager = TextAccessibilityManager;
  11015. /***/ }),
  11016. /* 35 */
  11017. /***/ ((__unused_webpack_module, exports) => {
  11018. Object.defineProperty(exports, "__esModule", ({
  11019. value: true
  11020. }));
  11021. exports.TextHighlighter = void 0;
  11022. class TextHighlighter {
  11023. constructor({
  11024. findController,
  11025. eventBus,
  11026. pageIndex
  11027. }) {
  11028. this.findController = findController;
  11029. this.matches = [];
  11030. this.eventBus = eventBus;
  11031. this.pageIdx = pageIndex;
  11032. this._onUpdateTextLayerMatches = null;
  11033. this.textDivs = null;
  11034. this.textContentItemsStr = null;
  11035. this.enabled = false;
  11036. }
  11037. setTextMapping(divs, texts) {
  11038. this.textDivs = divs;
  11039. this.textContentItemsStr = texts;
  11040. }
  11041. enable() {
  11042. if (!this.textDivs || !this.textContentItemsStr) {
  11043. throw new Error("Text divs and strings have not been set.");
  11044. }
  11045. if (this.enabled) {
  11046. throw new Error("TextHighlighter is already enabled.");
  11047. }
  11048. this.enabled = true;
  11049. if (!this._onUpdateTextLayerMatches) {
  11050. this._onUpdateTextLayerMatches = evt => {
  11051. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  11052. this._updateMatches();
  11053. }
  11054. };
  11055. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11056. }
  11057. this._updateMatches();
  11058. }
  11059. disable() {
  11060. if (!this.enabled) {
  11061. return;
  11062. }
  11063. this.enabled = false;
  11064. if (this._onUpdateTextLayerMatches) {
  11065. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11066. this._onUpdateTextLayerMatches = null;
  11067. }
  11068. this._updateMatches(true);
  11069. }
  11070. _convertMatches(matches, matchesLength) {
  11071. if (!matches) {
  11072. return [];
  11073. }
  11074. const {
  11075. textContentItemsStr
  11076. } = this;
  11077. let i = 0,
  11078. iIndex = 0;
  11079. const end = textContentItemsStr.length - 1;
  11080. const result = [];
  11081. for (let m = 0, mm = matches.length; m < mm; m++) {
  11082. let matchIdx = matches[m];
  11083. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  11084. iIndex += textContentItemsStr[i].length;
  11085. i++;
  11086. }
  11087. if (i === textContentItemsStr.length) {
  11088. console.error("Could not find a matching mapping");
  11089. }
  11090. const match = {
  11091. begin: {
  11092. divIdx: i,
  11093. offset: matchIdx - iIndex
  11094. }
  11095. };
  11096. matchIdx += matchesLength[m];
  11097. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  11098. iIndex += textContentItemsStr[i].length;
  11099. i++;
  11100. }
  11101. match.end = {
  11102. divIdx: i,
  11103. offset: matchIdx - iIndex
  11104. };
  11105. result.push(match);
  11106. }
  11107. return result;
  11108. }
  11109. _renderMatches(matches) {
  11110. if (matches.length === 0) {
  11111. return;
  11112. }
  11113. const {
  11114. findController,
  11115. pageIdx
  11116. } = this;
  11117. const {
  11118. textContentItemsStr,
  11119. textDivs
  11120. } = this;
  11121. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  11122. const selectedMatchIdx = findController.selected.matchIdx;
  11123. const highlightAll = findController.state.highlightAll;
  11124. let prevEnd = null;
  11125. const infinity = {
  11126. divIdx: -1,
  11127. offset: undefined
  11128. };
  11129. function beginText(begin, className) {
  11130. const divIdx = begin.divIdx;
  11131. textDivs[divIdx].textContent = "";
  11132. return appendTextToDiv(divIdx, 0, begin.offset, className);
  11133. }
  11134. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  11135. let div = textDivs[divIdx];
  11136. if (div.nodeType === Node.TEXT_NODE) {
  11137. const span = document.createElement("span");
  11138. div.before(span);
  11139. span.append(div);
  11140. textDivs[divIdx] = span;
  11141. div = span;
  11142. }
  11143. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  11144. const node = document.createTextNode(content);
  11145. if (className) {
  11146. const span = document.createElement("span");
  11147. span.className = `${className} appended`;
  11148. span.append(node);
  11149. div.append(span);
  11150. return className.includes("selected") ? span.offsetLeft : 0;
  11151. }
  11152. div.append(node);
  11153. return 0;
  11154. }
  11155. let i0 = selectedMatchIdx,
  11156. i1 = i0 + 1;
  11157. if (highlightAll) {
  11158. i0 = 0;
  11159. i1 = matches.length;
  11160. } else if (!isSelectedPage) {
  11161. return;
  11162. }
  11163. let lastDivIdx = -1;
  11164. let lastOffset = -1;
  11165. for (let i = i0; i < i1; i++) {
  11166. const match = matches[i];
  11167. const begin = match.begin;
  11168. if (begin.divIdx === lastDivIdx && begin.offset === lastOffset) {
  11169. continue;
  11170. }
  11171. lastDivIdx = begin.divIdx;
  11172. lastOffset = begin.offset;
  11173. const end = match.end;
  11174. const isSelected = isSelectedPage && i === selectedMatchIdx;
  11175. const highlightSuffix = isSelected ? " selected" : "";
  11176. let selectedLeft = 0;
  11177. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  11178. if (prevEnd !== null) {
  11179. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11180. }
  11181. beginText(begin);
  11182. } else {
  11183. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  11184. }
  11185. if (begin.divIdx === end.divIdx) {
  11186. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  11187. } else {
  11188. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  11189. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  11190. textDivs[n0].className = "highlight middle" + highlightSuffix;
  11191. }
  11192. beginText(end, "highlight end" + highlightSuffix);
  11193. }
  11194. prevEnd = end;
  11195. if (isSelected) {
  11196. findController.scrollMatchIntoView({
  11197. element: textDivs[begin.divIdx],
  11198. selectedLeft,
  11199. pageIndex: pageIdx,
  11200. matchIndex: selectedMatchIdx
  11201. });
  11202. }
  11203. }
  11204. if (prevEnd) {
  11205. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11206. }
  11207. }
  11208. _updateMatches(reset = false) {
  11209. if (!this.enabled && !reset) {
  11210. return;
  11211. }
  11212. const {
  11213. findController,
  11214. matches,
  11215. pageIdx
  11216. } = this;
  11217. const {
  11218. textContentItemsStr,
  11219. textDivs
  11220. } = this;
  11221. let clearedUntilDivIdx = -1;
  11222. for (const match of matches) {
  11223. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  11224. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  11225. const div = textDivs[n];
  11226. div.textContent = textContentItemsStr[n];
  11227. div.className = "";
  11228. }
  11229. clearedUntilDivIdx = match.end.divIdx + 1;
  11230. }
  11231. if (!findController?.highlightMatches || reset) {
  11232. return;
  11233. }
  11234. const pageMatches = findController.pageMatches[pageIdx] || null;
  11235. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  11236. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  11237. this._renderMatches(this.matches);
  11238. }
  11239. }
  11240. exports.TextHighlighter = TextHighlighter;
  11241. /***/ }),
  11242. /* 36 */
  11243. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11244. Object.defineProperty(exports, "__esModule", ({
  11245. value: true
  11246. }));
  11247. exports.TextLayerBuilder = void 0;
  11248. var _pdfjsLib = __webpack_require__(4);
  11249. var _ui_utils = __webpack_require__(3);
  11250. class TextLayerBuilder {
  11251. #enablePermissions = false;
  11252. #rotation = 0;
  11253. #scale = 0;
  11254. #textContentSource = null;
  11255. constructor({
  11256. highlighter = null,
  11257. accessibilityManager = null,
  11258. isOffscreenCanvasSupported = true,
  11259. enablePermissions = false
  11260. }) {
  11261. this.textContentItemsStr = [];
  11262. this.renderingDone = false;
  11263. this.textDivs = [];
  11264. this.textDivProperties = new WeakMap();
  11265. this.textLayerRenderTask = null;
  11266. this.highlighter = highlighter;
  11267. this.accessibilityManager = accessibilityManager;
  11268. this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
  11269. this.#enablePermissions = enablePermissions === true;
  11270. this.div = document.createElement("div");
  11271. this.div.className = "textLayer";
  11272. this.hide();
  11273. }
  11274. #finishRendering() {
  11275. this.renderingDone = true;
  11276. const endOfContent = document.createElement("div");
  11277. endOfContent.className = "endOfContent";
  11278. this.div.append(endOfContent);
  11279. this.#bindMouse();
  11280. }
  11281. get numTextDivs() {
  11282. return this.textDivs.length;
  11283. }
  11284. async render(viewport) {
  11285. if (!this.#textContentSource) {
  11286. throw new Error('No "textContentSource" parameter specified.');
  11287. }
  11288. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  11289. const {
  11290. rotation
  11291. } = viewport;
  11292. if (this.renderingDone) {
  11293. const mustRotate = rotation !== this.#rotation;
  11294. const mustRescale = scale !== this.#scale;
  11295. if (mustRotate || mustRescale) {
  11296. this.hide();
  11297. (0, _pdfjsLib.updateTextLayer)({
  11298. container: this.div,
  11299. viewport,
  11300. textDivs: this.textDivs,
  11301. textDivProperties: this.textDivProperties,
  11302. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  11303. mustRescale,
  11304. mustRotate
  11305. });
  11306. this.#scale = scale;
  11307. this.#rotation = rotation;
  11308. }
  11309. this.show();
  11310. return;
  11311. }
  11312. this.cancel();
  11313. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  11314. this.accessibilityManager?.setTextMapping(this.textDivs);
  11315. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  11316. textContentSource: this.#textContentSource,
  11317. container: this.div,
  11318. viewport,
  11319. textDivs: this.textDivs,
  11320. textDivProperties: this.textDivProperties,
  11321. textContentItemsStr: this.textContentItemsStr,
  11322. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
  11323. });
  11324. await this.textLayerRenderTask.promise;
  11325. this.#finishRendering();
  11326. this.#scale = scale;
  11327. this.#rotation = rotation;
  11328. this.show();
  11329. this.accessibilityManager?.enable();
  11330. }
  11331. hide() {
  11332. if (!this.div.hidden) {
  11333. this.highlighter?.disable();
  11334. this.div.hidden = true;
  11335. }
  11336. }
  11337. show() {
  11338. if (this.div.hidden && this.renderingDone) {
  11339. this.div.hidden = false;
  11340. this.highlighter?.enable();
  11341. }
  11342. }
  11343. cancel() {
  11344. if (this.textLayerRenderTask) {
  11345. this.textLayerRenderTask.cancel();
  11346. this.textLayerRenderTask = null;
  11347. }
  11348. this.highlighter?.disable();
  11349. this.accessibilityManager?.disable();
  11350. this.textContentItemsStr.length = 0;
  11351. this.textDivs.length = 0;
  11352. this.textDivProperties = new WeakMap();
  11353. }
  11354. setTextContentSource(source) {
  11355. this.cancel();
  11356. this.#textContentSource = source;
  11357. }
  11358. #bindMouse() {
  11359. const {
  11360. div
  11361. } = this;
  11362. div.addEventListener("mousedown", evt => {
  11363. const end = div.querySelector(".endOfContent");
  11364. if (!end) {
  11365. return;
  11366. }
  11367. let adjustTop = evt.target !== div;
  11368. adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  11369. if (adjustTop) {
  11370. const divBounds = div.getBoundingClientRect();
  11371. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  11372. end.style.top = (r * 100).toFixed(2) + "%";
  11373. }
  11374. end.classList.add("active");
  11375. });
  11376. div.addEventListener("mouseup", () => {
  11377. const end = div.querySelector(".endOfContent");
  11378. if (!end) {
  11379. return;
  11380. }
  11381. end.style.top = "";
  11382. end.classList.remove("active");
  11383. });
  11384. div.addEventListener("copy", event => {
  11385. if (!this.#enablePermissions) {
  11386. const selection = document.getSelection();
  11387. event.clipboardData.setData("text/plain", (0, _ui_utils.removeNullCharacters)((0, _pdfjsLib.normalizeUnicode)(selection.toString())));
  11388. }
  11389. event.preventDefault();
  11390. event.stopPropagation();
  11391. });
  11392. }
  11393. }
  11394. exports.TextLayerBuilder = TextLayerBuilder;
  11395. /***/ }),
  11396. /* 37 */
  11397. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11398. Object.defineProperty(exports, "__esModule", ({
  11399. value: true
  11400. }));
  11401. exports.XfaLayerBuilder = void 0;
  11402. var _pdfjsLib = __webpack_require__(4);
  11403. class XfaLayerBuilder {
  11404. constructor({
  11405. pageDiv,
  11406. pdfPage,
  11407. annotationStorage = null,
  11408. linkService,
  11409. xfaHtml = null
  11410. }) {
  11411. this.pageDiv = pageDiv;
  11412. this.pdfPage = pdfPage;
  11413. this.annotationStorage = annotationStorage;
  11414. this.linkService = linkService;
  11415. this.xfaHtml = xfaHtml;
  11416. this.div = null;
  11417. this._cancelled = false;
  11418. }
  11419. async render(viewport, intent = "display") {
  11420. if (intent === "print") {
  11421. const parameters = {
  11422. viewport: viewport.clone({
  11423. dontFlip: true
  11424. }),
  11425. div: this.div,
  11426. xfaHtml: this.xfaHtml,
  11427. annotationStorage: this.annotationStorage,
  11428. linkService: this.linkService,
  11429. intent
  11430. };
  11431. const div = document.createElement("div");
  11432. this.pageDiv.append(div);
  11433. parameters.div = div;
  11434. return _pdfjsLib.XfaLayer.render(parameters);
  11435. }
  11436. const xfaHtml = await this.pdfPage.getXfa();
  11437. if (this._cancelled || !xfaHtml) {
  11438. return {
  11439. textDivs: []
  11440. };
  11441. }
  11442. const parameters = {
  11443. viewport: viewport.clone({
  11444. dontFlip: true
  11445. }),
  11446. div: this.div,
  11447. xfaHtml,
  11448. annotationStorage: this.annotationStorage,
  11449. linkService: this.linkService,
  11450. intent
  11451. };
  11452. if (this.div) {
  11453. return _pdfjsLib.XfaLayer.update(parameters);
  11454. }
  11455. this.div = document.createElement("div");
  11456. this.pageDiv.append(this.div);
  11457. parameters.div = this.div;
  11458. return _pdfjsLib.XfaLayer.render(parameters);
  11459. }
  11460. cancel() {
  11461. this._cancelled = true;
  11462. }
  11463. hide() {
  11464. if (!this.div) {
  11465. return;
  11466. }
  11467. this.div.hidden = true;
  11468. }
  11469. }
  11470. exports.XfaLayerBuilder = XfaLayerBuilder;
  11471. /***/ }),
  11472. /* 38 */
  11473. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11474. Object.defineProperty(exports, "__esModule", ({
  11475. value: true
  11476. }));
  11477. exports.SecondaryToolbar = void 0;
  11478. var _ui_utils = __webpack_require__(3);
  11479. var _pdf_viewer = __webpack_require__(28);
  11480. class SecondaryToolbar {
  11481. constructor(options, eventBus, externalServices) {
  11482. this.toolbar = options.toolbar;
  11483. this.toggleButton = options.toggleButton;
  11484. this.buttons = [{
  11485. element: options.presentationModeButton,
  11486. eventName: "presentationmode",
  11487. close: true
  11488. }, {
  11489. element: options.printButton,
  11490. eventName: "print",
  11491. close: true
  11492. }, {
  11493. element: options.downloadButton,
  11494. eventName: "download",
  11495. close: true
  11496. }, {
  11497. element: options.viewBookmarkButton,
  11498. eventName: null,
  11499. close: true
  11500. }, {
  11501. element: options.firstPageButton,
  11502. eventName: "firstpage",
  11503. close: true
  11504. }, {
  11505. element: options.lastPageButton,
  11506. eventName: "lastpage",
  11507. close: true
  11508. }, {
  11509. element: options.pageRotateCwButton,
  11510. eventName: "rotatecw",
  11511. close: false
  11512. }, {
  11513. element: options.pageRotateCcwButton,
  11514. eventName: "rotateccw",
  11515. close: false
  11516. }, {
  11517. element: options.cursorSelectToolButton,
  11518. eventName: "switchcursortool",
  11519. eventDetails: {
  11520. tool: _ui_utils.CursorTool.SELECT
  11521. },
  11522. close: true
  11523. }, {
  11524. element: options.cursorHandToolButton,
  11525. eventName: "switchcursortool",
  11526. eventDetails: {
  11527. tool: _ui_utils.CursorTool.HAND
  11528. },
  11529. close: true
  11530. }, {
  11531. element: options.scrollPageButton,
  11532. eventName: "switchscrollmode",
  11533. eventDetails: {
  11534. mode: _ui_utils.ScrollMode.PAGE
  11535. },
  11536. close: true
  11537. }, {
  11538. element: options.scrollVerticalButton,
  11539. eventName: "switchscrollmode",
  11540. eventDetails: {
  11541. mode: _ui_utils.ScrollMode.VERTICAL
  11542. },
  11543. close: true
  11544. }, {
  11545. element: options.scrollHorizontalButton,
  11546. eventName: "switchscrollmode",
  11547. eventDetails: {
  11548. mode: _ui_utils.ScrollMode.HORIZONTAL
  11549. },
  11550. close: true
  11551. }, {
  11552. element: options.scrollWrappedButton,
  11553. eventName: "switchscrollmode",
  11554. eventDetails: {
  11555. mode: _ui_utils.ScrollMode.WRAPPED
  11556. },
  11557. close: true
  11558. }, {
  11559. element: options.spreadNoneButton,
  11560. eventName: "switchspreadmode",
  11561. eventDetails: {
  11562. mode: _ui_utils.SpreadMode.NONE
  11563. },
  11564. close: true
  11565. }, {
  11566. element: options.spreadOddButton,
  11567. eventName: "switchspreadmode",
  11568. eventDetails: {
  11569. mode: _ui_utils.SpreadMode.ODD
  11570. },
  11571. close: true
  11572. }, {
  11573. element: options.spreadEvenButton,
  11574. eventName: "switchspreadmode",
  11575. eventDetails: {
  11576. mode: _ui_utils.SpreadMode.EVEN
  11577. },
  11578. close: true
  11579. }, {
  11580. element: options.documentPropertiesButton,
  11581. eventName: "documentproperties",
  11582. close: true
  11583. }];
  11584. this.buttons.push({
  11585. element: options.openFileButton,
  11586. eventName: "openfile",
  11587. close: true
  11588. });
  11589. this.items = {
  11590. firstPage: options.firstPageButton,
  11591. lastPage: options.lastPageButton,
  11592. pageRotateCw: options.pageRotateCwButton,
  11593. pageRotateCcw: options.pageRotateCcwButton
  11594. };
  11595. this.eventBus = eventBus;
  11596. this.externalServices = externalServices;
  11597. this.opened = false;
  11598. this.#bindClickListeners();
  11599. this.#bindCursorToolsListener(options);
  11600. this.#bindScrollModeListener(options);
  11601. this.#bindSpreadModeListener(options);
  11602. this.reset();
  11603. }
  11604. get isOpen() {
  11605. return this.opened;
  11606. }
  11607. setPageNumber(pageNumber) {
  11608. this.pageNumber = pageNumber;
  11609. this.#updateUIState();
  11610. }
  11611. setPagesCount(pagesCount) {
  11612. this.pagesCount = pagesCount;
  11613. this.#updateUIState();
  11614. }
  11615. reset() {
  11616. this.pageNumber = 0;
  11617. this.pagesCount = 0;
  11618. this.#updateUIState();
  11619. this.eventBus.dispatch("secondarytoolbarreset", {
  11620. source: this
  11621. });
  11622. }
  11623. #updateUIState() {
  11624. this.items.firstPage.disabled = this.pageNumber <= 1;
  11625. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  11626. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  11627. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  11628. }
  11629. #bindClickListeners() {
  11630. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  11631. for (const {
  11632. element,
  11633. eventName,
  11634. close,
  11635. eventDetails
  11636. } of this.buttons) {
  11637. element.addEventListener("click", evt => {
  11638. if (eventName !== null) {
  11639. this.eventBus.dispatch(eventName, {
  11640. source: this,
  11641. ...eventDetails
  11642. });
  11643. }
  11644. if (close) {
  11645. this.close();
  11646. }
  11647. this.externalServices.reportTelemetry({
  11648. type: "buttons",
  11649. data: {
  11650. id: element.id
  11651. }
  11652. });
  11653. });
  11654. }
  11655. }
  11656. #bindCursorToolsListener({
  11657. cursorSelectToolButton,
  11658. cursorHandToolButton
  11659. }) {
  11660. this.eventBus._on("cursortoolchanged", ({
  11661. tool
  11662. }) => {
  11663. (0, _ui_utils.toggleCheckedBtn)(cursorSelectToolButton, tool === _ui_utils.CursorTool.SELECT);
  11664. (0, _ui_utils.toggleCheckedBtn)(cursorHandToolButton, tool === _ui_utils.CursorTool.HAND);
  11665. });
  11666. }
  11667. #bindScrollModeListener({
  11668. scrollPageButton,
  11669. scrollVerticalButton,
  11670. scrollHorizontalButton,
  11671. scrollWrappedButton,
  11672. spreadNoneButton,
  11673. spreadOddButton,
  11674. spreadEvenButton
  11675. }) {
  11676. const scrollModeChanged = ({
  11677. mode
  11678. }) => {
  11679. (0, _ui_utils.toggleCheckedBtn)(scrollPageButton, mode === _ui_utils.ScrollMode.PAGE);
  11680. (0, _ui_utils.toggleCheckedBtn)(scrollVerticalButton, mode === _ui_utils.ScrollMode.VERTICAL);
  11681. (0, _ui_utils.toggleCheckedBtn)(scrollHorizontalButton, mode === _ui_utils.ScrollMode.HORIZONTAL);
  11682. (0, _ui_utils.toggleCheckedBtn)(scrollWrappedButton, mode === _ui_utils.ScrollMode.WRAPPED);
  11683. const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11684. scrollPageButton.disabled = forceScrollModePage;
  11685. scrollVerticalButton.disabled = forceScrollModePage;
  11686. scrollHorizontalButton.disabled = forceScrollModePage;
  11687. scrollWrappedButton.disabled = forceScrollModePage;
  11688. const isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  11689. spreadNoneButton.disabled = isHorizontal;
  11690. spreadOddButton.disabled = isHorizontal;
  11691. spreadEvenButton.disabled = isHorizontal;
  11692. };
  11693. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  11694. this.eventBus._on("secondarytoolbarreset", evt => {
  11695. if (evt.source === this) {
  11696. scrollModeChanged({
  11697. mode: _ui_utils.ScrollMode.VERTICAL
  11698. });
  11699. }
  11700. });
  11701. }
  11702. #bindSpreadModeListener({
  11703. spreadNoneButton,
  11704. spreadOddButton,
  11705. spreadEvenButton
  11706. }) {
  11707. const spreadModeChanged = ({
  11708. mode
  11709. }) => {
  11710. (0, _ui_utils.toggleCheckedBtn)(spreadNoneButton, mode === _ui_utils.SpreadMode.NONE);
  11711. (0, _ui_utils.toggleCheckedBtn)(spreadOddButton, mode === _ui_utils.SpreadMode.ODD);
  11712. (0, _ui_utils.toggleCheckedBtn)(spreadEvenButton, mode === _ui_utils.SpreadMode.EVEN);
  11713. };
  11714. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  11715. this.eventBus._on("secondarytoolbarreset", evt => {
  11716. if (evt.source === this) {
  11717. spreadModeChanged({
  11718. mode: _ui_utils.SpreadMode.NONE
  11719. });
  11720. }
  11721. });
  11722. }
  11723. open() {
  11724. if (this.opened) {
  11725. return;
  11726. }
  11727. this.opened = true;
  11728. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true, this.toolbar);
  11729. }
  11730. close() {
  11731. if (!this.opened) {
  11732. return;
  11733. }
  11734. this.opened = false;
  11735. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false, this.toolbar);
  11736. }
  11737. toggle() {
  11738. if (this.opened) {
  11739. this.close();
  11740. } else {
  11741. this.open();
  11742. }
  11743. }
  11744. }
  11745. exports.SecondaryToolbar = SecondaryToolbar;
  11746. /***/ }),
  11747. /* 39 */
  11748. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11749. Object.defineProperty(exports, "__esModule", ({
  11750. value: true
  11751. }));
  11752. exports.Toolbar = void 0;
  11753. var _ui_utils = __webpack_require__(3);
  11754. var _pdfjsLib = __webpack_require__(4);
  11755. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  11756. class Toolbar {
  11757. #wasLocalized = false;
  11758. constructor(options, eventBus, l10n) {
  11759. this.toolbar = options.container;
  11760. this.eventBus = eventBus;
  11761. this.l10n = l10n;
  11762. this.buttons = [{
  11763. element: options.previous,
  11764. eventName: "previouspage"
  11765. }, {
  11766. element: options.next,
  11767. eventName: "nextpage"
  11768. }, {
  11769. element: options.zoomIn,
  11770. eventName: "zoomin"
  11771. }, {
  11772. element: options.zoomOut,
  11773. eventName: "zoomout"
  11774. }, {
  11775. element: options.print,
  11776. eventName: "print"
  11777. }, {
  11778. element: options.download,
  11779. eventName: "download"
  11780. }, {
  11781. element: options.editorFreeTextButton,
  11782. eventName: "switchannotationeditormode",
  11783. eventDetails: {
  11784. get mode() {
  11785. const {
  11786. classList
  11787. } = options.editorFreeTextButton;
  11788. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  11789. }
  11790. }
  11791. }, {
  11792. element: options.editorInkButton,
  11793. eventName: "switchannotationeditormode",
  11794. eventDetails: {
  11795. get mode() {
  11796. const {
  11797. classList
  11798. } = options.editorInkButton;
  11799. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  11800. }
  11801. }
  11802. }, {
  11803. element: options.editorStampButton,
  11804. eventName: "switchannotationeditormode",
  11805. eventDetails: {
  11806. get mode() {
  11807. const {
  11808. classList
  11809. } = options.editorStampButton;
  11810. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.STAMP;
  11811. }
  11812. }
  11813. }];
  11814. this.buttons.push({
  11815. element: options.openFile,
  11816. eventName: "openfile"
  11817. });
  11818. this.items = {
  11819. numPages: options.numPages,
  11820. pageNumber: options.pageNumber,
  11821. scaleSelect: options.scaleSelect,
  11822. customScaleOption: options.customScaleOption,
  11823. previous: options.previous,
  11824. next: options.next,
  11825. zoomIn: options.zoomIn,
  11826. zoomOut: options.zoomOut
  11827. };
  11828. this.#bindListeners(options);
  11829. this.reset();
  11830. }
  11831. setPageNumber(pageNumber, pageLabel) {
  11832. this.pageNumber = pageNumber;
  11833. this.pageLabel = pageLabel;
  11834. this.#updateUIState(false);
  11835. }
  11836. setPagesCount(pagesCount, hasPageLabels) {
  11837. this.pagesCount = pagesCount;
  11838. this.hasPageLabels = hasPageLabels;
  11839. this.#updateUIState(true);
  11840. }
  11841. setPageScale(pageScaleValue, pageScale) {
  11842. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11843. this.pageScale = pageScale;
  11844. this.#updateUIState(false);
  11845. }
  11846. reset() {
  11847. this.pageNumber = 0;
  11848. this.pageLabel = null;
  11849. this.hasPageLabels = false;
  11850. this.pagesCount = 0;
  11851. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  11852. this.pageScale = _ui_utils.DEFAULT_SCALE;
  11853. this.#updateUIState(true);
  11854. this.updateLoadingIndicatorState();
  11855. this.eventBus.dispatch("toolbarreset", {
  11856. source: this
  11857. });
  11858. }
  11859. #bindListeners(options) {
  11860. const {
  11861. pageNumber,
  11862. scaleSelect
  11863. } = this.items;
  11864. const self = this;
  11865. for (const {
  11866. element,
  11867. eventName,
  11868. eventDetails
  11869. } of this.buttons) {
  11870. element.addEventListener("click", evt => {
  11871. if (eventName !== null) {
  11872. this.eventBus.dispatch(eventName, {
  11873. source: this,
  11874. ...eventDetails
  11875. });
  11876. }
  11877. });
  11878. }
  11879. pageNumber.addEventListener("click", function () {
  11880. this.select();
  11881. });
  11882. pageNumber.addEventListener("change", function () {
  11883. self.eventBus.dispatch("pagenumberchanged", {
  11884. source: self,
  11885. value: this.value
  11886. });
  11887. });
  11888. scaleSelect.addEventListener("change", function () {
  11889. if (this.value === "custom") {
  11890. return;
  11891. }
  11892. self.eventBus.dispatch("scalechanged", {
  11893. source: self,
  11894. value: this.value
  11895. });
  11896. });
  11897. scaleSelect.addEventListener("click", function (evt) {
  11898. const target = evt.target;
  11899. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11900. this.blur();
  11901. }
  11902. });
  11903. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  11904. this.eventBus._on("localized", () => {
  11905. this.#wasLocalized = true;
  11906. this.#adjustScaleWidth();
  11907. this.#updateUIState(true);
  11908. });
  11909. this.#bindEditorToolsListener(options);
  11910. }
  11911. #bindEditorToolsListener({
  11912. editorFreeTextButton,
  11913. editorFreeTextParamsToolbar,
  11914. editorInkButton,
  11915. editorInkParamsToolbar,
  11916. editorStampButton,
  11917. editorStampParamsToolbar
  11918. }) {
  11919. const editorModeChanged = ({
  11920. mode
  11921. }) => {
  11922. (0, _ui_utils.toggleCheckedBtn)(editorFreeTextButton, mode === _pdfjsLib.AnnotationEditorType.FREETEXT, editorFreeTextParamsToolbar);
  11923. (0, _ui_utils.toggleCheckedBtn)(editorInkButton, mode === _pdfjsLib.AnnotationEditorType.INK, editorInkParamsToolbar);
  11924. (0, _ui_utils.toggleCheckedBtn)(editorStampButton, mode === _pdfjsLib.AnnotationEditorType.STAMP, editorStampParamsToolbar);
  11925. const isDisable = mode === _pdfjsLib.AnnotationEditorType.DISABLE;
  11926. editorFreeTextButton.disabled = isDisable;
  11927. editorInkButton.disabled = isDisable;
  11928. editorStampButton.disabled = isDisable;
  11929. };
  11930. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  11931. this.eventBus._on("toolbarreset", evt => {
  11932. if (evt.source === this) {
  11933. editorModeChanged({
  11934. mode: _pdfjsLib.AnnotationEditorType.DISABLE
  11935. });
  11936. }
  11937. });
  11938. }
  11939. #updateUIState(resetNumPages = false) {
  11940. if (!this.#wasLocalized) {
  11941. return;
  11942. }
  11943. const {
  11944. pageNumber,
  11945. pagesCount,
  11946. pageScaleValue,
  11947. pageScale,
  11948. items
  11949. } = this;
  11950. if (resetNumPages) {
  11951. if (this.hasPageLabels) {
  11952. items.pageNumber.type = "text";
  11953. } else {
  11954. items.pageNumber.type = "number";
  11955. this.l10n.get("of_pages", {
  11956. pagesCount
  11957. }).then(msg => {
  11958. items.numPages.textContent = msg;
  11959. });
  11960. }
  11961. items.pageNumber.max = pagesCount;
  11962. }
  11963. if (this.hasPageLabels) {
  11964. items.pageNumber.value = this.pageLabel;
  11965. this.l10n.get("page_of_pages", {
  11966. pageNumber,
  11967. pagesCount
  11968. }).then(msg => {
  11969. items.numPages.textContent = msg;
  11970. });
  11971. } else {
  11972. items.pageNumber.value = pageNumber;
  11973. }
  11974. items.previous.disabled = pageNumber <= 1;
  11975. items.next.disabled = pageNumber >= pagesCount;
  11976. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  11977. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  11978. this.l10n.get("page_scale_percent", {
  11979. scale: Math.round(pageScale * 10000) / 100
  11980. }).then(msg => {
  11981. let predefinedValueFound = false;
  11982. for (const option of items.scaleSelect.options) {
  11983. if (option.value !== pageScaleValue) {
  11984. option.selected = false;
  11985. continue;
  11986. }
  11987. option.selected = true;
  11988. predefinedValueFound = true;
  11989. }
  11990. if (!predefinedValueFound) {
  11991. items.customScaleOption.textContent = msg;
  11992. items.customScaleOption.selected = true;
  11993. }
  11994. });
  11995. }
  11996. updateLoadingIndicatorState(loading = false) {
  11997. const {
  11998. pageNumber
  11999. } = this.items;
  12000. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  12001. }
  12002. async #adjustScaleWidth() {
  12003. const {
  12004. items,
  12005. l10n
  12006. } = this;
  12007. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  12008. await _ui_utils.animationStarted;
  12009. const style = getComputedStyle(items.scaleSelect);
  12010. const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width"));
  12011. const canvas = document.createElement("canvas");
  12012. const ctx = canvas.getContext("2d", {
  12013. alpha: false
  12014. });
  12015. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  12016. let maxWidth = 0;
  12017. for (const predefinedValue of await predefinedValuesPromise) {
  12018. const {
  12019. width
  12020. } = ctx.measureText(predefinedValue);
  12021. if (width > maxWidth) {
  12022. maxWidth = width;
  12023. }
  12024. }
  12025. maxWidth += 0.3 * scaleSelectWidth;
  12026. if (maxWidth > scaleSelectWidth) {
  12027. const container = items.scaleSelect.parentNode;
  12028. container.style.setProperty("--scale-select-width", `${maxWidth}px`);
  12029. }
  12030. canvas.width = 0;
  12031. canvas.height = 0;
  12032. }
  12033. }
  12034. exports.Toolbar = Toolbar;
  12035. /***/ }),
  12036. /* 40 */
  12037. /***/ ((__unused_webpack_module, exports) => {
  12038. Object.defineProperty(exports, "__esModule", ({
  12039. value: true
  12040. }));
  12041. exports.ViewHistory = void 0;
  12042. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  12043. class ViewHistory {
  12044. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  12045. this.fingerprint = fingerprint;
  12046. this.cacheSize = cacheSize;
  12047. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  12048. const database = JSON.parse(databaseStr || "{}");
  12049. let index = -1;
  12050. if (!Array.isArray(database.files)) {
  12051. database.files = [];
  12052. } else {
  12053. while (database.files.length >= this.cacheSize) {
  12054. database.files.shift();
  12055. }
  12056. for (let i = 0, ii = database.files.length; i < ii; i++) {
  12057. const branch = database.files[i];
  12058. if (branch.fingerprint === this.fingerprint) {
  12059. index = i;
  12060. break;
  12061. }
  12062. }
  12063. }
  12064. if (index === -1) {
  12065. index = database.files.push({
  12066. fingerprint: this.fingerprint
  12067. }) - 1;
  12068. }
  12069. this.file = database.files[index];
  12070. this.database = database;
  12071. });
  12072. }
  12073. async _writeToStorage() {
  12074. const databaseStr = JSON.stringify(this.database);
  12075. localStorage.setItem("pdfjs.history", databaseStr);
  12076. }
  12077. async _readFromStorage() {
  12078. return localStorage.getItem("pdfjs.history");
  12079. }
  12080. async set(name, val) {
  12081. await this._initializedPromise;
  12082. this.file[name] = val;
  12083. return this._writeToStorage();
  12084. }
  12085. async setMultiple(properties) {
  12086. await this._initializedPromise;
  12087. for (const name in properties) {
  12088. this.file[name] = properties[name];
  12089. }
  12090. return this._writeToStorage();
  12091. }
  12092. async get(name, defaultValue) {
  12093. await this._initializedPromise;
  12094. const val = this.file[name];
  12095. return val !== undefined ? val : defaultValue;
  12096. }
  12097. async getMultiple(properties) {
  12098. await this._initializedPromise;
  12099. const values = Object.create(null);
  12100. for (const name in properties) {
  12101. const val = this.file[name];
  12102. values[name] = val !== undefined ? val : properties[name];
  12103. }
  12104. return values;
  12105. }
  12106. }
  12107. exports.ViewHistory = ViewHistory;
  12108. /***/ }),
  12109. /* 41 */
  12110. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12111. Object.defineProperty(exports, "__esModule", ({
  12112. value: true
  12113. }));
  12114. exports.BasePreferences = void 0;
  12115. var _app_options = __webpack_require__(5);
  12116. class BasePreferences {
  12117. #defaults = Object.freeze({
  12118. "annotationEditorMode": 0,
  12119. "annotationMode": 2,
  12120. "cursorToolOnLoad": 0,
  12121. "defaultZoomDelay": 400,
  12122. "defaultZoomValue": "",
  12123. "disablePageLabels": false,
  12124. "enablePermissions": false,
  12125. "enablePrintAutoRotate": true,
  12126. "enableScripting": true,
  12127. "enableStampEditor": true,
  12128. "externalLinkTarget": 0,
  12129. "historyUpdateUrl": false,
  12130. "ignoreDestinationZoom": false,
  12131. "forcePageColors": false,
  12132. "pageColorsBackground": "Canvas",
  12133. "pageColorsForeground": "CanvasText",
  12134. "pdfBugEnabled": false,
  12135. "sidebarViewOnLoad": -1,
  12136. "scrollModeOnLoad": -1,
  12137. "spreadModeOnLoad": -1,
  12138. "textLayerMode": 1,
  12139. "viewerCssTheme": 0,
  12140. "viewOnLoad": 0,
  12141. "disableAutoFetch": false,
  12142. "disableFontFace": false,
  12143. "disableRange": false,
  12144. "disableStream": false,
  12145. "enableXfa": true
  12146. });
  12147. #prefs = Object.create(null);
  12148. #initializedPromise = null;
  12149. constructor() {
  12150. if (this.constructor === BasePreferences) {
  12151. throw new Error("Cannot initialize BasePreferences.");
  12152. }
  12153. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  12154. for (const name in this.#defaults) {
  12155. const prefValue = prefs?.[name];
  12156. if (typeof prefValue === typeof this.#defaults[name]) {
  12157. this.#prefs[name] = prefValue;
  12158. }
  12159. }
  12160. });
  12161. }
  12162. async _writeToStorage(prefObj) {
  12163. throw new Error("Not implemented: _writeToStorage");
  12164. }
  12165. async _readFromStorage(prefObj) {
  12166. throw new Error("Not implemented: _readFromStorage");
  12167. }
  12168. async reset() {
  12169. await this.#initializedPromise;
  12170. const prefs = this.#prefs;
  12171. this.#prefs = Object.create(null);
  12172. return this._writeToStorage(this.#defaults).catch(reason => {
  12173. this.#prefs = prefs;
  12174. throw reason;
  12175. });
  12176. }
  12177. async set(name, value) {
  12178. await this.#initializedPromise;
  12179. const defaultValue = this.#defaults[name],
  12180. prefs = this.#prefs;
  12181. if (defaultValue === undefined) {
  12182. throw new Error(`Set preference: "${name}" is undefined.`);
  12183. } else if (value === undefined) {
  12184. throw new Error("Set preference: no value is specified.");
  12185. }
  12186. const valueType = typeof value,
  12187. defaultType = typeof defaultValue;
  12188. if (valueType !== defaultType) {
  12189. if (valueType === "number" && defaultType === "string") {
  12190. value = value.toString();
  12191. } else {
  12192. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  12193. }
  12194. } else if (valueType === "number" && !Number.isInteger(value)) {
  12195. throw new Error(`Set preference: "${value}" must be an integer.`);
  12196. }
  12197. this.#prefs[name] = value;
  12198. return this._writeToStorage(this.#prefs).catch(reason => {
  12199. this.#prefs = prefs;
  12200. throw reason;
  12201. });
  12202. }
  12203. async get(name) {
  12204. await this.#initializedPromise;
  12205. const defaultValue = this.#defaults[name];
  12206. if (defaultValue === undefined) {
  12207. throw new Error(`Get preference: "${name}" is undefined.`);
  12208. }
  12209. return this.#prefs[name] ?? defaultValue;
  12210. }
  12211. async getAll() {
  12212. await this.#initializedPromise;
  12213. const obj = Object.create(null);
  12214. for (const name in this.#defaults) {
  12215. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  12216. }
  12217. return obj;
  12218. }
  12219. }
  12220. exports.BasePreferences = BasePreferences;
  12221. /***/ }),
  12222. /* 42 */
  12223. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12224. Object.defineProperty(exports, "__esModule", ({
  12225. value: true
  12226. }));
  12227. exports.DownloadManager = void 0;
  12228. var _pdfjsLib = __webpack_require__(4);
  12229. ;
  12230. function download(blobUrl, filename) {
  12231. const a = document.createElement("a");
  12232. if (!a.click) {
  12233. throw new Error('DownloadManager: "a.click()" is not supported.');
  12234. }
  12235. a.href = blobUrl;
  12236. a.target = "_parent";
  12237. if ("download" in a) {
  12238. a.download = filename;
  12239. }
  12240. (document.body || document.documentElement).append(a);
  12241. a.click();
  12242. a.remove();
  12243. }
  12244. class DownloadManager {
  12245. #openBlobUrls = new WeakMap();
  12246. downloadUrl(url, filename, _options) {
  12247. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  12248. console.error(`downloadUrl - not a valid URL: ${url}`);
  12249. return;
  12250. }
  12251. download(url + "#pdfjs.action=download", filename);
  12252. }
  12253. downloadData(data, filename, contentType) {
  12254. const blobUrl = URL.createObjectURL(new Blob([data], {
  12255. type: contentType
  12256. }));
  12257. download(blobUrl, filename);
  12258. }
  12259. openOrDownloadData(element, data, filename) {
  12260. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  12261. const contentType = isPdfData ? "application/pdf" : "";
  12262. if (isPdfData) {
  12263. let blobUrl = this.#openBlobUrls.get(element);
  12264. if (!blobUrl) {
  12265. blobUrl = URL.createObjectURL(new Blob([data], {
  12266. type: contentType
  12267. }));
  12268. this.#openBlobUrls.set(element, blobUrl);
  12269. }
  12270. let viewerUrl;
  12271. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  12272. try {
  12273. window.open(viewerUrl);
  12274. return true;
  12275. } catch (ex) {
  12276. console.error(`openOrDownloadData: ${ex}`);
  12277. URL.revokeObjectURL(blobUrl);
  12278. this.#openBlobUrls.delete(element);
  12279. }
  12280. }
  12281. this.downloadData(data, filename, contentType);
  12282. return false;
  12283. }
  12284. download(blob, url, filename, _options) {
  12285. const blobUrl = URL.createObjectURL(blob);
  12286. download(blobUrl, filename);
  12287. }
  12288. }
  12289. exports.DownloadManager = DownloadManager;
  12290. /***/ }),
  12291. /* 43 */
  12292. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12293. Object.defineProperty(exports, "__esModule", ({
  12294. value: true
  12295. }));
  12296. exports.GenericL10n = void 0;
  12297. __webpack_require__(44);
  12298. var _l10n_utils = __webpack_require__(29);
  12299. const PARTIAL_LANG_CODES = {
  12300. en: "en-US",
  12301. es: "es-ES",
  12302. fy: "fy-NL",
  12303. ga: "ga-IE",
  12304. gu: "gu-IN",
  12305. hi: "hi-IN",
  12306. hy: "hy-AM",
  12307. nb: "nb-NO",
  12308. ne: "ne-NP",
  12309. nn: "nn-NO",
  12310. pa: "pa-IN",
  12311. pt: "pt-PT",
  12312. sv: "sv-SE",
  12313. zh: "zh-CN"
  12314. };
  12315. function fixupLangCode(langCode) {
  12316. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  12317. }
  12318. class GenericL10n {
  12319. constructor(lang) {
  12320. const {
  12321. webL10n
  12322. } = document;
  12323. this._lang = lang;
  12324. this._ready = new Promise((resolve, reject) => {
  12325. webL10n.setLanguage(fixupLangCode(lang), () => {
  12326. resolve(webL10n);
  12327. });
  12328. });
  12329. }
  12330. async getLanguage() {
  12331. const l10n = await this._ready;
  12332. return l10n.getLanguage();
  12333. }
  12334. async getDirection() {
  12335. const l10n = await this._ready;
  12336. return l10n.getDirection();
  12337. }
  12338. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  12339. const l10n = await this._ready;
  12340. return l10n.get(key, args, fallback);
  12341. }
  12342. async translate(element) {
  12343. const l10n = await this._ready;
  12344. return l10n.translate(element);
  12345. }
  12346. }
  12347. exports.GenericL10n = GenericL10n;
  12348. /***/ }),
  12349. /* 44 */
  12350. /***/ (() => {
  12351. document.webL10n = function (window, document) {
  12352. var gL10nData = {};
  12353. var gTextData = '';
  12354. var gTextProp = 'textContent';
  12355. var gLanguage = '';
  12356. var gMacros = {};
  12357. var gReadyState = 'loading';
  12358. var gAsyncResourceLoading = true;
  12359. function getL10nResourceLinks() {
  12360. return document.querySelectorAll('link[type="application/l10n"]');
  12361. }
  12362. function getL10nDictionary() {
  12363. var script = document.querySelector('script[type="application/l10n"]');
  12364. return script ? JSON.parse(script.innerHTML) : null;
  12365. }
  12366. function getTranslatableChildren(element) {
  12367. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  12368. }
  12369. function getL10nAttributes(element) {
  12370. if (!element) return {};
  12371. var l10nId = element.getAttribute('data-l10n-id');
  12372. var l10nArgs = element.getAttribute('data-l10n-args');
  12373. var args = {};
  12374. if (l10nArgs) {
  12375. try {
  12376. args = JSON.parse(l10nArgs);
  12377. } catch (e) {
  12378. console.warn('could not parse arguments for #' + l10nId);
  12379. }
  12380. }
  12381. return {
  12382. id: l10nId,
  12383. args: args
  12384. };
  12385. }
  12386. function xhrLoadText(url, onSuccess, onFailure) {
  12387. onSuccess = onSuccess || function _onSuccess(data) {};
  12388. onFailure = onFailure || function _onFailure() {};
  12389. var xhr = new XMLHttpRequest();
  12390. xhr.open('GET', url, gAsyncResourceLoading);
  12391. if (xhr.overrideMimeType) {
  12392. xhr.overrideMimeType('text/plain; charset=utf-8');
  12393. }
  12394. xhr.onreadystatechange = function () {
  12395. if (xhr.readyState == 4) {
  12396. if (xhr.status == 200 || xhr.status === 0) {
  12397. onSuccess(xhr.responseText);
  12398. } else {
  12399. onFailure();
  12400. }
  12401. }
  12402. };
  12403. xhr.onerror = onFailure;
  12404. xhr.ontimeout = onFailure;
  12405. try {
  12406. xhr.send(null);
  12407. } catch (e) {
  12408. onFailure();
  12409. }
  12410. }
  12411. function parseResource(href, lang, successCallback, failureCallback) {
  12412. var baseURL = href.replace(/[^\/]*$/, '') || './';
  12413. function evalString(text) {
  12414. if (text.lastIndexOf('\\') < 0) return text;
  12415. 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, "'");
  12416. }
  12417. function parseProperties(text, parsedPropertiesCallback) {
  12418. var dictionary = {};
  12419. var reBlank = /^\s*|\s*$/;
  12420. var reComment = /^\s*#|^\s*$/;
  12421. var reSection = /^\s*\[(.*)\]\s*$/;
  12422. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  12423. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  12424. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  12425. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  12426. var currentLang = '*';
  12427. var genericLang = lang.split('-', 1)[0];
  12428. var skipLang = false;
  12429. var match = '';
  12430. function nextEntry() {
  12431. while (true) {
  12432. if (!entries.length) {
  12433. parsedRawLinesCallback();
  12434. return;
  12435. }
  12436. var line = entries.shift();
  12437. if (reComment.test(line)) continue;
  12438. if (extendedSyntax) {
  12439. match = reSection.exec(line);
  12440. if (match) {
  12441. currentLang = match[1].toLowerCase();
  12442. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  12443. continue;
  12444. } else if (skipLang) {
  12445. continue;
  12446. }
  12447. match = reImport.exec(line);
  12448. if (match) {
  12449. loadImport(baseURL + match[1], nextEntry);
  12450. return;
  12451. }
  12452. }
  12453. var tmp = line.match(reSplit);
  12454. if (tmp && tmp.length == 3) {
  12455. dictionary[tmp[1]] = evalString(tmp[2]);
  12456. }
  12457. }
  12458. }
  12459. nextEntry();
  12460. }
  12461. function loadImport(url, callback) {
  12462. xhrLoadText(url, function (content) {
  12463. parseRawLines(content, false, callback);
  12464. }, function () {
  12465. console.warn(url + ' not found.');
  12466. callback();
  12467. });
  12468. }
  12469. parseRawLines(text, true, function () {
  12470. parsedPropertiesCallback(dictionary);
  12471. });
  12472. }
  12473. xhrLoadText(href, function (response) {
  12474. gTextData += response;
  12475. parseProperties(response, function (data) {
  12476. for (var key in data) {
  12477. var id,
  12478. prop,
  12479. index = key.lastIndexOf('.');
  12480. if (index > 0) {
  12481. id = key.substring(0, index);
  12482. prop = key.substring(index + 1);
  12483. } else {
  12484. id = key;
  12485. prop = gTextProp;
  12486. }
  12487. if (!gL10nData[id]) {
  12488. gL10nData[id] = {};
  12489. }
  12490. gL10nData[id][prop] = data[key];
  12491. }
  12492. if (successCallback) {
  12493. successCallback();
  12494. }
  12495. });
  12496. }, failureCallback);
  12497. }
  12498. function loadLocale(lang, callback) {
  12499. if (lang) {
  12500. lang = lang.toLowerCase();
  12501. }
  12502. callback = callback || function _callback() {};
  12503. clear();
  12504. gLanguage = lang;
  12505. var langLinks = getL10nResourceLinks();
  12506. var langCount = langLinks.length;
  12507. if (langCount === 0) {
  12508. var dict = getL10nDictionary();
  12509. if (dict && dict.locales && dict.default_locale) {
  12510. console.log('using the embedded JSON directory, early way out');
  12511. gL10nData = dict.locales[lang];
  12512. if (!gL10nData) {
  12513. var defaultLocale = dict.default_locale.toLowerCase();
  12514. for (var anyCaseLang in dict.locales) {
  12515. anyCaseLang = anyCaseLang.toLowerCase();
  12516. if (anyCaseLang === lang) {
  12517. gL10nData = dict.locales[lang];
  12518. break;
  12519. } else if (anyCaseLang === defaultLocale) {
  12520. gL10nData = dict.locales[defaultLocale];
  12521. }
  12522. }
  12523. }
  12524. callback();
  12525. } else {
  12526. console.log('no resource to load, early way out');
  12527. }
  12528. gReadyState = 'complete';
  12529. return;
  12530. }
  12531. var onResourceLoaded = null;
  12532. var gResourceCount = 0;
  12533. onResourceLoaded = function () {
  12534. gResourceCount++;
  12535. if (gResourceCount >= langCount) {
  12536. callback();
  12537. gReadyState = 'complete';
  12538. }
  12539. };
  12540. function L10nResourceLink(link) {
  12541. var href = link.href;
  12542. this.load = function (lang, callback) {
  12543. parseResource(href, lang, callback, function () {
  12544. console.warn(href + ' not found.');
  12545. console.warn('"' + lang + '" resource not found');
  12546. gLanguage = '';
  12547. callback();
  12548. });
  12549. };
  12550. }
  12551. for (var i = 0; i < langCount; i++) {
  12552. var resource = new L10nResourceLink(langLinks[i]);
  12553. resource.load(lang, onResourceLoaded);
  12554. }
  12555. }
  12556. function clear() {
  12557. gL10nData = {};
  12558. gTextData = '';
  12559. gLanguage = '';
  12560. }
  12561. function getPluralRules(lang) {
  12562. var locales2rules = {
  12563. 'af': 3,
  12564. 'ak': 4,
  12565. 'am': 4,
  12566. 'ar': 1,
  12567. 'asa': 3,
  12568. 'az': 0,
  12569. 'be': 11,
  12570. 'bem': 3,
  12571. 'bez': 3,
  12572. 'bg': 3,
  12573. 'bh': 4,
  12574. 'bm': 0,
  12575. 'bn': 3,
  12576. 'bo': 0,
  12577. 'br': 20,
  12578. 'brx': 3,
  12579. 'bs': 11,
  12580. 'ca': 3,
  12581. 'cgg': 3,
  12582. 'chr': 3,
  12583. 'cs': 12,
  12584. 'cy': 17,
  12585. 'da': 3,
  12586. 'de': 3,
  12587. 'dv': 3,
  12588. 'dz': 0,
  12589. 'ee': 3,
  12590. 'el': 3,
  12591. 'en': 3,
  12592. 'eo': 3,
  12593. 'es': 3,
  12594. 'et': 3,
  12595. 'eu': 3,
  12596. 'fa': 0,
  12597. 'ff': 5,
  12598. 'fi': 3,
  12599. 'fil': 4,
  12600. 'fo': 3,
  12601. 'fr': 5,
  12602. 'fur': 3,
  12603. 'fy': 3,
  12604. 'ga': 8,
  12605. 'gd': 24,
  12606. 'gl': 3,
  12607. 'gsw': 3,
  12608. 'gu': 3,
  12609. 'guw': 4,
  12610. 'gv': 23,
  12611. 'ha': 3,
  12612. 'haw': 3,
  12613. 'he': 2,
  12614. 'hi': 4,
  12615. 'hr': 11,
  12616. 'hu': 0,
  12617. 'id': 0,
  12618. 'ig': 0,
  12619. 'ii': 0,
  12620. 'is': 3,
  12621. 'it': 3,
  12622. 'iu': 7,
  12623. 'ja': 0,
  12624. 'jmc': 3,
  12625. 'jv': 0,
  12626. 'ka': 0,
  12627. 'kab': 5,
  12628. 'kaj': 3,
  12629. 'kcg': 3,
  12630. 'kde': 0,
  12631. 'kea': 0,
  12632. 'kk': 3,
  12633. 'kl': 3,
  12634. 'km': 0,
  12635. 'kn': 0,
  12636. 'ko': 0,
  12637. 'ksb': 3,
  12638. 'ksh': 21,
  12639. 'ku': 3,
  12640. 'kw': 7,
  12641. 'lag': 18,
  12642. 'lb': 3,
  12643. 'lg': 3,
  12644. 'ln': 4,
  12645. 'lo': 0,
  12646. 'lt': 10,
  12647. 'lv': 6,
  12648. 'mas': 3,
  12649. 'mg': 4,
  12650. 'mk': 16,
  12651. 'ml': 3,
  12652. 'mn': 3,
  12653. 'mo': 9,
  12654. 'mr': 3,
  12655. 'ms': 0,
  12656. 'mt': 15,
  12657. 'my': 0,
  12658. 'nah': 3,
  12659. 'naq': 7,
  12660. 'nb': 3,
  12661. 'nd': 3,
  12662. 'ne': 3,
  12663. 'nl': 3,
  12664. 'nn': 3,
  12665. 'no': 3,
  12666. 'nr': 3,
  12667. 'nso': 4,
  12668. 'ny': 3,
  12669. 'nyn': 3,
  12670. 'om': 3,
  12671. 'or': 3,
  12672. 'pa': 3,
  12673. 'pap': 3,
  12674. 'pl': 13,
  12675. 'ps': 3,
  12676. 'pt': 3,
  12677. 'rm': 3,
  12678. 'ro': 9,
  12679. 'rof': 3,
  12680. 'ru': 11,
  12681. 'rwk': 3,
  12682. 'sah': 0,
  12683. 'saq': 3,
  12684. 'se': 7,
  12685. 'seh': 3,
  12686. 'ses': 0,
  12687. 'sg': 0,
  12688. 'sh': 11,
  12689. 'shi': 19,
  12690. 'sk': 12,
  12691. 'sl': 14,
  12692. 'sma': 7,
  12693. 'smi': 7,
  12694. 'smj': 7,
  12695. 'smn': 7,
  12696. 'sms': 7,
  12697. 'sn': 3,
  12698. 'so': 3,
  12699. 'sq': 3,
  12700. 'sr': 11,
  12701. 'ss': 3,
  12702. 'ssy': 3,
  12703. 'st': 3,
  12704. 'sv': 3,
  12705. 'sw': 3,
  12706. 'syr': 3,
  12707. 'ta': 3,
  12708. 'te': 3,
  12709. 'teo': 3,
  12710. 'th': 0,
  12711. 'ti': 4,
  12712. 'tig': 3,
  12713. 'tk': 3,
  12714. 'tl': 4,
  12715. 'tn': 3,
  12716. 'to': 0,
  12717. 'tr': 0,
  12718. 'ts': 3,
  12719. 'tzm': 22,
  12720. 'uk': 11,
  12721. 'ur': 3,
  12722. 've': 3,
  12723. 'vi': 0,
  12724. 'vun': 3,
  12725. 'wa': 4,
  12726. 'wae': 3,
  12727. 'wo': 0,
  12728. 'xh': 3,
  12729. 'xog': 3,
  12730. 'yo': 0,
  12731. 'zh': 0,
  12732. 'zu': 3
  12733. };
  12734. function isIn(n, list) {
  12735. return list.indexOf(n) !== -1;
  12736. }
  12737. function isBetween(n, start, end) {
  12738. return start <= n && n <= end;
  12739. }
  12740. var pluralRules = {
  12741. '0': function (n) {
  12742. return 'other';
  12743. },
  12744. '1': function (n) {
  12745. if (isBetween(n % 100, 3, 10)) return 'few';
  12746. if (n === 0) return 'zero';
  12747. if (isBetween(n % 100, 11, 99)) return 'many';
  12748. if (n == 2) return 'two';
  12749. if (n == 1) return 'one';
  12750. return 'other';
  12751. },
  12752. '2': function (n) {
  12753. if (n !== 0 && n % 10 === 0) return 'many';
  12754. if (n == 2) return 'two';
  12755. if (n == 1) return 'one';
  12756. return 'other';
  12757. },
  12758. '3': function (n) {
  12759. if (n == 1) return 'one';
  12760. return 'other';
  12761. },
  12762. '4': function (n) {
  12763. if (isBetween(n, 0, 1)) return 'one';
  12764. return 'other';
  12765. },
  12766. '5': function (n) {
  12767. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12768. return 'other';
  12769. },
  12770. '6': function (n) {
  12771. if (n === 0) return 'zero';
  12772. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12773. return 'other';
  12774. },
  12775. '7': function (n) {
  12776. if (n == 2) return 'two';
  12777. if (n == 1) return 'one';
  12778. return 'other';
  12779. },
  12780. '8': function (n) {
  12781. if (isBetween(n, 3, 6)) return 'few';
  12782. if (isBetween(n, 7, 10)) return 'many';
  12783. if (n == 2) return 'two';
  12784. if (n == 1) return 'one';
  12785. return 'other';
  12786. },
  12787. '9': function (n) {
  12788. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12789. if (n == 1) return 'one';
  12790. return 'other';
  12791. },
  12792. '10': function (n) {
  12793. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12794. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12795. return 'other';
  12796. },
  12797. '11': function (n) {
  12798. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12799. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12800. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12801. return 'other';
  12802. },
  12803. '12': function (n) {
  12804. if (isBetween(n, 2, 4)) return 'few';
  12805. if (n == 1) return 'one';
  12806. return 'other';
  12807. },
  12808. '13': function (n) {
  12809. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12810. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12811. if (n == 1) return 'one';
  12812. return 'other';
  12813. },
  12814. '14': function (n) {
  12815. if (isBetween(n % 100, 3, 4)) return 'few';
  12816. if (n % 100 == 2) return 'two';
  12817. if (n % 100 == 1) return 'one';
  12818. return 'other';
  12819. },
  12820. '15': function (n) {
  12821. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12822. if (isBetween(n % 100, 11, 19)) return 'many';
  12823. if (n == 1) return 'one';
  12824. return 'other';
  12825. },
  12826. '16': function (n) {
  12827. if (n % 10 == 1 && n != 11) return 'one';
  12828. return 'other';
  12829. },
  12830. '17': function (n) {
  12831. if (n == 3) return 'few';
  12832. if (n === 0) return 'zero';
  12833. if (n == 6) return 'many';
  12834. if (n == 2) return 'two';
  12835. if (n == 1) return 'one';
  12836. return 'other';
  12837. },
  12838. '18': function (n) {
  12839. if (n === 0) return 'zero';
  12840. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12841. return 'other';
  12842. },
  12843. '19': function (n) {
  12844. if (isBetween(n, 2, 10)) return 'few';
  12845. if (isBetween(n, 0, 1)) return 'one';
  12846. return 'other';
  12847. },
  12848. '20': function (n) {
  12849. 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';
  12850. if (n % 1000000 === 0 && n !== 0) return 'many';
  12851. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12852. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12853. return 'other';
  12854. },
  12855. '21': function (n) {
  12856. if (n === 0) return 'zero';
  12857. if (n == 1) return 'one';
  12858. return 'other';
  12859. },
  12860. '22': function (n) {
  12861. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  12862. return 'other';
  12863. },
  12864. '23': function (n) {
  12865. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  12866. return 'other';
  12867. },
  12868. '24': function (n) {
  12869. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  12870. if (isIn(n, [2, 12])) return 'two';
  12871. if (isIn(n, [1, 11])) return 'one';
  12872. return 'other';
  12873. }
  12874. };
  12875. var index = locales2rules[lang.replace(/-.*$/, '')];
  12876. if (!(index in pluralRules)) {
  12877. console.warn('plural form unknown for [' + lang + ']');
  12878. return function () {
  12879. return 'other';
  12880. };
  12881. }
  12882. return pluralRules[index];
  12883. }
  12884. gMacros.plural = function (str, param, key, prop) {
  12885. var n = parseFloat(param);
  12886. if (isNaN(n)) return str;
  12887. if (prop != gTextProp) return str;
  12888. if (!gMacros._pluralRules) {
  12889. gMacros._pluralRules = getPluralRules(gLanguage);
  12890. }
  12891. var index = '[' + gMacros._pluralRules(n) + ']';
  12892. if (n === 0 && key + '[zero]' in gL10nData) {
  12893. str = gL10nData[key + '[zero]'][prop];
  12894. } else if (n == 1 && key + '[one]' in gL10nData) {
  12895. str = gL10nData[key + '[one]'][prop];
  12896. } else if (n == 2 && key + '[two]' in gL10nData) {
  12897. str = gL10nData[key + '[two]'][prop];
  12898. } else if (key + index in gL10nData) {
  12899. str = gL10nData[key + index][prop];
  12900. } else if (key + '[other]' in gL10nData) {
  12901. str = gL10nData[key + '[other]'][prop];
  12902. }
  12903. return str;
  12904. };
  12905. function getL10nData(key, args, fallback) {
  12906. var data = gL10nData[key];
  12907. if (!data) {
  12908. console.warn('#' + key + ' is undefined.');
  12909. if (!fallback) {
  12910. return null;
  12911. }
  12912. data = fallback;
  12913. }
  12914. var rv = {};
  12915. for (var prop in data) {
  12916. var str = data[prop];
  12917. str = substIndexes(str, args, key, prop);
  12918. str = substArguments(str, args, key);
  12919. rv[prop] = str;
  12920. }
  12921. return rv;
  12922. }
  12923. function substIndexes(str, args, key, prop) {
  12924. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  12925. var reMatch = reIndex.exec(str);
  12926. if (!reMatch || !reMatch.length) return str;
  12927. var macroName = reMatch[1];
  12928. var paramName = reMatch[2];
  12929. var param;
  12930. if (args && paramName in args) {
  12931. param = args[paramName];
  12932. } else if (paramName in gL10nData) {
  12933. param = gL10nData[paramName];
  12934. }
  12935. if (macroName in gMacros) {
  12936. var macro = gMacros[macroName];
  12937. str = macro(str, param, key, prop);
  12938. }
  12939. return str;
  12940. }
  12941. function substArguments(str, args, key) {
  12942. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  12943. return str.replace(reArgs, function (matched_text, arg) {
  12944. if (args && arg in args) {
  12945. return args[arg];
  12946. }
  12947. if (arg in gL10nData) {
  12948. return gL10nData[arg];
  12949. }
  12950. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  12951. return matched_text;
  12952. });
  12953. }
  12954. function translateElement(element) {
  12955. var l10n = getL10nAttributes(element);
  12956. if (!l10n.id) return;
  12957. var data = getL10nData(l10n.id, l10n.args);
  12958. if (!data) {
  12959. console.warn('#' + l10n.id + ' is undefined.');
  12960. return;
  12961. }
  12962. if (data[gTextProp]) {
  12963. if (getChildElementCount(element) === 0) {
  12964. element[gTextProp] = data[gTextProp];
  12965. } else {
  12966. var children = element.childNodes;
  12967. var found = false;
  12968. for (var i = 0, l = children.length; i < l; i++) {
  12969. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  12970. if (found) {
  12971. children[i].nodeValue = '';
  12972. } else {
  12973. children[i].nodeValue = data[gTextProp];
  12974. found = true;
  12975. }
  12976. }
  12977. }
  12978. if (!found) {
  12979. var textNode = document.createTextNode(data[gTextProp]);
  12980. element.prepend(textNode);
  12981. }
  12982. }
  12983. delete data[gTextProp];
  12984. }
  12985. for (var k in data) {
  12986. element[k] = data[k];
  12987. }
  12988. }
  12989. function getChildElementCount(element) {
  12990. if (element.children) {
  12991. return element.children.length;
  12992. }
  12993. if (typeof element.childElementCount !== 'undefined') {
  12994. return element.childElementCount;
  12995. }
  12996. var count = 0;
  12997. for (var i = 0; i < element.childNodes.length; i++) {
  12998. count += element.nodeType === 1 ? 1 : 0;
  12999. }
  13000. return count;
  13001. }
  13002. function translateFragment(element) {
  13003. element = element || document.documentElement;
  13004. var children = getTranslatableChildren(element);
  13005. var elementCount = children.length;
  13006. for (var i = 0; i < elementCount; i++) {
  13007. translateElement(children[i]);
  13008. }
  13009. translateElement(element);
  13010. }
  13011. return {
  13012. get: function (key, args, fallbackString) {
  13013. var index = key.lastIndexOf('.');
  13014. var prop = gTextProp;
  13015. if (index > 0) {
  13016. prop = key.substring(index + 1);
  13017. key = key.substring(0, index);
  13018. }
  13019. var fallback;
  13020. if (fallbackString) {
  13021. fallback = {};
  13022. fallback[prop] = fallbackString;
  13023. }
  13024. var data = getL10nData(key, args, fallback);
  13025. if (data && prop in data) {
  13026. return data[prop];
  13027. }
  13028. return '{{' + key + '}}';
  13029. },
  13030. getData: function () {
  13031. return gL10nData;
  13032. },
  13033. getText: function () {
  13034. return gTextData;
  13035. },
  13036. getLanguage: function () {
  13037. return gLanguage;
  13038. },
  13039. setLanguage: function (lang, callback) {
  13040. loadLocale(lang, function () {
  13041. if (callback) callback();
  13042. });
  13043. },
  13044. getDirection: function () {
  13045. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  13046. var shortCode = gLanguage.split('-', 1)[0];
  13047. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  13048. },
  13049. translate: translateFragment,
  13050. getReadyState: function () {
  13051. return gReadyState;
  13052. },
  13053. ready: function (callback) {
  13054. if (!callback) {
  13055. return;
  13056. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  13057. window.setTimeout(function () {
  13058. callback();
  13059. });
  13060. } else if (document.addEventListener) {
  13061. document.addEventListener('localized', function once() {
  13062. document.removeEventListener('localized', once);
  13063. callback();
  13064. });
  13065. }
  13066. }
  13067. };
  13068. }(window, document);
  13069. /***/ }),
  13070. /* 45 */
  13071. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13072. Object.defineProperty(exports, "__esModule", ({
  13073. value: true
  13074. }));
  13075. exports.GenericScripting = void 0;
  13076. exports.docProperties = docProperties;
  13077. var _pdfjsLib = __webpack_require__(4);
  13078. async function docProperties(pdfDocument) {
  13079. const url = "",
  13080. baseUrl = url.split("#")[0];
  13081. let {
  13082. info,
  13083. metadata,
  13084. contentDispositionFilename,
  13085. contentLength
  13086. } = await pdfDocument.getMetadata();
  13087. if (!contentLength) {
  13088. const {
  13089. length
  13090. } = await pdfDocument.getDownloadInfo();
  13091. contentLength = length;
  13092. }
  13093. return {
  13094. ...info,
  13095. baseURL: baseUrl,
  13096. filesize: contentLength,
  13097. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  13098. metadata: metadata?.getRaw(),
  13099. authors: metadata?.get("dc:creator"),
  13100. numPages: pdfDocument.numPages,
  13101. URL: url
  13102. };
  13103. }
  13104. class GenericScripting {
  13105. constructor(sandboxBundleSrc) {
  13106. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  13107. return window.pdfjsSandbox.QuickJSSandbox();
  13108. });
  13109. }
  13110. async createSandbox(data) {
  13111. const sandbox = await this._ready;
  13112. sandbox.create(data);
  13113. }
  13114. async dispatchEventInSandbox(event) {
  13115. const sandbox = await this._ready;
  13116. setTimeout(() => sandbox.dispatchEvent(event), 0);
  13117. }
  13118. async destroySandbox() {
  13119. const sandbox = await this._ready;
  13120. sandbox.nukeSandbox();
  13121. }
  13122. }
  13123. exports.GenericScripting = GenericScripting;
  13124. /***/ }),
  13125. /* 46 */
  13126. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13127. Object.defineProperty(exports, "__esModule", ({
  13128. value: true
  13129. }));
  13130. exports.PDFPrintService = void 0;
  13131. var _pdfjsLib = __webpack_require__(4);
  13132. var _app = __webpack_require__(2);
  13133. var _print_utils = __webpack_require__(47);
  13134. let activeService = null;
  13135. let dialog = null;
  13136. let overlayManager = null;
  13137. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  13138. const scratchCanvas = activeService.scratchCanvas;
  13139. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  13140. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  13141. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  13142. const ctx = scratchCanvas.getContext("2d");
  13143. ctx.save();
  13144. ctx.fillStyle = "rgb(255, 255, 255)";
  13145. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  13146. ctx.restore();
  13147. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  13148. const renderContext = {
  13149. canvasContext: ctx,
  13150. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  13151. viewport: pdfPage.getViewport({
  13152. scale: 1,
  13153. rotation: size.rotation
  13154. }),
  13155. intent: "print",
  13156. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  13157. optionalContentConfigPromise,
  13158. printAnnotationStorage
  13159. };
  13160. return pdfPage.render(renderContext).promise;
  13161. });
  13162. }
  13163. class PDFPrintService {
  13164. constructor(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) {
  13165. this.pdfDocument = pdfDocument;
  13166. this.pagesOverview = pagesOverview;
  13167. this.printContainer = printContainer;
  13168. this._printResolution = printResolution || 150;
  13169. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  13170. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  13171. this.l10n = l10n;
  13172. this.currentPage = -1;
  13173. this.scratchCanvas = document.createElement("canvas");
  13174. }
  13175. layout() {
  13176. this.throwIfInactive();
  13177. const body = document.querySelector("body");
  13178. body.setAttribute("data-pdfjsprinting", true);
  13179. const {
  13180. width,
  13181. height
  13182. } = this.pagesOverview[0];
  13183. const hasEqualPageSizes = this.pagesOverview.every(size => size.width === width && size.height === height);
  13184. if (!hasEqualPageSizes) {
  13185. console.warn("Not all pages have the same size. The printed result may be incorrect!");
  13186. }
  13187. this.pageStyleSheet = document.createElement("style");
  13188. this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`;
  13189. body.append(this.pageStyleSheet);
  13190. }
  13191. destroy() {
  13192. if (activeService !== this) {
  13193. return;
  13194. }
  13195. this.printContainer.textContent = "";
  13196. const body = document.querySelector("body");
  13197. body.removeAttribute("data-pdfjsprinting");
  13198. if (this.pageStyleSheet) {
  13199. this.pageStyleSheet.remove();
  13200. this.pageStyleSheet = null;
  13201. }
  13202. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  13203. this.scratchCanvas = null;
  13204. activeService = null;
  13205. ensureOverlay().then(function () {
  13206. if (overlayManager.active === dialog) {
  13207. overlayManager.close(dialog);
  13208. }
  13209. });
  13210. }
  13211. renderPages() {
  13212. if (this.pdfDocument.isPureXfa) {
  13213. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  13214. return Promise.resolve();
  13215. }
  13216. const pageCount = this.pagesOverview.length;
  13217. const renderNextPage = (resolve, reject) => {
  13218. this.throwIfInactive();
  13219. if (++this.currentPage >= pageCount) {
  13220. renderProgress(pageCount, pageCount, this.l10n);
  13221. resolve();
  13222. return;
  13223. }
  13224. const index = this.currentPage;
  13225. renderProgress(index, pageCount, this.l10n);
  13226. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  13227. renderNextPage(resolve, reject);
  13228. }, reject);
  13229. };
  13230. return new Promise(renderNextPage);
  13231. }
  13232. useRenderedPage() {
  13233. this.throwIfInactive();
  13234. const img = document.createElement("img");
  13235. const scratchCanvas = this.scratchCanvas;
  13236. if ("toBlob" in scratchCanvas) {
  13237. scratchCanvas.toBlob(function (blob) {
  13238. img.src = URL.createObjectURL(blob);
  13239. });
  13240. } else {
  13241. img.src = scratchCanvas.toDataURL();
  13242. }
  13243. const wrapper = document.createElement("div");
  13244. wrapper.className = "printedPage";
  13245. wrapper.append(img);
  13246. this.printContainer.append(wrapper);
  13247. return new Promise(function (resolve, reject) {
  13248. img.onload = resolve;
  13249. img.onerror = reject;
  13250. });
  13251. }
  13252. performPrint() {
  13253. this.throwIfInactive();
  13254. return new Promise(resolve => {
  13255. setTimeout(() => {
  13256. if (!this.active) {
  13257. resolve();
  13258. return;
  13259. }
  13260. print.call(window);
  13261. setTimeout(resolve, 20);
  13262. }, 0);
  13263. });
  13264. }
  13265. get active() {
  13266. return this === activeService;
  13267. }
  13268. throwIfInactive() {
  13269. if (!this.active) {
  13270. throw new Error("This print request was cancelled or completed.");
  13271. }
  13272. }
  13273. }
  13274. exports.PDFPrintService = PDFPrintService;
  13275. const print = window.print;
  13276. window.print = function () {
  13277. if (activeService) {
  13278. console.warn("Ignored window.print() because of a pending print job.");
  13279. return;
  13280. }
  13281. ensureOverlay().then(function () {
  13282. if (activeService) {
  13283. overlayManager.open(dialog);
  13284. }
  13285. });
  13286. try {
  13287. dispatchEvent("beforeprint");
  13288. } finally {
  13289. if (!activeService) {
  13290. console.error("Expected print service to be initialized.");
  13291. ensureOverlay().then(function () {
  13292. if (overlayManager.active === dialog) {
  13293. overlayManager.close(dialog);
  13294. }
  13295. });
  13296. return;
  13297. }
  13298. const activeServiceOnEntry = activeService;
  13299. activeService.renderPages().then(function () {
  13300. return activeServiceOnEntry.performPrint();
  13301. }).catch(function () {}).then(function () {
  13302. if (activeServiceOnEntry.active) {
  13303. abort();
  13304. }
  13305. });
  13306. }
  13307. };
  13308. function dispatchEvent(eventType) {
  13309. const event = new CustomEvent(eventType, {
  13310. bubbles: false,
  13311. cancelable: false,
  13312. detail: "custom"
  13313. });
  13314. window.dispatchEvent(event);
  13315. }
  13316. function abort() {
  13317. if (activeService) {
  13318. activeService.destroy();
  13319. dispatchEvent("afterprint");
  13320. }
  13321. }
  13322. function renderProgress(index, total, l10n) {
  13323. dialog ||= document.getElementById("printServiceDialog");
  13324. const progress = Math.round(100 * index / total);
  13325. const progressBar = dialog.querySelector("progress");
  13326. const progressPerc = dialog.querySelector(".relative-progress");
  13327. progressBar.value = progress;
  13328. l10n.get("print_progress_percent", {
  13329. progress
  13330. }).then(msg => {
  13331. progressPerc.textContent = msg;
  13332. });
  13333. }
  13334. window.addEventListener("keydown", function (event) {
  13335. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  13336. window.print();
  13337. event.preventDefault();
  13338. event.stopImmediatePropagation();
  13339. }
  13340. }, true);
  13341. if ("onbeforeprint" in window) {
  13342. const stopPropagationIfNeeded = function (event) {
  13343. if (event.detail !== "custom") {
  13344. event.stopImmediatePropagation();
  13345. }
  13346. };
  13347. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  13348. window.addEventListener("afterprint", stopPropagationIfNeeded);
  13349. }
  13350. let overlayPromise;
  13351. function ensureOverlay() {
  13352. if (!overlayPromise) {
  13353. overlayManager = _app.PDFViewerApplication.overlayManager;
  13354. if (!overlayManager) {
  13355. throw new Error("The overlay manager has not yet been initialized.");
  13356. }
  13357. dialog ||= document.getElementById("printServiceDialog");
  13358. overlayPromise = overlayManager.register(dialog, true);
  13359. document.getElementById("printCancel").onclick = abort;
  13360. dialog.addEventListener("close", abort);
  13361. }
  13362. return overlayPromise;
  13363. }
  13364. _app.PDFPrintServiceFactory.instance = {
  13365. supportsPrinting: true,
  13366. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  13367. if (activeService) {
  13368. throw new Error("The print service is created and active.");
  13369. }
  13370. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  13371. return activeService;
  13372. }
  13373. };
  13374. /***/ }),
  13375. /* 47 */
  13376. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13377. Object.defineProperty(exports, "__esModule", ({
  13378. value: true
  13379. }));
  13380. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  13381. var _pdfjsLib = __webpack_require__(4);
  13382. var _pdf_link_service = __webpack_require__(7);
  13383. var _xfa_layer_builder = __webpack_require__(37);
  13384. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  13385. const xfaHtml = pdfDocument.allXfaHtml;
  13386. const linkService = new _pdf_link_service.SimpleLinkService();
  13387. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  13388. for (const xfaPage of xfaHtml.children) {
  13389. const page = document.createElement("div");
  13390. page.className = "xfaPrintedPage";
  13391. printContainer.append(page);
  13392. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  13393. pageDiv: page,
  13394. pdfPage: null,
  13395. annotationStorage: pdfDocument.annotationStorage,
  13396. linkService,
  13397. xfaHtml: xfaPage
  13398. });
  13399. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  13400. scale
  13401. });
  13402. builder.render(viewport, "print");
  13403. }
  13404. }
  13405. /***/ })
  13406. /******/ ]);
  13407. /************************************************************************/
  13408. /******/ // The module cache
  13409. /******/ var __webpack_module_cache__ = {};
  13410. /******/
  13411. /******/ // The require function
  13412. /******/ function __webpack_require__(moduleId) {
  13413. /******/ // Check if module is in cache
  13414. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  13415. /******/ if (cachedModule !== undefined) {
  13416. /******/ return cachedModule.exports;
  13417. /******/ }
  13418. /******/ // Create a new module (and put it into the cache)
  13419. /******/ var module = __webpack_module_cache__[moduleId] = {
  13420. /******/ // no module.id needed
  13421. /******/ // no module.loaded needed
  13422. /******/ exports: {}
  13423. /******/ };
  13424. /******/
  13425. /******/ // Execute the module function
  13426. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  13427. /******/
  13428. /******/ // Return the exports of the module
  13429. /******/ return module.exports;
  13430. /******/ }
  13431. /******/
  13432. /************************************************************************/
  13433. var __webpack_exports__ = {};
  13434. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  13435. (() => {
  13436. var exports = __webpack_exports__;
  13437. Object.defineProperty(exports, "__esModule", ({
  13438. value: true
  13439. }));
  13440. Object.defineProperty(exports, "PDFViewerApplication", ({
  13441. enumerable: true,
  13442. get: function () {
  13443. return _app.PDFViewerApplication;
  13444. }
  13445. }));
  13446. exports.PDFViewerApplicationConstants = void 0;
  13447. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  13448. enumerable: true,
  13449. get: function () {
  13450. return _app_options.AppOptions;
  13451. }
  13452. }));
  13453. __webpack_require__(1);
  13454. __webpack_require__(46);
  13455. var _ui_utils = __webpack_require__(3);
  13456. var _app_options = __webpack_require__(5);
  13457. var _pdf_link_service = __webpack_require__(7);
  13458. var _app = __webpack_require__(2);
  13459. const pdfjsVersion = '3.10.111';
  13460. const pdfjsBuild = 'e142baecb';
  13461. const AppConstants = {
  13462. LinkTarget: _pdf_link_service.LinkTarget,
  13463. RenderingStates: _ui_utils.RenderingStates,
  13464. ScrollMode: _ui_utils.ScrollMode,
  13465. SpreadMode: _ui_utils.SpreadMode
  13466. };
  13467. exports.PDFViewerApplicationConstants = AppConstants;
  13468. window.PDFViewerApplication = _app.PDFViewerApplication;
  13469. window.PDFViewerApplicationConstants = AppConstants;
  13470. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  13471. function getViewerConfiguration() {
  13472. return {
  13473. appContainer: document.body,
  13474. mainContainer: document.getElementById("viewerContainer"),
  13475. viewerContainer: document.getElementById("viewer"),
  13476. toolbar: {
  13477. container: document.getElementById("toolbarViewer"),
  13478. numPages: document.getElementById("numPages"),
  13479. pageNumber: document.getElementById("pageNumber"),
  13480. scaleSelect: document.getElementById("scaleSelect"),
  13481. customScaleOption: document.getElementById("customScaleOption"),
  13482. previous: document.getElementById("previous"),
  13483. next: document.getElementById("next"),
  13484. zoomIn: document.getElementById("zoomIn"),
  13485. zoomOut: document.getElementById("zoomOut"),
  13486. viewFind: document.getElementById("viewFind"),
  13487. openFile: document.getElementById("openFile"),
  13488. print: document.getElementById("print"),
  13489. editorFreeTextButton: document.getElementById("editorFreeText"),
  13490. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  13491. editorInkButton: document.getElementById("editorInk"),
  13492. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  13493. editorStampButton: document.getElementById("editorStamp"),
  13494. editorStampParamsToolbar: document.getElementById("editorStampParamsToolbar"),
  13495. download: document.getElementById("download")
  13496. },
  13497. secondaryToolbar: {
  13498. toolbar: document.getElementById("secondaryToolbar"),
  13499. toggleButton: document.getElementById("secondaryToolbarToggle"),
  13500. presentationModeButton: document.getElementById("presentationMode"),
  13501. openFileButton: document.getElementById("secondaryOpenFile"),
  13502. printButton: document.getElementById("secondaryPrint"),
  13503. downloadButton: document.getElementById("secondaryDownload"),
  13504. viewBookmarkButton: document.getElementById("viewBookmark"),
  13505. firstPageButton: document.getElementById("firstPage"),
  13506. lastPageButton: document.getElementById("lastPage"),
  13507. pageRotateCwButton: document.getElementById("pageRotateCw"),
  13508. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  13509. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  13510. cursorHandToolButton: document.getElementById("cursorHandTool"),
  13511. scrollPageButton: document.getElementById("scrollPage"),
  13512. scrollVerticalButton: document.getElementById("scrollVertical"),
  13513. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  13514. scrollWrappedButton: document.getElementById("scrollWrapped"),
  13515. spreadNoneButton: document.getElementById("spreadNone"),
  13516. spreadOddButton: document.getElementById("spreadOdd"),
  13517. spreadEvenButton: document.getElementById("spreadEven"),
  13518. documentPropertiesButton: document.getElementById("documentProperties")
  13519. },
  13520. sidebar: {
  13521. outerContainer: document.getElementById("outerContainer"),
  13522. sidebarContainer: document.getElementById("sidebarContainer"),
  13523. toggleButton: document.getElementById("sidebarToggle"),
  13524. resizer: document.getElementById("sidebarResizer"),
  13525. thumbnailButton: document.getElementById("viewThumbnail"),
  13526. outlineButton: document.getElementById("viewOutline"),
  13527. attachmentsButton: document.getElementById("viewAttachments"),
  13528. layersButton: document.getElementById("viewLayers"),
  13529. thumbnailView: document.getElementById("thumbnailView"),
  13530. outlineView: document.getElementById("outlineView"),
  13531. attachmentsView: document.getElementById("attachmentsView"),
  13532. layersView: document.getElementById("layersView"),
  13533. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  13534. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  13535. },
  13536. findBar: {
  13537. bar: document.getElementById("findbar"),
  13538. toggleButton: document.getElementById("viewFind"),
  13539. findField: document.getElementById("findInput"),
  13540. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  13541. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  13542. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  13543. entireWordCheckbox: document.getElementById("findEntireWord"),
  13544. findMsg: document.getElementById("findMsg"),
  13545. findResultsCount: document.getElementById("findResultsCount"),
  13546. findPreviousButton: document.getElementById("findPrevious"),
  13547. findNextButton: document.getElementById("findNext")
  13548. },
  13549. passwordOverlay: {
  13550. dialog: document.getElementById("passwordDialog"),
  13551. label: document.getElementById("passwordText"),
  13552. input: document.getElementById("password"),
  13553. submitButton: document.getElementById("passwordSubmit"),
  13554. cancelButton: document.getElementById("passwordCancel")
  13555. },
  13556. documentProperties: {
  13557. dialog: document.getElementById("documentPropertiesDialog"),
  13558. closeButton: document.getElementById("documentPropertiesClose"),
  13559. fields: {
  13560. fileName: document.getElementById("fileNameField"),
  13561. fileSize: document.getElementById("fileSizeField"),
  13562. title: document.getElementById("titleField"),
  13563. author: document.getElementById("authorField"),
  13564. subject: document.getElementById("subjectField"),
  13565. keywords: document.getElementById("keywordsField"),
  13566. creationDate: document.getElementById("creationDateField"),
  13567. modificationDate: document.getElementById("modificationDateField"),
  13568. creator: document.getElementById("creatorField"),
  13569. producer: document.getElementById("producerField"),
  13570. version: document.getElementById("versionField"),
  13571. pageCount: document.getElementById("pageCountField"),
  13572. pageSize: document.getElementById("pageSizeField"),
  13573. linearized: document.getElementById("linearizedField")
  13574. }
  13575. },
  13576. annotationEditorParams: {
  13577. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  13578. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  13579. editorInkColor: document.getElementById("editorInkColor"),
  13580. editorInkThickness: document.getElementById("editorInkThickness"),
  13581. editorInkOpacity: document.getElementById("editorInkOpacity"),
  13582. editorStampAddImage: document.getElementById("editorStampAddImage")
  13583. },
  13584. printContainer: document.getElementById("printContainer"),
  13585. openFileInput: document.getElementById("fileInput"),
  13586. debuggerScriptPath: "./debugger.js"
  13587. };
  13588. }
  13589. function webViewerLoad() {
  13590. const config = getViewerConfiguration();
  13591. const event = new CustomEvent("webviewerloaded", {
  13592. bubbles: true,
  13593. cancelable: true,
  13594. detail: {
  13595. source: window
  13596. }
  13597. });
  13598. try {
  13599. parent.document.dispatchEvent(event);
  13600. } catch (ex) {
  13601. console.error(`webviewerloaded: ${ex}`);
  13602. document.dispatchEvent(event);
  13603. }
  13604. _app.PDFViewerApplication.run(config);
  13605. }
  13606. document.blockUnblockOnload?.(true);
  13607. if (document.readyState === "interactive" || document.readyState === "complete") {
  13608. webViewerLoad();
  13609. } else {
  13610. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  13611. }
  13612. })();
  13613. /******/ })()
  13614. ;
  13615. //# sourceMappingURL=viewer.js.map