viewer.js 395 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  32. const compatibilityParams = Object.create(null);
  33. exports.compatibilityParams = compatibilityParams;
  34. {
  35. const userAgent = navigator.userAgent || "";
  36. const platform = navigator.platform || "";
  37. const maxTouchPoints = navigator.maxTouchPoints || 1;
  38. const isAndroid = /Android/.test(userAgent);
  39. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  40. (function checkCanvasSizeLimitation() {
  41. if (isIOS || isAndroid) {
  42. compatibilityParams.maxCanvasPixels = 5242880;
  43. }
  44. })();
  45. }
  46. const OptionKind = {
  47. VIEWER: 0x02,
  48. API: 0x04,
  49. WORKER: 0x08,
  50. PREFERENCE: 0x80
  51. };
  52. exports.OptionKind = OptionKind;
  53. const defaultOptions = {
  54. annotationMode: {
  55. value: 2,
  56. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  57. },
  58. cursorToolOnLoad: {
  59. value: 0,
  60. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  61. },
  62. defaultUrl: {
  63. value: "compressed.tracemonkey-pldi-09.pdf",
  64. kind: OptionKind.VIEWER
  65. },
  66. defaultZoomValue: {
  67. value: "",
  68. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  69. },
  70. disableHistory: {
  71. value: false,
  72. kind: OptionKind.VIEWER
  73. },
  74. disablePageLabels: {
  75. value: false,
  76. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  77. },
  78. enablePermissions: {
  79. value: false,
  80. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  81. },
  82. enablePrintAutoRotate: {
  83. value: true,
  84. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  85. },
  86. enableScripting: {
  87. value: true,
  88. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  89. },
  90. externalLinkRel: {
  91. value: "noopener noreferrer nofollow",
  92. kind: OptionKind.VIEWER
  93. },
  94. externalLinkTarget: {
  95. value: 0,
  96. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  97. },
  98. historyUpdateUrl: {
  99. value: false,
  100. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  101. },
  102. ignoreDestinationZoom: {
  103. value: false,
  104. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  105. },
  106. imageResourcesPath: {
  107. value: "./images/",
  108. kind: OptionKind.VIEWER
  109. },
  110. maxCanvasPixels: {
  111. value: 16777216,
  112. compatibility: compatibilityParams.maxCanvasPixels,
  113. kind: OptionKind.VIEWER
  114. },
  115. pdfBugEnabled: {
  116. value: false,
  117. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  118. },
  119. printResolution: {
  120. value: 150,
  121. kind: OptionKind.VIEWER
  122. },
  123. renderer: {
  124. value: "canvas",
  125. kind: OptionKind.VIEWER
  126. },
  127. sidebarViewOnLoad: {
  128. value: -1,
  129. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  130. },
  131. scrollModeOnLoad: {
  132. value: -1,
  133. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  134. },
  135. spreadModeOnLoad: {
  136. value: -1,
  137. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  138. },
  139. textLayerMode: {
  140. value: 1,
  141. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  142. },
  143. useOnlyCssZoom: {
  144. value: false,
  145. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  146. },
  147. viewerCssTheme: {
  148. value: 0,
  149. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  150. },
  151. viewOnLoad: {
  152. value: 0,
  153. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  154. },
  155. cMapPacked: {
  156. value: true,
  157. kind: OptionKind.API
  158. },
  159. cMapUrl: {
  160. value: "../web/cmaps/",
  161. kind: OptionKind.API
  162. },
  163. disableAutoFetch: {
  164. value: false,
  165. kind: OptionKind.API + OptionKind.PREFERENCE
  166. },
  167. disableFontFace: {
  168. value: false,
  169. kind: OptionKind.API + OptionKind.PREFERENCE
  170. },
  171. disableRange: {
  172. value: false,
  173. kind: OptionKind.API + OptionKind.PREFERENCE
  174. },
  175. disableStream: {
  176. value: false,
  177. kind: OptionKind.API + OptionKind.PREFERENCE
  178. },
  179. docBaseUrl: {
  180. value: "",
  181. kind: OptionKind.API
  182. },
  183. enableXfa: {
  184. value: true,
  185. kind: OptionKind.API + OptionKind.PREFERENCE
  186. },
  187. fontExtraProperties: {
  188. value: false,
  189. kind: OptionKind.API
  190. },
  191. isEvalSupported: {
  192. value: true,
  193. kind: OptionKind.API
  194. },
  195. maxImageSize: {
  196. value: -1,
  197. kind: OptionKind.API
  198. },
  199. pdfBug: {
  200. value: false,
  201. kind: OptionKind.API
  202. },
  203. standardFontDataUrl: {
  204. value: "../web/standard_fonts/",
  205. kind: OptionKind.API
  206. },
  207. verbosity: {
  208. value: 1,
  209. kind: OptionKind.API
  210. },
  211. workerPort: {
  212. value: null,
  213. kind: OptionKind.WORKER
  214. },
  215. workerSrc: {
  216. value: "../build/pdf.worker.js",
  217. kind: OptionKind.WORKER
  218. }
  219. };
  220. {
  221. defaultOptions.disablePreferences = {
  222. value: false,
  223. kind: OptionKind.VIEWER
  224. };
  225. defaultOptions.locale = {
  226. value: navigator.language || "en-US",
  227. kind: OptionKind.VIEWER
  228. };
  229. defaultOptions.sandboxBundleSrc = {
  230. value: "../build/pdf.sandbox.js",
  231. kind: OptionKind.VIEWER
  232. };
  233. defaultOptions.renderer.kind += OptionKind.PREFERENCE;
  234. }
  235. const userOptions = Object.create(null);
  236. class AppOptions {
  237. constructor() {
  238. throw new Error("Cannot initialize AppOptions.");
  239. }
  240. static get(name) {
  241. const userOption = userOptions[name];
  242. if (userOption !== undefined) {
  243. return userOption;
  244. }
  245. const defaultOption = defaultOptions[name];
  246. if (defaultOption !== undefined) {
  247. return defaultOption.compatibility ?? defaultOption.value;
  248. }
  249. return undefined;
  250. }
  251. static getAll(kind = null) {
  252. const options = Object.create(null);
  253. for (const name in defaultOptions) {
  254. const defaultOption = defaultOptions[name];
  255. if (kind) {
  256. if ((kind & defaultOption.kind) === 0) {
  257. continue;
  258. }
  259. if (kind === OptionKind.PREFERENCE) {
  260. const value = defaultOption.value,
  261. valueType = typeof value;
  262. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  263. options[name] = value;
  264. continue;
  265. }
  266. throw new Error(`Invalid type for preference: ${name}`);
  267. }
  268. }
  269. const userOption = userOptions[name];
  270. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility ?? defaultOption.value;
  271. }
  272. return options;
  273. }
  274. static set(name, value) {
  275. userOptions[name] = value;
  276. }
  277. static setAll(options) {
  278. for (const name in options) {
  279. userOptions[name] = options[name];
  280. }
  281. }
  282. static remove(name) {
  283. delete userOptions[name];
  284. }
  285. static _hasUserOptions() {
  286. return Object.keys(userOptions).length > 0;
  287. }
  288. }
  289. exports.AppOptions = AppOptions;
  290. /***/ }),
  291. /* 2 */
  292. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  293. Object.defineProperty(exports, "__esModule", ({
  294. value: true
  295. }));
  296. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  297. var _ui_utils = __webpack_require__(3);
  298. var _app_options = __webpack_require__(1);
  299. var _event_utils = __webpack_require__(4);
  300. var _pdfjsLib = __webpack_require__(5);
  301. var _pdf_cursor_tools = __webpack_require__(6);
  302. var _pdf_link_service = __webpack_require__(8);
  303. var _overlay_manager = __webpack_require__(9);
  304. var _password_prompt = __webpack_require__(10);
  305. var _pdf_attachment_viewer = __webpack_require__(11);
  306. var _pdf_document_properties = __webpack_require__(13);
  307. var _pdf_find_bar = __webpack_require__(14);
  308. var _pdf_find_controller = __webpack_require__(15);
  309. var _pdf_history = __webpack_require__(17);
  310. var _pdf_layer_viewer = __webpack_require__(18);
  311. var _pdf_outline_viewer = __webpack_require__(19);
  312. var _pdf_presentation_mode = __webpack_require__(20);
  313. var _pdf_rendering_queue = __webpack_require__(21);
  314. var _pdf_scripting_manager = __webpack_require__(22);
  315. var _pdf_sidebar = __webpack_require__(23);
  316. var _pdf_sidebar_resizer = __webpack_require__(24);
  317. var _pdf_thumbnail_viewer = __webpack_require__(25);
  318. var _pdf_viewer = __webpack_require__(27);
  319. var _secondary_toolbar = __webpack_require__(36);
  320. var _toolbar = __webpack_require__(37);
  321. var _view_history = __webpack_require__(38);
  322. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  323. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  324. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  325. const ViewOnLoad = {
  326. UNKNOWN: -1,
  327. PREVIOUS: 0,
  328. INITIAL: 1
  329. };
  330. const ViewerCssTheme = {
  331. AUTOMATIC: 0,
  332. LIGHT: 1,
  333. DARK: 2
  334. };
  335. 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"];
  336. 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"];
  337. class DefaultExternalServices {
  338. constructor() {
  339. throw new Error("Cannot initialize DefaultExternalServices.");
  340. }
  341. static updateFindControlState(data) {}
  342. static updateFindMatchesCount(data) {}
  343. static initPassiveLoading(callbacks) {}
  344. static async fallback(data) {}
  345. static reportTelemetry(data) {}
  346. static createDownloadManager(options) {
  347. throw new Error("Not implemented: createDownloadManager");
  348. }
  349. static createPreferences() {
  350. throw new Error("Not implemented: createPreferences");
  351. }
  352. static createL10n(options) {
  353. throw new Error("Not implemented: createL10n");
  354. }
  355. static createScripting(options) {
  356. throw new Error("Not implemented: createScripting");
  357. }
  358. static get supportsIntegratedFind() {
  359. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  360. }
  361. static get supportsDocumentFonts() {
  362. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  363. }
  364. static get supportedMouseWheelZoomModifierKeys() {
  365. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  366. ctrlKey: true,
  367. metaKey: true
  368. });
  369. }
  370. static get isInAutomation() {
  371. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  372. }
  373. }
  374. exports.DefaultExternalServices = DefaultExternalServices;
  375. const PDFViewerApplication = {
  376. initialBookmark: document.location.hash.substring(1),
  377. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  378. _fellback: false,
  379. appConfig: null,
  380. pdfDocument: null,
  381. pdfLoadingTask: null,
  382. printService: null,
  383. pdfViewer: null,
  384. pdfThumbnailViewer: null,
  385. pdfRenderingQueue: null,
  386. pdfPresentationMode: null,
  387. pdfDocumentProperties: null,
  388. pdfLinkService: null,
  389. pdfHistory: null,
  390. pdfSidebar: null,
  391. pdfSidebarResizer: null,
  392. pdfOutlineViewer: null,
  393. pdfAttachmentViewer: null,
  394. pdfLayerViewer: null,
  395. pdfCursorTools: null,
  396. pdfScriptingManager: null,
  397. store: null,
  398. downloadManager: null,
  399. overlayManager: null,
  400. preferences: null,
  401. toolbar: null,
  402. secondaryToolbar: null,
  403. eventBus: null,
  404. l10n: null,
  405. isInitialViewSet: false,
  406. downloadComplete: false,
  407. isViewerEmbedded: window.parent !== window,
  408. url: "",
  409. baseUrl: "",
  410. _downloadUrl: "",
  411. externalServices: DefaultExternalServices,
  412. _boundEvents: Object.create(null),
  413. documentInfo: null,
  414. metadata: null,
  415. _contentDispositionFilename: null,
  416. _contentLength: null,
  417. _saveInProgress: false,
  418. _docStats: null,
  419. _wheelUnusedTicks: 0,
  420. _idleCallbacks: new Set(),
  421. async initialize(appConfig) {
  422. this.preferences = this.externalServices.createPreferences();
  423. this.appConfig = appConfig;
  424. await this._readPreferences();
  425. await this._parseHashParameters();
  426. this._forceCssTheme();
  427. await this._initializeL10n();
  428. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  429. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  430. }
  431. await this._initializeViewerComponents();
  432. this.bindEvents();
  433. this.bindWindowEvents();
  434. const appContainer = appConfig.appContainer || document.documentElement;
  435. this.l10n.translate(appContainer).then(() => {
  436. this.eventBus.dispatch("localized", {
  437. source: this
  438. });
  439. });
  440. this._initializedCapability.resolve();
  441. },
  442. async _readPreferences() {
  443. if (_app_options.AppOptions.get("disablePreferences")) {
  444. return;
  445. }
  446. if (_app_options.AppOptions._hasUserOptions()) {
  447. console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  448. }
  449. try {
  450. _app_options.AppOptions.setAll(await this.preferences.getAll());
  451. } catch (reason) {
  452. console.error(`_readPreferences: "${reason?.message}".`);
  453. }
  454. },
  455. async _parseHashParameters() {
  456. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  457. return;
  458. }
  459. const hash = document.location.hash.substring(1);
  460. if (!hash) {
  461. return;
  462. }
  463. const params = (0, _ui_utils.parseQueryString)(hash),
  464. waitOn = [];
  465. if (params.get("disableworker") === "true") {
  466. waitOn.push(loadFakeWorker());
  467. }
  468. if (params.has("disablerange")) {
  469. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  470. }
  471. if (params.has("disablestream")) {
  472. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  473. }
  474. if (params.has("disableautofetch")) {
  475. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  476. }
  477. if (params.has("disablefontface")) {
  478. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  479. }
  480. if (params.has("disablehistory")) {
  481. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  482. }
  483. if (params.has("verbosity")) {
  484. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  485. }
  486. if (params.has("textlayer")) {
  487. switch (params.get("textlayer")) {
  488. case "off":
  489. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  490. break;
  491. case "visible":
  492. case "shadow":
  493. case "hover":
  494. const viewer = this.appConfig.viewerContainer;
  495. viewer.classList.add(`textLayer-${params.get("textlayer")}`);
  496. break;
  497. }
  498. }
  499. if (params.has("pdfbug")) {
  500. _app_options.AppOptions.set("pdfBug", true);
  501. _app_options.AppOptions.set("fontExtraProperties", true);
  502. const enabled = params.get("pdfbug").split(",");
  503. waitOn.push(initPDFBug(enabled));
  504. }
  505. if (params.has("locale")) {
  506. _app_options.AppOptions.set("locale", params.get("locale"));
  507. }
  508. if (waitOn.length === 0) {
  509. return;
  510. }
  511. try {
  512. await Promise.all(waitOn);
  513. } catch (reason) {
  514. console.error(`_parseHashParameters: "${reason.message}".`);
  515. }
  516. },
  517. async _initializeL10n() {
  518. this.l10n = this.externalServices.createL10n({
  519. locale: _app_options.AppOptions.get("locale")
  520. });
  521. const dir = await this.l10n.getDirection();
  522. document.getElementsByTagName("html")[0].dir = dir;
  523. },
  524. _forceCssTheme() {
  525. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  526. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  527. return;
  528. }
  529. try {
  530. const styleSheet = document.styleSheets[0];
  531. const cssRules = styleSheet?.cssRules || [];
  532. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  533. const rule = cssRules[i];
  534. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  535. if (cssTheme === ViewerCssTheme.LIGHT) {
  536. styleSheet.deleteRule(i);
  537. return;
  538. }
  539. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  540. if (darkRules?.[1]) {
  541. styleSheet.deleteRule(i);
  542. styleSheet.insertRule(darkRules[1], i);
  543. }
  544. return;
  545. }
  546. }
  547. } catch (reason) {
  548. console.error(`_forceCssTheme: "${reason?.message}".`);
  549. }
  550. },
  551. async _initializeViewerComponents() {
  552. const {
  553. appConfig,
  554. externalServices
  555. } = this;
  556. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  557. this.eventBus = eventBus;
  558. this.overlayManager = new _overlay_manager.OverlayManager();
  559. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  560. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  561. this.pdfRenderingQueue = pdfRenderingQueue;
  562. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  563. eventBus,
  564. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  565. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  566. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  567. });
  568. this.pdfLinkService = pdfLinkService;
  569. const downloadManager = externalServices.createDownloadManager();
  570. this.downloadManager = downloadManager;
  571. const findController = new _pdf_find_controller.PDFFindController({
  572. linkService: pdfLinkService,
  573. eventBus
  574. });
  575. this.findController = findController;
  576. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  577. eventBus,
  578. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  579. scriptingFactory: externalServices,
  580. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  581. });
  582. this.pdfScriptingManager = pdfScriptingManager;
  583. const container = appConfig.mainContainer;
  584. const viewer = appConfig.viewerContainer;
  585. this.pdfViewer = new _pdf_viewer.PDFViewer({
  586. container,
  587. viewer,
  588. eventBus,
  589. renderingQueue: pdfRenderingQueue,
  590. linkService: pdfLinkService,
  591. downloadManager,
  592. findController,
  593. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  594. renderer: _app_options.AppOptions.get("renderer"),
  595. l10n: this.l10n,
  596. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  597. annotationMode: _app_options.AppOptions.get("annotationMode"),
  598. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  599. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  600. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  601. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  602. enablePermissions: _app_options.AppOptions.get("enablePermissions")
  603. });
  604. pdfRenderingQueue.setViewer(this.pdfViewer);
  605. pdfLinkService.setViewer(this.pdfViewer);
  606. pdfScriptingManager.setViewer(this.pdfViewer);
  607. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  608. container: appConfig.sidebar.thumbnailView,
  609. eventBus,
  610. renderingQueue: pdfRenderingQueue,
  611. linkService: pdfLinkService,
  612. l10n: this.l10n
  613. });
  614. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  615. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  616. this.pdfHistory = new _pdf_history.PDFHistory({
  617. linkService: pdfLinkService,
  618. eventBus
  619. });
  620. pdfLinkService.setHistory(this.pdfHistory);
  621. }
  622. if (!this.supportsIntegratedFind) {
  623. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  624. }
  625. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  626. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  627. container,
  628. eventBus,
  629. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  630. });
  631. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  632. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  633. if (this.supportsFullscreen) {
  634. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  635. container,
  636. pdfViewer: this.pdfViewer,
  637. eventBus
  638. });
  639. }
  640. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  641. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  642. container: appConfig.sidebar.outlineView,
  643. eventBus,
  644. linkService: pdfLinkService
  645. });
  646. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  647. container: appConfig.sidebar.attachmentsView,
  648. eventBus,
  649. downloadManager
  650. });
  651. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  652. container: appConfig.sidebar.layersView,
  653. eventBus,
  654. l10n: this.l10n
  655. });
  656. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  657. elements: appConfig.sidebar,
  658. pdfViewer: this.pdfViewer,
  659. pdfThumbnailViewer: this.pdfThumbnailViewer,
  660. eventBus,
  661. l10n: this.l10n
  662. });
  663. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  664. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  665. },
  666. run(config) {
  667. this.initialize(config).then(webViewerInitialized);
  668. },
  669. get initialized() {
  670. return this._initializedCapability.settled;
  671. },
  672. get initializedPromise() {
  673. return this._initializedCapability.promise;
  674. },
  675. zoomIn(steps) {
  676. if (this.pdfViewer.isInPresentationMode) {
  677. return;
  678. }
  679. this.pdfViewer.increaseScale(steps);
  680. },
  681. zoomOut(steps) {
  682. if (this.pdfViewer.isInPresentationMode) {
  683. return;
  684. }
  685. this.pdfViewer.decreaseScale(steps);
  686. },
  687. zoomReset() {
  688. if (this.pdfViewer.isInPresentationMode) {
  689. return;
  690. }
  691. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  692. },
  693. get pagesCount() {
  694. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  695. },
  696. get page() {
  697. return this.pdfViewer.currentPageNumber;
  698. },
  699. set page(val) {
  700. this.pdfViewer.currentPageNumber = val;
  701. },
  702. get supportsPrinting() {
  703. return PDFPrintServiceFactory.instance.supportsPrinting;
  704. },
  705. get supportsFullscreen() {
  706. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  707. },
  708. get supportsIntegratedFind() {
  709. return this.externalServices.supportsIntegratedFind;
  710. },
  711. get supportsDocumentFonts() {
  712. return this.externalServices.supportsDocumentFonts;
  713. },
  714. get loadingBar() {
  715. const bar = new _ui_utils.ProgressBar("#loadingBar");
  716. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  717. },
  718. get supportedMouseWheelZoomModifierKeys() {
  719. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  720. },
  721. initPassiveLoading() {
  722. throw new Error("Not implemented: initPassiveLoading");
  723. },
  724. setTitleUsingUrl(url = "", downloadUrl = null) {
  725. this.url = url;
  726. this.baseUrl = url.split("#")[0];
  727. if (downloadUrl) {
  728. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  729. }
  730. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  731. if (!title) {
  732. try {
  733. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  734. } catch (ex) {
  735. title = url;
  736. }
  737. }
  738. this.setTitle(title);
  739. },
  740. setTitle(title) {
  741. if (this.isViewerEmbedded) {
  742. return;
  743. }
  744. document.title = title;
  745. },
  746. get _docFilename() {
  747. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  748. },
  749. _hideViewBookmark() {
  750. const {
  751. toolbar,
  752. secondaryToolbar
  753. } = this.appConfig;
  754. toolbar.viewBookmark.hidden = true;
  755. secondaryToolbar.viewBookmarkButton.hidden = true;
  756. },
  757. _cancelIdleCallbacks() {
  758. if (!this._idleCallbacks.size) {
  759. return;
  760. }
  761. for (const callback of this._idleCallbacks) {
  762. window.cancelIdleCallback(callback);
  763. }
  764. this._idleCallbacks.clear();
  765. },
  766. async close() {
  767. this._unblockDocumentLoadEvent();
  768. this._hideViewBookmark();
  769. const {
  770. container
  771. } = this.appConfig.errorWrapper;
  772. container.hidden = true;
  773. if (!this.pdfLoadingTask) {
  774. return;
  775. }
  776. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  777. try {
  778. await this.save({
  779. sourceEventType: "save"
  780. });
  781. } catch (reason) {}
  782. }
  783. const promises = [];
  784. promises.push(this.pdfLoadingTask.destroy());
  785. this.pdfLoadingTask = null;
  786. if (this.pdfDocument) {
  787. this.pdfDocument = null;
  788. this.pdfThumbnailViewer.setDocument(null);
  789. this.pdfViewer.setDocument(null);
  790. this.pdfLinkService.setDocument(null);
  791. this.pdfDocumentProperties.setDocument(null);
  792. }
  793. this.pdfLinkService.externalLinkEnabled = true;
  794. this._fellback = false;
  795. this.store = null;
  796. this.isInitialViewSet = false;
  797. this.downloadComplete = false;
  798. this.url = "";
  799. this.baseUrl = "";
  800. this._downloadUrl = "";
  801. this.documentInfo = null;
  802. this.metadata = null;
  803. this._contentDispositionFilename = null;
  804. this._contentLength = null;
  805. this._saveInProgress = false;
  806. this._docStats = null;
  807. this._cancelIdleCallbacks();
  808. promises.push(this.pdfScriptingManager.destroyPromise);
  809. this.pdfSidebar.reset();
  810. this.pdfOutlineViewer.reset();
  811. this.pdfAttachmentViewer.reset();
  812. this.pdfLayerViewer.reset();
  813. this.pdfHistory?.reset();
  814. this.findBar?.reset();
  815. this.toolbar.reset();
  816. this.secondaryToolbar.reset();
  817. if (typeof PDFBug !== "undefined") {
  818. PDFBug.cleanup();
  819. }
  820. await Promise.all(promises);
  821. },
  822. async open(file, args) {
  823. if (this.pdfLoadingTask) {
  824. await this.close();
  825. }
  826. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  827. for (const key in workerParameters) {
  828. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  829. }
  830. const parameters = Object.create(null);
  831. if (typeof file === "string") {
  832. this.setTitleUsingUrl(file, file);
  833. parameters.url = file;
  834. } else if (file && "byteLength" in file) {
  835. parameters.data = file;
  836. } else if (file.url && file.originalUrl) {
  837. this.setTitleUsingUrl(file.originalUrl, file.url);
  838. parameters.url = file.url;
  839. }
  840. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  841. for (const key in apiParameters) {
  842. let value = apiParameters[key];
  843. if (key === "docBaseUrl" && !value) {}
  844. parameters[key] = value;
  845. }
  846. if (args) {
  847. for (const key in args) {
  848. parameters[key] = args[key];
  849. }
  850. }
  851. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  852. this.pdfLoadingTask = loadingTask;
  853. loadingTask.onPassword = (updateCallback, reason) => {
  854. this.pdfLinkService.externalLinkEnabled = false;
  855. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  856. this.passwordPrompt.open();
  857. };
  858. loadingTask.onProgress = ({
  859. loaded,
  860. total
  861. }) => {
  862. this.progress(loaded / total);
  863. };
  864. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  865. return loadingTask.promise.then(pdfDocument => {
  866. this.load(pdfDocument);
  867. }, reason => {
  868. if (loadingTask !== this.pdfLoadingTask) {
  869. return undefined;
  870. }
  871. let key = "loading_error";
  872. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  873. key = "invalid_file_error";
  874. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  875. key = "missing_file_error";
  876. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  877. key = "unexpected_response_error";
  878. }
  879. return this.l10n.get(key).then(msg => {
  880. this._documentError(msg, {
  881. message: reason?.message
  882. });
  883. throw reason;
  884. });
  885. });
  886. },
  887. _ensureDownloadComplete() {
  888. if (this.pdfDocument && this.downloadComplete) {
  889. return;
  890. }
  891. throw new Error("PDF document not downloaded.");
  892. },
  893. async download({
  894. sourceEventType = "download"
  895. } = {}) {
  896. const url = this._downloadUrl,
  897. filename = this._docFilename;
  898. try {
  899. this._ensureDownloadComplete();
  900. const data = await this.pdfDocument.getData();
  901. const blob = new Blob([data], {
  902. type: "application/pdf"
  903. });
  904. await this.downloadManager.download(blob, url, filename, sourceEventType);
  905. } catch (reason) {
  906. await this.downloadManager.downloadUrl(url, filename);
  907. }
  908. },
  909. async save({
  910. sourceEventType = "download"
  911. } = {}) {
  912. if (this._saveInProgress) {
  913. return;
  914. }
  915. this._saveInProgress = true;
  916. await this.pdfScriptingManager.dispatchWillSave();
  917. const url = this._downloadUrl,
  918. filename = this._docFilename;
  919. try {
  920. this._ensureDownloadComplete();
  921. const data = await this.pdfDocument.saveDocument();
  922. const blob = new Blob([data], {
  923. type: "application/pdf"
  924. });
  925. await this.downloadManager.download(blob, url, filename, sourceEventType);
  926. } catch (reason) {
  927. console.error(`Error when saving the document: ${reason.message}`);
  928. await this.download({
  929. sourceEventType
  930. });
  931. } finally {
  932. await this.pdfScriptingManager.dispatchDidSave();
  933. this._saveInProgress = false;
  934. }
  935. },
  936. downloadOrSave(options) {
  937. if (this.pdfDocument?.annotationStorage.size > 0) {
  938. this.save(options);
  939. } else {
  940. this.download(options);
  941. }
  942. },
  943. fallback(featureId) {
  944. this.externalServices.reportTelemetry({
  945. type: "unsupportedFeature",
  946. featureId
  947. });
  948. if (this._fellback) {
  949. return;
  950. }
  951. this._fellback = true;
  952. this.externalServices.fallback({
  953. featureId,
  954. url: this.baseUrl
  955. }).then(download => {
  956. if (!download) {
  957. return;
  958. }
  959. this.download({
  960. sourceEventType: "download"
  961. });
  962. });
  963. },
  964. _documentError(message, moreInfo = null) {
  965. this._unblockDocumentLoadEvent();
  966. this._otherError(message, moreInfo);
  967. this.eventBus.dispatch("documenterror", {
  968. source: this,
  969. message,
  970. reason: moreInfo?.message ?? null
  971. });
  972. },
  973. _otherError(message, moreInfo = null) {
  974. const moreInfoText = [this.l10n.get("error_version_info", {
  975. version: _pdfjsLib.version || "?",
  976. build: _pdfjsLib.build || "?"
  977. })];
  978. if (moreInfo) {
  979. moreInfoText.push(this.l10n.get("error_message", {
  980. message: moreInfo.message
  981. }));
  982. if (moreInfo.stack) {
  983. moreInfoText.push(this.l10n.get("error_stack", {
  984. stack: moreInfo.stack
  985. }));
  986. } else {
  987. if (moreInfo.filename) {
  988. moreInfoText.push(this.l10n.get("error_file", {
  989. file: moreInfo.filename
  990. }));
  991. }
  992. if (moreInfo.lineNumber) {
  993. moreInfoText.push(this.l10n.get("error_line", {
  994. line: moreInfo.lineNumber
  995. }));
  996. }
  997. }
  998. }
  999. const errorWrapperConfig = this.appConfig.errorWrapper;
  1000. const errorWrapper = errorWrapperConfig.container;
  1001. errorWrapper.hidden = false;
  1002. const errorMessage = errorWrapperConfig.errorMessage;
  1003. errorMessage.textContent = message;
  1004. const closeButton = errorWrapperConfig.closeButton;
  1005. closeButton.onclick = function () {
  1006. errorWrapper.hidden = true;
  1007. };
  1008. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1009. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1010. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1011. moreInfoButton.onclick = function () {
  1012. errorMoreInfo.hidden = false;
  1013. moreInfoButton.hidden = true;
  1014. lessInfoButton.hidden = false;
  1015. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1016. };
  1017. lessInfoButton.onclick = function () {
  1018. errorMoreInfo.hidden = true;
  1019. moreInfoButton.hidden = false;
  1020. lessInfoButton.hidden = true;
  1021. };
  1022. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1023. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1024. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1025. moreInfoButton.hidden = false;
  1026. lessInfoButton.hidden = true;
  1027. Promise.all(moreInfoText).then(parts => {
  1028. errorMoreInfo.value = parts.join("\n");
  1029. });
  1030. },
  1031. progress(level) {
  1032. if (this.downloadComplete) {
  1033. return;
  1034. }
  1035. const percent = Math.round(level * 100);
  1036. if (percent > this.loadingBar.percent || isNaN(percent)) {
  1037. this.loadingBar.percent = percent;
  1038. const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
  1039. if (disableAutoFetch && percent) {
  1040. if (this.disableAutoFetchLoadingBarTimeout) {
  1041. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1042. this.disableAutoFetchLoadingBarTimeout = null;
  1043. }
  1044. this.loadingBar.show();
  1045. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  1046. this.loadingBar.hide();
  1047. this.disableAutoFetchLoadingBarTimeout = null;
  1048. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1049. }
  1050. }
  1051. },
  1052. load(pdfDocument) {
  1053. this.pdfDocument = pdfDocument;
  1054. pdfDocument.getDownloadInfo().then(({
  1055. length
  1056. }) => {
  1057. this._contentLength = length;
  1058. this.downloadComplete = true;
  1059. this.loadingBar.hide();
  1060. firstPagePromise.then(() => {
  1061. this.eventBus.dispatch("documentloaded", {
  1062. source: this
  1063. });
  1064. });
  1065. });
  1066. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  1067. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1068. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  1069. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1070. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1071. let baseDocumentUrl;
  1072. baseDocumentUrl = null;
  1073. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1074. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1075. const pdfViewer = this.pdfViewer;
  1076. pdfViewer.setDocument(pdfDocument);
  1077. const {
  1078. firstPagePromise,
  1079. onePageRendered,
  1080. pagesPromise
  1081. } = pdfViewer;
  1082. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  1083. pdfThumbnailViewer.setDocument(pdfDocument);
  1084. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  1085. page: null,
  1086. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1087. scrollLeft: "0",
  1088. scrollTop: "0",
  1089. rotation: null,
  1090. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  1091. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1092. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  1093. }).catch(() => {
  1094. return Object.create(null);
  1095. });
  1096. firstPagePromise.then(pdfPage => {
  1097. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  1098. this._initializeAnnotationStorageCallbacks(pdfDocument);
  1099. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  1100. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  1101. this._initializePdfHistory({
  1102. fingerprint: pdfDocument.fingerprints[0],
  1103. viewOnLoad,
  1104. initialDest: openAction?.dest
  1105. });
  1106. const initialBookmark = this.initialBookmark;
  1107. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  1108. let hash = zoom ? `zoom=${zoom}` : null;
  1109. let rotation = null;
  1110. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  1111. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  1112. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  1113. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1114. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  1115. rotation = parseInt(stored.rotation, 10);
  1116. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1117. sidebarView = stored.sidebarView | 0;
  1118. }
  1119. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1120. scrollMode = stored.scrollMode | 0;
  1121. }
  1122. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1123. spreadMode = stored.spreadMode | 0;
  1124. }
  1125. }
  1126. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1127. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  1128. }
  1129. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1130. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  1131. spreadMode = modes.spreadMode;
  1132. }
  1133. this.setInitialView(hash, {
  1134. rotation,
  1135. sidebarView,
  1136. scrollMode,
  1137. spreadMode
  1138. });
  1139. this.eventBus.dispatch("documentinit", {
  1140. source: this
  1141. });
  1142. if (!this.isViewerEmbedded) {
  1143. pdfViewer.focus();
  1144. }
  1145. await Promise.race([pagesPromise, new Promise(resolve => {
  1146. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1147. })]);
  1148. if (!initialBookmark && !hash) {
  1149. return;
  1150. }
  1151. if (pdfViewer.hasEqualPageSizes) {
  1152. return;
  1153. }
  1154. this.initialBookmark = initialBookmark;
  1155. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1156. this.setInitialView(hash);
  1157. }).catch(() => {
  1158. this.setInitialView();
  1159. }).then(function () {
  1160. pdfViewer.update();
  1161. });
  1162. });
  1163. pagesPromise.then(() => {
  1164. this._unblockDocumentLoadEvent();
  1165. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1166. }, reason => {
  1167. this.l10n.get("loading_error").then(msg => {
  1168. this._documentError(msg, {
  1169. message: reason?.message
  1170. });
  1171. });
  1172. });
  1173. onePageRendered.then(data => {
  1174. this.externalServices.reportTelemetry({
  1175. type: "pageInfo",
  1176. timestamp: data.timestamp
  1177. });
  1178. pdfDocument.getOutline().then(outline => {
  1179. if (pdfDocument !== this.pdfDocument) {
  1180. return;
  1181. }
  1182. this.pdfOutlineViewer.render({
  1183. outline,
  1184. pdfDocument
  1185. });
  1186. });
  1187. pdfDocument.getAttachments().then(attachments => {
  1188. if (pdfDocument !== this.pdfDocument) {
  1189. return;
  1190. }
  1191. this.pdfAttachmentViewer.render({
  1192. attachments
  1193. });
  1194. });
  1195. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1196. if (pdfDocument !== this.pdfDocument) {
  1197. return;
  1198. }
  1199. this.pdfLayerViewer.render({
  1200. optionalContentConfig,
  1201. pdfDocument
  1202. });
  1203. });
  1204. if ("requestIdleCallback" in window) {
  1205. const callback = window.requestIdleCallback(() => {
  1206. this._collectTelemetry(pdfDocument);
  1207. this._idleCallbacks.delete(callback);
  1208. }, {
  1209. timeout: 1000
  1210. });
  1211. this._idleCallbacks.add(callback);
  1212. }
  1213. });
  1214. this._initializePageLabels(pdfDocument);
  1215. this._initializeMetadata(pdfDocument);
  1216. },
  1217. async _scriptingDocProperties(pdfDocument) {
  1218. if (!this.documentInfo) {
  1219. await new Promise(resolve => {
  1220. this.eventBus._on("metadataloaded", resolve, {
  1221. once: true
  1222. });
  1223. });
  1224. if (pdfDocument !== this.pdfDocument) {
  1225. return null;
  1226. }
  1227. }
  1228. if (!this._contentLength) {
  1229. await new Promise(resolve => {
  1230. this.eventBus._on("documentloaded", resolve, {
  1231. once: true
  1232. });
  1233. });
  1234. if (pdfDocument !== this.pdfDocument) {
  1235. return null;
  1236. }
  1237. }
  1238. return { ...this.documentInfo,
  1239. baseURL: this.baseUrl,
  1240. filesize: this._contentLength,
  1241. filename: this._docFilename,
  1242. metadata: this.metadata?.getRaw(),
  1243. authors: this.metadata?.get("dc:creator"),
  1244. numPages: this.pagesCount,
  1245. URL: this.url
  1246. };
  1247. },
  1248. async _collectTelemetry(pdfDocument) {
  1249. const markInfo = await this.pdfDocument.getMarkInfo();
  1250. if (pdfDocument !== this.pdfDocument) {
  1251. return;
  1252. }
  1253. const tagged = markInfo?.Marked || false;
  1254. this.externalServices.reportTelemetry({
  1255. type: "tagged",
  1256. tagged
  1257. });
  1258. },
  1259. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1260. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  1261. if (pdfDocument !== this.pdfDocument) {
  1262. return;
  1263. }
  1264. let triggerAutoPrint = false;
  1265. if (openAction?.action === "Print") {
  1266. triggerAutoPrint = true;
  1267. }
  1268. if (javaScript) {
  1269. javaScript.some(js => {
  1270. if (!js) {
  1271. return false;
  1272. }
  1273. console.warn("Warning: JavaScript support is not enabled");
  1274. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1275. return true;
  1276. });
  1277. if (!triggerAutoPrint) {
  1278. for (const js of javaScript) {
  1279. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1280. triggerAutoPrint = true;
  1281. break;
  1282. }
  1283. }
  1284. }
  1285. }
  1286. if (triggerAutoPrint) {
  1287. this.triggerPrinting();
  1288. }
  1289. },
  1290. async _initializeMetadata(pdfDocument) {
  1291. const {
  1292. info,
  1293. metadata,
  1294. contentDispositionFilename,
  1295. contentLength
  1296. } = await pdfDocument.getMetadata();
  1297. if (pdfDocument !== this.pdfDocument) {
  1298. return;
  1299. }
  1300. this.documentInfo = info;
  1301. this.metadata = metadata;
  1302. this._contentDispositionFilename ??= contentDispositionFilename;
  1303. this._contentLength ??= contentLength;
  1304. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"})`);
  1305. let pdfTitle = info?.Title;
  1306. const metadataTitle = metadata?.get("dc:title");
  1307. if (metadataTitle) {
  1308. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1309. pdfTitle = metadataTitle;
  1310. }
  1311. }
  1312. if (pdfTitle) {
  1313. this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  1314. } else if (contentDispositionFilename) {
  1315. this.setTitle(contentDispositionFilename);
  1316. }
  1317. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1318. if (pdfDocument.loadingParams.enableXfa) {
  1319. console.warn("Warning: XFA Foreground documents are not supported");
  1320. } else {
  1321. console.warn("Warning: XFA support is not enabled");
  1322. }
  1323. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1324. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  1325. console.warn("Warning: Interactive form support is not enabled");
  1326. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1327. }
  1328. if (info.IsSignaturesPresent) {
  1329. console.warn("Warning: Digital signatures validation is not supported");
  1330. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  1331. }
  1332. let versionId = "other";
  1333. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  1334. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  1335. }
  1336. let generatorId = "other";
  1337. if (info.Producer) {
  1338. const producer = info.Producer.toLowerCase();
  1339. KNOWN_GENERATORS.some(function (generator) {
  1340. if (!producer.includes(generator)) {
  1341. return false;
  1342. }
  1343. generatorId = generator.replace(/[ .-]/g, "_");
  1344. return true;
  1345. });
  1346. }
  1347. let formType = null;
  1348. if (info.IsXFAPresent) {
  1349. formType = "xfa";
  1350. } else if (info.IsAcroFormPresent) {
  1351. formType = "acroform";
  1352. }
  1353. this.externalServices.reportTelemetry({
  1354. type: "documentInfo",
  1355. version: versionId,
  1356. generator: generatorId,
  1357. formType
  1358. });
  1359. this.eventBus.dispatch("metadataloaded", {
  1360. source: this
  1361. });
  1362. },
  1363. async _initializePageLabels(pdfDocument) {
  1364. const labels = await pdfDocument.getPageLabels();
  1365. if (pdfDocument !== this.pdfDocument) {
  1366. return;
  1367. }
  1368. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1369. return;
  1370. }
  1371. const numLabels = labels.length;
  1372. let standardLabels = 0,
  1373. emptyLabels = 0;
  1374. for (let i = 0; i < numLabels; i++) {
  1375. const label = labels[i];
  1376. if (label === (i + 1).toString()) {
  1377. standardLabels++;
  1378. } else if (label === "") {
  1379. emptyLabels++;
  1380. } else {
  1381. break;
  1382. }
  1383. }
  1384. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  1385. return;
  1386. }
  1387. const {
  1388. pdfViewer,
  1389. pdfThumbnailViewer,
  1390. toolbar
  1391. } = this;
  1392. pdfViewer.setPageLabels(labels);
  1393. pdfThumbnailViewer.setPageLabels(labels);
  1394. toolbar.setPagesCount(numLabels, true);
  1395. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1396. },
  1397. _initializePdfHistory({
  1398. fingerprint,
  1399. viewOnLoad,
  1400. initialDest = null
  1401. }) {
  1402. if (!this.pdfHistory) {
  1403. return;
  1404. }
  1405. this.pdfHistory.initialize({
  1406. fingerprint,
  1407. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1408. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1409. });
  1410. if (this.pdfHistory.initialBookmark) {
  1411. this.initialBookmark = this.pdfHistory.initialBookmark;
  1412. this.initialRotation = this.pdfHistory.initialRotation;
  1413. }
  1414. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1415. this.initialBookmark = JSON.stringify(initialDest);
  1416. this.pdfHistory.push({
  1417. explicitDest: initialDest,
  1418. pageNumber: null
  1419. });
  1420. }
  1421. },
  1422. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1423. if (pdfDocument !== this.pdfDocument) {
  1424. return;
  1425. }
  1426. const {
  1427. annotationStorage
  1428. } = pdfDocument;
  1429. annotationStorage.onSetModified = () => {
  1430. window.addEventListener("beforeunload", beforeUnload);
  1431. this._annotationStorageModified = true;
  1432. };
  1433. annotationStorage.onResetModified = () => {
  1434. window.removeEventListener("beforeunload", beforeUnload);
  1435. delete this._annotationStorageModified;
  1436. };
  1437. },
  1438. setInitialView(storedHash, {
  1439. rotation,
  1440. sidebarView,
  1441. scrollMode,
  1442. spreadMode
  1443. } = {}) {
  1444. const setRotation = angle => {
  1445. if ((0, _ui_utils.isValidRotation)(angle)) {
  1446. this.pdfViewer.pagesRotation = angle;
  1447. }
  1448. };
  1449. const setViewerModes = (scroll, spread) => {
  1450. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1451. this.pdfViewer.scrollMode = scroll;
  1452. }
  1453. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1454. this.pdfViewer.spreadMode = spread;
  1455. }
  1456. };
  1457. this.isInitialViewSet = true;
  1458. this.pdfSidebar.setInitialView(sidebarView);
  1459. setViewerModes(scrollMode, spreadMode);
  1460. if (this.initialBookmark) {
  1461. setRotation(this.initialRotation);
  1462. delete this.initialRotation;
  1463. this.pdfLinkService.setHash(this.initialBookmark);
  1464. this.initialBookmark = null;
  1465. } else if (storedHash) {
  1466. setRotation(rotation);
  1467. this.pdfLinkService.setHash(storedHash);
  1468. }
  1469. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1470. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1471. if (!this.pdfViewer.currentScaleValue) {
  1472. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1473. }
  1474. },
  1475. _cleanup() {
  1476. if (!this.pdfDocument) {
  1477. return;
  1478. }
  1479. this.pdfViewer.cleanup();
  1480. this.pdfThumbnailViewer.cleanup();
  1481. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  1482. },
  1483. forceRendering() {
  1484. this.pdfRenderingQueue.printing = !!this.printService;
  1485. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1486. this.pdfRenderingQueue.renderHighestPriority();
  1487. },
  1488. beforePrint() {
  1489. this.pdfScriptingManager.dispatchWillPrint();
  1490. if (this.printService) {
  1491. return;
  1492. }
  1493. if (!this.supportsPrinting) {
  1494. this.l10n.get("printing_not_supported").then(msg => {
  1495. this._otherError(msg);
  1496. });
  1497. return;
  1498. }
  1499. if (!this.pdfViewer.pageViewsReady) {
  1500. this.l10n.get("printing_not_ready").then(msg => {
  1501. window.alert(msg);
  1502. });
  1503. return;
  1504. }
  1505. const pagesOverview = this.pdfViewer.getPagesOverview();
  1506. const printContainer = this.appConfig.printContainer;
  1507. const printResolution = _app_options.AppOptions.get("printResolution");
  1508. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1509. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
  1510. this.printService = printService;
  1511. this.forceRendering();
  1512. printService.layout();
  1513. this.externalServices.reportTelemetry({
  1514. type: "print"
  1515. });
  1516. },
  1517. afterPrint() {
  1518. this.pdfScriptingManager.dispatchDidPrint();
  1519. if (this.printService) {
  1520. this.printService.destroy();
  1521. this.printService = null;
  1522. this.pdfDocument?.annotationStorage.resetModified();
  1523. }
  1524. this.forceRendering();
  1525. },
  1526. rotatePages(delta) {
  1527. this.pdfViewer.pagesRotation += delta;
  1528. },
  1529. requestPresentationMode() {
  1530. this.pdfPresentationMode?.request();
  1531. },
  1532. triggerPrinting() {
  1533. if (!this.supportsPrinting) {
  1534. return;
  1535. }
  1536. window.print();
  1537. },
  1538. bindEvents() {
  1539. const {
  1540. eventBus,
  1541. _boundEvents
  1542. } = this;
  1543. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1544. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1545. eventBus._on("resize", webViewerResize);
  1546. eventBus._on("hashchange", webViewerHashchange);
  1547. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1548. eventBus._on("afterprint", _boundEvents.afterPrint);
  1549. eventBus._on("pagerendered", webViewerPageRendered);
  1550. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1551. eventBus._on("pagechanging", webViewerPageChanging);
  1552. eventBus._on("scalechanging", webViewerScaleChanging);
  1553. eventBus._on("rotationchanging", webViewerRotationChanging);
  1554. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1555. eventBus._on("pagemode", webViewerPageMode);
  1556. eventBus._on("namedaction", webViewerNamedAction);
  1557. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1558. eventBus._on("presentationmode", webViewerPresentationMode);
  1559. eventBus._on("print", webViewerPrint);
  1560. eventBus._on("download", webViewerDownload);
  1561. eventBus._on("save", webViewerSave);
  1562. eventBus._on("firstpage", webViewerFirstPage);
  1563. eventBus._on("lastpage", webViewerLastPage);
  1564. eventBus._on("nextpage", webViewerNextPage);
  1565. eventBus._on("previouspage", webViewerPreviousPage);
  1566. eventBus._on("zoomin", webViewerZoomIn);
  1567. eventBus._on("zoomout", webViewerZoomOut);
  1568. eventBus._on("zoomreset", webViewerZoomReset);
  1569. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1570. eventBus._on("scalechanged", webViewerScaleChanged);
  1571. eventBus._on("rotatecw", webViewerRotateCw);
  1572. eventBus._on("rotateccw", webViewerRotateCcw);
  1573. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1574. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1575. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1576. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1577. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1578. eventBus._on("documentproperties", webViewerDocumentProperties);
  1579. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1580. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1581. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1582. if (_app_options.AppOptions.get("pdfBug")) {
  1583. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1584. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1585. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1586. }
  1587. eventBus._on("fileinputchange", webViewerFileInputChange);
  1588. eventBus._on("openfile", webViewerOpenFile);
  1589. },
  1590. bindWindowEvents() {
  1591. const {
  1592. eventBus,
  1593. _boundEvents
  1594. } = this;
  1595. _boundEvents.windowResize = () => {
  1596. eventBus.dispatch("resize", {
  1597. source: window
  1598. });
  1599. };
  1600. _boundEvents.windowHashChange = () => {
  1601. eventBus.dispatch("hashchange", {
  1602. source: window,
  1603. hash: document.location.hash.substring(1)
  1604. });
  1605. };
  1606. _boundEvents.windowBeforePrint = () => {
  1607. eventBus.dispatch("beforeprint", {
  1608. source: window
  1609. });
  1610. };
  1611. _boundEvents.windowAfterPrint = () => {
  1612. eventBus.dispatch("afterprint", {
  1613. source: window
  1614. });
  1615. };
  1616. _boundEvents.windowUpdateFromSandbox = event => {
  1617. eventBus.dispatch("updatefromsandbox", {
  1618. source: window,
  1619. detail: event.detail
  1620. });
  1621. };
  1622. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1623. window.addEventListener("wheel", webViewerWheel, {
  1624. passive: false
  1625. });
  1626. window.addEventListener("touchstart", webViewerTouchStart, {
  1627. passive: false
  1628. });
  1629. window.addEventListener("click", webViewerClick);
  1630. window.addEventListener("keydown", webViewerKeyDown);
  1631. window.addEventListener("resize", _boundEvents.windowResize);
  1632. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1633. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1634. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1635. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1636. },
  1637. unbindEvents() {
  1638. const {
  1639. eventBus,
  1640. _boundEvents
  1641. } = this;
  1642. eventBus._off("resize", webViewerResize);
  1643. eventBus._off("hashchange", webViewerHashchange);
  1644. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1645. eventBus._off("afterprint", _boundEvents.afterPrint);
  1646. eventBus._off("pagerendered", webViewerPageRendered);
  1647. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1648. eventBus._off("pagechanging", webViewerPageChanging);
  1649. eventBus._off("scalechanging", webViewerScaleChanging);
  1650. eventBus._off("rotationchanging", webViewerRotationChanging);
  1651. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1652. eventBus._off("pagemode", webViewerPageMode);
  1653. eventBus._off("namedaction", webViewerNamedAction);
  1654. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1655. eventBus._off("presentationmode", webViewerPresentationMode);
  1656. eventBus._off("print", webViewerPrint);
  1657. eventBus._off("download", webViewerDownload);
  1658. eventBus._off("save", webViewerSave);
  1659. eventBus._off("firstpage", webViewerFirstPage);
  1660. eventBus._off("lastpage", webViewerLastPage);
  1661. eventBus._off("nextpage", webViewerNextPage);
  1662. eventBus._off("previouspage", webViewerPreviousPage);
  1663. eventBus._off("zoomin", webViewerZoomIn);
  1664. eventBus._off("zoomout", webViewerZoomOut);
  1665. eventBus._off("zoomreset", webViewerZoomReset);
  1666. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1667. eventBus._off("scalechanged", webViewerScaleChanged);
  1668. eventBus._off("rotatecw", webViewerRotateCw);
  1669. eventBus._off("rotateccw", webViewerRotateCcw);
  1670. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1671. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1672. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1673. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1674. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1675. eventBus._off("documentproperties", webViewerDocumentProperties);
  1676. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1677. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1678. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1679. if (_boundEvents.reportPageStatsPDFBug) {
  1680. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1681. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1682. _boundEvents.reportPageStatsPDFBug = null;
  1683. }
  1684. eventBus._off("fileinputchange", webViewerFileInputChange);
  1685. eventBus._off("openfile", webViewerOpenFile);
  1686. _boundEvents.beforePrint = null;
  1687. _boundEvents.afterPrint = null;
  1688. },
  1689. unbindWindowEvents() {
  1690. const {
  1691. _boundEvents
  1692. } = this;
  1693. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1694. window.removeEventListener("wheel", webViewerWheel, {
  1695. passive: false
  1696. });
  1697. window.removeEventListener("touchstart", webViewerTouchStart, {
  1698. passive: false
  1699. });
  1700. window.removeEventListener("click", webViewerClick);
  1701. window.removeEventListener("keydown", webViewerKeyDown);
  1702. window.removeEventListener("resize", _boundEvents.windowResize);
  1703. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1704. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1705. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1706. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1707. _boundEvents.windowResize = null;
  1708. _boundEvents.windowHashChange = null;
  1709. _boundEvents.windowBeforePrint = null;
  1710. _boundEvents.windowAfterPrint = null;
  1711. _boundEvents.windowUpdateFromSandbox = null;
  1712. },
  1713. accumulateWheelTicks(ticks) {
  1714. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  1715. this._wheelUnusedTicks = 0;
  1716. }
  1717. this._wheelUnusedTicks += ticks;
  1718. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  1719. this._wheelUnusedTicks -= wholeTicks;
  1720. return wholeTicks;
  1721. },
  1722. _unblockDocumentLoadEvent() {
  1723. if (document.blockUnblockOnload) {
  1724. document.blockUnblockOnload(false);
  1725. }
  1726. this._unblockDocumentLoadEvent = () => {};
  1727. },
  1728. _reportDocumentStatsTelemetry() {
  1729. const {
  1730. stats
  1731. } = this.pdfDocument;
  1732. if (stats !== this._docStats) {
  1733. this._docStats = stats;
  1734. this.externalServices.reportTelemetry({
  1735. type: "documentStats",
  1736. stats
  1737. });
  1738. }
  1739. },
  1740. get scriptingReady() {
  1741. return this.pdfScriptingManager.ready;
  1742. }
  1743. };
  1744. exports.PDFViewerApplication = PDFViewerApplication;
  1745. let validateFileURL;
  1746. {
  1747. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1748. validateFileURL = function (file) {
  1749. if (file === undefined) {
  1750. return;
  1751. }
  1752. try {
  1753. const viewerOrigin = new URL(window.location.href).origin || "null";
  1754. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1755. return;
  1756. }
  1757. /*const fileOrigin = new URL(file, window.location.href).origin;
  1758. if (fileOrigin !== viewerOrigin) {
  1759. throw new Error("file origin does not match viewer's");
  1760. }*/
  1761. } catch (ex) {
  1762. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1763. PDFViewerApplication._documentError(msg, {
  1764. message: ex?.message
  1765. });
  1766. });
  1767. throw ex;
  1768. }
  1769. };
  1770. }
  1771. async function loadFakeWorker() {
  1772. if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
  1773. _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
  1774. }
  1775. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  1776. }
  1777. async function initPDFBug(enabledTabs) {
  1778. const {
  1779. debuggerScriptPath,
  1780. mainContainer
  1781. } = PDFViewerApplication.appConfig;
  1782. await (0, _pdfjsLib.loadScript)(debuggerScriptPath);
  1783. PDFBug.init({
  1784. OPS: _pdfjsLib.OPS
  1785. }, mainContainer, enabledTabs);
  1786. }
  1787. function reportPageStatsPDFBug({
  1788. pageNumber
  1789. }) {
  1790. if (typeof Stats === "undefined" || !Stats.enabled) {
  1791. return;
  1792. }
  1793. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1794. const pageStats = pageView?.pdfPage?.stats;
  1795. if (!pageStats) {
  1796. return;
  1797. }
  1798. Stats.add(pageNumber, pageStats);
  1799. }
  1800. function webViewerInitialized() {
  1801. const appConfig = PDFViewerApplication.appConfig;
  1802. let file;
  1803. const queryString = document.location.search.substring(1);
  1804. const params = (0, _ui_utils.parseQueryString)(queryString);
  1805. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  1806. validateFileURL(file);
  1807. const fileInput = document.createElement("input");
  1808. fileInput.id = appConfig.openFileInputName;
  1809. fileInput.className = "fileInput";
  1810. fileInput.setAttribute("type", "file");
  1811. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1812. document.body.appendChild(fileInput);
  1813. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1814. appConfig.toolbar.openFile.hidden = true;
  1815. appConfig.secondaryToolbar.openFileButton.hidden = true;
  1816. } else {
  1817. fileInput.value = null;
  1818. }
  1819. fileInput.addEventListener("change", function (evt) {
  1820. const files = evt.target.files;
  1821. if (!files || files.length === 0) {
  1822. return;
  1823. }
  1824. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1825. source: this,
  1826. fileInput: evt.target
  1827. });
  1828. });
  1829. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1830. evt.preventDefault();
  1831. evt.dataTransfer.dropEffect = "move";
  1832. });
  1833. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1834. evt.preventDefault();
  1835. const files = evt.dataTransfer.files;
  1836. if (!files || files.length === 0) {
  1837. return;
  1838. }
  1839. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1840. source: this,
  1841. fileInput: evt.dataTransfer
  1842. });
  1843. });
  1844. if (!PDFViewerApplication.supportsDocumentFonts) {
  1845. _app_options.AppOptions.set("disableFontFace", true);
  1846. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  1847. console.warn(msg);
  1848. });
  1849. }
  1850. if (!PDFViewerApplication.supportsPrinting) {
  1851. appConfig.toolbar.print.classList.add("hidden");
  1852. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  1853. }
  1854. if (!PDFViewerApplication.supportsFullscreen) {
  1855. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  1856. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  1857. }
  1858. if (PDFViewerApplication.supportsIntegratedFind) {
  1859. appConfig.toolbar.viewFind.classList.add("hidden");
  1860. }
  1861. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1862. if (evt.target === this) {
  1863. PDFViewerApplication.eventBus.dispatch("resize", {
  1864. source: this
  1865. });
  1866. }
  1867. }, true);
  1868. try {
  1869. webViewerOpenFileViaURL(file);
  1870. } catch (reason) {
  1871. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1872. PDFViewerApplication._documentError(msg, reason);
  1873. });
  1874. }
  1875. }
  1876. function webViewerOpenFileViaURL(file) {
  1877. if (file) {
  1878. PDFViewerApplication.open(file);
  1879. } else {
  1880. PDFViewerApplication._hideViewBookmark();
  1881. }
  1882. }
  1883. function webViewerPageRendered({
  1884. pageNumber,
  1885. error
  1886. }) {
  1887. if (pageNumber === PDFViewerApplication.page) {
  1888. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1889. }
  1890. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1891. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1892. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  1893. if (pageView && thumbnailView) {
  1894. thumbnailView.setImage(pageView);
  1895. }
  1896. }
  1897. if (error) {
  1898. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1899. PDFViewerApplication._otherError(msg, error);
  1900. });
  1901. }
  1902. PDFViewerApplication._reportDocumentStatsTelemetry();
  1903. }
  1904. function webViewerPageMode({
  1905. mode
  1906. }) {
  1907. let view;
  1908. switch (mode) {
  1909. case "thumbs":
  1910. view = _ui_utils.SidebarView.THUMBS;
  1911. break;
  1912. case "bookmarks":
  1913. case "outline":
  1914. view = _ui_utils.SidebarView.OUTLINE;
  1915. break;
  1916. case "attachments":
  1917. view = _ui_utils.SidebarView.ATTACHMENTS;
  1918. break;
  1919. case "layers":
  1920. view = _ui_utils.SidebarView.LAYERS;
  1921. break;
  1922. case "none":
  1923. view = _ui_utils.SidebarView.NONE;
  1924. break;
  1925. default:
  1926. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1927. return;
  1928. }
  1929. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1930. }
  1931. function webViewerNamedAction(evt) {
  1932. switch (evt.action) {
  1933. case "GoToPage":
  1934. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1935. break;
  1936. case "Find":
  1937. if (!PDFViewerApplication.supportsIntegratedFind) {
  1938. PDFViewerApplication.findBar.toggle();
  1939. }
  1940. break;
  1941. case "Print":
  1942. PDFViewerApplication.triggerPrinting();
  1943. break;
  1944. case "SaveAs":
  1945. webViewerSave();
  1946. break;
  1947. }
  1948. }
  1949. function webViewerPresentationModeChanged(evt) {
  1950. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1951. }
  1952. function webViewerSidebarViewChanged(evt) {
  1953. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1954. if (PDFViewerApplication.isInitialViewSet) {
  1955. PDFViewerApplication.store?.set("sidebarView", evt.view).catch(() => {});
  1956. }
  1957. }
  1958. function webViewerUpdateViewarea(evt) {
  1959. const location = evt.location;
  1960. if (PDFViewerApplication.isInitialViewSet) {
  1961. PDFViewerApplication.store?.setMultiple({
  1962. page: location.pageNumber,
  1963. zoom: location.scale,
  1964. scrollLeft: location.left,
  1965. scrollTop: location.top,
  1966. rotation: location.rotation
  1967. }).catch(() => {});
  1968. }
  1969. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1970. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1971. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1972. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1973. const loading = currentPage?.renderingState !== _ui_utils.RenderingStates.FINISHED;
  1974. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1975. }
  1976. function webViewerScrollModeChanged(evt) {
  1977. if (PDFViewerApplication.isInitialViewSet) {
  1978. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  1979. }
  1980. }
  1981. function webViewerSpreadModeChanged(evt) {
  1982. if (PDFViewerApplication.isInitialViewSet) {
  1983. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  1984. }
  1985. }
  1986. function webViewerResize() {
  1987. const {
  1988. pdfDocument,
  1989. pdfViewer
  1990. } = PDFViewerApplication;
  1991. if (!pdfDocument) {
  1992. return;
  1993. }
  1994. const currentScaleValue = pdfViewer.currentScaleValue;
  1995. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  1996. pdfViewer.currentScaleValue = currentScaleValue;
  1997. }
  1998. pdfViewer.update();
  1999. }
  2000. function webViewerHashchange(evt) {
  2001. const hash = evt.hash;
  2002. if (!hash) {
  2003. return;
  2004. }
  2005. if (!PDFViewerApplication.isInitialViewSet) {
  2006. PDFViewerApplication.initialBookmark = hash;
  2007. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  2008. PDFViewerApplication.pdfLinkService.setHash(hash);
  2009. }
  2010. }
  2011. let webViewerFileInputChange, webViewerOpenFile;
  2012. {
  2013. webViewerFileInputChange = function (evt) {
  2014. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2015. return;
  2016. }
  2017. const file = evt.fileInput.files[0];
  2018. let url = URL.createObjectURL(file);
  2019. if (file.name) {
  2020. url = {
  2021. url,
  2022. originalUrl: file.name
  2023. };
  2024. }
  2025. PDFViewerApplication.open(url);
  2026. };
  2027. webViewerOpenFile = function (evt) {
  2028. const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  2029. document.getElementById(openFileInputName).click();
  2030. };
  2031. }
  2032. function webViewerPresentationMode() {
  2033. PDFViewerApplication.requestPresentationMode();
  2034. }
  2035. function webViewerPrint() {
  2036. PDFViewerApplication.triggerPrinting();
  2037. }
  2038. function webViewerDownload() {
  2039. PDFViewerApplication.downloadOrSave({
  2040. sourceEventType: "download"
  2041. });
  2042. }
  2043. function webViewerSave() {
  2044. PDFViewerApplication.downloadOrSave({
  2045. sourceEventType: "save"
  2046. });
  2047. }
  2048. function webViewerFirstPage() {
  2049. if (PDFViewerApplication.pdfDocument) {
  2050. PDFViewerApplication.page = 1;
  2051. }
  2052. }
  2053. function webViewerLastPage() {
  2054. if (PDFViewerApplication.pdfDocument) {
  2055. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2056. }
  2057. }
  2058. function webViewerNextPage() {
  2059. PDFViewerApplication.pdfViewer.nextPage();
  2060. }
  2061. function webViewerPreviousPage() {
  2062. PDFViewerApplication.pdfViewer.previousPage();
  2063. }
  2064. function webViewerZoomIn() {
  2065. PDFViewerApplication.zoomIn();
  2066. }
  2067. function webViewerZoomOut() {
  2068. PDFViewerApplication.zoomOut();
  2069. }
  2070. function webViewerZoomReset() {
  2071. PDFViewerApplication.zoomReset();
  2072. }
  2073. function webViewerPageNumberChanged(evt) {
  2074. const pdfViewer = PDFViewerApplication.pdfViewer;
  2075. if (evt.value !== "") {
  2076. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  2077. }
  2078. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  2079. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2080. }
  2081. }
  2082. function webViewerScaleChanged(evt) {
  2083. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2084. }
  2085. function webViewerRotateCw() {
  2086. PDFViewerApplication.rotatePages(90);
  2087. }
  2088. function webViewerRotateCcw() {
  2089. PDFViewerApplication.rotatePages(-90);
  2090. }
  2091. function webViewerOptionalContentConfig(evt) {
  2092. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  2093. }
  2094. function webViewerSwitchScrollMode(evt) {
  2095. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  2096. }
  2097. function webViewerSwitchSpreadMode(evt) {
  2098. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  2099. }
  2100. function webViewerDocumentProperties() {
  2101. PDFViewerApplication.pdfDocumentProperties.open();
  2102. }
  2103. function webViewerFindFromUrlHash(evt) {
  2104. PDFViewerApplication.eventBus.dispatch("find", {
  2105. source: evt.source,
  2106. type: "",
  2107. query: evt.query,
  2108. phraseSearch: evt.phraseSearch,
  2109. caseSensitive: false,
  2110. entireWord: false,
  2111. highlightAll: true,
  2112. findPrevious: false,
  2113. matchDiacritics: true
  2114. });
  2115. }
  2116. function webViewerUpdateFindMatchesCount({
  2117. matchesCount
  2118. }) {
  2119. if (PDFViewerApplication.supportsIntegratedFind) {
  2120. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  2121. } else {
  2122. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  2123. }
  2124. }
  2125. function webViewerUpdateFindControlState({
  2126. state,
  2127. previous,
  2128. matchesCount,
  2129. rawQuery
  2130. }) {
  2131. if (PDFViewerApplication.supportsIntegratedFind) {
  2132. PDFViewerApplication.externalServices.updateFindControlState({
  2133. result: state,
  2134. findPrevious: previous,
  2135. matchesCount,
  2136. rawQuery
  2137. });
  2138. } else {
  2139. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  2140. }
  2141. }
  2142. function webViewerScaleChanging(evt) {
  2143. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  2144. PDFViewerApplication.pdfViewer.update();
  2145. }
  2146. function webViewerRotationChanging(evt) {
  2147. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  2148. PDFViewerApplication.forceRendering();
  2149. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2150. }
  2151. function webViewerPageChanging({
  2152. pageNumber,
  2153. pageLabel
  2154. }) {
  2155. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  2156. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  2157. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2158. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  2159. }
  2160. }
  2161. function webViewerVisibilityChange(evt) {
  2162. if (document.visibilityState === "visible") {
  2163. setZoomDisabledTimeout();
  2164. }
  2165. }
  2166. let zoomDisabledTimeout = null;
  2167. function setZoomDisabledTimeout() {
  2168. if (zoomDisabledTimeout) {
  2169. clearTimeout(zoomDisabledTimeout);
  2170. }
  2171. zoomDisabledTimeout = setTimeout(function () {
  2172. zoomDisabledTimeout = null;
  2173. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  2174. }
  2175. function webViewerWheel(evt) {
  2176. const {
  2177. pdfViewer,
  2178. supportedMouseWheelZoomModifierKeys
  2179. } = PDFViewerApplication;
  2180. if (pdfViewer.isInPresentationMode) {
  2181. return;
  2182. }
  2183. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  2184. evt.preventDefault();
  2185. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2186. return;
  2187. }
  2188. const deltaMode = evt.deltaMode;
  2189. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2190. const previousScale = pdfViewer.currentScale;
  2191. let ticks = 0;
  2192. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2193. if (Math.abs(delta) >= 1) {
  2194. ticks = Math.sign(delta);
  2195. } else {
  2196. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  2197. }
  2198. } else {
  2199. const PIXELS_PER_LINE_SCALE = 30;
  2200. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  2201. }
  2202. if (ticks < 0) {
  2203. PDFViewerApplication.zoomOut(-ticks);
  2204. } else if (ticks > 0) {
  2205. PDFViewerApplication.zoomIn(ticks);
  2206. }
  2207. const currentScale = pdfViewer.currentScale;
  2208. if (previousScale !== currentScale) {
  2209. const scaleCorrectionFactor = currentScale / previousScale - 1;
  2210. const rect = pdfViewer.container.getBoundingClientRect();
  2211. const dx = evt.clientX - rect.left;
  2212. const dy = evt.clientY - rect.top;
  2213. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  2214. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  2215. }
  2216. } else {
  2217. setZoomDisabledTimeout();
  2218. }
  2219. }
  2220. function webViewerTouchStart(evt) {
  2221. if (evt.touches.length > 1) {
  2222. evt.preventDefault();
  2223. }
  2224. }
  2225. function webViewerClick(evt) {
  2226. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  2227. return;
  2228. }
  2229. const appConfig = PDFViewerApplication.appConfig;
  2230. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  2231. PDFViewerApplication.secondaryToolbar.close();
  2232. }
  2233. }
  2234. function webViewerKeyDown(evt) {
  2235. if (PDFViewerApplication.overlayManager.active) {
  2236. return;
  2237. }
  2238. const {
  2239. eventBus,
  2240. pdfViewer
  2241. } = PDFViewerApplication;
  2242. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  2243. let handled = false,
  2244. ensureViewerFocused = false;
  2245. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2246. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2247. switch (evt.keyCode) {
  2248. case 70:
  2249. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2250. PDFViewerApplication.findBar.open();
  2251. handled = true;
  2252. }
  2253. break;
  2254. case 71:
  2255. if (!PDFViewerApplication.supportsIntegratedFind) {
  2256. const {
  2257. state
  2258. } = PDFViewerApplication.findController;
  2259. if (state) {
  2260. const eventState = Object.assign(Object.create(null), state, {
  2261. source: window,
  2262. type: "again",
  2263. findPrevious: cmd === 5 || cmd === 12
  2264. });
  2265. eventBus.dispatch("find", eventState);
  2266. }
  2267. handled = true;
  2268. }
  2269. break;
  2270. case 61:
  2271. case 107:
  2272. case 187:
  2273. case 171:
  2274. if (!isViewerInPresentationMode) {
  2275. PDFViewerApplication.zoomIn();
  2276. }
  2277. handled = true;
  2278. break;
  2279. case 173:
  2280. case 109:
  2281. case 189:
  2282. if (!isViewerInPresentationMode) {
  2283. PDFViewerApplication.zoomOut();
  2284. }
  2285. handled = true;
  2286. break;
  2287. case 48:
  2288. case 96:
  2289. if (!isViewerInPresentationMode) {
  2290. setTimeout(function () {
  2291. PDFViewerApplication.zoomReset();
  2292. });
  2293. handled = false;
  2294. }
  2295. break;
  2296. case 38:
  2297. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2298. PDFViewerApplication.page = 1;
  2299. handled = true;
  2300. ensureViewerFocused = true;
  2301. }
  2302. break;
  2303. case 40:
  2304. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2305. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2306. handled = true;
  2307. ensureViewerFocused = true;
  2308. }
  2309. break;
  2310. }
  2311. }
  2312. if (cmd === 1 || cmd === 8) {
  2313. switch (evt.keyCode) {
  2314. case 83:
  2315. eventBus.dispatch("download", {
  2316. source: window
  2317. });
  2318. handled = true;
  2319. break;
  2320. case 79:
  2321. {
  2322. eventBus.dispatch("openfile", {
  2323. source: window
  2324. });
  2325. handled = true;
  2326. }
  2327. break;
  2328. }
  2329. }
  2330. if (cmd === 3 || cmd === 10) {
  2331. switch (evt.keyCode) {
  2332. case 80:
  2333. PDFViewerApplication.requestPresentationMode();
  2334. handled = true;
  2335. break;
  2336. case 71:
  2337. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2338. handled = true;
  2339. break;
  2340. }
  2341. }
  2342. if (handled) {
  2343. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2344. pdfViewer.focus();
  2345. }
  2346. evt.preventDefault();
  2347. return;
  2348. }
  2349. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2350. const curElementTagName = curElement?.tagName.toUpperCase();
  2351. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2352. if (evt.keyCode !== 27) {
  2353. return;
  2354. }
  2355. }
  2356. if (cmd === 0) {
  2357. let turnPage = 0,
  2358. turnOnlyIfPageFit = false;
  2359. switch (evt.keyCode) {
  2360. case 38:
  2361. case 33:
  2362. if (pdfViewer.isVerticalScrollbarEnabled) {
  2363. turnOnlyIfPageFit = true;
  2364. }
  2365. turnPage = -1;
  2366. break;
  2367. case 8:
  2368. if (!isViewerInPresentationMode) {
  2369. turnOnlyIfPageFit = true;
  2370. }
  2371. turnPage = -1;
  2372. break;
  2373. case 37:
  2374. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2375. turnOnlyIfPageFit = true;
  2376. }
  2377. case 75:
  2378. case 80:
  2379. turnPage = -1;
  2380. break;
  2381. case 27:
  2382. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2383. PDFViewerApplication.secondaryToolbar.close();
  2384. handled = true;
  2385. }
  2386. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2387. PDFViewerApplication.findBar.close();
  2388. handled = true;
  2389. }
  2390. break;
  2391. case 40:
  2392. case 34:
  2393. if (pdfViewer.isVerticalScrollbarEnabled) {
  2394. turnOnlyIfPageFit = true;
  2395. }
  2396. turnPage = 1;
  2397. break;
  2398. case 13:
  2399. case 32:
  2400. if (!isViewerInPresentationMode) {
  2401. turnOnlyIfPageFit = true;
  2402. }
  2403. turnPage = 1;
  2404. break;
  2405. case 39:
  2406. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2407. turnOnlyIfPageFit = true;
  2408. }
  2409. case 74:
  2410. case 78:
  2411. turnPage = 1;
  2412. break;
  2413. case 36:
  2414. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2415. PDFViewerApplication.page = 1;
  2416. handled = true;
  2417. ensureViewerFocused = true;
  2418. }
  2419. break;
  2420. case 35:
  2421. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2422. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2423. handled = true;
  2424. ensureViewerFocused = true;
  2425. }
  2426. break;
  2427. case 83:
  2428. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2429. break;
  2430. case 72:
  2431. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2432. break;
  2433. case 82:
  2434. PDFViewerApplication.rotatePages(90);
  2435. break;
  2436. case 115:
  2437. PDFViewerApplication.pdfSidebar.toggle();
  2438. break;
  2439. }
  2440. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2441. if (turnPage > 0) {
  2442. pdfViewer.nextPage();
  2443. } else {
  2444. pdfViewer.previousPage();
  2445. }
  2446. handled = true;
  2447. }
  2448. }
  2449. if (cmd === 4) {
  2450. switch (evt.keyCode) {
  2451. case 13:
  2452. case 32:
  2453. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2454. break;
  2455. }
  2456. pdfViewer.previousPage();
  2457. handled = true;
  2458. break;
  2459. case 82:
  2460. PDFViewerApplication.rotatePages(-90);
  2461. break;
  2462. }
  2463. }
  2464. if (!handled && !isViewerInPresentationMode) {
  2465. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2466. ensureViewerFocused = true;
  2467. }
  2468. }
  2469. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2470. pdfViewer.focus();
  2471. }
  2472. if (handled) {
  2473. evt.preventDefault();
  2474. }
  2475. }
  2476. function beforeUnload(evt) {
  2477. evt.preventDefault();
  2478. evt.returnValue = "";
  2479. return false;
  2480. }
  2481. const PDFPrintServiceFactory = {
  2482. instance: {
  2483. supportsPrinting: false,
  2484. createPrintService() {
  2485. throw new Error("Not implemented: createPrintService");
  2486. }
  2487. }
  2488. };
  2489. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2490. /***/ }),
  2491. /* 3 */
  2492. /***/ ((__unused_webpack_module, exports) => {
  2493. Object.defineProperty(exports, "__esModule", ({
  2494. value: true
  2495. }));
  2496. exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = void 0;
  2497. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  2498. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2499. exports.approximateFraction = approximateFraction;
  2500. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2501. exports.binarySearchFirstItem = binarySearchFirstItem;
  2502. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2503. exports.getPageSizeInches = getPageSizeInches;
  2504. exports.getVisibleElements = getVisibleElements;
  2505. exports.isPortraitOrientation = isPortraitOrientation;
  2506. exports.isValidRotation = isValidRotation;
  2507. exports.isValidScrollMode = isValidScrollMode;
  2508. exports.isValidSpreadMode = isValidSpreadMode;
  2509. exports.noContextMenuHandler = noContextMenuHandler;
  2510. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2511. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2512. exports.parseQueryString = parseQueryString;
  2513. exports.removeNullCharacters = removeNullCharacters;
  2514. exports.roundToDivide = roundToDivide;
  2515. exports.scrollIntoView = scrollIntoView;
  2516. exports.watchScroll = watchScroll;
  2517. const DEFAULT_SCALE_VALUE = "auto";
  2518. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2519. const DEFAULT_SCALE = 1.0;
  2520. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2521. const DEFAULT_SCALE_DELTA = 1.1;
  2522. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  2523. const MIN_SCALE = 0.1;
  2524. exports.MIN_SCALE = MIN_SCALE;
  2525. const MAX_SCALE = 10.0;
  2526. exports.MAX_SCALE = MAX_SCALE;
  2527. const UNKNOWN_SCALE = 0;
  2528. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2529. const MAX_AUTO_SCALE = 1.25;
  2530. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2531. const SCROLLBAR_PADDING = 40;
  2532. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2533. const VERTICAL_PADDING = 5;
  2534. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2535. const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
  2536. const RenderingStates = {
  2537. INITIAL: 0,
  2538. RUNNING: 1,
  2539. PAUSED: 2,
  2540. FINISHED: 3
  2541. };
  2542. exports.RenderingStates = RenderingStates;
  2543. const PresentationModeState = {
  2544. UNKNOWN: 0,
  2545. NORMAL: 1,
  2546. CHANGING: 2,
  2547. FULLSCREEN: 3
  2548. };
  2549. exports.PresentationModeState = PresentationModeState;
  2550. const SidebarView = {
  2551. UNKNOWN: -1,
  2552. NONE: 0,
  2553. THUMBS: 1,
  2554. OUTLINE: 2,
  2555. ATTACHMENTS: 3,
  2556. LAYERS: 4
  2557. };
  2558. exports.SidebarView = SidebarView;
  2559. const RendererType = {
  2560. CANVAS: "canvas",
  2561. SVG: "svg"
  2562. };
  2563. exports.RendererType = RendererType;
  2564. const TextLayerMode = {
  2565. DISABLE: 0,
  2566. ENABLE: 1,
  2567. ENABLE_ENHANCE: 2
  2568. };
  2569. exports.TextLayerMode = TextLayerMode;
  2570. const ScrollMode = {
  2571. UNKNOWN: -1,
  2572. VERTICAL: 0,
  2573. HORIZONTAL: 1,
  2574. WRAPPED: 2,
  2575. PAGE: 3
  2576. };
  2577. exports.ScrollMode = ScrollMode;
  2578. const SpreadMode = {
  2579. UNKNOWN: -1,
  2580. NONE: 0,
  2581. ODD: 1,
  2582. EVEN: 2
  2583. };
  2584. exports.SpreadMode = SpreadMode;
  2585. const AutoPrintRegExp = /\bprint\s*\(/;
  2586. exports.AutoPrintRegExp = AutoPrintRegExp;
  2587. class OutputScale {
  2588. constructor() {
  2589. const pixelRatio = window.devicePixelRatio || 1;
  2590. this.sx = pixelRatio;
  2591. this.sy = pixelRatio;
  2592. }
  2593. get scaled() {
  2594. return this.sx !== 1 || this.sy !== 1;
  2595. }
  2596. }
  2597. exports.OutputScale = OutputScale;
  2598. function scrollIntoView(element, spot, scrollMatches = false) {
  2599. let parent = element.offsetParent;
  2600. if (!parent) {
  2601. console.error("offsetParent is not set -- cannot scroll");
  2602. return;
  2603. }
  2604. let offsetY = element.offsetTop + element.clientTop;
  2605. let offsetX = element.offsetLeft + element.clientLeft;
  2606. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  2607. offsetY += parent.offsetTop;
  2608. offsetX += parent.offsetLeft;
  2609. parent = parent.offsetParent;
  2610. if (!parent) {
  2611. return;
  2612. }
  2613. }
  2614. if (spot) {
  2615. if (spot.top !== undefined) {
  2616. offsetY += spot.top;
  2617. }
  2618. if (spot.left !== undefined) {
  2619. offsetX += spot.left;
  2620. parent.scrollLeft = offsetX;
  2621. }
  2622. }
  2623. parent.scrollTop = offsetY;
  2624. }
  2625. function watchScroll(viewAreaElement, callback) {
  2626. const debounceScroll = function (evt) {
  2627. if (rAF) {
  2628. return;
  2629. }
  2630. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2631. rAF = null;
  2632. const currentX = viewAreaElement.scrollLeft;
  2633. const lastX = state.lastX;
  2634. if (currentX !== lastX) {
  2635. state.right = currentX > lastX;
  2636. }
  2637. state.lastX = currentX;
  2638. const currentY = viewAreaElement.scrollTop;
  2639. const lastY = state.lastY;
  2640. if (currentY !== lastY) {
  2641. state.down = currentY > lastY;
  2642. }
  2643. state.lastY = currentY;
  2644. callback(state);
  2645. });
  2646. };
  2647. const state = {
  2648. right: true,
  2649. down: true,
  2650. lastX: viewAreaElement.scrollLeft,
  2651. lastY: viewAreaElement.scrollTop,
  2652. _eventHandler: debounceScroll
  2653. };
  2654. let rAF = null;
  2655. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2656. return state;
  2657. }
  2658. function parseQueryString(query) {
  2659. const params = new Map();
  2660. for (const [key, value] of new URLSearchParams(query)) {
  2661. params.set(key.toLowerCase(), value);
  2662. }
  2663. return params;
  2664. }
  2665. const NullCharactersRegExp = /\x00/g;
  2666. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  2667. function removeNullCharacters(str, replaceInvisible = false) {
  2668. if (typeof str !== "string") {
  2669. console.error(`The argument must be a string.`);
  2670. return str;
  2671. }
  2672. if (replaceInvisible) {
  2673. str = str.replace(InvisibleCharactersRegExp, " ");
  2674. }
  2675. return str.replace(NullCharactersRegExp, "");
  2676. }
  2677. function binarySearchFirstItem(items, condition, start = 0) {
  2678. let minIndex = start;
  2679. let maxIndex = items.length - 1;
  2680. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2681. return items.length;
  2682. }
  2683. if (condition(items[minIndex])) {
  2684. return minIndex;
  2685. }
  2686. while (minIndex < maxIndex) {
  2687. const currentIndex = minIndex + maxIndex >> 1;
  2688. const currentItem = items[currentIndex];
  2689. if (condition(currentItem)) {
  2690. maxIndex = currentIndex;
  2691. } else {
  2692. minIndex = currentIndex + 1;
  2693. }
  2694. }
  2695. return minIndex;
  2696. }
  2697. function approximateFraction(x) {
  2698. if (Math.floor(x) === x) {
  2699. return [x, 1];
  2700. }
  2701. const xinv = 1 / x;
  2702. const limit = 8;
  2703. if (xinv > limit) {
  2704. return [1, limit];
  2705. } else if (Math.floor(xinv) === xinv) {
  2706. return [1, xinv];
  2707. }
  2708. const x_ = x > 1 ? xinv : x;
  2709. let a = 0,
  2710. b = 1,
  2711. c = 1,
  2712. d = 1;
  2713. while (true) {
  2714. const p = a + c,
  2715. q = b + d;
  2716. if (q > limit) {
  2717. break;
  2718. }
  2719. if (x_ <= p / q) {
  2720. c = p;
  2721. d = q;
  2722. } else {
  2723. a = p;
  2724. b = q;
  2725. }
  2726. }
  2727. let result;
  2728. if (x_ - a / b < c / d - x_) {
  2729. result = x_ === x ? [a, b] : [b, a];
  2730. } else {
  2731. result = x_ === x ? [c, d] : [d, c];
  2732. }
  2733. return result;
  2734. }
  2735. function roundToDivide(x, div) {
  2736. const r = x % div;
  2737. return r === 0 ? x : Math.round(x - r + div);
  2738. }
  2739. function getPageSizeInches({
  2740. view,
  2741. userUnit,
  2742. rotate
  2743. }) {
  2744. const [x1, y1, x2, y2] = view;
  2745. const changeOrientation = rotate % 180 !== 0;
  2746. const width = (x2 - x1) / 72 * userUnit;
  2747. const height = (y2 - y1) / 72 * userUnit;
  2748. return {
  2749. width: changeOrientation ? height : width,
  2750. height: changeOrientation ? width : height
  2751. };
  2752. }
  2753. function backtrackBeforeAllVisibleElements(index, views, top) {
  2754. if (index < 2) {
  2755. return index;
  2756. }
  2757. let elt = views[index].div;
  2758. let pageTop = elt.offsetTop + elt.clientTop;
  2759. if (pageTop >= top) {
  2760. elt = views[index - 1].div;
  2761. pageTop = elt.offsetTop + elt.clientTop;
  2762. }
  2763. for (let i = index - 2; i >= 0; --i) {
  2764. elt = views[i].div;
  2765. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2766. break;
  2767. }
  2768. index = i;
  2769. }
  2770. return index;
  2771. }
  2772. function getVisibleElements({
  2773. scrollEl,
  2774. views,
  2775. sortByVisibility = false,
  2776. horizontal = false,
  2777. rtl = false
  2778. }) {
  2779. const top = scrollEl.scrollTop,
  2780. bottom = top + scrollEl.clientHeight;
  2781. const left = scrollEl.scrollLeft,
  2782. right = left + scrollEl.clientWidth;
  2783. function isElementBottomAfterViewTop(view) {
  2784. const element = view.div;
  2785. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2786. return elementBottom > top;
  2787. }
  2788. function isElementNextAfterViewHorizontally(view) {
  2789. const element = view.div;
  2790. const elementLeft = element.offsetLeft + element.clientLeft;
  2791. const elementRight = elementLeft + element.clientWidth;
  2792. return rtl ? elementLeft < right : elementRight > left;
  2793. }
  2794. const visible = [],
  2795. ids = new Set(),
  2796. numViews = views.length;
  2797. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2798. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2799. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2800. }
  2801. let lastEdge = horizontal ? right : -1;
  2802. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2803. const view = views[i],
  2804. element = view.div;
  2805. const currentWidth = element.offsetLeft + element.clientLeft;
  2806. const currentHeight = element.offsetTop + element.clientTop;
  2807. const viewWidth = element.clientWidth,
  2808. viewHeight = element.clientHeight;
  2809. const viewRight = currentWidth + viewWidth;
  2810. const viewBottom = currentHeight + viewHeight;
  2811. if (lastEdge === -1) {
  2812. if (viewBottom >= bottom) {
  2813. lastEdge = viewBottom;
  2814. }
  2815. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2816. break;
  2817. }
  2818. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2819. continue;
  2820. }
  2821. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2822. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2823. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2824. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2825. const percent = fractionHeight * fractionWidth * 100 | 0;
  2826. visible.push({
  2827. id: view.id,
  2828. x: currentWidth,
  2829. y: currentHeight,
  2830. view,
  2831. percent,
  2832. widthPercent: fractionWidth * 100 | 0
  2833. });
  2834. ids.add(view.id);
  2835. }
  2836. const first = visible[0],
  2837. last = visible[visible.length - 1];
  2838. if (sortByVisibility) {
  2839. visible.sort(function (a, b) {
  2840. const pc = a.percent - b.percent;
  2841. if (Math.abs(pc) > 0.001) {
  2842. return -pc;
  2843. }
  2844. return a.id - b.id;
  2845. });
  2846. }
  2847. return {
  2848. first,
  2849. last,
  2850. views: visible,
  2851. ids
  2852. };
  2853. }
  2854. function noContextMenuHandler(evt) {
  2855. evt.preventDefault();
  2856. }
  2857. function normalizeWheelEventDirection(evt) {
  2858. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2859. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2860. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2861. delta = -delta;
  2862. }
  2863. return delta;
  2864. }
  2865. function normalizeWheelEventDelta(evt) {
  2866. let delta = normalizeWheelEventDirection(evt);
  2867. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  2868. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  2869. const MOUSE_PIXELS_PER_LINE = 30;
  2870. const MOUSE_LINES_PER_PAGE = 30;
  2871. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  2872. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2873. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  2874. delta /= MOUSE_LINES_PER_PAGE;
  2875. }
  2876. return delta;
  2877. }
  2878. function isValidRotation(angle) {
  2879. return Number.isInteger(angle) && angle % 90 === 0;
  2880. }
  2881. function isValidScrollMode(mode) {
  2882. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2883. }
  2884. function isValidSpreadMode(mode) {
  2885. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2886. }
  2887. function isPortraitOrientation(size) {
  2888. return size.width <= size.height;
  2889. }
  2890. const animationStarted = new Promise(function (resolve) {
  2891. window.requestAnimationFrame(resolve);
  2892. });
  2893. exports.animationStarted = animationStarted;
  2894. function clamp(v, min, max) {
  2895. return Math.min(Math.max(v, min), max);
  2896. }
  2897. class ProgressBar {
  2898. constructor(id, {
  2899. height,
  2900. width,
  2901. units
  2902. } = {}) {
  2903. this.visible = true;
  2904. this.div = document.querySelector(id + " .progress");
  2905. this.bar = this.div.parentNode;
  2906. this.height = height || 100;
  2907. this.width = width || 100;
  2908. this.units = units || "%";
  2909. this.div.style.height = this.height + this.units;
  2910. this.percent = 0;
  2911. }
  2912. _updateBar() {
  2913. if (this._indeterminate) {
  2914. this.div.classList.add("indeterminate");
  2915. this.div.style.width = this.width + this.units;
  2916. return;
  2917. }
  2918. this.div.classList.remove("indeterminate");
  2919. const progressSize = this.width * this._percent / 100;
  2920. this.div.style.width = progressSize + this.units;
  2921. }
  2922. get percent() {
  2923. return this._percent;
  2924. }
  2925. set percent(val) {
  2926. this._indeterminate = isNaN(val);
  2927. this._percent = clamp(val, 0, 100);
  2928. this._updateBar();
  2929. }
  2930. setWidth(viewer) {
  2931. if (!viewer) {
  2932. return;
  2933. }
  2934. const container = viewer.parentNode;
  2935. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  2936. if (scrollbarWidth > 0) {
  2937. const doc = document.documentElement;
  2938. doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
  2939. }
  2940. }
  2941. hide() {
  2942. if (!this.visible) {
  2943. return;
  2944. }
  2945. this.visible = false;
  2946. this.bar.classList.add("hidden");
  2947. }
  2948. show() {
  2949. if (this.visible) {
  2950. return;
  2951. }
  2952. this.visible = true;
  2953. this.bar.classList.remove("hidden");
  2954. }
  2955. }
  2956. exports.ProgressBar = ProgressBar;
  2957. function getActiveOrFocusedElement() {
  2958. let curRoot = document;
  2959. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2960. while (curActiveOrFocused?.shadowRoot) {
  2961. curRoot = curActiveOrFocused.shadowRoot;
  2962. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2963. }
  2964. return curActiveOrFocused;
  2965. }
  2966. function apiPageLayoutToViewerModes(layout) {
  2967. let scrollMode = ScrollMode.VERTICAL,
  2968. spreadMode = SpreadMode.NONE;
  2969. switch (layout) {
  2970. case "SinglePage":
  2971. scrollMode = ScrollMode.PAGE;
  2972. break;
  2973. case "OneColumn":
  2974. break;
  2975. case "TwoPageLeft":
  2976. scrollMode = ScrollMode.PAGE;
  2977. case "TwoColumnLeft":
  2978. spreadMode = SpreadMode.ODD;
  2979. break;
  2980. case "TwoPageRight":
  2981. scrollMode = ScrollMode.PAGE;
  2982. case "TwoColumnRight":
  2983. spreadMode = SpreadMode.EVEN;
  2984. break;
  2985. }
  2986. return {
  2987. scrollMode,
  2988. spreadMode
  2989. };
  2990. }
  2991. function apiPageModeToSidebarView(mode) {
  2992. switch (mode) {
  2993. case "UseNone":
  2994. return SidebarView.NONE;
  2995. case "UseThumbs":
  2996. return SidebarView.THUMBS;
  2997. case "UseOutlines":
  2998. return SidebarView.OUTLINE;
  2999. case "UseAttachments":
  3000. return SidebarView.ATTACHMENTS;
  3001. case "UseOC":
  3002. return SidebarView.LAYERS;
  3003. }
  3004. return SidebarView.NONE;
  3005. }
  3006. /***/ }),
  3007. /* 4 */
  3008. /***/ ((__unused_webpack_module, exports) => {
  3009. Object.defineProperty(exports, "__esModule", ({
  3010. value: true
  3011. }));
  3012. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3013. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3014. const WaitOnType = {
  3015. EVENT: "event",
  3016. TIMEOUT: "timeout"
  3017. };
  3018. exports.WaitOnType = WaitOnType;
  3019. function waitOnEventOrTimeout({
  3020. target,
  3021. name,
  3022. delay = 0
  3023. }) {
  3024. return new Promise(function (resolve, reject) {
  3025. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3026. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3027. }
  3028. function handler(type) {
  3029. if (target instanceof EventBus) {
  3030. target._off(name, eventHandler);
  3031. } else {
  3032. target.removeEventListener(name, eventHandler);
  3033. }
  3034. if (timeout) {
  3035. clearTimeout(timeout);
  3036. }
  3037. resolve(type);
  3038. }
  3039. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3040. if (target instanceof EventBus) {
  3041. target._on(name, eventHandler);
  3042. } else {
  3043. target.addEventListener(name, eventHandler);
  3044. }
  3045. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3046. const timeout = setTimeout(timeoutHandler, delay);
  3047. });
  3048. }
  3049. class EventBus {
  3050. constructor() {
  3051. this._listeners = Object.create(null);
  3052. }
  3053. on(eventName, listener, options = null) {
  3054. this._on(eventName, listener, {
  3055. external: true,
  3056. once: options?.once
  3057. });
  3058. }
  3059. off(eventName, listener, options = null) {
  3060. this._off(eventName, listener, {
  3061. external: true,
  3062. once: options?.once
  3063. });
  3064. }
  3065. dispatch(eventName, data) {
  3066. const eventListeners = this._listeners[eventName];
  3067. if (!eventListeners || eventListeners.length === 0) {
  3068. return;
  3069. }
  3070. let externalListeners;
  3071. for (const {
  3072. listener,
  3073. external,
  3074. once
  3075. } of eventListeners.slice(0)) {
  3076. if (once) {
  3077. this._off(eventName, listener);
  3078. }
  3079. if (external) {
  3080. (externalListeners ||= []).push(listener);
  3081. continue;
  3082. }
  3083. listener(data);
  3084. }
  3085. if (externalListeners) {
  3086. for (const listener of externalListeners) {
  3087. listener(data);
  3088. }
  3089. externalListeners = null;
  3090. }
  3091. }
  3092. _on(eventName, listener, options = null) {
  3093. const eventListeners = this._listeners[eventName] ||= [];
  3094. eventListeners.push({
  3095. listener,
  3096. external: options?.external === true,
  3097. once: options?.once === true
  3098. });
  3099. }
  3100. _off(eventName, listener, options = null) {
  3101. const eventListeners = this._listeners[eventName];
  3102. if (!eventListeners) {
  3103. return;
  3104. }
  3105. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3106. if (eventListeners[i].listener === listener) {
  3107. eventListeners.splice(i, 1);
  3108. return;
  3109. }
  3110. }
  3111. }
  3112. }
  3113. exports.EventBus = EventBus;
  3114. class AutomationEventBus extends EventBus {
  3115. dispatch(eventName, data) {
  3116. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3117. }
  3118. }
  3119. exports.AutomationEventBus = AutomationEventBus;
  3120. /***/ }),
  3121. /* 5 */
  3122. /***/ ((module) => {
  3123. let pdfjsLib;
  3124. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3125. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3126. } else {
  3127. pdfjsLib = require("../build/pdf.js");
  3128. }
  3129. module.exports = pdfjsLib;
  3130. /***/ }),
  3131. /* 6 */
  3132. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3133. Object.defineProperty(exports, "__esModule", ({
  3134. value: true
  3135. }));
  3136. exports.PDFCursorTools = exports.CursorTool = void 0;
  3137. var _grab_to_pan = __webpack_require__(7);
  3138. var _ui_utils = __webpack_require__(3);
  3139. const CursorTool = {
  3140. SELECT: 0,
  3141. HAND: 1,
  3142. ZOOM: 2
  3143. };
  3144. exports.CursorTool = CursorTool;
  3145. class PDFCursorTools {
  3146. constructor({
  3147. container,
  3148. eventBus,
  3149. cursorToolOnLoad = CursorTool.SELECT
  3150. }) {
  3151. this.container = container;
  3152. this.eventBus = eventBus;
  3153. this.active = CursorTool.SELECT;
  3154. this.activeBeforePresentationMode = null;
  3155. this.handTool = new _grab_to_pan.GrabToPan({
  3156. element: this.container
  3157. });
  3158. this._addEventListeners();
  3159. Promise.resolve().then(() => {
  3160. this.switchTool(cursorToolOnLoad);
  3161. });
  3162. }
  3163. get activeTool() {
  3164. return this.active;
  3165. }
  3166. switchTool(tool) {
  3167. if (this.activeBeforePresentationMode !== null) {
  3168. return;
  3169. }
  3170. if (tool === this.active) {
  3171. return;
  3172. }
  3173. const disableActiveTool = () => {
  3174. switch (this.active) {
  3175. case CursorTool.SELECT:
  3176. break;
  3177. case CursorTool.HAND:
  3178. this.handTool.deactivate();
  3179. break;
  3180. case CursorTool.ZOOM:
  3181. }
  3182. };
  3183. switch (tool) {
  3184. case CursorTool.SELECT:
  3185. disableActiveTool();
  3186. break;
  3187. case CursorTool.HAND:
  3188. disableActiveTool();
  3189. this.handTool.activate();
  3190. break;
  3191. case CursorTool.ZOOM:
  3192. default:
  3193. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3194. return;
  3195. }
  3196. this.active = tool;
  3197. this._dispatchEvent();
  3198. }
  3199. _dispatchEvent() {
  3200. this.eventBus.dispatch("cursortoolchanged", {
  3201. source: this,
  3202. tool: this.active
  3203. });
  3204. }
  3205. _addEventListeners() {
  3206. this.eventBus._on("switchcursortool", evt => {
  3207. this.switchTool(evt.tool);
  3208. });
  3209. this.eventBus._on("presentationmodechanged", evt => {
  3210. switch (evt.state) {
  3211. case _ui_utils.PresentationModeState.FULLSCREEN:
  3212. {
  3213. const previouslyActive = this.active;
  3214. this.switchTool(CursorTool.SELECT);
  3215. this.activeBeforePresentationMode = previouslyActive;
  3216. break;
  3217. }
  3218. case _ui_utils.PresentationModeState.NORMAL:
  3219. {
  3220. const previouslyActive = this.activeBeforePresentationMode;
  3221. this.activeBeforePresentationMode = null;
  3222. this.switchTool(previouslyActive);
  3223. break;
  3224. }
  3225. }
  3226. });
  3227. }
  3228. }
  3229. exports.PDFCursorTools = PDFCursorTools;
  3230. /***/ }),
  3231. /* 7 */
  3232. /***/ ((__unused_webpack_module, exports) => {
  3233. Object.defineProperty(exports, "__esModule", ({
  3234. value: true
  3235. }));
  3236. exports.GrabToPan = void 0;
  3237. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3238. class GrabToPan {
  3239. constructor(options) {
  3240. this.element = options.element;
  3241. this.document = options.element.ownerDocument;
  3242. if (typeof options.ignoreTarget === "function") {
  3243. this.ignoreTarget = options.ignoreTarget;
  3244. }
  3245. this.onActiveChanged = options.onActiveChanged;
  3246. this.activate = this.activate.bind(this);
  3247. this.deactivate = this.deactivate.bind(this);
  3248. this.toggle = this.toggle.bind(this);
  3249. this._onMouseDown = this.#onMouseDown.bind(this);
  3250. this._onMouseMove = this.#onMouseMove.bind(this);
  3251. this._endPan = this.#endPan.bind(this);
  3252. const overlay = this.overlay = document.createElement("div");
  3253. overlay.className = "grab-to-pan-grabbing";
  3254. }
  3255. activate() {
  3256. if (!this.active) {
  3257. this.active = true;
  3258. this.element.addEventListener("mousedown", this._onMouseDown, true);
  3259. this.element.classList.add(CSS_CLASS_GRAB);
  3260. this.onActiveChanged?.(true);
  3261. }
  3262. }
  3263. deactivate() {
  3264. if (this.active) {
  3265. this.active = false;
  3266. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  3267. this._endPan();
  3268. this.element.classList.remove(CSS_CLASS_GRAB);
  3269. this.onActiveChanged?.(false);
  3270. }
  3271. }
  3272. toggle() {
  3273. if (this.active) {
  3274. this.deactivate();
  3275. } else {
  3276. this.activate();
  3277. }
  3278. }
  3279. ignoreTarget(node) {
  3280. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3281. }
  3282. #onMouseDown(event) {
  3283. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3284. return;
  3285. }
  3286. if (event.originalTarget) {
  3287. try {
  3288. event.originalTarget.tagName;
  3289. } catch (e) {
  3290. return;
  3291. }
  3292. }
  3293. this.scrollLeftStart = this.element.scrollLeft;
  3294. this.scrollTopStart = this.element.scrollTop;
  3295. this.clientXStart = event.clientX;
  3296. this.clientYStart = event.clientY;
  3297. this.document.addEventListener("mousemove", this._onMouseMove, true);
  3298. this.document.addEventListener("mouseup", this._endPan, true);
  3299. this.element.addEventListener("scroll", this._endPan, true);
  3300. event.preventDefault();
  3301. event.stopPropagation();
  3302. const focusedElement = document.activeElement;
  3303. if (focusedElement && !focusedElement.contains(event.target)) {
  3304. focusedElement.blur();
  3305. }
  3306. }
  3307. #onMouseMove(event) {
  3308. this.element.removeEventListener("scroll", this._endPan, true);
  3309. if (!(event.buttons & 1)) {
  3310. this._endPan();
  3311. return;
  3312. }
  3313. const xDiff = event.clientX - this.clientXStart;
  3314. const yDiff = event.clientY - this.clientYStart;
  3315. const scrollTop = this.scrollTopStart - yDiff;
  3316. const scrollLeft = this.scrollLeftStart - xDiff;
  3317. if (this.element.scrollTo) {
  3318. this.element.scrollTo({
  3319. top: scrollTop,
  3320. left: scrollLeft,
  3321. behavior: "instant"
  3322. });
  3323. } else {
  3324. this.element.scrollTop = scrollTop;
  3325. this.element.scrollLeft = scrollLeft;
  3326. }
  3327. if (!this.overlay.parentNode) {
  3328. document.body.appendChild(this.overlay);
  3329. }
  3330. }
  3331. #endPan() {
  3332. this.element.removeEventListener("scroll", this._endPan, true);
  3333. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  3334. this.document.removeEventListener("mouseup", this._endPan, true);
  3335. this.overlay.remove();
  3336. }
  3337. }
  3338. exports.GrabToPan = GrabToPan;
  3339. /***/ }),
  3340. /* 8 */
  3341. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3342. Object.defineProperty(exports, "__esModule", ({
  3343. value: true
  3344. }));
  3345. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  3346. var _ui_utils = __webpack_require__(3);
  3347. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  3348. const LinkTarget = {
  3349. NONE: 0,
  3350. SELF: 1,
  3351. BLANK: 2,
  3352. PARENT: 3,
  3353. TOP: 4
  3354. };
  3355. exports.LinkTarget = LinkTarget;
  3356. function addLinkAttributes(link, {
  3357. url,
  3358. target,
  3359. rel,
  3360. enabled = true
  3361. } = {}) {
  3362. if (!url || typeof url !== "string") {
  3363. throw new Error('A valid "url" parameter must provided.');
  3364. }
  3365. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  3366. if (enabled) {
  3367. link.href = link.title = urlNullRemoved;
  3368. } else {
  3369. link.href = "";
  3370. link.title = `Disabled: ${urlNullRemoved}`;
  3371. link.onclick = () => {
  3372. return false;
  3373. };
  3374. }
  3375. let targetStr = "";
  3376. switch (target) {
  3377. case LinkTarget.NONE:
  3378. break;
  3379. case LinkTarget.SELF:
  3380. targetStr = "_self";
  3381. break;
  3382. case LinkTarget.BLANK:
  3383. targetStr = "_blank";
  3384. break;
  3385. case LinkTarget.PARENT:
  3386. targetStr = "_parent";
  3387. break;
  3388. case LinkTarget.TOP:
  3389. targetStr = "_top";
  3390. break;
  3391. }
  3392. link.target = targetStr;
  3393. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  3394. }
  3395. class PDFLinkService {
  3396. #pagesRefCache = new Map();
  3397. constructor({
  3398. eventBus,
  3399. externalLinkTarget = null,
  3400. externalLinkRel = null,
  3401. ignoreDestinationZoom = false
  3402. } = {}) {
  3403. this.eventBus = eventBus;
  3404. this.externalLinkTarget = externalLinkTarget;
  3405. this.externalLinkRel = externalLinkRel;
  3406. this.externalLinkEnabled = true;
  3407. this._ignoreDestinationZoom = ignoreDestinationZoom;
  3408. this.baseUrl = null;
  3409. this.pdfDocument = null;
  3410. this.pdfViewer = null;
  3411. this.pdfHistory = null;
  3412. }
  3413. setDocument(pdfDocument, baseUrl = null) {
  3414. this.baseUrl = baseUrl;
  3415. this.pdfDocument = pdfDocument;
  3416. this.#pagesRefCache.clear();
  3417. }
  3418. setViewer(pdfViewer) {
  3419. this.pdfViewer = pdfViewer;
  3420. }
  3421. setHistory(pdfHistory) {
  3422. this.pdfHistory = pdfHistory;
  3423. }
  3424. get pagesCount() {
  3425. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  3426. }
  3427. get page() {
  3428. return this.pdfViewer.currentPageNumber;
  3429. }
  3430. set page(value) {
  3431. this.pdfViewer.currentPageNumber = value;
  3432. }
  3433. get rotation() {
  3434. return this.pdfViewer.pagesRotation;
  3435. }
  3436. set rotation(value) {
  3437. this.pdfViewer.pagesRotation = value;
  3438. }
  3439. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  3440. const destRef = explicitDest[0];
  3441. let pageNumber;
  3442. if (typeof destRef === "object" && destRef !== null) {
  3443. pageNumber = this._cachedPageNumber(destRef);
  3444. if (!pageNumber) {
  3445. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  3446. this.cachePageRef(pageIndex + 1, destRef);
  3447. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  3448. }).catch(() => {
  3449. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  3450. });
  3451. return;
  3452. }
  3453. } else if (Number.isInteger(destRef)) {
  3454. pageNumber = destRef + 1;
  3455. } else {
  3456. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  3457. return;
  3458. }
  3459. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  3460. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  3461. return;
  3462. }
  3463. if (this.pdfHistory) {
  3464. this.pdfHistory.pushCurrentPosition();
  3465. this.pdfHistory.push({
  3466. namedDest,
  3467. explicitDest,
  3468. pageNumber
  3469. });
  3470. }
  3471. this.pdfViewer.scrollPageIntoView({
  3472. pageNumber,
  3473. destArray: explicitDest,
  3474. ignoreDestinationZoom: this._ignoreDestinationZoom
  3475. });
  3476. }
  3477. async goToDestination(dest) {
  3478. if (!this.pdfDocument) {
  3479. return;
  3480. }
  3481. let namedDest, explicitDest;
  3482. if (typeof dest === "string") {
  3483. namedDest = dest;
  3484. explicitDest = await this.pdfDocument.getDestination(dest);
  3485. } else {
  3486. namedDest = null;
  3487. explicitDest = await dest;
  3488. }
  3489. if (!Array.isArray(explicitDest)) {
  3490. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  3491. return;
  3492. }
  3493. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  3494. }
  3495. goToPage(val) {
  3496. if (!this.pdfDocument) {
  3497. return;
  3498. }
  3499. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  3500. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  3501. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  3502. return;
  3503. }
  3504. if (this.pdfHistory) {
  3505. this.pdfHistory.pushCurrentPosition();
  3506. this.pdfHistory.pushPage(pageNumber);
  3507. }
  3508. this.pdfViewer.scrollPageIntoView({
  3509. pageNumber
  3510. });
  3511. }
  3512. addLinkAttributes(link, url, newWindow = false) {
  3513. addLinkAttributes(link, {
  3514. url,
  3515. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  3516. rel: this.externalLinkRel,
  3517. enabled: this.externalLinkEnabled
  3518. });
  3519. }
  3520. getDestinationHash(dest) {
  3521. if (typeof dest === "string") {
  3522. if (dest.length > 0) {
  3523. return this.getAnchorUrl("#" + escape(dest));
  3524. }
  3525. } else if (Array.isArray(dest)) {
  3526. const str = JSON.stringify(dest);
  3527. if (str.length > 0) {
  3528. return this.getAnchorUrl("#" + escape(str));
  3529. }
  3530. }
  3531. return this.getAnchorUrl("");
  3532. }
  3533. getAnchorUrl(anchor) {
  3534. return (this.baseUrl || "") + anchor;
  3535. }
  3536. setHash(hash) {
  3537. if (!this.pdfDocument) {
  3538. return;
  3539. }
  3540. let pageNumber, dest;
  3541. if (hash.includes("=")) {
  3542. const params = (0, _ui_utils.parseQueryString)(hash);
  3543. if (params.has("search")) {
  3544. this.eventBus.dispatch("findfromurlhash", {
  3545. source: this,
  3546. query: params.get("search").replace(/"/g, ""),
  3547. phraseSearch: params.get("phrase") === "true"
  3548. });
  3549. }
  3550. if (params.has("page")) {
  3551. pageNumber = params.get("page") | 0 || 1;
  3552. }
  3553. if (params.has("zoom")) {
  3554. const zoomArgs = params.get("zoom").split(",");
  3555. const zoomArg = zoomArgs[0];
  3556. const zoomArgNumber = parseFloat(zoomArg);
  3557. if (!zoomArg.includes("Fit")) {
  3558. dest = [null, {
  3559. name: "XYZ"
  3560. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  3561. } else {
  3562. if (zoomArg === "Fit" || zoomArg === "FitB") {
  3563. dest = [null, {
  3564. name: zoomArg
  3565. }];
  3566. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  3567. dest = [null, {
  3568. name: zoomArg
  3569. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  3570. } else if (zoomArg === "FitR") {
  3571. if (zoomArgs.length !== 5) {
  3572. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  3573. } else {
  3574. dest = [null, {
  3575. name: zoomArg
  3576. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  3577. }
  3578. } else {
  3579. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  3580. }
  3581. }
  3582. }
  3583. if (dest) {
  3584. this.pdfViewer.scrollPageIntoView({
  3585. pageNumber: pageNumber || this.page,
  3586. destArray: dest,
  3587. allowNegativeOffset: true
  3588. });
  3589. } else if (pageNumber) {
  3590. this.page = pageNumber;
  3591. }
  3592. if (params.has("pagemode")) {
  3593. this.eventBus.dispatch("pagemode", {
  3594. source: this,
  3595. mode: params.get("pagemode")
  3596. });
  3597. }
  3598. if (params.has("nameddest")) {
  3599. this.goToDestination(params.get("nameddest"));
  3600. }
  3601. } else {
  3602. dest = unescape(hash);
  3603. try {
  3604. dest = JSON.parse(dest);
  3605. if (!Array.isArray(dest)) {
  3606. dest = dest.toString();
  3607. }
  3608. } catch (ex) {}
  3609. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  3610. this.goToDestination(dest);
  3611. return;
  3612. }
  3613. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  3614. }
  3615. }
  3616. executeNamedAction(action) {
  3617. switch (action) {
  3618. case "GoBack":
  3619. this.pdfHistory?.back();
  3620. break;
  3621. case "GoForward":
  3622. this.pdfHistory?.forward();
  3623. break;
  3624. case "NextPage":
  3625. this.pdfViewer.nextPage();
  3626. break;
  3627. case "PrevPage":
  3628. this.pdfViewer.previousPage();
  3629. break;
  3630. case "LastPage":
  3631. this.page = this.pagesCount;
  3632. break;
  3633. case "FirstPage":
  3634. this.page = 1;
  3635. break;
  3636. default:
  3637. break;
  3638. }
  3639. this.eventBus.dispatch("namedaction", {
  3640. source: this,
  3641. action
  3642. });
  3643. }
  3644. cachePageRef(pageNum, pageRef) {
  3645. if (!pageRef) {
  3646. return;
  3647. }
  3648. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3649. this.#pagesRefCache.set(refStr, pageNum);
  3650. }
  3651. _cachedPageNumber(pageRef) {
  3652. if (!pageRef) {
  3653. return null;
  3654. }
  3655. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3656. return this.#pagesRefCache.get(refStr) || null;
  3657. }
  3658. isPageVisible(pageNumber) {
  3659. return this.pdfViewer.isPageVisible(pageNumber);
  3660. }
  3661. isPageCached(pageNumber) {
  3662. return this.pdfViewer.isPageCached(pageNumber);
  3663. }
  3664. static #isValidExplicitDestination(dest) {
  3665. if (!Array.isArray(dest)) {
  3666. return false;
  3667. }
  3668. const destLength = dest.length;
  3669. if (destLength < 2) {
  3670. return false;
  3671. }
  3672. const page = dest[0];
  3673. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  3674. return false;
  3675. }
  3676. const zoom = dest[1];
  3677. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  3678. return false;
  3679. }
  3680. let allowNull = true;
  3681. switch (zoom.name) {
  3682. case "XYZ":
  3683. if (destLength !== 5) {
  3684. return false;
  3685. }
  3686. break;
  3687. case "Fit":
  3688. case "FitB":
  3689. return destLength === 2;
  3690. case "FitH":
  3691. case "FitBH":
  3692. case "FitV":
  3693. case "FitBV":
  3694. if (destLength !== 3) {
  3695. return false;
  3696. }
  3697. break;
  3698. case "FitR":
  3699. if (destLength !== 6) {
  3700. return false;
  3701. }
  3702. allowNull = false;
  3703. break;
  3704. default:
  3705. return false;
  3706. }
  3707. for (let i = 2; i < destLength; i++) {
  3708. const param = dest[i];
  3709. if (!(typeof param === "number" || allowNull && param === null)) {
  3710. return false;
  3711. }
  3712. }
  3713. return true;
  3714. }
  3715. }
  3716. exports.PDFLinkService = PDFLinkService;
  3717. class SimpleLinkService {
  3718. constructor() {
  3719. this.externalLinkEnabled = true;
  3720. }
  3721. get pagesCount() {
  3722. return 0;
  3723. }
  3724. get page() {
  3725. return 0;
  3726. }
  3727. set page(value) {}
  3728. get rotation() {
  3729. return 0;
  3730. }
  3731. set rotation(value) {}
  3732. async goToDestination(dest) {}
  3733. goToPage(val) {}
  3734. addLinkAttributes(link, url, newWindow = false) {
  3735. addLinkAttributes(link, {
  3736. url,
  3737. enabled: this.externalLinkEnabled
  3738. });
  3739. }
  3740. getDestinationHash(dest) {
  3741. return "#";
  3742. }
  3743. getAnchorUrl(hash) {
  3744. return "#";
  3745. }
  3746. setHash(hash) {}
  3747. executeNamedAction(action) {}
  3748. cachePageRef(pageNum, pageRef) {}
  3749. isPageVisible(pageNumber) {
  3750. return true;
  3751. }
  3752. isPageCached(pageNumber) {
  3753. return true;
  3754. }
  3755. }
  3756. exports.SimpleLinkService = SimpleLinkService;
  3757. /***/ }),
  3758. /* 9 */
  3759. /***/ ((__unused_webpack_module, exports) => {
  3760. Object.defineProperty(exports, "__esModule", ({
  3761. value: true
  3762. }));
  3763. exports.OverlayManager = void 0;
  3764. class OverlayManager {
  3765. constructor() {
  3766. this._overlays = {};
  3767. this._active = null;
  3768. this._keyDownBound = this._keyDown.bind(this);
  3769. }
  3770. get active() {
  3771. return this._active;
  3772. }
  3773. async register(name, element, callerCloseMethod = null, canForceClose = false) {
  3774. let container;
  3775. if (!name || !element || !(container = element.parentNode)) {
  3776. throw new Error("Not enough parameters.");
  3777. } else if (this._overlays[name]) {
  3778. throw new Error("The overlay is already registered.");
  3779. }
  3780. this._overlays[name] = {
  3781. element,
  3782. container,
  3783. callerCloseMethod,
  3784. canForceClose
  3785. };
  3786. }
  3787. async unregister(name) {
  3788. if (!this._overlays[name]) {
  3789. throw new Error("The overlay does not exist.");
  3790. } else if (this._active === name) {
  3791. throw new Error("The overlay cannot be removed while it is active.");
  3792. }
  3793. delete this._overlays[name];
  3794. }
  3795. async open(name) {
  3796. if (!this._overlays[name]) {
  3797. throw new Error("The overlay does not exist.");
  3798. } else if (this._active) {
  3799. if (this._overlays[name].canForceClose) {
  3800. this._closeThroughCaller();
  3801. } else if (this._active === name) {
  3802. throw new Error("The overlay is already active.");
  3803. } else {
  3804. throw new Error("Another overlay is currently active.");
  3805. }
  3806. }
  3807. this._active = name;
  3808. this._overlays[this._active].element.classList.remove("hidden");
  3809. this._overlays[this._active].container.classList.remove("hidden");
  3810. window.addEventListener("keydown", this._keyDownBound);
  3811. }
  3812. async close(name) {
  3813. if (!this._overlays[name]) {
  3814. throw new Error("The overlay does not exist.");
  3815. } else if (!this._active) {
  3816. throw new Error("The overlay is currently not active.");
  3817. } else if (this._active !== name) {
  3818. throw new Error("Another overlay is currently active.");
  3819. }
  3820. this._overlays[this._active].container.classList.add("hidden");
  3821. this._overlays[this._active].element.classList.add("hidden");
  3822. this._active = null;
  3823. window.removeEventListener("keydown", this._keyDownBound);
  3824. }
  3825. _keyDown(evt) {
  3826. if (this._active && evt.keyCode === 27) {
  3827. this._closeThroughCaller();
  3828. evt.preventDefault();
  3829. }
  3830. }
  3831. _closeThroughCaller() {
  3832. if (this._overlays[this._active].callerCloseMethod) {
  3833. this._overlays[this._active].callerCloseMethod();
  3834. }
  3835. if (this._active) {
  3836. this.close(this._active);
  3837. }
  3838. }
  3839. }
  3840. exports.OverlayManager = OverlayManager;
  3841. /***/ }),
  3842. /* 10 */
  3843. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3844. Object.defineProperty(exports, "__esModule", ({
  3845. value: true
  3846. }));
  3847. exports.PasswordPrompt = void 0;
  3848. var _pdfjsLib = __webpack_require__(5);
  3849. class PasswordPrompt {
  3850. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3851. this.overlayName = options.overlayName;
  3852. this.container = options.container;
  3853. this.label = options.label;
  3854. this.input = options.input;
  3855. this.submitButton = options.submitButton;
  3856. this.cancelButton = options.cancelButton;
  3857. this.overlayManager = overlayManager;
  3858. this.l10n = l10n;
  3859. this._isViewerEmbedded = isViewerEmbedded;
  3860. this.updateCallback = null;
  3861. this.reason = null;
  3862. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3863. this.cancelButton.addEventListener("click", this.#cancel.bind(this));
  3864. this.input.addEventListener("keydown", e => {
  3865. if (e.keyCode === 13) {
  3866. this.#verify();
  3867. }
  3868. });
  3869. this.overlayManager.register(this.overlayName, this.container, this.#cancel.bind(this), true);
  3870. }
  3871. async open() {
  3872. await this.overlayManager.open(this.overlayName);
  3873. const passwordIncorrect = this.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3874. if (!this._isViewerEmbedded || passwordIncorrect) {
  3875. this.input.focus();
  3876. }
  3877. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3878. }
  3879. async close() {
  3880. await this.overlayManager.close(this.overlayName);
  3881. this.input.value = "";
  3882. }
  3883. #verify() {
  3884. const password = this.input.value;
  3885. if (password?.length > 0) {
  3886. this.close();
  3887. this.updateCallback(password);
  3888. }
  3889. }
  3890. #cancel() {
  3891. this.close();
  3892. this.updateCallback(new Error("PasswordPrompt cancelled."));
  3893. }
  3894. setUpdateCallback(updateCallback, reason) {
  3895. this.updateCallback = updateCallback;
  3896. this.reason = reason;
  3897. }
  3898. }
  3899. exports.PasswordPrompt = PasswordPrompt;
  3900. /***/ }),
  3901. /* 11 */
  3902. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3903. Object.defineProperty(exports, "__esModule", ({
  3904. value: true
  3905. }));
  3906. exports.PDFAttachmentViewer = void 0;
  3907. var _pdfjsLib = __webpack_require__(5);
  3908. var _base_tree_viewer = __webpack_require__(12);
  3909. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  3910. constructor(options) {
  3911. super(options);
  3912. this.downloadManager = options.downloadManager;
  3913. this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
  3914. }
  3915. reset(keepRenderedCapability = false) {
  3916. super.reset();
  3917. this._attachments = null;
  3918. if (!keepRenderedCapability) {
  3919. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  3920. }
  3921. if (this._pendingDispatchEvent) {
  3922. clearTimeout(this._pendingDispatchEvent);
  3923. }
  3924. this._pendingDispatchEvent = null;
  3925. }
  3926. _dispatchEvent(attachmentsCount) {
  3927. this._renderedCapability.resolve();
  3928. if (this._pendingDispatchEvent) {
  3929. clearTimeout(this._pendingDispatchEvent);
  3930. this._pendingDispatchEvent = null;
  3931. }
  3932. if (attachmentsCount === 0) {
  3933. this._pendingDispatchEvent = setTimeout(() => {
  3934. this.eventBus.dispatch("attachmentsloaded", {
  3935. source: this,
  3936. attachmentsCount: 0
  3937. });
  3938. this._pendingDispatchEvent = null;
  3939. });
  3940. return;
  3941. }
  3942. this.eventBus.dispatch("attachmentsloaded", {
  3943. source: this,
  3944. attachmentsCount
  3945. });
  3946. }
  3947. _bindLink(element, {
  3948. content,
  3949. filename
  3950. }) {
  3951. element.onclick = () => {
  3952. this.downloadManager.openOrDownloadData(element, content, filename);
  3953. return false;
  3954. };
  3955. }
  3956. render({
  3957. attachments,
  3958. keepRenderedCapability = false
  3959. }) {
  3960. if (this._attachments) {
  3961. this.reset(keepRenderedCapability);
  3962. }
  3963. this._attachments = attachments || null;
  3964. if (!attachments) {
  3965. this._dispatchEvent(0);
  3966. return;
  3967. }
  3968. const names = Object.keys(attachments).sort(function (a, b) {
  3969. return a.toLowerCase().localeCompare(b.toLowerCase());
  3970. });
  3971. const fragment = document.createDocumentFragment();
  3972. let attachmentsCount = 0;
  3973. for (const name of names) {
  3974. const item = attachments[name];
  3975. const content = item.content,
  3976. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  3977. const div = document.createElement("div");
  3978. div.className = "treeItem";
  3979. const element = document.createElement("a");
  3980. this._bindLink(element, {
  3981. content,
  3982. filename
  3983. });
  3984. element.textContent = this._normalizeTextContent(filename);
  3985. div.appendChild(element);
  3986. fragment.appendChild(div);
  3987. attachmentsCount++;
  3988. }
  3989. this._finishRendering(fragment, attachmentsCount);
  3990. }
  3991. _appendAttachment({
  3992. id,
  3993. filename,
  3994. content
  3995. }) {
  3996. const renderedPromise = this._renderedCapability.promise;
  3997. renderedPromise.then(() => {
  3998. if (renderedPromise !== this._renderedCapability.promise) {
  3999. return;
  4000. }
  4001. let attachments = this._attachments;
  4002. if (!attachments) {
  4003. attachments = Object.create(null);
  4004. } else {
  4005. for (const name in attachments) {
  4006. if (id === name) {
  4007. return;
  4008. }
  4009. }
  4010. }
  4011. attachments[id] = {
  4012. filename,
  4013. content
  4014. };
  4015. this.render({
  4016. attachments,
  4017. keepRenderedCapability: true
  4018. });
  4019. });
  4020. }
  4021. }
  4022. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4023. /***/ }),
  4024. /* 12 */
  4025. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4026. Object.defineProperty(exports, "__esModule", ({
  4027. value: true
  4028. }));
  4029. exports.BaseTreeViewer = void 0;
  4030. var _ui_utils = __webpack_require__(3);
  4031. const TREEITEM_OFFSET_TOP = -100;
  4032. const TREEITEM_SELECTED_CLASS = "selected";
  4033. class BaseTreeViewer {
  4034. constructor(options) {
  4035. if (this.constructor === BaseTreeViewer) {
  4036. throw new Error("Cannot initialize BaseTreeViewer.");
  4037. }
  4038. this.container = options.container;
  4039. this.eventBus = options.eventBus;
  4040. this.reset();
  4041. }
  4042. reset() {
  4043. this._pdfDocument = null;
  4044. this._lastToggleIsShow = true;
  4045. this._currentTreeItem = null;
  4046. this.container.textContent = "";
  4047. this.container.classList.remove("treeWithDeepNesting");
  4048. }
  4049. _dispatchEvent(count) {
  4050. throw new Error("Not implemented: _dispatchEvent");
  4051. }
  4052. _bindLink(element, params) {
  4053. throw new Error("Not implemented: _bindLink");
  4054. }
  4055. _normalizeTextContent(str) {
  4056. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4057. }
  4058. _addToggleButton(div, hidden = false) {
  4059. const toggler = document.createElement("div");
  4060. toggler.className = "treeItemToggler";
  4061. if (hidden) {
  4062. toggler.classList.add("treeItemsHidden");
  4063. }
  4064. toggler.onclick = evt => {
  4065. evt.stopPropagation();
  4066. toggler.classList.toggle("treeItemsHidden");
  4067. if (evt.shiftKey) {
  4068. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4069. this._toggleTreeItem(div, shouldShowAll);
  4070. }
  4071. };
  4072. div.insertBefore(toggler, div.firstChild);
  4073. }
  4074. _toggleTreeItem(root, show = false) {
  4075. this._lastToggleIsShow = show;
  4076. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4077. toggler.classList.toggle("treeItemsHidden", !show);
  4078. }
  4079. }
  4080. _toggleAllTreeItems() {
  4081. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4082. }
  4083. _finishRendering(fragment, count, hasAnyNesting = false) {
  4084. if (hasAnyNesting) {
  4085. this.container.classList.add("treeWithDeepNesting");
  4086. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4087. }
  4088. this.container.appendChild(fragment);
  4089. this._dispatchEvent(count);
  4090. }
  4091. render(params) {
  4092. throw new Error("Not implemented: render");
  4093. }
  4094. _updateCurrentTreeItem(treeItem = null) {
  4095. if (this._currentTreeItem) {
  4096. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4097. this._currentTreeItem = null;
  4098. }
  4099. if (treeItem) {
  4100. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4101. this._currentTreeItem = treeItem;
  4102. }
  4103. }
  4104. _scrollToCurrentTreeItem(treeItem) {
  4105. if (!treeItem) {
  4106. return;
  4107. }
  4108. let currentNode = treeItem.parentNode;
  4109. while (currentNode && currentNode !== this.container) {
  4110. if (currentNode.classList.contains("treeItem")) {
  4111. const toggler = currentNode.firstElementChild;
  4112. toggler?.classList.remove("treeItemsHidden");
  4113. }
  4114. currentNode = currentNode.parentNode;
  4115. }
  4116. this._updateCurrentTreeItem(treeItem);
  4117. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4118. }
  4119. }
  4120. exports.BaseTreeViewer = BaseTreeViewer;
  4121. /***/ }),
  4122. /* 13 */
  4123. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4124. Object.defineProperty(exports, "__esModule", ({
  4125. value: true
  4126. }));
  4127. exports.PDFDocumentProperties = void 0;
  4128. var _pdfjsLib = __webpack_require__(5);
  4129. var _ui_utils = __webpack_require__(3);
  4130. const DEFAULT_FIELD_CONTENT = "-";
  4131. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4132. const US_PAGE_NAMES = {
  4133. "8.5x11": "Letter",
  4134. "8.5x14": "Legal"
  4135. };
  4136. const METRIC_PAGE_NAMES = {
  4137. "297x420": "A3",
  4138. "210x297": "A4"
  4139. };
  4140. function getPageName(size, isPortrait, pageNames) {
  4141. const width = isPortrait ? size.width : size.height;
  4142. const height = isPortrait ? size.height : size.width;
  4143. return pageNames[`${width}x${height}`];
  4144. }
  4145. class PDFDocumentProperties {
  4146. constructor({
  4147. overlayName,
  4148. fields,
  4149. container,
  4150. closeButton
  4151. }, overlayManager, eventBus, l10n) {
  4152. this.overlayName = overlayName;
  4153. this.fields = fields;
  4154. this.container = container;
  4155. this.overlayManager = overlayManager;
  4156. this.l10n = l10n;
  4157. this._reset();
  4158. closeButton.addEventListener("click", this.close.bind(this));
  4159. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  4160. eventBus._on("pagechanging", evt => {
  4161. this._currentPageNumber = evt.pageNumber;
  4162. });
  4163. eventBus._on("rotationchanging", evt => {
  4164. this._pagesRotation = evt.pagesRotation;
  4165. });
  4166. this._isNonMetricLocale = true;
  4167. l10n.getLanguage().then(locale => {
  4168. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4169. });
  4170. }
  4171. async open() {
  4172. const freezeFieldData = data => {
  4173. Object.defineProperty(this, "fieldData", {
  4174. value: Object.freeze(data),
  4175. writable: false,
  4176. enumerable: true,
  4177. configurable: true
  4178. });
  4179. };
  4180. await Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]);
  4181. const currentPageNumber = this._currentPageNumber;
  4182. const pagesRotation = this._pagesRotation;
  4183. if (this.fieldData && currentPageNumber === this.fieldData._currentPageNumber && pagesRotation === this.fieldData._pagesRotation) {
  4184. this._updateUI();
  4185. return;
  4186. }
  4187. const {
  4188. info,
  4189. contentDispositionFilename,
  4190. contentLength
  4191. } = await this.pdfDocument.getMetadata();
  4192. 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 => {
  4193. return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4194. }), this._parseLinearization(info.IsLinearized)]);
  4195. freezeFieldData({
  4196. fileName,
  4197. fileSize,
  4198. title: info.Title,
  4199. author: info.Author,
  4200. subject: info.Subject,
  4201. keywords: info.Keywords,
  4202. creationDate,
  4203. modificationDate,
  4204. creator: info.Creator,
  4205. producer: info.Producer,
  4206. version: info.PDFFormatVersion,
  4207. pageCount: this.pdfDocument.numPages,
  4208. pageSize,
  4209. linearized: isLinearized,
  4210. _currentPageNumber: currentPageNumber,
  4211. _pagesRotation: pagesRotation
  4212. });
  4213. this._updateUI();
  4214. const {
  4215. length
  4216. } = await this.pdfDocument.getDownloadInfo();
  4217. if (contentLength === length) {
  4218. return;
  4219. }
  4220. const data = Object.assign(Object.create(null), this.fieldData);
  4221. data.fileSize = await this._parseFileSize(length);
  4222. freezeFieldData(data);
  4223. this._updateUI();
  4224. }
  4225. close() {
  4226. this.overlayManager.close(this.overlayName);
  4227. }
  4228. setDocument(pdfDocument, url = null) {
  4229. if (this.pdfDocument) {
  4230. this._reset();
  4231. this._updateUI(true);
  4232. }
  4233. if (!pdfDocument) {
  4234. return;
  4235. }
  4236. this.pdfDocument = pdfDocument;
  4237. this.url = url;
  4238. this._dataAvailableCapability.resolve();
  4239. }
  4240. _reset() {
  4241. this.pdfDocument = null;
  4242. this.url = null;
  4243. delete this.fieldData;
  4244. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4245. this._currentPageNumber = 1;
  4246. this._pagesRotation = 0;
  4247. }
  4248. _updateUI(reset = false) {
  4249. if (reset || !this.fieldData) {
  4250. for (const id in this.fields) {
  4251. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4252. }
  4253. return;
  4254. }
  4255. if (this.overlayManager.active !== this.overlayName) {
  4256. return;
  4257. }
  4258. for (const id in this.fields) {
  4259. const content = this.fieldData[id];
  4260. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4261. }
  4262. }
  4263. async _parseFileSize(fileSize = 0) {
  4264. const kb = fileSize / 1024,
  4265. mb = kb / 1024;
  4266. if (!kb) {
  4267. return undefined;
  4268. }
  4269. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4270. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4271. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4272. size_b: fileSize.toLocaleString()
  4273. });
  4274. }
  4275. async _parsePageSize(pageSizeInches, pagesRotation) {
  4276. if (!pageSizeInches) {
  4277. return undefined;
  4278. }
  4279. if (pagesRotation % 180 !== 0) {
  4280. pageSizeInches = {
  4281. width: pageSizeInches.height,
  4282. height: pageSizeInches.width
  4283. };
  4284. }
  4285. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4286. let sizeInches = {
  4287. width: Math.round(pageSizeInches.width * 100) / 100,
  4288. height: Math.round(pageSizeInches.height * 100) / 100
  4289. };
  4290. let sizeMillimeters = {
  4291. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4292. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4293. };
  4294. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4295. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4296. const exactMillimeters = {
  4297. width: pageSizeInches.width * 25.4,
  4298. height: pageSizeInches.height * 25.4
  4299. };
  4300. const intMillimeters = {
  4301. width: Math.round(sizeMillimeters.width),
  4302. height: Math.round(sizeMillimeters.height)
  4303. };
  4304. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4305. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4306. if (rawName) {
  4307. sizeInches = {
  4308. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4309. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4310. };
  4311. sizeMillimeters = intMillimeters;
  4312. }
  4313. }
  4314. }
  4315. const [{
  4316. width,
  4317. height
  4318. }, 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"}`)]);
  4319. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4320. width: width.toLocaleString(),
  4321. height: height.toLocaleString(),
  4322. unit,
  4323. name,
  4324. orientation
  4325. });
  4326. }
  4327. async _parseDate(inputDate) {
  4328. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4329. if (!dateObject) {
  4330. return undefined;
  4331. }
  4332. return this.l10n.get("document_properties_date_string", {
  4333. date: dateObject.toLocaleDateString(),
  4334. time: dateObject.toLocaleTimeString()
  4335. });
  4336. }
  4337. _parseLinearization(isLinearized) {
  4338. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4339. }
  4340. }
  4341. exports.PDFDocumentProperties = PDFDocumentProperties;
  4342. /***/ }),
  4343. /* 14 */
  4344. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4345. Object.defineProperty(exports, "__esModule", ({
  4346. value: true
  4347. }));
  4348. exports.PDFFindBar = void 0;
  4349. var _pdf_find_controller = __webpack_require__(15);
  4350. const MATCHES_COUNT_LIMIT = 1000;
  4351. class PDFFindBar {
  4352. constructor(options, eventBus, l10n) {
  4353. this.opened = false;
  4354. this.bar = options.bar;
  4355. this.toggleButton = options.toggleButton;
  4356. this.findField = options.findField;
  4357. this.highlightAll = options.highlightAllCheckbox;
  4358. this.caseSensitive = options.caseSensitiveCheckbox;
  4359. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4360. this.entireWord = options.entireWordCheckbox;
  4361. this.findMsg = options.findMsg;
  4362. this.findResultsCount = options.findResultsCount;
  4363. this.findPreviousButton = options.findPreviousButton;
  4364. this.findNextButton = options.findNextButton;
  4365. this.eventBus = eventBus;
  4366. this.l10n = l10n;
  4367. this.toggleButton.addEventListener("click", () => {
  4368. this.toggle();
  4369. });
  4370. this.findField.addEventListener("input", () => {
  4371. this.dispatchEvent("");
  4372. });
  4373. this.bar.addEventListener("keydown", e => {
  4374. switch (e.keyCode) {
  4375. case 13:
  4376. if (e.target === this.findField) {
  4377. this.dispatchEvent("again", e.shiftKey);
  4378. }
  4379. break;
  4380. case 27:
  4381. this.close();
  4382. break;
  4383. }
  4384. });
  4385. this.findPreviousButton.addEventListener("click", () => {
  4386. this.dispatchEvent("again", true);
  4387. });
  4388. this.findNextButton.addEventListener("click", () => {
  4389. this.dispatchEvent("again", false);
  4390. });
  4391. this.highlightAll.addEventListener("click", () => {
  4392. this.dispatchEvent("highlightallchange");
  4393. });
  4394. this.caseSensitive.addEventListener("click", () => {
  4395. this.dispatchEvent("casesensitivitychange");
  4396. });
  4397. this.entireWord.addEventListener("click", () => {
  4398. this.dispatchEvent("entirewordchange");
  4399. });
  4400. this.matchDiacritics.addEventListener("click", () => {
  4401. this.dispatchEvent("diacriticmatchingchange");
  4402. });
  4403. this.eventBus._on("resize", this._adjustWidth.bind(this));
  4404. }
  4405. reset() {
  4406. this.updateUIState();
  4407. }
  4408. dispatchEvent(type, findPrev = false) {
  4409. this.eventBus.dispatch("find", {
  4410. source: this,
  4411. type,
  4412. query: this.findField.value,
  4413. phraseSearch: true,
  4414. caseSensitive: this.caseSensitive.checked,
  4415. entireWord: this.entireWord.checked,
  4416. highlightAll: this.highlightAll.checked,
  4417. findPrevious: findPrev,
  4418. matchDiacritics: this.matchDiacritics.checked
  4419. });
  4420. }
  4421. updateUIState(state, previous, matchesCount) {
  4422. let findMsg = Promise.resolve("");
  4423. let status = "";
  4424. switch (state) {
  4425. case _pdf_find_controller.FindState.FOUND:
  4426. break;
  4427. case _pdf_find_controller.FindState.PENDING:
  4428. status = "pending";
  4429. break;
  4430. case _pdf_find_controller.FindState.NOT_FOUND:
  4431. findMsg = this.l10n.get("find_not_found");
  4432. status = "notFound";
  4433. break;
  4434. case _pdf_find_controller.FindState.WRAPPED:
  4435. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4436. break;
  4437. }
  4438. this.findField.setAttribute("data-status", status);
  4439. findMsg.then(msg => {
  4440. this.findMsg.textContent = msg;
  4441. this._adjustWidth();
  4442. });
  4443. this.updateResultsCount(matchesCount);
  4444. }
  4445. updateResultsCount({
  4446. current = 0,
  4447. total = 0
  4448. } = {}) {
  4449. const limit = MATCHES_COUNT_LIMIT;
  4450. let matchCountMsg = Promise.resolve("");
  4451. if (total > 0) {
  4452. if (total > limit) {
  4453. let key = "find_match_count_limit";
  4454. matchCountMsg = this.l10n.get(key, {
  4455. limit
  4456. });
  4457. } else {
  4458. let key = "find_match_count";
  4459. matchCountMsg = this.l10n.get(key, {
  4460. current,
  4461. total
  4462. });
  4463. }
  4464. }
  4465. matchCountMsg.then(msg => {
  4466. this.findResultsCount.textContent = msg;
  4467. this._adjustWidth();
  4468. });
  4469. }
  4470. open() {
  4471. if (!this.opened) {
  4472. this.opened = true;
  4473. this.toggleButton.classList.add("toggled");
  4474. this.toggleButton.setAttribute("aria-expanded", "true");
  4475. this.bar.classList.remove("hidden");
  4476. }
  4477. this.findField.select();
  4478. this.findField.focus();
  4479. this._adjustWidth();
  4480. }
  4481. close() {
  4482. if (!this.opened) {
  4483. return;
  4484. }
  4485. this.opened = false;
  4486. this.toggleButton.classList.remove("toggled");
  4487. this.toggleButton.setAttribute("aria-expanded", "false");
  4488. this.bar.classList.add("hidden");
  4489. this.eventBus.dispatch("findbarclose", {
  4490. source: this
  4491. });
  4492. }
  4493. toggle() {
  4494. if (this.opened) {
  4495. this.close();
  4496. } else {
  4497. this.open();
  4498. }
  4499. }
  4500. _adjustWidth() {
  4501. if (!this.opened) {
  4502. return;
  4503. }
  4504. this.bar.classList.remove("wrapContainers");
  4505. const findbarHeight = this.bar.clientHeight;
  4506. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4507. if (findbarHeight > inputContainerHeight) {
  4508. this.bar.classList.add("wrapContainers");
  4509. }
  4510. }
  4511. }
  4512. exports.PDFFindBar = PDFFindBar;
  4513. /***/ }),
  4514. /* 15 */
  4515. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4516. Object.defineProperty(exports, "__esModule", ({
  4517. value: true
  4518. }));
  4519. exports.PDFFindController = exports.FindState = void 0;
  4520. var _ui_utils = __webpack_require__(3);
  4521. var _pdfjsLib = __webpack_require__(5);
  4522. var _pdf_find_utils = __webpack_require__(16);
  4523. const FindState = {
  4524. FOUND: 0,
  4525. NOT_FOUND: 1,
  4526. WRAPPED: 2,
  4527. PENDING: 3
  4528. };
  4529. exports.FindState = FindState;
  4530. const FIND_TIMEOUT = 250;
  4531. const MATCH_SCROLL_OFFSET_TOP = -50;
  4532. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4533. const CHARACTERS_TO_NORMALIZE = {
  4534. "\u2010": "-",
  4535. "\u2018": "'",
  4536. "\u2019": "'",
  4537. "\u201A": "'",
  4538. "\u201B": "'",
  4539. "\u201C": '"',
  4540. "\u201D": '"',
  4541. "\u201E": '"',
  4542. "\u201F": '"',
  4543. "\u00BC": "1/4",
  4544. "\u00BD": "1/2",
  4545. "\u00BE": "3/4"
  4546. };
  4547. const DIACRITICS_EXCEPTION = new Set([0x3099, 0x309a, 0x094d, 0x09cd, 0x0a4d, 0x0acd, 0x0b4d, 0x0bcd, 0x0c4d, 0x0ccd, 0x0d3b, 0x0d3c, 0x0d4d, 0x0dca, 0x0e3a, 0x0eba, 0x0f84, 0x1039, 0x103a, 0x1714, 0x1734, 0x17d2, 0x1a60, 0x1b44, 0x1baa, 0x1bab, 0x1bf2, 0x1bf3, 0x2d7f, 0xa806, 0xa82c, 0xa8c4, 0xa953, 0xa9c0, 0xaaf6, 0xabed, 0x0c56, 0x0f71, 0x0f72, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f80, 0x0f74]);
  4548. const DIACRITICS_EXCEPTION_STR = [...DIACRITICS_EXCEPTION.values()].map(x => String.fromCharCode(x)).join("");
  4549. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4550. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4551. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4552. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4553. let normalizationRegex = null;
  4554. function normalize(text) {
  4555. if (!normalizationRegex) {
  4556. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4557. normalizationRegex = new RegExp(`([${replace}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(\\n)`, "gum");
  4558. }
  4559. const rawDiacriticsPositions = [];
  4560. let m;
  4561. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4562. rawDiacriticsPositions.push([m[0].length, m.index]);
  4563. }
  4564. let normalized = text.normalize("NFD");
  4565. const positions = [[0, 0]];
  4566. let k = 0;
  4567. let shift = 0;
  4568. let shiftOrigin = 0;
  4569. let eol = 0;
  4570. let hasDiacritics = false;
  4571. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, i) => {
  4572. i -= shiftOrigin;
  4573. if (p1) {
  4574. const replacement = CHARACTERS_TO_NORMALIZE[match];
  4575. const jj = replacement.length;
  4576. for (let j = 1; j < jj; j++) {
  4577. positions.push([i - shift + j, shift - j]);
  4578. }
  4579. shift -= jj - 1;
  4580. return replacement;
  4581. }
  4582. if (p2) {
  4583. const hasTrailingDashEOL = p2.endsWith("\n");
  4584. const len = hasTrailingDashEOL ? p2.length - 2 : p2.length;
  4585. hasDiacritics = true;
  4586. let jj = len;
  4587. if (i + eol === rawDiacriticsPositions[k]?.[1]) {
  4588. jj -= rawDiacriticsPositions[k][0];
  4589. ++k;
  4590. }
  4591. for (let j = 1; j < jj + 1; j++) {
  4592. positions.push([i - 1 - shift + j, shift - j]);
  4593. }
  4594. shift -= jj;
  4595. shiftOrigin += jj;
  4596. if (hasTrailingDashEOL) {
  4597. i += len - 1;
  4598. positions.push([i - shift + 1, 1 + shift]);
  4599. shift += 1;
  4600. shiftOrigin += 1;
  4601. eol += 1;
  4602. return p2.slice(0, len);
  4603. }
  4604. return p2;
  4605. }
  4606. if (p3) {
  4607. positions.push([i - shift + 1, 1 + shift]);
  4608. shift += 1;
  4609. shiftOrigin += 1;
  4610. eol += 1;
  4611. return p3.charAt(0);
  4612. }
  4613. positions.push([i - shift + 1, shift - 1]);
  4614. shift -= 1;
  4615. shiftOrigin += 1;
  4616. eol += 1;
  4617. return " ";
  4618. });
  4619. positions.push([normalized.length, shift]);
  4620. return [normalized, positions, hasDiacritics];
  4621. }
  4622. function getOriginalIndex(diffs, pos, len) {
  4623. if (!diffs) {
  4624. return [pos, len];
  4625. }
  4626. const start = pos;
  4627. const end = pos + len;
  4628. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  4629. if (diffs[i][0] > start) {
  4630. --i;
  4631. }
  4632. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  4633. if (diffs[j][0] > end) {
  4634. --j;
  4635. }
  4636. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  4637. }
  4638. class PDFFindController {
  4639. constructor({
  4640. linkService,
  4641. eventBus
  4642. }) {
  4643. this._linkService = linkService;
  4644. this._eventBus = eventBus;
  4645. this._reset();
  4646. eventBus._on("find", this._onFind.bind(this));
  4647. eventBus._on("findbarclose", this._onFindBarClose.bind(this));
  4648. this.executeCommand = (cmd, state) => {
  4649. console.error("Deprecated method `PDFFindController.executeCommand` called, " + 'please dispatch a "find"-event using the EventBus instead.');
  4650. const eventState = Object.assign(Object.create(null), state, {
  4651. type: cmd.substring("find".length)
  4652. });
  4653. this._onFind(eventState);
  4654. };
  4655. }
  4656. get highlightMatches() {
  4657. return this._highlightMatches;
  4658. }
  4659. get pageMatches() {
  4660. return this._pageMatches;
  4661. }
  4662. get pageMatchesLength() {
  4663. return this._pageMatchesLength;
  4664. }
  4665. get selected() {
  4666. return this._selected;
  4667. }
  4668. get state() {
  4669. return this._state;
  4670. }
  4671. setDocument(pdfDocument) {
  4672. if (this._pdfDocument) {
  4673. this._reset();
  4674. }
  4675. if (!pdfDocument) {
  4676. return;
  4677. }
  4678. this._pdfDocument = pdfDocument;
  4679. this._firstPageCapability.resolve();
  4680. }
  4681. _onFind(state) {
  4682. if (!state) {
  4683. return;
  4684. }
  4685. const pdfDocument = this._pdfDocument;
  4686. const {
  4687. type
  4688. } = state;
  4689. if (this._state === null || this._shouldDirtyMatch(state)) {
  4690. this._dirtyMatch = true;
  4691. }
  4692. this._state = state;
  4693. if (type !== "highlightallchange") {
  4694. this._updateUIState(FindState.PENDING);
  4695. }
  4696. this._firstPageCapability.promise.then(() => {
  4697. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4698. return;
  4699. }
  4700. this._extractText();
  4701. const findbarClosed = !this._highlightMatches;
  4702. const pendingTimeout = !!this._findTimeout;
  4703. if (this._findTimeout) {
  4704. clearTimeout(this._findTimeout);
  4705. this._findTimeout = null;
  4706. }
  4707. if (!type) {
  4708. this._findTimeout = setTimeout(() => {
  4709. this._nextMatch();
  4710. this._findTimeout = null;
  4711. }, FIND_TIMEOUT);
  4712. } else if (this._dirtyMatch) {
  4713. this._nextMatch();
  4714. } else if (type === "again") {
  4715. this._nextMatch();
  4716. if (findbarClosed && this._state.highlightAll) {
  4717. this._updateAllPages();
  4718. }
  4719. } else if (type === "highlightallchange") {
  4720. if (pendingTimeout) {
  4721. this._nextMatch();
  4722. } else {
  4723. this._highlightMatches = true;
  4724. }
  4725. this._updateAllPages();
  4726. } else {
  4727. this._nextMatch();
  4728. }
  4729. });
  4730. }
  4731. scrollMatchIntoView({
  4732. element = null,
  4733. selectedLeft = 0,
  4734. pageIndex = -1,
  4735. matchIndex = -1
  4736. }) {
  4737. if (!this._scrollMatches || !element) {
  4738. return;
  4739. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4740. return;
  4741. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4742. return;
  4743. }
  4744. this._scrollMatches = false;
  4745. const spot = {
  4746. top: MATCH_SCROLL_OFFSET_TOP,
  4747. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  4748. };
  4749. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4750. }
  4751. _reset() {
  4752. this._highlightMatches = false;
  4753. this._scrollMatches = false;
  4754. this._pdfDocument = null;
  4755. this._pageMatches = [];
  4756. this._pageMatchesLength = [];
  4757. this._state = null;
  4758. this._selected = {
  4759. pageIdx: -1,
  4760. matchIdx: -1
  4761. };
  4762. this._offset = {
  4763. pageIdx: null,
  4764. matchIdx: null,
  4765. wrapped: false
  4766. };
  4767. this._extractTextPromises = [];
  4768. this._pageContents = [];
  4769. this._pageDiffs = [];
  4770. this._hasDiacritics = [];
  4771. this._matchesCountTotal = 0;
  4772. this._pagesToSearch = null;
  4773. this._pendingFindMatches = new Set();
  4774. this._resumePageIdx = null;
  4775. this._dirtyMatch = false;
  4776. clearTimeout(this._findTimeout);
  4777. this._findTimeout = null;
  4778. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4779. }
  4780. get _query() {
  4781. if (this._state.query !== this._rawQuery) {
  4782. this._rawQuery = this._state.query;
  4783. [this._normalizedQuery] = normalize(this._state.query);
  4784. }
  4785. return this._normalizedQuery;
  4786. }
  4787. _shouldDirtyMatch(state) {
  4788. if (state.query !== this._state.query) {
  4789. return true;
  4790. }
  4791. switch (state.type) {
  4792. case "again":
  4793. const pageNumber = this._selected.pageIdx + 1;
  4794. const linkService = this._linkService;
  4795. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4796. return true;
  4797. }
  4798. return false;
  4799. case "highlightallchange":
  4800. return false;
  4801. }
  4802. return true;
  4803. }
  4804. _isEntireWord(content, startIdx, length) {
  4805. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  4806. if (match) {
  4807. const first = content.charCodeAt(startIdx);
  4808. const limit = match[1].charCodeAt(0);
  4809. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4810. return false;
  4811. }
  4812. }
  4813. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  4814. if (match) {
  4815. const last = content.charCodeAt(startIdx + length - 1);
  4816. const limit = match[1].charCodeAt(0);
  4817. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4818. return false;
  4819. }
  4820. }
  4821. return true;
  4822. }
  4823. _calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  4824. const matches = [],
  4825. matchesLength = [];
  4826. const diffs = this._pageDiffs[pageIndex];
  4827. let match;
  4828. while ((match = query.exec(pageContent)) !== null) {
  4829. if (entireWord && !this._isEntireWord(pageContent, match.index, match[0].length)) {
  4830. continue;
  4831. }
  4832. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  4833. if (matchLen) {
  4834. matches.push(matchPos);
  4835. matchesLength.push(matchLen);
  4836. }
  4837. }
  4838. this._pageMatches[pageIndex] = matches;
  4839. this._pageMatchesLength[pageIndex] = matchesLength;
  4840. }
  4841. _convertToRegExpString(query, hasDiacritics) {
  4842. const {
  4843. matchDiacritics
  4844. } = this._state;
  4845. let isUnicode = false;
  4846. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  4847. if (p1) {
  4848. return `[ ]*\\${p1}[ ]*`;
  4849. }
  4850. if (p2) {
  4851. return `[ ]*${p2}[ ]*`;
  4852. }
  4853. if (p3) {
  4854. return "[ ]+";
  4855. }
  4856. if (matchDiacritics) {
  4857. return p4 || p5;
  4858. }
  4859. if (p4) {
  4860. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  4861. }
  4862. if (hasDiacritics) {
  4863. isUnicode = true;
  4864. return `${p5}\\p{M}*`;
  4865. }
  4866. return p5;
  4867. });
  4868. const trailingSpaces = "[ ]*";
  4869. if (query.endsWith(trailingSpaces)) {
  4870. query = query.slice(0, query.length - trailingSpaces.length);
  4871. }
  4872. if (matchDiacritics) {
  4873. if (hasDiacritics) {
  4874. isUnicode = true;
  4875. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  4876. }
  4877. }
  4878. return [isUnicode, query];
  4879. }
  4880. _calculateMatch(pageIndex) {
  4881. let query = this._query;
  4882. if (query.length === 0) {
  4883. return;
  4884. }
  4885. const {
  4886. caseSensitive,
  4887. entireWord,
  4888. phraseSearch
  4889. } = this._state;
  4890. const pageContent = this._pageContents[pageIndex];
  4891. const hasDiacritics = this._hasDiacritics[pageIndex];
  4892. let isUnicode = false;
  4893. if (phraseSearch) {
  4894. [isUnicode, query] = this._convertToRegExpString(query, hasDiacritics);
  4895. } else {
  4896. const match = query.match(/\S+/g);
  4897. if (match) {
  4898. query = match.sort().reverse().map(q => {
  4899. const [isUnicodePart, queryPart] = this._convertToRegExpString(q, hasDiacritics);
  4900. isUnicode ||= isUnicodePart;
  4901. return `(${queryPart})`;
  4902. }).join("|");
  4903. }
  4904. }
  4905. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  4906. query = new RegExp(query, flags);
  4907. this._calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  4908. if (this._state.highlightAll) {
  4909. this._updatePage(pageIndex);
  4910. }
  4911. if (this._resumePageIdx === pageIndex) {
  4912. this._resumePageIdx = null;
  4913. this._nextPageMatch();
  4914. }
  4915. const pageMatchesCount = this._pageMatches[pageIndex].length;
  4916. if (pageMatchesCount > 0) {
  4917. this._matchesCountTotal += pageMatchesCount;
  4918. this._updateUIResultsCount();
  4919. }
  4920. }
  4921. _extractText() {
  4922. if (this._extractTextPromises.length > 0) {
  4923. return;
  4924. }
  4925. let promise = Promise.resolve();
  4926. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  4927. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  4928. this._extractTextPromises[i] = extractTextCapability.promise;
  4929. promise = promise.then(() => {
  4930. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  4931. return pdfPage.getTextContent();
  4932. }).then(textContent => {
  4933. const textItems = textContent.items;
  4934. const strBuf = [];
  4935. for (let j = 0, jj = textItems.length; j < jj; j++) {
  4936. strBuf.push(textItems[j].str);
  4937. if (textItems[j].hasEOL) {
  4938. strBuf.push("\n");
  4939. }
  4940. }
  4941. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  4942. extractTextCapability.resolve(i);
  4943. }, reason => {
  4944. console.error(`Unable to get text content for page ${i + 1}`, reason);
  4945. this._pageContents[i] = "";
  4946. this._pageDiffs[i] = null;
  4947. this._hasDiacritics[i] = false;
  4948. extractTextCapability.resolve(i);
  4949. });
  4950. });
  4951. }
  4952. }
  4953. _updatePage(index) {
  4954. if (this._scrollMatches && this._selected.pageIdx === index) {
  4955. this._linkService.page = index + 1;
  4956. }
  4957. this._eventBus.dispatch("updatetextlayermatches", {
  4958. source: this,
  4959. pageIndex: index
  4960. });
  4961. }
  4962. _updateAllPages() {
  4963. this._eventBus.dispatch("updatetextlayermatches", {
  4964. source: this,
  4965. pageIndex: -1
  4966. });
  4967. }
  4968. _nextMatch() {
  4969. const previous = this._state.findPrevious;
  4970. const currentPageIndex = this._linkService.page - 1;
  4971. const numPages = this._linkService.pagesCount;
  4972. this._highlightMatches = true;
  4973. if (this._dirtyMatch) {
  4974. this._dirtyMatch = false;
  4975. this._selected.pageIdx = this._selected.matchIdx = -1;
  4976. this._offset.pageIdx = currentPageIndex;
  4977. this._offset.matchIdx = null;
  4978. this._offset.wrapped = false;
  4979. this._resumePageIdx = null;
  4980. this._pageMatches.length = 0;
  4981. this._pageMatchesLength.length = 0;
  4982. this._matchesCountTotal = 0;
  4983. this._updateAllPages();
  4984. for (let i = 0; i < numPages; i++) {
  4985. if (this._pendingFindMatches.has(i)) {
  4986. continue;
  4987. }
  4988. this._pendingFindMatches.add(i);
  4989. this._extractTextPromises[i].then(pageIdx => {
  4990. this._pendingFindMatches.delete(pageIdx);
  4991. this._calculateMatch(pageIdx);
  4992. });
  4993. }
  4994. }
  4995. if (this._query === "") {
  4996. this._updateUIState(FindState.FOUND);
  4997. return;
  4998. }
  4999. if (this._resumePageIdx) {
  5000. return;
  5001. }
  5002. const offset = this._offset;
  5003. this._pagesToSearch = numPages;
  5004. if (offset.matchIdx !== null) {
  5005. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5006. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5007. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5008. this._updateMatch(true);
  5009. return;
  5010. }
  5011. this._advanceOffsetPage(previous);
  5012. }
  5013. this._nextPageMatch();
  5014. }
  5015. _matchesReady(matches) {
  5016. const offset = this._offset;
  5017. const numMatches = matches.length;
  5018. const previous = this._state.findPrevious;
  5019. if (numMatches) {
  5020. offset.matchIdx = previous ? numMatches - 1 : 0;
  5021. this._updateMatch(true);
  5022. return true;
  5023. }
  5024. this._advanceOffsetPage(previous);
  5025. if (offset.wrapped) {
  5026. offset.matchIdx = null;
  5027. if (this._pagesToSearch < 0) {
  5028. this._updateMatch(false);
  5029. return true;
  5030. }
  5031. }
  5032. return false;
  5033. }
  5034. _nextPageMatch() {
  5035. if (this._resumePageIdx !== null) {
  5036. console.error("There can only be one pending page.");
  5037. }
  5038. let matches = null;
  5039. do {
  5040. const pageIdx = this._offset.pageIdx;
  5041. matches = this._pageMatches[pageIdx];
  5042. if (!matches) {
  5043. this._resumePageIdx = pageIdx;
  5044. break;
  5045. }
  5046. } while (!this._matchesReady(matches));
  5047. }
  5048. _advanceOffsetPage(previous) {
  5049. const offset = this._offset;
  5050. const numPages = this._linkService.pagesCount;
  5051. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5052. offset.matchIdx = null;
  5053. this._pagesToSearch--;
  5054. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5055. offset.pageIdx = previous ? numPages - 1 : 0;
  5056. offset.wrapped = true;
  5057. }
  5058. }
  5059. _updateMatch(found = false) {
  5060. let state = FindState.NOT_FOUND;
  5061. const wrapped = this._offset.wrapped;
  5062. this._offset.wrapped = false;
  5063. if (found) {
  5064. const previousPage = this._selected.pageIdx;
  5065. this._selected.pageIdx = this._offset.pageIdx;
  5066. this._selected.matchIdx = this._offset.matchIdx;
  5067. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5068. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5069. this._updatePage(previousPage);
  5070. }
  5071. }
  5072. this._updateUIState(state, this._state.findPrevious);
  5073. if (this._selected.pageIdx !== -1) {
  5074. this._scrollMatches = true;
  5075. this._updatePage(this._selected.pageIdx);
  5076. }
  5077. }
  5078. _onFindBarClose(evt) {
  5079. const pdfDocument = this._pdfDocument;
  5080. this._firstPageCapability.promise.then(() => {
  5081. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5082. return;
  5083. }
  5084. if (this._findTimeout) {
  5085. clearTimeout(this._findTimeout);
  5086. this._findTimeout = null;
  5087. }
  5088. if (this._resumePageIdx) {
  5089. this._resumePageIdx = null;
  5090. this._dirtyMatch = true;
  5091. }
  5092. this._updateUIState(FindState.FOUND);
  5093. this._highlightMatches = false;
  5094. this._updateAllPages();
  5095. });
  5096. }
  5097. _requestMatchesCount() {
  5098. const {
  5099. pageIdx,
  5100. matchIdx
  5101. } = this._selected;
  5102. let current = 0,
  5103. total = this._matchesCountTotal;
  5104. if (matchIdx !== -1) {
  5105. for (let i = 0; i < pageIdx; i++) {
  5106. current += this._pageMatches[i]?.length || 0;
  5107. }
  5108. current += matchIdx + 1;
  5109. }
  5110. if (current < 1 || current > total) {
  5111. current = total = 0;
  5112. }
  5113. return {
  5114. current,
  5115. total
  5116. };
  5117. }
  5118. _updateUIResultsCount() {
  5119. this._eventBus.dispatch("updatefindmatchescount", {
  5120. source: this,
  5121. matchesCount: this._requestMatchesCount()
  5122. });
  5123. }
  5124. _updateUIState(state, previous = false) {
  5125. this._eventBus.dispatch("updatefindcontrolstate", {
  5126. source: this,
  5127. state,
  5128. previous,
  5129. matchesCount: this._requestMatchesCount(),
  5130. rawQuery: this._state?.query ?? null
  5131. });
  5132. }
  5133. }
  5134. exports.PDFFindController = PDFFindController;
  5135. /***/ }),
  5136. /* 16 */
  5137. /***/ ((__unused_webpack_module, exports) => {
  5138. Object.defineProperty(exports, "__esModule", ({
  5139. value: true
  5140. }));
  5141. exports.CharacterType = void 0;
  5142. exports.getCharacterType = getCharacterType;
  5143. const CharacterType = {
  5144. SPACE: 0,
  5145. ALPHA_LETTER: 1,
  5146. PUNCT: 2,
  5147. HAN_LETTER: 3,
  5148. KATAKANA_LETTER: 4,
  5149. HIRAGANA_LETTER: 5,
  5150. HALFWIDTH_KATAKANA_LETTER: 6,
  5151. THAI_LETTER: 7
  5152. };
  5153. exports.CharacterType = CharacterType;
  5154. function isAlphabeticalScript(charCode) {
  5155. return charCode < 0x2e80;
  5156. }
  5157. function isAscii(charCode) {
  5158. return (charCode & 0xff80) === 0;
  5159. }
  5160. function isAsciiAlpha(charCode) {
  5161. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5162. }
  5163. function isAsciiDigit(charCode) {
  5164. return charCode >= 0x30 && charCode <= 0x39;
  5165. }
  5166. function isAsciiSpace(charCode) {
  5167. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5168. }
  5169. function isHan(charCode) {
  5170. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5171. }
  5172. function isKatakana(charCode) {
  5173. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5174. }
  5175. function isHiragana(charCode) {
  5176. return charCode >= 0x3040 && charCode <= 0x309f;
  5177. }
  5178. function isHalfwidthKatakana(charCode) {
  5179. return charCode >= 0xff60 && charCode <= 0xff9f;
  5180. }
  5181. function isThai(charCode) {
  5182. return (charCode & 0xff80) === 0x0e00;
  5183. }
  5184. function getCharacterType(charCode) {
  5185. if (isAlphabeticalScript(charCode)) {
  5186. if (isAscii(charCode)) {
  5187. if (isAsciiSpace(charCode)) {
  5188. return CharacterType.SPACE;
  5189. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5190. return CharacterType.ALPHA_LETTER;
  5191. }
  5192. return CharacterType.PUNCT;
  5193. } else if (isThai(charCode)) {
  5194. return CharacterType.THAI_LETTER;
  5195. } else if (charCode === 0xa0) {
  5196. return CharacterType.SPACE;
  5197. }
  5198. return CharacterType.ALPHA_LETTER;
  5199. }
  5200. if (isHan(charCode)) {
  5201. return CharacterType.HAN_LETTER;
  5202. } else if (isKatakana(charCode)) {
  5203. return CharacterType.KATAKANA_LETTER;
  5204. } else if (isHiragana(charCode)) {
  5205. return CharacterType.HIRAGANA_LETTER;
  5206. } else if (isHalfwidthKatakana(charCode)) {
  5207. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5208. }
  5209. return CharacterType.ALPHA_LETTER;
  5210. }
  5211. /***/ }),
  5212. /* 17 */
  5213. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5214. Object.defineProperty(exports, "__esModule", ({
  5215. value: true
  5216. }));
  5217. exports.PDFHistory = void 0;
  5218. exports.isDestArraysEqual = isDestArraysEqual;
  5219. exports.isDestHashesEqual = isDestHashesEqual;
  5220. var _ui_utils = __webpack_require__(3);
  5221. var _event_utils = __webpack_require__(4);
  5222. const HASH_CHANGE_TIMEOUT = 1000;
  5223. const POSITION_UPDATED_THRESHOLD = 50;
  5224. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5225. function getCurrentHash() {
  5226. return document.location.hash;
  5227. }
  5228. class PDFHistory {
  5229. constructor({
  5230. linkService,
  5231. eventBus
  5232. }) {
  5233. this.linkService = linkService;
  5234. this.eventBus = eventBus;
  5235. this._initialized = false;
  5236. this._fingerprint = "";
  5237. this.reset();
  5238. this._boundEvents = null;
  5239. this._isViewerInPresentationMode = false;
  5240. this.eventBus._on("presentationmodechanged", evt => {
  5241. this._isViewerInPresentationMode = evt.state !== _ui_utils.PresentationModeState.NORMAL;
  5242. });
  5243. this.eventBus._on("pagesinit", () => {
  5244. this._isPagesLoaded = false;
  5245. this.eventBus._on("pagesloaded", evt => {
  5246. this._isPagesLoaded = !!evt.pagesCount;
  5247. }, {
  5248. once: true
  5249. });
  5250. });
  5251. }
  5252. initialize({
  5253. fingerprint,
  5254. resetHistory = false,
  5255. updateUrl = false
  5256. }) {
  5257. if (!fingerprint || typeof fingerprint !== "string") {
  5258. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5259. return;
  5260. }
  5261. if (this._initialized) {
  5262. this.reset();
  5263. }
  5264. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5265. this._fingerprint = fingerprint;
  5266. this._updateUrl = updateUrl === true;
  5267. this._initialized = true;
  5268. this._bindEvents();
  5269. const state = window.history.state;
  5270. this._popStateInProgress = false;
  5271. this._blockHashChange = 0;
  5272. this._currentHash = getCurrentHash();
  5273. this._numPositionUpdates = 0;
  5274. this._uid = this._maxUid = 0;
  5275. this._destination = null;
  5276. this._position = null;
  5277. if (!this._isValidState(state, true) || resetHistory) {
  5278. const {
  5279. hash,
  5280. page,
  5281. rotation
  5282. } = this._parseCurrentHash(true);
  5283. if (!hash || reInitialized || resetHistory) {
  5284. this._pushOrReplaceState(null, true);
  5285. return;
  5286. }
  5287. this._pushOrReplaceState({
  5288. hash,
  5289. page,
  5290. rotation
  5291. }, true);
  5292. return;
  5293. }
  5294. const destination = state.destination;
  5295. this._updateInternalState(destination, state.uid, true);
  5296. if (destination.rotation !== undefined) {
  5297. this._initialRotation = destination.rotation;
  5298. }
  5299. if (destination.dest) {
  5300. this._initialBookmark = JSON.stringify(destination.dest);
  5301. this._destination.page = null;
  5302. } else if (destination.hash) {
  5303. this._initialBookmark = destination.hash;
  5304. } else if (destination.page) {
  5305. this._initialBookmark = `page=${destination.page}`;
  5306. }
  5307. }
  5308. reset() {
  5309. if (this._initialized) {
  5310. this._pageHide();
  5311. this._initialized = false;
  5312. this._unbindEvents();
  5313. }
  5314. if (this._updateViewareaTimeout) {
  5315. clearTimeout(this._updateViewareaTimeout);
  5316. this._updateViewareaTimeout = null;
  5317. }
  5318. this._initialBookmark = null;
  5319. this._initialRotation = null;
  5320. }
  5321. push({
  5322. namedDest = null,
  5323. explicitDest,
  5324. pageNumber
  5325. }) {
  5326. if (!this._initialized) {
  5327. return;
  5328. }
  5329. if (namedDest && typeof namedDest !== "string") {
  5330. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5331. return;
  5332. } else if (!Array.isArray(explicitDest)) {
  5333. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5334. return;
  5335. } else if (!this._isValidPage(pageNumber)) {
  5336. if (pageNumber !== null || this._destination) {
  5337. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5338. return;
  5339. }
  5340. }
  5341. const hash = namedDest || JSON.stringify(explicitDest);
  5342. if (!hash) {
  5343. return;
  5344. }
  5345. let forceReplace = false;
  5346. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5347. if (this._destination.page) {
  5348. return;
  5349. }
  5350. forceReplace = true;
  5351. }
  5352. if (this._popStateInProgress && !forceReplace) {
  5353. return;
  5354. }
  5355. this._pushOrReplaceState({
  5356. dest: explicitDest,
  5357. hash,
  5358. page: pageNumber,
  5359. rotation: this.linkService.rotation
  5360. }, forceReplace);
  5361. if (!this._popStateInProgress) {
  5362. this._popStateInProgress = true;
  5363. Promise.resolve().then(() => {
  5364. this._popStateInProgress = false;
  5365. });
  5366. }
  5367. }
  5368. pushPage(pageNumber) {
  5369. if (!this._initialized) {
  5370. return;
  5371. }
  5372. if (!this._isValidPage(pageNumber)) {
  5373. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5374. return;
  5375. }
  5376. if (this._destination?.page === pageNumber) {
  5377. return;
  5378. }
  5379. if (this._popStateInProgress) {
  5380. return;
  5381. }
  5382. this._pushOrReplaceState({
  5383. dest: null,
  5384. hash: `page=${pageNumber}`,
  5385. page: pageNumber,
  5386. rotation: this.linkService.rotation
  5387. });
  5388. if (!this._popStateInProgress) {
  5389. this._popStateInProgress = true;
  5390. Promise.resolve().then(() => {
  5391. this._popStateInProgress = false;
  5392. });
  5393. }
  5394. }
  5395. pushCurrentPosition() {
  5396. if (!this._initialized || this._popStateInProgress) {
  5397. return;
  5398. }
  5399. this._tryPushCurrentPosition();
  5400. }
  5401. back() {
  5402. if (!this._initialized || this._popStateInProgress) {
  5403. return;
  5404. }
  5405. const state = window.history.state;
  5406. if (this._isValidState(state) && state.uid > 0) {
  5407. window.history.back();
  5408. }
  5409. }
  5410. forward() {
  5411. if (!this._initialized || this._popStateInProgress) {
  5412. return;
  5413. }
  5414. const state = window.history.state;
  5415. if (this._isValidState(state) && state.uid < this._maxUid) {
  5416. window.history.forward();
  5417. }
  5418. }
  5419. get popStateInProgress() {
  5420. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5421. }
  5422. get initialBookmark() {
  5423. return this._initialized ? this._initialBookmark : null;
  5424. }
  5425. get initialRotation() {
  5426. return this._initialized ? this._initialRotation : null;
  5427. }
  5428. _pushOrReplaceState(destination, forceReplace = false) {
  5429. const shouldReplace = forceReplace || !this._destination;
  5430. const newState = {
  5431. fingerprint: this._fingerprint,
  5432. uid: shouldReplace ? this._uid : this._uid + 1,
  5433. destination
  5434. };
  5435. this._updateInternalState(destination, newState.uid);
  5436. let newUrl;
  5437. if (this._updateUrl && destination?.hash) {
  5438. const baseUrl = document.location.href.split("#")[0];
  5439. if (!baseUrl.startsWith("file://")) {
  5440. newUrl = `${baseUrl}#${destination.hash}`;
  5441. }
  5442. }
  5443. if (shouldReplace) {
  5444. window.history.replaceState(newState, "", newUrl);
  5445. } else {
  5446. window.history.pushState(newState, "", newUrl);
  5447. }
  5448. }
  5449. _tryPushCurrentPosition(temporary = false) {
  5450. if (!this._position) {
  5451. return;
  5452. }
  5453. let position = this._position;
  5454. if (temporary) {
  5455. position = Object.assign(Object.create(null), this._position);
  5456. position.temporary = true;
  5457. }
  5458. if (!this._destination) {
  5459. this._pushOrReplaceState(position);
  5460. return;
  5461. }
  5462. if (this._destination.temporary) {
  5463. this._pushOrReplaceState(position, true);
  5464. return;
  5465. }
  5466. if (this._destination.hash === position.hash) {
  5467. return;
  5468. }
  5469. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5470. return;
  5471. }
  5472. let forceReplace = false;
  5473. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5474. if (this._destination.dest !== undefined || !this._destination.first) {
  5475. return;
  5476. }
  5477. forceReplace = true;
  5478. }
  5479. this._pushOrReplaceState(position, forceReplace);
  5480. }
  5481. _isValidPage(val) {
  5482. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5483. }
  5484. _isValidState(state, checkReload = false) {
  5485. if (!state) {
  5486. return false;
  5487. }
  5488. if (state.fingerprint !== this._fingerprint) {
  5489. if (checkReload) {
  5490. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5491. return false;
  5492. }
  5493. const [perfEntry] = performance.getEntriesByType("navigation");
  5494. if (perfEntry?.type !== "reload") {
  5495. return false;
  5496. }
  5497. } else {
  5498. return false;
  5499. }
  5500. }
  5501. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5502. return false;
  5503. }
  5504. if (state.destination === null || typeof state.destination !== "object") {
  5505. return false;
  5506. }
  5507. return true;
  5508. }
  5509. _updateInternalState(destination, uid, removeTemporary = false) {
  5510. if (this._updateViewareaTimeout) {
  5511. clearTimeout(this._updateViewareaTimeout);
  5512. this._updateViewareaTimeout = null;
  5513. }
  5514. if (removeTemporary && destination?.temporary) {
  5515. delete destination.temporary;
  5516. }
  5517. this._destination = destination;
  5518. this._uid = uid;
  5519. this._maxUid = Math.max(this._maxUid, uid);
  5520. this._numPositionUpdates = 0;
  5521. }
  5522. _parseCurrentHash(checkNameddest = false) {
  5523. const hash = unescape(getCurrentHash()).substring(1);
  5524. const params = (0, _ui_utils.parseQueryString)(hash);
  5525. const nameddest = params.get("nameddest") || "";
  5526. let page = params.get("page") | 0;
  5527. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5528. page = null;
  5529. }
  5530. return {
  5531. hash,
  5532. page,
  5533. rotation: this.linkService.rotation
  5534. };
  5535. }
  5536. _updateViewarea({
  5537. location
  5538. }) {
  5539. if (this._updateViewareaTimeout) {
  5540. clearTimeout(this._updateViewareaTimeout);
  5541. this._updateViewareaTimeout = null;
  5542. }
  5543. this._position = {
  5544. hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
  5545. page: this.linkService.page,
  5546. first: location.pageNumber,
  5547. rotation: location.rotation
  5548. };
  5549. if (this._popStateInProgress) {
  5550. return;
  5551. }
  5552. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5553. this._numPositionUpdates++;
  5554. }
  5555. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5556. this._updateViewareaTimeout = setTimeout(() => {
  5557. if (!this._popStateInProgress) {
  5558. this._tryPushCurrentPosition(true);
  5559. }
  5560. this._updateViewareaTimeout = null;
  5561. }, UPDATE_VIEWAREA_TIMEOUT);
  5562. }
  5563. }
  5564. _popState({
  5565. state
  5566. }) {
  5567. const newHash = getCurrentHash(),
  5568. hashChanged = this._currentHash !== newHash;
  5569. this._currentHash = newHash;
  5570. if (!state) {
  5571. this._uid++;
  5572. const {
  5573. hash,
  5574. page,
  5575. rotation
  5576. } = this._parseCurrentHash();
  5577. this._pushOrReplaceState({
  5578. hash,
  5579. page,
  5580. rotation
  5581. }, true);
  5582. return;
  5583. }
  5584. if (!this._isValidState(state)) {
  5585. return;
  5586. }
  5587. this._popStateInProgress = true;
  5588. if (hashChanged) {
  5589. this._blockHashChange++;
  5590. (0, _event_utils.waitOnEventOrTimeout)({
  5591. target: window,
  5592. name: "hashchange",
  5593. delay: HASH_CHANGE_TIMEOUT
  5594. }).then(() => {
  5595. this._blockHashChange--;
  5596. });
  5597. }
  5598. const destination = state.destination;
  5599. this._updateInternalState(destination, state.uid, true);
  5600. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5601. this.linkService.rotation = destination.rotation;
  5602. }
  5603. if (destination.dest) {
  5604. this.linkService.goToDestination(destination.dest);
  5605. } else if (destination.hash) {
  5606. this.linkService.setHash(destination.hash);
  5607. } else if (destination.page) {
  5608. this.linkService.page = destination.page;
  5609. }
  5610. Promise.resolve().then(() => {
  5611. this._popStateInProgress = false;
  5612. });
  5613. }
  5614. _pageHide() {
  5615. if (!this._destination || this._destination.temporary) {
  5616. this._tryPushCurrentPosition();
  5617. }
  5618. }
  5619. _bindEvents() {
  5620. if (this._boundEvents) {
  5621. return;
  5622. }
  5623. this._boundEvents = {
  5624. updateViewarea: this._updateViewarea.bind(this),
  5625. popState: this._popState.bind(this),
  5626. pageHide: this._pageHide.bind(this)
  5627. };
  5628. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5629. window.addEventListener("popstate", this._boundEvents.popState);
  5630. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5631. }
  5632. _unbindEvents() {
  5633. if (!this._boundEvents) {
  5634. return;
  5635. }
  5636. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5637. window.removeEventListener("popstate", this._boundEvents.popState);
  5638. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5639. this._boundEvents = null;
  5640. }
  5641. }
  5642. exports.PDFHistory = PDFHistory;
  5643. function isDestHashesEqual(destHash, pushHash) {
  5644. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5645. return false;
  5646. }
  5647. if (destHash === pushHash) {
  5648. return true;
  5649. }
  5650. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  5651. if (nameddest === pushHash) {
  5652. return true;
  5653. }
  5654. return false;
  5655. }
  5656. function isDestArraysEqual(firstDest, secondDest) {
  5657. function isEntryEqual(first, second) {
  5658. if (typeof first !== typeof second) {
  5659. return false;
  5660. }
  5661. if (Array.isArray(first) || Array.isArray(second)) {
  5662. return false;
  5663. }
  5664. if (first !== null && typeof first === "object" && second !== null) {
  5665. if (Object.keys(first).length !== Object.keys(second).length) {
  5666. return false;
  5667. }
  5668. for (const key in first) {
  5669. if (!isEntryEqual(first[key], second[key])) {
  5670. return false;
  5671. }
  5672. }
  5673. return true;
  5674. }
  5675. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5676. }
  5677. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5678. return false;
  5679. }
  5680. if (firstDest.length !== secondDest.length) {
  5681. return false;
  5682. }
  5683. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5684. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5685. return false;
  5686. }
  5687. }
  5688. return true;
  5689. }
  5690. /***/ }),
  5691. /* 18 */
  5692. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5693. Object.defineProperty(exports, "__esModule", ({
  5694. value: true
  5695. }));
  5696. exports.PDFLayerViewer = void 0;
  5697. var _base_tree_viewer = __webpack_require__(12);
  5698. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5699. constructor(options) {
  5700. super(options);
  5701. this.l10n = options.l10n;
  5702. this.eventBus._on("resetlayers", this._resetLayers.bind(this));
  5703. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5704. }
  5705. reset() {
  5706. super.reset();
  5707. this._optionalContentConfig = null;
  5708. }
  5709. _dispatchEvent(layersCount) {
  5710. this.eventBus.dispatch("layersloaded", {
  5711. source: this,
  5712. layersCount
  5713. });
  5714. }
  5715. _bindLink(element, {
  5716. groupId,
  5717. input
  5718. }) {
  5719. const setVisibility = () => {
  5720. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5721. this.eventBus.dispatch("optionalcontentconfig", {
  5722. source: this,
  5723. promise: Promise.resolve(this._optionalContentConfig)
  5724. });
  5725. };
  5726. element.onclick = evt => {
  5727. if (evt.target === input) {
  5728. setVisibility();
  5729. return true;
  5730. } else if (evt.target !== element) {
  5731. return true;
  5732. }
  5733. input.checked = !input.checked;
  5734. setVisibility();
  5735. return false;
  5736. };
  5737. }
  5738. async _setNestedName(element, {
  5739. name = null
  5740. }) {
  5741. if (typeof name === "string") {
  5742. element.textContent = this._normalizeTextContent(name);
  5743. return;
  5744. }
  5745. element.textContent = await this.l10n.get("additional_layers");
  5746. element.style.fontStyle = "italic";
  5747. }
  5748. _addToggleButton(div, {
  5749. name = null
  5750. }) {
  5751. super._addToggleButton(div, name === null);
  5752. }
  5753. _toggleAllTreeItems() {
  5754. if (!this._optionalContentConfig) {
  5755. return;
  5756. }
  5757. super._toggleAllTreeItems();
  5758. }
  5759. render({
  5760. optionalContentConfig,
  5761. pdfDocument
  5762. }) {
  5763. if (this._optionalContentConfig) {
  5764. this.reset();
  5765. }
  5766. this._optionalContentConfig = optionalContentConfig || null;
  5767. this._pdfDocument = pdfDocument || null;
  5768. const groups = optionalContentConfig?.getOrder();
  5769. if (!groups) {
  5770. this._dispatchEvent(0);
  5771. return;
  5772. }
  5773. const fragment = document.createDocumentFragment(),
  5774. queue = [{
  5775. parent: fragment,
  5776. groups
  5777. }];
  5778. let layersCount = 0,
  5779. hasAnyNesting = false;
  5780. while (queue.length > 0) {
  5781. const levelData = queue.shift();
  5782. for (const groupId of levelData.groups) {
  5783. const div = document.createElement("div");
  5784. div.className = "treeItem";
  5785. const element = document.createElement("a");
  5786. div.appendChild(element);
  5787. if (typeof groupId === "object") {
  5788. hasAnyNesting = true;
  5789. this._addToggleButton(div, groupId);
  5790. this._setNestedName(element, groupId);
  5791. const itemsDiv = document.createElement("div");
  5792. itemsDiv.className = "treeItems";
  5793. div.appendChild(itemsDiv);
  5794. queue.push({
  5795. parent: itemsDiv,
  5796. groups: groupId.order
  5797. });
  5798. } else {
  5799. const group = optionalContentConfig.getGroup(groupId);
  5800. const input = document.createElement("input");
  5801. this._bindLink(element, {
  5802. groupId,
  5803. input
  5804. });
  5805. input.type = "checkbox";
  5806. input.id = groupId;
  5807. input.checked = group.visible;
  5808. const label = document.createElement("label");
  5809. label.setAttribute("for", groupId);
  5810. label.textContent = this._normalizeTextContent(group.name);
  5811. element.appendChild(input);
  5812. element.appendChild(label);
  5813. layersCount++;
  5814. }
  5815. levelData.parent.appendChild(div);
  5816. }
  5817. }
  5818. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5819. }
  5820. async _resetLayers() {
  5821. if (!this._optionalContentConfig) {
  5822. return;
  5823. }
  5824. const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
  5825. this.eventBus.dispatch("optionalcontentconfig", {
  5826. source: this,
  5827. promise: Promise.resolve(optionalContentConfig)
  5828. });
  5829. this.render({
  5830. optionalContentConfig,
  5831. pdfDocument: this._pdfDocument
  5832. });
  5833. }
  5834. }
  5835. exports.PDFLayerViewer = PDFLayerViewer;
  5836. /***/ }),
  5837. /* 19 */
  5838. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5839. Object.defineProperty(exports, "__esModule", ({
  5840. value: true
  5841. }));
  5842. exports.PDFOutlineViewer = void 0;
  5843. var _base_tree_viewer = __webpack_require__(12);
  5844. var _pdfjsLib = __webpack_require__(5);
  5845. var _ui_utils = __webpack_require__(3);
  5846. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  5847. constructor(options) {
  5848. super(options);
  5849. this.linkService = options.linkService;
  5850. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  5851. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  5852. this.eventBus._on("pagechanging", evt => {
  5853. this._currentPageNumber = evt.pageNumber;
  5854. });
  5855. this.eventBus._on("pagesloaded", evt => {
  5856. this._isPagesLoaded = !!evt.pagesCount;
  5857. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5858. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  5859. }
  5860. });
  5861. this.eventBus._on("sidebarviewchanged", evt => {
  5862. this._sidebarView = evt.view;
  5863. });
  5864. }
  5865. reset() {
  5866. super.reset();
  5867. this._outline = null;
  5868. this._pageNumberToDestHashCapability = null;
  5869. this._currentPageNumber = 1;
  5870. this._isPagesLoaded = null;
  5871. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5872. this._currentOutlineItemCapability.resolve(false);
  5873. }
  5874. this._currentOutlineItemCapability = null;
  5875. }
  5876. _dispatchEvent(outlineCount) {
  5877. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  5878. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  5879. this._currentOutlineItemCapability.resolve(false);
  5880. } else if (this._isPagesLoaded !== null) {
  5881. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  5882. }
  5883. this.eventBus.dispatch("outlineloaded", {
  5884. source: this,
  5885. outlineCount,
  5886. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  5887. });
  5888. }
  5889. _bindLink(element, {
  5890. url,
  5891. newWindow,
  5892. dest
  5893. }) {
  5894. const {
  5895. linkService
  5896. } = this;
  5897. if (url) {
  5898. linkService.addLinkAttributes(element, url, newWindow);
  5899. return;
  5900. }
  5901. element.href = linkService.getDestinationHash(dest);
  5902. element.onclick = evt => {
  5903. this._updateCurrentTreeItem(evt.target.parentNode);
  5904. if (dest) {
  5905. linkService.goToDestination(dest);
  5906. }
  5907. return false;
  5908. };
  5909. }
  5910. _setStyles(element, {
  5911. bold,
  5912. italic
  5913. }) {
  5914. if (bold) {
  5915. element.style.fontWeight = "bold";
  5916. }
  5917. if (italic) {
  5918. element.style.fontStyle = "italic";
  5919. }
  5920. }
  5921. _addToggleButton(div, {
  5922. count,
  5923. items
  5924. }) {
  5925. let hidden = false;
  5926. if (count < 0) {
  5927. let totalCount = items.length;
  5928. if (totalCount > 0) {
  5929. const queue = [...items];
  5930. while (queue.length > 0) {
  5931. const {
  5932. count: nestedCount,
  5933. items: nestedItems
  5934. } = queue.shift();
  5935. if (nestedCount > 0 && nestedItems.length > 0) {
  5936. totalCount += nestedItems.length;
  5937. queue.push(...nestedItems);
  5938. }
  5939. }
  5940. }
  5941. if (Math.abs(count) === totalCount) {
  5942. hidden = true;
  5943. }
  5944. }
  5945. super._addToggleButton(div, hidden);
  5946. }
  5947. _toggleAllTreeItems() {
  5948. if (!this._outline) {
  5949. return;
  5950. }
  5951. super._toggleAllTreeItems();
  5952. }
  5953. render({
  5954. outline,
  5955. pdfDocument
  5956. }) {
  5957. if (this._outline) {
  5958. this.reset();
  5959. }
  5960. this._outline = outline || null;
  5961. this._pdfDocument = pdfDocument || null;
  5962. if (!outline) {
  5963. this._dispatchEvent(0);
  5964. return;
  5965. }
  5966. const fragment = document.createDocumentFragment();
  5967. const queue = [{
  5968. parent: fragment,
  5969. items: outline
  5970. }];
  5971. let outlineCount = 0,
  5972. hasAnyNesting = false;
  5973. while (queue.length > 0) {
  5974. const levelData = queue.shift();
  5975. for (const item of levelData.items) {
  5976. const div = document.createElement("div");
  5977. div.className = "treeItem";
  5978. const element = document.createElement("a");
  5979. this._bindLink(element, item);
  5980. this._setStyles(element, item);
  5981. element.textContent = this._normalizeTextContent(item.title);
  5982. div.appendChild(element);
  5983. if (item.items.length > 0) {
  5984. hasAnyNesting = true;
  5985. this._addToggleButton(div, item);
  5986. const itemsDiv = document.createElement("div");
  5987. itemsDiv.className = "treeItems";
  5988. div.appendChild(itemsDiv);
  5989. queue.push({
  5990. parent: itemsDiv,
  5991. items: item.items
  5992. });
  5993. }
  5994. levelData.parent.appendChild(div);
  5995. outlineCount++;
  5996. }
  5997. }
  5998. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  5999. }
  6000. async _currentOutlineItem() {
  6001. if (!this._isPagesLoaded) {
  6002. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6003. }
  6004. if (!this._outline || !this._pdfDocument) {
  6005. return;
  6006. }
  6007. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6008. if (!pageNumberToDestHash) {
  6009. return;
  6010. }
  6011. this._updateCurrentTreeItem(null);
  6012. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6013. return;
  6014. }
  6015. for (let i = this._currentPageNumber; i > 0; i--) {
  6016. const destHash = pageNumberToDestHash.get(i);
  6017. if (!destHash) {
  6018. continue;
  6019. }
  6020. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6021. if (!linkElement) {
  6022. continue;
  6023. }
  6024. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6025. break;
  6026. }
  6027. }
  6028. async _getPageNumberToDestHash(pdfDocument) {
  6029. if (this._pageNumberToDestHashCapability) {
  6030. return this._pageNumberToDestHashCapability.promise;
  6031. }
  6032. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6033. const pageNumberToDestHash = new Map(),
  6034. pageNumberNesting = new Map();
  6035. const queue = [{
  6036. nesting: 0,
  6037. items: this._outline
  6038. }];
  6039. while (queue.length > 0) {
  6040. const levelData = queue.shift(),
  6041. currentNesting = levelData.nesting;
  6042. for (const {
  6043. dest,
  6044. items
  6045. } of levelData.items) {
  6046. let explicitDest, pageNumber;
  6047. if (typeof dest === "string") {
  6048. explicitDest = await pdfDocument.getDestination(dest);
  6049. if (pdfDocument !== this._pdfDocument) {
  6050. return null;
  6051. }
  6052. } else {
  6053. explicitDest = dest;
  6054. }
  6055. if (Array.isArray(explicitDest)) {
  6056. const [destRef] = explicitDest;
  6057. if (typeof destRef === "object" && destRef !== null) {
  6058. pageNumber = this.linkService._cachedPageNumber(destRef);
  6059. if (!pageNumber) {
  6060. try {
  6061. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6062. if (pdfDocument !== this._pdfDocument) {
  6063. return null;
  6064. }
  6065. this.linkService.cachePageRef(pageNumber, destRef);
  6066. } catch (ex) {}
  6067. }
  6068. } else if (Number.isInteger(destRef)) {
  6069. pageNumber = destRef + 1;
  6070. }
  6071. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6072. const destHash = this.linkService.getDestinationHash(dest);
  6073. pageNumberToDestHash.set(pageNumber, destHash);
  6074. pageNumberNesting.set(pageNumber, currentNesting);
  6075. }
  6076. }
  6077. if (items.length > 0) {
  6078. queue.push({
  6079. nesting: currentNesting + 1,
  6080. items
  6081. });
  6082. }
  6083. }
  6084. }
  6085. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6086. return this._pageNumberToDestHashCapability.promise;
  6087. }
  6088. }
  6089. exports.PDFOutlineViewer = PDFOutlineViewer;
  6090. /***/ }),
  6091. /* 20 */
  6092. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6093. Object.defineProperty(exports, "__esModule", ({
  6094. value: true
  6095. }));
  6096. exports.PDFPresentationMode = void 0;
  6097. var _ui_utils = __webpack_require__(3);
  6098. const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  6099. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6100. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6101. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6102. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6103. const PAGE_SWITCH_THRESHOLD = 0.1;
  6104. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6105. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6106. class PDFPresentationMode {
  6107. constructor({
  6108. container,
  6109. pdfViewer,
  6110. eventBus
  6111. }) {
  6112. this.container = container;
  6113. this.pdfViewer = pdfViewer;
  6114. this.eventBus = eventBus;
  6115. this.active = false;
  6116. this.args = null;
  6117. this.contextMenuOpen = false;
  6118. this.mouseScrollTimeStamp = 0;
  6119. this.mouseScrollDelta = 0;
  6120. this.touchSwipeState = null;
  6121. }
  6122. request() {
  6123. if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount || !this.container.requestFullscreen) {
  6124. return false;
  6125. }
  6126. this.#addFullscreenChangeListeners();
  6127. this.#setSwitchInProgress();
  6128. this.#notifyStateChange();
  6129. this.container.requestFullscreen();
  6130. this.args = {
  6131. pageNumber: this.pdfViewer.currentPageNumber,
  6132. scaleValue: this.pdfViewer.currentScaleValue,
  6133. scrollMode: this.pdfViewer.scrollMode,
  6134. spreadMode: this.pdfViewer.spreadMode
  6135. };
  6136. return true;
  6137. }
  6138. #mouseWheel(evt) {
  6139. if (!this.active) {
  6140. return;
  6141. }
  6142. evt.preventDefault();
  6143. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6144. const currentTime = Date.now();
  6145. const storedTime = this.mouseScrollTimeStamp;
  6146. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6147. return;
  6148. }
  6149. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6150. this.#resetMouseScrollState();
  6151. }
  6152. this.mouseScrollDelta += delta;
  6153. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6154. const totalDelta = this.mouseScrollDelta;
  6155. this.#resetMouseScrollState();
  6156. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6157. if (success) {
  6158. this.mouseScrollTimeStamp = currentTime;
  6159. }
  6160. }
  6161. }
  6162. #notifyStateChange() {
  6163. let state = _ui_utils.PresentationModeState.NORMAL;
  6164. if (this.switchInProgress) {
  6165. state = _ui_utils.PresentationModeState.CHANGING;
  6166. } else if (this.active) {
  6167. state = _ui_utils.PresentationModeState.FULLSCREEN;
  6168. }
  6169. this.eventBus.dispatch("presentationmodechanged", {
  6170. source: this,
  6171. state
  6172. });
  6173. }
  6174. #setSwitchInProgress() {
  6175. if (this.switchInProgress) {
  6176. clearTimeout(this.switchInProgress);
  6177. }
  6178. this.switchInProgress = setTimeout(() => {
  6179. this.#removeFullscreenChangeListeners();
  6180. delete this.switchInProgress;
  6181. this.#notifyStateChange();
  6182. }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  6183. }
  6184. #resetSwitchInProgress() {
  6185. if (this.switchInProgress) {
  6186. clearTimeout(this.switchInProgress);
  6187. delete this.switchInProgress;
  6188. }
  6189. }
  6190. #enter() {
  6191. this.active = true;
  6192. this.#resetSwitchInProgress();
  6193. this.#notifyStateChange();
  6194. this.container.classList.add(ACTIVE_SELECTOR);
  6195. setTimeout(() => {
  6196. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6197. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6198. this.pdfViewer.currentPageNumber = this.args.pageNumber;
  6199. this.pdfViewer.currentScaleValue = "page-fit";
  6200. }, 0);
  6201. this.#addWindowListeners();
  6202. this.#showControls();
  6203. this.contextMenuOpen = false;
  6204. window.getSelection().removeAllRanges();
  6205. }
  6206. #exit() {
  6207. const pageNumber = this.pdfViewer.currentPageNumber;
  6208. this.container.classList.remove(ACTIVE_SELECTOR);
  6209. setTimeout(() => {
  6210. this.active = false;
  6211. this.#removeFullscreenChangeListeners();
  6212. this.#notifyStateChange();
  6213. this.pdfViewer.scrollMode = this.args.scrollMode;
  6214. this.pdfViewer.spreadMode = this.args.spreadMode;
  6215. this.pdfViewer.currentScaleValue = this.args.scaleValue;
  6216. this.pdfViewer.currentPageNumber = pageNumber;
  6217. this.args = null;
  6218. }, 0);
  6219. this.#removeWindowListeners();
  6220. this.#hideControls();
  6221. this.#resetMouseScrollState();
  6222. this.contextMenuOpen = false;
  6223. }
  6224. #mouseDown(evt) {
  6225. if (this.contextMenuOpen) {
  6226. this.contextMenuOpen = false;
  6227. evt.preventDefault();
  6228. return;
  6229. }
  6230. if (evt.button === 0) {
  6231. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6232. if (!isInternalLink) {
  6233. evt.preventDefault();
  6234. if (evt.shiftKey) {
  6235. this.pdfViewer.previousPage();
  6236. } else {
  6237. this.pdfViewer.nextPage();
  6238. }
  6239. }
  6240. }
  6241. }
  6242. #contextMenu() {
  6243. this.contextMenuOpen = true;
  6244. }
  6245. #showControls() {
  6246. if (this.controlsTimeout) {
  6247. clearTimeout(this.controlsTimeout);
  6248. } else {
  6249. this.container.classList.add(CONTROLS_SELECTOR);
  6250. }
  6251. this.controlsTimeout = setTimeout(() => {
  6252. this.container.classList.remove(CONTROLS_SELECTOR);
  6253. delete this.controlsTimeout;
  6254. }, DELAY_BEFORE_HIDING_CONTROLS);
  6255. }
  6256. #hideControls() {
  6257. if (!this.controlsTimeout) {
  6258. return;
  6259. }
  6260. clearTimeout(this.controlsTimeout);
  6261. this.container.classList.remove(CONTROLS_SELECTOR);
  6262. delete this.controlsTimeout;
  6263. }
  6264. #resetMouseScrollState() {
  6265. this.mouseScrollTimeStamp = 0;
  6266. this.mouseScrollDelta = 0;
  6267. }
  6268. #touchSwipe(evt) {
  6269. if (!this.active) {
  6270. return;
  6271. }
  6272. if (evt.touches.length > 1) {
  6273. this.touchSwipeState = null;
  6274. return;
  6275. }
  6276. switch (evt.type) {
  6277. case "touchstart":
  6278. this.touchSwipeState = {
  6279. startX: evt.touches[0].pageX,
  6280. startY: evt.touches[0].pageY,
  6281. endX: evt.touches[0].pageX,
  6282. endY: evt.touches[0].pageY
  6283. };
  6284. break;
  6285. case "touchmove":
  6286. if (this.touchSwipeState === null) {
  6287. return;
  6288. }
  6289. this.touchSwipeState.endX = evt.touches[0].pageX;
  6290. this.touchSwipeState.endY = evt.touches[0].pageY;
  6291. evt.preventDefault();
  6292. break;
  6293. case "touchend":
  6294. if (this.touchSwipeState === null) {
  6295. return;
  6296. }
  6297. let delta = 0;
  6298. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6299. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6300. const absAngle = Math.abs(Math.atan2(dy, dx));
  6301. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6302. delta = dx;
  6303. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6304. delta = dy;
  6305. }
  6306. if (delta > 0) {
  6307. this.pdfViewer.previousPage();
  6308. } else if (delta < 0) {
  6309. this.pdfViewer.nextPage();
  6310. }
  6311. break;
  6312. }
  6313. }
  6314. #addWindowListeners() {
  6315. this.showControlsBind = this.#showControls.bind(this);
  6316. this.mouseDownBind = this.#mouseDown.bind(this);
  6317. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6318. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6319. this.contextMenuBind = this.#contextMenu.bind(this);
  6320. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6321. window.addEventListener("mousemove", this.showControlsBind);
  6322. window.addEventListener("mousedown", this.mouseDownBind);
  6323. window.addEventListener("wheel", this.mouseWheelBind, {
  6324. passive: false
  6325. });
  6326. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6327. window.addEventListener("contextmenu", this.contextMenuBind);
  6328. window.addEventListener("touchstart", this.touchSwipeBind);
  6329. window.addEventListener("touchmove", this.touchSwipeBind);
  6330. window.addEventListener("touchend", this.touchSwipeBind);
  6331. }
  6332. #removeWindowListeners() {
  6333. window.removeEventListener("mousemove", this.showControlsBind);
  6334. window.removeEventListener("mousedown", this.mouseDownBind);
  6335. window.removeEventListener("wheel", this.mouseWheelBind, {
  6336. passive: false
  6337. });
  6338. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6339. window.removeEventListener("contextmenu", this.contextMenuBind);
  6340. window.removeEventListener("touchstart", this.touchSwipeBind);
  6341. window.removeEventListener("touchmove", this.touchSwipeBind);
  6342. window.removeEventListener("touchend", this.touchSwipeBind);
  6343. delete this.showControlsBind;
  6344. delete this.mouseDownBind;
  6345. delete this.mouseWheelBind;
  6346. delete this.resetMouseScrollStateBind;
  6347. delete this.contextMenuBind;
  6348. delete this.touchSwipeBind;
  6349. }
  6350. #fullscreenChange() {
  6351. if (document.fullscreenElement) {
  6352. this.#enter();
  6353. } else {
  6354. this.#exit();
  6355. }
  6356. }
  6357. #addFullscreenChangeListeners() {
  6358. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6359. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6360. }
  6361. #removeFullscreenChangeListeners() {
  6362. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6363. delete this.fullscreenChangeBind;
  6364. }
  6365. }
  6366. exports.PDFPresentationMode = PDFPresentationMode;
  6367. /***/ }),
  6368. /* 21 */
  6369. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6370. Object.defineProperty(exports, "__esModule", ({
  6371. value: true
  6372. }));
  6373. exports.PDFRenderingQueue = void 0;
  6374. var _pdfjsLib = __webpack_require__(5);
  6375. var _ui_utils = __webpack_require__(3);
  6376. const CLEANUP_TIMEOUT = 30000;
  6377. class PDFRenderingQueue {
  6378. constructor() {
  6379. this.pdfViewer = null;
  6380. this.pdfThumbnailViewer = null;
  6381. this.onIdle = null;
  6382. this.highestPriorityPage = null;
  6383. this.idleTimeout = null;
  6384. this.printing = false;
  6385. this.isThumbnailViewEnabled = false;
  6386. }
  6387. setViewer(pdfViewer) {
  6388. this.pdfViewer = pdfViewer;
  6389. }
  6390. setThumbnailViewer(pdfThumbnailViewer) {
  6391. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6392. }
  6393. isHighestPriority(view) {
  6394. return this.highestPriorityPage === view.renderingId;
  6395. }
  6396. hasViewer() {
  6397. return !!this.pdfViewer;
  6398. }
  6399. renderHighestPriority(currentlyVisiblePages) {
  6400. if (this.idleTimeout) {
  6401. clearTimeout(this.idleTimeout);
  6402. this.idleTimeout = null;
  6403. }
  6404. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6405. return;
  6406. }
  6407. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6408. return;
  6409. }
  6410. if (this.printing) {
  6411. return;
  6412. }
  6413. if (this.onIdle) {
  6414. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6415. }
  6416. }
  6417. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6418. const visibleViews = visible.views,
  6419. numVisible = visibleViews.length;
  6420. if (numVisible === 0) {
  6421. return null;
  6422. }
  6423. for (let i = 0; i < numVisible; i++) {
  6424. const view = visibleViews[i].view;
  6425. if (!this.isViewFinished(view)) {
  6426. return view;
  6427. }
  6428. }
  6429. const firstId = visible.first.id,
  6430. lastId = visible.last.id;
  6431. if (lastId - firstId + 1 > numVisible) {
  6432. const visibleIds = visible.ids;
  6433. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6434. const holeId = scrolledDown ? firstId + i : lastId - i;
  6435. if (visibleIds.has(holeId)) {
  6436. continue;
  6437. }
  6438. const holeView = views[holeId - 1];
  6439. if (!this.isViewFinished(holeView)) {
  6440. return holeView;
  6441. }
  6442. }
  6443. }
  6444. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6445. let preRenderView = views[preRenderIndex];
  6446. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6447. return preRenderView;
  6448. }
  6449. if (preRenderExtra) {
  6450. preRenderIndex += scrolledDown ? 1 : -1;
  6451. preRenderView = views[preRenderIndex];
  6452. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6453. return preRenderView;
  6454. }
  6455. }
  6456. return null;
  6457. }
  6458. isViewFinished(view) {
  6459. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6460. }
  6461. renderView(view) {
  6462. switch (view.renderingState) {
  6463. case _ui_utils.RenderingStates.FINISHED:
  6464. return false;
  6465. case _ui_utils.RenderingStates.PAUSED:
  6466. this.highestPriorityPage = view.renderingId;
  6467. view.resume();
  6468. break;
  6469. case _ui_utils.RenderingStates.RUNNING:
  6470. this.highestPriorityPage = view.renderingId;
  6471. break;
  6472. case _ui_utils.RenderingStates.INITIAL:
  6473. this.highestPriorityPage = view.renderingId;
  6474. view.draw().finally(() => {
  6475. this.renderHighestPriority();
  6476. }).catch(reason => {
  6477. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6478. return;
  6479. }
  6480. console.error(`renderView: "${reason}"`);
  6481. });
  6482. break;
  6483. }
  6484. return true;
  6485. }
  6486. }
  6487. exports.PDFRenderingQueue = PDFRenderingQueue;
  6488. /***/ }),
  6489. /* 22 */
  6490. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6491. Object.defineProperty(exports, "__esModule", ({
  6492. value: true
  6493. }));
  6494. exports.PDFScriptingManager = void 0;
  6495. var _ui_utils = __webpack_require__(3);
  6496. var _pdfjsLib = __webpack_require__(5);
  6497. class PDFScriptingManager {
  6498. constructor({
  6499. eventBus,
  6500. sandboxBundleSrc = null,
  6501. scriptingFactory = null,
  6502. docPropertiesLookup = null
  6503. }) {
  6504. this._pdfDocument = null;
  6505. this._pdfViewer = null;
  6506. this._closeCapability = null;
  6507. this._destroyCapability = null;
  6508. this._scripting = null;
  6509. this._mouseState = Object.create(null);
  6510. this._ready = false;
  6511. this._eventBus = eventBus;
  6512. this._sandboxBundleSrc = sandboxBundleSrc;
  6513. this._scriptingFactory = scriptingFactory;
  6514. this._docPropertiesLookup = docPropertiesLookup;
  6515. }
  6516. setViewer(pdfViewer) {
  6517. this._pdfViewer = pdfViewer;
  6518. }
  6519. async setDocument(pdfDocument) {
  6520. if (this._pdfDocument) {
  6521. await this._destroyScripting();
  6522. }
  6523. this._pdfDocument = pdfDocument;
  6524. if (!pdfDocument) {
  6525. return;
  6526. }
  6527. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6528. if (!objects && !docActions) {
  6529. await this._destroyScripting();
  6530. return;
  6531. }
  6532. if (pdfDocument !== this._pdfDocument) {
  6533. return;
  6534. }
  6535. try {
  6536. this._scripting = this._createScripting();
  6537. } catch (error) {
  6538. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6539. await this._destroyScripting();
  6540. return;
  6541. }
  6542. this._internalEvents.set("updatefromsandbox", event => {
  6543. if (event?.source !== window) {
  6544. return;
  6545. }
  6546. this._updateFromSandbox(event.detail);
  6547. });
  6548. this._internalEvents.set("dispatcheventinsandbox", event => {
  6549. this._scripting?.dispatchEventInSandbox(event.detail);
  6550. });
  6551. this._internalEvents.set("pagechanging", ({
  6552. pageNumber,
  6553. previous
  6554. }) => {
  6555. if (pageNumber === previous) {
  6556. return;
  6557. }
  6558. this._dispatchPageClose(previous);
  6559. this._dispatchPageOpen(pageNumber);
  6560. });
  6561. this._internalEvents.set("pagerendered", ({
  6562. pageNumber
  6563. }) => {
  6564. if (!this._pageOpenPending.has(pageNumber)) {
  6565. return;
  6566. }
  6567. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6568. return;
  6569. }
  6570. this._dispatchPageOpen(pageNumber);
  6571. });
  6572. this._internalEvents.set("pagesdestroy", async event => {
  6573. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6574. await this._scripting?.dispatchEventInSandbox({
  6575. id: "doc",
  6576. name: "WillClose"
  6577. });
  6578. this._closeCapability?.resolve();
  6579. });
  6580. this._domEvents.set("mousedown", event => {
  6581. this._mouseState.isDown = true;
  6582. });
  6583. this._domEvents.set("mouseup", event => {
  6584. this._mouseState.isDown = false;
  6585. });
  6586. for (const [name, listener] of this._internalEvents) {
  6587. this._eventBus._on(name, listener);
  6588. }
  6589. for (const [name, listener] of this._domEvents) {
  6590. window.addEventListener(name, listener);
  6591. }
  6592. try {
  6593. const docProperties = await this._getDocProperties();
  6594. if (pdfDocument !== this._pdfDocument) {
  6595. return;
  6596. }
  6597. await this._scripting.createSandbox({
  6598. objects,
  6599. calculationOrder,
  6600. appInfo: {
  6601. platform: navigator.platform,
  6602. language: navigator.language
  6603. },
  6604. docInfo: { ...docProperties,
  6605. actions: docActions
  6606. }
  6607. });
  6608. this._eventBus.dispatch("sandboxcreated", {
  6609. source: this
  6610. });
  6611. } catch (error) {
  6612. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6613. await this._destroyScripting();
  6614. return;
  6615. }
  6616. await this._scripting?.dispatchEventInSandbox({
  6617. id: "doc",
  6618. name: "Open"
  6619. });
  6620. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6621. Promise.resolve().then(() => {
  6622. if (pdfDocument === this._pdfDocument) {
  6623. this._ready = true;
  6624. }
  6625. });
  6626. }
  6627. async dispatchWillSave(detail) {
  6628. return this._scripting?.dispatchEventInSandbox({
  6629. id: "doc",
  6630. name: "WillSave"
  6631. });
  6632. }
  6633. async dispatchDidSave(detail) {
  6634. return this._scripting?.dispatchEventInSandbox({
  6635. id: "doc",
  6636. name: "DidSave"
  6637. });
  6638. }
  6639. async dispatchWillPrint(detail) {
  6640. return this._scripting?.dispatchEventInSandbox({
  6641. id: "doc",
  6642. name: "WillPrint"
  6643. });
  6644. }
  6645. async dispatchDidPrint(detail) {
  6646. return this._scripting?.dispatchEventInSandbox({
  6647. id: "doc",
  6648. name: "DidPrint"
  6649. });
  6650. }
  6651. get mouseState() {
  6652. return this._mouseState;
  6653. }
  6654. get destroyPromise() {
  6655. return this._destroyCapability?.promise || null;
  6656. }
  6657. get ready() {
  6658. return this._ready;
  6659. }
  6660. get _internalEvents() {
  6661. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6662. }
  6663. get _domEvents() {
  6664. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6665. }
  6666. get _pageOpenPending() {
  6667. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6668. }
  6669. get _visitedPages() {
  6670. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6671. }
  6672. async _updateFromSandbox(detail) {
  6673. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6674. const {
  6675. id,
  6676. siblings,
  6677. command,
  6678. value
  6679. } = detail;
  6680. if (!id) {
  6681. switch (command) {
  6682. case "clear":
  6683. console.clear();
  6684. break;
  6685. case "error":
  6686. console.error(value);
  6687. break;
  6688. case "layout":
  6689. if (isInPresentationMode) {
  6690. return;
  6691. }
  6692. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  6693. this._pdfViewer.spreadMode = modes.spreadMode;
  6694. break;
  6695. case "page-num":
  6696. this._pdfViewer.currentPageNumber = value + 1;
  6697. break;
  6698. case "print":
  6699. await this._pdfViewer.pagesPromise;
  6700. this._eventBus.dispatch("print", {
  6701. source: this
  6702. });
  6703. break;
  6704. case "println":
  6705. console.log(value);
  6706. break;
  6707. case "zoom":
  6708. if (isInPresentationMode) {
  6709. return;
  6710. }
  6711. this._pdfViewer.currentScaleValue = value;
  6712. break;
  6713. case "SaveAs":
  6714. this._eventBus.dispatch("save", {
  6715. source: this
  6716. });
  6717. break;
  6718. case "FirstPage":
  6719. this._pdfViewer.currentPageNumber = 1;
  6720. break;
  6721. case "LastPage":
  6722. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  6723. break;
  6724. case "NextPage":
  6725. this._pdfViewer.nextPage();
  6726. break;
  6727. case "PrevPage":
  6728. this._pdfViewer.previousPage();
  6729. break;
  6730. case "ZoomViewIn":
  6731. if (isInPresentationMode) {
  6732. return;
  6733. }
  6734. this._pdfViewer.increaseScale();
  6735. break;
  6736. case "ZoomViewOut":
  6737. if (isInPresentationMode) {
  6738. return;
  6739. }
  6740. this._pdfViewer.decreaseScale();
  6741. break;
  6742. }
  6743. return;
  6744. }
  6745. if (isInPresentationMode) {
  6746. if (detail.focus) {
  6747. return;
  6748. }
  6749. }
  6750. delete detail.id;
  6751. delete detail.siblings;
  6752. const ids = siblings ? [id, ...siblings] : [id];
  6753. for (const elementId of ids) {
  6754. const element = document.getElementById(elementId);
  6755. if (element) {
  6756. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6757. detail
  6758. }));
  6759. } else {
  6760. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6761. }
  6762. }
  6763. }
  6764. async _dispatchPageOpen(pageNumber, initialize = false) {
  6765. const pdfDocument = this._pdfDocument,
  6766. visitedPages = this._visitedPages;
  6767. if (initialize) {
  6768. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6769. }
  6770. if (!this._closeCapability) {
  6771. return;
  6772. }
  6773. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6774. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  6775. this._pageOpenPending.add(pageNumber);
  6776. return;
  6777. }
  6778. this._pageOpenPending.delete(pageNumber);
  6779. const actionsPromise = (async () => {
  6780. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6781. if (pdfDocument !== this._pdfDocument) {
  6782. return;
  6783. }
  6784. await this._scripting?.dispatchEventInSandbox({
  6785. id: "page",
  6786. name: "PageOpen",
  6787. pageNumber,
  6788. actions
  6789. });
  6790. })();
  6791. visitedPages.set(pageNumber, actionsPromise);
  6792. }
  6793. async _dispatchPageClose(pageNumber) {
  6794. const pdfDocument = this._pdfDocument,
  6795. visitedPages = this._visitedPages;
  6796. if (!this._closeCapability) {
  6797. return;
  6798. }
  6799. if (this._pageOpenPending.has(pageNumber)) {
  6800. return;
  6801. }
  6802. const actionsPromise = visitedPages.get(pageNumber);
  6803. if (!actionsPromise) {
  6804. return;
  6805. }
  6806. visitedPages.set(pageNumber, null);
  6807. await actionsPromise;
  6808. if (pdfDocument !== this._pdfDocument) {
  6809. return;
  6810. }
  6811. await this._scripting?.dispatchEventInSandbox({
  6812. id: "page",
  6813. name: "PageClose",
  6814. pageNumber
  6815. });
  6816. }
  6817. async _getDocProperties() {
  6818. if (this._docPropertiesLookup) {
  6819. return this._docPropertiesLookup(this._pdfDocument);
  6820. }
  6821. throw new Error("_getDocProperties: Unable to lookup properties.");
  6822. }
  6823. _createScripting() {
  6824. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  6825. if (this._scripting) {
  6826. throw new Error("_createScripting: Scripting already exists.");
  6827. }
  6828. if (this._scriptingFactory) {
  6829. return this._scriptingFactory.createScripting({
  6830. sandboxBundleSrc: this._sandboxBundleSrc
  6831. });
  6832. }
  6833. throw new Error("_createScripting: Cannot create scripting.");
  6834. }
  6835. async _destroyScripting() {
  6836. if (!this._scripting) {
  6837. this._pdfDocument = null;
  6838. this._destroyCapability?.resolve();
  6839. return;
  6840. }
  6841. if (this._closeCapability) {
  6842. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  6843. setTimeout(resolve, 1000);
  6844. })]).catch(reason => {});
  6845. this._closeCapability = null;
  6846. }
  6847. this._pdfDocument = null;
  6848. try {
  6849. await this._scripting.destroySandbox();
  6850. } catch (ex) {}
  6851. for (const [name, listener] of this._internalEvents) {
  6852. this._eventBus._off(name, listener);
  6853. }
  6854. this._internalEvents.clear();
  6855. for (const [name, listener] of this._domEvents) {
  6856. window.removeEventListener(name, listener);
  6857. }
  6858. this._domEvents.clear();
  6859. this._pageOpenPending.clear();
  6860. this._visitedPages.clear();
  6861. this._scripting = null;
  6862. delete this._mouseState.isDown;
  6863. this._ready = false;
  6864. this._destroyCapability?.resolve();
  6865. }
  6866. }
  6867. exports.PDFScriptingManager = PDFScriptingManager;
  6868. /***/ }),
  6869. /* 23 */
  6870. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6871. Object.defineProperty(exports, "__esModule", ({
  6872. value: true
  6873. }));
  6874. exports.PDFSidebar = void 0;
  6875. var _ui_utils = __webpack_require__(3);
  6876. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  6877. class PDFSidebar {
  6878. constructor({
  6879. elements,
  6880. pdfViewer,
  6881. pdfThumbnailViewer,
  6882. eventBus,
  6883. l10n
  6884. }) {
  6885. this.isOpen = false;
  6886. this.active = _ui_utils.SidebarView.THUMBS;
  6887. this.isInitialViewSet = false;
  6888. this.onToggled = null;
  6889. this.pdfViewer = pdfViewer;
  6890. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6891. this.outerContainer = elements.outerContainer;
  6892. this.viewerContainer = elements.viewerContainer;
  6893. this.toggleButton = elements.toggleButton;
  6894. this.thumbnailButton = elements.thumbnailButton;
  6895. this.outlineButton = elements.outlineButton;
  6896. this.attachmentsButton = elements.attachmentsButton;
  6897. this.layersButton = elements.layersButton;
  6898. this.thumbnailView = elements.thumbnailView;
  6899. this.outlineView = elements.outlineView;
  6900. this.attachmentsView = elements.attachmentsView;
  6901. this.layersView = elements.layersView;
  6902. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  6903. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  6904. this.eventBus = eventBus;
  6905. this.l10n = l10n;
  6906. this._addEventListeners();
  6907. }
  6908. reset() {
  6909. this.isInitialViewSet = false;
  6910. this._hideUINotification(true);
  6911. this.switchView(_ui_utils.SidebarView.THUMBS);
  6912. this.outlineButton.disabled = false;
  6913. this.attachmentsButton.disabled = false;
  6914. this.layersButton.disabled = false;
  6915. this._currentOutlineItemButton.disabled = true;
  6916. }
  6917. get visibleView() {
  6918. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  6919. }
  6920. get isThumbnailViewVisible() {
  6921. return this.isOpen && this.active === _ui_utils.SidebarView.THUMBS;
  6922. }
  6923. get isOutlineViewVisible() {
  6924. return this.isOpen && this.active === _ui_utils.SidebarView.OUTLINE;
  6925. }
  6926. get isAttachmentsViewVisible() {
  6927. return this.isOpen && this.active === _ui_utils.SidebarView.ATTACHMENTS;
  6928. }
  6929. get isLayersViewVisible() {
  6930. return this.isOpen && this.active === _ui_utils.SidebarView.LAYERS;
  6931. }
  6932. setInitialView(view = _ui_utils.SidebarView.NONE) {
  6933. if (this.isInitialViewSet) {
  6934. return;
  6935. }
  6936. this.isInitialViewSet = true;
  6937. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  6938. this._dispatchEvent();
  6939. return;
  6940. }
  6941. if (!this._switchView(view, true)) {
  6942. this._dispatchEvent();
  6943. }
  6944. }
  6945. switchView(view, forceOpen = false) {
  6946. this._switchView(view, forceOpen);
  6947. }
  6948. _switchView(view, forceOpen = false) {
  6949. const isViewChanged = view !== this.active;
  6950. let shouldForceRendering = false;
  6951. switch (view) {
  6952. case _ui_utils.SidebarView.NONE:
  6953. if (this.isOpen) {
  6954. this.close();
  6955. return true;
  6956. }
  6957. return false;
  6958. case _ui_utils.SidebarView.THUMBS:
  6959. if (this.isOpen && isViewChanged) {
  6960. shouldForceRendering = true;
  6961. }
  6962. break;
  6963. case _ui_utils.SidebarView.OUTLINE:
  6964. if (this.outlineButton.disabled) {
  6965. return false;
  6966. }
  6967. break;
  6968. case _ui_utils.SidebarView.ATTACHMENTS:
  6969. if (this.attachmentsButton.disabled) {
  6970. return false;
  6971. }
  6972. break;
  6973. case _ui_utils.SidebarView.LAYERS:
  6974. if (this.layersButton.disabled) {
  6975. return false;
  6976. }
  6977. break;
  6978. default:
  6979. console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
  6980. return false;
  6981. }
  6982. this.active = view;
  6983. this.thumbnailButton.classList.toggle("toggled", view === _ui_utils.SidebarView.THUMBS);
  6984. this.outlineButton.classList.toggle("toggled", view === _ui_utils.SidebarView.OUTLINE);
  6985. this.attachmentsButton.classList.toggle("toggled", view === _ui_utils.SidebarView.ATTACHMENTS);
  6986. this.layersButton.classList.toggle("toggled", view === _ui_utils.SidebarView.LAYERS);
  6987. this.thumbnailView.classList.toggle("hidden", view !== _ui_utils.SidebarView.THUMBS);
  6988. this.outlineView.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6989. this.attachmentsView.classList.toggle("hidden", view !== _ui_utils.SidebarView.ATTACHMENTS);
  6990. this.layersView.classList.toggle("hidden", view !== _ui_utils.SidebarView.LAYERS);
  6991. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6992. if (forceOpen && !this.isOpen) {
  6993. this.open();
  6994. return true;
  6995. }
  6996. if (shouldForceRendering) {
  6997. this._updateThumbnailViewer();
  6998. this._forceRendering();
  6999. }
  7000. if (isViewChanged) {
  7001. this._dispatchEvent();
  7002. }
  7003. return isViewChanged;
  7004. }
  7005. open() {
  7006. if (this.isOpen) {
  7007. return;
  7008. }
  7009. this.isOpen = true;
  7010. this.toggleButton.classList.add("toggled");
  7011. this.toggleButton.setAttribute("aria-expanded", "true");
  7012. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7013. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7014. this._updateThumbnailViewer();
  7015. }
  7016. this._forceRendering();
  7017. this._dispatchEvent();
  7018. this._hideUINotification();
  7019. }
  7020. close() {
  7021. if (!this.isOpen) {
  7022. return;
  7023. }
  7024. this.isOpen = false;
  7025. this.toggleButton.classList.remove("toggled");
  7026. this.toggleButton.setAttribute("aria-expanded", "false");
  7027. this.outerContainer.classList.add("sidebarMoving");
  7028. this.outerContainer.classList.remove("sidebarOpen");
  7029. this._forceRendering();
  7030. this._dispatchEvent();
  7031. }
  7032. toggle() {
  7033. if (this.isOpen) {
  7034. this.close();
  7035. } else {
  7036. this.open();
  7037. }
  7038. }
  7039. _dispatchEvent() {
  7040. this.eventBus.dispatch("sidebarviewchanged", {
  7041. source: this,
  7042. view: this.visibleView
  7043. });
  7044. }
  7045. _forceRendering() {
  7046. if (this.onToggled) {
  7047. this.onToggled();
  7048. } else {
  7049. this.pdfViewer.forceRendering();
  7050. this.pdfThumbnailViewer.forceRendering();
  7051. }
  7052. }
  7053. _updateThumbnailViewer() {
  7054. const {
  7055. pdfViewer,
  7056. pdfThumbnailViewer
  7057. } = this;
  7058. const pagesCount = pdfViewer.pagesCount;
  7059. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  7060. const pageView = pdfViewer.getPageView(pageIndex);
  7061. if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) {
  7062. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  7063. thumbnailView.setImage(pageView);
  7064. }
  7065. }
  7066. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  7067. }
  7068. _showUINotification() {
  7069. this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
  7070. this.toggleButton.title = msg;
  7071. });
  7072. if (!this.isOpen) {
  7073. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7074. }
  7075. }
  7076. _hideUINotification(reset = false) {
  7077. if (this.isOpen || reset) {
  7078. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7079. }
  7080. if (reset) {
  7081. this.l10n.get("toggle_sidebar.title").then(msg => {
  7082. this.toggleButton.title = msg;
  7083. });
  7084. }
  7085. }
  7086. _addEventListeners() {
  7087. this.viewerContainer.addEventListener("transitionend", evt => {
  7088. if (evt.target === this.viewerContainer) {
  7089. this.outerContainer.classList.remove("sidebarMoving");
  7090. }
  7091. });
  7092. this.toggleButton.addEventListener("click", () => {
  7093. this.toggle();
  7094. });
  7095. this.thumbnailButton.addEventListener("click", () => {
  7096. this.switchView(_ui_utils.SidebarView.THUMBS);
  7097. });
  7098. this.outlineButton.addEventListener("click", () => {
  7099. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7100. });
  7101. this.outlineButton.addEventListener("dblclick", () => {
  7102. this.eventBus.dispatch("toggleoutlinetree", {
  7103. source: this
  7104. });
  7105. });
  7106. this.attachmentsButton.addEventListener("click", () => {
  7107. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7108. });
  7109. this.layersButton.addEventListener("click", () => {
  7110. this.switchView(_ui_utils.SidebarView.LAYERS);
  7111. });
  7112. this.layersButton.addEventListener("dblclick", () => {
  7113. this.eventBus.dispatch("resetlayers", {
  7114. source: this
  7115. });
  7116. });
  7117. this._currentOutlineItemButton.addEventListener("click", () => {
  7118. this.eventBus.dispatch("currentoutlineitem", {
  7119. source: this
  7120. });
  7121. });
  7122. const onTreeLoaded = (count, button, view) => {
  7123. button.disabled = !count;
  7124. if (count) {
  7125. this._showUINotification();
  7126. } else if (this.active === view) {
  7127. this.switchView(_ui_utils.SidebarView.THUMBS);
  7128. }
  7129. };
  7130. this.eventBus._on("outlineloaded", evt => {
  7131. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7132. evt.currentOutlineItemPromise.then(enabled => {
  7133. if (!this.isInitialViewSet) {
  7134. return;
  7135. }
  7136. this._currentOutlineItemButton.disabled = !enabled;
  7137. });
  7138. });
  7139. this.eventBus._on("attachmentsloaded", evt => {
  7140. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7141. });
  7142. this.eventBus._on("layersloaded", evt => {
  7143. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7144. });
  7145. this.eventBus._on("presentationmodechanged", evt => {
  7146. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.isThumbnailViewVisible) {
  7147. this._updateThumbnailViewer();
  7148. }
  7149. });
  7150. }
  7151. }
  7152. exports.PDFSidebar = PDFSidebar;
  7153. /***/ }),
  7154. /* 24 */
  7155. /***/ ((__unused_webpack_module, exports) => {
  7156. Object.defineProperty(exports, "__esModule", ({
  7157. value: true
  7158. }));
  7159. exports.PDFSidebarResizer = void 0;
  7160. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7161. const SIDEBAR_MIN_WIDTH = 200;
  7162. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7163. class PDFSidebarResizer {
  7164. constructor(options, eventBus, l10n) {
  7165. this.isRTL = false;
  7166. this.sidebarOpen = false;
  7167. this.doc = document.documentElement;
  7168. this._width = null;
  7169. this._outerContainerWidth = null;
  7170. this._boundEvents = Object.create(null);
  7171. this.outerContainer = options.outerContainer;
  7172. this.resizer = options.resizer;
  7173. this.eventBus = eventBus;
  7174. l10n.getDirection().then(dir => {
  7175. this.isRTL = dir === "rtl";
  7176. });
  7177. this._addEventListeners();
  7178. }
  7179. get outerContainerWidth() {
  7180. return this._outerContainerWidth ||= this.outerContainer.clientWidth;
  7181. }
  7182. _updateWidth(width = 0) {
  7183. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7184. if (width > maxWidth) {
  7185. width = maxWidth;
  7186. }
  7187. if (width < SIDEBAR_MIN_WIDTH) {
  7188. width = SIDEBAR_MIN_WIDTH;
  7189. }
  7190. if (width === this._width) {
  7191. return false;
  7192. }
  7193. this._width = width;
  7194. this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7195. return true;
  7196. }
  7197. _mouseMove(evt) {
  7198. let width = evt.clientX;
  7199. if (this.isRTL) {
  7200. width = this.outerContainerWidth - width;
  7201. }
  7202. this._updateWidth(width);
  7203. }
  7204. _mouseUp(evt) {
  7205. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7206. this.eventBus.dispatch("resize", {
  7207. source: this
  7208. });
  7209. const _boundEvents = this._boundEvents;
  7210. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7211. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7212. }
  7213. _addEventListeners() {
  7214. const _boundEvents = this._boundEvents;
  7215. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7216. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7217. this.resizer.addEventListener("mousedown", evt => {
  7218. if (evt.button !== 0) {
  7219. return;
  7220. }
  7221. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7222. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7223. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7224. });
  7225. this.eventBus._on("sidebarviewchanged", evt => {
  7226. this.sidebarOpen = !!evt?.view;
  7227. });
  7228. this.eventBus._on("resize", evt => {
  7229. if (evt?.source !== window) {
  7230. return;
  7231. }
  7232. this._outerContainerWidth = null;
  7233. if (!this._width) {
  7234. return;
  7235. }
  7236. if (!this.sidebarOpen) {
  7237. this._updateWidth(this._width);
  7238. return;
  7239. }
  7240. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7241. const updated = this._updateWidth(this._width);
  7242. Promise.resolve().then(() => {
  7243. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7244. if (updated) {
  7245. this.eventBus.dispatch("resize", {
  7246. source: this
  7247. });
  7248. }
  7249. });
  7250. });
  7251. }
  7252. }
  7253. exports.PDFSidebarResizer = PDFSidebarResizer;
  7254. /***/ }),
  7255. /* 25 */
  7256. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7257. Object.defineProperty(exports, "__esModule", ({
  7258. value: true
  7259. }));
  7260. exports.PDFThumbnailViewer = void 0;
  7261. var _ui_utils = __webpack_require__(3);
  7262. var _pdf_thumbnail_view = __webpack_require__(26);
  7263. const THUMBNAIL_SCROLL_MARGIN = -19;
  7264. const THUMBNAIL_SELECTED_CLASS = "selected";
  7265. class PDFThumbnailViewer {
  7266. constructor({
  7267. container,
  7268. eventBus,
  7269. linkService,
  7270. renderingQueue,
  7271. l10n
  7272. }) {
  7273. this.container = container;
  7274. this.linkService = linkService;
  7275. this.renderingQueue = renderingQueue;
  7276. this.l10n = l10n;
  7277. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7278. this._resetView();
  7279. eventBus._on("optionalcontentconfigchanged", () => {
  7280. this._setImageDisabled = true;
  7281. });
  7282. }
  7283. _scrollUpdated() {
  7284. this.renderingQueue.renderHighestPriority();
  7285. }
  7286. getThumbnail(index) {
  7287. return this._thumbnails[index];
  7288. }
  7289. _getVisibleThumbs() {
  7290. return (0, _ui_utils.getVisibleElements)({
  7291. scrollEl: this.container,
  7292. views: this._thumbnails
  7293. });
  7294. }
  7295. scrollThumbnailIntoView(pageNumber) {
  7296. if (!this.pdfDocument) {
  7297. return;
  7298. }
  7299. const thumbnailView = this._thumbnails[pageNumber - 1];
  7300. if (!thumbnailView) {
  7301. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7302. return;
  7303. }
  7304. if (pageNumber !== this._currentPageNumber) {
  7305. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7306. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7307. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7308. }
  7309. const {
  7310. first,
  7311. last,
  7312. views
  7313. } = this._getVisibleThumbs();
  7314. if (views.length > 0) {
  7315. let shouldScroll = false;
  7316. if (pageNumber <= first.id || pageNumber >= last.id) {
  7317. shouldScroll = true;
  7318. } else {
  7319. for (const {
  7320. id,
  7321. percent
  7322. } of views) {
  7323. if (id !== pageNumber) {
  7324. continue;
  7325. }
  7326. shouldScroll = percent < 100;
  7327. break;
  7328. }
  7329. }
  7330. if (shouldScroll) {
  7331. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7332. top: THUMBNAIL_SCROLL_MARGIN
  7333. });
  7334. }
  7335. }
  7336. this._currentPageNumber = pageNumber;
  7337. }
  7338. get pagesRotation() {
  7339. return this._pagesRotation;
  7340. }
  7341. set pagesRotation(rotation) {
  7342. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7343. throw new Error("Invalid thumbnails rotation angle.");
  7344. }
  7345. if (!this.pdfDocument) {
  7346. return;
  7347. }
  7348. if (this._pagesRotation === rotation) {
  7349. return;
  7350. }
  7351. this._pagesRotation = rotation;
  7352. const updateArgs = {
  7353. rotation
  7354. };
  7355. for (const thumbnail of this._thumbnails) {
  7356. thumbnail.update(updateArgs);
  7357. }
  7358. }
  7359. cleanup() {
  7360. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7361. if (this._thumbnails[i] && this._thumbnails[i].renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7362. this._thumbnails[i].reset();
  7363. }
  7364. }
  7365. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7366. }
  7367. _resetView() {
  7368. this._thumbnails = [];
  7369. this._currentPageNumber = 1;
  7370. this._pageLabels = null;
  7371. this._pagesRotation = 0;
  7372. this._optionalContentConfigPromise = null;
  7373. this._setImageDisabled = false;
  7374. this.container.textContent = "";
  7375. }
  7376. setDocument(pdfDocument) {
  7377. if (this.pdfDocument) {
  7378. this._cancelRendering();
  7379. this._resetView();
  7380. }
  7381. this.pdfDocument = pdfDocument;
  7382. if (!pdfDocument) {
  7383. return;
  7384. }
  7385. const firstPagePromise = pdfDocument.getPage(1);
  7386. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7387. firstPagePromise.then(firstPdfPage => {
  7388. this._optionalContentConfigPromise = optionalContentConfigPromise;
  7389. const pagesCount = pdfDocument.numPages;
  7390. const viewport = firstPdfPage.getViewport({
  7391. scale: 1
  7392. });
  7393. const checkSetImageDisabled = () => {
  7394. return this._setImageDisabled;
  7395. };
  7396. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7397. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7398. container: this.container,
  7399. id: pageNum,
  7400. defaultViewport: viewport.clone(),
  7401. optionalContentConfigPromise,
  7402. linkService: this.linkService,
  7403. renderingQueue: this.renderingQueue,
  7404. checkSetImageDisabled,
  7405. l10n: this.l10n
  7406. });
  7407. this._thumbnails.push(thumbnail);
  7408. }
  7409. const firstThumbnailView = this._thumbnails[0];
  7410. if (firstThumbnailView) {
  7411. firstThumbnailView.setPdfPage(firstPdfPage);
  7412. }
  7413. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7414. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7415. }).catch(reason => {
  7416. console.error("Unable to initialize thumbnail viewer", reason);
  7417. });
  7418. }
  7419. _cancelRendering() {
  7420. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7421. if (this._thumbnails[i]) {
  7422. this._thumbnails[i].cancelRendering();
  7423. }
  7424. }
  7425. }
  7426. setPageLabels(labels) {
  7427. if (!this.pdfDocument) {
  7428. return;
  7429. }
  7430. if (!labels) {
  7431. this._pageLabels = null;
  7432. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7433. this._pageLabels = null;
  7434. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7435. } else {
  7436. this._pageLabels = labels;
  7437. }
  7438. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7439. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7440. }
  7441. }
  7442. async #ensurePdfPageLoaded(thumbView) {
  7443. if (thumbView.pdfPage) {
  7444. return thumbView.pdfPage;
  7445. }
  7446. try {
  7447. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7448. if (!thumbView.pdfPage) {
  7449. thumbView.setPdfPage(pdfPage);
  7450. }
  7451. return pdfPage;
  7452. } catch (reason) {
  7453. console.error("Unable to get page for thumb view", reason);
  7454. return null;
  7455. }
  7456. }
  7457. #getScrollAhead(visible) {
  7458. if (visible.first?.id === 1) {
  7459. return true;
  7460. } else if (visible.last?.id === this._thumbnails.length) {
  7461. return false;
  7462. }
  7463. return this.scroll.down;
  7464. }
  7465. forceRendering() {
  7466. const visibleThumbs = this._getVisibleThumbs();
  7467. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7468. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7469. if (thumbView) {
  7470. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7471. this.renderingQueue.renderView(thumbView);
  7472. });
  7473. return true;
  7474. }
  7475. return false;
  7476. }
  7477. }
  7478. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7479. /***/ }),
  7480. /* 26 */
  7481. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7482. Object.defineProperty(exports, "__esModule", ({
  7483. value: true
  7484. }));
  7485. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7486. var _ui_utils = __webpack_require__(3);
  7487. var _pdfjsLib = __webpack_require__(5);
  7488. const DRAW_UPSCALE_FACTOR = 2;
  7489. const MAX_NUM_SCALING_STEPS = 3;
  7490. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7491. const THUMBNAIL_WIDTH = 98;
  7492. class TempImageFactory {
  7493. static #tempCanvas = null;
  7494. static getCanvas(width, height) {
  7495. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7496. tempCanvas.width = width;
  7497. tempCanvas.height = height;
  7498. tempCanvas.mozOpaque = true;
  7499. const ctx = tempCanvas.getContext("2d", {
  7500. alpha: false
  7501. });
  7502. ctx.save();
  7503. ctx.fillStyle = "rgb(255, 255, 255)";
  7504. ctx.fillRect(0, 0, width, height);
  7505. ctx.restore();
  7506. return [tempCanvas, tempCanvas.getContext("2d")];
  7507. }
  7508. static destroyCanvas() {
  7509. const tempCanvas = this.#tempCanvas;
  7510. if (tempCanvas) {
  7511. tempCanvas.width = 0;
  7512. tempCanvas.height = 0;
  7513. }
  7514. this.#tempCanvas = null;
  7515. }
  7516. }
  7517. exports.TempImageFactory = TempImageFactory;
  7518. class PDFThumbnailView {
  7519. constructor({
  7520. container,
  7521. id,
  7522. defaultViewport,
  7523. optionalContentConfigPromise,
  7524. linkService,
  7525. renderingQueue,
  7526. checkSetImageDisabled,
  7527. l10n
  7528. }) {
  7529. this.id = id;
  7530. this.renderingId = "thumbnail" + id;
  7531. this.pageLabel = null;
  7532. this.pdfPage = null;
  7533. this.rotation = 0;
  7534. this.viewport = defaultViewport;
  7535. this.pdfPageRotate = defaultViewport.rotation;
  7536. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7537. this.linkService = linkService;
  7538. this.renderingQueue = renderingQueue;
  7539. this.renderTask = null;
  7540. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7541. this.resume = null;
  7542. this._checkSetImageDisabled = checkSetImageDisabled || function () {
  7543. return false;
  7544. };
  7545. const pageWidth = this.viewport.width,
  7546. pageHeight = this.viewport.height,
  7547. pageRatio = pageWidth / pageHeight;
  7548. this.canvasWidth = THUMBNAIL_WIDTH;
  7549. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7550. this.scale = this.canvasWidth / pageWidth;
  7551. this.l10n = l10n;
  7552. const anchor = document.createElement("a");
  7553. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7554. this._thumbPageTitle.then(msg => {
  7555. anchor.title = msg;
  7556. });
  7557. anchor.onclick = function () {
  7558. linkService.goToPage(id);
  7559. return false;
  7560. };
  7561. this.anchor = anchor;
  7562. const div = document.createElement("div");
  7563. div.className = "thumbnail";
  7564. div.setAttribute("data-page-number", this.id);
  7565. this.div = div;
  7566. const ring = document.createElement("div");
  7567. ring.className = "thumbnailSelectionRing";
  7568. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7569. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7570. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7571. this.ring = ring;
  7572. div.appendChild(ring);
  7573. anchor.appendChild(div);
  7574. container.appendChild(anchor);
  7575. }
  7576. setPdfPage(pdfPage) {
  7577. this.pdfPage = pdfPage;
  7578. this.pdfPageRotate = pdfPage.rotate;
  7579. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7580. this.viewport = pdfPage.getViewport({
  7581. scale: 1,
  7582. rotation: totalRotation
  7583. });
  7584. this.reset();
  7585. }
  7586. reset() {
  7587. this.cancelRendering();
  7588. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7589. const pageWidth = this.viewport.width,
  7590. pageHeight = this.viewport.height,
  7591. pageRatio = pageWidth / pageHeight;
  7592. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7593. this.scale = this.canvasWidth / pageWidth;
  7594. this.div.removeAttribute("data-loaded");
  7595. const ring = this.ring;
  7596. ring.textContent = "";
  7597. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7598. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7599. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7600. if (this.canvas) {
  7601. this.canvas.width = 0;
  7602. this.canvas.height = 0;
  7603. delete this.canvas;
  7604. }
  7605. if (this.image) {
  7606. this.image.removeAttribute("src");
  7607. delete this.image;
  7608. }
  7609. }
  7610. update({
  7611. rotation = null
  7612. }) {
  7613. if (typeof rotation === "number") {
  7614. this.rotation = rotation;
  7615. }
  7616. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7617. this.viewport = this.viewport.clone({
  7618. scale: 1,
  7619. rotation: totalRotation
  7620. });
  7621. this.reset();
  7622. }
  7623. cancelRendering() {
  7624. if (this.renderTask) {
  7625. this.renderTask.cancel();
  7626. this.renderTask = null;
  7627. }
  7628. this.resume = null;
  7629. }
  7630. _getPageDrawContext(upscaleFactor = 1) {
  7631. const canvas = document.createElement("canvas");
  7632. canvas.mozOpaque = true;
  7633. const ctx = canvas.getContext("2d", {
  7634. alpha: false
  7635. });
  7636. const outputScale = new _ui_utils.OutputScale();
  7637. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7638. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7639. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7640. return {
  7641. ctx,
  7642. canvas,
  7643. transform
  7644. };
  7645. }
  7646. _convertCanvasToImage(canvas) {
  7647. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7648. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  7649. }
  7650. const reducedCanvas = this._reduceImage(canvas);
  7651. const image = document.createElement("img");
  7652. image.className = "thumbnailImage";
  7653. this._thumbPageCanvas.then(msg => {
  7654. image.setAttribute("aria-label", msg);
  7655. });
  7656. image.style.width = this.canvasWidth + "px";
  7657. image.style.height = this.canvasHeight + "px";
  7658. image.src = reducedCanvas.toDataURL();
  7659. this.image = image;
  7660. this.div.setAttribute("data-loaded", true);
  7661. this.ring.appendChild(image);
  7662. reducedCanvas.width = 0;
  7663. reducedCanvas.height = 0;
  7664. }
  7665. draw() {
  7666. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7667. console.error("Must be in new state before drawing");
  7668. return Promise.resolve();
  7669. }
  7670. const {
  7671. pdfPage
  7672. } = this;
  7673. if (!pdfPage) {
  7674. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7675. return Promise.reject(new Error("pdfPage is not loaded"));
  7676. }
  7677. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7678. const finishRenderTask = async (error = null) => {
  7679. if (renderTask === this.renderTask) {
  7680. this.renderTask = null;
  7681. }
  7682. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7683. return;
  7684. }
  7685. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7686. this._convertCanvasToImage(canvas);
  7687. if (error) {
  7688. throw error;
  7689. }
  7690. };
  7691. const {
  7692. ctx,
  7693. canvas,
  7694. transform
  7695. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7696. const drawViewport = this.viewport.clone({
  7697. scale: DRAW_UPSCALE_FACTOR * this.scale
  7698. });
  7699. const renderContinueCallback = cont => {
  7700. if (!this.renderingQueue.isHighestPriority(this)) {
  7701. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  7702. this.resume = () => {
  7703. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7704. cont();
  7705. };
  7706. return;
  7707. }
  7708. cont();
  7709. };
  7710. const renderContext = {
  7711. canvasContext: ctx,
  7712. transform,
  7713. viewport: drawViewport,
  7714. optionalContentConfigPromise: this._optionalContentConfigPromise
  7715. };
  7716. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7717. renderTask.onContinue = renderContinueCallback;
  7718. const resultPromise = renderTask.promise.then(function () {
  7719. return finishRenderTask(null);
  7720. }, function (error) {
  7721. return finishRenderTask(error);
  7722. });
  7723. resultPromise.finally(() => {
  7724. canvas.width = 0;
  7725. canvas.height = 0;
  7726. const pageCached = this.linkService.isPageCached(this.id);
  7727. if (!pageCached) {
  7728. this.pdfPage?.cleanup();
  7729. }
  7730. });
  7731. return resultPromise;
  7732. }
  7733. setImage(pageView) {
  7734. if (this._checkSetImageDisabled()) {
  7735. return;
  7736. }
  7737. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7738. return;
  7739. }
  7740. const {
  7741. canvas,
  7742. pdfPage
  7743. } = pageView;
  7744. if (!canvas) {
  7745. return;
  7746. }
  7747. if (!this.pdfPage) {
  7748. this.setPdfPage(pdfPage);
  7749. }
  7750. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7751. this._convertCanvasToImage(canvas);
  7752. }
  7753. _reduceImage(img) {
  7754. const {
  7755. ctx,
  7756. canvas
  7757. } = this._getPageDrawContext();
  7758. if (img.width <= 2 * canvas.width) {
  7759. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7760. return canvas;
  7761. }
  7762. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7763. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7764. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7765. while (reducedWidth > img.width || reducedHeight > img.height) {
  7766. reducedWidth >>= 1;
  7767. reducedHeight >>= 1;
  7768. }
  7769. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7770. while (reducedWidth > 2 * canvas.width) {
  7771. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7772. reducedWidth >>= 1;
  7773. reducedHeight >>= 1;
  7774. }
  7775. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7776. return canvas;
  7777. }
  7778. get _thumbPageTitle() {
  7779. return this.l10n.get("thumb_page_title", {
  7780. page: this.pageLabel ?? this.id
  7781. });
  7782. }
  7783. get _thumbPageCanvas() {
  7784. return this.l10n.get("thumb_page_canvas", {
  7785. page: this.pageLabel ?? this.id
  7786. });
  7787. }
  7788. setPageLabel(label) {
  7789. this.pageLabel = typeof label === "string" ? label : null;
  7790. this._thumbPageTitle.then(msg => {
  7791. this.anchor.title = msg;
  7792. });
  7793. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7794. return;
  7795. }
  7796. this._thumbPageCanvas.then(msg => {
  7797. this.image?.setAttribute("aria-label", msg);
  7798. });
  7799. }
  7800. }
  7801. exports.PDFThumbnailView = PDFThumbnailView;
  7802. /***/ }),
  7803. /* 27 */
  7804. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7805. Object.defineProperty(exports, "__esModule", ({
  7806. value: true
  7807. }));
  7808. exports.PDFViewer = exports.PDFSinglePageViewer = void 0;
  7809. var _ui_utils = __webpack_require__(3);
  7810. var _base_viewer = __webpack_require__(28);
  7811. class PDFViewer extends _base_viewer.BaseViewer {}
  7812. exports.PDFViewer = PDFViewer;
  7813. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  7814. _resetView() {
  7815. super._resetView();
  7816. this._scrollMode = _ui_utils.ScrollMode.PAGE;
  7817. this._spreadMode = _ui_utils.SpreadMode.NONE;
  7818. }
  7819. set scrollMode(mode) {}
  7820. _updateScrollMode() {}
  7821. set spreadMode(mode) {}
  7822. _updateSpreadMode() {}
  7823. }
  7824. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  7825. /***/ }),
  7826. /* 28 */
  7827. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7828. Object.defineProperty(exports, "__esModule", ({
  7829. value: true
  7830. }));
  7831. exports.PagesCountLimit = exports.PDFPageViewBuffer = exports.BaseViewer = void 0;
  7832. var _pdfjsLib = __webpack_require__(5);
  7833. var _ui_utils = __webpack_require__(3);
  7834. var _annotation_layer_builder = __webpack_require__(29);
  7835. var _l10n_utils = __webpack_require__(30);
  7836. var _pdf_page_view = __webpack_require__(31);
  7837. var _pdf_rendering_queue = __webpack_require__(21);
  7838. var _pdf_link_service = __webpack_require__(8);
  7839. var _struct_tree_layer_builder = __webpack_require__(32);
  7840. var _text_highlighter = __webpack_require__(33);
  7841. var _text_layer_builder = __webpack_require__(34);
  7842. var _xfa_layer_builder = __webpack_require__(35);
  7843. const DEFAULT_CACHE_SIZE = 10;
  7844. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  7845. const PagesCountLimit = {
  7846. FORCE_SCROLL_MODE_PAGE: 15000,
  7847. FORCE_LAZY_PAGE_INIT: 7500,
  7848. PAUSE_EAGER_PAGE_INIT: 250
  7849. };
  7850. exports.PagesCountLimit = PagesCountLimit;
  7851. class PDFPageViewBuffer {
  7852. #buf = new Set();
  7853. #size = 0;
  7854. constructor(size) {
  7855. this.#size = size;
  7856. }
  7857. push(view) {
  7858. const buf = this.#buf;
  7859. if (buf.has(view)) {
  7860. buf.delete(view);
  7861. }
  7862. buf.add(view);
  7863. if (buf.size > this.#size) {
  7864. this.#destroyFirstView();
  7865. }
  7866. }
  7867. resize(newSize, idsToKeep = null) {
  7868. this.#size = newSize;
  7869. const buf = this.#buf;
  7870. if (idsToKeep) {
  7871. const ii = buf.size;
  7872. let i = 1;
  7873. for (const view of buf) {
  7874. if (idsToKeep.has(view.id)) {
  7875. buf.delete(view);
  7876. buf.add(view);
  7877. }
  7878. if (++i > ii) {
  7879. break;
  7880. }
  7881. }
  7882. }
  7883. while (buf.size > this.#size) {
  7884. this.#destroyFirstView();
  7885. }
  7886. }
  7887. has(view) {
  7888. return this.#buf.has(view);
  7889. }
  7890. [Symbol.iterator]() {
  7891. return this.#buf.keys();
  7892. }
  7893. #destroyFirstView() {
  7894. const firstView = this.#buf.keys().next().value;
  7895. firstView?.destroy();
  7896. this.#buf.delete(firstView);
  7897. }
  7898. }
  7899. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  7900. class BaseViewer {
  7901. #buffer = null;
  7902. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  7903. #previousAnnotationMode = null;
  7904. #enablePermissions = false;
  7905. #previousContainerHeight = 0;
  7906. #scrollModePageState = null;
  7907. #onVisibilityChange = null;
  7908. constructor(options) {
  7909. if (this.constructor === BaseViewer) {
  7910. throw new Error("Cannot initialize BaseViewer.");
  7911. }
  7912. const viewerVersion = '2.13.216';
  7913. if (_pdfjsLib.version !== viewerVersion) {
  7914. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  7915. }
  7916. this.container = options.container;
  7917. this.viewer = options.viewer || options.container.firstElementChild;
  7918. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  7919. throw new Error("Invalid `container` and/or `viewer` option.");
  7920. }
  7921. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  7922. throw new Error("The `container` must be absolutely positioned.");
  7923. }
  7924. this.eventBus = options.eventBus;
  7925. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  7926. this.downloadManager = options.downloadManager || null;
  7927. this.findController = options.findController || null;
  7928. this._scriptingManager = options.scriptingManager || null;
  7929. this.removePageBorders = options.removePageBorders || false;
  7930. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  7931. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  7932. this.imageResourcesPath = options.imageResourcesPath || "";
  7933. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  7934. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7935. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  7936. this.maxCanvasPixels = options.maxCanvasPixels;
  7937. this.l10n = options.l10n || _l10n_utils.NullL10n;
  7938. this.#enablePermissions = options.enablePermissions || false;
  7939. this.defaultRenderingQueue = !options.renderingQueue;
  7940. if (this.defaultRenderingQueue) {
  7941. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  7942. this.renderingQueue.setViewer(this);
  7943. } else {
  7944. this.renderingQueue = options.renderingQueue;
  7945. }
  7946. this._doc = document.documentElement;
  7947. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  7948. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  7949. this._onBeforeDraw = this._onAfterDraw = null;
  7950. this._resetView();
  7951. if (this.removePageBorders) {
  7952. this.viewer.classList.add("removePageBorders");
  7953. }
  7954. Promise.resolve().then(() => {
  7955. this.eventBus.dispatch("baseviewerinit", {
  7956. source: this
  7957. });
  7958. });
  7959. }
  7960. get pagesCount() {
  7961. return this._pages.length;
  7962. }
  7963. getPageView(index) {
  7964. return this._pages[index];
  7965. }
  7966. get pageViewsReady() {
  7967. if (!this._pagesCapability.settled) {
  7968. return false;
  7969. }
  7970. return this._pages.every(function (pageView) {
  7971. return pageView?.pdfPage;
  7972. });
  7973. }
  7974. get renderForms() {
  7975. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  7976. }
  7977. get enableScripting() {
  7978. return !!this._scriptingManager;
  7979. }
  7980. get currentPageNumber() {
  7981. return this._currentPageNumber;
  7982. }
  7983. set currentPageNumber(val) {
  7984. if (!Number.isInteger(val)) {
  7985. throw new Error("Invalid page number.");
  7986. }
  7987. if (!this.pdfDocument) {
  7988. return;
  7989. }
  7990. if (!this._setCurrentPageNumber(val, true)) {
  7991. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  7992. }
  7993. }
  7994. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  7995. if (this._currentPageNumber === val) {
  7996. if (resetCurrentPageView) {
  7997. this._resetCurrentPageView();
  7998. }
  7999. return true;
  8000. }
  8001. if (!(0 < val && val <= this.pagesCount)) {
  8002. return false;
  8003. }
  8004. const previous = this._currentPageNumber;
  8005. this._currentPageNumber = val;
  8006. this.eventBus.dispatch("pagechanging", {
  8007. source: this,
  8008. pageNumber: val,
  8009. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8010. previous
  8011. });
  8012. if (resetCurrentPageView) {
  8013. this._resetCurrentPageView();
  8014. }
  8015. return true;
  8016. }
  8017. get currentPageLabel() {
  8018. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8019. }
  8020. set currentPageLabel(val) {
  8021. if (!this.pdfDocument) {
  8022. return;
  8023. }
  8024. let page = val | 0;
  8025. if (this._pageLabels) {
  8026. const i = this._pageLabels.indexOf(val);
  8027. if (i >= 0) {
  8028. page = i + 1;
  8029. }
  8030. }
  8031. if (!this._setCurrentPageNumber(page, true)) {
  8032. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8033. }
  8034. }
  8035. get currentScale() {
  8036. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8037. }
  8038. set currentScale(val) {
  8039. if (isNaN(val)) {
  8040. throw new Error("Invalid numeric scale.");
  8041. }
  8042. if (!this.pdfDocument) {
  8043. return;
  8044. }
  8045. this._setScale(val, false);
  8046. }
  8047. get currentScaleValue() {
  8048. return this._currentScaleValue;
  8049. }
  8050. set currentScaleValue(val) {
  8051. if (!this.pdfDocument) {
  8052. return;
  8053. }
  8054. this._setScale(val, false);
  8055. }
  8056. get pagesRotation() {
  8057. return this._pagesRotation;
  8058. }
  8059. set pagesRotation(rotation) {
  8060. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8061. throw new Error("Invalid pages rotation angle.");
  8062. }
  8063. if (!this.pdfDocument) {
  8064. return;
  8065. }
  8066. rotation %= 360;
  8067. if (rotation < 0) {
  8068. rotation += 360;
  8069. }
  8070. if (this._pagesRotation === rotation) {
  8071. return;
  8072. }
  8073. this._pagesRotation = rotation;
  8074. const pageNumber = this._currentPageNumber;
  8075. const updateArgs = {
  8076. rotation
  8077. };
  8078. for (const pageView of this._pages) {
  8079. pageView.update(updateArgs);
  8080. }
  8081. if (this._currentScaleValue) {
  8082. this._setScale(this._currentScaleValue, true);
  8083. }
  8084. this.eventBus.dispatch("rotationchanging", {
  8085. source: this,
  8086. pagesRotation: rotation,
  8087. pageNumber
  8088. });
  8089. if (this.defaultRenderingQueue) {
  8090. this.update();
  8091. }
  8092. }
  8093. get firstPagePromise() {
  8094. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8095. }
  8096. get onePageRendered() {
  8097. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8098. }
  8099. get pagesPromise() {
  8100. return this.pdfDocument ? this._pagesCapability.promise : null;
  8101. }
  8102. #initializePermissions(permissions) {
  8103. if (!permissions) {
  8104. return;
  8105. }
  8106. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  8107. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  8108. }
  8109. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS)) {
  8110. if (this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8111. this.#previousAnnotationMode = this.#annotationMode;
  8112. this.#annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8113. }
  8114. }
  8115. }
  8116. #onePageRenderedOrForceFetch() {
  8117. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8118. return Promise.resolve();
  8119. }
  8120. const visibilityChangePromise = new Promise(resolve => {
  8121. this.#onVisibilityChange = () => {
  8122. if (document.visibilityState !== "hidden") {
  8123. return;
  8124. }
  8125. resolve();
  8126. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8127. this.#onVisibilityChange = null;
  8128. };
  8129. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8130. });
  8131. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8132. }
  8133. setDocument(pdfDocument) {
  8134. if (this.pdfDocument) {
  8135. this.eventBus.dispatch("pagesdestroy", {
  8136. source: this
  8137. });
  8138. this._cancelRendering();
  8139. this._resetView();
  8140. if (this.findController) {
  8141. this.findController.setDocument(null);
  8142. }
  8143. if (this._scriptingManager) {
  8144. this._scriptingManager.setDocument(null);
  8145. }
  8146. }
  8147. this.pdfDocument = pdfDocument;
  8148. if (!pdfDocument) {
  8149. return;
  8150. }
  8151. const isPureXfa = pdfDocument.isPureXfa;
  8152. const pagesCount = pdfDocument.numPages;
  8153. const firstPagePromise = pdfDocument.getPage(1);
  8154. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8155. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8156. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8157. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8158. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8159. this.eventBus.dispatch("scrollmodechanged", {
  8160. source: this,
  8161. mode
  8162. });
  8163. }
  8164. this._pagesCapability.promise.then(() => {
  8165. this.eventBus.dispatch("pagesloaded", {
  8166. source: this,
  8167. pagesCount
  8168. });
  8169. }, () => {});
  8170. this._onBeforeDraw = evt => {
  8171. const pageView = this._pages[evt.pageNumber - 1];
  8172. if (!pageView) {
  8173. return;
  8174. }
  8175. this.#buffer.push(pageView);
  8176. };
  8177. this.eventBus._on("pagerender", this._onBeforeDraw);
  8178. this._onAfterDraw = evt => {
  8179. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8180. return;
  8181. }
  8182. this._onePageRenderedCapability.resolve({
  8183. timestamp: evt.timestamp
  8184. });
  8185. this.eventBus._off("pagerendered", this._onAfterDraw);
  8186. this._onAfterDraw = null;
  8187. if (this.#onVisibilityChange) {
  8188. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8189. this.#onVisibilityChange = null;
  8190. }
  8191. };
  8192. this.eventBus._on("pagerendered", this._onAfterDraw);
  8193. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8194. if (pdfDocument !== this.pdfDocument) {
  8195. return;
  8196. }
  8197. this._firstPageCapability.resolve(firstPdfPage);
  8198. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8199. this.#initializePermissions(permissions);
  8200. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8201. const scale = this.currentScale;
  8202. const viewport = firstPdfPage.getViewport({
  8203. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8204. });
  8205. const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !isPureXfa ? this : null;
  8206. const annotationLayerFactory = this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE ? this : null;
  8207. const xfaLayerFactory = isPureXfa ? this : null;
  8208. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8209. const pageView = new _pdf_page_view.PDFPageView({
  8210. container: viewerElement,
  8211. eventBus: this.eventBus,
  8212. id: pageNum,
  8213. scale,
  8214. defaultViewport: viewport.clone(),
  8215. optionalContentConfigPromise,
  8216. renderingQueue: this.renderingQueue,
  8217. textLayerFactory,
  8218. textLayerMode: this.textLayerMode,
  8219. annotationLayerFactory,
  8220. annotationMode: this.#annotationMode,
  8221. xfaLayerFactory,
  8222. textHighlighterFactory: this,
  8223. structTreeLayerFactory: this,
  8224. imageResourcesPath: this.imageResourcesPath,
  8225. renderer: this.renderer,
  8226. useOnlyCssZoom: this.useOnlyCssZoom,
  8227. maxCanvasPixels: this.maxCanvasPixels,
  8228. l10n: this.l10n
  8229. });
  8230. this._pages.push(pageView);
  8231. }
  8232. const firstPageView = this._pages[0];
  8233. if (firstPageView) {
  8234. firstPageView.setPdfPage(firstPdfPage);
  8235. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8236. }
  8237. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8238. this.#ensurePageViewVisible();
  8239. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8240. this._updateSpreadMode();
  8241. }
  8242. this.#onePageRenderedOrForceFetch().then(async () => {
  8243. if (this.findController) {
  8244. this.findController.setDocument(pdfDocument);
  8245. }
  8246. if (this._scriptingManager) {
  8247. this._scriptingManager.setDocument(pdfDocument);
  8248. }
  8249. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8250. this._pagesCapability.resolve();
  8251. return;
  8252. }
  8253. let getPagesLeft = pagesCount - 1;
  8254. if (getPagesLeft <= 0) {
  8255. this._pagesCapability.resolve();
  8256. return;
  8257. }
  8258. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8259. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8260. const pageView = this._pages[pageNum - 1];
  8261. if (!pageView.pdfPage) {
  8262. pageView.setPdfPage(pdfPage);
  8263. }
  8264. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8265. if (--getPagesLeft === 0) {
  8266. this._pagesCapability.resolve();
  8267. }
  8268. }, reason => {
  8269. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8270. if (--getPagesLeft === 0) {
  8271. this._pagesCapability.resolve();
  8272. }
  8273. });
  8274. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8275. await promise;
  8276. }
  8277. }
  8278. });
  8279. this.eventBus.dispatch("pagesinit", {
  8280. source: this
  8281. });
  8282. pdfDocument.getMetadata().then(({
  8283. info
  8284. }) => {
  8285. if (pdfDocument !== this.pdfDocument) {
  8286. return;
  8287. }
  8288. if (info.Language) {
  8289. this.viewer.lang = info.Language;
  8290. }
  8291. });
  8292. if (this.defaultRenderingQueue) {
  8293. this.update();
  8294. }
  8295. }).catch(reason => {
  8296. console.error("Unable to initialize viewer", reason);
  8297. this._pagesCapability.reject(reason);
  8298. });
  8299. }
  8300. setPageLabels(labels) {
  8301. if (!this.pdfDocument) {
  8302. return;
  8303. }
  8304. if (!labels) {
  8305. this._pageLabels = null;
  8306. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8307. this._pageLabels = null;
  8308. console.error(`setPageLabels: Invalid page labels.`);
  8309. } else {
  8310. this._pageLabels = labels;
  8311. }
  8312. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8313. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8314. }
  8315. }
  8316. _resetView() {
  8317. this._pages = [];
  8318. this._currentPageNumber = 1;
  8319. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8320. this._currentScaleValue = null;
  8321. this._pageLabels = null;
  8322. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8323. this._location = null;
  8324. this._pagesRotation = 0;
  8325. this._optionalContentConfigPromise = null;
  8326. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8327. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8328. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8329. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8330. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8331. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8332. this.#scrollModePageState = {
  8333. previousPageNumber: 1,
  8334. scrollDown: true,
  8335. pages: []
  8336. };
  8337. if (this._onBeforeDraw) {
  8338. this.eventBus._off("pagerender", this._onBeforeDraw);
  8339. this._onBeforeDraw = null;
  8340. }
  8341. if (this._onAfterDraw) {
  8342. this.eventBus._off("pagerendered", this._onAfterDraw);
  8343. this._onAfterDraw = null;
  8344. }
  8345. if (this.#onVisibilityChange) {
  8346. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8347. this.#onVisibilityChange = null;
  8348. }
  8349. this.viewer.textContent = "";
  8350. this._updateScrollMode();
  8351. this.viewer.removeAttribute("lang");
  8352. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  8353. if (this.#previousAnnotationMode !== null) {
  8354. this.#annotationMode = this.#previousAnnotationMode;
  8355. this.#previousAnnotationMode = null;
  8356. }
  8357. }
  8358. #ensurePageViewVisible() {
  8359. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8360. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8361. }
  8362. const pageNumber = this._currentPageNumber,
  8363. state = this.#scrollModePageState,
  8364. viewer = this.viewer;
  8365. viewer.textContent = "";
  8366. state.pages.length = 0;
  8367. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8368. const pageView = this._pages[pageNumber - 1];
  8369. if (this.isInPresentationMode) {
  8370. const spread = document.createElement("div");
  8371. spread.className = "spread";
  8372. const dummyPage = document.createElement("div");
  8373. dummyPage.className = "dummyPage";
  8374. dummyPage.style.height = `${this.container.clientHeight}px`;
  8375. spread.appendChild(dummyPage);
  8376. spread.appendChild(pageView.div);
  8377. viewer.appendChild(spread);
  8378. } else {
  8379. viewer.appendChild(pageView.div);
  8380. }
  8381. state.pages.push(pageView);
  8382. } else {
  8383. const pageIndexSet = new Set(),
  8384. parity = this._spreadMode - 1;
  8385. if (pageNumber % 2 !== parity) {
  8386. pageIndexSet.add(pageNumber - 1);
  8387. pageIndexSet.add(pageNumber);
  8388. } else {
  8389. pageIndexSet.add(pageNumber - 2);
  8390. pageIndexSet.add(pageNumber - 1);
  8391. }
  8392. let spread = null;
  8393. for (const i of pageIndexSet) {
  8394. const pageView = this._pages[i];
  8395. if (!pageView) {
  8396. continue;
  8397. }
  8398. if (spread === null) {
  8399. spread = document.createElement("div");
  8400. spread.className = "spread";
  8401. viewer.appendChild(spread);
  8402. } else if (i % 2 === parity) {
  8403. spread = spread.cloneNode(false);
  8404. viewer.appendChild(spread);
  8405. }
  8406. spread.appendChild(pageView.div);
  8407. state.pages.push(pageView);
  8408. }
  8409. }
  8410. state.scrollDown = pageNumber >= state.previousPageNumber;
  8411. state.previousPageNumber = pageNumber;
  8412. }
  8413. _scrollUpdate() {
  8414. if (this.pagesCount === 0) {
  8415. return;
  8416. }
  8417. this.update();
  8418. }
  8419. _scrollIntoView({
  8420. pageDiv,
  8421. pageSpot = null,
  8422. pageNumber = null
  8423. }) {
  8424. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8425. if (pageNumber) {
  8426. this._setCurrentPageNumber(pageNumber);
  8427. }
  8428. this.#ensurePageViewVisible();
  8429. this.update();
  8430. }
  8431. if (!pageSpot && !this.isInPresentationMode) {
  8432. const left = pageDiv.offsetLeft + pageDiv.clientLeft;
  8433. const right = left + pageDiv.clientWidth;
  8434. const {
  8435. scrollLeft,
  8436. clientWidth
  8437. } = this.container;
  8438. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8439. pageSpot = {
  8440. left: 0,
  8441. top: 0
  8442. };
  8443. }
  8444. }
  8445. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  8446. }
  8447. #isSameScale(newScale) {
  8448. if (this.isInPresentationMode && this.container.clientHeight !== this.#previousContainerHeight) {
  8449. return false;
  8450. }
  8451. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8452. }
  8453. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8454. this._currentScaleValue = newValue.toString();
  8455. if (this.#isSameScale(newScale)) {
  8456. if (preset) {
  8457. this.eventBus.dispatch("scalechanging", {
  8458. source: this,
  8459. scale: newScale,
  8460. presetValue: newValue
  8461. });
  8462. }
  8463. return;
  8464. }
  8465. this._doc.style.setProperty("--zoom-factor", newScale);
  8466. this._doc.style.setProperty("--viewport-scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8467. const updateArgs = {
  8468. scale: newScale
  8469. };
  8470. for (const pageView of this._pages) {
  8471. pageView.update(updateArgs);
  8472. }
  8473. this._currentScale = newScale;
  8474. if (!noScroll) {
  8475. let page = this._currentPageNumber,
  8476. dest;
  8477. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8478. page = this._location.pageNumber;
  8479. dest = [null, {
  8480. name: "XYZ"
  8481. }, this._location.left, this._location.top, null];
  8482. }
  8483. this.scrollPageIntoView({
  8484. pageNumber: page,
  8485. destArray: dest,
  8486. allowNegativeOffset: true
  8487. });
  8488. }
  8489. this.eventBus.dispatch("scalechanging", {
  8490. source: this,
  8491. scale: newScale,
  8492. presetValue: preset ? newValue : undefined
  8493. });
  8494. if (this.defaultRenderingQueue) {
  8495. this.update();
  8496. }
  8497. this.#previousContainerHeight = this.container.clientHeight;
  8498. }
  8499. get _pageWidthScaleFactor() {
  8500. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8501. return 2;
  8502. }
  8503. return 1;
  8504. }
  8505. _setScale(value, noScroll = false) {
  8506. let scale = parseFloat(value);
  8507. if (scale > 0) {
  8508. this._setScaleUpdatePages(scale, value, noScroll, false);
  8509. } else {
  8510. const currentPage = this._pages[this._currentPageNumber - 1];
  8511. if (!currentPage) {
  8512. return;
  8513. }
  8514. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8515. vPadding = _ui_utils.VERTICAL_PADDING;
  8516. if (this.isInPresentationMode) {
  8517. hPadding = vPadding = 4;
  8518. } else if (this.removePageBorders) {
  8519. hPadding = vPadding = 0;
  8520. }
  8521. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8522. [hPadding, vPadding] = [vPadding, hPadding];
  8523. }
  8524. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8525. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8526. switch (value) {
  8527. case "page-actual":
  8528. scale = 1;
  8529. break;
  8530. case "page-width":
  8531. scale = pageWidthScale;
  8532. break;
  8533. case "page-height":
  8534. scale = pageHeightScale;
  8535. break;
  8536. case "page-fit":
  8537. scale = Math.min(pageWidthScale, pageHeightScale);
  8538. break;
  8539. case "auto":
  8540. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8541. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8542. break;
  8543. default:
  8544. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  8545. return;
  8546. }
  8547. this._setScaleUpdatePages(scale, value, noScroll, true);
  8548. }
  8549. }
  8550. _resetCurrentPageView() {
  8551. if (this.isInPresentationMode) {
  8552. this._setScale(this._currentScaleValue, true);
  8553. }
  8554. const pageView = this._pages[this._currentPageNumber - 1];
  8555. this._scrollIntoView({
  8556. pageDiv: pageView.div
  8557. });
  8558. }
  8559. pageLabelToPageNumber(label) {
  8560. if (!this._pageLabels) {
  8561. return null;
  8562. }
  8563. const i = this._pageLabels.indexOf(label);
  8564. if (i < 0) {
  8565. return null;
  8566. }
  8567. return i + 1;
  8568. }
  8569. scrollPageIntoView({
  8570. pageNumber,
  8571. destArray = null,
  8572. allowNegativeOffset = false,
  8573. ignoreDestinationZoom = false
  8574. }) {
  8575. if (!this.pdfDocument) {
  8576. return;
  8577. }
  8578. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8579. if (!pageView) {
  8580. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  8581. return;
  8582. }
  8583. if (this.isInPresentationMode || !destArray) {
  8584. this._setCurrentPageNumber(pageNumber, true);
  8585. return;
  8586. }
  8587. let x = 0,
  8588. y = 0;
  8589. let width = 0,
  8590. height = 0,
  8591. widthScale,
  8592. heightScale;
  8593. const changeOrientation = pageView.rotation % 180 !== 0;
  8594. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8595. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8596. let scale = 0;
  8597. switch (destArray[1].name) {
  8598. case "XYZ":
  8599. x = destArray[2];
  8600. y = destArray[3];
  8601. scale = destArray[4];
  8602. x = x !== null ? x : 0;
  8603. y = y !== null ? y : pageHeight;
  8604. break;
  8605. case "Fit":
  8606. case "FitB":
  8607. scale = "page-fit";
  8608. break;
  8609. case "FitH":
  8610. case "FitBH":
  8611. y = destArray[2];
  8612. scale = "page-width";
  8613. if (y === null && this._location) {
  8614. x = this._location.left;
  8615. y = this._location.top;
  8616. } else if (typeof y !== "number" || y < 0) {
  8617. y = pageHeight;
  8618. }
  8619. break;
  8620. case "FitV":
  8621. case "FitBV":
  8622. x = destArray[2];
  8623. width = pageWidth;
  8624. height = pageHeight;
  8625. scale = "page-height";
  8626. break;
  8627. case "FitR":
  8628. x = destArray[2];
  8629. y = destArray[3];
  8630. width = destArray[4] - x;
  8631. height = destArray[5] - y;
  8632. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8633. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8634. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8635. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8636. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8637. break;
  8638. default:
  8639. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  8640. return;
  8641. }
  8642. if (!ignoreDestinationZoom) {
  8643. if (scale && scale !== this._currentScale) {
  8644. this.currentScaleValue = scale;
  8645. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8646. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8647. }
  8648. }
  8649. if (scale === "page-fit" && !destArray[4]) {
  8650. this._scrollIntoView({
  8651. pageDiv: pageView.div,
  8652. pageNumber
  8653. });
  8654. return;
  8655. }
  8656. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8657. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8658. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8659. if (!allowNegativeOffset) {
  8660. left = Math.max(left, 0);
  8661. top = Math.max(top, 0);
  8662. }
  8663. this._scrollIntoView({
  8664. pageDiv: pageView.div,
  8665. pageSpot: {
  8666. left,
  8667. top
  8668. },
  8669. pageNumber
  8670. });
  8671. }
  8672. _updateLocation(firstPage) {
  8673. const currentScale = this._currentScale;
  8674. const currentScaleValue = this._currentScaleValue;
  8675. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8676. const pageNumber = firstPage.id;
  8677. let pdfOpenParams = "#page=" + pageNumber;
  8678. pdfOpenParams += "&zoom=" + normalizedScaleValue;
  8679. const currentPageView = this._pages[pageNumber - 1];
  8680. const container = this.container;
  8681. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8682. const intLeft = Math.round(topLeft[0]);
  8683. const intTop = Math.round(topLeft[1]);
  8684. pdfOpenParams += "," + intLeft + "," + intTop;
  8685. this._location = {
  8686. pageNumber,
  8687. scale: normalizedScaleValue,
  8688. top: intTop,
  8689. left: intLeft,
  8690. rotation: this._pagesRotation,
  8691. pdfOpenParams
  8692. };
  8693. }
  8694. update() {
  8695. const visible = this._getVisiblePages();
  8696. const visiblePages = visible.views,
  8697. numVisiblePages = visiblePages.length;
  8698. if (numVisiblePages === 0) {
  8699. return;
  8700. }
  8701. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8702. this.#buffer.resize(newCacheSize, visible.ids);
  8703. this.renderingQueue.renderHighestPriority(visible);
  8704. if (!this.isInPresentationMode) {
  8705. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  8706. let currentId = this._currentPageNumber;
  8707. let stillFullyVisible = false;
  8708. for (const page of visiblePages) {
  8709. if (page.percent < 100) {
  8710. break;
  8711. }
  8712. if (page.id === currentId && isSimpleLayout) {
  8713. stillFullyVisible = true;
  8714. break;
  8715. }
  8716. }
  8717. if (!stillFullyVisible) {
  8718. currentId = visiblePages[0].id;
  8719. }
  8720. this._setCurrentPageNumber(currentId);
  8721. }
  8722. this._updateLocation(visible.first);
  8723. this.eventBus.dispatch("updateviewarea", {
  8724. source: this,
  8725. location: this._location
  8726. });
  8727. }
  8728. containsElement(element) {
  8729. return this.container.contains(element);
  8730. }
  8731. focus() {
  8732. this.container.focus();
  8733. }
  8734. get _isContainerRtl() {
  8735. return getComputedStyle(this.container).direction === "rtl";
  8736. }
  8737. get isInPresentationMode() {
  8738. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8739. }
  8740. get isChangingPresentationMode() {
  8741. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8742. }
  8743. get isHorizontalScrollbarEnabled() {
  8744. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8745. }
  8746. get isVerticalScrollbarEnabled() {
  8747. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8748. }
  8749. _getCurrentVisiblePage() {
  8750. if (!this.pagesCount) {
  8751. return {
  8752. views: []
  8753. };
  8754. }
  8755. const pageView = this._pages[this._currentPageNumber - 1];
  8756. const element = pageView.div;
  8757. const view = {
  8758. id: pageView.id,
  8759. x: element.offsetLeft + element.clientLeft,
  8760. y: element.offsetTop + element.clientTop,
  8761. view: pageView
  8762. };
  8763. const ids = new Set([pageView.id]);
  8764. return {
  8765. first: view,
  8766. last: view,
  8767. views: [view],
  8768. ids
  8769. };
  8770. }
  8771. _getVisiblePages() {
  8772. if (this.isInPresentationMode) {
  8773. return this._getCurrentVisiblePage();
  8774. }
  8775. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  8776. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  8777. rtl = horizontal && this._isContainerRtl;
  8778. return (0, _ui_utils.getVisibleElements)({
  8779. scrollEl: this.container,
  8780. views,
  8781. sortByVisibility: true,
  8782. horizontal,
  8783. rtl
  8784. });
  8785. }
  8786. isPageVisible(pageNumber) {
  8787. if (!this.pdfDocument) {
  8788. return false;
  8789. }
  8790. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8791. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  8792. return false;
  8793. }
  8794. return this._getVisiblePages().ids.has(pageNumber);
  8795. }
  8796. isPageCached(pageNumber) {
  8797. if (!this.pdfDocument) {
  8798. return false;
  8799. }
  8800. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8801. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  8802. return false;
  8803. }
  8804. const pageView = this._pages[pageNumber - 1];
  8805. return this.#buffer.has(pageView);
  8806. }
  8807. cleanup() {
  8808. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8809. if (this._pages[i] && this._pages[i].renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8810. this._pages[i].reset();
  8811. }
  8812. }
  8813. }
  8814. _cancelRendering() {
  8815. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8816. if (this._pages[i]) {
  8817. this._pages[i].cancelRendering();
  8818. }
  8819. }
  8820. }
  8821. async #ensurePdfPageLoaded(pageView) {
  8822. if (pageView.pdfPage) {
  8823. return pageView.pdfPage;
  8824. }
  8825. try {
  8826. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  8827. if (!pageView.pdfPage) {
  8828. pageView.setPdfPage(pdfPage);
  8829. }
  8830. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  8831. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  8832. }
  8833. return pdfPage;
  8834. } catch (reason) {
  8835. console.error("Unable to get page for page view", reason);
  8836. return null;
  8837. }
  8838. }
  8839. #getScrollAhead(visible) {
  8840. if (visible.first?.id === 1) {
  8841. return true;
  8842. } else if (visible.last?.id === this.pagesCount) {
  8843. return false;
  8844. }
  8845. switch (this._scrollMode) {
  8846. case _ui_utils.ScrollMode.PAGE:
  8847. return this.#scrollModePageState.scrollDown;
  8848. case _ui_utils.ScrollMode.HORIZONTAL:
  8849. return this.scroll.right;
  8850. }
  8851. return this.scroll.down;
  8852. }
  8853. #toggleLoadingIconSpinner(visibleIds) {
  8854. for (const id of visibleIds) {
  8855. const pageView = this._pages[id - 1];
  8856. pageView?.toggleLoadingIconSpinner(true);
  8857. }
  8858. for (const pageView of this.#buffer) {
  8859. if (visibleIds.has(pageView.id)) {
  8860. continue;
  8861. }
  8862. pageView.toggleLoadingIconSpinner(false);
  8863. }
  8864. }
  8865. forceRendering(currentlyVisiblePages) {
  8866. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  8867. const scrollAhead = this.#getScrollAhead(visiblePages);
  8868. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  8869. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  8870. this.#toggleLoadingIconSpinner(visiblePages.ids);
  8871. if (pageView) {
  8872. this.#ensurePdfPageLoaded(pageView).then(() => {
  8873. this.renderingQueue.renderView(pageView);
  8874. });
  8875. return true;
  8876. }
  8877. return false;
  8878. }
  8879. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus, highlighter) {
  8880. return new _text_layer_builder.TextLayerBuilder({
  8881. textLayerDiv,
  8882. eventBus,
  8883. pageIndex,
  8884. viewport,
  8885. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection,
  8886. highlighter
  8887. });
  8888. }
  8889. createTextHighlighter(pageIndex, eventBus) {
  8890. return new _text_highlighter.TextHighlighter({
  8891. eventBus,
  8892. pageIndex,
  8893. findController: this.isInPresentationMode ? null : this.findController
  8894. });
  8895. }
  8896. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderForms = true, l10n = _l10n_utils.NullL10n, enableScripting = null, hasJSActionsPromise = null, mouseState = null, fieldObjectsPromise = null, annotationCanvasMap = null) {
  8897. return new _annotation_layer_builder.AnnotationLayerBuilder({
  8898. pageDiv,
  8899. pdfPage,
  8900. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8901. imageResourcesPath,
  8902. renderForms,
  8903. linkService: this.linkService,
  8904. downloadManager: this.downloadManager,
  8905. l10n,
  8906. enableScripting: enableScripting ?? this.enableScripting,
  8907. hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
  8908. fieldObjectsPromise: fieldObjectsPromise || this.pdfDocument?.getFieldObjects(),
  8909. mouseState: mouseState || this._scriptingManager?.mouseState,
  8910. annotationCanvasMap
  8911. });
  8912. }
  8913. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null) {
  8914. return new _xfa_layer_builder.XfaLayerBuilder({
  8915. pageDiv,
  8916. pdfPage,
  8917. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8918. linkService: this.linkService
  8919. });
  8920. }
  8921. createStructTreeLayerBuilder(pdfPage) {
  8922. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  8923. pdfPage
  8924. });
  8925. }
  8926. get hasEqualPageSizes() {
  8927. const firstPageView = this._pages[0];
  8928. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  8929. const pageView = this._pages[i];
  8930. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  8931. return false;
  8932. }
  8933. }
  8934. return true;
  8935. }
  8936. getPagesOverview() {
  8937. return this._pages.map(pageView => {
  8938. const viewport = pageView.pdfPage.getViewport({
  8939. scale: 1
  8940. });
  8941. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  8942. return {
  8943. width: viewport.width,
  8944. height: viewport.height,
  8945. rotation: viewport.rotation
  8946. };
  8947. }
  8948. return {
  8949. width: viewport.height,
  8950. height: viewport.width,
  8951. rotation: (viewport.rotation - 90) % 360
  8952. };
  8953. });
  8954. }
  8955. get optionalContentConfigPromise() {
  8956. if (!this.pdfDocument) {
  8957. return Promise.resolve(null);
  8958. }
  8959. if (!this._optionalContentConfigPromise) {
  8960. return this.pdfDocument.getOptionalContentConfig();
  8961. }
  8962. return this._optionalContentConfigPromise;
  8963. }
  8964. set optionalContentConfigPromise(promise) {
  8965. if (!(promise instanceof Promise)) {
  8966. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  8967. }
  8968. if (!this.pdfDocument) {
  8969. return;
  8970. }
  8971. if (!this._optionalContentConfigPromise) {
  8972. return;
  8973. }
  8974. this._optionalContentConfigPromise = promise;
  8975. const updateArgs = {
  8976. optionalContentConfigPromise: promise
  8977. };
  8978. for (const pageView of this._pages) {
  8979. pageView.update(updateArgs);
  8980. }
  8981. this.update();
  8982. this.eventBus.dispatch("optionalcontentconfigchanged", {
  8983. source: this,
  8984. promise
  8985. });
  8986. }
  8987. get scrollMode() {
  8988. return this._scrollMode;
  8989. }
  8990. set scrollMode(mode) {
  8991. if (this._scrollMode === mode) {
  8992. return;
  8993. }
  8994. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  8995. throw new Error(`Invalid scroll mode: ${mode}`);
  8996. }
  8997. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8998. return;
  8999. }
  9000. this._previousScrollMode = this._scrollMode;
  9001. this._scrollMode = mode;
  9002. this.eventBus.dispatch("scrollmodechanged", {
  9003. source: this,
  9004. mode
  9005. });
  9006. this._updateScrollMode(this._currentPageNumber);
  9007. }
  9008. _updateScrollMode(pageNumber = null) {
  9009. const scrollMode = this._scrollMode,
  9010. viewer = this.viewer;
  9011. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9012. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9013. if (!this.pdfDocument || !pageNumber) {
  9014. return;
  9015. }
  9016. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9017. this.#ensurePageViewVisible();
  9018. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9019. this._updateSpreadMode();
  9020. }
  9021. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9022. this._setScale(this._currentScaleValue, true);
  9023. }
  9024. this._setCurrentPageNumber(pageNumber, true);
  9025. this.update();
  9026. }
  9027. get spreadMode() {
  9028. return this._spreadMode;
  9029. }
  9030. set spreadMode(mode) {
  9031. if (this._spreadMode === mode) {
  9032. return;
  9033. }
  9034. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9035. throw new Error(`Invalid spread mode: ${mode}`);
  9036. }
  9037. this._spreadMode = mode;
  9038. this.eventBus.dispatch("spreadmodechanged", {
  9039. source: this,
  9040. mode
  9041. });
  9042. this._updateSpreadMode(this._currentPageNumber);
  9043. }
  9044. _updateSpreadMode(pageNumber = null) {
  9045. if (!this.pdfDocument) {
  9046. return;
  9047. }
  9048. const viewer = this.viewer,
  9049. pages = this._pages;
  9050. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9051. this.#ensurePageViewVisible();
  9052. } else {
  9053. viewer.textContent = "";
  9054. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9055. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9056. viewer.appendChild(pages[i].div);
  9057. }
  9058. } else {
  9059. const parity = this._spreadMode - 1;
  9060. let spread = null;
  9061. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9062. if (spread === null) {
  9063. spread = document.createElement("div");
  9064. spread.className = "spread";
  9065. viewer.appendChild(spread);
  9066. } else if (i % 2 === parity) {
  9067. spread = spread.cloneNode(false);
  9068. viewer.appendChild(spread);
  9069. }
  9070. spread.appendChild(pages[i].div);
  9071. }
  9072. }
  9073. }
  9074. if (!pageNumber) {
  9075. return;
  9076. }
  9077. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9078. this._setScale(this._currentScaleValue, true);
  9079. }
  9080. this._setCurrentPageNumber(pageNumber, true);
  9081. this.update();
  9082. }
  9083. _getPageAdvance(currentPageNumber, previous = false) {
  9084. switch (this._scrollMode) {
  9085. case _ui_utils.ScrollMode.WRAPPED:
  9086. {
  9087. const {
  9088. views
  9089. } = this._getVisiblePages(),
  9090. pageLayout = new Map();
  9091. for (const {
  9092. id,
  9093. y,
  9094. percent,
  9095. widthPercent
  9096. } of views) {
  9097. if (percent === 0 || widthPercent < 100) {
  9098. continue;
  9099. }
  9100. let yArray = pageLayout.get(y);
  9101. if (!yArray) {
  9102. pageLayout.set(y, yArray ||= []);
  9103. }
  9104. yArray.push(id);
  9105. }
  9106. for (const yArray of pageLayout.values()) {
  9107. const currentIndex = yArray.indexOf(currentPageNumber);
  9108. if (currentIndex === -1) {
  9109. continue;
  9110. }
  9111. const numPages = yArray.length;
  9112. if (numPages === 1) {
  9113. break;
  9114. }
  9115. if (previous) {
  9116. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9117. const currentId = yArray[i],
  9118. expectedId = yArray[i + 1] - 1;
  9119. if (currentId < expectedId) {
  9120. return currentPageNumber - expectedId;
  9121. }
  9122. }
  9123. } else {
  9124. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9125. const currentId = yArray[i],
  9126. expectedId = yArray[i - 1] + 1;
  9127. if (currentId > expectedId) {
  9128. return expectedId - currentPageNumber;
  9129. }
  9130. }
  9131. }
  9132. if (previous) {
  9133. const firstId = yArray[0];
  9134. if (firstId < currentPageNumber) {
  9135. return currentPageNumber - firstId + 1;
  9136. }
  9137. } else {
  9138. const lastId = yArray[numPages - 1];
  9139. if (lastId > currentPageNumber) {
  9140. return lastId - currentPageNumber + 1;
  9141. }
  9142. }
  9143. break;
  9144. }
  9145. break;
  9146. }
  9147. case _ui_utils.ScrollMode.HORIZONTAL:
  9148. {
  9149. break;
  9150. }
  9151. case _ui_utils.ScrollMode.PAGE:
  9152. case _ui_utils.ScrollMode.VERTICAL:
  9153. {
  9154. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9155. break;
  9156. }
  9157. const parity = this._spreadMode - 1;
  9158. if (previous && currentPageNumber % 2 !== parity) {
  9159. break;
  9160. } else if (!previous && currentPageNumber % 2 === parity) {
  9161. break;
  9162. }
  9163. const {
  9164. views
  9165. } = this._getVisiblePages(),
  9166. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9167. for (const {
  9168. id,
  9169. percent,
  9170. widthPercent
  9171. } of views) {
  9172. if (id !== expectedId) {
  9173. continue;
  9174. }
  9175. if (percent > 0 && widthPercent === 100) {
  9176. return 2;
  9177. }
  9178. break;
  9179. }
  9180. break;
  9181. }
  9182. }
  9183. return 1;
  9184. }
  9185. nextPage() {
  9186. const currentPageNumber = this._currentPageNumber,
  9187. pagesCount = this.pagesCount;
  9188. if (currentPageNumber >= pagesCount) {
  9189. return false;
  9190. }
  9191. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9192. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9193. return true;
  9194. }
  9195. previousPage() {
  9196. const currentPageNumber = this._currentPageNumber;
  9197. if (currentPageNumber <= 1) {
  9198. return false;
  9199. }
  9200. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9201. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9202. return true;
  9203. }
  9204. increaseScale(steps = 1) {
  9205. let newScale = this._currentScale;
  9206. do {
  9207. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9208. newScale = Math.ceil(newScale * 10) / 10;
  9209. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  9210. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9211. this.currentScaleValue = newScale;
  9212. }
  9213. decreaseScale(steps = 1) {
  9214. let newScale = this._currentScale;
  9215. do {
  9216. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9217. newScale = Math.floor(newScale * 10) / 10;
  9218. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  9219. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9220. this.currentScaleValue = newScale;
  9221. }
  9222. }
  9223. exports.BaseViewer = BaseViewer;
  9224. /***/ }),
  9225. /* 29 */
  9226. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9227. Object.defineProperty(exports, "__esModule", ({
  9228. value: true
  9229. }));
  9230. exports.AnnotationLayerBuilder = void 0;
  9231. var _pdfjsLib = __webpack_require__(5);
  9232. var _l10n_utils = __webpack_require__(30);
  9233. class AnnotationLayerBuilder {
  9234. constructor({
  9235. pageDiv,
  9236. pdfPage,
  9237. linkService,
  9238. downloadManager,
  9239. annotationStorage = null,
  9240. imageResourcesPath = "",
  9241. renderForms = true,
  9242. l10n = _l10n_utils.NullL10n,
  9243. enableScripting = false,
  9244. hasJSActionsPromise = null,
  9245. fieldObjectsPromise = null,
  9246. mouseState = null,
  9247. annotationCanvasMap = null
  9248. }) {
  9249. this.pageDiv = pageDiv;
  9250. this.pdfPage = pdfPage;
  9251. this.linkService = linkService;
  9252. this.downloadManager = downloadManager;
  9253. this.imageResourcesPath = imageResourcesPath;
  9254. this.renderForms = renderForms;
  9255. this.l10n = l10n;
  9256. this.annotationStorage = annotationStorage;
  9257. this.enableScripting = enableScripting;
  9258. this._hasJSActionsPromise = hasJSActionsPromise;
  9259. this._fieldObjectsPromise = fieldObjectsPromise;
  9260. this._mouseState = mouseState;
  9261. this._annotationCanvasMap = annotationCanvasMap;
  9262. this.div = null;
  9263. this._cancelled = false;
  9264. }
  9265. async render(viewport, intent = "display") {
  9266. const [annotations, hasJSActions = false, fieldObjects = null] = await Promise.all([this.pdfPage.getAnnotations({
  9267. intent
  9268. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  9269. if (this._cancelled || annotations.length === 0) {
  9270. return;
  9271. }
  9272. const parameters = {
  9273. viewport: viewport.clone({
  9274. dontFlip: true
  9275. }),
  9276. div: this.div,
  9277. annotations,
  9278. page: this.pdfPage,
  9279. imageResourcesPath: this.imageResourcesPath,
  9280. renderForms: this.renderForms,
  9281. linkService: this.linkService,
  9282. downloadManager: this.downloadManager,
  9283. annotationStorage: this.annotationStorage,
  9284. enableScripting: this.enableScripting,
  9285. hasJSActions,
  9286. fieldObjects,
  9287. mouseState: this._mouseState,
  9288. annotationCanvasMap: this._annotationCanvasMap
  9289. };
  9290. if (this.div) {
  9291. _pdfjsLib.AnnotationLayer.update(parameters);
  9292. } else {
  9293. this.div = document.createElement("div");
  9294. this.div.className = "annotationLayer";
  9295. this.pageDiv.appendChild(this.div);
  9296. parameters.div = this.div;
  9297. _pdfjsLib.AnnotationLayer.render(parameters);
  9298. this.l10n.translate(this.div);
  9299. }
  9300. }
  9301. cancel() {
  9302. this._cancelled = true;
  9303. }
  9304. hide() {
  9305. if (!this.div) {
  9306. return;
  9307. }
  9308. this.div.hidden = true;
  9309. }
  9310. }
  9311. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  9312. /***/ }),
  9313. /* 30 */
  9314. /***/ ((__unused_webpack_module, exports) => {
  9315. Object.defineProperty(exports, "__esModule", ({
  9316. value: true
  9317. }));
  9318. exports.NullL10n = void 0;
  9319. exports.fixupLangCode = fixupLangCode;
  9320. exports.getL10nFallback = getL10nFallback;
  9321. const DEFAULT_L10N_STRINGS = {
  9322. of_pages: "of {{pagesCount}}",
  9323. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9324. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9325. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9326. document_properties_date_string: "{{date}}, {{time}}",
  9327. document_properties_page_size_unit_inches: "in",
  9328. document_properties_page_size_unit_millimeters: "mm",
  9329. document_properties_page_size_orientation_portrait: "portrait",
  9330. document_properties_page_size_orientation_landscape: "landscape",
  9331. document_properties_page_size_name_a3: "A3",
  9332. document_properties_page_size_name_a4: "A4",
  9333. document_properties_page_size_name_letter: "Letter",
  9334. document_properties_page_size_name_legal: "Legal",
  9335. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9336. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9337. document_properties_linearized_yes: "Yes",
  9338. document_properties_linearized_no: "No",
  9339. print_progress_percent: "{{progress}}%",
  9340. "toggle_sidebar.title": "Toggle Sidebar",
  9341. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  9342. additional_layers: "Additional Layers",
  9343. page_landmark: "Page {{page}}",
  9344. thumb_page_title: "Page {{page}}",
  9345. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9346. find_reached_top: "Reached top of document, continued from bottom",
  9347. find_reached_bottom: "Reached end of document, continued from top",
  9348. "find_match_count[one]": "{{current}} of {{total}} match",
  9349. "find_match_count[other]": "{{current}} of {{total}} matches",
  9350. "find_match_count_limit[one]": "More than {{limit}} match",
  9351. "find_match_count_limit[other]": "More than {{limit}} matches",
  9352. find_not_found: "Phrase not found",
  9353. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  9354. error_message: "Message: {{message}}",
  9355. error_stack: "Stack: {{stack}}",
  9356. error_file: "File: {{file}}",
  9357. error_line: "Line: {{line}}",
  9358. rendering_error: "An error occurred while rendering the page.",
  9359. page_scale_width: "Page Width",
  9360. page_scale_fit: "Page Fit",
  9361. page_scale_auto: "Automatic Zoom",
  9362. page_scale_actual: "Actual Size",
  9363. page_scale_percent: "{{scale}}%",
  9364. loading: "Loading…",
  9365. loading_error: "An error occurred while loading the PDF.",
  9366. invalid_file_error: "Invalid or corrupted PDF file.",
  9367. missing_file_error: "Missing PDF file.",
  9368. unexpected_response_error: "Unexpected server response.",
  9369. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9370. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9371. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
  9372. };
  9373. function getL10nFallback(key, args) {
  9374. switch (key) {
  9375. case "find_match_count":
  9376. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9377. break;
  9378. case "find_match_count_limit":
  9379. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9380. break;
  9381. }
  9382. return DEFAULT_L10N_STRINGS[key] || "";
  9383. }
  9384. const PARTIAL_LANG_CODES = {
  9385. en: "en-US",
  9386. es: "es-ES",
  9387. fy: "fy-NL",
  9388. ga: "ga-IE",
  9389. gu: "gu-IN",
  9390. hi: "hi-IN",
  9391. hy: "hy-AM",
  9392. nb: "nb-NO",
  9393. ne: "ne-NP",
  9394. nn: "nn-NO",
  9395. pa: "pa-IN",
  9396. pt: "pt-PT",
  9397. sv: "sv-SE",
  9398. zh: "zh-CN"
  9399. };
  9400. function fixupLangCode(langCode) {
  9401. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9402. }
  9403. function formatL10nValue(text, args) {
  9404. if (!args) {
  9405. return text;
  9406. }
  9407. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9408. return name in args ? args[name] : "{{" + name + "}}";
  9409. });
  9410. }
  9411. const NullL10n = {
  9412. async getLanguage() {
  9413. return "en-us";
  9414. },
  9415. async getDirection() {
  9416. return "ltr";
  9417. },
  9418. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9419. return formatL10nValue(fallback, args);
  9420. },
  9421. async translate(element) {}
  9422. };
  9423. exports.NullL10n = NullL10n;
  9424. /***/ }),
  9425. /* 31 */
  9426. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9427. Object.defineProperty(exports, "__esModule", ({
  9428. value: true
  9429. }));
  9430. exports.PDFPageView = void 0;
  9431. var _pdfjsLib = __webpack_require__(5);
  9432. var _ui_utils = __webpack_require__(3);
  9433. var _app_options = __webpack_require__(1);
  9434. var _l10n_utils = __webpack_require__(30);
  9435. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9436. class PDFPageView {
  9437. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9438. constructor(options) {
  9439. const container = options.container;
  9440. const defaultViewport = options.defaultViewport;
  9441. this.id = options.id;
  9442. this.renderingId = "page" + this.id;
  9443. this.pdfPage = null;
  9444. this.pageLabel = null;
  9445. this.rotation = 0;
  9446. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9447. this.viewport = defaultViewport;
  9448. this.pdfPageRotate = defaultViewport.rotation;
  9449. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9450. this.hasRestrictedScaling = false;
  9451. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9452. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9453. this.imageResourcesPath = options.imageResourcesPath || "";
  9454. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9455. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9456. this.eventBus = options.eventBus;
  9457. this.renderingQueue = options.renderingQueue;
  9458. this.textLayerFactory = options.textLayerFactory;
  9459. this.annotationLayerFactory = options.annotationLayerFactory;
  9460. this.xfaLayerFactory = options.xfaLayerFactory;
  9461. this.textHighlighter = options.textHighlighterFactory?.createTextHighlighter(this.id - 1, this.eventBus);
  9462. this.structTreeLayerFactory = options.structTreeLayerFactory;
  9463. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9464. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9465. this.paintTask = null;
  9466. this.paintedViewportMap = new WeakMap();
  9467. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9468. this.resume = null;
  9469. this._renderError = null;
  9470. this._isStandalone = !this.renderingQueue?.hasViewer();
  9471. this._annotationCanvasMap = null;
  9472. this.annotationLayer = null;
  9473. this.textLayer = null;
  9474. this.zoomLayer = null;
  9475. this.xfaLayer = null;
  9476. this.structTreeLayer = null;
  9477. const div = document.createElement("div");
  9478. div.className = "page";
  9479. div.style.width = Math.floor(this.viewport.width) + "px";
  9480. div.style.height = Math.floor(this.viewport.height) + "px";
  9481. div.setAttribute("data-page-number", this.id);
  9482. div.setAttribute("role", "region");
  9483. this.l10n.get("page_landmark", {
  9484. page: this.id
  9485. }).then(msg => {
  9486. div.setAttribute("aria-label", msg);
  9487. });
  9488. this.div = div;
  9489. container?.appendChild(div);
  9490. }
  9491. setPdfPage(pdfPage) {
  9492. this.pdfPage = pdfPage;
  9493. this.pdfPageRotate = pdfPage.rotate;
  9494. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9495. this.viewport = pdfPage.getViewport({
  9496. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9497. rotation: totalRotation
  9498. });
  9499. this.reset();
  9500. }
  9501. destroy() {
  9502. this.reset();
  9503. if (this.pdfPage) {
  9504. this.pdfPage.cleanup();
  9505. }
  9506. }
  9507. async _renderAnnotationLayer() {
  9508. let error = null;
  9509. try {
  9510. await this.annotationLayer.render(this.viewport, "display");
  9511. } catch (ex) {
  9512. error = ex;
  9513. } finally {
  9514. this.eventBus.dispatch("annotationlayerrendered", {
  9515. source: this,
  9516. pageNumber: this.id,
  9517. error
  9518. });
  9519. }
  9520. }
  9521. async _renderXfaLayer() {
  9522. let error = null;
  9523. try {
  9524. const result = await this.xfaLayer.render(this.viewport, "display");
  9525. if (this.textHighlighter) {
  9526. this._buildXfaTextContentItems(result.textDivs);
  9527. }
  9528. } catch (ex) {
  9529. error = ex;
  9530. } finally {
  9531. this.eventBus.dispatch("xfalayerrendered", {
  9532. source: this,
  9533. pageNumber: this.id,
  9534. error
  9535. });
  9536. }
  9537. }
  9538. async _buildXfaTextContentItems(textDivs) {
  9539. const text = await this.pdfPage.getTextContent();
  9540. const items = [];
  9541. for (const item of text.items) {
  9542. items.push(item.str);
  9543. }
  9544. this.textHighlighter.setTextMapping(textDivs, items);
  9545. this.textHighlighter.enable();
  9546. }
  9547. _resetZoomLayer(removeFromDOM = false) {
  9548. if (!this.zoomLayer) {
  9549. return;
  9550. }
  9551. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9552. this.paintedViewportMap.delete(zoomLayerCanvas);
  9553. zoomLayerCanvas.width = 0;
  9554. zoomLayerCanvas.height = 0;
  9555. if (removeFromDOM) {
  9556. this.zoomLayer.remove();
  9557. }
  9558. this.zoomLayer = null;
  9559. }
  9560. reset({
  9561. keepZoomLayer = false,
  9562. keepAnnotationLayer = false,
  9563. keepXfaLayer = false
  9564. } = {}) {
  9565. this.cancelRendering({
  9566. keepAnnotationLayer,
  9567. keepXfaLayer
  9568. });
  9569. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9570. const div = this.div;
  9571. div.style.width = Math.floor(this.viewport.width) + "px";
  9572. div.style.height = Math.floor(this.viewport.height) + "px";
  9573. const childNodes = div.childNodes,
  9574. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  9575. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  9576. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null;
  9577. for (let i = childNodes.length - 1; i >= 0; i--) {
  9578. const node = childNodes[i];
  9579. switch (node) {
  9580. case zoomLayerNode:
  9581. case annotationLayerNode:
  9582. case xfaLayerNode:
  9583. continue;
  9584. }
  9585. node.remove();
  9586. }
  9587. div.removeAttribute("data-loaded");
  9588. if (annotationLayerNode) {
  9589. this.annotationLayer.hide();
  9590. }
  9591. if (xfaLayerNode) {
  9592. this.xfaLayer.hide();
  9593. }
  9594. if (!zoomLayerNode) {
  9595. if (this.canvas) {
  9596. this.paintedViewportMap.delete(this.canvas);
  9597. this.canvas.width = 0;
  9598. this.canvas.height = 0;
  9599. delete this.canvas;
  9600. }
  9601. this._resetZoomLayer();
  9602. }
  9603. if (this.svg) {
  9604. this.paintedViewportMap.delete(this.svg);
  9605. delete this.svg;
  9606. }
  9607. this.loadingIconDiv = document.createElement("div");
  9608. this.loadingIconDiv.className = "loadingIcon notVisible";
  9609. if (this._isStandalone) {
  9610. this.toggleLoadingIconSpinner(true);
  9611. }
  9612. this.loadingIconDiv.setAttribute("role", "img");
  9613. this.l10n.get("loading").then(msg => {
  9614. this.loadingIconDiv?.setAttribute("aria-label", msg);
  9615. });
  9616. div.appendChild(this.loadingIconDiv);
  9617. }
  9618. update({
  9619. scale = 0,
  9620. rotation = null,
  9621. optionalContentConfigPromise = null
  9622. }) {
  9623. if (typeof arguments[0] !== "object") {
  9624. console.error("PDFPageView.update called with separate parameters, please use an object instead.");
  9625. this.update({
  9626. scale: arguments[0],
  9627. rotation: arguments[1],
  9628. optionalContentConfigPromise: arguments[2]
  9629. });
  9630. return;
  9631. }
  9632. this.scale = scale || this.scale;
  9633. if (typeof rotation === "number") {
  9634. this.rotation = rotation;
  9635. }
  9636. if (optionalContentConfigPromise instanceof Promise) {
  9637. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9638. }
  9639. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9640. const viewportScale = this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9641. this.viewport = this.viewport.clone({
  9642. scale: viewportScale,
  9643. rotation: totalRotation
  9644. });
  9645. if (this._isStandalone) {
  9646. const {
  9647. style
  9648. } = document.documentElement;
  9649. style.setProperty("--zoom-factor", this.scale);
  9650. style.setProperty("--viewport-scale-factor", viewportScale);
  9651. }
  9652. if (this.svg) {
  9653. this.cssTransform({
  9654. target: this.svg,
  9655. redrawAnnotationLayer: true,
  9656. redrawXfaLayer: true
  9657. });
  9658. this.eventBus.dispatch("pagerendered", {
  9659. source: this,
  9660. pageNumber: this.id,
  9661. cssTransform: true,
  9662. timestamp: performance.now(),
  9663. error: this._renderError
  9664. });
  9665. return;
  9666. }
  9667. let isScalingRestricted = false;
  9668. if (this.canvas && this.maxCanvasPixels > 0) {
  9669. const outputScale = this.outputScale;
  9670. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  9671. isScalingRestricted = true;
  9672. }
  9673. }
  9674. if (this.canvas) {
  9675. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  9676. this.cssTransform({
  9677. target: this.canvas,
  9678. redrawAnnotationLayer: true,
  9679. redrawXfaLayer: true
  9680. });
  9681. this.eventBus.dispatch("pagerendered", {
  9682. source: this,
  9683. pageNumber: this.id,
  9684. cssTransform: true,
  9685. timestamp: performance.now(),
  9686. error: this._renderError
  9687. });
  9688. return;
  9689. }
  9690. if (!this.zoomLayer && !this.canvas.hidden) {
  9691. this.zoomLayer = this.canvas.parentNode;
  9692. this.zoomLayer.style.position = "absolute";
  9693. }
  9694. }
  9695. if (this.zoomLayer) {
  9696. this.cssTransform({
  9697. target: this.zoomLayer.firstChild
  9698. });
  9699. }
  9700. this.reset({
  9701. keepZoomLayer: true,
  9702. keepAnnotationLayer: true,
  9703. keepXfaLayer: true
  9704. });
  9705. }
  9706. cancelRendering({
  9707. keepAnnotationLayer = false,
  9708. keepXfaLayer = false
  9709. } = {}) {
  9710. if (this.paintTask) {
  9711. this.paintTask.cancel();
  9712. this.paintTask = null;
  9713. }
  9714. this.resume = null;
  9715. if (this.textLayer) {
  9716. this.textLayer.cancel();
  9717. this.textLayer = null;
  9718. }
  9719. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  9720. this.annotationLayer.cancel();
  9721. this.annotationLayer = null;
  9722. this._annotationCanvasMap = null;
  9723. }
  9724. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  9725. this.xfaLayer.cancel();
  9726. this.xfaLayer = null;
  9727. this.textHighlighter?.disable();
  9728. }
  9729. if (this._onTextLayerRendered) {
  9730. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9731. this._onTextLayerRendered = null;
  9732. }
  9733. }
  9734. cssTransform({
  9735. target,
  9736. redrawAnnotationLayer = false,
  9737. redrawXfaLayer = false
  9738. }) {
  9739. const width = this.viewport.width;
  9740. const height = this.viewport.height;
  9741. const div = this.div;
  9742. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  9743. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  9744. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  9745. const absRotation = Math.abs(relativeRotation);
  9746. let scaleX = 1,
  9747. scaleY = 1;
  9748. if (absRotation === 90 || absRotation === 270) {
  9749. scaleX = height / width;
  9750. scaleY = width / height;
  9751. }
  9752. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  9753. if (this.textLayer) {
  9754. const textLayerViewport = this.textLayer.viewport;
  9755. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  9756. const textAbsRotation = Math.abs(textRelativeRotation);
  9757. let scale = width / textLayerViewport.width;
  9758. if (textAbsRotation === 90 || textAbsRotation === 270) {
  9759. scale = width / textLayerViewport.height;
  9760. }
  9761. const textLayerDiv = this.textLayer.textLayerDiv;
  9762. let transX, transY;
  9763. switch (textAbsRotation) {
  9764. case 0:
  9765. transX = transY = 0;
  9766. break;
  9767. case 90:
  9768. transX = 0;
  9769. transY = "-" + textLayerDiv.style.height;
  9770. break;
  9771. case 180:
  9772. transX = "-" + textLayerDiv.style.width;
  9773. transY = "-" + textLayerDiv.style.height;
  9774. break;
  9775. case 270:
  9776. transX = "-" + textLayerDiv.style.width;
  9777. transY = 0;
  9778. break;
  9779. default:
  9780. console.error("Bad rotation value.");
  9781. break;
  9782. }
  9783. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  9784. textLayerDiv.style.transformOrigin = "0% 0%";
  9785. }
  9786. if (redrawAnnotationLayer && this.annotationLayer) {
  9787. this._renderAnnotationLayer();
  9788. }
  9789. if (redrawXfaLayer && this.xfaLayer) {
  9790. this._renderXfaLayer();
  9791. }
  9792. }
  9793. get width() {
  9794. return this.viewport.width;
  9795. }
  9796. get height() {
  9797. return this.viewport.height;
  9798. }
  9799. getPagePoint(x, y) {
  9800. return this.viewport.convertToPdfPoint(x, y);
  9801. }
  9802. toggleLoadingIconSpinner(viewVisible = false) {
  9803. this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
  9804. }
  9805. draw() {
  9806. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  9807. console.error("Must be in new state before drawing");
  9808. this.reset();
  9809. }
  9810. const {
  9811. div,
  9812. pdfPage
  9813. } = this;
  9814. if (!pdfPage) {
  9815. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9816. if (this.loadingIconDiv) {
  9817. this.loadingIconDiv.remove();
  9818. delete this.loadingIconDiv;
  9819. }
  9820. return Promise.reject(new Error("pdfPage is not loaded"));
  9821. }
  9822. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  9823. const canvasWrapper = document.createElement("div");
  9824. canvasWrapper.style.width = div.style.width;
  9825. canvasWrapper.style.height = div.style.height;
  9826. canvasWrapper.classList.add("canvasWrapper");
  9827. if (this.annotationLayer?.div) {
  9828. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  9829. } else {
  9830. div.appendChild(canvasWrapper);
  9831. }
  9832. let textLayer = null;
  9833. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  9834. const textLayerDiv = document.createElement("div");
  9835. textLayerDiv.className = "textLayer";
  9836. textLayerDiv.style.width = canvasWrapper.style.width;
  9837. textLayerDiv.style.height = canvasWrapper.style.height;
  9838. if (this.annotationLayer?.div) {
  9839. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  9840. } else {
  9841. div.appendChild(textLayerDiv);
  9842. }
  9843. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus, this.textHighlighter);
  9844. }
  9845. this.textLayer = textLayer;
  9846. if (this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE && this.annotationLayerFactory) {
  9847. this._annotationCanvasMap ||= new Map();
  9848. this.annotationLayer ||= this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS, this.l10n, null, null, null, null, this._annotationCanvasMap);
  9849. }
  9850. if (this.xfaLayer?.div) {
  9851. div.appendChild(this.xfaLayer.div);
  9852. }
  9853. let renderContinueCallback = null;
  9854. if (this.renderingQueue) {
  9855. renderContinueCallback = cont => {
  9856. if (!this.renderingQueue.isHighestPriority(this)) {
  9857. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  9858. this.resume = () => {
  9859. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  9860. cont();
  9861. };
  9862. return;
  9863. }
  9864. cont();
  9865. };
  9866. }
  9867. const finishPaintTask = async (error = null) => {
  9868. if (paintTask === this.paintTask) {
  9869. this.paintTask = null;
  9870. }
  9871. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  9872. this._renderError = null;
  9873. return;
  9874. }
  9875. this._renderError = error;
  9876. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9877. if (this.loadingIconDiv) {
  9878. this.loadingIconDiv.remove();
  9879. delete this.loadingIconDiv;
  9880. }
  9881. this._resetZoomLayer(true);
  9882. this.eventBus.dispatch("pagerendered", {
  9883. source: this,
  9884. pageNumber: this.id,
  9885. cssTransform: false,
  9886. timestamp: performance.now(),
  9887. error: this._renderError
  9888. });
  9889. if (error) {
  9890. throw error;
  9891. }
  9892. };
  9893. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  9894. paintTask.onRenderContinue = renderContinueCallback;
  9895. this.paintTask = paintTask;
  9896. const resultPromise = paintTask.promise.then(() => {
  9897. return finishPaintTask(null).then(() => {
  9898. if (textLayer) {
  9899. const readableStream = pdfPage.streamTextContent({
  9900. includeMarkedContent: true
  9901. });
  9902. textLayer.setTextContentStream(readableStream);
  9903. textLayer.render();
  9904. }
  9905. if (this.annotationLayer) {
  9906. this._renderAnnotationLayer();
  9907. }
  9908. });
  9909. }, function (reason) {
  9910. return finishPaintTask(reason);
  9911. });
  9912. if (this.xfaLayerFactory) {
  9913. if (!this.xfaLayer) {
  9914. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage, null);
  9915. }
  9916. this._renderXfaLayer();
  9917. }
  9918. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  9919. this._onTextLayerRendered = event => {
  9920. if (event.pageNumber !== this.id) {
  9921. return;
  9922. }
  9923. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9924. this._onTextLayerRendered = null;
  9925. if (!this.canvas) {
  9926. return;
  9927. }
  9928. this.pdfPage.getStructTree().then(tree => {
  9929. if (!tree) {
  9930. return;
  9931. }
  9932. if (!this.canvas) {
  9933. return;
  9934. }
  9935. const treeDom = this.structTreeLayer.render(tree);
  9936. treeDom.classList.add("structTree");
  9937. this.canvas.appendChild(treeDom);
  9938. });
  9939. };
  9940. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  9941. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder(pdfPage);
  9942. }
  9943. div.setAttribute("data-loaded", true);
  9944. this.eventBus.dispatch("pagerender", {
  9945. source: this,
  9946. pageNumber: this.id
  9947. });
  9948. return resultPromise;
  9949. }
  9950. paintOnCanvas(canvasWrapper) {
  9951. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  9952. const result = {
  9953. promise: renderCapability.promise,
  9954. onRenderContinue(cont) {
  9955. cont();
  9956. },
  9957. cancel() {
  9958. renderTask.cancel();
  9959. }
  9960. };
  9961. const viewport = this.viewport;
  9962. const canvas = document.createElement("canvas");
  9963. canvas.hidden = true;
  9964. let isCanvasHidden = true;
  9965. const showCanvas = function () {
  9966. if (isCanvasHidden) {
  9967. canvas.hidden = false;
  9968. isCanvasHidden = false;
  9969. }
  9970. };
  9971. canvasWrapper.appendChild(canvas);
  9972. this.canvas = canvas;
  9973. canvas.mozOpaque = true;
  9974. const ctx = canvas.getContext("2d", {
  9975. alpha: false
  9976. });
  9977. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  9978. if (this.useOnlyCssZoom) {
  9979. const actualSizeViewport = viewport.clone({
  9980. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  9981. });
  9982. outputScale.sx *= actualSizeViewport.width / viewport.width;
  9983. outputScale.sy *= actualSizeViewport.height / viewport.height;
  9984. }
  9985. if (this.maxCanvasPixels > 0) {
  9986. const pixelsInViewport = viewport.width * viewport.height;
  9987. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  9988. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  9989. outputScale.sx = maxScale;
  9990. outputScale.sy = maxScale;
  9991. this.hasRestrictedScaling = true;
  9992. } else {
  9993. this.hasRestrictedScaling = false;
  9994. }
  9995. }
  9996. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  9997. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  9998. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  9999. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  10000. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  10001. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  10002. this.paintedViewportMap.set(canvas, viewport);
  10003. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10004. const renderContext = {
  10005. canvasContext: ctx,
  10006. transform,
  10007. viewport: this.viewport,
  10008. annotationMode: this.#annotationMode,
  10009. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10010. annotationCanvasMap: this._annotationCanvasMap
  10011. };
  10012. const renderTask = this.pdfPage.render(renderContext);
  10013. renderTask.onContinue = function (cont) {
  10014. showCanvas();
  10015. if (result.onRenderContinue) {
  10016. result.onRenderContinue(cont);
  10017. } else {
  10018. cont();
  10019. }
  10020. };
  10021. renderTask.promise.then(function () {
  10022. showCanvas();
  10023. renderCapability.resolve();
  10024. }, function (error) {
  10025. showCanvas();
  10026. renderCapability.reject(error);
  10027. });
  10028. return result;
  10029. }
  10030. paintOnSvg(wrapper) {
  10031. let cancelled = false;
  10032. const ensureNotCancelled = () => {
  10033. if (cancelled) {
  10034. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  10035. }
  10036. };
  10037. const pdfPage = this.pdfPage;
  10038. const actualSizeViewport = this.viewport.clone({
  10039. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10040. });
  10041. const promise = pdfPage.getOperatorList({
  10042. annotationMode: this.#annotationMode
  10043. }).then(opList => {
  10044. ensureNotCancelled();
  10045. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  10046. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  10047. ensureNotCancelled();
  10048. this.svg = svg;
  10049. this.paintedViewportMap.set(svg, actualSizeViewport);
  10050. svg.style.width = wrapper.style.width;
  10051. svg.style.height = wrapper.style.height;
  10052. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10053. wrapper.appendChild(svg);
  10054. });
  10055. });
  10056. return {
  10057. promise,
  10058. onRenderContinue(cont) {
  10059. cont();
  10060. },
  10061. cancel() {
  10062. cancelled = true;
  10063. }
  10064. };
  10065. }
  10066. setPageLabel(label) {
  10067. this.pageLabel = typeof label === "string" ? label : null;
  10068. if (this.pageLabel !== null) {
  10069. this.div.setAttribute("data-page-label", this.pageLabel);
  10070. } else {
  10071. this.div.removeAttribute("data-page-label");
  10072. }
  10073. }
  10074. }
  10075. exports.PDFPageView = PDFPageView;
  10076. /***/ }),
  10077. /* 32 */
  10078. /***/ ((__unused_webpack_module, exports) => {
  10079. Object.defineProperty(exports, "__esModule", ({
  10080. value: true
  10081. }));
  10082. exports.StructTreeLayerBuilder = void 0;
  10083. const PDF_ROLE_TO_HTML_ROLE = {
  10084. Document: null,
  10085. DocumentFragment: null,
  10086. Part: "group",
  10087. Sect: "group",
  10088. Div: "group",
  10089. Aside: "note",
  10090. NonStruct: "none",
  10091. P: null,
  10092. H: "heading",
  10093. Title: null,
  10094. FENote: "note",
  10095. Sub: "group",
  10096. Lbl: null,
  10097. Span: null,
  10098. Em: null,
  10099. Strong: null,
  10100. Link: "link",
  10101. Annot: "note",
  10102. Form: "form",
  10103. Ruby: null,
  10104. RB: null,
  10105. RT: null,
  10106. RP: null,
  10107. Warichu: null,
  10108. WT: null,
  10109. WP: null,
  10110. L: "list",
  10111. LI: "listitem",
  10112. LBody: null,
  10113. Table: "table",
  10114. TR: "row",
  10115. TH: "columnheader",
  10116. TD: "cell",
  10117. THead: "columnheader",
  10118. TBody: null,
  10119. TFoot: null,
  10120. Caption: null,
  10121. Figure: "figure",
  10122. Formula: null,
  10123. Artifact: null
  10124. };
  10125. const HEADING_PATTERN = /^H(\d+)$/;
  10126. class StructTreeLayerBuilder {
  10127. constructor({
  10128. pdfPage
  10129. }) {
  10130. this.pdfPage = pdfPage;
  10131. }
  10132. render(structTree) {
  10133. return this._walk(structTree);
  10134. }
  10135. _setAttributes(structElement, htmlElement) {
  10136. if (structElement.alt !== undefined) {
  10137. htmlElement.setAttribute("aria-label", structElement.alt);
  10138. }
  10139. if (structElement.id !== undefined) {
  10140. htmlElement.setAttribute("aria-owns", structElement.id);
  10141. }
  10142. if (structElement.lang !== undefined) {
  10143. htmlElement.setAttribute("lang", structElement.lang);
  10144. }
  10145. }
  10146. _walk(node) {
  10147. if (!node) {
  10148. return null;
  10149. }
  10150. const element = document.createElement("span");
  10151. if ("role" in node) {
  10152. const {
  10153. role
  10154. } = node;
  10155. const match = role.match(HEADING_PATTERN);
  10156. if (match) {
  10157. element.setAttribute("role", "heading");
  10158. element.setAttribute("aria-level", match[1]);
  10159. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10160. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10161. }
  10162. }
  10163. this._setAttributes(node, element);
  10164. if (node.children) {
  10165. if (node.children.length === 1 && "id" in node.children[0]) {
  10166. this._setAttributes(node.children[0], element);
  10167. } else {
  10168. for (const kid of node.children) {
  10169. element.appendChild(this._walk(kid));
  10170. }
  10171. }
  10172. }
  10173. return element;
  10174. }
  10175. }
  10176. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10177. /***/ }),
  10178. /* 33 */
  10179. /***/ ((__unused_webpack_module, exports) => {
  10180. Object.defineProperty(exports, "__esModule", ({
  10181. value: true
  10182. }));
  10183. exports.TextHighlighter = void 0;
  10184. class TextHighlighter {
  10185. constructor({
  10186. findController,
  10187. eventBus,
  10188. pageIndex
  10189. }) {
  10190. this.findController = findController;
  10191. this.matches = [];
  10192. this.eventBus = eventBus;
  10193. this.pageIdx = pageIndex;
  10194. this._onUpdateTextLayerMatches = null;
  10195. this.textDivs = null;
  10196. this.textContentItemsStr = null;
  10197. this.enabled = false;
  10198. }
  10199. setTextMapping(divs, texts) {
  10200. this.textDivs = divs;
  10201. this.textContentItemsStr = texts;
  10202. }
  10203. enable() {
  10204. if (!this.textDivs || !this.textContentItemsStr) {
  10205. throw new Error("Text divs and strings have not been set.");
  10206. }
  10207. if (this.enabled) {
  10208. throw new Error("TextHighlighter is already enabled.");
  10209. }
  10210. this.enabled = true;
  10211. if (!this._onUpdateTextLayerMatches) {
  10212. this._onUpdateTextLayerMatches = evt => {
  10213. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  10214. this._updateMatches();
  10215. }
  10216. };
  10217. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10218. }
  10219. this._updateMatches();
  10220. }
  10221. disable() {
  10222. if (!this.enabled) {
  10223. return;
  10224. }
  10225. this.enabled = false;
  10226. if (this._onUpdateTextLayerMatches) {
  10227. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10228. this._onUpdateTextLayerMatches = null;
  10229. }
  10230. }
  10231. _convertMatches(matches, matchesLength) {
  10232. if (!matches) {
  10233. return [];
  10234. }
  10235. const {
  10236. textContentItemsStr
  10237. } = this;
  10238. let i = 0,
  10239. iIndex = 0;
  10240. const end = textContentItemsStr.length - 1;
  10241. const result = [];
  10242. for (let m = 0, mm = matches.length; m < mm; m++) {
  10243. let matchIdx = matches[m];
  10244. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  10245. iIndex += textContentItemsStr[i].length;
  10246. i++;
  10247. }
  10248. if (i === textContentItemsStr.length) {
  10249. console.error("Could not find a matching mapping");
  10250. }
  10251. const match = {
  10252. begin: {
  10253. divIdx: i,
  10254. offset: matchIdx - iIndex
  10255. }
  10256. };
  10257. matchIdx += matchesLength[m];
  10258. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  10259. iIndex += textContentItemsStr[i].length;
  10260. i++;
  10261. }
  10262. match.end = {
  10263. divIdx: i,
  10264. offset: matchIdx - iIndex
  10265. };
  10266. result.push(match);
  10267. }
  10268. return result;
  10269. }
  10270. _renderMatches(matches) {
  10271. if (matches.length === 0) {
  10272. return;
  10273. }
  10274. const {
  10275. findController,
  10276. pageIdx
  10277. } = this;
  10278. const {
  10279. textContentItemsStr,
  10280. textDivs
  10281. } = this;
  10282. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  10283. const selectedMatchIdx = findController.selected.matchIdx;
  10284. const highlightAll = findController.state.highlightAll;
  10285. let prevEnd = null;
  10286. const infinity = {
  10287. divIdx: -1,
  10288. offset: undefined
  10289. };
  10290. function beginText(begin, className) {
  10291. const divIdx = begin.divIdx;
  10292. textDivs[divIdx].textContent = "";
  10293. return appendTextToDiv(divIdx, 0, begin.offset, className);
  10294. }
  10295. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  10296. let div = textDivs[divIdx];
  10297. if (div.nodeType === Node.TEXT_NODE) {
  10298. const span = document.createElement("span");
  10299. div.parentNode.insertBefore(span, div);
  10300. span.appendChild(div);
  10301. textDivs[divIdx] = span;
  10302. div = span;
  10303. }
  10304. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  10305. const node = document.createTextNode(content);
  10306. if (className) {
  10307. const span = document.createElement("span");
  10308. span.className = `${className} appended`;
  10309. span.appendChild(node);
  10310. div.appendChild(span);
  10311. return className.includes("selected") ? span.offsetLeft : 0;
  10312. }
  10313. div.appendChild(node);
  10314. return 0;
  10315. }
  10316. let i0 = selectedMatchIdx,
  10317. i1 = i0 + 1;
  10318. if (highlightAll) {
  10319. i0 = 0;
  10320. i1 = matches.length;
  10321. } else if (!isSelectedPage) {
  10322. return;
  10323. }
  10324. for (let i = i0; i < i1; i++) {
  10325. const match = matches[i];
  10326. const begin = match.begin;
  10327. const end = match.end;
  10328. const isSelected = isSelectedPage && i === selectedMatchIdx;
  10329. const highlightSuffix = isSelected ? " selected" : "";
  10330. let selectedLeft = 0;
  10331. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  10332. if (prevEnd !== null) {
  10333. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10334. }
  10335. beginText(begin);
  10336. } else {
  10337. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  10338. }
  10339. if (begin.divIdx === end.divIdx) {
  10340. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  10341. } else {
  10342. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  10343. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  10344. textDivs[n0].className = "highlight middle" + highlightSuffix;
  10345. }
  10346. beginText(end, "highlight end" + highlightSuffix);
  10347. }
  10348. prevEnd = end;
  10349. if (isSelected) {
  10350. findController.scrollMatchIntoView({
  10351. element: textDivs[begin.divIdx],
  10352. selectedLeft,
  10353. pageIndex: pageIdx,
  10354. matchIndex: selectedMatchIdx
  10355. });
  10356. }
  10357. }
  10358. if (prevEnd) {
  10359. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10360. }
  10361. }
  10362. _updateMatches() {
  10363. if (!this.enabled) {
  10364. return;
  10365. }
  10366. const {
  10367. findController,
  10368. matches,
  10369. pageIdx
  10370. } = this;
  10371. const {
  10372. textContentItemsStr,
  10373. textDivs
  10374. } = this;
  10375. let clearedUntilDivIdx = -1;
  10376. for (let i = 0, ii = matches.length; i < ii; i++) {
  10377. const match = matches[i];
  10378. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  10379. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  10380. const div = textDivs[n];
  10381. div.textContent = textContentItemsStr[n];
  10382. div.className = "";
  10383. }
  10384. clearedUntilDivIdx = match.end.divIdx + 1;
  10385. }
  10386. if (!findController?.highlightMatches) {
  10387. return;
  10388. }
  10389. const pageMatches = findController.pageMatches[pageIdx] || null;
  10390. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  10391. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  10392. this._renderMatches(this.matches);
  10393. }
  10394. }
  10395. exports.TextHighlighter = TextHighlighter;
  10396. /***/ }),
  10397. /* 34 */
  10398. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10399. Object.defineProperty(exports, "__esModule", ({
  10400. value: true
  10401. }));
  10402. exports.TextLayerBuilder = void 0;
  10403. var _pdfjsLib = __webpack_require__(5);
  10404. const EXPAND_DIVS_TIMEOUT = 300;
  10405. class TextLayerBuilder {
  10406. constructor({
  10407. textLayerDiv,
  10408. eventBus,
  10409. pageIndex,
  10410. viewport,
  10411. highlighter = null,
  10412. enhanceTextSelection = false
  10413. }) {
  10414. this.textLayerDiv = textLayerDiv;
  10415. this.eventBus = eventBus;
  10416. this.textContent = null;
  10417. this.textContentItemsStr = [];
  10418. this.textContentStream = null;
  10419. this.renderingDone = false;
  10420. this.pageNumber = pageIndex + 1;
  10421. this.viewport = viewport;
  10422. this.textDivs = [];
  10423. this.textLayerRenderTask = null;
  10424. this.highlighter = highlighter;
  10425. this.enhanceTextSelection = enhanceTextSelection;
  10426. this._bindMouse();
  10427. }
  10428. _finishRendering() {
  10429. this.renderingDone = true;
  10430. if (!this.enhanceTextSelection) {
  10431. const endOfContent = document.createElement("div");
  10432. endOfContent.className = "endOfContent";
  10433. this.textLayerDiv.appendChild(endOfContent);
  10434. }
  10435. this.eventBus.dispatch("textlayerrendered", {
  10436. source: this,
  10437. pageNumber: this.pageNumber,
  10438. numTextDivs: this.textDivs.length
  10439. });
  10440. }
  10441. render(timeout = 0) {
  10442. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  10443. return;
  10444. }
  10445. this.cancel();
  10446. this.textDivs.length = 0;
  10447. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  10448. const textLayerFrag = document.createDocumentFragment();
  10449. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  10450. textContent: this.textContent,
  10451. textContentStream: this.textContentStream,
  10452. container: textLayerFrag,
  10453. viewport: this.viewport,
  10454. textDivs: this.textDivs,
  10455. textContentItemsStr: this.textContentItemsStr,
  10456. timeout,
  10457. enhanceTextSelection: this.enhanceTextSelection
  10458. });
  10459. this.textLayerRenderTask.promise.then(() => {
  10460. this.textLayerDiv.appendChild(textLayerFrag);
  10461. this._finishRendering();
  10462. this.highlighter?.enable();
  10463. }, function (reason) {});
  10464. }
  10465. cancel() {
  10466. if (this.textLayerRenderTask) {
  10467. this.textLayerRenderTask.cancel();
  10468. this.textLayerRenderTask = null;
  10469. }
  10470. this.highlighter?.disable();
  10471. }
  10472. setTextContentStream(readableStream) {
  10473. this.cancel();
  10474. this.textContentStream = readableStream;
  10475. }
  10476. setTextContent(textContent) {
  10477. this.cancel();
  10478. this.textContent = textContent;
  10479. }
  10480. _bindMouse() {
  10481. const div = this.textLayerDiv;
  10482. let expandDivsTimer = null;
  10483. div.addEventListener("mousedown", evt => {
  10484. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10485. this.textLayerRenderTask.expandTextDivs(true);
  10486. if (expandDivsTimer) {
  10487. clearTimeout(expandDivsTimer);
  10488. expandDivsTimer = null;
  10489. }
  10490. return;
  10491. }
  10492. const end = div.querySelector(".endOfContent");
  10493. if (!end) {
  10494. return;
  10495. }
  10496. let adjustTop = evt.target !== div;
  10497. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  10498. if (adjustTop) {
  10499. const divBounds = div.getBoundingClientRect();
  10500. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  10501. end.style.top = (r * 100).toFixed(2) + "%";
  10502. }
  10503. end.classList.add("active");
  10504. });
  10505. div.addEventListener("mouseup", () => {
  10506. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10507. expandDivsTimer = setTimeout(() => {
  10508. if (this.textLayerRenderTask) {
  10509. this.textLayerRenderTask.expandTextDivs(false);
  10510. }
  10511. expandDivsTimer = null;
  10512. }, EXPAND_DIVS_TIMEOUT);
  10513. return;
  10514. }
  10515. const end = div.querySelector(".endOfContent");
  10516. if (!end) {
  10517. return;
  10518. }
  10519. end.style.top = "";
  10520. end.classList.remove("active");
  10521. });
  10522. }
  10523. }
  10524. exports.TextLayerBuilder = TextLayerBuilder;
  10525. /***/ }),
  10526. /* 35 */
  10527. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10528. Object.defineProperty(exports, "__esModule", ({
  10529. value: true
  10530. }));
  10531. exports.XfaLayerBuilder = void 0;
  10532. var _pdfjsLib = __webpack_require__(5);
  10533. class XfaLayerBuilder {
  10534. constructor({
  10535. pageDiv,
  10536. pdfPage,
  10537. annotationStorage = null,
  10538. linkService,
  10539. xfaHtml = null
  10540. }) {
  10541. this.pageDiv = pageDiv;
  10542. this.pdfPage = pdfPage;
  10543. this.annotationStorage = annotationStorage;
  10544. this.linkService = linkService;
  10545. this.xfaHtml = xfaHtml;
  10546. this.div = null;
  10547. this._cancelled = false;
  10548. }
  10549. render(viewport, intent = "display") {
  10550. if (intent === "print") {
  10551. const parameters = {
  10552. viewport: viewport.clone({
  10553. dontFlip: true
  10554. }),
  10555. div: this.div,
  10556. xfaHtml: this.xfaHtml,
  10557. annotationStorage: this.annotationStorage,
  10558. linkService: this.linkService,
  10559. intent
  10560. };
  10561. const div = document.createElement("div");
  10562. this.pageDiv.appendChild(div);
  10563. parameters.div = div;
  10564. const result = _pdfjsLib.XfaLayer.render(parameters);
  10565. return Promise.resolve(result);
  10566. }
  10567. return this.pdfPage.getXfa().then(xfaHtml => {
  10568. if (this._cancelled || !xfaHtml) {
  10569. return {
  10570. textDivs: []
  10571. };
  10572. }
  10573. const parameters = {
  10574. viewport: viewport.clone({
  10575. dontFlip: true
  10576. }),
  10577. div: this.div,
  10578. xfaHtml,
  10579. annotationStorage: this.annotationStorage,
  10580. linkService: this.linkService,
  10581. intent
  10582. };
  10583. if (this.div) {
  10584. return _pdfjsLib.XfaLayer.update(parameters);
  10585. }
  10586. this.div = document.createElement("div");
  10587. this.pageDiv.appendChild(this.div);
  10588. parameters.div = this.div;
  10589. return _pdfjsLib.XfaLayer.render(parameters);
  10590. }).catch(error => {
  10591. console.error(error);
  10592. });
  10593. }
  10594. cancel() {
  10595. this._cancelled = true;
  10596. }
  10597. hide() {
  10598. if (!this.div) {
  10599. return;
  10600. }
  10601. this.div.hidden = true;
  10602. }
  10603. }
  10604. exports.XfaLayerBuilder = XfaLayerBuilder;
  10605. /***/ }),
  10606. /* 36 */
  10607. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10608. Object.defineProperty(exports, "__esModule", ({
  10609. value: true
  10610. }));
  10611. exports.SecondaryToolbar = void 0;
  10612. var _ui_utils = __webpack_require__(3);
  10613. var _pdf_cursor_tools = __webpack_require__(6);
  10614. var _base_viewer = __webpack_require__(28);
  10615. class SecondaryToolbar {
  10616. constructor(options, mainContainer, eventBus) {
  10617. this.toolbar = options.toolbar;
  10618. this.toggleButton = options.toggleButton;
  10619. this.toolbarButtonContainer = options.toolbarButtonContainer;
  10620. this.buttons = [{
  10621. element: options.presentationModeButton,
  10622. eventName: "presentationmode",
  10623. close: true
  10624. }, {
  10625. element: options.openFileButton,
  10626. eventName: "openfile",
  10627. close: true
  10628. }, {
  10629. element: options.printButton,
  10630. eventName: "print",
  10631. close: true
  10632. }, {
  10633. element: options.downloadButton,
  10634. eventName: "download",
  10635. close: true
  10636. }, {
  10637. element: options.viewBookmarkButton,
  10638. eventName: null,
  10639. close: true
  10640. }, {
  10641. element: options.firstPageButton,
  10642. eventName: "firstpage",
  10643. close: true
  10644. }, {
  10645. element: options.lastPageButton,
  10646. eventName: "lastpage",
  10647. close: true
  10648. }, {
  10649. element: options.pageRotateCwButton,
  10650. eventName: "rotatecw",
  10651. close: false
  10652. }, {
  10653. element: options.pageRotateCcwButton,
  10654. eventName: "rotateccw",
  10655. close: false
  10656. }, {
  10657. element: options.cursorSelectToolButton,
  10658. eventName: "switchcursortool",
  10659. eventDetails: {
  10660. tool: _pdf_cursor_tools.CursorTool.SELECT
  10661. },
  10662. close: true
  10663. }, {
  10664. element: options.cursorHandToolButton,
  10665. eventName: "switchcursortool",
  10666. eventDetails: {
  10667. tool: _pdf_cursor_tools.CursorTool.HAND
  10668. },
  10669. close: true
  10670. }, {
  10671. element: options.scrollPageButton,
  10672. eventName: "switchscrollmode",
  10673. eventDetails: {
  10674. mode: _ui_utils.ScrollMode.PAGE
  10675. },
  10676. close: true
  10677. }, {
  10678. element: options.scrollVerticalButton,
  10679. eventName: "switchscrollmode",
  10680. eventDetails: {
  10681. mode: _ui_utils.ScrollMode.VERTICAL
  10682. },
  10683. close: true
  10684. }, {
  10685. element: options.scrollHorizontalButton,
  10686. eventName: "switchscrollmode",
  10687. eventDetails: {
  10688. mode: _ui_utils.ScrollMode.HORIZONTAL
  10689. },
  10690. close: true
  10691. }, {
  10692. element: options.scrollWrappedButton,
  10693. eventName: "switchscrollmode",
  10694. eventDetails: {
  10695. mode: _ui_utils.ScrollMode.WRAPPED
  10696. },
  10697. close: true
  10698. }, {
  10699. element: options.spreadNoneButton,
  10700. eventName: "switchspreadmode",
  10701. eventDetails: {
  10702. mode: _ui_utils.SpreadMode.NONE
  10703. },
  10704. close: true
  10705. }, {
  10706. element: options.spreadOddButton,
  10707. eventName: "switchspreadmode",
  10708. eventDetails: {
  10709. mode: _ui_utils.SpreadMode.ODD
  10710. },
  10711. close: true
  10712. }, {
  10713. element: options.spreadEvenButton,
  10714. eventName: "switchspreadmode",
  10715. eventDetails: {
  10716. mode: _ui_utils.SpreadMode.EVEN
  10717. },
  10718. close: true
  10719. }, {
  10720. element: options.documentPropertiesButton,
  10721. eventName: "documentproperties",
  10722. close: true
  10723. }];
  10724. this.items = {
  10725. firstPage: options.firstPageButton,
  10726. lastPage: options.lastPageButton,
  10727. pageRotateCw: options.pageRotateCwButton,
  10728. pageRotateCcw: options.pageRotateCcwButton
  10729. };
  10730. this.mainContainer = mainContainer;
  10731. this.eventBus = eventBus;
  10732. this.opened = false;
  10733. this.containerHeight = null;
  10734. this.previousContainerHeight = null;
  10735. this.reset();
  10736. this._bindClickListeners();
  10737. this._bindCursorToolsListener(options);
  10738. this._bindScrollModeListener(options);
  10739. this._bindSpreadModeListener(options);
  10740. this.eventBus._on("resize", this._setMaxHeight.bind(this));
  10741. }
  10742. get isOpen() {
  10743. return this.opened;
  10744. }
  10745. setPageNumber(pageNumber) {
  10746. this.pageNumber = pageNumber;
  10747. this._updateUIState();
  10748. }
  10749. setPagesCount(pagesCount) {
  10750. this.pagesCount = pagesCount;
  10751. this._updateUIState();
  10752. }
  10753. reset() {
  10754. this.pageNumber = 0;
  10755. this.pagesCount = 0;
  10756. this._updateUIState();
  10757. this.eventBus.dispatch("secondarytoolbarreset", {
  10758. source: this
  10759. });
  10760. }
  10761. _updateUIState() {
  10762. this.items.firstPage.disabled = this.pageNumber <= 1;
  10763. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  10764. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  10765. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  10766. }
  10767. _bindClickListeners() {
  10768. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  10769. for (const {
  10770. element,
  10771. eventName,
  10772. close,
  10773. eventDetails
  10774. } of this.buttons) {
  10775. element.addEventListener("click", evt => {
  10776. if (eventName !== null) {
  10777. const details = {
  10778. source: this
  10779. };
  10780. for (const property in eventDetails) {
  10781. details[property] = eventDetails[property];
  10782. }
  10783. this.eventBus.dispatch(eventName, details);
  10784. }
  10785. if (close) {
  10786. this.close();
  10787. }
  10788. });
  10789. }
  10790. }
  10791. _bindCursorToolsListener(buttons) {
  10792. this.eventBus._on("cursortoolchanged", function ({
  10793. tool
  10794. }) {
  10795. buttons.cursorSelectToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.SELECT);
  10796. buttons.cursorHandToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.HAND);
  10797. });
  10798. }
  10799. _bindScrollModeListener(buttons) {
  10800. const scrollModeChanged = ({
  10801. mode
  10802. }) => {
  10803. buttons.scrollPageButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.PAGE);
  10804. buttons.scrollVerticalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.VERTICAL);
  10805. buttons.scrollHorizontalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.HORIZONTAL);
  10806. buttons.scrollWrappedButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.WRAPPED);
  10807. const forceScrollModePage = this.pagesCount > _base_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  10808. buttons.scrollPageButton.disabled = forceScrollModePage;
  10809. buttons.scrollVerticalButton.disabled = forceScrollModePage;
  10810. buttons.scrollHorizontalButton.disabled = forceScrollModePage;
  10811. buttons.scrollWrappedButton.disabled = forceScrollModePage;
  10812. const isScrollModeHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  10813. buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
  10814. buttons.spreadOddButton.disabled = isScrollModeHorizontal;
  10815. buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
  10816. };
  10817. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  10818. this.eventBus._on("secondarytoolbarreset", evt => {
  10819. if (evt.source === this) {
  10820. scrollModeChanged({
  10821. mode: _ui_utils.ScrollMode.VERTICAL
  10822. });
  10823. }
  10824. });
  10825. }
  10826. _bindSpreadModeListener(buttons) {
  10827. function spreadModeChanged({
  10828. mode
  10829. }) {
  10830. buttons.spreadNoneButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.NONE);
  10831. buttons.spreadOddButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.ODD);
  10832. buttons.spreadEvenButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.EVEN);
  10833. }
  10834. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  10835. this.eventBus._on("secondarytoolbarreset", evt => {
  10836. if (evt.source === this) {
  10837. spreadModeChanged({
  10838. mode: _ui_utils.SpreadMode.NONE
  10839. });
  10840. }
  10841. });
  10842. }
  10843. open() {
  10844. if (this.opened) {
  10845. return;
  10846. }
  10847. this.opened = true;
  10848. this._setMaxHeight();
  10849. this.toggleButton.classList.add("toggled");
  10850. this.toggleButton.setAttribute("aria-expanded", "true");
  10851. this.toolbar.classList.remove("hidden");
  10852. }
  10853. close() {
  10854. if (!this.opened) {
  10855. return;
  10856. }
  10857. this.opened = false;
  10858. this.toolbar.classList.add("hidden");
  10859. this.toggleButton.classList.remove("toggled");
  10860. this.toggleButton.setAttribute("aria-expanded", "false");
  10861. }
  10862. toggle() {
  10863. if (this.opened) {
  10864. this.close();
  10865. } else {
  10866. this.open();
  10867. }
  10868. }
  10869. _setMaxHeight() {
  10870. if (!this.opened) {
  10871. return;
  10872. }
  10873. this.containerHeight = this.mainContainer.clientHeight;
  10874. if (this.containerHeight === this.previousContainerHeight) {
  10875. return;
  10876. }
  10877. this.toolbarButtonContainer.style.maxHeight = `${this.containerHeight - _ui_utils.SCROLLBAR_PADDING}px`;
  10878. this.previousContainerHeight = this.containerHeight;
  10879. }
  10880. }
  10881. exports.SecondaryToolbar = SecondaryToolbar;
  10882. /***/ }),
  10883. /* 37 */
  10884. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10885. Object.defineProperty(exports, "__esModule", ({
  10886. value: true
  10887. }));
  10888. exports.Toolbar = void 0;
  10889. var _ui_utils = __webpack_require__(3);
  10890. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  10891. class Toolbar {
  10892. constructor(options, eventBus, l10n) {
  10893. this.toolbar = options.container;
  10894. this.eventBus = eventBus;
  10895. this.l10n = l10n;
  10896. this.buttons = [{
  10897. element: options.previous,
  10898. eventName: "previouspage"
  10899. }, {
  10900. element: options.next,
  10901. eventName: "nextpage"
  10902. }, {
  10903. element: options.zoomIn,
  10904. eventName: "zoomin"
  10905. }, {
  10906. element: options.zoomOut,
  10907. eventName: "zoomout"
  10908. }, {
  10909. element: options.openFile,
  10910. eventName: "openfile"
  10911. }, {
  10912. element: options.print,
  10913. eventName: "print"
  10914. }, {
  10915. element: options.presentationModeButton,
  10916. eventName: "presentationmode"
  10917. }, {
  10918. element: options.download,
  10919. eventName: "download"
  10920. }, {
  10921. element: options.viewBookmark,
  10922. eventName: null
  10923. }];
  10924. this.items = {
  10925. numPages: options.numPages,
  10926. pageNumber: options.pageNumber,
  10927. scaleSelect: options.scaleSelect,
  10928. customScaleOption: options.customScaleOption,
  10929. previous: options.previous,
  10930. next: options.next,
  10931. zoomIn: options.zoomIn,
  10932. zoomOut: options.zoomOut
  10933. };
  10934. this._wasLocalized = false;
  10935. this.reset();
  10936. this._bindListeners();
  10937. }
  10938. setPageNumber(pageNumber, pageLabel) {
  10939. this.pageNumber = pageNumber;
  10940. this.pageLabel = pageLabel;
  10941. this._updateUIState(false);
  10942. }
  10943. setPagesCount(pagesCount, hasPageLabels) {
  10944. this.pagesCount = pagesCount;
  10945. this.hasPageLabels = hasPageLabels;
  10946. this._updateUIState(true);
  10947. }
  10948. setPageScale(pageScaleValue, pageScale) {
  10949. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  10950. this.pageScale = pageScale;
  10951. this._updateUIState(false);
  10952. }
  10953. reset() {
  10954. this.pageNumber = 0;
  10955. this.pageLabel = null;
  10956. this.hasPageLabels = false;
  10957. this.pagesCount = 0;
  10958. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  10959. this.pageScale = _ui_utils.DEFAULT_SCALE;
  10960. this._updateUIState(true);
  10961. this.updateLoadingIndicatorState();
  10962. }
  10963. _bindListeners() {
  10964. const {
  10965. pageNumber,
  10966. scaleSelect
  10967. } = this.items;
  10968. const self = this;
  10969. for (const {
  10970. element,
  10971. eventName
  10972. } of this.buttons) {
  10973. element.addEventListener("click", evt => {
  10974. if (eventName !== null) {
  10975. this.eventBus.dispatch(eventName, {
  10976. source: this
  10977. });
  10978. }
  10979. });
  10980. }
  10981. pageNumber.addEventListener("click", function () {
  10982. this.select();
  10983. });
  10984. pageNumber.addEventListener("change", function () {
  10985. self.eventBus.dispatch("pagenumberchanged", {
  10986. source: self,
  10987. value: this.value
  10988. });
  10989. });
  10990. scaleSelect.addEventListener("change", function () {
  10991. if (this.value === "custom") {
  10992. return;
  10993. }
  10994. self.eventBus.dispatch("scalechanged", {
  10995. source: self,
  10996. value: this.value
  10997. });
  10998. });
  10999. scaleSelect.addEventListener("click", function (evt) {
  11000. const target = evt.target;
  11001. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11002. this.blur();
  11003. }
  11004. });
  11005. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  11006. this.eventBus._on("localized", () => {
  11007. this._wasLocalized = true;
  11008. this._adjustScaleWidth();
  11009. this._updateUIState(true);
  11010. });
  11011. }
  11012. _updateUIState(resetNumPages = false) {
  11013. if (!this._wasLocalized) {
  11014. return;
  11015. }
  11016. const {
  11017. pageNumber,
  11018. pagesCount,
  11019. pageScaleValue,
  11020. pageScale,
  11021. items
  11022. } = this;
  11023. if (resetNumPages) {
  11024. if (this.hasPageLabels) {
  11025. items.pageNumber.type = "text";
  11026. } else {
  11027. items.pageNumber.type = "number";
  11028. this.l10n.get("of_pages", {
  11029. pagesCount
  11030. }).then(msg => {
  11031. items.numPages.textContent = msg;
  11032. });
  11033. }
  11034. items.pageNumber.max = pagesCount;
  11035. }
  11036. if (this.hasPageLabels) {
  11037. items.pageNumber.value = this.pageLabel;
  11038. this.l10n.get("page_of_pages", {
  11039. pageNumber,
  11040. pagesCount
  11041. }).then(msg => {
  11042. items.numPages.textContent = msg;
  11043. });
  11044. } else {
  11045. items.pageNumber.value = pageNumber;
  11046. }
  11047. items.previous.disabled = pageNumber <= 1;
  11048. items.next.disabled = pageNumber >= pagesCount;
  11049. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  11050. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  11051. this.l10n.get("page_scale_percent", {
  11052. scale: Math.round(pageScale * 10000) / 100
  11053. }).then(msg => {
  11054. let predefinedValueFound = false;
  11055. for (const option of items.scaleSelect.options) {
  11056. if (option.value !== pageScaleValue) {
  11057. option.selected = false;
  11058. continue;
  11059. }
  11060. option.selected = true;
  11061. predefinedValueFound = true;
  11062. }
  11063. if (!predefinedValueFound) {
  11064. items.customScaleOption.textContent = msg;
  11065. items.customScaleOption.selected = true;
  11066. }
  11067. });
  11068. }
  11069. updateLoadingIndicatorState(loading = false) {
  11070. const pageNumberInput = this.items.pageNumber;
  11071. pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  11072. }
  11073. async _adjustScaleWidth() {
  11074. const {
  11075. items,
  11076. l10n
  11077. } = this;
  11078. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  11079. const style = getComputedStyle(items.scaleSelect),
  11080. scaleSelectContainerWidth = parseInt(style.getPropertyValue("--scale-select-container-width"), 10),
  11081. scaleSelectOverflow = parseInt(style.getPropertyValue("--scale-select-overflow"), 10);
  11082. let canvas = document.createElement("canvas");
  11083. canvas.mozOpaque = true;
  11084. let ctx = canvas.getContext("2d", {
  11085. alpha: false
  11086. });
  11087. await _ui_utils.animationStarted;
  11088. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  11089. let maxWidth = 0;
  11090. for (const predefinedValue of await predefinedValuesPromise) {
  11091. const {
  11092. width
  11093. } = ctx.measureText(predefinedValue);
  11094. if (width > maxWidth) {
  11095. maxWidth = width;
  11096. }
  11097. }
  11098. maxWidth += 2 * scaleSelectOverflow;
  11099. if (maxWidth > scaleSelectContainerWidth) {
  11100. const doc = document.documentElement;
  11101. doc.style.setProperty("--scale-select-container-width", `${maxWidth}px`);
  11102. }
  11103. canvas.width = 0;
  11104. canvas.height = 0;
  11105. canvas = ctx = null;
  11106. }
  11107. }
  11108. exports.Toolbar = Toolbar;
  11109. /***/ }),
  11110. /* 38 */
  11111. /***/ ((__unused_webpack_module, exports) => {
  11112. Object.defineProperty(exports, "__esModule", ({
  11113. value: true
  11114. }));
  11115. exports.ViewHistory = void 0;
  11116. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  11117. class ViewHistory {
  11118. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  11119. this.fingerprint = fingerprint;
  11120. this.cacheSize = cacheSize;
  11121. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  11122. const database = JSON.parse(databaseStr || "{}");
  11123. let index = -1;
  11124. if (!Array.isArray(database.files)) {
  11125. database.files = [];
  11126. } else {
  11127. while (database.files.length >= this.cacheSize) {
  11128. database.files.shift();
  11129. }
  11130. for (let i = 0, ii = database.files.length; i < ii; i++) {
  11131. const branch = database.files[i];
  11132. if (branch.fingerprint === this.fingerprint) {
  11133. index = i;
  11134. break;
  11135. }
  11136. }
  11137. }
  11138. if (index === -1) {
  11139. index = database.files.push({
  11140. fingerprint: this.fingerprint
  11141. }) - 1;
  11142. }
  11143. this.file = database.files[index];
  11144. this.database = database;
  11145. });
  11146. }
  11147. async _writeToStorage() {
  11148. const databaseStr = JSON.stringify(this.database);
  11149. localStorage.setItem("pdfjs.history", databaseStr);
  11150. }
  11151. async _readFromStorage() {
  11152. return localStorage.getItem("pdfjs.history");
  11153. }
  11154. async set(name, val) {
  11155. await this._initializedPromise;
  11156. this.file[name] = val;
  11157. return this._writeToStorage();
  11158. }
  11159. async setMultiple(properties) {
  11160. await this._initializedPromise;
  11161. for (const name in properties) {
  11162. this.file[name] = properties[name];
  11163. }
  11164. return this._writeToStorage();
  11165. }
  11166. async get(name, defaultValue) {
  11167. await this._initializedPromise;
  11168. const val = this.file[name];
  11169. return val !== undefined ? val : defaultValue;
  11170. }
  11171. async getMultiple(properties) {
  11172. await this._initializedPromise;
  11173. const values = Object.create(null);
  11174. for (const name in properties) {
  11175. const val = this.file[name];
  11176. values[name] = val !== undefined ? val : properties[name];
  11177. }
  11178. return values;
  11179. }
  11180. }
  11181. exports.ViewHistory = ViewHistory;
  11182. /***/ }),
  11183. /* 39 */
  11184. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11185. Object.defineProperty(exports, "__esModule", ({
  11186. value: true
  11187. }));
  11188. exports.GenericCom = void 0;
  11189. var _app = __webpack_require__(2);
  11190. var _preferences = __webpack_require__(40);
  11191. var _download_manager = __webpack_require__(41);
  11192. var _genericl10n = __webpack_require__(42);
  11193. var _generic_scripting = __webpack_require__(44);
  11194. ;
  11195. const GenericCom = {};
  11196. exports.GenericCom = GenericCom;
  11197. class GenericPreferences extends _preferences.BasePreferences {
  11198. async _writeToStorage(prefObj) {
  11199. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  11200. }
  11201. async _readFromStorage(prefObj) {
  11202. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  11203. }
  11204. }
  11205. class GenericExternalServices extends _app.DefaultExternalServices {
  11206. static createDownloadManager(options) {
  11207. return new _download_manager.DownloadManager();
  11208. }
  11209. static createPreferences() {
  11210. return new GenericPreferences();
  11211. }
  11212. static createL10n({
  11213. locale = "en-US"
  11214. }) {
  11215. return new _genericl10n.GenericL10n(locale);
  11216. }
  11217. static createScripting({
  11218. sandboxBundleSrc
  11219. }) {
  11220. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  11221. }
  11222. }
  11223. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  11224. /***/ }),
  11225. /* 40 */
  11226. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11227. Object.defineProperty(exports, "__esModule", ({
  11228. value: true
  11229. }));
  11230. exports.BasePreferences = void 0;
  11231. var _app_options = __webpack_require__(1);
  11232. class BasePreferences {
  11233. constructor() {
  11234. if (this.constructor === BasePreferences) {
  11235. throw new Error("Cannot initialize BasePreferences.");
  11236. }
  11237. Object.defineProperty(this, "defaults", {
  11238. value: Object.freeze({
  11239. "annotationMode": 2,
  11240. "cursorToolOnLoad": 0,
  11241. "defaultZoomValue": "",
  11242. "disablePageLabels": false,
  11243. "enablePermissions": false,
  11244. "enablePrintAutoRotate": true,
  11245. "enableScripting": true,
  11246. "externalLinkTarget": 0,
  11247. "historyUpdateUrl": false,
  11248. "ignoreDestinationZoom": false,
  11249. "pdfBugEnabled": false,
  11250. "renderer": "canvas",
  11251. "sidebarViewOnLoad": -1,
  11252. "scrollModeOnLoad": -1,
  11253. "spreadModeOnLoad": -1,
  11254. "textLayerMode": 1,
  11255. "useOnlyCssZoom": false,
  11256. "viewerCssTheme": 0,
  11257. "viewOnLoad": 0,
  11258. "disableAutoFetch": false,
  11259. "disableFontFace": false,
  11260. "disableRange": false,
  11261. "disableStream": false,
  11262. "enableXfa": true
  11263. }),
  11264. writable: false,
  11265. enumerable: true,
  11266. configurable: false
  11267. });
  11268. this.prefs = Object.create(null);
  11269. this._initializedPromise = this._readFromStorage(this.defaults).then(prefs => {
  11270. for (const name in this.defaults) {
  11271. const prefValue = prefs?.[name];
  11272. if (typeof prefValue === typeof this.defaults[name]) {
  11273. this.prefs[name] = prefValue;
  11274. }
  11275. }
  11276. });
  11277. }
  11278. async _writeToStorage(prefObj) {
  11279. throw new Error("Not implemented: _writeToStorage");
  11280. }
  11281. async _readFromStorage(prefObj) {
  11282. throw new Error("Not implemented: _readFromStorage");
  11283. }
  11284. async reset() {
  11285. await this._initializedPromise;
  11286. this.prefs = Object.create(null);
  11287. return this._writeToStorage(this.defaults);
  11288. }
  11289. async set(name, value) {
  11290. await this._initializedPromise;
  11291. const defaultValue = this.defaults[name];
  11292. if (defaultValue === undefined) {
  11293. throw new Error(`Set preference: "${name}" is undefined.`);
  11294. } else if (value === undefined) {
  11295. throw new Error("Set preference: no value is specified.");
  11296. }
  11297. const valueType = typeof value;
  11298. const defaultType = typeof defaultValue;
  11299. if (valueType !== defaultType) {
  11300. if (valueType === "number" && defaultType === "string") {
  11301. value = value.toString();
  11302. } else {
  11303. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  11304. }
  11305. } else {
  11306. if (valueType === "number" && !Number.isInteger(value)) {
  11307. throw new Error(`Set preference: "${value}" must be an integer.`);
  11308. }
  11309. }
  11310. this.prefs[name] = value;
  11311. return this._writeToStorage(this.prefs);
  11312. }
  11313. async get(name) {
  11314. await this._initializedPromise;
  11315. const defaultValue = this.defaults[name],
  11316. prefValue = this.prefs[name];
  11317. if (defaultValue === undefined) {
  11318. throw new Error(`Get preference: "${name}" is undefined.`);
  11319. }
  11320. return prefValue !== undefined ? prefValue : defaultValue;
  11321. }
  11322. async getAll() {
  11323. await this._initializedPromise;
  11324. const obj = Object.create(null);
  11325. for (const name in this.defaults) {
  11326. const prefValue = this.prefs[name];
  11327. obj[name] = prefValue !== undefined ? prefValue : this.defaults[name];
  11328. }
  11329. return obj;
  11330. }
  11331. }
  11332. exports.BasePreferences = BasePreferences;
  11333. /***/ }),
  11334. /* 41 */
  11335. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11336. Object.defineProperty(exports, "__esModule", ({
  11337. value: true
  11338. }));
  11339. exports.DownloadManager = void 0;
  11340. var _pdfjsLib = __webpack_require__(5);
  11341. ;
  11342. function download(blobUrl, filename) {
  11343. const a = document.createElement("a");
  11344. if (!a.click) {
  11345. throw new Error('DownloadManager: "a.click()" is not supported.');
  11346. }
  11347. a.href = blobUrl;
  11348. a.target = "_parent";
  11349. if ("download" in a) {
  11350. a.download = filename;
  11351. }
  11352. (document.body || document.documentElement).appendChild(a);
  11353. a.click();
  11354. a.remove();
  11355. }
  11356. class DownloadManager {
  11357. constructor() {
  11358. this._openBlobUrls = new WeakMap();
  11359. }
  11360. downloadUrl(url, filename) {
  11361. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  11362. console.error(`downloadUrl - not a valid URL: ${url}`);
  11363. return;
  11364. }
  11365. download(url + "#pdfjs.action=download", filename);
  11366. }
  11367. downloadData(data, filename, contentType) {
  11368. const blobUrl = URL.createObjectURL(new Blob([data], {
  11369. type: contentType
  11370. }));
  11371. download(blobUrl, filename);
  11372. }
  11373. openOrDownloadData(element, data, filename) {
  11374. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  11375. const contentType = isPdfData ? "application/pdf" : "";
  11376. if (isPdfData) {
  11377. let blobUrl = this._openBlobUrls.get(element);
  11378. if (!blobUrl) {
  11379. blobUrl = URL.createObjectURL(new Blob([data], {
  11380. type: contentType
  11381. }));
  11382. this._openBlobUrls.set(element, blobUrl);
  11383. }
  11384. let viewerUrl;
  11385. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  11386. try {
  11387. window.open(viewerUrl);
  11388. return true;
  11389. } catch (ex) {
  11390. console.error(`openOrDownloadData: ${ex}`);
  11391. URL.revokeObjectURL(blobUrl);
  11392. this._openBlobUrls.delete(element);
  11393. }
  11394. }
  11395. this.downloadData(data, filename, contentType);
  11396. return false;
  11397. }
  11398. download(blob, url, filename, sourceEventType = "download") {
  11399. const blobUrl = URL.createObjectURL(blob);
  11400. download(blobUrl, filename);
  11401. }
  11402. }
  11403. exports.DownloadManager = DownloadManager;
  11404. /***/ }),
  11405. /* 42 */
  11406. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11407. Object.defineProperty(exports, "__esModule", ({
  11408. value: true
  11409. }));
  11410. exports.GenericL10n = void 0;
  11411. __webpack_require__(43);
  11412. var _l10n_utils = __webpack_require__(30);
  11413. const webL10n = document.webL10n;
  11414. class GenericL10n {
  11415. constructor(lang) {
  11416. this._lang = lang;
  11417. this._ready = new Promise((resolve, reject) => {
  11418. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  11419. resolve(webL10n);
  11420. });
  11421. });
  11422. }
  11423. async getLanguage() {
  11424. const l10n = await this._ready;
  11425. return l10n.getLanguage();
  11426. }
  11427. async getDirection() {
  11428. const l10n = await this._ready;
  11429. return l10n.getDirection();
  11430. }
  11431. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  11432. const l10n = await this._ready;
  11433. return l10n.get(key, args, fallback);
  11434. }
  11435. async translate(element) {
  11436. const l10n = await this._ready;
  11437. return l10n.translate(element);
  11438. }
  11439. }
  11440. exports.GenericL10n = GenericL10n;
  11441. /***/ }),
  11442. /* 43 */
  11443. /***/ (() => {
  11444. document.webL10n = function (window, document, undefined) {
  11445. var gL10nData = {};
  11446. var gTextData = '';
  11447. var gTextProp = 'textContent';
  11448. var gLanguage = '';
  11449. var gMacros = {};
  11450. var gReadyState = 'loading';
  11451. var gAsyncResourceLoading = true;
  11452. function getL10nResourceLinks() {
  11453. return document.querySelectorAll('link[type="application/l10n"]');
  11454. }
  11455. function getL10nDictionary() {
  11456. var script = document.querySelector('script[type="application/l10n"]');
  11457. return script ? JSON.parse(script.innerHTML) : null;
  11458. }
  11459. function getTranslatableChildren(element) {
  11460. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  11461. }
  11462. function getL10nAttributes(element) {
  11463. if (!element) return {};
  11464. var l10nId = element.getAttribute('data-l10n-id');
  11465. var l10nArgs = element.getAttribute('data-l10n-args');
  11466. var args = {};
  11467. if (l10nArgs) {
  11468. try {
  11469. args = JSON.parse(l10nArgs);
  11470. } catch (e) {
  11471. console.warn('could not parse arguments for #' + l10nId);
  11472. }
  11473. }
  11474. return {
  11475. id: l10nId,
  11476. args: args
  11477. };
  11478. }
  11479. function xhrLoadText(url, onSuccess, onFailure) {
  11480. onSuccess = onSuccess || function _onSuccess(data) {};
  11481. onFailure = onFailure || function _onFailure() {};
  11482. var xhr = new XMLHttpRequest();
  11483. xhr.open('GET', url, gAsyncResourceLoading);
  11484. if (xhr.overrideMimeType) {
  11485. xhr.overrideMimeType('text/plain; charset=utf-8');
  11486. }
  11487. xhr.onreadystatechange = function () {
  11488. if (xhr.readyState == 4) {
  11489. if (xhr.status == 200 || xhr.status === 0) {
  11490. onSuccess(xhr.responseText);
  11491. } else {
  11492. onFailure();
  11493. }
  11494. }
  11495. };
  11496. xhr.onerror = onFailure;
  11497. xhr.ontimeout = onFailure;
  11498. try {
  11499. xhr.send(null);
  11500. } catch (e) {
  11501. onFailure();
  11502. }
  11503. }
  11504. function parseResource(href, lang, successCallback, failureCallback) {
  11505. var baseURL = href.replace(/[^\/]*$/, '') || './';
  11506. function evalString(text) {
  11507. if (text.lastIndexOf('\\') < 0) return text;
  11508. 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, "'");
  11509. }
  11510. function parseProperties(text, parsedPropertiesCallback) {
  11511. var dictionary = {};
  11512. var reBlank = /^\s*|\s*$/;
  11513. var reComment = /^\s*#|^\s*$/;
  11514. var reSection = /^\s*\[(.*)\]\s*$/;
  11515. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  11516. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  11517. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  11518. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  11519. var currentLang = '*';
  11520. var genericLang = lang.split('-', 1)[0];
  11521. var skipLang = false;
  11522. var match = '';
  11523. function nextEntry() {
  11524. while (true) {
  11525. if (!entries.length) {
  11526. parsedRawLinesCallback();
  11527. return;
  11528. }
  11529. var line = entries.shift();
  11530. if (reComment.test(line)) continue;
  11531. if (extendedSyntax) {
  11532. match = reSection.exec(line);
  11533. if (match) {
  11534. currentLang = match[1].toLowerCase();
  11535. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  11536. continue;
  11537. } else if (skipLang) {
  11538. continue;
  11539. }
  11540. match = reImport.exec(line);
  11541. if (match) {
  11542. loadImport(baseURL + match[1], nextEntry);
  11543. return;
  11544. }
  11545. }
  11546. var tmp = line.match(reSplit);
  11547. if (tmp && tmp.length == 3) {
  11548. dictionary[tmp[1]] = evalString(tmp[2]);
  11549. }
  11550. }
  11551. }
  11552. nextEntry();
  11553. }
  11554. function loadImport(url, callback) {
  11555. xhrLoadText(url, function (content) {
  11556. parseRawLines(content, false, callback);
  11557. }, function () {
  11558. console.warn(url + ' not found.');
  11559. callback();
  11560. });
  11561. }
  11562. parseRawLines(text, true, function () {
  11563. parsedPropertiesCallback(dictionary);
  11564. });
  11565. }
  11566. xhrLoadText(href, function (response) {
  11567. gTextData += response;
  11568. parseProperties(response, function (data) {
  11569. for (var key in data) {
  11570. var id,
  11571. prop,
  11572. index = key.lastIndexOf('.');
  11573. if (index > 0) {
  11574. id = key.substring(0, index);
  11575. prop = key.substring(index + 1);
  11576. } else {
  11577. id = key;
  11578. prop = gTextProp;
  11579. }
  11580. if (!gL10nData[id]) {
  11581. gL10nData[id] = {};
  11582. }
  11583. gL10nData[id][prop] = data[key];
  11584. }
  11585. if (successCallback) {
  11586. successCallback();
  11587. }
  11588. });
  11589. }, failureCallback);
  11590. }
  11591. function loadLocale(lang, callback) {
  11592. if (lang) {
  11593. lang = lang.toLowerCase();
  11594. }
  11595. callback = callback || function _callback() {};
  11596. clear();
  11597. gLanguage = lang;
  11598. var langLinks = getL10nResourceLinks();
  11599. var langCount = langLinks.length;
  11600. if (langCount === 0) {
  11601. var dict = getL10nDictionary();
  11602. if (dict && dict.locales && dict.default_locale) {
  11603. console.log('using the embedded JSON directory, early way out');
  11604. gL10nData = dict.locales[lang];
  11605. if (!gL10nData) {
  11606. var defaultLocale = dict.default_locale.toLowerCase();
  11607. for (var anyCaseLang in dict.locales) {
  11608. anyCaseLang = anyCaseLang.toLowerCase();
  11609. if (anyCaseLang === lang) {
  11610. gL10nData = dict.locales[lang];
  11611. break;
  11612. } else if (anyCaseLang === defaultLocale) {
  11613. gL10nData = dict.locales[defaultLocale];
  11614. }
  11615. }
  11616. }
  11617. callback();
  11618. } else {
  11619. console.log('no resource to load, early way out');
  11620. }
  11621. gReadyState = 'complete';
  11622. return;
  11623. }
  11624. var onResourceLoaded = null;
  11625. var gResourceCount = 0;
  11626. onResourceLoaded = function () {
  11627. gResourceCount++;
  11628. if (gResourceCount >= langCount) {
  11629. callback();
  11630. gReadyState = 'complete';
  11631. }
  11632. };
  11633. function L10nResourceLink(link) {
  11634. var href = link.href;
  11635. this.load = function (lang, callback) {
  11636. parseResource(href, lang, callback, function () {
  11637. console.warn(href + ' not found.');
  11638. console.warn('"' + lang + '" resource not found');
  11639. gLanguage = '';
  11640. callback();
  11641. });
  11642. };
  11643. }
  11644. for (var i = 0; i < langCount; i++) {
  11645. var resource = new L10nResourceLink(langLinks[i]);
  11646. resource.load(lang, onResourceLoaded);
  11647. }
  11648. }
  11649. function clear() {
  11650. gL10nData = {};
  11651. gTextData = '';
  11652. gLanguage = '';
  11653. }
  11654. function getPluralRules(lang) {
  11655. var locales2rules = {
  11656. 'af': 3,
  11657. 'ak': 4,
  11658. 'am': 4,
  11659. 'ar': 1,
  11660. 'asa': 3,
  11661. 'az': 0,
  11662. 'be': 11,
  11663. 'bem': 3,
  11664. 'bez': 3,
  11665. 'bg': 3,
  11666. 'bh': 4,
  11667. 'bm': 0,
  11668. 'bn': 3,
  11669. 'bo': 0,
  11670. 'br': 20,
  11671. 'brx': 3,
  11672. 'bs': 11,
  11673. 'ca': 3,
  11674. 'cgg': 3,
  11675. 'chr': 3,
  11676. 'cs': 12,
  11677. 'cy': 17,
  11678. 'da': 3,
  11679. 'de': 3,
  11680. 'dv': 3,
  11681. 'dz': 0,
  11682. 'ee': 3,
  11683. 'el': 3,
  11684. 'en': 3,
  11685. 'eo': 3,
  11686. 'es': 3,
  11687. 'et': 3,
  11688. 'eu': 3,
  11689. 'fa': 0,
  11690. 'ff': 5,
  11691. 'fi': 3,
  11692. 'fil': 4,
  11693. 'fo': 3,
  11694. 'fr': 5,
  11695. 'fur': 3,
  11696. 'fy': 3,
  11697. 'ga': 8,
  11698. 'gd': 24,
  11699. 'gl': 3,
  11700. 'gsw': 3,
  11701. 'gu': 3,
  11702. 'guw': 4,
  11703. 'gv': 23,
  11704. 'ha': 3,
  11705. 'haw': 3,
  11706. 'he': 2,
  11707. 'hi': 4,
  11708. 'hr': 11,
  11709. 'hu': 0,
  11710. 'id': 0,
  11711. 'ig': 0,
  11712. 'ii': 0,
  11713. 'is': 3,
  11714. 'it': 3,
  11715. 'iu': 7,
  11716. 'ja': 0,
  11717. 'jmc': 3,
  11718. 'jv': 0,
  11719. 'ka': 0,
  11720. 'kab': 5,
  11721. 'kaj': 3,
  11722. 'kcg': 3,
  11723. 'kde': 0,
  11724. 'kea': 0,
  11725. 'kk': 3,
  11726. 'kl': 3,
  11727. 'km': 0,
  11728. 'kn': 0,
  11729. 'ko': 0,
  11730. 'ksb': 3,
  11731. 'ksh': 21,
  11732. 'ku': 3,
  11733. 'kw': 7,
  11734. 'lag': 18,
  11735. 'lb': 3,
  11736. 'lg': 3,
  11737. 'ln': 4,
  11738. 'lo': 0,
  11739. 'lt': 10,
  11740. 'lv': 6,
  11741. 'mas': 3,
  11742. 'mg': 4,
  11743. 'mk': 16,
  11744. 'ml': 3,
  11745. 'mn': 3,
  11746. 'mo': 9,
  11747. 'mr': 3,
  11748. 'ms': 0,
  11749. 'mt': 15,
  11750. 'my': 0,
  11751. 'nah': 3,
  11752. 'naq': 7,
  11753. 'nb': 3,
  11754. 'nd': 3,
  11755. 'ne': 3,
  11756. 'nl': 3,
  11757. 'nn': 3,
  11758. 'no': 3,
  11759. 'nr': 3,
  11760. 'nso': 4,
  11761. 'ny': 3,
  11762. 'nyn': 3,
  11763. 'om': 3,
  11764. 'or': 3,
  11765. 'pa': 3,
  11766. 'pap': 3,
  11767. 'pl': 13,
  11768. 'ps': 3,
  11769. 'pt': 3,
  11770. 'rm': 3,
  11771. 'ro': 9,
  11772. 'rof': 3,
  11773. 'ru': 11,
  11774. 'rwk': 3,
  11775. 'sah': 0,
  11776. 'saq': 3,
  11777. 'se': 7,
  11778. 'seh': 3,
  11779. 'ses': 0,
  11780. 'sg': 0,
  11781. 'sh': 11,
  11782. 'shi': 19,
  11783. 'sk': 12,
  11784. 'sl': 14,
  11785. 'sma': 7,
  11786. 'smi': 7,
  11787. 'smj': 7,
  11788. 'smn': 7,
  11789. 'sms': 7,
  11790. 'sn': 3,
  11791. 'so': 3,
  11792. 'sq': 3,
  11793. 'sr': 11,
  11794. 'ss': 3,
  11795. 'ssy': 3,
  11796. 'st': 3,
  11797. 'sv': 3,
  11798. 'sw': 3,
  11799. 'syr': 3,
  11800. 'ta': 3,
  11801. 'te': 3,
  11802. 'teo': 3,
  11803. 'th': 0,
  11804. 'ti': 4,
  11805. 'tig': 3,
  11806. 'tk': 3,
  11807. 'tl': 4,
  11808. 'tn': 3,
  11809. 'to': 0,
  11810. 'tr': 0,
  11811. 'ts': 3,
  11812. 'tzm': 22,
  11813. 'uk': 11,
  11814. 'ur': 3,
  11815. 've': 3,
  11816. 'vi': 0,
  11817. 'vun': 3,
  11818. 'wa': 4,
  11819. 'wae': 3,
  11820. 'wo': 0,
  11821. 'xh': 3,
  11822. 'xog': 3,
  11823. 'yo': 0,
  11824. 'zh': 0,
  11825. 'zu': 3
  11826. };
  11827. function isIn(n, list) {
  11828. return list.indexOf(n) !== -1;
  11829. }
  11830. function isBetween(n, start, end) {
  11831. return start <= n && n <= end;
  11832. }
  11833. var pluralRules = {
  11834. '0': function (n) {
  11835. return 'other';
  11836. },
  11837. '1': function (n) {
  11838. if (isBetween(n % 100, 3, 10)) return 'few';
  11839. if (n === 0) return 'zero';
  11840. if (isBetween(n % 100, 11, 99)) return 'many';
  11841. if (n == 2) return 'two';
  11842. if (n == 1) return 'one';
  11843. return 'other';
  11844. },
  11845. '2': function (n) {
  11846. if (n !== 0 && n % 10 === 0) return 'many';
  11847. if (n == 2) return 'two';
  11848. if (n == 1) return 'one';
  11849. return 'other';
  11850. },
  11851. '3': function (n) {
  11852. if (n == 1) return 'one';
  11853. return 'other';
  11854. },
  11855. '4': function (n) {
  11856. if (isBetween(n, 0, 1)) return 'one';
  11857. return 'other';
  11858. },
  11859. '5': function (n) {
  11860. if (isBetween(n, 0, 2) && n != 2) return 'one';
  11861. return 'other';
  11862. },
  11863. '6': function (n) {
  11864. if (n === 0) return 'zero';
  11865. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11866. return 'other';
  11867. },
  11868. '7': function (n) {
  11869. if (n == 2) return 'two';
  11870. if (n == 1) return 'one';
  11871. return 'other';
  11872. },
  11873. '8': function (n) {
  11874. if (isBetween(n, 3, 6)) return 'few';
  11875. if (isBetween(n, 7, 10)) return 'many';
  11876. if (n == 2) return 'two';
  11877. if (n == 1) return 'one';
  11878. return 'other';
  11879. },
  11880. '9': function (n) {
  11881. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  11882. if (n == 1) return 'one';
  11883. return 'other';
  11884. },
  11885. '10': function (n) {
  11886. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  11887. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  11888. return 'other';
  11889. },
  11890. '11': function (n) {
  11891. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11892. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  11893. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11894. return 'other';
  11895. },
  11896. '12': function (n) {
  11897. if (isBetween(n, 2, 4)) return 'few';
  11898. if (n == 1) return 'one';
  11899. return 'other';
  11900. },
  11901. '13': function (n) {
  11902. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11903. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  11904. if (n == 1) return 'one';
  11905. return 'other';
  11906. },
  11907. '14': function (n) {
  11908. if (isBetween(n % 100, 3, 4)) return 'few';
  11909. if (n % 100 == 2) return 'two';
  11910. if (n % 100 == 1) return 'one';
  11911. return 'other';
  11912. },
  11913. '15': function (n) {
  11914. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  11915. if (isBetween(n % 100, 11, 19)) return 'many';
  11916. if (n == 1) return 'one';
  11917. return 'other';
  11918. },
  11919. '16': function (n) {
  11920. if (n % 10 == 1 && n != 11) return 'one';
  11921. return 'other';
  11922. },
  11923. '17': function (n) {
  11924. if (n == 3) return 'few';
  11925. if (n === 0) return 'zero';
  11926. if (n == 6) return 'many';
  11927. if (n == 2) return 'two';
  11928. if (n == 1) return 'one';
  11929. return 'other';
  11930. },
  11931. '18': function (n) {
  11932. if (n === 0) return 'zero';
  11933. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  11934. return 'other';
  11935. },
  11936. '19': function (n) {
  11937. if (isBetween(n, 2, 10)) return 'few';
  11938. if (isBetween(n, 0, 1)) return 'one';
  11939. return 'other';
  11940. },
  11941. '20': function (n) {
  11942. 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';
  11943. if (n % 1000000 === 0 && n !== 0) return 'many';
  11944. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  11945. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  11946. return 'other';
  11947. },
  11948. '21': function (n) {
  11949. if (n === 0) return 'zero';
  11950. if (n == 1) return 'one';
  11951. return 'other';
  11952. },
  11953. '22': function (n) {
  11954. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  11955. return 'other';
  11956. },
  11957. '23': function (n) {
  11958. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  11959. return 'other';
  11960. },
  11961. '24': function (n) {
  11962. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  11963. if (isIn(n, [2, 12])) return 'two';
  11964. if (isIn(n, [1, 11])) return 'one';
  11965. return 'other';
  11966. }
  11967. };
  11968. var index = locales2rules[lang.replace(/-.*$/, '')];
  11969. if (!(index in pluralRules)) {
  11970. console.warn('plural form unknown for [' + lang + ']');
  11971. return function () {
  11972. return 'other';
  11973. };
  11974. }
  11975. return pluralRules[index];
  11976. }
  11977. gMacros.plural = function (str, param, key, prop) {
  11978. var n = parseFloat(param);
  11979. if (isNaN(n)) return str;
  11980. if (prop != gTextProp) return str;
  11981. if (!gMacros._pluralRules) {
  11982. gMacros._pluralRules = getPluralRules(gLanguage);
  11983. }
  11984. var index = '[' + gMacros._pluralRules(n) + ']';
  11985. if (n === 0 && key + '[zero]' in gL10nData) {
  11986. str = gL10nData[key + '[zero]'][prop];
  11987. } else if (n == 1 && key + '[one]' in gL10nData) {
  11988. str = gL10nData[key + '[one]'][prop];
  11989. } else if (n == 2 && key + '[two]' in gL10nData) {
  11990. str = gL10nData[key + '[two]'][prop];
  11991. } else if (key + index in gL10nData) {
  11992. str = gL10nData[key + index][prop];
  11993. } else if (key + '[other]' in gL10nData) {
  11994. str = gL10nData[key + '[other]'][prop];
  11995. }
  11996. return str;
  11997. };
  11998. function getL10nData(key, args, fallback) {
  11999. var data = gL10nData[key];
  12000. if (!data) {
  12001. console.warn('#' + key + ' is undefined.');
  12002. if (!fallback) {
  12003. return null;
  12004. }
  12005. data = fallback;
  12006. }
  12007. var rv = {};
  12008. for (var prop in data) {
  12009. var str = data[prop];
  12010. str = substIndexes(str, args, key, prop);
  12011. str = substArguments(str, args, key);
  12012. rv[prop] = str;
  12013. }
  12014. return rv;
  12015. }
  12016. function substIndexes(str, args, key, prop) {
  12017. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  12018. var reMatch = reIndex.exec(str);
  12019. if (!reMatch || !reMatch.length) return str;
  12020. var macroName = reMatch[1];
  12021. var paramName = reMatch[2];
  12022. var param;
  12023. if (args && paramName in args) {
  12024. param = args[paramName];
  12025. } else if (paramName in gL10nData) {
  12026. param = gL10nData[paramName];
  12027. }
  12028. if (macroName in gMacros) {
  12029. var macro = gMacros[macroName];
  12030. str = macro(str, param, key, prop);
  12031. }
  12032. return str;
  12033. }
  12034. function substArguments(str, args, key) {
  12035. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  12036. return str.replace(reArgs, function (matched_text, arg) {
  12037. if (args && arg in args) {
  12038. return args[arg];
  12039. }
  12040. if (arg in gL10nData) {
  12041. return gL10nData[arg];
  12042. }
  12043. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  12044. return matched_text;
  12045. });
  12046. }
  12047. function translateElement(element) {
  12048. var l10n = getL10nAttributes(element);
  12049. if (!l10n.id) return;
  12050. var data = getL10nData(l10n.id, l10n.args);
  12051. if (!data) {
  12052. console.warn('#' + l10n.id + ' is undefined.');
  12053. return;
  12054. }
  12055. if (data[gTextProp]) {
  12056. if (getChildElementCount(element) === 0) {
  12057. element[gTextProp] = data[gTextProp];
  12058. } else {
  12059. var children = element.childNodes;
  12060. var found = false;
  12061. for (var i = 0, l = children.length; i < l; i++) {
  12062. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  12063. if (found) {
  12064. children[i].nodeValue = '';
  12065. } else {
  12066. children[i].nodeValue = data[gTextProp];
  12067. found = true;
  12068. }
  12069. }
  12070. }
  12071. if (!found) {
  12072. var textNode = document.createTextNode(data[gTextProp]);
  12073. element.insertBefore(textNode, element.firstChild);
  12074. }
  12075. }
  12076. delete data[gTextProp];
  12077. }
  12078. for (var k in data) {
  12079. element[k] = data[k];
  12080. }
  12081. }
  12082. function getChildElementCount(element) {
  12083. if (element.children) {
  12084. return element.children.length;
  12085. }
  12086. if (typeof element.childElementCount !== 'undefined') {
  12087. return element.childElementCount;
  12088. }
  12089. var count = 0;
  12090. for (var i = 0; i < element.childNodes.length; i++) {
  12091. count += element.nodeType === 1 ? 1 : 0;
  12092. }
  12093. return count;
  12094. }
  12095. function translateFragment(element) {
  12096. element = element || document.documentElement;
  12097. var children = getTranslatableChildren(element);
  12098. var elementCount = children.length;
  12099. for (var i = 0; i < elementCount; i++) {
  12100. translateElement(children[i]);
  12101. }
  12102. translateElement(element);
  12103. }
  12104. return {
  12105. get: function (key, args, fallbackString) {
  12106. var index = key.lastIndexOf('.');
  12107. var prop = gTextProp;
  12108. if (index > 0) {
  12109. prop = key.substring(index + 1);
  12110. key = key.substring(0, index);
  12111. }
  12112. var fallback;
  12113. if (fallbackString) {
  12114. fallback = {};
  12115. fallback[prop] = fallbackString;
  12116. }
  12117. var data = getL10nData(key, args, fallback);
  12118. if (data && prop in data) {
  12119. return data[prop];
  12120. }
  12121. return '{{' + key + '}}';
  12122. },
  12123. getData: function () {
  12124. return gL10nData;
  12125. },
  12126. getText: function () {
  12127. return gTextData;
  12128. },
  12129. getLanguage: function () {
  12130. return gLanguage;
  12131. },
  12132. setLanguage: function (lang, callback) {
  12133. loadLocale(lang, function () {
  12134. if (callback) callback();
  12135. });
  12136. },
  12137. getDirection: function () {
  12138. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  12139. var shortCode = gLanguage.split('-', 1)[0];
  12140. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  12141. },
  12142. translate: translateFragment,
  12143. getReadyState: function () {
  12144. return gReadyState;
  12145. },
  12146. ready: function (callback) {
  12147. if (!callback) {
  12148. return;
  12149. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  12150. window.setTimeout(function () {
  12151. callback();
  12152. });
  12153. } else if (document.addEventListener) {
  12154. document.addEventListener('localized', function once() {
  12155. document.removeEventListener('localized', once);
  12156. callback();
  12157. });
  12158. }
  12159. }
  12160. };
  12161. }(window, document);
  12162. /***/ }),
  12163. /* 44 */
  12164. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12165. Object.defineProperty(exports, "__esModule", ({
  12166. value: true
  12167. }));
  12168. exports.GenericScripting = void 0;
  12169. exports.docPropertiesLookup = docPropertiesLookup;
  12170. var _pdfjsLib = __webpack_require__(5);
  12171. async function docPropertiesLookup(pdfDocument) {
  12172. const url = "",
  12173. baseUrl = url.split("#")[0];
  12174. let {
  12175. info,
  12176. metadata,
  12177. contentDispositionFilename,
  12178. contentLength
  12179. } = await pdfDocument.getMetadata();
  12180. if (!contentLength) {
  12181. const {
  12182. length
  12183. } = await pdfDocument.getDownloadInfo();
  12184. contentLength = length;
  12185. }
  12186. return { ...info,
  12187. baseURL: baseUrl,
  12188. filesize: contentLength,
  12189. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  12190. metadata: metadata?.getRaw(),
  12191. authors: metadata?.get("dc:creator"),
  12192. numPages: pdfDocument.numPages,
  12193. URL: url
  12194. };
  12195. }
  12196. class GenericScripting {
  12197. constructor(sandboxBundleSrc) {
  12198. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  12199. return window.pdfjsSandbox.QuickJSSandbox();
  12200. });
  12201. }
  12202. async createSandbox(data) {
  12203. const sandbox = await this._ready;
  12204. sandbox.create(data);
  12205. }
  12206. async dispatchEventInSandbox(event) {
  12207. const sandbox = await this._ready;
  12208. setTimeout(() => sandbox.dispatchEvent(event), 0);
  12209. }
  12210. async destroySandbox() {
  12211. const sandbox = await this._ready;
  12212. sandbox.nukeSandbox();
  12213. }
  12214. }
  12215. exports.GenericScripting = GenericScripting;
  12216. /***/ }),
  12217. /* 45 */
  12218. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12219. Object.defineProperty(exports, "__esModule", ({
  12220. value: true
  12221. }));
  12222. exports.PDFPrintService = PDFPrintService;
  12223. var _pdfjsLib = __webpack_require__(5);
  12224. var _app = __webpack_require__(2);
  12225. var _print_utils = __webpack_require__(46);
  12226. let activeService = null;
  12227. let overlayManager = null;
  12228. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise) {
  12229. const scratchCanvas = activeService.scratchCanvas;
  12230. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  12231. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  12232. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  12233. const ctx = scratchCanvas.getContext("2d");
  12234. ctx.save();
  12235. ctx.fillStyle = "rgb(255, 255, 255)";
  12236. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  12237. ctx.restore();
  12238. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  12239. const renderContext = {
  12240. canvasContext: ctx,
  12241. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  12242. viewport: pdfPage.getViewport({
  12243. scale: 1,
  12244. rotation: size.rotation
  12245. }),
  12246. intent: "print",
  12247. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  12248. optionalContentConfigPromise
  12249. };
  12250. return pdfPage.render(renderContext).promise;
  12251. });
  12252. }
  12253. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, l10n) {
  12254. this.pdfDocument = pdfDocument;
  12255. this.pagesOverview = pagesOverview;
  12256. this.printContainer = printContainer;
  12257. this._printResolution = printResolution || 150;
  12258. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  12259. this.l10n = l10n;
  12260. this.currentPage = -1;
  12261. this.scratchCanvas = document.createElement("canvas");
  12262. }
  12263. PDFPrintService.prototype = {
  12264. layout() {
  12265. this.throwIfInactive();
  12266. const body = document.querySelector("body");
  12267. body.setAttribute("data-pdfjsprinting", true);
  12268. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  12269. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  12270. }, this);
  12271. if (!hasEqualPageSizes) {
  12272. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  12273. }
  12274. this.pageStyleSheet = document.createElement("style");
  12275. const pageSize = this.pagesOverview[0];
  12276. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  12277. body.appendChild(this.pageStyleSheet);
  12278. },
  12279. destroy() {
  12280. if (activeService !== this) {
  12281. return;
  12282. }
  12283. this.printContainer.textContent = "";
  12284. const body = document.querySelector("body");
  12285. body.removeAttribute("data-pdfjsprinting");
  12286. if (this.pageStyleSheet) {
  12287. this.pageStyleSheet.remove();
  12288. this.pageStyleSheet = null;
  12289. }
  12290. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  12291. this.scratchCanvas = null;
  12292. activeService = null;
  12293. ensureOverlay().then(function () {
  12294. if (overlayManager.active !== "printServiceOverlay") {
  12295. return;
  12296. }
  12297. overlayManager.close("printServiceOverlay");
  12298. });
  12299. },
  12300. renderPages() {
  12301. if (this.pdfDocument.isPureXfa) {
  12302. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  12303. return Promise.resolve();
  12304. }
  12305. const pageCount = this.pagesOverview.length;
  12306. const renderNextPage = (resolve, reject) => {
  12307. this.throwIfInactive();
  12308. if (++this.currentPage >= pageCount) {
  12309. renderProgress(pageCount, pageCount, this.l10n);
  12310. resolve();
  12311. return;
  12312. }
  12313. const index = this.currentPage;
  12314. renderProgress(index, pageCount, this.l10n);
  12315. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise).then(this.useRenderedPage.bind(this)).then(function () {
  12316. renderNextPage(resolve, reject);
  12317. }, reject);
  12318. };
  12319. return new Promise(renderNextPage);
  12320. },
  12321. useRenderedPage() {
  12322. this.throwIfInactive();
  12323. const img = document.createElement("img");
  12324. const scratchCanvas = this.scratchCanvas;
  12325. if ("toBlob" in scratchCanvas) {
  12326. scratchCanvas.toBlob(function (blob) {
  12327. img.src = URL.createObjectURL(blob);
  12328. });
  12329. } else {
  12330. img.src = scratchCanvas.toDataURL();
  12331. }
  12332. const wrapper = document.createElement("div");
  12333. wrapper.className = "printedPage";
  12334. wrapper.appendChild(img);
  12335. this.printContainer.appendChild(wrapper);
  12336. return new Promise(function (resolve, reject) {
  12337. img.onload = resolve;
  12338. img.onerror = reject;
  12339. });
  12340. },
  12341. performPrint() {
  12342. this.throwIfInactive();
  12343. return new Promise(resolve => {
  12344. setTimeout(() => {
  12345. if (!this.active) {
  12346. resolve();
  12347. return;
  12348. }
  12349. print.call(window);
  12350. setTimeout(resolve, 20);
  12351. }, 0);
  12352. });
  12353. },
  12354. get active() {
  12355. return this === activeService;
  12356. },
  12357. throwIfInactive() {
  12358. if (!this.active) {
  12359. throw new Error("This print request was cancelled or completed.");
  12360. }
  12361. }
  12362. };
  12363. const print = window.print;
  12364. window.print = function () {
  12365. if (activeService) {
  12366. console.warn("Ignored window.print() because of a pending print job.");
  12367. return;
  12368. }
  12369. ensureOverlay().then(function () {
  12370. if (activeService) {
  12371. overlayManager.open("printServiceOverlay");
  12372. }
  12373. });
  12374. try {
  12375. dispatchEvent("beforeprint");
  12376. } finally {
  12377. if (!activeService) {
  12378. console.error("Expected print service to be initialized.");
  12379. ensureOverlay().then(function () {
  12380. if (overlayManager.active === "printServiceOverlay") {
  12381. overlayManager.close("printServiceOverlay");
  12382. }
  12383. });
  12384. return;
  12385. }
  12386. const activeServiceOnEntry = activeService;
  12387. activeService.renderPages().then(function () {
  12388. return activeServiceOnEntry.performPrint();
  12389. }).catch(function () {}).then(function () {
  12390. if (activeServiceOnEntry.active) {
  12391. abort();
  12392. }
  12393. });
  12394. }
  12395. };
  12396. function dispatchEvent(eventType) {
  12397. const event = document.createEvent("CustomEvent");
  12398. event.initCustomEvent(eventType, false, false, "custom");
  12399. window.dispatchEvent(event);
  12400. }
  12401. function abort() {
  12402. if (activeService) {
  12403. activeService.destroy();
  12404. dispatchEvent("afterprint");
  12405. }
  12406. }
  12407. function renderProgress(index, total, l10n) {
  12408. const progressContainer = document.getElementById("printServiceOverlay");
  12409. const progress = Math.round(100 * index / total);
  12410. const progressBar = progressContainer.querySelector("progress");
  12411. const progressPerc = progressContainer.querySelector(".relative-progress");
  12412. progressBar.value = progress;
  12413. l10n.get("print_progress_percent", {
  12414. progress
  12415. }).then(msg => {
  12416. progressPerc.textContent = msg;
  12417. });
  12418. }
  12419. window.addEventListener("keydown", function (event) {
  12420. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  12421. window.print();
  12422. event.preventDefault();
  12423. if (event.stopImmediatePropagation) {
  12424. event.stopImmediatePropagation();
  12425. } else {
  12426. event.stopPropagation();
  12427. }
  12428. }
  12429. }, true);
  12430. if ("onbeforeprint" in window) {
  12431. const stopPropagationIfNeeded = function (event) {
  12432. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  12433. event.stopImmediatePropagation();
  12434. }
  12435. };
  12436. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  12437. window.addEventListener("afterprint", stopPropagationIfNeeded);
  12438. }
  12439. let overlayPromise;
  12440. function ensureOverlay() {
  12441. if (!overlayPromise) {
  12442. overlayManager = _app.PDFViewerApplication.overlayManager;
  12443. if (!overlayManager) {
  12444. throw new Error("The overlay manager has not yet been initialized.");
  12445. }
  12446. overlayPromise = overlayManager.register("printServiceOverlay", document.getElementById("printServiceOverlay"), abort, true);
  12447. document.getElementById("printCancel").onclick = abort;
  12448. }
  12449. return overlayPromise;
  12450. }
  12451. _app.PDFPrintServiceFactory.instance = {
  12452. supportsPrinting: true,
  12453. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n) {
  12454. if (activeService) {
  12455. throw new Error("The print service is created and active.");
  12456. }
  12457. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n);
  12458. return activeService;
  12459. }
  12460. };
  12461. /***/ }),
  12462. /* 46 */
  12463. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12464. Object.defineProperty(exports, "__esModule", ({
  12465. value: true
  12466. }));
  12467. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  12468. var _pdfjsLib = __webpack_require__(5);
  12469. var _pdf_link_service = __webpack_require__(8);
  12470. var _xfa_layer_builder = __webpack_require__(35);
  12471. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  12472. const xfaHtml = pdfDocument.allXfaHtml;
  12473. const linkService = new _pdf_link_service.SimpleLinkService();
  12474. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  12475. for (const xfaPage of xfaHtml.children) {
  12476. const page = document.createElement("div");
  12477. page.className = "xfaPrintedPage";
  12478. printContainer.appendChild(page);
  12479. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  12480. pageDiv: page,
  12481. pdfPage: null,
  12482. annotationStorage: pdfDocument.annotationStorage,
  12483. linkService,
  12484. xfaHtml: xfaPage
  12485. });
  12486. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  12487. scale
  12488. });
  12489. builder.render(viewport, "print");
  12490. }
  12491. }
  12492. /***/ })
  12493. /******/ ]);
  12494. /************************************************************************/
  12495. /******/ // The module cache
  12496. /******/ var __webpack_module_cache__ = {};
  12497. /******/
  12498. /******/ // The require function
  12499. /******/ function __webpack_require__(moduleId) {
  12500. /******/ // Check if module is in cache
  12501. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  12502. /******/ if (cachedModule !== undefined) {
  12503. /******/ return cachedModule.exports;
  12504. /******/ }
  12505. /******/ // Create a new module (and put it into the cache)
  12506. /******/ var module = __webpack_module_cache__[moduleId] = {
  12507. /******/ // no module.id needed
  12508. /******/ // no module.loaded needed
  12509. /******/ exports: {}
  12510. /******/ };
  12511. /******/
  12512. /******/ // Execute the module function
  12513. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  12514. /******/
  12515. /******/ // Return the exports of the module
  12516. /******/ return module.exports;
  12517. /******/ }
  12518. /******/
  12519. /************************************************************************/
  12520. var __webpack_exports__ = {};
  12521. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  12522. (() => {
  12523. var exports = __webpack_exports__;
  12524. Object.defineProperty(exports, "__esModule", ({
  12525. value: true
  12526. }));
  12527. Object.defineProperty(exports, "PDFViewerApplication", ({
  12528. enumerable: true,
  12529. get: function () {
  12530. return _app.PDFViewerApplication;
  12531. }
  12532. }));
  12533. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  12534. enumerable: true,
  12535. get: function () {
  12536. return _app_options.AppOptions;
  12537. }
  12538. }));
  12539. var _app_options = __webpack_require__(1);
  12540. var _app = __webpack_require__(2);
  12541. const pdfjsVersion = '2.13.216';
  12542. const pdfjsBuild = '399a0ec60';
  12543. window.PDFViewerApplication = _app.PDFViewerApplication;
  12544. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  12545. ;
  12546. ;
  12547. {
  12548. __webpack_require__(39);
  12549. }
  12550. ;
  12551. {
  12552. __webpack_require__(45);
  12553. }
  12554. function getViewerConfiguration() {
  12555. let errorWrapper = null;
  12556. errorWrapper = {
  12557. container: document.getElementById("errorWrapper"),
  12558. errorMessage: document.getElementById("errorMessage"),
  12559. closeButton: document.getElementById("errorClose"),
  12560. errorMoreInfo: document.getElementById("errorMoreInfo"),
  12561. moreInfoButton: document.getElementById("errorShowMore"),
  12562. lessInfoButton: document.getElementById("errorShowLess")
  12563. };
  12564. return {
  12565. appContainer: document.body,
  12566. mainContainer: document.getElementById("viewerContainer"),
  12567. viewerContainer: document.getElementById("viewer"),
  12568. toolbar: {
  12569. container: document.getElementById("toolbarViewer"),
  12570. numPages: document.getElementById("numPages"),
  12571. pageNumber: document.getElementById("pageNumber"),
  12572. scaleSelect: document.getElementById("scaleSelect"),
  12573. customScaleOption: document.getElementById("customScaleOption"),
  12574. previous: document.getElementById("previous"),
  12575. next: document.getElementById("next"),
  12576. zoomIn: document.getElementById("zoomIn"),
  12577. zoomOut: document.getElementById("zoomOut"),
  12578. viewFind: document.getElementById("viewFind"),
  12579. openFile: document.getElementById("openFile"),
  12580. print: document.getElementById("print"),
  12581. presentationModeButton: document.getElementById("presentationMode"),
  12582. download: document.getElementById("download"),
  12583. viewBookmark: document.getElementById("viewBookmark")
  12584. },
  12585. secondaryToolbar: {
  12586. toolbar: document.getElementById("secondaryToolbar"),
  12587. toggleButton: document.getElementById("secondaryToolbarToggle"),
  12588. toolbarButtonContainer: document.getElementById("secondaryToolbarButtonContainer"),
  12589. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  12590. openFileButton: document.getElementById("secondaryOpenFile"),
  12591. printButton: document.getElementById("secondaryPrint"),
  12592. downloadButton: document.getElementById("secondaryDownload"),
  12593. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  12594. firstPageButton: document.getElementById("firstPage"),
  12595. lastPageButton: document.getElementById("lastPage"),
  12596. pageRotateCwButton: document.getElementById("pageRotateCw"),
  12597. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  12598. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  12599. cursorHandToolButton: document.getElementById("cursorHandTool"),
  12600. scrollPageButton: document.getElementById("scrollPage"),
  12601. scrollVerticalButton: document.getElementById("scrollVertical"),
  12602. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  12603. scrollWrappedButton: document.getElementById("scrollWrapped"),
  12604. spreadNoneButton: document.getElementById("spreadNone"),
  12605. spreadOddButton: document.getElementById("spreadOdd"),
  12606. spreadEvenButton: document.getElementById("spreadEven"),
  12607. documentPropertiesButton: document.getElementById("documentProperties")
  12608. },
  12609. sidebar: {
  12610. outerContainer: document.getElementById("outerContainer"),
  12611. viewerContainer: document.getElementById("viewerContainer"),
  12612. toggleButton: document.getElementById("sidebarToggle"),
  12613. thumbnailButton: document.getElementById("viewThumbnail"),
  12614. outlineButton: document.getElementById("viewOutline"),
  12615. attachmentsButton: document.getElementById("viewAttachments"),
  12616. layersButton: document.getElementById("viewLayers"),
  12617. thumbnailView: document.getElementById("thumbnailView"),
  12618. outlineView: document.getElementById("outlineView"),
  12619. attachmentsView: document.getElementById("attachmentsView"),
  12620. layersView: document.getElementById("layersView"),
  12621. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  12622. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  12623. },
  12624. sidebarResizer: {
  12625. outerContainer: document.getElementById("outerContainer"),
  12626. resizer: document.getElementById("sidebarResizer")
  12627. },
  12628. findBar: {
  12629. bar: document.getElementById("findbar"),
  12630. toggleButton: document.getElementById("viewFind"),
  12631. findField: document.getElementById("findInput"),
  12632. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  12633. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  12634. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  12635. entireWordCheckbox: document.getElementById("findEntireWord"),
  12636. findMsg: document.getElementById("findMsg"),
  12637. findResultsCount: document.getElementById("findResultsCount"),
  12638. findPreviousButton: document.getElementById("findPrevious"),
  12639. findNextButton: document.getElementById("findNext")
  12640. },
  12641. passwordOverlay: {
  12642. overlayName: "passwordOverlay",
  12643. container: document.getElementById("passwordOverlay"),
  12644. label: document.getElementById("passwordText"),
  12645. input: document.getElementById("password"),
  12646. submitButton: document.getElementById("passwordSubmit"),
  12647. cancelButton: document.getElementById("passwordCancel")
  12648. },
  12649. documentProperties: {
  12650. overlayName: "documentPropertiesOverlay",
  12651. container: document.getElementById("documentPropertiesOverlay"),
  12652. closeButton: document.getElementById("documentPropertiesClose"),
  12653. fields: {
  12654. fileName: document.getElementById("fileNameField"),
  12655. fileSize: document.getElementById("fileSizeField"),
  12656. title: document.getElementById("titleField"),
  12657. author: document.getElementById("authorField"),
  12658. subject: document.getElementById("subjectField"),
  12659. keywords: document.getElementById("keywordsField"),
  12660. creationDate: document.getElementById("creationDateField"),
  12661. modificationDate: document.getElementById("modificationDateField"),
  12662. creator: document.getElementById("creatorField"),
  12663. producer: document.getElementById("producerField"),
  12664. version: document.getElementById("versionField"),
  12665. pageCount: document.getElementById("pageCountField"),
  12666. pageSize: document.getElementById("pageSizeField"),
  12667. linearized: document.getElementById("linearizedField")
  12668. }
  12669. },
  12670. errorWrapper,
  12671. printContainer: document.getElementById("printContainer"),
  12672. openFileInputName: "fileInput",
  12673. debuggerScriptPath: "./debugger.js"
  12674. };
  12675. }
  12676. function webViewerLoad() {
  12677. const config = getViewerConfiguration();
  12678. const event = document.createEvent("CustomEvent");
  12679. event.initCustomEvent("webviewerloaded", true, true, {
  12680. source: window
  12681. });
  12682. try {
  12683. parent.document.dispatchEvent(event);
  12684. } catch (ex) {
  12685. console.error(`webviewerloaded: ${ex}`);
  12686. document.dispatchEvent(event);
  12687. }
  12688. _app.PDFViewerApplication.run(config);
  12689. }
  12690. if (document.blockUnblockOnload) {
  12691. document.blockUnblockOnload(true);
  12692. }
  12693. if (document.readyState === "interactive" || document.readyState === "complete") {
  12694. webViewerLoad();
  12695. } else {
  12696. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  12697. }
  12698. })();
  12699. /******/ })()
  12700. ;
  12701. //# sourceMappingURL=viewer.js.map