viewer.mjs 693 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2024 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. /**
  23. * pdfjsVersion = 5.3.31
  24. * pdfjsBuild = 47ad820d9
  25. */
  26. /******/ var __webpack_modules__ = ({
  27. /***/ 34:
  28. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  29. var isCallable = __webpack_require__(4901);
  30. module.exports = function (it) {
  31. return typeof it == 'object' ? it !== null : isCallable(it);
  32. };
  33. /***/ }),
  34. /***/ 81:
  35. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  36. var call = __webpack_require__(9565);
  37. var aCallable = __webpack_require__(9306);
  38. var anObject = __webpack_require__(8551);
  39. var tryToString = __webpack_require__(6823);
  40. var getIteratorMethod = __webpack_require__(851);
  41. var $TypeError = TypeError;
  42. module.exports = function (argument, usingIterator) {
  43. var iteratorMethod = arguments.length < 2 ? getIteratorMethod(argument) : usingIterator;
  44. if (aCallable(iteratorMethod)) return anObject(call(iteratorMethod, argument));
  45. throw new $TypeError(tryToString(argument) + ' is not iterable');
  46. };
  47. /***/ }),
  48. /***/ 283:
  49. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  50. var uncurryThis = __webpack_require__(9504);
  51. var fails = __webpack_require__(9039);
  52. var isCallable = __webpack_require__(4901);
  53. var hasOwn = __webpack_require__(9297);
  54. var DESCRIPTORS = __webpack_require__(3724);
  55. var CONFIGURABLE_FUNCTION_NAME = (__webpack_require__(350).CONFIGURABLE);
  56. var inspectSource = __webpack_require__(3706);
  57. var InternalStateModule = __webpack_require__(1181);
  58. var enforceInternalState = InternalStateModule.enforce;
  59. var getInternalState = InternalStateModule.get;
  60. var $String = String;
  61. // eslint-disable-next-line es/no-object-defineproperty -- safe
  62. var defineProperty = Object.defineProperty;
  63. var stringSlice = uncurryThis(''.slice);
  64. var replace = uncurryThis(''.replace);
  65. var join = uncurryThis([].join);
  66. var CONFIGURABLE_LENGTH = DESCRIPTORS && !fails(function () {
  67. return defineProperty(function () { /* empty */ }, 'length', { value: 8 }).length !== 8;
  68. });
  69. var TEMPLATE = String(String).split('String');
  70. var makeBuiltIn = module.exports = function (value, name, options) {
  71. if (stringSlice($String(name), 0, 7) === 'Symbol(') {
  72. name = '[' + replace($String(name), /^Symbol\(([^)]*)\).*$/, '$1') + ']';
  73. }
  74. if (options && options.getter) name = 'get ' + name;
  75. if (options && options.setter) name = 'set ' + name;
  76. if (!hasOwn(value, 'name') || (CONFIGURABLE_FUNCTION_NAME && value.name !== name)) {
  77. if (DESCRIPTORS) defineProperty(value, 'name', { value: name, configurable: true });
  78. else value.name = name;
  79. }
  80. if (CONFIGURABLE_LENGTH && options && hasOwn(options, 'arity') && value.length !== options.arity) {
  81. defineProperty(value, 'length', { value: options.arity });
  82. }
  83. try {
  84. if (options && hasOwn(options, 'constructor') && options.constructor) {
  85. if (DESCRIPTORS) defineProperty(value, 'prototype', { writable: false });
  86. // in V8 ~ Chrome 53, prototypes of some methods, like `Array.prototype.values`, are non-writable
  87. } else if (value.prototype) value.prototype = undefined;
  88. } catch (error) { /* empty */ }
  89. var state = enforceInternalState(value);
  90. if (!hasOwn(state, 'source')) {
  91. state.source = join(TEMPLATE, typeof name == 'string' ? name : '');
  92. } return value;
  93. };
  94. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  95. // eslint-disable-next-line no-extend-native -- required
  96. Function.prototype.toString = makeBuiltIn(function toString() {
  97. return isCallable(this) && getInternalState(this).source || inspectSource(this);
  98. }, 'toString');
  99. /***/ }),
  100. /***/ 350:
  101. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  102. var DESCRIPTORS = __webpack_require__(3724);
  103. var hasOwn = __webpack_require__(9297);
  104. var FunctionPrototype = Function.prototype;
  105. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  106. var getDescriptor = DESCRIPTORS && Object.getOwnPropertyDescriptor;
  107. var EXISTS = hasOwn(FunctionPrototype, 'name');
  108. // additional protection from minified / mangled / dropped function names
  109. var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something';
  110. var CONFIGURABLE = EXISTS && (!DESCRIPTORS || (DESCRIPTORS && getDescriptor(FunctionPrototype, 'name').configurable));
  111. module.exports = {
  112. EXISTS: EXISTS,
  113. PROPER: PROPER,
  114. CONFIGURABLE: CONFIGURABLE
  115. };
  116. /***/ }),
  117. /***/ 397:
  118. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  119. var getBuiltIn = __webpack_require__(7751);
  120. module.exports = getBuiltIn('document', 'documentElement');
  121. /***/ }),
  122. /***/ 421:
  123. /***/ ((module) => {
  124. module.exports = {};
  125. /***/ }),
  126. /***/ 507:
  127. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  128. var call = __webpack_require__(9565);
  129. module.exports = function (record, fn, ITERATOR_INSTEAD_OF_RECORD) {
  130. var iterator = ITERATOR_INSTEAD_OF_RECORD ? record : record.iterator;
  131. var next = record.next;
  132. var step, result;
  133. while (!(step = call(next, iterator)).done) {
  134. result = fn(step.value);
  135. if (result !== undefined) return result;
  136. }
  137. };
  138. /***/ }),
  139. /***/ 616:
  140. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  141. var fails = __webpack_require__(9039);
  142. module.exports = !fails(function () {
  143. // eslint-disable-next-line es/no-function-prototype-bind -- safe
  144. var test = (function () { /* empty */ }).bind();
  145. // eslint-disable-next-line no-prototype-builtins -- safe
  146. return typeof test != 'function' || test.hasOwnProperty('prototype');
  147. });
  148. /***/ }),
  149. /***/ 655:
  150. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  151. var classof = __webpack_require__(6955);
  152. var $String = String;
  153. module.exports = function (argument) {
  154. if (classof(argument) === 'Symbol') throw new TypeError('Cannot convert a Symbol value to a string');
  155. return $String(argument);
  156. };
  157. /***/ }),
  158. /***/ 679:
  159. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  160. var isPrototypeOf = __webpack_require__(1625);
  161. var $TypeError = TypeError;
  162. module.exports = function (it, Prototype) {
  163. if (isPrototypeOf(Prototype, it)) return it;
  164. throw new $TypeError('Incorrect invocation');
  165. };
  166. /***/ }),
  167. /***/ 741:
  168. /***/ ((module) => {
  169. var ceil = Math.ceil;
  170. var floor = Math.floor;
  171. // `Math.trunc` method
  172. // https://tc39.es/ecma262/#sec-math.trunc
  173. // eslint-disable-next-line es/no-math-trunc -- safe
  174. module.exports = Math.trunc || function trunc(x) {
  175. var n = +x;
  176. return (n > 0 ? floor : ceil)(n);
  177. };
  178. /***/ }),
  179. /***/ 757:
  180. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  181. var getBuiltIn = __webpack_require__(7751);
  182. var isCallable = __webpack_require__(4901);
  183. var isPrototypeOf = __webpack_require__(1625);
  184. var USE_SYMBOL_AS_UID = __webpack_require__(7040);
  185. var $Object = Object;
  186. module.exports = USE_SYMBOL_AS_UID ? function (it) {
  187. return typeof it == 'symbol';
  188. } : function (it) {
  189. var $Symbol = getBuiltIn('Symbol');
  190. return isCallable($Symbol) && isPrototypeOf($Symbol.prototype, $Object(it));
  191. };
  192. /***/ }),
  193. /***/ 851:
  194. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  195. var classof = __webpack_require__(6955);
  196. var getMethod = __webpack_require__(5966);
  197. var isNullOrUndefined = __webpack_require__(4117);
  198. var Iterators = __webpack_require__(6269);
  199. var wellKnownSymbol = __webpack_require__(8227);
  200. var ITERATOR = wellKnownSymbol('iterator');
  201. module.exports = function (it) {
  202. if (!isNullOrUndefined(it)) return getMethod(it, ITERATOR)
  203. || getMethod(it, '@@iterator')
  204. || Iterators[classof(it)];
  205. };
  206. /***/ }),
  207. /***/ 1072:
  208. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  209. var internalObjectKeys = __webpack_require__(1828);
  210. var enumBugKeys = __webpack_require__(8727);
  211. // `Object.keys` method
  212. // https://tc39.es/ecma262/#sec-object.keys
  213. // eslint-disable-next-line es/no-object-keys -- safe
  214. module.exports = Object.keys || function keys(O) {
  215. return internalObjectKeys(O, enumBugKeys);
  216. };
  217. /***/ }),
  218. /***/ 1148:
  219. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  220. var $ = __webpack_require__(6518);
  221. var call = __webpack_require__(9565);
  222. var iterate = __webpack_require__(2652);
  223. var aCallable = __webpack_require__(9306);
  224. var anObject = __webpack_require__(8551);
  225. var getIteratorDirect = __webpack_require__(1767);
  226. var iteratorClose = __webpack_require__(9539);
  227. var iteratorHelperWithoutClosingOnEarlyError = __webpack_require__(4549);
  228. var everyWithoutClosingOnEarlyError = iteratorHelperWithoutClosingOnEarlyError('every', TypeError);
  229. // `Iterator.prototype.every` method
  230. // https://tc39.es/ecma262/#sec-iterator.prototype.every
  231. $({ target: 'Iterator', proto: true, real: true, forced: everyWithoutClosingOnEarlyError }, {
  232. every: function every(predicate) {
  233. anObject(this);
  234. try {
  235. aCallable(predicate);
  236. } catch (error) {
  237. iteratorClose(this, 'throw', error);
  238. }
  239. if (everyWithoutClosingOnEarlyError) return call(everyWithoutClosingOnEarlyError, this, predicate);
  240. var record = getIteratorDirect(this);
  241. var counter = 0;
  242. return !iterate(record, function (value, stop) {
  243. if (!predicate(value, counter++)) return stop();
  244. }, { IS_RECORD: true, INTERRUPTED: true }).stopped;
  245. }
  246. });
  247. /***/ }),
  248. /***/ 1181:
  249. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  250. var NATIVE_WEAK_MAP = __webpack_require__(8622);
  251. var globalThis = __webpack_require__(4576);
  252. var isObject = __webpack_require__(34);
  253. var createNonEnumerableProperty = __webpack_require__(6699);
  254. var hasOwn = __webpack_require__(9297);
  255. var shared = __webpack_require__(7629);
  256. var sharedKey = __webpack_require__(6119);
  257. var hiddenKeys = __webpack_require__(421);
  258. var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
  259. var TypeError = globalThis.TypeError;
  260. var WeakMap = globalThis.WeakMap;
  261. var set, get, has;
  262. var enforce = function (it) {
  263. return has(it) ? get(it) : set(it, {});
  264. };
  265. var getterFor = function (TYPE) {
  266. return function (it) {
  267. var state;
  268. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  269. throw new TypeError('Incompatible receiver, ' + TYPE + ' required');
  270. } return state;
  271. };
  272. };
  273. if (NATIVE_WEAK_MAP || shared.state) {
  274. var store = shared.state || (shared.state = new WeakMap());
  275. /* eslint-disable no-self-assign -- prototype methods protection */
  276. store.get = store.get;
  277. store.has = store.has;
  278. store.set = store.set;
  279. /* eslint-enable no-self-assign -- prototype methods protection */
  280. set = function (it, metadata) {
  281. if (store.has(it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  282. metadata.facade = it;
  283. store.set(it, metadata);
  284. return metadata;
  285. };
  286. get = function (it) {
  287. return store.get(it) || {};
  288. };
  289. has = function (it) {
  290. return store.has(it);
  291. };
  292. } else {
  293. var STATE = sharedKey('state');
  294. hiddenKeys[STATE] = true;
  295. set = function (it, metadata) {
  296. if (hasOwn(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  297. metadata.facade = it;
  298. createNonEnumerableProperty(it, STATE, metadata);
  299. return metadata;
  300. };
  301. get = function (it) {
  302. return hasOwn(it, STATE) ? it[STATE] : {};
  303. };
  304. has = function (it) {
  305. return hasOwn(it, STATE);
  306. };
  307. }
  308. module.exports = {
  309. set: set,
  310. get: get,
  311. has: has,
  312. enforce: enforce,
  313. getterFor: getterFor
  314. };
  315. /***/ }),
  316. /***/ 1291:
  317. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  318. var trunc = __webpack_require__(741);
  319. // `ToIntegerOrInfinity` abstract operation
  320. // https://tc39.es/ecma262/#sec-tointegerorinfinity
  321. module.exports = function (argument) {
  322. var number = +argument;
  323. // eslint-disable-next-line no-self-compare -- NaN check
  324. return number !== number || number === 0 ? 0 : trunc(number);
  325. };
  326. /***/ }),
  327. /***/ 1548:
  328. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  329. var globalThis = __webpack_require__(4576);
  330. var fails = __webpack_require__(9039);
  331. var V8 = __webpack_require__(9519);
  332. var ENVIRONMENT = __webpack_require__(4215);
  333. var structuredClone = globalThis.structuredClone;
  334. module.exports = !!structuredClone && !fails(function () {
  335. // prevent V8 ArrayBufferDetaching protector cell invalidation and performance degradation
  336. // https://github.com/zloirock/core-js/issues/679
  337. if ((ENVIRONMENT === 'DENO' && V8 > 92) || (ENVIRONMENT === 'NODE' && V8 > 94) || (ENVIRONMENT === 'BROWSER' && V8 > 97)) return false;
  338. var buffer = new ArrayBuffer(8);
  339. var clone = structuredClone(buffer, { transfer: [buffer] });
  340. return buffer.byteLength !== 0 || clone.byteLength !== 8;
  341. });
  342. /***/ }),
  343. /***/ 1625:
  344. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  345. var uncurryThis = __webpack_require__(9504);
  346. module.exports = uncurryThis({}.isPrototypeOf);
  347. /***/ }),
  348. /***/ 1698:
  349. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  350. var $ = __webpack_require__(6518);
  351. var union = __webpack_require__(4204);
  352. var setMethodAcceptSetLike = __webpack_require__(4916);
  353. // `Set.prototype.union` method
  354. // https://tc39.es/ecma262/#sec-set.prototype.union
  355. $({ target: 'Set', proto: true, real: true, forced: !setMethodAcceptSetLike('union') }, {
  356. union: union
  357. });
  358. /***/ }),
  359. /***/ 1701:
  360. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  361. var $ = __webpack_require__(6518);
  362. var call = __webpack_require__(9565);
  363. var aCallable = __webpack_require__(9306);
  364. var anObject = __webpack_require__(8551);
  365. var getIteratorDirect = __webpack_require__(1767);
  366. var createIteratorProxy = __webpack_require__(9462);
  367. var callWithSafeIterationClosing = __webpack_require__(6319);
  368. var iteratorClose = __webpack_require__(9539);
  369. var iteratorHelperWithoutClosingOnEarlyError = __webpack_require__(4549);
  370. var IS_PURE = __webpack_require__(6395);
  371. var mapWithoutClosingOnEarlyError = !IS_PURE && iteratorHelperWithoutClosingOnEarlyError('map', TypeError);
  372. var IteratorProxy = createIteratorProxy(function () {
  373. var iterator = this.iterator;
  374. var result = anObject(call(this.next, iterator));
  375. var done = this.done = !!result.done;
  376. if (!done) return callWithSafeIterationClosing(iterator, this.mapper, [result.value, this.counter++], true);
  377. });
  378. // `Iterator.prototype.map` method
  379. // https://tc39.es/ecma262/#sec-iterator.prototype.map
  380. $({ target: 'Iterator', proto: true, real: true, forced: IS_PURE || mapWithoutClosingOnEarlyError }, {
  381. map: function map(mapper) {
  382. anObject(this);
  383. try {
  384. aCallable(mapper);
  385. } catch (error) {
  386. iteratorClose(this, 'throw', error);
  387. }
  388. if (mapWithoutClosingOnEarlyError) return call(mapWithoutClosingOnEarlyError, this, mapper);
  389. return new IteratorProxy(getIteratorDirect(this), {
  390. mapper: mapper
  391. });
  392. }
  393. });
  394. /***/ }),
  395. /***/ 1767:
  396. /***/ ((module) => {
  397. // `GetIteratorDirect(obj)` abstract operation
  398. // https://tc39.es/proposal-iterator-helpers/#sec-getiteratordirect
  399. module.exports = function (obj) {
  400. return {
  401. iterator: obj,
  402. next: obj.next,
  403. done: false
  404. };
  405. };
  406. /***/ }),
  407. /***/ 1828:
  408. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  409. var uncurryThis = __webpack_require__(9504);
  410. var hasOwn = __webpack_require__(9297);
  411. var toIndexedObject = __webpack_require__(5397);
  412. var indexOf = (__webpack_require__(9617).indexOf);
  413. var hiddenKeys = __webpack_require__(421);
  414. var push = uncurryThis([].push);
  415. module.exports = function (object, names) {
  416. var O = toIndexedObject(object);
  417. var i = 0;
  418. var result = [];
  419. var key;
  420. for (key in O) !hasOwn(hiddenKeys, key) && hasOwn(O, key) && push(result, key);
  421. // Don't enum bug & hidden keys
  422. while (names.length > i) if (hasOwn(O, key = names[i++])) {
  423. ~indexOf(result, key) || push(result, key);
  424. }
  425. return result;
  426. };
  427. /***/ }),
  428. /***/ 2106:
  429. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  430. var makeBuiltIn = __webpack_require__(283);
  431. var defineProperty = __webpack_require__(4913);
  432. module.exports = function (target, name, descriptor) {
  433. if (descriptor.get) makeBuiltIn(descriptor.get, name, { getter: true });
  434. if (descriptor.set) makeBuiltIn(descriptor.set, name, { setter: true });
  435. return defineProperty.f(target, name, descriptor);
  436. };
  437. /***/ }),
  438. /***/ 2140:
  439. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  440. var wellKnownSymbol = __webpack_require__(8227);
  441. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  442. var test = {};
  443. test[TO_STRING_TAG] = 'z';
  444. module.exports = String(test) === '[object z]';
  445. /***/ }),
  446. /***/ 2195:
  447. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  448. var uncurryThis = __webpack_require__(9504);
  449. var toString = uncurryThis({}.toString);
  450. var stringSlice = uncurryThis(''.slice);
  451. module.exports = function (it) {
  452. return stringSlice(toString(it), 8, -1);
  453. };
  454. /***/ }),
  455. /***/ 2211:
  456. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  457. var fails = __webpack_require__(9039);
  458. module.exports = !fails(function () {
  459. function F() { /* empty */ }
  460. F.prototype.constructor = null;
  461. // eslint-disable-next-line es/no-object-getprototypeof -- required for testing
  462. return Object.getPrototypeOf(new F()) !== F.prototype;
  463. });
  464. /***/ }),
  465. /***/ 2222:
  466. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  467. var $ = __webpack_require__(6518);
  468. var getBuiltIn = __webpack_require__(7751);
  469. var fails = __webpack_require__(9039);
  470. var validateArgumentsLength = __webpack_require__(2812);
  471. var toString = __webpack_require__(655);
  472. var USE_NATIVE_URL = __webpack_require__(7416);
  473. var URL = getBuiltIn('URL');
  474. // https://github.com/nodejs/node/issues/47505
  475. // https://github.com/denoland/deno/issues/18893
  476. var THROWS_WITHOUT_ARGUMENTS = USE_NATIVE_URL && fails(function () {
  477. URL.canParse();
  478. });
  479. // Bun ~ 1.0.30 bug
  480. // https://github.com/oven-sh/bun/issues/9250
  481. var WRONG_ARITY = fails(function () {
  482. return URL.canParse.length !== 1;
  483. });
  484. // `URL.canParse` method
  485. // https://url.spec.whatwg.org/#dom-url-canparse
  486. $({ target: 'URL', stat: true, forced: !THROWS_WITHOUT_ARGUMENTS || WRONG_ARITY }, {
  487. canParse: function canParse(url) {
  488. var length = validateArgumentsLength(arguments.length, 1);
  489. var urlString = toString(url);
  490. var base = length < 2 || arguments[1] === undefined ? undefined : toString(arguments[1]);
  491. try {
  492. return !!new URL(urlString, base);
  493. } catch (error) {
  494. return false;
  495. }
  496. }
  497. });
  498. /***/ }),
  499. /***/ 2360:
  500. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  501. /* global ActiveXObject -- old IE, WSH */
  502. var anObject = __webpack_require__(8551);
  503. var definePropertiesModule = __webpack_require__(6801);
  504. var enumBugKeys = __webpack_require__(8727);
  505. var hiddenKeys = __webpack_require__(421);
  506. var html = __webpack_require__(397);
  507. var documentCreateElement = __webpack_require__(4055);
  508. var sharedKey = __webpack_require__(6119);
  509. var GT = '>';
  510. var LT = '<';
  511. var PROTOTYPE = 'prototype';
  512. var SCRIPT = 'script';
  513. var IE_PROTO = sharedKey('IE_PROTO');
  514. var EmptyConstructor = function () { /* empty */ };
  515. var scriptTag = function (content) {
  516. return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
  517. };
  518. // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
  519. var NullProtoObjectViaActiveX = function (activeXDocument) {
  520. activeXDocument.write(scriptTag(''));
  521. activeXDocument.close();
  522. var temp = activeXDocument.parentWindow.Object;
  523. // eslint-disable-next-line no-useless-assignment -- avoid memory leak
  524. activeXDocument = null;
  525. return temp;
  526. };
  527. // Create object with fake `null` prototype: use iframe Object with cleared prototype
  528. var NullProtoObjectViaIFrame = function () {
  529. // Thrash, waste and sodomy: IE GC bug
  530. var iframe = documentCreateElement('iframe');
  531. var JS = 'java' + SCRIPT + ':';
  532. var iframeDocument;
  533. iframe.style.display = 'none';
  534. html.appendChild(iframe);
  535. // https://github.com/zloirock/core-js/issues/475
  536. iframe.src = String(JS);
  537. iframeDocument = iframe.contentWindow.document;
  538. iframeDocument.open();
  539. iframeDocument.write(scriptTag('document.F=Object'));
  540. iframeDocument.close();
  541. return iframeDocument.F;
  542. };
  543. // Check for document.domain and active x support
  544. // No need to use active x approach when document.domain is not set
  545. // see https://github.com/es-shims/es5-shim/issues/150
  546. // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
  547. // avoid IE GC bug
  548. var activeXDocument;
  549. var NullProtoObject = function () {
  550. try {
  551. activeXDocument = new ActiveXObject('htmlfile');
  552. } catch (error) { /* ignore */ }
  553. NullProtoObject = typeof document != 'undefined'
  554. ? document.domain && activeXDocument
  555. ? NullProtoObjectViaActiveX(activeXDocument) // old IE
  556. : NullProtoObjectViaIFrame()
  557. : NullProtoObjectViaActiveX(activeXDocument); // WSH
  558. var length = enumBugKeys.length;
  559. while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
  560. return NullProtoObject();
  561. };
  562. hiddenKeys[IE_PROTO] = true;
  563. // `Object.create` method
  564. // https://tc39.es/ecma262/#sec-object.create
  565. // eslint-disable-next-line es/no-object-create -- safe
  566. module.exports = Object.create || function create(O, Properties) {
  567. var result;
  568. if (O !== null) {
  569. EmptyConstructor[PROTOTYPE] = anObject(O);
  570. result = new EmptyConstructor();
  571. EmptyConstructor[PROTOTYPE] = null;
  572. // add "__proto__" for Object.getPrototypeOf polyfill
  573. result[IE_PROTO] = O;
  574. } else result = NullProtoObject();
  575. return Properties === undefined ? result : definePropertiesModule.f(result, Properties);
  576. };
  577. /***/ }),
  578. /***/ 2475:
  579. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  580. var $ = __webpack_require__(6518);
  581. var isSupersetOf = __webpack_require__(8527);
  582. var setMethodAcceptSetLike = __webpack_require__(4916);
  583. var INCORRECT = !setMethodAcceptSetLike('isSupersetOf', function (result) {
  584. return !result;
  585. });
  586. // `Set.prototype.isSupersetOf` method
  587. // https://tc39.es/ecma262/#sec-set.prototype.issupersetof
  588. $({ target: 'Set', proto: true, real: true, forced: INCORRECT }, {
  589. isSupersetOf: isSupersetOf
  590. });
  591. /***/ }),
  592. /***/ 2489:
  593. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  594. var $ = __webpack_require__(6518);
  595. var call = __webpack_require__(9565);
  596. var aCallable = __webpack_require__(9306);
  597. var anObject = __webpack_require__(8551);
  598. var getIteratorDirect = __webpack_require__(1767);
  599. var createIteratorProxy = __webpack_require__(9462);
  600. var callWithSafeIterationClosing = __webpack_require__(6319);
  601. var IS_PURE = __webpack_require__(6395);
  602. var iteratorClose = __webpack_require__(9539);
  603. var iteratorHelperWithoutClosingOnEarlyError = __webpack_require__(4549);
  604. var filterWithoutClosingOnEarlyError = !IS_PURE && iteratorHelperWithoutClosingOnEarlyError('filter', TypeError);
  605. var IteratorProxy = createIteratorProxy(function () {
  606. var iterator = this.iterator;
  607. var predicate = this.predicate;
  608. var next = this.next;
  609. var result, done, value;
  610. while (true) {
  611. result = anObject(call(next, iterator));
  612. done = this.done = !!result.done;
  613. if (done) return;
  614. value = result.value;
  615. if (callWithSafeIterationClosing(iterator, predicate, [value, this.counter++], true)) return value;
  616. }
  617. });
  618. // `Iterator.prototype.filter` method
  619. // https://tc39.es/ecma262/#sec-iterator.prototype.filter
  620. $({ target: 'Iterator', proto: true, real: true, forced: IS_PURE || filterWithoutClosingOnEarlyError }, {
  621. filter: function filter(predicate) {
  622. anObject(this);
  623. try {
  624. aCallable(predicate);
  625. } catch (error) {
  626. iteratorClose(this, 'throw', error);
  627. }
  628. if (filterWithoutClosingOnEarlyError) return call(filterWithoutClosingOnEarlyError, this, predicate);
  629. return new IteratorProxy(getIteratorDirect(this), {
  630. predicate: predicate
  631. });
  632. }
  633. });
  634. /***/ }),
  635. /***/ 2529:
  636. /***/ ((module) => {
  637. // `CreateIterResultObject` abstract operation
  638. // https://tc39.es/ecma262/#sec-createiterresultobject
  639. module.exports = function (value, done) {
  640. return { value: value, done: done };
  641. };
  642. /***/ }),
  643. /***/ 2652:
  644. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  645. var bind = __webpack_require__(6080);
  646. var call = __webpack_require__(9565);
  647. var anObject = __webpack_require__(8551);
  648. var tryToString = __webpack_require__(6823);
  649. var isArrayIteratorMethod = __webpack_require__(4209);
  650. var lengthOfArrayLike = __webpack_require__(6198);
  651. var isPrototypeOf = __webpack_require__(1625);
  652. var getIterator = __webpack_require__(81);
  653. var getIteratorMethod = __webpack_require__(851);
  654. var iteratorClose = __webpack_require__(9539);
  655. var $TypeError = TypeError;
  656. var Result = function (stopped, result) {
  657. this.stopped = stopped;
  658. this.result = result;
  659. };
  660. var ResultPrototype = Result.prototype;
  661. module.exports = function (iterable, unboundFunction, options) {
  662. var that = options && options.that;
  663. var AS_ENTRIES = !!(options && options.AS_ENTRIES);
  664. var IS_RECORD = !!(options && options.IS_RECORD);
  665. var IS_ITERATOR = !!(options && options.IS_ITERATOR);
  666. var INTERRUPTED = !!(options && options.INTERRUPTED);
  667. var fn = bind(unboundFunction, that);
  668. var iterator, iterFn, index, length, result, next, step;
  669. var stop = function (condition) {
  670. if (iterator) iteratorClose(iterator, 'normal', condition);
  671. return new Result(true, condition);
  672. };
  673. var callFn = function (value) {
  674. if (AS_ENTRIES) {
  675. anObject(value);
  676. return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]);
  677. } return INTERRUPTED ? fn(value, stop) : fn(value);
  678. };
  679. if (IS_RECORD) {
  680. iterator = iterable.iterator;
  681. } else if (IS_ITERATOR) {
  682. iterator = iterable;
  683. } else {
  684. iterFn = getIteratorMethod(iterable);
  685. if (!iterFn) throw new $TypeError(tryToString(iterable) + ' is not iterable');
  686. // optimisation for array iterators
  687. if (isArrayIteratorMethod(iterFn)) {
  688. for (index = 0, length = lengthOfArrayLike(iterable); length > index; index++) {
  689. result = callFn(iterable[index]);
  690. if (result && isPrototypeOf(ResultPrototype, result)) return result;
  691. } return new Result(false);
  692. }
  693. iterator = getIterator(iterable, iterFn);
  694. }
  695. next = IS_RECORD ? iterable.next : iterator.next;
  696. while (!(step = call(next, iterator)).done) {
  697. try {
  698. result = callFn(step.value);
  699. } catch (error) {
  700. iteratorClose(iterator, 'throw', error);
  701. }
  702. if (typeof result == 'object' && result && isPrototypeOf(ResultPrototype, result)) return result;
  703. } return new Result(false);
  704. };
  705. /***/ }),
  706. /***/ 2777:
  707. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  708. var call = __webpack_require__(9565);
  709. var isObject = __webpack_require__(34);
  710. var isSymbol = __webpack_require__(757);
  711. var getMethod = __webpack_require__(5966);
  712. var ordinaryToPrimitive = __webpack_require__(4270);
  713. var wellKnownSymbol = __webpack_require__(8227);
  714. var $TypeError = TypeError;
  715. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  716. // `ToPrimitive` abstract operation
  717. // https://tc39.es/ecma262/#sec-toprimitive
  718. module.exports = function (input, pref) {
  719. if (!isObject(input) || isSymbol(input)) return input;
  720. var exoticToPrim = getMethod(input, TO_PRIMITIVE);
  721. var result;
  722. if (exoticToPrim) {
  723. if (pref === undefined) pref = 'default';
  724. result = call(exoticToPrim, input, pref);
  725. if (!isObject(result) || isSymbol(result)) return result;
  726. throw new $TypeError("Can't convert object to primitive value");
  727. }
  728. if (pref === undefined) pref = 'number';
  729. return ordinaryToPrimitive(input, pref);
  730. };
  731. /***/ }),
  732. /***/ 2787:
  733. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  734. var hasOwn = __webpack_require__(9297);
  735. var isCallable = __webpack_require__(4901);
  736. var toObject = __webpack_require__(8981);
  737. var sharedKey = __webpack_require__(6119);
  738. var CORRECT_PROTOTYPE_GETTER = __webpack_require__(2211);
  739. var IE_PROTO = sharedKey('IE_PROTO');
  740. var $Object = Object;
  741. var ObjectPrototype = $Object.prototype;
  742. // `Object.getPrototypeOf` method
  743. // https://tc39.es/ecma262/#sec-object.getprototypeof
  744. // eslint-disable-next-line es/no-object-getprototypeof -- safe
  745. module.exports = CORRECT_PROTOTYPE_GETTER ? $Object.getPrototypeOf : function (O) {
  746. var object = toObject(O);
  747. if (hasOwn(object, IE_PROTO)) return object[IE_PROTO];
  748. var constructor = object.constructor;
  749. if (isCallable(constructor) && object instanceof constructor) {
  750. return constructor.prototype;
  751. } return object instanceof $Object ? ObjectPrototype : null;
  752. };
  753. /***/ }),
  754. /***/ 2796:
  755. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  756. var fails = __webpack_require__(9039);
  757. var isCallable = __webpack_require__(4901);
  758. var replacement = /#|\.prototype\./;
  759. var isForced = function (feature, detection) {
  760. var value = data[normalize(feature)];
  761. return value === POLYFILL ? true
  762. : value === NATIVE ? false
  763. : isCallable(detection) ? fails(detection)
  764. : !!detection;
  765. };
  766. var normalize = isForced.normalize = function (string) {
  767. return String(string).replace(replacement, '.').toLowerCase();
  768. };
  769. var data = isForced.data = {};
  770. var NATIVE = isForced.NATIVE = 'N';
  771. var POLYFILL = isForced.POLYFILL = 'P';
  772. module.exports = isForced;
  773. /***/ }),
  774. /***/ 2812:
  775. /***/ ((module) => {
  776. var $TypeError = TypeError;
  777. module.exports = function (passed, required) {
  778. if (passed < required) throw new $TypeError('Not enough arguments');
  779. return passed;
  780. };
  781. /***/ }),
  782. /***/ 2839:
  783. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  784. var globalThis = __webpack_require__(4576);
  785. var navigator = globalThis.navigator;
  786. var userAgent = navigator && navigator.userAgent;
  787. module.exports = userAgent ? String(userAgent) : '';
  788. /***/ }),
  789. /***/ 3238:
  790. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  791. var globalThis = __webpack_require__(4576);
  792. var NATIVE_ARRAY_BUFFER = __webpack_require__(7811);
  793. var arrayBufferByteLength = __webpack_require__(7394);
  794. var DataView = globalThis.DataView;
  795. module.exports = function (O) {
  796. if (!NATIVE_ARRAY_BUFFER || arrayBufferByteLength(O) !== 0) return false;
  797. try {
  798. // eslint-disable-next-line no-new -- thrower
  799. new DataView(O);
  800. return false;
  801. } catch (error) {
  802. return true;
  803. }
  804. };
  805. /***/ }),
  806. /***/ 3392:
  807. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  808. var uncurryThis = __webpack_require__(9504);
  809. var id = 0;
  810. var postfix = Math.random();
  811. var toString = uncurryThis(1.0.toString);
  812. module.exports = function (key) {
  813. return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString(++id + postfix, 36);
  814. };
  815. /***/ }),
  816. /***/ 3440:
  817. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  818. var aSet = __webpack_require__(7080);
  819. var SetHelpers = __webpack_require__(4402);
  820. var clone = __webpack_require__(9286);
  821. var size = __webpack_require__(5170);
  822. var getSetRecord = __webpack_require__(3789);
  823. var iterateSet = __webpack_require__(8469);
  824. var iterateSimple = __webpack_require__(507);
  825. var has = SetHelpers.has;
  826. var remove = SetHelpers.remove;
  827. // `Set.prototype.difference` method
  828. // https://github.com/tc39/proposal-set-methods
  829. module.exports = function difference(other) {
  830. var O = aSet(this);
  831. var otherRec = getSetRecord(other);
  832. var result = clone(O);
  833. if (size(O) <= otherRec.size) iterateSet(O, function (e) {
  834. if (otherRec.includes(e)) remove(result, e);
  835. });
  836. else iterateSimple(otherRec.getIterator(), function (e) {
  837. if (has(O, e)) remove(result, e);
  838. });
  839. return result;
  840. };
  841. /***/ }),
  842. /***/ 3579:
  843. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  844. var $ = __webpack_require__(6518);
  845. var call = __webpack_require__(9565);
  846. var iterate = __webpack_require__(2652);
  847. var aCallable = __webpack_require__(9306);
  848. var anObject = __webpack_require__(8551);
  849. var getIteratorDirect = __webpack_require__(1767);
  850. var iteratorClose = __webpack_require__(9539);
  851. var iteratorHelperWithoutClosingOnEarlyError = __webpack_require__(4549);
  852. var someWithoutClosingOnEarlyError = iteratorHelperWithoutClosingOnEarlyError('some', TypeError);
  853. // `Iterator.prototype.some` method
  854. // https://tc39.es/ecma262/#sec-iterator.prototype.some
  855. $({ target: 'Iterator', proto: true, real: true, forced: someWithoutClosingOnEarlyError }, {
  856. some: function some(predicate) {
  857. anObject(this);
  858. try {
  859. aCallable(predicate);
  860. } catch (error) {
  861. iteratorClose(this, 'throw', error);
  862. }
  863. if (someWithoutClosingOnEarlyError) return call(someWithoutClosingOnEarlyError, this, predicate);
  864. var record = getIteratorDirect(this);
  865. var counter = 0;
  866. return iterate(record, function (value, stop) {
  867. if (predicate(value, counter++)) return stop();
  868. }, { IS_RECORD: true, INTERRUPTED: true }).stopped;
  869. }
  870. });
  871. /***/ }),
  872. /***/ 3650:
  873. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  874. var aSet = __webpack_require__(7080);
  875. var SetHelpers = __webpack_require__(4402);
  876. var clone = __webpack_require__(9286);
  877. var getSetRecord = __webpack_require__(3789);
  878. var iterateSimple = __webpack_require__(507);
  879. var add = SetHelpers.add;
  880. var has = SetHelpers.has;
  881. var remove = SetHelpers.remove;
  882. // `Set.prototype.symmetricDifference` method
  883. // https://github.com/tc39/proposal-set-methods
  884. module.exports = function symmetricDifference(other) {
  885. var O = aSet(this);
  886. var keysIter = getSetRecord(other).getIterator();
  887. var result = clone(O);
  888. iterateSimple(keysIter, function (e) {
  889. if (has(O, e)) remove(result, e);
  890. else add(result, e);
  891. });
  892. return result;
  893. };
  894. /***/ }),
  895. /***/ 3706:
  896. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  897. var uncurryThis = __webpack_require__(9504);
  898. var isCallable = __webpack_require__(4901);
  899. var store = __webpack_require__(7629);
  900. var functionToString = uncurryThis(Function.toString);
  901. // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
  902. if (!isCallable(store.inspectSource)) {
  903. store.inspectSource = function (it) {
  904. return functionToString(it);
  905. };
  906. }
  907. module.exports = store.inspectSource;
  908. /***/ }),
  909. /***/ 3717:
  910. /***/ ((__unused_webpack_module, exports) => {
  911. // eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
  912. exports.f = Object.getOwnPropertySymbols;
  913. /***/ }),
  914. /***/ 3724:
  915. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  916. var fails = __webpack_require__(9039);
  917. // Detect IE8's incomplete defineProperty implementation
  918. module.exports = !fails(function () {
  919. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  920. return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] !== 7;
  921. });
  922. /***/ }),
  923. /***/ 3789:
  924. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  925. var aCallable = __webpack_require__(9306);
  926. var anObject = __webpack_require__(8551);
  927. var call = __webpack_require__(9565);
  928. var toIntegerOrInfinity = __webpack_require__(1291);
  929. var getIteratorDirect = __webpack_require__(1767);
  930. var INVALID_SIZE = 'Invalid size';
  931. var $RangeError = RangeError;
  932. var $TypeError = TypeError;
  933. var max = Math.max;
  934. var SetRecord = function (set, intSize) {
  935. this.set = set;
  936. this.size = max(intSize, 0);
  937. this.has = aCallable(set.has);
  938. this.keys = aCallable(set.keys);
  939. };
  940. SetRecord.prototype = {
  941. getIterator: function () {
  942. return getIteratorDirect(anObject(call(this.keys, this.set)));
  943. },
  944. includes: function (it) {
  945. return call(this.has, this.set, it);
  946. }
  947. };
  948. // `GetSetRecord` abstract operation
  949. // https://tc39.es/proposal-set-methods/#sec-getsetrecord
  950. module.exports = function (obj) {
  951. anObject(obj);
  952. var numSize = +obj.size;
  953. // NOTE: If size is undefined, then numSize will be NaN
  954. // eslint-disable-next-line no-self-compare -- NaN check
  955. if (numSize !== numSize) throw new $TypeError(INVALID_SIZE);
  956. var intSize = toIntegerOrInfinity(numSize);
  957. if (intSize < 0) throw new $RangeError(INVALID_SIZE);
  958. return new SetRecord(obj, intSize);
  959. };
  960. /***/ }),
  961. /***/ 3838:
  962. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  963. var aSet = __webpack_require__(7080);
  964. var size = __webpack_require__(5170);
  965. var iterate = __webpack_require__(8469);
  966. var getSetRecord = __webpack_require__(3789);
  967. // `Set.prototype.isSubsetOf` method
  968. // https://tc39.github.io/proposal-set-methods/#Set.prototype.isSubsetOf
  969. module.exports = function isSubsetOf(other) {
  970. var O = aSet(this);
  971. var otherRec = getSetRecord(other);
  972. if (size(O) > otherRec.size) return false;
  973. return iterate(O, function (e) {
  974. if (!otherRec.includes(e)) return false;
  975. }, true) !== false;
  976. };
  977. /***/ }),
  978. /***/ 3853:
  979. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  980. var $ = __webpack_require__(6518);
  981. var isDisjointFrom = __webpack_require__(4449);
  982. var setMethodAcceptSetLike = __webpack_require__(4916);
  983. var INCORRECT = !setMethodAcceptSetLike('isDisjointFrom', function (result) {
  984. return !result;
  985. });
  986. // `Set.prototype.isDisjointFrom` method
  987. // https://tc39.es/ecma262/#sec-set.prototype.isdisjointfrom
  988. $({ target: 'Set', proto: true, real: true, forced: INCORRECT }, {
  989. isDisjointFrom: isDisjointFrom
  990. });
  991. /***/ }),
  992. /***/ 4055:
  993. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  994. var globalThis = __webpack_require__(4576);
  995. var isObject = __webpack_require__(34);
  996. var document = globalThis.document;
  997. // typeof document.createElement is 'object' in old IE
  998. var EXISTS = isObject(document) && isObject(document.createElement);
  999. module.exports = function (it) {
  1000. return EXISTS ? document.createElement(it) : {};
  1001. };
  1002. /***/ }),
  1003. /***/ 4114:
  1004. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  1005. var $ = __webpack_require__(6518);
  1006. var toObject = __webpack_require__(8981);
  1007. var lengthOfArrayLike = __webpack_require__(6198);
  1008. var setArrayLength = __webpack_require__(4527);
  1009. var doesNotExceedSafeInteger = __webpack_require__(6837);
  1010. var fails = __webpack_require__(9039);
  1011. var INCORRECT_TO_LENGTH = fails(function () {
  1012. return [].push.call({ length: 0x100000000 }, 1) !== 4294967297;
  1013. });
  1014. // V8 <= 121 and Safari <= 15.4; FF < 23 throws InternalError
  1015. // https://bugs.chromium.org/p/v8/issues/detail?id=12681
  1016. var properErrorOnNonWritableLength = function () {
  1017. try {
  1018. // eslint-disable-next-line es/no-object-defineproperty -- safe
  1019. Object.defineProperty([], 'length', { writable: false }).push();
  1020. } catch (error) {
  1021. return error instanceof TypeError;
  1022. }
  1023. };
  1024. var FORCED = INCORRECT_TO_LENGTH || !properErrorOnNonWritableLength();
  1025. // `Array.prototype.push` method
  1026. // https://tc39.es/ecma262/#sec-array.prototype.push
  1027. $({ target: 'Array', proto: true, arity: 1, forced: FORCED }, {
  1028. // eslint-disable-next-line no-unused-vars -- required for `.length`
  1029. push: function push(item) {
  1030. var O = toObject(this);
  1031. var len = lengthOfArrayLike(O);
  1032. var argCount = arguments.length;
  1033. doesNotExceedSafeInteger(len + argCount);
  1034. for (var i = 0; i < argCount; i++) {
  1035. O[len] = arguments[i];
  1036. len++;
  1037. }
  1038. setArrayLength(O, len);
  1039. return len;
  1040. }
  1041. });
  1042. /***/ }),
  1043. /***/ 4117:
  1044. /***/ ((module) => {
  1045. // we can't use just `it == null` since of `document.all` special case
  1046. // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-aec
  1047. module.exports = function (it) {
  1048. return it === null || it === undefined;
  1049. };
  1050. /***/ }),
  1051. /***/ 4204:
  1052. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1053. var aSet = __webpack_require__(7080);
  1054. var add = (__webpack_require__(4402).add);
  1055. var clone = __webpack_require__(9286);
  1056. var getSetRecord = __webpack_require__(3789);
  1057. var iterateSimple = __webpack_require__(507);
  1058. // `Set.prototype.union` method
  1059. // https://github.com/tc39/proposal-set-methods
  1060. module.exports = function union(other) {
  1061. var O = aSet(this);
  1062. var keysIter = getSetRecord(other).getIterator();
  1063. var result = clone(O);
  1064. iterateSimple(keysIter, function (it) {
  1065. add(result, it);
  1066. });
  1067. return result;
  1068. };
  1069. /***/ }),
  1070. /***/ 4209:
  1071. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1072. var wellKnownSymbol = __webpack_require__(8227);
  1073. var Iterators = __webpack_require__(6269);
  1074. var ITERATOR = wellKnownSymbol('iterator');
  1075. var ArrayPrototype = Array.prototype;
  1076. // check on default Array iterator
  1077. module.exports = function (it) {
  1078. return it !== undefined && (Iterators.Array === it || ArrayPrototype[ITERATOR] === it);
  1079. };
  1080. /***/ }),
  1081. /***/ 4215:
  1082. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1083. /* global Bun, Deno -- detection */
  1084. var globalThis = __webpack_require__(4576);
  1085. var userAgent = __webpack_require__(2839);
  1086. var classof = __webpack_require__(2195);
  1087. var userAgentStartsWith = function (string) {
  1088. return userAgent.slice(0, string.length) === string;
  1089. };
  1090. module.exports = (function () {
  1091. if (userAgentStartsWith('Bun/')) return 'BUN';
  1092. if (userAgentStartsWith('Cloudflare-Workers')) return 'CLOUDFLARE';
  1093. if (userAgentStartsWith('Deno/')) return 'DENO';
  1094. if (userAgentStartsWith('Node.js/')) return 'NODE';
  1095. if (globalThis.Bun && typeof Bun.version == 'string') return 'BUN';
  1096. if (globalThis.Deno && typeof Deno.version == 'object') return 'DENO';
  1097. if (classof(globalThis.process) === 'process') return 'NODE';
  1098. if (globalThis.window && globalThis.document) return 'BROWSER';
  1099. return 'REST';
  1100. })();
  1101. /***/ }),
  1102. /***/ 4270:
  1103. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1104. var call = __webpack_require__(9565);
  1105. var isCallable = __webpack_require__(4901);
  1106. var isObject = __webpack_require__(34);
  1107. var $TypeError = TypeError;
  1108. // `OrdinaryToPrimitive` abstract operation
  1109. // https://tc39.es/ecma262/#sec-ordinarytoprimitive
  1110. module.exports = function (input, pref) {
  1111. var fn, val;
  1112. if (pref === 'string' && isCallable(fn = input.toString) && !isObject(val = call(fn, input))) return val;
  1113. if (isCallable(fn = input.valueOf) && !isObject(val = call(fn, input))) return val;
  1114. if (pref !== 'string' && isCallable(fn = input.toString) && !isObject(val = call(fn, input))) return val;
  1115. throw new $TypeError("Can't convert object to primitive value");
  1116. };
  1117. /***/ }),
  1118. /***/ 4376:
  1119. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1120. var classof = __webpack_require__(2195);
  1121. // `IsArray` abstract operation
  1122. // https://tc39.es/ecma262/#sec-isarray
  1123. // eslint-disable-next-line es/no-array-isarray -- safe
  1124. module.exports = Array.isArray || function isArray(argument) {
  1125. return classof(argument) === 'Array';
  1126. };
  1127. /***/ }),
  1128. /***/ 4402:
  1129. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1130. var uncurryThis = __webpack_require__(9504);
  1131. // eslint-disable-next-line es/no-set -- safe
  1132. var SetPrototype = Set.prototype;
  1133. module.exports = {
  1134. // eslint-disable-next-line es/no-set -- safe
  1135. Set: Set,
  1136. add: uncurryThis(SetPrototype.add),
  1137. has: uncurryThis(SetPrototype.has),
  1138. remove: uncurryThis(SetPrototype['delete']),
  1139. proto: SetPrototype
  1140. };
  1141. /***/ }),
  1142. /***/ 4449:
  1143. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1144. var aSet = __webpack_require__(7080);
  1145. var has = (__webpack_require__(4402).has);
  1146. var size = __webpack_require__(5170);
  1147. var getSetRecord = __webpack_require__(3789);
  1148. var iterateSet = __webpack_require__(8469);
  1149. var iterateSimple = __webpack_require__(507);
  1150. var iteratorClose = __webpack_require__(9539);
  1151. // `Set.prototype.isDisjointFrom` method
  1152. // https://tc39.github.io/proposal-set-methods/#Set.prototype.isDisjointFrom
  1153. module.exports = function isDisjointFrom(other) {
  1154. var O = aSet(this);
  1155. var otherRec = getSetRecord(other);
  1156. if (size(O) <= otherRec.size) return iterateSet(O, function (e) {
  1157. if (otherRec.includes(e)) return false;
  1158. }, true) !== false;
  1159. var iterator = otherRec.getIterator();
  1160. return iterateSimple(iterator, function (e) {
  1161. if (has(O, e)) return iteratorClose(iterator, 'normal', false);
  1162. }) !== false;
  1163. };
  1164. /***/ }),
  1165. /***/ 4483:
  1166. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1167. var globalThis = __webpack_require__(4576);
  1168. var getBuiltInNodeModule = __webpack_require__(9429);
  1169. var PROPER_STRUCTURED_CLONE_TRANSFER = __webpack_require__(1548);
  1170. var structuredClone = globalThis.structuredClone;
  1171. var $ArrayBuffer = globalThis.ArrayBuffer;
  1172. var $MessageChannel = globalThis.MessageChannel;
  1173. var detach = false;
  1174. var WorkerThreads, channel, buffer, $detach;
  1175. if (PROPER_STRUCTURED_CLONE_TRANSFER) {
  1176. detach = function (transferable) {
  1177. structuredClone(transferable, { transfer: [transferable] });
  1178. };
  1179. } else if ($ArrayBuffer) try {
  1180. if (!$MessageChannel) {
  1181. WorkerThreads = getBuiltInNodeModule('worker_threads');
  1182. if (WorkerThreads) $MessageChannel = WorkerThreads.MessageChannel;
  1183. }
  1184. if ($MessageChannel) {
  1185. channel = new $MessageChannel();
  1186. buffer = new $ArrayBuffer(2);
  1187. $detach = function (transferable) {
  1188. channel.port1.postMessage(null, [transferable]);
  1189. };
  1190. if (buffer.byteLength === 2) {
  1191. $detach(buffer);
  1192. if (buffer.byteLength === 0) detach = $detach;
  1193. }
  1194. }
  1195. } catch (error) { /* empty */ }
  1196. module.exports = detach;
  1197. /***/ }),
  1198. /***/ 4495:
  1199. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1200. /* eslint-disable es/no-symbol -- required for testing */
  1201. var V8_VERSION = __webpack_require__(9519);
  1202. var fails = __webpack_require__(9039);
  1203. var globalThis = __webpack_require__(4576);
  1204. var $String = globalThis.String;
  1205. // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
  1206. module.exports = !!Object.getOwnPropertySymbols && !fails(function () {
  1207. var symbol = Symbol('symbol detection');
  1208. // Chrome 38 Symbol has incorrect toString conversion
  1209. // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
  1210. // nb: Do not call `String` directly to avoid this being optimized out to `symbol+''` which will,
  1211. // of course, fail.
  1212. return !$String(symbol) || !(Object(symbol) instanceof Symbol) ||
  1213. // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
  1214. !Symbol.sham && V8_VERSION && V8_VERSION < 41;
  1215. });
  1216. /***/ }),
  1217. /***/ 4527:
  1218. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1219. var DESCRIPTORS = __webpack_require__(3724);
  1220. var isArray = __webpack_require__(4376);
  1221. var $TypeError = TypeError;
  1222. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  1223. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  1224. // Safari < 13 does not throw an error in this case
  1225. var SILENT_ON_NON_WRITABLE_LENGTH_SET = DESCRIPTORS && !function () {
  1226. // makes no sense without proper strict mode support
  1227. if (this !== undefined) return true;
  1228. try {
  1229. // eslint-disable-next-line es/no-object-defineproperty -- safe
  1230. Object.defineProperty([], 'length', { writable: false }).length = 1;
  1231. } catch (error) {
  1232. return error instanceof TypeError;
  1233. }
  1234. }();
  1235. module.exports = SILENT_ON_NON_WRITABLE_LENGTH_SET ? function (O, length) {
  1236. if (isArray(O) && !getOwnPropertyDescriptor(O, 'length').writable) {
  1237. throw new $TypeError('Cannot set read only .length');
  1238. } return O.length = length;
  1239. } : function (O, length) {
  1240. return O.length = length;
  1241. };
  1242. /***/ }),
  1243. /***/ 4549:
  1244. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1245. var globalThis = __webpack_require__(4576);
  1246. // https://github.com/tc39/ecma262/pull/3467
  1247. module.exports = function (METHOD_NAME, ExpectedError) {
  1248. var Iterator = globalThis.Iterator;
  1249. var IteratorPrototype = Iterator && Iterator.prototype;
  1250. var method = IteratorPrototype && IteratorPrototype[METHOD_NAME];
  1251. var CLOSED = false;
  1252. if (method) try {
  1253. method.call({
  1254. next: function () { return { done: true }; },
  1255. 'return': function () { CLOSED = true; }
  1256. }, -1);
  1257. } catch (error) {
  1258. // https://bugs.webkit.org/show_bug.cgi?id=291195
  1259. if (!(error instanceof ExpectedError)) CLOSED = false;
  1260. }
  1261. if (!CLOSED) return method;
  1262. };
  1263. /***/ }),
  1264. /***/ 4576:
  1265. /***/ (function(module) {
  1266. var check = function (it) {
  1267. return it && it.Math === Math && it;
  1268. };
  1269. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  1270. module.exports =
  1271. // eslint-disable-next-line es/no-global-this -- safe
  1272. check(typeof globalThis == 'object' && globalThis) ||
  1273. check(typeof window == 'object' && window) ||
  1274. // eslint-disable-next-line no-restricted-globals -- safe
  1275. check(typeof self == 'object' && self) ||
  1276. check(typeof global == 'object' && global) ||
  1277. check(typeof this == 'object' && this) ||
  1278. // eslint-disable-next-line no-new-func -- fallback
  1279. (function () { return this; })() || Function('return this')();
  1280. /***/ }),
  1281. /***/ 4603:
  1282. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  1283. var defineBuiltIn = __webpack_require__(6840);
  1284. var uncurryThis = __webpack_require__(9504);
  1285. var toString = __webpack_require__(655);
  1286. var validateArgumentsLength = __webpack_require__(2812);
  1287. var $URLSearchParams = URLSearchParams;
  1288. var URLSearchParamsPrototype = $URLSearchParams.prototype;
  1289. var append = uncurryThis(URLSearchParamsPrototype.append);
  1290. var $delete = uncurryThis(URLSearchParamsPrototype['delete']);
  1291. var forEach = uncurryThis(URLSearchParamsPrototype.forEach);
  1292. var push = uncurryThis([].push);
  1293. var params = new $URLSearchParams('a=1&a=2&b=3');
  1294. params['delete']('a', 1);
  1295. // `undefined` case is a Chromium 117 bug
  1296. // https://bugs.chromium.org/p/v8/issues/detail?id=14222
  1297. params['delete']('b', undefined);
  1298. if (params + '' !== 'a=2') {
  1299. defineBuiltIn(URLSearchParamsPrototype, 'delete', function (name /* , value */) {
  1300. var length = arguments.length;
  1301. var $value = length < 2 ? undefined : arguments[1];
  1302. if (length && $value === undefined) return $delete(this, name);
  1303. var entries = [];
  1304. forEach(this, function (v, k) { // also validates `this`
  1305. push(entries, { key: k, value: v });
  1306. });
  1307. validateArgumentsLength(length, 1);
  1308. var key = toString(name);
  1309. var value = toString($value);
  1310. var index = 0;
  1311. var dindex = 0;
  1312. var found = false;
  1313. var entriesLength = entries.length;
  1314. var entry;
  1315. while (index < entriesLength) {
  1316. entry = entries[index++];
  1317. if (found || entry.key === key) {
  1318. found = true;
  1319. $delete(this, entry.key);
  1320. } else dindex++;
  1321. }
  1322. while (dindex < entriesLength) {
  1323. entry = entries[dindex++];
  1324. if (!(entry.key === key && entry.value === value)) append(this, entry.key, entry.value);
  1325. }
  1326. }, { enumerable: true, unsafe: true });
  1327. }
  1328. /***/ }),
  1329. /***/ 4628:
  1330. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  1331. var $ = __webpack_require__(6518);
  1332. var newPromiseCapabilityModule = __webpack_require__(6043);
  1333. // `Promise.withResolvers` method
  1334. // https://tc39.es/ecma262/#sec-promise.withResolvers
  1335. $({ target: 'Promise', stat: true }, {
  1336. withResolvers: function withResolvers() {
  1337. var promiseCapability = newPromiseCapabilityModule.f(this);
  1338. return {
  1339. promise: promiseCapability.promise,
  1340. resolve: promiseCapability.resolve,
  1341. reject: promiseCapability.reject
  1342. };
  1343. }
  1344. });
  1345. /***/ }),
  1346. /***/ 4659:
  1347. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1348. var DESCRIPTORS = __webpack_require__(3724);
  1349. var definePropertyModule = __webpack_require__(4913);
  1350. var createPropertyDescriptor = __webpack_require__(6980);
  1351. module.exports = function (object, key, value) {
  1352. if (DESCRIPTORS) definePropertyModule.f(object, key, createPropertyDescriptor(0, value));
  1353. else object[key] = value;
  1354. };
  1355. /***/ }),
  1356. /***/ 4901:
  1357. /***/ ((module) => {
  1358. // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
  1359. var documentAll = typeof document == 'object' && document.all;
  1360. // `IsCallable` abstract operation
  1361. // https://tc39.es/ecma262/#sec-iscallable
  1362. // eslint-disable-next-line unicorn/no-typeof-undefined -- required for testing
  1363. module.exports = typeof documentAll == 'undefined' && documentAll !== undefined ? function (argument) {
  1364. return typeof argument == 'function' || argument === documentAll;
  1365. } : function (argument) {
  1366. return typeof argument == 'function';
  1367. };
  1368. /***/ }),
  1369. /***/ 4913:
  1370. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1371. var DESCRIPTORS = __webpack_require__(3724);
  1372. var IE8_DOM_DEFINE = __webpack_require__(5917);
  1373. var V8_PROTOTYPE_DEFINE_BUG = __webpack_require__(8686);
  1374. var anObject = __webpack_require__(8551);
  1375. var toPropertyKey = __webpack_require__(6969);
  1376. var $TypeError = TypeError;
  1377. // eslint-disable-next-line es/no-object-defineproperty -- safe
  1378. var $defineProperty = Object.defineProperty;
  1379. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  1380. var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  1381. var ENUMERABLE = 'enumerable';
  1382. var CONFIGURABLE = 'configurable';
  1383. var WRITABLE = 'writable';
  1384. // `Object.defineProperty` method
  1385. // https://tc39.es/ecma262/#sec-object.defineproperty
  1386. exports.f = DESCRIPTORS ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) {
  1387. anObject(O);
  1388. P = toPropertyKey(P);
  1389. anObject(Attributes);
  1390. if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) {
  1391. var current = $getOwnPropertyDescriptor(O, P);
  1392. if (current && current[WRITABLE]) {
  1393. O[P] = Attributes.value;
  1394. Attributes = {
  1395. configurable: CONFIGURABLE in Attributes ? Attributes[CONFIGURABLE] : current[CONFIGURABLE],
  1396. enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE],
  1397. writable: false
  1398. };
  1399. }
  1400. } return $defineProperty(O, P, Attributes);
  1401. } : $defineProperty : function defineProperty(O, P, Attributes) {
  1402. anObject(O);
  1403. P = toPropertyKey(P);
  1404. anObject(Attributes);
  1405. if (IE8_DOM_DEFINE) try {
  1406. return $defineProperty(O, P, Attributes);
  1407. } catch (error) { /* empty */ }
  1408. if ('get' in Attributes || 'set' in Attributes) throw new $TypeError('Accessors not supported');
  1409. if ('value' in Attributes) O[P] = Attributes.value;
  1410. return O;
  1411. };
  1412. /***/ }),
  1413. /***/ 4916:
  1414. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1415. var getBuiltIn = __webpack_require__(7751);
  1416. var createSetLike = function (size) {
  1417. return {
  1418. size: size,
  1419. has: function () {
  1420. return false;
  1421. },
  1422. keys: function () {
  1423. return {
  1424. next: function () {
  1425. return { done: true };
  1426. }
  1427. };
  1428. }
  1429. };
  1430. };
  1431. var createSetLikeWithInfinitySize = function (size) {
  1432. return {
  1433. size: size,
  1434. has: function () {
  1435. return true;
  1436. },
  1437. keys: function () {
  1438. throw new Error('e');
  1439. }
  1440. };
  1441. };
  1442. module.exports = function (name, callback) {
  1443. var Set = getBuiltIn('Set');
  1444. try {
  1445. new Set()[name](createSetLike(0));
  1446. try {
  1447. // late spec change, early WebKit ~ Safari 17 implementation does not pass it
  1448. // https://github.com/tc39/proposal-set-methods/pull/88
  1449. // also covered engines with
  1450. // https://bugs.webkit.org/show_bug.cgi?id=272679
  1451. new Set()[name](createSetLike(-1));
  1452. return false;
  1453. } catch (error2) {
  1454. if (!callback) return true;
  1455. // early V8 implementation bug
  1456. // https://issues.chromium.org/issues/351332634
  1457. try {
  1458. new Set()[name](createSetLikeWithInfinitySize(-Infinity));
  1459. return false;
  1460. } catch (error) {
  1461. var set = new Set();
  1462. set.add(1);
  1463. set.add(2);
  1464. return callback(set[name](createSetLikeWithInfinitySize(Infinity)));
  1465. }
  1466. }
  1467. } catch (error) {
  1468. return false;
  1469. }
  1470. };
  1471. /***/ }),
  1472. /***/ 5024:
  1473. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  1474. var $ = __webpack_require__(6518);
  1475. var symmetricDifference = __webpack_require__(3650);
  1476. var setMethodAcceptSetLike = __webpack_require__(4916);
  1477. // `Set.prototype.symmetricDifference` method
  1478. // https://tc39.es/ecma262/#sec-set.prototype.symmetricdifference
  1479. $({ target: 'Set', proto: true, real: true, forced: !setMethodAcceptSetLike('symmetricDifference') }, {
  1480. symmetricDifference: symmetricDifference
  1481. });
  1482. /***/ }),
  1483. /***/ 5031:
  1484. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1485. var getBuiltIn = __webpack_require__(7751);
  1486. var uncurryThis = __webpack_require__(9504);
  1487. var getOwnPropertyNamesModule = __webpack_require__(8480);
  1488. var getOwnPropertySymbolsModule = __webpack_require__(3717);
  1489. var anObject = __webpack_require__(8551);
  1490. var concat = uncurryThis([].concat);
  1491. // all object keys, includes non-enumerable and symbols
  1492. module.exports = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
  1493. var keys = getOwnPropertyNamesModule.f(anObject(it));
  1494. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  1495. return getOwnPropertySymbols ? concat(keys, getOwnPropertySymbols(it)) : keys;
  1496. };
  1497. /***/ }),
  1498. /***/ 5169:
  1499. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1500. var isDetached = __webpack_require__(3238);
  1501. var $TypeError = TypeError;
  1502. module.exports = function (it) {
  1503. if (isDetached(it)) throw new $TypeError('ArrayBuffer is detached');
  1504. return it;
  1505. };
  1506. /***/ }),
  1507. /***/ 5170:
  1508. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1509. var uncurryThisAccessor = __webpack_require__(6706);
  1510. var SetHelpers = __webpack_require__(4402);
  1511. module.exports = uncurryThisAccessor(SetHelpers.proto, 'size', 'get') || function (set) {
  1512. return set.size;
  1513. };
  1514. /***/ }),
  1515. /***/ 5397:
  1516. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1517. // toObject with fallback for non-array-like ES3 strings
  1518. var IndexedObject = __webpack_require__(7055);
  1519. var requireObjectCoercible = __webpack_require__(7750);
  1520. module.exports = function (it) {
  1521. return IndexedObject(requireObjectCoercible(it));
  1522. };
  1523. /***/ }),
  1524. /***/ 5610:
  1525. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1526. var toIntegerOrInfinity = __webpack_require__(1291);
  1527. var max = Math.max;
  1528. var min = Math.min;
  1529. // Helper for a popular repeating case of the spec:
  1530. // Let integer be ? ToInteger(index).
  1531. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  1532. module.exports = function (index, length) {
  1533. var integer = toIntegerOrInfinity(index);
  1534. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  1535. };
  1536. /***/ }),
  1537. /***/ 5636:
  1538. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1539. var globalThis = __webpack_require__(4576);
  1540. var uncurryThis = __webpack_require__(9504);
  1541. var uncurryThisAccessor = __webpack_require__(6706);
  1542. var toIndex = __webpack_require__(7696);
  1543. var notDetached = __webpack_require__(5169);
  1544. var arrayBufferByteLength = __webpack_require__(7394);
  1545. var detachTransferable = __webpack_require__(4483);
  1546. var PROPER_STRUCTURED_CLONE_TRANSFER = __webpack_require__(1548);
  1547. var structuredClone = globalThis.structuredClone;
  1548. var ArrayBuffer = globalThis.ArrayBuffer;
  1549. var DataView = globalThis.DataView;
  1550. var min = Math.min;
  1551. var ArrayBufferPrototype = ArrayBuffer.prototype;
  1552. var DataViewPrototype = DataView.prototype;
  1553. var slice = uncurryThis(ArrayBufferPrototype.slice);
  1554. var isResizable = uncurryThisAccessor(ArrayBufferPrototype, 'resizable', 'get');
  1555. var maxByteLength = uncurryThisAccessor(ArrayBufferPrototype, 'maxByteLength', 'get');
  1556. var getInt8 = uncurryThis(DataViewPrototype.getInt8);
  1557. var setInt8 = uncurryThis(DataViewPrototype.setInt8);
  1558. module.exports = (PROPER_STRUCTURED_CLONE_TRANSFER || detachTransferable) && function (arrayBuffer, newLength, preserveResizability) {
  1559. var byteLength = arrayBufferByteLength(arrayBuffer);
  1560. var newByteLength = newLength === undefined ? byteLength : toIndex(newLength);
  1561. var fixedLength = !isResizable || !isResizable(arrayBuffer);
  1562. var newBuffer;
  1563. notDetached(arrayBuffer);
  1564. if (PROPER_STRUCTURED_CLONE_TRANSFER) {
  1565. arrayBuffer = structuredClone(arrayBuffer, { transfer: [arrayBuffer] });
  1566. if (byteLength === newByteLength && (preserveResizability || fixedLength)) return arrayBuffer;
  1567. }
  1568. if (byteLength >= newByteLength && (!preserveResizability || fixedLength)) {
  1569. newBuffer = slice(arrayBuffer, 0, newByteLength);
  1570. } else {
  1571. var options = preserveResizability && !fixedLength && maxByteLength ? { maxByteLength: maxByteLength(arrayBuffer) } : undefined;
  1572. newBuffer = new ArrayBuffer(newByteLength, options);
  1573. var a = new DataView(arrayBuffer);
  1574. var b = new DataView(newBuffer);
  1575. var copyLength = min(newByteLength, byteLength);
  1576. for (var i = 0; i < copyLength; i++) setInt8(b, i, getInt8(a, i));
  1577. }
  1578. if (!PROPER_STRUCTURED_CLONE_TRANSFER) detachTransferable(arrayBuffer);
  1579. return newBuffer;
  1580. };
  1581. /***/ }),
  1582. /***/ 5745:
  1583. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1584. var store = __webpack_require__(7629);
  1585. module.exports = function (key, value) {
  1586. return store[key] || (store[key] = value || {});
  1587. };
  1588. /***/ }),
  1589. /***/ 5781:
  1590. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  1591. var $ = __webpack_require__(6518);
  1592. var getBuiltIn = __webpack_require__(7751);
  1593. var validateArgumentsLength = __webpack_require__(2812);
  1594. var toString = __webpack_require__(655);
  1595. var USE_NATIVE_URL = __webpack_require__(7416);
  1596. var URL = getBuiltIn('URL');
  1597. // `URL.parse` method
  1598. // https://url.spec.whatwg.org/#dom-url-canparse
  1599. $({ target: 'URL', stat: true, forced: !USE_NATIVE_URL }, {
  1600. parse: function parse(url) {
  1601. var length = validateArgumentsLength(arguments.length, 1);
  1602. var urlString = toString(url);
  1603. var base = length < 2 || arguments[1] === undefined ? undefined : toString(arguments[1]);
  1604. try {
  1605. return new URL(urlString, base);
  1606. } catch (error) {
  1607. return null;
  1608. }
  1609. }
  1610. });
  1611. /***/ }),
  1612. /***/ 5876:
  1613. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  1614. var $ = __webpack_require__(6518);
  1615. var isSubsetOf = __webpack_require__(3838);
  1616. var setMethodAcceptSetLike = __webpack_require__(4916);
  1617. var INCORRECT = !setMethodAcceptSetLike('isSubsetOf', function (result) {
  1618. return result;
  1619. });
  1620. // `Set.prototype.isSubsetOf` method
  1621. // https://tc39.es/ecma262/#sec-set.prototype.issubsetof
  1622. $({ target: 'Set', proto: true, real: true, forced: INCORRECT }, {
  1623. isSubsetOf: isSubsetOf
  1624. });
  1625. /***/ }),
  1626. /***/ 5917:
  1627. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1628. var DESCRIPTORS = __webpack_require__(3724);
  1629. var fails = __webpack_require__(9039);
  1630. var createElement = __webpack_require__(4055);
  1631. // Thanks to IE8 for its funny defineProperty
  1632. module.exports = !DESCRIPTORS && !fails(function () {
  1633. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  1634. return Object.defineProperty(createElement('div'), 'a', {
  1635. get: function () { return 7; }
  1636. }).a !== 7;
  1637. });
  1638. /***/ }),
  1639. /***/ 5966:
  1640. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1641. var aCallable = __webpack_require__(9306);
  1642. var isNullOrUndefined = __webpack_require__(4117);
  1643. // `GetMethod` abstract operation
  1644. // https://tc39.es/ecma262/#sec-getmethod
  1645. module.exports = function (V, P) {
  1646. var func = V[P];
  1647. return isNullOrUndefined(func) ? undefined : aCallable(func);
  1648. };
  1649. /***/ }),
  1650. /***/ 6043:
  1651. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1652. var aCallable = __webpack_require__(9306);
  1653. var $TypeError = TypeError;
  1654. var PromiseCapability = function (C) {
  1655. var resolve, reject;
  1656. this.promise = new C(function ($$resolve, $$reject) {
  1657. if (resolve !== undefined || reject !== undefined) throw new $TypeError('Bad Promise constructor');
  1658. resolve = $$resolve;
  1659. reject = $$reject;
  1660. });
  1661. this.resolve = aCallable(resolve);
  1662. this.reject = aCallable(reject);
  1663. };
  1664. // `NewPromiseCapability` abstract operation
  1665. // https://tc39.es/ecma262/#sec-newpromisecapability
  1666. module.exports.f = function (C) {
  1667. return new PromiseCapability(C);
  1668. };
  1669. /***/ }),
  1670. /***/ 6080:
  1671. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1672. var uncurryThis = __webpack_require__(7476);
  1673. var aCallable = __webpack_require__(9306);
  1674. var NATIVE_BIND = __webpack_require__(616);
  1675. var bind = uncurryThis(uncurryThis.bind);
  1676. // optional / simple context binding
  1677. module.exports = function (fn, that) {
  1678. aCallable(fn);
  1679. return that === undefined ? fn : NATIVE_BIND ? bind(fn, that) : function (/* ...args */) {
  1680. return fn.apply(that, arguments);
  1681. };
  1682. };
  1683. /***/ }),
  1684. /***/ 6119:
  1685. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1686. var shared = __webpack_require__(5745);
  1687. var uid = __webpack_require__(3392);
  1688. var keys = shared('keys');
  1689. module.exports = function (key) {
  1690. return keys[key] || (keys[key] = uid(key));
  1691. };
  1692. /***/ }),
  1693. /***/ 6193:
  1694. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1695. var ENVIRONMENT = __webpack_require__(4215);
  1696. module.exports = ENVIRONMENT === 'NODE';
  1697. /***/ }),
  1698. /***/ 6198:
  1699. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1700. var toLength = __webpack_require__(8014);
  1701. // `LengthOfArrayLike` abstract operation
  1702. // https://tc39.es/ecma262/#sec-lengthofarraylike
  1703. module.exports = function (obj) {
  1704. return toLength(obj.length);
  1705. };
  1706. /***/ }),
  1707. /***/ 6269:
  1708. /***/ ((module) => {
  1709. module.exports = {};
  1710. /***/ }),
  1711. /***/ 6279:
  1712. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1713. var defineBuiltIn = __webpack_require__(6840);
  1714. module.exports = function (target, src, options) {
  1715. for (var key in src) defineBuiltIn(target, key, src[key], options);
  1716. return target;
  1717. };
  1718. /***/ }),
  1719. /***/ 6319:
  1720. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1721. var anObject = __webpack_require__(8551);
  1722. var iteratorClose = __webpack_require__(9539);
  1723. // call something on iterator step with safe closing on error
  1724. module.exports = function (iterator, fn, value, ENTRIES) {
  1725. try {
  1726. return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);
  1727. } catch (error) {
  1728. iteratorClose(iterator, 'throw', error);
  1729. }
  1730. };
  1731. /***/ }),
  1732. /***/ 6395:
  1733. /***/ ((module) => {
  1734. module.exports = false;
  1735. /***/ }),
  1736. /***/ 6518:
  1737. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1738. var globalThis = __webpack_require__(4576);
  1739. var getOwnPropertyDescriptor = (__webpack_require__(7347).f);
  1740. var createNonEnumerableProperty = __webpack_require__(6699);
  1741. var defineBuiltIn = __webpack_require__(6840);
  1742. var defineGlobalProperty = __webpack_require__(9433);
  1743. var copyConstructorProperties = __webpack_require__(7740);
  1744. var isForced = __webpack_require__(2796);
  1745. /*
  1746. options.target - name of the target object
  1747. options.global - target is the global object
  1748. options.stat - export as static methods of target
  1749. options.proto - export as prototype methods of target
  1750. options.real - real prototype method for the `pure` version
  1751. options.forced - export even if the native feature is available
  1752. options.bind - bind methods to the target, required for the `pure` version
  1753. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  1754. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  1755. options.sham - add a flag to not completely full polyfills
  1756. options.enumerable - export as enumerable property
  1757. options.dontCallGetSet - prevent calling a getter on target
  1758. options.name - the .name of the function if it does not match the key
  1759. */
  1760. module.exports = function (options, source) {
  1761. var TARGET = options.target;
  1762. var GLOBAL = options.global;
  1763. var STATIC = options.stat;
  1764. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  1765. if (GLOBAL) {
  1766. target = globalThis;
  1767. } else if (STATIC) {
  1768. target = globalThis[TARGET] || defineGlobalProperty(TARGET, {});
  1769. } else {
  1770. target = globalThis[TARGET] && globalThis[TARGET].prototype;
  1771. }
  1772. if (target) for (key in source) {
  1773. sourceProperty = source[key];
  1774. if (options.dontCallGetSet) {
  1775. descriptor = getOwnPropertyDescriptor(target, key);
  1776. targetProperty = descriptor && descriptor.value;
  1777. } else targetProperty = target[key];
  1778. FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  1779. // contained in target
  1780. if (!FORCED && targetProperty !== undefined) {
  1781. if (typeof sourceProperty == typeof targetProperty) continue;
  1782. copyConstructorProperties(sourceProperty, targetProperty);
  1783. }
  1784. // add a flag to not completely full polyfills
  1785. if (options.sham || (targetProperty && targetProperty.sham)) {
  1786. createNonEnumerableProperty(sourceProperty, 'sham', true);
  1787. }
  1788. defineBuiltIn(target, key, sourceProperty, options);
  1789. }
  1790. };
  1791. /***/ }),
  1792. /***/ 6573:
  1793. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  1794. var DESCRIPTORS = __webpack_require__(3724);
  1795. var defineBuiltInAccessor = __webpack_require__(2106);
  1796. var isDetached = __webpack_require__(3238);
  1797. var ArrayBufferPrototype = ArrayBuffer.prototype;
  1798. // `ArrayBuffer.prototype.detached` getter
  1799. // https://tc39.es/ecma262/#sec-get-arraybuffer.prototype.detached
  1800. if (DESCRIPTORS && !('detached' in ArrayBufferPrototype)) {
  1801. defineBuiltInAccessor(ArrayBufferPrototype, 'detached', {
  1802. configurable: true,
  1803. get: function detached() {
  1804. return isDetached(this);
  1805. }
  1806. });
  1807. }
  1808. /***/ }),
  1809. /***/ 6699:
  1810. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1811. var DESCRIPTORS = __webpack_require__(3724);
  1812. var definePropertyModule = __webpack_require__(4913);
  1813. var createPropertyDescriptor = __webpack_require__(6980);
  1814. module.exports = DESCRIPTORS ? function (object, key, value) {
  1815. return definePropertyModule.f(object, key, createPropertyDescriptor(1, value));
  1816. } : function (object, key, value) {
  1817. object[key] = value;
  1818. return object;
  1819. };
  1820. /***/ }),
  1821. /***/ 6706:
  1822. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1823. var uncurryThis = __webpack_require__(9504);
  1824. var aCallable = __webpack_require__(9306);
  1825. module.exports = function (object, key, method) {
  1826. try {
  1827. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  1828. return uncurryThis(aCallable(Object.getOwnPropertyDescriptor(object, key)[method]));
  1829. } catch (error) { /* empty */ }
  1830. };
  1831. /***/ }),
  1832. /***/ 6801:
  1833. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1834. var DESCRIPTORS = __webpack_require__(3724);
  1835. var V8_PROTOTYPE_DEFINE_BUG = __webpack_require__(8686);
  1836. var definePropertyModule = __webpack_require__(4913);
  1837. var anObject = __webpack_require__(8551);
  1838. var toIndexedObject = __webpack_require__(5397);
  1839. var objectKeys = __webpack_require__(1072);
  1840. // `Object.defineProperties` method
  1841. // https://tc39.es/ecma262/#sec-object.defineproperties
  1842. // eslint-disable-next-line es/no-object-defineproperties -- safe
  1843. exports.f = DESCRIPTORS && !V8_PROTOTYPE_DEFINE_BUG ? Object.defineProperties : function defineProperties(O, Properties) {
  1844. anObject(O);
  1845. var props = toIndexedObject(Properties);
  1846. var keys = objectKeys(Properties);
  1847. var length = keys.length;
  1848. var index = 0;
  1849. var key;
  1850. while (length > index) definePropertyModule.f(O, key = keys[index++], props[key]);
  1851. return O;
  1852. };
  1853. /***/ }),
  1854. /***/ 6823:
  1855. /***/ ((module) => {
  1856. var $String = String;
  1857. module.exports = function (argument) {
  1858. try {
  1859. return $String(argument);
  1860. } catch (error) {
  1861. return 'Object';
  1862. }
  1863. };
  1864. /***/ }),
  1865. /***/ 6837:
  1866. /***/ ((module) => {
  1867. var $TypeError = TypeError;
  1868. var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; // 2 ** 53 - 1 == 9007199254740991
  1869. module.exports = function (it) {
  1870. if (it > MAX_SAFE_INTEGER) throw $TypeError('Maximum allowed index exceeded');
  1871. return it;
  1872. };
  1873. /***/ }),
  1874. /***/ 6840:
  1875. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1876. var isCallable = __webpack_require__(4901);
  1877. var definePropertyModule = __webpack_require__(4913);
  1878. var makeBuiltIn = __webpack_require__(283);
  1879. var defineGlobalProperty = __webpack_require__(9433);
  1880. module.exports = function (O, key, value, options) {
  1881. if (!options) options = {};
  1882. var simple = options.enumerable;
  1883. var name = options.name !== undefined ? options.name : key;
  1884. if (isCallable(value)) makeBuiltIn(value, name, options);
  1885. if (options.global) {
  1886. if (simple) O[key] = value;
  1887. else defineGlobalProperty(key, value);
  1888. } else {
  1889. try {
  1890. if (!options.unsafe) delete O[key];
  1891. else if (O[key]) simple = true;
  1892. } catch (error) { /* empty */ }
  1893. if (simple) O[key] = value;
  1894. else definePropertyModule.f(O, key, {
  1895. value: value,
  1896. enumerable: false,
  1897. configurable: !options.nonConfigurable,
  1898. writable: !options.nonWritable
  1899. });
  1900. } return O;
  1901. };
  1902. /***/ }),
  1903. /***/ 6955:
  1904. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1905. var TO_STRING_TAG_SUPPORT = __webpack_require__(2140);
  1906. var isCallable = __webpack_require__(4901);
  1907. var classofRaw = __webpack_require__(2195);
  1908. var wellKnownSymbol = __webpack_require__(8227);
  1909. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  1910. var $Object = Object;
  1911. // ES3 wrong here
  1912. var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) === 'Arguments';
  1913. // fallback for IE11 Script Access Denied error
  1914. var tryGet = function (it, key) {
  1915. try {
  1916. return it[key];
  1917. } catch (error) { /* empty */ }
  1918. };
  1919. // getting tag from ES6+ `Object.prototype.toString`
  1920. module.exports = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) {
  1921. var O, tag, result;
  1922. return it === undefined ? 'Undefined' : it === null ? 'Null'
  1923. // @@toStringTag case
  1924. : typeof (tag = tryGet(O = $Object(it), TO_STRING_TAG)) == 'string' ? tag
  1925. // builtinTag case
  1926. : CORRECT_ARGUMENTS ? classofRaw(O)
  1927. // ES3 arguments fallback
  1928. : (result = classofRaw(O)) === 'Object' && isCallable(O.callee) ? 'Arguments' : result;
  1929. };
  1930. /***/ }),
  1931. /***/ 6969:
  1932. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1933. var toPrimitive = __webpack_require__(2777);
  1934. var isSymbol = __webpack_require__(757);
  1935. // `ToPropertyKey` abstract operation
  1936. // https://tc39.es/ecma262/#sec-topropertykey
  1937. module.exports = function (argument) {
  1938. var key = toPrimitive(argument, 'string');
  1939. return isSymbol(key) ? key : key + '';
  1940. };
  1941. /***/ }),
  1942. /***/ 6980:
  1943. /***/ ((module) => {
  1944. module.exports = function (bitmap, value) {
  1945. return {
  1946. enumerable: !(bitmap & 1),
  1947. configurable: !(bitmap & 2),
  1948. writable: !(bitmap & 4),
  1949. value: value
  1950. };
  1951. };
  1952. /***/ }),
  1953. /***/ 7040:
  1954. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1955. /* eslint-disable es/no-symbol -- required for testing */
  1956. var NATIVE_SYMBOL = __webpack_require__(4495);
  1957. module.exports = NATIVE_SYMBOL &&
  1958. !Symbol.sham &&
  1959. typeof Symbol.iterator == 'symbol';
  1960. /***/ }),
  1961. /***/ 7055:
  1962. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1963. var uncurryThis = __webpack_require__(9504);
  1964. var fails = __webpack_require__(9039);
  1965. var classof = __webpack_require__(2195);
  1966. var $Object = Object;
  1967. var split = uncurryThis(''.split);
  1968. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  1969. module.exports = fails(function () {
  1970. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  1971. // eslint-disable-next-line no-prototype-builtins -- safe
  1972. return !$Object('z').propertyIsEnumerable(0);
  1973. }) ? function (it) {
  1974. return classof(it) === 'String' ? split(it, '') : $Object(it);
  1975. } : $Object;
  1976. /***/ }),
  1977. /***/ 7080:
  1978. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1979. var has = (__webpack_require__(4402).has);
  1980. // Perform ? RequireInternalSlot(M, [[SetData]])
  1981. module.exports = function (it) {
  1982. has(it);
  1983. return it;
  1984. };
  1985. /***/ }),
  1986. /***/ 7347:
  1987. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1988. var DESCRIPTORS = __webpack_require__(3724);
  1989. var call = __webpack_require__(9565);
  1990. var propertyIsEnumerableModule = __webpack_require__(8773);
  1991. var createPropertyDescriptor = __webpack_require__(6980);
  1992. var toIndexedObject = __webpack_require__(5397);
  1993. var toPropertyKey = __webpack_require__(6969);
  1994. var hasOwn = __webpack_require__(9297);
  1995. var IE8_DOM_DEFINE = __webpack_require__(5917);
  1996. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  1997. var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  1998. // `Object.getOwnPropertyDescriptor` method
  1999. // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
  2000. exports.f = DESCRIPTORS ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  2001. O = toIndexedObject(O);
  2002. P = toPropertyKey(P);
  2003. if (IE8_DOM_DEFINE) try {
  2004. return $getOwnPropertyDescriptor(O, P);
  2005. } catch (error) { /* empty */ }
  2006. if (hasOwn(O, P)) return createPropertyDescriptor(!call(propertyIsEnumerableModule.f, O, P), O[P]);
  2007. };
  2008. /***/ }),
  2009. /***/ 7394:
  2010. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2011. var globalThis = __webpack_require__(4576);
  2012. var uncurryThisAccessor = __webpack_require__(6706);
  2013. var classof = __webpack_require__(2195);
  2014. var ArrayBuffer = globalThis.ArrayBuffer;
  2015. var TypeError = globalThis.TypeError;
  2016. // Includes
  2017. // - Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  2018. // - If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  2019. module.exports = ArrayBuffer && uncurryThisAccessor(ArrayBuffer.prototype, 'byteLength', 'get') || function (O) {
  2020. if (classof(O) !== 'ArrayBuffer') throw new TypeError('ArrayBuffer expected');
  2021. return O.byteLength;
  2022. };
  2023. /***/ }),
  2024. /***/ 7416:
  2025. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2026. var fails = __webpack_require__(9039);
  2027. var wellKnownSymbol = __webpack_require__(8227);
  2028. var DESCRIPTORS = __webpack_require__(3724);
  2029. var IS_PURE = __webpack_require__(6395);
  2030. var ITERATOR = wellKnownSymbol('iterator');
  2031. module.exports = !fails(function () {
  2032. // eslint-disable-next-line unicorn/relative-url-style -- required for testing
  2033. var url = new URL('b?a=1&b=2&c=3', 'https://a');
  2034. var params = url.searchParams;
  2035. var params2 = new URLSearchParams('a=1&a=2&b=3');
  2036. var result = '';
  2037. url.pathname = 'c%20d';
  2038. params.forEach(function (value, key) {
  2039. params['delete']('b');
  2040. result += key + value;
  2041. });
  2042. params2['delete']('a', 2);
  2043. // `undefined` case is a Chromium 117 bug
  2044. // https://bugs.chromium.org/p/v8/issues/detail?id=14222
  2045. params2['delete']('b', undefined);
  2046. return (IS_PURE && (!url.toJSON || !params2.has('a', 1) || params2.has('a', 2) || !params2.has('a', undefined) || params2.has('b')))
  2047. || (!params.size && (IS_PURE || !DESCRIPTORS))
  2048. || !params.sort
  2049. || url.href !== 'https://a/c%20d?a=1&c=3'
  2050. || params.get('c') !== '3'
  2051. || String(new URLSearchParams('?a=1')) !== 'a=1'
  2052. || !params[ITERATOR]
  2053. // throws in Edge
  2054. || new URL('https://a@b').username !== 'a'
  2055. || new URLSearchParams(new URLSearchParams('a=b')).get('a') !== 'b'
  2056. // not punycoded in Edge
  2057. || new URL('https://тест').host !== 'xn--e1aybc'
  2058. // not escaped in Chrome 62-
  2059. || new URL('https://a#б').hash !== '#%D0%B1'
  2060. // fails in Chrome 66-
  2061. || result !== 'a1c3'
  2062. // throws in Safari
  2063. || new URL('https://x', undefined).host !== 'x';
  2064. });
  2065. /***/ }),
  2066. /***/ 7476:
  2067. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2068. var classofRaw = __webpack_require__(2195);
  2069. var uncurryThis = __webpack_require__(9504);
  2070. module.exports = function (fn) {
  2071. // Nashorn bug:
  2072. // https://github.com/zloirock/core-js/issues/1128
  2073. // https://github.com/zloirock/core-js/issues/1130
  2074. if (classofRaw(fn) === 'Function') return uncurryThis(fn);
  2075. };
  2076. /***/ }),
  2077. /***/ 7566:
  2078. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  2079. var defineBuiltIn = __webpack_require__(6840);
  2080. var uncurryThis = __webpack_require__(9504);
  2081. var toString = __webpack_require__(655);
  2082. var validateArgumentsLength = __webpack_require__(2812);
  2083. var $URLSearchParams = URLSearchParams;
  2084. var URLSearchParamsPrototype = $URLSearchParams.prototype;
  2085. var getAll = uncurryThis(URLSearchParamsPrototype.getAll);
  2086. var $has = uncurryThis(URLSearchParamsPrototype.has);
  2087. var params = new $URLSearchParams('a=1');
  2088. // `undefined` case is a Chromium 117 bug
  2089. // https://bugs.chromium.org/p/v8/issues/detail?id=14222
  2090. if (params.has('a', 2) || !params.has('a', undefined)) {
  2091. defineBuiltIn(URLSearchParamsPrototype, 'has', function has(name /* , value */) {
  2092. var length = arguments.length;
  2093. var $value = length < 2 ? undefined : arguments[1];
  2094. if (length && $value === undefined) return $has(this, name);
  2095. var values = getAll(this, name); // also validates `this`
  2096. validateArgumentsLength(length, 1);
  2097. var value = toString($value);
  2098. var index = 0;
  2099. while (index < values.length) {
  2100. if (values[index++] === value) return true;
  2101. } return false;
  2102. }, { enumerable: true, unsafe: true });
  2103. }
  2104. /***/ }),
  2105. /***/ 7588:
  2106. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  2107. var $ = __webpack_require__(6518);
  2108. var call = __webpack_require__(9565);
  2109. var iterate = __webpack_require__(2652);
  2110. var aCallable = __webpack_require__(9306);
  2111. var anObject = __webpack_require__(8551);
  2112. var getIteratorDirect = __webpack_require__(1767);
  2113. var iteratorClose = __webpack_require__(9539);
  2114. var iteratorHelperWithoutClosingOnEarlyError = __webpack_require__(4549);
  2115. var forEachWithoutClosingOnEarlyError = iteratorHelperWithoutClosingOnEarlyError('forEach', TypeError);
  2116. // `Iterator.prototype.forEach` method
  2117. // https://tc39.es/ecma262/#sec-iterator.prototype.foreach
  2118. $({ target: 'Iterator', proto: true, real: true, forced: forEachWithoutClosingOnEarlyError }, {
  2119. forEach: function forEach(fn) {
  2120. anObject(this);
  2121. try {
  2122. aCallable(fn);
  2123. } catch (error) {
  2124. iteratorClose(this, 'throw', error);
  2125. }
  2126. if (forEachWithoutClosingOnEarlyError) return call(forEachWithoutClosingOnEarlyError, this, fn);
  2127. var record = getIteratorDirect(this);
  2128. var counter = 0;
  2129. iterate(record, function (value) {
  2130. fn(value, counter++);
  2131. }, { IS_RECORD: true });
  2132. }
  2133. });
  2134. /***/ }),
  2135. /***/ 7629:
  2136. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2137. var IS_PURE = __webpack_require__(6395);
  2138. var globalThis = __webpack_require__(4576);
  2139. var defineGlobalProperty = __webpack_require__(9433);
  2140. var SHARED = '__core-js_shared__';
  2141. var store = module.exports = globalThis[SHARED] || defineGlobalProperty(SHARED, {});
  2142. (store.versions || (store.versions = [])).push({
  2143. version: '3.42.0',
  2144. mode: IS_PURE ? 'pure' : 'global',
  2145. copyright: '© 2014-2025 Denis Pushkarev (zloirock.ru)',
  2146. license: 'https://github.com/zloirock/core-js/blob/v3.42.0/LICENSE',
  2147. source: 'https://github.com/zloirock/core-js'
  2148. });
  2149. /***/ }),
  2150. /***/ 7642:
  2151. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  2152. var $ = __webpack_require__(6518);
  2153. var difference = __webpack_require__(3440);
  2154. var setMethodAcceptSetLike = __webpack_require__(4916);
  2155. var INCORRECT = !setMethodAcceptSetLike('difference', function (result) {
  2156. return result.size === 0;
  2157. });
  2158. // `Set.prototype.difference` method
  2159. // https://tc39.es/ecma262/#sec-set.prototype.difference
  2160. $({ target: 'Set', proto: true, real: true, forced: INCORRECT }, {
  2161. difference: difference
  2162. });
  2163. /***/ }),
  2164. /***/ 7657:
  2165. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2166. var fails = __webpack_require__(9039);
  2167. var isCallable = __webpack_require__(4901);
  2168. var isObject = __webpack_require__(34);
  2169. var create = __webpack_require__(2360);
  2170. var getPrototypeOf = __webpack_require__(2787);
  2171. var defineBuiltIn = __webpack_require__(6840);
  2172. var wellKnownSymbol = __webpack_require__(8227);
  2173. var IS_PURE = __webpack_require__(6395);
  2174. var ITERATOR = wellKnownSymbol('iterator');
  2175. var BUGGY_SAFARI_ITERATORS = false;
  2176. // `%IteratorPrototype%` object
  2177. // https://tc39.es/ecma262/#sec-%iteratorprototype%-object
  2178. var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator;
  2179. /* eslint-disable es/no-array-prototype-keys -- safe */
  2180. if ([].keys) {
  2181. arrayIterator = [].keys();
  2182. // Safari 8 has buggy iterators w/o `next`
  2183. if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true;
  2184. else {
  2185. PrototypeOfArrayIteratorPrototype = getPrototypeOf(getPrototypeOf(arrayIterator));
  2186. if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype;
  2187. }
  2188. }
  2189. var NEW_ITERATOR_PROTOTYPE = !isObject(IteratorPrototype) || fails(function () {
  2190. var test = {};
  2191. // FF44- legacy iterators case
  2192. return IteratorPrototype[ITERATOR].call(test) !== test;
  2193. });
  2194. if (NEW_ITERATOR_PROTOTYPE) IteratorPrototype = {};
  2195. else if (IS_PURE) IteratorPrototype = create(IteratorPrototype);
  2196. // `%IteratorPrototype%[@@iterator]()` method
  2197. // https://tc39.es/ecma262/#sec-%iteratorprototype%-@@iterator
  2198. if (!isCallable(IteratorPrototype[ITERATOR])) {
  2199. defineBuiltIn(IteratorPrototype, ITERATOR, function () {
  2200. return this;
  2201. });
  2202. }
  2203. module.exports = {
  2204. IteratorPrototype: IteratorPrototype,
  2205. BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS
  2206. };
  2207. /***/ }),
  2208. /***/ 7696:
  2209. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2210. var toIntegerOrInfinity = __webpack_require__(1291);
  2211. var toLength = __webpack_require__(8014);
  2212. var $RangeError = RangeError;
  2213. // `ToIndex` abstract operation
  2214. // https://tc39.es/ecma262/#sec-toindex
  2215. module.exports = function (it) {
  2216. if (it === undefined) return 0;
  2217. var number = toIntegerOrInfinity(it);
  2218. var length = toLength(number);
  2219. if (number !== length) throw new $RangeError('Wrong length or index');
  2220. return length;
  2221. };
  2222. /***/ }),
  2223. /***/ 7740:
  2224. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2225. var hasOwn = __webpack_require__(9297);
  2226. var ownKeys = __webpack_require__(5031);
  2227. var getOwnPropertyDescriptorModule = __webpack_require__(7347);
  2228. var definePropertyModule = __webpack_require__(4913);
  2229. module.exports = function (target, source, exceptions) {
  2230. var keys = ownKeys(source);
  2231. var defineProperty = definePropertyModule.f;
  2232. var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  2233. for (var i = 0; i < keys.length; i++) {
  2234. var key = keys[i];
  2235. if (!hasOwn(target, key) && !(exceptions && hasOwn(exceptions, key))) {
  2236. defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  2237. }
  2238. }
  2239. };
  2240. /***/ }),
  2241. /***/ 7750:
  2242. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2243. var isNullOrUndefined = __webpack_require__(4117);
  2244. var $TypeError = TypeError;
  2245. // `RequireObjectCoercible` abstract operation
  2246. // https://tc39.es/ecma262/#sec-requireobjectcoercible
  2247. module.exports = function (it) {
  2248. if (isNullOrUndefined(it)) throw new $TypeError("Can't call method on " + it);
  2249. return it;
  2250. };
  2251. /***/ }),
  2252. /***/ 7751:
  2253. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2254. var globalThis = __webpack_require__(4576);
  2255. var isCallable = __webpack_require__(4901);
  2256. var aFunction = function (argument) {
  2257. return isCallable(argument) ? argument : undefined;
  2258. };
  2259. module.exports = function (namespace, method) {
  2260. return arguments.length < 2 ? aFunction(globalThis[namespace]) : globalThis[namespace] && globalThis[namespace][method];
  2261. };
  2262. /***/ }),
  2263. /***/ 7811:
  2264. /***/ ((module) => {
  2265. // eslint-disable-next-line es/no-typed-arrays -- safe
  2266. module.exports = typeof ArrayBuffer != 'undefined' && typeof DataView != 'undefined';
  2267. /***/ }),
  2268. /***/ 7936:
  2269. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  2270. var $ = __webpack_require__(6518);
  2271. var $transfer = __webpack_require__(5636);
  2272. // `ArrayBuffer.prototype.transferToFixedLength` method
  2273. // https://tc39.es/proposal-arraybuffer-transfer/#sec-arraybuffer.prototype.transfertofixedlength
  2274. if ($transfer) $({ target: 'ArrayBuffer', proto: true }, {
  2275. transferToFixedLength: function transferToFixedLength() {
  2276. return $transfer(this, arguments.length ? arguments[0] : undefined, false);
  2277. }
  2278. });
  2279. /***/ }),
  2280. /***/ 8004:
  2281. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  2282. var $ = __webpack_require__(6518);
  2283. var fails = __webpack_require__(9039);
  2284. var intersection = __webpack_require__(8750);
  2285. var setMethodAcceptSetLike = __webpack_require__(4916);
  2286. var INCORRECT = !setMethodAcceptSetLike('intersection', function (result) {
  2287. return result.size === 2 && result.has(1) && result.has(2);
  2288. }) || fails(function () {
  2289. // eslint-disable-next-line es/no-array-from, es/no-set, es/no-set-prototype-intersection -- testing
  2290. return String(Array.from(new Set([1, 2, 3]).intersection(new Set([3, 2])))) !== '3,2';
  2291. });
  2292. // `Set.prototype.intersection` method
  2293. // https://tc39.es/ecma262/#sec-set.prototype.intersection
  2294. $({ target: 'Set', proto: true, real: true, forced: INCORRECT }, {
  2295. intersection: intersection
  2296. });
  2297. /***/ }),
  2298. /***/ 8014:
  2299. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2300. var toIntegerOrInfinity = __webpack_require__(1291);
  2301. var min = Math.min;
  2302. // `ToLength` abstract operation
  2303. // https://tc39.es/ecma262/#sec-tolength
  2304. module.exports = function (argument) {
  2305. var len = toIntegerOrInfinity(argument);
  2306. return len > 0 ? min(len, 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
  2307. };
  2308. /***/ }),
  2309. /***/ 8100:
  2310. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  2311. var $ = __webpack_require__(6518);
  2312. var $transfer = __webpack_require__(5636);
  2313. // `ArrayBuffer.prototype.transfer` method
  2314. // https://tc39.es/proposal-arraybuffer-transfer/#sec-arraybuffer.prototype.transfer
  2315. if ($transfer) $({ target: 'ArrayBuffer', proto: true }, {
  2316. transfer: function transfer() {
  2317. return $transfer(this, arguments.length ? arguments[0] : undefined, true);
  2318. }
  2319. });
  2320. /***/ }),
  2321. /***/ 8111:
  2322. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  2323. var $ = __webpack_require__(6518);
  2324. var globalThis = __webpack_require__(4576);
  2325. var anInstance = __webpack_require__(679);
  2326. var anObject = __webpack_require__(8551);
  2327. var isCallable = __webpack_require__(4901);
  2328. var getPrototypeOf = __webpack_require__(2787);
  2329. var defineBuiltInAccessor = __webpack_require__(2106);
  2330. var createProperty = __webpack_require__(4659);
  2331. var fails = __webpack_require__(9039);
  2332. var hasOwn = __webpack_require__(9297);
  2333. var wellKnownSymbol = __webpack_require__(8227);
  2334. var IteratorPrototype = (__webpack_require__(7657).IteratorPrototype);
  2335. var DESCRIPTORS = __webpack_require__(3724);
  2336. var IS_PURE = __webpack_require__(6395);
  2337. var CONSTRUCTOR = 'constructor';
  2338. var ITERATOR = 'Iterator';
  2339. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  2340. var $TypeError = TypeError;
  2341. var NativeIterator = globalThis[ITERATOR];
  2342. // FF56- have non-standard global helper `Iterator`
  2343. var FORCED = IS_PURE
  2344. || !isCallable(NativeIterator)
  2345. || NativeIterator.prototype !== IteratorPrototype
  2346. // FF44- non-standard `Iterator` passes previous tests
  2347. || !fails(function () { NativeIterator({}); });
  2348. var IteratorConstructor = function Iterator() {
  2349. anInstance(this, IteratorPrototype);
  2350. if (getPrototypeOf(this) === IteratorPrototype) throw new $TypeError('Abstract class Iterator not directly constructable');
  2351. };
  2352. var defineIteratorPrototypeAccessor = function (key, value) {
  2353. if (DESCRIPTORS) {
  2354. defineBuiltInAccessor(IteratorPrototype, key, {
  2355. configurable: true,
  2356. get: function () {
  2357. return value;
  2358. },
  2359. set: function (replacement) {
  2360. anObject(this);
  2361. if (this === IteratorPrototype) throw new $TypeError("You can't redefine this property");
  2362. if (hasOwn(this, key)) this[key] = replacement;
  2363. else createProperty(this, key, replacement);
  2364. }
  2365. });
  2366. } else IteratorPrototype[key] = value;
  2367. };
  2368. if (!hasOwn(IteratorPrototype, TO_STRING_TAG)) defineIteratorPrototypeAccessor(TO_STRING_TAG, ITERATOR);
  2369. if (FORCED || !hasOwn(IteratorPrototype, CONSTRUCTOR) || IteratorPrototype[CONSTRUCTOR] === Object) {
  2370. defineIteratorPrototypeAccessor(CONSTRUCTOR, IteratorConstructor);
  2371. }
  2372. IteratorConstructor.prototype = IteratorPrototype;
  2373. // `Iterator` constructor
  2374. // https://tc39.es/ecma262/#sec-iterator
  2375. $({ global: true, constructor: true, forced: FORCED }, {
  2376. Iterator: IteratorConstructor
  2377. });
  2378. /***/ }),
  2379. /***/ 8227:
  2380. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2381. var globalThis = __webpack_require__(4576);
  2382. var shared = __webpack_require__(5745);
  2383. var hasOwn = __webpack_require__(9297);
  2384. var uid = __webpack_require__(3392);
  2385. var NATIVE_SYMBOL = __webpack_require__(4495);
  2386. var USE_SYMBOL_AS_UID = __webpack_require__(7040);
  2387. var Symbol = globalThis.Symbol;
  2388. var WellKnownSymbolsStore = shared('wks');
  2389. var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol['for'] || Symbol : Symbol && Symbol.withoutSetter || uid;
  2390. module.exports = function (name) {
  2391. if (!hasOwn(WellKnownSymbolsStore, name)) {
  2392. WellKnownSymbolsStore[name] = NATIVE_SYMBOL && hasOwn(Symbol, name)
  2393. ? Symbol[name]
  2394. : createWellKnownSymbol('Symbol.' + name);
  2395. } return WellKnownSymbolsStore[name];
  2396. };
  2397. /***/ }),
  2398. /***/ 8235:
  2399. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2400. var uncurryThis = __webpack_require__(9504);
  2401. var hasOwn = __webpack_require__(9297);
  2402. var $SyntaxError = SyntaxError;
  2403. var $parseInt = parseInt;
  2404. var fromCharCode = String.fromCharCode;
  2405. var at = uncurryThis(''.charAt);
  2406. var slice = uncurryThis(''.slice);
  2407. var exec = uncurryThis(/./.exec);
  2408. var codePoints = {
  2409. '\\"': '"',
  2410. '\\\\': '\\',
  2411. '\\/': '/',
  2412. '\\b': '\b',
  2413. '\\f': '\f',
  2414. '\\n': '\n',
  2415. '\\r': '\r',
  2416. '\\t': '\t'
  2417. };
  2418. var IS_4_HEX_DIGITS = /^[\da-f]{4}$/i;
  2419. // eslint-disable-next-line regexp/no-control-character -- safe
  2420. var IS_C0_CONTROL_CODE = /^[\u0000-\u001F]$/;
  2421. module.exports = function (source, i) {
  2422. var unterminated = true;
  2423. var value = '';
  2424. while (i < source.length) {
  2425. var chr = at(source, i);
  2426. if (chr === '\\') {
  2427. var twoChars = slice(source, i, i + 2);
  2428. if (hasOwn(codePoints, twoChars)) {
  2429. value += codePoints[twoChars];
  2430. i += 2;
  2431. } else if (twoChars === '\\u') {
  2432. i += 2;
  2433. var fourHexDigits = slice(source, i, i + 4);
  2434. if (!exec(IS_4_HEX_DIGITS, fourHexDigits)) throw new $SyntaxError('Bad Unicode escape at: ' + i);
  2435. value += fromCharCode($parseInt(fourHexDigits, 16));
  2436. i += 4;
  2437. } else throw new $SyntaxError('Unknown escape sequence: "' + twoChars + '"');
  2438. } else if (chr === '"') {
  2439. unterminated = false;
  2440. i++;
  2441. break;
  2442. } else {
  2443. if (exec(IS_C0_CONTROL_CODE, chr)) throw new $SyntaxError('Bad control character in string literal at: ' + i);
  2444. value += chr;
  2445. i++;
  2446. }
  2447. }
  2448. if (unterminated) throw new $SyntaxError('Unterminated string at: ' + i);
  2449. return { value: value, end: i };
  2450. };
  2451. /***/ }),
  2452. /***/ 8335:
  2453. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  2454. var $ = __webpack_require__(6518);
  2455. var DESCRIPTORS = __webpack_require__(3724);
  2456. var globalThis = __webpack_require__(4576);
  2457. var getBuiltIn = __webpack_require__(7751);
  2458. var uncurryThis = __webpack_require__(9504);
  2459. var call = __webpack_require__(9565);
  2460. var isCallable = __webpack_require__(4901);
  2461. var isObject = __webpack_require__(34);
  2462. var isArray = __webpack_require__(4376);
  2463. var hasOwn = __webpack_require__(9297);
  2464. var toString = __webpack_require__(655);
  2465. var lengthOfArrayLike = __webpack_require__(6198);
  2466. var createProperty = __webpack_require__(4659);
  2467. var fails = __webpack_require__(9039);
  2468. var parseJSONString = __webpack_require__(8235);
  2469. var NATIVE_SYMBOL = __webpack_require__(4495);
  2470. var JSON = globalThis.JSON;
  2471. var Number = globalThis.Number;
  2472. var SyntaxError = globalThis.SyntaxError;
  2473. var nativeParse = JSON && JSON.parse;
  2474. var enumerableOwnProperties = getBuiltIn('Object', 'keys');
  2475. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  2476. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  2477. var at = uncurryThis(''.charAt);
  2478. var slice = uncurryThis(''.slice);
  2479. var exec = uncurryThis(/./.exec);
  2480. var push = uncurryThis([].push);
  2481. var IS_DIGIT = /^\d$/;
  2482. var IS_NON_ZERO_DIGIT = /^[1-9]$/;
  2483. var IS_NUMBER_START = /^[\d-]$/;
  2484. var IS_WHITESPACE = /^[\t\n\r ]$/;
  2485. var PRIMITIVE = 0;
  2486. var OBJECT = 1;
  2487. var $parse = function (source, reviver) {
  2488. source = toString(source);
  2489. var context = new Context(source, 0, '');
  2490. var root = context.parse();
  2491. var value = root.value;
  2492. var endIndex = context.skip(IS_WHITESPACE, root.end);
  2493. if (endIndex < source.length) {
  2494. throw new SyntaxError('Unexpected extra character: "' + at(source, endIndex) + '" after the parsed data at: ' + endIndex);
  2495. }
  2496. return isCallable(reviver) ? internalize({ '': value }, '', reviver, root) : value;
  2497. };
  2498. var internalize = function (holder, name, reviver, node) {
  2499. var val = holder[name];
  2500. var unmodified = node && val === node.value;
  2501. var context = unmodified && typeof node.source == 'string' ? { source: node.source } : {};
  2502. var elementRecordsLen, keys, len, i, P;
  2503. if (isObject(val)) {
  2504. var nodeIsArray = isArray(val);
  2505. var nodes = unmodified ? node.nodes : nodeIsArray ? [] : {};
  2506. if (nodeIsArray) {
  2507. elementRecordsLen = nodes.length;
  2508. len = lengthOfArrayLike(val);
  2509. for (i = 0; i < len; i++) {
  2510. internalizeProperty(val, i, internalize(val, '' + i, reviver, i < elementRecordsLen ? nodes[i] : undefined));
  2511. }
  2512. } else {
  2513. keys = enumerableOwnProperties(val);
  2514. len = lengthOfArrayLike(keys);
  2515. for (i = 0; i < len; i++) {
  2516. P = keys[i];
  2517. internalizeProperty(val, P, internalize(val, P, reviver, hasOwn(nodes, P) ? nodes[P] : undefined));
  2518. }
  2519. }
  2520. }
  2521. return call(reviver, holder, name, val, context);
  2522. };
  2523. var internalizeProperty = function (object, key, value) {
  2524. if (DESCRIPTORS) {
  2525. var descriptor = getOwnPropertyDescriptor(object, key);
  2526. if (descriptor && !descriptor.configurable) return;
  2527. }
  2528. if (value === undefined) delete object[key];
  2529. else createProperty(object, key, value);
  2530. };
  2531. var Node = function (value, end, source, nodes) {
  2532. this.value = value;
  2533. this.end = end;
  2534. this.source = source;
  2535. this.nodes = nodes;
  2536. };
  2537. var Context = function (source, index) {
  2538. this.source = source;
  2539. this.index = index;
  2540. };
  2541. // https://www.json.org/json-en.html
  2542. Context.prototype = {
  2543. fork: function (nextIndex) {
  2544. return new Context(this.source, nextIndex);
  2545. },
  2546. parse: function () {
  2547. var source = this.source;
  2548. var i = this.skip(IS_WHITESPACE, this.index);
  2549. var fork = this.fork(i);
  2550. var chr = at(source, i);
  2551. if (exec(IS_NUMBER_START, chr)) return fork.number();
  2552. switch (chr) {
  2553. case '{':
  2554. return fork.object();
  2555. case '[':
  2556. return fork.array();
  2557. case '"':
  2558. return fork.string();
  2559. case 't':
  2560. return fork.keyword(true);
  2561. case 'f':
  2562. return fork.keyword(false);
  2563. case 'n':
  2564. return fork.keyword(null);
  2565. } throw new SyntaxError('Unexpected character: "' + chr + '" at: ' + i);
  2566. },
  2567. node: function (type, value, start, end, nodes) {
  2568. return new Node(value, end, type ? null : slice(this.source, start, end), nodes);
  2569. },
  2570. object: function () {
  2571. var source = this.source;
  2572. var i = this.index + 1;
  2573. var expectKeypair = false;
  2574. var object = {};
  2575. var nodes = {};
  2576. while (i < source.length) {
  2577. i = this.until(['"', '}'], i);
  2578. if (at(source, i) === '}' && !expectKeypair) {
  2579. i++;
  2580. break;
  2581. }
  2582. // Parsing the key
  2583. var result = this.fork(i).string();
  2584. var key = result.value;
  2585. i = result.end;
  2586. i = this.until([':'], i) + 1;
  2587. // Parsing value
  2588. i = this.skip(IS_WHITESPACE, i);
  2589. result = this.fork(i).parse();
  2590. createProperty(nodes, key, result);
  2591. createProperty(object, key, result.value);
  2592. i = this.until([',', '}'], result.end);
  2593. var chr = at(source, i);
  2594. if (chr === ',') {
  2595. expectKeypair = true;
  2596. i++;
  2597. } else if (chr === '}') {
  2598. i++;
  2599. break;
  2600. }
  2601. }
  2602. return this.node(OBJECT, object, this.index, i, nodes);
  2603. },
  2604. array: function () {
  2605. var source = this.source;
  2606. var i = this.index + 1;
  2607. var expectElement = false;
  2608. var array = [];
  2609. var nodes = [];
  2610. while (i < source.length) {
  2611. i = this.skip(IS_WHITESPACE, i);
  2612. if (at(source, i) === ']' && !expectElement) {
  2613. i++;
  2614. break;
  2615. }
  2616. var result = this.fork(i).parse();
  2617. push(nodes, result);
  2618. push(array, result.value);
  2619. i = this.until([',', ']'], result.end);
  2620. if (at(source, i) === ',') {
  2621. expectElement = true;
  2622. i++;
  2623. } else if (at(source, i) === ']') {
  2624. i++;
  2625. break;
  2626. }
  2627. }
  2628. return this.node(OBJECT, array, this.index, i, nodes);
  2629. },
  2630. string: function () {
  2631. var index = this.index;
  2632. var parsed = parseJSONString(this.source, this.index + 1);
  2633. return this.node(PRIMITIVE, parsed.value, index, parsed.end);
  2634. },
  2635. number: function () {
  2636. var source = this.source;
  2637. var startIndex = this.index;
  2638. var i = startIndex;
  2639. if (at(source, i) === '-') i++;
  2640. if (at(source, i) === '0') i++;
  2641. else if (exec(IS_NON_ZERO_DIGIT, at(source, i))) i = this.skip(IS_DIGIT, i + 1);
  2642. else throw new SyntaxError('Failed to parse number at: ' + i);
  2643. if (at(source, i) === '.') i = this.skip(IS_DIGIT, i + 1);
  2644. if (at(source, i) === 'e' || at(source, i) === 'E') {
  2645. i++;
  2646. if (at(source, i) === '+' || at(source, i) === '-') i++;
  2647. var exponentStartIndex = i;
  2648. i = this.skip(IS_DIGIT, i);
  2649. if (exponentStartIndex === i) throw new SyntaxError("Failed to parse number's exponent value at: " + i);
  2650. }
  2651. return this.node(PRIMITIVE, Number(slice(source, startIndex, i)), startIndex, i);
  2652. },
  2653. keyword: function (value) {
  2654. var keyword = '' + value;
  2655. var index = this.index;
  2656. var endIndex = index + keyword.length;
  2657. if (slice(this.source, index, endIndex) !== keyword) throw new SyntaxError('Failed to parse value at: ' + index);
  2658. return this.node(PRIMITIVE, value, index, endIndex);
  2659. },
  2660. skip: function (regex, i) {
  2661. var source = this.source;
  2662. for (; i < source.length; i++) if (!exec(regex, at(source, i))) break;
  2663. return i;
  2664. },
  2665. until: function (array, i) {
  2666. i = this.skip(IS_WHITESPACE, i);
  2667. var chr = at(this.source, i);
  2668. for (var j = 0; j < array.length; j++) if (array[j] === chr) return i;
  2669. throw new SyntaxError('Unexpected character: "' + chr + '" at: ' + i);
  2670. }
  2671. };
  2672. var NO_SOURCE_SUPPORT = fails(function () {
  2673. var unsafeInt = '9007199254740993';
  2674. var source;
  2675. nativeParse(unsafeInt, function (key, value, context) {
  2676. source = context.source;
  2677. });
  2678. return source !== unsafeInt;
  2679. });
  2680. var PROPER_BASE_PARSE = NATIVE_SYMBOL && !fails(function () {
  2681. // Safari 9 bug
  2682. return 1 / nativeParse('-0 \t') !== -Infinity;
  2683. });
  2684. // `JSON.parse` method
  2685. // https://tc39.es/ecma262/#sec-json.parse
  2686. // https://github.com/tc39/proposal-json-parse-with-source
  2687. $({ target: 'JSON', stat: true, forced: NO_SOURCE_SUPPORT }, {
  2688. parse: function parse(text, reviver) {
  2689. return PROPER_BASE_PARSE && !isCallable(reviver) ? nativeParse(text) : $parse(text, reviver);
  2690. }
  2691. });
  2692. /***/ }),
  2693. /***/ 8469:
  2694. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2695. var uncurryThis = __webpack_require__(9504);
  2696. var iterateSimple = __webpack_require__(507);
  2697. var SetHelpers = __webpack_require__(4402);
  2698. var Set = SetHelpers.Set;
  2699. var SetPrototype = SetHelpers.proto;
  2700. var forEach = uncurryThis(SetPrototype.forEach);
  2701. var keys = uncurryThis(SetPrototype.keys);
  2702. var next = keys(new Set()).next;
  2703. module.exports = function (set, fn, interruptible) {
  2704. return interruptible ? iterateSimple({ iterator: keys(set), next: next }, fn) : forEach(set, fn);
  2705. };
  2706. /***/ }),
  2707. /***/ 8480:
  2708. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  2709. var internalObjectKeys = __webpack_require__(1828);
  2710. var enumBugKeys = __webpack_require__(8727);
  2711. var hiddenKeys = enumBugKeys.concat('length', 'prototype');
  2712. // `Object.getOwnPropertyNames` method
  2713. // https://tc39.es/ecma262/#sec-object.getownpropertynames
  2714. // eslint-disable-next-line es/no-object-getownpropertynames -- safe
  2715. exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
  2716. return internalObjectKeys(O, hiddenKeys);
  2717. };
  2718. /***/ }),
  2719. /***/ 8527:
  2720. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2721. var aSet = __webpack_require__(7080);
  2722. var has = (__webpack_require__(4402).has);
  2723. var size = __webpack_require__(5170);
  2724. var getSetRecord = __webpack_require__(3789);
  2725. var iterateSimple = __webpack_require__(507);
  2726. var iteratorClose = __webpack_require__(9539);
  2727. // `Set.prototype.isSupersetOf` method
  2728. // https://tc39.github.io/proposal-set-methods/#Set.prototype.isSupersetOf
  2729. module.exports = function isSupersetOf(other) {
  2730. var O = aSet(this);
  2731. var otherRec = getSetRecord(other);
  2732. if (size(O) < otherRec.size) return false;
  2733. var iterator = otherRec.getIterator();
  2734. return iterateSimple(iterator, function (e) {
  2735. if (!has(O, e)) return iteratorClose(iterator, 'normal', false);
  2736. }) !== false;
  2737. };
  2738. /***/ }),
  2739. /***/ 8551:
  2740. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2741. var isObject = __webpack_require__(34);
  2742. var $String = String;
  2743. var $TypeError = TypeError;
  2744. // `Assert: Type(argument) is Object`
  2745. module.exports = function (argument) {
  2746. if (isObject(argument)) return argument;
  2747. throw new $TypeError($String(argument) + ' is not an object');
  2748. };
  2749. /***/ }),
  2750. /***/ 8622:
  2751. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2752. var globalThis = __webpack_require__(4576);
  2753. var isCallable = __webpack_require__(4901);
  2754. var WeakMap = globalThis.WeakMap;
  2755. module.exports = isCallable(WeakMap) && /native code/.test(String(WeakMap));
  2756. /***/ }),
  2757. /***/ 8686:
  2758. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2759. var DESCRIPTORS = __webpack_require__(3724);
  2760. var fails = __webpack_require__(9039);
  2761. // V8 ~ Chrome 36-
  2762. // https://bugs.chromium.org/p/v8/issues/detail?id=3334
  2763. module.exports = DESCRIPTORS && fails(function () {
  2764. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  2765. return Object.defineProperty(function () { /* empty */ }, 'prototype', {
  2766. value: 42,
  2767. writable: false
  2768. }).prototype !== 42;
  2769. });
  2770. /***/ }),
  2771. /***/ 8721:
  2772. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  2773. var DESCRIPTORS = __webpack_require__(3724);
  2774. var uncurryThis = __webpack_require__(9504);
  2775. var defineBuiltInAccessor = __webpack_require__(2106);
  2776. var URLSearchParamsPrototype = URLSearchParams.prototype;
  2777. var forEach = uncurryThis(URLSearchParamsPrototype.forEach);
  2778. // `URLSearchParams.prototype.size` getter
  2779. // https://github.com/whatwg/url/pull/734
  2780. if (DESCRIPTORS && !('size' in URLSearchParamsPrototype)) {
  2781. defineBuiltInAccessor(URLSearchParamsPrototype, 'size', {
  2782. get: function size() {
  2783. var count = 0;
  2784. forEach(this, function () { count++; });
  2785. return count;
  2786. },
  2787. configurable: true,
  2788. enumerable: true
  2789. });
  2790. }
  2791. /***/ }),
  2792. /***/ 8727:
  2793. /***/ ((module) => {
  2794. // IE8- don't enum bug keys
  2795. module.exports = [
  2796. 'constructor',
  2797. 'hasOwnProperty',
  2798. 'isPrototypeOf',
  2799. 'propertyIsEnumerable',
  2800. 'toLocaleString',
  2801. 'toString',
  2802. 'valueOf'
  2803. ];
  2804. /***/ }),
  2805. /***/ 8750:
  2806. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2807. var aSet = __webpack_require__(7080);
  2808. var SetHelpers = __webpack_require__(4402);
  2809. var size = __webpack_require__(5170);
  2810. var getSetRecord = __webpack_require__(3789);
  2811. var iterateSet = __webpack_require__(8469);
  2812. var iterateSimple = __webpack_require__(507);
  2813. var Set = SetHelpers.Set;
  2814. var add = SetHelpers.add;
  2815. var has = SetHelpers.has;
  2816. // `Set.prototype.intersection` method
  2817. // https://github.com/tc39/proposal-set-methods
  2818. module.exports = function intersection(other) {
  2819. var O = aSet(this);
  2820. var otherRec = getSetRecord(other);
  2821. var result = new Set();
  2822. if (size(O) > otherRec.size) {
  2823. iterateSimple(otherRec.getIterator(), function (e) {
  2824. if (has(O, e)) add(result, e);
  2825. });
  2826. } else {
  2827. iterateSet(O, function (e) {
  2828. if (otherRec.includes(e)) add(result, e);
  2829. });
  2830. }
  2831. return result;
  2832. };
  2833. /***/ }),
  2834. /***/ 8773:
  2835. /***/ ((__unused_webpack_module, exports) => {
  2836. var $propertyIsEnumerable = {}.propertyIsEnumerable;
  2837. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  2838. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  2839. // Nashorn ~ JDK8 bug
  2840. var NASHORN_BUG = getOwnPropertyDescriptor && !$propertyIsEnumerable.call({ 1: 2 }, 1);
  2841. // `Object.prototype.propertyIsEnumerable` method implementation
  2842. // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
  2843. exports.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
  2844. var descriptor = getOwnPropertyDescriptor(this, V);
  2845. return !!descriptor && descriptor.enumerable;
  2846. } : $propertyIsEnumerable;
  2847. /***/ }),
  2848. /***/ 8981:
  2849. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2850. var requireObjectCoercible = __webpack_require__(7750);
  2851. var $Object = Object;
  2852. // `ToObject` abstract operation
  2853. // https://tc39.es/ecma262/#sec-toobject
  2854. module.exports = function (argument) {
  2855. return $Object(requireObjectCoercible(argument));
  2856. };
  2857. /***/ }),
  2858. /***/ 9039:
  2859. /***/ ((module) => {
  2860. module.exports = function (exec) {
  2861. try {
  2862. return !!exec();
  2863. } catch (error) {
  2864. return true;
  2865. }
  2866. };
  2867. /***/ }),
  2868. /***/ 9286:
  2869. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2870. var SetHelpers = __webpack_require__(4402);
  2871. var iterate = __webpack_require__(8469);
  2872. var Set = SetHelpers.Set;
  2873. var add = SetHelpers.add;
  2874. module.exports = function (set) {
  2875. var result = new Set();
  2876. iterate(set, function (it) {
  2877. add(result, it);
  2878. });
  2879. return result;
  2880. };
  2881. /***/ }),
  2882. /***/ 9297:
  2883. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2884. var uncurryThis = __webpack_require__(9504);
  2885. var toObject = __webpack_require__(8981);
  2886. var hasOwnProperty = uncurryThis({}.hasOwnProperty);
  2887. // `HasOwnProperty` abstract operation
  2888. // https://tc39.es/ecma262/#sec-hasownproperty
  2889. // eslint-disable-next-line es/no-object-hasown -- safe
  2890. module.exports = Object.hasOwn || function hasOwn(it, key) {
  2891. return hasOwnProperty(toObject(it), key);
  2892. };
  2893. /***/ }),
  2894. /***/ 9306:
  2895. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2896. var isCallable = __webpack_require__(4901);
  2897. var tryToString = __webpack_require__(6823);
  2898. var $TypeError = TypeError;
  2899. // `Assert: IsCallable(argument) is true`
  2900. module.exports = function (argument) {
  2901. if (isCallable(argument)) return argument;
  2902. throw new $TypeError(tryToString(argument) + ' is not a function');
  2903. };
  2904. /***/ }),
  2905. /***/ 9429:
  2906. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2907. var globalThis = __webpack_require__(4576);
  2908. var IS_NODE = __webpack_require__(6193);
  2909. module.exports = function (name) {
  2910. if (IS_NODE) {
  2911. try {
  2912. return globalThis.process.getBuiltinModule(name);
  2913. } catch (error) { /* empty */ }
  2914. try {
  2915. // eslint-disable-next-line no-new-func -- safe
  2916. return Function('return require("' + name + '")')();
  2917. } catch (error) { /* empty */ }
  2918. }
  2919. };
  2920. /***/ }),
  2921. /***/ 9433:
  2922. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2923. var globalThis = __webpack_require__(4576);
  2924. // eslint-disable-next-line es/no-object-defineproperty -- safe
  2925. var defineProperty = Object.defineProperty;
  2926. module.exports = function (key, value) {
  2927. try {
  2928. defineProperty(globalThis, key, { value: value, configurable: true, writable: true });
  2929. } catch (error) {
  2930. globalThis[key] = value;
  2931. } return value;
  2932. };
  2933. /***/ }),
  2934. /***/ 9462:
  2935. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2936. var call = __webpack_require__(9565);
  2937. var create = __webpack_require__(2360);
  2938. var createNonEnumerableProperty = __webpack_require__(6699);
  2939. var defineBuiltIns = __webpack_require__(6279);
  2940. var wellKnownSymbol = __webpack_require__(8227);
  2941. var InternalStateModule = __webpack_require__(1181);
  2942. var getMethod = __webpack_require__(5966);
  2943. var IteratorPrototype = (__webpack_require__(7657).IteratorPrototype);
  2944. var createIterResultObject = __webpack_require__(2529);
  2945. var iteratorClose = __webpack_require__(9539);
  2946. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  2947. var ITERATOR_HELPER = 'IteratorHelper';
  2948. var WRAP_FOR_VALID_ITERATOR = 'WrapForValidIterator';
  2949. var setInternalState = InternalStateModule.set;
  2950. var createIteratorProxyPrototype = function (IS_ITERATOR) {
  2951. var getInternalState = InternalStateModule.getterFor(IS_ITERATOR ? WRAP_FOR_VALID_ITERATOR : ITERATOR_HELPER);
  2952. return defineBuiltIns(create(IteratorPrototype), {
  2953. next: function next() {
  2954. var state = getInternalState(this);
  2955. // for simplification:
  2956. // for `%WrapForValidIteratorPrototype%.next` or with `state.returnHandlerResult` our `nextHandler` returns `IterResultObject`
  2957. // for `%IteratorHelperPrototype%.next` - just a value
  2958. if (IS_ITERATOR) return state.nextHandler();
  2959. if (state.done) return createIterResultObject(undefined, true);
  2960. try {
  2961. var result = state.nextHandler();
  2962. return state.returnHandlerResult ? result : createIterResultObject(result, state.done);
  2963. } catch (error) {
  2964. state.done = true;
  2965. throw error;
  2966. }
  2967. },
  2968. 'return': function () {
  2969. var state = getInternalState(this);
  2970. var iterator = state.iterator;
  2971. state.done = true;
  2972. if (IS_ITERATOR) {
  2973. var returnMethod = getMethod(iterator, 'return');
  2974. return returnMethod ? call(returnMethod, iterator) : createIterResultObject(undefined, true);
  2975. }
  2976. if (state.inner) try {
  2977. iteratorClose(state.inner.iterator, 'normal');
  2978. } catch (error) {
  2979. return iteratorClose(iterator, 'throw', error);
  2980. }
  2981. if (iterator) iteratorClose(iterator, 'normal');
  2982. return createIterResultObject(undefined, true);
  2983. }
  2984. });
  2985. };
  2986. var WrapForValidIteratorPrototype = createIteratorProxyPrototype(true);
  2987. var IteratorHelperPrototype = createIteratorProxyPrototype(false);
  2988. createNonEnumerableProperty(IteratorHelperPrototype, TO_STRING_TAG, 'Iterator Helper');
  2989. module.exports = function (nextHandler, IS_ITERATOR, RETURN_HANDLER_RESULT) {
  2990. var IteratorProxy = function Iterator(record, state) {
  2991. if (state) {
  2992. state.iterator = record.iterator;
  2993. state.next = record.next;
  2994. } else state = record;
  2995. state.type = IS_ITERATOR ? WRAP_FOR_VALID_ITERATOR : ITERATOR_HELPER;
  2996. state.returnHandlerResult = !!RETURN_HANDLER_RESULT;
  2997. state.nextHandler = nextHandler;
  2998. state.counter = 0;
  2999. state.done = false;
  3000. setInternalState(this, state);
  3001. };
  3002. IteratorProxy.prototype = IS_ITERATOR ? WrapForValidIteratorPrototype : IteratorHelperPrototype;
  3003. return IteratorProxy;
  3004. };
  3005. /***/ }),
  3006. /***/ 9504:
  3007. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3008. var NATIVE_BIND = __webpack_require__(616);
  3009. var FunctionPrototype = Function.prototype;
  3010. var call = FunctionPrototype.call;
  3011. // eslint-disable-next-line es/no-function-prototype-bind -- safe
  3012. var uncurryThisWithBind = NATIVE_BIND && FunctionPrototype.bind.bind(call, call);
  3013. module.exports = NATIVE_BIND ? uncurryThisWithBind : function (fn) {
  3014. return function () {
  3015. return call.apply(fn, arguments);
  3016. };
  3017. };
  3018. /***/ }),
  3019. /***/ 9519:
  3020. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3021. var globalThis = __webpack_require__(4576);
  3022. var userAgent = __webpack_require__(2839);
  3023. var process = globalThis.process;
  3024. var Deno = globalThis.Deno;
  3025. var versions = process && process.versions || Deno && Deno.version;
  3026. var v8 = versions && versions.v8;
  3027. var match, version;
  3028. if (v8) {
  3029. match = v8.split('.');
  3030. // in old Chrome, versions of V8 isn't V8 = Chrome / 10
  3031. // but their correct versions are not interesting for us
  3032. version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]);
  3033. }
  3034. // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0`
  3035. // so check `userAgent` even if `.v8` exists, but 0
  3036. if (!version && userAgent) {
  3037. match = userAgent.match(/Edge\/(\d+)/);
  3038. if (!match || match[1] >= 74) {
  3039. match = userAgent.match(/Chrome\/(\d+)/);
  3040. if (match) version = +match[1];
  3041. }
  3042. }
  3043. module.exports = version;
  3044. /***/ }),
  3045. /***/ 9539:
  3046. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3047. var call = __webpack_require__(9565);
  3048. var anObject = __webpack_require__(8551);
  3049. var getMethod = __webpack_require__(5966);
  3050. module.exports = function (iterator, kind, value) {
  3051. var innerResult, innerError;
  3052. anObject(iterator);
  3053. try {
  3054. innerResult = getMethod(iterator, 'return');
  3055. if (!innerResult) {
  3056. if (kind === 'throw') throw value;
  3057. return value;
  3058. }
  3059. innerResult = call(innerResult, iterator);
  3060. } catch (error) {
  3061. innerError = true;
  3062. innerResult = error;
  3063. }
  3064. if (kind === 'throw') throw value;
  3065. if (innerError) throw innerResult;
  3066. anObject(innerResult);
  3067. return value;
  3068. };
  3069. /***/ }),
  3070. /***/ 9565:
  3071. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3072. var NATIVE_BIND = __webpack_require__(616);
  3073. var call = Function.prototype.call;
  3074. // eslint-disable-next-line es/no-function-prototype-bind -- safe
  3075. module.exports = NATIVE_BIND ? call.bind(call) : function () {
  3076. return call.apply(call, arguments);
  3077. };
  3078. /***/ }),
  3079. /***/ 9617:
  3080. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3081. var toIndexedObject = __webpack_require__(5397);
  3082. var toAbsoluteIndex = __webpack_require__(5610);
  3083. var lengthOfArrayLike = __webpack_require__(6198);
  3084. // `Array.prototype.{ indexOf, includes }` methods implementation
  3085. var createMethod = function (IS_INCLUDES) {
  3086. return function ($this, el, fromIndex) {
  3087. var O = toIndexedObject($this);
  3088. var length = lengthOfArrayLike(O);
  3089. if (length === 0) return !IS_INCLUDES && -1;
  3090. var index = toAbsoluteIndex(fromIndex, length);
  3091. var value;
  3092. // Array#includes uses SameValueZero equality algorithm
  3093. // eslint-disable-next-line no-self-compare -- NaN check
  3094. if (IS_INCLUDES && el !== el) while (length > index) {
  3095. value = O[index++];
  3096. // eslint-disable-next-line no-self-compare -- NaN check
  3097. if (value !== value) return true;
  3098. // Array#indexOf ignores holes, Array#includes - not
  3099. } else for (;length > index; index++) {
  3100. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  3101. } return !IS_INCLUDES && -1;
  3102. };
  3103. };
  3104. module.exports = {
  3105. // `Array.prototype.includes` method
  3106. // https://tc39.es/ecma262/#sec-array.prototype.includes
  3107. includes: createMethod(true),
  3108. // `Array.prototype.indexOf` method
  3109. // https://tc39.es/ecma262/#sec-array.prototype.indexof
  3110. indexOf: createMethod(false)
  3111. };
  3112. /***/ })
  3113. /******/ });
  3114. /************************************************************************/
  3115. /******/ // The module cache
  3116. /******/ var __webpack_module_cache__ = {};
  3117. /******/
  3118. /******/ // The require function
  3119. /******/ function __webpack_require__(moduleId) {
  3120. /******/ // Check if module is in cache
  3121. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  3122. /******/ if (cachedModule !== undefined) {
  3123. /******/ return cachedModule.exports;
  3124. /******/ }
  3125. /******/ // Create a new module (and put it into the cache)
  3126. /******/ var module = __webpack_module_cache__[moduleId] = {
  3127. /******/ // no module.id needed
  3128. /******/ // no module.loaded needed
  3129. /******/ exports: {}
  3130. /******/ };
  3131. /******/
  3132. /******/ // Execute the module function
  3133. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  3134. /******/
  3135. /******/ // Return the exports of the module
  3136. /******/ return module.exports;
  3137. /******/ }
  3138. /******/
  3139. /************************************************************************/
  3140. var __webpack_exports__ = {};
  3141. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.array.push.js
  3142. var es_array_push = __webpack_require__(4114);
  3143. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.difference.v2.js
  3144. var es_set_difference_v2 = __webpack_require__(7642);
  3145. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.intersection.v2.js
  3146. var es_set_intersection_v2 = __webpack_require__(8004);
  3147. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.is-disjoint-from.v2.js
  3148. var es_set_is_disjoint_from_v2 = __webpack_require__(3853);
  3149. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.is-subset-of.v2.js
  3150. var es_set_is_subset_of_v2 = __webpack_require__(5876);
  3151. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.is-superset-of.v2.js
  3152. var es_set_is_superset_of_v2 = __webpack_require__(2475);
  3153. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.symmetric-difference.v2.js
  3154. var es_set_symmetric_difference_v2 = __webpack_require__(5024);
  3155. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.union.v2.js
  3156. var es_set_union_v2 = __webpack_require__(1698);
  3157. // EXTERNAL MODULE: ./node_modules/core-js/modules/web.url-search-params.delete.js
  3158. var web_url_search_params_delete = __webpack_require__(4603);
  3159. // EXTERNAL MODULE: ./node_modules/core-js/modules/web.url-search-params.has.js
  3160. var web_url_search_params_has = __webpack_require__(7566);
  3161. // EXTERNAL MODULE: ./node_modules/core-js/modules/web.url-search-params.size.js
  3162. var web_url_search_params_size = __webpack_require__(8721);
  3163. ;// ./web/pdfjs.js
  3164. const {
  3165. AbortException,
  3166. AnnotationEditorLayer,
  3167. AnnotationEditorParamsType,
  3168. AnnotationEditorType,
  3169. AnnotationEditorUIManager,
  3170. AnnotationLayer,
  3171. AnnotationMode,
  3172. AnnotationType,
  3173. build,
  3174. ColorPicker,
  3175. createValidAbsoluteUrl,
  3176. DOMSVGFactory,
  3177. DrawLayer,
  3178. FeatureTest,
  3179. fetchData,
  3180. getDocument,
  3181. getFilenameFromUrl,
  3182. getPdfFilenameFromUrl: pdfjs_getPdfFilenameFromUrl,
  3183. getUuid,
  3184. getXfaPageViewport,
  3185. GlobalWorkerOptions,
  3186. ImageKind,
  3187. InvalidPDFException,
  3188. isDataScheme,
  3189. isPdfFile,
  3190. isValidExplicitDest,
  3191. MathClamp,
  3192. noContextMenu,
  3193. normalizeUnicode,
  3194. OPS,
  3195. OutputScale,
  3196. PasswordResponses,
  3197. PDFDataRangeTransport,
  3198. PDFDateString,
  3199. PDFWorker,
  3200. PermissionFlag,
  3201. PixelsPerInch,
  3202. RenderingCancelledException,
  3203. ResponseException,
  3204. setLayerDimensions,
  3205. shadow,
  3206. SignatureExtractor,
  3207. stopEvent,
  3208. SupportedImageMimeTypes,
  3209. TextLayer,
  3210. TouchManager,
  3211. updateUrlHash,
  3212. Util,
  3213. VerbosityLevel,
  3214. version,
  3215. XfaLayer
  3216. } = globalThis.pdfjsLib;
  3217. ;// ./web/ui_utils.js
  3218. const DEFAULT_SCALE_VALUE = "auto";
  3219. const DEFAULT_SCALE = 1.0;
  3220. const DEFAULT_SCALE_DELTA = 1.1;
  3221. const MIN_SCALE = 0.1;
  3222. const MAX_SCALE = 10.0;
  3223. const UNKNOWN_SCALE = 0;
  3224. const MAX_AUTO_SCALE = 1.25;
  3225. const SCROLLBAR_PADDING = 40;
  3226. const VERTICAL_PADDING = 5;
  3227. const RenderingStates = {
  3228. INITIAL: 0,
  3229. RUNNING: 1,
  3230. PAUSED: 2,
  3231. FINISHED: 3
  3232. };
  3233. const PresentationModeState = {
  3234. UNKNOWN: 0,
  3235. NORMAL: 1,
  3236. CHANGING: 2,
  3237. FULLSCREEN: 3
  3238. };
  3239. const SidebarView = {
  3240. UNKNOWN: -1,
  3241. NONE: 0,
  3242. THUMBS: 1,
  3243. OUTLINE: 2,
  3244. ATTACHMENTS: 3,
  3245. LAYERS: 4
  3246. };
  3247. const TextLayerMode = {
  3248. DISABLE: 0,
  3249. ENABLE: 1,
  3250. ENABLE_PERMISSIONS: 2
  3251. };
  3252. const ScrollMode = {
  3253. UNKNOWN: -1,
  3254. VERTICAL: 0,
  3255. HORIZONTAL: 1,
  3256. WRAPPED: 2,
  3257. PAGE: 3
  3258. };
  3259. const SpreadMode = {
  3260. UNKNOWN: -1,
  3261. NONE: 0,
  3262. ODD: 1,
  3263. EVEN: 2
  3264. };
  3265. const CursorTool = {
  3266. SELECT: 0,
  3267. HAND: 1,
  3268. ZOOM: 2
  3269. };
  3270. const AutoPrintRegExp = /\bprint\s*\(/;
  3271. function scrollIntoView(element, spot, scrollMatches = false) {
  3272. let parent = element.offsetParent;
  3273. if (!parent) {
  3274. console.error("offsetParent is not set -- cannot scroll");
  3275. return;
  3276. }
  3277. let offsetY = element.offsetTop + element.clientTop;
  3278. let offsetX = element.offsetLeft + element.clientLeft;
  3279. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  3280. offsetY += parent.offsetTop;
  3281. offsetX += parent.offsetLeft;
  3282. parent = parent.offsetParent;
  3283. if (!parent) {
  3284. return;
  3285. }
  3286. }
  3287. if (spot) {
  3288. if (spot.top !== undefined) {
  3289. offsetY += spot.top;
  3290. }
  3291. if (spot.left !== undefined) {
  3292. offsetX += spot.left;
  3293. parent.scrollLeft = offsetX;
  3294. }
  3295. }
  3296. parent.scrollTop = offsetY;
  3297. }
  3298. function watchScroll(viewAreaElement, callback, abortSignal = undefined) {
  3299. const debounceScroll = function (evt) {
  3300. if (rAF) {
  3301. return;
  3302. }
  3303. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  3304. rAF = null;
  3305. const currentX = viewAreaElement.scrollLeft;
  3306. const lastX = state.lastX;
  3307. if (currentX !== lastX) {
  3308. state.right = currentX > lastX;
  3309. }
  3310. state.lastX = currentX;
  3311. const currentY = viewAreaElement.scrollTop;
  3312. const lastY = state.lastY;
  3313. if (currentY !== lastY) {
  3314. state.down = currentY > lastY;
  3315. }
  3316. state.lastY = currentY;
  3317. callback(state);
  3318. });
  3319. };
  3320. const state = {
  3321. right: true,
  3322. down: true,
  3323. lastX: viewAreaElement.scrollLeft,
  3324. lastY: viewAreaElement.scrollTop,
  3325. _eventHandler: debounceScroll
  3326. };
  3327. let rAF = null;
  3328. viewAreaElement.addEventListener("scroll", debounceScroll, {
  3329. useCapture: true,
  3330. signal: abortSignal
  3331. });
  3332. abortSignal?.addEventListener("abort", () => window.cancelAnimationFrame(rAF), {
  3333. once: true
  3334. });
  3335. return state;
  3336. }
  3337. function parseQueryString(query) {
  3338. const params = new Map();
  3339. for (const [key, value] of new URLSearchParams(query)) {
  3340. params.set(key.toLowerCase(), value);
  3341. }
  3342. return params;
  3343. }
  3344. const InvisibleCharsRegExp = /[\x00-\x1F]/g;
  3345. function removeNullCharacters(str, replaceInvisible = false) {
  3346. if (!InvisibleCharsRegExp.test(str)) {
  3347. return str;
  3348. }
  3349. if (replaceInvisible) {
  3350. return str.replaceAll(InvisibleCharsRegExp, m => m === "\x00" ? "" : " ");
  3351. }
  3352. return str.replaceAll("\x00", "");
  3353. }
  3354. function binarySearchFirstItem(items, condition, start = 0) {
  3355. let minIndex = start;
  3356. let maxIndex = items.length - 1;
  3357. if (maxIndex < 0 || !condition(items[maxIndex])) {
  3358. return items.length;
  3359. }
  3360. if (condition(items[minIndex])) {
  3361. return minIndex;
  3362. }
  3363. while (minIndex < maxIndex) {
  3364. const currentIndex = minIndex + maxIndex >> 1;
  3365. const currentItem = items[currentIndex];
  3366. if (condition(currentItem)) {
  3367. maxIndex = currentIndex;
  3368. } else {
  3369. minIndex = currentIndex + 1;
  3370. }
  3371. }
  3372. return minIndex;
  3373. }
  3374. function approximateFraction(x) {
  3375. if (Math.floor(x) === x) {
  3376. return [x, 1];
  3377. }
  3378. const xinv = 1 / x;
  3379. const limit = 8;
  3380. if (xinv > limit) {
  3381. return [1, limit];
  3382. } else if (Math.floor(xinv) === xinv) {
  3383. return [1, xinv];
  3384. }
  3385. const x_ = x > 1 ? xinv : x;
  3386. let a = 0,
  3387. b = 1,
  3388. c = 1,
  3389. d = 1;
  3390. while (true) {
  3391. const p = a + c,
  3392. q = b + d;
  3393. if (q > limit) {
  3394. break;
  3395. }
  3396. if (x_ <= p / q) {
  3397. c = p;
  3398. d = q;
  3399. } else {
  3400. a = p;
  3401. b = q;
  3402. }
  3403. }
  3404. let result;
  3405. if (x_ - a / b < c / d - x_) {
  3406. result = x_ === x ? [a, b] : [b, a];
  3407. } else {
  3408. result = x_ === x ? [c, d] : [d, c];
  3409. }
  3410. return result;
  3411. }
  3412. function floorToDivide(x, div) {
  3413. return x - x % div;
  3414. }
  3415. function getPageSizeInches({
  3416. view,
  3417. userUnit,
  3418. rotate
  3419. }) {
  3420. const [x1, y1, x2, y2] = view;
  3421. const changeOrientation = rotate % 180 !== 0;
  3422. const width = (x2 - x1) / 72 * userUnit;
  3423. const height = (y2 - y1) / 72 * userUnit;
  3424. return {
  3425. width: changeOrientation ? height : width,
  3426. height: changeOrientation ? width : height
  3427. };
  3428. }
  3429. function backtrackBeforeAllVisibleElements(index, views, top) {
  3430. if (index < 2) {
  3431. return index;
  3432. }
  3433. let elt = views[index].div;
  3434. let pageTop = elt.offsetTop + elt.clientTop;
  3435. if (pageTop >= top) {
  3436. elt = views[index - 1].div;
  3437. pageTop = elt.offsetTop + elt.clientTop;
  3438. }
  3439. for (let i = index - 2; i >= 0; --i) {
  3440. elt = views[i].div;
  3441. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  3442. break;
  3443. }
  3444. index = i;
  3445. }
  3446. return index;
  3447. }
  3448. function getVisibleElements({
  3449. scrollEl,
  3450. views,
  3451. sortByVisibility = false,
  3452. horizontal = false,
  3453. rtl = false
  3454. }) {
  3455. const top = scrollEl.scrollTop,
  3456. bottom = top + scrollEl.clientHeight;
  3457. const left = scrollEl.scrollLeft,
  3458. right = left + scrollEl.clientWidth;
  3459. function isElementBottomAfterViewTop(view) {
  3460. const element = view.div;
  3461. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  3462. return elementBottom > top;
  3463. }
  3464. function isElementNextAfterViewHorizontally(view) {
  3465. const element = view.div;
  3466. const elementLeft = element.offsetLeft + element.clientLeft;
  3467. const elementRight = elementLeft + element.clientWidth;
  3468. return rtl ? elementLeft < right : elementRight > left;
  3469. }
  3470. const visible = [],
  3471. ids = new Set(),
  3472. numViews = views.length;
  3473. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  3474. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  3475. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  3476. }
  3477. let lastEdge = horizontal ? right : -1;
  3478. for (let i = firstVisibleElementInd; i < numViews; i++) {
  3479. const view = views[i],
  3480. element = view.div;
  3481. const currentWidth = element.offsetLeft + element.clientLeft;
  3482. const currentHeight = element.offsetTop + element.clientTop;
  3483. const viewWidth = element.clientWidth,
  3484. viewHeight = element.clientHeight;
  3485. const viewRight = currentWidth + viewWidth;
  3486. const viewBottom = currentHeight + viewHeight;
  3487. if (lastEdge === -1) {
  3488. if (viewBottom >= bottom) {
  3489. lastEdge = viewBottom;
  3490. }
  3491. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  3492. break;
  3493. }
  3494. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  3495. continue;
  3496. }
  3497. const minY = Math.max(0, top - currentHeight);
  3498. const minX = Math.max(0, left - currentWidth);
  3499. const hiddenHeight = minY + Math.max(0, viewBottom - bottom);
  3500. const hiddenWidth = minX + Math.max(0, viewRight - right);
  3501. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  3502. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  3503. const percent = fractionHeight * fractionWidth * 100 | 0;
  3504. visible.push({
  3505. id: view.id,
  3506. x: currentWidth,
  3507. y: currentHeight,
  3508. visibleArea: percent === 100 ? null : {
  3509. minX,
  3510. minY,
  3511. maxX: Math.min(viewRight, right) - currentWidth,
  3512. maxY: Math.min(viewBottom, bottom) - currentHeight
  3513. },
  3514. view,
  3515. percent,
  3516. widthPercent: fractionWidth * 100 | 0
  3517. });
  3518. ids.add(view.id);
  3519. }
  3520. const first = visible[0],
  3521. last = visible.at(-1);
  3522. if (sortByVisibility) {
  3523. visible.sort(function (a, b) {
  3524. const pc = a.percent - b.percent;
  3525. if (Math.abs(pc) > 0.001) {
  3526. return -pc;
  3527. }
  3528. return a.id - b.id;
  3529. });
  3530. }
  3531. return {
  3532. first,
  3533. last,
  3534. views: visible,
  3535. ids
  3536. };
  3537. }
  3538. function normalizeWheelEventDirection(evt) {
  3539. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  3540. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  3541. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  3542. delta = -delta;
  3543. }
  3544. return delta;
  3545. }
  3546. function normalizeWheelEventDelta(evt) {
  3547. const deltaMode = evt.deltaMode;
  3548. let delta = normalizeWheelEventDirection(evt);
  3549. const MOUSE_PIXELS_PER_LINE = 30;
  3550. const MOUSE_LINES_PER_PAGE = 30;
  3551. if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
  3552. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  3553. } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
  3554. delta /= MOUSE_LINES_PER_PAGE;
  3555. }
  3556. return delta;
  3557. }
  3558. function isValidRotation(angle) {
  3559. return Number.isInteger(angle) && angle % 90 === 0;
  3560. }
  3561. function isValidScrollMode(mode) {
  3562. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  3563. }
  3564. function isValidSpreadMode(mode) {
  3565. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  3566. }
  3567. function isPortraitOrientation(size) {
  3568. return size.width <= size.height;
  3569. }
  3570. const animationStarted = new Promise(function (resolve) {
  3571. window.requestAnimationFrame(resolve);
  3572. });
  3573. const docStyle = document.documentElement.style;
  3574. class ProgressBar {
  3575. #classList = null;
  3576. #disableAutoFetchTimeout = null;
  3577. #percent = 0;
  3578. #style = null;
  3579. #visible = true;
  3580. constructor(bar) {
  3581. this.#classList = bar.classList;
  3582. this.#style = bar.style;
  3583. }
  3584. get percent() {
  3585. return this.#percent;
  3586. }
  3587. set percent(val) {
  3588. this.#percent = MathClamp(val, 0, 100);
  3589. if (isNaN(val)) {
  3590. this.#classList.add("indeterminate");
  3591. return;
  3592. }
  3593. this.#classList.remove("indeterminate");
  3594. this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
  3595. }
  3596. setWidth(viewer) {
  3597. if (!viewer) {
  3598. return;
  3599. }
  3600. const container = viewer.parentNode;
  3601. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  3602. if (scrollbarWidth > 0) {
  3603. this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  3604. }
  3605. }
  3606. setDisableAutoFetch(delay = 5000) {
  3607. if (this.#percent === 100 || isNaN(this.#percent)) {
  3608. return;
  3609. }
  3610. if (this.#disableAutoFetchTimeout) {
  3611. clearTimeout(this.#disableAutoFetchTimeout);
  3612. }
  3613. this.show();
  3614. this.#disableAutoFetchTimeout = setTimeout(() => {
  3615. this.#disableAutoFetchTimeout = null;
  3616. this.hide();
  3617. }, delay);
  3618. }
  3619. hide() {
  3620. if (!this.#visible) {
  3621. return;
  3622. }
  3623. this.#visible = false;
  3624. this.#classList.add("hidden");
  3625. }
  3626. show() {
  3627. if (this.#visible) {
  3628. return;
  3629. }
  3630. this.#visible = true;
  3631. this.#classList.remove("hidden");
  3632. }
  3633. }
  3634. function getActiveOrFocusedElement() {
  3635. let curRoot = document;
  3636. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3637. while (curActiveOrFocused?.shadowRoot) {
  3638. curRoot = curActiveOrFocused.shadowRoot;
  3639. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3640. }
  3641. return curActiveOrFocused;
  3642. }
  3643. function apiPageLayoutToViewerModes(layout) {
  3644. let scrollMode = ScrollMode.VERTICAL,
  3645. spreadMode = SpreadMode.NONE;
  3646. switch (layout) {
  3647. case "SinglePage":
  3648. scrollMode = ScrollMode.PAGE;
  3649. break;
  3650. case "OneColumn":
  3651. break;
  3652. case "TwoPageLeft":
  3653. scrollMode = ScrollMode.PAGE;
  3654. case "TwoColumnLeft":
  3655. spreadMode = SpreadMode.ODD;
  3656. break;
  3657. case "TwoPageRight":
  3658. scrollMode = ScrollMode.PAGE;
  3659. case "TwoColumnRight":
  3660. spreadMode = SpreadMode.EVEN;
  3661. break;
  3662. }
  3663. return {
  3664. scrollMode,
  3665. spreadMode
  3666. };
  3667. }
  3668. function apiPageModeToSidebarView(mode) {
  3669. switch (mode) {
  3670. case "UseNone":
  3671. return SidebarView.NONE;
  3672. case "UseThumbs":
  3673. return SidebarView.THUMBS;
  3674. case "UseOutlines":
  3675. return SidebarView.OUTLINE;
  3676. case "UseAttachments":
  3677. return SidebarView.ATTACHMENTS;
  3678. case "UseOC":
  3679. return SidebarView.LAYERS;
  3680. }
  3681. return SidebarView.NONE;
  3682. }
  3683. function toggleCheckedBtn(button, toggle, view = null) {
  3684. button.classList.toggle("toggled", toggle);
  3685. button.setAttribute("aria-checked", toggle);
  3686. view?.classList.toggle("hidden", !toggle);
  3687. }
  3688. function toggleExpandedBtn(button, toggle, view = null) {
  3689. button.classList.toggle("toggled", toggle);
  3690. button.setAttribute("aria-expanded", toggle);
  3691. view?.classList.toggle("hidden", !toggle);
  3692. }
  3693. const calcRound = function () {
  3694. const e = document.createElement("div");
  3695. e.style.width = "round(down, calc(1.6666666666666665 * 792px), 1px)";
  3696. return e.style.width === "calc(1320px)" ? Math.fround : x => x;
  3697. }();
  3698. ;// ./web/app_options.js
  3699. {
  3700. var compatParams = new Map();
  3701. const {
  3702. maxTouchPoints,
  3703. platform,
  3704. userAgent
  3705. } = navigator;
  3706. const isAndroid = /Android/.test(userAgent);
  3707. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  3708. (function () {
  3709. if (isIOS || isAndroid) {
  3710. compatParams.set("maxCanvasPixels", 5242880);
  3711. }
  3712. })();
  3713. (function () {
  3714. if (isAndroid) {
  3715. compatParams.set("useSystemFonts", false);
  3716. }
  3717. })();
  3718. }
  3719. const OptionKind = {
  3720. BROWSER: 0x01,
  3721. VIEWER: 0x02,
  3722. API: 0x04,
  3723. WORKER: 0x08,
  3724. EVENT_DISPATCH: 0x10,
  3725. PREFERENCE: 0x80
  3726. };
  3727. const Type = {
  3728. BOOLEAN: 0x01,
  3729. NUMBER: 0x02,
  3730. OBJECT: 0x04,
  3731. STRING: 0x08,
  3732. UNDEFINED: 0x10
  3733. };
  3734. const defaultOptions = {
  3735. hasRole: {
  3736. value: '0',
  3737. kind: OptionKind.VIEWER
  3738. },
  3739. allowedGlobalEvents: {
  3740. value: null,
  3741. kind: OptionKind.BROWSER
  3742. },
  3743. canvasMaxAreaInBytes: {
  3744. value: -1,
  3745. kind: OptionKind.BROWSER + OptionKind.API
  3746. },
  3747. isInAutomation: {
  3748. value: false,
  3749. kind: OptionKind.BROWSER
  3750. },
  3751. localeProperties: {
  3752. value: {
  3753. lang: navigator.language || "en-US"
  3754. },
  3755. kind: OptionKind.BROWSER
  3756. },
  3757. maxCanvasDim: {
  3758. value: 32767,
  3759. kind: OptionKind.BROWSER + OptionKind.VIEWER
  3760. },
  3761. nimbusDataStr: {
  3762. value: "",
  3763. kind: OptionKind.BROWSER
  3764. },
  3765. supportsCaretBrowsingMode: {
  3766. value: false,
  3767. kind: OptionKind.BROWSER
  3768. },
  3769. supportsDocumentFonts: {
  3770. value: true,
  3771. kind: OptionKind.BROWSER
  3772. },
  3773. supportsIntegratedFind: {
  3774. value: false,
  3775. kind: OptionKind.BROWSER
  3776. },
  3777. supportsMouseWheelZoomCtrlKey: {
  3778. value: true,
  3779. kind: OptionKind.BROWSER
  3780. },
  3781. supportsMouseWheelZoomMetaKey: {
  3782. value: true,
  3783. kind: OptionKind.BROWSER
  3784. },
  3785. supportsPinchToZoom: {
  3786. value: true,
  3787. kind: OptionKind.BROWSER
  3788. },
  3789. supportsPrinting: {
  3790. value: true,
  3791. kind: OptionKind.BROWSER
  3792. },
  3793. toolbarDensity: {
  3794. value: 0,
  3795. kind: OptionKind.BROWSER + OptionKind.EVENT_DISPATCH
  3796. },
  3797. altTextLearnMoreUrl: {
  3798. value: "",
  3799. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3800. },
  3801. annotationEditorMode: {
  3802. value: 0,
  3803. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3804. },
  3805. annotationMode: {
  3806. value: 2,
  3807. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3808. },
  3809. capCanvasAreaFactor: {
  3810. value: 200,
  3811. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3812. },
  3813. cursorToolOnLoad: {
  3814. value: 0,
  3815. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3816. },
  3817. debuggerSrc: {
  3818. value: "./debugger.mjs",
  3819. kind: OptionKind.VIEWER
  3820. },
  3821. defaultZoomDelay: {
  3822. value: 400,
  3823. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3824. },
  3825. defaultZoomValue: {
  3826. value: "",
  3827. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3828. },
  3829. disableHistory: {
  3830. value: false,
  3831. kind: OptionKind.VIEWER
  3832. },
  3833. disablePageLabels: {
  3834. value: false,
  3835. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3836. },
  3837. enableAltText: {
  3838. value: false,
  3839. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3840. },
  3841. enableAltTextModelDownload: {
  3842. value: true,
  3843. kind: OptionKind.VIEWER + OptionKind.PREFERENCE + OptionKind.EVENT_DISPATCH
  3844. },
  3845. enableAutoLinking: {
  3846. value: true,
  3847. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3848. },
  3849. enableDetailCanvas: {
  3850. value: true,
  3851. kind: OptionKind.VIEWER
  3852. },
  3853. enableGuessAltText: {
  3854. value: true,
  3855. kind: OptionKind.VIEWER + OptionKind.PREFERENCE + OptionKind.EVENT_DISPATCH
  3856. },
  3857. enableHighlightFloatingButton: {
  3858. value: false,
  3859. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3860. },
  3861. enableNewAltTextWhenAddingImage: {
  3862. value: true,
  3863. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3864. },
  3865. enablePermissions: {
  3866. value: false,
  3867. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3868. },
  3869. enablePrintAutoRotate: {
  3870. value: true,
  3871. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3872. },
  3873. enableScripting: {
  3874. value: true,
  3875. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3876. },
  3877. enableSignatureEditor: {
  3878. value: false,
  3879. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3880. },
  3881. enableUpdatedAddImage: {
  3882. value: false,
  3883. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3884. },
  3885. externalLinkRel: {
  3886. value: "noopener noreferrer nofollow",
  3887. kind: OptionKind.VIEWER
  3888. },
  3889. externalLinkTarget: {
  3890. value: 0,
  3891. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3892. },
  3893. highlightEditorColors: {
  3894. value: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F",
  3895. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3896. },
  3897. historyUpdateUrl: {
  3898. value: false,
  3899. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3900. },
  3901. ignoreDestinationZoom: {
  3902. value: false,
  3903. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3904. },
  3905. imageResourcesPath: {
  3906. value: "./images/",
  3907. kind: OptionKind.VIEWER
  3908. },
  3909. maxCanvasPixels: {
  3910. value: 2 ** 25,
  3911. kind: OptionKind.VIEWER
  3912. },
  3913. minDurationToUpdateCanvas: {
  3914. value: 500,
  3915. kind: OptionKind.VIEWER
  3916. },
  3917. forcePageColors: {
  3918. value: false,
  3919. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3920. },
  3921. pageColorsBackground: {
  3922. value: "Canvas",
  3923. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3924. },
  3925. pageColorsForeground: {
  3926. value: "CanvasText",
  3927. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3928. },
  3929. pdfBugEnabled: {
  3930. value: false,
  3931. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3932. },
  3933. printResolution: {
  3934. value: 150,
  3935. kind: OptionKind.VIEWER
  3936. },
  3937. sidebarViewOnLoad: {
  3938. value: -1,
  3939. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3940. },
  3941. scrollModeOnLoad: {
  3942. value: -1,
  3943. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3944. },
  3945. spreadModeOnLoad: {
  3946. value: -1,
  3947. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3948. },
  3949. textLayerMode: {
  3950. value: 1,
  3951. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3952. },
  3953. viewerCssTheme: {
  3954. value: 0,
  3955. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3956. },
  3957. viewOnLoad: {
  3958. value: 0,
  3959. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3960. },
  3961. cMapPacked: {
  3962. value: true,
  3963. kind: OptionKind.API
  3964. },
  3965. cMapUrl: {
  3966. value: "../web/cmaps/",
  3967. kind: OptionKind.API
  3968. },
  3969. disableAutoFetch: {
  3970. value: false,
  3971. kind: OptionKind.API + OptionKind.PREFERENCE
  3972. },
  3973. disableFontFace: {
  3974. value: false,
  3975. kind: OptionKind.API + OptionKind.PREFERENCE
  3976. },
  3977. disableRange: {
  3978. value: false,
  3979. kind: OptionKind.API + OptionKind.PREFERENCE
  3980. },
  3981. disableStream: {
  3982. value: false,
  3983. kind: OptionKind.API + OptionKind.PREFERENCE
  3984. },
  3985. docBaseUrl: {
  3986. value: "",
  3987. kind: OptionKind.API
  3988. },
  3989. enableHWA: {
  3990. value: true,
  3991. kind: OptionKind.API + OptionKind.VIEWER + OptionKind.PREFERENCE
  3992. },
  3993. enableXfa: {
  3994. value: true,
  3995. kind: OptionKind.API + OptionKind.PREFERENCE
  3996. },
  3997. fontExtraProperties: {
  3998. value: false,
  3999. kind: OptionKind.API
  4000. },
  4001. iccUrl: {
  4002. value: "../web/iccs/",
  4003. kind: OptionKind.API
  4004. },
  4005. isEvalSupported: {
  4006. value: true,
  4007. kind: OptionKind.API
  4008. },
  4009. isOffscreenCanvasSupported: {
  4010. value: true,
  4011. kind: OptionKind.API
  4012. },
  4013. maxImageSize: {
  4014. value: -1,
  4015. kind: OptionKind.API
  4016. },
  4017. pdfBug: {
  4018. value: false,
  4019. kind: OptionKind.API
  4020. },
  4021. standardFontDataUrl: {
  4022. value: "../web/standard_fonts/",
  4023. kind: OptionKind.API
  4024. },
  4025. useSystemFonts: {
  4026. value: undefined,
  4027. kind: OptionKind.API,
  4028. type: Type.BOOLEAN + Type.UNDEFINED
  4029. },
  4030. verbosity: {
  4031. value: 1,
  4032. kind: OptionKind.API
  4033. },
  4034. wasmUrl: {
  4035. value: "../web/wasm/",
  4036. kind: OptionKind.API
  4037. },
  4038. workerPort: {
  4039. value: null,
  4040. kind: OptionKind.WORKER
  4041. },
  4042. workerSrc: {
  4043. value: "../build/pdf.worker.mjs",
  4044. kind: OptionKind.WORKER
  4045. }
  4046. };
  4047. {
  4048. defaultOptions.defaultUrl = {
  4049. value: "compressed.tracemonkey-pldi-09.pdf",
  4050. kind: OptionKind.VIEWER
  4051. };
  4052. defaultOptions.sandboxBundleSrc = {
  4053. value: "../build/pdf.sandbox.mjs",
  4054. kind: OptionKind.VIEWER
  4055. };
  4056. defaultOptions.enableFakeMLManager = {
  4057. value: true,
  4058. kind: OptionKind.VIEWER
  4059. };
  4060. }
  4061. {
  4062. defaultOptions.disablePreferences = {
  4063. value: false,
  4064. kind: OptionKind.VIEWER
  4065. };
  4066. }
  4067. class AppOptions {
  4068. static eventBus;
  4069. static #opts = new Map();
  4070. static {
  4071. for (const name in defaultOptions) {
  4072. this.#opts.set(name, defaultOptions[name].value);
  4073. }
  4074. for (const [name, value] of compatParams) {
  4075. this.#opts.set(name, value);
  4076. }
  4077. this._hasInvokedSet = false;
  4078. this._checkDisablePreferences = () => {
  4079. if (this.get("disablePreferences")) {
  4080. return true;
  4081. }
  4082. if (this._hasInvokedSet) {
  4083. console.warn("The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option to prevent that.');
  4084. }
  4085. return false;
  4086. };
  4087. }
  4088. static get(name) {
  4089. return this.#opts.get(name);
  4090. }
  4091. static getAll(kind = null, defaultOnly = false) {
  4092. const options = Object.create(null);
  4093. for (const name in defaultOptions) {
  4094. const defaultOpt = defaultOptions[name];
  4095. if (kind && !(kind & defaultOpt.kind)) {
  4096. continue;
  4097. }
  4098. options[name] = !defaultOnly ? this.#opts.get(name) : defaultOpt.value;
  4099. }
  4100. return options;
  4101. }
  4102. static set(name, value) {
  4103. this.setAll({
  4104. [name]: value
  4105. });
  4106. }
  4107. static setAll(options, prefs = false) {
  4108. this._hasInvokedSet ||= true;
  4109. let events;
  4110. for (const name in options) {
  4111. const defaultOpt = defaultOptions[name],
  4112. userOpt = options[name];
  4113. if (!defaultOpt || !(typeof userOpt === typeof defaultOpt.value || Type[(typeof userOpt).toUpperCase()] & defaultOpt.type)) {
  4114. continue;
  4115. }
  4116. const {
  4117. kind
  4118. } = defaultOpt;
  4119. if (prefs && !(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)) {
  4120. continue;
  4121. }
  4122. if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) {
  4123. (events ||= new Map()).set(name, userOpt);
  4124. }
  4125. this.#opts.set(name, userOpt);
  4126. }
  4127. if (events) {
  4128. for (const [name, value] of events) {
  4129. this.eventBus.dispatch(name.toLowerCase(), {
  4130. source: this,
  4131. value
  4132. });
  4133. }
  4134. }
  4135. }
  4136. }
  4137. // EXTERNAL MODULE: ./node_modules/core-js/modules/esnext.json.parse.js
  4138. var esnext_json_parse = __webpack_require__(8335);
  4139. ;// ./web/pdf_link_service.js
  4140. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  4141. const LinkTarget = {
  4142. NONE: 0,
  4143. SELF: 1,
  4144. BLANK: 2,
  4145. PARENT: 3,
  4146. TOP: 4
  4147. };
  4148. class PDFLinkService {
  4149. externalLinkEnabled = true;
  4150. constructor({
  4151. eventBus,
  4152. externalLinkTarget = null,
  4153. externalLinkRel = null,
  4154. ignoreDestinationZoom = false
  4155. } = {}) {
  4156. this.eventBus = eventBus;
  4157. this.externalLinkTarget = externalLinkTarget;
  4158. this.externalLinkRel = externalLinkRel;
  4159. this._ignoreDestinationZoom = ignoreDestinationZoom;
  4160. this.baseUrl = null;
  4161. this.pdfDocument = null;
  4162. this.pdfViewer = null;
  4163. this.pdfHistory = null;
  4164. }
  4165. setDocument(pdfDocument, baseUrl = null) {
  4166. this.baseUrl = baseUrl;
  4167. this.pdfDocument = pdfDocument;
  4168. }
  4169. setViewer(pdfViewer) {
  4170. this.pdfViewer = pdfViewer;
  4171. }
  4172. setHistory(pdfHistory) {
  4173. this.pdfHistory = pdfHistory;
  4174. }
  4175. get pagesCount() {
  4176. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  4177. }
  4178. get page() {
  4179. return this.pdfDocument ? this.pdfViewer.currentPageNumber : 1;
  4180. }
  4181. set page(value) {
  4182. if (this.pdfDocument) {
  4183. this.pdfViewer.currentPageNumber = value;
  4184. }
  4185. }
  4186. get rotation() {
  4187. return this.pdfDocument ? this.pdfViewer.pagesRotation : 0;
  4188. }
  4189. set rotation(value) {
  4190. if (this.pdfDocument) {
  4191. this.pdfViewer.pagesRotation = value;
  4192. }
  4193. }
  4194. get isInPresentationMode() {
  4195. return this.pdfDocument ? this.pdfViewer.isInPresentationMode : false;
  4196. }
  4197. async goToDestination(dest) {
  4198. if (!this.pdfDocument) {
  4199. return;
  4200. }
  4201. let namedDest, explicitDest, pageNumber;
  4202. if (typeof dest === "string") {
  4203. namedDest = dest;
  4204. explicitDest = await this.pdfDocument.getDestination(dest);
  4205. } else {
  4206. namedDest = null;
  4207. explicitDest = await dest;
  4208. }
  4209. if (!Array.isArray(explicitDest)) {
  4210. console.error(`goToDestination: "${explicitDest}" is not a valid destination array, for dest="${dest}".`);
  4211. return;
  4212. }
  4213. const [destRef] = explicitDest;
  4214. if (destRef && typeof destRef === "object") {
  4215. pageNumber = this.pdfDocument.cachedPageNumber(destRef);
  4216. if (!pageNumber) {
  4217. try {
  4218. pageNumber = (await this.pdfDocument.getPageIndex(destRef)) + 1;
  4219. } catch {
  4220. console.error(`goToDestination: "${destRef}" is not a valid page reference, for dest="${dest}".`);
  4221. return;
  4222. }
  4223. }
  4224. } else if (Number.isInteger(destRef)) {
  4225. pageNumber = destRef + 1;
  4226. }
  4227. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  4228. console.error(`goToDestination: "${pageNumber}" is not a valid page number, for dest="${dest}".`);
  4229. return;
  4230. }
  4231. if (this.pdfHistory) {
  4232. this.pdfHistory.pushCurrentPosition();
  4233. this.pdfHistory.push({
  4234. namedDest,
  4235. explicitDest,
  4236. pageNumber
  4237. });
  4238. }
  4239. this.pdfViewer.scrollPageIntoView({
  4240. pageNumber,
  4241. destArray: explicitDest,
  4242. ignoreDestinationZoom: this._ignoreDestinationZoom
  4243. });
  4244. }
  4245. goToPage(val) {
  4246. if (!this.pdfDocument) {
  4247. return;
  4248. }
  4249. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  4250. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  4251. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  4252. return;
  4253. }
  4254. if (this.pdfHistory) {
  4255. this.pdfHistory.pushCurrentPosition();
  4256. this.pdfHistory.pushPage(pageNumber);
  4257. }
  4258. this.pdfViewer.scrollPageIntoView({
  4259. pageNumber
  4260. });
  4261. }
  4262. addLinkAttributes(link, url, newWindow = false) {
  4263. if (!url || typeof url !== "string") {
  4264. throw new Error('A valid "url" parameter must provided.');
  4265. }
  4266. const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  4267. rel = this.externalLinkRel;
  4268. if (this.externalLinkEnabled) {
  4269. link.href = link.title = url;
  4270. } else {
  4271. link.href = "";
  4272. link.title = `Disabled: ${url}`;
  4273. link.onclick = () => false;
  4274. }
  4275. let targetStr = "";
  4276. switch (target) {
  4277. case LinkTarget.NONE:
  4278. break;
  4279. case LinkTarget.SELF:
  4280. targetStr = "_self";
  4281. break;
  4282. case LinkTarget.BLANK:
  4283. targetStr = "_blank";
  4284. break;
  4285. case LinkTarget.PARENT:
  4286. targetStr = "_parent";
  4287. break;
  4288. case LinkTarget.TOP:
  4289. targetStr = "_top";
  4290. break;
  4291. }
  4292. link.target = targetStr;
  4293. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  4294. }
  4295. getDestinationHash(dest) {
  4296. if (typeof dest === "string") {
  4297. if (dest.length > 0) {
  4298. return this.getAnchorUrl("#" + escape(dest));
  4299. }
  4300. } else if (Array.isArray(dest)) {
  4301. const str = JSON.stringify(dest);
  4302. if (str.length > 0) {
  4303. return this.getAnchorUrl("#" + escape(str));
  4304. }
  4305. }
  4306. return this.getAnchorUrl("");
  4307. }
  4308. getAnchorUrl(anchor) {
  4309. return this.baseUrl ? this.baseUrl + anchor : anchor;
  4310. }
  4311. setHash(hash) {
  4312. if (!this.pdfDocument) {
  4313. return;
  4314. }
  4315. let pageNumber, dest;
  4316. if (hash.includes("=")) {
  4317. const params = parseQueryString(hash);
  4318. if (params.has("search")) {
  4319. const query = params.get("search").replaceAll('"', ""),
  4320. phrase = params.get("phrase") === "true";
  4321. this.eventBus.dispatch("findfromurlhash", {
  4322. source: this,
  4323. query: phrase ? query : query.match(/\S+/g)
  4324. });
  4325. }
  4326. if (params.has("page")) {
  4327. pageNumber = params.get("page") | 0 || 1;
  4328. }
  4329. if (params.has("zoom")) {
  4330. const zoomArgs = params.get("zoom").split(",");
  4331. const zoomArg = zoomArgs[0];
  4332. const zoomArgNumber = parseFloat(zoomArg);
  4333. if (!zoomArg.includes("Fit")) {
  4334. dest = [null, {
  4335. name: "XYZ"
  4336. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  4337. } else if (zoomArg === "Fit" || zoomArg === "FitB") {
  4338. dest = [null, {
  4339. name: zoomArg
  4340. }];
  4341. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  4342. dest = [null, {
  4343. name: zoomArg
  4344. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  4345. } else if (zoomArg === "FitR") {
  4346. if (zoomArgs.length !== 5) {
  4347. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  4348. } else {
  4349. dest = [null, {
  4350. name: zoomArg
  4351. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  4352. }
  4353. } else {
  4354. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  4355. }
  4356. }
  4357. if (dest) {
  4358. this.pdfViewer.scrollPageIntoView({
  4359. pageNumber: pageNumber || this.page,
  4360. destArray: dest,
  4361. allowNegativeOffset: true
  4362. });
  4363. } else if (pageNumber) {
  4364. this.page = pageNumber;
  4365. }
  4366. if (params.has("pagemode")) {
  4367. this.eventBus.dispatch("pagemode", {
  4368. source: this,
  4369. mode: params.get("pagemode")
  4370. });
  4371. }
  4372. if (params.has("nameddest")) {
  4373. this.goToDestination(params.get("nameddest"));
  4374. }
  4375. return;
  4376. }
  4377. dest = unescape(hash);
  4378. try {
  4379. dest = JSON.parse(dest);
  4380. if (!Array.isArray(dest)) {
  4381. dest = dest.toString();
  4382. }
  4383. } catch {}
  4384. if (typeof dest === "string" || isValidExplicitDest(dest)) {
  4385. this.goToDestination(dest);
  4386. return;
  4387. }
  4388. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  4389. }
  4390. executeNamedAction(action) {
  4391. if (!this.pdfDocument) {
  4392. return;
  4393. }
  4394. switch (action) {
  4395. case "GoBack":
  4396. this.pdfHistory?.back();
  4397. break;
  4398. case "GoForward":
  4399. this.pdfHistory?.forward();
  4400. break;
  4401. case "NextPage":
  4402. this.pdfViewer.nextPage();
  4403. break;
  4404. case "PrevPage":
  4405. this.pdfViewer.previousPage();
  4406. break;
  4407. case "LastPage":
  4408. this.page = this.pagesCount;
  4409. break;
  4410. case "FirstPage":
  4411. this.page = 1;
  4412. break;
  4413. default:
  4414. break;
  4415. }
  4416. this.eventBus.dispatch("namedaction", {
  4417. source: this,
  4418. action
  4419. });
  4420. }
  4421. async executeSetOCGState(action) {
  4422. if (!this.pdfDocument) {
  4423. return;
  4424. }
  4425. const pdfDocument = this.pdfDocument,
  4426. optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  4427. if (pdfDocument !== this.pdfDocument) {
  4428. return;
  4429. }
  4430. optionalContentConfig.setOCGState(action);
  4431. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  4432. }
  4433. }
  4434. class SimpleLinkService extends PDFLinkService {
  4435. setDocument(pdfDocument, baseUrl = null) {}
  4436. }
  4437. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.constructor.js
  4438. var es_iterator_constructor = __webpack_require__(8111);
  4439. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.some.js
  4440. var es_iterator_some = __webpack_require__(3579);
  4441. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.promise.with-resolvers.js
  4442. var es_promise_with_resolvers = __webpack_require__(4628);
  4443. // EXTERNAL MODULE: ./node_modules/core-js/modules/web.url.parse.js
  4444. var web_url_parse = __webpack_require__(5781);
  4445. ;// ./web/event_utils.js
  4446. const WaitOnType = {
  4447. EVENT: "event",
  4448. TIMEOUT: "timeout"
  4449. };
  4450. async function waitOnEventOrTimeout({
  4451. target,
  4452. name,
  4453. delay = 0
  4454. }) {
  4455. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  4456. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  4457. }
  4458. const {
  4459. promise,
  4460. resolve
  4461. } = Promise.withResolvers();
  4462. const ac = new AbortController();
  4463. function handler(type) {
  4464. ac.abort();
  4465. clearTimeout(timeout);
  4466. resolve(type);
  4467. }
  4468. const evtMethod = target instanceof EventBus ? "_on" : "addEventListener";
  4469. target[evtMethod](name, handler.bind(null, WaitOnType.EVENT), {
  4470. signal: ac.signal
  4471. });
  4472. const timeout = setTimeout(handler.bind(null, WaitOnType.TIMEOUT), delay);
  4473. return promise;
  4474. }
  4475. class EventBus {
  4476. #listeners = Object.create(null);
  4477. on(eventName, listener, options = null) {
  4478. this._on(eventName, listener, {
  4479. external: true,
  4480. once: options?.once,
  4481. signal: options?.signal
  4482. });
  4483. }
  4484. off(eventName, listener, options = null) {
  4485. this._off(eventName, listener);
  4486. }
  4487. dispatch(eventName, data) {
  4488. const eventListeners = this.#listeners[eventName];
  4489. if (!eventListeners || eventListeners.length === 0) {
  4490. return;
  4491. }
  4492. let externalListeners;
  4493. for (const {
  4494. listener,
  4495. external,
  4496. once
  4497. } of eventListeners.slice(0)) {
  4498. if (once) {
  4499. this._off(eventName, listener);
  4500. }
  4501. if (external) {
  4502. (externalListeners ||= []).push(listener);
  4503. continue;
  4504. }
  4505. listener(data);
  4506. }
  4507. if (externalListeners) {
  4508. for (const listener of externalListeners) {
  4509. listener(data);
  4510. }
  4511. externalListeners = null;
  4512. }
  4513. }
  4514. _on(eventName, listener, options = null) {
  4515. let rmAbort = null;
  4516. if (options?.signal instanceof AbortSignal) {
  4517. const {
  4518. signal
  4519. } = options;
  4520. if (signal.aborted) {
  4521. console.error("Cannot use an `aborted` signal.");
  4522. return;
  4523. }
  4524. const onAbort = () => this._off(eventName, listener);
  4525. rmAbort = () => signal.removeEventListener("abort", onAbort);
  4526. signal.addEventListener("abort", onAbort);
  4527. }
  4528. const eventListeners = this.#listeners[eventName] ||= [];
  4529. eventListeners.push({
  4530. listener,
  4531. external: options?.external === true,
  4532. once: options?.once === true,
  4533. rmAbort
  4534. });
  4535. }
  4536. _off(eventName, listener, options = null) {
  4537. const eventListeners = this.#listeners[eventName];
  4538. if (!eventListeners) {
  4539. return;
  4540. }
  4541. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  4542. const evt = eventListeners[i];
  4543. if (evt.listener === listener) {
  4544. evt.rmAbort?.();
  4545. eventListeners.splice(i, 1);
  4546. return;
  4547. }
  4548. }
  4549. }
  4550. }
  4551. class FirefoxEventBus extends EventBus {
  4552. #externalServices;
  4553. #globalEventNames;
  4554. #isInAutomation;
  4555. constructor(globalEventNames, externalServices, isInAutomation) {
  4556. super();
  4557. this.#globalEventNames = globalEventNames;
  4558. this.#externalServices = externalServices;
  4559. this.#isInAutomation = isInAutomation;
  4560. }
  4561. dispatch(eventName, data) {
  4562. throw new Error("Not implemented: FirefoxEventBus.dispatch");
  4563. }
  4564. }
  4565. ;// ./web/external_services.js
  4566. class BaseExternalServices {
  4567. updateFindControlState(data) {}
  4568. updateFindMatchesCount(data) {}
  4569. initPassiveLoading() {}
  4570. reportTelemetry(data) {}
  4571. async createL10n() {
  4572. throw new Error("Not implemented: createL10n");
  4573. }
  4574. createScripting() {
  4575. throw new Error("Not implemented: createScripting");
  4576. }
  4577. createSignatureStorage() {
  4578. throw new Error("Not implemented: createSignatureStorage");
  4579. }
  4580. updateEditorStates(data) {
  4581. throw new Error("Not implemented: updateEditorStates");
  4582. }
  4583. dispatchGlobalEvent(_event) {}
  4584. }
  4585. ;// ./web/preferences.js
  4586. class BasePreferences {
  4587. #defaults = Object.freeze({
  4588. altTextLearnMoreUrl: "",
  4589. annotationEditorMode: 0,
  4590. annotationMode: 2,
  4591. capCanvasAreaFactor: 200,
  4592. cursorToolOnLoad: 0,
  4593. defaultZoomDelay: 400,
  4594. defaultZoomValue: "",
  4595. disablePageLabels: false,
  4596. enableAltText: false,
  4597. enableAltTextModelDownload: true,
  4598. enableAutoLinking: true,
  4599. enableGuessAltText: true,
  4600. enableHighlightFloatingButton: false,
  4601. enableNewAltTextWhenAddingImage: true,
  4602. enablePermissions: false,
  4603. enablePrintAutoRotate: true,
  4604. enableScripting: true,
  4605. enableSignatureEditor: false,
  4606. enableUpdatedAddImage: false,
  4607. externalLinkTarget: 0,
  4608. highlightEditorColors: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F",
  4609. historyUpdateUrl: false,
  4610. ignoreDestinationZoom: false,
  4611. forcePageColors: false,
  4612. pageColorsBackground: "Canvas",
  4613. pageColorsForeground: "CanvasText",
  4614. pdfBugEnabled: false,
  4615. sidebarViewOnLoad: -1,
  4616. scrollModeOnLoad: -1,
  4617. spreadModeOnLoad: -1,
  4618. textLayerMode: 1,
  4619. viewerCssTheme: 0,
  4620. viewOnLoad: 0,
  4621. disableAutoFetch: false,
  4622. disableFontFace: false,
  4623. disableRange: false,
  4624. disableStream: false,
  4625. enableHWA: true,
  4626. enableXfa: true
  4627. });
  4628. #initializedPromise = null;
  4629. constructor() {
  4630. this.#initializedPromise = this._readFromStorage(this.#defaults).then(({
  4631. browserPrefs,
  4632. prefs
  4633. }) => {
  4634. if (AppOptions._checkDisablePreferences()) {
  4635. return;
  4636. }
  4637. AppOptions.setAll({
  4638. ...browserPrefs,
  4639. ...prefs
  4640. }, true);
  4641. });
  4642. }
  4643. async _writeToStorage(prefObj) {
  4644. throw new Error("Not implemented: _writeToStorage");
  4645. }
  4646. async _readFromStorage(prefObj) {
  4647. throw new Error("Not implemented: _readFromStorage");
  4648. }
  4649. async reset() {
  4650. await this.#initializedPromise;
  4651. AppOptions.setAll(this.#defaults, true);
  4652. await this._writeToStorage(this.#defaults);
  4653. }
  4654. async set(name, value) {
  4655. await this.#initializedPromise;
  4656. AppOptions.setAll({
  4657. [name]: value
  4658. }, true);
  4659. await this._writeToStorage(AppOptions.getAll(OptionKind.PREFERENCE));
  4660. }
  4661. async get(name) {
  4662. await this.#initializedPromise;
  4663. return AppOptions.get(name);
  4664. }
  4665. get initializedPromise() {
  4666. return this.#initializedPromise;
  4667. }
  4668. }
  4669. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.map.js
  4670. var es_iterator_map = __webpack_require__(1701);
  4671. ;// ./node_modules/@fluent/bundle/esm/types.js
  4672. class FluentType {
  4673. constructor(value) {
  4674. this.value = value;
  4675. }
  4676. valueOf() {
  4677. return this.value;
  4678. }
  4679. }
  4680. class FluentNone extends FluentType {
  4681. constructor(value = "???") {
  4682. super(value);
  4683. }
  4684. toString(scope) {
  4685. return `{${this.value}}`;
  4686. }
  4687. }
  4688. class FluentNumber extends FluentType {
  4689. constructor(value, opts = {}) {
  4690. super(value);
  4691. this.opts = opts;
  4692. }
  4693. toString(scope) {
  4694. if (scope) {
  4695. try {
  4696. const nf = scope.memoizeIntlObject(Intl.NumberFormat, this.opts);
  4697. return nf.format(this.value);
  4698. } catch (err) {
  4699. scope.reportError(err);
  4700. }
  4701. }
  4702. return this.value.toString(10);
  4703. }
  4704. }
  4705. class FluentDateTime extends FluentType {
  4706. static supportsValue(value) {
  4707. if (typeof value === "number") return true;
  4708. if (value instanceof Date) return true;
  4709. if (value instanceof FluentType) return FluentDateTime.supportsValue(value.valueOf());
  4710. if ("Temporal" in globalThis) {
  4711. const _Temporal = globalThis.Temporal;
  4712. if (value instanceof _Temporal.Instant || value instanceof _Temporal.PlainDateTime || value instanceof _Temporal.PlainDate || value instanceof _Temporal.PlainMonthDay || value instanceof _Temporal.PlainTime || value instanceof _Temporal.PlainYearMonth) {
  4713. return true;
  4714. }
  4715. }
  4716. return false;
  4717. }
  4718. constructor(value, opts = {}) {
  4719. if (value instanceof FluentDateTime) {
  4720. opts = {
  4721. ...value.opts,
  4722. ...opts
  4723. };
  4724. value = value.value;
  4725. } else if (value instanceof FluentType) {
  4726. value = value.valueOf();
  4727. }
  4728. if (typeof value === "object" && "calendarId" in value && opts.calendar === undefined) {
  4729. opts = {
  4730. ...opts,
  4731. calendar: value.calendarId
  4732. };
  4733. }
  4734. super(value);
  4735. this.opts = opts;
  4736. }
  4737. [Symbol.toPrimitive](hint) {
  4738. return hint === "string" ? this.toString() : this.toNumber();
  4739. }
  4740. toNumber() {
  4741. const value = this.value;
  4742. if (typeof value === "number") return value;
  4743. if (value instanceof Date) return value.getTime();
  4744. if ("epochMilliseconds" in value) {
  4745. return value.epochMilliseconds;
  4746. }
  4747. if ("toZonedDateTime" in value) {
  4748. return value.toZonedDateTime("UTC").epochMilliseconds;
  4749. }
  4750. throw new TypeError("Unwrapping a non-number value as a number");
  4751. }
  4752. toString(scope) {
  4753. if (scope) {
  4754. try {
  4755. const dtf = scope.memoizeIntlObject(Intl.DateTimeFormat, this.opts);
  4756. return dtf.format(this.value);
  4757. } catch (err) {
  4758. scope.reportError(err);
  4759. }
  4760. }
  4761. if (typeof this.value === "number" || this.value instanceof Date) {
  4762. return new Date(this.value).toISOString();
  4763. }
  4764. return this.value.toString();
  4765. }
  4766. }
  4767. ;// ./node_modules/@fluent/bundle/esm/resolver.js
  4768. const MAX_PLACEABLES = 100;
  4769. const FSI = "\u2068";
  4770. const PDI = "\u2069";
  4771. function match(scope, selector, key) {
  4772. if (key === selector) {
  4773. return true;
  4774. }
  4775. if (key instanceof FluentNumber && selector instanceof FluentNumber && key.value === selector.value) {
  4776. return true;
  4777. }
  4778. if (selector instanceof FluentNumber && typeof key === "string") {
  4779. let category = scope.memoizeIntlObject(Intl.PluralRules, selector.opts).select(selector.value);
  4780. if (key === category) {
  4781. return true;
  4782. }
  4783. }
  4784. return false;
  4785. }
  4786. function getDefault(scope, variants, star) {
  4787. if (variants[star]) {
  4788. return resolvePattern(scope, variants[star].value);
  4789. }
  4790. scope.reportError(new RangeError("No default"));
  4791. return new FluentNone();
  4792. }
  4793. function getArguments(scope, args) {
  4794. const positional = [];
  4795. const named = Object.create(null);
  4796. for (const arg of args) {
  4797. if (arg.type === "narg") {
  4798. named[arg.name] = resolveExpression(scope, arg.value);
  4799. } else {
  4800. positional.push(resolveExpression(scope, arg));
  4801. }
  4802. }
  4803. return {
  4804. positional,
  4805. named
  4806. };
  4807. }
  4808. function resolveExpression(scope, expr) {
  4809. switch (expr.type) {
  4810. case "str":
  4811. return expr.value;
  4812. case "num":
  4813. return new FluentNumber(expr.value, {
  4814. minimumFractionDigits: expr.precision
  4815. });
  4816. case "var":
  4817. return resolveVariableReference(scope, expr);
  4818. case "mesg":
  4819. return resolveMessageReference(scope, expr);
  4820. case "term":
  4821. return resolveTermReference(scope, expr);
  4822. case "func":
  4823. return resolveFunctionReference(scope, expr);
  4824. case "select":
  4825. return resolveSelectExpression(scope, expr);
  4826. default:
  4827. return new FluentNone();
  4828. }
  4829. }
  4830. function resolveVariableReference(scope, {
  4831. name
  4832. }) {
  4833. let arg;
  4834. if (scope.params) {
  4835. if (Object.prototype.hasOwnProperty.call(scope.params, name)) {
  4836. arg = scope.params[name];
  4837. } else {
  4838. return new FluentNone(`$${name}`);
  4839. }
  4840. } else if (scope.args && Object.prototype.hasOwnProperty.call(scope.args, name)) {
  4841. arg = scope.args[name];
  4842. } else {
  4843. scope.reportError(new ReferenceError(`Unknown variable: $${name}`));
  4844. return new FluentNone(`$${name}`);
  4845. }
  4846. if (arg instanceof FluentType) {
  4847. return arg;
  4848. }
  4849. switch (typeof arg) {
  4850. case "string":
  4851. return arg;
  4852. case "number":
  4853. return new FluentNumber(arg);
  4854. case "object":
  4855. if (FluentDateTime.supportsValue(arg)) {
  4856. return new FluentDateTime(arg);
  4857. }
  4858. default:
  4859. scope.reportError(new TypeError(`Variable type not supported: $${name}, ${typeof arg}`));
  4860. return new FluentNone(`$${name}`);
  4861. }
  4862. }
  4863. function resolveMessageReference(scope, {
  4864. name,
  4865. attr
  4866. }) {
  4867. const message = scope.bundle._messages.get(name);
  4868. if (!message) {
  4869. scope.reportError(new ReferenceError(`Unknown message: ${name}`));
  4870. return new FluentNone(name);
  4871. }
  4872. if (attr) {
  4873. const attribute = message.attributes[attr];
  4874. if (attribute) {
  4875. return resolvePattern(scope, attribute);
  4876. }
  4877. scope.reportError(new ReferenceError(`Unknown attribute: ${attr}`));
  4878. return new FluentNone(`${name}.${attr}`);
  4879. }
  4880. if (message.value) {
  4881. return resolvePattern(scope, message.value);
  4882. }
  4883. scope.reportError(new ReferenceError(`No value: ${name}`));
  4884. return new FluentNone(name);
  4885. }
  4886. function resolveTermReference(scope, {
  4887. name,
  4888. attr,
  4889. args
  4890. }) {
  4891. const id = `-${name}`;
  4892. const term = scope.bundle._terms.get(id);
  4893. if (!term) {
  4894. scope.reportError(new ReferenceError(`Unknown term: ${id}`));
  4895. return new FluentNone(id);
  4896. }
  4897. if (attr) {
  4898. const attribute = term.attributes[attr];
  4899. if (attribute) {
  4900. scope.params = getArguments(scope, args).named;
  4901. const resolved = resolvePattern(scope, attribute);
  4902. scope.params = null;
  4903. return resolved;
  4904. }
  4905. scope.reportError(new ReferenceError(`Unknown attribute: ${attr}`));
  4906. return new FluentNone(`${id}.${attr}`);
  4907. }
  4908. scope.params = getArguments(scope, args).named;
  4909. const resolved = resolvePattern(scope, term.value);
  4910. scope.params = null;
  4911. return resolved;
  4912. }
  4913. function resolveFunctionReference(scope, {
  4914. name,
  4915. args
  4916. }) {
  4917. let func = scope.bundle._functions[name];
  4918. if (!func) {
  4919. scope.reportError(new ReferenceError(`Unknown function: ${name}()`));
  4920. return new FluentNone(`${name}()`);
  4921. }
  4922. if (typeof func !== "function") {
  4923. scope.reportError(new TypeError(`Function ${name}() is not callable`));
  4924. return new FluentNone(`${name}()`);
  4925. }
  4926. try {
  4927. let resolved = getArguments(scope, args);
  4928. return func(resolved.positional, resolved.named);
  4929. } catch (err) {
  4930. scope.reportError(err);
  4931. return new FluentNone(`${name}()`);
  4932. }
  4933. }
  4934. function resolveSelectExpression(scope, {
  4935. selector,
  4936. variants,
  4937. star
  4938. }) {
  4939. let sel = resolveExpression(scope, selector);
  4940. if (sel instanceof FluentNone) {
  4941. return getDefault(scope, variants, star);
  4942. }
  4943. for (const variant of variants) {
  4944. const key = resolveExpression(scope, variant.key);
  4945. if (match(scope, sel, key)) {
  4946. return resolvePattern(scope, variant.value);
  4947. }
  4948. }
  4949. return getDefault(scope, variants, star);
  4950. }
  4951. function resolveComplexPattern(scope, ptn) {
  4952. if (scope.dirty.has(ptn)) {
  4953. scope.reportError(new RangeError("Cyclic reference"));
  4954. return new FluentNone();
  4955. }
  4956. scope.dirty.add(ptn);
  4957. const result = [];
  4958. const useIsolating = scope.bundle._useIsolating && ptn.length > 1;
  4959. for (const elem of ptn) {
  4960. if (typeof elem === "string") {
  4961. result.push(scope.bundle._transform(elem));
  4962. continue;
  4963. }
  4964. scope.placeables++;
  4965. if (scope.placeables > MAX_PLACEABLES) {
  4966. scope.dirty.delete(ptn);
  4967. throw new RangeError(`Too many placeables expanded: ${scope.placeables}, ` + `max allowed is ${MAX_PLACEABLES}`);
  4968. }
  4969. if (useIsolating) {
  4970. result.push(FSI);
  4971. }
  4972. result.push(resolveExpression(scope, elem).toString(scope));
  4973. if (useIsolating) {
  4974. result.push(PDI);
  4975. }
  4976. }
  4977. scope.dirty.delete(ptn);
  4978. return result.join("");
  4979. }
  4980. function resolvePattern(scope, value) {
  4981. if (typeof value === "string") {
  4982. return scope.bundle._transform(value);
  4983. }
  4984. return resolveComplexPattern(scope, value);
  4985. }
  4986. ;// ./node_modules/@fluent/bundle/esm/scope.js
  4987. class Scope {
  4988. constructor(bundle, errors, args) {
  4989. this.dirty = new WeakSet();
  4990. this.params = null;
  4991. this.placeables = 0;
  4992. this.bundle = bundle;
  4993. this.errors = errors;
  4994. this.args = args;
  4995. }
  4996. reportError(error) {
  4997. if (!this.errors || !(error instanceof Error)) {
  4998. throw error;
  4999. }
  5000. this.errors.push(error);
  5001. }
  5002. memoizeIntlObject(ctor, opts) {
  5003. let cache = this.bundle._intls.get(ctor);
  5004. if (!cache) {
  5005. cache = {};
  5006. this.bundle._intls.set(ctor, cache);
  5007. }
  5008. let id = JSON.stringify(opts);
  5009. if (!cache[id]) {
  5010. cache[id] = new ctor(this.bundle.locales, opts);
  5011. }
  5012. return cache[id];
  5013. }
  5014. }
  5015. ;// ./node_modules/@fluent/bundle/esm/builtins.js
  5016. function values(opts, allowed) {
  5017. const unwrapped = Object.create(null);
  5018. for (const [name, opt] of Object.entries(opts)) {
  5019. if (allowed.includes(name)) {
  5020. unwrapped[name] = opt.valueOf();
  5021. }
  5022. }
  5023. return unwrapped;
  5024. }
  5025. const NUMBER_ALLOWED = ["unitDisplay", "currencyDisplay", "useGrouping", "minimumIntegerDigits", "minimumFractionDigits", "maximumFractionDigits", "minimumSignificantDigits", "maximumSignificantDigits"];
  5026. function NUMBER(args, opts) {
  5027. let arg = args[0];
  5028. if (arg instanceof FluentNone) {
  5029. return new FluentNone(`NUMBER(${arg.valueOf()})`);
  5030. }
  5031. if (arg instanceof FluentNumber) {
  5032. return new FluentNumber(arg.valueOf(), {
  5033. ...arg.opts,
  5034. ...values(opts, NUMBER_ALLOWED)
  5035. });
  5036. }
  5037. if (arg instanceof FluentDateTime) {
  5038. return new FluentNumber(arg.toNumber(), {
  5039. ...values(opts, NUMBER_ALLOWED)
  5040. });
  5041. }
  5042. throw new TypeError("Invalid argument to NUMBER");
  5043. }
  5044. const DATETIME_ALLOWED = ["dateStyle", "timeStyle", "fractionalSecondDigits", "dayPeriod", "hour12", "weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZoneName"];
  5045. function DATETIME(args, opts) {
  5046. let arg = args[0];
  5047. if (arg instanceof FluentNone) {
  5048. return new FluentNone(`DATETIME(${arg.valueOf()})`);
  5049. }
  5050. if (arg instanceof FluentDateTime || arg instanceof FluentNumber) {
  5051. return new FluentDateTime(arg, values(opts, DATETIME_ALLOWED));
  5052. }
  5053. throw new TypeError("Invalid argument to DATETIME");
  5054. }
  5055. ;// ./node_modules/@fluent/bundle/esm/memoizer.js
  5056. const cache = new Map();
  5057. function getMemoizerForLocale(locales) {
  5058. const stringLocale = Array.isArray(locales) ? locales.join(" ") : locales;
  5059. let memoizer = cache.get(stringLocale);
  5060. if (memoizer === undefined) {
  5061. memoizer = new Map();
  5062. cache.set(stringLocale, memoizer);
  5063. }
  5064. return memoizer;
  5065. }
  5066. ;// ./node_modules/@fluent/bundle/esm/bundle.js
  5067. class FluentBundle {
  5068. constructor(locales, {
  5069. functions,
  5070. useIsolating = true,
  5071. transform = v => v
  5072. } = {}) {
  5073. this._terms = new Map();
  5074. this._messages = new Map();
  5075. this.locales = Array.isArray(locales) ? locales : [locales];
  5076. this._functions = {
  5077. NUMBER: NUMBER,
  5078. DATETIME: DATETIME,
  5079. ...functions
  5080. };
  5081. this._useIsolating = useIsolating;
  5082. this._transform = transform;
  5083. this._intls = getMemoizerForLocale(locales);
  5084. }
  5085. hasMessage(id) {
  5086. return this._messages.has(id);
  5087. }
  5088. getMessage(id) {
  5089. return this._messages.get(id);
  5090. }
  5091. addResource(res, {
  5092. allowOverrides = false
  5093. } = {}) {
  5094. const errors = [];
  5095. for (let i = 0; i < res.body.length; i++) {
  5096. let entry = res.body[i];
  5097. if (entry.id.startsWith("-")) {
  5098. if (allowOverrides === false && this._terms.has(entry.id)) {
  5099. errors.push(new Error(`Attempt to override an existing term: "${entry.id}"`));
  5100. continue;
  5101. }
  5102. this._terms.set(entry.id, entry);
  5103. } else {
  5104. if (allowOverrides === false && this._messages.has(entry.id)) {
  5105. errors.push(new Error(`Attempt to override an existing message: "${entry.id}"`));
  5106. continue;
  5107. }
  5108. this._messages.set(entry.id, entry);
  5109. }
  5110. }
  5111. return errors;
  5112. }
  5113. formatPattern(pattern, args = null, errors = null) {
  5114. if (typeof pattern === "string") {
  5115. return this._transform(pattern);
  5116. }
  5117. let scope = new Scope(this, errors, args);
  5118. try {
  5119. let value = resolveComplexPattern(scope, pattern);
  5120. return value.toString(scope);
  5121. } catch (err) {
  5122. if (scope.errors && err instanceof Error) {
  5123. scope.errors.push(err);
  5124. return new FluentNone().toString(scope);
  5125. }
  5126. throw err;
  5127. }
  5128. }
  5129. }
  5130. ;// ./node_modules/@fluent/bundle/esm/resource.js
  5131. const RE_MESSAGE_START = /^(-?[a-zA-Z][\w-]*) *= */gm;
  5132. const RE_ATTRIBUTE_START = /\.([a-zA-Z][\w-]*) *= */y;
  5133. const RE_VARIANT_START = /\*?\[/y;
  5134. const RE_NUMBER_LITERAL = /(-?[0-9]+(?:\.([0-9]+))?)/y;
  5135. const RE_IDENTIFIER = /([a-zA-Z][\w-]*)/y;
  5136. const RE_REFERENCE = /([$-])?([a-zA-Z][\w-]*)(?:\.([a-zA-Z][\w-]*))?/y;
  5137. const RE_FUNCTION_NAME = /^[A-Z][A-Z0-9_-]*$/;
  5138. const RE_TEXT_RUN = /([^{}\n\r]+)/y;
  5139. const RE_STRING_RUN = /([^\\"\n\r]*)/y;
  5140. const RE_STRING_ESCAPE = /\\([\\"])/y;
  5141. const RE_UNICODE_ESCAPE = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{6})/y;
  5142. const RE_LEADING_NEWLINES = /^\n+/;
  5143. const RE_TRAILING_SPACES = / +$/;
  5144. const RE_BLANK_LINES = / *\r?\n/g;
  5145. const RE_INDENT = /( *)$/;
  5146. const TOKEN_BRACE_OPEN = /{\s*/y;
  5147. const TOKEN_BRACE_CLOSE = /\s*}/y;
  5148. const TOKEN_BRACKET_OPEN = /\[\s*/y;
  5149. const TOKEN_BRACKET_CLOSE = /\s*] */y;
  5150. const TOKEN_PAREN_OPEN = /\s*\(\s*/y;
  5151. const TOKEN_ARROW = /\s*->\s*/y;
  5152. const TOKEN_COLON = /\s*:\s*/y;
  5153. const TOKEN_COMMA = /\s*,?\s*/y;
  5154. const TOKEN_BLANK = /\s+/y;
  5155. class FluentResource {
  5156. constructor(source) {
  5157. this.body = [];
  5158. RE_MESSAGE_START.lastIndex = 0;
  5159. let cursor = 0;
  5160. while (true) {
  5161. let next = RE_MESSAGE_START.exec(source);
  5162. if (next === null) {
  5163. break;
  5164. }
  5165. cursor = RE_MESSAGE_START.lastIndex;
  5166. try {
  5167. this.body.push(parseMessage(next[1]));
  5168. } catch (err) {
  5169. if (err instanceof SyntaxError) {
  5170. continue;
  5171. }
  5172. throw err;
  5173. }
  5174. }
  5175. function test(re) {
  5176. re.lastIndex = cursor;
  5177. return re.test(source);
  5178. }
  5179. function consumeChar(char, errorClass) {
  5180. if (source[cursor] === char) {
  5181. cursor++;
  5182. return true;
  5183. }
  5184. if (errorClass) {
  5185. throw new errorClass(`Expected ${char}`);
  5186. }
  5187. return false;
  5188. }
  5189. function consumeToken(re, errorClass) {
  5190. if (test(re)) {
  5191. cursor = re.lastIndex;
  5192. return true;
  5193. }
  5194. if (errorClass) {
  5195. throw new errorClass(`Expected ${re.toString()}`);
  5196. }
  5197. return false;
  5198. }
  5199. function match(re) {
  5200. re.lastIndex = cursor;
  5201. let result = re.exec(source);
  5202. if (result === null) {
  5203. throw new SyntaxError(`Expected ${re.toString()}`);
  5204. }
  5205. cursor = re.lastIndex;
  5206. return result;
  5207. }
  5208. function match1(re) {
  5209. return match(re)[1];
  5210. }
  5211. function parseMessage(id) {
  5212. let value = parsePattern();
  5213. let attributes = parseAttributes();
  5214. if (value === null && Object.keys(attributes).length === 0) {
  5215. throw new SyntaxError("Expected message value or attributes");
  5216. }
  5217. return {
  5218. id,
  5219. value,
  5220. attributes
  5221. };
  5222. }
  5223. function parseAttributes() {
  5224. let attrs = Object.create(null);
  5225. while (test(RE_ATTRIBUTE_START)) {
  5226. let name = match1(RE_ATTRIBUTE_START);
  5227. let value = parsePattern();
  5228. if (value === null) {
  5229. throw new SyntaxError("Expected attribute value");
  5230. }
  5231. attrs[name] = value;
  5232. }
  5233. return attrs;
  5234. }
  5235. function parsePattern() {
  5236. let first;
  5237. if (test(RE_TEXT_RUN)) {
  5238. first = match1(RE_TEXT_RUN);
  5239. }
  5240. if (source[cursor] === "{" || source[cursor] === "}") {
  5241. return parsePatternElements(first ? [first] : [], Infinity);
  5242. }
  5243. let indent = parseIndent();
  5244. if (indent) {
  5245. if (first) {
  5246. return parsePatternElements([first, indent], indent.length);
  5247. }
  5248. indent.value = trim(indent.value, RE_LEADING_NEWLINES);
  5249. return parsePatternElements([indent], indent.length);
  5250. }
  5251. if (first) {
  5252. return trim(first, RE_TRAILING_SPACES);
  5253. }
  5254. return null;
  5255. }
  5256. function parsePatternElements(elements = [], commonIndent) {
  5257. while (true) {
  5258. if (test(RE_TEXT_RUN)) {
  5259. elements.push(match1(RE_TEXT_RUN));
  5260. continue;
  5261. }
  5262. if (source[cursor] === "{") {
  5263. elements.push(parsePlaceable());
  5264. continue;
  5265. }
  5266. if (source[cursor] === "}") {
  5267. throw new SyntaxError("Unbalanced closing brace");
  5268. }
  5269. let indent = parseIndent();
  5270. if (indent) {
  5271. elements.push(indent);
  5272. commonIndent = Math.min(commonIndent, indent.length);
  5273. continue;
  5274. }
  5275. break;
  5276. }
  5277. let lastIndex = elements.length - 1;
  5278. let lastElement = elements[lastIndex];
  5279. if (typeof lastElement === "string") {
  5280. elements[lastIndex] = trim(lastElement, RE_TRAILING_SPACES);
  5281. }
  5282. let baked = [];
  5283. for (let element of elements) {
  5284. if (element instanceof Indent) {
  5285. element = element.value.slice(0, element.value.length - commonIndent);
  5286. }
  5287. if (element) {
  5288. baked.push(element);
  5289. }
  5290. }
  5291. return baked;
  5292. }
  5293. function parsePlaceable() {
  5294. consumeToken(TOKEN_BRACE_OPEN, SyntaxError);
  5295. let selector = parseInlineExpression();
  5296. if (consumeToken(TOKEN_BRACE_CLOSE)) {
  5297. return selector;
  5298. }
  5299. if (consumeToken(TOKEN_ARROW)) {
  5300. let variants = parseVariants();
  5301. consumeToken(TOKEN_BRACE_CLOSE, SyntaxError);
  5302. return {
  5303. type: "select",
  5304. selector,
  5305. ...variants
  5306. };
  5307. }
  5308. throw new SyntaxError("Unclosed placeable");
  5309. }
  5310. function parseInlineExpression() {
  5311. if (source[cursor] === "{") {
  5312. return parsePlaceable();
  5313. }
  5314. if (test(RE_REFERENCE)) {
  5315. let [, sigil, name, attr = null] = match(RE_REFERENCE);
  5316. if (sigil === "$") {
  5317. return {
  5318. type: "var",
  5319. name
  5320. };
  5321. }
  5322. if (consumeToken(TOKEN_PAREN_OPEN)) {
  5323. let args = parseArguments();
  5324. if (sigil === "-") {
  5325. return {
  5326. type: "term",
  5327. name,
  5328. attr,
  5329. args
  5330. };
  5331. }
  5332. if (RE_FUNCTION_NAME.test(name)) {
  5333. return {
  5334. type: "func",
  5335. name,
  5336. args
  5337. };
  5338. }
  5339. throw new SyntaxError("Function names must be all upper-case");
  5340. }
  5341. if (sigil === "-") {
  5342. return {
  5343. type: "term",
  5344. name,
  5345. attr,
  5346. args: []
  5347. };
  5348. }
  5349. return {
  5350. type: "mesg",
  5351. name,
  5352. attr
  5353. };
  5354. }
  5355. return parseLiteral();
  5356. }
  5357. function parseArguments() {
  5358. let args = [];
  5359. while (true) {
  5360. switch (source[cursor]) {
  5361. case ")":
  5362. cursor++;
  5363. return args;
  5364. case undefined:
  5365. throw new SyntaxError("Unclosed argument list");
  5366. }
  5367. args.push(parseArgument());
  5368. consumeToken(TOKEN_COMMA);
  5369. }
  5370. }
  5371. function parseArgument() {
  5372. let expr = parseInlineExpression();
  5373. if (expr.type !== "mesg") {
  5374. return expr;
  5375. }
  5376. if (consumeToken(TOKEN_COLON)) {
  5377. return {
  5378. type: "narg",
  5379. name: expr.name,
  5380. value: parseLiteral()
  5381. };
  5382. }
  5383. return expr;
  5384. }
  5385. function parseVariants() {
  5386. let variants = [];
  5387. let count = 0;
  5388. let star;
  5389. while (test(RE_VARIANT_START)) {
  5390. if (consumeChar("*")) {
  5391. star = count;
  5392. }
  5393. let key = parseVariantKey();
  5394. let value = parsePattern();
  5395. if (value === null) {
  5396. throw new SyntaxError("Expected variant value");
  5397. }
  5398. variants[count++] = {
  5399. key,
  5400. value
  5401. };
  5402. }
  5403. if (count === 0) {
  5404. return null;
  5405. }
  5406. if (star === undefined) {
  5407. throw new SyntaxError("Expected default variant");
  5408. }
  5409. return {
  5410. variants,
  5411. star
  5412. };
  5413. }
  5414. function parseVariantKey() {
  5415. consumeToken(TOKEN_BRACKET_OPEN, SyntaxError);
  5416. let key;
  5417. if (test(RE_NUMBER_LITERAL)) {
  5418. key = parseNumberLiteral();
  5419. } else {
  5420. key = {
  5421. type: "str",
  5422. value: match1(RE_IDENTIFIER)
  5423. };
  5424. }
  5425. consumeToken(TOKEN_BRACKET_CLOSE, SyntaxError);
  5426. return key;
  5427. }
  5428. function parseLiteral() {
  5429. if (test(RE_NUMBER_LITERAL)) {
  5430. return parseNumberLiteral();
  5431. }
  5432. if (source[cursor] === '"') {
  5433. return parseStringLiteral();
  5434. }
  5435. throw new SyntaxError("Invalid expression");
  5436. }
  5437. function parseNumberLiteral() {
  5438. let [, value, fraction = ""] = match(RE_NUMBER_LITERAL);
  5439. let precision = fraction.length;
  5440. return {
  5441. type: "num",
  5442. value: parseFloat(value),
  5443. precision
  5444. };
  5445. }
  5446. function parseStringLiteral() {
  5447. consumeChar('"', SyntaxError);
  5448. let value = "";
  5449. while (true) {
  5450. value += match1(RE_STRING_RUN);
  5451. if (source[cursor] === "\\") {
  5452. value += parseEscapeSequence();
  5453. continue;
  5454. }
  5455. if (consumeChar('"')) {
  5456. return {
  5457. type: "str",
  5458. value
  5459. };
  5460. }
  5461. throw new SyntaxError("Unclosed string literal");
  5462. }
  5463. }
  5464. function parseEscapeSequence() {
  5465. if (test(RE_STRING_ESCAPE)) {
  5466. return match1(RE_STRING_ESCAPE);
  5467. }
  5468. if (test(RE_UNICODE_ESCAPE)) {
  5469. let [, codepoint4, codepoint6] = match(RE_UNICODE_ESCAPE);
  5470. let codepoint = parseInt(codepoint4 || codepoint6, 16);
  5471. return codepoint <= 0xd7ff || 0xe000 <= codepoint ? String.fromCodePoint(codepoint) : "�";
  5472. }
  5473. throw new SyntaxError("Unknown escape sequence");
  5474. }
  5475. function parseIndent() {
  5476. let start = cursor;
  5477. consumeToken(TOKEN_BLANK);
  5478. switch (source[cursor]) {
  5479. case ".":
  5480. case "[":
  5481. case "*":
  5482. case "}":
  5483. case undefined:
  5484. return false;
  5485. case "{":
  5486. return makeIndent(source.slice(start, cursor));
  5487. }
  5488. if (source[cursor - 1] === " ") {
  5489. return makeIndent(source.slice(start, cursor));
  5490. }
  5491. return false;
  5492. }
  5493. function trim(text, re) {
  5494. return text.replace(re, "");
  5495. }
  5496. function makeIndent(blank) {
  5497. let value = blank.replace(RE_BLANK_LINES, "\n");
  5498. let length = RE_INDENT.exec(blank)[1].length;
  5499. return new Indent(value, length);
  5500. }
  5501. }
  5502. }
  5503. class Indent {
  5504. constructor(value, length) {
  5505. this.value = value;
  5506. this.length = length;
  5507. }
  5508. }
  5509. ;// ./node_modules/@fluent/bundle/esm/index.js
  5510. ;// ./node_modules/@fluent/dom/esm/overlay.js
  5511. const reOverlay = /<|&#?\w+;/;
  5512. const TEXT_LEVEL_ELEMENTS = {
  5513. "http://www.w3.org/1999/xhtml": ["em", "strong", "small", "s", "cite", "q", "dfn", "abbr", "data", "time", "code", "var", "samp", "kbd", "sub", "sup", "i", "b", "u", "mark", "bdi", "bdo", "span", "br", "wbr"]
  5514. };
  5515. const LOCALIZABLE_ATTRIBUTES = {
  5516. "http://www.w3.org/1999/xhtml": {
  5517. global: ["title", "aria-description", "aria-label", "aria-valuetext"],
  5518. a: ["download"],
  5519. area: ["download", "alt"],
  5520. input: ["alt", "placeholder"],
  5521. menuitem: ["label"],
  5522. menu: ["label"],
  5523. optgroup: ["label"],
  5524. option: ["label"],
  5525. track: ["label"],
  5526. img: ["alt"],
  5527. textarea: ["placeholder"],
  5528. th: ["abbr"]
  5529. },
  5530. "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul": {
  5531. global: ["accesskey", "aria-label", "aria-valuetext", "label", "title", "tooltiptext"],
  5532. description: ["value"],
  5533. key: ["key", "keycode"],
  5534. label: ["value"],
  5535. textbox: ["placeholder", "value"]
  5536. }
  5537. };
  5538. function translateElement(element, translation) {
  5539. const {
  5540. value
  5541. } = translation;
  5542. if (typeof value === "string") {
  5543. if (element.localName === "title" && element.namespaceURI === "http://www.w3.org/1999/xhtml") {
  5544. element.textContent = value;
  5545. } else if (!reOverlay.test(value)) {
  5546. element.textContent = value;
  5547. } else {
  5548. const templateElement = element.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml", "template");
  5549. templateElement.innerHTML = value;
  5550. overlayChildNodes(templateElement.content, element);
  5551. }
  5552. }
  5553. overlayAttributes(translation, element);
  5554. }
  5555. function overlayChildNodes(fromFragment, toElement) {
  5556. for (const childNode of fromFragment.childNodes) {
  5557. if (childNode.nodeType === childNode.TEXT_NODE) {
  5558. continue;
  5559. }
  5560. if (childNode.hasAttribute("data-l10n-name")) {
  5561. const sanitized = getNodeForNamedElement(toElement, childNode);
  5562. fromFragment.replaceChild(sanitized, childNode);
  5563. continue;
  5564. }
  5565. if (isElementAllowed(childNode)) {
  5566. const sanitized = createSanitizedElement(childNode);
  5567. fromFragment.replaceChild(sanitized, childNode);
  5568. continue;
  5569. }
  5570. console.warn(`An element of forbidden type "${childNode.localName}" was found in ` + "the translation. Only safe text-level elements and elements with " + "data-l10n-name are allowed.");
  5571. fromFragment.replaceChild(createTextNodeFromTextContent(childNode), childNode);
  5572. }
  5573. toElement.textContent = "";
  5574. toElement.appendChild(fromFragment);
  5575. }
  5576. function hasAttribute(attributes, name) {
  5577. if (!attributes) {
  5578. return false;
  5579. }
  5580. for (let attr of attributes) {
  5581. if (attr.name === name) {
  5582. return true;
  5583. }
  5584. }
  5585. return false;
  5586. }
  5587. function overlayAttributes(fromElement, toElement) {
  5588. const explicitlyAllowed = toElement.hasAttribute("data-l10n-attrs") ? toElement.getAttribute("data-l10n-attrs").split(",").map(i => i.trim()) : null;
  5589. for (const attr of Array.from(toElement.attributes)) {
  5590. if (isAttrNameLocalizable(attr.name, toElement, explicitlyAllowed) && !hasAttribute(fromElement.attributes, attr.name)) {
  5591. toElement.removeAttribute(attr.name);
  5592. }
  5593. }
  5594. if (!fromElement.attributes) {
  5595. return;
  5596. }
  5597. for (const attr of Array.from(fromElement.attributes)) {
  5598. if (isAttrNameLocalizable(attr.name, toElement, explicitlyAllowed) && toElement.getAttribute(attr.name) !== attr.value) {
  5599. toElement.setAttribute(attr.name, attr.value);
  5600. }
  5601. }
  5602. }
  5603. function getNodeForNamedElement(sourceElement, translatedChild) {
  5604. const childName = translatedChild.getAttribute("data-l10n-name");
  5605. const sourceChild = sourceElement.querySelector(`[data-l10n-name="${childName}"]`);
  5606. if (!sourceChild) {
  5607. console.warn(`An element named "${childName}" wasn't found in the source.`);
  5608. return createTextNodeFromTextContent(translatedChild);
  5609. }
  5610. if (sourceChild.localName !== translatedChild.localName) {
  5611. console.warn(`An element named "${childName}" was found in the translation ` + `but its type ${translatedChild.localName} didn't match the ` + `element found in the source (${sourceChild.localName}).`);
  5612. return createTextNodeFromTextContent(translatedChild);
  5613. }
  5614. sourceElement.removeChild(sourceChild);
  5615. const clone = sourceChild.cloneNode(false);
  5616. return shallowPopulateUsing(translatedChild, clone);
  5617. }
  5618. function createSanitizedElement(element) {
  5619. const clone = element.ownerDocument.createElement(element.localName);
  5620. return shallowPopulateUsing(element, clone);
  5621. }
  5622. function createTextNodeFromTextContent(element) {
  5623. return element.ownerDocument.createTextNode(element.textContent);
  5624. }
  5625. function isElementAllowed(element) {
  5626. const allowed = TEXT_LEVEL_ELEMENTS[element.namespaceURI];
  5627. return allowed && allowed.includes(element.localName);
  5628. }
  5629. function isAttrNameLocalizable(name, element, explicitlyAllowed = null) {
  5630. if (explicitlyAllowed && explicitlyAllowed.includes(name)) {
  5631. return true;
  5632. }
  5633. const allowed = LOCALIZABLE_ATTRIBUTES[element.namespaceURI];
  5634. if (!allowed) {
  5635. return false;
  5636. }
  5637. const attrName = name.toLowerCase();
  5638. const elemName = element.localName;
  5639. if (allowed.global.includes(attrName)) {
  5640. return true;
  5641. }
  5642. if (!allowed[elemName]) {
  5643. return false;
  5644. }
  5645. if (allowed[elemName].includes(attrName)) {
  5646. return true;
  5647. }
  5648. if (element.namespaceURI === "http://www.w3.org/1999/xhtml" && elemName === "input" && attrName === "value") {
  5649. const type = element.type.toLowerCase();
  5650. if (type === "submit" || type === "button" || type === "reset") {
  5651. return true;
  5652. }
  5653. }
  5654. return false;
  5655. }
  5656. function shallowPopulateUsing(fromElement, toElement) {
  5657. toElement.textContent = fromElement.textContent;
  5658. overlayAttributes(fromElement, toElement);
  5659. return toElement;
  5660. }
  5661. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.filter.js
  5662. var es_iterator_filter = __webpack_require__(2489);
  5663. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.for-each.js
  5664. var es_iterator_for_each = __webpack_require__(7588);
  5665. ;// ./node_modules/cached-iterable/src/cached_iterable.mjs
  5666. class CachedIterable extends Array {
  5667. static from(iterable) {
  5668. if (iterable instanceof this) {
  5669. return iterable;
  5670. }
  5671. return new this(iterable);
  5672. }
  5673. }
  5674. ;// ./node_modules/cached-iterable/src/cached_sync_iterable.mjs
  5675. class CachedSyncIterable extends CachedIterable {
  5676. constructor(iterable) {
  5677. super();
  5678. if (Symbol.iterator in Object(iterable)) {
  5679. this.iterator = iterable[Symbol.iterator]();
  5680. } else {
  5681. throw new TypeError("Argument must implement the iteration protocol.");
  5682. }
  5683. }
  5684. [Symbol.iterator]() {
  5685. const cached = this;
  5686. let cur = 0;
  5687. return {
  5688. next() {
  5689. if (cached.length <= cur) {
  5690. cached.push(cached.iterator.next());
  5691. }
  5692. return cached[cur++];
  5693. }
  5694. };
  5695. }
  5696. touchNext(count = 1) {
  5697. let idx = 0;
  5698. while (idx++ < count) {
  5699. const last = this[this.length - 1];
  5700. if (last && last.done) {
  5701. break;
  5702. }
  5703. this.push(this.iterator.next());
  5704. }
  5705. return this[this.length - 1];
  5706. }
  5707. }
  5708. ;// ./node_modules/cached-iterable/src/cached_async_iterable.mjs
  5709. class CachedAsyncIterable extends CachedIterable {
  5710. constructor(iterable) {
  5711. super();
  5712. if (Symbol.asyncIterator in Object(iterable)) {
  5713. this.iterator = iterable[Symbol.asyncIterator]();
  5714. } else if (Symbol.iterator in Object(iterable)) {
  5715. this.iterator = iterable[Symbol.iterator]();
  5716. } else {
  5717. throw new TypeError("Argument must implement the iteration protocol.");
  5718. }
  5719. }
  5720. [Symbol.asyncIterator]() {
  5721. const cached = this;
  5722. let cur = 0;
  5723. return {
  5724. async next() {
  5725. if (cached.length <= cur) {
  5726. cached.push(cached.iterator.next());
  5727. }
  5728. return cached[cur++];
  5729. }
  5730. };
  5731. }
  5732. async touchNext(count = 1) {
  5733. let idx = 0;
  5734. while (idx++ < count) {
  5735. const last = this[this.length - 1];
  5736. if (last && (await last).done) {
  5737. break;
  5738. }
  5739. this.push(this.iterator.next());
  5740. }
  5741. return this[this.length - 1];
  5742. }
  5743. }
  5744. ;// ./node_modules/cached-iterable/src/index.mjs
  5745. ;// ./node_modules/@fluent/dom/esm/localization.js
  5746. class Localization {
  5747. constructor(resourceIds = [], generateBundles) {
  5748. this.resourceIds = resourceIds;
  5749. this.generateBundles = generateBundles;
  5750. this.onChange(true);
  5751. }
  5752. addResourceIds(resourceIds, eager = false) {
  5753. this.resourceIds.push(...resourceIds);
  5754. this.onChange(eager);
  5755. return this.resourceIds.length;
  5756. }
  5757. removeResourceIds(resourceIds) {
  5758. this.resourceIds = this.resourceIds.filter(r => !resourceIds.includes(r));
  5759. this.onChange();
  5760. return this.resourceIds.length;
  5761. }
  5762. async formatWithFallback(keys, method) {
  5763. const translations = [];
  5764. let hasAtLeastOneBundle = false;
  5765. for await (const bundle of this.bundles) {
  5766. hasAtLeastOneBundle = true;
  5767. const missingIds = keysFromBundle(method, bundle, keys, translations);
  5768. if (missingIds.size === 0) {
  5769. break;
  5770. }
  5771. if (typeof console !== "undefined") {
  5772. const locale = bundle.locales[0];
  5773. const ids = Array.from(missingIds).join(", ");
  5774. console.warn(`[fluent] Missing translations in ${locale}: ${ids}`);
  5775. }
  5776. }
  5777. if (!hasAtLeastOneBundle && typeof console !== "undefined") {
  5778. console.warn(`[fluent] Request for keys failed because no resource bundles got generated.
  5779. keys: ${JSON.stringify(keys)}.
  5780. resourceIds: ${JSON.stringify(this.resourceIds)}.`);
  5781. }
  5782. return translations;
  5783. }
  5784. formatMessages(keys) {
  5785. return this.formatWithFallback(keys, messageFromBundle);
  5786. }
  5787. formatValues(keys) {
  5788. return this.formatWithFallback(keys, valueFromBundle);
  5789. }
  5790. async formatValue(id, args) {
  5791. const [val] = await this.formatValues([{
  5792. id,
  5793. args
  5794. }]);
  5795. return val;
  5796. }
  5797. handleEvent() {
  5798. this.onChange();
  5799. }
  5800. onChange(eager = false) {
  5801. this.bundles = CachedAsyncIterable.from(this.generateBundles(this.resourceIds));
  5802. if (eager) {
  5803. this.bundles.touchNext(2);
  5804. }
  5805. }
  5806. }
  5807. function valueFromBundle(bundle, errors, message, args) {
  5808. if (message.value) {
  5809. return bundle.formatPattern(message.value, args, errors);
  5810. }
  5811. return null;
  5812. }
  5813. function messageFromBundle(bundle, errors, message, args) {
  5814. const formatted = {
  5815. value: null,
  5816. attributes: null
  5817. };
  5818. if (message.value) {
  5819. formatted.value = bundle.formatPattern(message.value, args, errors);
  5820. }
  5821. let attrNames = Object.keys(message.attributes);
  5822. if (attrNames.length > 0) {
  5823. formatted.attributes = new Array(attrNames.length);
  5824. for (let [i, name] of attrNames.entries()) {
  5825. let value = bundle.formatPattern(message.attributes[name], args, errors);
  5826. formatted.attributes[i] = {
  5827. name,
  5828. value
  5829. };
  5830. }
  5831. }
  5832. return formatted;
  5833. }
  5834. function keysFromBundle(method, bundle, keys, translations) {
  5835. const messageErrors = [];
  5836. const missingIds = new Set();
  5837. keys.forEach(({
  5838. id,
  5839. args
  5840. }, i) => {
  5841. if (translations[i] !== undefined) {
  5842. return;
  5843. }
  5844. let message = bundle.getMessage(id);
  5845. if (message) {
  5846. messageErrors.length = 0;
  5847. translations[i] = method(bundle, messageErrors, message, args);
  5848. if (messageErrors.length > 0 && typeof console !== "undefined") {
  5849. const locale = bundle.locales[0];
  5850. const errors = messageErrors.join(", ");
  5851. console.warn(`[fluent][resolver] errors in ${locale}/${id}: ${errors}.`);
  5852. }
  5853. } else {
  5854. missingIds.add(id);
  5855. }
  5856. });
  5857. return missingIds;
  5858. }
  5859. ;// ./node_modules/@fluent/dom/esm/dom_localization.js
  5860. const L10NID_ATTR_NAME = "data-l10n-id";
  5861. const L10NARGS_ATTR_NAME = "data-l10n-args";
  5862. const L10N_ELEMENT_QUERY = `[${L10NID_ATTR_NAME}]`;
  5863. class DOMLocalization extends Localization {
  5864. constructor(resourceIds, generateBundles) {
  5865. super(resourceIds, generateBundles);
  5866. this.roots = new Set();
  5867. this.pendingrAF = null;
  5868. this.pendingElements = new Set();
  5869. this.windowElement = null;
  5870. this.mutationObserver = null;
  5871. this.observerConfig = {
  5872. attributes: true,
  5873. characterData: false,
  5874. childList: true,
  5875. subtree: true,
  5876. attributeFilter: [L10NID_ATTR_NAME, L10NARGS_ATTR_NAME]
  5877. };
  5878. }
  5879. onChange(eager = false) {
  5880. super.onChange(eager);
  5881. if (this.roots) {
  5882. this.translateRoots();
  5883. }
  5884. }
  5885. setAttributes(element, id, args) {
  5886. element.setAttribute(L10NID_ATTR_NAME, id);
  5887. if (args) {
  5888. element.setAttribute(L10NARGS_ATTR_NAME, JSON.stringify(args));
  5889. } else {
  5890. element.removeAttribute(L10NARGS_ATTR_NAME);
  5891. }
  5892. return element;
  5893. }
  5894. getAttributes(element) {
  5895. return {
  5896. id: element.getAttribute(L10NID_ATTR_NAME),
  5897. args: JSON.parse(element.getAttribute(L10NARGS_ATTR_NAME) || null)
  5898. };
  5899. }
  5900. connectRoot(newRoot) {
  5901. for (const root of this.roots) {
  5902. if (root === newRoot || root.contains(newRoot) || newRoot.contains(root)) {
  5903. throw new Error("Cannot add a root that overlaps with existing root.");
  5904. }
  5905. }
  5906. if (this.windowElement) {
  5907. if (this.windowElement !== newRoot.ownerDocument.defaultView) {
  5908. throw new Error(`Cannot connect a root:
  5909. DOMLocalization already has a root from a different window.`);
  5910. }
  5911. } else {
  5912. this.windowElement = newRoot.ownerDocument.defaultView;
  5913. this.mutationObserver = new this.windowElement.MutationObserver(mutations => this.translateMutations(mutations));
  5914. }
  5915. this.roots.add(newRoot);
  5916. this.mutationObserver.observe(newRoot, this.observerConfig);
  5917. }
  5918. disconnectRoot(root) {
  5919. this.roots.delete(root);
  5920. this.pauseObserving();
  5921. if (this.roots.size === 0) {
  5922. this.mutationObserver = null;
  5923. if (this.windowElement && this.pendingrAF) {
  5924. this.windowElement.cancelAnimationFrame(this.pendingrAF);
  5925. }
  5926. this.windowElement = null;
  5927. this.pendingrAF = null;
  5928. this.pendingElements.clear();
  5929. return true;
  5930. }
  5931. this.resumeObserving();
  5932. return false;
  5933. }
  5934. translateRoots() {
  5935. const roots = Array.from(this.roots);
  5936. return Promise.all(roots.map(root => this.translateFragment(root)));
  5937. }
  5938. pauseObserving() {
  5939. if (!this.mutationObserver) {
  5940. return;
  5941. }
  5942. this.translateMutations(this.mutationObserver.takeRecords());
  5943. this.mutationObserver.disconnect();
  5944. }
  5945. resumeObserving() {
  5946. if (!this.mutationObserver) {
  5947. return;
  5948. }
  5949. for (const root of this.roots) {
  5950. this.mutationObserver.observe(root, this.observerConfig);
  5951. }
  5952. }
  5953. translateMutations(mutations) {
  5954. for (const mutation of mutations) {
  5955. switch (mutation.type) {
  5956. case "attributes":
  5957. if (mutation.target.hasAttribute("data-l10n-id")) {
  5958. this.pendingElements.add(mutation.target);
  5959. }
  5960. break;
  5961. case "childList":
  5962. for (const addedNode of mutation.addedNodes) {
  5963. if (addedNode.nodeType === addedNode.ELEMENT_NODE) {
  5964. if (addedNode.childElementCount) {
  5965. for (const element of this.getTranslatables(addedNode)) {
  5966. this.pendingElements.add(element);
  5967. }
  5968. } else if (addedNode.hasAttribute(L10NID_ATTR_NAME)) {
  5969. this.pendingElements.add(addedNode);
  5970. }
  5971. }
  5972. }
  5973. break;
  5974. }
  5975. }
  5976. if (this.pendingElements.size > 0) {
  5977. if (this.pendingrAF === null) {
  5978. this.pendingrAF = this.windowElement.requestAnimationFrame(() => {
  5979. this.translateElements(Array.from(this.pendingElements));
  5980. this.pendingElements.clear();
  5981. this.pendingrAF = null;
  5982. });
  5983. }
  5984. }
  5985. }
  5986. translateFragment(frag) {
  5987. return this.translateElements(this.getTranslatables(frag));
  5988. }
  5989. async translateElements(elements) {
  5990. if (!elements.length) {
  5991. return undefined;
  5992. }
  5993. const keys = elements.map(this.getKeysForElement);
  5994. const translations = await this.formatMessages(keys);
  5995. return this.applyTranslations(elements, translations);
  5996. }
  5997. applyTranslations(elements, translations) {
  5998. this.pauseObserving();
  5999. for (let i = 0; i < elements.length; i++) {
  6000. if (translations[i] !== undefined) {
  6001. translateElement(elements[i], translations[i]);
  6002. }
  6003. }
  6004. this.resumeObserving();
  6005. }
  6006. getTranslatables(element) {
  6007. const nodes = Array.from(element.querySelectorAll(L10N_ELEMENT_QUERY));
  6008. if (typeof element.hasAttribute === "function" && element.hasAttribute(L10NID_ATTR_NAME)) {
  6009. nodes.push(element);
  6010. }
  6011. return nodes;
  6012. }
  6013. getKeysForElement(element) {
  6014. return {
  6015. id: element.getAttribute(L10NID_ATTR_NAME),
  6016. args: JSON.parse(element.getAttribute(L10NARGS_ATTR_NAME) || null)
  6017. };
  6018. }
  6019. }
  6020. ;// ./node_modules/@fluent/dom/esm/index.js
  6021. ;// ./web/l10n.js
  6022. class L10n {
  6023. #dir;
  6024. #elements;
  6025. #lang;
  6026. #l10n;
  6027. constructor({
  6028. lang,
  6029. isRTL
  6030. }, l10n = null) {
  6031. this.#lang = L10n.#fixupLangCode(lang);
  6032. this.#l10n = l10n;
  6033. this.#dir = isRTL ?? L10n.#isRTL(this.#lang) ? "rtl" : "ltr";
  6034. }
  6035. _setL10n(l10n) {
  6036. this.#l10n = l10n;
  6037. }
  6038. getLanguage() {
  6039. return this.#lang;
  6040. }
  6041. getDirection() {
  6042. return this.#dir;
  6043. }
  6044. async get(ids, args = null, fallback) {
  6045. if (Array.isArray(ids)) {
  6046. ids = ids.map(id => ({
  6047. id
  6048. }));
  6049. const messages = await this.#l10n.formatMessages(ids);
  6050. return messages.map(message => message.value);
  6051. }
  6052. const messages = await this.#l10n.formatMessages([{
  6053. id: ids,
  6054. args
  6055. }]);
  6056. return messages[0]?.value || fallback;
  6057. }
  6058. async translate(element) {
  6059. (this.#elements ||= new Set()).add(element);
  6060. try {
  6061. this.#l10n.connectRoot(element);
  6062. await this.#l10n.translateRoots();
  6063. } catch {}
  6064. }
  6065. async translateOnce(element) {
  6066. try {
  6067. await this.#l10n.translateElements([element]);
  6068. } catch (ex) {
  6069. console.error("translateOnce:", ex);
  6070. }
  6071. }
  6072. async destroy() {
  6073. if (this.#elements) {
  6074. for (const element of this.#elements) {
  6075. this.#l10n.disconnectRoot(element);
  6076. }
  6077. this.#elements.clear();
  6078. this.#elements = null;
  6079. }
  6080. this.#l10n.pauseObserving();
  6081. }
  6082. pause() {
  6083. this.#l10n.pauseObserving();
  6084. }
  6085. resume() {
  6086. this.#l10n.resumeObserving();
  6087. }
  6088. static #fixupLangCode(langCode) {
  6089. langCode = langCode?.toLowerCase() || "en-us";
  6090. const PARTIAL_LANG_CODES = {
  6091. en: "en-us",
  6092. es: "es-es",
  6093. fy: "fy-nl",
  6094. ga: "ga-ie",
  6095. gu: "gu-in",
  6096. hi: "hi-in",
  6097. hy: "hy-am",
  6098. nb: "nb-no",
  6099. ne: "ne-np",
  6100. nn: "nn-no",
  6101. pa: "pa-in",
  6102. pt: "pt-pt",
  6103. sv: "sv-se",
  6104. zh: "zh-cn"
  6105. };
  6106. return PARTIAL_LANG_CODES[langCode] || langCode;
  6107. }
  6108. static #isRTL(lang) {
  6109. const shortCode = lang.split("-", 1)[0];
  6110. return ["ar", "he", "fa", "ps", "ur"].includes(shortCode);
  6111. }
  6112. }
  6113. const GenericL10n = null;
  6114. ;// ./web/genericl10n.js
  6115. function PLATFORM() {
  6116. const {
  6117. isAndroid,
  6118. isLinux,
  6119. isMac,
  6120. isWindows
  6121. } = FeatureTest.platform;
  6122. if (isLinux) {
  6123. return "linux";
  6124. }
  6125. if (isWindows) {
  6126. return "windows";
  6127. }
  6128. if (isMac) {
  6129. return "macos";
  6130. }
  6131. if (isAndroid) {
  6132. return "android";
  6133. }
  6134. return "other";
  6135. }
  6136. function createBundle(lang, text) {
  6137. const resource = new FluentResource(text);
  6138. const bundle = new FluentBundle(lang, {
  6139. functions: {
  6140. PLATFORM
  6141. }
  6142. });
  6143. const errors = bundle.addResource(resource);
  6144. if (errors.length) {
  6145. console.error("L10n errors", errors);
  6146. }
  6147. return bundle;
  6148. }
  6149. class genericl10n_GenericL10n extends L10n {
  6150. constructor(lang) {
  6151. super({
  6152. lang
  6153. });
  6154. const generateBundles = !lang ? genericl10n_GenericL10n.#generateBundlesFallback.bind(genericl10n_GenericL10n, this.getLanguage()) : genericl10n_GenericL10n.#generateBundles.bind(genericl10n_GenericL10n, "en-us", this.getLanguage());
  6155. this._setL10n(new DOMLocalization([], generateBundles));
  6156. }
  6157. static async *#generateBundles(defaultLang, baseLang) {
  6158. const {
  6159. baseURL,
  6160. paths
  6161. } = await this.#getPaths();
  6162. const langs = [baseLang];
  6163. if (defaultLang !== baseLang) {
  6164. const shortLang = baseLang.split("-", 1)[0];
  6165. if (shortLang !== baseLang) {
  6166. langs.push(shortLang);
  6167. }
  6168. langs.push(defaultLang);
  6169. }
  6170. const bundles = langs.map(lang => [lang, this.#createBundle(lang, baseURL, paths)]);
  6171. for (const [lang, bundlePromise] of bundles) {
  6172. const bundle = await bundlePromise;
  6173. if (bundle) {
  6174. yield bundle;
  6175. } else if (lang === "en-us") {
  6176. yield this.#createBundleFallback(lang);
  6177. }
  6178. }
  6179. }
  6180. static async #createBundle(lang, baseURL, paths) {
  6181. const path = paths[lang];
  6182. if (!path) {
  6183. return null;
  6184. }
  6185. const url = new URL(path, baseURL);
  6186. const text = await fetchData(url, "text");
  6187. return createBundle(lang, text);
  6188. }
  6189. static async #getPaths() {
  6190. try {
  6191. const {
  6192. href
  6193. } = document.querySelector(`link[type="application/l10n"]`);
  6194. const paths = await fetchData(href, "json");
  6195. return {
  6196. baseURL: href.substring(0, href.lastIndexOf("/") + 1) || "./",
  6197. paths
  6198. };
  6199. } catch {}
  6200. return {
  6201. baseURL: "./",
  6202. paths: Object.create(null)
  6203. };
  6204. }
  6205. static async *#generateBundlesFallback(lang) {
  6206. yield this.#createBundleFallback(lang);
  6207. }
  6208. static async #createBundleFallback(lang) {
  6209. const text = "pdfjs-previous-button =\n .title = Previous Page\npdfjs-previous-button-label = Previous\npdfjs-next-button =\n .title = Next Page\npdfjs-next-button-label = Next\npdfjs-page-input =\n .title = Page\npdfjs-of-pages = of { $pagesCount }\npdfjs-page-of-pages = ({ $pageNumber } of { $pagesCount })\npdfjs-zoom-out-button =\n .title = Zoom Out\npdfjs-zoom-out-button-label = Zoom Out\npdfjs-zoom-in-button =\n .title = Zoom In\npdfjs-zoom-in-button-label = Zoom In\npdfjs-zoom-select =\n .title = Zoom\npdfjs-presentation-mode-button =\n .title = Switch to Presentation Mode\npdfjs-presentation-mode-button-label = Presentation Mode\npdfjs-open-file-button =\n .title = Open File\npdfjs-open-file-button-label = Open\npdfjs-print-button =\n .title = Print\npdfjs-print-button-label = Print\npdfjs-save-button =\n .title = Save\npdfjs-save-button-label = Save\npdfjs-download-button =\n .title = Download\npdfjs-download-button-label = Download\npdfjs-bookmark-button =\n .title = Current Page (View URL from Current Page)\npdfjs-bookmark-button-label = Current Page\npdfjs-tools-button =\n .title = Tools\npdfjs-tools-button-label = Tools\npdfjs-first-page-button =\n .title = Go to First Page\npdfjs-first-page-button-label = Go to First Page\npdfjs-last-page-button =\n .title = Go to Last Page\npdfjs-last-page-button-label = Go to Last Page\npdfjs-page-rotate-cw-button =\n .title = Rotate Clockwise\npdfjs-page-rotate-cw-button-label = Rotate Clockwise\npdfjs-page-rotate-ccw-button =\n .title = Rotate Counterclockwise\npdfjs-page-rotate-ccw-button-label = Rotate Counterclockwise\npdfjs-cursor-text-select-tool-button =\n .title = Enable Text Selection Tool\npdfjs-cursor-text-select-tool-button-label = Text Selection Tool\npdfjs-cursor-hand-tool-button =\n .title = Enable Hand Tool\npdfjs-cursor-hand-tool-button-label = Hand Tool\npdfjs-scroll-page-button =\n .title = Use Page Scrolling\npdfjs-scroll-page-button-label = Page Scrolling\npdfjs-scroll-vertical-button =\n .title = Use Vertical Scrolling\npdfjs-scroll-vertical-button-label = Vertical Scrolling\npdfjs-scroll-horizontal-button =\n .title = Use Horizontal Scrolling\npdfjs-scroll-horizontal-button-label = Horizontal Scrolling\npdfjs-scroll-wrapped-button =\n .title = Use Wrapped Scrolling\npdfjs-scroll-wrapped-button-label = Wrapped Scrolling\npdfjs-spread-none-button =\n .title = Do not join page spreads\npdfjs-spread-none-button-label = No Spreads\npdfjs-spread-odd-button =\n .title = Join page spreads starting with odd-numbered pages\npdfjs-spread-odd-button-label = Odd Spreads\npdfjs-spread-even-button =\n .title = Join page spreads starting with even-numbered pages\npdfjs-spread-even-button-label = Even Spreads\npdfjs-document-properties-button =\n .title = Document Properties\u2026\npdfjs-document-properties-button-label = Document Properties\u2026\npdfjs-document-properties-file-name = File name:\npdfjs-document-properties-file-size = File size:\npdfjs-document-properties-size-kb = { NUMBER($kb, maximumSignificantDigits: 3) } KB ({ $b } bytes)\npdfjs-document-properties-size-mb = { NUMBER($mb, maximumSignificantDigits: 3) } MB ({ $b } bytes)\npdfjs-document-properties-title = Title:\npdfjs-document-properties-author = Author:\npdfjs-document-properties-subject = Subject:\npdfjs-document-properties-keywords = Keywords:\npdfjs-document-properties-creation-date = Creation Date:\npdfjs-document-properties-modification-date = Modification Date:\npdfjs-document-properties-date-time-string = { DATETIME($dateObj, dateStyle: \"short\", timeStyle: \"medium\") }\npdfjs-document-properties-creator = Creator:\npdfjs-document-properties-producer = PDF Producer:\npdfjs-document-properties-version = PDF Version:\npdfjs-document-properties-page-count = Page Count:\npdfjs-document-properties-page-size = Page Size:\npdfjs-document-properties-page-size-unit-inches = in\npdfjs-document-properties-page-size-unit-millimeters = mm\npdfjs-document-properties-page-size-orientation-portrait = portrait\npdfjs-document-properties-page-size-orientation-landscape = landscape\npdfjs-document-properties-page-size-name-a-three = A3\npdfjs-document-properties-page-size-name-a-four = A4\npdfjs-document-properties-page-size-name-letter = Letter\npdfjs-document-properties-page-size-name-legal = Legal\npdfjs-document-properties-page-size-dimension-string = { $width } \xD7 { $height } { $unit } ({ $orientation })\npdfjs-document-properties-page-size-dimension-name-string = { $width } \xD7 { $height } { $unit } ({ $name }, { $orientation })\npdfjs-document-properties-linearized = Fast Web View:\npdfjs-document-properties-linearized-yes = Yes\npdfjs-document-properties-linearized-no = No\npdfjs-document-properties-close-button = Close\npdfjs-print-progress-message = Preparing document for printing\u2026\npdfjs-print-progress-percent = { $progress }%\npdfjs-print-progress-close-button = Cancel\npdfjs-printing-not-supported = Warning: Printing is not fully supported by this browser.\npdfjs-printing-not-ready = Warning: The PDF is not fully loaded for printing.\npdfjs-toggle-sidebar-button =\n .title = Toggle Sidebar\npdfjs-toggle-sidebar-notification-button =\n .title = Toggle Sidebar (document contains outline/attachments/layers)\npdfjs-toggle-sidebar-button-label = Toggle Sidebar\npdfjs-document-outline-button =\n .title = Show Document Outline (double-click to expand/collapse all items)\npdfjs-document-outline-button-label = Document Outline\npdfjs-attachments-button =\n .title = Show Attachments\npdfjs-attachments-button-label = Attachments\npdfjs-layers-button =\n .title = Show Layers (double-click to reset all layers to the default state)\npdfjs-layers-button-label = Layers\npdfjs-thumbs-button =\n .title = Show Thumbnails\npdfjs-thumbs-button-label = Thumbnails\npdfjs-current-outline-item-button =\n .title = Find Current Outline Item\npdfjs-current-outline-item-button-label = Current Outline Item\npdfjs-findbar-button =\n .title = Find in Document\npdfjs-findbar-button-label = Find\npdfjs-additional-layers = Additional Layers\npdfjs-thumb-page-title =\n .title = Page { $page }\npdfjs-thumb-page-canvas =\n .aria-label = Thumbnail of Page { $page }\npdfjs-find-input =\n .title = Find\n .placeholder = Find in document\u2026\npdfjs-find-previous-button =\n .title = Find the previous occurrence of the phrase\npdfjs-find-previous-button-label = Previous\npdfjs-find-next-button =\n .title = Find the next occurrence of the phrase\npdfjs-find-next-button-label = Next\npdfjs-find-highlight-checkbox = Highlight All\npdfjs-find-match-case-checkbox-label = Match Case\npdfjs-find-match-diacritics-checkbox-label = Match Diacritics\npdfjs-find-entire-word-checkbox-label = Whole Words\npdfjs-find-reached-top = Reached top of document, continued from bottom\npdfjs-find-reached-bottom = Reached end of document, continued from top\npdfjs-find-match-count =\n { $total ->\n [one] { $current } of { $total } match\n *[other] { $current } of { $total } matches\n }\npdfjs-find-match-count-limit =\n { $limit ->\n [one] More than { $limit } match\n *[other] More than { $limit } matches\n }\npdfjs-find-not-found = Phrase not found\npdfjs-page-scale-width = Page Width\npdfjs-page-scale-fit = Page Fit\npdfjs-page-scale-auto = Automatic Zoom\npdfjs-page-scale-actual = Actual Size\npdfjs-page-scale-percent = { $scale }%\npdfjs-page-landmark =\n .aria-label = Page { $page }\npdfjs-loading-error = An error occurred while loading the PDF.\npdfjs-invalid-file-error = Invalid or corrupted PDF file.\npdfjs-missing-file-error = Missing PDF file.\npdfjs-unexpected-response-error = Unexpected server response.\npdfjs-rendering-error = An error occurred while rendering the page.\npdfjs-annotation-date-time-string = { DATETIME($dateObj, dateStyle: \"short\", timeStyle: \"medium\") }\npdfjs-text-annotation-type =\n .alt = [{ $type } Annotation]\npdfjs-password-label = Enter the password to open this PDF file.\npdfjs-password-invalid = Invalid password. Please try again.\npdfjs-password-ok-button = OK\npdfjs-password-cancel-button = Cancel\npdfjs-web-fonts-disabled = Web fonts are disabled: unable to use embedded PDF fonts.\npdfjs-editor-free-text-button =\n .title = Text\npdfjs-editor-free-text-button-label = Text\npdfjs-editor-ink-button =\n .title = Draw\npdfjs-editor-ink-button-label = Draw\npdfjs-editor-stamp-button =\n .title = Add or edit images\npdfjs-editor-stamp-button-label = Add or edit images\npdfjs-editor-highlight-button =\n .title = Highlight\npdfjs-editor-highlight-button-label = Highlight\npdfjs-highlight-floating-button1 =\n .title = Highlight\n .aria-label = Highlight\npdfjs-highlight-floating-button-label = Highlight\npdfjs-editor-signature-button =\n .title = Add signature\npdfjs-editor-signature-button-label = Add signature\npdfjs-editor-highlight-editor =\n .aria-label = Highlight editor\npdfjs-editor-ink-editor =\n .aria-label = Drawing editor\npdfjs-editor-signature-editor1 =\n .aria-description = Signature editor: { $description }\npdfjs-editor-stamp-editor =\n .aria-label = Image editor\npdfjs-editor-remove-ink-button =\n .title = Remove drawing\npdfjs-editor-remove-freetext-button =\n .title = Remove text\npdfjs-editor-remove-stamp-button =\n .title = Remove image\npdfjs-editor-remove-highlight-button =\n .title = Remove highlight\npdfjs-editor-remove-signature-button =\n .title = Remove signature\npdfjs-editor-free-text-color-input = Color\npdfjs-editor-free-text-size-input = Size\npdfjs-editor-ink-color-input = Color\npdfjs-editor-ink-thickness-input = Thickness\npdfjs-editor-ink-opacity-input = Opacity\npdfjs-editor-stamp-add-image-button =\n .title = Add image\npdfjs-editor-stamp-add-image-button-label = Add image\npdfjs-editor-free-highlight-thickness-input = Thickness\npdfjs-editor-free-highlight-thickness-title =\n .title = Change thickness when highlighting items other than text\npdfjs-editor-add-signature-container =\n .aria-label = Signature controls and saved signatures\npdfjs-editor-signature-add-signature-button =\n .title = Add new signature\npdfjs-editor-signature-add-signature-button-label = Add new signature\npdfjs-editor-add-saved-signature-button =\n .title = Saved signature: { $description }\npdfjs-free-text2 =\n .aria-label = Text Editor\n .default-content = Start typing\u2026\npdfjs-editor-alt-text-button =\n .aria-label = Alt text\npdfjs-editor-alt-text-button-label = Alt text\npdfjs-editor-alt-text-edit-button =\n .aria-label = Edit alt text\npdfjs-editor-alt-text-dialog-label = Choose an option\npdfjs-editor-alt-text-dialog-description = Alt text (alternative text) helps when people can\u2019t see the image or when it doesn\u2019t load.\npdfjs-editor-alt-text-add-description-label = Add a description\npdfjs-editor-alt-text-add-description-description = Aim for 1-2 sentences that describe the subject, setting, or actions.\npdfjs-editor-alt-text-mark-decorative-label = Mark as decorative\npdfjs-editor-alt-text-mark-decorative-description = This is used for ornamental images, like borders or watermarks.\npdfjs-editor-alt-text-cancel-button = Cancel\npdfjs-editor-alt-text-save-button = Save\npdfjs-editor-alt-text-decorative-tooltip = Marked as decorative\npdfjs-editor-alt-text-textarea =\n .placeholder = For example, \u201CA young man sits down at a table to eat a meal\u201D\npdfjs-editor-resizer-top-left =\n .aria-label = Top left corner \u2014 resize\npdfjs-editor-resizer-top-middle =\n .aria-label = Top middle \u2014 resize\npdfjs-editor-resizer-top-right =\n .aria-label = Top right corner \u2014 resize\npdfjs-editor-resizer-middle-right =\n .aria-label = Middle right \u2014 resize\npdfjs-editor-resizer-bottom-right =\n .aria-label = Bottom right corner \u2014 resize\npdfjs-editor-resizer-bottom-middle =\n .aria-label = Bottom middle \u2014 resize\npdfjs-editor-resizer-bottom-left =\n .aria-label = Bottom left corner \u2014 resize\npdfjs-editor-resizer-middle-left =\n .aria-label = Middle left \u2014 resize\npdfjs-editor-highlight-colorpicker-label = Highlight color\npdfjs-editor-colorpicker-button =\n .title = Change color\npdfjs-editor-colorpicker-dropdown =\n .aria-label = Color choices\npdfjs-editor-colorpicker-yellow =\n .title = Yellow\npdfjs-editor-colorpicker-green =\n .title = Green\npdfjs-editor-colorpicker-blue =\n .title = Blue\npdfjs-editor-colorpicker-pink =\n .title = Pink\npdfjs-editor-colorpicker-red =\n .title = Red\npdfjs-editor-highlight-show-all-button-label = Show all\npdfjs-editor-highlight-show-all-button =\n .title = Show all\npdfjs-editor-new-alt-text-dialog-edit-label = Edit alt text (image description)\npdfjs-editor-new-alt-text-dialog-add-label = Add alt text (image description)\npdfjs-editor-new-alt-text-textarea =\n .placeholder = Write your description here\u2026\npdfjs-editor-new-alt-text-description = Short description for people who can\u2019t see the image or when the image doesn\u2019t load.\npdfjs-editor-new-alt-text-disclaimer1 = This alt text was created automatically and may be inaccurate.\npdfjs-editor-new-alt-text-disclaimer-learn-more-url = Learn more\npdfjs-editor-new-alt-text-create-automatically-button-label = Create alt text automatically\npdfjs-editor-new-alt-text-not-now-button = Not now\npdfjs-editor-new-alt-text-error-title = Couldn\u2019t create alt text automatically\npdfjs-editor-new-alt-text-error-description = Please write your own alt text or try again later.\npdfjs-editor-new-alt-text-error-close-button = Close\npdfjs-editor-new-alt-text-ai-model-downloading-progress = Downloading alt text AI model ({ $downloadedSize } of { $totalSize } MB)\n .aria-valuetext = Downloading alt text AI model ({ $downloadedSize } of { $totalSize } MB)\npdfjs-editor-new-alt-text-added-button =\n .aria-label = Alt text added\npdfjs-editor-new-alt-text-added-button-label = Alt text added\npdfjs-editor-new-alt-text-missing-button =\n .aria-label = Missing alt text\npdfjs-editor-new-alt-text-missing-button-label = Missing alt text\npdfjs-editor-new-alt-text-to-review-button =\n .aria-label = Review alt text\npdfjs-editor-new-alt-text-to-review-button-label = Review alt text\npdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer = Created automatically: { $generatedAltText }\npdfjs-image-alt-text-settings-button =\n .title = Image alt text settings\npdfjs-image-alt-text-settings-button-label = Image alt text settings\npdfjs-editor-alt-text-settings-dialog-label = Image alt text settings\npdfjs-editor-alt-text-settings-automatic-title = Automatic alt text\npdfjs-editor-alt-text-settings-create-model-button-label = Create alt text automatically\npdfjs-editor-alt-text-settings-create-model-description = Suggests descriptions to help people who can\u2019t see the image or when the image doesn\u2019t load.\npdfjs-editor-alt-text-settings-download-model-label = Alt text AI model ({ $totalSize } MB)\npdfjs-editor-alt-text-settings-ai-model-description = Runs locally on your device so your data stays private. Required for automatic alt text.\npdfjs-editor-alt-text-settings-delete-model-button = Delete\npdfjs-editor-alt-text-settings-download-model-button = Download\npdfjs-editor-alt-text-settings-downloading-model-button = Downloading\u2026\npdfjs-editor-alt-text-settings-editor-title = Alt text editor\npdfjs-editor-alt-text-settings-show-dialog-button-label = Show alt text editor right away when adding an image\npdfjs-editor-alt-text-settings-show-dialog-description = Helps you make sure all your images have alt text.\npdfjs-editor-alt-text-settings-close-button = Close\npdfjs-editor-undo-bar-message-highlight = Highlight removed\npdfjs-editor-undo-bar-message-freetext = Text removed\npdfjs-editor-undo-bar-message-ink = Drawing removed\npdfjs-editor-undo-bar-message-stamp = Image removed\npdfjs-editor-undo-bar-message-signature = Signature removed\npdfjs-editor-undo-bar-message-multiple =\n { $count ->\n [one] { $count } annotation removed\n *[other] { $count } annotations removed\n }\npdfjs-editor-undo-bar-undo-button =\n .title = Undo\npdfjs-editor-undo-bar-undo-button-label = Undo\npdfjs-editor-undo-bar-close-button =\n .title = Close\npdfjs-editor-undo-bar-close-button-label = Close\npdfjs-editor-add-signature-dialog-label = This modal allows the user to create a signature to add to a PDF document. The user can edit the name (which also serves as the alt text), and optionally save the signature for repeated use.\npdfjs-editor-add-signature-dialog-title = Add a signature\npdfjs-editor-add-signature-type-button = Type\n .title = Type\npdfjs-editor-add-signature-draw-button = Draw\n .title = Draw\npdfjs-editor-add-signature-image-button = Image\n .title = Image\npdfjs-editor-add-signature-type-input =\n .aria-label = Type your signature\n .placeholder = Type your signature\npdfjs-editor-add-signature-draw-placeholder = Draw your signature\npdfjs-editor-add-signature-draw-thickness-range-label = Thickness\npdfjs-editor-add-signature-draw-thickness-range =\n .title = Drawing thickness: { $thickness }\npdfjs-editor-add-signature-image-placeholder = Drag a file here to upload\npdfjs-editor-add-signature-image-browse-link =\n { PLATFORM() ->\n [macos] Or choose image files\n *[other] Or browse image files\n }\npdfjs-editor-add-signature-description-label = Description (alt text)\npdfjs-editor-add-signature-description-input =\n .title = Description (alt text)\npdfjs-editor-add-signature-description-default-when-drawing = Signature\npdfjs-editor-add-signature-clear-button-label = Clear signature\npdfjs-editor-add-signature-clear-button =\n .title = Clear signature\npdfjs-editor-add-signature-save-checkbox = Save signature\npdfjs-editor-add-signature-save-warning-message = You\u2019ve reached the limit of 5 saved signatures. Remove one to save more.\npdfjs-editor-add-signature-image-upload-error-title = Couldn\u2019t upload image\npdfjs-editor-add-signature-image-upload-error-description = Check your network connection or try another image.\npdfjs-editor-add-signature-error-close-button = Close\npdfjs-editor-add-signature-cancel-button = Cancel\npdfjs-editor-add-signature-add-button = Add\npdfjs-editor-delete-signature-button1 =\n .title = Remove saved signature\npdfjs-editor-delete-signature-button-label1 = Remove saved signature\npdfjs-editor-add-signature-edit-button-label = Edit description\npdfjs-editor-edit-signature-dialog-title = Edit description\npdfjs-editor-edit-signature-update-button = Update";
  6210. return createBundle(lang, text);
  6211. }
  6212. }
  6213. ;// ./web/generic_scripting.js
  6214. async function docProperties(pdfDocument) {
  6215. const url = "",
  6216. baseUrl = "";
  6217. const {
  6218. info,
  6219. metadata,
  6220. contentDispositionFilename,
  6221. contentLength
  6222. } = await pdfDocument.getMetadata();
  6223. return {
  6224. ...info,
  6225. baseURL: baseUrl,
  6226. filesize: contentLength || (await pdfDocument.getDownloadInfo()).length,
  6227. filename: contentDispositionFilename || getPdfFilenameFromUrl(url),
  6228. metadata: metadata?.getRaw(),
  6229. authors: metadata?.get("dc:creator"),
  6230. numPages: pdfDocument.numPages,
  6231. URL: url
  6232. };
  6233. }
  6234. class GenericScripting {
  6235. constructor(sandboxBundleSrc) {
  6236. this._ready = new Promise((resolve, reject) => {
  6237. const sandbox = import(
  6238. /*webpackIgnore: true*/
  6239. /*@vite-ignore*/
  6240. sandboxBundleSrc);
  6241. sandbox.then(pdfjsSandbox => {
  6242. resolve(pdfjsSandbox.QuickJSSandbox());
  6243. }).catch(reject);
  6244. });
  6245. }
  6246. async createSandbox(data) {
  6247. const sandbox = await this._ready;
  6248. sandbox.create(data);
  6249. }
  6250. async dispatchEventInSandbox(event) {
  6251. const sandbox = await this._ready;
  6252. setTimeout(() => sandbox.dispatchEvent(event), 0);
  6253. }
  6254. async destroySandbox() {
  6255. const sandbox = await this._ready;
  6256. sandbox.nukeSandbox();
  6257. }
  6258. }
  6259. ;// ./web/generic_signature_storage.js
  6260. const KEY_STORAGE = "pdfjs.signature";
  6261. class SignatureStorage {
  6262. #eventBus;
  6263. #signatures = null;
  6264. #signal = null;
  6265. constructor(eventBus, signal) {
  6266. this.#eventBus = eventBus;
  6267. this.#signal = signal;
  6268. }
  6269. #save() {
  6270. localStorage.setItem(KEY_STORAGE, JSON.stringify(Object.fromEntries(this.#signatures)));
  6271. }
  6272. async getAll() {
  6273. if (this.#signal) {
  6274. window.addEventListener("storage", ({
  6275. key
  6276. }) => {
  6277. if (key === KEY_STORAGE) {
  6278. this.#signatures = null;
  6279. this.#eventBus?.dispatch("storedsignatureschanged", {
  6280. source: this
  6281. });
  6282. }
  6283. }, {
  6284. signal: this.#signal
  6285. });
  6286. this.#signal = null;
  6287. }
  6288. if (!this.#signatures) {
  6289. this.#signatures = new Map();
  6290. const data = localStorage.getItem(KEY_STORAGE);
  6291. if (data) {
  6292. for (const [key, value] of Object.entries(JSON.parse(data))) {
  6293. this.#signatures.set(key, value);
  6294. }
  6295. }
  6296. }
  6297. return this.#signatures;
  6298. }
  6299. async isFull() {
  6300. return (await this.size()) === 5;
  6301. }
  6302. async size() {
  6303. return (await this.getAll()).size;
  6304. }
  6305. async create(data) {
  6306. if (await this.isFull()) {
  6307. return null;
  6308. }
  6309. const uuid = getUuid();
  6310. this.#signatures.set(uuid, data);
  6311. this.#save();
  6312. return uuid;
  6313. }
  6314. async delete(uuid) {
  6315. const signatures = await this.getAll();
  6316. if (!signatures.has(uuid)) {
  6317. return false;
  6318. }
  6319. signatures.delete(uuid);
  6320. this.#save();
  6321. return true;
  6322. }
  6323. }
  6324. ;// ./web/genericcom.js
  6325. function initCom(app) {}
  6326. class Preferences extends BasePreferences {
  6327. async _writeToStorage(prefObj) {
  6328. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  6329. }
  6330. async _readFromStorage(prefObj) {
  6331. return {
  6332. prefs: JSON.parse(localStorage.getItem("pdfjs.preferences"))
  6333. };
  6334. }
  6335. }
  6336. class ExternalServices extends BaseExternalServices {
  6337. async createL10n() {
  6338. return new genericl10n_GenericL10n(AppOptions.get("localeProperties")?.lang);
  6339. }
  6340. createScripting() {
  6341. return new GenericScripting(AppOptions.get("sandboxBundleSrc"));
  6342. }
  6343. createSignatureStorage(eventBus, signal) {
  6344. return new SignatureStorage(eventBus, signal);
  6345. }
  6346. }
  6347. class MLManager {
  6348. async isEnabledFor(_name) {
  6349. return false;
  6350. }
  6351. async deleteModel(_service) {
  6352. return null;
  6353. }
  6354. isReady(_name) {
  6355. return false;
  6356. }
  6357. guess(_data) {}
  6358. toggleService(_name, _enabled) {}
  6359. }
  6360. ;// ./web/new_alt_text_manager.js
  6361. class NewAltTextManager {
  6362. #boundCancel = this.#cancel.bind(this);
  6363. #createAutomaticallyButton;
  6364. #currentEditor = null;
  6365. #cancelButton;
  6366. #descriptionContainer;
  6367. #dialog;
  6368. #disclaimer;
  6369. #downloadModel;
  6370. #downloadModelDescription;
  6371. #eventBus;
  6372. #firstTime = false;
  6373. #guessedAltText;
  6374. #hasAI = null;
  6375. #isEditing = null;
  6376. #imagePreview;
  6377. #imageData;
  6378. #isAILoading = false;
  6379. #wasAILoading = false;
  6380. #learnMore;
  6381. #notNowButton;
  6382. #overlayManager;
  6383. #textarea;
  6384. #title;
  6385. #uiManager;
  6386. #previousAltText = null;
  6387. constructor({
  6388. descriptionContainer,
  6389. dialog,
  6390. imagePreview,
  6391. cancelButton,
  6392. disclaimer,
  6393. notNowButton,
  6394. saveButton,
  6395. textarea,
  6396. learnMore,
  6397. errorCloseButton,
  6398. createAutomaticallyButton,
  6399. downloadModel,
  6400. downloadModelDescription,
  6401. title
  6402. }, overlayManager, eventBus) {
  6403. this.#cancelButton = cancelButton;
  6404. this.#createAutomaticallyButton = createAutomaticallyButton;
  6405. this.#descriptionContainer = descriptionContainer;
  6406. this.#dialog = dialog;
  6407. this.#disclaimer = disclaimer;
  6408. this.#notNowButton = notNowButton;
  6409. this.#imagePreview = imagePreview;
  6410. this.#textarea = textarea;
  6411. this.#learnMore = learnMore;
  6412. this.#title = title;
  6413. this.#downloadModel = downloadModel;
  6414. this.#downloadModelDescription = downloadModelDescription;
  6415. this.#overlayManager = overlayManager;
  6416. this.#eventBus = eventBus;
  6417. dialog.addEventListener("close", this.#close.bind(this));
  6418. dialog.addEventListener("contextmenu", event => {
  6419. if (event.target !== this.#textarea) {
  6420. event.preventDefault();
  6421. }
  6422. });
  6423. cancelButton.addEventListener("click", this.#boundCancel);
  6424. notNowButton.addEventListener("click", this.#boundCancel);
  6425. saveButton.addEventListener("click", this.#save.bind(this));
  6426. errorCloseButton.addEventListener("click", () => {
  6427. this.#toggleError(false);
  6428. });
  6429. createAutomaticallyButton.addEventListener("click", async () => {
  6430. const checked = createAutomaticallyButton.getAttribute("aria-pressed") !== "true";
  6431. this.#currentEditor._reportTelemetry({
  6432. action: "pdfjs.image.alt_text.ai_generation_check",
  6433. data: {
  6434. status: checked
  6435. }
  6436. });
  6437. if (this.#uiManager) {
  6438. this.#uiManager.setPreference("enableGuessAltText", checked);
  6439. await this.#uiManager.mlManager.toggleService("altText", checked);
  6440. }
  6441. this.#toggleGuessAltText(checked, false);
  6442. });
  6443. textarea.addEventListener("focus", () => {
  6444. this.#wasAILoading = this.#isAILoading;
  6445. this.#toggleLoading(false);
  6446. this.#toggleTitleAndDisclaimer();
  6447. });
  6448. textarea.addEventListener("blur", () => {
  6449. if (!textarea.value) {
  6450. this.#toggleLoading(this.#wasAILoading);
  6451. }
  6452. this.#toggleTitleAndDisclaimer();
  6453. });
  6454. textarea.addEventListener("input", () => {
  6455. this.#toggleTitleAndDisclaimer();
  6456. });
  6457. eventBus._on("enableguessalttext", ({
  6458. value
  6459. }) => {
  6460. this.#toggleGuessAltText(value, false);
  6461. });
  6462. this.#overlayManager.register(dialog);
  6463. this.#learnMore.addEventListener("click", () => {
  6464. this.#currentEditor._reportTelemetry({
  6465. action: "pdfjs.image.alt_text.info",
  6466. data: {
  6467. topic: "alt_text"
  6468. }
  6469. });
  6470. });
  6471. }
  6472. #toggleLoading(value) {
  6473. if (!this.#uiManager || this.#isAILoading === value) {
  6474. return;
  6475. }
  6476. this.#isAILoading = value;
  6477. this.#descriptionContainer.classList.toggle("loading", value);
  6478. }
  6479. #toggleError(value) {
  6480. if (!this.#uiManager) {
  6481. return;
  6482. }
  6483. this.#dialog.classList.toggle("error", value);
  6484. }
  6485. async #toggleGuessAltText(value, isInitial = false) {
  6486. if (!this.#uiManager) {
  6487. return;
  6488. }
  6489. this.#dialog.classList.toggle("aiDisabled", !value);
  6490. this.#createAutomaticallyButton.setAttribute("aria-pressed", value);
  6491. if (value) {
  6492. const {
  6493. altTextLearnMoreUrl
  6494. } = this.#uiManager.mlManager;
  6495. if (altTextLearnMoreUrl) {
  6496. this.#learnMore.href = altTextLearnMoreUrl;
  6497. }
  6498. this.#mlGuessAltText(isInitial);
  6499. } else {
  6500. this.#toggleLoading(false);
  6501. this.#isAILoading = false;
  6502. this.#toggleTitleAndDisclaimer();
  6503. }
  6504. }
  6505. #toggleNotNow() {
  6506. this.#notNowButton.classList.toggle("hidden", !this.#firstTime);
  6507. this.#cancelButton.classList.toggle("hidden", this.#firstTime);
  6508. }
  6509. #toggleAI(value) {
  6510. if (!this.#uiManager || this.#hasAI === value) {
  6511. return;
  6512. }
  6513. this.#hasAI = value;
  6514. this.#dialog.classList.toggle("noAi", !value);
  6515. this.#toggleTitleAndDisclaimer();
  6516. }
  6517. #toggleTitleAndDisclaimer() {
  6518. const visible = this.#isAILoading || this.#guessedAltText && this.#guessedAltText === this.#textarea.value;
  6519. this.#disclaimer.hidden = !visible;
  6520. const isEditing = this.#isAILoading || !!this.#textarea.value;
  6521. if (this.#isEditing === isEditing) {
  6522. return;
  6523. }
  6524. this.#isEditing = isEditing;
  6525. this.#title.setAttribute("data-l10n-id", isEditing ? "pdfjs-editor-new-alt-text-dialog-edit-label" : "pdfjs-editor-new-alt-text-dialog-add-label");
  6526. }
  6527. async #mlGuessAltText(isInitial) {
  6528. if (this.#isAILoading) {
  6529. return;
  6530. }
  6531. if (this.#textarea.value) {
  6532. return;
  6533. }
  6534. if (isInitial && this.#previousAltText !== null) {
  6535. return;
  6536. }
  6537. this.#guessedAltText = this.#currentEditor.guessedAltText;
  6538. if (this.#previousAltText === null && this.#guessedAltText) {
  6539. this.#addAltText(this.#guessedAltText);
  6540. return;
  6541. }
  6542. this.#toggleLoading(true);
  6543. this.#toggleTitleAndDisclaimer();
  6544. let hasError = false;
  6545. try {
  6546. const altText = await this.#currentEditor.mlGuessAltText(this.#imageData, false);
  6547. if (altText) {
  6548. this.#guessedAltText = altText;
  6549. this.#wasAILoading = this.#isAILoading;
  6550. if (this.#isAILoading) {
  6551. this.#addAltText(altText);
  6552. }
  6553. }
  6554. } catch (e) {
  6555. console.error(e);
  6556. hasError = true;
  6557. }
  6558. this.#toggleLoading(false);
  6559. this.#toggleTitleAndDisclaimer();
  6560. if (hasError && this.#uiManager) {
  6561. this.#toggleError(true);
  6562. }
  6563. }
  6564. #addAltText(altText) {
  6565. if (!this.#uiManager || this.#textarea.value) {
  6566. return;
  6567. }
  6568. this.#textarea.value = altText;
  6569. this.#toggleTitleAndDisclaimer();
  6570. }
  6571. #setProgress() {
  6572. this.#downloadModel.classList.toggle("hidden", false);
  6573. const callback = async ({
  6574. detail: {
  6575. finished,
  6576. total,
  6577. totalLoaded
  6578. }
  6579. }) => {
  6580. const ONE_MEGA_BYTES = 1e6;
  6581. totalLoaded = Math.min(0.99 * total, totalLoaded);
  6582. const totalSize = this.#downloadModelDescription.ariaValueMax = Math.round(total / ONE_MEGA_BYTES);
  6583. const downloadedSize = this.#downloadModelDescription.ariaValueNow = Math.round(totalLoaded / ONE_MEGA_BYTES);
  6584. this.#downloadModelDescription.setAttribute("data-l10n-args", JSON.stringify({
  6585. totalSize,
  6586. downloadedSize
  6587. }));
  6588. if (!finished) {
  6589. return;
  6590. }
  6591. this.#eventBus._off("loadaiengineprogress", callback);
  6592. this.#downloadModel.classList.toggle("hidden", true);
  6593. this.#toggleAI(true);
  6594. if (!this.#uiManager) {
  6595. return;
  6596. }
  6597. const {
  6598. mlManager
  6599. } = this.#uiManager;
  6600. mlManager.toggleService("altText", true);
  6601. this.#toggleGuessAltText(await mlManager.isEnabledFor("altText"), true);
  6602. };
  6603. this.#eventBus._on("loadaiengineprogress", callback);
  6604. }
  6605. async editAltText(uiManager, editor, firstTime) {
  6606. if (this.#currentEditor || !editor) {
  6607. return;
  6608. }
  6609. if (firstTime && editor.hasAltTextData()) {
  6610. editor.altTextFinish();
  6611. return;
  6612. }
  6613. this.#firstTime = firstTime;
  6614. let {
  6615. mlManager
  6616. } = uiManager;
  6617. let hasAI = !!mlManager;
  6618. this.#toggleTitleAndDisclaimer();
  6619. if (mlManager && !mlManager.isReady("altText")) {
  6620. hasAI = false;
  6621. if (mlManager.hasProgress) {
  6622. this.#setProgress();
  6623. } else {
  6624. mlManager = null;
  6625. }
  6626. } else {
  6627. this.#downloadModel.classList.toggle("hidden", true);
  6628. }
  6629. const isAltTextEnabledPromise = mlManager?.isEnabledFor("altText");
  6630. this.#currentEditor = editor;
  6631. this.#uiManager = uiManager;
  6632. this.#uiManager.removeEditListeners();
  6633. ({
  6634. altText: this.#previousAltText
  6635. } = editor.altTextData);
  6636. this.#textarea.value = this.#previousAltText ?? "";
  6637. const AI_MAX_IMAGE_DIMENSION = 224;
  6638. const MAX_PREVIEW_DIMENSION = 180;
  6639. let canvas, width, height;
  6640. if (mlManager) {
  6641. ({
  6642. canvas,
  6643. width,
  6644. height,
  6645. imageData: this.#imageData
  6646. } = editor.copyCanvas(AI_MAX_IMAGE_DIMENSION, MAX_PREVIEW_DIMENSION, true));
  6647. if (hasAI) {
  6648. this.#toggleGuessAltText(await isAltTextEnabledPromise, true);
  6649. }
  6650. } else {
  6651. ({
  6652. canvas,
  6653. width,
  6654. height
  6655. } = editor.copyCanvas(AI_MAX_IMAGE_DIMENSION, MAX_PREVIEW_DIMENSION, false));
  6656. }
  6657. canvas.setAttribute("role", "presentation");
  6658. const {
  6659. style
  6660. } = canvas;
  6661. style.width = `${width}px`;
  6662. style.height = `${height}px`;
  6663. this.#imagePreview.append(canvas);
  6664. this.#toggleNotNow();
  6665. this.#toggleAI(hasAI);
  6666. this.#toggleError(false);
  6667. try {
  6668. await this.#overlayManager.open(this.#dialog);
  6669. } catch (ex) {
  6670. this.#close();
  6671. throw ex;
  6672. }
  6673. }
  6674. #cancel() {
  6675. this.#currentEditor.altTextData = {
  6676. cancel: true
  6677. };
  6678. const altText = this.#textarea.value.trim();
  6679. this.#currentEditor._reportTelemetry({
  6680. action: "pdfjs.image.alt_text.dismiss",
  6681. data: {
  6682. alt_text_type: altText ? "present" : "empty",
  6683. flow: this.#firstTime ? "image_add" : "alt_text_edit"
  6684. }
  6685. });
  6686. this.#currentEditor._reportTelemetry({
  6687. action: "pdfjs.image.image_added",
  6688. data: {
  6689. alt_text_modal: true,
  6690. alt_text_type: "skipped"
  6691. }
  6692. });
  6693. this.#finish();
  6694. }
  6695. #finish() {
  6696. this.#overlayManager.closeIfActive(this.#dialog);
  6697. }
  6698. #close() {
  6699. const canvas = this.#imagePreview.firstChild;
  6700. canvas.remove();
  6701. canvas.width = canvas.height = 0;
  6702. this.#imageData = null;
  6703. this.#toggleLoading(false);
  6704. this.#uiManager?.addEditListeners();
  6705. this.#currentEditor.altTextFinish();
  6706. this.#uiManager?.setSelected(this.#currentEditor);
  6707. this.#currentEditor = null;
  6708. this.#uiManager = null;
  6709. }
  6710. #extractWords(text) {
  6711. return new Set(text.toLowerCase().split(/[^\p{L}\p{N}]+/gu).filter(x => !!x));
  6712. }
  6713. #save() {
  6714. const altText = this.#textarea.value.trim();
  6715. this.#currentEditor.altTextData = {
  6716. altText,
  6717. decorative: false
  6718. };
  6719. this.#currentEditor.altTextData.guessedAltText = this.#guessedAltText;
  6720. if (this.#guessedAltText && this.#guessedAltText !== altText) {
  6721. const guessedWords = this.#extractWords(this.#guessedAltText);
  6722. const words = this.#extractWords(altText);
  6723. this.#currentEditor._reportTelemetry({
  6724. action: "pdfjs.image.alt_text.user_edit",
  6725. data: {
  6726. total_words: guessedWords.size,
  6727. words_removed: guessedWords.difference(words).size,
  6728. words_added: words.difference(guessedWords).size
  6729. }
  6730. });
  6731. }
  6732. this.#currentEditor._reportTelemetry({
  6733. action: "pdfjs.image.image_added",
  6734. data: {
  6735. alt_text_modal: true,
  6736. alt_text_type: altText ? "present" : "empty"
  6737. }
  6738. });
  6739. this.#currentEditor._reportTelemetry({
  6740. action: "pdfjs.image.alt_text.save",
  6741. data: {
  6742. alt_text_type: altText ? "present" : "empty",
  6743. flow: this.#firstTime ? "image_add" : "alt_text_edit"
  6744. }
  6745. });
  6746. this.#finish();
  6747. }
  6748. destroy() {
  6749. this.#uiManager = null;
  6750. this.#finish();
  6751. }
  6752. }
  6753. class ImageAltTextSettings {
  6754. #aiModelSettings;
  6755. #createModelButton;
  6756. #downloadModelButton;
  6757. #dialog;
  6758. #eventBus;
  6759. #mlManager;
  6760. #overlayManager;
  6761. #showAltTextDialogButton;
  6762. constructor({
  6763. dialog,
  6764. createModelButton,
  6765. aiModelSettings,
  6766. learnMore,
  6767. closeButton,
  6768. deleteModelButton,
  6769. downloadModelButton,
  6770. showAltTextDialogButton
  6771. }, overlayManager, eventBus, mlManager) {
  6772. this.#dialog = dialog;
  6773. this.#aiModelSettings = aiModelSettings;
  6774. this.#createModelButton = createModelButton;
  6775. this.#downloadModelButton = downloadModelButton;
  6776. this.#showAltTextDialogButton = showAltTextDialogButton;
  6777. this.#overlayManager = overlayManager;
  6778. this.#eventBus = eventBus;
  6779. this.#mlManager = mlManager;
  6780. const {
  6781. altTextLearnMoreUrl
  6782. } = mlManager;
  6783. if (altTextLearnMoreUrl) {
  6784. learnMore.href = altTextLearnMoreUrl;
  6785. }
  6786. dialog.addEventListener("contextmenu", noContextMenu);
  6787. createModelButton.addEventListener("click", async e => {
  6788. const checked = this.#togglePref("enableGuessAltText", e);
  6789. await mlManager.toggleService("altText", checked);
  6790. this.#reportTelemetry({
  6791. type: "stamp",
  6792. action: "pdfjs.image.alt_text.settings_ai_generation_check",
  6793. data: {
  6794. status: checked
  6795. }
  6796. });
  6797. });
  6798. showAltTextDialogButton.addEventListener("click", e => {
  6799. const checked = this.#togglePref("enableNewAltTextWhenAddingImage", e);
  6800. this.#reportTelemetry({
  6801. type: "stamp",
  6802. action: "pdfjs.image.alt_text.settings_edit_alt_text_check",
  6803. data: {
  6804. status: checked
  6805. }
  6806. });
  6807. });
  6808. deleteModelButton.addEventListener("click", this.#delete.bind(this, true));
  6809. downloadModelButton.addEventListener("click", this.#download.bind(this, true));
  6810. closeButton.addEventListener("click", this.#finish.bind(this));
  6811. learnMore.addEventListener("click", () => {
  6812. this.#reportTelemetry({
  6813. type: "stamp",
  6814. action: "pdfjs.image.alt_text.info",
  6815. data: {
  6816. topic: "ai_generation"
  6817. }
  6818. });
  6819. });
  6820. eventBus._on("enablealttextmodeldownload", ({
  6821. value
  6822. }) => {
  6823. if (value) {
  6824. this.#download(false);
  6825. } else {
  6826. this.#delete(false);
  6827. }
  6828. });
  6829. this.#overlayManager.register(dialog);
  6830. }
  6831. #reportTelemetry(data) {
  6832. this.#eventBus.dispatch("reporttelemetry", {
  6833. source: this,
  6834. details: {
  6835. type: "editing",
  6836. data
  6837. }
  6838. });
  6839. }
  6840. async #download(isFromUI = false) {
  6841. if (isFromUI) {
  6842. this.#downloadModelButton.disabled = true;
  6843. const span = this.#downloadModelButton.firstChild;
  6844. span.setAttribute("data-l10n-id", "pdfjs-editor-alt-text-settings-downloading-model-button");
  6845. await this.#mlManager.downloadModel("altText");
  6846. span.setAttribute("data-l10n-id", "pdfjs-editor-alt-text-settings-download-model-button");
  6847. this.#createModelButton.disabled = false;
  6848. this.#setPref("enableGuessAltText", true);
  6849. this.#mlManager.toggleService("altText", true);
  6850. this.#setPref("enableAltTextModelDownload", true);
  6851. this.#downloadModelButton.disabled = false;
  6852. }
  6853. this.#aiModelSettings.classList.toggle("download", false);
  6854. this.#createModelButton.setAttribute("aria-pressed", true);
  6855. }
  6856. async #delete(isFromUI = false) {
  6857. if (isFromUI) {
  6858. await this.#mlManager.deleteModel("altText");
  6859. this.#setPref("enableGuessAltText", false);
  6860. this.#setPref("enableAltTextModelDownload", false);
  6861. }
  6862. this.#aiModelSettings.classList.toggle("download", true);
  6863. this.#createModelButton.disabled = true;
  6864. this.#createModelButton.setAttribute("aria-pressed", false);
  6865. }
  6866. async open({
  6867. enableGuessAltText,
  6868. enableNewAltTextWhenAddingImage
  6869. }) {
  6870. const {
  6871. enableAltTextModelDownload
  6872. } = this.#mlManager;
  6873. this.#createModelButton.disabled = !enableAltTextModelDownload;
  6874. this.#createModelButton.setAttribute("aria-pressed", enableAltTextModelDownload && enableGuessAltText);
  6875. this.#showAltTextDialogButton.setAttribute("aria-pressed", enableNewAltTextWhenAddingImage);
  6876. this.#aiModelSettings.classList.toggle("download", !enableAltTextModelDownload);
  6877. await this.#overlayManager.open(this.#dialog);
  6878. this.#reportTelemetry({
  6879. type: "stamp",
  6880. action: "pdfjs.image.alt_text.settings_displayed"
  6881. });
  6882. }
  6883. #togglePref(name, {
  6884. target
  6885. }) {
  6886. const checked = target.getAttribute("aria-pressed") !== "true";
  6887. this.#setPref(name, checked);
  6888. target.setAttribute("aria-pressed", checked);
  6889. return checked;
  6890. }
  6891. #setPref(name, value) {
  6892. this.#eventBus.dispatch("setpreference", {
  6893. source: this,
  6894. name,
  6895. value
  6896. });
  6897. }
  6898. #finish() {
  6899. this.#overlayManager.closeIfActive(this.#dialog);
  6900. }
  6901. }
  6902. ;// ./web/alt_text_manager.js
  6903. class AltTextManager {
  6904. #clickAC = null;
  6905. #currentEditor = null;
  6906. #cancelButton;
  6907. #dialog;
  6908. #eventBus;
  6909. #hasUsedPointer = false;
  6910. #optionDescription;
  6911. #optionDecorative;
  6912. #overlayManager;
  6913. #saveButton;
  6914. #textarea;
  6915. #uiManager;
  6916. #previousAltText = null;
  6917. #resizeAC = null;
  6918. #svgElement = null;
  6919. #rectElement = null;
  6920. #container;
  6921. #telemetryData = null;
  6922. constructor({
  6923. dialog,
  6924. optionDescription,
  6925. optionDecorative,
  6926. textarea,
  6927. cancelButton,
  6928. saveButton
  6929. }, container, overlayManager, eventBus) {
  6930. this.#dialog = dialog;
  6931. this.#optionDescription = optionDescription;
  6932. this.#optionDecorative = optionDecorative;
  6933. this.#textarea = textarea;
  6934. this.#cancelButton = cancelButton;
  6935. this.#saveButton = saveButton;
  6936. this.#overlayManager = overlayManager;
  6937. this.#eventBus = eventBus;
  6938. this.#container = container;
  6939. const onUpdateUIState = this.#updateUIState.bind(this);
  6940. dialog.addEventListener("close", this.#close.bind(this));
  6941. dialog.addEventListener("contextmenu", event => {
  6942. if (event.target !== this.#textarea) {
  6943. event.preventDefault();
  6944. }
  6945. });
  6946. cancelButton.addEventListener("click", this.#finish.bind(this));
  6947. saveButton.addEventListener("click", this.#save.bind(this));
  6948. optionDescription.addEventListener("change", onUpdateUIState);
  6949. optionDecorative.addEventListener("change", onUpdateUIState);
  6950. this.#overlayManager.register(dialog);
  6951. }
  6952. #createSVGElement() {
  6953. if (this.#svgElement) {
  6954. return;
  6955. }
  6956. const svgFactory = new DOMSVGFactory();
  6957. const svg = this.#svgElement = svgFactory.createElement("svg");
  6958. svg.setAttribute("width", "0");
  6959. svg.setAttribute("height", "0");
  6960. const defs = svgFactory.createElement("defs");
  6961. svg.append(defs);
  6962. const mask = svgFactory.createElement("mask");
  6963. defs.append(mask);
  6964. mask.setAttribute("id", "alttext-manager-mask");
  6965. mask.setAttribute("maskContentUnits", "objectBoundingBox");
  6966. let rect = svgFactory.createElement("rect");
  6967. mask.append(rect);
  6968. rect.setAttribute("fill", "white");
  6969. rect.setAttribute("width", "1");
  6970. rect.setAttribute("height", "1");
  6971. rect.setAttribute("x", "0");
  6972. rect.setAttribute("y", "0");
  6973. rect = this.#rectElement = svgFactory.createElement("rect");
  6974. mask.append(rect);
  6975. rect.setAttribute("fill", "black");
  6976. this.#dialog.append(svg);
  6977. }
  6978. async editAltText(uiManager, editor) {
  6979. if (this.#currentEditor || !editor) {
  6980. return;
  6981. }
  6982. this.#createSVGElement();
  6983. this.#hasUsedPointer = false;
  6984. this.#clickAC = new AbortController();
  6985. const clickOpts = {
  6986. signal: this.#clickAC.signal
  6987. },
  6988. onClick = this.#onClick.bind(this);
  6989. for (const element of [this.#optionDescription, this.#optionDecorative, this.#textarea, this.#saveButton, this.#cancelButton]) {
  6990. element.addEventListener("click", onClick, clickOpts);
  6991. }
  6992. const {
  6993. altText,
  6994. decorative
  6995. } = editor.altTextData;
  6996. if (decorative === true) {
  6997. this.#optionDecorative.checked = true;
  6998. this.#optionDescription.checked = false;
  6999. } else {
  7000. this.#optionDecorative.checked = false;
  7001. this.#optionDescription.checked = true;
  7002. }
  7003. this.#previousAltText = this.#textarea.value = altText?.trim() || "";
  7004. this.#updateUIState();
  7005. this.#currentEditor = editor;
  7006. this.#uiManager = uiManager;
  7007. this.#uiManager.removeEditListeners();
  7008. this.#resizeAC = new AbortController();
  7009. this.#eventBus._on("resize", this.#setPosition.bind(this), {
  7010. signal: this.#resizeAC.signal
  7011. });
  7012. try {
  7013. await this.#overlayManager.open(this.#dialog);
  7014. this.#setPosition();
  7015. } catch (ex) {
  7016. this.#close();
  7017. throw ex;
  7018. }
  7019. }
  7020. #setPosition() {
  7021. if (!this.#currentEditor) {
  7022. return;
  7023. }
  7024. const dialog = this.#dialog;
  7025. const {
  7026. style
  7027. } = dialog;
  7028. const {
  7029. x: containerX,
  7030. y: containerY,
  7031. width: containerW,
  7032. height: containerH
  7033. } = this.#container.getBoundingClientRect();
  7034. const {
  7035. innerWidth: windowW,
  7036. innerHeight: windowH
  7037. } = window;
  7038. const {
  7039. width: dialogW,
  7040. height: dialogH
  7041. } = dialog.getBoundingClientRect();
  7042. const {
  7043. x,
  7044. y,
  7045. width,
  7046. height
  7047. } = this.#currentEditor.getClientDimensions();
  7048. const MARGIN = 10;
  7049. const isLTR = this.#uiManager.direction === "ltr";
  7050. const xs = Math.max(x, containerX);
  7051. const xe = Math.min(x + width, containerX + containerW);
  7052. const ys = Math.max(y, containerY);
  7053. const ye = Math.min(y + height, containerY + containerH);
  7054. this.#rectElement.setAttribute("width", `${(xe - xs) / windowW}`);
  7055. this.#rectElement.setAttribute("height", `${(ye - ys) / windowH}`);
  7056. this.#rectElement.setAttribute("x", `${xs / windowW}`);
  7057. this.#rectElement.setAttribute("y", `${ys / windowH}`);
  7058. let left = null;
  7059. let top = Math.max(y, 0);
  7060. top += Math.min(windowH - (top + dialogH), 0);
  7061. if (isLTR) {
  7062. if (x + width + MARGIN + dialogW < windowW) {
  7063. left = x + width + MARGIN;
  7064. } else if (x > dialogW + MARGIN) {
  7065. left = x - dialogW - MARGIN;
  7066. }
  7067. } else if (x > dialogW + MARGIN) {
  7068. left = x - dialogW - MARGIN;
  7069. } else if (x + width + MARGIN + dialogW < windowW) {
  7070. left = x + width + MARGIN;
  7071. }
  7072. if (left === null) {
  7073. top = null;
  7074. left = Math.max(x, 0);
  7075. left += Math.min(windowW - (left + dialogW), 0);
  7076. if (y > dialogH + MARGIN) {
  7077. top = y - dialogH - MARGIN;
  7078. } else if (y + height + MARGIN + dialogH < windowH) {
  7079. top = y + height + MARGIN;
  7080. }
  7081. }
  7082. if (top !== null) {
  7083. dialog.classList.add("positioned");
  7084. if (isLTR) {
  7085. style.left = `${left}px`;
  7086. } else {
  7087. style.right = `${windowW - left - dialogW}px`;
  7088. }
  7089. style.top = `${top}px`;
  7090. } else {
  7091. dialog.classList.remove("positioned");
  7092. style.left = "";
  7093. style.top = "";
  7094. }
  7095. }
  7096. #finish() {
  7097. this.#overlayManager.closeIfActive(this.#dialog);
  7098. }
  7099. #close() {
  7100. this.#currentEditor._reportTelemetry(this.#telemetryData || {
  7101. action: "alt_text_cancel",
  7102. alt_text_keyboard: !this.#hasUsedPointer
  7103. });
  7104. this.#telemetryData = null;
  7105. this.#removeOnClickListeners();
  7106. this.#uiManager?.addEditListeners();
  7107. this.#resizeAC?.abort();
  7108. this.#resizeAC = null;
  7109. this.#currentEditor.altTextFinish();
  7110. this.#currentEditor = null;
  7111. this.#uiManager = null;
  7112. }
  7113. #updateUIState() {
  7114. this.#textarea.disabled = this.#optionDecorative.checked;
  7115. }
  7116. #save() {
  7117. const altText = this.#textarea.value.trim();
  7118. const decorative = this.#optionDecorative.checked;
  7119. this.#currentEditor.altTextData = {
  7120. altText,
  7121. decorative
  7122. };
  7123. this.#telemetryData = {
  7124. action: "alt_text_save",
  7125. alt_text_description: !!altText,
  7126. alt_text_edit: !!this.#previousAltText && this.#previousAltText !== altText,
  7127. alt_text_decorative: decorative,
  7128. alt_text_keyboard: !this.#hasUsedPointer
  7129. };
  7130. this.#finish();
  7131. }
  7132. #onClick(evt) {
  7133. if (evt.detail === 0) {
  7134. return;
  7135. }
  7136. this.#hasUsedPointer = true;
  7137. this.#removeOnClickListeners();
  7138. }
  7139. #removeOnClickListeners() {
  7140. this.#clickAC?.abort();
  7141. this.#clickAC = null;
  7142. }
  7143. destroy() {
  7144. this.#uiManager = null;
  7145. this.#finish();
  7146. this.#svgElement?.remove();
  7147. this.#svgElement = this.#rectElement = null;
  7148. }
  7149. }
  7150. ;// ./web/annotation_editor_params.js
  7151. class AnnotationEditorParams {
  7152. constructor(options, eventBus) {
  7153. this.eventBus = eventBus;
  7154. this.#bindListeners(options);
  7155. }
  7156. #bindListeners({
  7157. editorFreeTextFontSize,
  7158. editorFreeTextColor,
  7159. editorInkColor,
  7160. editorInkThickness,
  7161. editorInkOpacity,
  7162. editorStampAddImage,
  7163. editorFreeHighlightThickness,
  7164. editorHighlightShowAll,
  7165. editorSignatureAddSignature
  7166. }) {
  7167. const {
  7168. eventBus
  7169. } = this;
  7170. const dispatchEvent = (typeStr, value) => {
  7171. eventBus.dispatch("switchannotationeditorparams", {
  7172. source: this,
  7173. type: AnnotationEditorParamsType[typeStr],
  7174. value
  7175. });
  7176. };
  7177. editorFreeTextFontSize.addEventListener("input", function () {
  7178. dispatchEvent("FREETEXT_SIZE", this.valueAsNumber);
  7179. });
  7180. editorFreeTextColor.addEventListener("input", function () {
  7181. dispatchEvent("FREETEXT_COLOR", this.value);
  7182. });
  7183. editorInkColor.addEventListener("input", function () {
  7184. dispatchEvent("INK_COLOR", this.value);
  7185. });
  7186. editorInkThickness.addEventListener("input", function () {
  7187. dispatchEvent("INK_THICKNESS", this.valueAsNumber);
  7188. });
  7189. editorInkOpacity.addEventListener("input", function () {
  7190. dispatchEvent("INK_OPACITY", this.valueAsNumber);
  7191. });
  7192. editorStampAddImage.addEventListener("click", () => {
  7193. eventBus.dispatch("reporttelemetry", {
  7194. source: this,
  7195. details: {
  7196. type: "editing",
  7197. data: {
  7198. action: "pdfjs.image.add_image_click"
  7199. }
  7200. }
  7201. });
  7202. dispatchEvent("CREATE");
  7203. });
  7204. editorFreeHighlightThickness.addEventListener("input", function () {
  7205. dispatchEvent("HIGHLIGHT_THICKNESS", this.valueAsNumber);
  7206. });
  7207. editorHighlightShowAll.addEventListener("click", function () {
  7208. const checked = this.getAttribute("aria-pressed") === "true";
  7209. this.setAttribute("aria-pressed", !checked);
  7210. dispatchEvent("HIGHLIGHT_SHOW_ALL", !checked);
  7211. });
  7212. editorSignatureAddSignature.addEventListener("click", () => {
  7213. dispatchEvent("CREATE");
  7214. });
  7215. eventBus._on("annotationeditorparamschanged", evt => {
  7216. for (const [type, value] of evt.details) {
  7217. switch (type) {
  7218. case AnnotationEditorParamsType.FREETEXT_SIZE:
  7219. editorFreeTextFontSize.value = value;
  7220. break;
  7221. case AnnotationEditorParamsType.FREETEXT_COLOR:
  7222. editorFreeTextColor.value = value;
  7223. break;
  7224. case AnnotationEditorParamsType.INK_COLOR:
  7225. editorInkColor.value = value;
  7226. break;
  7227. case AnnotationEditorParamsType.INK_THICKNESS:
  7228. editorInkThickness.value = value;
  7229. break;
  7230. case AnnotationEditorParamsType.INK_OPACITY:
  7231. editorInkOpacity.value = value;
  7232. break;
  7233. case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR:
  7234. eventBus.dispatch("mainhighlightcolorpickerupdatecolor", {
  7235. source: this,
  7236. value
  7237. });
  7238. break;
  7239. case AnnotationEditorParamsType.HIGHLIGHT_THICKNESS:
  7240. editorFreeHighlightThickness.value = value;
  7241. break;
  7242. case AnnotationEditorParamsType.HIGHLIGHT_FREE:
  7243. editorFreeHighlightThickness.disabled = !value;
  7244. break;
  7245. case AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL:
  7246. editorHighlightShowAll.setAttribute("aria-pressed", value);
  7247. break;
  7248. }
  7249. }
  7250. });
  7251. }
  7252. }
  7253. ;// ./web/caret_browsing.js
  7254. const PRECISION = 1e-1;
  7255. class CaretBrowsingMode {
  7256. #mainContainer;
  7257. #toolBarHeight = 0;
  7258. #viewerContainer;
  7259. constructor(abortSignal, mainContainer, viewerContainer, toolbarContainer) {
  7260. this.#mainContainer = mainContainer;
  7261. this.#viewerContainer = viewerContainer;
  7262. if (!toolbarContainer) {
  7263. return;
  7264. }
  7265. this.#toolBarHeight = toolbarContainer.getBoundingClientRect().height;
  7266. const toolbarObserver = new ResizeObserver(entries => {
  7267. for (const entry of entries) {
  7268. if (entry.target === toolbarContainer) {
  7269. this.#toolBarHeight = Math.floor(entry.borderBoxSize[0].blockSize);
  7270. break;
  7271. }
  7272. }
  7273. });
  7274. toolbarObserver.observe(toolbarContainer);
  7275. abortSignal.addEventListener("abort", () => toolbarObserver.disconnect(), {
  7276. once: true
  7277. });
  7278. }
  7279. #isOnSameLine(rect1, rect2) {
  7280. const top1 = rect1.y;
  7281. const bot1 = rect1.bottom;
  7282. const mid1 = rect1.y + rect1.height / 2;
  7283. const top2 = rect2.y;
  7284. const bot2 = rect2.bottom;
  7285. const mid2 = rect2.y + rect2.height / 2;
  7286. return top1 <= mid2 && mid2 <= bot1 || top2 <= mid1 && mid1 <= bot2;
  7287. }
  7288. #isUnderOver(rect, x, y, isUp) {
  7289. const midY = rect.y + rect.height / 2;
  7290. return (isUp ? y >= midY : y <= midY) && rect.x - PRECISION <= x && x <= rect.right + PRECISION;
  7291. }
  7292. #isVisible(rect) {
  7293. return rect.top >= this.#toolBarHeight && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
  7294. }
  7295. #getCaretPosition(selection, isUp) {
  7296. const {
  7297. focusNode,
  7298. focusOffset
  7299. } = selection;
  7300. const range = document.createRange();
  7301. range.setStart(focusNode, focusOffset);
  7302. range.setEnd(focusNode, focusOffset);
  7303. const rect = range.getBoundingClientRect();
  7304. return [rect.x, isUp ? rect.top : rect.bottom];
  7305. }
  7306. static #caretPositionFromPoint(x, y) {
  7307. if (!document.caretPositionFromPoint) {
  7308. const {
  7309. startContainer: offsetNode,
  7310. startOffset: offset
  7311. } = document.caretRangeFromPoint(x, y);
  7312. return {
  7313. offsetNode,
  7314. offset
  7315. };
  7316. }
  7317. return document.caretPositionFromPoint(x, y);
  7318. }
  7319. #setCaretPositionHelper(selection, caretX, select, element, rect) {
  7320. rect ||= element.getBoundingClientRect();
  7321. if (caretX <= rect.x + PRECISION) {
  7322. if (select) {
  7323. selection.extend(element.firstChild, 0);
  7324. } else {
  7325. selection.setPosition(element.firstChild, 0);
  7326. }
  7327. return;
  7328. }
  7329. if (rect.right - PRECISION <= caretX) {
  7330. const {
  7331. lastChild
  7332. } = element;
  7333. if (select) {
  7334. selection.extend(lastChild, lastChild.length);
  7335. } else {
  7336. selection.setPosition(lastChild, lastChild.length);
  7337. }
  7338. return;
  7339. }
  7340. const midY = rect.y + rect.height / 2;
  7341. let caretPosition = CaretBrowsingMode.#caretPositionFromPoint(caretX, midY);
  7342. let parentElement = caretPosition.offsetNode?.parentElement;
  7343. if (parentElement && parentElement !== element) {
  7344. const elementsAtPoint = document.elementsFromPoint(caretX, midY);
  7345. const savedVisibilities = [];
  7346. for (const el of elementsAtPoint) {
  7347. if (el === element) {
  7348. break;
  7349. }
  7350. const {
  7351. style
  7352. } = el;
  7353. savedVisibilities.push([el, style.visibility]);
  7354. style.visibility = "hidden";
  7355. }
  7356. caretPosition = CaretBrowsingMode.#caretPositionFromPoint(caretX, midY);
  7357. parentElement = caretPosition.offsetNode?.parentElement;
  7358. for (const [el, visibility] of savedVisibilities) {
  7359. el.style.visibility = visibility;
  7360. }
  7361. }
  7362. if (parentElement !== element) {
  7363. if (select) {
  7364. selection.extend(element.firstChild, 0);
  7365. } else {
  7366. selection.setPosition(element.firstChild, 0);
  7367. }
  7368. return;
  7369. }
  7370. if (select) {
  7371. selection.extend(caretPosition.offsetNode, caretPosition.offset);
  7372. } else {
  7373. selection.setPosition(caretPosition.offsetNode, caretPosition.offset);
  7374. }
  7375. }
  7376. #setCaretPosition(select, selection, newLineElement, newLineElementRect, caretX) {
  7377. if (this.#isVisible(newLineElementRect)) {
  7378. this.#setCaretPositionHelper(selection, caretX, select, newLineElement, newLineElementRect);
  7379. return;
  7380. }
  7381. this.#mainContainer.addEventListener("scrollend", this.#setCaretPositionHelper.bind(this, selection, caretX, select, newLineElement, null), {
  7382. once: true
  7383. });
  7384. newLineElement.scrollIntoView();
  7385. }
  7386. #getNodeOnNextPage(textLayer, isUp) {
  7387. while (true) {
  7388. const page = textLayer.closest(".page");
  7389. const pageNumber = parseInt(page.getAttribute("data-page-number"));
  7390. const nextPage = isUp ? pageNumber - 1 : pageNumber + 1;
  7391. textLayer = this.#viewerContainer.querySelector(`.page[data-page-number="${nextPage}"] .textLayer`);
  7392. if (!textLayer) {
  7393. return null;
  7394. }
  7395. const walker = document.createTreeWalker(textLayer, NodeFilter.SHOW_TEXT);
  7396. const node = isUp ? walker.lastChild() : walker.firstChild();
  7397. if (node) {
  7398. return node;
  7399. }
  7400. }
  7401. }
  7402. moveCaret(isUp, select) {
  7403. const selection = document.getSelection();
  7404. if (selection.rangeCount === 0) {
  7405. return;
  7406. }
  7407. const {
  7408. focusNode
  7409. } = selection;
  7410. const focusElement = focusNode.nodeType !== Node.ELEMENT_NODE ? focusNode.parentElement : focusNode;
  7411. const root = focusElement.closest(".textLayer");
  7412. if (!root) {
  7413. return;
  7414. }
  7415. const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
  7416. walker.currentNode = focusNode;
  7417. const focusRect = focusElement.getBoundingClientRect();
  7418. let newLineElement = null;
  7419. const nodeIterator = (isUp ? walker.previousSibling : walker.nextSibling).bind(walker);
  7420. while (nodeIterator()) {
  7421. const element = walker.currentNode.parentElement;
  7422. if (!this.#isOnSameLine(focusRect, element.getBoundingClientRect())) {
  7423. newLineElement = element;
  7424. break;
  7425. }
  7426. }
  7427. if (!newLineElement) {
  7428. const node = this.#getNodeOnNextPage(root, isUp);
  7429. if (!node) {
  7430. return;
  7431. }
  7432. if (select) {
  7433. const lastNode = (isUp ? walker.firstChild() : walker.lastChild()) || focusNode;
  7434. selection.extend(lastNode, isUp ? 0 : lastNode.length);
  7435. const range = document.createRange();
  7436. range.setStart(node, isUp ? node.length : 0);
  7437. range.setEnd(node, isUp ? node.length : 0);
  7438. selection.addRange(range);
  7439. return;
  7440. }
  7441. const [caretX] = this.#getCaretPosition(selection, isUp);
  7442. const {
  7443. parentElement
  7444. } = node;
  7445. this.#setCaretPosition(select, selection, parentElement, parentElement.getBoundingClientRect(), caretX);
  7446. return;
  7447. }
  7448. const [caretX, caretY] = this.#getCaretPosition(selection, isUp);
  7449. const newLineElementRect = newLineElement.getBoundingClientRect();
  7450. if (this.#isUnderOver(newLineElementRect, caretX, caretY, isUp)) {
  7451. this.#setCaretPosition(select, selection, newLineElement, newLineElementRect, caretX);
  7452. return;
  7453. }
  7454. while (nodeIterator()) {
  7455. const element = walker.currentNode.parentElement;
  7456. const elementRect = element.getBoundingClientRect();
  7457. if (!this.#isOnSameLine(newLineElementRect, elementRect)) {
  7458. break;
  7459. }
  7460. if (this.#isUnderOver(elementRect, caretX, caretY, isUp)) {
  7461. this.#setCaretPosition(select, selection, element, elementRect, caretX);
  7462. return;
  7463. }
  7464. }
  7465. this.#setCaretPosition(select, selection, newLineElement, newLineElementRect, caretX);
  7466. }
  7467. }
  7468. ;// ./web/download_manager.js
  7469. function download(blobUrl, filename) {
  7470. const a = document.createElement("a");
  7471. if (!a.click) {
  7472. throw new Error('DownloadManager: "a.click()" is not supported.');
  7473. }
  7474. a.href = blobUrl;
  7475. a.target = "_parent";
  7476. if ("download" in a) {
  7477. a.download = filename;
  7478. }
  7479. (document.body || document.documentElement).append(a);
  7480. a.click();
  7481. a.remove();
  7482. }
  7483. class DownloadManager {
  7484. #openBlobUrls = new WeakMap();
  7485. downloadData(data, filename, contentType) {
  7486. const blobUrl = URL.createObjectURL(new Blob([data], {
  7487. type: contentType
  7488. }));
  7489. download(blobUrl, filename);
  7490. }
  7491. openOrDownloadData(data, filename, dest = null) {
  7492. const isPdfData = isPdfFile(filename);
  7493. const contentType = isPdfData ? "application/pdf" : "";
  7494. if (isPdfData) {
  7495. let blobUrl = this.#openBlobUrls.get(data);
  7496. if (!blobUrl) {
  7497. blobUrl = URL.createObjectURL(new Blob([data], {
  7498. type: contentType
  7499. }));
  7500. this.#openBlobUrls.set(data, blobUrl);
  7501. }
  7502. let viewerUrl;
  7503. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  7504. if (dest) {
  7505. viewerUrl += `#${escape(dest)}`;
  7506. }
  7507. try {
  7508. window.open(viewerUrl);
  7509. return true;
  7510. } catch (ex) {
  7511. console.error("openOrDownloadData:", ex);
  7512. URL.revokeObjectURL(blobUrl);
  7513. this.#openBlobUrls.delete(data);
  7514. }
  7515. }
  7516. this.downloadData(data, filename, contentType);
  7517. return false;
  7518. }
  7519. download(data, url, filename) {
  7520. let blobUrl;
  7521. if (data) {
  7522. blobUrl = URL.createObjectURL(new Blob([data], {
  7523. type: "application/pdf"
  7524. }));
  7525. } else {
  7526. if (!createValidAbsoluteUrl(url, "http://example.com")) {
  7527. console.error(`download - not a valid URL: ${url}`);
  7528. return;
  7529. }
  7530. blobUrl = url + "#pdfjs.action=download";
  7531. }
  7532. download(blobUrl, filename);
  7533. }
  7534. }
  7535. ;// ./web/editor_undo_bar.js
  7536. class EditorUndoBar {
  7537. #closeButton = null;
  7538. #container;
  7539. #eventBus = null;
  7540. #focusTimeout = null;
  7541. #initController = null;
  7542. isOpen = false;
  7543. #message;
  7544. #showController = null;
  7545. #undoButton;
  7546. static #l10nMessages = Object.freeze({
  7547. highlight: "pdfjs-editor-undo-bar-message-highlight",
  7548. freetext: "pdfjs-editor-undo-bar-message-freetext",
  7549. stamp: "pdfjs-editor-undo-bar-message-stamp",
  7550. ink: "pdfjs-editor-undo-bar-message-ink",
  7551. signature: "pdfjs-editor-undo-bar-message-signature",
  7552. _multiple: "pdfjs-editor-undo-bar-message-multiple"
  7553. });
  7554. constructor({
  7555. container,
  7556. message,
  7557. undoButton,
  7558. closeButton
  7559. }, eventBus) {
  7560. this.#container = container;
  7561. this.#message = message;
  7562. this.#undoButton = undoButton;
  7563. this.#closeButton = closeButton;
  7564. this.#eventBus = eventBus;
  7565. }
  7566. destroy() {
  7567. this.#initController?.abort();
  7568. this.#initController = null;
  7569. this.hide();
  7570. }
  7571. show(undoAction, messageData) {
  7572. if (!this.#initController) {
  7573. this.#initController = new AbortController();
  7574. const opts = {
  7575. signal: this.#initController.signal
  7576. };
  7577. const boundHide = this.hide.bind(this);
  7578. this.#container.addEventListener("contextmenu", noContextMenu, opts);
  7579. this.#closeButton.addEventListener("click", boundHide, opts);
  7580. this.#eventBus._on("beforeprint", boundHide, opts);
  7581. this.#eventBus._on("download", boundHide, opts);
  7582. }
  7583. this.hide();
  7584. if (typeof messageData === "string") {
  7585. this.#message.setAttribute("data-l10n-id", EditorUndoBar.#l10nMessages[messageData]);
  7586. } else {
  7587. this.#message.setAttribute("data-l10n-id", EditorUndoBar.#l10nMessages._multiple);
  7588. this.#message.setAttribute("data-l10n-args", JSON.stringify({
  7589. count: messageData
  7590. }));
  7591. }
  7592. this.isOpen = true;
  7593. this.#container.hidden = false;
  7594. this.#showController = new AbortController();
  7595. this.#undoButton.addEventListener("click", () => {
  7596. undoAction();
  7597. this.hide();
  7598. }, {
  7599. signal: this.#showController.signal
  7600. });
  7601. this.#focusTimeout = setTimeout(() => {
  7602. this.#container.focus();
  7603. this.#focusTimeout = null;
  7604. }, 100);
  7605. }
  7606. hide() {
  7607. if (!this.isOpen) {
  7608. return;
  7609. }
  7610. this.isOpen = false;
  7611. this.#container.hidden = true;
  7612. this.#showController?.abort();
  7613. this.#showController = null;
  7614. if (this.#focusTimeout) {
  7615. clearTimeout(this.#focusTimeout);
  7616. this.#focusTimeout = null;
  7617. }
  7618. }
  7619. }
  7620. ;// ./web/overlay_manager.js
  7621. class OverlayManager {
  7622. #overlays = new WeakMap();
  7623. #active = null;
  7624. get active() {
  7625. return this.#active;
  7626. }
  7627. async register(dialog, canForceClose = false) {
  7628. if (typeof dialog !== "object") {
  7629. throw new Error("Not enough parameters.");
  7630. } else if (this.#overlays.has(dialog)) {
  7631. throw new Error("The overlay is already registered.");
  7632. }
  7633. this.#overlays.set(dialog, {
  7634. canForceClose
  7635. });
  7636. dialog.addEventListener("cancel", ({
  7637. target
  7638. }) => {
  7639. if (this.#active === target) {
  7640. this.#active = null;
  7641. }
  7642. });
  7643. }
  7644. async open(dialog) {
  7645. if (!this.#overlays.has(dialog)) {
  7646. throw new Error("The overlay does not exist.");
  7647. } else if (this.#active) {
  7648. if (this.#active === dialog) {
  7649. throw new Error("The overlay is already active.");
  7650. } else if (this.#overlays.get(dialog).canForceClose) {
  7651. await this.close();
  7652. } else {
  7653. throw new Error("Another overlay is currently active.");
  7654. }
  7655. }
  7656. this.#active = dialog;
  7657. dialog.showModal();
  7658. }
  7659. async close(dialog = this.#active) {
  7660. if (!this.#overlays.has(dialog)) {
  7661. throw new Error("The overlay does not exist.");
  7662. } else if (!this.#active) {
  7663. throw new Error("The overlay is currently not active.");
  7664. } else if (this.#active !== dialog) {
  7665. throw new Error("Another overlay is currently active.");
  7666. }
  7667. dialog.close();
  7668. this.#active = null;
  7669. }
  7670. async closeIfActive(dialog) {
  7671. if (this.#active === dialog) {
  7672. await this.close(dialog);
  7673. }
  7674. }
  7675. }
  7676. ;// ./web/password_prompt.js
  7677. class PasswordPrompt {
  7678. #activeCapability = null;
  7679. #updateCallback = null;
  7680. #reason = null;
  7681. constructor(options, overlayManager, isViewerEmbedded = false) {
  7682. this.dialog = options.dialog;
  7683. this.label = options.label;
  7684. this.input = options.input;
  7685. this.submitButton = options.submitButton;
  7686. this.cancelButton = options.cancelButton;
  7687. this.overlayManager = overlayManager;
  7688. this._isViewerEmbedded = isViewerEmbedded;
  7689. this.submitButton.addEventListener("click", this.#verify.bind(this));
  7690. this.cancelButton.addEventListener("click", this.close.bind(this));
  7691. this.input.addEventListener("keydown", e => {
  7692. if (e.keyCode === 13) {
  7693. this.#verify();
  7694. }
  7695. });
  7696. this.overlayManager.register(this.dialog, true);
  7697. this.dialog.addEventListener("close", this.#cancel.bind(this));
  7698. }
  7699. async open() {
  7700. await this.#activeCapability?.promise;
  7701. this.#activeCapability = Promise.withResolvers();
  7702. try {
  7703. await this.overlayManager.open(this.dialog);
  7704. } catch (ex) {
  7705. this.#activeCapability.resolve();
  7706. throw ex;
  7707. }
  7708. const passwordIncorrect = this.#reason === PasswordResponses.INCORRECT_PASSWORD;
  7709. if (!this._isViewerEmbedded || passwordIncorrect) {
  7710. this.input.focus();
  7711. }
  7712. this.label.setAttribute("data-l10n-id", passwordIncorrect ? "pdfjs-password-invalid" : "pdfjs-password-label");
  7713. }
  7714. async close() {
  7715. this.overlayManager.closeIfActive(this.dialog);
  7716. }
  7717. #verify() {
  7718. const password = this.input.value;
  7719. if (password?.length > 0) {
  7720. this.#invokeCallback(password);
  7721. }
  7722. }
  7723. #cancel() {
  7724. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  7725. this.#activeCapability.resolve();
  7726. }
  7727. #invokeCallback(password) {
  7728. if (!this.#updateCallback) {
  7729. return;
  7730. }
  7731. this.close();
  7732. this.input.value = "";
  7733. this.#updateCallback(password);
  7734. this.#updateCallback = null;
  7735. }
  7736. async setUpdateCallback(updateCallback, reason) {
  7737. if (this.#activeCapability) {
  7738. await this.#activeCapability.promise;
  7739. }
  7740. this.#updateCallback = updateCallback;
  7741. this.#reason = reason;
  7742. }
  7743. }
  7744. ;// ./web/base_tree_viewer.js
  7745. const TREEITEM_OFFSET_TOP = -100;
  7746. const TREEITEM_SELECTED_CLASS = "selected";
  7747. class BaseTreeViewer {
  7748. constructor(options) {
  7749. this.container = options.container;
  7750. this.eventBus = options.eventBus;
  7751. this._l10n = options.l10n;
  7752. this.reset();
  7753. }
  7754. reset() {
  7755. this._pdfDocument = null;
  7756. this._lastToggleIsShow = true;
  7757. this._currentTreeItem = null;
  7758. this.container.textContent = "";
  7759. this.container.classList.remove("treeWithDeepNesting");
  7760. }
  7761. _dispatchEvent(count) {
  7762. throw new Error("Not implemented: _dispatchEvent");
  7763. }
  7764. _bindLink(element, params) {
  7765. throw new Error("Not implemented: _bindLink");
  7766. }
  7767. _normalizeTextContent(str) {
  7768. return removeNullCharacters(str, true) || "\u2013";
  7769. }
  7770. _addToggleButton(div, hidden = false) {
  7771. const toggler = document.createElement("div");
  7772. toggler.className = "treeItemToggler";
  7773. if (hidden) {
  7774. toggler.classList.add("treeItemsHidden");
  7775. }
  7776. toggler.onclick = evt => {
  7777. evt.stopPropagation();
  7778. toggler.classList.toggle("treeItemsHidden");
  7779. if (evt.shiftKey) {
  7780. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  7781. this._toggleTreeItem(div, shouldShowAll);
  7782. }
  7783. };
  7784. div.prepend(toggler);
  7785. }
  7786. _toggleTreeItem(root, show = false) {
  7787. this._l10n.pause();
  7788. this._lastToggleIsShow = show;
  7789. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  7790. toggler.classList.toggle("treeItemsHidden", !show);
  7791. }
  7792. this._l10n.resume();
  7793. }
  7794. _toggleAllTreeItems() {
  7795. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  7796. }
  7797. _finishRendering(fragment, count, hasAnyNesting = false) {
  7798. if (hasAnyNesting) {
  7799. this.container.classList.add("treeWithDeepNesting");
  7800. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  7801. }
  7802. this._l10n.pause();
  7803. this.container.append(fragment);
  7804. this._l10n.resume();
  7805. this._dispatchEvent(count);
  7806. }
  7807. render(params) {
  7808. throw new Error("Not implemented: render");
  7809. }
  7810. _updateCurrentTreeItem(treeItem = null) {
  7811. if (this._currentTreeItem) {
  7812. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  7813. this._currentTreeItem = null;
  7814. }
  7815. if (treeItem) {
  7816. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  7817. this._currentTreeItem = treeItem;
  7818. }
  7819. }
  7820. _scrollToCurrentTreeItem(treeItem) {
  7821. if (!treeItem) {
  7822. return;
  7823. }
  7824. this._l10n.pause();
  7825. let currentNode = treeItem.parentNode;
  7826. while (currentNode && currentNode !== this.container) {
  7827. if (currentNode.classList.contains("treeItem")) {
  7828. const toggler = currentNode.firstElementChild;
  7829. toggler?.classList.remove("treeItemsHidden");
  7830. }
  7831. currentNode = currentNode.parentNode;
  7832. }
  7833. this._l10n.resume();
  7834. this._updateCurrentTreeItem(treeItem);
  7835. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  7836. }
  7837. }
  7838. ;// ./web/pdf_attachment_viewer.js
  7839. class PDFAttachmentViewer extends BaseTreeViewer {
  7840. constructor(options) {
  7841. super(options);
  7842. this.downloadManager = options.downloadManager;
  7843. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  7844. }
  7845. reset(keepRenderedCapability = false) {
  7846. super.reset();
  7847. this._attachments = null;
  7848. if (!keepRenderedCapability) {
  7849. this._renderedCapability = Promise.withResolvers();
  7850. }
  7851. this._pendingDispatchEvent = false;
  7852. }
  7853. async _dispatchEvent(attachmentsCount) {
  7854. this._renderedCapability.resolve();
  7855. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  7856. this._pendingDispatchEvent = true;
  7857. await waitOnEventOrTimeout({
  7858. target: this.eventBus,
  7859. name: "annotationlayerrendered",
  7860. delay: 1000
  7861. });
  7862. if (!this._pendingDispatchEvent) {
  7863. return;
  7864. }
  7865. }
  7866. this._pendingDispatchEvent = false;
  7867. this.eventBus.dispatch("attachmentsloaded", {
  7868. source: this,
  7869. attachmentsCount
  7870. });
  7871. }
  7872. _bindLink(element, {
  7873. content,
  7874. description,
  7875. filename
  7876. }) {
  7877. if (description) {
  7878. element.title = description;
  7879. }
  7880. element.onclick = () => {
  7881. this.downloadManager.openOrDownloadData(content, filename);
  7882. return false;
  7883. };
  7884. }
  7885. render({
  7886. attachments,
  7887. keepRenderedCapability = false
  7888. }) {
  7889. if (this._attachments) {
  7890. this.reset(keepRenderedCapability);
  7891. }
  7892. this._attachments = attachments || null;
  7893. if (!attachments) {
  7894. this._dispatchEvent(0);
  7895. return;
  7896. }
  7897. const fragment = document.createDocumentFragment();
  7898. let attachmentsCount = 0;
  7899. for (const name in attachments) {
  7900. const item = attachments[name];
  7901. const div = document.createElement("div");
  7902. div.className = "treeItem";
  7903. const element = document.createElement("a");
  7904. this._bindLink(element, item);
  7905. element.textContent = this._normalizeTextContent(item.filename);
  7906. div.append(element);
  7907. fragment.append(div);
  7908. attachmentsCount++;
  7909. }
  7910. this._finishRendering(fragment, attachmentsCount);
  7911. }
  7912. #appendAttachment(item) {
  7913. const renderedPromise = this._renderedCapability.promise;
  7914. renderedPromise.then(() => {
  7915. if (renderedPromise !== this._renderedCapability.promise) {
  7916. return;
  7917. }
  7918. const attachments = this._attachments || Object.create(null);
  7919. for (const name in attachments) {
  7920. if (item.filename === name) {
  7921. return;
  7922. }
  7923. }
  7924. attachments[item.filename] = item;
  7925. this.render({
  7926. attachments,
  7927. keepRenderedCapability: true
  7928. });
  7929. });
  7930. }
  7931. }
  7932. ;// ./web/grab_to_pan.js
  7933. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  7934. class GrabToPan {
  7935. #activateAC = null;
  7936. #mouseDownAC = null;
  7937. #scrollAC = null;
  7938. constructor({
  7939. element
  7940. }) {
  7941. this.element = element;
  7942. this.document = element.ownerDocument;
  7943. const overlay = this.overlay = document.createElement("div");
  7944. overlay.className = "grab-to-pan-grabbing";
  7945. }
  7946. activate() {
  7947. if (!this.#activateAC) {
  7948. this.#activateAC = new AbortController();
  7949. this.element.addEventListener("mousedown", this.#onMouseDown.bind(this), {
  7950. capture: true,
  7951. signal: this.#activateAC.signal
  7952. });
  7953. this.element.classList.add(CSS_CLASS_GRAB);
  7954. }
  7955. }
  7956. deactivate() {
  7957. if (this.#activateAC) {
  7958. this.#activateAC.abort();
  7959. this.#activateAC = null;
  7960. this.#endPan();
  7961. this.element.classList.remove(CSS_CLASS_GRAB);
  7962. }
  7963. }
  7964. toggle() {
  7965. if (this.#activateAC) {
  7966. this.deactivate();
  7967. } else {
  7968. this.activate();
  7969. }
  7970. }
  7971. ignoreTarget(node) {
  7972. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  7973. }
  7974. #onMouseDown(event) {
  7975. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  7976. return;
  7977. }
  7978. if (event.originalTarget) {
  7979. try {
  7980. event.originalTarget.tagName;
  7981. } catch {
  7982. return;
  7983. }
  7984. }
  7985. this.scrollLeftStart = this.element.scrollLeft;
  7986. this.scrollTopStart = this.element.scrollTop;
  7987. this.clientXStart = event.clientX;
  7988. this.clientYStart = event.clientY;
  7989. this.#mouseDownAC = new AbortController();
  7990. const boundEndPan = this.#endPan.bind(this),
  7991. mouseOpts = {
  7992. capture: true,
  7993. signal: this.#mouseDownAC.signal
  7994. };
  7995. this.document.addEventListener("mousemove", this.#onMouseMove.bind(this), mouseOpts);
  7996. this.document.addEventListener("mouseup", boundEndPan, mouseOpts);
  7997. this.#scrollAC = new AbortController();
  7998. this.element.addEventListener("scroll", boundEndPan, {
  7999. capture: true,
  8000. signal: this.#scrollAC.signal
  8001. });
  8002. stopEvent(event);
  8003. const focusedElement = document.activeElement;
  8004. if (focusedElement && !focusedElement.contains(event.target)) {
  8005. focusedElement.blur();
  8006. }
  8007. }
  8008. #onMouseMove(event) {
  8009. this.#scrollAC?.abort();
  8010. this.#scrollAC = null;
  8011. if (!(event.buttons & 1)) {
  8012. this.#endPan();
  8013. return;
  8014. }
  8015. const xDiff = event.clientX - this.clientXStart;
  8016. const yDiff = event.clientY - this.clientYStart;
  8017. this.element.scrollTo({
  8018. top: this.scrollTopStart - yDiff,
  8019. left: this.scrollLeftStart - xDiff,
  8020. behavior: "instant"
  8021. });
  8022. if (!this.overlay.parentNode) {
  8023. document.body.append(this.overlay);
  8024. }
  8025. }
  8026. #endPan() {
  8027. this.#mouseDownAC?.abort();
  8028. this.#mouseDownAC = null;
  8029. this.#scrollAC?.abort();
  8030. this.#scrollAC = null;
  8031. this.overlay.remove();
  8032. }
  8033. }
  8034. ;// ./web/pdf_cursor_tools.js
  8035. class PDFCursorTools {
  8036. #active = CursorTool.SELECT;
  8037. #prevActive = null;
  8038. constructor({
  8039. container,
  8040. eventBus,
  8041. cursorToolOnLoad = CursorTool.SELECT
  8042. }) {
  8043. this.container = container;
  8044. this.eventBus = eventBus;
  8045. this.#addEventListeners();
  8046. Promise.resolve().then(() => {
  8047. this.switchTool(cursorToolOnLoad);
  8048. });
  8049. }
  8050. get activeTool() {
  8051. return this.#active;
  8052. }
  8053. switchTool(tool) {
  8054. if (this.#prevActive !== null) {
  8055. return;
  8056. }
  8057. this.#switchTool(tool);
  8058. }
  8059. #switchTool(tool, disabled = false) {
  8060. if (tool === this.#active) {
  8061. if (this.#prevActive !== null) {
  8062. this.eventBus.dispatch("cursortoolchanged", {
  8063. source: this,
  8064. tool,
  8065. disabled
  8066. });
  8067. }
  8068. return;
  8069. }
  8070. const disableActiveTool = () => {
  8071. switch (this.#active) {
  8072. case CursorTool.SELECT:
  8073. break;
  8074. case CursorTool.HAND:
  8075. this._handTool.deactivate();
  8076. break;
  8077. case CursorTool.ZOOM:
  8078. }
  8079. };
  8080. switch (tool) {
  8081. case CursorTool.SELECT:
  8082. disableActiveTool();
  8083. break;
  8084. case CursorTool.HAND:
  8085. disableActiveTool();
  8086. this._handTool.activate();
  8087. break;
  8088. case CursorTool.ZOOM:
  8089. default:
  8090. console.error(`switchTool: "${tool}" is an unsupported value.`);
  8091. return;
  8092. }
  8093. this.#active = tool;
  8094. this.eventBus.dispatch("cursortoolchanged", {
  8095. source: this,
  8096. tool,
  8097. disabled
  8098. });
  8099. }
  8100. #addEventListeners() {
  8101. this.eventBus._on("switchcursortool", evt => {
  8102. if (!evt.reset) {
  8103. this.switchTool(evt.tool);
  8104. } else if (this.#prevActive !== null) {
  8105. annotationEditorMode = AnnotationEditorType.NONE;
  8106. presentationModeState = PresentationModeState.NORMAL;
  8107. enableActive();
  8108. }
  8109. });
  8110. let annotationEditorMode = AnnotationEditorType.NONE,
  8111. presentationModeState = PresentationModeState.NORMAL;
  8112. const disableActive = () => {
  8113. this.#prevActive ??= this.#active;
  8114. this.#switchTool(CursorTool.SELECT, true);
  8115. };
  8116. const enableActive = () => {
  8117. if (this.#prevActive !== null && annotationEditorMode === AnnotationEditorType.NONE && presentationModeState === PresentationModeState.NORMAL) {
  8118. this.#switchTool(this.#prevActive);
  8119. this.#prevActive = null;
  8120. }
  8121. };
  8122. this.eventBus._on("annotationeditormodechanged", ({
  8123. mode
  8124. }) => {
  8125. annotationEditorMode = mode;
  8126. if (mode === AnnotationEditorType.NONE) {
  8127. enableActive();
  8128. } else {
  8129. disableActive();
  8130. }
  8131. });
  8132. this.eventBus._on("presentationmodechanged", ({
  8133. state
  8134. }) => {
  8135. presentationModeState = state;
  8136. if (state === PresentationModeState.NORMAL) {
  8137. enableActive();
  8138. } else if (state === PresentationModeState.FULLSCREEN) {
  8139. disableActive();
  8140. }
  8141. });
  8142. }
  8143. get _handTool() {
  8144. return shadow(this, "_handTool", new GrabToPan({
  8145. element: this.container
  8146. }));
  8147. }
  8148. }
  8149. ;// ./web/pdf_document_properties.js
  8150. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  8151. const US_PAGE_NAMES = {
  8152. "8.5x11": "pdfjs-document-properties-page-size-name-letter",
  8153. "8.5x14": "pdfjs-document-properties-page-size-name-legal"
  8154. };
  8155. const METRIC_PAGE_NAMES = {
  8156. "297x420": "pdfjs-document-properties-page-size-name-a-three",
  8157. "210x297": "pdfjs-document-properties-page-size-name-a-four"
  8158. };
  8159. function getPageName(size, isPortrait, pageNames) {
  8160. const width = isPortrait ? size.width : size.height;
  8161. const height = isPortrait ? size.height : size.width;
  8162. return pageNames[`${width}x${height}`];
  8163. }
  8164. class PDFDocumentProperties {
  8165. #fieldData = null;
  8166. constructor({
  8167. dialog,
  8168. fields,
  8169. closeButton
  8170. }, overlayManager, eventBus, l10n, fileNameLookup, titleLookup) {
  8171. this.dialog = dialog;
  8172. this.fields = fields;
  8173. this.overlayManager = overlayManager;
  8174. this.l10n = l10n;
  8175. this._fileNameLookup = fileNameLookup;
  8176. this._titleLookup = titleLookup;
  8177. this.#reset();
  8178. closeButton.addEventListener("click", this.close.bind(this));
  8179. this.overlayManager.register(this.dialog);
  8180. eventBus._on("pagechanging", evt => {
  8181. this._currentPageNumber = evt.pageNumber;
  8182. });
  8183. eventBus._on("rotationchanging", evt => {
  8184. this._pagesRotation = evt.pagesRotation;
  8185. });
  8186. }
  8187. async open() {
  8188. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  8189. const currentPageNumber = this._currentPageNumber;
  8190. const pagesRotation = this._pagesRotation;
  8191. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  8192. this.#updateUI();
  8193. return;
  8194. }
  8195. const [{
  8196. info,
  8197. metadata,
  8198. contentLength
  8199. }, pdfPage] = await Promise.all([this.pdfDocument.getMetadata(), this.pdfDocument.getPage(currentPageNumber)]);
  8200. const [fileName, fileSize, title, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([this._fileNameLookup(), this.#parseFileSize(contentLength), this._titleLookup(), this.#parseDate(metadata?.get("xmp:createdate"), info.CreationDate), this.#parseDate(metadata?.get("xmp:modifydate"), info.ModDate), this.#parsePageSize(getPageSizeInches(pdfPage), pagesRotation), this.#parseLinearization(info.IsLinearized)]);
  8201. this.#fieldData = Object.freeze({
  8202. fileName,
  8203. fileSize,
  8204. title,
  8205. author: metadata?.get("dc:creator")?.join("\n") || info.Author,
  8206. subject: metadata?.get("dc:subject")?.join("\n") || info.Subject,
  8207. keywords: metadata?.get("pdf:keywords") || info.Keywords,
  8208. creationDate,
  8209. modificationDate,
  8210. creator: metadata?.get("xmp:creatortool") || info.Creator,
  8211. producer: metadata?.get("pdf:producer") || info.Producer,
  8212. version: info.PDFFormatVersion,
  8213. pageCount: this.pdfDocument.numPages,
  8214. pageSize,
  8215. linearized: isLinearized,
  8216. _currentPageNumber: currentPageNumber,
  8217. _pagesRotation: pagesRotation
  8218. });
  8219. this.#updateUI();
  8220. const {
  8221. length
  8222. } = await this.pdfDocument.getDownloadInfo();
  8223. if (contentLength === length) {
  8224. return;
  8225. }
  8226. const data = Object.assign(Object.create(null), this.#fieldData);
  8227. data.fileSize = await this.#parseFileSize(length);
  8228. this.#fieldData = Object.freeze(data);
  8229. this.#updateUI();
  8230. }
  8231. async close() {
  8232. this.overlayManager.close(this.dialog);
  8233. }
  8234. setDocument(pdfDocument) {
  8235. if (this.pdfDocument) {
  8236. this.#reset();
  8237. this.#updateUI();
  8238. }
  8239. if (!pdfDocument) {
  8240. return;
  8241. }
  8242. this.pdfDocument = pdfDocument;
  8243. this._dataAvailableCapability.resolve();
  8244. }
  8245. #reset() {
  8246. this.pdfDocument = null;
  8247. this.#fieldData = null;
  8248. this._dataAvailableCapability = Promise.withResolvers();
  8249. this._currentPageNumber = 1;
  8250. this._pagesRotation = 0;
  8251. }
  8252. #updateUI() {
  8253. if (this.#fieldData && this.overlayManager.active !== this.dialog) {
  8254. return;
  8255. }
  8256. for (const id in this.fields) {
  8257. const content = this.#fieldData?.[id];
  8258. this.fields[id].textContent = content || content === 0 ? content : "-";
  8259. }
  8260. }
  8261. async #parseFileSize(b = 0) {
  8262. const kb = b / 1024,
  8263. mb = kb / 1024;
  8264. return kb ? this.l10n.get(mb >= 1 ? "pdfjs-document-properties-size-mb" : "pdfjs-document-properties-size-kb", {
  8265. mb,
  8266. kb,
  8267. b
  8268. }) : undefined;
  8269. }
  8270. async #parsePageSize(pageSizeInches, pagesRotation) {
  8271. if (!pageSizeInches) {
  8272. return undefined;
  8273. }
  8274. if (pagesRotation % 180 !== 0) {
  8275. pageSizeInches = {
  8276. width: pageSizeInches.height,
  8277. height: pageSizeInches.width
  8278. };
  8279. }
  8280. const isPortrait = isPortraitOrientation(pageSizeInches),
  8281. nonMetric = NON_METRIC_LOCALES.includes(this.l10n.getLanguage());
  8282. let sizeInches = {
  8283. width: Math.round(pageSizeInches.width * 100) / 100,
  8284. height: Math.round(pageSizeInches.height * 100) / 100
  8285. };
  8286. let sizeMillimeters = {
  8287. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  8288. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  8289. };
  8290. let nameId = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  8291. if (!nameId && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  8292. const exactMillimeters = {
  8293. width: pageSizeInches.width * 25.4,
  8294. height: pageSizeInches.height * 25.4
  8295. };
  8296. const intMillimeters = {
  8297. width: Math.round(sizeMillimeters.width),
  8298. height: Math.round(sizeMillimeters.height)
  8299. };
  8300. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  8301. nameId = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  8302. if (nameId) {
  8303. sizeInches = {
  8304. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  8305. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  8306. };
  8307. sizeMillimeters = intMillimeters;
  8308. }
  8309. }
  8310. }
  8311. const [{
  8312. width,
  8313. height
  8314. }, unit, name, orientation] = await Promise.all([nonMetric ? sizeInches : sizeMillimeters, this.l10n.get(nonMetric ? "pdfjs-document-properties-page-size-unit-inches" : "pdfjs-document-properties-page-size-unit-millimeters"), nameId && this.l10n.get(nameId), this.l10n.get(isPortrait ? "pdfjs-document-properties-page-size-orientation-portrait" : "pdfjs-document-properties-page-size-orientation-landscape")]);
  8315. return this.l10n.get(name ? "pdfjs-document-properties-page-size-dimension-name-string" : "pdfjs-document-properties-page-size-dimension-string", {
  8316. width,
  8317. height,
  8318. unit,
  8319. name,
  8320. orientation
  8321. });
  8322. }
  8323. async #parseDate(metadataDate, infoDate) {
  8324. const dateObj = Date.parse(metadataDate) || PDFDateString.toDateObject(infoDate);
  8325. return dateObj ? this.l10n.get("pdfjs-document-properties-date-time-string", {
  8326. dateObj: dateObj.valueOf()
  8327. }) : undefined;
  8328. }
  8329. #parseLinearization(isLinearized) {
  8330. return this.l10n.get(isLinearized ? "pdfjs-document-properties-linearized-yes" : "pdfjs-document-properties-linearized-no");
  8331. }
  8332. }
  8333. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.array-buffer.detached.js
  8334. var es_array_buffer_detached = __webpack_require__(6573);
  8335. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.array-buffer.transfer.js
  8336. var es_array_buffer_transfer = __webpack_require__(8100);
  8337. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.array-buffer.transfer-to-fixed-length.js
  8338. var es_array_buffer_transfer_to_fixed_length = __webpack_require__(7936);
  8339. ;// ./web/pdf_find_utils.js
  8340. const CharacterType = {
  8341. SPACE: 0,
  8342. ALPHA_LETTER: 1,
  8343. PUNCT: 2,
  8344. HAN_LETTER: 3,
  8345. KATAKANA_LETTER: 4,
  8346. HIRAGANA_LETTER: 5,
  8347. HALFWIDTH_KATAKANA_LETTER: 6,
  8348. THAI_LETTER: 7
  8349. };
  8350. function isAlphabeticalScript(charCode) {
  8351. return charCode < 0x2e80;
  8352. }
  8353. function isAscii(charCode) {
  8354. return (charCode & 0xff80) === 0;
  8355. }
  8356. function isAsciiAlpha(charCode) {
  8357. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  8358. }
  8359. function isAsciiDigit(charCode) {
  8360. return charCode >= 0x30 && charCode <= 0x39;
  8361. }
  8362. function isAsciiSpace(charCode) {
  8363. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  8364. }
  8365. function isHan(charCode) {
  8366. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  8367. }
  8368. function isKatakana(charCode) {
  8369. return charCode >= 0x30a0 && charCode <= 0x30ff;
  8370. }
  8371. function isHiragana(charCode) {
  8372. return charCode >= 0x3040 && charCode <= 0x309f;
  8373. }
  8374. function isHalfwidthKatakana(charCode) {
  8375. return charCode >= 0xff60 && charCode <= 0xff9f;
  8376. }
  8377. function isThai(charCode) {
  8378. return (charCode & 0xff80) === 0x0e00;
  8379. }
  8380. function getCharacterType(charCode) {
  8381. if (isAlphabeticalScript(charCode)) {
  8382. if (isAscii(charCode)) {
  8383. if (isAsciiSpace(charCode)) {
  8384. return CharacterType.SPACE;
  8385. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  8386. return CharacterType.ALPHA_LETTER;
  8387. }
  8388. return CharacterType.PUNCT;
  8389. } else if (isThai(charCode)) {
  8390. return CharacterType.THAI_LETTER;
  8391. } else if (charCode === 0xa0) {
  8392. return CharacterType.SPACE;
  8393. }
  8394. return CharacterType.ALPHA_LETTER;
  8395. }
  8396. if (isHan(charCode)) {
  8397. return CharacterType.HAN_LETTER;
  8398. } else if (isKatakana(charCode)) {
  8399. return CharacterType.KATAKANA_LETTER;
  8400. } else if (isHiragana(charCode)) {
  8401. return CharacterType.HIRAGANA_LETTER;
  8402. } else if (isHalfwidthKatakana(charCode)) {
  8403. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  8404. }
  8405. return CharacterType.ALPHA_LETTER;
  8406. }
  8407. let NormalizeWithNFKC;
  8408. function getNormalizeWithNFKC() {
  8409. NormalizeWithNFKC ||= ` ¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰꟲ-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`;
  8410. return NormalizeWithNFKC;
  8411. }
  8412. ;// ./web/pdf_find_controller.js
  8413. const FindState = {
  8414. FOUND: 0,
  8415. NOT_FOUND: 1,
  8416. WRAPPED: 2,
  8417. PENDING: 3
  8418. };
  8419. const FIND_TIMEOUT = 250;
  8420. const MATCH_SCROLL_OFFSET_TOP = -50;
  8421. const MATCH_SCROLL_OFFSET_LEFT = -400;
  8422. const CHARACTERS_TO_NORMALIZE = {
  8423. "\u2010": "-",
  8424. "\u2018": "'",
  8425. "\u2019": "'",
  8426. "\u201A": "'",
  8427. "\u201B": "'",
  8428. "\u201C": '"',
  8429. "\u201D": '"',
  8430. "\u201E": '"',
  8431. "\u201F": '"',
  8432. "\u00BC": "1/4",
  8433. "\u00BD": "1/2",
  8434. "\u00BE": "3/4"
  8435. };
  8436. 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]);
  8437. let DIACRITICS_EXCEPTION_STR;
  8438. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  8439. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  8440. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  8441. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  8442. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  8443. const SYLLABLES_LENGTHS = new Map();
  8444. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  8445. const NFKC_CHARS_TO_NORMALIZE = new Map();
  8446. let noSyllablesRegExp = null;
  8447. let withSyllablesRegExp = null;
  8448. function normalize(text) {
  8449. const syllablePositions = [];
  8450. let m;
  8451. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  8452. let {
  8453. index
  8454. } = m;
  8455. for (const char of m[0]) {
  8456. let len = SYLLABLES_LENGTHS.get(char);
  8457. if (!len) {
  8458. len = char.normalize("NFD").length;
  8459. SYLLABLES_LENGTHS.set(char, len);
  8460. }
  8461. syllablePositions.push([len, index++]);
  8462. }
  8463. }
  8464. const hasSyllables = syllablePositions.length > 0;
  8465. let normalizationRegex;
  8466. if (!hasSyllables && noSyllablesRegExp) {
  8467. normalizationRegex = noSyllablesRegExp;
  8468. } else if (hasSyllables && withSyllablesRegExp) {
  8469. normalizationRegex = withSyllablesRegExp;
  8470. } else {
  8471. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  8472. const toNormalizeWithNFKC = getNormalizeWithNFKC();
  8473. const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
  8474. const HKDiacritics = "(?:\u3099|\u309A)";
  8475. const BrokenWord = `\\p{Ll}-\\n(?=\\p{Ll})|\\p{Lu}-\\n(?=\\p{L})`;
  8476. const regexps = [`[${replace}]`, `[${toNormalizeWithNFKC}]`, `${HKDiacritics}\\n`, "\\p{M}+(?:-\\n)?", `${BrokenWord}`, "\\S-\\n", `${CJK}\\n`, "\\n", hasSyllables ? FIRST_CHAR_SYLLABLES_REG_EXP : "\\u0000"];
  8477. normalizationRegex = new RegExp(regexps.map(r => `(${r})`).join("|"), "gum");
  8478. if (hasSyllables) {
  8479. withSyllablesRegExp = normalizationRegex;
  8480. } else {
  8481. noSyllablesRegExp = normalizationRegex;
  8482. }
  8483. }
  8484. const rawDiacriticsPositions = [];
  8485. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  8486. rawDiacriticsPositions.push([m[0].length, m.index]);
  8487. }
  8488. let normalized = text.normalize("NFD");
  8489. const positions = [0, 0];
  8490. let rawDiacriticsIndex = 0;
  8491. let syllableIndex = 0;
  8492. let shift = 0;
  8493. let shiftOrigin = 0;
  8494. let eol = 0;
  8495. let hasDiacritics = false;
  8496. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, p8, p9, i) => {
  8497. i -= shiftOrigin;
  8498. if (p1) {
  8499. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  8500. const jj = replacement.length;
  8501. for (let j = 1; j < jj; j++) {
  8502. positions.push(i - shift + j, shift - j);
  8503. }
  8504. shift -= jj - 1;
  8505. return replacement;
  8506. }
  8507. if (p2) {
  8508. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  8509. if (!replacement) {
  8510. replacement = p2.normalize("NFKC");
  8511. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  8512. }
  8513. const jj = replacement.length;
  8514. for (let j = 1; j < jj; j++) {
  8515. positions.push(i - shift + j, shift - j);
  8516. }
  8517. shift -= jj - 1;
  8518. return replacement;
  8519. }
  8520. if (p3) {
  8521. hasDiacritics = true;
  8522. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  8523. ++rawDiacriticsIndex;
  8524. } else {
  8525. positions.push(i - 1 - shift + 1, shift - 1);
  8526. shift -= 1;
  8527. shiftOrigin += 1;
  8528. }
  8529. positions.push(i - shift + 1, shift);
  8530. shiftOrigin += 1;
  8531. eol += 1;
  8532. return p3.charAt(0);
  8533. }
  8534. if (p4) {
  8535. const hasTrailingDashEOL = p4.endsWith("\n");
  8536. const len = hasTrailingDashEOL ? p4.length - 2 : p4.length;
  8537. hasDiacritics = true;
  8538. let jj = len;
  8539. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  8540. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  8541. ++rawDiacriticsIndex;
  8542. }
  8543. for (let j = 1; j <= jj; j++) {
  8544. positions.push(i - 1 - shift + j, shift - j);
  8545. }
  8546. shift -= jj;
  8547. shiftOrigin += jj;
  8548. if (hasTrailingDashEOL) {
  8549. i += len - 1;
  8550. positions.push(i - shift + 1, 1 + shift);
  8551. shift += 1;
  8552. shiftOrigin += 1;
  8553. eol += 1;
  8554. return p4.slice(0, len);
  8555. }
  8556. return p4;
  8557. }
  8558. if (p5) {
  8559. const len = p5.length - 2;
  8560. positions.push(i - shift + len, 1 + shift);
  8561. shift += 1;
  8562. shiftOrigin += 1;
  8563. eol += 1;
  8564. return p5.slice(0, -2);
  8565. }
  8566. if (p6) {
  8567. shiftOrigin += 1;
  8568. eol += 1;
  8569. return p6.slice(0, -1);
  8570. }
  8571. if (p7) {
  8572. const len = p7.length - 1;
  8573. positions.push(i - shift + len, shift);
  8574. shiftOrigin += 1;
  8575. eol += 1;
  8576. return p7.slice(0, -1);
  8577. }
  8578. if (p8) {
  8579. positions.push(i - shift + 1, shift - 1);
  8580. shift -= 1;
  8581. shiftOrigin += 1;
  8582. eol += 1;
  8583. return " ";
  8584. }
  8585. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  8586. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  8587. ++syllableIndex;
  8588. for (let j = 1; j <= newCharLen; j++) {
  8589. positions.push(i - (shift - j), shift - j);
  8590. }
  8591. shift -= newCharLen;
  8592. shiftOrigin += newCharLen;
  8593. }
  8594. return p9;
  8595. });
  8596. positions.push(normalized.length, shift);
  8597. const starts = new Uint32Array(positions.length >> 1);
  8598. const shifts = new Int32Array(positions.length >> 1);
  8599. for (let i = 0, ii = positions.length; i < ii; i += 2) {
  8600. starts[i >> 1] = positions[i];
  8601. shifts[i >> 1] = positions[i + 1];
  8602. }
  8603. return [normalized, [starts, shifts], hasDiacritics];
  8604. }
  8605. function getOriginalIndex(diffs, pos, len) {
  8606. if (!diffs) {
  8607. return [pos, len];
  8608. }
  8609. const [starts, shifts] = diffs;
  8610. const start = pos;
  8611. const end = pos + len - 1;
  8612. let i = binarySearchFirstItem(starts, x => x >= start);
  8613. if (starts[i] > start) {
  8614. --i;
  8615. }
  8616. let j = binarySearchFirstItem(starts, x => x >= end, i);
  8617. if (starts[j] > end) {
  8618. --j;
  8619. }
  8620. const oldStart = start + shifts[i];
  8621. const oldEnd = end + shifts[j];
  8622. const oldLen = oldEnd + 1 - oldStart;
  8623. return [oldStart, oldLen];
  8624. }
  8625. class PDFFindController {
  8626. #state = null;
  8627. #updateMatchesCountOnProgress = true;
  8628. #visitedPagesCount = 0;
  8629. constructor({
  8630. linkService,
  8631. eventBus,
  8632. updateMatchesCountOnProgress = true
  8633. }) {
  8634. this._linkService = linkService;
  8635. this._eventBus = eventBus;
  8636. this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
  8637. this.onIsPageVisible = null;
  8638. this.#reset();
  8639. eventBus._on("find", this.#onFind.bind(this));
  8640. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  8641. }
  8642. get highlightMatches() {
  8643. return this._highlightMatches;
  8644. }
  8645. get pageMatches() {
  8646. return this._pageMatches;
  8647. }
  8648. get pageMatchesLength() {
  8649. return this._pageMatchesLength;
  8650. }
  8651. get selected() {
  8652. return this._selected;
  8653. }
  8654. get state() {
  8655. return this.#state;
  8656. }
  8657. setDocument(pdfDocument) {
  8658. if (this._pdfDocument) {
  8659. this.#reset();
  8660. }
  8661. if (!pdfDocument) {
  8662. return;
  8663. }
  8664. this._pdfDocument = pdfDocument;
  8665. this._firstPageCapability.resolve();
  8666. }
  8667. #onFind(state) {
  8668. if (!state) {
  8669. return;
  8670. }
  8671. const pdfDocument = this._pdfDocument;
  8672. const {
  8673. type
  8674. } = state;
  8675. if (this.#state === null || this.#shouldDirtyMatch(state)) {
  8676. this._dirtyMatch = true;
  8677. }
  8678. this.#state = state;
  8679. if (type !== "highlightallchange") {
  8680. this.#updateUIState(FindState.PENDING);
  8681. }
  8682. this._firstPageCapability.promise.then(() => {
  8683. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  8684. return;
  8685. }
  8686. this.#extractText();
  8687. const findbarClosed = !this._highlightMatches;
  8688. const pendingTimeout = !!this._findTimeout;
  8689. if (this._findTimeout) {
  8690. clearTimeout(this._findTimeout);
  8691. this._findTimeout = null;
  8692. }
  8693. if (!type) {
  8694. this._findTimeout = setTimeout(() => {
  8695. this.#nextMatch();
  8696. this._findTimeout = null;
  8697. }, FIND_TIMEOUT);
  8698. } else if (this._dirtyMatch) {
  8699. this.#nextMatch();
  8700. } else if (type === "again") {
  8701. this.#nextMatch();
  8702. if (findbarClosed && this.#state.highlightAll) {
  8703. this.#updateAllPages();
  8704. }
  8705. } else if (type === "highlightallchange") {
  8706. if (pendingTimeout) {
  8707. this.#nextMatch();
  8708. } else {
  8709. this._highlightMatches = true;
  8710. }
  8711. this.#updateAllPages();
  8712. } else {
  8713. this.#nextMatch();
  8714. }
  8715. });
  8716. }
  8717. scrollMatchIntoView({
  8718. element = null,
  8719. selectedLeft = 0,
  8720. pageIndex = -1,
  8721. matchIndex = -1
  8722. }) {
  8723. if (!this._scrollMatches || !element) {
  8724. return;
  8725. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  8726. return;
  8727. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  8728. return;
  8729. }
  8730. this._scrollMatches = false;
  8731. const spot = {
  8732. top: MATCH_SCROLL_OFFSET_TOP,
  8733. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  8734. };
  8735. scrollIntoView(element, spot, true);
  8736. }
  8737. #reset() {
  8738. this._highlightMatches = false;
  8739. this._scrollMatches = false;
  8740. this._pdfDocument = null;
  8741. this._pageMatches = [];
  8742. this._pageMatchesLength = [];
  8743. this.#visitedPagesCount = 0;
  8744. this.#state = null;
  8745. this._selected = {
  8746. pageIdx: -1,
  8747. matchIdx: -1
  8748. };
  8749. this._offset = {
  8750. pageIdx: null,
  8751. matchIdx: null,
  8752. wrapped: false
  8753. };
  8754. this._extractTextPromises = [];
  8755. this._pageContents = [];
  8756. this._pageDiffs = [];
  8757. this._hasDiacritics = [];
  8758. this._matchesCountTotal = 0;
  8759. this._pagesToSearch = null;
  8760. this._pendingFindMatches = new Set();
  8761. this._resumePageIdx = null;
  8762. this._dirtyMatch = false;
  8763. clearTimeout(this._findTimeout);
  8764. this._findTimeout = null;
  8765. this._firstPageCapability = Promise.withResolvers();
  8766. }
  8767. get #query() {
  8768. const {
  8769. query
  8770. } = this.#state;
  8771. if (typeof query === "string") {
  8772. if (query !== this._rawQuery) {
  8773. this._rawQuery = query;
  8774. [this._normalizedQuery] = normalize(query);
  8775. }
  8776. return this._normalizedQuery;
  8777. }
  8778. return (query || []).filter(q => !!q).map(q => normalize(q)[0]);
  8779. }
  8780. #shouldDirtyMatch(state) {
  8781. const newQuery = state.query,
  8782. prevQuery = this.#state.query;
  8783. const newType = typeof newQuery,
  8784. prevType = typeof prevQuery;
  8785. if (newType !== prevType) {
  8786. return true;
  8787. }
  8788. if (newType === "string") {
  8789. if (newQuery !== prevQuery) {
  8790. return true;
  8791. }
  8792. } else if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) {
  8793. return true;
  8794. }
  8795. switch (state.type) {
  8796. case "again":
  8797. const pageNumber = this._selected.pageIdx + 1;
  8798. const linkService = this._linkService;
  8799. return pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !(this.onIsPageVisible?.(pageNumber) ?? true);
  8800. case "highlightallchange":
  8801. return false;
  8802. }
  8803. return true;
  8804. }
  8805. #isEntireWord(content, startIdx, length) {
  8806. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  8807. if (match) {
  8808. const first = content.charCodeAt(startIdx);
  8809. const limit = match[1].charCodeAt(0);
  8810. if (getCharacterType(first) === getCharacterType(limit)) {
  8811. return false;
  8812. }
  8813. }
  8814. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  8815. if (match) {
  8816. const last = content.charCodeAt(startIdx + length - 1);
  8817. const limit = match[1].charCodeAt(0);
  8818. if (getCharacterType(last) === getCharacterType(limit)) {
  8819. return false;
  8820. }
  8821. }
  8822. return true;
  8823. }
  8824. #convertToRegExpString(query, hasDiacritics) {
  8825. const {
  8826. matchDiacritics
  8827. } = this.#state;
  8828. let isUnicode = false;
  8829. query = query.replaceAll(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  8830. if (p1) {
  8831. return `[ ]*\\${p1}[ ]*`;
  8832. }
  8833. if (p2) {
  8834. return `[ ]*${p2}[ ]*`;
  8835. }
  8836. if (p3) {
  8837. return "[ ]+";
  8838. }
  8839. if (matchDiacritics) {
  8840. return p4 || p5;
  8841. }
  8842. if (p4) {
  8843. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  8844. }
  8845. if (hasDiacritics) {
  8846. isUnicode = true;
  8847. return `${p5}\\p{M}*`;
  8848. }
  8849. return p5;
  8850. });
  8851. const trailingSpaces = "[ ]*";
  8852. if (query.endsWith(trailingSpaces)) {
  8853. query = query.slice(0, query.length - trailingSpaces.length);
  8854. }
  8855. if (matchDiacritics) {
  8856. if (hasDiacritics) {
  8857. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
  8858. isUnicode = true;
  8859. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  8860. }
  8861. }
  8862. return [isUnicode, query];
  8863. }
  8864. #calculateMatch(pageIndex) {
  8865. if (!this.#state) {
  8866. return;
  8867. }
  8868. const query = this.#query;
  8869. if (query.length === 0) {
  8870. return;
  8871. }
  8872. const pageContent = this._pageContents[pageIndex];
  8873. const matcherResult = this.match(query, pageContent, pageIndex);
  8874. const matches = this._pageMatches[pageIndex] = [];
  8875. const matchesLength = this._pageMatchesLength[pageIndex] = [];
  8876. const diffs = this._pageDiffs[pageIndex];
  8877. matcherResult?.forEach(({
  8878. index,
  8879. length
  8880. }) => {
  8881. const [matchPos, matchLen] = getOriginalIndex(diffs, index, length);
  8882. if (matchLen) {
  8883. matches.push(matchPos);
  8884. matchesLength.push(matchLen);
  8885. }
  8886. });
  8887. if (this.#state.highlightAll) {
  8888. this.#updatePage(pageIndex);
  8889. }
  8890. if (this._resumePageIdx === pageIndex) {
  8891. this._resumePageIdx = null;
  8892. this.#nextPageMatch();
  8893. }
  8894. const pageMatchesCount = matches.length;
  8895. this._matchesCountTotal += pageMatchesCount;
  8896. if (this.#updateMatchesCountOnProgress) {
  8897. if (pageMatchesCount > 0) {
  8898. this.#updateUIResultsCount();
  8899. }
  8900. } else if (++this.#visitedPagesCount === this._linkService.pagesCount) {
  8901. this.#updateUIResultsCount();
  8902. }
  8903. }
  8904. match(query, pageContent, pageIndex) {
  8905. const hasDiacritics = this._hasDiacritics[pageIndex];
  8906. let isUnicode = false;
  8907. if (typeof query === "string") {
  8908. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  8909. } else {
  8910. query = query.sort().reverse().map(q => {
  8911. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  8912. isUnicode ||= isUnicodePart;
  8913. return `(${queryPart})`;
  8914. }).join("|");
  8915. }
  8916. if (!query) {
  8917. return undefined;
  8918. }
  8919. const {
  8920. caseSensitive,
  8921. entireWord
  8922. } = this.#state;
  8923. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  8924. query = new RegExp(query, flags);
  8925. const matches = [];
  8926. let match;
  8927. while ((match = query.exec(pageContent)) !== null) {
  8928. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  8929. continue;
  8930. }
  8931. matches.push({
  8932. index: match.index,
  8933. length: match[0].length
  8934. });
  8935. }
  8936. return matches;
  8937. }
  8938. #extractText() {
  8939. if (this._extractTextPromises.length > 0) {
  8940. return;
  8941. }
  8942. let deferred = Promise.resolve();
  8943. const textOptions = {
  8944. disableNormalization: true
  8945. };
  8946. const pdfDoc = this._pdfDocument;
  8947. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  8948. const {
  8949. promise,
  8950. resolve
  8951. } = Promise.withResolvers();
  8952. this._extractTextPromises[i] = promise;
  8953. deferred = deferred.then(async () => {
  8954. if (pdfDoc !== this._pdfDocument) {
  8955. resolve();
  8956. return;
  8957. }
  8958. await pdfDoc.getPage(i + 1).then(pdfPage => pdfPage.getTextContent(textOptions)).then(textContent => {
  8959. const strBuf = [];
  8960. for (const textItem of textContent.items) {
  8961. strBuf.push(textItem.str);
  8962. if (textItem.hasEOL) {
  8963. strBuf.push("\n");
  8964. }
  8965. }
  8966. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  8967. resolve();
  8968. }, reason => {
  8969. console.error(`Unable to get text content for page ${i + 1}`, reason);
  8970. this._pageContents[i] = "";
  8971. this._pageDiffs[i] = null;
  8972. this._hasDiacritics[i] = false;
  8973. resolve();
  8974. });
  8975. });
  8976. }
  8977. }
  8978. #updatePage(index) {
  8979. if (this._scrollMatches && this._selected.pageIdx === index) {
  8980. this._linkService.page = index + 1;
  8981. }
  8982. this._eventBus.dispatch("updatetextlayermatches", {
  8983. source: this,
  8984. pageIndex: index
  8985. });
  8986. }
  8987. #updateAllPages() {
  8988. this._eventBus.dispatch("updatetextlayermatches", {
  8989. source: this,
  8990. pageIndex: -1
  8991. });
  8992. }
  8993. #nextMatch() {
  8994. const previous = this.#state.findPrevious;
  8995. const currentPageIndex = this._linkService.page - 1;
  8996. const numPages = this._linkService.pagesCount;
  8997. this._highlightMatches = true;
  8998. if (this._dirtyMatch) {
  8999. this._dirtyMatch = false;
  9000. this._selected.pageIdx = this._selected.matchIdx = -1;
  9001. this._offset.pageIdx = currentPageIndex;
  9002. this._offset.matchIdx = null;
  9003. this._offset.wrapped = false;
  9004. this._resumePageIdx = null;
  9005. this._pageMatches.length = 0;
  9006. this._pageMatchesLength.length = 0;
  9007. this.#visitedPagesCount = 0;
  9008. this._matchesCountTotal = 0;
  9009. this.#updateAllPages();
  9010. for (let i = 0; i < numPages; i++) {
  9011. if (this._pendingFindMatches.has(i)) {
  9012. continue;
  9013. }
  9014. this._pendingFindMatches.add(i);
  9015. this._extractTextPromises[i].then(() => {
  9016. this._pendingFindMatches.delete(i);
  9017. this.#calculateMatch(i);
  9018. });
  9019. }
  9020. }
  9021. const query = this.#query;
  9022. if (query.length === 0) {
  9023. this.#updateUIState(FindState.FOUND);
  9024. return;
  9025. }
  9026. if (this._resumePageIdx) {
  9027. return;
  9028. }
  9029. const offset = this._offset;
  9030. this._pagesToSearch = numPages;
  9031. if (offset.matchIdx !== null) {
  9032. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  9033. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  9034. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  9035. this.#updateMatch(true);
  9036. return;
  9037. }
  9038. this.#advanceOffsetPage(previous);
  9039. }
  9040. this.#nextPageMatch();
  9041. }
  9042. #matchesReady(matches) {
  9043. const offset = this._offset;
  9044. const numMatches = matches.length;
  9045. const previous = this.#state.findPrevious;
  9046. if (numMatches) {
  9047. offset.matchIdx = previous ? numMatches - 1 : 0;
  9048. this.#updateMatch(true);
  9049. return true;
  9050. }
  9051. this.#advanceOffsetPage(previous);
  9052. if (offset.wrapped) {
  9053. offset.matchIdx = null;
  9054. if (this._pagesToSearch < 0) {
  9055. this.#updateMatch(false);
  9056. return true;
  9057. }
  9058. }
  9059. return false;
  9060. }
  9061. #nextPageMatch() {
  9062. if (this._resumePageIdx !== null) {
  9063. console.error("There can only be one pending page.");
  9064. }
  9065. let matches = null;
  9066. do {
  9067. const pageIdx = this._offset.pageIdx;
  9068. matches = this._pageMatches[pageIdx];
  9069. if (!matches) {
  9070. this._resumePageIdx = pageIdx;
  9071. break;
  9072. }
  9073. } while (!this.#matchesReady(matches));
  9074. }
  9075. #advanceOffsetPage(previous) {
  9076. const offset = this._offset;
  9077. const numPages = this._linkService.pagesCount;
  9078. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  9079. offset.matchIdx = null;
  9080. this._pagesToSearch--;
  9081. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  9082. offset.pageIdx = previous ? numPages - 1 : 0;
  9083. offset.wrapped = true;
  9084. }
  9085. }
  9086. #updateMatch(found = false) {
  9087. let state = FindState.NOT_FOUND;
  9088. const wrapped = this._offset.wrapped;
  9089. this._offset.wrapped = false;
  9090. if (found) {
  9091. const previousPage = this._selected.pageIdx;
  9092. this._selected.pageIdx = this._offset.pageIdx;
  9093. this._selected.matchIdx = this._offset.matchIdx;
  9094. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  9095. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  9096. this.#updatePage(previousPage);
  9097. }
  9098. }
  9099. this.#updateUIState(state, this.#state.findPrevious);
  9100. if (this._selected.pageIdx !== -1) {
  9101. this._scrollMatches = true;
  9102. this.#updatePage(this._selected.pageIdx);
  9103. }
  9104. }
  9105. #onFindBarClose(evt) {
  9106. const pdfDocument = this._pdfDocument;
  9107. this._firstPageCapability.promise.then(() => {
  9108. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  9109. return;
  9110. }
  9111. if (this._findTimeout) {
  9112. clearTimeout(this._findTimeout);
  9113. this._findTimeout = null;
  9114. }
  9115. if (this._resumePageIdx) {
  9116. this._resumePageIdx = null;
  9117. this._dirtyMatch = true;
  9118. }
  9119. this.#updateUIState(FindState.FOUND);
  9120. this._highlightMatches = false;
  9121. this.#updateAllPages();
  9122. });
  9123. }
  9124. #requestMatchesCount() {
  9125. const {
  9126. pageIdx,
  9127. matchIdx
  9128. } = this._selected;
  9129. let current = 0,
  9130. total = this._matchesCountTotal;
  9131. if (matchIdx !== -1) {
  9132. for (let i = 0; i < pageIdx; i++) {
  9133. current += this._pageMatches[i]?.length || 0;
  9134. }
  9135. current += matchIdx + 1;
  9136. }
  9137. if (current < 1 || current > total) {
  9138. current = total = 0;
  9139. }
  9140. return {
  9141. current,
  9142. total
  9143. };
  9144. }
  9145. #updateUIResultsCount() {
  9146. this._eventBus.dispatch("updatefindmatchescount", {
  9147. source: this,
  9148. matchesCount: this.#requestMatchesCount()
  9149. });
  9150. }
  9151. #updateUIState(state, previous = false) {
  9152. if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) {
  9153. return;
  9154. }
  9155. this._eventBus.dispatch("updatefindcontrolstate", {
  9156. source: this,
  9157. state,
  9158. previous,
  9159. entireWord: this.#state?.entireWord ?? null,
  9160. matchesCount: this.#requestMatchesCount(),
  9161. rawQuery: this.#state?.query ?? null
  9162. });
  9163. }
  9164. }
  9165. ;// ./web/pdf_find_bar.js
  9166. const MATCHES_COUNT_LIMIT = 1000;
  9167. class PDFFindBar {
  9168. #mainContainer;
  9169. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  9170. constructor(options, mainContainer, eventBus) {
  9171. this.opened = false;
  9172. this.bar = options.bar;
  9173. this.toggleButton = options.toggleButton;
  9174. this.findField = options.findField;
  9175. this.highlightAll = options.highlightAllCheckbox;
  9176. this.caseSensitive = options.caseSensitiveCheckbox;
  9177. this.matchDiacritics = options.matchDiacriticsCheckbox;
  9178. this.entireWord = options.entireWordCheckbox;
  9179. this.findMsg = options.findMsg;
  9180. this.findResultsCount = options.findResultsCount;
  9181. this.findPreviousButton = options.findPreviousButton;
  9182. this.findNextButton = options.findNextButton;
  9183. this.eventBus = eventBus;
  9184. this.#mainContainer = mainContainer;
  9185. const checkedInputs = new Map([[this.highlightAll, "highlightallchange"], [this.caseSensitive, "casesensitivitychange"], [this.entireWord, "entirewordchange"], [this.matchDiacritics, "diacriticmatchingchange"]]);
  9186. this.toggleButton.addEventListener("click", () => {
  9187. this.toggle();
  9188. });
  9189. this.findField.addEventListener("input", () => {
  9190. this.dispatchEvent("");
  9191. });
  9192. this.bar.addEventListener("keydown", ({
  9193. keyCode,
  9194. shiftKey,
  9195. target
  9196. }) => {
  9197. switch (keyCode) {
  9198. case 13:
  9199. if (target === this.findField) {
  9200. this.dispatchEvent("again", shiftKey);
  9201. } else if (checkedInputs.has(target)) {
  9202. target.checked = !target.checked;
  9203. this.dispatchEvent(checkedInputs.get(target));
  9204. }
  9205. break;
  9206. case 27:
  9207. this.close();
  9208. break;
  9209. }
  9210. });
  9211. this.findPreviousButton.addEventListener("click", () => {
  9212. this.dispatchEvent("again", true);
  9213. });
  9214. this.findNextButton.addEventListener("click", () => {
  9215. this.dispatchEvent("again", false);
  9216. });
  9217. for (const [elem, evtName] of checkedInputs) {
  9218. elem.addEventListener("click", () => {
  9219. this.dispatchEvent(evtName);
  9220. });
  9221. }
  9222. }
  9223. reset() {
  9224. this.updateUIState();
  9225. }
  9226. dispatchEvent(type, findPrev = false) {
  9227. this.eventBus.dispatch("find", {
  9228. source: this,
  9229. type,
  9230. query: this.findField.value,
  9231. caseSensitive: this.caseSensitive.checked,
  9232. entireWord: this.entireWord.checked,
  9233. highlightAll: this.highlightAll.checked,
  9234. findPrevious: findPrev,
  9235. matchDiacritics: this.matchDiacritics.checked
  9236. });
  9237. }
  9238. updateUIState(state, previous, matchesCount) {
  9239. const {
  9240. findField,
  9241. findMsg
  9242. } = this;
  9243. let findMsgId = "",
  9244. status = "";
  9245. switch (state) {
  9246. case FindState.FOUND:
  9247. break;
  9248. case FindState.PENDING:
  9249. status = "pending";
  9250. break;
  9251. case FindState.NOT_FOUND:
  9252. findMsgId = "pdfjs-find-not-found";
  9253. status = "notFound";
  9254. break;
  9255. case FindState.WRAPPED:
  9256. findMsgId = previous ? "pdfjs-find-reached-top" : "pdfjs-find-reached-bottom";
  9257. break;
  9258. }
  9259. findField.setAttribute("data-status", status);
  9260. findField.setAttribute("aria-invalid", state === FindState.NOT_FOUND);
  9261. findMsg.setAttribute("data-status", status);
  9262. if (findMsgId) {
  9263. findMsg.setAttribute("data-l10n-id", findMsgId);
  9264. } else {
  9265. findMsg.removeAttribute("data-l10n-id");
  9266. findMsg.textContent = "";
  9267. }
  9268. this.updateResultsCount(matchesCount);
  9269. }
  9270. updateResultsCount({
  9271. current = 0,
  9272. total = 0
  9273. } = {}) {
  9274. const {
  9275. findResultsCount
  9276. } = this;
  9277. if (total > 0) {
  9278. const limit = MATCHES_COUNT_LIMIT;
  9279. findResultsCount.setAttribute("data-l10n-id", total > limit ? "pdfjs-find-match-count-limit" : "pdfjs-find-match-count");
  9280. findResultsCount.setAttribute("data-l10n-args", JSON.stringify({
  9281. limit,
  9282. current,
  9283. total
  9284. }));
  9285. } else {
  9286. findResultsCount.removeAttribute("data-l10n-id");
  9287. findResultsCount.textContent = "";
  9288. }
  9289. }
  9290. open() {
  9291. if (!this.opened) {
  9292. this.#resizeObserver.observe(this.#mainContainer);
  9293. this.#resizeObserver.observe(this.bar);
  9294. this.opened = true;
  9295. toggleExpandedBtn(this.toggleButton, true, this.bar);
  9296. }
  9297. this.findField.select();
  9298. this.findField.focus();
  9299. }
  9300. close() {
  9301. if (!this.opened) {
  9302. return;
  9303. }
  9304. this.#resizeObserver.disconnect();
  9305. this.opened = false;
  9306. toggleExpandedBtn(this.toggleButton, false, this.bar);
  9307. this.eventBus.dispatch("findbarclose", {
  9308. source: this
  9309. });
  9310. }
  9311. toggle() {
  9312. if (this.opened) {
  9313. this.close();
  9314. } else {
  9315. this.open();
  9316. }
  9317. }
  9318. #resizeObserverCallback() {
  9319. const {
  9320. bar
  9321. } = this;
  9322. bar.classList.remove("wrapContainers");
  9323. const findbarHeight = bar.clientHeight;
  9324. const inputContainerHeight = bar.firstElementChild.clientHeight;
  9325. if (findbarHeight > inputContainerHeight) {
  9326. bar.classList.add("wrapContainers");
  9327. }
  9328. }
  9329. }
  9330. ;// ./web/pdf_history.js
  9331. const HASH_CHANGE_TIMEOUT = 1000;
  9332. const POSITION_UPDATED_THRESHOLD = 50;
  9333. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  9334. function getCurrentHash() {
  9335. return document.location.hash;
  9336. }
  9337. class PDFHistory {
  9338. #eventAbortController = null;
  9339. constructor({
  9340. linkService,
  9341. eventBus
  9342. }) {
  9343. this.linkService = linkService;
  9344. this.eventBus = eventBus;
  9345. this._initialized = false;
  9346. this._fingerprint = "";
  9347. this.reset();
  9348. this.eventBus._on("pagesinit", () => {
  9349. this._isPagesLoaded = false;
  9350. this.eventBus._on("pagesloaded", evt => {
  9351. this._isPagesLoaded = !!evt.pagesCount;
  9352. }, {
  9353. once: true
  9354. });
  9355. });
  9356. }
  9357. initialize({
  9358. fingerprint,
  9359. resetHistory = false,
  9360. updateUrl = false
  9361. }) {
  9362. if (!fingerprint || typeof fingerprint !== "string") {
  9363. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  9364. return;
  9365. }
  9366. if (this._initialized) {
  9367. this.reset();
  9368. }
  9369. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  9370. this._fingerprint = fingerprint;
  9371. this._updateUrl = updateUrl === true;
  9372. this._initialized = true;
  9373. this.#bindEvents();
  9374. const state = window.history.state;
  9375. this._popStateInProgress = false;
  9376. this._blockHashChange = 0;
  9377. this._currentHash = getCurrentHash();
  9378. this._numPositionUpdates = 0;
  9379. this._uid = this._maxUid = 0;
  9380. this._destination = null;
  9381. this._position = null;
  9382. if (!this.#isValidState(state, true) || resetHistory) {
  9383. const {
  9384. hash,
  9385. page,
  9386. rotation
  9387. } = this.#parseCurrentHash(true);
  9388. if (!hash || reInitialized || resetHistory) {
  9389. this.#pushOrReplaceState(null, true);
  9390. return;
  9391. }
  9392. this.#pushOrReplaceState({
  9393. hash,
  9394. page,
  9395. rotation
  9396. }, true);
  9397. return;
  9398. }
  9399. const destination = state.destination;
  9400. this.#updateInternalState(destination, state.uid, true);
  9401. if (destination.rotation !== undefined) {
  9402. this._initialRotation = destination.rotation;
  9403. }
  9404. if (destination.dest) {
  9405. this._initialBookmark = JSON.stringify(destination.dest);
  9406. this._destination.page = null;
  9407. } else if (destination.hash) {
  9408. this._initialBookmark = destination.hash;
  9409. } else if (destination.page) {
  9410. this._initialBookmark = `page=${destination.page}`;
  9411. }
  9412. }
  9413. reset() {
  9414. if (this._initialized) {
  9415. this.#pageHide();
  9416. this._initialized = false;
  9417. this.#unbindEvents();
  9418. }
  9419. if (this._updateViewareaTimeout) {
  9420. clearTimeout(this._updateViewareaTimeout);
  9421. this._updateViewareaTimeout = null;
  9422. }
  9423. this._initialBookmark = null;
  9424. this._initialRotation = null;
  9425. }
  9426. push({
  9427. namedDest = null,
  9428. explicitDest,
  9429. pageNumber
  9430. }) {
  9431. if (!this._initialized) {
  9432. return;
  9433. }
  9434. if (namedDest && typeof namedDest !== "string") {
  9435. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  9436. return;
  9437. } else if (!Array.isArray(explicitDest)) {
  9438. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  9439. return;
  9440. } else if (!this.#isValidPage(pageNumber)) {
  9441. if (pageNumber !== null || this._destination) {
  9442. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  9443. return;
  9444. }
  9445. }
  9446. const hash = namedDest || JSON.stringify(explicitDest);
  9447. if (!hash) {
  9448. return;
  9449. }
  9450. let forceReplace = false;
  9451. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  9452. if (this._destination.page) {
  9453. return;
  9454. }
  9455. forceReplace = true;
  9456. }
  9457. if (this._popStateInProgress && !forceReplace) {
  9458. return;
  9459. }
  9460. this.#pushOrReplaceState({
  9461. dest: explicitDest,
  9462. hash,
  9463. page: pageNumber,
  9464. rotation: this.linkService.rotation
  9465. }, forceReplace);
  9466. if (!this._popStateInProgress) {
  9467. this._popStateInProgress = true;
  9468. Promise.resolve().then(() => {
  9469. this._popStateInProgress = false;
  9470. });
  9471. }
  9472. }
  9473. pushPage(pageNumber) {
  9474. if (!this._initialized) {
  9475. return;
  9476. }
  9477. if (!this.#isValidPage(pageNumber)) {
  9478. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  9479. return;
  9480. }
  9481. if (this._destination?.page === pageNumber) {
  9482. return;
  9483. }
  9484. if (this._popStateInProgress) {
  9485. return;
  9486. }
  9487. this.#pushOrReplaceState({
  9488. dest: null,
  9489. hash: `page=${pageNumber}`,
  9490. page: pageNumber,
  9491. rotation: this.linkService.rotation
  9492. });
  9493. if (!this._popStateInProgress) {
  9494. this._popStateInProgress = true;
  9495. Promise.resolve().then(() => {
  9496. this._popStateInProgress = false;
  9497. });
  9498. }
  9499. }
  9500. pushCurrentPosition() {
  9501. if (!this._initialized || this._popStateInProgress) {
  9502. return;
  9503. }
  9504. this.#tryPushCurrentPosition();
  9505. }
  9506. back() {
  9507. if (!this._initialized || this._popStateInProgress) {
  9508. return;
  9509. }
  9510. const state = window.history.state;
  9511. if (this.#isValidState(state) && state.uid > 0) {
  9512. window.history.back();
  9513. }
  9514. }
  9515. forward() {
  9516. if (!this._initialized || this._popStateInProgress) {
  9517. return;
  9518. }
  9519. const state = window.history.state;
  9520. if (this.#isValidState(state) && state.uid < this._maxUid) {
  9521. window.history.forward();
  9522. }
  9523. }
  9524. get popStateInProgress() {
  9525. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  9526. }
  9527. get initialBookmark() {
  9528. return this._initialized ? this._initialBookmark : null;
  9529. }
  9530. get initialRotation() {
  9531. return this._initialized ? this._initialRotation : null;
  9532. }
  9533. #pushOrReplaceState(destination, forceReplace = false) {
  9534. const shouldReplace = forceReplace || !this._destination;
  9535. const newState = {
  9536. fingerprint: this._fingerprint,
  9537. uid: shouldReplace ? this._uid : this._uid + 1,
  9538. destination
  9539. };
  9540. this.#updateInternalState(destination, newState.uid);
  9541. let newUrl;
  9542. if (this._updateUrl && destination?.hash) {
  9543. const {
  9544. href,
  9545. protocol
  9546. } = document.location;
  9547. if (protocol !== "file:") {
  9548. newUrl = updateUrlHash(href, destination.hash);
  9549. }
  9550. }
  9551. if (shouldReplace) {
  9552. window.history.replaceState(newState, "", newUrl);
  9553. } else {
  9554. window.history.pushState(newState, "", newUrl);
  9555. }
  9556. }
  9557. #tryPushCurrentPosition(temporary = false) {
  9558. if (!this._position) {
  9559. return;
  9560. }
  9561. let position = this._position;
  9562. if (temporary) {
  9563. position = Object.assign(Object.create(null), this._position);
  9564. position.temporary = true;
  9565. }
  9566. if (!this._destination) {
  9567. this.#pushOrReplaceState(position);
  9568. return;
  9569. }
  9570. if (this._destination.temporary) {
  9571. this.#pushOrReplaceState(position, true);
  9572. return;
  9573. }
  9574. if (this._destination.hash === position.hash) {
  9575. return;
  9576. }
  9577. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  9578. return;
  9579. }
  9580. let forceReplace = false;
  9581. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  9582. if (this._destination.dest !== undefined || !this._destination.first) {
  9583. return;
  9584. }
  9585. forceReplace = true;
  9586. }
  9587. this.#pushOrReplaceState(position, forceReplace);
  9588. }
  9589. #isValidPage(val) {
  9590. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  9591. }
  9592. #isValidState(state, checkReload = false) {
  9593. if (!state) {
  9594. return false;
  9595. }
  9596. if (state.fingerprint !== this._fingerprint) {
  9597. if (checkReload) {
  9598. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  9599. return false;
  9600. }
  9601. const [perfEntry] = performance.getEntriesByType("navigation");
  9602. if (perfEntry?.type !== "reload") {
  9603. return false;
  9604. }
  9605. } else {
  9606. return false;
  9607. }
  9608. }
  9609. if (!Number.isInteger(state.uid) || state.uid < 0) {
  9610. return false;
  9611. }
  9612. if (state.destination === null || typeof state.destination !== "object") {
  9613. return false;
  9614. }
  9615. return true;
  9616. }
  9617. #updateInternalState(destination, uid, removeTemporary = false) {
  9618. if (this._updateViewareaTimeout) {
  9619. clearTimeout(this._updateViewareaTimeout);
  9620. this._updateViewareaTimeout = null;
  9621. }
  9622. if (removeTemporary && destination?.temporary) {
  9623. delete destination.temporary;
  9624. }
  9625. this._destination = destination;
  9626. this._uid = uid;
  9627. this._maxUid = Math.max(this._maxUid, uid);
  9628. this._numPositionUpdates = 0;
  9629. }
  9630. #parseCurrentHash(checkNameddest = false) {
  9631. const hash = unescape(getCurrentHash()).substring(1);
  9632. const params = parseQueryString(hash);
  9633. const nameddest = params.get("nameddest") || "";
  9634. let page = params.get("page") | 0;
  9635. if (!this.#isValidPage(page) || checkNameddest && nameddest.length > 0) {
  9636. page = null;
  9637. }
  9638. return {
  9639. hash,
  9640. page,
  9641. rotation: this.linkService.rotation
  9642. };
  9643. }
  9644. #updateViewarea({
  9645. location
  9646. }) {
  9647. if (this._updateViewareaTimeout) {
  9648. clearTimeout(this._updateViewareaTimeout);
  9649. this._updateViewareaTimeout = null;
  9650. }
  9651. this._position = {
  9652. hash: location.pdfOpenParams.substring(1),
  9653. page: this.linkService.page,
  9654. first: location.pageNumber,
  9655. rotation: location.rotation
  9656. };
  9657. if (this._popStateInProgress) {
  9658. return;
  9659. }
  9660. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  9661. this._numPositionUpdates++;
  9662. }
  9663. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  9664. this._updateViewareaTimeout = setTimeout(() => {
  9665. if (!this._popStateInProgress) {
  9666. this.#tryPushCurrentPosition(true);
  9667. }
  9668. this._updateViewareaTimeout = null;
  9669. }, UPDATE_VIEWAREA_TIMEOUT);
  9670. }
  9671. }
  9672. #popState({
  9673. state
  9674. }) {
  9675. const newHash = getCurrentHash(),
  9676. hashChanged = this._currentHash !== newHash;
  9677. this._currentHash = newHash;
  9678. if (!state) {
  9679. this._uid++;
  9680. const {
  9681. hash,
  9682. page,
  9683. rotation
  9684. } = this.#parseCurrentHash();
  9685. this.#pushOrReplaceState({
  9686. hash,
  9687. page,
  9688. rotation
  9689. }, true);
  9690. return;
  9691. }
  9692. if (!this.#isValidState(state)) {
  9693. return;
  9694. }
  9695. this._popStateInProgress = true;
  9696. if (hashChanged) {
  9697. this._blockHashChange++;
  9698. waitOnEventOrTimeout({
  9699. target: window,
  9700. name: "hashchange",
  9701. delay: HASH_CHANGE_TIMEOUT
  9702. }).then(() => {
  9703. this._blockHashChange--;
  9704. });
  9705. }
  9706. const destination = state.destination;
  9707. this.#updateInternalState(destination, state.uid, true);
  9708. if (isValidRotation(destination.rotation)) {
  9709. this.linkService.rotation = destination.rotation;
  9710. }
  9711. if (destination.dest) {
  9712. this.linkService.goToDestination(destination.dest);
  9713. } else if (destination.hash) {
  9714. this.linkService.setHash(destination.hash);
  9715. } else if (destination.page) {
  9716. this.linkService.page = destination.page;
  9717. }
  9718. Promise.resolve().then(() => {
  9719. this._popStateInProgress = false;
  9720. });
  9721. }
  9722. #pageHide() {
  9723. if (!this._destination || this._destination.temporary) {
  9724. this.#tryPushCurrentPosition();
  9725. }
  9726. }
  9727. #bindEvents() {
  9728. if (this.#eventAbortController) {
  9729. return;
  9730. }
  9731. this.#eventAbortController = new AbortController();
  9732. const {
  9733. signal
  9734. } = this.#eventAbortController;
  9735. this.eventBus._on("updateviewarea", this.#updateViewarea.bind(this), {
  9736. signal
  9737. });
  9738. window.addEventListener("popstate", this.#popState.bind(this), {
  9739. signal
  9740. });
  9741. window.addEventListener("pagehide", this.#pageHide.bind(this), {
  9742. signal
  9743. });
  9744. }
  9745. #unbindEvents() {
  9746. this.#eventAbortController?.abort();
  9747. this.#eventAbortController = null;
  9748. }
  9749. }
  9750. function isDestHashesEqual(destHash, pushHash) {
  9751. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  9752. return false;
  9753. }
  9754. if (destHash === pushHash) {
  9755. return true;
  9756. }
  9757. const nameddest = parseQueryString(destHash).get("nameddest");
  9758. if (nameddest === pushHash) {
  9759. return true;
  9760. }
  9761. return false;
  9762. }
  9763. function isDestArraysEqual(firstDest, secondDest) {
  9764. function isEntryEqual(first, second) {
  9765. if (typeof first !== typeof second) {
  9766. return false;
  9767. }
  9768. if (Array.isArray(first) || Array.isArray(second)) {
  9769. return false;
  9770. }
  9771. if (first !== null && typeof first === "object" && second !== null) {
  9772. if (Object.keys(first).length !== Object.keys(second).length) {
  9773. return false;
  9774. }
  9775. for (const key in first) {
  9776. if (!isEntryEqual(first[key], second[key])) {
  9777. return false;
  9778. }
  9779. }
  9780. return true;
  9781. }
  9782. return first === second || Number.isNaN(first) && Number.isNaN(second);
  9783. }
  9784. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  9785. return false;
  9786. }
  9787. if (firstDest.length !== secondDest.length) {
  9788. return false;
  9789. }
  9790. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  9791. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  9792. return false;
  9793. }
  9794. }
  9795. return true;
  9796. }
  9797. ;// ./web/pdf_layer_viewer.js
  9798. class PDFLayerViewer extends BaseTreeViewer {
  9799. constructor(options) {
  9800. super(options);
  9801. this.eventBus._on("optionalcontentconfigchanged", evt => {
  9802. this.#updateLayers(evt.promise);
  9803. });
  9804. this.eventBus._on("resetlayers", () => {
  9805. this.#updateLayers();
  9806. });
  9807. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  9808. }
  9809. reset() {
  9810. super.reset();
  9811. this._optionalContentConfig = null;
  9812. this._optionalContentVisibility?.clear();
  9813. this._optionalContentVisibility = null;
  9814. }
  9815. _dispatchEvent(layersCount) {
  9816. this.eventBus.dispatch("layersloaded", {
  9817. source: this,
  9818. layersCount
  9819. });
  9820. }
  9821. _bindLink(element, {
  9822. groupId,
  9823. input
  9824. }) {
  9825. const setVisibility = () => {
  9826. const visible = input.checked;
  9827. this._optionalContentConfig.setVisibility(groupId, visible);
  9828. const cached = this._optionalContentVisibility.get(groupId);
  9829. if (cached) {
  9830. cached.visible = visible;
  9831. }
  9832. this.eventBus.dispatch("optionalcontentconfig", {
  9833. source: this,
  9834. promise: Promise.resolve(this._optionalContentConfig)
  9835. });
  9836. };
  9837. element.onclick = evt => {
  9838. if (evt.target === input) {
  9839. setVisibility();
  9840. return true;
  9841. } else if (evt.target !== element) {
  9842. return true;
  9843. }
  9844. input.checked = !input.checked;
  9845. setVisibility();
  9846. return false;
  9847. };
  9848. }
  9849. _setNestedName(element, {
  9850. name = null
  9851. }) {
  9852. if (typeof name === "string") {
  9853. element.textContent = this._normalizeTextContent(name);
  9854. return;
  9855. }
  9856. element.setAttribute("data-l10n-id", "pdfjs-additional-layers");
  9857. element.style.fontStyle = "italic";
  9858. this._l10n.translateOnce(element);
  9859. }
  9860. _addToggleButton(div, {
  9861. name = null
  9862. }) {
  9863. super._addToggleButton(div, name === null);
  9864. }
  9865. _toggleAllTreeItems() {
  9866. if (!this._optionalContentConfig) {
  9867. return;
  9868. }
  9869. super._toggleAllTreeItems();
  9870. }
  9871. render({
  9872. optionalContentConfig,
  9873. pdfDocument
  9874. }) {
  9875. if (this._optionalContentConfig) {
  9876. this.reset();
  9877. }
  9878. this._optionalContentConfig = optionalContentConfig || null;
  9879. this._pdfDocument = pdfDocument || null;
  9880. const groups = optionalContentConfig?.getOrder();
  9881. if (!groups) {
  9882. this._dispatchEvent(0);
  9883. return;
  9884. }
  9885. this._optionalContentVisibility = new Map();
  9886. const fragment = document.createDocumentFragment(),
  9887. queue = [{
  9888. parent: fragment,
  9889. groups
  9890. }];
  9891. let layersCount = 0,
  9892. hasAnyNesting = false;
  9893. while (queue.length > 0) {
  9894. const levelData = queue.shift();
  9895. for (const groupId of levelData.groups) {
  9896. const div = document.createElement("div");
  9897. div.className = "treeItem";
  9898. const element = document.createElement("a");
  9899. div.append(element);
  9900. if (typeof groupId === "object") {
  9901. hasAnyNesting = true;
  9902. this._addToggleButton(div, groupId);
  9903. this._setNestedName(element, groupId);
  9904. const itemsDiv = document.createElement("div");
  9905. itemsDiv.className = "treeItems";
  9906. div.append(itemsDiv);
  9907. queue.push({
  9908. parent: itemsDiv,
  9909. groups: groupId.order
  9910. });
  9911. } else {
  9912. const group = optionalContentConfig.getGroup(groupId);
  9913. const input = document.createElement("input");
  9914. this._bindLink(element, {
  9915. groupId,
  9916. input
  9917. });
  9918. input.type = "checkbox";
  9919. input.checked = group.visible;
  9920. this._optionalContentVisibility.set(groupId, {
  9921. input,
  9922. visible: input.checked
  9923. });
  9924. const label = document.createElement("label");
  9925. label.textContent = this._normalizeTextContent(group.name);
  9926. label.append(input);
  9927. element.append(label);
  9928. layersCount++;
  9929. }
  9930. levelData.parent.append(div);
  9931. }
  9932. }
  9933. this._finishRendering(fragment, layersCount, hasAnyNesting);
  9934. }
  9935. async #updateLayers(promise = null) {
  9936. if (!this._optionalContentConfig) {
  9937. return;
  9938. }
  9939. const pdfDocument = this._pdfDocument;
  9940. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig({
  9941. intent: "display"
  9942. }));
  9943. if (pdfDocument !== this._pdfDocument) {
  9944. return;
  9945. }
  9946. if (promise) {
  9947. for (const [groupId, cached] of this._optionalContentVisibility) {
  9948. const group = optionalContentConfig.getGroup(groupId);
  9949. if (group && cached.visible !== group.visible) {
  9950. cached.input.checked = cached.visible = !cached.visible;
  9951. }
  9952. }
  9953. return;
  9954. }
  9955. this.eventBus.dispatch("optionalcontentconfig", {
  9956. source: this,
  9957. promise: Promise.resolve(optionalContentConfig)
  9958. });
  9959. this.render({
  9960. optionalContentConfig,
  9961. pdfDocument: this._pdfDocument
  9962. });
  9963. }
  9964. }
  9965. ;// ./web/pdf_outline_viewer.js
  9966. class PDFOutlineViewer extends BaseTreeViewer {
  9967. constructor(options) {
  9968. super(options);
  9969. this.linkService = options.linkService;
  9970. this.downloadManager = options.downloadManager;
  9971. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  9972. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  9973. this.eventBus._on("pagechanging", evt => {
  9974. this._currentPageNumber = evt.pageNumber;
  9975. });
  9976. this.eventBus._on("pagesloaded", evt => {
  9977. this._isPagesLoaded = !!evt.pagesCount;
  9978. this._currentOutlineItemCapability?.resolve(this._isPagesLoaded);
  9979. });
  9980. this.eventBus._on("sidebarviewchanged", evt => {
  9981. this._sidebarView = evt.view;
  9982. });
  9983. }
  9984. reset() {
  9985. super.reset();
  9986. this._outline = null;
  9987. this._pageNumberToDestHashCapability = null;
  9988. this._currentPageNumber = 1;
  9989. this._isPagesLoaded = null;
  9990. this._currentOutlineItemCapability?.resolve(false);
  9991. this._currentOutlineItemCapability = null;
  9992. }
  9993. _dispatchEvent(outlineCount) {
  9994. this._currentOutlineItemCapability = Promise.withResolvers();
  9995. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  9996. this._currentOutlineItemCapability.resolve(false);
  9997. } else if (this._isPagesLoaded !== null) {
  9998. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  9999. }
  10000. this.eventBus.dispatch("outlineloaded", {
  10001. source: this,
  10002. outlineCount,
  10003. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  10004. });
  10005. }
  10006. _bindLink(element, {
  10007. url,
  10008. newWindow,
  10009. action,
  10010. attachment,
  10011. dest,
  10012. setOCGState
  10013. }) {
  10014. const {
  10015. linkService
  10016. } = this;
  10017. if (url) {
  10018. linkService.addLinkAttributes(element, url, newWindow);
  10019. return;
  10020. }
  10021. if (action) {
  10022. element.href = linkService.getAnchorUrl("");
  10023. element.onclick = () => {
  10024. linkService.executeNamedAction(action);
  10025. return false;
  10026. };
  10027. return;
  10028. }
  10029. if (attachment) {
  10030. element.href = linkService.getAnchorUrl("");
  10031. element.onclick = () => {
  10032. this.downloadManager.openOrDownloadData(attachment.content, attachment.filename);
  10033. return false;
  10034. };
  10035. return;
  10036. }
  10037. if (setOCGState) {
  10038. element.href = linkService.getAnchorUrl("");
  10039. element.onclick = () => {
  10040. linkService.executeSetOCGState(setOCGState);
  10041. return false;
  10042. };
  10043. return;
  10044. }
  10045. element.href = linkService.getDestinationHash(dest);
  10046. element.onclick = evt => {
  10047. this._updateCurrentTreeItem(evt.target.parentNode);
  10048. if (dest) {
  10049. linkService.goToDestination(dest);
  10050. }
  10051. return false;
  10052. };
  10053. }
  10054. _setStyles(element, {
  10055. bold,
  10056. italic
  10057. }) {
  10058. if (bold) {
  10059. element.style.fontWeight = "bold";
  10060. }
  10061. if (italic) {
  10062. element.style.fontStyle = "italic";
  10063. }
  10064. }
  10065. _addToggleButton(div, {
  10066. count,
  10067. items
  10068. }) {
  10069. let hidden = false;
  10070. if (count < 0) {
  10071. let totalCount = items.length;
  10072. if (totalCount > 0) {
  10073. const queue = [...items];
  10074. while (queue.length > 0) {
  10075. const {
  10076. count: nestedCount,
  10077. items: nestedItems
  10078. } = queue.shift();
  10079. if (nestedCount > 0 && nestedItems.length > 0) {
  10080. totalCount += nestedItems.length;
  10081. queue.push(...nestedItems);
  10082. }
  10083. }
  10084. }
  10085. if (Math.abs(count) === totalCount) {
  10086. hidden = true;
  10087. }
  10088. }
  10089. super._addToggleButton(div, hidden);
  10090. }
  10091. _toggleAllTreeItems() {
  10092. if (!this._outline) {
  10093. return;
  10094. }
  10095. super._toggleAllTreeItems();
  10096. }
  10097. render({
  10098. outline,
  10099. pdfDocument
  10100. }) {
  10101. if (this._outline) {
  10102. this.reset();
  10103. }
  10104. this._outline = outline || null;
  10105. this._pdfDocument = pdfDocument || null;
  10106. if (!outline) {
  10107. this._dispatchEvent(0);
  10108. return;
  10109. }
  10110. const fragment = document.createDocumentFragment();
  10111. const queue = [{
  10112. parent: fragment,
  10113. items: outline
  10114. }];
  10115. let outlineCount = 0,
  10116. hasAnyNesting = false;
  10117. while (queue.length > 0) {
  10118. const levelData = queue.shift();
  10119. for (const item of levelData.items) {
  10120. const div = document.createElement("div");
  10121. div.className = "treeItem";
  10122. const element = document.createElement("a");
  10123. this._bindLink(element, item);
  10124. this._setStyles(element, item);
  10125. element.textContent = this._normalizeTextContent(item.title);
  10126. div.append(element);
  10127. if (item.items.length > 0) {
  10128. hasAnyNesting = true;
  10129. this._addToggleButton(div, item);
  10130. const itemsDiv = document.createElement("div");
  10131. itemsDiv.className = "treeItems";
  10132. div.append(itemsDiv);
  10133. queue.push({
  10134. parent: itemsDiv,
  10135. items: item.items
  10136. });
  10137. }
  10138. levelData.parent.append(div);
  10139. outlineCount++;
  10140. }
  10141. }
  10142. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  10143. }
  10144. async _currentOutlineItem() {
  10145. if (!this._isPagesLoaded) {
  10146. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  10147. }
  10148. if (!this._outline || !this._pdfDocument) {
  10149. return;
  10150. }
  10151. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  10152. if (!pageNumberToDestHash) {
  10153. return;
  10154. }
  10155. this._updateCurrentTreeItem(null);
  10156. if (this._sidebarView !== SidebarView.OUTLINE) {
  10157. return;
  10158. }
  10159. for (let i = this._currentPageNumber; i > 0; i--) {
  10160. const destHash = pageNumberToDestHash.get(i);
  10161. if (!destHash) {
  10162. continue;
  10163. }
  10164. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  10165. if (!linkElement) {
  10166. continue;
  10167. }
  10168. this._scrollToCurrentTreeItem(linkElement.parentNode);
  10169. break;
  10170. }
  10171. }
  10172. async _getPageNumberToDestHash(pdfDocument) {
  10173. if (this._pageNumberToDestHashCapability) {
  10174. return this._pageNumberToDestHashCapability.promise;
  10175. }
  10176. this._pageNumberToDestHashCapability = Promise.withResolvers();
  10177. const pageNumberToDestHash = new Map(),
  10178. pageNumberNesting = new Map();
  10179. const queue = [{
  10180. nesting: 0,
  10181. items: this._outline
  10182. }];
  10183. while (queue.length > 0) {
  10184. const levelData = queue.shift(),
  10185. currentNesting = levelData.nesting;
  10186. for (const {
  10187. dest,
  10188. items
  10189. } of levelData.items) {
  10190. let explicitDest, pageNumber;
  10191. if (typeof dest === "string") {
  10192. explicitDest = await pdfDocument.getDestination(dest);
  10193. if (pdfDocument !== this._pdfDocument) {
  10194. return null;
  10195. }
  10196. } else {
  10197. explicitDest = dest;
  10198. }
  10199. if (Array.isArray(explicitDest)) {
  10200. const [destRef] = explicitDest;
  10201. if (destRef && typeof destRef === "object") {
  10202. pageNumber = pdfDocument.cachedPageNumber(destRef);
  10203. } else if (Number.isInteger(destRef)) {
  10204. pageNumber = destRef + 1;
  10205. }
  10206. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  10207. const destHash = this.linkService.getDestinationHash(dest);
  10208. pageNumberToDestHash.set(pageNumber, destHash);
  10209. pageNumberNesting.set(pageNumber, currentNesting);
  10210. }
  10211. }
  10212. if (items.length > 0) {
  10213. queue.push({
  10214. nesting: currentNesting + 1,
  10215. items
  10216. });
  10217. }
  10218. }
  10219. }
  10220. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  10221. return this._pageNumberToDestHashCapability.promise;
  10222. }
  10223. }
  10224. ;// ./web/pdf_presentation_mode.js
  10225. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  10226. const ACTIVE_SELECTOR = "pdfPresentationMode";
  10227. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  10228. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  10229. const PAGE_SWITCH_THRESHOLD = 0.1;
  10230. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  10231. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  10232. class PDFPresentationMode {
  10233. #state = PresentationModeState.UNKNOWN;
  10234. #args = null;
  10235. #fullscreenChangeAbortController = null;
  10236. #windowAbortController = null;
  10237. constructor({
  10238. container,
  10239. pdfViewer,
  10240. eventBus
  10241. }) {
  10242. this.container = container;
  10243. this.pdfViewer = pdfViewer;
  10244. this.eventBus = eventBus;
  10245. this.contextMenuOpen = false;
  10246. this.mouseScrollTimeStamp = 0;
  10247. this.mouseScrollDelta = 0;
  10248. this.touchSwipeState = null;
  10249. }
  10250. async request() {
  10251. const {
  10252. container,
  10253. pdfViewer
  10254. } = this;
  10255. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  10256. return false;
  10257. }
  10258. this.#addFullscreenChangeListeners();
  10259. this.#notifyStateChange(PresentationModeState.CHANGING);
  10260. const promise = container.requestFullscreen();
  10261. this.#args = {
  10262. pageNumber: pdfViewer.currentPageNumber,
  10263. scaleValue: pdfViewer.currentScaleValue,
  10264. scrollMode: pdfViewer.scrollMode,
  10265. spreadMode: null,
  10266. annotationEditorMode: null
  10267. };
  10268. if (pdfViewer.spreadMode !== SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  10269. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  10270. this.#args.spreadMode = pdfViewer.spreadMode;
  10271. }
  10272. if (pdfViewer.annotationEditorMode !== AnnotationEditorType.DISABLE) {
  10273. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  10274. }
  10275. try {
  10276. await promise;
  10277. pdfViewer.focus();
  10278. return true;
  10279. } catch {
  10280. this.#removeFullscreenChangeListeners();
  10281. this.#notifyStateChange(PresentationModeState.NORMAL);
  10282. }
  10283. return false;
  10284. }
  10285. get active() {
  10286. return this.#state === PresentationModeState.CHANGING || this.#state === PresentationModeState.FULLSCREEN;
  10287. }
  10288. #mouseWheel(evt) {
  10289. if (!this.active) {
  10290. return;
  10291. }
  10292. evt.preventDefault();
  10293. const delta = normalizeWheelEventDelta(evt);
  10294. const currentTime = Date.now();
  10295. const storedTime = this.mouseScrollTimeStamp;
  10296. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  10297. return;
  10298. }
  10299. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  10300. this.#resetMouseScrollState();
  10301. }
  10302. this.mouseScrollDelta += delta;
  10303. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  10304. const totalDelta = this.mouseScrollDelta;
  10305. this.#resetMouseScrollState();
  10306. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  10307. if (success) {
  10308. this.mouseScrollTimeStamp = currentTime;
  10309. }
  10310. }
  10311. }
  10312. #notifyStateChange(state) {
  10313. this.#state = state;
  10314. this.eventBus.dispatch("presentationmodechanged", {
  10315. source: this,
  10316. state
  10317. });
  10318. }
  10319. #enter() {
  10320. this.#notifyStateChange(PresentationModeState.FULLSCREEN);
  10321. this.container.classList.add(ACTIVE_SELECTOR);
  10322. setTimeout(() => {
  10323. this.pdfViewer.scrollMode = ScrollMode.PAGE;
  10324. if (this.#args.spreadMode !== null) {
  10325. this.pdfViewer.spreadMode = SpreadMode.NONE;
  10326. }
  10327. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  10328. this.pdfViewer.currentScaleValue = "page-fit";
  10329. if (this.#args.annotationEditorMode !== null) {
  10330. this.pdfViewer.annotationEditorMode = {
  10331. mode: AnnotationEditorType.NONE
  10332. };
  10333. }
  10334. }, 0);
  10335. this.#addWindowListeners();
  10336. this.#showControls();
  10337. this.contextMenuOpen = false;
  10338. document.getSelection().empty();
  10339. }
  10340. #exit() {
  10341. const pageNumber = this.pdfViewer.currentPageNumber;
  10342. this.container.classList.remove(ACTIVE_SELECTOR);
  10343. setTimeout(() => {
  10344. this.#removeFullscreenChangeListeners();
  10345. this.#notifyStateChange(PresentationModeState.NORMAL);
  10346. this.pdfViewer.scrollMode = this.#args.scrollMode;
  10347. if (this.#args.spreadMode !== null) {
  10348. this.pdfViewer.spreadMode = this.#args.spreadMode;
  10349. }
  10350. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  10351. this.pdfViewer.currentPageNumber = pageNumber;
  10352. if (this.#args.annotationEditorMode !== null) {
  10353. this.pdfViewer.annotationEditorMode = {
  10354. mode: this.#args.annotationEditorMode
  10355. };
  10356. }
  10357. this.#args = null;
  10358. }, 0);
  10359. this.#removeWindowListeners();
  10360. this.#hideControls();
  10361. this.#resetMouseScrollState();
  10362. this.contextMenuOpen = false;
  10363. }
  10364. #mouseDown(evt) {
  10365. if (this.contextMenuOpen) {
  10366. this.contextMenuOpen = false;
  10367. evt.preventDefault();
  10368. return;
  10369. }
  10370. if (evt.button !== 0) {
  10371. return;
  10372. }
  10373. if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) {
  10374. return;
  10375. }
  10376. evt.preventDefault();
  10377. if (evt.shiftKey) {
  10378. this.pdfViewer.previousPage();
  10379. } else {
  10380. this.pdfViewer.nextPage();
  10381. }
  10382. }
  10383. #contextMenu() {
  10384. this.contextMenuOpen = true;
  10385. }
  10386. #showControls() {
  10387. if (this.controlsTimeout) {
  10388. clearTimeout(this.controlsTimeout);
  10389. } else {
  10390. this.container.classList.add(CONTROLS_SELECTOR);
  10391. }
  10392. this.controlsTimeout = setTimeout(() => {
  10393. this.container.classList.remove(CONTROLS_SELECTOR);
  10394. delete this.controlsTimeout;
  10395. }, DELAY_BEFORE_HIDING_CONTROLS);
  10396. }
  10397. #hideControls() {
  10398. if (!this.controlsTimeout) {
  10399. return;
  10400. }
  10401. clearTimeout(this.controlsTimeout);
  10402. this.container.classList.remove(CONTROLS_SELECTOR);
  10403. delete this.controlsTimeout;
  10404. }
  10405. #resetMouseScrollState() {
  10406. this.mouseScrollTimeStamp = 0;
  10407. this.mouseScrollDelta = 0;
  10408. }
  10409. #touchSwipe(evt) {
  10410. if (!this.active) {
  10411. return;
  10412. }
  10413. if (evt.touches.length > 1) {
  10414. this.touchSwipeState = null;
  10415. return;
  10416. }
  10417. switch (evt.type) {
  10418. case "touchstart":
  10419. this.touchSwipeState = {
  10420. startX: evt.touches[0].pageX,
  10421. startY: evt.touches[0].pageY,
  10422. endX: evt.touches[0].pageX,
  10423. endY: evt.touches[0].pageY
  10424. };
  10425. break;
  10426. case "touchmove":
  10427. if (this.touchSwipeState === null) {
  10428. return;
  10429. }
  10430. this.touchSwipeState.endX = evt.touches[0].pageX;
  10431. this.touchSwipeState.endY = evt.touches[0].pageY;
  10432. evt.preventDefault();
  10433. break;
  10434. case "touchend":
  10435. if (this.touchSwipeState === null) {
  10436. return;
  10437. }
  10438. let delta = 0;
  10439. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  10440. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  10441. const absAngle = Math.abs(Math.atan2(dy, dx));
  10442. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  10443. delta = dx;
  10444. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  10445. delta = dy;
  10446. }
  10447. if (delta > 0) {
  10448. this.pdfViewer.previousPage();
  10449. } else if (delta < 0) {
  10450. this.pdfViewer.nextPage();
  10451. }
  10452. break;
  10453. }
  10454. }
  10455. #addWindowListeners() {
  10456. if (this.#windowAbortController) {
  10457. return;
  10458. }
  10459. this.#windowAbortController = new AbortController();
  10460. const {
  10461. signal
  10462. } = this.#windowAbortController;
  10463. const touchSwipeBind = this.#touchSwipe.bind(this);
  10464. window.addEventListener("mousemove", this.#showControls.bind(this), {
  10465. signal
  10466. });
  10467. window.addEventListener("mousedown", this.#mouseDown.bind(this), {
  10468. signal
  10469. });
  10470. window.addEventListener("wheel", this.#mouseWheel.bind(this), {
  10471. passive: false,
  10472. signal
  10473. });
  10474. window.addEventListener("keydown", this.#resetMouseScrollState.bind(this), {
  10475. signal
  10476. });
  10477. window.addEventListener("contextmenu", this.#contextMenu.bind(this), {
  10478. signal
  10479. });
  10480. window.addEventListener("touchstart", touchSwipeBind, {
  10481. signal
  10482. });
  10483. window.addEventListener("touchmove", touchSwipeBind, {
  10484. signal
  10485. });
  10486. window.addEventListener("touchend", touchSwipeBind, {
  10487. signal
  10488. });
  10489. }
  10490. #removeWindowListeners() {
  10491. this.#windowAbortController?.abort();
  10492. this.#windowAbortController = null;
  10493. }
  10494. #addFullscreenChangeListeners() {
  10495. if (this.#fullscreenChangeAbortController) {
  10496. return;
  10497. }
  10498. this.#fullscreenChangeAbortController = new AbortController();
  10499. window.addEventListener("fullscreenchange", () => {
  10500. if (document.fullscreenElement) {
  10501. this.#enter();
  10502. } else {
  10503. this.#exit();
  10504. }
  10505. }, {
  10506. signal: this.#fullscreenChangeAbortController.signal
  10507. });
  10508. }
  10509. #removeFullscreenChangeListeners() {
  10510. this.#fullscreenChangeAbortController?.abort();
  10511. this.#fullscreenChangeAbortController = null;
  10512. }
  10513. }
  10514. // EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.every.js
  10515. var es_iterator_every = __webpack_require__(1148);
  10516. ;// ./web/xfa_layer_builder.js
  10517. class XfaLayerBuilder {
  10518. constructor({
  10519. pdfPage,
  10520. annotationStorage = null,
  10521. linkService,
  10522. xfaHtml = null
  10523. }) {
  10524. this.pdfPage = pdfPage;
  10525. this.annotationStorage = annotationStorage;
  10526. this.linkService = linkService;
  10527. this.xfaHtml = xfaHtml;
  10528. this.div = null;
  10529. this._cancelled = false;
  10530. }
  10531. async render({
  10532. viewport,
  10533. intent = "display"
  10534. }) {
  10535. if (intent === "print") {
  10536. const parameters = {
  10537. viewport: viewport.clone({
  10538. dontFlip: true
  10539. }),
  10540. div: this.div,
  10541. xfaHtml: this.xfaHtml,
  10542. annotationStorage: this.annotationStorage,
  10543. linkService: this.linkService,
  10544. intent
  10545. };
  10546. this.div = document.createElement("div");
  10547. parameters.div = this.div;
  10548. return XfaLayer.render(parameters);
  10549. }
  10550. const xfaHtml = await this.pdfPage.getXfa();
  10551. if (this._cancelled || !xfaHtml) {
  10552. return {
  10553. textDivs: []
  10554. };
  10555. }
  10556. const parameters = {
  10557. viewport: viewport.clone({
  10558. dontFlip: true
  10559. }),
  10560. div: this.div,
  10561. xfaHtml,
  10562. annotationStorage: this.annotationStorage,
  10563. linkService: this.linkService,
  10564. intent
  10565. };
  10566. if (this.div) {
  10567. return XfaLayer.update(parameters);
  10568. }
  10569. this.div = document.createElement("div");
  10570. parameters.div = this.div;
  10571. return XfaLayer.render(parameters);
  10572. }
  10573. cancel() {
  10574. this._cancelled = true;
  10575. }
  10576. hide() {
  10577. if (!this.div) {
  10578. return;
  10579. }
  10580. this.div.hidden = true;
  10581. }
  10582. }
  10583. ;// ./web/print_utils.js
  10584. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  10585. const xfaHtml = pdfDocument.allXfaHtml;
  10586. const linkService = new SimpleLinkService();
  10587. const scale = Math.round(PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  10588. for (const xfaPage of xfaHtml.children) {
  10589. const page = document.createElement("div");
  10590. page.className = "xfaPrintedPage";
  10591. printContainer.append(page);
  10592. const builder = new XfaLayerBuilder({
  10593. pdfPage: null,
  10594. annotationStorage: pdfDocument.annotationStorage,
  10595. linkService,
  10596. xfaHtml: xfaPage
  10597. });
  10598. const viewport = getXfaPageViewport(xfaPage, {
  10599. scale
  10600. });
  10601. builder.render({
  10602. viewport,
  10603. intent: "print"
  10604. });
  10605. page.append(builder.div);
  10606. }
  10607. }
  10608. ;// ./web/pdf_print_service.js
  10609. let activeService = null;
  10610. let dialog = null;
  10611. let overlayManager = null;
  10612. let viewerApp = {
  10613. initialized: false
  10614. };
  10615. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  10616. const scratchCanvas = activeService.scratchCanvas;
  10617. const PRINT_UNITS = printResolution / PixelsPerInch.PDF;
  10618. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  10619. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  10620. const ctx = scratchCanvas.getContext("2d");
  10621. ctx.save();
  10622. ctx.fillStyle = "rgb(255, 255, 255)";
  10623. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  10624. ctx.restore();
  10625. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  10626. const renderContext = {
  10627. canvasContext: ctx,
  10628. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  10629. viewport: pdfPage.getViewport({
  10630. scale: 1,
  10631. rotation: size.rotation
  10632. }),
  10633. intent: "print",
  10634. annotationMode: AnnotationMode.ENABLE_STORAGE,
  10635. optionalContentConfigPromise,
  10636. printAnnotationStorage
  10637. };
  10638. const renderTask = pdfPage.render(renderContext);
  10639. return renderTask.promise.catch(reason => {
  10640. if (!(reason instanceof RenderingCancelledException)) {
  10641. console.error(reason);
  10642. }
  10643. throw reason;
  10644. });
  10645. });
  10646. }
  10647. class PDFPrintService {
  10648. constructor({
  10649. pdfDocument,
  10650. pagesOverview,
  10651. printContainer,
  10652. printResolution,
  10653. printAnnotationStoragePromise = null
  10654. }) {
  10655. this.pdfDocument = pdfDocument;
  10656. this.pagesOverview = pagesOverview;
  10657. this.printContainer = printContainer;
  10658. this._printResolution = printResolution || 150;
  10659. this._optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({
  10660. intent: "print"
  10661. });
  10662. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  10663. this.currentPage = -1;
  10664. this.scratchCanvas = document.createElement("canvas");
  10665. }
  10666. layout() {
  10667. this.throwIfInactive();
  10668. const body = document.querySelector("body");
  10669. body.setAttribute("data-pdfjsprinting", true);
  10670. const {
  10671. width,
  10672. height
  10673. } = this.pagesOverview[0];
  10674. const hasEqualPageSizes = this.pagesOverview.every(size => size.width === width && size.height === height);
  10675. if (!hasEqualPageSizes) {
  10676. console.warn("Not all pages have the same size. The printed result may be incorrect!");
  10677. }
  10678. this.pageStyleSheet = document.createElement("style");
  10679. this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`;
  10680. body.append(this.pageStyleSheet);
  10681. }
  10682. destroy() {
  10683. if (activeService !== this) {
  10684. return;
  10685. }
  10686. this.printContainer.textContent = "";
  10687. const body = document.querySelector("body");
  10688. body.removeAttribute("data-pdfjsprinting");
  10689. if (this.pageStyleSheet) {
  10690. this.pageStyleSheet.remove();
  10691. this.pageStyleSheet = null;
  10692. }
  10693. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  10694. this.scratchCanvas = null;
  10695. activeService = null;
  10696. ensureOverlay().then(function () {
  10697. overlayManager.closeIfActive(dialog);
  10698. });
  10699. }
  10700. renderPages() {
  10701. if (this.pdfDocument.isPureXfa) {
  10702. getXfaHtmlForPrinting(this.printContainer, this.pdfDocument);
  10703. return Promise.resolve();
  10704. }
  10705. const pageCount = this.pagesOverview.length;
  10706. const renderNextPage = (resolve, reject) => {
  10707. this.throwIfInactive();
  10708. if (++this.currentPage >= pageCount) {
  10709. renderProgress(pageCount, pageCount);
  10710. resolve();
  10711. return;
  10712. }
  10713. const index = this.currentPage;
  10714. renderProgress(index, pageCount);
  10715. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  10716. renderNextPage(resolve, reject);
  10717. }, reject);
  10718. };
  10719. return new Promise(renderNextPage);
  10720. }
  10721. useRenderedPage() {
  10722. this.throwIfInactive();
  10723. const img = document.createElement("img");
  10724. this.scratchCanvas.toBlob(blob => {
  10725. img.src = URL.createObjectURL(blob);
  10726. });
  10727. const wrapper = document.createElement("div");
  10728. wrapper.className = "printedPage";
  10729. wrapper.append(img);
  10730. this.printContainer.append(wrapper);
  10731. const {
  10732. promise,
  10733. resolve,
  10734. reject
  10735. } = Promise.withResolvers();
  10736. img.onload = resolve;
  10737. img.onerror = reject;
  10738. promise.catch(() => {}).then(() => {
  10739. URL.revokeObjectURL(img.src);
  10740. });
  10741. return promise;
  10742. }
  10743. performPrint() {
  10744. this.throwIfInactive();
  10745. return new Promise(resolve => {
  10746. setTimeout(() => {
  10747. if (!this.active) {
  10748. resolve();
  10749. return;
  10750. }
  10751. print.call(window);
  10752. setTimeout(resolve, 20);
  10753. }, 0);
  10754. });
  10755. }
  10756. get active() {
  10757. return this === activeService;
  10758. }
  10759. throwIfInactive() {
  10760. if (!this.active) {
  10761. throw new Error("This print request was cancelled or completed.");
  10762. }
  10763. }
  10764. }
  10765. const print = window.print;
  10766. window.print = function () {
  10767. if (activeService) {
  10768. console.warn("Ignored window.print() because of a pending print job.");
  10769. return;
  10770. }
  10771. ensureOverlay().then(function () {
  10772. if (activeService) {
  10773. overlayManager.open(dialog);
  10774. }
  10775. });
  10776. try {
  10777. dispatchEvent("beforeprint");
  10778. } finally {
  10779. if (!activeService) {
  10780. console.error("Expected print service to be initialized.");
  10781. ensureOverlay().then(function () {
  10782. overlayManager.closeIfActive(dialog);
  10783. });
  10784. } else {
  10785. const activeServiceOnEntry = activeService;
  10786. activeService.renderPages().then(() => activeServiceOnEntry.performPrint()).catch(() => {}).then(() => {
  10787. if (activeServiceOnEntry.active) {
  10788. abort();
  10789. }
  10790. });
  10791. }
  10792. }
  10793. };
  10794. function dispatchEvent(eventType) {
  10795. const event = new CustomEvent(eventType, {
  10796. bubbles: false,
  10797. cancelable: false,
  10798. detail: "custom"
  10799. });
  10800. window.dispatchEvent(event);
  10801. }
  10802. function abort() {
  10803. if (activeService) {
  10804. activeService.destroy();
  10805. dispatchEvent("afterprint");
  10806. }
  10807. }
  10808. function renderProgress(index, total) {
  10809. dialog ||= document.getElementById("printServiceDialog");
  10810. const progress = Math.round(100 * index / total);
  10811. const progressBar = dialog.querySelector("progress");
  10812. const progressPerc = dialog.querySelector(".relative-progress");
  10813. progressBar.value = progress;
  10814. progressPerc.setAttribute("data-l10n-args", JSON.stringify({
  10815. progress
  10816. }));
  10817. }
  10818. window.addEventListener("keydown", function (event) {
  10819. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  10820. window.print();
  10821. event.preventDefault();
  10822. event.stopImmediatePropagation();
  10823. }
  10824. }, true);
  10825. if ("onbeforeprint" in window) {
  10826. const stopPropagationIfNeeded = function (event) {
  10827. if (event.detail !== "custom") {
  10828. event.stopImmediatePropagation();
  10829. }
  10830. };
  10831. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  10832. window.addEventListener("afterprint", stopPropagationIfNeeded);
  10833. }
  10834. let overlayPromise;
  10835. function ensureOverlay() {
  10836. if (!overlayPromise) {
  10837. overlayManager = viewerApp.overlayManager;
  10838. if (!overlayManager) {
  10839. throw new Error("The overlay manager has not yet been initialized.");
  10840. }
  10841. dialog ||= document.getElementById("printServiceDialog");
  10842. overlayPromise = overlayManager.register(dialog, true);
  10843. document.getElementById("printCancel").onclick = abort;
  10844. dialog.addEventListener("close", abort);
  10845. }
  10846. return overlayPromise;
  10847. }
  10848. class PDFPrintServiceFactory {
  10849. static initGlobals(app) {
  10850. viewerApp = app;
  10851. }
  10852. static get supportsPrinting() {
  10853. return shadow(this, "supportsPrinting", true);
  10854. }
  10855. static createPrintService(params) {
  10856. if (activeService) {
  10857. throw new Error("The print service is created and active.");
  10858. }
  10859. return activeService = new PDFPrintService(params);
  10860. }
  10861. }
  10862. ;// ./web/pdf_rendering_queue.js
  10863. const CLEANUP_TIMEOUT = 30000;
  10864. class PDFRenderingQueue {
  10865. constructor() {
  10866. this.pdfViewer = null;
  10867. this.pdfThumbnailViewer = null;
  10868. this.onIdle = null;
  10869. this.highestPriorityPage = null;
  10870. this.idleTimeout = null;
  10871. this.printing = false;
  10872. this.isThumbnailViewEnabled = false;
  10873. Object.defineProperty(this, "hasViewer", {
  10874. value: () => !!this.pdfViewer
  10875. });
  10876. }
  10877. setViewer(pdfViewer) {
  10878. this.pdfViewer = pdfViewer;
  10879. }
  10880. setThumbnailViewer(pdfThumbnailViewer) {
  10881. this.pdfThumbnailViewer = pdfThumbnailViewer;
  10882. }
  10883. isHighestPriority(view) {
  10884. return this.highestPriorityPage === view.renderingId;
  10885. }
  10886. renderHighestPriority(currentlyVisiblePages) {
  10887. if (this.idleTimeout) {
  10888. clearTimeout(this.idleTimeout);
  10889. this.idleTimeout = null;
  10890. }
  10891. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  10892. return;
  10893. }
  10894. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  10895. return;
  10896. }
  10897. if (this.printing) {
  10898. return;
  10899. }
  10900. if (this.onIdle) {
  10901. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  10902. }
  10903. }
  10904. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false, ignoreDetailViews = false) {
  10905. const visibleViews = visible.views,
  10906. numVisible = visibleViews.length;
  10907. if (numVisible === 0) {
  10908. return null;
  10909. }
  10910. for (let i = 0; i < numVisible; i++) {
  10911. const view = visibleViews[i].view;
  10912. if (!this.isViewFinished(view)) {
  10913. return view;
  10914. }
  10915. }
  10916. if (!ignoreDetailViews) {
  10917. for (let i = 0; i < numVisible; i++) {
  10918. const {
  10919. detailView
  10920. } = visibleViews[i].view;
  10921. if (detailView && !this.isViewFinished(detailView)) {
  10922. return detailView;
  10923. }
  10924. }
  10925. }
  10926. const firstId = visible.first.id,
  10927. lastId = visible.last.id;
  10928. if (lastId - firstId + 1 > numVisible) {
  10929. const visibleIds = visible.ids;
  10930. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  10931. const holeId = scrolledDown ? firstId + i : lastId - i;
  10932. if (visibleIds.has(holeId)) {
  10933. continue;
  10934. }
  10935. const holeView = views[holeId - 1];
  10936. if (!this.isViewFinished(holeView)) {
  10937. return holeView;
  10938. }
  10939. }
  10940. }
  10941. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  10942. let preRenderView = views[preRenderIndex];
  10943. if (preRenderView && !this.isViewFinished(preRenderView)) {
  10944. return preRenderView;
  10945. }
  10946. if (preRenderExtra) {
  10947. preRenderIndex += scrolledDown ? 1 : -1;
  10948. preRenderView = views[preRenderIndex];
  10949. if (preRenderView && !this.isViewFinished(preRenderView)) {
  10950. return preRenderView;
  10951. }
  10952. }
  10953. return null;
  10954. }
  10955. isViewFinished(view) {
  10956. return view.renderingState === RenderingStates.FINISHED;
  10957. }
  10958. renderView(view) {
  10959. switch (view.renderingState) {
  10960. case RenderingStates.FINISHED:
  10961. return false;
  10962. case RenderingStates.PAUSED:
  10963. this.highestPriorityPage = view.renderingId;
  10964. view.resume();
  10965. break;
  10966. case RenderingStates.RUNNING:
  10967. this.highestPriorityPage = view.renderingId;
  10968. break;
  10969. case RenderingStates.INITIAL:
  10970. this.highestPriorityPage = view.renderingId;
  10971. view.draw().finally(() => {
  10972. this.renderHighestPriority();
  10973. }).catch(reason => {
  10974. if (reason instanceof RenderingCancelledException) {
  10975. return;
  10976. }
  10977. console.error("renderView:", reason);
  10978. });
  10979. break;
  10980. }
  10981. return true;
  10982. }
  10983. }
  10984. ;// ./web/pdf_scripting_manager.js
  10985. class PDFScriptingManager {
  10986. #closeCapability = null;
  10987. #destroyCapability = null;
  10988. #docProperties = null;
  10989. #eventAbortController = null;
  10990. #eventBus = null;
  10991. #externalServices = null;
  10992. #pdfDocument = null;
  10993. #pdfViewer = null;
  10994. #ready = false;
  10995. #scripting = null;
  10996. #willPrintCapability = null;
  10997. constructor({
  10998. eventBus,
  10999. externalServices = null,
  11000. docProperties = null
  11001. }) {
  11002. this.#eventBus = eventBus;
  11003. this.#externalServices = externalServices;
  11004. this.#docProperties = docProperties;
  11005. }
  11006. setViewer(pdfViewer) {
  11007. this.#pdfViewer = pdfViewer;
  11008. }
  11009. async setDocument(pdfDocument) {
  11010. if (this.#pdfDocument) {
  11011. await this.#destroyScripting();
  11012. }
  11013. this.#pdfDocument = pdfDocument;
  11014. if (!pdfDocument) {
  11015. return;
  11016. }
  11017. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  11018. if (!objects && !docActions) {
  11019. await this.#destroyScripting();
  11020. return;
  11021. }
  11022. if (pdfDocument !== this.#pdfDocument) {
  11023. return;
  11024. }
  11025. try {
  11026. this.#scripting = this.#initScripting();
  11027. } catch (error) {
  11028. console.error("setDocument:", error);
  11029. await this.#destroyScripting();
  11030. return;
  11031. }
  11032. const eventBus = this.#eventBus;
  11033. this.#eventAbortController = new AbortController();
  11034. const {
  11035. signal
  11036. } = this.#eventAbortController;
  11037. eventBus._on("updatefromsandbox", event => {
  11038. if (event?.source === window) {
  11039. this.#updateFromSandbox(event.detail);
  11040. }
  11041. }, {
  11042. signal
  11043. });
  11044. eventBus._on("dispatcheventinsandbox", event => {
  11045. this.#scripting?.dispatchEventInSandbox(event.detail);
  11046. }, {
  11047. signal
  11048. });
  11049. eventBus._on("pagechanging", ({
  11050. pageNumber,
  11051. previous
  11052. }) => {
  11053. if (pageNumber === previous) {
  11054. return;
  11055. }
  11056. this.#dispatchPageClose(previous);
  11057. this.#dispatchPageOpen(pageNumber);
  11058. }, {
  11059. signal
  11060. });
  11061. eventBus._on("pagerendered", ({
  11062. pageNumber
  11063. }) => {
  11064. if (!this._pageOpenPending.has(pageNumber)) {
  11065. return;
  11066. }
  11067. if (pageNumber !== this.#pdfViewer.currentPageNumber) {
  11068. return;
  11069. }
  11070. this.#dispatchPageOpen(pageNumber);
  11071. }, {
  11072. signal
  11073. });
  11074. eventBus._on("pagesdestroy", async () => {
  11075. await this.#dispatchPageClose(this.#pdfViewer.currentPageNumber);
  11076. await this.#scripting?.dispatchEventInSandbox({
  11077. id: "doc",
  11078. name: "WillClose"
  11079. });
  11080. this.#closeCapability?.resolve();
  11081. }, {
  11082. signal
  11083. });
  11084. try {
  11085. const docProperties = await this.#docProperties(pdfDocument);
  11086. if (pdfDocument !== this.#pdfDocument) {
  11087. return;
  11088. }
  11089. await this.#scripting.createSandbox({
  11090. objects,
  11091. calculationOrder,
  11092. appInfo: {
  11093. platform: navigator.platform,
  11094. language: navigator.language
  11095. },
  11096. docInfo: {
  11097. ...docProperties,
  11098. actions: docActions
  11099. }
  11100. });
  11101. eventBus.dispatch("sandboxcreated", {
  11102. source: this
  11103. });
  11104. } catch (error) {
  11105. console.error("setDocument:", error);
  11106. await this.#destroyScripting();
  11107. return;
  11108. }
  11109. await this.#scripting?.dispatchEventInSandbox({
  11110. id: "doc",
  11111. name: "Open"
  11112. });
  11113. await this.#dispatchPageOpen(this.#pdfViewer.currentPageNumber, true);
  11114. Promise.resolve().then(() => {
  11115. if (pdfDocument === this.#pdfDocument) {
  11116. this.#ready = true;
  11117. }
  11118. });
  11119. }
  11120. async dispatchWillSave() {
  11121. return this.#scripting?.dispatchEventInSandbox({
  11122. id: "doc",
  11123. name: "WillSave"
  11124. });
  11125. }
  11126. async dispatchDidSave() {
  11127. return this.#scripting?.dispatchEventInSandbox({
  11128. id: "doc",
  11129. name: "DidSave"
  11130. });
  11131. }
  11132. async dispatchWillPrint() {
  11133. if (!this.#scripting) {
  11134. return;
  11135. }
  11136. await this.#willPrintCapability?.promise;
  11137. this.#willPrintCapability = Promise.withResolvers();
  11138. try {
  11139. await this.#scripting.dispatchEventInSandbox({
  11140. id: "doc",
  11141. name: "WillPrint"
  11142. });
  11143. } catch (ex) {
  11144. this.#willPrintCapability.resolve();
  11145. this.#willPrintCapability = null;
  11146. throw ex;
  11147. }
  11148. await this.#willPrintCapability.promise;
  11149. }
  11150. async dispatchDidPrint() {
  11151. return this.#scripting?.dispatchEventInSandbox({
  11152. id: "doc",
  11153. name: "DidPrint"
  11154. });
  11155. }
  11156. get destroyPromise() {
  11157. return this.#destroyCapability?.promise || null;
  11158. }
  11159. get ready() {
  11160. return this.#ready;
  11161. }
  11162. get _pageOpenPending() {
  11163. return shadow(this, "_pageOpenPending", new Set());
  11164. }
  11165. get _visitedPages() {
  11166. return shadow(this, "_visitedPages", new Map());
  11167. }
  11168. async #updateFromSandbox(detail) {
  11169. const pdfViewer = this.#pdfViewer;
  11170. const isInPresentationMode = pdfViewer.isInPresentationMode || pdfViewer.isChangingPresentationMode;
  11171. const {
  11172. id,
  11173. siblings,
  11174. command,
  11175. value
  11176. } = detail;
  11177. if (!id) {
  11178. switch (command) {
  11179. case "clear":
  11180. console.clear();
  11181. break;
  11182. case "error":
  11183. console.error(value);
  11184. break;
  11185. case "layout":
  11186. if (!isInPresentationMode) {
  11187. const modes = apiPageLayoutToViewerModes(value);
  11188. pdfViewer.spreadMode = modes.spreadMode;
  11189. }
  11190. break;
  11191. case "page-num":
  11192. pdfViewer.currentPageNumber = value + 1;
  11193. break;
  11194. case "print":
  11195. await pdfViewer.pagesPromise;
  11196. this.#eventBus.dispatch("print", {
  11197. source: this
  11198. });
  11199. break;
  11200. case "println":
  11201. console.log(value);
  11202. break;
  11203. case "zoom":
  11204. if (!isInPresentationMode) {
  11205. pdfViewer.currentScaleValue = value;
  11206. }
  11207. break;
  11208. case "SaveAs":
  11209. this.#eventBus.dispatch("download", {
  11210. source: this
  11211. });
  11212. break;
  11213. case "FirstPage":
  11214. pdfViewer.currentPageNumber = 1;
  11215. break;
  11216. case "LastPage":
  11217. pdfViewer.currentPageNumber = pdfViewer.pagesCount;
  11218. break;
  11219. case "NextPage":
  11220. pdfViewer.nextPage();
  11221. break;
  11222. case "PrevPage":
  11223. pdfViewer.previousPage();
  11224. break;
  11225. case "ZoomViewIn":
  11226. if (!isInPresentationMode) {
  11227. pdfViewer.increaseScale();
  11228. }
  11229. break;
  11230. case "ZoomViewOut":
  11231. if (!isInPresentationMode) {
  11232. pdfViewer.decreaseScale();
  11233. }
  11234. break;
  11235. case "WillPrintFinished":
  11236. this.#willPrintCapability?.resolve();
  11237. this.#willPrintCapability = null;
  11238. break;
  11239. }
  11240. return;
  11241. }
  11242. if (isInPresentationMode && detail.focus) {
  11243. return;
  11244. }
  11245. delete detail.id;
  11246. delete detail.siblings;
  11247. const ids = siblings ? [id, ...siblings] : [id];
  11248. for (const elementId of ids) {
  11249. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  11250. if (element) {
  11251. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  11252. detail
  11253. }));
  11254. } else {
  11255. this.#pdfDocument?.annotationStorage.setValue(elementId, detail);
  11256. }
  11257. }
  11258. }
  11259. async #dispatchPageOpen(pageNumber, initialize = false) {
  11260. const pdfDocument = this.#pdfDocument,
  11261. visitedPages = this._visitedPages;
  11262. if (initialize) {
  11263. this.#closeCapability = Promise.withResolvers();
  11264. }
  11265. if (!this.#closeCapability) {
  11266. return;
  11267. }
  11268. const pageView = this.#pdfViewer.getPageView(pageNumber - 1);
  11269. if (pageView?.renderingState !== RenderingStates.FINISHED) {
  11270. this._pageOpenPending.add(pageNumber);
  11271. return;
  11272. }
  11273. this._pageOpenPending.delete(pageNumber);
  11274. const actionsPromise = (async () => {
  11275. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  11276. if (pdfDocument !== this.#pdfDocument) {
  11277. return;
  11278. }
  11279. await this.#scripting?.dispatchEventInSandbox({
  11280. id: "page",
  11281. name: "PageOpen",
  11282. pageNumber,
  11283. actions
  11284. });
  11285. })();
  11286. visitedPages.set(pageNumber, actionsPromise);
  11287. }
  11288. async #dispatchPageClose(pageNumber) {
  11289. const pdfDocument = this.#pdfDocument,
  11290. visitedPages = this._visitedPages;
  11291. if (!this.#closeCapability) {
  11292. return;
  11293. }
  11294. if (this._pageOpenPending.has(pageNumber)) {
  11295. return;
  11296. }
  11297. const actionsPromise = visitedPages.get(pageNumber);
  11298. if (!actionsPromise) {
  11299. return;
  11300. }
  11301. visitedPages.set(pageNumber, null);
  11302. await actionsPromise;
  11303. if (pdfDocument !== this.#pdfDocument) {
  11304. return;
  11305. }
  11306. await this.#scripting?.dispatchEventInSandbox({
  11307. id: "page",
  11308. name: "PageClose",
  11309. pageNumber
  11310. });
  11311. }
  11312. #initScripting() {
  11313. this.#destroyCapability = Promise.withResolvers();
  11314. if (this.#scripting) {
  11315. throw new Error("#initScripting: Scripting already exists.");
  11316. }
  11317. return this.#externalServices.createScripting();
  11318. }
  11319. async #destroyScripting() {
  11320. if (!this.#scripting) {
  11321. this.#pdfDocument = null;
  11322. this.#destroyCapability?.resolve();
  11323. return;
  11324. }
  11325. if (this.#closeCapability) {
  11326. await Promise.race([this.#closeCapability.promise, new Promise(resolve => {
  11327. setTimeout(resolve, 1000);
  11328. })]).catch(() => {});
  11329. this.#closeCapability = null;
  11330. }
  11331. this.#pdfDocument = null;
  11332. try {
  11333. await this.#scripting.destroySandbox();
  11334. } catch {}
  11335. this.#willPrintCapability?.reject(new Error("Scripting destroyed."));
  11336. this.#willPrintCapability = null;
  11337. this.#eventAbortController?.abort();
  11338. this.#eventAbortController = null;
  11339. this._pageOpenPending.clear();
  11340. this._visitedPages.clear();
  11341. this.#scripting = null;
  11342. this.#ready = false;
  11343. this.#destroyCapability?.resolve();
  11344. }
  11345. }
  11346. ;// ./web/pdf_sidebar.js
  11347. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  11348. const SIDEBAR_MIN_WIDTH = 200;
  11349. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  11350. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  11351. class PDFSidebar {
  11352. #isRTL = false;
  11353. #mouseAC = null;
  11354. #outerContainerWidth = null;
  11355. #width = null;
  11356. constructor({
  11357. elements,
  11358. eventBus,
  11359. l10n
  11360. }) {
  11361. this.isOpen = false;
  11362. this.active = SidebarView.THUMBS;
  11363. this.isInitialViewSet = false;
  11364. this.isInitialEventDispatched = false;
  11365. this.onToggled = null;
  11366. this.onUpdateThumbnails = null;
  11367. this.outerContainer = elements.outerContainer;
  11368. this.sidebarContainer = elements.sidebarContainer;
  11369. this.toggleButton = elements.toggleButton;
  11370. this.resizer = elements.resizer;
  11371. this.thumbnailButton = elements.thumbnailButton;
  11372. this.outlineButton = elements.outlineButton;
  11373. this.attachmentsButton = elements.attachmentsButton;
  11374. this.layersButton = elements.layersButton;
  11375. this.thumbnailView = elements.thumbnailView;
  11376. this.outlineView = elements.outlineView;
  11377. this.attachmentsView = elements.attachmentsView;
  11378. this.layersView = elements.layersView;
  11379. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  11380. this.eventBus = eventBus;
  11381. this.#isRTL = l10n.getDirection() === "rtl";
  11382. this.#addEventListeners();
  11383. }
  11384. reset() {
  11385. this.isInitialViewSet = false;
  11386. this.isInitialEventDispatched = false;
  11387. this.#hideUINotification(true);
  11388. this.switchView(SidebarView.THUMBS);
  11389. this.outlineButton.disabled = false;
  11390. this.attachmentsButton.disabled = false;
  11391. this.layersButton.disabled = false;
  11392. this._currentOutlineItemButton.disabled = true;
  11393. }
  11394. get visibleView() {
  11395. return this.isOpen ? this.active : SidebarView.NONE;
  11396. }
  11397. setInitialView(view = SidebarView.NONE) {
  11398. if (this.isInitialViewSet) {
  11399. return;
  11400. }
  11401. this.isInitialViewSet = true;
  11402. if (view === SidebarView.NONE || view === SidebarView.UNKNOWN) {
  11403. this.#dispatchEvent();
  11404. return;
  11405. }
  11406. this.switchView(view, true);
  11407. if (!this.isInitialEventDispatched) {
  11408. this.#dispatchEvent();
  11409. }
  11410. }
  11411. switchView(view, forceOpen = false) {
  11412. const isViewChanged = view !== this.active;
  11413. let forceRendering = false;
  11414. switch (view) {
  11415. case SidebarView.NONE:
  11416. if (this.isOpen) {
  11417. this.close();
  11418. }
  11419. return;
  11420. case SidebarView.THUMBS:
  11421. if (this.isOpen && isViewChanged) {
  11422. forceRendering = true;
  11423. }
  11424. break;
  11425. case SidebarView.OUTLINE:
  11426. if (this.outlineButton.disabled) {
  11427. return;
  11428. }
  11429. break;
  11430. case SidebarView.ATTACHMENTS:
  11431. if (this.attachmentsButton.disabled) {
  11432. return;
  11433. }
  11434. break;
  11435. case SidebarView.LAYERS:
  11436. if (this.layersButton.disabled) {
  11437. return;
  11438. }
  11439. break;
  11440. default:
  11441. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  11442. return;
  11443. }
  11444. this.active = view;
  11445. toggleCheckedBtn(this.thumbnailButton, view === SidebarView.THUMBS, this.thumbnailView);
  11446. toggleCheckedBtn(this.outlineButton, view === SidebarView.OUTLINE, this.outlineView);
  11447. toggleCheckedBtn(this.attachmentsButton, view === SidebarView.ATTACHMENTS, this.attachmentsView);
  11448. toggleCheckedBtn(this.layersButton, view === SidebarView.LAYERS, this.layersView);
  11449. if (forceOpen && !this.isOpen) {
  11450. this.open();
  11451. return;
  11452. }
  11453. if (forceRendering) {
  11454. this.onUpdateThumbnails();
  11455. this.onToggled();
  11456. }
  11457. if (isViewChanged) {
  11458. this.#dispatchEvent();
  11459. }
  11460. }
  11461. open() {
  11462. if (this.isOpen) {
  11463. return;
  11464. }
  11465. this.isOpen = true;
  11466. toggleExpandedBtn(this.toggleButton, true);
  11467. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  11468. if (this.active === SidebarView.THUMBS) {
  11469. this.onUpdateThumbnails();
  11470. }
  11471. this.onToggled();
  11472. this.#dispatchEvent();
  11473. this.#hideUINotification();
  11474. }
  11475. close(evt = null) {
  11476. if (!this.isOpen) {
  11477. return;
  11478. }
  11479. this.isOpen = false;
  11480. toggleExpandedBtn(this.toggleButton, false);
  11481. this.outerContainer.classList.add("sidebarMoving");
  11482. this.outerContainer.classList.remove("sidebarOpen");
  11483. this.onToggled();
  11484. this.#dispatchEvent();
  11485. if (evt?.detail > 0) {
  11486. this.toggleButton.blur();
  11487. }
  11488. }
  11489. toggle(evt = null) {
  11490. if (this.isOpen) {
  11491. this.close(evt);
  11492. } else {
  11493. this.open();
  11494. }
  11495. }
  11496. #dispatchEvent() {
  11497. if (this.isInitialViewSet) {
  11498. this.isInitialEventDispatched ||= true;
  11499. }
  11500. this.eventBus.dispatch("sidebarviewchanged", {
  11501. source: this,
  11502. view: this.visibleView
  11503. });
  11504. }
  11505. #showUINotification() {
  11506. this.toggleButton.setAttribute("data-l10n-id", "pdfjs-toggle-sidebar-notification-button");
  11507. if (!this.isOpen) {
  11508. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  11509. }
  11510. }
  11511. #hideUINotification(reset = false) {
  11512. if (this.isOpen || reset) {
  11513. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  11514. }
  11515. if (reset) {
  11516. this.toggleButton.setAttribute("data-l10n-id", "pdfjs-toggle-sidebar-button");
  11517. }
  11518. }
  11519. #addEventListeners() {
  11520. const {
  11521. eventBus,
  11522. outerContainer
  11523. } = this;
  11524. this.sidebarContainer.addEventListener("transitionend", evt => {
  11525. if (evt.target === this.sidebarContainer) {
  11526. outerContainer.classList.remove("sidebarMoving");
  11527. eventBus.dispatch("resize", {
  11528. source: this
  11529. });
  11530. }
  11531. });
  11532. this.toggleButton.addEventListener("click", evt => {
  11533. this.toggle(evt);
  11534. });
  11535. this.thumbnailButton.addEventListener("click", () => {
  11536. this.switchView(SidebarView.THUMBS);
  11537. });
  11538. this.outlineButton.addEventListener("click", () => {
  11539. this.switchView(SidebarView.OUTLINE);
  11540. });
  11541. this.outlineButton.addEventListener("dblclick", () => {
  11542. eventBus.dispatch("toggleoutlinetree", {
  11543. source: this
  11544. });
  11545. });
  11546. this.attachmentsButton.addEventListener("click", () => {
  11547. this.switchView(SidebarView.ATTACHMENTS);
  11548. });
  11549. this.layersButton.addEventListener("click", () => {
  11550. this.switchView(SidebarView.LAYERS);
  11551. });
  11552. this.layersButton.addEventListener("dblclick", () => {
  11553. eventBus.dispatch("resetlayers", {
  11554. source: this
  11555. });
  11556. });
  11557. this._currentOutlineItemButton.addEventListener("click", () => {
  11558. eventBus.dispatch("currentoutlineitem", {
  11559. source: this
  11560. });
  11561. });
  11562. const onTreeLoaded = (count, button, view) => {
  11563. button.disabled = !count;
  11564. if (count) {
  11565. this.#showUINotification();
  11566. } else if (this.active === view) {
  11567. this.switchView(SidebarView.THUMBS);
  11568. }
  11569. };
  11570. eventBus._on("outlineloaded", evt => {
  11571. onTreeLoaded(evt.outlineCount, this.outlineButton, SidebarView.OUTLINE);
  11572. evt.currentOutlineItemPromise.then(enabled => {
  11573. if (!this.isInitialViewSet) {
  11574. return;
  11575. }
  11576. this._currentOutlineItemButton.disabled = !enabled;
  11577. });
  11578. });
  11579. eventBus._on("attachmentsloaded", evt => {
  11580. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, SidebarView.ATTACHMENTS);
  11581. });
  11582. eventBus._on("layersloaded", evt => {
  11583. onTreeLoaded(evt.layersCount, this.layersButton, SidebarView.LAYERS);
  11584. });
  11585. eventBus._on("presentationmodechanged", evt => {
  11586. if (evt.state === PresentationModeState.NORMAL && this.visibleView === SidebarView.THUMBS) {
  11587. this.onUpdateThumbnails();
  11588. }
  11589. });
  11590. this.resizer.addEventListener("mousedown", evt => {
  11591. if (evt.button !== 0) {
  11592. return;
  11593. }
  11594. outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  11595. this.#mouseAC = new AbortController();
  11596. const opts = {
  11597. signal: this.#mouseAC.signal
  11598. };
  11599. window.addEventListener("mousemove", this.#mouseMove.bind(this), opts);
  11600. window.addEventListener("mouseup", this.#mouseUp.bind(this), opts);
  11601. window.addEventListener("blur", this.#mouseUp.bind(this), opts);
  11602. });
  11603. eventBus._on("resize", evt => {
  11604. if (evt.source !== window) {
  11605. return;
  11606. }
  11607. this.#outerContainerWidth = null;
  11608. if (!this.#width) {
  11609. return;
  11610. }
  11611. if (!this.isOpen) {
  11612. this.#updateWidth(this.#width);
  11613. return;
  11614. }
  11615. outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  11616. const updated = this.#updateWidth(this.#width);
  11617. Promise.resolve().then(() => {
  11618. outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  11619. if (updated) {
  11620. eventBus.dispatch("resize", {
  11621. source: this
  11622. });
  11623. }
  11624. });
  11625. });
  11626. }
  11627. get outerContainerWidth() {
  11628. return this.#outerContainerWidth ||= this.outerContainer.clientWidth;
  11629. }
  11630. #updateWidth(width = 0) {
  11631. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  11632. if (width > maxWidth) {
  11633. width = maxWidth;
  11634. }
  11635. if (width < SIDEBAR_MIN_WIDTH) {
  11636. width = SIDEBAR_MIN_WIDTH;
  11637. }
  11638. if (width === this.#width) {
  11639. return false;
  11640. }
  11641. this.#width = width;
  11642. docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  11643. return true;
  11644. }
  11645. #mouseMove(evt) {
  11646. let width = evt.clientX;
  11647. if (this.#isRTL) {
  11648. width = this.outerContainerWidth - width;
  11649. }
  11650. this.#updateWidth(width);
  11651. }
  11652. #mouseUp(evt) {
  11653. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  11654. this.eventBus.dispatch("resize", {
  11655. source: this
  11656. });
  11657. this.#mouseAC?.abort();
  11658. this.#mouseAC = null;
  11659. }
  11660. }
  11661. ;// ./web/pdf_thumbnail_view.js
  11662. const DRAW_UPSCALE_FACTOR = 2;
  11663. const MAX_NUM_SCALING_STEPS = 3;
  11664. const THUMBNAIL_WIDTH = 98;
  11665. function zeroCanvas(c) {
  11666. c.width = 0;
  11667. c.height = 0;
  11668. }
  11669. class TempImageFactory {
  11670. static #tempCanvas = null;
  11671. static getCanvas(width, height) {
  11672. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  11673. tempCanvas.width = width;
  11674. tempCanvas.height = height;
  11675. const ctx = tempCanvas.getContext("2d", {
  11676. alpha: false
  11677. });
  11678. ctx.save();
  11679. ctx.fillStyle = "rgb(255, 255, 255)";
  11680. ctx.fillRect(0, 0, width, height);
  11681. ctx.restore();
  11682. return [tempCanvas, tempCanvas.getContext("2d")];
  11683. }
  11684. static destroyCanvas() {
  11685. if (this.#tempCanvas) {
  11686. zeroCanvas(this.#tempCanvas);
  11687. }
  11688. this.#tempCanvas = null;
  11689. }
  11690. }
  11691. class PDFThumbnailView {
  11692. constructor({
  11693. container,
  11694. eventBus,
  11695. id,
  11696. defaultViewport,
  11697. optionalContentConfigPromise,
  11698. linkService,
  11699. renderingQueue,
  11700. maxCanvasPixels,
  11701. maxCanvasDim,
  11702. pageColors,
  11703. enableHWA
  11704. }) {
  11705. this.id = id;
  11706. this.renderingId = "thumbnail" + id;
  11707. this.pageLabel = null;
  11708. this.pdfPage = null;
  11709. this.rotation = 0;
  11710. this.viewport = defaultViewport;
  11711. this.pdfPageRotate = defaultViewport.rotation;
  11712. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  11713. this.maxCanvasPixels = maxCanvasPixels ?? AppOptions.get("maxCanvasPixels");
  11714. this.maxCanvasDim = maxCanvasDim || AppOptions.get("maxCanvasDim");
  11715. this.pageColors = pageColors || null;
  11716. this.enableHWA = enableHWA || false;
  11717. this.eventBus = eventBus;
  11718. this.linkService = linkService;
  11719. this.renderingQueue = renderingQueue;
  11720. this.renderTask = null;
  11721. this.renderingState = RenderingStates.INITIAL;
  11722. this.resume = null;
  11723. const anchor = document.createElement("a");
  11724. anchor.href = linkService.getAnchorUrl("#page=" + id);
  11725. anchor.setAttribute("data-l10n-id", "pdfjs-thumb-page-title");
  11726. anchor.setAttribute("data-l10n-args", this.#pageL10nArgs);
  11727. anchor.onclick = function () {
  11728. linkService.goToPage(id);
  11729. return false;
  11730. };
  11731. this.anchor = anchor;
  11732. const div = document.createElement("div");
  11733. div.className = "thumbnail";
  11734. div.setAttribute("data-page-number", this.id);
  11735. this.div = div;
  11736. this.#updateDims();
  11737. const img = document.createElement("div");
  11738. img.className = "thumbnailImage";
  11739. this._placeholderImg = img;
  11740. div.append(img);
  11741. anchor.append(div);
  11742. container.append(anchor);
  11743. }
  11744. #updateDims() {
  11745. const {
  11746. width,
  11747. height
  11748. } = this.viewport;
  11749. const ratio = width / height;
  11750. this.canvasWidth = THUMBNAIL_WIDTH;
  11751. this.canvasHeight = this.canvasWidth / ratio | 0;
  11752. this.scale = this.canvasWidth / width;
  11753. const {
  11754. style
  11755. } = this.div;
  11756. style.setProperty("--thumbnail-width", `${this.canvasWidth}px`);
  11757. style.setProperty("--thumbnail-height", `${this.canvasHeight}px`);
  11758. }
  11759. setPdfPage(pdfPage) {
  11760. this.pdfPage = pdfPage;
  11761. this.pdfPageRotate = pdfPage.rotate;
  11762. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  11763. this.viewport = pdfPage.getViewport({
  11764. scale: 1,
  11765. rotation: totalRotation
  11766. });
  11767. this.reset();
  11768. }
  11769. reset() {
  11770. this.cancelRendering();
  11771. this.renderingState = RenderingStates.INITIAL;
  11772. this.div.removeAttribute("data-loaded");
  11773. this.image?.replaceWith(this._placeholderImg);
  11774. this.#updateDims();
  11775. if (this.image) {
  11776. this.image.removeAttribute("src");
  11777. delete this.image;
  11778. }
  11779. }
  11780. update({
  11781. rotation = null
  11782. }) {
  11783. if (typeof rotation === "number") {
  11784. this.rotation = rotation;
  11785. }
  11786. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  11787. this.viewport = this.viewport.clone({
  11788. scale: 1,
  11789. rotation: totalRotation
  11790. });
  11791. this.reset();
  11792. }
  11793. cancelRendering() {
  11794. if (this.renderTask) {
  11795. this.renderTask.cancel();
  11796. this.renderTask = null;
  11797. }
  11798. this.resume = null;
  11799. }
  11800. #getPageDrawContext(upscaleFactor = 1, enableHWA = this.enableHWA) {
  11801. const canvas = document.createElement("canvas");
  11802. const ctx = canvas.getContext("2d", {
  11803. alpha: false,
  11804. willReadFrequently: !enableHWA
  11805. });
  11806. const outputScale = new OutputScale();
  11807. const width = upscaleFactor * this.canvasWidth,
  11808. height = upscaleFactor * this.canvasHeight;
  11809. outputScale.limitCanvas(width, height, this.maxCanvasPixels, this.maxCanvasDim);
  11810. canvas.width = width * outputScale.sx | 0;
  11811. canvas.height = height * outputScale.sy | 0;
  11812. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  11813. return {
  11814. ctx,
  11815. canvas,
  11816. transform
  11817. };
  11818. }
  11819. #convertCanvasToImage(canvas) {
  11820. if (this.renderingState !== RenderingStates.FINISHED) {
  11821. throw new Error("#convertCanvasToImage: Rendering has not finished.");
  11822. }
  11823. const reducedCanvas = this.#reduceImage(canvas);
  11824. const image = document.createElement("img");
  11825. image.className = "thumbnailImage";
  11826. image.setAttribute("data-l10n-id", "pdfjs-thumb-page-canvas");
  11827. image.setAttribute("data-l10n-args", this.#pageL10nArgs);
  11828. image.src = reducedCanvas.toDataURL();
  11829. this.image = image;
  11830. this.div.setAttribute("data-loaded", true);
  11831. this._placeholderImg.replaceWith(image);
  11832. zeroCanvas(reducedCanvas);
  11833. }
  11834. async draw() {
  11835. if (this.renderingState !== RenderingStates.INITIAL) {
  11836. console.error("Must be in new state before drawing");
  11837. return;
  11838. }
  11839. const {
  11840. pageColors,
  11841. pdfPage
  11842. } = this;
  11843. if (!pdfPage) {
  11844. this.renderingState = RenderingStates.FINISHED;
  11845. throw new Error("pdfPage is not loaded");
  11846. }
  11847. this.renderingState = RenderingStates.RUNNING;
  11848. const {
  11849. ctx,
  11850. canvas,
  11851. transform
  11852. } = this.#getPageDrawContext(DRAW_UPSCALE_FACTOR);
  11853. const drawViewport = this.viewport.clone({
  11854. scale: DRAW_UPSCALE_FACTOR * this.scale
  11855. });
  11856. const renderContinueCallback = cont => {
  11857. if (!this.renderingQueue.isHighestPriority(this)) {
  11858. this.renderingState = RenderingStates.PAUSED;
  11859. this.resume = () => {
  11860. this.renderingState = RenderingStates.RUNNING;
  11861. cont();
  11862. };
  11863. return;
  11864. }
  11865. cont();
  11866. };
  11867. const renderContext = {
  11868. canvasContext: ctx,
  11869. transform,
  11870. viewport: drawViewport,
  11871. optionalContentConfigPromise: this._optionalContentConfigPromise,
  11872. pageColors
  11873. };
  11874. const renderTask = this.renderTask = pdfPage.render(renderContext);
  11875. renderTask.onContinue = renderContinueCallback;
  11876. let error = null;
  11877. try {
  11878. await renderTask.promise;
  11879. } catch (e) {
  11880. if (e instanceof RenderingCancelledException) {
  11881. zeroCanvas(canvas);
  11882. return;
  11883. }
  11884. error = e;
  11885. } finally {
  11886. if (renderTask === this.renderTask) {
  11887. this.renderTask = null;
  11888. }
  11889. }
  11890. this.renderingState = RenderingStates.FINISHED;
  11891. this.#convertCanvasToImage(canvas);
  11892. zeroCanvas(canvas);
  11893. this.eventBus.dispatch("thumbnailrendered", {
  11894. source: this,
  11895. pageNumber: this.id,
  11896. pdfPage
  11897. });
  11898. if (error) {
  11899. throw error;
  11900. }
  11901. }
  11902. setImage(pageView) {
  11903. if (this.renderingState !== RenderingStates.INITIAL) {
  11904. return;
  11905. }
  11906. const {
  11907. thumbnailCanvas: canvas,
  11908. pdfPage,
  11909. scale
  11910. } = pageView;
  11911. if (!canvas) {
  11912. return;
  11913. }
  11914. if (!this.pdfPage) {
  11915. this.setPdfPage(pdfPage);
  11916. }
  11917. if (scale < this.scale) {
  11918. return;
  11919. }
  11920. this.renderingState = RenderingStates.FINISHED;
  11921. this.#convertCanvasToImage(canvas);
  11922. }
  11923. #getReducedImageDims(canvas) {
  11924. const width = canvas.width << MAX_NUM_SCALING_STEPS,
  11925. height = canvas.height << MAX_NUM_SCALING_STEPS;
  11926. const outputScale = new OutputScale();
  11927. outputScale.sx = outputScale.sy = 1;
  11928. outputScale.limitCanvas(width, height, this.maxCanvasPixels, this.maxCanvasDim);
  11929. return [width * outputScale.sx | 0, height * outputScale.sy | 0];
  11930. }
  11931. #reduceImage(img) {
  11932. const {
  11933. ctx,
  11934. canvas
  11935. } = this.#getPageDrawContext(1, true);
  11936. if (img.width <= 2 * canvas.width) {
  11937. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  11938. return canvas;
  11939. }
  11940. let [reducedWidth, reducedHeight] = this.#getReducedImageDims(canvas);
  11941. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  11942. while (reducedWidth > img.width || reducedHeight > img.height) {
  11943. reducedWidth >>= 1;
  11944. reducedHeight >>= 1;
  11945. }
  11946. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  11947. while (reducedWidth > 2 * canvas.width) {
  11948. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  11949. reducedWidth >>= 1;
  11950. reducedHeight >>= 1;
  11951. }
  11952. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  11953. return canvas;
  11954. }
  11955. get #pageL10nArgs() {
  11956. return JSON.stringify({
  11957. page: this.pageLabel ?? this.id
  11958. });
  11959. }
  11960. setPageLabel(label) {
  11961. this.pageLabel = typeof label === "string" ? label : null;
  11962. this.anchor.setAttribute("data-l10n-args", this.#pageL10nArgs);
  11963. if (this.renderingState !== RenderingStates.FINISHED) {
  11964. return;
  11965. }
  11966. this.image?.setAttribute("data-l10n-args", this.#pageL10nArgs);
  11967. }
  11968. }
  11969. ;// ./web/pdf_thumbnail_viewer.js
  11970. const THUMBNAIL_SCROLL_MARGIN = -19;
  11971. const THUMBNAIL_SELECTED_CLASS = "selected";
  11972. class PDFThumbnailViewer {
  11973. constructor({
  11974. container,
  11975. eventBus,
  11976. linkService,
  11977. renderingQueue,
  11978. maxCanvasPixels,
  11979. maxCanvasDim,
  11980. pageColors,
  11981. abortSignal,
  11982. enableHWA
  11983. }) {
  11984. this.container = container;
  11985. this.eventBus = eventBus;
  11986. this.linkService = linkService;
  11987. this.renderingQueue = renderingQueue;
  11988. this.maxCanvasPixels = maxCanvasPixels;
  11989. this.maxCanvasDim = maxCanvasDim;
  11990. this.pageColors = pageColors || null;
  11991. this.enableHWA = enableHWA || false;
  11992. this.scroll = watchScroll(this.container, this.#scrollUpdated.bind(this), abortSignal);
  11993. this.#resetView();
  11994. }
  11995. #scrollUpdated() {
  11996. this.renderingQueue.renderHighestPriority();
  11997. }
  11998. getThumbnail(index) {
  11999. return this._thumbnails[index];
  12000. }
  12001. #getVisibleThumbs() {
  12002. return getVisibleElements({
  12003. scrollEl: this.container,
  12004. views: this._thumbnails
  12005. });
  12006. }
  12007. scrollThumbnailIntoView(pageNumber) {
  12008. if (!this.pdfDocument) {
  12009. return;
  12010. }
  12011. const thumbnailView = this._thumbnails[pageNumber - 1];
  12012. if (!thumbnailView) {
  12013. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  12014. return;
  12015. }
  12016. if (pageNumber !== this._currentPageNumber) {
  12017. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  12018. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  12019. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  12020. }
  12021. const {
  12022. first,
  12023. last,
  12024. views
  12025. } = this.#getVisibleThumbs();
  12026. if (views.length > 0) {
  12027. let shouldScroll = false;
  12028. if (pageNumber <= first.id || pageNumber >= last.id) {
  12029. shouldScroll = true;
  12030. } else {
  12031. for (const {
  12032. id,
  12033. percent
  12034. } of views) {
  12035. if (id !== pageNumber) {
  12036. continue;
  12037. }
  12038. shouldScroll = percent < 100;
  12039. break;
  12040. }
  12041. }
  12042. if (shouldScroll) {
  12043. scrollIntoView(thumbnailView.div, {
  12044. top: THUMBNAIL_SCROLL_MARGIN
  12045. });
  12046. }
  12047. }
  12048. this._currentPageNumber = pageNumber;
  12049. }
  12050. get pagesRotation() {
  12051. return this._pagesRotation;
  12052. }
  12053. set pagesRotation(rotation) {
  12054. if (!isValidRotation(rotation)) {
  12055. throw new Error("Invalid thumbnails rotation angle.");
  12056. }
  12057. if (!this.pdfDocument) {
  12058. return;
  12059. }
  12060. if (this._pagesRotation === rotation) {
  12061. return;
  12062. }
  12063. this._pagesRotation = rotation;
  12064. const updateArgs = {
  12065. rotation
  12066. };
  12067. for (const thumbnail of this._thumbnails) {
  12068. thumbnail.update(updateArgs);
  12069. }
  12070. }
  12071. cleanup() {
  12072. for (const thumbnail of this._thumbnails) {
  12073. if (thumbnail.renderingState !== RenderingStates.FINISHED) {
  12074. thumbnail.reset();
  12075. }
  12076. }
  12077. TempImageFactory.destroyCanvas();
  12078. }
  12079. #resetView() {
  12080. this._thumbnails = [];
  12081. this._currentPageNumber = 1;
  12082. this._pageLabels = null;
  12083. this._pagesRotation = 0;
  12084. this.container.textContent = "";
  12085. }
  12086. setDocument(pdfDocument) {
  12087. if (this.pdfDocument) {
  12088. this.#cancelRendering();
  12089. this.#resetView();
  12090. }
  12091. this.pdfDocument = pdfDocument;
  12092. if (!pdfDocument) {
  12093. return;
  12094. }
  12095. const firstPagePromise = pdfDocument.getPage(1);
  12096. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({
  12097. intent: "display"
  12098. });
  12099. firstPagePromise.then(firstPdfPage => {
  12100. const pagesCount = pdfDocument.numPages;
  12101. const viewport = firstPdfPage.getViewport({
  12102. scale: 1
  12103. });
  12104. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  12105. const thumbnail = new PDFThumbnailView({
  12106. container: this.container,
  12107. eventBus: this.eventBus,
  12108. id: pageNum,
  12109. defaultViewport: viewport.clone(),
  12110. optionalContentConfigPromise,
  12111. linkService: this.linkService,
  12112. renderingQueue: this.renderingQueue,
  12113. maxCanvasPixels: this.maxCanvasPixels,
  12114. maxCanvasDim: this.maxCanvasDim,
  12115. pageColors: this.pageColors,
  12116. enableHWA: this.enableHWA
  12117. });
  12118. this._thumbnails.push(thumbnail);
  12119. }
  12120. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  12121. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  12122. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  12123. }).catch(reason => {
  12124. console.error("Unable to initialize thumbnail viewer", reason);
  12125. });
  12126. }
  12127. #cancelRendering() {
  12128. for (const thumbnail of this._thumbnails) {
  12129. thumbnail.cancelRendering();
  12130. }
  12131. }
  12132. setPageLabels(labels) {
  12133. if (!this.pdfDocument) {
  12134. return;
  12135. }
  12136. if (!labels) {
  12137. this._pageLabels = null;
  12138. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  12139. this._pageLabels = null;
  12140. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  12141. } else {
  12142. this._pageLabels = labels;
  12143. }
  12144. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  12145. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  12146. }
  12147. }
  12148. async #ensurePdfPageLoaded(thumbView) {
  12149. if (thumbView.pdfPage) {
  12150. return thumbView.pdfPage;
  12151. }
  12152. try {
  12153. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  12154. if (!thumbView.pdfPage) {
  12155. thumbView.setPdfPage(pdfPage);
  12156. }
  12157. return pdfPage;
  12158. } catch (reason) {
  12159. console.error("Unable to get page for thumb view", reason);
  12160. return null;
  12161. }
  12162. }
  12163. #getScrollAhead(visible) {
  12164. if (visible.first?.id === 1) {
  12165. return true;
  12166. } else if (visible.last?.id === this._thumbnails.length) {
  12167. return false;
  12168. }
  12169. return this.scroll.down;
  12170. }
  12171. forceRendering() {
  12172. const visibleThumbs = this.#getVisibleThumbs();
  12173. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  12174. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead, false, true);
  12175. if (thumbView) {
  12176. this.#ensurePdfPageLoaded(thumbView).then(() => {
  12177. this.renderingQueue.renderView(thumbView);
  12178. });
  12179. return true;
  12180. }
  12181. return false;
  12182. }
  12183. }
  12184. ;// ./web/annotation_editor_layer_builder.js
  12185. class AnnotationEditorLayerBuilder {
  12186. #annotationLayer = null;
  12187. #drawLayer = null;
  12188. #onAppend = null;
  12189. #structTreeLayer = null;
  12190. #textLayer = null;
  12191. #uiManager;
  12192. constructor(options) {
  12193. this.pdfPage = options.pdfPage;
  12194. this.accessibilityManager = options.accessibilityManager;
  12195. this.l10n = options.l10n;
  12196. this.l10n ||= new genericl10n_GenericL10n();
  12197. this.annotationEditorLayer = null;
  12198. this.div = null;
  12199. this._cancelled = false;
  12200. this.#uiManager = options.uiManager;
  12201. this.#annotationLayer = options.annotationLayer || null;
  12202. this.#textLayer = options.textLayer || null;
  12203. this.#drawLayer = options.drawLayer || null;
  12204. this.#onAppend = options.onAppend || null;
  12205. this.#structTreeLayer = options.structTreeLayer || null;
  12206. }
  12207. async render({
  12208. viewport,
  12209. intent = "display"
  12210. }) {
  12211. if (intent !== "display") {
  12212. return;
  12213. }
  12214. if (this._cancelled) {
  12215. return;
  12216. }
  12217. const clonedViewport = viewport.clone({
  12218. dontFlip: true
  12219. });
  12220. if (this.div) {
  12221. this.annotationEditorLayer.update({
  12222. viewport: clonedViewport
  12223. });
  12224. this.show();
  12225. return;
  12226. }
  12227. const div = this.div = document.createElement("div");
  12228. div.className = "annotationEditorLayer";
  12229. div.hidden = true;
  12230. div.dir = this.#uiManager.direction;
  12231. this.#onAppend?.(div);
  12232. this.annotationEditorLayer = new AnnotationEditorLayer({
  12233. uiManager: this.#uiManager,
  12234. div,
  12235. structTreeLayer: this.#structTreeLayer,
  12236. accessibilityManager: this.accessibilityManager,
  12237. pageIndex: this.pdfPage.pageNumber - 1,
  12238. l10n: this.l10n,
  12239. viewport: clonedViewport,
  12240. annotationLayer: this.#annotationLayer,
  12241. textLayer: this.#textLayer,
  12242. drawLayer: this.#drawLayer
  12243. });
  12244. const parameters = {
  12245. viewport: clonedViewport,
  12246. div,
  12247. annotations: null,
  12248. intent
  12249. };
  12250. this.annotationEditorLayer.render(parameters);
  12251. this.show();
  12252. }
  12253. cancel() {
  12254. this._cancelled = true;
  12255. if (!this.div) {
  12256. return;
  12257. }
  12258. this.annotationEditorLayer.destroy();
  12259. }
  12260. hide() {
  12261. if (!this.div) {
  12262. return;
  12263. }
  12264. this.annotationEditorLayer.pause(true);
  12265. this.div.hidden = true;
  12266. }
  12267. show() {
  12268. if (!this.div || this.annotationEditorLayer.isInvisible) {
  12269. return;
  12270. }
  12271. this.div.hidden = false;
  12272. this.annotationEditorLayer.pause(false);
  12273. }
  12274. }
  12275. ;// ./web/annotation_layer_builder.js
  12276. class AnnotationLayerBuilder {
  12277. #annotations = null;
  12278. #externalHide = false;
  12279. #onAppend = null;
  12280. #eventAbortController = null;
  12281. #linksInjected = false;
  12282. constructor({
  12283. pdfPage,
  12284. linkService,
  12285. downloadManager,
  12286. annotationStorage = null,
  12287. imageResourcesPath = "",
  12288. renderForms = true,
  12289. enableScripting = false,
  12290. hasJSActionsPromise = null,
  12291. fieldObjectsPromise = null,
  12292. annotationCanvasMap = null,
  12293. accessibilityManager = null,
  12294. annotationEditorUIManager = null,
  12295. onAppend = null
  12296. }) {
  12297. this.pdfPage = pdfPage;
  12298. this.linkService = linkService;
  12299. this.downloadManager = downloadManager;
  12300. this.imageResourcesPath = imageResourcesPath;
  12301. this.renderForms = renderForms;
  12302. this.annotationStorage = annotationStorage;
  12303. this.enableScripting = enableScripting;
  12304. this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
  12305. this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
  12306. this._annotationCanvasMap = annotationCanvasMap;
  12307. this._accessibilityManager = accessibilityManager;
  12308. this._annotationEditorUIManager = annotationEditorUIManager;
  12309. this.#onAppend = onAppend;
  12310. this.annotationLayer = null;
  12311. this.div = null;
  12312. this._cancelled = false;
  12313. this._eventBus = linkService.eventBus;
  12314. }
  12315. async render({
  12316. viewport,
  12317. intent = "display",
  12318. structTreeLayer = null
  12319. }) {
  12320. if (this.div) {
  12321. if (this._cancelled || !this.annotationLayer) {
  12322. return;
  12323. }
  12324. this.annotationLayer.update({
  12325. viewport: viewport.clone({
  12326. dontFlip: true
  12327. })
  12328. });
  12329. return;
  12330. }
  12331. const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
  12332. intent
  12333. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  12334. if (this._cancelled) {
  12335. return;
  12336. }
  12337. const div = this.div = document.createElement("div");
  12338. div.className = "annotationLayer";
  12339. this.#onAppend?.(div);
  12340. if (annotations.length === 0) {
  12341. this.#annotations = annotations;
  12342. this.hide(true);
  12343. return;
  12344. }
  12345. this.#initAnnotationLayer(viewport, structTreeLayer);
  12346. await this.annotationLayer.render({
  12347. annotations,
  12348. imageResourcesPath: this.imageResourcesPath,
  12349. renderForms: this.renderForms,
  12350. linkService: this.linkService,
  12351. downloadManager: this.downloadManager,
  12352. annotationStorage: this.annotationStorage,
  12353. enableScripting: this.enableScripting,
  12354. hasJSActions,
  12355. fieldObjects
  12356. });
  12357. this.#annotations = annotations;
  12358. if (this.linkService.isInPresentationMode) {
  12359. this.#updatePresentationModeState(PresentationModeState.FULLSCREEN);
  12360. }
  12361. if (!this.#eventAbortController) {
  12362. this.#eventAbortController = new AbortController();
  12363. this._eventBus?._on("presentationmodechanged", evt => {
  12364. this.#updatePresentationModeState(evt.state);
  12365. }, {
  12366. signal: this.#eventAbortController.signal
  12367. });
  12368. }
  12369. }
  12370. #initAnnotationLayer(viewport, structTreeLayer) {
  12371. this.annotationLayer = new AnnotationLayer({
  12372. div: this.div,
  12373. accessibilityManager: this._accessibilityManager,
  12374. annotationCanvasMap: this._annotationCanvasMap,
  12375. annotationEditorUIManager: this._annotationEditorUIManager,
  12376. page: this.pdfPage,
  12377. viewport: viewport.clone({
  12378. dontFlip: true
  12379. }),
  12380. structTreeLayer
  12381. });
  12382. }
  12383. cancel() {
  12384. this._cancelled = true;
  12385. this.#eventAbortController?.abort();
  12386. this.#eventAbortController = null;
  12387. }
  12388. hide(internal = false) {
  12389. this.#externalHide = !internal;
  12390. if (!this.div) {
  12391. return;
  12392. }
  12393. this.div.hidden = true;
  12394. }
  12395. hasEditableAnnotations() {
  12396. return !!this.annotationLayer?.hasEditableAnnotations();
  12397. }
  12398. async injectLinkAnnotations({
  12399. inferredLinks,
  12400. viewport,
  12401. structTreeLayer = null
  12402. }) {
  12403. if (this.#annotations === null) {
  12404. throw new Error("`render` method must be called before `injectLinkAnnotations`.");
  12405. }
  12406. if (this._cancelled || this.#linksInjected) {
  12407. return;
  12408. }
  12409. this.#linksInjected = true;
  12410. const newLinks = this.#annotations.length ? this.#checkInferredLinks(inferredLinks) : inferredLinks;
  12411. if (!newLinks.length) {
  12412. return;
  12413. }
  12414. if (!this.annotationLayer) {
  12415. this.#initAnnotationLayer(viewport, structTreeLayer);
  12416. setLayerDimensions(this.div, viewport);
  12417. }
  12418. await this.annotationLayer.addLinkAnnotations(newLinks, this.linkService);
  12419. if (!this.#externalHide) {
  12420. this.div.hidden = false;
  12421. }
  12422. }
  12423. #updatePresentationModeState(state) {
  12424. if (!this.div) {
  12425. return;
  12426. }
  12427. let disableFormElements = false;
  12428. switch (state) {
  12429. case PresentationModeState.FULLSCREEN:
  12430. disableFormElements = true;
  12431. break;
  12432. case PresentationModeState.NORMAL:
  12433. break;
  12434. default:
  12435. return;
  12436. }
  12437. for (const section of this.div.childNodes) {
  12438. if (section.hasAttribute("data-internal-link")) {
  12439. continue;
  12440. }
  12441. section.inert = disableFormElements;
  12442. }
  12443. }
  12444. #checkInferredLinks(inferredLinks) {
  12445. function annotationRects(annot) {
  12446. if (!annot.quadPoints) {
  12447. return [annot.rect];
  12448. }
  12449. const rects = [];
  12450. for (let i = 2, ii = annot.quadPoints.length; i < ii; i += 8) {
  12451. const trX = annot.quadPoints[i];
  12452. const trY = annot.quadPoints[i + 1];
  12453. const blX = annot.quadPoints[i + 2];
  12454. const blY = annot.quadPoints[i + 3];
  12455. rects.push([blX, blY, trX, trY]);
  12456. }
  12457. return rects;
  12458. }
  12459. function intersectAnnotations(annot1, annot2) {
  12460. const intersections = [];
  12461. const annot1Rects = annotationRects(annot1);
  12462. const annot2Rects = annotationRects(annot2);
  12463. for (const rect1 of annot1Rects) {
  12464. for (const rect2 of annot2Rects) {
  12465. const intersection = Util.intersect(rect1, rect2);
  12466. if (intersection) {
  12467. intersections.push(intersection);
  12468. }
  12469. }
  12470. }
  12471. return intersections;
  12472. }
  12473. function areaRects(rects) {
  12474. let totalArea = 0;
  12475. for (const rect of rects) {
  12476. totalArea += Math.abs((rect[2] - rect[0]) * (rect[3] - rect[1]));
  12477. }
  12478. return totalArea;
  12479. }
  12480. return inferredLinks.filter(link => {
  12481. let linkAreaRects;
  12482. for (const annotation of this.#annotations) {
  12483. if (annotation.annotationType !== AnnotationType.LINK || !annotation.url) {
  12484. continue;
  12485. }
  12486. const intersections = intersectAnnotations(annotation, link);
  12487. if (intersections.length === 0) {
  12488. continue;
  12489. }
  12490. linkAreaRects ??= areaRects(annotationRects(link));
  12491. if (areaRects(intersections) / linkAreaRects > 0.5) {
  12492. return false;
  12493. }
  12494. }
  12495. return true;
  12496. });
  12497. }
  12498. }
  12499. // EXTERNAL MODULE: ./node_modules/core-js/modules/web.url.can-parse.js
  12500. var web_url_can_parse = __webpack_require__(2222);
  12501. ;// ./web/autolinker.js
  12502. function DOMRectToPDF({
  12503. width,
  12504. height,
  12505. left,
  12506. top
  12507. }, pdfPageView) {
  12508. if (width === 0 || height === 0) {
  12509. return null;
  12510. }
  12511. const pageBox = pdfPageView.textLayer.div.getBoundingClientRect();
  12512. const bottomLeft = pdfPageView.getPagePoint(left - pageBox.left, top - pageBox.top);
  12513. const topRight = pdfPageView.getPagePoint(left - pageBox.left + width, top - pageBox.top + height);
  12514. return Util.normalizeRect([bottomLeft[0], bottomLeft[1], topRight[0], topRight[1]]);
  12515. }
  12516. function calculateLinkPosition(range, pdfPageView) {
  12517. const rangeRects = range.getClientRects();
  12518. if (rangeRects.length === 1) {
  12519. return {
  12520. rect: DOMRectToPDF(rangeRects[0], pdfPageView)
  12521. };
  12522. }
  12523. const rect = [Infinity, Infinity, -Infinity, -Infinity];
  12524. const quadPoints = [];
  12525. let i = 0;
  12526. for (const domRect of rangeRects) {
  12527. const normalized = DOMRectToPDF(domRect, pdfPageView);
  12528. if (normalized === null) {
  12529. continue;
  12530. }
  12531. quadPoints[i] = quadPoints[i + 4] = normalized[0];
  12532. quadPoints[i + 1] = quadPoints[i + 3] = normalized[3];
  12533. quadPoints[i + 2] = quadPoints[i + 6] = normalized[2];
  12534. quadPoints[i + 5] = quadPoints[i + 7] = normalized[1];
  12535. Util.rectBoundingBox(...normalized, rect);
  12536. i += 8;
  12537. }
  12538. return {
  12539. quadPoints,
  12540. rect
  12541. };
  12542. }
  12543. function textPosition(container, offset) {
  12544. let currentContainer = container;
  12545. do {
  12546. if (currentContainer.nodeType === Node.TEXT_NODE) {
  12547. const currentLength = currentContainer.textContent.length;
  12548. if (offset <= currentLength) {
  12549. return [currentContainer, offset];
  12550. }
  12551. offset -= currentLength;
  12552. } else if (currentContainer.firstChild) {
  12553. currentContainer = currentContainer.firstChild;
  12554. continue;
  12555. }
  12556. while (!currentContainer.nextSibling && currentContainer !== container) {
  12557. currentContainer = currentContainer.parentNode;
  12558. }
  12559. if (currentContainer !== container) {
  12560. currentContainer = currentContainer.nextSibling;
  12561. }
  12562. } while (currentContainer !== container);
  12563. throw new Error("Offset is bigger than container's contents length.");
  12564. }
  12565. function createLinkAnnotation({
  12566. url,
  12567. index,
  12568. length
  12569. }, pdfPageView, id) {
  12570. const highlighter = pdfPageView._textHighlighter;
  12571. const [{
  12572. begin,
  12573. end
  12574. }] = highlighter._convertMatches([index], [length]);
  12575. const range = new Range();
  12576. range.setStart(...textPosition(highlighter.textDivs[begin.divIdx], begin.offset));
  12577. range.setEnd(...textPosition(highlighter.textDivs[end.divIdx], end.offset));
  12578. return {
  12579. id: `inferred_link_${id}`,
  12580. unsafeUrl: url,
  12581. url,
  12582. annotationType: AnnotationType.LINK,
  12583. rotation: 0,
  12584. ...calculateLinkPosition(range, pdfPageView),
  12585. borderStyle: null
  12586. };
  12587. }
  12588. class Autolinker {
  12589. static #index = 0;
  12590. static #regex;
  12591. static findLinks(text) {
  12592. this.#regex ??= /\b(?:https?:\/\/|mailto:|www\.)(?:[\0-\x08\x0E-\x1F\$\+0-9=A-Z\^`-z\|~-\x9F\xA2-\xA6\xA8-\xAA\xAC-\xB5\xB8-\xBA\xBC-\xBE\xC0-\u037D\u037F-\u0386\u0388-\u0559\u0560-\u0588\u058B-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7-\u05F2\u05F5-\u0608\u060B\u060E-\u061A\u061C\u0620-\u0669\u066E-\u06D3\u06D5-\u06FF\u070E-\u07F6\u07FA-\u082F\u083F-\u085D\u085F-\u0963\u0966-\u096F\u0971-\u09FC\u09FE-\u0A75\u0A77-\u0AEF\u0AF1-\u0C76\u0C78-\u0C83\u0C85-\u0DF3\u0DF5-\u0E4E\u0E50-\u0E59\u0E5C-\u0F03\u0F13\u0F15-\u0F39\u0F3E-\u0F84\u0F86-\u0FCF\u0FD5-\u0FD8\u0FDB-\u1049\u1050-\u10FA\u10FC-\u135F\u1369-\u13FF\u1401-\u166D\u166F-\u167F\u1681-\u169A\u169D-\u16EA\u16EE-\u1734\u1737-\u17D3\u17D7\u17DB-\u17FF\u180B-\u1943\u1946-\u1A1D\u1A20-\u1A9F\u1AA7\u1AAE-\u1B4D\u1B50-\u1B59\u1B61-\u1B7C\u1B80-\u1BFB\u1C00-\u1C3A\u1C40-\u1C7D\u1C80-\u1CBF\u1CC8-\u1CD2\u1CD4-\u1FFF\u200B-\u200F\u202A-\u202E\u2044\u2052\u2060-\u207C\u207F-\u208C\u208F-\u2307\u230C-\u2328\u232B-\u2767\u2776-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2CF8\u2CFD\u2D00-\u2D6F\u2D71-\u2DFF\u2E2F\u2E50\u2E51\u2E5E-\u2FFF\u3004-\u3007\u3012\u3013\u3020-\u302F\u3031-\u303C\u303E-\u309F\u30A1-\u30FA\u30FC-\uA4FD\uA500-\uA60C\uA610-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA6F8-\uA873\uA878-\uA8CD\uA8D0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA95E\uA960-\uA9C0\uA9CE-\uA9DD\uA9E0-\uAA5B\uAA60-\uAADD\uAAE0-\uAAEF\uAAF2-\uABEA\uABEC-\uFD3D\uFD40-\uFE0F\uFE1A-\uFE2F\uFE53\uFE62\uFE64-\uFE67\uFE69\uFE6C-\uFEFE\uFF00\uFF04\uFF0B\uFF10-\uFF19\uFF1C-\uFF1E\uFF21-\uFF3A\uFF3E\uFF40-\uFF5A\uFF5C\uFF5E\uFF66-\u{100FF}\u{10103}-\u{1039E}\u{103A0}-\u{103CF}\u{103D1}-\u{1056E}\u{10570}-\u{10856}\u{10858}-\u{1091E}\u{10920}-\u{1093E}\u{10940}-\u{10A4F}\u{10A59}-\u{10A7E}\u{10A80}-\u{10AEF}\u{10AF7}-\u{10B38}\u{10B40}-\u{10B98}\u{10B9D}-\u{10D6D}\u{10D6F}-\u{10EAC}\u{10EAE}-\u{10F54}\u{10F5A}-\u{10F85}\u{10F8A}-\u{11046}\u{1104E}-\u{110BA}\u{110BD}\u{110C2}-\u{1113F}\u{11144}-\u{11173}\u{11176}-\u{111C4}\u{111C9}-\u{111CC}\u{111CE}-\u{111DA}\u{111DC}\u{111E0}-\u{11237}\u{1123E}-\u{112A8}\u{112AA}-\u{113D3}\u{113D6}\u{113D9}-\u{1144A}\u{11450}-\u{11459}\u{1145C}\u{1145E}-\u{114C5}\u{114C7}-\u{115C0}\u{115D8}-\u{11640}\u{11644}-\u{1165F}\u{1166D}-\u{116B8}\u{116BA}-\u{1173B}\u{1173F}-\u{1183A}\u{1183C}-\u{11943}\u{11947}-\u{119E1}\u{119E3}-\u{11A3E}\u{11A47}-\u{11A99}\u{11A9D}\u{11AA3}-\u{11AFF}\u{11B0A}-\u{11BE0}\u{11BE2}-\u{11C40}\u{11C46}-\u{11C6F}\u{11C72}-\u{11EF6}\u{11EF9}-\u{11F42}\u{11F50}-\u{11FFE}\u{12000}-\u{1246F}\u{12475}-\u{12FF0}\u{12FF3}-\u{16A6D}\u{16A70}-\u{16AF4}\u{16AF6}-\u{16B36}\u{16B3C}-\u{16B43}\u{16B45}-\u{16D6C}\u{16D70}-\u{16E96}\u{16E9B}-\u{16FE1}\u{16FE3}-\u{1BC9E}\u{1BCA0}-\u{1DA86}\u{1DA8C}-\u{1E5FE}\u{1E600}-\u{1E95D}\u{1E960}-\u{10FFFF}]|\/|[\0-\x08\x0E-\x1F!-Z\\\^-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uFEFE\uFF00-\u{10FFFF}]+[\0-\x08\x0E-\x1F\$\+0-9=A-Z\^`-z\|~-\x9F\xA2-\xA6\xA8-\xAA\xAC-\xB5\xB8-\xBA\xBC-\xBE\xC0-\u037D\u037F-\u0386\u0388-\u0559\u0560-\u0588\u058B-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7-\u05F2\u05F5-\u0608\u060B\u060E-\u061A\u061C\u0620-\u0669\u066E-\u06D3\u06D5-\u06FF\u070E-\u07F6\u07FA-\u082F\u083F-\u085D\u085F-\u0963\u0966-\u096F\u0971-\u09FC\u09FE-\u0A75\u0A77-\u0AEF\u0AF1-\u0C76\u0C78-\u0C83\u0C85-\u0DF3\u0DF5-\u0E4E\u0E50-\u0E59\u0E5C-\u0F03\u0F13\u0F15-\u0F39\u0F3E-\u0F84\u0F86-\u0FCF\u0FD5-\u0FD8\u0FDB-\u1049\u1050-\u10FA\u10FC-\u135F\u1369-\u13FF\u1401-\u166D\u166F-\u167F\u1681-\u169A\u169D-\u16EA\u16EE-\u1734\u1737-\u17D3\u17D7\u17DB-\u17FF\u180B-\u1943\u1946-\u1A1D\u1A20-\u1A9F\u1AA7\u1AAE-\u1B4D\u1B50-\u1B59\u1B61-\u1B7C\u1B80-\u1BFB\u1C00-\u1C3A\u1C40-\u1C7D\u1C80-\u1CBF\u1CC8-\u1CD2\u1CD4-\u1FFF\u200B-\u200F\u202A-\u202E\u2044\u2052\u2060-\u207C\u207F-\u208C\u208F-\u2307\u230C-\u2328\u232B-\u2767\u2776-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2CF8\u2CFD\u2D00-\u2D6F\u2D71-\u2DFF\u2E2F\u2E50\u2E51\u2E5E-\u2FFF\u3004-\u3007\u3012\u3013\u3020-\u302F\u3031-\u303C\u303E-\u309F\u30A1-\u30FA\u30FC-\uA4FD\uA500-\uA60C\uA610-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA6F8-\uA873\uA878-\uA8CD\uA8D0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA95E\uA960-\uA9C0\uA9CE-\uA9DD\uA9E0-\uAA5B\uAA60-\uAADD\uAAE0-\uAAEF\uAAF2-\uABEA\uABEC-\uFD3D\uFD40-\uFE0F\uFE1A-\uFE2F\uFE53\uFE62\uFE64-\uFE67\uFE69\uFE6C-\uFEFE\uFF00\uFF04\uFF0B\uFF10-\uFF19\uFF1C-\uFF1E\uFF21-\uFF3A\uFF3E\uFF40-\uFF5A\uFF5C\uFF5E\uFF66-\u{100FF}\u{10103}-\u{1039E}\u{103A0}-\u{103CF}\u{103D1}-\u{1056E}\u{10570}-\u{10856}\u{10858}-\u{1091E}\u{10920}-\u{1093E}\u{10940}-\u{10A4F}\u{10A59}-\u{10A7E}\u{10A80}-\u{10AEF}\u{10AF7}-\u{10B38}\u{10B40}-\u{10B98}\u{10B9D}-\u{10D6D}\u{10D6F}-\u{10EAC}\u{10EAE}-\u{10F54}\u{10F5A}-\u{10F85}\u{10F8A}-\u{11046}\u{1104E}-\u{110BA}\u{110BD}\u{110C2}-\u{1113F}\u{11144}-\u{11173}\u{11176}-\u{111C4}\u{111C9}-\u{111CC}\u{111CE}-\u{111DA}\u{111DC}\u{111E0}-\u{11237}\u{1123E}-\u{112A8}\u{112AA}-\u{113D3}\u{113D6}\u{113D9}-\u{1144A}\u{11450}-\u{11459}\u{1145C}\u{1145E}-\u{114C5}\u{114C7}-\u{115C0}\u{115D8}-\u{11640}\u{11644}-\u{1165F}\u{1166D}-\u{116B8}\u{116BA}-\u{1173B}\u{1173F}-\u{1183A}\u{1183C}-\u{11943}\u{11947}-\u{119E1}\u{119E3}-\u{11A3E}\u{11A47}-\u{11A99}\u{11A9D}\u{11AA3}-\u{11AFF}\u{11B0A}-\u{11BE0}\u{11BE2}-\u{11C40}\u{11C46}-\u{11C6F}\u{11C72}-\u{11EF6}\u{11EF9}-\u{11F42}\u{11F50}-\u{11FFE}\u{12000}-\u{1246F}\u{12475}-\u{12FF0}\u{12FF3}-\u{16A6D}\u{16A70}-\u{16AF4}\u{16AF6}-\u{16B36}\u{16B3C}-\u{16B43}\u{16B45}-\u{16D6C}\u{16D70}-\u{16E96}\u{16E9B}-\u{16FE1}\u{16FE3}-\u{1BC9E}\u{1BCA0}-\u{1DA86}\u{1DA8C}-\u{1E5FE}\u{1E600}-\u{1E95D}\u{1E960}-\u{10FFFF}])+|\b[\0-\x08\x0E-\x1F!-'\*-;=\?A-Z\\\^-z\|~-\x9F\xA1-\u0F39\u0F3E-\u167F\u1681-\u169A\u169D-\u1FFF\u200B-\u2019\u201B-\u201D\u201F-\u2027\u202A-\u202E\u2030-\u2044\u2047-\u205E\u2060-\u207C\u207F-\u208C\u208F-\u2307\u230C-\u2328\u232B-\u2767\u2776-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2E21\u2E2A-\u2E41\u2E43-\u2E54\u2E5D-\u2FFF\u3001-\u3007\u3012\u3013\u301C\u3020-\uFD3D\uFD40-\uFE16\uFE19-\uFE34\uFE45\uFE46\uFE49-\uFE58\uFE5F-\uFEFE\uFF00-\uFF07\uFF0A-\uFF3A\uFF3C\uFF3E-\uFF5A\uFF5C\uFF5E\uFF61\uFF64-\u{10FFFF}]+@([\0-\x08\x0E-\x1F\$\+0-9=A-Z\^`-z\|~-\x9F\xA2-\xA6\xA8-\xAA\xAC-\xB5\xB8-\xBA\xBC-\xBE\xC0-\u037D\u037F-\u0386\u0388-\u0559\u0560-\u0588\u058B-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7-\u05F2\u05F5-\u0608\u060B\u060E-\u061A\u061C\u0620-\u0669\u066E-\u06D3\u06D5-\u06FF\u070E-\u07F6\u07FA-\u082F\u083F-\u085D\u085F-\u0963\u0966-\u096F\u0971-\u09FC\u09FE-\u0A75\u0A77-\u0AEF\u0AF1-\u0C76\u0C78-\u0C83\u0C85-\u0DF3\u0DF5-\u0E4E\u0E50-\u0E59\u0E5C-\u0F03\u0F13\u0F15-\u0F39\u0F3E-\u0F84\u0F86-\u0FCF\u0FD5-\u0FD8\u0FDB-\u1049\u1050-\u10FA\u10FC-\u135F\u1369-\u13FF\u1401-\u166D\u166F-\u167F\u1681-\u169A\u169D-\u16EA\u16EE-\u1734\u1737-\u17D3\u17D7\u17DB-\u17FF\u180B-\u1943\u1946-\u1A1D\u1A20-\u1A9F\u1AA7\u1AAE-\u1B4D\u1B50-\u1B59\u1B61-\u1B7C\u1B80-\u1BFB\u1C00-\u1C3A\u1C40-\u1C7D\u1C80-\u1CBF\u1CC8-\u1CD2\u1CD4-\u1FFF\u200B-\u200F\u202A-\u202E\u2044\u2052\u2060-\u207C\u207F-\u208C\u208F-\u2307\u230C-\u2328\u232B-\u2767\u2776-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2CF8\u2CFD\u2D00-\u2D6F\u2D71-\u2DFF\u2E2F\u2E50\u2E51\u2E5E-\u2FFF\u3004-\u3007\u3012\u3013\u3020-\u302F\u3031-\u303C\u303E-\u309F\u30A1-\u30FA\u30FC-\uA4FD\uA500-\uA60C\uA610-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA6F8-\uA873\uA878-\uA8CD\uA8D0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA95E\uA960-\uA9C0\uA9CE-\uA9DD\uA9E0-\uAA5B\uAA60-\uAADD\uAAE0-\uAAEF\uAAF2-\uABEA\uABEC-\uFD3D\uFD40-\uFE0F\uFE1A-\uFE2F\uFE53\uFE62\uFE64-\uFE67\uFE69\uFE6C-\uFEFE\uFF00\uFF04\uFF0B\uFF10-\uFF19\uFF1C-\uFF1E\uFF21-\uFF3A\uFF3E\uFF40-\uFF5A\uFF5C\uFF5E\uFF66-\u{100FF}\u{10103}-\u{1039E}\u{103A0}-\u{103CF}\u{103D1}-\u{1056E}\u{10570}-\u{10856}\u{10858}-\u{1091E}\u{10920}-\u{1093E}\u{10940}-\u{10A4F}\u{10A59}-\u{10A7E}\u{10A80}-\u{10AEF}\u{10AF7}-\u{10B38}\u{10B40}-\u{10B98}\u{10B9D}-\u{10D6D}\u{10D6F}-\u{10EAC}\u{10EAE}-\u{10F54}\u{10F5A}-\u{10F85}\u{10F8A}-\u{11046}\u{1104E}-\u{110BA}\u{110BD}\u{110C2}-\u{1113F}\u{11144}-\u{11173}\u{11176}-\u{111C4}\u{111C9}-\u{111CC}\u{111CE}-\u{111DA}\u{111DC}\u{111E0}-\u{11237}\u{1123E}-\u{112A8}\u{112AA}-\u{113D3}\u{113D6}\u{113D9}-\u{1144A}\u{11450}-\u{11459}\u{1145C}\u{1145E}-\u{114C5}\u{114C7}-\u{115C0}\u{115D8}-\u{11640}\u{11644}-\u{1165F}\u{1166D}-\u{116B8}\u{116BA}-\u{1173B}\u{1173F}-\u{1183A}\u{1183C}-\u{11943}\u{11947}-\u{119E1}\u{119E3}-\u{11A3E}\u{11A47}-\u{11A99}\u{11A9D}\u{11AA3}-\u{11AFF}\u{11B0A}-\u{11BE0}\u{11BE2}-\u{11C40}\u{11C46}-\u{11C6F}\u{11C72}-\u{11EF6}\u{11EF9}-\u{11F42}\u{11F50}-\u{11FFE}\u{12000}-\u{1246F}\u{12475}-\u{12FF0}\u{12FF3}-\u{16A6D}\u{16A70}-\u{16AF4}\u{16AF6}-\u{16B36}\u{16B3C}-\u{16B43}\u{16B45}-\u{16D6C}\u{16D70}-\u{16E96}\u{16E9B}-\u{16FE1}\u{16FE3}-\u{1BC9E}\u{1BCA0}-\u{1DA86}\u{1DA8C}-\u{1E5FE}\u{1E600}-\u{1E95D}\u{1E960}-\u{10FFFF}]+(?:\.[\0-\x08\x0E-\x1F\$\+0-9=A-Z\^`-z\|~-\x9F\xA2-\xA6\xA8-\xAA\xAC-\xB5\xB8-\xBA\xBC-\xBE\xC0-\u037D\u037F-\u0386\u0388-\u0559\u0560-\u0588\u058B-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7-\u05F2\u05F5-\u0608\u060B\u060E-\u061A\u061C\u0620-\u0669\u066E-\u06D3\u06D5-\u06FF\u070E-\u07F6\u07FA-\u082F\u083F-\u085D\u085F-\u0963\u0966-\u096F\u0971-\u09FC\u09FE-\u0A75\u0A77-\u0AEF\u0AF1-\u0C76\u0C78-\u0C83\u0C85-\u0DF3\u0DF5-\u0E4E\u0E50-\u0E59\u0E5C-\u0F03\u0F13\u0F15-\u0F39\u0F3E-\u0F84\u0F86-\u0FCF\u0FD5-\u0FD8\u0FDB-\u1049\u1050-\u10FA\u10FC-\u135F\u1369-\u13FF\u1401-\u166D\u166F-\u167F\u1681-\u169A\u169D-\u16EA\u16EE-\u1734\u1737-\u17D3\u17D7\u17DB-\u17FF\u180B-\u1943\u1946-\u1A1D\u1A20-\u1A9F\u1AA7\u1AAE-\u1B4D\u1B50-\u1B59\u1B61-\u1B7C\u1B80-\u1BFB\u1C00-\u1C3A\u1C40-\u1C7D\u1C80-\u1CBF\u1CC8-\u1CD2\u1CD4-\u1FFF\u200B-\u200F\u202A-\u202E\u2044\u2052\u2060-\u207C\u207F-\u208C\u208F-\u2307\u230C-\u2328\u232B-\u2767\u2776-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2CF8\u2CFD\u2D00-\u2D6F\u2D71-\u2DFF\u2E2F\u2E50\u2E51\u2E5E-\u2FFF\u3004-\u3007\u3012\u3013\u3020-\u302F\u3031-\u303C\u303E-\u309F\u30A1-\u30FA\u30FC-\uA4FD\uA500-\uA60C\uA610-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA6F8-\uA873\uA878-\uA8CD\uA8D0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA95E\uA960-\uA9C0\uA9CE-\uA9DD\uA9E0-\uAA5B\uAA60-\uAADD\uAAE0-\uAAEF\uAAF2-\uABEA\uABEC-\uFD3D\uFD40-\uFE0F\uFE1A-\uFE2F\uFE53\uFE62\uFE64-\uFE67\uFE69\uFE6C-\uFEFE\uFF00\uFF04\uFF0B\uFF10-\uFF19\uFF1C-\uFF1E\uFF21-\uFF3A\uFF3E\uFF40-\uFF5A\uFF5C\uFF5E\uFF66-\u{100FF}\u{10103}-\u{1039E}\u{103A0}-\u{103CF}\u{103D1}-\u{1056E}\u{10570}-\u{10856}\u{10858}-\u{1091E}\u{10920}-\u{1093E}\u{10940}-\u{10A4F}\u{10A59}-\u{10A7E}\u{10A80}-\u{10AEF}\u{10AF7}-\u{10B38}\u{10B40}-\u{10B98}\u{10B9D}-\u{10D6D}\u{10D6F}-\u{10EAC}\u{10EAE}-\u{10F54}\u{10F5A}-\u{10F85}\u{10F8A}-\u{11046}\u{1104E}-\u{110BA}\u{110BD}\u{110C2}-\u{1113F}\u{11144}-\u{11173}\u{11176}-\u{111C4}\u{111C9}-\u{111CC}\u{111CE}-\u{111DA}\u{111DC}\u{111E0}-\u{11237}\u{1123E}-\u{112A8}\u{112AA}-\u{113D3}\u{113D6}\u{113D9}-\u{1144A}\u{11450}-\u{11459}\u{1145C}\u{1145E}-\u{114C5}\u{114C7}-\u{115C0}\u{115D8}-\u{11640}\u{11644}-\u{1165F}\u{1166D}-\u{116B8}\u{116BA}-\u{1173B}\u{1173F}-\u{1183A}\u{1183C}-\u{11943}\u{11947}-\u{119E1}\u{119E3}-\u{11A3E}\u{11A47}-\u{11A99}\u{11A9D}\u{11AA3}-\u{11AFF}\u{11B0A}-\u{11BE0}\u{11BE2}-\u{11C40}\u{11C46}-\u{11C6F}\u{11C72}-\u{11EF6}\u{11EF9}-\u{11F42}\u{11F50}-\u{11FFE}\u{12000}-\u{1246F}\u{12475}-\u{12FF0}\u{12FF3}-\u{16A6D}\u{16A70}-\u{16AF4}\u{16AF6}-\u{16B36}\u{16B3C}-\u{16B43}\u{16B45}-\u{16D6C}\u{16D70}-\u{16E96}\u{16E9B}-\u{16FE1}\u{16FE3}-\u{1BC9E}\u{1BCA0}-\u{1DA86}\u{1DA8C}-\u{1E5FE}\u{1E600}-\u{1E95D}\u{1E960}-\u{10FFFF}]+)+)/gmu;
  12593. const [normalizedText, diffs] = normalize(text);
  12594. const matches = normalizedText.matchAll(this.#regex);
  12595. const links = [];
  12596. for (const match of matches) {
  12597. const [url, emailDomain] = match;
  12598. let raw;
  12599. if (url.startsWith("www.") || url.startsWith("http://") || url.startsWith("https://")) {
  12600. raw = url;
  12601. } else if (URL.canParse(`http://${emailDomain}`)) {
  12602. raw = url.startsWith("mailto:") ? url : `mailto:${url}`;
  12603. } else {
  12604. continue;
  12605. }
  12606. const absoluteURL = createValidAbsoluteUrl(raw, null, {
  12607. addDefaultProtocol: true
  12608. });
  12609. if (absoluteURL) {
  12610. const [index, length] = getOriginalIndex(diffs, match.index, url.length);
  12611. links.push({
  12612. url: absoluteURL.href,
  12613. index,
  12614. length
  12615. });
  12616. }
  12617. }
  12618. return links;
  12619. }
  12620. static processLinks(pdfPageView) {
  12621. return this.findLinks(pdfPageView._textHighlighter.textContentItemsStr.join("\n")).map(link => createLinkAnnotation(link, pdfPageView, this.#index++));
  12622. }
  12623. }
  12624. ;// ./web/base_pdf_page_view.js
  12625. class BasePDFPageView {
  12626. #enableHWA = false;
  12627. #loadingId = null;
  12628. #minDurationToUpdateCanvas = 0;
  12629. #renderError = null;
  12630. #renderingState = RenderingStates.INITIAL;
  12631. #showCanvas = null;
  12632. #startTime = 0;
  12633. #tempCanvas = null;
  12634. canvas = null;
  12635. div = null;
  12636. eventBus = null;
  12637. id = null;
  12638. pageColors = null;
  12639. renderingQueue = null;
  12640. renderTask = null;
  12641. resume = null;
  12642. constructor(options) {
  12643. this.#enableHWA = #enableHWA in options ? options.#enableHWA : options.enableHWA || false;
  12644. this.eventBus = options.eventBus;
  12645. this.id = options.id;
  12646. this.pageColors = options.pageColors || null;
  12647. this.renderingQueue = options.renderingQueue;
  12648. this.#minDurationToUpdateCanvas = options.minDurationToUpdateCanvas ?? 500;
  12649. }
  12650. get renderingState() {
  12651. return this.#renderingState;
  12652. }
  12653. set renderingState(state) {
  12654. if (state === this.#renderingState) {
  12655. return;
  12656. }
  12657. this.#renderingState = state;
  12658. if (this.#loadingId) {
  12659. clearTimeout(this.#loadingId);
  12660. this.#loadingId = null;
  12661. }
  12662. switch (state) {
  12663. case RenderingStates.PAUSED:
  12664. this.div.classList.remove("loading");
  12665. this.#startTime = 0;
  12666. this.#showCanvas?.(false);
  12667. break;
  12668. case RenderingStates.RUNNING:
  12669. this.div.classList.add("loadingIcon");
  12670. this.#loadingId = setTimeout(() => {
  12671. this.div.classList.add("loading");
  12672. this.#loadingId = null;
  12673. }, 0);
  12674. this.#startTime = Date.now();
  12675. break;
  12676. case RenderingStates.INITIAL:
  12677. case RenderingStates.FINISHED:
  12678. this.div.classList.remove("loadingIcon", "loading");
  12679. this.#startTime = 0;
  12680. break;
  12681. }
  12682. }
  12683. _createCanvas(onShow, hideUntilComplete = false) {
  12684. const {
  12685. pageColors
  12686. } = this;
  12687. const hasHCM = !!(pageColors?.background && pageColors?.foreground);
  12688. const prevCanvas = this.canvas;
  12689. const updateOnFirstShow = !prevCanvas && !hasHCM && !hideUntilComplete;
  12690. let canvas = this.canvas = document.createElement("canvas");
  12691. this.#showCanvas = isLastShow => {
  12692. if (updateOnFirstShow) {
  12693. let tempCanvas = this.#tempCanvas;
  12694. if (!isLastShow && this.#minDurationToUpdateCanvas > 0) {
  12695. if (Date.now() - this.#startTime < this.#minDurationToUpdateCanvas) {
  12696. return;
  12697. }
  12698. if (!tempCanvas) {
  12699. tempCanvas = this.#tempCanvas = canvas;
  12700. canvas = this.canvas = canvas.cloneNode(false);
  12701. onShow(canvas);
  12702. }
  12703. }
  12704. if (tempCanvas) {
  12705. const ctx = canvas.getContext("2d", {
  12706. alpha: false
  12707. });
  12708. ctx.drawImage(tempCanvas, 0, 0);
  12709. if (isLastShow) {
  12710. this.#resetTempCanvas();
  12711. } else {
  12712. this.#startTime = Date.now();
  12713. }
  12714. return;
  12715. }
  12716. onShow(canvas);
  12717. this.#showCanvas = null;
  12718. return;
  12719. }
  12720. if (!isLastShow) {
  12721. return;
  12722. }
  12723. if (prevCanvas) {
  12724. prevCanvas.replaceWith(canvas);
  12725. prevCanvas.width = prevCanvas.height = 0;
  12726. } else {
  12727. onShow(canvas);
  12728. }
  12729. };
  12730. const ctx = canvas.getContext("2d", {
  12731. alpha: false,
  12732. willReadFrequently: !this.#enableHWA
  12733. });
  12734. return {
  12735. canvas,
  12736. prevCanvas,
  12737. ctx
  12738. };
  12739. }
  12740. #renderContinueCallback = cont => {
  12741. this.#showCanvas?.(false);
  12742. if (this.renderingQueue && !this.renderingQueue.isHighestPriority(this)) {
  12743. this.renderingState = RenderingStates.PAUSED;
  12744. this.resume = () => {
  12745. this.renderingState = RenderingStates.RUNNING;
  12746. cont();
  12747. };
  12748. return;
  12749. }
  12750. cont();
  12751. };
  12752. _resetCanvas() {
  12753. const {
  12754. canvas
  12755. } = this;
  12756. if (!canvas) {
  12757. return;
  12758. }
  12759. canvas.remove();
  12760. canvas.width = canvas.height = 0;
  12761. this.canvas = null;
  12762. this.#resetTempCanvas();
  12763. }
  12764. #resetTempCanvas() {
  12765. if (this.#tempCanvas) {
  12766. this.#tempCanvas.width = this.#tempCanvas.height = 0;
  12767. this.#tempCanvas = null;
  12768. }
  12769. }
  12770. async _drawCanvas(options, onCancel, onFinish) {
  12771. const renderTask = this.renderTask = this.pdfPage.render(options);
  12772. renderTask.onContinue = this.#renderContinueCallback;
  12773. renderTask.onError = error => {
  12774. if (error instanceof RenderingCancelledException) {
  12775. onCancel();
  12776. this.#renderError = null;
  12777. }
  12778. };
  12779. let error = null;
  12780. try {
  12781. await renderTask.promise;
  12782. this.#showCanvas?.(true);
  12783. } catch (e) {
  12784. if (e instanceof RenderingCancelledException) {
  12785. return;
  12786. }
  12787. error = e;
  12788. this.#showCanvas?.(true);
  12789. } finally {
  12790. this.#renderError = error;
  12791. if (renderTask === this.renderTask) {
  12792. this.renderTask = null;
  12793. }
  12794. }
  12795. this.renderingState = RenderingStates.FINISHED;
  12796. onFinish(renderTask);
  12797. if (error) {
  12798. throw error;
  12799. }
  12800. }
  12801. cancelRendering({
  12802. cancelExtraDelay = 0
  12803. } = {}) {
  12804. if (this.renderTask) {
  12805. this.renderTask.cancel(cancelExtraDelay);
  12806. this.renderTask = null;
  12807. }
  12808. this.resume = null;
  12809. }
  12810. dispatchPageRender() {
  12811. this.eventBus.dispatch("pagerender", {
  12812. source: this,
  12813. pageNumber: this.id
  12814. });
  12815. }
  12816. dispatchPageRendered(cssTransform, isDetailView) {
  12817. this.eventBus.dispatch("pagerendered", {
  12818. source: this,
  12819. pageNumber: this.id,
  12820. cssTransform,
  12821. isDetailView,
  12822. timestamp: performance.now(),
  12823. error: this.#renderError
  12824. });
  12825. }
  12826. }
  12827. ;// ./web/draw_layer_builder.js
  12828. class DrawLayerBuilder {
  12829. #drawLayer = null;
  12830. constructor(options) {
  12831. this.pageIndex = options.pageIndex;
  12832. }
  12833. async render({
  12834. intent = "display"
  12835. }) {
  12836. if (intent !== "display" || this.#drawLayer || this._cancelled) {
  12837. return;
  12838. }
  12839. this.#drawLayer = new DrawLayer({
  12840. pageIndex: this.pageIndex
  12841. });
  12842. }
  12843. cancel() {
  12844. this._cancelled = true;
  12845. if (!this.#drawLayer) {
  12846. return;
  12847. }
  12848. this.#drawLayer.destroy();
  12849. this.#drawLayer = null;
  12850. }
  12851. setParent(parent) {
  12852. this.#drawLayer?.setParent(parent);
  12853. }
  12854. getDrawLayer() {
  12855. return this.#drawLayer;
  12856. }
  12857. }
  12858. ;// ./web/pdf_page_detail_view.js
  12859. class PDFPageDetailView extends BasePDFPageView {
  12860. #detailArea = null;
  12861. renderingCancelled = false;
  12862. constructor({
  12863. pageView
  12864. }) {
  12865. super(pageView);
  12866. this.pageView = pageView;
  12867. this.renderingId = "detail" + this.id;
  12868. this.div = pageView.div;
  12869. }
  12870. setPdfPage(pdfPage) {
  12871. this.pageView.setPdfPage(pdfPage);
  12872. }
  12873. get pdfPage() {
  12874. return this.pageView.pdfPage;
  12875. }
  12876. get renderingState() {
  12877. return super.renderingState;
  12878. }
  12879. set renderingState(value) {
  12880. this.renderingCancelled = false;
  12881. super.renderingState = value;
  12882. }
  12883. reset({
  12884. keepCanvas = false
  12885. } = {}) {
  12886. const renderingCancelled = this.renderingCancelled || this.renderingState === RenderingStates.RUNNING || this.renderingState === RenderingStates.PAUSED;
  12887. this.cancelRendering();
  12888. this.renderingState = RenderingStates.INITIAL;
  12889. this.renderingCancelled = renderingCancelled;
  12890. if (!keepCanvas) {
  12891. this._resetCanvas();
  12892. }
  12893. }
  12894. #shouldRenderDifferentArea(visibleArea) {
  12895. if (!this.#detailArea) {
  12896. return true;
  12897. }
  12898. const minDetailX = this.#detailArea.minX;
  12899. const minDetailY = this.#detailArea.minY;
  12900. const maxDetailX = this.#detailArea.width + minDetailX;
  12901. const maxDetailY = this.#detailArea.height + minDetailY;
  12902. if (visibleArea.minX < minDetailX || visibleArea.minY < minDetailY || visibleArea.maxX > maxDetailX || visibleArea.maxY > maxDetailY) {
  12903. return true;
  12904. }
  12905. const {
  12906. width: maxWidth,
  12907. height: maxHeight,
  12908. scale
  12909. } = this.pageView.viewport;
  12910. if (this.#detailArea.scale !== scale) {
  12911. return true;
  12912. }
  12913. const paddingLeftSize = visibleArea.minX - minDetailX;
  12914. const paddingRightSize = maxDetailX - visibleArea.maxX;
  12915. const paddingTopSize = visibleArea.minY - minDetailY;
  12916. const paddingBottomSize = maxDetailY - visibleArea.maxY;
  12917. const MOVEMENT_THRESHOLD = 0.5;
  12918. const ratio = (1 + MOVEMENT_THRESHOLD) / MOVEMENT_THRESHOLD;
  12919. if (minDetailX > 0 && paddingRightSize / paddingLeftSize > ratio || maxDetailX < maxWidth && paddingLeftSize / paddingRightSize > ratio || minDetailY > 0 && paddingBottomSize / paddingTopSize > ratio || maxDetailY < maxHeight && paddingTopSize / paddingBottomSize > ratio) {
  12920. return true;
  12921. }
  12922. return false;
  12923. }
  12924. update({
  12925. visibleArea = null,
  12926. underlyingViewUpdated = false
  12927. } = {}) {
  12928. if (underlyingViewUpdated) {
  12929. this.cancelRendering();
  12930. this.renderingState = RenderingStates.INITIAL;
  12931. return;
  12932. }
  12933. if (!this.#shouldRenderDifferentArea(visibleArea)) {
  12934. return;
  12935. }
  12936. const {
  12937. viewport,
  12938. maxCanvasPixels,
  12939. capCanvasAreaFactor
  12940. } = this.pageView;
  12941. const visibleWidth = visibleArea.maxX - visibleArea.minX;
  12942. const visibleHeight = visibleArea.maxY - visibleArea.minY;
  12943. const visiblePixels = visibleWidth * visibleHeight * OutputScale.pixelRatio ** 2;
  12944. const maxDetailToVisibleLinearRatio = Math.sqrt(OutputScale.capPixels(maxCanvasPixels, capCanvasAreaFactor) / visiblePixels);
  12945. const maxOverflowScale = (maxDetailToVisibleLinearRatio - 1) / 2;
  12946. let overflowScale = Math.min(1, maxOverflowScale);
  12947. if (overflowScale < 0) {
  12948. overflowScale = 0;
  12949. }
  12950. const overflowWidth = visibleWidth * overflowScale;
  12951. const overflowHeight = visibleHeight * overflowScale;
  12952. const minX = Math.max(0, visibleArea.minX - overflowWidth);
  12953. const maxX = Math.min(viewport.width, visibleArea.maxX + overflowWidth);
  12954. const minY = Math.max(0, visibleArea.minY - overflowHeight);
  12955. const maxY = Math.min(viewport.height, visibleArea.maxY + overflowHeight);
  12956. const width = maxX - minX;
  12957. const height = maxY - minY;
  12958. this.#detailArea = {
  12959. minX,
  12960. minY,
  12961. width,
  12962. height,
  12963. scale: viewport.scale
  12964. };
  12965. this.reset({
  12966. keepCanvas: true
  12967. });
  12968. }
  12969. async draw() {
  12970. if (this.pageView.detailView !== this) {
  12971. return undefined;
  12972. }
  12973. const hideUntilComplete = this.pageView.renderingState === RenderingStates.FINISHED || this.renderingState === RenderingStates.FINISHED;
  12974. if (this.renderingState !== RenderingStates.INITIAL) {
  12975. console.error("Must be in new state before drawing");
  12976. this.reset();
  12977. }
  12978. const {
  12979. div,
  12980. pdfPage,
  12981. viewport
  12982. } = this.pageView;
  12983. if (!pdfPage) {
  12984. this.renderingState = RenderingStates.FINISHED;
  12985. throw new Error("pdfPage is not loaded");
  12986. }
  12987. this.renderingState = RenderingStates.RUNNING;
  12988. const canvasWrapper = this.pageView._ensureCanvasWrapper();
  12989. const {
  12990. canvas,
  12991. prevCanvas,
  12992. ctx
  12993. } = this._createCanvas(newCanvas => {
  12994. if (canvasWrapper.firstElementChild?.tagName === "CANVAS") {
  12995. canvasWrapper.firstElementChild.after(newCanvas);
  12996. } else {
  12997. canvasWrapper.prepend(newCanvas);
  12998. }
  12999. }, hideUntilComplete);
  13000. canvas.setAttribute("aria-hidden", "true");
  13001. const {
  13002. width,
  13003. height
  13004. } = viewport;
  13005. const area = this.#detailArea;
  13006. const {
  13007. pixelRatio
  13008. } = OutputScale;
  13009. const transform = [pixelRatio, 0, 0, pixelRatio, -area.minX * pixelRatio, -area.minY * pixelRatio];
  13010. canvas.width = area.width * pixelRatio;
  13011. canvas.height = area.height * pixelRatio;
  13012. const {
  13013. style
  13014. } = canvas;
  13015. style.width = `${area.width * 100 / width}%`;
  13016. style.height = `${area.height * 100 / height}%`;
  13017. style.top = `${area.minY * 100 / height}%`;
  13018. style.left = `${area.minX * 100 / width}%`;
  13019. const renderingPromise = this._drawCanvas(this.pageView._getRenderingContext(ctx, transform), () => {
  13020. this.canvas?.remove();
  13021. this.canvas = prevCanvas;
  13022. }, () => {
  13023. this.dispatchPageRendered(false, true);
  13024. });
  13025. div.setAttribute("data-loaded", true);
  13026. this.dispatchPageRender();
  13027. return renderingPromise;
  13028. }
  13029. }
  13030. ;// ./web/struct_tree_layer_builder.js
  13031. const PDF_ROLE_TO_HTML_ROLE = {
  13032. Document: null,
  13033. DocumentFragment: null,
  13034. Part: "group",
  13035. Sect: "group",
  13036. Div: "group",
  13037. Aside: "note",
  13038. NonStruct: "none",
  13039. P: null,
  13040. H: "heading",
  13041. Title: null,
  13042. FENote: "note",
  13043. Sub: "group",
  13044. Lbl: null,
  13045. Span: null,
  13046. Em: null,
  13047. Strong: null,
  13048. Link: "link",
  13049. Annot: "note",
  13050. Form: "form",
  13051. Ruby: null,
  13052. RB: null,
  13053. RT: null,
  13054. RP: null,
  13055. Warichu: null,
  13056. WT: null,
  13057. WP: null,
  13058. L: "list",
  13059. LI: "listitem",
  13060. LBody: null,
  13061. Table: "table",
  13062. TR: "row",
  13063. TH: "columnheader",
  13064. TD: "cell",
  13065. THead: "columnheader",
  13066. TBody: null,
  13067. TFoot: null,
  13068. Caption: null,
  13069. Figure: "figure",
  13070. Formula: null,
  13071. Artifact: null
  13072. };
  13073. const HEADING_PATTERN = /^H(\d+)$/;
  13074. class StructTreeLayerBuilder {
  13075. #promise;
  13076. #treeDom = null;
  13077. #treePromise;
  13078. #elementAttributes = new Map();
  13079. #rawDims;
  13080. #elementsToAddToTextLayer = null;
  13081. constructor(pdfPage, rawDims) {
  13082. this.#promise = pdfPage.getStructTree();
  13083. this.#rawDims = rawDims;
  13084. }
  13085. async render() {
  13086. if (this.#treePromise) {
  13087. return this.#treePromise;
  13088. }
  13089. const {
  13090. promise,
  13091. resolve,
  13092. reject
  13093. } = Promise.withResolvers();
  13094. this.#treePromise = promise;
  13095. try {
  13096. this.#treeDom = this.#walk(await this.#promise);
  13097. } catch (ex) {
  13098. reject(ex);
  13099. }
  13100. this.#promise = null;
  13101. this.#treeDom?.classList.add("structTree");
  13102. resolve(this.#treeDom);
  13103. return promise;
  13104. }
  13105. async getAriaAttributes(annotationId) {
  13106. try {
  13107. await this.render();
  13108. return this.#elementAttributes.get(annotationId);
  13109. } catch {}
  13110. return null;
  13111. }
  13112. hide() {
  13113. if (this.#treeDom && !this.#treeDom.hidden) {
  13114. this.#treeDom.hidden = true;
  13115. }
  13116. }
  13117. show() {
  13118. if (this.#treeDom?.hidden) {
  13119. this.#treeDom.hidden = false;
  13120. }
  13121. }
  13122. #setAttributes(structElement, htmlElement) {
  13123. const {
  13124. alt,
  13125. id,
  13126. lang
  13127. } = structElement;
  13128. if (alt !== undefined) {
  13129. let added = false;
  13130. const label = removeNullCharacters(alt);
  13131. for (const child of structElement.children) {
  13132. if (child.type === "annotation") {
  13133. let attrs = this.#elementAttributes.get(child.id);
  13134. if (!attrs) {
  13135. attrs = new Map();
  13136. this.#elementAttributes.set(child.id, attrs);
  13137. }
  13138. attrs.set("aria-label", label);
  13139. added = true;
  13140. }
  13141. }
  13142. if (!added) {
  13143. htmlElement.setAttribute("aria-label", label);
  13144. }
  13145. }
  13146. if (id !== undefined) {
  13147. htmlElement.setAttribute("aria-owns", id);
  13148. }
  13149. if (lang !== undefined) {
  13150. htmlElement.setAttribute("lang", removeNullCharacters(lang, true));
  13151. }
  13152. }
  13153. #addImageInTextLayer(node, element) {
  13154. const {
  13155. alt,
  13156. bbox,
  13157. children
  13158. } = node;
  13159. const child = children?.[0];
  13160. if (!this.#rawDims || !alt || !bbox || child?.type !== "content") {
  13161. return false;
  13162. }
  13163. const {
  13164. id
  13165. } = child;
  13166. if (!id) {
  13167. return false;
  13168. }
  13169. element.setAttribute("aria-owns", id);
  13170. const img = document.createElement("span");
  13171. (this.#elementsToAddToTextLayer ||= new Map()).set(id, img);
  13172. img.setAttribute("role", "img");
  13173. img.setAttribute("aria-label", removeNullCharacters(alt));
  13174. const {
  13175. pageHeight,
  13176. pageX,
  13177. pageY
  13178. } = this.#rawDims;
  13179. const calc = "calc(var(--total-scale-factor) *";
  13180. const {
  13181. style
  13182. } = img;
  13183. style.width = `${calc}${bbox[2] - bbox[0]}px)`;
  13184. style.height = `${calc}${bbox[3] - bbox[1]}px)`;
  13185. style.left = `${calc}${bbox[0] - pageX}px)`;
  13186. style.top = `${calc}${pageHeight - bbox[3] + pageY}px)`;
  13187. return true;
  13188. }
  13189. addElementsToTextLayer() {
  13190. if (!this.#elementsToAddToTextLayer) {
  13191. return;
  13192. }
  13193. for (const [id, img] of this.#elementsToAddToTextLayer) {
  13194. document.getElementById(id)?.append(img);
  13195. }
  13196. this.#elementsToAddToTextLayer.clear();
  13197. this.#elementsToAddToTextLayer = null;
  13198. }
  13199. #walk(node) {
  13200. if (!node) {
  13201. return null;
  13202. }
  13203. const element = document.createElement("span");
  13204. if ("role" in node) {
  13205. const {
  13206. role
  13207. } = node;
  13208. const match = role.match(HEADING_PATTERN);
  13209. if (match) {
  13210. element.setAttribute("role", "heading");
  13211. element.setAttribute("aria-level", match[1]);
  13212. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  13213. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  13214. }
  13215. if (role === "Figure" && this.#addImageInTextLayer(node, element)) {
  13216. return element;
  13217. }
  13218. }
  13219. this.#setAttributes(node, element);
  13220. if (node.children) {
  13221. if (node.children.length === 1 && "id" in node.children[0]) {
  13222. this.#setAttributes(node.children[0], element);
  13223. } else {
  13224. for (const kid of node.children) {
  13225. element.append(this.#walk(kid));
  13226. }
  13227. }
  13228. }
  13229. return element;
  13230. }
  13231. }
  13232. ;// ./web/text_accessibility.js
  13233. class TextAccessibilityManager {
  13234. #enabled = false;
  13235. #textChildren = null;
  13236. #textNodes = new Map();
  13237. #waitingElements = new Map();
  13238. setTextMapping(textDivs) {
  13239. this.#textChildren = textDivs;
  13240. }
  13241. static #compareElementPositions(e1, e2) {
  13242. const rect1 = e1.getBoundingClientRect();
  13243. const rect2 = e2.getBoundingClientRect();
  13244. if (rect1.width === 0 && rect1.height === 0) {
  13245. return +1;
  13246. }
  13247. if (rect2.width === 0 && rect2.height === 0) {
  13248. return -1;
  13249. }
  13250. const top1 = rect1.y;
  13251. const bot1 = rect1.y + rect1.height;
  13252. const mid1 = rect1.y + rect1.height / 2;
  13253. const top2 = rect2.y;
  13254. const bot2 = rect2.y + rect2.height;
  13255. const mid2 = rect2.y + rect2.height / 2;
  13256. if (mid1 <= top2 && mid2 >= bot1) {
  13257. return -1;
  13258. }
  13259. if (mid2 <= top1 && mid1 >= bot2) {
  13260. return +1;
  13261. }
  13262. const centerX1 = rect1.x + rect1.width / 2;
  13263. const centerX2 = rect2.x + rect2.width / 2;
  13264. return centerX1 - centerX2;
  13265. }
  13266. enable() {
  13267. if (this.#enabled) {
  13268. throw new Error("TextAccessibilityManager is already enabled.");
  13269. }
  13270. if (!this.#textChildren) {
  13271. throw new Error("Text divs and strings have not been set.");
  13272. }
  13273. this.#enabled = true;
  13274. this.#textChildren = this.#textChildren.slice();
  13275. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  13276. if (this.#textNodes.size > 0) {
  13277. const textChildren = this.#textChildren;
  13278. for (const [id, nodeIndex] of this.#textNodes) {
  13279. const element = document.getElementById(id);
  13280. if (!element) {
  13281. this.#textNodes.delete(id);
  13282. continue;
  13283. }
  13284. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  13285. }
  13286. }
  13287. for (const [element, isRemovable] of this.#waitingElements) {
  13288. this.addPointerInTextLayer(element, isRemovable);
  13289. }
  13290. this.#waitingElements.clear();
  13291. }
  13292. disable() {
  13293. if (!this.#enabled) {
  13294. return;
  13295. }
  13296. this.#waitingElements.clear();
  13297. this.#textChildren = null;
  13298. this.#enabled = false;
  13299. }
  13300. removePointerInTextLayer(element) {
  13301. if (!this.#enabled) {
  13302. this.#waitingElements.delete(element);
  13303. return;
  13304. }
  13305. const children = this.#textChildren;
  13306. if (!children || children.length === 0) {
  13307. return;
  13308. }
  13309. const {
  13310. id
  13311. } = element;
  13312. const nodeIndex = this.#textNodes.get(id);
  13313. if (nodeIndex === undefined) {
  13314. return;
  13315. }
  13316. const node = children[nodeIndex];
  13317. this.#textNodes.delete(id);
  13318. let owns = node.getAttribute("aria-owns");
  13319. if (owns?.includes(id)) {
  13320. owns = owns.split(" ").filter(x => x !== id).join(" ");
  13321. if (owns) {
  13322. node.setAttribute("aria-owns", owns);
  13323. } else {
  13324. node.removeAttribute("aria-owns");
  13325. node.setAttribute("role", "presentation");
  13326. }
  13327. }
  13328. }
  13329. #addIdToAriaOwns(id, node) {
  13330. const owns = node.getAttribute("aria-owns");
  13331. if (!owns?.includes(id)) {
  13332. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  13333. }
  13334. node.removeAttribute("role");
  13335. }
  13336. addPointerInTextLayer(element, isRemovable) {
  13337. const {
  13338. id
  13339. } = element;
  13340. if (!id) {
  13341. return null;
  13342. }
  13343. if (!this.#enabled) {
  13344. this.#waitingElements.set(element, isRemovable);
  13345. return null;
  13346. }
  13347. if (isRemovable) {
  13348. this.removePointerInTextLayer(element);
  13349. }
  13350. const children = this.#textChildren;
  13351. if (!children || children.length === 0) {
  13352. return null;
  13353. }
  13354. const index = binarySearchFirstItem(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  13355. const nodeIndex = Math.max(0, index - 1);
  13356. const child = children[nodeIndex];
  13357. this.#addIdToAriaOwns(id, child);
  13358. this.#textNodes.set(id, nodeIndex);
  13359. const parent = child.parentNode;
  13360. return parent?.classList.contains("markedContent") ? parent.id : null;
  13361. }
  13362. moveElementInDOM(container, element, contentElement, isRemovable) {
  13363. const id = this.addPointerInTextLayer(contentElement, isRemovable);
  13364. if (!container.hasChildNodes()) {
  13365. container.append(element);
  13366. return id;
  13367. }
  13368. const children = Array.from(container.childNodes).filter(node => node !== element);
  13369. if (children.length === 0) {
  13370. return id;
  13371. }
  13372. const elementToCompare = contentElement || element;
  13373. const index = binarySearchFirstItem(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  13374. if (index === 0) {
  13375. children[0].before(element);
  13376. } else {
  13377. children[index - 1].after(element);
  13378. }
  13379. return id;
  13380. }
  13381. }
  13382. ;// ./web/text_highlighter.js
  13383. class TextHighlighter {
  13384. #eventAbortController = null;
  13385. constructor({
  13386. findController,
  13387. eventBus,
  13388. pageIndex
  13389. }) {
  13390. this.findController = findController;
  13391. this.matches = [];
  13392. this.eventBus = eventBus;
  13393. this.pageIdx = pageIndex;
  13394. this.textDivs = null;
  13395. this.textContentItemsStr = null;
  13396. this.enabled = false;
  13397. }
  13398. setTextMapping(divs, texts) {
  13399. this.textDivs = divs;
  13400. this.textContentItemsStr = texts;
  13401. }
  13402. enable() {
  13403. if (!this.textDivs || !this.textContentItemsStr) {
  13404. throw new Error("Text divs and strings have not been set.");
  13405. }
  13406. if (this.enabled) {
  13407. throw new Error("TextHighlighter is already enabled.");
  13408. }
  13409. this.enabled = true;
  13410. if (!this.#eventAbortController) {
  13411. this.#eventAbortController = new AbortController();
  13412. this.eventBus._on("updatetextlayermatches", evt => {
  13413. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  13414. this._updateMatches();
  13415. }
  13416. }, {
  13417. signal: this.#eventAbortController.signal
  13418. });
  13419. }
  13420. this._updateMatches();
  13421. }
  13422. disable() {
  13423. if (!this.enabled) {
  13424. return;
  13425. }
  13426. this.enabled = false;
  13427. this.#eventAbortController?.abort();
  13428. this.#eventAbortController = null;
  13429. this._updateMatches(true);
  13430. }
  13431. _convertMatches(matches, matchesLength) {
  13432. if (!matches) {
  13433. return [];
  13434. }
  13435. const {
  13436. textContentItemsStr
  13437. } = this;
  13438. let i = 0,
  13439. iIndex = 0;
  13440. const end = textContentItemsStr.length - 1;
  13441. const result = [];
  13442. for (let m = 0, mm = matches.length; m < mm; m++) {
  13443. let matchIdx = matches[m];
  13444. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  13445. iIndex += textContentItemsStr[i].length;
  13446. i++;
  13447. }
  13448. if (i === textContentItemsStr.length) {
  13449. console.error("Could not find a matching mapping");
  13450. }
  13451. const match = {
  13452. begin: {
  13453. divIdx: i,
  13454. offset: matchIdx - iIndex
  13455. }
  13456. };
  13457. matchIdx += matchesLength[m];
  13458. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  13459. iIndex += textContentItemsStr[i].length;
  13460. i++;
  13461. }
  13462. match.end = {
  13463. divIdx: i,
  13464. offset: matchIdx - iIndex
  13465. };
  13466. result.push(match);
  13467. }
  13468. return result;
  13469. }
  13470. _renderMatches(matches) {
  13471. if (matches.length === 0) {
  13472. return;
  13473. }
  13474. const {
  13475. findController,
  13476. pageIdx
  13477. } = this;
  13478. const {
  13479. textContentItemsStr,
  13480. textDivs
  13481. } = this;
  13482. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  13483. const selectedMatchIdx = findController.selected.matchIdx;
  13484. const highlightAll = findController.state.highlightAll;
  13485. let prevEnd = null;
  13486. const infinity = {
  13487. divIdx: -1,
  13488. offset: undefined
  13489. };
  13490. function beginText(begin, className) {
  13491. const divIdx = begin.divIdx;
  13492. textDivs[divIdx].textContent = "";
  13493. return appendTextToDiv(divIdx, 0, begin.offset, className);
  13494. }
  13495. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  13496. let div = textDivs[divIdx];
  13497. if (div.nodeType === Node.TEXT_NODE) {
  13498. const span = document.createElement("span");
  13499. div.before(span);
  13500. span.append(div);
  13501. textDivs[divIdx] = span;
  13502. div = span;
  13503. }
  13504. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  13505. const node = document.createTextNode(content);
  13506. if (className) {
  13507. const span = document.createElement("span");
  13508. span.className = `${className} appended`;
  13509. span.append(node);
  13510. div.append(span);
  13511. if (className.includes("selected")) {
  13512. const {
  13513. left
  13514. } = span.getClientRects()[0];
  13515. const parentLeft = div.getBoundingClientRect().left;
  13516. return left - parentLeft;
  13517. }
  13518. return 0;
  13519. }
  13520. div.append(node);
  13521. return 0;
  13522. }
  13523. let i0 = selectedMatchIdx,
  13524. i1 = i0 + 1;
  13525. if (highlightAll) {
  13526. i0 = 0;
  13527. i1 = matches.length;
  13528. } else if (!isSelectedPage) {
  13529. return;
  13530. }
  13531. let lastDivIdx = -1;
  13532. let lastOffset = -1;
  13533. for (let i = i0; i < i1; i++) {
  13534. const match = matches[i];
  13535. const begin = match.begin;
  13536. if (begin.divIdx === lastDivIdx && begin.offset === lastOffset) {
  13537. continue;
  13538. }
  13539. lastDivIdx = begin.divIdx;
  13540. lastOffset = begin.offset;
  13541. const end = match.end;
  13542. const isSelected = isSelectedPage && i === selectedMatchIdx;
  13543. const highlightSuffix = isSelected ? " selected" : "";
  13544. let selectedLeft = 0;
  13545. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  13546. if (prevEnd !== null) {
  13547. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  13548. }
  13549. beginText(begin);
  13550. } else {
  13551. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  13552. }
  13553. if (begin.divIdx === end.divIdx) {
  13554. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  13555. } else {
  13556. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  13557. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  13558. textDivs[n0].className = "highlight middle" + highlightSuffix;
  13559. }
  13560. beginText(end, "highlight end" + highlightSuffix);
  13561. }
  13562. prevEnd = end;
  13563. if (isSelected) {
  13564. findController.scrollMatchIntoView({
  13565. element: textDivs[begin.divIdx],
  13566. selectedLeft,
  13567. pageIndex: pageIdx,
  13568. matchIndex: selectedMatchIdx
  13569. });
  13570. }
  13571. }
  13572. if (prevEnd) {
  13573. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  13574. }
  13575. }
  13576. _updateMatches(reset = false) {
  13577. if (!this.enabled && !reset) {
  13578. return;
  13579. }
  13580. const {
  13581. findController,
  13582. matches,
  13583. pageIdx
  13584. } = this;
  13585. const {
  13586. textContentItemsStr,
  13587. textDivs
  13588. } = this;
  13589. let clearedUntilDivIdx = -1;
  13590. for (const match of matches) {
  13591. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  13592. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  13593. const div = textDivs[n];
  13594. div.textContent = textContentItemsStr[n];
  13595. div.className = "";
  13596. }
  13597. clearedUntilDivIdx = match.end.divIdx + 1;
  13598. }
  13599. if (!findController?.highlightMatches || reset) {
  13600. return;
  13601. }
  13602. const pageMatches = findController.pageMatches[pageIdx] || null;
  13603. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  13604. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  13605. this._renderMatches(this.matches);
  13606. }
  13607. }
  13608. ;// ./web/text_layer_builder.js
  13609. class TextLayerBuilder {
  13610. #enablePermissions = false;
  13611. #onAppend = null;
  13612. #renderingDone = false;
  13613. #textLayer = null;
  13614. static #textLayers = new Map();
  13615. static #selectionChangeAbortController = null;
  13616. constructor({
  13617. pdfPage,
  13618. highlighter = null,
  13619. accessibilityManager = null,
  13620. enablePermissions = false,
  13621. onAppend = null
  13622. }) {
  13623. this.pdfPage = pdfPage;
  13624. this.highlighter = highlighter;
  13625. this.accessibilityManager = accessibilityManager;
  13626. this.#enablePermissions = enablePermissions === true;
  13627. this.#onAppend = onAppend;
  13628. this.div = document.createElement("div");
  13629. this.div.tabIndex = 0;
  13630. this.div.className = "textLayer";
  13631. }
  13632. async render({
  13633. viewport,
  13634. textContentParams = null
  13635. }) {
  13636. if (this.#renderingDone && this.#textLayer) {
  13637. this.#textLayer.update({
  13638. viewport,
  13639. onBefore: this.hide.bind(this)
  13640. });
  13641. this.show();
  13642. return;
  13643. }
  13644. this.cancel();
  13645. this.#textLayer = new TextLayer({
  13646. textContentSource: this.pdfPage.streamTextContent(textContentParams || {
  13647. includeMarkedContent: true,
  13648. disableNormalization: true
  13649. }),
  13650. container: this.div,
  13651. viewport
  13652. });
  13653. const {
  13654. textDivs,
  13655. textContentItemsStr
  13656. } = this.#textLayer;
  13657. this.highlighter?.setTextMapping(textDivs, textContentItemsStr);
  13658. this.accessibilityManager?.setTextMapping(textDivs);
  13659. await this.#textLayer.render();
  13660. this.#renderingDone = true;
  13661. const endOfContent = document.createElement("div");
  13662. endOfContent.className = "endOfContent";
  13663. this.div.append(endOfContent);
  13664. this.#bindMouse(endOfContent);
  13665. this.#onAppend?.(this.div);
  13666. this.highlighter?.enable();
  13667. this.accessibilityManager?.enable();
  13668. }
  13669. hide() {
  13670. if (!this.div.hidden && this.#renderingDone) {
  13671. this.highlighter?.disable();
  13672. this.div.hidden = true;
  13673. }
  13674. }
  13675. show() {
  13676. if (this.div.hidden && this.#renderingDone) {
  13677. this.div.hidden = false;
  13678. this.highlighter?.enable();
  13679. }
  13680. }
  13681. cancel() {
  13682. this.#textLayer?.cancel();
  13683. this.#textLayer = null;
  13684. this.highlighter?.disable();
  13685. this.accessibilityManager?.disable();
  13686. TextLayerBuilder.#removeGlobalSelectionListener(this.div);
  13687. }
  13688. #bindMouse(end) {
  13689. const {
  13690. div
  13691. } = this;
  13692. div.addEventListener("mousedown", () => {
  13693. div.classList.add("selecting");
  13694. });
  13695. div.addEventListener("copy", event => {
  13696. if (!this.#enablePermissions) {
  13697. const selection = document.getSelection();
  13698. event.clipboardData.setData("text/plain", removeNullCharacters(normalizeUnicode(selection.toString())));
  13699. }
  13700. stopEvent(event);
  13701. });
  13702. TextLayerBuilder.#textLayers.set(div, end);
  13703. TextLayerBuilder.#enableGlobalSelectionListener();
  13704. }
  13705. static #removeGlobalSelectionListener(textLayerDiv) {
  13706. this.#textLayers.delete(textLayerDiv);
  13707. if (this.#textLayers.size === 0) {
  13708. this.#selectionChangeAbortController?.abort();
  13709. this.#selectionChangeAbortController = null;
  13710. }
  13711. }
  13712. static #enableGlobalSelectionListener() {
  13713. if (this.#selectionChangeAbortController) {
  13714. return;
  13715. }
  13716. this.#selectionChangeAbortController = new AbortController();
  13717. const {
  13718. signal
  13719. } = this.#selectionChangeAbortController;
  13720. const reset = (end, textLayer) => {
  13721. textLayer.append(end);
  13722. end.style.width = "";
  13723. end.style.height = "";
  13724. textLayer.classList.remove("selecting");
  13725. };
  13726. let isPointerDown = false;
  13727. document.addEventListener("pointerdown", () => {
  13728. isPointerDown = true;
  13729. }, {
  13730. signal
  13731. });
  13732. document.addEventListener("pointerup", () => {
  13733. isPointerDown = false;
  13734. this.#textLayers.forEach(reset);
  13735. }, {
  13736. signal
  13737. });
  13738. window.addEventListener("blur", () => {
  13739. isPointerDown = false;
  13740. this.#textLayers.forEach(reset);
  13741. }, {
  13742. signal
  13743. });
  13744. document.addEventListener("keyup", () => {
  13745. if (!isPointerDown) {
  13746. this.#textLayers.forEach(reset);
  13747. }
  13748. }, {
  13749. signal
  13750. });
  13751. var isFirefox, prevRange;
  13752. document.addEventListener("selectionchange", () => {
  13753. const selection = document.getSelection();
  13754. if (selection.rangeCount === 0) {
  13755. this.#textLayers.forEach(reset);
  13756. return;
  13757. }
  13758. const activeTextLayers = new Set();
  13759. for (let i = 0; i < selection.rangeCount; i++) {
  13760. const range = selection.getRangeAt(i);
  13761. for (const textLayerDiv of this.#textLayers.keys()) {
  13762. if (!activeTextLayers.has(textLayerDiv) && range.intersectsNode(textLayerDiv)) {
  13763. activeTextLayers.add(textLayerDiv);
  13764. }
  13765. }
  13766. }
  13767. for (const [textLayerDiv, endDiv] of this.#textLayers) {
  13768. if (activeTextLayers.has(textLayerDiv)) {
  13769. textLayerDiv.classList.add("selecting");
  13770. } else {
  13771. reset(endDiv, textLayerDiv);
  13772. }
  13773. }
  13774. isFirefox ??= getComputedStyle(this.#textLayers.values().next().value).getPropertyValue("-moz-user-select") === "none";
  13775. if (isFirefox) {
  13776. return;
  13777. }
  13778. const range = selection.getRangeAt(0);
  13779. const modifyStart = prevRange && (range.compareBoundaryPoints(Range.END_TO_END, prevRange) === 0 || range.compareBoundaryPoints(Range.START_TO_END, prevRange) === 0);
  13780. let anchor = modifyStart ? range.startContainer : range.endContainer;
  13781. if (anchor.nodeType === Node.TEXT_NODE) {
  13782. anchor = anchor.parentNode;
  13783. }
  13784. if (!modifyStart && range.endOffset === 0) {
  13785. do {
  13786. while (!anchor.previousSibling) {
  13787. anchor = anchor.parentNode;
  13788. }
  13789. anchor = anchor.previousSibling;
  13790. } while (!anchor.childNodes.length);
  13791. }
  13792. const parentTextLayer = anchor.parentElement?.closest(".textLayer");
  13793. const endDiv = this.#textLayers.get(parentTextLayer);
  13794. if (endDiv) {
  13795. endDiv.style.width = parentTextLayer.style.width;
  13796. endDiv.style.height = parentTextLayer.style.height;
  13797. anchor.parentElement.insertBefore(endDiv, modifyStart ? anchor : anchor.nextSibling);
  13798. }
  13799. prevRange = range.cloneRange();
  13800. }, {
  13801. signal
  13802. });
  13803. }
  13804. }
  13805. ;// ./web/pdf_page_view.js
  13806. const DEFAULT_LAYER_PROPERTIES = null;
  13807. const LAYERS_ORDER = new Map([["canvasWrapper", 0], ["textLayer", 1], ["annotationLayer", 2], ["annotationEditorLayer", 3], ["xfaLayer", 3]]);
  13808. class PDFPageView extends BasePDFPageView {
  13809. #annotationMode = AnnotationMode.ENABLE_FORMS;
  13810. #canvasWrapper = null;
  13811. #enableAutoLinking = true;
  13812. #hasRestrictedScaling = false;
  13813. #isEditing = false;
  13814. #layerProperties = null;
  13815. #needsRestrictedScaling = false;
  13816. #originalViewport = null;
  13817. #previousRotation = null;
  13818. #scaleRoundX = 1;
  13819. #scaleRoundY = 1;
  13820. #textLayerMode = TextLayerMode.ENABLE;
  13821. #userUnit = 1;
  13822. #useThumbnailCanvas = {
  13823. directDrawing: true,
  13824. initialOptionalContent: true,
  13825. regularAnnotations: true
  13826. };
  13827. #layers = [null, null, null, null];
  13828. constructor(options) {
  13829. super(options);
  13830. const container = options.container;
  13831. const defaultViewport = options.defaultViewport;
  13832. this.renderingId = "page" + this.id;
  13833. this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
  13834. this.pdfPage = null;
  13835. this.pageLabel = null;
  13836. this.rotation = 0;
  13837. this.scale = options.scale || DEFAULT_SCALE;
  13838. this.viewport = defaultViewport;
  13839. this.pdfPageRotate = defaultViewport.rotation;
  13840. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  13841. this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
  13842. this.#annotationMode = options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
  13843. this.imageResourcesPath = options.imageResourcesPath || "";
  13844. this.enableDetailCanvas = options.enableDetailCanvas ?? true;
  13845. this.maxCanvasPixels = options.maxCanvasPixels ?? AppOptions.get("maxCanvasPixels");
  13846. this.maxCanvasDim = options.maxCanvasDim || AppOptions.get("maxCanvasDim");
  13847. this.capCanvasAreaFactor = options.capCanvasAreaFactor ?? AppOptions.get("capCanvasAreaFactor");
  13848. this.#enableAutoLinking = options.enableAutoLinking !== false;
  13849. this.l10n = options.l10n;
  13850. this.l10n ||= new genericl10n_GenericL10n();
  13851. this._isStandalone = !this.renderingQueue?.hasViewer();
  13852. this._container = container;
  13853. this._annotationCanvasMap = null;
  13854. this.annotationLayer = null;
  13855. this.annotationEditorLayer = null;
  13856. this.textLayer = null;
  13857. this.xfaLayer = null;
  13858. this.structTreeLayer = null;
  13859. this.drawLayer = null;
  13860. this.detailView = null;
  13861. const div = document.createElement("div");
  13862. div.className = "page";
  13863. div.setAttribute("data-page-number", this.id);
  13864. div.setAttribute("role", "region");
  13865. div.setAttribute("data-l10n-id", "pdfjs-page-landmark");
  13866. div.setAttribute("data-l10n-args", JSON.stringify({
  13867. page: this.id
  13868. }));
  13869. this.div = div;
  13870. this.#setDimensions();
  13871. container?.append(div);
  13872. if (this._isStandalone) {
  13873. container?.style.setProperty("--scale-factor", this.scale * PixelsPerInch.PDF_TO_CSS_UNITS);
  13874. if (this.pageColors?.background) {
  13875. container?.style.setProperty("--page-bg-color", this.pageColors.background);
  13876. }
  13877. const {
  13878. optionalContentConfigPromise
  13879. } = options;
  13880. if (optionalContentConfigPromise) {
  13881. optionalContentConfigPromise.then(optionalContentConfig => {
  13882. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  13883. return;
  13884. }
  13885. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  13886. });
  13887. }
  13888. if (!options.l10n) {
  13889. this.l10n.translate(this.div);
  13890. }
  13891. }
  13892. }
  13893. #addLayer(div, name) {
  13894. const pos = LAYERS_ORDER.get(name);
  13895. const oldDiv = this.#layers[pos];
  13896. this.#layers[pos] = div;
  13897. if (oldDiv) {
  13898. oldDiv.replaceWith(div);
  13899. return;
  13900. }
  13901. for (let i = pos - 1; i >= 0; i--) {
  13902. const layer = this.#layers[i];
  13903. if (layer) {
  13904. layer.after(div);
  13905. return;
  13906. }
  13907. }
  13908. this.div.prepend(div);
  13909. }
  13910. #setDimensions() {
  13911. const {
  13912. div,
  13913. viewport
  13914. } = this;
  13915. if (viewport.userUnit !== this.#userUnit) {
  13916. if (viewport.userUnit !== 1) {
  13917. div.style.setProperty("--user-unit", viewport.userUnit);
  13918. } else {
  13919. div.style.removeProperty("--user-unit");
  13920. }
  13921. this.#userUnit = viewport.userUnit;
  13922. }
  13923. if (this.pdfPage) {
  13924. if (this.#previousRotation === viewport.rotation) {
  13925. return;
  13926. }
  13927. this.#previousRotation = viewport.rotation;
  13928. }
  13929. setLayerDimensions(div, viewport, true, false);
  13930. }
  13931. setPdfPage(pdfPage) {
  13932. if (this._isStandalone && (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas")) {
  13933. this._container?.style.setProperty("--hcm-highlight-filter", pdfPage.filterFactory.addHighlightHCMFilter("highlight", "CanvasText", "Canvas", "HighlightText", "Highlight"));
  13934. this._container?.style.setProperty("--hcm-highlight-selected-filter", pdfPage.filterFactory.addHighlightHCMFilter("highlight_selected", "CanvasText", "Canvas", "HighlightText", "Highlight"));
  13935. }
  13936. this.pdfPage = pdfPage;
  13937. this.pdfPageRotate = pdfPage.rotate;
  13938. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  13939. this.viewport = pdfPage.getViewport({
  13940. scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
  13941. rotation: totalRotation
  13942. });
  13943. this.#setDimensions();
  13944. this.reset();
  13945. }
  13946. destroy() {
  13947. this.reset();
  13948. this.pdfPage?.cleanup();
  13949. }
  13950. hasEditableAnnotations() {
  13951. return !!this.annotationLayer?.hasEditableAnnotations();
  13952. }
  13953. get _textHighlighter() {
  13954. return shadow(this, "_textHighlighter", new TextHighlighter({
  13955. pageIndex: this.id - 1,
  13956. eventBus: this.eventBus,
  13957. findController: this.#layerProperties.findController
  13958. }));
  13959. }
  13960. #dispatchLayerRendered(name, error) {
  13961. this.eventBus.dispatch(name, {
  13962. source: this,
  13963. pageNumber: this.id,
  13964. error
  13965. });
  13966. }
  13967. async #renderAnnotationLayer() {
  13968. let error = null;
  13969. try {
  13970. await this.annotationLayer.render({
  13971. viewport: this.viewport,
  13972. intent: "display",
  13973. structTreeLayer: this.structTreeLayer
  13974. });
  13975. } catch (ex) {
  13976. console.error("#renderAnnotationLayer:", ex);
  13977. error = ex;
  13978. } finally {
  13979. this.#dispatchLayerRendered("annotationlayerrendered", error);
  13980. }
  13981. }
  13982. async #renderAnnotationEditorLayer() {
  13983. let error = null;
  13984. try {
  13985. await this.annotationEditorLayer.render({
  13986. viewport: this.viewport,
  13987. intent: "display"
  13988. });
  13989. } catch (ex) {
  13990. console.error("#renderAnnotationEditorLayer:", ex);
  13991. error = ex;
  13992. } finally {
  13993. this.#dispatchLayerRendered("annotationeditorlayerrendered", error);
  13994. }
  13995. }
  13996. async #renderDrawLayer() {
  13997. try {
  13998. await this.drawLayer.render({
  13999. intent: "display"
  14000. });
  14001. } catch (ex) {
  14002. console.error("#renderDrawLayer:", ex);
  14003. }
  14004. }
  14005. async #renderXfaLayer() {
  14006. let error = null;
  14007. try {
  14008. const result = await this.xfaLayer.render({
  14009. viewport: this.viewport,
  14010. intent: "display"
  14011. });
  14012. if (result?.textDivs && this._textHighlighter) {
  14013. this.#buildXfaTextContentItems(result.textDivs);
  14014. }
  14015. } catch (ex) {
  14016. console.error("#renderXfaLayer:", ex);
  14017. error = ex;
  14018. } finally {
  14019. if (this.xfaLayer?.div) {
  14020. this.l10n.pause();
  14021. this.#addLayer(this.xfaLayer.div, "xfaLayer");
  14022. this.l10n.resume();
  14023. }
  14024. this.#dispatchLayerRendered("xfalayerrendered", error);
  14025. }
  14026. }
  14027. async #renderTextLayer() {
  14028. if (!this.textLayer) {
  14029. return;
  14030. }
  14031. let error = null;
  14032. try {
  14033. await this.textLayer.render({
  14034. viewport: this.viewport
  14035. });
  14036. } catch (ex) {
  14037. if (ex instanceof AbortException) {
  14038. return;
  14039. }
  14040. console.error("#renderTextLayer:", ex);
  14041. error = ex;
  14042. }
  14043. this.#dispatchLayerRendered("textlayerrendered", error);
  14044. this.#renderStructTreeLayer();
  14045. }
  14046. async #renderStructTreeLayer() {
  14047. if (!this.textLayer) {
  14048. return;
  14049. }
  14050. const treeDom = await this.structTreeLayer?.render();
  14051. if (treeDom) {
  14052. this.l10n.pause();
  14053. this.structTreeLayer?.addElementsToTextLayer();
  14054. if (this.canvas && treeDom.parentNode !== this.canvas) {
  14055. this.canvas.append(treeDom);
  14056. }
  14057. this.l10n.resume();
  14058. }
  14059. this.structTreeLayer?.show();
  14060. }
  14061. async #buildXfaTextContentItems(textDivs) {
  14062. const text = await this.pdfPage.getTextContent();
  14063. const items = [];
  14064. for (const item of text.items) {
  14065. items.push(item.str);
  14066. }
  14067. this._textHighlighter.setTextMapping(textDivs, items);
  14068. this._textHighlighter.enable();
  14069. }
  14070. async #injectLinkAnnotations(textLayerPromise) {
  14071. let error = null;
  14072. try {
  14073. await textLayerPromise;
  14074. if (!this.annotationLayer) {
  14075. return;
  14076. }
  14077. await this.annotationLayer.injectLinkAnnotations({
  14078. inferredLinks: Autolinker.processLinks(this),
  14079. viewport: this.viewport,
  14080. structTreeLayer: this.structTreeLayer
  14081. });
  14082. } catch (ex) {
  14083. console.error("#injectLinkAnnotations:", ex);
  14084. error = ex;
  14085. }
  14086. }
  14087. _resetCanvas() {
  14088. super._resetCanvas();
  14089. this.#originalViewport = null;
  14090. }
  14091. reset({
  14092. keepAnnotationLayer = false,
  14093. keepAnnotationEditorLayer = false,
  14094. keepXfaLayer = false,
  14095. keepTextLayer = false,
  14096. keepCanvasWrapper = false,
  14097. preserveDetailViewState = false
  14098. } = {}) {
  14099. this.cancelRendering({
  14100. keepAnnotationLayer,
  14101. keepAnnotationEditorLayer,
  14102. keepXfaLayer,
  14103. keepTextLayer
  14104. });
  14105. this.renderingState = RenderingStates.INITIAL;
  14106. const div = this.div;
  14107. const childNodes = div.childNodes,
  14108. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  14109. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  14110. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
  14111. textLayerNode = keepTextLayer && this.textLayer?.div || null,
  14112. canvasWrapperNode = keepCanvasWrapper && this.#canvasWrapper || null;
  14113. for (let i = childNodes.length - 1; i >= 0; i--) {
  14114. const node = childNodes[i];
  14115. switch (node) {
  14116. case annotationLayerNode:
  14117. case annotationEditorLayerNode:
  14118. case xfaLayerNode:
  14119. case textLayerNode:
  14120. case canvasWrapperNode:
  14121. continue;
  14122. }
  14123. node.remove();
  14124. const layerIndex = this.#layers.indexOf(node);
  14125. if (layerIndex >= 0) {
  14126. this.#layers[layerIndex] = null;
  14127. }
  14128. }
  14129. div.removeAttribute("data-loaded");
  14130. if (annotationLayerNode) {
  14131. this.annotationLayer.hide();
  14132. }
  14133. if (annotationEditorLayerNode) {
  14134. this.annotationEditorLayer.hide();
  14135. }
  14136. if (xfaLayerNode) {
  14137. this.xfaLayer.hide();
  14138. }
  14139. if (textLayerNode) {
  14140. this.textLayer.hide();
  14141. }
  14142. this.structTreeLayer?.hide();
  14143. if (!keepCanvasWrapper && this.#canvasWrapper) {
  14144. this.#canvasWrapper = null;
  14145. this._resetCanvas();
  14146. }
  14147. if (!preserveDetailViewState) {
  14148. this.detailView?.reset({
  14149. keepCanvas: keepCanvasWrapper
  14150. });
  14151. if (!keepCanvasWrapper) {
  14152. this.detailView = null;
  14153. }
  14154. }
  14155. }
  14156. toggleEditingMode(isEditing) {
  14157. this.#isEditing = isEditing;
  14158. if (!this.hasEditableAnnotations()) {
  14159. return;
  14160. }
  14161. this.reset({
  14162. keepAnnotationLayer: true,
  14163. keepAnnotationEditorLayer: true,
  14164. keepXfaLayer: true,
  14165. keepTextLayer: true,
  14166. keepCanvasWrapper: true
  14167. });
  14168. }
  14169. updateVisibleArea(visibleArea) {
  14170. if (this.enableDetailCanvas) {
  14171. if (this.#needsRestrictedScaling && this.maxCanvasPixels > 0 && visibleArea) {
  14172. this.detailView ??= new PDFPageDetailView({
  14173. pageView: this
  14174. });
  14175. this.detailView.update({
  14176. visibleArea
  14177. });
  14178. } else if (this.detailView) {
  14179. this.detailView.reset();
  14180. this.detailView = null;
  14181. }
  14182. }
  14183. }
  14184. update({
  14185. scale = 0,
  14186. rotation = null,
  14187. optionalContentConfigPromise = null,
  14188. drawingDelay = -1
  14189. }) {
  14190. this.scale = scale || this.scale;
  14191. if (typeof rotation === "number") {
  14192. this.rotation = rotation;
  14193. }
  14194. if (optionalContentConfigPromise instanceof Promise) {
  14195. this._optionalContentConfigPromise = optionalContentConfigPromise;
  14196. optionalContentConfigPromise.then(optionalContentConfig => {
  14197. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  14198. return;
  14199. }
  14200. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  14201. });
  14202. }
  14203. this.#useThumbnailCanvas.directDrawing = true;
  14204. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  14205. this.viewport = this.viewport.clone({
  14206. scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
  14207. rotation: totalRotation
  14208. });
  14209. this.#setDimensions();
  14210. if (this._isStandalone) {
  14211. this._container?.style.setProperty("--scale-factor", this.viewport.scale);
  14212. }
  14213. this.#computeScale();
  14214. if (this.canvas) {
  14215. const onlyCssZoom = this.#hasRestrictedScaling && this.#needsRestrictedScaling;
  14216. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  14217. if (postponeDrawing || onlyCssZoom) {
  14218. if (postponeDrawing && !onlyCssZoom && this.renderingState !== RenderingStates.FINISHED) {
  14219. this.cancelRendering({
  14220. keepAnnotationLayer: true,
  14221. keepAnnotationEditorLayer: true,
  14222. keepXfaLayer: true,
  14223. keepTextLayer: true,
  14224. cancelExtraDelay: drawingDelay
  14225. });
  14226. this.renderingState = RenderingStates.FINISHED;
  14227. this.#useThumbnailCanvas.directDrawing = false;
  14228. }
  14229. this.cssTransform({
  14230. redrawAnnotationLayer: true,
  14231. redrawAnnotationEditorLayer: true,
  14232. redrawXfaLayer: true,
  14233. redrawTextLayer: !postponeDrawing,
  14234. hideTextLayer: postponeDrawing
  14235. });
  14236. if (!postponeDrawing) {
  14237. this.detailView?.update({
  14238. underlyingViewUpdated: true
  14239. });
  14240. this.dispatchPageRendered(true, false);
  14241. }
  14242. return;
  14243. }
  14244. }
  14245. this.cssTransform({});
  14246. this.reset({
  14247. keepAnnotationLayer: true,
  14248. keepAnnotationEditorLayer: true,
  14249. keepXfaLayer: true,
  14250. keepTextLayer: true,
  14251. keepCanvasWrapper: true,
  14252. preserveDetailViewState: true
  14253. });
  14254. this.detailView?.update({
  14255. underlyingViewUpdated: true
  14256. });
  14257. }
  14258. #computeScale() {
  14259. const {
  14260. width,
  14261. height
  14262. } = this.viewport;
  14263. const outputScale = this.outputScale = new OutputScale();
  14264. if (this.maxCanvasPixels === 0) {
  14265. const invScale = 1 / this.scale;
  14266. outputScale.sx *= invScale;
  14267. outputScale.sy *= invScale;
  14268. this.#needsRestrictedScaling = true;
  14269. } else {
  14270. this.#needsRestrictedScaling = outputScale.limitCanvas(width, height, this.maxCanvasPixels, this.maxCanvasDim, this.capCanvasAreaFactor);
  14271. }
  14272. }
  14273. cancelRendering({
  14274. keepAnnotationLayer = false,
  14275. keepAnnotationEditorLayer = false,
  14276. keepXfaLayer = false,
  14277. keepTextLayer = false,
  14278. cancelExtraDelay = 0
  14279. } = {}) {
  14280. super.cancelRendering({
  14281. cancelExtraDelay
  14282. });
  14283. if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
  14284. this.textLayer.cancel();
  14285. this.textLayer = null;
  14286. }
  14287. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  14288. this.annotationLayer.cancel();
  14289. this.annotationLayer = null;
  14290. this._annotationCanvasMap = null;
  14291. }
  14292. if (this.structTreeLayer && !this.textLayer) {
  14293. this.structTreeLayer = null;
  14294. }
  14295. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  14296. if (this.drawLayer) {
  14297. this.drawLayer.cancel();
  14298. this.drawLayer = null;
  14299. }
  14300. this.annotationEditorLayer.cancel();
  14301. this.annotationEditorLayer = null;
  14302. }
  14303. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  14304. this.xfaLayer.cancel();
  14305. this.xfaLayer = null;
  14306. this._textHighlighter?.disable();
  14307. }
  14308. }
  14309. cssTransform({
  14310. redrawAnnotationLayer = false,
  14311. redrawAnnotationEditorLayer = false,
  14312. redrawXfaLayer = false,
  14313. redrawTextLayer = false,
  14314. hideTextLayer = false
  14315. }) {
  14316. const {
  14317. canvas
  14318. } = this;
  14319. if (!canvas) {
  14320. return;
  14321. }
  14322. const originalViewport = this.#originalViewport;
  14323. if (this.viewport !== originalViewport) {
  14324. const relativeRotation = (360 + this.viewport.rotation - originalViewport.rotation) % 360;
  14325. if (relativeRotation === 90 || relativeRotation === 270) {
  14326. const {
  14327. width,
  14328. height
  14329. } = this.viewport;
  14330. const scaleX = height / width;
  14331. const scaleY = width / height;
  14332. canvas.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX},${scaleY})`;
  14333. } else {
  14334. canvas.style.transform = relativeRotation === 0 ? "" : `rotate(${relativeRotation}deg)`;
  14335. }
  14336. }
  14337. if (redrawAnnotationLayer && this.annotationLayer) {
  14338. this.#renderAnnotationLayer();
  14339. }
  14340. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  14341. if (this.drawLayer) {
  14342. this.#renderDrawLayer();
  14343. }
  14344. this.#renderAnnotationEditorLayer();
  14345. }
  14346. if (redrawXfaLayer && this.xfaLayer) {
  14347. this.#renderXfaLayer();
  14348. }
  14349. if (this.textLayer) {
  14350. if (hideTextLayer) {
  14351. this.textLayer.hide();
  14352. this.structTreeLayer?.hide();
  14353. } else if (redrawTextLayer) {
  14354. this.#renderTextLayer();
  14355. }
  14356. }
  14357. }
  14358. get width() {
  14359. return this.viewport.width;
  14360. }
  14361. get height() {
  14362. return this.viewport.height;
  14363. }
  14364. getPagePoint(x, y) {
  14365. return this.viewport.convertToPdfPoint(x, y);
  14366. }
  14367. _ensureCanvasWrapper() {
  14368. let canvasWrapper = this.#canvasWrapper;
  14369. if (!canvasWrapper) {
  14370. canvasWrapper = this.#canvasWrapper = document.createElement("div");
  14371. canvasWrapper.classList.add("canvasWrapper");
  14372. this.#addLayer(canvasWrapper, "canvasWrapper");
  14373. }
  14374. return canvasWrapper;
  14375. }
  14376. _getRenderingContext(canvasContext, transform) {
  14377. return {
  14378. canvasContext,
  14379. transform,
  14380. viewport: this.viewport,
  14381. annotationMode: this.#annotationMode,
  14382. optionalContentConfigPromise: this._optionalContentConfigPromise,
  14383. annotationCanvasMap: this._annotationCanvasMap,
  14384. pageColors: this.pageColors,
  14385. isEditing: this.#isEditing
  14386. };
  14387. }
  14388. async draw() {
  14389. if (this.renderingState !== RenderingStates.INITIAL) {
  14390. console.error("Must be in new state before drawing");
  14391. this.reset();
  14392. }
  14393. const {
  14394. div,
  14395. l10n,
  14396. pdfPage,
  14397. viewport
  14398. } = this;
  14399. if (!pdfPage) {
  14400. this.renderingState = RenderingStates.FINISHED;
  14401. throw new Error("pdfPage is not loaded");
  14402. }
  14403. this.renderingState = RenderingStates.RUNNING;
  14404. const canvasWrapper = this._ensureCanvasWrapper();
  14405. if (!this.textLayer && this.#textLayerMode !== TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
  14406. this._accessibilityManager ||= new TextAccessibilityManager();
  14407. this.textLayer = new TextLayerBuilder({
  14408. pdfPage,
  14409. highlighter: this._textHighlighter,
  14410. accessibilityManager: this._accessibilityManager,
  14411. enablePermissions: this.#textLayerMode === TextLayerMode.ENABLE_PERMISSIONS,
  14412. onAppend: textLayerDiv => {
  14413. this.l10n.pause();
  14414. this.#addLayer(textLayerDiv, "textLayer");
  14415. this.l10n.resume();
  14416. }
  14417. });
  14418. }
  14419. if (!this.annotationLayer && this.#annotationMode !== AnnotationMode.DISABLE) {
  14420. const {
  14421. annotationStorage,
  14422. annotationEditorUIManager,
  14423. downloadManager,
  14424. enableScripting,
  14425. fieldObjectsPromise,
  14426. hasJSActionsPromise,
  14427. linkService
  14428. } = this.#layerProperties;
  14429. this._annotationCanvasMap ||= new Map();
  14430. this.annotationLayer = new AnnotationLayerBuilder({
  14431. pdfPage,
  14432. annotationStorage,
  14433. imageResourcesPath: this.imageResourcesPath,
  14434. renderForms: this.#annotationMode === AnnotationMode.ENABLE_FORMS,
  14435. linkService,
  14436. downloadManager,
  14437. enableScripting,
  14438. hasJSActionsPromise,
  14439. fieldObjectsPromise,
  14440. annotationCanvasMap: this._annotationCanvasMap,
  14441. accessibilityManager: this._accessibilityManager,
  14442. annotationEditorUIManager,
  14443. onAppend: annotationLayerDiv => {
  14444. this.#addLayer(annotationLayerDiv, "annotationLayer");
  14445. }
  14446. });
  14447. }
  14448. const {
  14449. width,
  14450. height
  14451. } = viewport;
  14452. this.#originalViewport = viewport;
  14453. const {
  14454. canvas,
  14455. prevCanvas,
  14456. ctx
  14457. } = this._createCanvas(newCanvas => {
  14458. canvasWrapper.prepend(newCanvas);
  14459. });
  14460. canvas.setAttribute("role", "presentation");
  14461. if (!this.outputScale) {
  14462. this.#computeScale();
  14463. }
  14464. const {
  14465. outputScale
  14466. } = this;
  14467. this.#hasRestrictedScaling = this.#needsRestrictedScaling;
  14468. const sfx = approximateFraction(outputScale.sx);
  14469. const sfy = approximateFraction(outputScale.sy);
  14470. const canvasWidth = canvas.width = floorToDivide(calcRound(width * outputScale.sx), sfx[0]);
  14471. const canvasHeight = canvas.height = floorToDivide(calcRound(height * outputScale.sy), sfy[0]);
  14472. const pageWidth = floorToDivide(calcRound(width), sfx[1]);
  14473. const pageHeight = floorToDivide(calcRound(height), sfy[1]);
  14474. outputScale.sx = canvasWidth / pageWidth;
  14475. outputScale.sy = canvasHeight / pageHeight;
  14476. if (this.#scaleRoundX !== sfx[1]) {
  14477. div.style.setProperty("--scale-round-x", `${sfx[1]}px`);
  14478. this.#scaleRoundX = sfx[1];
  14479. }
  14480. if (this.#scaleRoundY !== sfy[1]) {
  14481. div.style.setProperty("--scale-round-y", `${sfy[1]}px`);
  14482. this.#scaleRoundY = sfy[1];
  14483. }
  14484. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  14485. const resultPromise = this._drawCanvas(this._getRenderingContext(ctx, transform), () => {
  14486. prevCanvas?.remove();
  14487. this._resetCanvas();
  14488. }, renderTask => {
  14489. this.#useThumbnailCanvas.regularAnnotations = !renderTask.separateAnnots;
  14490. this.dispatchPageRendered(false, false);
  14491. }).then(async () => {
  14492. this.structTreeLayer ||= new StructTreeLayerBuilder(pdfPage, viewport.rawDims);
  14493. const textLayerPromise = this.#renderTextLayer();
  14494. if (this.annotationLayer) {
  14495. await this.#renderAnnotationLayer();
  14496. if (this.#enableAutoLinking && this.annotationLayer && this.textLayer) {
  14497. await this.#injectLinkAnnotations(textLayerPromise);
  14498. }
  14499. }
  14500. const {
  14501. annotationEditorUIManager
  14502. } = this.#layerProperties;
  14503. if (!annotationEditorUIManager) {
  14504. return;
  14505. }
  14506. this.drawLayer ||= new DrawLayerBuilder({
  14507. pageIndex: this.id
  14508. });
  14509. await this.#renderDrawLayer();
  14510. this.drawLayer.setParent(canvasWrapper);
  14511. this.annotationEditorLayer ||= new AnnotationEditorLayerBuilder({
  14512. uiManager: annotationEditorUIManager,
  14513. pdfPage,
  14514. l10n,
  14515. structTreeLayer: this.structTreeLayer,
  14516. accessibilityManager: this._accessibilityManager,
  14517. annotationLayer: this.annotationLayer?.annotationLayer,
  14518. textLayer: this.textLayer,
  14519. drawLayer: this.drawLayer.getDrawLayer(),
  14520. onAppend: annotationEditorLayerDiv => {
  14521. this.#addLayer(annotationEditorLayerDiv, "annotationEditorLayer");
  14522. }
  14523. });
  14524. this.#renderAnnotationEditorLayer();
  14525. });
  14526. if (pdfPage.isPureXfa) {
  14527. if (!this.xfaLayer) {
  14528. const {
  14529. annotationStorage,
  14530. linkService
  14531. } = this.#layerProperties;
  14532. this.xfaLayer = new XfaLayerBuilder({
  14533. pdfPage,
  14534. annotationStorage,
  14535. linkService
  14536. });
  14537. }
  14538. this.#renderXfaLayer();
  14539. }
  14540. div.setAttribute("data-loaded", true);
  14541. this.dispatchPageRender();
  14542. return resultPromise;
  14543. }
  14544. setPageLabel(label) {
  14545. this.pageLabel = typeof label === "string" ? label : null;
  14546. this.div.setAttribute("data-l10n-args", JSON.stringify({
  14547. page: this.pageLabel ?? this.id
  14548. }));
  14549. if (this.pageLabel !== null) {
  14550. this.div.setAttribute("data-page-label", this.pageLabel);
  14551. } else {
  14552. this.div.removeAttribute("data-page-label");
  14553. }
  14554. }
  14555. get thumbnailCanvas() {
  14556. const {
  14557. directDrawing,
  14558. initialOptionalContent,
  14559. regularAnnotations
  14560. } = this.#useThumbnailCanvas;
  14561. return directDrawing && initialOptionalContent && regularAnnotations ? this.canvas : null;
  14562. }
  14563. }
  14564. ;// ./web/pdf_viewer.js
  14565. const DEFAULT_CACHE_SIZE = 10;
  14566. const PagesCountLimit = {
  14567. FORCE_SCROLL_MODE_PAGE: 10000,
  14568. FORCE_LAZY_PAGE_INIT: 5000,
  14569. PAUSE_EAGER_PAGE_INIT: 250
  14570. };
  14571. function isValidAnnotationEditorMode(mode) {
  14572. return Object.values(AnnotationEditorType).includes(mode) && mode !== AnnotationEditorType.DISABLE;
  14573. }
  14574. class PDFPageViewBuffer {
  14575. #buf = new Set();
  14576. #size = 0;
  14577. constructor(size) {
  14578. this.#size = size;
  14579. }
  14580. push(view) {
  14581. const buf = this.#buf;
  14582. if (buf.has(view)) {
  14583. buf.delete(view);
  14584. }
  14585. buf.add(view);
  14586. if (buf.size > this.#size) {
  14587. this.#destroyFirstView();
  14588. }
  14589. }
  14590. resize(newSize, idsToKeep = null) {
  14591. this.#size = newSize;
  14592. const buf = this.#buf;
  14593. if (idsToKeep) {
  14594. const ii = buf.size;
  14595. let i = 1;
  14596. for (const view of buf) {
  14597. if (idsToKeep.has(view.id)) {
  14598. buf.delete(view);
  14599. buf.add(view);
  14600. }
  14601. if (++i > ii) {
  14602. break;
  14603. }
  14604. }
  14605. }
  14606. while (buf.size > this.#size) {
  14607. this.#destroyFirstView();
  14608. }
  14609. }
  14610. has(view) {
  14611. return this.#buf.has(view);
  14612. }
  14613. [Symbol.iterator]() {
  14614. return this.#buf.keys();
  14615. }
  14616. #destroyFirstView() {
  14617. const firstView = this.#buf.keys().next().value;
  14618. firstView?.destroy();
  14619. this.#buf.delete(firstView);
  14620. }
  14621. }
  14622. class PDFViewer {
  14623. #buffer = null;
  14624. #altTextManager = null;
  14625. #annotationEditorHighlightColors = null;
  14626. #annotationEditorMode = AnnotationEditorType.NONE;
  14627. #annotationEditorUIManager = null;
  14628. #annotationMode = AnnotationMode.ENABLE_FORMS;
  14629. #containerTopLeft = null;
  14630. #editorUndoBar = null;
  14631. #enableHWA = false;
  14632. #enableHighlightFloatingButton = false;
  14633. #enablePermissions = false;
  14634. #enableUpdatedAddImage = false;
  14635. #enableNewAltTextWhenAddingImage = false;
  14636. #enableAutoLinking = true;
  14637. #eventAbortController = null;
  14638. #minDurationToUpdateCanvas = 0;
  14639. #mlManager = null;
  14640. #scrollTimeoutId = null;
  14641. #switchAnnotationEditorModeAC = null;
  14642. #switchAnnotationEditorModeTimeoutId = null;
  14643. #getAllTextInProgress = false;
  14644. #hiddenCopyElement = null;
  14645. #interruptCopyCondition = false;
  14646. #previousContainerHeight = 0;
  14647. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  14648. #scrollModePageState = null;
  14649. #scaleTimeoutId = null;
  14650. #signatureManager = null;
  14651. #supportsPinchToZoom = true;
  14652. #textLayerMode = TextLayerMode.ENABLE;
  14653. constructor(options) {
  14654. const viewerVersion = "5.3.31";
  14655. if (version !== viewerVersion) {
  14656. throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`);
  14657. }
  14658. this.container = options.container;
  14659. this.viewer = options.viewer || options.container.firstElementChild;
  14660. if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
  14661. throw new Error("Invalid `container` and/or `viewer` option.");
  14662. }
  14663. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  14664. throw new Error("The `container` must be absolutely positioned.");
  14665. }
  14666. this.#resizeObserver.observe(this.container);
  14667. this.eventBus = options.eventBus;
  14668. this.linkService = options.linkService || new SimpleLinkService();
  14669. this.downloadManager = options.downloadManager || null;
  14670. this.findController = options.findController || null;
  14671. this.#altTextManager = options.altTextManager || null;
  14672. this.#signatureManager = options.signatureManager || null;
  14673. this.#editorUndoBar = options.editorUndoBar || null;
  14674. if (this.findController) {
  14675. this.findController.onIsPageVisible = pageNumber => this._getVisiblePages().ids.has(pageNumber);
  14676. }
  14677. this._scriptingManager = options.scriptingManager || null;
  14678. this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
  14679. this.#annotationMode = options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
  14680. this.#annotationEditorMode = options.annotationEditorMode ?? AnnotationEditorType.NONE;
  14681. this.#annotationEditorHighlightColors = options.annotationEditorHighlightColors || null;
  14682. this.#enableHighlightFloatingButton = options.enableHighlightFloatingButton === true;
  14683. this.#enableUpdatedAddImage = options.enableUpdatedAddImage === true;
  14684. this.#enableNewAltTextWhenAddingImage = options.enableNewAltTextWhenAddingImage === true;
  14685. this.imageResourcesPath = options.imageResourcesPath || "";
  14686. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  14687. this.removePageBorders = options.removePageBorders || false;
  14688. this.maxCanvasPixels = options.maxCanvasPixels;
  14689. this.maxCanvasDim = options.maxCanvasDim;
  14690. this.capCanvasAreaFactor = options.capCanvasAreaFactor;
  14691. this.enableDetailCanvas = options.enableDetailCanvas ?? true;
  14692. this.l10n = options.l10n;
  14693. this.l10n ||= new genericl10n_GenericL10n();
  14694. this.#enablePermissions = options.enablePermissions || false;
  14695. this.pageColors = options.pageColors || null;
  14696. this.#mlManager = options.mlManager || null;
  14697. this.#enableHWA = options.enableHWA || false;
  14698. this.#supportsPinchToZoom = options.supportsPinchToZoom !== false;
  14699. this.#enableAutoLinking = options.enableAutoLinking !== false;
  14700. this.#minDurationToUpdateCanvas = options.minDurationToUpdateCanvas ?? 500;
  14701. this.defaultRenderingQueue = !options.renderingQueue;
  14702. if (this.defaultRenderingQueue) {
  14703. this.renderingQueue = new PDFRenderingQueue();
  14704. this.renderingQueue.setViewer(this);
  14705. } else {
  14706. this.renderingQueue = options.renderingQueue;
  14707. }
  14708. const {
  14709. abortSignal
  14710. } = options;
  14711. abortSignal?.addEventListener("abort", () => {
  14712. this.#resizeObserver.disconnect();
  14713. this.#resizeObserver = null;
  14714. }, {
  14715. once: true
  14716. });
  14717. this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this), abortSignal);
  14718. this.presentationModeState = PresentationModeState.UNKNOWN;
  14719. this._resetView();
  14720. if (this.removePageBorders) {
  14721. this.viewer.classList.add("removePageBorders");
  14722. }
  14723. this.#updateContainerHeightCss();
  14724. this.eventBus._on("thumbnailrendered", ({
  14725. pageNumber,
  14726. pdfPage
  14727. }) => {
  14728. const pageView = this._pages[pageNumber - 1];
  14729. if (!this.#buffer.has(pageView)) {
  14730. pdfPage?.cleanup();
  14731. }
  14732. });
  14733. if (!options.l10n) {
  14734. this.l10n.translate(this.container);
  14735. }
  14736. }
  14737. get pagesCount() {
  14738. return this._pages.length;
  14739. }
  14740. getPageView(index) {
  14741. return this._pages[index];
  14742. }
  14743. getCachedPageViews() {
  14744. return new Set(this.#buffer);
  14745. }
  14746. get pageViewsReady() {
  14747. return this._pages.every(pageView => pageView?.pdfPage);
  14748. }
  14749. get renderForms() {
  14750. return this.#annotationMode === AnnotationMode.ENABLE_FORMS;
  14751. }
  14752. get enableScripting() {
  14753. return !!this._scriptingManager;
  14754. }
  14755. get currentPageNumber() {
  14756. return this._currentPageNumber;
  14757. }
  14758. set currentPageNumber(val) {
  14759. if (!Number.isInteger(val)) {
  14760. throw new Error("Invalid page number.");
  14761. }
  14762. if (!this.pdfDocument) {
  14763. return;
  14764. }
  14765. if (!this._setCurrentPageNumber(val, true)) {
  14766. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  14767. }
  14768. }
  14769. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  14770. if (this._currentPageNumber === val) {
  14771. if (resetCurrentPageView) {
  14772. this.#resetCurrentPageView();
  14773. }
  14774. return true;
  14775. }
  14776. if (!(0 < val && val <= this.pagesCount)) {
  14777. return false;
  14778. }
  14779. const previous = this._currentPageNumber;
  14780. this._currentPageNumber = val;
  14781. this.eventBus.dispatch("pagechanging", {
  14782. source: this,
  14783. pageNumber: val,
  14784. pageLabel: this._pageLabels?.[val - 1] ?? null,
  14785. previous
  14786. });
  14787. if (resetCurrentPageView) {
  14788. this.#resetCurrentPageView();
  14789. }
  14790. return true;
  14791. }
  14792. get currentPageLabel() {
  14793. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  14794. }
  14795. set currentPageLabel(val) {
  14796. if (!this.pdfDocument) {
  14797. return;
  14798. }
  14799. let page = val | 0;
  14800. if (this._pageLabels) {
  14801. const i = this._pageLabels.indexOf(val);
  14802. if (i >= 0) {
  14803. page = i + 1;
  14804. }
  14805. }
  14806. if (!this._setCurrentPageNumber(page, true)) {
  14807. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  14808. }
  14809. }
  14810. get currentScale() {
  14811. return this._currentScale !== UNKNOWN_SCALE ? this._currentScale : DEFAULT_SCALE;
  14812. }
  14813. set currentScale(val) {
  14814. if (isNaN(val)) {
  14815. throw new Error("Invalid numeric scale.");
  14816. }
  14817. if (!this.pdfDocument) {
  14818. return;
  14819. }
  14820. this.#setScale(val, {
  14821. noScroll: false
  14822. });
  14823. }
  14824. get currentScaleValue() {
  14825. return this._currentScaleValue;
  14826. }
  14827. set currentScaleValue(val) {
  14828. if (!this.pdfDocument) {
  14829. return;
  14830. }
  14831. this.#setScale(val, {
  14832. noScroll: false
  14833. });
  14834. }
  14835. get pagesRotation() {
  14836. return this._pagesRotation;
  14837. }
  14838. set pagesRotation(rotation) {
  14839. if (!isValidRotation(rotation)) {
  14840. throw new Error("Invalid pages rotation angle.");
  14841. }
  14842. if (!this.pdfDocument) {
  14843. return;
  14844. }
  14845. rotation %= 360;
  14846. if (rotation < 0) {
  14847. rotation += 360;
  14848. }
  14849. if (this._pagesRotation === rotation) {
  14850. return;
  14851. }
  14852. this._pagesRotation = rotation;
  14853. const pageNumber = this._currentPageNumber;
  14854. this.refresh(true, {
  14855. rotation
  14856. });
  14857. if (this._currentScaleValue) {
  14858. this.#setScale(this._currentScaleValue, {
  14859. noScroll: true
  14860. });
  14861. }
  14862. this.eventBus.dispatch("rotationchanging", {
  14863. source: this,
  14864. pagesRotation: rotation,
  14865. pageNumber
  14866. });
  14867. if (this.defaultRenderingQueue) {
  14868. this.update();
  14869. }
  14870. }
  14871. get firstPagePromise() {
  14872. return this.pdfDocument ? this._firstPageCapability.promise : null;
  14873. }
  14874. get onePageRendered() {
  14875. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  14876. }
  14877. get pagesPromise() {
  14878. return this.pdfDocument ? this._pagesCapability.promise : null;
  14879. }
  14880. get _layerProperties() {
  14881. const self = this;
  14882. return shadow(this, "_layerProperties", {
  14883. get annotationEditorUIManager() {
  14884. return self.#annotationEditorUIManager;
  14885. },
  14886. get annotationStorage() {
  14887. return self.pdfDocument?.annotationStorage;
  14888. },
  14889. get downloadManager() {
  14890. return self.downloadManager;
  14891. },
  14892. get enableScripting() {
  14893. return !!self._scriptingManager;
  14894. },
  14895. get fieldObjectsPromise() {
  14896. return self.pdfDocument?.getFieldObjects();
  14897. },
  14898. get findController() {
  14899. return self.findController;
  14900. },
  14901. get hasJSActionsPromise() {
  14902. return self.pdfDocument?.hasJSActions();
  14903. },
  14904. get linkService() {
  14905. return self.linkService;
  14906. }
  14907. });
  14908. }
  14909. #initializePermissions(permissions) {
  14910. const params = {
  14911. annotationEditorMode: this.#annotationEditorMode,
  14912. annotationMode: this.#annotationMode,
  14913. textLayerMode: this.#textLayerMode
  14914. };
  14915. if (!permissions) {
  14916. return params;
  14917. }
  14918. if (!permissions.includes(PermissionFlag.COPY) && this.#textLayerMode === TextLayerMode.ENABLE) {
  14919. params.textLayerMode = TextLayerMode.ENABLE_PERMISSIONS;
  14920. }
  14921. if (!permissions.includes(PermissionFlag.MODIFY_CONTENTS)) {
  14922. params.annotationEditorMode = AnnotationEditorType.DISABLE;
  14923. }
  14924. if (!permissions.includes(PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === AnnotationMode.ENABLE_FORMS) {
  14925. params.annotationMode = AnnotationMode.ENABLE;
  14926. }
  14927. return params;
  14928. }
  14929. async #onePageRenderedOrForceFetch(signal) {
  14930. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  14931. return;
  14932. }
  14933. const hiddenCapability = Promise.withResolvers(),
  14934. ac = new AbortController();
  14935. document.addEventListener("visibilitychange", () => {
  14936. if (document.visibilityState === "hidden") {
  14937. hiddenCapability.resolve();
  14938. }
  14939. }, {
  14940. signal: AbortSignal.any([signal, ac.signal])
  14941. });
  14942. await Promise.race([this._onePageRenderedCapability.promise, hiddenCapability.promise]);
  14943. ac.abort();
  14944. }
  14945. async getAllText() {
  14946. const texts = [];
  14947. const buffer = [];
  14948. for (let pageNum = 1, pagesCount = this.pdfDocument.numPages; pageNum <= pagesCount; ++pageNum) {
  14949. if (this.#interruptCopyCondition) {
  14950. return null;
  14951. }
  14952. buffer.length = 0;
  14953. const page = await this.pdfDocument.getPage(pageNum);
  14954. const {
  14955. items
  14956. } = await page.getTextContent();
  14957. for (const item of items) {
  14958. if (item.str) {
  14959. buffer.push(item.str);
  14960. }
  14961. if (item.hasEOL) {
  14962. buffer.push("\n");
  14963. }
  14964. }
  14965. texts.push(removeNullCharacters(buffer.join("")));
  14966. }
  14967. return texts.join("\n");
  14968. }
  14969. #copyCallback(textLayerMode, event) {
  14970. const selection = document.getSelection();
  14971. const {
  14972. focusNode,
  14973. anchorNode
  14974. } = selection;
  14975. if (anchorNode && focusNode && selection.containsNode(this.#hiddenCopyElement)) {
  14976. if (this.#getAllTextInProgress || textLayerMode === TextLayerMode.ENABLE_PERMISSIONS) {
  14977. stopEvent(event);
  14978. return;
  14979. }
  14980. this.#getAllTextInProgress = true;
  14981. const {
  14982. classList
  14983. } = this.viewer;
  14984. classList.add("copyAll");
  14985. const ac = new AbortController();
  14986. window.addEventListener("keydown", ev => this.#interruptCopyCondition = ev.key === "Escape", {
  14987. signal: ac.signal
  14988. });
  14989. this.getAllText().then(async text => {
  14990. if (text !== null) {
  14991. await navigator.clipboard.writeText(text);
  14992. }
  14993. }).catch(reason => {
  14994. console.warn(`Something goes wrong when extracting the text: ${reason.message}`);
  14995. }).finally(() => {
  14996. this.#getAllTextInProgress = false;
  14997. this.#interruptCopyCondition = false;
  14998. ac.abort();
  14999. classList.remove("copyAll");
  15000. });
  15001. stopEvent(event);
  15002. }
  15003. }
  15004. setDocument(pdfDocument) {
  15005. if (this.pdfDocument) {
  15006. this.eventBus.dispatch("pagesdestroy", {
  15007. source: this
  15008. });
  15009. this._cancelRendering();
  15010. this._resetView();
  15011. this.findController?.setDocument(null);
  15012. this._scriptingManager?.setDocument(null);
  15013. this.#annotationEditorUIManager?.destroy();
  15014. this.#annotationEditorUIManager = null;
  15015. }
  15016. this.pdfDocument = pdfDocument;
  15017. if (!pdfDocument) {
  15018. return;
  15019. }
  15020. const pagesCount = pdfDocument.numPages;
  15021. const firstPagePromise = pdfDocument.getPage(1);
  15022. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({
  15023. intent: "display"
  15024. });
  15025. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  15026. const {
  15027. eventBus,
  15028. pageColors,
  15029. viewer
  15030. } = this;
  15031. this.#eventAbortController = new AbortController();
  15032. const {
  15033. signal
  15034. } = this.#eventAbortController;
  15035. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  15036. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  15037. const mode = this._scrollMode = ScrollMode.PAGE;
  15038. eventBus.dispatch("scrollmodechanged", {
  15039. source: this,
  15040. mode
  15041. });
  15042. }
  15043. this._pagesCapability.promise.then(() => {
  15044. eventBus.dispatch("pagesloaded", {
  15045. source: this,
  15046. pagesCount
  15047. });
  15048. }, () => {});
  15049. const onBeforeDraw = evt => {
  15050. const pageView = this._pages[evt.pageNumber - 1];
  15051. if (!pageView) {
  15052. return;
  15053. }
  15054. this.#buffer.push(pageView);
  15055. };
  15056. eventBus._on("pagerender", onBeforeDraw, {
  15057. signal
  15058. });
  15059. const onAfterDraw = evt => {
  15060. if (evt.cssTransform || evt.isDetailView) {
  15061. return;
  15062. }
  15063. this._onePageRenderedCapability.resolve({
  15064. timestamp: evt.timestamp
  15065. });
  15066. eventBus._off("pagerendered", onAfterDraw);
  15067. };
  15068. eventBus._on("pagerendered", onAfterDraw, {
  15069. signal
  15070. });
  15071. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  15072. if (pdfDocument !== this.pdfDocument) {
  15073. return;
  15074. }
  15075. this._firstPageCapability.resolve(firstPdfPage);
  15076. this._optionalContentConfigPromise = optionalContentConfigPromise;
  15077. const {
  15078. annotationEditorMode,
  15079. annotationMode,
  15080. textLayerMode
  15081. } = this.#initializePermissions(permissions);
  15082. if (textLayerMode !== TextLayerMode.DISABLE) {
  15083. const element = this.#hiddenCopyElement = document.createElement("div");
  15084. element.id = "hiddenCopyElement";
  15085. viewer.before(element);
  15086. }
  15087. if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
  15088. const mode = annotationEditorMode;
  15089. if (pdfDocument.isPureXfa) {
  15090. console.warn("Warning: XFA-editing is not implemented.");
  15091. } else if (isValidAnnotationEditorMode(mode)) {
  15092. this.#annotationEditorUIManager = new AnnotationEditorUIManager(this.container, viewer, this.#altTextManager, this.#signatureManager, eventBus, pdfDocument, pageColors, this.#annotationEditorHighlightColors, this.#enableHighlightFloatingButton, this.#enableUpdatedAddImage, this.#enableNewAltTextWhenAddingImage, this.#mlManager, this.#editorUndoBar, this.#supportsPinchToZoom);
  15093. eventBus.dispatch("annotationeditoruimanager", {
  15094. source: this,
  15095. uiManager: this.#annotationEditorUIManager
  15096. });
  15097. if (mode !== AnnotationEditorType.NONE) {
  15098. this.#preloadEditingData(mode);
  15099. this.#annotationEditorUIManager.updateMode(mode);
  15100. }
  15101. } else {
  15102. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  15103. }
  15104. }
  15105. const viewerElement = this._scrollMode === ScrollMode.PAGE ? null : viewer;
  15106. const scale = this.currentScale;
  15107. const viewport = firstPdfPage.getViewport({
  15108. scale: scale * PixelsPerInch.PDF_TO_CSS_UNITS
  15109. });
  15110. viewer.style.setProperty("--scale-factor", viewport.scale);
  15111. if (pageColors?.background) {
  15112. viewer.style.setProperty("--page-bg-color", pageColors.background);
  15113. }
  15114. if (pageColors?.foreground === "CanvasText" || pageColors?.background === "Canvas") {
  15115. viewer.style.setProperty("--hcm-highlight-filter", pdfDocument.filterFactory.addHighlightHCMFilter("highlight", "CanvasText", "Canvas", "HighlightText", "Highlight"));
  15116. viewer.style.setProperty("--hcm-highlight-selected-filter", pdfDocument.filterFactory.addHighlightHCMFilter("highlight_selected", "CanvasText", "Canvas", "HighlightText", "ButtonText"));
  15117. }
  15118. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  15119. const pageView = new PDFPageView({
  15120. container: viewerElement,
  15121. eventBus,
  15122. id: pageNum,
  15123. scale,
  15124. defaultViewport: viewport.clone(),
  15125. optionalContentConfigPromise,
  15126. renderingQueue: this.renderingQueue,
  15127. textLayerMode,
  15128. annotationMode,
  15129. imageResourcesPath: this.imageResourcesPath,
  15130. maxCanvasPixels: this.maxCanvasPixels,
  15131. maxCanvasDim: this.maxCanvasDim,
  15132. capCanvasAreaFactor: this.capCanvasAreaFactor,
  15133. enableDetailCanvas: this.enableDetailCanvas,
  15134. pageColors,
  15135. l10n: this.l10n,
  15136. layerProperties: this._layerProperties,
  15137. enableHWA: this.#enableHWA,
  15138. enableAutoLinking: this.#enableAutoLinking,
  15139. minDurationToUpdateCanvas: this.#minDurationToUpdateCanvas
  15140. });
  15141. this._pages.push(pageView);
  15142. }
  15143. this._pages[0]?.setPdfPage(firstPdfPage);
  15144. if (this._scrollMode === ScrollMode.PAGE) {
  15145. this.#ensurePageViewVisible();
  15146. } else if (this._spreadMode !== SpreadMode.NONE) {
  15147. this._updateSpreadMode();
  15148. }
  15149. this.#onePageRenderedOrForceFetch(signal).then(async () => {
  15150. if (pdfDocument !== this.pdfDocument) {
  15151. return;
  15152. }
  15153. this.findController?.setDocument(pdfDocument);
  15154. this._scriptingManager?.setDocument(pdfDocument);
  15155. if (this.#hiddenCopyElement) {
  15156. document.addEventListener("copy", this.#copyCallback.bind(this, textLayerMode), {
  15157. signal
  15158. });
  15159. }
  15160. if (this.#annotationEditorUIManager) {
  15161. eventBus.dispatch("annotationeditormodechanged", {
  15162. source: this,
  15163. mode: this.#annotationEditorMode
  15164. });
  15165. }
  15166. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  15167. this._pagesCapability.resolve();
  15168. return;
  15169. }
  15170. let getPagesLeft = pagesCount - 1;
  15171. if (getPagesLeft <= 0) {
  15172. this._pagesCapability.resolve();
  15173. return;
  15174. }
  15175. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  15176. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  15177. const pageView = this._pages[pageNum - 1];
  15178. if (!pageView.pdfPage) {
  15179. pageView.setPdfPage(pdfPage);
  15180. }
  15181. if (--getPagesLeft === 0) {
  15182. this._pagesCapability.resolve();
  15183. }
  15184. }, reason => {
  15185. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  15186. if (--getPagesLeft === 0) {
  15187. this._pagesCapability.resolve();
  15188. }
  15189. });
  15190. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  15191. await promise;
  15192. }
  15193. }
  15194. });
  15195. eventBus.dispatch("pagesinit", {
  15196. source: this
  15197. });
  15198. pdfDocument.getMetadata().then(({
  15199. info
  15200. }) => {
  15201. if (pdfDocument !== this.pdfDocument) {
  15202. return;
  15203. }
  15204. if (info.Language) {
  15205. viewer.lang = info.Language;
  15206. }
  15207. });
  15208. if (this.defaultRenderingQueue) {
  15209. this.update();
  15210. }
  15211. }).catch(reason => {
  15212. console.error("Unable to initialize viewer", reason);
  15213. this._pagesCapability.reject(reason);
  15214. });
  15215. }
  15216. setPageLabels(labels) {
  15217. if (!this.pdfDocument) {
  15218. return;
  15219. }
  15220. if (!labels) {
  15221. this._pageLabels = null;
  15222. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  15223. this._pageLabels = null;
  15224. console.error(`setPageLabels: Invalid page labels.`);
  15225. } else {
  15226. this._pageLabels = labels;
  15227. }
  15228. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  15229. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  15230. }
  15231. }
  15232. _resetView() {
  15233. this._pages = [];
  15234. this._currentPageNumber = 1;
  15235. this._currentScale = UNKNOWN_SCALE;
  15236. this._currentScaleValue = null;
  15237. this._pageLabels = null;
  15238. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  15239. this._location = null;
  15240. this._pagesRotation = 0;
  15241. this._optionalContentConfigPromise = null;
  15242. this._firstPageCapability = Promise.withResolvers();
  15243. this._onePageRenderedCapability = Promise.withResolvers();
  15244. this._pagesCapability = Promise.withResolvers();
  15245. this._scrollMode = ScrollMode.VERTICAL;
  15246. this._previousScrollMode = ScrollMode.UNKNOWN;
  15247. this._spreadMode = SpreadMode.NONE;
  15248. this.#scrollModePageState = {
  15249. previousPageNumber: 1,
  15250. scrollDown: true,
  15251. pages: []
  15252. };
  15253. this.#eventAbortController?.abort();
  15254. this.#eventAbortController = null;
  15255. this.viewer.textContent = "";
  15256. this._updateScrollMode();
  15257. this.viewer.removeAttribute("lang");
  15258. this.#hiddenCopyElement?.remove();
  15259. this.#hiddenCopyElement = null;
  15260. this.#cleanupTimeouts();
  15261. this.#cleanupSwitchAnnotationEditorMode();
  15262. }
  15263. #ensurePageViewVisible() {
  15264. if (this._scrollMode !== ScrollMode.PAGE) {
  15265. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  15266. }
  15267. const pageNumber = this._currentPageNumber,
  15268. state = this.#scrollModePageState,
  15269. viewer = this.viewer;
  15270. viewer.textContent = "";
  15271. state.pages.length = 0;
  15272. if (this._spreadMode === SpreadMode.NONE && !this.isInPresentationMode) {
  15273. const pageView = this._pages[pageNumber - 1];
  15274. viewer.append(pageView.div);
  15275. state.pages.push(pageView);
  15276. } else {
  15277. const pageIndexSet = new Set(),
  15278. parity = this._spreadMode - 1;
  15279. if (parity === -1) {
  15280. pageIndexSet.add(pageNumber - 1);
  15281. } else if (pageNumber % 2 !== parity) {
  15282. pageIndexSet.add(pageNumber - 1);
  15283. pageIndexSet.add(pageNumber);
  15284. } else {
  15285. pageIndexSet.add(pageNumber - 2);
  15286. pageIndexSet.add(pageNumber - 1);
  15287. }
  15288. const spread = document.createElement("div");
  15289. spread.className = "spread";
  15290. if (this.isInPresentationMode) {
  15291. const dummyPage = document.createElement("div");
  15292. dummyPage.className = "dummyPage";
  15293. spread.append(dummyPage);
  15294. }
  15295. for (const i of pageIndexSet) {
  15296. const pageView = this._pages[i];
  15297. if (!pageView) {
  15298. continue;
  15299. }
  15300. spread.append(pageView.div);
  15301. state.pages.push(pageView);
  15302. }
  15303. viewer.append(spread);
  15304. }
  15305. state.scrollDown = pageNumber >= state.previousPageNumber;
  15306. state.previousPageNumber = pageNumber;
  15307. }
  15308. _scrollUpdate() {
  15309. if (this.pagesCount === 0) {
  15310. return;
  15311. }
  15312. if (this.#scrollTimeoutId) {
  15313. clearTimeout(this.#scrollTimeoutId);
  15314. }
  15315. this.#scrollTimeoutId = setTimeout(() => {
  15316. this.#scrollTimeoutId = null;
  15317. this.update();
  15318. }, 100);
  15319. this.update();
  15320. }
  15321. #scrollIntoView(pageView, pageSpot = null) {
  15322. const {
  15323. div,
  15324. id
  15325. } = pageView;
  15326. if (this._currentPageNumber !== id) {
  15327. this._setCurrentPageNumber(id);
  15328. }
  15329. if (this._scrollMode === ScrollMode.PAGE) {
  15330. this.#ensurePageViewVisible();
  15331. this.update();
  15332. }
  15333. if (!pageSpot && !this.isInPresentationMode) {
  15334. const left = div.offsetLeft + div.clientLeft,
  15335. right = left + div.clientWidth;
  15336. const {
  15337. scrollLeft,
  15338. clientWidth
  15339. } = this.container;
  15340. if (this._scrollMode === ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  15341. pageSpot = {
  15342. left: 0,
  15343. top: 0
  15344. };
  15345. }
  15346. }
  15347. scrollIntoView(div, pageSpot);
  15348. if (!this._currentScaleValue && this._location) {
  15349. this._location = null;
  15350. }
  15351. }
  15352. #isSameScale(newScale) {
  15353. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  15354. }
  15355. #setScaleUpdatePages(newScale, newValue, {
  15356. noScroll = false,
  15357. preset = false,
  15358. drawingDelay = -1,
  15359. origin = null
  15360. }) {
  15361. this._currentScaleValue = newValue.toString();
  15362. if (this.#isSameScale(newScale)) {
  15363. if (preset) {
  15364. this.eventBus.dispatch("scalechanging", {
  15365. source: this,
  15366. scale: newScale,
  15367. presetValue: newValue
  15368. });
  15369. }
  15370. return;
  15371. }
  15372. this.viewer.style.setProperty("--scale-factor", newScale * PixelsPerInch.PDF_TO_CSS_UNITS);
  15373. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  15374. this.refresh(true, {
  15375. scale: newScale,
  15376. drawingDelay: postponeDrawing ? drawingDelay : -1
  15377. });
  15378. if (postponeDrawing) {
  15379. this.#scaleTimeoutId = setTimeout(() => {
  15380. this.#scaleTimeoutId = null;
  15381. this.refresh();
  15382. }, drawingDelay);
  15383. }
  15384. const previousScale = this._currentScale;
  15385. this._currentScale = newScale;
  15386. if (!noScroll) {
  15387. let page = this._currentPageNumber,
  15388. dest;
  15389. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  15390. page = this._location.pageNumber;
  15391. dest = [null, {
  15392. name: "XYZ"
  15393. }, this._location.left, this._location.top, null];
  15394. }
  15395. this.scrollPageIntoView({
  15396. pageNumber: page,
  15397. destArray: dest,
  15398. allowNegativeOffset: true
  15399. });
  15400. if (Array.isArray(origin)) {
  15401. const scaleDiff = newScale / previousScale - 1;
  15402. const [top, left] = this.containerTopLeft;
  15403. this.container.scrollLeft += (origin[0] - left) * scaleDiff;
  15404. this.container.scrollTop += (origin[1] - top) * scaleDiff;
  15405. }
  15406. }
  15407. this.eventBus.dispatch("scalechanging", {
  15408. source: this,
  15409. scale: newScale,
  15410. presetValue: preset ? newValue : undefined
  15411. });
  15412. if (this.defaultRenderingQueue) {
  15413. this.update();
  15414. }
  15415. }
  15416. get #pageWidthScaleFactor() {
  15417. if (this._spreadMode !== SpreadMode.NONE && this._scrollMode !== ScrollMode.HORIZONTAL) {
  15418. return 2;
  15419. }
  15420. return 1;
  15421. }
  15422. #setScale(value, options) {
  15423. let scale = parseFloat(value);
  15424. if (scale > 0) {
  15425. options.preset = false;
  15426. this.#setScaleUpdatePages(scale, value, options);
  15427. } else {
  15428. const currentPage = this._pages[this._currentPageNumber - 1];
  15429. if (!currentPage) {
  15430. return;
  15431. }
  15432. let hPadding = SCROLLBAR_PADDING,
  15433. vPadding = VERTICAL_PADDING;
  15434. if (this.isInPresentationMode) {
  15435. hPadding = vPadding = 4;
  15436. if (this._spreadMode !== SpreadMode.NONE) {
  15437. hPadding *= 2;
  15438. }
  15439. } else if (this.removePageBorders) {
  15440. hPadding = vPadding = 0;
  15441. } else if (this._scrollMode === ScrollMode.HORIZONTAL) {
  15442. [hPadding, vPadding] = [vPadding, hPadding];
  15443. }
  15444. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor;
  15445. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  15446. switch (value) {
  15447. case "page-actual":
  15448. scale = 1;
  15449. break;
  15450. case "page-width":
  15451. scale = pageWidthScale;
  15452. break;
  15453. case "page-height":
  15454. scale = pageHeightScale;
  15455. break;
  15456. case "page-fit":
  15457. scale = Math.min(pageWidthScale, pageHeightScale);
  15458. break;
  15459. case "auto":
  15460. const horizontalScale = isPortraitOrientation(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  15461. scale = Math.min(MAX_AUTO_SCALE, horizontalScale);
  15462. break;
  15463. default:
  15464. console.error(`#setScale: "${value}" is an unknown zoom value.`);
  15465. return;
  15466. }
  15467. options.preset = true;
  15468. this.#setScaleUpdatePages(scale, value, options);
  15469. }
  15470. }
  15471. #resetCurrentPageView() {
  15472. const pageView = this._pages[this._currentPageNumber - 1];
  15473. if (this.isInPresentationMode) {
  15474. this.#setScale(this._currentScaleValue, {
  15475. noScroll: true
  15476. });
  15477. }
  15478. this.#scrollIntoView(pageView);
  15479. }
  15480. pageLabelToPageNumber(label) {
  15481. if (!this._pageLabels) {
  15482. return null;
  15483. }
  15484. const i = this._pageLabels.indexOf(label);
  15485. if (i < 0) {
  15486. return null;
  15487. }
  15488. return i + 1;
  15489. }
  15490. scrollPageIntoView({
  15491. pageNumber,
  15492. destArray = null,
  15493. allowNegativeOffset = false,
  15494. ignoreDestinationZoom = false
  15495. }) {
  15496. if (!this.pdfDocument) {
  15497. return;
  15498. }
  15499. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  15500. if (!pageView) {
  15501. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  15502. return;
  15503. }
  15504. if (this.isInPresentationMode || !destArray) {
  15505. this._setCurrentPageNumber(pageNumber, true);
  15506. return;
  15507. }
  15508. let x = 0,
  15509. y = 0;
  15510. let width = 0,
  15511. height = 0,
  15512. widthScale,
  15513. heightScale;
  15514. const changeOrientation = pageView.rotation % 180 !== 0;
  15515. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / PixelsPerInch.PDF_TO_CSS_UNITS;
  15516. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / PixelsPerInch.PDF_TO_CSS_UNITS;
  15517. let scale = 0;
  15518. switch (destArray[1].name) {
  15519. case "XYZ":
  15520. x = destArray[2];
  15521. y = destArray[3];
  15522. scale = destArray[4];
  15523. x = x !== null ? x : 0;
  15524. y = y !== null ? y : pageHeight;
  15525. break;
  15526. case "Fit":
  15527. case "FitB":
  15528. scale = "page-fit";
  15529. break;
  15530. case "FitH":
  15531. case "FitBH":
  15532. y = destArray[2];
  15533. scale = "page-width";
  15534. if (y === null && this._location) {
  15535. x = this._location.left;
  15536. y = this._location.top;
  15537. } else if (typeof y !== "number" || y < 0) {
  15538. y = pageHeight;
  15539. }
  15540. break;
  15541. case "FitV":
  15542. case "FitBV":
  15543. x = destArray[2];
  15544. width = pageWidth;
  15545. height = pageHeight;
  15546. scale = "page-height";
  15547. break;
  15548. case "FitR":
  15549. x = destArray[2];
  15550. y = destArray[3];
  15551. width = destArray[4] - x;
  15552. height = destArray[5] - y;
  15553. let hPadding = SCROLLBAR_PADDING,
  15554. vPadding = VERTICAL_PADDING;
  15555. if (this.removePageBorders) {
  15556. hPadding = vPadding = 0;
  15557. }
  15558. widthScale = (this.container.clientWidth - hPadding) / width / PixelsPerInch.PDF_TO_CSS_UNITS;
  15559. heightScale = (this.container.clientHeight - vPadding) / height / PixelsPerInch.PDF_TO_CSS_UNITS;
  15560. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  15561. break;
  15562. default:
  15563. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  15564. return;
  15565. }
  15566. if (!ignoreDestinationZoom) {
  15567. if (scale && scale !== this._currentScale) {
  15568. this.currentScaleValue = scale;
  15569. } else if (this._currentScale === UNKNOWN_SCALE) {
  15570. this.currentScaleValue = DEFAULT_SCALE_VALUE;
  15571. }
  15572. }
  15573. if (scale === "page-fit" && !destArray[4]) {
  15574. this.#scrollIntoView(pageView);
  15575. return;
  15576. }
  15577. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  15578. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  15579. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  15580. if (!allowNegativeOffset) {
  15581. left = Math.max(left, 0);
  15582. top = Math.max(top, 0);
  15583. }
  15584. this.#scrollIntoView(pageView, {
  15585. left,
  15586. top
  15587. });
  15588. }
  15589. _updateLocation(firstPage) {
  15590. const currentScale = this._currentScale;
  15591. const currentScaleValue = this._currentScaleValue;
  15592. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  15593. const pageNumber = firstPage.id;
  15594. const currentPageView = this._pages[pageNumber - 1];
  15595. const container = this.container;
  15596. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  15597. const intLeft = Math.round(topLeft[0]);
  15598. const intTop = Math.round(topLeft[1]);
  15599. let pdfOpenParams = `#page=${pageNumber}`;
  15600. if (!this.isInPresentationMode) {
  15601. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  15602. }
  15603. this._location = {
  15604. pageNumber,
  15605. scale: normalizedScaleValue,
  15606. top: intTop,
  15607. left: intLeft,
  15608. rotation: this._pagesRotation,
  15609. pdfOpenParams
  15610. };
  15611. }
  15612. update() {
  15613. const visible = this._getVisiblePages();
  15614. const visiblePages = visible.views,
  15615. numVisiblePages = visiblePages.length;
  15616. if (numVisiblePages === 0) {
  15617. return;
  15618. }
  15619. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  15620. this.#buffer.resize(newCacheSize, visible.ids);
  15621. for (const {
  15622. view,
  15623. visibleArea
  15624. } of visiblePages) {
  15625. view.updateVisibleArea(visibleArea);
  15626. }
  15627. for (const view of this.#buffer) {
  15628. if (!visible.ids.has(view.id)) {
  15629. view.updateVisibleArea(null);
  15630. }
  15631. }
  15632. this.renderingQueue.renderHighestPriority(visible);
  15633. const isSimpleLayout = this._spreadMode === SpreadMode.NONE && (this._scrollMode === ScrollMode.PAGE || this._scrollMode === ScrollMode.VERTICAL);
  15634. const currentId = this._currentPageNumber;
  15635. let stillFullyVisible = false;
  15636. for (const page of visiblePages) {
  15637. if (page.percent < 100) {
  15638. break;
  15639. }
  15640. if (page.id === currentId && isSimpleLayout) {
  15641. stillFullyVisible = true;
  15642. break;
  15643. }
  15644. }
  15645. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  15646. this._updateLocation(visible.first);
  15647. this.eventBus.dispatch("updateviewarea", {
  15648. source: this,
  15649. location: this._location
  15650. });
  15651. }
  15652. #switchToEditAnnotationMode() {
  15653. const visible = this._getVisiblePages();
  15654. const pagesToRefresh = [];
  15655. const {
  15656. ids,
  15657. views
  15658. } = visible;
  15659. for (const page of views) {
  15660. const {
  15661. view
  15662. } = page;
  15663. if (!view.hasEditableAnnotations()) {
  15664. ids.delete(view.id);
  15665. continue;
  15666. }
  15667. pagesToRefresh.push(page);
  15668. }
  15669. if (pagesToRefresh.length === 0) {
  15670. return null;
  15671. }
  15672. this.renderingQueue.renderHighestPriority({
  15673. first: pagesToRefresh[0],
  15674. last: pagesToRefresh.at(-1),
  15675. views: pagesToRefresh,
  15676. ids
  15677. });
  15678. return ids;
  15679. }
  15680. containsElement(element) {
  15681. return this.container.contains(element);
  15682. }
  15683. focus() {
  15684. this.container.focus();
  15685. }
  15686. get _isContainerRtl() {
  15687. return getComputedStyle(this.container).direction === "rtl";
  15688. }
  15689. get isInPresentationMode() {
  15690. return this.presentationModeState === PresentationModeState.FULLSCREEN;
  15691. }
  15692. get isChangingPresentationMode() {
  15693. return this.presentationModeState === PresentationModeState.CHANGING;
  15694. }
  15695. get isHorizontalScrollbarEnabled() {
  15696. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  15697. }
  15698. get isVerticalScrollbarEnabled() {
  15699. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  15700. }
  15701. _getVisiblePages() {
  15702. const views = this._scrollMode === ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  15703. horizontal = this._scrollMode === ScrollMode.HORIZONTAL,
  15704. rtl = horizontal && this._isContainerRtl;
  15705. return getVisibleElements({
  15706. scrollEl: this.container,
  15707. views,
  15708. sortByVisibility: true,
  15709. horizontal,
  15710. rtl
  15711. });
  15712. }
  15713. cleanup() {
  15714. for (const pageView of this._pages) {
  15715. if (pageView.renderingState !== RenderingStates.FINISHED) {
  15716. pageView.reset();
  15717. }
  15718. }
  15719. }
  15720. _cancelRendering() {
  15721. for (const pageView of this._pages) {
  15722. pageView.cancelRendering();
  15723. }
  15724. }
  15725. async #ensurePdfPageLoaded(pageView) {
  15726. if (pageView.pdfPage) {
  15727. return pageView.pdfPage;
  15728. }
  15729. try {
  15730. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  15731. if (!pageView.pdfPage) {
  15732. pageView.setPdfPage(pdfPage);
  15733. }
  15734. return pdfPage;
  15735. } catch (reason) {
  15736. console.error("Unable to get page for page view", reason);
  15737. return null;
  15738. }
  15739. }
  15740. #getScrollAhead(visible) {
  15741. if (visible.first?.id === 1) {
  15742. return true;
  15743. } else if (visible.last?.id === this.pagesCount) {
  15744. return false;
  15745. }
  15746. switch (this._scrollMode) {
  15747. case ScrollMode.PAGE:
  15748. return this.#scrollModePageState.scrollDown;
  15749. case ScrollMode.HORIZONTAL:
  15750. return this.scroll.right;
  15751. }
  15752. return this.scroll.down;
  15753. }
  15754. forceRendering(currentlyVisiblePages) {
  15755. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  15756. const scrollAhead = this.#getScrollAhead(visiblePages);
  15757. const preRenderExtra = this._spreadMode !== SpreadMode.NONE && this._scrollMode !== ScrollMode.HORIZONTAL;
  15758. const ignoreDetailViews = this.#scaleTimeoutId !== null || this.#scrollTimeoutId !== null && visiblePages.views.some(page => page.detailView?.renderingCancelled);
  15759. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra, ignoreDetailViews);
  15760. if (pageView) {
  15761. this.#ensurePdfPageLoaded(pageView).then(() => {
  15762. this.renderingQueue.renderView(pageView);
  15763. });
  15764. return true;
  15765. }
  15766. return false;
  15767. }
  15768. get hasEqualPageSizes() {
  15769. const firstPageView = this._pages[0];
  15770. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  15771. const pageView = this._pages[i];
  15772. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  15773. return false;
  15774. }
  15775. }
  15776. return true;
  15777. }
  15778. getPagesOverview() {
  15779. let initialOrientation;
  15780. return this._pages.map(pageView => {
  15781. const viewport = pageView.pdfPage.getViewport({
  15782. scale: 1
  15783. });
  15784. const orientation = isPortraitOrientation(viewport);
  15785. if (initialOrientation === undefined) {
  15786. initialOrientation = orientation;
  15787. } else if (this.enablePrintAutoRotate && orientation !== initialOrientation) {
  15788. return {
  15789. width: viewport.height,
  15790. height: viewport.width,
  15791. rotation: (viewport.rotation - 90) % 360
  15792. };
  15793. }
  15794. return {
  15795. width: viewport.width,
  15796. height: viewport.height,
  15797. rotation: viewport.rotation
  15798. };
  15799. });
  15800. }
  15801. get optionalContentConfigPromise() {
  15802. if (!this.pdfDocument) {
  15803. return Promise.resolve(null);
  15804. }
  15805. if (!this._optionalContentConfigPromise) {
  15806. console.error("optionalContentConfigPromise: Not initialized yet.");
  15807. return this.pdfDocument.getOptionalContentConfig({
  15808. intent: "display"
  15809. });
  15810. }
  15811. return this._optionalContentConfigPromise;
  15812. }
  15813. set optionalContentConfigPromise(promise) {
  15814. if (!(promise instanceof Promise)) {
  15815. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  15816. }
  15817. if (!this.pdfDocument) {
  15818. return;
  15819. }
  15820. if (!this._optionalContentConfigPromise) {
  15821. return;
  15822. }
  15823. this._optionalContentConfigPromise = promise;
  15824. this.refresh(false, {
  15825. optionalContentConfigPromise: promise
  15826. });
  15827. this.eventBus.dispatch("optionalcontentconfigchanged", {
  15828. source: this,
  15829. promise
  15830. });
  15831. }
  15832. get scrollMode() {
  15833. return this._scrollMode;
  15834. }
  15835. set scrollMode(mode) {
  15836. if (this._scrollMode === mode) {
  15837. return;
  15838. }
  15839. if (!isValidScrollMode(mode)) {
  15840. throw new Error(`Invalid scroll mode: ${mode}`);
  15841. }
  15842. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  15843. return;
  15844. }
  15845. this._previousScrollMode = this._scrollMode;
  15846. this._scrollMode = mode;
  15847. this.eventBus.dispatch("scrollmodechanged", {
  15848. source: this,
  15849. mode
  15850. });
  15851. this._updateScrollMode(this._currentPageNumber);
  15852. }
  15853. _updateScrollMode(pageNumber = null) {
  15854. const scrollMode = this._scrollMode,
  15855. viewer = this.viewer;
  15856. viewer.classList.toggle("scrollHorizontal", scrollMode === ScrollMode.HORIZONTAL);
  15857. viewer.classList.toggle("scrollWrapped", scrollMode === ScrollMode.WRAPPED);
  15858. if (!this.pdfDocument || !pageNumber) {
  15859. return;
  15860. }
  15861. if (scrollMode === ScrollMode.PAGE) {
  15862. this.#ensurePageViewVisible();
  15863. } else if (this._previousScrollMode === ScrollMode.PAGE) {
  15864. this._updateSpreadMode();
  15865. }
  15866. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  15867. this.#setScale(this._currentScaleValue, {
  15868. noScroll: true
  15869. });
  15870. }
  15871. this._setCurrentPageNumber(pageNumber, true);
  15872. this.update();
  15873. }
  15874. get spreadMode() {
  15875. return this._spreadMode;
  15876. }
  15877. set spreadMode(mode) {
  15878. if (this._spreadMode === mode) {
  15879. return;
  15880. }
  15881. if (!isValidSpreadMode(mode)) {
  15882. throw new Error(`Invalid spread mode: ${mode}`);
  15883. }
  15884. this._spreadMode = mode;
  15885. this.eventBus.dispatch("spreadmodechanged", {
  15886. source: this,
  15887. mode
  15888. });
  15889. this._updateSpreadMode(this._currentPageNumber);
  15890. }
  15891. _updateSpreadMode(pageNumber = null) {
  15892. if (!this.pdfDocument) {
  15893. return;
  15894. }
  15895. const viewer = this.viewer,
  15896. pages = this._pages;
  15897. if (this._scrollMode === ScrollMode.PAGE) {
  15898. this.#ensurePageViewVisible();
  15899. } else {
  15900. viewer.textContent = "";
  15901. if (this._spreadMode === SpreadMode.NONE) {
  15902. for (const pageView of this._pages) {
  15903. viewer.append(pageView.div);
  15904. }
  15905. } else {
  15906. const parity = this._spreadMode - 1;
  15907. let spread = null;
  15908. for (let i = 0, ii = pages.length; i < ii; ++i) {
  15909. if (spread === null) {
  15910. spread = document.createElement("div");
  15911. spread.className = "spread";
  15912. viewer.append(spread);
  15913. } else if (i % 2 === parity) {
  15914. spread = spread.cloneNode(false);
  15915. viewer.append(spread);
  15916. }
  15917. spread.append(pages[i].div);
  15918. }
  15919. }
  15920. }
  15921. if (!pageNumber) {
  15922. return;
  15923. }
  15924. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  15925. this.#setScale(this._currentScaleValue, {
  15926. noScroll: true
  15927. });
  15928. }
  15929. this._setCurrentPageNumber(pageNumber, true);
  15930. this.update();
  15931. }
  15932. _getPageAdvance(currentPageNumber, previous = false) {
  15933. switch (this._scrollMode) {
  15934. case ScrollMode.WRAPPED:
  15935. {
  15936. const {
  15937. views
  15938. } = this._getVisiblePages(),
  15939. pageLayout = new Map();
  15940. for (const {
  15941. id,
  15942. y,
  15943. percent,
  15944. widthPercent
  15945. } of views) {
  15946. if (percent === 0 || widthPercent < 100) {
  15947. continue;
  15948. }
  15949. let yArray = pageLayout.get(y);
  15950. if (!yArray) {
  15951. pageLayout.set(y, yArray ||= []);
  15952. }
  15953. yArray.push(id);
  15954. }
  15955. for (const yArray of pageLayout.values()) {
  15956. const currentIndex = yArray.indexOf(currentPageNumber);
  15957. if (currentIndex === -1) {
  15958. continue;
  15959. }
  15960. const numPages = yArray.length;
  15961. if (numPages === 1) {
  15962. break;
  15963. }
  15964. if (previous) {
  15965. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  15966. const currentId = yArray[i],
  15967. expectedId = yArray[i + 1] - 1;
  15968. if (currentId < expectedId) {
  15969. return currentPageNumber - expectedId;
  15970. }
  15971. }
  15972. } else {
  15973. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  15974. const currentId = yArray[i],
  15975. expectedId = yArray[i - 1] + 1;
  15976. if (currentId > expectedId) {
  15977. return expectedId - currentPageNumber;
  15978. }
  15979. }
  15980. }
  15981. if (previous) {
  15982. const firstId = yArray[0];
  15983. if (firstId < currentPageNumber) {
  15984. return currentPageNumber - firstId + 1;
  15985. }
  15986. } else {
  15987. const lastId = yArray[numPages - 1];
  15988. if (lastId > currentPageNumber) {
  15989. return lastId - currentPageNumber + 1;
  15990. }
  15991. }
  15992. break;
  15993. }
  15994. break;
  15995. }
  15996. case ScrollMode.HORIZONTAL:
  15997. {
  15998. break;
  15999. }
  16000. case ScrollMode.PAGE:
  16001. case ScrollMode.VERTICAL:
  16002. {
  16003. if (this._spreadMode === SpreadMode.NONE) {
  16004. break;
  16005. }
  16006. const parity = this._spreadMode - 1;
  16007. if (previous && currentPageNumber % 2 !== parity) {
  16008. break;
  16009. } else if (!previous && currentPageNumber % 2 === parity) {
  16010. break;
  16011. }
  16012. const {
  16013. views
  16014. } = this._getVisiblePages(),
  16015. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  16016. for (const {
  16017. id,
  16018. percent,
  16019. widthPercent
  16020. } of views) {
  16021. if (id !== expectedId) {
  16022. continue;
  16023. }
  16024. if (percent > 0 && widthPercent === 100) {
  16025. return 2;
  16026. }
  16027. break;
  16028. }
  16029. break;
  16030. }
  16031. }
  16032. return 1;
  16033. }
  16034. nextPage() {
  16035. const currentPageNumber = this._currentPageNumber,
  16036. pagesCount = this.pagesCount;
  16037. if (currentPageNumber >= pagesCount) {
  16038. return false;
  16039. }
  16040. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  16041. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  16042. return true;
  16043. }
  16044. previousPage() {
  16045. const currentPageNumber = this._currentPageNumber;
  16046. if (currentPageNumber <= 1) {
  16047. return false;
  16048. }
  16049. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  16050. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  16051. return true;
  16052. }
  16053. updateScale({
  16054. drawingDelay,
  16055. scaleFactor = null,
  16056. steps = null,
  16057. origin
  16058. }) {
  16059. if (steps === null && scaleFactor === null) {
  16060. throw new Error("Invalid updateScale options: either `steps` or `scaleFactor` must be provided.");
  16061. }
  16062. if (!this.pdfDocument) {
  16063. return;
  16064. }
  16065. let newScale = this._currentScale;
  16066. if (scaleFactor > 0 && scaleFactor !== 1) {
  16067. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  16068. } else if (steps) {
  16069. const delta = steps > 0 ? DEFAULT_SCALE_DELTA : 1 / DEFAULT_SCALE_DELTA;
  16070. const round = steps > 0 ? Math.ceil : Math.floor;
  16071. steps = Math.abs(steps);
  16072. do {
  16073. newScale = round((newScale * delta).toFixed(2) * 10) / 10;
  16074. } while (--steps > 0);
  16075. }
  16076. newScale = MathClamp(newScale, MIN_SCALE, MAX_SCALE);
  16077. this.#setScale(newScale, {
  16078. noScroll: false,
  16079. drawingDelay,
  16080. origin
  16081. });
  16082. }
  16083. increaseScale(options = {}) {
  16084. this.updateScale({
  16085. ...options,
  16086. steps: options.steps ?? 1
  16087. });
  16088. }
  16089. decreaseScale(options = {}) {
  16090. this.updateScale({
  16091. ...options,
  16092. steps: -(options.steps ?? 1)
  16093. });
  16094. }
  16095. #updateContainerHeightCss(height = this.container.clientHeight) {
  16096. if (height !== this.#previousContainerHeight) {
  16097. this.#previousContainerHeight = height;
  16098. docStyle.setProperty("--viewer-container-height", `${height}px`);
  16099. }
  16100. }
  16101. #resizeObserverCallback(entries) {
  16102. for (const entry of entries) {
  16103. if (entry.target === this.container) {
  16104. this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
  16105. this.#containerTopLeft = null;
  16106. break;
  16107. }
  16108. }
  16109. }
  16110. get containerTopLeft() {
  16111. return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
  16112. }
  16113. #cleanupTimeouts() {
  16114. if (this.#scaleTimeoutId !== null) {
  16115. clearTimeout(this.#scaleTimeoutId);
  16116. this.#scaleTimeoutId = null;
  16117. }
  16118. if (this.#scrollTimeoutId !== null) {
  16119. clearTimeout(this.#scrollTimeoutId);
  16120. this.#scrollTimeoutId = null;
  16121. }
  16122. }
  16123. #cleanupSwitchAnnotationEditorMode() {
  16124. this.#switchAnnotationEditorModeAC?.abort();
  16125. this.#switchAnnotationEditorModeAC = null;
  16126. if (this.#switchAnnotationEditorModeTimeoutId !== null) {
  16127. clearTimeout(this.#switchAnnotationEditorModeTimeoutId);
  16128. this.#switchAnnotationEditorModeTimeoutId = null;
  16129. }
  16130. }
  16131. #preloadEditingData(mode) {
  16132. switch (mode) {
  16133. case AnnotationEditorType.STAMP:
  16134. this.#mlManager?.loadModel("altText");
  16135. break;
  16136. case AnnotationEditorType.SIGNATURE:
  16137. this.#signatureManager?.loadSignatures();
  16138. break;
  16139. }
  16140. }
  16141. get annotationEditorMode() {
  16142. return this.#annotationEditorUIManager ? this.#annotationEditorMode : AnnotationEditorType.DISABLE;
  16143. }
  16144. set annotationEditorMode({
  16145. mode,
  16146. editId = null,
  16147. isFromKeyboard = false
  16148. }) {
  16149. if (!this.#annotationEditorUIManager) {
  16150. throw new Error(`The AnnotationEditor is not enabled.`);
  16151. }
  16152. if (this.#annotationEditorMode === mode) {
  16153. return;
  16154. }
  16155. if (!isValidAnnotationEditorMode(mode)) {
  16156. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  16157. }
  16158. if (!this.pdfDocument) {
  16159. return;
  16160. }
  16161. this.#preloadEditingData(mode);
  16162. const {
  16163. eventBus,
  16164. pdfDocument
  16165. } = this;
  16166. const updater = async () => {
  16167. this.#cleanupSwitchAnnotationEditorMode();
  16168. this.#annotationEditorMode = mode;
  16169. await this.#annotationEditorUIManager.updateMode(mode, editId, isFromKeyboard);
  16170. if (mode !== this.#annotationEditorMode || pdfDocument !== this.pdfDocument) {
  16171. return;
  16172. }
  16173. eventBus.dispatch("annotationeditormodechanged", {
  16174. source: this,
  16175. mode
  16176. });
  16177. };
  16178. if (mode === AnnotationEditorType.NONE || this.#annotationEditorMode === AnnotationEditorType.NONE) {
  16179. const isEditing = mode !== AnnotationEditorType.NONE;
  16180. if (!isEditing) {
  16181. this.pdfDocument.annotationStorage.resetModifiedIds();
  16182. }
  16183. for (const pageView of this._pages) {
  16184. pageView.toggleEditingMode(isEditing);
  16185. }
  16186. const idsToRefresh = this.#switchToEditAnnotationMode();
  16187. if (isEditing && idsToRefresh) {
  16188. this.#cleanupSwitchAnnotationEditorMode();
  16189. this.#switchAnnotationEditorModeAC = new AbortController();
  16190. const signal = AbortSignal.any([this.#eventAbortController.signal, this.#switchAnnotationEditorModeAC.signal]);
  16191. eventBus._on("pagerendered", ({
  16192. pageNumber
  16193. }) => {
  16194. idsToRefresh.delete(pageNumber);
  16195. if (idsToRefresh.size === 0) {
  16196. this.#switchAnnotationEditorModeTimeoutId = setTimeout(updater, 0);
  16197. }
  16198. }, {
  16199. signal
  16200. });
  16201. return;
  16202. }
  16203. }
  16204. updater();
  16205. }
  16206. refresh(noUpdate = false, updateArgs = Object.create(null)) {
  16207. if (!this.pdfDocument) {
  16208. return;
  16209. }
  16210. for (const pageView of this._pages) {
  16211. pageView.update(updateArgs);
  16212. }
  16213. this.#cleanupTimeouts();
  16214. if (!noUpdate) {
  16215. this.update();
  16216. }
  16217. }
  16218. }
  16219. ;// ./web/secondary_toolbar.js
  16220. class SecondaryToolbar {
  16221. #opts;
  16222. constructor(options, eventBus) {
  16223. this.#opts = options;
  16224. const buttons = [{
  16225. element: options.presentationModeButton,
  16226. eventName: "presentationmode",
  16227. close: true
  16228. }, {
  16229. element: options.printButton,
  16230. eventName: "print",
  16231. close: true
  16232. }, {
  16233. element: options.downloadButton,
  16234. eventName: "download",
  16235. close: true
  16236. }, {
  16237. element: options.viewBookmarkButton,
  16238. eventName: null,
  16239. close: true
  16240. }, {
  16241. element: options.firstPageButton,
  16242. eventName: "firstpage",
  16243. close: true
  16244. }, {
  16245. element: options.lastPageButton,
  16246. eventName: "lastpage",
  16247. close: true
  16248. }, {
  16249. element: options.pageRotateCwButton,
  16250. eventName: "rotatecw",
  16251. close: false
  16252. }, {
  16253. element: options.pageRotateCcwButton,
  16254. eventName: "rotateccw",
  16255. close: false
  16256. }, {
  16257. element: options.cursorSelectToolButton,
  16258. eventName: "switchcursortool",
  16259. eventDetails: {
  16260. tool: CursorTool.SELECT
  16261. },
  16262. close: true
  16263. }, {
  16264. element: options.cursorHandToolButton,
  16265. eventName: "switchcursortool",
  16266. eventDetails: {
  16267. tool: CursorTool.HAND
  16268. },
  16269. close: true
  16270. }, {
  16271. element: options.scrollPageButton,
  16272. eventName: "switchscrollmode",
  16273. eventDetails: {
  16274. mode: ScrollMode.PAGE
  16275. },
  16276. close: true
  16277. }, {
  16278. element: options.scrollVerticalButton,
  16279. eventName: "switchscrollmode",
  16280. eventDetails: {
  16281. mode: ScrollMode.VERTICAL
  16282. },
  16283. close: true
  16284. }, {
  16285. element: options.scrollHorizontalButton,
  16286. eventName: "switchscrollmode",
  16287. eventDetails: {
  16288. mode: ScrollMode.HORIZONTAL
  16289. },
  16290. close: true
  16291. }, {
  16292. element: options.scrollWrappedButton,
  16293. eventName: "switchscrollmode",
  16294. eventDetails: {
  16295. mode: ScrollMode.WRAPPED
  16296. },
  16297. close: true
  16298. }, {
  16299. element: options.spreadNoneButton,
  16300. eventName: "switchspreadmode",
  16301. eventDetails: {
  16302. mode: SpreadMode.NONE
  16303. },
  16304. close: true
  16305. }, {
  16306. element: options.spreadOddButton,
  16307. eventName: "switchspreadmode",
  16308. eventDetails: {
  16309. mode: SpreadMode.ODD
  16310. },
  16311. close: true
  16312. }, {
  16313. element: options.spreadEvenButton,
  16314. eventName: "switchspreadmode",
  16315. eventDetails: {
  16316. mode: SpreadMode.EVEN
  16317. },
  16318. close: true
  16319. }, {
  16320. element: options.imageAltTextSettingsButton,
  16321. eventName: "imagealttextsettings",
  16322. close: true
  16323. }, {
  16324. element: options.documentPropertiesButton,
  16325. eventName: "documentproperties",
  16326. close: true
  16327. }];
  16328. buttons.push({
  16329. element: options.openFileButton,
  16330. eventName: "openfile",
  16331. close: true
  16332. });
  16333. this.eventBus = eventBus;
  16334. this.opened = false;
  16335. this.#bindListeners(buttons);
  16336. this.reset();
  16337. }
  16338. get isOpen() {
  16339. return this.opened;
  16340. }
  16341. setPageNumber(pageNumber) {
  16342. this.pageNumber = pageNumber;
  16343. this.#updateUIState();
  16344. }
  16345. setPagesCount(pagesCount) {
  16346. this.pagesCount = pagesCount;
  16347. this.#updateUIState();
  16348. }
  16349. reset() {
  16350. this.pageNumber = 0;
  16351. this.pagesCount = 0;
  16352. this.#updateUIState();
  16353. this.eventBus.dispatch("switchcursortool", {
  16354. source: this,
  16355. reset: true
  16356. });
  16357. this.#scrollModeChanged({
  16358. mode: ScrollMode.VERTICAL
  16359. });
  16360. this.#spreadModeChanged({
  16361. mode: SpreadMode.NONE
  16362. });
  16363. }
  16364. #updateUIState() {
  16365. const {
  16366. firstPageButton,
  16367. lastPageButton,
  16368. pageRotateCwButton,
  16369. pageRotateCcwButton
  16370. } = this.#opts;
  16371. firstPageButton.disabled = this.pageNumber <= 1;
  16372. lastPageButton.disabled = this.pageNumber >= this.pagesCount;
  16373. pageRotateCwButton.disabled = this.pagesCount === 0;
  16374. pageRotateCcwButton.disabled = this.pagesCount === 0;
  16375. }
  16376. #bindListeners(buttons) {
  16377. const {
  16378. eventBus
  16379. } = this;
  16380. const {
  16381. toggleButton
  16382. } = this.#opts;
  16383. toggleButton.addEventListener("click", this.toggle.bind(this));
  16384. for (const {
  16385. element,
  16386. eventName,
  16387. close,
  16388. eventDetails
  16389. } of buttons) {
  16390. element.addEventListener("click", evt => {
  16391. if (eventName !== null) {
  16392. eventBus.dispatch(eventName, {
  16393. source: this,
  16394. ...eventDetails
  16395. });
  16396. }
  16397. if (close) {
  16398. this.close();
  16399. }
  16400. eventBus.dispatch("reporttelemetry", {
  16401. source: this,
  16402. details: {
  16403. type: "buttons",
  16404. data: {
  16405. id: element.id
  16406. }
  16407. }
  16408. });
  16409. });
  16410. }
  16411. eventBus._on("cursortoolchanged", this.#cursorToolChanged.bind(this));
  16412. eventBus._on("scrollmodechanged", this.#scrollModeChanged.bind(this));
  16413. eventBus._on("spreadmodechanged", this.#spreadModeChanged.bind(this));
  16414. }
  16415. #cursorToolChanged({
  16416. tool,
  16417. disabled
  16418. }) {
  16419. const {
  16420. cursorSelectToolButton,
  16421. cursorHandToolButton
  16422. } = this.#opts;
  16423. toggleCheckedBtn(cursorSelectToolButton, tool === CursorTool.SELECT);
  16424. toggleCheckedBtn(cursorHandToolButton, tool === CursorTool.HAND);
  16425. cursorSelectToolButton.disabled = disabled;
  16426. cursorHandToolButton.disabled = disabled;
  16427. }
  16428. #scrollModeChanged({
  16429. mode
  16430. }) {
  16431. const {
  16432. scrollPageButton,
  16433. scrollVerticalButton,
  16434. scrollHorizontalButton,
  16435. scrollWrappedButton,
  16436. spreadNoneButton,
  16437. spreadOddButton,
  16438. spreadEvenButton
  16439. } = this.#opts;
  16440. toggleCheckedBtn(scrollPageButton, mode === ScrollMode.PAGE);
  16441. toggleCheckedBtn(scrollVerticalButton, mode === ScrollMode.VERTICAL);
  16442. toggleCheckedBtn(scrollHorizontalButton, mode === ScrollMode.HORIZONTAL);
  16443. toggleCheckedBtn(scrollWrappedButton, mode === ScrollMode.WRAPPED);
  16444. const forceScrollModePage = this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  16445. scrollPageButton.disabled = forceScrollModePage;
  16446. scrollVerticalButton.disabled = forceScrollModePage;
  16447. scrollHorizontalButton.disabled = forceScrollModePage;
  16448. scrollWrappedButton.disabled = forceScrollModePage;
  16449. const isHorizontal = mode === ScrollMode.HORIZONTAL;
  16450. spreadNoneButton.disabled = isHorizontal;
  16451. spreadOddButton.disabled = isHorizontal;
  16452. spreadEvenButton.disabled = isHorizontal;
  16453. }
  16454. #spreadModeChanged({
  16455. mode
  16456. }) {
  16457. const {
  16458. spreadNoneButton,
  16459. spreadOddButton,
  16460. spreadEvenButton
  16461. } = this.#opts;
  16462. toggleCheckedBtn(spreadNoneButton, mode === SpreadMode.NONE);
  16463. toggleCheckedBtn(spreadOddButton, mode === SpreadMode.ODD);
  16464. toggleCheckedBtn(spreadEvenButton, mode === SpreadMode.EVEN);
  16465. }
  16466. open() {
  16467. if (this.opened) {
  16468. return;
  16469. }
  16470. this.opened = true;
  16471. const {
  16472. toggleButton,
  16473. toolbar
  16474. } = this.#opts;
  16475. toggleExpandedBtn(toggleButton, true, toolbar);
  16476. }
  16477. close() {
  16478. if (!this.opened) {
  16479. return;
  16480. }
  16481. this.opened = false;
  16482. const {
  16483. toggleButton,
  16484. toolbar
  16485. } = this.#opts;
  16486. toggleExpandedBtn(toggleButton, false, toolbar);
  16487. }
  16488. toggle() {
  16489. if (this.opened) {
  16490. this.close();
  16491. } else {
  16492. this.open();
  16493. }
  16494. }
  16495. }
  16496. ;// ./web/signature_manager.js
  16497. const DEFAULT_HEIGHT_IN_PAGE = 40;
  16498. class SignatureManager {
  16499. #addButton;
  16500. #tabsToAltText = null;
  16501. #clearButton;
  16502. #clearDescription;
  16503. #currentEditor;
  16504. #description;
  16505. #dialog;
  16506. #drawCurves = null;
  16507. #drawPlaceholder;
  16508. #drawPath = null;
  16509. #drawPathString = "";
  16510. #drawPoints = null;
  16511. #drawSVG;
  16512. #drawThickness;
  16513. #errorBar;
  16514. #extractedSignatureData = null;
  16515. #imagePath = null;
  16516. #imagePicker;
  16517. #imagePickerLink;
  16518. #imagePlaceholder;
  16519. #imageSVG;
  16520. #saveCheckbox;
  16521. #saveContainer;
  16522. #tabButtons;
  16523. #addSignatureToolbarButton;
  16524. #loadSignaturesPromise = null;
  16525. #typeInput;
  16526. #currentTab = null;
  16527. #currentTabAC = null;
  16528. #hasDescriptionChanged = false;
  16529. #eventBus;
  16530. #l10n;
  16531. #overlayManager;
  16532. #editDescriptionDialog;
  16533. #signatureStorage;
  16534. #uiManager = null;
  16535. static #l10nDescription = null;
  16536. constructor({
  16537. dialog,
  16538. panels,
  16539. typeButton,
  16540. typeInput,
  16541. drawButton,
  16542. drawPlaceholder,
  16543. drawSVG,
  16544. drawThickness,
  16545. imageButton,
  16546. imageSVG,
  16547. imagePlaceholder,
  16548. imagePicker,
  16549. imagePickerLink,
  16550. description,
  16551. clearButton,
  16552. cancelButton,
  16553. addButton,
  16554. errorCloseButton,
  16555. errorBar,
  16556. saveCheckbox,
  16557. saveContainer
  16558. }, editSignatureElements, addSignatureToolbarButton, overlayManager, l10n, signatureStorage, eventBus) {
  16559. this.#addButton = addButton;
  16560. this.#clearButton = clearButton;
  16561. this.#clearDescription = description.lastElementChild;
  16562. this.#description = description.firstElementChild;
  16563. this.#dialog = dialog;
  16564. this.#drawSVG = drawSVG;
  16565. this.#drawPlaceholder = drawPlaceholder;
  16566. this.#drawThickness = drawThickness;
  16567. this.#errorBar = errorBar;
  16568. this.#imageSVG = imageSVG;
  16569. this.#imagePlaceholder = imagePlaceholder;
  16570. this.#imagePicker = imagePicker;
  16571. this.#imagePickerLink = imagePickerLink;
  16572. this.#overlayManager = overlayManager;
  16573. this.#saveCheckbox = saveCheckbox;
  16574. this.#saveContainer = saveContainer;
  16575. this.#addSignatureToolbarButton = addSignatureToolbarButton;
  16576. this.#typeInput = typeInput;
  16577. this.#l10n = l10n;
  16578. this.#signatureStorage = signatureStorage;
  16579. this.#eventBus = eventBus;
  16580. this.#editDescriptionDialog = new EditDescriptionDialog(editSignatureElements, overlayManager);
  16581. SignatureManager.#l10nDescription ||= Object.freeze({
  16582. signature: "pdfjs-editor-add-signature-description-default-when-drawing"
  16583. });
  16584. dialog.addEventListener("close", this.#close.bind(this));
  16585. dialog.addEventListener("contextmenu", e => {
  16586. const {
  16587. target
  16588. } = e;
  16589. if (target !== this.#typeInput && target !== this.#description) {
  16590. e.preventDefault();
  16591. }
  16592. });
  16593. dialog.addEventListener("drop", e => {
  16594. stopEvent(e);
  16595. });
  16596. cancelButton.addEventListener("click", this.#cancel.bind(this));
  16597. addButton.addEventListener("click", this.#add.bind(this));
  16598. clearButton.addEventListener("click", () => {
  16599. this.#reportTelemetry({
  16600. type: "signature",
  16601. action: "pdfjs.signature.clear",
  16602. data: {
  16603. type: this.#currentTab
  16604. }
  16605. });
  16606. this.#initTab(null);
  16607. }, {
  16608. passive: true
  16609. });
  16610. this.#description.addEventListener("input", () => {
  16611. this.#clearDescription.disabled = this.#description.value === "";
  16612. }, {
  16613. passive: true
  16614. });
  16615. this.#clearDescription.addEventListener("click", () => {
  16616. this.#description.value = "";
  16617. this.#clearDescription.disabled = true;
  16618. }, {
  16619. passive: true
  16620. });
  16621. errorCloseButton.addEventListener("click", () => {
  16622. errorBar.hidden = true;
  16623. }, {
  16624. passive: true
  16625. });
  16626. this.#initTabButtons(typeButton, drawButton, imageButton, panels);
  16627. imagePicker.accept = SupportedImageMimeTypes.join(",");
  16628. eventBus._on("storedsignatureschanged", this.#signaturesChanged.bind(this));
  16629. overlayManager.register(dialog);
  16630. }
  16631. #initTabButtons(typeButton, drawButton, imageButton, panels) {
  16632. const buttons = this.#tabButtons = new Map([["type", typeButton], ["draw", drawButton], ["image", imageButton]]);
  16633. const tabCallback = e => {
  16634. for (const [name, button] of buttons) {
  16635. if (button === e.target) {
  16636. button.setAttribute("aria-selected", true);
  16637. button.setAttribute("tabindex", 0);
  16638. panels.setAttribute("data-selected", name);
  16639. this.#initTab(name);
  16640. } else {
  16641. button.setAttribute("aria-selected", false);
  16642. button.setAttribute("tabindex", -1);
  16643. }
  16644. }
  16645. };
  16646. const buttonsArray = Array.from(buttons.values());
  16647. for (let i = 0, ii = buttonsArray.length; i < ii; i++) {
  16648. const button = buttonsArray[i];
  16649. button.addEventListener("click", tabCallback, {
  16650. passive: true
  16651. });
  16652. button.addEventListener("keydown", ({
  16653. key
  16654. }) => {
  16655. if (key !== "ArrowLeft" && key !== "ArrowRight") {
  16656. return;
  16657. }
  16658. buttonsArray[i + (key === "ArrowLeft" ? -1 : 1)]?.focus();
  16659. }, {
  16660. passive: true
  16661. });
  16662. }
  16663. }
  16664. #resetCommon() {
  16665. this.#hasDescriptionChanged = false;
  16666. this.#description.value = "";
  16667. if (this.#currentTab) {
  16668. this.#tabsToAltText.get(this.#currentTab).value = "";
  16669. }
  16670. }
  16671. #resetTab(name) {
  16672. switch (name) {
  16673. case "type":
  16674. this.#typeInput.value = "";
  16675. break;
  16676. case "draw":
  16677. this.#drawCurves = null;
  16678. this.#drawPoints = null;
  16679. this.#drawPathString = "";
  16680. this.#drawPath?.remove();
  16681. this.#drawPath = null;
  16682. this.#drawPlaceholder.hidden = false;
  16683. this.#drawThickness.value = 1;
  16684. break;
  16685. case "image":
  16686. this.#imagePlaceholder.hidden = false;
  16687. this.#imagePath?.remove();
  16688. this.#imagePath = null;
  16689. break;
  16690. }
  16691. }
  16692. #initTab(name) {
  16693. if (name && this.#currentTab === name) {
  16694. return;
  16695. }
  16696. if (this.#currentTab) {
  16697. this.#tabsToAltText.get(this.#currentTab).value = this.#description.value;
  16698. }
  16699. if (name) {
  16700. this.#currentTab = name;
  16701. }
  16702. this.#errorBar.hidden = true;
  16703. const reset = !name;
  16704. if (reset) {
  16705. this.#resetCommon();
  16706. } else {
  16707. this.#description.value = this.#tabsToAltText.get(this.#currentTab).value;
  16708. }
  16709. this.#clearDescription.disabled = this.#description.value === "";
  16710. this.#currentTabAC?.abort();
  16711. this.#currentTabAC = new AbortController();
  16712. switch (this.#currentTab) {
  16713. case "type":
  16714. this.#initTypeTab(reset);
  16715. break;
  16716. case "draw":
  16717. this.#initDrawTab(reset);
  16718. break;
  16719. case "image":
  16720. this.#initImageTab(reset);
  16721. break;
  16722. }
  16723. }
  16724. #disableButtons(value) {
  16725. this.#saveCheckbox.disabled = this.#clearButton.disabled = this.#addButton.disabled = this.#description.disabled = !value;
  16726. }
  16727. #initTypeTab(reset) {
  16728. if (reset) {
  16729. this.#resetTab("type");
  16730. }
  16731. this.#disableButtons(this.#typeInput.value);
  16732. const {
  16733. signal
  16734. } = this.#currentTabAC;
  16735. const options = {
  16736. passive: true,
  16737. signal
  16738. };
  16739. this.#typeInput.addEventListener("input", () => {
  16740. const {
  16741. value
  16742. } = this.#typeInput;
  16743. if (!this.#hasDescriptionChanged) {
  16744. this.#tabsToAltText.get("type").default = this.#description.value = value;
  16745. this.#clearDescription.disabled = value === "";
  16746. }
  16747. this.#disableButtons(value);
  16748. }, options);
  16749. this.#description.addEventListener("input", () => {
  16750. this.#hasDescriptionChanged = this.#typeInput.value !== this.#description.value;
  16751. }, options);
  16752. }
  16753. #initDrawTab(reset) {
  16754. if (reset) {
  16755. this.#resetTab("draw");
  16756. }
  16757. this.#disableButtons(this.#drawPath);
  16758. const {
  16759. signal
  16760. } = this.#currentTabAC;
  16761. const options = {
  16762. signal
  16763. };
  16764. let currentPointerId = NaN;
  16765. const drawCallback = e => {
  16766. const {
  16767. pointerId
  16768. } = e;
  16769. if (!isNaN(currentPointerId) && currentPointerId !== pointerId) {
  16770. return;
  16771. }
  16772. currentPointerId = pointerId;
  16773. e.preventDefault();
  16774. this.#drawSVG.setPointerCapture(pointerId);
  16775. const {
  16776. width: drawWidth,
  16777. height: drawHeight
  16778. } = this.#drawSVG.getBoundingClientRect();
  16779. let {
  16780. offsetX,
  16781. offsetY
  16782. } = e;
  16783. offsetX = Math.round(offsetX);
  16784. offsetY = Math.round(offsetY);
  16785. if (e.target === this.#drawPlaceholder) {
  16786. this.#drawPlaceholder.hidden = true;
  16787. }
  16788. if (!this.#drawCurves) {
  16789. this.#drawCurves = {
  16790. width: drawWidth,
  16791. height: drawHeight,
  16792. thickness: parseInt(this.#drawThickness.value),
  16793. curves: []
  16794. };
  16795. this.#disableButtons(true);
  16796. const svgFactory = new DOMSVGFactory();
  16797. const path = this.#drawPath = svgFactory.createElement("path");
  16798. path.setAttribute("stroke-width", this.#drawThickness.value);
  16799. this.#drawSVG.append(path);
  16800. this.#drawSVG.addEventListener("pointerdown", drawCallback, options);
  16801. this.#drawPlaceholder.removeEventListener("pointerdown", drawCallback);
  16802. if (this.#description.value === "") {
  16803. this.#l10n.get(SignatureManager.#l10nDescription.signature).then(description => {
  16804. this.#tabsToAltText.get("draw").default = description;
  16805. this.#description.value ||= description;
  16806. this.#clearDescription.disabled = this.#description.value === "";
  16807. });
  16808. }
  16809. }
  16810. this.#drawPoints = [offsetX, offsetY];
  16811. this.#drawCurves.curves.push({
  16812. points: this.#drawPoints
  16813. });
  16814. this.#drawPathString += `M ${offsetX} ${offsetY}`;
  16815. this.#drawPath.setAttribute("d", this.#drawPathString);
  16816. const finishDrawAC = new AbortController();
  16817. const listenerDrawOptions = {
  16818. signal: AbortSignal.any([signal, finishDrawAC.signal])
  16819. };
  16820. this.#drawSVG.addEventListener("contextmenu", noContextMenu, listenerDrawOptions);
  16821. this.#drawSVG.addEventListener("pointermove", evt => {
  16822. evt.preventDefault();
  16823. let {
  16824. offsetX: x,
  16825. offsetY: y
  16826. } = evt;
  16827. x = Math.round(x);
  16828. y = Math.round(y);
  16829. const drawPoints = this.#drawPoints;
  16830. if (x < 0 || y < 0 || x > drawWidth || y > drawHeight || x === drawPoints.at(-2) && y === drawPoints.at(-1)) {
  16831. return;
  16832. }
  16833. if (drawPoints.length >= 4) {
  16834. const [x1, y1, x2, y2] = drawPoints.slice(-4);
  16835. this.#drawPathString += `C${(x1 + 5 * x2) / 6} ${(y1 + 5 * y2) / 6} ${(5 * x2 + x) / 6} ${(5 * y2 + y) / 6} ${(x2 + x) / 2} ${(y2 + y) / 2}`;
  16836. } else {
  16837. this.#drawPathString += `L${x} ${y}`;
  16838. }
  16839. drawPoints.push(x, y);
  16840. this.#drawPath.setAttribute("d", this.#drawPathString);
  16841. }, listenerDrawOptions);
  16842. this.#drawSVG.addEventListener("pointerup", evt => {
  16843. const {
  16844. pointerId: pId
  16845. } = evt;
  16846. if (!isNaN(currentPointerId) && currentPointerId !== pId) {
  16847. return;
  16848. }
  16849. currentPointerId = NaN;
  16850. evt.preventDefault();
  16851. this.#drawSVG.releasePointerCapture(pId);
  16852. finishDrawAC.abort();
  16853. if (this.#drawPoints.length === 2) {
  16854. this.#drawPathString += `L${this.#drawPoints[0]} ${this.#drawPoints[1]}`;
  16855. this.#drawPath.setAttribute("d", this.#drawPathString);
  16856. }
  16857. }, listenerDrawOptions);
  16858. };
  16859. if (this.#drawCurves) {
  16860. this.#drawSVG.addEventListener("pointerdown", drawCallback, options);
  16861. } else {
  16862. this.#drawPlaceholder.addEventListener("pointerdown", drawCallback, options);
  16863. }
  16864. this.#drawThickness.addEventListener("input", () => {
  16865. const {
  16866. value: thickness
  16867. } = this.#drawThickness;
  16868. this.#drawThickness.setAttribute("data-l10n-args", JSON.stringify({
  16869. thickness
  16870. }));
  16871. if (!this.#drawCurves) {
  16872. return;
  16873. }
  16874. this.#drawPath.setAttribute("stroke-width", thickness);
  16875. this.#drawCurves.thickness = thickness;
  16876. }, options);
  16877. }
  16878. #initImageTab(reset) {
  16879. if (reset) {
  16880. this.#resetTab("image");
  16881. }
  16882. this.#disableButtons(this.#imagePath);
  16883. const {
  16884. signal
  16885. } = this.#currentTabAC;
  16886. const options = {
  16887. signal
  16888. };
  16889. const passiveOptions = {
  16890. passive: true,
  16891. signal
  16892. };
  16893. this.#imagePickerLink.addEventListener("keydown", e => {
  16894. const {
  16895. key
  16896. } = e;
  16897. if (key === "Enter" || key === " ") {
  16898. stopEvent(e);
  16899. this.#imagePicker.click();
  16900. }
  16901. }, options);
  16902. this.#imagePicker.addEventListener("click", () => {
  16903. this.#dialog.classList.toggle("waiting", true);
  16904. }, passiveOptions);
  16905. this.#imagePicker.addEventListener("change", async () => {
  16906. const file = this.#imagePicker.files?.[0];
  16907. if (!file || !SupportedImageMimeTypes.includes(file.type)) {
  16908. this.#errorBar.hidden = false;
  16909. this.#dialog.classList.toggle("waiting", false);
  16910. return;
  16911. }
  16912. await this.#extractSignature(file);
  16913. }, passiveOptions);
  16914. this.#imagePicker.addEventListener("cancel", () => {
  16915. this.#dialog.classList.toggle("waiting", false);
  16916. }, passiveOptions);
  16917. this.#imagePlaceholder.addEventListener("dragover", e => {
  16918. const {
  16919. dataTransfer
  16920. } = e;
  16921. for (const {
  16922. type
  16923. } of dataTransfer.items) {
  16924. if (!SupportedImageMimeTypes.includes(type)) {
  16925. continue;
  16926. }
  16927. dataTransfer.dropEffect = dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  16928. stopEvent(e);
  16929. return;
  16930. }
  16931. dataTransfer.dropEffect = "none";
  16932. }, options);
  16933. this.#imagePlaceholder.addEventListener("drop", e => {
  16934. const {
  16935. dataTransfer: {
  16936. files
  16937. }
  16938. } = e;
  16939. if (!files?.length) {
  16940. return;
  16941. }
  16942. for (const file of files) {
  16943. if (SupportedImageMimeTypes.includes(file.type)) {
  16944. this.#extractSignature(file);
  16945. break;
  16946. }
  16947. }
  16948. stopEvent(e);
  16949. this.#dialog.classList.toggle("waiting", true);
  16950. }, options);
  16951. }
  16952. async #extractSignature(file) {
  16953. let data;
  16954. try {
  16955. data = await this.#uiManager.imageManager.getFromFile(file);
  16956. } catch (e) {
  16957. console.error("SignatureManager.#extractSignature.", e);
  16958. }
  16959. if (!data) {
  16960. this.#errorBar.hidden = false;
  16961. this.#dialog.classList.toggle("waiting", false);
  16962. return;
  16963. }
  16964. const {
  16965. outline
  16966. } = this.#extractedSignatureData = this.#currentEditor.getFromImage(data.bitmap);
  16967. if (!outline) {
  16968. this.#dialog.classList.toggle("waiting", false);
  16969. return;
  16970. }
  16971. this.#imagePlaceholder.hidden = true;
  16972. this.#disableButtons(true);
  16973. const svgFactory = new DOMSVGFactory();
  16974. const path = this.#imagePath = svgFactory.createElement("path");
  16975. this.#imageSVG.setAttribute("viewBox", outline.viewBox);
  16976. this.#imageSVG.setAttribute("preserveAspectRatio", "xMidYMid meet");
  16977. this.#imageSVG.append(path);
  16978. path.setAttribute("d", outline.toSVGPath());
  16979. this.#tabsToAltText.get("image").default = file.name;
  16980. if (this.#description.value === "") {
  16981. this.#description.value = file.name || "";
  16982. this.#clearDescription.disabled = this.#description.value === "";
  16983. }
  16984. this.#dialog.classList.toggle("waiting", false);
  16985. }
  16986. #getOutlineForType() {
  16987. return this.#currentEditor.getFromText(this.#typeInput.value, window.getComputedStyle(this.#typeInput));
  16988. }
  16989. #getOutlineForDraw() {
  16990. const {
  16991. width,
  16992. height
  16993. } = this.#drawSVG.getBoundingClientRect();
  16994. return this.#currentEditor.getDrawnSignature(this.#drawCurves, width, height);
  16995. }
  16996. #reportTelemetry(data) {
  16997. this.#eventBus.dispatch("reporttelemetry", {
  16998. source: this,
  16999. details: {
  17000. type: "editing",
  17001. data
  17002. }
  17003. });
  17004. }
  17005. #addToolbarButton(signatureData, uuid, description) {
  17006. const {
  17007. curves,
  17008. areContours,
  17009. thickness,
  17010. width,
  17011. height
  17012. } = signatureData;
  17013. const maxDim = Math.max(width, height);
  17014. const outlineData = SignatureExtractor.processDrawnLines({
  17015. lines: {
  17016. curves,
  17017. thickness,
  17018. width,
  17019. height
  17020. },
  17021. pageWidth: maxDim,
  17022. pageHeight: maxDim,
  17023. rotation: 0,
  17024. innerMargin: 0,
  17025. mustSmooth: false,
  17026. areContours
  17027. });
  17028. if (!outlineData) {
  17029. return;
  17030. }
  17031. const {
  17032. outline
  17033. } = outlineData;
  17034. const svgFactory = new DOMSVGFactory();
  17035. const div = document.createElement("div");
  17036. const button = document.createElement("button");
  17037. button.addEventListener("click", () => {
  17038. this.#eventBus.dispatch("switchannotationeditorparams", {
  17039. source: this,
  17040. type: AnnotationEditorParamsType.CREATE,
  17041. value: {
  17042. signatureData: {
  17043. lines: {
  17044. curves,
  17045. thickness,
  17046. width,
  17047. height
  17048. },
  17049. mustSmooth: false,
  17050. areContours,
  17051. description,
  17052. uuid,
  17053. heightInPage: DEFAULT_HEIGHT_IN_PAGE
  17054. }
  17055. }
  17056. });
  17057. });
  17058. div.append(button);
  17059. div.classList.add("toolbarAddSignatureButtonContainer");
  17060. const svg = svgFactory.create(1, 1, true);
  17061. button.append(svg);
  17062. const span = document.createElement("span");
  17063. span.ariaHidden = true;
  17064. button.append(span);
  17065. button.classList.add("toolbarAddSignatureButton");
  17066. button.type = "button";
  17067. span.textContent = description;
  17068. button.setAttribute("data-l10n-id", "pdfjs-editor-add-saved-signature-button");
  17069. button.setAttribute("data-l10n-args", JSON.stringify({
  17070. description
  17071. }));
  17072. button.tabIndex = 0;
  17073. const path = svgFactory.createElement("path");
  17074. svg.append(path);
  17075. svg.setAttribute("viewBox", outline.viewBox);
  17076. svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
  17077. if (areContours) {
  17078. path.classList.add("contours");
  17079. }
  17080. path.setAttribute("d", outline.toSVGPath());
  17081. const deleteButton = document.createElement("button");
  17082. div.append(deleteButton);
  17083. deleteButton.classList.add("toolbarButton", "deleteButton");
  17084. deleteButton.setAttribute("data-l10n-id", "pdfjs-editor-delete-signature-button1");
  17085. deleteButton.type = "button";
  17086. deleteButton.tabIndex = 0;
  17087. deleteButton.addEventListener("click", async () => {
  17088. if (await this.#signatureStorage.delete(uuid)) {
  17089. div.remove();
  17090. this.#reportTelemetry({
  17091. type: "signature",
  17092. action: "pdfjs.signature.delete_saved",
  17093. data: {
  17094. savedCount: await this.#signatureStorage.size()
  17095. }
  17096. });
  17097. }
  17098. });
  17099. const deleteSpan = document.createElement("span");
  17100. deleteButton.append(deleteSpan);
  17101. deleteSpan.setAttribute("data-l10n-id", "pdfjs-editor-delete-signature-button-label1");
  17102. this.#addSignatureToolbarButton.before(div);
  17103. }
  17104. async #signaturesChanged() {
  17105. const parent = this.#addSignatureToolbarButton.parentElement;
  17106. while (parent.firstElementChild !== this.#addSignatureToolbarButton) {
  17107. parent.firstElementChild.remove();
  17108. }
  17109. this.#loadSignaturesPromise = null;
  17110. await this.loadSignatures(true);
  17111. }
  17112. getSignature(params) {
  17113. return this.open(params);
  17114. }
  17115. async loadSignatures(reload = false) {
  17116. if (!this.#addSignatureToolbarButton || !reload && this.#addSignatureToolbarButton.previousElementSibling || !this.#signatureStorage) {
  17117. return;
  17118. }
  17119. if (!this.#loadSignaturesPromise) {
  17120. this.#loadSignaturesPromise = this.#signatureStorage.getAll().then(async signatures => [signatures, await Promise.all(Array.from(signatures.values(), ({
  17121. signatureData
  17122. }) => SignatureExtractor.decompressSignature(signatureData)))]);
  17123. if (!reload) {
  17124. return;
  17125. }
  17126. }
  17127. const [signatures, signaturesData] = await this.#loadSignaturesPromise;
  17128. this.#loadSignaturesPromise = null;
  17129. let i = 0;
  17130. for (const [uuid, {
  17131. description
  17132. }] of signatures) {
  17133. const data = signaturesData[i++];
  17134. if (!data) {
  17135. continue;
  17136. }
  17137. data.curves = data.outlines.map(points => ({
  17138. points
  17139. }));
  17140. delete data.outlines;
  17141. this.#addToolbarButton(data, uuid, description);
  17142. }
  17143. }
  17144. async renderEditButton(editor) {
  17145. const button = document.createElement("button");
  17146. button.classList.add("altText", "editDescription");
  17147. button.tabIndex = 0;
  17148. button.title = editor.description;
  17149. const span = document.createElement("span");
  17150. button.append(span);
  17151. span.setAttribute("data-l10n-id", "pdfjs-editor-add-signature-edit-button-label");
  17152. button.addEventListener("click", () => {
  17153. this.#editDescriptionDialog.open(editor);
  17154. }, {
  17155. passive: true
  17156. });
  17157. return button;
  17158. }
  17159. async open({
  17160. uiManager,
  17161. editor
  17162. }) {
  17163. this.#tabsToAltText ||= new Map(this.#tabButtons.keys().map(name => [name, {
  17164. value: "",
  17165. default: ""
  17166. }]));
  17167. this.#uiManager = uiManager;
  17168. this.#currentEditor = editor;
  17169. this.#uiManager.removeEditListeners();
  17170. const isStorageFull = await this.#signatureStorage.isFull();
  17171. this.#saveContainer.classList.toggle("fullStorage", isStorageFull);
  17172. this.#saveCheckbox.checked = !isStorageFull;
  17173. await this.#overlayManager.open(this.#dialog);
  17174. const tabType = this.#tabButtons.get("type");
  17175. tabType.focus();
  17176. tabType.click();
  17177. }
  17178. #cancel() {
  17179. this.#finish();
  17180. }
  17181. #finish() {
  17182. this.#overlayManager.closeIfActive(this.#dialog);
  17183. }
  17184. #close() {
  17185. if (this.#currentEditor._drawId === null) {
  17186. this.#currentEditor.remove();
  17187. }
  17188. this.#uiManager?.addEditListeners();
  17189. this.#currentTabAC?.abort();
  17190. this.#currentTabAC = null;
  17191. this.#uiManager = null;
  17192. this.#currentEditor = null;
  17193. this.#resetCommon();
  17194. for (const [name] of this.#tabButtons) {
  17195. this.#resetTab(name);
  17196. }
  17197. this.#disableButtons(false);
  17198. this.#currentTab = null;
  17199. this.#tabsToAltText = null;
  17200. }
  17201. async #add() {
  17202. let data;
  17203. const type = this.#currentTab;
  17204. switch (type) {
  17205. case "type":
  17206. data = this.#getOutlineForType();
  17207. break;
  17208. case "draw":
  17209. data = this.#getOutlineForDraw();
  17210. break;
  17211. case "image":
  17212. data = this.#extractedSignatureData;
  17213. break;
  17214. }
  17215. let uuid = null;
  17216. const description = this.#description.value;
  17217. if (this.#saveCheckbox.checked) {
  17218. const {
  17219. newCurves,
  17220. areContours,
  17221. thickness,
  17222. width,
  17223. height
  17224. } = data;
  17225. const signatureData = await SignatureExtractor.compressSignature({
  17226. outlines: newCurves,
  17227. areContours,
  17228. thickness,
  17229. width,
  17230. height
  17231. });
  17232. uuid = await this.#signatureStorage.create({
  17233. description,
  17234. signatureData
  17235. });
  17236. if (uuid) {
  17237. this.#addToolbarButton({
  17238. curves: newCurves.map(points => ({
  17239. points
  17240. })),
  17241. areContours,
  17242. thickness,
  17243. width,
  17244. height
  17245. }, uuid, description);
  17246. } else {
  17247. console.warn("SignatureManager.add: cannot save the signature.");
  17248. }
  17249. }
  17250. const altText = this.#tabsToAltText.get(type);
  17251. this.#reportTelemetry({
  17252. type: "signature",
  17253. action: "pdfjs.signature.created",
  17254. data: {
  17255. type,
  17256. saved: !!uuid,
  17257. savedCount: await this.#signatureStorage.size(),
  17258. descriptionChanged: description !== altText.default
  17259. }
  17260. });
  17261. this.#currentEditor.addSignature(data, DEFAULT_HEIGHT_IN_PAGE, this.#description.value, uuid);
  17262. this.#finish();
  17263. }
  17264. destroy() {
  17265. this.#uiManager = null;
  17266. this.#finish();
  17267. }
  17268. }
  17269. class EditDescriptionDialog {
  17270. #currentEditor;
  17271. #previousDescription;
  17272. #description;
  17273. #dialog;
  17274. #overlayManager;
  17275. #signatureSVG;
  17276. #uiManager;
  17277. constructor({
  17278. dialog,
  17279. description,
  17280. cancelButton,
  17281. updateButton,
  17282. editSignatureView
  17283. }, overlayManager) {
  17284. const descriptionInput = this.#description = description.firstElementChild;
  17285. this.#signatureSVG = editSignatureView;
  17286. this.#dialog = dialog;
  17287. this.#overlayManager = overlayManager;
  17288. dialog.addEventListener("close", this.#close.bind(this));
  17289. dialog.addEventListener("contextmenu", e => {
  17290. if (e.target !== this.#description) {
  17291. e.preventDefault();
  17292. }
  17293. });
  17294. cancelButton.addEventListener("click", this.#cancel.bind(this));
  17295. updateButton.addEventListener("click", this.#update.bind(this));
  17296. const clearDescription = description.lastElementChild;
  17297. clearDescription.addEventListener("click", () => {
  17298. descriptionInput.value = "";
  17299. clearDescription.disabled = true;
  17300. updateButton.disabled = this.#previousDescription === "";
  17301. });
  17302. descriptionInput.addEventListener("input", () => {
  17303. const {
  17304. value
  17305. } = descriptionInput;
  17306. clearDescription.disabled = value === "";
  17307. updateButton.disabled = value === this.#previousDescription;
  17308. editSignatureView.setAttribute("aria-label", value);
  17309. }, {
  17310. passive: true
  17311. });
  17312. overlayManager.register(dialog);
  17313. }
  17314. async open(editor) {
  17315. this.#uiManager = editor._uiManager;
  17316. this.#currentEditor = editor;
  17317. this.#previousDescription = this.#description.value = editor.description;
  17318. this.#description.dispatchEvent(new Event("input"));
  17319. this.#uiManager.removeEditListeners();
  17320. const {
  17321. areContours,
  17322. outline
  17323. } = editor.getSignaturePreview();
  17324. const svgFactory = new DOMSVGFactory();
  17325. const path = svgFactory.createElement("path");
  17326. this.#signatureSVG.append(path);
  17327. this.#signatureSVG.setAttribute("viewBox", outline.viewBox);
  17328. path.setAttribute("d", outline.toSVGPath());
  17329. if (areContours) {
  17330. path.classList.add("contours");
  17331. }
  17332. await this.#overlayManager.open(this.#dialog);
  17333. }
  17334. async #update() {
  17335. this.#currentEditor._reportTelemetry({
  17336. action: "pdfjs.signature.edit_description",
  17337. data: {
  17338. hasBeenChanged: true
  17339. }
  17340. });
  17341. this.#currentEditor.description = this.#description.value;
  17342. this.#finish();
  17343. }
  17344. #cancel() {
  17345. this.#currentEditor._reportTelemetry({
  17346. action: "pdfjs.signature.edit_description",
  17347. data: {
  17348. hasBeenChanged: false
  17349. }
  17350. });
  17351. this.#finish();
  17352. }
  17353. #finish() {
  17354. this.#overlayManager.closeIfActive(this.#dialog);
  17355. }
  17356. #close() {
  17357. this.#uiManager?.addEditListeners();
  17358. this.#uiManager = null;
  17359. this.#currentEditor = null;
  17360. this.#signatureSVG.firstElementChild.remove();
  17361. }
  17362. }
  17363. ;// ./web/toolbar.js
  17364. class Toolbar {
  17365. #colorPicker = null;
  17366. #opts;
  17367. constructor(options, eventBus, toolbarDensity = 0) {
  17368. this.#opts = options;
  17369. this.eventBus = eventBus;
  17370. const buttons = [{
  17371. element: options.previous,
  17372. eventName: "previouspage"
  17373. }, {
  17374. element: options.next,
  17375. eventName: "nextpage"
  17376. }, {
  17377. element: options.zoomIn,
  17378. eventName: "zoomin"
  17379. }, {
  17380. element: options.zoomOut,
  17381. eventName: "zoomout"
  17382. }, {
  17383. element: options.print,
  17384. eventName: "print"
  17385. }, {
  17386. element: options.download,
  17387. eventName: "download"
  17388. }, {
  17389. element: options.editorFreeTextButton,
  17390. eventName: "switchannotationeditormode",
  17391. eventDetails: {
  17392. get mode() {
  17393. const {
  17394. classList
  17395. } = options.editorFreeTextButton;
  17396. return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.FREETEXT;
  17397. }
  17398. }
  17399. }, {
  17400. element: options.editorHighlightButton,
  17401. eventName: "switchannotationeditormode",
  17402. eventDetails: {
  17403. get mode() {
  17404. const {
  17405. classList
  17406. } = options.editorHighlightButton;
  17407. return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.HIGHLIGHT;
  17408. }
  17409. }
  17410. }, {
  17411. element: options.editorInkButton,
  17412. eventName: "switchannotationeditormode",
  17413. eventDetails: {
  17414. get mode() {
  17415. const {
  17416. classList
  17417. } = options.editorInkButton;
  17418. return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.INK;
  17419. }
  17420. }
  17421. }, {
  17422. element: options.editorStampButton,
  17423. eventName: "switchannotationeditormode",
  17424. eventDetails: {
  17425. get mode() {
  17426. const {
  17427. classList
  17428. } = options.editorStampButton;
  17429. return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.STAMP;
  17430. }
  17431. },
  17432. telemetry: {
  17433. type: "editing",
  17434. data: {
  17435. action: "pdfjs.image.icon_click"
  17436. }
  17437. }
  17438. }, {
  17439. element: options.editorSignatureButton,
  17440. eventName: "switchannotationeditormode",
  17441. eventDetails: {
  17442. get mode() {
  17443. const {
  17444. classList
  17445. } = options.editorSignatureButton;
  17446. return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.SIGNATURE;
  17447. }
  17448. }
  17449. }];
  17450. this.#bindListeners(buttons);
  17451. this.#updateToolbarDensity({
  17452. value: toolbarDensity
  17453. });
  17454. this.reset();
  17455. }
  17456. #updateToolbarDensity({
  17457. value
  17458. }) {
  17459. let name = "normal";
  17460. switch (value) {
  17461. case 1:
  17462. name = "compact";
  17463. break;
  17464. case 2:
  17465. name = "touch";
  17466. break;
  17467. }
  17468. document.documentElement.setAttribute("data-toolbar-density", name);
  17469. }
  17470. setPageNumber(pageNumber, pageLabel) {
  17471. this.pageNumber = pageNumber;
  17472. this.pageLabel = pageLabel;
  17473. this.#updateUIState(false);
  17474. }
  17475. setPagesCount(pagesCount, hasPageLabels) {
  17476. this.pagesCount = pagesCount;
  17477. this.hasPageLabels = hasPageLabels;
  17478. this.#updateUIState(true);
  17479. }
  17480. setPageScale(pageScaleValue, pageScale) {
  17481. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  17482. this.pageScale = pageScale;
  17483. this.#updateUIState(false);
  17484. }
  17485. reset() {
  17486. this.#colorPicker = null;
  17487. this.pageNumber = 0;
  17488. this.pageLabel = null;
  17489. this.hasPageLabels = false;
  17490. this.pagesCount = 0;
  17491. this.pageScaleValue = DEFAULT_SCALE_VALUE;
  17492. this.pageScale = DEFAULT_SCALE;
  17493. this.#updateUIState(true);
  17494. this.updateLoadingIndicatorState();
  17495. this.#editorModeChanged({
  17496. mode: AnnotationEditorType.DISABLE
  17497. });
  17498. }
  17499. #bindListeners(buttons) {
  17500. const {
  17501. eventBus
  17502. } = this;
  17503. const {
  17504. editorHighlightColorPicker,
  17505. editorHighlightButton,
  17506. pageNumber,
  17507. scaleSelect
  17508. } = this.#opts;
  17509. const self = this;
  17510. for (const {
  17511. element,
  17512. eventName,
  17513. eventDetails,
  17514. telemetry
  17515. } of buttons) {
  17516. element.addEventListener("click", evt => {
  17517. if (eventName !== null) {
  17518. eventBus.dispatch(eventName, {
  17519. source: this,
  17520. ...eventDetails,
  17521. isFromKeyboard: evt.detail === 0
  17522. });
  17523. }
  17524. if (telemetry) {
  17525. eventBus.dispatch("reporttelemetry", {
  17526. source: this,
  17527. details: telemetry
  17528. });
  17529. }
  17530. });
  17531. }
  17532. pageNumber.addEventListener("click", function () {
  17533. this.select();
  17534. });
  17535. pageNumber.addEventListener("change", function () {
  17536. eventBus.dispatch("pagenumberchanged", {
  17537. source: self,
  17538. value: this.value
  17539. });
  17540. });
  17541. scaleSelect.addEventListener("change", function () {
  17542. if (this.value === "custom") {
  17543. return;
  17544. }
  17545. eventBus.dispatch("scalechanged", {
  17546. source: self,
  17547. value: this.value
  17548. });
  17549. });
  17550. scaleSelect.addEventListener("click", function ({
  17551. target
  17552. }) {
  17553. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  17554. this.blur();
  17555. }
  17556. });
  17557. scaleSelect.oncontextmenu = noContextMenu;
  17558. eventBus._on("annotationeditormodechanged", this.#editorModeChanged.bind(this));
  17559. eventBus._on("showannotationeditorui", ({
  17560. mode
  17561. }) => {
  17562. switch (mode) {
  17563. case AnnotationEditorType.HIGHLIGHT:
  17564. editorHighlightButton.click();
  17565. break;
  17566. }
  17567. });
  17568. eventBus._on("toolbardensity", this.#updateToolbarDensity.bind(this));
  17569. if (editorHighlightColorPicker) {
  17570. eventBus._on("annotationeditoruimanager", ({
  17571. uiManager
  17572. }) => {
  17573. const cp = this.#colorPicker = new ColorPicker({
  17574. uiManager
  17575. });
  17576. uiManager.setMainHighlightColorPicker(cp);
  17577. editorHighlightColorPicker.append(cp.renderMainDropdown());
  17578. });
  17579. eventBus._on("mainhighlightcolorpickerupdatecolor", ({
  17580. value
  17581. }) => {
  17582. this.#colorPicker?.updateColor(value);
  17583. });
  17584. }
  17585. }
  17586. #editorModeChanged({
  17587. mode
  17588. }) {
  17589. const {
  17590. editorFreeTextButton,
  17591. editorFreeTextParamsToolbar,
  17592. editorHighlightButton,
  17593. editorHighlightParamsToolbar,
  17594. editorInkButton,
  17595. editorInkParamsToolbar,
  17596. editorStampButton,
  17597. editorStampParamsToolbar,
  17598. editorSignatureButton,
  17599. editorSignatureParamsToolbar
  17600. } = this.#opts;
  17601. toggleExpandedBtn(editorFreeTextButton, mode === AnnotationEditorType.FREETEXT, editorFreeTextParamsToolbar);
  17602. toggleExpandedBtn(editorHighlightButton, mode === AnnotationEditorType.HIGHLIGHT, editorHighlightParamsToolbar);
  17603. toggleExpandedBtn(editorInkButton, mode === AnnotationEditorType.INK, editorInkParamsToolbar);
  17604. toggleExpandedBtn(editorStampButton, mode === AnnotationEditorType.STAMP, editorStampParamsToolbar);
  17605. toggleExpandedBtn(editorSignatureButton, mode === AnnotationEditorType.SIGNATURE, editorSignatureParamsToolbar);
  17606. const isDisable = mode === AnnotationEditorType.DISABLE;
  17607. editorFreeTextButton.disabled = isDisable;
  17608. editorHighlightButton.disabled = isDisable;
  17609. editorInkButton.disabled = isDisable;
  17610. editorStampButton.disabled = isDisable;
  17611. editorSignatureButton.disabled = isDisable;
  17612. }
  17613. #updateUIState(resetNumPages = false) {
  17614. const {
  17615. pageNumber,
  17616. pagesCount,
  17617. pageScaleValue,
  17618. pageScale
  17619. } = this;
  17620. const opts = this.#opts;
  17621. if (resetNumPages) {
  17622. if (this.hasPageLabels) {
  17623. opts.pageNumber.type = "text";
  17624. opts.numPages.setAttribute("data-l10n-id", "pdfjs-page-of-pages");
  17625. } else {
  17626. opts.pageNumber.type = "number";
  17627. opts.numPages.setAttribute("data-l10n-id", "pdfjs-of-pages");
  17628. opts.numPages.setAttribute("data-l10n-args", JSON.stringify({
  17629. pagesCount
  17630. }));
  17631. }
  17632. opts.pageNumber.max = pagesCount;
  17633. }
  17634. if (this.hasPageLabels) {
  17635. opts.pageNumber.value = this.pageLabel;
  17636. opts.numPages.setAttribute("data-l10n-args", JSON.stringify({
  17637. pageNumber,
  17638. pagesCount
  17639. }));
  17640. } else {
  17641. opts.pageNumber.value = pageNumber;
  17642. }
  17643. opts.previous.disabled = pageNumber <= 1;
  17644. opts.next.disabled = pageNumber >= pagesCount;
  17645. opts.zoomOut.disabled = pageScale <= MIN_SCALE;
  17646. opts.zoomIn.disabled = pageScale >= MAX_SCALE;
  17647. let predefinedValueFound = false;
  17648. for (const option of opts.scaleSelect.options) {
  17649. if (option.value !== pageScaleValue) {
  17650. option.selected = false;
  17651. continue;
  17652. }
  17653. option.selected = true;
  17654. predefinedValueFound = true;
  17655. }
  17656. if (!predefinedValueFound) {
  17657. opts.customScaleOption.selected = true;
  17658. opts.customScaleOption.setAttribute("data-l10n-args", JSON.stringify({
  17659. scale: Math.round(pageScale * 10000) / 100
  17660. }));
  17661. }
  17662. }
  17663. updateLoadingIndicatorState(loading = false) {
  17664. const {
  17665. pageNumber
  17666. } = this.#opts;
  17667. pageNumber.classList.toggle("loading", loading);
  17668. }
  17669. }
  17670. ;// ./web/view_history.js
  17671. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  17672. class ViewHistory {
  17673. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  17674. this.fingerprint = fingerprint;
  17675. this.cacheSize = cacheSize;
  17676. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  17677. const database = JSON.parse(databaseStr || "{}");
  17678. let index = -1;
  17679. if (!Array.isArray(database.files)) {
  17680. database.files = [];
  17681. } else {
  17682. while (database.files.length >= this.cacheSize) {
  17683. database.files.shift();
  17684. }
  17685. for (let i = 0, ii = database.files.length; i < ii; i++) {
  17686. const branch = database.files[i];
  17687. if (branch.fingerprint === this.fingerprint) {
  17688. index = i;
  17689. break;
  17690. }
  17691. }
  17692. }
  17693. if (index === -1) {
  17694. index = database.files.push({
  17695. fingerprint: this.fingerprint
  17696. }) - 1;
  17697. }
  17698. this.file = database.files[index];
  17699. this.database = database;
  17700. });
  17701. }
  17702. async _writeToStorage() {
  17703. const databaseStr = JSON.stringify(this.database);
  17704. localStorage.setItem("pdfjs.history", databaseStr);
  17705. }
  17706. async _readFromStorage() {
  17707. return localStorage.getItem("pdfjs.history");
  17708. }
  17709. async set(name, val) {
  17710. await this._initializedPromise;
  17711. this.file[name] = val;
  17712. return this._writeToStorage();
  17713. }
  17714. async setMultiple(properties) {
  17715. await this._initializedPromise;
  17716. for (const name in properties) {
  17717. this.file[name] = properties[name];
  17718. }
  17719. return this._writeToStorage();
  17720. }
  17721. async get(name, defaultValue) {
  17722. await this._initializedPromise;
  17723. const val = this.file[name];
  17724. return val !== undefined ? val : defaultValue;
  17725. }
  17726. async getMultiple(properties) {
  17727. await this._initializedPromise;
  17728. const values = Object.create(null);
  17729. for (const name in properties) {
  17730. const val = this.file[name];
  17731. values[name] = val !== undefined ? val : properties[name];
  17732. }
  17733. return values;
  17734. }
  17735. }
  17736. ;// ./web/app.js
  17737. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  17738. const ViewOnLoad = {
  17739. UNKNOWN: -1,
  17740. PREVIOUS: 0,
  17741. INITIAL: 1
  17742. };
  17743. const PDFViewerApplication = {
  17744. initialBookmark: document.location.hash.substring(1),
  17745. _initializedCapability: {
  17746. ...Promise.withResolvers(),
  17747. settled: false
  17748. },
  17749. appConfig: null,
  17750. pdfDocument: null,
  17751. pdfLoadingTask: null,
  17752. printService: null,
  17753. pdfViewer: null,
  17754. pdfThumbnailViewer: null,
  17755. pdfRenderingQueue: null,
  17756. pdfPresentationMode: null,
  17757. pdfDocumentProperties: null,
  17758. pdfLinkService: null,
  17759. pdfHistory: null,
  17760. pdfSidebar: null,
  17761. pdfOutlineViewer: null,
  17762. pdfAttachmentViewer: null,
  17763. pdfLayerViewer: null,
  17764. pdfCursorTools: null,
  17765. pdfScriptingManager: null,
  17766. store: null,
  17767. downloadManager: null,
  17768. overlayManager: null,
  17769. preferences: new Preferences(),
  17770. toolbar: null,
  17771. secondaryToolbar: null,
  17772. eventBus: null,
  17773. l10n: null,
  17774. annotationEditorParams: null,
  17775. imageAltTextSettings: null,
  17776. isInitialViewSet: false,
  17777. isViewerEmbedded: window.parent !== window,
  17778. url: "",
  17779. baseUrl: "",
  17780. mlManager: null,
  17781. _downloadUrl: "",
  17782. _eventBusAbortController: null,
  17783. _windowAbortController: null,
  17784. _globalAbortController: new AbortController(),
  17785. documentInfo: null,
  17786. metadata: null,
  17787. _contentDispositionFilename: null,
  17788. _contentLength: null,
  17789. _saveInProgress: false,
  17790. _wheelUnusedTicks: 0,
  17791. _wheelUnusedFactor: 1,
  17792. _touchManager: null,
  17793. _touchUnusedTicks: 0,
  17794. _touchUnusedFactor: 1,
  17795. _PDFBug: null,
  17796. _hasAnnotationEditors: false,
  17797. _title: document.title,
  17798. _printAnnotationStoragePromise: null,
  17799. _isCtrlKeyDown: false,
  17800. _caretBrowsing: null,
  17801. _isScrolling: false,
  17802. editorUndoBar: null,
  17803. async initialize(appConfig) {
  17804. this.appConfig = appConfig;
  17805. try {
  17806. await this.preferences.initializedPromise;
  17807. } catch (ex) {
  17808. console.error("initialize:", ex);
  17809. }
  17810. if (AppOptions.get("pdfBugEnabled")) {
  17811. await this._parseHashParams();
  17812. }
  17813. let mode;
  17814. switch (AppOptions.get("viewerCssTheme")) {
  17815. case 1:
  17816. mode = "light";
  17817. break;
  17818. case 2:
  17819. mode = "dark";
  17820. break;
  17821. }
  17822. if (mode) {
  17823. docStyle.setProperty("color-scheme", mode);
  17824. }
  17825. this.l10n = await this.externalServices.createL10n();
  17826. document.getElementsByTagName("html")[0].dir = this.l10n.getDirection();
  17827. this.l10n.translate(appConfig.appContainer || document.documentElement);
  17828. if (this.isViewerEmbedded && AppOptions.get("externalLinkTarget") === LinkTarget.NONE) {
  17829. AppOptions.set("externalLinkTarget", LinkTarget.TOP);
  17830. }
  17831. await this._initializeViewerComponents();
  17832. this.bindEvents();
  17833. this.bindWindowEvents();
  17834. this._initializedCapability.settled = true;
  17835. this._initializedCapability.resolve();
  17836. },
  17837. async _parseHashParams() {
  17838. const hash = document.location.hash.substring(1);
  17839. if (!hash) {
  17840. return;
  17841. }
  17842. const {
  17843. mainContainer,
  17844. viewerContainer
  17845. } = this.appConfig,
  17846. params = parseQueryString(hash);
  17847. const loadPDFBug = async () => {
  17848. if (this._PDFBug) {
  17849. return;
  17850. }
  17851. const {
  17852. PDFBug
  17853. } = await import(
  17854. /*webpackIgnore: true*/
  17855. /*@vite-ignore*/
  17856. AppOptions.get("debuggerSrc"));
  17857. this._PDFBug = PDFBug;
  17858. };
  17859. if (params.get("disableworker") === "true") {
  17860. try {
  17861. GlobalWorkerOptions.workerSrc ||= AppOptions.get("workerSrc");
  17862. await import(
  17863. /*webpackIgnore: true*/
  17864. /*@vite-ignore*/
  17865. PDFWorker.workerSrc);
  17866. AppOptions.set("workerPort", null);
  17867. } catch (ex) {
  17868. console.error("_parseHashParams:", ex);
  17869. }
  17870. }
  17871. if (params.has("textlayer")) {
  17872. switch (params.get("textlayer")) {
  17873. case "off":
  17874. AppOptions.set("textLayerMode", TextLayerMode.DISABLE);
  17875. break;
  17876. case "visible":
  17877. case "shadow":
  17878. case "hover":
  17879. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  17880. try {
  17881. await loadPDFBug();
  17882. this._PDFBug.loadCSS();
  17883. } catch (ex) {
  17884. console.error("_parseHashParams:", ex);
  17885. }
  17886. break;
  17887. }
  17888. }
  17889. if (params.has("pdfbug")) {
  17890. const enabled = params.get("pdfbug").split(",");
  17891. try {
  17892. await loadPDFBug();
  17893. this._PDFBug.init(mainContainer, enabled);
  17894. } catch (ex) {
  17895. console.error("_parseHashParams:", ex);
  17896. }
  17897. const debugOpts = {
  17898. pdfBug: true,
  17899. fontExtraProperties: true
  17900. };
  17901. if (globalThis.StepperManager?.enabled) {
  17902. debugOpts.minDurationToUpdateCanvas = 0;
  17903. }
  17904. AppOptions.setAll(debugOpts);
  17905. }
  17906. if (params.has("locale")) {
  17907. AppOptions.set("localeProperties", {
  17908. lang: params.get("locale")
  17909. });
  17910. }
  17911. const opts = {
  17912. disableAutoFetch: x => x === "true",
  17913. disableFontFace: x => x === "true",
  17914. disableHistory: x => x === "true",
  17915. disableRange: x => x === "true",
  17916. disableStream: x => x === "true",
  17917. verbosity: x => x | 0
  17918. };
  17919. for (const name in opts) {
  17920. const check = opts[name],
  17921. key = name.toLowerCase();
  17922. if (params.has(key)) {
  17923. AppOptions.set(name, check(params.get(key)));
  17924. }
  17925. }
  17926. },
  17927. async _initializeViewerComponents() {
  17928. const {
  17929. appConfig,
  17930. externalServices,
  17931. l10n,
  17932. mlManager
  17933. } = this;
  17934. const abortSignal = this._globalAbortController.signal;
  17935. const eventBus = new EventBus();
  17936. this.eventBus = AppOptions.eventBus = eventBus;
  17937. mlManager?.setEventBus(eventBus, abortSignal);
  17938. const overlayManager = this.overlayManager = new OverlayManager();
  17939. const renderingQueue = this.pdfRenderingQueue = new PDFRenderingQueue();
  17940. renderingQueue.onIdle = this._cleanup.bind(this);
  17941. const linkService = this.pdfLinkService = new PDFLinkService({
  17942. eventBus,
  17943. externalLinkTarget: AppOptions.get("externalLinkTarget"),
  17944. externalLinkRel: AppOptions.get("externalLinkRel"),
  17945. ignoreDestinationZoom: AppOptions.get("ignoreDestinationZoom")
  17946. });
  17947. const downloadManager = this.downloadManager = new DownloadManager();
  17948. const findController = this.findController = new PDFFindController({
  17949. linkService,
  17950. eventBus,
  17951. updateMatchesCountOnProgress: true
  17952. });
  17953. const pdfScriptingManager = this.pdfScriptingManager = new PDFScriptingManager({
  17954. eventBus,
  17955. externalServices,
  17956. docProperties: this._scriptingDocProperties.bind(this)
  17957. });
  17958. const container = appConfig.mainContainer,
  17959. viewer = appConfig.viewerContainer;
  17960. const annotationEditorMode = AppOptions.get("annotationEditorMode");
  17961. const pageColors = AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  17962. background: AppOptions.get("pageColorsBackground"),
  17963. foreground: AppOptions.get("pageColorsForeground")
  17964. } : null;
  17965. let altTextManager;
  17966. if (AppOptions.get("enableUpdatedAddImage")) {
  17967. altTextManager = appConfig.newAltTextDialog ? new NewAltTextManager(appConfig.newAltTextDialog, overlayManager, eventBus) : null;
  17968. } else {
  17969. altTextManager = appConfig.altTextDialog ? new AltTextManager(appConfig.altTextDialog, container, overlayManager, eventBus) : null;
  17970. }
  17971. if (appConfig.editorUndoBar) {
  17972. this.editorUndoBar = new EditorUndoBar(appConfig.editorUndoBar, eventBus);
  17973. }
  17974. const signatureManager = AppOptions.get("enableSignatureEditor") && appConfig.addSignatureDialog ? new SignatureManager(appConfig.addSignatureDialog, appConfig.editSignatureDialog, appConfig.annotationEditorParams?.editorSignatureAddSignature || null, overlayManager, l10n, externalServices.createSignatureStorage(eventBus, abortSignal), eventBus) : null;
  17975. const enableHWA = AppOptions.get("enableHWA"),
  17976. maxCanvasPixels = AppOptions.get("maxCanvasPixels"),
  17977. maxCanvasDim = AppOptions.get("maxCanvasDim"),
  17978. capCanvasAreaFactor = AppOptions.get("capCanvasAreaFactor");
  17979. const pdfViewer = this.pdfViewer = new PDFViewer({
  17980. container,
  17981. viewer,
  17982. eventBus,
  17983. renderingQueue,
  17984. linkService,
  17985. downloadManager,
  17986. altTextManager,
  17987. signatureManager,
  17988. editorUndoBar: this.editorUndoBar,
  17989. findController,
  17990. scriptingManager: AppOptions.get("enableScripting") && pdfScriptingManager,
  17991. l10n,
  17992. textLayerMode: AppOptions.get("textLayerMode"),
  17993. annotationMode: AppOptions.get("annotationMode"),
  17994. annotationEditorMode,
  17995. annotationEditorHighlightColors: AppOptions.get("highlightEditorColors"),
  17996. enableHighlightFloatingButton: AppOptions.get("enableHighlightFloatingButton"),
  17997. enableUpdatedAddImage: AppOptions.get("enableUpdatedAddImage"),
  17998. enableNewAltTextWhenAddingImage: AppOptions.get("enableNewAltTextWhenAddingImage"),
  17999. imageResourcesPath: AppOptions.get("imageResourcesPath"),
  18000. enablePrintAutoRotate: AppOptions.get("enablePrintAutoRotate"),
  18001. maxCanvasPixels,
  18002. maxCanvasDim,
  18003. capCanvasAreaFactor,
  18004. enableDetailCanvas: AppOptions.get("enableDetailCanvas"),
  18005. enablePermissions: AppOptions.get("enablePermissions"),
  18006. pageColors,
  18007. mlManager,
  18008. abortSignal,
  18009. enableHWA,
  18010. supportsPinchToZoom: this.supportsPinchToZoom,
  18011. enableAutoLinking: AppOptions.get("enableAutoLinking"),
  18012. minDurationToUpdateCanvas: AppOptions.get("minDurationToUpdateCanvas")
  18013. });
  18014. renderingQueue.setViewer(pdfViewer);
  18015. linkService.setViewer(pdfViewer);
  18016. pdfScriptingManager.setViewer(pdfViewer);
  18017. if (appConfig.sidebar?.thumbnailView) {
  18018. this.pdfThumbnailViewer = new PDFThumbnailViewer({
  18019. container: appConfig.sidebar.thumbnailView,
  18020. eventBus,
  18021. renderingQueue,
  18022. linkService,
  18023. maxCanvasPixels,
  18024. maxCanvasDim,
  18025. pageColors,
  18026. abortSignal,
  18027. enableHWA
  18028. });
  18029. renderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  18030. }
  18031. if (!this.isViewerEmbedded && !AppOptions.get("disableHistory")) {
  18032. this.pdfHistory = new PDFHistory({
  18033. linkService,
  18034. eventBus
  18035. });
  18036. linkService.setHistory(this.pdfHistory);
  18037. }
  18038. if (!this.supportsIntegratedFind && appConfig.findBar) {
  18039. this.findBar = new PDFFindBar(appConfig.findBar, appConfig.principalContainer, eventBus);
  18040. }
  18041. if (appConfig.annotationEditorParams) {
  18042. if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
  18043. const editorSignatureButton = appConfig.toolbar?.editorSignatureButton;
  18044. if (editorSignatureButton && AppOptions.get("enableSignatureEditor")) {
  18045. editorSignatureButton.parentElement.hidden = false;
  18046. }
  18047. this.annotationEditorParams = new AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  18048. } else {
  18049. for (const id of ["editorModeButtons", "editorModeSeparator"]) {
  18050. document.getElementById(id)?.classList.add("hidden");
  18051. }
  18052. }
  18053. }
  18054. if (mlManager && appConfig.secondaryToolbar?.imageAltTextSettingsButton) {
  18055. this.imageAltTextSettings = new ImageAltTextSettings(appConfig.altTextSettingsDialog, overlayManager, eventBus, mlManager);
  18056. }
  18057. if (appConfig.documentProperties) {
  18058. this.pdfDocumentProperties = new PDFDocumentProperties(appConfig.documentProperties, overlayManager, eventBus, l10n, () => this._docFilename, () => this._docTitle);
  18059. }
  18060. if (appConfig.secondaryToolbar?.cursorHandToolButton) {
  18061. this.pdfCursorTools = new PDFCursorTools({
  18062. container,
  18063. eventBus,
  18064. cursorToolOnLoad: AppOptions.get("cursorToolOnLoad")
  18065. });
  18066. }
  18067. if (appConfig.toolbar) {
  18068. this.toolbar = new Toolbar(appConfig.toolbar, eventBus, AppOptions.get("toolbarDensity"));
  18069. }
  18070. if (appConfig.secondaryToolbar) {
  18071. if (AppOptions.get("enableAltText")) {
  18072. appConfig.secondaryToolbar.imageAltTextSettingsButton?.classList.remove("hidden");
  18073. appConfig.secondaryToolbar.imageAltTextSettingsSeparator?.classList.remove("hidden");
  18074. }
  18075. this.secondaryToolbar = new SecondaryToolbar(appConfig.secondaryToolbar, eventBus);
  18076. }
  18077. if (this.supportsFullscreen && appConfig.secondaryToolbar?.presentationModeButton) {
  18078. this.pdfPresentationMode = new PDFPresentationMode({
  18079. container,
  18080. pdfViewer,
  18081. eventBus
  18082. });
  18083. }
  18084. if (appConfig.passwordOverlay) {
  18085. this.passwordPrompt = new PasswordPrompt(appConfig.passwordOverlay, overlayManager, this.isViewerEmbedded);
  18086. }
  18087. if (appConfig.sidebar?.outlineView) {
  18088. this.pdfOutlineViewer = new PDFOutlineViewer({
  18089. container: appConfig.sidebar.outlineView,
  18090. eventBus,
  18091. l10n,
  18092. linkService,
  18093. downloadManager
  18094. });
  18095. }
  18096. if (appConfig.sidebar?.attachmentsView) {
  18097. this.pdfAttachmentViewer = new PDFAttachmentViewer({
  18098. container: appConfig.sidebar.attachmentsView,
  18099. eventBus,
  18100. l10n,
  18101. downloadManager
  18102. });
  18103. }
  18104. if (appConfig.sidebar?.layersView) {
  18105. this.pdfLayerViewer = new PDFLayerViewer({
  18106. container: appConfig.sidebar.layersView,
  18107. eventBus,
  18108. l10n
  18109. });
  18110. }
  18111. if (appConfig.sidebar) {
  18112. this.pdfSidebar = new PDFSidebar({
  18113. elements: appConfig.sidebar,
  18114. eventBus,
  18115. l10n
  18116. });
  18117. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  18118. this.pdfSidebar.onUpdateThumbnails = () => {
  18119. for (const pageView of pdfViewer.getCachedPageViews()) {
  18120. if (pageView.renderingState === RenderingStates.FINISHED) {
  18121. this.pdfThumbnailViewer.getThumbnail(pageView.id - 1)?.setImage(pageView);
  18122. }
  18123. }
  18124. this.pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  18125. };
  18126. }
  18127. },
  18128. async run(config) {
  18129. await this.initialize(config);
  18130. const {
  18131. appConfig,
  18132. eventBus
  18133. } = this;
  18134. let file;
  18135. let hasRole;
  18136. const queryString = document.location.search.substring(1);
  18137. const params = parseQueryString(queryString);
  18138. file = params.get("file") ?? AppOptions.get("defaultUrl");
  18139. hasRole = params.get("hasrole") ?? AppOptions.get("hasRole");
  18140. // validateFileURL(file);
  18141. const fileInput = this._openFileInput = document.createElement("input");
  18142. fileInput.id = "fileInput";
  18143. fileInput.hidden = true;
  18144. fileInput.type = "file";
  18145. fileInput.value = null;
  18146. document.body.append(fileInput);
  18147. // 权限判定,无权限用户隐藏部分功能按钮
  18148. if (hasRole !== '1') {
  18149. appConfig.toolbar?.download.setAttribute("hidden", "true");
  18150. appConfig.toolbar?.print.setAttribute("hidden", "true");
  18151. appConfig.secondaryToolbar?.downloadButton.setAttribute("hidden", "true");
  18152. appConfig.secondaryToolbar?.printButton.setAttribute("hidden", "true");
  18153. appConfig.secondaryToolbar?.openFileButton.setAttribute("hidden", "true");
  18154. appConfig.secondaryToolbar?.viewBookmarkButton.setAttribute("hidden", "true");
  18155. }
  18156. fileInput.addEventListener("change", function (evt) {
  18157. const {
  18158. files
  18159. } = evt.target;
  18160. if (!files || files.length === 0) {
  18161. return;
  18162. }
  18163. eventBus.dispatch("fileinputchange", {
  18164. source: this,
  18165. fileInput: evt.target
  18166. });
  18167. });
  18168. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  18169. for (const item of evt.dataTransfer.items) {
  18170. if (item.type === "application/pdf") {
  18171. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  18172. stopEvent(evt);
  18173. return;
  18174. }
  18175. }
  18176. });
  18177. appConfig.mainContainer.addEventListener("drop", function (evt) {
  18178. if (evt.dataTransfer.files?.[0].type !== "application/pdf") {
  18179. return;
  18180. }
  18181. stopEvent(evt);
  18182. eventBus.dispatch("fileinputchange", {
  18183. source: this,
  18184. fileInput: evt.dataTransfer
  18185. });
  18186. });
  18187. if (!AppOptions.get("supportsDocumentFonts")) {
  18188. AppOptions.set("disableFontFace", true);
  18189. this.l10n.get("pdfjs-web-fonts-disabled").then(msg => {
  18190. console.warn(msg);
  18191. });
  18192. }
  18193. if (!this.supportsPrinting) {
  18194. appConfig.toolbar?.print?.classList.add("hidden");
  18195. appConfig.secondaryToolbar?.printButton.classList.add("hidden");
  18196. }
  18197. if (!this.supportsFullscreen) {
  18198. appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
  18199. }
  18200. if (this.supportsIntegratedFind) {
  18201. appConfig.findBar?.toggleButton?.classList.add("hidden");
  18202. }
  18203. if (file) {
  18204. this.open({
  18205. url: file
  18206. });
  18207. } else {
  18208. this._hideViewBookmark();
  18209. }
  18210. },
  18211. get externalServices() {
  18212. return shadow(this, "externalServices", new ExternalServices());
  18213. },
  18214. get initialized() {
  18215. return this._initializedCapability.settled;
  18216. },
  18217. get initializedPromise() {
  18218. return this._initializedCapability.promise;
  18219. },
  18220. updateZoom(steps, scaleFactor, origin) {
  18221. if (this.pdfViewer.isInPresentationMode) {
  18222. return;
  18223. }
  18224. this.pdfViewer.updateScale({
  18225. drawingDelay: AppOptions.get("defaultZoomDelay"),
  18226. steps,
  18227. scaleFactor,
  18228. origin
  18229. });
  18230. },
  18231. zoomIn() {
  18232. this.updateZoom(1);
  18233. },
  18234. zoomOut() {
  18235. this.updateZoom(-1);
  18236. },
  18237. zoomReset() {
  18238. if (this.pdfViewer.isInPresentationMode) {
  18239. return;
  18240. }
  18241. this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
  18242. },
  18243. touchPinchCallback(origin, prevDistance, distance) {
  18244. if (this.supportsPinchToZoom) {
  18245. const newScaleFactor = this._accumulateFactor(this.pdfViewer.currentScale, distance / prevDistance, "_touchUnusedFactor");
  18246. this.updateZoom(null, newScaleFactor, origin);
  18247. } else {
  18248. const PIXELS_PER_LINE_SCALE = 30;
  18249. const ticks = this._accumulateTicks((distance - prevDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks");
  18250. this.updateZoom(ticks, null, origin);
  18251. }
  18252. },
  18253. touchPinchEndCallback() {
  18254. this._touchUnusedTicks = 0;
  18255. this._touchUnusedFactor = 1;
  18256. },
  18257. get pagesCount() {
  18258. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  18259. },
  18260. get page() {
  18261. return this.pdfViewer.currentPageNumber;
  18262. },
  18263. set page(val) {
  18264. this.pdfViewer.currentPageNumber = val;
  18265. },
  18266. get supportsPrinting() {
  18267. return shadow(this, "supportsPrinting", AppOptions.get("supportsPrinting") && PDFPrintServiceFactory.supportsPrinting);
  18268. },
  18269. get supportsFullscreen() {
  18270. return shadow(this, "supportsFullscreen", document.fullscreenEnabled);
  18271. },
  18272. get supportsPinchToZoom() {
  18273. return shadow(this, "supportsPinchToZoom", AppOptions.get("supportsPinchToZoom"));
  18274. },
  18275. get supportsIntegratedFind() {
  18276. return shadow(this, "supportsIntegratedFind", AppOptions.get("supportsIntegratedFind"));
  18277. },
  18278. get loadingBar() {
  18279. const barElement = document.getElementById("loadingBar");
  18280. const bar = barElement ? new ProgressBar(barElement) : null;
  18281. return shadow(this, "loadingBar", bar);
  18282. },
  18283. get supportsMouseWheelZoomCtrlKey() {
  18284. return shadow(this, "supportsMouseWheelZoomCtrlKey", AppOptions.get("supportsMouseWheelZoomCtrlKey"));
  18285. },
  18286. get supportsMouseWheelZoomMetaKey() {
  18287. return shadow(this, "supportsMouseWheelZoomMetaKey", AppOptions.get("supportsMouseWheelZoomMetaKey"));
  18288. },
  18289. get supportsCaretBrowsingMode() {
  18290. return AppOptions.get("supportsCaretBrowsingMode");
  18291. },
  18292. moveCaret(isUp, select) {
  18293. this._caretBrowsing ||= new CaretBrowsingMode(this._globalAbortController.signal, this.appConfig.mainContainer, this.appConfig.viewerContainer, this.appConfig.toolbar?.container);
  18294. this._caretBrowsing.moveCaret(isUp, select);
  18295. },
  18296. setTitleUsingUrl(url = "", downloadUrl = null) {
  18297. this.url = url;
  18298. this.baseUrl = updateUrlHash(url, "", true);
  18299. if (downloadUrl) {
  18300. this._downloadUrl = downloadUrl === url ? this.baseUrl : updateUrlHash(downloadUrl, "", true);
  18301. }
  18302. if (isDataScheme(url)) {
  18303. this._hideViewBookmark();
  18304. }
  18305. let title = pdfjs_getPdfFilenameFromUrl(url, "");
  18306. if (!title) {
  18307. try {
  18308. title = decodeURIComponent(getFilenameFromUrl(url));
  18309. } catch {}
  18310. }
  18311. this.setTitle(title || url);
  18312. },
  18313. setTitle(title = this._title) {
  18314. this._title = title;
  18315. if (this.isViewerEmbedded) {
  18316. return;
  18317. }
  18318. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  18319. document.title = `${editorIndicator ? "* " : ""}${title}`;
  18320. },
  18321. get _docFilename() {
  18322. return this._contentDispositionFilename || pdfjs_getPdfFilenameFromUrl(this.url);
  18323. },
  18324. get _docTitle() {
  18325. const {
  18326. documentInfo,
  18327. metadata
  18328. } = this;
  18329. const title = metadata?.get("dc:title");
  18330. if (title) {
  18331. if (title !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(title)) {
  18332. return title;
  18333. }
  18334. }
  18335. return documentInfo.Title;
  18336. },
  18337. _hideViewBookmark() {
  18338. const {
  18339. secondaryToolbar
  18340. } = this.appConfig;
  18341. secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
  18342. if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) {
  18343. document.getElementById("viewBookmarkSeparator")?.classList.add("hidden");
  18344. }
  18345. },
  18346. async close() {
  18347. this._unblockDocumentLoadEvent();
  18348. this._hideViewBookmark();
  18349. if (!this.pdfLoadingTask) {
  18350. return;
  18351. }
  18352. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  18353. try {
  18354. await this.save();
  18355. } catch {}
  18356. }
  18357. const promises = [];
  18358. promises.push(this.pdfLoadingTask.destroy());
  18359. this.pdfLoadingTask = null;
  18360. if (this.pdfDocument) {
  18361. this.pdfDocument = null;
  18362. this.pdfThumbnailViewer?.setDocument(null);
  18363. this.pdfViewer.setDocument(null);
  18364. this.pdfLinkService.setDocument(null);
  18365. this.pdfDocumentProperties?.setDocument(null);
  18366. }
  18367. this.pdfLinkService.externalLinkEnabled = true;
  18368. this.store = null;
  18369. this.isInitialViewSet = false;
  18370. this.url = "";
  18371. this.baseUrl = "";
  18372. this._downloadUrl = "";
  18373. this.documentInfo = null;
  18374. this.metadata = null;
  18375. this._contentDispositionFilename = null;
  18376. this._contentLength = null;
  18377. this._saveInProgress = false;
  18378. this._hasAnnotationEditors = false;
  18379. promises.push(this.pdfScriptingManager.destroyPromise, this.passwordPrompt.close());
  18380. this.setTitle();
  18381. this.pdfSidebar?.reset();
  18382. this.pdfOutlineViewer?.reset();
  18383. this.pdfAttachmentViewer?.reset();
  18384. this.pdfLayerViewer?.reset();
  18385. this.pdfHistory?.reset();
  18386. this.findBar?.reset();
  18387. this.toolbar?.reset();
  18388. this.secondaryToolbar?.reset();
  18389. this._PDFBug?.cleanup();
  18390. await Promise.all(promises);
  18391. },
  18392. async open(args) {
  18393. if (this.pdfLoadingTask) {
  18394. await this.close();
  18395. }
  18396. const workerParams = AppOptions.getAll(OptionKind.WORKER);
  18397. Object.assign(GlobalWorkerOptions, workerParams);
  18398. if (args.url) {
  18399. this.setTitleUsingUrl(args.originalUrl || args.url, args.url);
  18400. }
  18401. const apiParams = AppOptions.getAll(OptionKind.API);
  18402. const loadingTask = getDocument({
  18403. ...apiParams,
  18404. ...args
  18405. });
  18406. this.pdfLoadingTask = loadingTask;
  18407. loadingTask.onPassword = (updateCallback, reason) => {
  18408. if (this.isViewerEmbedded) {
  18409. this._unblockDocumentLoadEvent();
  18410. }
  18411. this.pdfLinkService.externalLinkEnabled = false;
  18412. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  18413. this.passwordPrompt.open();
  18414. };
  18415. loadingTask.onProgress = ({
  18416. loaded,
  18417. total
  18418. }) => {
  18419. this.progress(loaded / total);
  18420. };
  18421. return loadingTask.promise.then(pdfDocument => {
  18422. this.load(pdfDocument);
  18423. }, reason => {
  18424. if (loadingTask !== this.pdfLoadingTask) {
  18425. return undefined;
  18426. }
  18427. let key = "pdfjs-loading-error";
  18428. if (reason instanceof InvalidPDFException) {
  18429. key = "pdfjs-invalid-file-error";
  18430. } else if (reason instanceof ResponseException) {
  18431. key = reason.missing ? "pdfjs-missing-file-error" : "pdfjs-unexpected-response-error";
  18432. }
  18433. return this._documentError(key, {
  18434. message: reason.message
  18435. }).then(() => {
  18436. throw reason;
  18437. });
  18438. });
  18439. },
  18440. async download() {
  18441. let data;
  18442. try {
  18443. data = await (this.pdfDocument ? this.pdfDocument.getData() : this.pdfLoadingTask.getData());
  18444. } catch {}
  18445. this.downloadManager.download(data, this._downloadUrl, this._docFilename);
  18446. },
  18447. async save() {
  18448. if (this._saveInProgress) {
  18449. return;
  18450. }
  18451. this._saveInProgress = true;
  18452. await this.pdfScriptingManager.dispatchWillSave();
  18453. try {
  18454. const data = await this.pdfDocument.saveDocument();
  18455. this.downloadManager.download(data, this._downloadUrl, this._docFilename);
  18456. } catch (reason) {
  18457. console.error(`Error when saving the document:`, reason);
  18458. await this.download();
  18459. } finally {
  18460. await this.pdfScriptingManager.dispatchDidSave();
  18461. this._saveInProgress = false;
  18462. }
  18463. if (this._hasAnnotationEditors) {
  18464. this.externalServices.reportTelemetry({
  18465. type: "editing",
  18466. data: {
  18467. type: "save",
  18468. stats: this.pdfDocument?.annotationStorage.editorStats
  18469. }
  18470. });
  18471. }
  18472. },
  18473. async downloadOrSave() {
  18474. const {
  18475. classList
  18476. } = this.appConfig.appContainer;
  18477. classList.add("wait");
  18478. await (this.pdfDocument?.annotationStorage.size > 0 ? this.save() : this.download());
  18479. classList.remove("wait");
  18480. },
  18481. async _documentError(key, moreInfo = null) {
  18482. this._unblockDocumentLoadEvent();
  18483. const message = await this._otherError(key || "pdfjs-loading-error", moreInfo);
  18484. this.eventBus.dispatch("documenterror", {
  18485. source: this,
  18486. message,
  18487. reason: moreInfo?.message ?? null
  18488. });
  18489. },
  18490. async _otherError(key, moreInfo = null) {
  18491. const message = await this.l10n.get(key);
  18492. const moreInfoText = [`PDF.js v${version || "?"} (build: ${build || "?"})`];
  18493. if (moreInfo) {
  18494. moreInfoText.push(`Message: ${moreInfo.message}`);
  18495. if (moreInfo.stack) {
  18496. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  18497. } else {
  18498. if (moreInfo.filename) {
  18499. moreInfoText.push(`File: ${moreInfo.filename}`);
  18500. }
  18501. if (moreInfo.lineNumber) {
  18502. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  18503. }
  18504. }
  18505. }
  18506. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  18507. return message;
  18508. },
  18509. progress(level) {
  18510. const percent = Math.round(level * 100);
  18511. if (!this.loadingBar || percent <= this.loadingBar.percent) {
  18512. return;
  18513. }
  18514. this.loadingBar.percent = percent;
  18515. if (this.pdfDocument?.loadingParams.disableAutoFetch ?? AppOptions.get("disableAutoFetch")) {
  18516. this.loadingBar.setDisableAutoFetch();
  18517. }
  18518. },
  18519. load(pdfDocument) {
  18520. this.pdfDocument = pdfDocument;
  18521. pdfDocument.getDownloadInfo().then(({
  18522. length
  18523. }) => {
  18524. this._contentLength = length;
  18525. this.loadingBar?.hide();
  18526. firstPagePromise.then(() => {
  18527. this.eventBus.dispatch("documentloaded", {
  18528. source: this
  18529. });
  18530. });
  18531. });
  18532. const pageLayoutPromise = pdfDocument.getPageLayout().catch(() => {});
  18533. const pageModePromise = pdfDocument.getPageMode().catch(() => {});
  18534. const openActionPromise = pdfDocument.getOpenAction().catch(() => {});
  18535. this.toolbar?.setPagesCount(pdfDocument.numPages, false);
  18536. this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
  18537. this.pdfLinkService.setDocument(pdfDocument);
  18538. this.pdfDocumentProperties?.setDocument(pdfDocument);
  18539. const pdfViewer = this.pdfViewer;
  18540. pdfViewer.setDocument(pdfDocument);
  18541. const {
  18542. firstPagePromise,
  18543. onePageRendered,
  18544. pagesPromise
  18545. } = pdfViewer;
  18546. this.pdfThumbnailViewer?.setDocument(pdfDocument);
  18547. const storedPromise = (this.store = new ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  18548. page: null,
  18549. zoom: DEFAULT_SCALE_VALUE,
  18550. scrollLeft: "0",
  18551. scrollTop: "0",
  18552. rotation: null,
  18553. sidebarView: SidebarView.UNKNOWN,
  18554. scrollMode: ScrollMode.UNKNOWN,
  18555. spreadMode: SpreadMode.UNKNOWN
  18556. }).catch(() => {});
  18557. firstPagePromise.then(pdfPage => {
  18558. this.loadingBar?.setWidth(this.appConfig.viewerContainer);
  18559. this._initializeAnnotationStorageCallbacks(pdfDocument);
  18560. Promise.all([animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  18561. const viewOnLoad = AppOptions.get("viewOnLoad");
  18562. this._initializePdfHistory({
  18563. fingerprint: pdfDocument.fingerprints[0],
  18564. viewOnLoad,
  18565. initialDest: openAction?.dest
  18566. });
  18567. const initialBookmark = this.initialBookmark;
  18568. const zoom = AppOptions.get("defaultZoomValue");
  18569. let hash = zoom ? `zoom=${zoom}` : null;
  18570. let rotation = null;
  18571. let sidebarView = AppOptions.get("sidebarViewOnLoad");
  18572. let scrollMode = AppOptions.get("scrollModeOnLoad");
  18573. let spreadMode = AppOptions.get("spreadModeOnLoad");
  18574. if (stored?.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  18575. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  18576. rotation = parseInt(stored.rotation, 10);
  18577. if (sidebarView === SidebarView.UNKNOWN) {
  18578. sidebarView = stored.sidebarView | 0;
  18579. }
  18580. if (scrollMode === ScrollMode.UNKNOWN) {
  18581. scrollMode = stored.scrollMode | 0;
  18582. }
  18583. if (spreadMode === SpreadMode.UNKNOWN) {
  18584. spreadMode = stored.spreadMode | 0;
  18585. }
  18586. }
  18587. if (pageMode && sidebarView === SidebarView.UNKNOWN) {
  18588. sidebarView = apiPageModeToSidebarView(pageMode);
  18589. }
  18590. if (pageLayout && scrollMode === ScrollMode.UNKNOWN && spreadMode === SpreadMode.UNKNOWN) {
  18591. const modes = apiPageLayoutToViewerModes(pageLayout);
  18592. spreadMode = modes.spreadMode;
  18593. }
  18594. this.setInitialView(hash, {
  18595. rotation,
  18596. sidebarView,
  18597. scrollMode,
  18598. spreadMode
  18599. });
  18600. this.eventBus.dispatch("documentinit", {
  18601. source: this
  18602. });
  18603. if (!this.isViewerEmbedded) {
  18604. pdfViewer.focus();
  18605. }
  18606. await Promise.race([pagesPromise, new Promise(resolve => {
  18607. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  18608. })]);
  18609. if (!initialBookmark && !hash) {
  18610. return;
  18611. }
  18612. if (pdfViewer.hasEqualPageSizes) {
  18613. return;
  18614. }
  18615. this.initialBookmark = initialBookmark;
  18616. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  18617. this.setInitialView(hash);
  18618. }).catch(() => {
  18619. this.setInitialView();
  18620. }).then(function () {
  18621. pdfViewer.update();
  18622. });
  18623. });
  18624. pagesPromise.then(() => {
  18625. this._unblockDocumentLoadEvent();
  18626. this._initializeAutoPrint(pdfDocument, openActionPromise);
  18627. }, reason => {
  18628. this._documentError("pdfjs-loading-error", {
  18629. message: reason.message
  18630. });
  18631. });
  18632. onePageRendered.then(data => {
  18633. this.externalServices.reportTelemetry({
  18634. type: "pageInfo",
  18635. timestamp: data.timestamp
  18636. });
  18637. if (this.pdfOutlineViewer) {
  18638. pdfDocument.getOutline().then(outline => {
  18639. if (pdfDocument !== this.pdfDocument) {
  18640. return;
  18641. }
  18642. this.pdfOutlineViewer.render({
  18643. outline,
  18644. pdfDocument
  18645. });
  18646. });
  18647. }
  18648. if (this.pdfAttachmentViewer) {
  18649. pdfDocument.getAttachments().then(attachments => {
  18650. if (pdfDocument !== this.pdfDocument) {
  18651. return;
  18652. }
  18653. this.pdfAttachmentViewer.render({
  18654. attachments
  18655. });
  18656. });
  18657. }
  18658. if (this.pdfLayerViewer) {
  18659. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  18660. if (pdfDocument !== this.pdfDocument) {
  18661. return;
  18662. }
  18663. this.pdfLayerViewer.render({
  18664. optionalContentConfig,
  18665. pdfDocument
  18666. });
  18667. });
  18668. }
  18669. });
  18670. this._initializePageLabels(pdfDocument);
  18671. this._initializeMetadata(pdfDocument);
  18672. },
  18673. async _scriptingDocProperties(pdfDocument) {
  18674. if (!this.documentInfo) {
  18675. await new Promise(resolve => {
  18676. this.eventBus._on("metadataloaded", resolve, {
  18677. once: true
  18678. });
  18679. });
  18680. if (pdfDocument !== this.pdfDocument) {
  18681. return null;
  18682. }
  18683. }
  18684. if (!this._contentLength) {
  18685. await new Promise(resolve => {
  18686. this.eventBus._on("documentloaded", resolve, {
  18687. once: true
  18688. });
  18689. });
  18690. if (pdfDocument !== this.pdfDocument) {
  18691. return null;
  18692. }
  18693. }
  18694. return {
  18695. ...this.documentInfo,
  18696. baseURL: this.baseUrl,
  18697. filesize: this._contentLength,
  18698. filename: this._docFilename,
  18699. metadata: this.metadata?.getRaw(),
  18700. authors: this.metadata?.get("dc:creator"),
  18701. numPages: this.pagesCount,
  18702. URL: this.url
  18703. };
  18704. },
  18705. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  18706. const [openAction, jsActions] = await Promise.all([openActionPromise, this.pdfViewer.enableScripting ? null : pdfDocument.getJSActions()]);
  18707. if (pdfDocument !== this.pdfDocument) {
  18708. return;
  18709. }
  18710. let triggerAutoPrint = openAction?.action === "Print";
  18711. if (jsActions) {
  18712. console.warn("Warning: JavaScript support is not enabled");
  18713. for (const name in jsActions) {
  18714. if (triggerAutoPrint) {
  18715. break;
  18716. }
  18717. switch (name) {
  18718. case "WillClose":
  18719. case "WillSave":
  18720. case "DidSave":
  18721. case "WillPrint":
  18722. case "DidPrint":
  18723. continue;
  18724. }
  18725. triggerAutoPrint = jsActions[name].some(js => AutoPrintRegExp.test(js));
  18726. }
  18727. }
  18728. if (triggerAutoPrint) {
  18729. this.triggerPrinting();
  18730. }
  18731. },
  18732. async _initializeMetadata(pdfDocument) {
  18733. const {
  18734. info,
  18735. metadata,
  18736. contentDispositionFilename,
  18737. contentLength
  18738. } = await pdfDocument.getMetadata();
  18739. if (pdfDocument !== this.pdfDocument) {
  18740. return;
  18741. }
  18742. this.documentInfo = info;
  18743. this.metadata = metadata;
  18744. this._contentDispositionFilename ??= contentDispositionFilename;
  18745. this._contentLength ??= contentLength;
  18746. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(metadata?.get("pdf:producer") || info.Producer || "-").trim()} / ` + `${(metadata?.get("xmp:creatortool") || info.Creator || "-").trim()}` + `] (PDF.js: ${version || "?"} [${build || "?"}])`);
  18747. const pdfTitle = this._docTitle;
  18748. if (pdfTitle) {
  18749. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  18750. } else if (this._contentDispositionFilename) {
  18751. this.setTitle(this._contentDispositionFilename);
  18752. }
  18753. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  18754. if (pdfDocument.loadingParams.enableXfa) {
  18755. console.warn("Warning: XFA Foreground documents are not supported");
  18756. } else {
  18757. console.warn("Warning: XFA support is not enabled");
  18758. }
  18759. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  18760. console.warn("Warning: Interactive form support is not enabled");
  18761. }
  18762. if (info.IsSignaturesPresent) {
  18763. console.warn("Warning: Digital signatures validation is not supported");
  18764. }
  18765. this.eventBus.dispatch("metadataloaded", {
  18766. source: this
  18767. });
  18768. },
  18769. async _initializePageLabels(pdfDocument) {
  18770. const labels = await pdfDocument.getPageLabels();
  18771. if (pdfDocument !== this.pdfDocument) {
  18772. return;
  18773. }
  18774. if (!labels || AppOptions.get("disablePageLabels")) {
  18775. return;
  18776. }
  18777. const numLabels = labels.length;
  18778. let standardLabels = 0,
  18779. emptyLabels = 0;
  18780. for (let i = 0; i < numLabels; i++) {
  18781. const label = labels[i];
  18782. if (label === (i + 1).toString()) {
  18783. standardLabels++;
  18784. } else if (label === "") {
  18785. emptyLabels++;
  18786. } else {
  18787. break;
  18788. }
  18789. }
  18790. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  18791. return;
  18792. }
  18793. const {
  18794. pdfViewer,
  18795. pdfThumbnailViewer,
  18796. toolbar
  18797. } = this;
  18798. pdfViewer.setPageLabels(labels);
  18799. pdfThumbnailViewer?.setPageLabels(labels);
  18800. toolbar?.setPagesCount(numLabels, true);
  18801. toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  18802. },
  18803. _initializePdfHistory({
  18804. fingerprint,
  18805. viewOnLoad,
  18806. initialDest = null
  18807. }) {
  18808. if (!this.pdfHistory) {
  18809. return;
  18810. }
  18811. this.pdfHistory.initialize({
  18812. fingerprint,
  18813. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  18814. updateUrl: AppOptions.get("historyUpdateUrl")
  18815. });
  18816. if (this.pdfHistory.initialBookmark) {
  18817. this.initialBookmark = this.pdfHistory.initialBookmark;
  18818. this.initialRotation = this.pdfHistory.initialRotation;
  18819. }
  18820. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  18821. this.initialBookmark = JSON.stringify(initialDest);
  18822. this.pdfHistory.push({
  18823. explicitDest: initialDest,
  18824. pageNumber: null
  18825. });
  18826. }
  18827. },
  18828. _initializeAnnotationStorageCallbacks(pdfDocument) {
  18829. if (pdfDocument !== this.pdfDocument) {
  18830. return;
  18831. }
  18832. const {
  18833. annotationStorage
  18834. } = pdfDocument;
  18835. annotationStorage.onSetModified = () => {
  18836. window.addEventListener("beforeunload", beforeUnload);
  18837. this._annotationStorageModified = true;
  18838. };
  18839. annotationStorage.onResetModified = () => {
  18840. window.removeEventListener("beforeunload", beforeUnload);
  18841. delete this._annotationStorageModified;
  18842. };
  18843. annotationStorage.onAnnotationEditor = typeStr => {
  18844. this._hasAnnotationEditors = !!typeStr;
  18845. this.setTitle();
  18846. };
  18847. },
  18848. setInitialView(storedHash, {
  18849. rotation,
  18850. sidebarView,
  18851. scrollMode,
  18852. spreadMode
  18853. } = {}) {
  18854. const setRotation = angle => {
  18855. if (isValidRotation(angle)) {
  18856. this.pdfViewer.pagesRotation = angle;
  18857. }
  18858. };
  18859. const setViewerModes = (scroll, spread) => {
  18860. if (isValidScrollMode(scroll)) {
  18861. this.pdfViewer.scrollMode = scroll;
  18862. }
  18863. if (isValidSpreadMode(spread)) {
  18864. this.pdfViewer.spreadMode = spread;
  18865. }
  18866. };
  18867. this.isInitialViewSet = true;
  18868. this.pdfSidebar?.setInitialView(sidebarView);
  18869. setViewerModes(scrollMode, spreadMode);
  18870. if (this.initialBookmark) {
  18871. setRotation(this.initialRotation);
  18872. delete this.initialRotation;
  18873. this.pdfLinkService.setHash(this.initialBookmark);
  18874. this.initialBookmark = null;
  18875. } else if (storedHash) {
  18876. setRotation(rotation);
  18877. this.pdfLinkService.setHash(storedHash);
  18878. }
  18879. this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  18880. this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
  18881. if (!this.pdfViewer.currentScaleValue) {
  18882. this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
  18883. }
  18884. },
  18885. _cleanup() {
  18886. if (!this.pdfDocument) {
  18887. return;
  18888. }
  18889. this.pdfViewer.cleanup();
  18890. this.pdfThumbnailViewer?.cleanup();
  18891. this.pdfDocument.cleanup(AppOptions.get("fontExtraProperties"));
  18892. },
  18893. forceRendering() {
  18894. this.pdfRenderingQueue.printing = !!this.printService;
  18895. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === SidebarView.THUMBS;
  18896. this.pdfRenderingQueue.renderHighestPriority();
  18897. },
  18898. beforePrint() {
  18899. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => this.pdfDocument?.annotationStorage.print);
  18900. if (this.printService) {
  18901. return;
  18902. }
  18903. if (!this.supportsPrinting) {
  18904. this._otherError("pdfjs-printing-not-supported");
  18905. return;
  18906. }
  18907. if (!this.pdfViewer.pageViewsReady) {
  18908. this.l10n.get("pdfjs-printing-not-ready").then(msg => {
  18909. window.alert(msg);
  18910. });
  18911. return;
  18912. }
  18913. this.printService = PDFPrintServiceFactory.createPrintService({
  18914. pdfDocument: this.pdfDocument,
  18915. pagesOverview: this.pdfViewer.getPagesOverview(),
  18916. printContainer: this.appConfig.printContainer,
  18917. printResolution: AppOptions.get("printResolution"),
  18918. printAnnotationStoragePromise: this._printAnnotationStoragePromise
  18919. });
  18920. this.forceRendering();
  18921. this.setTitle();
  18922. this.printService.layout();
  18923. if (this._hasAnnotationEditors) {
  18924. this.externalServices.reportTelemetry({
  18925. type: "editing",
  18926. data: {
  18927. type: "print",
  18928. stats: this.pdfDocument?.annotationStorage.editorStats
  18929. }
  18930. });
  18931. }
  18932. },
  18933. afterPrint() {
  18934. if (this._printAnnotationStoragePromise) {
  18935. this._printAnnotationStoragePromise.then(() => {
  18936. this.pdfScriptingManager.dispatchDidPrint();
  18937. });
  18938. this._printAnnotationStoragePromise = null;
  18939. }
  18940. if (this.printService) {
  18941. this.printService.destroy();
  18942. this.printService = null;
  18943. this.pdfDocument?.annotationStorage.resetModified();
  18944. }
  18945. this.forceRendering();
  18946. this.setTitle();
  18947. },
  18948. rotatePages(delta) {
  18949. this.pdfViewer.pagesRotation += delta;
  18950. },
  18951. requestPresentationMode() {
  18952. this.pdfPresentationMode?.request();
  18953. },
  18954. triggerPrinting() {
  18955. if (this.supportsPrinting) {
  18956. window.print();
  18957. }
  18958. },
  18959. bindEvents() {
  18960. if (this._eventBusAbortController) {
  18961. return;
  18962. }
  18963. const ac = this._eventBusAbortController = new AbortController();
  18964. const opts = {
  18965. signal: ac.signal
  18966. };
  18967. const {
  18968. eventBus,
  18969. externalServices,
  18970. pdfDocumentProperties,
  18971. pdfViewer,
  18972. preferences
  18973. } = this;
  18974. eventBus._on("resize", onResize.bind(this), opts);
  18975. eventBus._on("hashchange", onHashchange.bind(this), opts);
  18976. eventBus._on("beforeprint", this.beforePrint.bind(this), opts);
  18977. eventBus._on("afterprint", this.afterPrint.bind(this), opts);
  18978. eventBus._on("pagerender", onPageRender.bind(this), opts);
  18979. eventBus._on("pagerendered", onPageRendered.bind(this), opts);
  18980. eventBus._on("updateviewarea", onUpdateViewarea.bind(this), opts);
  18981. eventBus._on("pagechanging", onPageChanging.bind(this), opts);
  18982. eventBus._on("scalechanging", onScaleChanging.bind(this), opts);
  18983. eventBus._on("rotationchanging", onRotationChanging.bind(this), opts);
  18984. eventBus._on("sidebarviewchanged", onSidebarViewChanged.bind(this), opts);
  18985. eventBus._on("pagemode", onPageMode.bind(this), opts);
  18986. eventBus._on("namedaction", onNamedAction.bind(this), opts);
  18987. eventBus._on("presentationmodechanged", evt => pdfViewer.presentationModeState = evt.state, opts);
  18988. eventBus._on("presentationmode", this.requestPresentationMode.bind(this), opts);
  18989. eventBus._on("switchannotationeditormode", evt => pdfViewer.annotationEditorMode = evt, opts);
  18990. eventBus._on("print", this.triggerPrinting.bind(this), opts);
  18991. eventBus._on("download", this.downloadOrSave.bind(this), opts);
  18992. eventBus._on("firstpage", () => this.page = 1, opts);
  18993. eventBus._on("lastpage", () => this.page = this.pagesCount, opts);
  18994. eventBus._on("nextpage", () => pdfViewer.nextPage(), opts);
  18995. eventBus._on("previouspage", () => pdfViewer.previousPage(), opts);
  18996. eventBus._on("zoomin", this.zoomIn.bind(this), opts);
  18997. eventBus._on("zoomout", this.zoomOut.bind(this), opts);
  18998. eventBus._on("zoomreset", this.zoomReset.bind(this), opts);
  18999. eventBus._on("pagenumberchanged", onPageNumberChanged.bind(this), opts);
  19000. eventBus._on("scalechanged", evt => pdfViewer.currentScaleValue = evt.value, opts);
  19001. eventBus._on("rotatecw", this.rotatePages.bind(this, 90), opts);
  19002. eventBus._on("rotateccw", this.rotatePages.bind(this, -90), opts);
  19003. eventBus._on("optionalcontentconfig", evt => pdfViewer.optionalContentConfigPromise = evt.promise, opts);
  19004. eventBus._on("switchscrollmode", evt => pdfViewer.scrollMode = evt.mode, opts);
  19005. eventBus._on("scrollmodechanged", onViewerModesChanged.bind(this, "scrollMode"), opts);
  19006. eventBus._on("switchspreadmode", evt => pdfViewer.spreadMode = evt.mode, opts);
  19007. eventBus._on("spreadmodechanged", onViewerModesChanged.bind(this, "spreadMode"), opts);
  19008. eventBus._on("imagealttextsettings", onImageAltTextSettings.bind(this), opts);
  19009. eventBus._on("documentproperties", () => pdfDocumentProperties?.open(), opts);
  19010. eventBus._on("findfromurlhash", onFindFromUrlHash.bind(this), opts);
  19011. eventBus._on("updatefindmatchescount", onUpdateFindMatchesCount.bind(this), opts);
  19012. eventBus._on("updatefindcontrolstate", onUpdateFindControlState.bind(this), opts);
  19013. eventBus._on("fileinputchange", onFileInputChange.bind(this), opts);
  19014. eventBus._on("openfile", onOpenFile.bind(this), opts);
  19015. },
  19016. bindWindowEvents() {
  19017. if (this._windowAbortController) {
  19018. return;
  19019. }
  19020. this._windowAbortController = new AbortController();
  19021. const {
  19022. eventBus,
  19023. appConfig: {
  19024. mainContainer
  19025. },
  19026. pdfViewer,
  19027. _windowAbortController: {
  19028. signal
  19029. }
  19030. } = this;
  19031. this._touchManager = new TouchManager({
  19032. container: window,
  19033. isPinchingDisabled: () => pdfViewer.isInPresentationMode,
  19034. isPinchingStopped: () => this.overlayManager?.active,
  19035. onPinching: this.touchPinchCallback.bind(this),
  19036. onPinchEnd: this.touchPinchEndCallback.bind(this),
  19037. signal
  19038. });
  19039. function addWindowResolutionChange(evt = null) {
  19040. if (evt) {
  19041. pdfViewer.refresh();
  19042. }
  19043. const mediaQueryList = window.matchMedia(`(resolution: ${OutputScale.pixelRatio}dppx)`);
  19044. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  19045. once: true,
  19046. signal
  19047. });
  19048. }
  19049. addWindowResolutionChange();
  19050. window.addEventListener("wheel", onWheel.bind(this), {
  19051. passive: false,
  19052. signal
  19053. });
  19054. window.addEventListener("click", onClick.bind(this), {
  19055. signal
  19056. });
  19057. window.addEventListener("keydown", onKeyDown.bind(this), {
  19058. signal
  19059. });
  19060. window.addEventListener("keyup", onKeyUp.bind(this), {
  19061. signal
  19062. });
  19063. window.addEventListener("resize", () => eventBus.dispatch("resize", {
  19064. source: window
  19065. }), {
  19066. signal
  19067. });
  19068. window.addEventListener("hashchange", () => {
  19069. eventBus.dispatch("hashchange", {
  19070. source: window,
  19071. hash: document.location.hash.substring(1)
  19072. });
  19073. }, {
  19074. signal
  19075. });
  19076. window.addEventListener("beforeprint", () => eventBus.dispatch("beforeprint", {
  19077. source: window
  19078. }), {
  19079. signal
  19080. });
  19081. window.addEventListener("afterprint", () => eventBus.dispatch("afterprint", {
  19082. source: window
  19083. }), {
  19084. signal
  19085. });
  19086. window.addEventListener("updatefromsandbox", evt => {
  19087. eventBus.dispatch("updatefromsandbox", {
  19088. source: window,
  19089. detail: evt.detail
  19090. });
  19091. }, {
  19092. signal
  19093. });
  19094. if (!("onscrollend" in document.documentElement)) {
  19095. return;
  19096. }
  19097. ({
  19098. scrollTop: this._lastScrollTop,
  19099. scrollLeft: this._lastScrollLeft
  19100. } = mainContainer);
  19101. const scrollend = () => {
  19102. ({
  19103. scrollTop: this._lastScrollTop,
  19104. scrollLeft: this._lastScrollLeft
  19105. } = mainContainer);
  19106. this._isScrolling = false;
  19107. mainContainer.addEventListener("scroll", scroll, {
  19108. passive: true,
  19109. signal
  19110. });
  19111. mainContainer.removeEventListener("scrollend", scrollend);
  19112. mainContainer.removeEventListener("blur", scrollend);
  19113. };
  19114. const scroll = () => {
  19115. if (this._isCtrlKeyDown) {
  19116. return;
  19117. }
  19118. if (this._lastScrollTop === mainContainer.scrollTop && this._lastScrollLeft === mainContainer.scrollLeft) {
  19119. return;
  19120. }
  19121. mainContainer.removeEventListener("scroll", scroll);
  19122. this._isScrolling = true;
  19123. mainContainer.addEventListener("scrollend", scrollend, {
  19124. signal
  19125. });
  19126. mainContainer.addEventListener("blur", scrollend, {
  19127. signal
  19128. });
  19129. };
  19130. mainContainer.addEventListener("scroll", scroll, {
  19131. passive: true,
  19132. signal
  19133. });
  19134. },
  19135. unbindEvents() {
  19136. this._eventBusAbortController?.abort();
  19137. this._eventBusAbortController = null;
  19138. },
  19139. unbindWindowEvents() {
  19140. this._windowAbortController?.abort();
  19141. this._windowAbortController = null;
  19142. this._touchManager = null;
  19143. },
  19144. async testingClose() {
  19145. this.unbindEvents();
  19146. this.unbindWindowEvents();
  19147. this._globalAbortController?.abort();
  19148. this._globalAbortController = null;
  19149. this.findBar?.close();
  19150. await Promise.all([this.l10n?.destroy(), this.close()]);
  19151. },
  19152. _accumulateTicks(ticks, prop) {
  19153. if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) {
  19154. this[prop] = 0;
  19155. }
  19156. this[prop] += ticks;
  19157. const wholeTicks = Math.trunc(this[prop]);
  19158. this[prop] -= wholeTicks;
  19159. return wholeTicks;
  19160. },
  19161. _accumulateFactor(previousScale, factor, prop) {
  19162. if (factor === 1) {
  19163. return 1;
  19164. }
  19165. if (this[prop] > 1 && factor < 1 || this[prop] < 1 && factor > 1) {
  19166. this[prop] = 1;
  19167. }
  19168. const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale);
  19169. this[prop] = factor / newFactor;
  19170. return newFactor;
  19171. },
  19172. _unblockDocumentLoadEvent() {
  19173. document.blockUnblockOnload?.(false);
  19174. this._unblockDocumentLoadEvent = () => {};
  19175. },
  19176. get scriptingReady() {
  19177. return this.pdfScriptingManager.ready;
  19178. }
  19179. };
  19180. initCom(PDFViewerApplication);
  19181. {
  19182. PDFPrintServiceFactory.initGlobals(PDFViewerApplication);
  19183. }
  19184. {
  19185. const HOSTED_VIEWER_ORIGINS = new Set(["null", "http://mozilla.github.io", "https://mozilla.github.io"]);
  19186. var validateFileURL = function (file) {
  19187. if (!file) {
  19188. return;
  19189. }
  19190. const viewerOrigin = URL.parse(window.location)?.origin || "null";
  19191. if (HOSTED_VIEWER_ORIGINS.has(viewerOrigin)) {
  19192. return;
  19193. }
  19194. const fileOrigin = URL.parse(file, window.location)?.origin;
  19195. if (fileOrigin === viewerOrigin) {
  19196. return;
  19197. }
  19198. const ex = new Error("file origin does not match viewer's");
  19199. PDFViewerApplication._documentError("pdfjs-loading-error", {
  19200. message: ex.message
  19201. });
  19202. throw ex;
  19203. };
  19204. var onFileInputChange = function (evt) {
  19205. if (this.pdfViewer?.isInPresentationMode) {
  19206. return;
  19207. }
  19208. const file = evt.fileInput.files[0];
  19209. this.open({
  19210. url: URL.createObjectURL(file),
  19211. originalUrl: file.name
  19212. });
  19213. };
  19214. var onOpenFile = function (evt) {
  19215. this._openFileInput?.click();
  19216. };
  19217. }
  19218. function onPageRender({
  19219. pageNumber
  19220. }) {
  19221. if (pageNumber === this.page) {
  19222. this.toolbar?.updateLoadingIndicatorState(true);
  19223. }
  19224. }
  19225. function onPageRendered({
  19226. pageNumber,
  19227. isDetailView,
  19228. error
  19229. }) {
  19230. if (pageNumber === this.page) {
  19231. this.toolbar?.updateLoadingIndicatorState(false);
  19232. }
  19233. if (!isDetailView && this.pdfSidebar?.visibleView === SidebarView.THUMBS) {
  19234. const pageView = this.pdfViewer.getPageView(pageNumber - 1);
  19235. const thumbnailView = this.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
  19236. if (pageView) {
  19237. thumbnailView?.setImage(pageView);
  19238. }
  19239. }
  19240. if (error) {
  19241. this._otherError("pdfjs-rendering-error", error);
  19242. }
  19243. }
  19244. function onPageMode({
  19245. mode
  19246. }) {
  19247. let view;
  19248. switch (mode) {
  19249. case "thumbs":
  19250. view = SidebarView.THUMBS;
  19251. break;
  19252. case "bookmarks":
  19253. case "outline":
  19254. view = SidebarView.OUTLINE;
  19255. break;
  19256. case "attachments":
  19257. view = SidebarView.ATTACHMENTS;
  19258. break;
  19259. case "layers":
  19260. view = SidebarView.LAYERS;
  19261. break;
  19262. case "none":
  19263. view = SidebarView.NONE;
  19264. break;
  19265. default:
  19266. console.error('Invalid "pagemode" hash parameter: ' + mode);
  19267. return;
  19268. }
  19269. this.pdfSidebar?.switchView(view, true);
  19270. }
  19271. function onNamedAction(evt) {
  19272. switch (evt.action) {
  19273. case "GoToPage":
  19274. this.appConfig.toolbar?.pageNumber.select();
  19275. break;
  19276. case "Find":
  19277. if (!this.supportsIntegratedFind) {
  19278. this.findBar?.toggle();
  19279. }
  19280. break;
  19281. case "Print":
  19282. this.triggerPrinting();
  19283. break;
  19284. case "SaveAs":
  19285. this.downloadOrSave();
  19286. break;
  19287. }
  19288. }
  19289. function onSidebarViewChanged({
  19290. view
  19291. }) {
  19292. this.pdfRenderingQueue.isThumbnailViewEnabled = view === SidebarView.THUMBS;
  19293. if (this.isInitialViewSet) {
  19294. this.store?.set("sidebarView", view).catch(() => {});
  19295. }
  19296. }
  19297. function onUpdateViewarea({
  19298. location
  19299. }) {
  19300. if (this.isInitialViewSet) {
  19301. this.store?.setMultiple({
  19302. page: location.pageNumber,
  19303. zoom: location.scale,
  19304. scrollLeft: location.left,
  19305. scrollTop: location.top,
  19306. rotation: location.rotation
  19307. }).catch(() => {});
  19308. }
  19309. if (this.appConfig.secondaryToolbar) {
  19310. this.appConfig.secondaryToolbar.viewBookmarkButton.href = this.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  19311. }
  19312. }
  19313. function onViewerModesChanged(name, evt) {
  19314. if (this.isInitialViewSet && !this.pdfViewer.isInPresentationMode) {
  19315. this.store?.set(name, evt.mode).catch(() => {});
  19316. }
  19317. }
  19318. function onResize() {
  19319. const {
  19320. pdfDocument,
  19321. pdfViewer,
  19322. pdfRenderingQueue
  19323. } = this;
  19324. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  19325. return;
  19326. }
  19327. if (!pdfDocument) {
  19328. return;
  19329. }
  19330. const currentScaleValue = pdfViewer.currentScaleValue;
  19331. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  19332. pdfViewer.currentScaleValue = currentScaleValue;
  19333. }
  19334. pdfViewer.update();
  19335. }
  19336. function onHashchange(evt) {
  19337. const hash = evt.hash;
  19338. if (!hash) {
  19339. return;
  19340. }
  19341. if (!this.isInitialViewSet) {
  19342. this.initialBookmark = hash;
  19343. } else if (!this.pdfHistory?.popStateInProgress) {
  19344. this.pdfLinkService.setHash(hash);
  19345. }
  19346. }
  19347. function onPageNumberChanged(evt) {
  19348. const {
  19349. pdfViewer
  19350. } = this;
  19351. if (evt.value !== "") {
  19352. this.pdfLinkService.goToPage(evt.value);
  19353. }
  19354. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  19355. this.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  19356. }
  19357. }
  19358. function onImageAltTextSettings() {
  19359. this.imageAltTextSettings?.open({
  19360. enableGuessAltText: AppOptions.get("enableGuessAltText"),
  19361. enableNewAltTextWhenAddingImage: AppOptions.get("enableNewAltTextWhenAddingImage")
  19362. });
  19363. }
  19364. function onFindFromUrlHash(evt) {
  19365. this.eventBus.dispatch("find", {
  19366. source: evt.source,
  19367. type: "",
  19368. query: evt.query,
  19369. caseSensitive: false,
  19370. entireWord: false,
  19371. highlightAll: true,
  19372. findPrevious: false,
  19373. matchDiacritics: true
  19374. });
  19375. }
  19376. function onUpdateFindMatchesCount({
  19377. matchesCount
  19378. }) {
  19379. if (this.supportsIntegratedFind) {
  19380. this.externalServices.updateFindMatchesCount(matchesCount);
  19381. } else {
  19382. this.findBar?.updateResultsCount(matchesCount);
  19383. }
  19384. }
  19385. function onUpdateFindControlState({
  19386. state,
  19387. previous,
  19388. entireWord,
  19389. matchesCount,
  19390. rawQuery
  19391. }) {
  19392. if (this.supportsIntegratedFind) {
  19393. this.externalServices.updateFindControlState({
  19394. result: state,
  19395. findPrevious: previous,
  19396. entireWord,
  19397. matchesCount,
  19398. rawQuery
  19399. });
  19400. } else {
  19401. this.findBar?.updateUIState(state, previous, matchesCount);
  19402. }
  19403. }
  19404. function onScaleChanging(evt) {
  19405. this.toolbar?.setPageScale(evt.presetValue, evt.scale);
  19406. this.pdfViewer.update();
  19407. }
  19408. function onRotationChanging(evt) {
  19409. if (this.pdfThumbnailViewer) {
  19410. this.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  19411. }
  19412. this.forceRendering();
  19413. this.pdfViewer.currentPageNumber = evt.pageNumber;
  19414. }
  19415. function onPageChanging({
  19416. pageNumber,
  19417. pageLabel
  19418. }) {
  19419. this.toolbar?.setPageNumber(pageNumber, pageLabel);
  19420. this.secondaryToolbar?.setPageNumber(pageNumber);
  19421. if (this.pdfSidebar?.visibleView === SidebarView.THUMBS) {
  19422. this.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
  19423. }
  19424. const currentPage = this.pdfViewer.getPageView(pageNumber - 1);
  19425. this.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === RenderingStates.RUNNING);
  19426. }
  19427. function onWheel(evt) {
  19428. const {
  19429. pdfViewer,
  19430. supportsMouseWheelZoomCtrlKey,
  19431. supportsMouseWheelZoomMetaKey,
  19432. supportsPinchToZoom
  19433. } = this;
  19434. if (pdfViewer.isInPresentationMode) {
  19435. return;
  19436. }
  19437. const deltaMode = evt.deltaMode;
  19438. let scaleFactor = Math.exp(-evt.deltaY / 100);
  19439. const isBuiltInMac = false;
  19440. const isPinchToZoom = evt.ctrlKey && !this._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && (Math.abs(scaleFactor - 1) < 0.05 || isBuiltInMac) && evt.deltaZ === 0;
  19441. const origin = [evt.clientX, evt.clientY];
  19442. if (isPinchToZoom || evt.ctrlKey && supportsMouseWheelZoomCtrlKey || evt.metaKey && supportsMouseWheelZoomMetaKey) {
  19443. evt.preventDefault();
  19444. if (this._isScrolling || document.visibilityState === "hidden" || this.overlayManager.active) {
  19445. return;
  19446. }
  19447. if (isPinchToZoom && supportsPinchToZoom) {
  19448. scaleFactor = this._accumulateFactor(pdfViewer.currentScale, scaleFactor, "_wheelUnusedFactor");
  19449. this.updateZoom(null, scaleFactor, origin);
  19450. } else {
  19451. const delta = normalizeWheelEventDirection(evt);
  19452. let ticks = 0;
  19453. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  19454. ticks = Math.abs(delta) >= 1 ? Math.sign(delta) : this._accumulateTicks(delta, "_wheelUnusedTicks");
  19455. } else {
  19456. const PIXELS_PER_LINE_SCALE = 30;
  19457. ticks = this._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks");
  19458. }
  19459. this.updateZoom(ticks, null, origin);
  19460. }
  19461. }
  19462. }
  19463. function closeSecondaryToolbar({
  19464. target
  19465. }) {
  19466. if (!this.secondaryToolbar?.isOpen) {
  19467. return;
  19468. }
  19469. const {
  19470. toolbar,
  19471. secondaryToolbar
  19472. } = this.appConfig;
  19473. if (this.pdfViewer.containsElement(target) || toolbar?.container.contains(target) && !secondaryToolbar?.toolbar.contains(target) && !secondaryToolbar?.toggleButton.contains(target)) {
  19474. this.secondaryToolbar.close();
  19475. }
  19476. }
  19477. function closeEditorUndoBar(evt) {
  19478. if (!this.editorUndoBar?.isOpen) {
  19479. return;
  19480. }
  19481. if (this.appConfig.secondaryToolbar?.toolbar.contains(evt.target)) {
  19482. this.editorUndoBar.hide();
  19483. }
  19484. }
  19485. function onClick(evt) {
  19486. closeSecondaryToolbar.call(this, evt);
  19487. closeEditorUndoBar.call(this, evt);
  19488. }
  19489. function onKeyUp(evt) {
  19490. if (evt.key === "Control") {
  19491. this._isCtrlKeyDown = false;
  19492. }
  19493. }
  19494. function onKeyDown(evt) {
  19495. this._isCtrlKeyDown = evt.key === "Control";
  19496. if (this.editorUndoBar?.isOpen && evt.keyCode !== 9 && evt.keyCode !== 16 && !((evt.keyCode === 13 || evt.keyCode === 32) && getActiveOrFocusedElement() === this.appConfig.editorUndoBar.undoButton)) {
  19497. this.editorUndoBar.hide();
  19498. }
  19499. if (this.overlayManager.active) {
  19500. return;
  19501. }
  19502. const {
  19503. eventBus,
  19504. pdfViewer
  19505. } = this;
  19506. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  19507. let handled = false,
  19508. ensureViewerFocused = false;
  19509. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  19510. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  19511. switch (evt.keyCode) {
  19512. case 70:
  19513. if (!this.supportsIntegratedFind && !evt.shiftKey) {
  19514. this.findBar?.open();
  19515. handled = true;
  19516. }
  19517. break;
  19518. case 71:
  19519. if (!this.supportsIntegratedFind) {
  19520. const {
  19521. state
  19522. } = this.findController;
  19523. if (state) {
  19524. const newState = {
  19525. source: window,
  19526. type: "again",
  19527. findPrevious: cmd === 5 || cmd === 12
  19528. };
  19529. eventBus.dispatch("find", {
  19530. ...state,
  19531. ...newState
  19532. });
  19533. }
  19534. handled = true;
  19535. }
  19536. break;
  19537. case 61:
  19538. case 107:
  19539. case 187:
  19540. case 171:
  19541. this.zoomIn();
  19542. handled = true;
  19543. break;
  19544. case 173:
  19545. case 109:
  19546. case 189:
  19547. this.zoomOut();
  19548. handled = true;
  19549. break;
  19550. case 48:
  19551. case 96:
  19552. if (!isViewerInPresentationMode) {
  19553. setTimeout(() => {
  19554. this.zoomReset();
  19555. });
  19556. handled = false;
  19557. }
  19558. break;
  19559. case 38:
  19560. if (isViewerInPresentationMode || this.page > 1) {
  19561. this.page = 1;
  19562. handled = true;
  19563. ensureViewerFocused = true;
  19564. }
  19565. break;
  19566. case 40:
  19567. if (isViewerInPresentationMode || this.page < this.pagesCount) {
  19568. this.page = this.pagesCount;
  19569. handled = true;
  19570. ensureViewerFocused = true;
  19571. }
  19572. break;
  19573. }
  19574. }
  19575. if (cmd === 1 || cmd === 8) {
  19576. switch (evt.keyCode) {
  19577. case 83:
  19578. eventBus.dispatch("download", {
  19579. source: window
  19580. });
  19581. handled = true;
  19582. break;
  19583. case 79:
  19584. {
  19585. eventBus.dispatch("openfile", {
  19586. source: window
  19587. });
  19588. handled = true;
  19589. }
  19590. break;
  19591. }
  19592. }
  19593. if (cmd === 3 || cmd === 10) {
  19594. switch (evt.keyCode) {
  19595. case 80:
  19596. this.requestPresentationMode();
  19597. handled = true;
  19598. this.externalServices.reportTelemetry({
  19599. type: "buttons",
  19600. data: {
  19601. id: "presentationModeKeyboard"
  19602. }
  19603. });
  19604. break;
  19605. case 71:
  19606. if (this.appConfig.toolbar) {
  19607. this.appConfig.toolbar.pageNumber.select();
  19608. handled = true;
  19609. }
  19610. break;
  19611. }
  19612. }
  19613. if (handled) {
  19614. if (ensureViewerFocused && !isViewerInPresentationMode) {
  19615. pdfViewer.focus();
  19616. }
  19617. evt.preventDefault();
  19618. return;
  19619. }
  19620. const curElement = getActiveOrFocusedElement();
  19621. const curElementTagName = curElement?.tagName.toUpperCase();
  19622. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElementTagName === "BUTTON" && (evt.keyCode === 13 || evt.keyCode === 32) || curElement?.isContentEditable) {
  19623. if (evt.keyCode !== 27) {
  19624. return;
  19625. }
  19626. }
  19627. if (cmd === 0) {
  19628. let turnPage = 0,
  19629. turnOnlyIfPageFit = false;
  19630. switch (evt.keyCode) {
  19631. case 38:
  19632. if (this.supportsCaretBrowsingMode) {
  19633. this.moveCaret(true, false);
  19634. handled = true;
  19635. break;
  19636. }
  19637. case 33:
  19638. if (pdfViewer.isVerticalScrollbarEnabled) {
  19639. turnOnlyIfPageFit = true;
  19640. }
  19641. turnPage = -1;
  19642. break;
  19643. case 8:
  19644. if (!isViewerInPresentationMode) {
  19645. turnOnlyIfPageFit = true;
  19646. }
  19647. turnPage = -1;
  19648. break;
  19649. case 37:
  19650. if (this.supportsCaretBrowsingMode) {
  19651. return;
  19652. }
  19653. if (pdfViewer.isHorizontalScrollbarEnabled) {
  19654. turnOnlyIfPageFit = true;
  19655. }
  19656. case 75:
  19657. case 80:
  19658. turnPage = -1;
  19659. break;
  19660. case 27:
  19661. if (this.secondaryToolbar?.isOpen) {
  19662. this.secondaryToolbar.close();
  19663. handled = true;
  19664. }
  19665. if (!this.supportsIntegratedFind && this.findBar?.opened) {
  19666. this.findBar.close();
  19667. handled = true;
  19668. }
  19669. break;
  19670. case 40:
  19671. if (this.supportsCaretBrowsingMode) {
  19672. this.moveCaret(false, false);
  19673. handled = true;
  19674. break;
  19675. }
  19676. case 34:
  19677. if (pdfViewer.isVerticalScrollbarEnabled) {
  19678. turnOnlyIfPageFit = true;
  19679. }
  19680. turnPage = 1;
  19681. break;
  19682. case 13:
  19683. case 32:
  19684. if (!isViewerInPresentationMode) {
  19685. turnOnlyIfPageFit = true;
  19686. }
  19687. turnPage = 1;
  19688. break;
  19689. case 39:
  19690. if (this.supportsCaretBrowsingMode) {
  19691. return;
  19692. }
  19693. if (pdfViewer.isHorizontalScrollbarEnabled) {
  19694. turnOnlyIfPageFit = true;
  19695. }
  19696. case 74:
  19697. case 78:
  19698. turnPage = 1;
  19699. break;
  19700. case 36:
  19701. if (isViewerInPresentationMode || this.page > 1) {
  19702. this.page = 1;
  19703. handled = true;
  19704. ensureViewerFocused = true;
  19705. }
  19706. break;
  19707. case 35:
  19708. if (isViewerInPresentationMode || this.page < this.pagesCount) {
  19709. this.page = this.pagesCount;
  19710. handled = true;
  19711. ensureViewerFocused = true;
  19712. }
  19713. break;
  19714. case 83:
  19715. this.pdfCursorTools?.switchTool(CursorTool.SELECT);
  19716. break;
  19717. case 72:
  19718. this.pdfCursorTools?.switchTool(CursorTool.HAND);
  19719. break;
  19720. case 82:
  19721. this.rotatePages(90);
  19722. break;
  19723. case 115:
  19724. this.pdfSidebar?.toggle();
  19725. break;
  19726. }
  19727. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  19728. if (turnPage > 0) {
  19729. pdfViewer.nextPage();
  19730. } else {
  19731. pdfViewer.previousPage();
  19732. }
  19733. handled = true;
  19734. }
  19735. }
  19736. if (cmd === 4) {
  19737. switch (evt.keyCode) {
  19738. case 13:
  19739. case 32:
  19740. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  19741. break;
  19742. }
  19743. pdfViewer.previousPage();
  19744. handled = true;
  19745. break;
  19746. case 38:
  19747. this.moveCaret(true, true);
  19748. handled = true;
  19749. break;
  19750. case 40:
  19751. this.moveCaret(false, true);
  19752. handled = true;
  19753. break;
  19754. case 82:
  19755. this.rotatePages(-90);
  19756. break;
  19757. }
  19758. }
  19759. if (!handled && !isViewerInPresentationMode) {
  19760. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  19761. ensureViewerFocused = true;
  19762. }
  19763. }
  19764. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  19765. pdfViewer.focus();
  19766. }
  19767. if (handled) {
  19768. evt.preventDefault();
  19769. }
  19770. }
  19771. function beforeUnload(evt) {
  19772. evt.preventDefault();
  19773. evt.returnValue = "";
  19774. return false;
  19775. }
  19776. ;// ./web/viewer.js
  19777. const AppConstants = {
  19778. LinkTarget: LinkTarget,
  19779. RenderingStates: RenderingStates,
  19780. ScrollMode: ScrollMode,
  19781. SpreadMode: SpreadMode
  19782. };
  19783. window.PDFViewerApplication = PDFViewerApplication;
  19784. window.PDFViewerApplicationConstants = AppConstants;
  19785. window.PDFViewerApplicationOptions = AppOptions;
  19786. function getViewerConfiguration() {
  19787. return {
  19788. appContainer: document.body,
  19789. principalContainer: document.getElementById("mainContainer"),
  19790. mainContainer: document.getElementById("viewerContainer"),
  19791. viewerContainer: document.getElementById("viewer"),
  19792. toolbar: {
  19793. container: document.getElementById("toolbarContainer"),
  19794. numPages: document.getElementById("numPages"),
  19795. pageNumber: document.getElementById("pageNumber"),
  19796. scaleSelect: document.getElementById("scaleSelect"),
  19797. customScaleOption: document.getElementById("customScaleOption"),
  19798. previous: document.getElementById("previous"),
  19799. next: document.getElementById("next"),
  19800. zoomIn: document.getElementById("zoomInButton"),
  19801. zoomOut: document.getElementById("zoomOutButton"),
  19802. print: document.getElementById("printButton"),
  19803. editorFreeTextButton: document.getElementById("editorFreeTextButton"),
  19804. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  19805. editorHighlightButton: document.getElementById("editorHighlightButton"),
  19806. editorHighlightParamsToolbar: document.getElementById("editorHighlightParamsToolbar"),
  19807. editorHighlightColorPicker: document.getElementById("editorHighlightColorPicker"),
  19808. editorInkButton: document.getElementById("editorInkButton"),
  19809. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  19810. editorStampButton: document.getElementById("editorStampButton"),
  19811. editorStampParamsToolbar: document.getElementById("editorStampParamsToolbar"),
  19812. editorSignatureButton: document.getElementById("editorSignatureButton"),
  19813. editorSignatureParamsToolbar: document.getElementById("editorSignatureParamsToolbar"),
  19814. download: document.getElementById("downloadButton")
  19815. },
  19816. secondaryToolbar: {
  19817. toolbar: document.getElementById("secondaryToolbar"),
  19818. toggleButton: document.getElementById("secondaryToolbarToggleButton"),
  19819. presentationModeButton: document.getElementById("presentationMode"),
  19820. openFileButton: document.getElementById("secondaryOpenFile"),
  19821. printButton: document.getElementById("secondaryPrint"),
  19822. downloadButton: document.getElementById("secondaryDownload"),
  19823. viewBookmarkButton: document.getElementById("viewBookmark"),
  19824. firstPageButton: document.getElementById("firstPage"),
  19825. lastPageButton: document.getElementById("lastPage"),
  19826. pageRotateCwButton: document.getElementById("pageRotateCw"),
  19827. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  19828. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  19829. cursorHandToolButton: document.getElementById("cursorHandTool"),
  19830. scrollPageButton: document.getElementById("scrollPage"),
  19831. scrollVerticalButton: document.getElementById("scrollVertical"),
  19832. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  19833. scrollWrappedButton: document.getElementById("scrollWrapped"),
  19834. spreadNoneButton: document.getElementById("spreadNone"),
  19835. spreadOddButton: document.getElementById("spreadOdd"),
  19836. spreadEvenButton: document.getElementById("spreadEven"),
  19837. imageAltTextSettingsButton: document.getElementById("imageAltTextSettings"),
  19838. imageAltTextSettingsSeparator: document.getElementById("imageAltTextSettingsSeparator"),
  19839. documentPropertiesButton: document.getElementById("documentProperties")
  19840. },
  19841. sidebar: {
  19842. outerContainer: document.getElementById("outerContainer"),
  19843. sidebarContainer: document.getElementById("sidebarContainer"),
  19844. toggleButton: document.getElementById("sidebarToggleButton"),
  19845. resizer: document.getElementById("sidebarResizer"),
  19846. thumbnailButton: document.getElementById("viewThumbnail"),
  19847. outlineButton: document.getElementById("viewOutline"),
  19848. attachmentsButton: document.getElementById("viewAttachments"),
  19849. layersButton: document.getElementById("viewLayers"),
  19850. thumbnailView: document.getElementById("thumbnailView"),
  19851. outlineView: document.getElementById("outlineView"),
  19852. attachmentsView: document.getElementById("attachmentsView"),
  19853. layersView: document.getElementById("layersView"),
  19854. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  19855. },
  19856. findBar: {
  19857. bar: document.getElementById("findbar"),
  19858. toggleButton: document.getElementById("viewFindButton"),
  19859. findField: document.getElementById("findInput"),
  19860. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  19861. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  19862. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  19863. entireWordCheckbox: document.getElementById("findEntireWord"),
  19864. findMsg: document.getElementById("findMsg"),
  19865. findResultsCount: document.getElementById("findResultsCount"),
  19866. findPreviousButton: document.getElementById("findPreviousButton"),
  19867. findNextButton: document.getElementById("findNextButton")
  19868. },
  19869. passwordOverlay: {
  19870. dialog: document.getElementById("passwordDialog"),
  19871. label: document.getElementById("passwordText"),
  19872. input: document.getElementById("password"),
  19873. submitButton: document.getElementById("passwordSubmit"),
  19874. cancelButton: document.getElementById("passwordCancel")
  19875. },
  19876. documentProperties: {
  19877. dialog: document.getElementById("documentPropertiesDialog"),
  19878. closeButton: document.getElementById("documentPropertiesClose"),
  19879. fields: {
  19880. fileName: document.getElementById("fileNameField"),
  19881. fileSize: document.getElementById("fileSizeField"),
  19882. title: document.getElementById("titleField"),
  19883. author: document.getElementById("authorField"),
  19884. subject: document.getElementById("subjectField"),
  19885. keywords: document.getElementById("keywordsField"),
  19886. creationDate: document.getElementById("creationDateField"),
  19887. modificationDate: document.getElementById("modificationDateField"),
  19888. creator: document.getElementById("creatorField"),
  19889. producer: document.getElementById("producerField"),
  19890. version: document.getElementById("versionField"),
  19891. pageCount: document.getElementById("pageCountField"),
  19892. pageSize: document.getElementById("pageSizeField"),
  19893. linearized: document.getElementById("linearizedField")
  19894. }
  19895. },
  19896. altTextDialog: {
  19897. dialog: document.getElementById("altTextDialog"),
  19898. optionDescription: document.getElementById("descriptionButton"),
  19899. optionDecorative: document.getElementById("decorativeButton"),
  19900. textarea: document.getElementById("descriptionTextarea"),
  19901. cancelButton: document.getElementById("altTextCancel"),
  19902. saveButton: document.getElementById("altTextSave")
  19903. },
  19904. newAltTextDialog: {
  19905. dialog: document.getElementById("newAltTextDialog"),
  19906. title: document.getElementById("newAltTextTitle"),
  19907. descriptionContainer: document.getElementById("newAltTextDescriptionContainer"),
  19908. textarea: document.getElementById("newAltTextDescriptionTextarea"),
  19909. disclaimer: document.getElementById("newAltTextDisclaimer"),
  19910. learnMore: document.getElementById("newAltTextLearnMore"),
  19911. imagePreview: document.getElementById("newAltTextImagePreview"),
  19912. createAutomatically: document.getElementById("newAltTextCreateAutomatically"),
  19913. createAutomaticallyButton: document.getElementById("newAltTextCreateAutomaticallyButton"),
  19914. downloadModel: document.getElementById("newAltTextDownloadModel"),
  19915. downloadModelDescription: document.getElementById("newAltTextDownloadModelDescription"),
  19916. error: document.getElementById("newAltTextError"),
  19917. errorCloseButton: document.getElementById("newAltTextCloseButton"),
  19918. cancelButton: document.getElementById("newAltTextCancel"),
  19919. notNowButton: document.getElementById("newAltTextNotNow"),
  19920. saveButton: document.getElementById("newAltTextSave")
  19921. },
  19922. altTextSettingsDialog: {
  19923. dialog: document.getElementById("altTextSettingsDialog"),
  19924. createModelButton: document.getElementById("createModelButton"),
  19925. aiModelSettings: document.getElementById("aiModelSettings"),
  19926. learnMore: document.getElementById("altTextSettingsLearnMore"),
  19927. deleteModelButton: document.getElementById("deleteModelButton"),
  19928. downloadModelButton: document.getElementById("downloadModelButton"),
  19929. showAltTextDialogButton: document.getElementById("showAltTextDialogButton"),
  19930. altTextSettingsCloseButton: document.getElementById("altTextSettingsCloseButton"),
  19931. closeButton: document.getElementById("altTextSettingsCloseButton")
  19932. },
  19933. addSignatureDialog: {
  19934. dialog: document.getElementById("addSignatureDialog"),
  19935. panels: document.getElementById("addSignatureActionContainer"),
  19936. typeButton: document.getElementById("addSignatureTypeButton"),
  19937. typeInput: document.getElementById("addSignatureTypeInput"),
  19938. drawButton: document.getElementById("addSignatureDrawButton"),
  19939. drawSVG: document.getElementById("addSignatureDraw"),
  19940. drawPlaceholder: document.getElementById("addSignatureDrawPlaceholder"),
  19941. drawThickness: document.getElementById("addSignatureDrawThickness"),
  19942. imageButton: document.getElementById("addSignatureImageButton"),
  19943. imageSVG: document.getElementById("addSignatureImage"),
  19944. imagePlaceholder: document.getElementById("addSignatureImagePlaceholder"),
  19945. imagePicker: document.getElementById("addSignatureFilePicker"),
  19946. imagePickerLink: document.getElementById("addSignatureImageBrowse"),
  19947. description: document.getElementById("addSignatureDescription"),
  19948. clearButton: document.getElementById("clearSignatureButton"),
  19949. saveContainer: document.getElementById("addSignatureSaveContainer"),
  19950. saveCheckbox: document.getElementById("addSignatureSaveCheckbox"),
  19951. errorBar: document.getElementById("addSignatureError"),
  19952. errorCloseButton: document.getElementById("addSignatureErrorCloseButton"),
  19953. cancelButton: document.getElementById("addSignatureCancelButton"),
  19954. addButton: document.getElementById("addSignatureAddButton")
  19955. },
  19956. editSignatureDialog: {
  19957. dialog: document.getElementById("editSignatureDescriptionDialog"),
  19958. description: document.getElementById("editSignatureDescription"),
  19959. editSignatureView: document.getElementById("editSignatureView"),
  19960. cancelButton: document.getElementById("editSignatureCancelButton"),
  19961. updateButton: document.getElementById("editSignatureUpdateButton")
  19962. },
  19963. annotationEditorParams: {
  19964. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  19965. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  19966. editorInkColor: document.getElementById("editorInkColor"),
  19967. editorInkThickness: document.getElementById("editorInkThickness"),
  19968. editorInkOpacity: document.getElementById("editorInkOpacity"),
  19969. editorStampAddImage: document.getElementById("editorStampAddImage"),
  19970. editorSignatureAddSignature: document.getElementById("editorSignatureAddSignature"),
  19971. editorFreeHighlightThickness: document.getElementById("editorFreeHighlightThickness"),
  19972. editorHighlightShowAll: document.getElementById("editorHighlightShowAll")
  19973. },
  19974. printContainer: document.getElementById("printContainer"),
  19975. editorUndoBar: {
  19976. container: document.getElementById("editorUndoBar"),
  19977. message: document.getElementById("editorUndoBarMessage"),
  19978. undoButton: document.getElementById("editorUndoBarUndoButton"),
  19979. closeButton: document.getElementById("editorUndoBarCloseButton")
  19980. }
  19981. };
  19982. }
  19983. function webViewerLoad() {
  19984. const config = getViewerConfiguration();
  19985. const event = new CustomEvent("webviewerloaded", {
  19986. bubbles: true,
  19987. cancelable: true,
  19988. detail: {
  19989. source: window
  19990. }
  19991. });
  19992. try {
  19993. parent.document.dispatchEvent(event);
  19994. } catch (ex) {
  19995. console.error("webviewerloaded:", ex);
  19996. document.dispatchEvent(event);
  19997. }
  19998. PDFViewerApplication.run(config);
  19999. }
  20000. document.blockUnblockOnload?.(true);
  20001. if (document.readyState === "interactive" || document.readyState === "complete") {
  20002. webViewerLoad();
  20003. } else {
  20004. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  20005. }
  20006. export { PDFViewerApplication, AppConstants as PDFViewerApplicationConstants, AppOptions as PDFViewerApplicationOptions };
  20007. //# sourceMappingURL=viewer.mjs.map