viewer.js 391 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  32. const compatibilityParams = Object.create(null);
  33. exports.compatibilityParams = compatibilityParams;
  34. {
  35. const userAgent = navigator.userAgent || "";
  36. const platform = navigator.platform || "";
  37. const maxTouchPoints = navigator.maxTouchPoints || 1;
  38. const isAndroid = /Android/.test(userAgent);
  39. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  40. (function checkCanvasSizeLimitation() {
  41. if (isIOS || isAndroid) {
  42. compatibilityParams.maxCanvasPixels = 5242880;
  43. }
  44. })();
  45. }
  46. const OptionKind = {
  47. VIEWER: 0x02,
  48. API: 0x04,
  49. WORKER: 0x08,
  50. PREFERENCE: 0x80
  51. };
  52. exports.OptionKind = OptionKind;
  53. const defaultOptions = {
  54. annotationMode: {
  55. value: 2,
  56. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  57. },
  58. cursorToolOnLoad: {
  59. value: 0,
  60. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  61. },
  62. defaultUrl: {
  63. value: "compressed.tracemonkey-pldi-09.pdf",
  64. kind: OptionKind.VIEWER
  65. },
  66. defaultZoomValue: {
  67. value: "",
  68. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  69. },
  70. disableHistory: {
  71. value: false,
  72. kind: OptionKind.VIEWER
  73. },
  74. disablePageLabels: {
  75. value: false,
  76. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  77. },
  78. enablePermissions: {
  79. value: false,
  80. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  81. },
  82. enablePrintAutoRotate: {
  83. value: true,
  84. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  85. },
  86. enableScripting: {
  87. value: true,
  88. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  89. },
  90. externalLinkRel: {
  91. value: "noopener noreferrer nofollow",
  92. kind: OptionKind.VIEWER
  93. },
  94. externalLinkTarget: {
  95. value: 0,
  96. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  97. },
  98. historyUpdateUrl: {
  99. value: false,
  100. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  101. },
  102. ignoreDestinationZoom: {
  103. value: false,
  104. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  105. },
  106. imageResourcesPath: {
  107. value: "./images/",
  108. kind: OptionKind.VIEWER
  109. },
  110. maxCanvasPixels: {
  111. value: 16777216,
  112. compatibility: compatibilityParams.maxCanvasPixels,
  113. kind: OptionKind.VIEWER
  114. },
  115. pageColorsBackground: {
  116. value: "Canvas",
  117. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  118. },
  119. pageColorsForeground: {
  120. value: "CanvasText",
  121. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  122. },
  123. pdfBugEnabled: {
  124. value: false,
  125. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  126. },
  127. printResolution: {
  128. value: 150,
  129. kind: OptionKind.VIEWER
  130. },
  131. renderer: {
  132. value: "canvas",
  133. kind: OptionKind.VIEWER
  134. },
  135. sidebarViewOnLoad: {
  136. value: -1,
  137. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  138. },
  139. scrollModeOnLoad: {
  140. value: -1,
  141. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  142. },
  143. spreadModeOnLoad: {
  144. value: -1,
  145. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  146. },
  147. textLayerMode: {
  148. value: 1,
  149. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  150. },
  151. useOnlyCssZoom: {
  152. value: false,
  153. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  154. },
  155. viewerCssTheme: {
  156. value: 0,
  157. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  158. },
  159. viewOnLoad: {
  160. value: 0,
  161. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  162. },
  163. cMapPacked: {
  164. value: true,
  165. kind: OptionKind.API
  166. },
  167. cMapUrl: {
  168. value: "../web/cmaps/",
  169. kind: OptionKind.API
  170. },
  171. disableAutoFetch: {
  172. value: false,
  173. kind: OptionKind.API + OptionKind.PREFERENCE
  174. },
  175. disableFontFace: {
  176. value: false,
  177. kind: OptionKind.API + OptionKind.PREFERENCE
  178. },
  179. disableRange: {
  180. value: false,
  181. kind: OptionKind.API + OptionKind.PREFERENCE
  182. },
  183. disableStream: {
  184. value: false,
  185. kind: OptionKind.API + OptionKind.PREFERENCE
  186. },
  187. docBaseUrl: {
  188. value: "",
  189. kind: OptionKind.API
  190. },
  191. enableXfa: {
  192. value: true,
  193. kind: OptionKind.API + OptionKind.PREFERENCE
  194. },
  195. fontExtraProperties: {
  196. value: false,
  197. kind: OptionKind.API
  198. },
  199. isEvalSupported: {
  200. value: true,
  201. kind: OptionKind.API
  202. },
  203. maxImageSize: {
  204. value: -1,
  205. kind: OptionKind.API
  206. },
  207. pdfBug: {
  208. value: false,
  209. kind: OptionKind.API
  210. },
  211. standardFontDataUrl: {
  212. value: "../web/standard_fonts/",
  213. kind: OptionKind.API
  214. },
  215. verbosity: {
  216. value: 1,
  217. kind: OptionKind.API
  218. },
  219. workerPort: {
  220. value: null,
  221. kind: OptionKind.WORKER
  222. },
  223. workerSrc: {
  224. value: "../build/pdf.worker.js",
  225. kind: OptionKind.WORKER
  226. }
  227. };
  228. {
  229. defaultOptions.disablePreferences = {
  230. value: false,
  231. kind: OptionKind.VIEWER
  232. };
  233. defaultOptions.locale = {
  234. value: navigator.language || "en-US",
  235. kind: OptionKind.VIEWER
  236. };
  237. defaultOptions.sandboxBundleSrc = {
  238. value: "../build/pdf.sandbox.js",
  239. kind: OptionKind.VIEWER
  240. };
  241. defaultOptions.renderer.kind += OptionKind.PREFERENCE;
  242. }
  243. const userOptions = Object.create(null);
  244. class AppOptions {
  245. constructor() {
  246. throw new Error("Cannot initialize AppOptions.");
  247. }
  248. static get(name) {
  249. const userOption = userOptions[name];
  250. if (userOption !== undefined) {
  251. return userOption;
  252. }
  253. const defaultOption = defaultOptions[name];
  254. if (defaultOption !== undefined) {
  255. return defaultOption.compatibility ?? defaultOption.value;
  256. }
  257. return undefined;
  258. }
  259. static getAll(kind = null) {
  260. const options = Object.create(null);
  261. for (const name in defaultOptions) {
  262. const defaultOption = defaultOptions[name];
  263. if (kind) {
  264. if ((kind & defaultOption.kind) === 0) {
  265. continue;
  266. }
  267. if (kind === OptionKind.PREFERENCE) {
  268. const value = defaultOption.value,
  269. valueType = typeof value;
  270. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  271. options[name] = value;
  272. continue;
  273. }
  274. throw new Error(`Invalid type for preference: ${name}`);
  275. }
  276. }
  277. const userOption = userOptions[name];
  278. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility ?? defaultOption.value;
  279. }
  280. return options;
  281. }
  282. static set(name, value) {
  283. userOptions[name] = value;
  284. }
  285. static setAll(options) {
  286. for (const name in options) {
  287. userOptions[name] = options[name];
  288. }
  289. }
  290. static remove(name) {
  291. delete userOptions[name];
  292. }
  293. static _hasUserOptions() {
  294. return Object.keys(userOptions).length > 0;
  295. }
  296. }
  297. exports.AppOptions = AppOptions;
  298. /***/ }),
  299. /* 2 */
  300. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  301. Object.defineProperty(exports, "__esModule", ({
  302. value: true
  303. }));
  304. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  305. var _ui_utils = __webpack_require__(3);
  306. var _app_options = __webpack_require__(1);
  307. var _event_utils = __webpack_require__(4);
  308. var _pdfjsLib = __webpack_require__(5);
  309. var _pdf_cursor_tools = __webpack_require__(6);
  310. var _pdf_link_service = __webpack_require__(8);
  311. var _overlay_manager = __webpack_require__(9);
  312. var _password_prompt = __webpack_require__(10);
  313. var _pdf_attachment_viewer = __webpack_require__(11);
  314. var _pdf_document_properties = __webpack_require__(13);
  315. var _pdf_find_bar = __webpack_require__(14);
  316. var _pdf_find_controller = __webpack_require__(15);
  317. var _pdf_history = __webpack_require__(17);
  318. var _pdf_layer_viewer = __webpack_require__(18);
  319. var _pdf_outline_viewer = __webpack_require__(19);
  320. var _pdf_presentation_mode = __webpack_require__(20);
  321. var _pdf_rendering_queue = __webpack_require__(21);
  322. var _pdf_scripting_manager = __webpack_require__(22);
  323. var _pdf_sidebar = __webpack_require__(23);
  324. var _pdf_sidebar_resizer = __webpack_require__(24);
  325. var _pdf_thumbnail_viewer = __webpack_require__(25);
  326. var _pdf_viewer = __webpack_require__(27);
  327. var _secondary_toolbar = __webpack_require__(36);
  328. var _toolbar = __webpack_require__(37);
  329. var _view_history = __webpack_require__(38);
  330. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  331. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  332. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  333. const ViewOnLoad = {
  334. UNKNOWN: -1,
  335. PREVIOUS: 0,
  336. INITIAL: 1
  337. };
  338. const ViewerCssTheme = {
  339. AUTOMATIC: 0,
  340. LIGHT: 1,
  341. DARK: 2
  342. };
  343. const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
  344. const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
  345. class DefaultExternalServices {
  346. constructor() {
  347. throw new Error("Cannot initialize DefaultExternalServices.");
  348. }
  349. static updateFindControlState(data) {}
  350. static updateFindMatchesCount(data) {}
  351. static initPassiveLoading(callbacks) {}
  352. static reportTelemetry(data) {}
  353. static createDownloadManager(options) {
  354. throw new Error("Not implemented: createDownloadManager");
  355. }
  356. static createPreferences() {
  357. throw new Error("Not implemented: createPreferences");
  358. }
  359. static createL10n(options) {
  360. throw new Error("Not implemented: createL10n");
  361. }
  362. static createScripting(options) {
  363. throw new Error("Not implemented: createScripting");
  364. }
  365. static get supportsIntegratedFind() {
  366. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  367. }
  368. static get supportsDocumentFonts() {
  369. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  370. }
  371. static get supportedMouseWheelZoomModifierKeys() {
  372. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  373. ctrlKey: true,
  374. metaKey: true
  375. });
  376. }
  377. static get isInAutomation() {
  378. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  379. }
  380. }
  381. exports.DefaultExternalServices = DefaultExternalServices;
  382. const PDFViewerApplication = {
  383. initialBookmark: document.location.hash.substring(1),
  384. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  385. appConfig: null,
  386. pdfDocument: null,
  387. pdfLoadingTask: null,
  388. printService: null,
  389. pdfViewer: null,
  390. pdfThumbnailViewer: null,
  391. pdfRenderingQueue: null,
  392. pdfPresentationMode: null,
  393. pdfDocumentProperties: null,
  394. pdfLinkService: null,
  395. pdfHistory: null,
  396. pdfSidebar: null,
  397. pdfSidebarResizer: null,
  398. pdfOutlineViewer: null,
  399. pdfAttachmentViewer: null,
  400. pdfLayerViewer: null,
  401. pdfCursorTools: null,
  402. pdfScriptingManager: null,
  403. store: null,
  404. downloadManager: null,
  405. overlayManager: null,
  406. preferences: null,
  407. toolbar: null,
  408. secondaryToolbar: null,
  409. eventBus: null,
  410. l10n: null,
  411. isInitialViewSet: false,
  412. downloadComplete: false,
  413. isViewerEmbedded: window.parent !== window,
  414. url: "",
  415. baseUrl: "",
  416. _downloadUrl: "",
  417. externalServices: DefaultExternalServices,
  418. _boundEvents: Object.create(null),
  419. documentInfo: null,
  420. metadata: null,
  421. _contentDispositionFilename: null,
  422. _contentLength: null,
  423. _saveInProgress: false,
  424. _docStats: null,
  425. _wheelUnusedTicks: 0,
  426. _idleCallbacks: new Set(),
  427. _PDFBug: null,
  428. async initialize(appConfig) {
  429. this.preferences = this.externalServices.createPreferences();
  430. this.appConfig = appConfig;
  431. await this._readPreferences();
  432. await this._parseHashParameters();
  433. this._forceCssTheme();
  434. await this._initializeL10n();
  435. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  436. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  437. }
  438. await this._initializeViewerComponents();
  439. this.bindEvents();
  440. this.bindWindowEvents();
  441. const appContainer = appConfig.appContainer || document.documentElement;
  442. this.l10n.translate(appContainer).then(() => {
  443. this.eventBus.dispatch("localized", {
  444. source: this
  445. });
  446. });
  447. this._initializedCapability.resolve();
  448. },
  449. async _readPreferences() {
  450. if (_app_options.AppOptions.get("disablePreferences")) {
  451. return;
  452. }
  453. if (_app_options.AppOptions._hasUserOptions()) {
  454. console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  455. }
  456. try {
  457. _app_options.AppOptions.setAll(await this.preferences.getAll());
  458. } catch (reason) {
  459. console.error(`_readPreferences: "${reason?.message}".`);
  460. }
  461. },
  462. async _parseHashParameters() {
  463. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  464. return;
  465. }
  466. const hash = document.location.hash.substring(1);
  467. if (!hash) {
  468. return;
  469. }
  470. const {
  471. mainContainer,
  472. viewerContainer
  473. } = this.appConfig,
  474. params = (0, _ui_utils.parseQueryString)(hash);
  475. if (params.get("disableworker") === "true") {
  476. try {
  477. await loadFakeWorker();
  478. } catch (ex) {
  479. console.error(`_parseHashParameters: "${ex.message}".`);
  480. }
  481. }
  482. if (params.has("disablerange")) {
  483. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  484. }
  485. if (params.has("disablestream")) {
  486. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  487. }
  488. if (params.has("disableautofetch")) {
  489. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  490. }
  491. if (params.has("disablefontface")) {
  492. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  493. }
  494. if (params.has("disablehistory")) {
  495. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  496. }
  497. if (params.has("verbosity")) {
  498. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  499. }
  500. if (params.has("textlayer")) {
  501. switch (params.get("textlayer")) {
  502. case "off":
  503. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  504. break;
  505. case "visible":
  506. case "shadow":
  507. case "hover":
  508. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  509. try {
  510. await loadPDFBug(this);
  511. this._PDFBug.loadCSS();
  512. } catch (ex) {
  513. console.error(`_parseHashParameters: "${ex.message}".`);
  514. }
  515. break;
  516. }
  517. }
  518. if (params.has("pdfbug")) {
  519. _app_options.AppOptions.set("pdfBug", true);
  520. _app_options.AppOptions.set("fontExtraProperties", true);
  521. const enabled = params.get("pdfbug").split(",");
  522. try {
  523. await loadPDFBug(this);
  524. this._PDFBug.init({
  525. OPS: _pdfjsLib.OPS
  526. }, mainContainer, enabled);
  527. } catch (ex) {
  528. console.error(`_parseHashParameters: "${ex.message}".`);
  529. }
  530. }
  531. if (params.has("locale")) {
  532. _app_options.AppOptions.set("locale", params.get("locale"));
  533. }
  534. },
  535. async _initializeL10n() {
  536. this.l10n = this.externalServices.createL10n({
  537. locale: _app_options.AppOptions.get("locale")
  538. });
  539. const dir = await this.l10n.getDirection();
  540. document.getElementsByTagName("html")[0].dir = dir;
  541. },
  542. _forceCssTheme() {
  543. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  544. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  545. return;
  546. }
  547. try {
  548. const styleSheet = document.styleSheets[0];
  549. const cssRules = styleSheet?.cssRules || [];
  550. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  551. const rule = cssRules[i];
  552. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  553. if (cssTheme === ViewerCssTheme.LIGHT) {
  554. styleSheet.deleteRule(i);
  555. return;
  556. }
  557. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  558. if (darkRules?.[1]) {
  559. styleSheet.deleteRule(i);
  560. styleSheet.insertRule(darkRules[1], i);
  561. }
  562. return;
  563. }
  564. }
  565. } catch (reason) {
  566. console.error(`_forceCssTheme: "${reason?.message}".`);
  567. }
  568. },
  569. async _initializeViewerComponents() {
  570. const {
  571. appConfig,
  572. externalServices
  573. } = this;
  574. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  575. this.eventBus = eventBus;
  576. this.overlayManager = new _overlay_manager.OverlayManager();
  577. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  578. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  579. this.pdfRenderingQueue = pdfRenderingQueue;
  580. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  581. eventBus,
  582. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  583. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  584. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  585. });
  586. this.pdfLinkService = pdfLinkService;
  587. const downloadManager = externalServices.createDownloadManager();
  588. this.downloadManager = downloadManager;
  589. const findController = new _pdf_find_controller.PDFFindController({
  590. linkService: pdfLinkService,
  591. eventBus
  592. });
  593. this.findController = findController;
  594. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  595. eventBus,
  596. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  597. scriptingFactory: externalServices,
  598. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  599. });
  600. this.pdfScriptingManager = pdfScriptingManager;
  601. const container = appConfig.mainContainer;
  602. const viewer = appConfig.viewerContainer;
  603. this.pdfViewer = new _pdf_viewer.PDFViewer({
  604. container,
  605. viewer,
  606. eventBus,
  607. renderingQueue: pdfRenderingQueue,
  608. linkService: pdfLinkService,
  609. downloadManager,
  610. findController,
  611. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  612. renderer: _app_options.AppOptions.get("renderer"),
  613. l10n: this.l10n,
  614. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  615. annotationMode: _app_options.AppOptions.get("annotationMode"),
  616. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  617. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  618. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  619. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  620. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  621. pageColors: {
  622. background: _app_options.AppOptions.get("pageColorsBackground"),
  623. foreground: _app_options.AppOptions.get("pageColorsForeground")
  624. }
  625. });
  626. pdfRenderingQueue.setViewer(this.pdfViewer);
  627. pdfLinkService.setViewer(this.pdfViewer);
  628. pdfScriptingManager.setViewer(this.pdfViewer);
  629. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  630. container: appConfig.sidebar.thumbnailView,
  631. eventBus,
  632. renderingQueue: pdfRenderingQueue,
  633. linkService: pdfLinkService,
  634. l10n: this.l10n
  635. });
  636. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  637. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  638. this.pdfHistory = new _pdf_history.PDFHistory({
  639. linkService: pdfLinkService,
  640. eventBus
  641. });
  642. pdfLinkService.setHistory(this.pdfHistory);
  643. }
  644. if (!this.supportsIntegratedFind) {
  645. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  646. }
  647. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  648. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  649. container,
  650. eventBus,
  651. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  652. });
  653. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  654. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus);
  655. if (this.supportsFullscreen) {
  656. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  657. container,
  658. pdfViewer: this.pdfViewer,
  659. eventBus
  660. });
  661. }
  662. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  663. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  664. container: appConfig.sidebar.outlineView,
  665. eventBus,
  666. linkService: pdfLinkService
  667. });
  668. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  669. container: appConfig.sidebar.attachmentsView,
  670. eventBus,
  671. downloadManager
  672. });
  673. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  674. container: appConfig.sidebar.layersView,
  675. eventBus,
  676. l10n: this.l10n
  677. });
  678. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  679. elements: appConfig.sidebar,
  680. pdfViewer: this.pdfViewer,
  681. pdfThumbnailViewer: this.pdfThumbnailViewer,
  682. eventBus,
  683. l10n: this.l10n
  684. });
  685. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  686. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  687. },
  688. run(config) {
  689. this.initialize(config).then(webViewerInitialized);
  690. },
  691. get initialized() {
  692. return this._initializedCapability.settled;
  693. },
  694. get initializedPromise() {
  695. return this._initializedCapability.promise;
  696. },
  697. zoomIn(steps) {
  698. if (this.pdfViewer.isInPresentationMode) {
  699. return;
  700. }
  701. this.pdfViewer.increaseScale(steps);
  702. },
  703. zoomOut(steps) {
  704. if (this.pdfViewer.isInPresentationMode) {
  705. return;
  706. }
  707. this.pdfViewer.decreaseScale(steps);
  708. },
  709. zoomReset() {
  710. if (this.pdfViewer.isInPresentationMode) {
  711. return;
  712. }
  713. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  714. },
  715. get pagesCount() {
  716. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  717. },
  718. get page() {
  719. return this.pdfViewer.currentPageNumber;
  720. },
  721. set page(val) {
  722. this.pdfViewer.currentPageNumber = val;
  723. },
  724. get supportsPrinting() {
  725. return PDFPrintServiceFactory.instance.supportsPrinting;
  726. },
  727. get supportsFullscreen() {
  728. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  729. },
  730. get supportsIntegratedFind() {
  731. return this.externalServices.supportsIntegratedFind;
  732. },
  733. get supportsDocumentFonts() {
  734. return this.externalServices.supportsDocumentFonts;
  735. },
  736. get loadingBar() {
  737. const bar = new _ui_utils.ProgressBar("#loadingBar");
  738. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  739. },
  740. get supportedMouseWheelZoomModifierKeys() {
  741. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  742. },
  743. initPassiveLoading() {
  744. throw new Error("Not implemented: initPassiveLoading");
  745. },
  746. setTitleUsingUrl(url = "", downloadUrl = null) {
  747. this.url = url;
  748. this.baseUrl = url.split("#")[0];
  749. if (downloadUrl) {
  750. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  751. }
  752. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  753. if (!title) {
  754. try {
  755. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  756. } catch (ex) {
  757. title = url;
  758. }
  759. }
  760. this.setTitle(title);
  761. },
  762. setTitle(title) {
  763. if (this.isViewerEmbedded) {
  764. return;
  765. }
  766. document.title = title;
  767. },
  768. get _docFilename() {
  769. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  770. },
  771. _hideViewBookmark() {
  772. const {
  773. toolbar,
  774. secondaryToolbar
  775. } = this.appConfig;
  776. toolbar.viewBookmark.hidden = true;
  777. secondaryToolbar.viewBookmarkButton.hidden = true;
  778. },
  779. _cancelIdleCallbacks() {
  780. if (!this._idleCallbacks.size) {
  781. return;
  782. }
  783. for (const callback of this._idleCallbacks) {
  784. window.cancelIdleCallback(callback);
  785. }
  786. this._idleCallbacks.clear();
  787. },
  788. async close() {
  789. this._unblockDocumentLoadEvent();
  790. this._hideViewBookmark();
  791. const {
  792. container
  793. } = this.appConfig.errorWrapper;
  794. container.hidden = true;
  795. if (!this.pdfLoadingTask) {
  796. return;
  797. }
  798. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  799. try {
  800. await this.save({
  801. sourceEventType: "save"
  802. });
  803. } catch (reason) {}
  804. }
  805. const promises = [];
  806. promises.push(this.pdfLoadingTask.destroy());
  807. this.pdfLoadingTask = null;
  808. if (this.pdfDocument) {
  809. this.pdfDocument = null;
  810. this.pdfThumbnailViewer.setDocument(null);
  811. this.pdfViewer.setDocument(null);
  812. this.pdfLinkService.setDocument(null);
  813. this.pdfDocumentProperties.setDocument(null);
  814. }
  815. this.pdfLinkService.externalLinkEnabled = true;
  816. this.store = null;
  817. this.isInitialViewSet = false;
  818. this.downloadComplete = false;
  819. this.url = "";
  820. this.baseUrl = "";
  821. this._downloadUrl = "";
  822. this.documentInfo = null;
  823. this.metadata = null;
  824. this._contentDispositionFilename = null;
  825. this._contentLength = null;
  826. this._saveInProgress = false;
  827. this._docStats = null;
  828. this._cancelIdleCallbacks();
  829. promises.push(this.pdfScriptingManager.destroyPromise);
  830. this.pdfSidebar.reset();
  831. this.pdfOutlineViewer.reset();
  832. this.pdfAttachmentViewer.reset();
  833. this.pdfLayerViewer.reset();
  834. this.pdfHistory?.reset();
  835. this.findBar?.reset();
  836. this.toolbar.reset();
  837. this.secondaryToolbar.reset();
  838. this._PDFBug?.cleanup();
  839. await Promise.all(promises);
  840. },
  841. async open(file, args) {
  842. if (this.pdfLoadingTask) {
  843. await this.close();
  844. }
  845. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  846. for (const key in workerParameters) {
  847. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  848. }
  849. const parameters = Object.create(null);
  850. if (typeof file === "string") {
  851. this.setTitleUsingUrl(file, file);
  852. parameters.url = file;
  853. } else if (file && "byteLength" in file) {
  854. parameters.data = file;
  855. } else if (file.url && file.originalUrl) {
  856. this.setTitleUsingUrl(file.originalUrl, file.url);
  857. parameters.url = file.url;
  858. }
  859. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  860. for (const key in apiParameters) {
  861. let value = apiParameters[key];
  862. if (key === "docBaseUrl" && !value) {}
  863. parameters[key] = value;
  864. }
  865. if (args) {
  866. for (const key in args) {
  867. parameters[key] = args[key];
  868. }
  869. }
  870. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  871. this.pdfLoadingTask = loadingTask;
  872. loadingTask.onPassword = (updateCallback, reason) => {
  873. this.pdfLinkService.externalLinkEnabled = false;
  874. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  875. this.passwordPrompt.open();
  876. };
  877. loadingTask.onProgress = ({
  878. loaded,
  879. total
  880. }) => {
  881. this.progress(loaded / total);
  882. };
  883. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  884. return loadingTask.promise.then(pdfDocument => {
  885. this.load(pdfDocument);
  886. }, reason => {
  887. if (loadingTask !== this.pdfLoadingTask) {
  888. return undefined;
  889. }
  890. let key = "loading_error";
  891. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  892. key = "invalid_file_error";
  893. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  894. key = "missing_file_error";
  895. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  896. key = "unexpected_response_error";
  897. }
  898. return this.l10n.get(key).then(msg => {
  899. this._documentError(msg, {
  900. message: reason?.message
  901. });
  902. throw reason;
  903. });
  904. });
  905. },
  906. _ensureDownloadComplete() {
  907. if (this.pdfDocument && this.downloadComplete) {
  908. return;
  909. }
  910. throw new Error("PDF document not downloaded.");
  911. },
  912. async download({
  913. sourceEventType = "download"
  914. } = {}) {
  915. const url = this._downloadUrl,
  916. filename = this._docFilename;
  917. try {
  918. this._ensureDownloadComplete();
  919. const data = await this.pdfDocument.getData();
  920. const blob = new Blob([data], {
  921. type: "application/pdf"
  922. });
  923. await this.downloadManager.download(blob, url, filename, sourceEventType);
  924. } catch (reason) {
  925. await this.downloadManager.downloadUrl(url, filename);
  926. }
  927. },
  928. async save({
  929. sourceEventType = "download"
  930. } = {}) {
  931. if (this._saveInProgress) {
  932. return;
  933. }
  934. this._saveInProgress = true;
  935. await this.pdfScriptingManager.dispatchWillSave();
  936. const url = this._downloadUrl,
  937. filename = this._docFilename;
  938. try {
  939. this._ensureDownloadComplete();
  940. const data = await this.pdfDocument.saveDocument();
  941. const blob = new Blob([data], {
  942. type: "application/pdf"
  943. });
  944. await this.downloadManager.download(blob, url, filename, sourceEventType);
  945. } catch (reason) {
  946. console.error(`Error when saving the document: ${reason.message}`);
  947. await this.download({
  948. sourceEventType
  949. });
  950. } finally {
  951. await this.pdfScriptingManager.dispatchDidSave();
  952. this._saveInProgress = false;
  953. }
  954. },
  955. downloadOrSave(options) {
  956. if (this.pdfDocument?.annotationStorage.size > 0) {
  957. this.save(options);
  958. } else {
  959. this.download(options);
  960. }
  961. },
  962. fallback(featureId) {
  963. this.externalServices.reportTelemetry({
  964. type: "unsupportedFeature",
  965. featureId
  966. });
  967. },
  968. _documentError(message, moreInfo = null) {
  969. this._unblockDocumentLoadEvent();
  970. this._otherError(message, moreInfo);
  971. this.eventBus.dispatch("documenterror", {
  972. source: this,
  973. message,
  974. reason: moreInfo?.message ?? null
  975. });
  976. },
  977. _otherError(message, moreInfo = null) {
  978. const moreInfoText = [this.l10n.get("error_version_info", {
  979. version: _pdfjsLib.version || "?",
  980. build: _pdfjsLib.build || "?"
  981. })];
  982. if (moreInfo) {
  983. moreInfoText.push(this.l10n.get("error_message", {
  984. message: moreInfo.message
  985. }));
  986. if (moreInfo.stack) {
  987. moreInfoText.push(this.l10n.get("error_stack", {
  988. stack: moreInfo.stack
  989. }));
  990. } else {
  991. if (moreInfo.filename) {
  992. moreInfoText.push(this.l10n.get("error_file", {
  993. file: moreInfo.filename
  994. }));
  995. }
  996. if (moreInfo.lineNumber) {
  997. moreInfoText.push(this.l10n.get("error_line", {
  998. line: moreInfo.lineNumber
  999. }));
  1000. }
  1001. }
  1002. }
  1003. const errorWrapperConfig = this.appConfig.errorWrapper;
  1004. const errorWrapper = errorWrapperConfig.container;
  1005. errorWrapper.hidden = false;
  1006. const errorMessage = errorWrapperConfig.errorMessage;
  1007. errorMessage.textContent = message;
  1008. const closeButton = errorWrapperConfig.closeButton;
  1009. closeButton.onclick = function () {
  1010. errorWrapper.hidden = true;
  1011. };
  1012. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1013. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1014. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1015. moreInfoButton.onclick = function () {
  1016. errorMoreInfo.hidden = false;
  1017. moreInfoButton.hidden = true;
  1018. lessInfoButton.hidden = false;
  1019. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1020. };
  1021. lessInfoButton.onclick = function () {
  1022. errorMoreInfo.hidden = true;
  1023. moreInfoButton.hidden = false;
  1024. lessInfoButton.hidden = true;
  1025. };
  1026. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1027. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1028. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1029. moreInfoButton.hidden = false;
  1030. lessInfoButton.hidden = true;
  1031. Promise.all(moreInfoText).then(parts => {
  1032. errorMoreInfo.value = parts.join("\n");
  1033. });
  1034. },
  1035. progress(level) {
  1036. if (this.downloadComplete) {
  1037. return;
  1038. }
  1039. const percent = Math.round(level * 100);
  1040. if (percent > this.loadingBar.percent || isNaN(percent)) {
  1041. this.loadingBar.percent = percent;
  1042. const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
  1043. if (disableAutoFetch && percent) {
  1044. if (this.disableAutoFetchLoadingBarTimeout) {
  1045. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1046. this.disableAutoFetchLoadingBarTimeout = null;
  1047. }
  1048. this.loadingBar.show();
  1049. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  1050. this.loadingBar.hide();
  1051. this.disableAutoFetchLoadingBarTimeout = null;
  1052. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1053. }
  1054. }
  1055. },
  1056. load(pdfDocument) {
  1057. this.pdfDocument = pdfDocument;
  1058. pdfDocument.getDownloadInfo().then(({
  1059. length
  1060. }) => {
  1061. this._contentLength = length;
  1062. this.downloadComplete = true;
  1063. this.loadingBar.hide();
  1064. firstPagePromise.then(() => {
  1065. this.eventBus.dispatch("documentloaded", {
  1066. source: this
  1067. });
  1068. });
  1069. });
  1070. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  1071. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1072. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  1073. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1074. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1075. let baseDocumentUrl;
  1076. baseDocumentUrl = null;
  1077. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1078. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1079. const pdfViewer = this.pdfViewer;
  1080. pdfViewer.setDocument(pdfDocument);
  1081. const {
  1082. firstPagePromise,
  1083. onePageRendered,
  1084. pagesPromise
  1085. } = pdfViewer;
  1086. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  1087. pdfThumbnailViewer.setDocument(pdfDocument);
  1088. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  1089. page: null,
  1090. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1091. scrollLeft: "0",
  1092. scrollTop: "0",
  1093. rotation: null,
  1094. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  1095. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1096. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  1097. }).catch(() => {
  1098. return Object.create(null);
  1099. });
  1100. firstPagePromise.then(pdfPage => {
  1101. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  1102. this._initializeAnnotationStorageCallbacks(pdfDocument);
  1103. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  1104. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  1105. this._initializePdfHistory({
  1106. fingerprint: pdfDocument.fingerprints[0],
  1107. viewOnLoad,
  1108. initialDest: openAction?.dest
  1109. });
  1110. const initialBookmark = this.initialBookmark;
  1111. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  1112. let hash = zoom ? `zoom=${zoom}` : null;
  1113. let rotation = null;
  1114. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  1115. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  1116. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  1117. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1118. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  1119. rotation = parseInt(stored.rotation, 10);
  1120. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1121. sidebarView = stored.sidebarView | 0;
  1122. }
  1123. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1124. scrollMode = stored.scrollMode | 0;
  1125. }
  1126. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1127. spreadMode = stored.spreadMode | 0;
  1128. }
  1129. }
  1130. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1131. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  1132. }
  1133. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1134. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  1135. spreadMode = modes.spreadMode;
  1136. }
  1137. this.setInitialView(hash, {
  1138. rotation,
  1139. sidebarView,
  1140. scrollMode,
  1141. spreadMode
  1142. });
  1143. this.eventBus.dispatch("documentinit", {
  1144. source: this
  1145. });
  1146. if (!this.isViewerEmbedded) {
  1147. pdfViewer.focus();
  1148. }
  1149. await Promise.race([pagesPromise, new Promise(resolve => {
  1150. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1151. })]);
  1152. if (!initialBookmark && !hash) {
  1153. return;
  1154. }
  1155. if (pdfViewer.hasEqualPageSizes) {
  1156. return;
  1157. }
  1158. this.initialBookmark = initialBookmark;
  1159. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1160. this.setInitialView(hash);
  1161. }).catch(() => {
  1162. this.setInitialView();
  1163. }).then(function () {
  1164. pdfViewer.update();
  1165. });
  1166. });
  1167. pagesPromise.then(() => {
  1168. this._unblockDocumentLoadEvent();
  1169. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1170. }, reason => {
  1171. this.l10n.get("loading_error").then(msg => {
  1172. this._documentError(msg, {
  1173. message: reason?.message
  1174. });
  1175. });
  1176. });
  1177. onePageRendered.then(data => {
  1178. this.externalServices.reportTelemetry({
  1179. type: "pageInfo",
  1180. timestamp: data.timestamp
  1181. });
  1182. pdfDocument.getOutline().then(outline => {
  1183. if (pdfDocument !== this.pdfDocument) {
  1184. return;
  1185. }
  1186. this.pdfOutlineViewer.render({
  1187. outline,
  1188. pdfDocument
  1189. });
  1190. });
  1191. pdfDocument.getAttachments().then(attachments => {
  1192. if (pdfDocument !== this.pdfDocument) {
  1193. return;
  1194. }
  1195. this.pdfAttachmentViewer.render({
  1196. attachments
  1197. });
  1198. });
  1199. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1200. if (pdfDocument !== this.pdfDocument) {
  1201. return;
  1202. }
  1203. this.pdfLayerViewer.render({
  1204. optionalContentConfig,
  1205. pdfDocument
  1206. });
  1207. });
  1208. if ("requestIdleCallback" in window) {
  1209. const callback = window.requestIdleCallback(() => {
  1210. this._collectTelemetry(pdfDocument);
  1211. this._idleCallbacks.delete(callback);
  1212. }, {
  1213. timeout: 1000
  1214. });
  1215. this._idleCallbacks.add(callback);
  1216. }
  1217. });
  1218. this._initializePageLabels(pdfDocument);
  1219. this._initializeMetadata(pdfDocument);
  1220. },
  1221. async _scriptingDocProperties(pdfDocument) {
  1222. if (!this.documentInfo) {
  1223. await new Promise(resolve => {
  1224. this.eventBus._on("metadataloaded", resolve, {
  1225. once: true
  1226. });
  1227. });
  1228. if (pdfDocument !== this.pdfDocument) {
  1229. return null;
  1230. }
  1231. }
  1232. if (!this._contentLength) {
  1233. await new Promise(resolve => {
  1234. this.eventBus._on("documentloaded", resolve, {
  1235. once: true
  1236. });
  1237. });
  1238. if (pdfDocument !== this.pdfDocument) {
  1239. return null;
  1240. }
  1241. }
  1242. return { ...this.documentInfo,
  1243. baseURL: this.baseUrl,
  1244. filesize: this._contentLength,
  1245. filename: this._docFilename,
  1246. metadata: this.metadata?.getRaw(),
  1247. authors: this.metadata?.get("dc:creator"),
  1248. numPages: this.pagesCount,
  1249. URL: this.url
  1250. };
  1251. },
  1252. async _collectTelemetry(pdfDocument) {
  1253. const markInfo = await this.pdfDocument.getMarkInfo();
  1254. if (pdfDocument !== this.pdfDocument) {
  1255. return;
  1256. }
  1257. const tagged = markInfo?.Marked || false;
  1258. this.externalServices.reportTelemetry({
  1259. type: "tagged",
  1260. tagged
  1261. });
  1262. },
  1263. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1264. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  1265. if (pdfDocument !== this.pdfDocument) {
  1266. return;
  1267. }
  1268. let triggerAutoPrint = false;
  1269. if (openAction?.action === "Print") {
  1270. triggerAutoPrint = true;
  1271. }
  1272. if (javaScript) {
  1273. javaScript.some(js => {
  1274. if (!js) {
  1275. return false;
  1276. }
  1277. console.warn("Warning: JavaScript support is not enabled");
  1278. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1279. return true;
  1280. });
  1281. if (!triggerAutoPrint) {
  1282. for (const js of javaScript) {
  1283. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1284. triggerAutoPrint = true;
  1285. break;
  1286. }
  1287. }
  1288. }
  1289. }
  1290. if (triggerAutoPrint) {
  1291. this.triggerPrinting();
  1292. }
  1293. },
  1294. async _initializeMetadata(pdfDocument) {
  1295. const {
  1296. info,
  1297. metadata,
  1298. contentDispositionFilename,
  1299. contentLength
  1300. } = await pdfDocument.getMetadata();
  1301. if (pdfDocument !== this.pdfDocument) {
  1302. return;
  1303. }
  1304. this.documentInfo = info;
  1305. this.metadata = metadata;
  1306. this._contentDispositionFilename ??= contentDispositionFilename;
  1307. this._contentLength ??= contentLength;
  1308. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"})`);
  1309. let pdfTitle = info?.Title;
  1310. const metadataTitle = metadata?.get("dc:title");
  1311. if (metadataTitle) {
  1312. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1313. pdfTitle = metadataTitle;
  1314. }
  1315. }
  1316. if (pdfTitle) {
  1317. this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  1318. } else if (contentDispositionFilename) {
  1319. this.setTitle(contentDispositionFilename);
  1320. }
  1321. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1322. if (pdfDocument.loadingParams.enableXfa) {
  1323. console.warn("Warning: XFA Foreground documents are not supported");
  1324. } else {
  1325. console.warn("Warning: XFA support is not enabled");
  1326. }
  1327. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1328. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  1329. console.warn("Warning: Interactive form support is not enabled");
  1330. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1331. }
  1332. if (info.IsSignaturesPresent) {
  1333. console.warn("Warning: Digital signatures validation is not supported");
  1334. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  1335. }
  1336. let versionId = "other";
  1337. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  1338. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  1339. }
  1340. let generatorId = "other";
  1341. if (info.Producer) {
  1342. const producer = info.Producer.toLowerCase();
  1343. KNOWN_GENERATORS.some(function (generator) {
  1344. if (!producer.includes(generator)) {
  1345. return false;
  1346. }
  1347. generatorId = generator.replace(/[ .-]/g, "_");
  1348. return true;
  1349. });
  1350. }
  1351. let formType = null;
  1352. if (info.IsXFAPresent) {
  1353. formType = "xfa";
  1354. } else if (info.IsAcroFormPresent) {
  1355. formType = "acroform";
  1356. }
  1357. this.externalServices.reportTelemetry({
  1358. type: "documentInfo",
  1359. version: versionId,
  1360. generator: generatorId,
  1361. formType
  1362. });
  1363. this.eventBus.dispatch("metadataloaded", {
  1364. source: this
  1365. });
  1366. },
  1367. async _initializePageLabels(pdfDocument) {
  1368. const labels = await pdfDocument.getPageLabels();
  1369. if (pdfDocument !== this.pdfDocument) {
  1370. return;
  1371. }
  1372. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1373. return;
  1374. }
  1375. const numLabels = labels.length;
  1376. let standardLabels = 0,
  1377. emptyLabels = 0;
  1378. for (let i = 0; i < numLabels; i++) {
  1379. const label = labels[i];
  1380. if (label === (i + 1).toString()) {
  1381. standardLabels++;
  1382. } else if (label === "") {
  1383. emptyLabels++;
  1384. } else {
  1385. break;
  1386. }
  1387. }
  1388. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  1389. return;
  1390. }
  1391. const {
  1392. pdfViewer,
  1393. pdfThumbnailViewer,
  1394. toolbar
  1395. } = this;
  1396. pdfViewer.setPageLabels(labels);
  1397. pdfThumbnailViewer.setPageLabels(labels);
  1398. toolbar.setPagesCount(numLabels, true);
  1399. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1400. },
  1401. _initializePdfHistory({
  1402. fingerprint,
  1403. viewOnLoad,
  1404. initialDest = null
  1405. }) {
  1406. if (!this.pdfHistory) {
  1407. return;
  1408. }
  1409. this.pdfHistory.initialize({
  1410. fingerprint,
  1411. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1412. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1413. });
  1414. if (this.pdfHistory.initialBookmark) {
  1415. this.initialBookmark = this.pdfHistory.initialBookmark;
  1416. this.initialRotation = this.pdfHistory.initialRotation;
  1417. }
  1418. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1419. this.initialBookmark = JSON.stringify(initialDest);
  1420. this.pdfHistory.push({
  1421. explicitDest: initialDest,
  1422. pageNumber: null
  1423. });
  1424. }
  1425. },
  1426. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1427. if (pdfDocument !== this.pdfDocument) {
  1428. return;
  1429. }
  1430. const {
  1431. annotationStorage
  1432. } = pdfDocument;
  1433. annotationStorage.onSetModified = () => {
  1434. window.addEventListener("beforeunload", beforeUnload);
  1435. this._annotationStorageModified = true;
  1436. };
  1437. annotationStorage.onResetModified = () => {
  1438. window.removeEventListener("beforeunload", beforeUnload);
  1439. delete this._annotationStorageModified;
  1440. };
  1441. },
  1442. setInitialView(storedHash, {
  1443. rotation,
  1444. sidebarView,
  1445. scrollMode,
  1446. spreadMode
  1447. } = {}) {
  1448. const setRotation = angle => {
  1449. if ((0, _ui_utils.isValidRotation)(angle)) {
  1450. this.pdfViewer.pagesRotation = angle;
  1451. }
  1452. };
  1453. const setViewerModes = (scroll, spread) => {
  1454. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1455. this.pdfViewer.scrollMode = scroll;
  1456. }
  1457. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1458. this.pdfViewer.spreadMode = spread;
  1459. }
  1460. };
  1461. this.isInitialViewSet = true;
  1462. this.pdfSidebar.setInitialView(sidebarView);
  1463. setViewerModes(scrollMode, spreadMode);
  1464. if (this.initialBookmark) {
  1465. setRotation(this.initialRotation);
  1466. delete this.initialRotation;
  1467. this.pdfLinkService.setHash(this.initialBookmark);
  1468. this.initialBookmark = null;
  1469. } else if (storedHash) {
  1470. setRotation(rotation);
  1471. this.pdfLinkService.setHash(storedHash);
  1472. }
  1473. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1474. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1475. if (!this.pdfViewer.currentScaleValue) {
  1476. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1477. }
  1478. },
  1479. _cleanup() {
  1480. if (!this.pdfDocument) {
  1481. return;
  1482. }
  1483. this.pdfViewer.cleanup();
  1484. this.pdfThumbnailViewer.cleanup();
  1485. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  1486. },
  1487. forceRendering() {
  1488. this.pdfRenderingQueue.printing = !!this.printService;
  1489. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1490. this.pdfRenderingQueue.renderHighestPriority();
  1491. },
  1492. beforePrint() {
  1493. this.pdfScriptingManager.dispatchWillPrint();
  1494. if (this.printService) {
  1495. return;
  1496. }
  1497. if (!this.supportsPrinting) {
  1498. this.l10n.get("printing_not_supported").then(msg => {
  1499. this._otherError(msg);
  1500. });
  1501. return;
  1502. }
  1503. if (!this.pdfViewer.pageViewsReady) {
  1504. this.l10n.get("printing_not_ready").then(msg => {
  1505. window.alert(msg);
  1506. });
  1507. return;
  1508. }
  1509. const pagesOverview = this.pdfViewer.getPagesOverview();
  1510. const printContainer = this.appConfig.printContainer;
  1511. const printResolution = _app_options.AppOptions.get("printResolution");
  1512. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1513. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
  1514. this.printService = printService;
  1515. this.forceRendering();
  1516. printService.layout();
  1517. this.externalServices.reportTelemetry({
  1518. type: "print"
  1519. });
  1520. },
  1521. afterPrint() {
  1522. this.pdfScriptingManager.dispatchDidPrint();
  1523. if (this.printService) {
  1524. this.printService.destroy();
  1525. this.printService = null;
  1526. this.pdfDocument?.annotationStorage.resetModified();
  1527. }
  1528. this.forceRendering();
  1529. },
  1530. rotatePages(delta) {
  1531. this.pdfViewer.pagesRotation += delta;
  1532. },
  1533. requestPresentationMode() {
  1534. this.pdfPresentationMode?.request();
  1535. },
  1536. triggerPrinting() {
  1537. if (!this.supportsPrinting) {
  1538. return;
  1539. }
  1540. window.print();
  1541. },
  1542. bindEvents() {
  1543. const {
  1544. eventBus,
  1545. _boundEvents
  1546. } = this;
  1547. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1548. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1549. eventBus._on("resize", webViewerResize);
  1550. eventBus._on("hashchange", webViewerHashchange);
  1551. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1552. eventBus._on("afterprint", _boundEvents.afterPrint);
  1553. eventBus._on("pagerendered", webViewerPageRendered);
  1554. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1555. eventBus._on("pagechanging", webViewerPageChanging);
  1556. eventBus._on("scalechanging", webViewerScaleChanging);
  1557. eventBus._on("rotationchanging", webViewerRotationChanging);
  1558. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1559. eventBus._on("pagemode", webViewerPageMode);
  1560. eventBus._on("namedaction", webViewerNamedAction);
  1561. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1562. eventBus._on("presentationmode", webViewerPresentationMode);
  1563. eventBus._on("print", webViewerPrint);
  1564. eventBus._on("download", webViewerDownload);
  1565. eventBus._on("save", webViewerSave);
  1566. eventBus._on("firstpage", webViewerFirstPage);
  1567. eventBus._on("lastpage", webViewerLastPage);
  1568. eventBus._on("nextpage", webViewerNextPage);
  1569. eventBus._on("previouspage", webViewerPreviousPage);
  1570. eventBus._on("zoomin", webViewerZoomIn);
  1571. eventBus._on("zoomout", webViewerZoomOut);
  1572. eventBus._on("zoomreset", webViewerZoomReset);
  1573. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1574. eventBus._on("scalechanged", webViewerScaleChanged);
  1575. eventBus._on("rotatecw", webViewerRotateCw);
  1576. eventBus._on("rotateccw", webViewerRotateCcw);
  1577. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1578. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1579. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1580. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1581. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1582. eventBus._on("documentproperties", webViewerDocumentProperties);
  1583. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1584. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1585. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1586. if (_app_options.AppOptions.get("pdfBug")) {
  1587. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1588. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1589. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1590. }
  1591. eventBus._on("fileinputchange", webViewerFileInputChange);
  1592. eventBus._on("openfile", webViewerOpenFile);
  1593. },
  1594. bindWindowEvents() {
  1595. const {
  1596. eventBus,
  1597. _boundEvents
  1598. } = this;
  1599. _boundEvents.windowResize = () => {
  1600. eventBus.dispatch("resize", {
  1601. source: window
  1602. });
  1603. };
  1604. _boundEvents.windowHashChange = () => {
  1605. eventBus.dispatch("hashchange", {
  1606. source: window,
  1607. hash: document.location.hash.substring(1)
  1608. });
  1609. };
  1610. _boundEvents.windowBeforePrint = () => {
  1611. eventBus.dispatch("beforeprint", {
  1612. source: window
  1613. });
  1614. };
  1615. _boundEvents.windowAfterPrint = () => {
  1616. eventBus.dispatch("afterprint", {
  1617. source: window
  1618. });
  1619. };
  1620. _boundEvents.windowUpdateFromSandbox = event => {
  1621. eventBus.dispatch("updatefromsandbox", {
  1622. source: window,
  1623. detail: event.detail
  1624. });
  1625. };
  1626. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1627. window.addEventListener("wheel", webViewerWheel, {
  1628. passive: false
  1629. });
  1630. window.addEventListener("touchstart", webViewerTouchStart, {
  1631. passive: false
  1632. });
  1633. window.addEventListener("click", webViewerClick);
  1634. window.addEventListener("keydown", webViewerKeyDown);
  1635. window.addEventListener("resize", _boundEvents.windowResize);
  1636. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1637. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1638. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1639. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1640. },
  1641. unbindEvents() {
  1642. const {
  1643. eventBus,
  1644. _boundEvents
  1645. } = this;
  1646. eventBus._off("resize", webViewerResize);
  1647. eventBus._off("hashchange", webViewerHashchange);
  1648. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1649. eventBus._off("afterprint", _boundEvents.afterPrint);
  1650. eventBus._off("pagerendered", webViewerPageRendered);
  1651. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1652. eventBus._off("pagechanging", webViewerPageChanging);
  1653. eventBus._off("scalechanging", webViewerScaleChanging);
  1654. eventBus._off("rotationchanging", webViewerRotationChanging);
  1655. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1656. eventBus._off("pagemode", webViewerPageMode);
  1657. eventBus._off("namedaction", webViewerNamedAction);
  1658. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1659. eventBus._off("presentationmode", webViewerPresentationMode);
  1660. eventBus._off("print", webViewerPrint);
  1661. eventBus._off("download", webViewerDownload);
  1662. eventBus._off("save", webViewerSave);
  1663. eventBus._off("firstpage", webViewerFirstPage);
  1664. eventBus._off("lastpage", webViewerLastPage);
  1665. eventBus._off("nextpage", webViewerNextPage);
  1666. eventBus._off("previouspage", webViewerPreviousPage);
  1667. eventBus._off("zoomin", webViewerZoomIn);
  1668. eventBus._off("zoomout", webViewerZoomOut);
  1669. eventBus._off("zoomreset", webViewerZoomReset);
  1670. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1671. eventBus._off("scalechanged", webViewerScaleChanged);
  1672. eventBus._off("rotatecw", webViewerRotateCw);
  1673. eventBus._off("rotateccw", webViewerRotateCcw);
  1674. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1675. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1676. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1677. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1678. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1679. eventBus._off("documentproperties", webViewerDocumentProperties);
  1680. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1681. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1682. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1683. if (_boundEvents.reportPageStatsPDFBug) {
  1684. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1685. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1686. _boundEvents.reportPageStatsPDFBug = null;
  1687. }
  1688. eventBus._off("fileinputchange", webViewerFileInputChange);
  1689. eventBus._off("openfile", webViewerOpenFile);
  1690. _boundEvents.beforePrint = null;
  1691. _boundEvents.afterPrint = null;
  1692. },
  1693. unbindWindowEvents() {
  1694. const {
  1695. _boundEvents
  1696. } = this;
  1697. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1698. window.removeEventListener("wheel", webViewerWheel, {
  1699. passive: false
  1700. });
  1701. window.removeEventListener("touchstart", webViewerTouchStart, {
  1702. passive: false
  1703. });
  1704. window.removeEventListener("click", webViewerClick);
  1705. window.removeEventListener("keydown", webViewerKeyDown);
  1706. window.removeEventListener("resize", _boundEvents.windowResize);
  1707. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1708. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1709. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1710. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1711. _boundEvents.windowResize = null;
  1712. _boundEvents.windowHashChange = null;
  1713. _boundEvents.windowBeforePrint = null;
  1714. _boundEvents.windowAfterPrint = null;
  1715. _boundEvents.windowUpdateFromSandbox = null;
  1716. },
  1717. accumulateWheelTicks(ticks) {
  1718. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  1719. this._wheelUnusedTicks = 0;
  1720. }
  1721. this._wheelUnusedTicks += ticks;
  1722. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  1723. this._wheelUnusedTicks -= wholeTicks;
  1724. return wholeTicks;
  1725. },
  1726. _unblockDocumentLoadEvent() {
  1727. document.blockUnblockOnload?.(false);
  1728. this._unblockDocumentLoadEvent = () => {};
  1729. },
  1730. _reportDocumentStatsTelemetry() {
  1731. const {
  1732. stats
  1733. } = this.pdfDocument;
  1734. if (stats !== this._docStats) {
  1735. this._docStats = stats;
  1736. this.externalServices.reportTelemetry({
  1737. type: "documentStats",
  1738. stats
  1739. });
  1740. }
  1741. },
  1742. get scriptingReady() {
  1743. return this.pdfScriptingManager.ready;
  1744. }
  1745. };
  1746. exports.PDFViewerApplication = PDFViewerApplication;
  1747. let validateFileURL;
  1748. {
  1749. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1750. validateFileURL = function (file) {
  1751. if (!file) {
  1752. return;
  1753. }
  1754. try {
  1755. const viewerOrigin = new URL(window.location.href).origin || "null";
  1756. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1757. return;
  1758. }
  1759. const fileOrigin = new URL(file, window.location.href).origin;
  1760. if (fileOrigin !== viewerOrigin) {
  1761. throw new Error("file origin does not match viewer's");
  1762. }
  1763. } catch (ex) {
  1764. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1765. PDFViewerApplication._documentError(msg, {
  1766. message: ex?.message
  1767. });
  1768. });
  1769. throw ex;
  1770. }
  1771. };
  1772. }
  1773. async function loadFakeWorker() {
  1774. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  1775. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  1776. }
  1777. async function loadPDFBug(self) {
  1778. const {
  1779. debuggerScriptPath
  1780. } = self.appConfig;
  1781. const {
  1782. PDFBug
  1783. } = await import(debuggerScriptPath);
  1784. self._PDFBug = PDFBug;
  1785. }
  1786. function reportPageStatsPDFBug({
  1787. pageNumber
  1788. }) {
  1789. if (!globalThis.Stats?.enabled) {
  1790. return;
  1791. }
  1792. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1793. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  1794. }
  1795. function webViewerInitialized() {
  1796. const {
  1797. appConfig,
  1798. eventBus
  1799. } = PDFViewerApplication;
  1800. let file;
  1801. const queryString = document.location.search.substring(1);
  1802. const params = (0, _ui_utils.parseQueryString)(queryString);
  1803. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  1804. validateFileURL(file);
  1805. const fileInput = appConfig.openFileInput;
  1806. fileInput.value = null;
  1807. fileInput.addEventListener("change", function (evt) {
  1808. const {
  1809. files
  1810. } = evt.target;
  1811. if (!files || files.length === 0) {
  1812. return;
  1813. }
  1814. eventBus.dispatch("fileinputchange", {
  1815. source: this,
  1816. fileInput: evt.target
  1817. });
  1818. });
  1819. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1820. evt.preventDefault();
  1821. evt.dataTransfer.dropEffect = "move";
  1822. });
  1823. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1824. evt.preventDefault();
  1825. const {
  1826. files
  1827. } = evt.dataTransfer;
  1828. if (!files || files.length === 0) {
  1829. return;
  1830. }
  1831. eventBus.dispatch("fileinputchange", {
  1832. source: this,
  1833. fileInput: evt.dataTransfer
  1834. });
  1835. });
  1836. if (!PDFViewerApplication.supportsDocumentFonts) {
  1837. _app_options.AppOptions.set("disableFontFace", true);
  1838. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  1839. console.warn(msg);
  1840. });
  1841. }
  1842. if (!PDFViewerApplication.supportsPrinting) {
  1843. appConfig.toolbar.print.classList.add("hidden");
  1844. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  1845. }
  1846. if (!PDFViewerApplication.supportsFullscreen) {
  1847. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  1848. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  1849. }
  1850. if (PDFViewerApplication.supportsIntegratedFind) {
  1851. appConfig.toolbar.viewFind.classList.add("hidden");
  1852. }
  1853. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1854. if (evt.target === this) {
  1855. eventBus.dispatch("resize", {
  1856. source: this
  1857. });
  1858. }
  1859. }, true);
  1860. try {
  1861. if (file) {
  1862. PDFViewerApplication.open(file);
  1863. } else {
  1864. PDFViewerApplication._hideViewBookmark();
  1865. }
  1866. } catch (reason) {
  1867. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1868. PDFViewerApplication._documentError(msg, reason);
  1869. });
  1870. }
  1871. }
  1872. function webViewerPageRendered({
  1873. pageNumber,
  1874. error
  1875. }) {
  1876. if (pageNumber === PDFViewerApplication.page) {
  1877. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1878. }
  1879. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1880. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1881. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  1882. if (pageView && thumbnailView) {
  1883. thumbnailView.setImage(pageView);
  1884. }
  1885. }
  1886. if (error) {
  1887. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1888. PDFViewerApplication._otherError(msg, error);
  1889. });
  1890. }
  1891. PDFViewerApplication._reportDocumentStatsTelemetry();
  1892. }
  1893. function webViewerPageMode({
  1894. mode
  1895. }) {
  1896. let view;
  1897. switch (mode) {
  1898. case "thumbs":
  1899. view = _ui_utils.SidebarView.THUMBS;
  1900. break;
  1901. case "bookmarks":
  1902. case "outline":
  1903. view = _ui_utils.SidebarView.OUTLINE;
  1904. break;
  1905. case "attachments":
  1906. view = _ui_utils.SidebarView.ATTACHMENTS;
  1907. break;
  1908. case "layers":
  1909. view = _ui_utils.SidebarView.LAYERS;
  1910. break;
  1911. case "none":
  1912. view = _ui_utils.SidebarView.NONE;
  1913. break;
  1914. default:
  1915. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1916. return;
  1917. }
  1918. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1919. }
  1920. function webViewerNamedAction(evt) {
  1921. switch (evt.action) {
  1922. case "GoToPage":
  1923. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1924. break;
  1925. case "Find":
  1926. if (!PDFViewerApplication.supportsIntegratedFind) {
  1927. PDFViewerApplication.findBar.toggle();
  1928. }
  1929. break;
  1930. case "Print":
  1931. PDFViewerApplication.triggerPrinting();
  1932. break;
  1933. case "SaveAs":
  1934. webViewerSave();
  1935. break;
  1936. }
  1937. }
  1938. function webViewerPresentationModeChanged(evt) {
  1939. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1940. }
  1941. function webViewerSidebarViewChanged(evt) {
  1942. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1943. if (PDFViewerApplication.isInitialViewSet) {
  1944. PDFViewerApplication.store?.set("sidebarView", evt.view).catch(() => {});
  1945. }
  1946. }
  1947. function webViewerUpdateViewarea(evt) {
  1948. const location = evt.location;
  1949. if (PDFViewerApplication.isInitialViewSet) {
  1950. PDFViewerApplication.store?.setMultiple({
  1951. page: location.pageNumber,
  1952. zoom: location.scale,
  1953. scrollLeft: location.left,
  1954. scrollTop: location.top,
  1955. rotation: location.rotation
  1956. }).catch(() => {});
  1957. }
  1958. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1959. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1960. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1961. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1962. const loading = currentPage?.renderingState !== _ui_utils.RenderingStates.FINISHED;
  1963. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1964. }
  1965. function webViewerScrollModeChanged(evt) {
  1966. if (PDFViewerApplication.isInitialViewSet) {
  1967. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  1968. }
  1969. }
  1970. function webViewerSpreadModeChanged(evt) {
  1971. if (PDFViewerApplication.isInitialViewSet) {
  1972. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  1973. }
  1974. }
  1975. function webViewerResize() {
  1976. const {
  1977. pdfDocument,
  1978. pdfViewer
  1979. } = PDFViewerApplication;
  1980. pdfViewer.updateContainerHeightCss();
  1981. if (!pdfDocument) {
  1982. return;
  1983. }
  1984. const currentScaleValue = pdfViewer.currentScaleValue;
  1985. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  1986. pdfViewer.currentScaleValue = currentScaleValue;
  1987. }
  1988. pdfViewer.update();
  1989. }
  1990. function webViewerHashchange(evt) {
  1991. const hash = evt.hash;
  1992. if (!hash) {
  1993. return;
  1994. }
  1995. if (!PDFViewerApplication.isInitialViewSet) {
  1996. PDFViewerApplication.initialBookmark = hash;
  1997. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  1998. PDFViewerApplication.pdfLinkService.setHash(hash);
  1999. }
  2000. }
  2001. {
  2002. var webViewerFileInputChange = function (evt) {
  2003. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2004. return;
  2005. }
  2006. const file = evt.fileInput.files[0];
  2007. let url = URL.createObjectURL(file);
  2008. if (file.name) {
  2009. url = {
  2010. url,
  2011. originalUrl: file.name
  2012. };
  2013. }
  2014. PDFViewerApplication.open(url);
  2015. };
  2016. var webViewerOpenFile = function (evt) {
  2017. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  2018. fileInput.click();
  2019. };
  2020. }
  2021. function webViewerPresentationMode() {
  2022. PDFViewerApplication.requestPresentationMode();
  2023. }
  2024. function webViewerPrint() {
  2025. PDFViewerApplication.triggerPrinting();
  2026. }
  2027. function webViewerDownload() {
  2028. PDFViewerApplication.downloadOrSave({
  2029. sourceEventType: "download"
  2030. });
  2031. }
  2032. function webViewerSave() {
  2033. PDFViewerApplication.downloadOrSave({
  2034. sourceEventType: "save"
  2035. });
  2036. }
  2037. function webViewerFirstPage() {
  2038. if (PDFViewerApplication.pdfDocument) {
  2039. PDFViewerApplication.page = 1;
  2040. }
  2041. }
  2042. function webViewerLastPage() {
  2043. if (PDFViewerApplication.pdfDocument) {
  2044. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2045. }
  2046. }
  2047. function webViewerNextPage() {
  2048. PDFViewerApplication.pdfViewer.nextPage();
  2049. }
  2050. function webViewerPreviousPage() {
  2051. PDFViewerApplication.pdfViewer.previousPage();
  2052. }
  2053. function webViewerZoomIn() {
  2054. PDFViewerApplication.zoomIn();
  2055. }
  2056. function webViewerZoomOut() {
  2057. PDFViewerApplication.zoomOut();
  2058. }
  2059. function webViewerZoomReset() {
  2060. PDFViewerApplication.zoomReset();
  2061. }
  2062. function webViewerPageNumberChanged(evt) {
  2063. const pdfViewer = PDFViewerApplication.pdfViewer;
  2064. if (evt.value !== "") {
  2065. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  2066. }
  2067. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  2068. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2069. }
  2070. }
  2071. function webViewerScaleChanged(evt) {
  2072. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2073. }
  2074. function webViewerRotateCw() {
  2075. PDFViewerApplication.rotatePages(90);
  2076. }
  2077. function webViewerRotateCcw() {
  2078. PDFViewerApplication.rotatePages(-90);
  2079. }
  2080. function webViewerOptionalContentConfig(evt) {
  2081. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  2082. }
  2083. function webViewerSwitchScrollMode(evt) {
  2084. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  2085. }
  2086. function webViewerSwitchSpreadMode(evt) {
  2087. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  2088. }
  2089. function webViewerDocumentProperties() {
  2090. PDFViewerApplication.pdfDocumentProperties.open();
  2091. }
  2092. function webViewerFindFromUrlHash(evt) {
  2093. PDFViewerApplication.eventBus.dispatch("find", {
  2094. source: evt.source,
  2095. type: "",
  2096. query: evt.query,
  2097. phraseSearch: evt.phraseSearch,
  2098. caseSensitive: false,
  2099. entireWord: false,
  2100. highlightAll: true,
  2101. findPrevious: false,
  2102. matchDiacritics: true
  2103. });
  2104. }
  2105. function webViewerUpdateFindMatchesCount({
  2106. matchesCount
  2107. }) {
  2108. if (PDFViewerApplication.supportsIntegratedFind) {
  2109. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  2110. } else {
  2111. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  2112. }
  2113. }
  2114. function webViewerUpdateFindControlState({
  2115. state,
  2116. previous,
  2117. matchesCount,
  2118. rawQuery
  2119. }) {
  2120. if (PDFViewerApplication.supportsIntegratedFind) {
  2121. PDFViewerApplication.externalServices.updateFindControlState({
  2122. result: state,
  2123. findPrevious: previous,
  2124. matchesCount,
  2125. rawQuery
  2126. });
  2127. } else {
  2128. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  2129. }
  2130. }
  2131. function webViewerScaleChanging(evt) {
  2132. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  2133. PDFViewerApplication.pdfViewer.update();
  2134. }
  2135. function webViewerRotationChanging(evt) {
  2136. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  2137. PDFViewerApplication.forceRendering();
  2138. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2139. }
  2140. function webViewerPageChanging({
  2141. pageNumber,
  2142. pageLabel
  2143. }) {
  2144. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  2145. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  2146. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2147. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  2148. }
  2149. }
  2150. function webViewerVisibilityChange(evt) {
  2151. if (document.visibilityState === "visible") {
  2152. setZoomDisabledTimeout();
  2153. }
  2154. }
  2155. let zoomDisabledTimeout = null;
  2156. function setZoomDisabledTimeout() {
  2157. if (zoomDisabledTimeout) {
  2158. clearTimeout(zoomDisabledTimeout);
  2159. }
  2160. zoomDisabledTimeout = setTimeout(function () {
  2161. zoomDisabledTimeout = null;
  2162. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  2163. }
  2164. function webViewerWheel(evt) {
  2165. const {
  2166. pdfViewer,
  2167. supportedMouseWheelZoomModifierKeys
  2168. } = PDFViewerApplication;
  2169. if (pdfViewer.isInPresentationMode) {
  2170. return;
  2171. }
  2172. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  2173. evt.preventDefault();
  2174. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2175. return;
  2176. }
  2177. const deltaMode = evt.deltaMode;
  2178. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2179. const previousScale = pdfViewer.currentScale;
  2180. let ticks = 0;
  2181. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2182. if (Math.abs(delta) >= 1) {
  2183. ticks = Math.sign(delta);
  2184. } else {
  2185. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  2186. }
  2187. } else {
  2188. const PIXELS_PER_LINE_SCALE = 30;
  2189. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  2190. }
  2191. if (ticks < 0) {
  2192. PDFViewerApplication.zoomOut(-ticks);
  2193. } else if (ticks > 0) {
  2194. PDFViewerApplication.zoomIn(ticks);
  2195. }
  2196. const currentScale = pdfViewer.currentScale;
  2197. if (previousScale !== currentScale) {
  2198. const scaleCorrectionFactor = currentScale / previousScale - 1;
  2199. const rect = pdfViewer.container.getBoundingClientRect();
  2200. const dx = evt.clientX - rect.left;
  2201. const dy = evt.clientY - rect.top;
  2202. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  2203. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  2204. }
  2205. } else {
  2206. setZoomDisabledTimeout();
  2207. }
  2208. }
  2209. function webViewerTouchStart(evt) {
  2210. if (evt.touches.length > 1) {
  2211. evt.preventDefault();
  2212. }
  2213. }
  2214. function webViewerClick(evt) {
  2215. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  2216. return;
  2217. }
  2218. const appConfig = PDFViewerApplication.appConfig;
  2219. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  2220. PDFViewerApplication.secondaryToolbar.close();
  2221. }
  2222. }
  2223. function webViewerKeyDown(evt) {
  2224. if (PDFViewerApplication.overlayManager.active) {
  2225. return;
  2226. }
  2227. const {
  2228. eventBus,
  2229. pdfViewer
  2230. } = PDFViewerApplication;
  2231. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  2232. let handled = false,
  2233. ensureViewerFocused = false;
  2234. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2235. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2236. switch (evt.keyCode) {
  2237. case 70:
  2238. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2239. PDFViewerApplication.findBar.open();
  2240. handled = true;
  2241. }
  2242. break;
  2243. case 71:
  2244. if (!PDFViewerApplication.supportsIntegratedFind) {
  2245. const {
  2246. state
  2247. } = PDFViewerApplication.findController;
  2248. if (state) {
  2249. const eventState = Object.assign(Object.create(null), state, {
  2250. source: window,
  2251. type: "again",
  2252. findPrevious: cmd === 5 || cmd === 12
  2253. });
  2254. eventBus.dispatch("find", eventState);
  2255. }
  2256. handled = true;
  2257. }
  2258. break;
  2259. case 61:
  2260. case 107:
  2261. case 187:
  2262. case 171:
  2263. if (!isViewerInPresentationMode) {
  2264. PDFViewerApplication.zoomIn();
  2265. }
  2266. handled = true;
  2267. break;
  2268. case 173:
  2269. case 109:
  2270. case 189:
  2271. if (!isViewerInPresentationMode) {
  2272. PDFViewerApplication.zoomOut();
  2273. }
  2274. handled = true;
  2275. break;
  2276. case 48:
  2277. case 96:
  2278. if (!isViewerInPresentationMode) {
  2279. setTimeout(function () {
  2280. PDFViewerApplication.zoomReset();
  2281. });
  2282. handled = false;
  2283. }
  2284. break;
  2285. case 38:
  2286. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2287. PDFViewerApplication.page = 1;
  2288. handled = true;
  2289. ensureViewerFocused = true;
  2290. }
  2291. break;
  2292. case 40:
  2293. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2294. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2295. handled = true;
  2296. ensureViewerFocused = true;
  2297. }
  2298. break;
  2299. }
  2300. }
  2301. if (cmd === 1 || cmd === 8) {
  2302. switch (evt.keyCode) {
  2303. case 83:
  2304. eventBus.dispatch("download", {
  2305. source: window
  2306. });
  2307. handled = true;
  2308. break;
  2309. case 79:
  2310. {
  2311. eventBus.dispatch("openfile", {
  2312. source: window
  2313. });
  2314. handled = true;
  2315. }
  2316. break;
  2317. }
  2318. }
  2319. if (cmd === 3 || cmd === 10) {
  2320. switch (evt.keyCode) {
  2321. case 80:
  2322. PDFViewerApplication.requestPresentationMode();
  2323. handled = true;
  2324. break;
  2325. case 71:
  2326. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2327. handled = true;
  2328. break;
  2329. }
  2330. }
  2331. if (handled) {
  2332. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2333. pdfViewer.focus();
  2334. }
  2335. evt.preventDefault();
  2336. return;
  2337. }
  2338. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2339. const curElementTagName = curElement?.tagName.toUpperCase();
  2340. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2341. if (evt.keyCode !== 27) {
  2342. return;
  2343. }
  2344. }
  2345. if (cmd === 0) {
  2346. let turnPage = 0,
  2347. turnOnlyIfPageFit = false;
  2348. switch (evt.keyCode) {
  2349. case 38:
  2350. case 33:
  2351. if (pdfViewer.isVerticalScrollbarEnabled) {
  2352. turnOnlyIfPageFit = true;
  2353. }
  2354. turnPage = -1;
  2355. break;
  2356. case 8:
  2357. if (!isViewerInPresentationMode) {
  2358. turnOnlyIfPageFit = true;
  2359. }
  2360. turnPage = -1;
  2361. break;
  2362. case 37:
  2363. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2364. turnOnlyIfPageFit = true;
  2365. }
  2366. case 75:
  2367. case 80:
  2368. turnPage = -1;
  2369. break;
  2370. case 27:
  2371. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2372. PDFViewerApplication.secondaryToolbar.close();
  2373. handled = true;
  2374. }
  2375. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2376. PDFViewerApplication.findBar.close();
  2377. handled = true;
  2378. }
  2379. break;
  2380. case 40:
  2381. case 34:
  2382. if (pdfViewer.isVerticalScrollbarEnabled) {
  2383. turnOnlyIfPageFit = true;
  2384. }
  2385. turnPage = 1;
  2386. break;
  2387. case 13:
  2388. case 32:
  2389. if (!isViewerInPresentationMode) {
  2390. turnOnlyIfPageFit = true;
  2391. }
  2392. turnPage = 1;
  2393. break;
  2394. case 39:
  2395. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2396. turnOnlyIfPageFit = true;
  2397. }
  2398. case 74:
  2399. case 78:
  2400. turnPage = 1;
  2401. break;
  2402. case 36:
  2403. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2404. PDFViewerApplication.page = 1;
  2405. handled = true;
  2406. ensureViewerFocused = true;
  2407. }
  2408. break;
  2409. case 35:
  2410. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2411. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2412. handled = true;
  2413. ensureViewerFocused = true;
  2414. }
  2415. break;
  2416. case 83:
  2417. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2418. break;
  2419. case 72:
  2420. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2421. break;
  2422. case 82:
  2423. PDFViewerApplication.rotatePages(90);
  2424. break;
  2425. case 115:
  2426. PDFViewerApplication.pdfSidebar.toggle();
  2427. break;
  2428. }
  2429. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2430. if (turnPage > 0) {
  2431. pdfViewer.nextPage();
  2432. } else {
  2433. pdfViewer.previousPage();
  2434. }
  2435. handled = true;
  2436. }
  2437. }
  2438. if (cmd === 4) {
  2439. switch (evt.keyCode) {
  2440. case 13:
  2441. case 32:
  2442. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2443. break;
  2444. }
  2445. pdfViewer.previousPage();
  2446. handled = true;
  2447. break;
  2448. case 82:
  2449. PDFViewerApplication.rotatePages(-90);
  2450. break;
  2451. }
  2452. }
  2453. if (!handled && !isViewerInPresentationMode) {
  2454. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2455. ensureViewerFocused = true;
  2456. }
  2457. }
  2458. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2459. pdfViewer.focus();
  2460. }
  2461. if (handled) {
  2462. evt.preventDefault();
  2463. }
  2464. }
  2465. function beforeUnload(evt) {
  2466. evt.preventDefault();
  2467. evt.returnValue = "";
  2468. return false;
  2469. }
  2470. const PDFPrintServiceFactory = {
  2471. instance: {
  2472. supportsPrinting: false,
  2473. createPrintService() {
  2474. throw new Error("Not implemented: createPrintService");
  2475. }
  2476. }
  2477. };
  2478. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2479. /***/ }),
  2480. /* 3 */
  2481. /***/ ((__unused_webpack_module, exports) => {
  2482. Object.defineProperty(exports, "__esModule", ({
  2483. value: true
  2484. }));
  2485. exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = void 0;
  2486. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  2487. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2488. exports.approximateFraction = approximateFraction;
  2489. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2490. exports.binarySearchFirstItem = binarySearchFirstItem;
  2491. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2492. exports.getPageSizeInches = getPageSizeInches;
  2493. exports.getVisibleElements = getVisibleElements;
  2494. exports.isPortraitOrientation = isPortraitOrientation;
  2495. exports.isValidRotation = isValidRotation;
  2496. exports.isValidScrollMode = isValidScrollMode;
  2497. exports.isValidSpreadMode = isValidSpreadMode;
  2498. exports.noContextMenuHandler = noContextMenuHandler;
  2499. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2500. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2501. exports.parseQueryString = parseQueryString;
  2502. exports.removeNullCharacters = removeNullCharacters;
  2503. exports.roundToDivide = roundToDivide;
  2504. exports.scrollIntoView = scrollIntoView;
  2505. exports.watchScroll = watchScroll;
  2506. const DEFAULT_SCALE_VALUE = "auto";
  2507. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2508. const DEFAULT_SCALE = 1.0;
  2509. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2510. const DEFAULT_SCALE_DELTA = 1.1;
  2511. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  2512. const MIN_SCALE = 0.1;
  2513. exports.MIN_SCALE = MIN_SCALE;
  2514. const MAX_SCALE = 10.0;
  2515. exports.MAX_SCALE = MAX_SCALE;
  2516. const UNKNOWN_SCALE = 0;
  2517. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2518. const MAX_AUTO_SCALE = 1.25;
  2519. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2520. const SCROLLBAR_PADDING = 40;
  2521. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2522. const VERTICAL_PADDING = 5;
  2523. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2524. const RenderingStates = {
  2525. INITIAL: 0,
  2526. RUNNING: 1,
  2527. PAUSED: 2,
  2528. FINISHED: 3
  2529. };
  2530. exports.RenderingStates = RenderingStates;
  2531. const PresentationModeState = {
  2532. UNKNOWN: 0,
  2533. NORMAL: 1,
  2534. CHANGING: 2,
  2535. FULLSCREEN: 3
  2536. };
  2537. exports.PresentationModeState = PresentationModeState;
  2538. const SidebarView = {
  2539. UNKNOWN: -1,
  2540. NONE: 0,
  2541. THUMBS: 1,
  2542. OUTLINE: 2,
  2543. ATTACHMENTS: 3,
  2544. LAYERS: 4
  2545. };
  2546. exports.SidebarView = SidebarView;
  2547. const RendererType = {
  2548. CANVAS: "canvas",
  2549. SVG: "svg"
  2550. };
  2551. exports.RendererType = RendererType;
  2552. const TextLayerMode = {
  2553. DISABLE: 0,
  2554. ENABLE: 1,
  2555. ENABLE_ENHANCE: 2
  2556. };
  2557. exports.TextLayerMode = TextLayerMode;
  2558. const ScrollMode = {
  2559. UNKNOWN: -1,
  2560. VERTICAL: 0,
  2561. HORIZONTAL: 1,
  2562. WRAPPED: 2,
  2563. PAGE: 3
  2564. };
  2565. exports.ScrollMode = ScrollMode;
  2566. const SpreadMode = {
  2567. UNKNOWN: -1,
  2568. NONE: 0,
  2569. ODD: 1,
  2570. EVEN: 2
  2571. };
  2572. exports.SpreadMode = SpreadMode;
  2573. const AutoPrintRegExp = /\bprint\s*\(/;
  2574. exports.AutoPrintRegExp = AutoPrintRegExp;
  2575. class OutputScale {
  2576. constructor() {
  2577. const pixelRatio = window.devicePixelRatio || 1;
  2578. this.sx = pixelRatio;
  2579. this.sy = pixelRatio;
  2580. }
  2581. get scaled() {
  2582. return this.sx !== 1 || this.sy !== 1;
  2583. }
  2584. }
  2585. exports.OutputScale = OutputScale;
  2586. function scrollIntoView(element, spot, scrollMatches = false) {
  2587. let parent = element.offsetParent;
  2588. if (!parent) {
  2589. console.error("offsetParent is not set -- cannot scroll");
  2590. return;
  2591. }
  2592. let offsetY = element.offsetTop + element.clientTop;
  2593. let offsetX = element.offsetLeft + element.clientLeft;
  2594. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  2595. offsetY += parent.offsetTop;
  2596. offsetX += parent.offsetLeft;
  2597. parent = parent.offsetParent;
  2598. if (!parent) {
  2599. return;
  2600. }
  2601. }
  2602. if (spot) {
  2603. if (spot.top !== undefined) {
  2604. offsetY += spot.top;
  2605. }
  2606. if (spot.left !== undefined) {
  2607. offsetX += spot.left;
  2608. parent.scrollLeft = offsetX;
  2609. }
  2610. }
  2611. parent.scrollTop = offsetY;
  2612. }
  2613. function watchScroll(viewAreaElement, callback) {
  2614. const debounceScroll = function (evt) {
  2615. if (rAF) {
  2616. return;
  2617. }
  2618. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2619. rAF = null;
  2620. const currentX = viewAreaElement.scrollLeft;
  2621. const lastX = state.lastX;
  2622. if (currentX !== lastX) {
  2623. state.right = currentX > lastX;
  2624. }
  2625. state.lastX = currentX;
  2626. const currentY = viewAreaElement.scrollTop;
  2627. const lastY = state.lastY;
  2628. if (currentY !== lastY) {
  2629. state.down = currentY > lastY;
  2630. }
  2631. state.lastY = currentY;
  2632. callback(state);
  2633. });
  2634. };
  2635. const state = {
  2636. right: true,
  2637. down: true,
  2638. lastX: viewAreaElement.scrollLeft,
  2639. lastY: viewAreaElement.scrollTop,
  2640. _eventHandler: debounceScroll
  2641. };
  2642. let rAF = null;
  2643. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2644. return state;
  2645. }
  2646. function parseQueryString(query) {
  2647. const params = new Map();
  2648. for (const [key, value] of new URLSearchParams(query)) {
  2649. params.set(key.toLowerCase(), value);
  2650. }
  2651. return params;
  2652. }
  2653. const NullCharactersRegExp = /\x00/g;
  2654. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  2655. function removeNullCharacters(str, replaceInvisible = false) {
  2656. if (typeof str !== "string") {
  2657. console.error(`The argument must be a string.`);
  2658. return str;
  2659. }
  2660. if (replaceInvisible) {
  2661. str = str.replace(InvisibleCharactersRegExp, " ");
  2662. }
  2663. return str.replace(NullCharactersRegExp, "");
  2664. }
  2665. function binarySearchFirstItem(items, condition, start = 0) {
  2666. let minIndex = start;
  2667. let maxIndex = items.length - 1;
  2668. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2669. return items.length;
  2670. }
  2671. if (condition(items[minIndex])) {
  2672. return minIndex;
  2673. }
  2674. while (minIndex < maxIndex) {
  2675. const currentIndex = minIndex + maxIndex >> 1;
  2676. const currentItem = items[currentIndex];
  2677. if (condition(currentItem)) {
  2678. maxIndex = currentIndex;
  2679. } else {
  2680. minIndex = currentIndex + 1;
  2681. }
  2682. }
  2683. return minIndex;
  2684. }
  2685. function approximateFraction(x) {
  2686. if (Math.floor(x) === x) {
  2687. return [x, 1];
  2688. }
  2689. const xinv = 1 / x;
  2690. const limit = 8;
  2691. if (xinv > limit) {
  2692. return [1, limit];
  2693. } else if (Math.floor(xinv) === xinv) {
  2694. return [1, xinv];
  2695. }
  2696. const x_ = x > 1 ? xinv : x;
  2697. let a = 0,
  2698. b = 1,
  2699. c = 1,
  2700. d = 1;
  2701. while (true) {
  2702. const p = a + c,
  2703. q = b + d;
  2704. if (q > limit) {
  2705. break;
  2706. }
  2707. if (x_ <= p / q) {
  2708. c = p;
  2709. d = q;
  2710. } else {
  2711. a = p;
  2712. b = q;
  2713. }
  2714. }
  2715. let result;
  2716. if (x_ - a / b < c / d - x_) {
  2717. result = x_ === x ? [a, b] : [b, a];
  2718. } else {
  2719. result = x_ === x ? [c, d] : [d, c];
  2720. }
  2721. return result;
  2722. }
  2723. function roundToDivide(x, div) {
  2724. const r = x % div;
  2725. return r === 0 ? x : Math.round(x - r + div);
  2726. }
  2727. function getPageSizeInches({
  2728. view,
  2729. userUnit,
  2730. rotate
  2731. }) {
  2732. const [x1, y1, x2, y2] = view;
  2733. const changeOrientation = rotate % 180 !== 0;
  2734. const width = (x2 - x1) / 72 * userUnit;
  2735. const height = (y2 - y1) / 72 * userUnit;
  2736. return {
  2737. width: changeOrientation ? height : width,
  2738. height: changeOrientation ? width : height
  2739. };
  2740. }
  2741. function backtrackBeforeAllVisibleElements(index, views, top) {
  2742. if (index < 2) {
  2743. return index;
  2744. }
  2745. let elt = views[index].div;
  2746. let pageTop = elt.offsetTop + elt.clientTop;
  2747. if (pageTop >= top) {
  2748. elt = views[index - 1].div;
  2749. pageTop = elt.offsetTop + elt.clientTop;
  2750. }
  2751. for (let i = index - 2; i >= 0; --i) {
  2752. elt = views[i].div;
  2753. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2754. break;
  2755. }
  2756. index = i;
  2757. }
  2758. return index;
  2759. }
  2760. function getVisibleElements({
  2761. scrollEl,
  2762. views,
  2763. sortByVisibility = false,
  2764. horizontal = false,
  2765. rtl = false
  2766. }) {
  2767. const top = scrollEl.scrollTop,
  2768. bottom = top + scrollEl.clientHeight;
  2769. const left = scrollEl.scrollLeft,
  2770. right = left + scrollEl.clientWidth;
  2771. function isElementBottomAfterViewTop(view) {
  2772. const element = view.div;
  2773. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2774. return elementBottom > top;
  2775. }
  2776. function isElementNextAfterViewHorizontally(view) {
  2777. const element = view.div;
  2778. const elementLeft = element.offsetLeft + element.clientLeft;
  2779. const elementRight = elementLeft + element.clientWidth;
  2780. return rtl ? elementLeft < right : elementRight > left;
  2781. }
  2782. const visible = [],
  2783. ids = new Set(),
  2784. numViews = views.length;
  2785. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2786. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2787. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2788. }
  2789. let lastEdge = horizontal ? right : -1;
  2790. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2791. const view = views[i],
  2792. element = view.div;
  2793. const currentWidth = element.offsetLeft + element.clientLeft;
  2794. const currentHeight = element.offsetTop + element.clientTop;
  2795. const viewWidth = element.clientWidth,
  2796. viewHeight = element.clientHeight;
  2797. const viewRight = currentWidth + viewWidth;
  2798. const viewBottom = currentHeight + viewHeight;
  2799. if (lastEdge === -1) {
  2800. if (viewBottom >= bottom) {
  2801. lastEdge = viewBottom;
  2802. }
  2803. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2804. break;
  2805. }
  2806. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2807. continue;
  2808. }
  2809. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2810. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2811. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2812. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2813. const percent = fractionHeight * fractionWidth * 100 | 0;
  2814. visible.push({
  2815. id: view.id,
  2816. x: currentWidth,
  2817. y: currentHeight,
  2818. view,
  2819. percent,
  2820. widthPercent: fractionWidth * 100 | 0
  2821. });
  2822. ids.add(view.id);
  2823. }
  2824. const first = visible[0],
  2825. last = visible[visible.length - 1];
  2826. if (sortByVisibility) {
  2827. visible.sort(function (a, b) {
  2828. const pc = a.percent - b.percent;
  2829. if (Math.abs(pc) > 0.001) {
  2830. return -pc;
  2831. }
  2832. return a.id - b.id;
  2833. });
  2834. }
  2835. return {
  2836. first,
  2837. last,
  2838. views: visible,
  2839. ids
  2840. };
  2841. }
  2842. function noContextMenuHandler(evt) {
  2843. evt.preventDefault();
  2844. }
  2845. function normalizeWheelEventDirection(evt) {
  2846. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2847. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2848. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2849. delta = -delta;
  2850. }
  2851. return delta;
  2852. }
  2853. function normalizeWheelEventDelta(evt) {
  2854. let delta = normalizeWheelEventDirection(evt);
  2855. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  2856. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  2857. const MOUSE_PIXELS_PER_LINE = 30;
  2858. const MOUSE_LINES_PER_PAGE = 30;
  2859. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  2860. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2861. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  2862. delta /= MOUSE_LINES_PER_PAGE;
  2863. }
  2864. return delta;
  2865. }
  2866. function isValidRotation(angle) {
  2867. return Number.isInteger(angle) && angle % 90 === 0;
  2868. }
  2869. function isValidScrollMode(mode) {
  2870. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2871. }
  2872. function isValidSpreadMode(mode) {
  2873. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2874. }
  2875. function isPortraitOrientation(size) {
  2876. return size.width <= size.height;
  2877. }
  2878. const animationStarted = new Promise(function (resolve) {
  2879. window.requestAnimationFrame(resolve);
  2880. });
  2881. exports.animationStarted = animationStarted;
  2882. function clamp(v, min, max) {
  2883. return Math.min(Math.max(v, min), max);
  2884. }
  2885. class ProgressBar {
  2886. constructor(id) {
  2887. if (arguments.length > 1) {
  2888. throw new Error("ProgressBar no longer accepts any additional options, " + "please use CSS rules to modify its appearance instead.");
  2889. }
  2890. this.visible = true;
  2891. this.div = document.querySelector(id + " .progress");
  2892. this.bar = this.div.parentNode;
  2893. this.percent = 0;
  2894. }
  2895. #updateBar() {
  2896. if (this._indeterminate) {
  2897. this.div.classList.add("indeterminate");
  2898. return;
  2899. }
  2900. this.div.classList.remove("indeterminate");
  2901. const doc = document.documentElement;
  2902. doc.style.setProperty("--progressBar-percent", `${this._percent}%`);
  2903. }
  2904. get percent() {
  2905. return this._percent;
  2906. }
  2907. set percent(val) {
  2908. this._indeterminate = isNaN(val);
  2909. this._percent = clamp(val, 0, 100);
  2910. this.#updateBar();
  2911. }
  2912. setWidth(viewer) {
  2913. if (!viewer) {
  2914. return;
  2915. }
  2916. const container = viewer.parentNode;
  2917. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  2918. if (scrollbarWidth > 0) {
  2919. const doc = document.documentElement;
  2920. doc.style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  2921. }
  2922. }
  2923. hide() {
  2924. if (!this.visible) {
  2925. return;
  2926. }
  2927. this.visible = false;
  2928. this.bar.classList.add("hidden");
  2929. }
  2930. show() {
  2931. if (this.visible) {
  2932. return;
  2933. }
  2934. this.visible = true;
  2935. this.bar.classList.remove("hidden");
  2936. }
  2937. }
  2938. exports.ProgressBar = ProgressBar;
  2939. function getActiveOrFocusedElement() {
  2940. let curRoot = document;
  2941. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2942. while (curActiveOrFocused?.shadowRoot) {
  2943. curRoot = curActiveOrFocused.shadowRoot;
  2944. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2945. }
  2946. return curActiveOrFocused;
  2947. }
  2948. function apiPageLayoutToViewerModes(layout) {
  2949. let scrollMode = ScrollMode.VERTICAL,
  2950. spreadMode = SpreadMode.NONE;
  2951. switch (layout) {
  2952. case "SinglePage":
  2953. scrollMode = ScrollMode.PAGE;
  2954. break;
  2955. case "OneColumn":
  2956. break;
  2957. case "TwoPageLeft":
  2958. scrollMode = ScrollMode.PAGE;
  2959. case "TwoColumnLeft":
  2960. spreadMode = SpreadMode.ODD;
  2961. break;
  2962. case "TwoPageRight":
  2963. scrollMode = ScrollMode.PAGE;
  2964. case "TwoColumnRight":
  2965. spreadMode = SpreadMode.EVEN;
  2966. break;
  2967. }
  2968. return {
  2969. scrollMode,
  2970. spreadMode
  2971. };
  2972. }
  2973. function apiPageModeToSidebarView(mode) {
  2974. switch (mode) {
  2975. case "UseNone":
  2976. return SidebarView.NONE;
  2977. case "UseThumbs":
  2978. return SidebarView.THUMBS;
  2979. case "UseOutlines":
  2980. return SidebarView.OUTLINE;
  2981. case "UseAttachments":
  2982. return SidebarView.ATTACHMENTS;
  2983. case "UseOC":
  2984. return SidebarView.LAYERS;
  2985. }
  2986. return SidebarView.NONE;
  2987. }
  2988. /***/ }),
  2989. /* 4 */
  2990. /***/ ((__unused_webpack_module, exports) => {
  2991. Object.defineProperty(exports, "__esModule", ({
  2992. value: true
  2993. }));
  2994. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  2995. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  2996. const WaitOnType = {
  2997. EVENT: "event",
  2998. TIMEOUT: "timeout"
  2999. };
  3000. exports.WaitOnType = WaitOnType;
  3001. function waitOnEventOrTimeout({
  3002. target,
  3003. name,
  3004. delay = 0
  3005. }) {
  3006. return new Promise(function (resolve, reject) {
  3007. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3008. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3009. }
  3010. function handler(type) {
  3011. if (target instanceof EventBus) {
  3012. target._off(name, eventHandler);
  3013. } else {
  3014. target.removeEventListener(name, eventHandler);
  3015. }
  3016. if (timeout) {
  3017. clearTimeout(timeout);
  3018. }
  3019. resolve(type);
  3020. }
  3021. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3022. if (target instanceof EventBus) {
  3023. target._on(name, eventHandler);
  3024. } else {
  3025. target.addEventListener(name, eventHandler);
  3026. }
  3027. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3028. const timeout = setTimeout(timeoutHandler, delay);
  3029. });
  3030. }
  3031. class EventBus {
  3032. constructor() {
  3033. this._listeners = Object.create(null);
  3034. }
  3035. on(eventName, listener, options = null) {
  3036. this._on(eventName, listener, {
  3037. external: true,
  3038. once: options?.once
  3039. });
  3040. }
  3041. off(eventName, listener, options = null) {
  3042. this._off(eventName, listener, {
  3043. external: true,
  3044. once: options?.once
  3045. });
  3046. }
  3047. dispatch(eventName, data) {
  3048. const eventListeners = this._listeners[eventName];
  3049. if (!eventListeners || eventListeners.length === 0) {
  3050. return;
  3051. }
  3052. let externalListeners;
  3053. for (const {
  3054. listener,
  3055. external,
  3056. once
  3057. } of eventListeners.slice(0)) {
  3058. if (once) {
  3059. this._off(eventName, listener);
  3060. }
  3061. if (external) {
  3062. (externalListeners ||= []).push(listener);
  3063. continue;
  3064. }
  3065. listener(data);
  3066. }
  3067. if (externalListeners) {
  3068. for (const listener of externalListeners) {
  3069. listener(data);
  3070. }
  3071. externalListeners = null;
  3072. }
  3073. }
  3074. _on(eventName, listener, options = null) {
  3075. const eventListeners = this._listeners[eventName] ||= [];
  3076. eventListeners.push({
  3077. listener,
  3078. external: options?.external === true,
  3079. once: options?.once === true
  3080. });
  3081. }
  3082. _off(eventName, listener, options = null) {
  3083. const eventListeners = this._listeners[eventName];
  3084. if (!eventListeners) {
  3085. return;
  3086. }
  3087. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3088. if (eventListeners[i].listener === listener) {
  3089. eventListeners.splice(i, 1);
  3090. return;
  3091. }
  3092. }
  3093. }
  3094. }
  3095. exports.EventBus = EventBus;
  3096. class AutomationEventBus extends EventBus {
  3097. dispatch(eventName, data) {
  3098. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3099. }
  3100. }
  3101. exports.AutomationEventBus = AutomationEventBus;
  3102. /***/ }),
  3103. /* 5 */
  3104. /***/ ((module) => {
  3105. let pdfjsLib;
  3106. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3107. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3108. } else {
  3109. pdfjsLib = require("../build/pdf.js");
  3110. }
  3111. module.exports = pdfjsLib;
  3112. /***/ }),
  3113. /* 6 */
  3114. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3115. Object.defineProperty(exports, "__esModule", ({
  3116. value: true
  3117. }));
  3118. exports.PDFCursorTools = exports.CursorTool = void 0;
  3119. var _grab_to_pan = __webpack_require__(7);
  3120. var _ui_utils = __webpack_require__(3);
  3121. const CursorTool = {
  3122. SELECT: 0,
  3123. HAND: 1,
  3124. ZOOM: 2
  3125. };
  3126. exports.CursorTool = CursorTool;
  3127. class PDFCursorTools {
  3128. constructor({
  3129. container,
  3130. eventBus,
  3131. cursorToolOnLoad = CursorTool.SELECT
  3132. }) {
  3133. this.container = container;
  3134. this.eventBus = eventBus;
  3135. this.active = CursorTool.SELECT;
  3136. this.activeBeforePresentationMode = null;
  3137. this.handTool = new _grab_to_pan.GrabToPan({
  3138. element: this.container
  3139. });
  3140. this.#addEventListeners();
  3141. Promise.resolve().then(() => {
  3142. this.switchTool(cursorToolOnLoad);
  3143. });
  3144. }
  3145. get activeTool() {
  3146. return this.active;
  3147. }
  3148. switchTool(tool) {
  3149. if (this.activeBeforePresentationMode !== null) {
  3150. return;
  3151. }
  3152. if (tool === this.active) {
  3153. return;
  3154. }
  3155. const disableActiveTool = () => {
  3156. switch (this.active) {
  3157. case CursorTool.SELECT:
  3158. break;
  3159. case CursorTool.HAND:
  3160. this.handTool.deactivate();
  3161. break;
  3162. case CursorTool.ZOOM:
  3163. }
  3164. };
  3165. switch (tool) {
  3166. case CursorTool.SELECT:
  3167. disableActiveTool();
  3168. break;
  3169. case CursorTool.HAND:
  3170. disableActiveTool();
  3171. this.handTool.activate();
  3172. break;
  3173. case CursorTool.ZOOM:
  3174. default:
  3175. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3176. return;
  3177. }
  3178. this.active = tool;
  3179. this.#dispatchEvent();
  3180. }
  3181. #dispatchEvent() {
  3182. this.eventBus.dispatch("cursortoolchanged", {
  3183. source: this,
  3184. tool: this.active
  3185. });
  3186. }
  3187. #addEventListeners() {
  3188. this.eventBus._on("switchcursortool", evt => {
  3189. this.switchTool(evt.tool);
  3190. });
  3191. this.eventBus._on("presentationmodechanged", evt => {
  3192. switch (evt.state) {
  3193. case _ui_utils.PresentationModeState.FULLSCREEN:
  3194. {
  3195. const previouslyActive = this.active;
  3196. this.switchTool(CursorTool.SELECT);
  3197. this.activeBeforePresentationMode = previouslyActive;
  3198. break;
  3199. }
  3200. case _ui_utils.PresentationModeState.NORMAL:
  3201. {
  3202. const previouslyActive = this.activeBeforePresentationMode;
  3203. this.activeBeforePresentationMode = null;
  3204. this.switchTool(previouslyActive);
  3205. break;
  3206. }
  3207. }
  3208. });
  3209. }
  3210. }
  3211. exports.PDFCursorTools = PDFCursorTools;
  3212. /***/ }),
  3213. /* 7 */
  3214. /***/ ((__unused_webpack_module, exports) => {
  3215. Object.defineProperty(exports, "__esModule", ({
  3216. value: true
  3217. }));
  3218. exports.GrabToPan = void 0;
  3219. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3220. class GrabToPan {
  3221. constructor(options) {
  3222. this.element = options.element;
  3223. this.document = options.element.ownerDocument;
  3224. if (typeof options.ignoreTarget === "function") {
  3225. this.ignoreTarget = options.ignoreTarget;
  3226. }
  3227. this.onActiveChanged = options.onActiveChanged;
  3228. this.activate = this.activate.bind(this);
  3229. this.deactivate = this.deactivate.bind(this);
  3230. this.toggle = this.toggle.bind(this);
  3231. this._onMouseDown = this.#onMouseDown.bind(this);
  3232. this._onMouseMove = this.#onMouseMove.bind(this);
  3233. this._endPan = this.#endPan.bind(this);
  3234. const overlay = this.overlay = document.createElement("div");
  3235. overlay.className = "grab-to-pan-grabbing";
  3236. }
  3237. activate() {
  3238. if (!this.active) {
  3239. this.active = true;
  3240. this.element.addEventListener("mousedown", this._onMouseDown, true);
  3241. this.element.classList.add(CSS_CLASS_GRAB);
  3242. this.onActiveChanged?.(true);
  3243. }
  3244. }
  3245. deactivate() {
  3246. if (this.active) {
  3247. this.active = false;
  3248. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  3249. this._endPan();
  3250. this.element.classList.remove(CSS_CLASS_GRAB);
  3251. this.onActiveChanged?.(false);
  3252. }
  3253. }
  3254. toggle() {
  3255. if (this.active) {
  3256. this.deactivate();
  3257. } else {
  3258. this.activate();
  3259. }
  3260. }
  3261. ignoreTarget(node) {
  3262. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3263. }
  3264. #onMouseDown(event) {
  3265. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3266. return;
  3267. }
  3268. if (event.originalTarget) {
  3269. try {
  3270. event.originalTarget.tagName;
  3271. } catch (e) {
  3272. return;
  3273. }
  3274. }
  3275. this.scrollLeftStart = this.element.scrollLeft;
  3276. this.scrollTopStart = this.element.scrollTop;
  3277. this.clientXStart = event.clientX;
  3278. this.clientYStart = event.clientY;
  3279. this.document.addEventListener("mousemove", this._onMouseMove, true);
  3280. this.document.addEventListener("mouseup", this._endPan, true);
  3281. this.element.addEventListener("scroll", this._endPan, true);
  3282. event.preventDefault();
  3283. event.stopPropagation();
  3284. const focusedElement = document.activeElement;
  3285. if (focusedElement && !focusedElement.contains(event.target)) {
  3286. focusedElement.blur();
  3287. }
  3288. }
  3289. #onMouseMove(event) {
  3290. this.element.removeEventListener("scroll", this._endPan, true);
  3291. if (!(event.buttons & 1)) {
  3292. this._endPan();
  3293. return;
  3294. }
  3295. const xDiff = event.clientX - this.clientXStart;
  3296. const yDiff = event.clientY - this.clientYStart;
  3297. const scrollTop = this.scrollTopStart - yDiff;
  3298. const scrollLeft = this.scrollLeftStart - xDiff;
  3299. if (this.element.scrollTo) {
  3300. this.element.scrollTo({
  3301. top: scrollTop,
  3302. left: scrollLeft,
  3303. behavior: "instant"
  3304. });
  3305. } else {
  3306. this.element.scrollTop = scrollTop;
  3307. this.element.scrollLeft = scrollLeft;
  3308. }
  3309. if (!this.overlay.parentNode) {
  3310. document.body.appendChild(this.overlay);
  3311. }
  3312. }
  3313. #endPan() {
  3314. this.element.removeEventListener("scroll", this._endPan, true);
  3315. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  3316. this.document.removeEventListener("mouseup", this._endPan, true);
  3317. this.overlay.remove();
  3318. }
  3319. }
  3320. exports.GrabToPan = GrabToPan;
  3321. /***/ }),
  3322. /* 8 */
  3323. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3324. Object.defineProperty(exports, "__esModule", ({
  3325. value: true
  3326. }));
  3327. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  3328. var _ui_utils = __webpack_require__(3);
  3329. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  3330. const LinkTarget = {
  3331. NONE: 0,
  3332. SELF: 1,
  3333. BLANK: 2,
  3334. PARENT: 3,
  3335. TOP: 4
  3336. };
  3337. exports.LinkTarget = LinkTarget;
  3338. function addLinkAttributes(link, {
  3339. url,
  3340. target,
  3341. rel,
  3342. enabled = true
  3343. } = {}) {
  3344. if (!url || typeof url !== "string") {
  3345. throw new Error('A valid "url" parameter must provided.');
  3346. }
  3347. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  3348. if (enabled) {
  3349. link.href = link.title = urlNullRemoved;
  3350. } else {
  3351. link.href = "";
  3352. link.title = `Disabled: ${urlNullRemoved}`;
  3353. link.onclick = () => {
  3354. return false;
  3355. };
  3356. }
  3357. let targetStr = "";
  3358. switch (target) {
  3359. case LinkTarget.NONE:
  3360. break;
  3361. case LinkTarget.SELF:
  3362. targetStr = "_self";
  3363. break;
  3364. case LinkTarget.BLANK:
  3365. targetStr = "_blank";
  3366. break;
  3367. case LinkTarget.PARENT:
  3368. targetStr = "_parent";
  3369. break;
  3370. case LinkTarget.TOP:
  3371. targetStr = "_top";
  3372. break;
  3373. }
  3374. link.target = targetStr;
  3375. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  3376. }
  3377. class PDFLinkService {
  3378. #pagesRefCache = new Map();
  3379. constructor({
  3380. eventBus,
  3381. externalLinkTarget = null,
  3382. externalLinkRel = null,
  3383. ignoreDestinationZoom = false
  3384. } = {}) {
  3385. this.eventBus = eventBus;
  3386. this.externalLinkTarget = externalLinkTarget;
  3387. this.externalLinkRel = externalLinkRel;
  3388. this.externalLinkEnabled = true;
  3389. this._ignoreDestinationZoom = ignoreDestinationZoom;
  3390. this.baseUrl = null;
  3391. this.pdfDocument = null;
  3392. this.pdfViewer = null;
  3393. this.pdfHistory = null;
  3394. }
  3395. setDocument(pdfDocument, baseUrl = null) {
  3396. this.baseUrl = baseUrl;
  3397. this.pdfDocument = pdfDocument;
  3398. this.#pagesRefCache.clear();
  3399. }
  3400. setViewer(pdfViewer) {
  3401. this.pdfViewer = pdfViewer;
  3402. }
  3403. setHistory(pdfHistory) {
  3404. this.pdfHistory = pdfHistory;
  3405. }
  3406. get pagesCount() {
  3407. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  3408. }
  3409. get page() {
  3410. return this.pdfViewer.currentPageNumber;
  3411. }
  3412. set page(value) {
  3413. this.pdfViewer.currentPageNumber = value;
  3414. }
  3415. get rotation() {
  3416. return this.pdfViewer.pagesRotation;
  3417. }
  3418. set rotation(value) {
  3419. this.pdfViewer.pagesRotation = value;
  3420. }
  3421. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  3422. const destRef = explicitDest[0];
  3423. let pageNumber;
  3424. if (typeof destRef === "object" && destRef !== null) {
  3425. pageNumber = this._cachedPageNumber(destRef);
  3426. if (!pageNumber) {
  3427. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  3428. this.cachePageRef(pageIndex + 1, destRef);
  3429. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  3430. }).catch(() => {
  3431. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  3432. });
  3433. return;
  3434. }
  3435. } else if (Number.isInteger(destRef)) {
  3436. pageNumber = destRef + 1;
  3437. } else {
  3438. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  3439. return;
  3440. }
  3441. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  3442. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  3443. return;
  3444. }
  3445. if (this.pdfHistory) {
  3446. this.pdfHistory.pushCurrentPosition();
  3447. this.pdfHistory.push({
  3448. namedDest,
  3449. explicitDest,
  3450. pageNumber
  3451. });
  3452. }
  3453. this.pdfViewer.scrollPageIntoView({
  3454. pageNumber,
  3455. destArray: explicitDest,
  3456. ignoreDestinationZoom: this._ignoreDestinationZoom
  3457. });
  3458. }
  3459. async goToDestination(dest) {
  3460. if (!this.pdfDocument) {
  3461. return;
  3462. }
  3463. let namedDest, explicitDest;
  3464. if (typeof dest === "string") {
  3465. namedDest = dest;
  3466. explicitDest = await this.pdfDocument.getDestination(dest);
  3467. } else {
  3468. namedDest = null;
  3469. explicitDest = await dest;
  3470. }
  3471. if (!Array.isArray(explicitDest)) {
  3472. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  3473. return;
  3474. }
  3475. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  3476. }
  3477. goToPage(val) {
  3478. if (!this.pdfDocument) {
  3479. return;
  3480. }
  3481. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  3482. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  3483. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  3484. return;
  3485. }
  3486. if (this.pdfHistory) {
  3487. this.pdfHistory.pushCurrentPosition();
  3488. this.pdfHistory.pushPage(pageNumber);
  3489. }
  3490. this.pdfViewer.scrollPageIntoView({
  3491. pageNumber
  3492. });
  3493. }
  3494. addLinkAttributes(link, url, newWindow = false) {
  3495. addLinkAttributes(link, {
  3496. url,
  3497. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  3498. rel: this.externalLinkRel,
  3499. enabled: this.externalLinkEnabled
  3500. });
  3501. }
  3502. getDestinationHash(dest) {
  3503. if (typeof dest === "string") {
  3504. if (dest.length > 0) {
  3505. return this.getAnchorUrl("#" + escape(dest));
  3506. }
  3507. } else if (Array.isArray(dest)) {
  3508. const str = JSON.stringify(dest);
  3509. if (str.length > 0) {
  3510. return this.getAnchorUrl("#" + escape(str));
  3511. }
  3512. }
  3513. return this.getAnchorUrl("");
  3514. }
  3515. getAnchorUrl(anchor) {
  3516. return (this.baseUrl || "") + anchor;
  3517. }
  3518. setHash(hash) {
  3519. if (!this.pdfDocument) {
  3520. return;
  3521. }
  3522. let pageNumber, dest;
  3523. if (hash.includes("=")) {
  3524. const params = (0, _ui_utils.parseQueryString)(hash);
  3525. if (params.has("search")) {
  3526. this.eventBus.dispatch("findfromurlhash", {
  3527. source: this,
  3528. query: params.get("search").replace(/"/g, ""),
  3529. phraseSearch: params.get("phrase") === "true"
  3530. });
  3531. }
  3532. if (params.has("page")) {
  3533. pageNumber = params.get("page") | 0 || 1;
  3534. }
  3535. if (params.has("zoom")) {
  3536. const zoomArgs = params.get("zoom").split(",");
  3537. const zoomArg = zoomArgs[0];
  3538. const zoomArgNumber = parseFloat(zoomArg);
  3539. if (!zoomArg.includes("Fit")) {
  3540. dest = [null, {
  3541. name: "XYZ"
  3542. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  3543. } else {
  3544. if (zoomArg === "Fit" || zoomArg === "FitB") {
  3545. dest = [null, {
  3546. name: zoomArg
  3547. }];
  3548. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  3549. dest = [null, {
  3550. name: zoomArg
  3551. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  3552. } else if (zoomArg === "FitR") {
  3553. if (zoomArgs.length !== 5) {
  3554. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  3555. } else {
  3556. dest = [null, {
  3557. name: zoomArg
  3558. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  3559. }
  3560. } else {
  3561. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  3562. }
  3563. }
  3564. }
  3565. if (dest) {
  3566. this.pdfViewer.scrollPageIntoView({
  3567. pageNumber: pageNumber || this.page,
  3568. destArray: dest,
  3569. allowNegativeOffset: true
  3570. });
  3571. } else if (pageNumber) {
  3572. this.page = pageNumber;
  3573. }
  3574. if (params.has("pagemode")) {
  3575. this.eventBus.dispatch("pagemode", {
  3576. source: this,
  3577. mode: params.get("pagemode")
  3578. });
  3579. }
  3580. if (params.has("nameddest")) {
  3581. this.goToDestination(params.get("nameddest"));
  3582. }
  3583. } else {
  3584. dest = unescape(hash);
  3585. try {
  3586. dest = JSON.parse(dest);
  3587. if (!Array.isArray(dest)) {
  3588. dest = dest.toString();
  3589. }
  3590. } catch (ex) {}
  3591. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  3592. this.goToDestination(dest);
  3593. return;
  3594. }
  3595. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  3596. }
  3597. }
  3598. executeNamedAction(action) {
  3599. switch (action) {
  3600. case "GoBack":
  3601. this.pdfHistory?.back();
  3602. break;
  3603. case "GoForward":
  3604. this.pdfHistory?.forward();
  3605. break;
  3606. case "NextPage":
  3607. this.pdfViewer.nextPage();
  3608. break;
  3609. case "PrevPage":
  3610. this.pdfViewer.previousPage();
  3611. break;
  3612. case "LastPage":
  3613. this.page = this.pagesCount;
  3614. break;
  3615. case "FirstPage":
  3616. this.page = 1;
  3617. break;
  3618. default:
  3619. break;
  3620. }
  3621. this.eventBus.dispatch("namedaction", {
  3622. source: this,
  3623. action
  3624. });
  3625. }
  3626. cachePageRef(pageNum, pageRef) {
  3627. if (!pageRef) {
  3628. return;
  3629. }
  3630. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3631. this.#pagesRefCache.set(refStr, pageNum);
  3632. }
  3633. _cachedPageNumber(pageRef) {
  3634. if (!pageRef) {
  3635. return null;
  3636. }
  3637. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3638. return this.#pagesRefCache.get(refStr) || null;
  3639. }
  3640. isPageVisible(pageNumber) {
  3641. return this.pdfViewer.isPageVisible(pageNumber);
  3642. }
  3643. isPageCached(pageNumber) {
  3644. return this.pdfViewer.isPageCached(pageNumber);
  3645. }
  3646. static #isValidExplicitDestination(dest) {
  3647. if (!Array.isArray(dest)) {
  3648. return false;
  3649. }
  3650. const destLength = dest.length;
  3651. if (destLength < 2) {
  3652. return false;
  3653. }
  3654. const page = dest[0];
  3655. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  3656. return false;
  3657. }
  3658. const zoom = dest[1];
  3659. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  3660. return false;
  3661. }
  3662. let allowNull = true;
  3663. switch (zoom.name) {
  3664. case "XYZ":
  3665. if (destLength !== 5) {
  3666. return false;
  3667. }
  3668. break;
  3669. case "Fit":
  3670. case "FitB":
  3671. return destLength === 2;
  3672. case "FitH":
  3673. case "FitBH":
  3674. case "FitV":
  3675. case "FitBV":
  3676. if (destLength !== 3) {
  3677. return false;
  3678. }
  3679. break;
  3680. case "FitR":
  3681. if (destLength !== 6) {
  3682. return false;
  3683. }
  3684. allowNull = false;
  3685. break;
  3686. default:
  3687. return false;
  3688. }
  3689. for (let i = 2; i < destLength; i++) {
  3690. const param = dest[i];
  3691. if (!(typeof param === "number" || allowNull && param === null)) {
  3692. return false;
  3693. }
  3694. }
  3695. return true;
  3696. }
  3697. }
  3698. exports.PDFLinkService = PDFLinkService;
  3699. class SimpleLinkService {
  3700. constructor() {
  3701. this.externalLinkEnabled = true;
  3702. }
  3703. get pagesCount() {
  3704. return 0;
  3705. }
  3706. get page() {
  3707. return 0;
  3708. }
  3709. set page(value) {}
  3710. get rotation() {
  3711. return 0;
  3712. }
  3713. set rotation(value) {}
  3714. async goToDestination(dest) {}
  3715. goToPage(val) {}
  3716. addLinkAttributes(link, url, newWindow = false) {
  3717. addLinkAttributes(link, {
  3718. url,
  3719. enabled: this.externalLinkEnabled
  3720. });
  3721. }
  3722. getDestinationHash(dest) {
  3723. return "#";
  3724. }
  3725. getAnchorUrl(hash) {
  3726. return "#";
  3727. }
  3728. setHash(hash) {}
  3729. executeNamedAction(action) {}
  3730. cachePageRef(pageNum, pageRef) {}
  3731. isPageVisible(pageNumber) {
  3732. return true;
  3733. }
  3734. isPageCached(pageNumber) {
  3735. return true;
  3736. }
  3737. }
  3738. exports.SimpleLinkService = SimpleLinkService;
  3739. /***/ }),
  3740. /* 9 */
  3741. /***/ ((__unused_webpack_module, exports) => {
  3742. Object.defineProperty(exports, "__esModule", ({
  3743. value: true
  3744. }));
  3745. exports.OverlayManager = void 0;
  3746. class OverlayManager {
  3747. #overlays = new WeakMap();
  3748. #active = null;
  3749. get active() {
  3750. return this.#active;
  3751. }
  3752. async register(dialog, canForceClose = false) {
  3753. if (typeof dialog !== "object") {
  3754. throw new Error("Not enough parameters.");
  3755. } else if (this.#overlays.has(dialog)) {
  3756. throw new Error("The overlay is already registered.");
  3757. }
  3758. this.#overlays.set(dialog, {
  3759. canForceClose
  3760. });
  3761. dialog.addEventListener("cancel", evt => {
  3762. this.#active = null;
  3763. });
  3764. }
  3765. async unregister(dialog) {
  3766. if (!this.#overlays.has(dialog)) {
  3767. throw new Error("The overlay does not exist.");
  3768. } else if (this.#active === dialog) {
  3769. throw new Error("The overlay cannot be removed while it is active.");
  3770. }
  3771. this.#overlays.delete(dialog);
  3772. }
  3773. async open(dialog) {
  3774. if (!this.#overlays.has(dialog)) {
  3775. throw new Error("The overlay does not exist.");
  3776. } else if (this.#active) {
  3777. if (this.#active === dialog) {
  3778. throw new Error("The overlay is already active.");
  3779. } else if (this.#overlays.get(dialog).canForceClose) {
  3780. await this.close();
  3781. } else {
  3782. throw new Error("Another overlay is currently active.");
  3783. }
  3784. }
  3785. this.#active = dialog;
  3786. dialog.showModal();
  3787. }
  3788. async close(dialog = this.#active) {
  3789. if (!this.#overlays.has(dialog)) {
  3790. throw new Error("The overlay does not exist.");
  3791. } else if (!this.#active) {
  3792. throw new Error("The overlay is currently not active.");
  3793. } else if (this.#active !== dialog) {
  3794. throw new Error("Another overlay is currently active.");
  3795. }
  3796. dialog.close();
  3797. this.#active = null;
  3798. }
  3799. }
  3800. exports.OverlayManager = OverlayManager;
  3801. /***/ }),
  3802. /* 10 */
  3803. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3804. Object.defineProperty(exports, "__esModule", ({
  3805. value: true
  3806. }));
  3807. exports.PasswordPrompt = void 0;
  3808. var _pdfjsLib = __webpack_require__(5);
  3809. class PasswordPrompt {
  3810. #updateCallback = null;
  3811. #reason = null;
  3812. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3813. this.dialog = options.dialog;
  3814. this.label = options.label;
  3815. this.input = options.input;
  3816. this.submitButton = options.submitButton;
  3817. this.cancelButton = options.cancelButton;
  3818. this.overlayManager = overlayManager;
  3819. this.l10n = l10n;
  3820. this._isViewerEmbedded = isViewerEmbedded;
  3821. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3822. this.cancelButton.addEventListener("click", this.#cancel.bind(this));
  3823. this.input.addEventListener("keydown", e => {
  3824. if (e.keyCode === 13) {
  3825. this.#verify();
  3826. }
  3827. });
  3828. this.overlayManager.register(this.dialog, true);
  3829. this.dialog.addEventListener("close", this.#cancel.bind(this));
  3830. }
  3831. async open() {
  3832. await this.overlayManager.open(this.dialog);
  3833. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3834. if (!this._isViewerEmbedded || passwordIncorrect) {
  3835. this.input.focus();
  3836. }
  3837. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3838. }
  3839. async close() {
  3840. if (this.overlayManager.active === this.dialog) {
  3841. this.overlayManager.close(this.dialog);
  3842. }
  3843. }
  3844. #verify() {
  3845. const password = this.input.value;
  3846. if (password?.length > 0) {
  3847. this.#invokeCallback(password);
  3848. }
  3849. }
  3850. #cancel() {
  3851. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  3852. }
  3853. #invokeCallback(password) {
  3854. if (!this.#updateCallback) {
  3855. return;
  3856. }
  3857. this.close();
  3858. this.input.value = "";
  3859. this.#updateCallback(password);
  3860. this.#updateCallback = null;
  3861. }
  3862. setUpdateCallback(updateCallback, reason) {
  3863. this.#updateCallback = updateCallback;
  3864. this.#reason = reason;
  3865. }
  3866. }
  3867. exports.PasswordPrompt = PasswordPrompt;
  3868. /***/ }),
  3869. /* 11 */
  3870. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3871. Object.defineProperty(exports, "__esModule", ({
  3872. value: true
  3873. }));
  3874. exports.PDFAttachmentViewer = void 0;
  3875. var _pdfjsLib = __webpack_require__(5);
  3876. var _base_tree_viewer = __webpack_require__(12);
  3877. var _event_utils = __webpack_require__(4);
  3878. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  3879. constructor(options) {
  3880. super(options);
  3881. this.downloadManager = options.downloadManager;
  3882. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  3883. }
  3884. reset(keepRenderedCapability = false) {
  3885. super.reset();
  3886. this._attachments = null;
  3887. if (!keepRenderedCapability) {
  3888. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  3889. }
  3890. this._pendingDispatchEvent = false;
  3891. }
  3892. async _dispatchEvent(attachmentsCount) {
  3893. this._renderedCapability.resolve();
  3894. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  3895. this._pendingDispatchEvent = true;
  3896. await (0, _event_utils.waitOnEventOrTimeout)({
  3897. target: this.eventBus,
  3898. name: "annotationlayerrendered",
  3899. delay: 1000
  3900. });
  3901. if (!this._pendingDispatchEvent) {
  3902. return;
  3903. }
  3904. }
  3905. this._pendingDispatchEvent = false;
  3906. this.eventBus.dispatch("attachmentsloaded", {
  3907. source: this,
  3908. attachmentsCount
  3909. });
  3910. }
  3911. _bindLink(element, {
  3912. content,
  3913. filename
  3914. }) {
  3915. element.onclick = () => {
  3916. this.downloadManager.openOrDownloadData(element, content, filename);
  3917. return false;
  3918. };
  3919. }
  3920. render({
  3921. attachments,
  3922. keepRenderedCapability = false
  3923. }) {
  3924. if (this._attachments) {
  3925. this.reset(keepRenderedCapability);
  3926. }
  3927. this._attachments = attachments || null;
  3928. if (!attachments) {
  3929. this._dispatchEvent(0);
  3930. return;
  3931. }
  3932. const names = Object.keys(attachments).sort(function (a, b) {
  3933. return a.toLowerCase().localeCompare(b.toLowerCase());
  3934. });
  3935. const fragment = document.createDocumentFragment();
  3936. let attachmentsCount = 0;
  3937. for (const name of names) {
  3938. const item = attachments[name];
  3939. const content = item.content,
  3940. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  3941. const div = document.createElement("div");
  3942. div.className = "treeItem";
  3943. const element = document.createElement("a");
  3944. this._bindLink(element, {
  3945. content,
  3946. filename
  3947. });
  3948. element.textContent = this._normalizeTextContent(filename);
  3949. div.appendChild(element);
  3950. fragment.appendChild(div);
  3951. attachmentsCount++;
  3952. }
  3953. this._finishRendering(fragment, attachmentsCount);
  3954. }
  3955. #appendAttachment({
  3956. filename,
  3957. content
  3958. }) {
  3959. const renderedPromise = this._renderedCapability.promise;
  3960. renderedPromise.then(() => {
  3961. if (renderedPromise !== this._renderedCapability.promise) {
  3962. return;
  3963. }
  3964. const attachments = this._attachments || Object.create(null);
  3965. for (const name in attachments) {
  3966. if (filename === name) {
  3967. return;
  3968. }
  3969. }
  3970. attachments[filename] = {
  3971. filename,
  3972. content
  3973. };
  3974. this.render({
  3975. attachments,
  3976. keepRenderedCapability: true
  3977. });
  3978. });
  3979. }
  3980. }
  3981. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  3982. /***/ }),
  3983. /* 12 */
  3984. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3985. Object.defineProperty(exports, "__esModule", ({
  3986. value: true
  3987. }));
  3988. exports.BaseTreeViewer = void 0;
  3989. var _ui_utils = __webpack_require__(3);
  3990. const TREEITEM_OFFSET_TOP = -100;
  3991. const TREEITEM_SELECTED_CLASS = "selected";
  3992. class BaseTreeViewer {
  3993. constructor(options) {
  3994. if (this.constructor === BaseTreeViewer) {
  3995. throw new Error("Cannot initialize BaseTreeViewer.");
  3996. }
  3997. this.container = options.container;
  3998. this.eventBus = options.eventBus;
  3999. this.reset();
  4000. }
  4001. reset() {
  4002. this._pdfDocument = null;
  4003. this._lastToggleIsShow = true;
  4004. this._currentTreeItem = null;
  4005. this.container.textContent = "";
  4006. this.container.classList.remove("treeWithDeepNesting");
  4007. }
  4008. _dispatchEvent(count) {
  4009. throw new Error("Not implemented: _dispatchEvent");
  4010. }
  4011. _bindLink(element, params) {
  4012. throw new Error("Not implemented: _bindLink");
  4013. }
  4014. _normalizeTextContent(str) {
  4015. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4016. }
  4017. _addToggleButton(div, hidden = false) {
  4018. const toggler = document.createElement("div");
  4019. toggler.className = "treeItemToggler";
  4020. if (hidden) {
  4021. toggler.classList.add("treeItemsHidden");
  4022. }
  4023. toggler.onclick = evt => {
  4024. evt.stopPropagation();
  4025. toggler.classList.toggle("treeItemsHidden");
  4026. if (evt.shiftKey) {
  4027. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4028. this._toggleTreeItem(div, shouldShowAll);
  4029. }
  4030. };
  4031. div.insertBefore(toggler, div.firstChild);
  4032. }
  4033. _toggleTreeItem(root, show = false) {
  4034. this._lastToggleIsShow = show;
  4035. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4036. toggler.classList.toggle("treeItemsHidden", !show);
  4037. }
  4038. }
  4039. _toggleAllTreeItems() {
  4040. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4041. }
  4042. _finishRendering(fragment, count, hasAnyNesting = false) {
  4043. if (hasAnyNesting) {
  4044. this.container.classList.add("treeWithDeepNesting");
  4045. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4046. }
  4047. this.container.appendChild(fragment);
  4048. this._dispatchEvent(count);
  4049. }
  4050. render(params) {
  4051. throw new Error("Not implemented: render");
  4052. }
  4053. _updateCurrentTreeItem(treeItem = null) {
  4054. if (this._currentTreeItem) {
  4055. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4056. this._currentTreeItem = null;
  4057. }
  4058. if (treeItem) {
  4059. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4060. this._currentTreeItem = treeItem;
  4061. }
  4062. }
  4063. _scrollToCurrentTreeItem(treeItem) {
  4064. if (!treeItem) {
  4065. return;
  4066. }
  4067. let currentNode = treeItem.parentNode;
  4068. while (currentNode && currentNode !== this.container) {
  4069. if (currentNode.classList.contains("treeItem")) {
  4070. const toggler = currentNode.firstElementChild;
  4071. toggler?.classList.remove("treeItemsHidden");
  4072. }
  4073. currentNode = currentNode.parentNode;
  4074. }
  4075. this._updateCurrentTreeItem(treeItem);
  4076. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4077. }
  4078. }
  4079. exports.BaseTreeViewer = BaseTreeViewer;
  4080. /***/ }),
  4081. /* 13 */
  4082. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4083. Object.defineProperty(exports, "__esModule", ({
  4084. value: true
  4085. }));
  4086. exports.PDFDocumentProperties = void 0;
  4087. var _pdfjsLib = __webpack_require__(5);
  4088. var _ui_utils = __webpack_require__(3);
  4089. const DEFAULT_FIELD_CONTENT = "-";
  4090. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4091. const US_PAGE_NAMES = {
  4092. "8.5x11": "Letter",
  4093. "8.5x14": "Legal"
  4094. };
  4095. const METRIC_PAGE_NAMES = {
  4096. "297x420": "A3",
  4097. "210x297": "A4"
  4098. };
  4099. function getPageName(size, isPortrait, pageNames) {
  4100. const width = isPortrait ? size.width : size.height;
  4101. const height = isPortrait ? size.height : size.width;
  4102. return pageNames[`${width}x${height}`];
  4103. }
  4104. class PDFDocumentProperties {
  4105. #fieldData = null;
  4106. constructor({
  4107. dialog,
  4108. fields,
  4109. closeButton
  4110. }, overlayManager, eventBus, l10n) {
  4111. this.dialog = dialog;
  4112. this.fields = fields;
  4113. this.overlayManager = overlayManager;
  4114. this.l10n = l10n;
  4115. this.#reset();
  4116. closeButton.addEventListener("click", this.close.bind(this));
  4117. this.overlayManager.register(this.dialog);
  4118. eventBus._on("pagechanging", evt => {
  4119. this._currentPageNumber = evt.pageNumber;
  4120. });
  4121. eventBus._on("rotationchanging", evt => {
  4122. this._pagesRotation = evt.pagesRotation;
  4123. });
  4124. this._isNonMetricLocale = true;
  4125. l10n.getLanguage().then(locale => {
  4126. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4127. });
  4128. }
  4129. async open() {
  4130. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4131. const currentPageNumber = this._currentPageNumber;
  4132. const pagesRotation = this._pagesRotation;
  4133. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4134. this.#updateUI();
  4135. return;
  4136. }
  4137. const {
  4138. info,
  4139. contentDispositionFilename,
  4140. contentLength
  4141. } = await this.pdfDocument.getMetadata();
  4142. const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url), this.#parseFileSize(contentLength), this.#parseDate(info.CreationDate), this.#parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
  4143. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4144. }), this.#parseLinearization(info.IsLinearized)]);
  4145. this.#fieldData = Object.freeze({
  4146. fileName,
  4147. fileSize,
  4148. title: info.Title,
  4149. author: info.Author,
  4150. subject: info.Subject,
  4151. keywords: info.Keywords,
  4152. creationDate,
  4153. modificationDate,
  4154. creator: info.Creator,
  4155. producer: info.Producer,
  4156. version: info.PDFFormatVersion,
  4157. pageCount: this.pdfDocument.numPages,
  4158. pageSize,
  4159. linearized: isLinearized,
  4160. _currentPageNumber: currentPageNumber,
  4161. _pagesRotation: pagesRotation
  4162. });
  4163. this.#updateUI();
  4164. const {
  4165. length
  4166. } = await this.pdfDocument.getDownloadInfo();
  4167. if (contentLength === length) {
  4168. return;
  4169. }
  4170. const data = Object.assign(Object.create(null), this.#fieldData);
  4171. data.fileSize = await this.#parseFileSize(length);
  4172. this.#fieldData = Object.freeze(data);
  4173. this.#updateUI();
  4174. }
  4175. async close() {
  4176. this.overlayManager.close(this.dialog);
  4177. }
  4178. setDocument(pdfDocument, url = null) {
  4179. if (this.pdfDocument) {
  4180. this.#reset();
  4181. this.#updateUI(true);
  4182. }
  4183. if (!pdfDocument) {
  4184. return;
  4185. }
  4186. this.pdfDocument = pdfDocument;
  4187. this.url = url;
  4188. this._dataAvailableCapability.resolve();
  4189. }
  4190. #reset() {
  4191. this.pdfDocument = null;
  4192. this.url = null;
  4193. this.#fieldData = null;
  4194. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4195. this._currentPageNumber = 1;
  4196. this._pagesRotation = 0;
  4197. }
  4198. #updateUI(reset = false) {
  4199. if (reset || !this.#fieldData) {
  4200. for (const id in this.fields) {
  4201. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4202. }
  4203. return;
  4204. }
  4205. if (this.overlayManager.active !== this.dialog) {
  4206. return;
  4207. }
  4208. for (const id in this.fields) {
  4209. const content = this.#fieldData[id];
  4210. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4211. }
  4212. }
  4213. async #parseFileSize(fileSize = 0) {
  4214. const kb = fileSize / 1024,
  4215. mb = kb / 1024;
  4216. if (!kb) {
  4217. return undefined;
  4218. }
  4219. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4220. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4221. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4222. size_b: fileSize.toLocaleString()
  4223. });
  4224. }
  4225. async #parsePageSize(pageSizeInches, pagesRotation) {
  4226. if (!pageSizeInches) {
  4227. return undefined;
  4228. }
  4229. if (pagesRotation % 180 !== 0) {
  4230. pageSizeInches = {
  4231. width: pageSizeInches.height,
  4232. height: pageSizeInches.width
  4233. };
  4234. }
  4235. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4236. let sizeInches = {
  4237. width: Math.round(pageSizeInches.width * 100) / 100,
  4238. height: Math.round(pageSizeInches.height * 100) / 100
  4239. };
  4240. let sizeMillimeters = {
  4241. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4242. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4243. };
  4244. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4245. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4246. const exactMillimeters = {
  4247. width: pageSizeInches.width * 25.4,
  4248. height: pageSizeInches.height * 25.4
  4249. };
  4250. const intMillimeters = {
  4251. width: Math.round(sizeMillimeters.width),
  4252. height: Math.round(sizeMillimeters.height)
  4253. };
  4254. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4255. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4256. if (rawName) {
  4257. sizeInches = {
  4258. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4259. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4260. };
  4261. sizeMillimeters = intMillimeters;
  4262. }
  4263. }
  4264. }
  4265. const [{
  4266. width,
  4267. height
  4268. }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`document_properties_page_size_unit_${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`), this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`)]);
  4269. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4270. width: width.toLocaleString(),
  4271. height: height.toLocaleString(),
  4272. unit,
  4273. name,
  4274. orientation
  4275. });
  4276. }
  4277. async #parseDate(inputDate) {
  4278. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4279. if (!dateObject) {
  4280. return undefined;
  4281. }
  4282. return this.l10n.get("document_properties_date_string", {
  4283. date: dateObject.toLocaleDateString(),
  4284. time: dateObject.toLocaleTimeString()
  4285. });
  4286. }
  4287. #parseLinearization(isLinearized) {
  4288. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4289. }
  4290. }
  4291. exports.PDFDocumentProperties = PDFDocumentProperties;
  4292. /***/ }),
  4293. /* 14 */
  4294. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4295. Object.defineProperty(exports, "__esModule", ({
  4296. value: true
  4297. }));
  4298. exports.PDFFindBar = void 0;
  4299. var _pdf_find_controller = __webpack_require__(15);
  4300. const MATCHES_COUNT_LIMIT = 1000;
  4301. class PDFFindBar {
  4302. constructor(options, eventBus, l10n) {
  4303. this.opened = false;
  4304. this.bar = options.bar;
  4305. this.toggleButton = options.toggleButton;
  4306. this.findField = options.findField;
  4307. this.highlightAll = options.highlightAllCheckbox;
  4308. this.caseSensitive = options.caseSensitiveCheckbox;
  4309. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4310. this.entireWord = options.entireWordCheckbox;
  4311. this.findMsg = options.findMsg;
  4312. this.findResultsCount = options.findResultsCount;
  4313. this.findPreviousButton = options.findPreviousButton;
  4314. this.findNextButton = options.findNextButton;
  4315. this.eventBus = eventBus;
  4316. this.l10n = l10n;
  4317. this.toggleButton.addEventListener("click", () => {
  4318. this.toggle();
  4319. });
  4320. this.findField.addEventListener("input", () => {
  4321. this.dispatchEvent("");
  4322. });
  4323. this.bar.addEventListener("keydown", e => {
  4324. switch (e.keyCode) {
  4325. case 13:
  4326. if (e.target === this.findField) {
  4327. this.dispatchEvent("again", e.shiftKey);
  4328. }
  4329. break;
  4330. case 27:
  4331. this.close();
  4332. break;
  4333. }
  4334. });
  4335. this.findPreviousButton.addEventListener("click", () => {
  4336. this.dispatchEvent("again", true);
  4337. });
  4338. this.findNextButton.addEventListener("click", () => {
  4339. this.dispatchEvent("again", false);
  4340. });
  4341. this.highlightAll.addEventListener("click", () => {
  4342. this.dispatchEvent("highlightallchange");
  4343. });
  4344. this.caseSensitive.addEventListener("click", () => {
  4345. this.dispatchEvent("casesensitivitychange");
  4346. });
  4347. this.entireWord.addEventListener("click", () => {
  4348. this.dispatchEvent("entirewordchange");
  4349. });
  4350. this.matchDiacritics.addEventListener("click", () => {
  4351. this.dispatchEvent("diacriticmatchingchange");
  4352. });
  4353. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4354. }
  4355. reset() {
  4356. this.updateUIState();
  4357. }
  4358. dispatchEvent(type, findPrev = false) {
  4359. this.eventBus.dispatch("find", {
  4360. source: this,
  4361. type,
  4362. query: this.findField.value,
  4363. phraseSearch: true,
  4364. caseSensitive: this.caseSensitive.checked,
  4365. entireWord: this.entireWord.checked,
  4366. highlightAll: this.highlightAll.checked,
  4367. findPrevious: findPrev,
  4368. matchDiacritics: this.matchDiacritics.checked
  4369. });
  4370. }
  4371. updateUIState(state, previous, matchesCount) {
  4372. let findMsg = Promise.resolve("");
  4373. let status = "";
  4374. switch (state) {
  4375. case _pdf_find_controller.FindState.FOUND:
  4376. break;
  4377. case _pdf_find_controller.FindState.PENDING:
  4378. status = "pending";
  4379. break;
  4380. case _pdf_find_controller.FindState.NOT_FOUND:
  4381. findMsg = this.l10n.get("find_not_found");
  4382. status = "notFound";
  4383. break;
  4384. case _pdf_find_controller.FindState.WRAPPED:
  4385. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4386. break;
  4387. }
  4388. this.findField.setAttribute("data-status", status);
  4389. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4390. findMsg.then(msg => {
  4391. this.findMsg.textContent = msg;
  4392. this.#adjustWidth();
  4393. });
  4394. this.updateResultsCount(matchesCount);
  4395. }
  4396. updateResultsCount({
  4397. current = 0,
  4398. total = 0
  4399. } = {}) {
  4400. const limit = MATCHES_COUNT_LIMIT;
  4401. let matchCountMsg = Promise.resolve("");
  4402. if (total > 0) {
  4403. if (total > limit) {
  4404. let key = "find_match_count_limit";
  4405. matchCountMsg = this.l10n.get(key, {
  4406. limit
  4407. });
  4408. } else {
  4409. let key = "find_match_count";
  4410. matchCountMsg = this.l10n.get(key, {
  4411. current,
  4412. total
  4413. });
  4414. }
  4415. }
  4416. matchCountMsg.then(msg => {
  4417. this.findResultsCount.textContent = msg;
  4418. this.#adjustWidth();
  4419. });
  4420. }
  4421. open() {
  4422. if (!this.opened) {
  4423. this.opened = true;
  4424. this.toggleButton.classList.add("toggled");
  4425. this.toggleButton.setAttribute("aria-expanded", "true");
  4426. this.bar.classList.remove("hidden");
  4427. }
  4428. this.findField.select();
  4429. this.findField.focus();
  4430. this.#adjustWidth();
  4431. }
  4432. close() {
  4433. if (!this.opened) {
  4434. return;
  4435. }
  4436. this.opened = false;
  4437. this.toggleButton.classList.remove("toggled");
  4438. this.toggleButton.setAttribute("aria-expanded", "false");
  4439. this.bar.classList.add("hidden");
  4440. this.eventBus.dispatch("findbarclose", {
  4441. source: this
  4442. });
  4443. }
  4444. toggle() {
  4445. if (this.opened) {
  4446. this.close();
  4447. } else {
  4448. this.open();
  4449. }
  4450. }
  4451. #adjustWidth() {
  4452. if (!this.opened) {
  4453. return;
  4454. }
  4455. this.bar.classList.remove("wrapContainers");
  4456. const findbarHeight = this.bar.clientHeight;
  4457. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4458. if (findbarHeight > inputContainerHeight) {
  4459. this.bar.classList.add("wrapContainers");
  4460. }
  4461. }
  4462. }
  4463. exports.PDFFindBar = PDFFindBar;
  4464. /***/ }),
  4465. /* 15 */
  4466. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4467. Object.defineProperty(exports, "__esModule", ({
  4468. value: true
  4469. }));
  4470. exports.PDFFindController = exports.FindState = void 0;
  4471. var _ui_utils = __webpack_require__(3);
  4472. var _pdfjsLib = __webpack_require__(5);
  4473. var _pdf_find_utils = __webpack_require__(16);
  4474. const FindState = {
  4475. FOUND: 0,
  4476. NOT_FOUND: 1,
  4477. WRAPPED: 2,
  4478. PENDING: 3
  4479. };
  4480. exports.FindState = FindState;
  4481. const FIND_TIMEOUT = 250;
  4482. const MATCH_SCROLL_OFFSET_TOP = -50;
  4483. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4484. const CHARACTERS_TO_NORMALIZE = {
  4485. "\u2010": "-",
  4486. "\u2018": "'",
  4487. "\u2019": "'",
  4488. "\u201A": "'",
  4489. "\u201B": "'",
  4490. "\u201C": '"',
  4491. "\u201D": '"',
  4492. "\u201E": '"',
  4493. "\u201F": '"',
  4494. "\u00BC": "1/4",
  4495. "\u00BD": "1/2",
  4496. "\u00BE": "3/4"
  4497. };
  4498. 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]);
  4499. const DIACRITICS_EXCEPTION_STR = [...DIACRITICS_EXCEPTION.values()].map(x => String.fromCharCode(x)).join("");
  4500. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4501. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4502. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4503. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4504. let normalizationRegex = null;
  4505. function normalize(text) {
  4506. if (!normalizationRegex) {
  4507. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4508. normalizationRegex = new RegExp(`([${replace}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(\\n)`, "gum");
  4509. }
  4510. const rawDiacriticsPositions = [];
  4511. let m;
  4512. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4513. rawDiacriticsPositions.push([m[0].length, m.index]);
  4514. }
  4515. let normalized = text.normalize("NFD");
  4516. const positions = [[0, 0]];
  4517. let k = 0;
  4518. let shift = 0;
  4519. let shiftOrigin = 0;
  4520. let eol = 0;
  4521. let hasDiacritics = false;
  4522. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, i) => {
  4523. i -= shiftOrigin;
  4524. if (p1) {
  4525. const replacement = CHARACTERS_TO_NORMALIZE[match];
  4526. const jj = replacement.length;
  4527. for (let j = 1; j < jj; j++) {
  4528. positions.push([i - shift + j, shift - j]);
  4529. }
  4530. shift -= jj - 1;
  4531. return replacement;
  4532. }
  4533. if (p2) {
  4534. const hasTrailingDashEOL = p2.endsWith("\n");
  4535. const len = hasTrailingDashEOL ? p2.length - 2 : p2.length;
  4536. hasDiacritics = true;
  4537. let jj = len;
  4538. if (i + eol === rawDiacriticsPositions[k]?.[1]) {
  4539. jj -= rawDiacriticsPositions[k][0];
  4540. ++k;
  4541. }
  4542. for (let j = 1; j < jj + 1; j++) {
  4543. positions.push([i - 1 - shift + j, shift - j]);
  4544. }
  4545. shift -= jj;
  4546. shiftOrigin += jj;
  4547. if (hasTrailingDashEOL) {
  4548. i += len - 1;
  4549. positions.push([i - shift + 1, 1 + shift]);
  4550. shift += 1;
  4551. shiftOrigin += 1;
  4552. eol += 1;
  4553. return p2.slice(0, len);
  4554. }
  4555. return p2;
  4556. }
  4557. if (p3) {
  4558. positions.push([i - shift + 1, 1 + shift]);
  4559. shift += 1;
  4560. shiftOrigin += 1;
  4561. eol += 1;
  4562. return p3.charAt(0);
  4563. }
  4564. positions.push([i - shift + 1, shift - 1]);
  4565. shift -= 1;
  4566. shiftOrigin += 1;
  4567. eol += 1;
  4568. return " ";
  4569. });
  4570. positions.push([normalized.length, shift]);
  4571. return [normalized, positions, hasDiacritics];
  4572. }
  4573. function getOriginalIndex(diffs, pos, len) {
  4574. if (!diffs) {
  4575. return [pos, len];
  4576. }
  4577. const start = pos;
  4578. const end = pos + len;
  4579. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  4580. if (diffs[i][0] > start) {
  4581. --i;
  4582. }
  4583. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  4584. if (diffs[j][0] > end) {
  4585. --j;
  4586. }
  4587. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  4588. }
  4589. class PDFFindController {
  4590. constructor({
  4591. linkService,
  4592. eventBus
  4593. }) {
  4594. this._linkService = linkService;
  4595. this._eventBus = eventBus;
  4596. this.#reset();
  4597. eventBus._on("find", this.#onFind.bind(this));
  4598. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  4599. }
  4600. get highlightMatches() {
  4601. return this._highlightMatches;
  4602. }
  4603. get pageMatches() {
  4604. return this._pageMatches;
  4605. }
  4606. get pageMatchesLength() {
  4607. return this._pageMatchesLength;
  4608. }
  4609. get selected() {
  4610. return this._selected;
  4611. }
  4612. get state() {
  4613. return this._state;
  4614. }
  4615. setDocument(pdfDocument) {
  4616. if (this._pdfDocument) {
  4617. this.#reset();
  4618. }
  4619. if (!pdfDocument) {
  4620. return;
  4621. }
  4622. this._pdfDocument = pdfDocument;
  4623. this._firstPageCapability.resolve();
  4624. }
  4625. #onFind(state) {
  4626. if (!state) {
  4627. return;
  4628. }
  4629. const pdfDocument = this._pdfDocument;
  4630. const {
  4631. type
  4632. } = state;
  4633. if (this._state === null || this.#shouldDirtyMatch(state)) {
  4634. this._dirtyMatch = true;
  4635. }
  4636. this._state = state;
  4637. if (type !== "highlightallchange") {
  4638. this.#updateUIState(FindState.PENDING);
  4639. }
  4640. this._firstPageCapability.promise.then(() => {
  4641. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4642. return;
  4643. }
  4644. this.#extractText();
  4645. const findbarClosed = !this._highlightMatches;
  4646. const pendingTimeout = !!this._findTimeout;
  4647. if (this._findTimeout) {
  4648. clearTimeout(this._findTimeout);
  4649. this._findTimeout = null;
  4650. }
  4651. if (!type) {
  4652. this._findTimeout = setTimeout(() => {
  4653. this.#nextMatch();
  4654. this._findTimeout = null;
  4655. }, FIND_TIMEOUT);
  4656. } else if (this._dirtyMatch) {
  4657. this.#nextMatch();
  4658. } else if (type === "again") {
  4659. this.#nextMatch();
  4660. if (findbarClosed && this._state.highlightAll) {
  4661. this.#updateAllPages();
  4662. }
  4663. } else if (type === "highlightallchange") {
  4664. if (pendingTimeout) {
  4665. this.#nextMatch();
  4666. } else {
  4667. this._highlightMatches = true;
  4668. }
  4669. this.#updateAllPages();
  4670. } else {
  4671. this.#nextMatch();
  4672. }
  4673. });
  4674. }
  4675. scrollMatchIntoView({
  4676. element = null,
  4677. selectedLeft = 0,
  4678. pageIndex = -1,
  4679. matchIndex = -1
  4680. }) {
  4681. if (!this._scrollMatches || !element) {
  4682. return;
  4683. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4684. return;
  4685. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4686. return;
  4687. }
  4688. this._scrollMatches = false;
  4689. const spot = {
  4690. top: MATCH_SCROLL_OFFSET_TOP,
  4691. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  4692. };
  4693. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4694. }
  4695. #reset() {
  4696. this._highlightMatches = false;
  4697. this._scrollMatches = false;
  4698. this._pdfDocument = null;
  4699. this._pageMatches = [];
  4700. this._pageMatchesLength = [];
  4701. this._state = null;
  4702. this._selected = {
  4703. pageIdx: -1,
  4704. matchIdx: -1
  4705. };
  4706. this._offset = {
  4707. pageIdx: null,
  4708. matchIdx: null,
  4709. wrapped: false
  4710. };
  4711. this._extractTextPromises = [];
  4712. this._pageContents = [];
  4713. this._pageDiffs = [];
  4714. this._hasDiacritics = [];
  4715. this._matchesCountTotal = 0;
  4716. this._pagesToSearch = null;
  4717. this._pendingFindMatches = new Set();
  4718. this._resumePageIdx = null;
  4719. this._dirtyMatch = false;
  4720. clearTimeout(this._findTimeout);
  4721. this._findTimeout = null;
  4722. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4723. }
  4724. get #query() {
  4725. if (this._state.query !== this._rawQuery) {
  4726. this._rawQuery = this._state.query;
  4727. [this._normalizedQuery] = normalize(this._state.query);
  4728. }
  4729. return this._normalizedQuery;
  4730. }
  4731. #shouldDirtyMatch(state) {
  4732. if (state.query !== this._state.query) {
  4733. return true;
  4734. }
  4735. switch (state.type) {
  4736. case "again":
  4737. const pageNumber = this._selected.pageIdx + 1;
  4738. const linkService = this._linkService;
  4739. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4740. return true;
  4741. }
  4742. return false;
  4743. case "highlightallchange":
  4744. return false;
  4745. }
  4746. return true;
  4747. }
  4748. #isEntireWord(content, startIdx, length) {
  4749. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  4750. if (match) {
  4751. const first = content.charCodeAt(startIdx);
  4752. const limit = match[1].charCodeAt(0);
  4753. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4754. return false;
  4755. }
  4756. }
  4757. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  4758. if (match) {
  4759. const last = content.charCodeAt(startIdx + length - 1);
  4760. const limit = match[1].charCodeAt(0);
  4761. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4762. return false;
  4763. }
  4764. }
  4765. return true;
  4766. }
  4767. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  4768. const matches = [],
  4769. matchesLength = [];
  4770. const diffs = this._pageDiffs[pageIndex];
  4771. let match;
  4772. while ((match = query.exec(pageContent)) !== null) {
  4773. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  4774. continue;
  4775. }
  4776. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  4777. if (matchLen) {
  4778. matches.push(matchPos);
  4779. matchesLength.push(matchLen);
  4780. }
  4781. }
  4782. this._pageMatches[pageIndex] = matches;
  4783. this._pageMatchesLength[pageIndex] = matchesLength;
  4784. }
  4785. #convertToRegExpString(query, hasDiacritics) {
  4786. const {
  4787. matchDiacritics
  4788. } = this._state;
  4789. let isUnicode = false;
  4790. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  4791. if (p1) {
  4792. return `[ ]*\\${p1}[ ]*`;
  4793. }
  4794. if (p2) {
  4795. return `[ ]*${p2}[ ]*`;
  4796. }
  4797. if (p3) {
  4798. return "[ ]+";
  4799. }
  4800. if (matchDiacritics) {
  4801. return p4 || p5;
  4802. }
  4803. if (p4) {
  4804. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  4805. }
  4806. if (hasDiacritics) {
  4807. isUnicode = true;
  4808. return `${p5}\\p{M}*`;
  4809. }
  4810. return p5;
  4811. });
  4812. const trailingSpaces = "[ ]*";
  4813. if (query.endsWith(trailingSpaces)) {
  4814. query = query.slice(0, query.length - trailingSpaces.length);
  4815. }
  4816. if (matchDiacritics) {
  4817. if (hasDiacritics) {
  4818. isUnicode = true;
  4819. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  4820. }
  4821. }
  4822. return [isUnicode, query];
  4823. }
  4824. #calculateMatch(pageIndex) {
  4825. let query = this.#query;
  4826. if (query.length === 0) {
  4827. return;
  4828. }
  4829. const {
  4830. caseSensitive,
  4831. entireWord,
  4832. phraseSearch
  4833. } = this._state;
  4834. const pageContent = this._pageContents[pageIndex];
  4835. const hasDiacritics = this._hasDiacritics[pageIndex];
  4836. let isUnicode = false;
  4837. if (phraseSearch) {
  4838. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  4839. } else {
  4840. const match = query.match(/\S+/g);
  4841. if (match) {
  4842. query = match.sort().reverse().map(q => {
  4843. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  4844. isUnicode ||= isUnicodePart;
  4845. return `(${queryPart})`;
  4846. }).join("|");
  4847. }
  4848. }
  4849. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  4850. query = new RegExp(query, flags);
  4851. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  4852. if (this._state.highlightAll) {
  4853. this.#updatePage(pageIndex);
  4854. }
  4855. if (this._resumePageIdx === pageIndex) {
  4856. this._resumePageIdx = null;
  4857. this.#nextPageMatch();
  4858. }
  4859. const pageMatchesCount = this._pageMatches[pageIndex].length;
  4860. if (pageMatchesCount > 0) {
  4861. this._matchesCountTotal += pageMatchesCount;
  4862. this.#updateUIResultsCount();
  4863. }
  4864. }
  4865. #extractText() {
  4866. if (this._extractTextPromises.length > 0) {
  4867. return;
  4868. }
  4869. let promise = Promise.resolve();
  4870. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  4871. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  4872. this._extractTextPromises[i] = extractTextCapability.promise;
  4873. promise = promise.then(() => {
  4874. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  4875. return pdfPage.getTextContent();
  4876. }).then(textContent => {
  4877. const strBuf = [];
  4878. for (const textItem of textContent.items) {
  4879. strBuf.push(textItem.str);
  4880. if (textItem.hasEOL) {
  4881. strBuf.push("\n");
  4882. }
  4883. }
  4884. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  4885. extractTextCapability.resolve();
  4886. }, reason => {
  4887. console.error(`Unable to get text content for page ${i + 1}`, reason);
  4888. this._pageContents[i] = "";
  4889. this._pageDiffs[i] = null;
  4890. this._hasDiacritics[i] = false;
  4891. extractTextCapability.resolve();
  4892. });
  4893. });
  4894. }
  4895. }
  4896. #updatePage(index) {
  4897. if (this._scrollMatches && this._selected.pageIdx === index) {
  4898. this._linkService.page = index + 1;
  4899. }
  4900. this._eventBus.dispatch("updatetextlayermatches", {
  4901. source: this,
  4902. pageIndex: index
  4903. });
  4904. }
  4905. #updateAllPages() {
  4906. this._eventBus.dispatch("updatetextlayermatches", {
  4907. source: this,
  4908. pageIndex: -1
  4909. });
  4910. }
  4911. #nextMatch() {
  4912. const previous = this._state.findPrevious;
  4913. const currentPageIndex = this._linkService.page - 1;
  4914. const numPages = this._linkService.pagesCount;
  4915. this._highlightMatches = true;
  4916. if (this._dirtyMatch) {
  4917. this._dirtyMatch = false;
  4918. this._selected.pageIdx = this._selected.matchIdx = -1;
  4919. this._offset.pageIdx = currentPageIndex;
  4920. this._offset.matchIdx = null;
  4921. this._offset.wrapped = false;
  4922. this._resumePageIdx = null;
  4923. this._pageMatches.length = 0;
  4924. this._pageMatchesLength.length = 0;
  4925. this._matchesCountTotal = 0;
  4926. this.#updateAllPages();
  4927. for (let i = 0; i < numPages; i++) {
  4928. if (this._pendingFindMatches.has(i)) {
  4929. continue;
  4930. }
  4931. this._pendingFindMatches.add(i);
  4932. this._extractTextPromises[i].then(() => {
  4933. this._pendingFindMatches.delete(i);
  4934. this.#calculateMatch(i);
  4935. });
  4936. }
  4937. }
  4938. if (this.#query === "") {
  4939. this.#updateUIState(FindState.FOUND);
  4940. return;
  4941. }
  4942. if (this._resumePageIdx) {
  4943. return;
  4944. }
  4945. const offset = this._offset;
  4946. this._pagesToSearch = numPages;
  4947. if (offset.matchIdx !== null) {
  4948. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  4949. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  4950. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  4951. this.#updateMatch(true);
  4952. return;
  4953. }
  4954. this.#advanceOffsetPage(previous);
  4955. }
  4956. this.#nextPageMatch();
  4957. }
  4958. #matchesReady(matches) {
  4959. const offset = this._offset;
  4960. const numMatches = matches.length;
  4961. const previous = this._state.findPrevious;
  4962. if (numMatches) {
  4963. offset.matchIdx = previous ? numMatches - 1 : 0;
  4964. this.#updateMatch(true);
  4965. return true;
  4966. }
  4967. this.#advanceOffsetPage(previous);
  4968. if (offset.wrapped) {
  4969. offset.matchIdx = null;
  4970. if (this._pagesToSearch < 0) {
  4971. this.#updateMatch(false);
  4972. return true;
  4973. }
  4974. }
  4975. return false;
  4976. }
  4977. #nextPageMatch() {
  4978. if (this._resumePageIdx !== null) {
  4979. console.error("There can only be one pending page.");
  4980. }
  4981. let matches = null;
  4982. do {
  4983. const pageIdx = this._offset.pageIdx;
  4984. matches = this._pageMatches[pageIdx];
  4985. if (!matches) {
  4986. this._resumePageIdx = pageIdx;
  4987. break;
  4988. }
  4989. } while (!this.#matchesReady(matches));
  4990. }
  4991. #advanceOffsetPage(previous) {
  4992. const offset = this._offset;
  4993. const numPages = this._linkService.pagesCount;
  4994. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  4995. offset.matchIdx = null;
  4996. this._pagesToSearch--;
  4997. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  4998. offset.pageIdx = previous ? numPages - 1 : 0;
  4999. offset.wrapped = true;
  5000. }
  5001. }
  5002. #updateMatch(found = false) {
  5003. let state = FindState.NOT_FOUND;
  5004. const wrapped = this._offset.wrapped;
  5005. this._offset.wrapped = false;
  5006. if (found) {
  5007. const previousPage = this._selected.pageIdx;
  5008. this._selected.pageIdx = this._offset.pageIdx;
  5009. this._selected.matchIdx = this._offset.matchIdx;
  5010. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5011. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5012. this.#updatePage(previousPage);
  5013. }
  5014. }
  5015. this.#updateUIState(state, this._state.findPrevious);
  5016. if (this._selected.pageIdx !== -1) {
  5017. this._scrollMatches = true;
  5018. this.#updatePage(this._selected.pageIdx);
  5019. }
  5020. }
  5021. #onFindBarClose(evt) {
  5022. const pdfDocument = this._pdfDocument;
  5023. this._firstPageCapability.promise.then(() => {
  5024. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5025. return;
  5026. }
  5027. if (this._findTimeout) {
  5028. clearTimeout(this._findTimeout);
  5029. this._findTimeout = null;
  5030. }
  5031. if (this._resumePageIdx) {
  5032. this._resumePageIdx = null;
  5033. this._dirtyMatch = true;
  5034. }
  5035. this.#updateUIState(FindState.FOUND);
  5036. this._highlightMatches = false;
  5037. this.#updateAllPages();
  5038. });
  5039. }
  5040. #requestMatchesCount() {
  5041. const {
  5042. pageIdx,
  5043. matchIdx
  5044. } = this._selected;
  5045. let current = 0,
  5046. total = this._matchesCountTotal;
  5047. if (matchIdx !== -1) {
  5048. for (let i = 0; i < pageIdx; i++) {
  5049. current += this._pageMatches[i]?.length || 0;
  5050. }
  5051. current += matchIdx + 1;
  5052. }
  5053. if (current < 1 || current > total) {
  5054. current = total = 0;
  5055. }
  5056. return {
  5057. current,
  5058. total
  5059. };
  5060. }
  5061. #updateUIResultsCount() {
  5062. this._eventBus.dispatch("updatefindmatchescount", {
  5063. source: this,
  5064. matchesCount: this.#requestMatchesCount()
  5065. });
  5066. }
  5067. #updateUIState(state, previous = false) {
  5068. this._eventBus.dispatch("updatefindcontrolstate", {
  5069. source: this,
  5070. state,
  5071. previous,
  5072. matchesCount: this.#requestMatchesCount(),
  5073. rawQuery: this._state?.query ?? null
  5074. });
  5075. }
  5076. }
  5077. exports.PDFFindController = PDFFindController;
  5078. /***/ }),
  5079. /* 16 */
  5080. /***/ ((__unused_webpack_module, exports) => {
  5081. Object.defineProperty(exports, "__esModule", ({
  5082. value: true
  5083. }));
  5084. exports.CharacterType = void 0;
  5085. exports.getCharacterType = getCharacterType;
  5086. const CharacterType = {
  5087. SPACE: 0,
  5088. ALPHA_LETTER: 1,
  5089. PUNCT: 2,
  5090. HAN_LETTER: 3,
  5091. KATAKANA_LETTER: 4,
  5092. HIRAGANA_LETTER: 5,
  5093. HALFWIDTH_KATAKANA_LETTER: 6,
  5094. THAI_LETTER: 7
  5095. };
  5096. exports.CharacterType = CharacterType;
  5097. function isAlphabeticalScript(charCode) {
  5098. return charCode < 0x2e80;
  5099. }
  5100. function isAscii(charCode) {
  5101. return (charCode & 0xff80) === 0;
  5102. }
  5103. function isAsciiAlpha(charCode) {
  5104. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5105. }
  5106. function isAsciiDigit(charCode) {
  5107. return charCode >= 0x30 && charCode <= 0x39;
  5108. }
  5109. function isAsciiSpace(charCode) {
  5110. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5111. }
  5112. function isHan(charCode) {
  5113. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5114. }
  5115. function isKatakana(charCode) {
  5116. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5117. }
  5118. function isHiragana(charCode) {
  5119. return charCode >= 0x3040 && charCode <= 0x309f;
  5120. }
  5121. function isHalfwidthKatakana(charCode) {
  5122. return charCode >= 0xff60 && charCode <= 0xff9f;
  5123. }
  5124. function isThai(charCode) {
  5125. return (charCode & 0xff80) === 0x0e00;
  5126. }
  5127. function getCharacterType(charCode) {
  5128. if (isAlphabeticalScript(charCode)) {
  5129. if (isAscii(charCode)) {
  5130. if (isAsciiSpace(charCode)) {
  5131. return CharacterType.SPACE;
  5132. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5133. return CharacterType.ALPHA_LETTER;
  5134. }
  5135. return CharacterType.PUNCT;
  5136. } else if (isThai(charCode)) {
  5137. return CharacterType.THAI_LETTER;
  5138. } else if (charCode === 0xa0) {
  5139. return CharacterType.SPACE;
  5140. }
  5141. return CharacterType.ALPHA_LETTER;
  5142. }
  5143. if (isHan(charCode)) {
  5144. return CharacterType.HAN_LETTER;
  5145. } else if (isKatakana(charCode)) {
  5146. return CharacterType.KATAKANA_LETTER;
  5147. } else if (isHiragana(charCode)) {
  5148. return CharacterType.HIRAGANA_LETTER;
  5149. } else if (isHalfwidthKatakana(charCode)) {
  5150. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5151. }
  5152. return CharacterType.ALPHA_LETTER;
  5153. }
  5154. /***/ }),
  5155. /* 17 */
  5156. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5157. Object.defineProperty(exports, "__esModule", ({
  5158. value: true
  5159. }));
  5160. exports.PDFHistory = void 0;
  5161. exports.isDestArraysEqual = isDestArraysEqual;
  5162. exports.isDestHashesEqual = isDestHashesEqual;
  5163. var _ui_utils = __webpack_require__(3);
  5164. var _event_utils = __webpack_require__(4);
  5165. const HASH_CHANGE_TIMEOUT = 1000;
  5166. const POSITION_UPDATED_THRESHOLD = 50;
  5167. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5168. function getCurrentHash() {
  5169. return document.location.hash;
  5170. }
  5171. class PDFHistory {
  5172. constructor({
  5173. linkService,
  5174. eventBus
  5175. }) {
  5176. this.linkService = linkService;
  5177. this.eventBus = eventBus;
  5178. this._initialized = false;
  5179. this._fingerprint = "";
  5180. this.reset();
  5181. this._boundEvents = null;
  5182. this.eventBus._on("pagesinit", () => {
  5183. this._isPagesLoaded = false;
  5184. this.eventBus._on("pagesloaded", evt => {
  5185. this._isPagesLoaded = !!evt.pagesCount;
  5186. }, {
  5187. once: true
  5188. });
  5189. });
  5190. }
  5191. initialize({
  5192. fingerprint,
  5193. resetHistory = false,
  5194. updateUrl = false
  5195. }) {
  5196. if (!fingerprint || typeof fingerprint !== "string") {
  5197. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5198. return;
  5199. }
  5200. if (this._initialized) {
  5201. this.reset();
  5202. }
  5203. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5204. this._fingerprint = fingerprint;
  5205. this._updateUrl = updateUrl === true;
  5206. this._initialized = true;
  5207. this._bindEvents();
  5208. const state = window.history.state;
  5209. this._popStateInProgress = false;
  5210. this._blockHashChange = 0;
  5211. this._currentHash = getCurrentHash();
  5212. this._numPositionUpdates = 0;
  5213. this._uid = this._maxUid = 0;
  5214. this._destination = null;
  5215. this._position = null;
  5216. if (!this._isValidState(state, true) || resetHistory) {
  5217. const {
  5218. hash,
  5219. page,
  5220. rotation
  5221. } = this._parseCurrentHash(true);
  5222. if (!hash || reInitialized || resetHistory) {
  5223. this._pushOrReplaceState(null, true);
  5224. return;
  5225. }
  5226. this._pushOrReplaceState({
  5227. hash,
  5228. page,
  5229. rotation
  5230. }, true);
  5231. return;
  5232. }
  5233. const destination = state.destination;
  5234. this._updateInternalState(destination, state.uid, true);
  5235. if (destination.rotation !== undefined) {
  5236. this._initialRotation = destination.rotation;
  5237. }
  5238. if (destination.dest) {
  5239. this._initialBookmark = JSON.stringify(destination.dest);
  5240. this._destination.page = null;
  5241. } else if (destination.hash) {
  5242. this._initialBookmark = destination.hash;
  5243. } else if (destination.page) {
  5244. this._initialBookmark = `page=${destination.page}`;
  5245. }
  5246. }
  5247. reset() {
  5248. if (this._initialized) {
  5249. this._pageHide();
  5250. this._initialized = false;
  5251. this._unbindEvents();
  5252. }
  5253. if (this._updateViewareaTimeout) {
  5254. clearTimeout(this._updateViewareaTimeout);
  5255. this._updateViewareaTimeout = null;
  5256. }
  5257. this._initialBookmark = null;
  5258. this._initialRotation = null;
  5259. }
  5260. push({
  5261. namedDest = null,
  5262. explicitDest,
  5263. pageNumber
  5264. }) {
  5265. if (!this._initialized) {
  5266. return;
  5267. }
  5268. if (namedDest && typeof namedDest !== "string") {
  5269. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5270. return;
  5271. } else if (!Array.isArray(explicitDest)) {
  5272. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5273. return;
  5274. } else if (!this._isValidPage(pageNumber)) {
  5275. if (pageNumber !== null || this._destination) {
  5276. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5277. return;
  5278. }
  5279. }
  5280. const hash = namedDest || JSON.stringify(explicitDest);
  5281. if (!hash) {
  5282. return;
  5283. }
  5284. let forceReplace = false;
  5285. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5286. if (this._destination.page) {
  5287. return;
  5288. }
  5289. forceReplace = true;
  5290. }
  5291. if (this._popStateInProgress && !forceReplace) {
  5292. return;
  5293. }
  5294. this._pushOrReplaceState({
  5295. dest: explicitDest,
  5296. hash,
  5297. page: pageNumber,
  5298. rotation: this.linkService.rotation
  5299. }, forceReplace);
  5300. if (!this._popStateInProgress) {
  5301. this._popStateInProgress = true;
  5302. Promise.resolve().then(() => {
  5303. this._popStateInProgress = false;
  5304. });
  5305. }
  5306. }
  5307. pushPage(pageNumber) {
  5308. if (!this._initialized) {
  5309. return;
  5310. }
  5311. if (!this._isValidPage(pageNumber)) {
  5312. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5313. return;
  5314. }
  5315. if (this._destination?.page === pageNumber) {
  5316. return;
  5317. }
  5318. if (this._popStateInProgress) {
  5319. return;
  5320. }
  5321. this._pushOrReplaceState({
  5322. dest: null,
  5323. hash: `page=${pageNumber}`,
  5324. page: pageNumber,
  5325. rotation: this.linkService.rotation
  5326. });
  5327. if (!this._popStateInProgress) {
  5328. this._popStateInProgress = true;
  5329. Promise.resolve().then(() => {
  5330. this._popStateInProgress = false;
  5331. });
  5332. }
  5333. }
  5334. pushCurrentPosition() {
  5335. if (!this._initialized || this._popStateInProgress) {
  5336. return;
  5337. }
  5338. this._tryPushCurrentPosition();
  5339. }
  5340. back() {
  5341. if (!this._initialized || this._popStateInProgress) {
  5342. return;
  5343. }
  5344. const state = window.history.state;
  5345. if (this._isValidState(state) && state.uid > 0) {
  5346. window.history.back();
  5347. }
  5348. }
  5349. forward() {
  5350. if (!this._initialized || this._popStateInProgress) {
  5351. return;
  5352. }
  5353. const state = window.history.state;
  5354. if (this._isValidState(state) && state.uid < this._maxUid) {
  5355. window.history.forward();
  5356. }
  5357. }
  5358. get popStateInProgress() {
  5359. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5360. }
  5361. get initialBookmark() {
  5362. return this._initialized ? this._initialBookmark : null;
  5363. }
  5364. get initialRotation() {
  5365. return this._initialized ? this._initialRotation : null;
  5366. }
  5367. _pushOrReplaceState(destination, forceReplace = false) {
  5368. const shouldReplace = forceReplace || !this._destination;
  5369. const newState = {
  5370. fingerprint: this._fingerprint,
  5371. uid: shouldReplace ? this._uid : this._uid + 1,
  5372. destination
  5373. };
  5374. this._updateInternalState(destination, newState.uid);
  5375. let newUrl;
  5376. if (this._updateUrl && destination?.hash) {
  5377. const baseUrl = document.location.href.split("#")[0];
  5378. if (!baseUrl.startsWith("file://")) {
  5379. newUrl = `${baseUrl}#${destination.hash}`;
  5380. }
  5381. }
  5382. if (shouldReplace) {
  5383. window.history.replaceState(newState, "", newUrl);
  5384. } else {
  5385. window.history.pushState(newState, "", newUrl);
  5386. }
  5387. }
  5388. _tryPushCurrentPosition(temporary = false) {
  5389. if (!this._position) {
  5390. return;
  5391. }
  5392. let position = this._position;
  5393. if (temporary) {
  5394. position = Object.assign(Object.create(null), this._position);
  5395. position.temporary = true;
  5396. }
  5397. if (!this._destination) {
  5398. this._pushOrReplaceState(position);
  5399. return;
  5400. }
  5401. if (this._destination.temporary) {
  5402. this._pushOrReplaceState(position, true);
  5403. return;
  5404. }
  5405. if (this._destination.hash === position.hash) {
  5406. return;
  5407. }
  5408. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5409. return;
  5410. }
  5411. let forceReplace = false;
  5412. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5413. if (this._destination.dest !== undefined || !this._destination.first) {
  5414. return;
  5415. }
  5416. forceReplace = true;
  5417. }
  5418. this._pushOrReplaceState(position, forceReplace);
  5419. }
  5420. _isValidPage(val) {
  5421. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5422. }
  5423. _isValidState(state, checkReload = false) {
  5424. if (!state) {
  5425. return false;
  5426. }
  5427. if (state.fingerprint !== this._fingerprint) {
  5428. if (checkReload) {
  5429. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5430. return false;
  5431. }
  5432. const [perfEntry] = performance.getEntriesByType("navigation");
  5433. if (perfEntry?.type !== "reload") {
  5434. return false;
  5435. }
  5436. } else {
  5437. return false;
  5438. }
  5439. }
  5440. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5441. return false;
  5442. }
  5443. if (state.destination === null || typeof state.destination !== "object") {
  5444. return false;
  5445. }
  5446. return true;
  5447. }
  5448. _updateInternalState(destination, uid, removeTemporary = false) {
  5449. if (this._updateViewareaTimeout) {
  5450. clearTimeout(this._updateViewareaTimeout);
  5451. this._updateViewareaTimeout = null;
  5452. }
  5453. if (removeTemporary && destination?.temporary) {
  5454. delete destination.temporary;
  5455. }
  5456. this._destination = destination;
  5457. this._uid = uid;
  5458. this._maxUid = Math.max(this._maxUid, uid);
  5459. this._numPositionUpdates = 0;
  5460. }
  5461. _parseCurrentHash(checkNameddest = false) {
  5462. const hash = unescape(getCurrentHash()).substring(1);
  5463. const params = (0, _ui_utils.parseQueryString)(hash);
  5464. const nameddest = params.get("nameddest") || "";
  5465. let page = params.get("page") | 0;
  5466. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5467. page = null;
  5468. }
  5469. return {
  5470. hash,
  5471. page,
  5472. rotation: this.linkService.rotation
  5473. };
  5474. }
  5475. _updateViewarea({
  5476. location
  5477. }) {
  5478. if (this._updateViewareaTimeout) {
  5479. clearTimeout(this._updateViewareaTimeout);
  5480. this._updateViewareaTimeout = null;
  5481. }
  5482. this._position = {
  5483. hash: location.pdfOpenParams.substring(1),
  5484. page: this.linkService.page,
  5485. first: location.pageNumber,
  5486. rotation: location.rotation
  5487. };
  5488. if (this._popStateInProgress) {
  5489. return;
  5490. }
  5491. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5492. this._numPositionUpdates++;
  5493. }
  5494. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5495. this._updateViewareaTimeout = setTimeout(() => {
  5496. if (!this._popStateInProgress) {
  5497. this._tryPushCurrentPosition(true);
  5498. }
  5499. this._updateViewareaTimeout = null;
  5500. }, UPDATE_VIEWAREA_TIMEOUT);
  5501. }
  5502. }
  5503. _popState({
  5504. state
  5505. }) {
  5506. const newHash = getCurrentHash(),
  5507. hashChanged = this._currentHash !== newHash;
  5508. this._currentHash = newHash;
  5509. if (!state) {
  5510. this._uid++;
  5511. const {
  5512. hash,
  5513. page,
  5514. rotation
  5515. } = this._parseCurrentHash();
  5516. this._pushOrReplaceState({
  5517. hash,
  5518. page,
  5519. rotation
  5520. }, true);
  5521. return;
  5522. }
  5523. if (!this._isValidState(state)) {
  5524. return;
  5525. }
  5526. this._popStateInProgress = true;
  5527. if (hashChanged) {
  5528. this._blockHashChange++;
  5529. (0, _event_utils.waitOnEventOrTimeout)({
  5530. target: window,
  5531. name: "hashchange",
  5532. delay: HASH_CHANGE_TIMEOUT
  5533. }).then(() => {
  5534. this._blockHashChange--;
  5535. });
  5536. }
  5537. const destination = state.destination;
  5538. this._updateInternalState(destination, state.uid, true);
  5539. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5540. this.linkService.rotation = destination.rotation;
  5541. }
  5542. if (destination.dest) {
  5543. this.linkService.goToDestination(destination.dest);
  5544. } else if (destination.hash) {
  5545. this.linkService.setHash(destination.hash);
  5546. } else if (destination.page) {
  5547. this.linkService.page = destination.page;
  5548. }
  5549. Promise.resolve().then(() => {
  5550. this._popStateInProgress = false;
  5551. });
  5552. }
  5553. _pageHide() {
  5554. if (!this._destination || this._destination.temporary) {
  5555. this._tryPushCurrentPosition();
  5556. }
  5557. }
  5558. _bindEvents() {
  5559. if (this._boundEvents) {
  5560. return;
  5561. }
  5562. this._boundEvents = {
  5563. updateViewarea: this._updateViewarea.bind(this),
  5564. popState: this._popState.bind(this),
  5565. pageHide: this._pageHide.bind(this)
  5566. };
  5567. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5568. window.addEventListener("popstate", this._boundEvents.popState);
  5569. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5570. }
  5571. _unbindEvents() {
  5572. if (!this._boundEvents) {
  5573. return;
  5574. }
  5575. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5576. window.removeEventListener("popstate", this._boundEvents.popState);
  5577. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5578. this._boundEvents = null;
  5579. }
  5580. }
  5581. exports.PDFHistory = PDFHistory;
  5582. function isDestHashesEqual(destHash, pushHash) {
  5583. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5584. return false;
  5585. }
  5586. if (destHash === pushHash) {
  5587. return true;
  5588. }
  5589. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  5590. if (nameddest === pushHash) {
  5591. return true;
  5592. }
  5593. return false;
  5594. }
  5595. function isDestArraysEqual(firstDest, secondDest) {
  5596. function isEntryEqual(first, second) {
  5597. if (typeof first !== typeof second) {
  5598. return false;
  5599. }
  5600. if (Array.isArray(first) || Array.isArray(second)) {
  5601. return false;
  5602. }
  5603. if (first !== null && typeof first === "object" && second !== null) {
  5604. if (Object.keys(first).length !== Object.keys(second).length) {
  5605. return false;
  5606. }
  5607. for (const key in first) {
  5608. if (!isEntryEqual(first[key], second[key])) {
  5609. return false;
  5610. }
  5611. }
  5612. return true;
  5613. }
  5614. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5615. }
  5616. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5617. return false;
  5618. }
  5619. if (firstDest.length !== secondDest.length) {
  5620. return false;
  5621. }
  5622. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5623. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5624. return false;
  5625. }
  5626. }
  5627. return true;
  5628. }
  5629. /***/ }),
  5630. /* 18 */
  5631. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5632. Object.defineProperty(exports, "__esModule", ({
  5633. value: true
  5634. }));
  5635. exports.PDFLayerViewer = void 0;
  5636. var _base_tree_viewer = __webpack_require__(12);
  5637. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5638. constructor(options) {
  5639. super(options);
  5640. this.l10n = options.l10n;
  5641. this.eventBus._on("resetlayers", this._resetLayers.bind(this));
  5642. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5643. }
  5644. reset() {
  5645. super.reset();
  5646. this._optionalContentConfig = null;
  5647. }
  5648. _dispatchEvent(layersCount) {
  5649. this.eventBus.dispatch("layersloaded", {
  5650. source: this,
  5651. layersCount
  5652. });
  5653. }
  5654. _bindLink(element, {
  5655. groupId,
  5656. input
  5657. }) {
  5658. const setVisibility = () => {
  5659. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5660. this.eventBus.dispatch("optionalcontentconfig", {
  5661. source: this,
  5662. promise: Promise.resolve(this._optionalContentConfig)
  5663. });
  5664. };
  5665. element.onclick = evt => {
  5666. if (evt.target === input) {
  5667. setVisibility();
  5668. return true;
  5669. } else if (evt.target !== element) {
  5670. return true;
  5671. }
  5672. input.checked = !input.checked;
  5673. setVisibility();
  5674. return false;
  5675. };
  5676. }
  5677. async _setNestedName(element, {
  5678. name = null
  5679. }) {
  5680. if (typeof name === "string") {
  5681. element.textContent = this._normalizeTextContent(name);
  5682. return;
  5683. }
  5684. element.textContent = await this.l10n.get("additional_layers");
  5685. element.style.fontStyle = "italic";
  5686. }
  5687. _addToggleButton(div, {
  5688. name = null
  5689. }) {
  5690. super._addToggleButton(div, name === null);
  5691. }
  5692. _toggleAllTreeItems() {
  5693. if (!this._optionalContentConfig) {
  5694. return;
  5695. }
  5696. super._toggleAllTreeItems();
  5697. }
  5698. render({
  5699. optionalContentConfig,
  5700. pdfDocument
  5701. }) {
  5702. if (this._optionalContentConfig) {
  5703. this.reset();
  5704. }
  5705. this._optionalContentConfig = optionalContentConfig || null;
  5706. this._pdfDocument = pdfDocument || null;
  5707. const groups = optionalContentConfig?.getOrder();
  5708. if (!groups) {
  5709. this._dispatchEvent(0);
  5710. return;
  5711. }
  5712. const fragment = document.createDocumentFragment(),
  5713. queue = [{
  5714. parent: fragment,
  5715. groups
  5716. }];
  5717. let layersCount = 0,
  5718. hasAnyNesting = false;
  5719. while (queue.length > 0) {
  5720. const levelData = queue.shift();
  5721. for (const groupId of levelData.groups) {
  5722. const div = document.createElement("div");
  5723. div.className = "treeItem";
  5724. const element = document.createElement("a");
  5725. div.appendChild(element);
  5726. if (typeof groupId === "object") {
  5727. hasAnyNesting = true;
  5728. this._addToggleButton(div, groupId);
  5729. this._setNestedName(element, groupId);
  5730. const itemsDiv = document.createElement("div");
  5731. itemsDiv.className = "treeItems";
  5732. div.appendChild(itemsDiv);
  5733. queue.push({
  5734. parent: itemsDiv,
  5735. groups: groupId.order
  5736. });
  5737. } else {
  5738. const group = optionalContentConfig.getGroup(groupId);
  5739. const input = document.createElement("input");
  5740. this._bindLink(element, {
  5741. groupId,
  5742. input
  5743. });
  5744. input.type = "checkbox";
  5745. input.id = groupId;
  5746. input.checked = group.visible;
  5747. const label = document.createElement("label");
  5748. label.setAttribute("for", groupId);
  5749. label.textContent = this._normalizeTextContent(group.name);
  5750. element.appendChild(input);
  5751. element.appendChild(label);
  5752. layersCount++;
  5753. }
  5754. levelData.parent.appendChild(div);
  5755. }
  5756. }
  5757. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5758. }
  5759. async _resetLayers() {
  5760. if (!this._optionalContentConfig) {
  5761. return;
  5762. }
  5763. const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
  5764. this.eventBus.dispatch("optionalcontentconfig", {
  5765. source: this,
  5766. promise: Promise.resolve(optionalContentConfig)
  5767. });
  5768. this.render({
  5769. optionalContentConfig,
  5770. pdfDocument: this._pdfDocument
  5771. });
  5772. }
  5773. }
  5774. exports.PDFLayerViewer = PDFLayerViewer;
  5775. /***/ }),
  5776. /* 19 */
  5777. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5778. Object.defineProperty(exports, "__esModule", ({
  5779. value: true
  5780. }));
  5781. exports.PDFOutlineViewer = void 0;
  5782. var _base_tree_viewer = __webpack_require__(12);
  5783. var _pdfjsLib = __webpack_require__(5);
  5784. var _ui_utils = __webpack_require__(3);
  5785. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  5786. constructor(options) {
  5787. super(options);
  5788. this.linkService = options.linkService;
  5789. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  5790. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  5791. this.eventBus._on("pagechanging", evt => {
  5792. this._currentPageNumber = evt.pageNumber;
  5793. });
  5794. this.eventBus._on("pagesloaded", evt => {
  5795. this._isPagesLoaded = !!evt.pagesCount;
  5796. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5797. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  5798. }
  5799. });
  5800. this.eventBus._on("sidebarviewchanged", evt => {
  5801. this._sidebarView = evt.view;
  5802. });
  5803. }
  5804. reset() {
  5805. super.reset();
  5806. this._outline = null;
  5807. this._pageNumberToDestHashCapability = null;
  5808. this._currentPageNumber = 1;
  5809. this._isPagesLoaded = null;
  5810. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5811. this._currentOutlineItemCapability.resolve(false);
  5812. }
  5813. this._currentOutlineItemCapability = null;
  5814. }
  5815. _dispatchEvent(outlineCount) {
  5816. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  5817. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  5818. this._currentOutlineItemCapability.resolve(false);
  5819. } else if (this._isPagesLoaded !== null) {
  5820. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  5821. }
  5822. this.eventBus.dispatch("outlineloaded", {
  5823. source: this,
  5824. outlineCount,
  5825. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  5826. });
  5827. }
  5828. _bindLink(element, {
  5829. url,
  5830. newWindow,
  5831. dest
  5832. }) {
  5833. const {
  5834. linkService
  5835. } = this;
  5836. if (url) {
  5837. linkService.addLinkAttributes(element, url, newWindow);
  5838. return;
  5839. }
  5840. element.href = linkService.getDestinationHash(dest);
  5841. element.onclick = evt => {
  5842. this._updateCurrentTreeItem(evt.target.parentNode);
  5843. if (dest) {
  5844. linkService.goToDestination(dest);
  5845. }
  5846. return false;
  5847. };
  5848. }
  5849. _setStyles(element, {
  5850. bold,
  5851. italic
  5852. }) {
  5853. if (bold) {
  5854. element.style.fontWeight = "bold";
  5855. }
  5856. if (italic) {
  5857. element.style.fontStyle = "italic";
  5858. }
  5859. }
  5860. _addToggleButton(div, {
  5861. count,
  5862. items
  5863. }) {
  5864. let hidden = false;
  5865. if (count < 0) {
  5866. let totalCount = items.length;
  5867. if (totalCount > 0) {
  5868. const queue = [...items];
  5869. while (queue.length > 0) {
  5870. const {
  5871. count: nestedCount,
  5872. items: nestedItems
  5873. } = queue.shift();
  5874. if (nestedCount > 0 && nestedItems.length > 0) {
  5875. totalCount += nestedItems.length;
  5876. queue.push(...nestedItems);
  5877. }
  5878. }
  5879. }
  5880. if (Math.abs(count) === totalCount) {
  5881. hidden = true;
  5882. }
  5883. }
  5884. super._addToggleButton(div, hidden);
  5885. }
  5886. _toggleAllTreeItems() {
  5887. if (!this._outline) {
  5888. return;
  5889. }
  5890. super._toggleAllTreeItems();
  5891. }
  5892. render({
  5893. outline,
  5894. pdfDocument
  5895. }) {
  5896. if (this._outline) {
  5897. this.reset();
  5898. }
  5899. this._outline = outline || null;
  5900. this._pdfDocument = pdfDocument || null;
  5901. if (!outline) {
  5902. this._dispatchEvent(0);
  5903. return;
  5904. }
  5905. const fragment = document.createDocumentFragment();
  5906. const queue = [{
  5907. parent: fragment,
  5908. items: outline
  5909. }];
  5910. let outlineCount = 0,
  5911. hasAnyNesting = false;
  5912. while (queue.length > 0) {
  5913. const levelData = queue.shift();
  5914. for (const item of levelData.items) {
  5915. const div = document.createElement("div");
  5916. div.className = "treeItem";
  5917. const element = document.createElement("a");
  5918. this._bindLink(element, item);
  5919. this._setStyles(element, item);
  5920. element.textContent = this._normalizeTextContent(item.title);
  5921. div.appendChild(element);
  5922. if (item.items.length > 0) {
  5923. hasAnyNesting = true;
  5924. this._addToggleButton(div, item);
  5925. const itemsDiv = document.createElement("div");
  5926. itemsDiv.className = "treeItems";
  5927. div.appendChild(itemsDiv);
  5928. queue.push({
  5929. parent: itemsDiv,
  5930. items: item.items
  5931. });
  5932. }
  5933. levelData.parent.appendChild(div);
  5934. outlineCount++;
  5935. }
  5936. }
  5937. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  5938. }
  5939. async _currentOutlineItem() {
  5940. if (!this._isPagesLoaded) {
  5941. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  5942. }
  5943. if (!this._outline || !this._pdfDocument) {
  5944. return;
  5945. }
  5946. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  5947. if (!pageNumberToDestHash) {
  5948. return;
  5949. }
  5950. this._updateCurrentTreeItem(null);
  5951. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  5952. return;
  5953. }
  5954. for (let i = this._currentPageNumber; i > 0; i--) {
  5955. const destHash = pageNumberToDestHash.get(i);
  5956. if (!destHash) {
  5957. continue;
  5958. }
  5959. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  5960. if (!linkElement) {
  5961. continue;
  5962. }
  5963. this._scrollToCurrentTreeItem(linkElement.parentNode);
  5964. break;
  5965. }
  5966. }
  5967. async _getPageNumberToDestHash(pdfDocument) {
  5968. if (this._pageNumberToDestHashCapability) {
  5969. return this._pageNumberToDestHashCapability.promise;
  5970. }
  5971. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  5972. const pageNumberToDestHash = new Map(),
  5973. pageNumberNesting = new Map();
  5974. const queue = [{
  5975. nesting: 0,
  5976. items: this._outline
  5977. }];
  5978. while (queue.length > 0) {
  5979. const levelData = queue.shift(),
  5980. currentNesting = levelData.nesting;
  5981. for (const {
  5982. dest,
  5983. items
  5984. } of levelData.items) {
  5985. let explicitDest, pageNumber;
  5986. if (typeof dest === "string") {
  5987. explicitDest = await pdfDocument.getDestination(dest);
  5988. if (pdfDocument !== this._pdfDocument) {
  5989. return null;
  5990. }
  5991. } else {
  5992. explicitDest = dest;
  5993. }
  5994. if (Array.isArray(explicitDest)) {
  5995. const [destRef] = explicitDest;
  5996. if (typeof destRef === "object" && destRef !== null) {
  5997. pageNumber = this.linkService._cachedPageNumber(destRef);
  5998. if (!pageNumber) {
  5999. try {
  6000. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6001. if (pdfDocument !== this._pdfDocument) {
  6002. return null;
  6003. }
  6004. this.linkService.cachePageRef(pageNumber, destRef);
  6005. } catch (ex) {}
  6006. }
  6007. } else if (Number.isInteger(destRef)) {
  6008. pageNumber = destRef + 1;
  6009. }
  6010. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6011. const destHash = this.linkService.getDestinationHash(dest);
  6012. pageNumberToDestHash.set(pageNumber, destHash);
  6013. pageNumberNesting.set(pageNumber, currentNesting);
  6014. }
  6015. }
  6016. if (items.length > 0) {
  6017. queue.push({
  6018. nesting: currentNesting + 1,
  6019. items
  6020. });
  6021. }
  6022. }
  6023. }
  6024. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6025. return this._pageNumberToDestHashCapability.promise;
  6026. }
  6027. }
  6028. exports.PDFOutlineViewer = PDFOutlineViewer;
  6029. /***/ }),
  6030. /* 20 */
  6031. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6032. Object.defineProperty(exports, "__esModule", ({
  6033. value: true
  6034. }));
  6035. exports.PDFPresentationMode = void 0;
  6036. var _ui_utils = __webpack_require__(3);
  6037. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6038. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6039. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6040. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6041. const PAGE_SWITCH_THRESHOLD = 0.1;
  6042. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6043. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6044. class PDFPresentationMode {
  6045. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6046. #args = null;
  6047. constructor({
  6048. container,
  6049. pdfViewer,
  6050. eventBus
  6051. }) {
  6052. this.container = container;
  6053. this.pdfViewer = pdfViewer;
  6054. this.eventBus = eventBus;
  6055. this.contextMenuOpen = false;
  6056. this.mouseScrollTimeStamp = 0;
  6057. this.mouseScrollDelta = 0;
  6058. this.touchSwipeState = null;
  6059. }
  6060. async request() {
  6061. const {
  6062. container,
  6063. pdfViewer
  6064. } = this;
  6065. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6066. return false;
  6067. }
  6068. this.#addFullscreenChangeListeners();
  6069. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6070. const promise = container.requestFullscreen();
  6071. this.#args = {
  6072. pageNumber: pdfViewer.currentPageNumber,
  6073. scaleValue: pdfViewer.currentScaleValue,
  6074. scrollMode: pdfViewer.scrollMode,
  6075. spreadMode: null
  6076. };
  6077. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6078. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6079. this.#args.spreadMode = pdfViewer.spreadMode;
  6080. }
  6081. try {
  6082. await promise;
  6083. return true;
  6084. } catch (reason) {
  6085. this.#removeFullscreenChangeListeners();
  6086. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6087. }
  6088. return false;
  6089. }
  6090. get active() {
  6091. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6092. }
  6093. #mouseWheel(evt) {
  6094. if (!this.active) {
  6095. return;
  6096. }
  6097. evt.preventDefault();
  6098. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6099. const currentTime = Date.now();
  6100. const storedTime = this.mouseScrollTimeStamp;
  6101. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6102. return;
  6103. }
  6104. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6105. this.#resetMouseScrollState();
  6106. }
  6107. this.mouseScrollDelta += delta;
  6108. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6109. const totalDelta = this.mouseScrollDelta;
  6110. this.#resetMouseScrollState();
  6111. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6112. if (success) {
  6113. this.mouseScrollTimeStamp = currentTime;
  6114. }
  6115. }
  6116. }
  6117. #notifyStateChange(state) {
  6118. this.#state = state;
  6119. this.eventBus.dispatch("presentationmodechanged", {
  6120. source: this,
  6121. state
  6122. });
  6123. }
  6124. #enter() {
  6125. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6126. this.container.classList.add(ACTIVE_SELECTOR);
  6127. setTimeout(() => {
  6128. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6129. if (this.#args.spreadMode !== null) {
  6130. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6131. }
  6132. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6133. this.pdfViewer.currentScaleValue = "page-fit";
  6134. }, 0);
  6135. this.#addWindowListeners();
  6136. this.#showControls();
  6137. this.contextMenuOpen = false;
  6138. window.getSelection().removeAllRanges();
  6139. }
  6140. #exit() {
  6141. const pageNumber = this.pdfViewer.currentPageNumber;
  6142. this.container.classList.remove(ACTIVE_SELECTOR);
  6143. setTimeout(() => {
  6144. this.#removeFullscreenChangeListeners();
  6145. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6146. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6147. if (this.#args.spreadMode !== null) {
  6148. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6149. }
  6150. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6151. this.pdfViewer.currentPageNumber = pageNumber;
  6152. this.#args = null;
  6153. }, 0);
  6154. this.#removeWindowListeners();
  6155. this.#hideControls();
  6156. this.#resetMouseScrollState();
  6157. this.contextMenuOpen = false;
  6158. }
  6159. #mouseDown(evt) {
  6160. if (this.contextMenuOpen) {
  6161. this.contextMenuOpen = false;
  6162. evt.preventDefault();
  6163. return;
  6164. }
  6165. if (evt.button === 0) {
  6166. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6167. if (!isInternalLink) {
  6168. evt.preventDefault();
  6169. if (evt.shiftKey) {
  6170. this.pdfViewer.previousPage();
  6171. } else {
  6172. this.pdfViewer.nextPage();
  6173. }
  6174. }
  6175. }
  6176. }
  6177. #contextMenu() {
  6178. this.contextMenuOpen = true;
  6179. }
  6180. #showControls() {
  6181. if (this.controlsTimeout) {
  6182. clearTimeout(this.controlsTimeout);
  6183. } else {
  6184. this.container.classList.add(CONTROLS_SELECTOR);
  6185. }
  6186. this.controlsTimeout = setTimeout(() => {
  6187. this.container.classList.remove(CONTROLS_SELECTOR);
  6188. delete this.controlsTimeout;
  6189. }, DELAY_BEFORE_HIDING_CONTROLS);
  6190. }
  6191. #hideControls() {
  6192. if (!this.controlsTimeout) {
  6193. return;
  6194. }
  6195. clearTimeout(this.controlsTimeout);
  6196. this.container.classList.remove(CONTROLS_SELECTOR);
  6197. delete this.controlsTimeout;
  6198. }
  6199. #resetMouseScrollState() {
  6200. this.mouseScrollTimeStamp = 0;
  6201. this.mouseScrollDelta = 0;
  6202. }
  6203. #touchSwipe(evt) {
  6204. if (!this.active) {
  6205. return;
  6206. }
  6207. if (evt.touches.length > 1) {
  6208. this.touchSwipeState = null;
  6209. return;
  6210. }
  6211. switch (evt.type) {
  6212. case "touchstart":
  6213. this.touchSwipeState = {
  6214. startX: evt.touches[0].pageX,
  6215. startY: evt.touches[0].pageY,
  6216. endX: evt.touches[0].pageX,
  6217. endY: evt.touches[0].pageY
  6218. };
  6219. break;
  6220. case "touchmove":
  6221. if (this.touchSwipeState === null) {
  6222. return;
  6223. }
  6224. this.touchSwipeState.endX = evt.touches[0].pageX;
  6225. this.touchSwipeState.endY = evt.touches[0].pageY;
  6226. evt.preventDefault();
  6227. break;
  6228. case "touchend":
  6229. if (this.touchSwipeState === null) {
  6230. return;
  6231. }
  6232. let delta = 0;
  6233. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6234. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6235. const absAngle = Math.abs(Math.atan2(dy, dx));
  6236. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6237. delta = dx;
  6238. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6239. delta = dy;
  6240. }
  6241. if (delta > 0) {
  6242. this.pdfViewer.previousPage();
  6243. } else if (delta < 0) {
  6244. this.pdfViewer.nextPage();
  6245. }
  6246. break;
  6247. }
  6248. }
  6249. #addWindowListeners() {
  6250. this.showControlsBind = this.#showControls.bind(this);
  6251. this.mouseDownBind = this.#mouseDown.bind(this);
  6252. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6253. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6254. this.contextMenuBind = this.#contextMenu.bind(this);
  6255. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6256. window.addEventListener("mousemove", this.showControlsBind);
  6257. window.addEventListener("mousedown", this.mouseDownBind);
  6258. window.addEventListener("wheel", this.mouseWheelBind, {
  6259. passive: false
  6260. });
  6261. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6262. window.addEventListener("contextmenu", this.contextMenuBind);
  6263. window.addEventListener("touchstart", this.touchSwipeBind);
  6264. window.addEventListener("touchmove", this.touchSwipeBind);
  6265. window.addEventListener("touchend", this.touchSwipeBind);
  6266. }
  6267. #removeWindowListeners() {
  6268. window.removeEventListener("mousemove", this.showControlsBind);
  6269. window.removeEventListener("mousedown", this.mouseDownBind);
  6270. window.removeEventListener("wheel", this.mouseWheelBind, {
  6271. passive: false
  6272. });
  6273. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6274. window.removeEventListener("contextmenu", this.contextMenuBind);
  6275. window.removeEventListener("touchstart", this.touchSwipeBind);
  6276. window.removeEventListener("touchmove", this.touchSwipeBind);
  6277. window.removeEventListener("touchend", this.touchSwipeBind);
  6278. delete this.showControlsBind;
  6279. delete this.mouseDownBind;
  6280. delete this.mouseWheelBind;
  6281. delete this.resetMouseScrollStateBind;
  6282. delete this.contextMenuBind;
  6283. delete this.touchSwipeBind;
  6284. }
  6285. #fullscreenChange() {
  6286. if (document.fullscreenElement) {
  6287. this.#enter();
  6288. } else {
  6289. this.#exit();
  6290. }
  6291. }
  6292. #addFullscreenChangeListeners() {
  6293. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6294. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6295. }
  6296. #removeFullscreenChangeListeners() {
  6297. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6298. delete this.fullscreenChangeBind;
  6299. }
  6300. }
  6301. exports.PDFPresentationMode = PDFPresentationMode;
  6302. /***/ }),
  6303. /* 21 */
  6304. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6305. Object.defineProperty(exports, "__esModule", ({
  6306. value: true
  6307. }));
  6308. exports.PDFRenderingQueue = void 0;
  6309. var _pdfjsLib = __webpack_require__(5);
  6310. var _ui_utils = __webpack_require__(3);
  6311. const CLEANUP_TIMEOUT = 30000;
  6312. class PDFRenderingQueue {
  6313. constructor() {
  6314. this.pdfViewer = null;
  6315. this.pdfThumbnailViewer = null;
  6316. this.onIdle = null;
  6317. this.highestPriorityPage = null;
  6318. this.idleTimeout = null;
  6319. this.printing = false;
  6320. this.isThumbnailViewEnabled = false;
  6321. }
  6322. setViewer(pdfViewer) {
  6323. this.pdfViewer = pdfViewer;
  6324. }
  6325. setThumbnailViewer(pdfThumbnailViewer) {
  6326. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6327. }
  6328. isHighestPriority(view) {
  6329. return this.highestPriorityPage === view.renderingId;
  6330. }
  6331. hasViewer() {
  6332. return !!this.pdfViewer;
  6333. }
  6334. renderHighestPriority(currentlyVisiblePages) {
  6335. if (this.idleTimeout) {
  6336. clearTimeout(this.idleTimeout);
  6337. this.idleTimeout = null;
  6338. }
  6339. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6340. return;
  6341. }
  6342. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6343. return;
  6344. }
  6345. if (this.printing) {
  6346. return;
  6347. }
  6348. if (this.onIdle) {
  6349. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6350. }
  6351. }
  6352. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6353. const visibleViews = visible.views,
  6354. numVisible = visibleViews.length;
  6355. if (numVisible === 0) {
  6356. return null;
  6357. }
  6358. for (let i = 0; i < numVisible; i++) {
  6359. const view = visibleViews[i].view;
  6360. if (!this.isViewFinished(view)) {
  6361. return view;
  6362. }
  6363. }
  6364. const firstId = visible.first.id,
  6365. lastId = visible.last.id;
  6366. if (lastId - firstId + 1 > numVisible) {
  6367. const visibleIds = visible.ids;
  6368. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6369. const holeId = scrolledDown ? firstId + i : lastId - i;
  6370. if (visibleIds.has(holeId)) {
  6371. continue;
  6372. }
  6373. const holeView = views[holeId - 1];
  6374. if (!this.isViewFinished(holeView)) {
  6375. return holeView;
  6376. }
  6377. }
  6378. }
  6379. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6380. let preRenderView = views[preRenderIndex];
  6381. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6382. return preRenderView;
  6383. }
  6384. if (preRenderExtra) {
  6385. preRenderIndex += scrolledDown ? 1 : -1;
  6386. preRenderView = views[preRenderIndex];
  6387. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6388. return preRenderView;
  6389. }
  6390. }
  6391. return null;
  6392. }
  6393. isViewFinished(view) {
  6394. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6395. }
  6396. renderView(view) {
  6397. switch (view.renderingState) {
  6398. case _ui_utils.RenderingStates.FINISHED:
  6399. return false;
  6400. case _ui_utils.RenderingStates.PAUSED:
  6401. this.highestPriorityPage = view.renderingId;
  6402. view.resume();
  6403. break;
  6404. case _ui_utils.RenderingStates.RUNNING:
  6405. this.highestPriorityPage = view.renderingId;
  6406. break;
  6407. case _ui_utils.RenderingStates.INITIAL:
  6408. this.highestPriorityPage = view.renderingId;
  6409. view.draw().finally(() => {
  6410. this.renderHighestPriority();
  6411. }).catch(reason => {
  6412. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6413. return;
  6414. }
  6415. console.error(`renderView: "${reason}"`);
  6416. });
  6417. break;
  6418. }
  6419. return true;
  6420. }
  6421. }
  6422. exports.PDFRenderingQueue = PDFRenderingQueue;
  6423. /***/ }),
  6424. /* 22 */
  6425. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6426. Object.defineProperty(exports, "__esModule", ({
  6427. value: true
  6428. }));
  6429. exports.PDFScriptingManager = void 0;
  6430. var _ui_utils = __webpack_require__(3);
  6431. var _pdfjsLib = __webpack_require__(5);
  6432. class PDFScriptingManager {
  6433. constructor({
  6434. eventBus,
  6435. sandboxBundleSrc = null,
  6436. scriptingFactory = null,
  6437. docPropertiesLookup = null
  6438. }) {
  6439. this._pdfDocument = null;
  6440. this._pdfViewer = null;
  6441. this._closeCapability = null;
  6442. this._destroyCapability = null;
  6443. this._scripting = null;
  6444. this._mouseState = Object.create(null);
  6445. this._ready = false;
  6446. this._eventBus = eventBus;
  6447. this._sandboxBundleSrc = sandboxBundleSrc;
  6448. this._scriptingFactory = scriptingFactory;
  6449. this._docPropertiesLookup = docPropertiesLookup;
  6450. }
  6451. setViewer(pdfViewer) {
  6452. this._pdfViewer = pdfViewer;
  6453. }
  6454. async setDocument(pdfDocument) {
  6455. if (this._pdfDocument) {
  6456. await this._destroyScripting();
  6457. }
  6458. this._pdfDocument = pdfDocument;
  6459. if (!pdfDocument) {
  6460. return;
  6461. }
  6462. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6463. if (!objects && !docActions) {
  6464. await this._destroyScripting();
  6465. return;
  6466. }
  6467. if (pdfDocument !== this._pdfDocument) {
  6468. return;
  6469. }
  6470. try {
  6471. this._scripting = this._createScripting();
  6472. } catch (error) {
  6473. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6474. await this._destroyScripting();
  6475. return;
  6476. }
  6477. this._internalEvents.set("updatefromsandbox", event => {
  6478. if (event?.source !== window) {
  6479. return;
  6480. }
  6481. this._updateFromSandbox(event.detail);
  6482. });
  6483. this._internalEvents.set("dispatcheventinsandbox", event => {
  6484. this._scripting?.dispatchEventInSandbox(event.detail);
  6485. });
  6486. this._internalEvents.set("pagechanging", ({
  6487. pageNumber,
  6488. previous
  6489. }) => {
  6490. if (pageNumber === previous) {
  6491. return;
  6492. }
  6493. this._dispatchPageClose(previous);
  6494. this._dispatchPageOpen(pageNumber);
  6495. });
  6496. this._internalEvents.set("pagerendered", ({
  6497. pageNumber
  6498. }) => {
  6499. if (!this._pageOpenPending.has(pageNumber)) {
  6500. return;
  6501. }
  6502. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6503. return;
  6504. }
  6505. this._dispatchPageOpen(pageNumber);
  6506. });
  6507. this._internalEvents.set("pagesdestroy", async event => {
  6508. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6509. await this._scripting?.dispatchEventInSandbox({
  6510. id: "doc",
  6511. name: "WillClose"
  6512. });
  6513. this._closeCapability?.resolve();
  6514. });
  6515. this._domEvents.set("mousedown", event => {
  6516. this._mouseState.isDown = true;
  6517. });
  6518. this._domEvents.set("mouseup", event => {
  6519. this._mouseState.isDown = false;
  6520. });
  6521. for (const [name, listener] of this._internalEvents) {
  6522. this._eventBus._on(name, listener);
  6523. }
  6524. for (const [name, listener] of this._domEvents) {
  6525. window.addEventListener(name, listener, true);
  6526. }
  6527. try {
  6528. const docProperties = await this._getDocProperties();
  6529. if (pdfDocument !== this._pdfDocument) {
  6530. return;
  6531. }
  6532. await this._scripting.createSandbox({
  6533. objects,
  6534. calculationOrder,
  6535. appInfo: {
  6536. platform: navigator.platform,
  6537. language: navigator.language
  6538. },
  6539. docInfo: { ...docProperties,
  6540. actions: docActions
  6541. }
  6542. });
  6543. this._eventBus.dispatch("sandboxcreated", {
  6544. source: this
  6545. });
  6546. } catch (error) {
  6547. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6548. await this._destroyScripting();
  6549. return;
  6550. }
  6551. await this._scripting?.dispatchEventInSandbox({
  6552. id: "doc",
  6553. name: "Open"
  6554. });
  6555. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6556. Promise.resolve().then(() => {
  6557. if (pdfDocument === this._pdfDocument) {
  6558. this._ready = true;
  6559. }
  6560. });
  6561. }
  6562. async dispatchWillSave(detail) {
  6563. return this._scripting?.dispatchEventInSandbox({
  6564. id: "doc",
  6565. name: "WillSave"
  6566. });
  6567. }
  6568. async dispatchDidSave(detail) {
  6569. return this._scripting?.dispatchEventInSandbox({
  6570. id: "doc",
  6571. name: "DidSave"
  6572. });
  6573. }
  6574. async dispatchWillPrint(detail) {
  6575. return this._scripting?.dispatchEventInSandbox({
  6576. id: "doc",
  6577. name: "WillPrint"
  6578. });
  6579. }
  6580. async dispatchDidPrint(detail) {
  6581. return this._scripting?.dispatchEventInSandbox({
  6582. id: "doc",
  6583. name: "DidPrint"
  6584. });
  6585. }
  6586. get mouseState() {
  6587. return this._mouseState;
  6588. }
  6589. get destroyPromise() {
  6590. return this._destroyCapability?.promise || null;
  6591. }
  6592. get ready() {
  6593. return this._ready;
  6594. }
  6595. get _internalEvents() {
  6596. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6597. }
  6598. get _domEvents() {
  6599. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6600. }
  6601. get _pageOpenPending() {
  6602. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6603. }
  6604. get _visitedPages() {
  6605. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6606. }
  6607. async _updateFromSandbox(detail) {
  6608. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6609. const {
  6610. id,
  6611. siblings,
  6612. command,
  6613. value
  6614. } = detail;
  6615. if (!id) {
  6616. switch (command) {
  6617. case "clear":
  6618. console.clear();
  6619. break;
  6620. case "error":
  6621. console.error(value);
  6622. break;
  6623. case "layout":
  6624. if (isInPresentationMode) {
  6625. return;
  6626. }
  6627. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  6628. this._pdfViewer.spreadMode = modes.spreadMode;
  6629. break;
  6630. case "page-num":
  6631. this._pdfViewer.currentPageNumber = value + 1;
  6632. break;
  6633. case "print":
  6634. await this._pdfViewer.pagesPromise;
  6635. this._eventBus.dispatch("print", {
  6636. source: this
  6637. });
  6638. break;
  6639. case "println":
  6640. console.log(value);
  6641. break;
  6642. case "zoom":
  6643. if (isInPresentationMode) {
  6644. return;
  6645. }
  6646. this._pdfViewer.currentScaleValue = value;
  6647. break;
  6648. case "SaveAs":
  6649. this._eventBus.dispatch("save", {
  6650. source: this
  6651. });
  6652. break;
  6653. case "FirstPage":
  6654. this._pdfViewer.currentPageNumber = 1;
  6655. break;
  6656. case "LastPage":
  6657. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  6658. break;
  6659. case "NextPage":
  6660. this._pdfViewer.nextPage();
  6661. break;
  6662. case "PrevPage":
  6663. this._pdfViewer.previousPage();
  6664. break;
  6665. case "ZoomViewIn":
  6666. if (isInPresentationMode) {
  6667. return;
  6668. }
  6669. this._pdfViewer.increaseScale();
  6670. break;
  6671. case "ZoomViewOut":
  6672. if (isInPresentationMode) {
  6673. return;
  6674. }
  6675. this._pdfViewer.decreaseScale();
  6676. break;
  6677. }
  6678. return;
  6679. }
  6680. if (isInPresentationMode) {
  6681. if (detail.focus) {
  6682. return;
  6683. }
  6684. }
  6685. delete detail.id;
  6686. delete detail.siblings;
  6687. const ids = siblings ? [id, ...siblings] : [id];
  6688. for (const elementId of ids) {
  6689. const element = document.getElementById(elementId);
  6690. if (element) {
  6691. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6692. detail
  6693. }));
  6694. } else {
  6695. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6696. }
  6697. }
  6698. }
  6699. async _dispatchPageOpen(pageNumber, initialize = false) {
  6700. const pdfDocument = this._pdfDocument,
  6701. visitedPages = this._visitedPages;
  6702. if (initialize) {
  6703. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6704. }
  6705. if (!this._closeCapability) {
  6706. return;
  6707. }
  6708. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6709. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  6710. this._pageOpenPending.add(pageNumber);
  6711. return;
  6712. }
  6713. this._pageOpenPending.delete(pageNumber);
  6714. const actionsPromise = (async () => {
  6715. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6716. if (pdfDocument !== this._pdfDocument) {
  6717. return;
  6718. }
  6719. await this._scripting?.dispatchEventInSandbox({
  6720. id: "page",
  6721. name: "PageOpen",
  6722. pageNumber,
  6723. actions
  6724. });
  6725. })();
  6726. visitedPages.set(pageNumber, actionsPromise);
  6727. }
  6728. async _dispatchPageClose(pageNumber) {
  6729. const pdfDocument = this._pdfDocument,
  6730. visitedPages = this._visitedPages;
  6731. if (!this._closeCapability) {
  6732. return;
  6733. }
  6734. if (this._pageOpenPending.has(pageNumber)) {
  6735. return;
  6736. }
  6737. const actionsPromise = visitedPages.get(pageNumber);
  6738. if (!actionsPromise) {
  6739. return;
  6740. }
  6741. visitedPages.set(pageNumber, null);
  6742. await actionsPromise;
  6743. if (pdfDocument !== this._pdfDocument) {
  6744. return;
  6745. }
  6746. await this._scripting?.dispatchEventInSandbox({
  6747. id: "page",
  6748. name: "PageClose",
  6749. pageNumber
  6750. });
  6751. }
  6752. async _getDocProperties() {
  6753. if (this._docPropertiesLookup) {
  6754. return this._docPropertiesLookup(this._pdfDocument);
  6755. }
  6756. throw new Error("_getDocProperties: Unable to lookup properties.");
  6757. }
  6758. _createScripting() {
  6759. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  6760. if (this._scripting) {
  6761. throw new Error("_createScripting: Scripting already exists.");
  6762. }
  6763. if (this._scriptingFactory) {
  6764. return this._scriptingFactory.createScripting({
  6765. sandboxBundleSrc: this._sandboxBundleSrc
  6766. });
  6767. }
  6768. throw new Error("_createScripting: Cannot create scripting.");
  6769. }
  6770. async _destroyScripting() {
  6771. if (!this._scripting) {
  6772. this._pdfDocument = null;
  6773. this._destroyCapability?.resolve();
  6774. return;
  6775. }
  6776. if (this._closeCapability) {
  6777. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  6778. setTimeout(resolve, 1000);
  6779. })]).catch(reason => {});
  6780. this._closeCapability = null;
  6781. }
  6782. this._pdfDocument = null;
  6783. try {
  6784. await this._scripting.destroySandbox();
  6785. } catch (ex) {}
  6786. for (const [name, listener] of this._internalEvents) {
  6787. this._eventBus._off(name, listener);
  6788. }
  6789. this._internalEvents.clear();
  6790. for (const [name, listener] of this._domEvents) {
  6791. window.removeEventListener(name, listener, true);
  6792. }
  6793. this._domEvents.clear();
  6794. this._pageOpenPending.clear();
  6795. this._visitedPages.clear();
  6796. this._scripting = null;
  6797. delete this._mouseState.isDown;
  6798. this._ready = false;
  6799. this._destroyCapability?.resolve();
  6800. }
  6801. }
  6802. exports.PDFScriptingManager = PDFScriptingManager;
  6803. /***/ }),
  6804. /* 23 */
  6805. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6806. Object.defineProperty(exports, "__esModule", ({
  6807. value: true
  6808. }));
  6809. exports.PDFSidebar = void 0;
  6810. var _ui_utils = __webpack_require__(3);
  6811. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  6812. class PDFSidebar {
  6813. constructor({
  6814. elements,
  6815. pdfViewer,
  6816. pdfThumbnailViewer,
  6817. eventBus,
  6818. l10n
  6819. }) {
  6820. this.isOpen = false;
  6821. this.active = _ui_utils.SidebarView.THUMBS;
  6822. this.isInitialViewSet = false;
  6823. this.onToggled = null;
  6824. this.pdfViewer = pdfViewer;
  6825. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6826. this.outerContainer = elements.outerContainer;
  6827. this.sidebarContainer = elements.sidebarContainer;
  6828. this.toggleButton = elements.toggleButton;
  6829. this.thumbnailButton = elements.thumbnailButton;
  6830. this.outlineButton = elements.outlineButton;
  6831. this.attachmentsButton = elements.attachmentsButton;
  6832. this.layersButton = elements.layersButton;
  6833. this.thumbnailView = elements.thumbnailView;
  6834. this.outlineView = elements.outlineView;
  6835. this.attachmentsView = elements.attachmentsView;
  6836. this.layersView = elements.layersView;
  6837. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  6838. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  6839. this.eventBus = eventBus;
  6840. this.l10n = l10n;
  6841. this._addEventListeners();
  6842. }
  6843. reset() {
  6844. this.isInitialViewSet = false;
  6845. this._hideUINotification(true);
  6846. this.switchView(_ui_utils.SidebarView.THUMBS);
  6847. this.outlineButton.disabled = false;
  6848. this.attachmentsButton.disabled = false;
  6849. this.layersButton.disabled = false;
  6850. this._currentOutlineItemButton.disabled = true;
  6851. }
  6852. get visibleView() {
  6853. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  6854. }
  6855. get isThumbnailViewVisible() {
  6856. return this.isOpen && this.active === _ui_utils.SidebarView.THUMBS;
  6857. }
  6858. get isOutlineViewVisible() {
  6859. return this.isOpen && this.active === _ui_utils.SidebarView.OUTLINE;
  6860. }
  6861. get isAttachmentsViewVisible() {
  6862. return this.isOpen && this.active === _ui_utils.SidebarView.ATTACHMENTS;
  6863. }
  6864. get isLayersViewVisible() {
  6865. return this.isOpen && this.active === _ui_utils.SidebarView.LAYERS;
  6866. }
  6867. setInitialView(view = _ui_utils.SidebarView.NONE) {
  6868. if (this.isInitialViewSet) {
  6869. return;
  6870. }
  6871. this.isInitialViewSet = true;
  6872. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  6873. this._dispatchEvent();
  6874. return;
  6875. }
  6876. if (!this._switchView(view, true)) {
  6877. this._dispatchEvent();
  6878. }
  6879. }
  6880. switchView(view, forceOpen = false) {
  6881. this._switchView(view, forceOpen);
  6882. }
  6883. _switchView(view, forceOpen = false) {
  6884. const isViewChanged = view !== this.active;
  6885. let shouldForceRendering = false;
  6886. switch (view) {
  6887. case _ui_utils.SidebarView.NONE:
  6888. if (this.isOpen) {
  6889. this.close();
  6890. return true;
  6891. }
  6892. return false;
  6893. case _ui_utils.SidebarView.THUMBS:
  6894. if (this.isOpen && isViewChanged) {
  6895. shouldForceRendering = true;
  6896. }
  6897. break;
  6898. case _ui_utils.SidebarView.OUTLINE:
  6899. if (this.outlineButton.disabled) {
  6900. return false;
  6901. }
  6902. break;
  6903. case _ui_utils.SidebarView.ATTACHMENTS:
  6904. if (this.attachmentsButton.disabled) {
  6905. return false;
  6906. }
  6907. break;
  6908. case _ui_utils.SidebarView.LAYERS:
  6909. if (this.layersButton.disabled) {
  6910. return false;
  6911. }
  6912. break;
  6913. default:
  6914. console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
  6915. return false;
  6916. }
  6917. this.active = view;
  6918. const isThumbs = view === _ui_utils.SidebarView.THUMBS,
  6919. isOutline = view === _ui_utils.SidebarView.OUTLINE,
  6920. isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS,
  6921. isLayers = view === _ui_utils.SidebarView.LAYERS;
  6922. this.thumbnailButton.classList.toggle("toggled", isThumbs);
  6923. this.outlineButton.classList.toggle("toggled", isOutline);
  6924. this.attachmentsButton.classList.toggle("toggled", isAttachments);
  6925. this.layersButton.classList.toggle("toggled", isLayers);
  6926. this.thumbnailButton.setAttribute("aria-checked", isThumbs);
  6927. this.outlineButton.setAttribute("aria-checked", isOutline);
  6928. this.attachmentsButton.setAttribute("aria-checked", isAttachments);
  6929. this.layersButton.setAttribute("aria-checked", isLayers);
  6930. this.thumbnailView.classList.toggle("hidden", !isThumbs);
  6931. this.outlineView.classList.toggle("hidden", !isOutline);
  6932. this.attachmentsView.classList.toggle("hidden", !isAttachments);
  6933. this.layersView.classList.toggle("hidden", !isLayers);
  6934. this._outlineOptionsContainer.classList.toggle("hidden", !isOutline);
  6935. if (forceOpen && !this.isOpen) {
  6936. this.open();
  6937. return true;
  6938. }
  6939. if (shouldForceRendering) {
  6940. this._updateThumbnailViewer();
  6941. this._forceRendering();
  6942. }
  6943. if (isViewChanged) {
  6944. this._dispatchEvent();
  6945. }
  6946. return isViewChanged;
  6947. }
  6948. open() {
  6949. if (this.isOpen) {
  6950. return;
  6951. }
  6952. this.isOpen = true;
  6953. this.toggleButton.classList.add("toggled");
  6954. this.toggleButton.setAttribute("aria-expanded", "true");
  6955. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  6956. if (this.active === _ui_utils.SidebarView.THUMBS) {
  6957. this._updateThumbnailViewer();
  6958. }
  6959. this._forceRendering();
  6960. this._dispatchEvent();
  6961. this._hideUINotification();
  6962. }
  6963. close() {
  6964. if (!this.isOpen) {
  6965. return;
  6966. }
  6967. this.isOpen = false;
  6968. this.toggleButton.classList.remove("toggled");
  6969. this.toggleButton.setAttribute("aria-expanded", "false");
  6970. this.outerContainer.classList.add("sidebarMoving");
  6971. this.outerContainer.classList.remove("sidebarOpen");
  6972. this._forceRendering();
  6973. this._dispatchEvent();
  6974. }
  6975. toggle() {
  6976. if (this.isOpen) {
  6977. this.close();
  6978. } else {
  6979. this.open();
  6980. }
  6981. }
  6982. _dispatchEvent() {
  6983. this.eventBus.dispatch("sidebarviewchanged", {
  6984. source: this,
  6985. view: this.visibleView
  6986. });
  6987. }
  6988. _forceRendering() {
  6989. if (this.onToggled) {
  6990. this.onToggled();
  6991. } else {
  6992. this.pdfViewer.forceRendering();
  6993. this.pdfThumbnailViewer.forceRendering();
  6994. }
  6995. }
  6996. _updateThumbnailViewer() {
  6997. const {
  6998. pdfViewer,
  6999. pdfThumbnailViewer
  7000. } = this;
  7001. const pagesCount = pdfViewer.pagesCount;
  7002. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  7003. const pageView = pdfViewer.getPageView(pageIndex);
  7004. if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) {
  7005. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  7006. thumbnailView.setImage(pageView);
  7007. }
  7008. }
  7009. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  7010. }
  7011. _showUINotification() {
  7012. this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
  7013. this.toggleButton.title = msg;
  7014. });
  7015. if (!this.isOpen) {
  7016. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7017. }
  7018. }
  7019. _hideUINotification(reset = false) {
  7020. if (this.isOpen || reset) {
  7021. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7022. }
  7023. if (reset) {
  7024. this.l10n.get("toggle_sidebar.title").then(msg => {
  7025. this.toggleButton.title = msg;
  7026. });
  7027. }
  7028. }
  7029. _addEventListeners() {
  7030. this.sidebarContainer.addEventListener("transitionend", evt => {
  7031. if (evt.target === this.sidebarContainer) {
  7032. this.outerContainer.classList.remove("sidebarMoving");
  7033. }
  7034. });
  7035. this.toggleButton.addEventListener("click", () => {
  7036. this.toggle();
  7037. });
  7038. this.thumbnailButton.addEventListener("click", () => {
  7039. this.switchView(_ui_utils.SidebarView.THUMBS);
  7040. });
  7041. this.outlineButton.addEventListener("click", () => {
  7042. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7043. });
  7044. this.outlineButton.addEventListener("dblclick", () => {
  7045. this.eventBus.dispatch("toggleoutlinetree", {
  7046. source: this
  7047. });
  7048. });
  7049. this.attachmentsButton.addEventListener("click", () => {
  7050. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7051. });
  7052. this.layersButton.addEventListener("click", () => {
  7053. this.switchView(_ui_utils.SidebarView.LAYERS);
  7054. });
  7055. this.layersButton.addEventListener("dblclick", () => {
  7056. this.eventBus.dispatch("resetlayers", {
  7057. source: this
  7058. });
  7059. });
  7060. this._currentOutlineItemButton.addEventListener("click", () => {
  7061. this.eventBus.dispatch("currentoutlineitem", {
  7062. source: this
  7063. });
  7064. });
  7065. const onTreeLoaded = (count, button, view) => {
  7066. button.disabled = !count;
  7067. if (count) {
  7068. this._showUINotification();
  7069. } else if (this.active === view) {
  7070. this.switchView(_ui_utils.SidebarView.THUMBS);
  7071. }
  7072. };
  7073. this.eventBus._on("outlineloaded", evt => {
  7074. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7075. evt.currentOutlineItemPromise.then(enabled => {
  7076. if (!this.isInitialViewSet) {
  7077. return;
  7078. }
  7079. this._currentOutlineItemButton.disabled = !enabled;
  7080. });
  7081. });
  7082. this.eventBus._on("attachmentsloaded", evt => {
  7083. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7084. });
  7085. this.eventBus._on("layersloaded", evt => {
  7086. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7087. });
  7088. this.eventBus._on("presentationmodechanged", evt => {
  7089. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.isThumbnailViewVisible) {
  7090. this._updateThumbnailViewer();
  7091. }
  7092. });
  7093. }
  7094. }
  7095. exports.PDFSidebar = PDFSidebar;
  7096. /***/ }),
  7097. /* 24 */
  7098. /***/ ((__unused_webpack_module, exports) => {
  7099. Object.defineProperty(exports, "__esModule", ({
  7100. value: true
  7101. }));
  7102. exports.PDFSidebarResizer = void 0;
  7103. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7104. const SIDEBAR_MIN_WIDTH = 200;
  7105. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7106. class PDFSidebarResizer {
  7107. constructor(options, eventBus, l10n) {
  7108. this.isRTL = false;
  7109. this.sidebarOpen = false;
  7110. this.doc = document.documentElement;
  7111. this._width = null;
  7112. this._outerContainerWidth = null;
  7113. this._boundEvents = Object.create(null);
  7114. this.outerContainer = options.outerContainer;
  7115. this.resizer = options.resizer;
  7116. this.eventBus = eventBus;
  7117. l10n.getDirection().then(dir => {
  7118. this.isRTL = dir === "rtl";
  7119. });
  7120. this._addEventListeners();
  7121. }
  7122. get outerContainerWidth() {
  7123. return this._outerContainerWidth ||= this.outerContainer.clientWidth;
  7124. }
  7125. _updateWidth(width = 0) {
  7126. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7127. if (width > maxWidth) {
  7128. width = maxWidth;
  7129. }
  7130. if (width < SIDEBAR_MIN_WIDTH) {
  7131. width = SIDEBAR_MIN_WIDTH;
  7132. }
  7133. if (width === this._width) {
  7134. return false;
  7135. }
  7136. this._width = width;
  7137. this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7138. return true;
  7139. }
  7140. _mouseMove(evt) {
  7141. let width = evt.clientX;
  7142. if (this.isRTL) {
  7143. width = this.outerContainerWidth - width;
  7144. }
  7145. this._updateWidth(width);
  7146. }
  7147. _mouseUp(evt) {
  7148. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7149. this.eventBus.dispatch("resize", {
  7150. source: this
  7151. });
  7152. const _boundEvents = this._boundEvents;
  7153. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7154. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7155. }
  7156. _addEventListeners() {
  7157. const _boundEvents = this._boundEvents;
  7158. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7159. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7160. this.resizer.addEventListener("mousedown", evt => {
  7161. if (evt.button !== 0) {
  7162. return;
  7163. }
  7164. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7165. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7166. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7167. });
  7168. this.eventBus._on("sidebarviewchanged", evt => {
  7169. this.sidebarOpen = !!evt?.view;
  7170. });
  7171. this.eventBus._on("resize", evt => {
  7172. if (evt?.source !== window) {
  7173. return;
  7174. }
  7175. this._outerContainerWidth = null;
  7176. if (!this._width) {
  7177. return;
  7178. }
  7179. if (!this.sidebarOpen) {
  7180. this._updateWidth(this._width);
  7181. return;
  7182. }
  7183. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7184. const updated = this._updateWidth(this._width);
  7185. Promise.resolve().then(() => {
  7186. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7187. if (updated) {
  7188. this.eventBus.dispatch("resize", {
  7189. source: this
  7190. });
  7191. }
  7192. });
  7193. });
  7194. }
  7195. }
  7196. exports.PDFSidebarResizer = PDFSidebarResizer;
  7197. /***/ }),
  7198. /* 25 */
  7199. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7200. Object.defineProperty(exports, "__esModule", ({
  7201. value: true
  7202. }));
  7203. exports.PDFThumbnailViewer = void 0;
  7204. var _ui_utils = __webpack_require__(3);
  7205. var _pdf_thumbnail_view = __webpack_require__(26);
  7206. const THUMBNAIL_SCROLL_MARGIN = -19;
  7207. const THUMBNAIL_SELECTED_CLASS = "selected";
  7208. class PDFThumbnailViewer {
  7209. constructor({
  7210. container,
  7211. eventBus,
  7212. linkService,
  7213. renderingQueue,
  7214. l10n
  7215. }) {
  7216. this.container = container;
  7217. this.linkService = linkService;
  7218. this.renderingQueue = renderingQueue;
  7219. this.l10n = l10n;
  7220. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7221. this._resetView();
  7222. eventBus._on("optionalcontentconfigchanged", () => {
  7223. this._setImageDisabled = true;
  7224. });
  7225. }
  7226. _scrollUpdated() {
  7227. this.renderingQueue.renderHighestPriority();
  7228. }
  7229. getThumbnail(index) {
  7230. return this._thumbnails[index];
  7231. }
  7232. _getVisibleThumbs() {
  7233. return (0, _ui_utils.getVisibleElements)({
  7234. scrollEl: this.container,
  7235. views: this._thumbnails
  7236. });
  7237. }
  7238. scrollThumbnailIntoView(pageNumber) {
  7239. if (!this.pdfDocument) {
  7240. return;
  7241. }
  7242. const thumbnailView = this._thumbnails[pageNumber - 1];
  7243. if (!thumbnailView) {
  7244. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7245. return;
  7246. }
  7247. if (pageNumber !== this._currentPageNumber) {
  7248. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7249. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7250. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7251. }
  7252. const {
  7253. first,
  7254. last,
  7255. views
  7256. } = this._getVisibleThumbs();
  7257. if (views.length > 0) {
  7258. let shouldScroll = false;
  7259. if (pageNumber <= first.id || pageNumber >= last.id) {
  7260. shouldScroll = true;
  7261. } else {
  7262. for (const {
  7263. id,
  7264. percent
  7265. } of views) {
  7266. if (id !== pageNumber) {
  7267. continue;
  7268. }
  7269. shouldScroll = percent < 100;
  7270. break;
  7271. }
  7272. }
  7273. if (shouldScroll) {
  7274. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7275. top: THUMBNAIL_SCROLL_MARGIN
  7276. });
  7277. }
  7278. }
  7279. this._currentPageNumber = pageNumber;
  7280. }
  7281. get pagesRotation() {
  7282. return this._pagesRotation;
  7283. }
  7284. set pagesRotation(rotation) {
  7285. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7286. throw new Error("Invalid thumbnails rotation angle.");
  7287. }
  7288. if (!this.pdfDocument) {
  7289. return;
  7290. }
  7291. if (this._pagesRotation === rotation) {
  7292. return;
  7293. }
  7294. this._pagesRotation = rotation;
  7295. const updateArgs = {
  7296. rotation
  7297. };
  7298. for (const thumbnail of this._thumbnails) {
  7299. thumbnail.update(updateArgs);
  7300. }
  7301. }
  7302. cleanup() {
  7303. for (const thumbnail of this._thumbnails) {
  7304. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7305. thumbnail.reset();
  7306. }
  7307. }
  7308. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7309. }
  7310. _resetView() {
  7311. this._thumbnails = [];
  7312. this._currentPageNumber = 1;
  7313. this._pageLabels = null;
  7314. this._pagesRotation = 0;
  7315. this._optionalContentConfigPromise = null;
  7316. this._setImageDisabled = false;
  7317. this.container.textContent = "";
  7318. }
  7319. setDocument(pdfDocument) {
  7320. if (this.pdfDocument) {
  7321. this._cancelRendering();
  7322. this._resetView();
  7323. }
  7324. this.pdfDocument = pdfDocument;
  7325. if (!pdfDocument) {
  7326. return;
  7327. }
  7328. const firstPagePromise = pdfDocument.getPage(1);
  7329. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7330. firstPagePromise.then(firstPdfPage => {
  7331. this._optionalContentConfigPromise = optionalContentConfigPromise;
  7332. const pagesCount = pdfDocument.numPages;
  7333. const viewport = firstPdfPage.getViewport({
  7334. scale: 1
  7335. });
  7336. const checkSetImageDisabled = () => {
  7337. return this._setImageDisabled;
  7338. };
  7339. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7340. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7341. container: this.container,
  7342. id: pageNum,
  7343. defaultViewport: viewport.clone(),
  7344. optionalContentConfigPromise,
  7345. linkService: this.linkService,
  7346. renderingQueue: this.renderingQueue,
  7347. checkSetImageDisabled,
  7348. l10n: this.l10n
  7349. });
  7350. this._thumbnails.push(thumbnail);
  7351. }
  7352. const firstThumbnailView = this._thumbnails[0];
  7353. if (firstThumbnailView) {
  7354. firstThumbnailView.setPdfPage(firstPdfPage);
  7355. }
  7356. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7357. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7358. }).catch(reason => {
  7359. console.error("Unable to initialize thumbnail viewer", reason);
  7360. });
  7361. }
  7362. _cancelRendering() {
  7363. for (const thumbnail of this._thumbnails) {
  7364. thumbnail.cancelRendering();
  7365. }
  7366. }
  7367. setPageLabels(labels) {
  7368. if (!this.pdfDocument) {
  7369. return;
  7370. }
  7371. if (!labels) {
  7372. this._pageLabels = null;
  7373. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7374. this._pageLabels = null;
  7375. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7376. } else {
  7377. this._pageLabels = labels;
  7378. }
  7379. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7380. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7381. }
  7382. }
  7383. async #ensurePdfPageLoaded(thumbView) {
  7384. if (thumbView.pdfPage) {
  7385. return thumbView.pdfPage;
  7386. }
  7387. try {
  7388. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7389. if (!thumbView.pdfPage) {
  7390. thumbView.setPdfPage(pdfPage);
  7391. }
  7392. return pdfPage;
  7393. } catch (reason) {
  7394. console.error("Unable to get page for thumb view", reason);
  7395. return null;
  7396. }
  7397. }
  7398. #getScrollAhead(visible) {
  7399. if (visible.first?.id === 1) {
  7400. return true;
  7401. } else if (visible.last?.id === this._thumbnails.length) {
  7402. return false;
  7403. }
  7404. return this.scroll.down;
  7405. }
  7406. forceRendering() {
  7407. const visibleThumbs = this._getVisibleThumbs();
  7408. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7409. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7410. if (thumbView) {
  7411. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7412. this.renderingQueue.renderView(thumbView);
  7413. });
  7414. return true;
  7415. }
  7416. return false;
  7417. }
  7418. }
  7419. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7420. /***/ }),
  7421. /* 26 */
  7422. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7423. Object.defineProperty(exports, "__esModule", ({
  7424. value: true
  7425. }));
  7426. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7427. var _ui_utils = __webpack_require__(3);
  7428. var _pdfjsLib = __webpack_require__(5);
  7429. const DRAW_UPSCALE_FACTOR = 2;
  7430. const MAX_NUM_SCALING_STEPS = 3;
  7431. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7432. const THUMBNAIL_WIDTH = 98;
  7433. class TempImageFactory {
  7434. static #tempCanvas = null;
  7435. static getCanvas(width, height) {
  7436. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7437. tempCanvas.width = width;
  7438. tempCanvas.height = height;
  7439. const ctx = tempCanvas.getContext("2d", {
  7440. alpha: false
  7441. });
  7442. ctx.save();
  7443. ctx.fillStyle = "rgb(255, 255, 255)";
  7444. ctx.fillRect(0, 0, width, height);
  7445. ctx.restore();
  7446. return [tempCanvas, tempCanvas.getContext("2d")];
  7447. }
  7448. static destroyCanvas() {
  7449. const tempCanvas = this.#tempCanvas;
  7450. if (tempCanvas) {
  7451. tempCanvas.width = 0;
  7452. tempCanvas.height = 0;
  7453. }
  7454. this.#tempCanvas = null;
  7455. }
  7456. }
  7457. exports.TempImageFactory = TempImageFactory;
  7458. class PDFThumbnailView {
  7459. constructor({
  7460. container,
  7461. id,
  7462. defaultViewport,
  7463. optionalContentConfigPromise,
  7464. linkService,
  7465. renderingQueue,
  7466. checkSetImageDisabled,
  7467. l10n
  7468. }) {
  7469. this.id = id;
  7470. this.renderingId = "thumbnail" + id;
  7471. this.pageLabel = null;
  7472. this.pdfPage = null;
  7473. this.rotation = 0;
  7474. this.viewport = defaultViewport;
  7475. this.pdfPageRotate = defaultViewport.rotation;
  7476. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7477. this.linkService = linkService;
  7478. this.renderingQueue = renderingQueue;
  7479. this.renderTask = null;
  7480. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7481. this.resume = null;
  7482. this._checkSetImageDisabled = checkSetImageDisabled || function () {
  7483. return false;
  7484. };
  7485. const pageWidth = this.viewport.width,
  7486. pageHeight = this.viewport.height,
  7487. pageRatio = pageWidth / pageHeight;
  7488. this.canvasWidth = THUMBNAIL_WIDTH;
  7489. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7490. this.scale = this.canvasWidth / pageWidth;
  7491. this.l10n = l10n;
  7492. const anchor = document.createElement("a");
  7493. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7494. this._thumbPageTitle.then(msg => {
  7495. anchor.title = msg;
  7496. });
  7497. anchor.onclick = function () {
  7498. linkService.goToPage(id);
  7499. return false;
  7500. };
  7501. this.anchor = anchor;
  7502. const div = document.createElement("div");
  7503. div.className = "thumbnail";
  7504. div.setAttribute("data-page-number", this.id);
  7505. this.div = div;
  7506. const ring = document.createElement("div");
  7507. ring.className = "thumbnailSelectionRing";
  7508. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7509. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7510. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7511. this.ring = ring;
  7512. div.appendChild(ring);
  7513. anchor.appendChild(div);
  7514. container.appendChild(anchor);
  7515. }
  7516. setPdfPage(pdfPage) {
  7517. this.pdfPage = pdfPage;
  7518. this.pdfPageRotate = pdfPage.rotate;
  7519. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7520. this.viewport = pdfPage.getViewport({
  7521. scale: 1,
  7522. rotation: totalRotation
  7523. });
  7524. this.reset();
  7525. }
  7526. reset() {
  7527. this.cancelRendering();
  7528. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7529. const pageWidth = this.viewport.width,
  7530. pageHeight = this.viewport.height,
  7531. pageRatio = pageWidth / pageHeight;
  7532. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7533. this.scale = this.canvasWidth / pageWidth;
  7534. this.div.removeAttribute("data-loaded");
  7535. const ring = this.ring;
  7536. ring.textContent = "";
  7537. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7538. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7539. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7540. if (this.canvas) {
  7541. this.canvas.width = 0;
  7542. this.canvas.height = 0;
  7543. delete this.canvas;
  7544. }
  7545. if (this.image) {
  7546. this.image.removeAttribute("src");
  7547. delete this.image;
  7548. }
  7549. }
  7550. update({
  7551. rotation = null
  7552. }) {
  7553. if (typeof rotation === "number") {
  7554. this.rotation = rotation;
  7555. }
  7556. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7557. this.viewport = this.viewport.clone({
  7558. scale: 1,
  7559. rotation: totalRotation
  7560. });
  7561. this.reset();
  7562. }
  7563. cancelRendering() {
  7564. if (this.renderTask) {
  7565. this.renderTask.cancel();
  7566. this.renderTask = null;
  7567. }
  7568. this.resume = null;
  7569. }
  7570. _getPageDrawContext(upscaleFactor = 1) {
  7571. const canvas = document.createElement("canvas");
  7572. const ctx = canvas.getContext("2d", {
  7573. alpha: false
  7574. });
  7575. const outputScale = new _ui_utils.OutputScale();
  7576. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7577. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7578. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7579. return {
  7580. ctx,
  7581. canvas,
  7582. transform
  7583. };
  7584. }
  7585. _convertCanvasToImage(canvas) {
  7586. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7587. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  7588. }
  7589. const reducedCanvas = this._reduceImage(canvas);
  7590. const image = document.createElement("img");
  7591. image.className = "thumbnailImage";
  7592. this._thumbPageCanvas.then(msg => {
  7593. image.setAttribute("aria-label", msg);
  7594. });
  7595. image.style.width = this.canvasWidth + "px";
  7596. image.style.height = this.canvasHeight + "px";
  7597. image.src = reducedCanvas.toDataURL();
  7598. this.image = image;
  7599. this.div.setAttribute("data-loaded", true);
  7600. this.ring.appendChild(image);
  7601. reducedCanvas.width = 0;
  7602. reducedCanvas.height = 0;
  7603. }
  7604. draw() {
  7605. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7606. console.error("Must be in new state before drawing");
  7607. return Promise.resolve();
  7608. }
  7609. const {
  7610. pdfPage
  7611. } = this;
  7612. if (!pdfPage) {
  7613. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7614. return Promise.reject(new Error("pdfPage is not loaded"));
  7615. }
  7616. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7617. const finishRenderTask = async (error = null) => {
  7618. if (renderTask === this.renderTask) {
  7619. this.renderTask = null;
  7620. }
  7621. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7622. return;
  7623. }
  7624. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7625. this._convertCanvasToImage(canvas);
  7626. if (error) {
  7627. throw error;
  7628. }
  7629. };
  7630. const {
  7631. ctx,
  7632. canvas,
  7633. transform
  7634. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7635. const drawViewport = this.viewport.clone({
  7636. scale: DRAW_UPSCALE_FACTOR * this.scale
  7637. });
  7638. const renderContinueCallback = cont => {
  7639. if (!this.renderingQueue.isHighestPriority(this)) {
  7640. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  7641. this.resume = () => {
  7642. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7643. cont();
  7644. };
  7645. return;
  7646. }
  7647. cont();
  7648. };
  7649. const renderContext = {
  7650. canvasContext: ctx,
  7651. transform,
  7652. viewport: drawViewport,
  7653. optionalContentConfigPromise: this._optionalContentConfigPromise
  7654. };
  7655. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7656. renderTask.onContinue = renderContinueCallback;
  7657. const resultPromise = renderTask.promise.then(function () {
  7658. return finishRenderTask(null);
  7659. }, function (error) {
  7660. return finishRenderTask(error);
  7661. });
  7662. resultPromise.finally(() => {
  7663. canvas.width = 0;
  7664. canvas.height = 0;
  7665. const pageCached = this.linkService.isPageCached(this.id);
  7666. if (!pageCached) {
  7667. this.pdfPage?.cleanup();
  7668. }
  7669. });
  7670. return resultPromise;
  7671. }
  7672. setImage(pageView) {
  7673. if (this._checkSetImageDisabled()) {
  7674. return;
  7675. }
  7676. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7677. return;
  7678. }
  7679. const {
  7680. canvas,
  7681. pdfPage
  7682. } = pageView;
  7683. if (!canvas) {
  7684. return;
  7685. }
  7686. if (!this.pdfPage) {
  7687. this.setPdfPage(pdfPage);
  7688. }
  7689. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7690. this._convertCanvasToImage(canvas);
  7691. }
  7692. _reduceImage(img) {
  7693. const {
  7694. ctx,
  7695. canvas
  7696. } = this._getPageDrawContext();
  7697. if (img.width <= 2 * canvas.width) {
  7698. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7699. return canvas;
  7700. }
  7701. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7702. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7703. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7704. while (reducedWidth > img.width || reducedHeight > img.height) {
  7705. reducedWidth >>= 1;
  7706. reducedHeight >>= 1;
  7707. }
  7708. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7709. while (reducedWidth > 2 * canvas.width) {
  7710. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7711. reducedWidth >>= 1;
  7712. reducedHeight >>= 1;
  7713. }
  7714. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7715. return canvas;
  7716. }
  7717. get _thumbPageTitle() {
  7718. return this.l10n.get("thumb_page_title", {
  7719. page: this.pageLabel ?? this.id
  7720. });
  7721. }
  7722. get _thumbPageCanvas() {
  7723. return this.l10n.get("thumb_page_canvas", {
  7724. page: this.pageLabel ?? this.id
  7725. });
  7726. }
  7727. setPageLabel(label) {
  7728. this.pageLabel = typeof label === "string" ? label : null;
  7729. this._thumbPageTitle.then(msg => {
  7730. this.anchor.title = msg;
  7731. });
  7732. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7733. return;
  7734. }
  7735. this._thumbPageCanvas.then(msg => {
  7736. this.image?.setAttribute("aria-label", msg);
  7737. });
  7738. }
  7739. }
  7740. exports.PDFThumbnailView = PDFThumbnailView;
  7741. /***/ }),
  7742. /* 27 */
  7743. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7744. Object.defineProperty(exports, "__esModule", ({
  7745. value: true
  7746. }));
  7747. exports.PDFViewer = exports.PDFSinglePageViewer = void 0;
  7748. var _ui_utils = __webpack_require__(3);
  7749. var _base_viewer = __webpack_require__(28);
  7750. class PDFViewer extends _base_viewer.BaseViewer {}
  7751. exports.PDFViewer = PDFViewer;
  7752. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  7753. _resetView() {
  7754. super._resetView();
  7755. this._scrollMode = _ui_utils.ScrollMode.PAGE;
  7756. this._spreadMode = _ui_utils.SpreadMode.NONE;
  7757. }
  7758. set scrollMode(mode) {}
  7759. _updateScrollMode() {}
  7760. set spreadMode(mode) {}
  7761. _updateSpreadMode() {}
  7762. }
  7763. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  7764. /***/ }),
  7765. /* 28 */
  7766. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7767. Object.defineProperty(exports, "__esModule", ({
  7768. value: true
  7769. }));
  7770. exports.PagesCountLimit = exports.PDFPageViewBuffer = exports.BaseViewer = void 0;
  7771. var _pdfjsLib = __webpack_require__(5);
  7772. var _ui_utils = __webpack_require__(3);
  7773. var _annotation_layer_builder = __webpack_require__(29);
  7774. var _l10n_utils = __webpack_require__(30);
  7775. var _pdf_page_view = __webpack_require__(31);
  7776. var _pdf_rendering_queue = __webpack_require__(21);
  7777. var _pdf_link_service = __webpack_require__(8);
  7778. var _struct_tree_layer_builder = __webpack_require__(32);
  7779. var _text_highlighter = __webpack_require__(33);
  7780. var _text_layer_builder = __webpack_require__(34);
  7781. var _xfa_layer_builder = __webpack_require__(35);
  7782. const DEFAULT_CACHE_SIZE = 10;
  7783. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  7784. const PagesCountLimit = {
  7785. FORCE_SCROLL_MODE_PAGE: 15000,
  7786. FORCE_LAZY_PAGE_INIT: 7500,
  7787. PAUSE_EAGER_PAGE_INIT: 250
  7788. };
  7789. exports.PagesCountLimit = PagesCountLimit;
  7790. class PDFPageViewBuffer {
  7791. #buf = new Set();
  7792. #size = 0;
  7793. constructor(size) {
  7794. this.#size = size;
  7795. }
  7796. push(view) {
  7797. const buf = this.#buf;
  7798. if (buf.has(view)) {
  7799. buf.delete(view);
  7800. }
  7801. buf.add(view);
  7802. if (buf.size > this.#size) {
  7803. this.#destroyFirstView();
  7804. }
  7805. }
  7806. resize(newSize, idsToKeep = null) {
  7807. this.#size = newSize;
  7808. const buf = this.#buf;
  7809. if (idsToKeep) {
  7810. const ii = buf.size;
  7811. let i = 1;
  7812. for (const view of buf) {
  7813. if (idsToKeep.has(view.id)) {
  7814. buf.delete(view);
  7815. buf.add(view);
  7816. }
  7817. if (++i > ii) {
  7818. break;
  7819. }
  7820. }
  7821. }
  7822. while (buf.size > this.#size) {
  7823. this.#destroyFirstView();
  7824. }
  7825. }
  7826. has(view) {
  7827. return this.#buf.has(view);
  7828. }
  7829. [Symbol.iterator]() {
  7830. return this.#buf.keys();
  7831. }
  7832. #destroyFirstView() {
  7833. const firstView = this.#buf.keys().next().value;
  7834. firstView?.destroy();
  7835. this.#buf.delete(firstView);
  7836. }
  7837. }
  7838. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  7839. class BaseViewer {
  7840. #buffer = null;
  7841. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  7842. #previousAnnotationMode = null;
  7843. #enablePermissions = false;
  7844. #previousContainerHeight = 0;
  7845. #scrollModePageState = null;
  7846. #onVisibilityChange = null;
  7847. constructor(options) {
  7848. if (this.constructor === BaseViewer) {
  7849. throw new Error("Cannot initialize BaseViewer.");
  7850. }
  7851. const viewerVersion = '2.14.305';
  7852. if (_pdfjsLib.version !== viewerVersion) {
  7853. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  7854. }
  7855. this.container = options.container;
  7856. this.viewer = options.viewer || options.container.firstElementChild;
  7857. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  7858. throw new Error("Invalid `container` and/or `viewer` option.");
  7859. }
  7860. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  7861. throw new Error("The `container` must be absolutely positioned.");
  7862. }
  7863. this.eventBus = options.eventBus;
  7864. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  7865. this.downloadManager = options.downloadManager || null;
  7866. this.findController = options.findController || null;
  7867. this._scriptingManager = options.scriptingManager || null;
  7868. this.removePageBorders = options.removePageBorders || false;
  7869. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  7870. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  7871. this.imageResourcesPath = options.imageResourcesPath || "";
  7872. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  7873. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7874. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  7875. this.maxCanvasPixels = options.maxCanvasPixels;
  7876. this.l10n = options.l10n || _l10n_utils.NullL10n;
  7877. this.#enablePermissions = options.enablePermissions || false;
  7878. this.pageColors = options.pageColors || null;
  7879. if (options.pageColors && (!CSS.supports("color", options.pageColors.background) || !CSS.supports("color", options.pageColors.foreground))) {
  7880. if (options.pageColors.background || options.pageColors.foreground) {
  7881. console.warn("Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  7882. }
  7883. this.pageColors = null;
  7884. }
  7885. this.defaultRenderingQueue = !options.renderingQueue;
  7886. if (this.defaultRenderingQueue) {
  7887. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  7888. this.renderingQueue.setViewer(this);
  7889. } else {
  7890. this.renderingQueue = options.renderingQueue;
  7891. }
  7892. this._doc = document.documentElement;
  7893. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  7894. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  7895. this._onBeforeDraw = this._onAfterDraw = null;
  7896. this._resetView();
  7897. if (this.removePageBorders) {
  7898. this.viewer.classList.add("removePageBorders");
  7899. }
  7900. this.updateContainerHeightCss();
  7901. Promise.resolve().then(() => {
  7902. this.eventBus.dispatch("baseviewerinit", {
  7903. source: this
  7904. });
  7905. });
  7906. }
  7907. get pagesCount() {
  7908. return this._pages.length;
  7909. }
  7910. getPageView(index) {
  7911. return this._pages[index];
  7912. }
  7913. get pageViewsReady() {
  7914. if (!this._pagesCapability.settled) {
  7915. return false;
  7916. }
  7917. return this._pages.every(function (pageView) {
  7918. return pageView?.pdfPage;
  7919. });
  7920. }
  7921. get renderForms() {
  7922. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  7923. }
  7924. get enableScripting() {
  7925. return !!this._scriptingManager;
  7926. }
  7927. get currentPageNumber() {
  7928. return this._currentPageNumber;
  7929. }
  7930. set currentPageNumber(val) {
  7931. if (!Number.isInteger(val)) {
  7932. throw new Error("Invalid page number.");
  7933. }
  7934. if (!this.pdfDocument) {
  7935. return;
  7936. }
  7937. if (!this._setCurrentPageNumber(val, true)) {
  7938. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  7939. }
  7940. }
  7941. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  7942. if (this._currentPageNumber === val) {
  7943. if (resetCurrentPageView) {
  7944. this.#resetCurrentPageView();
  7945. }
  7946. return true;
  7947. }
  7948. if (!(0 < val && val <= this.pagesCount)) {
  7949. return false;
  7950. }
  7951. const previous = this._currentPageNumber;
  7952. this._currentPageNumber = val;
  7953. this.eventBus.dispatch("pagechanging", {
  7954. source: this,
  7955. pageNumber: val,
  7956. pageLabel: this._pageLabels?.[val - 1] ?? null,
  7957. previous
  7958. });
  7959. if (resetCurrentPageView) {
  7960. this.#resetCurrentPageView();
  7961. }
  7962. return true;
  7963. }
  7964. get currentPageLabel() {
  7965. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  7966. }
  7967. set currentPageLabel(val) {
  7968. if (!this.pdfDocument) {
  7969. return;
  7970. }
  7971. let page = val | 0;
  7972. if (this._pageLabels) {
  7973. const i = this._pageLabels.indexOf(val);
  7974. if (i >= 0) {
  7975. page = i + 1;
  7976. }
  7977. }
  7978. if (!this._setCurrentPageNumber(page, true)) {
  7979. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  7980. }
  7981. }
  7982. get currentScale() {
  7983. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  7984. }
  7985. set currentScale(val) {
  7986. if (isNaN(val)) {
  7987. throw new Error("Invalid numeric scale.");
  7988. }
  7989. if (!this.pdfDocument) {
  7990. return;
  7991. }
  7992. this._setScale(val, false);
  7993. }
  7994. get currentScaleValue() {
  7995. return this._currentScaleValue;
  7996. }
  7997. set currentScaleValue(val) {
  7998. if (!this.pdfDocument) {
  7999. return;
  8000. }
  8001. this._setScale(val, false);
  8002. }
  8003. get pagesRotation() {
  8004. return this._pagesRotation;
  8005. }
  8006. set pagesRotation(rotation) {
  8007. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8008. throw new Error("Invalid pages rotation angle.");
  8009. }
  8010. if (!this.pdfDocument) {
  8011. return;
  8012. }
  8013. rotation %= 360;
  8014. if (rotation < 0) {
  8015. rotation += 360;
  8016. }
  8017. if (this._pagesRotation === rotation) {
  8018. return;
  8019. }
  8020. this._pagesRotation = rotation;
  8021. const pageNumber = this._currentPageNumber;
  8022. const updateArgs = {
  8023. rotation
  8024. };
  8025. for (const pageView of this._pages) {
  8026. pageView.update(updateArgs);
  8027. }
  8028. if (this._currentScaleValue) {
  8029. this._setScale(this._currentScaleValue, true);
  8030. }
  8031. this.eventBus.dispatch("rotationchanging", {
  8032. source: this,
  8033. pagesRotation: rotation,
  8034. pageNumber
  8035. });
  8036. if (this.defaultRenderingQueue) {
  8037. this.update();
  8038. }
  8039. }
  8040. get firstPagePromise() {
  8041. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8042. }
  8043. get onePageRendered() {
  8044. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8045. }
  8046. get pagesPromise() {
  8047. return this.pdfDocument ? this._pagesCapability.promise : null;
  8048. }
  8049. #initializePermissions(permissions) {
  8050. if (!permissions) {
  8051. return;
  8052. }
  8053. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  8054. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  8055. }
  8056. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS)) {
  8057. if (this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8058. this.#previousAnnotationMode = this.#annotationMode;
  8059. this.#annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8060. }
  8061. }
  8062. }
  8063. #onePageRenderedOrForceFetch() {
  8064. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8065. return Promise.resolve();
  8066. }
  8067. const visibilityChangePromise = new Promise(resolve => {
  8068. this.#onVisibilityChange = () => {
  8069. if (document.visibilityState !== "hidden") {
  8070. return;
  8071. }
  8072. resolve();
  8073. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8074. this.#onVisibilityChange = null;
  8075. };
  8076. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8077. });
  8078. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8079. }
  8080. setDocument(pdfDocument) {
  8081. if (this.pdfDocument) {
  8082. this.eventBus.dispatch("pagesdestroy", {
  8083. source: this
  8084. });
  8085. this._cancelRendering();
  8086. this._resetView();
  8087. if (this.findController) {
  8088. this.findController.setDocument(null);
  8089. }
  8090. if (this._scriptingManager) {
  8091. this._scriptingManager.setDocument(null);
  8092. }
  8093. }
  8094. this.pdfDocument = pdfDocument;
  8095. if (!pdfDocument) {
  8096. return;
  8097. }
  8098. const isPureXfa = pdfDocument.isPureXfa;
  8099. const pagesCount = pdfDocument.numPages;
  8100. const firstPagePromise = pdfDocument.getPage(1);
  8101. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8102. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8103. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8104. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8105. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8106. this.eventBus.dispatch("scrollmodechanged", {
  8107. source: this,
  8108. mode
  8109. });
  8110. }
  8111. this._pagesCapability.promise.then(() => {
  8112. this.eventBus.dispatch("pagesloaded", {
  8113. source: this,
  8114. pagesCount
  8115. });
  8116. }, () => {});
  8117. this._onBeforeDraw = evt => {
  8118. const pageView = this._pages[evt.pageNumber - 1];
  8119. if (!pageView) {
  8120. return;
  8121. }
  8122. this.#buffer.push(pageView);
  8123. };
  8124. this.eventBus._on("pagerender", this._onBeforeDraw);
  8125. this._onAfterDraw = evt => {
  8126. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8127. return;
  8128. }
  8129. this._onePageRenderedCapability.resolve({
  8130. timestamp: evt.timestamp
  8131. });
  8132. this.eventBus._off("pagerendered", this._onAfterDraw);
  8133. this._onAfterDraw = null;
  8134. if (this.#onVisibilityChange) {
  8135. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8136. this.#onVisibilityChange = null;
  8137. }
  8138. };
  8139. this.eventBus._on("pagerendered", this._onAfterDraw);
  8140. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8141. if (pdfDocument !== this.pdfDocument) {
  8142. return;
  8143. }
  8144. this._firstPageCapability.resolve(firstPdfPage);
  8145. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8146. this.#initializePermissions(permissions);
  8147. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8148. const scale = this.currentScale;
  8149. const viewport = firstPdfPage.getViewport({
  8150. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8151. });
  8152. const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !isPureXfa ? this : null;
  8153. const annotationLayerFactory = this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE ? this : null;
  8154. const xfaLayerFactory = isPureXfa ? this : null;
  8155. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8156. const pageView = new _pdf_page_view.PDFPageView({
  8157. container: viewerElement,
  8158. eventBus: this.eventBus,
  8159. id: pageNum,
  8160. scale,
  8161. defaultViewport: viewport.clone(),
  8162. optionalContentConfigPromise,
  8163. renderingQueue: this.renderingQueue,
  8164. textLayerFactory,
  8165. textLayerMode: this.textLayerMode,
  8166. annotationLayerFactory,
  8167. annotationMode: this.#annotationMode,
  8168. xfaLayerFactory,
  8169. textHighlighterFactory: this,
  8170. structTreeLayerFactory: this,
  8171. imageResourcesPath: this.imageResourcesPath,
  8172. renderer: this.renderer,
  8173. useOnlyCssZoom: this.useOnlyCssZoom,
  8174. maxCanvasPixels: this.maxCanvasPixels,
  8175. pageColors: this.pageColors,
  8176. l10n: this.l10n
  8177. });
  8178. this._pages.push(pageView);
  8179. }
  8180. const firstPageView = this._pages[0];
  8181. if (firstPageView) {
  8182. firstPageView.setPdfPage(firstPdfPage);
  8183. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8184. }
  8185. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8186. this.#ensurePageViewVisible();
  8187. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8188. this._updateSpreadMode();
  8189. }
  8190. this.#onePageRenderedOrForceFetch().then(async () => {
  8191. if (this.findController) {
  8192. this.findController.setDocument(pdfDocument);
  8193. }
  8194. if (this._scriptingManager) {
  8195. this._scriptingManager.setDocument(pdfDocument);
  8196. }
  8197. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8198. this._pagesCapability.resolve();
  8199. return;
  8200. }
  8201. let getPagesLeft = pagesCount - 1;
  8202. if (getPagesLeft <= 0) {
  8203. this._pagesCapability.resolve();
  8204. return;
  8205. }
  8206. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8207. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8208. const pageView = this._pages[pageNum - 1];
  8209. if (!pageView.pdfPage) {
  8210. pageView.setPdfPage(pdfPage);
  8211. }
  8212. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8213. if (--getPagesLeft === 0) {
  8214. this._pagesCapability.resolve();
  8215. }
  8216. }, reason => {
  8217. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8218. if (--getPagesLeft === 0) {
  8219. this._pagesCapability.resolve();
  8220. }
  8221. });
  8222. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8223. await promise;
  8224. }
  8225. }
  8226. });
  8227. this.eventBus.dispatch("pagesinit", {
  8228. source: this
  8229. });
  8230. pdfDocument.getMetadata().then(({
  8231. info
  8232. }) => {
  8233. if (pdfDocument !== this.pdfDocument) {
  8234. return;
  8235. }
  8236. if (info.Language) {
  8237. this.viewer.lang = info.Language;
  8238. }
  8239. });
  8240. if (this.defaultRenderingQueue) {
  8241. this.update();
  8242. }
  8243. }).catch(reason => {
  8244. console.error("Unable to initialize viewer", reason);
  8245. this._pagesCapability.reject(reason);
  8246. });
  8247. }
  8248. setPageLabels(labels) {
  8249. if (!this.pdfDocument) {
  8250. return;
  8251. }
  8252. if (!labels) {
  8253. this._pageLabels = null;
  8254. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8255. this._pageLabels = null;
  8256. console.error(`setPageLabels: Invalid page labels.`);
  8257. } else {
  8258. this._pageLabels = labels;
  8259. }
  8260. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8261. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8262. }
  8263. }
  8264. _resetView() {
  8265. this._pages = [];
  8266. this._currentPageNumber = 1;
  8267. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8268. this._currentScaleValue = null;
  8269. this._pageLabels = null;
  8270. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8271. this._location = null;
  8272. this._pagesRotation = 0;
  8273. this._optionalContentConfigPromise = null;
  8274. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8275. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8276. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8277. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8278. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8279. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8280. this.#scrollModePageState = {
  8281. previousPageNumber: 1,
  8282. scrollDown: true,
  8283. pages: []
  8284. };
  8285. if (this._onBeforeDraw) {
  8286. this.eventBus._off("pagerender", this._onBeforeDraw);
  8287. this._onBeforeDraw = null;
  8288. }
  8289. if (this._onAfterDraw) {
  8290. this.eventBus._off("pagerendered", this._onAfterDraw);
  8291. this._onAfterDraw = null;
  8292. }
  8293. if (this.#onVisibilityChange) {
  8294. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8295. this.#onVisibilityChange = null;
  8296. }
  8297. this.viewer.textContent = "";
  8298. this._updateScrollMode();
  8299. this.viewer.removeAttribute("lang");
  8300. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  8301. if (this.#previousAnnotationMode !== null) {
  8302. this.#annotationMode = this.#previousAnnotationMode;
  8303. this.#previousAnnotationMode = null;
  8304. }
  8305. }
  8306. #ensurePageViewVisible() {
  8307. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8308. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8309. }
  8310. const pageNumber = this._currentPageNumber,
  8311. state = this.#scrollModePageState,
  8312. viewer = this.viewer;
  8313. viewer.textContent = "";
  8314. state.pages.length = 0;
  8315. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8316. const pageView = this._pages[pageNumber - 1];
  8317. viewer.appendChild(pageView.div);
  8318. state.pages.push(pageView);
  8319. } else {
  8320. const pageIndexSet = new Set(),
  8321. parity = this._spreadMode - 1;
  8322. if (parity === -1) {
  8323. pageIndexSet.add(pageNumber - 1);
  8324. } else if (pageNumber % 2 !== parity) {
  8325. pageIndexSet.add(pageNumber - 1);
  8326. pageIndexSet.add(pageNumber);
  8327. } else {
  8328. pageIndexSet.add(pageNumber - 2);
  8329. pageIndexSet.add(pageNumber - 1);
  8330. }
  8331. const spread = document.createElement("div");
  8332. spread.className = "spread";
  8333. if (this.isInPresentationMode) {
  8334. const dummyPage = document.createElement("div");
  8335. dummyPage.className = "dummyPage";
  8336. spread.appendChild(dummyPage);
  8337. }
  8338. for (const i of pageIndexSet) {
  8339. const pageView = this._pages[i];
  8340. if (!pageView) {
  8341. continue;
  8342. }
  8343. spread.appendChild(pageView.div);
  8344. state.pages.push(pageView);
  8345. }
  8346. viewer.appendChild(spread);
  8347. }
  8348. state.scrollDown = pageNumber >= state.previousPageNumber;
  8349. state.previousPageNumber = pageNumber;
  8350. }
  8351. _scrollUpdate() {
  8352. if (this.pagesCount === 0) {
  8353. return;
  8354. }
  8355. this.update();
  8356. }
  8357. #scrollIntoView(pageView, pageSpot = null) {
  8358. const {
  8359. div,
  8360. id
  8361. } = pageView;
  8362. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8363. this._setCurrentPageNumber(id);
  8364. this.#ensurePageViewVisible();
  8365. this.update();
  8366. }
  8367. if (!pageSpot && !this.isInPresentationMode) {
  8368. const left = div.offsetLeft + div.clientLeft,
  8369. right = left + div.clientWidth;
  8370. const {
  8371. scrollLeft,
  8372. clientWidth
  8373. } = this.container;
  8374. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8375. pageSpot = {
  8376. left: 0,
  8377. top: 0
  8378. };
  8379. }
  8380. }
  8381. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8382. }
  8383. #isSameScale(newScale) {
  8384. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8385. }
  8386. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8387. this._currentScaleValue = newValue.toString();
  8388. if (this.#isSameScale(newScale)) {
  8389. if (preset) {
  8390. this.eventBus.dispatch("scalechanging", {
  8391. source: this,
  8392. scale: newScale,
  8393. presetValue: newValue
  8394. });
  8395. }
  8396. return;
  8397. }
  8398. this._doc.style.setProperty("--zoom-factor", newScale);
  8399. const updateArgs = {
  8400. scale: newScale
  8401. };
  8402. for (const pageView of this._pages) {
  8403. pageView.update(updateArgs);
  8404. }
  8405. this._currentScale = newScale;
  8406. if (!noScroll) {
  8407. let page = this._currentPageNumber,
  8408. dest;
  8409. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8410. page = this._location.pageNumber;
  8411. dest = [null, {
  8412. name: "XYZ"
  8413. }, this._location.left, this._location.top, null];
  8414. }
  8415. this.scrollPageIntoView({
  8416. pageNumber: page,
  8417. destArray: dest,
  8418. allowNegativeOffset: true
  8419. });
  8420. }
  8421. this.eventBus.dispatch("scalechanging", {
  8422. source: this,
  8423. scale: newScale,
  8424. presetValue: preset ? newValue : undefined
  8425. });
  8426. if (this.defaultRenderingQueue) {
  8427. this.update();
  8428. }
  8429. this.updateContainerHeightCss();
  8430. }
  8431. get _pageWidthScaleFactor() {
  8432. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8433. return 2;
  8434. }
  8435. return 1;
  8436. }
  8437. _setScale(value, noScroll = false) {
  8438. let scale = parseFloat(value);
  8439. if (scale > 0) {
  8440. this._setScaleUpdatePages(scale, value, noScroll, false);
  8441. } else {
  8442. const currentPage = this._pages[this._currentPageNumber - 1];
  8443. if (!currentPage) {
  8444. return;
  8445. }
  8446. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8447. vPadding = _ui_utils.VERTICAL_PADDING;
  8448. if (this.isInPresentationMode) {
  8449. hPadding = vPadding = 4;
  8450. } else if (this.removePageBorders) {
  8451. hPadding = vPadding = 0;
  8452. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8453. [hPadding, vPadding] = [vPadding, hPadding];
  8454. }
  8455. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8456. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8457. switch (value) {
  8458. case "page-actual":
  8459. scale = 1;
  8460. break;
  8461. case "page-width":
  8462. scale = pageWidthScale;
  8463. break;
  8464. case "page-height":
  8465. scale = pageHeightScale;
  8466. break;
  8467. case "page-fit":
  8468. scale = Math.min(pageWidthScale, pageHeightScale);
  8469. break;
  8470. case "auto":
  8471. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8472. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8473. break;
  8474. default:
  8475. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  8476. return;
  8477. }
  8478. this._setScaleUpdatePages(scale, value, noScroll, true);
  8479. }
  8480. }
  8481. #resetCurrentPageView() {
  8482. const pageView = this._pages[this._currentPageNumber - 1];
  8483. if (this.isInPresentationMode) {
  8484. this._setScale(this._currentScaleValue, true);
  8485. }
  8486. this.#scrollIntoView(pageView);
  8487. }
  8488. pageLabelToPageNumber(label) {
  8489. if (!this._pageLabels) {
  8490. return null;
  8491. }
  8492. const i = this._pageLabels.indexOf(label);
  8493. if (i < 0) {
  8494. return null;
  8495. }
  8496. return i + 1;
  8497. }
  8498. scrollPageIntoView({
  8499. pageNumber,
  8500. destArray = null,
  8501. allowNegativeOffset = false,
  8502. ignoreDestinationZoom = false
  8503. }) {
  8504. if (!this.pdfDocument) {
  8505. return;
  8506. }
  8507. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8508. if (!pageView) {
  8509. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  8510. return;
  8511. }
  8512. if (this.isInPresentationMode || !destArray) {
  8513. this._setCurrentPageNumber(pageNumber, true);
  8514. return;
  8515. }
  8516. let x = 0,
  8517. y = 0;
  8518. let width = 0,
  8519. height = 0,
  8520. widthScale,
  8521. heightScale;
  8522. const changeOrientation = pageView.rotation % 180 !== 0;
  8523. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8524. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8525. let scale = 0;
  8526. switch (destArray[1].name) {
  8527. case "XYZ":
  8528. x = destArray[2];
  8529. y = destArray[3];
  8530. scale = destArray[4];
  8531. x = x !== null ? x : 0;
  8532. y = y !== null ? y : pageHeight;
  8533. break;
  8534. case "Fit":
  8535. case "FitB":
  8536. scale = "page-fit";
  8537. break;
  8538. case "FitH":
  8539. case "FitBH":
  8540. y = destArray[2];
  8541. scale = "page-width";
  8542. if (y === null && this._location) {
  8543. x = this._location.left;
  8544. y = this._location.top;
  8545. } else if (typeof y !== "number" || y < 0) {
  8546. y = pageHeight;
  8547. }
  8548. break;
  8549. case "FitV":
  8550. case "FitBV":
  8551. x = destArray[2];
  8552. width = pageWidth;
  8553. height = pageHeight;
  8554. scale = "page-height";
  8555. break;
  8556. case "FitR":
  8557. x = destArray[2];
  8558. y = destArray[3];
  8559. width = destArray[4] - x;
  8560. height = destArray[5] - y;
  8561. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8562. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8563. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8564. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8565. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8566. break;
  8567. default:
  8568. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  8569. return;
  8570. }
  8571. if (!ignoreDestinationZoom) {
  8572. if (scale && scale !== this._currentScale) {
  8573. this.currentScaleValue = scale;
  8574. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8575. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8576. }
  8577. }
  8578. if (scale === "page-fit" && !destArray[4]) {
  8579. this.#scrollIntoView(pageView);
  8580. return;
  8581. }
  8582. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8583. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8584. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8585. if (!allowNegativeOffset) {
  8586. left = Math.max(left, 0);
  8587. top = Math.max(top, 0);
  8588. }
  8589. this.#scrollIntoView(pageView, {
  8590. left,
  8591. top
  8592. });
  8593. }
  8594. _updateLocation(firstPage) {
  8595. const currentScale = this._currentScale;
  8596. const currentScaleValue = this._currentScaleValue;
  8597. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8598. const pageNumber = firstPage.id;
  8599. const currentPageView = this._pages[pageNumber - 1];
  8600. const container = this.container;
  8601. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8602. const intLeft = Math.round(topLeft[0]);
  8603. const intTop = Math.round(topLeft[1]);
  8604. let pdfOpenParams = `#page=${pageNumber}`;
  8605. if (!this.isInPresentationMode) {
  8606. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  8607. }
  8608. this._location = {
  8609. pageNumber,
  8610. scale: normalizedScaleValue,
  8611. top: intTop,
  8612. left: intLeft,
  8613. rotation: this._pagesRotation,
  8614. pdfOpenParams
  8615. };
  8616. }
  8617. update() {
  8618. const visible = this._getVisiblePages();
  8619. const visiblePages = visible.views,
  8620. numVisiblePages = visiblePages.length;
  8621. if (numVisiblePages === 0) {
  8622. return;
  8623. }
  8624. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8625. this.#buffer.resize(newCacheSize, visible.ids);
  8626. this.renderingQueue.renderHighestPriority(visible);
  8627. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  8628. const currentId = this._currentPageNumber;
  8629. let stillFullyVisible = false;
  8630. for (const page of visiblePages) {
  8631. if (page.percent < 100) {
  8632. break;
  8633. }
  8634. if (page.id === currentId && isSimpleLayout) {
  8635. stillFullyVisible = true;
  8636. break;
  8637. }
  8638. }
  8639. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  8640. this._updateLocation(visible.first);
  8641. this.eventBus.dispatch("updateviewarea", {
  8642. source: this,
  8643. location: this._location
  8644. });
  8645. }
  8646. containsElement(element) {
  8647. return this.container.contains(element);
  8648. }
  8649. focus() {
  8650. this.container.focus();
  8651. }
  8652. get _isContainerRtl() {
  8653. return getComputedStyle(this.container).direction === "rtl";
  8654. }
  8655. get isInPresentationMode() {
  8656. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8657. }
  8658. get isChangingPresentationMode() {
  8659. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8660. }
  8661. get isHorizontalScrollbarEnabled() {
  8662. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8663. }
  8664. get isVerticalScrollbarEnabled() {
  8665. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8666. }
  8667. _getVisiblePages() {
  8668. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  8669. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  8670. rtl = horizontal && this._isContainerRtl;
  8671. return (0, _ui_utils.getVisibleElements)({
  8672. scrollEl: this.container,
  8673. views,
  8674. sortByVisibility: true,
  8675. horizontal,
  8676. rtl
  8677. });
  8678. }
  8679. isPageVisible(pageNumber) {
  8680. if (!this.pdfDocument) {
  8681. return false;
  8682. }
  8683. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8684. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  8685. return false;
  8686. }
  8687. return this._getVisiblePages().ids.has(pageNumber);
  8688. }
  8689. isPageCached(pageNumber) {
  8690. if (!this.pdfDocument) {
  8691. return false;
  8692. }
  8693. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8694. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  8695. return false;
  8696. }
  8697. const pageView = this._pages[pageNumber - 1];
  8698. return this.#buffer.has(pageView);
  8699. }
  8700. cleanup() {
  8701. for (const pageView of this._pages) {
  8702. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8703. pageView.reset();
  8704. }
  8705. }
  8706. }
  8707. _cancelRendering() {
  8708. for (const pageView of this._pages) {
  8709. pageView.cancelRendering();
  8710. }
  8711. }
  8712. async #ensurePdfPageLoaded(pageView) {
  8713. if (pageView.pdfPage) {
  8714. return pageView.pdfPage;
  8715. }
  8716. try {
  8717. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  8718. if (!pageView.pdfPage) {
  8719. pageView.setPdfPage(pdfPage);
  8720. }
  8721. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  8722. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  8723. }
  8724. return pdfPage;
  8725. } catch (reason) {
  8726. console.error("Unable to get page for page view", reason);
  8727. return null;
  8728. }
  8729. }
  8730. #getScrollAhead(visible) {
  8731. if (visible.first?.id === 1) {
  8732. return true;
  8733. } else if (visible.last?.id === this.pagesCount) {
  8734. return false;
  8735. }
  8736. switch (this._scrollMode) {
  8737. case _ui_utils.ScrollMode.PAGE:
  8738. return this.#scrollModePageState.scrollDown;
  8739. case _ui_utils.ScrollMode.HORIZONTAL:
  8740. return this.scroll.right;
  8741. }
  8742. return this.scroll.down;
  8743. }
  8744. #toggleLoadingIconSpinner(visibleIds) {
  8745. for (const id of visibleIds) {
  8746. const pageView = this._pages[id - 1];
  8747. pageView?.toggleLoadingIconSpinner(true);
  8748. }
  8749. for (const pageView of this.#buffer) {
  8750. if (visibleIds.has(pageView.id)) {
  8751. continue;
  8752. }
  8753. pageView.toggleLoadingIconSpinner(false);
  8754. }
  8755. }
  8756. forceRendering(currentlyVisiblePages) {
  8757. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  8758. const scrollAhead = this.#getScrollAhead(visiblePages);
  8759. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  8760. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  8761. this.#toggleLoadingIconSpinner(visiblePages.ids);
  8762. if (pageView) {
  8763. this.#ensurePdfPageLoaded(pageView).then(() => {
  8764. this.renderingQueue.renderView(pageView);
  8765. });
  8766. return true;
  8767. }
  8768. return false;
  8769. }
  8770. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus, highlighter) {
  8771. return new _text_layer_builder.TextLayerBuilder({
  8772. textLayerDiv,
  8773. eventBus,
  8774. pageIndex,
  8775. viewport,
  8776. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection,
  8777. highlighter
  8778. });
  8779. }
  8780. createTextHighlighter(pageIndex, eventBus) {
  8781. return new _text_highlighter.TextHighlighter({
  8782. eventBus,
  8783. pageIndex,
  8784. findController: this.isInPresentationMode ? null : this.findController
  8785. });
  8786. }
  8787. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderForms = true, l10n = _l10n_utils.NullL10n, enableScripting = null, hasJSActionsPromise = null, mouseState = null, fieldObjectsPromise = null, annotationCanvasMap = null) {
  8788. return new _annotation_layer_builder.AnnotationLayerBuilder({
  8789. pageDiv,
  8790. pdfPage,
  8791. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8792. imageResourcesPath,
  8793. renderForms,
  8794. linkService: this.linkService,
  8795. downloadManager: this.downloadManager,
  8796. l10n,
  8797. enableScripting: enableScripting ?? this.enableScripting,
  8798. hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
  8799. fieldObjectsPromise: fieldObjectsPromise || this.pdfDocument?.getFieldObjects(),
  8800. mouseState: mouseState || this._scriptingManager?.mouseState,
  8801. annotationCanvasMap
  8802. });
  8803. }
  8804. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null) {
  8805. return new _xfa_layer_builder.XfaLayerBuilder({
  8806. pageDiv,
  8807. pdfPage,
  8808. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8809. linkService: this.linkService
  8810. });
  8811. }
  8812. createStructTreeLayerBuilder(pdfPage) {
  8813. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  8814. pdfPage
  8815. });
  8816. }
  8817. get hasEqualPageSizes() {
  8818. const firstPageView = this._pages[0];
  8819. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  8820. const pageView = this._pages[i];
  8821. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  8822. return false;
  8823. }
  8824. }
  8825. return true;
  8826. }
  8827. getPagesOverview() {
  8828. return this._pages.map(pageView => {
  8829. const viewport = pageView.pdfPage.getViewport({
  8830. scale: 1
  8831. });
  8832. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  8833. return {
  8834. width: viewport.width,
  8835. height: viewport.height,
  8836. rotation: viewport.rotation
  8837. };
  8838. }
  8839. return {
  8840. width: viewport.height,
  8841. height: viewport.width,
  8842. rotation: (viewport.rotation - 90) % 360
  8843. };
  8844. });
  8845. }
  8846. get optionalContentConfigPromise() {
  8847. if (!this.pdfDocument) {
  8848. return Promise.resolve(null);
  8849. }
  8850. if (!this._optionalContentConfigPromise) {
  8851. return this.pdfDocument.getOptionalContentConfig();
  8852. }
  8853. return this._optionalContentConfigPromise;
  8854. }
  8855. set optionalContentConfigPromise(promise) {
  8856. if (!(promise instanceof Promise)) {
  8857. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  8858. }
  8859. if (!this.pdfDocument) {
  8860. return;
  8861. }
  8862. if (!this._optionalContentConfigPromise) {
  8863. return;
  8864. }
  8865. this._optionalContentConfigPromise = promise;
  8866. const updateArgs = {
  8867. optionalContentConfigPromise: promise
  8868. };
  8869. for (const pageView of this._pages) {
  8870. pageView.update(updateArgs);
  8871. }
  8872. this.update();
  8873. this.eventBus.dispatch("optionalcontentconfigchanged", {
  8874. source: this,
  8875. promise
  8876. });
  8877. }
  8878. get scrollMode() {
  8879. return this._scrollMode;
  8880. }
  8881. set scrollMode(mode) {
  8882. if (this._scrollMode === mode) {
  8883. return;
  8884. }
  8885. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  8886. throw new Error(`Invalid scroll mode: ${mode}`);
  8887. }
  8888. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8889. return;
  8890. }
  8891. this._previousScrollMode = this._scrollMode;
  8892. this._scrollMode = mode;
  8893. this.eventBus.dispatch("scrollmodechanged", {
  8894. source: this,
  8895. mode
  8896. });
  8897. this._updateScrollMode(this._currentPageNumber);
  8898. }
  8899. _updateScrollMode(pageNumber = null) {
  8900. const scrollMode = this._scrollMode,
  8901. viewer = this.viewer;
  8902. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  8903. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  8904. if (!this.pdfDocument || !pageNumber) {
  8905. return;
  8906. }
  8907. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  8908. this.#ensurePageViewVisible();
  8909. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  8910. this._updateSpreadMode();
  8911. }
  8912. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8913. this._setScale(this._currentScaleValue, true);
  8914. }
  8915. this._setCurrentPageNumber(pageNumber, true);
  8916. this.update();
  8917. }
  8918. get spreadMode() {
  8919. return this._spreadMode;
  8920. }
  8921. set spreadMode(mode) {
  8922. if (this._spreadMode === mode) {
  8923. return;
  8924. }
  8925. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  8926. throw new Error(`Invalid spread mode: ${mode}`);
  8927. }
  8928. this._spreadMode = mode;
  8929. this.eventBus.dispatch("spreadmodechanged", {
  8930. source: this,
  8931. mode
  8932. });
  8933. this._updateSpreadMode(this._currentPageNumber);
  8934. }
  8935. _updateSpreadMode(pageNumber = null) {
  8936. if (!this.pdfDocument) {
  8937. return;
  8938. }
  8939. const viewer = this.viewer,
  8940. pages = this._pages;
  8941. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8942. this.#ensurePageViewVisible();
  8943. } else {
  8944. viewer.textContent = "";
  8945. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8946. for (const pageView of this._pages) {
  8947. viewer.appendChild(pageView.div);
  8948. }
  8949. } else {
  8950. const parity = this._spreadMode - 1;
  8951. let spread = null;
  8952. for (let i = 0, ii = pages.length; i < ii; ++i) {
  8953. if (spread === null) {
  8954. spread = document.createElement("div");
  8955. spread.className = "spread";
  8956. viewer.appendChild(spread);
  8957. } else if (i % 2 === parity) {
  8958. spread = spread.cloneNode(false);
  8959. viewer.appendChild(spread);
  8960. }
  8961. spread.appendChild(pages[i].div);
  8962. }
  8963. }
  8964. }
  8965. if (!pageNumber) {
  8966. return;
  8967. }
  8968. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8969. this._setScale(this._currentScaleValue, true);
  8970. }
  8971. this._setCurrentPageNumber(pageNumber, true);
  8972. this.update();
  8973. }
  8974. _getPageAdvance(currentPageNumber, previous = false) {
  8975. switch (this._scrollMode) {
  8976. case _ui_utils.ScrollMode.WRAPPED:
  8977. {
  8978. const {
  8979. views
  8980. } = this._getVisiblePages(),
  8981. pageLayout = new Map();
  8982. for (const {
  8983. id,
  8984. y,
  8985. percent,
  8986. widthPercent
  8987. } of views) {
  8988. if (percent === 0 || widthPercent < 100) {
  8989. continue;
  8990. }
  8991. let yArray = pageLayout.get(y);
  8992. if (!yArray) {
  8993. pageLayout.set(y, yArray ||= []);
  8994. }
  8995. yArray.push(id);
  8996. }
  8997. for (const yArray of pageLayout.values()) {
  8998. const currentIndex = yArray.indexOf(currentPageNumber);
  8999. if (currentIndex === -1) {
  9000. continue;
  9001. }
  9002. const numPages = yArray.length;
  9003. if (numPages === 1) {
  9004. break;
  9005. }
  9006. if (previous) {
  9007. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9008. const currentId = yArray[i],
  9009. expectedId = yArray[i + 1] - 1;
  9010. if (currentId < expectedId) {
  9011. return currentPageNumber - expectedId;
  9012. }
  9013. }
  9014. } else {
  9015. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9016. const currentId = yArray[i],
  9017. expectedId = yArray[i - 1] + 1;
  9018. if (currentId > expectedId) {
  9019. return expectedId - currentPageNumber;
  9020. }
  9021. }
  9022. }
  9023. if (previous) {
  9024. const firstId = yArray[0];
  9025. if (firstId < currentPageNumber) {
  9026. return currentPageNumber - firstId + 1;
  9027. }
  9028. } else {
  9029. const lastId = yArray[numPages - 1];
  9030. if (lastId > currentPageNumber) {
  9031. return lastId - currentPageNumber + 1;
  9032. }
  9033. }
  9034. break;
  9035. }
  9036. break;
  9037. }
  9038. case _ui_utils.ScrollMode.HORIZONTAL:
  9039. {
  9040. break;
  9041. }
  9042. case _ui_utils.ScrollMode.PAGE:
  9043. case _ui_utils.ScrollMode.VERTICAL:
  9044. {
  9045. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9046. break;
  9047. }
  9048. const parity = this._spreadMode - 1;
  9049. if (previous && currentPageNumber % 2 !== parity) {
  9050. break;
  9051. } else if (!previous && currentPageNumber % 2 === parity) {
  9052. break;
  9053. }
  9054. const {
  9055. views
  9056. } = this._getVisiblePages(),
  9057. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9058. for (const {
  9059. id,
  9060. percent,
  9061. widthPercent
  9062. } of views) {
  9063. if (id !== expectedId) {
  9064. continue;
  9065. }
  9066. if (percent > 0 && widthPercent === 100) {
  9067. return 2;
  9068. }
  9069. break;
  9070. }
  9071. break;
  9072. }
  9073. }
  9074. return 1;
  9075. }
  9076. nextPage() {
  9077. const currentPageNumber = this._currentPageNumber,
  9078. pagesCount = this.pagesCount;
  9079. if (currentPageNumber >= pagesCount) {
  9080. return false;
  9081. }
  9082. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9083. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9084. return true;
  9085. }
  9086. previousPage() {
  9087. const currentPageNumber = this._currentPageNumber;
  9088. if (currentPageNumber <= 1) {
  9089. return false;
  9090. }
  9091. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9092. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9093. return true;
  9094. }
  9095. increaseScale(steps = 1) {
  9096. let newScale = this._currentScale;
  9097. do {
  9098. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9099. newScale = Math.ceil(newScale * 10) / 10;
  9100. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  9101. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9102. this.currentScaleValue = newScale;
  9103. }
  9104. decreaseScale(steps = 1) {
  9105. let newScale = this._currentScale;
  9106. do {
  9107. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9108. newScale = Math.floor(newScale * 10) / 10;
  9109. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  9110. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9111. this.currentScaleValue = newScale;
  9112. }
  9113. updateContainerHeightCss() {
  9114. const height = this.container.clientHeight;
  9115. if (height !== this.#previousContainerHeight) {
  9116. this.#previousContainerHeight = height;
  9117. this._doc.style.setProperty("--viewer-container-height", `${height}px`);
  9118. }
  9119. }
  9120. }
  9121. exports.BaseViewer = BaseViewer;
  9122. /***/ }),
  9123. /* 29 */
  9124. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9125. Object.defineProperty(exports, "__esModule", ({
  9126. value: true
  9127. }));
  9128. exports.AnnotationLayerBuilder = void 0;
  9129. var _pdfjsLib = __webpack_require__(5);
  9130. var _l10n_utils = __webpack_require__(30);
  9131. class AnnotationLayerBuilder {
  9132. constructor({
  9133. pageDiv,
  9134. pdfPage,
  9135. linkService,
  9136. downloadManager,
  9137. annotationStorage = null,
  9138. imageResourcesPath = "",
  9139. renderForms = true,
  9140. l10n = _l10n_utils.NullL10n,
  9141. enableScripting = false,
  9142. hasJSActionsPromise = null,
  9143. fieldObjectsPromise = null,
  9144. mouseState = null,
  9145. annotationCanvasMap = null
  9146. }) {
  9147. this.pageDiv = pageDiv;
  9148. this.pdfPage = pdfPage;
  9149. this.linkService = linkService;
  9150. this.downloadManager = downloadManager;
  9151. this.imageResourcesPath = imageResourcesPath;
  9152. this.renderForms = renderForms;
  9153. this.l10n = l10n;
  9154. this.annotationStorage = annotationStorage;
  9155. this.enableScripting = enableScripting;
  9156. this._hasJSActionsPromise = hasJSActionsPromise;
  9157. this._fieldObjectsPromise = fieldObjectsPromise;
  9158. this._mouseState = mouseState;
  9159. this._annotationCanvasMap = annotationCanvasMap;
  9160. this.div = null;
  9161. this._cancelled = false;
  9162. }
  9163. async render(viewport, intent = "display") {
  9164. const [annotations, hasJSActions = false, fieldObjects = null] = await Promise.all([this.pdfPage.getAnnotations({
  9165. intent
  9166. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  9167. if (this._cancelled || annotations.length === 0) {
  9168. return;
  9169. }
  9170. const parameters = {
  9171. viewport: viewport.clone({
  9172. dontFlip: true
  9173. }),
  9174. div: this.div,
  9175. annotations,
  9176. page: this.pdfPage,
  9177. imageResourcesPath: this.imageResourcesPath,
  9178. renderForms: this.renderForms,
  9179. linkService: this.linkService,
  9180. downloadManager: this.downloadManager,
  9181. annotationStorage: this.annotationStorage,
  9182. enableScripting: this.enableScripting,
  9183. hasJSActions,
  9184. fieldObjects,
  9185. mouseState: this._mouseState,
  9186. annotationCanvasMap: this._annotationCanvasMap
  9187. };
  9188. if (this.div) {
  9189. _pdfjsLib.AnnotationLayer.update(parameters);
  9190. } else {
  9191. this.div = document.createElement("div");
  9192. this.div.className = "annotationLayer";
  9193. this.pageDiv.appendChild(this.div);
  9194. parameters.div = this.div;
  9195. _pdfjsLib.AnnotationLayer.render(parameters);
  9196. this.l10n.translate(this.div);
  9197. }
  9198. }
  9199. cancel() {
  9200. this._cancelled = true;
  9201. }
  9202. hide() {
  9203. if (!this.div) {
  9204. return;
  9205. }
  9206. this.div.hidden = true;
  9207. }
  9208. }
  9209. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  9210. /***/ }),
  9211. /* 30 */
  9212. /***/ ((__unused_webpack_module, exports) => {
  9213. Object.defineProperty(exports, "__esModule", ({
  9214. value: true
  9215. }));
  9216. exports.NullL10n = void 0;
  9217. exports.fixupLangCode = fixupLangCode;
  9218. exports.getL10nFallback = getL10nFallback;
  9219. const DEFAULT_L10N_STRINGS = {
  9220. of_pages: "of {{pagesCount}}",
  9221. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9222. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9223. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9224. document_properties_date_string: "{{date}}, {{time}}",
  9225. document_properties_page_size_unit_inches: "in",
  9226. document_properties_page_size_unit_millimeters: "mm",
  9227. document_properties_page_size_orientation_portrait: "portrait",
  9228. document_properties_page_size_orientation_landscape: "landscape",
  9229. document_properties_page_size_name_a3: "A3",
  9230. document_properties_page_size_name_a4: "A4",
  9231. document_properties_page_size_name_letter: "Letter",
  9232. document_properties_page_size_name_legal: "Legal",
  9233. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9234. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9235. document_properties_linearized_yes: "Yes",
  9236. document_properties_linearized_no: "No",
  9237. print_progress_percent: "{{progress}}%",
  9238. "toggle_sidebar.title": "Toggle Sidebar",
  9239. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  9240. additional_layers: "Additional Layers",
  9241. page_landmark: "Page {{page}}",
  9242. thumb_page_title: "Page {{page}}",
  9243. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9244. find_reached_top: "Reached top of document, continued from bottom",
  9245. find_reached_bottom: "Reached end of document, continued from top",
  9246. "find_match_count[one]": "{{current}} of {{total}} match",
  9247. "find_match_count[other]": "{{current}} of {{total}} matches",
  9248. "find_match_count_limit[one]": "More than {{limit}} match",
  9249. "find_match_count_limit[other]": "More than {{limit}} matches",
  9250. find_not_found: "Phrase not found",
  9251. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  9252. error_message: "Message: {{message}}",
  9253. error_stack: "Stack: {{stack}}",
  9254. error_file: "File: {{file}}",
  9255. error_line: "Line: {{line}}",
  9256. rendering_error: "An error occurred while rendering the page.",
  9257. page_scale_width: "Page Width",
  9258. page_scale_fit: "Page Fit",
  9259. page_scale_auto: "Automatic Zoom",
  9260. page_scale_actual: "Actual Size",
  9261. page_scale_percent: "{{scale}}%",
  9262. loading: "Loading…",
  9263. loading_error: "An error occurred while loading the PDF.",
  9264. invalid_file_error: "Invalid or corrupted PDF file.",
  9265. missing_file_error: "Missing PDF file.",
  9266. unexpected_response_error: "Unexpected server response.",
  9267. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9268. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9269. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
  9270. };
  9271. function getL10nFallback(key, args) {
  9272. switch (key) {
  9273. case "find_match_count":
  9274. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9275. break;
  9276. case "find_match_count_limit":
  9277. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9278. break;
  9279. }
  9280. return DEFAULT_L10N_STRINGS[key] || "";
  9281. }
  9282. const PARTIAL_LANG_CODES = {
  9283. en: "en-US",
  9284. es: "es-ES",
  9285. fy: "fy-NL",
  9286. ga: "ga-IE",
  9287. gu: "gu-IN",
  9288. hi: "hi-IN",
  9289. hy: "hy-AM",
  9290. nb: "nb-NO",
  9291. ne: "ne-NP",
  9292. nn: "nn-NO",
  9293. pa: "pa-IN",
  9294. pt: "pt-PT",
  9295. sv: "sv-SE",
  9296. zh: "zh-CN"
  9297. };
  9298. function fixupLangCode(langCode) {
  9299. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9300. }
  9301. function formatL10nValue(text, args) {
  9302. if (!args) {
  9303. return text;
  9304. }
  9305. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9306. return name in args ? args[name] : "{{" + name + "}}";
  9307. });
  9308. }
  9309. const NullL10n = {
  9310. async getLanguage() {
  9311. return "en-us";
  9312. },
  9313. async getDirection() {
  9314. return "ltr";
  9315. },
  9316. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9317. return formatL10nValue(fallback, args);
  9318. },
  9319. async translate(element) {}
  9320. };
  9321. exports.NullL10n = NullL10n;
  9322. /***/ }),
  9323. /* 31 */
  9324. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9325. Object.defineProperty(exports, "__esModule", ({
  9326. value: true
  9327. }));
  9328. exports.PDFPageView = void 0;
  9329. var _pdfjsLib = __webpack_require__(5);
  9330. var _ui_utils = __webpack_require__(3);
  9331. var _app_options = __webpack_require__(1);
  9332. var _l10n_utils = __webpack_require__(30);
  9333. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9334. class PDFPageView {
  9335. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9336. constructor(options) {
  9337. const container = options.container;
  9338. const defaultViewport = options.defaultViewport;
  9339. this.id = options.id;
  9340. this.renderingId = "page" + this.id;
  9341. this.pdfPage = null;
  9342. this.pageLabel = null;
  9343. this.rotation = 0;
  9344. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9345. this.viewport = defaultViewport;
  9346. this.pdfPageRotate = defaultViewport.rotation;
  9347. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9348. this.hasRestrictedScaling = false;
  9349. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9350. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9351. this.imageResourcesPath = options.imageResourcesPath || "";
  9352. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9353. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9354. this.pageColors = options.pageColors || null;
  9355. this.eventBus = options.eventBus;
  9356. this.renderingQueue = options.renderingQueue;
  9357. this.textLayerFactory = options.textLayerFactory;
  9358. this.annotationLayerFactory = options.annotationLayerFactory;
  9359. this.xfaLayerFactory = options.xfaLayerFactory;
  9360. this.textHighlighter = options.textHighlighterFactory?.createTextHighlighter(this.id - 1, this.eventBus);
  9361. this.structTreeLayerFactory = options.structTreeLayerFactory;
  9362. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9363. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9364. this.paintTask = null;
  9365. this.paintedViewportMap = new WeakMap();
  9366. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9367. this.resume = null;
  9368. this._renderError = null;
  9369. this._isStandalone = !this.renderingQueue?.hasViewer();
  9370. this._annotationCanvasMap = null;
  9371. this.annotationLayer = null;
  9372. this.textLayer = null;
  9373. this.zoomLayer = null;
  9374. this.xfaLayer = null;
  9375. this.structTreeLayer = null;
  9376. const div = document.createElement("div");
  9377. div.className = "page";
  9378. div.style.width = Math.floor(this.viewport.width) + "px";
  9379. div.style.height = Math.floor(this.viewport.height) + "px";
  9380. div.setAttribute("data-page-number", this.id);
  9381. div.setAttribute("role", "region");
  9382. this.l10n.get("page_landmark", {
  9383. page: this.id
  9384. }).then(msg => {
  9385. div.setAttribute("aria-label", msg);
  9386. });
  9387. this.div = div;
  9388. container?.appendChild(div);
  9389. }
  9390. setPdfPage(pdfPage) {
  9391. this.pdfPage = pdfPage;
  9392. this.pdfPageRotate = pdfPage.rotate;
  9393. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9394. this.viewport = pdfPage.getViewport({
  9395. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9396. rotation: totalRotation
  9397. });
  9398. this.reset();
  9399. }
  9400. destroy() {
  9401. this.reset();
  9402. if (this.pdfPage) {
  9403. this.pdfPage.cleanup();
  9404. }
  9405. }
  9406. async _renderAnnotationLayer() {
  9407. let error = null;
  9408. try {
  9409. await this.annotationLayer.render(this.viewport, "display");
  9410. } catch (ex) {
  9411. error = ex;
  9412. } finally {
  9413. this.eventBus.dispatch("annotationlayerrendered", {
  9414. source: this,
  9415. pageNumber: this.id,
  9416. error
  9417. });
  9418. }
  9419. }
  9420. async _renderXfaLayer() {
  9421. let error = null;
  9422. try {
  9423. const result = await this.xfaLayer.render(this.viewport, "display");
  9424. if (this.textHighlighter) {
  9425. this._buildXfaTextContentItems(result.textDivs);
  9426. }
  9427. } catch (ex) {
  9428. error = ex;
  9429. } finally {
  9430. this.eventBus.dispatch("xfalayerrendered", {
  9431. source: this,
  9432. pageNumber: this.id,
  9433. error
  9434. });
  9435. }
  9436. }
  9437. async _buildXfaTextContentItems(textDivs) {
  9438. const text = await this.pdfPage.getTextContent();
  9439. const items = [];
  9440. for (const item of text.items) {
  9441. items.push(item.str);
  9442. }
  9443. this.textHighlighter.setTextMapping(textDivs, items);
  9444. this.textHighlighter.enable();
  9445. }
  9446. _resetZoomLayer(removeFromDOM = false) {
  9447. if (!this.zoomLayer) {
  9448. return;
  9449. }
  9450. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9451. this.paintedViewportMap.delete(zoomLayerCanvas);
  9452. zoomLayerCanvas.width = 0;
  9453. zoomLayerCanvas.height = 0;
  9454. if (removeFromDOM) {
  9455. this.zoomLayer.remove();
  9456. }
  9457. this.zoomLayer = null;
  9458. }
  9459. reset({
  9460. keepZoomLayer = false,
  9461. keepAnnotationLayer = false,
  9462. keepXfaLayer = false
  9463. } = {}) {
  9464. this.cancelRendering({
  9465. keepAnnotationLayer,
  9466. keepXfaLayer
  9467. });
  9468. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9469. const div = this.div;
  9470. div.style.width = Math.floor(this.viewport.width) + "px";
  9471. div.style.height = Math.floor(this.viewport.height) + "px";
  9472. const childNodes = div.childNodes,
  9473. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  9474. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  9475. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null;
  9476. for (let i = childNodes.length - 1; i >= 0; i--) {
  9477. const node = childNodes[i];
  9478. switch (node) {
  9479. case zoomLayerNode:
  9480. case annotationLayerNode:
  9481. case xfaLayerNode:
  9482. continue;
  9483. }
  9484. node.remove();
  9485. }
  9486. div.removeAttribute("data-loaded");
  9487. if (annotationLayerNode) {
  9488. this.annotationLayer.hide();
  9489. }
  9490. if (xfaLayerNode) {
  9491. this.xfaLayer.hide();
  9492. }
  9493. if (!zoomLayerNode) {
  9494. if (this.canvas) {
  9495. this.paintedViewportMap.delete(this.canvas);
  9496. this.canvas.width = 0;
  9497. this.canvas.height = 0;
  9498. delete this.canvas;
  9499. }
  9500. this._resetZoomLayer();
  9501. }
  9502. if (this.svg) {
  9503. this.paintedViewportMap.delete(this.svg);
  9504. delete this.svg;
  9505. }
  9506. this.loadingIconDiv = document.createElement("div");
  9507. this.loadingIconDiv.className = "loadingIcon notVisible";
  9508. if (this._isStandalone) {
  9509. this.toggleLoadingIconSpinner(true);
  9510. }
  9511. this.loadingIconDiv.setAttribute("role", "img");
  9512. this.l10n.get("loading").then(msg => {
  9513. this.loadingIconDiv?.setAttribute("aria-label", msg);
  9514. });
  9515. div.appendChild(this.loadingIconDiv);
  9516. }
  9517. update({
  9518. scale = 0,
  9519. rotation = null,
  9520. optionalContentConfigPromise = null
  9521. }) {
  9522. this.scale = scale || this.scale;
  9523. if (typeof rotation === "number") {
  9524. this.rotation = rotation;
  9525. }
  9526. if (optionalContentConfigPromise instanceof Promise) {
  9527. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9528. }
  9529. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9530. this.viewport = this.viewport.clone({
  9531. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9532. rotation: totalRotation
  9533. });
  9534. if (this._isStandalone) {
  9535. const {
  9536. style
  9537. } = document.documentElement;
  9538. style.setProperty("--zoom-factor", this.scale);
  9539. }
  9540. if (this.svg) {
  9541. this.cssTransform({
  9542. target: this.svg,
  9543. redrawAnnotationLayer: true,
  9544. redrawXfaLayer: true
  9545. });
  9546. this.eventBus.dispatch("pagerendered", {
  9547. source: this,
  9548. pageNumber: this.id,
  9549. cssTransform: true,
  9550. timestamp: performance.now(),
  9551. error: this._renderError
  9552. });
  9553. return;
  9554. }
  9555. let isScalingRestricted = false;
  9556. if (this.canvas && this.maxCanvasPixels > 0) {
  9557. const outputScale = this.outputScale;
  9558. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  9559. isScalingRestricted = true;
  9560. }
  9561. }
  9562. if (this.canvas) {
  9563. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  9564. this.cssTransform({
  9565. target: this.canvas,
  9566. redrawAnnotationLayer: true,
  9567. redrawXfaLayer: true
  9568. });
  9569. this.eventBus.dispatch("pagerendered", {
  9570. source: this,
  9571. pageNumber: this.id,
  9572. cssTransform: true,
  9573. timestamp: performance.now(),
  9574. error: this._renderError
  9575. });
  9576. return;
  9577. }
  9578. if (!this.zoomLayer && !this.canvas.hidden) {
  9579. this.zoomLayer = this.canvas.parentNode;
  9580. this.zoomLayer.style.position = "absolute";
  9581. }
  9582. }
  9583. if (this.zoomLayer) {
  9584. this.cssTransform({
  9585. target: this.zoomLayer.firstChild
  9586. });
  9587. }
  9588. this.reset({
  9589. keepZoomLayer: true,
  9590. keepAnnotationLayer: true,
  9591. keepXfaLayer: true
  9592. });
  9593. }
  9594. cancelRendering({
  9595. keepAnnotationLayer = false,
  9596. keepXfaLayer = false
  9597. } = {}) {
  9598. if (this.paintTask) {
  9599. this.paintTask.cancel();
  9600. this.paintTask = null;
  9601. }
  9602. this.resume = null;
  9603. if (this.textLayer) {
  9604. this.textLayer.cancel();
  9605. this.textLayer = null;
  9606. }
  9607. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  9608. this.annotationLayer.cancel();
  9609. this.annotationLayer = null;
  9610. this._annotationCanvasMap = null;
  9611. }
  9612. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  9613. this.xfaLayer.cancel();
  9614. this.xfaLayer = null;
  9615. this.textHighlighter?.disable();
  9616. }
  9617. if (this._onTextLayerRendered) {
  9618. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9619. this._onTextLayerRendered = null;
  9620. }
  9621. }
  9622. cssTransform({
  9623. target,
  9624. redrawAnnotationLayer = false,
  9625. redrawXfaLayer = false
  9626. }) {
  9627. const width = this.viewport.width;
  9628. const height = this.viewport.height;
  9629. const div = this.div;
  9630. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  9631. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  9632. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  9633. const absRotation = Math.abs(relativeRotation);
  9634. let scaleX = 1,
  9635. scaleY = 1;
  9636. if (absRotation === 90 || absRotation === 270) {
  9637. scaleX = height / width;
  9638. scaleY = width / height;
  9639. }
  9640. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  9641. if (this.textLayer) {
  9642. const textLayerViewport = this.textLayer.viewport;
  9643. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  9644. const textAbsRotation = Math.abs(textRelativeRotation);
  9645. let scale = width / textLayerViewport.width;
  9646. if (textAbsRotation === 90 || textAbsRotation === 270) {
  9647. scale = width / textLayerViewport.height;
  9648. }
  9649. const textLayerDiv = this.textLayer.textLayerDiv;
  9650. let transX, transY;
  9651. switch (textAbsRotation) {
  9652. case 0:
  9653. transX = transY = 0;
  9654. break;
  9655. case 90:
  9656. transX = 0;
  9657. transY = "-" + textLayerDiv.style.height;
  9658. break;
  9659. case 180:
  9660. transX = "-" + textLayerDiv.style.width;
  9661. transY = "-" + textLayerDiv.style.height;
  9662. break;
  9663. case 270:
  9664. transX = "-" + textLayerDiv.style.width;
  9665. transY = 0;
  9666. break;
  9667. default:
  9668. console.error("Bad rotation value.");
  9669. break;
  9670. }
  9671. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  9672. textLayerDiv.style.transformOrigin = "0% 0%";
  9673. }
  9674. if (redrawAnnotationLayer && this.annotationLayer) {
  9675. this._renderAnnotationLayer();
  9676. }
  9677. if (redrawXfaLayer && this.xfaLayer) {
  9678. this._renderXfaLayer();
  9679. }
  9680. }
  9681. get width() {
  9682. return this.viewport.width;
  9683. }
  9684. get height() {
  9685. return this.viewport.height;
  9686. }
  9687. getPagePoint(x, y) {
  9688. return this.viewport.convertToPdfPoint(x, y);
  9689. }
  9690. toggleLoadingIconSpinner(viewVisible = false) {
  9691. this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
  9692. }
  9693. draw() {
  9694. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  9695. console.error("Must be in new state before drawing");
  9696. this.reset();
  9697. }
  9698. const {
  9699. div,
  9700. pdfPage
  9701. } = this;
  9702. if (!pdfPage) {
  9703. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9704. if (this.loadingIconDiv) {
  9705. this.loadingIconDiv.remove();
  9706. delete this.loadingIconDiv;
  9707. }
  9708. return Promise.reject(new Error("pdfPage is not loaded"));
  9709. }
  9710. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  9711. const canvasWrapper = document.createElement("div");
  9712. canvasWrapper.style.width = div.style.width;
  9713. canvasWrapper.style.height = div.style.height;
  9714. canvasWrapper.classList.add("canvasWrapper");
  9715. if (this.annotationLayer?.div) {
  9716. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  9717. } else {
  9718. div.appendChild(canvasWrapper);
  9719. }
  9720. let textLayer = null;
  9721. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  9722. const textLayerDiv = document.createElement("div");
  9723. textLayerDiv.className = "textLayer";
  9724. textLayerDiv.style.width = canvasWrapper.style.width;
  9725. textLayerDiv.style.height = canvasWrapper.style.height;
  9726. if (this.annotationLayer?.div) {
  9727. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  9728. } else {
  9729. div.appendChild(textLayerDiv);
  9730. }
  9731. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus, this.textHighlighter);
  9732. }
  9733. this.textLayer = textLayer;
  9734. if (this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE && this.annotationLayerFactory) {
  9735. this._annotationCanvasMap ||= new Map();
  9736. this.annotationLayer ||= this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS, this.l10n, null, null, null, null, this._annotationCanvasMap);
  9737. }
  9738. if (this.xfaLayer?.div) {
  9739. div.appendChild(this.xfaLayer.div);
  9740. }
  9741. let renderContinueCallback = null;
  9742. if (this.renderingQueue) {
  9743. renderContinueCallback = cont => {
  9744. if (!this.renderingQueue.isHighestPriority(this)) {
  9745. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  9746. this.resume = () => {
  9747. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  9748. cont();
  9749. };
  9750. return;
  9751. }
  9752. cont();
  9753. };
  9754. }
  9755. const finishPaintTask = async (error = null) => {
  9756. if (paintTask === this.paintTask) {
  9757. this.paintTask = null;
  9758. }
  9759. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  9760. this._renderError = null;
  9761. return;
  9762. }
  9763. this._renderError = error;
  9764. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9765. if (this.loadingIconDiv) {
  9766. this.loadingIconDiv.remove();
  9767. delete this.loadingIconDiv;
  9768. }
  9769. this._resetZoomLayer(true);
  9770. this.eventBus.dispatch("pagerendered", {
  9771. source: this,
  9772. pageNumber: this.id,
  9773. cssTransform: false,
  9774. timestamp: performance.now(),
  9775. error: this._renderError
  9776. });
  9777. if (error) {
  9778. throw error;
  9779. }
  9780. };
  9781. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  9782. paintTask.onRenderContinue = renderContinueCallback;
  9783. this.paintTask = paintTask;
  9784. const resultPromise = paintTask.promise.then(() => {
  9785. return finishPaintTask(null).then(() => {
  9786. if (textLayer) {
  9787. const readableStream = pdfPage.streamTextContent({
  9788. includeMarkedContent: true
  9789. });
  9790. textLayer.setTextContentStream(readableStream);
  9791. textLayer.render();
  9792. }
  9793. if (this.annotationLayer) {
  9794. this._renderAnnotationLayer();
  9795. }
  9796. });
  9797. }, function (reason) {
  9798. return finishPaintTask(reason);
  9799. });
  9800. if (this.xfaLayerFactory) {
  9801. if (!this.xfaLayer) {
  9802. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage, null);
  9803. }
  9804. this._renderXfaLayer();
  9805. }
  9806. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  9807. this._onTextLayerRendered = event => {
  9808. if (event.pageNumber !== this.id) {
  9809. return;
  9810. }
  9811. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9812. this._onTextLayerRendered = null;
  9813. if (!this.canvas) {
  9814. return;
  9815. }
  9816. this.pdfPage.getStructTree().then(tree => {
  9817. if (!tree) {
  9818. return;
  9819. }
  9820. if (!this.canvas) {
  9821. return;
  9822. }
  9823. const treeDom = this.structTreeLayer.render(tree);
  9824. treeDom.classList.add("structTree");
  9825. this.canvas.appendChild(treeDom);
  9826. });
  9827. };
  9828. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  9829. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder(pdfPage);
  9830. }
  9831. div.setAttribute("data-loaded", true);
  9832. this.eventBus.dispatch("pagerender", {
  9833. source: this,
  9834. pageNumber: this.id
  9835. });
  9836. return resultPromise;
  9837. }
  9838. paintOnCanvas(canvasWrapper) {
  9839. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  9840. const result = {
  9841. promise: renderCapability.promise,
  9842. onRenderContinue(cont) {
  9843. cont();
  9844. },
  9845. cancel() {
  9846. renderTask.cancel();
  9847. }
  9848. };
  9849. const viewport = this.viewport;
  9850. const canvas = document.createElement("canvas");
  9851. canvas.hidden = true;
  9852. let isCanvasHidden = true;
  9853. const showCanvas = function () {
  9854. if (isCanvasHidden) {
  9855. canvas.hidden = false;
  9856. isCanvasHidden = false;
  9857. }
  9858. };
  9859. canvasWrapper.appendChild(canvas);
  9860. this.canvas = canvas;
  9861. const ctx = canvas.getContext("2d", {
  9862. alpha: false
  9863. });
  9864. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  9865. if (this.useOnlyCssZoom) {
  9866. const actualSizeViewport = viewport.clone({
  9867. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  9868. });
  9869. outputScale.sx *= actualSizeViewport.width / viewport.width;
  9870. outputScale.sy *= actualSizeViewport.height / viewport.height;
  9871. }
  9872. if (this.maxCanvasPixels > 0) {
  9873. const pixelsInViewport = viewport.width * viewport.height;
  9874. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  9875. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  9876. outputScale.sx = maxScale;
  9877. outputScale.sy = maxScale;
  9878. this.hasRestrictedScaling = true;
  9879. } else {
  9880. this.hasRestrictedScaling = false;
  9881. }
  9882. }
  9883. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  9884. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  9885. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  9886. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  9887. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  9888. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  9889. this.paintedViewportMap.set(canvas, viewport);
  9890. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  9891. const renderContext = {
  9892. canvasContext: ctx,
  9893. transform,
  9894. viewport: this.viewport,
  9895. annotationMode: this.#annotationMode,
  9896. optionalContentConfigPromise: this._optionalContentConfigPromise,
  9897. annotationCanvasMap: this._annotationCanvasMap,
  9898. pageColors: this.pageColors
  9899. };
  9900. const renderTask = this.pdfPage.render(renderContext);
  9901. renderTask.onContinue = function (cont) {
  9902. showCanvas();
  9903. if (result.onRenderContinue) {
  9904. result.onRenderContinue(cont);
  9905. } else {
  9906. cont();
  9907. }
  9908. };
  9909. renderTask.promise.then(function () {
  9910. showCanvas();
  9911. renderCapability.resolve();
  9912. }, function (error) {
  9913. showCanvas();
  9914. renderCapability.reject(error);
  9915. });
  9916. return result;
  9917. }
  9918. paintOnSvg(wrapper) {
  9919. let cancelled = false;
  9920. const ensureNotCancelled = () => {
  9921. if (cancelled) {
  9922. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  9923. }
  9924. };
  9925. const pdfPage = this.pdfPage;
  9926. const actualSizeViewport = this.viewport.clone({
  9927. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  9928. });
  9929. const promise = pdfPage.getOperatorList({
  9930. annotationMode: this.#annotationMode
  9931. }).then(opList => {
  9932. ensureNotCancelled();
  9933. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  9934. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  9935. ensureNotCancelled();
  9936. this.svg = svg;
  9937. this.paintedViewportMap.set(svg, actualSizeViewport);
  9938. svg.style.width = wrapper.style.width;
  9939. svg.style.height = wrapper.style.height;
  9940. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9941. wrapper.appendChild(svg);
  9942. });
  9943. });
  9944. return {
  9945. promise,
  9946. onRenderContinue(cont) {
  9947. cont();
  9948. },
  9949. cancel() {
  9950. cancelled = true;
  9951. }
  9952. };
  9953. }
  9954. setPageLabel(label) {
  9955. this.pageLabel = typeof label === "string" ? label : null;
  9956. if (this.pageLabel !== null) {
  9957. this.div.setAttribute("data-page-label", this.pageLabel);
  9958. } else {
  9959. this.div.removeAttribute("data-page-label");
  9960. }
  9961. }
  9962. }
  9963. exports.PDFPageView = PDFPageView;
  9964. /***/ }),
  9965. /* 32 */
  9966. /***/ ((__unused_webpack_module, exports) => {
  9967. Object.defineProperty(exports, "__esModule", ({
  9968. value: true
  9969. }));
  9970. exports.StructTreeLayerBuilder = void 0;
  9971. const PDF_ROLE_TO_HTML_ROLE = {
  9972. Document: null,
  9973. DocumentFragment: null,
  9974. Part: "group",
  9975. Sect: "group",
  9976. Div: "group",
  9977. Aside: "note",
  9978. NonStruct: "none",
  9979. P: null,
  9980. H: "heading",
  9981. Title: null,
  9982. FENote: "note",
  9983. Sub: "group",
  9984. Lbl: null,
  9985. Span: null,
  9986. Em: null,
  9987. Strong: null,
  9988. Link: "link",
  9989. Annot: "note",
  9990. Form: "form",
  9991. Ruby: null,
  9992. RB: null,
  9993. RT: null,
  9994. RP: null,
  9995. Warichu: null,
  9996. WT: null,
  9997. WP: null,
  9998. L: "list",
  9999. LI: "listitem",
  10000. LBody: null,
  10001. Table: "table",
  10002. TR: "row",
  10003. TH: "columnheader",
  10004. TD: "cell",
  10005. THead: "columnheader",
  10006. TBody: null,
  10007. TFoot: null,
  10008. Caption: null,
  10009. Figure: "figure",
  10010. Formula: null,
  10011. Artifact: null
  10012. };
  10013. const HEADING_PATTERN = /^H(\d+)$/;
  10014. class StructTreeLayerBuilder {
  10015. constructor({
  10016. pdfPage
  10017. }) {
  10018. this.pdfPage = pdfPage;
  10019. }
  10020. render(structTree) {
  10021. return this._walk(structTree);
  10022. }
  10023. _setAttributes(structElement, htmlElement) {
  10024. if (structElement.alt !== undefined) {
  10025. htmlElement.setAttribute("aria-label", structElement.alt);
  10026. }
  10027. if (structElement.id !== undefined) {
  10028. htmlElement.setAttribute("aria-owns", structElement.id);
  10029. }
  10030. if (structElement.lang !== undefined) {
  10031. htmlElement.setAttribute("lang", structElement.lang);
  10032. }
  10033. }
  10034. _walk(node) {
  10035. if (!node) {
  10036. return null;
  10037. }
  10038. const element = document.createElement("span");
  10039. if ("role" in node) {
  10040. const {
  10041. role
  10042. } = node;
  10043. const match = role.match(HEADING_PATTERN);
  10044. if (match) {
  10045. element.setAttribute("role", "heading");
  10046. element.setAttribute("aria-level", match[1]);
  10047. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10048. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10049. }
  10050. }
  10051. this._setAttributes(node, element);
  10052. if (node.children) {
  10053. if (node.children.length === 1 && "id" in node.children[0]) {
  10054. this._setAttributes(node.children[0], element);
  10055. } else {
  10056. for (const kid of node.children) {
  10057. element.appendChild(this._walk(kid));
  10058. }
  10059. }
  10060. }
  10061. return element;
  10062. }
  10063. }
  10064. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10065. /***/ }),
  10066. /* 33 */
  10067. /***/ ((__unused_webpack_module, exports) => {
  10068. Object.defineProperty(exports, "__esModule", ({
  10069. value: true
  10070. }));
  10071. exports.TextHighlighter = void 0;
  10072. class TextHighlighter {
  10073. constructor({
  10074. findController,
  10075. eventBus,
  10076. pageIndex
  10077. }) {
  10078. this.findController = findController;
  10079. this.matches = [];
  10080. this.eventBus = eventBus;
  10081. this.pageIdx = pageIndex;
  10082. this._onUpdateTextLayerMatches = null;
  10083. this.textDivs = null;
  10084. this.textContentItemsStr = null;
  10085. this.enabled = false;
  10086. }
  10087. setTextMapping(divs, texts) {
  10088. this.textDivs = divs;
  10089. this.textContentItemsStr = texts;
  10090. }
  10091. enable() {
  10092. if (!this.textDivs || !this.textContentItemsStr) {
  10093. throw new Error("Text divs and strings have not been set.");
  10094. }
  10095. if (this.enabled) {
  10096. throw new Error("TextHighlighter is already enabled.");
  10097. }
  10098. this.enabled = true;
  10099. if (!this._onUpdateTextLayerMatches) {
  10100. this._onUpdateTextLayerMatches = evt => {
  10101. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  10102. this._updateMatches();
  10103. }
  10104. };
  10105. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10106. }
  10107. this._updateMatches();
  10108. }
  10109. disable() {
  10110. if (!this.enabled) {
  10111. return;
  10112. }
  10113. this.enabled = false;
  10114. if (this._onUpdateTextLayerMatches) {
  10115. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10116. this._onUpdateTextLayerMatches = null;
  10117. }
  10118. }
  10119. _convertMatches(matches, matchesLength) {
  10120. if (!matches) {
  10121. return [];
  10122. }
  10123. const {
  10124. textContentItemsStr
  10125. } = this;
  10126. let i = 0,
  10127. iIndex = 0;
  10128. const end = textContentItemsStr.length - 1;
  10129. const result = [];
  10130. for (let m = 0, mm = matches.length; m < mm; m++) {
  10131. let matchIdx = matches[m];
  10132. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  10133. iIndex += textContentItemsStr[i].length;
  10134. i++;
  10135. }
  10136. if (i === textContentItemsStr.length) {
  10137. console.error("Could not find a matching mapping");
  10138. }
  10139. const match = {
  10140. begin: {
  10141. divIdx: i,
  10142. offset: matchIdx - iIndex
  10143. }
  10144. };
  10145. matchIdx += matchesLength[m];
  10146. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  10147. iIndex += textContentItemsStr[i].length;
  10148. i++;
  10149. }
  10150. match.end = {
  10151. divIdx: i,
  10152. offset: matchIdx - iIndex
  10153. };
  10154. result.push(match);
  10155. }
  10156. return result;
  10157. }
  10158. _renderMatches(matches) {
  10159. if (matches.length === 0) {
  10160. return;
  10161. }
  10162. const {
  10163. findController,
  10164. pageIdx
  10165. } = this;
  10166. const {
  10167. textContentItemsStr,
  10168. textDivs
  10169. } = this;
  10170. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  10171. const selectedMatchIdx = findController.selected.matchIdx;
  10172. const highlightAll = findController.state.highlightAll;
  10173. let prevEnd = null;
  10174. const infinity = {
  10175. divIdx: -1,
  10176. offset: undefined
  10177. };
  10178. function beginText(begin, className) {
  10179. const divIdx = begin.divIdx;
  10180. textDivs[divIdx].textContent = "";
  10181. return appendTextToDiv(divIdx, 0, begin.offset, className);
  10182. }
  10183. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  10184. let div = textDivs[divIdx];
  10185. if (div.nodeType === Node.TEXT_NODE) {
  10186. const span = document.createElement("span");
  10187. div.parentNode.insertBefore(span, div);
  10188. span.appendChild(div);
  10189. textDivs[divIdx] = span;
  10190. div = span;
  10191. }
  10192. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  10193. const node = document.createTextNode(content);
  10194. if (className) {
  10195. const span = document.createElement("span");
  10196. span.className = `${className} appended`;
  10197. span.appendChild(node);
  10198. div.appendChild(span);
  10199. return className.includes("selected") ? span.offsetLeft : 0;
  10200. }
  10201. div.appendChild(node);
  10202. return 0;
  10203. }
  10204. let i0 = selectedMatchIdx,
  10205. i1 = i0 + 1;
  10206. if (highlightAll) {
  10207. i0 = 0;
  10208. i1 = matches.length;
  10209. } else if (!isSelectedPage) {
  10210. return;
  10211. }
  10212. for (let i = i0; i < i1; i++) {
  10213. const match = matches[i];
  10214. const begin = match.begin;
  10215. const end = match.end;
  10216. const isSelected = isSelectedPage && i === selectedMatchIdx;
  10217. const highlightSuffix = isSelected ? " selected" : "";
  10218. let selectedLeft = 0;
  10219. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  10220. if (prevEnd !== null) {
  10221. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10222. }
  10223. beginText(begin);
  10224. } else {
  10225. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  10226. }
  10227. if (begin.divIdx === end.divIdx) {
  10228. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  10229. } else {
  10230. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  10231. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  10232. textDivs[n0].className = "highlight middle" + highlightSuffix;
  10233. }
  10234. beginText(end, "highlight end" + highlightSuffix);
  10235. }
  10236. prevEnd = end;
  10237. if (isSelected) {
  10238. findController.scrollMatchIntoView({
  10239. element: textDivs[begin.divIdx],
  10240. selectedLeft,
  10241. pageIndex: pageIdx,
  10242. matchIndex: selectedMatchIdx
  10243. });
  10244. }
  10245. }
  10246. if (prevEnd) {
  10247. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10248. }
  10249. }
  10250. _updateMatches() {
  10251. if (!this.enabled) {
  10252. return;
  10253. }
  10254. const {
  10255. findController,
  10256. matches,
  10257. pageIdx
  10258. } = this;
  10259. const {
  10260. textContentItemsStr,
  10261. textDivs
  10262. } = this;
  10263. let clearedUntilDivIdx = -1;
  10264. for (let i = 0, ii = matches.length; i < ii; i++) {
  10265. const match = matches[i];
  10266. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  10267. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  10268. const div = textDivs[n];
  10269. div.textContent = textContentItemsStr[n];
  10270. div.className = "";
  10271. }
  10272. clearedUntilDivIdx = match.end.divIdx + 1;
  10273. }
  10274. if (!findController?.highlightMatches) {
  10275. return;
  10276. }
  10277. const pageMatches = findController.pageMatches[pageIdx] || null;
  10278. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  10279. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  10280. this._renderMatches(this.matches);
  10281. }
  10282. }
  10283. exports.TextHighlighter = TextHighlighter;
  10284. /***/ }),
  10285. /* 34 */
  10286. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10287. Object.defineProperty(exports, "__esModule", ({
  10288. value: true
  10289. }));
  10290. exports.TextLayerBuilder = void 0;
  10291. var _pdfjsLib = __webpack_require__(5);
  10292. const EXPAND_DIVS_TIMEOUT = 300;
  10293. class TextLayerBuilder {
  10294. constructor({
  10295. textLayerDiv,
  10296. eventBus,
  10297. pageIndex,
  10298. viewport,
  10299. highlighter = null,
  10300. enhanceTextSelection = false
  10301. }) {
  10302. this.textLayerDiv = textLayerDiv;
  10303. this.eventBus = eventBus;
  10304. this.textContent = null;
  10305. this.textContentItemsStr = [];
  10306. this.textContentStream = null;
  10307. this.renderingDone = false;
  10308. this.pageNumber = pageIndex + 1;
  10309. this.viewport = viewport;
  10310. this.textDivs = [];
  10311. this.textLayerRenderTask = null;
  10312. this.highlighter = highlighter;
  10313. this.enhanceTextSelection = enhanceTextSelection;
  10314. this._bindMouse();
  10315. }
  10316. _finishRendering() {
  10317. this.renderingDone = true;
  10318. if (!this.enhanceTextSelection) {
  10319. const endOfContent = document.createElement("div");
  10320. endOfContent.className = "endOfContent";
  10321. this.textLayerDiv.appendChild(endOfContent);
  10322. }
  10323. this.eventBus.dispatch("textlayerrendered", {
  10324. source: this,
  10325. pageNumber: this.pageNumber,
  10326. numTextDivs: this.textDivs.length
  10327. });
  10328. }
  10329. render(timeout = 0) {
  10330. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  10331. return;
  10332. }
  10333. this.cancel();
  10334. this.textDivs.length = 0;
  10335. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  10336. const textLayerFrag = document.createDocumentFragment();
  10337. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  10338. textContent: this.textContent,
  10339. textContentStream: this.textContentStream,
  10340. container: textLayerFrag,
  10341. viewport: this.viewport,
  10342. textDivs: this.textDivs,
  10343. textContentItemsStr: this.textContentItemsStr,
  10344. timeout,
  10345. enhanceTextSelection: this.enhanceTextSelection
  10346. });
  10347. this.textLayerRenderTask.promise.then(() => {
  10348. this.textLayerDiv.appendChild(textLayerFrag);
  10349. this._finishRendering();
  10350. this.highlighter?.enable();
  10351. }, function (reason) {});
  10352. }
  10353. cancel() {
  10354. if (this.textLayerRenderTask) {
  10355. this.textLayerRenderTask.cancel();
  10356. this.textLayerRenderTask = null;
  10357. }
  10358. this.highlighter?.disable();
  10359. }
  10360. setTextContentStream(readableStream) {
  10361. this.cancel();
  10362. this.textContentStream = readableStream;
  10363. }
  10364. setTextContent(textContent) {
  10365. this.cancel();
  10366. this.textContent = textContent;
  10367. }
  10368. _bindMouse() {
  10369. const div = this.textLayerDiv;
  10370. let expandDivsTimer = null;
  10371. div.addEventListener("mousedown", evt => {
  10372. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10373. this.textLayerRenderTask.expandTextDivs(true);
  10374. if (expandDivsTimer) {
  10375. clearTimeout(expandDivsTimer);
  10376. expandDivsTimer = null;
  10377. }
  10378. return;
  10379. }
  10380. const end = div.querySelector(".endOfContent");
  10381. if (!end) {
  10382. return;
  10383. }
  10384. let adjustTop = evt.target !== div;
  10385. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  10386. if (adjustTop) {
  10387. const divBounds = div.getBoundingClientRect();
  10388. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  10389. end.style.top = (r * 100).toFixed(2) + "%";
  10390. }
  10391. end.classList.add("active");
  10392. });
  10393. div.addEventListener("mouseup", () => {
  10394. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10395. expandDivsTimer = setTimeout(() => {
  10396. if (this.textLayerRenderTask) {
  10397. this.textLayerRenderTask.expandTextDivs(false);
  10398. }
  10399. expandDivsTimer = null;
  10400. }, EXPAND_DIVS_TIMEOUT);
  10401. return;
  10402. }
  10403. const end = div.querySelector(".endOfContent");
  10404. if (!end) {
  10405. return;
  10406. }
  10407. end.style.top = "";
  10408. end.classList.remove("active");
  10409. });
  10410. }
  10411. }
  10412. exports.TextLayerBuilder = TextLayerBuilder;
  10413. /***/ }),
  10414. /* 35 */
  10415. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10416. Object.defineProperty(exports, "__esModule", ({
  10417. value: true
  10418. }));
  10419. exports.XfaLayerBuilder = void 0;
  10420. var _pdfjsLib = __webpack_require__(5);
  10421. class XfaLayerBuilder {
  10422. constructor({
  10423. pageDiv,
  10424. pdfPage,
  10425. annotationStorage = null,
  10426. linkService,
  10427. xfaHtml = null
  10428. }) {
  10429. this.pageDiv = pageDiv;
  10430. this.pdfPage = pdfPage;
  10431. this.annotationStorage = annotationStorage;
  10432. this.linkService = linkService;
  10433. this.xfaHtml = xfaHtml;
  10434. this.div = null;
  10435. this._cancelled = false;
  10436. }
  10437. render(viewport, intent = "display") {
  10438. if (intent === "print") {
  10439. const parameters = {
  10440. viewport: viewport.clone({
  10441. dontFlip: true
  10442. }),
  10443. div: this.div,
  10444. xfaHtml: this.xfaHtml,
  10445. annotationStorage: this.annotationStorage,
  10446. linkService: this.linkService,
  10447. intent
  10448. };
  10449. const div = document.createElement("div");
  10450. this.pageDiv.appendChild(div);
  10451. parameters.div = div;
  10452. const result = _pdfjsLib.XfaLayer.render(parameters);
  10453. return Promise.resolve(result);
  10454. }
  10455. return this.pdfPage.getXfa().then(xfaHtml => {
  10456. if (this._cancelled || !xfaHtml) {
  10457. return {
  10458. textDivs: []
  10459. };
  10460. }
  10461. const parameters = {
  10462. viewport: viewport.clone({
  10463. dontFlip: true
  10464. }),
  10465. div: this.div,
  10466. xfaHtml,
  10467. annotationStorage: this.annotationStorage,
  10468. linkService: this.linkService,
  10469. intent
  10470. };
  10471. if (this.div) {
  10472. return _pdfjsLib.XfaLayer.update(parameters);
  10473. }
  10474. this.div = document.createElement("div");
  10475. this.pageDiv.appendChild(this.div);
  10476. parameters.div = this.div;
  10477. return _pdfjsLib.XfaLayer.render(parameters);
  10478. }).catch(error => {
  10479. console.error(error);
  10480. });
  10481. }
  10482. cancel() {
  10483. this._cancelled = true;
  10484. }
  10485. hide() {
  10486. if (!this.div) {
  10487. return;
  10488. }
  10489. this.div.hidden = true;
  10490. }
  10491. }
  10492. exports.XfaLayerBuilder = XfaLayerBuilder;
  10493. /***/ }),
  10494. /* 36 */
  10495. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10496. Object.defineProperty(exports, "__esModule", ({
  10497. value: true
  10498. }));
  10499. exports.SecondaryToolbar = void 0;
  10500. var _ui_utils = __webpack_require__(3);
  10501. var _pdf_cursor_tools = __webpack_require__(6);
  10502. var _base_viewer = __webpack_require__(28);
  10503. class SecondaryToolbar {
  10504. constructor(options, eventBus) {
  10505. this.toolbar = options.toolbar;
  10506. this.toggleButton = options.toggleButton;
  10507. this.buttons = [{
  10508. element: options.presentationModeButton,
  10509. eventName: "presentationmode",
  10510. close: true
  10511. }, {
  10512. element: options.printButton,
  10513. eventName: "print",
  10514. close: true
  10515. }, {
  10516. element: options.downloadButton,
  10517. eventName: "download",
  10518. close: true
  10519. }, {
  10520. element: options.viewBookmarkButton,
  10521. eventName: null,
  10522. close: true
  10523. }, {
  10524. element: options.firstPageButton,
  10525. eventName: "firstpage",
  10526. close: true
  10527. }, {
  10528. element: options.lastPageButton,
  10529. eventName: "lastpage",
  10530. close: true
  10531. }, {
  10532. element: options.pageRotateCwButton,
  10533. eventName: "rotatecw",
  10534. close: false
  10535. }, {
  10536. element: options.pageRotateCcwButton,
  10537. eventName: "rotateccw",
  10538. close: false
  10539. }, {
  10540. element: options.cursorSelectToolButton,
  10541. eventName: "switchcursortool",
  10542. eventDetails: {
  10543. tool: _pdf_cursor_tools.CursorTool.SELECT
  10544. },
  10545. close: true
  10546. }, {
  10547. element: options.cursorHandToolButton,
  10548. eventName: "switchcursortool",
  10549. eventDetails: {
  10550. tool: _pdf_cursor_tools.CursorTool.HAND
  10551. },
  10552. close: true
  10553. }, {
  10554. element: options.scrollPageButton,
  10555. eventName: "switchscrollmode",
  10556. eventDetails: {
  10557. mode: _ui_utils.ScrollMode.PAGE
  10558. },
  10559. close: true
  10560. }, {
  10561. element: options.scrollVerticalButton,
  10562. eventName: "switchscrollmode",
  10563. eventDetails: {
  10564. mode: _ui_utils.ScrollMode.VERTICAL
  10565. },
  10566. close: true
  10567. }, {
  10568. element: options.scrollHorizontalButton,
  10569. eventName: "switchscrollmode",
  10570. eventDetails: {
  10571. mode: _ui_utils.ScrollMode.HORIZONTAL
  10572. },
  10573. close: true
  10574. }, {
  10575. element: options.scrollWrappedButton,
  10576. eventName: "switchscrollmode",
  10577. eventDetails: {
  10578. mode: _ui_utils.ScrollMode.WRAPPED
  10579. },
  10580. close: true
  10581. }, {
  10582. element: options.spreadNoneButton,
  10583. eventName: "switchspreadmode",
  10584. eventDetails: {
  10585. mode: _ui_utils.SpreadMode.NONE
  10586. },
  10587. close: true
  10588. }, {
  10589. element: options.spreadOddButton,
  10590. eventName: "switchspreadmode",
  10591. eventDetails: {
  10592. mode: _ui_utils.SpreadMode.ODD
  10593. },
  10594. close: true
  10595. }, {
  10596. element: options.spreadEvenButton,
  10597. eventName: "switchspreadmode",
  10598. eventDetails: {
  10599. mode: _ui_utils.SpreadMode.EVEN
  10600. },
  10601. close: true
  10602. }, {
  10603. element: options.documentPropertiesButton,
  10604. eventName: "documentproperties",
  10605. close: true
  10606. }];
  10607. this.buttons.push({
  10608. element: options.openFileButton,
  10609. eventName: "openfile",
  10610. close: true
  10611. });
  10612. this.items = {
  10613. firstPage: options.firstPageButton,
  10614. lastPage: options.lastPageButton,
  10615. pageRotateCw: options.pageRotateCwButton,
  10616. pageRotateCcw: options.pageRotateCcwButton
  10617. };
  10618. this.eventBus = eventBus;
  10619. this.opened = false;
  10620. this.reset();
  10621. this.#bindClickListeners();
  10622. this.#bindCursorToolsListener(options);
  10623. this.#bindScrollModeListener(options);
  10624. this.#bindSpreadModeListener(options);
  10625. }
  10626. get isOpen() {
  10627. return this.opened;
  10628. }
  10629. setPageNumber(pageNumber) {
  10630. this.pageNumber = pageNumber;
  10631. this.#updateUIState();
  10632. }
  10633. setPagesCount(pagesCount) {
  10634. this.pagesCount = pagesCount;
  10635. this.#updateUIState();
  10636. }
  10637. reset() {
  10638. this.pageNumber = 0;
  10639. this.pagesCount = 0;
  10640. this.#updateUIState();
  10641. this.eventBus.dispatch("secondarytoolbarreset", {
  10642. source: this
  10643. });
  10644. }
  10645. #updateUIState() {
  10646. this.items.firstPage.disabled = this.pageNumber <= 1;
  10647. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  10648. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  10649. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  10650. }
  10651. #bindClickListeners() {
  10652. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  10653. for (const {
  10654. element,
  10655. eventName,
  10656. close,
  10657. eventDetails
  10658. } of this.buttons) {
  10659. element.addEventListener("click", evt => {
  10660. if (eventName !== null) {
  10661. const details = {
  10662. source: this
  10663. };
  10664. for (const property in eventDetails) {
  10665. details[property] = eventDetails[property];
  10666. }
  10667. this.eventBus.dispatch(eventName, details);
  10668. }
  10669. if (close) {
  10670. this.close();
  10671. }
  10672. });
  10673. }
  10674. }
  10675. #bindCursorToolsListener({
  10676. cursorSelectToolButton,
  10677. cursorHandToolButton
  10678. }) {
  10679. this.eventBus._on("cursortoolchanged", function ({
  10680. tool
  10681. }) {
  10682. const isSelect = tool === _pdf_cursor_tools.CursorTool.SELECT,
  10683. isHand = tool === _pdf_cursor_tools.CursorTool.HAND;
  10684. cursorSelectToolButton.classList.toggle("toggled", isSelect);
  10685. cursorHandToolButton.classList.toggle("toggled", isHand);
  10686. cursorSelectToolButton.setAttribute("aria-checked", isSelect);
  10687. cursorHandToolButton.setAttribute("aria-checked", isHand);
  10688. });
  10689. }
  10690. #bindScrollModeListener({
  10691. scrollPageButton,
  10692. scrollVerticalButton,
  10693. scrollHorizontalButton,
  10694. scrollWrappedButton,
  10695. spreadNoneButton,
  10696. spreadOddButton,
  10697. spreadEvenButton
  10698. }) {
  10699. const scrollModeChanged = ({
  10700. mode
  10701. }) => {
  10702. const isPage = mode === _ui_utils.ScrollMode.PAGE,
  10703. isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
  10704. isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
  10705. isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
  10706. scrollPageButton.classList.toggle("toggled", isPage);
  10707. scrollVerticalButton.classList.toggle("toggled", isVertical);
  10708. scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
  10709. scrollWrappedButton.classList.toggle("toggled", isWrapped);
  10710. scrollPageButton.setAttribute("aria-checked", isPage);
  10711. scrollVerticalButton.setAttribute("aria-checked", isVertical);
  10712. scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
  10713. scrollWrappedButton.setAttribute("aria-checked", isWrapped);
  10714. const forceScrollModePage = this.pagesCount > _base_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  10715. scrollPageButton.disabled = forceScrollModePage;
  10716. scrollVerticalButton.disabled = forceScrollModePage;
  10717. scrollHorizontalButton.disabled = forceScrollModePage;
  10718. scrollWrappedButton.disabled = forceScrollModePage;
  10719. spreadNoneButton.disabled = isHorizontal;
  10720. spreadOddButton.disabled = isHorizontal;
  10721. spreadEvenButton.disabled = isHorizontal;
  10722. };
  10723. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  10724. this.eventBus._on("secondarytoolbarreset", evt => {
  10725. if (evt.source === this) {
  10726. scrollModeChanged({
  10727. mode: _ui_utils.ScrollMode.VERTICAL
  10728. });
  10729. }
  10730. });
  10731. }
  10732. #bindSpreadModeListener({
  10733. spreadNoneButton,
  10734. spreadOddButton,
  10735. spreadEvenButton
  10736. }) {
  10737. function spreadModeChanged({
  10738. mode
  10739. }) {
  10740. const isNone = mode === _ui_utils.SpreadMode.NONE,
  10741. isOdd = mode === _ui_utils.SpreadMode.ODD,
  10742. isEven = mode === _ui_utils.SpreadMode.EVEN;
  10743. spreadNoneButton.classList.toggle("toggled", isNone);
  10744. spreadOddButton.classList.toggle("toggled", isOdd);
  10745. spreadEvenButton.classList.toggle("toggled", isEven);
  10746. spreadNoneButton.setAttribute("aria-checked", isNone);
  10747. spreadOddButton.setAttribute("aria-checked", isOdd);
  10748. spreadEvenButton.setAttribute("aria-checked", isEven);
  10749. }
  10750. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  10751. this.eventBus._on("secondarytoolbarreset", evt => {
  10752. if (evt.source === this) {
  10753. spreadModeChanged({
  10754. mode: _ui_utils.SpreadMode.NONE
  10755. });
  10756. }
  10757. });
  10758. }
  10759. open() {
  10760. if (this.opened) {
  10761. return;
  10762. }
  10763. this.opened = true;
  10764. this.toggleButton.classList.add("toggled");
  10765. this.toggleButton.setAttribute("aria-expanded", "true");
  10766. this.toolbar.classList.remove("hidden");
  10767. }
  10768. close() {
  10769. if (!this.opened) {
  10770. return;
  10771. }
  10772. this.opened = false;
  10773. this.toolbar.classList.add("hidden");
  10774. this.toggleButton.classList.remove("toggled");
  10775. this.toggleButton.setAttribute("aria-expanded", "false");
  10776. }
  10777. toggle() {
  10778. if (this.opened) {
  10779. this.close();
  10780. } else {
  10781. this.open();
  10782. }
  10783. }
  10784. }
  10785. exports.SecondaryToolbar = SecondaryToolbar;
  10786. /***/ }),
  10787. /* 37 */
  10788. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10789. Object.defineProperty(exports, "__esModule", ({
  10790. value: true
  10791. }));
  10792. exports.Toolbar = void 0;
  10793. var _ui_utils = __webpack_require__(3);
  10794. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  10795. class Toolbar {
  10796. constructor(options, eventBus, l10n) {
  10797. this.toolbar = options.container;
  10798. this.eventBus = eventBus;
  10799. this.l10n = l10n;
  10800. this.buttons = [{
  10801. element: options.previous,
  10802. eventName: "previouspage"
  10803. }, {
  10804. element: options.next,
  10805. eventName: "nextpage"
  10806. }, {
  10807. element: options.zoomIn,
  10808. eventName: "zoomin"
  10809. }, {
  10810. element: options.zoomOut,
  10811. eventName: "zoomout"
  10812. }, {
  10813. element: options.print,
  10814. eventName: "print"
  10815. }, {
  10816. element: options.presentationModeButton,
  10817. eventName: "presentationmode"
  10818. }, {
  10819. element: options.download,
  10820. eventName: "download"
  10821. }, {
  10822. element: options.viewBookmark,
  10823. eventName: null
  10824. }];
  10825. this.buttons.push({
  10826. element: options.openFile,
  10827. eventName: "openfile"
  10828. });
  10829. this.items = {
  10830. numPages: options.numPages,
  10831. pageNumber: options.pageNumber,
  10832. scaleSelect: options.scaleSelect,
  10833. customScaleOption: options.customScaleOption,
  10834. previous: options.previous,
  10835. next: options.next,
  10836. zoomIn: options.zoomIn,
  10837. zoomOut: options.zoomOut
  10838. };
  10839. this._wasLocalized = false;
  10840. this.reset();
  10841. this._bindListeners();
  10842. }
  10843. setPageNumber(pageNumber, pageLabel) {
  10844. this.pageNumber = pageNumber;
  10845. this.pageLabel = pageLabel;
  10846. this._updateUIState(false);
  10847. }
  10848. setPagesCount(pagesCount, hasPageLabels) {
  10849. this.pagesCount = pagesCount;
  10850. this.hasPageLabels = hasPageLabels;
  10851. this._updateUIState(true);
  10852. }
  10853. setPageScale(pageScaleValue, pageScale) {
  10854. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  10855. this.pageScale = pageScale;
  10856. this._updateUIState(false);
  10857. }
  10858. reset() {
  10859. this.pageNumber = 0;
  10860. this.pageLabel = null;
  10861. this.hasPageLabels = false;
  10862. this.pagesCount = 0;
  10863. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  10864. this.pageScale = _ui_utils.DEFAULT_SCALE;
  10865. this._updateUIState(true);
  10866. this.updateLoadingIndicatorState();
  10867. }
  10868. _bindListeners() {
  10869. const {
  10870. pageNumber,
  10871. scaleSelect
  10872. } = this.items;
  10873. const self = this;
  10874. for (const {
  10875. element,
  10876. eventName
  10877. } of this.buttons) {
  10878. element.addEventListener("click", evt => {
  10879. if (eventName !== null) {
  10880. this.eventBus.dispatch(eventName, {
  10881. source: this
  10882. });
  10883. }
  10884. });
  10885. }
  10886. pageNumber.addEventListener("click", function () {
  10887. this.select();
  10888. });
  10889. pageNumber.addEventListener("change", function () {
  10890. self.eventBus.dispatch("pagenumberchanged", {
  10891. source: self,
  10892. value: this.value
  10893. });
  10894. });
  10895. scaleSelect.addEventListener("change", function () {
  10896. if (this.value === "custom") {
  10897. return;
  10898. }
  10899. self.eventBus.dispatch("scalechanged", {
  10900. source: self,
  10901. value: this.value
  10902. });
  10903. });
  10904. scaleSelect.addEventListener("click", function (evt) {
  10905. const target = evt.target;
  10906. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  10907. this.blur();
  10908. }
  10909. });
  10910. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  10911. this.eventBus._on("localized", () => {
  10912. this._wasLocalized = true;
  10913. this.#adjustScaleWidth();
  10914. this._updateUIState(true);
  10915. });
  10916. }
  10917. _updateUIState(resetNumPages = false) {
  10918. if (!this._wasLocalized) {
  10919. return;
  10920. }
  10921. const {
  10922. pageNumber,
  10923. pagesCount,
  10924. pageScaleValue,
  10925. pageScale,
  10926. items
  10927. } = this;
  10928. if (resetNumPages) {
  10929. if (this.hasPageLabels) {
  10930. items.pageNumber.type = "text";
  10931. } else {
  10932. items.pageNumber.type = "number";
  10933. this.l10n.get("of_pages", {
  10934. pagesCount
  10935. }).then(msg => {
  10936. items.numPages.textContent = msg;
  10937. });
  10938. }
  10939. items.pageNumber.max = pagesCount;
  10940. }
  10941. if (this.hasPageLabels) {
  10942. items.pageNumber.value = this.pageLabel;
  10943. this.l10n.get("page_of_pages", {
  10944. pageNumber,
  10945. pagesCount
  10946. }).then(msg => {
  10947. items.numPages.textContent = msg;
  10948. });
  10949. } else {
  10950. items.pageNumber.value = pageNumber;
  10951. }
  10952. items.previous.disabled = pageNumber <= 1;
  10953. items.next.disabled = pageNumber >= pagesCount;
  10954. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  10955. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  10956. this.l10n.get("page_scale_percent", {
  10957. scale: Math.round(pageScale * 10000) / 100
  10958. }).then(msg => {
  10959. let predefinedValueFound = false;
  10960. for (const option of items.scaleSelect.options) {
  10961. if (option.value !== pageScaleValue) {
  10962. option.selected = false;
  10963. continue;
  10964. }
  10965. option.selected = true;
  10966. predefinedValueFound = true;
  10967. }
  10968. if (!predefinedValueFound) {
  10969. items.customScaleOption.textContent = msg;
  10970. items.customScaleOption.selected = true;
  10971. }
  10972. });
  10973. }
  10974. updateLoadingIndicatorState(loading = false) {
  10975. const pageNumberInput = this.items.pageNumber;
  10976. pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  10977. }
  10978. async #adjustScaleWidth() {
  10979. const {
  10980. items,
  10981. l10n
  10982. } = this;
  10983. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  10984. await _ui_utils.animationStarted;
  10985. const style = getComputedStyle(items.scaleSelect),
  10986. scaleSelectContainerWidth = parseInt(style.getPropertyValue("--scale-select-container-width"), 10),
  10987. scaleSelectOverflow = parseInt(style.getPropertyValue("--scale-select-overflow"), 10);
  10988. const canvas = document.createElement("canvas");
  10989. const ctx = canvas.getContext("2d", {
  10990. alpha: false
  10991. });
  10992. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  10993. let maxWidth = 0;
  10994. for (const predefinedValue of await predefinedValuesPromise) {
  10995. const {
  10996. width
  10997. } = ctx.measureText(predefinedValue);
  10998. if (width > maxWidth) {
  10999. maxWidth = width;
  11000. }
  11001. }
  11002. maxWidth += 2 * scaleSelectOverflow;
  11003. if (maxWidth > scaleSelectContainerWidth) {
  11004. const doc = document.documentElement;
  11005. doc.style.setProperty("--scale-select-container-width", `${maxWidth}px`);
  11006. }
  11007. canvas.width = 0;
  11008. canvas.height = 0;
  11009. }
  11010. }
  11011. exports.Toolbar = Toolbar;
  11012. /***/ }),
  11013. /* 38 */
  11014. /***/ ((__unused_webpack_module, exports) => {
  11015. Object.defineProperty(exports, "__esModule", ({
  11016. value: true
  11017. }));
  11018. exports.ViewHistory = void 0;
  11019. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  11020. class ViewHistory {
  11021. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  11022. this.fingerprint = fingerprint;
  11023. this.cacheSize = cacheSize;
  11024. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  11025. const database = JSON.parse(databaseStr || "{}");
  11026. let index = -1;
  11027. if (!Array.isArray(database.files)) {
  11028. database.files = [];
  11029. } else {
  11030. while (database.files.length >= this.cacheSize) {
  11031. database.files.shift();
  11032. }
  11033. for (let i = 0, ii = database.files.length; i < ii; i++) {
  11034. const branch = database.files[i];
  11035. if (branch.fingerprint === this.fingerprint) {
  11036. index = i;
  11037. break;
  11038. }
  11039. }
  11040. }
  11041. if (index === -1) {
  11042. index = database.files.push({
  11043. fingerprint: this.fingerprint
  11044. }) - 1;
  11045. }
  11046. this.file = database.files[index];
  11047. this.database = database;
  11048. });
  11049. }
  11050. async _writeToStorage() {
  11051. const databaseStr = JSON.stringify(this.database);
  11052. localStorage.setItem("pdfjs.history", databaseStr);
  11053. }
  11054. async _readFromStorage() {
  11055. return localStorage.getItem("pdfjs.history");
  11056. }
  11057. async set(name, val) {
  11058. await this._initializedPromise;
  11059. this.file[name] = val;
  11060. return this._writeToStorage();
  11061. }
  11062. async setMultiple(properties) {
  11063. await this._initializedPromise;
  11064. for (const name in properties) {
  11065. this.file[name] = properties[name];
  11066. }
  11067. return this._writeToStorage();
  11068. }
  11069. async get(name, defaultValue) {
  11070. await this._initializedPromise;
  11071. const val = this.file[name];
  11072. return val !== undefined ? val : defaultValue;
  11073. }
  11074. async getMultiple(properties) {
  11075. await this._initializedPromise;
  11076. const values = Object.create(null);
  11077. for (const name in properties) {
  11078. const val = this.file[name];
  11079. values[name] = val !== undefined ? val : properties[name];
  11080. }
  11081. return values;
  11082. }
  11083. }
  11084. exports.ViewHistory = ViewHistory;
  11085. /***/ }),
  11086. /* 39 */
  11087. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11088. Object.defineProperty(exports, "__esModule", ({
  11089. value: true
  11090. }));
  11091. exports.GenericCom = void 0;
  11092. var _app = __webpack_require__(2);
  11093. var _preferences = __webpack_require__(40);
  11094. var _download_manager = __webpack_require__(41);
  11095. var _genericl10n = __webpack_require__(42);
  11096. var _generic_scripting = __webpack_require__(44);
  11097. ;
  11098. const GenericCom = {};
  11099. exports.GenericCom = GenericCom;
  11100. class GenericPreferences extends _preferences.BasePreferences {
  11101. async _writeToStorage(prefObj) {
  11102. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  11103. }
  11104. async _readFromStorage(prefObj) {
  11105. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  11106. }
  11107. }
  11108. class GenericExternalServices extends _app.DefaultExternalServices {
  11109. static createDownloadManager(options) {
  11110. return new _download_manager.DownloadManager();
  11111. }
  11112. static createPreferences() {
  11113. return new GenericPreferences();
  11114. }
  11115. static createL10n({
  11116. locale = "en-US"
  11117. }) {
  11118. return new _genericl10n.GenericL10n(locale);
  11119. }
  11120. static createScripting({
  11121. sandboxBundleSrc
  11122. }) {
  11123. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  11124. }
  11125. }
  11126. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  11127. /***/ }),
  11128. /* 40 */
  11129. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11130. Object.defineProperty(exports, "__esModule", ({
  11131. value: true
  11132. }));
  11133. exports.BasePreferences = void 0;
  11134. var _app_options = __webpack_require__(1);
  11135. class BasePreferences {
  11136. #defaults = Object.freeze({
  11137. "annotationMode": 2,
  11138. "cursorToolOnLoad": 0,
  11139. "defaultZoomValue": "",
  11140. "disablePageLabels": false,
  11141. "enablePermissions": false,
  11142. "enablePrintAutoRotate": true,
  11143. "enableScripting": true,
  11144. "externalLinkTarget": 0,
  11145. "historyUpdateUrl": false,
  11146. "ignoreDestinationZoom": false,
  11147. "pageColorsBackground": "Canvas",
  11148. "pageColorsForeground": "CanvasText",
  11149. "pdfBugEnabled": false,
  11150. "renderer": "canvas",
  11151. "sidebarViewOnLoad": -1,
  11152. "scrollModeOnLoad": -1,
  11153. "spreadModeOnLoad": -1,
  11154. "textLayerMode": 1,
  11155. "useOnlyCssZoom": false,
  11156. "viewerCssTheme": 0,
  11157. "viewOnLoad": 0,
  11158. "disableAutoFetch": false,
  11159. "disableFontFace": false,
  11160. "disableRange": false,
  11161. "disableStream": false,
  11162. "enableXfa": true
  11163. });
  11164. #prefs = Object.create(null);
  11165. #initializedPromise = null;
  11166. constructor() {
  11167. if (this.constructor === BasePreferences) {
  11168. throw new Error("Cannot initialize BasePreferences.");
  11169. }
  11170. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  11171. for (const name in this.#defaults) {
  11172. const prefValue = prefs?.[name];
  11173. if (typeof prefValue === typeof this.#defaults[name]) {
  11174. this.#prefs[name] = prefValue;
  11175. }
  11176. }
  11177. });
  11178. }
  11179. async _writeToStorage(prefObj) {
  11180. throw new Error("Not implemented: _writeToStorage");
  11181. }
  11182. async _readFromStorage(prefObj) {
  11183. throw new Error("Not implemented: _readFromStorage");
  11184. }
  11185. async reset() {
  11186. await this.#initializedPromise;
  11187. const prefs = this.#prefs;
  11188. this.#prefs = Object.create(null);
  11189. return this._writeToStorage(this.#defaults).catch(reason => {
  11190. this.#prefs = prefs;
  11191. throw reason;
  11192. });
  11193. }
  11194. async set(name, value) {
  11195. await this.#initializedPromise;
  11196. const defaultValue = this.#defaults[name],
  11197. prefs = this.#prefs;
  11198. if (defaultValue === undefined) {
  11199. throw new Error(`Set preference: "${name}" is undefined.`);
  11200. } else if (value === undefined) {
  11201. throw new Error("Set preference: no value is specified.");
  11202. }
  11203. const valueType = typeof value,
  11204. defaultType = typeof defaultValue;
  11205. if (valueType !== defaultType) {
  11206. if (valueType === "number" && defaultType === "string") {
  11207. value = value.toString();
  11208. } else {
  11209. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  11210. }
  11211. } else {
  11212. if (valueType === "number" && !Number.isInteger(value)) {
  11213. throw new Error(`Set preference: "${value}" must be an integer.`);
  11214. }
  11215. }
  11216. this.#prefs[name] = value;
  11217. return this._writeToStorage(this.#prefs).catch(reason => {
  11218. this.#prefs = prefs;
  11219. throw reason;
  11220. });
  11221. }
  11222. async get(name) {
  11223. await this.#initializedPromise;
  11224. const defaultValue = this.#defaults[name];
  11225. if (defaultValue === undefined) {
  11226. throw new Error(`Get preference: "${name}" is undefined.`);
  11227. }
  11228. return this.#prefs[name] ?? defaultValue;
  11229. }
  11230. async getAll() {
  11231. await this.#initializedPromise;
  11232. const obj = Object.create(null);
  11233. for (const name in this.#defaults) {
  11234. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  11235. }
  11236. return obj;
  11237. }
  11238. }
  11239. exports.BasePreferences = BasePreferences;
  11240. /***/ }),
  11241. /* 41 */
  11242. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11243. Object.defineProperty(exports, "__esModule", ({
  11244. value: true
  11245. }));
  11246. exports.DownloadManager = void 0;
  11247. var _pdfjsLib = __webpack_require__(5);
  11248. ;
  11249. function download(blobUrl, filename) {
  11250. const a = document.createElement("a");
  11251. if (!a.click) {
  11252. throw new Error('DownloadManager: "a.click()" is not supported.');
  11253. }
  11254. a.href = blobUrl;
  11255. a.target = "_parent";
  11256. if ("download" in a) {
  11257. a.download = filename;
  11258. }
  11259. (document.body || document.documentElement).appendChild(a);
  11260. a.click();
  11261. a.remove();
  11262. }
  11263. class DownloadManager {
  11264. constructor() {
  11265. this._openBlobUrls = new WeakMap();
  11266. }
  11267. downloadUrl(url, filename) {
  11268. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  11269. console.error(`downloadUrl - not a valid URL: ${url}`);
  11270. return;
  11271. }
  11272. download(url + "#pdfjs.action=download", filename);
  11273. }
  11274. downloadData(data, filename, contentType) {
  11275. const blobUrl = URL.createObjectURL(new Blob([data], {
  11276. type: contentType
  11277. }));
  11278. download(blobUrl, filename);
  11279. }
  11280. openOrDownloadData(element, data, filename) {
  11281. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  11282. const contentType = isPdfData ? "application/pdf" : "";
  11283. if (isPdfData) {
  11284. let blobUrl = this._openBlobUrls.get(element);
  11285. if (!blobUrl) {
  11286. blobUrl = URL.createObjectURL(new Blob([data], {
  11287. type: contentType
  11288. }));
  11289. this._openBlobUrls.set(element, blobUrl);
  11290. }
  11291. let viewerUrl;
  11292. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  11293. try {
  11294. window.open(viewerUrl);
  11295. return true;
  11296. } catch (ex) {
  11297. console.error(`openOrDownloadData: ${ex}`);
  11298. URL.revokeObjectURL(blobUrl);
  11299. this._openBlobUrls.delete(element);
  11300. }
  11301. }
  11302. this.downloadData(data, filename, contentType);
  11303. return false;
  11304. }
  11305. download(blob, url, filename, sourceEventType = "download") {
  11306. const blobUrl = URL.createObjectURL(blob);
  11307. download(blobUrl, filename);
  11308. }
  11309. }
  11310. exports.DownloadManager = DownloadManager;
  11311. /***/ }),
  11312. /* 42 */
  11313. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11314. Object.defineProperty(exports, "__esModule", ({
  11315. value: true
  11316. }));
  11317. exports.GenericL10n = void 0;
  11318. __webpack_require__(43);
  11319. var _l10n_utils = __webpack_require__(30);
  11320. const webL10n = document.webL10n;
  11321. class GenericL10n {
  11322. constructor(lang) {
  11323. this._lang = lang;
  11324. this._ready = new Promise((resolve, reject) => {
  11325. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  11326. resolve(webL10n);
  11327. });
  11328. });
  11329. }
  11330. async getLanguage() {
  11331. const l10n = await this._ready;
  11332. return l10n.getLanguage();
  11333. }
  11334. async getDirection() {
  11335. const l10n = await this._ready;
  11336. return l10n.getDirection();
  11337. }
  11338. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  11339. const l10n = await this._ready;
  11340. return l10n.get(key, args, fallback);
  11341. }
  11342. async translate(element) {
  11343. const l10n = await this._ready;
  11344. return l10n.translate(element);
  11345. }
  11346. }
  11347. exports.GenericL10n = GenericL10n;
  11348. /***/ }),
  11349. /* 43 */
  11350. /***/ (() => {
  11351. document.webL10n = function (window, document, undefined) {
  11352. var gL10nData = {};
  11353. var gTextData = '';
  11354. var gTextProp = 'textContent';
  11355. var gLanguage = '';
  11356. var gMacros = {};
  11357. var gReadyState = 'loading';
  11358. var gAsyncResourceLoading = true;
  11359. function getL10nResourceLinks() {
  11360. return document.querySelectorAll('link[type="application/l10n"]');
  11361. }
  11362. function getL10nDictionary() {
  11363. var script = document.querySelector('script[type="application/l10n"]');
  11364. return script ? JSON.parse(script.innerHTML) : null;
  11365. }
  11366. function getTranslatableChildren(element) {
  11367. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  11368. }
  11369. function getL10nAttributes(element) {
  11370. if (!element) return {};
  11371. var l10nId = element.getAttribute('data-l10n-id');
  11372. var l10nArgs = element.getAttribute('data-l10n-args');
  11373. var args = {};
  11374. if (l10nArgs) {
  11375. try {
  11376. args = JSON.parse(l10nArgs);
  11377. } catch (e) {
  11378. console.warn('could not parse arguments for #' + l10nId);
  11379. }
  11380. }
  11381. return {
  11382. id: l10nId,
  11383. args: args
  11384. };
  11385. }
  11386. function xhrLoadText(url, onSuccess, onFailure) {
  11387. onSuccess = onSuccess || function _onSuccess(data) {};
  11388. onFailure = onFailure || function _onFailure() {};
  11389. var xhr = new XMLHttpRequest();
  11390. xhr.open('GET', url, gAsyncResourceLoading);
  11391. if (xhr.overrideMimeType) {
  11392. xhr.overrideMimeType('text/plain; charset=utf-8');
  11393. }
  11394. xhr.onreadystatechange = function () {
  11395. if (xhr.readyState == 4) {
  11396. if (xhr.status == 200 || xhr.status === 0) {
  11397. onSuccess(xhr.responseText);
  11398. } else {
  11399. onFailure();
  11400. }
  11401. }
  11402. };
  11403. xhr.onerror = onFailure;
  11404. xhr.ontimeout = onFailure;
  11405. try {
  11406. xhr.send(null);
  11407. } catch (e) {
  11408. onFailure();
  11409. }
  11410. }
  11411. function parseResource(href, lang, successCallback, failureCallback) {
  11412. var baseURL = href.replace(/[^\/]*$/, '') || './';
  11413. function evalString(text) {
  11414. if (text.lastIndexOf('\\') < 0) return text;
  11415. return text.replace(/\\\\/g, '\\').replace(/\\n/g, '\n').replace(/\\r/g, '\r').replace(/\\t/g, '\t').replace(/\\b/g, '\b').replace(/\\f/g, '\f').replace(/\\{/g, '{').replace(/\\}/g, '}').replace(/\\"/g, '"').replace(/\\'/g, "'");
  11416. }
  11417. function parseProperties(text, parsedPropertiesCallback) {
  11418. var dictionary = {};
  11419. var reBlank = /^\s*|\s*$/;
  11420. var reComment = /^\s*#|^\s*$/;
  11421. var reSection = /^\s*\[(.*)\]\s*$/;
  11422. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  11423. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  11424. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  11425. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  11426. var currentLang = '*';
  11427. var genericLang = lang.split('-', 1)[0];
  11428. var skipLang = false;
  11429. var match = '';
  11430. function nextEntry() {
  11431. while (true) {
  11432. if (!entries.length) {
  11433. parsedRawLinesCallback();
  11434. return;
  11435. }
  11436. var line = entries.shift();
  11437. if (reComment.test(line)) continue;
  11438. if (extendedSyntax) {
  11439. match = reSection.exec(line);
  11440. if (match) {
  11441. currentLang = match[1].toLowerCase();
  11442. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  11443. continue;
  11444. } else if (skipLang) {
  11445. continue;
  11446. }
  11447. match = reImport.exec(line);
  11448. if (match) {
  11449. loadImport(baseURL + match[1], nextEntry);
  11450. return;
  11451. }
  11452. }
  11453. var tmp = line.match(reSplit);
  11454. if (tmp && tmp.length == 3) {
  11455. dictionary[tmp[1]] = evalString(tmp[2]);
  11456. }
  11457. }
  11458. }
  11459. nextEntry();
  11460. }
  11461. function loadImport(url, callback) {
  11462. xhrLoadText(url, function (content) {
  11463. parseRawLines(content, false, callback);
  11464. }, function () {
  11465. console.warn(url + ' not found.');
  11466. callback();
  11467. });
  11468. }
  11469. parseRawLines(text, true, function () {
  11470. parsedPropertiesCallback(dictionary);
  11471. });
  11472. }
  11473. xhrLoadText(href, function (response) {
  11474. gTextData += response;
  11475. parseProperties(response, function (data) {
  11476. for (var key in data) {
  11477. var id,
  11478. prop,
  11479. index = key.lastIndexOf('.');
  11480. if (index > 0) {
  11481. id = key.substring(0, index);
  11482. prop = key.substring(index + 1);
  11483. } else {
  11484. id = key;
  11485. prop = gTextProp;
  11486. }
  11487. if (!gL10nData[id]) {
  11488. gL10nData[id] = {};
  11489. }
  11490. gL10nData[id][prop] = data[key];
  11491. }
  11492. if (successCallback) {
  11493. successCallback();
  11494. }
  11495. });
  11496. }, failureCallback);
  11497. }
  11498. function loadLocale(lang, callback) {
  11499. if (lang) {
  11500. lang = lang.toLowerCase();
  11501. }
  11502. callback = callback || function _callback() {};
  11503. clear();
  11504. gLanguage = lang;
  11505. var langLinks = getL10nResourceLinks();
  11506. var langCount = langLinks.length;
  11507. if (langCount === 0) {
  11508. var dict = getL10nDictionary();
  11509. if (dict && dict.locales && dict.default_locale) {
  11510. console.log('using the embedded JSON directory, early way out');
  11511. gL10nData = dict.locales[lang];
  11512. if (!gL10nData) {
  11513. var defaultLocale = dict.default_locale.toLowerCase();
  11514. for (var anyCaseLang in dict.locales) {
  11515. anyCaseLang = anyCaseLang.toLowerCase();
  11516. if (anyCaseLang === lang) {
  11517. gL10nData = dict.locales[lang];
  11518. break;
  11519. } else if (anyCaseLang === defaultLocale) {
  11520. gL10nData = dict.locales[defaultLocale];
  11521. }
  11522. }
  11523. }
  11524. callback();
  11525. } else {
  11526. console.log('no resource to load, early way out');
  11527. }
  11528. gReadyState = 'complete';
  11529. return;
  11530. }
  11531. var onResourceLoaded = null;
  11532. var gResourceCount = 0;
  11533. onResourceLoaded = function () {
  11534. gResourceCount++;
  11535. if (gResourceCount >= langCount) {
  11536. callback();
  11537. gReadyState = 'complete';
  11538. }
  11539. };
  11540. function L10nResourceLink(link) {
  11541. var href = link.href;
  11542. this.load = function (lang, callback) {
  11543. parseResource(href, lang, callback, function () {
  11544. console.warn(href + ' not found.');
  11545. console.warn('"' + lang + '" resource not found');
  11546. gLanguage = '';
  11547. callback();
  11548. });
  11549. };
  11550. }
  11551. for (var i = 0; i < langCount; i++) {
  11552. var resource = new L10nResourceLink(langLinks[i]);
  11553. resource.load(lang, onResourceLoaded);
  11554. }
  11555. }
  11556. function clear() {
  11557. gL10nData = {};
  11558. gTextData = '';
  11559. gLanguage = '';
  11560. }
  11561. function getPluralRules(lang) {
  11562. var locales2rules = {
  11563. 'af': 3,
  11564. 'ak': 4,
  11565. 'am': 4,
  11566. 'ar': 1,
  11567. 'asa': 3,
  11568. 'az': 0,
  11569. 'be': 11,
  11570. 'bem': 3,
  11571. 'bez': 3,
  11572. 'bg': 3,
  11573. 'bh': 4,
  11574. 'bm': 0,
  11575. 'bn': 3,
  11576. 'bo': 0,
  11577. 'br': 20,
  11578. 'brx': 3,
  11579. 'bs': 11,
  11580. 'ca': 3,
  11581. 'cgg': 3,
  11582. 'chr': 3,
  11583. 'cs': 12,
  11584. 'cy': 17,
  11585. 'da': 3,
  11586. 'de': 3,
  11587. 'dv': 3,
  11588. 'dz': 0,
  11589. 'ee': 3,
  11590. 'el': 3,
  11591. 'en': 3,
  11592. 'eo': 3,
  11593. 'es': 3,
  11594. 'et': 3,
  11595. 'eu': 3,
  11596. 'fa': 0,
  11597. 'ff': 5,
  11598. 'fi': 3,
  11599. 'fil': 4,
  11600. 'fo': 3,
  11601. 'fr': 5,
  11602. 'fur': 3,
  11603. 'fy': 3,
  11604. 'ga': 8,
  11605. 'gd': 24,
  11606. 'gl': 3,
  11607. 'gsw': 3,
  11608. 'gu': 3,
  11609. 'guw': 4,
  11610. 'gv': 23,
  11611. 'ha': 3,
  11612. 'haw': 3,
  11613. 'he': 2,
  11614. 'hi': 4,
  11615. 'hr': 11,
  11616. 'hu': 0,
  11617. 'id': 0,
  11618. 'ig': 0,
  11619. 'ii': 0,
  11620. 'is': 3,
  11621. 'it': 3,
  11622. 'iu': 7,
  11623. 'ja': 0,
  11624. 'jmc': 3,
  11625. 'jv': 0,
  11626. 'ka': 0,
  11627. 'kab': 5,
  11628. 'kaj': 3,
  11629. 'kcg': 3,
  11630. 'kde': 0,
  11631. 'kea': 0,
  11632. 'kk': 3,
  11633. 'kl': 3,
  11634. 'km': 0,
  11635. 'kn': 0,
  11636. 'ko': 0,
  11637. 'ksb': 3,
  11638. 'ksh': 21,
  11639. 'ku': 3,
  11640. 'kw': 7,
  11641. 'lag': 18,
  11642. 'lb': 3,
  11643. 'lg': 3,
  11644. 'ln': 4,
  11645. 'lo': 0,
  11646. 'lt': 10,
  11647. 'lv': 6,
  11648. 'mas': 3,
  11649. 'mg': 4,
  11650. 'mk': 16,
  11651. 'ml': 3,
  11652. 'mn': 3,
  11653. 'mo': 9,
  11654. 'mr': 3,
  11655. 'ms': 0,
  11656. 'mt': 15,
  11657. 'my': 0,
  11658. 'nah': 3,
  11659. 'naq': 7,
  11660. 'nb': 3,
  11661. 'nd': 3,
  11662. 'ne': 3,
  11663. 'nl': 3,
  11664. 'nn': 3,
  11665. 'no': 3,
  11666. 'nr': 3,
  11667. 'nso': 4,
  11668. 'ny': 3,
  11669. 'nyn': 3,
  11670. 'om': 3,
  11671. 'or': 3,
  11672. 'pa': 3,
  11673. 'pap': 3,
  11674. 'pl': 13,
  11675. 'ps': 3,
  11676. 'pt': 3,
  11677. 'rm': 3,
  11678. 'ro': 9,
  11679. 'rof': 3,
  11680. 'ru': 11,
  11681. 'rwk': 3,
  11682. 'sah': 0,
  11683. 'saq': 3,
  11684. 'se': 7,
  11685. 'seh': 3,
  11686. 'ses': 0,
  11687. 'sg': 0,
  11688. 'sh': 11,
  11689. 'shi': 19,
  11690. 'sk': 12,
  11691. 'sl': 14,
  11692. 'sma': 7,
  11693. 'smi': 7,
  11694. 'smj': 7,
  11695. 'smn': 7,
  11696. 'sms': 7,
  11697. 'sn': 3,
  11698. 'so': 3,
  11699. 'sq': 3,
  11700. 'sr': 11,
  11701. 'ss': 3,
  11702. 'ssy': 3,
  11703. 'st': 3,
  11704. 'sv': 3,
  11705. 'sw': 3,
  11706. 'syr': 3,
  11707. 'ta': 3,
  11708. 'te': 3,
  11709. 'teo': 3,
  11710. 'th': 0,
  11711. 'ti': 4,
  11712. 'tig': 3,
  11713. 'tk': 3,
  11714. 'tl': 4,
  11715. 'tn': 3,
  11716. 'to': 0,
  11717. 'tr': 0,
  11718. 'ts': 3,
  11719. 'tzm': 22,
  11720. 'uk': 11,
  11721. 'ur': 3,
  11722. 've': 3,
  11723. 'vi': 0,
  11724. 'vun': 3,
  11725. 'wa': 4,
  11726. 'wae': 3,
  11727. 'wo': 0,
  11728. 'xh': 3,
  11729. 'xog': 3,
  11730. 'yo': 0,
  11731. 'zh': 0,
  11732. 'zu': 3
  11733. };
  11734. function isIn(n, list) {
  11735. return list.indexOf(n) !== -1;
  11736. }
  11737. function isBetween(n, start, end) {
  11738. return start <= n && n <= end;
  11739. }
  11740. var pluralRules = {
  11741. '0': function (n) {
  11742. return 'other';
  11743. },
  11744. '1': function (n) {
  11745. if (isBetween(n % 100, 3, 10)) return 'few';
  11746. if (n === 0) return 'zero';
  11747. if (isBetween(n % 100, 11, 99)) return 'many';
  11748. if (n == 2) return 'two';
  11749. if (n == 1) return 'one';
  11750. return 'other';
  11751. },
  11752. '2': function (n) {
  11753. if (n !== 0 && n % 10 === 0) return 'many';
  11754. if (n == 2) return 'two';
  11755. if (n == 1) return 'one';
  11756. return 'other';
  11757. },
  11758. '3': function (n) {
  11759. if (n == 1) return 'one';
  11760. return 'other';
  11761. },
  11762. '4': function (n) {
  11763. if (isBetween(n, 0, 1)) return 'one';
  11764. return 'other';
  11765. },
  11766. '5': function (n) {
  11767. if (isBetween(n, 0, 2) && n != 2) return 'one';
  11768. return 'other';
  11769. },
  11770. '6': function (n) {
  11771. if (n === 0) return 'zero';
  11772. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11773. return 'other';
  11774. },
  11775. '7': function (n) {
  11776. if (n == 2) return 'two';
  11777. if (n == 1) return 'one';
  11778. return 'other';
  11779. },
  11780. '8': function (n) {
  11781. if (isBetween(n, 3, 6)) return 'few';
  11782. if (isBetween(n, 7, 10)) return 'many';
  11783. if (n == 2) return 'two';
  11784. if (n == 1) return 'one';
  11785. return 'other';
  11786. },
  11787. '9': function (n) {
  11788. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  11789. if (n == 1) return 'one';
  11790. return 'other';
  11791. },
  11792. '10': function (n) {
  11793. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  11794. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  11795. return 'other';
  11796. },
  11797. '11': function (n) {
  11798. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11799. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  11800. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11801. return 'other';
  11802. },
  11803. '12': function (n) {
  11804. if (isBetween(n, 2, 4)) return 'few';
  11805. if (n == 1) return 'one';
  11806. return 'other';
  11807. },
  11808. '13': function (n) {
  11809. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11810. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  11811. if (n == 1) return 'one';
  11812. return 'other';
  11813. },
  11814. '14': function (n) {
  11815. if (isBetween(n % 100, 3, 4)) return 'few';
  11816. if (n % 100 == 2) return 'two';
  11817. if (n % 100 == 1) return 'one';
  11818. return 'other';
  11819. },
  11820. '15': function (n) {
  11821. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  11822. if (isBetween(n % 100, 11, 19)) return 'many';
  11823. if (n == 1) return 'one';
  11824. return 'other';
  11825. },
  11826. '16': function (n) {
  11827. if (n % 10 == 1 && n != 11) return 'one';
  11828. return 'other';
  11829. },
  11830. '17': function (n) {
  11831. if (n == 3) return 'few';
  11832. if (n === 0) return 'zero';
  11833. if (n == 6) return 'many';
  11834. if (n == 2) return 'two';
  11835. if (n == 1) return 'one';
  11836. return 'other';
  11837. },
  11838. '18': function (n) {
  11839. if (n === 0) return 'zero';
  11840. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  11841. return 'other';
  11842. },
  11843. '19': function (n) {
  11844. if (isBetween(n, 2, 10)) return 'few';
  11845. if (isBetween(n, 0, 1)) return 'one';
  11846. return 'other';
  11847. },
  11848. '20': function (n) {
  11849. if ((isBetween(n % 10, 3, 4) || n % 10 == 9) && !(isBetween(n % 100, 10, 19) || isBetween(n % 100, 70, 79) || isBetween(n % 100, 90, 99))) return 'few';
  11850. if (n % 1000000 === 0 && n !== 0) return 'many';
  11851. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  11852. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  11853. return 'other';
  11854. },
  11855. '21': function (n) {
  11856. if (n === 0) return 'zero';
  11857. if (n == 1) return 'one';
  11858. return 'other';
  11859. },
  11860. '22': function (n) {
  11861. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  11862. return 'other';
  11863. },
  11864. '23': function (n) {
  11865. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  11866. return 'other';
  11867. },
  11868. '24': function (n) {
  11869. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  11870. if (isIn(n, [2, 12])) return 'two';
  11871. if (isIn(n, [1, 11])) return 'one';
  11872. return 'other';
  11873. }
  11874. };
  11875. var index = locales2rules[lang.replace(/-.*$/, '')];
  11876. if (!(index in pluralRules)) {
  11877. console.warn('plural form unknown for [' + lang + ']');
  11878. return function () {
  11879. return 'other';
  11880. };
  11881. }
  11882. return pluralRules[index];
  11883. }
  11884. gMacros.plural = function (str, param, key, prop) {
  11885. var n = parseFloat(param);
  11886. if (isNaN(n)) return str;
  11887. if (prop != gTextProp) return str;
  11888. if (!gMacros._pluralRules) {
  11889. gMacros._pluralRules = getPluralRules(gLanguage);
  11890. }
  11891. var index = '[' + gMacros._pluralRules(n) + ']';
  11892. if (n === 0 && key + '[zero]' in gL10nData) {
  11893. str = gL10nData[key + '[zero]'][prop];
  11894. } else if (n == 1 && key + '[one]' in gL10nData) {
  11895. str = gL10nData[key + '[one]'][prop];
  11896. } else if (n == 2 && key + '[two]' in gL10nData) {
  11897. str = gL10nData[key + '[two]'][prop];
  11898. } else if (key + index in gL10nData) {
  11899. str = gL10nData[key + index][prop];
  11900. } else if (key + '[other]' in gL10nData) {
  11901. str = gL10nData[key + '[other]'][prop];
  11902. }
  11903. return str;
  11904. };
  11905. function getL10nData(key, args, fallback) {
  11906. var data = gL10nData[key];
  11907. if (!data) {
  11908. console.warn('#' + key + ' is undefined.');
  11909. if (!fallback) {
  11910. return null;
  11911. }
  11912. data = fallback;
  11913. }
  11914. var rv = {};
  11915. for (var prop in data) {
  11916. var str = data[prop];
  11917. str = substIndexes(str, args, key, prop);
  11918. str = substArguments(str, args, key);
  11919. rv[prop] = str;
  11920. }
  11921. return rv;
  11922. }
  11923. function substIndexes(str, args, key, prop) {
  11924. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  11925. var reMatch = reIndex.exec(str);
  11926. if (!reMatch || !reMatch.length) return str;
  11927. var macroName = reMatch[1];
  11928. var paramName = reMatch[2];
  11929. var param;
  11930. if (args && paramName in args) {
  11931. param = args[paramName];
  11932. } else if (paramName in gL10nData) {
  11933. param = gL10nData[paramName];
  11934. }
  11935. if (macroName in gMacros) {
  11936. var macro = gMacros[macroName];
  11937. str = macro(str, param, key, prop);
  11938. }
  11939. return str;
  11940. }
  11941. function substArguments(str, args, key) {
  11942. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  11943. return str.replace(reArgs, function (matched_text, arg) {
  11944. if (args && arg in args) {
  11945. return args[arg];
  11946. }
  11947. if (arg in gL10nData) {
  11948. return gL10nData[arg];
  11949. }
  11950. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  11951. return matched_text;
  11952. });
  11953. }
  11954. function translateElement(element) {
  11955. var l10n = getL10nAttributes(element);
  11956. if (!l10n.id) return;
  11957. var data = getL10nData(l10n.id, l10n.args);
  11958. if (!data) {
  11959. console.warn('#' + l10n.id + ' is undefined.');
  11960. return;
  11961. }
  11962. if (data[gTextProp]) {
  11963. if (getChildElementCount(element) === 0) {
  11964. element[gTextProp] = data[gTextProp];
  11965. } else {
  11966. var children = element.childNodes;
  11967. var found = false;
  11968. for (var i = 0, l = children.length; i < l; i++) {
  11969. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  11970. if (found) {
  11971. children[i].nodeValue = '';
  11972. } else {
  11973. children[i].nodeValue = data[gTextProp];
  11974. found = true;
  11975. }
  11976. }
  11977. }
  11978. if (!found) {
  11979. var textNode = document.createTextNode(data[gTextProp]);
  11980. element.insertBefore(textNode, element.firstChild);
  11981. }
  11982. }
  11983. delete data[gTextProp];
  11984. }
  11985. for (var k in data) {
  11986. element[k] = data[k];
  11987. }
  11988. }
  11989. function getChildElementCount(element) {
  11990. if (element.children) {
  11991. return element.children.length;
  11992. }
  11993. if (typeof element.childElementCount !== 'undefined') {
  11994. return element.childElementCount;
  11995. }
  11996. var count = 0;
  11997. for (var i = 0; i < element.childNodes.length; i++) {
  11998. count += element.nodeType === 1 ? 1 : 0;
  11999. }
  12000. return count;
  12001. }
  12002. function translateFragment(element) {
  12003. element = element || document.documentElement;
  12004. var children = getTranslatableChildren(element);
  12005. var elementCount = children.length;
  12006. for (var i = 0; i < elementCount; i++) {
  12007. translateElement(children[i]);
  12008. }
  12009. translateElement(element);
  12010. }
  12011. return {
  12012. get: function (key, args, fallbackString) {
  12013. var index = key.lastIndexOf('.');
  12014. var prop = gTextProp;
  12015. if (index > 0) {
  12016. prop = key.substring(index + 1);
  12017. key = key.substring(0, index);
  12018. }
  12019. var fallback;
  12020. if (fallbackString) {
  12021. fallback = {};
  12022. fallback[prop] = fallbackString;
  12023. }
  12024. var data = getL10nData(key, args, fallback);
  12025. if (data && prop in data) {
  12026. return data[prop];
  12027. }
  12028. return '{{' + key + '}}';
  12029. },
  12030. getData: function () {
  12031. return gL10nData;
  12032. },
  12033. getText: function () {
  12034. return gTextData;
  12035. },
  12036. getLanguage: function () {
  12037. return gLanguage;
  12038. },
  12039. setLanguage: function (lang, callback) {
  12040. loadLocale(lang, function () {
  12041. if (callback) callback();
  12042. });
  12043. },
  12044. getDirection: function () {
  12045. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  12046. var shortCode = gLanguage.split('-', 1)[0];
  12047. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  12048. },
  12049. translate: translateFragment,
  12050. getReadyState: function () {
  12051. return gReadyState;
  12052. },
  12053. ready: function (callback) {
  12054. if (!callback) {
  12055. return;
  12056. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  12057. window.setTimeout(function () {
  12058. callback();
  12059. });
  12060. } else if (document.addEventListener) {
  12061. document.addEventListener('localized', function once() {
  12062. document.removeEventListener('localized', once);
  12063. callback();
  12064. });
  12065. }
  12066. }
  12067. };
  12068. }(window, document);
  12069. /***/ }),
  12070. /* 44 */
  12071. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12072. Object.defineProperty(exports, "__esModule", ({
  12073. value: true
  12074. }));
  12075. exports.GenericScripting = void 0;
  12076. exports.docPropertiesLookup = docPropertiesLookup;
  12077. var _pdfjsLib = __webpack_require__(5);
  12078. async function docPropertiesLookup(pdfDocument) {
  12079. const url = "",
  12080. baseUrl = url.split("#")[0];
  12081. let {
  12082. info,
  12083. metadata,
  12084. contentDispositionFilename,
  12085. contentLength
  12086. } = await pdfDocument.getMetadata();
  12087. if (!contentLength) {
  12088. const {
  12089. length
  12090. } = await pdfDocument.getDownloadInfo();
  12091. contentLength = length;
  12092. }
  12093. return { ...info,
  12094. baseURL: baseUrl,
  12095. filesize: contentLength,
  12096. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  12097. metadata: metadata?.getRaw(),
  12098. authors: metadata?.get("dc:creator"),
  12099. numPages: pdfDocument.numPages,
  12100. URL: url
  12101. };
  12102. }
  12103. class GenericScripting {
  12104. constructor(sandboxBundleSrc) {
  12105. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  12106. return window.pdfjsSandbox.QuickJSSandbox();
  12107. });
  12108. }
  12109. async createSandbox(data) {
  12110. const sandbox = await this._ready;
  12111. sandbox.create(data);
  12112. }
  12113. async dispatchEventInSandbox(event) {
  12114. const sandbox = await this._ready;
  12115. setTimeout(() => sandbox.dispatchEvent(event), 0);
  12116. }
  12117. async destroySandbox() {
  12118. const sandbox = await this._ready;
  12119. sandbox.nukeSandbox();
  12120. }
  12121. }
  12122. exports.GenericScripting = GenericScripting;
  12123. /***/ }),
  12124. /* 45 */
  12125. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12126. Object.defineProperty(exports, "__esModule", ({
  12127. value: true
  12128. }));
  12129. exports.PDFPrintService = PDFPrintService;
  12130. var _pdfjsLib = __webpack_require__(5);
  12131. var _app = __webpack_require__(2);
  12132. var _print_utils = __webpack_require__(46);
  12133. let activeService = null;
  12134. let dialog = null;
  12135. let overlayManager = null;
  12136. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise) {
  12137. const scratchCanvas = activeService.scratchCanvas;
  12138. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  12139. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  12140. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  12141. const ctx = scratchCanvas.getContext("2d");
  12142. ctx.save();
  12143. ctx.fillStyle = "rgb(255, 255, 255)";
  12144. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  12145. ctx.restore();
  12146. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  12147. const renderContext = {
  12148. canvasContext: ctx,
  12149. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  12150. viewport: pdfPage.getViewport({
  12151. scale: 1,
  12152. rotation: size.rotation
  12153. }),
  12154. intent: "print",
  12155. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  12156. optionalContentConfigPromise
  12157. };
  12158. return pdfPage.render(renderContext).promise;
  12159. });
  12160. }
  12161. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, l10n) {
  12162. this.pdfDocument = pdfDocument;
  12163. this.pagesOverview = pagesOverview;
  12164. this.printContainer = printContainer;
  12165. this._printResolution = printResolution || 150;
  12166. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  12167. this.l10n = l10n;
  12168. this.currentPage = -1;
  12169. this.scratchCanvas = document.createElement("canvas");
  12170. }
  12171. PDFPrintService.prototype = {
  12172. layout() {
  12173. this.throwIfInactive();
  12174. const body = document.querySelector("body");
  12175. body.setAttribute("data-pdfjsprinting", true);
  12176. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  12177. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  12178. }, this);
  12179. if (!hasEqualPageSizes) {
  12180. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  12181. }
  12182. this.pageStyleSheet = document.createElement("style");
  12183. const pageSize = this.pagesOverview[0];
  12184. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  12185. body.appendChild(this.pageStyleSheet);
  12186. },
  12187. destroy() {
  12188. if (activeService !== this) {
  12189. return;
  12190. }
  12191. this.printContainer.textContent = "";
  12192. const body = document.querySelector("body");
  12193. body.removeAttribute("data-pdfjsprinting");
  12194. if (this.pageStyleSheet) {
  12195. this.pageStyleSheet.remove();
  12196. this.pageStyleSheet = null;
  12197. }
  12198. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  12199. this.scratchCanvas = null;
  12200. activeService = null;
  12201. ensureOverlay().then(function () {
  12202. if (overlayManager.active === dialog) {
  12203. overlayManager.close(dialog);
  12204. }
  12205. });
  12206. },
  12207. renderPages() {
  12208. if (this.pdfDocument.isPureXfa) {
  12209. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  12210. return Promise.resolve();
  12211. }
  12212. const pageCount = this.pagesOverview.length;
  12213. const renderNextPage = (resolve, reject) => {
  12214. this.throwIfInactive();
  12215. if (++this.currentPage >= pageCount) {
  12216. renderProgress(pageCount, pageCount, this.l10n);
  12217. resolve();
  12218. return;
  12219. }
  12220. const index = this.currentPage;
  12221. renderProgress(index, pageCount, this.l10n);
  12222. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise).then(this.useRenderedPage.bind(this)).then(function () {
  12223. renderNextPage(resolve, reject);
  12224. }, reject);
  12225. };
  12226. return new Promise(renderNextPage);
  12227. },
  12228. useRenderedPage() {
  12229. this.throwIfInactive();
  12230. const img = document.createElement("img");
  12231. const scratchCanvas = this.scratchCanvas;
  12232. if ("toBlob" in scratchCanvas) {
  12233. scratchCanvas.toBlob(function (blob) {
  12234. img.src = URL.createObjectURL(blob);
  12235. });
  12236. } else {
  12237. img.src = scratchCanvas.toDataURL();
  12238. }
  12239. const wrapper = document.createElement("div");
  12240. wrapper.className = "printedPage";
  12241. wrapper.appendChild(img);
  12242. this.printContainer.appendChild(wrapper);
  12243. return new Promise(function (resolve, reject) {
  12244. img.onload = resolve;
  12245. img.onerror = reject;
  12246. });
  12247. },
  12248. performPrint() {
  12249. this.throwIfInactive();
  12250. return new Promise(resolve => {
  12251. setTimeout(() => {
  12252. if (!this.active) {
  12253. resolve();
  12254. return;
  12255. }
  12256. print.call(window);
  12257. setTimeout(resolve, 20);
  12258. }, 0);
  12259. });
  12260. },
  12261. get active() {
  12262. return this === activeService;
  12263. },
  12264. throwIfInactive() {
  12265. if (!this.active) {
  12266. throw new Error("This print request was cancelled or completed.");
  12267. }
  12268. }
  12269. };
  12270. const print = window.print;
  12271. window.print = function () {
  12272. if (activeService) {
  12273. console.warn("Ignored window.print() because of a pending print job.");
  12274. return;
  12275. }
  12276. ensureOverlay().then(function () {
  12277. if (activeService) {
  12278. overlayManager.open(dialog);
  12279. }
  12280. });
  12281. try {
  12282. dispatchEvent("beforeprint");
  12283. } finally {
  12284. if (!activeService) {
  12285. console.error("Expected print service to be initialized.");
  12286. ensureOverlay().then(function () {
  12287. if (overlayManager.active === dialog) {
  12288. overlayManager.close(dialog);
  12289. }
  12290. });
  12291. return;
  12292. }
  12293. const activeServiceOnEntry = activeService;
  12294. activeService.renderPages().then(function () {
  12295. return activeServiceOnEntry.performPrint();
  12296. }).catch(function () {}).then(function () {
  12297. if (activeServiceOnEntry.active) {
  12298. abort();
  12299. }
  12300. });
  12301. }
  12302. };
  12303. function dispatchEvent(eventType) {
  12304. const event = document.createEvent("CustomEvent");
  12305. event.initCustomEvent(eventType, false, false, "custom");
  12306. window.dispatchEvent(event);
  12307. }
  12308. function abort() {
  12309. if (activeService) {
  12310. activeService.destroy();
  12311. dispatchEvent("afterprint");
  12312. }
  12313. }
  12314. function renderProgress(index, total, l10n) {
  12315. dialog ||= document.getElementById("printServiceDialog");
  12316. const progress = Math.round(100 * index / total);
  12317. const progressBar = dialog.querySelector("progress");
  12318. const progressPerc = dialog.querySelector(".relative-progress");
  12319. progressBar.value = progress;
  12320. l10n.get("print_progress_percent", {
  12321. progress
  12322. }).then(msg => {
  12323. progressPerc.textContent = msg;
  12324. });
  12325. }
  12326. window.addEventListener("keydown", function (event) {
  12327. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  12328. window.print();
  12329. event.preventDefault();
  12330. if (event.stopImmediatePropagation) {
  12331. event.stopImmediatePropagation();
  12332. } else {
  12333. event.stopPropagation();
  12334. }
  12335. }
  12336. }, true);
  12337. if ("onbeforeprint" in window) {
  12338. const stopPropagationIfNeeded = function (event) {
  12339. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  12340. event.stopImmediatePropagation();
  12341. }
  12342. };
  12343. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  12344. window.addEventListener("afterprint", stopPropagationIfNeeded);
  12345. }
  12346. let overlayPromise;
  12347. function ensureOverlay() {
  12348. if (!overlayPromise) {
  12349. overlayManager = _app.PDFViewerApplication.overlayManager;
  12350. if (!overlayManager) {
  12351. throw new Error("The overlay manager has not yet been initialized.");
  12352. }
  12353. dialog ||= document.getElementById("printServiceDialog");
  12354. overlayPromise = overlayManager.register(dialog, true);
  12355. document.getElementById("printCancel").onclick = abort;
  12356. dialog.addEventListener("close", abort);
  12357. }
  12358. return overlayPromise;
  12359. }
  12360. _app.PDFPrintServiceFactory.instance = {
  12361. supportsPrinting: true,
  12362. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n) {
  12363. if (activeService) {
  12364. throw new Error("The print service is created and active.");
  12365. }
  12366. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n);
  12367. return activeService;
  12368. }
  12369. };
  12370. /***/ }),
  12371. /* 46 */
  12372. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12373. Object.defineProperty(exports, "__esModule", ({
  12374. value: true
  12375. }));
  12376. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  12377. var _pdfjsLib = __webpack_require__(5);
  12378. var _pdf_link_service = __webpack_require__(8);
  12379. var _xfa_layer_builder = __webpack_require__(35);
  12380. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  12381. const xfaHtml = pdfDocument.allXfaHtml;
  12382. const linkService = new _pdf_link_service.SimpleLinkService();
  12383. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  12384. for (const xfaPage of xfaHtml.children) {
  12385. const page = document.createElement("div");
  12386. page.className = "xfaPrintedPage";
  12387. printContainer.appendChild(page);
  12388. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  12389. pageDiv: page,
  12390. pdfPage: null,
  12391. annotationStorage: pdfDocument.annotationStorage,
  12392. linkService,
  12393. xfaHtml: xfaPage
  12394. });
  12395. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  12396. scale
  12397. });
  12398. builder.render(viewport, "print");
  12399. }
  12400. }
  12401. /***/ })
  12402. /******/ ]);
  12403. /************************************************************************/
  12404. /******/ // The module cache
  12405. /******/ var __webpack_module_cache__ = {};
  12406. /******/
  12407. /******/ // The require function
  12408. /******/ function __webpack_require__(moduleId) {
  12409. /******/ // Check if module is in cache
  12410. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  12411. /******/ if (cachedModule !== undefined) {
  12412. /******/ return cachedModule.exports;
  12413. /******/ }
  12414. /******/ // Create a new module (and put it into the cache)
  12415. /******/ var module = __webpack_module_cache__[moduleId] = {
  12416. /******/ // no module.id needed
  12417. /******/ // no module.loaded needed
  12418. /******/ exports: {}
  12419. /******/ };
  12420. /******/
  12421. /******/ // Execute the module function
  12422. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  12423. /******/
  12424. /******/ // Return the exports of the module
  12425. /******/ return module.exports;
  12426. /******/ }
  12427. /******/
  12428. /************************************************************************/
  12429. var __webpack_exports__ = {};
  12430. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  12431. (() => {
  12432. var exports = __webpack_exports__;
  12433. Object.defineProperty(exports, "__esModule", ({
  12434. value: true
  12435. }));
  12436. Object.defineProperty(exports, "PDFViewerApplication", ({
  12437. enumerable: true,
  12438. get: function () {
  12439. return _app.PDFViewerApplication;
  12440. }
  12441. }));
  12442. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  12443. enumerable: true,
  12444. get: function () {
  12445. return _app_options.AppOptions;
  12446. }
  12447. }));
  12448. var _app_options = __webpack_require__(1);
  12449. var _app = __webpack_require__(2);
  12450. const pdfjsVersion = '2.14.305';
  12451. const pdfjsBuild = 'eaaa8b4ad';
  12452. window.PDFViewerApplication = _app.PDFViewerApplication;
  12453. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  12454. ;
  12455. ;
  12456. {
  12457. __webpack_require__(39);
  12458. }
  12459. ;
  12460. {
  12461. __webpack_require__(45);
  12462. }
  12463. function getViewerConfiguration() {
  12464. let errorWrapper = null;
  12465. errorWrapper = {
  12466. container: document.getElementById("errorWrapper"),
  12467. errorMessage: document.getElementById("errorMessage"),
  12468. closeButton: document.getElementById("errorClose"),
  12469. errorMoreInfo: document.getElementById("errorMoreInfo"),
  12470. moreInfoButton: document.getElementById("errorShowMore"),
  12471. lessInfoButton: document.getElementById("errorShowLess")
  12472. };
  12473. return {
  12474. appContainer: document.body,
  12475. mainContainer: document.getElementById("viewerContainer"),
  12476. viewerContainer: document.getElementById("viewer"),
  12477. toolbar: {
  12478. container: document.getElementById("toolbarViewer"),
  12479. numPages: document.getElementById("numPages"),
  12480. pageNumber: document.getElementById("pageNumber"),
  12481. scaleSelect: document.getElementById("scaleSelect"),
  12482. customScaleOption: document.getElementById("customScaleOption"),
  12483. previous: document.getElementById("previous"),
  12484. next: document.getElementById("next"),
  12485. zoomIn: document.getElementById("zoomIn"),
  12486. zoomOut: document.getElementById("zoomOut"),
  12487. viewFind: document.getElementById("viewFind"),
  12488. openFile: document.getElementById("openFile"),
  12489. print: document.getElementById("print"),
  12490. presentationModeButton: document.getElementById("presentationMode"),
  12491. download: document.getElementById("download"),
  12492. viewBookmark: document.getElementById("viewBookmark")
  12493. },
  12494. secondaryToolbar: {
  12495. toolbar: document.getElementById("secondaryToolbar"),
  12496. toggleButton: document.getElementById("secondaryToolbarToggle"),
  12497. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  12498. openFileButton: document.getElementById("secondaryOpenFile"),
  12499. printButton: document.getElementById("secondaryPrint"),
  12500. downloadButton: document.getElementById("secondaryDownload"),
  12501. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  12502. firstPageButton: document.getElementById("firstPage"),
  12503. lastPageButton: document.getElementById("lastPage"),
  12504. pageRotateCwButton: document.getElementById("pageRotateCw"),
  12505. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  12506. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  12507. cursorHandToolButton: document.getElementById("cursorHandTool"),
  12508. scrollPageButton: document.getElementById("scrollPage"),
  12509. scrollVerticalButton: document.getElementById("scrollVertical"),
  12510. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  12511. scrollWrappedButton: document.getElementById("scrollWrapped"),
  12512. spreadNoneButton: document.getElementById("spreadNone"),
  12513. spreadOddButton: document.getElementById("spreadOdd"),
  12514. spreadEvenButton: document.getElementById("spreadEven"),
  12515. documentPropertiesButton: document.getElementById("documentProperties")
  12516. },
  12517. sidebar: {
  12518. outerContainer: document.getElementById("outerContainer"),
  12519. sidebarContainer: document.getElementById("sidebarContainer"),
  12520. toggleButton: document.getElementById("sidebarToggle"),
  12521. thumbnailButton: document.getElementById("viewThumbnail"),
  12522. outlineButton: document.getElementById("viewOutline"),
  12523. attachmentsButton: document.getElementById("viewAttachments"),
  12524. layersButton: document.getElementById("viewLayers"),
  12525. thumbnailView: document.getElementById("thumbnailView"),
  12526. outlineView: document.getElementById("outlineView"),
  12527. attachmentsView: document.getElementById("attachmentsView"),
  12528. layersView: document.getElementById("layersView"),
  12529. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  12530. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  12531. },
  12532. sidebarResizer: {
  12533. outerContainer: document.getElementById("outerContainer"),
  12534. resizer: document.getElementById("sidebarResizer")
  12535. },
  12536. findBar: {
  12537. bar: document.getElementById("findbar"),
  12538. toggleButton: document.getElementById("viewFind"),
  12539. findField: document.getElementById("findInput"),
  12540. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  12541. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  12542. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  12543. entireWordCheckbox: document.getElementById("findEntireWord"),
  12544. findMsg: document.getElementById("findMsg"),
  12545. findResultsCount: document.getElementById("findResultsCount"),
  12546. findPreviousButton: document.getElementById("findPrevious"),
  12547. findNextButton: document.getElementById("findNext")
  12548. },
  12549. passwordOverlay: {
  12550. dialog: document.getElementById("passwordDialog"),
  12551. label: document.getElementById("passwordText"),
  12552. input: document.getElementById("password"),
  12553. submitButton: document.getElementById("passwordSubmit"),
  12554. cancelButton: document.getElementById("passwordCancel")
  12555. },
  12556. documentProperties: {
  12557. dialog: document.getElementById("documentPropertiesDialog"),
  12558. closeButton: document.getElementById("documentPropertiesClose"),
  12559. fields: {
  12560. fileName: document.getElementById("fileNameField"),
  12561. fileSize: document.getElementById("fileSizeField"),
  12562. title: document.getElementById("titleField"),
  12563. author: document.getElementById("authorField"),
  12564. subject: document.getElementById("subjectField"),
  12565. keywords: document.getElementById("keywordsField"),
  12566. creationDate: document.getElementById("creationDateField"),
  12567. modificationDate: document.getElementById("modificationDateField"),
  12568. creator: document.getElementById("creatorField"),
  12569. producer: document.getElementById("producerField"),
  12570. version: document.getElementById("versionField"),
  12571. pageCount: document.getElementById("pageCountField"),
  12572. pageSize: document.getElementById("pageSizeField"),
  12573. linearized: document.getElementById("linearizedField")
  12574. }
  12575. },
  12576. errorWrapper,
  12577. printContainer: document.getElementById("printContainer"),
  12578. openFileInput: document.getElementById("fileInput"),
  12579. debuggerScriptPath: "./debugger.js"
  12580. };
  12581. }
  12582. function webViewerLoad() {
  12583. const config = getViewerConfiguration();
  12584. const event = document.createEvent("CustomEvent");
  12585. event.initCustomEvent("webviewerloaded", true, true, {
  12586. source: window
  12587. });
  12588. try {
  12589. parent.document.dispatchEvent(event);
  12590. } catch (ex) {
  12591. console.error(`webviewerloaded: ${ex}`);
  12592. document.dispatchEvent(event);
  12593. }
  12594. _app.PDFViewerApplication.run(config);
  12595. }
  12596. document.blockUnblockOnload?.(true);
  12597. if (document.readyState === "interactive" || document.readyState === "complete") {
  12598. webViewerLoad();
  12599. } else {
  12600. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  12601. }
  12602. })();
  12603. /******/ })()
  12604. ;
  12605. //# sourceMappingURL=viewer.js.map