2
0

pdf_viewer.js 189 KB

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