2
0

pdf_viewer.js 187 KB

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