viewer.js 393 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. /******/ (() => { // 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 = typeof navigator !== "undefined" && navigator.userAgent || "";
  36. const platform = typeof navigator !== "undefined" && navigator.platform || "";
  37. const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1;
  38. const isAndroid = /Android/.test(userAgent);
  39. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  40. const isIOSChrome = /CriOS/.test(userAgent);
  41. (function checkOnBlobSupport() {
  42. if (isIOSChrome) {
  43. compatibilityParams.disableCreateObjectURL = true;
  44. }
  45. })();
  46. (function checkCanvasSizeLimitation() {
  47. if (isIOS || isAndroid) {
  48. compatibilityParams.maxCanvasPixels = 5242880;
  49. }
  50. })();
  51. }
  52. const OptionKind = {
  53. VIEWER: 0x02,
  54. API: 0x04,
  55. WORKER: 0x08,
  56. PREFERENCE: 0x80
  57. };
  58. exports.OptionKind = OptionKind;
  59. const defaultOptions = {
  60. annotationMode: {
  61. value: 2,
  62. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  63. },
  64. cursorToolOnLoad: {
  65. value: 0,
  66. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  67. },
  68. defaultUrl: {
  69. // value: "compressed.tracemonkey-pldi-09.pdf",
  70. value:DEFAULT_URL,
  71. kind: OptionKind.VIEWER
  72. },
  73. defaultZoomValue: {
  74. value: "",
  75. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  76. },
  77. disableHistory: {
  78. value: false,
  79. kind: OptionKind.VIEWER
  80. },
  81. disablePageLabels: {
  82. value: false,
  83. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  84. },
  85. enablePermissions: {
  86. value: false,
  87. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  88. },
  89. enablePrintAutoRotate: {
  90. value: true,
  91. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  92. },
  93. enableScripting: {
  94. value: true,
  95. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  96. },
  97. externalLinkRel: {
  98. value: "noopener noreferrer nofollow",
  99. kind: OptionKind.VIEWER
  100. },
  101. externalLinkTarget: {
  102. value: 0,
  103. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  104. },
  105. historyUpdateUrl: {
  106. value: false,
  107. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  108. },
  109. ignoreDestinationZoom: {
  110. value: false,
  111. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  112. },
  113. imageResourcesPath: {
  114. value: "./images/",
  115. kind: OptionKind.VIEWER
  116. },
  117. maxCanvasPixels: {
  118. value: 16777216,
  119. compatibility: compatibilityParams.maxCanvasPixels,
  120. kind: OptionKind.VIEWER
  121. },
  122. pdfBugEnabled: {
  123. value: false,
  124. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  125. },
  126. printResolution: {
  127. value: 150,
  128. kind: OptionKind.VIEWER
  129. },
  130. renderer: {
  131. value: "canvas",
  132. kind: OptionKind.VIEWER
  133. },
  134. sidebarViewOnLoad: {
  135. value: -1,
  136. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  137. },
  138. scrollModeOnLoad: {
  139. value: -1,
  140. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  141. },
  142. spreadModeOnLoad: {
  143. value: -1,
  144. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  145. },
  146. textLayerMode: {
  147. value: 1,
  148. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  149. },
  150. useOnlyCssZoom: {
  151. value: false,
  152. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  153. },
  154. viewerCssTheme: {
  155. value: 0,
  156. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  157. },
  158. viewOnLoad: {
  159. value: 0,
  160. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  161. },
  162. cMapPacked: {
  163. value: true,
  164. kind: OptionKind.API
  165. },
  166. cMapUrl: {
  167. value: "../web/cmaps/",
  168. kind: OptionKind.API
  169. },
  170. disableAutoFetch: {
  171. value: false,
  172. kind: OptionKind.API + OptionKind.PREFERENCE
  173. },
  174. disableFontFace: {
  175. value: false,
  176. kind: OptionKind.API + OptionKind.PREFERENCE
  177. },
  178. disableRange: {
  179. value: false,
  180. kind: OptionKind.API + OptionKind.PREFERENCE
  181. },
  182. disableStream: {
  183. value: false,
  184. kind: OptionKind.API + OptionKind.PREFERENCE
  185. },
  186. docBaseUrl: {
  187. value: "",
  188. kind: OptionKind.API
  189. },
  190. enableXfa: {
  191. value: true,
  192. kind: OptionKind.API + OptionKind.PREFERENCE
  193. },
  194. fontExtraProperties: {
  195. value: false,
  196. kind: OptionKind.API
  197. },
  198. isEvalSupported: {
  199. value: true,
  200. kind: OptionKind.API
  201. },
  202. maxImageSize: {
  203. value: -1,
  204. kind: OptionKind.API
  205. },
  206. pdfBug: {
  207. value: false,
  208. kind: OptionKind.API
  209. },
  210. standardFontDataUrl: {
  211. value: "../web/standard_fonts/",
  212. kind: OptionKind.API
  213. },
  214. verbosity: {
  215. value: 1,
  216. kind: OptionKind.API
  217. },
  218. workerPort: {
  219. value: null,
  220. kind: OptionKind.WORKER
  221. },
  222. workerSrc: {
  223. value: "../build/pdf.worker.js",
  224. kind: OptionKind.WORKER
  225. }
  226. };
  227. {
  228. defaultOptions.disablePreferences = {
  229. value: false,
  230. kind: OptionKind.VIEWER
  231. };
  232. defaultOptions.locale = {
  233. value: typeof navigator !== "undefined" ? navigator.language : "en-US",
  234. kind: OptionKind.VIEWER
  235. };
  236. defaultOptions.sandboxBundleSrc = {
  237. value: "../build/pdf.sandbox.js",
  238. kind: OptionKind.VIEWER
  239. };
  240. defaultOptions.renderer.kind += OptionKind.PREFERENCE;
  241. }
  242. const userOptions = Object.create(null);
  243. class AppOptions {
  244. constructor() {
  245. throw new Error("Cannot initialize AppOptions.");
  246. }
  247. static get(name) {
  248. const userOption = userOptions[name];
  249. if (userOption !== undefined) {
  250. return userOption;
  251. }
  252. const defaultOption = defaultOptions[name];
  253. if (defaultOption !== undefined) {
  254. return defaultOption.compatibility ?? defaultOption.value;
  255. }
  256. return undefined;
  257. }
  258. static getAll(kind = null) {
  259. const options = Object.create(null);
  260. for (const name in defaultOptions) {
  261. const defaultOption = defaultOptions[name];
  262. if (kind) {
  263. if ((kind & defaultOption.kind) === 0) {
  264. continue;
  265. }
  266. if (kind === OptionKind.PREFERENCE) {
  267. const value = defaultOption.value,
  268. valueType = typeof value;
  269. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  270. options[name] = value;
  271. continue;
  272. }
  273. throw new Error(`Invalid type for preference: ${name}`);
  274. }
  275. }
  276. const userOption = userOptions[name];
  277. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility ?? defaultOption.value;
  278. }
  279. return options;
  280. }
  281. static set(name, value) {
  282. userOptions[name] = value;
  283. }
  284. static setAll(options) {
  285. for (const name in options) {
  286. userOptions[name] = options[name];
  287. }
  288. }
  289. static remove(name) {
  290. delete userOptions[name];
  291. }
  292. static _hasUserOptions() {
  293. return Object.keys(userOptions).length > 0;
  294. }
  295. }
  296. exports.AppOptions = AppOptions;
  297. /***/ }),
  298. /* 2 */
  299. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  300. Object.defineProperty(exports, "__esModule", ({
  301. value: true
  302. }));
  303. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  304. var _ui_utils = __webpack_require__(3);
  305. var _app_options = __webpack_require__(1);
  306. var _event_utils = __webpack_require__(4);
  307. var _pdfjsLib = __webpack_require__(5);
  308. var _pdf_cursor_tools = __webpack_require__(6);
  309. var _overlay_manager = __webpack_require__(8);
  310. var _password_prompt = __webpack_require__(9);
  311. var _pdf_attachment_viewer = __webpack_require__(10);
  312. var _pdf_document_properties = __webpack_require__(12);
  313. var _pdf_find_bar = __webpack_require__(13);
  314. var _pdf_find_controller = __webpack_require__(14);
  315. var _pdf_history = __webpack_require__(16);
  316. var _pdf_layer_viewer = __webpack_require__(17);
  317. var _pdf_link_service = __webpack_require__(18);
  318. var _pdf_outline_viewer = __webpack_require__(19);
  319. var _pdf_presentation_mode = __webpack_require__(20);
  320. var _pdf_rendering_queue = __webpack_require__(21);
  321. var _pdf_scripting_manager = __webpack_require__(22);
  322. var _pdf_sidebar = __webpack_require__(23);
  323. var _pdf_sidebar_resizer = __webpack_require__(24);
  324. var _pdf_thumbnail_viewer = __webpack_require__(25);
  325. var _pdf_viewer = __webpack_require__(27);
  326. var _secondary_toolbar = __webpack_require__(36);
  327. var _toolbar = __webpack_require__(37);
  328. var _view_history = __webpack_require__(38);
  329. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  330. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  331. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  332. const ViewOnLoad = {
  333. UNKNOWN: -1,
  334. PREVIOUS: 0,
  335. INITIAL: 1
  336. };
  337. const ViewerCssTheme = {
  338. AUTOMATIC: 0,
  339. LIGHT: 1,
  340. DARK: 2
  341. };
  342. 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"];
  343. 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"];
  344. class DefaultExternalServices {
  345. constructor() {
  346. throw new Error("Cannot initialize DefaultExternalServices.");
  347. }
  348. static updateFindControlState(data) {}
  349. static updateFindMatchesCount(data) {}
  350. static initPassiveLoading(callbacks) {}
  351. static async fallback(data) {}
  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. _fellback: false,
  386. appConfig: null,
  387. pdfDocument: null,
  388. pdfLoadingTask: null,
  389. printService: null,
  390. pdfViewer: null,
  391. pdfThumbnailViewer: null,
  392. pdfRenderingQueue: null,
  393. pdfPresentationMode: null,
  394. pdfDocumentProperties: null,
  395. pdfLinkService: null,
  396. pdfHistory: null,
  397. pdfSidebar: null,
  398. pdfSidebarResizer: null,
  399. pdfOutlineViewer: null,
  400. pdfAttachmentViewer: null,
  401. pdfLayerViewer: null,
  402. pdfCursorTools: null,
  403. pdfScriptingManager: null,
  404. store: null,
  405. downloadManager: null,
  406. overlayManager: null,
  407. preferences: null,
  408. toolbar: null,
  409. secondaryToolbar: null,
  410. eventBus: null,
  411. l10n: null,
  412. isInitialViewSet: false,
  413. downloadComplete: false,
  414. isViewerEmbedded: window.parent !== window,
  415. url: "",
  416. baseUrl: "",
  417. _downloadUrl: "",
  418. externalServices: DefaultExternalServices,
  419. _boundEvents: Object.create(null),
  420. documentInfo: null,
  421. metadata: null,
  422. _contentDispositionFilename: null,
  423. _contentLength: null,
  424. _saveInProgress: false,
  425. _docStats: null,
  426. _wheelUnusedTicks: 0,
  427. _idleCallbacks: new Set(),
  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") === _pdfjsLib.LinkTarget.NONE) {
  436. _app_options.AppOptions.set("externalLinkTarget", _pdfjsLib.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 params = (0, _ui_utils.parseQueryString)(hash),
  471. waitOn = [];
  472. if (params.get("disableworker") === "true") {
  473. waitOn.push(loadFakeWorker());
  474. }
  475. if (params.has("disablerange")) {
  476. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  477. }
  478. if (params.has("disablestream")) {
  479. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  480. }
  481. if (params.has("disableautofetch")) {
  482. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  483. }
  484. if (params.has("disablefontface")) {
  485. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  486. }
  487. if (params.has("disablehistory")) {
  488. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  489. }
  490. if (params.has("verbosity")) {
  491. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  492. }
  493. if (params.has("textlayer")) {
  494. switch (params.get("textlayer")) {
  495. case "off":
  496. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  497. break;
  498. case "visible":
  499. case "shadow":
  500. case "hover":
  501. const viewer = this.appConfig.viewerContainer;
  502. viewer.classList.add(`textLayer-${params.get("textlayer")}`);
  503. break;
  504. }
  505. }
  506. if (params.has("pdfbug")) {
  507. _app_options.AppOptions.set("pdfBug", true);
  508. _app_options.AppOptions.set("fontExtraProperties", true);
  509. const enabled = params.get("pdfbug").split(",");
  510. waitOn.push(initPDFBug(enabled));
  511. }
  512. if (params.has("locale")) {
  513. _app_options.AppOptions.set("locale", params.get("locale"));
  514. }
  515. if (waitOn.length === 0) {
  516. return;
  517. }
  518. try {
  519. await Promise.all(waitOn);
  520. } catch (reason) {
  521. console.error(`_parseHashParameters: "${reason.message}".`);
  522. }
  523. },
  524. async _initializeL10n() {
  525. this.l10n = this.externalServices.createL10n({
  526. locale: _app_options.AppOptions.get("locale")
  527. });
  528. const dir = await this.l10n.getDirection();
  529. document.getElementsByTagName("html")[0].dir = dir;
  530. },
  531. _forceCssTheme() {
  532. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  533. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  534. return;
  535. }
  536. try {
  537. const styleSheet = document.styleSheets[0];
  538. const cssRules = styleSheet?.cssRules || [];
  539. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  540. const rule = cssRules[i];
  541. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  542. if (cssTheme === ViewerCssTheme.LIGHT) {
  543. styleSheet.deleteRule(i);
  544. return;
  545. }
  546. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  547. if (darkRules?.[1]) {
  548. styleSheet.deleteRule(i);
  549. styleSheet.insertRule(darkRules[1], i);
  550. }
  551. return;
  552. }
  553. }
  554. } catch (reason) {
  555. console.error(`_forceCssTheme: "${reason?.message}".`);
  556. }
  557. },
  558. async _initializeViewerComponents() {
  559. const {
  560. appConfig,
  561. externalServices
  562. } = this;
  563. let eventBus;
  564. if (appConfig.eventBus) {
  565. eventBus = appConfig.eventBus;
  566. } else if (externalServices.isInAutomation) {
  567. eventBus = new _event_utils.AutomationEventBus();
  568. } else {
  569. eventBus = new _event_utils.EventBus();
  570. }
  571. this.eventBus = eventBus;
  572. this.overlayManager = new _overlay_manager.OverlayManager();
  573. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  574. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  575. this.pdfRenderingQueue = pdfRenderingQueue;
  576. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  577. eventBus,
  578. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  579. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  580. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  581. });
  582. this.pdfLinkService = pdfLinkService;
  583. const downloadManager = externalServices.createDownloadManager();
  584. this.downloadManager = downloadManager;
  585. const findController = new _pdf_find_controller.PDFFindController({
  586. linkService: pdfLinkService,
  587. eventBus
  588. });
  589. this.findController = findController;
  590. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  591. eventBus,
  592. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  593. scriptingFactory: externalServices,
  594. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  595. });
  596. this.pdfScriptingManager = pdfScriptingManager;
  597. const container = appConfig.mainContainer;
  598. const viewer = appConfig.viewerContainer;
  599. this.pdfViewer = new _pdf_viewer.PDFViewer({
  600. container,
  601. viewer,
  602. eventBus,
  603. renderingQueue: pdfRenderingQueue,
  604. linkService: pdfLinkService,
  605. downloadManager,
  606. findController,
  607. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  608. renderer: _app_options.AppOptions.get("renderer"),
  609. l10n: this.l10n,
  610. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  611. annotationMode: _app_options.AppOptions.get("annotationMode"),
  612. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  613. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  614. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  615. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  616. enablePermissions: _app_options.AppOptions.get("enablePermissions")
  617. });
  618. pdfRenderingQueue.setViewer(this.pdfViewer);
  619. pdfLinkService.setViewer(this.pdfViewer);
  620. pdfScriptingManager.setViewer(this.pdfViewer);
  621. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  622. container: appConfig.sidebar.thumbnailView,
  623. eventBus,
  624. renderingQueue: pdfRenderingQueue,
  625. linkService: pdfLinkService,
  626. l10n: this.l10n
  627. });
  628. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  629. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  630. this.pdfHistory = new _pdf_history.PDFHistory({
  631. linkService: pdfLinkService,
  632. eventBus
  633. });
  634. pdfLinkService.setHistory(this.pdfHistory);
  635. }
  636. if (!this.supportsIntegratedFind) {
  637. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  638. }
  639. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  640. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  641. container,
  642. eventBus,
  643. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  644. });
  645. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  646. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  647. if (this.supportsFullscreen) {
  648. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  649. container,
  650. pdfViewer: this.pdfViewer,
  651. eventBus
  652. });
  653. }
  654. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  655. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  656. container: appConfig.sidebar.outlineView,
  657. eventBus,
  658. linkService: pdfLinkService
  659. });
  660. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  661. container: appConfig.sidebar.attachmentsView,
  662. eventBus,
  663. downloadManager
  664. });
  665. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  666. container: appConfig.sidebar.layersView,
  667. eventBus,
  668. l10n: this.l10n
  669. });
  670. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  671. elements: appConfig.sidebar,
  672. pdfViewer: this.pdfViewer,
  673. pdfThumbnailViewer: this.pdfThumbnailViewer,
  674. eventBus,
  675. l10n: this.l10n
  676. });
  677. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  678. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  679. },
  680. run(config) {
  681. this.initialize(config).then(webViewerInitialized);
  682. },
  683. get initialized() {
  684. return this._initializedCapability.settled;
  685. },
  686. get initializedPromise() {
  687. return this._initializedCapability.promise;
  688. },
  689. zoomIn(steps) {
  690. if (this.pdfViewer.isInPresentationMode) {
  691. return;
  692. }
  693. this.pdfViewer.increaseScale(steps);
  694. },
  695. zoomOut(steps) {
  696. if (this.pdfViewer.isInPresentationMode) {
  697. return;
  698. }
  699. this.pdfViewer.decreaseScale(steps);
  700. },
  701. zoomReset() {
  702. if (this.pdfViewer.isInPresentationMode) {
  703. return;
  704. }
  705. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  706. },
  707. get pagesCount() {
  708. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  709. },
  710. get page() {
  711. return this.pdfViewer.currentPageNumber;
  712. },
  713. set page(val) {
  714. this.pdfViewer.currentPageNumber = val;
  715. },
  716. get supportsPrinting() {
  717. return PDFPrintServiceFactory.instance.supportsPrinting;
  718. },
  719. get supportsFullscreen() {
  720. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled);
  721. },
  722. get supportsIntegratedFind() {
  723. return this.externalServices.supportsIntegratedFind;
  724. },
  725. get supportsDocumentFonts() {
  726. return this.externalServices.supportsDocumentFonts;
  727. },
  728. get loadingBar() {
  729. const bar = new _ui_utils.ProgressBar("#loadingBar");
  730. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  731. },
  732. get supportedMouseWheelZoomModifierKeys() {
  733. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  734. },
  735. initPassiveLoading() {
  736. throw new Error("Not implemented: initPassiveLoading");
  737. },
  738. setTitleUsingUrl(url = "", downloadUrl = null) {
  739. this.url = url;
  740. this.baseUrl = url.split("#")[0];
  741. if (downloadUrl) {
  742. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  743. }
  744. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  745. if (!title) {
  746. try {
  747. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  748. } catch (ex) {
  749. title = url;
  750. }
  751. }
  752. this.setTitle(title);
  753. },
  754. setTitle(title) {
  755. if (this.isViewerEmbedded) {
  756. return;
  757. }
  758. document.title = title;
  759. },
  760. get _docFilename() {
  761. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  762. },
  763. _hideViewBookmark() {
  764. const {
  765. toolbar,
  766. secondaryToolbar
  767. } = this.appConfig;
  768. toolbar.viewBookmark.hidden = true;
  769. secondaryToolbar.viewBookmarkButton.hidden = true;
  770. },
  771. _cancelIdleCallbacks() {
  772. if (!this._idleCallbacks.size) {
  773. return;
  774. }
  775. for (const callback of this._idleCallbacks) {
  776. window.cancelIdleCallback(callback);
  777. }
  778. this._idleCallbacks.clear();
  779. },
  780. async close() {
  781. this._unblockDocumentLoadEvent();
  782. this._hideViewBookmark();
  783. const {
  784. container
  785. } = this.appConfig.errorWrapper;
  786. container.hidden = true;
  787. if (!this.pdfLoadingTask) {
  788. return;
  789. }
  790. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  791. try {
  792. await this.save({
  793. sourceEventType: "save"
  794. });
  795. } catch (reason) {}
  796. }
  797. const promises = [];
  798. promises.push(this.pdfLoadingTask.destroy());
  799. this.pdfLoadingTask = null;
  800. if (this.pdfDocument) {
  801. this.pdfDocument = null;
  802. this.pdfThumbnailViewer.setDocument(null);
  803. this.pdfViewer.setDocument(null);
  804. this.pdfLinkService.setDocument(null);
  805. this.pdfDocumentProperties.setDocument(null);
  806. }
  807. this.pdfLinkService.externalLinkEnabled = true;
  808. this._fellback = false;
  809. this.store = null;
  810. this.isInitialViewSet = false;
  811. this.downloadComplete = false;
  812. this.url = "";
  813. this.baseUrl = "";
  814. this._downloadUrl = "";
  815. this.documentInfo = null;
  816. this.metadata = null;
  817. this._contentDispositionFilename = null;
  818. this._contentLength = null;
  819. this._saveInProgress = false;
  820. this._docStats = null;
  821. this._cancelIdleCallbacks();
  822. promises.push(this.pdfScriptingManager.destroyPromise);
  823. this.pdfSidebar.reset();
  824. this.pdfOutlineViewer.reset();
  825. this.pdfAttachmentViewer.reset();
  826. this.pdfLayerViewer.reset();
  827. this.pdfHistory?.reset();
  828. this.findBar?.reset();
  829. this.toolbar.reset();
  830. this.secondaryToolbar.reset();
  831. if (typeof PDFBug !== "undefined") {
  832. PDFBug.cleanup();
  833. }
  834. await Promise.all(promises);
  835. },
  836. async open(file, args) {
  837. if (this.pdfLoadingTask) {
  838. await this.close();
  839. }
  840. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  841. for (const key in workerParameters) {
  842. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  843. }
  844. const parameters = Object.create(null);
  845. if (typeof file === "string") {
  846. this.setTitleUsingUrl(file, file);
  847. parameters.url = file;
  848. } else if (file && "byteLength" in file) {
  849. parameters.data = file;
  850. } else if (file.url && file.originalUrl) {
  851. this.setTitleUsingUrl(file.originalUrl, file.url);
  852. parameters.url = file.url;
  853. }
  854. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  855. for (const key in apiParameters) {
  856. let value = apiParameters[key];
  857. if (key === "docBaseUrl" && !value) {}
  858. parameters[key] = value;
  859. }
  860. if (args) {
  861. for (const key in args) {
  862. parameters[key] = args[key];
  863. }
  864. }
  865. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  866. this.pdfLoadingTask = loadingTask;
  867. loadingTask.onPassword = (updateCallback, reason) => {
  868. this.pdfLinkService.externalLinkEnabled = false;
  869. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  870. this.passwordPrompt.open();
  871. };
  872. loadingTask.onProgress = ({
  873. loaded,
  874. total
  875. }) => {
  876. this.progress(loaded / total);
  877. };
  878. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  879. return loadingTask.promise.then(pdfDocument => {
  880. this.load(pdfDocument);
  881. }, reason => {
  882. if (loadingTask !== this.pdfLoadingTask) {
  883. return undefined;
  884. }
  885. let key = "loading_error";
  886. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  887. key = "invalid_file_error";
  888. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  889. key = "missing_file_error";
  890. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  891. key = "unexpected_response_error";
  892. }
  893. return this.l10n.get(key).then(msg => {
  894. this._documentError(msg, {
  895. message: reason?.message
  896. });
  897. throw reason;
  898. });
  899. });
  900. },
  901. _ensureDownloadComplete() {
  902. if (this.pdfDocument && this.downloadComplete) {
  903. return;
  904. }
  905. throw new Error("PDF document not downloaded.");
  906. },
  907. async download({
  908. sourceEventType = "download"
  909. } = {}) {
  910. const url = this._downloadUrl,
  911. filename = this._docFilename;
  912. try {
  913. this._ensureDownloadComplete();
  914. const data = await this.pdfDocument.getData();
  915. const blob = new Blob([data], {
  916. type: "application/pdf"
  917. });
  918. await this.downloadManager.download(blob, url, filename, sourceEventType);
  919. } catch (reason) {
  920. await this.downloadManager.downloadUrl(url, filename);
  921. }
  922. },
  923. async save({
  924. sourceEventType = "download"
  925. } = {}) {
  926. if (this._saveInProgress) {
  927. return;
  928. }
  929. this._saveInProgress = true;
  930. await this.pdfScriptingManager.dispatchWillSave();
  931. const url = this._downloadUrl,
  932. filename = this._docFilename;
  933. try {
  934. this._ensureDownloadComplete();
  935. const data = await this.pdfDocument.saveDocument();
  936. const blob = new Blob([data], {
  937. type: "application/pdf"
  938. });
  939. await this.downloadManager.download(blob, url, filename, sourceEventType);
  940. } catch (reason) {
  941. console.error(`Error when saving the document: ${reason.message}`);
  942. await this.download({
  943. sourceEventType
  944. });
  945. } finally {
  946. await this.pdfScriptingManager.dispatchDidSave();
  947. this._saveInProgress = false;
  948. }
  949. },
  950. downloadOrSave(options) {
  951. if (this.pdfDocument?.annotationStorage.size > 0) {
  952. this.save(options);
  953. } else {
  954. this.download(options);
  955. }
  956. },
  957. fallback(featureId) {
  958. this.externalServices.reportTelemetry({
  959. type: "unsupportedFeature",
  960. featureId
  961. });
  962. if (this._fellback) {
  963. return;
  964. }
  965. this._fellback = true;
  966. this.externalServices.fallback({
  967. featureId,
  968. url: this.baseUrl
  969. }).then(download => {
  970. if (!download) {
  971. return;
  972. }
  973. this.download({
  974. sourceEventType: "download"
  975. });
  976. });
  977. },
  978. _documentError(message, moreInfo = null) {
  979. this._unblockDocumentLoadEvent();
  980. this._otherError(message, moreInfo);
  981. },
  982. _otherError(message, moreInfo = null) {
  983. const moreInfoText = [this.l10n.get("error_version_info", {
  984. version: _pdfjsLib.version || "?",
  985. build: _pdfjsLib.build || "?"
  986. })];
  987. if (moreInfo) {
  988. moreInfoText.push(this.l10n.get("error_message", {
  989. message: moreInfo.message
  990. }));
  991. if (moreInfo.stack) {
  992. moreInfoText.push(this.l10n.get("error_stack", {
  993. stack: moreInfo.stack
  994. }));
  995. } else {
  996. if (moreInfo.filename) {
  997. moreInfoText.push(this.l10n.get("error_file", {
  998. file: moreInfo.filename
  999. }));
  1000. }
  1001. if (moreInfo.lineNumber) {
  1002. moreInfoText.push(this.l10n.get("error_line", {
  1003. line: moreInfo.lineNumber
  1004. }));
  1005. }
  1006. }
  1007. }
  1008. const errorWrapperConfig = this.appConfig.errorWrapper;
  1009. const errorWrapper = errorWrapperConfig.container;
  1010. errorWrapper.hidden = false;
  1011. const errorMessage = errorWrapperConfig.errorMessage;
  1012. errorMessage.textContent = message;
  1013. const closeButton = errorWrapperConfig.closeButton;
  1014. closeButton.onclick = function () {
  1015. errorWrapper.hidden = true;
  1016. };
  1017. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1018. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1019. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1020. moreInfoButton.onclick = function () {
  1021. errorMoreInfo.hidden = false;
  1022. moreInfoButton.hidden = true;
  1023. lessInfoButton.hidden = false;
  1024. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1025. };
  1026. lessInfoButton.onclick = function () {
  1027. errorMoreInfo.hidden = true;
  1028. moreInfoButton.hidden = false;
  1029. lessInfoButton.hidden = true;
  1030. };
  1031. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1032. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1033. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1034. moreInfoButton.hidden = false;
  1035. lessInfoButton.hidden = true;
  1036. Promise.all(moreInfoText).then(parts => {
  1037. errorMoreInfo.value = parts.join("\n");
  1038. });
  1039. },
  1040. progress(level) {
  1041. if (this.downloadComplete) {
  1042. return;
  1043. }
  1044. const percent = Math.round(level * 100);
  1045. if (percent > this.loadingBar.percent || isNaN(percent)) {
  1046. this.loadingBar.percent = percent;
  1047. const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
  1048. if (disableAutoFetch && percent) {
  1049. if (this.disableAutoFetchLoadingBarTimeout) {
  1050. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1051. this.disableAutoFetchLoadingBarTimeout = null;
  1052. }
  1053. this.loadingBar.show();
  1054. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  1055. this.loadingBar.hide();
  1056. this.disableAutoFetchLoadingBarTimeout = null;
  1057. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1058. }
  1059. }
  1060. },
  1061. load(pdfDocument) {
  1062. this.pdfDocument = pdfDocument;
  1063. pdfDocument.getDownloadInfo().then(({
  1064. length
  1065. }) => {
  1066. this._contentLength = length;
  1067. this.downloadComplete = true;
  1068. this.loadingBar.hide();
  1069. firstPagePromise.then(() => {
  1070. this.eventBus.dispatch("documentloaded", {
  1071. source: this
  1072. });
  1073. });
  1074. });
  1075. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  1076. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1077. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  1078. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1079. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1080. let baseDocumentUrl;
  1081. baseDocumentUrl = null;
  1082. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1083. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1084. const pdfViewer = this.pdfViewer;
  1085. pdfViewer.setDocument(pdfDocument);
  1086. const {
  1087. firstPagePromise,
  1088. onePageRendered,
  1089. pagesPromise
  1090. } = pdfViewer;
  1091. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  1092. pdfThumbnailViewer.setDocument(pdfDocument);
  1093. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  1094. page: null,
  1095. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1096. scrollLeft: "0",
  1097. scrollTop: "0",
  1098. rotation: null,
  1099. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  1100. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1101. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  1102. }).catch(() => {
  1103. return Object.create(null);
  1104. });
  1105. firstPagePromise.then(pdfPage => {
  1106. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  1107. this._initializeAnnotationStorageCallbacks(pdfDocument);
  1108. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  1109. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  1110. this._initializePdfHistory({
  1111. fingerprint: pdfDocument.fingerprints[0],
  1112. viewOnLoad,
  1113. initialDest: openAction?.dest
  1114. });
  1115. const initialBookmark = this.initialBookmark;
  1116. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  1117. let hash = zoom ? `zoom=${zoom}` : null;
  1118. let rotation = null;
  1119. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  1120. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  1121. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  1122. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1123. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  1124. rotation = parseInt(stored.rotation, 10);
  1125. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1126. sidebarView = stored.sidebarView | 0;
  1127. }
  1128. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1129. scrollMode = stored.scrollMode | 0;
  1130. }
  1131. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1132. spreadMode = stored.spreadMode | 0;
  1133. }
  1134. }
  1135. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1136. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  1137. }
  1138. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1139. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  1140. spreadMode = modes.spreadMode;
  1141. }
  1142. this.setInitialView(hash, {
  1143. rotation,
  1144. sidebarView,
  1145. scrollMode,
  1146. spreadMode
  1147. });
  1148. this.eventBus.dispatch("documentinit", {
  1149. source: this
  1150. });
  1151. if (!this.isViewerEmbedded) {
  1152. pdfViewer.focus();
  1153. }
  1154. await Promise.race([pagesPromise, new Promise(resolve => {
  1155. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1156. })]);
  1157. if (!initialBookmark && !hash) {
  1158. return;
  1159. }
  1160. if (pdfViewer.hasEqualPageSizes) {
  1161. return;
  1162. }
  1163. this.initialBookmark = initialBookmark;
  1164. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1165. this.setInitialView(hash);
  1166. }).catch(() => {
  1167. this.setInitialView();
  1168. }).then(function () {
  1169. pdfViewer.update();
  1170. });
  1171. });
  1172. pagesPromise.then(() => {
  1173. this._unblockDocumentLoadEvent();
  1174. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1175. }, reason => {
  1176. this.l10n.get("loading_error").then(msg => {
  1177. this._documentError(msg, {
  1178. message: reason?.message
  1179. });
  1180. });
  1181. });
  1182. onePageRendered.then(data => {
  1183. this.externalServices.reportTelemetry({
  1184. type: "pageInfo",
  1185. timestamp: data.timestamp
  1186. });
  1187. pdfDocument.getOutline().then(outline => {
  1188. if (pdfDocument !== this.pdfDocument) {
  1189. return;
  1190. }
  1191. this.pdfOutlineViewer.render({
  1192. outline,
  1193. pdfDocument
  1194. });
  1195. });
  1196. pdfDocument.getAttachments().then(attachments => {
  1197. if (pdfDocument !== this.pdfDocument) {
  1198. return;
  1199. }
  1200. this.pdfAttachmentViewer.render({
  1201. attachments
  1202. });
  1203. });
  1204. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1205. if (pdfDocument !== this.pdfDocument) {
  1206. return;
  1207. }
  1208. this.pdfLayerViewer.render({
  1209. optionalContentConfig,
  1210. pdfDocument
  1211. });
  1212. });
  1213. if ("requestIdleCallback" in window) {
  1214. const callback = window.requestIdleCallback(() => {
  1215. this._collectTelemetry(pdfDocument);
  1216. this._idleCallbacks.delete(callback);
  1217. }, {
  1218. timeout: 1000
  1219. });
  1220. this._idleCallbacks.add(callback);
  1221. }
  1222. });
  1223. this._initializePageLabels(pdfDocument);
  1224. this._initializeMetadata(pdfDocument);
  1225. },
  1226. async _scriptingDocProperties(pdfDocument) {
  1227. if (!this.documentInfo) {
  1228. await new Promise(resolve => {
  1229. this.eventBus._on("metadataloaded", resolve, {
  1230. once: true
  1231. });
  1232. });
  1233. if (pdfDocument !== this.pdfDocument) {
  1234. return null;
  1235. }
  1236. }
  1237. if (!this._contentLength) {
  1238. await new Promise(resolve => {
  1239. this.eventBus._on("documentloaded", resolve, {
  1240. once: true
  1241. });
  1242. });
  1243. if (pdfDocument !== this.pdfDocument) {
  1244. return null;
  1245. }
  1246. }
  1247. return { ...this.documentInfo,
  1248. baseURL: this.baseUrl,
  1249. filesize: this._contentLength,
  1250. filename: this._docFilename,
  1251. metadata: this.metadata?.getRaw(),
  1252. authors: this.metadata?.get("dc:creator"),
  1253. numPages: this.pagesCount,
  1254. URL: this.url
  1255. };
  1256. },
  1257. async _collectTelemetry(pdfDocument) {
  1258. const markInfo = await this.pdfDocument.getMarkInfo();
  1259. if (pdfDocument !== this.pdfDocument) {
  1260. return;
  1261. }
  1262. const tagged = markInfo?.Marked || false;
  1263. this.externalServices.reportTelemetry({
  1264. type: "tagged",
  1265. tagged
  1266. });
  1267. },
  1268. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1269. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  1270. if (pdfDocument !== this.pdfDocument) {
  1271. return;
  1272. }
  1273. let triggerAutoPrint = false;
  1274. if (openAction?.action === "Print") {
  1275. triggerAutoPrint = true;
  1276. }
  1277. if (javaScript) {
  1278. javaScript.some(js => {
  1279. if (!js) {
  1280. return false;
  1281. }
  1282. console.warn("Warning: JavaScript support is not enabled");
  1283. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1284. return true;
  1285. });
  1286. if (!triggerAutoPrint) {
  1287. for (const js of javaScript) {
  1288. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1289. triggerAutoPrint = true;
  1290. break;
  1291. }
  1292. }
  1293. }
  1294. }
  1295. if (triggerAutoPrint) {
  1296. this.triggerPrinting();
  1297. }
  1298. },
  1299. async _initializeMetadata(pdfDocument) {
  1300. const {
  1301. info,
  1302. metadata,
  1303. contentDispositionFilename,
  1304. contentLength
  1305. } = await pdfDocument.getMetadata();
  1306. if (pdfDocument !== this.pdfDocument) {
  1307. return;
  1308. }
  1309. this.documentInfo = info;
  1310. this.metadata = metadata;
  1311. this._contentDispositionFilename ??= contentDispositionFilename;
  1312. this._contentLength ??= contentLength;
  1313. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"})`);
  1314. let pdfTitle = info?.Title;
  1315. const metadataTitle = metadata?.get("dc:title");
  1316. if (metadataTitle) {
  1317. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1318. pdfTitle = metadataTitle;
  1319. }
  1320. }
  1321. if (pdfTitle) {
  1322. this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  1323. } else if (contentDispositionFilename) {
  1324. this.setTitle(contentDispositionFilename);
  1325. }
  1326. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1327. if (pdfDocument.loadingParams.enableXfa) {
  1328. console.warn("Warning: XFA Foreground documents are not supported");
  1329. } else {
  1330. console.warn("Warning: XFA support is not enabled");
  1331. }
  1332. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1333. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  1334. console.warn("Warning: Interactive form support is not enabled");
  1335. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1336. }
  1337. if (info.IsSignaturesPresent) {
  1338. console.warn("Warning: Digital signatures validation is not supported");
  1339. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  1340. }
  1341. let versionId = "other";
  1342. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  1343. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  1344. }
  1345. let generatorId = "other";
  1346. if (info.Producer) {
  1347. const producer = info.Producer.toLowerCase();
  1348. KNOWN_GENERATORS.some(function (generator) {
  1349. if (!producer.includes(generator)) {
  1350. return false;
  1351. }
  1352. generatorId = generator.replace(/[ .-]/g, "_");
  1353. return true;
  1354. });
  1355. }
  1356. let formType = null;
  1357. if (info.IsXFAPresent) {
  1358. formType = "xfa";
  1359. } else if (info.IsAcroFormPresent) {
  1360. formType = "acroform";
  1361. }
  1362. this.externalServices.reportTelemetry({
  1363. type: "documentInfo",
  1364. version: versionId,
  1365. generator: generatorId,
  1366. formType
  1367. });
  1368. this.eventBus.dispatch("metadataloaded", {
  1369. source: this
  1370. });
  1371. },
  1372. async _initializePageLabels(pdfDocument) {
  1373. const labels = await pdfDocument.getPageLabels();
  1374. if (pdfDocument !== this.pdfDocument) {
  1375. return;
  1376. }
  1377. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1378. return;
  1379. }
  1380. const numLabels = labels.length;
  1381. let standardLabels = 0,
  1382. emptyLabels = 0;
  1383. for (let i = 0; i < numLabels; i++) {
  1384. const label = labels[i];
  1385. if (label === (i + 1).toString()) {
  1386. standardLabels++;
  1387. } else if (label === "") {
  1388. emptyLabels++;
  1389. } else {
  1390. break;
  1391. }
  1392. }
  1393. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  1394. return;
  1395. }
  1396. const {
  1397. pdfViewer,
  1398. pdfThumbnailViewer,
  1399. toolbar
  1400. } = this;
  1401. pdfViewer.setPageLabels(labels);
  1402. pdfThumbnailViewer.setPageLabels(labels);
  1403. toolbar.setPagesCount(numLabels, true);
  1404. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1405. },
  1406. _initializePdfHistory({
  1407. fingerprint,
  1408. viewOnLoad,
  1409. initialDest = null
  1410. }) {
  1411. if (!this.pdfHistory) {
  1412. return;
  1413. }
  1414. this.pdfHistory.initialize({
  1415. fingerprint,
  1416. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1417. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1418. });
  1419. if (this.pdfHistory.initialBookmark) {
  1420. this.initialBookmark = this.pdfHistory.initialBookmark;
  1421. this.initialRotation = this.pdfHistory.initialRotation;
  1422. }
  1423. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1424. this.initialBookmark = JSON.stringify(initialDest);
  1425. this.pdfHistory.push({
  1426. explicitDest: initialDest,
  1427. pageNumber: null
  1428. });
  1429. }
  1430. },
  1431. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1432. if (pdfDocument !== this.pdfDocument) {
  1433. return;
  1434. }
  1435. const {
  1436. annotationStorage
  1437. } = pdfDocument;
  1438. annotationStorage.onSetModified = () => {
  1439. window.addEventListener("beforeunload", beforeUnload);
  1440. this._annotationStorageModified = true;
  1441. };
  1442. annotationStorage.onResetModified = () => {
  1443. window.removeEventListener("beforeunload", beforeUnload);
  1444. delete this._annotationStorageModified;
  1445. };
  1446. },
  1447. setInitialView(storedHash, {
  1448. rotation,
  1449. sidebarView,
  1450. scrollMode,
  1451. spreadMode
  1452. } = {}) {
  1453. const setRotation = angle => {
  1454. if ((0, _ui_utils.isValidRotation)(angle)) {
  1455. this.pdfViewer.pagesRotation = angle;
  1456. }
  1457. };
  1458. const setViewerModes = (scroll, spread) => {
  1459. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1460. this.pdfViewer.scrollMode = scroll;
  1461. }
  1462. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1463. this.pdfViewer.spreadMode = spread;
  1464. }
  1465. };
  1466. this.isInitialViewSet = true;
  1467. this.pdfSidebar.setInitialView(sidebarView);
  1468. setViewerModes(scrollMode, spreadMode);
  1469. if (this.initialBookmark) {
  1470. setRotation(this.initialRotation);
  1471. delete this.initialRotation;
  1472. this.pdfLinkService.setHash(this.initialBookmark);
  1473. this.initialBookmark = null;
  1474. } else if (storedHash) {
  1475. setRotation(rotation);
  1476. this.pdfLinkService.setHash(storedHash);
  1477. }
  1478. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1479. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1480. if (!this.pdfViewer.currentScaleValue) {
  1481. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1482. }
  1483. },
  1484. _cleanup() {
  1485. if (!this.pdfDocument) {
  1486. return;
  1487. }
  1488. this.pdfViewer.cleanup();
  1489. this.pdfThumbnailViewer.cleanup();
  1490. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  1491. },
  1492. forceRendering() {
  1493. this.pdfRenderingQueue.printing = !!this.printService;
  1494. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1495. this.pdfRenderingQueue.renderHighestPriority();
  1496. },
  1497. beforePrint() {
  1498. this.pdfScriptingManager.dispatchWillPrint();
  1499. if (this.printService) {
  1500. return;
  1501. }
  1502. if (!this.supportsPrinting) {
  1503. this.l10n.get("printing_not_supported").then(msg => {
  1504. this._otherError(msg);
  1505. });
  1506. return;
  1507. }
  1508. if (!this.pdfViewer.pageViewsReady) {
  1509. this.l10n.get("printing_not_ready").then(msg => {
  1510. window.alert(msg);
  1511. });
  1512. return;
  1513. }
  1514. const pagesOverview = this.pdfViewer.getPagesOverview();
  1515. const printContainer = this.appConfig.printContainer;
  1516. const printResolution = _app_options.AppOptions.get("printResolution");
  1517. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1518. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
  1519. this.printService = printService;
  1520. this.forceRendering();
  1521. printService.layout();
  1522. this.externalServices.reportTelemetry({
  1523. type: "print"
  1524. });
  1525. },
  1526. afterPrint() {
  1527. this.pdfScriptingManager.dispatchDidPrint();
  1528. if (this.printService) {
  1529. this.printService.destroy();
  1530. this.printService = null;
  1531. this.pdfDocument?.annotationStorage.resetModified();
  1532. }
  1533. this.forceRendering();
  1534. },
  1535. rotatePages(delta) {
  1536. this.pdfViewer.pagesRotation += delta;
  1537. },
  1538. requestPresentationMode() {
  1539. this.pdfPresentationMode?.request();
  1540. },
  1541. triggerPrinting() {
  1542. if (!this.supportsPrinting) {
  1543. return;
  1544. }
  1545. window.print();
  1546. },
  1547. bindEvents() {
  1548. const {
  1549. eventBus,
  1550. _boundEvents
  1551. } = this;
  1552. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1553. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1554. eventBus._on("resize", webViewerResize);
  1555. eventBus._on("hashchange", webViewerHashchange);
  1556. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1557. eventBus._on("afterprint", _boundEvents.afterPrint);
  1558. eventBus._on("pagerendered", webViewerPageRendered);
  1559. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1560. eventBus._on("pagechanging", webViewerPageChanging);
  1561. eventBus._on("scalechanging", webViewerScaleChanging);
  1562. eventBus._on("rotationchanging", webViewerRotationChanging);
  1563. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1564. eventBus._on("pagemode", webViewerPageMode);
  1565. eventBus._on("namedaction", webViewerNamedAction);
  1566. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1567. eventBus._on("presentationmode", webViewerPresentationMode);
  1568. eventBus._on("print", webViewerPrint);
  1569. eventBus._on("download", webViewerDownload);
  1570. eventBus._on("save", webViewerSave);
  1571. eventBus._on("firstpage", webViewerFirstPage);
  1572. eventBus._on("lastpage", webViewerLastPage);
  1573. eventBus._on("nextpage", webViewerNextPage);
  1574. eventBus._on("previouspage", webViewerPreviousPage);
  1575. eventBus._on("zoomin", webViewerZoomIn);
  1576. eventBus._on("zoomout", webViewerZoomOut);
  1577. eventBus._on("zoomreset", webViewerZoomReset);
  1578. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1579. eventBus._on("scalechanged", webViewerScaleChanged);
  1580. eventBus._on("rotatecw", webViewerRotateCw);
  1581. eventBus._on("rotateccw", webViewerRotateCcw);
  1582. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1583. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1584. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1585. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1586. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1587. eventBus._on("documentproperties", webViewerDocumentProperties);
  1588. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1589. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1590. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1591. if (_app_options.AppOptions.get("pdfBug")) {
  1592. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1593. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1594. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1595. }
  1596. eventBus._on("fileinputchange", webViewerFileInputChange);
  1597. eventBus._on("openfile", webViewerOpenFile);
  1598. },
  1599. bindWindowEvents() {
  1600. const {
  1601. eventBus,
  1602. _boundEvents
  1603. } = this;
  1604. _boundEvents.windowResize = () => {
  1605. eventBus.dispatch("resize", {
  1606. source: window
  1607. });
  1608. };
  1609. _boundEvents.windowHashChange = () => {
  1610. eventBus.dispatch("hashchange", {
  1611. source: window,
  1612. hash: document.location.hash.substring(1)
  1613. });
  1614. };
  1615. _boundEvents.windowBeforePrint = () => {
  1616. eventBus.dispatch("beforeprint", {
  1617. source: window
  1618. });
  1619. };
  1620. _boundEvents.windowAfterPrint = () => {
  1621. eventBus.dispatch("afterprint", {
  1622. source: window
  1623. });
  1624. };
  1625. _boundEvents.windowUpdateFromSandbox = event => {
  1626. eventBus.dispatch("updatefromsandbox", {
  1627. source: window,
  1628. detail: event.detail
  1629. });
  1630. };
  1631. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1632. window.addEventListener("wheel", webViewerWheel, {
  1633. passive: false
  1634. });
  1635. window.addEventListener("touchstart", webViewerTouchStart, {
  1636. passive: false
  1637. });
  1638. window.addEventListener("click", webViewerClick);
  1639. window.addEventListener("keydown", webViewerKeyDown);
  1640. window.addEventListener("resize", _boundEvents.windowResize);
  1641. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1642. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1643. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1644. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1645. },
  1646. unbindEvents() {
  1647. const {
  1648. eventBus,
  1649. _boundEvents
  1650. } = this;
  1651. eventBus._off("resize", webViewerResize);
  1652. eventBus._off("hashchange", webViewerHashchange);
  1653. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1654. eventBus._off("afterprint", _boundEvents.afterPrint);
  1655. eventBus._off("pagerendered", webViewerPageRendered);
  1656. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1657. eventBus._off("pagechanging", webViewerPageChanging);
  1658. eventBus._off("scalechanging", webViewerScaleChanging);
  1659. eventBus._off("rotationchanging", webViewerRotationChanging);
  1660. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1661. eventBus._off("pagemode", webViewerPageMode);
  1662. eventBus._off("namedaction", webViewerNamedAction);
  1663. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1664. eventBus._off("presentationmode", webViewerPresentationMode);
  1665. eventBus._off("print", webViewerPrint);
  1666. eventBus._off("download", webViewerDownload);
  1667. eventBus._off("save", webViewerSave);
  1668. eventBus._off("firstpage", webViewerFirstPage);
  1669. eventBus._off("lastpage", webViewerLastPage);
  1670. eventBus._off("nextpage", webViewerNextPage);
  1671. eventBus._off("previouspage", webViewerPreviousPage);
  1672. eventBus._off("zoomin", webViewerZoomIn);
  1673. eventBus._off("zoomout", webViewerZoomOut);
  1674. eventBus._off("zoomreset", webViewerZoomReset);
  1675. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1676. eventBus._off("scalechanged", webViewerScaleChanged);
  1677. eventBus._off("rotatecw", webViewerRotateCw);
  1678. eventBus._off("rotateccw", webViewerRotateCcw);
  1679. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1680. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1681. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1682. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1683. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1684. eventBus._off("documentproperties", webViewerDocumentProperties);
  1685. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1686. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1687. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1688. if (_boundEvents.reportPageStatsPDFBug) {
  1689. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1690. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1691. _boundEvents.reportPageStatsPDFBug = null;
  1692. }
  1693. eventBus._off("fileinputchange", webViewerFileInputChange);
  1694. eventBus._off("openfile", webViewerOpenFile);
  1695. _boundEvents.beforePrint = null;
  1696. _boundEvents.afterPrint = null;
  1697. },
  1698. unbindWindowEvents() {
  1699. const {
  1700. _boundEvents
  1701. } = this;
  1702. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1703. window.removeEventListener("wheel", webViewerWheel, {
  1704. passive: false
  1705. });
  1706. window.removeEventListener("touchstart", webViewerTouchStart, {
  1707. passive: false
  1708. });
  1709. window.removeEventListener("click", webViewerClick);
  1710. window.removeEventListener("keydown", webViewerKeyDown);
  1711. window.removeEventListener("resize", _boundEvents.windowResize);
  1712. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1713. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1714. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1715. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1716. _boundEvents.windowResize = null;
  1717. _boundEvents.windowHashChange = null;
  1718. _boundEvents.windowBeforePrint = null;
  1719. _boundEvents.windowAfterPrint = null;
  1720. _boundEvents.windowUpdateFromSandbox = null;
  1721. },
  1722. accumulateWheelTicks(ticks) {
  1723. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  1724. this._wheelUnusedTicks = 0;
  1725. }
  1726. this._wheelUnusedTicks += ticks;
  1727. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  1728. this._wheelUnusedTicks -= wholeTicks;
  1729. return wholeTicks;
  1730. },
  1731. _unblockDocumentLoadEvent() {
  1732. if (document.blockUnblockOnload) {
  1733. document.blockUnblockOnload(false);
  1734. }
  1735. this._unblockDocumentLoadEvent = () => {};
  1736. },
  1737. _reportDocumentStatsTelemetry() {
  1738. const {
  1739. stats
  1740. } = this.pdfDocument;
  1741. if (stats !== this._docStats) {
  1742. this._docStats = stats;
  1743. this.externalServices.reportTelemetry({
  1744. type: "documentStats",
  1745. stats
  1746. });
  1747. }
  1748. },
  1749. get scriptingReady() {
  1750. return this.pdfScriptingManager.ready;
  1751. }
  1752. };
  1753. exports.PDFViewerApplication = PDFViewerApplication;
  1754. let validateFileURL;
  1755. {
  1756. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1757. validateFileURL = function (file) {
  1758. if (file === undefined) {
  1759. return;
  1760. }
  1761. try {
  1762. const viewerOrigin = new URL(window.location.href).origin || "null";
  1763. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1764. return;
  1765. }
  1766. const {
  1767. origin,
  1768. protocol
  1769. } = new URL(file, window.location.href);
  1770. // if (origin !== viewerOrigin && protocol !== "blob:") {
  1771. // throw new Error("file origin does not match viewer's");
  1772. // }
  1773. } catch (ex) {
  1774. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1775. PDFViewerApplication._documentError(msg, {
  1776. message: ex?.message
  1777. });
  1778. });
  1779. throw ex;
  1780. }
  1781. };
  1782. }
  1783. async function loadFakeWorker() {
  1784. if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
  1785. _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
  1786. }
  1787. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  1788. }
  1789. async function initPDFBug(enabledTabs) {
  1790. const {
  1791. debuggerScriptPath,
  1792. mainContainer
  1793. } = PDFViewerApplication.appConfig;
  1794. await (0, _pdfjsLib.loadScript)(debuggerScriptPath);
  1795. PDFBug.init({
  1796. OPS: _pdfjsLib.OPS
  1797. }, mainContainer, enabledTabs);
  1798. }
  1799. function reportPageStatsPDFBug({
  1800. pageNumber
  1801. }) {
  1802. if (typeof Stats === "undefined" || !Stats.enabled) {
  1803. return;
  1804. }
  1805. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1806. const pageStats = pageView?.pdfPage?.stats;
  1807. if (!pageStats) {
  1808. return;
  1809. }
  1810. Stats.add(pageNumber, pageStats);
  1811. }
  1812. function webViewerInitialized() {
  1813. const appConfig = PDFViewerApplication.appConfig;
  1814. let file;
  1815. const queryString = document.location.search.substring(1);
  1816. const params = (0, _ui_utils.parseQueryString)(queryString);
  1817. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  1818. validateFileURL(file);
  1819. const fileInput = document.createElement("input");
  1820. fileInput.id = appConfig.openFileInputName;
  1821. fileInput.className = "fileInput";
  1822. fileInput.setAttribute("type", "file");
  1823. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1824. document.body.appendChild(fileInput);
  1825. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1826. appConfig.toolbar.openFile.hidden = true;
  1827. appConfig.secondaryToolbar.openFileButton.hidden = true;
  1828. } else {
  1829. fileInput.value = null;
  1830. }
  1831. fileInput.addEventListener("change", function (evt) {
  1832. const files = evt.target.files;
  1833. if (!files || files.length === 0) {
  1834. return;
  1835. }
  1836. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1837. source: this,
  1838. fileInput: evt.target
  1839. });
  1840. });
  1841. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1842. evt.preventDefault();
  1843. evt.dataTransfer.dropEffect = "move";
  1844. });
  1845. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1846. evt.preventDefault();
  1847. const files = evt.dataTransfer.files;
  1848. if (!files || files.length === 0) {
  1849. return;
  1850. }
  1851. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1852. source: this,
  1853. fileInput: evt.dataTransfer
  1854. });
  1855. });
  1856. if (!PDFViewerApplication.supportsDocumentFonts) {
  1857. _app_options.AppOptions.set("disableFontFace", true);
  1858. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  1859. console.warn(msg);
  1860. });
  1861. }
  1862. if (!PDFViewerApplication.supportsPrinting) {
  1863. appConfig.toolbar.print.classList.add("hidden");
  1864. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  1865. }
  1866. if (!PDFViewerApplication.supportsFullscreen) {
  1867. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  1868. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  1869. }
  1870. if (PDFViewerApplication.supportsIntegratedFind) {
  1871. appConfig.toolbar.viewFind.classList.add("hidden");
  1872. }
  1873. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1874. if (evt.target === this) {
  1875. PDFViewerApplication.eventBus.dispatch("resize", {
  1876. source: this
  1877. });
  1878. }
  1879. }, true);
  1880. try {
  1881. webViewerOpenFileViaURL(file);
  1882. } catch (reason) {
  1883. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1884. PDFViewerApplication._documentError(msg, reason);
  1885. });
  1886. }
  1887. }
  1888. function webViewerOpenFileViaURL(file) {
  1889. if (file) {
  1890. PDFViewerApplication.open(file);
  1891. } else {
  1892. PDFViewerApplication._hideViewBookmark();
  1893. }
  1894. }
  1895. function webViewerPageRendered({
  1896. pageNumber,
  1897. error
  1898. }) {
  1899. if (pageNumber === PDFViewerApplication.page) {
  1900. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1901. }
  1902. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1903. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1904. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  1905. if (pageView && thumbnailView) {
  1906. thumbnailView.setImage(pageView);
  1907. }
  1908. }
  1909. if (error) {
  1910. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1911. PDFViewerApplication._otherError(msg, error);
  1912. });
  1913. }
  1914. PDFViewerApplication._reportDocumentStatsTelemetry();
  1915. }
  1916. function webViewerPageMode({
  1917. mode
  1918. }) {
  1919. let view;
  1920. switch (mode) {
  1921. case "thumbs":
  1922. view = _ui_utils.SidebarView.THUMBS;
  1923. break;
  1924. case "bookmarks":
  1925. case "outline":
  1926. view = _ui_utils.SidebarView.OUTLINE;
  1927. break;
  1928. case "attachments":
  1929. view = _ui_utils.SidebarView.ATTACHMENTS;
  1930. break;
  1931. case "layers":
  1932. view = _ui_utils.SidebarView.LAYERS;
  1933. break;
  1934. case "none":
  1935. view = _ui_utils.SidebarView.NONE;
  1936. break;
  1937. default:
  1938. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1939. return;
  1940. }
  1941. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1942. }
  1943. function webViewerNamedAction(evt) {
  1944. switch (evt.action) {
  1945. case "GoToPage":
  1946. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1947. break;
  1948. case "Find":
  1949. if (!PDFViewerApplication.supportsIntegratedFind) {
  1950. PDFViewerApplication.findBar.toggle();
  1951. }
  1952. break;
  1953. case "Print":
  1954. PDFViewerApplication.triggerPrinting();
  1955. break;
  1956. case "SaveAs":
  1957. webViewerSave();
  1958. break;
  1959. }
  1960. }
  1961. function webViewerPresentationModeChanged(evt) {
  1962. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1963. }
  1964. function webViewerSidebarViewChanged(evt) {
  1965. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1966. if (PDFViewerApplication.isInitialViewSet) {
  1967. PDFViewerApplication.store?.set("sidebarView", evt.view).catch(() => {});
  1968. }
  1969. }
  1970. function webViewerUpdateViewarea(evt) {
  1971. const location = evt.location;
  1972. if (PDFViewerApplication.isInitialViewSet) {
  1973. PDFViewerApplication.store?.setMultiple({
  1974. page: location.pageNumber,
  1975. zoom: location.scale,
  1976. scrollLeft: location.left,
  1977. scrollTop: location.top,
  1978. rotation: location.rotation
  1979. }).catch(() => {});
  1980. }
  1981. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1982. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1983. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1984. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1985. const loading = currentPage?.renderingState !== _ui_utils.RenderingStates.FINISHED;
  1986. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1987. }
  1988. function webViewerScrollModeChanged(evt) {
  1989. if (PDFViewerApplication.isInitialViewSet) {
  1990. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  1991. }
  1992. }
  1993. function webViewerSpreadModeChanged(evt) {
  1994. if (PDFViewerApplication.isInitialViewSet) {
  1995. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  1996. }
  1997. }
  1998. function webViewerResize() {
  1999. const {
  2000. pdfDocument,
  2001. pdfViewer
  2002. } = PDFViewerApplication;
  2003. if (!pdfDocument) {
  2004. return;
  2005. }
  2006. const currentScaleValue = pdfViewer.currentScaleValue;
  2007. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  2008. pdfViewer.currentScaleValue = currentScaleValue;
  2009. }
  2010. pdfViewer.update();
  2011. }
  2012. function webViewerHashchange(evt) {
  2013. const hash = evt.hash;
  2014. if (!hash) {
  2015. return;
  2016. }
  2017. if (!PDFViewerApplication.isInitialViewSet) {
  2018. PDFViewerApplication.initialBookmark = hash;
  2019. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  2020. PDFViewerApplication.pdfLinkService.setHash(hash);
  2021. }
  2022. }
  2023. let webViewerFileInputChange, webViewerOpenFile;
  2024. {
  2025. webViewerFileInputChange = function (evt) {
  2026. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2027. return;
  2028. }
  2029. const file = evt.fileInput.files[0];
  2030. if (!_app_options.compatibilityParams.disableCreateObjectURL) {
  2031. let url = URL.createObjectURL(file);
  2032. if (file.name) {
  2033. url = {
  2034. url,
  2035. originalUrl: file.name
  2036. };
  2037. }
  2038. PDFViewerApplication.open(url);
  2039. } else {
  2040. PDFViewerApplication.setTitleUsingUrl(file.name);
  2041. const fileReader = new FileReader();
  2042. fileReader.onload = function webViewerChangeFileReaderOnload(event) {
  2043. const buffer = event.target.result;
  2044. PDFViewerApplication.open(new Uint8Array(buffer));
  2045. };
  2046. fileReader.readAsArrayBuffer(file);
  2047. }
  2048. };
  2049. webViewerOpenFile = function (evt) {
  2050. const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  2051. document.getElementById(openFileInputName).click();
  2052. };
  2053. }
  2054. function webViewerPresentationMode() {
  2055. PDFViewerApplication.requestPresentationMode();
  2056. }
  2057. function webViewerPrint() {
  2058. PDFViewerApplication.triggerPrinting();
  2059. }
  2060. function webViewerDownload() {
  2061. PDFViewerApplication.downloadOrSave({
  2062. sourceEventType: "download"
  2063. });
  2064. }
  2065. function webViewerSave() {
  2066. PDFViewerApplication.downloadOrSave({
  2067. sourceEventType: "save"
  2068. });
  2069. }
  2070. function webViewerFirstPage() {
  2071. if (PDFViewerApplication.pdfDocument) {
  2072. PDFViewerApplication.page = 1;
  2073. }
  2074. }
  2075. function webViewerLastPage() {
  2076. if (PDFViewerApplication.pdfDocument) {
  2077. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2078. }
  2079. }
  2080. function webViewerNextPage() {
  2081. PDFViewerApplication.pdfViewer.nextPage();
  2082. }
  2083. function webViewerPreviousPage() {
  2084. PDFViewerApplication.pdfViewer.previousPage();
  2085. }
  2086. function webViewerZoomIn() {
  2087. PDFViewerApplication.zoomIn();
  2088. }
  2089. function webViewerZoomOut() {
  2090. PDFViewerApplication.zoomOut();
  2091. }
  2092. function webViewerZoomReset() {
  2093. PDFViewerApplication.zoomReset();
  2094. }
  2095. function webViewerPageNumberChanged(evt) {
  2096. const pdfViewer = PDFViewerApplication.pdfViewer;
  2097. if (evt.value !== "") {
  2098. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  2099. }
  2100. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  2101. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2102. }
  2103. }
  2104. function webViewerScaleChanged(evt) {
  2105. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2106. }
  2107. function webViewerRotateCw() {
  2108. PDFViewerApplication.rotatePages(90);
  2109. }
  2110. function webViewerRotateCcw() {
  2111. PDFViewerApplication.rotatePages(-90);
  2112. }
  2113. function webViewerOptionalContentConfig(evt) {
  2114. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  2115. }
  2116. function webViewerSwitchScrollMode(evt) {
  2117. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  2118. }
  2119. function webViewerSwitchSpreadMode(evt) {
  2120. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  2121. }
  2122. function webViewerDocumentProperties() {
  2123. PDFViewerApplication.pdfDocumentProperties.open();
  2124. }
  2125. function webViewerFindFromUrlHash(evt) {
  2126. PDFViewerApplication.eventBus.dispatch("find", {
  2127. source: evt.source,
  2128. type: "",
  2129. query: evt.query,
  2130. phraseSearch: evt.phraseSearch,
  2131. caseSensitive: false,
  2132. entireWord: false,
  2133. highlightAll: true,
  2134. findPrevious: false
  2135. });
  2136. }
  2137. function webViewerUpdateFindMatchesCount({
  2138. matchesCount
  2139. }) {
  2140. if (PDFViewerApplication.supportsIntegratedFind) {
  2141. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  2142. } else {
  2143. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  2144. }
  2145. }
  2146. function webViewerUpdateFindControlState({
  2147. state,
  2148. previous,
  2149. matchesCount,
  2150. rawQuery
  2151. }) {
  2152. if (PDFViewerApplication.supportsIntegratedFind) {
  2153. PDFViewerApplication.externalServices.updateFindControlState({
  2154. result: state,
  2155. findPrevious: previous,
  2156. matchesCount,
  2157. rawQuery
  2158. });
  2159. } else {
  2160. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  2161. }
  2162. }
  2163. function webViewerScaleChanging(evt) {
  2164. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  2165. PDFViewerApplication.pdfViewer.update();
  2166. }
  2167. function webViewerRotationChanging(evt) {
  2168. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  2169. PDFViewerApplication.forceRendering();
  2170. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2171. }
  2172. function webViewerPageChanging({
  2173. pageNumber,
  2174. pageLabel
  2175. }) {
  2176. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  2177. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  2178. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2179. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  2180. }
  2181. }
  2182. function webViewerVisibilityChange(evt) {
  2183. if (document.visibilityState === "visible") {
  2184. setZoomDisabledTimeout();
  2185. }
  2186. }
  2187. let zoomDisabledTimeout = null;
  2188. function setZoomDisabledTimeout() {
  2189. if (zoomDisabledTimeout) {
  2190. clearTimeout(zoomDisabledTimeout);
  2191. }
  2192. zoomDisabledTimeout = setTimeout(function () {
  2193. zoomDisabledTimeout = null;
  2194. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  2195. }
  2196. function webViewerWheel(evt) {
  2197. const {
  2198. pdfViewer,
  2199. supportedMouseWheelZoomModifierKeys
  2200. } = PDFViewerApplication;
  2201. if (pdfViewer.isInPresentationMode) {
  2202. return;
  2203. }
  2204. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  2205. evt.preventDefault();
  2206. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2207. return;
  2208. }
  2209. const previousScale = pdfViewer.currentScale;
  2210. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2211. let ticks = 0;
  2212. if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE || evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2213. if (Math.abs(delta) >= 1) {
  2214. ticks = Math.sign(delta);
  2215. } else {
  2216. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  2217. }
  2218. } else {
  2219. const PIXELS_PER_LINE_SCALE = 30;
  2220. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  2221. }
  2222. if (ticks < 0) {
  2223. PDFViewerApplication.zoomOut(-ticks);
  2224. } else if (ticks > 0) {
  2225. PDFViewerApplication.zoomIn(ticks);
  2226. }
  2227. const currentScale = pdfViewer.currentScale;
  2228. if (previousScale !== currentScale) {
  2229. const scaleCorrectionFactor = currentScale / previousScale - 1;
  2230. const rect = pdfViewer.container.getBoundingClientRect();
  2231. const dx = evt.clientX - rect.left;
  2232. const dy = evt.clientY - rect.top;
  2233. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  2234. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  2235. }
  2236. } else {
  2237. setZoomDisabledTimeout();
  2238. }
  2239. }
  2240. function webViewerTouchStart(evt) {
  2241. if (evt.touches.length > 1) {
  2242. evt.preventDefault();
  2243. }
  2244. }
  2245. function webViewerClick(evt) {
  2246. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  2247. return;
  2248. }
  2249. const appConfig = PDFViewerApplication.appConfig;
  2250. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  2251. PDFViewerApplication.secondaryToolbar.close();
  2252. }
  2253. }
  2254. function webViewerKeyDown(evt) {
  2255. if (PDFViewerApplication.overlayManager.active) {
  2256. return;
  2257. }
  2258. const {
  2259. eventBus,
  2260. pdfViewer
  2261. } = PDFViewerApplication;
  2262. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  2263. let handled = false,
  2264. ensureViewerFocused = false;
  2265. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2266. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2267. switch (evt.keyCode) {
  2268. case 70:
  2269. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2270. PDFViewerApplication.findBar.open();
  2271. handled = true;
  2272. }
  2273. break;
  2274. case 71:
  2275. if (!PDFViewerApplication.supportsIntegratedFind) {
  2276. const {
  2277. state
  2278. } = PDFViewerApplication.findController;
  2279. if (state) {
  2280. const eventState = Object.assign(Object.create(null), state, {
  2281. source: window,
  2282. type: "again",
  2283. findPrevious: cmd === 5 || cmd === 12
  2284. });
  2285. eventBus.dispatch("find", eventState);
  2286. }
  2287. handled = true;
  2288. }
  2289. break;
  2290. case 61:
  2291. case 107:
  2292. case 187:
  2293. case 171:
  2294. if (!isViewerInPresentationMode) {
  2295. PDFViewerApplication.zoomIn();
  2296. }
  2297. handled = true;
  2298. break;
  2299. case 173:
  2300. case 109:
  2301. case 189:
  2302. if (!isViewerInPresentationMode) {
  2303. PDFViewerApplication.zoomOut();
  2304. }
  2305. handled = true;
  2306. break;
  2307. case 48:
  2308. case 96:
  2309. if (!isViewerInPresentationMode) {
  2310. setTimeout(function () {
  2311. PDFViewerApplication.zoomReset();
  2312. });
  2313. handled = false;
  2314. }
  2315. break;
  2316. case 38:
  2317. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2318. PDFViewerApplication.page = 1;
  2319. handled = true;
  2320. ensureViewerFocused = true;
  2321. }
  2322. break;
  2323. case 40:
  2324. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2325. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2326. handled = true;
  2327. ensureViewerFocused = true;
  2328. }
  2329. break;
  2330. }
  2331. }
  2332. if (cmd === 1 || cmd === 8) {
  2333. switch (evt.keyCode) {
  2334. case 83:
  2335. eventBus.dispatch("download", {
  2336. source: window
  2337. });
  2338. handled = true;
  2339. break;
  2340. case 79:
  2341. {
  2342. eventBus.dispatch("openfile", {
  2343. source: window
  2344. });
  2345. handled = true;
  2346. }
  2347. break;
  2348. }
  2349. }
  2350. if (cmd === 3 || cmd === 10) {
  2351. switch (evt.keyCode) {
  2352. case 80:
  2353. PDFViewerApplication.requestPresentationMode();
  2354. handled = true;
  2355. break;
  2356. case 71:
  2357. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2358. handled = true;
  2359. break;
  2360. }
  2361. }
  2362. if (handled) {
  2363. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2364. pdfViewer.focus();
  2365. }
  2366. evt.preventDefault();
  2367. return;
  2368. }
  2369. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2370. const curElementTagName = curElement?.tagName.toUpperCase();
  2371. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2372. if (evt.keyCode !== 27) {
  2373. return;
  2374. }
  2375. }
  2376. if (cmd === 0) {
  2377. let turnPage = 0,
  2378. turnOnlyIfPageFit = false;
  2379. switch (evt.keyCode) {
  2380. case 38:
  2381. case 33:
  2382. if (pdfViewer.isVerticalScrollbarEnabled) {
  2383. turnOnlyIfPageFit = true;
  2384. }
  2385. turnPage = -1;
  2386. break;
  2387. case 8:
  2388. if (!isViewerInPresentationMode) {
  2389. turnOnlyIfPageFit = true;
  2390. }
  2391. turnPage = -1;
  2392. break;
  2393. case 37:
  2394. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2395. turnOnlyIfPageFit = true;
  2396. }
  2397. case 75:
  2398. case 80:
  2399. turnPage = -1;
  2400. break;
  2401. case 27:
  2402. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2403. PDFViewerApplication.secondaryToolbar.close();
  2404. handled = true;
  2405. }
  2406. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2407. PDFViewerApplication.findBar.close();
  2408. handled = true;
  2409. }
  2410. break;
  2411. case 40:
  2412. case 34:
  2413. if (pdfViewer.isVerticalScrollbarEnabled) {
  2414. turnOnlyIfPageFit = true;
  2415. }
  2416. turnPage = 1;
  2417. break;
  2418. case 13:
  2419. case 32:
  2420. if (!isViewerInPresentationMode) {
  2421. turnOnlyIfPageFit = true;
  2422. }
  2423. turnPage = 1;
  2424. break;
  2425. case 39:
  2426. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2427. turnOnlyIfPageFit = true;
  2428. }
  2429. case 74:
  2430. case 78:
  2431. turnPage = 1;
  2432. break;
  2433. case 36:
  2434. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2435. PDFViewerApplication.page = 1;
  2436. handled = true;
  2437. ensureViewerFocused = true;
  2438. }
  2439. break;
  2440. case 35:
  2441. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2442. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2443. handled = true;
  2444. ensureViewerFocused = true;
  2445. }
  2446. break;
  2447. case 83:
  2448. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2449. break;
  2450. case 72:
  2451. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2452. break;
  2453. case 82:
  2454. PDFViewerApplication.rotatePages(90);
  2455. break;
  2456. case 115:
  2457. PDFViewerApplication.pdfSidebar.toggle();
  2458. break;
  2459. }
  2460. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2461. if (turnPage > 0) {
  2462. pdfViewer.nextPage();
  2463. } else {
  2464. pdfViewer.previousPage();
  2465. }
  2466. handled = true;
  2467. }
  2468. }
  2469. if (cmd === 4) {
  2470. switch (evt.keyCode) {
  2471. case 13:
  2472. case 32:
  2473. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2474. break;
  2475. }
  2476. pdfViewer.previousPage();
  2477. handled = true;
  2478. break;
  2479. case 82:
  2480. PDFViewerApplication.rotatePages(-90);
  2481. break;
  2482. }
  2483. }
  2484. if (!handled && !isViewerInPresentationMode) {
  2485. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2486. ensureViewerFocused = true;
  2487. }
  2488. }
  2489. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2490. pdfViewer.focus();
  2491. }
  2492. if (handled) {
  2493. evt.preventDefault();
  2494. }
  2495. }
  2496. function beforeUnload(evt) {
  2497. evt.preventDefault();
  2498. evt.returnValue = "";
  2499. return false;
  2500. }
  2501. const PDFPrintServiceFactory = {
  2502. instance: {
  2503. supportsPrinting: false,
  2504. createPrintService() {
  2505. throw new Error("Not implemented: createPrintService");
  2506. }
  2507. }
  2508. };
  2509. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2510. /***/ }),
  2511. /* 3 */
  2512. /***/ ((__unused_webpack_module, exports) => {
  2513. Object.defineProperty(exports, "__esModule", ({
  2514. value: true
  2515. }));
  2516. 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.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = void 0;
  2517. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  2518. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2519. exports.approximateFraction = approximateFraction;
  2520. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2521. exports.binarySearchFirstItem = binarySearchFirstItem;
  2522. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2523. exports.getOutputScale = getOutputScale;
  2524. exports.getPageSizeInches = getPageSizeInches;
  2525. exports.getVisibleElements = getVisibleElements;
  2526. exports.isPortraitOrientation = isPortraitOrientation;
  2527. exports.isValidRotation = isValidRotation;
  2528. exports.isValidScrollMode = isValidScrollMode;
  2529. exports.isValidSpreadMode = isValidSpreadMode;
  2530. exports.noContextMenuHandler = noContextMenuHandler;
  2531. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2532. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2533. exports.parseQueryString = parseQueryString;
  2534. exports.roundToDivide = roundToDivide;
  2535. exports.scrollIntoView = scrollIntoView;
  2536. exports.watchScroll = watchScroll;
  2537. const DEFAULT_SCALE_VALUE = "auto";
  2538. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2539. const DEFAULT_SCALE = 1.0;
  2540. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2541. const DEFAULT_SCALE_DELTA = 1.1;
  2542. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  2543. const MIN_SCALE = 0.1;
  2544. exports.MIN_SCALE = MIN_SCALE;
  2545. const MAX_SCALE = 10.0;
  2546. exports.MAX_SCALE = MAX_SCALE;
  2547. const UNKNOWN_SCALE = 0;
  2548. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2549. const MAX_AUTO_SCALE = 1.25;
  2550. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2551. const SCROLLBAR_PADDING = 40;
  2552. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2553. const VERTICAL_PADDING = 5;
  2554. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2555. const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
  2556. const RenderingStates = {
  2557. INITIAL: 0,
  2558. RUNNING: 1,
  2559. PAUSED: 2,
  2560. FINISHED: 3
  2561. };
  2562. exports.RenderingStates = RenderingStates;
  2563. const PresentationModeState = {
  2564. UNKNOWN: 0,
  2565. NORMAL: 1,
  2566. CHANGING: 2,
  2567. FULLSCREEN: 3
  2568. };
  2569. exports.PresentationModeState = PresentationModeState;
  2570. const SidebarView = {
  2571. UNKNOWN: -1,
  2572. NONE: 0,
  2573. THUMBS: 1,
  2574. OUTLINE: 2,
  2575. ATTACHMENTS: 3,
  2576. LAYERS: 4
  2577. };
  2578. exports.SidebarView = SidebarView;
  2579. const RendererType = {
  2580. CANVAS: "canvas",
  2581. SVG: "svg"
  2582. };
  2583. exports.RendererType = RendererType;
  2584. const TextLayerMode = {
  2585. DISABLE: 0,
  2586. ENABLE: 1,
  2587. ENABLE_ENHANCE: 2
  2588. };
  2589. exports.TextLayerMode = TextLayerMode;
  2590. const ScrollMode = {
  2591. UNKNOWN: -1,
  2592. VERTICAL: 0,
  2593. HORIZONTAL: 1,
  2594. WRAPPED: 2,
  2595. PAGE: 3
  2596. };
  2597. exports.ScrollMode = ScrollMode;
  2598. const SpreadMode = {
  2599. UNKNOWN: -1,
  2600. NONE: 0,
  2601. ODD: 1,
  2602. EVEN: 2
  2603. };
  2604. exports.SpreadMode = SpreadMode;
  2605. const AutoPrintRegExp = /\bprint\s*\(/;
  2606. exports.AutoPrintRegExp = AutoPrintRegExp;
  2607. function getOutputScale(ctx) {
  2608. const devicePixelRatio = window.devicePixelRatio || 1;
  2609. const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  2610. const pixelRatio = devicePixelRatio / backingStoreRatio;
  2611. return {
  2612. sx: pixelRatio,
  2613. sy: pixelRatio,
  2614. scaled: pixelRatio !== 1
  2615. };
  2616. }
  2617. function scrollIntoView(element, spot, scrollMatches = false) {
  2618. let parent = element.offsetParent;
  2619. if (!parent) {
  2620. console.error("offsetParent is not set -- cannot scroll");
  2621. return;
  2622. }
  2623. let offsetY = element.offsetTop + element.clientTop;
  2624. let offsetX = element.offsetLeft + element.clientLeft;
  2625. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  2626. offsetY += parent.offsetTop;
  2627. offsetX += parent.offsetLeft;
  2628. parent = parent.offsetParent;
  2629. if (!parent) {
  2630. return;
  2631. }
  2632. }
  2633. if (spot) {
  2634. if (spot.top !== undefined) {
  2635. offsetY += spot.top;
  2636. }
  2637. if (spot.left !== undefined) {
  2638. offsetX += spot.left;
  2639. parent.scrollLeft = offsetX;
  2640. }
  2641. }
  2642. parent.scrollTop = offsetY;
  2643. }
  2644. function watchScroll(viewAreaElement, callback) {
  2645. const debounceScroll = function (evt) {
  2646. if (rAF) {
  2647. return;
  2648. }
  2649. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2650. rAF = null;
  2651. const currentX = viewAreaElement.scrollLeft;
  2652. const lastX = state.lastX;
  2653. if (currentX !== lastX) {
  2654. state.right = currentX > lastX;
  2655. }
  2656. state.lastX = currentX;
  2657. const currentY = viewAreaElement.scrollTop;
  2658. const lastY = state.lastY;
  2659. if (currentY !== lastY) {
  2660. state.down = currentY > lastY;
  2661. }
  2662. state.lastY = currentY;
  2663. callback(state);
  2664. });
  2665. };
  2666. const state = {
  2667. right: true,
  2668. down: true,
  2669. lastX: viewAreaElement.scrollLeft,
  2670. lastY: viewAreaElement.scrollTop,
  2671. _eventHandler: debounceScroll
  2672. };
  2673. let rAF = null;
  2674. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2675. return state;
  2676. }
  2677. function parseQueryString(query) {
  2678. const params = new Map();
  2679. for (const [key, value] of new URLSearchParams(query)) {
  2680. params.set(key.toLowerCase(), value);
  2681. }
  2682. return params;
  2683. }
  2684. function binarySearchFirstItem(items, condition) {
  2685. let minIndex = 0;
  2686. let maxIndex = items.length - 1;
  2687. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2688. return items.length;
  2689. }
  2690. if (condition(items[minIndex])) {
  2691. return minIndex;
  2692. }
  2693. while (minIndex < maxIndex) {
  2694. const currentIndex = minIndex + maxIndex >> 1;
  2695. const currentItem = items[currentIndex];
  2696. if (condition(currentItem)) {
  2697. maxIndex = currentIndex;
  2698. } else {
  2699. minIndex = currentIndex + 1;
  2700. }
  2701. }
  2702. return minIndex;
  2703. }
  2704. function approximateFraction(x) {
  2705. if (Math.floor(x) === x) {
  2706. return [x, 1];
  2707. }
  2708. const xinv = 1 / x;
  2709. const limit = 8;
  2710. if (xinv > limit) {
  2711. return [1, limit];
  2712. } else if (Math.floor(xinv) === xinv) {
  2713. return [1, xinv];
  2714. }
  2715. const x_ = x > 1 ? xinv : x;
  2716. let a = 0,
  2717. b = 1,
  2718. c = 1,
  2719. d = 1;
  2720. while (true) {
  2721. const p = a + c,
  2722. q = b + d;
  2723. if (q > limit) {
  2724. break;
  2725. }
  2726. if (x_ <= p / q) {
  2727. c = p;
  2728. d = q;
  2729. } else {
  2730. a = p;
  2731. b = q;
  2732. }
  2733. }
  2734. let result;
  2735. if (x_ - a / b < c / d - x_) {
  2736. result = x_ === x ? [a, b] : [b, a];
  2737. } else {
  2738. result = x_ === x ? [c, d] : [d, c];
  2739. }
  2740. return result;
  2741. }
  2742. function roundToDivide(x, div) {
  2743. const r = x % div;
  2744. return r === 0 ? x : Math.round(x - r + div);
  2745. }
  2746. function getPageSizeInches({
  2747. view,
  2748. userUnit,
  2749. rotate
  2750. }) {
  2751. const [x1, y1, x2, y2] = view;
  2752. const changeOrientation = rotate % 180 !== 0;
  2753. const width = (x2 - x1) / 72 * userUnit;
  2754. const height = (y2 - y1) / 72 * userUnit;
  2755. return {
  2756. width: changeOrientation ? height : width,
  2757. height: changeOrientation ? width : height
  2758. };
  2759. }
  2760. function backtrackBeforeAllVisibleElements(index, views, top) {
  2761. if (index < 2) {
  2762. return index;
  2763. }
  2764. let elt = views[index].div;
  2765. let pageTop = elt.offsetTop + elt.clientTop;
  2766. if (pageTop >= top) {
  2767. elt = views[index - 1].div;
  2768. pageTop = elt.offsetTop + elt.clientTop;
  2769. }
  2770. for (let i = index - 2; i >= 0; --i) {
  2771. elt = views[i].div;
  2772. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2773. break;
  2774. }
  2775. index = i;
  2776. }
  2777. return index;
  2778. }
  2779. function getVisibleElements({
  2780. scrollEl,
  2781. views,
  2782. sortByVisibility = false,
  2783. horizontal = false,
  2784. rtl = false
  2785. }) {
  2786. const top = scrollEl.scrollTop,
  2787. bottom = top + scrollEl.clientHeight;
  2788. const left = scrollEl.scrollLeft,
  2789. right = left + scrollEl.clientWidth;
  2790. function isElementBottomAfterViewTop(view) {
  2791. const element = view.div;
  2792. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2793. return elementBottom > top;
  2794. }
  2795. function isElementNextAfterViewHorizontally(view) {
  2796. const element = view.div;
  2797. const elementLeft = element.offsetLeft + element.clientLeft;
  2798. const elementRight = elementLeft + element.clientWidth;
  2799. return rtl ? elementLeft < right : elementRight > left;
  2800. }
  2801. const visible = [],
  2802. ids = new Set(),
  2803. numViews = views.length;
  2804. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2805. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2806. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2807. }
  2808. let lastEdge = horizontal ? right : -1;
  2809. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2810. const view = views[i],
  2811. element = view.div;
  2812. const currentWidth = element.offsetLeft + element.clientLeft;
  2813. const currentHeight = element.offsetTop + element.clientTop;
  2814. const viewWidth = element.clientWidth,
  2815. viewHeight = element.clientHeight;
  2816. const viewRight = currentWidth + viewWidth;
  2817. const viewBottom = currentHeight + viewHeight;
  2818. if (lastEdge === -1) {
  2819. if (viewBottom >= bottom) {
  2820. lastEdge = viewBottom;
  2821. }
  2822. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2823. break;
  2824. }
  2825. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2826. continue;
  2827. }
  2828. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2829. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2830. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2831. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2832. const percent = fractionHeight * fractionWidth * 100 | 0;
  2833. visible.push({
  2834. id: view.id,
  2835. x: currentWidth,
  2836. y: currentHeight,
  2837. view,
  2838. percent,
  2839. widthPercent: fractionWidth * 100 | 0
  2840. });
  2841. ids.add(view.id);
  2842. }
  2843. const first = visible[0],
  2844. last = visible[visible.length - 1];
  2845. if (sortByVisibility) {
  2846. visible.sort(function (a, b) {
  2847. const pc = a.percent - b.percent;
  2848. if (Math.abs(pc) > 0.001) {
  2849. return -pc;
  2850. }
  2851. return a.id - b.id;
  2852. });
  2853. }
  2854. return {
  2855. first,
  2856. last,
  2857. views: visible,
  2858. ids
  2859. };
  2860. }
  2861. function noContextMenuHandler(evt) {
  2862. evt.preventDefault();
  2863. }
  2864. function normalizeWheelEventDirection(evt) {
  2865. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2866. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2867. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2868. delta = -delta;
  2869. }
  2870. return delta;
  2871. }
  2872. function normalizeWheelEventDelta(evt) {
  2873. let delta = normalizeWheelEventDirection(evt);
  2874. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  2875. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  2876. const MOUSE_PIXELS_PER_LINE = 30;
  2877. const MOUSE_LINES_PER_PAGE = 30;
  2878. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  2879. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2880. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  2881. delta /= MOUSE_LINES_PER_PAGE;
  2882. }
  2883. return delta;
  2884. }
  2885. function isValidRotation(angle) {
  2886. return Number.isInteger(angle) && angle % 90 === 0;
  2887. }
  2888. function isValidScrollMode(mode) {
  2889. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2890. }
  2891. function isValidSpreadMode(mode) {
  2892. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2893. }
  2894. function isPortraitOrientation(size) {
  2895. return size.width <= size.height;
  2896. }
  2897. const animationStarted = new Promise(function (resolve) {
  2898. window.requestAnimationFrame(resolve);
  2899. });
  2900. exports.animationStarted = animationStarted;
  2901. function clamp(v, min, max) {
  2902. return Math.min(Math.max(v, min), max);
  2903. }
  2904. class ProgressBar {
  2905. constructor(id, {
  2906. height,
  2907. width,
  2908. units
  2909. } = {}) {
  2910. this.visible = true;
  2911. this.div = document.querySelector(id + " .progress");
  2912. this.bar = this.div.parentNode;
  2913. this.height = height || 100;
  2914. this.width = width || 100;
  2915. this.units = units || "%";
  2916. this.div.style.height = this.height + this.units;
  2917. this.percent = 0;
  2918. }
  2919. _updateBar() {
  2920. if (this._indeterminate) {
  2921. this.div.classList.add("indeterminate");
  2922. this.div.style.width = this.width + this.units;
  2923. return;
  2924. }
  2925. this.div.classList.remove("indeterminate");
  2926. const progressSize = this.width * this._percent / 100;
  2927. this.div.style.width = progressSize + this.units;
  2928. }
  2929. get percent() {
  2930. return this._percent;
  2931. }
  2932. set percent(val) {
  2933. this._indeterminate = isNaN(val);
  2934. this._percent = clamp(val, 0, 100);
  2935. this._updateBar();
  2936. }
  2937. setWidth(viewer) {
  2938. if (!viewer) {
  2939. return;
  2940. }
  2941. const container = viewer.parentNode;
  2942. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  2943. if (scrollbarWidth > 0) {
  2944. const doc = document.documentElement;
  2945. doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
  2946. }
  2947. }
  2948. hide() {
  2949. if (!this.visible) {
  2950. return;
  2951. }
  2952. this.visible = false;
  2953. this.bar.classList.add("hidden");
  2954. }
  2955. show() {
  2956. if (this.visible) {
  2957. return;
  2958. }
  2959. this.visible = true;
  2960. this.bar.classList.remove("hidden");
  2961. }
  2962. }
  2963. exports.ProgressBar = ProgressBar;
  2964. function getActiveOrFocusedElement() {
  2965. let curRoot = document;
  2966. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2967. while (curActiveOrFocused?.shadowRoot) {
  2968. curRoot = curActiveOrFocused.shadowRoot;
  2969. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2970. }
  2971. return curActiveOrFocused;
  2972. }
  2973. function apiPageLayoutToViewerModes(layout) {
  2974. let scrollMode = ScrollMode.VERTICAL,
  2975. spreadMode = SpreadMode.NONE;
  2976. switch (layout) {
  2977. case "SinglePage":
  2978. scrollMode = ScrollMode.PAGE;
  2979. break;
  2980. case "OneColumn":
  2981. break;
  2982. case "TwoPageLeft":
  2983. scrollMode = ScrollMode.PAGE;
  2984. case "TwoColumnLeft":
  2985. spreadMode = SpreadMode.ODD;
  2986. break;
  2987. case "TwoPageRight":
  2988. scrollMode = ScrollMode.PAGE;
  2989. case "TwoColumnRight":
  2990. spreadMode = SpreadMode.EVEN;
  2991. break;
  2992. }
  2993. return {
  2994. scrollMode,
  2995. spreadMode
  2996. };
  2997. }
  2998. function apiPageModeToSidebarView(mode) {
  2999. switch (mode) {
  3000. case "UseNone":
  3001. return SidebarView.NONE;
  3002. case "UseThumbs":
  3003. return SidebarView.THUMBS;
  3004. case "UseOutlines":
  3005. return SidebarView.OUTLINE;
  3006. case "UseAttachments":
  3007. return SidebarView.ATTACHMENTS;
  3008. case "UseOC":
  3009. return SidebarView.LAYERS;
  3010. }
  3011. return SidebarView.NONE;
  3012. }
  3013. /***/ }),
  3014. /* 4 */
  3015. /***/ ((__unused_webpack_module, exports) => {
  3016. Object.defineProperty(exports, "__esModule", ({
  3017. value: true
  3018. }));
  3019. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3020. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3021. const WaitOnType = {
  3022. EVENT: "event",
  3023. TIMEOUT: "timeout"
  3024. };
  3025. exports.WaitOnType = WaitOnType;
  3026. function waitOnEventOrTimeout({
  3027. target,
  3028. name,
  3029. delay = 0
  3030. }) {
  3031. return new Promise(function (resolve, reject) {
  3032. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3033. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3034. }
  3035. function handler(type) {
  3036. if (target instanceof EventBus) {
  3037. target._off(name, eventHandler);
  3038. } else {
  3039. target.removeEventListener(name, eventHandler);
  3040. }
  3041. if (timeout) {
  3042. clearTimeout(timeout);
  3043. }
  3044. resolve(type);
  3045. }
  3046. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3047. if (target instanceof EventBus) {
  3048. target._on(name, eventHandler);
  3049. } else {
  3050. target.addEventListener(name, eventHandler);
  3051. }
  3052. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3053. const timeout = setTimeout(timeoutHandler, delay);
  3054. });
  3055. }
  3056. class EventBus {
  3057. constructor() {
  3058. this._listeners = Object.create(null);
  3059. }
  3060. on(eventName, listener, options = null) {
  3061. this._on(eventName, listener, {
  3062. external: true,
  3063. once: options?.once
  3064. });
  3065. }
  3066. off(eventName, listener, options = null) {
  3067. this._off(eventName, listener, {
  3068. external: true,
  3069. once: options?.once
  3070. });
  3071. }
  3072. dispatch(eventName, data) {
  3073. const eventListeners = this._listeners[eventName];
  3074. if (!eventListeners || eventListeners.length === 0) {
  3075. return;
  3076. }
  3077. let externalListeners;
  3078. for (const {
  3079. listener,
  3080. external,
  3081. once
  3082. } of eventListeners.slice(0)) {
  3083. if (once) {
  3084. this._off(eventName, listener);
  3085. }
  3086. if (external) {
  3087. (externalListeners ||= []).push(listener);
  3088. continue;
  3089. }
  3090. listener(data);
  3091. }
  3092. if (externalListeners) {
  3093. for (const listener of externalListeners) {
  3094. listener(data);
  3095. }
  3096. externalListeners = null;
  3097. }
  3098. }
  3099. _on(eventName, listener, options = null) {
  3100. const eventListeners = this._listeners[eventName] ||= [];
  3101. eventListeners.push({
  3102. listener,
  3103. external: options?.external === true,
  3104. once: options?.once === true
  3105. });
  3106. }
  3107. _off(eventName, listener, options = null) {
  3108. const eventListeners = this._listeners[eventName];
  3109. if (!eventListeners) {
  3110. return;
  3111. }
  3112. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3113. if (eventListeners[i].listener === listener) {
  3114. eventListeners.splice(i, 1);
  3115. return;
  3116. }
  3117. }
  3118. }
  3119. }
  3120. exports.EventBus = EventBus;
  3121. class AutomationEventBus extends EventBus {
  3122. dispatch(eventName, data) {
  3123. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3124. }
  3125. }
  3126. exports.AutomationEventBus = AutomationEventBus;
  3127. /***/ }),
  3128. /* 5 */
  3129. /***/ ((module) => {
  3130. let pdfjsLib;
  3131. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3132. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3133. } else {
  3134. pdfjsLib = require("../build/pdf.js");
  3135. }
  3136. module.exports = pdfjsLib;
  3137. /***/ }),
  3138. /* 6 */
  3139. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3140. Object.defineProperty(exports, "__esModule", ({
  3141. value: true
  3142. }));
  3143. exports.PDFCursorTools = exports.CursorTool = void 0;
  3144. var _grab_to_pan = __webpack_require__(7);
  3145. var _ui_utils = __webpack_require__(3);
  3146. const CursorTool = {
  3147. SELECT: 0,
  3148. HAND: 1,
  3149. ZOOM: 2
  3150. };
  3151. exports.CursorTool = CursorTool;
  3152. class PDFCursorTools {
  3153. constructor({
  3154. container,
  3155. eventBus,
  3156. cursorToolOnLoad = CursorTool.SELECT
  3157. }) {
  3158. this.container = container;
  3159. this.eventBus = eventBus;
  3160. this.active = CursorTool.SELECT;
  3161. this.activeBeforePresentationMode = null;
  3162. this.handTool = new _grab_to_pan.GrabToPan({
  3163. element: this.container
  3164. });
  3165. this._addEventListeners();
  3166. Promise.resolve().then(() => {
  3167. this.switchTool(cursorToolOnLoad);
  3168. });
  3169. }
  3170. get activeTool() {
  3171. return this.active;
  3172. }
  3173. switchTool(tool) {
  3174. if (this.activeBeforePresentationMode !== null) {
  3175. return;
  3176. }
  3177. if (tool === this.active) {
  3178. return;
  3179. }
  3180. const disableActiveTool = () => {
  3181. switch (this.active) {
  3182. case CursorTool.SELECT:
  3183. break;
  3184. case CursorTool.HAND:
  3185. this.handTool.deactivate();
  3186. break;
  3187. case CursorTool.ZOOM:
  3188. }
  3189. };
  3190. switch (tool) {
  3191. case CursorTool.SELECT:
  3192. disableActiveTool();
  3193. break;
  3194. case CursorTool.HAND:
  3195. disableActiveTool();
  3196. this.handTool.activate();
  3197. break;
  3198. case CursorTool.ZOOM:
  3199. default:
  3200. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3201. return;
  3202. }
  3203. this.active = tool;
  3204. this._dispatchEvent();
  3205. }
  3206. _dispatchEvent() {
  3207. this.eventBus.dispatch("cursortoolchanged", {
  3208. source: this,
  3209. tool: this.active
  3210. });
  3211. }
  3212. _addEventListeners() {
  3213. this.eventBus._on("switchcursortool", evt => {
  3214. this.switchTool(evt.tool);
  3215. });
  3216. this.eventBus._on("presentationmodechanged", evt => {
  3217. switch (evt.state) {
  3218. case _ui_utils.PresentationModeState.FULLSCREEN:
  3219. {
  3220. const previouslyActive = this.active;
  3221. this.switchTool(CursorTool.SELECT);
  3222. this.activeBeforePresentationMode = previouslyActive;
  3223. break;
  3224. }
  3225. case _ui_utils.PresentationModeState.NORMAL:
  3226. {
  3227. const previouslyActive = this.activeBeforePresentationMode;
  3228. this.activeBeforePresentationMode = null;
  3229. this.switchTool(previouslyActive);
  3230. break;
  3231. }
  3232. }
  3233. });
  3234. }
  3235. }
  3236. exports.PDFCursorTools = PDFCursorTools;
  3237. /***/ }),
  3238. /* 7 */
  3239. /***/ ((__unused_webpack_module, exports) => {
  3240. Object.defineProperty(exports, "__esModule", ({
  3241. value: true
  3242. }));
  3243. exports.GrabToPan = void 0;
  3244. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3245. class GrabToPan {
  3246. constructor(options) {
  3247. this.element = options.element;
  3248. this.document = options.element.ownerDocument;
  3249. if (typeof options.ignoreTarget === "function") {
  3250. this.ignoreTarget = options.ignoreTarget;
  3251. }
  3252. this.onActiveChanged = options.onActiveChanged;
  3253. this.activate = this.activate.bind(this);
  3254. this.deactivate = this.deactivate.bind(this);
  3255. this.toggle = this.toggle.bind(this);
  3256. this._onMouseDown = this.#onMouseDown.bind(this);
  3257. this._onMouseMove = this.#onMouseMove.bind(this);
  3258. this._endPan = this.#endPan.bind(this);
  3259. const overlay = this.overlay = document.createElement("div");
  3260. overlay.className = "grab-to-pan-grabbing";
  3261. }
  3262. activate() {
  3263. if (!this.active) {
  3264. this.active = true;
  3265. this.element.addEventListener("mousedown", this._onMouseDown, true);
  3266. this.element.classList.add(CSS_CLASS_GRAB);
  3267. this.onActiveChanged?.(true);
  3268. }
  3269. }
  3270. deactivate() {
  3271. if (this.active) {
  3272. this.active = false;
  3273. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  3274. this._endPan();
  3275. this.element.classList.remove(CSS_CLASS_GRAB);
  3276. this.onActiveChanged?.(false);
  3277. }
  3278. }
  3279. toggle() {
  3280. if (this.active) {
  3281. this.deactivate();
  3282. } else {
  3283. this.activate();
  3284. }
  3285. }
  3286. ignoreTarget(node) {
  3287. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3288. }
  3289. #onMouseDown(event) {
  3290. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3291. return;
  3292. }
  3293. if (event.originalTarget) {
  3294. try {
  3295. event.originalTarget.tagName;
  3296. } catch (e) {
  3297. return;
  3298. }
  3299. }
  3300. this.scrollLeftStart = this.element.scrollLeft;
  3301. this.scrollTopStart = this.element.scrollTop;
  3302. this.clientXStart = event.clientX;
  3303. this.clientYStart = event.clientY;
  3304. this.document.addEventListener("mousemove", this._onMouseMove, true);
  3305. this.document.addEventListener("mouseup", this._endPan, true);
  3306. this.element.addEventListener("scroll", this._endPan, true);
  3307. event.preventDefault();
  3308. event.stopPropagation();
  3309. const focusedElement = document.activeElement;
  3310. if (focusedElement && !focusedElement.contains(event.target)) {
  3311. focusedElement.blur();
  3312. }
  3313. }
  3314. #onMouseMove(event) {
  3315. this.element.removeEventListener("scroll", this._endPan, true);
  3316. if (!(event.buttons & 1)) {
  3317. this._endPan();
  3318. return;
  3319. }
  3320. const xDiff = event.clientX - this.clientXStart;
  3321. const yDiff = event.clientY - this.clientYStart;
  3322. const scrollTop = this.scrollTopStart - yDiff;
  3323. const scrollLeft = this.scrollLeftStart - xDiff;
  3324. if (this.element.scrollTo) {
  3325. this.element.scrollTo({
  3326. top: scrollTop,
  3327. left: scrollLeft,
  3328. behavior: "instant"
  3329. });
  3330. } else {
  3331. this.element.scrollTop = scrollTop;
  3332. this.element.scrollLeft = scrollLeft;
  3333. }
  3334. if (!this.overlay.parentNode) {
  3335. document.body.appendChild(this.overlay);
  3336. }
  3337. }
  3338. #endPan() {
  3339. this.element.removeEventListener("scroll", this._endPan, true);
  3340. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  3341. this.document.removeEventListener("mouseup", this._endPan, true);
  3342. this.overlay.remove();
  3343. }
  3344. }
  3345. exports.GrabToPan = GrabToPan;
  3346. /***/ }),
  3347. /* 8 */
  3348. /***/ ((__unused_webpack_module, exports) => {
  3349. Object.defineProperty(exports, "__esModule", ({
  3350. value: true
  3351. }));
  3352. exports.OverlayManager = void 0;
  3353. class OverlayManager {
  3354. constructor() {
  3355. this._overlays = {};
  3356. this._active = null;
  3357. this._keyDownBound = this._keyDown.bind(this);
  3358. }
  3359. get active() {
  3360. return this._active;
  3361. }
  3362. async register(name, element, callerCloseMethod = null, canForceClose = false) {
  3363. let container;
  3364. if (!name || !element || !(container = element.parentNode)) {
  3365. throw new Error("Not enough parameters.");
  3366. } else if (this._overlays[name]) {
  3367. throw new Error("The overlay is already registered.");
  3368. }
  3369. this._overlays[name] = {
  3370. element,
  3371. container,
  3372. callerCloseMethod,
  3373. canForceClose
  3374. };
  3375. }
  3376. async unregister(name) {
  3377. if (!this._overlays[name]) {
  3378. throw new Error("The overlay does not exist.");
  3379. } else if (this._active === name) {
  3380. throw new Error("The overlay cannot be removed while it is active.");
  3381. }
  3382. delete this._overlays[name];
  3383. }
  3384. async open(name) {
  3385. if (!this._overlays[name]) {
  3386. throw new Error("The overlay does not exist.");
  3387. } else if (this._active) {
  3388. if (this._overlays[name].canForceClose) {
  3389. this._closeThroughCaller();
  3390. } else if (this._active === name) {
  3391. throw new Error("The overlay is already active.");
  3392. } else {
  3393. throw new Error("Another overlay is currently active.");
  3394. }
  3395. }
  3396. this._active = name;
  3397. this._overlays[this._active].element.classList.remove("hidden");
  3398. this._overlays[this._active].container.classList.remove("hidden");
  3399. window.addEventListener("keydown", this._keyDownBound);
  3400. }
  3401. async close(name) {
  3402. if (!this._overlays[name]) {
  3403. throw new Error("The overlay does not exist.");
  3404. } else if (!this._active) {
  3405. throw new Error("The overlay is currently not active.");
  3406. } else if (this._active !== name) {
  3407. throw new Error("Another overlay is currently active.");
  3408. }
  3409. this._overlays[this._active].container.classList.add("hidden");
  3410. this._overlays[this._active].element.classList.add("hidden");
  3411. this._active = null;
  3412. window.removeEventListener("keydown", this._keyDownBound);
  3413. }
  3414. _keyDown(evt) {
  3415. if (this._active && evt.keyCode === 27) {
  3416. this._closeThroughCaller();
  3417. evt.preventDefault();
  3418. }
  3419. }
  3420. _closeThroughCaller() {
  3421. if (this._overlays[this._active].callerCloseMethod) {
  3422. this._overlays[this._active].callerCloseMethod();
  3423. }
  3424. if (this._active) {
  3425. this.close(this._active);
  3426. }
  3427. }
  3428. }
  3429. exports.OverlayManager = OverlayManager;
  3430. /***/ }),
  3431. /* 9 */
  3432. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3433. Object.defineProperty(exports, "__esModule", ({
  3434. value: true
  3435. }));
  3436. exports.PasswordPrompt = void 0;
  3437. var _pdfjsLib = __webpack_require__(5);
  3438. class PasswordPrompt {
  3439. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3440. this.overlayName = options.overlayName;
  3441. this.container = options.container;
  3442. this.label = options.label;
  3443. this.input = options.input;
  3444. this.submitButton = options.submitButton;
  3445. this.cancelButton = options.cancelButton;
  3446. this.overlayManager = overlayManager;
  3447. this.l10n = l10n;
  3448. this._isViewerEmbedded = isViewerEmbedded;
  3449. this.updateCallback = null;
  3450. this.reason = null;
  3451. this.submitButton.addEventListener("click", this.verify.bind(this));
  3452. this.cancelButton.addEventListener("click", this.close.bind(this));
  3453. this.input.addEventListener("keydown", e => {
  3454. if (e.keyCode === 13) {
  3455. this.verify();
  3456. }
  3457. });
  3458. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  3459. }
  3460. async open() {
  3461. await this.overlayManager.open(this.overlayName);
  3462. const passwordIncorrect = this.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3463. if (!this._isViewerEmbedded || passwordIncorrect) {
  3464. this.input.focus();
  3465. }
  3466. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3467. }
  3468. close() {
  3469. this.overlayManager.close(this.overlayName).then(() => {
  3470. this.input.value = "";
  3471. });
  3472. }
  3473. verify() {
  3474. const password = this.input.value;
  3475. if (password?.length > 0) {
  3476. this.close();
  3477. this.updateCallback(password);
  3478. }
  3479. }
  3480. setUpdateCallback(updateCallback, reason) {
  3481. this.updateCallback = updateCallback;
  3482. this.reason = reason;
  3483. }
  3484. }
  3485. exports.PasswordPrompt = PasswordPrompt;
  3486. /***/ }),
  3487. /* 10 */
  3488. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3489. Object.defineProperty(exports, "__esModule", ({
  3490. value: true
  3491. }));
  3492. exports.PDFAttachmentViewer = void 0;
  3493. var _pdfjsLib = __webpack_require__(5);
  3494. var _base_tree_viewer = __webpack_require__(11);
  3495. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  3496. constructor(options) {
  3497. super(options);
  3498. this.downloadManager = options.downloadManager;
  3499. this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
  3500. }
  3501. reset(keepRenderedCapability = false) {
  3502. super.reset();
  3503. this._attachments = null;
  3504. if (!keepRenderedCapability) {
  3505. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  3506. }
  3507. if (this._pendingDispatchEvent) {
  3508. clearTimeout(this._pendingDispatchEvent);
  3509. }
  3510. this._pendingDispatchEvent = null;
  3511. }
  3512. _dispatchEvent(attachmentsCount) {
  3513. this._renderedCapability.resolve();
  3514. if (this._pendingDispatchEvent) {
  3515. clearTimeout(this._pendingDispatchEvent);
  3516. this._pendingDispatchEvent = null;
  3517. }
  3518. if (attachmentsCount === 0) {
  3519. this._pendingDispatchEvent = setTimeout(() => {
  3520. this.eventBus.dispatch("attachmentsloaded", {
  3521. source: this,
  3522. attachmentsCount: 0
  3523. });
  3524. this._pendingDispatchEvent = null;
  3525. });
  3526. return;
  3527. }
  3528. this.eventBus.dispatch("attachmentsloaded", {
  3529. source: this,
  3530. attachmentsCount
  3531. });
  3532. }
  3533. _bindLink(element, {
  3534. content,
  3535. filename
  3536. }) {
  3537. element.onclick = () => {
  3538. this.downloadManager.openOrDownloadData(element, content, filename);
  3539. return false;
  3540. };
  3541. }
  3542. render({
  3543. attachments,
  3544. keepRenderedCapability = false
  3545. }) {
  3546. if (this._attachments) {
  3547. this.reset(keepRenderedCapability);
  3548. }
  3549. this._attachments = attachments || null;
  3550. if (!attachments) {
  3551. this._dispatchEvent(0);
  3552. return;
  3553. }
  3554. const names = Object.keys(attachments).sort(function (a, b) {
  3555. return a.toLowerCase().localeCompare(b.toLowerCase());
  3556. });
  3557. const fragment = document.createDocumentFragment();
  3558. let attachmentsCount = 0;
  3559. for (const name of names) {
  3560. const item = attachments[name];
  3561. const content = item.content,
  3562. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  3563. const div = document.createElement("div");
  3564. div.className = "treeItem";
  3565. const element = document.createElement("a");
  3566. this._bindLink(element, {
  3567. content,
  3568. filename
  3569. });
  3570. element.textContent = this._normalizeTextContent(filename);
  3571. div.appendChild(element);
  3572. fragment.appendChild(div);
  3573. attachmentsCount++;
  3574. }
  3575. this._finishRendering(fragment, attachmentsCount);
  3576. }
  3577. _appendAttachment({
  3578. id,
  3579. filename,
  3580. content
  3581. }) {
  3582. const renderedPromise = this._renderedCapability.promise;
  3583. renderedPromise.then(() => {
  3584. if (renderedPromise !== this._renderedCapability.promise) {
  3585. return;
  3586. }
  3587. let attachments = this._attachments;
  3588. if (!attachments) {
  3589. attachments = Object.create(null);
  3590. } else {
  3591. for (const name in attachments) {
  3592. if (id === name) {
  3593. return;
  3594. }
  3595. }
  3596. }
  3597. attachments[id] = {
  3598. filename,
  3599. content
  3600. };
  3601. this.render({
  3602. attachments,
  3603. keepRenderedCapability: true
  3604. });
  3605. });
  3606. }
  3607. }
  3608. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  3609. /***/ }),
  3610. /* 11 */
  3611. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3612. Object.defineProperty(exports, "__esModule", ({
  3613. value: true
  3614. }));
  3615. exports.BaseTreeViewer = void 0;
  3616. var _pdfjsLib = __webpack_require__(5);
  3617. const TREEITEM_OFFSET_TOP = -100;
  3618. const TREEITEM_SELECTED_CLASS = "selected";
  3619. class BaseTreeViewer {
  3620. constructor(options) {
  3621. if (this.constructor === BaseTreeViewer) {
  3622. throw new Error("Cannot initialize BaseTreeViewer.");
  3623. }
  3624. this.container = options.container;
  3625. this.eventBus = options.eventBus;
  3626. this.reset();
  3627. }
  3628. reset() {
  3629. this._pdfDocument = null;
  3630. this._lastToggleIsShow = true;
  3631. this._currentTreeItem = null;
  3632. this.container.textContent = "";
  3633. this.container.classList.remove("treeWithDeepNesting");
  3634. }
  3635. _dispatchEvent(count) {
  3636. throw new Error("Not implemented: _dispatchEvent");
  3637. }
  3638. _bindLink(element, params) {
  3639. throw new Error("Not implemented: _bindLink");
  3640. }
  3641. _normalizeTextContent(str) {
  3642. return (0, _pdfjsLib.removeNullCharacters)(str, true) || "\u2013";
  3643. }
  3644. _addToggleButton(div, hidden = false) {
  3645. const toggler = document.createElement("div");
  3646. toggler.className = "treeItemToggler";
  3647. if (hidden) {
  3648. toggler.classList.add("treeItemsHidden");
  3649. }
  3650. toggler.onclick = evt => {
  3651. evt.stopPropagation();
  3652. toggler.classList.toggle("treeItemsHidden");
  3653. if (evt.shiftKey) {
  3654. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  3655. this._toggleTreeItem(div, shouldShowAll);
  3656. }
  3657. };
  3658. div.insertBefore(toggler, div.firstChild);
  3659. }
  3660. _toggleTreeItem(root, show = false) {
  3661. this._lastToggleIsShow = show;
  3662. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  3663. toggler.classList.toggle("treeItemsHidden", !show);
  3664. }
  3665. }
  3666. _toggleAllTreeItems() {
  3667. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  3668. }
  3669. _finishRendering(fragment, count, hasAnyNesting = false) {
  3670. if (hasAnyNesting) {
  3671. this.container.classList.add("treeWithDeepNesting");
  3672. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  3673. }
  3674. this.container.appendChild(fragment);
  3675. this._dispatchEvent(count);
  3676. }
  3677. render(params) {
  3678. throw new Error("Not implemented: render");
  3679. }
  3680. _updateCurrentTreeItem(treeItem = null) {
  3681. if (this._currentTreeItem) {
  3682. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  3683. this._currentTreeItem = null;
  3684. }
  3685. if (treeItem) {
  3686. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  3687. this._currentTreeItem = treeItem;
  3688. }
  3689. }
  3690. _scrollToCurrentTreeItem(treeItem) {
  3691. if (!treeItem) {
  3692. return;
  3693. }
  3694. let currentNode = treeItem.parentNode;
  3695. while (currentNode && currentNode !== this.container) {
  3696. if (currentNode.classList.contains("treeItem")) {
  3697. const toggler = currentNode.firstElementChild;
  3698. toggler?.classList.remove("treeItemsHidden");
  3699. }
  3700. currentNode = currentNode.parentNode;
  3701. }
  3702. this._updateCurrentTreeItem(treeItem);
  3703. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  3704. }
  3705. }
  3706. exports.BaseTreeViewer = BaseTreeViewer;
  3707. /***/ }),
  3708. /* 12 */
  3709. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3710. Object.defineProperty(exports, "__esModule", ({
  3711. value: true
  3712. }));
  3713. exports.PDFDocumentProperties = void 0;
  3714. var _pdfjsLib = __webpack_require__(5);
  3715. var _ui_utils = __webpack_require__(3);
  3716. const DEFAULT_FIELD_CONTENT = "-";
  3717. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  3718. const US_PAGE_NAMES = {
  3719. "8.5x11": "Letter",
  3720. "8.5x14": "Legal"
  3721. };
  3722. const METRIC_PAGE_NAMES = {
  3723. "297x420": "A3",
  3724. "210x297": "A4"
  3725. };
  3726. function getPageName(size, isPortrait, pageNames) {
  3727. const width = isPortrait ? size.width : size.height;
  3728. const height = isPortrait ? size.height : size.width;
  3729. return pageNames[`${width}x${height}`];
  3730. }
  3731. class PDFDocumentProperties {
  3732. constructor({
  3733. overlayName,
  3734. fields,
  3735. container,
  3736. closeButton
  3737. }, overlayManager, eventBus, l10n) {
  3738. this.overlayName = overlayName;
  3739. this.fields = fields;
  3740. this.container = container;
  3741. this.overlayManager = overlayManager;
  3742. this.l10n = l10n;
  3743. this._reset();
  3744. closeButton.addEventListener("click", this.close.bind(this));
  3745. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  3746. eventBus._on("pagechanging", evt => {
  3747. this._currentPageNumber = evt.pageNumber;
  3748. });
  3749. eventBus._on("rotationchanging", evt => {
  3750. this._pagesRotation = evt.pagesRotation;
  3751. });
  3752. this._isNonMetricLocale = true;
  3753. l10n.getLanguage().then(locale => {
  3754. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  3755. });
  3756. }
  3757. async open() {
  3758. const freezeFieldData = data => {
  3759. Object.defineProperty(this, "fieldData", {
  3760. value: Object.freeze(data),
  3761. writable: false,
  3762. enumerable: true,
  3763. configurable: true
  3764. });
  3765. };
  3766. await Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]);
  3767. const currentPageNumber = this._currentPageNumber;
  3768. const pagesRotation = this._pagesRotation;
  3769. if (this.fieldData && currentPageNumber === this.fieldData._currentPageNumber && pagesRotation === this.fieldData._pagesRotation) {
  3770. this._updateUI();
  3771. return;
  3772. }
  3773. const {
  3774. info,
  3775. contentDispositionFilename,
  3776. contentLength
  3777. } = await this.pdfDocument.getMetadata();
  3778. 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 => {
  3779. return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  3780. }), this._parseLinearization(info.IsLinearized)]);
  3781. freezeFieldData({
  3782. fileName,
  3783. fileSize,
  3784. title: info.Title,
  3785. author: info.Author,
  3786. subject: info.Subject,
  3787. keywords: info.Keywords,
  3788. creationDate,
  3789. modificationDate,
  3790. creator: info.Creator,
  3791. producer: info.Producer,
  3792. version: info.PDFFormatVersion,
  3793. pageCount: this.pdfDocument.numPages,
  3794. pageSize,
  3795. linearized: isLinearized,
  3796. _currentPageNumber: currentPageNumber,
  3797. _pagesRotation: pagesRotation
  3798. });
  3799. this._updateUI();
  3800. const {
  3801. length
  3802. } = await this.pdfDocument.getDownloadInfo();
  3803. if (contentLength === length) {
  3804. return;
  3805. }
  3806. const data = Object.assign(Object.create(null), this.fieldData);
  3807. data.fileSize = await this._parseFileSize(length);
  3808. freezeFieldData(data);
  3809. this._updateUI();
  3810. }
  3811. close() {
  3812. this.overlayManager.close(this.overlayName);
  3813. }
  3814. setDocument(pdfDocument, url = null) {
  3815. if (this.pdfDocument) {
  3816. this._reset();
  3817. this._updateUI(true);
  3818. }
  3819. if (!pdfDocument) {
  3820. return;
  3821. }
  3822. this.pdfDocument = pdfDocument;
  3823. this.url = url;
  3824. this._dataAvailableCapability.resolve();
  3825. }
  3826. _reset() {
  3827. this.pdfDocument = null;
  3828. this.url = null;
  3829. delete this.fieldData;
  3830. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  3831. this._currentPageNumber = 1;
  3832. this._pagesRotation = 0;
  3833. }
  3834. _updateUI(reset = false) {
  3835. if (reset || !this.fieldData) {
  3836. for (const id in this.fields) {
  3837. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  3838. }
  3839. return;
  3840. }
  3841. if (this.overlayManager.active !== this.overlayName) {
  3842. return;
  3843. }
  3844. for (const id in this.fields) {
  3845. const content = this.fieldData[id];
  3846. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  3847. }
  3848. }
  3849. async _parseFileSize(fileSize = 0) {
  3850. const kb = fileSize / 1024,
  3851. mb = kb / 1024;
  3852. if (!kb) {
  3853. return undefined;
  3854. }
  3855. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  3856. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  3857. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  3858. size_b: fileSize.toLocaleString()
  3859. });
  3860. }
  3861. async _parsePageSize(pageSizeInches, pagesRotation) {
  3862. if (!pageSizeInches) {
  3863. return undefined;
  3864. }
  3865. if (pagesRotation % 180 !== 0) {
  3866. pageSizeInches = {
  3867. width: pageSizeInches.height,
  3868. height: pageSizeInches.width
  3869. };
  3870. }
  3871. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  3872. let sizeInches = {
  3873. width: Math.round(pageSizeInches.width * 100) / 100,
  3874. height: Math.round(pageSizeInches.height * 100) / 100
  3875. };
  3876. let sizeMillimeters = {
  3877. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  3878. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  3879. };
  3880. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  3881. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  3882. const exactMillimeters = {
  3883. width: pageSizeInches.width * 25.4,
  3884. height: pageSizeInches.height * 25.4
  3885. };
  3886. const intMillimeters = {
  3887. width: Math.round(sizeMillimeters.width),
  3888. height: Math.round(sizeMillimeters.height)
  3889. };
  3890. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  3891. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  3892. if (rawName) {
  3893. sizeInches = {
  3894. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  3895. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  3896. };
  3897. sizeMillimeters = intMillimeters;
  3898. }
  3899. }
  3900. }
  3901. const [{
  3902. width,
  3903. height
  3904. }, 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"}`)]);
  3905. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  3906. width: width.toLocaleString(),
  3907. height: height.toLocaleString(),
  3908. unit,
  3909. name,
  3910. orientation
  3911. });
  3912. }
  3913. async _parseDate(inputDate) {
  3914. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  3915. if (!dateObject) {
  3916. return undefined;
  3917. }
  3918. return this.l10n.get("document_properties_date_string", {
  3919. date: dateObject.toLocaleDateString(),
  3920. time: dateObject.toLocaleTimeString()
  3921. });
  3922. }
  3923. _parseLinearization(isLinearized) {
  3924. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  3925. }
  3926. }
  3927. exports.PDFDocumentProperties = PDFDocumentProperties;
  3928. /***/ }),
  3929. /* 13 */
  3930. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3931. Object.defineProperty(exports, "__esModule", ({
  3932. value: true
  3933. }));
  3934. exports.PDFFindBar = void 0;
  3935. var _pdf_find_controller = __webpack_require__(14);
  3936. const MATCHES_COUNT_LIMIT = 1000;
  3937. class PDFFindBar {
  3938. constructor(options, eventBus, l10n) {
  3939. this.opened = false;
  3940. this.bar = options.bar;
  3941. this.toggleButton = options.toggleButton;
  3942. this.findField = options.findField;
  3943. this.highlightAll = options.highlightAllCheckbox;
  3944. this.caseSensitive = options.caseSensitiveCheckbox;
  3945. this.entireWord = options.entireWordCheckbox;
  3946. this.findMsg = options.findMsg;
  3947. this.findResultsCount = options.findResultsCount;
  3948. this.findPreviousButton = options.findPreviousButton;
  3949. this.findNextButton = options.findNextButton;
  3950. this.eventBus = eventBus;
  3951. this.l10n = l10n;
  3952. this.toggleButton.addEventListener("click", () => {
  3953. this.toggle();
  3954. });
  3955. this.findField.addEventListener("input", () => {
  3956. this.dispatchEvent("");
  3957. });
  3958. this.bar.addEventListener("keydown", e => {
  3959. switch (e.keyCode) {
  3960. case 13:
  3961. if (e.target === this.findField) {
  3962. this.dispatchEvent("again", e.shiftKey);
  3963. }
  3964. break;
  3965. case 27:
  3966. this.close();
  3967. break;
  3968. }
  3969. });
  3970. this.findPreviousButton.addEventListener("click", () => {
  3971. this.dispatchEvent("again", true);
  3972. });
  3973. this.findNextButton.addEventListener("click", () => {
  3974. this.dispatchEvent("again", false);
  3975. });
  3976. this.highlightAll.addEventListener("click", () => {
  3977. this.dispatchEvent("highlightallchange");
  3978. });
  3979. this.caseSensitive.addEventListener("click", () => {
  3980. this.dispatchEvent("casesensitivitychange");
  3981. });
  3982. this.entireWord.addEventListener("click", () => {
  3983. this.dispatchEvent("entirewordchange");
  3984. });
  3985. this.eventBus._on("resize", this._adjustWidth.bind(this));
  3986. }
  3987. reset() {
  3988. this.updateUIState();
  3989. }
  3990. dispatchEvent(type, findPrev = false) {
  3991. this.eventBus.dispatch("find", {
  3992. source: this,
  3993. type,
  3994. query: this.findField.value,
  3995. phraseSearch: true,
  3996. caseSensitive: this.caseSensitive.checked,
  3997. entireWord: this.entireWord.checked,
  3998. highlightAll: this.highlightAll.checked,
  3999. findPrevious: findPrev
  4000. });
  4001. }
  4002. updateUIState(state, previous, matchesCount) {
  4003. let findMsg = Promise.resolve("");
  4004. let status = "";
  4005. switch (state) {
  4006. case _pdf_find_controller.FindState.FOUND:
  4007. break;
  4008. case _pdf_find_controller.FindState.PENDING:
  4009. status = "pending";
  4010. break;
  4011. case _pdf_find_controller.FindState.NOT_FOUND:
  4012. findMsg = this.l10n.get("find_not_found");
  4013. status = "notFound";
  4014. break;
  4015. case _pdf_find_controller.FindState.WRAPPED:
  4016. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4017. break;
  4018. }
  4019. this.findField.setAttribute("data-status", status);
  4020. findMsg.then(msg => {
  4021. this.findMsg.textContent = msg;
  4022. this._adjustWidth();
  4023. });
  4024. this.updateResultsCount(matchesCount);
  4025. }
  4026. updateResultsCount({
  4027. current = 0,
  4028. total = 0
  4029. } = {}) {
  4030. const limit = MATCHES_COUNT_LIMIT;
  4031. let matchCountMsg = Promise.resolve("");
  4032. if (total > 0) {
  4033. if (total > limit) {
  4034. let key = "find_match_count_limit";
  4035. matchCountMsg = this.l10n.get(key, {
  4036. limit
  4037. });
  4038. } else {
  4039. let key = "find_match_count";
  4040. matchCountMsg = this.l10n.get(key, {
  4041. current,
  4042. total
  4043. });
  4044. }
  4045. }
  4046. matchCountMsg.then(msg => {
  4047. this.findResultsCount.textContent = msg;
  4048. this.findResultsCount.classList.toggle("hidden", !total);
  4049. this._adjustWidth();
  4050. });
  4051. }
  4052. open() {
  4053. if (!this.opened) {
  4054. this.opened = true;
  4055. this.toggleButton.classList.add("toggled");
  4056. this.toggleButton.setAttribute("aria-expanded", "true");
  4057. this.bar.classList.remove("hidden");
  4058. }
  4059. this.findField.select();
  4060. this.findField.focus();
  4061. this._adjustWidth();
  4062. }
  4063. close() {
  4064. if (!this.opened) {
  4065. return;
  4066. }
  4067. this.opened = false;
  4068. this.toggleButton.classList.remove("toggled");
  4069. this.toggleButton.setAttribute("aria-expanded", "false");
  4070. this.bar.classList.add("hidden");
  4071. this.eventBus.dispatch("findbarclose", {
  4072. source: this
  4073. });
  4074. }
  4075. toggle() {
  4076. if (this.opened) {
  4077. this.close();
  4078. } else {
  4079. this.open();
  4080. }
  4081. }
  4082. _adjustWidth() {
  4083. if (!this.opened) {
  4084. return;
  4085. }
  4086. this.bar.classList.remove("wrapContainers");
  4087. const findbarHeight = this.bar.clientHeight;
  4088. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4089. if (findbarHeight > inputContainerHeight) {
  4090. this.bar.classList.add("wrapContainers");
  4091. }
  4092. }
  4093. }
  4094. exports.PDFFindBar = PDFFindBar;
  4095. /***/ }),
  4096. /* 14 */
  4097. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4098. Object.defineProperty(exports, "__esModule", ({
  4099. value: true
  4100. }));
  4101. exports.PDFFindController = exports.FindState = void 0;
  4102. var _pdfjsLib = __webpack_require__(5);
  4103. var _pdf_find_utils = __webpack_require__(15);
  4104. var _ui_utils = __webpack_require__(3);
  4105. const FindState = {
  4106. FOUND: 0,
  4107. NOT_FOUND: 1,
  4108. WRAPPED: 2,
  4109. PENDING: 3
  4110. };
  4111. exports.FindState = FindState;
  4112. const FIND_TIMEOUT = 250;
  4113. const MATCH_SCROLL_OFFSET_TOP = -50;
  4114. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4115. const CHARACTERS_TO_NORMALIZE = {
  4116. "\u2010": "-",
  4117. "\u2018": "'",
  4118. "\u2019": "'",
  4119. "\u201A": "'",
  4120. "\u201B": "'",
  4121. "\u201C": '"',
  4122. "\u201D": '"',
  4123. "\u201E": '"',
  4124. "\u201F": '"',
  4125. "\u00BC": "1/4",
  4126. "\u00BD": "1/2",
  4127. "\u00BE": "3/4"
  4128. };
  4129. let normalizationRegex = null;
  4130. function normalize(text) {
  4131. if (!normalizationRegex) {
  4132. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4133. normalizationRegex = new RegExp(`[${replace}]`, "g");
  4134. }
  4135. let diffs = null;
  4136. const normalizedText = text.replace(normalizationRegex, function (ch, index) {
  4137. const normalizedCh = CHARACTERS_TO_NORMALIZE[ch],
  4138. diff = normalizedCh.length - ch.length;
  4139. if (diff !== 0) {
  4140. (diffs ||= []).push([index, diff]);
  4141. }
  4142. return normalizedCh;
  4143. });
  4144. return [normalizedText, diffs];
  4145. }
  4146. function getOriginalIndex(matchIndex, diffs = null) {
  4147. if (!diffs) {
  4148. return matchIndex;
  4149. }
  4150. let totalDiff = 0;
  4151. for (const [index, diff] of diffs) {
  4152. const currentIndex = index + totalDiff;
  4153. if (currentIndex >= matchIndex) {
  4154. break;
  4155. }
  4156. if (currentIndex + diff > matchIndex) {
  4157. totalDiff += matchIndex - currentIndex;
  4158. break;
  4159. }
  4160. totalDiff += diff;
  4161. }
  4162. return matchIndex - totalDiff;
  4163. }
  4164. class PDFFindController {
  4165. constructor({
  4166. linkService,
  4167. eventBus
  4168. }) {
  4169. this._linkService = linkService;
  4170. this._eventBus = eventBus;
  4171. this._reset();
  4172. eventBus._on("find", this._onFind.bind(this));
  4173. eventBus._on("findbarclose", this._onFindBarClose.bind(this));
  4174. this.executeCommand = (cmd, state) => {
  4175. console.error("Deprecated method `PDFFindController.executeCommand` called, " + 'please dispatch a "find"-event using the EventBus instead.');
  4176. const eventState = Object.assign(Object.create(null), state, {
  4177. type: cmd.substring("find".length)
  4178. });
  4179. this._onFind(eventState);
  4180. };
  4181. }
  4182. get highlightMatches() {
  4183. return this._highlightMatches;
  4184. }
  4185. get pageMatches() {
  4186. return this._pageMatches;
  4187. }
  4188. get pageMatchesLength() {
  4189. return this._pageMatchesLength;
  4190. }
  4191. get selected() {
  4192. return this._selected;
  4193. }
  4194. get state() {
  4195. return this._state;
  4196. }
  4197. setDocument(pdfDocument) {
  4198. if (this._pdfDocument) {
  4199. this._reset();
  4200. }
  4201. if (!pdfDocument) {
  4202. return;
  4203. }
  4204. this._pdfDocument = pdfDocument;
  4205. this._firstPageCapability.resolve();
  4206. }
  4207. _onFind(state) {
  4208. if (!state) {
  4209. return;
  4210. }
  4211. const pdfDocument = this._pdfDocument;
  4212. const {
  4213. type
  4214. } = state;
  4215. if (this._state === null || this._shouldDirtyMatch(state)) {
  4216. this._dirtyMatch = true;
  4217. }
  4218. this._state = state;
  4219. if (type !== "highlightallchange") {
  4220. this._updateUIState(FindState.PENDING);
  4221. }
  4222. this._firstPageCapability.promise.then(() => {
  4223. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4224. return;
  4225. }
  4226. this._extractText();
  4227. const findbarClosed = !this._highlightMatches;
  4228. const pendingTimeout = !!this._findTimeout;
  4229. if (this._findTimeout) {
  4230. clearTimeout(this._findTimeout);
  4231. this._findTimeout = null;
  4232. }
  4233. if (!type) {
  4234. this._findTimeout = setTimeout(() => {
  4235. this._nextMatch();
  4236. this._findTimeout = null;
  4237. }, FIND_TIMEOUT);
  4238. } else if (this._dirtyMatch) {
  4239. this._nextMatch();
  4240. } else if (type === "again") {
  4241. this._nextMatch();
  4242. if (findbarClosed && this._state.highlightAll) {
  4243. this._updateAllPages();
  4244. }
  4245. } else if (type === "highlightallchange") {
  4246. if (pendingTimeout) {
  4247. this._nextMatch();
  4248. } else {
  4249. this._highlightMatches = true;
  4250. }
  4251. this._updateAllPages();
  4252. } else {
  4253. this._nextMatch();
  4254. }
  4255. });
  4256. }
  4257. scrollMatchIntoView({
  4258. element = null,
  4259. selectedLeft = 0,
  4260. pageIndex = -1,
  4261. matchIndex = -1
  4262. }) {
  4263. if (!this._scrollMatches || !element) {
  4264. return;
  4265. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4266. return;
  4267. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4268. return;
  4269. }
  4270. this._scrollMatches = false;
  4271. const spot = {
  4272. top: MATCH_SCROLL_OFFSET_TOP,
  4273. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  4274. };
  4275. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4276. }
  4277. _reset() {
  4278. this._highlightMatches = false;
  4279. this._scrollMatches = false;
  4280. this._pdfDocument = null;
  4281. this._pageMatches = [];
  4282. this._pageMatchesLength = [];
  4283. this._state = null;
  4284. this._selected = {
  4285. pageIdx: -1,
  4286. matchIdx: -1
  4287. };
  4288. this._offset = {
  4289. pageIdx: null,
  4290. matchIdx: null,
  4291. wrapped: false
  4292. };
  4293. this._extractTextPromises = [];
  4294. this._pageContents = [];
  4295. this._pageDiffs = [];
  4296. this._matchesCountTotal = 0;
  4297. this._pagesToSearch = null;
  4298. this._pendingFindMatches = new Set();
  4299. this._resumePageIdx = null;
  4300. this._dirtyMatch = false;
  4301. clearTimeout(this._findTimeout);
  4302. this._findTimeout = null;
  4303. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4304. }
  4305. get _query() {
  4306. if (this._state.query !== this._rawQuery) {
  4307. this._rawQuery = this._state.query;
  4308. [this._normalizedQuery] = normalize(this._state.query);
  4309. }
  4310. return this._normalizedQuery;
  4311. }
  4312. _shouldDirtyMatch(state) {
  4313. if (state.query !== this._state.query) {
  4314. return true;
  4315. }
  4316. switch (state.type) {
  4317. case "again":
  4318. const pageNumber = this._selected.pageIdx + 1;
  4319. const linkService = this._linkService;
  4320. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4321. return true;
  4322. }
  4323. return false;
  4324. case "highlightallchange":
  4325. return false;
  4326. }
  4327. return true;
  4328. }
  4329. _prepareMatches(matchesWithLength, matches, matchesLength) {
  4330. function isSubTerm(currentIndex) {
  4331. const currentElem = matchesWithLength[currentIndex];
  4332. const nextElem = matchesWithLength[currentIndex + 1];
  4333. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  4334. currentElem.skipped = true;
  4335. return true;
  4336. }
  4337. for (let i = currentIndex - 1; i >= 0; i--) {
  4338. const prevElem = matchesWithLength[i];
  4339. if (prevElem.skipped) {
  4340. continue;
  4341. }
  4342. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  4343. break;
  4344. }
  4345. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  4346. currentElem.skipped = true;
  4347. return true;
  4348. }
  4349. }
  4350. return false;
  4351. }
  4352. matchesWithLength.sort(function (a, b) {
  4353. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  4354. });
  4355. for (let i = 0, len = matchesWithLength.length; i < len; i++) {
  4356. if (isSubTerm(i)) {
  4357. continue;
  4358. }
  4359. matches.push(matchesWithLength[i].match);
  4360. matchesLength.push(matchesWithLength[i].matchLength);
  4361. }
  4362. }
  4363. _isEntireWord(content, startIdx, length) {
  4364. if (startIdx > 0) {
  4365. const first = content.charCodeAt(startIdx);
  4366. const limit = content.charCodeAt(startIdx - 1);
  4367. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4368. return false;
  4369. }
  4370. }
  4371. const endIdx = startIdx + length - 1;
  4372. if (endIdx < content.length - 1) {
  4373. const last = content.charCodeAt(endIdx);
  4374. const limit = content.charCodeAt(endIdx + 1);
  4375. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4376. return false;
  4377. }
  4378. }
  4379. return true;
  4380. }
  4381. _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4382. const matches = [],
  4383. matchesLength = [];
  4384. const queryLen = query.length;
  4385. let matchIdx = -queryLen;
  4386. while (true) {
  4387. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  4388. if (matchIdx === -1) {
  4389. break;
  4390. }
  4391. if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
  4392. continue;
  4393. }
  4394. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4395. matchEnd = matchIdx + queryLen - 1,
  4396. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4397. matches.push(originalMatchIdx);
  4398. matchesLength.push(originalQueryLen);
  4399. }
  4400. this._pageMatches[pageIndex] = matches;
  4401. this._pageMatchesLength[pageIndex] = matchesLength;
  4402. }
  4403. _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4404. const matchesWithLength = [];
  4405. const queryArray = query.match(/\S+/g);
  4406. for (let i = 0, len = queryArray.length; i < len; i++) {
  4407. const subquery = queryArray[i];
  4408. const subqueryLen = subquery.length;
  4409. let matchIdx = -subqueryLen;
  4410. while (true) {
  4411. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  4412. if (matchIdx === -1) {
  4413. break;
  4414. }
  4415. if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
  4416. continue;
  4417. }
  4418. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4419. matchEnd = matchIdx + subqueryLen - 1,
  4420. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4421. matchesWithLength.push({
  4422. match: originalMatchIdx,
  4423. matchLength: originalQueryLen,
  4424. skipped: false
  4425. });
  4426. }
  4427. }
  4428. this._pageMatchesLength[pageIndex] = [];
  4429. this._pageMatches[pageIndex] = [];
  4430. this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
  4431. }
  4432. _calculateMatch(pageIndex) {
  4433. let pageContent = this._pageContents[pageIndex];
  4434. const pageDiffs = this._pageDiffs[pageIndex];
  4435. let query = this._query;
  4436. const {
  4437. caseSensitive,
  4438. entireWord,
  4439. phraseSearch
  4440. } = this._state;
  4441. if (query.length === 0) {
  4442. return;
  4443. }
  4444. if (!caseSensitive) {
  4445. pageContent = pageContent.toLowerCase();
  4446. query = query.toLowerCase();
  4447. }
  4448. if (phraseSearch) {
  4449. this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4450. } else {
  4451. this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4452. }
  4453. if (this._state.highlightAll) {
  4454. this._updatePage(pageIndex);
  4455. }
  4456. if (this._resumePageIdx === pageIndex) {
  4457. this._resumePageIdx = null;
  4458. this._nextPageMatch();
  4459. }
  4460. const pageMatchesCount = this._pageMatches[pageIndex].length;
  4461. if (pageMatchesCount > 0) {
  4462. this._matchesCountTotal += pageMatchesCount;
  4463. this._updateUIResultsCount();
  4464. }
  4465. }
  4466. _extractText() {
  4467. if (this._extractTextPromises.length > 0) {
  4468. return;
  4469. }
  4470. let promise = Promise.resolve();
  4471. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  4472. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  4473. this._extractTextPromises[i] = extractTextCapability.promise;
  4474. promise = promise.then(() => {
  4475. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  4476. return pdfPage.getTextContent({
  4477. normalizeWhitespace: true
  4478. });
  4479. }).then(textContent => {
  4480. const textItems = textContent.items;
  4481. const strBuf = [];
  4482. for (let j = 0, jj = textItems.length; j < jj; j++) {
  4483. strBuf.push(textItems[j].str);
  4484. }
  4485. [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""));
  4486. extractTextCapability.resolve(i);
  4487. }, reason => {
  4488. console.error(`Unable to get text content for page ${i + 1}`, reason);
  4489. this._pageContents[i] = "";
  4490. this._pageDiffs[i] = null;
  4491. extractTextCapability.resolve(i);
  4492. });
  4493. });
  4494. }
  4495. }
  4496. _updatePage(index) {
  4497. if (this._scrollMatches && this._selected.pageIdx === index) {
  4498. this._linkService.page = index + 1;
  4499. }
  4500. this._eventBus.dispatch("updatetextlayermatches", {
  4501. source: this,
  4502. pageIndex: index
  4503. });
  4504. }
  4505. _updateAllPages() {
  4506. this._eventBus.dispatch("updatetextlayermatches", {
  4507. source: this,
  4508. pageIndex: -1
  4509. });
  4510. }
  4511. _nextMatch() {
  4512. const previous = this._state.findPrevious;
  4513. const currentPageIndex = this._linkService.page - 1;
  4514. const numPages = this._linkService.pagesCount;
  4515. this._highlightMatches = true;
  4516. if (this._dirtyMatch) {
  4517. this._dirtyMatch = false;
  4518. this._selected.pageIdx = this._selected.matchIdx = -1;
  4519. this._offset.pageIdx = currentPageIndex;
  4520. this._offset.matchIdx = null;
  4521. this._offset.wrapped = false;
  4522. this._resumePageIdx = null;
  4523. this._pageMatches.length = 0;
  4524. this._pageMatchesLength.length = 0;
  4525. this._matchesCountTotal = 0;
  4526. this._updateAllPages();
  4527. for (let i = 0; i < numPages; i++) {
  4528. if (this._pendingFindMatches.has(i)) {
  4529. continue;
  4530. }
  4531. this._pendingFindMatches.add(i);
  4532. this._extractTextPromises[i].then(pageIdx => {
  4533. this._pendingFindMatches.delete(pageIdx);
  4534. this._calculateMatch(pageIdx);
  4535. });
  4536. }
  4537. }
  4538. if (this._query === "") {
  4539. this._updateUIState(FindState.FOUND);
  4540. return;
  4541. }
  4542. if (this._resumePageIdx) {
  4543. return;
  4544. }
  4545. const offset = this._offset;
  4546. this._pagesToSearch = numPages;
  4547. if (offset.matchIdx !== null) {
  4548. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  4549. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  4550. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  4551. this._updateMatch(true);
  4552. return;
  4553. }
  4554. this._advanceOffsetPage(previous);
  4555. }
  4556. this._nextPageMatch();
  4557. }
  4558. _matchesReady(matches) {
  4559. const offset = this._offset;
  4560. const numMatches = matches.length;
  4561. const previous = this._state.findPrevious;
  4562. if (numMatches) {
  4563. offset.matchIdx = previous ? numMatches - 1 : 0;
  4564. this._updateMatch(true);
  4565. return true;
  4566. }
  4567. this._advanceOffsetPage(previous);
  4568. if (offset.wrapped) {
  4569. offset.matchIdx = null;
  4570. if (this._pagesToSearch < 0) {
  4571. this._updateMatch(false);
  4572. return true;
  4573. }
  4574. }
  4575. return false;
  4576. }
  4577. _nextPageMatch() {
  4578. if (this._resumePageIdx !== null) {
  4579. console.error("There can only be one pending page.");
  4580. }
  4581. let matches = null;
  4582. do {
  4583. const pageIdx = this._offset.pageIdx;
  4584. matches = this._pageMatches[pageIdx];
  4585. if (!matches) {
  4586. this._resumePageIdx = pageIdx;
  4587. break;
  4588. }
  4589. } while (!this._matchesReady(matches));
  4590. }
  4591. _advanceOffsetPage(previous) {
  4592. const offset = this._offset;
  4593. const numPages = this._linkService.pagesCount;
  4594. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  4595. offset.matchIdx = null;
  4596. this._pagesToSearch--;
  4597. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  4598. offset.pageIdx = previous ? numPages - 1 : 0;
  4599. offset.wrapped = true;
  4600. }
  4601. }
  4602. _updateMatch(found = false) {
  4603. let state = FindState.NOT_FOUND;
  4604. const wrapped = this._offset.wrapped;
  4605. this._offset.wrapped = false;
  4606. if (found) {
  4607. const previousPage = this._selected.pageIdx;
  4608. this._selected.pageIdx = this._offset.pageIdx;
  4609. this._selected.matchIdx = this._offset.matchIdx;
  4610. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  4611. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  4612. this._updatePage(previousPage);
  4613. }
  4614. }
  4615. this._updateUIState(state, this._state.findPrevious);
  4616. if (this._selected.pageIdx !== -1) {
  4617. this._scrollMatches = true;
  4618. this._updatePage(this._selected.pageIdx);
  4619. }
  4620. }
  4621. _onFindBarClose(evt) {
  4622. const pdfDocument = this._pdfDocument;
  4623. this._firstPageCapability.promise.then(() => {
  4624. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4625. return;
  4626. }
  4627. if (this._findTimeout) {
  4628. clearTimeout(this._findTimeout);
  4629. this._findTimeout = null;
  4630. }
  4631. if (this._resumePageIdx) {
  4632. this._resumePageIdx = null;
  4633. this._dirtyMatch = true;
  4634. }
  4635. this._updateUIState(FindState.FOUND);
  4636. this._highlightMatches = false;
  4637. this._updateAllPages();
  4638. });
  4639. }
  4640. _requestMatchesCount() {
  4641. const {
  4642. pageIdx,
  4643. matchIdx
  4644. } = this._selected;
  4645. let current = 0,
  4646. total = this._matchesCountTotal;
  4647. if (matchIdx !== -1) {
  4648. for (let i = 0; i < pageIdx; i++) {
  4649. current += this._pageMatches[i]?.length || 0;
  4650. }
  4651. current += matchIdx + 1;
  4652. }
  4653. if (current < 1 || current > total) {
  4654. current = total = 0;
  4655. }
  4656. return {
  4657. current,
  4658. total
  4659. };
  4660. }
  4661. _updateUIResultsCount() {
  4662. this._eventBus.dispatch("updatefindmatchescount", {
  4663. source: this,
  4664. matchesCount: this._requestMatchesCount()
  4665. });
  4666. }
  4667. _updateUIState(state, previous = false) {
  4668. this._eventBus.dispatch("updatefindcontrolstate", {
  4669. source: this,
  4670. state,
  4671. previous,
  4672. matchesCount: this._requestMatchesCount(),
  4673. rawQuery: this._state?.query ?? null
  4674. });
  4675. }
  4676. }
  4677. exports.PDFFindController = PDFFindController;
  4678. /***/ }),
  4679. /* 15 */
  4680. /***/ ((__unused_webpack_module, exports) => {
  4681. Object.defineProperty(exports, "__esModule", ({
  4682. value: true
  4683. }));
  4684. exports.CharacterType = void 0;
  4685. exports.getCharacterType = getCharacterType;
  4686. const CharacterType = {
  4687. SPACE: 0,
  4688. ALPHA_LETTER: 1,
  4689. PUNCT: 2,
  4690. HAN_LETTER: 3,
  4691. KATAKANA_LETTER: 4,
  4692. HIRAGANA_LETTER: 5,
  4693. HALFWIDTH_KATAKANA_LETTER: 6,
  4694. THAI_LETTER: 7
  4695. };
  4696. exports.CharacterType = CharacterType;
  4697. function isAlphabeticalScript(charCode) {
  4698. return charCode < 0x2e80;
  4699. }
  4700. function isAscii(charCode) {
  4701. return (charCode & 0xff80) === 0;
  4702. }
  4703. function isAsciiAlpha(charCode) {
  4704. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  4705. }
  4706. function isAsciiDigit(charCode) {
  4707. return charCode >= 0x30 && charCode <= 0x39;
  4708. }
  4709. function isAsciiSpace(charCode) {
  4710. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  4711. }
  4712. function isHan(charCode) {
  4713. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  4714. }
  4715. function isKatakana(charCode) {
  4716. return charCode >= 0x30a0 && charCode <= 0x30ff;
  4717. }
  4718. function isHiragana(charCode) {
  4719. return charCode >= 0x3040 && charCode <= 0x309f;
  4720. }
  4721. function isHalfwidthKatakana(charCode) {
  4722. return charCode >= 0xff60 && charCode <= 0xff9f;
  4723. }
  4724. function isThai(charCode) {
  4725. return (charCode & 0xff80) === 0x0e00;
  4726. }
  4727. function getCharacterType(charCode) {
  4728. if (isAlphabeticalScript(charCode)) {
  4729. if (isAscii(charCode)) {
  4730. if (isAsciiSpace(charCode)) {
  4731. return CharacterType.SPACE;
  4732. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  4733. return CharacterType.ALPHA_LETTER;
  4734. }
  4735. return CharacterType.PUNCT;
  4736. } else if (isThai(charCode)) {
  4737. return CharacterType.THAI_LETTER;
  4738. } else if (charCode === 0xa0) {
  4739. return CharacterType.SPACE;
  4740. }
  4741. return CharacterType.ALPHA_LETTER;
  4742. }
  4743. if (isHan(charCode)) {
  4744. return CharacterType.HAN_LETTER;
  4745. } else if (isKatakana(charCode)) {
  4746. return CharacterType.KATAKANA_LETTER;
  4747. } else if (isHiragana(charCode)) {
  4748. return CharacterType.HIRAGANA_LETTER;
  4749. } else if (isHalfwidthKatakana(charCode)) {
  4750. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  4751. }
  4752. return CharacterType.ALPHA_LETTER;
  4753. }
  4754. /***/ }),
  4755. /* 16 */
  4756. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4757. Object.defineProperty(exports, "__esModule", ({
  4758. value: true
  4759. }));
  4760. exports.PDFHistory = void 0;
  4761. exports.isDestArraysEqual = isDestArraysEqual;
  4762. exports.isDestHashesEqual = isDestHashesEqual;
  4763. var _ui_utils = __webpack_require__(3);
  4764. var _event_utils = __webpack_require__(4);
  4765. const HASH_CHANGE_TIMEOUT = 1000;
  4766. const POSITION_UPDATED_THRESHOLD = 50;
  4767. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  4768. function getCurrentHash() {
  4769. return document.location.hash;
  4770. }
  4771. class PDFHistory {
  4772. constructor({
  4773. linkService,
  4774. eventBus
  4775. }) {
  4776. this.linkService = linkService;
  4777. this.eventBus = eventBus;
  4778. this._initialized = false;
  4779. this._fingerprint = "";
  4780. this.reset();
  4781. this._boundEvents = null;
  4782. this._isViewerInPresentationMode = false;
  4783. this.eventBus._on("presentationmodechanged", evt => {
  4784. this._isViewerInPresentationMode = evt.state !== _ui_utils.PresentationModeState.NORMAL;
  4785. });
  4786. this.eventBus._on("pagesinit", () => {
  4787. this._isPagesLoaded = false;
  4788. this.eventBus._on("pagesloaded", evt => {
  4789. this._isPagesLoaded = !!evt.pagesCount;
  4790. }, {
  4791. once: true
  4792. });
  4793. });
  4794. }
  4795. initialize({
  4796. fingerprint,
  4797. resetHistory = false,
  4798. updateUrl = false
  4799. }) {
  4800. if (!fingerprint || typeof fingerprint !== "string") {
  4801. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  4802. return;
  4803. }
  4804. if (this._initialized) {
  4805. this.reset();
  4806. }
  4807. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  4808. this._fingerprint = fingerprint;
  4809. this._updateUrl = updateUrl === true;
  4810. this._initialized = true;
  4811. this._bindEvents();
  4812. const state = window.history.state;
  4813. this._popStateInProgress = false;
  4814. this._blockHashChange = 0;
  4815. this._currentHash = getCurrentHash();
  4816. this._numPositionUpdates = 0;
  4817. this._uid = this._maxUid = 0;
  4818. this._destination = null;
  4819. this._position = null;
  4820. if (!this._isValidState(state, true) || resetHistory) {
  4821. const {
  4822. hash,
  4823. page,
  4824. rotation
  4825. } = this._parseCurrentHash(true);
  4826. if (!hash || reInitialized || resetHistory) {
  4827. this._pushOrReplaceState(null, true);
  4828. return;
  4829. }
  4830. this._pushOrReplaceState({
  4831. hash,
  4832. page,
  4833. rotation
  4834. }, true);
  4835. return;
  4836. }
  4837. const destination = state.destination;
  4838. this._updateInternalState(destination, state.uid, true);
  4839. if (destination.rotation !== undefined) {
  4840. this._initialRotation = destination.rotation;
  4841. }
  4842. if (destination.dest) {
  4843. this._initialBookmark = JSON.stringify(destination.dest);
  4844. this._destination.page = null;
  4845. } else if (destination.hash) {
  4846. this._initialBookmark = destination.hash;
  4847. } else if (destination.page) {
  4848. this._initialBookmark = `page=${destination.page}`;
  4849. }
  4850. }
  4851. reset() {
  4852. if (this._initialized) {
  4853. this._pageHide();
  4854. this._initialized = false;
  4855. this._unbindEvents();
  4856. }
  4857. if (this._updateViewareaTimeout) {
  4858. clearTimeout(this._updateViewareaTimeout);
  4859. this._updateViewareaTimeout = null;
  4860. }
  4861. this._initialBookmark = null;
  4862. this._initialRotation = null;
  4863. }
  4864. push({
  4865. namedDest = null,
  4866. explicitDest,
  4867. pageNumber
  4868. }) {
  4869. if (!this._initialized) {
  4870. return;
  4871. }
  4872. if (namedDest && typeof namedDest !== "string") {
  4873. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  4874. return;
  4875. } else if (!Array.isArray(explicitDest)) {
  4876. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  4877. return;
  4878. } else if (!this._isValidPage(pageNumber)) {
  4879. if (pageNumber !== null || this._destination) {
  4880. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  4881. return;
  4882. }
  4883. }
  4884. const hash = namedDest || JSON.stringify(explicitDest);
  4885. if (!hash) {
  4886. return;
  4887. }
  4888. let forceReplace = false;
  4889. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  4890. if (this._destination.page) {
  4891. return;
  4892. }
  4893. forceReplace = true;
  4894. }
  4895. if (this._popStateInProgress && !forceReplace) {
  4896. return;
  4897. }
  4898. this._pushOrReplaceState({
  4899. dest: explicitDest,
  4900. hash,
  4901. page: pageNumber,
  4902. rotation: this.linkService.rotation
  4903. }, forceReplace);
  4904. if (!this._popStateInProgress) {
  4905. this._popStateInProgress = true;
  4906. Promise.resolve().then(() => {
  4907. this._popStateInProgress = false;
  4908. });
  4909. }
  4910. }
  4911. pushPage(pageNumber) {
  4912. if (!this._initialized) {
  4913. return;
  4914. }
  4915. if (!this._isValidPage(pageNumber)) {
  4916. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  4917. return;
  4918. }
  4919. if (this._destination?.page === pageNumber) {
  4920. return;
  4921. }
  4922. if (this._popStateInProgress) {
  4923. return;
  4924. }
  4925. this._pushOrReplaceState({
  4926. dest: null,
  4927. hash: `page=${pageNumber}`,
  4928. page: pageNumber,
  4929. rotation: this.linkService.rotation
  4930. });
  4931. if (!this._popStateInProgress) {
  4932. this._popStateInProgress = true;
  4933. Promise.resolve().then(() => {
  4934. this._popStateInProgress = false;
  4935. });
  4936. }
  4937. }
  4938. pushCurrentPosition() {
  4939. if (!this._initialized || this._popStateInProgress) {
  4940. return;
  4941. }
  4942. this._tryPushCurrentPosition();
  4943. }
  4944. back() {
  4945. if (!this._initialized || this._popStateInProgress) {
  4946. return;
  4947. }
  4948. const state = window.history.state;
  4949. if (this._isValidState(state) && state.uid > 0) {
  4950. window.history.back();
  4951. }
  4952. }
  4953. forward() {
  4954. if (!this._initialized || this._popStateInProgress) {
  4955. return;
  4956. }
  4957. const state = window.history.state;
  4958. if (this._isValidState(state) && state.uid < this._maxUid) {
  4959. window.history.forward();
  4960. }
  4961. }
  4962. get popStateInProgress() {
  4963. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  4964. }
  4965. get initialBookmark() {
  4966. return this._initialized ? this._initialBookmark : null;
  4967. }
  4968. get initialRotation() {
  4969. return this._initialized ? this._initialRotation : null;
  4970. }
  4971. _pushOrReplaceState(destination, forceReplace = false) {
  4972. const shouldReplace = forceReplace || !this._destination;
  4973. const newState = {
  4974. fingerprint: this._fingerprint,
  4975. uid: shouldReplace ? this._uid : this._uid + 1,
  4976. destination
  4977. };
  4978. this._updateInternalState(destination, newState.uid);
  4979. let newUrl;
  4980. if (this._updateUrl && destination?.hash) {
  4981. const baseUrl = document.location.href.split("#")[0];
  4982. if (!baseUrl.startsWith("file://")) {
  4983. newUrl = `${baseUrl}#${destination.hash}`;
  4984. }
  4985. }
  4986. if (shouldReplace) {
  4987. window.history.replaceState(newState, "", newUrl);
  4988. } else {
  4989. window.history.pushState(newState, "", newUrl);
  4990. }
  4991. }
  4992. _tryPushCurrentPosition(temporary = false) {
  4993. if (!this._position) {
  4994. return;
  4995. }
  4996. let position = this._position;
  4997. if (temporary) {
  4998. position = Object.assign(Object.create(null), this._position);
  4999. position.temporary = true;
  5000. }
  5001. if (!this._destination) {
  5002. this._pushOrReplaceState(position);
  5003. return;
  5004. }
  5005. if (this._destination.temporary) {
  5006. this._pushOrReplaceState(position, true);
  5007. return;
  5008. }
  5009. if (this._destination.hash === position.hash) {
  5010. return;
  5011. }
  5012. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5013. return;
  5014. }
  5015. let forceReplace = false;
  5016. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5017. if (this._destination.dest !== undefined || !this._destination.first) {
  5018. return;
  5019. }
  5020. forceReplace = true;
  5021. }
  5022. this._pushOrReplaceState(position, forceReplace);
  5023. }
  5024. _isValidPage(val) {
  5025. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5026. }
  5027. _isValidState(state, checkReload = false) {
  5028. if (!state) {
  5029. return false;
  5030. }
  5031. if (state.fingerprint !== this._fingerprint) {
  5032. if (checkReload) {
  5033. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5034. return false;
  5035. }
  5036. const [perfEntry] = performance.getEntriesByType("navigation");
  5037. if (perfEntry?.type !== "reload") {
  5038. return false;
  5039. }
  5040. } else {
  5041. return false;
  5042. }
  5043. }
  5044. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5045. return false;
  5046. }
  5047. if (state.destination === null || typeof state.destination !== "object") {
  5048. return false;
  5049. }
  5050. return true;
  5051. }
  5052. _updateInternalState(destination, uid, removeTemporary = false) {
  5053. if (this._updateViewareaTimeout) {
  5054. clearTimeout(this._updateViewareaTimeout);
  5055. this._updateViewareaTimeout = null;
  5056. }
  5057. if (removeTemporary && destination?.temporary) {
  5058. delete destination.temporary;
  5059. }
  5060. this._destination = destination;
  5061. this._uid = uid;
  5062. this._maxUid = Math.max(this._maxUid, uid);
  5063. this._numPositionUpdates = 0;
  5064. }
  5065. _parseCurrentHash(checkNameddest = false) {
  5066. const hash = unescape(getCurrentHash()).substring(1);
  5067. const params = (0, _ui_utils.parseQueryString)(hash);
  5068. const nameddest = params.get("nameddest") || "";
  5069. let page = params.get("page") | 0;
  5070. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5071. page = null;
  5072. }
  5073. return {
  5074. hash,
  5075. page,
  5076. rotation: this.linkService.rotation
  5077. };
  5078. }
  5079. _updateViewarea({
  5080. location
  5081. }) {
  5082. if (this._updateViewareaTimeout) {
  5083. clearTimeout(this._updateViewareaTimeout);
  5084. this._updateViewareaTimeout = null;
  5085. }
  5086. this._position = {
  5087. hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
  5088. page: this.linkService.page,
  5089. first: location.pageNumber,
  5090. rotation: location.rotation
  5091. };
  5092. if (this._popStateInProgress) {
  5093. return;
  5094. }
  5095. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5096. this._numPositionUpdates++;
  5097. }
  5098. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5099. this._updateViewareaTimeout = setTimeout(() => {
  5100. if (!this._popStateInProgress) {
  5101. this._tryPushCurrentPosition(true);
  5102. }
  5103. this._updateViewareaTimeout = null;
  5104. }, UPDATE_VIEWAREA_TIMEOUT);
  5105. }
  5106. }
  5107. _popState({
  5108. state
  5109. }) {
  5110. const newHash = getCurrentHash(),
  5111. hashChanged = this._currentHash !== newHash;
  5112. this._currentHash = newHash;
  5113. if (!state) {
  5114. this._uid++;
  5115. const {
  5116. hash,
  5117. page,
  5118. rotation
  5119. } = this._parseCurrentHash();
  5120. this._pushOrReplaceState({
  5121. hash,
  5122. page,
  5123. rotation
  5124. }, true);
  5125. return;
  5126. }
  5127. if (!this._isValidState(state)) {
  5128. return;
  5129. }
  5130. this._popStateInProgress = true;
  5131. if (hashChanged) {
  5132. this._blockHashChange++;
  5133. (0, _event_utils.waitOnEventOrTimeout)({
  5134. target: window,
  5135. name: "hashchange",
  5136. delay: HASH_CHANGE_TIMEOUT
  5137. }).then(() => {
  5138. this._blockHashChange--;
  5139. });
  5140. }
  5141. const destination = state.destination;
  5142. this._updateInternalState(destination, state.uid, true);
  5143. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5144. this.linkService.rotation = destination.rotation;
  5145. }
  5146. if (destination.dest) {
  5147. this.linkService.goToDestination(destination.dest);
  5148. } else if (destination.hash) {
  5149. this.linkService.setHash(destination.hash);
  5150. } else if (destination.page) {
  5151. this.linkService.page = destination.page;
  5152. }
  5153. Promise.resolve().then(() => {
  5154. this._popStateInProgress = false;
  5155. });
  5156. }
  5157. _pageHide() {
  5158. if (!this._destination || this._destination.temporary) {
  5159. this._tryPushCurrentPosition();
  5160. }
  5161. }
  5162. _bindEvents() {
  5163. if (this._boundEvents) {
  5164. return;
  5165. }
  5166. this._boundEvents = {
  5167. updateViewarea: this._updateViewarea.bind(this),
  5168. popState: this._popState.bind(this),
  5169. pageHide: this._pageHide.bind(this)
  5170. };
  5171. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5172. window.addEventListener("popstate", this._boundEvents.popState);
  5173. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5174. }
  5175. _unbindEvents() {
  5176. if (!this._boundEvents) {
  5177. return;
  5178. }
  5179. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5180. window.removeEventListener("popstate", this._boundEvents.popState);
  5181. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5182. this._boundEvents = null;
  5183. }
  5184. }
  5185. exports.PDFHistory = PDFHistory;
  5186. function isDestHashesEqual(destHash, pushHash) {
  5187. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5188. return false;
  5189. }
  5190. if (destHash === pushHash) {
  5191. return true;
  5192. }
  5193. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  5194. if (nameddest === pushHash) {
  5195. return true;
  5196. }
  5197. return false;
  5198. }
  5199. function isDestArraysEqual(firstDest, secondDest) {
  5200. function isEntryEqual(first, second) {
  5201. if (typeof first !== typeof second) {
  5202. return false;
  5203. }
  5204. if (Array.isArray(first) || Array.isArray(second)) {
  5205. return false;
  5206. }
  5207. if (first !== null && typeof first === "object" && second !== null) {
  5208. if (Object.keys(first).length !== Object.keys(second).length) {
  5209. return false;
  5210. }
  5211. for (const key in first) {
  5212. if (!isEntryEqual(first[key], second[key])) {
  5213. return false;
  5214. }
  5215. }
  5216. return true;
  5217. }
  5218. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5219. }
  5220. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5221. return false;
  5222. }
  5223. if (firstDest.length !== secondDest.length) {
  5224. return false;
  5225. }
  5226. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5227. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5228. return false;
  5229. }
  5230. }
  5231. return true;
  5232. }
  5233. /***/ }),
  5234. /* 17 */
  5235. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5236. Object.defineProperty(exports, "__esModule", ({
  5237. value: true
  5238. }));
  5239. exports.PDFLayerViewer = void 0;
  5240. var _base_tree_viewer = __webpack_require__(11);
  5241. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5242. constructor(options) {
  5243. super(options);
  5244. this.l10n = options.l10n;
  5245. this.eventBus._on("resetlayers", this._resetLayers.bind(this));
  5246. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5247. }
  5248. reset() {
  5249. super.reset();
  5250. this._optionalContentConfig = null;
  5251. }
  5252. _dispatchEvent(layersCount) {
  5253. this.eventBus.dispatch("layersloaded", {
  5254. source: this,
  5255. layersCount
  5256. });
  5257. }
  5258. _bindLink(element, {
  5259. groupId,
  5260. input
  5261. }) {
  5262. const setVisibility = () => {
  5263. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5264. this.eventBus.dispatch("optionalcontentconfig", {
  5265. source: this,
  5266. promise: Promise.resolve(this._optionalContentConfig)
  5267. });
  5268. };
  5269. element.onclick = evt => {
  5270. if (evt.target === input) {
  5271. setVisibility();
  5272. return true;
  5273. } else if (evt.target !== element) {
  5274. return true;
  5275. }
  5276. input.checked = !input.checked;
  5277. setVisibility();
  5278. return false;
  5279. };
  5280. }
  5281. async _setNestedName(element, {
  5282. name = null
  5283. }) {
  5284. if (typeof name === "string") {
  5285. element.textContent = this._normalizeTextContent(name);
  5286. return;
  5287. }
  5288. element.textContent = await this.l10n.get("additional_layers");
  5289. element.style.fontStyle = "italic";
  5290. }
  5291. _addToggleButton(div, {
  5292. name = null
  5293. }) {
  5294. super._addToggleButton(div, name === null);
  5295. }
  5296. _toggleAllTreeItems() {
  5297. if (!this._optionalContentConfig) {
  5298. return;
  5299. }
  5300. super._toggleAllTreeItems();
  5301. }
  5302. render({
  5303. optionalContentConfig,
  5304. pdfDocument
  5305. }) {
  5306. if (this._optionalContentConfig) {
  5307. this.reset();
  5308. }
  5309. this._optionalContentConfig = optionalContentConfig || null;
  5310. this._pdfDocument = pdfDocument || null;
  5311. const groups = optionalContentConfig?.getOrder();
  5312. if (!groups) {
  5313. this._dispatchEvent(0);
  5314. return;
  5315. }
  5316. const fragment = document.createDocumentFragment(),
  5317. queue = [{
  5318. parent: fragment,
  5319. groups
  5320. }];
  5321. let layersCount = 0,
  5322. hasAnyNesting = false;
  5323. while (queue.length > 0) {
  5324. const levelData = queue.shift();
  5325. for (const groupId of levelData.groups) {
  5326. const div = document.createElement("div");
  5327. div.className = "treeItem";
  5328. const element = document.createElement("a");
  5329. div.appendChild(element);
  5330. if (typeof groupId === "object") {
  5331. hasAnyNesting = true;
  5332. this._addToggleButton(div, groupId);
  5333. this._setNestedName(element, groupId);
  5334. const itemsDiv = document.createElement("div");
  5335. itemsDiv.className = "treeItems";
  5336. div.appendChild(itemsDiv);
  5337. queue.push({
  5338. parent: itemsDiv,
  5339. groups: groupId.order
  5340. });
  5341. } else {
  5342. const group = optionalContentConfig.getGroup(groupId);
  5343. const input = document.createElement("input");
  5344. this._bindLink(element, {
  5345. groupId,
  5346. input
  5347. });
  5348. input.type = "checkbox";
  5349. input.id = groupId;
  5350. input.checked = group.visible;
  5351. const label = document.createElement("label");
  5352. label.setAttribute("for", groupId);
  5353. label.textContent = this._normalizeTextContent(group.name);
  5354. element.appendChild(input);
  5355. element.appendChild(label);
  5356. layersCount++;
  5357. }
  5358. levelData.parent.appendChild(div);
  5359. }
  5360. }
  5361. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5362. }
  5363. async _resetLayers() {
  5364. if (!this._optionalContentConfig) {
  5365. return;
  5366. }
  5367. const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
  5368. this.eventBus.dispatch("optionalcontentconfig", {
  5369. source: this,
  5370. promise: Promise.resolve(optionalContentConfig)
  5371. });
  5372. this.render({
  5373. optionalContentConfig,
  5374. pdfDocument: this._pdfDocument
  5375. });
  5376. }
  5377. }
  5378. exports.PDFLayerViewer = PDFLayerViewer;
  5379. /***/ }),
  5380. /* 18 */
  5381. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5382. Object.defineProperty(exports, "__esModule", ({
  5383. value: true
  5384. }));
  5385. exports.SimpleLinkService = exports.PDFLinkService = void 0;
  5386. var _pdfjsLib = __webpack_require__(5);
  5387. var _ui_utils = __webpack_require__(3);
  5388. class PDFLinkService {
  5389. constructor({
  5390. eventBus,
  5391. externalLinkTarget = null,
  5392. externalLinkRel = null,
  5393. ignoreDestinationZoom = false
  5394. } = {}) {
  5395. this.eventBus = eventBus;
  5396. this.externalLinkTarget = externalLinkTarget;
  5397. this.externalLinkRel = externalLinkRel;
  5398. this.externalLinkEnabled = true;
  5399. this._ignoreDestinationZoom = ignoreDestinationZoom;
  5400. this.baseUrl = null;
  5401. this.pdfDocument = null;
  5402. this.pdfViewer = null;
  5403. this.pdfHistory = null;
  5404. this._pagesRefCache = null;
  5405. }
  5406. setDocument(pdfDocument, baseUrl = null) {
  5407. this.baseUrl = baseUrl;
  5408. this.pdfDocument = pdfDocument;
  5409. this._pagesRefCache = Object.create(null);
  5410. }
  5411. setViewer(pdfViewer) {
  5412. this.pdfViewer = pdfViewer;
  5413. }
  5414. setHistory(pdfHistory) {
  5415. this.pdfHistory = pdfHistory;
  5416. }
  5417. get pagesCount() {
  5418. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  5419. }
  5420. get page() {
  5421. return this.pdfViewer.currentPageNumber;
  5422. }
  5423. set page(value) {
  5424. this.pdfViewer.currentPageNumber = value;
  5425. }
  5426. get rotation() {
  5427. return this.pdfViewer.pagesRotation;
  5428. }
  5429. set rotation(value) {
  5430. this.pdfViewer.pagesRotation = value;
  5431. }
  5432. _goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  5433. const destRef = explicitDest[0];
  5434. let pageNumber;
  5435. if (typeof destRef === "object" && destRef !== null) {
  5436. pageNumber = this._cachedPageNumber(destRef);
  5437. if (!pageNumber) {
  5438. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  5439. this.cachePageRef(pageIndex + 1, destRef);
  5440. this._goToDestinationHelper(rawDest, namedDest, explicitDest);
  5441. }).catch(() => {
  5442. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  5443. });
  5444. return;
  5445. }
  5446. } else if (Number.isInteger(destRef)) {
  5447. pageNumber = destRef + 1;
  5448. } else {
  5449. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  5450. return;
  5451. }
  5452. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  5453. console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  5454. return;
  5455. }
  5456. if (this.pdfHistory) {
  5457. this.pdfHistory.pushCurrentPosition();
  5458. this.pdfHistory.push({
  5459. namedDest,
  5460. explicitDest,
  5461. pageNumber
  5462. });
  5463. }
  5464. this.pdfViewer.scrollPageIntoView({
  5465. pageNumber,
  5466. destArray: explicitDest,
  5467. ignoreDestinationZoom: this._ignoreDestinationZoom
  5468. });
  5469. }
  5470. async goToDestination(dest) {
  5471. if (!this.pdfDocument) {
  5472. return;
  5473. }
  5474. let namedDest, explicitDest;
  5475. if (typeof dest === "string") {
  5476. namedDest = dest;
  5477. explicitDest = await this.pdfDocument.getDestination(dest);
  5478. } else {
  5479. namedDest = null;
  5480. explicitDest = await dest;
  5481. }
  5482. if (!Array.isArray(explicitDest)) {
  5483. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  5484. return;
  5485. }
  5486. this._goToDestinationHelper(dest, namedDest, explicitDest);
  5487. }
  5488. goToPage(val) {
  5489. if (!this.pdfDocument) {
  5490. return;
  5491. }
  5492. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  5493. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  5494. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  5495. return;
  5496. }
  5497. if (this.pdfHistory) {
  5498. this.pdfHistory.pushCurrentPosition();
  5499. this.pdfHistory.pushPage(pageNumber);
  5500. }
  5501. this.pdfViewer.scrollPageIntoView({
  5502. pageNumber
  5503. });
  5504. }
  5505. addLinkAttributes(link, url, newWindow = false) {
  5506. (0, _pdfjsLib.addLinkAttributes)(link, {
  5507. url,
  5508. target: newWindow ? _pdfjsLib.LinkTarget.BLANK : this.externalLinkTarget,
  5509. rel: this.externalLinkRel,
  5510. enabled: this.externalLinkEnabled
  5511. });
  5512. }
  5513. getDestinationHash(dest) {
  5514. if (typeof dest === "string") {
  5515. if (dest.length > 0) {
  5516. return this.getAnchorUrl("#" + escape(dest));
  5517. }
  5518. } else if (Array.isArray(dest)) {
  5519. const str = JSON.stringify(dest);
  5520. if (str.length > 0) {
  5521. return this.getAnchorUrl("#" + escape(str));
  5522. }
  5523. }
  5524. return this.getAnchorUrl("");
  5525. }
  5526. getAnchorUrl(anchor) {
  5527. return (this.baseUrl || "") + anchor;
  5528. }
  5529. setHash(hash) {
  5530. if (!this.pdfDocument) {
  5531. return;
  5532. }
  5533. let pageNumber, dest;
  5534. if (hash.includes("=")) {
  5535. const params = (0, _ui_utils.parseQueryString)(hash);
  5536. if (params.has("search")) {
  5537. this.eventBus.dispatch("findfromurlhash", {
  5538. source: this,
  5539. query: params.get("search").replace(/"/g, ""),
  5540. phraseSearch: params.get("phrase") === "true"
  5541. });
  5542. }
  5543. if (params.has("page")) {
  5544. pageNumber = params.get("page") | 0 || 1;
  5545. }
  5546. if (params.has("zoom")) {
  5547. const zoomArgs = params.get("zoom").split(",");
  5548. const zoomArg = zoomArgs[0];
  5549. const zoomArgNumber = parseFloat(zoomArg);
  5550. if (!zoomArg.includes("Fit")) {
  5551. dest = [null, {
  5552. name: "XYZ"
  5553. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  5554. } else {
  5555. if (zoomArg === "Fit" || zoomArg === "FitB") {
  5556. dest = [null, {
  5557. name: zoomArg
  5558. }];
  5559. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  5560. dest = [null, {
  5561. name: zoomArg
  5562. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  5563. } else if (zoomArg === "FitR") {
  5564. if (zoomArgs.length !== 5) {
  5565. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  5566. } else {
  5567. dest = [null, {
  5568. name: zoomArg
  5569. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  5570. }
  5571. } else {
  5572. console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
  5573. }
  5574. }
  5575. }
  5576. if (dest) {
  5577. this.pdfViewer.scrollPageIntoView({
  5578. pageNumber: pageNumber || this.page,
  5579. destArray: dest,
  5580. allowNegativeOffset: true
  5581. });
  5582. } else if (pageNumber) {
  5583. this.page = pageNumber;
  5584. }
  5585. if (params.has("pagemode")) {
  5586. this.eventBus.dispatch("pagemode", {
  5587. source: this,
  5588. mode: params.get("pagemode")
  5589. });
  5590. }
  5591. if (params.has("nameddest")) {
  5592. this.goToDestination(params.get("nameddest"));
  5593. }
  5594. } else {
  5595. dest = unescape(hash);
  5596. try {
  5597. dest = JSON.parse(dest);
  5598. if (!Array.isArray(dest)) {
  5599. dest = dest.toString();
  5600. }
  5601. } catch (ex) {}
  5602. if (typeof dest === "string" || isValidExplicitDestination(dest)) {
  5603. this.goToDestination(dest);
  5604. return;
  5605. }
  5606. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
  5607. }
  5608. }
  5609. executeNamedAction(action) {
  5610. switch (action) {
  5611. case "GoBack":
  5612. this.pdfHistory?.back();
  5613. break;
  5614. case "GoForward":
  5615. this.pdfHistory?.forward();
  5616. break;
  5617. case "NextPage":
  5618. this.pdfViewer.nextPage();
  5619. break;
  5620. case "PrevPage":
  5621. this.pdfViewer.previousPage();
  5622. break;
  5623. case "LastPage":
  5624. this.page = this.pagesCount;
  5625. break;
  5626. case "FirstPage":
  5627. this.page = 1;
  5628. break;
  5629. default:
  5630. break;
  5631. }
  5632. this.eventBus.dispatch("namedaction", {
  5633. source: this,
  5634. action
  5635. });
  5636. }
  5637. cachePageRef(pageNum, pageRef) {
  5638. if (!pageRef) {
  5639. return;
  5640. }
  5641. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5642. this._pagesRefCache[refStr] = pageNum;
  5643. }
  5644. _cachedPageNumber(pageRef) {
  5645. if (!pageRef) {
  5646. return null;
  5647. }
  5648. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5649. return this._pagesRefCache?.[refStr] || null;
  5650. }
  5651. isPageVisible(pageNumber) {
  5652. return this.pdfViewer.isPageVisible(pageNumber);
  5653. }
  5654. isPageCached(pageNumber) {
  5655. return this.pdfViewer.isPageCached(pageNumber);
  5656. }
  5657. }
  5658. exports.PDFLinkService = PDFLinkService;
  5659. function isValidExplicitDestination(dest) {
  5660. if (!Array.isArray(dest)) {
  5661. return false;
  5662. }
  5663. const destLength = dest.length;
  5664. if (destLength < 2) {
  5665. return false;
  5666. }
  5667. const page = dest[0];
  5668. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  5669. return false;
  5670. }
  5671. const zoom = dest[1];
  5672. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  5673. return false;
  5674. }
  5675. let allowNull = true;
  5676. switch (zoom.name) {
  5677. case "XYZ":
  5678. if (destLength !== 5) {
  5679. return false;
  5680. }
  5681. break;
  5682. case "Fit":
  5683. case "FitB":
  5684. return destLength === 2;
  5685. case "FitH":
  5686. case "FitBH":
  5687. case "FitV":
  5688. case "FitBV":
  5689. if (destLength !== 3) {
  5690. return false;
  5691. }
  5692. break;
  5693. case "FitR":
  5694. if (destLength !== 6) {
  5695. return false;
  5696. }
  5697. allowNull = false;
  5698. break;
  5699. default:
  5700. return false;
  5701. }
  5702. for (let i = 2; i < destLength; i++) {
  5703. const param = dest[i];
  5704. if (!(typeof param === "number" || allowNull && param === null)) {
  5705. return false;
  5706. }
  5707. }
  5708. return true;
  5709. }
  5710. class SimpleLinkService {
  5711. constructor() {
  5712. this.externalLinkEnabled = true;
  5713. }
  5714. get pagesCount() {
  5715. return 0;
  5716. }
  5717. get page() {
  5718. return 0;
  5719. }
  5720. set page(value) {}
  5721. get rotation() {
  5722. return 0;
  5723. }
  5724. set rotation(value) {}
  5725. async goToDestination(dest) {}
  5726. goToPage(val) {}
  5727. addLinkAttributes(link, url, newWindow = false) {
  5728. (0, _pdfjsLib.addLinkAttributes)(link, {
  5729. url,
  5730. enabled: this.externalLinkEnabled
  5731. });
  5732. }
  5733. getDestinationHash(dest) {
  5734. return "#";
  5735. }
  5736. getAnchorUrl(hash) {
  5737. return "#";
  5738. }
  5739. setHash(hash) {}
  5740. executeNamedAction(action) {}
  5741. cachePageRef(pageNum, pageRef) {}
  5742. isPageVisible(pageNumber) {
  5743. return true;
  5744. }
  5745. isPageCached(pageNumber) {
  5746. return true;
  5747. }
  5748. }
  5749. exports.SimpleLinkService = SimpleLinkService;
  5750. /***/ }),
  5751. /* 19 */
  5752. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5753. Object.defineProperty(exports, "__esModule", ({
  5754. value: true
  5755. }));
  5756. exports.PDFOutlineViewer = void 0;
  5757. var _base_tree_viewer = __webpack_require__(11);
  5758. var _pdfjsLib = __webpack_require__(5);
  5759. var _ui_utils = __webpack_require__(3);
  5760. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  5761. constructor(options) {
  5762. super(options);
  5763. this.linkService = options.linkService;
  5764. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  5765. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  5766. this.eventBus._on("pagechanging", evt => {
  5767. this._currentPageNumber = evt.pageNumber;
  5768. });
  5769. this.eventBus._on("pagesloaded", evt => {
  5770. this._isPagesLoaded = !!evt.pagesCount;
  5771. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5772. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  5773. }
  5774. });
  5775. this.eventBus._on("sidebarviewchanged", evt => {
  5776. this._sidebarView = evt.view;
  5777. });
  5778. }
  5779. reset() {
  5780. super.reset();
  5781. this._outline = null;
  5782. this._pageNumberToDestHashCapability = null;
  5783. this._currentPageNumber = 1;
  5784. this._isPagesLoaded = null;
  5785. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5786. this._currentOutlineItemCapability.resolve(false);
  5787. }
  5788. this._currentOutlineItemCapability = null;
  5789. }
  5790. _dispatchEvent(outlineCount) {
  5791. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  5792. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  5793. this._currentOutlineItemCapability.resolve(false);
  5794. } else if (this._isPagesLoaded !== null) {
  5795. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  5796. }
  5797. this.eventBus.dispatch("outlineloaded", {
  5798. source: this,
  5799. outlineCount,
  5800. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  5801. });
  5802. }
  5803. _bindLink(element, {
  5804. url,
  5805. newWindow,
  5806. dest
  5807. }) {
  5808. const {
  5809. linkService
  5810. } = this;
  5811. if (url) {
  5812. linkService.addLinkAttributes(element, url, newWindow);
  5813. return;
  5814. }
  5815. element.href = linkService.getDestinationHash(dest);
  5816. element.onclick = evt => {
  5817. this._updateCurrentTreeItem(evt.target.parentNode);
  5818. if (dest) {
  5819. linkService.goToDestination(dest);
  5820. }
  5821. return false;
  5822. };
  5823. }
  5824. _setStyles(element, {
  5825. bold,
  5826. italic
  5827. }) {
  5828. if (bold) {
  5829. element.style.fontWeight = "bold";
  5830. }
  5831. if (italic) {
  5832. element.style.fontStyle = "italic";
  5833. }
  5834. }
  5835. _addToggleButton(div, {
  5836. count,
  5837. items
  5838. }) {
  5839. let hidden = false;
  5840. if (count < 0) {
  5841. let totalCount = items.length;
  5842. if (totalCount > 0) {
  5843. const queue = [...items];
  5844. while (queue.length > 0) {
  5845. const {
  5846. count: nestedCount,
  5847. items: nestedItems
  5848. } = queue.shift();
  5849. if (nestedCount > 0 && nestedItems.length > 0) {
  5850. totalCount += nestedItems.length;
  5851. queue.push(...nestedItems);
  5852. }
  5853. }
  5854. }
  5855. if (Math.abs(count) === totalCount) {
  5856. hidden = true;
  5857. }
  5858. }
  5859. super._addToggleButton(div, hidden);
  5860. }
  5861. _toggleAllTreeItems() {
  5862. if (!this._outline) {
  5863. return;
  5864. }
  5865. super._toggleAllTreeItems();
  5866. }
  5867. render({
  5868. outline,
  5869. pdfDocument
  5870. }) {
  5871. if (this._outline) {
  5872. this.reset();
  5873. }
  5874. this._outline = outline || null;
  5875. this._pdfDocument = pdfDocument || null;
  5876. if (!outline) {
  5877. this._dispatchEvent(0);
  5878. return;
  5879. }
  5880. const fragment = document.createDocumentFragment();
  5881. const queue = [{
  5882. parent: fragment,
  5883. items: outline
  5884. }];
  5885. let outlineCount = 0,
  5886. hasAnyNesting = false;
  5887. while (queue.length > 0) {
  5888. const levelData = queue.shift();
  5889. for (const item of levelData.items) {
  5890. const div = document.createElement("div");
  5891. div.className = "treeItem";
  5892. const element = document.createElement("a");
  5893. this._bindLink(element, item);
  5894. this._setStyles(element, item);
  5895. element.textContent = this._normalizeTextContent(item.title);
  5896. div.appendChild(element);
  5897. if (item.items.length > 0) {
  5898. hasAnyNesting = true;
  5899. this._addToggleButton(div, item);
  5900. const itemsDiv = document.createElement("div");
  5901. itemsDiv.className = "treeItems";
  5902. div.appendChild(itemsDiv);
  5903. queue.push({
  5904. parent: itemsDiv,
  5905. items: item.items
  5906. });
  5907. }
  5908. levelData.parent.appendChild(div);
  5909. outlineCount++;
  5910. }
  5911. }
  5912. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  5913. }
  5914. async _currentOutlineItem() {
  5915. if (!this._isPagesLoaded) {
  5916. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  5917. }
  5918. if (!this._outline || !this._pdfDocument) {
  5919. return;
  5920. }
  5921. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  5922. if (!pageNumberToDestHash) {
  5923. return;
  5924. }
  5925. this._updateCurrentTreeItem(null);
  5926. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  5927. return;
  5928. }
  5929. for (let i = this._currentPageNumber; i > 0; i--) {
  5930. const destHash = pageNumberToDestHash.get(i);
  5931. if (!destHash) {
  5932. continue;
  5933. }
  5934. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  5935. if (!linkElement) {
  5936. continue;
  5937. }
  5938. this._scrollToCurrentTreeItem(linkElement.parentNode);
  5939. break;
  5940. }
  5941. }
  5942. async _getPageNumberToDestHash(pdfDocument) {
  5943. if (this._pageNumberToDestHashCapability) {
  5944. return this._pageNumberToDestHashCapability.promise;
  5945. }
  5946. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  5947. const pageNumberToDestHash = new Map(),
  5948. pageNumberNesting = new Map();
  5949. const queue = [{
  5950. nesting: 0,
  5951. items: this._outline
  5952. }];
  5953. while (queue.length > 0) {
  5954. const levelData = queue.shift(),
  5955. currentNesting = levelData.nesting;
  5956. for (const {
  5957. dest,
  5958. items
  5959. } of levelData.items) {
  5960. let explicitDest, pageNumber;
  5961. if (typeof dest === "string") {
  5962. explicitDest = await pdfDocument.getDestination(dest);
  5963. if (pdfDocument !== this._pdfDocument) {
  5964. return null;
  5965. }
  5966. } else {
  5967. explicitDest = dest;
  5968. }
  5969. if (Array.isArray(explicitDest)) {
  5970. const [destRef] = explicitDest;
  5971. if (typeof destRef === "object" && destRef !== null) {
  5972. pageNumber = this.linkService._cachedPageNumber(destRef);
  5973. if (!pageNumber) {
  5974. try {
  5975. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  5976. if (pdfDocument !== this._pdfDocument) {
  5977. return null;
  5978. }
  5979. this.linkService.cachePageRef(pageNumber, destRef);
  5980. } catch (ex) {}
  5981. }
  5982. } else if (Number.isInteger(destRef)) {
  5983. pageNumber = destRef + 1;
  5984. }
  5985. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  5986. const destHash = this.linkService.getDestinationHash(dest);
  5987. pageNumberToDestHash.set(pageNumber, destHash);
  5988. pageNumberNesting.set(pageNumber, currentNesting);
  5989. }
  5990. }
  5991. if (items.length > 0) {
  5992. queue.push({
  5993. nesting: currentNesting + 1,
  5994. items
  5995. });
  5996. }
  5997. }
  5998. }
  5999. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6000. return this._pageNumberToDestHashCapability.promise;
  6001. }
  6002. }
  6003. exports.PDFOutlineViewer = PDFOutlineViewer;
  6004. /***/ }),
  6005. /* 20 */
  6006. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6007. Object.defineProperty(exports, "__esModule", ({
  6008. value: true
  6009. }));
  6010. exports.PDFPresentationMode = void 0;
  6011. var _ui_utils = __webpack_require__(3);
  6012. const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  6013. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6014. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6015. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6016. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6017. const PAGE_SWITCH_THRESHOLD = 0.1;
  6018. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6019. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6020. class PDFPresentationMode {
  6021. constructor({
  6022. container,
  6023. pdfViewer,
  6024. eventBus
  6025. }) {
  6026. this.container = container;
  6027. this.pdfViewer = pdfViewer;
  6028. this.eventBus = eventBus;
  6029. this.active = false;
  6030. this.args = null;
  6031. this.contextMenuOpen = false;
  6032. this.mouseScrollTimeStamp = 0;
  6033. this.mouseScrollDelta = 0;
  6034. this.touchSwipeState = null;
  6035. }
  6036. request() {
  6037. if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) {
  6038. return false;
  6039. }
  6040. this._addFullscreenChangeListeners();
  6041. this._setSwitchInProgress();
  6042. this._notifyStateChange();
  6043. if (this.container.requestFullscreen) {
  6044. this.container.requestFullscreen();
  6045. } else if (this.container.mozRequestFullScreen) {
  6046. this.container.mozRequestFullScreen();
  6047. } else if (this.container.webkitRequestFullscreen) {
  6048. this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  6049. } else {
  6050. return false;
  6051. }
  6052. this.args = {
  6053. pageNumber: this.pdfViewer.currentPageNumber,
  6054. scaleValue: this.pdfViewer.currentScaleValue,
  6055. scrollMode: this.pdfViewer.scrollMode,
  6056. spreadMode: this.pdfViewer.spreadMode
  6057. };
  6058. return true;
  6059. }
  6060. _mouseWheel(evt) {
  6061. if (!this.active) {
  6062. return;
  6063. }
  6064. evt.preventDefault();
  6065. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6066. const currentTime = Date.now();
  6067. const storedTime = this.mouseScrollTimeStamp;
  6068. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6069. return;
  6070. }
  6071. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6072. this._resetMouseScrollState();
  6073. }
  6074. this.mouseScrollDelta += delta;
  6075. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6076. const totalDelta = this.mouseScrollDelta;
  6077. this._resetMouseScrollState();
  6078. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6079. if (success) {
  6080. this.mouseScrollTimeStamp = currentTime;
  6081. }
  6082. }
  6083. }
  6084. get isFullscreen() {
  6085. return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen);
  6086. }
  6087. _notifyStateChange() {
  6088. let state = _ui_utils.PresentationModeState.NORMAL;
  6089. if (this.switchInProgress) {
  6090. state = _ui_utils.PresentationModeState.CHANGING;
  6091. } else if (this.active) {
  6092. state = _ui_utils.PresentationModeState.FULLSCREEN;
  6093. }
  6094. this.eventBus.dispatch("presentationmodechanged", {
  6095. source: this,
  6096. state
  6097. });
  6098. }
  6099. _setSwitchInProgress() {
  6100. if (this.switchInProgress) {
  6101. clearTimeout(this.switchInProgress);
  6102. }
  6103. this.switchInProgress = setTimeout(() => {
  6104. this._removeFullscreenChangeListeners();
  6105. delete this.switchInProgress;
  6106. this._notifyStateChange();
  6107. }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  6108. }
  6109. _resetSwitchInProgress() {
  6110. if (this.switchInProgress) {
  6111. clearTimeout(this.switchInProgress);
  6112. delete this.switchInProgress;
  6113. }
  6114. }
  6115. _enter() {
  6116. this.active = true;
  6117. this._resetSwitchInProgress();
  6118. this._notifyStateChange();
  6119. this.container.classList.add(ACTIVE_SELECTOR);
  6120. setTimeout(() => {
  6121. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6122. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6123. this.pdfViewer.currentPageNumber = this.args.pageNumber;
  6124. this.pdfViewer.currentScaleValue = "page-fit";
  6125. }, 0);
  6126. this._addWindowListeners();
  6127. this._showControls();
  6128. this.contextMenuOpen = false;
  6129. window.getSelection().removeAllRanges();
  6130. }
  6131. _exit() {
  6132. const pageNumber = this.pdfViewer.currentPageNumber;
  6133. this.container.classList.remove(ACTIVE_SELECTOR);
  6134. setTimeout(() => {
  6135. this.active = false;
  6136. this._removeFullscreenChangeListeners();
  6137. this._notifyStateChange();
  6138. this.pdfViewer.scrollMode = this.args.scrollMode;
  6139. this.pdfViewer.spreadMode = this.args.spreadMode;
  6140. this.pdfViewer.currentScaleValue = this.args.scaleValue;
  6141. this.pdfViewer.currentPageNumber = pageNumber;
  6142. this.args = null;
  6143. }, 0);
  6144. this._removeWindowListeners();
  6145. this._hideControls();
  6146. this._resetMouseScrollState();
  6147. this.contextMenuOpen = false;
  6148. }
  6149. _mouseDown(evt) {
  6150. if (this.contextMenuOpen) {
  6151. this.contextMenuOpen = false;
  6152. evt.preventDefault();
  6153. return;
  6154. }
  6155. if (evt.button === 0) {
  6156. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6157. if (!isInternalLink) {
  6158. evt.preventDefault();
  6159. if (evt.shiftKey) {
  6160. this.pdfViewer.previousPage();
  6161. } else {
  6162. this.pdfViewer.nextPage();
  6163. }
  6164. }
  6165. }
  6166. }
  6167. _contextMenu() {
  6168. this.contextMenuOpen = true;
  6169. }
  6170. _showControls() {
  6171. if (this.controlsTimeout) {
  6172. clearTimeout(this.controlsTimeout);
  6173. } else {
  6174. this.container.classList.add(CONTROLS_SELECTOR);
  6175. }
  6176. this.controlsTimeout = setTimeout(() => {
  6177. this.container.classList.remove(CONTROLS_SELECTOR);
  6178. delete this.controlsTimeout;
  6179. }, DELAY_BEFORE_HIDING_CONTROLS);
  6180. }
  6181. _hideControls() {
  6182. if (!this.controlsTimeout) {
  6183. return;
  6184. }
  6185. clearTimeout(this.controlsTimeout);
  6186. this.container.classList.remove(CONTROLS_SELECTOR);
  6187. delete this.controlsTimeout;
  6188. }
  6189. _resetMouseScrollState() {
  6190. this.mouseScrollTimeStamp = 0;
  6191. this.mouseScrollDelta = 0;
  6192. }
  6193. _touchSwipe(evt) {
  6194. if (!this.active) {
  6195. return;
  6196. }
  6197. if (evt.touches.length > 1) {
  6198. this.touchSwipeState = null;
  6199. return;
  6200. }
  6201. switch (evt.type) {
  6202. case "touchstart":
  6203. this.touchSwipeState = {
  6204. startX: evt.touches[0].pageX,
  6205. startY: evt.touches[0].pageY,
  6206. endX: evt.touches[0].pageX,
  6207. endY: evt.touches[0].pageY
  6208. };
  6209. break;
  6210. case "touchmove":
  6211. if (this.touchSwipeState === null) {
  6212. return;
  6213. }
  6214. this.touchSwipeState.endX = evt.touches[0].pageX;
  6215. this.touchSwipeState.endY = evt.touches[0].pageY;
  6216. evt.preventDefault();
  6217. break;
  6218. case "touchend":
  6219. if (this.touchSwipeState === null) {
  6220. return;
  6221. }
  6222. let delta = 0;
  6223. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6224. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6225. const absAngle = Math.abs(Math.atan2(dy, dx));
  6226. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6227. delta = dx;
  6228. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6229. delta = dy;
  6230. }
  6231. if (delta > 0) {
  6232. this.pdfViewer.previousPage();
  6233. } else if (delta < 0) {
  6234. this.pdfViewer.nextPage();
  6235. }
  6236. break;
  6237. }
  6238. }
  6239. _addWindowListeners() {
  6240. this.showControlsBind = this._showControls.bind(this);
  6241. this.mouseDownBind = this._mouseDown.bind(this);
  6242. this.mouseWheelBind = this._mouseWheel.bind(this);
  6243. this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
  6244. this.contextMenuBind = this._contextMenu.bind(this);
  6245. this.touchSwipeBind = this._touchSwipe.bind(this);
  6246. window.addEventListener("mousemove", this.showControlsBind);
  6247. window.addEventListener("mousedown", this.mouseDownBind);
  6248. window.addEventListener("wheel", this.mouseWheelBind, {
  6249. passive: false
  6250. });
  6251. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6252. window.addEventListener("contextmenu", this.contextMenuBind);
  6253. window.addEventListener("touchstart", this.touchSwipeBind);
  6254. window.addEventListener("touchmove", this.touchSwipeBind);
  6255. window.addEventListener("touchend", this.touchSwipeBind);
  6256. }
  6257. _removeWindowListeners() {
  6258. window.removeEventListener("mousemove", this.showControlsBind);
  6259. window.removeEventListener("mousedown", this.mouseDownBind);
  6260. window.removeEventListener("wheel", this.mouseWheelBind, {
  6261. passive: false
  6262. });
  6263. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6264. window.removeEventListener("contextmenu", this.contextMenuBind);
  6265. window.removeEventListener("touchstart", this.touchSwipeBind);
  6266. window.removeEventListener("touchmove", this.touchSwipeBind);
  6267. window.removeEventListener("touchend", this.touchSwipeBind);
  6268. delete this.showControlsBind;
  6269. delete this.mouseDownBind;
  6270. delete this.mouseWheelBind;
  6271. delete this.resetMouseScrollStateBind;
  6272. delete this.contextMenuBind;
  6273. delete this.touchSwipeBind;
  6274. }
  6275. _fullscreenChange() {
  6276. if (this.isFullscreen) {
  6277. this._enter();
  6278. } else {
  6279. this._exit();
  6280. }
  6281. }
  6282. _addFullscreenChangeListeners() {
  6283. this.fullscreenChangeBind = this._fullscreenChange.bind(this);
  6284. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6285. window.addEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6286. window.addEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6287. }
  6288. _removeFullscreenChangeListeners() {
  6289. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6290. window.removeEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6291. window.removeEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6292. delete this.fullscreenChangeBind;
  6293. }
  6294. }
  6295. exports.PDFPresentationMode = PDFPresentationMode;
  6296. /***/ }),
  6297. /* 21 */
  6298. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6299. Object.defineProperty(exports, "__esModule", ({
  6300. value: true
  6301. }));
  6302. exports.PDFRenderingQueue = void 0;
  6303. var _pdfjsLib = __webpack_require__(5);
  6304. var _ui_utils = __webpack_require__(3);
  6305. const CLEANUP_TIMEOUT = 30000;
  6306. class PDFRenderingQueue {
  6307. constructor() {
  6308. this.pdfViewer = null;
  6309. this.pdfThumbnailViewer = null;
  6310. this.onIdle = null;
  6311. this.highestPriorityPage = null;
  6312. this.idleTimeout = null;
  6313. this.printing = false;
  6314. this.isThumbnailViewEnabled = false;
  6315. }
  6316. setViewer(pdfViewer) {
  6317. this.pdfViewer = pdfViewer;
  6318. }
  6319. setThumbnailViewer(pdfThumbnailViewer) {
  6320. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6321. }
  6322. isHighestPriority(view) {
  6323. return this.highestPriorityPage === view.renderingId;
  6324. }
  6325. hasViewer() {
  6326. return !!this.pdfViewer;
  6327. }
  6328. renderHighestPriority(currentlyVisiblePages) {
  6329. if (this.idleTimeout) {
  6330. clearTimeout(this.idleTimeout);
  6331. this.idleTimeout = null;
  6332. }
  6333. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6334. return;
  6335. }
  6336. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6337. return;
  6338. }
  6339. if (this.printing) {
  6340. return;
  6341. }
  6342. if (this.onIdle) {
  6343. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6344. }
  6345. }
  6346. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6347. const visibleViews = visible.views,
  6348. numVisible = visibleViews.length;
  6349. if (numVisible === 0) {
  6350. return null;
  6351. }
  6352. for (let i = 0; i < numVisible; i++) {
  6353. const view = visibleViews[i].view;
  6354. if (!this.isViewFinished(view)) {
  6355. return view;
  6356. }
  6357. }
  6358. const firstId = visible.first.id,
  6359. lastId = visible.last.id;
  6360. if (lastId - firstId + 1 > numVisible) {
  6361. const visibleIds = visible.ids;
  6362. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6363. const holeId = scrolledDown ? firstId + i : lastId - i;
  6364. if (visibleIds.has(holeId)) {
  6365. continue;
  6366. }
  6367. const holeView = views[holeId - 1];
  6368. if (!this.isViewFinished(holeView)) {
  6369. return holeView;
  6370. }
  6371. }
  6372. }
  6373. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6374. let preRenderView = views[preRenderIndex];
  6375. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6376. return preRenderView;
  6377. }
  6378. if (preRenderExtra) {
  6379. preRenderIndex += scrolledDown ? 1 : -1;
  6380. preRenderView = views[preRenderIndex];
  6381. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6382. return preRenderView;
  6383. }
  6384. }
  6385. return null;
  6386. }
  6387. isViewFinished(view) {
  6388. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6389. }
  6390. renderView(view) {
  6391. switch (view.renderingState) {
  6392. case _ui_utils.RenderingStates.FINISHED:
  6393. return false;
  6394. case _ui_utils.RenderingStates.PAUSED:
  6395. this.highestPriorityPage = view.renderingId;
  6396. view.resume();
  6397. break;
  6398. case _ui_utils.RenderingStates.RUNNING:
  6399. this.highestPriorityPage = view.renderingId;
  6400. break;
  6401. case _ui_utils.RenderingStates.INITIAL:
  6402. this.highestPriorityPage = view.renderingId;
  6403. view.draw().finally(() => {
  6404. this.renderHighestPriority();
  6405. }).catch(reason => {
  6406. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6407. return;
  6408. }
  6409. console.error(`renderView: "${reason}"`);
  6410. });
  6411. break;
  6412. }
  6413. return true;
  6414. }
  6415. }
  6416. exports.PDFRenderingQueue = PDFRenderingQueue;
  6417. /***/ }),
  6418. /* 22 */
  6419. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6420. Object.defineProperty(exports, "__esModule", ({
  6421. value: true
  6422. }));
  6423. exports.PDFScriptingManager = void 0;
  6424. var _ui_utils = __webpack_require__(3);
  6425. var _pdfjsLib = __webpack_require__(5);
  6426. class PDFScriptingManager {
  6427. constructor({
  6428. eventBus,
  6429. sandboxBundleSrc = null,
  6430. scriptingFactory = null,
  6431. docPropertiesLookup = null
  6432. }) {
  6433. this._pdfDocument = null;
  6434. this._pdfViewer = null;
  6435. this._closeCapability = null;
  6436. this._destroyCapability = null;
  6437. this._scripting = null;
  6438. this._mouseState = Object.create(null);
  6439. this._ready = false;
  6440. this._eventBus = eventBus;
  6441. this._sandboxBundleSrc = sandboxBundleSrc;
  6442. this._scriptingFactory = scriptingFactory;
  6443. this._docPropertiesLookup = docPropertiesLookup;
  6444. }
  6445. setViewer(pdfViewer) {
  6446. this._pdfViewer = pdfViewer;
  6447. }
  6448. async setDocument(pdfDocument) {
  6449. if (this._pdfDocument) {
  6450. await this._destroyScripting();
  6451. }
  6452. this._pdfDocument = pdfDocument;
  6453. if (!pdfDocument) {
  6454. return;
  6455. }
  6456. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6457. if (!objects && !docActions) {
  6458. await this._destroyScripting();
  6459. return;
  6460. }
  6461. if (pdfDocument !== this._pdfDocument) {
  6462. return;
  6463. }
  6464. try {
  6465. this._scripting = this._createScripting();
  6466. } catch (error) {
  6467. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6468. await this._destroyScripting();
  6469. return;
  6470. }
  6471. this._internalEvents.set("updatefromsandbox", event => {
  6472. if (event?.source !== window) {
  6473. return;
  6474. }
  6475. this._updateFromSandbox(event.detail);
  6476. });
  6477. this._internalEvents.set("dispatcheventinsandbox", event => {
  6478. this._scripting?.dispatchEventInSandbox(event.detail);
  6479. });
  6480. this._internalEvents.set("pagechanging", ({
  6481. pageNumber,
  6482. previous
  6483. }) => {
  6484. if (pageNumber === previous) {
  6485. return;
  6486. }
  6487. this._dispatchPageClose(previous);
  6488. this._dispatchPageOpen(pageNumber);
  6489. });
  6490. this._internalEvents.set("pagerendered", ({
  6491. pageNumber
  6492. }) => {
  6493. if (!this._pageOpenPending.has(pageNumber)) {
  6494. return;
  6495. }
  6496. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6497. return;
  6498. }
  6499. this._dispatchPageOpen(pageNumber);
  6500. });
  6501. this._internalEvents.set("pagesdestroy", async event => {
  6502. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6503. await this._scripting?.dispatchEventInSandbox({
  6504. id: "doc",
  6505. name: "WillClose"
  6506. });
  6507. this._closeCapability?.resolve();
  6508. });
  6509. this._domEvents.set("mousedown", event => {
  6510. this._mouseState.isDown = true;
  6511. });
  6512. this._domEvents.set("mouseup", event => {
  6513. this._mouseState.isDown = false;
  6514. });
  6515. for (const [name, listener] of this._internalEvents) {
  6516. this._eventBus._on(name, listener);
  6517. }
  6518. for (const [name, listener] of this._domEvents) {
  6519. window.addEventListener(name, listener);
  6520. }
  6521. try {
  6522. const docProperties = await this._getDocProperties();
  6523. if (pdfDocument !== this._pdfDocument) {
  6524. return;
  6525. }
  6526. await this._scripting.createSandbox({
  6527. objects,
  6528. calculationOrder,
  6529. appInfo: {
  6530. platform: navigator.platform,
  6531. language: navigator.language
  6532. },
  6533. docInfo: { ...docProperties,
  6534. actions: docActions
  6535. }
  6536. });
  6537. this._eventBus.dispatch("sandboxcreated", {
  6538. source: this
  6539. });
  6540. } catch (error) {
  6541. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6542. await this._destroyScripting();
  6543. return;
  6544. }
  6545. await this._scripting?.dispatchEventInSandbox({
  6546. id: "doc",
  6547. name: "Open"
  6548. });
  6549. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6550. Promise.resolve().then(() => {
  6551. if (pdfDocument === this._pdfDocument) {
  6552. this._ready = true;
  6553. }
  6554. });
  6555. }
  6556. async dispatchWillSave(detail) {
  6557. return this._scripting?.dispatchEventInSandbox({
  6558. id: "doc",
  6559. name: "WillSave"
  6560. });
  6561. }
  6562. async dispatchDidSave(detail) {
  6563. return this._scripting?.dispatchEventInSandbox({
  6564. id: "doc",
  6565. name: "DidSave"
  6566. });
  6567. }
  6568. async dispatchWillPrint(detail) {
  6569. return this._scripting?.dispatchEventInSandbox({
  6570. id: "doc",
  6571. name: "WillPrint"
  6572. });
  6573. }
  6574. async dispatchDidPrint(detail) {
  6575. return this._scripting?.dispatchEventInSandbox({
  6576. id: "doc",
  6577. name: "DidPrint"
  6578. });
  6579. }
  6580. get mouseState() {
  6581. return this._mouseState;
  6582. }
  6583. get destroyPromise() {
  6584. return this._destroyCapability?.promise || null;
  6585. }
  6586. get ready() {
  6587. return this._ready;
  6588. }
  6589. get _internalEvents() {
  6590. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6591. }
  6592. get _domEvents() {
  6593. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6594. }
  6595. get _pageOpenPending() {
  6596. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6597. }
  6598. get _visitedPages() {
  6599. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6600. }
  6601. async _updateFromSandbox(detail) {
  6602. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6603. const {
  6604. id,
  6605. siblings,
  6606. command,
  6607. value
  6608. } = detail;
  6609. if (!id) {
  6610. switch (command) {
  6611. case "clear":
  6612. console.clear();
  6613. break;
  6614. case "error":
  6615. console.error(value);
  6616. break;
  6617. case "layout":
  6618. if (isInPresentationMode) {
  6619. return;
  6620. }
  6621. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  6622. this._pdfViewer.spreadMode = modes.spreadMode;
  6623. break;
  6624. case "page-num":
  6625. this._pdfViewer.currentPageNumber = value + 1;
  6626. break;
  6627. case "print":
  6628. await this._pdfViewer.pagesPromise;
  6629. this._eventBus.dispatch("print", {
  6630. source: this
  6631. });
  6632. break;
  6633. case "println":
  6634. console.log(value);
  6635. break;
  6636. case "zoom":
  6637. if (isInPresentationMode) {
  6638. return;
  6639. }
  6640. this._pdfViewer.currentScaleValue = value;
  6641. break;
  6642. case "SaveAs":
  6643. this._eventBus.dispatch("save", {
  6644. source: this
  6645. });
  6646. break;
  6647. case "FirstPage":
  6648. this._pdfViewer.currentPageNumber = 1;
  6649. break;
  6650. case "LastPage":
  6651. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  6652. break;
  6653. case "NextPage":
  6654. this._pdfViewer.nextPage();
  6655. break;
  6656. case "PrevPage":
  6657. this._pdfViewer.previousPage();
  6658. break;
  6659. case "ZoomViewIn":
  6660. if (isInPresentationMode) {
  6661. return;
  6662. }
  6663. this._pdfViewer.increaseScale();
  6664. break;
  6665. case "ZoomViewOut":
  6666. if (isInPresentationMode) {
  6667. return;
  6668. }
  6669. this._pdfViewer.decreaseScale();
  6670. break;
  6671. }
  6672. return;
  6673. }
  6674. if (isInPresentationMode) {
  6675. if (detail.focus) {
  6676. return;
  6677. }
  6678. }
  6679. delete detail.id;
  6680. delete detail.siblings;
  6681. const ids = siblings ? [id, ...siblings] : [id];
  6682. for (const elementId of ids) {
  6683. const element = document.getElementById(elementId);
  6684. if (element) {
  6685. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6686. detail
  6687. }));
  6688. } else {
  6689. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6690. }
  6691. }
  6692. }
  6693. async _dispatchPageOpen(pageNumber, initialize = false) {
  6694. const pdfDocument = this._pdfDocument,
  6695. visitedPages = this._visitedPages;
  6696. if (initialize) {
  6697. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6698. }
  6699. if (!this._closeCapability) {
  6700. return;
  6701. }
  6702. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6703. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  6704. this._pageOpenPending.add(pageNumber);
  6705. return;
  6706. }
  6707. this._pageOpenPending.delete(pageNumber);
  6708. const actionsPromise = (async () => {
  6709. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6710. if (pdfDocument !== this._pdfDocument) {
  6711. return;
  6712. }
  6713. await this._scripting?.dispatchEventInSandbox({
  6714. id: "page",
  6715. name: "PageOpen",
  6716. pageNumber,
  6717. actions
  6718. });
  6719. })();
  6720. visitedPages.set(pageNumber, actionsPromise);
  6721. }
  6722. async _dispatchPageClose(pageNumber) {
  6723. const pdfDocument = this._pdfDocument,
  6724. visitedPages = this._visitedPages;
  6725. if (!this._closeCapability) {
  6726. return;
  6727. }
  6728. if (this._pageOpenPending.has(pageNumber)) {
  6729. return;
  6730. }
  6731. const actionsPromise = visitedPages.get(pageNumber);
  6732. if (!actionsPromise) {
  6733. return;
  6734. }
  6735. visitedPages.set(pageNumber, null);
  6736. await actionsPromise;
  6737. if (pdfDocument !== this._pdfDocument) {
  6738. return;
  6739. }
  6740. await this._scripting?.dispatchEventInSandbox({
  6741. id: "page",
  6742. name: "PageClose",
  6743. pageNumber
  6744. });
  6745. }
  6746. async _getDocProperties() {
  6747. if (this._docPropertiesLookup) {
  6748. return this._docPropertiesLookup(this._pdfDocument);
  6749. }
  6750. throw new Error("_getDocProperties: Unable to lookup properties.");
  6751. }
  6752. _createScripting() {
  6753. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  6754. if (this._scripting) {
  6755. throw new Error("_createScripting: Scripting already exists.");
  6756. }
  6757. if (this._scriptingFactory) {
  6758. return this._scriptingFactory.createScripting({
  6759. sandboxBundleSrc: this._sandboxBundleSrc
  6760. });
  6761. }
  6762. throw new Error("_createScripting: Cannot create scripting.");
  6763. }
  6764. async _destroyScripting() {
  6765. if (!this._scripting) {
  6766. this._pdfDocument = null;
  6767. this._destroyCapability?.resolve();
  6768. return;
  6769. }
  6770. if (this._closeCapability) {
  6771. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  6772. setTimeout(resolve, 1000);
  6773. })]).catch(reason => {});
  6774. this._closeCapability = null;
  6775. }
  6776. this._pdfDocument = null;
  6777. try {
  6778. await this._scripting.destroySandbox();
  6779. } catch (ex) {}
  6780. for (const [name, listener] of this._internalEvents) {
  6781. this._eventBus._off(name, listener);
  6782. }
  6783. this._internalEvents.clear();
  6784. for (const [name, listener] of this._domEvents) {
  6785. window.removeEventListener(name, listener);
  6786. }
  6787. this._domEvents.clear();
  6788. this._pageOpenPending.clear();
  6789. this._visitedPages.clear();
  6790. this._scripting = null;
  6791. delete this._mouseState.isDown;
  6792. this._ready = false;
  6793. this._destroyCapability?.resolve();
  6794. }
  6795. }
  6796. exports.PDFScriptingManager = PDFScriptingManager;
  6797. /***/ }),
  6798. /* 23 */
  6799. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6800. Object.defineProperty(exports, "__esModule", ({
  6801. value: true
  6802. }));
  6803. exports.PDFSidebar = void 0;
  6804. var _ui_utils = __webpack_require__(3);
  6805. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  6806. class PDFSidebar {
  6807. constructor({
  6808. elements,
  6809. pdfViewer,
  6810. pdfThumbnailViewer,
  6811. eventBus,
  6812. l10n
  6813. }) {
  6814. this.isOpen = false;
  6815. this.active = _ui_utils.SidebarView.THUMBS;
  6816. this.isInitialViewSet = false;
  6817. this.onToggled = null;
  6818. this.pdfViewer = pdfViewer;
  6819. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6820. this.outerContainer = elements.outerContainer;
  6821. this.viewerContainer = elements.viewerContainer;
  6822. this.toggleButton = elements.toggleButton;
  6823. this.thumbnailButton = elements.thumbnailButton;
  6824. this.outlineButton = elements.outlineButton;
  6825. this.attachmentsButton = elements.attachmentsButton;
  6826. this.layersButton = elements.layersButton;
  6827. this.thumbnailView = elements.thumbnailView;
  6828. this.outlineView = elements.outlineView;
  6829. this.attachmentsView = elements.attachmentsView;
  6830. this.layersView = elements.layersView;
  6831. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  6832. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  6833. this.eventBus = eventBus;
  6834. this.l10n = l10n;
  6835. this._addEventListeners();
  6836. }
  6837. reset() {
  6838. this.isInitialViewSet = false;
  6839. this._hideUINotification(true);
  6840. this.switchView(_ui_utils.SidebarView.THUMBS);
  6841. this.outlineButton.disabled = false;
  6842. this.attachmentsButton.disabled = false;
  6843. this.layersButton.disabled = false;
  6844. this._currentOutlineItemButton.disabled = true;
  6845. }
  6846. get visibleView() {
  6847. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  6848. }
  6849. get isThumbnailViewVisible() {
  6850. return this.isOpen && this.active === _ui_utils.SidebarView.THUMBS;
  6851. }
  6852. get isOutlineViewVisible() {
  6853. return this.isOpen && this.active === _ui_utils.SidebarView.OUTLINE;
  6854. }
  6855. get isAttachmentsViewVisible() {
  6856. return this.isOpen && this.active === _ui_utils.SidebarView.ATTACHMENTS;
  6857. }
  6858. get isLayersViewVisible() {
  6859. return this.isOpen && this.active === _ui_utils.SidebarView.LAYERS;
  6860. }
  6861. setInitialView(view = _ui_utils.SidebarView.NONE) {
  6862. if (this.isInitialViewSet) {
  6863. return;
  6864. }
  6865. this.isInitialViewSet = true;
  6866. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  6867. this._dispatchEvent();
  6868. return;
  6869. }
  6870. if (!this._switchView(view, true)) {
  6871. this._dispatchEvent();
  6872. }
  6873. }
  6874. switchView(view, forceOpen = false) {
  6875. this._switchView(view, forceOpen);
  6876. }
  6877. _switchView(view, forceOpen = false) {
  6878. const isViewChanged = view !== this.active;
  6879. let shouldForceRendering = false;
  6880. switch (view) {
  6881. case _ui_utils.SidebarView.NONE:
  6882. if (this.isOpen) {
  6883. this.close();
  6884. return true;
  6885. }
  6886. return false;
  6887. case _ui_utils.SidebarView.THUMBS:
  6888. if (this.isOpen && isViewChanged) {
  6889. shouldForceRendering = true;
  6890. }
  6891. break;
  6892. case _ui_utils.SidebarView.OUTLINE:
  6893. if (this.outlineButton.disabled) {
  6894. return false;
  6895. }
  6896. break;
  6897. case _ui_utils.SidebarView.ATTACHMENTS:
  6898. if (this.attachmentsButton.disabled) {
  6899. return false;
  6900. }
  6901. break;
  6902. case _ui_utils.SidebarView.LAYERS:
  6903. if (this.layersButton.disabled) {
  6904. return false;
  6905. }
  6906. break;
  6907. default:
  6908. console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
  6909. return false;
  6910. }
  6911. this.active = view;
  6912. this.thumbnailButton.classList.toggle("toggled", view === _ui_utils.SidebarView.THUMBS);
  6913. this.outlineButton.classList.toggle("toggled", view === _ui_utils.SidebarView.OUTLINE);
  6914. this.attachmentsButton.classList.toggle("toggled", view === _ui_utils.SidebarView.ATTACHMENTS);
  6915. this.layersButton.classList.toggle("toggled", view === _ui_utils.SidebarView.LAYERS);
  6916. this.thumbnailView.classList.toggle("hidden", view !== _ui_utils.SidebarView.THUMBS);
  6917. this.outlineView.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6918. this.attachmentsView.classList.toggle("hidden", view !== _ui_utils.SidebarView.ATTACHMENTS);
  6919. this.layersView.classList.toggle("hidden", view !== _ui_utils.SidebarView.LAYERS);
  6920. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6921. if (forceOpen && !this.isOpen) {
  6922. this.open();
  6923. return true;
  6924. }
  6925. if (shouldForceRendering) {
  6926. this._updateThumbnailViewer();
  6927. this._forceRendering();
  6928. }
  6929. if (isViewChanged) {
  6930. this._dispatchEvent();
  6931. }
  6932. return isViewChanged;
  6933. }
  6934. open() {
  6935. if (this.isOpen) {
  6936. return;
  6937. }
  6938. this.isOpen = true;
  6939. this.toggleButton.classList.add("toggled");
  6940. this.toggleButton.setAttribute("aria-expanded", "true");
  6941. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  6942. if (this.active === _ui_utils.SidebarView.THUMBS) {
  6943. this._updateThumbnailViewer();
  6944. }
  6945. this._forceRendering();
  6946. this._dispatchEvent();
  6947. this._hideUINotification();
  6948. }
  6949. close() {
  6950. if (!this.isOpen) {
  6951. return;
  6952. }
  6953. this.isOpen = false;
  6954. this.toggleButton.classList.remove("toggled");
  6955. this.toggleButton.setAttribute("aria-expanded", "false");
  6956. this.outerContainer.classList.add("sidebarMoving");
  6957. this.outerContainer.classList.remove("sidebarOpen");
  6958. this._forceRendering();
  6959. this._dispatchEvent();
  6960. }
  6961. toggle() {
  6962. if (this.isOpen) {
  6963. this.close();
  6964. } else {
  6965. this.open();
  6966. }
  6967. }
  6968. _dispatchEvent() {
  6969. this.eventBus.dispatch("sidebarviewchanged", {
  6970. source: this,
  6971. view: this.visibleView
  6972. });
  6973. }
  6974. _forceRendering() {
  6975. if (this.onToggled) {
  6976. this.onToggled();
  6977. } else {
  6978. this.pdfViewer.forceRendering();
  6979. this.pdfThumbnailViewer.forceRendering();
  6980. }
  6981. }
  6982. _updateThumbnailViewer() {
  6983. const {
  6984. pdfViewer,
  6985. pdfThumbnailViewer
  6986. } = this;
  6987. const pagesCount = pdfViewer.pagesCount;
  6988. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  6989. const pageView = pdfViewer.getPageView(pageIndex);
  6990. if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) {
  6991. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  6992. thumbnailView.setImage(pageView);
  6993. }
  6994. }
  6995. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  6996. }
  6997. _showUINotification() {
  6998. this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
  6999. this.toggleButton.title = msg;
  7000. });
  7001. if (!this.isOpen) {
  7002. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7003. }
  7004. }
  7005. _hideUINotification(reset = false) {
  7006. if (this.isOpen || reset) {
  7007. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7008. }
  7009. if (reset) {
  7010. this.l10n.get("toggle_sidebar.title").then(msg => {
  7011. this.toggleButton.title = msg;
  7012. });
  7013. }
  7014. }
  7015. _addEventListeners() {
  7016. this.viewerContainer.addEventListener("transitionend", evt => {
  7017. if (evt.target === this.viewerContainer) {
  7018. this.outerContainer.classList.remove("sidebarMoving");
  7019. }
  7020. });
  7021. this.toggleButton.addEventListener("click", () => {
  7022. this.toggle();
  7023. });
  7024. this.thumbnailButton.addEventListener("click", () => {
  7025. this.switchView(_ui_utils.SidebarView.THUMBS);
  7026. });
  7027. this.outlineButton.addEventListener("click", () => {
  7028. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7029. });
  7030. this.outlineButton.addEventListener("dblclick", () => {
  7031. this.eventBus.dispatch("toggleoutlinetree", {
  7032. source: this
  7033. });
  7034. });
  7035. this.attachmentsButton.addEventListener("click", () => {
  7036. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7037. });
  7038. this.layersButton.addEventListener("click", () => {
  7039. this.switchView(_ui_utils.SidebarView.LAYERS);
  7040. });
  7041. this.layersButton.addEventListener("dblclick", () => {
  7042. this.eventBus.dispatch("resetlayers", {
  7043. source: this
  7044. });
  7045. });
  7046. this._currentOutlineItemButton.addEventListener("click", () => {
  7047. this.eventBus.dispatch("currentoutlineitem", {
  7048. source: this
  7049. });
  7050. });
  7051. const onTreeLoaded = (count, button, view) => {
  7052. button.disabled = !count;
  7053. if (count) {
  7054. this._showUINotification();
  7055. } else if (this.active === view) {
  7056. this.switchView(_ui_utils.SidebarView.THUMBS);
  7057. }
  7058. };
  7059. this.eventBus._on("outlineloaded", evt => {
  7060. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7061. evt.currentOutlineItemPromise.then(enabled => {
  7062. if (!this.isInitialViewSet) {
  7063. return;
  7064. }
  7065. this._currentOutlineItemButton.disabled = !enabled;
  7066. });
  7067. });
  7068. this.eventBus._on("attachmentsloaded", evt => {
  7069. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7070. });
  7071. this.eventBus._on("layersloaded", evt => {
  7072. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7073. });
  7074. this.eventBus._on("presentationmodechanged", evt => {
  7075. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.isThumbnailViewVisible) {
  7076. this._updateThumbnailViewer();
  7077. }
  7078. });
  7079. }
  7080. }
  7081. exports.PDFSidebar = PDFSidebar;
  7082. /***/ }),
  7083. /* 24 */
  7084. /***/ ((__unused_webpack_module, exports) => {
  7085. Object.defineProperty(exports, "__esModule", ({
  7086. value: true
  7087. }));
  7088. exports.PDFSidebarResizer = void 0;
  7089. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7090. const SIDEBAR_MIN_WIDTH = 200;
  7091. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7092. class PDFSidebarResizer {
  7093. constructor(options, eventBus, l10n) {
  7094. this.isRTL = false;
  7095. this.sidebarOpen = false;
  7096. this.doc = document.documentElement;
  7097. this._width = null;
  7098. this._outerContainerWidth = null;
  7099. this._boundEvents = Object.create(null);
  7100. this.outerContainer = options.outerContainer;
  7101. this.resizer = options.resizer;
  7102. this.eventBus = eventBus;
  7103. l10n.getDirection().then(dir => {
  7104. this.isRTL = dir === "rtl";
  7105. });
  7106. this._addEventListeners();
  7107. }
  7108. get outerContainerWidth() {
  7109. return this._outerContainerWidth ||= this.outerContainer.clientWidth;
  7110. }
  7111. _updateWidth(width = 0) {
  7112. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7113. if (width > maxWidth) {
  7114. width = maxWidth;
  7115. }
  7116. if (width < SIDEBAR_MIN_WIDTH) {
  7117. width = SIDEBAR_MIN_WIDTH;
  7118. }
  7119. if (width === this._width) {
  7120. return false;
  7121. }
  7122. this._width = width;
  7123. this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7124. return true;
  7125. }
  7126. _mouseMove(evt) {
  7127. let width = evt.clientX;
  7128. if (this.isRTL) {
  7129. width = this.outerContainerWidth - width;
  7130. }
  7131. this._updateWidth(width);
  7132. }
  7133. _mouseUp(evt) {
  7134. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7135. this.eventBus.dispatch("resize", {
  7136. source: this
  7137. });
  7138. const _boundEvents = this._boundEvents;
  7139. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7140. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7141. }
  7142. _addEventListeners() {
  7143. const _boundEvents = this._boundEvents;
  7144. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7145. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7146. this.resizer.addEventListener("mousedown", evt => {
  7147. if (evt.button !== 0) {
  7148. return;
  7149. }
  7150. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7151. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7152. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7153. });
  7154. this.eventBus._on("sidebarviewchanged", evt => {
  7155. this.sidebarOpen = !!evt?.view;
  7156. });
  7157. this.eventBus._on("resize", evt => {
  7158. if (evt?.source !== window) {
  7159. return;
  7160. }
  7161. this._outerContainerWidth = null;
  7162. if (!this._width) {
  7163. return;
  7164. }
  7165. if (!this.sidebarOpen) {
  7166. this._updateWidth(this._width);
  7167. return;
  7168. }
  7169. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7170. const updated = this._updateWidth(this._width);
  7171. Promise.resolve().then(() => {
  7172. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7173. if (updated) {
  7174. this.eventBus.dispatch("resize", {
  7175. source: this
  7176. });
  7177. }
  7178. });
  7179. });
  7180. }
  7181. }
  7182. exports.PDFSidebarResizer = PDFSidebarResizer;
  7183. /***/ }),
  7184. /* 25 */
  7185. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7186. Object.defineProperty(exports, "__esModule", ({
  7187. value: true
  7188. }));
  7189. exports.PDFThumbnailViewer = void 0;
  7190. var _ui_utils = __webpack_require__(3);
  7191. var _pdf_thumbnail_view = __webpack_require__(26);
  7192. const THUMBNAIL_SCROLL_MARGIN = -19;
  7193. const THUMBNAIL_SELECTED_CLASS = "selected";
  7194. class PDFThumbnailViewer {
  7195. constructor({
  7196. container,
  7197. eventBus,
  7198. linkService,
  7199. renderingQueue,
  7200. l10n
  7201. }) {
  7202. this.container = container;
  7203. this.linkService = linkService;
  7204. this.renderingQueue = renderingQueue;
  7205. this.l10n = l10n;
  7206. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7207. this._resetView();
  7208. eventBus._on("optionalcontentconfigchanged", () => {
  7209. this._setImageDisabled = true;
  7210. });
  7211. }
  7212. _scrollUpdated() {
  7213. this.renderingQueue.renderHighestPriority();
  7214. }
  7215. getThumbnail(index) {
  7216. return this._thumbnails[index];
  7217. }
  7218. _getVisibleThumbs() {
  7219. return (0, _ui_utils.getVisibleElements)({
  7220. scrollEl: this.container,
  7221. views: this._thumbnails
  7222. });
  7223. }
  7224. scrollThumbnailIntoView(pageNumber) {
  7225. if (!this.pdfDocument) {
  7226. return;
  7227. }
  7228. const thumbnailView = this._thumbnails[pageNumber - 1];
  7229. if (!thumbnailView) {
  7230. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7231. return;
  7232. }
  7233. if (pageNumber !== this._currentPageNumber) {
  7234. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7235. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7236. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7237. }
  7238. const {
  7239. first,
  7240. last,
  7241. views
  7242. } = this._getVisibleThumbs();
  7243. if (views.length > 0) {
  7244. let shouldScroll = false;
  7245. if (pageNumber <= first.id || pageNumber >= last.id) {
  7246. shouldScroll = true;
  7247. } else {
  7248. for (const {
  7249. id,
  7250. percent
  7251. } of views) {
  7252. if (id !== pageNumber) {
  7253. continue;
  7254. }
  7255. shouldScroll = percent < 100;
  7256. break;
  7257. }
  7258. }
  7259. if (shouldScroll) {
  7260. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7261. top: THUMBNAIL_SCROLL_MARGIN
  7262. });
  7263. }
  7264. }
  7265. this._currentPageNumber = pageNumber;
  7266. }
  7267. get pagesRotation() {
  7268. return this._pagesRotation;
  7269. }
  7270. set pagesRotation(rotation) {
  7271. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7272. throw new Error("Invalid thumbnails rotation angle.");
  7273. }
  7274. if (!this.pdfDocument) {
  7275. return;
  7276. }
  7277. if (this._pagesRotation === rotation) {
  7278. return;
  7279. }
  7280. this._pagesRotation = rotation;
  7281. const updateArgs = {
  7282. rotation
  7283. };
  7284. for (const thumbnail of this._thumbnails) {
  7285. thumbnail.update(updateArgs);
  7286. }
  7287. }
  7288. cleanup() {
  7289. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7290. if (this._thumbnails[i] && this._thumbnails[i].renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7291. this._thumbnails[i].reset();
  7292. }
  7293. }
  7294. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7295. }
  7296. _resetView() {
  7297. this._thumbnails = [];
  7298. this._currentPageNumber = 1;
  7299. this._pageLabels = null;
  7300. this._pagesRotation = 0;
  7301. this._optionalContentConfigPromise = null;
  7302. this._setImageDisabled = false;
  7303. this.container.textContent = "";
  7304. }
  7305. setDocument(pdfDocument) {
  7306. if (this.pdfDocument) {
  7307. this._cancelRendering();
  7308. this._resetView();
  7309. }
  7310. this.pdfDocument = pdfDocument;
  7311. if (!pdfDocument) {
  7312. return;
  7313. }
  7314. const firstPagePromise = pdfDocument.getPage(1);
  7315. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7316. firstPagePromise.then(firstPdfPage => {
  7317. this._optionalContentConfigPromise = optionalContentConfigPromise;
  7318. const pagesCount = pdfDocument.numPages;
  7319. const viewport = firstPdfPage.getViewport({
  7320. scale: 1
  7321. });
  7322. const checkSetImageDisabled = () => {
  7323. return this._setImageDisabled;
  7324. };
  7325. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7326. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7327. container: this.container,
  7328. id: pageNum,
  7329. defaultViewport: viewport.clone(),
  7330. optionalContentConfigPromise,
  7331. linkService: this.linkService,
  7332. renderingQueue: this.renderingQueue,
  7333. checkSetImageDisabled,
  7334. l10n: this.l10n
  7335. });
  7336. this._thumbnails.push(thumbnail);
  7337. }
  7338. const firstThumbnailView = this._thumbnails[0];
  7339. if (firstThumbnailView) {
  7340. firstThumbnailView.setPdfPage(firstPdfPage);
  7341. }
  7342. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7343. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7344. }).catch(reason => {
  7345. console.error("Unable to initialize thumbnail viewer", reason);
  7346. });
  7347. }
  7348. _cancelRendering() {
  7349. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7350. if (this._thumbnails[i]) {
  7351. this._thumbnails[i].cancelRendering();
  7352. }
  7353. }
  7354. }
  7355. setPageLabels(labels) {
  7356. if (!this.pdfDocument) {
  7357. return;
  7358. }
  7359. if (!labels) {
  7360. this._pageLabels = null;
  7361. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7362. this._pageLabels = null;
  7363. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7364. } else {
  7365. this._pageLabels = labels;
  7366. }
  7367. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7368. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7369. }
  7370. }
  7371. async #ensurePdfPageLoaded(thumbView) {
  7372. if (thumbView.pdfPage) {
  7373. return thumbView.pdfPage;
  7374. }
  7375. try {
  7376. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7377. if (!thumbView.pdfPage) {
  7378. thumbView.setPdfPage(pdfPage);
  7379. }
  7380. return pdfPage;
  7381. } catch (reason) {
  7382. console.error("Unable to get page for thumb view", reason);
  7383. return null;
  7384. }
  7385. }
  7386. #getScrollAhead(visible) {
  7387. if (visible.first?.id === 1) {
  7388. return true;
  7389. } else if (visible.last?.id === this._thumbnails.length) {
  7390. return false;
  7391. }
  7392. return this.scroll.down;
  7393. }
  7394. forceRendering() {
  7395. const visibleThumbs = this._getVisibleThumbs();
  7396. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7397. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7398. if (thumbView) {
  7399. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7400. this.renderingQueue.renderView(thumbView);
  7401. });
  7402. return true;
  7403. }
  7404. return false;
  7405. }
  7406. }
  7407. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7408. /***/ }),
  7409. /* 26 */
  7410. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7411. Object.defineProperty(exports, "__esModule", ({
  7412. value: true
  7413. }));
  7414. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7415. var _ui_utils = __webpack_require__(3);
  7416. var _pdfjsLib = __webpack_require__(5);
  7417. const DRAW_UPSCALE_FACTOR = 2;
  7418. const MAX_NUM_SCALING_STEPS = 3;
  7419. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7420. const THUMBNAIL_WIDTH = 98;
  7421. class TempImageFactory {
  7422. static #tempCanvas = null;
  7423. static getCanvas(width, height) {
  7424. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7425. tempCanvas.width = width;
  7426. tempCanvas.height = height;
  7427. tempCanvas.mozOpaque = true;
  7428. const ctx = tempCanvas.getContext("2d", {
  7429. alpha: false
  7430. });
  7431. ctx.save();
  7432. ctx.fillStyle = "rgb(255, 255, 255)";
  7433. ctx.fillRect(0, 0, width, height);
  7434. ctx.restore();
  7435. return [tempCanvas, tempCanvas.getContext("2d")];
  7436. }
  7437. static destroyCanvas() {
  7438. const tempCanvas = this.#tempCanvas;
  7439. if (tempCanvas) {
  7440. tempCanvas.width = 0;
  7441. tempCanvas.height = 0;
  7442. }
  7443. this.#tempCanvas = null;
  7444. }
  7445. }
  7446. exports.TempImageFactory = TempImageFactory;
  7447. class PDFThumbnailView {
  7448. constructor({
  7449. container,
  7450. id,
  7451. defaultViewport,
  7452. optionalContentConfigPromise,
  7453. linkService,
  7454. renderingQueue,
  7455. checkSetImageDisabled,
  7456. l10n
  7457. }) {
  7458. this.id = id;
  7459. this.renderingId = "thumbnail" + id;
  7460. this.pageLabel = null;
  7461. this.pdfPage = null;
  7462. this.rotation = 0;
  7463. this.viewport = defaultViewport;
  7464. this.pdfPageRotate = defaultViewport.rotation;
  7465. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7466. this.linkService = linkService;
  7467. this.renderingQueue = renderingQueue;
  7468. this.renderTask = null;
  7469. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7470. this.resume = null;
  7471. this._checkSetImageDisabled = checkSetImageDisabled || function () {
  7472. return false;
  7473. };
  7474. const pageWidth = this.viewport.width,
  7475. pageHeight = this.viewport.height,
  7476. pageRatio = pageWidth / pageHeight;
  7477. this.canvasWidth = THUMBNAIL_WIDTH;
  7478. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7479. this.scale = this.canvasWidth / pageWidth;
  7480. this.l10n = l10n;
  7481. const anchor = document.createElement("a");
  7482. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7483. this._thumbPageTitle.then(msg => {
  7484. anchor.title = msg;
  7485. });
  7486. anchor.onclick = function () {
  7487. linkService.goToPage(id);
  7488. return false;
  7489. };
  7490. this.anchor = anchor;
  7491. const div = document.createElement("div");
  7492. div.className = "thumbnail";
  7493. div.setAttribute("data-page-number", this.id);
  7494. this.div = div;
  7495. const ring = document.createElement("div");
  7496. ring.className = "thumbnailSelectionRing";
  7497. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7498. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7499. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7500. this.ring = ring;
  7501. div.appendChild(ring);
  7502. anchor.appendChild(div);
  7503. container.appendChild(anchor);
  7504. }
  7505. setPdfPage(pdfPage) {
  7506. this.pdfPage = pdfPage;
  7507. this.pdfPageRotate = pdfPage.rotate;
  7508. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7509. this.viewport = pdfPage.getViewport({
  7510. scale: 1,
  7511. rotation: totalRotation
  7512. });
  7513. this.reset();
  7514. }
  7515. reset() {
  7516. this.cancelRendering();
  7517. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7518. const pageWidth = this.viewport.width,
  7519. pageHeight = this.viewport.height,
  7520. pageRatio = pageWidth / pageHeight;
  7521. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7522. this.scale = this.canvasWidth / pageWidth;
  7523. this.div.removeAttribute("data-loaded");
  7524. const ring = this.ring;
  7525. ring.textContent = "";
  7526. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7527. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7528. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7529. if (this.canvas) {
  7530. this.canvas.width = 0;
  7531. this.canvas.height = 0;
  7532. delete this.canvas;
  7533. }
  7534. if (this.image) {
  7535. this.image.removeAttribute("src");
  7536. delete this.image;
  7537. }
  7538. }
  7539. update({
  7540. rotation = null
  7541. }) {
  7542. if (typeof rotation === "number") {
  7543. this.rotation = rotation;
  7544. }
  7545. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7546. this.viewport = this.viewport.clone({
  7547. scale: 1,
  7548. rotation: totalRotation
  7549. });
  7550. this.reset();
  7551. }
  7552. cancelRendering() {
  7553. if (this.renderTask) {
  7554. this.renderTask.cancel();
  7555. this.renderTask = null;
  7556. }
  7557. this.resume = null;
  7558. }
  7559. _getPageDrawContext(upscaleFactor = 1) {
  7560. const canvas = document.createElement("canvas");
  7561. canvas.mozOpaque = true;
  7562. const ctx = canvas.getContext("2d", {
  7563. alpha: false
  7564. });
  7565. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  7566. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7567. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7568. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7569. return {
  7570. ctx,
  7571. canvas,
  7572. transform
  7573. };
  7574. }
  7575. _convertCanvasToImage(canvas) {
  7576. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7577. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  7578. }
  7579. const reducedCanvas = this._reduceImage(canvas);
  7580. const image = document.createElement("img");
  7581. image.className = "thumbnailImage";
  7582. this._thumbPageCanvas.then(msg => {
  7583. image.setAttribute("aria-label", msg);
  7584. });
  7585. image.style.width = this.canvasWidth + "px";
  7586. image.style.height = this.canvasHeight + "px";
  7587. image.src = reducedCanvas.toDataURL();
  7588. this.image = image;
  7589. this.div.setAttribute("data-loaded", true);
  7590. this.ring.appendChild(image);
  7591. reducedCanvas.width = 0;
  7592. reducedCanvas.height = 0;
  7593. }
  7594. draw() {
  7595. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7596. console.error("Must be in new state before drawing");
  7597. return Promise.resolve();
  7598. }
  7599. const {
  7600. pdfPage
  7601. } = this;
  7602. if (!pdfPage) {
  7603. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7604. return Promise.reject(new Error("pdfPage is not loaded"));
  7605. }
  7606. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7607. const finishRenderTask = async (error = null) => {
  7608. if (renderTask === this.renderTask) {
  7609. this.renderTask = null;
  7610. }
  7611. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7612. return;
  7613. }
  7614. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7615. this._convertCanvasToImage(canvas);
  7616. if (error) {
  7617. throw error;
  7618. }
  7619. };
  7620. const {
  7621. ctx,
  7622. canvas,
  7623. transform
  7624. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7625. const drawViewport = this.viewport.clone({
  7626. scale: DRAW_UPSCALE_FACTOR * this.scale
  7627. });
  7628. const renderContinueCallback = cont => {
  7629. if (!this.renderingQueue.isHighestPriority(this)) {
  7630. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  7631. this.resume = () => {
  7632. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7633. cont();
  7634. };
  7635. return;
  7636. }
  7637. cont();
  7638. };
  7639. const renderContext = {
  7640. canvasContext: ctx,
  7641. transform,
  7642. viewport: drawViewport,
  7643. optionalContentConfigPromise: this._optionalContentConfigPromise
  7644. };
  7645. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7646. renderTask.onContinue = renderContinueCallback;
  7647. const resultPromise = renderTask.promise.then(function () {
  7648. return finishRenderTask(null);
  7649. }, function (error) {
  7650. return finishRenderTask(error);
  7651. });
  7652. resultPromise.finally(() => {
  7653. canvas.width = 0;
  7654. canvas.height = 0;
  7655. const pageCached = this.linkService.isPageCached(this.id);
  7656. if (!pageCached) {
  7657. this.pdfPage?.cleanup();
  7658. }
  7659. });
  7660. return resultPromise;
  7661. }
  7662. setImage(pageView) {
  7663. if (this._checkSetImageDisabled()) {
  7664. return;
  7665. }
  7666. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7667. return;
  7668. }
  7669. const {
  7670. canvas,
  7671. pdfPage
  7672. } = pageView;
  7673. if (!canvas) {
  7674. return;
  7675. }
  7676. if (!this.pdfPage) {
  7677. this.setPdfPage(pdfPage);
  7678. }
  7679. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7680. this._convertCanvasToImage(canvas);
  7681. }
  7682. _reduceImage(img) {
  7683. const {
  7684. ctx,
  7685. canvas
  7686. } = this._getPageDrawContext();
  7687. if (img.width <= 2 * canvas.width) {
  7688. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7689. return canvas;
  7690. }
  7691. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7692. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7693. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7694. while (reducedWidth > img.width || reducedHeight > img.height) {
  7695. reducedWidth >>= 1;
  7696. reducedHeight >>= 1;
  7697. }
  7698. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7699. while (reducedWidth > 2 * canvas.width) {
  7700. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7701. reducedWidth >>= 1;
  7702. reducedHeight >>= 1;
  7703. }
  7704. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7705. return canvas;
  7706. }
  7707. get _thumbPageTitle() {
  7708. return this.l10n.get("thumb_page_title", {
  7709. page: this.pageLabel ?? this.id
  7710. });
  7711. }
  7712. get _thumbPageCanvas() {
  7713. return this.l10n.get("thumb_page_canvas", {
  7714. page: this.pageLabel ?? this.id
  7715. });
  7716. }
  7717. setPageLabel(label) {
  7718. this.pageLabel = typeof label === "string" ? label : null;
  7719. this._thumbPageTitle.then(msg => {
  7720. this.anchor.title = msg;
  7721. });
  7722. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7723. return;
  7724. }
  7725. this._thumbPageCanvas.then(msg => {
  7726. this.image?.setAttribute("aria-label", msg);
  7727. });
  7728. }
  7729. }
  7730. exports.PDFThumbnailView = PDFThumbnailView;
  7731. /***/ }),
  7732. /* 27 */
  7733. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7734. Object.defineProperty(exports, "__esModule", ({
  7735. value: true
  7736. }));
  7737. exports.PDFViewer = exports.PDFSinglePageViewer = void 0;
  7738. var _ui_utils = __webpack_require__(3);
  7739. var _base_viewer = __webpack_require__(28);
  7740. class PDFViewer extends _base_viewer.BaseViewer {}
  7741. exports.PDFViewer = PDFViewer;
  7742. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  7743. _resetView() {
  7744. super._resetView();
  7745. this._scrollMode = _ui_utils.ScrollMode.PAGE;
  7746. this._spreadMode = _ui_utils.SpreadMode.NONE;
  7747. }
  7748. set scrollMode(mode) {}
  7749. _updateScrollMode() {}
  7750. set spreadMode(mode) {}
  7751. _updateSpreadMode() {}
  7752. }
  7753. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  7754. /***/ }),
  7755. /* 28 */
  7756. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7757. Object.defineProperty(exports, "__esModule", ({
  7758. value: true
  7759. }));
  7760. exports.PagesCountLimit = exports.PDFPageViewBuffer = exports.BaseViewer = void 0;
  7761. var _pdfjsLib = __webpack_require__(5);
  7762. var _ui_utils = __webpack_require__(3);
  7763. var _annotation_layer_builder = __webpack_require__(29);
  7764. var _l10n_utils = __webpack_require__(30);
  7765. var _pdf_page_view = __webpack_require__(31);
  7766. var _pdf_rendering_queue = __webpack_require__(21);
  7767. var _pdf_link_service = __webpack_require__(18);
  7768. var _struct_tree_layer_builder = __webpack_require__(32);
  7769. var _text_highlighter = __webpack_require__(33);
  7770. var _text_layer_builder = __webpack_require__(34);
  7771. var _xfa_layer_builder = __webpack_require__(35);
  7772. const DEFAULT_CACHE_SIZE = 10;
  7773. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  7774. const PagesCountLimit = {
  7775. FORCE_SCROLL_MODE_PAGE: 15000,
  7776. FORCE_LAZY_PAGE_INIT: 7500,
  7777. PAUSE_EAGER_PAGE_INIT: 500
  7778. };
  7779. exports.PagesCountLimit = PagesCountLimit;
  7780. class PDFPageViewBuffer {
  7781. #buf = new Set();
  7782. #size = 0;
  7783. constructor(size) {
  7784. this.#size = size;
  7785. }
  7786. push(view) {
  7787. const buf = this.#buf;
  7788. if (buf.has(view)) {
  7789. buf.delete(view);
  7790. }
  7791. buf.add(view);
  7792. if (buf.size > this.#size) {
  7793. this.#destroyFirstView();
  7794. }
  7795. }
  7796. resize(newSize, idsToKeep = null) {
  7797. this.#size = newSize;
  7798. const buf = this.#buf;
  7799. if (idsToKeep) {
  7800. const ii = buf.size;
  7801. let i = 1;
  7802. for (const view of buf) {
  7803. if (idsToKeep.has(view.id)) {
  7804. buf.delete(view);
  7805. buf.add(view);
  7806. }
  7807. if (++i > ii) {
  7808. break;
  7809. }
  7810. }
  7811. }
  7812. while (buf.size > this.#size) {
  7813. this.#destroyFirstView();
  7814. }
  7815. }
  7816. has(view) {
  7817. return this.#buf.has(view);
  7818. }
  7819. [Symbol.iterator]() {
  7820. return this.#buf.keys();
  7821. }
  7822. #destroyFirstView() {
  7823. const firstView = this.#buf.keys().next().value;
  7824. firstView?.destroy();
  7825. this.#buf.delete(firstView);
  7826. }
  7827. }
  7828. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  7829. class BaseViewer {
  7830. #buffer = null;
  7831. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  7832. #previousAnnotationMode = null;
  7833. #enablePermissions = false;
  7834. #previousContainerHeight = 0;
  7835. #scrollModePageState = null;
  7836. constructor(options) {
  7837. if (this.constructor === BaseViewer) {
  7838. throw new Error("Cannot initialize BaseViewer.");
  7839. }
  7840. const viewerVersion = '2.12.313';
  7841. if (_pdfjsLib.version !== viewerVersion) {
  7842. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  7843. }
  7844. this.container = options.container;
  7845. this.viewer = options.viewer || options.container.firstElementChild;
  7846. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  7847. throw new Error("Invalid `container` and/or `viewer` option.");
  7848. }
  7849. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  7850. throw new Error("The `container` must be absolutely positioned.");
  7851. }
  7852. this.eventBus = options.eventBus;
  7853. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  7854. this.downloadManager = options.downloadManager || null;
  7855. this.findController = options.findController || null;
  7856. this._scriptingManager = options.scriptingManager || null;
  7857. this.removePageBorders = options.removePageBorders || false;
  7858. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  7859. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  7860. this.imageResourcesPath = options.imageResourcesPath || "";
  7861. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  7862. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7863. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  7864. this.maxCanvasPixels = options.maxCanvasPixels;
  7865. this.l10n = options.l10n || _l10n_utils.NullL10n;
  7866. this.#enablePermissions = options.enablePermissions || false;
  7867. this.defaultRenderingQueue = !options.renderingQueue;
  7868. if (this.defaultRenderingQueue) {
  7869. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  7870. this.renderingQueue.setViewer(this);
  7871. } else {
  7872. this.renderingQueue = options.renderingQueue;
  7873. }
  7874. this._doc = document.documentElement;
  7875. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  7876. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  7877. this._onBeforeDraw = this._onAfterDraw = null;
  7878. this._resetView();
  7879. if (this.removePageBorders) {
  7880. this.viewer.classList.add("removePageBorders");
  7881. }
  7882. Promise.resolve().then(() => {
  7883. this.eventBus.dispatch("baseviewerinit", {
  7884. source: this
  7885. });
  7886. });
  7887. }
  7888. get pagesCount() {
  7889. return this._pages.length;
  7890. }
  7891. getPageView(index) {
  7892. return this._pages[index];
  7893. }
  7894. get pageViewsReady() {
  7895. if (!this._pagesCapability.settled) {
  7896. return false;
  7897. }
  7898. return this._pages.every(function (pageView) {
  7899. return pageView?.pdfPage;
  7900. });
  7901. }
  7902. get renderForms() {
  7903. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  7904. }
  7905. get enableScripting() {
  7906. return !!this._scriptingManager;
  7907. }
  7908. get currentPageNumber() {
  7909. return this._currentPageNumber;
  7910. }
  7911. set currentPageNumber(val) {
  7912. if (!Number.isInteger(val)) {
  7913. throw new Error("Invalid page number.");
  7914. }
  7915. if (!this.pdfDocument) {
  7916. return;
  7917. }
  7918. if (!this._setCurrentPageNumber(val, true)) {
  7919. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  7920. }
  7921. }
  7922. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  7923. if (this._currentPageNumber === val) {
  7924. if (resetCurrentPageView) {
  7925. this._resetCurrentPageView();
  7926. }
  7927. return true;
  7928. }
  7929. if (!(0 < val && val <= this.pagesCount)) {
  7930. return false;
  7931. }
  7932. const previous = this._currentPageNumber;
  7933. this._currentPageNumber = val;
  7934. this.eventBus.dispatch("pagechanging", {
  7935. source: this,
  7936. pageNumber: val,
  7937. pageLabel: this._pageLabels?.[val - 1] ?? null,
  7938. previous
  7939. });
  7940. if (resetCurrentPageView) {
  7941. this._resetCurrentPageView();
  7942. }
  7943. return true;
  7944. }
  7945. get currentPageLabel() {
  7946. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  7947. }
  7948. set currentPageLabel(val) {
  7949. if (!this.pdfDocument) {
  7950. return;
  7951. }
  7952. let page = val | 0;
  7953. if (this._pageLabels) {
  7954. const i = this._pageLabels.indexOf(val);
  7955. if (i >= 0) {
  7956. page = i + 1;
  7957. }
  7958. }
  7959. if (!this._setCurrentPageNumber(page, true)) {
  7960. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  7961. }
  7962. }
  7963. get currentScale() {
  7964. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  7965. }
  7966. set currentScale(val) {
  7967. if (isNaN(val)) {
  7968. throw new Error("Invalid numeric scale.");
  7969. }
  7970. if (!this.pdfDocument) {
  7971. return;
  7972. }
  7973. this._setScale(val, false);
  7974. }
  7975. get currentScaleValue() {
  7976. return this._currentScaleValue;
  7977. }
  7978. set currentScaleValue(val) {
  7979. if (!this.pdfDocument) {
  7980. return;
  7981. }
  7982. this._setScale(val, false);
  7983. }
  7984. get pagesRotation() {
  7985. return this._pagesRotation;
  7986. }
  7987. set pagesRotation(rotation) {
  7988. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7989. throw new Error("Invalid pages rotation angle.");
  7990. }
  7991. if (!this.pdfDocument) {
  7992. return;
  7993. }
  7994. rotation %= 360;
  7995. if (rotation < 0) {
  7996. rotation += 360;
  7997. }
  7998. if (this._pagesRotation === rotation) {
  7999. return;
  8000. }
  8001. this._pagesRotation = rotation;
  8002. const pageNumber = this._currentPageNumber;
  8003. const updateArgs = {
  8004. rotation
  8005. };
  8006. for (const pageView of this._pages) {
  8007. pageView.update(updateArgs);
  8008. }
  8009. if (this._currentScaleValue) {
  8010. this._setScale(this._currentScaleValue, true);
  8011. }
  8012. this.eventBus.dispatch("rotationchanging", {
  8013. source: this,
  8014. pagesRotation: rotation,
  8015. pageNumber
  8016. });
  8017. if (this.defaultRenderingQueue) {
  8018. this.update();
  8019. }
  8020. }
  8021. get firstPagePromise() {
  8022. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8023. }
  8024. get onePageRendered() {
  8025. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8026. }
  8027. get pagesPromise() {
  8028. return this.pdfDocument ? this._pagesCapability.promise : null;
  8029. }
  8030. #initializePermissions(permissions) {
  8031. if (!permissions) {
  8032. return;
  8033. }
  8034. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  8035. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  8036. }
  8037. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS)) {
  8038. if (this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8039. this.#previousAnnotationMode = this.#annotationMode;
  8040. this.#annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8041. }
  8042. }
  8043. }
  8044. #onePageRenderedOrForceFetch() {
  8045. if (!this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8046. return Promise.resolve();
  8047. }
  8048. return this._onePageRenderedCapability.promise;
  8049. }
  8050. setDocument(pdfDocument) {
  8051. if (this.pdfDocument) {
  8052. this.eventBus.dispatch("pagesdestroy", {
  8053. source: this
  8054. });
  8055. this._cancelRendering();
  8056. this._resetView();
  8057. if (this.findController) {
  8058. this.findController.setDocument(null);
  8059. }
  8060. if (this._scriptingManager) {
  8061. this._scriptingManager.setDocument(null);
  8062. }
  8063. }
  8064. this.pdfDocument = pdfDocument;
  8065. if (!pdfDocument) {
  8066. return;
  8067. }
  8068. const isPureXfa = pdfDocument.isPureXfa;
  8069. const pagesCount = pdfDocument.numPages;
  8070. const firstPagePromise = pdfDocument.getPage(1);
  8071. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8072. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8073. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8074. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8075. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8076. this.eventBus.dispatch("scrollmodechanged", {
  8077. source: this,
  8078. mode
  8079. });
  8080. }
  8081. this._pagesCapability.promise.then(() => {
  8082. this.eventBus.dispatch("pagesloaded", {
  8083. source: this,
  8084. pagesCount
  8085. });
  8086. }, () => {});
  8087. this._onBeforeDraw = evt => {
  8088. const pageView = this._pages[evt.pageNumber - 1];
  8089. if (!pageView) {
  8090. return;
  8091. }
  8092. this.#buffer.push(pageView);
  8093. };
  8094. this.eventBus._on("pagerender", this._onBeforeDraw);
  8095. this._onAfterDraw = evt => {
  8096. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8097. return;
  8098. }
  8099. this._onePageRenderedCapability.resolve({
  8100. timestamp: evt.timestamp
  8101. });
  8102. this.eventBus._off("pagerendered", this._onAfterDraw);
  8103. this._onAfterDraw = null;
  8104. };
  8105. this.eventBus._on("pagerendered", this._onAfterDraw);
  8106. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8107. if (pdfDocument !== this.pdfDocument) {
  8108. return;
  8109. }
  8110. this._firstPageCapability.resolve(firstPdfPage);
  8111. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8112. this.#initializePermissions(permissions);
  8113. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8114. const scale = this.currentScale;
  8115. const viewport = firstPdfPage.getViewport({
  8116. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8117. });
  8118. const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !isPureXfa ? this : null;
  8119. const annotationLayerFactory = this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE ? this : null;
  8120. const xfaLayerFactory = isPureXfa ? this : null;
  8121. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8122. const pageView = new _pdf_page_view.PDFPageView({
  8123. container: viewerElement,
  8124. eventBus: this.eventBus,
  8125. id: pageNum,
  8126. scale,
  8127. defaultViewport: viewport.clone(),
  8128. optionalContentConfigPromise,
  8129. renderingQueue: this.renderingQueue,
  8130. textLayerFactory,
  8131. textLayerMode: this.textLayerMode,
  8132. annotationLayerFactory,
  8133. annotationMode: this.#annotationMode,
  8134. xfaLayerFactory,
  8135. textHighlighterFactory: this,
  8136. structTreeLayerFactory: this,
  8137. imageResourcesPath: this.imageResourcesPath,
  8138. renderer: this.renderer,
  8139. useOnlyCssZoom: this.useOnlyCssZoom,
  8140. maxCanvasPixels: this.maxCanvasPixels,
  8141. l10n: this.l10n
  8142. });
  8143. this._pages.push(pageView);
  8144. }
  8145. const firstPageView = this._pages[0];
  8146. if (firstPageView) {
  8147. firstPageView.setPdfPage(firstPdfPage);
  8148. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8149. }
  8150. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8151. this.#ensurePageViewVisible();
  8152. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8153. this._updateSpreadMode();
  8154. }
  8155. this.#onePageRenderedOrForceFetch().then(async () => {
  8156. if (this.findController) {
  8157. this.findController.setDocument(pdfDocument);
  8158. }
  8159. if (this._scriptingManager) {
  8160. this._scriptingManager.setDocument(pdfDocument);
  8161. }
  8162. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8163. this._pagesCapability.resolve();
  8164. return;
  8165. }
  8166. let getPagesLeft = pagesCount - 1;
  8167. if (getPagesLeft <= 0) {
  8168. this._pagesCapability.resolve();
  8169. return;
  8170. }
  8171. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8172. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8173. const pageView = this._pages[pageNum - 1];
  8174. if (!pageView.pdfPage) {
  8175. pageView.setPdfPage(pdfPage);
  8176. }
  8177. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8178. if (--getPagesLeft === 0) {
  8179. this._pagesCapability.resolve();
  8180. }
  8181. }, reason => {
  8182. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8183. if (--getPagesLeft === 0) {
  8184. this._pagesCapability.resolve();
  8185. }
  8186. });
  8187. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8188. await promise;
  8189. }
  8190. }
  8191. });
  8192. this.eventBus.dispatch("pagesinit", {
  8193. source: this
  8194. });
  8195. pdfDocument.getMetadata().then(({
  8196. info
  8197. }) => {
  8198. if (pdfDocument !== this.pdfDocument) {
  8199. return;
  8200. }
  8201. if (info.Language) {
  8202. this.viewer.lang = info.Language;
  8203. }
  8204. });
  8205. if (this.defaultRenderingQueue) {
  8206. this.update();
  8207. }
  8208. }).catch(reason => {
  8209. console.error("Unable to initialize viewer", reason);
  8210. this._pagesCapability.reject(reason);
  8211. });
  8212. }
  8213. setPageLabels(labels) {
  8214. if (!this.pdfDocument) {
  8215. return;
  8216. }
  8217. if (!labels) {
  8218. this._pageLabels = null;
  8219. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8220. this._pageLabels = null;
  8221. console.error(`setPageLabels: Invalid page labels.`);
  8222. } else {
  8223. this._pageLabels = labels;
  8224. }
  8225. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8226. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8227. }
  8228. }
  8229. _resetView() {
  8230. this._pages = [];
  8231. this._currentPageNumber = 1;
  8232. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8233. this._currentScaleValue = null;
  8234. this._pageLabels = null;
  8235. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8236. this._location = null;
  8237. this._pagesRotation = 0;
  8238. this._optionalContentConfigPromise = null;
  8239. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8240. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8241. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8242. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8243. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8244. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8245. this.#scrollModePageState = {
  8246. previousPageNumber: 1,
  8247. scrollDown: true,
  8248. pages: []
  8249. };
  8250. if (this._onBeforeDraw) {
  8251. this.eventBus._off("pagerender", this._onBeforeDraw);
  8252. this._onBeforeDraw = null;
  8253. }
  8254. if (this._onAfterDraw) {
  8255. this.eventBus._off("pagerendered", this._onAfterDraw);
  8256. this._onAfterDraw = null;
  8257. }
  8258. this.viewer.textContent = "";
  8259. this._updateScrollMode();
  8260. this.viewer.removeAttribute("lang");
  8261. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  8262. if (this.#previousAnnotationMode !== null) {
  8263. this.#annotationMode = this.#previousAnnotationMode;
  8264. this.#previousAnnotationMode = null;
  8265. }
  8266. }
  8267. #ensurePageViewVisible() {
  8268. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8269. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8270. }
  8271. const pageNumber = this._currentPageNumber,
  8272. state = this.#scrollModePageState,
  8273. viewer = this.viewer;
  8274. viewer.textContent = "";
  8275. state.pages.length = 0;
  8276. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8277. const pageView = this._pages[pageNumber - 1];
  8278. if (this.isInPresentationMode) {
  8279. const spread = document.createElement("div");
  8280. spread.className = "spread";
  8281. const dummyPage = document.createElement("div");
  8282. dummyPage.className = "dummyPage";
  8283. dummyPage.style.height = `${this.container.clientHeight}px`;
  8284. spread.appendChild(dummyPage);
  8285. spread.appendChild(pageView.div);
  8286. viewer.appendChild(spread);
  8287. } else {
  8288. viewer.appendChild(pageView.div);
  8289. }
  8290. state.pages.push(pageView);
  8291. } else {
  8292. const pageIndexSet = new Set(),
  8293. parity = this._spreadMode - 1;
  8294. if (pageNumber % 2 !== parity) {
  8295. pageIndexSet.add(pageNumber - 1);
  8296. pageIndexSet.add(pageNumber);
  8297. } else {
  8298. pageIndexSet.add(pageNumber - 2);
  8299. pageIndexSet.add(pageNumber - 1);
  8300. }
  8301. let spread = null;
  8302. for (const i of pageIndexSet) {
  8303. const pageView = this._pages[i];
  8304. if (!pageView) {
  8305. continue;
  8306. }
  8307. if (spread === null) {
  8308. spread = document.createElement("div");
  8309. spread.className = "spread";
  8310. viewer.appendChild(spread);
  8311. } else if (i % 2 === parity) {
  8312. spread = spread.cloneNode(false);
  8313. viewer.appendChild(spread);
  8314. }
  8315. spread.appendChild(pageView.div);
  8316. state.pages.push(pageView);
  8317. }
  8318. }
  8319. state.scrollDown = pageNumber >= state.previousPageNumber;
  8320. state.previousPageNumber = pageNumber;
  8321. }
  8322. _scrollUpdate() {
  8323. if (this.pagesCount === 0) {
  8324. return;
  8325. }
  8326. this.update();
  8327. }
  8328. _scrollIntoView({
  8329. pageDiv,
  8330. pageSpot = null,
  8331. pageNumber = null
  8332. }) {
  8333. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8334. if (pageNumber) {
  8335. this._setCurrentPageNumber(pageNumber);
  8336. }
  8337. this.#ensurePageViewVisible();
  8338. this.update();
  8339. }
  8340. if (!pageSpot && !this.isInPresentationMode) {
  8341. const left = pageDiv.offsetLeft + pageDiv.clientLeft;
  8342. const right = left + pageDiv.clientWidth;
  8343. const {
  8344. scrollLeft,
  8345. clientWidth
  8346. } = this.container;
  8347. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8348. pageSpot = {
  8349. left: 0,
  8350. top: 0
  8351. };
  8352. }
  8353. }
  8354. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  8355. }
  8356. #isSameScale(newScale) {
  8357. if (this.isInPresentationMode && this.container.clientHeight !== this.#previousContainerHeight) {
  8358. return false;
  8359. }
  8360. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8361. }
  8362. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8363. this._currentScaleValue = newValue.toString();
  8364. if (this.#isSameScale(newScale)) {
  8365. if (preset) {
  8366. this.eventBus.dispatch("scalechanging", {
  8367. source: this,
  8368. scale: newScale,
  8369. presetValue: newValue
  8370. });
  8371. }
  8372. return;
  8373. }
  8374. this._doc.style.setProperty("--zoom-factor", newScale);
  8375. this._doc.style.setProperty("--viewport-scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8376. const updateArgs = {
  8377. scale: newScale
  8378. };
  8379. for (const pageView of this._pages) {
  8380. pageView.update(updateArgs);
  8381. }
  8382. this._currentScale = newScale;
  8383. if (!noScroll) {
  8384. let page = this._currentPageNumber,
  8385. dest;
  8386. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8387. page = this._location.pageNumber;
  8388. dest = [null, {
  8389. name: "XYZ"
  8390. }, this._location.left, this._location.top, null];
  8391. }
  8392. this.scrollPageIntoView({
  8393. pageNumber: page,
  8394. destArray: dest,
  8395. allowNegativeOffset: true
  8396. });
  8397. }
  8398. this.eventBus.dispatch("scalechanging", {
  8399. source: this,
  8400. scale: newScale,
  8401. presetValue: preset ? newValue : undefined
  8402. });
  8403. if (this.defaultRenderingQueue) {
  8404. this.update();
  8405. }
  8406. this.#previousContainerHeight = this.container.clientHeight;
  8407. }
  8408. get _pageWidthScaleFactor() {
  8409. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8410. return 2;
  8411. }
  8412. return 1;
  8413. }
  8414. _setScale(value, noScroll = false) {
  8415. let scale = parseFloat(value);
  8416. if (scale > 0) {
  8417. this._setScaleUpdatePages(scale, value, noScroll, false);
  8418. } else {
  8419. const currentPage = this._pages[this._currentPageNumber - 1];
  8420. if (!currentPage) {
  8421. return;
  8422. }
  8423. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8424. vPadding = _ui_utils.VERTICAL_PADDING;
  8425. if (this.isInPresentationMode) {
  8426. hPadding = vPadding = 4;
  8427. } else if (this.removePageBorders) {
  8428. hPadding = vPadding = 0;
  8429. }
  8430. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8431. [hPadding, vPadding] = [vPadding, hPadding];
  8432. }
  8433. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8434. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8435. switch (value) {
  8436. case "page-actual":
  8437. scale = 1;
  8438. break;
  8439. case "page-width":
  8440. scale = pageWidthScale;
  8441. break;
  8442. case "page-height":
  8443. scale = pageHeightScale;
  8444. break;
  8445. case "page-fit":
  8446. scale = Math.min(pageWidthScale, pageHeightScale);
  8447. break;
  8448. case "auto":
  8449. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8450. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8451. break;
  8452. default:
  8453. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  8454. return;
  8455. }
  8456. this._setScaleUpdatePages(scale, value, noScroll, true);
  8457. }
  8458. }
  8459. _resetCurrentPageView() {
  8460. if (this.isInPresentationMode) {
  8461. this._setScale(this._currentScaleValue, true);
  8462. }
  8463. const pageView = this._pages[this._currentPageNumber - 1];
  8464. this._scrollIntoView({
  8465. pageDiv: pageView.div
  8466. });
  8467. }
  8468. pageLabelToPageNumber(label) {
  8469. if (!this._pageLabels) {
  8470. return null;
  8471. }
  8472. const i = this._pageLabels.indexOf(label);
  8473. if (i < 0) {
  8474. return null;
  8475. }
  8476. return i + 1;
  8477. }
  8478. scrollPageIntoView({
  8479. pageNumber,
  8480. destArray = null,
  8481. allowNegativeOffset = false,
  8482. ignoreDestinationZoom = false
  8483. }) {
  8484. if (!this.pdfDocument) {
  8485. return;
  8486. }
  8487. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8488. if (!pageView) {
  8489. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  8490. return;
  8491. }
  8492. if (this.isInPresentationMode || !destArray) {
  8493. this._setCurrentPageNumber(pageNumber, true);
  8494. return;
  8495. }
  8496. let x = 0,
  8497. y = 0;
  8498. let width = 0,
  8499. height = 0,
  8500. widthScale,
  8501. heightScale;
  8502. const changeOrientation = pageView.rotation % 180 !== 0;
  8503. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8504. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8505. let scale = 0;
  8506. switch (destArray[1].name) {
  8507. case "XYZ":
  8508. x = destArray[2];
  8509. y = destArray[3];
  8510. scale = destArray[4];
  8511. x = x !== null ? x : 0;
  8512. y = y !== null ? y : pageHeight;
  8513. break;
  8514. case "Fit":
  8515. case "FitB":
  8516. scale = "page-fit";
  8517. break;
  8518. case "FitH":
  8519. case "FitBH":
  8520. y = destArray[2];
  8521. scale = "page-width";
  8522. if (y === null && this._location) {
  8523. x = this._location.left;
  8524. y = this._location.top;
  8525. } else if (typeof y !== "number" || y < 0) {
  8526. y = pageHeight;
  8527. }
  8528. break;
  8529. case "FitV":
  8530. case "FitBV":
  8531. x = destArray[2];
  8532. width = pageWidth;
  8533. height = pageHeight;
  8534. scale = "page-height";
  8535. break;
  8536. case "FitR":
  8537. x = destArray[2];
  8538. y = destArray[3];
  8539. width = destArray[4] - x;
  8540. height = destArray[5] - y;
  8541. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8542. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8543. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8544. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8545. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8546. break;
  8547. default:
  8548. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  8549. return;
  8550. }
  8551. if (!ignoreDestinationZoom) {
  8552. if (scale && scale !== this._currentScale) {
  8553. this.currentScaleValue = scale;
  8554. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8555. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8556. }
  8557. }
  8558. if (scale === "page-fit" && !destArray[4]) {
  8559. this._scrollIntoView({
  8560. pageDiv: pageView.div,
  8561. pageNumber
  8562. });
  8563. return;
  8564. }
  8565. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8566. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8567. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8568. if (!allowNegativeOffset) {
  8569. left = Math.max(left, 0);
  8570. top = Math.max(top, 0);
  8571. }
  8572. this._scrollIntoView({
  8573. pageDiv: pageView.div,
  8574. pageSpot: {
  8575. left,
  8576. top
  8577. },
  8578. pageNumber
  8579. });
  8580. }
  8581. _updateLocation(firstPage) {
  8582. const currentScale = this._currentScale;
  8583. const currentScaleValue = this._currentScaleValue;
  8584. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8585. const pageNumber = firstPage.id;
  8586. let pdfOpenParams = "#page=" + pageNumber;
  8587. pdfOpenParams += "&zoom=" + normalizedScaleValue;
  8588. const currentPageView = this._pages[pageNumber - 1];
  8589. const container = this.container;
  8590. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8591. const intLeft = Math.round(topLeft[0]);
  8592. const intTop = Math.round(topLeft[1]);
  8593. pdfOpenParams += "," + intLeft + "," + intTop;
  8594. this._location = {
  8595. pageNumber,
  8596. scale: normalizedScaleValue,
  8597. top: intTop,
  8598. left: intLeft,
  8599. rotation: this._pagesRotation,
  8600. pdfOpenParams
  8601. };
  8602. }
  8603. update() {
  8604. const visible = this._getVisiblePages();
  8605. const visiblePages = visible.views,
  8606. numVisiblePages = visiblePages.length;
  8607. if (numVisiblePages === 0) {
  8608. return;
  8609. }
  8610. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8611. this.#buffer.resize(newCacheSize, visible.ids);
  8612. this.renderingQueue.renderHighestPriority(visible);
  8613. if (!this.isInPresentationMode) {
  8614. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  8615. let currentId = this._currentPageNumber;
  8616. let stillFullyVisible = false;
  8617. for (const page of visiblePages) {
  8618. if (page.percent < 100) {
  8619. break;
  8620. }
  8621. if (page.id === currentId && isSimpleLayout) {
  8622. stillFullyVisible = true;
  8623. break;
  8624. }
  8625. }
  8626. if (!stillFullyVisible) {
  8627. currentId = visiblePages[0].id;
  8628. }
  8629. this._setCurrentPageNumber(currentId);
  8630. }
  8631. this._updateLocation(visible.first);
  8632. this.eventBus.dispatch("updateviewarea", {
  8633. source: this,
  8634. location: this._location
  8635. });
  8636. }
  8637. containsElement(element) {
  8638. return this.container.contains(element);
  8639. }
  8640. focus() {
  8641. this.container.focus();
  8642. }
  8643. get _isContainerRtl() {
  8644. return getComputedStyle(this.container).direction === "rtl";
  8645. }
  8646. get isInPresentationMode() {
  8647. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8648. }
  8649. get isChangingPresentationMode() {
  8650. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8651. }
  8652. get isHorizontalScrollbarEnabled() {
  8653. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8654. }
  8655. get isVerticalScrollbarEnabled() {
  8656. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8657. }
  8658. _getCurrentVisiblePage() {
  8659. if (!this.pagesCount) {
  8660. return {
  8661. views: []
  8662. };
  8663. }
  8664. const pageView = this._pages[this._currentPageNumber - 1];
  8665. const element = pageView.div;
  8666. const view = {
  8667. id: pageView.id,
  8668. x: element.offsetLeft + element.clientLeft,
  8669. y: element.offsetTop + element.clientTop,
  8670. view: pageView
  8671. };
  8672. const ids = new Set([pageView.id]);
  8673. return {
  8674. first: view,
  8675. last: view,
  8676. views: [view],
  8677. ids
  8678. };
  8679. }
  8680. _getVisiblePages() {
  8681. if (this.isInPresentationMode) {
  8682. return this._getCurrentVisiblePage();
  8683. }
  8684. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  8685. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  8686. rtl = horizontal && this._isContainerRtl;
  8687. return (0, _ui_utils.getVisibleElements)({
  8688. scrollEl: this.container,
  8689. views,
  8690. sortByVisibility: true,
  8691. horizontal,
  8692. rtl
  8693. });
  8694. }
  8695. isPageVisible(pageNumber) {
  8696. if (!this.pdfDocument) {
  8697. return false;
  8698. }
  8699. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8700. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  8701. return false;
  8702. }
  8703. return this._getVisiblePages().ids.has(pageNumber);
  8704. }
  8705. isPageCached(pageNumber) {
  8706. if (!this.pdfDocument) {
  8707. return false;
  8708. }
  8709. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8710. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  8711. return false;
  8712. }
  8713. const pageView = this._pages[pageNumber - 1];
  8714. return this.#buffer.has(pageView);
  8715. }
  8716. cleanup() {
  8717. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8718. if (this._pages[i] && this._pages[i].renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8719. this._pages[i].reset();
  8720. }
  8721. }
  8722. }
  8723. _cancelRendering() {
  8724. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8725. if (this._pages[i]) {
  8726. this._pages[i].cancelRendering();
  8727. }
  8728. }
  8729. }
  8730. async #ensurePdfPageLoaded(pageView) {
  8731. if (pageView.pdfPage) {
  8732. return pageView.pdfPage;
  8733. }
  8734. try {
  8735. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  8736. if (!pageView.pdfPage) {
  8737. pageView.setPdfPage(pdfPage);
  8738. }
  8739. if (!this.linkService._cachedPageNumber(pdfPage.ref)) {
  8740. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  8741. }
  8742. return pdfPage;
  8743. } catch (reason) {
  8744. console.error("Unable to get page for page view", reason);
  8745. return null;
  8746. }
  8747. }
  8748. #getScrollAhead(visible) {
  8749. if (visible.first?.id === 1) {
  8750. return true;
  8751. } else if (visible.last?.id === this.pagesCount) {
  8752. return false;
  8753. }
  8754. switch (this._scrollMode) {
  8755. case _ui_utils.ScrollMode.PAGE:
  8756. return this.#scrollModePageState.scrollDown;
  8757. case _ui_utils.ScrollMode.HORIZONTAL:
  8758. return this.scroll.right;
  8759. }
  8760. return this.scroll.down;
  8761. }
  8762. #toggleLoadingIconSpinner(visibleIds) {
  8763. for (const id of visibleIds) {
  8764. const pageView = this._pages[id - 1];
  8765. pageView?.toggleLoadingIconSpinner(true);
  8766. }
  8767. for (const pageView of this.#buffer) {
  8768. if (visibleIds.has(pageView.id)) {
  8769. continue;
  8770. }
  8771. pageView.toggleLoadingIconSpinner(false);
  8772. }
  8773. }
  8774. forceRendering(currentlyVisiblePages) {
  8775. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  8776. const scrollAhead = this.#getScrollAhead(visiblePages);
  8777. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  8778. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  8779. this.#toggleLoadingIconSpinner(visiblePages.ids);
  8780. if (pageView) {
  8781. this.#ensurePdfPageLoaded(pageView).then(() => {
  8782. this.renderingQueue.renderView(pageView);
  8783. });
  8784. return true;
  8785. }
  8786. return false;
  8787. }
  8788. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus, highlighter) {
  8789. return new _text_layer_builder.TextLayerBuilder({
  8790. textLayerDiv,
  8791. eventBus,
  8792. pageIndex,
  8793. viewport,
  8794. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection,
  8795. highlighter
  8796. });
  8797. }
  8798. createTextHighlighter(pageIndex, eventBus) {
  8799. return new _text_highlighter.TextHighlighter({
  8800. eventBus,
  8801. pageIndex,
  8802. findController: this.isInPresentationMode ? null : this.findController
  8803. });
  8804. }
  8805. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderForms = true, l10n = _l10n_utils.NullL10n, enableScripting = null, hasJSActionsPromise = null, mouseState = null, fieldObjectsPromise = null, annotationCanvasMap = null) {
  8806. return new _annotation_layer_builder.AnnotationLayerBuilder({
  8807. pageDiv,
  8808. pdfPage,
  8809. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8810. imageResourcesPath,
  8811. renderForms,
  8812. linkService: this.linkService,
  8813. downloadManager: this.downloadManager,
  8814. l10n,
  8815. enableScripting: enableScripting ?? this.enableScripting,
  8816. hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
  8817. fieldObjectsPromise: fieldObjectsPromise || this.pdfDocument?.getFieldObjects(),
  8818. mouseState: mouseState || this._scriptingManager?.mouseState,
  8819. annotationCanvasMap
  8820. });
  8821. }
  8822. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null) {
  8823. return new _xfa_layer_builder.XfaLayerBuilder({
  8824. pageDiv,
  8825. pdfPage,
  8826. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8827. linkService: this.linkService
  8828. });
  8829. }
  8830. createStructTreeLayerBuilder(pdfPage) {
  8831. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  8832. pdfPage
  8833. });
  8834. }
  8835. get hasEqualPageSizes() {
  8836. const firstPageView = this._pages[0];
  8837. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  8838. const pageView = this._pages[i];
  8839. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  8840. return false;
  8841. }
  8842. }
  8843. return true;
  8844. }
  8845. getPagesOverview() {
  8846. return this._pages.map(pageView => {
  8847. const viewport = pageView.pdfPage.getViewport({
  8848. scale: 1
  8849. });
  8850. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  8851. return {
  8852. width: viewport.width,
  8853. height: viewport.height,
  8854. rotation: viewport.rotation
  8855. };
  8856. }
  8857. return {
  8858. width: viewport.height,
  8859. height: viewport.width,
  8860. rotation: (viewport.rotation - 90) % 360
  8861. };
  8862. });
  8863. }
  8864. get optionalContentConfigPromise() {
  8865. if (!this.pdfDocument) {
  8866. return Promise.resolve(null);
  8867. }
  8868. if (!this._optionalContentConfigPromise) {
  8869. return this.pdfDocument.getOptionalContentConfig();
  8870. }
  8871. return this._optionalContentConfigPromise;
  8872. }
  8873. set optionalContentConfigPromise(promise) {
  8874. if (!(promise instanceof Promise)) {
  8875. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  8876. }
  8877. if (!this.pdfDocument) {
  8878. return;
  8879. }
  8880. if (!this._optionalContentConfigPromise) {
  8881. return;
  8882. }
  8883. this._optionalContentConfigPromise = promise;
  8884. const updateArgs = {
  8885. optionalContentConfigPromise: promise
  8886. };
  8887. for (const pageView of this._pages) {
  8888. pageView.update(updateArgs);
  8889. }
  8890. this.update();
  8891. this.eventBus.dispatch("optionalcontentconfigchanged", {
  8892. source: this,
  8893. promise
  8894. });
  8895. }
  8896. get scrollMode() {
  8897. return this._scrollMode;
  8898. }
  8899. set scrollMode(mode) {
  8900. if (this._scrollMode === mode) {
  8901. return;
  8902. }
  8903. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  8904. throw new Error(`Invalid scroll mode: ${mode}`);
  8905. }
  8906. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8907. return;
  8908. }
  8909. this._previousScrollMode = this._scrollMode;
  8910. this._scrollMode = mode;
  8911. this.eventBus.dispatch("scrollmodechanged", {
  8912. source: this,
  8913. mode
  8914. });
  8915. this._updateScrollMode(this._currentPageNumber);
  8916. }
  8917. _updateScrollMode(pageNumber = null) {
  8918. const scrollMode = this._scrollMode,
  8919. viewer = this.viewer;
  8920. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  8921. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  8922. if (!this.pdfDocument || !pageNumber) {
  8923. return;
  8924. }
  8925. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  8926. this.#ensurePageViewVisible();
  8927. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  8928. this._updateSpreadMode();
  8929. }
  8930. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8931. this._setScale(this._currentScaleValue, true);
  8932. }
  8933. this._setCurrentPageNumber(pageNumber, true);
  8934. this.update();
  8935. }
  8936. get spreadMode() {
  8937. return this._spreadMode;
  8938. }
  8939. set spreadMode(mode) {
  8940. if (this._spreadMode === mode) {
  8941. return;
  8942. }
  8943. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  8944. throw new Error(`Invalid spread mode: ${mode}`);
  8945. }
  8946. this._spreadMode = mode;
  8947. this.eventBus.dispatch("spreadmodechanged", {
  8948. source: this,
  8949. mode
  8950. });
  8951. this._updateSpreadMode(this._currentPageNumber);
  8952. }
  8953. _updateSpreadMode(pageNumber = null) {
  8954. if (!this.pdfDocument) {
  8955. return;
  8956. }
  8957. const viewer = this.viewer,
  8958. pages = this._pages;
  8959. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8960. this.#ensurePageViewVisible();
  8961. } else {
  8962. viewer.textContent = "";
  8963. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8964. for (let i = 0, ii = pages.length; i < ii; ++i) {
  8965. viewer.appendChild(pages[i].div);
  8966. }
  8967. } else {
  8968. const parity = this._spreadMode - 1;
  8969. let spread = null;
  8970. for (let i = 0, ii = pages.length; i < ii; ++i) {
  8971. if (spread === null) {
  8972. spread = document.createElement("div");
  8973. spread.className = "spread";
  8974. viewer.appendChild(spread);
  8975. } else if (i % 2 === parity) {
  8976. spread = spread.cloneNode(false);
  8977. viewer.appendChild(spread);
  8978. }
  8979. spread.appendChild(pages[i].div);
  8980. }
  8981. }
  8982. }
  8983. if (!pageNumber) {
  8984. return;
  8985. }
  8986. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8987. this._setScale(this._currentScaleValue, true);
  8988. }
  8989. this._setCurrentPageNumber(pageNumber, true);
  8990. this.update();
  8991. }
  8992. _getPageAdvance(currentPageNumber, previous = false) {
  8993. switch (this._scrollMode) {
  8994. case _ui_utils.ScrollMode.WRAPPED:
  8995. {
  8996. const {
  8997. views
  8998. } = this._getVisiblePages(),
  8999. pageLayout = new Map();
  9000. for (const {
  9001. id,
  9002. y,
  9003. percent,
  9004. widthPercent
  9005. } of views) {
  9006. if (percent === 0 || widthPercent < 100) {
  9007. continue;
  9008. }
  9009. let yArray = pageLayout.get(y);
  9010. if (!yArray) {
  9011. pageLayout.set(y, yArray ||= []);
  9012. }
  9013. yArray.push(id);
  9014. }
  9015. for (const yArray of pageLayout.values()) {
  9016. const currentIndex = yArray.indexOf(currentPageNumber);
  9017. if (currentIndex === -1) {
  9018. continue;
  9019. }
  9020. const numPages = yArray.length;
  9021. if (numPages === 1) {
  9022. break;
  9023. }
  9024. if (previous) {
  9025. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9026. const currentId = yArray[i],
  9027. expectedId = yArray[i + 1] - 1;
  9028. if (currentId < expectedId) {
  9029. return currentPageNumber - expectedId;
  9030. }
  9031. }
  9032. } else {
  9033. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9034. const currentId = yArray[i],
  9035. expectedId = yArray[i - 1] + 1;
  9036. if (currentId > expectedId) {
  9037. return expectedId - currentPageNumber;
  9038. }
  9039. }
  9040. }
  9041. if (previous) {
  9042. const firstId = yArray[0];
  9043. if (firstId < currentPageNumber) {
  9044. return currentPageNumber - firstId + 1;
  9045. }
  9046. } else {
  9047. const lastId = yArray[numPages - 1];
  9048. if (lastId > currentPageNumber) {
  9049. return lastId - currentPageNumber + 1;
  9050. }
  9051. }
  9052. break;
  9053. }
  9054. break;
  9055. }
  9056. case _ui_utils.ScrollMode.HORIZONTAL:
  9057. {
  9058. break;
  9059. }
  9060. case _ui_utils.ScrollMode.PAGE:
  9061. case _ui_utils.ScrollMode.VERTICAL:
  9062. {
  9063. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9064. break;
  9065. }
  9066. const parity = this._spreadMode - 1;
  9067. if (previous && currentPageNumber % 2 !== parity) {
  9068. break;
  9069. } else if (!previous && currentPageNumber % 2 === parity) {
  9070. break;
  9071. }
  9072. const {
  9073. views
  9074. } = this._getVisiblePages(),
  9075. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9076. for (const {
  9077. id,
  9078. percent,
  9079. widthPercent
  9080. } of views) {
  9081. if (id !== expectedId) {
  9082. continue;
  9083. }
  9084. if (percent > 0 && widthPercent === 100) {
  9085. return 2;
  9086. }
  9087. break;
  9088. }
  9089. break;
  9090. }
  9091. }
  9092. return 1;
  9093. }
  9094. nextPage() {
  9095. const currentPageNumber = this._currentPageNumber,
  9096. pagesCount = this.pagesCount;
  9097. if (currentPageNumber >= pagesCount) {
  9098. return false;
  9099. }
  9100. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9101. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9102. return true;
  9103. }
  9104. previousPage() {
  9105. const currentPageNumber = this._currentPageNumber;
  9106. if (currentPageNumber <= 1) {
  9107. return false;
  9108. }
  9109. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9110. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9111. return true;
  9112. }
  9113. increaseScale(steps = 1) {
  9114. let newScale = this._currentScale;
  9115. do {
  9116. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9117. newScale = Math.ceil(newScale * 10) / 10;
  9118. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  9119. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9120. this.currentScaleValue = newScale;
  9121. }
  9122. decreaseScale(steps = 1) {
  9123. let newScale = this._currentScale;
  9124. do {
  9125. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9126. newScale = Math.floor(newScale * 10) / 10;
  9127. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  9128. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9129. this.currentScaleValue = newScale;
  9130. }
  9131. }
  9132. exports.BaseViewer = BaseViewer;
  9133. /***/ }),
  9134. /* 29 */
  9135. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9136. Object.defineProperty(exports, "__esModule", ({
  9137. value: true
  9138. }));
  9139. exports.AnnotationLayerBuilder = void 0;
  9140. var _pdfjsLib = __webpack_require__(5);
  9141. var _l10n_utils = __webpack_require__(30);
  9142. class AnnotationLayerBuilder {
  9143. constructor({
  9144. pageDiv,
  9145. pdfPage,
  9146. linkService,
  9147. downloadManager,
  9148. annotationStorage = null,
  9149. imageResourcesPath = "",
  9150. renderForms = true,
  9151. l10n = _l10n_utils.NullL10n,
  9152. enableScripting = false,
  9153. hasJSActionsPromise = null,
  9154. fieldObjectsPromise = null,
  9155. mouseState = null,
  9156. annotationCanvasMap = null
  9157. }) {
  9158. this.pageDiv = pageDiv;
  9159. this.pdfPage = pdfPage;
  9160. this.linkService = linkService;
  9161. this.downloadManager = downloadManager;
  9162. this.imageResourcesPath = imageResourcesPath;
  9163. this.renderForms = renderForms;
  9164. this.l10n = l10n;
  9165. this.annotationStorage = annotationStorage;
  9166. this.enableScripting = enableScripting;
  9167. this._hasJSActionsPromise = hasJSActionsPromise;
  9168. this._fieldObjectsPromise = fieldObjectsPromise;
  9169. this._mouseState = mouseState;
  9170. this._annotationCanvasMap = annotationCanvasMap;
  9171. this.div = null;
  9172. this._cancelled = false;
  9173. }
  9174. async render(viewport, intent = "display") {
  9175. const [annotations, hasJSActions = false, fieldObjects = null] = await Promise.all([this.pdfPage.getAnnotations({
  9176. intent
  9177. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  9178. if (this._cancelled || annotations.length === 0) {
  9179. return;
  9180. }
  9181. const parameters = {
  9182. viewport: viewport.clone({
  9183. dontFlip: true
  9184. }),
  9185. div: this.div,
  9186. annotations,
  9187. page: this.pdfPage,
  9188. imageResourcesPath: this.imageResourcesPath,
  9189. renderForms: this.renderForms,
  9190. linkService: this.linkService,
  9191. downloadManager: this.downloadManager,
  9192. annotationStorage: this.annotationStorage,
  9193. enableScripting: this.enableScripting,
  9194. hasJSActions,
  9195. fieldObjects,
  9196. mouseState: this._mouseState,
  9197. annotationCanvasMap: this._annotationCanvasMap
  9198. };
  9199. if (this.div) {
  9200. _pdfjsLib.AnnotationLayer.update(parameters);
  9201. } else {
  9202. this.div = document.createElement("div");
  9203. this.div.className = "annotationLayer";
  9204. this.pageDiv.appendChild(this.div);
  9205. parameters.div = this.div;
  9206. _pdfjsLib.AnnotationLayer.render(parameters);
  9207. this.l10n.translate(this.div);
  9208. }
  9209. }
  9210. cancel() {
  9211. this._cancelled = true;
  9212. }
  9213. hide() {
  9214. if (!this.div) {
  9215. return;
  9216. }
  9217. this.div.hidden = true;
  9218. }
  9219. }
  9220. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  9221. /***/ }),
  9222. /* 30 */
  9223. /***/ ((__unused_webpack_module, exports) => {
  9224. Object.defineProperty(exports, "__esModule", ({
  9225. value: true
  9226. }));
  9227. exports.NullL10n = void 0;
  9228. exports.fixupLangCode = fixupLangCode;
  9229. exports.getL10nFallback = getL10nFallback;
  9230. const DEFAULT_L10N_STRINGS = {
  9231. of_pages: "of {{pagesCount}}",
  9232. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9233. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9234. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9235. document_properties_date_string: "{{date}}, {{time}}",
  9236. document_properties_page_size_unit_inches: "in",
  9237. document_properties_page_size_unit_millimeters: "mm",
  9238. document_properties_page_size_orientation_portrait: "portrait",
  9239. document_properties_page_size_orientation_landscape: "landscape",
  9240. document_properties_page_size_name_a3: "A3",
  9241. document_properties_page_size_name_a4: "A4",
  9242. document_properties_page_size_name_letter: "Letter",
  9243. document_properties_page_size_name_legal: "Legal",
  9244. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9245. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9246. document_properties_linearized_yes: "Yes",
  9247. document_properties_linearized_no: "No",
  9248. print_progress_percent: "{{progress}}%",
  9249. "toggle_sidebar.title": "Toggle Sidebar",
  9250. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  9251. additional_layers: "Additional Layers",
  9252. page_landmark: "Page {{page}}",
  9253. thumb_page_title: "Page {{page}}",
  9254. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9255. find_reached_top: "Reached top of document, continued from bottom",
  9256. find_reached_bottom: "Reached end of document, continued from top",
  9257. "find_match_count[one]": "{{current}} of {{total}} match",
  9258. "find_match_count[other]": "{{current}} of {{total}} matches",
  9259. "find_match_count_limit[one]": "More than {{limit}} match",
  9260. "find_match_count_limit[other]": "More than {{limit}} matches",
  9261. find_not_found: "Phrase not found",
  9262. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  9263. error_message: "Message: {{message}}",
  9264. error_stack: "Stack: {{stack}}",
  9265. error_file: "File: {{file}}",
  9266. error_line: "Line: {{line}}",
  9267. rendering_error: "An error occurred while rendering the page.",
  9268. page_scale_width: "Page Width",
  9269. page_scale_fit: "Page Fit",
  9270. page_scale_auto: "Automatic Zoom",
  9271. page_scale_actual: "Actual Size",
  9272. page_scale_percent: "{{scale}}%",
  9273. loading: "Loading…",
  9274. loading_error: "An error occurred while loading the PDF.",
  9275. invalid_file_error: "Invalid or corrupted PDF file.",
  9276. missing_file_error: "Missing PDF file.",
  9277. unexpected_response_error: "Unexpected server response.",
  9278. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9279. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9280. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
  9281. };
  9282. function getL10nFallback(key, args) {
  9283. switch (key) {
  9284. case "find_match_count":
  9285. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9286. break;
  9287. case "find_match_count_limit":
  9288. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9289. break;
  9290. }
  9291. return DEFAULT_L10N_STRINGS[key] || "";
  9292. }
  9293. const PARTIAL_LANG_CODES = {
  9294. en: "en-US",
  9295. es: "es-ES",
  9296. fy: "fy-NL",
  9297. ga: "ga-IE",
  9298. gu: "gu-IN",
  9299. hi: "hi-IN",
  9300. hy: "hy-AM",
  9301. nb: "nb-NO",
  9302. ne: "ne-NP",
  9303. nn: "nn-NO",
  9304. pa: "pa-IN",
  9305. pt: "pt-PT",
  9306. sv: "sv-SE",
  9307. zh: "zh-CN"
  9308. };
  9309. function fixupLangCode(langCode) {
  9310. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9311. }
  9312. function formatL10nValue(text, args) {
  9313. if (!args) {
  9314. return text;
  9315. }
  9316. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9317. return name in args ? args[name] : "{{" + name + "}}";
  9318. });
  9319. }
  9320. const NullL10n = {
  9321. async getLanguage() {
  9322. return "en-us";
  9323. },
  9324. async getDirection() {
  9325. return "ltr";
  9326. },
  9327. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9328. return formatL10nValue(fallback, args);
  9329. },
  9330. async translate(element) {}
  9331. };
  9332. exports.NullL10n = NullL10n;
  9333. /***/ }),
  9334. /* 31 */
  9335. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9336. Object.defineProperty(exports, "__esModule", ({
  9337. value: true
  9338. }));
  9339. exports.PDFPageView = void 0;
  9340. var _pdfjsLib = __webpack_require__(5);
  9341. var _ui_utils = __webpack_require__(3);
  9342. var _app_options = __webpack_require__(1);
  9343. var _l10n_utils = __webpack_require__(30);
  9344. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9345. class PDFPageView {
  9346. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9347. constructor(options) {
  9348. const container = options.container;
  9349. const defaultViewport = options.defaultViewport;
  9350. this.id = options.id;
  9351. this.renderingId = "page" + this.id;
  9352. this.pdfPage = null;
  9353. this.pageLabel = null;
  9354. this.rotation = 0;
  9355. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9356. this.viewport = defaultViewport;
  9357. this.pdfPageRotate = defaultViewport.rotation;
  9358. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9359. this.hasRestrictedScaling = false;
  9360. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9361. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9362. this.imageResourcesPath = options.imageResourcesPath || "";
  9363. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9364. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9365. this.eventBus = options.eventBus;
  9366. this.renderingQueue = options.renderingQueue;
  9367. this.textLayerFactory = options.textLayerFactory;
  9368. this.annotationLayerFactory = options.annotationLayerFactory;
  9369. this.xfaLayerFactory = options.xfaLayerFactory;
  9370. this.textHighlighter = options.textHighlighterFactory?.createTextHighlighter(this.id - 1, this.eventBus);
  9371. this.structTreeLayerFactory = options.structTreeLayerFactory;
  9372. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9373. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9374. this.paintTask = null;
  9375. this.paintedViewportMap = new WeakMap();
  9376. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9377. this.resume = null;
  9378. this._renderError = null;
  9379. this._isStandalone = !this.renderingQueue?.hasViewer();
  9380. this._annotationCanvasMap = null;
  9381. this.annotationLayer = null;
  9382. this.textLayer = null;
  9383. this.zoomLayer = null;
  9384. this.xfaLayer = null;
  9385. this.structTreeLayer = null;
  9386. const div = document.createElement("div");
  9387. div.className = "page";
  9388. div.style.width = Math.floor(this.viewport.width) + "px";
  9389. div.style.height = Math.floor(this.viewport.height) + "px";
  9390. div.setAttribute("data-page-number", this.id);
  9391. div.setAttribute("role", "region");
  9392. this.l10n.get("page_landmark", {
  9393. page: this.id
  9394. }).then(msg => {
  9395. div.setAttribute("aria-label", msg);
  9396. });
  9397. this.div = div;
  9398. container?.appendChild(div);
  9399. }
  9400. setPdfPage(pdfPage) {
  9401. this.pdfPage = pdfPage;
  9402. this.pdfPageRotate = pdfPage.rotate;
  9403. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9404. this.viewport = pdfPage.getViewport({
  9405. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9406. rotation: totalRotation
  9407. });
  9408. this.reset();
  9409. }
  9410. destroy() {
  9411. this.reset();
  9412. if (this.pdfPage) {
  9413. this.pdfPage.cleanup();
  9414. }
  9415. }
  9416. async _renderAnnotationLayer() {
  9417. let error = null;
  9418. try {
  9419. await this.annotationLayer.render(this.viewport, "display");
  9420. } catch (ex) {
  9421. error = ex;
  9422. } finally {
  9423. this.eventBus.dispatch("annotationlayerrendered", {
  9424. source: this,
  9425. pageNumber: this.id,
  9426. error
  9427. });
  9428. }
  9429. }
  9430. async _renderXfaLayer() {
  9431. let error = null;
  9432. try {
  9433. const result = await this.xfaLayer.render(this.viewport, "display");
  9434. if (this.textHighlighter) {
  9435. this._buildXfaTextContentItems(result.textDivs);
  9436. }
  9437. } catch (ex) {
  9438. error = ex;
  9439. } finally {
  9440. this.eventBus.dispatch("xfalayerrendered", {
  9441. source: this,
  9442. pageNumber: this.id,
  9443. error
  9444. });
  9445. }
  9446. }
  9447. async _buildXfaTextContentItems(textDivs) {
  9448. const text = await this.pdfPage.getTextContent();
  9449. const items = [];
  9450. for (const item of text.items) {
  9451. items.push(item.str);
  9452. }
  9453. this.textHighlighter.setTextMapping(textDivs, items);
  9454. this.textHighlighter.enable();
  9455. }
  9456. _resetZoomLayer(removeFromDOM = false) {
  9457. if (!this.zoomLayer) {
  9458. return;
  9459. }
  9460. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9461. this.paintedViewportMap.delete(zoomLayerCanvas);
  9462. zoomLayerCanvas.width = 0;
  9463. zoomLayerCanvas.height = 0;
  9464. if (removeFromDOM) {
  9465. this.zoomLayer.remove();
  9466. }
  9467. this.zoomLayer = null;
  9468. }
  9469. reset({
  9470. keepZoomLayer = false,
  9471. keepAnnotationLayer = false,
  9472. keepXfaLayer = false
  9473. } = {}) {
  9474. this.cancelRendering({
  9475. keepAnnotationLayer,
  9476. keepXfaLayer
  9477. });
  9478. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9479. const div = this.div;
  9480. div.style.width = Math.floor(this.viewport.width) + "px";
  9481. div.style.height = Math.floor(this.viewport.height) + "px";
  9482. const childNodes = div.childNodes,
  9483. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  9484. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  9485. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null;
  9486. for (let i = childNodes.length - 1; i >= 0; i--) {
  9487. const node = childNodes[i];
  9488. switch (node) {
  9489. case zoomLayerNode:
  9490. case annotationLayerNode:
  9491. case xfaLayerNode:
  9492. continue;
  9493. }
  9494. node.remove();
  9495. }
  9496. div.removeAttribute("data-loaded");
  9497. if (annotationLayerNode) {
  9498. this.annotationLayer.hide();
  9499. }
  9500. if (xfaLayerNode) {
  9501. this.xfaLayer.hide();
  9502. }
  9503. if (!zoomLayerNode) {
  9504. if (this.canvas) {
  9505. this.paintedViewportMap.delete(this.canvas);
  9506. this.canvas.width = 0;
  9507. this.canvas.height = 0;
  9508. delete this.canvas;
  9509. }
  9510. this._resetZoomLayer();
  9511. }
  9512. if (this.svg) {
  9513. this.paintedViewportMap.delete(this.svg);
  9514. delete this.svg;
  9515. }
  9516. this.loadingIconDiv = document.createElement("div");
  9517. this.loadingIconDiv.className = "loadingIcon notVisible";
  9518. if (this._isStandalone) {
  9519. this.toggleLoadingIconSpinner(true);
  9520. }
  9521. this.loadingIconDiv.setAttribute("role", "img");
  9522. this.l10n.get("loading").then(msg => {
  9523. this.loadingIconDiv?.setAttribute("aria-label", msg);
  9524. });
  9525. div.appendChild(this.loadingIconDiv);
  9526. }
  9527. update({
  9528. scale = 0,
  9529. rotation = null,
  9530. optionalContentConfigPromise = null
  9531. }) {
  9532. if (typeof arguments[0] !== "object") {
  9533. console.error("PDFPageView.update called with separate parameters, please use an object instead.");
  9534. this.update({
  9535. scale: arguments[0],
  9536. rotation: arguments[1],
  9537. optionalContentConfigPromise: arguments[2]
  9538. });
  9539. return;
  9540. }
  9541. this.scale = scale || this.scale;
  9542. if (typeof rotation === "number") {
  9543. this.rotation = rotation;
  9544. }
  9545. if (optionalContentConfigPromise instanceof Promise) {
  9546. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9547. }
  9548. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9549. const viewportScale = this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9550. this.viewport = this.viewport.clone({
  9551. scale: viewportScale,
  9552. rotation: totalRotation
  9553. });
  9554. if (this._isStandalone) {
  9555. const {
  9556. style
  9557. } = document.documentElement;
  9558. style.setProperty("--zoom-factor", this.scale);
  9559. style.setProperty("--viewport-scale-factor", viewportScale);
  9560. }
  9561. if (this.svg) {
  9562. this.cssTransform({
  9563. target: this.svg,
  9564. redrawAnnotationLayer: true,
  9565. redrawXfaLayer: true
  9566. });
  9567. this.eventBus.dispatch("pagerendered", {
  9568. source: this,
  9569. pageNumber: this.id,
  9570. cssTransform: true,
  9571. timestamp: performance.now(),
  9572. error: this._renderError
  9573. });
  9574. return;
  9575. }
  9576. let isScalingRestricted = false;
  9577. if (this.canvas && this.maxCanvasPixels > 0) {
  9578. const outputScale = this.outputScale;
  9579. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  9580. isScalingRestricted = true;
  9581. }
  9582. }
  9583. if (this.canvas) {
  9584. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  9585. this.cssTransform({
  9586. target: this.canvas,
  9587. redrawAnnotationLayer: true,
  9588. redrawXfaLayer: true
  9589. });
  9590. this.eventBus.dispatch("pagerendered", {
  9591. source: this,
  9592. pageNumber: this.id,
  9593. cssTransform: true,
  9594. timestamp: performance.now(),
  9595. error: this._renderError
  9596. });
  9597. return;
  9598. }
  9599. if (!this.zoomLayer && !this.canvas.hidden) {
  9600. this.zoomLayer = this.canvas.parentNode;
  9601. this.zoomLayer.style.position = "absolute";
  9602. }
  9603. }
  9604. if (this.zoomLayer) {
  9605. this.cssTransform({
  9606. target: this.zoomLayer.firstChild
  9607. });
  9608. }
  9609. this.reset({
  9610. keepZoomLayer: true,
  9611. keepAnnotationLayer: true,
  9612. keepXfaLayer: true
  9613. });
  9614. }
  9615. cancelRendering({
  9616. keepAnnotationLayer = false,
  9617. keepXfaLayer = false
  9618. } = {}) {
  9619. if (this.paintTask) {
  9620. this.paintTask.cancel();
  9621. this.paintTask = null;
  9622. }
  9623. this.resume = null;
  9624. if (this.textLayer) {
  9625. this.textLayer.cancel();
  9626. this.textLayer = null;
  9627. }
  9628. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  9629. this.annotationLayer.cancel();
  9630. this.annotationLayer = null;
  9631. this._annotationCanvasMap = null;
  9632. }
  9633. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  9634. this.xfaLayer.cancel();
  9635. this.xfaLayer = null;
  9636. this.textHighlighter?.disable();
  9637. }
  9638. if (this._onTextLayerRendered) {
  9639. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9640. this._onTextLayerRendered = null;
  9641. }
  9642. }
  9643. cssTransform({
  9644. target,
  9645. redrawAnnotationLayer = false,
  9646. redrawXfaLayer = false
  9647. }) {
  9648. const width = this.viewport.width;
  9649. const height = this.viewport.height;
  9650. const div = this.div;
  9651. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  9652. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  9653. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  9654. const absRotation = Math.abs(relativeRotation);
  9655. let scaleX = 1,
  9656. scaleY = 1;
  9657. if (absRotation === 90 || absRotation === 270) {
  9658. scaleX = height / width;
  9659. scaleY = width / height;
  9660. }
  9661. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  9662. if (this.textLayer) {
  9663. const textLayerViewport = this.textLayer.viewport;
  9664. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  9665. const textAbsRotation = Math.abs(textRelativeRotation);
  9666. let scale = width / textLayerViewport.width;
  9667. if (textAbsRotation === 90 || textAbsRotation === 270) {
  9668. scale = width / textLayerViewport.height;
  9669. }
  9670. const textLayerDiv = this.textLayer.textLayerDiv;
  9671. let transX, transY;
  9672. switch (textAbsRotation) {
  9673. case 0:
  9674. transX = transY = 0;
  9675. break;
  9676. case 90:
  9677. transX = 0;
  9678. transY = "-" + textLayerDiv.style.height;
  9679. break;
  9680. case 180:
  9681. transX = "-" + textLayerDiv.style.width;
  9682. transY = "-" + textLayerDiv.style.height;
  9683. break;
  9684. case 270:
  9685. transX = "-" + textLayerDiv.style.width;
  9686. transY = 0;
  9687. break;
  9688. default:
  9689. console.error("Bad rotation value.");
  9690. break;
  9691. }
  9692. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  9693. textLayerDiv.style.transformOrigin = "0% 0%";
  9694. }
  9695. if (redrawAnnotationLayer && this.annotationLayer) {
  9696. this._renderAnnotationLayer();
  9697. }
  9698. if (redrawXfaLayer && this.xfaLayer) {
  9699. this._renderXfaLayer();
  9700. }
  9701. }
  9702. get width() {
  9703. return this.viewport.width;
  9704. }
  9705. get height() {
  9706. return this.viewport.height;
  9707. }
  9708. getPagePoint(x, y) {
  9709. return this.viewport.convertToPdfPoint(x, y);
  9710. }
  9711. toggleLoadingIconSpinner(viewVisible = false) {
  9712. this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
  9713. }
  9714. draw() {
  9715. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  9716. console.error("Must be in new state before drawing");
  9717. this.reset();
  9718. }
  9719. const {
  9720. div,
  9721. pdfPage
  9722. } = this;
  9723. if (!pdfPage) {
  9724. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9725. if (this.loadingIconDiv) {
  9726. this.loadingIconDiv.remove();
  9727. delete this.loadingIconDiv;
  9728. }
  9729. return Promise.reject(new Error("pdfPage is not loaded"));
  9730. }
  9731. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  9732. const canvasWrapper = document.createElement("div");
  9733. canvasWrapper.style.width = div.style.width;
  9734. canvasWrapper.style.height = div.style.height;
  9735. canvasWrapper.classList.add("canvasWrapper");
  9736. if (this.annotationLayer?.div) {
  9737. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  9738. } else {
  9739. div.appendChild(canvasWrapper);
  9740. }
  9741. let textLayer = null;
  9742. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  9743. const textLayerDiv = document.createElement("div");
  9744. textLayerDiv.className = "textLayer";
  9745. textLayerDiv.style.width = canvasWrapper.style.width;
  9746. textLayerDiv.style.height = canvasWrapper.style.height;
  9747. if (this.annotationLayer?.div) {
  9748. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  9749. } else {
  9750. div.appendChild(textLayerDiv);
  9751. }
  9752. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus, this.textHighlighter);
  9753. }
  9754. this.textLayer = textLayer;
  9755. if (this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE && this.annotationLayerFactory) {
  9756. this._annotationCanvasMap ||= new Map();
  9757. this.annotationLayer ||= this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS, this.l10n, null, null, null, null, this._annotationCanvasMap);
  9758. }
  9759. if (this.xfaLayer?.div) {
  9760. div.appendChild(this.xfaLayer.div);
  9761. }
  9762. let renderContinueCallback = null;
  9763. if (this.renderingQueue) {
  9764. renderContinueCallback = cont => {
  9765. if (!this.renderingQueue.isHighestPriority(this)) {
  9766. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  9767. this.resume = () => {
  9768. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  9769. cont();
  9770. };
  9771. return;
  9772. }
  9773. cont();
  9774. };
  9775. }
  9776. const finishPaintTask = async (error = null) => {
  9777. if (paintTask === this.paintTask) {
  9778. this.paintTask = null;
  9779. }
  9780. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  9781. this._renderError = null;
  9782. return;
  9783. }
  9784. this._renderError = error;
  9785. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9786. if (this.loadingIconDiv) {
  9787. this.loadingIconDiv.remove();
  9788. delete this.loadingIconDiv;
  9789. }
  9790. this._resetZoomLayer(true);
  9791. this.eventBus.dispatch("pagerendered", {
  9792. source: this,
  9793. pageNumber: this.id,
  9794. cssTransform: false,
  9795. timestamp: performance.now(),
  9796. error: this._renderError
  9797. });
  9798. if (error) {
  9799. throw error;
  9800. }
  9801. };
  9802. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  9803. paintTask.onRenderContinue = renderContinueCallback;
  9804. this.paintTask = paintTask;
  9805. const resultPromise = paintTask.promise.then(() => {
  9806. return finishPaintTask(null).then(() => {
  9807. if (textLayer) {
  9808. const readableStream = pdfPage.streamTextContent({
  9809. normalizeWhitespace: true,
  9810. includeMarkedContent: true
  9811. });
  9812. textLayer.setTextContentStream(readableStream);
  9813. textLayer.render();
  9814. }
  9815. if (this.annotationLayer) {
  9816. this._renderAnnotationLayer();
  9817. }
  9818. });
  9819. }, function (reason) {
  9820. return finishPaintTask(reason);
  9821. });
  9822. if (this.xfaLayerFactory) {
  9823. if (!this.xfaLayer) {
  9824. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage, null);
  9825. }
  9826. this._renderXfaLayer();
  9827. }
  9828. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  9829. this._onTextLayerRendered = event => {
  9830. if (event.pageNumber !== this.id) {
  9831. return;
  9832. }
  9833. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9834. this._onTextLayerRendered = null;
  9835. if (!this.canvas) {
  9836. return;
  9837. }
  9838. this.pdfPage.getStructTree().then(tree => {
  9839. if (!tree) {
  9840. return;
  9841. }
  9842. if (!this.canvas) {
  9843. return;
  9844. }
  9845. const treeDom = this.structTreeLayer.render(tree);
  9846. treeDom.classList.add("structTree");
  9847. this.canvas.appendChild(treeDom);
  9848. });
  9849. };
  9850. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  9851. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder(pdfPage);
  9852. }
  9853. div.setAttribute("data-loaded", true);
  9854. this.eventBus.dispatch("pagerender", {
  9855. source: this,
  9856. pageNumber: this.id
  9857. });
  9858. return resultPromise;
  9859. }
  9860. paintOnCanvas(canvasWrapper) {
  9861. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  9862. const result = {
  9863. promise: renderCapability.promise,
  9864. onRenderContinue(cont) {
  9865. cont();
  9866. },
  9867. cancel() {
  9868. renderTask.cancel();
  9869. }
  9870. };
  9871. const viewport = this.viewport;
  9872. const canvas = document.createElement("canvas");
  9873. canvas.hidden = true;
  9874. let isCanvasHidden = true;
  9875. const showCanvas = function () {
  9876. if (isCanvasHidden) {
  9877. canvas.hidden = false;
  9878. isCanvasHidden = false;
  9879. }
  9880. };
  9881. canvasWrapper.appendChild(canvas);
  9882. this.canvas = canvas;
  9883. canvas.mozOpaque = true;
  9884. const ctx = canvas.getContext("2d", {
  9885. alpha: false
  9886. });
  9887. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  9888. this.outputScale = outputScale;
  9889. if (this.useOnlyCssZoom) {
  9890. const actualSizeViewport = viewport.clone({
  9891. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  9892. });
  9893. outputScale.sx *= actualSizeViewport.width / viewport.width;
  9894. outputScale.sy *= actualSizeViewport.height / viewport.height;
  9895. outputScale.scaled = true;
  9896. }
  9897. if (this.maxCanvasPixels > 0) {
  9898. const pixelsInViewport = viewport.width * viewport.height;
  9899. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  9900. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  9901. outputScale.sx = maxScale;
  9902. outputScale.sy = maxScale;
  9903. outputScale.scaled = true;
  9904. this.hasRestrictedScaling = true;
  9905. } else {
  9906. this.hasRestrictedScaling = false;
  9907. }
  9908. }
  9909. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  9910. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  9911. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  9912. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  9913. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  9914. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  9915. this.paintedViewportMap.set(canvas, viewport);
  9916. const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  9917. const renderContext = {
  9918. canvasContext: ctx,
  9919. transform,
  9920. viewport: this.viewport,
  9921. annotationMode: this.#annotationMode,
  9922. optionalContentConfigPromise: this._optionalContentConfigPromise,
  9923. annotationCanvasMap: this._annotationCanvasMap
  9924. };
  9925. const renderTask = this.pdfPage.render(renderContext);
  9926. renderTask.onContinue = function (cont) {
  9927. showCanvas();
  9928. if (result.onRenderContinue) {
  9929. result.onRenderContinue(cont);
  9930. } else {
  9931. cont();
  9932. }
  9933. };
  9934. renderTask.promise.then(function () {
  9935. showCanvas();
  9936. renderCapability.resolve();
  9937. }, function (error) {
  9938. showCanvas();
  9939. renderCapability.reject(error);
  9940. });
  9941. return result;
  9942. }
  9943. paintOnSvg(wrapper) {
  9944. let cancelled = false;
  9945. const ensureNotCancelled = () => {
  9946. if (cancelled) {
  9947. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  9948. }
  9949. };
  9950. const pdfPage = this.pdfPage;
  9951. const actualSizeViewport = this.viewport.clone({
  9952. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  9953. });
  9954. const promise = pdfPage.getOperatorList({
  9955. annotationMode: this.#annotationMode
  9956. }).then(opList => {
  9957. ensureNotCancelled();
  9958. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs, _app_options.compatibilityParams.disableCreateObjectURL);
  9959. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  9960. ensureNotCancelled();
  9961. this.svg = svg;
  9962. this.paintedViewportMap.set(svg, actualSizeViewport);
  9963. svg.style.width = wrapper.style.width;
  9964. svg.style.height = wrapper.style.height;
  9965. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9966. wrapper.appendChild(svg);
  9967. });
  9968. });
  9969. return {
  9970. promise,
  9971. onRenderContinue(cont) {
  9972. cont();
  9973. },
  9974. cancel() {
  9975. cancelled = true;
  9976. }
  9977. };
  9978. }
  9979. setPageLabel(label) {
  9980. this.pageLabel = typeof label === "string" ? label : null;
  9981. if (this.pageLabel !== null) {
  9982. this.div.setAttribute("data-page-label", this.pageLabel);
  9983. } else {
  9984. this.div.removeAttribute("data-page-label");
  9985. }
  9986. }
  9987. }
  9988. exports.PDFPageView = PDFPageView;
  9989. /***/ }),
  9990. /* 32 */
  9991. /***/ ((__unused_webpack_module, exports) => {
  9992. Object.defineProperty(exports, "__esModule", ({
  9993. value: true
  9994. }));
  9995. exports.StructTreeLayerBuilder = void 0;
  9996. const PDF_ROLE_TO_HTML_ROLE = {
  9997. Document: null,
  9998. DocumentFragment: null,
  9999. Part: "group",
  10000. Sect: "group",
  10001. Div: "group",
  10002. Aside: "note",
  10003. NonStruct: "none",
  10004. P: null,
  10005. H: "heading",
  10006. Title: null,
  10007. FENote: "note",
  10008. Sub: "group",
  10009. Lbl: null,
  10010. Span: null,
  10011. Em: null,
  10012. Strong: null,
  10013. Link: "link",
  10014. Annot: "note",
  10015. Form: "form",
  10016. Ruby: null,
  10017. RB: null,
  10018. RT: null,
  10019. RP: null,
  10020. Warichu: null,
  10021. WT: null,
  10022. WP: null,
  10023. L: "list",
  10024. LI: "listitem",
  10025. LBody: null,
  10026. Table: "table",
  10027. TR: "row",
  10028. TH: "columnheader",
  10029. TD: "cell",
  10030. THead: "columnheader",
  10031. TBody: null,
  10032. TFoot: null,
  10033. Caption: null,
  10034. Figure: "figure",
  10035. Formula: null,
  10036. Artifact: null
  10037. };
  10038. const HEADING_PATTERN = /^H(\d+)$/;
  10039. class StructTreeLayerBuilder {
  10040. constructor({
  10041. pdfPage
  10042. }) {
  10043. this.pdfPage = pdfPage;
  10044. }
  10045. render(structTree) {
  10046. return this._walk(structTree);
  10047. }
  10048. _setAttributes(structElement, htmlElement) {
  10049. if (structElement.alt !== undefined) {
  10050. htmlElement.setAttribute("aria-label", structElement.alt);
  10051. }
  10052. if (structElement.id !== undefined) {
  10053. htmlElement.setAttribute("aria-owns", structElement.id);
  10054. }
  10055. if (structElement.lang !== undefined) {
  10056. htmlElement.setAttribute("lang", structElement.lang);
  10057. }
  10058. }
  10059. _walk(node) {
  10060. if (!node) {
  10061. return null;
  10062. }
  10063. const element = document.createElement("span");
  10064. if ("role" in node) {
  10065. const {
  10066. role
  10067. } = node;
  10068. const match = role.match(HEADING_PATTERN);
  10069. if (match) {
  10070. element.setAttribute("role", "heading");
  10071. element.setAttribute("aria-level", match[1]);
  10072. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10073. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10074. }
  10075. }
  10076. this._setAttributes(node, element);
  10077. if (node.children) {
  10078. if (node.children.length === 1 && "id" in node.children[0]) {
  10079. this._setAttributes(node.children[0], element);
  10080. } else {
  10081. for (const kid of node.children) {
  10082. element.appendChild(this._walk(kid));
  10083. }
  10084. }
  10085. }
  10086. return element;
  10087. }
  10088. }
  10089. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10090. /***/ }),
  10091. /* 33 */
  10092. /***/ ((__unused_webpack_module, exports) => {
  10093. Object.defineProperty(exports, "__esModule", ({
  10094. value: true
  10095. }));
  10096. exports.TextHighlighter = void 0;
  10097. class TextHighlighter {
  10098. constructor({
  10099. findController,
  10100. eventBus,
  10101. pageIndex
  10102. }) {
  10103. this.findController = findController;
  10104. this.matches = [];
  10105. this.eventBus = eventBus;
  10106. this.pageIdx = pageIndex;
  10107. this._onUpdateTextLayerMatches = null;
  10108. this.textDivs = null;
  10109. this.textContentItemsStr = null;
  10110. this.enabled = false;
  10111. }
  10112. setTextMapping(divs, texts) {
  10113. this.textDivs = divs;
  10114. this.textContentItemsStr = texts;
  10115. }
  10116. enable() {
  10117. if (!this.textDivs || !this.textContentItemsStr) {
  10118. throw new Error("Text divs and strings have not been set.");
  10119. }
  10120. if (this.enabled) {
  10121. throw new Error("TextHighlighter is already enabled.");
  10122. }
  10123. this.enabled = true;
  10124. if (!this._onUpdateTextLayerMatches) {
  10125. this._onUpdateTextLayerMatches = evt => {
  10126. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  10127. this._updateMatches();
  10128. }
  10129. };
  10130. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10131. }
  10132. this._updateMatches();
  10133. }
  10134. disable() {
  10135. if (!this.enabled) {
  10136. return;
  10137. }
  10138. this.enabled = false;
  10139. if (this._onUpdateTextLayerMatches) {
  10140. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10141. this._onUpdateTextLayerMatches = null;
  10142. }
  10143. }
  10144. _convertMatches(matches, matchesLength) {
  10145. if (!matches) {
  10146. return [];
  10147. }
  10148. const {
  10149. textContentItemsStr
  10150. } = this;
  10151. let i = 0,
  10152. iIndex = 0;
  10153. const end = textContentItemsStr.length - 1;
  10154. const result = [];
  10155. for (let m = 0, mm = matches.length; m < mm; m++) {
  10156. let matchIdx = matches[m];
  10157. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  10158. iIndex += textContentItemsStr[i].length;
  10159. i++;
  10160. }
  10161. if (i === textContentItemsStr.length) {
  10162. console.error("Could not find a matching mapping");
  10163. }
  10164. const match = {
  10165. begin: {
  10166. divIdx: i,
  10167. offset: matchIdx - iIndex
  10168. }
  10169. };
  10170. matchIdx += matchesLength[m];
  10171. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  10172. iIndex += textContentItemsStr[i].length;
  10173. i++;
  10174. }
  10175. match.end = {
  10176. divIdx: i,
  10177. offset: matchIdx - iIndex
  10178. };
  10179. result.push(match);
  10180. }
  10181. return result;
  10182. }
  10183. _renderMatches(matches) {
  10184. if (matches.length === 0) {
  10185. return;
  10186. }
  10187. const {
  10188. findController,
  10189. pageIdx
  10190. } = this;
  10191. const {
  10192. textContentItemsStr,
  10193. textDivs
  10194. } = this;
  10195. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  10196. const selectedMatchIdx = findController.selected.matchIdx;
  10197. const highlightAll = findController.state.highlightAll;
  10198. let prevEnd = null;
  10199. const infinity = {
  10200. divIdx: -1,
  10201. offset: undefined
  10202. };
  10203. function beginText(begin, className) {
  10204. const divIdx = begin.divIdx;
  10205. textDivs[divIdx].textContent = "";
  10206. return appendTextToDiv(divIdx, 0, begin.offset, className);
  10207. }
  10208. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  10209. let div = textDivs[divIdx];
  10210. if (div.nodeType === Node.TEXT_NODE) {
  10211. const span = document.createElement("span");
  10212. div.parentNode.insertBefore(span, div);
  10213. span.appendChild(div);
  10214. textDivs[divIdx] = span;
  10215. div = span;
  10216. }
  10217. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  10218. const node = document.createTextNode(content);
  10219. if (className) {
  10220. const span = document.createElement("span");
  10221. span.className = `${className} appended`;
  10222. span.appendChild(node);
  10223. div.appendChild(span);
  10224. return className.includes("selected") ? span.offsetLeft : 0;
  10225. }
  10226. div.appendChild(node);
  10227. return 0;
  10228. }
  10229. let i0 = selectedMatchIdx,
  10230. i1 = i0 + 1;
  10231. if (highlightAll) {
  10232. i0 = 0;
  10233. i1 = matches.length;
  10234. } else if (!isSelectedPage) {
  10235. return;
  10236. }
  10237. for (let i = i0; i < i1; i++) {
  10238. const match = matches[i];
  10239. const begin = match.begin;
  10240. const end = match.end;
  10241. const isSelected = isSelectedPage && i === selectedMatchIdx;
  10242. const highlightSuffix = isSelected ? " selected" : "";
  10243. let selectedLeft = 0;
  10244. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  10245. if (prevEnd !== null) {
  10246. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10247. }
  10248. beginText(begin);
  10249. } else {
  10250. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  10251. }
  10252. if (begin.divIdx === end.divIdx) {
  10253. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  10254. } else {
  10255. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  10256. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  10257. textDivs[n0].className = "highlight middle" + highlightSuffix;
  10258. }
  10259. beginText(end, "highlight end" + highlightSuffix);
  10260. }
  10261. prevEnd = end;
  10262. if (isSelected) {
  10263. findController.scrollMatchIntoView({
  10264. element: textDivs[begin.divIdx],
  10265. selectedLeft,
  10266. pageIndex: pageIdx,
  10267. matchIndex: selectedMatchIdx
  10268. });
  10269. }
  10270. }
  10271. if (prevEnd) {
  10272. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10273. }
  10274. }
  10275. _updateMatches() {
  10276. if (!this.enabled) {
  10277. return;
  10278. }
  10279. const {
  10280. findController,
  10281. matches,
  10282. pageIdx
  10283. } = this;
  10284. const {
  10285. textContentItemsStr,
  10286. textDivs
  10287. } = this;
  10288. let clearedUntilDivIdx = -1;
  10289. for (let i = 0, ii = matches.length; i < ii; i++) {
  10290. const match = matches[i];
  10291. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  10292. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  10293. const div = textDivs[n];
  10294. div.textContent = textContentItemsStr[n];
  10295. div.className = "";
  10296. }
  10297. clearedUntilDivIdx = match.end.divIdx + 1;
  10298. }
  10299. if (!findController?.highlightMatches) {
  10300. return;
  10301. }
  10302. const pageMatches = findController.pageMatches[pageIdx] || null;
  10303. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  10304. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  10305. this._renderMatches(this.matches);
  10306. }
  10307. }
  10308. exports.TextHighlighter = TextHighlighter;
  10309. /***/ }),
  10310. /* 34 */
  10311. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10312. Object.defineProperty(exports, "__esModule", ({
  10313. value: true
  10314. }));
  10315. exports.TextLayerBuilder = void 0;
  10316. var _pdfjsLib = __webpack_require__(5);
  10317. const EXPAND_DIVS_TIMEOUT = 300;
  10318. class TextLayerBuilder {
  10319. constructor({
  10320. textLayerDiv,
  10321. eventBus,
  10322. pageIndex,
  10323. viewport,
  10324. highlighter = null,
  10325. enhanceTextSelection = false
  10326. }) {
  10327. this.textLayerDiv = textLayerDiv;
  10328. this.eventBus = eventBus;
  10329. this.textContent = null;
  10330. this.textContentItemsStr = [];
  10331. this.textContentStream = null;
  10332. this.renderingDone = false;
  10333. this.pageNumber = pageIndex + 1;
  10334. this.viewport = viewport;
  10335. this.textDivs = [];
  10336. this.textLayerRenderTask = null;
  10337. this.highlighter = highlighter;
  10338. this.enhanceTextSelection = enhanceTextSelection;
  10339. this._bindMouse();
  10340. }
  10341. _finishRendering() {
  10342. this.renderingDone = true;
  10343. if (!this.enhanceTextSelection) {
  10344. const endOfContent = document.createElement("div");
  10345. endOfContent.className = "endOfContent";
  10346. this.textLayerDiv.appendChild(endOfContent);
  10347. }
  10348. this.eventBus.dispatch("textlayerrendered", {
  10349. source: this,
  10350. pageNumber: this.pageNumber,
  10351. numTextDivs: this.textDivs.length
  10352. });
  10353. }
  10354. render(timeout = 0) {
  10355. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  10356. return;
  10357. }
  10358. this.cancel();
  10359. this.textDivs.length = 0;
  10360. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  10361. const textLayerFrag = document.createDocumentFragment();
  10362. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  10363. textContent: this.textContent,
  10364. textContentStream: this.textContentStream,
  10365. container: textLayerFrag,
  10366. viewport: this.viewport,
  10367. textDivs: this.textDivs,
  10368. textContentItemsStr: this.textContentItemsStr,
  10369. timeout,
  10370. enhanceTextSelection: this.enhanceTextSelection
  10371. });
  10372. this.textLayerRenderTask.promise.then(() => {
  10373. this.textLayerDiv.appendChild(textLayerFrag);
  10374. this._finishRendering();
  10375. this.highlighter?.enable();
  10376. }, function (reason) {});
  10377. }
  10378. cancel() {
  10379. if (this.textLayerRenderTask) {
  10380. this.textLayerRenderTask.cancel();
  10381. this.textLayerRenderTask = null;
  10382. }
  10383. this.highlighter?.disable();
  10384. }
  10385. setTextContentStream(readableStream) {
  10386. this.cancel();
  10387. this.textContentStream = readableStream;
  10388. }
  10389. setTextContent(textContent) {
  10390. this.cancel();
  10391. this.textContent = textContent;
  10392. }
  10393. _bindMouse() {
  10394. const div = this.textLayerDiv;
  10395. let expandDivsTimer = null;
  10396. div.addEventListener("mousedown", evt => {
  10397. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10398. this.textLayerRenderTask.expandTextDivs(true);
  10399. if (expandDivsTimer) {
  10400. clearTimeout(expandDivsTimer);
  10401. expandDivsTimer = null;
  10402. }
  10403. return;
  10404. }
  10405. const end = div.querySelector(".endOfContent");
  10406. if (!end) {
  10407. return;
  10408. }
  10409. let adjustTop = evt.target !== div;
  10410. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  10411. if (adjustTop) {
  10412. const divBounds = div.getBoundingClientRect();
  10413. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  10414. end.style.top = (r * 100).toFixed(2) + "%";
  10415. }
  10416. end.classList.add("active");
  10417. });
  10418. div.addEventListener("mouseup", () => {
  10419. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10420. expandDivsTimer = setTimeout(() => {
  10421. if (this.textLayerRenderTask) {
  10422. this.textLayerRenderTask.expandTextDivs(false);
  10423. }
  10424. expandDivsTimer = null;
  10425. }, EXPAND_DIVS_TIMEOUT);
  10426. return;
  10427. }
  10428. const end = div.querySelector(".endOfContent");
  10429. if (!end) {
  10430. return;
  10431. }
  10432. end.style.top = "";
  10433. end.classList.remove("active");
  10434. });
  10435. }
  10436. }
  10437. exports.TextLayerBuilder = TextLayerBuilder;
  10438. /***/ }),
  10439. /* 35 */
  10440. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10441. Object.defineProperty(exports, "__esModule", ({
  10442. value: true
  10443. }));
  10444. exports.XfaLayerBuilder = void 0;
  10445. var _pdfjsLib = __webpack_require__(5);
  10446. class XfaLayerBuilder {
  10447. constructor({
  10448. pageDiv,
  10449. pdfPage,
  10450. annotationStorage = null,
  10451. linkService,
  10452. xfaHtml = null
  10453. }) {
  10454. this.pageDiv = pageDiv;
  10455. this.pdfPage = pdfPage;
  10456. this.annotationStorage = annotationStorage;
  10457. this.linkService = linkService;
  10458. this.xfaHtml = xfaHtml;
  10459. this.div = null;
  10460. this._cancelled = false;
  10461. }
  10462. render(viewport, intent = "display") {
  10463. if (intent === "print") {
  10464. const parameters = {
  10465. viewport: viewport.clone({
  10466. dontFlip: true
  10467. }),
  10468. div: this.div,
  10469. xfaHtml: this.xfaHtml,
  10470. annotationStorage: this.annotationStorage,
  10471. linkService: this.linkService,
  10472. intent
  10473. };
  10474. const div = document.createElement("div");
  10475. this.pageDiv.appendChild(div);
  10476. parameters.div = div;
  10477. const result = _pdfjsLib.XfaLayer.render(parameters);
  10478. return Promise.resolve(result);
  10479. }
  10480. return this.pdfPage.getXfa().then(xfaHtml => {
  10481. if (this._cancelled || !xfaHtml) {
  10482. return {
  10483. textDivs: []
  10484. };
  10485. }
  10486. const parameters = {
  10487. viewport: viewport.clone({
  10488. dontFlip: true
  10489. }),
  10490. div: this.div,
  10491. xfaHtml,
  10492. annotationStorage: this.annotationStorage,
  10493. linkService: this.linkService,
  10494. intent
  10495. };
  10496. if (this.div) {
  10497. return _pdfjsLib.XfaLayer.update(parameters);
  10498. }
  10499. this.div = document.createElement("div");
  10500. this.pageDiv.appendChild(this.div);
  10501. parameters.div = this.div;
  10502. return _pdfjsLib.XfaLayer.render(parameters);
  10503. }).catch(error => {
  10504. console.error(error);
  10505. });
  10506. }
  10507. cancel() {
  10508. this._cancelled = true;
  10509. }
  10510. hide() {
  10511. if (!this.div) {
  10512. return;
  10513. }
  10514. this.div.hidden = true;
  10515. }
  10516. }
  10517. exports.XfaLayerBuilder = XfaLayerBuilder;
  10518. /***/ }),
  10519. /* 36 */
  10520. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10521. Object.defineProperty(exports, "__esModule", ({
  10522. value: true
  10523. }));
  10524. exports.SecondaryToolbar = void 0;
  10525. var _ui_utils = __webpack_require__(3);
  10526. var _pdf_cursor_tools = __webpack_require__(6);
  10527. var _base_viewer = __webpack_require__(28);
  10528. class SecondaryToolbar {
  10529. constructor(options, mainContainer, eventBus) {
  10530. this.toolbar = options.toolbar;
  10531. this.toggleButton = options.toggleButton;
  10532. this.toolbarButtonContainer = options.toolbarButtonContainer;
  10533. this.buttons = [{
  10534. element: options.presentationModeButton,
  10535. eventName: "presentationmode",
  10536. close: true
  10537. }, {
  10538. element: options.openFileButton,
  10539. eventName: "openfile",
  10540. close: true
  10541. }, {
  10542. element: options.printButton,
  10543. eventName: "print",
  10544. close: true
  10545. }, {
  10546. element: options.downloadButton,
  10547. eventName: "download",
  10548. close: true
  10549. }, {
  10550. element: options.viewBookmarkButton,
  10551. eventName: null,
  10552. close: true
  10553. }, {
  10554. element: options.firstPageButton,
  10555. eventName: "firstpage",
  10556. close: true
  10557. }, {
  10558. element: options.lastPageButton,
  10559. eventName: "lastpage",
  10560. close: true
  10561. }, {
  10562. element: options.pageRotateCwButton,
  10563. eventName: "rotatecw",
  10564. close: false
  10565. }, {
  10566. element: options.pageRotateCcwButton,
  10567. eventName: "rotateccw",
  10568. close: false
  10569. }, {
  10570. element: options.cursorSelectToolButton,
  10571. eventName: "switchcursortool",
  10572. eventDetails: {
  10573. tool: _pdf_cursor_tools.CursorTool.SELECT
  10574. },
  10575. close: true
  10576. }, {
  10577. element: options.cursorHandToolButton,
  10578. eventName: "switchcursortool",
  10579. eventDetails: {
  10580. tool: _pdf_cursor_tools.CursorTool.HAND
  10581. },
  10582. close: true
  10583. }, {
  10584. element: options.scrollPageButton,
  10585. eventName: "switchscrollmode",
  10586. eventDetails: {
  10587. mode: _ui_utils.ScrollMode.PAGE
  10588. },
  10589. close: true
  10590. }, {
  10591. element: options.scrollVerticalButton,
  10592. eventName: "switchscrollmode",
  10593. eventDetails: {
  10594. mode: _ui_utils.ScrollMode.VERTICAL
  10595. },
  10596. close: true
  10597. }, {
  10598. element: options.scrollHorizontalButton,
  10599. eventName: "switchscrollmode",
  10600. eventDetails: {
  10601. mode: _ui_utils.ScrollMode.HORIZONTAL
  10602. },
  10603. close: true
  10604. }, {
  10605. element: options.scrollWrappedButton,
  10606. eventName: "switchscrollmode",
  10607. eventDetails: {
  10608. mode: _ui_utils.ScrollMode.WRAPPED
  10609. },
  10610. close: true
  10611. }, {
  10612. element: options.spreadNoneButton,
  10613. eventName: "switchspreadmode",
  10614. eventDetails: {
  10615. mode: _ui_utils.SpreadMode.NONE
  10616. },
  10617. close: true
  10618. }, {
  10619. element: options.spreadOddButton,
  10620. eventName: "switchspreadmode",
  10621. eventDetails: {
  10622. mode: _ui_utils.SpreadMode.ODD
  10623. },
  10624. close: true
  10625. }, {
  10626. element: options.spreadEvenButton,
  10627. eventName: "switchspreadmode",
  10628. eventDetails: {
  10629. mode: _ui_utils.SpreadMode.EVEN
  10630. },
  10631. close: true
  10632. }, {
  10633. element: options.documentPropertiesButton,
  10634. eventName: "documentproperties",
  10635. close: true
  10636. }];
  10637. this.items = {
  10638. firstPage: options.firstPageButton,
  10639. lastPage: options.lastPageButton,
  10640. pageRotateCw: options.pageRotateCwButton,
  10641. pageRotateCcw: options.pageRotateCcwButton
  10642. };
  10643. this.mainContainer = mainContainer;
  10644. this.eventBus = eventBus;
  10645. this.opened = false;
  10646. this.containerHeight = null;
  10647. this.previousContainerHeight = null;
  10648. this.reset();
  10649. this._bindClickListeners();
  10650. this._bindCursorToolsListener(options);
  10651. this._bindScrollModeListener(options);
  10652. this._bindSpreadModeListener(options);
  10653. this.eventBus._on("resize", this._setMaxHeight.bind(this));
  10654. }
  10655. get isOpen() {
  10656. return this.opened;
  10657. }
  10658. setPageNumber(pageNumber) {
  10659. this.pageNumber = pageNumber;
  10660. this._updateUIState();
  10661. }
  10662. setPagesCount(pagesCount) {
  10663. this.pagesCount = pagesCount;
  10664. this._updateUIState();
  10665. }
  10666. reset() {
  10667. this.pageNumber = 0;
  10668. this.pagesCount = 0;
  10669. this._updateUIState();
  10670. this.eventBus.dispatch("secondarytoolbarreset", {
  10671. source: this
  10672. });
  10673. }
  10674. _updateUIState() {
  10675. this.items.firstPage.disabled = this.pageNumber <= 1;
  10676. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  10677. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  10678. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  10679. }
  10680. _bindClickListeners() {
  10681. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  10682. for (const {
  10683. element,
  10684. eventName,
  10685. close,
  10686. eventDetails
  10687. } of this.buttons) {
  10688. element.addEventListener("click", evt => {
  10689. if (eventName !== null) {
  10690. const details = {
  10691. source: this
  10692. };
  10693. for (const property in eventDetails) {
  10694. details[property] = eventDetails[property];
  10695. }
  10696. this.eventBus.dispatch(eventName, details);
  10697. }
  10698. if (close) {
  10699. this.close();
  10700. }
  10701. });
  10702. }
  10703. }
  10704. _bindCursorToolsListener(buttons) {
  10705. this.eventBus._on("cursortoolchanged", function ({
  10706. tool
  10707. }) {
  10708. buttons.cursorSelectToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.SELECT);
  10709. buttons.cursorHandToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.HAND);
  10710. });
  10711. }
  10712. _bindScrollModeListener(buttons) {
  10713. const scrollModeChanged = ({
  10714. mode
  10715. }) => {
  10716. buttons.scrollPageButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.PAGE);
  10717. buttons.scrollVerticalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.VERTICAL);
  10718. buttons.scrollHorizontalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.HORIZONTAL);
  10719. buttons.scrollWrappedButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.WRAPPED);
  10720. const forceScrollModePage = this.pagesCount > _base_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  10721. buttons.scrollPageButton.disabled = forceScrollModePage;
  10722. buttons.scrollVerticalButton.disabled = forceScrollModePage;
  10723. buttons.scrollHorizontalButton.disabled = forceScrollModePage;
  10724. buttons.scrollWrappedButton.disabled = forceScrollModePage;
  10725. const isScrollModeHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  10726. buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
  10727. buttons.spreadOddButton.disabled = isScrollModeHorizontal;
  10728. buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
  10729. };
  10730. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  10731. this.eventBus._on("secondarytoolbarreset", evt => {
  10732. if (evt.source === this) {
  10733. scrollModeChanged({
  10734. mode: _ui_utils.ScrollMode.VERTICAL
  10735. });
  10736. }
  10737. });
  10738. }
  10739. _bindSpreadModeListener(buttons) {
  10740. function spreadModeChanged({
  10741. mode
  10742. }) {
  10743. buttons.spreadNoneButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.NONE);
  10744. buttons.spreadOddButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.ODD);
  10745. buttons.spreadEvenButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.EVEN);
  10746. }
  10747. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  10748. this.eventBus._on("secondarytoolbarreset", evt => {
  10749. if (evt.source === this) {
  10750. spreadModeChanged({
  10751. mode: _ui_utils.SpreadMode.NONE
  10752. });
  10753. }
  10754. });
  10755. }
  10756. open() {
  10757. if (this.opened) {
  10758. return;
  10759. }
  10760. this.opened = true;
  10761. this._setMaxHeight();
  10762. this.toggleButton.classList.add("toggled");
  10763. this.toggleButton.setAttribute("aria-expanded", "true");
  10764. this.toolbar.classList.remove("hidden");
  10765. }
  10766. close() {
  10767. if (!this.opened) {
  10768. return;
  10769. }
  10770. this.opened = false;
  10771. this.toolbar.classList.add("hidden");
  10772. this.toggleButton.classList.remove("toggled");
  10773. this.toggleButton.setAttribute("aria-expanded", "false");
  10774. }
  10775. toggle() {
  10776. if (this.opened) {
  10777. this.close();
  10778. } else {
  10779. this.open();
  10780. }
  10781. }
  10782. _setMaxHeight() {
  10783. if (!this.opened) {
  10784. return;
  10785. }
  10786. this.containerHeight = this.mainContainer.clientHeight;
  10787. if (this.containerHeight === this.previousContainerHeight) {
  10788. return;
  10789. }
  10790. this.toolbarButtonContainer.style.maxHeight = `${this.containerHeight - _ui_utils.SCROLLBAR_PADDING}px`;
  10791. this.previousContainerHeight = this.containerHeight;
  10792. }
  10793. }
  10794. exports.SecondaryToolbar = SecondaryToolbar;
  10795. /***/ }),
  10796. /* 37 */
  10797. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10798. Object.defineProperty(exports, "__esModule", ({
  10799. value: true
  10800. }));
  10801. exports.Toolbar = void 0;
  10802. var _ui_utils = __webpack_require__(3);
  10803. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  10804. class Toolbar {
  10805. constructor(options, eventBus, l10n) {
  10806. this.toolbar = options.container;
  10807. this.eventBus = eventBus;
  10808. this.l10n = l10n;
  10809. this.buttons = [{
  10810. element: options.previous,
  10811. eventName: "previouspage"
  10812. }, {
  10813. element: options.next,
  10814. eventName: "nextpage"
  10815. }, {
  10816. element: options.zoomIn,
  10817. eventName: "zoomin"
  10818. }, {
  10819. element: options.zoomOut,
  10820. eventName: "zoomout"
  10821. }, {
  10822. element: options.openFile,
  10823. eventName: "openfile"
  10824. }, {
  10825. element: options.print,
  10826. eventName: "print"
  10827. }, {
  10828. element: options.presentationModeButton,
  10829. eventName: "presentationmode"
  10830. }, {
  10831. element: options.download,
  10832. eventName: "download"
  10833. }, {
  10834. element: options.viewBookmark,
  10835. eventName: null
  10836. }];
  10837. this.items = {
  10838. numPages: options.numPages,
  10839. pageNumber: options.pageNumber,
  10840. scaleSelect: options.scaleSelect,
  10841. customScaleOption: options.customScaleOption,
  10842. previous: options.previous,
  10843. next: options.next,
  10844. zoomIn: options.zoomIn,
  10845. zoomOut: options.zoomOut
  10846. };
  10847. this._wasLocalized = false;
  10848. this.reset();
  10849. this._bindListeners();
  10850. }
  10851. setPageNumber(pageNumber, pageLabel) {
  10852. this.pageNumber = pageNumber;
  10853. this.pageLabel = pageLabel;
  10854. this._updateUIState(false);
  10855. }
  10856. setPagesCount(pagesCount, hasPageLabels) {
  10857. this.pagesCount = pagesCount;
  10858. this.hasPageLabels = hasPageLabels;
  10859. this._updateUIState(true);
  10860. }
  10861. setPageScale(pageScaleValue, pageScale) {
  10862. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  10863. this.pageScale = pageScale;
  10864. this._updateUIState(false);
  10865. }
  10866. reset() {
  10867. this.pageNumber = 0;
  10868. this.pageLabel = null;
  10869. this.hasPageLabels = false;
  10870. this.pagesCount = 0;
  10871. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  10872. this.pageScale = _ui_utils.DEFAULT_SCALE;
  10873. this._updateUIState(true);
  10874. this.updateLoadingIndicatorState();
  10875. }
  10876. _bindListeners() {
  10877. const {
  10878. pageNumber,
  10879. scaleSelect
  10880. } = this.items;
  10881. const self = this;
  10882. for (const {
  10883. element,
  10884. eventName
  10885. } of this.buttons) {
  10886. element.addEventListener("click", evt => {
  10887. if (eventName !== null) {
  10888. this.eventBus.dispatch(eventName, {
  10889. source: this
  10890. });
  10891. }
  10892. });
  10893. }
  10894. pageNumber.addEventListener("click", function () {
  10895. this.select();
  10896. });
  10897. pageNumber.addEventListener("change", function () {
  10898. self.eventBus.dispatch("pagenumberchanged", {
  10899. source: self,
  10900. value: this.value
  10901. });
  10902. });
  10903. scaleSelect.addEventListener("change", function () {
  10904. if (this.value === "custom") {
  10905. return;
  10906. }
  10907. self.eventBus.dispatch("scalechanged", {
  10908. source: self,
  10909. value: this.value
  10910. });
  10911. });
  10912. scaleSelect.addEventListener("click", function (evt) {
  10913. const target = evt.target;
  10914. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  10915. this.blur();
  10916. }
  10917. });
  10918. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  10919. this.eventBus._on("localized", () => {
  10920. this._wasLocalized = true;
  10921. this._adjustScaleWidth();
  10922. this._updateUIState(true);
  10923. });
  10924. }
  10925. _updateUIState(resetNumPages = false) {
  10926. if (!this._wasLocalized) {
  10927. return;
  10928. }
  10929. const {
  10930. pageNumber,
  10931. pagesCount,
  10932. pageScaleValue,
  10933. pageScale,
  10934. items
  10935. } = this;
  10936. if (resetNumPages) {
  10937. if (this.hasPageLabels) {
  10938. items.pageNumber.type = "text";
  10939. } else {
  10940. items.pageNumber.type = "number";
  10941. this.l10n.get("of_pages", {
  10942. pagesCount
  10943. }).then(msg => {
  10944. items.numPages.textContent = msg;
  10945. });
  10946. }
  10947. items.pageNumber.max = pagesCount;
  10948. }
  10949. if (this.hasPageLabels) {
  10950. items.pageNumber.value = this.pageLabel;
  10951. this.l10n.get("page_of_pages", {
  10952. pageNumber,
  10953. pagesCount
  10954. }).then(msg => {
  10955. items.numPages.textContent = msg;
  10956. });
  10957. } else {
  10958. items.pageNumber.value = pageNumber;
  10959. }
  10960. items.previous.disabled = pageNumber <= 1;
  10961. items.next.disabled = pageNumber >= pagesCount;
  10962. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  10963. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  10964. this.l10n.get("page_scale_percent", {
  10965. scale: Math.round(pageScale * 10000) / 100
  10966. }).then(msg => {
  10967. let predefinedValueFound = false;
  10968. for (const option of items.scaleSelect.options) {
  10969. if (option.value !== pageScaleValue) {
  10970. option.selected = false;
  10971. continue;
  10972. }
  10973. option.selected = true;
  10974. predefinedValueFound = true;
  10975. }
  10976. if (!predefinedValueFound) {
  10977. items.customScaleOption.textContent = msg;
  10978. items.customScaleOption.selected = true;
  10979. }
  10980. });
  10981. }
  10982. updateLoadingIndicatorState(loading = false) {
  10983. const pageNumberInput = this.items.pageNumber;
  10984. pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  10985. }
  10986. async _adjustScaleWidth() {
  10987. const {
  10988. items,
  10989. l10n
  10990. } = this;
  10991. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  10992. const style = getComputedStyle(items.scaleSelect),
  10993. scaleSelectContainerWidth = parseInt(style.getPropertyValue("--scale-select-container-width"), 10),
  10994. scaleSelectOverflow = parseInt(style.getPropertyValue("--scale-select-overflow"), 10);
  10995. let canvas = document.createElement("canvas");
  10996. canvas.mozOpaque = true;
  10997. let ctx = canvas.getContext("2d", {
  10998. alpha: false
  10999. });
  11000. await _ui_utils.animationStarted;
  11001. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  11002. let maxWidth = 0;
  11003. for (const predefinedValue of await predefinedValuesPromise) {
  11004. const {
  11005. width
  11006. } = ctx.measureText(predefinedValue);
  11007. if (width > maxWidth) {
  11008. maxWidth = width;
  11009. }
  11010. }
  11011. maxWidth += 2 * scaleSelectOverflow;
  11012. if (maxWidth > scaleSelectContainerWidth) {
  11013. const doc = document.documentElement;
  11014. doc.style.setProperty("--scale-select-container-width", `${maxWidth}px`);
  11015. }
  11016. canvas.width = 0;
  11017. canvas.height = 0;
  11018. canvas = ctx = null;
  11019. }
  11020. }
  11021. exports.Toolbar = Toolbar;
  11022. /***/ }),
  11023. /* 38 */
  11024. /***/ ((__unused_webpack_module, exports) => {
  11025. Object.defineProperty(exports, "__esModule", ({
  11026. value: true
  11027. }));
  11028. exports.ViewHistory = void 0;
  11029. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  11030. class ViewHistory {
  11031. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  11032. this.fingerprint = fingerprint;
  11033. this.cacheSize = cacheSize;
  11034. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  11035. const database = JSON.parse(databaseStr || "{}");
  11036. let index = -1;
  11037. if (!Array.isArray(database.files)) {
  11038. database.files = [];
  11039. } else {
  11040. while (database.files.length >= this.cacheSize) {
  11041. database.files.shift();
  11042. }
  11043. for (let i = 0, ii = database.files.length; i < ii; i++) {
  11044. const branch = database.files[i];
  11045. if (branch.fingerprint === this.fingerprint) {
  11046. index = i;
  11047. break;
  11048. }
  11049. }
  11050. }
  11051. if (index === -1) {
  11052. index = database.files.push({
  11053. fingerprint: this.fingerprint
  11054. }) - 1;
  11055. }
  11056. this.file = database.files[index];
  11057. this.database = database;
  11058. });
  11059. }
  11060. async _writeToStorage() {
  11061. const databaseStr = JSON.stringify(this.database);
  11062. localStorage.setItem("pdfjs.history", databaseStr);
  11063. }
  11064. async _readFromStorage() {
  11065. return localStorage.getItem("pdfjs.history");
  11066. }
  11067. async set(name, val) {
  11068. await this._initializedPromise;
  11069. this.file[name] = val;
  11070. return this._writeToStorage();
  11071. }
  11072. async setMultiple(properties) {
  11073. await this._initializedPromise;
  11074. for (const name in properties) {
  11075. this.file[name] = properties[name];
  11076. }
  11077. return this._writeToStorage();
  11078. }
  11079. async get(name, defaultValue) {
  11080. await this._initializedPromise;
  11081. const val = this.file[name];
  11082. return val !== undefined ? val : defaultValue;
  11083. }
  11084. async getMultiple(properties) {
  11085. await this._initializedPromise;
  11086. const values = Object.create(null);
  11087. for (const name in properties) {
  11088. const val = this.file[name];
  11089. values[name] = val !== undefined ? val : properties[name];
  11090. }
  11091. return values;
  11092. }
  11093. }
  11094. exports.ViewHistory = ViewHistory;
  11095. /***/ }),
  11096. /* 39 */
  11097. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11098. Object.defineProperty(exports, "__esModule", ({
  11099. value: true
  11100. }));
  11101. exports.GenericCom = void 0;
  11102. var _app = __webpack_require__(2);
  11103. var _preferences = __webpack_require__(40);
  11104. var _download_manager = __webpack_require__(41);
  11105. var _genericl10n = __webpack_require__(42);
  11106. var _generic_scripting = __webpack_require__(44);
  11107. ;
  11108. const GenericCom = {};
  11109. exports.GenericCom = GenericCom;
  11110. class GenericPreferences extends _preferences.BasePreferences {
  11111. async _writeToStorage(prefObj) {
  11112. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  11113. }
  11114. async _readFromStorage(prefObj) {
  11115. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  11116. }
  11117. }
  11118. class GenericExternalServices extends _app.DefaultExternalServices {
  11119. static createDownloadManager(options) {
  11120. return new _download_manager.DownloadManager();
  11121. }
  11122. static createPreferences() {
  11123. return new GenericPreferences();
  11124. }
  11125. static createL10n({
  11126. locale = "en-US"
  11127. }) {
  11128. return new _genericl10n.GenericL10n(locale);
  11129. }
  11130. static createScripting({
  11131. sandboxBundleSrc
  11132. }) {
  11133. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  11134. }
  11135. }
  11136. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  11137. /***/ }),
  11138. /* 40 */
  11139. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11140. Object.defineProperty(exports, "__esModule", ({
  11141. value: true
  11142. }));
  11143. exports.BasePreferences = void 0;
  11144. var _app_options = __webpack_require__(1);
  11145. class BasePreferences {
  11146. constructor() {
  11147. if (this.constructor === BasePreferences) {
  11148. throw new Error("Cannot initialize BasePreferences.");
  11149. }
  11150. Object.defineProperty(this, "defaults", {
  11151. value: Object.freeze({
  11152. "annotationMode": 2,
  11153. "cursorToolOnLoad": 0,
  11154. "defaultZoomValue": "",
  11155. "disablePageLabels": false,
  11156. "enablePermissions": false,
  11157. "enablePrintAutoRotate": true,
  11158. "enableScripting": true,
  11159. "externalLinkTarget": 0,
  11160. "historyUpdateUrl": false,
  11161. "ignoreDestinationZoom": false,
  11162. "pdfBugEnabled": false,
  11163. "renderer": "canvas",
  11164. "sidebarViewOnLoad": -1,
  11165. "scrollModeOnLoad": -1,
  11166. "spreadModeOnLoad": -1,
  11167. "textLayerMode": 1,
  11168. "useOnlyCssZoom": false,
  11169. "viewerCssTheme": 0,
  11170. "viewOnLoad": 0,
  11171. "disableAutoFetch": false,
  11172. "disableFontFace": false,
  11173. "disableRange": false,
  11174. "disableStream": false,
  11175. "enableXfa": true
  11176. }),
  11177. writable: false,
  11178. enumerable: true,
  11179. configurable: false
  11180. });
  11181. this.prefs = Object.create(null);
  11182. this._initializedPromise = this._readFromStorage(this.defaults).then(prefs => {
  11183. for (const name in this.defaults) {
  11184. const prefValue = prefs?.[name];
  11185. if (typeof prefValue === typeof this.defaults[name]) {
  11186. this.prefs[name] = prefValue;
  11187. }
  11188. }
  11189. });
  11190. }
  11191. async _writeToStorage(prefObj) {
  11192. throw new Error("Not implemented: _writeToStorage");
  11193. }
  11194. async _readFromStorage(prefObj) {
  11195. throw new Error("Not implemented: _readFromStorage");
  11196. }
  11197. async reset() {
  11198. await this._initializedPromise;
  11199. this.prefs = Object.create(null);
  11200. return this._writeToStorage(this.defaults);
  11201. }
  11202. async set(name, value) {
  11203. await this._initializedPromise;
  11204. const defaultValue = this.defaults[name];
  11205. if (defaultValue === undefined) {
  11206. throw new Error(`Set preference: "${name}" is undefined.`);
  11207. } else if (value === undefined) {
  11208. throw new Error("Set preference: no value is specified.");
  11209. }
  11210. const valueType = typeof value;
  11211. const defaultType = typeof defaultValue;
  11212. if (valueType !== defaultType) {
  11213. if (valueType === "number" && defaultType === "string") {
  11214. value = value.toString();
  11215. } else {
  11216. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  11217. }
  11218. } else {
  11219. if (valueType === "number" && !Number.isInteger(value)) {
  11220. throw new Error(`Set preference: "${value}" must be an integer.`);
  11221. }
  11222. }
  11223. this.prefs[name] = value;
  11224. return this._writeToStorage(this.prefs);
  11225. }
  11226. async get(name) {
  11227. await this._initializedPromise;
  11228. const defaultValue = this.defaults[name],
  11229. prefValue = this.prefs[name];
  11230. if (defaultValue === undefined) {
  11231. throw new Error(`Get preference: "${name}" is undefined.`);
  11232. }
  11233. return prefValue !== undefined ? prefValue : defaultValue;
  11234. }
  11235. async getAll() {
  11236. await this._initializedPromise;
  11237. const obj = Object.create(null);
  11238. for (const name in this.defaults) {
  11239. const prefValue = this.prefs[name];
  11240. obj[name] = prefValue !== undefined ? prefValue : this.defaults[name];
  11241. }
  11242. return obj;
  11243. }
  11244. }
  11245. exports.BasePreferences = BasePreferences;
  11246. /***/ }),
  11247. /* 41 */
  11248. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11249. Object.defineProperty(exports, "__esModule", ({
  11250. value: true
  11251. }));
  11252. exports.DownloadManager = void 0;
  11253. var _pdfjsLib = __webpack_require__(5);
  11254. var _app_options = __webpack_require__(1);
  11255. ;
  11256. function download(blobUrl, filename) {
  11257. const a = document.createElement("a");
  11258. if (!a.click) {
  11259. throw new Error('DownloadManager: "a.click()" is not supported.');
  11260. }
  11261. a.href = blobUrl;
  11262. a.target = "_parent";
  11263. if ("download" in a) {
  11264. a.download = filename;
  11265. }
  11266. (document.body || document.documentElement).appendChild(a);
  11267. a.click();
  11268. a.remove();
  11269. }
  11270. class DownloadManager {
  11271. constructor() {
  11272. this._openBlobUrls = new WeakMap();
  11273. }
  11274. downloadUrl(url, filename) {
  11275. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  11276. console.error(`downloadUrl - not a valid URL: ${url}`);
  11277. return;
  11278. }
  11279. download(url + "#pdfjs.action=download", filename);
  11280. }
  11281. downloadData(data, filename, contentType) {
  11282. const blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _app_options.compatibilityParams.disableCreateObjectURL);
  11283. download(blobUrl, filename);
  11284. }
  11285. openOrDownloadData(element, data, filename) {
  11286. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  11287. const contentType = isPdfData ? "application/pdf" : "";
  11288. if (isPdfData && !_app_options.compatibilityParams.disableCreateObjectURL) {
  11289. let blobUrl = this._openBlobUrls.get(element);
  11290. if (!blobUrl) {
  11291. blobUrl = URL.createObjectURL(new Blob([data], {
  11292. type: contentType
  11293. }));
  11294. this._openBlobUrls.set(element, blobUrl);
  11295. }
  11296. let viewerUrl;
  11297. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  11298. try {
  11299. window.open(viewerUrl);
  11300. return true;
  11301. } catch (ex) {
  11302. console.error(`openOrDownloadData: ${ex}`);
  11303. URL.revokeObjectURL(blobUrl);
  11304. this._openBlobUrls.delete(element);
  11305. }
  11306. }
  11307. this.downloadData(data, filename, contentType);
  11308. return false;
  11309. }
  11310. download(blob, url, filename, sourceEventType = "download") {
  11311. if (_app_options.compatibilityParams.disableCreateObjectURL) {
  11312. this.downloadUrl(url, filename);
  11313. return;
  11314. }
  11315. const blobUrl = URL.createObjectURL(blob);
  11316. download(blobUrl, filename);
  11317. }
  11318. }
  11319. exports.DownloadManager = DownloadManager;
  11320. /***/ }),
  11321. /* 42 */
  11322. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11323. Object.defineProperty(exports, "__esModule", ({
  11324. value: true
  11325. }));
  11326. exports.GenericL10n = void 0;
  11327. __webpack_require__(43);
  11328. var _l10n_utils = __webpack_require__(30);
  11329. const webL10n = document.webL10n;
  11330. class GenericL10n {
  11331. constructor(lang) {
  11332. this._lang = lang;
  11333. this._ready = new Promise((resolve, reject) => {
  11334. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  11335. resolve(webL10n);
  11336. });
  11337. });
  11338. }
  11339. async getLanguage() {
  11340. const l10n = await this._ready;
  11341. return l10n.getLanguage();
  11342. }
  11343. async getDirection() {
  11344. const l10n = await this._ready;
  11345. return l10n.getDirection();
  11346. }
  11347. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  11348. const l10n = await this._ready;
  11349. return l10n.get(key, args, fallback);
  11350. }
  11351. async translate(element) {
  11352. const l10n = await this._ready;
  11353. return l10n.translate(element);
  11354. }
  11355. }
  11356. exports.GenericL10n = GenericL10n;
  11357. /***/ }),
  11358. /* 43 */
  11359. /***/ (() => {
  11360. document.webL10n = function (window, document, undefined) {
  11361. var gL10nData = {};
  11362. var gTextData = '';
  11363. var gTextProp = 'textContent';
  11364. var gLanguage = '';
  11365. var gMacros = {};
  11366. var gReadyState = 'loading';
  11367. var gAsyncResourceLoading = true;
  11368. function getL10nResourceLinks() {
  11369. return document.querySelectorAll('link[type="application/l10n"]');
  11370. }
  11371. function getL10nDictionary() {
  11372. var script = document.querySelector('script[type="application/l10n"]');
  11373. return script ? JSON.parse(script.innerHTML) : null;
  11374. }
  11375. function getTranslatableChildren(element) {
  11376. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  11377. }
  11378. function getL10nAttributes(element) {
  11379. if (!element) return {};
  11380. var l10nId = element.getAttribute('data-l10n-id');
  11381. var l10nArgs = element.getAttribute('data-l10n-args');
  11382. var args = {};
  11383. if (l10nArgs) {
  11384. try {
  11385. args = JSON.parse(l10nArgs);
  11386. } catch (e) {
  11387. console.warn('could not parse arguments for #' + l10nId);
  11388. }
  11389. }
  11390. return {
  11391. id: l10nId,
  11392. args: args
  11393. };
  11394. }
  11395. function xhrLoadText(url, onSuccess, onFailure) {
  11396. onSuccess = onSuccess || function _onSuccess(data) {};
  11397. onFailure = onFailure || function _onFailure() {};
  11398. var xhr = new XMLHttpRequest();
  11399. xhr.open('GET', url, gAsyncResourceLoading);
  11400. if (xhr.overrideMimeType) {
  11401. xhr.overrideMimeType('text/plain; charset=utf-8');
  11402. }
  11403. xhr.onreadystatechange = function () {
  11404. if (xhr.readyState == 4) {
  11405. if (xhr.status == 200 || xhr.status === 0) {
  11406. onSuccess(xhr.responseText);
  11407. } else {
  11408. onFailure();
  11409. }
  11410. }
  11411. };
  11412. xhr.onerror = onFailure;
  11413. xhr.ontimeout = onFailure;
  11414. try {
  11415. xhr.send(null);
  11416. } catch (e) {
  11417. onFailure();
  11418. }
  11419. }
  11420. function parseResource(href, lang, successCallback, failureCallback) {
  11421. var baseURL = href.replace(/[^\/]*$/, '') || './';
  11422. function evalString(text) {
  11423. if (text.lastIndexOf('\\') < 0) return text;
  11424. 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, "'");
  11425. }
  11426. function parseProperties(text, parsedPropertiesCallback) {
  11427. var dictionary = {};
  11428. var reBlank = /^\s*|\s*$/;
  11429. var reComment = /^\s*#|^\s*$/;
  11430. var reSection = /^\s*\[(.*)\]\s*$/;
  11431. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  11432. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  11433. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  11434. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  11435. var currentLang = '*';
  11436. var genericLang = lang.split('-', 1)[0];
  11437. var skipLang = false;
  11438. var match = '';
  11439. function nextEntry() {
  11440. while (true) {
  11441. if (!entries.length) {
  11442. parsedRawLinesCallback();
  11443. return;
  11444. }
  11445. var line = entries.shift();
  11446. if (reComment.test(line)) continue;
  11447. if (extendedSyntax) {
  11448. match = reSection.exec(line);
  11449. if (match) {
  11450. currentLang = match[1].toLowerCase();
  11451. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  11452. continue;
  11453. } else if (skipLang) {
  11454. continue;
  11455. }
  11456. match = reImport.exec(line);
  11457. if (match) {
  11458. loadImport(baseURL + match[1], nextEntry);
  11459. return;
  11460. }
  11461. }
  11462. var tmp = line.match(reSplit);
  11463. if (tmp && tmp.length == 3) {
  11464. dictionary[tmp[1]] = evalString(tmp[2]);
  11465. }
  11466. }
  11467. }
  11468. nextEntry();
  11469. }
  11470. function loadImport(url, callback) {
  11471. xhrLoadText(url, function (content) {
  11472. parseRawLines(content, false, callback);
  11473. }, function () {
  11474. console.warn(url + ' not found.');
  11475. callback();
  11476. });
  11477. }
  11478. parseRawLines(text, true, function () {
  11479. parsedPropertiesCallback(dictionary);
  11480. });
  11481. }
  11482. xhrLoadText(href, function (response) {
  11483. gTextData += response;
  11484. parseProperties(response, function (data) {
  11485. for (var key in data) {
  11486. var id,
  11487. prop,
  11488. index = key.lastIndexOf('.');
  11489. if (index > 0) {
  11490. id = key.substring(0, index);
  11491. prop = key.substring(index + 1);
  11492. } else {
  11493. id = key;
  11494. prop = gTextProp;
  11495. }
  11496. if (!gL10nData[id]) {
  11497. gL10nData[id] = {};
  11498. }
  11499. gL10nData[id][prop] = data[key];
  11500. }
  11501. if (successCallback) {
  11502. successCallback();
  11503. }
  11504. });
  11505. }, failureCallback);
  11506. }
  11507. function loadLocale(lang, callback) {
  11508. if (lang) {
  11509. lang = lang.toLowerCase();
  11510. }
  11511. callback = callback || function _callback() {};
  11512. clear();
  11513. gLanguage = lang;
  11514. var langLinks = getL10nResourceLinks();
  11515. var langCount = langLinks.length;
  11516. if (langCount === 0) {
  11517. var dict = getL10nDictionary();
  11518. if (dict && dict.locales && dict.default_locale) {
  11519. console.log('using the embedded JSON directory, early way out');
  11520. gL10nData = dict.locales[lang];
  11521. if (!gL10nData) {
  11522. var defaultLocale = dict.default_locale.toLowerCase();
  11523. for (var anyCaseLang in dict.locales) {
  11524. anyCaseLang = anyCaseLang.toLowerCase();
  11525. if (anyCaseLang === lang) {
  11526. gL10nData = dict.locales[lang];
  11527. break;
  11528. } else if (anyCaseLang === defaultLocale) {
  11529. gL10nData = dict.locales[defaultLocale];
  11530. }
  11531. }
  11532. }
  11533. callback();
  11534. } else {
  11535. console.log('no resource to load, early way out');
  11536. }
  11537. gReadyState = 'complete';
  11538. return;
  11539. }
  11540. var onResourceLoaded = null;
  11541. var gResourceCount = 0;
  11542. onResourceLoaded = function () {
  11543. gResourceCount++;
  11544. if (gResourceCount >= langCount) {
  11545. callback();
  11546. gReadyState = 'complete';
  11547. }
  11548. };
  11549. function L10nResourceLink(link) {
  11550. var href = link.href;
  11551. this.load = function (lang, callback) {
  11552. parseResource(href, lang, callback, function () {
  11553. console.warn(href + ' not found.');
  11554. console.warn('"' + lang + '" resource not found');
  11555. gLanguage = '';
  11556. callback();
  11557. });
  11558. };
  11559. }
  11560. for (var i = 0; i < langCount; i++) {
  11561. var resource = new L10nResourceLink(langLinks[i]);
  11562. resource.load(lang, onResourceLoaded);
  11563. }
  11564. }
  11565. function clear() {
  11566. gL10nData = {};
  11567. gTextData = '';
  11568. gLanguage = '';
  11569. }
  11570. function getPluralRules(lang) {
  11571. var locales2rules = {
  11572. 'af': 3,
  11573. 'ak': 4,
  11574. 'am': 4,
  11575. 'ar': 1,
  11576. 'asa': 3,
  11577. 'az': 0,
  11578. 'be': 11,
  11579. 'bem': 3,
  11580. 'bez': 3,
  11581. 'bg': 3,
  11582. 'bh': 4,
  11583. 'bm': 0,
  11584. 'bn': 3,
  11585. 'bo': 0,
  11586. 'br': 20,
  11587. 'brx': 3,
  11588. 'bs': 11,
  11589. 'ca': 3,
  11590. 'cgg': 3,
  11591. 'chr': 3,
  11592. 'cs': 12,
  11593. 'cy': 17,
  11594. 'da': 3,
  11595. 'de': 3,
  11596. 'dv': 3,
  11597. 'dz': 0,
  11598. 'ee': 3,
  11599. 'el': 3,
  11600. 'en': 3,
  11601. 'eo': 3,
  11602. 'es': 3,
  11603. 'et': 3,
  11604. 'eu': 3,
  11605. 'fa': 0,
  11606. 'ff': 5,
  11607. 'fi': 3,
  11608. 'fil': 4,
  11609. 'fo': 3,
  11610. 'fr': 5,
  11611. 'fur': 3,
  11612. 'fy': 3,
  11613. 'ga': 8,
  11614. 'gd': 24,
  11615. 'gl': 3,
  11616. 'gsw': 3,
  11617. 'gu': 3,
  11618. 'guw': 4,
  11619. 'gv': 23,
  11620. 'ha': 3,
  11621. 'haw': 3,
  11622. 'he': 2,
  11623. 'hi': 4,
  11624. 'hr': 11,
  11625. 'hu': 0,
  11626. 'id': 0,
  11627. 'ig': 0,
  11628. 'ii': 0,
  11629. 'is': 3,
  11630. 'it': 3,
  11631. 'iu': 7,
  11632. 'ja': 0,
  11633. 'jmc': 3,
  11634. 'jv': 0,
  11635. 'ka': 0,
  11636. 'kab': 5,
  11637. 'kaj': 3,
  11638. 'kcg': 3,
  11639. 'kde': 0,
  11640. 'kea': 0,
  11641. 'kk': 3,
  11642. 'kl': 3,
  11643. 'km': 0,
  11644. 'kn': 0,
  11645. 'ko': 0,
  11646. 'ksb': 3,
  11647. 'ksh': 21,
  11648. 'ku': 3,
  11649. 'kw': 7,
  11650. 'lag': 18,
  11651. 'lb': 3,
  11652. 'lg': 3,
  11653. 'ln': 4,
  11654. 'lo': 0,
  11655. 'lt': 10,
  11656. 'lv': 6,
  11657. 'mas': 3,
  11658. 'mg': 4,
  11659. 'mk': 16,
  11660. 'ml': 3,
  11661. 'mn': 3,
  11662. 'mo': 9,
  11663. 'mr': 3,
  11664. 'ms': 0,
  11665. 'mt': 15,
  11666. 'my': 0,
  11667. 'nah': 3,
  11668. 'naq': 7,
  11669. 'nb': 3,
  11670. 'nd': 3,
  11671. 'ne': 3,
  11672. 'nl': 3,
  11673. 'nn': 3,
  11674. 'no': 3,
  11675. 'nr': 3,
  11676. 'nso': 4,
  11677. 'ny': 3,
  11678. 'nyn': 3,
  11679. 'om': 3,
  11680. 'or': 3,
  11681. 'pa': 3,
  11682. 'pap': 3,
  11683. 'pl': 13,
  11684. 'ps': 3,
  11685. 'pt': 3,
  11686. 'rm': 3,
  11687. 'ro': 9,
  11688. 'rof': 3,
  11689. 'ru': 11,
  11690. 'rwk': 3,
  11691. 'sah': 0,
  11692. 'saq': 3,
  11693. 'se': 7,
  11694. 'seh': 3,
  11695. 'ses': 0,
  11696. 'sg': 0,
  11697. 'sh': 11,
  11698. 'shi': 19,
  11699. 'sk': 12,
  11700. 'sl': 14,
  11701. 'sma': 7,
  11702. 'smi': 7,
  11703. 'smj': 7,
  11704. 'smn': 7,
  11705. 'sms': 7,
  11706. 'sn': 3,
  11707. 'so': 3,
  11708. 'sq': 3,
  11709. 'sr': 11,
  11710. 'ss': 3,
  11711. 'ssy': 3,
  11712. 'st': 3,
  11713. 'sv': 3,
  11714. 'sw': 3,
  11715. 'syr': 3,
  11716. 'ta': 3,
  11717. 'te': 3,
  11718. 'teo': 3,
  11719. 'th': 0,
  11720. 'ti': 4,
  11721. 'tig': 3,
  11722. 'tk': 3,
  11723. 'tl': 4,
  11724. 'tn': 3,
  11725. 'to': 0,
  11726. 'tr': 0,
  11727. 'ts': 3,
  11728. 'tzm': 22,
  11729. 'uk': 11,
  11730. 'ur': 3,
  11731. 've': 3,
  11732. 'vi': 0,
  11733. 'vun': 3,
  11734. 'wa': 4,
  11735. 'wae': 3,
  11736. 'wo': 0,
  11737. 'xh': 3,
  11738. 'xog': 3,
  11739. 'yo': 0,
  11740. 'zh': 0,
  11741. 'zu': 3
  11742. };
  11743. function isIn(n, list) {
  11744. return list.indexOf(n) !== -1;
  11745. }
  11746. function isBetween(n, start, end) {
  11747. return start <= n && n <= end;
  11748. }
  11749. var pluralRules = {
  11750. '0': function (n) {
  11751. return 'other';
  11752. },
  11753. '1': function (n) {
  11754. if (isBetween(n % 100, 3, 10)) return 'few';
  11755. if (n === 0) return 'zero';
  11756. if (isBetween(n % 100, 11, 99)) return 'many';
  11757. if (n == 2) return 'two';
  11758. if (n == 1) return 'one';
  11759. return 'other';
  11760. },
  11761. '2': function (n) {
  11762. if (n !== 0 && n % 10 === 0) return 'many';
  11763. if (n == 2) return 'two';
  11764. if (n == 1) return 'one';
  11765. return 'other';
  11766. },
  11767. '3': function (n) {
  11768. if (n == 1) return 'one';
  11769. return 'other';
  11770. },
  11771. '4': function (n) {
  11772. if (isBetween(n, 0, 1)) return 'one';
  11773. return 'other';
  11774. },
  11775. '5': function (n) {
  11776. if (isBetween(n, 0, 2) && n != 2) return 'one';
  11777. return 'other';
  11778. },
  11779. '6': function (n) {
  11780. if (n === 0) return 'zero';
  11781. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11782. return 'other';
  11783. },
  11784. '7': function (n) {
  11785. if (n == 2) return 'two';
  11786. if (n == 1) return 'one';
  11787. return 'other';
  11788. },
  11789. '8': function (n) {
  11790. if (isBetween(n, 3, 6)) return 'few';
  11791. if (isBetween(n, 7, 10)) return 'many';
  11792. if (n == 2) return 'two';
  11793. if (n == 1) return 'one';
  11794. return 'other';
  11795. },
  11796. '9': function (n) {
  11797. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  11798. if (n == 1) return 'one';
  11799. return 'other';
  11800. },
  11801. '10': function (n) {
  11802. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  11803. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  11804. return 'other';
  11805. },
  11806. '11': function (n) {
  11807. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11808. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  11809. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11810. return 'other';
  11811. },
  11812. '12': function (n) {
  11813. if (isBetween(n, 2, 4)) return 'few';
  11814. if (n == 1) return 'one';
  11815. return 'other';
  11816. },
  11817. '13': function (n) {
  11818. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11819. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  11820. if (n == 1) return 'one';
  11821. return 'other';
  11822. },
  11823. '14': function (n) {
  11824. if (isBetween(n % 100, 3, 4)) return 'few';
  11825. if (n % 100 == 2) return 'two';
  11826. if (n % 100 == 1) return 'one';
  11827. return 'other';
  11828. },
  11829. '15': function (n) {
  11830. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  11831. if (isBetween(n % 100, 11, 19)) return 'many';
  11832. if (n == 1) return 'one';
  11833. return 'other';
  11834. },
  11835. '16': function (n) {
  11836. if (n % 10 == 1 && n != 11) return 'one';
  11837. return 'other';
  11838. },
  11839. '17': function (n) {
  11840. if (n == 3) return 'few';
  11841. if (n === 0) return 'zero';
  11842. if (n == 6) return 'many';
  11843. if (n == 2) return 'two';
  11844. if (n == 1) return 'one';
  11845. return 'other';
  11846. },
  11847. '18': function (n) {
  11848. if (n === 0) return 'zero';
  11849. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  11850. return 'other';
  11851. },
  11852. '19': function (n) {
  11853. if (isBetween(n, 2, 10)) return 'few';
  11854. if (isBetween(n, 0, 1)) return 'one';
  11855. return 'other';
  11856. },
  11857. '20': function (n) {
  11858. 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';
  11859. if (n % 1000000 === 0 && n !== 0) return 'many';
  11860. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  11861. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  11862. return 'other';
  11863. },
  11864. '21': function (n) {
  11865. if (n === 0) return 'zero';
  11866. if (n == 1) return 'one';
  11867. return 'other';
  11868. },
  11869. '22': function (n) {
  11870. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  11871. return 'other';
  11872. },
  11873. '23': function (n) {
  11874. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  11875. return 'other';
  11876. },
  11877. '24': function (n) {
  11878. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  11879. if (isIn(n, [2, 12])) return 'two';
  11880. if (isIn(n, [1, 11])) return 'one';
  11881. return 'other';
  11882. }
  11883. };
  11884. var index = locales2rules[lang.replace(/-.*$/, '')];
  11885. if (!(index in pluralRules)) {
  11886. console.warn('plural form unknown for [' + lang + ']');
  11887. return function () {
  11888. return 'other';
  11889. };
  11890. }
  11891. return pluralRules[index];
  11892. }
  11893. gMacros.plural = function (str, param, key, prop) {
  11894. var n = parseFloat(param);
  11895. if (isNaN(n)) return str;
  11896. if (prop != gTextProp) return str;
  11897. if (!gMacros._pluralRules) {
  11898. gMacros._pluralRules = getPluralRules(gLanguage);
  11899. }
  11900. var index = '[' + gMacros._pluralRules(n) + ']';
  11901. if (n === 0 && key + '[zero]' in gL10nData) {
  11902. str = gL10nData[key + '[zero]'][prop];
  11903. } else if (n == 1 && key + '[one]' in gL10nData) {
  11904. str = gL10nData[key + '[one]'][prop];
  11905. } else if (n == 2 && key + '[two]' in gL10nData) {
  11906. str = gL10nData[key + '[two]'][prop];
  11907. } else if (key + index in gL10nData) {
  11908. str = gL10nData[key + index][prop];
  11909. } else if (key + '[other]' in gL10nData) {
  11910. str = gL10nData[key + '[other]'][prop];
  11911. }
  11912. return str;
  11913. };
  11914. function getL10nData(key, args, fallback) {
  11915. var data = gL10nData[key];
  11916. if (!data) {
  11917. console.warn('#' + key + ' is undefined.');
  11918. if (!fallback) {
  11919. return null;
  11920. }
  11921. data = fallback;
  11922. }
  11923. var rv = {};
  11924. for (var prop in data) {
  11925. var str = data[prop];
  11926. str = substIndexes(str, args, key, prop);
  11927. str = substArguments(str, args, key);
  11928. rv[prop] = str;
  11929. }
  11930. return rv;
  11931. }
  11932. function substIndexes(str, args, key, prop) {
  11933. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  11934. var reMatch = reIndex.exec(str);
  11935. if (!reMatch || !reMatch.length) return str;
  11936. var macroName = reMatch[1];
  11937. var paramName = reMatch[2];
  11938. var param;
  11939. if (args && paramName in args) {
  11940. param = args[paramName];
  11941. } else if (paramName in gL10nData) {
  11942. param = gL10nData[paramName];
  11943. }
  11944. if (macroName in gMacros) {
  11945. var macro = gMacros[macroName];
  11946. str = macro(str, param, key, prop);
  11947. }
  11948. return str;
  11949. }
  11950. function substArguments(str, args, key) {
  11951. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  11952. return str.replace(reArgs, function (matched_text, arg) {
  11953. if (args && arg in args) {
  11954. return args[arg];
  11955. }
  11956. if (arg in gL10nData) {
  11957. return gL10nData[arg];
  11958. }
  11959. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  11960. return matched_text;
  11961. });
  11962. }
  11963. function translateElement(element) {
  11964. var l10n = getL10nAttributes(element);
  11965. if (!l10n.id) return;
  11966. var data = getL10nData(l10n.id, l10n.args);
  11967. if (!data) {
  11968. console.warn('#' + l10n.id + ' is undefined.');
  11969. return;
  11970. }
  11971. if (data[gTextProp]) {
  11972. if (getChildElementCount(element) === 0) {
  11973. element[gTextProp] = data[gTextProp];
  11974. } else {
  11975. var children = element.childNodes;
  11976. var found = false;
  11977. for (var i = 0, l = children.length; i < l; i++) {
  11978. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  11979. if (found) {
  11980. children[i].nodeValue = '';
  11981. } else {
  11982. children[i].nodeValue = data[gTextProp];
  11983. found = true;
  11984. }
  11985. }
  11986. }
  11987. if (!found) {
  11988. var textNode = document.createTextNode(data[gTextProp]);
  11989. element.insertBefore(textNode, element.firstChild);
  11990. }
  11991. }
  11992. delete data[gTextProp];
  11993. }
  11994. for (var k in data) {
  11995. element[k] = data[k];
  11996. }
  11997. }
  11998. function getChildElementCount(element) {
  11999. if (element.children) {
  12000. return element.children.length;
  12001. }
  12002. if (typeof element.childElementCount !== 'undefined') {
  12003. return element.childElementCount;
  12004. }
  12005. var count = 0;
  12006. for (var i = 0; i < element.childNodes.length; i++) {
  12007. count += element.nodeType === 1 ? 1 : 0;
  12008. }
  12009. return count;
  12010. }
  12011. function translateFragment(element) {
  12012. element = element || document.documentElement;
  12013. var children = getTranslatableChildren(element);
  12014. var elementCount = children.length;
  12015. for (var i = 0; i < elementCount; i++) {
  12016. translateElement(children[i]);
  12017. }
  12018. translateElement(element);
  12019. }
  12020. return {
  12021. get: function (key, args, fallbackString) {
  12022. var index = key.lastIndexOf('.');
  12023. var prop = gTextProp;
  12024. if (index > 0) {
  12025. prop = key.substring(index + 1);
  12026. key = key.substring(0, index);
  12027. }
  12028. var fallback;
  12029. if (fallbackString) {
  12030. fallback = {};
  12031. fallback[prop] = fallbackString;
  12032. }
  12033. var data = getL10nData(key, args, fallback);
  12034. if (data && prop in data) {
  12035. return data[prop];
  12036. }
  12037. return '{{' + key + '}}';
  12038. },
  12039. getData: function () {
  12040. return gL10nData;
  12041. },
  12042. getText: function () {
  12043. return gTextData;
  12044. },
  12045. getLanguage: function () {
  12046. return gLanguage;
  12047. },
  12048. setLanguage: function (lang, callback) {
  12049. loadLocale(lang, function () {
  12050. if (callback) callback();
  12051. });
  12052. },
  12053. getDirection: function () {
  12054. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  12055. var shortCode = gLanguage.split('-', 1)[0];
  12056. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  12057. },
  12058. translate: translateFragment,
  12059. getReadyState: function () {
  12060. return gReadyState;
  12061. },
  12062. ready: function (callback) {
  12063. if (!callback) {
  12064. return;
  12065. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  12066. window.setTimeout(function () {
  12067. callback();
  12068. });
  12069. } else if (document.addEventListener) {
  12070. document.addEventListener('localized', function once() {
  12071. document.removeEventListener('localized', once);
  12072. callback();
  12073. });
  12074. }
  12075. }
  12076. };
  12077. }(window, document);
  12078. /***/ }),
  12079. /* 44 */
  12080. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12081. Object.defineProperty(exports, "__esModule", ({
  12082. value: true
  12083. }));
  12084. exports.GenericScripting = void 0;
  12085. exports.docPropertiesLookup = docPropertiesLookup;
  12086. var _pdfjsLib = __webpack_require__(5);
  12087. async function docPropertiesLookup(pdfDocument) {
  12088. const url = "",
  12089. baseUrl = url.split("#")[0];
  12090. let {
  12091. info,
  12092. metadata,
  12093. contentDispositionFilename,
  12094. contentLength
  12095. } = await pdfDocument.getMetadata();
  12096. if (!contentLength) {
  12097. const {
  12098. length
  12099. } = await pdfDocument.getDownloadInfo();
  12100. contentLength = length;
  12101. }
  12102. return { ...info,
  12103. baseURL: baseUrl,
  12104. filesize: contentLength,
  12105. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  12106. metadata: metadata?.getRaw(),
  12107. authors: metadata?.get("dc:creator"),
  12108. numPages: pdfDocument.numPages,
  12109. URL: url
  12110. };
  12111. }
  12112. class GenericScripting {
  12113. constructor(sandboxBundleSrc) {
  12114. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  12115. return window.pdfjsSandbox.QuickJSSandbox();
  12116. });
  12117. }
  12118. async createSandbox(data) {
  12119. const sandbox = await this._ready;
  12120. sandbox.create(data);
  12121. }
  12122. async dispatchEventInSandbox(event) {
  12123. const sandbox = await this._ready;
  12124. sandbox.dispatchEvent(event);
  12125. }
  12126. async destroySandbox() {
  12127. const sandbox = await this._ready;
  12128. sandbox.nukeSandbox();
  12129. }
  12130. }
  12131. exports.GenericScripting = GenericScripting;
  12132. /***/ }),
  12133. /* 45 */
  12134. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12135. Object.defineProperty(exports, "__esModule", ({
  12136. value: true
  12137. }));
  12138. exports.PDFPrintService = PDFPrintService;
  12139. var _pdfjsLib = __webpack_require__(5);
  12140. var _app = __webpack_require__(2);
  12141. var _app_options = __webpack_require__(1);
  12142. var _print_utils = __webpack_require__(46);
  12143. let activeService = null;
  12144. let overlayManager = null;
  12145. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise) {
  12146. const scratchCanvas = activeService.scratchCanvas;
  12147. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  12148. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  12149. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  12150. const ctx = scratchCanvas.getContext("2d");
  12151. ctx.save();
  12152. ctx.fillStyle = "rgb(255, 255, 255)";
  12153. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  12154. ctx.restore();
  12155. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  12156. const renderContext = {
  12157. canvasContext: ctx,
  12158. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  12159. viewport: pdfPage.getViewport({
  12160. scale: 1,
  12161. rotation: size.rotation
  12162. }),
  12163. intent: "print",
  12164. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  12165. optionalContentConfigPromise
  12166. };
  12167. return pdfPage.render(renderContext).promise;
  12168. });
  12169. }
  12170. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, l10n) {
  12171. this.pdfDocument = pdfDocument;
  12172. this.pagesOverview = pagesOverview;
  12173. this.printContainer = printContainer;
  12174. this._printResolution = printResolution || 150;
  12175. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  12176. this.l10n = l10n;
  12177. this.currentPage = -1;
  12178. this.scratchCanvas = document.createElement("canvas");
  12179. }
  12180. PDFPrintService.prototype = {
  12181. layout() {
  12182. this.throwIfInactive();
  12183. const body = document.querySelector("body");
  12184. body.setAttribute("data-pdfjsprinting", true);
  12185. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  12186. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  12187. }, this);
  12188. if (!hasEqualPageSizes) {
  12189. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  12190. }
  12191. this.pageStyleSheet = document.createElement("style");
  12192. const pageSize = this.pagesOverview[0];
  12193. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  12194. body.appendChild(this.pageStyleSheet);
  12195. },
  12196. destroy() {
  12197. if (activeService !== this) {
  12198. return;
  12199. }
  12200. this.printContainer.textContent = "";
  12201. const body = document.querySelector("body");
  12202. body.removeAttribute("data-pdfjsprinting");
  12203. if (this.pageStyleSheet) {
  12204. this.pageStyleSheet.remove();
  12205. this.pageStyleSheet = null;
  12206. }
  12207. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  12208. this.scratchCanvas = null;
  12209. activeService = null;
  12210. ensureOverlay().then(function () {
  12211. if (overlayManager.active !== "printServiceOverlay") {
  12212. return;
  12213. }
  12214. overlayManager.close("printServiceOverlay");
  12215. });
  12216. },
  12217. renderPages() {
  12218. if (this.pdfDocument.isPureXfa) {
  12219. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  12220. return Promise.resolve();
  12221. }
  12222. const pageCount = this.pagesOverview.length;
  12223. const renderNextPage = (resolve, reject) => {
  12224. this.throwIfInactive();
  12225. if (++this.currentPage >= pageCount) {
  12226. renderProgress(pageCount, pageCount, this.l10n);
  12227. resolve();
  12228. return;
  12229. }
  12230. const index = this.currentPage;
  12231. renderProgress(index, pageCount, this.l10n);
  12232. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise).then(this.useRenderedPage.bind(this)).then(function () {
  12233. renderNextPage(resolve, reject);
  12234. }, reject);
  12235. };
  12236. return new Promise(renderNextPage);
  12237. },
  12238. useRenderedPage() {
  12239. this.throwIfInactive();
  12240. const img = document.createElement("img");
  12241. const scratchCanvas = this.scratchCanvas;
  12242. if ("toBlob" in scratchCanvas && !_app_options.compatibilityParams.disableCreateObjectURL) {
  12243. scratchCanvas.toBlob(function (blob) {
  12244. img.src = URL.createObjectURL(blob);
  12245. });
  12246. } else {
  12247. img.src = scratchCanvas.toDataURL();
  12248. }
  12249. const wrapper = document.createElement("div");
  12250. wrapper.className = "printedPage";
  12251. wrapper.appendChild(img);
  12252. this.printContainer.appendChild(wrapper);
  12253. return new Promise(function (resolve, reject) {
  12254. img.onload = resolve;
  12255. img.onerror = reject;
  12256. });
  12257. },
  12258. performPrint() {
  12259. this.throwIfInactive();
  12260. return new Promise(resolve => {
  12261. setTimeout(() => {
  12262. if (!this.active) {
  12263. resolve();
  12264. return;
  12265. }
  12266. print.call(window);
  12267. setTimeout(resolve, 20);
  12268. }, 0);
  12269. });
  12270. },
  12271. get active() {
  12272. return this === activeService;
  12273. },
  12274. throwIfInactive() {
  12275. if (!this.active) {
  12276. throw new Error("This print request was cancelled or completed.");
  12277. }
  12278. }
  12279. };
  12280. const print = window.print;
  12281. window.print = function () {
  12282. if (activeService) {
  12283. console.warn("Ignored window.print() because of a pending print job.");
  12284. return;
  12285. }
  12286. ensureOverlay().then(function () {
  12287. if (activeService) {
  12288. overlayManager.open("printServiceOverlay");
  12289. }
  12290. });
  12291. try {
  12292. dispatchEvent("beforeprint");
  12293. } finally {
  12294. if (!activeService) {
  12295. console.error("Expected print service to be initialized.");
  12296. ensureOverlay().then(function () {
  12297. if (overlayManager.active === "printServiceOverlay") {
  12298. overlayManager.close("printServiceOverlay");
  12299. }
  12300. });
  12301. return;
  12302. }
  12303. const activeServiceOnEntry = activeService;
  12304. activeService.renderPages().then(function () {
  12305. return activeServiceOnEntry.performPrint();
  12306. }).catch(function () {}).then(function () {
  12307. if (activeServiceOnEntry.active) {
  12308. abort();
  12309. }
  12310. });
  12311. }
  12312. };
  12313. function dispatchEvent(eventType) {
  12314. const event = document.createEvent("CustomEvent");
  12315. event.initCustomEvent(eventType, false, false, "custom");
  12316. window.dispatchEvent(event);
  12317. }
  12318. function abort() {
  12319. if (activeService) {
  12320. activeService.destroy();
  12321. dispatchEvent("afterprint");
  12322. }
  12323. }
  12324. function renderProgress(index, total, l10n) {
  12325. const progressContainer = document.getElementById("printServiceOverlay");
  12326. const progress = Math.round(100 * index / total);
  12327. const progressBar = progressContainer.querySelector("progress");
  12328. const progressPerc = progressContainer.querySelector(".relative-progress");
  12329. progressBar.value = progress;
  12330. l10n.get("print_progress_percent", {
  12331. progress
  12332. }).then(msg => {
  12333. progressPerc.textContent = msg;
  12334. });
  12335. }
  12336. window.addEventListener("keydown", function (event) {
  12337. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  12338. window.print();
  12339. event.preventDefault();
  12340. if (event.stopImmediatePropagation) {
  12341. event.stopImmediatePropagation();
  12342. } else {
  12343. event.stopPropagation();
  12344. }
  12345. }
  12346. }, true);
  12347. if ("onbeforeprint" in window) {
  12348. const stopPropagationIfNeeded = function (event) {
  12349. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  12350. event.stopImmediatePropagation();
  12351. }
  12352. };
  12353. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  12354. window.addEventListener("afterprint", stopPropagationIfNeeded);
  12355. }
  12356. let overlayPromise;
  12357. function ensureOverlay() {
  12358. if (!overlayPromise) {
  12359. overlayManager = _app.PDFViewerApplication.overlayManager;
  12360. if (!overlayManager) {
  12361. throw new Error("The overlay manager has not yet been initialized.");
  12362. }
  12363. overlayPromise = overlayManager.register("printServiceOverlay", document.getElementById("printServiceOverlay"), abort, true);
  12364. document.getElementById("printCancel").onclick = abort;
  12365. }
  12366. return overlayPromise;
  12367. }
  12368. _app.PDFPrintServiceFactory.instance = {
  12369. supportsPrinting: true,
  12370. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n) {
  12371. if (activeService) {
  12372. throw new Error("The print service is created and active.");
  12373. }
  12374. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n);
  12375. return activeService;
  12376. }
  12377. };
  12378. /***/ }),
  12379. /* 46 */
  12380. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12381. Object.defineProperty(exports, "__esModule", ({
  12382. value: true
  12383. }));
  12384. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  12385. var _pdfjsLib = __webpack_require__(5);
  12386. var _pdf_link_service = __webpack_require__(18);
  12387. var _xfa_layer_builder = __webpack_require__(35);
  12388. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  12389. const xfaHtml = pdfDocument.allXfaHtml;
  12390. const linkService = new _pdf_link_service.SimpleLinkService();
  12391. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  12392. for (const xfaPage of xfaHtml.children) {
  12393. const page = document.createElement("div");
  12394. page.className = "xfaPrintedPage";
  12395. printContainer.appendChild(page);
  12396. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  12397. pageDiv: page,
  12398. pdfPage: null,
  12399. annotationStorage: pdfDocument.annotationStorage,
  12400. linkService,
  12401. xfaHtml: xfaPage
  12402. });
  12403. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  12404. scale
  12405. });
  12406. builder.render(viewport, "print");
  12407. }
  12408. }
  12409. /***/ })
  12410. /******/ ]);
  12411. /************************************************************************/
  12412. /******/ // The module cache
  12413. /******/ var __webpack_module_cache__ = {};
  12414. /******/
  12415. /******/ // The require function
  12416. /******/ function __webpack_require__(moduleId) {
  12417. /******/ // Check if module is in cache
  12418. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  12419. /******/ if (cachedModule !== undefined) {
  12420. /******/ return cachedModule.exports;
  12421. /******/ }
  12422. /******/ // Create a new module (and put it into the cache)
  12423. /******/ var module = __webpack_module_cache__[moduleId] = {
  12424. /******/ // no module.id needed
  12425. /******/ // no module.loaded needed
  12426. /******/ exports: {}
  12427. /******/ };
  12428. /******/
  12429. /******/ // Execute the module function
  12430. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  12431. /******/
  12432. /******/ // Return the exports of the module
  12433. /******/ return module.exports;
  12434. /******/ }
  12435. /******/
  12436. /************************************************************************/
  12437. var __webpack_exports__ = {};
  12438. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  12439. (() => {
  12440. var exports = __webpack_exports__;
  12441. Object.defineProperty(exports, "__esModule", ({
  12442. value: true
  12443. }));
  12444. Object.defineProperty(exports, "PDFViewerApplication", ({
  12445. enumerable: true,
  12446. get: function () {
  12447. return _app.PDFViewerApplication;
  12448. }
  12449. }));
  12450. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  12451. enumerable: true,
  12452. get: function () {
  12453. return _app_options.AppOptions;
  12454. }
  12455. }));
  12456. var _app_options = __webpack_require__(1);
  12457. var _app = __webpack_require__(2);
  12458. const pdfjsVersion = '2.12.313';
  12459. const pdfjsBuild = 'a2ae56f39';
  12460. window.PDFViewerApplication = _app.PDFViewerApplication;
  12461. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  12462. ;
  12463. ;
  12464. {
  12465. __webpack_require__(39);
  12466. }
  12467. ;
  12468. {
  12469. __webpack_require__(45);
  12470. }
  12471. function getViewerConfiguration() {
  12472. let errorWrapper = null;
  12473. errorWrapper = {
  12474. container: document.getElementById("errorWrapper"),
  12475. errorMessage: document.getElementById("errorMessage"),
  12476. closeButton: document.getElementById("errorClose"),
  12477. errorMoreInfo: document.getElementById("errorMoreInfo"),
  12478. moreInfoButton: document.getElementById("errorShowMore"),
  12479. lessInfoButton: document.getElementById("errorShowLess")
  12480. };
  12481. return {
  12482. appContainer: document.body,
  12483. mainContainer: document.getElementById("viewerContainer"),
  12484. viewerContainer: document.getElementById("viewer"),
  12485. eventBus: null,
  12486. toolbar: {
  12487. container: document.getElementById("toolbarViewer"),
  12488. numPages: document.getElementById("numPages"),
  12489. pageNumber: document.getElementById("pageNumber"),
  12490. scaleSelect: document.getElementById("scaleSelect"),
  12491. customScaleOption: document.getElementById("customScaleOption"),
  12492. previous: document.getElementById("previous"),
  12493. next: document.getElementById("next"),
  12494. zoomIn: document.getElementById("zoomIn"),
  12495. zoomOut: document.getElementById("zoomOut"),
  12496. viewFind: document.getElementById("viewFind"),
  12497. openFile: document.getElementById("openFile"),
  12498. print: document.getElementById("print"),
  12499. presentationModeButton: document.getElementById("presentationMode"),
  12500. download: document.getElementById("download"),
  12501. viewBookmark: document.getElementById("viewBookmark")
  12502. },
  12503. secondaryToolbar: {
  12504. toolbar: document.getElementById("secondaryToolbar"),
  12505. toggleButton: document.getElementById("secondaryToolbarToggle"),
  12506. toolbarButtonContainer: document.getElementById("secondaryToolbarButtonContainer"),
  12507. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  12508. openFileButton: document.getElementById("secondaryOpenFile"),
  12509. printButton: document.getElementById("secondaryPrint"),
  12510. downloadButton: document.getElementById("secondaryDownload"),
  12511. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  12512. firstPageButton: document.getElementById("firstPage"),
  12513. lastPageButton: document.getElementById("lastPage"),
  12514. pageRotateCwButton: document.getElementById("pageRotateCw"),
  12515. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  12516. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  12517. cursorHandToolButton: document.getElementById("cursorHandTool"),
  12518. scrollPageButton: document.getElementById("scrollPage"),
  12519. scrollVerticalButton: document.getElementById("scrollVertical"),
  12520. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  12521. scrollWrappedButton: document.getElementById("scrollWrapped"),
  12522. spreadNoneButton: document.getElementById("spreadNone"),
  12523. spreadOddButton: document.getElementById("spreadOdd"),
  12524. spreadEvenButton: document.getElementById("spreadEven"),
  12525. documentPropertiesButton: document.getElementById("documentProperties")
  12526. },
  12527. sidebar: {
  12528. outerContainer: document.getElementById("outerContainer"),
  12529. viewerContainer: document.getElementById("viewerContainer"),
  12530. toggleButton: document.getElementById("sidebarToggle"),
  12531. thumbnailButton: document.getElementById("viewThumbnail"),
  12532. outlineButton: document.getElementById("viewOutline"),
  12533. attachmentsButton: document.getElementById("viewAttachments"),
  12534. layersButton: document.getElementById("viewLayers"),
  12535. thumbnailView: document.getElementById("thumbnailView"),
  12536. outlineView: document.getElementById("outlineView"),
  12537. attachmentsView: document.getElementById("attachmentsView"),
  12538. layersView: document.getElementById("layersView"),
  12539. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  12540. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  12541. },
  12542. sidebarResizer: {
  12543. outerContainer: document.getElementById("outerContainer"),
  12544. resizer: document.getElementById("sidebarResizer")
  12545. },
  12546. findBar: {
  12547. bar: document.getElementById("findbar"),
  12548. toggleButton: document.getElementById("viewFind"),
  12549. findField: document.getElementById("findInput"),
  12550. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  12551. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  12552. entireWordCheckbox: document.getElementById("findEntireWord"),
  12553. findMsg: document.getElementById("findMsg"),
  12554. findResultsCount: document.getElementById("findResultsCount"),
  12555. findPreviousButton: document.getElementById("findPrevious"),
  12556. findNextButton: document.getElementById("findNext")
  12557. },
  12558. passwordOverlay: {
  12559. overlayName: "passwordOverlay",
  12560. container: document.getElementById("passwordOverlay"),
  12561. label: document.getElementById("passwordText"),
  12562. input: document.getElementById("password"),
  12563. submitButton: document.getElementById("passwordSubmit"),
  12564. cancelButton: document.getElementById("passwordCancel")
  12565. },
  12566. documentProperties: {
  12567. overlayName: "documentPropertiesOverlay",
  12568. container: document.getElementById("documentPropertiesOverlay"),
  12569. closeButton: document.getElementById("documentPropertiesClose"),
  12570. fields: {
  12571. fileName: document.getElementById("fileNameField"),
  12572. fileSize: document.getElementById("fileSizeField"),
  12573. title: document.getElementById("titleField"),
  12574. author: document.getElementById("authorField"),
  12575. subject: document.getElementById("subjectField"),
  12576. keywords: document.getElementById("keywordsField"),
  12577. creationDate: document.getElementById("creationDateField"),
  12578. modificationDate: document.getElementById("modificationDateField"),
  12579. creator: document.getElementById("creatorField"),
  12580. producer: document.getElementById("producerField"),
  12581. version: document.getElementById("versionField"),
  12582. pageCount: document.getElementById("pageCountField"),
  12583. pageSize: document.getElementById("pageSizeField"),
  12584. linearized: document.getElementById("linearizedField")
  12585. }
  12586. },
  12587. errorWrapper,
  12588. printContainer: document.getElementById("printContainer"),
  12589. openFileInputName: "fileInput",
  12590. debuggerScriptPath: "./debugger.js"
  12591. };
  12592. }
  12593. function webViewerLoad() {
  12594. const config = getViewerConfiguration();
  12595. const event = document.createEvent("CustomEvent");
  12596. event.initCustomEvent("webviewerloaded", true, true, {
  12597. source: window
  12598. });
  12599. try {
  12600. parent.document.dispatchEvent(event);
  12601. } catch (ex) {
  12602. console.error(`webviewerloaded: ${ex}`);
  12603. document.dispatchEvent(event);
  12604. }
  12605. _app.PDFViewerApplication.run(config);
  12606. }
  12607. if (document.blockUnblockOnload) {
  12608. document.blockUnblockOnload(true);
  12609. }
  12610. if (document.readyState === "interactive" || document.readyState === "complete") {
  12611. webViewerLoad();
  12612. } else {
  12613. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  12614. }
  12615. })();
  12616. /******/ })()
  12617. ;
  12618. //# sourceMappingURL=viewer.js.map