viewer.js 391 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591
  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