viewer.js 509 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = void 0;
  32. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  33. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  34. exports.approximateFraction = approximateFraction;
  35. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  36. exports.binarySearchFirstItem = binarySearchFirstItem;
  37. exports.docStyle = void 0;
  38. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  39. exports.getPageSizeInches = getPageSizeInches;
  40. exports.getVisibleElements = getVisibleElements;
  41. exports.isPortraitOrientation = isPortraitOrientation;
  42. exports.isValidRotation = isValidRotation;
  43. exports.isValidScrollMode = isValidScrollMode;
  44. exports.isValidSpreadMode = isValidSpreadMode;
  45. exports.noContextMenuHandler = noContextMenuHandler;
  46. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  47. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  48. exports.parseQueryString = parseQueryString;
  49. exports.removeNullCharacters = removeNullCharacters;
  50. exports.roundToDivide = roundToDivide;
  51. exports.scrollIntoView = scrollIntoView;
  52. exports.watchScroll = watchScroll;
  53. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  54. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  55. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  56. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  57. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  58. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  59. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  60. const DEFAULT_SCALE_VALUE = "auto";
  61. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  62. const DEFAULT_SCALE = 1.0;
  63. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  64. const DEFAULT_SCALE_DELTA = 1.1;
  65. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  66. const MIN_SCALE = 0.1;
  67. exports.MIN_SCALE = MIN_SCALE;
  68. const MAX_SCALE = 10.0;
  69. exports.MAX_SCALE = MAX_SCALE;
  70. const UNKNOWN_SCALE = 0;
  71. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  72. const MAX_AUTO_SCALE = 1.25;
  73. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  74. const SCROLLBAR_PADDING = 40;
  75. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  76. const VERTICAL_PADDING = 5;
  77. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  78. const RenderingStates = {
  79. INITIAL: 0,
  80. RUNNING: 1,
  81. PAUSED: 2,
  82. FINISHED: 3
  83. };
  84. exports.RenderingStates = RenderingStates;
  85. const PresentationModeState = {
  86. UNKNOWN: 0,
  87. NORMAL: 1,
  88. CHANGING: 2,
  89. FULLSCREEN: 3
  90. };
  91. exports.PresentationModeState = PresentationModeState;
  92. const SidebarView = {
  93. UNKNOWN: -1,
  94. NONE: 0,
  95. THUMBS: 1,
  96. OUTLINE: 2,
  97. ATTACHMENTS: 3,
  98. LAYERS: 4
  99. };
  100. exports.SidebarView = SidebarView;
  101. const RendererType = {
  102. CANVAS: "canvas",
  103. SVG: "svg"
  104. };
  105. exports.RendererType = RendererType;
  106. const TextLayerMode = {
  107. DISABLE: 0,
  108. ENABLE: 1
  109. };
  110. exports.TextLayerMode = TextLayerMode;
  111. const ScrollMode = {
  112. UNKNOWN: -1,
  113. VERTICAL: 0,
  114. HORIZONTAL: 1,
  115. WRAPPED: 2,
  116. PAGE: 3
  117. };
  118. exports.ScrollMode = ScrollMode;
  119. const SpreadMode = {
  120. UNKNOWN: -1,
  121. NONE: 0,
  122. ODD: 1,
  123. EVEN: 2
  124. };
  125. exports.SpreadMode = SpreadMode;
  126. const AutoPrintRegExp = /\bprint\s*\(/;
  127. exports.AutoPrintRegExp = AutoPrintRegExp;
  128. class OutputScale {
  129. constructor() {
  130. const pixelRatio = window.devicePixelRatio || 1;
  131. this.sx = pixelRatio;
  132. this.sy = pixelRatio;
  133. }
  134. get scaled() {
  135. return this.sx !== 1 || this.sy !== 1;
  136. }
  137. }
  138. exports.OutputScale = OutputScale;
  139. function scrollIntoView(element, spot) {
  140. let scrollMatches = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  141. let parent = element.offsetParent;
  142. if (!parent) {
  143. console.error("offsetParent is not set -- cannot scroll");
  144. return;
  145. }
  146. let offsetY = element.offsetTop + element.clientTop;
  147. let offsetX = element.offsetLeft + element.clientLeft;
  148. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  149. offsetY += parent.offsetTop;
  150. offsetX += parent.offsetLeft;
  151. parent = parent.offsetParent;
  152. if (!parent) {
  153. return;
  154. }
  155. }
  156. if (spot) {
  157. if (spot.top !== undefined) {
  158. offsetY += spot.top;
  159. }
  160. if (spot.left !== undefined) {
  161. offsetX += spot.left;
  162. parent.scrollLeft = offsetX;
  163. }
  164. }
  165. parent.scrollTop = offsetY;
  166. }
  167. function watchScroll(viewAreaElement, callback) {
  168. const debounceScroll = function (evt) {
  169. if (rAF) {
  170. return;
  171. }
  172. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  173. rAF = null;
  174. const currentX = viewAreaElement.scrollLeft;
  175. const lastX = state.lastX;
  176. if (currentX !== lastX) {
  177. state.right = currentX > lastX;
  178. }
  179. state.lastX = currentX;
  180. const currentY = viewAreaElement.scrollTop;
  181. const lastY = state.lastY;
  182. if (currentY !== lastY) {
  183. state.down = currentY > lastY;
  184. }
  185. state.lastY = currentY;
  186. callback(state);
  187. });
  188. };
  189. const state = {
  190. right: true,
  191. down: true,
  192. lastX: viewAreaElement.scrollLeft,
  193. lastY: viewAreaElement.scrollTop,
  194. _eventHandler: debounceScroll
  195. };
  196. let rAF = null;
  197. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  198. return state;
  199. }
  200. function parseQueryString(query) {
  201. const params = new Map();
  202. for (const [key, value] of new URLSearchParams(query)) {
  203. params.set(key.toLowerCase(), value);
  204. }
  205. return params;
  206. }
  207. const NullCharactersRegExp = /\x00/g;
  208. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  209. function removeNullCharacters(str) {
  210. let replaceInvisible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  211. if (typeof str !== "string") {
  212. console.error(`The argument must be a string.`);
  213. return str;
  214. }
  215. if (replaceInvisible) {
  216. str = str.replace(InvisibleCharactersRegExp, " ");
  217. }
  218. return str.replace(NullCharactersRegExp, "");
  219. }
  220. function binarySearchFirstItem(items, condition) {
  221. let start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  222. let minIndex = start;
  223. let maxIndex = items.length - 1;
  224. if (maxIndex < 0 || !condition(items[maxIndex])) {
  225. return items.length;
  226. }
  227. if (condition(items[minIndex])) {
  228. return minIndex;
  229. }
  230. while (minIndex < maxIndex) {
  231. const currentIndex = minIndex + maxIndex >> 1;
  232. const currentItem = items[currentIndex];
  233. if (condition(currentItem)) {
  234. maxIndex = currentIndex;
  235. } else {
  236. minIndex = currentIndex + 1;
  237. }
  238. }
  239. return minIndex;
  240. }
  241. function approximateFraction(x) {
  242. if (Math.floor(x) === x) {
  243. return [x, 1];
  244. }
  245. const xinv = 1 / x;
  246. const limit = 8;
  247. if (xinv > limit) {
  248. return [1, limit];
  249. } else if (Math.floor(xinv) === xinv) {
  250. return [1, xinv];
  251. }
  252. const x_ = x > 1 ? xinv : x;
  253. let a = 0,
  254. b = 1,
  255. c = 1,
  256. d = 1;
  257. while (true) {
  258. const p = a + c,
  259. q = b + d;
  260. if (q > limit) {
  261. break;
  262. }
  263. if (x_ <= p / q) {
  264. c = p;
  265. d = q;
  266. } else {
  267. a = p;
  268. b = q;
  269. }
  270. }
  271. let result;
  272. if (x_ - a / b < c / d - x_) {
  273. result = x_ === x ? [a, b] : [b, a];
  274. } else {
  275. result = x_ === x ? [c, d] : [d, c];
  276. }
  277. return result;
  278. }
  279. function roundToDivide(x, div) {
  280. const r = x % div;
  281. return r === 0 ? x : Math.round(x - r + div);
  282. }
  283. function getPageSizeInches(_ref) {
  284. let {
  285. view,
  286. userUnit,
  287. rotate
  288. } = _ref;
  289. const [x1, y1, x2, y2] = view;
  290. const changeOrientation = rotate % 180 !== 0;
  291. const width = (x2 - x1) / 72 * userUnit;
  292. const height = (y2 - y1) / 72 * userUnit;
  293. return {
  294. width: changeOrientation ? height : width,
  295. height: changeOrientation ? width : height
  296. };
  297. }
  298. function backtrackBeforeAllVisibleElements(index, views, top) {
  299. if (index < 2) {
  300. return index;
  301. }
  302. let elt = views[index].div;
  303. let pageTop = elt.offsetTop + elt.clientTop;
  304. if (pageTop >= top) {
  305. elt = views[index - 1].div;
  306. pageTop = elt.offsetTop + elt.clientTop;
  307. }
  308. for (let i = index - 2; i >= 0; --i) {
  309. elt = views[i].div;
  310. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  311. break;
  312. }
  313. index = i;
  314. }
  315. return index;
  316. }
  317. function getVisibleElements(_ref2) {
  318. let {
  319. scrollEl,
  320. views,
  321. sortByVisibility = false,
  322. horizontal = false,
  323. rtl = false
  324. } = _ref2;
  325. const top = scrollEl.scrollTop,
  326. bottom = top + scrollEl.clientHeight;
  327. const left = scrollEl.scrollLeft,
  328. right = left + scrollEl.clientWidth;
  329. function isElementBottomAfterViewTop(view) {
  330. const element = view.div;
  331. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  332. return elementBottom > top;
  333. }
  334. function isElementNextAfterViewHorizontally(view) {
  335. const element = view.div;
  336. const elementLeft = element.offsetLeft + element.clientLeft;
  337. const elementRight = elementLeft + element.clientWidth;
  338. return rtl ? elementLeft < right : elementRight > left;
  339. }
  340. const visible = [],
  341. ids = new Set(),
  342. numViews = views.length;
  343. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  344. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  345. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  346. }
  347. let lastEdge = horizontal ? right : -1;
  348. for (let i = firstVisibleElementInd; i < numViews; i++) {
  349. const view = views[i],
  350. element = view.div;
  351. const currentWidth = element.offsetLeft + element.clientLeft;
  352. const currentHeight = element.offsetTop + element.clientTop;
  353. const viewWidth = element.clientWidth,
  354. viewHeight = element.clientHeight;
  355. const viewRight = currentWidth + viewWidth;
  356. const viewBottom = currentHeight + viewHeight;
  357. if (lastEdge === -1) {
  358. if (viewBottom >= bottom) {
  359. lastEdge = viewBottom;
  360. }
  361. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  362. break;
  363. }
  364. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  365. continue;
  366. }
  367. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  368. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  369. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  370. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  371. const percent = fractionHeight * fractionWidth * 100 | 0;
  372. visible.push({
  373. id: view.id,
  374. x: currentWidth,
  375. y: currentHeight,
  376. view,
  377. percent,
  378. widthPercent: fractionWidth * 100 | 0
  379. });
  380. ids.add(view.id);
  381. }
  382. const first = visible[0],
  383. last = visible.at(-1);
  384. if (sortByVisibility) {
  385. visible.sort(function (a, b) {
  386. const pc = a.percent - b.percent;
  387. if (Math.abs(pc) > 0.001) {
  388. return -pc;
  389. }
  390. return a.id - b.id;
  391. });
  392. }
  393. return {
  394. first,
  395. last,
  396. views: visible,
  397. ids
  398. };
  399. }
  400. function noContextMenuHandler(evt) {
  401. evt.preventDefault();
  402. }
  403. function normalizeWheelEventDirection(evt) {
  404. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  405. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  406. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  407. delta = -delta;
  408. }
  409. return delta;
  410. }
  411. function normalizeWheelEventDelta(evt) {
  412. let delta = normalizeWheelEventDirection(evt);
  413. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  414. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  415. const MOUSE_PIXELS_PER_LINE = 30;
  416. const MOUSE_LINES_PER_PAGE = 30;
  417. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  418. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  419. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  420. delta /= MOUSE_LINES_PER_PAGE;
  421. }
  422. return delta;
  423. }
  424. function isValidRotation(angle) {
  425. return Number.isInteger(angle) && angle % 90 === 0;
  426. }
  427. function isValidScrollMode(mode) {
  428. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  429. }
  430. function isValidSpreadMode(mode) {
  431. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  432. }
  433. function isPortraitOrientation(size) {
  434. return size.width <= size.height;
  435. }
  436. const animationStarted = new Promise(function (resolve) {
  437. window.requestAnimationFrame(resolve);
  438. });
  439. exports.animationStarted = animationStarted;
  440. const docStyle = document.documentElement.style;
  441. exports.docStyle = docStyle;
  442. function clamp(v, min, max) {
  443. return Math.min(Math.max(v, min), max);
  444. }
  445. var _classList = /*#__PURE__*/new WeakMap();
  446. var _percent = /*#__PURE__*/new WeakMap();
  447. var _visible = /*#__PURE__*/new WeakMap();
  448. class ProgressBar {
  449. constructor(id) {
  450. _classPrivateFieldInitSpec(this, _classList, {
  451. writable: true,
  452. value: null
  453. });
  454. _classPrivateFieldInitSpec(this, _percent, {
  455. writable: true,
  456. value: 0
  457. });
  458. _classPrivateFieldInitSpec(this, _visible, {
  459. writable: true,
  460. value: true
  461. });
  462. const bar = document.getElementById(id);
  463. _classPrivateFieldSet(this, _classList, bar.classList);
  464. }
  465. get percent() {
  466. return _classPrivateFieldGet(this, _percent);
  467. }
  468. set percent(val) {
  469. _classPrivateFieldSet(this, _percent, clamp(val, 0, 100));
  470. if (isNaN(val)) {
  471. _classPrivateFieldGet(this, _classList).add("indeterminate");
  472. return;
  473. }
  474. _classPrivateFieldGet(this, _classList).remove("indeterminate");
  475. docStyle.setProperty("--progressBar-percent", `${_classPrivateFieldGet(this, _percent)}%`);
  476. }
  477. setWidth(viewer) {
  478. if (!viewer) {
  479. return;
  480. }
  481. const container = viewer.parentNode;
  482. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  483. if (scrollbarWidth > 0) {
  484. docStyle.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  485. }
  486. }
  487. hide() {
  488. if (!_classPrivateFieldGet(this, _visible)) {
  489. return;
  490. }
  491. _classPrivateFieldSet(this, _visible, false);
  492. _classPrivateFieldGet(this, _classList).add("hidden");
  493. }
  494. show() {
  495. if (_classPrivateFieldGet(this, _visible)) {
  496. return;
  497. }
  498. _classPrivateFieldSet(this, _visible, true);
  499. _classPrivateFieldGet(this, _classList).remove("hidden");
  500. }
  501. }
  502. exports.ProgressBar = ProgressBar;
  503. function getActiveOrFocusedElement() {
  504. let curRoot = document;
  505. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  506. while ((_curActiveOrFocused = curActiveOrFocused) !== null && _curActiveOrFocused !== void 0 && _curActiveOrFocused.shadowRoot) {
  507. var _curActiveOrFocused;
  508. curRoot = curActiveOrFocused.shadowRoot;
  509. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  510. }
  511. return curActiveOrFocused;
  512. }
  513. function apiPageLayoutToViewerModes(layout) {
  514. let scrollMode = ScrollMode.VERTICAL,
  515. spreadMode = SpreadMode.NONE;
  516. switch (layout) {
  517. case "SinglePage":
  518. scrollMode = ScrollMode.PAGE;
  519. break;
  520. case "OneColumn":
  521. break;
  522. case "TwoPageLeft":
  523. scrollMode = ScrollMode.PAGE;
  524. case "TwoColumnLeft":
  525. spreadMode = SpreadMode.ODD;
  526. break;
  527. case "TwoPageRight":
  528. scrollMode = ScrollMode.PAGE;
  529. case "TwoColumnRight":
  530. spreadMode = SpreadMode.EVEN;
  531. break;
  532. }
  533. return {
  534. scrollMode,
  535. spreadMode
  536. };
  537. }
  538. function apiPageModeToSidebarView(mode) {
  539. switch (mode) {
  540. case "UseNone":
  541. return SidebarView.NONE;
  542. case "UseThumbs":
  543. return SidebarView.THUMBS;
  544. case "UseOutlines":
  545. return SidebarView.OUTLINE;
  546. case "UseAttachments":
  547. return SidebarView.ATTACHMENTS;
  548. case "UseOC":
  549. return SidebarView.LAYERS;
  550. }
  551. return SidebarView.NONE;
  552. }
  553. /***/ }),
  554. /* 2 */
  555. /***/ ((__unused_webpack_module, exports) => {
  556. Object.defineProperty(exports, "__esModule", ({
  557. value: true
  558. }));
  559. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  560. const compatibilityParams = Object.create(null);
  561. exports.compatibilityParams = compatibilityParams;
  562. {
  563. const userAgent = navigator.userAgent || "";
  564. const platform = navigator.platform || "";
  565. const maxTouchPoints = navigator.maxTouchPoints || 1;
  566. const isAndroid = /Android/.test(userAgent);
  567. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  568. (function checkCanvasSizeLimitation() {
  569. if (isIOS || isAndroid) {
  570. compatibilityParams.maxCanvasPixels = 5242880;
  571. }
  572. })();
  573. }
  574. const OptionKind = {
  575. VIEWER: 0x02,
  576. API: 0x04,
  577. WORKER: 0x08,
  578. PREFERENCE: 0x80
  579. };
  580. exports.OptionKind = OptionKind;
  581. const defaultOptions = {
  582. annotationEditorMode: {
  583. value: 0,
  584. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  585. },
  586. annotationMode: {
  587. value: 2,
  588. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  589. },
  590. cursorToolOnLoad: {
  591. value: 0,
  592. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  593. },
  594. defaultZoomValue: {
  595. value: "",
  596. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  597. },
  598. disableHistory: {
  599. value: false,
  600. kind: OptionKind.VIEWER
  601. },
  602. disablePageLabels: {
  603. value: false,
  604. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  605. },
  606. enablePermissions: {
  607. value: false,
  608. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  609. },
  610. enablePrintAutoRotate: {
  611. value: true,
  612. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  613. },
  614. enableScripting: {
  615. value: true,
  616. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  617. },
  618. externalLinkRel: {
  619. value: "noopener noreferrer nofollow",
  620. kind: OptionKind.VIEWER
  621. },
  622. externalLinkTarget: {
  623. value: 0,
  624. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  625. },
  626. historyUpdateUrl: {
  627. value: false,
  628. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  629. },
  630. ignoreDestinationZoom: {
  631. value: false,
  632. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  633. },
  634. imageResourcesPath: {
  635. value: "./images/",
  636. kind: OptionKind.VIEWER
  637. },
  638. maxCanvasPixels: {
  639. value: 16777216,
  640. kind: OptionKind.VIEWER
  641. },
  642. forcePageColors: {
  643. value: false,
  644. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  645. },
  646. pageColorsBackground: {
  647. value: "Canvas",
  648. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  649. },
  650. pageColorsForeground: {
  651. value: "CanvasText",
  652. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  653. },
  654. pdfBugEnabled: {
  655. value: false,
  656. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  657. },
  658. printResolution: {
  659. value: 150,
  660. kind: OptionKind.VIEWER
  661. },
  662. sidebarViewOnLoad: {
  663. value: -1,
  664. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  665. },
  666. scrollModeOnLoad: {
  667. value: -1,
  668. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  669. },
  670. spreadModeOnLoad: {
  671. value: -1,
  672. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  673. },
  674. textLayerMode: {
  675. value: 1,
  676. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  677. },
  678. useOnlyCssZoom: {
  679. value: false,
  680. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  681. },
  682. viewerCssTheme: {
  683. value: 0,
  684. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  685. },
  686. viewOnLoad: {
  687. value: 0,
  688. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  689. },
  690. cMapPacked: {
  691. value: true,
  692. kind: OptionKind.API
  693. },
  694. cMapUrl: {
  695. value: "../web/cmaps/",
  696. kind: OptionKind.API
  697. },
  698. disableAutoFetch: {
  699. value: false,
  700. kind: OptionKind.API + OptionKind.PREFERENCE
  701. },
  702. disableFontFace: {
  703. value: false,
  704. kind: OptionKind.API + OptionKind.PREFERENCE
  705. },
  706. disableRange: {
  707. value: false,
  708. kind: OptionKind.API + OptionKind.PREFERENCE
  709. },
  710. disableStream: {
  711. value: false,
  712. kind: OptionKind.API + OptionKind.PREFERENCE
  713. },
  714. docBaseUrl: {
  715. value: "",
  716. kind: OptionKind.API
  717. },
  718. enableXfa: {
  719. value: true,
  720. kind: OptionKind.API + OptionKind.PREFERENCE
  721. },
  722. fontExtraProperties: {
  723. value: false,
  724. kind: OptionKind.API
  725. },
  726. isEvalSupported: {
  727. value: true,
  728. kind: OptionKind.API
  729. },
  730. isOffscreenCanvasSupported: {
  731. value: true,
  732. kind: OptionKind.API
  733. },
  734. maxImageSize: {
  735. value: -1,
  736. kind: OptionKind.API
  737. },
  738. pdfBug: {
  739. value: false,
  740. kind: OptionKind.API
  741. },
  742. standardFontDataUrl: {
  743. value: "../web/standard_fonts/",
  744. kind: OptionKind.API
  745. },
  746. verbosity: {
  747. value: 1,
  748. kind: OptionKind.API
  749. },
  750. workerPort: {
  751. value: null,
  752. kind: OptionKind.WORKER
  753. },
  754. workerSrc: {
  755. value: "../build/pdf.worker.js",
  756. kind: OptionKind.WORKER
  757. }
  758. };
  759. {
  760. defaultOptions.defaultUrl = {
  761. value: "compressed.tracemonkey-pldi-09.pdf",
  762. kind: OptionKind.VIEWER
  763. };
  764. defaultOptions.disablePreferences = {
  765. value: false,
  766. kind: OptionKind.VIEWER
  767. };
  768. defaultOptions.locale = {
  769. value: navigator.language || "en-US",
  770. kind: OptionKind.VIEWER
  771. };
  772. defaultOptions.renderer = {
  773. value: "canvas",
  774. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  775. };
  776. defaultOptions.sandboxBundleSrc = {
  777. value: "../build/pdf.sandbox.js",
  778. kind: OptionKind.VIEWER
  779. };
  780. }
  781. const userOptions = Object.create(null);
  782. class AppOptions {
  783. constructor() {
  784. throw new Error("Cannot initialize AppOptions.");
  785. }
  786. static get(name) {
  787. const userOption = userOptions[name];
  788. if (userOption !== undefined) {
  789. return userOption;
  790. }
  791. const defaultOption = defaultOptions[name];
  792. if (defaultOption !== undefined) {
  793. return compatibilityParams[name] ?? defaultOption.value;
  794. }
  795. return undefined;
  796. }
  797. static getAll() {
  798. let kind = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  799. const options = Object.create(null);
  800. for (const name in defaultOptions) {
  801. const defaultOption = defaultOptions[name];
  802. if (kind) {
  803. if ((kind & defaultOption.kind) === 0) {
  804. continue;
  805. }
  806. if (kind === OptionKind.PREFERENCE) {
  807. const value = defaultOption.value,
  808. valueType = typeof value;
  809. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  810. options[name] = value;
  811. continue;
  812. }
  813. throw new Error(`Invalid type for preference: ${name}`);
  814. }
  815. }
  816. const userOption = userOptions[name];
  817. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  818. }
  819. return options;
  820. }
  821. static set(name, value) {
  822. userOptions[name] = value;
  823. }
  824. static setAll(options) {
  825. for (const name in options) {
  826. userOptions[name] = options[name];
  827. }
  828. }
  829. static remove(name) {
  830. delete userOptions[name];
  831. }
  832. static _hasUserOptions() {
  833. return Object.keys(userOptions).length > 0;
  834. }
  835. }
  836. exports.AppOptions = AppOptions;
  837. /***/ }),
  838. /* 3 */
  839. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  840. Object.defineProperty(exports, "__esModule", ({
  841. value: true
  842. }));
  843. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  844. var _ui_utils = __webpack_require__(1);
  845. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  846. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  847. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  848. function _classStaticPrivateMethodGet(receiver, classConstructor, method) { _classCheckPrivateStaticAccess(receiver, classConstructor); return method; }
  849. function _classCheckPrivateStaticAccess(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } }
  850. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  851. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  852. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  853. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  854. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  855. const LinkTarget = {
  856. NONE: 0,
  857. SELF: 1,
  858. BLANK: 2,
  859. PARENT: 3,
  860. TOP: 4
  861. };
  862. exports.LinkTarget = LinkTarget;
  863. function addLinkAttributes(link) {
  864. let {
  865. url,
  866. target,
  867. rel,
  868. enabled = true
  869. } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  870. if (!url || typeof url !== "string") {
  871. throw new Error('A valid "url" parameter must provided.');
  872. }
  873. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  874. if (enabled) {
  875. link.href = link.title = urlNullRemoved;
  876. } else {
  877. link.href = "";
  878. link.title = `Disabled: ${urlNullRemoved}`;
  879. link.onclick = () => {
  880. return false;
  881. };
  882. }
  883. let targetStr = "";
  884. switch (target) {
  885. case LinkTarget.NONE:
  886. break;
  887. case LinkTarget.SELF:
  888. targetStr = "_self";
  889. break;
  890. case LinkTarget.BLANK:
  891. targetStr = "_blank";
  892. break;
  893. case LinkTarget.PARENT:
  894. targetStr = "_parent";
  895. break;
  896. case LinkTarget.TOP:
  897. targetStr = "_top";
  898. break;
  899. }
  900. link.target = targetStr;
  901. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  902. }
  903. var _pagesRefCache = /*#__PURE__*/new WeakMap();
  904. var _goToDestinationHelper = /*#__PURE__*/new WeakSet();
  905. class PDFLinkService {
  906. constructor() {
  907. let {
  908. eventBus,
  909. externalLinkTarget = null,
  910. externalLinkRel = null,
  911. ignoreDestinationZoom = false
  912. } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  913. _classPrivateMethodInitSpec(this, _goToDestinationHelper);
  914. _classPrivateFieldInitSpec(this, _pagesRefCache, {
  915. writable: true,
  916. value: new Map()
  917. });
  918. this.eventBus = eventBus;
  919. this.externalLinkTarget = externalLinkTarget;
  920. this.externalLinkRel = externalLinkRel;
  921. this.externalLinkEnabled = true;
  922. this._ignoreDestinationZoom = ignoreDestinationZoom;
  923. this.baseUrl = null;
  924. this.pdfDocument = null;
  925. this.pdfViewer = null;
  926. this.pdfHistory = null;
  927. }
  928. setDocument(pdfDocument) {
  929. let baseUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  930. this.baseUrl = baseUrl;
  931. this.pdfDocument = pdfDocument;
  932. _classPrivateFieldGet(this, _pagesRefCache).clear();
  933. }
  934. setViewer(pdfViewer) {
  935. this.pdfViewer = pdfViewer;
  936. }
  937. setHistory(pdfHistory) {
  938. this.pdfHistory = pdfHistory;
  939. }
  940. get pagesCount() {
  941. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  942. }
  943. get page() {
  944. return this.pdfViewer.currentPageNumber;
  945. }
  946. set page(value) {
  947. this.pdfViewer.currentPageNumber = value;
  948. }
  949. get rotation() {
  950. return this.pdfViewer.pagesRotation;
  951. }
  952. set rotation(value) {
  953. this.pdfViewer.pagesRotation = value;
  954. }
  955. get isInPresentationMode() {
  956. return this.pdfViewer.isInPresentationMode;
  957. }
  958. async goToDestination(dest) {
  959. if (!this.pdfDocument) {
  960. return;
  961. }
  962. let namedDest, explicitDest;
  963. if (typeof dest === "string") {
  964. namedDest = dest;
  965. explicitDest = await this.pdfDocument.getDestination(dest);
  966. } else {
  967. namedDest = null;
  968. explicitDest = await dest;
  969. }
  970. if (!Array.isArray(explicitDest)) {
  971. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  972. return;
  973. }
  974. _classPrivateMethodGet(this, _goToDestinationHelper, _goToDestinationHelper2).call(this, dest, namedDest, explicitDest);
  975. }
  976. goToPage(val) {
  977. if (!this.pdfDocument) {
  978. return;
  979. }
  980. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  981. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  982. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  983. return;
  984. }
  985. if (this.pdfHistory) {
  986. this.pdfHistory.pushCurrentPosition();
  987. this.pdfHistory.pushPage(pageNumber);
  988. }
  989. this.pdfViewer.scrollPageIntoView({
  990. pageNumber
  991. });
  992. }
  993. addLinkAttributes(link, url) {
  994. let newWindow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  995. addLinkAttributes(link, {
  996. url,
  997. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  998. rel: this.externalLinkRel,
  999. enabled: this.externalLinkEnabled
  1000. });
  1001. }
  1002. getDestinationHash(dest) {
  1003. if (typeof dest === "string") {
  1004. if (dest.length > 0) {
  1005. return this.getAnchorUrl("#" + escape(dest));
  1006. }
  1007. } else if (Array.isArray(dest)) {
  1008. const str = JSON.stringify(dest);
  1009. if (str.length > 0) {
  1010. return this.getAnchorUrl("#" + escape(str));
  1011. }
  1012. }
  1013. return this.getAnchorUrl("");
  1014. }
  1015. getAnchorUrl(anchor) {
  1016. return (this.baseUrl || "") + anchor;
  1017. }
  1018. setHash(hash) {
  1019. if (!this.pdfDocument) {
  1020. return;
  1021. }
  1022. let pageNumber, dest;
  1023. if (hash.includes("=")) {
  1024. const params = (0, _ui_utils.parseQueryString)(hash);
  1025. if (params.has("search")) {
  1026. this.eventBus.dispatch("findfromurlhash", {
  1027. source: this,
  1028. query: params.get("search").replace(/"/g, ""),
  1029. phraseSearch: params.get("phrase") === "true"
  1030. });
  1031. }
  1032. if (params.has("page")) {
  1033. pageNumber = params.get("page") | 0 || 1;
  1034. }
  1035. if (params.has("zoom")) {
  1036. const zoomArgs = params.get("zoom").split(",");
  1037. const zoomArg = zoomArgs[0];
  1038. const zoomArgNumber = parseFloat(zoomArg);
  1039. if (!zoomArg.includes("Fit")) {
  1040. dest = [null, {
  1041. name: "XYZ"
  1042. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  1043. } else {
  1044. if (zoomArg === "Fit" || zoomArg === "FitB") {
  1045. dest = [null, {
  1046. name: zoomArg
  1047. }];
  1048. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  1049. dest = [null, {
  1050. name: zoomArg
  1051. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  1052. } else if (zoomArg === "FitR") {
  1053. if (zoomArgs.length !== 5) {
  1054. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  1055. } else {
  1056. dest = [null, {
  1057. name: zoomArg
  1058. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  1059. }
  1060. } else {
  1061. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  1062. }
  1063. }
  1064. }
  1065. if (dest) {
  1066. this.pdfViewer.scrollPageIntoView({
  1067. pageNumber: pageNumber || this.page,
  1068. destArray: dest,
  1069. allowNegativeOffset: true
  1070. });
  1071. } else if (pageNumber) {
  1072. this.page = pageNumber;
  1073. }
  1074. if (params.has("pagemode")) {
  1075. this.eventBus.dispatch("pagemode", {
  1076. source: this,
  1077. mode: params.get("pagemode")
  1078. });
  1079. }
  1080. if (params.has("nameddest")) {
  1081. this.goToDestination(params.get("nameddest"));
  1082. }
  1083. } else {
  1084. dest = unescape(hash);
  1085. try {
  1086. dest = JSON.parse(dest);
  1087. if (!Array.isArray(dest)) {
  1088. dest = dest.toString();
  1089. }
  1090. } catch (ex) {}
  1091. if (typeof dest === "string" || _classStaticPrivateMethodGet(PDFLinkService, PDFLinkService, _isValidExplicitDestination).call(PDFLinkService, dest)) {
  1092. this.goToDestination(dest);
  1093. return;
  1094. }
  1095. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  1096. }
  1097. }
  1098. executeNamedAction(action) {
  1099. var _this$pdfHistory, _this$pdfHistory2;
  1100. switch (action) {
  1101. case "GoBack":
  1102. (_this$pdfHistory = this.pdfHistory) === null || _this$pdfHistory === void 0 ? void 0 : _this$pdfHistory.back();
  1103. break;
  1104. case "GoForward":
  1105. (_this$pdfHistory2 = this.pdfHistory) === null || _this$pdfHistory2 === void 0 ? void 0 : _this$pdfHistory2.forward();
  1106. break;
  1107. case "NextPage":
  1108. this.pdfViewer.nextPage();
  1109. break;
  1110. case "PrevPage":
  1111. this.pdfViewer.previousPage();
  1112. break;
  1113. case "LastPage":
  1114. this.page = this.pagesCount;
  1115. break;
  1116. case "FirstPage":
  1117. this.page = 1;
  1118. break;
  1119. default:
  1120. break;
  1121. }
  1122. this.eventBus.dispatch("namedaction", {
  1123. source: this,
  1124. action
  1125. });
  1126. }
  1127. async executeSetOCGState(action) {
  1128. const pdfDocument = this.pdfDocument;
  1129. const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  1130. if (pdfDocument !== this.pdfDocument) {
  1131. return;
  1132. }
  1133. let operator;
  1134. for (const elem of action.state) {
  1135. switch (elem) {
  1136. case "ON":
  1137. case "OFF":
  1138. case "Toggle":
  1139. operator = elem;
  1140. continue;
  1141. }
  1142. switch (operator) {
  1143. case "ON":
  1144. optionalContentConfig.setVisibility(elem, true);
  1145. break;
  1146. case "OFF":
  1147. optionalContentConfig.setVisibility(elem, false);
  1148. break;
  1149. case "Toggle":
  1150. const group = optionalContentConfig.getGroup(elem);
  1151. if (group) {
  1152. optionalContentConfig.setVisibility(elem, !group.visible);
  1153. }
  1154. break;
  1155. }
  1156. }
  1157. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  1158. }
  1159. cachePageRef(pageNum, pageRef) {
  1160. if (!pageRef) {
  1161. return;
  1162. }
  1163. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1164. _classPrivateFieldGet(this, _pagesRefCache).set(refStr, pageNum);
  1165. }
  1166. _cachedPageNumber(pageRef) {
  1167. if (!pageRef) {
  1168. return null;
  1169. }
  1170. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1171. return _classPrivateFieldGet(this, _pagesRefCache).get(refStr) || null;
  1172. }
  1173. isPageVisible(pageNumber) {
  1174. return this.pdfViewer.isPageVisible(pageNumber);
  1175. }
  1176. isPageCached(pageNumber) {
  1177. return this.pdfViewer.isPageCached(pageNumber);
  1178. }
  1179. }
  1180. exports.PDFLinkService = PDFLinkService;
  1181. function _goToDestinationHelper2(rawDest) {
  1182. let namedDest = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  1183. let explicitDest = arguments.length > 2 ? arguments[2] : undefined;
  1184. const destRef = explicitDest[0];
  1185. let pageNumber;
  1186. if (typeof destRef === "object" && destRef !== null) {
  1187. pageNumber = this._cachedPageNumber(destRef);
  1188. if (!pageNumber) {
  1189. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  1190. this.cachePageRef(pageIndex + 1, destRef);
  1191. _classPrivateMethodGet(this, _goToDestinationHelper, _goToDestinationHelper2).call(this, rawDest, namedDest, explicitDest);
  1192. }).catch(() => {
  1193. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  1194. });
  1195. return;
  1196. }
  1197. } else if (Number.isInteger(destRef)) {
  1198. pageNumber = destRef + 1;
  1199. } else {
  1200. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  1201. return;
  1202. }
  1203. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  1204. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  1205. return;
  1206. }
  1207. if (this.pdfHistory) {
  1208. this.pdfHistory.pushCurrentPosition();
  1209. this.pdfHistory.push({
  1210. namedDest,
  1211. explicitDest,
  1212. pageNumber
  1213. });
  1214. }
  1215. this.pdfViewer.scrollPageIntoView({
  1216. pageNumber,
  1217. destArray: explicitDest,
  1218. ignoreDestinationZoom: this._ignoreDestinationZoom
  1219. });
  1220. }
  1221. function _isValidExplicitDestination(dest) {
  1222. if (!Array.isArray(dest)) {
  1223. return false;
  1224. }
  1225. const destLength = dest.length;
  1226. if (destLength < 2) {
  1227. return false;
  1228. }
  1229. const page = dest[0];
  1230. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  1231. return false;
  1232. }
  1233. const zoom = dest[1];
  1234. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  1235. return false;
  1236. }
  1237. let allowNull = true;
  1238. switch (zoom.name) {
  1239. case "XYZ":
  1240. if (destLength !== 5) {
  1241. return false;
  1242. }
  1243. break;
  1244. case "Fit":
  1245. case "FitB":
  1246. return destLength === 2;
  1247. case "FitH":
  1248. case "FitBH":
  1249. case "FitV":
  1250. case "FitBV":
  1251. if (destLength !== 3) {
  1252. return false;
  1253. }
  1254. break;
  1255. case "FitR":
  1256. if (destLength !== 6) {
  1257. return false;
  1258. }
  1259. allowNull = false;
  1260. break;
  1261. default:
  1262. return false;
  1263. }
  1264. for (let i = 2; i < destLength; i++) {
  1265. const param = dest[i];
  1266. if (!(typeof param === "number" || allowNull && param === null)) {
  1267. return false;
  1268. }
  1269. }
  1270. return true;
  1271. }
  1272. class SimpleLinkService {
  1273. constructor() {
  1274. this.externalLinkEnabled = true;
  1275. }
  1276. get pagesCount() {
  1277. return 0;
  1278. }
  1279. get page() {
  1280. return 0;
  1281. }
  1282. set page(value) {}
  1283. get rotation() {
  1284. return 0;
  1285. }
  1286. set rotation(value) {}
  1287. get isInPresentationMode() {
  1288. return false;
  1289. }
  1290. async goToDestination(dest) {}
  1291. goToPage(val) {}
  1292. addLinkAttributes(link, url) {
  1293. let newWindow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  1294. addLinkAttributes(link, {
  1295. url,
  1296. enabled: this.externalLinkEnabled
  1297. });
  1298. }
  1299. getDestinationHash(dest) {
  1300. return "#";
  1301. }
  1302. getAnchorUrl(hash) {
  1303. return "#";
  1304. }
  1305. setHash(hash) {}
  1306. executeNamedAction(action) {}
  1307. executeSetOCGState(action) {}
  1308. cachePageRef(pageNum, pageRef) {}
  1309. isPageVisible(pageNumber) {
  1310. return true;
  1311. }
  1312. isPageCached(pageNumber) {
  1313. return true;
  1314. }
  1315. }
  1316. exports.SimpleLinkService = SimpleLinkService;
  1317. /***/ }),
  1318. /* 4 */
  1319. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1320. Object.defineProperty(exports, "__esModule", ({
  1321. value: true
  1322. }));
  1323. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  1324. var _ui_utils = __webpack_require__(1);
  1325. var _pdfjsLib = __webpack_require__(5);
  1326. var _app_options = __webpack_require__(2);
  1327. var _event_utils = __webpack_require__(6);
  1328. var _pdf_cursor_tools = __webpack_require__(7);
  1329. var _pdf_link_service = __webpack_require__(3);
  1330. var _annotation_editor_params = __webpack_require__(9);
  1331. var _overlay_manager = __webpack_require__(10);
  1332. var _password_prompt = __webpack_require__(12);
  1333. var _pdf_attachment_viewer = __webpack_require__(13);
  1334. var _pdf_document_properties = __webpack_require__(15);
  1335. var _pdf_find_bar = __webpack_require__(16);
  1336. var _pdf_find_controller = __webpack_require__(17);
  1337. var _pdf_history = __webpack_require__(19);
  1338. var _pdf_layer_viewer = __webpack_require__(20);
  1339. var _pdf_outline_viewer = __webpack_require__(21);
  1340. var _pdf_presentation_mode = __webpack_require__(22);
  1341. var _pdf_rendering_queue = __webpack_require__(23);
  1342. var _pdf_scripting_manager = __webpack_require__(24);
  1343. var _pdf_sidebar = __webpack_require__(25);
  1344. var _pdf_sidebar_resizer = __webpack_require__(26);
  1345. var _pdf_thumbnail_viewer = __webpack_require__(27);
  1346. var _pdf_viewer = __webpack_require__(29);
  1347. var _secondary_toolbar = __webpack_require__(39);
  1348. var _toolbar = __webpack_require__(40);
  1349. var _view_history = __webpack_require__(41);
  1350. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  1351. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  1352. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  1353. const ViewOnLoad = {
  1354. UNKNOWN: -1,
  1355. PREVIOUS: 0,
  1356. INITIAL: 1
  1357. };
  1358. const ViewerCssTheme = {
  1359. AUTOMATIC: 0,
  1360. LIGHT: 1,
  1361. DARK: 2
  1362. };
  1363. const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
  1364. const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
  1365. class DefaultExternalServices {
  1366. constructor() {
  1367. throw new Error("Cannot initialize DefaultExternalServices.");
  1368. }
  1369. static updateFindControlState(data) {}
  1370. static updateFindMatchesCount(data) {}
  1371. static initPassiveLoading(callbacks) {}
  1372. static reportTelemetry(data) {}
  1373. static createDownloadManager(options) {
  1374. throw new Error("Not implemented: createDownloadManager");
  1375. }
  1376. static createPreferences() {
  1377. throw new Error("Not implemented: createPreferences");
  1378. }
  1379. static createL10n(options) {
  1380. throw new Error("Not implemented: createL10n");
  1381. }
  1382. static createScripting(options) {
  1383. throw new Error("Not implemented: createScripting");
  1384. }
  1385. static get supportsIntegratedFind() {
  1386. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  1387. }
  1388. static get supportsDocumentFonts() {
  1389. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  1390. }
  1391. static get supportedMouseWheelZoomModifierKeys() {
  1392. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  1393. ctrlKey: true,
  1394. metaKey: true
  1395. });
  1396. }
  1397. static get isInAutomation() {
  1398. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  1399. }
  1400. static updateEditorStates(data) {
  1401. throw new Error("Not implemented: updateEditorStates");
  1402. }
  1403. }
  1404. exports.DefaultExternalServices = DefaultExternalServices;
  1405. const PDFViewerApplication = {
  1406. initialBookmark: document.location.hash.substring(1),
  1407. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  1408. appConfig: null,
  1409. pdfDocument: null,
  1410. pdfLoadingTask: null,
  1411. printService: null,
  1412. pdfViewer: null,
  1413. pdfThumbnailViewer: null,
  1414. pdfRenderingQueue: null,
  1415. pdfPresentationMode: null,
  1416. pdfDocumentProperties: null,
  1417. pdfLinkService: null,
  1418. pdfHistory: null,
  1419. pdfSidebar: null,
  1420. pdfSidebarResizer: null,
  1421. pdfOutlineViewer: null,
  1422. pdfAttachmentViewer: null,
  1423. pdfLayerViewer: null,
  1424. pdfCursorTools: null,
  1425. pdfScriptingManager: null,
  1426. store: null,
  1427. downloadManager: null,
  1428. overlayManager: null,
  1429. preferences: null,
  1430. toolbar: null,
  1431. secondaryToolbar: null,
  1432. eventBus: null,
  1433. l10n: null,
  1434. annotationEditorParams: null,
  1435. isInitialViewSet: false,
  1436. downloadComplete: false,
  1437. isViewerEmbedded: window.parent !== window,
  1438. url: "",
  1439. baseUrl: "",
  1440. _downloadUrl: "",
  1441. externalServices: DefaultExternalServices,
  1442. _boundEvents: Object.create(null),
  1443. documentInfo: null,
  1444. metadata: null,
  1445. _contentDispositionFilename: null,
  1446. _contentLength: null,
  1447. _saveInProgress: false,
  1448. _docStats: null,
  1449. _wheelUnusedTicks: 0,
  1450. _PDFBug: null,
  1451. _hasAnnotationEditors: false,
  1452. _title: document.title,
  1453. _printAnnotationStoragePromise: null,
  1454. async initialize(appConfig) {
  1455. this.preferences = this.externalServices.createPreferences();
  1456. this.appConfig = appConfig;
  1457. await this._readPreferences();
  1458. await this._parseHashParameters();
  1459. this._forceCssTheme();
  1460. await this._initializeL10n();
  1461. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  1462. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  1463. }
  1464. await this._initializeViewerComponents();
  1465. this.bindEvents();
  1466. this.bindWindowEvents();
  1467. const appContainer = appConfig.appContainer || document.documentElement;
  1468. this.l10n.translate(appContainer).then(() => {
  1469. this.eventBus.dispatch("localized", {
  1470. source: this
  1471. });
  1472. });
  1473. this._initializedCapability.resolve();
  1474. },
  1475. async _readPreferences() {
  1476. if (_app_options.AppOptions.get("disablePreferences")) {
  1477. return;
  1478. }
  1479. if (_app_options.AppOptions._hasUserOptions()) {
  1480. console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  1481. }
  1482. try {
  1483. _app_options.AppOptions.setAll(await this.preferences.getAll());
  1484. } catch (reason) {
  1485. console.error(`_readPreferences: "${reason === null || reason === void 0 ? void 0 : reason.message}".`);
  1486. }
  1487. },
  1488. async _parseHashParameters() {
  1489. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  1490. return;
  1491. }
  1492. const hash = document.location.hash.substring(1);
  1493. if (!hash) {
  1494. return;
  1495. }
  1496. const {
  1497. mainContainer,
  1498. viewerContainer
  1499. } = this.appConfig,
  1500. params = (0, _ui_utils.parseQueryString)(hash);
  1501. if (params.get("disableworker") === "true") {
  1502. try {
  1503. await loadFakeWorker();
  1504. } catch (ex) {
  1505. console.error(`_parseHashParameters: "${ex.message}".`);
  1506. }
  1507. }
  1508. if (params.has("disablerange")) {
  1509. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  1510. }
  1511. if (params.has("disablestream")) {
  1512. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  1513. }
  1514. if (params.has("disableautofetch")) {
  1515. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  1516. }
  1517. if (params.has("disablefontface")) {
  1518. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  1519. }
  1520. if (params.has("disablehistory")) {
  1521. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  1522. }
  1523. if (params.has("verbosity")) {
  1524. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  1525. }
  1526. if (params.has("textlayer")) {
  1527. switch (params.get("textlayer")) {
  1528. case "off":
  1529. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  1530. break;
  1531. case "visible":
  1532. case "shadow":
  1533. case "hover":
  1534. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  1535. try {
  1536. await loadPDFBug(this);
  1537. this._PDFBug.loadCSS();
  1538. } catch (ex) {
  1539. console.error(`_parseHashParameters: "${ex.message}".`);
  1540. }
  1541. break;
  1542. }
  1543. }
  1544. if (params.has("pdfbug")) {
  1545. _app_options.AppOptions.set("pdfBug", true);
  1546. _app_options.AppOptions.set("fontExtraProperties", true);
  1547. const enabled = params.get("pdfbug").split(",");
  1548. try {
  1549. await loadPDFBug(this);
  1550. this._PDFBug.init({
  1551. OPS: _pdfjsLib.OPS
  1552. }, mainContainer, enabled);
  1553. } catch (ex) {
  1554. console.error(`_parseHashParameters: "${ex.message}".`);
  1555. }
  1556. }
  1557. if (params.has("locale")) {
  1558. _app_options.AppOptions.set("locale", params.get("locale"));
  1559. }
  1560. },
  1561. async _initializeL10n() {
  1562. this.l10n = this.externalServices.createL10n({
  1563. locale: _app_options.AppOptions.get("locale")
  1564. });
  1565. const dir = await this.l10n.getDirection();
  1566. document.getElementsByTagName("html")[0].dir = dir;
  1567. },
  1568. _forceCssTheme() {
  1569. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  1570. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  1571. return;
  1572. }
  1573. try {
  1574. const styleSheet = document.styleSheets[0];
  1575. const cssRules = (styleSheet === null || styleSheet === void 0 ? void 0 : styleSheet.cssRules) || [];
  1576. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  1577. var _rule$media;
  1578. const rule = cssRules[i];
  1579. if (rule instanceof CSSMediaRule && ((_rule$media = rule.media) === null || _rule$media === void 0 ? void 0 : _rule$media[0]) === "(prefers-color-scheme: dark)") {
  1580. if (cssTheme === ViewerCssTheme.LIGHT) {
  1581. styleSheet.deleteRule(i);
  1582. return;
  1583. }
  1584. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  1585. if (darkRules !== null && darkRules !== void 0 && darkRules[1]) {
  1586. styleSheet.deleteRule(i);
  1587. styleSheet.insertRule(darkRules[1], i);
  1588. }
  1589. return;
  1590. }
  1591. }
  1592. } catch (reason) {
  1593. console.error(`_forceCssTheme: "${reason === null || reason === void 0 ? void 0 : reason.message}".`);
  1594. }
  1595. },
  1596. async _initializeViewerComponents() {
  1597. const {
  1598. appConfig,
  1599. externalServices
  1600. } = this;
  1601. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  1602. this.eventBus = eventBus;
  1603. this.overlayManager = new _overlay_manager.OverlayManager();
  1604. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  1605. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  1606. this.pdfRenderingQueue = pdfRenderingQueue;
  1607. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  1608. eventBus,
  1609. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  1610. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  1611. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  1612. });
  1613. this.pdfLinkService = pdfLinkService;
  1614. const downloadManager = externalServices.createDownloadManager();
  1615. this.downloadManager = downloadManager;
  1616. const findController = new _pdf_find_controller.PDFFindController({
  1617. linkService: pdfLinkService,
  1618. eventBus
  1619. });
  1620. this.findController = findController;
  1621. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  1622. eventBus,
  1623. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  1624. scriptingFactory: externalServices,
  1625. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  1626. });
  1627. this.pdfScriptingManager = pdfScriptingManager;
  1628. const container = appConfig.mainContainer,
  1629. viewer = appConfig.viewerContainer;
  1630. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  1631. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  1632. background: _app_options.AppOptions.get("pageColorsBackground"),
  1633. foreground: _app_options.AppOptions.get("pageColorsForeground")
  1634. } : null;
  1635. this.pdfViewer = new _pdf_viewer.PDFViewer({
  1636. container,
  1637. viewer,
  1638. eventBus,
  1639. renderingQueue: pdfRenderingQueue,
  1640. linkService: pdfLinkService,
  1641. downloadManager,
  1642. findController,
  1643. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  1644. renderer: _app_options.AppOptions.get("renderer"),
  1645. l10n: this.l10n,
  1646. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  1647. annotationMode: _app_options.AppOptions.get("annotationMode"),
  1648. annotationEditorMode,
  1649. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  1650. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  1651. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  1652. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  1653. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  1654. pageColors
  1655. });
  1656. pdfRenderingQueue.setViewer(this.pdfViewer);
  1657. pdfLinkService.setViewer(this.pdfViewer);
  1658. pdfScriptingManager.setViewer(this.pdfViewer);
  1659. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  1660. container: appConfig.sidebar.thumbnailView,
  1661. eventBus,
  1662. renderingQueue: pdfRenderingQueue,
  1663. linkService: pdfLinkService,
  1664. l10n: this.l10n,
  1665. pageColors
  1666. });
  1667. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  1668. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  1669. this.pdfHistory = new _pdf_history.PDFHistory({
  1670. linkService: pdfLinkService,
  1671. eventBus
  1672. });
  1673. pdfLinkService.setHistory(this.pdfHistory);
  1674. }
  1675. if (!this.supportsIntegratedFind) {
  1676. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  1677. }
  1678. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  1679. this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  1680. } else {
  1681. for (const element of [document.getElementById("editorModeButtons"), document.getElementById("editorModeSeparator")]) {
  1682. element.hidden = true;
  1683. }
  1684. }
  1685. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
  1686. return this._docFilename;
  1687. });
  1688. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  1689. container,
  1690. eventBus,
  1691. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  1692. });
  1693. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  1694. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, this.externalServices);
  1695. if (this.supportsFullscreen) {
  1696. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  1697. container,
  1698. pdfViewer: this.pdfViewer,
  1699. eventBus
  1700. });
  1701. }
  1702. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  1703. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  1704. container: appConfig.sidebar.outlineView,
  1705. eventBus,
  1706. linkService: pdfLinkService,
  1707. downloadManager
  1708. });
  1709. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  1710. container: appConfig.sidebar.attachmentsView,
  1711. eventBus,
  1712. downloadManager
  1713. });
  1714. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  1715. container: appConfig.sidebar.layersView,
  1716. eventBus,
  1717. l10n: this.l10n
  1718. });
  1719. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  1720. elements: appConfig.sidebar,
  1721. pdfViewer: this.pdfViewer,
  1722. pdfThumbnailViewer: this.pdfThumbnailViewer,
  1723. eventBus,
  1724. l10n: this.l10n
  1725. });
  1726. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  1727. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  1728. },
  1729. run(config) {
  1730. this.initialize(config).then(webViewerInitialized);
  1731. },
  1732. get initialized() {
  1733. return this._initializedCapability.settled;
  1734. },
  1735. get initializedPromise() {
  1736. return this._initializedCapability.promise;
  1737. },
  1738. zoomIn(steps) {
  1739. if (this.pdfViewer.isInPresentationMode) {
  1740. return;
  1741. }
  1742. this.pdfViewer.increaseScale(steps);
  1743. },
  1744. zoomOut(steps) {
  1745. if (this.pdfViewer.isInPresentationMode) {
  1746. return;
  1747. }
  1748. this.pdfViewer.decreaseScale(steps);
  1749. },
  1750. zoomReset() {
  1751. if (this.pdfViewer.isInPresentationMode) {
  1752. return;
  1753. }
  1754. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1755. },
  1756. get pagesCount() {
  1757. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  1758. },
  1759. get page() {
  1760. return this.pdfViewer.currentPageNumber;
  1761. },
  1762. set page(val) {
  1763. this.pdfViewer.currentPageNumber = val;
  1764. },
  1765. get supportsPrinting() {
  1766. return PDFPrintServiceFactory.instance.supportsPrinting;
  1767. },
  1768. get supportsFullscreen() {
  1769. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  1770. },
  1771. get supportsIntegratedFind() {
  1772. return this.externalServices.supportsIntegratedFind;
  1773. },
  1774. get supportsDocumentFonts() {
  1775. return this.externalServices.supportsDocumentFonts;
  1776. },
  1777. get loadingBar() {
  1778. const bar = new _ui_utils.ProgressBar("loadingBar");
  1779. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  1780. },
  1781. get supportedMouseWheelZoomModifierKeys() {
  1782. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  1783. },
  1784. initPassiveLoading() {
  1785. throw new Error("Not implemented: initPassiveLoading");
  1786. },
  1787. setTitleUsingUrl() {
  1788. let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
  1789. let downloadUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  1790. this.url = url;
  1791. this.baseUrl = url.split("#")[0];
  1792. if (downloadUrl) {
  1793. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  1794. }
  1795. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  1796. if (!title) {
  1797. try {
  1798. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  1799. } catch (ex) {
  1800. title = url;
  1801. }
  1802. }
  1803. this.setTitle(title);
  1804. },
  1805. setTitle() {
  1806. let title = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._title;
  1807. this._title = title;
  1808. if (this.isViewerEmbedded) {
  1809. return;
  1810. }
  1811. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  1812. document.title = `${editorIndicator ? "* " : ""}${title}`;
  1813. },
  1814. get _docFilename() {
  1815. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  1816. },
  1817. _hideViewBookmark() {
  1818. this.appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
  1819. },
  1820. async close() {
  1821. var _this$pdfDocument, _this$pdfHistory, _this$findBar, _this$_PDFBug;
  1822. this._unblockDocumentLoadEvent();
  1823. this._hideViewBookmark();
  1824. if (!this.pdfLoadingTask) {
  1825. return;
  1826. }
  1827. if (((_this$pdfDocument = this.pdfDocument) === null || _this$pdfDocument === void 0 ? void 0 : _this$pdfDocument.annotationStorage.size) > 0 && this._annotationStorageModified) {
  1828. try {
  1829. await this.save();
  1830. } catch (reason) {}
  1831. }
  1832. const promises = [];
  1833. promises.push(this.pdfLoadingTask.destroy());
  1834. this.pdfLoadingTask = null;
  1835. if (this.pdfDocument) {
  1836. this.pdfDocument = null;
  1837. this.pdfThumbnailViewer.setDocument(null);
  1838. this.pdfViewer.setDocument(null);
  1839. this.pdfLinkService.setDocument(null);
  1840. this.pdfDocumentProperties.setDocument(null);
  1841. }
  1842. this.pdfLinkService.externalLinkEnabled = true;
  1843. this.store = null;
  1844. this.isInitialViewSet = false;
  1845. this.downloadComplete = false;
  1846. this.url = "";
  1847. this.baseUrl = "";
  1848. this._downloadUrl = "";
  1849. this.documentInfo = null;
  1850. this.metadata = null;
  1851. this._contentDispositionFilename = null;
  1852. this._contentLength = null;
  1853. this._saveInProgress = false;
  1854. this._docStats = null;
  1855. this._hasAnnotationEditors = false;
  1856. promises.push(this.pdfScriptingManager.destroyPromise);
  1857. this.setTitle();
  1858. this.pdfSidebar.reset();
  1859. this.pdfOutlineViewer.reset();
  1860. this.pdfAttachmentViewer.reset();
  1861. this.pdfLayerViewer.reset();
  1862. (_this$pdfHistory = this.pdfHistory) === null || _this$pdfHistory === void 0 ? void 0 : _this$pdfHistory.reset();
  1863. (_this$findBar = this.findBar) === null || _this$findBar === void 0 ? void 0 : _this$findBar.reset();
  1864. this.toolbar.reset();
  1865. this.secondaryToolbar.reset();
  1866. (_this$_PDFBug = this._PDFBug) === null || _this$_PDFBug === void 0 ? void 0 : _this$_PDFBug.cleanup();
  1867. await Promise.all(promises);
  1868. },
  1869. async open(file, args) {
  1870. if (this.pdfLoadingTask) {
  1871. await this.close();
  1872. }
  1873. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  1874. for (const key in workerParameters) {
  1875. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  1876. }
  1877. const parameters = Object.create(null);
  1878. if (typeof file === "string") {
  1879. this.setTitleUsingUrl(file, file);
  1880. parameters.url = file;
  1881. } else if (file && "byteLength" in file) {
  1882. parameters.data = file;
  1883. } else if (file.url && file.originalUrl) {
  1884. this.setTitleUsingUrl(file.originalUrl, file.url);
  1885. parameters.url = file.url;
  1886. }
  1887. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  1888. for (const key in apiParameters) {
  1889. let value = apiParameters[key];
  1890. if (key === "docBaseUrl" && !value) {}
  1891. parameters[key] = value;
  1892. }
  1893. if (args) {
  1894. for (const key in args) {
  1895. parameters[key] = args[key];
  1896. }
  1897. }
  1898. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  1899. this.pdfLoadingTask = loadingTask;
  1900. loadingTask.onPassword = (updateCallback, reason) => {
  1901. if (this.isViewerEmbedded) {
  1902. this._unblockDocumentLoadEvent();
  1903. }
  1904. this.pdfLinkService.externalLinkEnabled = false;
  1905. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  1906. this.passwordPrompt.open();
  1907. };
  1908. loadingTask.onProgress = _ref => {
  1909. let {
  1910. loaded,
  1911. total
  1912. } = _ref;
  1913. this.progress(loaded / total);
  1914. };
  1915. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  1916. return loadingTask.promise.then(pdfDocument => {
  1917. this.load(pdfDocument);
  1918. }, reason => {
  1919. if (loadingTask !== this.pdfLoadingTask) {
  1920. return undefined;
  1921. }
  1922. let key = "loading_error";
  1923. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  1924. key = "invalid_file_error";
  1925. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  1926. key = "missing_file_error";
  1927. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  1928. key = "unexpected_response_error";
  1929. }
  1930. return this.l10n.get(key).then(msg => {
  1931. this._documentError(msg, {
  1932. message: reason === null || reason === void 0 ? void 0 : reason.message
  1933. });
  1934. throw reason;
  1935. });
  1936. });
  1937. },
  1938. _ensureDownloadComplete() {
  1939. if (this.pdfDocument && this.downloadComplete) {
  1940. return;
  1941. }
  1942. throw new Error("PDF document not downloaded.");
  1943. },
  1944. async download() {
  1945. const url = this._downloadUrl,
  1946. filename = this._docFilename;
  1947. try {
  1948. this._ensureDownloadComplete();
  1949. const data = await this.pdfDocument.getData();
  1950. const blob = new Blob([data], {
  1951. type: "application/pdf"
  1952. });
  1953. await this.downloadManager.download(blob, url, filename);
  1954. } catch (reason) {
  1955. await this.downloadManager.downloadUrl(url, filename);
  1956. }
  1957. },
  1958. async save() {
  1959. if (this._saveInProgress) {
  1960. return;
  1961. }
  1962. this._saveInProgress = true;
  1963. await this.pdfScriptingManager.dispatchWillSave();
  1964. const url = this._downloadUrl,
  1965. filename = this._docFilename;
  1966. try {
  1967. this._ensureDownloadComplete();
  1968. const data = await this.pdfDocument.saveDocument();
  1969. const blob = new Blob([data], {
  1970. type: "application/pdf"
  1971. });
  1972. await this.downloadManager.download(blob, url, filename);
  1973. } catch (reason) {
  1974. console.error(`Error when saving the document: ${reason.message}`);
  1975. await this.download();
  1976. } finally {
  1977. await this.pdfScriptingManager.dispatchDidSave();
  1978. this._saveInProgress = false;
  1979. }
  1980. if (this._hasAnnotationEditors) {
  1981. this.externalServices.reportTelemetry({
  1982. type: "editing",
  1983. data: {
  1984. type: "save"
  1985. }
  1986. });
  1987. }
  1988. },
  1989. downloadOrSave() {
  1990. var _this$pdfDocument2;
  1991. if (((_this$pdfDocument2 = this.pdfDocument) === null || _this$pdfDocument2 === void 0 ? void 0 : _this$pdfDocument2.annotationStorage.size) > 0) {
  1992. this.save();
  1993. } else {
  1994. this.download();
  1995. }
  1996. },
  1997. fallback(featureId) {
  1998. this.externalServices.reportTelemetry({
  1999. type: "unsupportedFeature",
  2000. featureId
  2001. });
  2002. },
  2003. _documentError(message) {
  2004. let moreInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  2005. this._unblockDocumentLoadEvent();
  2006. this._otherError(message, moreInfo);
  2007. this.eventBus.dispatch("documenterror", {
  2008. source: this,
  2009. message,
  2010. reason: (moreInfo === null || moreInfo === void 0 ? void 0 : moreInfo.message) ?? null
  2011. });
  2012. },
  2013. _otherError(message) {
  2014. let moreInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  2015. const moreInfoText = [`PDF.js v${_pdfjsLib.version || "?"} (build: ${_pdfjsLib.build || "?"})`];
  2016. if (moreInfo) {
  2017. moreInfoText.push(`Message: ${moreInfo.message}`);
  2018. if (moreInfo.stack) {
  2019. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  2020. } else {
  2021. if (moreInfo.filename) {
  2022. moreInfoText.push(`File: ${moreInfo.filename}`);
  2023. }
  2024. if (moreInfo.lineNumber) {
  2025. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  2026. }
  2027. }
  2028. }
  2029. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  2030. this.fallback();
  2031. },
  2032. progress(level) {
  2033. var _this$pdfDocument3;
  2034. if (this.downloadComplete) {
  2035. return;
  2036. }
  2037. const percent = Math.round(level * 100);
  2038. if (percent <= this.loadingBar.percent) {
  2039. return;
  2040. }
  2041. this.loadingBar.percent = percent;
  2042. const disableAutoFetch = ((_this$pdfDocument3 = this.pdfDocument) === null || _this$pdfDocument3 === void 0 ? void 0 : _this$pdfDocument3.loadingParams.disableAutoFetch) ?? _app_options.AppOptions.get("disableAutoFetch");
  2043. if (!disableAutoFetch || isNaN(percent)) {
  2044. return;
  2045. }
  2046. if (this.disableAutoFetchLoadingBarTimeout) {
  2047. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  2048. this.disableAutoFetchLoadingBarTimeout = null;
  2049. }
  2050. this.loadingBar.show();
  2051. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  2052. this.loadingBar.hide();
  2053. this.disableAutoFetchLoadingBarTimeout = null;
  2054. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  2055. },
  2056. load(pdfDocument) {
  2057. this.pdfDocument = pdfDocument;
  2058. pdfDocument.getDownloadInfo().then(_ref2 => {
  2059. let {
  2060. length
  2061. } = _ref2;
  2062. this._contentLength = length;
  2063. this.downloadComplete = true;
  2064. this.loadingBar.hide();
  2065. firstPagePromise.then(() => {
  2066. this.eventBus.dispatch("documentloaded", {
  2067. source: this
  2068. });
  2069. });
  2070. });
  2071. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  2072. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  2073. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  2074. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  2075. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  2076. let baseDocumentUrl;
  2077. baseDocumentUrl = null;
  2078. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  2079. this.pdfDocumentProperties.setDocument(pdfDocument);
  2080. const pdfViewer = this.pdfViewer;
  2081. pdfViewer.setDocument(pdfDocument);
  2082. const {
  2083. firstPagePromise,
  2084. onePageRendered,
  2085. pagesPromise
  2086. } = pdfViewer;
  2087. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  2088. pdfThumbnailViewer.setDocument(pdfDocument);
  2089. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  2090. page: null,
  2091. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  2092. scrollLeft: "0",
  2093. scrollTop: "0",
  2094. rotation: null,
  2095. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  2096. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  2097. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  2098. }).catch(() => {
  2099. return Object.create(null);
  2100. });
  2101. firstPagePromise.then(pdfPage => {
  2102. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  2103. this._initializeAnnotationStorageCallbacks(pdfDocument);
  2104. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async _ref3 => {
  2105. let [timeStamp, stored, pageLayout, pageMode, openAction] = _ref3;
  2106. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  2107. this._initializePdfHistory({
  2108. fingerprint: pdfDocument.fingerprints[0],
  2109. viewOnLoad,
  2110. initialDest: openAction === null || openAction === void 0 ? void 0 : openAction.dest
  2111. });
  2112. const initialBookmark = this.initialBookmark;
  2113. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  2114. let hash = zoom ? `zoom=${zoom}` : null;
  2115. let rotation = null;
  2116. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  2117. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  2118. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  2119. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  2120. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  2121. rotation = parseInt(stored.rotation, 10);
  2122. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2123. sidebarView = stored.sidebarView | 0;
  2124. }
  2125. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  2126. scrollMode = stored.scrollMode | 0;
  2127. }
  2128. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2129. spreadMode = stored.spreadMode | 0;
  2130. }
  2131. }
  2132. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2133. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  2134. }
  2135. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2136. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  2137. spreadMode = modes.spreadMode;
  2138. }
  2139. this.setInitialView(hash, {
  2140. rotation,
  2141. sidebarView,
  2142. scrollMode,
  2143. spreadMode
  2144. });
  2145. this.eventBus.dispatch("documentinit", {
  2146. source: this
  2147. });
  2148. if (!this.isViewerEmbedded) {
  2149. pdfViewer.focus();
  2150. }
  2151. await Promise.race([pagesPromise, new Promise(resolve => {
  2152. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  2153. })]);
  2154. if (!initialBookmark && !hash) {
  2155. return;
  2156. }
  2157. if (pdfViewer.hasEqualPageSizes) {
  2158. return;
  2159. }
  2160. this.initialBookmark = initialBookmark;
  2161. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  2162. this.setInitialView(hash);
  2163. }).catch(() => {
  2164. this.setInitialView();
  2165. }).then(function () {
  2166. pdfViewer.update();
  2167. });
  2168. });
  2169. pagesPromise.then(() => {
  2170. this._unblockDocumentLoadEvent();
  2171. this._initializeAutoPrint(pdfDocument, openActionPromise);
  2172. }, reason => {
  2173. this.l10n.get("loading_error").then(msg => {
  2174. this._documentError(msg, {
  2175. message: reason === null || reason === void 0 ? void 0 : reason.message
  2176. });
  2177. });
  2178. });
  2179. onePageRendered.then(data => {
  2180. this.externalServices.reportTelemetry({
  2181. type: "pageInfo",
  2182. timestamp: data.timestamp
  2183. });
  2184. pdfDocument.getOutline().then(outline => {
  2185. if (pdfDocument !== this.pdfDocument) {
  2186. return;
  2187. }
  2188. this.pdfOutlineViewer.render({
  2189. outline,
  2190. pdfDocument
  2191. });
  2192. });
  2193. pdfDocument.getAttachments().then(attachments => {
  2194. if (pdfDocument !== this.pdfDocument) {
  2195. return;
  2196. }
  2197. this.pdfAttachmentViewer.render({
  2198. attachments
  2199. });
  2200. });
  2201. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  2202. if (pdfDocument !== this.pdfDocument) {
  2203. return;
  2204. }
  2205. this.pdfLayerViewer.render({
  2206. optionalContentConfig,
  2207. pdfDocument
  2208. });
  2209. });
  2210. });
  2211. this._initializePageLabels(pdfDocument);
  2212. this._initializeMetadata(pdfDocument);
  2213. },
  2214. async _scriptingDocProperties(pdfDocument) {
  2215. var _this$metadata, _this$metadata2;
  2216. if (!this.documentInfo) {
  2217. await new Promise(resolve => {
  2218. this.eventBus._on("metadataloaded", resolve, {
  2219. once: true
  2220. });
  2221. });
  2222. if (pdfDocument !== this.pdfDocument) {
  2223. return null;
  2224. }
  2225. }
  2226. if (!this._contentLength) {
  2227. await new Promise(resolve => {
  2228. this.eventBus._on("documentloaded", resolve, {
  2229. once: true
  2230. });
  2231. });
  2232. if (pdfDocument !== this.pdfDocument) {
  2233. return null;
  2234. }
  2235. }
  2236. return {
  2237. ...this.documentInfo,
  2238. baseURL: this.baseUrl,
  2239. filesize: this._contentLength,
  2240. filename: this._docFilename,
  2241. metadata: (_this$metadata = this.metadata) === null || _this$metadata === void 0 ? void 0 : _this$metadata.getRaw(),
  2242. authors: (_this$metadata2 = this.metadata) === null || _this$metadata2 === void 0 ? void 0 : _this$metadata2.get("dc:creator"),
  2243. numPages: this.pagesCount,
  2244. URL: this.url
  2245. };
  2246. },
  2247. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  2248. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  2249. if (pdfDocument !== this.pdfDocument) {
  2250. return;
  2251. }
  2252. let triggerAutoPrint = false;
  2253. if ((openAction === null || openAction === void 0 ? void 0 : openAction.action) === "Print") {
  2254. triggerAutoPrint = true;
  2255. }
  2256. if (javaScript) {
  2257. javaScript.some(js => {
  2258. if (!js) {
  2259. return false;
  2260. }
  2261. console.warn("Warning: JavaScript support is not enabled");
  2262. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  2263. return true;
  2264. });
  2265. if (!triggerAutoPrint) {
  2266. for (const js of javaScript) {
  2267. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  2268. triggerAutoPrint = true;
  2269. break;
  2270. }
  2271. }
  2272. }
  2273. }
  2274. if (triggerAutoPrint) {
  2275. this.triggerPrinting();
  2276. }
  2277. },
  2278. async _initializeMetadata(pdfDocument) {
  2279. const {
  2280. info,
  2281. metadata,
  2282. contentDispositionFilename,
  2283. contentLength
  2284. } = await pdfDocument.getMetadata();
  2285. if (pdfDocument !== this.pdfDocument) {
  2286. return;
  2287. }
  2288. this.documentInfo = info;
  2289. this.metadata = metadata;
  2290. this._contentDispositionFilename ?? (this._contentDispositionFilename = contentDispositionFilename);
  2291. this._contentLength ?? (this._contentLength = contentLength);
  2292. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`);
  2293. let pdfTitle = info.Title;
  2294. const metadataTitle = metadata === null || metadata === void 0 ? void 0 : metadata.get("dc:title");
  2295. if (metadataTitle) {
  2296. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  2297. pdfTitle = metadataTitle;
  2298. }
  2299. }
  2300. if (pdfTitle) {
  2301. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  2302. } else if (this._contentDispositionFilename) {
  2303. this.setTitle(this._contentDispositionFilename);
  2304. }
  2305. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  2306. if (pdfDocument.loadingParams.enableXfa) {
  2307. console.warn("Warning: XFA Foreground documents are not supported");
  2308. } else {
  2309. console.warn("Warning: XFA support is not enabled");
  2310. }
  2311. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  2312. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  2313. console.warn("Warning: Interactive form support is not enabled");
  2314. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  2315. }
  2316. if (info.IsSignaturesPresent) {
  2317. console.warn("Warning: Digital signatures validation is not supported");
  2318. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  2319. }
  2320. let versionId = "other";
  2321. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  2322. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  2323. }
  2324. let generatorId = "other";
  2325. if (info.Producer) {
  2326. const producer = info.Producer.toLowerCase();
  2327. KNOWN_GENERATORS.some(function (generator) {
  2328. if (!producer.includes(generator)) {
  2329. return false;
  2330. }
  2331. generatorId = generator.replace(/[ .-]/g, "_");
  2332. return true;
  2333. });
  2334. }
  2335. let formType = null;
  2336. if (info.IsXFAPresent) {
  2337. formType = "xfa";
  2338. } else if (info.IsAcroFormPresent) {
  2339. formType = "acroform";
  2340. }
  2341. this.externalServices.reportTelemetry({
  2342. type: "documentInfo",
  2343. version: versionId,
  2344. generator: generatorId,
  2345. formType
  2346. });
  2347. this.eventBus.dispatch("metadataloaded", {
  2348. source: this
  2349. });
  2350. },
  2351. async _initializePageLabels(pdfDocument) {
  2352. const labels = await pdfDocument.getPageLabels();
  2353. if (pdfDocument !== this.pdfDocument) {
  2354. return;
  2355. }
  2356. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  2357. return;
  2358. }
  2359. const numLabels = labels.length;
  2360. let standardLabels = 0,
  2361. emptyLabels = 0;
  2362. for (let i = 0; i < numLabels; i++) {
  2363. const label = labels[i];
  2364. if (label === (i + 1).toString()) {
  2365. standardLabels++;
  2366. } else if (label === "") {
  2367. emptyLabels++;
  2368. } else {
  2369. break;
  2370. }
  2371. }
  2372. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  2373. return;
  2374. }
  2375. const {
  2376. pdfViewer,
  2377. pdfThumbnailViewer,
  2378. toolbar
  2379. } = this;
  2380. pdfViewer.setPageLabels(labels);
  2381. pdfThumbnailViewer.setPageLabels(labels);
  2382. toolbar.setPagesCount(numLabels, true);
  2383. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2384. },
  2385. _initializePdfHistory(_ref4) {
  2386. let {
  2387. fingerprint,
  2388. viewOnLoad,
  2389. initialDest = null
  2390. } = _ref4;
  2391. if (!this.pdfHistory) {
  2392. return;
  2393. }
  2394. this.pdfHistory.initialize({
  2395. fingerprint,
  2396. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  2397. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  2398. });
  2399. if (this.pdfHistory.initialBookmark) {
  2400. this.initialBookmark = this.pdfHistory.initialBookmark;
  2401. this.initialRotation = this.pdfHistory.initialRotation;
  2402. }
  2403. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  2404. this.initialBookmark = JSON.stringify(initialDest);
  2405. this.pdfHistory.push({
  2406. explicitDest: initialDest,
  2407. pageNumber: null
  2408. });
  2409. }
  2410. },
  2411. _initializeAnnotationStorageCallbacks(pdfDocument) {
  2412. if (pdfDocument !== this.pdfDocument) {
  2413. return;
  2414. }
  2415. const {
  2416. annotationStorage
  2417. } = pdfDocument;
  2418. annotationStorage.onSetModified = () => {
  2419. window.addEventListener("beforeunload", beforeUnload);
  2420. this._annotationStorageModified = true;
  2421. };
  2422. annotationStorage.onResetModified = () => {
  2423. window.removeEventListener("beforeunload", beforeUnload);
  2424. delete this._annotationStorageModified;
  2425. };
  2426. annotationStorage.onAnnotationEditor = typeStr => {
  2427. this._hasAnnotationEditors = !!typeStr;
  2428. this.setTitle();
  2429. if (typeStr) {
  2430. this.externalServices.reportTelemetry({
  2431. type: "editing",
  2432. data: {
  2433. type: typeStr
  2434. }
  2435. });
  2436. }
  2437. };
  2438. },
  2439. setInitialView(storedHash) {
  2440. let {
  2441. rotation,
  2442. sidebarView,
  2443. scrollMode,
  2444. spreadMode
  2445. } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2446. const setRotation = angle => {
  2447. if ((0, _ui_utils.isValidRotation)(angle)) {
  2448. this.pdfViewer.pagesRotation = angle;
  2449. }
  2450. };
  2451. const setViewerModes = (scroll, spread) => {
  2452. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  2453. this.pdfViewer.scrollMode = scroll;
  2454. }
  2455. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  2456. this.pdfViewer.spreadMode = spread;
  2457. }
  2458. };
  2459. this.isInitialViewSet = true;
  2460. this.pdfSidebar.setInitialView(sidebarView);
  2461. setViewerModes(scrollMode, spreadMode);
  2462. if (this.initialBookmark) {
  2463. setRotation(this.initialRotation);
  2464. delete this.initialRotation;
  2465. this.pdfLinkService.setHash(this.initialBookmark);
  2466. this.initialBookmark = null;
  2467. } else if (storedHash) {
  2468. setRotation(rotation);
  2469. this.pdfLinkService.setHash(storedHash);
  2470. }
  2471. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  2472. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  2473. if (!this.pdfViewer.currentScaleValue) {
  2474. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2475. }
  2476. },
  2477. _cleanup() {
  2478. if (!this.pdfDocument) {
  2479. return;
  2480. }
  2481. this.pdfViewer.cleanup();
  2482. this.pdfThumbnailViewer.cleanup();
  2483. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  2484. },
  2485. forceRendering() {
  2486. this.pdfRenderingQueue.printing = !!this.printService;
  2487. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS;
  2488. this.pdfRenderingQueue.renderHighestPriority();
  2489. },
  2490. beforePrint() {
  2491. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => {
  2492. var _this$pdfDocument4;
  2493. return (_this$pdfDocument4 = this.pdfDocument) === null || _this$pdfDocument4 === void 0 ? void 0 : _this$pdfDocument4.annotationStorage.print;
  2494. });
  2495. if (this.printService) {
  2496. return;
  2497. }
  2498. if (!this.supportsPrinting) {
  2499. this.l10n.get("printing_not_supported").then(msg => {
  2500. this._otherError(msg);
  2501. });
  2502. return;
  2503. }
  2504. if (!this.pdfViewer.pageViewsReady) {
  2505. this.l10n.get("printing_not_ready").then(msg => {
  2506. window.alert(msg);
  2507. });
  2508. return;
  2509. }
  2510. const pagesOverview = this.pdfViewer.getPagesOverview();
  2511. const printContainer = this.appConfig.printContainer;
  2512. const printResolution = _app_options.AppOptions.get("printResolution");
  2513. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  2514. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  2515. this.printService = printService;
  2516. this.forceRendering();
  2517. this.setTitle();
  2518. printService.layout();
  2519. this.externalServices.reportTelemetry({
  2520. type: "print"
  2521. });
  2522. if (this._hasAnnotationEditors) {
  2523. this.externalServices.reportTelemetry({
  2524. type: "editing",
  2525. data: {
  2526. type: "print"
  2527. }
  2528. });
  2529. }
  2530. },
  2531. afterPrint() {
  2532. if (this._printAnnotationStoragePromise) {
  2533. this._printAnnotationStoragePromise.then(() => {
  2534. this.pdfScriptingManager.dispatchDidPrint();
  2535. });
  2536. this._printAnnotationStoragePromise = null;
  2537. }
  2538. if (this.printService) {
  2539. var _this$pdfDocument5;
  2540. this.printService.destroy();
  2541. this.printService = null;
  2542. (_this$pdfDocument5 = this.pdfDocument) === null || _this$pdfDocument5 === void 0 ? void 0 : _this$pdfDocument5.annotationStorage.resetModified();
  2543. }
  2544. this.forceRendering();
  2545. this.setTitle();
  2546. },
  2547. rotatePages(delta) {
  2548. this.pdfViewer.pagesRotation += delta;
  2549. },
  2550. requestPresentationMode() {
  2551. var _this$pdfPresentation;
  2552. (_this$pdfPresentation = this.pdfPresentationMode) === null || _this$pdfPresentation === void 0 ? void 0 : _this$pdfPresentation.request();
  2553. },
  2554. triggerPrinting() {
  2555. if (!this.supportsPrinting) {
  2556. return;
  2557. }
  2558. window.print();
  2559. },
  2560. bindEvents() {
  2561. const {
  2562. eventBus,
  2563. _boundEvents
  2564. } = this;
  2565. _boundEvents.beforePrint = this.beforePrint.bind(this);
  2566. _boundEvents.afterPrint = this.afterPrint.bind(this);
  2567. eventBus._on("resize", webViewerResize);
  2568. eventBus._on("hashchange", webViewerHashchange);
  2569. eventBus._on("beforeprint", _boundEvents.beforePrint);
  2570. eventBus._on("afterprint", _boundEvents.afterPrint);
  2571. eventBus._on("pagerendered", webViewerPageRendered);
  2572. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  2573. eventBus._on("pagechanging", webViewerPageChanging);
  2574. eventBus._on("scalechanging", webViewerScaleChanging);
  2575. eventBus._on("rotationchanging", webViewerRotationChanging);
  2576. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  2577. eventBus._on("pagemode", webViewerPageMode);
  2578. eventBus._on("namedaction", webViewerNamedAction);
  2579. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  2580. eventBus._on("presentationmode", webViewerPresentationMode);
  2581. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  2582. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  2583. eventBus._on("print", webViewerPrint);
  2584. eventBus._on("download", webViewerDownload);
  2585. eventBus._on("firstpage", webViewerFirstPage);
  2586. eventBus._on("lastpage", webViewerLastPage);
  2587. eventBus._on("nextpage", webViewerNextPage);
  2588. eventBus._on("previouspage", webViewerPreviousPage);
  2589. eventBus._on("zoomin", webViewerZoomIn);
  2590. eventBus._on("zoomout", webViewerZoomOut);
  2591. eventBus._on("zoomreset", webViewerZoomReset);
  2592. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  2593. eventBus._on("scalechanged", webViewerScaleChanged);
  2594. eventBus._on("rotatecw", webViewerRotateCw);
  2595. eventBus._on("rotateccw", webViewerRotateCcw);
  2596. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  2597. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  2598. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  2599. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  2600. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  2601. eventBus._on("documentproperties", webViewerDocumentProperties);
  2602. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  2603. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2604. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  2605. if (_app_options.AppOptions.get("pdfBug")) {
  2606. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  2607. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2608. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2609. }
  2610. eventBus._on("fileinputchange", webViewerFileInputChange);
  2611. eventBus._on("openfile", webViewerOpenFile);
  2612. },
  2613. bindWindowEvents() {
  2614. const {
  2615. eventBus,
  2616. _boundEvents
  2617. } = this;
  2618. function addWindowResolutionChange() {
  2619. let evt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  2620. if (evt) {
  2621. webViewerResolutionChange(evt);
  2622. }
  2623. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  2624. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  2625. once: true
  2626. });
  2627. _boundEvents.removeWindowResolutionChange || (_boundEvents.removeWindowResolutionChange = function () {
  2628. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  2629. _boundEvents.removeWindowResolutionChange = null;
  2630. });
  2631. }
  2632. addWindowResolutionChange();
  2633. _boundEvents.windowResize = () => {
  2634. eventBus.dispatch("resize", {
  2635. source: window
  2636. });
  2637. };
  2638. _boundEvents.windowHashChange = () => {
  2639. eventBus.dispatch("hashchange", {
  2640. source: window,
  2641. hash: document.location.hash.substring(1)
  2642. });
  2643. };
  2644. _boundEvents.windowBeforePrint = () => {
  2645. eventBus.dispatch("beforeprint", {
  2646. source: window
  2647. });
  2648. };
  2649. _boundEvents.windowAfterPrint = () => {
  2650. eventBus.dispatch("afterprint", {
  2651. source: window
  2652. });
  2653. };
  2654. _boundEvents.windowUpdateFromSandbox = event => {
  2655. eventBus.dispatch("updatefromsandbox", {
  2656. source: window,
  2657. detail: event.detail
  2658. });
  2659. };
  2660. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  2661. window.addEventListener("wheel", webViewerWheel, {
  2662. passive: false
  2663. });
  2664. window.addEventListener("touchstart", webViewerTouchStart, {
  2665. passive: false
  2666. });
  2667. window.addEventListener("click", webViewerClick);
  2668. window.addEventListener("keydown", webViewerKeyDown);
  2669. window.addEventListener("resize", _boundEvents.windowResize);
  2670. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  2671. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2672. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  2673. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2674. },
  2675. unbindEvents() {
  2676. const {
  2677. eventBus,
  2678. _boundEvents
  2679. } = this;
  2680. eventBus._off("resize", webViewerResize);
  2681. eventBus._off("hashchange", webViewerHashchange);
  2682. eventBus._off("beforeprint", _boundEvents.beforePrint);
  2683. eventBus._off("afterprint", _boundEvents.afterPrint);
  2684. eventBus._off("pagerendered", webViewerPageRendered);
  2685. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  2686. eventBus._off("pagechanging", webViewerPageChanging);
  2687. eventBus._off("scalechanging", webViewerScaleChanging);
  2688. eventBus._off("rotationchanging", webViewerRotationChanging);
  2689. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  2690. eventBus._off("pagemode", webViewerPageMode);
  2691. eventBus._off("namedaction", webViewerNamedAction);
  2692. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  2693. eventBus._off("presentationmode", webViewerPresentationMode);
  2694. eventBus._off("print", webViewerPrint);
  2695. eventBus._off("download", webViewerDownload);
  2696. eventBus._off("firstpage", webViewerFirstPage);
  2697. eventBus._off("lastpage", webViewerLastPage);
  2698. eventBus._off("nextpage", webViewerNextPage);
  2699. eventBus._off("previouspage", webViewerPreviousPage);
  2700. eventBus._off("zoomin", webViewerZoomIn);
  2701. eventBus._off("zoomout", webViewerZoomOut);
  2702. eventBus._off("zoomreset", webViewerZoomReset);
  2703. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  2704. eventBus._off("scalechanged", webViewerScaleChanged);
  2705. eventBus._off("rotatecw", webViewerRotateCw);
  2706. eventBus._off("rotateccw", webViewerRotateCcw);
  2707. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  2708. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  2709. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  2710. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  2711. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  2712. eventBus._off("documentproperties", webViewerDocumentProperties);
  2713. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  2714. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2715. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  2716. if (_boundEvents.reportPageStatsPDFBug) {
  2717. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2718. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2719. _boundEvents.reportPageStatsPDFBug = null;
  2720. }
  2721. eventBus._off("fileinputchange", webViewerFileInputChange);
  2722. eventBus._off("openfile", webViewerOpenFile);
  2723. _boundEvents.beforePrint = null;
  2724. _boundEvents.afterPrint = null;
  2725. },
  2726. unbindWindowEvents() {
  2727. var _boundEvents$removeWi;
  2728. const {
  2729. _boundEvents
  2730. } = this;
  2731. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  2732. window.removeEventListener("wheel", webViewerWheel, {
  2733. passive: false
  2734. });
  2735. window.removeEventListener("touchstart", webViewerTouchStart, {
  2736. passive: false
  2737. });
  2738. window.removeEventListener("click", webViewerClick);
  2739. window.removeEventListener("keydown", webViewerKeyDown);
  2740. window.removeEventListener("resize", _boundEvents.windowResize);
  2741. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  2742. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2743. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  2744. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2745. (_boundEvents$removeWi = _boundEvents.removeWindowResolutionChange) === null || _boundEvents$removeWi === void 0 ? void 0 : _boundEvents$removeWi.call(_boundEvents);
  2746. _boundEvents.windowResize = null;
  2747. _boundEvents.windowHashChange = null;
  2748. _boundEvents.windowBeforePrint = null;
  2749. _boundEvents.windowAfterPrint = null;
  2750. _boundEvents.windowUpdateFromSandbox = null;
  2751. },
  2752. accumulateWheelTicks(ticks) {
  2753. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  2754. this._wheelUnusedTicks = 0;
  2755. }
  2756. this._wheelUnusedTicks += ticks;
  2757. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  2758. this._wheelUnusedTicks -= wholeTicks;
  2759. return wholeTicks;
  2760. },
  2761. _unblockDocumentLoadEvent() {
  2762. var _document$blockUnbloc, _document;
  2763. (_document$blockUnbloc = (_document = document).blockUnblockOnload) === null || _document$blockUnbloc === void 0 ? void 0 : _document$blockUnbloc.call(_document, false);
  2764. this._unblockDocumentLoadEvent = () => {};
  2765. },
  2766. _reportDocumentStatsTelemetry() {
  2767. const {
  2768. stats
  2769. } = this.pdfDocument;
  2770. if (stats !== this._docStats) {
  2771. this._docStats = stats;
  2772. this.externalServices.reportTelemetry({
  2773. type: "documentStats",
  2774. stats
  2775. });
  2776. }
  2777. },
  2778. get scriptingReady() {
  2779. return this.pdfScriptingManager.ready;
  2780. }
  2781. };
  2782. exports.PDFViewerApplication = PDFViewerApplication;
  2783. {
  2784. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  2785. var validateFileURL = function (file) {
  2786. if (!file) {
  2787. return;
  2788. }
  2789. try {
  2790. const viewerOrigin = new URL(window.location.href).origin || "null";
  2791. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  2792. return;
  2793. }
  2794. const fileOrigin = new URL(file, window.location.href).origin;
  2795. if (fileOrigin !== viewerOrigin) {
  2796. throw new Error("file origin does not match viewer's");
  2797. }
  2798. } catch (ex) {
  2799. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2800. PDFViewerApplication._documentError(msg, {
  2801. message: ex === null || ex === void 0 ? void 0 : ex.message
  2802. });
  2803. });
  2804. throw ex;
  2805. }
  2806. };
  2807. }
  2808. async function loadFakeWorker() {
  2809. _pdfjsLib.GlobalWorkerOptions.workerSrc || (_pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc"));
  2810. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  2811. }
  2812. async function loadPDFBug(self) {
  2813. const {
  2814. debuggerScriptPath
  2815. } = self.appConfig;
  2816. const {
  2817. PDFBug
  2818. } = await import(debuggerScriptPath);
  2819. self._PDFBug = PDFBug;
  2820. }
  2821. function reportPageStatsPDFBug(_ref5) {
  2822. var _globalThis$Stats, _pageView$pdfPage;
  2823. let {
  2824. pageNumber
  2825. } = _ref5;
  2826. if (!((_globalThis$Stats = globalThis.Stats) !== null && _globalThis$Stats !== void 0 && _globalThis$Stats.enabled)) {
  2827. return;
  2828. }
  2829. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2830. globalThis.Stats.add(pageNumber, pageView === null || pageView === void 0 ? void 0 : (_pageView$pdfPage = pageView.pdfPage) === null || _pageView$pdfPage === void 0 ? void 0 : _pageView$pdfPage.stats);
  2831. }
  2832. function webViewerInitialized() {
  2833. const {
  2834. appConfig,
  2835. eventBus
  2836. } = PDFViewerApplication;
  2837. let file;
  2838. const queryString = document.location.search.substring(1);
  2839. const params = (0, _ui_utils.parseQueryString)(queryString);
  2840. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  2841. validateFileURL(file);
  2842. const fileInput = appConfig.openFileInput;
  2843. fileInput.value = null;
  2844. fileInput.addEventListener("change", function (evt) {
  2845. const {
  2846. files
  2847. } = evt.target;
  2848. if (!files || files.length === 0) {
  2849. return;
  2850. }
  2851. eventBus.dispatch("fileinputchange", {
  2852. source: this,
  2853. fileInput: evt.target
  2854. });
  2855. });
  2856. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  2857. evt.preventDefault();
  2858. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  2859. });
  2860. appConfig.mainContainer.addEventListener("drop", function (evt) {
  2861. evt.preventDefault();
  2862. const {
  2863. files
  2864. } = evt.dataTransfer;
  2865. if (!files || files.length === 0) {
  2866. return;
  2867. }
  2868. eventBus.dispatch("fileinputchange", {
  2869. source: this,
  2870. fileInput: evt.dataTransfer
  2871. });
  2872. });
  2873. if (!PDFViewerApplication.supportsDocumentFonts) {
  2874. _app_options.AppOptions.set("disableFontFace", true);
  2875. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  2876. console.warn(msg);
  2877. });
  2878. }
  2879. if (!PDFViewerApplication.supportsPrinting) {
  2880. appConfig.toolbar.print.classList.add("hidden");
  2881. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  2882. }
  2883. if (!PDFViewerApplication.supportsFullscreen) {
  2884. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  2885. }
  2886. if (PDFViewerApplication.supportsIntegratedFind) {
  2887. appConfig.toolbar.viewFind.classList.add("hidden");
  2888. }
  2889. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  2890. if (evt.target === this) {
  2891. eventBus.dispatch("resize", {
  2892. source: this
  2893. });
  2894. }
  2895. }, true);
  2896. try {
  2897. if (file) {
  2898. PDFViewerApplication.open(file);
  2899. } else {
  2900. PDFViewerApplication._hideViewBookmark();
  2901. }
  2902. } catch (reason) {
  2903. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2904. PDFViewerApplication._documentError(msg, reason);
  2905. });
  2906. }
  2907. }
  2908. function webViewerPageRendered(_ref6) {
  2909. let {
  2910. pageNumber,
  2911. error
  2912. } = _ref6;
  2913. if (pageNumber === PDFViewerApplication.page) {
  2914. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  2915. }
  2916. if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
  2917. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2918. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  2919. if (pageView && thumbnailView) {
  2920. thumbnailView.setImage(pageView);
  2921. }
  2922. }
  2923. if (error) {
  2924. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  2925. PDFViewerApplication._otherError(msg, error);
  2926. });
  2927. }
  2928. PDFViewerApplication._reportDocumentStatsTelemetry();
  2929. }
  2930. function webViewerPageMode(_ref7) {
  2931. let {
  2932. mode
  2933. } = _ref7;
  2934. let view;
  2935. switch (mode) {
  2936. case "thumbs":
  2937. view = _ui_utils.SidebarView.THUMBS;
  2938. break;
  2939. case "bookmarks":
  2940. case "outline":
  2941. view = _ui_utils.SidebarView.OUTLINE;
  2942. break;
  2943. case "attachments":
  2944. view = _ui_utils.SidebarView.ATTACHMENTS;
  2945. break;
  2946. case "layers":
  2947. view = _ui_utils.SidebarView.LAYERS;
  2948. break;
  2949. case "none":
  2950. view = _ui_utils.SidebarView.NONE;
  2951. break;
  2952. default:
  2953. console.error('Invalid "pagemode" hash parameter: ' + mode);
  2954. return;
  2955. }
  2956. PDFViewerApplication.pdfSidebar.switchView(view, true);
  2957. }
  2958. function webViewerNamedAction(evt) {
  2959. switch (evt.action) {
  2960. case "GoToPage":
  2961. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2962. break;
  2963. case "Find":
  2964. if (!PDFViewerApplication.supportsIntegratedFind) {
  2965. PDFViewerApplication.findBar.toggle();
  2966. }
  2967. break;
  2968. case "Print":
  2969. PDFViewerApplication.triggerPrinting();
  2970. break;
  2971. case "SaveAs":
  2972. PDFViewerApplication.downloadOrSave();
  2973. break;
  2974. }
  2975. }
  2976. function webViewerPresentationModeChanged(evt) {
  2977. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  2978. }
  2979. function webViewerSidebarViewChanged(_ref8) {
  2980. let {
  2981. view
  2982. } = _ref8;
  2983. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  2984. if (PDFViewerApplication.isInitialViewSet) {
  2985. var _PDFViewerApplication;
  2986. (_PDFViewerApplication = PDFViewerApplication.store) === null || _PDFViewerApplication === void 0 ? void 0 : _PDFViewerApplication.set("sidebarView", view).catch(() => {});
  2987. }
  2988. }
  2989. function webViewerUpdateViewarea(_ref9) {
  2990. let {
  2991. location
  2992. } = _ref9;
  2993. if (PDFViewerApplication.isInitialViewSet) {
  2994. var _PDFViewerApplication2;
  2995. (_PDFViewerApplication2 = PDFViewerApplication.store) === null || _PDFViewerApplication2 === void 0 ? void 0 : _PDFViewerApplication2.setMultiple({
  2996. page: location.pageNumber,
  2997. zoom: location.scale,
  2998. scrollLeft: location.left,
  2999. scrollTop: location.top,
  3000. rotation: location.rotation
  3001. }).catch(() => {});
  3002. }
  3003. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  3004. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  3005. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  3006. const loading = (currentPage === null || currentPage === void 0 ? void 0 : currentPage.renderingState) !== _ui_utils.RenderingStates.FINISHED;
  3007. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  3008. }
  3009. function webViewerScrollModeChanged(evt) {
  3010. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  3011. var _PDFViewerApplication3;
  3012. (_PDFViewerApplication3 = PDFViewerApplication.store) === null || _PDFViewerApplication3 === void 0 ? void 0 : _PDFViewerApplication3.set("scrollMode", evt.mode).catch(() => {});
  3013. }
  3014. }
  3015. function webViewerSpreadModeChanged(evt) {
  3016. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  3017. var _PDFViewerApplication4;
  3018. (_PDFViewerApplication4 = PDFViewerApplication.store) === null || _PDFViewerApplication4 === void 0 ? void 0 : _PDFViewerApplication4.set("spreadMode", evt.mode).catch(() => {});
  3019. }
  3020. }
  3021. function webViewerResize() {
  3022. const {
  3023. pdfDocument,
  3024. pdfViewer,
  3025. pdfRenderingQueue
  3026. } = PDFViewerApplication;
  3027. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  3028. return;
  3029. }
  3030. pdfViewer.updateContainerHeightCss();
  3031. if (!pdfDocument) {
  3032. return;
  3033. }
  3034. const currentScaleValue = pdfViewer.currentScaleValue;
  3035. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  3036. pdfViewer.currentScaleValue = currentScaleValue;
  3037. }
  3038. pdfViewer.update();
  3039. }
  3040. function webViewerHashchange(evt) {
  3041. var _PDFViewerApplication5;
  3042. const hash = evt.hash;
  3043. if (!hash) {
  3044. return;
  3045. }
  3046. if (!PDFViewerApplication.isInitialViewSet) {
  3047. PDFViewerApplication.initialBookmark = hash;
  3048. } else if (!((_PDFViewerApplication5 = PDFViewerApplication.pdfHistory) !== null && _PDFViewerApplication5 !== void 0 && _PDFViewerApplication5.popStateInProgress)) {
  3049. PDFViewerApplication.pdfLinkService.setHash(hash);
  3050. }
  3051. }
  3052. {
  3053. var webViewerFileInputChange = function (evt) {
  3054. var _PDFViewerApplication6;
  3055. if ((_PDFViewerApplication6 = PDFViewerApplication.pdfViewer) !== null && _PDFViewerApplication6 !== void 0 && _PDFViewerApplication6.isInPresentationMode) {
  3056. return;
  3057. }
  3058. const file = evt.fileInput.files[0];
  3059. let url = URL.createObjectURL(file);
  3060. if (file.name) {
  3061. url = {
  3062. url,
  3063. originalUrl: file.name
  3064. };
  3065. }
  3066. PDFViewerApplication.open(url);
  3067. };
  3068. var webViewerOpenFile = function (evt) {
  3069. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  3070. fileInput.click();
  3071. };
  3072. }
  3073. function webViewerPresentationMode() {
  3074. PDFViewerApplication.requestPresentationMode();
  3075. }
  3076. function webViewerSwitchAnnotationEditorMode(evt) {
  3077. PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
  3078. }
  3079. function webViewerSwitchAnnotationEditorParams(evt) {
  3080. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  3081. }
  3082. function webViewerPrint() {
  3083. PDFViewerApplication.triggerPrinting();
  3084. }
  3085. function webViewerDownload() {
  3086. PDFViewerApplication.downloadOrSave();
  3087. }
  3088. function webViewerFirstPage() {
  3089. if (PDFViewerApplication.pdfDocument) {
  3090. PDFViewerApplication.page = 1;
  3091. }
  3092. }
  3093. function webViewerLastPage() {
  3094. if (PDFViewerApplication.pdfDocument) {
  3095. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3096. }
  3097. }
  3098. function webViewerNextPage() {
  3099. PDFViewerApplication.pdfViewer.nextPage();
  3100. }
  3101. function webViewerPreviousPage() {
  3102. PDFViewerApplication.pdfViewer.previousPage();
  3103. }
  3104. function webViewerZoomIn() {
  3105. PDFViewerApplication.zoomIn();
  3106. }
  3107. function webViewerZoomOut() {
  3108. PDFViewerApplication.zoomOut();
  3109. }
  3110. function webViewerZoomReset() {
  3111. PDFViewerApplication.zoomReset();
  3112. }
  3113. function webViewerPageNumberChanged(evt) {
  3114. const pdfViewer = PDFViewerApplication.pdfViewer;
  3115. if (evt.value !== "") {
  3116. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  3117. }
  3118. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  3119. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  3120. }
  3121. }
  3122. function webViewerScaleChanged(evt) {
  3123. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  3124. }
  3125. function webViewerRotateCw() {
  3126. PDFViewerApplication.rotatePages(90);
  3127. }
  3128. function webViewerRotateCcw() {
  3129. PDFViewerApplication.rotatePages(-90);
  3130. }
  3131. function webViewerOptionalContentConfig(evt) {
  3132. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  3133. }
  3134. function webViewerSwitchScrollMode(evt) {
  3135. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  3136. }
  3137. function webViewerSwitchSpreadMode(evt) {
  3138. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  3139. }
  3140. function webViewerDocumentProperties() {
  3141. PDFViewerApplication.pdfDocumentProperties.open();
  3142. }
  3143. function webViewerFindFromUrlHash(evt) {
  3144. PDFViewerApplication.eventBus.dispatch("find", {
  3145. source: evt.source,
  3146. type: "",
  3147. query: evt.query,
  3148. phraseSearch: evt.phraseSearch,
  3149. caseSensitive: false,
  3150. entireWord: false,
  3151. highlightAll: true,
  3152. findPrevious: false,
  3153. matchDiacritics: true
  3154. });
  3155. }
  3156. function webViewerUpdateFindMatchesCount(_ref10) {
  3157. let {
  3158. matchesCount
  3159. } = _ref10;
  3160. if (PDFViewerApplication.supportsIntegratedFind) {
  3161. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  3162. } else {
  3163. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  3164. }
  3165. }
  3166. function webViewerUpdateFindControlState(_ref11) {
  3167. let {
  3168. state,
  3169. previous,
  3170. matchesCount,
  3171. rawQuery
  3172. } = _ref11;
  3173. if (PDFViewerApplication.supportsIntegratedFind) {
  3174. PDFViewerApplication.externalServices.updateFindControlState({
  3175. result: state,
  3176. findPrevious: previous,
  3177. matchesCount,
  3178. rawQuery
  3179. });
  3180. } else {
  3181. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  3182. }
  3183. }
  3184. function webViewerScaleChanging(evt) {
  3185. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  3186. PDFViewerApplication.pdfViewer.update();
  3187. }
  3188. function webViewerRotationChanging(evt) {
  3189. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  3190. PDFViewerApplication.forceRendering();
  3191. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  3192. }
  3193. function webViewerPageChanging(_ref12) {
  3194. let {
  3195. pageNumber,
  3196. pageLabel
  3197. } = _ref12;
  3198. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  3199. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  3200. if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
  3201. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  3202. }
  3203. }
  3204. function webViewerResolutionChange(evt) {
  3205. PDFViewerApplication.pdfViewer.refresh();
  3206. }
  3207. function webViewerVisibilityChange(evt) {
  3208. if (document.visibilityState === "visible") {
  3209. setZoomDisabledTimeout();
  3210. }
  3211. }
  3212. let zoomDisabledTimeout = null;
  3213. function setZoomDisabledTimeout() {
  3214. if (zoomDisabledTimeout) {
  3215. clearTimeout(zoomDisabledTimeout);
  3216. }
  3217. zoomDisabledTimeout = setTimeout(function () {
  3218. zoomDisabledTimeout = null;
  3219. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  3220. }
  3221. function webViewerWheel(evt) {
  3222. const {
  3223. pdfViewer,
  3224. supportedMouseWheelZoomModifierKeys
  3225. } = PDFViewerApplication;
  3226. if (pdfViewer.isInPresentationMode) {
  3227. return;
  3228. }
  3229. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  3230. evt.preventDefault();
  3231. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  3232. return;
  3233. }
  3234. const deltaMode = evt.deltaMode;
  3235. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  3236. const previousScale = pdfViewer.currentScale;
  3237. let ticks = 0;
  3238. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  3239. if (Math.abs(delta) >= 1) {
  3240. ticks = Math.sign(delta);
  3241. } else {
  3242. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  3243. }
  3244. } else {
  3245. const PIXELS_PER_LINE_SCALE = 30;
  3246. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  3247. }
  3248. if (ticks < 0) {
  3249. PDFViewerApplication.zoomOut(-ticks);
  3250. } else if (ticks > 0) {
  3251. PDFViewerApplication.zoomIn(ticks);
  3252. }
  3253. const currentScale = pdfViewer.currentScale;
  3254. if (previousScale !== currentScale) {
  3255. const scaleCorrectionFactor = currentScale / previousScale - 1;
  3256. const rect = pdfViewer.container.getBoundingClientRect();
  3257. const dx = evt.clientX - rect.left;
  3258. const dy = evt.clientY - rect.top;
  3259. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  3260. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  3261. }
  3262. } else {
  3263. setZoomDisabledTimeout();
  3264. }
  3265. }
  3266. function webViewerTouchStart(evt) {
  3267. if (evt.touches.length > 1) {
  3268. evt.preventDefault();
  3269. }
  3270. }
  3271. function webViewerClick(evt) {
  3272. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  3273. return;
  3274. }
  3275. const appConfig = PDFViewerApplication.appConfig;
  3276. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  3277. PDFViewerApplication.secondaryToolbar.close();
  3278. }
  3279. }
  3280. function webViewerKeyDown(evt) {
  3281. if (PDFViewerApplication.overlayManager.active) {
  3282. return;
  3283. }
  3284. const {
  3285. eventBus,
  3286. pdfViewer
  3287. } = PDFViewerApplication;
  3288. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  3289. let handled = false,
  3290. ensureViewerFocused = false;
  3291. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  3292. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  3293. switch (evt.keyCode) {
  3294. case 70:
  3295. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  3296. PDFViewerApplication.findBar.open();
  3297. handled = true;
  3298. }
  3299. break;
  3300. case 71:
  3301. if (!PDFViewerApplication.supportsIntegratedFind) {
  3302. const {
  3303. state
  3304. } = PDFViewerApplication.findController;
  3305. if (state) {
  3306. const eventState = Object.assign(Object.create(null), state, {
  3307. source: window,
  3308. type: "again",
  3309. findPrevious: cmd === 5 || cmd === 12
  3310. });
  3311. eventBus.dispatch("find", eventState);
  3312. }
  3313. handled = true;
  3314. }
  3315. break;
  3316. case 61:
  3317. case 107:
  3318. case 187:
  3319. case 171:
  3320. if (!isViewerInPresentationMode) {
  3321. PDFViewerApplication.zoomIn();
  3322. }
  3323. handled = true;
  3324. break;
  3325. case 173:
  3326. case 109:
  3327. case 189:
  3328. if (!isViewerInPresentationMode) {
  3329. PDFViewerApplication.zoomOut();
  3330. }
  3331. handled = true;
  3332. break;
  3333. case 48:
  3334. case 96:
  3335. if (!isViewerInPresentationMode) {
  3336. setTimeout(function () {
  3337. PDFViewerApplication.zoomReset();
  3338. });
  3339. handled = false;
  3340. }
  3341. break;
  3342. case 38:
  3343. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3344. PDFViewerApplication.page = 1;
  3345. handled = true;
  3346. ensureViewerFocused = true;
  3347. }
  3348. break;
  3349. case 40:
  3350. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3351. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3352. handled = true;
  3353. ensureViewerFocused = true;
  3354. }
  3355. break;
  3356. }
  3357. }
  3358. if (cmd === 1 || cmd === 8) {
  3359. switch (evt.keyCode) {
  3360. case 83:
  3361. eventBus.dispatch("download", {
  3362. source: window
  3363. });
  3364. handled = true;
  3365. break;
  3366. case 79:
  3367. {
  3368. eventBus.dispatch("openfile", {
  3369. source: window
  3370. });
  3371. handled = true;
  3372. }
  3373. break;
  3374. }
  3375. }
  3376. if (cmd === 3 || cmd === 10) {
  3377. switch (evt.keyCode) {
  3378. case 80:
  3379. PDFViewerApplication.requestPresentationMode();
  3380. handled = true;
  3381. PDFViewerApplication.externalServices.reportTelemetry({
  3382. type: "buttons",
  3383. data: {
  3384. id: "presentationModeKeyboard"
  3385. }
  3386. });
  3387. break;
  3388. case 71:
  3389. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  3390. handled = true;
  3391. break;
  3392. }
  3393. }
  3394. if (handled) {
  3395. if (ensureViewerFocused && !isViewerInPresentationMode) {
  3396. pdfViewer.focus();
  3397. }
  3398. evt.preventDefault();
  3399. return;
  3400. }
  3401. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  3402. const curElementTagName = curElement === null || curElement === void 0 ? void 0 : curElement.tagName.toUpperCase();
  3403. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement !== null && curElement !== void 0 && curElement.isContentEditable) {
  3404. if (evt.keyCode !== 27) {
  3405. return;
  3406. }
  3407. }
  3408. if (cmd === 0) {
  3409. let turnPage = 0,
  3410. turnOnlyIfPageFit = false;
  3411. switch (evt.keyCode) {
  3412. case 38:
  3413. case 33:
  3414. if (pdfViewer.isVerticalScrollbarEnabled) {
  3415. turnOnlyIfPageFit = true;
  3416. }
  3417. turnPage = -1;
  3418. break;
  3419. case 8:
  3420. if (!isViewerInPresentationMode) {
  3421. turnOnlyIfPageFit = true;
  3422. }
  3423. turnPage = -1;
  3424. break;
  3425. case 37:
  3426. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3427. turnOnlyIfPageFit = true;
  3428. }
  3429. case 75:
  3430. case 80:
  3431. turnPage = -1;
  3432. break;
  3433. case 27:
  3434. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  3435. PDFViewerApplication.secondaryToolbar.close();
  3436. handled = true;
  3437. }
  3438. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  3439. PDFViewerApplication.findBar.close();
  3440. handled = true;
  3441. }
  3442. break;
  3443. case 40:
  3444. case 34:
  3445. if (pdfViewer.isVerticalScrollbarEnabled) {
  3446. turnOnlyIfPageFit = true;
  3447. }
  3448. turnPage = 1;
  3449. break;
  3450. case 13:
  3451. case 32:
  3452. if (!isViewerInPresentationMode) {
  3453. turnOnlyIfPageFit = true;
  3454. }
  3455. turnPage = 1;
  3456. break;
  3457. case 39:
  3458. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3459. turnOnlyIfPageFit = true;
  3460. }
  3461. case 74:
  3462. case 78:
  3463. turnPage = 1;
  3464. break;
  3465. case 36:
  3466. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3467. PDFViewerApplication.page = 1;
  3468. handled = true;
  3469. ensureViewerFocused = true;
  3470. }
  3471. break;
  3472. case 35:
  3473. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3474. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3475. handled = true;
  3476. ensureViewerFocused = true;
  3477. }
  3478. break;
  3479. case 83:
  3480. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  3481. break;
  3482. case 72:
  3483. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  3484. break;
  3485. case 82:
  3486. PDFViewerApplication.rotatePages(90);
  3487. break;
  3488. case 115:
  3489. PDFViewerApplication.pdfSidebar.toggle();
  3490. break;
  3491. }
  3492. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  3493. if (turnPage > 0) {
  3494. pdfViewer.nextPage();
  3495. } else {
  3496. pdfViewer.previousPage();
  3497. }
  3498. handled = true;
  3499. }
  3500. }
  3501. if (cmd === 4) {
  3502. switch (evt.keyCode) {
  3503. case 13:
  3504. case 32:
  3505. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  3506. break;
  3507. }
  3508. pdfViewer.previousPage();
  3509. handled = true;
  3510. break;
  3511. case 82:
  3512. PDFViewerApplication.rotatePages(-90);
  3513. break;
  3514. }
  3515. }
  3516. if (!handled && !isViewerInPresentationMode) {
  3517. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  3518. ensureViewerFocused = true;
  3519. }
  3520. }
  3521. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  3522. pdfViewer.focus();
  3523. }
  3524. if (handled) {
  3525. evt.preventDefault();
  3526. }
  3527. }
  3528. function beforeUnload(evt) {
  3529. evt.preventDefault();
  3530. evt.returnValue = "";
  3531. return false;
  3532. }
  3533. function webViewerAnnotationEditorStatesChanged(data) {
  3534. PDFViewerApplication.externalServices.updateEditorStates(data);
  3535. }
  3536. const PDFPrintServiceFactory = {
  3537. instance: {
  3538. supportsPrinting: false,
  3539. createPrintService() {
  3540. throw new Error("Not implemented: createPrintService");
  3541. }
  3542. }
  3543. };
  3544. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  3545. /***/ }),
  3546. /* 5 */
  3547. /***/ ((module) => {
  3548. let pdfjsLib;
  3549. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3550. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3551. } else {
  3552. pdfjsLib = require("../build/pdf.js");
  3553. }
  3554. module.exports = pdfjsLib;
  3555. /***/ }),
  3556. /* 6 */
  3557. /***/ ((__unused_webpack_module, exports) => {
  3558. Object.defineProperty(exports, "__esModule", ({
  3559. value: true
  3560. }));
  3561. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3562. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3563. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  3564. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  3565. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  3566. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  3567. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  3568. const WaitOnType = {
  3569. EVENT: "event",
  3570. TIMEOUT: "timeout"
  3571. };
  3572. exports.WaitOnType = WaitOnType;
  3573. function waitOnEventOrTimeout(_ref) {
  3574. let {
  3575. target,
  3576. name,
  3577. delay = 0
  3578. } = _ref;
  3579. return new Promise(function (resolve, reject) {
  3580. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3581. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3582. }
  3583. function handler(type) {
  3584. if (target instanceof EventBus) {
  3585. target._off(name, eventHandler);
  3586. } else {
  3587. target.removeEventListener(name, eventHandler);
  3588. }
  3589. if (timeout) {
  3590. clearTimeout(timeout);
  3591. }
  3592. resolve(type);
  3593. }
  3594. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3595. if (target instanceof EventBus) {
  3596. target._on(name, eventHandler);
  3597. } else {
  3598. target.addEventListener(name, eventHandler);
  3599. }
  3600. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3601. const timeout = setTimeout(timeoutHandler, delay);
  3602. });
  3603. }
  3604. var _listeners = /*#__PURE__*/new WeakMap();
  3605. class EventBus {
  3606. constructor() {
  3607. _classPrivateFieldInitSpec(this, _listeners, {
  3608. writable: true,
  3609. value: Object.create(null)
  3610. });
  3611. }
  3612. on(eventName, listener) {
  3613. let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  3614. this._on(eventName, listener, {
  3615. external: true,
  3616. once: options === null || options === void 0 ? void 0 : options.once
  3617. });
  3618. }
  3619. off(eventName, listener) {
  3620. let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  3621. this._off(eventName, listener, {
  3622. external: true,
  3623. once: options === null || options === void 0 ? void 0 : options.once
  3624. });
  3625. }
  3626. dispatch(eventName, data) {
  3627. const eventListeners = _classPrivateFieldGet(this, _listeners)[eventName];
  3628. if (!eventListeners || eventListeners.length === 0) {
  3629. return;
  3630. }
  3631. let externalListeners;
  3632. for (const {
  3633. listener,
  3634. external,
  3635. once
  3636. } of eventListeners.slice(0)) {
  3637. if (once) {
  3638. this._off(eventName, listener);
  3639. }
  3640. if (external) {
  3641. (externalListeners || (externalListeners = [])).push(listener);
  3642. continue;
  3643. }
  3644. listener(data);
  3645. }
  3646. if (externalListeners) {
  3647. for (const listener of externalListeners) {
  3648. listener(data);
  3649. }
  3650. externalListeners = null;
  3651. }
  3652. }
  3653. _on(eventName, listener) {
  3654. var _classPrivateFieldGet2;
  3655. let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  3656. const eventListeners = (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _listeners))[eventName] || (_classPrivateFieldGet2[eventName] = []);
  3657. eventListeners.push({
  3658. listener,
  3659. external: (options === null || options === void 0 ? void 0 : options.external) === true,
  3660. once: (options === null || options === void 0 ? void 0 : options.once) === true
  3661. });
  3662. }
  3663. _off(eventName, listener) {
  3664. let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  3665. const eventListeners = _classPrivateFieldGet(this, _listeners)[eventName];
  3666. if (!eventListeners) {
  3667. return;
  3668. }
  3669. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3670. if (eventListeners[i].listener === listener) {
  3671. eventListeners.splice(i, 1);
  3672. return;
  3673. }
  3674. }
  3675. }
  3676. }
  3677. exports.EventBus = EventBus;
  3678. class AutomationEventBus extends EventBus {
  3679. dispatch(eventName, data) {
  3680. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3681. }
  3682. }
  3683. exports.AutomationEventBus = AutomationEventBus;
  3684. /***/ }),
  3685. /* 7 */
  3686. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3687. Object.defineProperty(exports, "__esModule", ({
  3688. value: true
  3689. }));
  3690. exports.PDFCursorTools = exports.CursorTool = void 0;
  3691. var _pdfjsLib = __webpack_require__(5);
  3692. var _grab_to_pan = __webpack_require__(8);
  3693. var _ui_utils = __webpack_require__(1);
  3694. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  3695. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  3696. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  3697. const CursorTool = {
  3698. SELECT: 0,
  3699. HAND: 1,
  3700. ZOOM: 2
  3701. };
  3702. exports.CursorTool = CursorTool;
  3703. var _dispatchEvent = /*#__PURE__*/new WeakSet();
  3704. var _addEventListeners = /*#__PURE__*/new WeakSet();
  3705. class PDFCursorTools {
  3706. constructor(_ref) {
  3707. let {
  3708. container,
  3709. eventBus,
  3710. cursorToolOnLoad = CursorTool.SELECT
  3711. } = _ref;
  3712. _classPrivateMethodInitSpec(this, _addEventListeners);
  3713. _classPrivateMethodInitSpec(this, _dispatchEvent);
  3714. this.container = container;
  3715. this.eventBus = eventBus;
  3716. this.active = CursorTool.SELECT;
  3717. this.previouslyActive = null;
  3718. this.handTool = new _grab_to_pan.GrabToPan({
  3719. element: this.container
  3720. });
  3721. _classPrivateMethodGet(this, _addEventListeners, _addEventListeners2).call(this);
  3722. Promise.resolve().then(() => {
  3723. this.switchTool(cursorToolOnLoad);
  3724. });
  3725. }
  3726. get activeTool() {
  3727. return this.active;
  3728. }
  3729. switchTool(tool) {
  3730. if (this.previouslyActive !== null) {
  3731. return;
  3732. }
  3733. if (tool === this.active) {
  3734. return;
  3735. }
  3736. const disableActiveTool = () => {
  3737. switch (this.active) {
  3738. case CursorTool.SELECT:
  3739. break;
  3740. case CursorTool.HAND:
  3741. this.handTool.deactivate();
  3742. break;
  3743. case CursorTool.ZOOM:
  3744. }
  3745. };
  3746. switch (tool) {
  3747. case CursorTool.SELECT:
  3748. disableActiveTool();
  3749. break;
  3750. case CursorTool.HAND:
  3751. disableActiveTool();
  3752. this.handTool.activate();
  3753. break;
  3754. case CursorTool.ZOOM:
  3755. default:
  3756. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3757. return;
  3758. }
  3759. this.active = tool;
  3760. _classPrivateMethodGet(this, _dispatchEvent, _dispatchEvent2).call(this);
  3761. }
  3762. }
  3763. exports.PDFCursorTools = PDFCursorTools;
  3764. function _dispatchEvent2() {
  3765. this.eventBus.dispatch("cursortoolchanged", {
  3766. source: this,
  3767. tool: this.active
  3768. });
  3769. }
  3770. function _addEventListeners2() {
  3771. this.eventBus._on("switchcursortool", evt => {
  3772. this.switchTool(evt.tool);
  3773. });
  3774. let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
  3775. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  3776. const disableActive = () => {
  3777. const previouslyActive = this.active;
  3778. this.switchTool(CursorTool.SELECT);
  3779. this.previouslyActive ?? (this.previouslyActive = previouslyActive);
  3780. };
  3781. const enableActive = () => {
  3782. const previouslyActive = this.previouslyActive;
  3783. if (previouslyActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) {
  3784. this.previouslyActive = null;
  3785. this.switchTool(previouslyActive);
  3786. }
  3787. };
  3788. this.eventBus._on("secondarytoolbarreset", evt => {
  3789. if (this.previouslyActive !== null) {
  3790. annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  3791. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  3792. enableActive();
  3793. }
  3794. });
  3795. this.eventBus._on("annotationeditormodechanged", _ref2 => {
  3796. let {
  3797. mode
  3798. } = _ref2;
  3799. annotationEditorMode = mode;
  3800. if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
  3801. enableActive();
  3802. } else {
  3803. disableActive();
  3804. }
  3805. });
  3806. this.eventBus._on("presentationmodechanged", _ref3 => {
  3807. let {
  3808. state
  3809. } = _ref3;
  3810. presentationModeState = state;
  3811. if (state === _ui_utils.PresentationModeState.NORMAL) {
  3812. enableActive();
  3813. } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
  3814. disableActive();
  3815. }
  3816. });
  3817. }
  3818. /***/ }),
  3819. /* 8 */
  3820. /***/ ((__unused_webpack_module, exports) => {
  3821. Object.defineProperty(exports, "__esModule", ({
  3822. value: true
  3823. }));
  3824. exports.GrabToPan = void 0;
  3825. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  3826. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  3827. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  3828. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3829. var _onMouseDown = /*#__PURE__*/new WeakSet();
  3830. var _onMouseMove = /*#__PURE__*/new WeakSet();
  3831. var _endPan = /*#__PURE__*/new WeakSet();
  3832. class GrabToPan {
  3833. constructor(options) {
  3834. _classPrivateMethodInitSpec(this, _endPan);
  3835. _classPrivateMethodInitSpec(this, _onMouseMove);
  3836. _classPrivateMethodInitSpec(this, _onMouseDown);
  3837. this.element = options.element;
  3838. this.document = options.element.ownerDocument;
  3839. if (typeof options.ignoreTarget === "function") {
  3840. this.ignoreTarget = options.ignoreTarget;
  3841. }
  3842. this.onActiveChanged = options.onActiveChanged;
  3843. this.activate = this.activate.bind(this);
  3844. this.deactivate = this.deactivate.bind(this);
  3845. this.toggle = this.toggle.bind(this);
  3846. this._onMouseDown = _classPrivateMethodGet(this, _onMouseDown, _onMouseDown2).bind(this);
  3847. this._onMouseMove = _classPrivateMethodGet(this, _onMouseMove, _onMouseMove2).bind(this);
  3848. this._endPan = _classPrivateMethodGet(this, _endPan, _endPan2).bind(this);
  3849. const overlay = this.overlay = document.createElement("div");
  3850. overlay.className = "grab-to-pan-grabbing";
  3851. }
  3852. activate() {
  3853. if (!this.active) {
  3854. var _this$onActiveChanged;
  3855. this.active = true;
  3856. this.element.addEventListener("mousedown", this._onMouseDown, true);
  3857. this.element.classList.add(CSS_CLASS_GRAB);
  3858. (_this$onActiveChanged = this.onActiveChanged) === null || _this$onActiveChanged === void 0 ? void 0 : _this$onActiveChanged.call(this, true);
  3859. }
  3860. }
  3861. deactivate() {
  3862. if (this.active) {
  3863. var _this$onActiveChanged2;
  3864. this.active = false;
  3865. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  3866. this._endPan();
  3867. this.element.classList.remove(CSS_CLASS_GRAB);
  3868. (_this$onActiveChanged2 = this.onActiveChanged) === null || _this$onActiveChanged2 === void 0 ? void 0 : _this$onActiveChanged2.call(this, false);
  3869. }
  3870. }
  3871. toggle() {
  3872. if (this.active) {
  3873. this.deactivate();
  3874. } else {
  3875. this.activate();
  3876. }
  3877. }
  3878. ignoreTarget(node) {
  3879. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3880. }
  3881. }
  3882. exports.GrabToPan = GrabToPan;
  3883. function _onMouseDown2(event) {
  3884. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3885. return;
  3886. }
  3887. if (event.originalTarget) {
  3888. try {
  3889. event.originalTarget.tagName;
  3890. } catch (e) {
  3891. return;
  3892. }
  3893. }
  3894. this.scrollLeftStart = this.element.scrollLeft;
  3895. this.scrollTopStart = this.element.scrollTop;
  3896. this.clientXStart = event.clientX;
  3897. this.clientYStart = event.clientY;
  3898. this.document.addEventListener("mousemove", this._onMouseMove, true);
  3899. this.document.addEventListener("mouseup", this._endPan, true);
  3900. this.element.addEventListener("scroll", this._endPan, true);
  3901. event.preventDefault();
  3902. event.stopPropagation();
  3903. const focusedElement = document.activeElement;
  3904. if (focusedElement && !focusedElement.contains(event.target)) {
  3905. focusedElement.blur();
  3906. }
  3907. }
  3908. function _onMouseMove2(event) {
  3909. this.element.removeEventListener("scroll", this._endPan, true);
  3910. if (!(event.buttons & 1)) {
  3911. this._endPan();
  3912. return;
  3913. }
  3914. const xDiff = event.clientX - this.clientXStart;
  3915. const yDiff = event.clientY - this.clientYStart;
  3916. const scrollTop = this.scrollTopStart - yDiff;
  3917. const scrollLeft = this.scrollLeftStart - xDiff;
  3918. if (this.element.scrollTo) {
  3919. this.element.scrollTo({
  3920. top: scrollTop,
  3921. left: scrollLeft,
  3922. behavior: "instant"
  3923. });
  3924. } else {
  3925. this.element.scrollTop = scrollTop;
  3926. this.element.scrollLeft = scrollLeft;
  3927. }
  3928. if (!this.overlay.parentNode) {
  3929. document.body.append(this.overlay);
  3930. }
  3931. }
  3932. function _endPan2() {
  3933. this.element.removeEventListener("scroll", this._endPan, true);
  3934. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  3935. this.document.removeEventListener("mouseup", this._endPan, true);
  3936. this.overlay.remove();
  3937. }
  3938. /***/ }),
  3939. /* 9 */
  3940. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3941. Object.defineProperty(exports, "__esModule", ({
  3942. value: true
  3943. }));
  3944. exports.AnnotationEditorParams = void 0;
  3945. var _pdfjsLib = __webpack_require__(5);
  3946. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  3947. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  3948. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  3949. var _bindListeners = /*#__PURE__*/new WeakSet();
  3950. class AnnotationEditorParams {
  3951. constructor(options, eventBus) {
  3952. _classPrivateMethodInitSpec(this, _bindListeners);
  3953. this.eventBus = eventBus;
  3954. _classPrivateMethodGet(this, _bindListeners, _bindListeners2).call(this, options);
  3955. }
  3956. }
  3957. exports.AnnotationEditorParams = AnnotationEditorParams;
  3958. function _bindListeners2(_ref) {
  3959. let {
  3960. editorFreeTextFontSize,
  3961. editorFreeTextColor,
  3962. editorInkColor,
  3963. editorInkThickness,
  3964. editorInkOpacity
  3965. } = _ref;
  3966. editorFreeTextFontSize.addEventListener("input", evt => {
  3967. this.eventBus.dispatch("switchannotationeditorparams", {
  3968. source: this,
  3969. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE,
  3970. value: editorFreeTextFontSize.valueAsNumber
  3971. });
  3972. });
  3973. editorFreeTextColor.addEventListener("input", evt => {
  3974. this.eventBus.dispatch("switchannotationeditorparams", {
  3975. source: this,
  3976. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR,
  3977. value: editorFreeTextColor.value
  3978. });
  3979. });
  3980. editorInkColor.addEventListener("input", evt => {
  3981. this.eventBus.dispatch("switchannotationeditorparams", {
  3982. source: this,
  3983. type: _pdfjsLib.AnnotationEditorParamsType.INK_COLOR,
  3984. value: editorInkColor.value
  3985. });
  3986. });
  3987. editorInkThickness.addEventListener("input", evt => {
  3988. this.eventBus.dispatch("switchannotationeditorparams", {
  3989. source: this,
  3990. type: _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS,
  3991. value: editorInkThickness.valueAsNumber
  3992. });
  3993. });
  3994. editorInkOpacity.addEventListener("input", evt => {
  3995. this.eventBus.dispatch("switchannotationeditorparams", {
  3996. source: this,
  3997. type: _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY,
  3998. value: editorInkOpacity.valueAsNumber
  3999. });
  4000. });
  4001. this.eventBus._on("annotationeditorparamschanged", evt => {
  4002. for (const [type, value] of evt.details) {
  4003. switch (type) {
  4004. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  4005. editorFreeTextFontSize.value = value;
  4006. break;
  4007. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  4008. editorFreeTextColor.value = value;
  4009. break;
  4010. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  4011. editorInkColor.value = value;
  4012. break;
  4013. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  4014. editorInkThickness.value = value;
  4015. break;
  4016. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  4017. editorInkOpacity.value = value;
  4018. break;
  4019. }
  4020. }
  4021. });
  4022. }
  4023. /***/ }),
  4024. /* 10 */
  4025. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4026. Object.defineProperty(exports, "__esModule", ({
  4027. value: true
  4028. }));
  4029. exports.OverlayManager = void 0;
  4030. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  4031. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  4032. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  4033. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  4034. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  4035. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  4036. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  4037. var _overlays = /*#__PURE__*/new WeakMap();
  4038. var _active = /*#__PURE__*/new WeakMap();
  4039. class OverlayManager {
  4040. constructor() {
  4041. _classPrivateFieldInitSpec(this, _overlays, {
  4042. writable: true,
  4043. value: new WeakMap()
  4044. });
  4045. _classPrivateFieldInitSpec(this, _active, {
  4046. writable: true,
  4047. value: null
  4048. });
  4049. }
  4050. get active() {
  4051. return _classPrivateFieldGet(this, _active);
  4052. }
  4053. async register(dialog) {
  4054. let canForceClose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  4055. if (typeof dialog !== "object") {
  4056. throw new Error("Not enough parameters.");
  4057. } else if (_classPrivateFieldGet(this, _overlays).has(dialog)) {
  4058. throw new Error("The overlay is already registered.");
  4059. }
  4060. _classPrivateFieldGet(this, _overlays).set(dialog, {
  4061. canForceClose
  4062. });
  4063. if (!dialog.showModal) {
  4064. const dialogPolyfill = __webpack_require__(11);
  4065. dialogPolyfill.registerDialog(dialog);
  4066. if (!this._dialogPolyfillCSS) {
  4067. this._dialogPolyfillCSS = true;
  4068. const style = document.createElement("style");
  4069. style.textContent = 'dialog {\n position: absolute;\n left: 0; right: 0;\n width: -moz-fit-content;\n width: -webkit-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: -webkit-fit-content;\n height: fit-content;\n margin: auto;\n border: solid;\n padding: 1em;\n background: white;\n color: black;\n display: block;\n}\n\ndialog:not([open]) {\n display: none;\n}\n\ndialog + .backdrop {\n position: fixed;\n top: 0; right: 0; bottom: 0; left: 0;\n background: rgba(0,0,0,0.1);\n}\n\n._dialog_overlay {\n position: fixed;\n top: 0; right: 0; bottom: 0; left: 0;\n}\n\ndialog.fixed {\n position: fixed;\n top: 50%;\n transform: translate(0, -50%);\n}';
  4070. document.head.prepend(style);
  4071. }
  4072. }
  4073. dialog.addEventListener("cancel", evt => {
  4074. _classPrivateFieldSet(this, _active, null);
  4075. });
  4076. }
  4077. async unregister(dialog) {
  4078. if (!_classPrivateFieldGet(this, _overlays).has(dialog)) {
  4079. throw new Error("The overlay does not exist.");
  4080. } else if (_classPrivateFieldGet(this, _active) === dialog) {
  4081. throw new Error("The overlay cannot be removed while it is active.");
  4082. }
  4083. _classPrivateFieldGet(this, _overlays).delete(dialog);
  4084. }
  4085. async open(dialog) {
  4086. if (!_classPrivateFieldGet(this, _overlays).has(dialog)) {
  4087. throw new Error("The overlay does not exist.");
  4088. } else if (_classPrivateFieldGet(this, _active)) {
  4089. if (_classPrivateFieldGet(this, _active) === dialog) {
  4090. throw new Error("The overlay is already active.");
  4091. } else if (_classPrivateFieldGet(this, _overlays).get(dialog).canForceClose) {
  4092. await this.close();
  4093. } else {
  4094. throw new Error("Another overlay is currently active.");
  4095. }
  4096. }
  4097. _classPrivateFieldSet(this, _active, dialog);
  4098. dialog.showModal();
  4099. }
  4100. async close() {
  4101. let dialog = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _classPrivateFieldGet(this, _active);
  4102. if (!_classPrivateFieldGet(this, _overlays).has(dialog)) {
  4103. throw new Error("The overlay does not exist.");
  4104. } else if (!_classPrivateFieldGet(this, _active)) {
  4105. throw new Error("The overlay is currently not active.");
  4106. } else if (_classPrivateFieldGet(this, _active) !== dialog) {
  4107. throw new Error("Another overlay is currently active.");
  4108. }
  4109. dialog.close();
  4110. _classPrivateFieldSet(this, _active, null);
  4111. }
  4112. }
  4113. exports.OverlayManager = OverlayManager;
  4114. /***/ }),
  4115. /* 11 */
  4116. /***/ ((module) => {
  4117. (function (global, factory) {
  4118. true ? module.exports = factory() : 0;
  4119. })(void 0, function () {
  4120. 'use strict';
  4121. var supportCustomEvent = window.CustomEvent;
  4122. if (!supportCustomEvent || typeof supportCustomEvent === 'object') {
  4123. supportCustomEvent = function CustomEvent(event, x) {
  4124. x = x || {};
  4125. var ev = document.createEvent('CustomEvent');
  4126. ev.initCustomEvent(event, !!x.bubbles, !!x.cancelable, x.detail || null);
  4127. return ev;
  4128. };
  4129. supportCustomEvent.prototype = window.Event.prototype;
  4130. }
  4131. function safeDispatchEvent(target, event) {
  4132. var check = 'on' + event.type.toLowerCase();
  4133. if (typeof target[check] === 'function') {
  4134. target[check](event);
  4135. }
  4136. return target.dispatchEvent(event);
  4137. }
  4138. function createsStackingContext(el) {
  4139. while (el && el !== document.body) {
  4140. var s = window.getComputedStyle(el);
  4141. var invalid = function (k, ok) {
  4142. return !(s[k] === undefined || s[k] === ok);
  4143. };
  4144. if (s.opacity < 1 || invalid('zIndex', 'auto') || invalid('transform', 'none') || invalid('mixBlendMode', 'normal') || invalid('filter', 'none') || invalid('perspective', 'none') || s['isolation'] === 'isolate' || s.position === 'fixed' || s.webkitOverflowScrolling === 'touch') {
  4145. return true;
  4146. }
  4147. el = el.parentElement;
  4148. }
  4149. return false;
  4150. }
  4151. function findNearestDialog(el) {
  4152. while (el) {
  4153. if (el.localName === 'dialog') {
  4154. return el;
  4155. }
  4156. if (el.parentElement) {
  4157. el = el.parentElement;
  4158. } else if (el.parentNode) {
  4159. el = el.parentNode.host;
  4160. } else {
  4161. el = null;
  4162. }
  4163. }
  4164. return null;
  4165. }
  4166. function safeBlur(el) {
  4167. while (el && el.shadowRoot && el.shadowRoot.activeElement) {
  4168. el = el.shadowRoot.activeElement;
  4169. }
  4170. if (el && el.blur && el !== document.body) {
  4171. el.blur();
  4172. }
  4173. }
  4174. function inNodeList(nodeList, node) {
  4175. for (var i = 0; i < nodeList.length; ++i) {
  4176. if (nodeList[i] === node) {
  4177. return true;
  4178. }
  4179. }
  4180. return false;
  4181. }
  4182. function isFormMethodDialog(el) {
  4183. if (!el || !el.hasAttribute('method')) {
  4184. return false;
  4185. }
  4186. return el.getAttribute('method').toLowerCase() === 'dialog';
  4187. }
  4188. function findFocusableElementWithin(hostElement) {
  4189. var opts = ['button', 'input', 'keygen', 'select', 'textarea'];
  4190. var query = opts.map(function (el) {
  4191. return el + ':not([disabled])';
  4192. });
  4193. query.push('[tabindex]:not([disabled]):not([tabindex=""])');
  4194. var target = hostElement.querySelector(query.join(', '));
  4195. if (!target && 'attachShadow' in Element.prototype) {
  4196. var elems = hostElement.querySelectorAll('*');
  4197. for (var i = 0; i < elems.length; i++) {
  4198. if (elems[i].tagName && elems[i].shadowRoot) {
  4199. target = findFocusableElementWithin(elems[i].shadowRoot);
  4200. if (target) {
  4201. break;
  4202. }
  4203. }
  4204. }
  4205. }
  4206. return target;
  4207. }
  4208. function isConnected(element) {
  4209. return element.isConnected || document.body.contains(element);
  4210. }
  4211. function findFormSubmitter(event) {
  4212. if (event.submitter) {
  4213. return event.submitter;
  4214. }
  4215. var form = event.target;
  4216. if (!(form instanceof HTMLFormElement)) {
  4217. return null;
  4218. }
  4219. var submitter = dialogPolyfill.formSubmitter;
  4220. if (!submitter) {
  4221. var target = event.target;
  4222. var root = 'getRootNode' in target && target.getRootNode() || document;
  4223. submitter = root.activeElement;
  4224. }
  4225. if (!submitter || submitter.form !== form) {
  4226. return null;
  4227. }
  4228. return submitter;
  4229. }
  4230. function maybeHandleSubmit(event) {
  4231. if (event.defaultPrevented) {
  4232. return;
  4233. }
  4234. var form = event.target;
  4235. var value = dialogPolyfill.imagemapUseValue;
  4236. var submitter = findFormSubmitter(event);
  4237. if (value === null && submitter) {
  4238. value = submitter.value;
  4239. }
  4240. var dialog = findNearestDialog(form);
  4241. if (!dialog) {
  4242. return;
  4243. }
  4244. var formmethod = submitter && submitter.getAttribute('formmethod') || form.getAttribute('method');
  4245. if (formmethod !== 'dialog') {
  4246. return;
  4247. }
  4248. event.preventDefault();
  4249. if (value != null) {
  4250. dialog.close(value);
  4251. } else {
  4252. dialog.close();
  4253. }
  4254. }
  4255. function dialogPolyfillInfo(dialog) {
  4256. this.dialog_ = dialog;
  4257. this.replacedStyleTop_ = false;
  4258. this.openAsModal_ = false;
  4259. if (!dialog.hasAttribute('role')) {
  4260. dialog.setAttribute('role', 'dialog');
  4261. }
  4262. dialog.show = this.show.bind(this);
  4263. dialog.showModal = this.showModal.bind(this);
  4264. dialog.close = this.close.bind(this);
  4265. dialog.addEventListener('submit', maybeHandleSubmit, false);
  4266. if (!('returnValue' in dialog)) {
  4267. dialog.returnValue = '';
  4268. }
  4269. if ('MutationObserver' in window) {
  4270. var mo = new MutationObserver(this.maybeHideModal.bind(this));
  4271. mo.observe(dialog, {
  4272. attributes: true,
  4273. attributeFilter: ['open']
  4274. });
  4275. } else {
  4276. var removed = false;
  4277. var cb = function () {
  4278. removed ? this.downgradeModal() : this.maybeHideModal();
  4279. removed = false;
  4280. }.bind(this);
  4281. var timeout;
  4282. var delayModel = function (ev) {
  4283. if (ev.target !== dialog) {
  4284. return;
  4285. }
  4286. var cand = 'DOMNodeRemoved';
  4287. removed |= ev.type.substr(0, cand.length) === cand;
  4288. window.clearTimeout(timeout);
  4289. timeout = window.setTimeout(cb, 0);
  4290. };
  4291. ['DOMAttrModified', 'DOMNodeRemoved', 'DOMNodeRemovedFromDocument'].forEach(function (name) {
  4292. dialog.addEventListener(name, delayModel);
  4293. });
  4294. }
  4295. Object.defineProperty(dialog, 'open', {
  4296. set: this.setOpen.bind(this),
  4297. get: dialog.hasAttribute.bind(dialog, 'open')
  4298. });
  4299. this.backdrop_ = document.createElement('div');
  4300. this.backdrop_.className = 'backdrop';
  4301. this.backdrop_.addEventListener('mouseup', this.backdropMouseEvent_.bind(this));
  4302. this.backdrop_.addEventListener('mousedown', this.backdropMouseEvent_.bind(this));
  4303. this.backdrop_.addEventListener('click', this.backdropMouseEvent_.bind(this));
  4304. }
  4305. dialogPolyfillInfo.prototype = {
  4306. get dialog() {
  4307. return this.dialog_;
  4308. },
  4309. maybeHideModal: function () {
  4310. if (this.dialog_.hasAttribute('open') && isConnected(this.dialog_)) {
  4311. return;
  4312. }
  4313. this.downgradeModal();
  4314. },
  4315. downgradeModal: function () {
  4316. if (!this.openAsModal_) {
  4317. return;
  4318. }
  4319. this.openAsModal_ = false;
  4320. this.dialog_.style.zIndex = '';
  4321. if (this.replacedStyleTop_) {
  4322. this.dialog_.style.top = '';
  4323. this.replacedStyleTop_ = false;
  4324. }
  4325. this.backdrop_.parentNode && this.backdrop_.parentNode.removeChild(this.backdrop_);
  4326. dialogPolyfill.dm.removeDialog(this);
  4327. },
  4328. setOpen: function (value) {
  4329. if (value) {
  4330. this.dialog_.hasAttribute('open') || this.dialog_.setAttribute('open', '');
  4331. } else {
  4332. this.dialog_.removeAttribute('open');
  4333. this.maybeHideModal();
  4334. }
  4335. },
  4336. backdropMouseEvent_: function (e) {
  4337. if (!this.dialog_.hasAttribute('tabindex')) {
  4338. var fake = document.createElement('div');
  4339. this.dialog_.insertBefore(fake, this.dialog_.firstChild);
  4340. fake.tabIndex = -1;
  4341. fake.focus();
  4342. this.dialog_.removeChild(fake);
  4343. } else {
  4344. this.dialog_.focus();
  4345. }
  4346. var redirectedEvent = document.createEvent('MouseEvents');
  4347. redirectedEvent.initMouseEvent(e.type, e.bubbles, e.cancelable, window, e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget);
  4348. this.dialog_.dispatchEvent(redirectedEvent);
  4349. e.stopPropagation();
  4350. },
  4351. focus_: function () {
  4352. var target = this.dialog_.querySelector('[autofocus]:not([disabled])');
  4353. if (!target && this.dialog_.tabIndex >= 0) {
  4354. target = this.dialog_;
  4355. }
  4356. if (!target) {
  4357. target = findFocusableElementWithin(this.dialog_);
  4358. }
  4359. safeBlur(document.activeElement);
  4360. target && target.focus();
  4361. },
  4362. updateZIndex: function (dialogZ, backdropZ) {
  4363. if (dialogZ < backdropZ) {
  4364. throw new Error('dialogZ should never be < backdropZ');
  4365. }
  4366. this.dialog_.style.zIndex = dialogZ;
  4367. this.backdrop_.style.zIndex = backdropZ;
  4368. },
  4369. show: function () {
  4370. if (!this.dialog_.open) {
  4371. this.setOpen(true);
  4372. this.focus_();
  4373. }
  4374. },
  4375. showModal: function () {
  4376. if (this.dialog_.hasAttribute('open')) {
  4377. throw new Error('Failed to execute \'showModal\' on dialog: The element is already open, and therefore cannot be opened modally.');
  4378. }
  4379. if (!isConnected(this.dialog_)) {
  4380. throw new Error('Failed to execute \'showModal\' on dialog: The element is not in a Document.');
  4381. }
  4382. if (!dialogPolyfill.dm.pushDialog(this)) {
  4383. throw new Error('Failed to execute \'showModal\' on dialog: There are too many open modal dialogs.');
  4384. }
  4385. if (createsStackingContext(this.dialog_.parentElement)) {
  4386. console.warn('A dialog is being shown inside a stacking context. ' + 'This may cause it to be unusable. For more information, see this link: ' + 'https://github.com/GoogleChrome/dialog-polyfill/#stacking-context');
  4387. }
  4388. this.setOpen(true);
  4389. this.openAsModal_ = true;
  4390. if (dialogPolyfill.needsCentering(this.dialog_)) {
  4391. dialogPolyfill.reposition(this.dialog_);
  4392. this.replacedStyleTop_ = true;
  4393. } else {
  4394. this.replacedStyleTop_ = false;
  4395. }
  4396. this.dialog_.parentNode.insertBefore(this.backdrop_, this.dialog_.nextSibling);
  4397. this.focus_();
  4398. },
  4399. close: function (opt_returnValue) {
  4400. if (!this.dialog_.hasAttribute('open')) {
  4401. throw new Error('Failed to execute \'close\' on dialog: The element does not have an \'open\' attribute, and therefore cannot be closed.');
  4402. }
  4403. this.setOpen(false);
  4404. if (opt_returnValue !== undefined) {
  4405. this.dialog_.returnValue = opt_returnValue;
  4406. }
  4407. var closeEvent = new supportCustomEvent('close', {
  4408. bubbles: false,
  4409. cancelable: false
  4410. });
  4411. safeDispatchEvent(this.dialog_, closeEvent);
  4412. }
  4413. };
  4414. var dialogPolyfill = {};
  4415. dialogPolyfill.reposition = function (element) {
  4416. var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  4417. var topValue = scrollTop + (window.innerHeight - element.offsetHeight) / 2;
  4418. element.style.top = Math.max(scrollTop, topValue) + 'px';
  4419. };
  4420. dialogPolyfill.isInlinePositionSetByStylesheet = function (element) {
  4421. for (var i = 0; i < document.styleSheets.length; ++i) {
  4422. var styleSheet = document.styleSheets[i];
  4423. var cssRules = null;
  4424. try {
  4425. cssRules = styleSheet.cssRules;
  4426. } catch (e) {}
  4427. if (!cssRules) {
  4428. continue;
  4429. }
  4430. for (var j = 0; j < cssRules.length; ++j) {
  4431. var rule = cssRules[j];
  4432. var selectedNodes = null;
  4433. try {
  4434. selectedNodes = document.querySelectorAll(rule.selectorText);
  4435. } catch (e) {}
  4436. if (!selectedNodes || !inNodeList(selectedNodes, element)) {
  4437. continue;
  4438. }
  4439. var cssTop = rule.style.getPropertyValue('top');
  4440. var cssBottom = rule.style.getPropertyValue('bottom');
  4441. if (cssTop && cssTop !== 'auto' || cssBottom && cssBottom !== 'auto') {
  4442. return true;
  4443. }
  4444. }
  4445. }
  4446. return false;
  4447. };
  4448. dialogPolyfill.needsCentering = function (dialog) {
  4449. var computedStyle = window.getComputedStyle(dialog);
  4450. if (computedStyle.position !== 'absolute') {
  4451. return false;
  4452. }
  4453. if (dialog.style.top !== 'auto' && dialog.style.top !== '' || dialog.style.bottom !== 'auto' && dialog.style.bottom !== '') {
  4454. return false;
  4455. }
  4456. return !dialogPolyfill.isInlinePositionSetByStylesheet(dialog);
  4457. };
  4458. dialogPolyfill.forceRegisterDialog = function (element) {
  4459. if (window.HTMLDialogElement || element.showModal) {
  4460. console.warn('This browser already supports <dialog>, the polyfill ' + 'may not work correctly', element);
  4461. }
  4462. if (element.localName !== 'dialog') {
  4463. throw new Error('Failed to register dialog: The element is not a dialog.');
  4464. }
  4465. new dialogPolyfillInfo(element);
  4466. };
  4467. dialogPolyfill.registerDialog = function (element) {
  4468. if (!element.showModal) {
  4469. dialogPolyfill.forceRegisterDialog(element);
  4470. }
  4471. };
  4472. dialogPolyfill.DialogManager = function () {
  4473. this.pendingDialogStack = [];
  4474. var checkDOM = this.checkDOM_.bind(this);
  4475. this.overlay = document.createElement('div');
  4476. this.overlay.className = '_dialog_overlay';
  4477. this.overlay.addEventListener('click', function (e) {
  4478. this.forwardTab_ = undefined;
  4479. e.stopPropagation();
  4480. checkDOM([]);
  4481. }.bind(this));
  4482. this.handleKey_ = this.handleKey_.bind(this);
  4483. this.handleFocus_ = this.handleFocus_.bind(this);
  4484. this.zIndexLow_ = 100000;
  4485. this.zIndexHigh_ = 100000 + 150;
  4486. this.forwardTab_ = undefined;
  4487. if ('MutationObserver' in window) {
  4488. this.mo_ = new MutationObserver(function (records) {
  4489. var removed = [];
  4490. records.forEach(function (rec) {
  4491. for (var i = 0, c; c = rec.removedNodes[i]; ++i) {
  4492. if (!(c instanceof Element)) {
  4493. continue;
  4494. } else if (c.localName === 'dialog') {
  4495. removed.push(c);
  4496. }
  4497. removed = removed.concat(c.querySelectorAll('dialog'));
  4498. }
  4499. });
  4500. removed.length && checkDOM(removed);
  4501. });
  4502. }
  4503. };
  4504. dialogPolyfill.DialogManager.prototype.blockDocument = function () {
  4505. document.documentElement.addEventListener('focus', this.handleFocus_, true);
  4506. document.addEventListener('keydown', this.handleKey_);
  4507. this.mo_ && this.mo_.observe(document, {
  4508. childList: true,
  4509. subtree: true
  4510. });
  4511. };
  4512. dialogPolyfill.DialogManager.prototype.unblockDocument = function () {
  4513. document.documentElement.removeEventListener('focus', this.handleFocus_, true);
  4514. document.removeEventListener('keydown', this.handleKey_);
  4515. this.mo_ && this.mo_.disconnect();
  4516. };
  4517. dialogPolyfill.DialogManager.prototype.updateStacking = function () {
  4518. var zIndex = this.zIndexHigh_;
  4519. for (var i = 0, dpi; dpi = this.pendingDialogStack[i]; ++i) {
  4520. dpi.updateZIndex(--zIndex, --zIndex);
  4521. if (i === 0) {
  4522. this.overlay.style.zIndex = --zIndex;
  4523. }
  4524. }
  4525. var last = this.pendingDialogStack[0];
  4526. if (last) {
  4527. var p = last.dialog.parentNode || document.body;
  4528. p.appendChild(this.overlay);
  4529. } else if (this.overlay.parentNode) {
  4530. this.overlay.parentNode.removeChild(this.overlay);
  4531. }
  4532. };
  4533. dialogPolyfill.DialogManager.prototype.containedByTopDialog_ = function (candidate) {
  4534. while (candidate = findNearestDialog(candidate)) {
  4535. for (var i = 0, dpi; dpi = this.pendingDialogStack[i]; ++i) {
  4536. if (dpi.dialog === candidate) {
  4537. return i === 0;
  4538. }
  4539. }
  4540. candidate = candidate.parentElement;
  4541. }
  4542. return false;
  4543. };
  4544. dialogPolyfill.DialogManager.prototype.handleFocus_ = function (event) {
  4545. var target = event.composedPath ? event.composedPath()[0] : event.target;
  4546. if (this.containedByTopDialog_(target)) {
  4547. return;
  4548. }
  4549. if (document.activeElement === document.documentElement) {
  4550. return;
  4551. }
  4552. event.preventDefault();
  4553. event.stopPropagation();
  4554. safeBlur(target);
  4555. if (this.forwardTab_ === undefined) {
  4556. return;
  4557. }
  4558. var dpi = this.pendingDialogStack[0];
  4559. var dialog = dpi.dialog;
  4560. var position = dialog.compareDocumentPosition(target);
  4561. if (position & Node.DOCUMENT_POSITION_PRECEDING) {
  4562. if (this.forwardTab_) {
  4563. dpi.focus_();
  4564. } else if (target !== document.documentElement) {
  4565. document.documentElement.focus();
  4566. }
  4567. }
  4568. return false;
  4569. };
  4570. dialogPolyfill.DialogManager.prototype.handleKey_ = function (event) {
  4571. this.forwardTab_ = undefined;
  4572. if (event.keyCode === 27) {
  4573. event.preventDefault();
  4574. event.stopPropagation();
  4575. var cancelEvent = new supportCustomEvent('cancel', {
  4576. bubbles: false,
  4577. cancelable: true
  4578. });
  4579. var dpi = this.pendingDialogStack[0];
  4580. if (dpi && safeDispatchEvent(dpi.dialog, cancelEvent)) {
  4581. dpi.dialog.close();
  4582. }
  4583. } else if (event.keyCode === 9) {
  4584. this.forwardTab_ = !event.shiftKey;
  4585. }
  4586. };
  4587. dialogPolyfill.DialogManager.prototype.checkDOM_ = function (removed) {
  4588. var clone = this.pendingDialogStack.slice();
  4589. clone.forEach(function (dpi) {
  4590. if (removed.indexOf(dpi.dialog) !== -1) {
  4591. dpi.downgradeModal();
  4592. } else {
  4593. dpi.maybeHideModal();
  4594. }
  4595. });
  4596. };
  4597. dialogPolyfill.DialogManager.prototype.pushDialog = function (dpi) {
  4598. var allowed = (this.zIndexHigh_ - this.zIndexLow_) / 2 - 1;
  4599. if (this.pendingDialogStack.length >= allowed) {
  4600. return false;
  4601. }
  4602. if (this.pendingDialogStack.unshift(dpi) === 1) {
  4603. this.blockDocument();
  4604. }
  4605. this.updateStacking();
  4606. return true;
  4607. };
  4608. dialogPolyfill.DialogManager.prototype.removeDialog = function (dpi) {
  4609. var index = this.pendingDialogStack.indexOf(dpi);
  4610. if (index === -1) {
  4611. return;
  4612. }
  4613. this.pendingDialogStack.splice(index, 1);
  4614. if (this.pendingDialogStack.length === 0) {
  4615. this.unblockDocument();
  4616. }
  4617. this.updateStacking();
  4618. };
  4619. dialogPolyfill.dm = new dialogPolyfill.DialogManager();
  4620. dialogPolyfill.formSubmitter = null;
  4621. dialogPolyfill.imagemapUseValue = null;
  4622. if (window.HTMLDialogElement === undefined) {
  4623. var testForm = document.createElement('form');
  4624. testForm.setAttribute('method', 'dialog');
  4625. if (testForm.method !== 'dialog') {
  4626. var methodDescriptor = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, 'method');
  4627. if (methodDescriptor) {
  4628. var realGet = methodDescriptor.get;
  4629. methodDescriptor.get = function () {
  4630. if (isFormMethodDialog(this)) {
  4631. return 'dialog';
  4632. }
  4633. return realGet.call(this);
  4634. };
  4635. var realSet = methodDescriptor.set;
  4636. methodDescriptor.set = function (v) {
  4637. if (typeof v === 'string' && v.toLowerCase() === 'dialog') {
  4638. return this.setAttribute('method', v);
  4639. }
  4640. return realSet.call(this, v);
  4641. };
  4642. Object.defineProperty(HTMLFormElement.prototype, 'method', methodDescriptor);
  4643. }
  4644. }
  4645. document.addEventListener('click', function (ev) {
  4646. dialogPolyfill.formSubmitter = null;
  4647. dialogPolyfill.imagemapUseValue = null;
  4648. if (ev.defaultPrevented) {
  4649. return;
  4650. }
  4651. var target = ev.target;
  4652. if ('composedPath' in ev) {
  4653. var path = ev.composedPath();
  4654. target = path.shift() || target;
  4655. }
  4656. if (!target || !isFormMethodDialog(target.form)) {
  4657. return;
  4658. }
  4659. var valid = target.type === 'submit' && ['button', 'input'].indexOf(target.localName) > -1;
  4660. if (!valid) {
  4661. if (!(target.localName === 'input' && target.type === 'image')) {
  4662. return;
  4663. }
  4664. dialogPolyfill.imagemapUseValue = ev.offsetX + ',' + ev.offsetY;
  4665. }
  4666. var dialog = findNearestDialog(target);
  4667. if (!dialog) {
  4668. return;
  4669. }
  4670. dialogPolyfill.formSubmitter = target;
  4671. }, false);
  4672. document.addEventListener('submit', function (ev) {
  4673. var form = ev.target;
  4674. var dialog = findNearestDialog(form);
  4675. if (dialog) {
  4676. return;
  4677. }
  4678. var submitter = findFormSubmitter(ev);
  4679. var formmethod = submitter && submitter.getAttribute('formmethod') || form.getAttribute('method');
  4680. if (formmethod === 'dialog') {
  4681. ev.preventDefault();
  4682. }
  4683. });
  4684. var nativeFormSubmit = HTMLFormElement.prototype.submit;
  4685. var replacementFormSubmit = function () {
  4686. if (!isFormMethodDialog(this)) {
  4687. return nativeFormSubmit.call(this);
  4688. }
  4689. var dialog = findNearestDialog(this);
  4690. dialog && dialog.close();
  4691. };
  4692. HTMLFormElement.prototype.submit = replacementFormSubmit;
  4693. }
  4694. return dialogPolyfill;
  4695. });
  4696. /***/ }),
  4697. /* 12 */
  4698. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4699. Object.defineProperty(exports, "__esModule", ({
  4700. value: true
  4701. }));
  4702. exports.PasswordPrompt = void 0;
  4703. var _pdfjsLib = __webpack_require__(5);
  4704. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  4705. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  4706. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  4707. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  4708. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  4709. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  4710. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  4711. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  4712. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  4713. var _activeCapability = /*#__PURE__*/new WeakMap();
  4714. var _updateCallback = /*#__PURE__*/new WeakMap();
  4715. var _reason = /*#__PURE__*/new WeakMap();
  4716. var _verify = /*#__PURE__*/new WeakSet();
  4717. var _cancel = /*#__PURE__*/new WeakSet();
  4718. var _invokeCallback = /*#__PURE__*/new WeakSet();
  4719. class PasswordPrompt {
  4720. constructor(options, overlayManager, l10n) {
  4721. let isViewerEmbedded = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  4722. _classPrivateMethodInitSpec(this, _invokeCallback);
  4723. _classPrivateMethodInitSpec(this, _cancel);
  4724. _classPrivateMethodInitSpec(this, _verify);
  4725. _classPrivateFieldInitSpec(this, _activeCapability, {
  4726. writable: true,
  4727. value: null
  4728. });
  4729. _classPrivateFieldInitSpec(this, _updateCallback, {
  4730. writable: true,
  4731. value: null
  4732. });
  4733. _classPrivateFieldInitSpec(this, _reason, {
  4734. writable: true,
  4735. value: null
  4736. });
  4737. this.dialog = options.dialog;
  4738. this.label = options.label;
  4739. this.input = options.input;
  4740. this.submitButton = options.submitButton;
  4741. this.cancelButton = options.cancelButton;
  4742. this.overlayManager = overlayManager;
  4743. this.l10n = l10n;
  4744. this._isViewerEmbedded = isViewerEmbedded;
  4745. this.submitButton.addEventListener("click", _classPrivateMethodGet(this, _verify, _verify2).bind(this));
  4746. this.cancelButton.addEventListener("click", this.close.bind(this));
  4747. this.input.addEventListener("keydown", e => {
  4748. if (e.keyCode === 13) {
  4749. _classPrivateMethodGet(this, _verify, _verify2).call(this);
  4750. }
  4751. });
  4752. this.overlayManager.register(this.dialog, true);
  4753. this.dialog.addEventListener("close", _classPrivateMethodGet(this, _cancel, _cancel2).bind(this));
  4754. }
  4755. async open() {
  4756. if (_classPrivateFieldGet(this, _activeCapability)) {
  4757. await _classPrivateFieldGet(this, _activeCapability).promise;
  4758. }
  4759. _classPrivateFieldSet(this, _activeCapability, (0, _pdfjsLib.createPromiseCapability)());
  4760. try {
  4761. await this.overlayManager.open(this.dialog);
  4762. } catch (ex) {
  4763. _classPrivateFieldSet(this, _activeCapability, null);
  4764. throw ex;
  4765. }
  4766. const passwordIncorrect = _classPrivateFieldGet(this, _reason) === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  4767. if (!this._isViewerEmbedded || passwordIncorrect) {
  4768. this.input.focus();
  4769. }
  4770. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  4771. }
  4772. async close() {
  4773. if (this.overlayManager.active === this.dialog) {
  4774. this.overlayManager.close(this.dialog);
  4775. }
  4776. }
  4777. async setUpdateCallback(updateCallback, reason) {
  4778. if (_classPrivateFieldGet(this, _activeCapability)) {
  4779. await _classPrivateFieldGet(this, _activeCapability).promise;
  4780. }
  4781. _classPrivateFieldSet(this, _updateCallback, updateCallback);
  4782. _classPrivateFieldSet(this, _reason, reason);
  4783. }
  4784. }
  4785. exports.PasswordPrompt = PasswordPrompt;
  4786. function _verify2() {
  4787. const password = this.input.value;
  4788. if ((password === null || password === void 0 ? void 0 : password.length) > 0) {
  4789. _classPrivateMethodGet(this, _invokeCallback, _invokeCallback2).call(this, password);
  4790. }
  4791. }
  4792. function _cancel2() {
  4793. _classPrivateMethodGet(this, _invokeCallback, _invokeCallback2).call(this, new Error("PasswordPrompt cancelled."));
  4794. _classPrivateFieldGet(this, _activeCapability).resolve();
  4795. }
  4796. function _invokeCallback2(password) {
  4797. if (!_classPrivateFieldGet(this, _updateCallback)) {
  4798. return;
  4799. }
  4800. this.close();
  4801. this.input.value = "";
  4802. _classPrivateFieldGet(this, _updateCallback).call(this, password);
  4803. _classPrivateFieldSet(this, _updateCallback, null);
  4804. }
  4805. /***/ }),
  4806. /* 13 */
  4807. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4808. Object.defineProperty(exports, "__esModule", ({
  4809. value: true
  4810. }));
  4811. exports.PDFAttachmentViewer = void 0;
  4812. var _pdfjsLib = __webpack_require__(5);
  4813. var _base_tree_viewer = __webpack_require__(14);
  4814. var _event_utils = __webpack_require__(6);
  4815. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  4816. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  4817. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  4818. var _appendAttachment = /*#__PURE__*/new WeakSet();
  4819. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4820. constructor(options) {
  4821. super(options);
  4822. _classPrivateMethodInitSpec(this, _appendAttachment);
  4823. this.downloadManager = options.downloadManager;
  4824. this.eventBus._on("fileattachmentannotation", _classPrivateMethodGet(this, _appendAttachment, _appendAttachment2).bind(this));
  4825. }
  4826. reset() {
  4827. let keepRenderedCapability = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  4828. super.reset();
  4829. this._attachments = null;
  4830. if (!keepRenderedCapability) {
  4831. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4832. }
  4833. this._pendingDispatchEvent = false;
  4834. }
  4835. async _dispatchEvent(attachmentsCount) {
  4836. this._renderedCapability.resolve();
  4837. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4838. this._pendingDispatchEvent = true;
  4839. await (0, _event_utils.waitOnEventOrTimeout)({
  4840. target: this.eventBus,
  4841. name: "annotationlayerrendered",
  4842. delay: 1000
  4843. });
  4844. if (!this._pendingDispatchEvent) {
  4845. return;
  4846. }
  4847. }
  4848. this._pendingDispatchEvent = false;
  4849. this.eventBus.dispatch("attachmentsloaded", {
  4850. source: this,
  4851. attachmentsCount
  4852. });
  4853. }
  4854. _bindLink(element, _ref) {
  4855. let {
  4856. content,
  4857. filename
  4858. } = _ref;
  4859. element.onclick = () => {
  4860. this.downloadManager.openOrDownloadData(element, content, filename);
  4861. return false;
  4862. };
  4863. }
  4864. render(_ref2) {
  4865. let {
  4866. attachments,
  4867. keepRenderedCapability = false
  4868. } = _ref2;
  4869. if (this._attachments) {
  4870. this.reset(keepRenderedCapability);
  4871. }
  4872. this._attachments = attachments || null;
  4873. if (!attachments) {
  4874. this._dispatchEvent(0);
  4875. return;
  4876. }
  4877. const names = Object.keys(attachments).sort(function (a, b) {
  4878. return a.toLowerCase().localeCompare(b.toLowerCase());
  4879. });
  4880. const fragment = document.createDocumentFragment();
  4881. let attachmentsCount = 0;
  4882. for (const name of names) {
  4883. const item = attachments[name];
  4884. const content = item.content,
  4885. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true);
  4886. const div = document.createElement("div");
  4887. div.className = "treeItem";
  4888. const element = document.createElement("a");
  4889. this._bindLink(element, {
  4890. content,
  4891. filename
  4892. });
  4893. element.textContent = this._normalizeTextContent(filename);
  4894. div.append(element);
  4895. fragment.append(div);
  4896. attachmentsCount++;
  4897. }
  4898. this._finishRendering(fragment, attachmentsCount);
  4899. }
  4900. }
  4901. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4902. function _appendAttachment2(_ref3) {
  4903. let {
  4904. filename,
  4905. content
  4906. } = _ref3;
  4907. const renderedPromise = this._renderedCapability.promise;
  4908. renderedPromise.then(() => {
  4909. if (renderedPromise !== this._renderedCapability.promise) {
  4910. return;
  4911. }
  4912. const attachments = this._attachments || Object.create(null);
  4913. for (const name in attachments) {
  4914. if (filename === name) {
  4915. return;
  4916. }
  4917. }
  4918. attachments[filename] = {
  4919. filename,
  4920. content
  4921. };
  4922. this.render({
  4923. attachments,
  4924. keepRenderedCapability: true
  4925. });
  4926. });
  4927. }
  4928. /***/ }),
  4929. /* 14 */
  4930. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4931. Object.defineProperty(exports, "__esModule", ({
  4932. value: true
  4933. }));
  4934. exports.BaseTreeViewer = void 0;
  4935. var _ui_utils = __webpack_require__(1);
  4936. const TREEITEM_OFFSET_TOP = -100;
  4937. const TREEITEM_SELECTED_CLASS = "selected";
  4938. class BaseTreeViewer {
  4939. constructor(options) {
  4940. if (this.constructor === BaseTreeViewer) {
  4941. throw new Error("Cannot initialize BaseTreeViewer.");
  4942. }
  4943. this.container = options.container;
  4944. this.eventBus = options.eventBus;
  4945. this.reset();
  4946. }
  4947. reset() {
  4948. this._pdfDocument = null;
  4949. this._lastToggleIsShow = true;
  4950. this._currentTreeItem = null;
  4951. this.container.textContent = "";
  4952. this.container.classList.remove("treeWithDeepNesting");
  4953. }
  4954. _dispatchEvent(count) {
  4955. throw new Error("Not implemented: _dispatchEvent");
  4956. }
  4957. _bindLink(element, params) {
  4958. throw new Error("Not implemented: _bindLink");
  4959. }
  4960. _normalizeTextContent(str) {
  4961. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4962. }
  4963. _addToggleButton(div) {
  4964. let hidden = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  4965. const toggler = document.createElement("div");
  4966. toggler.className = "treeItemToggler";
  4967. if (hidden) {
  4968. toggler.classList.add("treeItemsHidden");
  4969. }
  4970. toggler.onclick = evt => {
  4971. evt.stopPropagation();
  4972. toggler.classList.toggle("treeItemsHidden");
  4973. if (evt.shiftKey) {
  4974. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4975. this._toggleTreeItem(div, shouldShowAll);
  4976. }
  4977. };
  4978. div.prepend(toggler);
  4979. }
  4980. _toggleTreeItem(root) {
  4981. let show = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  4982. this._lastToggleIsShow = show;
  4983. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4984. toggler.classList.toggle("treeItemsHidden", !show);
  4985. }
  4986. }
  4987. _toggleAllTreeItems() {
  4988. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4989. }
  4990. _finishRendering(fragment, count) {
  4991. let hasAnyNesting = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  4992. if (hasAnyNesting) {
  4993. this.container.classList.add("treeWithDeepNesting");
  4994. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4995. }
  4996. this.container.append(fragment);
  4997. this._dispatchEvent(count);
  4998. }
  4999. render(params) {
  5000. throw new Error("Not implemented: render");
  5001. }
  5002. _updateCurrentTreeItem() {
  5003. let treeItem = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  5004. if (this._currentTreeItem) {
  5005. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  5006. this._currentTreeItem = null;
  5007. }
  5008. if (treeItem) {
  5009. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  5010. this._currentTreeItem = treeItem;
  5011. }
  5012. }
  5013. _scrollToCurrentTreeItem(treeItem) {
  5014. if (!treeItem) {
  5015. return;
  5016. }
  5017. let currentNode = treeItem.parentNode;
  5018. while (currentNode && currentNode !== this.container) {
  5019. if (currentNode.classList.contains("treeItem")) {
  5020. const toggler = currentNode.firstElementChild;
  5021. toggler === null || toggler === void 0 ? void 0 : toggler.classList.remove("treeItemsHidden");
  5022. }
  5023. currentNode = currentNode.parentNode;
  5024. }
  5025. this._updateCurrentTreeItem(treeItem);
  5026. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  5027. }
  5028. }
  5029. exports.BaseTreeViewer = BaseTreeViewer;
  5030. /***/ }),
  5031. /* 15 */
  5032. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5033. Object.defineProperty(exports, "__esModule", ({
  5034. value: true
  5035. }));
  5036. exports.PDFDocumentProperties = void 0;
  5037. var _pdfjsLib = __webpack_require__(5);
  5038. var _ui_utils = __webpack_require__(1);
  5039. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  5040. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  5041. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  5042. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  5043. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  5044. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  5045. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  5046. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  5047. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  5048. const DEFAULT_FIELD_CONTENT = "-";
  5049. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  5050. const US_PAGE_NAMES = {
  5051. "8.5x11": "Letter",
  5052. "8.5x14": "Legal"
  5053. };
  5054. const METRIC_PAGE_NAMES = {
  5055. "297x420": "A3",
  5056. "210x297": "A4"
  5057. };
  5058. function getPageName(size, isPortrait, pageNames) {
  5059. const width = isPortrait ? size.width : size.height;
  5060. const height = isPortrait ? size.height : size.width;
  5061. return pageNames[`${width}x${height}`];
  5062. }
  5063. var _fieldData = /*#__PURE__*/new WeakMap();
  5064. var _reset = /*#__PURE__*/new WeakSet();
  5065. var _updateUI = /*#__PURE__*/new WeakSet();
  5066. var _parseFileSize = /*#__PURE__*/new WeakSet();
  5067. var _parsePageSize = /*#__PURE__*/new WeakSet();
  5068. var _parseDate = /*#__PURE__*/new WeakSet();
  5069. var _parseLinearization = /*#__PURE__*/new WeakSet();
  5070. class PDFDocumentProperties {
  5071. constructor(_ref, overlayManager, eventBus, l10n, fileNameLookup) {
  5072. let {
  5073. dialog,
  5074. fields,
  5075. closeButton
  5076. } = _ref;
  5077. _classPrivateMethodInitSpec(this, _parseLinearization);
  5078. _classPrivateMethodInitSpec(this, _parseDate);
  5079. _classPrivateMethodInitSpec(this, _parsePageSize);
  5080. _classPrivateMethodInitSpec(this, _parseFileSize);
  5081. _classPrivateMethodInitSpec(this, _updateUI);
  5082. _classPrivateMethodInitSpec(this, _reset);
  5083. _classPrivateFieldInitSpec(this, _fieldData, {
  5084. writable: true,
  5085. value: null
  5086. });
  5087. this.dialog = dialog;
  5088. this.fields = fields;
  5089. this.overlayManager = overlayManager;
  5090. this.l10n = l10n;
  5091. this._fileNameLookup = fileNameLookup;
  5092. _classPrivateMethodGet(this, _reset, _reset2).call(this);
  5093. closeButton.addEventListener("click", this.close.bind(this));
  5094. this.overlayManager.register(this.dialog);
  5095. eventBus._on("pagechanging", evt => {
  5096. this._currentPageNumber = evt.pageNumber;
  5097. });
  5098. eventBus._on("rotationchanging", evt => {
  5099. this._pagesRotation = evt.pagesRotation;
  5100. });
  5101. this._isNonMetricLocale = true;
  5102. l10n.getLanguage().then(locale => {
  5103. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  5104. });
  5105. }
  5106. async open() {
  5107. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  5108. const currentPageNumber = this._currentPageNumber;
  5109. const pagesRotation = this._pagesRotation;
  5110. if (_classPrivateFieldGet(this, _fieldData) && currentPageNumber === _classPrivateFieldGet(this, _fieldData)._currentPageNumber && pagesRotation === _classPrivateFieldGet(this, _fieldData)._pagesRotation) {
  5111. _classPrivateMethodGet(this, _updateUI, _updateUI2).call(this);
  5112. return;
  5113. }
  5114. const {
  5115. info,
  5116. contentLength
  5117. } = await this.pdfDocument.getMetadata();
  5118. const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([this._fileNameLookup(), _classPrivateMethodGet(this, _parseFileSize, _parseFileSize2).call(this, contentLength), _classPrivateMethodGet(this, _parseDate, _parseDate2).call(this, info.CreationDate), _classPrivateMethodGet(this, _parseDate, _parseDate2).call(this, info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
  5119. return _classPrivateMethodGet(this, _parsePageSize, _parsePageSize2).call(this, (0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  5120. }), _classPrivateMethodGet(this, _parseLinearization, _parseLinearization2).call(this, info.IsLinearized)]);
  5121. _classPrivateFieldSet(this, _fieldData, Object.freeze({
  5122. fileName,
  5123. fileSize,
  5124. title: info.Title,
  5125. author: info.Author,
  5126. subject: info.Subject,
  5127. keywords: info.Keywords,
  5128. creationDate,
  5129. modificationDate,
  5130. creator: info.Creator,
  5131. producer: info.Producer,
  5132. version: info.PDFFormatVersion,
  5133. pageCount: this.pdfDocument.numPages,
  5134. pageSize,
  5135. linearized: isLinearized,
  5136. _currentPageNumber: currentPageNumber,
  5137. _pagesRotation: pagesRotation
  5138. }));
  5139. _classPrivateMethodGet(this, _updateUI, _updateUI2).call(this);
  5140. const {
  5141. length
  5142. } = await this.pdfDocument.getDownloadInfo();
  5143. if (contentLength === length) {
  5144. return;
  5145. }
  5146. const data = Object.assign(Object.create(null), _classPrivateFieldGet(this, _fieldData));
  5147. data.fileSize = await _classPrivateMethodGet(this, _parseFileSize, _parseFileSize2).call(this, length);
  5148. _classPrivateFieldSet(this, _fieldData, Object.freeze(data));
  5149. _classPrivateMethodGet(this, _updateUI, _updateUI2).call(this);
  5150. }
  5151. async close() {
  5152. this.overlayManager.close(this.dialog);
  5153. }
  5154. setDocument(pdfDocument) {
  5155. if (this.pdfDocument) {
  5156. _classPrivateMethodGet(this, _reset, _reset2).call(this);
  5157. _classPrivateMethodGet(this, _updateUI, _updateUI2).call(this, true);
  5158. }
  5159. if (!pdfDocument) {
  5160. return;
  5161. }
  5162. this.pdfDocument = pdfDocument;
  5163. this._dataAvailableCapability.resolve();
  5164. }
  5165. }
  5166. exports.PDFDocumentProperties = PDFDocumentProperties;
  5167. function _reset2() {
  5168. this.pdfDocument = null;
  5169. _classPrivateFieldSet(this, _fieldData, null);
  5170. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  5171. this._currentPageNumber = 1;
  5172. this._pagesRotation = 0;
  5173. }
  5174. function _updateUI2() {
  5175. let reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  5176. if (reset || !_classPrivateFieldGet(this, _fieldData)) {
  5177. for (const id in this.fields) {
  5178. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  5179. }
  5180. return;
  5181. }
  5182. if (this.overlayManager.active !== this.dialog) {
  5183. return;
  5184. }
  5185. for (const id in this.fields) {
  5186. const content = _classPrivateFieldGet(this, _fieldData)[id];
  5187. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  5188. }
  5189. }
  5190. async function _parseFileSize2() {
  5191. let fileSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  5192. const kb = fileSize / 1024,
  5193. mb = kb / 1024;
  5194. if (!kb) {
  5195. return undefined;
  5196. }
  5197. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  5198. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  5199. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  5200. size_b: fileSize.toLocaleString()
  5201. });
  5202. }
  5203. async function _parsePageSize2(pageSizeInches, pagesRotation) {
  5204. if (!pageSizeInches) {
  5205. return undefined;
  5206. }
  5207. if (pagesRotation % 180 !== 0) {
  5208. pageSizeInches = {
  5209. width: pageSizeInches.height,
  5210. height: pageSizeInches.width
  5211. };
  5212. }
  5213. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  5214. let sizeInches = {
  5215. width: Math.round(pageSizeInches.width * 100) / 100,
  5216. height: Math.round(pageSizeInches.height * 100) / 100
  5217. };
  5218. let sizeMillimeters = {
  5219. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  5220. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  5221. };
  5222. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  5223. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  5224. const exactMillimeters = {
  5225. width: pageSizeInches.width * 25.4,
  5226. height: pageSizeInches.height * 25.4
  5227. };
  5228. const intMillimeters = {
  5229. width: Math.round(sizeMillimeters.width),
  5230. height: Math.round(sizeMillimeters.height)
  5231. };
  5232. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  5233. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  5234. if (rawName) {
  5235. sizeInches = {
  5236. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  5237. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  5238. };
  5239. sizeMillimeters = intMillimeters;
  5240. }
  5241. }
  5242. }
  5243. const [{
  5244. width,
  5245. height
  5246. }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`document_properties_page_size_unit_${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`), this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`)]);
  5247. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  5248. width: width.toLocaleString(),
  5249. height: height.toLocaleString(),
  5250. unit,
  5251. name,
  5252. orientation
  5253. });
  5254. }
  5255. async function _parseDate2(inputDate) {
  5256. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  5257. if (!dateObject) {
  5258. return undefined;
  5259. }
  5260. return this.l10n.get("document_properties_date_string", {
  5261. date: dateObject.toLocaleDateString(),
  5262. time: dateObject.toLocaleTimeString()
  5263. });
  5264. }
  5265. function _parseLinearization2(isLinearized) {
  5266. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  5267. }
  5268. /***/ }),
  5269. /* 16 */
  5270. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5271. Object.defineProperty(exports, "__esModule", ({
  5272. value: true
  5273. }));
  5274. exports.PDFFindBar = void 0;
  5275. var _pdf_find_controller = __webpack_require__(17);
  5276. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  5277. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  5278. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  5279. const MATCHES_COUNT_LIMIT = 1000;
  5280. var _adjustWidth = /*#__PURE__*/new WeakSet();
  5281. class PDFFindBar {
  5282. constructor(options, eventBus, l10n) {
  5283. _classPrivateMethodInitSpec(this, _adjustWidth);
  5284. this.opened = false;
  5285. this.bar = options.bar;
  5286. this.toggleButton = options.toggleButton;
  5287. this.findField = options.findField;
  5288. this.highlightAll = options.highlightAllCheckbox;
  5289. this.caseSensitive = options.caseSensitiveCheckbox;
  5290. this.matchDiacritics = options.matchDiacriticsCheckbox;
  5291. this.entireWord = options.entireWordCheckbox;
  5292. this.findMsg = options.findMsg;
  5293. this.findResultsCount = options.findResultsCount;
  5294. this.findPreviousButton = options.findPreviousButton;
  5295. this.findNextButton = options.findNextButton;
  5296. this.eventBus = eventBus;
  5297. this.l10n = l10n;
  5298. this.toggleButton.addEventListener("click", () => {
  5299. this.toggle();
  5300. });
  5301. this.findField.addEventListener("input", () => {
  5302. this.dispatchEvent("");
  5303. });
  5304. this.bar.addEventListener("keydown", e => {
  5305. switch (e.keyCode) {
  5306. case 13:
  5307. if (e.target === this.findField) {
  5308. this.dispatchEvent("again", e.shiftKey);
  5309. }
  5310. break;
  5311. case 27:
  5312. this.close();
  5313. break;
  5314. }
  5315. });
  5316. this.findPreviousButton.addEventListener("click", () => {
  5317. this.dispatchEvent("again", true);
  5318. });
  5319. this.findNextButton.addEventListener("click", () => {
  5320. this.dispatchEvent("again", false);
  5321. });
  5322. this.highlightAll.addEventListener("click", () => {
  5323. this.dispatchEvent("highlightallchange");
  5324. });
  5325. this.caseSensitive.addEventListener("click", () => {
  5326. this.dispatchEvent("casesensitivitychange");
  5327. });
  5328. this.entireWord.addEventListener("click", () => {
  5329. this.dispatchEvent("entirewordchange");
  5330. });
  5331. this.matchDiacritics.addEventListener("click", () => {
  5332. this.dispatchEvent("diacriticmatchingchange");
  5333. });
  5334. this.eventBus._on("resize", _classPrivateMethodGet(this, _adjustWidth, _adjustWidth2).bind(this));
  5335. }
  5336. reset() {
  5337. this.updateUIState();
  5338. }
  5339. dispatchEvent(type) {
  5340. let findPrev = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  5341. this.eventBus.dispatch("find", {
  5342. source: this,
  5343. type,
  5344. query: this.findField.value,
  5345. phraseSearch: true,
  5346. caseSensitive: this.caseSensitive.checked,
  5347. entireWord: this.entireWord.checked,
  5348. highlightAll: this.highlightAll.checked,
  5349. findPrevious: findPrev,
  5350. matchDiacritics: this.matchDiacritics.checked
  5351. });
  5352. }
  5353. updateUIState(state, previous, matchesCount) {
  5354. let findMsg = Promise.resolve("");
  5355. let status = "";
  5356. switch (state) {
  5357. case _pdf_find_controller.FindState.FOUND:
  5358. break;
  5359. case _pdf_find_controller.FindState.PENDING:
  5360. status = "pending";
  5361. break;
  5362. case _pdf_find_controller.FindState.NOT_FOUND:
  5363. findMsg = this.l10n.get("find_not_found");
  5364. status = "notFound";
  5365. break;
  5366. case _pdf_find_controller.FindState.WRAPPED:
  5367. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  5368. break;
  5369. }
  5370. this.findField.setAttribute("data-status", status);
  5371. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  5372. findMsg.then(msg => {
  5373. this.findMsg.textContent = msg;
  5374. _classPrivateMethodGet(this, _adjustWidth, _adjustWidth2).call(this);
  5375. });
  5376. this.updateResultsCount(matchesCount);
  5377. }
  5378. updateResultsCount() {
  5379. let {
  5380. current = 0,
  5381. total = 0
  5382. } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  5383. const limit = MATCHES_COUNT_LIMIT;
  5384. let matchCountMsg = Promise.resolve("");
  5385. if (total > 0) {
  5386. if (total > limit) {
  5387. let key = "find_match_count_limit";
  5388. matchCountMsg = this.l10n.get(key, {
  5389. limit
  5390. });
  5391. } else {
  5392. let key = "find_match_count";
  5393. matchCountMsg = this.l10n.get(key, {
  5394. current,
  5395. total
  5396. });
  5397. }
  5398. }
  5399. matchCountMsg.then(msg => {
  5400. this.findResultsCount.textContent = msg;
  5401. _classPrivateMethodGet(this, _adjustWidth, _adjustWidth2).call(this);
  5402. });
  5403. }
  5404. open() {
  5405. if (!this.opened) {
  5406. this.opened = true;
  5407. this.toggleButton.classList.add("toggled");
  5408. this.toggleButton.setAttribute("aria-expanded", "true");
  5409. this.bar.classList.remove("hidden");
  5410. }
  5411. this.findField.select();
  5412. this.findField.focus();
  5413. _classPrivateMethodGet(this, _adjustWidth, _adjustWidth2).call(this);
  5414. }
  5415. close() {
  5416. if (!this.opened) {
  5417. return;
  5418. }
  5419. this.opened = false;
  5420. this.toggleButton.classList.remove("toggled");
  5421. this.toggleButton.setAttribute("aria-expanded", "false");
  5422. this.bar.classList.add("hidden");
  5423. this.eventBus.dispatch("findbarclose", {
  5424. source: this
  5425. });
  5426. }
  5427. toggle() {
  5428. if (this.opened) {
  5429. this.close();
  5430. } else {
  5431. this.open();
  5432. }
  5433. }
  5434. }
  5435. exports.PDFFindBar = PDFFindBar;
  5436. function _adjustWidth2() {
  5437. if (!this.opened) {
  5438. return;
  5439. }
  5440. this.bar.classList.remove("wrapContainers");
  5441. const findbarHeight = this.bar.clientHeight;
  5442. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  5443. if (findbarHeight > inputContainerHeight) {
  5444. this.bar.classList.add("wrapContainers");
  5445. }
  5446. }
  5447. /***/ }),
  5448. /* 17 */
  5449. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5450. Object.defineProperty(exports, "__esModule", ({
  5451. value: true
  5452. }));
  5453. exports.PDFFindController = exports.FindState = void 0;
  5454. var _ui_utils = __webpack_require__(1);
  5455. var _pdfjsLib = __webpack_require__(5);
  5456. var _pdf_find_utils = __webpack_require__(18);
  5457. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  5458. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  5459. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  5460. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  5461. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  5462. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  5463. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  5464. const FindState = {
  5465. FOUND: 0,
  5466. NOT_FOUND: 1,
  5467. WRAPPED: 2,
  5468. PENDING: 3
  5469. };
  5470. exports.FindState = FindState;
  5471. const FIND_TIMEOUT = 250;
  5472. const MATCH_SCROLL_OFFSET_TOP = -50;
  5473. const MATCH_SCROLL_OFFSET_LEFT = -400;
  5474. const CHARACTERS_TO_NORMALIZE = {
  5475. "\u2010": "-",
  5476. "\u2018": "'",
  5477. "\u2019": "'",
  5478. "\u201A": "'",
  5479. "\u201B": "'",
  5480. "\u201C": '"',
  5481. "\u201D": '"',
  5482. "\u201E": '"',
  5483. "\u201F": '"',
  5484. "\u00BC": "1/4",
  5485. "\u00BD": "1/2",
  5486. "\u00BE": "3/4"
  5487. };
  5488. const DIACRITICS_EXCEPTION = new Set([0x3099, 0x309a, 0x094d, 0x09cd, 0x0a4d, 0x0acd, 0x0b4d, 0x0bcd, 0x0c4d, 0x0ccd, 0x0d3b, 0x0d3c, 0x0d4d, 0x0dca, 0x0e3a, 0x0eba, 0x0f84, 0x1039, 0x103a, 0x1714, 0x1734, 0x17d2, 0x1a60, 0x1b44, 0x1baa, 0x1bab, 0x1bf2, 0x1bf3, 0x2d7f, 0xa806, 0xa82c, 0xa8c4, 0xa953, 0xa9c0, 0xaaf6, 0xabed, 0x0c56, 0x0f71, 0x0f72, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f80, 0x0f74]);
  5489. let DIACRITICS_EXCEPTION_STR;
  5490. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  5491. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  5492. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  5493. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  5494. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  5495. const SYLLABLES_LENGTHS = new Map();
  5496. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  5497. const NFKC_CHARS_TO_NORMALIZE = new Map();
  5498. let noSyllablesRegExp = null;
  5499. let withSyllablesRegExp = null;
  5500. function normalize(text) {
  5501. const syllablePositions = [];
  5502. let m;
  5503. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  5504. let {
  5505. index
  5506. } = m;
  5507. for (const char of m[0]) {
  5508. let len = SYLLABLES_LENGTHS.get(char);
  5509. if (!len) {
  5510. len = char.normalize("NFD").length;
  5511. SYLLABLES_LENGTHS.set(char, len);
  5512. }
  5513. syllablePositions.push([len, index++]);
  5514. }
  5515. }
  5516. let normalizationRegex;
  5517. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  5518. normalizationRegex = noSyllablesRegExp;
  5519. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  5520. normalizationRegex = withSyllablesRegExp;
  5521. } else {
  5522. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  5523. const toNormalizeWithNFKC = "\u2460-\u2473" + "\u24b6-\u24ff" + "\u3244-\u32bf" + "\u32d0-\u32fe" + "\uff00-\uffef";
  5524. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(\\p{Ideographic}\\n)|(\\n)`;
  5525. if (syllablePositions.length === 0) {
  5526. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  5527. } else {
  5528. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  5529. }
  5530. }
  5531. const rawDiacriticsPositions = [];
  5532. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  5533. rawDiacriticsPositions.push([m[0].length, m.index]);
  5534. }
  5535. let normalized = text.normalize("NFD");
  5536. const positions = [[0, 0]];
  5537. let rawDiacriticsIndex = 0;
  5538. let syllableIndex = 0;
  5539. let shift = 0;
  5540. let shiftOrigin = 0;
  5541. let eol = 0;
  5542. let hasDiacritics = false;
  5543. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, i) => {
  5544. var _syllablePositions$sy;
  5545. i -= shiftOrigin;
  5546. if (p1) {
  5547. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  5548. const jj = replacement.length;
  5549. for (let j = 1; j < jj; j++) {
  5550. positions.push([i - shift + j, shift - j]);
  5551. }
  5552. shift -= jj - 1;
  5553. return replacement;
  5554. }
  5555. if (p2) {
  5556. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  5557. if (!replacement) {
  5558. replacement = p2.normalize("NFKC");
  5559. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  5560. }
  5561. const jj = replacement.length;
  5562. for (let j = 1; j < jj; j++) {
  5563. positions.push([i - shift + j, shift - j]);
  5564. }
  5565. shift -= jj - 1;
  5566. return replacement;
  5567. }
  5568. if (p3) {
  5569. var _rawDiacriticsPositio;
  5570. const hasTrailingDashEOL = p3.endsWith("\n");
  5571. const len = hasTrailingDashEOL ? p3.length - 2 : p3.length;
  5572. hasDiacritics = true;
  5573. let jj = len;
  5574. if (i + eol === ((_rawDiacriticsPositio = rawDiacriticsPositions[rawDiacriticsIndex]) === null || _rawDiacriticsPositio === void 0 ? void 0 : _rawDiacriticsPositio[1])) {
  5575. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  5576. ++rawDiacriticsIndex;
  5577. }
  5578. for (let j = 1; j <= jj; j++) {
  5579. positions.push([i - 1 - shift + j, shift - j]);
  5580. }
  5581. shift -= jj;
  5582. shiftOrigin += jj;
  5583. if (hasTrailingDashEOL) {
  5584. i += len - 1;
  5585. positions.push([i - shift + 1, 1 + shift]);
  5586. shift += 1;
  5587. shiftOrigin += 1;
  5588. eol += 1;
  5589. return p3.slice(0, len);
  5590. }
  5591. return p3;
  5592. }
  5593. if (p4) {
  5594. positions.push([i - shift + 1, 1 + shift]);
  5595. shift += 1;
  5596. shiftOrigin += 1;
  5597. eol += 1;
  5598. return p4.charAt(0);
  5599. }
  5600. if (p5) {
  5601. positions.push([i - shift + 1, shift]);
  5602. shiftOrigin += 1;
  5603. eol += 1;
  5604. return p5.charAt(0);
  5605. }
  5606. if (p6) {
  5607. positions.push([i - shift + 1, shift - 1]);
  5608. shift -= 1;
  5609. shiftOrigin += 1;
  5610. eol += 1;
  5611. return " ";
  5612. }
  5613. if (i + eol === ((_syllablePositions$sy = syllablePositions[syllableIndex]) === null || _syllablePositions$sy === void 0 ? void 0 : _syllablePositions$sy[1])) {
  5614. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  5615. ++syllableIndex;
  5616. for (let j = 1; j <= newCharLen; j++) {
  5617. positions.push([i - (shift - j), shift - j]);
  5618. }
  5619. shift -= newCharLen;
  5620. shiftOrigin += newCharLen;
  5621. }
  5622. return p7;
  5623. });
  5624. positions.push([normalized.length, shift]);
  5625. return [normalized, positions, hasDiacritics];
  5626. }
  5627. function getOriginalIndex(diffs, pos, len) {
  5628. if (!diffs) {
  5629. return [pos, len];
  5630. }
  5631. const start = pos;
  5632. const end = pos + len;
  5633. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  5634. if (diffs[i][0] > start) {
  5635. --i;
  5636. }
  5637. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  5638. if (diffs[j][0] > end) {
  5639. --j;
  5640. }
  5641. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  5642. }
  5643. var _onFind = /*#__PURE__*/new WeakSet();
  5644. var _reset = /*#__PURE__*/new WeakSet();
  5645. var _query = /*#__PURE__*/new WeakMap();
  5646. var _shouldDirtyMatch = /*#__PURE__*/new WeakSet();
  5647. var _isEntireWord = /*#__PURE__*/new WeakSet();
  5648. var _calculateRegExpMatch = /*#__PURE__*/new WeakSet();
  5649. var _convertToRegExpString = /*#__PURE__*/new WeakSet();
  5650. var _calculateMatch = /*#__PURE__*/new WeakSet();
  5651. var _extractText = /*#__PURE__*/new WeakSet();
  5652. var _updatePage = /*#__PURE__*/new WeakSet();
  5653. var _updateAllPages = /*#__PURE__*/new WeakSet();
  5654. var _nextMatch = /*#__PURE__*/new WeakSet();
  5655. var _matchesReady = /*#__PURE__*/new WeakSet();
  5656. var _nextPageMatch = /*#__PURE__*/new WeakSet();
  5657. var _advanceOffsetPage = /*#__PURE__*/new WeakSet();
  5658. var _updateMatch = /*#__PURE__*/new WeakSet();
  5659. var _onFindBarClose = /*#__PURE__*/new WeakSet();
  5660. var _requestMatchesCount = /*#__PURE__*/new WeakSet();
  5661. var _updateUIResultsCount = /*#__PURE__*/new WeakSet();
  5662. var _updateUIState = /*#__PURE__*/new WeakSet();
  5663. class PDFFindController {
  5664. constructor(_ref) {
  5665. let {
  5666. linkService: _linkService,
  5667. eventBus
  5668. } = _ref;
  5669. _classPrivateMethodInitSpec(this, _updateUIState);
  5670. _classPrivateMethodInitSpec(this, _updateUIResultsCount);
  5671. _classPrivateMethodInitSpec(this, _requestMatchesCount);
  5672. _classPrivateMethodInitSpec(this, _onFindBarClose);
  5673. _classPrivateMethodInitSpec(this, _updateMatch);
  5674. _classPrivateMethodInitSpec(this, _advanceOffsetPage);
  5675. _classPrivateMethodInitSpec(this, _nextPageMatch);
  5676. _classPrivateMethodInitSpec(this, _matchesReady);
  5677. _classPrivateMethodInitSpec(this, _nextMatch);
  5678. _classPrivateMethodInitSpec(this, _updateAllPages);
  5679. _classPrivateMethodInitSpec(this, _updatePage);
  5680. _classPrivateMethodInitSpec(this, _extractText);
  5681. _classPrivateMethodInitSpec(this, _calculateMatch);
  5682. _classPrivateMethodInitSpec(this, _convertToRegExpString);
  5683. _classPrivateMethodInitSpec(this, _calculateRegExpMatch);
  5684. _classPrivateMethodInitSpec(this, _isEntireWord);
  5685. _classPrivateMethodInitSpec(this, _shouldDirtyMatch);
  5686. _classPrivateFieldInitSpec(this, _query, {
  5687. get: _get_query,
  5688. set: void 0
  5689. });
  5690. _classPrivateMethodInitSpec(this, _reset);
  5691. _classPrivateMethodInitSpec(this, _onFind);
  5692. this._linkService = _linkService;
  5693. this._eventBus = eventBus;
  5694. _classPrivateMethodGet(this, _reset, _reset2).call(this);
  5695. eventBus._on("find", _classPrivateMethodGet(this, _onFind, _onFind2).bind(this));
  5696. eventBus._on("findbarclose", _classPrivateMethodGet(this, _onFindBarClose, _onFindBarClose2).bind(this));
  5697. }
  5698. get highlightMatches() {
  5699. return this._highlightMatches;
  5700. }
  5701. get pageMatches() {
  5702. return this._pageMatches;
  5703. }
  5704. get pageMatchesLength() {
  5705. return this._pageMatchesLength;
  5706. }
  5707. get selected() {
  5708. return this._selected;
  5709. }
  5710. get state() {
  5711. return this._state;
  5712. }
  5713. setDocument(pdfDocument) {
  5714. if (this._pdfDocument) {
  5715. _classPrivateMethodGet(this, _reset, _reset2).call(this);
  5716. }
  5717. if (!pdfDocument) {
  5718. return;
  5719. }
  5720. this._pdfDocument = pdfDocument;
  5721. this._firstPageCapability.resolve();
  5722. }
  5723. scrollMatchIntoView(_ref2) {
  5724. let {
  5725. element = null,
  5726. selectedLeft = 0,
  5727. pageIndex = -1,
  5728. matchIndex = -1
  5729. } = _ref2;
  5730. if (!this._scrollMatches || !element) {
  5731. return;
  5732. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  5733. return;
  5734. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5735. return;
  5736. }
  5737. this._scrollMatches = false;
  5738. const spot = {
  5739. top: MATCH_SCROLL_OFFSET_TOP,
  5740. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  5741. };
  5742. (0, _ui_utils.scrollIntoView)(element, spot, true);
  5743. }
  5744. }
  5745. exports.PDFFindController = PDFFindController;
  5746. function _onFind2(state) {
  5747. if (!state) {
  5748. return;
  5749. }
  5750. const pdfDocument = this._pdfDocument;
  5751. const {
  5752. type
  5753. } = state;
  5754. if (this._state === null || _classPrivateMethodGet(this, _shouldDirtyMatch, _shouldDirtyMatch2).call(this, state)) {
  5755. this._dirtyMatch = true;
  5756. }
  5757. this._state = state;
  5758. if (type !== "highlightallchange") {
  5759. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this, FindState.PENDING);
  5760. }
  5761. this._firstPageCapability.promise.then(() => {
  5762. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5763. return;
  5764. }
  5765. _classPrivateMethodGet(this, _extractText, _extractText2).call(this);
  5766. const findbarClosed = !this._highlightMatches;
  5767. const pendingTimeout = !!this._findTimeout;
  5768. if (this._findTimeout) {
  5769. clearTimeout(this._findTimeout);
  5770. this._findTimeout = null;
  5771. }
  5772. if (!type) {
  5773. this._findTimeout = setTimeout(() => {
  5774. _classPrivateMethodGet(this, _nextMatch, _nextMatch2).call(this);
  5775. this._findTimeout = null;
  5776. }, FIND_TIMEOUT);
  5777. } else if (this._dirtyMatch) {
  5778. _classPrivateMethodGet(this, _nextMatch, _nextMatch2).call(this);
  5779. } else if (type === "again") {
  5780. _classPrivateMethodGet(this, _nextMatch, _nextMatch2).call(this);
  5781. if (findbarClosed && this._state.highlightAll) {
  5782. _classPrivateMethodGet(this, _updateAllPages, _updateAllPages2).call(this);
  5783. }
  5784. } else if (type === "highlightallchange") {
  5785. if (pendingTimeout) {
  5786. _classPrivateMethodGet(this, _nextMatch, _nextMatch2).call(this);
  5787. } else {
  5788. this._highlightMatches = true;
  5789. }
  5790. _classPrivateMethodGet(this, _updateAllPages, _updateAllPages2).call(this);
  5791. } else {
  5792. _classPrivateMethodGet(this, _nextMatch, _nextMatch2).call(this);
  5793. }
  5794. });
  5795. }
  5796. function _reset2() {
  5797. this._highlightMatches = false;
  5798. this._scrollMatches = false;
  5799. this._pdfDocument = null;
  5800. this._pageMatches = [];
  5801. this._pageMatchesLength = [];
  5802. this._state = null;
  5803. this._selected = {
  5804. pageIdx: -1,
  5805. matchIdx: -1
  5806. };
  5807. this._offset = {
  5808. pageIdx: null,
  5809. matchIdx: null,
  5810. wrapped: false
  5811. };
  5812. this._extractTextPromises = [];
  5813. this._pageContents = [];
  5814. this._pageDiffs = [];
  5815. this._hasDiacritics = [];
  5816. this._matchesCountTotal = 0;
  5817. this._pagesToSearch = null;
  5818. this._pendingFindMatches = new Set();
  5819. this._resumePageIdx = null;
  5820. this._dirtyMatch = false;
  5821. clearTimeout(this._findTimeout);
  5822. this._findTimeout = null;
  5823. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  5824. }
  5825. function _get_query() {
  5826. if (this._state.query !== this._rawQuery) {
  5827. this._rawQuery = this._state.query;
  5828. [this._normalizedQuery] = normalize(this._state.query);
  5829. }
  5830. return this._normalizedQuery;
  5831. }
  5832. function _shouldDirtyMatch2(state) {
  5833. if (state.query !== this._state.query) {
  5834. return true;
  5835. }
  5836. switch (state.type) {
  5837. case "again":
  5838. const pageNumber = this._selected.pageIdx + 1;
  5839. const linkService = this._linkService;
  5840. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  5841. return true;
  5842. }
  5843. return false;
  5844. case "highlightallchange":
  5845. return false;
  5846. }
  5847. return true;
  5848. }
  5849. function _isEntireWord2(content, startIdx, length) {
  5850. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  5851. if (match) {
  5852. const first = content.charCodeAt(startIdx);
  5853. const limit = match[1].charCodeAt(0);
  5854. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5855. return false;
  5856. }
  5857. }
  5858. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  5859. if (match) {
  5860. const last = content.charCodeAt(startIdx + length - 1);
  5861. const limit = match[1].charCodeAt(0);
  5862. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5863. return false;
  5864. }
  5865. }
  5866. return true;
  5867. }
  5868. function _calculateRegExpMatch2(query, entireWord, pageIndex, pageContent) {
  5869. const matches = [],
  5870. matchesLength = [];
  5871. const diffs = this._pageDiffs[pageIndex];
  5872. let match;
  5873. while ((match = query.exec(pageContent)) !== null) {
  5874. if (entireWord && !_classPrivateMethodGet(this, _isEntireWord, _isEntireWord2).call(this, pageContent, match.index, match[0].length)) {
  5875. continue;
  5876. }
  5877. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  5878. if (matchLen) {
  5879. matches.push(matchPos);
  5880. matchesLength.push(matchLen);
  5881. }
  5882. }
  5883. this._pageMatches[pageIndex] = matches;
  5884. this._pageMatchesLength[pageIndex] = matchesLength;
  5885. }
  5886. function _convertToRegExpString2(query, hasDiacritics) {
  5887. const {
  5888. matchDiacritics
  5889. } = this._state;
  5890. let isUnicode = false;
  5891. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5892. if (p1) {
  5893. return `[ ]*\\${p1}[ ]*`;
  5894. }
  5895. if (p2) {
  5896. return `[ ]*${p2}[ ]*`;
  5897. }
  5898. if (p3) {
  5899. return "[ ]+";
  5900. }
  5901. if (matchDiacritics) {
  5902. return p4 || p5;
  5903. }
  5904. if (p4) {
  5905. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5906. }
  5907. if (hasDiacritics) {
  5908. isUnicode = true;
  5909. return `${p5}\\p{M}*`;
  5910. }
  5911. return p5;
  5912. });
  5913. const trailingSpaces = "[ ]*";
  5914. if (query.endsWith(trailingSpaces)) {
  5915. query = query.slice(0, query.length - trailingSpaces.length);
  5916. }
  5917. if (matchDiacritics) {
  5918. if (hasDiacritics) {
  5919. DIACRITICS_EXCEPTION_STR || (DIACRITICS_EXCEPTION_STR = String.fromCharCode(...DIACRITICS_EXCEPTION));
  5920. isUnicode = true;
  5921. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5922. }
  5923. }
  5924. return [isUnicode, query];
  5925. }
  5926. function _calculateMatch2(pageIndex) {
  5927. let query = _classPrivateFieldGet(this, _query);
  5928. if (query.length === 0) {
  5929. return;
  5930. }
  5931. const {
  5932. caseSensitive,
  5933. entireWord,
  5934. phraseSearch
  5935. } = this._state;
  5936. const pageContent = this._pageContents[pageIndex];
  5937. const hasDiacritics = this._hasDiacritics[pageIndex];
  5938. let isUnicode = false;
  5939. if (phraseSearch) {
  5940. [isUnicode, query] = _classPrivateMethodGet(this, _convertToRegExpString, _convertToRegExpString2).call(this, query, hasDiacritics);
  5941. } else {
  5942. const match = query.match(/\S+/g);
  5943. if (match) {
  5944. query = match.sort().reverse().map(q => {
  5945. const [isUnicodePart, queryPart] = _classPrivateMethodGet(this, _convertToRegExpString, _convertToRegExpString2).call(this, q, hasDiacritics);
  5946. isUnicode || (isUnicode = isUnicodePart);
  5947. return `(${queryPart})`;
  5948. }).join("|");
  5949. }
  5950. }
  5951. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5952. query = new RegExp(query, flags);
  5953. _classPrivateMethodGet(this, _calculateRegExpMatch, _calculateRegExpMatch2).call(this, query, entireWord, pageIndex, pageContent);
  5954. if (this._state.highlightAll) {
  5955. _classPrivateMethodGet(this, _updatePage, _updatePage2).call(this, pageIndex);
  5956. }
  5957. if (this._resumePageIdx === pageIndex) {
  5958. this._resumePageIdx = null;
  5959. _classPrivateMethodGet(this, _nextPageMatch, _nextPageMatch2).call(this);
  5960. }
  5961. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5962. if (pageMatchesCount > 0) {
  5963. this._matchesCountTotal += pageMatchesCount;
  5964. _classPrivateMethodGet(this, _updateUIResultsCount, _updateUIResultsCount2).call(this);
  5965. }
  5966. }
  5967. function _extractText2() {
  5968. if (this._extractTextPromises.length > 0) {
  5969. return;
  5970. }
  5971. let promise = Promise.resolve();
  5972. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5973. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  5974. this._extractTextPromises[i] = extractTextCapability.promise;
  5975. promise = promise.then(() => {
  5976. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5977. return pdfPage.getTextContent();
  5978. }).then(textContent => {
  5979. const strBuf = [];
  5980. for (const textItem of textContent.items) {
  5981. strBuf.push(textItem.str);
  5982. if (textItem.hasEOL) {
  5983. strBuf.push("\n");
  5984. }
  5985. }
  5986. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5987. extractTextCapability.resolve();
  5988. }, reason => {
  5989. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5990. this._pageContents[i] = "";
  5991. this._pageDiffs[i] = null;
  5992. this._hasDiacritics[i] = false;
  5993. extractTextCapability.resolve();
  5994. });
  5995. });
  5996. }
  5997. }
  5998. function _updatePage2(index) {
  5999. if (this._scrollMatches && this._selected.pageIdx === index) {
  6000. this._linkService.page = index + 1;
  6001. }
  6002. this._eventBus.dispatch("updatetextlayermatches", {
  6003. source: this,
  6004. pageIndex: index
  6005. });
  6006. }
  6007. function _updateAllPages2() {
  6008. this._eventBus.dispatch("updatetextlayermatches", {
  6009. source: this,
  6010. pageIndex: -1
  6011. });
  6012. }
  6013. function _nextMatch2() {
  6014. const previous = this._state.findPrevious;
  6015. const currentPageIndex = this._linkService.page - 1;
  6016. const numPages = this._linkService.pagesCount;
  6017. this._highlightMatches = true;
  6018. if (this._dirtyMatch) {
  6019. this._dirtyMatch = false;
  6020. this._selected.pageIdx = this._selected.matchIdx = -1;
  6021. this._offset.pageIdx = currentPageIndex;
  6022. this._offset.matchIdx = null;
  6023. this._offset.wrapped = false;
  6024. this._resumePageIdx = null;
  6025. this._pageMatches.length = 0;
  6026. this._pageMatchesLength.length = 0;
  6027. this._matchesCountTotal = 0;
  6028. _classPrivateMethodGet(this, _updateAllPages, _updateAllPages2).call(this);
  6029. for (let i = 0; i < numPages; i++) {
  6030. if (this._pendingFindMatches.has(i)) {
  6031. continue;
  6032. }
  6033. this._pendingFindMatches.add(i);
  6034. this._extractTextPromises[i].then(() => {
  6035. this._pendingFindMatches.delete(i);
  6036. _classPrivateMethodGet(this, _calculateMatch, _calculateMatch2).call(this, i);
  6037. });
  6038. }
  6039. }
  6040. if (_classPrivateFieldGet(this, _query) === "") {
  6041. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this, FindState.FOUND);
  6042. return;
  6043. }
  6044. if (this._resumePageIdx) {
  6045. return;
  6046. }
  6047. const offset = this._offset;
  6048. this._pagesToSearch = numPages;
  6049. if (offset.matchIdx !== null) {
  6050. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  6051. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  6052. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  6053. _classPrivateMethodGet(this, _updateMatch, _updateMatch2).call(this, true);
  6054. return;
  6055. }
  6056. _classPrivateMethodGet(this, _advanceOffsetPage, _advanceOffsetPage2).call(this, previous);
  6057. }
  6058. _classPrivateMethodGet(this, _nextPageMatch, _nextPageMatch2).call(this);
  6059. }
  6060. function _matchesReady2(matches) {
  6061. const offset = this._offset;
  6062. const numMatches = matches.length;
  6063. const previous = this._state.findPrevious;
  6064. if (numMatches) {
  6065. offset.matchIdx = previous ? numMatches - 1 : 0;
  6066. _classPrivateMethodGet(this, _updateMatch, _updateMatch2).call(this, true);
  6067. return true;
  6068. }
  6069. _classPrivateMethodGet(this, _advanceOffsetPage, _advanceOffsetPage2).call(this, previous);
  6070. if (offset.wrapped) {
  6071. offset.matchIdx = null;
  6072. if (this._pagesToSearch < 0) {
  6073. _classPrivateMethodGet(this, _updateMatch, _updateMatch2).call(this, false);
  6074. return true;
  6075. }
  6076. }
  6077. return false;
  6078. }
  6079. function _nextPageMatch2() {
  6080. if (this._resumePageIdx !== null) {
  6081. console.error("There can only be one pending page.");
  6082. }
  6083. let matches = null;
  6084. do {
  6085. const pageIdx = this._offset.pageIdx;
  6086. matches = this._pageMatches[pageIdx];
  6087. if (!matches) {
  6088. this._resumePageIdx = pageIdx;
  6089. break;
  6090. }
  6091. } while (!_classPrivateMethodGet(this, _matchesReady, _matchesReady2).call(this, matches));
  6092. }
  6093. function _advanceOffsetPage2(previous) {
  6094. const offset = this._offset;
  6095. const numPages = this._linkService.pagesCount;
  6096. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  6097. offset.matchIdx = null;
  6098. this._pagesToSearch--;
  6099. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  6100. offset.pageIdx = previous ? numPages - 1 : 0;
  6101. offset.wrapped = true;
  6102. }
  6103. }
  6104. function _updateMatch2() {
  6105. let found = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  6106. let state = FindState.NOT_FOUND;
  6107. const wrapped = this._offset.wrapped;
  6108. this._offset.wrapped = false;
  6109. if (found) {
  6110. const previousPage = this._selected.pageIdx;
  6111. this._selected.pageIdx = this._offset.pageIdx;
  6112. this._selected.matchIdx = this._offset.matchIdx;
  6113. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  6114. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  6115. _classPrivateMethodGet(this, _updatePage, _updatePage2).call(this, previousPage);
  6116. }
  6117. }
  6118. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this, state, this._state.findPrevious);
  6119. if (this._selected.pageIdx !== -1) {
  6120. this._scrollMatches = true;
  6121. _classPrivateMethodGet(this, _updatePage, _updatePage2).call(this, this._selected.pageIdx);
  6122. }
  6123. }
  6124. function _onFindBarClose2(evt) {
  6125. const pdfDocument = this._pdfDocument;
  6126. this._firstPageCapability.promise.then(() => {
  6127. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  6128. return;
  6129. }
  6130. if (this._findTimeout) {
  6131. clearTimeout(this._findTimeout);
  6132. this._findTimeout = null;
  6133. }
  6134. if (this._resumePageIdx) {
  6135. this._resumePageIdx = null;
  6136. this._dirtyMatch = true;
  6137. }
  6138. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this, FindState.FOUND);
  6139. this._highlightMatches = false;
  6140. _classPrivateMethodGet(this, _updateAllPages, _updateAllPages2).call(this);
  6141. });
  6142. }
  6143. function _requestMatchesCount2() {
  6144. const {
  6145. pageIdx,
  6146. matchIdx
  6147. } = this._selected;
  6148. let current = 0,
  6149. total = this._matchesCountTotal;
  6150. if (matchIdx !== -1) {
  6151. for (let i = 0; i < pageIdx; i++) {
  6152. var _this$_pageMatches$i;
  6153. current += ((_this$_pageMatches$i = this._pageMatches[i]) === null || _this$_pageMatches$i === void 0 ? void 0 : _this$_pageMatches$i.length) || 0;
  6154. }
  6155. current += matchIdx + 1;
  6156. }
  6157. if (current < 1 || current > total) {
  6158. current = total = 0;
  6159. }
  6160. return {
  6161. current,
  6162. total
  6163. };
  6164. }
  6165. function _updateUIResultsCount2() {
  6166. this._eventBus.dispatch("updatefindmatchescount", {
  6167. source: this,
  6168. matchesCount: _classPrivateMethodGet(this, _requestMatchesCount, _requestMatchesCount2).call(this)
  6169. });
  6170. }
  6171. function _updateUIState2(state) {
  6172. var _this$_state;
  6173. let previous = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  6174. this._eventBus.dispatch("updatefindcontrolstate", {
  6175. source: this,
  6176. state,
  6177. previous,
  6178. matchesCount: _classPrivateMethodGet(this, _requestMatchesCount, _requestMatchesCount2).call(this),
  6179. rawQuery: ((_this$_state = this._state) === null || _this$_state === void 0 ? void 0 : _this$_state.query) ?? null
  6180. });
  6181. }
  6182. /***/ }),
  6183. /* 18 */
  6184. /***/ ((__unused_webpack_module, exports) => {
  6185. Object.defineProperty(exports, "__esModule", ({
  6186. value: true
  6187. }));
  6188. exports.CharacterType = void 0;
  6189. exports.getCharacterType = getCharacterType;
  6190. const CharacterType = {
  6191. SPACE: 0,
  6192. ALPHA_LETTER: 1,
  6193. PUNCT: 2,
  6194. HAN_LETTER: 3,
  6195. KATAKANA_LETTER: 4,
  6196. HIRAGANA_LETTER: 5,
  6197. HALFWIDTH_KATAKANA_LETTER: 6,
  6198. THAI_LETTER: 7
  6199. };
  6200. exports.CharacterType = CharacterType;
  6201. function isAlphabeticalScript(charCode) {
  6202. return charCode < 0x2e80;
  6203. }
  6204. function isAscii(charCode) {
  6205. return (charCode & 0xff80) === 0;
  6206. }
  6207. function isAsciiAlpha(charCode) {
  6208. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  6209. }
  6210. function isAsciiDigit(charCode) {
  6211. return charCode >= 0x30 && charCode <= 0x39;
  6212. }
  6213. function isAsciiSpace(charCode) {
  6214. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  6215. }
  6216. function isHan(charCode) {
  6217. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  6218. }
  6219. function isKatakana(charCode) {
  6220. return charCode >= 0x30a0 && charCode <= 0x30ff;
  6221. }
  6222. function isHiragana(charCode) {
  6223. return charCode >= 0x3040 && charCode <= 0x309f;
  6224. }
  6225. function isHalfwidthKatakana(charCode) {
  6226. return charCode >= 0xff60 && charCode <= 0xff9f;
  6227. }
  6228. function isThai(charCode) {
  6229. return (charCode & 0xff80) === 0x0e00;
  6230. }
  6231. function getCharacterType(charCode) {
  6232. if (isAlphabeticalScript(charCode)) {
  6233. if (isAscii(charCode)) {
  6234. if (isAsciiSpace(charCode)) {
  6235. return CharacterType.SPACE;
  6236. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  6237. return CharacterType.ALPHA_LETTER;
  6238. }
  6239. return CharacterType.PUNCT;
  6240. } else if (isThai(charCode)) {
  6241. return CharacterType.THAI_LETTER;
  6242. } else if (charCode === 0xa0) {
  6243. return CharacterType.SPACE;
  6244. }
  6245. return CharacterType.ALPHA_LETTER;
  6246. }
  6247. if (isHan(charCode)) {
  6248. return CharacterType.HAN_LETTER;
  6249. } else if (isKatakana(charCode)) {
  6250. return CharacterType.KATAKANA_LETTER;
  6251. } else if (isHiragana(charCode)) {
  6252. return CharacterType.HIRAGANA_LETTER;
  6253. } else if (isHalfwidthKatakana(charCode)) {
  6254. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  6255. }
  6256. return CharacterType.ALPHA_LETTER;
  6257. }
  6258. /***/ }),
  6259. /* 19 */
  6260. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6261. Object.defineProperty(exports, "__esModule", ({
  6262. value: true
  6263. }));
  6264. exports.PDFHistory = void 0;
  6265. exports.isDestArraysEqual = isDestArraysEqual;
  6266. exports.isDestHashesEqual = isDestHashesEqual;
  6267. var _ui_utils = __webpack_require__(1);
  6268. var _event_utils = __webpack_require__(6);
  6269. const HASH_CHANGE_TIMEOUT = 1000;
  6270. const POSITION_UPDATED_THRESHOLD = 50;
  6271. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  6272. function getCurrentHash() {
  6273. return document.location.hash;
  6274. }
  6275. class PDFHistory {
  6276. constructor(_ref) {
  6277. let {
  6278. linkService,
  6279. eventBus
  6280. } = _ref;
  6281. this.linkService = linkService;
  6282. this.eventBus = eventBus;
  6283. this._initialized = false;
  6284. this._fingerprint = "";
  6285. this.reset();
  6286. this._boundEvents = null;
  6287. this.eventBus._on("pagesinit", () => {
  6288. this._isPagesLoaded = false;
  6289. this.eventBus._on("pagesloaded", evt => {
  6290. this._isPagesLoaded = !!evt.pagesCount;
  6291. }, {
  6292. once: true
  6293. });
  6294. });
  6295. }
  6296. initialize(_ref2) {
  6297. let {
  6298. fingerprint,
  6299. resetHistory = false,
  6300. updateUrl = false
  6301. } = _ref2;
  6302. if (!fingerprint || typeof fingerprint !== "string") {
  6303. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  6304. return;
  6305. }
  6306. if (this._initialized) {
  6307. this.reset();
  6308. }
  6309. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  6310. this._fingerprint = fingerprint;
  6311. this._updateUrl = updateUrl === true;
  6312. this._initialized = true;
  6313. this._bindEvents();
  6314. const state = window.history.state;
  6315. this._popStateInProgress = false;
  6316. this._blockHashChange = 0;
  6317. this._currentHash = getCurrentHash();
  6318. this._numPositionUpdates = 0;
  6319. this._uid = this._maxUid = 0;
  6320. this._destination = null;
  6321. this._position = null;
  6322. if (!this._isValidState(state, true) || resetHistory) {
  6323. const {
  6324. hash,
  6325. page,
  6326. rotation
  6327. } = this._parseCurrentHash(true);
  6328. if (!hash || reInitialized || resetHistory) {
  6329. this._pushOrReplaceState(null, true);
  6330. return;
  6331. }
  6332. this._pushOrReplaceState({
  6333. hash,
  6334. page,
  6335. rotation
  6336. }, true);
  6337. return;
  6338. }
  6339. const destination = state.destination;
  6340. this._updateInternalState(destination, state.uid, true);
  6341. if (destination.rotation !== undefined) {
  6342. this._initialRotation = destination.rotation;
  6343. }
  6344. if (destination.dest) {
  6345. this._initialBookmark = JSON.stringify(destination.dest);
  6346. this._destination.page = null;
  6347. } else if (destination.hash) {
  6348. this._initialBookmark = destination.hash;
  6349. } else if (destination.page) {
  6350. this._initialBookmark = `page=${destination.page}`;
  6351. }
  6352. }
  6353. reset() {
  6354. if (this._initialized) {
  6355. this._pageHide();
  6356. this._initialized = false;
  6357. this._unbindEvents();
  6358. }
  6359. if (this._updateViewareaTimeout) {
  6360. clearTimeout(this._updateViewareaTimeout);
  6361. this._updateViewareaTimeout = null;
  6362. }
  6363. this._initialBookmark = null;
  6364. this._initialRotation = null;
  6365. }
  6366. push(_ref3) {
  6367. let {
  6368. namedDest = null,
  6369. explicitDest,
  6370. pageNumber
  6371. } = _ref3;
  6372. if (!this._initialized) {
  6373. return;
  6374. }
  6375. if (namedDest && typeof namedDest !== "string") {
  6376. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  6377. return;
  6378. } else if (!Array.isArray(explicitDest)) {
  6379. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  6380. return;
  6381. } else if (!this._isValidPage(pageNumber)) {
  6382. if (pageNumber !== null || this._destination) {
  6383. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  6384. return;
  6385. }
  6386. }
  6387. const hash = namedDest || JSON.stringify(explicitDest);
  6388. if (!hash) {
  6389. return;
  6390. }
  6391. let forceReplace = false;
  6392. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  6393. if (this._destination.page) {
  6394. return;
  6395. }
  6396. forceReplace = true;
  6397. }
  6398. if (this._popStateInProgress && !forceReplace) {
  6399. return;
  6400. }
  6401. this._pushOrReplaceState({
  6402. dest: explicitDest,
  6403. hash,
  6404. page: pageNumber,
  6405. rotation: this.linkService.rotation
  6406. }, forceReplace);
  6407. if (!this._popStateInProgress) {
  6408. this._popStateInProgress = true;
  6409. Promise.resolve().then(() => {
  6410. this._popStateInProgress = false;
  6411. });
  6412. }
  6413. }
  6414. pushPage(pageNumber) {
  6415. var _this$_destination;
  6416. if (!this._initialized) {
  6417. return;
  6418. }
  6419. if (!this._isValidPage(pageNumber)) {
  6420. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  6421. return;
  6422. }
  6423. if (((_this$_destination = this._destination) === null || _this$_destination === void 0 ? void 0 : _this$_destination.page) === pageNumber) {
  6424. return;
  6425. }
  6426. if (this._popStateInProgress) {
  6427. return;
  6428. }
  6429. this._pushOrReplaceState({
  6430. dest: null,
  6431. hash: `page=${pageNumber}`,
  6432. page: pageNumber,
  6433. rotation: this.linkService.rotation
  6434. });
  6435. if (!this._popStateInProgress) {
  6436. this._popStateInProgress = true;
  6437. Promise.resolve().then(() => {
  6438. this._popStateInProgress = false;
  6439. });
  6440. }
  6441. }
  6442. pushCurrentPosition() {
  6443. if (!this._initialized || this._popStateInProgress) {
  6444. return;
  6445. }
  6446. this._tryPushCurrentPosition();
  6447. }
  6448. back() {
  6449. if (!this._initialized || this._popStateInProgress) {
  6450. return;
  6451. }
  6452. const state = window.history.state;
  6453. if (this._isValidState(state) && state.uid > 0) {
  6454. window.history.back();
  6455. }
  6456. }
  6457. forward() {
  6458. if (!this._initialized || this._popStateInProgress) {
  6459. return;
  6460. }
  6461. const state = window.history.state;
  6462. if (this._isValidState(state) && state.uid < this._maxUid) {
  6463. window.history.forward();
  6464. }
  6465. }
  6466. get popStateInProgress() {
  6467. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  6468. }
  6469. get initialBookmark() {
  6470. return this._initialized ? this._initialBookmark : null;
  6471. }
  6472. get initialRotation() {
  6473. return this._initialized ? this._initialRotation : null;
  6474. }
  6475. _pushOrReplaceState(destination) {
  6476. let forceReplace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  6477. const shouldReplace = forceReplace || !this._destination;
  6478. const newState = {
  6479. fingerprint: this._fingerprint,
  6480. uid: shouldReplace ? this._uid : this._uid + 1,
  6481. destination
  6482. };
  6483. this._updateInternalState(destination, newState.uid);
  6484. let newUrl;
  6485. if (this._updateUrl && destination !== null && destination !== void 0 && destination.hash) {
  6486. const baseUrl = document.location.href.split("#")[0];
  6487. if (!baseUrl.startsWith("file://")) {
  6488. newUrl = `${baseUrl}#${destination.hash}`;
  6489. }
  6490. }
  6491. if (shouldReplace) {
  6492. window.history.replaceState(newState, "", newUrl);
  6493. } else {
  6494. window.history.pushState(newState, "", newUrl);
  6495. }
  6496. }
  6497. _tryPushCurrentPosition() {
  6498. let temporary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  6499. if (!this._position) {
  6500. return;
  6501. }
  6502. let position = this._position;
  6503. if (temporary) {
  6504. position = Object.assign(Object.create(null), this._position);
  6505. position.temporary = true;
  6506. }
  6507. if (!this._destination) {
  6508. this._pushOrReplaceState(position);
  6509. return;
  6510. }
  6511. if (this._destination.temporary) {
  6512. this._pushOrReplaceState(position, true);
  6513. return;
  6514. }
  6515. if (this._destination.hash === position.hash) {
  6516. return;
  6517. }
  6518. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  6519. return;
  6520. }
  6521. let forceReplace = false;
  6522. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  6523. if (this._destination.dest !== undefined || !this._destination.first) {
  6524. return;
  6525. }
  6526. forceReplace = true;
  6527. }
  6528. this._pushOrReplaceState(position, forceReplace);
  6529. }
  6530. _isValidPage(val) {
  6531. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  6532. }
  6533. _isValidState(state) {
  6534. let checkReload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  6535. if (!state) {
  6536. return false;
  6537. }
  6538. if (state.fingerprint !== this._fingerprint) {
  6539. if (checkReload) {
  6540. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  6541. return false;
  6542. }
  6543. const [perfEntry] = performance.getEntriesByType("navigation");
  6544. if ((perfEntry === null || perfEntry === void 0 ? void 0 : perfEntry.type) !== "reload") {
  6545. return false;
  6546. }
  6547. } else {
  6548. return false;
  6549. }
  6550. }
  6551. if (!Number.isInteger(state.uid) || state.uid < 0) {
  6552. return false;
  6553. }
  6554. if (state.destination === null || typeof state.destination !== "object") {
  6555. return false;
  6556. }
  6557. return true;
  6558. }
  6559. _updateInternalState(destination, uid) {
  6560. let removeTemporary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  6561. if (this._updateViewareaTimeout) {
  6562. clearTimeout(this._updateViewareaTimeout);
  6563. this._updateViewareaTimeout = null;
  6564. }
  6565. if (removeTemporary && destination !== null && destination !== void 0 && destination.temporary) {
  6566. delete destination.temporary;
  6567. }
  6568. this._destination = destination;
  6569. this._uid = uid;
  6570. this._maxUid = Math.max(this._maxUid, uid);
  6571. this._numPositionUpdates = 0;
  6572. }
  6573. _parseCurrentHash() {
  6574. let checkNameddest = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  6575. const hash = unescape(getCurrentHash()).substring(1);
  6576. const params = (0, _ui_utils.parseQueryString)(hash);
  6577. const nameddest = params.get("nameddest") || "";
  6578. let page = params.get("page") | 0;
  6579. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  6580. page = null;
  6581. }
  6582. return {
  6583. hash,
  6584. page,
  6585. rotation: this.linkService.rotation
  6586. };
  6587. }
  6588. _updateViewarea(_ref4) {
  6589. let {
  6590. location
  6591. } = _ref4;
  6592. if (this._updateViewareaTimeout) {
  6593. clearTimeout(this._updateViewareaTimeout);
  6594. this._updateViewareaTimeout = null;
  6595. }
  6596. this._position = {
  6597. hash: location.pdfOpenParams.substring(1),
  6598. page: this.linkService.page,
  6599. first: location.pageNumber,
  6600. rotation: location.rotation
  6601. };
  6602. if (this._popStateInProgress) {
  6603. return;
  6604. }
  6605. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  6606. this._numPositionUpdates++;
  6607. }
  6608. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  6609. this._updateViewareaTimeout = setTimeout(() => {
  6610. if (!this._popStateInProgress) {
  6611. this._tryPushCurrentPosition(true);
  6612. }
  6613. this._updateViewareaTimeout = null;
  6614. }, UPDATE_VIEWAREA_TIMEOUT);
  6615. }
  6616. }
  6617. _popState(_ref5) {
  6618. let {
  6619. state
  6620. } = _ref5;
  6621. const newHash = getCurrentHash(),
  6622. hashChanged = this._currentHash !== newHash;
  6623. this._currentHash = newHash;
  6624. if (!state) {
  6625. this._uid++;
  6626. const {
  6627. hash,
  6628. page,
  6629. rotation
  6630. } = this._parseCurrentHash();
  6631. this._pushOrReplaceState({
  6632. hash,
  6633. page,
  6634. rotation
  6635. }, true);
  6636. return;
  6637. }
  6638. if (!this._isValidState(state)) {
  6639. return;
  6640. }
  6641. this._popStateInProgress = true;
  6642. if (hashChanged) {
  6643. this._blockHashChange++;
  6644. (0, _event_utils.waitOnEventOrTimeout)({
  6645. target: window,
  6646. name: "hashchange",
  6647. delay: HASH_CHANGE_TIMEOUT
  6648. }).then(() => {
  6649. this._blockHashChange--;
  6650. });
  6651. }
  6652. const destination = state.destination;
  6653. this._updateInternalState(destination, state.uid, true);
  6654. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  6655. this.linkService.rotation = destination.rotation;
  6656. }
  6657. if (destination.dest) {
  6658. this.linkService.goToDestination(destination.dest);
  6659. } else if (destination.hash) {
  6660. this.linkService.setHash(destination.hash);
  6661. } else if (destination.page) {
  6662. this.linkService.page = destination.page;
  6663. }
  6664. Promise.resolve().then(() => {
  6665. this._popStateInProgress = false;
  6666. });
  6667. }
  6668. _pageHide() {
  6669. if (!this._destination || this._destination.temporary) {
  6670. this._tryPushCurrentPosition();
  6671. }
  6672. }
  6673. _bindEvents() {
  6674. if (this._boundEvents) {
  6675. return;
  6676. }
  6677. this._boundEvents = {
  6678. updateViewarea: this._updateViewarea.bind(this),
  6679. popState: this._popState.bind(this),
  6680. pageHide: this._pageHide.bind(this)
  6681. };
  6682. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  6683. window.addEventListener("popstate", this._boundEvents.popState);
  6684. window.addEventListener("pagehide", this._boundEvents.pageHide);
  6685. }
  6686. _unbindEvents() {
  6687. if (!this._boundEvents) {
  6688. return;
  6689. }
  6690. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  6691. window.removeEventListener("popstate", this._boundEvents.popState);
  6692. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  6693. this._boundEvents = null;
  6694. }
  6695. }
  6696. exports.PDFHistory = PDFHistory;
  6697. function isDestHashesEqual(destHash, pushHash) {
  6698. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  6699. return false;
  6700. }
  6701. if (destHash === pushHash) {
  6702. return true;
  6703. }
  6704. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  6705. if (nameddest === pushHash) {
  6706. return true;
  6707. }
  6708. return false;
  6709. }
  6710. function isDestArraysEqual(firstDest, secondDest) {
  6711. function isEntryEqual(first, second) {
  6712. if (typeof first !== typeof second) {
  6713. return false;
  6714. }
  6715. if (Array.isArray(first) || Array.isArray(second)) {
  6716. return false;
  6717. }
  6718. if (first !== null && typeof first === "object" && second !== null) {
  6719. if (Object.keys(first).length !== Object.keys(second).length) {
  6720. return false;
  6721. }
  6722. for (const key in first) {
  6723. if (!isEntryEqual(first[key], second[key])) {
  6724. return false;
  6725. }
  6726. }
  6727. return true;
  6728. }
  6729. return first === second || Number.isNaN(first) && Number.isNaN(second);
  6730. }
  6731. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  6732. return false;
  6733. }
  6734. if (firstDest.length !== secondDest.length) {
  6735. return false;
  6736. }
  6737. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  6738. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  6739. return false;
  6740. }
  6741. }
  6742. return true;
  6743. }
  6744. /***/ }),
  6745. /* 20 */
  6746. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6747. Object.defineProperty(exports, "__esModule", ({
  6748. value: true
  6749. }));
  6750. exports.PDFLayerViewer = void 0;
  6751. var _base_tree_viewer = __webpack_require__(14);
  6752. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  6753. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  6754. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  6755. var _updateLayers = /*#__PURE__*/new WeakSet();
  6756. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  6757. constructor(options) {
  6758. super(options);
  6759. _classPrivateMethodInitSpec(this, _updateLayers);
  6760. this.l10n = options.l10n;
  6761. this.eventBus._on("optionalcontentconfigchanged", evt => {
  6762. _classPrivateMethodGet(this, _updateLayers, _updateLayers2).call(this, evt.promise);
  6763. });
  6764. this.eventBus._on("resetlayers", () => {
  6765. _classPrivateMethodGet(this, _updateLayers, _updateLayers2).call(this);
  6766. });
  6767. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  6768. }
  6769. reset() {
  6770. super.reset();
  6771. this._optionalContentConfig = null;
  6772. this._optionalContentHash = null;
  6773. }
  6774. _dispatchEvent(layersCount) {
  6775. this.eventBus.dispatch("layersloaded", {
  6776. source: this,
  6777. layersCount
  6778. });
  6779. }
  6780. _bindLink(element, _ref) {
  6781. let {
  6782. groupId,
  6783. input
  6784. } = _ref;
  6785. const setVisibility = () => {
  6786. this._optionalContentConfig.setVisibility(groupId, input.checked);
  6787. this._optionalContentHash = this._optionalContentConfig.getHash();
  6788. this.eventBus.dispatch("optionalcontentconfig", {
  6789. source: this,
  6790. promise: Promise.resolve(this._optionalContentConfig)
  6791. });
  6792. };
  6793. element.onclick = evt => {
  6794. if (evt.target === input) {
  6795. setVisibility();
  6796. return true;
  6797. } else if (evt.target !== element) {
  6798. return true;
  6799. }
  6800. input.checked = !input.checked;
  6801. setVisibility();
  6802. return false;
  6803. };
  6804. }
  6805. async _setNestedName(element, _ref2) {
  6806. let {
  6807. name = null
  6808. } = _ref2;
  6809. if (typeof name === "string") {
  6810. element.textContent = this._normalizeTextContent(name);
  6811. return;
  6812. }
  6813. element.textContent = await this.l10n.get("additional_layers");
  6814. element.style.fontStyle = "italic";
  6815. }
  6816. _addToggleButton(div, _ref3) {
  6817. let {
  6818. name = null
  6819. } = _ref3;
  6820. super._addToggleButton(div, name === null);
  6821. }
  6822. _toggleAllTreeItems() {
  6823. if (!this._optionalContentConfig) {
  6824. return;
  6825. }
  6826. super._toggleAllTreeItems();
  6827. }
  6828. render(_ref4) {
  6829. let {
  6830. optionalContentConfig,
  6831. pdfDocument
  6832. } = _ref4;
  6833. if (this._optionalContentConfig) {
  6834. this.reset();
  6835. }
  6836. this._optionalContentConfig = optionalContentConfig || null;
  6837. this._pdfDocument = pdfDocument || null;
  6838. const groups = optionalContentConfig === null || optionalContentConfig === void 0 ? void 0 : optionalContentConfig.getOrder();
  6839. if (!groups) {
  6840. this._dispatchEvent(0);
  6841. return;
  6842. }
  6843. this._optionalContentHash = optionalContentConfig.getHash();
  6844. const fragment = document.createDocumentFragment(),
  6845. queue = [{
  6846. parent: fragment,
  6847. groups
  6848. }];
  6849. let layersCount = 0,
  6850. hasAnyNesting = false;
  6851. while (queue.length > 0) {
  6852. const levelData = queue.shift();
  6853. for (const groupId of levelData.groups) {
  6854. const div = document.createElement("div");
  6855. div.className = "treeItem";
  6856. const element = document.createElement("a");
  6857. div.append(element);
  6858. if (typeof groupId === "object") {
  6859. hasAnyNesting = true;
  6860. this._addToggleButton(div, groupId);
  6861. this._setNestedName(element, groupId);
  6862. const itemsDiv = document.createElement("div");
  6863. itemsDiv.className = "treeItems";
  6864. div.append(itemsDiv);
  6865. queue.push({
  6866. parent: itemsDiv,
  6867. groups: groupId.order
  6868. });
  6869. } else {
  6870. const group = optionalContentConfig.getGroup(groupId);
  6871. const input = document.createElement("input");
  6872. this._bindLink(element, {
  6873. groupId,
  6874. input
  6875. });
  6876. input.type = "checkbox";
  6877. input.checked = group.visible;
  6878. const label = document.createElement("label");
  6879. label.textContent = this._normalizeTextContent(group.name);
  6880. label.append(input);
  6881. element.append(label);
  6882. layersCount++;
  6883. }
  6884. levelData.parent.append(div);
  6885. }
  6886. }
  6887. this._finishRendering(fragment, layersCount, hasAnyNesting);
  6888. }
  6889. }
  6890. exports.PDFLayerViewer = PDFLayerViewer;
  6891. async function _updateLayers2() {
  6892. let promise = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  6893. if (!this._optionalContentConfig) {
  6894. return;
  6895. }
  6896. const pdfDocument = this._pdfDocument;
  6897. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig());
  6898. if (pdfDocument !== this._pdfDocument) {
  6899. return;
  6900. }
  6901. if (promise) {
  6902. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  6903. return;
  6904. }
  6905. } else {
  6906. this.eventBus.dispatch("optionalcontentconfig", {
  6907. source: this,
  6908. promise: Promise.resolve(optionalContentConfig)
  6909. });
  6910. }
  6911. this.render({
  6912. optionalContentConfig,
  6913. pdfDocument: this._pdfDocument
  6914. });
  6915. }
  6916. /***/ }),
  6917. /* 21 */
  6918. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6919. Object.defineProperty(exports, "__esModule", ({
  6920. value: true
  6921. }));
  6922. exports.PDFOutlineViewer = void 0;
  6923. var _base_tree_viewer = __webpack_require__(14);
  6924. var _pdfjsLib = __webpack_require__(5);
  6925. var _ui_utils = __webpack_require__(1);
  6926. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  6927. constructor(options) {
  6928. super(options);
  6929. this.linkService = options.linkService;
  6930. this.downloadManager = options.downloadManager;
  6931. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6932. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6933. this.eventBus._on("pagechanging", evt => {
  6934. this._currentPageNumber = evt.pageNumber;
  6935. });
  6936. this.eventBus._on("pagesloaded", evt => {
  6937. this._isPagesLoaded = !!evt.pagesCount;
  6938. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6939. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6940. }
  6941. });
  6942. this.eventBus._on("sidebarviewchanged", evt => {
  6943. this._sidebarView = evt.view;
  6944. });
  6945. }
  6946. reset() {
  6947. super.reset();
  6948. this._outline = null;
  6949. this._pageNumberToDestHashCapability = null;
  6950. this._currentPageNumber = 1;
  6951. this._isPagesLoaded = null;
  6952. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6953. this._currentOutlineItemCapability.resolve(false);
  6954. }
  6955. this._currentOutlineItemCapability = null;
  6956. }
  6957. _dispatchEvent(outlineCount) {
  6958. var _this$_pdfDocument;
  6959. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  6960. if (outlineCount === 0 || (_this$_pdfDocument = this._pdfDocument) !== null && _this$_pdfDocument !== void 0 && _this$_pdfDocument.loadingParams.disableAutoFetch) {
  6961. this._currentOutlineItemCapability.resolve(false);
  6962. } else if (this._isPagesLoaded !== null) {
  6963. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6964. }
  6965. this.eventBus.dispatch("outlineloaded", {
  6966. source: this,
  6967. outlineCount,
  6968. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6969. });
  6970. }
  6971. _bindLink(element, _ref) {
  6972. let {
  6973. url,
  6974. newWindow,
  6975. action,
  6976. attachment,
  6977. dest,
  6978. setOCGState
  6979. } = _ref;
  6980. const {
  6981. linkService
  6982. } = this;
  6983. if (url) {
  6984. linkService.addLinkAttributes(element, url, newWindow);
  6985. return;
  6986. }
  6987. if (action) {
  6988. element.href = linkService.getAnchorUrl("");
  6989. element.onclick = () => {
  6990. linkService.executeNamedAction(action);
  6991. return false;
  6992. };
  6993. return;
  6994. }
  6995. if (attachment) {
  6996. element.href = linkService.getAnchorUrl("");
  6997. element.onclick = () => {
  6998. this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename);
  6999. return false;
  7000. };
  7001. return;
  7002. }
  7003. if (setOCGState) {
  7004. element.href = linkService.getAnchorUrl("");
  7005. element.onclick = () => {
  7006. linkService.executeSetOCGState(setOCGState);
  7007. return false;
  7008. };
  7009. return;
  7010. }
  7011. element.href = linkService.getDestinationHash(dest);
  7012. element.onclick = evt => {
  7013. this._updateCurrentTreeItem(evt.target.parentNode);
  7014. if (dest) {
  7015. linkService.goToDestination(dest);
  7016. }
  7017. return false;
  7018. };
  7019. }
  7020. _setStyles(element, _ref2) {
  7021. let {
  7022. bold,
  7023. italic
  7024. } = _ref2;
  7025. if (bold) {
  7026. element.style.fontWeight = "bold";
  7027. }
  7028. if (italic) {
  7029. element.style.fontStyle = "italic";
  7030. }
  7031. }
  7032. _addToggleButton(div, _ref3) {
  7033. let {
  7034. count,
  7035. items
  7036. } = _ref3;
  7037. let hidden = false;
  7038. if (count < 0) {
  7039. let totalCount = items.length;
  7040. if (totalCount > 0) {
  7041. const queue = [...items];
  7042. while (queue.length > 0) {
  7043. const {
  7044. count: nestedCount,
  7045. items: nestedItems
  7046. } = queue.shift();
  7047. if (nestedCount > 0 && nestedItems.length > 0) {
  7048. totalCount += nestedItems.length;
  7049. queue.push(...nestedItems);
  7050. }
  7051. }
  7052. }
  7053. if (Math.abs(count) === totalCount) {
  7054. hidden = true;
  7055. }
  7056. }
  7057. super._addToggleButton(div, hidden);
  7058. }
  7059. _toggleAllTreeItems() {
  7060. if (!this._outline) {
  7061. return;
  7062. }
  7063. super._toggleAllTreeItems();
  7064. }
  7065. render(_ref4) {
  7066. let {
  7067. outline,
  7068. pdfDocument
  7069. } = _ref4;
  7070. if (this._outline) {
  7071. this.reset();
  7072. }
  7073. this._outline = outline || null;
  7074. this._pdfDocument = pdfDocument || null;
  7075. if (!outline) {
  7076. this._dispatchEvent(0);
  7077. return;
  7078. }
  7079. const fragment = document.createDocumentFragment();
  7080. const queue = [{
  7081. parent: fragment,
  7082. items: outline
  7083. }];
  7084. let outlineCount = 0,
  7085. hasAnyNesting = false;
  7086. while (queue.length > 0) {
  7087. const levelData = queue.shift();
  7088. for (const item of levelData.items) {
  7089. const div = document.createElement("div");
  7090. div.className = "treeItem";
  7091. const element = document.createElement("a");
  7092. this._bindLink(element, item);
  7093. this._setStyles(element, item);
  7094. element.textContent = this._normalizeTextContent(item.title);
  7095. div.append(element);
  7096. if (item.items.length > 0) {
  7097. hasAnyNesting = true;
  7098. this._addToggleButton(div, item);
  7099. const itemsDiv = document.createElement("div");
  7100. itemsDiv.className = "treeItems";
  7101. div.append(itemsDiv);
  7102. queue.push({
  7103. parent: itemsDiv,
  7104. items: item.items
  7105. });
  7106. }
  7107. levelData.parent.append(div);
  7108. outlineCount++;
  7109. }
  7110. }
  7111. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  7112. }
  7113. async _currentOutlineItem() {
  7114. if (!this._isPagesLoaded) {
  7115. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  7116. }
  7117. if (!this._outline || !this._pdfDocument) {
  7118. return;
  7119. }
  7120. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  7121. if (!pageNumberToDestHash) {
  7122. return;
  7123. }
  7124. this._updateCurrentTreeItem(null);
  7125. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  7126. return;
  7127. }
  7128. for (let i = this._currentPageNumber; i > 0; i--) {
  7129. const destHash = pageNumberToDestHash.get(i);
  7130. if (!destHash) {
  7131. continue;
  7132. }
  7133. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  7134. if (!linkElement) {
  7135. continue;
  7136. }
  7137. this._scrollToCurrentTreeItem(linkElement.parentNode);
  7138. break;
  7139. }
  7140. }
  7141. async _getPageNumberToDestHash(pdfDocument) {
  7142. if (this._pageNumberToDestHashCapability) {
  7143. return this._pageNumberToDestHashCapability.promise;
  7144. }
  7145. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  7146. const pageNumberToDestHash = new Map(),
  7147. pageNumberNesting = new Map();
  7148. const queue = [{
  7149. nesting: 0,
  7150. items: this._outline
  7151. }];
  7152. while (queue.length > 0) {
  7153. const levelData = queue.shift(),
  7154. currentNesting = levelData.nesting;
  7155. for (const {
  7156. dest,
  7157. items
  7158. } of levelData.items) {
  7159. let explicitDest, pageNumber;
  7160. if (typeof dest === "string") {
  7161. explicitDest = await pdfDocument.getDestination(dest);
  7162. if (pdfDocument !== this._pdfDocument) {
  7163. return null;
  7164. }
  7165. } else {
  7166. explicitDest = dest;
  7167. }
  7168. if (Array.isArray(explicitDest)) {
  7169. const [destRef] = explicitDest;
  7170. if (typeof destRef === "object" && destRef !== null) {
  7171. pageNumber = this.linkService._cachedPageNumber(destRef);
  7172. if (!pageNumber) {
  7173. try {
  7174. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  7175. if (pdfDocument !== this._pdfDocument) {
  7176. return null;
  7177. }
  7178. this.linkService.cachePageRef(pageNumber, destRef);
  7179. } catch (ex) {}
  7180. }
  7181. } else if (Number.isInteger(destRef)) {
  7182. pageNumber = destRef + 1;
  7183. }
  7184. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  7185. const destHash = this.linkService.getDestinationHash(dest);
  7186. pageNumberToDestHash.set(pageNumber, destHash);
  7187. pageNumberNesting.set(pageNumber, currentNesting);
  7188. }
  7189. }
  7190. if (items.length > 0) {
  7191. queue.push({
  7192. nesting: currentNesting + 1,
  7193. items
  7194. });
  7195. }
  7196. }
  7197. }
  7198. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  7199. return this._pageNumberToDestHashCapability.promise;
  7200. }
  7201. }
  7202. exports.PDFOutlineViewer = PDFOutlineViewer;
  7203. /***/ }),
  7204. /* 22 */
  7205. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7206. Object.defineProperty(exports, "__esModule", ({
  7207. value: true
  7208. }));
  7209. exports.PDFPresentationMode = void 0;
  7210. var _ui_utils = __webpack_require__(1);
  7211. var _pdfjsLib = __webpack_require__(5);
  7212. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  7213. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  7214. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  7215. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  7216. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  7217. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  7218. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  7219. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  7220. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  7221. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  7222. const ACTIVE_SELECTOR = "pdfPresentationMode";
  7223. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  7224. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  7225. const PAGE_SWITCH_THRESHOLD = 0.1;
  7226. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  7227. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  7228. var _state = /*#__PURE__*/new WeakMap();
  7229. var _args = /*#__PURE__*/new WeakMap();
  7230. var _mouseWheel = /*#__PURE__*/new WeakSet();
  7231. var _notifyStateChange = /*#__PURE__*/new WeakSet();
  7232. var _enter = /*#__PURE__*/new WeakSet();
  7233. var _exit = /*#__PURE__*/new WeakSet();
  7234. var _mouseDown = /*#__PURE__*/new WeakSet();
  7235. var _contextMenu = /*#__PURE__*/new WeakSet();
  7236. var _showControls = /*#__PURE__*/new WeakSet();
  7237. var _hideControls = /*#__PURE__*/new WeakSet();
  7238. var _resetMouseScrollState = /*#__PURE__*/new WeakSet();
  7239. var _touchSwipe = /*#__PURE__*/new WeakSet();
  7240. var _addWindowListeners = /*#__PURE__*/new WeakSet();
  7241. var _removeWindowListeners = /*#__PURE__*/new WeakSet();
  7242. var _fullscreenChange = /*#__PURE__*/new WeakSet();
  7243. var _addFullscreenChangeListeners = /*#__PURE__*/new WeakSet();
  7244. var _removeFullscreenChangeListeners = /*#__PURE__*/new WeakSet();
  7245. class PDFPresentationMode {
  7246. constructor(_ref) {
  7247. let {
  7248. container,
  7249. pdfViewer,
  7250. eventBus
  7251. } = _ref;
  7252. _classPrivateMethodInitSpec(this, _removeFullscreenChangeListeners);
  7253. _classPrivateMethodInitSpec(this, _addFullscreenChangeListeners);
  7254. _classPrivateMethodInitSpec(this, _fullscreenChange);
  7255. _classPrivateMethodInitSpec(this, _removeWindowListeners);
  7256. _classPrivateMethodInitSpec(this, _addWindowListeners);
  7257. _classPrivateMethodInitSpec(this, _touchSwipe);
  7258. _classPrivateMethodInitSpec(this, _resetMouseScrollState);
  7259. _classPrivateMethodInitSpec(this, _hideControls);
  7260. _classPrivateMethodInitSpec(this, _showControls);
  7261. _classPrivateMethodInitSpec(this, _contextMenu);
  7262. _classPrivateMethodInitSpec(this, _mouseDown);
  7263. _classPrivateMethodInitSpec(this, _exit);
  7264. _classPrivateMethodInitSpec(this, _enter);
  7265. _classPrivateMethodInitSpec(this, _notifyStateChange);
  7266. _classPrivateMethodInitSpec(this, _mouseWheel);
  7267. _classPrivateFieldInitSpec(this, _state, {
  7268. writable: true,
  7269. value: _ui_utils.PresentationModeState.UNKNOWN
  7270. });
  7271. _classPrivateFieldInitSpec(this, _args, {
  7272. writable: true,
  7273. value: null
  7274. });
  7275. this.container = container;
  7276. this.pdfViewer = pdfViewer;
  7277. this.eventBus = eventBus;
  7278. this.contextMenuOpen = false;
  7279. this.mouseScrollTimeStamp = 0;
  7280. this.mouseScrollDelta = 0;
  7281. this.touchSwipeState = null;
  7282. }
  7283. async request() {
  7284. const {
  7285. container,
  7286. pdfViewer
  7287. } = this;
  7288. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  7289. return false;
  7290. }
  7291. _classPrivateMethodGet(this, _addFullscreenChangeListeners, _addFullscreenChangeListeners2).call(this);
  7292. _classPrivateMethodGet(this, _notifyStateChange, _notifyStateChange2).call(this, _ui_utils.PresentationModeState.CHANGING);
  7293. const promise = container.requestFullscreen();
  7294. _classPrivateFieldSet(this, _args, {
  7295. pageNumber: pdfViewer.currentPageNumber,
  7296. scaleValue: pdfViewer.currentScaleValue,
  7297. scrollMode: pdfViewer.scrollMode,
  7298. spreadMode: null,
  7299. annotationEditorMode: null
  7300. });
  7301. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  7302. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  7303. _classPrivateFieldGet(this, _args).spreadMode = pdfViewer.spreadMode;
  7304. }
  7305. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  7306. _classPrivateFieldGet(this, _args).annotationEditorMode = pdfViewer.annotationEditorMode;
  7307. }
  7308. try {
  7309. await promise;
  7310. pdfViewer.focus();
  7311. return true;
  7312. } catch (reason) {
  7313. _classPrivateMethodGet(this, _removeFullscreenChangeListeners, _removeFullscreenChangeListeners2).call(this);
  7314. _classPrivateMethodGet(this, _notifyStateChange, _notifyStateChange2).call(this, _ui_utils.PresentationModeState.NORMAL);
  7315. }
  7316. return false;
  7317. }
  7318. get active() {
  7319. return _classPrivateFieldGet(this, _state) === _ui_utils.PresentationModeState.CHANGING || _classPrivateFieldGet(this, _state) === _ui_utils.PresentationModeState.FULLSCREEN;
  7320. }
  7321. }
  7322. exports.PDFPresentationMode = PDFPresentationMode;
  7323. function _mouseWheel2(evt) {
  7324. if (!this.active) {
  7325. return;
  7326. }
  7327. evt.preventDefault();
  7328. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  7329. const currentTime = Date.now();
  7330. const storedTime = this.mouseScrollTimeStamp;
  7331. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  7332. return;
  7333. }
  7334. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  7335. _classPrivateMethodGet(this, _resetMouseScrollState, _resetMouseScrollState2).call(this);
  7336. }
  7337. this.mouseScrollDelta += delta;
  7338. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  7339. const totalDelta = this.mouseScrollDelta;
  7340. _classPrivateMethodGet(this, _resetMouseScrollState, _resetMouseScrollState2).call(this);
  7341. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  7342. if (success) {
  7343. this.mouseScrollTimeStamp = currentTime;
  7344. }
  7345. }
  7346. }
  7347. function _notifyStateChange2(state) {
  7348. _classPrivateFieldSet(this, _state, state);
  7349. this.eventBus.dispatch("presentationmodechanged", {
  7350. source: this,
  7351. state
  7352. });
  7353. }
  7354. function _enter2() {
  7355. _classPrivateMethodGet(this, _notifyStateChange, _notifyStateChange2).call(this, _ui_utils.PresentationModeState.FULLSCREEN);
  7356. this.container.classList.add(ACTIVE_SELECTOR);
  7357. setTimeout(() => {
  7358. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  7359. if (_classPrivateFieldGet(this, _args).spreadMode !== null) {
  7360. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  7361. }
  7362. this.pdfViewer.currentPageNumber = _classPrivateFieldGet(this, _args).pageNumber;
  7363. this.pdfViewer.currentScaleValue = "page-fit";
  7364. if (_classPrivateFieldGet(this, _args).annotationEditorMode !== null) {
  7365. this.pdfViewer.annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  7366. }
  7367. }, 0);
  7368. _classPrivateMethodGet(this, _addWindowListeners, _addWindowListeners2).call(this);
  7369. _classPrivateMethodGet(this, _showControls, _showControls2).call(this);
  7370. this.contextMenuOpen = false;
  7371. window.getSelection().removeAllRanges();
  7372. }
  7373. function _exit2() {
  7374. const pageNumber = this.pdfViewer.currentPageNumber;
  7375. this.container.classList.remove(ACTIVE_SELECTOR);
  7376. setTimeout(() => {
  7377. _classPrivateMethodGet(this, _removeFullscreenChangeListeners, _removeFullscreenChangeListeners2).call(this);
  7378. _classPrivateMethodGet(this, _notifyStateChange, _notifyStateChange2).call(this, _ui_utils.PresentationModeState.NORMAL);
  7379. this.pdfViewer.scrollMode = _classPrivateFieldGet(this, _args).scrollMode;
  7380. if (_classPrivateFieldGet(this, _args).spreadMode !== null) {
  7381. this.pdfViewer.spreadMode = _classPrivateFieldGet(this, _args).spreadMode;
  7382. }
  7383. this.pdfViewer.currentScaleValue = _classPrivateFieldGet(this, _args).scaleValue;
  7384. this.pdfViewer.currentPageNumber = pageNumber;
  7385. if (_classPrivateFieldGet(this, _args).annotationEditorMode !== null) {
  7386. this.pdfViewer.annotationEditorMode = _classPrivateFieldGet(this, _args).annotationEditorMode;
  7387. }
  7388. _classPrivateFieldSet(this, _args, null);
  7389. }, 0);
  7390. _classPrivateMethodGet(this, _removeWindowListeners, _removeWindowListeners2).call(this);
  7391. _classPrivateMethodGet(this, _hideControls, _hideControls2).call(this);
  7392. _classPrivateMethodGet(this, _resetMouseScrollState, _resetMouseScrollState2).call(this);
  7393. this.contextMenuOpen = false;
  7394. }
  7395. function _mouseDown2(evt) {
  7396. var _evt$target$parentNod;
  7397. if (this.contextMenuOpen) {
  7398. this.contextMenuOpen = false;
  7399. evt.preventDefault();
  7400. return;
  7401. }
  7402. if (evt.button !== 0) {
  7403. return;
  7404. }
  7405. if (evt.target.href && (_evt$target$parentNod = evt.target.parentNode) !== null && _evt$target$parentNod !== void 0 && _evt$target$parentNod.hasAttribute("data-internal-link")) {
  7406. return;
  7407. }
  7408. evt.preventDefault();
  7409. if (evt.shiftKey) {
  7410. this.pdfViewer.previousPage();
  7411. } else {
  7412. this.pdfViewer.nextPage();
  7413. }
  7414. }
  7415. function _contextMenu2() {
  7416. this.contextMenuOpen = true;
  7417. }
  7418. function _showControls2() {
  7419. if (this.controlsTimeout) {
  7420. clearTimeout(this.controlsTimeout);
  7421. } else {
  7422. this.container.classList.add(CONTROLS_SELECTOR);
  7423. }
  7424. this.controlsTimeout = setTimeout(() => {
  7425. this.container.classList.remove(CONTROLS_SELECTOR);
  7426. delete this.controlsTimeout;
  7427. }, DELAY_BEFORE_HIDING_CONTROLS);
  7428. }
  7429. function _hideControls2() {
  7430. if (!this.controlsTimeout) {
  7431. return;
  7432. }
  7433. clearTimeout(this.controlsTimeout);
  7434. this.container.classList.remove(CONTROLS_SELECTOR);
  7435. delete this.controlsTimeout;
  7436. }
  7437. function _resetMouseScrollState2() {
  7438. this.mouseScrollTimeStamp = 0;
  7439. this.mouseScrollDelta = 0;
  7440. }
  7441. function _touchSwipe2(evt) {
  7442. if (!this.active) {
  7443. return;
  7444. }
  7445. if (evt.touches.length > 1) {
  7446. this.touchSwipeState = null;
  7447. return;
  7448. }
  7449. switch (evt.type) {
  7450. case "touchstart":
  7451. this.touchSwipeState = {
  7452. startX: evt.touches[0].pageX,
  7453. startY: evt.touches[0].pageY,
  7454. endX: evt.touches[0].pageX,
  7455. endY: evt.touches[0].pageY
  7456. };
  7457. break;
  7458. case "touchmove":
  7459. if (this.touchSwipeState === null) {
  7460. return;
  7461. }
  7462. this.touchSwipeState.endX = evt.touches[0].pageX;
  7463. this.touchSwipeState.endY = evt.touches[0].pageY;
  7464. evt.preventDefault();
  7465. break;
  7466. case "touchend":
  7467. if (this.touchSwipeState === null) {
  7468. return;
  7469. }
  7470. let delta = 0;
  7471. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  7472. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  7473. const absAngle = Math.abs(Math.atan2(dy, dx));
  7474. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  7475. delta = dx;
  7476. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  7477. delta = dy;
  7478. }
  7479. if (delta > 0) {
  7480. this.pdfViewer.previousPage();
  7481. } else if (delta < 0) {
  7482. this.pdfViewer.nextPage();
  7483. }
  7484. break;
  7485. }
  7486. }
  7487. function _addWindowListeners2() {
  7488. this.showControlsBind = _classPrivateMethodGet(this, _showControls, _showControls2).bind(this);
  7489. this.mouseDownBind = _classPrivateMethodGet(this, _mouseDown, _mouseDown2).bind(this);
  7490. this.mouseWheelBind = _classPrivateMethodGet(this, _mouseWheel, _mouseWheel2).bind(this);
  7491. this.resetMouseScrollStateBind = _classPrivateMethodGet(this, _resetMouseScrollState, _resetMouseScrollState2).bind(this);
  7492. this.contextMenuBind = _classPrivateMethodGet(this, _contextMenu, _contextMenu2).bind(this);
  7493. this.touchSwipeBind = _classPrivateMethodGet(this, _touchSwipe, _touchSwipe2).bind(this);
  7494. window.addEventListener("mousemove", this.showControlsBind);
  7495. window.addEventListener("mousedown", this.mouseDownBind);
  7496. window.addEventListener("wheel", this.mouseWheelBind, {
  7497. passive: false
  7498. });
  7499. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  7500. window.addEventListener("contextmenu", this.contextMenuBind);
  7501. window.addEventListener("touchstart", this.touchSwipeBind);
  7502. window.addEventListener("touchmove", this.touchSwipeBind);
  7503. window.addEventListener("touchend", this.touchSwipeBind);
  7504. }
  7505. function _removeWindowListeners2() {
  7506. window.removeEventListener("mousemove", this.showControlsBind);
  7507. window.removeEventListener("mousedown", this.mouseDownBind);
  7508. window.removeEventListener("wheel", this.mouseWheelBind, {
  7509. passive: false
  7510. });
  7511. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  7512. window.removeEventListener("contextmenu", this.contextMenuBind);
  7513. window.removeEventListener("touchstart", this.touchSwipeBind);
  7514. window.removeEventListener("touchmove", this.touchSwipeBind);
  7515. window.removeEventListener("touchend", this.touchSwipeBind);
  7516. delete this.showControlsBind;
  7517. delete this.mouseDownBind;
  7518. delete this.mouseWheelBind;
  7519. delete this.resetMouseScrollStateBind;
  7520. delete this.contextMenuBind;
  7521. delete this.touchSwipeBind;
  7522. }
  7523. function _fullscreenChange2() {
  7524. if (document.fullscreenElement) {
  7525. _classPrivateMethodGet(this, _enter, _enter2).call(this);
  7526. } else {
  7527. _classPrivateMethodGet(this, _exit, _exit2).call(this);
  7528. }
  7529. }
  7530. function _addFullscreenChangeListeners2() {
  7531. this.fullscreenChangeBind = _classPrivateMethodGet(this, _fullscreenChange, _fullscreenChange2).bind(this);
  7532. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  7533. }
  7534. function _removeFullscreenChangeListeners2() {
  7535. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  7536. delete this.fullscreenChangeBind;
  7537. }
  7538. /***/ }),
  7539. /* 23 */
  7540. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7541. Object.defineProperty(exports, "__esModule", ({
  7542. value: true
  7543. }));
  7544. exports.PDFRenderingQueue = void 0;
  7545. var _pdfjsLib = __webpack_require__(5);
  7546. var _ui_utils = __webpack_require__(1);
  7547. const CLEANUP_TIMEOUT = 30000;
  7548. class PDFRenderingQueue {
  7549. constructor() {
  7550. this.pdfViewer = null;
  7551. this.pdfThumbnailViewer = null;
  7552. this.onIdle = null;
  7553. this.highestPriorityPage = null;
  7554. this.idleTimeout = null;
  7555. this.printing = false;
  7556. this.isThumbnailViewEnabled = false;
  7557. }
  7558. setViewer(pdfViewer) {
  7559. this.pdfViewer = pdfViewer;
  7560. }
  7561. setThumbnailViewer(pdfThumbnailViewer) {
  7562. this.pdfThumbnailViewer = pdfThumbnailViewer;
  7563. }
  7564. isHighestPriority(view) {
  7565. return this.highestPriorityPage === view.renderingId;
  7566. }
  7567. hasViewer() {
  7568. return !!this.pdfViewer;
  7569. }
  7570. renderHighestPriority(currentlyVisiblePages) {
  7571. var _this$pdfThumbnailVie;
  7572. if (this.idleTimeout) {
  7573. clearTimeout(this.idleTimeout);
  7574. this.idleTimeout = null;
  7575. }
  7576. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  7577. return;
  7578. }
  7579. if (this.isThumbnailViewEnabled && (_this$pdfThumbnailVie = this.pdfThumbnailViewer) !== null && _this$pdfThumbnailVie !== void 0 && _this$pdfThumbnailVie.forceRendering()) {
  7580. return;
  7581. }
  7582. if (this.printing) {
  7583. return;
  7584. }
  7585. if (this.onIdle) {
  7586. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  7587. }
  7588. }
  7589. getHighestPriority(visible, views, scrolledDown) {
  7590. let preRenderExtra = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  7591. const visibleViews = visible.views,
  7592. numVisible = visibleViews.length;
  7593. if (numVisible === 0) {
  7594. return null;
  7595. }
  7596. for (let i = 0; i < numVisible; i++) {
  7597. const view = visibleViews[i].view;
  7598. if (!this.isViewFinished(view)) {
  7599. return view;
  7600. }
  7601. }
  7602. const firstId = visible.first.id,
  7603. lastId = visible.last.id;
  7604. if (lastId - firstId + 1 > numVisible) {
  7605. const visibleIds = visible.ids;
  7606. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  7607. const holeId = scrolledDown ? firstId + i : lastId - i;
  7608. if (visibleIds.has(holeId)) {
  7609. continue;
  7610. }
  7611. const holeView = views[holeId - 1];
  7612. if (!this.isViewFinished(holeView)) {
  7613. return holeView;
  7614. }
  7615. }
  7616. }
  7617. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  7618. let preRenderView = views[preRenderIndex];
  7619. if (preRenderView && !this.isViewFinished(preRenderView)) {
  7620. return preRenderView;
  7621. }
  7622. if (preRenderExtra) {
  7623. preRenderIndex += scrolledDown ? 1 : -1;
  7624. preRenderView = views[preRenderIndex];
  7625. if (preRenderView && !this.isViewFinished(preRenderView)) {
  7626. return preRenderView;
  7627. }
  7628. }
  7629. return null;
  7630. }
  7631. isViewFinished(view) {
  7632. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  7633. }
  7634. renderView(view) {
  7635. switch (view.renderingState) {
  7636. case _ui_utils.RenderingStates.FINISHED:
  7637. return false;
  7638. case _ui_utils.RenderingStates.PAUSED:
  7639. this.highestPriorityPage = view.renderingId;
  7640. view.resume();
  7641. break;
  7642. case _ui_utils.RenderingStates.RUNNING:
  7643. this.highestPriorityPage = view.renderingId;
  7644. break;
  7645. case _ui_utils.RenderingStates.INITIAL:
  7646. this.highestPriorityPage = view.renderingId;
  7647. view.draw().finally(() => {
  7648. this.renderHighestPriority();
  7649. }).catch(reason => {
  7650. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  7651. return;
  7652. }
  7653. console.error(`renderView: "${reason}"`);
  7654. });
  7655. break;
  7656. }
  7657. return true;
  7658. }
  7659. }
  7660. exports.PDFRenderingQueue = PDFRenderingQueue;
  7661. /***/ }),
  7662. /* 24 */
  7663. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7664. Object.defineProperty(exports, "__esModule", ({
  7665. value: true
  7666. }));
  7667. exports.PDFScriptingManager = void 0;
  7668. var _ui_utils = __webpack_require__(1);
  7669. var _pdfjsLib = __webpack_require__(5);
  7670. class PDFScriptingManager {
  7671. constructor(_ref) {
  7672. let {
  7673. eventBus,
  7674. sandboxBundleSrc = null,
  7675. scriptingFactory = null,
  7676. docPropertiesLookup = null
  7677. } = _ref;
  7678. this._pdfDocument = null;
  7679. this._pdfViewer = null;
  7680. this._closeCapability = null;
  7681. this._destroyCapability = null;
  7682. this._scripting = null;
  7683. this._mouseState = Object.create(null);
  7684. this._ready = false;
  7685. this._eventBus = eventBus;
  7686. this._sandboxBundleSrc = sandboxBundleSrc;
  7687. this._scriptingFactory = scriptingFactory;
  7688. this._docPropertiesLookup = docPropertiesLookup;
  7689. }
  7690. setViewer(pdfViewer) {
  7691. this._pdfViewer = pdfViewer;
  7692. }
  7693. async setDocument(pdfDocument) {
  7694. var _this$_scripting3;
  7695. if (this._pdfDocument) {
  7696. await this._destroyScripting();
  7697. }
  7698. this._pdfDocument = pdfDocument;
  7699. if (!pdfDocument) {
  7700. return;
  7701. }
  7702. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  7703. if (!objects && !docActions) {
  7704. await this._destroyScripting();
  7705. return;
  7706. }
  7707. if (pdfDocument !== this._pdfDocument) {
  7708. return;
  7709. }
  7710. try {
  7711. this._scripting = this._createScripting();
  7712. } catch (error) {
  7713. console.error(`PDFScriptingManager.setDocument: "${error === null || error === void 0 ? void 0 : error.message}".`);
  7714. await this._destroyScripting();
  7715. return;
  7716. }
  7717. this._internalEvents.set("updatefromsandbox", event => {
  7718. if ((event === null || event === void 0 ? void 0 : event.source) !== window) {
  7719. return;
  7720. }
  7721. this._updateFromSandbox(event.detail);
  7722. });
  7723. this._internalEvents.set("dispatcheventinsandbox", event => {
  7724. var _this$_scripting;
  7725. (_this$_scripting = this._scripting) === null || _this$_scripting === void 0 ? void 0 : _this$_scripting.dispatchEventInSandbox(event.detail);
  7726. });
  7727. this._internalEvents.set("pagechanging", _ref2 => {
  7728. let {
  7729. pageNumber,
  7730. previous
  7731. } = _ref2;
  7732. if (pageNumber === previous) {
  7733. return;
  7734. }
  7735. this._dispatchPageClose(previous);
  7736. this._dispatchPageOpen(pageNumber);
  7737. });
  7738. this._internalEvents.set("pagerendered", _ref3 => {
  7739. let {
  7740. pageNumber
  7741. } = _ref3;
  7742. if (!this._pageOpenPending.has(pageNumber)) {
  7743. return;
  7744. }
  7745. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  7746. return;
  7747. }
  7748. this._dispatchPageOpen(pageNumber);
  7749. });
  7750. this._internalEvents.set("pagesdestroy", async event => {
  7751. var _this$_scripting2, _this$_closeCapabilit;
  7752. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  7753. await ((_this$_scripting2 = this._scripting) === null || _this$_scripting2 === void 0 ? void 0 : _this$_scripting2.dispatchEventInSandbox({
  7754. id: "doc",
  7755. name: "WillClose"
  7756. }));
  7757. (_this$_closeCapabilit = this._closeCapability) === null || _this$_closeCapabilit === void 0 ? void 0 : _this$_closeCapabilit.resolve();
  7758. });
  7759. this._domEvents.set("mousedown", event => {
  7760. this._mouseState.isDown = true;
  7761. });
  7762. this._domEvents.set("mouseup", event => {
  7763. this._mouseState.isDown = false;
  7764. });
  7765. for (const [name, listener] of this._internalEvents) {
  7766. this._eventBus._on(name, listener);
  7767. }
  7768. for (const [name, listener] of this._domEvents) {
  7769. window.addEventListener(name, listener, true);
  7770. }
  7771. try {
  7772. const docProperties = await this._getDocProperties();
  7773. if (pdfDocument !== this._pdfDocument) {
  7774. return;
  7775. }
  7776. await this._scripting.createSandbox({
  7777. objects,
  7778. calculationOrder,
  7779. appInfo: {
  7780. platform: navigator.platform,
  7781. language: navigator.language
  7782. },
  7783. docInfo: {
  7784. ...docProperties,
  7785. actions: docActions
  7786. }
  7787. });
  7788. this._eventBus.dispatch("sandboxcreated", {
  7789. source: this
  7790. });
  7791. } catch (error) {
  7792. console.error(`PDFScriptingManager.setDocument: "${error === null || error === void 0 ? void 0 : error.message}".`);
  7793. await this._destroyScripting();
  7794. return;
  7795. }
  7796. await ((_this$_scripting3 = this._scripting) === null || _this$_scripting3 === void 0 ? void 0 : _this$_scripting3.dispatchEventInSandbox({
  7797. id: "doc",
  7798. name: "Open"
  7799. }));
  7800. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  7801. Promise.resolve().then(() => {
  7802. if (pdfDocument === this._pdfDocument) {
  7803. this._ready = true;
  7804. }
  7805. });
  7806. }
  7807. async dispatchWillSave(detail) {
  7808. var _this$_scripting4;
  7809. return (_this$_scripting4 = this._scripting) === null || _this$_scripting4 === void 0 ? void 0 : _this$_scripting4.dispatchEventInSandbox({
  7810. id: "doc",
  7811. name: "WillSave"
  7812. });
  7813. }
  7814. async dispatchDidSave(detail) {
  7815. var _this$_scripting5;
  7816. return (_this$_scripting5 = this._scripting) === null || _this$_scripting5 === void 0 ? void 0 : _this$_scripting5.dispatchEventInSandbox({
  7817. id: "doc",
  7818. name: "DidSave"
  7819. });
  7820. }
  7821. async dispatchWillPrint(detail) {
  7822. var _this$_scripting6;
  7823. return (_this$_scripting6 = this._scripting) === null || _this$_scripting6 === void 0 ? void 0 : _this$_scripting6.dispatchEventInSandbox({
  7824. id: "doc",
  7825. name: "WillPrint"
  7826. });
  7827. }
  7828. async dispatchDidPrint(detail) {
  7829. var _this$_scripting7;
  7830. return (_this$_scripting7 = this._scripting) === null || _this$_scripting7 === void 0 ? void 0 : _this$_scripting7.dispatchEventInSandbox({
  7831. id: "doc",
  7832. name: "DidPrint"
  7833. });
  7834. }
  7835. get mouseState() {
  7836. return this._mouseState;
  7837. }
  7838. get destroyPromise() {
  7839. var _this$_destroyCapabil;
  7840. return ((_this$_destroyCapabil = this._destroyCapability) === null || _this$_destroyCapabil === void 0 ? void 0 : _this$_destroyCapabil.promise) || null;
  7841. }
  7842. get ready() {
  7843. return this._ready;
  7844. }
  7845. get _internalEvents() {
  7846. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  7847. }
  7848. get _domEvents() {
  7849. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  7850. }
  7851. get _pageOpenPending() {
  7852. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  7853. }
  7854. get _visitedPages() {
  7855. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  7856. }
  7857. async _updateFromSandbox(detail) {
  7858. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  7859. const {
  7860. id,
  7861. siblings,
  7862. command,
  7863. value
  7864. } = detail;
  7865. if (!id) {
  7866. switch (command) {
  7867. case "clear":
  7868. console.clear();
  7869. break;
  7870. case "error":
  7871. console.error(value);
  7872. break;
  7873. case "layout":
  7874. if (isInPresentationMode) {
  7875. return;
  7876. }
  7877. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  7878. this._pdfViewer.spreadMode = modes.spreadMode;
  7879. break;
  7880. case "page-num":
  7881. this._pdfViewer.currentPageNumber = value + 1;
  7882. break;
  7883. case "print":
  7884. await this._pdfViewer.pagesPromise;
  7885. this._eventBus.dispatch("print", {
  7886. source: this
  7887. });
  7888. break;
  7889. case "println":
  7890. console.log(value);
  7891. break;
  7892. case "zoom":
  7893. if (isInPresentationMode) {
  7894. return;
  7895. }
  7896. this._pdfViewer.currentScaleValue = value;
  7897. break;
  7898. case "SaveAs":
  7899. this._eventBus.dispatch("download", {
  7900. source: this
  7901. });
  7902. break;
  7903. case "FirstPage":
  7904. this._pdfViewer.currentPageNumber = 1;
  7905. break;
  7906. case "LastPage":
  7907. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  7908. break;
  7909. case "NextPage":
  7910. this._pdfViewer.nextPage();
  7911. break;
  7912. case "PrevPage":
  7913. this._pdfViewer.previousPage();
  7914. break;
  7915. case "ZoomViewIn":
  7916. if (isInPresentationMode) {
  7917. return;
  7918. }
  7919. this._pdfViewer.increaseScale();
  7920. break;
  7921. case "ZoomViewOut":
  7922. if (isInPresentationMode) {
  7923. return;
  7924. }
  7925. this._pdfViewer.decreaseScale();
  7926. break;
  7927. }
  7928. return;
  7929. }
  7930. if (isInPresentationMode) {
  7931. if (detail.focus) {
  7932. return;
  7933. }
  7934. }
  7935. delete detail.id;
  7936. delete detail.siblings;
  7937. const ids = siblings ? [id, ...siblings] : [id];
  7938. for (const elementId of ids) {
  7939. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  7940. if (element) {
  7941. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  7942. detail
  7943. }));
  7944. } else {
  7945. var _this$_pdfDocument;
  7946. (_this$_pdfDocument = this._pdfDocument) === null || _this$_pdfDocument === void 0 ? void 0 : _this$_pdfDocument.annotationStorage.setValue(elementId, detail);
  7947. }
  7948. }
  7949. }
  7950. async _dispatchPageOpen(pageNumber) {
  7951. let initialize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  7952. const pdfDocument = this._pdfDocument,
  7953. visitedPages = this._visitedPages;
  7954. if (initialize) {
  7955. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  7956. }
  7957. if (!this._closeCapability) {
  7958. return;
  7959. }
  7960. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  7961. if ((pageView === null || pageView === void 0 ? void 0 : pageView.renderingState) !== _ui_utils.RenderingStates.FINISHED) {
  7962. this._pageOpenPending.add(pageNumber);
  7963. return;
  7964. }
  7965. this._pageOpenPending.delete(pageNumber);
  7966. const actionsPromise = (async () => {
  7967. var _pageView$pdfPage, _this$_scripting8;
  7968. const actions = await (!visitedPages.has(pageNumber) ? (_pageView$pdfPage = pageView.pdfPage) === null || _pageView$pdfPage === void 0 ? void 0 : _pageView$pdfPage.getJSActions() : null);
  7969. if (pdfDocument !== this._pdfDocument) {
  7970. return;
  7971. }
  7972. await ((_this$_scripting8 = this._scripting) === null || _this$_scripting8 === void 0 ? void 0 : _this$_scripting8.dispatchEventInSandbox({
  7973. id: "page",
  7974. name: "PageOpen",
  7975. pageNumber,
  7976. actions
  7977. }));
  7978. })();
  7979. visitedPages.set(pageNumber, actionsPromise);
  7980. }
  7981. async _dispatchPageClose(pageNumber) {
  7982. var _this$_scripting9;
  7983. const pdfDocument = this._pdfDocument,
  7984. visitedPages = this._visitedPages;
  7985. if (!this._closeCapability) {
  7986. return;
  7987. }
  7988. if (this._pageOpenPending.has(pageNumber)) {
  7989. return;
  7990. }
  7991. const actionsPromise = visitedPages.get(pageNumber);
  7992. if (!actionsPromise) {
  7993. return;
  7994. }
  7995. visitedPages.set(pageNumber, null);
  7996. await actionsPromise;
  7997. if (pdfDocument !== this._pdfDocument) {
  7998. return;
  7999. }
  8000. await ((_this$_scripting9 = this._scripting) === null || _this$_scripting9 === void 0 ? void 0 : _this$_scripting9.dispatchEventInSandbox({
  8001. id: "page",
  8002. name: "PageClose",
  8003. pageNumber
  8004. }));
  8005. }
  8006. async _getDocProperties() {
  8007. if (this._docPropertiesLookup) {
  8008. return this._docPropertiesLookup(this._pdfDocument);
  8009. }
  8010. throw new Error("_getDocProperties: Unable to lookup properties.");
  8011. }
  8012. _createScripting() {
  8013. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  8014. if (this._scripting) {
  8015. throw new Error("_createScripting: Scripting already exists.");
  8016. }
  8017. if (this._scriptingFactory) {
  8018. return this._scriptingFactory.createScripting({
  8019. sandboxBundleSrc: this._sandboxBundleSrc
  8020. });
  8021. }
  8022. throw new Error("_createScripting: Cannot create scripting.");
  8023. }
  8024. async _destroyScripting() {
  8025. var _this$_destroyCapabil3;
  8026. if (!this._scripting) {
  8027. var _this$_destroyCapabil2;
  8028. this._pdfDocument = null;
  8029. (_this$_destroyCapabil2 = this._destroyCapability) === null || _this$_destroyCapabil2 === void 0 ? void 0 : _this$_destroyCapabil2.resolve();
  8030. return;
  8031. }
  8032. if (this._closeCapability) {
  8033. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  8034. setTimeout(resolve, 1000);
  8035. })]).catch(reason => {});
  8036. this._closeCapability = null;
  8037. }
  8038. this._pdfDocument = null;
  8039. try {
  8040. await this._scripting.destroySandbox();
  8041. } catch (ex) {}
  8042. for (const [name, listener] of this._internalEvents) {
  8043. this._eventBus._off(name, listener);
  8044. }
  8045. this._internalEvents.clear();
  8046. for (const [name, listener] of this._domEvents) {
  8047. window.removeEventListener(name, listener, true);
  8048. }
  8049. this._domEvents.clear();
  8050. this._pageOpenPending.clear();
  8051. this._visitedPages.clear();
  8052. this._scripting = null;
  8053. delete this._mouseState.isDown;
  8054. this._ready = false;
  8055. (_this$_destroyCapabil3 = this._destroyCapability) === null || _this$_destroyCapabil3 === void 0 ? void 0 : _this$_destroyCapabil3.resolve();
  8056. }
  8057. }
  8058. exports.PDFScriptingManager = PDFScriptingManager;
  8059. /***/ }),
  8060. /* 25 */
  8061. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8062. Object.defineProperty(exports, "__esModule", ({
  8063. value: true
  8064. }));
  8065. exports.PDFSidebar = void 0;
  8066. var _ui_utils = __webpack_require__(1);
  8067. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  8068. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  8069. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  8070. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  8071. var _dispatchEvent = /*#__PURE__*/new WeakSet();
  8072. var _forceRendering = /*#__PURE__*/new WeakSet();
  8073. var _updateThumbnailViewer = /*#__PURE__*/new WeakSet();
  8074. var _showUINotification = /*#__PURE__*/new WeakSet();
  8075. var _hideUINotification = /*#__PURE__*/new WeakSet();
  8076. var _addEventListeners = /*#__PURE__*/new WeakSet();
  8077. class PDFSidebar {
  8078. constructor(_ref) {
  8079. let {
  8080. elements,
  8081. pdfViewer: _pdfViewer,
  8082. pdfThumbnailViewer: _pdfThumbnailViewer,
  8083. eventBus,
  8084. l10n
  8085. } = _ref;
  8086. _classPrivateMethodInitSpec(this, _addEventListeners);
  8087. _classPrivateMethodInitSpec(this, _hideUINotification);
  8088. _classPrivateMethodInitSpec(this, _showUINotification);
  8089. _classPrivateMethodInitSpec(this, _updateThumbnailViewer);
  8090. _classPrivateMethodInitSpec(this, _forceRendering);
  8091. _classPrivateMethodInitSpec(this, _dispatchEvent);
  8092. this.isOpen = false;
  8093. this.active = _ui_utils.SidebarView.THUMBS;
  8094. this.isInitialViewSet = false;
  8095. this.isInitialEventDispatched = false;
  8096. this.onToggled = null;
  8097. this.pdfViewer = _pdfViewer;
  8098. this.pdfThumbnailViewer = _pdfThumbnailViewer;
  8099. this.outerContainer = elements.outerContainer;
  8100. this.sidebarContainer = elements.sidebarContainer;
  8101. this.toggleButton = elements.toggleButton;
  8102. this.thumbnailButton = elements.thumbnailButton;
  8103. this.outlineButton = elements.outlineButton;
  8104. this.attachmentsButton = elements.attachmentsButton;
  8105. this.layersButton = elements.layersButton;
  8106. this.thumbnailView = elements.thumbnailView;
  8107. this.outlineView = elements.outlineView;
  8108. this.attachmentsView = elements.attachmentsView;
  8109. this.layersView = elements.layersView;
  8110. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  8111. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  8112. this.eventBus = eventBus;
  8113. this.l10n = l10n;
  8114. _classPrivateMethodGet(this, _addEventListeners, _addEventListeners2).call(this);
  8115. }
  8116. reset() {
  8117. this.isInitialViewSet = false;
  8118. this.isInitialEventDispatched = false;
  8119. _classPrivateMethodGet(this, _hideUINotification, _hideUINotification2).call(this, true);
  8120. this.switchView(_ui_utils.SidebarView.THUMBS);
  8121. this.outlineButton.disabled = false;
  8122. this.attachmentsButton.disabled = false;
  8123. this.layersButton.disabled = false;
  8124. this._currentOutlineItemButton.disabled = true;
  8125. }
  8126. get visibleView() {
  8127. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  8128. }
  8129. setInitialView() {
  8130. let view = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _ui_utils.SidebarView.NONE;
  8131. if (this.isInitialViewSet) {
  8132. return;
  8133. }
  8134. this.isInitialViewSet = true;
  8135. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  8136. _classPrivateMethodGet(this, _dispatchEvent, _dispatchEvent2).call(this);
  8137. return;
  8138. }
  8139. this.switchView(view, true);
  8140. if (!this.isInitialEventDispatched) {
  8141. _classPrivateMethodGet(this, _dispatchEvent, _dispatchEvent2).call(this);
  8142. }
  8143. }
  8144. switchView(view) {
  8145. let forceOpen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  8146. const isViewChanged = view !== this.active;
  8147. let shouldForceRendering = false;
  8148. switch (view) {
  8149. case _ui_utils.SidebarView.NONE:
  8150. if (this.isOpen) {
  8151. this.close();
  8152. }
  8153. return;
  8154. case _ui_utils.SidebarView.THUMBS:
  8155. if (this.isOpen && isViewChanged) {
  8156. shouldForceRendering = true;
  8157. }
  8158. break;
  8159. case _ui_utils.SidebarView.OUTLINE:
  8160. if (this.outlineButton.disabled) {
  8161. return;
  8162. }
  8163. break;
  8164. case _ui_utils.SidebarView.ATTACHMENTS:
  8165. if (this.attachmentsButton.disabled) {
  8166. return;
  8167. }
  8168. break;
  8169. case _ui_utils.SidebarView.LAYERS:
  8170. if (this.layersButton.disabled) {
  8171. return;
  8172. }
  8173. break;
  8174. default:
  8175. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  8176. return;
  8177. }
  8178. this.active = view;
  8179. const isThumbs = view === _ui_utils.SidebarView.THUMBS,
  8180. isOutline = view === _ui_utils.SidebarView.OUTLINE,
  8181. isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS,
  8182. isLayers = view === _ui_utils.SidebarView.LAYERS;
  8183. this.thumbnailButton.classList.toggle("toggled", isThumbs);
  8184. this.outlineButton.classList.toggle("toggled", isOutline);
  8185. this.attachmentsButton.classList.toggle("toggled", isAttachments);
  8186. this.layersButton.classList.toggle("toggled", isLayers);
  8187. this.thumbnailButton.setAttribute("aria-checked", isThumbs);
  8188. this.outlineButton.setAttribute("aria-checked", isOutline);
  8189. this.attachmentsButton.setAttribute("aria-checked", isAttachments);
  8190. this.layersButton.setAttribute("aria-checked", isLayers);
  8191. this.thumbnailView.classList.toggle("hidden", !isThumbs);
  8192. this.outlineView.classList.toggle("hidden", !isOutline);
  8193. this.attachmentsView.classList.toggle("hidden", !isAttachments);
  8194. this.layersView.classList.toggle("hidden", !isLayers);
  8195. this._outlineOptionsContainer.classList.toggle("hidden", !isOutline);
  8196. if (forceOpen && !this.isOpen) {
  8197. this.open();
  8198. return;
  8199. }
  8200. if (shouldForceRendering) {
  8201. _classPrivateMethodGet(this, _updateThumbnailViewer, _updateThumbnailViewer2).call(this);
  8202. _classPrivateMethodGet(this, _forceRendering, _forceRendering2).call(this);
  8203. }
  8204. if (isViewChanged) {
  8205. _classPrivateMethodGet(this, _dispatchEvent, _dispatchEvent2).call(this);
  8206. }
  8207. }
  8208. open() {
  8209. if (this.isOpen) {
  8210. return;
  8211. }
  8212. this.isOpen = true;
  8213. this.toggleButton.classList.add("toggled");
  8214. this.toggleButton.setAttribute("aria-expanded", "true");
  8215. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  8216. if (this.active === _ui_utils.SidebarView.THUMBS) {
  8217. _classPrivateMethodGet(this, _updateThumbnailViewer, _updateThumbnailViewer2).call(this);
  8218. }
  8219. _classPrivateMethodGet(this, _forceRendering, _forceRendering2).call(this);
  8220. _classPrivateMethodGet(this, _dispatchEvent, _dispatchEvent2).call(this);
  8221. _classPrivateMethodGet(this, _hideUINotification, _hideUINotification2).call(this);
  8222. }
  8223. close() {
  8224. if (!this.isOpen) {
  8225. return;
  8226. }
  8227. this.isOpen = false;
  8228. this.toggleButton.classList.remove("toggled");
  8229. this.toggleButton.setAttribute("aria-expanded", "false");
  8230. this.outerContainer.classList.add("sidebarMoving");
  8231. this.outerContainer.classList.remove("sidebarOpen");
  8232. _classPrivateMethodGet(this, _forceRendering, _forceRendering2).call(this);
  8233. _classPrivateMethodGet(this, _dispatchEvent, _dispatchEvent2).call(this);
  8234. }
  8235. toggle() {
  8236. if (this.isOpen) {
  8237. this.close();
  8238. } else {
  8239. this.open();
  8240. }
  8241. }
  8242. }
  8243. exports.PDFSidebar = PDFSidebar;
  8244. function _dispatchEvent2() {
  8245. if (this.isInitialViewSet && !this.isInitialEventDispatched) {
  8246. this.isInitialEventDispatched = true;
  8247. }
  8248. this.eventBus.dispatch("sidebarviewchanged", {
  8249. source: this,
  8250. view: this.visibleView
  8251. });
  8252. }
  8253. function _forceRendering2() {
  8254. if (this.onToggled) {
  8255. this.onToggled();
  8256. } else {
  8257. this.pdfViewer.forceRendering();
  8258. this.pdfThumbnailViewer.forceRendering();
  8259. }
  8260. }
  8261. function _updateThumbnailViewer2() {
  8262. const {
  8263. pdfViewer,
  8264. pdfThumbnailViewer
  8265. } = this;
  8266. const pagesCount = pdfViewer.pagesCount;
  8267. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  8268. const pageView = pdfViewer.getPageView(pageIndex);
  8269. if ((pageView === null || pageView === void 0 ? void 0 : pageView.renderingState) === _ui_utils.RenderingStates.FINISHED) {
  8270. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  8271. thumbnailView.setImage(pageView);
  8272. }
  8273. }
  8274. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  8275. }
  8276. function _showUINotification2() {
  8277. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2");
  8278. this.l10n.translate(this.toggleButton);
  8279. if (!this.isOpen) {
  8280. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  8281. }
  8282. }
  8283. function _hideUINotification2() {
  8284. let reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  8285. if (this.isOpen || reset) {
  8286. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  8287. }
  8288. if (reset) {
  8289. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
  8290. this.l10n.translate(this.toggleButton);
  8291. }
  8292. }
  8293. function _addEventListeners2() {
  8294. this.sidebarContainer.addEventListener("transitionend", evt => {
  8295. if (evt.target === this.sidebarContainer) {
  8296. this.outerContainer.classList.remove("sidebarMoving");
  8297. }
  8298. });
  8299. this.toggleButton.addEventListener("click", () => {
  8300. this.toggle();
  8301. });
  8302. this.thumbnailButton.addEventListener("click", () => {
  8303. this.switchView(_ui_utils.SidebarView.THUMBS);
  8304. });
  8305. this.outlineButton.addEventListener("click", () => {
  8306. this.switchView(_ui_utils.SidebarView.OUTLINE);
  8307. });
  8308. this.outlineButton.addEventListener("dblclick", () => {
  8309. this.eventBus.dispatch("toggleoutlinetree", {
  8310. source: this
  8311. });
  8312. });
  8313. this.attachmentsButton.addEventListener("click", () => {
  8314. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  8315. });
  8316. this.layersButton.addEventListener("click", () => {
  8317. this.switchView(_ui_utils.SidebarView.LAYERS);
  8318. });
  8319. this.layersButton.addEventListener("dblclick", () => {
  8320. this.eventBus.dispatch("resetlayers", {
  8321. source: this
  8322. });
  8323. });
  8324. this._currentOutlineItemButton.addEventListener("click", () => {
  8325. this.eventBus.dispatch("currentoutlineitem", {
  8326. source: this
  8327. });
  8328. });
  8329. const onTreeLoaded = (count, button, view) => {
  8330. button.disabled = !count;
  8331. if (count) {
  8332. _classPrivateMethodGet(this, _showUINotification, _showUINotification2).call(this);
  8333. } else if (this.active === view) {
  8334. this.switchView(_ui_utils.SidebarView.THUMBS);
  8335. }
  8336. };
  8337. this.eventBus._on("outlineloaded", evt => {
  8338. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  8339. evt.currentOutlineItemPromise.then(enabled => {
  8340. if (!this.isInitialViewSet) {
  8341. return;
  8342. }
  8343. this._currentOutlineItemButton.disabled = !enabled;
  8344. });
  8345. });
  8346. this.eventBus._on("attachmentsloaded", evt => {
  8347. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  8348. });
  8349. this.eventBus._on("layersloaded", evt => {
  8350. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  8351. });
  8352. this.eventBus._on("presentationmodechanged", evt => {
  8353. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  8354. _classPrivateMethodGet(this, _updateThumbnailViewer, _updateThumbnailViewer2).call(this);
  8355. }
  8356. });
  8357. }
  8358. /***/ }),
  8359. /* 26 */
  8360. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8361. Object.defineProperty(exports, "__esModule", ({
  8362. value: true
  8363. }));
  8364. exports.PDFSidebarResizer = void 0;
  8365. var _ui_utils = __webpack_require__(1);
  8366. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  8367. const SIDEBAR_MIN_WIDTH = 200;
  8368. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  8369. class PDFSidebarResizer {
  8370. constructor(options, eventBus, l10n) {
  8371. this.isRTL = false;
  8372. this.sidebarOpen = false;
  8373. this._width = null;
  8374. this._outerContainerWidth = null;
  8375. this._boundEvents = Object.create(null);
  8376. this.outerContainer = options.outerContainer;
  8377. this.resizer = options.resizer;
  8378. this.eventBus = eventBus;
  8379. l10n.getDirection().then(dir => {
  8380. this.isRTL = dir === "rtl";
  8381. });
  8382. this._addEventListeners();
  8383. }
  8384. get outerContainerWidth() {
  8385. return this._outerContainerWidth || (this._outerContainerWidth = this.outerContainer.clientWidth);
  8386. }
  8387. _updateWidth() {
  8388. let width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  8389. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  8390. if (width > maxWidth) {
  8391. width = maxWidth;
  8392. }
  8393. if (width < SIDEBAR_MIN_WIDTH) {
  8394. width = SIDEBAR_MIN_WIDTH;
  8395. }
  8396. if (width === this._width) {
  8397. return false;
  8398. }
  8399. this._width = width;
  8400. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  8401. return true;
  8402. }
  8403. _mouseMove(evt) {
  8404. let width = evt.clientX;
  8405. if (this.isRTL) {
  8406. width = this.outerContainerWidth - width;
  8407. }
  8408. this._updateWidth(width);
  8409. }
  8410. _mouseUp(evt) {
  8411. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  8412. this.eventBus.dispatch("resize", {
  8413. source: this
  8414. });
  8415. const _boundEvents = this._boundEvents;
  8416. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  8417. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  8418. }
  8419. _addEventListeners() {
  8420. const _boundEvents = this._boundEvents;
  8421. _boundEvents.mouseMove = this._mouseMove.bind(this);
  8422. _boundEvents.mouseUp = this._mouseUp.bind(this);
  8423. this.resizer.addEventListener("mousedown", evt => {
  8424. if (evt.button !== 0) {
  8425. return;
  8426. }
  8427. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  8428. window.addEventListener("mousemove", _boundEvents.mouseMove);
  8429. window.addEventListener("mouseup", _boundEvents.mouseUp);
  8430. });
  8431. this.eventBus._on("sidebarviewchanged", evt => {
  8432. this.sidebarOpen = !!(evt !== null && evt !== void 0 && evt.view);
  8433. });
  8434. this.eventBus._on("resize", evt => {
  8435. if ((evt === null || evt === void 0 ? void 0 : evt.source) !== window) {
  8436. return;
  8437. }
  8438. this._outerContainerWidth = null;
  8439. if (!this._width) {
  8440. return;
  8441. }
  8442. if (!this.sidebarOpen) {
  8443. this._updateWidth(this._width);
  8444. return;
  8445. }
  8446. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  8447. const updated = this._updateWidth(this._width);
  8448. Promise.resolve().then(() => {
  8449. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  8450. if (updated) {
  8451. this.eventBus.dispatch("resize", {
  8452. source: this
  8453. });
  8454. }
  8455. });
  8456. });
  8457. }
  8458. }
  8459. exports.PDFSidebarResizer = PDFSidebarResizer;
  8460. /***/ }),
  8461. /* 27 */
  8462. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8463. Object.defineProperty(exports, "__esModule", ({
  8464. value: true
  8465. }));
  8466. exports.PDFThumbnailViewer = void 0;
  8467. var _ui_utils = __webpack_require__(1);
  8468. var _pdf_thumbnail_view = __webpack_require__(28);
  8469. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  8470. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  8471. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  8472. const THUMBNAIL_SCROLL_MARGIN = -19;
  8473. const THUMBNAIL_SELECTED_CLASS = "selected";
  8474. var _ensurePdfPageLoaded = /*#__PURE__*/new WeakSet();
  8475. var _getScrollAhead = /*#__PURE__*/new WeakSet();
  8476. class PDFThumbnailViewer {
  8477. constructor(_ref) {
  8478. let {
  8479. container,
  8480. eventBus,
  8481. linkService,
  8482. renderingQueue,
  8483. l10n,
  8484. pageColors
  8485. } = _ref;
  8486. _classPrivateMethodInitSpec(this, _getScrollAhead);
  8487. _classPrivateMethodInitSpec(this, _ensurePdfPageLoaded);
  8488. this.container = container;
  8489. this.linkService = linkService;
  8490. this.renderingQueue = renderingQueue;
  8491. this.l10n = l10n;
  8492. this.pageColors = pageColors || null;
  8493. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  8494. if (this.pageColors.background || this.pageColors.foreground) {
  8495. console.warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  8496. }
  8497. this.pageColors = null;
  8498. }
  8499. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  8500. this._resetView();
  8501. }
  8502. _scrollUpdated() {
  8503. this.renderingQueue.renderHighestPriority();
  8504. }
  8505. getThumbnail(index) {
  8506. return this._thumbnails[index];
  8507. }
  8508. _getVisibleThumbs() {
  8509. return (0, _ui_utils.getVisibleElements)({
  8510. scrollEl: this.container,
  8511. views: this._thumbnails
  8512. });
  8513. }
  8514. scrollThumbnailIntoView(pageNumber) {
  8515. if (!this.pdfDocument) {
  8516. return;
  8517. }
  8518. const thumbnailView = this._thumbnails[pageNumber - 1];
  8519. if (!thumbnailView) {
  8520. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  8521. return;
  8522. }
  8523. if (pageNumber !== this._currentPageNumber) {
  8524. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  8525. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  8526. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  8527. }
  8528. const {
  8529. first,
  8530. last,
  8531. views
  8532. } = this._getVisibleThumbs();
  8533. if (views.length > 0) {
  8534. let shouldScroll = false;
  8535. if (pageNumber <= first.id || pageNumber >= last.id) {
  8536. shouldScroll = true;
  8537. } else {
  8538. for (const {
  8539. id,
  8540. percent
  8541. } of views) {
  8542. if (id !== pageNumber) {
  8543. continue;
  8544. }
  8545. shouldScroll = percent < 100;
  8546. break;
  8547. }
  8548. }
  8549. if (shouldScroll) {
  8550. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  8551. top: THUMBNAIL_SCROLL_MARGIN
  8552. });
  8553. }
  8554. }
  8555. this._currentPageNumber = pageNumber;
  8556. }
  8557. get pagesRotation() {
  8558. return this._pagesRotation;
  8559. }
  8560. set pagesRotation(rotation) {
  8561. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8562. throw new Error("Invalid thumbnails rotation angle.");
  8563. }
  8564. if (!this.pdfDocument) {
  8565. return;
  8566. }
  8567. if (this._pagesRotation === rotation) {
  8568. return;
  8569. }
  8570. this._pagesRotation = rotation;
  8571. const updateArgs = {
  8572. rotation
  8573. };
  8574. for (const thumbnail of this._thumbnails) {
  8575. thumbnail.update(updateArgs);
  8576. }
  8577. }
  8578. cleanup() {
  8579. for (const thumbnail of this._thumbnails) {
  8580. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8581. thumbnail.reset();
  8582. }
  8583. }
  8584. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  8585. }
  8586. _resetView() {
  8587. this._thumbnails = [];
  8588. this._currentPageNumber = 1;
  8589. this._pageLabels = null;
  8590. this._pagesRotation = 0;
  8591. this.container.textContent = "";
  8592. }
  8593. setDocument(pdfDocument) {
  8594. if (this.pdfDocument) {
  8595. this._cancelRendering();
  8596. this._resetView();
  8597. }
  8598. this.pdfDocument = pdfDocument;
  8599. if (!pdfDocument) {
  8600. return;
  8601. }
  8602. const firstPagePromise = pdfDocument.getPage(1);
  8603. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8604. firstPagePromise.then(firstPdfPage => {
  8605. var _this$_thumbnails$;
  8606. const pagesCount = pdfDocument.numPages;
  8607. const viewport = firstPdfPage.getViewport({
  8608. scale: 1
  8609. });
  8610. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8611. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  8612. container: this.container,
  8613. id: pageNum,
  8614. defaultViewport: viewport.clone(),
  8615. optionalContentConfigPromise,
  8616. linkService: this.linkService,
  8617. renderingQueue: this.renderingQueue,
  8618. l10n: this.l10n,
  8619. pageColors: this.pageColors
  8620. });
  8621. this._thumbnails.push(thumbnail);
  8622. }
  8623. (_this$_thumbnails$ = this._thumbnails[0]) === null || _this$_thumbnails$ === void 0 ? void 0 : _this$_thumbnails$.setPdfPage(firstPdfPage);
  8624. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  8625. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  8626. }).catch(reason => {
  8627. console.error("Unable to initialize thumbnail viewer", reason);
  8628. });
  8629. }
  8630. _cancelRendering() {
  8631. for (const thumbnail of this._thumbnails) {
  8632. thumbnail.cancelRendering();
  8633. }
  8634. }
  8635. setPageLabels(labels) {
  8636. if (!this.pdfDocument) {
  8637. return;
  8638. }
  8639. if (!labels) {
  8640. this._pageLabels = null;
  8641. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8642. this._pageLabels = null;
  8643. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  8644. } else {
  8645. this._pageLabels = labels;
  8646. }
  8647. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  8648. var _this$_pageLabels;
  8649. this._thumbnails[i].setPageLabel(((_this$_pageLabels = this._pageLabels) === null || _this$_pageLabels === void 0 ? void 0 : _this$_pageLabels[i]) ?? null);
  8650. }
  8651. }
  8652. forceRendering() {
  8653. const visibleThumbs = this._getVisibleThumbs();
  8654. const scrollAhead = _classPrivateMethodGet(this, _getScrollAhead, _getScrollAhead2).call(this, visibleThumbs);
  8655. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  8656. if (thumbView) {
  8657. _classPrivateMethodGet(this, _ensurePdfPageLoaded, _ensurePdfPageLoaded2).call(this, thumbView).then(() => {
  8658. this.renderingQueue.renderView(thumbView);
  8659. });
  8660. return true;
  8661. }
  8662. return false;
  8663. }
  8664. }
  8665. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  8666. async function _ensurePdfPageLoaded2(thumbView) {
  8667. if (thumbView.pdfPage) {
  8668. return thumbView.pdfPage;
  8669. }
  8670. try {
  8671. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  8672. if (!thumbView.pdfPage) {
  8673. thumbView.setPdfPage(pdfPage);
  8674. }
  8675. return pdfPage;
  8676. } catch (reason) {
  8677. console.error("Unable to get page for thumb view", reason);
  8678. return null;
  8679. }
  8680. }
  8681. function _getScrollAhead2(visible) {
  8682. var _visible$first, _visible$last;
  8683. if (((_visible$first = visible.first) === null || _visible$first === void 0 ? void 0 : _visible$first.id) === 1) {
  8684. return true;
  8685. } else if (((_visible$last = visible.last) === null || _visible$last === void 0 ? void 0 : _visible$last.id) === this._thumbnails.length) {
  8686. return false;
  8687. }
  8688. return this.scroll.down;
  8689. }
  8690. /***/ }),
  8691. /* 28 */
  8692. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8693. Object.defineProperty(exports, "__esModule", ({
  8694. value: true
  8695. }));
  8696. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  8697. var _ui_utils = __webpack_require__(1);
  8698. var _pdfjsLib = __webpack_require__(5);
  8699. function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  8700. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  8701. function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  8702. function _classCheckPrivateStaticFieldDescriptor(descriptor, action) { if (descriptor === undefined) { throw new TypeError("attempted to " + action + " private static field before its declaration"); } }
  8703. function _classCheckPrivateStaticAccess(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } }
  8704. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  8705. const DRAW_UPSCALE_FACTOR = 2;
  8706. const MAX_NUM_SCALING_STEPS = 3;
  8707. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  8708. const THUMBNAIL_WIDTH = 98;
  8709. class TempImageFactory {
  8710. static getCanvas(width, height) {
  8711. const tempCanvas = _classStaticPrivateFieldSpecGet(this, TempImageFactory, _tempCanvas) || _classStaticPrivateFieldSpecSet(this, TempImageFactory, _tempCanvas, document.createElement("canvas"));
  8712. tempCanvas.width = width;
  8713. tempCanvas.height = height;
  8714. const ctx = tempCanvas.getContext("2d", {
  8715. alpha: false
  8716. });
  8717. ctx.save();
  8718. ctx.fillStyle = "rgb(255, 255, 255)";
  8719. ctx.fillRect(0, 0, width, height);
  8720. ctx.restore();
  8721. return [tempCanvas, tempCanvas.getContext("2d")];
  8722. }
  8723. static destroyCanvas() {
  8724. const tempCanvas = _classStaticPrivateFieldSpecGet(this, TempImageFactory, _tempCanvas);
  8725. if (tempCanvas) {
  8726. tempCanvas.width = 0;
  8727. tempCanvas.height = 0;
  8728. }
  8729. _classStaticPrivateFieldSpecSet(this, TempImageFactory, _tempCanvas, null);
  8730. }
  8731. }
  8732. exports.TempImageFactory = TempImageFactory;
  8733. var _tempCanvas = {
  8734. writable: true,
  8735. value: null
  8736. };
  8737. class PDFThumbnailView {
  8738. constructor(_ref) {
  8739. let {
  8740. container,
  8741. id,
  8742. defaultViewport,
  8743. optionalContentConfigPromise,
  8744. linkService,
  8745. renderingQueue,
  8746. l10n,
  8747. pageColors
  8748. } = _ref;
  8749. this.id = id;
  8750. this.renderingId = "thumbnail" + id;
  8751. this.pageLabel = null;
  8752. this.pdfPage = null;
  8753. this.rotation = 0;
  8754. this.viewport = defaultViewport;
  8755. this.pdfPageRotate = defaultViewport.rotation;
  8756. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  8757. this.pageColors = pageColors || null;
  8758. this.linkService = linkService;
  8759. this.renderingQueue = renderingQueue;
  8760. this.renderTask = null;
  8761. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  8762. this.resume = null;
  8763. const pageWidth = this.viewport.width,
  8764. pageHeight = this.viewport.height,
  8765. pageRatio = pageWidth / pageHeight;
  8766. this.canvasWidth = THUMBNAIL_WIDTH;
  8767. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  8768. this.scale = this.canvasWidth / pageWidth;
  8769. this.l10n = l10n;
  8770. const anchor = document.createElement("a");
  8771. anchor.href = linkService.getAnchorUrl("#page=" + id);
  8772. this._thumbPageTitle.then(msg => {
  8773. anchor.title = msg;
  8774. });
  8775. anchor.onclick = function () {
  8776. linkService.goToPage(id);
  8777. return false;
  8778. };
  8779. this.anchor = anchor;
  8780. const div = document.createElement("div");
  8781. div.className = "thumbnail";
  8782. div.setAttribute("data-page-number", this.id);
  8783. this.div = div;
  8784. const ring = document.createElement("div");
  8785. ring.className = "thumbnailSelectionRing";
  8786. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  8787. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  8788. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  8789. this.ring = ring;
  8790. div.append(ring);
  8791. anchor.append(div);
  8792. container.append(anchor);
  8793. }
  8794. setPdfPage(pdfPage) {
  8795. this.pdfPage = pdfPage;
  8796. this.pdfPageRotate = pdfPage.rotate;
  8797. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8798. this.viewport = pdfPage.getViewport({
  8799. scale: 1,
  8800. rotation: totalRotation
  8801. });
  8802. this.reset();
  8803. }
  8804. reset() {
  8805. this.cancelRendering();
  8806. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  8807. const pageWidth = this.viewport.width,
  8808. pageHeight = this.viewport.height,
  8809. pageRatio = pageWidth / pageHeight;
  8810. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  8811. this.scale = this.canvasWidth / pageWidth;
  8812. this.div.removeAttribute("data-loaded");
  8813. const ring = this.ring;
  8814. ring.textContent = "";
  8815. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  8816. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  8817. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  8818. if (this.canvas) {
  8819. this.canvas.width = 0;
  8820. this.canvas.height = 0;
  8821. delete this.canvas;
  8822. }
  8823. if (this.image) {
  8824. this.image.removeAttribute("src");
  8825. delete this.image;
  8826. }
  8827. }
  8828. update(_ref2) {
  8829. let {
  8830. rotation = null
  8831. } = _ref2;
  8832. if (typeof rotation === "number") {
  8833. this.rotation = rotation;
  8834. }
  8835. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8836. this.viewport = this.viewport.clone({
  8837. scale: 1,
  8838. rotation: totalRotation
  8839. });
  8840. this.reset();
  8841. }
  8842. cancelRendering() {
  8843. if (this.renderTask) {
  8844. this.renderTask.cancel();
  8845. this.renderTask = null;
  8846. }
  8847. this.resume = null;
  8848. }
  8849. _getPageDrawContext() {
  8850. let upscaleFactor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  8851. const canvas = document.createElement("canvas");
  8852. const ctx = canvas.getContext("2d", {
  8853. alpha: false
  8854. });
  8855. const outputScale = new _ui_utils.OutputScale();
  8856. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  8857. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  8858. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  8859. return {
  8860. ctx,
  8861. canvas,
  8862. transform
  8863. };
  8864. }
  8865. _convertCanvasToImage(canvas) {
  8866. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8867. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  8868. }
  8869. const reducedCanvas = this._reduceImage(canvas);
  8870. const image = document.createElement("img");
  8871. image.className = "thumbnailImage";
  8872. this._thumbPageCanvas.then(msg => {
  8873. image.setAttribute("aria-label", msg);
  8874. });
  8875. image.style.width = this.canvasWidth + "px";
  8876. image.style.height = this.canvasHeight + "px";
  8877. image.src = reducedCanvas.toDataURL();
  8878. this.image = image;
  8879. this.div.setAttribute("data-loaded", true);
  8880. this.ring.append(image);
  8881. reducedCanvas.width = 0;
  8882. reducedCanvas.height = 0;
  8883. }
  8884. draw() {
  8885. var _this = this;
  8886. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8887. console.error("Must be in new state before drawing");
  8888. return Promise.resolve();
  8889. }
  8890. const {
  8891. pdfPage
  8892. } = this;
  8893. if (!pdfPage) {
  8894. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8895. return Promise.reject(new Error("pdfPage is not loaded"));
  8896. }
  8897. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8898. const finishRenderTask = async function () {
  8899. let error = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  8900. if (renderTask === _this.renderTask) {
  8901. _this.renderTask = null;
  8902. }
  8903. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  8904. return;
  8905. }
  8906. _this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8907. _this._convertCanvasToImage(canvas);
  8908. if (error) {
  8909. throw error;
  8910. }
  8911. };
  8912. const {
  8913. ctx,
  8914. canvas,
  8915. transform
  8916. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  8917. const drawViewport = this.viewport.clone({
  8918. scale: DRAW_UPSCALE_FACTOR * this.scale
  8919. });
  8920. const renderContinueCallback = cont => {
  8921. if (!this.renderingQueue.isHighestPriority(this)) {
  8922. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  8923. this.resume = () => {
  8924. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8925. cont();
  8926. };
  8927. return;
  8928. }
  8929. cont();
  8930. };
  8931. const renderContext = {
  8932. canvasContext: ctx,
  8933. transform,
  8934. viewport: drawViewport,
  8935. optionalContentConfigPromise: this._optionalContentConfigPromise,
  8936. pageColors: this.pageColors
  8937. };
  8938. const renderTask = this.renderTask = pdfPage.render(renderContext);
  8939. renderTask.onContinue = renderContinueCallback;
  8940. const resultPromise = renderTask.promise.then(function () {
  8941. return finishRenderTask(null);
  8942. }, function (error) {
  8943. return finishRenderTask(error);
  8944. });
  8945. resultPromise.finally(() => {
  8946. canvas.width = 0;
  8947. canvas.height = 0;
  8948. const pageCached = this.linkService.isPageCached(this.id);
  8949. if (!pageCached) {
  8950. var _this$pdfPage;
  8951. (_this$pdfPage = this.pdfPage) === null || _this$pdfPage === void 0 ? void 0 : _this$pdfPage.cleanup();
  8952. }
  8953. });
  8954. return resultPromise;
  8955. }
  8956. setImage(pageView) {
  8957. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8958. return;
  8959. }
  8960. const {
  8961. thumbnailCanvas: canvas,
  8962. pdfPage,
  8963. scale
  8964. } = pageView;
  8965. if (!canvas) {
  8966. return;
  8967. }
  8968. if (!this.pdfPage) {
  8969. this.setPdfPage(pdfPage);
  8970. }
  8971. if (scale < this.scale) {
  8972. return;
  8973. }
  8974. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8975. this._convertCanvasToImage(canvas);
  8976. }
  8977. _reduceImage(img) {
  8978. const {
  8979. ctx,
  8980. canvas
  8981. } = this._getPageDrawContext();
  8982. if (img.width <= 2 * canvas.width) {
  8983. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  8984. return canvas;
  8985. }
  8986. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  8987. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  8988. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  8989. while (reducedWidth > img.width || reducedHeight > img.height) {
  8990. reducedWidth >>= 1;
  8991. reducedHeight >>= 1;
  8992. }
  8993. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  8994. while (reducedWidth > 2 * canvas.width) {
  8995. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  8996. reducedWidth >>= 1;
  8997. reducedHeight >>= 1;
  8998. }
  8999. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  9000. return canvas;
  9001. }
  9002. get _thumbPageTitle() {
  9003. return this.l10n.get("thumb_page_title", {
  9004. page: this.pageLabel ?? this.id
  9005. });
  9006. }
  9007. get _thumbPageCanvas() {
  9008. return this.l10n.get("thumb_page_canvas", {
  9009. page: this.pageLabel ?? this.id
  9010. });
  9011. }
  9012. setPageLabel(label) {
  9013. this.pageLabel = typeof label === "string" ? label : null;
  9014. this._thumbPageTitle.then(msg => {
  9015. this.anchor.title = msg;
  9016. });
  9017. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  9018. return;
  9019. }
  9020. this._thumbPageCanvas.then(msg => {
  9021. var _this$image;
  9022. (_this$image = this.image) === null || _this$image === void 0 ? void 0 : _this$image.setAttribute("aria-label", msg);
  9023. });
  9024. }
  9025. }
  9026. exports.PDFThumbnailView = PDFThumbnailView;
  9027. /***/ }),
  9028. /* 29 */
  9029. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9030. Object.defineProperty(exports, "__esModule", ({
  9031. value: true
  9032. }));
  9033. exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
  9034. var _pdfjsLib = __webpack_require__(5);
  9035. var _ui_utils = __webpack_require__(1);
  9036. var _annotation_editor_layer_builder = __webpack_require__(30);
  9037. var _annotation_layer_builder = __webpack_require__(32);
  9038. var _l10n_utils = __webpack_require__(31);
  9039. var _pdf_page_view = __webpack_require__(33);
  9040. var _pdf_rendering_queue = __webpack_require__(23);
  9041. var _pdf_link_service = __webpack_require__(3);
  9042. var _struct_tree_layer_builder = __webpack_require__(35);
  9043. var _text_highlighter = __webpack_require__(36);
  9044. var _text_layer_builder = __webpack_require__(37);
  9045. var _xfa_layer_builder = __webpack_require__(38);
  9046. let _Symbol$iterator;
  9047. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  9048. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  9049. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  9050. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  9051. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  9052. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  9053. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  9054. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  9055. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  9056. const DEFAULT_CACHE_SIZE = 10;
  9057. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  9058. const PagesCountLimit = {
  9059. FORCE_SCROLL_MODE_PAGE: 15000,
  9060. FORCE_LAZY_PAGE_INIT: 7500,
  9061. PAUSE_EAGER_PAGE_INIT: 250
  9062. };
  9063. exports.PagesCountLimit = PagesCountLimit;
  9064. function isValidAnnotationEditorMode(mode) {
  9065. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  9066. }
  9067. var _buf = /*#__PURE__*/new WeakMap();
  9068. var _size = /*#__PURE__*/new WeakMap();
  9069. var _destroyFirstView = /*#__PURE__*/new WeakSet();
  9070. _Symbol$iterator = Symbol.iterator;
  9071. class PDFPageViewBuffer {
  9072. constructor(size) {
  9073. _classPrivateMethodInitSpec(this, _destroyFirstView);
  9074. _classPrivateFieldInitSpec(this, _buf, {
  9075. writable: true,
  9076. value: new Set()
  9077. });
  9078. _classPrivateFieldInitSpec(this, _size, {
  9079. writable: true,
  9080. value: 0
  9081. });
  9082. _classPrivateFieldSet(this, _size, size);
  9083. }
  9084. push(view) {
  9085. const buf = _classPrivateFieldGet(this, _buf);
  9086. if (buf.has(view)) {
  9087. buf.delete(view);
  9088. }
  9089. buf.add(view);
  9090. if (buf.size > _classPrivateFieldGet(this, _size)) {
  9091. _classPrivateMethodGet(this, _destroyFirstView, _destroyFirstView2).call(this);
  9092. }
  9093. }
  9094. resize(newSize) {
  9095. let idsToKeep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  9096. _classPrivateFieldSet(this, _size, newSize);
  9097. const buf = _classPrivateFieldGet(this, _buf);
  9098. if (idsToKeep) {
  9099. const ii = buf.size;
  9100. let i = 1;
  9101. for (const view of buf) {
  9102. if (idsToKeep.has(view.id)) {
  9103. buf.delete(view);
  9104. buf.add(view);
  9105. }
  9106. if (++i > ii) {
  9107. break;
  9108. }
  9109. }
  9110. }
  9111. while (buf.size > _classPrivateFieldGet(this, _size)) {
  9112. _classPrivateMethodGet(this, _destroyFirstView, _destroyFirstView2).call(this);
  9113. }
  9114. }
  9115. has(view) {
  9116. return _classPrivateFieldGet(this, _buf).has(view);
  9117. }
  9118. [_Symbol$iterator]() {
  9119. return _classPrivateFieldGet(this, _buf).keys();
  9120. }
  9121. }
  9122. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  9123. function _destroyFirstView2() {
  9124. const firstView = _classPrivateFieldGet(this, _buf).keys().next().value;
  9125. firstView === null || firstView === void 0 ? void 0 : firstView.destroy();
  9126. _classPrivateFieldGet(this, _buf).delete(firstView);
  9127. }
  9128. var _buffer = /*#__PURE__*/new WeakMap();
  9129. var _annotationEditorMode = /*#__PURE__*/new WeakMap();
  9130. var _annotationEditorUIManager = /*#__PURE__*/new WeakMap();
  9131. var _annotationMode = /*#__PURE__*/new WeakMap();
  9132. var _enablePermissions = /*#__PURE__*/new WeakMap();
  9133. var _previousContainerHeight = /*#__PURE__*/new WeakMap();
  9134. var _scrollModePageState = /*#__PURE__*/new WeakMap();
  9135. var _onVisibilityChange = /*#__PURE__*/new WeakMap();
  9136. var _initializePermissions = /*#__PURE__*/new WeakSet();
  9137. var _onePageRenderedOrForceFetch = /*#__PURE__*/new WeakSet();
  9138. var _ensurePageViewVisible = /*#__PURE__*/new WeakSet();
  9139. var _scrollIntoView = /*#__PURE__*/new WeakSet();
  9140. var _isSameScale = /*#__PURE__*/new WeakSet();
  9141. var _resetCurrentPageView = /*#__PURE__*/new WeakSet();
  9142. var _ensurePdfPageLoaded = /*#__PURE__*/new WeakSet();
  9143. var _getScrollAhead = /*#__PURE__*/new WeakSet();
  9144. var _toggleLoadingIconSpinner = /*#__PURE__*/new WeakSet();
  9145. class PDFViewer {
  9146. constructor(options) {
  9147. var _this$container, _this$viewer;
  9148. _classPrivateMethodInitSpec(this, _toggleLoadingIconSpinner);
  9149. _classPrivateMethodInitSpec(this, _getScrollAhead);
  9150. _classPrivateMethodInitSpec(this, _ensurePdfPageLoaded);
  9151. _classPrivateMethodInitSpec(this, _resetCurrentPageView);
  9152. _classPrivateMethodInitSpec(this, _isSameScale);
  9153. _classPrivateMethodInitSpec(this, _scrollIntoView);
  9154. _classPrivateMethodInitSpec(this, _ensurePageViewVisible);
  9155. _classPrivateMethodInitSpec(this, _onePageRenderedOrForceFetch);
  9156. _classPrivateMethodInitSpec(this, _initializePermissions);
  9157. _classPrivateFieldInitSpec(this, _buffer, {
  9158. writable: true,
  9159. value: null
  9160. });
  9161. _classPrivateFieldInitSpec(this, _annotationEditorMode, {
  9162. writable: true,
  9163. value: _pdfjsLib.AnnotationEditorType.NONE
  9164. });
  9165. _classPrivateFieldInitSpec(this, _annotationEditorUIManager, {
  9166. writable: true,
  9167. value: null
  9168. });
  9169. _classPrivateFieldInitSpec(this, _annotationMode, {
  9170. writable: true,
  9171. value: _pdfjsLib.AnnotationMode.ENABLE_FORMS
  9172. });
  9173. _classPrivateFieldInitSpec(this, _enablePermissions, {
  9174. writable: true,
  9175. value: false
  9176. });
  9177. _classPrivateFieldInitSpec(this, _previousContainerHeight, {
  9178. writable: true,
  9179. value: 0
  9180. });
  9181. _classPrivateFieldInitSpec(this, _scrollModePageState, {
  9182. writable: true,
  9183. value: null
  9184. });
  9185. _classPrivateFieldInitSpec(this, _onVisibilityChange, {
  9186. writable: true,
  9187. value: null
  9188. });
  9189. const viewerVersion = '3.1.81';
  9190. if (_pdfjsLib.version !== viewerVersion) {
  9191. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  9192. }
  9193. this.container = options.container;
  9194. this.viewer = options.viewer || options.container.firstElementChild;
  9195. if (!(((_this$container = this.container) === null || _this$container === void 0 ? void 0 : _this$container.tagName.toUpperCase()) === "DIV" && ((_this$viewer = this.viewer) === null || _this$viewer === void 0 ? void 0 : _this$viewer.tagName.toUpperCase()) === "DIV")) {
  9196. throw new Error("Invalid `container` and/or `viewer` option.");
  9197. }
  9198. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  9199. throw new Error("The `container` must be absolutely positioned.");
  9200. }
  9201. this.eventBus = options.eventBus;
  9202. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  9203. this.downloadManager = options.downloadManager || null;
  9204. this.findController = options.findController || null;
  9205. this._scriptingManager = options.scriptingManager || null;
  9206. this.removePageBorders = options.removePageBorders || false;
  9207. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9208. _classPrivateFieldSet(this, _annotationMode, options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS);
  9209. _classPrivateFieldSet(this, _annotationEditorMode, options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE);
  9210. this.imageResourcesPath = options.imageResourcesPath || "";
  9211. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  9212. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9213. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9214. this.maxCanvasPixels = options.maxCanvasPixels;
  9215. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9216. _classPrivateFieldSet(this, _enablePermissions, options.enablePermissions || false);
  9217. this.pageColors = options.pageColors || null;
  9218. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  9219. if (this.pageColors.background || this.pageColors.foreground) {
  9220. console.warn("PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  9221. }
  9222. this.pageColors = null;
  9223. }
  9224. this.defaultRenderingQueue = !options.renderingQueue;
  9225. if (this.defaultRenderingQueue) {
  9226. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  9227. this.renderingQueue.setViewer(this);
  9228. } else {
  9229. this.renderingQueue = options.renderingQueue;
  9230. }
  9231. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  9232. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  9233. this._onBeforeDraw = this._onAfterDraw = null;
  9234. this._resetView();
  9235. if (this.removePageBorders) {
  9236. this.viewer.classList.add("removePageBorders");
  9237. }
  9238. this.updateContainerHeightCss();
  9239. }
  9240. get pagesCount() {
  9241. return this._pages.length;
  9242. }
  9243. getPageView(index) {
  9244. return this._pages[index];
  9245. }
  9246. get pageViewsReady() {
  9247. if (!this._pagesCapability.settled) {
  9248. return false;
  9249. }
  9250. return this._pages.every(function (pageView) {
  9251. return pageView === null || pageView === void 0 ? void 0 : pageView.pdfPage;
  9252. });
  9253. }
  9254. get renderForms() {
  9255. return _classPrivateFieldGet(this, _annotationMode) === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9256. }
  9257. get enableScripting() {
  9258. return !!this._scriptingManager;
  9259. }
  9260. get currentPageNumber() {
  9261. return this._currentPageNumber;
  9262. }
  9263. set currentPageNumber(val) {
  9264. if (!Number.isInteger(val)) {
  9265. throw new Error("Invalid page number.");
  9266. }
  9267. if (!this.pdfDocument) {
  9268. return;
  9269. }
  9270. if (!this._setCurrentPageNumber(val, true)) {
  9271. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  9272. }
  9273. }
  9274. _setCurrentPageNumber(val) {
  9275. var _this$_pageLabels;
  9276. let resetCurrentPageView = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  9277. if (this._currentPageNumber === val) {
  9278. if (resetCurrentPageView) {
  9279. _classPrivateMethodGet(this, _resetCurrentPageView, _resetCurrentPageView2).call(this);
  9280. }
  9281. return true;
  9282. }
  9283. if (!(0 < val && val <= this.pagesCount)) {
  9284. return false;
  9285. }
  9286. const previous = this._currentPageNumber;
  9287. this._currentPageNumber = val;
  9288. this.eventBus.dispatch("pagechanging", {
  9289. source: this,
  9290. pageNumber: val,
  9291. pageLabel: ((_this$_pageLabels = this._pageLabels) === null || _this$_pageLabels === void 0 ? void 0 : _this$_pageLabels[val - 1]) ?? null,
  9292. previous
  9293. });
  9294. if (resetCurrentPageView) {
  9295. _classPrivateMethodGet(this, _resetCurrentPageView, _resetCurrentPageView2).call(this);
  9296. }
  9297. return true;
  9298. }
  9299. get currentPageLabel() {
  9300. var _this$_pageLabels2;
  9301. return ((_this$_pageLabels2 = this._pageLabels) === null || _this$_pageLabels2 === void 0 ? void 0 : _this$_pageLabels2[this._currentPageNumber - 1]) ?? null;
  9302. }
  9303. set currentPageLabel(val) {
  9304. if (!this.pdfDocument) {
  9305. return;
  9306. }
  9307. let page = val | 0;
  9308. if (this._pageLabels) {
  9309. const i = this._pageLabels.indexOf(val);
  9310. if (i >= 0) {
  9311. page = i + 1;
  9312. }
  9313. }
  9314. if (!this._setCurrentPageNumber(page, true)) {
  9315. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  9316. }
  9317. }
  9318. get currentScale() {
  9319. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  9320. }
  9321. set currentScale(val) {
  9322. if (isNaN(val)) {
  9323. throw new Error("Invalid numeric scale.");
  9324. }
  9325. if (!this.pdfDocument) {
  9326. return;
  9327. }
  9328. this._setScale(val, false);
  9329. }
  9330. get currentScaleValue() {
  9331. return this._currentScaleValue;
  9332. }
  9333. set currentScaleValue(val) {
  9334. if (!this.pdfDocument) {
  9335. return;
  9336. }
  9337. this._setScale(val, false);
  9338. }
  9339. get pagesRotation() {
  9340. return this._pagesRotation;
  9341. }
  9342. set pagesRotation(rotation) {
  9343. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  9344. throw new Error("Invalid pages rotation angle.");
  9345. }
  9346. if (!this.pdfDocument) {
  9347. return;
  9348. }
  9349. rotation %= 360;
  9350. if (rotation < 0) {
  9351. rotation += 360;
  9352. }
  9353. if (this._pagesRotation === rotation) {
  9354. return;
  9355. }
  9356. this._pagesRotation = rotation;
  9357. const pageNumber = this._currentPageNumber;
  9358. const updateArgs = {
  9359. rotation
  9360. };
  9361. for (const pageView of this._pages) {
  9362. pageView.update(updateArgs);
  9363. }
  9364. if (this._currentScaleValue) {
  9365. this._setScale(this._currentScaleValue, true);
  9366. }
  9367. this.eventBus.dispatch("rotationchanging", {
  9368. source: this,
  9369. pagesRotation: rotation,
  9370. pageNumber
  9371. });
  9372. if (this.defaultRenderingQueue) {
  9373. this.update();
  9374. }
  9375. }
  9376. get firstPagePromise() {
  9377. return this.pdfDocument ? this._firstPageCapability.promise : null;
  9378. }
  9379. get onePageRendered() {
  9380. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  9381. }
  9382. get pagesPromise() {
  9383. return this.pdfDocument ? this._pagesCapability.promise : null;
  9384. }
  9385. setDocument(pdfDocument) {
  9386. if (this.pdfDocument) {
  9387. var _this$findController, _this$_scriptingManag;
  9388. this.eventBus.dispatch("pagesdestroy", {
  9389. source: this
  9390. });
  9391. this._cancelRendering();
  9392. this._resetView();
  9393. (_this$findController = this.findController) === null || _this$findController === void 0 ? void 0 : _this$findController.setDocument(null);
  9394. (_this$_scriptingManag = this._scriptingManager) === null || _this$_scriptingManag === void 0 ? void 0 : _this$_scriptingManag.setDocument(null);
  9395. if (_classPrivateFieldGet(this, _annotationEditorUIManager)) {
  9396. _classPrivateFieldGet(this, _annotationEditorUIManager).destroy();
  9397. _classPrivateFieldSet(this, _annotationEditorUIManager, null);
  9398. }
  9399. }
  9400. this.pdfDocument = pdfDocument;
  9401. if (!pdfDocument) {
  9402. return;
  9403. }
  9404. const isPureXfa = pdfDocument.isPureXfa;
  9405. const pagesCount = pdfDocument.numPages;
  9406. const firstPagePromise = pdfDocument.getPage(1);
  9407. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  9408. const permissionsPromise = _classPrivateFieldGet(this, _enablePermissions) ? pdfDocument.getPermissions() : Promise.resolve();
  9409. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9410. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  9411. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  9412. this.eventBus.dispatch("scrollmodechanged", {
  9413. source: this,
  9414. mode
  9415. });
  9416. }
  9417. this._pagesCapability.promise.then(() => {
  9418. this.eventBus.dispatch("pagesloaded", {
  9419. source: this,
  9420. pagesCount
  9421. });
  9422. }, () => {});
  9423. this._onBeforeDraw = evt => {
  9424. const pageView = this._pages[evt.pageNumber - 1];
  9425. if (!pageView) {
  9426. return;
  9427. }
  9428. _classPrivateFieldGet(this, _buffer).push(pageView);
  9429. };
  9430. this.eventBus._on("pagerender", this._onBeforeDraw);
  9431. this._onAfterDraw = evt => {
  9432. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  9433. return;
  9434. }
  9435. this._onePageRenderedCapability.resolve({
  9436. timestamp: evt.timestamp
  9437. });
  9438. this.eventBus._off("pagerendered", this._onAfterDraw);
  9439. this._onAfterDraw = null;
  9440. if (_classPrivateFieldGet(this, _onVisibilityChange)) {
  9441. document.removeEventListener("visibilitychange", _classPrivateFieldGet(this, _onVisibilityChange));
  9442. _classPrivateFieldSet(this, _onVisibilityChange, null);
  9443. }
  9444. };
  9445. this.eventBus._on("pagerendered", this._onAfterDraw);
  9446. Promise.all([firstPagePromise, permissionsPromise]).then(_ref => {
  9447. let [firstPdfPage, permissions] = _ref;
  9448. if (pdfDocument !== this.pdfDocument) {
  9449. return;
  9450. }
  9451. this._firstPageCapability.resolve(firstPdfPage);
  9452. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9453. const {
  9454. annotationEditorMode,
  9455. annotationMode,
  9456. textLayerMode
  9457. } = _classPrivateMethodGet(this, _initializePermissions, _initializePermissions2).call(this, permissions);
  9458. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  9459. const mode = annotationEditorMode;
  9460. if (isPureXfa) {
  9461. console.warn("Warning: XFA-editing is not implemented.");
  9462. } else if (isValidAnnotationEditorMode(mode)) {
  9463. _classPrivateFieldSet(this, _annotationEditorUIManager, new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus));
  9464. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  9465. _classPrivateFieldGet(this, _annotationEditorUIManager).updateMode(mode);
  9466. }
  9467. } else {
  9468. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  9469. }
  9470. }
  9471. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  9472. const scale = this.currentScale;
  9473. const viewport = firstPdfPage.getViewport({
  9474. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  9475. });
  9476. const textLayerFactory = textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !isPureXfa ? this : null;
  9477. const annotationLayerFactory = annotationMode !== _pdfjsLib.AnnotationMode.DISABLE ? this : null;
  9478. const xfaLayerFactory = isPureXfa ? this : null;
  9479. const annotationEditorLayerFactory = _classPrivateFieldGet(this, _annotationEditorUIManager) ? this : null;
  9480. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  9481. const pageView = new _pdf_page_view.PDFPageView({
  9482. container: viewerElement,
  9483. eventBus: this.eventBus,
  9484. id: pageNum,
  9485. scale,
  9486. defaultViewport: viewport.clone(),
  9487. optionalContentConfigPromise,
  9488. renderingQueue: this.renderingQueue,
  9489. textLayerFactory,
  9490. textLayerMode,
  9491. annotationLayerFactory,
  9492. annotationMode,
  9493. xfaLayerFactory,
  9494. annotationEditorLayerFactory,
  9495. textHighlighterFactory: this,
  9496. structTreeLayerFactory: this,
  9497. imageResourcesPath: this.imageResourcesPath,
  9498. renderer: this.renderer,
  9499. useOnlyCssZoom: this.useOnlyCssZoom,
  9500. maxCanvasPixels: this.maxCanvasPixels,
  9501. pageColors: this.pageColors,
  9502. l10n: this.l10n
  9503. });
  9504. this._pages.push(pageView);
  9505. }
  9506. const firstPageView = this._pages[0];
  9507. if (firstPageView) {
  9508. firstPageView.setPdfPage(firstPdfPage);
  9509. this.linkService.cachePageRef(1, firstPdfPage.ref);
  9510. }
  9511. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9512. _classPrivateMethodGet(this, _ensurePageViewVisible, _ensurePageViewVisible2).call(this);
  9513. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  9514. this._updateSpreadMode();
  9515. }
  9516. _classPrivateMethodGet(this, _onePageRenderedOrForceFetch, _onePageRenderedOrForceFetch2).call(this).then(async () => {
  9517. var _this$findController2, _this$_scriptingManag2;
  9518. (_this$findController2 = this.findController) === null || _this$findController2 === void 0 ? void 0 : _this$findController2.setDocument(pdfDocument);
  9519. (_this$_scriptingManag2 = this._scriptingManager) === null || _this$_scriptingManag2 === void 0 ? void 0 : _this$_scriptingManag2.setDocument(pdfDocument);
  9520. if (_classPrivateFieldGet(this, _annotationEditorUIManager)) {
  9521. this.eventBus.dispatch("annotationeditormodechanged", {
  9522. source: this,
  9523. mode: _classPrivateFieldGet(this, _annotationEditorMode)
  9524. });
  9525. }
  9526. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  9527. this._pagesCapability.resolve();
  9528. return;
  9529. }
  9530. let getPagesLeft = pagesCount - 1;
  9531. if (getPagesLeft <= 0) {
  9532. this._pagesCapability.resolve();
  9533. return;
  9534. }
  9535. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  9536. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  9537. const pageView = this._pages[pageNum - 1];
  9538. if (!pageView.pdfPage) {
  9539. pageView.setPdfPage(pdfPage);
  9540. }
  9541. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  9542. if (--getPagesLeft === 0) {
  9543. this._pagesCapability.resolve();
  9544. }
  9545. }, reason => {
  9546. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  9547. if (--getPagesLeft === 0) {
  9548. this._pagesCapability.resolve();
  9549. }
  9550. });
  9551. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  9552. await promise;
  9553. }
  9554. }
  9555. });
  9556. this.eventBus.dispatch("pagesinit", {
  9557. source: this
  9558. });
  9559. pdfDocument.getMetadata().then(_ref2 => {
  9560. let {
  9561. info
  9562. } = _ref2;
  9563. if (pdfDocument !== this.pdfDocument) {
  9564. return;
  9565. }
  9566. if (info.Language) {
  9567. this.viewer.lang = info.Language;
  9568. }
  9569. });
  9570. if (this.defaultRenderingQueue) {
  9571. this.update();
  9572. }
  9573. }).catch(reason => {
  9574. console.error("Unable to initialize viewer", reason);
  9575. this._pagesCapability.reject(reason);
  9576. });
  9577. }
  9578. setPageLabels(labels) {
  9579. if (!this.pdfDocument) {
  9580. return;
  9581. }
  9582. if (!labels) {
  9583. this._pageLabels = null;
  9584. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  9585. this._pageLabels = null;
  9586. console.error(`setPageLabels: Invalid page labels.`);
  9587. } else {
  9588. this._pageLabels = labels;
  9589. }
  9590. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  9591. var _this$_pageLabels3;
  9592. this._pages[i].setPageLabel(((_this$_pageLabels3 = this._pageLabels) === null || _this$_pageLabels3 === void 0 ? void 0 : _this$_pageLabels3[i]) ?? null);
  9593. }
  9594. }
  9595. _resetView() {
  9596. this._pages = [];
  9597. this._currentPageNumber = 1;
  9598. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  9599. this._currentScaleValue = null;
  9600. this._pageLabels = null;
  9601. _classPrivateFieldSet(this, _buffer, new PDFPageViewBuffer(DEFAULT_CACHE_SIZE));
  9602. this._location = null;
  9603. this._pagesRotation = 0;
  9604. this._optionalContentConfigPromise = null;
  9605. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  9606. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  9607. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  9608. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  9609. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  9610. this._spreadMode = _ui_utils.SpreadMode.NONE;
  9611. _classPrivateFieldSet(this, _scrollModePageState, {
  9612. previousPageNumber: 1,
  9613. scrollDown: true,
  9614. pages: []
  9615. });
  9616. if (this._onBeforeDraw) {
  9617. this.eventBus._off("pagerender", this._onBeforeDraw);
  9618. this._onBeforeDraw = null;
  9619. }
  9620. if (this._onAfterDraw) {
  9621. this.eventBus._off("pagerendered", this._onAfterDraw);
  9622. this._onAfterDraw = null;
  9623. }
  9624. if (_classPrivateFieldGet(this, _onVisibilityChange)) {
  9625. document.removeEventListener("visibilitychange", _classPrivateFieldGet(this, _onVisibilityChange));
  9626. _classPrivateFieldSet(this, _onVisibilityChange, null);
  9627. }
  9628. this.viewer.textContent = "";
  9629. this._updateScrollMode();
  9630. this.viewer.removeAttribute("lang");
  9631. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  9632. }
  9633. _scrollUpdate() {
  9634. if (this.pagesCount === 0) {
  9635. return;
  9636. }
  9637. this.update();
  9638. }
  9639. _setScaleUpdatePages(newScale, newValue) {
  9640. let noScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  9641. let preset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  9642. this._currentScaleValue = newValue.toString();
  9643. if (_classPrivateMethodGet(this, _isSameScale, _isSameScale2).call(this, newScale)) {
  9644. if (preset) {
  9645. this.eventBus.dispatch("scalechanging", {
  9646. source: this,
  9647. scale: newScale,
  9648. presetValue: newValue
  9649. });
  9650. }
  9651. return;
  9652. }
  9653. _ui_utils.docStyle.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  9654. const updateArgs = {
  9655. scale: newScale
  9656. };
  9657. for (const pageView of this._pages) {
  9658. pageView.update(updateArgs);
  9659. }
  9660. this._currentScale = newScale;
  9661. if (!noScroll) {
  9662. let page = this._currentPageNumber,
  9663. dest;
  9664. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  9665. page = this._location.pageNumber;
  9666. dest = [null, {
  9667. name: "XYZ"
  9668. }, this._location.left, this._location.top, null];
  9669. }
  9670. this.scrollPageIntoView({
  9671. pageNumber: page,
  9672. destArray: dest,
  9673. allowNegativeOffset: true
  9674. });
  9675. }
  9676. this.eventBus.dispatch("scalechanging", {
  9677. source: this,
  9678. scale: newScale,
  9679. presetValue: preset ? newValue : undefined
  9680. });
  9681. if (this.defaultRenderingQueue) {
  9682. this.update();
  9683. }
  9684. this.updateContainerHeightCss();
  9685. }
  9686. get _pageWidthScaleFactor() {
  9687. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  9688. return 2;
  9689. }
  9690. return 1;
  9691. }
  9692. _setScale(value) {
  9693. let noScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  9694. let scale = parseFloat(value);
  9695. if (scale > 0) {
  9696. this._setScaleUpdatePages(scale, value, noScroll, false);
  9697. } else {
  9698. const currentPage = this._pages[this._currentPageNumber - 1];
  9699. if (!currentPage) {
  9700. return;
  9701. }
  9702. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  9703. vPadding = _ui_utils.VERTICAL_PADDING;
  9704. if (this.isInPresentationMode) {
  9705. hPadding = vPadding = 4;
  9706. } else if (this.removePageBorders) {
  9707. hPadding = vPadding = 0;
  9708. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  9709. [hPadding, vPadding] = [vPadding, hPadding];
  9710. }
  9711. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  9712. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  9713. switch (value) {
  9714. case "page-actual":
  9715. scale = 1;
  9716. break;
  9717. case "page-width":
  9718. scale = pageWidthScale;
  9719. break;
  9720. case "page-height":
  9721. scale = pageHeightScale;
  9722. break;
  9723. case "page-fit":
  9724. scale = Math.min(pageWidthScale, pageHeightScale);
  9725. break;
  9726. case "auto":
  9727. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  9728. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  9729. break;
  9730. default:
  9731. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  9732. return;
  9733. }
  9734. this._setScaleUpdatePages(scale, value, noScroll, true);
  9735. }
  9736. }
  9737. pageLabelToPageNumber(label) {
  9738. if (!this._pageLabels) {
  9739. return null;
  9740. }
  9741. const i = this._pageLabels.indexOf(label);
  9742. if (i < 0) {
  9743. return null;
  9744. }
  9745. return i + 1;
  9746. }
  9747. scrollPageIntoView(_ref3) {
  9748. let {
  9749. pageNumber,
  9750. destArray = null,
  9751. allowNegativeOffset = false,
  9752. ignoreDestinationZoom = false
  9753. } = _ref3;
  9754. if (!this.pdfDocument) {
  9755. return;
  9756. }
  9757. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  9758. if (!pageView) {
  9759. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  9760. return;
  9761. }
  9762. if (this.isInPresentationMode || !destArray) {
  9763. this._setCurrentPageNumber(pageNumber, true);
  9764. return;
  9765. }
  9766. let x = 0,
  9767. y = 0;
  9768. let width = 0,
  9769. height = 0,
  9770. widthScale,
  9771. heightScale;
  9772. const changeOrientation = pageView.rotation % 180 !== 0;
  9773. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9774. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9775. let scale = 0;
  9776. switch (destArray[1].name) {
  9777. case "XYZ":
  9778. x = destArray[2];
  9779. y = destArray[3];
  9780. scale = destArray[4];
  9781. x = x !== null ? x : 0;
  9782. y = y !== null ? y : pageHeight;
  9783. break;
  9784. case "Fit":
  9785. case "FitB":
  9786. scale = "page-fit";
  9787. break;
  9788. case "FitH":
  9789. case "FitBH":
  9790. y = destArray[2];
  9791. scale = "page-width";
  9792. if (y === null && this._location) {
  9793. x = this._location.left;
  9794. y = this._location.top;
  9795. } else if (typeof y !== "number" || y < 0) {
  9796. y = pageHeight;
  9797. }
  9798. break;
  9799. case "FitV":
  9800. case "FitBV":
  9801. x = destArray[2];
  9802. width = pageWidth;
  9803. height = pageHeight;
  9804. scale = "page-height";
  9805. break;
  9806. case "FitR":
  9807. x = destArray[2];
  9808. y = destArray[3];
  9809. width = destArray[4] - x;
  9810. height = destArray[5] - y;
  9811. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  9812. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  9813. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9814. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9815. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  9816. break;
  9817. default:
  9818. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  9819. return;
  9820. }
  9821. if (!ignoreDestinationZoom) {
  9822. if (scale && scale !== this._currentScale) {
  9823. this.currentScaleValue = scale;
  9824. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  9825. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  9826. }
  9827. }
  9828. if (scale === "page-fit" && !destArray[4]) {
  9829. _classPrivateMethodGet(this, _scrollIntoView, _scrollIntoView2).call(this, pageView);
  9830. return;
  9831. }
  9832. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  9833. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  9834. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  9835. if (!allowNegativeOffset) {
  9836. left = Math.max(left, 0);
  9837. top = Math.max(top, 0);
  9838. }
  9839. _classPrivateMethodGet(this, _scrollIntoView, _scrollIntoView2).call(this, pageView, {
  9840. left,
  9841. top
  9842. });
  9843. }
  9844. _updateLocation(firstPage) {
  9845. const currentScale = this._currentScale;
  9846. const currentScaleValue = this._currentScaleValue;
  9847. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  9848. const pageNumber = firstPage.id;
  9849. const currentPageView = this._pages[pageNumber - 1];
  9850. const container = this.container;
  9851. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  9852. const intLeft = Math.round(topLeft[0]);
  9853. const intTop = Math.round(topLeft[1]);
  9854. let pdfOpenParams = `#page=${pageNumber}`;
  9855. if (!this.isInPresentationMode) {
  9856. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  9857. }
  9858. this._location = {
  9859. pageNumber,
  9860. scale: normalizedScaleValue,
  9861. top: intTop,
  9862. left: intLeft,
  9863. rotation: this._pagesRotation,
  9864. pdfOpenParams
  9865. };
  9866. }
  9867. update() {
  9868. const visible = this._getVisiblePages();
  9869. const visiblePages = visible.views,
  9870. numVisiblePages = visiblePages.length;
  9871. if (numVisiblePages === 0) {
  9872. return;
  9873. }
  9874. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  9875. _classPrivateFieldGet(this, _buffer).resize(newCacheSize, visible.ids);
  9876. this.renderingQueue.renderHighestPriority(visible);
  9877. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  9878. const currentId = this._currentPageNumber;
  9879. let stillFullyVisible = false;
  9880. for (const page of visiblePages) {
  9881. if (page.percent < 100) {
  9882. break;
  9883. }
  9884. if (page.id === currentId && isSimpleLayout) {
  9885. stillFullyVisible = true;
  9886. break;
  9887. }
  9888. }
  9889. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  9890. this._updateLocation(visible.first);
  9891. this.eventBus.dispatch("updateviewarea", {
  9892. source: this,
  9893. location: this._location
  9894. });
  9895. }
  9896. containsElement(element) {
  9897. return this.container.contains(element);
  9898. }
  9899. focus() {
  9900. this.container.focus();
  9901. }
  9902. get _isContainerRtl() {
  9903. return getComputedStyle(this.container).direction === "rtl";
  9904. }
  9905. get isInPresentationMode() {
  9906. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  9907. }
  9908. get isChangingPresentationMode() {
  9909. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  9910. }
  9911. get isHorizontalScrollbarEnabled() {
  9912. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  9913. }
  9914. get isVerticalScrollbarEnabled() {
  9915. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  9916. }
  9917. _getVisiblePages() {
  9918. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? _classPrivateFieldGet(this, _scrollModePageState).pages : this._pages,
  9919. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  9920. rtl = horizontal && this._isContainerRtl;
  9921. return (0, _ui_utils.getVisibleElements)({
  9922. scrollEl: this.container,
  9923. views,
  9924. sortByVisibility: true,
  9925. horizontal,
  9926. rtl
  9927. });
  9928. }
  9929. isPageVisible(pageNumber) {
  9930. if (!this.pdfDocument) {
  9931. return false;
  9932. }
  9933. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  9934. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  9935. return false;
  9936. }
  9937. return this._getVisiblePages().ids.has(pageNumber);
  9938. }
  9939. isPageCached(pageNumber) {
  9940. if (!this.pdfDocument) {
  9941. return false;
  9942. }
  9943. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  9944. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  9945. return false;
  9946. }
  9947. const pageView = this._pages[pageNumber - 1];
  9948. return _classPrivateFieldGet(this, _buffer).has(pageView);
  9949. }
  9950. cleanup() {
  9951. for (const pageView of this._pages) {
  9952. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  9953. pageView.reset();
  9954. }
  9955. }
  9956. }
  9957. _cancelRendering() {
  9958. for (const pageView of this._pages) {
  9959. pageView.cancelRendering();
  9960. }
  9961. }
  9962. forceRendering(currentlyVisiblePages) {
  9963. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9964. const scrollAhead = _classPrivateMethodGet(this, _getScrollAhead, _getScrollAhead2).call(this, visiblePages);
  9965. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9966. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9967. _classPrivateMethodGet(this, _toggleLoadingIconSpinner, _toggleLoadingIconSpinner2).call(this, visiblePages.ids);
  9968. if (pageView) {
  9969. _classPrivateMethodGet(this, _ensurePdfPageLoaded, _ensurePdfPageLoaded2).call(this, pageView).then(() => {
  9970. this.renderingQueue.renderView(pageView);
  9971. });
  9972. return true;
  9973. }
  9974. return false;
  9975. }
  9976. createTextLayerBuilder(_ref4) {
  9977. let {
  9978. textLayerDiv,
  9979. pageIndex,
  9980. viewport,
  9981. eventBus,
  9982. highlighter,
  9983. accessibilityManager = null
  9984. } = _ref4;
  9985. return new _text_layer_builder.TextLayerBuilder({
  9986. textLayerDiv,
  9987. eventBus,
  9988. pageIndex,
  9989. viewport,
  9990. highlighter,
  9991. accessibilityManager
  9992. });
  9993. }
  9994. createTextHighlighter(_ref5) {
  9995. let {
  9996. pageIndex,
  9997. eventBus
  9998. } = _ref5;
  9999. return new _text_highlighter.TextHighlighter({
  10000. eventBus,
  10001. pageIndex,
  10002. findController: this.isInPresentationMode ? null : this.findController
  10003. });
  10004. }
  10005. createAnnotationLayerBuilder(_ref6) {
  10006. var _this$pdfDocument, _this$pdfDocument2, _this$_scriptingManag3, _this$pdfDocument3;
  10007. let {
  10008. pageDiv,
  10009. pdfPage,
  10010. annotationStorage = (_this$pdfDocument = this.pdfDocument) === null || _this$pdfDocument === void 0 ? void 0 : _this$pdfDocument.annotationStorage,
  10011. imageResourcesPath = "",
  10012. renderForms = true,
  10013. l10n = _l10n_utils.NullL10n,
  10014. enableScripting = this.enableScripting,
  10015. hasJSActionsPromise = (_this$pdfDocument2 = this.pdfDocument) === null || _this$pdfDocument2 === void 0 ? void 0 : _this$pdfDocument2.hasJSActions(),
  10016. mouseState = (_this$_scriptingManag3 = this._scriptingManager) === null || _this$_scriptingManag3 === void 0 ? void 0 : _this$_scriptingManag3.mouseState,
  10017. fieldObjectsPromise = (_this$pdfDocument3 = this.pdfDocument) === null || _this$pdfDocument3 === void 0 ? void 0 : _this$pdfDocument3.getFieldObjects(),
  10018. annotationCanvasMap = null,
  10019. accessibilityManager = null
  10020. } = _ref6;
  10021. return new _annotation_layer_builder.AnnotationLayerBuilder({
  10022. pageDiv,
  10023. pdfPage,
  10024. annotationStorage,
  10025. imageResourcesPath,
  10026. renderForms,
  10027. linkService: this.linkService,
  10028. downloadManager: this.downloadManager,
  10029. l10n,
  10030. enableScripting,
  10031. hasJSActionsPromise,
  10032. mouseState,
  10033. fieldObjectsPromise,
  10034. annotationCanvasMap,
  10035. accessibilityManager
  10036. });
  10037. }
  10038. createAnnotationEditorLayerBuilder(_ref7) {
  10039. var _this$pdfDocument4;
  10040. let {
  10041. uiManager = _classPrivateFieldGet(this, _annotationEditorUIManager),
  10042. pageDiv,
  10043. pdfPage,
  10044. accessibilityManager = null,
  10045. l10n,
  10046. annotationStorage = (_this$pdfDocument4 = this.pdfDocument) === null || _this$pdfDocument4 === void 0 ? void 0 : _this$pdfDocument4.annotationStorage
  10047. } = _ref7;
  10048. return new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  10049. uiManager,
  10050. pageDiv,
  10051. pdfPage,
  10052. annotationStorage,
  10053. accessibilityManager,
  10054. l10n
  10055. });
  10056. }
  10057. createXfaLayerBuilder(_ref8) {
  10058. var _this$pdfDocument5;
  10059. let {
  10060. pageDiv,
  10061. pdfPage,
  10062. annotationStorage = (_this$pdfDocument5 = this.pdfDocument) === null || _this$pdfDocument5 === void 0 ? void 0 : _this$pdfDocument5.annotationStorage
  10063. } = _ref8;
  10064. return new _xfa_layer_builder.XfaLayerBuilder({
  10065. pageDiv,
  10066. pdfPage,
  10067. annotationStorage,
  10068. linkService: this.linkService
  10069. });
  10070. }
  10071. createStructTreeLayerBuilder(_ref9) {
  10072. let {
  10073. pdfPage
  10074. } = _ref9;
  10075. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  10076. pdfPage
  10077. });
  10078. }
  10079. get hasEqualPageSizes() {
  10080. const firstPageView = this._pages[0];
  10081. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  10082. const pageView = this._pages[i];
  10083. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  10084. return false;
  10085. }
  10086. }
  10087. return true;
  10088. }
  10089. getPagesOverview() {
  10090. return this._pages.map(pageView => {
  10091. const viewport = pageView.pdfPage.getViewport({
  10092. scale: 1
  10093. });
  10094. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  10095. return {
  10096. width: viewport.width,
  10097. height: viewport.height,
  10098. rotation: viewport.rotation
  10099. };
  10100. }
  10101. return {
  10102. width: viewport.height,
  10103. height: viewport.width,
  10104. rotation: (viewport.rotation - 90) % 360
  10105. };
  10106. });
  10107. }
  10108. get optionalContentConfigPromise() {
  10109. if (!this.pdfDocument) {
  10110. return Promise.resolve(null);
  10111. }
  10112. if (!this._optionalContentConfigPromise) {
  10113. console.error("optionalContentConfigPromise: Not initialized yet.");
  10114. return this.pdfDocument.getOptionalContentConfig();
  10115. }
  10116. return this._optionalContentConfigPromise;
  10117. }
  10118. set optionalContentConfigPromise(promise) {
  10119. if (!(promise instanceof Promise)) {
  10120. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  10121. }
  10122. if (!this.pdfDocument) {
  10123. return;
  10124. }
  10125. if (!this._optionalContentConfigPromise) {
  10126. return;
  10127. }
  10128. this._optionalContentConfigPromise = promise;
  10129. const updateArgs = {
  10130. optionalContentConfigPromise: promise
  10131. };
  10132. for (const pageView of this._pages) {
  10133. pageView.update(updateArgs);
  10134. }
  10135. this.update();
  10136. this.eventBus.dispatch("optionalcontentconfigchanged", {
  10137. source: this,
  10138. promise
  10139. });
  10140. }
  10141. get scrollMode() {
  10142. return this._scrollMode;
  10143. }
  10144. set scrollMode(mode) {
  10145. if (this._scrollMode === mode) {
  10146. return;
  10147. }
  10148. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  10149. throw new Error(`Invalid scroll mode: ${mode}`);
  10150. }
  10151. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  10152. return;
  10153. }
  10154. this._previousScrollMode = this._scrollMode;
  10155. this._scrollMode = mode;
  10156. this.eventBus.dispatch("scrollmodechanged", {
  10157. source: this,
  10158. mode
  10159. });
  10160. this._updateScrollMode(this._currentPageNumber);
  10161. }
  10162. _updateScrollMode() {
  10163. let pageNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  10164. const scrollMode = this._scrollMode,
  10165. viewer = this.viewer;
  10166. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  10167. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  10168. if (!this.pdfDocument || !pageNumber) {
  10169. return;
  10170. }
  10171. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  10172. _classPrivateMethodGet(this, _ensurePageViewVisible, _ensurePageViewVisible2).call(this);
  10173. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  10174. this._updateSpreadMode();
  10175. }
  10176. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  10177. this._setScale(this._currentScaleValue, true);
  10178. }
  10179. this._setCurrentPageNumber(pageNumber, true);
  10180. this.update();
  10181. }
  10182. get spreadMode() {
  10183. return this._spreadMode;
  10184. }
  10185. set spreadMode(mode) {
  10186. if (this._spreadMode === mode) {
  10187. return;
  10188. }
  10189. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  10190. throw new Error(`Invalid spread mode: ${mode}`);
  10191. }
  10192. this._spreadMode = mode;
  10193. this.eventBus.dispatch("spreadmodechanged", {
  10194. source: this,
  10195. mode
  10196. });
  10197. this._updateSpreadMode(this._currentPageNumber);
  10198. }
  10199. _updateSpreadMode() {
  10200. let pageNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  10201. if (!this.pdfDocument) {
  10202. return;
  10203. }
  10204. const viewer = this.viewer,
  10205. pages = this._pages;
  10206. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  10207. _classPrivateMethodGet(this, _ensurePageViewVisible, _ensurePageViewVisible2).call(this);
  10208. } else {
  10209. viewer.textContent = "";
  10210. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  10211. for (const pageView of this._pages) {
  10212. viewer.append(pageView.div);
  10213. }
  10214. } else {
  10215. const parity = this._spreadMode - 1;
  10216. let spread = null;
  10217. for (let i = 0, ii = pages.length; i < ii; ++i) {
  10218. if (spread === null) {
  10219. spread = document.createElement("div");
  10220. spread.className = "spread";
  10221. viewer.append(spread);
  10222. } else if (i % 2 === parity) {
  10223. spread = spread.cloneNode(false);
  10224. viewer.append(spread);
  10225. }
  10226. spread.append(pages[i].div);
  10227. }
  10228. }
  10229. }
  10230. if (!pageNumber) {
  10231. return;
  10232. }
  10233. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  10234. this._setScale(this._currentScaleValue, true);
  10235. }
  10236. this._setCurrentPageNumber(pageNumber, true);
  10237. this.update();
  10238. }
  10239. _getPageAdvance(currentPageNumber) {
  10240. let previous = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  10241. switch (this._scrollMode) {
  10242. case _ui_utils.ScrollMode.WRAPPED:
  10243. {
  10244. const {
  10245. views
  10246. } = this._getVisiblePages(),
  10247. pageLayout = new Map();
  10248. for (const {
  10249. id,
  10250. y,
  10251. percent,
  10252. widthPercent
  10253. } of views) {
  10254. if (percent === 0 || widthPercent < 100) {
  10255. continue;
  10256. }
  10257. let yArray = pageLayout.get(y);
  10258. if (!yArray) {
  10259. pageLayout.set(y, yArray || (yArray = []));
  10260. }
  10261. yArray.push(id);
  10262. }
  10263. for (const yArray of pageLayout.values()) {
  10264. const currentIndex = yArray.indexOf(currentPageNumber);
  10265. if (currentIndex === -1) {
  10266. continue;
  10267. }
  10268. const numPages = yArray.length;
  10269. if (numPages === 1) {
  10270. break;
  10271. }
  10272. if (previous) {
  10273. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  10274. const currentId = yArray[i],
  10275. expectedId = yArray[i + 1] - 1;
  10276. if (currentId < expectedId) {
  10277. return currentPageNumber - expectedId;
  10278. }
  10279. }
  10280. } else {
  10281. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  10282. const currentId = yArray[i],
  10283. expectedId = yArray[i - 1] + 1;
  10284. if (currentId > expectedId) {
  10285. return expectedId - currentPageNumber;
  10286. }
  10287. }
  10288. }
  10289. if (previous) {
  10290. const firstId = yArray[0];
  10291. if (firstId < currentPageNumber) {
  10292. return currentPageNumber - firstId + 1;
  10293. }
  10294. } else {
  10295. const lastId = yArray[numPages - 1];
  10296. if (lastId > currentPageNumber) {
  10297. return lastId - currentPageNumber + 1;
  10298. }
  10299. }
  10300. break;
  10301. }
  10302. break;
  10303. }
  10304. case _ui_utils.ScrollMode.HORIZONTAL:
  10305. {
  10306. break;
  10307. }
  10308. case _ui_utils.ScrollMode.PAGE:
  10309. case _ui_utils.ScrollMode.VERTICAL:
  10310. {
  10311. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  10312. break;
  10313. }
  10314. const parity = this._spreadMode - 1;
  10315. if (previous && currentPageNumber % 2 !== parity) {
  10316. break;
  10317. } else if (!previous && currentPageNumber % 2 === parity) {
  10318. break;
  10319. }
  10320. const {
  10321. views
  10322. } = this._getVisiblePages(),
  10323. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  10324. for (const {
  10325. id,
  10326. percent,
  10327. widthPercent
  10328. } of views) {
  10329. if (id !== expectedId) {
  10330. continue;
  10331. }
  10332. if (percent > 0 && widthPercent === 100) {
  10333. return 2;
  10334. }
  10335. break;
  10336. }
  10337. break;
  10338. }
  10339. }
  10340. return 1;
  10341. }
  10342. nextPage() {
  10343. const currentPageNumber = this._currentPageNumber,
  10344. pagesCount = this.pagesCount;
  10345. if (currentPageNumber >= pagesCount) {
  10346. return false;
  10347. }
  10348. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  10349. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  10350. return true;
  10351. }
  10352. previousPage() {
  10353. const currentPageNumber = this._currentPageNumber;
  10354. if (currentPageNumber <= 1) {
  10355. return false;
  10356. }
  10357. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  10358. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  10359. return true;
  10360. }
  10361. increaseScale() {
  10362. let steps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  10363. let newScale = this._currentScale;
  10364. do {
  10365. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  10366. newScale = Math.ceil(newScale * 10) / 10;
  10367. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  10368. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  10369. this.currentScaleValue = newScale;
  10370. }
  10371. decreaseScale() {
  10372. let steps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  10373. let newScale = this._currentScale;
  10374. do {
  10375. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  10376. newScale = Math.floor(newScale * 10) / 10;
  10377. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  10378. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  10379. this.currentScaleValue = newScale;
  10380. }
  10381. updateContainerHeightCss() {
  10382. const height = this.container.clientHeight;
  10383. if (height !== _classPrivateFieldGet(this, _previousContainerHeight)) {
  10384. _classPrivateFieldSet(this, _previousContainerHeight, height);
  10385. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  10386. }
  10387. }
  10388. get annotationEditorMode() {
  10389. return _classPrivateFieldGet(this, _annotationEditorUIManager) ? _classPrivateFieldGet(this, _annotationEditorMode) : _pdfjsLib.AnnotationEditorType.DISABLE;
  10390. }
  10391. set annotationEditorMode(mode) {
  10392. if (!_classPrivateFieldGet(this, _annotationEditorUIManager)) {
  10393. throw new Error(`The AnnotationEditor is not enabled.`);
  10394. }
  10395. if (_classPrivateFieldGet(this, _annotationEditorMode) === mode) {
  10396. return;
  10397. }
  10398. if (!isValidAnnotationEditorMode(mode)) {
  10399. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  10400. }
  10401. if (!this.pdfDocument) {
  10402. return;
  10403. }
  10404. _classPrivateFieldSet(this, _annotationEditorMode, mode);
  10405. this.eventBus.dispatch("annotationeditormodechanged", {
  10406. source: this,
  10407. mode
  10408. });
  10409. _classPrivateFieldGet(this, _annotationEditorUIManager).updateMode(mode);
  10410. }
  10411. set annotationEditorParams(_ref10) {
  10412. let {
  10413. type,
  10414. value
  10415. } = _ref10;
  10416. if (!_classPrivateFieldGet(this, _annotationEditorUIManager)) {
  10417. throw new Error(`The AnnotationEditor is not enabled.`);
  10418. }
  10419. _classPrivateFieldGet(this, _annotationEditorUIManager).updateParams(type, value);
  10420. }
  10421. refresh() {
  10422. if (!this.pdfDocument) {
  10423. return;
  10424. }
  10425. const updateArgs = {};
  10426. for (const pageView of this._pages) {
  10427. pageView.update(updateArgs);
  10428. }
  10429. this.update();
  10430. }
  10431. }
  10432. exports.PDFViewer = PDFViewer;
  10433. function _initializePermissions2(permissions) {
  10434. const params = {
  10435. annotationEditorMode: _classPrivateFieldGet(this, _annotationEditorMode),
  10436. annotationMode: _classPrivateFieldGet(this, _annotationMode),
  10437. textLayerMode: this.textLayerMode
  10438. };
  10439. if (!permissions) {
  10440. return params;
  10441. }
  10442. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  10443. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  10444. }
  10445. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  10446. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  10447. }
  10448. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && _classPrivateFieldGet(this, _annotationMode) === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  10449. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  10450. }
  10451. return params;
  10452. }
  10453. function _onePageRenderedOrForceFetch2() {
  10454. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  10455. return Promise.resolve();
  10456. }
  10457. const visibilityChangePromise = new Promise(resolve => {
  10458. _classPrivateFieldSet(this, _onVisibilityChange, () => {
  10459. if (document.visibilityState !== "hidden") {
  10460. return;
  10461. }
  10462. resolve();
  10463. document.removeEventListener("visibilitychange", _classPrivateFieldGet(this, _onVisibilityChange));
  10464. _classPrivateFieldSet(this, _onVisibilityChange, null);
  10465. });
  10466. document.addEventListener("visibilitychange", _classPrivateFieldGet(this, _onVisibilityChange));
  10467. });
  10468. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  10469. }
  10470. function _ensurePageViewVisible2() {
  10471. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  10472. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  10473. }
  10474. const pageNumber = this._currentPageNumber,
  10475. state = _classPrivateFieldGet(this, _scrollModePageState),
  10476. viewer = this.viewer;
  10477. viewer.textContent = "";
  10478. state.pages.length = 0;
  10479. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  10480. const pageView = this._pages[pageNumber - 1];
  10481. viewer.append(pageView.div);
  10482. state.pages.push(pageView);
  10483. } else {
  10484. const pageIndexSet = new Set(),
  10485. parity = this._spreadMode - 1;
  10486. if (parity === -1) {
  10487. pageIndexSet.add(pageNumber - 1);
  10488. } else if (pageNumber % 2 !== parity) {
  10489. pageIndexSet.add(pageNumber - 1);
  10490. pageIndexSet.add(pageNumber);
  10491. } else {
  10492. pageIndexSet.add(pageNumber - 2);
  10493. pageIndexSet.add(pageNumber - 1);
  10494. }
  10495. const spread = document.createElement("div");
  10496. spread.className = "spread";
  10497. if (this.isInPresentationMode) {
  10498. const dummyPage = document.createElement("div");
  10499. dummyPage.className = "dummyPage";
  10500. spread.append(dummyPage);
  10501. }
  10502. for (const i of pageIndexSet) {
  10503. const pageView = this._pages[i];
  10504. if (!pageView) {
  10505. continue;
  10506. }
  10507. spread.append(pageView.div);
  10508. state.pages.push(pageView);
  10509. }
  10510. viewer.append(spread);
  10511. }
  10512. state.scrollDown = pageNumber >= state.previousPageNumber;
  10513. state.previousPageNumber = pageNumber;
  10514. }
  10515. function _scrollIntoView2(pageView) {
  10516. let pageSpot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  10517. const {
  10518. div,
  10519. id
  10520. } = pageView;
  10521. if (this._currentPageNumber !== id) {
  10522. this._setCurrentPageNumber(id);
  10523. }
  10524. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  10525. _classPrivateMethodGet(this, _ensurePageViewVisible, _ensurePageViewVisible2).call(this);
  10526. this.update();
  10527. }
  10528. if (!pageSpot && !this.isInPresentationMode) {
  10529. const left = div.offsetLeft + div.clientLeft,
  10530. right = left + div.clientWidth;
  10531. const {
  10532. scrollLeft,
  10533. clientWidth
  10534. } = this.container;
  10535. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  10536. pageSpot = {
  10537. left: 0,
  10538. top: 0
  10539. };
  10540. }
  10541. }
  10542. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  10543. if (!this._currentScaleValue && this._location) {
  10544. this._location = null;
  10545. }
  10546. }
  10547. function _isSameScale2(newScale) {
  10548. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  10549. }
  10550. function _resetCurrentPageView2() {
  10551. const pageView = this._pages[this._currentPageNumber - 1];
  10552. if (this.isInPresentationMode) {
  10553. this._setScale(this._currentScaleValue, true);
  10554. }
  10555. _classPrivateMethodGet(this, _scrollIntoView, _scrollIntoView2).call(this, pageView);
  10556. }
  10557. async function _ensurePdfPageLoaded2(pageView) {
  10558. if (pageView.pdfPage) {
  10559. return pageView.pdfPage;
  10560. }
  10561. try {
  10562. var _this$linkService$_ca, _this$linkService;
  10563. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  10564. if (!pageView.pdfPage) {
  10565. pageView.setPdfPage(pdfPage);
  10566. }
  10567. if (!((_this$linkService$_ca = (_this$linkService = this.linkService)._cachedPageNumber) !== null && _this$linkService$_ca !== void 0 && _this$linkService$_ca.call(_this$linkService, pdfPage.ref))) {
  10568. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  10569. }
  10570. return pdfPage;
  10571. } catch (reason) {
  10572. console.error("Unable to get page for page view", reason);
  10573. return null;
  10574. }
  10575. }
  10576. function _getScrollAhead2(visible) {
  10577. var _visible$first, _visible$last;
  10578. if (((_visible$first = visible.first) === null || _visible$first === void 0 ? void 0 : _visible$first.id) === 1) {
  10579. return true;
  10580. } else if (((_visible$last = visible.last) === null || _visible$last === void 0 ? void 0 : _visible$last.id) === this.pagesCount) {
  10581. return false;
  10582. }
  10583. switch (this._scrollMode) {
  10584. case _ui_utils.ScrollMode.PAGE:
  10585. return _classPrivateFieldGet(this, _scrollModePageState).scrollDown;
  10586. case _ui_utils.ScrollMode.HORIZONTAL:
  10587. return this.scroll.right;
  10588. }
  10589. return this.scroll.down;
  10590. }
  10591. function _toggleLoadingIconSpinner2(visibleIds) {
  10592. for (const id of visibleIds) {
  10593. const pageView = this._pages[id - 1];
  10594. pageView === null || pageView === void 0 ? void 0 : pageView.toggleLoadingIconSpinner(true);
  10595. }
  10596. for (const pageView of _classPrivateFieldGet(this, _buffer)) {
  10597. if (visibleIds.has(pageView.id)) {
  10598. continue;
  10599. }
  10600. pageView.toggleLoadingIconSpinner(false);
  10601. }
  10602. }
  10603. /***/ }),
  10604. /* 30 */
  10605. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10606. Object.defineProperty(exports, "__esModule", ({
  10607. value: true
  10608. }));
  10609. exports.AnnotationEditorLayerBuilder = void 0;
  10610. var _pdfjsLib = __webpack_require__(5);
  10611. var _l10n_utils = __webpack_require__(31);
  10612. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  10613. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  10614. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  10615. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  10616. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  10617. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  10618. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  10619. var _uiManager = /*#__PURE__*/new WeakMap();
  10620. class AnnotationEditorLayerBuilder {
  10621. constructor(options) {
  10622. _classPrivateFieldInitSpec(this, _uiManager, {
  10623. writable: true,
  10624. value: void 0
  10625. });
  10626. this.pageDiv = options.pageDiv;
  10627. this.pdfPage = options.pdfPage;
  10628. this.annotationStorage = options.annotationStorage || null;
  10629. this.accessibilityManager = options.accessibilityManager;
  10630. this.l10n = options.l10n || _l10n_utils.NullL10n;
  10631. this.annotationEditorLayer = null;
  10632. this.div = null;
  10633. this._cancelled = false;
  10634. _classPrivateFieldSet(this, _uiManager, options.uiManager);
  10635. }
  10636. async render(viewport) {
  10637. let intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "display";
  10638. if (intent !== "display") {
  10639. return;
  10640. }
  10641. if (this._cancelled) {
  10642. return;
  10643. }
  10644. const clonedViewport = viewport.clone({
  10645. dontFlip: true
  10646. });
  10647. if (this.div) {
  10648. this.annotationEditorLayer.update({
  10649. viewport: clonedViewport
  10650. });
  10651. this.show();
  10652. return;
  10653. }
  10654. this.div = document.createElement("div");
  10655. this.div.className = "annotationEditorLayer";
  10656. this.div.tabIndex = 0;
  10657. this.pageDiv.append(this.div);
  10658. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  10659. uiManager: _classPrivateFieldGet(this, _uiManager),
  10660. div: this.div,
  10661. annotationStorage: this.annotationStorage,
  10662. accessibilityManager: this.accessibilityManager,
  10663. pageIndex: this.pdfPage._pageIndex,
  10664. l10n: this.l10n,
  10665. viewport: clonedViewport
  10666. });
  10667. const parameters = {
  10668. viewport: clonedViewport,
  10669. div: this.div,
  10670. annotations: null,
  10671. intent
  10672. };
  10673. this.annotationEditorLayer.render(parameters);
  10674. }
  10675. cancel() {
  10676. this._cancelled = true;
  10677. this.destroy();
  10678. }
  10679. hide() {
  10680. if (!this.div) {
  10681. return;
  10682. }
  10683. this.div.hidden = true;
  10684. }
  10685. show() {
  10686. if (!this.div) {
  10687. return;
  10688. }
  10689. this.div.hidden = false;
  10690. }
  10691. destroy() {
  10692. if (!this.div) {
  10693. return;
  10694. }
  10695. this.pageDiv = null;
  10696. this.annotationEditorLayer.destroy();
  10697. this.div.remove();
  10698. }
  10699. }
  10700. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  10701. /***/ }),
  10702. /* 31 */
  10703. /***/ ((__unused_webpack_module, exports) => {
  10704. Object.defineProperty(exports, "__esModule", ({
  10705. value: true
  10706. }));
  10707. exports.NullL10n = void 0;
  10708. exports.fixupLangCode = fixupLangCode;
  10709. exports.getL10nFallback = getL10nFallback;
  10710. const DEFAULT_L10N_STRINGS = {
  10711. of_pages: "of {{pagesCount}}",
  10712. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  10713. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  10714. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  10715. document_properties_date_string: "{{date}}, {{time}}",
  10716. document_properties_page_size_unit_inches: "in",
  10717. document_properties_page_size_unit_millimeters: "mm",
  10718. document_properties_page_size_orientation_portrait: "portrait",
  10719. document_properties_page_size_orientation_landscape: "landscape",
  10720. document_properties_page_size_name_a3: "A3",
  10721. document_properties_page_size_name_a4: "A4",
  10722. document_properties_page_size_name_letter: "Letter",
  10723. document_properties_page_size_name_legal: "Legal",
  10724. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  10725. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  10726. document_properties_linearized_yes: "Yes",
  10727. document_properties_linearized_no: "No",
  10728. additional_layers: "Additional Layers",
  10729. page_landmark: "Page {{page}}",
  10730. thumb_page_title: "Page {{page}}",
  10731. thumb_page_canvas: "Thumbnail of Page {{page}}",
  10732. find_reached_top: "Reached top of document, continued from bottom",
  10733. find_reached_bottom: "Reached end of document, continued from top",
  10734. "find_match_count[one]": "{{current}} of {{total}} match",
  10735. "find_match_count[other]": "{{current}} of {{total}} matches",
  10736. "find_match_count_limit[one]": "More than {{limit}} match",
  10737. "find_match_count_limit[other]": "More than {{limit}} matches",
  10738. find_not_found: "Phrase not found",
  10739. page_scale_width: "Page Width",
  10740. page_scale_fit: "Page Fit",
  10741. page_scale_auto: "Automatic Zoom",
  10742. page_scale_actual: "Actual Size",
  10743. page_scale_percent: "{{scale}}%",
  10744. loading: "Loading…",
  10745. loading_error: "An error occurred while loading the PDF.",
  10746. invalid_file_error: "Invalid or corrupted PDF file.",
  10747. missing_file_error: "Missing PDF file.",
  10748. unexpected_response_error: "Unexpected server response.",
  10749. rendering_error: "An error occurred while rendering the page.",
  10750. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  10751. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  10752. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  10753. free_text2_default_content: "Start typing…",
  10754. editor_free_text2_aria_label: "Text Editor",
  10755. editor_ink2_aria_label: "Draw Editor",
  10756. editor_ink_canvas_aria_label: "User-created image"
  10757. };
  10758. {
  10759. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  10760. }
  10761. function getL10nFallback(key, args) {
  10762. switch (key) {
  10763. case "find_match_count":
  10764. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  10765. break;
  10766. case "find_match_count_limit":
  10767. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  10768. break;
  10769. }
  10770. return DEFAULT_L10N_STRINGS[key] || "";
  10771. }
  10772. const PARTIAL_LANG_CODES = {
  10773. en: "en-US",
  10774. es: "es-ES",
  10775. fy: "fy-NL",
  10776. ga: "ga-IE",
  10777. gu: "gu-IN",
  10778. hi: "hi-IN",
  10779. hy: "hy-AM",
  10780. nb: "nb-NO",
  10781. ne: "ne-NP",
  10782. nn: "nn-NO",
  10783. pa: "pa-IN",
  10784. pt: "pt-PT",
  10785. sv: "sv-SE",
  10786. zh: "zh-CN"
  10787. };
  10788. function fixupLangCode(langCode) {
  10789. return PARTIAL_LANG_CODES[langCode === null || langCode === void 0 ? void 0 : langCode.toLowerCase()] || langCode;
  10790. }
  10791. function formatL10nValue(text, args) {
  10792. if (!args) {
  10793. return text;
  10794. }
  10795. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  10796. return name in args ? args[name] : "{{" + name + "}}";
  10797. });
  10798. }
  10799. const NullL10n = {
  10800. async getLanguage() {
  10801. return "en-us";
  10802. },
  10803. async getDirection() {
  10804. return "ltr";
  10805. },
  10806. async get(key) {
  10807. let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  10808. let fallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getL10nFallback(key, args);
  10809. return formatL10nValue(fallback, args);
  10810. },
  10811. async translate(element) {}
  10812. };
  10813. exports.NullL10n = NullL10n;
  10814. /***/ }),
  10815. /* 32 */
  10816. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10817. Object.defineProperty(exports, "__esModule", ({
  10818. value: true
  10819. }));
  10820. exports.AnnotationLayerBuilder = void 0;
  10821. var _pdfjsLib = __webpack_require__(5);
  10822. var _l10n_utils = __webpack_require__(31);
  10823. var _ui_utils = __webpack_require__(1);
  10824. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  10825. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  10826. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  10827. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  10828. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  10829. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  10830. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  10831. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  10832. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  10833. var _onPresentationModeChanged = /*#__PURE__*/new WeakMap();
  10834. var _updatePresentationModeState = /*#__PURE__*/new WeakSet();
  10835. class AnnotationLayerBuilder {
  10836. constructor(_ref) {
  10837. let {
  10838. pageDiv,
  10839. pdfPage,
  10840. linkService,
  10841. downloadManager,
  10842. annotationStorage = null,
  10843. imageResourcesPath = "",
  10844. renderForms = true,
  10845. l10n = _l10n_utils.NullL10n,
  10846. enableScripting = false,
  10847. hasJSActionsPromise = null,
  10848. fieldObjectsPromise = null,
  10849. mouseState = null,
  10850. annotationCanvasMap = null,
  10851. accessibilityManager = null
  10852. } = _ref;
  10853. _classPrivateMethodInitSpec(this, _updatePresentationModeState);
  10854. _classPrivateFieldInitSpec(this, _onPresentationModeChanged, {
  10855. writable: true,
  10856. value: null
  10857. });
  10858. this.pageDiv = pageDiv;
  10859. this.pdfPage = pdfPage;
  10860. this.linkService = linkService;
  10861. this.downloadManager = downloadManager;
  10862. this.imageResourcesPath = imageResourcesPath;
  10863. this.renderForms = renderForms;
  10864. this.l10n = l10n;
  10865. this.annotationStorage = annotationStorage;
  10866. this.enableScripting = enableScripting;
  10867. this._hasJSActionsPromise = hasJSActionsPromise;
  10868. this._fieldObjectsPromise = fieldObjectsPromise;
  10869. this._mouseState = mouseState;
  10870. this._annotationCanvasMap = annotationCanvasMap;
  10871. this._accessibilityManager = accessibilityManager;
  10872. this.div = null;
  10873. this._cancelled = false;
  10874. this._eventBus = linkService.eventBus;
  10875. }
  10876. async render(viewport) {
  10877. let intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "display";
  10878. const [annotations, hasJSActions = false, fieldObjects = null] = await Promise.all([this.pdfPage.getAnnotations({
  10879. intent
  10880. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  10881. if (this._cancelled || annotations.length === 0) {
  10882. return;
  10883. }
  10884. const parameters = {
  10885. viewport: viewport.clone({
  10886. dontFlip: true
  10887. }),
  10888. div: this.div,
  10889. annotations,
  10890. page: this.pdfPage,
  10891. imageResourcesPath: this.imageResourcesPath,
  10892. renderForms: this.renderForms,
  10893. linkService: this.linkService,
  10894. downloadManager: this.downloadManager,
  10895. annotationStorage: this.annotationStorage,
  10896. enableScripting: this.enableScripting,
  10897. hasJSActions,
  10898. fieldObjects,
  10899. mouseState: this._mouseState,
  10900. annotationCanvasMap: this._annotationCanvasMap,
  10901. accessibilityManager: this._accessibilityManager
  10902. };
  10903. if (this.div) {
  10904. _pdfjsLib.AnnotationLayer.update(parameters);
  10905. } else {
  10906. this.div = document.createElement("div");
  10907. this.div.className = "annotationLayer";
  10908. this.pageDiv.append(this.div);
  10909. parameters.div = this.div;
  10910. _pdfjsLib.AnnotationLayer.render(parameters);
  10911. this.l10n.translate(this.div);
  10912. if (this.linkService.isInPresentationMode) {
  10913. _classPrivateMethodGet(this, _updatePresentationModeState, _updatePresentationModeState2).call(this, _ui_utils.PresentationModeState.FULLSCREEN);
  10914. }
  10915. if (!_classPrivateFieldGet(this, _onPresentationModeChanged)) {
  10916. var _this$_eventBus;
  10917. _classPrivateFieldSet(this, _onPresentationModeChanged, evt => {
  10918. _classPrivateMethodGet(this, _updatePresentationModeState, _updatePresentationModeState2).call(this, evt.state);
  10919. });
  10920. (_this$_eventBus = this._eventBus) === null || _this$_eventBus === void 0 ? void 0 : _this$_eventBus._on("presentationmodechanged", _classPrivateFieldGet(this, _onPresentationModeChanged));
  10921. }
  10922. }
  10923. }
  10924. cancel() {
  10925. this._cancelled = true;
  10926. if (_classPrivateFieldGet(this, _onPresentationModeChanged)) {
  10927. var _this$_eventBus2;
  10928. (_this$_eventBus2 = this._eventBus) === null || _this$_eventBus2 === void 0 ? void 0 : _this$_eventBus2._off("presentationmodechanged", _classPrivateFieldGet(this, _onPresentationModeChanged));
  10929. _classPrivateFieldSet(this, _onPresentationModeChanged, null);
  10930. }
  10931. }
  10932. hide() {
  10933. if (!this.div) {
  10934. return;
  10935. }
  10936. this.div.hidden = true;
  10937. }
  10938. }
  10939. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  10940. function _updatePresentationModeState2(state) {
  10941. if (!this.div) {
  10942. return;
  10943. }
  10944. let disableFormElements = false;
  10945. switch (state) {
  10946. case _ui_utils.PresentationModeState.FULLSCREEN:
  10947. disableFormElements = true;
  10948. break;
  10949. case _ui_utils.PresentationModeState.NORMAL:
  10950. break;
  10951. default:
  10952. return;
  10953. }
  10954. for (const section of this.div.childNodes) {
  10955. if (section.hasAttribute("data-internal-link")) {
  10956. continue;
  10957. }
  10958. section.inert = disableFormElements;
  10959. }
  10960. }
  10961. /***/ }),
  10962. /* 33 */
  10963. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10964. Object.defineProperty(exports, "__esModule", ({
  10965. value: true
  10966. }));
  10967. exports.PDFPageView = void 0;
  10968. var _pdfjsLib = __webpack_require__(5);
  10969. var _ui_utils = __webpack_require__(1);
  10970. var _app_options = __webpack_require__(2);
  10971. var _l10n_utils = __webpack_require__(31);
  10972. var _text_accessibility = __webpack_require__(34);
  10973. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  10974. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  10975. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  10976. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  10977. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  10978. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  10979. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  10980. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  10981. var _annotationMode = /*#__PURE__*/new WeakMap();
  10982. var _useThumbnailCanvas = /*#__PURE__*/new WeakMap();
  10983. class PDFPageView {
  10984. constructor(options) {
  10985. var _options$textHighligh, _this$renderingQueue;
  10986. _classPrivateFieldInitSpec(this, _annotationMode, {
  10987. writable: true,
  10988. value: _pdfjsLib.AnnotationMode.ENABLE_FORMS
  10989. });
  10990. _classPrivateFieldInitSpec(this, _useThumbnailCanvas, {
  10991. writable: true,
  10992. value: {
  10993. initialOptionalContent: true,
  10994. regularAnnotations: true
  10995. }
  10996. });
  10997. const container = options.container;
  10998. const defaultViewport = options.defaultViewport;
  10999. this.id = options.id;
  11000. this.renderingId = "page" + this.id;
  11001. this.pdfPage = null;
  11002. this.pageLabel = null;
  11003. this.rotation = 0;
  11004. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  11005. this.viewport = defaultViewport;
  11006. this.pdfPageRotate = defaultViewport.rotation;
  11007. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  11008. this.hasRestrictedScaling = false;
  11009. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  11010. _classPrivateFieldSet(this, _annotationMode, options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS);
  11011. this.imageResourcesPath = options.imageResourcesPath || "";
  11012. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  11013. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  11014. this.pageColors = options.pageColors || null;
  11015. this.eventBus = options.eventBus;
  11016. this.renderingQueue = options.renderingQueue;
  11017. this.textLayerFactory = options.textLayerFactory;
  11018. this.annotationLayerFactory = options.annotationLayerFactory;
  11019. this.annotationEditorLayerFactory = options.annotationEditorLayerFactory;
  11020. this.xfaLayerFactory = options.xfaLayerFactory;
  11021. this.textHighlighter = (_options$textHighligh = options.textHighlighterFactory) === null || _options$textHighligh === void 0 ? void 0 : _options$textHighligh.createTextHighlighter({
  11022. pageIndex: this.id - 1,
  11023. eventBus: this.eventBus
  11024. });
  11025. this.structTreeLayerFactory = options.structTreeLayerFactory;
  11026. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  11027. this.l10n = options.l10n || _l10n_utils.NullL10n;
  11028. this.paintTask = null;
  11029. this.paintedViewportMap = new WeakMap();
  11030. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  11031. this.resume = null;
  11032. this._renderError = null;
  11033. this._isStandalone = !((_this$renderingQueue = this.renderingQueue) !== null && _this$renderingQueue !== void 0 && _this$renderingQueue.hasViewer());
  11034. this._annotationCanvasMap = null;
  11035. this.annotationLayer = null;
  11036. this.annotationEditorLayer = null;
  11037. this.textLayer = null;
  11038. this.zoomLayer = null;
  11039. this.xfaLayer = null;
  11040. this.structTreeLayer = null;
  11041. const div = document.createElement("div");
  11042. div.className = "page";
  11043. div.style.width = Math.floor(this.viewport.width) + "px";
  11044. div.style.height = Math.floor(this.viewport.height) + "px";
  11045. div.setAttribute("data-page-number", this.id);
  11046. div.setAttribute("role", "region");
  11047. this.l10n.get("page_landmark", {
  11048. page: this.id
  11049. }).then(msg => {
  11050. div.setAttribute("aria-label", msg);
  11051. });
  11052. this.div = div;
  11053. container === null || container === void 0 ? void 0 : container.append(div);
  11054. if (this._isStandalone) {
  11055. const {
  11056. optionalContentConfigPromise
  11057. } = options;
  11058. if (optionalContentConfigPromise) {
  11059. optionalContentConfigPromise.then(optionalContentConfig => {
  11060. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  11061. return;
  11062. }
  11063. _classPrivateFieldGet(this, _useThumbnailCanvas).initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  11064. });
  11065. }
  11066. }
  11067. }
  11068. setPdfPage(pdfPage) {
  11069. this.pdfPage = pdfPage;
  11070. this.pdfPageRotate = pdfPage.rotate;
  11071. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  11072. this.viewport = pdfPage.getViewport({
  11073. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  11074. rotation: totalRotation
  11075. });
  11076. this.reset();
  11077. }
  11078. destroy() {
  11079. var _this$pdfPage;
  11080. this.reset();
  11081. (_this$pdfPage = this.pdfPage) === null || _this$pdfPage === void 0 ? void 0 : _this$pdfPage.cleanup();
  11082. }
  11083. async _renderAnnotationLayer() {
  11084. let error = null;
  11085. try {
  11086. await this.annotationLayer.render(this.viewport, "display");
  11087. } catch (ex) {
  11088. console.error(`_renderAnnotationLayer: "${ex}".`);
  11089. error = ex;
  11090. } finally {
  11091. this.eventBus.dispatch("annotationlayerrendered", {
  11092. source: this,
  11093. pageNumber: this.id,
  11094. error
  11095. });
  11096. }
  11097. }
  11098. async _renderAnnotationEditorLayer() {
  11099. let error = null;
  11100. try {
  11101. await this.annotationEditorLayer.render(this.viewport, "display");
  11102. } catch (ex) {
  11103. console.error(`_renderAnnotationEditorLayer: "${ex}".`);
  11104. error = ex;
  11105. } finally {
  11106. this.eventBus.dispatch("annotationeditorlayerrendered", {
  11107. source: this,
  11108. pageNumber: this.id,
  11109. error
  11110. });
  11111. }
  11112. }
  11113. async _renderXfaLayer() {
  11114. let error = null;
  11115. try {
  11116. const result = await this.xfaLayer.render(this.viewport, "display");
  11117. if (result !== null && result !== void 0 && result.textDivs && this.textHighlighter) {
  11118. this._buildXfaTextContentItems(result.textDivs);
  11119. }
  11120. } catch (ex) {
  11121. console.error(`_renderXfaLayer: "${ex}".`);
  11122. error = ex;
  11123. } finally {
  11124. this.eventBus.dispatch("xfalayerrendered", {
  11125. source: this,
  11126. pageNumber: this.id,
  11127. error
  11128. });
  11129. }
  11130. }
  11131. async _buildXfaTextContentItems(textDivs) {
  11132. const text = await this.pdfPage.getTextContent();
  11133. const items = [];
  11134. for (const item of text.items) {
  11135. items.push(item.str);
  11136. }
  11137. this.textHighlighter.setTextMapping(textDivs, items);
  11138. this.textHighlighter.enable();
  11139. }
  11140. _resetZoomLayer() {
  11141. let removeFromDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  11142. if (!this.zoomLayer) {
  11143. return;
  11144. }
  11145. const zoomLayerCanvas = this.zoomLayer.firstChild;
  11146. this.paintedViewportMap.delete(zoomLayerCanvas);
  11147. zoomLayerCanvas.width = 0;
  11148. zoomLayerCanvas.height = 0;
  11149. if (removeFromDOM) {
  11150. this.zoomLayer.remove();
  11151. }
  11152. this.zoomLayer = null;
  11153. }
  11154. reset() {
  11155. var _this$annotationLayer, _this$annotationEdito, _this$xfaLayer;
  11156. let {
  11157. keepZoomLayer = false,
  11158. keepAnnotationLayer = false,
  11159. keepAnnotationEditorLayer = false,
  11160. keepXfaLayer = false
  11161. } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  11162. this.cancelRendering({
  11163. keepAnnotationLayer,
  11164. keepAnnotationEditorLayer,
  11165. keepXfaLayer
  11166. });
  11167. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  11168. const div = this.div;
  11169. div.style.width = Math.floor(this.viewport.width) + "px";
  11170. div.style.height = Math.floor(this.viewport.height) + "px";
  11171. const childNodes = div.childNodes,
  11172. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  11173. annotationLayerNode = keepAnnotationLayer && ((_this$annotationLayer = this.annotationLayer) === null || _this$annotationLayer === void 0 ? void 0 : _this$annotationLayer.div) || null,
  11174. annotationEditorLayerNode = keepAnnotationEditorLayer && ((_this$annotationEdito = this.annotationEditorLayer) === null || _this$annotationEdito === void 0 ? void 0 : _this$annotationEdito.div) || null,
  11175. xfaLayerNode = keepXfaLayer && ((_this$xfaLayer = this.xfaLayer) === null || _this$xfaLayer === void 0 ? void 0 : _this$xfaLayer.div) || null;
  11176. for (let i = childNodes.length - 1; i >= 0; i--) {
  11177. const node = childNodes[i];
  11178. switch (node) {
  11179. case zoomLayerNode:
  11180. case annotationLayerNode:
  11181. case annotationEditorLayerNode:
  11182. case xfaLayerNode:
  11183. continue;
  11184. }
  11185. node.remove();
  11186. }
  11187. div.removeAttribute("data-loaded");
  11188. if (annotationLayerNode) {
  11189. this.annotationLayer.hide();
  11190. }
  11191. if (annotationEditorLayerNode) {
  11192. this.annotationEditorLayer.hide();
  11193. } else {
  11194. var _this$annotationEdito2;
  11195. (_this$annotationEdito2 = this.annotationEditorLayer) === null || _this$annotationEdito2 === void 0 ? void 0 : _this$annotationEdito2.destroy();
  11196. }
  11197. if (xfaLayerNode) {
  11198. this.xfaLayer.hide();
  11199. }
  11200. if (!zoomLayerNode) {
  11201. if (this.canvas) {
  11202. this.paintedViewportMap.delete(this.canvas);
  11203. this.canvas.width = 0;
  11204. this.canvas.height = 0;
  11205. delete this.canvas;
  11206. }
  11207. this._resetZoomLayer();
  11208. }
  11209. if (this.svg) {
  11210. this.paintedViewportMap.delete(this.svg);
  11211. delete this.svg;
  11212. }
  11213. this.loadingIconDiv = document.createElement("div");
  11214. this.loadingIconDiv.className = "loadingIcon notVisible";
  11215. if (this._isStandalone) {
  11216. this.toggleLoadingIconSpinner(true);
  11217. }
  11218. this.loadingIconDiv.setAttribute("role", "img");
  11219. this.l10n.get("loading").then(msg => {
  11220. var _this$loadingIconDiv;
  11221. (_this$loadingIconDiv = this.loadingIconDiv) === null || _this$loadingIconDiv === void 0 ? void 0 : _this$loadingIconDiv.setAttribute("aria-label", msg);
  11222. });
  11223. div.append(this.loadingIconDiv);
  11224. }
  11225. update(_ref) {
  11226. let {
  11227. scale = 0,
  11228. rotation = null,
  11229. optionalContentConfigPromise = null
  11230. } = _ref;
  11231. this.scale = scale || this.scale;
  11232. if (typeof rotation === "number") {
  11233. this.rotation = rotation;
  11234. }
  11235. if (optionalContentConfigPromise instanceof Promise) {
  11236. this._optionalContentConfigPromise = optionalContentConfigPromise;
  11237. optionalContentConfigPromise.then(optionalContentConfig => {
  11238. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  11239. return;
  11240. }
  11241. _classPrivateFieldGet(this, _useThumbnailCanvas).initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  11242. });
  11243. }
  11244. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  11245. this.viewport = this.viewport.clone({
  11246. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  11247. rotation: totalRotation
  11248. });
  11249. if (this._isStandalone) {
  11250. _ui_utils.docStyle.setProperty("--scale-factor", this.viewport.scale);
  11251. }
  11252. if (this.svg) {
  11253. this.cssTransform({
  11254. target: this.svg,
  11255. redrawAnnotationLayer: true,
  11256. redrawAnnotationEditorLayer: true,
  11257. redrawXfaLayer: true
  11258. });
  11259. this.eventBus.dispatch("pagerendered", {
  11260. source: this,
  11261. pageNumber: this.id,
  11262. cssTransform: true,
  11263. timestamp: performance.now(),
  11264. error: this._renderError
  11265. });
  11266. return;
  11267. }
  11268. let isScalingRestricted = false;
  11269. if (this.canvas && this.maxCanvasPixels > 0) {
  11270. const outputScale = this.outputScale;
  11271. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  11272. isScalingRestricted = true;
  11273. }
  11274. }
  11275. if (this.canvas) {
  11276. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  11277. this.cssTransform({
  11278. target: this.canvas,
  11279. redrawAnnotationLayer: true,
  11280. redrawAnnotationEditorLayer: true,
  11281. redrawXfaLayer: true
  11282. });
  11283. this.eventBus.dispatch("pagerendered", {
  11284. source: this,
  11285. pageNumber: this.id,
  11286. cssTransform: true,
  11287. timestamp: performance.now(),
  11288. error: this._renderError
  11289. });
  11290. return;
  11291. }
  11292. if (!this.zoomLayer && !this.canvas.hidden) {
  11293. this.zoomLayer = this.canvas.parentNode;
  11294. this.zoomLayer.style.position = "absolute";
  11295. }
  11296. }
  11297. if (this.zoomLayer) {
  11298. this.cssTransform({
  11299. target: this.zoomLayer.firstChild
  11300. });
  11301. }
  11302. this.reset({
  11303. keepZoomLayer: true,
  11304. keepAnnotationLayer: true,
  11305. keepAnnotationEditorLayer: true,
  11306. keepXfaLayer: true
  11307. });
  11308. }
  11309. cancelRendering() {
  11310. let {
  11311. keepAnnotationLayer = false,
  11312. keepAnnotationEditorLayer = false,
  11313. keepXfaLayer = false
  11314. } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  11315. if (this.paintTask) {
  11316. this.paintTask.cancel();
  11317. this.paintTask = null;
  11318. }
  11319. this.resume = null;
  11320. if (this.textLayer) {
  11321. this.textLayer.cancel();
  11322. this.textLayer = null;
  11323. }
  11324. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  11325. this.annotationLayer.cancel();
  11326. this.annotationLayer = null;
  11327. this._annotationCanvasMap = null;
  11328. }
  11329. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  11330. this.annotationEditorLayer.cancel();
  11331. this.annotationEditorLayer = null;
  11332. }
  11333. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  11334. var _this$textHighlighter;
  11335. this.xfaLayer.cancel();
  11336. this.xfaLayer = null;
  11337. (_this$textHighlighter = this.textHighlighter) === null || _this$textHighlighter === void 0 ? void 0 : _this$textHighlighter.disable();
  11338. }
  11339. if (this._onTextLayerRendered) {
  11340. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  11341. this._onTextLayerRendered = null;
  11342. }
  11343. }
  11344. cssTransform(_ref2) {
  11345. let {
  11346. target,
  11347. redrawAnnotationLayer = false,
  11348. redrawAnnotationEditorLayer = false,
  11349. redrawXfaLayer = false
  11350. } = _ref2;
  11351. const width = this.viewport.width;
  11352. const height = this.viewport.height;
  11353. const div = this.div;
  11354. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  11355. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  11356. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  11357. const absRotation = Math.abs(relativeRotation);
  11358. let scaleX = 1,
  11359. scaleY = 1;
  11360. if (absRotation === 90 || absRotation === 270) {
  11361. scaleX = height / width;
  11362. scaleY = width / height;
  11363. }
  11364. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  11365. if (this.textLayer) {
  11366. const textLayerViewport = this.textLayer.viewport;
  11367. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  11368. const textAbsRotation = Math.abs(textRelativeRotation);
  11369. let scale = width / textLayerViewport.width;
  11370. if (textAbsRotation === 90 || textAbsRotation === 270) {
  11371. scale = width / textLayerViewport.height;
  11372. }
  11373. const textLayerDiv = this.textLayer.textLayerDiv;
  11374. let transX, transY;
  11375. switch (textAbsRotation) {
  11376. case 0:
  11377. transX = transY = 0;
  11378. break;
  11379. case 90:
  11380. transX = 0;
  11381. transY = "-" + textLayerDiv.style.height;
  11382. break;
  11383. case 180:
  11384. transX = "-" + textLayerDiv.style.width;
  11385. transY = "-" + textLayerDiv.style.height;
  11386. break;
  11387. case 270:
  11388. transX = "-" + textLayerDiv.style.width;
  11389. transY = 0;
  11390. break;
  11391. default:
  11392. console.error("Bad rotation value.");
  11393. break;
  11394. }
  11395. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  11396. textLayerDiv.style.transformOrigin = "0% 0%";
  11397. }
  11398. if (redrawAnnotationLayer && this.annotationLayer) {
  11399. this._renderAnnotationLayer();
  11400. }
  11401. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  11402. this._renderAnnotationEditorLayer();
  11403. }
  11404. if (redrawXfaLayer && this.xfaLayer) {
  11405. this._renderXfaLayer();
  11406. }
  11407. }
  11408. get width() {
  11409. return this.viewport.width;
  11410. }
  11411. get height() {
  11412. return this.viewport.height;
  11413. }
  11414. getPagePoint(x, y) {
  11415. return this.viewport.convertToPdfPoint(x, y);
  11416. }
  11417. toggleLoadingIconSpinner() {
  11418. var _this$loadingIconDiv2;
  11419. let viewVisible = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  11420. (_this$loadingIconDiv2 = this.loadingIconDiv) === null || _this$loadingIconDiv2 === void 0 ? void 0 : _this$loadingIconDiv2.classList.toggle("notVisible", !viewVisible);
  11421. }
  11422. draw() {
  11423. var _this$annotationLayer2,
  11424. _this$annotationEdito3,
  11425. _this$xfaLayer2,
  11426. _this = this;
  11427. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  11428. console.error("Must be in new state before drawing");
  11429. this.reset();
  11430. }
  11431. const {
  11432. div,
  11433. pdfPage
  11434. } = this;
  11435. if (!pdfPage) {
  11436. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  11437. if (this.loadingIconDiv) {
  11438. this.loadingIconDiv.remove();
  11439. delete this.loadingIconDiv;
  11440. }
  11441. return Promise.reject(new Error("pdfPage is not loaded"));
  11442. }
  11443. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  11444. const canvasWrapper = document.createElement("div");
  11445. canvasWrapper.style.width = div.style.width;
  11446. canvasWrapper.style.height = div.style.height;
  11447. canvasWrapper.classList.add("canvasWrapper");
  11448. const lastDivBeforeTextDiv = ((_this$annotationLayer2 = this.annotationLayer) === null || _this$annotationLayer2 === void 0 ? void 0 : _this$annotationLayer2.div) || ((_this$annotationEdito3 = this.annotationEditorLayer) === null || _this$annotationEdito3 === void 0 ? void 0 : _this$annotationEdito3.div);
  11449. if (lastDivBeforeTextDiv) {
  11450. lastDivBeforeTextDiv.before(canvasWrapper);
  11451. } else {
  11452. div.append(canvasWrapper);
  11453. }
  11454. let textLayer = null;
  11455. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  11456. this._accessibilityManager || (this._accessibilityManager = new _text_accessibility.TextAccessibilityManager());
  11457. const textLayerDiv = document.createElement("div");
  11458. textLayerDiv.className = "textLayer";
  11459. textLayerDiv.style.width = canvasWrapper.style.width;
  11460. textLayerDiv.style.height = canvasWrapper.style.height;
  11461. if (lastDivBeforeTextDiv) {
  11462. lastDivBeforeTextDiv.before(textLayerDiv);
  11463. } else {
  11464. div.append(textLayerDiv);
  11465. }
  11466. textLayer = this.textLayerFactory.createTextLayerBuilder({
  11467. textLayerDiv,
  11468. pageIndex: this.id - 1,
  11469. viewport: this.viewport,
  11470. eventBus: this.eventBus,
  11471. highlighter: this.textHighlighter,
  11472. accessibilityManager: this._accessibilityManager
  11473. });
  11474. }
  11475. this.textLayer = textLayer;
  11476. if (_classPrivateFieldGet(this, _annotationMode) !== _pdfjsLib.AnnotationMode.DISABLE && this.annotationLayerFactory) {
  11477. this._annotationCanvasMap || (this._annotationCanvasMap = new Map());
  11478. this.annotationLayer || (this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder({
  11479. pageDiv: div,
  11480. pdfPage,
  11481. imageResourcesPath: this.imageResourcesPath,
  11482. renderForms: _classPrivateFieldGet(this, _annotationMode) === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  11483. l10n: this.l10n,
  11484. annotationCanvasMap: this._annotationCanvasMap,
  11485. accessibilityManager: this._accessibilityManager
  11486. }));
  11487. }
  11488. if ((_this$xfaLayer2 = this.xfaLayer) !== null && _this$xfaLayer2 !== void 0 && _this$xfaLayer2.div) {
  11489. div.append(this.xfaLayer.div);
  11490. }
  11491. let renderContinueCallback = null;
  11492. if (this.renderingQueue) {
  11493. renderContinueCallback = cont => {
  11494. if (!this.renderingQueue.isHighestPriority(this)) {
  11495. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  11496. this.resume = () => {
  11497. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  11498. cont();
  11499. };
  11500. return;
  11501. }
  11502. cont();
  11503. };
  11504. }
  11505. const finishPaintTask = async function () {
  11506. let error = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  11507. if (paintTask === _this.paintTask) {
  11508. _this.paintTask = null;
  11509. }
  11510. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  11511. _this._renderError = null;
  11512. return;
  11513. }
  11514. _this._renderError = error;
  11515. _this.renderingState = _ui_utils.RenderingStates.FINISHED;
  11516. if (_this.loadingIconDiv) {
  11517. _this.loadingIconDiv.remove();
  11518. delete _this.loadingIconDiv;
  11519. }
  11520. _this._resetZoomLayer(true);
  11521. _classPrivateFieldGet(_this, _useThumbnailCanvas).regularAnnotations = !paintTask.separateAnnots;
  11522. _this.eventBus.dispatch("pagerendered", {
  11523. source: _this,
  11524. pageNumber: _this.id,
  11525. cssTransform: false,
  11526. timestamp: performance.now(),
  11527. error: _this._renderError
  11528. });
  11529. if (error) {
  11530. throw error;
  11531. }
  11532. };
  11533. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  11534. paintTask.onRenderContinue = renderContinueCallback;
  11535. this.paintTask = paintTask;
  11536. const resultPromise = paintTask.promise.then(() => {
  11537. return finishPaintTask(null).then(() => {
  11538. if (textLayer) {
  11539. const readableStream = pdfPage.streamTextContent({
  11540. includeMarkedContent: true
  11541. });
  11542. textLayer.setTextContentStream(readableStream);
  11543. textLayer.render();
  11544. }
  11545. if (this.annotationLayer) {
  11546. this._renderAnnotationLayer().then(() => {
  11547. if (this.annotationEditorLayerFactory) {
  11548. this.annotationEditorLayer || (this.annotationEditorLayer = this.annotationEditorLayerFactory.createAnnotationEditorLayerBuilder({
  11549. pageDiv: div,
  11550. pdfPage,
  11551. l10n: this.l10n,
  11552. accessibilityManager: this._accessibilityManager
  11553. }));
  11554. this._renderAnnotationEditorLayer();
  11555. }
  11556. });
  11557. }
  11558. });
  11559. }, function (reason) {
  11560. return finishPaintTask(reason);
  11561. });
  11562. if (this.xfaLayerFactory) {
  11563. this.xfaLayer || (this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder({
  11564. pageDiv: div,
  11565. pdfPage
  11566. }));
  11567. this._renderXfaLayer();
  11568. }
  11569. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  11570. this._onTextLayerRendered = event => {
  11571. if (event.pageNumber !== this.id) {
  11572. return;
  11573. }
  11574. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  11575. this._onTextLayerRendered = null;
  11576. if (!this.canvas) {
  11577. return;
  11578. }
  11579. this.pdfPage.getStructTree().then(tree => {
  11580. if (!tree) {
  11581. return;
  11582. }
  11583. if (!this.canvas) {
  11584. return;
  11585. }
  11586. const treeDom = this.structTreeLayer.render(tree);
  11587. treeDom.classList.add("structTree");
  11588. this.canvas.append(treeDom);
  11589. });
  11590. };
  11591. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  11592. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder({
  11593. pdfPage
  11594. });
  11595. }
  11596. div.setAttribute("data-loaded", true);
  11597. this.eventBus.dispatch("pagerender", {
  11598. source: this,
  11599. pageNumber: this.id
  11600. });
  11601. return resultPromise;
  11602. }
  11603. paintOnCanvas(canvasWrapper) {
  11604. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  11605. const result = {
  11606. promise: renderCapability.promise,
  11607. onRenderContinue(cont) {
  11608. cont();
  11609. },
  11610. cancel() {
  11611. renderTask.cancel();
  11612. },
  11613. get separateAnnots() {
  11614. return renderTask.separateAnnots;
  11615. }
  11616. };
  11617. const viewport = this.viewport;
  11618. const canvas = document.createElement("canvas");
  11619. canvas.setAttribute("role", "presentation");
  11620. canvas.hidden = true;
  11621. let isCanvasHidden = true;
  11622. const showCanvas = function () {
  11623. if (isCanvasHidden) {
  11624. canvas.hidden = false;
  11625. isCanvasHidden = false;
  11626. }
  11627. };
  11628. canvasWrapper.append(canvas);
  11629. this.canvas = canvas;
  11630. const ctx = canvas.getContext("2d", {
  11631. alpha: false
  11632. });
  11633. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  11634. if (this.useOnlyCssZoom) {
  11635. const actualSizeViewport = viewport.clone({
  11636. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  11637. });
  11638. outputScale.sx *= actualSizeViewport.width / viewport.width;
  11639. outputScale.sy *= actualSizeViewport.height / viewport.height;
  11640. }
  11641. if (this.maxCanvasPixels > 0) {
  11642. const pixelsInViewport = viewport.width * viewport.height;
  11643. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  11644. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  11645. outputScale.sx = maxScale;
  11646. outputScale.sy = maxScale;
  11647. this.hasRestrictedScaling = true;
  11648. } else {
  11649. this.hasRestrictedScaling = false;
  11650. }
  11651. }
  11652. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  11653. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  11654. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  11655. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  11656. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  11657. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  11658. this.paintedViewportMap.set(canvas, viewport);
  11659. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  11660. const renderContext = {
  11661. canvasContext: ctx,
  11662. transform,
  11663. viewport: this.viewport,
  11664. annotationMode: _classPrivateFieldGet(this, _annotationMode),
  11665. optionalContentConfigPromise: this._optionalContentConfigPromise,
  11666. annotationCanvasMap: this._annotationCanvasMap,
  11667. pageColors: this.pageColors
  11668. };
  11669. const renderTask = this.pdfPage.render(renderContext);
  11670. renderTask.onContinue = function (cont) {
  11671. showCanvas();
  11672. if (result.onRenderContinue) {
  11673. result.onRenderContinue(cont);
  11674. } else {
  11675. cont();
  11676. }
  11677. };
  11678. renderTask.promise.then(function () {
  11679. showCanvas();
  11680. renderCapability.resolve();
  11681. }, function (error) {
  11682. showCanvas();
  11683. renderCapability.reject(error);
  11684. });
  11685. return result;
  11686. }
  11687. paintOnSvg(wrapper) {
  11688. let cancelled = false;
  11689. const ensureNotCancelled = () => {
  11690. if (cancelled) {
  11691. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  11692. }
  11693. };
  11694. const pdfPage = this.pdfPage;
  11695. const actualSizeViewport = this.viewport.clone({
  11696. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  11697. });
  11698. const promise = pdfPage.getOperatorList({
  11699. annotationMode: _classPrivateFieldGet(this, _annotationMode)
  11700. }).then(opList => {
  11701. ensureNotCancelled();
  11702. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  11703. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  11704. ensureNotCancelled();
  11705. this.svg = svg;
  11706. this.paintedViewportMap.set(svg, actualSizeViewport);
  11707. svg.style.width = wrapper.style.width;
  11708. svg.style.height = wrapper.style.height;
  11709. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  11710. wrapper.append(svg);
  11711. });
  11712. });
  11713. return {
  11714. promise,
  11715. onRenderContinue(cont) {
  11716. cont();
  11717. },
  11718. cancel() {
  11719. cancelled = true;
  11720. },
  11721. get separateAnnots() {
  11722. return false;
  11723. }
  11724. };
  11725. }
  11726. setPageLabel(label) {
  11727. this.pageLabel = typeof label === "string" ? label : null;
  11728. if (this.pageLabel !== null) {
  11729. this.div.setAttribute("data-page-label", this.pageLabel);
  11730. } else {
  11731. this.div.removeAttribute("data-page-label");
  11732. }
  11733. }
  11734. get thumbnailCanvas() {
  11735. const {
  11736. initialOptionalContent,
  11737. regularAnnotations
  11738. } = _classPrivateFieldGet(this, _useThumbnailCanvas);
  11739. return initialOptionalContent && regularAnnotations ? this.canvas : null;
  11740. }
  11741. }
  11742. exports.PDFPageView = PDFPageView;
  11743. /***/ }),
  11744. /* 34 */
  11745. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11746. Object.defineProperty(exports, "__esModule", ({
  11747. value: true
  11748. }));
  11749. exports.TextAccessibilityManager = void 0;
  11750. var _ui_utils = __webpack_require__(1);
  11751. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  11752. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  11753. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  11754. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  11755. function _classStaticPrivateMethodGet(receiver, classConstructor, method) { _classCheckPrivateStaticAccess(receiver, classConstructor); return method; }
  11756. function _classCheckPrivateStaticAccess(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } }
  11757. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  11758. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  11759. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  11760. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  11761. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  11762. var _enabled = /*#__PURE__*/new WeakMap();
  11763. var _textChildren = /*#__PURE__*/new WeakMap();
  11764. var _textNodes = /*#__PURE__*/new WeakMap();
  11765. var _waitingElements = /*#__PURE__*/new WeakMap();
  11766. var _addIdToAriaOwns = /*#__PURE__*/new WeakSet();
  11767. class TextAccessibilityManager {
  11768. constructor() {
  11769. _classPrivateMethodInitSpec(this, _addIdToAriaOwns);
  11770. _classPrivateFieldInitSpec(this, _enabled, {
  11771. writable: true,
  11772. value: false
  11773. });
  11774. _classPrivateFieldInitSpec(this, _textChildren, {
  11775. writable: true,
  11776. value: null
  11777. });
  11778. _classPrivateFieldInitSpec(this, _textNodes, {
  11779. writable: true,
  11780. value: new Map()
  11781. });
  11782. _classPrivateFieldInitSpec(this, _waitingElements, {
  11783. writable: true,
  11784. value: new Map()
  11785. });
  11786. }
  11787. setTextMapping(textDivs) {
  11788. _classPrivateFieldSet(this, _textChildren, textDivs);
  11789. }
  11790. enable() {
  11791. if (_classPrivateFieldGet(this, _enabled)) {
  11792. throw new Error("TextAccessibilityManager is already enabled.");
  11793. }
  11794. if (!_classPrivateFieldGet(this, _textChildren)) {
  11795. throw new Error("Text divs and strings have not been set.");
  11796. }
  11797. _classPrivateFieldSet(this, _enabled, true);
  11798. _classPrivateFieldSet(this, _textChildren, _classPrivateFieldGet(this, _textChildren).slice());
  11799. _classPrivateFieldGet(this, _textChildren).sort(_classStaticPrivateMethodGet(TextAccessibilityManager, TextAccessibilityManager, _compareElementPositions));
  11800. if (_classPrivateFieldGet(this, _textNodes).size > 0) {
  11801. const textChildren = _classPrivateFieldGet(this, _textChildren);
  11802. for (const [id, nodeIndex] of _classPrivateFieldGet(this, _textNodes)) {
  11803. const element = document.getElementById(id);
  11804. if (!element) {
  11805. _classPrivateFieldGet(this, _textNodes).delete(id);
  11806. continue;
  11807. }
  11808. _classPrivateMethodGet(this, _addIdToAriaOwns, _addIdToAriaOwns2).call(this, id, textChildren[nodeIndex]);
  11809. }
  11810. }
  11811. for (const [element, isRemovable] of _classPrivateFieldGet(this, _waitingElements)) {
  11812. this.addPointerInTextLayer(element, isRemovable);
  11813. }
  11814. _classPrivateFieldGet(this, _waitingElements).clear();
  11815. }
  11816. disable() {
  11817. if (!_classPrivateFieldGet(this, _enabled)) {
  11818. return;
  11819. }
  11820. _classPrivateFieldGet(this, _waitingElements).clear();
  11821. _classPrivateFieldSet(this, _textChildren, null);
  11822. _classPrivateFieldSet(this, _enabled, false);
  11823. }
  11824. removePointerInTextLayer(element) {
  11825. var _owns;
  11826. if (!_classPrivateFieldGet(this, _enabled)) {
  11827. _classPrivateFieldGet(this, _waitingElements).delete(element);
  11828. return;
  11829. }
  11830. const children = _classPrivateFieldGet(this, _textChildren);
  11831. if (!children || children.length === 0) {
  11832. return;
  11833. }
  11834. const {
  11835. id
  11836. } = element;
  11837. const nodeIndex = _classPrivateFieldGet(this, _textNodes).get(id);
  11838. if (nodeIndex === undefined) {
  11839. return;
  11840. }
  11841. const node = children[nodeIndex];
  11842. _classPrivateFieldGet(this, _textNodes).delete(id);
  11843. let owns = node.getAttribute("aria-owns");
  11844. if ((_owns = owns) !== null && _owns !== void 0 && _owns.includes(id)) {
  11845. owns = owns.split(" ").filter(x => x !== id).join(" ");
  11846. if (owns) {
  11847. node.setAttribute("aria-owns", owns);
  11848. } else {
  11849. node.removeAttribute("aria-owns");
  11850. node.setAttribute("role", "presentation");
  11851. }
  11852. }
  11853. }
  11854. addPointerInTextLayer(element, isRemovable) {
  11855. const {
  11856. id
  11857. } = element;
  11858. if (!id) {
  11859. return;
  11860. }
  11861. if (!_classPrivateFieldGet(this, _enabled)) {
  11862. _classPrivateFieldGet(this, _waitingElements).set(element, isRemovable);
  11863. return;
  11864. }
  11865. if (isRemovable) {
  11866. this.removePointerInTextLayer(element);
  11867. }
  11868. const children = _classPrivateFieldGet(this, _textChildren);
  11869. if (!children || children.length === 0) {
  11870. return;
  11871. }
  11872. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => _classStaticPrivateMethodGet(TextAccessibilityManager, TextAccessibilityManager, _compareElementPositions).call(TextAccessibilityManager, element, node) < 0);
  11873. const nodeIndex = Math.max(0, index - 1);
  11874. _classPrivateMethodGet(this, _addIdToAriaOwns, _addIdToAriaOwns2).call(this, id, children[nodeIndex]);
  11875. _classPrivateFieldGet(this, _textNodes).set(id, nodeIndex);
  11876. }
  11877. moveElementInDOM(container, element, contentElement, isRemovable) {
  11878. this.addPointerInTextLayer(contentElement, isRemovable);
  11879. if (!container.hasChildNodes()) {
  11880. container.append(element);
  11881. return;
  11882. }
  11883. const children = Array.from(container.childNodes).filter(node => node !== element);
  11884. if (children.length === 0) {
  11885. return;
  11886. }
  11887. const elementToCompare = contentElement || element;
  11888. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => _classStaticPrivateMethodGet(TextAccessibilityManager, TextAccessibilityManager, _compareElementPositions).call(TextAccessibilityManager, elementToCompare, node) < 0);
  11889. if (index === 0) {
  11890. children[0].before(element);
  11891. } else {
  11892. children[index - 1].after(element);
  11893. }
  11894. }
  11895. }
  11896. exports.TextAccessibilityManager = TextAccessibilityManager;
  11897. function _compareElementPositions(e1, e2) {
  11898. const rect1 = e1.getBoundingClientRect();
  11899. const rect2 = e2.getBoundingClientRect();
  11900. if (rect1.width === 0 && rect1.height === 0) {
  11901. return +1;
  11902. }
  11903. if (rect2.width === 0 && rect2.height === 0) {
  11904. return -1;
  11905. }
  11906. const top1 = rect1.y;
  11907. const bot1 = rect1.y + rect1.height;
  11908. const mid1 = rect1.y + rect1.height / 2;
  11909. const top2 = rect2.y;
  11910. const bot2 = rect2.y + rect2.height;
  11911. const mid2 = rect2.y + rect2.height / 2;
  11912. if (mid1 <= top2 && mid2 >= bot1) {
  11913. return -1;
  11914. }
  11915. if (mid2 <= top1 && mid1 >= bot2) {
  11916. return +1;
  11917. }
  11918. const centerX1 = rect1.x + rect1.width / 2;
  11919. const centerX2 = rect2.x + rect2.width / 2;
  11920. return centerX1 - centerX2;
  11921. }
  11922. function _addIdToAriaOwns2(id, node) {
  11923. const owns = node.getAttribute("aria-owns");
  11924. if (!(owns !== null && owns !== void 0 && owns.includes(id))) {
  11925. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  11926. }
  11927. node.removeAttribute("role");
  11928. }
  11929. /***/ }),
  11930. /* 35 */
  11931. /***/ ((__unused_webpack_module, exports) => {
  11932. Object.defineProperty(exports, "__esModule", ({
  11933. value: true
  11934. }));
  11935. exports.StructTreeLayerBuilder = void 0;
  11936. const PDF_ROLE_TO_HTML_ROLE = {
  11937. Document: null,
  11938. DocumentFragment: null,
  11939. Part: "group",
  11940. Sect: "group",
  11941. Div: "group",
  11942. Aside: "note",
  11943. NonStruct: "none",
  11944. P: null,
  11945. H: "heading",
  11946. Title: null,
  11947. FENote: "note",
  11948. Sub: "group",
  11949. Lbl: null,
  11950. Span: null,
  11951. Em: null,
  11952. Strong: null,
  11953. Link: "link",
  11954. Annot: "note",
  11955. Form: "form",
  11956. Ruby: null,
  11957. RB: null,
  11958. RT: null,
  11959. RP: null,
  11960. Warichu: null,
  11961. WT: null,
  11962. WP: null,
  11963. L: "list",
  11964. LI: "listitem",
  11965. LBody: null,
  11966. Table: "table",
  11967. TR: "row",
  11968. TH: "columnheader",
  11969. TD: "cell",
  11970. THead: "columnheader",
  11971. TBody: null,
  11972. TFoot: null,
  11973. Caption: null,
  11974. Figure: "figure",
  11975. Formula: null,
  11976. Artifact: null
  11977. };
  11978. const HEADING_PATTERN = /^H(\d+)$/;
  11979. class StructTreeLayerBuilder {
  11980. constructor(_ref) {
  11981. let {
  11982. pdfPage
  11983. } = _ref;
  11984. this.pdfPage = pdfPage;
  11985. }
  11986. render(structTree) {
  11987. return this._walk(structTree);
  11988. }
  11989. _setAttributes(structElement, htmlElement) {
  11990. if (structElement.alt !== undefined) {
  11991. htmlElement.setAttribute("aria-label", structElement.alt);
  11992. }
  11993. if (structElement.id !== undefined) {
  11994. htmlElement.setAttribute("aria-owns", structElement.id);
  11995. }
  11996. if (structElement.lang !== undefined) {
  11997. htmlElement.setAttribute("lang", structElement.lang);
  11998. }
  11999. }
  12000. _walk(node) {
  12001. if (!node) {
  12002. return null;
  12003. }
  12004. const element = document.createElement("span");
  12005. if ("role" in node) {
  12006. const {
  12007. role
  12008. } = node;
  12009. const match = role.match(HEADING_PATTERN);
  12010. if (match) {
  12011. element.setAttribute("role", "heading");
  12012. element.setAttribute("aria-level", match[1]);
  12013. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  12014. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  12015. }
  12016. }
  12017. this._setAttributes(node, element);
  12018. if (node.children) {
  12019. if (node.children.length === 1 && "id" in node.children[0]) {
  12020. this._setAttributes(node.children[0], element);
  12021. } else {
  12022. for (const kid of node.children) {
  12023. element.append(this._walk(kid));
  12024. }
  12025. }
  12026. }
  12027. return element;
  12028. }
  12029. }
  12030. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  12031. /***/ }),
  12032. /* 36 */
  12033. /***/ ((__unused_webpack_module, exports) => {
  12034. Object.defineProperty(exports, "__esModule", ({
  12035. value: true
  12036. }));
  12037. exports.TextHighlighter = void 0;
  12038. class TextHighlighter {
  12039. constructor(_ref) {
  12040. let {
  12041. findController,
  12042. eventBus,
  12043. pageIndex
  12044. } = _ref;
  12045. this.findController = findController;
  12046. this.matches = [];
  12047. this.eventBus = eventBus;
  12048. this.pageIdx = pageIndex;
  12049. this._onUpdateTextLayerMatches = null;
  12050. this.textDivs = null;
  12051. this.textContentItemsStr = null;
  12052. this.enabled = false;
  12053. }
  12054. setTextMapping(divs, texts) {
  12055. this.textDivs = divs;
  12056. this.textContentItemsStr = texts;
  12057. }
  12058. enable() {
  12059. if (!this.textDivs || !this.textContentItemsStr) {
  12060. throw new Error("Text divs and strings have not been set.");
  12061. }
  12062. if (this.enabled) {
  12063. throw new Error("TextHighlighter is already enabled.");
  12064. }
  12065. this.enabled = true;
  12066. if (!this._onUpdateTextLayerMatches) {
  12067. this._onUpdateTextLayerMatches = evt => {
  12068. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  12069. this._updateMatches();
  12070. }
  12071. };
  12072. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  12073. }
  12074. this._updateMatches();
  12075. }
  12076. disable() {
  12077. if (!this.enabled) {
  12078. return;
  12079. }
  12080. this.enabled = false;
  12081. if (this._onUpdateTextLayerMatches) {
  12082. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  12083. this._onUpdateTextLayerMatches = null;
  12084. }
  12085. }
  12086. _convertMatches(matches, matchesLength) {
  12087. if (!matches) {
  12088. return [];
  12089. }
  12090. const {
  12091. textContentItemsStr
  12092. } = this;
  12093. let i = 0,
  12094. iIndex = 0;
  12095. const end = textContentItemsStr.length - 1;
  12096. const result = [];
  12097. for (let m = 0, mm = matches.length; m < mm; m++) {
  12098. let matchIdx = matches[m];
  12099. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  12100. iIndex += textContentItemsStr[i].length;
  12101. i++;
  12102. }
  12103. if (i === textContentItemsStr.length) {
  12104. console.error("Could not find a matching mapping");
  12105. }
  12106. const match = {
  12107. begin: {
  12108. divIdx: i,
  12109. offset: matchIdx - iIndex
  12110. }
  12111. };
  12112. matchIdx += matchesLength[m];
  12113. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  12114. iIndex += textContentItemsStr[i].length;
  12115. i++;
  12116. }
  12117. match.end = {
  12118. divIdx: i,
  12119. offset: matchIdx - iIndex
  12120. };
  12121. result.push(match);
  12122. }
  12123. return result;
  12124. }
  12125. _renderMatches(matches) {
  12126. if (matches.length === 0) {
  12127. return;
  12128. }
  12129. const {
  12130. findController,
  12131. pageIdx
  12132. } = this;
  12133. const {
  12134. textContentItemsStr,
  12135. textDivs
  12136. } = this;
  12137. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  12138. const selectedMatchIdx = findController.selected.matchIdx;
  12139. const highlightAll = findController.state.highlightAll;
  12140. let prevEnd = null;
  12141. const infinity = {
  12142. divIdx: -1,
  12143. offset: undefined
  12144. };
  12145. function beginText(begin, className) {
  12146. const divIdx = begin.divIdx;
  12147. textDivs[divIdx].textContent = "";
  12148. return appendTextToDiv(divIdx, 0, begin.offset, className);
  12149. }
  12150. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  12151. let div = textDivs[divIdx];
  12152. if (div.nodeType === Node.TEXT_NODE) {
  12153. const span = document.createElement("span");
  12154. div.before(span);
  12155. span.append(div);
  12156. textDivs[divIdx] = span;
  12157. div = span;
  12158. }
  12159. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  12160. const node = document.createTextNode(content);
  12161. if (className) {
  12162. const span = document.createElement("span");
  12163. span.className = `${className} appended`;
  12164. span.append(node);
  12165. div.append(span);
  12166. return className.includes("selected") ? span.offsetLeft : 0;
  12167. }
  12168. div.append(node);
  12169. return 0;
  12170. }
  12171. let i0 = selectedMatchIdx,
  12172. i1 = i0 + 1;
  12173. if (highlightAll) {
  12174. i0 = 0;
  12175. i1 = matches.length;
  12176. } else if (!isSelectedPage) {
  12177. return;
  12178. }
  12179. for (let i = i0; i < i1; i++) {
  12180. const match = matches[i];
  12181. const begin = match.begin;
  12182. const end = match.end;
  12183. const isSelected = isSelectedPage && i === selectedMatchIdx;
  12184. const highlightSuffix = isSelected ? " selected" : "";
  12185. let selectedLeft = 0;
  12186. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  12187. if (prevEnd !== null) {
  12188. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  12189. }
  12190. beginText(begin);
  12191. } else {
  12192. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  12193. }
  12194. if (begin.divIdx === end.divIdx) {
  12195. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  12196. } else {
  12197. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  12198. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  12199. textDivs[n0].className = "highlight middle" + highlightSuffix;
  12200. }
  12201. beginText(end, "highlight end" + highlightSuffix);
  12202. }
  12203. prevEnd = end;
  12204. if (isSelected) {
  12205. findController.scrollMatchIntoView({
  12206. element: textDivs[begin.divIdx],
  12207. selectedLeft,
  12208. pageIndex: pageIdx,
  12209. matchIndex: selectedMatchIdx
  12210. });
  12211. }
  12212. }
  12213. if (prevEnd) {
  12214. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  12215. }
  12216. }
  12217. _updateMatches() {
  12218. if (!this.enabled) {
  12219. return;
  12220. }
  12221. const {
  12222. findController,
  12223. matches,
  12224. pageIdx
  12225. } = this;
  12226. const {
  12227. textContentItemsStr,
  12228. textDivs
  12229. } = this;
  12230. let clearedUntilDivIdx = -1;
  12231. for (const match of matches) {
  12232. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  12233. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  12234. const div = textDivs[n];
  12235. div.textContent = textContentItemsStr[n];
  12236. div.className = "";
  12237. }
  12238. clearedUntilDivIdx = match.end.divIdx + 1;
  12239. }
  12240. if (!(findController !== null && findController !== void 0 && findController.highlightMatches)) {
  12241. return;
  12242. }
  12243. const pageMatches = findController.pageMatches[pageIdx] || null;
  12244. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  12245. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  12246. this._renderMatches(this.matches);
  12247. }
  12248. }
  12249. exports.TextHighlighter = TextHighlighter;
  12250. /***/ }),
  12251. /* 37 */
  12252. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12253. Object.defineProperty(exports, "__esModule", ({
  12254. value: true
  12255. }));
  12256. exports.TextLayerBuilder = void 0;
  12257. var _pdfjsLib = __webpack_require__(5);
  12258. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  12259. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  12260. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  12261. var _finishRendering = /*#__PURE__*/new WeakSet();
  12262. var _bindMouse = /*#__PURE__*/new WeakSet();
  12263. class TextLayerBuilder {
  12264. constructor(_ref) {
  12265. let {
  12266. textLayerDiv,
  12267. eventBus,
  12268. pageIndex,
  12269. viewport,
  12270. highlighter = null,
  12271. accessibilityManager = null
  12272. } = _ref;
  12273. _classPrivateMethodInitSpec(this, _bindMouse);
  12274. _classPrivateMethodInitSpec(this, _finishRendering);
  12275. this.textLayerDiv = textLayerDiv;
  12276. this.eventBus = eventBus;
  12277. this.textContent = null;
  12278. this.textContentItemsStr = [];
  12279. this.textContentStream = null;
  12280. this.renderingDone = false;
  12281. this.pageNumber = pageIndex + 1;
  12282. this.viewport = viewport;
  12283. this.textDivs = [];
  12284. this.textLayerRenderTask = null;
  12285. this.highlighter = highlighter;
  12286. this.accessibilityManager = accessibilityManager;
  12287. _classPrivateMethodGet(this, _bindMouse, _bindMouse2).call(this);
  12288. }
  12289. render() {
  12290. var _this$highlighter, _this$accessibilityMa;
  12291. let timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  12292. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  12293. return;
  12294. }
  12295. this.cancel();
  12296. this.textDivs.length = 0;
  12297. (_this$highlighter = this.highlighter) === null || _this$highlighter === void 0 ? void 0 : _this$highlighter.setTextMapping(this.textDivs, this.textContentItemsStr);
  12298. (_this$accessibilityMa = this.accessibilityManager) === null || _this$accessibilityMa === void 0 ? void 0 : _this$accessibilityMa.setTextMapping(this.textDivs);
  12299. const textLayerFrag = document.createDocumentFragment();
  12300. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  12301. textContent: this.textContent,
  12302. textContentStream: this.textContentStream,
  12303. container: textLayerFrag,
  12304. viewport: this.viewport,
  12305. textDivs: this.textDivs,
  12306. textContentItemsStr: this.textContentItemsStr,
  12307. timeout
  12308. });
  12309. this.textLayerRenderTask.promise.then(() => {
  12310. var _this$highlighter2, _this$accessibilityMa2;
  12311. this.textLayerDiv.append(textLayerFrag);
  12312. _classPrivateMethodGet(this, _finishRendering, _finishRendering2).call(this);
  12313. (_this$highlighter2 = this.highlighter) === null || _this$highlighter2 === void 0 ? void 0 : _this$highlighter2.enable();
  12314. (_this$accessibilityMa2 = this.accessibilityManager) === null || _this$accessibilityMa2 === void 0 ? void 0 : _this$accessibilityMa2.enable();
  12315. }, function (reason) {});
  12316. }
  12317. cancel() {
  12318. var _this$highlighter3, _this$accessibilityMa3;
  12319. if (this.textLayerRenderTask) {
  12320. this.textLayerRenderTask.cancel();
  12321. this.textLayerRenderTask = null;
  12322. }
  12323. (_this$highlighter3 = this.highlighter) === null || _this$highlighter3 === void 0 ? void 0 : _this$highlighter3.disable();
  12324. (_this$accessibilityMa3 = this.accessibilityManager) === null || _this$accessibilityMa3 === void 0 ? void 0 : _this$accessibilityMa3.disable();
  12325. }
  12326. setTextContentStream(readableStream) {
  12327. this.cancel();
  12328. this.textContentStream = readableStream;
  12329. }
  12330. setTextContent(textContent) {
  12331. this.cancel();
  12332. this.textContent = textContent;
  12333. }
  12334. }
  12335. exports.TextLayerBuilder = TextLayerBuilder;
  12336. function _finishRendering2() {
  12337. this.renderingDone = true;
  12338. const endOfContent = document.createElement("div");
  12339. endOfContent.className = "endOfContent";
  12340. this.textLayerDiv.append(endOfContent);
  12341. this.eventBus.dispatch("textlayerrendered", {
  12342. source: this,
  12343. pageNumber: this.pageNumber,
  12344. numTextDivs: this.textDivs.length
  12345. });
  12346. }
  12347. function _bindMouse2() {
  12348. const div = this.textLayerDiv;
  12349. div.addEventListener("mousedown", evt => {
  12350. const end = div.querySelector(".endOfContent");
  12351. if (!end) {
  12352. return;
  12353. }
  12354. let adjustTop = evt.target !== div;
  12355. adjustTop && (adjustTop = getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none");
  12356. if (adjustTop) {
  12357. const divBounds = div.getBoundingClientRect();
  12358. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  12359. end.style.top = (r * 100).toFixed(2) + "%";
  12360. }
  12361. end.classList.add("active");
  12362. });
  12363. div.addEventListener("mouseup", () => {
  12364. const end = div.querySelector(".endOfContent");
  12365. if (!end) {
  12366. return;
  12367. }
  12368. end.style.top = "";
  12369. end.classList.remove("active");
  12370. });
  12371. }
  12372. /***/ }),
  12373. /* 38 */
  12374. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12375. Object.defineProperty(exports, "__esModule", ({
  12376. value: true
  12377. }));
  12378. exports.XfaLayerBuilder = void 0;
  12379. var _pdfjsLib = __webpack_require__(5);
  12380. class XfaLayerBuilder {
  12381. constructor(_ref) {
  12382. let {
  12383. pageDiv,
  12384. pdfPage,
  12385. annotationStorage = null,
  12386. linkService,
  12387. xfaHtml = null
  12388. } = _ref;
  12389. this.pageDiv = pageDiv;
  12390. this.pdfPage = pdfPage;
  12391. this.annotationStorage = annotationStorage;
  12392. this.linkService = linkService;
  12393. this.xfaHtml = xfaHtml;
  12394. this.div = null;
  12395. this._cancelled = false;
  12396. }
  12397. render(viewport) {
  12398. let intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "display";
  12399. if (intent === "print") {
  12400. const parameters = {
  12401. viewport: viewport.clone({
  12402. dontFlip: true
  12403. }),
  12404. div: this.div,
  12405. xfaHtml: this.xfaHtml,
  12406. annotationStorage: this.annotationStorage,
  12407. linkService: this.linkService,
  12408. intent
  12409. };
  12410. const div = document.createElement("div");
  12411. this.pageDiv.append(div);
  12412. parameters.div = div;
  12413. const result = _pdfjsLib.XfaLayer.render(parameters);
  12414. return Promise.resolve(result);
  12415. }
  12416. return this.pdfPage.getXfa().then(xfaHtml => {
  12417. if (this._cancelled || !xfaHtml) {
  12418. return {
  12419. textDivs: []
  12420. };
  12421. }
  12422. const parameters = {
  12423. viewport: viewport.clone({
  12424. dontFlip: true
  12425. }),
  12426. div: this.div,
  12427. xfaHtml,
  12428. annotationStorage: this.annotationStorage,
  12429. linkService: this.linkService,
  12430. intent
  12431. };
  12432. if (this.div) {
  12433. return _pdfjsLib.XfaLayer.update(parameters);
  12434. }
  12435. this.div = document.createElement("div");
  12436. this.pageDiv.append(this.div);
  12437. parameters.div = this.div;
  12438. return _pdfjsLib.XfaLayer.render(parameters);
  12439. }).catch(error => {
  12440. console.error(error);
  12441. });
  12442. }
  12443. cancel() {
  12444. this._cancelled = true;
  12445. }
  12446. hide() {
  12447. if (!this.div) {
  12448. return;
  12449. }
  12450. this.div.hidden = true;
  12451. }
  12452. }
  12453. exports.XfaLayerBuilder = XfaLayerBuilder;
  12454. /***/ }),
  12455. /* 39 */
  12456. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12457. Object.defineProperty(exports, "__esModule", ({
  12458. value: true
  12459. }));
  12460. exports.SecondaryToolbar = void 0;
  12461. var _ui_utils = __webpack_require__(1);
  12462. var _pdf_cursor_tools = __webpack_require__(7);
  12463. var _pdf_viewer = __webpack_require__(29);
  12464. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  12465. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  12466. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  12467. var _updateUIState = /*#__PURE__*/new WeakSet();
  12468. var _bindClickListeners = /*#__PURE__*/new WeakSet();
  12469. var _bindCursorToolsListener = /*#__PURE__*/new WeakSet();
  12470. var _bindScrollModeListener = /*#__PURE__*/new WeakSet();
  12471. var _bindSpreadModeListener = /*#__PURE__*/new WeakSet();
  12472. class SecondaryToolbar {
  12473. constructor(options, eventBus, externalServices) {
  12474. _classPrivateMethodInitSpec(this, _bindSpreadModeListener);
  12475. _classPrivateMethodInitSpec(this, _bindScrollModeListener);
  12476. _classPrivateMethodInitSpec(this, _bindCursorToolsListener);
  12477. _classPrivateMethodInitSpec(this, _bindClickListeners);
  12478. _classPrivateMethodInitSpec(this, _updateUIState);
  12479. this.toolbar = options.toolbar;
  12480. this.toggleButton = options.toggleButton;
  12481. this.buttons = [{
  12482. element: options.presentationModeButton,
  12483. eventName: "presentationmode",
  12484. close: true
  12485. }, {
  12486. element: options.printButton,
  12487. eventName: "print",
  12488. close: true
  12489. }, {
  12490. element: options.downloadButton,
  12491. eventName: "download",
  12492. close: true
  12493. }, {
  12494. element: options.viewBookmarkButton,
  12495. eventName: null,
  12496. close: true
  12497. }, {
  12498. element: options.firstPageButton,
  12499. eventName: "firstpage",
  12500. close: true
  12501. }, {
  12502. element: options.lastPageButton,
  12503. eventName: "lastpage",
  12504. close: true
  12505. }, {
  12506. element: options.pageRotateCwButton,
  12507. eventName: "rotatecw",
  12508. close: false
  12509. }, {
  12510. element: options.pageRotateCcwButton,
  12511. eventName: "rotateccw",
  12512. close: false
  12513. }, {
  12514. element: options.cursorSelectToolButton,
  12515. eventName: "switchcursortool",
  12516. eventDetails: {
  12517. tool: _pdf_cursor_tools.CursorTool.SELECT
  12518. },
  12519. close: true
  12520. }, {
  12521. element: options.cursorHandToolButton,
  12522. eventName: "switchcursortool",
  12523. eventDetails: {
  12524. tool: _pdf_cursor_tools.CursorTool.HAND
  12525. },
  12526. close: true
  12527. }, {
  12528. element: options.scrollPageButton,
  12529. eventName: "switchscrollmode",
  12530. eventDetails: {
  12531. mode: _ui_utils.ScrollMode.PAGE
  12532. },
  12533. close: true
  12534. }, {
  12535. element: options.scrollVerticalButton,
  12536. eventName: "switchscrollmode",
  12537. eventDetails: {
  12538. mode: _ui_utils.ScrollMode.VERTICAL
  12539. },
  12540. close: true
  12541. }, {
  12542. element: options.scrollHorizontalButton,
  12543. eventName: "switchscrollmode",
  12544. eventDetails: {
  12545. mode: _ui_utils.ScrollMode.HORIZONTAL
  12546. },
  12547. close: true
  12548. }, {
  12549. element: options.scrollWrappedButton,
  12550. eventName: "switchscrollmode",
  12551. eventDetails: {
  12552. mode: _ui_utils.ScrollMode.WRAPPED
  12553. },
  12554. close: true
  12555. }, {
  12556. element: options.spreadNoneButton,
  12557. eventName: "switchspreadmode",
  12558. eventDetails: {
  12559. mode: _ui_utils.SpreadMode.NONE
  12560. },
  12561. close: true
  12562. }, {
  12563. element: options.spreadOddButton,
  12564. eventName: "switchspreadmode",
  12565. eventDetails: {
  12566. mode: _ui_utils.SpreadMode.ODD
  12567. },
  12568. close: true
  12569. }, {
  12570. element: options.spreadEvenButton,
  12571. eventName: "switchspreadmode",
  12572. eventDetails: {
  12573. mode: _ui_utils.SpreadMode.EVEN
  12574. },
  12575. close: true
  12576. }, {
  12577. element: options.documentPropertiesButton,
  12578. eventName: "documentproperties",
  12579. close: true
  12580. }];
  12581. this.buttons.push({
  12582. element: options.openFileButton,
  12583. eventName: "openfile",
  12584. close: true
  12585. });
  12586. this.items = {
  12587. firstPage: options.firstPageButton,
  12588. lastPage: options.lastPageButton,
  12589. pageRotateCw: options.pageRotateCwButton,
  12590. pageRotateCcw: options.pageRotateCcwButton
  12591. };
  12592. this.eventBus = eventBus;
  12593. this.externalServices = externalServices;
  12594. this.opened = false;
  12595. _classPrivateMethodGet(this, _bindClickListeners, _bindClickListeners2).call(this);
  12596. _classPrivateMethodGet(this, _bindCursorToolsListener, _bindCursorToolsListener2).call(this, options);
  12597. _classPrivateMethodGet(this, _bindScrollModeListener, _bindScrollModeListener2).call(this, options);
  12598. _classPrivateMethodGet(this, _bindSpreadModeListener, _bindSpreadModeListener2).call(this, options);
  12599. this.reset();
  12600. }
  12601. get isOpen() {
  12602. return this.opened;
  12603. }
  12604. setPageNumber(pageNumber) {
  12605. this.pageNumber = pageNumber;
  12606. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this);
  12607. }
  12608. setPagesCount(pagesCount) {
  12609. this.pagesCount = pagesCount;
  12610. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this);
  12611. }
  12612. reset() {
  12613. this.pageNumber = 0;
  12614. this.pagesCount = 0;
  12615. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this);
  12616. this.eventBus.dispatch("secondarytoolbarreset", {
  12617. source: this
  12618. });
  12619. }
  12620. open() {
  12621. if (this.opened) {
  12622. return;
  12623. }
  12624. this.opened = true;
  12625. this.toggleButton.classList.add("toggled");
  12626. this.toggleButton.setAttribute("aria-expanded", "true");
  12627. this.toolbar.classList.remove("hidden");
  12628. }
  12629. close() {
  12630. if (!this.opened) {
  12631. return;
  12632. }
  12633. this.opened = false;
  12634. this.toolbar.classList.add("hidden");
  12635. this.toggleButton.classList.remove("toggled");
  12636. this.toggleButton.setAttribute("aria-expanded", "false");
  12637. }
  12638. toggle() {
  12639. if (this.opened) {
  12640. this.close();
  12641. } else {
  12642. this.open();
  12643. }
  12644. }
  12645. }
  12646. exports.SecondaryToolbar = SecondaryToolbar;
  12647. function _updateUIState2() {
  12648. this.items.firstPage.disabled = this.pageNumber <= 1;
  12649. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  12650. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  12651. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  12652. }
  12653. function _bindClickListeners2() {
  12654. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  12655. for (const {
  12656. element,
  12657. eventName,
  12658. close,
  12659. eventDetails
  12660. } of this.buttons) {
  12661. element.addEventListener("click", evt => {
  12662. if (eventName !== null) {
  12663. const details = {
  12664. source: this
  12665. };
  12666. for (const property in eventDetails) {
  12667. details[property] = eventDetails[property];
  12668. }
  12669. this.eventBus.dispatch(eventName, details);
  12670. }
  12671. if (close) {
  12672. this.close();
  12673. }
  12674. this.externalServices.reportTelemetry({
  12675. type: "buttons",
  12676. data: {
  12677. id: element.id
  12678. }
  12679. });
  12680. });
  12681. }
  12682. }
  12683. function _bindCursorToolsListener2(_ref) {
  12684. let {
  12685. cursorSelectToolButton,
  12686. cursorHandToolButton
  12687. } = _ref;
  12688. this.eventBus._on("cursortoolchanged", function (_ref2) {
  12689. let {
  12690. tool
  12691. } = _ref2;
  12692. const isSelect = tool === _pdf_cursor_tools.CursorTool.SELECT,
  12693. isHand = tool === _pdf_cursor_tools.CursorTool.HAND;
  12694. cursorSelectToolButton.classList.toggle("toggled", isSelect);
  12695. cursorHandToolButton.classList.toggle("toggled", isHand);
  12696. cursorSelectToolButton.setAttribute("aria-checked", isSelect);
  12697. cursorHandToolButton.setAttribute("aria-checked", isHand);
  12698. });
  12699. }
  12700. function _bindScrollModeListener2(_ref3) {
  12701. let {
  12702. scrollPageButton,
  12703. scrollVerticalButton,
  12704. scrollHorizontalButton,
  12705. scrollWrappedButton,
  12706. spreadNoneButton,
  12707. spreadOddButton,
  12708. spreadEvenButton
  12709. } = _ref3;
  12710. const scrollModeChanged = _ref4 => {
  12711. let {
  12712. mode
  12713. } = _ref4;
  12714. const isPage = mode === _ui_utils.ScrollMode.PAGE,
  12715. isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
  12716. isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
  12717. isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
  12718. scrollPageButton.classList.toggle("toggled", isPage);
  12719. scrollVerticalButton.classList.toggle("toggled", isVertical);
  12720. scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
  12721. scrollWrappedButton.classList.toggle("toggled", isWrapped);
  12722. scrollPageButton.setAttribute("aria-checked", isPage);
  12723. scrollVerticalButton.setAttribute("aria-checked", isVertical);
  12724. scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
  12725. scrollWrappedButton.setAttribute("aria-checked", isWrapped);
  12726. const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  12727. scrollPageButton.disabled = forceScrollModePage;
  12728. scrollVerticalButton.disabled = forceScrollModePage;
  12729. scrollHorizontalButton.disabled = forceScrollModePage;
  12730. scrollWrappedButton.disabled = forceScrollModePage;
  12731. spreadNoneButton.disabled = isHorizontal;
  12732. spreadOddButton.disabled = isHorizontal;
  12733. spreadEvenButton.disabled = isHorizontal;
  12734. };
  12735. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  12736. this.eventBus._on("secondarytoolbarreset", evt => {
  12737. if (evt.source === this) {
  12738. scrollModeChanged({
  12739. mode: _ui_utils.ScrollMode.VERTICAL
  12740. });
  12741. }
  12742. });
  12743. }
  12744. function _bindSpreadModeListener2(_ref5) {
  12745. let {
  12746. spreadNoneButton,
  12747. spreadOddButton,
  12748. spreadEvenButton
  12749. } = _ref5;
  12750. function spreadModeChanged(_ref6) {
  12751. let {
  12752. mode
  12753. } = _ref6;
  12754. const isNone = mode === _ui_utils.SpreadMode.NONE,
  12755. isOdd = mode === _ui_utils.SpreadMode.ODD,
  12756. isEven = mode === _ui_utils.SpreadMode.EVEN;
  12757. spreadNoneButton.classList.toggle("toggled", isNone);
  12758. spreadOddButton.classList.toggle("toggled", isOdd);
  12759. spreadEvenButton.classList.toggle("toggled", isEven);
  12760. spreadNoneButton.setAttribute("aria-checked", isNone);
  12761. spreadOddButton.setAttribute("aria-checked", isOdd);
  12762. spreadEvenButton.setAttribute("aria-checked", isEven);
  12763. }
  12764. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  12765. this.eventBus._on("secondarytoolbarreset", evt => {
  12766. if (evt.source === this) {
  12767. spreadModeChanged({
  12768. mode: _ui_utils.SpreadMode.NONE
  12769. });
  12770. }
  12771. });
  12772. }
  12773. /***/ }),
  12774. /* 40 */
  12775. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12776. Object.defineProperty(exports, "__esModule", ({
  12777. value: true
  12778. }));
  12779. exports.Toolbar = void 0;
  12780. var _ui_utils = __webpack_require__(1);
  12781. var _pdfjsLib = __webpack_require__(5);
  12782. function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
  12783. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  12784. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  12785. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  12786. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  12787. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  12788. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  12789. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  12790. function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
  12791. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  12792. var _wasLocalized = /*#__PURE__*/new WeakMap();
  12793. var _bindListeners = /*#__PURE__*/new WeakSet();
  12794. var _bindEditorToolsListener = /*#__PURE__*/new WeakSet();
  12795. var _updateUIState = /*#__PURE__*/new WeakSet();
  12796. var _adjustScaleWidth = /*#__PURE__*/new WeakSet();
  12797. class Toolbar {
  12798. constructor(_options, eventBus, _l10n) {
  12799. _classPrivateMethodInitSpec(this, _adjustScaleWidth);
  12800. _classPrivateMethodInitSpec(this, _updateUIState);
  12801. _classPrivateMethodInitSpec(this, _bindEditorToolsListener);
  12802. _classPrivateMethodInitSpec(this, _bindListeners);
  12803. _classPrivateFieldInitSpec(this, _wasLocalized, {
  12804. writable: true,
  12805. value: false
  12806. });
  12807. this.toolbar = _options.container;
  12808. this.eventBus = eventBus;
  12809. this.l10n = _l10n;
  12810. this.buttons = [{
  12811. element: _options.previous,
  12812. eventName: "previouspage"
  12813. }, {
  12814. element: _options.next,
  12815. eventName: "nextpage"
  12816. }, {
  12817. element: _options.zoomIn,
  12818. eventName: "zoomin"
  12819. }, {
  12820. element: _options.zoomOut,
  12821. eventName: "zoomout"
  12822. }, {
  12823. element: _options.print,
  12824. eventName: "print"
  12825. }, {
  12826. element: _options.download,
  12827. eventName: "download"
  12828. }, {
  12829. element: _options.editorFreeTextButton,
  12830. eventName: "switchannotationeditormode",
  12831. eventDetails: {
  12832. get mode() {
  12833. const {
  12834. classList
  12835. } = _options.editorFreeTextButton;
  12836. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  12837. }
  12838. }
  12839. }, {
  12840. element: _options.editorInkButton,
  12841. eventName: "switchannotationeditormode",
  12842. eventDetails: {
  12843. get mode() {
  12844. const {
  12845. classList
  12846. } = _options.editorInkButton;
  12847. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  12848. }
  12849. }
  12850. }];
  12851. this.buttons.push({
  12852. element: _options.openFile,
  12853. eventName: "openfile"
  12854. });
  12855. this.items = {
  12856. numPages: _options.numPages,
  12857. pageNumber: _options.pageNumber,
  12858. scaleSelect: _options.scaleSelect,
  12859. customScaleOption: _options.customScaleOption,
  12860. previous: _options.previous,
  12861. next: _options.next,
  12862. zoomIn: _options.zoomIn,
  12863. zoomOut: _options.zoomOut
  12864. };
  12865. _classPrivateMethodGet(this, _bindListeners, _bindListeners2).call(this, _options);
  12866. this.reset();
  12867. }
  12868. setPageNumber(pageNumber, pageLabel) {
  12869. this.pageNumber = pageNumber;
  12870. this.pageLabel = pageLabel;
  12871. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this, false);
  12872. }
  12873. setPagesCount(pagesCount, hasPageLabels) {
  12874. this.pagesCount = pagesCount;
  12875. this.hasPageLabels = hasPageLabels;
  12876. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this, true);
  12877. }
  12878. setPageScale(pageScaleValue, pageScale) {
  12879. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  12880. this.pageScale = pageScale;
  12881. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this, false);
  12882. }
  12883. reset() {
  12884. this.pageNumber = 0;
  12885. this.pageLabel = null;
  12886. this.hasPageLabels = false;
  12887. this.pagesCount = 0;
  12888. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  12889. this.pageScale = _ui_utils.DEFAULT_SCALE;
  12890. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this, true);
  12891. this.updateLoadingIndicatorState();
  12892. this.eventBus.dispatch("toolbarreset", {
  12893. source: this
  12894. });
  12895. }
  12896. updateLoadingIndicatorState() {
  12897. let loading = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  12898. const {
  12899. pageNumber
  12900. } = this.items;
  12901. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  12902. }
  12903. }
  12904. exports.Toolbar = Toolbar;
  12905. function _bindListeners2(options) {
  12906. const {
  12907. pageNumber,
  12908. scaleSelect
  12909. } = this.items;
  12910. const self = this;
  12911. for (const {
  12912. element,
  12913. eventName,
  12914. eventDetails
  12915. } of this.buttons) {
  12916. element.addEventListener("click", evt => {
  12917. if (eventName !== null) {
  12918. const details = {
  12919. source: this
  12920. };
  12921. if (eventDetails) {
  12922. for (const property in eventDetails) {
  12923. details[property] = eventDetails[property];
  12924. }
  12925. }
  12926. this.eventBus.dispatch(eventName, details);
  12927. }
  12928. });
  12929. }
  12930. pageNumber.addEventListener("click", function () {
  12931. this.select();
  12932. });
  12933. pageNumber.addEventListener("change", function () {
  12934. self.eventBus.dispatch("pagenumberchanged", {
  12935. source: self,
  12936. value: this.value
  12937. });
  12938. });
  12939. scaleSelect.addEventListener("change", function () {
  12940. if (this.value === "custom") {
  12941. return;
  12942. }
  12943. self.eventBus.dispatch("scalechanged", {
  12944. source: self,
  12945. value: this.value
  12946. });
  12947. });
  12948. scaleSelect.addEventListener("click", function (evt) {
  12949. const target = evt.target;
  12950. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  12951. this.blur();
  12952. }
  12953. });
  12954. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  12955. this.eventBus._on("localized", () => {
  12956. _classPrivateFieldSet(this, _wasLocalized, true);
  12957. _classPrivateMethodGet(this, _adjustScaleWidth, _adjustScaleWidth2).call(this);
  12958. _classPrivateMethodGet(this, _updateUIState, _updateUIState2).call(this, true);
  12959. });
  12960. _classPrivateMethodGet(this, _bindEditorToolsListener, _bindEditorToolsListener2).call(this, options);
  12961. }
  12962. function _bindEditorToolsListener2(_ref) {
  12963. let {
  12964. editorFreeTextButton,
  12965. editorFreeTextParamsToolbar,
  12966. editorInkButton,
  12967. editorInkParamsToolbar
  12968. } = _ref;
  12969. const editorModeChanged = function (evt) {
  12970. let disableButtons = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  12971. const editorButtons = [{
  12972. mode: _pdfjsLib.AnnotationEditorType.FREETEXT,
  12973. button: editorFreeTextButton,
  12974. toolbar: editorFreeTextParamsToolbar
  12975. }, {
  12976. mode: _pdfjsLib.AnnotationEditorType.INK,
  12977. button: editorInkButton,
  12978. toolbar: editorInkParamsToolbar
  12979. }];
  12980. for (const {
  12981. mode,
  12982. button,
  12983. toolbar
  12984. } of editorButtons) {
  12985. const checked = mode === evt.mode;
  12986. button.classList.toggle("toggled", checked);
  12987. button.setAttribute("aria-checked", checked);
  12988. button.disabled = disableButtons;
  12989. toolbar === null || toolbar === void 0 ? void 0 : toolbar.classList.toggle("hidden", !checked);
  12990. }
  12991. };
  12992. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  12993. this.eventBus._on("toolbarreset", evt => {
  12994. if (evt.source === this) {
  12995. editorModeChanged({
  12996. mode: _pdfjsLib.AnnotationEditorType.NONE
  12997. }, true);
  12998. }
  12999. });
  13000. }
  13001. function _updateUIState2() {
  13002. let resetNumPages = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  13003. if (!_classPrivateFieldGet(this, _wasLocalized)) {
  13004. return;
  13005. }
  13006. const {
  13007. pageNumber,
  13008. pagesCount,
  13009. pageScaleValue,
  13010. pageScale,
  13011. items
  13012. } = this;
  13013. if (resetNumPages) {
  13014. if (this.hasPageLabels) {
  13015. items.pageNumber.type = "text";
  13016. } else {
  13017. items.pageNumber.type = "number";
  13018. this.l10n.get("of_pages", {
  13019. pagesCount
  13020. }).then(msg => {
  13021. items.numPages.textContent = msg;
  13022. });
  13023. }
  13024. items.pageNumber.max = pagesCount;
  13025. }
  13026. if (this.hasPageLabels) {
  13027. items.pageNumber.value = this.pageLabel;
  13028. this.l10n.get("page_of_pages", {
  13029. pageNumber,
  13030. pagesCount
  13031. }).then(msg => {
  13032. items.numPages.textContent = msg;
  13033. });
  13034. } else {
  13035. items.pageNumber.value = pageNumber;
  13036. }
  13037. items.previous.disabled = pageNumber <= 1;
  13038. items.next.disabled = pageNumber >= pagesCount;
  13039. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  13040. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  13041. this.l10n.get("page_scale_percent", {
  13042. scale: Math.round(pageScale * 10000) / 100
  13043. }).then(msg => {
  13044. let predefinedValueFound = false;
  13045. for (const option of items.scaleSelect.options) {
  13046. if (option.value !== pageScaleValue) {
  13047. option.selected = false;
  13048. continue;
  13049. }
  13050. option.selected = true;
  13051. predefinedValueFound = true;
  13052. }
  13053. if (!predefinedValueFound) {
  13054. items.customScaleOption.textContent = msg;
  13055. items.customScaleOption.selected = true;
  13056. }
  13057. });
  13058. }
  13059. async function _adjustScaleWidth2() {
  13060. const {
  13061. items,
  13062. l10n
  13063. } = this;
  13064. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  13065. await _ui_utils.animationStarted;
  13066. const style = getComputedStyle(items.scaleSelect);
  13067. const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width"));
  13068. const canvas = document.createElement("canvas");
  13069. const ctx = canvas.getContext("2d", {
  13070. alpha: false
  13071. });
  13072. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  13073. let maxWidth = 0;
  13074. for (const predefinedValue of await predefinedValuesPromise) {
  13075. const {
  13076. width
  13077. } = ctx.measureText(predefinedValue);
  13078. if (width > maxWidth) {
  13079. maxWidth = width;
  13080. }
  13081. }
  13082. maxWidth += 0.3 * scaleSelectWidth;
  13083. if (maxWidth > scaleSelectWidth) {
  13084. _ui_utils.docStyle.setProperty("--scale-select-width", `${maxWidth}px`);
  13085. }
  13086. canvas.width = 0;
  13087. canvas.height = 0;
  13088. }
  13089. /***/ }),
  13090. /* 41 */
  13091. /***/ ((__unused_webpack_module, exports) => {
  13092. Object.defineProperty(exports, "__esModule", ({
  13093. value: true
  13094. }));
  13095. exports.ViewHistory = void 0;
  13096. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  13097. class ViewHistory {
  13098. constructor(fingerprint) {
  13099. let cacheSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_VIEW_HISTORY_CACHE_SIZE;
  13100. this.fingerprint = fingerprint;
  13101. this.cacheSize = cacheSize;
  13102. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  13103. const database = JSON.parse(databaseStr || "{}");
  13104. let index = -1;
  13105. if (!Array.isArray(database.files)) {
  13106. database.files = [];
  13107. } else {
  13108. while (database.files.length >= this.cacheSize) {
  13109. database.files.shift();
  13110. }
  13111. for (let i = 0, ii = database.files.length; i < ii; i++) {
  13112. const branch = database.files[i];
  13113. if (branch.fingerprint === this.fingerprint) {
  13114. index = i;
  13115. break;
  13116. }
  13117. }
  13118. }
  13119. if (index === -1) {
  13120. index = database.files.push({
  13121. fingerprint: this.fingerprint
  13122. }) - 1;
  13123. }
  13124. this.file = database.files[index];
  13125. this.database = database;
  13126. });
  13127. }
  13128. async _writeToStorage() {
  13129. const databaseStr = JSON.stringify(this.database);
  13130. localStorage.setItem("pdfjs.history", databaseStr);
  13131. }
  13132. async _readFromStorage() {
  13133. return localStorage.getItem("pdfjs.history");
  13134. }
  13135. async set(name, val) {
  13136. await this._initializedPromise;
  13137. this.file[name] = val;
  13138. return this._writeToStorage();
  13139. }
  13140. async setMultiple(properties) {
  13141. await this._initializedPromise;
  13142. for (const name in properties) {
  13143. this.file[name] = properties[name];
  13144. }
  13145. return this._writeToStorage();
  13146. }
  13147. async get(name, defaultValue) {
  13148. await this._initializedPromise;
  13149. const val = this.file[name];
  13150. return val !== undefined ? val : defaultValue;
  13151. }
  13152. async getMultiple(properties) {
  13153. await this._initializedPromise;
  13154. const values = Object.create(null);
  13155. for (const name in properties) {
  13156. const val = this.file[name];
  13157. values[name] = val !== undefined ? val : properties[name];
  13158. }
  13159. return values;
  13160. }
  13161. }
  13162. exports.ViewHistory = ViewHistory;
  13163. /***/ }),
  13164. /* 42 */
  13165. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13166. Object.defineProperty(exports, "__esModule", ({
  13167. value: true
  13168. }));
  13169. exports.GenericCom = void 0;
  13170. var _app = __webpack_require__(4);
  13171. var _preferences = __webpack_require__(43);
  13172. var _download_manager = __webpack_require__(44);
  13173. var _genericl10n = __webpack_require__(45);
  13174. var _generic_scripting = __webpack_require__(47);
  13175. ;
  13176. const GenericCom = {};
  13177. exports.GenericCom = GenericCom;
  13178. class GenericPreferences extends _preferences.BasePreferences {
  13179. async _writeToStorage(prefObj) {
  13180. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  13181. }
  13182. async _readFromStorage(prefObj) {
  13183. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  13184. }
  13185. }
  13186. class GenericExternalServices extends _app.DefaultExternalServices {
  13187. static createDownloadManager(options) {
  13188. return new _download_manager.DownloadManager();
  13189. }
  13190. static createPreferences() {
  13191. return new GenericPreferences();
  13192. }
  13193. static createL10n(_ref) {
  13194. let {
  13195. locale = "en-US"
  13196. } = _ref;
  13197. return new _genericl10n.GenericL10n(locale);
  13198. }
  13199. static createScripting(_ref2) {
  13200. let {
  13201. sandboxBundleSrc
  13202. } = _ref2;
  13203. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  13204. }
  13205. }
  13206. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  13207. /***/ }),
  13208. /* 43 */
  13209. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13210. Object.defineProperty(exports, "__esModule", ({
  13211. value: true
  13212. }));
  13213. exports.BasePreferences = void 0;
  13214. var _app_options = __webpack_require__(2);
  13215. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  13216. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  13217. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  13218. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  13219. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  13220. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  13221. function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
  13222. var _defaults = /*#__PURE__*/new WeakMap();
  13223. var _prefs = /*#__PURE__*/new WeakMap();
  13224. var _initializedPromise = /*#__PURE__*/new WeakMap();
  13225. class BasePreferences {
  13226. constructor() {
  13227. _classPrivateFieldInitSpec(this, _defaults, {
  13228. writable: true,
  13229. value: Object.freeze({
  13230. "annotationEditorMode": 0,
  13231. "annotationMode": 2,
  13232. "cursorToolOnLoad": 0,
  13233. "defaultZoomValue": "",
  13234. "disablePageLabels": false,
  13235. "enablePermissions": false,
  13236. "enablePrintAutoRotate": true,
  13237. "enableScripting": true,
  13238. "externalLinkTarget": 0,
  13239. "historyUpdateUrl": false,
  13240. "ignoreDestinationZoom": false,
  13241. "forcePageColors": false,
  13242. "pageColorsBackground": "Canvas",
  13243. "pageColorsForeground": "CanvasText",
  13244. "pdfBugEnabled": false,
  13245. "sidebarViewOnLoad": -1,
  13246. "scrollModeOnLoad": -1,
  13247. "spreadModeOnLoad": -1,
  13248. "textLayerMode": 1,
  13249. "useOnlyCssZoom": false,
  13250. "viewerCssTheme": 0,
  13251. "viewOnLoad": 0,
  13252. "disableAutoFetch": false,
  13253. "disableFontFace": false,
  13254. "disableRange": false,
  13255. "disableStream": false,
  13256. "enableXfa": true,
  13257. "renderer": "canvas"
  13258. })
  13259. });
  13260. _classPrivateFieldInitSpec(this, _prefs, {
  13261. writable: true,
  13262. value: Object.create(null)
  13263. });
  13264. _classPrivateFieldInitSpec(this, _initializedPromise, {
  13265. writable: true,
  13266. value: null
  13267. });
  13268. if (this.constructor === BasePreferences) {
  13269. throw new Error("Cannot initialize BasePreferences.");
  13270. }
  13271. _classPrivateFieldSet(this, _initializedPromise, this._readFromStorage(_classPrivateFieldGet(this, _defaults)).then(prefs => {
  13272. for (const name in _classPrivateFieldGet(this, _defaults)) {
  13273. const prefValue = prefs === null || prefs === void 0 ? void 0 : prefs[name];
  13274. if (typeof prefValue === typeof _classPrivateFieldGet(this, _defaults)[name]) {
  13275. _classPrivateFieldGet(this, _prefs)[name] = prefValue;
  13276. }
  13277. }
  13278. }));
  13279. }
  13280. async _writeToStorage(prefObj) {
  13281. throw new Error("Not implemented: _writeToStorage");
  13282. }
  13283. async _readFromStorage(prefObj) {
  13284. throw new Error("Not implemented: _readFromStorage");
  13285. }
  13286. async reset() {
  13287. await _classPrivateFieldGet(this, _initializedPromise);
  13288. const prefs = _classPrivateFieldGet(this, _prefs);
  13289. _classPrivateFieldSet(this, _prefs, Object.create(null));
  13290. return this._writeToStorage(_classPrivateFieldGet(this, _defaults)).catch(reason => {
  13291. _classPrivateFieldSet(this, _prefs, prefs);
  13292. throw reason;
  13293. });
  13294. }
  13295. async set(name, value) {
  13296. await _classPrivateFieldGet(this, _initializedPromise);
  13297. const defaultValue = _classPrivateFieldGet(this, _defaults)[name],
  13298. prefs = _classPrivateFieldGet(this, _prefs);
  13299. if (defaultValue === undefined) {
  13300. throw new Error(`Set preference: "${name}" is undefined.`);
  13301. } else if (value === undefined) {
  13302. throw new Error("Set preference: no value is specified.");
  13303. }
  13304. const valueType = typeof value,
  13305. defaultType = typeof defaultValue;
  13306. if (valueType !== defaultType) {
  13307. if (valueType === "number" && defaultType === "string") {
  13308. value = value.toString();
  13309. } else {
  13310. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  13311. }
  13312. } else {
  13313. if (valueType === "number" && !Number.isInteger(value)) {
  13314. throw new Error(`Set preference: "${value}" must be an integer.`);
  13315. }
  13316. }
  13317. _classPrivateFieldGet(this, _prefs)[name] = value;
  13318. return this._writeToStorage(_classPrivateFieldGet(this, _prefs)).catch(reason => {
  13319. _classPrivateFieldSet(this, _prefs, prefs);
  13320. throw reason;
  13321. });
  13322. }
  13323. async get(name) {
  13324. await _classPrivateFieldGet(this, _initializedPromise);
  13325. const defaultValue = _classPrivateFieldGet(this, _defaults)[name];
  13326. if (defaultValue === undefined) {
  13327. throw new Error(`Get preference: "${name}" is undefined.`);
  13328. }
  13329. return _classPrivateFieldGet(this, _prefs)[name] ?? defaultValue;
  13330. }
  13331. async getAll() {
  13332. await _classPrivateFieldGet(this, _initializedPromise);
  13333. const obj = Object.create(null);
  13334. for (const name in _classPrivateFieldGet(this, _defaults)) {
  13335. obj[name] = _classPrivateFieldGet(this, _prefs)[name] ?? _classPrivateFieldGet(this, _defaults)[name];
  13336. }
  13337. return obj;
  13338. }
  13339. }
  13340. exports.BasePreferences = BasePreferences;
  13341. /***/ }),
  13342. /* 44 */
  13343. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13344. Object.defineProperty(exports, "__esModule", ({
  13345. value: true
  13346. }));
  13347. exports.DownloadManager = void 0;
  13348. var _pdfjsLib = __webpack_require__(5);
  13349. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  13350. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  13351. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  13352. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  13353. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  13354. ;
  13355. function download(blobUrl, filename) {
  13356. const a = document.createElement("a");
  13357. if (!a.click) {
  13358. throw new Error('DownloadManager: "a.click()" is not supported.');
  13359. }
  13360. a.href = blobUrl;
  13361. a.target = "_parent";
  13362. if ("download" in a) {
  13363. a.download = filename;
  13364. }
  13365. (document.body || document.documentElement).append(a);
  13366. a.click();
  13367. a.remove();
  13368. }
  13369. var _openBlobUrls = /*#__PURE__*/new WeakMap();
  13370. class DownloadManager {
  13371. constructor() {
  13372. _classPrivateFieldInitSpec(this, _openBlobUrls, {
  13373. writable: true,
  13374. value: new WeakMap()
  13375. });
  13376. }
  13377. downloadUrl(url, filename) {
  13378. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  13379. console.error(`downloadUrl - not a valid URL: ${url}`);
  13380. return;
  13381. }
  13382. download(url + "#pdfjs.action=download", filename);
  13383. }
  13384. downloadData(data, filename, contentType) {
  13385. const blobUrl = URL.createObjectURL(new Blob([data], {
  13386. type: contentType
  13387. }));
  13388. download(blobUrl, filename);
  13389. }
  13390. openOrDownloadData(element, data, filename) {
  13391. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  13392. const contentType = isPdfData ? "application/pdf" : "";
  13393. if (isPdfData) {
  13394. let blobUrl = _classPrivateFieldGet(this, _openBlobUrls).get(element);
  13395. if (!blobUrl) {
  13396. blobUrl = URL.createObjectURL(new Blob([data], {
  13397. type: contentType
  13398. }));
  13399. _classPrivateFieldGet(this, _openBlobUrls).set(element, blobUrl);
  13400. }
  13401. let viewerUrl;
  13402. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  13403. try {
  13404. window.open(viewerUrl);
  13405. return true;
  13406. } catch (ex) {
  13407. console.error(`openOrDownloadData: ${ex}`);
  13408. URL.revokeObjectURL(blobUrl);
  13409. _classPrivateFieldGet(this, _openBlobUrls).delete(element);
  13410. }
  13411. }
  13412. this.downloadData(data, filename, contentType);
  13413. return false;
  13414. }
  13415. download(blob, url, filename) {
  13416. const blobUrl = URL.createObjectURL(blob);
  13417. download(blobUrl, filename);
  13418. }
  13419. }
  13420. exports.DownloadManager = DownloadManager;
  13421. /***/ }),
  13422. /* 45 */
  13423. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13424. Object.defineProperty(exports, "__esModule", ({
  13425. value: true
  13426. }));
  13427. exports.GenericL10n = void 0;
  13428. __webpack_require__(46);
  13429. var _l10n_utils = __webpack_require__(31);
  13430. const webL10n = document.webL10n;
  13431. class GenericL10n {
  13432. constructor(lang) {
  13433. this._lang = lang;
  13434. this._ready = new Promise((resolve, reject) => {
  13435. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  13436. resolve(webL10n);
  13437. });
  13438. });
  13439. }
  13440. async getLanguage() {
  13441. const l10n = await this._ready;
  13442. return l10n.getLanguage();
  13443. }
  13444. async getDirection() {
  13445. const l10n = await this._ready;
  13446. return l10n.getDirection();
  13447. }
  13448. async get(key) {
  13449. let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  13450. let fallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, _l10n_utils.getL10nFallback)(key, args);
  13451. const l10n = await this._ready;
  13452. return l10n.get(key, args, fallback);
  13453. }
  13454. async translate(element) {
  13455. const l10n = await this._ready;
  13456. return l10n.translate(element);
  13457. }
  13458. }
  13459. exports.GenericL10n = GenericL10n;
  13460. /***/ }),
  13461. /* 46 */
  13462. /***/ (() => {
  13463. document.webL10n = function (window, document, undefined) {
  13464. var gL10nData = {};
  13465. var gTextData = '';
  13466. var gTextProp = 'textContent';
  13467. var gLanguage = '';
  13468. var gMacros = {};
  13469. var gReadyState = 'loading';
  13470. var gAsyncResourceLoading = true;
  13471. function getL10nResourceLinks() {
  13472. return document.querySelectorAll('link[type="application/l10n"]');
  13473. }
  13474. function getL10nDictionary() {
  13475. var script = document.querySelector('script[type="application/l10n"]');
  13476. return script ? JSON.parse(script.innerHTML) : null;
  13477. }
  13478. function getTranslatableChildren(element) {
  13479. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  13480. }
  13481. function getL10nAttributes(element) {
  13482. if (!element) return {};
  13483. var l10nId = element.getAttribute('data-l10n-id');
  13484. var l10nArgs = element.getAttribute('data-l10n-args');
  13485. var args = {};
  13486. if (l10nArgs) {
  13487. try {
  13488. args = JSON.parse(l10nArgs);
  13489. } catch (e) {
  13490. console.warn('could not parse arguments for #' + l10nId);
  13491. }
  13492. }
  13493. return {
  13494. id: l10nId,
  13495. args: args
  13496. };
  13497. }
  13498. function xhrLoadText(url, onSuccess, onFailure) {
  13499. onSuccess = onSuccess || function _onSuccess(data) {};
  13500. onFailure = onFailure || function _onFailure() {};
  13501. var xhr = new XMLHttpRequest();
  13502. xhr.open('GET', url, gAsyncResourceLoading);
  13503. if (xhr.overrideMimeType) {
  13504. xhr.overrideMimeType('text/plain; charset=utf-8');
  13505. }
  13506. xhr.onreadystatechange = function () {
  13507. if (xhr.readyState == 4) {
  13508. if (xhr.status == 200 || xhr.status === 0) {
  13509. onSuccess(xhr.responseText);
  13510. } else {
  13511. onFailure();
  13512. }
  13513. }
  13514. };
  13515. xhr.onerror = onFailure;
  13516. xhr.ontimeout = onFailure;
  13517. try {
  13518. xhr.send(null);
  13519. } catch (e) {
  13520. onFailure();
  13521. }
  13522. }
  13523. function parseResource(href, lang, successCallback, failureCallback) {
  13524. var baseURL = href.replace(/[^\/]*$/, '') || './';
  13525. function evalString(text) {
  13526. if (text.lastIndexOf('\\') < 0) return text;
  13527. 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, "'");
  13528. }
  13529. function parseProperties(text, parsedPropertiesCallback) {
  13530. var dictionary = {};
  13531. var reBlank = /^\s*|\s*$/;
  13532. var reComment = /^\s*#|^\s*$/;
  13533. var reSection = /^\s*\[(.*)\]\s*$/;
  13534. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  13535. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  13536. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  13537. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  13538. var currentLang = '*';
  13539. var genericLang = lang.split('-', 1)[0];
  13540. var skipLang = false;
  13541. var match = '';
  13542. function nextEntry() {
  13543. while (true) {
  13544. if (!entries.length) {
  13545. parsedRawLinesCallback();
  13546. return;
  13547. }
  13548. var line = entries.shift();
  13549. if (reComment.test(line)) continue;
  13550. if (extendedSyntax) {
  13551. match = reSection.exec(line);
  13552. if (match) {
  13553. currentLang = match[1].toLowerCase();
  13554. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  13555. continue;
  13556. } else if (skipLang) {
  13557. continue;
  13558. }
  13559. match = reImport.exec(line);
  13560. if (match) {
  13561. loadImport(baseURL + match[1], nextEntry);
  13562. return;
  13563. }
  13564. }
  13565. var tmp = line.match(reSplit);
  13566. if (tmp && tmp.length == 3) {
  13567. dictionary[tmp[1]] = evalString(tmp[2]);
  13568. }
  13569. }
  13570. }
  13571. nextEntry();
  13572. }
  13573. function loadImport(url, callback) {
  13574. xhrLoadText(url, function (content) {
  13575. parseRawLines(content, false, callback);
  13576. }, function () {
  13577. console.warn(url + ' not found.');
  13578. callback();
  13579. });
  13580. }
  13581. parseRawLines(text, true, function () {
  13582. parsedPropertiesCallback(dictionary);
  13583. });
  13584. }
  13585. xhrLoadText(href, function (response) {
  13586. gTextData += response;
  13587. parseProperties(response, function (data) {
  13588. for (var key in data) {
  13589. var id,
  13590. prop,
  13591. index = key.lastIndexOf('.');
  13592. if (index > 0) {
  13593. id = key.substring(0, index);
  13594. prop = key.substring(index + 1);
  13595. } else {
  13596. id = key;
  13597. prop = gTextProp;
  13598. }
  13599. if (!gL10nData[id]) {
  13600. gL10nData[id] = {};
  13601. }
  13602. gL10nData[id][prop] = data[key];
  13603. }
  13604. if (successCallback) {
  13605. successCallback();
  13606. }
  13607. });
  13608. }, failureCallback);
  13609. }
  13610. function loadLocale(lang, callback) {
  13611. if (lang) {
  13612. lang = lang.toLowerCase();
  13613. }
  13614. callback = callback || function _callback() {};
  13615. clear();
  13616. gLanguage = lang;
  13617. var langLinks = getL10nResourceLinks();
  13618. var langCount = langLinks.length;
  13619. if (langCount === 0) {
  13620. var dict = getL10nDictionary();
  13621. if (dict && dict.locales && dict.default_locale) {
  13622. console.log('using the embedded JSON directory, early way out');
  13623. gL10nData = dict.locales[lang];
  13624. if (!gL10nData) {
  13625. var defaultLocale = dict.default_locale.toLowerCase();
  13626. for (var anyCaseLang in dict.locales) {
  13627. anyCaseLang = anyCaseLang.toLowerCase();
  13628. if (anyCaseLang === lang) {
  13629. gL10nData = dict.locales[lang];
  13630. break;
  13631. } else if (anyCaseLang === defaultLocale) {
  13632. gL10nData = dict.locales[defaultLocale];
  13633. }
  13634. }
  13635. }
  13636. callback();
  13637. } else {
  13638. console.log('no resource to load, early way out');
  13639. }
  13640. gReadyState = 'complete';
  13641. return;
  13642. }
  13643. var onResourceLoaded = null;
  13644. var gResourceCount = 0;
  13645. onResourceLoaded = function () {
  13646. gResourceCount++;
  13647. if (gResourceCount >= langCount) {
  13648. callback();
  13649. gReadyState = 'complete';
  13650. }
  13651. };
  13652. function L10nResourceLink(link) {
  13653. var href = link.href;
  13654. this.load = function (lang, callback) {
  13655. parseResource(href, lang, callback, function () {
  13656. console.warn(href + ' not found.');
  13657. console.warn('"' + lang + '" resource not found');
  13658. gLanguage = '';
  13659. callback();
  13660. });
  13661. };
  13662. }
  13663. for (var i = 0; i < langCount; i++) {
  13664. var resource = new L10nResourceLink(langLinks[i]);
  13665. resource.load(lang, onResourceLoaded);
  13666. }
  13667. }
  13668. function clear() {
  13669. gL10nData = {};
  13670. gTextData = '';
  13671. gLanguage = '';
  13672. }
  13673. function getPluralRules(lang) {
  13674. var locales2rules = {
  13675. 'af': 3,
  13676. 'ak': 4,
  13677. 'am': 4,
  13678. 'ar': 1,
  13679. 'asa': 3,
  13680. 'az': 0,
  13681. 'be': 11,
  13682. 'bem': 3,
  13683. 'bez': 3,
  13684. 'bg': 3,
  13685. 'bh': 4,
  13686. 'bm': 0,
  13687. 'bn': 3,
  13688. 'bo': 0,
  13689. 'br': 20,
  13690. 'brx': 3,
  13691. 'bs': 11,
  13692. 'ca': 3,
  13693. 'cgg': 3,
  13694. 'chr': 3,
  13695. 'cs': 12,
  13696. 'cy': 17,
  13697. 'da': 3,
  13698. 'de': 3,
  13699. 'dv': 3,
  13700. 'dz': 0,
  13701. 'ee': 3,
  13702. 'el': 3,
  13703. 'en': 3,
  13704. 'eo': 3,
  13705. 'es': 3,
  13706. 'et': 3,
  13707. 'eu': 3,
  13708. 'fa': 0,
  13709. 'ff': 5,
  13710. 'fi': 3,
  13711. 'fil': 4,
  13712. 'fo': 3,
  13713. 'fr': 5,
  13714. 'fur': 3,
  13715. 'fy': 3,
  13716. 'ga': 8,
  13717. 'gd': 24,
  13718. 'gl': 3,
  13719. 'gsw': 3,
  13720. 'gu': 3,
  13721. 'guw': 4,
  13722. 'gv': 23,
  13723. 'ha': 3,
  13724. 'haw': 3,
  13725. 'he': 2,
  13726. 'hi': 4,
  13727. 'hr': 11,
  13728. 'hu': 0,
  13729. 'id': 0,
  13730. 'ig': 0,
  13731. 'ii': 0,
  13732. 'is': 3,
  13733. 'it': 3,
  13734. 'iu': 7,
  13735. 'ja': 0,
  13736. 'jmc': 3,
  13737. 'jv': 0,
  13738. 'ka': 0,
  13739. 'kab': 5,
  13740. 'kaj': 3,
  13741. 'kcg': 3,
  13742. 'kde': 0,
  13743. 'kea': 0,
  13744. 'kk': 3,
  13745. 'kl': 3,
  13746. 'km': 0,
  13747. 'kn': 0,
  13748. 'ko': 0,
  13749. 'ksb': 3,
  13750. 'ksh': 21,
  13751. 'ku': 3,
  13752. 'kw': 7,
  13753. 'lag': 18,
  13754. 'lb': 3,
  13755. 'lg': 3,
  13756. 'ln': 4,
  13757. 'lo': 0,
  13758. 'lt': 10,
  13759. 'lv': 6,
  13760. 'mas': 3,
  13761. 'mg': 4,
  13762. 'mk': 16,
  13763. 'ml': 3,
  13764. 'mn': 3,
  13765. 'mo': 9,
  13766. 'mr': 3,
  13767. 'ms': 0,
  13768. 'mt': 15,
  13769. 'my': 0,
  13770. 'nah': 3,
  13771. 'naq': 7,
  13772. 'nb': 3,
  13773. 'nd': 3,
  13774. 'ne': 3,
  13775. 'nl': 3,
  13776. 'nn': 3,
  13777. 'no': 3,
  13778. 'nr': 3,
  13779. 'nso': 4,
  13780. 'ny': 3,
  13781. 'nyn': 3,
  13782. 'om': 3,
  13783. 'or': 3,
  13784. 'pa': 3,
  13785. 'pap': 3,
  13786. 'pl': 13,
  13787. 'ps': 3,
  13788. 'pt': 3,
  13789. 'rm': 3,
  13790. 'ro': 9,
  13791. 'rof': 3,
  13792. 'ru': 11,
  13793. 'rwk': 3,
  13794. 'sah': 0,
  13795. 'saq': 3,
  13796. 'se': 7,
  13797. 'seh': 3,
  13798. 'ses': 0,
  13799. 'sg': 0,
  13800. 'sh': 11,
  13801. 'shi': 19,
  13802. 'sk': 12,
  13803. 'sl': 14,
  13804. 'sma': 7,
  13805. 'smi': 7,
  13806. 'smj': 7,
  13807. 'smn': 7,
  13808. 'sms': 7,
  13809. 'sn': 3,
  13810. 'so': 3,
  13811. 'sq': 3,
  13812. 'sr': 11,
  13813. 'ss': 3,
  13814. 'ssy': 3,
  13815. 'st': 3,
  13816. 'sv': 3,
  13817. 'sw': 3,
  13818. 'syr': 3,
  13819. 'ta': 3,
  13820. 'te': 3,
  13821. 'teo': 3,
  13822. 'th': 0,
  13823. 'ti': 4,
  13824. 'tig': 3,
  13825. 'tk': 3,
  13826. 'tl': 4,
  13827. 'tn': 3,
  13828. 'to': 0,
  13829. 'tr': 0,
  13830. 'ts': 3,
  13831. 'tzm': 22,
  13832. 'uk': 11,
  13833. 'ur': 3,
  13834. 've': 3,
  13835. 'vi': 0,
  13836. 'vun': 3,
  13837. 'wa': 4,
  13838. 'wae': 3,
  13839. 'wo': 0,
  13840. 'xh': 3,
  13841. 'xog': 3,
  13842. 'yo': 0,
  13843. 'zh': 0,
  13844. 'zu': 3
  13845. };
  13846. function isIn(n, list) {
  13847. return list.indexOf(n) !== -1;
  13848. }
  13849. function isBetween(n, start, end) {
  13850. return start <= n && n <= end;
  13851. }
  13852. var pluralRules = {
  13853. '0': function (n) {
  13854. return 'other';
  13855. },
  13856. '1': function (n) {
  13857. if (isBetween(n % 100, 3, 10)) return 'few';
  13858. if (n === 0) return 'zero';
  13859. if (isBetween(n % 100, 11, 99)) return 'many';
  13860. if (n == 2) return 'two';
  13861. if (n == 1) return 'one';
  13862. return 'other';
  13863. },
  13864. '2': function (n) {
  13865. if (n !== 0 && n % 10 === 0) return 'many';
  13866. if (n == 2) return 'two';
  13867. if (n == 1) return 'one';
  13868. return 'other';
  13869. },
  13870. '3': function (n) {
  13871. if (n == 1) return 'one';
  13872. return 'other';
  13873. },
  13874. '4': function (n) {
  13875. if (isBetween(n, 0, 1)) return 'one';
  13876. return 'other';
  13877. },
  13878. '5': function (n) {
  13879. if (isBetween(n, 0, 2) && n != 2) return 'one';
  13880. return 'other';
  13881. },
  13882. '6': function (n) {
  13883. if (n === 0) return 'zero';
  13884. if (n % 10 == 1 && n % 100 != 11) return 'one';
  13885. return 'other';
  13886. },
  13887. '7': function (n) {
  13888. if (n == 2) return 'two';
  13889. if (n == 1) return 'one';
  13890. return 'other';
  13891. },
  13892. '8': function (n) {
  13893. if (isBetween(n, 3, 6)) return 'few';
  13894. if (isBetween(n, 7, 10)) return 'many';
  13895. if (n == 2) return 'two';
  13896. if (n == 1) return 'one';
  13897. return 'other';
  13898. },
  13899. '9': function (n) {
  13900. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  13901. if (n == 1) return 'one';
  13902. return 'other';
  13903. },
  13904. '10': function (n) {
  13905. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  13906. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  13907. return 'other';
  13908. },
  13909. '11': function (n) {
  13910. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  13911. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  13912. if (n % 10 == 1 && n % 100 != 11) return 'one';
  13913. return 'other';
  13914. },
  13915. '12': function (n) {
  13916. if (isBetween(n, 2, 4)) return 'few';
  13917. if (n == 1) return 'one';
  13918. return 'other';
  13919. },
  13920. '13': function (n) {
  13921. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  13922. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  13923. if (n == 1) return 'one';
  13924. return 'other';
  13925. },
  13926. '14': function (n) {
  13927. if (isBetween(n % 100, 3, 4)) return 'few';
  13928. if (n % 100 == 2) return 'two';
  13929. if (n % 100 == 1) return 'one';
  13930. return 'other';
  13931. },
  13932. '15': function (n) {
  13933. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  13934. if (isBetween(n % 100, 11, 19)) return 'many';
  13935. if (n == 1) return 'one';
  13936. return 'other';
  13937. },
  13938. '16': function (n) {
  13939. if (n % 10 == 1 && n != 11) return 'one';
  13940. return 'other';
  13941. },
  13942. '17': function (n) {
  13943. if (n == 3) return 'few';
  13944. if (n === 0) return 'zero';
  13945. if (n == 6) return 'many';
  13946. if (n == 2) return 'two';
  13947. if (n == 1) return 'one';
  13948. return 'other';
  13949. },
  13950. '18': function (n) {
  13951. if (n === 0) return 'zero';
  13952. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  13953. return 'other';
  13954. },
  13955. '19': function (n) {
  13956. if (isBetween(n, 2, 10)) return 'few';
  13957. if (isBetween(n, 0, 1)) return 'one';
  13958. return 'other';
  13959. },
  13960. '20': function (n) {
  13961. 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';
  13962. if (n % 1000000 === 0 && n !== 0) return 'many';
  13963. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  13964. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  13965. return 'other';
  13966. },
  13967. '21': function (n) {
  13968. if (n === 0) return 'zero';
  13969. if (n == 1) return 'one';
  13970. return 'other';
  13971. },
  13972. '22': function (n) {
  13973. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  13974. return 'other';
  13975. },
  13976. '23': function (n) {
  13977. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  13978. return 'other';
  13979. },
  13980. '24': function (n) {
  13981. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  13982. if (isIn(n, [2, 12])) return 'two';
  13983. if (isIn(n, [1, 11])) return 'one';
  13984. return 'other';
  13985. }
  13986. };
  13987. var index = locales2rules[lang.replace(/-.*$/, '')];
  13988. if (!(index in pluralRules)) {
  13989. console.warn('plural form unknown for [' + lang + ']');
  13990. return function () {
  13991. return 'other';
  13992. };
  13993. }
  13994. return pluralRules[index];
  13995. }
  13996. gMacros.plural = function (str, param, key, prop) {
  13997. var n = parseFloat(param);
  13998. if (isNaN(n)) return str;
  13999. if (prop != gTextProp) return str;
  14000. if (!gMacros._pluralRules) {
  14001. gMacros._pluralRules = getPluralRules(gLanguage);
  14002. }
  14003. var index = '[' + gMacros._pluralRules(n) + ']';
  14004. if (n === 0 && key + '[zero]' in gL10nData) {
  14005. str = gL10nData[key + '[zero]'][prop];
  14006. } else if (n == 1 && key + '[one]' in gL10nData) {
  14007. str = gL10nData[key + '[one]'][prop];
  14008. } else if (n == 2 && key + '[two]' in gL10nData) {
  14009. str = gL10nData[key + '[two]'][prop];
  14010. } else if (key + index in gL10nData) {
  14011. str = gL10nData[key + index][prop];
  14012. } else if (key + '[other]' in gL10nData) {
  14013. str = gL10nData[key + '[other]'][prop];
  14014. }
  14015. return str;
  14016. };
  14017. function getL10nData(key, args, fallback) {
  14018. var data = gL10nData[key];
  14019. if (!data) {
  14020. console.warn('#' + key + ' is undefined.');
  14021. if (!fallback) {
  14022. return null;
  14023. }
  14024. data = fallback;
  14025. }
  14026. var rv = {};
  14027. for (var prop in data) {
  14028. var str = data[prop];
  14029. str = substIndexes(str, args, key, prop);
  14030. str = substArguments(str, args, key);
  14031. rv[prop] = str;
  14032. }
  14033. return rv;
  14034. }
  14035. function substIndexes(str, args, key, prop) {
  14036. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  14037. var reMatch = reIndex.exec(str);
  14038. if (!reMatch || !reMatch.length) return str;
  14039. var macroName = reMatch[1];
  14040. var paramName = reMatch[2];
  14041. var param;
  14042. if (args && paramName in args) {
  14043. param = args[paramName];
  14044. } else if (paramName in gL10nData) {
  14045. param = gL10nData[paramName];
  14046. }
  14047. if (macroName in gMacros) {
  14048. var macro = gMacros[macroName];
  14049. str = macro(str, param, key, prop);
  14050. }
  14051. return str;
  14052. }
  14053. function substArguments(str, args, key) {
  14054. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  14055. return str.replace(reArgs, function (matched_text, arg) {
  14056. if (args && arg in args) {
  14057. return args[arg];
  14058. }
  14059. if (arg in gL10nData) {
  14060. return gL10nData[arg];
  14061. }
  14062. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  14063. return matched_text;
  14064. });
  14065. }
  14066. function translateElement(element) {
  14067. var l10n = getL10nAttributes(element);
  14068. if (!l10n.id) return;
  14069. var data = getL10nData(l10n.id, l10n.args);
  14070. if (!data) {
  14071. console.warn('#' + l10n.id + ' is undefined.');
  14072. return;
  14073. }
  14074. if (data[gTextProp]) {
  14075. if (getChildElementCount(element) === 0) {
  14076. element[gTextProp] = data[gTextProp];
  14077. } else {
  14078. var children = element.childNodes;
  14079. var found = false;
  14080. for (var i = 0, l = children.length; i < l; i++) {
  14081. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  14082. if (found) {
  14083. children[i].nodeValue = '';
  14084. } else {
  14085. children[i].nodeValue = data[gTextProp];
  14086. found = true;
  14087. }
  14088. }
  14089. }
  14090. if (!found) {
  14091. var textNode = document.createTextNode(data[gTextProp]);
  14092. element.prepend(textNode);
  14093. }
  14094. }
  14095. delete data[gTextProp];
  14096. }
  14097. for (var k in data) {
  14098. element[k] = data[k];
  14099. }
  14100. }
  14101. function getChildElementCount(element) {
  14102. if (element.children) {
  14103. return element.children.length;
  14104. }
  14105. if (typeof element.childElementCount !== 'undefined') {
  14106. return element.childElementCount;
  14107. }
  14108. var count = 0;
  14109. for (var i = 0; i < element.childNodes.length; i++) {
  14110. count += element.nodeType === 1 ? 1 : 0;
  14111. }
  14112. return count;
  14113. }
  14114. function translateFragment(element) {
  14115. element = element || document.documentElement;
  14116. var children = getTranslatableChildren(element);
  14117. var elementCount = children.length;
  14118. for (var i = 0; i < elementCount; i++) {
  14119. translateElement(children[i]);
  14120. }
  14121. translateElement(element);
  14122. }
  14123. return {
  14124. get: function (key, args, fallbackString) {
  14125. var index = key.lastIndexOf('.');
  14126. var prop = gTextProp;
  14127. if (index > 0) {
  14128. prop = key.substring(index + 1);
  14129. key = key.substring(0, index);
  14130. }
  14131. var fallback;
  14132. if (fallbackString) {
  14133. fallback = {};
  14134. fallback[prop] = fallbackString;
  14135. }
  14136. var data = getL10nData(key, args, fallback);
  14137. if (data && prop in data) {
  14138. return data[prop];
  14139. }
  14140. return '{{' + key + '}}';
  14141. },
  14142. getData: function () {
  14143. return gL10nData;
  14144. },
  14145. getText: function () {
  14146. return gTextData;
  14147. },
  14148. getLanguage: function () {
  14149. return gLanguage;
  14150. },
  14151. setLanguage: function (lang, callback) {
  14152. loadLocale(lang, function () {
  14153. if (callback) callback();
  14154. });
  14155. },
  14156. getDirection: function () {
  14157. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  14158. var shortCode = gLanguage.split('-', 1)[0];
  14159. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  14160. },
  14161. translate: translateFragment,
  14162. getReadyState: function () {
  14163. return gReadyState;
  14164. },
  14165. ready: function (callback) {
  14166. if (!callback) {
  14167. return;
  14168. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  14169. window.setTimeout(function () {
  14170. callback();
  14171. });
  14172. } else if (document.addEventListener) {
  14173. document.addEventListener('localized', function once() {
  14174. document.removeEventListener('localized', once);
  14175. callback();
  14176. });
  14177. }
  14178. }
  14179. };
  14180. }(window, document);
  14181. /***/ }),
  14182. /* 47 */
  14183. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  14184. Object.defineProperty(exports, "__esModule", ({
  14185. value: true
  14186. }));
  14187. exports.GenericScripting = void 0;
  14188. exports.docPropertiesLookup = docPropertiesLookup;
  14189. var _pdfjsLib = __webpack_require__(5);
  14190. async function docPropertiesLookup(pdfDocument) {
  14191. const url = "",
  14192. baseUrl = url.split("#")[0];
  14193. let {
  14194. info,
  14195. metadata,
  14196. contentDispositionFilename,
  14197. contentLength
  14198. } = await pdfDocument.getMetadata();
  14199. if (!contentLength) {
  14200. const {
  14201. length
  14202. } = await pdfDocument.getDownloadInfo();
  14203. contentLength = length;
  14204. }
  14205. return {
  14206. ...info,
  14207. baseURL: baseUrl,
  14208. filesize: contentLength,
  14209. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  14210. metadata: metadata === null || metadata === void 0 ? void 0 : metadata.getRaw(),
  14211. authors: metadata === null || metadata === void 0 ? void 0 : metadata.get("dc:creator"),
  14212. numPages: pdfDocument.numPages,
  14213. URL: url
  14214. };
  14215. }
  14216. class GenericScripting {
  14217. constructor(sandboxBundleSrc) {
  14218. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  14219. return window.pdfjsSandbox.QuickJSSandbox();
  14220. });
  14221. }
  14222. async createSandbox(data) {
  14223. const sandbox = await this._ready;
  14224. sandbox.create(data);
  14225. }
  14226. async dispatchEventInSandbox(event) {
  14227. const sandbox = await this._ready;
  14228. setTimeout(() => sandbox.dispatchEvent(event), 0);
  14229. }
  14230. async destroySandbox() {
  14231. const sandbox = await this._ready;
  14232. sandbox.nukeSandbox();
  14233. }
  14234. }
  14235. exports.GenericScripting = GenericScripting;
  14236. /***/ }),
  14237. /* 48 */
  14238. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  14239. Object.defineProperty(exports, "__esModule", ({
  14240. value: true
  14241. }));
  14242. exports.PDFPrintService = PDFPrintService;
  14243. var _pdfjsLib = __webpack_require__(5);
  14244. var _app = __webpack_require__(4);
  14245. var _print_utils = __webpack_require__(49);
  14246. let activeService = null;
  14247. let dialog = null;
  14248. let overlayManager = null;
  14249. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  14250. const scratchCanvas = activeService.scratchCanvas;
  14251. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  14252. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  14253. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  14254. const ctx = scratchCanvas.getContext("2d");
  14255. ctx.save();
  14256. ctx.fillStyle = "rgb(255, 255, 255)";
  14257. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  14258. ctx.restore();
  14259. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function (_ref) {
  14260. let [pdfPage, printAnnotationStorage] = _ref;
  14261. const renderContext = {
  14262. canvasContext: ctx,
  14263. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  14264. viewport: pdfPage.getViewport({
  14265. scale: 1,
  14266. rotation: size.rotation
  14267. }),
  14268. intent: "print",
  14269. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  14270. optionalContentConfigPromise,
  14271. printAnnotationStorage
  14272. };
  14273. return pdfPage.render(renderContext).promise;
  14274. });
  14275. }
  14276. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution) {
  14277. let optionalContentConfigPromise = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
  14278. let printAnnotationStoragePromise = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
  14279. let l10n = arguments.length > 6 ? arguments[6] : undefined;
  14280. this.pdfDocument = pdfDocument;
  14281. this.pagesOverview = pagesOverview;
  14282. this.printContainer = printContainer;
  14283. this._printResolution = printResolution || 150;
  14284. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  14285. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  14286. this.l10n = l10n;
  14287. this.currentPage = -1;
  14288. this.scratchCanvas = document.createElement("canvas");
  14289. }
  14290. PDFPrintService.prototype = {
  14291. layout() {
  14292. this.throwIfInactive();
  14293. const body = document.querySelector("body");
  14294. body.setAttribute("data-pdfjsprinting", true);
  14295. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  14296. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  14297. }, this);
  14298. if (!hasEqualPageSizes) {
  14299. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  14300. }
  14301. this.pageStyleSheet = document.createElement("style");
  14302. const pageSize = this.pagesOverview[0];
  14303. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  14304. body.append(this.pageStyleSheet);
  14305. },
  14306. destroy() {
  14307. if (activeService !== this) {
  14308. return;
  14309. }
  14310. this.printContainer.textContent = "";
  14311. const body = document.querySelector("body");
  14312. body.removeAttribute("data-pdfjsprinting");
  14313. if (this.pageStyleSheet) {
  14314. this.pageStyleSheet.remove();
  14315. this.pageStyleSheet = null;
  14316. }
  14317. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  14318. this.scratchCanvas = null;
  14319. activeService = null;
  14320. ensureOverlay().then(function () {
  14321. if (overlayManager.active === dialog) {
  14322. overlayManager.close(dialog);
  14323. }
  14324. });
  14325. },
  14326. renderPages() {
  14327. if (this.pdfDocument.isPureXfa) {
  14328. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  14329. return Promise.resolve();
  14330. }
  14331. const pageCount = this.pagesOverview.length;
  14332. const renderNextPage = (resolve, reject) => {
  14333. this.throwIfInactive();
  14334. if (++this.currentPage >= pageCount) {
  14335. renderProgress(pageCount, pageCount, this.l10n);
  14336. resolve();
  14337. return;
  14338. }
  14339. const index = this.currentPage;
  14340. renderProgress(index, pageCount, this.l10n);
  14341. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  14342. renderNextPage(resolve, reject);
  14343. }, reject);
  14344. };
  14345. return new Promise(renderNextPage);
  14346. },
  14347. useRenderedPage() {
  14348. this.throwIfInactive();
  14349. const img = document.createElement("img");
  14350. const scratchCanvas = this.scratchCanvas;
  14351. if ("toBlob" in scratchCanvas) {
  14352. scratchCanvas.toBlob(function (blob) {
  14353. img.src = URL.createObjectURL(blob);
  14354. });
  14355. } else {
  14356. img.src = scratchCanvas.toDataURL();
  14357. }
  14358. const wrapper = document.createElement("div");
  14359. wrapper.className = "printedPage";
  14360. wrapper.append(img);
  14361. this.printContainer.append(wrapper);
  14362. return new Promise(function (resolve, reject) {
  14363. img.onload = resolve;
  14364. img.onerror = reject;
  14365. });
  14366. },
  14367. performPrint() {
  14368. this.throwIfInactive();
  14369. return new Promise(resolve => {
  14370. setTimeout(() => {
  14371. if (!this.active) {
  14372. resolve();
  14373. return;
  14374. }
  14375. print.call(window);
  14376. setTimeout(resolve, 20);
  14377. }, 0);
  14378. });
  14379. },
  14380. get active() {
  14381. return this === activeService;
  14382. },
  14383. throwIfInactive() {
  14384. if (!this.active) {
  14385. throw new Error("This print request was cancelled or completed.");
  14386. }
  14387. }
  14388. };
  14389. const print = window.print;
  14390. window.print = function () {
  14391. if (activeService) {
  14392. console.warn("Ignored window.print() because of a pending print job.");
  14393. return;
  14394. }
  14395. ensureOverlay().then(function () {
  14396. if (activeService) {
  14397. overlayManager.open(dialog);
  14398. }
  14399. });
  14400. try {
  14401. dispatchEvent("beforeprint");
  14402. } finally {
  14403. if (!activeService) {
  14404. console.error("Expected print service to be initialized.");
  14405. ensureOverlay().then(function () {
  14406. if (overlayManager.active === dialog) {
  14407. overlayManager.close(dialog);
  14408. }
  14409. });
  14410. return;
  14411. }
  14412. const activeServiceOnEntry = activeService;
  14413. activeService.renderPages().then(function () {
  14414. return activeServiceOnEntry.performPrint();
  14415. }).catch(function () {}).then(function () {
  14416. if (activeServiceOnEntry.active) {
  14417. abort();
  14418. }
  14419. });
  14420. }
  14421. };
  14422. function dispatchEvent(eventType) {
  14423. const event = document.createEvent("CustomEvent");
  14424. event.initCustomEvent(eventType, false, false, "custom");
  14425. window.dispatchEvent(event);
  14426. }
  14427. function abort() {
  14428. if (activeService) {
  14429. activeService.destroy();
  14430. dispatchEvent("afterprint");
  14431. }
  14432. }
  14433. function renderProgress(index, total, l10n) {
  14434. dialog || (dialog = document.getElementById("printServiceDialog"));
  14435. const progress = Math.round(100 * index / total);
  14436. const progressBar = dialog.querySelector("progress");
  14437. const progressPerc = dialog.querySelector(".relative-progress");
  14438. progressBar.value = progress;
  14439. l10n.get("print_progress_percent", {
  14440. progress
  14441. }).then(msg => {
  14442. progressPerc.textContent = msg;
  14443. });
  14444. }
  14445. window.addEventListener("keydown", function (event) {
  14446. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  14447. window.print();
  14448. event.preventDefault();
  14449. event.stopImmediatePropagation();
  14450. }
  14451. }, true);
  14452. if ("onbeforeprint" in window) {
  14453. const stopPropagationIfNeeded = function (event) {
  14454. if (event.detail !== "custom") {
  14455. event.stopImmediatePropagation();
  14456. }
  14457. };
  14458. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  14459. window.addEventListener("afterprint", stopPropagationIfNeeded);
  14460. }
  14461. let overlayPromise;
  14462. function ensureOverlay() {
  14463. if (!overlayPromise) {
  14464. overlayManager = _app.PDFViewerApplication.overlayManager;
  14465. if (!overlayManager) {
  14466. throw new Error("The overlay manager has not yet been initialized.");
  14467. }
  14468. dialog || (dialog = document.getElementById("printServiceDialog"));
  14469. overlayPromise = overlayManager.register(dialog, true);
  14470. document.getElementById("printCancel").onclick = abort;
  14471. dialog.addEventListener("close", abort);
  14472. }
  14473. return overlayPromise;
  14474. }
  14475. _app.PDFPrintServiceFactory.instance = {
  14476. supportsPrinting: true,
  14477. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  14478. if (activeService) {
  14479. throw new Error("The print service is created and active.");
  14480. }
  14481. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  14482. return activeService;
  14483. }
  14484. };
  14485. /***/ }),
  14486. /* 49 */
  14487. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  14488. Object.defineProperty(exports, "__esModule", ({
  14489. value: true
  14490. }));
  14491. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  14492. var _pdfjsLib = __webpack_require__(5);
  14493. var _pdf_link_service = __webpack_require__(3);
  14494. var _xfa_layer_builder = __webpack_require__(38);
  14495. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  14496. const xfaHtml = pdfDocument.allXfaHtml;
  14497. const linkService = new _pdf_link_service.SimpleLinkService();
  14498. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  14499. for (const xfaPage of xfaHtml.children) {
  14500. const page = document.createElement("div");
  14501. page.className = "xfaPrintedPage";
  14502. printContainer.append(page);
  14503. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  14504. pageDiv: page,
  14505. pdfPage: null,
  14506. annotationStorage: pdfDocument.annotationStorage,
  14507. linkService,
  14508. xfaHtml: xfaPage
  14509. });
  14510. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  14511. scale
  14512. });
  14513. builder.render(viewport, "print");
  14514. }
  14515. }
  14516. /***/ })
  14517. /******/ ]);
  14518. /************************************************************************/
  14519. /******/ // The module cache
  14520. /******/ var __webpack_module_cache__ = {};
  14521. /******/
  14522. /******/ // The require function
  14523. /******/ function __webpack_require__(moduleId) {
  14524. /******/ // Check if module is in cache
  14525. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  14526. /******/ if (cachedModule !== undefined) {
  14527. /******/ return cachedModule.exports;
  14528. /******/ }
  14529. /******/ // Create a new module (and put it into the cache)
  14530. /******/ var module = __webpack_module_cache__[moduleId] = {
  14531. /******/ // no module.id needed
  14532. /******/ // no module.loaded needed
  14533. /******/ exports: {}
  14534. /******/ };
  14535. /******/
  14536. /******/ // Execute the module function
  14537. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  14538. /******/
  14539. /******/ // Return the exports of the module
  14540. /******/ return module.exports;
  14541. /******/ }
  14542. /******/
  14543. /************************************************************************/
  14544. var __webpack_exports__ = {};
  14545. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  14546. (() => {
  14547. var exports = __webpack_exports__;
  14548. Object.defineProperty(exports, "__esModule", ({
  14549. value: true
  14550. }));
  14551. Object.defineProperty(exports, "PDFViewerApplication", ({
  14552. enumerable: true,
  14553. get: function () {
  14554. return _app.PDFViewerApplication;
  14555. }
  14556. }));
  14557. exports.PDFViewerApplicationConstants = void 0;
  14558. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  14559. enumerable: true,
  14560. get: function () {
  14561. return _app_options.AppOptions;
  14562. }
  14563. }));
  14564. var _ui_utils = __webpack_require__(1);
  14565. var _app_options = __webpack_require__(2);
  14566. var _pdf_link_service = __webpack_require__(3);
  14567. var _app = __webpack_require__(4);
  14568. var _document$blockUnbloc, _document;
  14569. const pdfjsVersion = '3.1.81';
  14570. const pdfjsBuild = '0766898d5';
  14571. const AppConstants = {
  14572. LinkTarget: _pdf_link_service.LinkTarget,
  14573. RenderingStates: _ui_utils.RenderingStates,
  14574. ScrollMode: _ui_utils.ScrollMode,
  14575. SpreadMode: _ui_utils.SpreadMode
  14576. };
  14577. exports.PDFViewerApplicationConstants = AppConstants;
  14578. window.PDFViewerApplication = _app.PDFViewerApplication;
  14579. window.PDFViewerApplicationConstants = AppConstants;
  14580. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  14581. ;
  14582. ;
  14583. {
  14584. __webpack_require__(42);
  14585. }
  14586. ;
  14587. {
  14588. __webpack_require__(48);
  14589. }
  14590. function getViewerConfiguration() {
  14591. return {
  14592. appContainer: document.body,
  14593. mainContainer: document.getElementById("viewerContainer"),
  14594. viewerContainer: document.getElementById("viewer"),
  14595. toolbar: {
  14596. container: document.getElementById("toolbarViewer"),
  14597. numPages: document.getElementById("numPages"),
  14598. pageNumber: document.getElementById("pageNumber"),
  14599. scaleSelect: document.getElementById("scaleSelect"),
  14600. customScaleOption: document.getElementById("customScaleOption"),
  14601. previous: document.getElementById("previous"),
  14602. next: document.getElementById("next"),
  14603. zoomIn: document.getElementById("zoomIn"),
  14604. zoomOut: document.getElementById("zoomOut"),
  14605. viewFind: document.getElementById("viewFind"),
  14606. openFile: document.getElementById("openFile"),
  14607. print: document.getElementById("print"),
  14608. editorFreeTextButton: document.getElementById("editorFreeText"),
  14609. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  14610. editorInkButton: document.getElementById("editorInk"),
  14611. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  14612. download: document.getElementById("download")
  14613. },
  14614. secondaryToolbar: {
  14615. toolbar: document.getElementById("secondaryToolbar"),
  14616. toggleButton: document.getElementById("secondaryToolbarToggle"),
  14617. presentationModeButton: document.getElementById("presentationMode"),
  14618. openFileButton: document.getElementById("secondaryOpenFile"),
  14619. printButton: document.getElementById("secondaryPrint"),
  14620. downloadButton: document.getElementById("secondaryDownload"),
  14621. viewBookmarkButton: document.getElementById("viewBookmark"),
  14622. firstPageButton: document.getElementById("firstPage"),
  14623. lastPageButton: document.getElementById("lastPage"),
  14624. pageRotateCwButton: document.getElementById("pageRotateCw"),
  14625. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  14626. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  14627. cursorHandToolButton: document.getElementById("cursorHandTool"),
  14628. scrollPageButton: document.getElementById("scrollPage"),
  14629. scrollVerticalButton: document.getElementById("scrollVertical"),
  14630. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  14631. scrollWrappedButton: document.getElementById("scrollWrapped"),
  14632. spreadNoneButton: document.getElementById("spreadNone"),
  14633. spreadOddButton: document.getElementById("spreadOdd"),
  14634. spreadEvenButton: document.getElementById("spreadEven"),
  14635. documentPropertiesButton: document.getElementById("documentProperties")
  14636. },
  14637. sidebar: {
  14638. outerContainer: document.getElementById("outerContainer"),
  14639. sidebarContainer: document.getElementById("sidebarContainer"),
  14640. toggleButton: document.getElementById("sidebarToggle"),
  14641. thumbnailButton: document.getElementById("viewThumbnail"),
  14642. outlineButton: document.getElementById("viewOutline"),
  14643. attachmentsButton: document.getElementById("viewAttachments"),
  14644. layersButton: document.getElementById("viewLayers"),
  14645. thumbnailView: document.getElementById("thumbnailView"),
  14646. outlineView: document.getElementById("outlineView"),
  14647. attachmentsView: document.getElementById("attachmentsView"),
  14648. layersView: document.getElementById("layersView"),
  14649. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  14650. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  14651. },
  14652. sidebarResizer: {
  14653. outerContainer: document.getElementById("outerContainer"),
  14654. resizer: document.getElementById("sidebarResizer")
  14655. },
  14656. findBar: {
  14657. bar: document.getElementById("findbar"),
  14658. toggleButton: document.getElementById("viewFind"),
  14659. findField: document.getElementById("findInput"),
  14660. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  14661. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  14662. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  14663. entireWordCheckbox: document.getElementById("findEntireWord"),
  14664. findMsg: document.getElementById("findMsg"),
  14665. findResultsCount: document.getElementById("findResultsCount"),
  14666. findPreviousButton: document.getElementById("findPrevious"),
  14667. findNextButton: document.getElementById("findNext")
  14668. },
  14669. passwordOverlay: {
  14670. dialog: document.getElementById("passwordDialog"),
  14671. label: document.getElementById("passwordText"),
  14672. input: document.getElementById("password"),
  14673. submitButton: document.getElementById("passwordSubmit"),
  14674. cancelButton: document.getElementById("passwordCancel")
  14675. },
  14676. documentProperties: {
  14677. dialog: document.getElementById("documentPropertiesDialog"),
  14678. closeButton: document.getElementById("documentPropertiesClose"),
  14679. fields: {
  14680. fileName: document.getElementById("fileNameField"),
  14681. fileSize: document.getElementById("fileSizeField"),
  14682. title: document.getElementById("titleField"),
  14683. author: document.getElementById("authorField"),
  14684. subject: document.getElementById("subjectField"),
  14685. keywords: document.getElementById("keywordsField"),
  14686. creationDate: document.getElementById("creationDateField"),
  14687. modificationDate: document.getElementById("modificationDateField"),
  14688. creator: document.getElementById("creatorField"),
  14689. producer: document.getElementById("producerField"),
  14690. version: document.getElementById("versionField"),
  14691. pageCount: document.getElementById("pageCountField"),
  14692. pageSize: document.getElementById("pageSizeField"),
  14693. linearized: document.getElementById("linearizedField")
  14694. }
  14695. },
  14696. annotationEditorParams: {
  14697. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  14698. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  14699. editorInkColor: document.getElementById("editorInkColor"),
  14700. editorInkThickness: document.getElementById("editorInkThickness"),
  14701. editorInkOpacity: document.getElementById("editorInkOpacity")
  14702. },
  14703. printContainer: document.getElementById("printContainer"),
  14704. openFileInput: document.getElementById("fileInput"),
  14705. debuggerScriptPath: "./debugger.js"
  14706. };
  14707. }
  14708. function webViewerLoad() {
  14709. const config = getViewerConfiguration();
  14710. const event = document.createEvent("CustomEvent");
  14711. event.initCustomEvent("webviewerloaded", true, true, {
  14712. source: window
  14713. });
  14714. try {
  14715. parent.document.dispatchEvent(event);
  14716. } catch (ex) {
  14717. console.error(`webviewerloaded: ${ex}`);
  14718. document.dispatchEvent(event);
  14719. }
  14720. _app.PDFViewerApplication.run(config);
  14721. }
  14722. (_document$blockUnbloc = (_document = document).blockUnblockOnload) === null || _document$blockUnbloc === void 0 ? void 0 : _document$blockUnbloc.call(_document, true);
  14723. if (document.readyState === "interactive" || document.readyState === "complete") {
  14724. webViewerLoad();
  14725. } else {
  14726. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  14727. }
  14728. })();
  14729. /******/ })()
  14730. ;
  14731. //# sourceMappingURL=viewer.js.map