viewer.js 384 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.OptionKind = exports.AppOptions = void 0;
  32. var _viewer_compatibility = __webpack_require__(2);
  33. const OptionKind = {
  34. VIEWER: 0x02,
  35. API: 0x04,
  36. WORKER: 0x08,
  37. PREFERENCE: 0x80
  38. };
  39. exports.OptionKind = OptionKind;
  40. const defaultOptions = {
  41. cursorToolOnLoad: {
  42. value: 0,
  43. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  44. },
  45. defaultUrl: {
  46. value: "compressed.tracemonkey-pldi-09.pdf",
  47. kind: OptionKind.VIEWER
  48. },
  49. defaultZoomValue: {
  50. value: "",
  51. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  52. },
  53. disableHistory: {
  54. value: false,
  55. kind: OptionKind.VIEWER
  56. },
  57. disablePageLabels: {
  58. value: false,
  59. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  60. },
  61. enablePermissions: {
  62. value: false,
  63. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  64. },
  65. enablePrintAutoRotate: {
  66. value: true,
  67. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  68. },
  69. enableScripting: {
  70. value: true,
  71. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  72. },
  73. externalLinkRel: {
  74. value: "noopener noreferrer nofollow",
  75. kind: OptionKind.VIEWER
  76. },
  77. externalLinkTarget: {
  78. value: 0,
  79. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  80. },
  81. historyUpdateUrl: {
  82. value: false,
  83. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  84. },
  85. ignoreDestinationZoom: {
  86. value: false,
  87. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  88. },
  89. imageResourcesPath: {
  90. value: "./images/",
  91. kind: OptionKind.VIEWER
  92. },
  93. maxCanvasPixels: {
  94. value: 16777216,
  95. compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
  96. kind: OptionKind.VIEWER
  97. },
  98. pdfBugEnabled: {
  99. value: false,
  100. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  101. },
  102. printResolution: {
  103. value: 150,
  104. kind: OptionKind.VIEWER
  105. },
  106. renderer: {
  107. value: "canvas",
  108. kind: OptionKind.VIEWER
  109. },
  110. renderInteractiveForms: {
  111. value: true,
  112. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  113. },
  114. sidebarViewOnLoad: {
  115. value: -1,
  116. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  117. },
  118. scrollModeOnLoad: {
  119. value: -1,
  120. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  121. },
  122. spreadModeOnLoad: {
  123. value: -1,
  124. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  125. },
  126. textLayerMode: {
  127. value: 1,
  128. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  129. },
  130. useOnlyCssZoom: {
  131. value: false,
  132. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  133. },
  134. viewerCssTheme: {
  135. value: 0,
  136. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  137. },
  138. viewOnLoad: {
  139. value: 0,
  140. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  141. },
  142. cMapPacked: {
  143. value: true,
  144. kind: OptionKind.API
  145. },
  146. cMapUrl: {
  147. value: "../web/cmaps/",
  148. kind: OptionKind.API
  149. },
  150. disableAutoFetch: {
  151. value: false,
  152. kind: OptionKind.API + OptionKind.PREFERENCE
  153. },
  154. disableFontFace: {
  155. value: false,
  156. kind: OptionKind.API + OptionKind.PREFERENCE
  157. },
  158. disableRange: {
  159. value: false,
  160. kind: OptionKind.API + OptionKind.PREFERENCE
  161. },
  162. disableStream: {
  163. value: false,
  164. kind: OptionKind.API + OptionKind.PREFERENCE
  165. },
  166. docBaseUrl: {
  167. value: "",
  168. kind: OptionKind.API
  169. },
  170. enableXfa: {
  171. value: false,
  172. kind: OptionKind.API + OptionKind.PREFERENCE
  173. },
  174. fontExtraProperties: {
  175. value: false,
  176. kind: OptionKind.API
  177. },
  178. isEvalSupported: {
  179. value: true,
  180. kind: OptionKind.API
  181. },
  182. maxImageSize: {
  183. value: -1,
  184. kind: OptionKind.API
  185. },
  186. pdfBug: {
  187. value: false,
  188. kind: OptionKind.API
  189. },
  190. verbosity: {
  191. value: 1,
  192. kind: OptionKind.API
  193. },
  194. workerPort: {
  195. value: null,
  196. kind: OptionKind.WORKER
  197. },
  198. workerSrc: {
  199. value: "../build/pdf.worker.js",
  200. kind: OptionKind.WORKER
  201. }
  202. };
  203. {
  204. defaultOptions.disablePreferences = {
  205. value: false,
  206. kind: OptionKind.VIEWER
  207. };
  208. defaultOptions.locale = {
  209. value: typeof navigator !== "undefined" ? navigator.language : "en-US",
  210. kind: OptionKind.VIEWER
  211. };
  212. defaultOptions.sandboxBundleSrc = {
  213. value: "../build/pdf.sandbox.js",
  214. kind: OptionKind.VIEWER
  215. };
  216. defaultOptions.renderer.kind += OptionKind.PREFERENCE;
  217. }
  218. const userOptions = Object.create(null);
  219. class AppOptions {
  220. constructor() {
  221. throw new Error("Cannot initialize AppOptions.");
  222. }
  223. static get(name) {
  224. const userOption = userOptions[name];
  225. if (userOption !== undefined) {
  226. return userOption;
  227. }
  228. const defaultOption = defaultOptions[name];
  229. if (defaultOption !== undefined) {
  230. return defaultOption.compatibility ?? defaultOption.value;
  231. }
  232. return undefined;
  233. }
  234. static getAll(kind = null) {
  235. const options = Object.create(null);
  236. for (const name in defaultOptions) {
  237. const defaultOption = defaultOptions[name];
  238. if (kind) {
  239. if ((kind & defaultOption.kind) === 0) {
  240. continue;
  241. }
  242. if (kind === OptionKind.PREFERENCE) {
  243. const value = defaultOption.value,
  244. valueType = typeof value;
  245. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  246. options[name] = value;
  247. continue;
  248. }
  249. throw new Error(`Invalid type for preference: ${name}`);
  250. }
  251. }
  252. const userOption = userOptions[name];
  253. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility ?? defaultOption.value;
  254. }
  255. return options;
  256. }
  257. static set(name, value) {
  258. userOptions[name] = value;
  259. }
  260. static setAll(options) {
  261. for (const name in options) {
  262. userOptions[name] = options[name];
  263. }
  264. }
  265. static remove(name) {
  266. delete userOptions[name];
  267. }
  268. }
  269. exports.AppOptions = AppOptions;
  270. /***/ }),
  271. /* 2 */
  272. /***/ ((__unused_webpack_module, exports) => {
  273. Object.defineProperty(exports, "__esModule", ({
  274. value: true
  275. }));
  276. exports.viewerCompatibilityParams = void 0;
  277. const compatibilityParams = Object.create(null);
  278. {
  279. const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
  280. const platform = typeof navigator !== "undefined" && navigator.platform || "";
  281. const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1;
  282. const isAndroid = /Android/.test(userAgent);
  283. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  284. const isIOSChrome = /CriOS/.test(userAgent);
  285. (function checkOnBlobSupport() {
  286. if (isIOSChrome) {
  287. compatibilityParams.disableCreateObjectURL = true;
  288. }
  289. })();
  290. (function checkCanvasSizeLimitation() {
  291. if (isIOS || isAndroid) {
  292. compatibilityParams.maxCanvasPixels = 5242880;
  293. }
  294. })();
  295. }
  296. const viewerCompatibilityParams = Object.freeze(compatibilityParams);
  297. exports.viewerCompatibilityParams = viewerCompatibilityParams;
  298. /***/ }),
  299. /* 3 */
  300. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  301. Object.defineProperty(exports, "__esModule", ({
  302. value: true
  303. }));
  304. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  305. var _ui_utils = __webpack_require__(4);
  306. var _app_options = __webpack_require__(1);
  307. var _pdfjsLib = __webpack_require__(5);
  308. var _pdf_cursor_tools = __webpack_require__(6);
  309. var _pdf_rendering_queue = __webpack_require__(8);
  310. var _overlay_manager = __webpack_require__(9);
  311. var _password_prompt = __webpack_require__(10);
  312. var _pdf_attachment_viewer = __webpack_require__(11);
  313. var _pdf_document_properties = __webpack_require__(13);
  314. var _pdf_find_bar = __webpack_require__(14);
  315. var _pdf_find_controller = __webpack_require__(15);
  316. var _pdf_history = __webpack_require__(17);
  317. var _pdf_layer_viewer = __webpack_require__(18);
  318. var _pdf_link_service = __webpack_require__(19);
  319. var _pdf_outline_viewer = __webpack_require__(20);
  320. var _pdf_presentation_mode = __webpack_require__(21);
  321. var _pdf_scripting_manager = __webpack_require__(22);
  322. var _pdf_sidebar = __webpack_require__(23);
  323. var _pdf_sidebar_resizer = __webpack_require__(24);
  324. var _pdf_thumbnail_viewer = __webpack_require__(25);
  325. var _pdf_viewer = __webpack_require__(27);
  326. var _secondary_toolbar = __webpack_require__(35);
  327. var _toolbar = __webpack_require__(37);
  328. var _viewer_compatibility = __webpack_require__(2);
  329. var _view_history = __webpack_require__(38);
  330. const DEFAULT_SCALE_DELTA = 1.1;
  331. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  332. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  333. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  334. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  335. const ViewOnLoad = {
  336. UNKNOWN: -1,
  337. PREVIOUS: 0,
  338. INITIAL: 1
  339. };
  340. const ViewerCssTheme = {
  341. AUTOMATIC: 0,
  342. LIGHT: 1,
  343. DARK: 2
  344. };
  345. 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"];
  346. 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"];
  347. class DefaultExternalServices {
  348. constructor() {
  349. throw new Error("Cannot initialize DefaultExternalServices.");
  350. }
  351. static updateFindControlState(data) {}
  352. static updateFindMatchesCount(data) {}
  353. static initPassiveLoading(callbacks) {}
  354. static async fallback(data) {}
  355. static reportTelemetry(data) {}
  356. static createDownloadManager(options) {
  357. throw new Error("Not implemented: createDownloadManager");
  358. }
  359. static createPreferences() {
  360. throw new Error("Not implemented: createPreferences");
  361. }
  362. static createL10n(options) {
  363. throw new Error("Not implemented: createL10n");
  364. }
  365. static createScripting(options) {
  366. throw new Error("Not implemented: createScripting");
  367. }
  368. static get supportsIntegratedFind() {
  369. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  370. }
  371. static get supportsDocumentFonts() {
  372. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  373. }
  374. static get supportedMouseWheelZoomModifierKeys() {
  375. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  376. ctrlKey: true,
  377. metaKey: true
  378. });
  379. }
  380. static get isInAutomation() {
  381. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  382. }
  383. }
  384. exports.DefaultExternalServices = DefaultExternalServices;
  385. const PDFViewerApplication = {
  386. initialBookmark: document.location.hash.substring(1),
  387. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  388. _fellback: false,
  389. appConfig: null,
  390. pdfDocument: null,
  391. pdfLoadingTask: null,
  392. printService: null,
  393. pdfViewer: null,
  394. pdfThumbnailViewer: null,
  395. pdfRenderingQueue: null,
  396. pdfPresentationMode: null,
  397. pdfDocumentProperties: null,
  398. pdfLinkService: null,
  399. pdfHistory: null,
  400. pdfSidebar: null,
  401. pdfSidebarResizer: null,
  402. pdfOutlineViewer: null,
  403. pdfAttachmentViewer: null,
  404. pdfLayerViewer: null,
  405. pdfCursorTools: null,
  406. pdfScriptingManager: null,
  407. store: null,
  408. downloadManager: null,
  409. overlayManager: null,
  410. preferences: null,
  411. toolbar: null,
  412. secondaryToolbar: null,
  413. eventBus: null,
  414. l10n: null,
  415. isInitialViewSet: false,
  416. downloadComplete: false,
  417. isViewerEmbedded: window.parent !== window,
  418. url: "",
  419. baseUrl: "",
  420. externalServices: DefaultExternalServices,
  421. _boundEvents: Object.create(null),
  422. documentInfo: null,
  423. metadata: null,
  424. _contentDispositionFilename: null,
  425. _contentLength: null,
  426. _saveInProgress: false,
  427. _wheelUnusedTicks: 0,
  428. _idleCallbacks: new Set(),
  429. async initialize(appConfig) {
  430. this.preferences = this.externalServices.createPreferences();
  431. this.appConfig = appConfig;
  432. await this._readPreferences();
  433. await this._parseHashParameters();
  434. this._forceCssTheme();
  435. await this._initializeL10n();
  436. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdfjsLib.LinkTarget.NONE) {
  437. _app_options.AppOptions.set("externalLinkTarget", _pdfjsLib.LinkTarget.TOP);
  438. }
  439. await this._initializeViewerComponents();
  440. this.bindEvents();
  441. this.bindWindowEvents();
  442. const appContainer = appConfig.appContainer || document.documentElement;
  443. this.l10n.translate(appContainer).then(() => {
  444. this.eventBus.dispatch("localized", {
  445. source: this
  446. });
  447. });
  448. this._initializedCapability.resolve();
  449. },
  450. async _readPreferences() {
  451. if (_app_options.AppOptions.get("disablePreferences")) {
  452. return;
  453. }
  454. try {
  455. _app_options.AppOptions.setAll(await this.preferences.getAll());
  456. } catch (reason) {
  457. console.error(`_readPreferences: "${reason?.message}".`);
  458. }
  459. },
  460. async _parseHashParameters() {
  461. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  462. return undefined;
  463. }
  464. const hash = document.location.hash.substring(1);
  465. if (!hash) {
  466. return undefined;
  467. }
  468. const hashParams = (0, _ui_utils.parseQueryString)(hash),
  469. waitOn = [];
  470. if ("disableworker" in hashParams && hashParams.disableworker === "true") {
  471. waitOn.push(loadFakeWorker());
  472. }
  473. if ("disablerange" in hashParams) {
  474. _app_options.AppOptions.set("disableRange", hashParams.disablerange === "true");
  475. }
  476. if ("disablestream" in hashParams) {
  477. _app_options.AppOptions.set("disableStream", hashParams.disablestream === "true");
  478. }
  479. if ("disableautofetch" in hashParams) {
  480. _app_options.AppOptions.set("disableAutoFetch", hashParams.disableautofetch === "true");
  481. }
  482. if ("disablefontface" in hashParams) {
  483. _app_options.AppOptions.set("disableFontFace", hashParams.disablefontface === "true");
  484. }
  485. if ("disablehistory" in hashParams) {
  486. _app_options.AppOptions.set("disableHistory", hashParams.disablehistory === "true");
  487. }
  488. if ("verbosity" in hashParams) {
  489. _app_options.AppOptions.set("verbosity", hashParams.verbosity | 0);
  490. }
  491. if ("textlayer" in hashParams) {
  492. switch (hashParams.textlayer) {
  493. case "off":
  494. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  495. break;
  496. case "visible":
  497. case "shadow":
  498. case "hover":
  499. const viewer = this.appConfig.viewerContainer;
  500. viewer.classList.add("textLayer-" + hashParams.textlayer);
  501. break;
  502. }
  503. }
  504. if ("pdfbug" in hashParams) {
  505. _app_options.AppOptions.set("pdfBug", true);
  506. _app_options.AppOptions.set("fontExtraProperties", true);
  507. const enabled = hashParams.pdfbug.split(",");
  508. waitOn.push(loadAndEnablePDFBug(enabled));
  509. }
  510. if ("locale" in hashParams) {
  511. _app_options.AppOptions.set("locale", hashParams.locale);
  512. }
  513. if (waitOn.length === 0) {
  514. return undefined;
  515. }
  516. return Promise.all(waitOn).catch(reason => {
  517. console.error(`_parseHashParameters: "${reason.message}".`);
  518. });
  519. },
  520. async _initializeL10n() {
  521. this.l10n = this.externalServices.createL10n({
  522. locale: _app_options.AppOptions.get("locale")
  523. });
  524. const dir = await this.l10n.getDirection();
  525. document.getElementsByTagName("html")[0].dir = dir;
  526. },
  527. _forceCssTheme() {
  528. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  529. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  530. return;
  531. }
  532. try {
  533. const styleSheet = document.styleSheets[0];
  534. const cssRules = styleSheet?.cssRules || [];
  535. const mediaMatcher = "prefers-color-scheme";
  536. const mediaRule = `(${mediaMatcher}: dark)`;
  537. const mediaRegex = new RegExp(`^@media \\(${mediaMatcher}: dark\\) {\\n\\s*([\\w\\s-.,:;/\\\\{}()]+)\\n}$`);
  538. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  539. const rule = cssRules[i];
  540. if (rule instanceof CSSMediaRule && rule.media?.[0] === mediaRule) {
  541. if (cssTheme === ViewerCssTheme.LIGHT) {
  542. styleSheet.deleteRule(i);
  543. return;
  544. }
  545. const darkRules = mediaRegex.exec(rule.cssText);
  546. if (darkRules?.[1]) {
  547. styleSheet.deleteRule(i);
  548. styleSheet.insertRule(darkRules[1], i);
  549. }
  550. return;
  551. }
  552. }
  553. } catch (reason) {
  554. console.error(`_forceCssTheme: "${reason?.message}".`);
  555. }
  556. },
  557. async _initializeViewerComponents() {
  558. const appConfig = this.appConfig;
  559. const eventBus = appConfig.eventBus || new _ui_utils.EventBus({
  560. isInAutomation: this.externalServices.isInAutomation
  561. });
  562. this.eventBus = eventBus;
  563. this.overlayManager = new _overlay_manager.OverlayManager();
  564. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  565. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  566. this.pdfRenderingQueue = pdfRenderingQueue;
  567. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  568. eventBus,
  569. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  570. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  571. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  572. });
  573. this.pdfLinkService = pdfLinkService;
  574. const downloadManager = this.externalServices.createDownloadManager();
  575. this.downloadManager = downloadManager;
  576. const findController = new _pdf_find_controller.PDFFindController({
  577. linkService: pdfLinkService,
  578. eventBus
  579. });
  580. this.findController = findController;
  581. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  582. eventBus,
  583. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  584. scriptingFactory: this.externalServices,
  585. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  586. });
  587. this.pdfScriptingManager = pdfScriptingManager;
  588. const container = appConfig.mainContainer;
  589. const viewer = appConfig.viewerContainer;
  590. this.pdfViewer = new _pdf_viewer.PDFViewer({
  591. container,
  592. viewer,
  593. eventBus,
  594. renderingQueue: pdfRenderingQueue,
  595. linkService: pdfLinkService,
  596. downloadManager,
  597. findController,
  598. scriptingManager: pdfScriptingManager,
  599. renderer: _app_options.AppOptions.get("renderer"),
  600. l10n: this.l10n,
  601. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  602. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  603. renderInteractiveForms: _app_options.AppOptions.get("renderInteractiveForms"),
  604. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  605. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  606. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  607. enableScripting: _app_options.AppOptions.get("enableScripting")
  608. });
  609. pdfRenderingQueue.setViewer(this.pdfViewer);
  610. pdfLinkService.setViewer(this.pdfViewer);
  611. pdfScriptingManager.setViewer(this.pdfViewer);
  612. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  613. container: appConfig.sidebar.thumbnailView,
  614. eventBus,
  615. renderingQueue: pdfRenderingQueue,
  616. linkService: pdfLinkService,
  617. l10n: this.l10n
  618. });
  619. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  620. this.pdfHistory = new _pdf_history.PDFHistory({
  621. linkService: pdfLinkService,
  622. eventBus
  623. });
  624. pdfLinkService.setHistory(this.pdfHistory);
  625. if (!this.supportsIntegratedFind) {
  626. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  627. }
  628. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  629. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  630. container,
  631. eventBus,
  632. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  633. });
  634. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  635. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  636. if (this.supportsFullscreen) {
  637. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  638. container,
  639. pdfViewer: this.pdfViewer,
  640. eventBus
  641. });
  642. }
  643. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  644. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  645. container: appConfig.sidebar.outlineView,
  646. eventBus,
  647. linkService: pdfLinkService
  648. });
  649. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  650. container: appConfig.sidebar.attachmentsView,
  651. eventBus,
  652. downloadManager
  653. });
  654. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  655. container: appConfig.sidebar.layersView,
  656. eventBus,
  657. l10n: this.l10n
  658. });
  659. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  660. elements: appConfig.sidebar,
  661. pdfViewer: this.pdfViewer,
  662. pdfThumbnailViewer: this.pdfThumbnailViewer,
  663. eventBus,
  664. l10n: this.l10n
  665. });
  666. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  667. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  668. },
  669. run(config) {
  670. this.initialize(config).then(webViewerInitialized);
  671. },
  672. get initialized() {
  673. return this._initializedCapability.settled;
  674. },
  675. get initializedPromise() {
  676. return this._initializedCapability.promise;
  677. },
  678. zoomIn(ticks) {
  679. if (this.pdfViewer.isInPresentationMode) {
  680. return;
  681. }
  682. let newScale = this.pdfViewer.currentScale;
  683. do {
  684. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  685. newScale = Math.ceil(newScale * 10) / 10;
  686. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  687. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  688. this.pdfViewer.currentScaleValue = newScale;
  689. },
  690. zoomOut(ticks) {
  691. if (this.pdfViewer.isInPresentationMode) {
  692. return;
  693. }
  694. let newScale = this.pdfViewer.currentScale;
  695. do {
  696. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  697. newScale = Math.floor(newScale * 10) / 10;
  698. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  699. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  700. this.pdfViewer.currentScaleValue = newScale;
  701. },
  702. zoomReset() {
  703. if (this.pdfViewer.isInPresentationMode) {
  704. return;
  705. }
  706. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  707. },
  708. get pagesCount() {
  709. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  710. },
  711. get page() {
  712. return this.pdfViewer.currentPageNumber;
  713. },
  714. set page(val) {
  715. this.pdfViewer.currentPageNumber = val;
  716. },
  717. get supportsPrinting() {
  718. return PDFPrintServiceFactory.instance.supportsPrinting;
  719. },
  720. get supportsFullscreen() {
  721. const doc = document.documentElement;
  722. let support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen);
  723. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false) {
  724. support = false;
  725. }
  726. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", support);
  727. },
  728. get supportsIntegratedFind() {
  729. return this.externalServices.supportsIntegratedFind;
  730. },
  731. get supportsDocumentFonts() {
  732. return this.externalServices.supportsDocumentFonts;
  733. },
  734. get loadingBar() {
  735. const bar = new _ui_utils.ProgressBar("#loadingBar");
  736. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  737. },
  738. get supportedMouseWheelZoomModifierKeys() {
  739. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  740. },
  741. initPassiveLoading() {
  742. throw new Error("Not implemented: initPassiveLoading");
  743. },
  744. setTitleUsingUrl(url = "") {
  745. this.url = url;
  746. this.baseUrl = url.split("#")[0];
  747. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  748. if (!title) {
  749. try {
  750. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  751. } catch (ex) {
  752. title = url;
  753. }
  754. }
  755. this.setTitle(title);
  756. },
  757. setTitle(title) {
  758. if (this.isViewerEmbedded) {
  759. return;
  760. }
  761. var reg = /^[^\u4e00-\u9fa5\w\s]+/;
  762. if (reg.test(title)) {
  763. var list = title.split('-');
  764. if (list.length > 1) {
  765. title = list[list.length - 1].trim();
  766. }
  767. }
  768. document.title = title;
  769. },
  770. get _docFilename() {
  771. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  772. },
  773. _cancelIdleCallbacks() {
  774. if (!this._idleCallbacks.size) {
  775. return;
  776. }
  777. for (const callback of this._idleCallbacks) {
  778. window.cancelIdleCallback(callback);
  779. }
  780. this._idleCallbacks.clear();
  781. },
  782. async close() {
  783. this._unblockDocumentLoadEvent();
  784. const {
  785. container
  786. } = this.appConfig.errorWrapper;
  787. container.hidden = true;
  788. if (!this.pdfLoadingTask) {
  789. return;
  790. }
  791. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  792. try {
  793. await this.save({
  794. sourceEventType: "save"
  795. });
  796. } catch (reason) {}
  797. }
  798. const promises = [];
  799. promises.push(this.pdfLoadingTask.destroy());
  800. this.pdfLoadingTask = null;
  801. if (this.pdfDocument) {
  802. this.pdfDocument = null;
  803. this.pdfThumbnailViewer.setDocument(null);
  804. this.pdfViewer.setDocument(null);
  805. this.pdfLinkService.setDocument(null);
  806. this.pdfDocumentProperties.setDocument(null);
  807. }
  808. webViewerResetPermissions();
  809. this._fellback = false;
  810. this.store = null;
  811. this.isInitialViewSet = false;
  812. this.downloadComplete = false;
  813. this.url = "";
  814. this.baseUrl = "";
  815. this.documentInfo = null;
  816. this.metadata = null;
  817. this._contentDispositionFilename = null;
  818. this._contentLength = null;
  819. this._saveInProgress = false;
  820. this._cancelIdleCallbacks();
  821. promises.push(this.pdfScriptingManager.destroyPromise);
  822. this.pdfSidebar.reset();
  823. this.pdfOutlineViewer.reset();
  824. this.pdfAttachmentViewer.reset();
  825. this.pdfLayerViewer.reset();
  826. if (this.pdfHistory) {
  827. this.pdfHistory.reset();
  828. }
  829. if (this.findBar) {
  830. this.findBar.reset();
  831. }
  832. this.toolbar.reset();
  833. this.secondaryToolbar.reset();
  834. if (typeof PDFBug !== "undefined") {
  835. PDFBug.cleanup();
  836. }
  837. await Promise.all(promises);
  838. },
  839. async open(file, args) {
  840. if (this.pdfLoadingTask) {
  841. await this.close();
  842. }
  843. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  844. for (const key in workerParameters) {
  845. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  846. }
  847. const parameters = Object.create(null);
  848. if (typeof file === "string") {
  849. const url = window.atob(file);
  850. this.setTitleUsingUrl(url);
  851. parameters.url = url;
  852. // parameters.url = FILE_DOWNLOAD_HOST + file;
  853. } else if (file && "byteLength" in file) {
  854. parameters.data = file;
  855. } else if (file.url && file.originalUrl) {
  856. this.setTitleUsingUrl(file.originalUrl);
  857. parameters.url = file.url;
  858. }
  859. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  860. for (const key in apiParameters) {
  861. let value = apiParameters[key];
  862. if (key === "docBaseUrl" && !value) {}
  863. parameters[key] = value;
  864. }
  865. if (args) {
  866. for (const key in args) {
  867. parameters[key] = args[key];
  868. }
  869. }
  870. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  871. this.pdfLoadingTask = loadingTask;
  872. loadingTask.onPassword = (updateCallback, reason) => {
  873. this.pdfLinkService.externalLinkEnabled = false;
  874. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  875. this.passwordPrompt.open();
  876. };
  877. loadingTask.onProgress = ({
  878. loaded,
  879. total
  880. }) => {
  881. this.progress(loaded / total);
  882. };
  883. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  884. return loadingTask.promise.then(pdfDocument => {
  885. this.load(pdfDocument);
  886. }, exception => {
  887. if (loadingTask !== this.pdfLoadingTask) {
  888. return undefined;
  889. }
  890. let key = "loading_error";
  891. if (exception instanceof _pdfjsLib.InvalidPDFException) {
  892. key = "invalid_file_error";
  893. } else if (exception instanceof _pdfjsLib.MissingPDFException) {
  894. key = "missing_file_error";
  895. } else if (exception instanceof _pdfjsLib.UnexpectedResponseException) {
  896. key = "unexpected_response_error";
  897. }
  898. return this.l10n.get(key).then(msg => {
  899. this._documentError(msg, {
  900. message: exception?.message
  901. });
  902. throw exception;
  903. });
  904. });
  905. },
  906. _ensureDownloadComplete() {
  907. if (this.pdfDocument && this.downloadComplete) {
  908. return;
  909. }
  910. throw new Error("PDF document not downloaded.");
  911. },
  912. async download({
  913. sourceEventType = "download"
  914. } = {}) {
  915. const url = this.baseUrl,
  916. filename = this._docFilename;
  917. try {
  918. this._ensureDownloadComplete();
  919. const data = await this.pdfDocument.getData();
  920. const blob = new Blob([data], {
  921. type: "application/pdf"
  922. });
  923. await this.downloadManager.download(blob, url, filename, sourceEventType);
  924. } catch (reason) {
  925. await this.downloadManager.downloadUrl(url, filename);
  926. }
  927. },
  928. async save({
  929. sourceEventType = "download"
  930. } = {}) {
  931. if (this._saveInProgress) {
  932. return;
  933. }
  934. this._saveInProgress = true;
  935. await this.pdfScriptingManager.dispatchWillSave();
  936. const url = this.baseUrl,
  937. filename = this._docFilename;
  938. try {
  939. this._ensureDownloadComplete();
  940. const data = await this.pdfDocument.saveDocument();
  941. const blob = new Blob([data], {
  942. type: "application/pdf"
  943. });
  944. await this.downloadManager.download(blob, url, filename, sourceEventType);
  945. } catch (reason) {
  946. await this.download({
  947. sourceEventType
  948. });
  949. } finally {
  950. await this.pdfScriptingManager.dispatchDidSave();
  951. this._saveInProgress = false;
  952. }
  953. },
  954. downloadOrSave(options) {
  955. if (this.pdfDocument?.annotationStorage.size > 0) {
  956. this.save(options);
  957. } else {
  958. this.download(options);
  959. }
  960. },
  961. fallback(featureId) {
  962. this.externalServices.reportTelemetry({
  963. type: "unsupportedFeature",
  964. featureId
  965. });
  966. if (this._fellback) {
  967. return;
  968. }
  969. this._fellback = true;
  970. this.externalServices.fallback({
  971. featureId,
  972. url: this.baseUrl
  973. }).then(download => {
  974. if (!download) {
  975. return;
  976. }
  977. this.download({
  978. sourceEventType: "download"
  979. });
  980. });
  981. },
  982. _documentError(message, moreInfo = null) {
  983. this._unblockDocumentLoadEvent();
  984. this._otherError(message, moreInfo);
  985. },
  986. _otherError(message, moreInfo = null) {
  987. const moreInfoText = [this.l10n.get("error_version_info", {
  988. version: _pdfjsLib.version || "?",
  989. build: _pdfjsLib.build || "?"
  990. })];
  991. if (moreInfo) {
  992. moreInfoText.push(this.l10n.get("error_message", {
  993. message: moreInfo.message
  994. }));
  995. if (moreInfo.stack) {
  996. moreInfoText.push(this.l10n.get("error_stack", {
  997. stack: moreInfo.stack
  998. }));
  999. } else {
  1000. if (moreInfo.filename) {
  1001. moreInfoText.push(this.l10n.get("error_file", {
  1002. file: moreInfo.filename
  1003. }));
  1004. }
  1005. if (moreInfo.lineNumber) {
  1006. moreInfoText.push(this.l10n.get("error_line", {
  1007. line: moreInfo.lineNumber
  1008. }));
  1009. }
  1010. }
  1011. }
  1012. const errorWrapperConfig = this.appConfig.errorWrapper;
  1013. const errorWrapper = errorWrapperConfig.container;
  1014. errorWrapper.hidden = false;
  1015. const errorMessage = errorWrapperConfig.errorMessage;
  1016. errorMessage.textContent = message;
  1017. const closeButton = errorWrapperConfig.closeButton;
  1018. closeButton.onclick = function () {
  1019. errorWrapper.hidden = true;
  1020. };
  1021. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1022. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1023. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1024. moreInfoButton.onclick = function () {
  1025. errorMoreInfo.hidden = false;
  1026. moreInfoButton.hidden = true;
  1027. lessInfoButton.hidden = false;
  1028. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1029. };
  1030. lessInfoButton.onclick = function () {
  1031. errorMoreInfo.hidden = true;
  1032. moreInfoButton.hidden = false;
  1033. lessInfoButton.hidden = true;
  1034. };
  1035. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1036. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1037. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1038. moreInfoButton.hidden = false;
  1039. lessInfoButton.hidden = true;
  1040. Promise.all(moreInfoText).then(parts => {
  1041. errorMoreInfo.value = parts.join("\n");
  1042. });
  1043. },
  1044. progress(level) {
  1045. if (this.downloadComplete) {
  1046. return;
  1047. }
  1048. const percent = Math.round(level * 100);
  1049. if (percent > this.loadingBar.percent || isNaN(percent)) {
  1050. this.loadingBar.percent = percent;
  1051. const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
  1052. if (disableAutoFetch && percent) {
  1053. if (this.disableAutoFetchLoadingBarTimeout) {
  1054. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1055. this.disableAutoFetchLoadingBarTimeout = null;
  1056. }
  1057. this.loadingBar.show();
  1058. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  1059. this.loadingBar.hide();
  1060. this.disableAutoFetchLoadingBarTimeout = null;
  1061. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1062. }
  1063. }
  1064. },
  1065. load(pdfDocument) {
  1066. this.pdfDocument = pdfDocument;
  1067. pdfDocument.getDownloadInfo().then(({
  1068. length
  1069. }) => {
  1070. this._contentLength = length;
  1071. this.downloadComplete = true;
  1072. this.loadingBar.hide();
  1073. firstPagePromise.then(() => {
  1074. this.eventBus.dispatch("documentloaded", {
  1075. source: this
  1076. });
  1077. });
  1078. });
  1079. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  1080. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1081. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  1082. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1083. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1084. let baseDocumentUrl;
  1085. baseDocumentUrl = null;
  1086. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1087. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1088. const pdfViewer = this.pdfViewer;
  1089. pdfViewer.setDocument(pdfDocument);
  1090. const {
  1091. firstPagePromise,
  1092. onePageRendered,
  1093. pagesPromise
  1094. } = pdfViewer;
  1095. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  1096. pdfThumbnailViewer.setDocument(pdfDocument);
  1097. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprint)).getMultiple({
  1098. page: null,
  1099. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1100. scrollLeft: "0",
  1101. scrollTop: "0",
  1102. rotation: null,
  1103. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  1104. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1105. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  1106. }).catch(() => {
  1107. return Object.create(null);
  1108. });
  1109. firstPagePromise.then(pdfPage => {
  1110. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  1111. this._initializeAnnotationStorageCallbacks(pdfDocument);
  1112. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  1113. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  1114. this._initializePdfHistory({
  1115. fingerprint: pdfDocument.fingerprint,
  1116. viewOnLoad,
  1117. initialDest: openAction?.dest
  1118. });
  1119. const initialBookmark = this.initialBookmark;
  1120. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  1121. let hash = zoom ? `zoom=${zoom}` : null;
  1122. let rotation = null;
  1123. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  1124. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  1125. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  1126. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1127. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  1128. rotation = parseInt(stored.rotation, 10);
  1129. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1130. sidebarView = stored.sidebarView | 0;
  1131. }
  1132. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1133. scrollMode = stored.scrollMode | 0;
  1134. }
  1135. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1136. spreadMode = stored.spreadMode | 0;
  1137. }
  1138. }
  1139. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1140. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  1141. }
  1142. if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1143. spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(pageLayout);
  1144. }
  1145. this.setInitialView(hash, {
  1146. rotation,
  1147. sidebarView,
  1148. scrollMode,
  1149. spreadMode
  1150. });
  1151. this.eventBus.dispatch("documentinit", {
  1152. source: this
  1153. });
  1154. if (!this.isViewerEmbedded) {
  1155. pdfViewer.focus();
  1156. }
  1157. this._initializePermissions(pdfDocument);
  1158. await Promise.race([pagesPromise, new Promise(resolve => {
  1159. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1160. })]);
  1161. if (!initialBookmark && !hash) {
  1162. return;
  1163. }
  1164. if (pdfViewer.hasEqualPageSizes) {
  1165. return;
  1166. }
  1167. this.initialBookmark = initialBookmark;
  1168. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1169. this.setInitialView(hash);
  1170. }).catch(() => {
  1171. this.setInitialView();
  1172. }).then(function () {
  1173. pdfViewer.update();
  1174. });
  1175. });
  1176. pagesPromise.then(() => {
  1177. this._unblockDocumentLoadEvent();
  1178. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1179. });
  1180. onePageRendered.then(() => {
  1181. pdfDocument.getOutline().then(outline => {
  1182. if (pdfDocument !== this.pdfDocument) {
  1183. return;
  1184. }
  1185. this.pdfOutlineViewer.render({
  1186. outline,
  1187. pdfDocument
  1188. });
  1189. });
  1190. pdfDocument.getAttachments().then(attachments => {
  1191. if (pdfDocument !== this.pdfDocument) {
  1192. return;
  1193. }
  1194. this.pdfAttachmentViewer.render({
  1195. attachments
  1196. });
  1197. });
  1198. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1199. if (pdfDocument !== this.pdfDocument) {
  1200. return;
  1201. }
  1202. this.pdfLayerViewer.render({
  1203. optionalContentConfig,
  1204. pdfDocument
  1205. });
  1206. });
  1207. if ("requestIdleCallback" in window) {
  1208. const callback = window.requestIdleCallback(() => {
  1209. this._collectTelemetry(pdfDocument);
  1210. this._idleCallbacks.delete(callback);
  1211. }, {
  1212. timeout: 1000
  1213. });
  1214. this._idleCallbacks.add(callback);
  1215. }
  1216. });
  1217. this._initializePageLabels(pdfDocument);
  1218. this._initializeMetadata(pdfDocument);
  1219. },
  1220. async _scriptingDocProperties(pdfDocument) {
  1221. if (!this.documentInfo) {
  1222. await new Promise(resolve => {
  1223. this.eventBus._on("metadataloaded", resolve, {
  1224. once: true
  1225. });
  1226. });
  1227. if (pdfDocument !== this.pdfDocument) {
  1228. return null;
  1229. }
  1230. }
  1231. if (!this._contentLength) {
  1232. await new Promise(resolve => {
  1233. this.eventBus._on("documentloaded", resolve, {
  1234. once: true
  1235. });
  1236. });
  1237. if (pdfDocument !== this.pdfDocument) {
  1238. return null;
  1239. }
  1240. }
  1241. return { ...this.documentInfo,
  1242. baseURL: this.baseUrl,
  1243. filesize: this._contentLength,
  1244. filename: this._docFilename,
  1245. metadata: this.metadata?.getRaw(),
  1246. authors: this.metadata?.get("dc:creator"),
  1247. numPages: this.pagesCount,
  1248. URL: this.url
  1249. };
  1250. },
  1251. async _collectTelemetry(pdfDocument) {
  1252. const markInfo = await this.pdfDocument.getMarkInfo();
  1253. if (pdfDocument !== this.pdfDocument) {
  1254. return;
  1255. }
  1256. const tagged = markInfo?.Marked || false;
  1257. this.externalServices.reportTelemetry({
  1258. type: "tagged",
  1259. tagged
  1260. });
  1261. },
  1262. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1263. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  1264. if (pdfDocument !== this.pdfDocument) {
  1265. return;
  1266. }
  1267. let triggerAutoPrint = false;
  1268. if (openAction?.action === "Print") {
  1269. triggerAutoPrint = true;
  1270. }
  1271. if (javaScript) {
  1272. javaScript.some(js => {
  1273. if (!js) {
  1274. return false;
  1275. }
  1276. console.warn("Warning: JavaScript support is not enabled");
  1277. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1278. return true;
  1279. });
  1280. if (!triggerAutoPrint) {
  1281. for (const js of javaScript) {
  1282. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1283. triggerAutoPrint = true;
  1284. break;
  1285. }
  1286. }
  1287. }
  1288. }
  1289. if (triggerAutoPrint) {
  1290. this.triggerPrinting();
  1291. }
  1292. },
  1293. async _initializeMetadata(pdfDocument) {
  1294. const {
  1295. info,
  1296. metadata,
  1297. contentDispositionFilename,
  1298. contentLength
  1299. } = await pdfDocument.getMetadata();
  1300. if (pdfDocument !== this.pdfDocument) {
  1301. return;
  1302. }
  1303. this.documentInfo = info;
  1304. this.metadata = metadata;
  1305. this._contentDispositionFilename ?? (this._contentDispositionFilename = contentDispositionFilename);
  1306. this._contentLength ?? (this._contentLength = contentLength);
  1307. console.log(`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"})`);
  1308. let pdfTitle = info?.Title;
  1309. const metadataTitle = metadata?.get("dc:title");
  1310. if (metadataTitle) {
  1311. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1312. pdfTitle = metadataTitle;
  1313. }
  1314. }
  1315. if (pdfTitle) {
  1316. this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  1317. } else if (contentDispositionFilename) {
  1318. this.setTitle(contentDispositionFilename);
  1319. }
  1320. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1321. console.warn("Warning: XFA is not enabled");
  1322. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1323. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderInteractiveForms) {
  1324. console.warn("Warning: Interactive form support is not enabled");
  1325. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1326. }
  1327. if (info.IsSignaturesPresent) {
  1328. console.warn("Warning: Digital signatures validation is not supported");
  1329. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  1330. }
  1331. let versionId = "other";
  1332. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  1333. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  1334. }
  1335. let generatorId = "other";
  1336. if (info.Producer) {
  1337. const producer = info.Producer.toLowerCase();
  1338. KNOWN_GENERATORS.some(function (generator) {
  1339. if (!producer.includes(generator)) {
  1340. return false;
  1341. }
  1342. generatorId = generator.replace(/[ .-]/g, "_");
  1343. return true;
  1344. });
  1345. }
  1346. let formType = null;
  1347. if (info.IsXFAPresent) {
  1348. formType = "xfa";
  1349. } else if (info.IsAcroFormPresent) {
  1350. formType = "acroform";
  1351. }
  1352. this.externalServices.reportTelemetry({
  1353. type: "documentInfo",
  1354. version: versionId,
  1355. generator: generatorId,
  1356. formType
  1357. });
  1358. this.eventBus.dispatch("metadataloaded", {
  1359. source: this
  1360. });
  1361. },
  1362. async _initializePageLabels(pdfDocument) {
  1363. const labels = await pdfDocument.getPageLabels();
  1364. if (pdfDocument !== this.pdfDocument) {
  1365. return;
  1366. }
  1367. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1368. return;
  1369. }
  1370. const numLabels = labels.length;
  1371. if (numLabels !== this.pagesCount) {
  1372. console.error("The number of Page Labels does not match the number of pages in the document.");
  1373. return;
  1374. }
  1375. let i = 0;
  1376. while (i < numLabels && labels[i] === (i + 1).toString()) {
  1377. i++;
  1378. }
  1379. if (i === numLabels) {
  1380. return;
  1381. }
  1382. const {
  1383. pdfViewer,
  1384. pdfThumbnailViewer,
  1385. toolbar
  1386. } = this;
  1387. pdfViewer.setPageLabels(labels);
  1388. pdfThumbnailViewer.setPageLabels(labels);
  1389. toolbar.setPagesCount(numLabels, true);
  1390. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1391. },
  1392. _initializePdfHistory({
  1393. fingerprint,
  1394. viewOnLoad,
  1395. initialDest = null
  1396. }) {
  1397. if (this.isViewerEmbedded || _app_options.AppOptions.get("disableHistory")) {
  1398. return;
  1399. }
  1400. this.pdfHistory.initialize({
  1401. fingerprint,
  1402. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1403. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1404. });
  1405. if (this.pdfHistory.initialBookmark) {
  1406. this.initialBookmark = this.pdfHistory.initialBookmark;
  1407. this.initialRotation = this.pdfHistory.initialRotation;
  1408. }
  1409. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1410. this.initialBookmark = JSON.stringify(initialDest);
  1411. this.pdfHistory.push({
  1412. explicitDest: initialDest,
  1413. pageNumber: null
  1414. });
  1415. }
  1416. },
  1417. async _initializePermissions(pdfDocument) {
  1418. const permissions = await pdfDocument.getPermissions();
  1419. if (pdfDocument !== this.pdfDocument) {
  1420. return;
  1421. }
  1422. if (!permissions || !_app_options.AppOptions.get("enablePermissions")) {
  1423. return;
  1424. }
  1425. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  1426. this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
  1427. }
  1428. },
  1429. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1430. if (pdfDocument !== this.pdfDocument) {
  1431. return;
  1432. }
  1433. const {
  1434. annotationStorage
  1435. } = pdfDocument;
  1436. annotationStorage.onSetModified = () => {
  1437. window.addEventListener("beforeunload", beforeUnload);
  1438. this._annotationStorageModified = true;
  1439. };
  1440. annotationStorage.onResetModified = () => {
  1441. window.removeEventListener("beforeunload", beforeUnload);
  1442. delete this._annotationStorageModified;
  1443. };
  1444. },
  1445. setInitialView(storedHash, {
  1446. rotation,
  1447. sidebarView,
  1448. scrollMode,
  1449. spreadMode
  1450. } = {}) {
  1451. const setRotation = angle => {
  1452. if ((0, _ui_utils.isValidRotation)(angle)) {
  1453. this.pdfViewer.pagesRotation = angle;
  1454. }
  1455. };
  1456. const setViewerModes = (scroll, spread) => {
  1457. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1458. this.pdfViewer.scrollMode = scroll;
  1459. }
  1460. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1461. this.pdfViewer.spreadMode = spread;
  1462. }
  1463. };
  1464. this.isInitialViewSet = true;
  1465. this.pdfSidebar.setInitialView(sidebarView);
  1466. setViewerModes(scrollMode, spreadMode);
  1467. if (this.initialBookmark) {
  1468. setRotation(this.initialRotation);
  1469. delete this.initialRotation;
  1470. this.pdfLinkService.setHash(this.initialBookmark);
  1471. this.initialBookmark = null;
  1472. } else if (storedHash) {
  1473. setRotation(rotation);
  1474. this.pdfLinkService.setHash(storedHash);
  1475. }
  1476. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1477. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1478. if (!this.pdfViewer.currentScaleValue) {
  1479. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1480. }
  1481. },
  1482. _cleanup() {
  1483. if (!this.pdfDocument) {
  1484. return;
  1485. }
  1486. this.pdfViewer.cleanup();
  1487. this.pdfThumbnailViewer.cleanup();
  1488. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  1489. },
  1490. forceRendering() {
  1491. this.pdfRenderingQueue.printing = !!this.printService;
  1492. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1493. this.pdfRenderingQueue.renderHighestPriority();
  1494. },
  1495. beforePrint() {
  1496. this.pdfScriptingManager.dispatchWillPrint();
  1497. if (this.printService) {
  1498. return;
  1499. }
  1500. if (!this.supportsPrinting) {
  1501. this.l10n.get("printing_not_supported").then(msg => {
  1502. this._otherError(msg);
  1503. });
  1504. return;
  1505. }
  1506. if (!this.pdfViewer.pageViewsReady) {
  1507. this.l10n.get("printing_not_ready").then(msg => {
  1508. window.alert(msg);
  1509. });
  1510. return;
  1511. }
  1512. const pagesOverview = this.pdfViewer.getPagesOverview();
  1513. const printContainer = this.appConfig.printContainer;
  1514. const printResolution = _app_options.AppOptions.get("printResolution");
  1515. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1516. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
  1517. this.printService = printService;
  1518. this.forceRendering();
  1519. printService.layout();
  1520. this.externalServices.reportTelemetry({
  1521. type: "print"
  1522. });
  1523. },
  1524. afterPrint() {
  1525. this.pdfScriptingManager.dispatchDidPrint();
  1526. if (this.printService) {
  1527. this.printService.destroy();
  1528. this.printService = null;
  1529. if (this.pdfDocument) {
  1530. this.pdfDocument.annotationStorage.resetModified();
  1531. }
  1532. }
  1533. this.forceRendering();
  1534. },
  1535. rotatePages(delta) {
  1536. this.pdfViewer.pagesRotation += delta;
  1537. },
  1538. requestPresentationMode() {
  1539. if (!this.pdfPresentationMode) {
  1540. return;
  1541. }
  1542. this.pdfPresentationMode.request();
  1543. },
  1544. triggerPrinting() {
  1545. if (!this.supportsPrinting) {
  1546. return;
  1547. }
  1548. window.print();
  1549. },
  1550. bindEvents() {
  1551. const {
  1552. eventBus,
  1553. _boundEvents
  1554. } = this;
  1555. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1556. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1557. eventBus._on("resize", webViewerResize);
  1558. eventBus._on("hashchange", webViewerHashchange);
  1559. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1560. eventBus._on("afterprint", _boundEvents.afterPrint);
  1561. eventBus._on("pagerendered", webViewerPageRendered);
  1562. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1563. eventBus._on("pagechanging", webViewerPageChanging);
  1564. eventBus._on("scalechanging", webViewerScaleChanging);
  1565. eventBus._on("rotationchanging", webViewerRotationChanging);
  1566. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1567. eventBus._on("pagemode", webViewerPageMode);
  1568. eventBus._on("namedaction", webViewerNamedAction);
  1569. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1570. eventBus._on("presentationmode", webViewerPresentationMode);
  1571. eventBus._on("print", webViewerPrint);
  1572. eventBus._on("download", webViewerDownload);
  1573. eventBus._on("save", webViewerSave);
  1574. eventBus._on("firstpage", webViewerFirstPage);
  1575. eventBus._on("lastpage", webViewerLastPage);
  1576. eventBus._on("nextpage", webViewerNextPage);
  1577. eventBus._on("previouspage", webViewerPreviousPage);
  1578. eventBus._on("zoomin", webViewerZoomIn);
  1579. eventBus._on("zoomout", webViewerZoomOut);
  1580. eventBus._on("zoomreset", webViewerZoomReset);
  1581. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1582. eventBus._on("scalechanged", webViewerScaleChanged);
  1583. eventBus._on("rotatecw", webViewerRotateCw);
  1584. eventBus._on("rotateccw", webViewerRotateCcw);
  1585. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1586. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1587. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1588. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1589. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1590. eventBus._on("documentproperties", webViewerDocumentProperties);
  1591. eventBus._on("find", webViewerFind);
  1592. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1593. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1594. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1595. if (_app_options.AppOptions.get("pdfBug")) {
  1596. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1597. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1598. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1599. }
  1600. eventBus._on("fileinputchange", webViewerFileInputChange);
  1601. eventBus._on("openfile", webViewerOpenFile);
  1602. },
  1603. bindWindowEvents() {
  1604. const {
  1605. eventBus,
  1606. _boundEvents
  1607. } = this;
  1608. _boundEvents.windowResize = () => {
  1609. eventBus.dispatch("resize", {
  1610. source: window
  1611. });
  1612. };
  1613. _boundEvents.windowHashChange = () => {
  1614. eventBus.dispatch("hashchange", {
  1615. source: window,
  1616. hash: document.location.hash.substring(1)
  1617. });
  1618. };
  1619. _boundEvents.windowBeforePrint = () => {
  1620. eventBus.dispatch("beforeprint", {
  1621. source: window
  1622. });
  1623. };
  1624. _boundEvents.windowAfterPrint = () => {
  1625. eventBus.dispatch("afterprint", {
  1626. source: window
  1627. });
  1628. };
  1629. _boundEvents.windowUpdateFromSandbox = event => {
  1630. eventBus.dispatch("updatefromsandbox", {
  1631. source: window,
  1632. detail: event.detail
  1633. });
  1634. };
  1635. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1636. window.addEventListener("wheel", webViewerWheel, {
  1637. passive: false
  1638. });
  1639. window.addEventListener("touchstart", webViewerTouchStart, {
  1640. passive: false
  1641. });
  1642. window.addEventListener("click", webViewerClick);
  1643. window.addEventListener("keydown", webViewerKeyDown);
  1644. window.addEventListener("resize", _boundEvents.windowResize);
  1645. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1646. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1647. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1648. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1649. },
  1650. unbindEvents() {
  1651. const {
  1652. eventBus,
  1653. _boundEvents
  1654. } = this;
  1655. eventBus._off("resize", webViewerResize);
  1656. eventBus._off("hashchange", webViewerHashchange);
  1657. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1658. eventBus._off("afterprint", _boundEvents.afterPrint);
  1659. eventBus._off("pagerendered", webViewerPageRendered);
  1660. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1661. eventBus._off("pagechanging", webViewerPageChanging);
  1662. eventBus._off("scalechanging", webViewerScaleChanging);
  1663. eventBus._off("rotationchanging", webViewerRotationChanging);
  1664. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1665. eventBus._off("pagemode", webViewerPageMode);
  1666. eventBus._off("namedaction", webViewerNamedAction);
  1667. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1668. eventBus._off("presentationmode", webViewerPresentationMode);
  1669. eventBus._off("print", webViewerPrint);
  1670. eventBus._off("download", webViewerDownload);
  1671. eventBus._off("save", webViewerSave);
  1672. eventBus._off("firstpage", webViewerFirstPage);
  1673. eventBus._off("lastpage", webViewerLastPage);
  1674. eventBus._off("nextpage", webViewerNextPage);
  1675. eventBus._off("previouspage", webViewerPreviousPage);
  1676. eventBus._off("zoomin", webViewerZoomIn);
  1677. eventBus._off("zoomout", webViewerZoomOut);
  1678. eventBus._off("zoomreset", webViewerZoomReset);
  1679. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1680. eventBus._off("scalechanged", webViewerScaleChanged);
  1681. eventBus._off("rotatecw", webViewerRotateCw);
  1682. eventBus._off("rotateccw", webViewerRotateCcw);
  1683. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1684. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1685. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1686. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1687. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1688. eventBus._off("documentproperties", webViewerDocumentProperties);
  1689. eventBus._off("find", webViewerFind);
  1690. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1691. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1692. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1693. if (_boundEvents.reportPageStatsPDFBug) {
  1694. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1695. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1696. _boundEvents.reportPageStatsPDFBug = null;
  1697. }
  1698. eventBus._off("fileinputchange", webViewerFileInputChange);
  1699. eventBus._off("openfile", webViewerOpenFile);
  1700. _boundEvents.beforePrint = null;
  1701. _boundEvents.afterPrint = null;
  1702. },
  1703. unbindWindowEvents() {
  1704. const {
  1705. _boundEvents
  1706. } = this;
  1707. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1708. window.removeEventListener("wheel", webViewerWheel, {
  1709. passive: false
  1710. });
  1711. window.removeEventListener("touchstart", webViewerTouchStart, {
  1712. passive: false
  1713. });
  1714. window.removeEventListener("click", webViewerClick);
  1715. window.removeEventListener("keydown", webViewerKeyDown);
  1716. window.removeEventListener("resize", _boundEvents.windowResize);
  1717. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1718. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1719. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1720. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1721. _boundEvents.windowResize = null;
  1722. _boundEvents.windowHashChange = null;
  1723. _boundEvents.windowBeforePrint = null;
  1724. _boundEvents.windowAfterPrint = null;
  1725. _boundEvents.windowUpdateFromSandbox = null;
  1726. },
  1727. accumulateWheelTicks(ticks) {
  1728. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  1729. this._wheelUnusedTicks = 0;
  1730. }
  1731. this._wheelUnusedTicks += ticks;
  1732. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  1733. this._wheelUnusedTicks -= wholeTicks;
  1734. return wholeTicks;
  1735. },
  1736. _unblockDocumentLoadEvent() {
  1737. if (document.blockUnblockOnload) {
  1738. document.blockUnblockOnload(false);
  1739. }
  1740. this._unblockDocumentLoadEvent = () => {};
  1741. },
  1742. get scriptingReady() {
  1743. return this.pdfScriptingManager.ready;
  1744. }
  1745. };
  1746. exports.PDFViewerApplication = PDFViewerApplication;
  1747. let validateFileURL;
  1748. {
  1749. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1750. validateFileURL = function (file) {
  1751. if (file === undefined) {
  1752. return;
  1753. }
  1754. try {
  1755. const viewerOrigin = new URL(window.location.href).origin || "null";
  1756. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1757. return;
  1758. }
  1759. const {
  1760. origin,
  1761. protocol
  1762. } = new URL(file, window.location.href);
  1763. // if (origin !== viewerOrigin && protocol !== "blob:") {
  1764. // throw new Error("file origin does not match viewer's");
  1765. // }
  1766. } catch (ex) {
  1767. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1768. PDFViewerApplication._documentError(msg, {
  1769. message: ex?.message
  1770. });
  1771. });
  1772. throw ex;
  1773. }
  1774. };
  1775. }
  1776. async function loadFakeWorker() {
  1777. if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
  1778. _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
  1779. }
  1780. return (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.getWorkerSrc());
  1781. }
  1782. function loadAndEnablePDFBug(enabledTabs) {
  1783. const appConfig = PDFViewerApplication.appConfig;
  1784. return (0, _pdfjsLib.loadScript)(appConfig.debuggerScriptPath).then(function () {
  1785. PDFBug.enable(enabledTabs);
  1786. PDFBug.init({
  1787. OPS: _pdfjsLib.OPS
  1788. }, appConfig.mainContainer);
  1789. });
  1790. }
  1791. function reportPageStatsPDFBug({
  1792. pageNumber
  1793. }) {
  1794. if (typeof Stats === "undefined" || !Stats.enabled) {
  1795. return;
  1796. }
  1797. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1798. const pageStats = pageView?.pdfPage?.stats;
  1799. if (!pageStats) {
  1800. return;
  1801. }
  1802. Stats.add(pageNumber, pageStats);
  1803. }
  1804. function webViewerInitialized() {
  1805. const appConfig = PDFViewerApplication.appConfig;
  1806. let file;
  1807. const queryString = document.location.search.substring(1);
  1808. const params = (0, _ui_utils.parseQueryString)(queryString);
  1809. file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
  1810. validateFileURL(file);
  1811. const fileInput = document.createElement("input");
  1812. fileInput.id = appConfig.openFileInputName;
  1813. fileInput.className = "fileInput";
  1814. fileInput.setAttribute("type", "file");
  1815. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1816. document.body.appendChild(fileInput);
  1817. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1818. appConfig.toolbar.openFile.hidden = true;
  1819. appConfig.secondaryToolbar.openFileButton.hidden = true;
  1820. } else {
  1821. fileInput.value = null;
  1822. }
  1823. fileInput.addEventListener("change", function (evt) {
  1824. const files = evt.target.files;
  1825. if (!files || files.length === 0) {
  1826. return;
  1827. }
  1828. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1829. source: this,
  1830. fileInput: evt.target
  1831. });
  1832. });
  1833. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1834. evt.preventDefault();
  1835. evt.dataTransfer.dropEffect = "move";
  1836. });
  1837. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1838. evt.preventDefault();
  1839. const files = evt.dataTransfer.files;
  1840. if (!files || files.length === 0) {
  1841. return;
  1842. }
  1843. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1844. source: this,
  1845. fileInput: evt.dataTransfer
  1846. });
  1847. });
  1848. if (!PDFViewerApplication.supportsDocumentFonts) {
  1849. _app_options.AppOptions.set("disableFontFace", true);
  1850. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  1851. console.warn(msg);
  1852. });
  1853. }
  1854. if (!PDFViewerApplication.supportsPrinting) {
  1855. appConfig.toolbar.print.classList.add("hidden");
  1856. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  1857. }
  1858. if (!PDFViewerApplication.supportsFullscreen) {
  1859. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  1860. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  1861. }
  1862. if (PDFViewerApplication.supportsIntegratedFind) {
  1863. appConfig.toolbar.viewFind.classList.add("hidden");
  1864. }
  1865. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1866. if (evt.target === this) {
  1867. PDFViewerApplication.eventBus.dispatch("resize", {
  1868. source: this
  1869. });
  1870. }
  1871. }, true);
  1872. try {
  1873. webViewerOpenFileViaURL(file);
  1874. } catch (reason) {
  1875. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1876. PDFViewerApplication._documentError(msg, reason);
  1877. });
  1878. }
  1879. }
  1880. function webViewerOpenFileViaURL(file) {
  1881. if (file) {
  1882. PDFViewerApplication.open(file);
  1883. }
  1884. }
  1885. function webViewerResetPermissions() {
  1886. const {
  1887. appConfig
  1888. } = PDFViewerApplication;
  1889. if (!appConfig) {
  1890. return;
  1891. }
  1892. appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  1893. }
  1894. function webViewerPageRendered({
  1895. pageNumber,
  1896. timestamp,
  1897. error
  1898. }) {
  1899. if (pageNumber === PDFViewerApplication.page) {
  1900. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1901. }
  1902. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1903. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1904. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  1905. if (pageView && thumbnailView) {
  1906. thumbnailView.setImage(pageView);
  1907. }
  1908. }
  1909. if (error) {
  1910. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1911. PDFViewerApplication._otherError(msg, error);
  1912. });
  1913. }
  1914. PDFViewerApplication.externalServices.reportTelemetry({
  1915. type: "pageInfo",
  1916. timestamp
  1917. });
  1918. PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
  1919. PDFViewerApplication.externalServices.reportTelemetry({
  1920. type: "documentStats",
  1921. stats
  1922. });
  1923. });
  1924. }
  1925. function webViewerPageMode({
  1926. mode
  1927. }) {
  1928. let view;
  1929. switch (mode) {
  1930. case "thumbs":
  1931. view = _ui_utils.SidebarView.THUMBS;
  1932. break;
  1933. case "bookmarks":
  1934. case "outline":
  1935. view = _ui_utils.SidebarView.OUTLINE;
  1936. break;
  1937. case "attachments":
  1938. view = _ui_utils.SidebarView.ATTACHMENTS;
  1939. break;
  1940. case "layers":
  1941. view = _ui_utils.SidebarView.LAYERS;
  1942. break;
  1943. case "none":
  1944. view = _ui_utils.SidebarView.NONE;
  1945. break;
  1946. default:
  1947. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1948. return;
  1949. }
  1950. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1951. }
  1952. function webViewerNamedAction(evt) {
  1953. switch (evt.action) {
  1954. case "GoToPage":
  1955. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1956. break;
  1957. case "Find":
  1958. if (!PDFViewerApplication.supportsIntegratedFind) {
  1959. PDFViewerApplication.findBar.toggle();
  1960. }
  1961. break;
  1962. case "Print":
  1963. PDFViewerApplication.triggerPrinting();
  1964. break;
  1965. case "SaveAs":
  1966. webViewerSave();
  1967. break;
  1968. }
  1969. }
  1970. function webViewerPresentationModeChanged(evt) {
  1971. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1972. }
  1973. function webViewerSidebarViewChanged(evt) {
  1974. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1975. const store = PDFViewerApplication.store;
  1976. if (store && PDFViewerApplication.isInitialViewSet) {
  1977. store.set("sidebarView", evt.view).catch(function () {});
  1978. }
  1979. }
  1980. function webViewerUpdateViewarea(evt) {
  1981. const location = evt.location,
  1982. store = PDFViewerApplication.store;
  1983. if (store && PDFViewerApplication.isInitialViewSet) {
  1984. store.setMultiple({
  1985. page: location.pageNumber,
  1986. zoom: location.scale,
  1987. scrollLeft: location.left,
  1988. scrollTop: location.top,
  1989. rotation: location.rotation
  1990. }).catch(function () {});
  1991. }
  1992. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1993. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1994. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1995. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1996. const loading = currentPage?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1997. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1998. }
  1999. function webViewerScrollModeChanged(evt) {
  2000. const store = PDFViewerApplication.store;
  2001. if (store && PDFViewerApplication.isInitialViewSet) {
  2002. store.set("scrollMode", evt.mode).catch(function () {});
  2003. }
  2004. }
  2005. function webViewerSpreadModeChanged(evt) {
  2006. const store = PDFViewerApplication.store;
  2007. if (store && PDFViewerApplication.isInitialViewSet) {
  2008. store.set("spreadMode", evt.mode).catch(function () {});
  2009. }
  2010. }
  2011. function webViewerResize() {
  2012. const {
  2013. pdfDocument,
  2014. pdfViewer
  2015. } = PDFViewerApplication;
  2016. if (!pdfDocument) {
  2017. return;
  2018. }
  2019. const currentScaleValue = pdfViewer.currentScaleValue;
  2020. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  2021. pdfViewer.currentScaleValue = currentScaleValue;
  2022. }
  2023. pdfViewer.update();
  2024. }
  2025. function webViewerHashchange(evt) {
  2026. const hash = evt.hash;
  2027. if (!hash) {
  2028. return;
  2029. }
  2030. if (!PDFViewerApplication.isInitialViewSet) {
  2031. PDFViewerApplication.initialBookmark = hash;
  2032. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  2033. PDFViewerApplication.pdfLinkService.setHash(hash);
  2034. }
  2035. }
  2036. let webViewerFileInputChange, webViewerOpenFile;
  2037. {
  2038. webViewerFileInputChange = function (evt) {
  2039. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2040. return;
  2041. }
  2042. const file = evt.fileInput.files[0];
  2043. if (!_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  2044. let url = URL.createObjectURL(file);
  2045. if (file.name) {
  2046. url = {
  2047. url,
  2048. originalUrl: file.name
  2049. };
  2050. }
  2051. PDFViewerApplication.open(url);
  2052. } else {
  2053. PDFViewerApplication.setTitleUsingUrl(file.name);
  2054. const fileReader = new FileReader();
  2055. fileReader.onload = function webViewerChangeFileReaderOnload(event) {
  2056. const buffer = event.target.result;
  2057. PDFViewerApplication.open(new Uint8Array(buffer));
  2058. };
  2059. fileReader.readAsArrayBuffer(file);
  2060. }
  2061. const appConfig = PDFViewerApplication.appConfig;
  2062. appConfig.toolbar.viewBookmark.hidden = true;
  2063. appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
  2064. appConfig.toolbar.download.hidden = true;
  2065. appConfig.secondaryToolbar.downloadButton.hidden = true;
  2066. };
  2067. webViewerOpenFile = function (evt) {
  2068. const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  2069. document.getElementById(openFileInputName).click();
  2070. };
  2071. }
  2072. function webViewerPresentationMode() {
  2073. PDFViewerApplication.requestPresentationMode();
  2074. }
  2075. function webViewerPrint() {
  2076. PDFViewerApplication.triggerPrinting();
  2077. }
  2078. function webViewerDownload() {
  2079. PDFViewerApplication.downloadOrSave({
  2080. sourceEventType: "download"
  2081. });
  2082. }
  2083. function webViewerSave() {
  2084. PDFViewerApplication.downloadOrSave({
  2085. sourceEventType: "save"
  2086. });
  2087. }
  2088. function webViewerFirstPage() {
  2089. if (PDFViewerApplication.pdfDocument) {
  2090. PDFViewerApplication.page = 1;
  2091. }
  2092. }
  2093. function webViewerLastPage() {
  2094. if (PDFViewerApplication.pdfDocument) {
  2095. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2096. }
  2097. }
  2098. function webViewerNextPage() {
  2099. PDFViewerApplication.pdfViewer.nextPage();
  2100. }
  2101. function webViewerPreviousPage() {
  2102. PDFViewerApplication.pdfViewer.previousPage();
  2103. }
  2104. function webViewerZoomIn() {
  2105. PDFViewerApplication.zoomIn();
  2106. }
  2107. function webViewerZoomOut() {
  2108. PDFViewerApplication.zoomOut();
  2109. }
  2110. function webViewerZoomReset() {
  2111. PDFViewerApplication.zoomReset();
  2112. }
  2113. function webViewerPageNumberChanged(evt) {
  2114. const pdfViewer = PDFViewerApplication.pdfViewer;
  2115. if (evt.value !== "") {
  2116. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  2117. }
  2118. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  2119. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2120. }
  2121. }
  2122. function webViewerScaleChanged(evt) {
  2123. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2124. }
  2125. function webViewerRotateCw() {
  2126. PDFViewerApplication.rotatePages(90);
  2127. }
  2128. function webViewerRotateCcw() {
  2129. PDFViewerApplication.rotatePages(-90);
  2130. }
  2131. function webViewerOptionalContentConfig(evt) {
  2132. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  2133. }
  2134. function webViewerSwitchScrollMode(evt) {
  2135. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  2136. }
  2137. function webViewerSwitchSpreadMode(evt) {
  2138. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  2139. }
  2140. function webViewerDocumentProperties() {
  2141. PDFViewerApplication.pdfDocumentProperties.open();
  2142. }
  2143. function webViewerFind(evt) {
  2144. PDFViewerApplication.findController.executeCommand("find" + evt.type, {
  2145. query: evt.query,
  2146. phraseSearch: evt.phraseSearch,
  2147. caseSensitive: evt.caseSensitive,
  2148. entireWord: evt.entireWord,
  2149. highlightAll: evt.highlightAll,
  2150. findPrevious: evt.findPrevious
  2151. });
  2152. }
  2153. function webViewerFindFromUrlHash(evt) {
  2154. PDFViewerApplication.findController.executeCommand("find", {
  2155. query: evt.query,
  2156. phraseSearch: evt.phraseSearch,
  2157. caseSensitive: false,
  2158. entireWord: false,
  2159. highlightAll: true,
  2160. findPrevious: false
  2161. });
  2162. }
  2163. function webViewerUpdateFindMatchesCount({
  2164. matchesCount
  2165. }) {
  2166. if (PDFViewerApplication.supportsIntegratedFind) {
  2167. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  2168. } else {
  2169. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  2170. }
  2171. }
  2172. function webViewerUpdateFindControlState({
  2173. state,
  2174. previous,
  2175. matchesCount,
  2176. rawQuery
  2177. }) {
  2178. if (PDFViewerApplication.supportsIntegratedFind) {
  2179. PDFViewerApplication.externalServices.updateFindControlState({
  2180. result: state,
  2181. findPrevious: previous,
  2182. matchesCount,
  2183. rawQuery
  2184. });
  2185. } else {
  2186. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  2187. }
  2188. }
  2189. function webViewerScaleChanging(evt) {
  2190. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  2191. PDFViewerApplication.pdfViewer.update();
  2192. }
  2193. function webViewerRotationChanging(evt) {
  2194. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  2195. PDFViewerApplication.forceRendering();
  2196. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2197. }
  2198. function webViewerPageChanging({
  2199. pageNumber,
  2200. pageLabel
  2201. }) {
  2202. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  2203. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  2204. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2205. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  2206. }
  2207. }
  2208. function webViewerVisibilityChange(evt) {
  2209. if (document.visibilityState === "visible") {
  2210. setZoomDisabledTimeout();
  2211. }
  2212. }
  2213. let zoomDisabledTimeout = null;
  2214. function setZoomDisabledTimeout() {
  2215. if (zoomDisabledTimeout) {
  2216. clearTimeout(zoomDisabledTimeout);
  2217. }
  2218. zoomDisabledTimeout = setTimeout(function () {
  2219. zoomDisabledTimeout = null;
  2220. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  2221. }
  2222. function webViewerWheel(evt) {
  2223. const {
  2224. pdfViewer,
  2225. supportedMouseWheelZoomModifierKeys
  2226. } = PDFViewerApplication;
  2227. if (pdfViewer.isInPresentationMode) {
  2228. return;
  2229. }
  2230. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  2231. evt.preventDefault();
  2232. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2233. return;
  2234. }
  2235. const previousScale = pdfViewer.currentScale;
  2236. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2237. let ticks = 0;
  2238. if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE || evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2239. if (Math.abs(delta) >= 1) {
  2240. ticks = Math.sign(delta);
  2241. } else {
  2242. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  2243. }
  2244. } else {
  2245. const PIXELS_PER_LINE_SCALE = 30;
  2246. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  2247. }
  2248. if (ticks < 0) {
  2249. PDFViewerApplication.zoomOut(-ticks);
  2250. } else if (ticks > 0) {
  2251. PDFViewerApplication.zoomIn(ticks);
  2252. }
  2253. const currentScale = pdfViewer.currentScale;
  2254. if (previousScale !== currentScale) {
  2255. const scaleCorrectionFactor = currentScale / previousScale - 1;
  2256. const rect = pdfViewer.container.getBoundingClientRect();
  2257. const dx = evt.clientX - rect.left;
  2258. const dy = evt.clientY - rect.top;
  2259. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  2260. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  2261. }
  2262. } else {
  2263. setZoomDisabledTimeout();
  2264. }
  2265. }
  2266. function webViewerTouchStart(evt) {
  2267. if (evt.touches.length > 1) {
  2268. evt.preventDefault();
  2269. }
  2270. }
  2271. function webViewerClick(evt) {
  2272. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  2273. return;
  2274. }
  2275. const appConfig = PDFViewerApplication.appConfig;
  2276. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  2277. PDFViewerApplication.secondaryToolbar.close();
  2278. }
  2279. }
  2280. function webViewerKeyDown(evt) {
  2281. if (PDFViewerApplication.overlayManager.active) {
  2282. return;
  2283. }
  2284. let handled = false,
  2285. ensureViewerFocused = false;
  2286. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2287. const pdfViewer = PDFViewerApplication.pdfViewer;
  2288. const isViewerInPresentationMode = pdfViewer?.isInPresentationMode;
  2289. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2290. switch (evt.keyCode) {
  2291. case 70:
  2292. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2293. PDFViewerApplication.findBar.open();
  2294. handled = true;
  2295. }
  2296. break;
  2297. case 71:
  2298. if (!PDFViewerApplication.supportsIntegratedFind) {
  2299. const findState = PDFViewerApplication.findController.state;
  2300. if (findState) {
  2301. PDFViewerApplication.findController.executeCommand("findagain", {
  2302. query: findState.query,
  2303. phraseSearch: findState.phraseSearch,
  2304. caseSensitive: findState.caseSensitive,
  2305. entireWord: findState.entireWord,
  2306. highlightAll: findState.highlightAll,
  2307. findPrevious: cmd === 5 || cmd === 12
  2308. });
  2309. }
  2310. handled = true;
  2311. }
  2312. break;
  2313. case 61:
  2314. case 107:
  2315. case 187:
  2316. case 171:
  2317. if (!isViewerInPresentationMode) {
  2318. PDFViewerApplication.zoomIn();
  2319. }
  2320. handled = true;
  2321. break;
  2322. case 173:
  2323. case 109:
  2324. case 189:
  2325. if (!isViewerInPresentationMode) {
  2326. PDFViewerApplication.zoomOut();
  2327. }
  2328. handled = true;
  2329. break;
  2330. case 48:
  2331. case 96:
  2332. if (!isViewerInPresentationMode) {
  2333. setTimeout(function () {
  2334. PDFViewerApplication.zoomReset();
  2335. });
  2336. handled = false;
  2337. }
  2338. break;
  2339. case 38:
  2340. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2341. PDFViewerApplication.page = 1;
  2342. handled = true;
  2343. ensureViewerFocused = true;
  2344. }
  2345. break;
  2346. case 40:
  2347. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2348. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2349. handled = true;
  2350. ensureViewerFocused = true;
  2351. }
  2352. break;
  2353. }
  2354. }
  2355. const {
  2356. eventBus
  2357. } = PDFViewerApplication;
  2358. if (cmd === 1 || cmd === 8) {
  2359. switch (evt.keyCode) {
  2360. case 83:
  2361. eventBus.dispatch("download", {
  2362. source: window
  2363. });
  2364. handled = true;
  2365. break;
  2366. case 79:
  2367. {
  2368. eventBus.dispatch("openfile", {
  2369. source: window
  2370. });
  2371. handled = true;
  2372. }
  2373. break;
  2374. }
  2375. }
  2376. if (cmd === 3 || cmd === 10) {
  2377. switch (evt.keyCode) {
  2378. case 80:
  2379. PDFViewerApplication.requestPresentationMode();
  2380. handled = true;
  2381. break;
  2382. case 71:
  2383. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2384. handled = true;
  2385. break;
  2386. }
  2387. }
  2388. if (handled) {
  2389. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2390. pdfViewer.focus();
  2391. }
  2392. evt.preventDefault();
  2393. return;
  2394. }
  2395. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2396. const curElementTagName = curElement?.tagName.toUpperCase();
  2397. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2398. if (evt.keyCode !== 27) {
  2399. return;
  2400. }
  2401. }
  2402. if (cmd === 0) {
  2403. let turnPage = 0,
  2404. turnOnlyIfPageFit = false;
  2405. switch (evt.keyCode) {
  2406. case 38:
  2407. case 33:
  2408. if (pdfViewer.isVerticalScrollbarEnabled) {
  2409. turnOnlyIfPageFit = true;
  2410. }
  2411. turnPage = -1;
  2412. break;
  2413. case 8:
  2414. if (!isViewerInPresentationMode) {
  2415. turnOnlyIfPageFit = true;
  2416. }
  2417. turnPage = -1;
  2418. break;
  2419. case 37:
  2420. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2421. turnOnlyIfPageFit = true;
  2422. }
  2423. case 75:
  2424. case 80:
  2425. turnPage = -1;
  2426. break;
  2427. case 27:
  2428. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2429. PDFViewerApplication.secondaryToolbar.close();
  2430. handled = true;
  2431. }
  2432. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2433. PDFViewerApplication.findBar.close();
  2434. handled = true;
  2435. }
  2436. break;
  2437. case 40:
  2438. case 34:
  2439. if (pdfViewer.isVerticalScrollbarEnabled) {
  2440. turnOnlyIfPageFit = true;
  2441. }
  2442. turnPage = 1;
  2443. break;
  2444. case 13:
  2445. case 32:
  2446. if (!isViewerInPresentationMode) {
  2447. turnOnlyIfPageFit = true;
  2448. }
  2449. turnPage = 1;
  2450. break;
  2451. case 39:
  2452. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2453. turnOnlyIfPageFit = true;
  2454. }
  2455. case 74:
  2456. case 78:
  2457. turnPage = 1;
  2458. break;
  2459. case 36:
  2460. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2461. PDFViewerApplication.page = 1;
  2462. handled = true;
  2463. ensureViewerFocused = true;
  2464. }
  2465. break;
  2466. case 35:
  2467. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2468. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2469. handled = true;
  2470. ensureViewerFocused = true;
  2471. }
  2472. break;
  2473. case 83:
  2474. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2475. break;
  2476. case 72:
  2477. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2478. break;
  2479. case 82:
  2480. PDFViewerApplication.rotatePages(90);
  2481. break;
  2482. case 115:
  2483. PDFViewerApplication.pdfSidebar.toggle();
  2484. break;
  2485. }
  2486. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2487. if (turnPage > 0) {
  2488. pdfViewer.nextPage();
  2489. } else {
  2490. pdfViewer.previousPage();
  2491. }
  2492. handled = true;
  2493. }
  2494. }
  2495. if (cmd === 4) {
  2496. switch (evt.keyCode) {
  2497. case 13:
  2498. case 32:
  2499. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2500. break;
  2501. }
  2502. if (PDFViewerApplication.page > 1) {
  2503. PDFViewerApplication.page--;
  2504. }
  2505. handled = true;
  2506. break;
  2507. case 82:
  2508. PDFViewerApplication.rotatePages(-90);
  2509. break;
  2510. }
  2511. }
  2512. if (!handled && !isViewerInPresentationMode) {
  2513. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2514. ensureViewerFocused = true;
  2515. }
  2516. }
  2517. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2518. pdfViewer.focus();
  2519. }
  2520. if (handled) {
  2521. evt.preventDefault();
  2522. }
  2523. }
  2524. function beforeUnload(evt) {
  2525. evt.preventDefault();
  2526. evt.returnValue = "";
  2527. return false;
  2528. }
  2529. const PDFPrintServiceFactory = {
  2530. instance: {
  2531. supportsPrinting: false,
  2532. createPrintService() {
  2533. throw new Error("Not implemented: createPrintService");
  2534. }
  2535. }
  2536. };
  2537. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2538. /***/ }),
  2539. /* 4 */
  2540. /***/ ((__unused_webpack_module, exports) => {
  2541. Object.defineProperty(exports, "__esModule", ({
  2542. value: true
  2543. }));
  2544. exports.apiPageLayoutToSpreadMode = apiPageLayoutToSpreadMode;
  2545. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2546. exports.approximateFraction = approximateFraction;
  2547. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2548. exports.binarySearchFirstItem = binarySearchFirstItem;
  2549. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2550. exports.getOutputScale = getOutputScale;
  2551. exports.getPageSizeInches = getPageSizeInches;
  2552. exports.getVisibleElements = getVisibleElements;
  2553. exports.isPortraitOrientation = isPortraitOrientation;
  2554. exports.isValidRotation = isValidRotation;
  2555. exports.isValidScrollMode = isValidScrollMode;
  2556. exports.isValidSpreadMode = isValidSpreadMode;
  2557. exports.moveToEndOfArray = moveToEndOfArray;
  2558. exports.noContextMenuHandler = noContextMenuHandler;
  2559. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2560. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2561. exports.parseQueryString = parseQueryString;
  2562. exports.roundToDivide = roundToDivide;
  2563. exports.scrollIntoView = scrollIntoView;
  2564. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  2565. exports.watchScroll = watchScroll;
  2566. exports.WaitOnType = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.EventBus = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE = exports.CSS_UNITS = exports.AutoPrintRegExp = exports.animationStarted = void 0;
  2567. const CSS_UNITS = 96.0 / 72.0;
  2568. exports.CSS_UNITS = CSS_UNITS;
  2569. const DEFAULT_SCALE_VALUE = "auto";
  2570. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2571. const DEFAULT_SCALE = 1.0;
  2572. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2573. const MIN_SCALE = 0.1;
  2574. exports.MIN_SCALE = MIN_SCALE;
  2575. const MAX_SCALE = 10.0;
  2576. exports.MAX_SCALE = MAX_SCALE;
  2577. const UNKNOWN_SCALE = 0;
  2578. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2579. const MAX_AUTO_SCALE = 1.25;
  2580. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2581. const SCROLLBAR_PADDING = 40;
  2582. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2583. const VERTICAL_PADDING = 5;
  2584. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2585. const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
  2586. const PresentationModeState = {
  2587. UNKNOWN: 0,
  2588. NORMAL: 1,
  2589. CHANGING: 2,
  2590. FULLSCREEN: 3
  2591. };
  2592. exports.PresentationModeState = PresentationModeState;
  2593. const SidebarView = {
  2594. UNKNOWN: -1,
  2595. NONE: 0,
  2596. THUMBS: 1,
  2597. OUTLINE: 2,
  2598. ATTACHMENTS: 3,
  2599. LAYERS: 4
  2600. };
  2601. exports.SidebarView = SidebarView;
  2602. const RendererType = {
  2603. CANVAS: "canvas",
  2604. SVG: "svg"
  2605. };
  2606. exports.RendererType = RendererType;
  2607. const TextLayerMode = {
  2608. DISABLE: 0,
  2609. ENABLE: 1,
  2610. ENABLE_ENHANCE: 2
  2611. };
  2612. exports.TextLayerMode = TextLayerMode;
  2613. const ScrollMode = {
  2614. UNKNOWN: -1,
  2615. VERTICAL: 0,
  2616. HORIZONTAL: 1,
  2617. WRAPPED: 2
  2618. };
  2619. exports.ScrollMode = ScrollMode;
  2620. const SpreadMode = {
  2621. UNKNOWN: -1,
  2622. NONE: 0,
  2623. ODD: 1,
  2624. EVEN: 2
  2625. };
  2626. exports.SpreadMode = SpreadMode;
  2627. const AutoPrintRegExp = /\bprint\s*\(/;
  2628. exports.AutoPrintRegExp = AutoPrintRegExp;
  2629. function getOutputScale(ctx) {
  2630. const devicePixelRatio = window.devicePixelRatio || 1;
  2631. const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  2632. const pixelRatio = devicePixelRatio / backingStoreRatio;
  2633. return {
  2634. sx: pixelRatio,
  2635. sy: pixelRatio,
  2636. scaled: pixelRatio !== 1
  2637. };
  2638. }
  2639. function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
  2640. let parent = element.offsetParent;
  2641. if (!parent) {
  2642. console.error("offsetParent is not set -- cannot scroll");
  2643. return;
  2644. }
  2645. let offsetY = element.offsetTop + element.clientTop;
  2646. let offsetX = element.offsetLeft + element.clientLeft;
  2647. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === "hidden") {
  2648. if (parent.dataset._scaleY) {
  2649. offsetY /= parent.dataset._scaleY;
  2650. offsetX /= parent.dataset._scaleX;
  2651. }
  2652. offsetY += parent.offsetTop;
  2653. offsetX += parent.offsetLeft;
  2654. parent = parent.offsetParent;
  2655. if (!parent) {
  2656. return;
  2657. }
  2658. }
  2659. if (spot) {
  2660. if (spot.top !== undefined) {
  2661. offsetY += spot.top;
  2662. }
  2663. if (spot.left !== undefined) {
  2664. offsetX += spot.left;
  2665. parent.scrollLeft = offsetX;
  2666. }
  2667. }
  2668. parent.scrollTop = offsetY;
  2669. }
  2670. function watchScroll(viewAreaElement, callback) {
  2671. const debounceScroll = function (evt) {
  2672. if (rAF) {
  2673. return;
  2674. }
  2675. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2676. rAF = null;
  2677. const currentX = viewAreaElement.scrollLeft;
  2678. const lastX = state.lastX;
  2679. if (currentX !== lastX) {
  2680. state.right = currentX > lastX;
  2681. }
  2682. state.lastX = currentX;
  2683. const currentY = viewAreaElement.scrollTop;
  2684. const lastY = state.lastY;
  2685. if (currentY !== lastY) {
  2686. state.down = currentY > lastY;
  2687. }
  2688. state.lastY = currentY;
  2689. callback(state);
  2690. });
  2691. };
  2692. const state = {
  2693. right: true,
  2694. down: true,
  2695. lastX: viewAreaElement.scrollLeft,
  2696. lastY: viewAreaElement.scrollTop,
  2697. _eventHandler: debounceScroll
  2698. };
  2699. let rAF = null;
  2700. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2701. return state;
  2702. }
  2703. function parseQueryString(query) {
  2704. const parts = query.split("&");
  2705. const params = Object.create(null);
  2706. for (let i = 0, ii = parts.length; i < ii; ++i) {
  2707. const param = parts[i].split("=");
  2708. const key = param[0].toLowerCase();
  2709. const value = param.length > 1 ? param[1] : null;
  2710. params[decodeURIComponent(key)] = decodeURIComponent(value);
  2711. }
  2712. return params;
  2713. }
  2714. function binarySearchFirstItem(items, condition) {
  2715. let minIndex = 0;
  2716. let maxIndex = items.length - 1;
  2717. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2718. return items.length;
  2719. }
  2720. if (condition(items[minIndex])) {
  2721. return minIndex;
  2722. }
  2723. while (minIndex < maxIndex) {
  2724. const currentIndex = minIndex + maxIndex >> 1;
  2725. const currentItem = items[currentIndex];
  2726. if (condition(currentItem)) {
  2727. maxIndex = currentIndex;
  2728. } else {
  2729. minIndex = currentIndex + 1;
  2730. }
  2731. }
  2732. return minIndex;
  2733. }
  2734. function approximateFraction(x) {
  2735. if (Math.floor(x) === x) {
  2736. return [x, 1];
  2737. }
  2738. const xinv = 1 / x;
  2739. const limit = 8;
  2740. if (xinv > limit) {
  2741. return [1, limit];
  2742. } else if (Math.floor(xinv) === xinv) {
  2743. return [1, xinv];
  2744. }
  2745. const x_ = x > 1 ? xinv : x;
  2746. let a = 0,
  2747. b = 1,
  2748. c = 1,
  2749. d = 1;
  2750. while (true) {
  2751. const p = a + c,
  2752. q = b + d;
  2753. if (q > limit) {
  2754. break;
  2755. }
  2756. if (x_ <= p / q) {
  2757. c = p;
  2758. d = q;
  2759. } else {
  2760. a = p;
  2761. b = q;
  2762. }
  2763. }
  2764. let result;
  2765. if (x_ - a / b < c / d - x_) {
  2766. result = x_ === x ? [a, b] : [b, a];
  2767. } else {
  2768. result = x_ === x ? [c, d] : [d, c];
  2769. }
  2770. return result;
  2771. }
  2772. function roundToDivide(x, div) {
  2773. const r = x % div;
  2774. return r === 0 ? x : Math.round(x - r + div);
  2775. }
  2776. function getPageSizeInches({
  2777. view,
  2778. userUnit,
  2779. rotate
  2780. }) {
  2781. const [x1, y1, x2, y2] = view;
  2782. const changeOrientation = rotate % 180 !== 0;
  2783. const width = (x2 - x1) / 72 * userUnit;
  2784. const height = (y2 - y1) / 72 * userUnit;
  2785. return {
  2786. width: changeOrientation ? height : width,
  2787. height: changeOrientation ? width : height
  2788. };
  2789. }
  2790. function backtrackBeforeAllVisibleElements(index, views, top) {
  2791. if (index < 2) {
  2792. return index;
  2793. }
  2794. let elt = views[index].div;
  2795. let pageTop = elt.offsetTop + elt.clientTop;
  2796. if (pageTop >= top) {
  2797. elt = views[index - 1].div;
  2798. pageTop = elt.offsetTop + elt.clientTop;
  2799. }
  2800. for (let i = index - 2; i >= 0; --i) {
  2801. elt = views[i].div;
  2802. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2803. break;
  2804. }
  2805. index = i;
  2806. }
  2807. return index;
  2808. }
  2809. function getVisibleElements({
  2810. scrollEl,
  2811. views,
  2812. sortByVisibility = false,
  2813. horizontal = false,
  2814. rtl = false
  2815. }) {
  2816. const top = scrollEl.scrollTop,
  2817. bottom = top + scrollEl.clientHeight;
  2818. const left = scrollEl.scrollLeft,
  2819. right = left + scrollEl.clientWidth;
  2820. function isElementBottomAfterViewTop(view) {
  2821. const element = view.div;
  2822. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2823. return elementBottom > top;
  2824. }
  2825. function isElementNextAfterViewHorizontally(view) {
  2826. const element = view.div;
  2827. const elementLeft = element.offsetLeft + element.clientLeft;
  2828. const elementRight = elementLeft + element.clientWidth;
  2829. return rtl ? elementLeft < right : elementRight > left;
  2830. }
  2831. const visible = [],
  2832. numViews = views.length;
  2833. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2834. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2835. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2836. }
  2837. let lastEdge = horizontal ? right : -1;
  2838. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2839. const view = views[i],
  2840. element = view.div;
  2841. const currentWidth = element.offsetLeft + element.clientLeft;
  2842. const currentHeight = element.offsetTop + element.clientTop;
  2843. const viewWidth = element.clientWidth,
  2844. viewHeight = element.clientHeight;
  2845. const viewRight = currentWidth + viewWidth;
  2846. const viewBottom = currentHeight + viewHeight;
  2847. if (lastEdge === -1) {
  2848. if (viewBottom >= bottom) {
  2849. lastEdge = viewBottom;
  2850. }
  2851. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2852. break;
  2853. }
  2854. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2855. continue;
  2856. }
  2857. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2858. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2859. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2860. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2861. const percent = fractionHeight * fractionWidth * 100 | 0;
  2862. visible.push({
  2863. id: view.id,
  2864. x: currentWidth,
  2865. y: currentHeight,
  2866. view,
  2867. percent,
  2868. widthPercent: fractionWidth * 100 | 0
  2869. });
  2870. }
  2871. const first = visible[0],
  2872. last = visible[visible.length - 1];
  2873. if (sortByVisibility) {
  2874. visible.sort(function (a, b) {
  2875. const pc = a.percent - b.percent;
  2876. if (Math.abs(pc) > 0.001) {
  2877. return -pc;
  2878. }
  2879. return a.id - b.id;
  2880. });
  2881. }
  2882. return {
  2883. first,
  2884. last,
  2885. views: visible
  2886. };
  2887. }
  2888. function noContextMenuHandler(evt) {
  2889. evt.preventDefault();
  2890. }
  2891. function normalizeWheelEventDirection(evt) {
  2892. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2893. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2894. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2895. delta = -delta;
  2896. }
  2897. return delta;
  2898. }
  2899. function normalizeWheelEventDelta(evt) {
  2900. let delta = normalizeWheelEventDirection(evt);
  2901. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  2902. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  2903. const MOUSE_PIXELS_PER_LINE = 30;
  2904. const MOUSE_LINES_PER_PAGE = 30;
  2905. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  2906. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2907. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  2908. delta /= MOUSE_LINES_PER_PAGE;
  2909. }
  2910. return delta;
  2911. }
  2912. function isValidRotation(angle) {
  2913. return Number.isInteger(angle) && angle % 90 === 0;
  2914. }
  2915. function isValidScrollMode(mode) {
  2916. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2917. }
  2918. function isValidSpreadMode(mode) {
  2919. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2920. }
  2921. function isPortraitOrientation(size) {
  2922. return size.width <= size.height;
  2923. }
  2924. const WaitOnType = {
  2925. EVENT: "event",
  2926. TIMEOUT: "timeout"
  2927. };
  2928. exports.WaitOnType = WaitOnType;
  2929. function waitOnEventOrTimeout({
  2930. target,
  2931. name,
  2932. delay = 0
  2933. }) {
  2934. return new Promise(function (resolve, reject) {
  2935. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  2936. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  2937. }
  2938. function handler(type) {
  2939. if (target instanceof EventBus) {
  2940. target._off(name, eventHandler);
  2941. } else {
  2942. target.removeEventListener(name, eventHandler);
  2943. }
  2944. if (timeout) {
  2945. clearTimeout(timeout);
  2946. }
  2947. resolve(type);
  2948. }
  2949. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  2950. if (target instanceof EventBus) {
  2951. target._on(name, eventHandler);
  2952. } else {
  2953. target.addEventListener(name, eventHandler);
  2954. }
  2955. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  2956. const timeout = setTimeout(timeoutHandler, delay);
  2957. });
  2958. }
  2959. const animationStarted = new Promise(function (resolve) {
  2960. window.requestAnimationFrame(resolve);
  2961. });
  2962. exports.animationStarted = animationStarted;
  2963. function dispatchDOMEvent(eventName, args = null) {
  2964. throw new Error("Not implemented: dispatchDOMEvent");
  2965. }
  2966. class EventBus {
  2967. constructor(options) {
  2968. this._listeners = Object.create(null);
  2969. }
  2970. on(eventName, listener, options = null) {
  2971. this._on(eventName, listener, {
  2972. external: true,
  2973. once: options?.once
  2974. });
  2975. }
  2976. off(eventName, listener, options = null) {
  2977. this._off(eventName, listener, {
  2978. external: true,
  2979. once: options?.once
  2980. });
  2981. }
  2982. dispatch(eventName) {
  2983. const eventListeners = this._listeners[eventName];
  2984. if (!eventListeners || eventListeners.length === 0) {
  2985. return;
  2986. }
  2987. const args = Array.prototype.slice.call(arguments, 1);
  2988. let externalListeners;
  2989. for (const {
  2990. listener,
  2991. external,
  2992. once
  2993. } of eventListeners.slice(0)) {
  2994. if (once) {
  2995. this._off(eventName, listener);
  2996. }
  2997. if (external) {
  2998. (externalListeners || (externalListeners = [])).push(listener);
  2999. continue;
  3000. }
  3001. listener.apply(null, args);
  3002. }
  3003. if (externalListeners) {
  3004. for (const listener of externalListeners) {
  3005. listener.apply(null, args);
  3006. }
  3007. externalListeners = null;
  3008. }
  3009. }
  3010. _on(eventName, listener, options = null) {
  3011. var _this$_listeners;
  3012. const eventListeners = (_this$_listeners = this._listeners)[eventName] || (_this$_listeners[eventName] = []);
  3013. eventListeners.push({
  3014. listener,
  3015. external: options?.external === true,
  3016. once: options?.once === true
  3017. });
  3018. }
  3019. _off(eventName, listener, options = null) {
  3020. const eventListeners = this._listeners[eventName];
  3021. if (!eventListeners) {
  3022. return;
  3023. }
  3024. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3025. if (eventListeners[i].listener === listener) {
  3026. eventListeners.splice(i, 1);
  3027. return;
  3028. }
  3029. }
  3030. }
  3031. }
  3032. exports.EventBus = EventBus;
  3033. function clamp(v, min, max) {
  3034. return Math.min(Math.max(v, min), max);
  3035. }
  3036. class ProgressBar {
  3037. constructor(id, {
  3038. height,
  3039. width,
  3040. units
  3041. } = {}) {
  3042. this.visible = true;
  3043. this.div = document.querySelector(id + " .progress");
  3044. this.bar = this.div.parentNode;
  3045. this.height = height || 100;
  3046. this.width = width || 100;
  3047. this.units = units || "%";
  3048. this.div.style.height = this.height + this.units;
  3049. this.percent = 0;
  3050. }
  3051. _updateBar() {
  3052. if (this._indeterminate) {
  3053. this.div.classList.add("indeterminate");
  3054. this.div.style.width = this.width + this.units;
  3055. return;
  3056. }
  3057. this.div.classList.remove("indeterminate");
  3058. const progressSize = this.width * this._percent / 100;
  3059. this.div.style.width = progressSize + this.units;
  3060. }
  3061. get percent() {
  3062. return this._percent;
  3063. }
  3064. set percent(val) {
  3065. this._indeterminate = isNaN(val);
  3066. this._percent = clamp(val, 0, 100);
  3067. this._updateBar();
  3068. }
  3069. setWidth(viewer) {
  3070. if (!viewer) {
  3071. return;
  3072. }
  3073. const container = viewer.parentNode;
  3074. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  3075. if (scrollbarWidth > 0) {
  3076. const doc = document.documentElement;
  3077. doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
  3078. }
  3079. }
  3080. hide() {
  3081. if (!this.visible) {
  3082. return;
  3083. }
  3084. this.visible = false;
  3085. this.bar.classList.add("hidden");
  3086. }
  3087. show() {
  3088. if (this.visible) {
  3089. return;
  3090. }
  3091. this.visible = true;
  3092. this.bar.classList.remove("hidden");
  3093. }
  3094. }
  3095. exports.ProgressBar = ProgressBar;
  3096. function moveToEndOfArray(arr, condition) {
  3097. const moved = [],
  3098. len = arr.length;
  3099. let write = 0;
  3100. for (let read = 0; read < len; ++read) {
  3101. if (condition(arr[read])) {
  3102. moved.push(arr[read]);
  3103. } else {
  3104. arr[write] = arr[read];
  3105. ++write;
  3106. }
  3107. }
  3108. for (let read = 0; write < len; ++read, ++write) {
  3109. arr[write] = moved[read];
  3110. }
  3111. }
  3112. function getActiveOrFocusedElement() {
  3113. let curRoot = document;
  3114. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3115. while (curActiveOrFocused?.shadowRoot) {
  3116. curRoot = curActiveOrFocused.shadowRoot;
  3117. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3118. }
  3119. return curActiveOrFocused;
  3120. }
  3121. function apiPageLayoutToSpreadMode(layout) {
  3122. switch (layout) {
  3123. case "SinglePage":
  3124. case "OneColumn":
  3125. return SpreadMode.NONE;
  3126. case "TwoColumnLeft":
  3127. case "TwoPageLeft":
  3128. return SpreadMode.ODD;
  3129. case "TwoColumnRight":
  3130. case "TwoPageRight":
  3131. return SpreadMode.EVEN;
  3132. }
  3133. return SpreadMode.NONE;
  3134. }
  3135. function apiPageModeToSidebarView(mode) {
  3136. switch (mode) {
  3137. case "UseNone":
  3138. return SidebarView.NONE;
  3139. case "UseThumbs":
  3140. return SidebarView.THUMBS;
  3141. case "UseOutlines":
  3142. return SidebarView.OUTLINE;
  3143. case "UseAttachments":
  3144. return SidebarView.ATTACHMENTS;
  3145. case "UseOC":
  3146. return SidebarView.LAYERS;
  3147. }
  3148. return SidebarView.NONE;
  3149. }
  3150. /***/ }),
  3151. /* 5 */
  3152. /***/ ((module) => {
  3153. let pdfjsLib;
  3154. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3155. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3156. } else {
  3157. pdfjsLib = require("../build/pdf.js");
  3158. }
  3159. module.exports = pdfjsLib;
  3160. /***/ }),
  3161. /* 6 */
  3162. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3163. Object.defineProperty(exports, "__esModule", ({
  3164. value: true
  3165. }));
  3166. exports.PDFCursorTools = exports.CursorTool = void 0;
  3167. var _grab_to_pan = __webpack_require__(7);
  3168. var _ui_utils = __webpack_require__(4);
  3169. const CursorTool = {
  3170. SELECT: 0,
  3171. HAND: 1,
  3172. ZOOM: 2
  3173. };
  3174. exports.CursorTool = CursorTool;
  3175. class PDFCursorTools {
  3176. constructor({
  3177. container,
  3178. eventBus,
  3179. cursorToolOnLoad = CursorTool.SELECT
  3180. }) {
  3181. this.container = container;
  3182. this.eventBus = eventBus;
  3183. this.active = CursorTool.SELECT;
  3184. this.activeBeforePresentationMode = null;
  3185. this.handTool = new _grab_to_pan.GrabToPan({
  3186. element: this.container
  3187. });
  3188. this._addEventListeners();
  3189. Promise.resolve().then(() => {
  3190. this.switchTool(cursorToolOnLoad);
  3191. });
  3192. }
  3193. get activeTool() {
  3194. return this.active;
  3195. }
  3196. switchTool(tool) {
  3197. if (this.activeBeforePresentationMode !== null) {
  3198. return;
  3199. }
  3200. if (tool === this.active) {
  3201. return;
  3202. }
  3203. const disableActiveTool = () => {
  3204. switch (this.active) {
  3205. case CursorTool.SELECT:
  3206. break;
  3207. case CursorTool.HAND:
  3208. this.handTool.deactivate();
  3209. break;
  3210. case CursorTool.ZOOM:
  3211. }
  3212. };
  3213. switch (tool) {
  3214. case CursorTool.SELECT:
  3215. disableActiveTool();
  3216. break;
  3217. case CursorTool.HAND:
  3218. disableActiveTool();
  3219. this.handTool.activate();
  3220. break;
  3221. case CursorTool.ZOOM:
  3222. default:
  3223. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3224. return;
  3225. }
  3226. this.active = tool;
  3227. this._dispatchEvent();
  3228. }
  3229. _dispatchEvent() {
  3230. this.eventBus.dispatch("cursortoolchanged", {
  3231. source: this,
  3232. tool: this.active
  3233. });
  3234. }
  3235. _addEventListeners() {
  3236. this.eventBus._on("switchcursortool", evt => {
  3237. this.switchTool(evt.tool);
  3238. });
  3239. this.eventBus._on("presentationmodechanged", evt => {
  3240. switch (evt.state) {
  3241. case _ui_utils.PresentationModeState.FULLSCREEN:
  3242. {
  3243. const previouslyActive = this.active;
  3244. this.switchTool(CursorTool.SELECT);
  3245. this.activeBeforePresentationMode = previouslyActive;
  3246. break;
  3247. }
  3248. case _ui_utils.PresentationModeState.NORMAL:
  3249. {
  3250. const previouslyActive = this.activeBeforePresentationMode;
  3251. this.activeBeforePresentationMode = null;
  3252. this.switchTool(previouslyActive);
  3253. break;
  3254. }
  3255. }
  3256. });
  3257. }
  3258. }
  3259. exports.PDFCursorTools = PDFCursorTools;
  3260. /***/ }),
  3261. /* 7 */
  3262. /***/ ((__unused_webpack_module, exports) => {
  3263. Object.defineProperty(exports, "__esModule", ({
  3264. value: true
  3265. }));
  3266. exports.GrabToPan = GrabToPan;
  3267. function GrabToPan(options) {
  3268. this.element = options.element;
  3269. this.document = options.element.ownerDocument;
  3270. if (typeof options.ignoreTarget === "function") {
  3271. this.ignoreTarget = options.ignoreTarget;
  3272. }
  3273. this.onActiveChanged = options.onActiveChanged;
  3274. this.activate = this.activate.bind(this);
  3275. this.deactivate = this.deactivate.bind(this);
  3276. this.toggle = this.toggle.bind(this);
  3277. this._onmousedown = this._onmousedown.bind(this);
  3278. this._onmousemove = this._onmousemove.bind(this);
  3279. this._endPan = this._endPan.bind(this);
  3280. const overlay = this.overlay = document.createElement("div");
  3281. overlay.className = "grab-to-pan-grabbing";
  3282. }
  3283. GrabToPan.prototype = {
  3284. CSS_CLASS_GRAB: "grab-to-pan-grab",
  3285. activate: function GrabToPan_activate() {
  3286. if (!this.active) {
  3287. this.active = true;
  3288. this.element.addEventListener("mousedown", this._onmousedown, true);
  3289. this.element.classList.add(this.CSS_CLASS_GRAB);
  3290. if (this.onActiveChanged) {
  3291. this.onActiveChanged(true);
  3292. }
  3293. }
  3294. },
  3295. deactivate: function GrabToPan_deactivate() {
  3296. if (this.active) {
  3297. this.active = false;
  3298. this.element.removeEventListener("mousedown", this._onmousedown, true);
  3299. this._endPan();
  3300. this.element.classList.remove(this.CSS_CLASS_GRAB);
  3301. if (this.onActiveChanged) {
  3302. this.onActiveChanged(false);
  3303. }
  3304. }
  3305. },
  3306. toggle: function GrabToPan_toggle() {
  3307. if (this.active) {
  3308. this.deactivate();
  3309. } else {
  3310. this.activate();
  3311. }
  3312. },
  3313. ignoreTarget: function GrabToPan_ignoreTarget(node) {
  3314. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3315. },
  3316. _onmousedown: function GrabToPan__onmousedown(event) {
  3317. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3318. return;
  3319. }
  3320. if (event.originalTarget) {
  3321. try {
  3322. event.originalTarget.tagName;
  3323. } catch (e) {
  3324. return;
  3325. }
  3326. }
  3327. this.scrollLeftStart = this.element.scrollLeft;
  3328. this.scrollTopStart = this.element.scrollTop;
  3329. this.clientXStart = event.clientX;
  3330. this.clientYStart = event.clientY;
  3331. this.document.addEventListener("mousemove", this._onmousemove, true);
  3332. this.document.addEventListener("mouseup", this._endPan, true);
  3333. this.element.addEventListener("scroll", this._endPan, true);
  3334. event.preventDefault();
  3335. event.stopPropagation();
  3336. const focusedElement = document.activeElement;
  3337. if (focusedElement && !focusedElement.contains(event.target)) {
  3338. focusedElement.blur();
  3339. }
  3340. },
  3341. _onmousemove: function GrabToPan__onmousemove(event) {
  3342. this.element.removeEventListener("scroll", this._endPan, true);
  3343. if (isLeftMouseReleased(event)) {
  3344. this._endPan();
  3345. return;
  3346. }
  3347. const xDiff = event.clientX - this.clientXStart;
  3348. const yDiff = event.clientY - this.clientYStart;
  3349. const scrollTop = this.scrollTopStart - yDiff;
  3350. const scrollLeft = this.scrollLeftStart - xDiff;
  3351. if (this.element.scrollTo) {
  3352. this.element.scrollTo({
  3353. top: scrollTop,
  3354. left: scrollLeft,
  3355. behavior: "instant"
  3356. });
  3357. } else {
  3358. this.element.scrollTop = scrollTop;
  3359. this.element.scrollLeft = scrollLeft;
  3360. }
  3361. if (!this.overlay.parentNode) {
  3362. document.body.appendChild(this.overlay);
  3363. }
  3364. },
  3365. _endPan: function GrabToPan__endPan() {
  3366. this.element.removeEventListener("scroll", this._endPan, true);
  3367. this.document.removeEventListener("mousemove", this._onmousemove, true);
  3368. this.document.removeEventListener("mouseup", this._endPan, true);
  3369. this.overlay.remove();
  3370. }
  3371. };
  3372. function isLeftMouseReleased(event) {
  3373. if ("buttons" in event) {
  3374. return !(event.buttons & 1);
  3375. }
  3376. const chrome = window.chrome;
  3377. const isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
  3378. const isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
  3379. if (isChrome15OrOpera15plus || isSafari6plus) {
  3380. return event.which === 0;
  3381. }
  3382. return false;
  3383. }
  3384. /***/ }),
  3385. /* 8 */
  3386. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3387. Object.defineProperty(exports, "__esModule", ({
  3388. value: true
  3389. }));
  3390. exports.RenderingStates = exports.PDFRenderingQueue = void 0;
  3391. var _pdfjsLib = __webpack_require__(5);
  3392. const CLEANUP_TIMEOUT = 30000;
  3393. const RenderingStates = {
  3394. INITIAL: 0,
  3395. RUNNING: 1,
  3396. PAUSED: 2,
  3397. FINISHED: 3
  3398. };
  3399. exports.RenderingStates = RenderingStates;
  3400. class PDFRenderingQueue {
  3401. constructor() {
  3402. this.pdfViewer = null;
  3403. this.pdfThumbnailViewer = null;
  3404. this.onIdle = null;
  3405. this.highestPriorityPage = null;
  3406. this.idleTimeout = null;
  3407. this.printing = false;
  3408. this.isThumbnailViewEnabled = false;
  3409. }
  3410. setViewer(pdfViewer) {
  3411. this.pdfViewer = pdfViewer;
  3412. }
  3413. setThumbnailViewer(pdfThumbnailViewer) {
  3414. this.pdfThumbnailViewer = pdfThumbnailViewer;
  3415. }
  3416. isHighestPriority(view) {
  3417. return this.highestPriorityPage === view.renderingId;
  3418. }
  3419. renderHighestPriority(currentlyVisiblePages) {
  3420. if (this.idleTimeout) {
  3421. clearTimeout(this.idleTimeout);
  3422. this.idleTimeout = null;
  3423. }
  3424. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  3425. return;
  3426. }
  3427. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  3428. if (this.pdfThumbnailViewer.forceRendering()) {
  3429. return;
  3430. }
  3431. }
  3432. if (this.printing) {
  3433. return;
  3434. }
  3435. if (this.onIdle) {
  3436. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  3437. }
  3438. }
  3439. getHighestPriority(visible, views, scrolledDown) {
  3440. const visibleViews = visible.views;
  3441. const numVisible = visibleViews.length;
  3442. if (numVisible === 0) {
  3443. return null;
  3444. }
  3445. for (let i = 0; i < numVisible; ++i) {
  3446. const view = visibleViews[i].view;
  3447. if (!this.isViewFinished(view)) {
  3448. return view;
  3449. }
  3450. }
  3451. if (scrolledDown) {
  3452. const nextPageIndex = visible.last.id;
  3453. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  3454. return views[nextPageIndex];
  3455. }
  3456. } else {
  3457. const previousPageIndex = visible.first.id - 2;
  3458. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  3459. return views[previousPageIndex];
  3460. }
  3461. }
  3462. return null;
  3463. }
  3464. isViewFinished(view) {
  3465. return view.renderingState === RenderingStates.FINISHED;
  3466. }
  3467. renderView(view) {
  3468. switch (view.renderingState) {
  3469. case RenderingStates.FINISHED:
  3470. return false;
  3471. case RenderingStates.PAUSED:
  3472. this.highestPriorityPage = view.renderingId;
  3473. view.resume();
  3474. break;
  3475. case RenderingStates.RUNNING:
  3476. this.highestPriorityPage = view.renderingId;
  3477. break;
  3478. case RenderingStates.INITIAL:
  3479. this.highestPriorityPage = view.renderingId;
  3480. view.draw().finally(() => {
  3481. this.renderHighestPriority();
  3482. }).catch(reason => {
  3483. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  3484. return;
  3485. }
  3486. console.error(`renderView: "${reason}"`);
  3487. });
  3488. break;
  3489. }
  3490. return true;
  3491. }
  3492. }
  3493. exports.PDFRenderingQueue = PDFRenderingQueue;
  3494. /***/ }),
  3495. /* 9 */
  3496. /***/ ((__unused_webpack_module, exports) => {
  3497. Object.defineProperty(exports, "__esModule", ({
  3498. value: true
  3499. }));
  3500. exports.OverlayManager = void 0;
  3501. class OverlayManager {
  3502. constructor() {
  3503. this._overlays = {};
  3504. this._active = null;
  3505. this._keyDownBound = this._keyDown.bind(this);
  3506. }
  3507. get active() {
  3508. return this._active;
  3509. }
  3510. async register(name, element, callerCloseMethod = null, canForceClose = false) {
  3511. let container;
  3512. if (!name || !element || !(container = element.parentNode)) {
  3513. throw new Error("Not enough parameters.");
  3514. } else if (this._overlays[name]) {
  3515. throw new Error("The overlay is already registered.");
  3516. }
  3517. this._overlays[name] = {
  3518. element,
  3519. container,
  3520. callerCloseMethod,
  3521. canForceClose
  3522. };
  3523. }
  3524. async unregister(name) {
  3525. if (!this._overlays[name]) {
  3526. throw new Error("The overlay does not exist.");
  3527. } else if (this._active === name) {
  3528. throw new Error("The overlay cannot be removed while it is active.");
  3529. }
  3530. delete this._overlays[name];
  3531. }
  3532. async open(name) {
  3533. if (!this._overlays[name]) {
  3534. throw new Error("The overlay does not exist.");
  3535. } else if (this._active) {
  3536. if (this._overlays[name].canForceClose) {
  3537. this._closeThroughCaller();
  3538. } else if (this._active === name) {
  3539. throw new Error("The overlay is already active.");
  3540. } else {
  3541. throw new Error("Another overlay is currently active.");
  3542. }
  3543. }
  3544. this._active = name;
  3545. this._overlays[this._active].element.classList.remove("hidden");
  3546. this._overlays[this._active].container.classList.remove("hidden");
  3547. window.addEventListener("keydown", this._keyDownBound);
  3548. }
  3549. async close(name) {
  3550. if (!this._overlays[name]) {
  3551. throw new Error("The overlay does not exist.");
  3552. } else if (!this._active) {
  3553. throw new Error("The overlay is currently not active.");
  3554. } else if (this._active !== name) {
  3555. throw new Error("Another overlay is currently active.");
  3556. }
  3557. this._overlays[this._active].container.classList.add("hidden");
  3558. this._overlays[this._active].element.classList.add("hidden");
  3559. this._active = null;
  3560. window.removeEventListener("keydown", this._keyDownBound);
  3561. }
  3562. _keyDown(evt) {
  3563. if (this._active && evt.keyCode === 27) {
  3564. this._closeThroughCaller();
  3565. evt.preventDefault();
  3566. }
  3567. }
  3568. _closeThroughCaller() {
  3569. if (this._overlays[this._active].callerCloseMethod) {
  3570. this._overlays[this._active].callerCloseMethod();
  3571. }
  3572. if (this._active) {
  3573. this.close(this._active);
  3574. }
  3575. }
  3576. }
  3577. exports.OverlayManager = OverlayManager;
  3578. /***/ }),
  3579. /* 10 */
  3580. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3581. Object.defineProperty(exports, "__esModule", ({
  3582. value: true
  3583. }));
  3584. exports.PasswordPrompt = void 0;
  3585. var _pdfjsLib = __webpack_require__(5);
  3586. class PasswordPrompt {
  3587. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3588. this.overlayName = options.overlayName;
  3589. this.container = options.container;
  3590. this.label = options.label;
  3591. this.input = options.input;
  3592. this.submitButton = options.submitButton;
  3593. this.cancelButton = options.cancelButton;
  3594. this.overlayManager = overlayManager;
  3595. this.l10n = l10n;
  3596. this._isViewerEmbedded = isViewerEmbedded;
  3597. this.updateCallback = null;
  3598. this.reason = null;
  3599. this.submitButton.addEventListener("click", this.verify.bind(this));
  3600. this.cancelButton.addEventListener("click", this.close.bind(this));
  3601. this.input.addEventListener("keydown", e => {
  3602. if (e.keyCode === 13) {
  3603. this.verify();
  3604. }
  3605. });
  3606. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  3607. }
  3608. async open() {
  3609. await this.overlayManager.open(this.overlayName);
  3610. const passwordIncorrect = this.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3611. if (!this._isViewerEmbedded || passwordIncorrect) {
  3612. this.input.focus();
  3613. }
  3614. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3615. }
  3616. close() {
  3617. this.overlayManager.close(this.overlayName).then(() => {
  3618. this.input.value = "";
  3619. });
  3620. }
  3621. verify() {
  3622. const password = this.input.value;
  3623. if (password?.length > 0) {
  3624. this.close();
  3625. this.updateCallback(password);
  3626. }
  3627. }
  3628. setUpdateCallback(updateCallback, reason) {
  3629. this.updateCallback = updateCallback;
  3630. this.reason = reason;
  3631. }
  3632. }
  3633. exports.PasswordPrompt = PasswordPrompt;
  3634. /***/ }),
  3635. /* 11 */
  3636. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3637. Object.defineProperty(exports, "__esModule", ({
  3638. value: true
  3639. }));
  3640. exports.PDFAttachmentViewer = void 0;
  3641. var _pdfjsLib = __webpack_require__(5);
  3642. var _base_tree_viewer = __webpack_require__(12);
  3643. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  3644. constructor(options) {
  3645. super(options);
  3646. this.downloadManager = options.downloadManager;
  3647. this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
  3648. }
  3649. reset(keepRenderedCapability = false) {
  3650. super.reset();
  3651. this._attachments = null;
  3652. if (!keepRenderedCapability) {
  3653. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  3654. }
  3655. if (this._pendingDispatchEvent) {
  3656. clearTimeout(this._pendingDispatchEvent);
  3657. }
  3658. this._pendingDispatchEvent = null;
  3659. }
  3660. _dispatchEvent(attachmentsCount) {
  3661. this._renderedCapability.resolve();
  3662. if (this._pendingDispatchEvent) {
  3663. clearTimeout(this._pendingDispatchEvent);
  3664. this._pendingDispatchEvent = null;
  3665. }
  3666. if (attachmentsCount === 0) {
  3667. this._pendingDispatchEvent = setTimeout(() => {
  3668. this.eventBus.dispatch("attachmentsloaded", {
  3669. source: this,
  3670. attachmentsCount: 0
  3671. });
  3672. this._pendingDispatchEvent = null;
  3673. });
  3674. return;
  3675. }
  3676. this.eventBus.dispatch("attachmentsloaded", {
  3677. source: this,
  3678. attachmentsCount
  3679. });
  3680. }
  3681. _bindLink(element, {
  3682. content,
  3683. filename
  3684. }) {
  3685. element.onclick = () => {
  3686. this.downloadManager.openOrDownloadData(element, content, filename);
  3687. return false;
  3688. };
  3689. }
  3690. render({
  3691. attachments,
  3692. keepRenderedCapability = false
  3693. }) {
  3694. if (this._attachments) {
  3695. this.reset(keepRenderedCapability);
  3696. }
  3697. this._attachments = attachments || null;
  3698. if (!attachments) {
  3699. this._dispatchEvent(0);
  3700. return;
  3701. }
  3702. const names = Object.keys(attachments).sort(function (a, b) {
  3703. return a.toLowerCase().localeCompare(b.toLowerCase());
  3704. });
  3705. const fragment = document.createDocumentFragment();
  3706. let attachmentsCount = 0;
  3707. for (const name of names) {
  3708. const item = attachments[name];
  3709. const content = item.content,
  3710. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  3711. const div = document.createElement("div");
  3712. div.className = "treeItem";
  3713. const element = document.createElement("a");
  3714. this._bindLink(element, {
  3715. content,
  3716. filename
  3717. });
  3718. element.textContent = this._normalizeTextContent(filename);
  3719. div.appendChild(element);
  3720. fragment.appendChild(div);
  3721. attachmentsCount++;
  3722. }
  3723. this._finishRendering(fragment, attachmentsCount);
  3724. }
  3725. _appendAttachment({
  3726. id,
  3727. filename,
  3728. content
  3729. }) {
  3730. const renderedPromise = this._renderedCapability.promise;
  3731. renderedPromise.then(() => {
  3732. if (renderedPromise !== this._renderedCapability.promise) {
  3733. return;
  3734. }
  3735. let attachments = this._attachments;
  3736. if (!attachments) {
  3737. attachments = Object.create(null);
  3738. } else {
  3739. for (const name in attachments) {
  3740. if (id === name) {
  3741. return;
  3742. }
  3743. }
  3744. }
  3745. attachments[id] = {
  3746. filename,
  3747. content
  3748. };
  3749. this.render({
  3750. attachments,
  3751. keepRenderedCapability: true
  3752. });
  3753. });
  3754. }
  3755. }
  3756. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  3757. /***/ }),
  3758. /* 12 */
  3759. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3760. Object.defineProperty(exports, "__esModule", ({
  3761. value: true
  3762. }));
  3763. exports.BaseTreeViewer = void 0;
  3764. var _pdfjsLib = __webpack_require__(5);
  3765. const TREEITEM_OFFSET_TOP = -100;
  3766. const TREEITEM_SELECTED_CLASS = "selected";
  3767. class BaseTreeViewer {
  3768. constructor(options) {
  3769. if (this.constructor === BaseTreeViewer) {
  3770. throw new Error("Cannot initialize BaseTreeViewer.");
  3771. }
  3772. this.container = options.container;
  3773. this.eventBus = options.eventBus;
  3774. this.reset();
  3775. }
  3776. reset() {
  3777. this._pdfDocument = null;
  3778. this._lastToggleIsShow = true;
  3779. this._currentTreeItem = null;
  3780. this.container.textContent = "";
  3781. this.container.classList.remove("treeWithDeepNesting");
  3782. }
  3783. _dispatchEvent(count) {
  3784. throw new Error("Not implemented: _dispatchEvent");
  3785. }
  3786. _bindLink(element, params) {
  3787. throw new Error("Not implemented: _bindLink");
  3788. }
  3789. _normalizeTextContent(str) {
  3790. return (0, _pdfjsLib.removeNullCharacters)(str) || "\u2013";
  3791. }
  3792. _addToggleButton(div, hidden = false) {
  3793. const toggler = document.createElement("div");
  3794. toggler.className = "treeItemToggler";
  3795. if (hidden) {
  3796. toggler.classList.add("treeItemsHidden");
  3797. }
  3798. toggler.onclick = evt => {
  3799. evt.stopPropagation();
  3800. toggler.classList.toggle("treeItemsHidden");
  3801. if (evt.shiftKey) {
  3802. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  3803. this._toggleTreeItem(div, shouldShowAll);
  3804. }
  3805. };
  3806. div.insertBefore(toggler, div.firstChild);
  3807. }
  3808. _toggleTreeItem(root, show = false) {
  3809. this._lastToggleIsShow = show;
  3810. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  3811. toggler.classList.toggle("treeItemsHidden", !show);
  3812. }
  3813. }
  3814. _toggleAllTreeItems() {
  3815. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  3816. }
  3817. _finishRendering(fragment, count, hasAnyNesting = false) {
  3818. if (hasAnyNesting) {
  3819. this.container.classList.add("treeWithDeepNesting");
  3820. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  3821. }
  3822. this.container.appendChild(fragment);
  3823. this._dispatchEvent(count);
  3824. }
  3825. render(params) {
  3826. throw new Error("Not implemented: render");
  3827. }
  3828. _updateCurrentTreeItem(treeItem = null) {
  3829. if (this._currentTreeItem) {
  3830. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  3831. this._currentTreeItem = null;
  3832. }
  3833. if (treeItem) {
  3834. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  3835. this._currentTreeItem = treeItem;
  3836. }
  3837. }
  3838. _scrollToCurrentTreeItem(treeItem) {
  3839. if (!treeItem) {
  3840. return;
  3841. }
  3842. let currentNode = treeItem.parentNode;
  3843. while (currentNode && currentNode !== this.container) {
  3844. if (currentNode.classList.contains("treeItem")) {
  3845. const toggler = currentNode.firstElementChild;
  3846. toggler?.classList.remove("treeItemsHidden");
  3847. }
  3848. currentNode = currentNode.parentNode;
  3849. }
  3850. this._updateCurrentTreeItem(treeItem);
  3851. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  3852. }
  3853. }
  3854. exports.BaseTreeViewer = BaseTreeViewer;
  3855. /***/ }),
  3856. /* 13 */
  3857. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3858. Object.defineProperty(exports, "__esModule", ({
  3859. value: true
  3860. }));
  3861. exports.PDFDocumentProperties = void 0;
  3862. var _pdfjsLib = __webpack_require__(5);
  3863. var _ui_utils = __webpack_require__(4);
  3864. const DEFAULT_FIELD_CONTENT = "-";
  3865. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  3866. const US_PAGE_NAMES = {
  3867. "8.5x11": "Letter",
  3868. "8.5x14": "Legal"
  3869. };
  3870. const METRIC_PAGE_NAMES = {
  3871. "297x420": "A3",
  3872. "210x297": "A4"
  3873. };
  3874. function getPageName(size, isPortrait, pageNames) {
  3875. const width = isPortrait ? size.width : size.height;
  3876. const height = isPortrait ? size.height : size.width;
  3877. return pageNames[`${width}x${height}`];
  3878. }
  3879. class PDFDocumentProperties {
  3880. constructor({
  3881. overlayName,
  3882. fields,
  3883. container,
  3884. closeButton
  3885. }, overlayManager, eventBus, l10n) {
  3886. this.overlayName = overlayName;
  3887. this.fields = fields;
  3888. this.container = container;
  3889. this.overlayManager = overlayManager;
  3890. this.l10n = l10n;
  3891. this._reset();
  3892. closeButton.addEventListener("click", this.close.bind(this));
  3893. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  3894. eventBus._on("pagechanging", evt => {
  3895. this._currentPageNumber = evt.pageNumber;
  3896. });
  3897. eventBus._on("rotationchanging", evt => {
  3898. this._pagesRotation = evt.pagesRotation;
  3899. });
  3900. this._isNonMetricLocale = true;
  3901. l10n.getLanguage().then(locale => {
  3902. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  3903. });
  3904. }
  3905. async open() {
  3906. const freezeFieldData = data => {
  3907. Object.defineProperty(this, "fieldData", {
  3908. value: Object.freeze(data),
  3909. writable: false,
  3910. enumerable: true,
  3911. configurable: true
  3912. });
  3913. };
  3914. await Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]);
  3915. const currentPageNumber = this._currentPageNumber;
  3916. const pagesRotation = this._pagesRotation;
  3917. if (this.fieldData && currentPageNumber === this.fieldData._currentPageNumber && pagesRotation === this.fieldData._pagesRotation) {
  3918. this._updateUI();
  3919. return;
  3920. }
  3921. const {
  3922. info,
  3923. contentDispositionFilename,
  3924. contentLength
  3925. } = await this.pdfDocument.getMetadata();
  3926. 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 => {
  3927. return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  3928. }), this._parseLinearization(info.IsLinearized)]);
  3929. freezeFieldData({
  3930. fileName,
  3931. fileSize,
  3932. title: info.Title,
  3933. author: info.Author,
  3934. subject: info.Subject,
  3935. keywords: info.Keywords,
  3936. creationDate,
  3937. modificationDate,
  3938. creator: info.Creator,
  3939. producer: info.Producer,
  3940. version: info.PDFFormatVersion,
  3941. pageCount: this.pdfDocument.numPages,
  3942. pageSize,
  3943. linearized: isLinearized,
  3944. _currentPageNumber: currentPageNumber,
  3945. _pagesRotation: pagesRotation
  3946. });
  3947. this._updateUI();
  3948. const {
  3949. length
  3950. } = await this.pdfDocument.getDownloadInfo();
  3951. if (contentLength === length) {
  3952. return;
  3953. }
  3954. const data = Object.assign(Object.create(null), this.fieldData);
  3955. data.fileSize = await this._parseFileSize(length);
  3956. freezeFieldData(data);
  3957. this._updateUI();
  3958. }
  3959. close() {
  3960. this.overlayManager.close(this.overlayName);
  3961. }
  3962. setDocument(pdfDocument, url = null) {
  3963. if (this.pdfDocument) {
  3964. this._reset();
  3965. this._updateUI(true);
  3966. }
  3967. if (!pdfDocument) {
  3968. return;
  3969. }
  3970. this.pdfDocument = pdfDocument;
  3971. this.url = url;
  3972. this._dataAvailableCapability.resolve();
  3973. }
  3974. _reset() {
  3975. this.pdfDocument = null;
  3976. this.url = null;
  3977. delete this.fieldData;
  3978. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  3979. this._currentPageNumber = 1;
  3980. this._pagesRotation = 0;
  3981. }
  3982. _updateUI(reset = false) {
  3983. if (reset || !this.fieldData) {
  3984. for (const id in this.fields) {
  3985. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  3986. }
  3987. return;
  3988. }
  3989. if (this.overlayManager.active !== this.overlayName) {
  3990. return;
  3991. }
  3992. for (const id in this.fields) {
  3993. const content = this.fieldData[id];
  3994. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  3995. }
  3996. }
  3997. async _parseFileSize(fileSize = 0) {
  3998. const kb = fileSize / 1024,
  3999. mb = kb / 1024;
  4000. if (!kb) {
  4001. return undefined;
  4002. }
  4003. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4004. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4005. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4006. size_b: fileSize.toLocaleString()
  4007. });
  4008. }
  4009. async _parsePageSize(pageSizeInches, pagesRotation) {
  4010. if (!pageSizeInches) {
  4011. return undefined;
  4012. }
  4013. if (pagesRotation % 180 !== 0) {
  4014. pageSizeInches = {
  4015. width: pageSizeInches.height,
  4016. height: pageSizeInches.width
  4017. };
  4018. }
  4019. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4020. let sizeInches = {
  4021. width: Math.round(pageSizeInches.width * 100) / 100,
  4022. height: Math.round(pageSizeInches.height * 100) / 100
  4023. };
  4024. let sizeMillimeters = {
  4025. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4026. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4027. };
  4028. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4029. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4030. const exactMillimeters = {
  4031. width: pageSizeInches.width * 25.4,
  4032. height: pageSizeInches.height * 25.4
  4033. };
  4034. const intMillimeters = {
  4035. width: Math.round(sizeMillimeters.width),
  4036. height: Math.round(sizeMillimeters.height)
  4037. };
  4038. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4039. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4040. if (rawName) {
  4041. sizeInches = {
  4042. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4043. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4044. };
  4045. sizeMillimeters = intMillimeters;
  4046. }
  4047. }
  4048. }
  4049. const [{
  4050. width,
  4051. height
  4052. }, 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"}`)]);
  4053. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4054. width: width.toLocaleString(),
  4055. height: height.toLocaleString(),
  4056. unit,
  4057. name,
  4058. orientation
  4059. });
  4060. }
  4061. async _parseDate(inputDate) {
  4062. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4063. if (!dateObject) {
  4064. return undefined;
  4065. }
  4066. return this.l10n.get("document_properties_date_string", {
  4067. date: dateObject.toLocaleDateString(),
  4068. time: dateObject.toLocaleTimeString()
  4069. });
  4070. }
  4071. _parseLinearization(isLinearized) {
  4072. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4073. }
  4074. }
  4075. exports.PDFDocumentProperties = PDFDocumentProperties;
  4076. /***/ }),
  4077. /* 14 */
  4078. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4079. Object.defineProperty(exports, "__esModule", ({
  4080. value: true
  4081. }));
  4082. exports.PDFFindBar = void 0;
  4083. var _pdf_find_controller = __webpack_require__(15);
  4084. const MATCHES_COUNT_LIMIT = 1000;
  4085. class PDFFindBar {
  4086. constructor(options, eventBus, l10n) {
  4087. this.opened = false;
  4088. this.bar = options.bar;
  4089. this.toggleButton = options.toggleButton;
  4090. this.findField = options.findField;
  4091. this.highlightAll = options.highlightAllCheckbox;
  4092. this.caseSensitive = options.caseSensitiveCheckbox;
  4093. this.entireWord = options.entireWordCheckbox;
  4094. this.findMsg = options.findMsg;
  4095. this.findResultsCount = options.findResultsCount;
  4096. this.findPreviousButton = options.findPreviousButton;
  4097. this.findNextButton = options.findNextButton;
  4098. this.eventBus = eventBus;
  4099. this.l10n = l10n;
  4100. this.toggleButton.addEventListener("click", () => {
  4101. this.toggle();
  4102. });
  4103. this.findField.addEventListener("input", () => {
  4104. this.dispatchEvent("");
  4105. });
  4106. this.bar.addEventListener("keydown", e => {
  4107. switch (e.keyCode) {
  4108. case 13:
  4109. if (e.target === this.findField) {
  4110. this.dispatchEvent("again", e.shiftKey);
  4111. }
  4112. break;
  4113. case 27:
  4114. this.close();
  4115. break;
  4116. }
  4117. });
  4118. this.findPreviousButton.addEventListener("click", () => {
  4119. this.dispatchEvent("again", true);
  4120. });
  4121. this.findNextButton.addEventListener("click", () => {
  4122. this.dispatchEvent("again", false);
  4123. });
  4124. this.highlightAll.addEventListener("click", () => {
  4125. this.dispatchEvent("highlightallchange");
  4126. });
  4127. this.caseSensitive.addEventListener("click", () => {
  4128. this.dispatchEvent("casesensitivitychange");
  4129. });
  4130. this.entireWord.addEventListener("click", () => {
  4131. this.dispatchEvent("entirewordchange");
  4132. });
  4133. this.eventBus._on("resize", this._adjustWidth.bind(this));
  4134. }
  4135. reset() {
  4136. this.updateUIState();
  4137. }
  4138. dispatchEvent(type, findPrev) {
  4139. this.eventBus.dispatch("find", {
  4140. source: this,
  4141. type,
  4142. query: this.findField.value,
  4143. phraseSearch: true,
  4144. caseSensitive: this.caseSensitive.checked,
  4145. entireWord: this.entireWord.checked,
  4146. highlightAll: this.highlightAll.checked,
  4147. findPrevious: findPrev
  4148. });
  4149. }
  4150. updateUIState(state, previous, matchesCount) {
  4151. let findMsg = Promise.resolve("");
  4152. let status = "";
  4153. switch (state) {
  4154. case _pdf_find_controller.FindState.FOUND:
  4155. break;
  4156. case _pdf_find_controller.FindState.PENDING:
  4157. status = "pending";
  4158. break;
  4159. case _pdf_find_controller.FindState.NOT_FOUND:
  4160. findMsg = this.l10n.get("find_not_found");
  4161. status = "notFound";
  4162. break;
  4163. case _pdf_find_controller.FindState.WRAPPED:
  4164. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4165. break;
  4166. }
  4167. this.findField.setAttribute("data-status", status);
  4168. findMsg.then(msg => {
  4169. this.findMsg.textContent = msg;
  4170. this._adjustWidth();
  4171. });
  4172. this.updateResultsCount(matchesCount);
  4173. }
  4174. updateResultsCount({
  4175. current = 0,
  4176. total = 0
  4177. } = {}) {
  4178. const limit = MATCHES_COUNT_LIMIT;
  4179. let matchCountMsg = Promise.resolve("");
  4180. if (total > 0) {
  4181. if (total > limit) {
  4182. let key = "find_match_count_limit";
  4183. matchCountMsg = this.l10n.get(key, {
  4184. limit
  4185. });
  4186. } else {
  4187. let key = "find_match_count";
  4188. matchCountMsg = this.l10n.get(key, {
  4189. current,
  4190. total
  4191. });
  4192. }
  4193. }
  4194. matchCountMsg.then(msg => {
  4195. this.findResultsCount.textContent = msg;
  4196. this.findResultsCount.classList.toggle("hidden", !total);
  4197. this._adjustWidth();
  4198. });
  4199. }
  4200. open() {
  4201. if (!this.opened) {
  4202. this.opened = true;
  4203. this.toggleButton.classList.add("toggled");
  4204. this.toggleButton.setAttribute("aria-expanded", "true");
  4205. this.bar.classList.remove("hidden");
  4206. }
  4207. this.findField.select();
  4208. this.findField.focus();
  4209. this._adjustWidth();
  4210. }
  4211. close() {
  4212. if (!this.opened) {
  4213. return;
  4214. }
  4215. this.opened = false;
  4216. this.toggleButton.classList.remove("toggled");
  4217. this.toggleButton.setAttribute("aria-expanded", "false");
  4218. this.bar.classList.add("hidden");
  4219. this.eventBus.dispatch("findbarclose", {
  4220. source: this
  4221. });
  4222. }
  4223. toggle() {
  4224. if (this.opened) {
  4225. this.close();
  4226. } else {
  4227. this.open();
  4228. }
  4229. }
  4230. _adjustWidth() {
  4231. if (!this.opened) {
  4232. return;
  4233. }
  4234. this.bar.classList.remove("wrapContainers");
  4235. const findbarHeight = this.bar.clientHeight;
  4236. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4237. if (findbarHeight > inputContainerHeight) {
  4238. this.bar.classList.add("wrapContainers");
  4239. }
  4240. }
  4241. }
  4242. exports.PDFFindBar = PDFFindBar;
  4243. /***/ }),
  4244. /* 15 */
  4245. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4246. Object.defineProperty(exports, "__esModule", ({
  4247. value: true
  4248. }));
  4249. exports.PDFFindController = exports.FindState = void 0;
  4250. var _pdfjsLib = __webpack_require__(5);
  4251. var _pdf_find_utils = __webpack_require__(16);
  4252. var _ui_utils = __webpack_require__(4);
  4253. const FindState = {
  4254. FOUND: 0,
  4255. NOT_FOUND: 1,
  4256. WRAPPED: 2,
  4257. PENDING: 3
  4258. };
  4259. exports.FindState = FindState;
  4260. const FIND_TIMEOUT = 250;
  4261. const MATCH_SCROLL_OFFSET_TOP = -50;
  4262. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4263. const CHARACTERS_TO_NORMALIZE = {
  4264. "\u2018": "'",
  4265. "\u2019": "'",
  4266. "\u201A": "'",
  4267. "\u201B": "'",
  4268. "\u201C": '"',
  4269. "\u201D": '"',
  4270. "\u201E": '"',
  4271. "\u201F": '"',
  4272. "\u00BC": "1/4",
  4273. "\u00BD": "1/2",
  4274. "\u00BE": "3/4"
  4275. };
  4276. let normalizationRegex = null;
  4277. function normalize(text) {
  4278. if (!normalizationRegex) {
  4279. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4280. normalizationRegex = new RegExp(`[${replace}]`, "g");
  4281. }
  4282. let diffs = null;
  4283. const normalizedText = text.replace(normalizationRegex, function (ch, index) {
  4284. const normalizedCh = CHARACTERS_TO_NORMALIZE[ch],
  4285. diff = normalizedCh.length - ch.length;
  4286. if (diff !== 0) {
  4287. (diffs || (diffs = [])).push([index, diff]);
  4288. }
  4289. return normalizedCh;
  4290. });
  4291. return [normalizedText, diffs];
  4292. }
  4293. function getOriginalIndex(matchIndex, diffs = null) {
  4294. if (!diffs) {
  4295. return matchIndex;
  4296. }
  4297. let totalDiff = 0;
  4298. for (const [index, diff] of diffs) {
  4299. const currentIndex = index + totalDiff;
  4300. if (currentIndex >= matchIndex) {
  4301. break;
  4302. }
  4303. if (currentIndex + diff > matchIndex) {
  4304. totalDiff += matchIndex - currentIndex;
  4305. break;
  4306. }
  4307. totalDiff += diff;
  4308. }
  4309. return matchIndex - totalDiff;
  4310. }
  4311. class PDFFindController {
  4312. constructor({
  4313. linkService,
  4314. eventBus
  4315. }) {
  4316. this._linkService = linkService;
  4317. this._eventBus = eventBus;
  4318. this._reset();
  4319. eventBus._on("findbarclose", this._onFindBarClose.bind(this));
  4320. }
  4321. get highlightMatches() {
  4322. return this._highlightMatches;
  4323. }
  4324. get pageMatches() {
  4325. return this._pageMatches;
  4326. }
  4327. get pageMatchesLength() {
  4328. return this._pageMatchesLength;
  4329. }
  4330. get selected() {
  4331. return this._selected;
  4332. }
  4333. get state() {
  4334. return this._state;
  4335. }
  4336. setDocument(pdfDocument) {
  4337. if (this._pdfDocument) {
  4338. this._reset();
  4339. }
  4340. if (!pdfDocument) {
  4341. return;
  4342. }
  4343. this._pdfDocument = pdfDocument;
  4344. this._firstPageCapability.resolve();
  4345. }
  4346. executeCommand(cmd, state) {
  4347. if (!state) {
  4348. return;
  4349. }
  4350. const pdfDocument = this._pdfDocument;
  4351. if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
  4352. this._dirtyMatch = true;
  4353. }
  4354. this._state = state;
  4355. if (cmd !== "findhighlightallchange") {
  4356. this._updateUIState(FindState.PENDING);
  4357. }
  4358. this._firstPageCapability.promise.then(() => {
  4359. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4360. return;
  4361. }
  4362. this._extractText();
  4363. const findbarClosed = !this._highlightMatches;
  4364. const pendingTimeout = !!this._findTimeout;
  4365. if (this._findTimeout) {
  4366. clearTimeout(this._findTimeout);
  4367. this._findTimeout = null;
  4368. }
  4369. if (cmd === "find") {
  4370. this._findTimeout = setTimeout(() => {
  4371. this._nextMatch();
  4372. this._findTimeout = null;
  4373. }, FIND_TIMEOUT);
  4374. } else if (this._dirtyMatch) {
  4375. this._nextMatch();
  4376. } else if (cmd === "findagain") {
  4377. this._nextMatch();
  4378. if (findbarClosed && this._state.highlightAll) {
  4379. this._updateAllPages();
  4380. }
  4381. } else if (cmd === "findhighlightallchange") {
  4382. if (pendingTimeout) {
  4383. this._nextMatch();
  4384. } else {
  4385. this._highlightMatches = true;
  4386. }
  4387. this._updateAllPages();
  4388. } else {
  4389. this._nextMatch();
  4390. }
  4391. });
  4392. }
  4393. scrollMatchIntoView({
  4394. element = null,
  4395. pageIndex = -1,
  4396. matchIndex = -1
  4397. }) {
  4398. if (!this._scrollMatches || !element) {
  4399. return;
  4400. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4401. return;
  4402. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4403. return;
  4404. }
  4405. this._scrollMatches = false;
  4406. const spot = {
  4407. top: MATCH_SCROLL_OFFSET_TOP,
  4408. left: MATCH_SCROLL_OFFSET_LEFT
  4409. };
  4410. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4411. }
  4412. _reset() {
  4413. this._highlightMatches = false;
  4414. this._scrollMatches = false;
  4415. this._pdfDocument = null;
  4416. this._pageMatches = [];
  4417. this._pageMatchesLength = [];
  4418. this._state = null;
  4419. this._selected = {
  4420. pageIdx: -1,
  4421. matchIdx: -1
  4422. };
  4423. this._offset = {
  4424. pageIdx: null,
  4425. matchIdx: null,
  4426. wrapped: false
  4427. };
  4428. this._extractTextPromises = [];
  4429. this._pageContents = [];
  4430. this._pageDiffs = [];
  4431. this._matchesCountTotal = 0;
  4432. this._pagesToSearch = null;
  4433. this._pendingFindMatches = new Set();
  4434. this._resumePageIdx = null;
  4435. this._dirtyMatch = false;
  4436. clearTimeout(this._findTimeout);
  4437. this._findTimeout = null;
  4438. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4439. }
  4440. get _query() {
  4441. if (this._state.query !== this._rawQuery) {
  4442. this._rawQuery = this._state.query;
  4443. [this._normalizedQuery] = normalize(this._state.query);
  4444. }
  4445. return this._normalizedQuery;
  4446. }
  4447. _shouldDirtyMatch(cmd, state) {
  4448. if (state.query !== this._state.query) {
  4449. return true;
  4450. }
  4451. switch (cmd) {
  4452. case "findagain":
  4453. const pageNumber = this._selected.pageIdx + 1;
  4454. const linkService = this._linkService;
  4455. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4456. return true;
  4457. }
  4458. return false;
  4459. case "findhighlightallchange":
  4460. return false;
  4461. }
  4462. return true;
  4463. }
  4464. _prepareMatches(matchesWithLength, matches, matchesLength) {
  4465. function isSubTerm(currentIndex) {
  4466. const currentElem = matchesWithLength[currentIndex];
  4467. const nextElem = matchesWithLength[currentIndex + 1];
  4468. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  4469. currentElem.skipped = true;
  4470. return true;
  4471. }
  4472. for (let i = currentIndex - 1; i >= 0; i--) {
  4473. const prevElem = matchesWithLength[i];
  4474. if (prevElem.skipped) {
  4475. continue;
  4476. }
  4477. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  4478. break;
  4479. }
  4480. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  4481. currentElem.skipped = true;
  4482. return true;
  4483. }
  4484. }
  4485. return false;
  4486. }
  4487. matchesWithLength.sort(function (a, b) {
  4488. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  4489. });
  4490. for (let i = 0, len = matchesWithLength.length; i < len; i++) {
  4491. if (isSubTerm(i)) {
  4492. continue;
  4493. }
  4494. matches.push(matchesWithLength[i].match);
  4495. matchesLength.push(matchesWithLength[i].matchLength);
  4496. }
  4497. }
  4498. _isEntireWord(content, startIdx, length) {
  4499. if (startIdx > 0) {
  4500. const first = content.charCodeAt(startIdx);
  4501. const limit = content.charCodeAt(startIdx - 1);
  4502. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4503. return false;
  4504. }
  4505. }
  4506. const endIdx = startIdx + length - 1;
  4507. if (endIdx < content.length - 1) {
  4508. const last = content.charCodeAt(endIdx);
  4509. const limit = content.charCodeAt(endIdx + 1);
  4510. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4511. return false;
  4512. }
  4513. }
  4514. return true;
  4515. }
  4516. _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4517. const matches = [],
  4518. matchesLength = [];
  4519. const queryLen = query.length;
  4520. let matchIdx = -queryLen;
  4521. while (true) {
  4522. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  4523. if (matchIdx === -1) {
  4524. break;
  4525. }
  4526. if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
  4527. continue;
  4528. }
  4529. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4530. matchEnd = matchIdx + queryLen - 1,
  4531. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4532. matches.push(originalMatchIdx);
  4533. matchesLength.push(originalQueryLen);
  4534. }
  4535. this._pageMatches[pageIndex] = matches;
  4536. this._pageMatchesLength[pageIndex] = matchesLength;
  4537. }
  4538. _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4539. const matchesWithLength = [];
  4540. const queryArray = query.match(/\S+/g);
  4541. for (let i = 0, len = queryArray.length; i < len; i++) {
  4542. const subquery = queryArray[i];
  4543. const subqueryLen = subquery.length;
  4544. let matchIdx = -subqueryLen;
  4545. while (true) {
  4546. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  4547. if (matchIdx === -1) {
  4548. break;
  4549. }
  4550. if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
  4551. continue;
  4552. }
  4553. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4554. matchEnd = matchIdx + subqueryLen - 1,
  4555. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4556. matchesWithLength.push({
  4557. match: originalMatchIdx,
  4558. matchLength: originalQueryLen,
  4559. skipped: false
  4560. });
  4561. }
  4562. }
  4563. this._pageMatchesLength[pageIndex] = [];
  4564. this._pageMatches[pageIndex] = [];
  4565. this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
  4566. }
  4567. _calculateMatch(pageIndex) {
  4568. let pageContent = this._pageContents[pageIndex];
  4569. const pageDiffs = this._pageDiffs[pageIndex];
  4570. let query = this._query;
  4571. const {
  4572. caseSensitive,
  4573. entireWord,
  4574. phraseSearch
  4575. } = this._state;
  4576. if (query.length === 0) {
  4577. return;
  4578. }
  4579. if (!caseSensitive) {
  4580. pageContent = pageContent.toLowerCase();
  4581. query = query.toLowerCase();
  4582. }
  4583. if (phraseSearch) {
  4584. this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4585. } else {
  4586. this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4587. }
  4588. if (this._state.highlightAll) {
  4589. this._updatePage(pageIndex);
  4590. }
  4591. if (this._resumePageIdx === pageIndex) {
  4592. this._resumePageIdx = null;
  4593. this._nextPageMatch();
  4594. }
  4595. const pageMatchesCount = this._pageMatches[pageIndex].length;
  4596. if (pageMatchesCount > 0) {
  4597. this._matchesCountTotal += pageMatchesCount;
  4598. this._updateUIResultsCount();
  4599. }
  4600. }
  4601. _extractText() {
  4602. if (this._extractTextPromises.length > 0) {
  4603. return;
  4604. }
  4605. let promise = Promise.resolve();
  4606. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  4607. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  4608. this._extractTextPromises[i] = extractTextCapability.promise;
  4609. promise = promise.then(() => {
  4610. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  4611. return pdfPage.getTextContent({
  4612. normalizeWhitespace: true
  4613. });
  4614. }).then(textContent => {
  4615. const textItems = textContent.items;
  4616. const strBuf = [];
  4617. for (let j = 0, jj = textItems.length; j < jj; j++) {
  4618. strBuf.push(textItems[j].str);
  4619. }
  4620. [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""));
  4621. extractTextCapability.resolve(i);
  4622. }, reason => {
  4623. console.error(`Unable to get text content for page ${i + 1}`, reason);
  4624. this._pageContents[i] = "";
  4625. this._pageDiffs[i] = null;
  4626. extractTextCapability.resolve(i);
  4627. });
  4628. });
  4629. }
  4630. }
  4631. _updatePage(index) {
  4632. if (this._scrollMatches && this._selected.pageIdx === index) {
  4633. this._linkService.page = index + 1;
  4634. }
  4635. this._eventBus.dispatch("updatetextlayermatches", {
  4636. source: this,
  4637. pageIndex: index
  4638. });
  4639. }
  4640. _updateAllPages() {
  4641. this._eventBus.dispatch("updatetextlayermatches", {
  4642. source: this,
  4643. pageIndex: -1
  4644. });
  4645. }
  4646. _nextMatch() {
  4647. const previous = this._state.findPrevious;
  4648. const currentPageIndex = this._linkService.page - 1;
  4649. const numPages = this._linkService.pagesCount;
  4650. this._highlightMatches = true;
  4651. if (this._dirtyMatch) {
  4652. this._dirtyMatch = false;
  4653. this._selected.pageIdx = this._selected.matchIdx = -1;
  4654. this._offset.pageIdx = currentPageIndex;
  4655. this._offset.matchIdx = null;
  4656. this._offset.wrapped = false;
  4657. this._resumePageIdx = null;
  4658. this._pageMatches.length = 0;
  4659. this._pageMatchesLength.length = 0;
  4660. this._matchesCountTotal = 0;
  4661. this._updateAllPages();
  4662. for (let i = 0; i < numPages; i++) {
  4663. if (this._pendingFindMatches.has(i)) {
  4664. continue;
  4665. }
  4666. this._pendingFindMatches.add(i);
  4667. this._extractTextPromises[i].then(pageIdx => {
  4668. this._pendingFindMatches.delete(pageIdx);
  4669. this._calculateMatch(pageIdx);
  4670. });
  4671. }
  4672. }
  4673. if (this._query === "") {
  4674. this._updateUIState(FindState.FOUND);
  4675. return;
  4676. }
  4677. if (this._resumePageIdx) {
  4678. return;
  4679. }
  4680. const offset = this._offset;
  4681. this._pagesToSearch = numPages;
  4682. if (offset.matchIdx !== null) {
  4683. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  4684. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  4685. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  4686. this._updateMatch(true);
  4687. return;
  4688. }
  4689. this._advanceOffsetPage(previous);
  4690. }
  4691. this._nextPageMatch();
  4692. }
  4693. _matchesReady(matches) {
  4694. const offset = this._offset;
  4695. const numMatches = matches.length;
  4696. const previous = this._state.findPrevious;
  4697. if (numMatches) {
  4698. offset.matchIdx = previous ? numMatches - 1 : 0;
  4699. this._updateMatch(true);
  4700. return true;
  4701. }
  4702. this._advanceOffsetPage(previous);
  4703. if (offset.wrapped) {
  4704. offset.matchIdx = null;
  4705. if (this._pagesToSearch < 0) {
  4706. this._updateMatch(false);
  4707. return true;
  4708. }
  4709. }
  4710. return false;
  4711. }
  4712. _nextPageMatch() {
  4713. if (this._resumePageIdx !== null) {
  4714. console.error("There can only be one pending page.");
  4715. }
  4716. let matches = null;
  4717. do {
  4718. const pageIdx = this._offset.pageIdx;
  4719. matches = this._pageMatches[pageIdx];
  4720. if (!matches) {
  4721. this._resumePageIdx = pageIdx;
  4722. break;
  4723. }
  4724. } while (!this._matchesReady(matches));
  4725. }
  4726. _advanceOffsetPage(previous) {
  4727. const offset = this._offset;
  4728. const numPages = this._linkService.pagesCount;
  4729. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  4730. offset.matchIdx = null;
  4731. this._pagesToSearch--;
  4732. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  4733. offset.pageIdx = previous ? numPages - 1 : 0;
  4734. offset.wrapped = true;
  4735. }
  4736. }
  4737. _updateMatch(found = false) {
  4738. let state = FindState.NOT_FOUND;
  4739. const wrapped = this._offset.wrapped;
  4740. this._offset.wrapped = false;
  4741. if (found) {
  4742. const previousPage = this._selected.pageIdx;
  4743. this._selected.pageIdx = this._offset.pageIdx;
  4744. this._selected.matchIdx = this._offset.matchIdx;
  4745. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  4746. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  4747. this._updatePage(previousPage);
  4748. }
  4749. }
  4750. this._updateUIState(state, this._state.findPrevious);
  4751. if (this._selected.pageIdx !== -1) {
  4752. this._scrollMatches = true;
  4753. this._updatePage(this._selected.pageIdx);
  4754. }
  4755. }
  4756. _onFindBarClose(evt) {
  4757. const pdfDocument = this._pdfDocument;
  4758. this._firstPageCapability.promise.then(() => {
  4759. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4760. return;
  4761. }
  4762. if (this._findTimeout) {
  4763. clearTimeout(this._findTimeout);
  4764. this._findTimeout = null;
  4765. }
  4766. if (this._resumePageIdx) {
  4767. this._resumePageIdx = null;
  4768. this._dirtyMatch = true;
  4769. }
  4770. this._updateUIState(FindState.FOUND);
  4771. this._highlightMatches = false;
  4772. this._updateAllPages();
  4773. });
  4774. }
  4775. _requestMatchesCount() {
  4776. const {
  4777. pageIdx,
  4778. matchIdx
  4779. } = this._selected;
  4780. let current = 0,
  4781. total = this._matchesCountTotal;
  4782. if (matchIdx !== -1) {
  4783. for (let i = 0; i < pageIdx; i++) {
  4784. current += this._pageMatches[i]?.length || 0;
  4785. }
  4786. current += matchIdx + 1;
  4787. }
  4788. if (current < 1 || current > total) {
  4789. current = total = 0;
  4790. }
  4791. return {
  4792. current,
  4793. total
  4794. };
  4795. }
  4796. _updateUIResultsCount() {
  4797. this._eventBus.dispatch("updatefindmatchescount", {
  4798. source: this,
  4799. matchesCount: this._requestMatchesCount()
  4800. });
  4801. }
  4802. _updateUIState(state, previous) {
  4803. this._eventBus.dispatch("updatefindcontrolstate", {
  4804. source: this,
  4805. state,
  4806. previous,
  4807. matchesCount: this._requestMatchesCount(),
  4808. rawQuery: this._state?.query ?? null
  4809. });
  4810. }
  4811. }
  4812. exports.PDFFindController = PDFFindController;
  4813. /***/ }),
  4814. /* 16 */
  4815. /***/ ((__unused_webpack_module, exports) => {
  4816. Object.defineProperty(exports, "__esModule", ({
  4817. value: true
  4818. }));
  4819. exports.getCharacterType = getCharacterType;
  4820. exports.CharacterType = void 0;
  4821. const CharacterType = {
  4822. SPACE: 0,
  4823. ALPHA_LETTER: 1,
  4824. PUNCT: 2,
  4825. HAN_LETTER: 3,
  4826. KATAKANA_LETTER: 4,
  4827. HIRAGANA_LETTER: 5,
  4828. HALFWIDTH_KATAKANA_LETTER: 6,
  4829. THAI_LETTER: 7
  4830. };
  4831. exports.CharacterType = CharacterType;
  4832. function isAlphabeticalScript(charCode) {
  4833. return charCode < 0x2e80;
  4834. }
  4835. function isAscii(charCode) {
  4836. return (charCode & 0xff80) === 0;
  4837. }
  4838. function isAsciiAlpha(charCode) {
  4839. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  4840. }
  4841. function isAsciiDigit(charCode) {
  4842. return charCode >= 0x30 && charCode <= 0x39;
  4843. }
  4844. function isAsciiSpace(charCode) {
  4845. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  4846. }
  4847. function isHan(charCode) {
  4848. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  4849. }
  4850. function isKatakana(charCode) {
  4851. return charCode >= 0x30a0 && charCode <= 0x30ff;
  4852. }
  4853. function isHiragana(charCode) {
  4854. return charCode >= 0x3040 && charCode <= 0x309f;
  4855. }
  4856. function isHalfwidthKatakana(charCode) {
  4857. return charCode >= 0xff60 && charCode <= 0xff9f;
  4858. }
  4859. function isThai(charCode) {
  4860. return (charCode & 0xff80) === 0x0e00;
  4861. }
  4862. function getCharacterType(charCode) {
  4863. if (isAlphabeticalScript(charCode)) {
  4864. if (isAscii(charCode)) {
  4865. if (isAsciiSpace(charCode)) {
  4866. return CharacterType.SPACE;
  4867. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  4868. return CharacterType.ALPHA_LETTER;
  4869. }
  4870. return CharacterType.PUNCT;
  4871. } else if (isThai(charCode)) {
  4872. return CharacterType.THAI_LETTER;
  4873. } else if (charCode === 0xa0) {
  4874. return CharacterType.SPACE;
  4875. }
  4876. return CharacterType.ALPHA_LETTER;
  4877. }
  4878. if (isHan(charCode)) {
  4879. return CharacterType.HAN_LETTER;
  4880. } else if (isKatakana(charCode)) {
  4881. return CharacterType.KATAKANA_LETTER;
  4882. } else if (isHiragana(charCode)) {
  4883. return CharacterType.HIRAGANA_LETTER;
  4884. } else if (isHalfwidthKatakana(charCode)) {
  4885. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  4886. }
  4887. return CharacterType.ALPHA_LETTER;
  4888. }
  4889. /***/ }),
  4890. /* 17 */
  4891. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4892. Object.defineProperty(exports, "__esModule", ({
  4893. value: true
  4894. }));
  4895. exports.isDestArraysEqual = isDestArraysEqual;
  4896. exports.isDestHashesEqual = isDestHashesEqual;
  4897. exports.PDFHistory = void 0;
  4898. var _ui_utils = __webpack_require__(4);
  4899. const HASH_CHANGE_TIMEOUT = 1000;
  4900. const POSITION_UPDATED_THRESHOLD = 50;
  4901. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  4902. function getCurrentHash() {
  4903. return document.location.hash;
  4904. }
  4905. class PDFHistory {
  4906. constructor({
  4907. linkService,
  4908. eventBus
  4909. }) {
  4910. this.linkService = linkService;
  4911. this.eventBus = eventBus;
  4912. this._initialized = false;
  4913. this._fingerprint = "";
  4914. this.reset();
  4915. this._boundEvents = null;
  4916. this._isViewerInPresentationMode = false;
  4917. this.eventBus._on("presentationmodechanged", evt => {
  4918. this._isViewerInPresentationMode = evt.state !== _ui_utils.PresentationModeState.NORMAL;
  4919. });
  4920. this.eventBus._on("pagesinit", () => {
  4921. this._isPagesLoaded = false;
  4922. this.eventBus._on("pagesloaded", evt => {
  4923. this._isPagesLoaded = !!evt.pagesCount;
  4924. }, {
  4925. once: true
  4926. });
  4927. });
  4928. }
  4929. initialize({
  4930. fingerprint,
  4931. resetHistory = false,
  4932. updateUrl = false
  4933. }) {
  4934. if (!fingerprint || typeof fingerprint !== "string") {
  4935. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  4936. return;
  4937. }
  4938. if (this._initialized) {
  4939. this.reset();
  4940. }
  4941. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  4942. this._fingerprint = fingerprint;
  4943. this._updateUrl = updateUrl === true;
  4944. this._initialized = true;
  4945. this._bindEvents();
  4946. const state = window.history.state;
  4947. this._popStateInProgress = false;
  4948. this._blockHashChange = 0;
  4949. this._currentHash = getCurrentHash();
  4950. this._numPositionUpdates = 0;
  4951. this._uid = this._maxUid = 0;
  4952. this._destination = null;
  4953. this._position = null;
  4954. if (!this._isValidState(state, true) || resetHistory) {
  4955. const {
  4956. hash,
  4957. page,
  4958. rotation
  4959. } = this._parseCurrentHash(true);
  4960. if (!hash || reInitialized || resetHistory) {
  4961. this._pushOrReplaceState(null, true);
  4962. return;
  4963. }
  4964. this._pushOrReplaceState({
  4965. hash,
  4966. page,
  4967. rotation
  4968. }, true);
  4969. return;
  4970. }
  4971. const destination = state.destination;
  4972. this._updateInternalState(destination, state.uid, true);
  4973. if (destination.rotation !== undefined) {
  4974. this._initialRotation = destination.rotation;
  4975. }
  4976. if (destination.dest) {
  4977. this._initialBookmark = JSON.stringify(destination.dest);
  4978. this._destination.page = null;
  4979. } else if (destination.hash) {
  4980. this._initialBookmark = destination.hash;
  4981. } else if (destination.page) {
  4982. this._initialBookmark = `page=${destination.page}`;
  4983. }
  4984. }
  4985. reset() {
  4986. if (this._initialized) {
  4987. this._pageHide();
  4988. this._initialized = false;
  4989. this._unbindEvents();
  4990. }
  4991. if (this._updateViewareaTimeout) {
  4992. clearTimeout(this._updateViewareaTimeout);
  4993. this._updateViewareaTimeout = null;
  4994. }
  4995. this._initialBookmark = null;
  4996. this._initialRotation = null;
  4997. }
  4998. push({
  4999. namedDest = null,
  5000. explicitDest,
  5001. pageNumber
  5002. }) {
  5003. if (!this._initialized) {
  5004. return;
  5005. }
  5006. if (namedDest && typeof namedDest !== "string") {
  5007. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5008. return;
  5009. } else if (!Array.isArray(explicitDest)) {
  5010. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5011. return;
  5012. } else if (!this._isValidPage(pageNumber)) {
  5013. if (pageNumber !== null || this._destination) {
  5014. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5015. return;
  5016. }
  5017. }
  5018. const hash = namedDest || JSON.stringify(explicitDest);
  5019. if (!hash) {
  5020. return;
  5021. }
  5022. let forceReplace = false;
  5023. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5024. if (this._destination.page) {
  5025. return;
  5026. }
  5027. forceReplace = true;
  5028. }
  5029. if (this._popStateInProgress && !forceReplace) {
  5030. return;
  5031. }
  5032. this._pushOrReplaceState({
  5033. dest: explicitDest,
  5034. hash,
  5035. page: pageNumber,
  5036. rotation: this.linkService.rotation
  5037. }, forceReplace);
  5038. if (!this._popStateInProgress) {
  5039. this._popStateInProgress = true;
  5040. Promise.resolve().then(() => {
  5041. this._popStateInProgress = false;
  5042. });
  5043. }
  5044. }
  5045. pushPage(pageNumber) {
  5046. if (!this._initialized) {
  5047. return;
  5048. }
  5049. if (!this._isValidPage(pageNumber)) {
  5050. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5051. return;
  5052. }
  5053. if (this._destination?.page === pageNumber) {
  5054. return;
  5055. }
  5056. if (this._popStateInProgress) {
  5057. return;
  5058. }
  5059. this._pushOrReplaceState({
  5060. dest: null,
  5061. hash: `page=${pageNumber}`,
  5062. page: pageNumber,
  5063. rotation: this.linkService.rotation
  5064. });
  5065. if (!this._popStateInProgress) {
  5066. this._popStateInProgress = true;
  5067. Promise.resolve().then(() => {
  5068. this._popStateInProgress = false;
  5069. });
  5070. }
  5071. }
  5072. pushCurrentPosition() {
  5073. if (!this._initialized || this._popStateInProgress) {
  5074. return;
  5075. }
  5076. this._tryPushCurrentPosition();
  5077. }
  5078. back() {
  5079. if (!this._initialized || this._popStateInProgress) {
  5080. return;
  5081. }
  5082. const state = window.history.state;
  5083. if (this._isValidState(state) && state.uid > 0) {
  5084. window.history.back();
  5085. }
  5086. }
  5087. forward() {
  5088. if (!this._initialized || this._popStateInProgress) {
  5089. return;
  5090. }
  5091. const state = window.history.state;
  5092. if (this._isValidState(state) && state.uid < this._maxUid) {
  5093. window.history.forward();
  5094. }
  5095. }
  5096. get popStateInProgress() {
  5097. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5098. }
  5099. get initialBookmark() {
  5100. return this._initialized ? this._initialBookmark : null;
  5101. }
  5102. get initialRotation() {
  5103. return this._initialized ? this._initialRotation : null;
  5104. }
  5105. _pushOrReplaceState(destination, forceReplace = false) {
  5106. const shouldReplace = forceReplace || !this._destination;
  5107. const newState = {
  5108. fingerprint: this._fingerprint,
  5109. uid: shouldReplace ? this._uid : this._uid + 1,
  5110. destination
  5111. };
  5112. this._updateInternalState(destination, newState.uid);
  5113. let newUrl;
  5114. if (this._updateUrl && destination?.hash) {
  5115. const baseUrl = document.location.href.split("#")[0];
  5116. if (!baseUrl.startsWith("file://")) {
  5117. newUrl = `${baseUrl}#${destination.hash}`;
  5118. }
  5119. }
  5120. if (shouldReplace) {
  5121. window.history.replaceState(newState, "", newUrl);
  5122. } else {
  5123. window.history.pushState(newState, "", newUrl);
  5124. }
  5125. }
  5126. _tryPushCurrentPosition(temporary = false) {
  5127. if (!this._position) {
  5128. return;
  5129. }
  5130. let position = this._position;
  5131. if (temporary) {
  5132. position = Object.assign(Object.create(null), this._position);
  5133. position.temporary = true;
  5134. }
  5135. if (!this._destination) {
  5136. this._pushOrReplaceState(position);
  5137. return;
  5138. }
  5139. if (this._destination.temporary) {
  5140. this._pushOrReplaceState(position, true);
  5141. return;
  5142. }
  5143. if (this._destination.hash === position.hash) {
  5144. return;
  5145. }
  5146. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5147. return;
  5148. }
  5149. let forceReplace = false;
  5150. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5151. if (this._destination.dest !== undefined || !this._destination.first) {
  5152. return;
  5153. }
  5154. forceReplace = true;
  5155. }
  5156. this._pushOrReplaceState(position, forceReplace);
  5157. }
  5158. _isValidPage(val) {
  5159. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5160. }
  5161. _isValidState(state, checkReload = false) {
  5162. if (!state) {
  5163. return false;
  5164. }
  5165. if (state.fingerprint !== this._fingerprint) {
  5166. if (checkReload) {
  5167. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5168. return false;
  5169. }
  5170. const [perfEntry] = performance.getEntriesByType("navigation");
  5171. if (perfEntry?.type !== "reload") {
  5172. return false;
  5173. }
  5174. } else {
  5175. return false;
  5176. }
  5177. }
  5178. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5179. return false;
  5180. }
  5181. if (state.destination === null || typeof state.destination !== "object") {
  5182. return false;
  5183. }
  5184. return true;
  5185. }
  5186. _updateInternalState(destination, uid, removeTemporary = false) {
  5187. if (this._updateViewareaTimeout) {
  5188. clearTimeout(this._updateViewareaTimeout);
  5189. this._updateViewareaTimeout = null;
  5190. }
  5191. if (removeTemporary && destination?.temporary) {
  5192. delete destination.temporary;
  5193. }
  5194. this._destination = destination;
  5195. this._uid = uid;
  5196. this._maxUid = Math.max(this._maxUid, uid);
  5197. this._numPositionUpdates = 0;
  5198. }
  5199. _parseCurrentHash(checkNameddest = false) {
  5200. const hash = unescape(getCurrentHash()).substring(1);
  5201. const params = (0, _ui_utils.parseQueryString)(hash);
  5202. const nameddest = params.nameddest || "";
  5203. let page = params.page | 0;
  5204. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5205. page = null;
  5206. }
  5207. return {
  5208. hash,
  5209. page,
  5210. rotation: this.linkService.rotation
  5211. };
  5212. }
  5213. _updateViewarea({
  5214. location
  5215. }) {
  5216. if (this._updateViewareaTimeout) {
  5217. clearTimeout(this._updateViewareaTimeout);
  5218. this._updateViewareaTimeout = null;
  5219. }
  5220. this._position = {
  5221. hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
  5222. page: this.linkService.page,
  5223. first: location.pageNumber,
  5224. rotation: location.rotation
  5225. };
  5226. if (this._popStateInProgress) {
  5227. return;
  5228. }
  5229. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5230. this._numPositionUpdates++;
  5231. }
  5232. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5233. this._updateViewareaTimeout = setTimeout(() => {
  5234. if (!this._popStateInProgress) {
  5235. this._tryPushCurrentPosition(true);
  5236. }
  5237. this._updateViewareaTimeout = null;
  5238. }, UPDATE_VIEWAREA_TIMEOUT);
  5239. }
  5240. }
  5241. _popState({
  5242. state
  5243. }) {
  5244. const newHash = getCurrentHash(),
  5245. hashChanged = this._currentHash !== newHash;
  5246. this._currentHash = newHash;
  5247. if (!state) {
  5248. this._uid++;
  5249. const {
  5250. hash,
  5251. page,
  5252. rotation
  5253. } = this._parseCurrentHash();
  5254. this._pushOrReplaceState({
  5255. hash,
  5256. page,
  5257. rotation
  5258. }, true);
  5259. return;
  5260. }
  5261. if (!this._isValidState(state)) {
  5262. return;
  5263. }
  5264. this._popStateInProgress = true;
  5265. if (hashChanged) {
  5266. this._blockHashChange++;
  5267. (0, _ui_utils.waitOnEventOrTimeout)({
  5268. target: window,
  5269. name: "hashchange",
  5270. delay: HASH_CHANGE_TIMEOUT
  5271. }).then(() => {
  5272. this._blockHashChange--;
  5273. });
  5274. }
  5275. const destination = state.destination;
  5276. this._updateInternalState(destination, state.uid, true);
  5277. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5278. this.linkService.rotation = destination.rotation;
  5279. }
  5280. if (destination.dest) {
  5281. this.linkService.goToDestination(destination.dest);
  5282. } else if (destination.hash) {
  5283. this.linkService.setHash(destination.hash);
  5284. } else if (destination.page) {
  5285. this.linkService.page = destination.page;
  5286. }
  5287. Promise.resolve().then(() => {
  5288. this._popStateInProgress = false;
  5289. });
  5290. }
  5291. _pageHide() {
  5292. if (!this._destination || this._destination.temporary) {
  5293. this._tryPushCurrentPosition();
  5294. }
  5295. }
  5296. _bindEvents() {
  5297. if (this._boundEvents) {
  5298. return;
  5299. }
  5300. this._boundEvents = {
  5301. updateViewarea: this._updateViewarea.bind(this),
  5302. popState: this._popState.bind(this),
  5303. pageHide: this._pageHide.bind(this)
  5304. };
  5305. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5306. window.addEventListener("popstate", this._boundEvents.popState);
  5307. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5308. }
  5309. _unbindEvents() {
  5310. if (!this._boundEvents) {
  5311. return;
  5312. }
  5313. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5314. window.removeEventListener("popstate", this._boundEvents.popState);
  5315. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5316. this._boundEvents = null;
  5317. }
  5318. }
  5319. exports.PDFHistory = PDFHistory;
  5320. function isDestHashesEqual(destHash, pushHash) {
  5321. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5322. return false;
  5323. }
  5324. if (destHash === pushHash) {
  5325. return true;
  5326. }
  5327. const {
  5328. nameddest
  5329. } = (0, _ui_utils.parseQueryString)(destHash);
  5330. if (nameddest === pushHash) {
  5331. return true;
  5332. }
  5333. return false;
  5334. }
  5335. function isDestArraysEqual(firstDest, secondDest) {
  5336. function isEntryEqual(first, second) {
  5337. if (typeof first !== typeof second) {
  5338. return false;
  5339. }
  5340. if (Array.isArray(first) || Array.isArray(second)) {
  5341. return false;
  5342. }
  5343. if (first !== null && typeof first === "object" && second !== null) {
  5344. if (Object.keys(first).length !== Object.keys(second).length) {
  5345. return false;
  5346. }
  5347. for (const key in first) {
  5348. if (!isEntryEqual(first[key], second[key])) {
  5349. return false;
  5350. }
  5351. }
  5352. return true;
  5353. }
  5354. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5355. }
  5356. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5357. return false;
  5358. }
  5359. if (firstDest.length !== secondDest.length) {
  5360. return false;
  5361. }
  5362. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5363. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5364. return false;
  5365. }
  5366. }
  5367. return true;
  5368. }
  5369. /***/ }),
  5370. /* 18 */
  5371. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5372. Object.defineProperty(exports, "__esModule", ({
  5373. value: true
  5374. }));
  5375. exports.PDFLayerViewer = void 0;
  5376. var _base_tree_viewer = __webpack_require__(12);
  5377. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5378. constructor(options) {
  5379. super(options);
  5380. this.l10n = options.l10n;
  5381. this.eventBus._on("resetlayers", this._resetLayers.bind(this));
  5382. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5383. }
  5384. reset() {
  5385. super.reset();
  5386. this._optionalContentConfig = null;
  5387. }
  5388. _dispatchEvent(layersCount) {
  5389. this.eventBus.dispatch("layersloaded", {
  5390. source: this,
  5391. layersCount
  5392. });
  5393. }
  5394. _bindLink(element, {
  5395. groupId,
  5396. input
  5397. }) {
  5398. const setVisibility = () => {
  5399. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5400. this.eventBus.dispatch("optionalcontentconfig", {
  5401. source: this,
  5402. promise: Promise.resolve(this._optionalContentConfig)
  5403. });
  5404. };
  5405. element.onclick = evt => {
  5406. if (evt.target === input) {
  5407. setVisibility();
  5408. return true;
  5409. } else if (evt.target !== element) {
  5410. return true;
  5411. }
  5412. input.checked = !input.checked;
  5413. setVisibility();
  5414. return false;
  5415. };
  5416. }
  5417. async _setNestedName(element, {
  5418. name = null
  5419. }) {
  5420. if (typeof name === "string") {
  5421. element.textContent = this._normalizeTextContent(name);
  5422. return;
  5423. }
  5424. element.textContent = await this.l10n.get("additional_layers");
  5425. element.style.fontStyle = "italic";
  5426. }
  5427. _addToggleButton(div, {
  5428. name = null
  5429. }) {
  5430. super._addToggleButton(div, name === null);
  5431. }
  5432. _toggleAllTreeItems() {
  5433. if (!this._optionalContentConfig) {
  5434. return;
  5435. }
  5436. super._toggleAllTreeItems();
  5437. }
  5438. render({
  5439. optionalContentConfig,
  5440. pdfDocument
  5441. }) {
  5442. if (this._optionalContentConfig) {
  5443. this.reset();
  5444. }
  5445. this._optionalContentConfig = optionalContentConfig || null;
  5446. this._pdfDocument = pdfDocument || null;
  5447. const groups = optionalContentConfig?.getOrder();
  5448. if (!groups) {
  5449. this._dispatchEvent(0);
  5450. return;
  5451. }
  5452. const fragment = document.createDocumentFragment(),
  5453. queue = [{
  5454. parent: fragment,
  5455. groups
  5456. }];
  5457. let layersCount = 0,
  5458. hasAnyNesting = false;
  5459. while (queue.length > 0) {
  5460. const levelData = queue.shift();
  5461. for (const groupId of levelData.groups) {
  5462. const div = document.createElement("div");
  5463. div.className = "treeItem";
  5464. const element = document.createElement("a");
  5465. div.appendChild(element);
  5466. if (typeof groupId === "object") {
  5467. hasAnyNesting = true;
  5468. this._addToggleButton(div, groupId);
  5469. this._setNestedName(element, groupId);
  5470. const itemsDiv = document.createElement("div");
  5471. itemsDiv.className = "treeItems";
  5472. div.appendChild(itemsDiv);
  5473. queue.push({
  5474. parent: itemsDiv,
  5475. groups: groupId.order
  5476. });
  5477. } else {
  5478. const group = optionalContentConfig.getGroup(groupId);
  5479. const input = document.createElement("input");
  5480. this._bindLink(element, {
  5481. groupId,
  5482. input
  5483. });
  5484. input.type = "checkbox";
  5485. input.id = groupId;
  5486. input.checked = group.visible;
  5487. const label = document.createElement("label");
  5488. label.setAttribute("for", groupId);
  5489. label.textContent = this._normalizeTextContent(group.name);
  5490. element.appendChild(input);
  5491. element.appendChild(label);
  5492. layersCount++;
  5493. }
  5494. levelData.parent.appendChild(div);
  5495. }
  5496. }
  5497. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5498. }
  5499. async _resetLayers() {
  5500. if (!this._optionalContentConfig) {
  5501. return;
  5502. }
  5503. const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
  5504. this.eventBus.dispatch("optionalcontentconfig", {
  5505. source: this,
  5506. promise: Promise.resolve(optionalContentConfig)
  5507. });
  5508. this.render({
  5509. optionalContentConfig,
  5510. pdfDocument: this._pdfDocument
  5511. });
  5512. }
  5513. }
  5514. exports.PDFLayerViewer = PDFLayerViewer;
  5515. /***/ }),
  5516. /* 19 */
  5517. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5518. Object.defineProperty(exports, "__esModule", ({
  5519. value: true
  5520. }));
  5521. exports.SimpleLinkService = exports.PDFLinkService = void 0;
  5522. var _ui_utils = __webpack_require__(4);
  5523. class PDFLinkService {
  5524. constructor({
  5525. eventBus,
  5526. externalLinkTarget = null,
  5527. externalLinkRel = null,
  5528. externalLinkEnabled = true,
  5529. ignoreDestinationZoom = false
  5530. } = {}) {
  5531. this.eventBus = eventBus;
  5532. this.externalLinkTarget = externalLinkTarget;
  5533. this.externalLinkRel = externalLinkRel;
  5534. this.externalLinkEnabled = externalLinkEnabled;
  5535. this._ignoreDestinationZoom = ignoreDestinationZoom;
  5536. this.baseUrl = null;
  5537. this.pdfDocument = null;
  5538. this.pdfViewer = null;
  5539. this.pdfHistory = null;
  5540. this._pagesRefCache = null;
  5541. }
  5542. setDocument(pdfDocument, baseUrl = null) {
  5543. this.baseUrl = baseUrl;
  5544. this.pdfDocument = pdfDocument;
  5545. this._pagesRefCache = Object.create(null);
  5546. }
  5547. setViewer(pdfViewer) {
  5548. this.pdfViewer = pdfViewer;
  5549. }
  5550. setHistory(pdfHistory) {
  5551. this.pdfHistory = pdfHistory;
  5552. }
  5553. get pagesCount() {
  5554. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  5555. }
  5556. get page() {
  5557. return this.pdfViewer.currentPageNumber;
  5558. }
  5559. set page(value) {
  5560. this.pdfViewer.currentPageNumber = value;
  5561. }
  5562. get rotation() {
  5563. return this.pdfViewer.pagesRotation;
  5564. }
  5565. set rotation(value) {
  5566. this.pdfViewer.pagesRotation = value;
  5567. }
  5568. _goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  5569. const destRef = explicitDest[0];
  5570. let pageNumber;
  5571. if (destRef instanceof Object) {
  5572. pageNumber = this._cachedPageNumber(destRef);
  5573. if (pageNumber === null) {
  5574. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  5575. this.cachePageRef(pageIndex + 1, destRef);
  5576. this._goToDestinationHelper(rawDest, namedDest, explicitDest);
  5577. }).catch(() => {
  5578. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  5579. });
  5580. return;
  5581. }
  5582. } else if (Number.isInteger(destRef)) {
  5583. pageNumber = destRef + 1;
  5584. } else {
  5585. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  5586. return;
  5587. }
  5588. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  5589. console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  5590. return;
  5591. }
  5592. if (this.pdfHistory) {
  5593. this.pdfHistory.pushCurrentPosition();
  5594. this.pdfHistory.push({
  5595. namedDest,
  5596. explicitDest,
  5597. pageNumber
  5598. });
  5599. }
  5600. this.pdfViewer.scrollPageIntoView({
  5601. pageNumber,
  5602. destArray: explicitDest,
  5603. ignoreDestinationZoom: this._ignoreDestinationZoom
  5604. });
  5605. }
  5606. async goToDestination(dest) {
  5607. if (!this.pdfDocument) {
  5608. return;
  5609. }
  5610. let namedDest, explicitDest;
  5611. if (typeof dest === "string") {
  5612. namedDest = dest;
  5613. explicitDest = await this.pdfDocument.getDestination(dest);
  5614. } else {
  5615. namedDest = null;
  5616. explicitDest = await dest;
  5617. }
  5618. if (!Array.isArray(explicitDest)) {
  5619. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  5620. return;
  5621. }
  5622. this._goToDestinationHelper(dest, namedDest, explicitDest);
  5623. }
  5624. goToPage(val) {
  5625. if (!this.pdfDocument) {
  5626. return;
  5627. }
  5628. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  5629. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  5630. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  5631. return;
  5632. }
  5633. if (this.pdfHistory) {
  5634. this.pdfHistory.pushCurrentPosition();
  5635. this.pdfHistory.pushPage(pageNumber);
  5636. }
  5637. this.pdfViewer.scrollPageIntoView({
  5638. pageNumber
  5639. });
  5640. }
  5641. getDestinationHash(dest) {
  5642. if (typeof dest === "string") {
  5643. if (dest.length > 0) {
  5644. return this.getAnchorUrl("#" + escape(dest));
  5645. }
  5646. } else if (Array.isArray(dest)) {
  5647. const str = JSON.stringify(dest);
  5648. if (str.length > 0) {
  5649. return this.getAnchorUrl("#" + escape(str));
  5650. }
  5651. }
  5652. return this.getAnchorUrl("");
  5653. }
  5654. getAnchorUrl(anchor) {
  5655. return (this.baseUrl || "") + anchor;
  5656. }
  5657. setHash(hash) {
  5658. if (!this.pdfDocument) {
  5659. return;
  5660. }
  5661. let pageNumber, dest;
  5662. if (hash.includes("=")) {
  5663. const params = (0, _ui_utils.parseQueryString)(hash);
  5664. if ("search" in params) {
  5665. this.eventBus.dispatch("findfromurlhash", {
  5666. source: this,
  5667. query: params.search.replace(/"/g, ""),
  5668. phraseSearch: params.phrase === "true"
  5669. });
  5670. }
  5671. if ("page" in params) {
  5672. pageNumber = params.page | 0 || 1;
  5673. }
  5674. if ("zoom" in params) {
  5675. const zoomArgs = params.zoom.split(",");
  5676. const zoomArg = zoomArgs[0];
  5677. const zoomArgNumber = parseFloat(zoomArg);
  5678. if (!zoomArg.includes("Fit")) {
  5679. dest = [null, {
  5680. name: "XYZ"
  5681. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  5682. } else {
  5683. if (zoomArg === "Fit" || zoomArg === "FitB") {
  5684. dest = [null, {
  5685. name: zoomArg
  5686. }];
  5687. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  5688. dest = [null, {
  5689. name: zoomArg
  5690. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  5691. } else if (zoomArg === "FitR") {
  5692. if (zoomArgs.length !== 5) {
  5693. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  5694. } else {
  5695. dest = [null, {
  5696. name: zoomArg
  5697. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  5698. }
  5699. } else {
  5700. console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
  5701. }
  5702. }
  5703. }
  5704. if (dest) {
  5705. this.pdfViewer.scrollPageIntoView({
  5706. pageNumber: pageNumber || this.page,
  5707. destArray: dest,
  5708. allowNegativeOffset: true
  5709. });
  5710. } else if (pageNumber) {
  5711. this.page = pageNumber;
  5712. }
  5713. if ("pagemode" in params) {
  5714. this.eventBus.dispatch("pagemode", {
  5715. source: this,
  5716. mode: params.pagemode
  5717. });
  5718. }
  5719. if ("nameddest" in params) {
  5720. this.goToDestination(params.nameddest);
  5721. }
  5722. } else {
  5723. dest = unescape(hash);
  5724. try {
  5725. dest = JSON.parse(dest);
  5726. if (!Array.isArray(dest)) {
  5727. dest = dest.toString();
  5728. }
  5729. } catch (ex) {}
  5730. if (typeof dest === "string" || isValidExplicitDestination(dest)) {
  5731. this.goToDestination(dest);
  5732. return;
  5733. }
  5734. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
  5735. }
  5736. }
  5737. executeNamedAction(action) {
  5738. switch (action) {
  5739. case "GoBack":
  5740. if (this.pdfHistory) {
  5741. this.pdfHistory.back();
  5742. }
  5743. break;
  5744. case "GoForward":
  5745. if (this.pdfHistory) {
  5746. this.pdfHistory.forward();
  5747. }
  5748. break;
  5749. case "NextPage":
  5750. this.pdfViewer.nextPage();
  5751. break;
  5752. case "PrevPage":
  5753. this.pdfViewer.previousPage();
  5754. break;
  5755. case "LastPage":
  5756. this.page = this.pagesCount;
  5757. break;
  5758. case "FirstPage":
  5759. this.page = 1;
  5760. break;
  5761. default:
  5762. break;
  5763. }
  5764. this.eventBus.dispatch("namedaction", {
  5765. source: this,
  5766. action
  5767. });
  5768. }
  5769. cachePageRef(pageNum, pageRef) {
  5770. if (!pageRef) {
  5771. return;
  5772. }
  5773. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5774. this._pagesRefCache[refStr] = pageNum;
  5775. }
  5776. _cachedPageNumber(pageRef) {
  5777. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5778. return this._pagesRefCache?.[refStr] || null;
  5779. }
  5780. isPageVisible(pageNumber) {
  5781. return this.pdfViewer.isPageVisible(pageNumber);
  5782. }
  5783. isPageCached(pageNumber) {
  5784. return this.pdfViewer.isPageCached(pageNumber);
  5785. }
  5786. }
  5787. exports.PDFLinkService = PDFLinkService;
  5788. function isValidExplicitDestination(dest) {
  5789. if (!Array.isArray(dest)) {
  5790. return false;
  5791. }
  5792. const destLength = dest.length;
  5793. if (destLength < 2) {
  5794. return false;
  5795. }
  5796. const page = dest[0];
  5797. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  5798. return false;
  5799. }
  5800. const zoom = dest[1];
  5801. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  5802. return false;
  5803. }
  5804. let allowNull = true;
  5805. switch (zoom.name) {
  5806. case "XYZ":
  5807. if (destLength !== 5) {
  5808. return false;
  5809. }
  5810. break;
  5811. case "Fit":
  5812. case "FitB":
  5813. return destLength === 2;
  5814. case "FitH":
  5815. case "FitBH":
  5816. case "FitV":
  5817. case "FitBV":
  5818. if (destLength !== 3) {
  5819. return false;
  5820. }
  5821. break;
  5822. case "FitR":
  5823. if (destLength !== 6) {
  5824. return false;
  5825. }
  5826. allowNull = false;
  5827. break;
  5828. default:
  5829. return false;
  5830. }
  5831. for (let i = 2; i < destLength; i++) {
  5832. const param = dest[i];
  5833. if (!(typeof param === "number" || allowNull && param === null)) {
  5834. return false;
  5835. }
  5836. }
  5837. return true;
  5838. }
  5839. class SimpleLinkService {
  5840. constructor() {
  5841. this.externalLinkTarget = null;
  5842. this.externalLinkRel = null;
  5843. this.externalLinkEnabled = true;
  5844. this._ignoreDestinationZoom = false;
  5845. }
  5846. get pagesCount() {
  5847. return 0;
  5848. }
  5849. get page() {
  5850. return 0;
  5851. }
  5852. set page(value) {}
  5853. get rotation() {
  5854. return 0;
  5855. }
  5856. set rotation(value) {}
  5857. async goToDestination(dest) {}
  5858. goToPage(val) {}
  5859. getDestinationHash(dest) {
  5860. return "#";
  5861. }
  5862. getAnchorUrl(hash) {
  5863. return "#";
  5864. }
  5865. setHash(hash) {}
  5866. executeNamedAction(action) {}
  5867. cachePageRef(pageNum, pageRef) {}
  5868. isPageVisible(pageNumber) {
  5869. return true;
  5870. }
  5871. isPageCached(pageNumber) {
  5872. return true;
  5873. }
  5874. }
  5875. exports.SimpleLinkService = SimpleLinkService;
  5876. /***/ }),
  5877. /* 20 */
  5878. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5879. Object.defineProperty(exports, "__esModule", ({
  5880. value: true
  5881. }));
  5882. exports.PDFOutlineViewer = void 0;
  5883. var _pdfjsLib = __webpack_require__(5);
  5884. var _base_tree_viewer = __webpack_require__(12);
  5885. var _ui_utils = __webpack_require__(4);
  5886. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  5887. constructor(options) {
  5888. super(options);
  5889. this.linkService = options.linkService;
  5890. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  5891. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  5892. this.eventBus._on("pagechanging", evt => {
  5893. this._currentPageNumber = evt.pageNumber;
  5894. });
  5895. this.eventBus._on("pagesloaded", evt => {
  5896. this._isPagesLoaded = !!evt.pagesCount;
  5897. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5898. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  5899. }
  5900. });
  5901. this.eventBus._on("sidebarviewchanged", evt => {
  5902. this._sidebarView = evt.view;
  5903. });
  5904. }
  5905. reset() {
  5906. super.reset();
  5907. this._outline = null;
  5908. this._pageNumberToDestHashCapability = null;
  5909. this._currentPageNumber = 1;
  5910. this._isPagesLoaded = false;
  5911. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5912. this._currentOutlineItemCapability.resolve(false);
  5913. }
  5914. this._currentOutlineItemCapability = null;
  5915. }
  5916. _dispatchEvent(outlineCount) {
  5917. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  5918. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  5919. this._currentOutlineItemCapability.resolve(false);
  5920. } else if (this._isPagesLoaded) {
  5921. this._currentOutlineItemCapability.resolve(true);
  5922. }
  5923. this.eventBus.dispatch("outlineloaded", {
  5924. source: this,
  5925. outlineCount,
  5926. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  5927. });
  5928. }
  5929. _bindLink(element, {
  5930. url,
  5931. newWindow,
  5932. dest
  5933. }) {
  5934. const {
  5935. linkService
  5936. } = this;
  5937. if (url) {
  5938. (0, _pdfjsLib.addLinkAttributes)(element, {
  5939. url,
  5940. target: newWindow ? _pdfjsLib.LinkTarget.BLANK : linkService.externalLinkTarget,
  5941. rel: linkService.externalLinkRel,
  5942. enabled: linkService.externalLinkEnabled
  5943. });
  5944. return;
  5945. }
  5946. element.href = linkService.getDestinationHash(dest);
  5947. element.onclick = evt => {
  5948. this._updateCurrentTreeItem(evt.target.parentNode);
  5949. if (dest) {
  5950. linkService.goToDestination(dest);
  5951. }
  5952. return false;
  5953. };
  5954. }
  5955. _setStyles(element, {
  5956. bold,
  5957. italic
  5958. }) {
  5959. if (bold) {
  5960. element.style.fontWeight = "bold";
  5961. }
  5962. if (italic) {
  5963. element.style.fontStyle = "italic";
  5964. }
  5965. }
  5966. _addToggleButton(div, {
  5967. count,
  5968. items
  5969. }) {
  5970. let hidden = false;
  5971. if (count < 0) {
  5972. let totalCount = items.length;
  5973. if (totalCount > 0) {
  5974. const queue = [...items];
  5975. while (queue.length > 0) {
  5976. const {
  5977. count: nestedCount,
  5978. items: nestedItems
  5979. } = queue.shift();
  5980. if (nestedCount > 0 && nestedItems.length > 0) {
  5981. totalCount += nestedItems.length;
  5982. queue.push(...nestedItems);
  5983. }
  5984. }
  5985. }
  5986. if (Math.abs(count) === totalCount) {
  5987. hidden = true;
  5988. }
  5989. }
  5990. super._addToggleButton(div, hidden);
  5991. }
  5992. _toggleAllTreeItems() {
  5993. if (!this._outline) {
  5994. return;
  5995. }
  5996. super._toggleAllTreeItems();
  5997. }
  5998. render({
  5999. outline,
  6000. pdfDocument
  6001. }) {
  6002. if (this._outline) {
  6003. this.reset();
  6004. }
  6005. this._outline = outline || null;
  6006. this._pdfDocument = pdfDocument || null;
  6007. if (!outline) {
  6008. this._dispatchEvent(0);
  6009. return;
  6010. }
  6011. const fragment = document.createDocumentFragment();
  6012. const queue = [{
  6013. parent: fragment,
  6014. items: outline
  6015. }];
  6016. let outlineCount = 0,
  6017. hasAnyNesting = false;
  6018. while (queue.length > 0) {
  6019. const levelData = queue.shift();
  6020. for (const item of levelData.items) {
  6021. const div = document.createElement("div");
  6022. div.className = "treeItem";
  6023. const element = document.createElement("a");
  6024. this._bindLink(element, item);
  6025. this._setStyles(element, item);
  6026. element.textContent = this._normalizeTextContent(item.title);
  6027. div.appendChild(element);
  6028. if (item.items.length > 0) {
  6029. hasAnyNesting = true;
  6030. this._addToggleButton(div, item);
  6031. const itemsDiv = document.createElement("div");
  6032. itemsDiv.className = "treeItems";
  6033. div.appendChild(itemsDiv);
  6034. queue.push({
  6035. parent: itemsDiv,
  6036. items: item.items
  6037. });
  6038. }
  6039. levelData.parent.appendChild(div);
  6040. outlineCount++;
  6041. }
  6042. }
  6043. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6044. }
  6045. async _currentOutlineItem() {
  6046. if (!this._isPagesLoaded) {
  6047. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6048. }
  6049. if (!this._outline || !this._pdfDocument) {
  6050. return;
  6051. }
  6052. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6053. if (!pageNumberToDestHash) {
  6054. return;
  6055. }
  6056. this._updateCurrentTreeItem(null);
  6057. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6058. return;
  6059. }
  6060. for (let i = this._currentPageNumber; i > 0; i--) {
  6061. const destHash = pageNumberToDestHash.get(i);
  6062. if (!destHash) {
  6063. continue;
  6064. }
  6065. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6066. if (!linkElement) {
  6067. continue;
  6068. }
  6069. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6070. break;
  6071. }
  6072. }
  6073. async _getPageNumberToDestHash(pdfDocument) {
  6074. if (this._pageNumberToDestHashCapability) {
  6075. return this._pageNumberToDestHashCapability.promise;
  6076. }
  6077. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6078. const pageNumberToDestHash = new Map(),
  6079. pageNumberNesting = new Map();
  6080. const queue = [{
  6081. nesting: 0,
  6082. items: this._outline
  6083. }];
  6084. while (queue.length > 0) {
  6085. const levelData = queue.shift(),
  6086. currentNesting = levelData.nesting;
  6087. for (const {
  6088. dest,
  6089. items
  6090. } of levelData.items) {
  6091. let explicitDest, pageNumber;
  6092. if (typeof dest === "string") {
  6093. explicitDest = await pdfDocument.getDestination(dest);
  6094. if (pdfDocument !== this._pdfDocument) {
  6095. return null;
  6096. }
  6097. } else {
  6098. explicitDest = dest;
  6099. }
  6100. if (Array.isArray(explicitDest)) {
  6101. const [destRef] = explicitDest;
  6102. if (destRef instanceof Object) {
  6103. pageNumber = this.linkService._cachedPageNumber(destRef);
  6104. if (!pageNumber) {
  6105. try {
  6106. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6107. if (pdfDocument !== this._pdfDocument) {
  6108. return null;
  6109. }
  6110. this.linkService.cachePageRef(pageNumber, destRef);
  6111. } catch (ex) {}
  6112. }
  6113. } else if (Number.isInteger(destRef)) {
  6114. pageNumber = destRef + 1;
  6115. }
  6116. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6117. const destHash = this.linkService.getDestinationHash(dest);
  6118. pageNumberToDestHash.set(pageNumber, destHash);
  6119. pageNumberNesting.set(pageNumber, currentNesting);
  6120. }
  6121. }
  6122. if (items.length > 0) {
  6123. queue.push({
  6124. nesting: currentNesting + 1,
  6125. items
  6126. });
  6127. }
  6128. }
  6129. }
  6130. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6131. return this._pageNumberToDestHashCapability.promise;
  6132. }
  6133. }
  6134. exports.PDFOutlineViewer = PDFOutlineViewer;
  6135. /***/ }),
  6136. /* 21 */
  6137. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6138. Object.defineProperty(exports, "__esModule", ({
  6139. value: true
  6140. }));
  6141. exports.PDFPresentationMode = void 0;
  6142. var _ui_utils = __webpack_require__(4);
  6143. const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  6144. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6145. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6146. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6147. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6148. const PAGE_SWITCH_THRESHOLD = 0.1;
  6149. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6150. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6151. class PDFPresentationMode {
  6152. constructor({
  6153. container,
  6154. pdfViewer,
  6155. eventBus
  6156. }) {
  6157. this.container = container;
  6158. this.pdfViewer = pdfViewer;
  6159. this.eventBus = eventBus;
  6160. this.active = false;
  6161. this.args = null;
  6162. this.contextMenuOpen = false;
  6163. this.mouseScrollTimeStamp = 0;
  6164. this.mouseScrollDelta = 0;
  6165. this.touchSwipeState = null;
  6166. }
  6167. request() {
  6168. if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) {
  6169. return false;
  6170. }
  6171. this._addFullscreenChangeListeners();
  6172. this._setSwitchInProgress();
  6173. this._notifyStateChange();
  6174. if (this.container.requestFullscreen) {
  6175. this.container.requestFullscreen();
  6176. } else if (this.container.mozRequestFullScreen) {
  6177. this.container.mozRequestFullScreen();
  6178. } else if (this.container.webkitRequestFullscreen) {
  6179. this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  6180. } else {
  6181. return false;
  6182. }
  6183. this.args = {
  6184. page: this.pdfViewer.currentPageNumber,
  6185. previousScale: this.pdfViewer.currentScaleValue
  6186. };
  6187. return true;
  6188. }
  6189. _mouseWheel(evt) {
  6190. if (!this.active) {
  6191. return;
  6192. }
  6193. evt.preventDefault();
  6194. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6195. const currentTime = Date.now();
  6196. const storedTime = this.mouseScrollTimeStamp;
  6197. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6198. return;
  6199. }
  6200. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6201. this._resetMouseScrollState();
  6202. }
  6203. this.mouseScrollDelta += delta;
  6204. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6205. const totalDelta = this.mouseScrollDelta;
  6206. this._resetMouseScrollState();
  6207. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6208. if (success) {
  6209. this.mouseScrollTimeStamp = currentTime;
  6210. }
  6211. }
  6212. }
  6213. get isFullscreen() {
  6214. return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen);
  6215. }
  6216. _notifyStateChange() {
  6217. let state = _ui_utils.PresentationModeState.NORMAL;
  6218. if (this.switchInProgress) {
  6219. state = _ui_utils.PresentationModeState.CHANGING;
  6220. } else if (this.active) {
  6221. state = _ui_utils.PresentationModeState.FULLSCREEN;
  6222. }
  6223. this.eventBus.dispatch("presentationmodechanged", {
  6224. source: this,
  6225. state
  6226. });
  6227. }
  6228. _setSwitchInProgress() {
  6229. if (this.switchInProgress) {
  6230. clearTimeout(this.switchInProgress);
  6231. }
  6232. this.switchInProgress = setTimeout(() => {
  6233. this._removeFullscreenChangeListeners();
  6234. delete this.switchInProgress;
  6235. this._notifyStateChange();
  6236. }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  6237. }
  6238. _resetSwitchInProgress() {
  6239. if (this.switchInProgress) {
  6240. clearTimeout(this.switchInProgress);
  6241. delete this.switchInProgress;
  6242. }
  6243. }
  6244. _enter() {
  6245. this.active = true;
  6246. this._resetSwitchInProgress();
  6247. this._notifyStateChange();
  6248. this.container.classList.add(ACTIVE_SELECTOR);
  6249. setTimeout(() => {
  6250. this.pdfViewer.currentPageNumber = this.args.page;
  6251. this.pdfViewer.currentScaleValue = "page-fit";
  6252. }, 0);
  6253. this._addWindowListeners();
  6254. this._showControls();
  6255. this.contextMenuOpen = false;
  6256. window.getSelection().removeAllRanges();
  6257. }
  6258. _exit() {
  6259. const page = this.pdfViewer.currentPageNumber;
  6260. this.container.classList.remove(ACTIVE_SELECTOR);
  6261. setTimeout(() => {
  6262. this.active = false;
  6263. this._removeFullscreenChangeListeners();
  6264. this._notifyStateChange();
  6265. this.pdfViewer.currentScaleValue = this.args.previousScale;
  6266. this.pdfViewer.currentPageNumber = page;
  6267. this.args = null;
  6268. }, 0);
  6269. this._removeWindowListeners();
  6270. this._hideControls();
  6271. this._resetMouseScrollState();
  6272. this.contextMenuOpen = false;
  6273. }
  6274. _mouseDown(evt) {
  6275. if (this.contextMenuOpen) {
  6276. this.contextMenuOpen = false;
  6277. evt.preventDefault();
  6278. return;
  6279. }
  6280. if (evt.button === 0) {
  6281. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6282. if (!isInternalLink) {
  6283. evt.preventDefault();
  6284. if (evt.shiftKey) {
  6285. this.pdfViewer.previousPage();
  6286. } else {
  6287. this.pdfViewer.nextPage();
  6288. }
  6289. }
  6290. }
  6291. }
  6292. _contextMenu() {
  6293. this.contextMenuOpen = true;
  6294. }
  6295. _showControls() {
  6296. if (this.controlsTimeout) {
  6297. clearTimeout(this.controlsTimeout);
  6298. } else {
  6299. this.container.classList.add(CONTROLS_SELECTOR);
  6300. }
  6301. this.controlsTimeout = setTimeout(() => {
  6302. this.container.classList.remove(CONTROLS_SELECTOR);
  6303. delete this.controlsTimeout;
  6304. }, DELAY_BEFORE_HIDING_CONTROLS);
  6305. }
  6306. _hideControls() {
  6307. if (!this.controlsTimeout) {
  6308. return;
  6309. }
  6310. clearTimeout(this.controlsTimeout);
  6311. this.container.classList.remove(CONTROLS_SELECTOR);
  6312. delete this.controlsTimeout;
  6313. }
  6314. _resetMouseScrollState() {
  6315. this.mouseScrollTimeStamp = 0;
  6316. this.mouseScrollDelta = 0;
  6317. }
  6318. _touchSwipe(evt) {
  6319. if (!this.active) {
  6320. return;
  6321. }
  6322. if (evt.touches.length > 1) {
  6323. this.touchSwipeState = null;
  6324. return;
  6325. }
  6326. switch (evt.type) {
  6327. case "touchstart":
  6328. this.touchSwipeState = {
  6329. startX: evt.touches[0].pageX,
  6330. startY: evt.touches[0].pageY,
  6331. endX: evt.touches[0].pageX,
  6332. endY: evt.touches[0].pageY
  6333. };
  6334. break;
  6335. case "touchmove":
  6336. if (this.touchSwipeState === null) {
  6337. return;
  6338. }
  6339. this.touchSwipeState.endX = evt.touches[0].pageX;
  6340. this.touchSwipeState.endY = evt.touches[0].pageY;
  6341. evt.preventDefault();
  6342. break;
  6343. case "touchend":
  6344. if (this.touchSwipeState === null) {
  6345. return;
  6346. }
  6347. let delta = 0;
  6348. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6349. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6350. const absAngle = Math.abs(Math.atan2(dy, dx));
  6351. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6352. delta = dx;
  6353. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6354. delta = dy;
  6355. }
  6356. if (delta > 0) {
  6357. this.pdfViewer.previousPage();
  6358. } else if (delta < 0) {
  6359. this.pdfViewer.nextPage();
  6360. }
  6361. break;
  6362. }
  6363. }
  6364. _addWindowListeners() {
  6365. this.showControlsBind = this._showControls.bind(this);
  6366. this.mouseDownBind = this._mouseDown.bind(this);
  6367. this.mouseWheelBind = this._mouseWheel.bind(this);
  6368. this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
  6369. this.contextMenuBind = this._contextMenu.bind(this);
  6370. this.touchSwipeBind = this._touchSwipe.bind(this);
  6371. window.addEventListener("mousemove", this.showControlsBind);
  6372. window.addEventListener("mousedown", this.mouseDownBind);
  6373. window.addEventListener("wheel", this.mouseWheelBind, {
  6374. passive: false
  6375. });
  6376. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6377. window.addEventListener("contextmenu", this.contextMenuBind);
  6378. window.addEventListener("touchstart", this.touchSwipeBind);
  6379. window.addEventListener("touchmove", this.touchSwipeBind);
  6380. window.addEventListener("touchend", this.touchSwipeBind);
  6381. }
  6382. _removeWindowListeners() {
  6383. window.removeEventListener("mousemove", this.showControlsBind);
  6384. window.removeEventListener("mousedown", this.mouseDownBind);
  6385. window.removeEventListener("wheel", this.mouseWheelBind, {
  6386. passive: false
  6387. });
  6388. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6389. window.removeEventListener("contextmenu", this.contextMenuBind);
  6390. window.removeEventListener("touchstart", this.touchSwipeBind);
  6391. window.removeEventListener("touchmove", this.touchSwipeBind);
  6392. window.removeEventListener("touchend", this.touchSwipeBind);
  6393. delete this.showControlsBind;
  6394. delete this.mouseDownBind;
  6395. delete this.mouseWheelBind;
  6396. delete this.resetMouseScrollStateBind;
  6397. delete this.contextMenuBind;
  6398. delete this.touchSwipeBind;
  6399. }
  6400. _fullscreenChange() {
  6401. if (this.isFullscreen) {
  6402. this._enter();
  6403. } else {
  6404. this._exit();
  6405. }
  6406. }
  6407. _addFullscreenChangeListeners() {
  6408. this.fullscreenChangeBind = this._fullscreenChange.bind(this);
  6409. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6410. window.addEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6411. window.addEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6412. }
  6413. _removeFullscreenChangeListeners() {
  6414. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6415. window.removeEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6416. window.removeEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6417. delete this.fullscreenChangeBind;
  6418. }
  6419. }
  6420. exports.PDFPresentationMode = PDFPresentationMode;
  6421. /***/ }),
  6422. /* 22 */
  6423. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6424. Object.defineProperty(exports, "__esModule", ({
  6425. value: true
  6426. }));
  6427. exports.PDFScriptingManager = void 0;
  6428. var _pdfjsLib = __webpack_require__(5);
  6429. var _ui_utils = __webpack_require__(4);
  6430. var _pdf_rendering_queue = __webpack_require__(8);
  6431. class PDFScriptingManager {
  6432. constructor({
  6433. eventBus,
  6434. sandboxBundleSrc = null,
  6435. scriptingFactory = null,
  6436. docPropertiesLookup = null
  6437. }) {
  6438. this._pdfDocument = null;
  6439. this._pdfViewer = null;
  6440. this._closeCapability = null;
  6441. this._destroyCapability = null;
  6442. this._scripting = null;
  6443. this._mouseState = Object.create(null);
  6444. this._pageEventsReady = false;
  6445. this._ready = false;
  6446. this._eventBus = eventBus;
  6447. this._sandboxBundleSrc = sandboxBundleSrc;
  6448. this._scriptingFactory = scriptingFactory;
  6449. this._docPropertiesLookup = docPropertiesLookup;
  6450. }
  6451. setViewer(pdfViewer) {
  6452. this._pdfViewer = pdfViewer;
  6453. }
  6454. async setDocument(pdfDocument) {
  6455. if (this._pdfDocument) {
  6456. await this._destroyScripting();
  6457. }
  6458. this._pdfDocument = pdfDocument;
  6459. if (!pdfDocument) {
  6460. return;
  6461. }
  6462. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6463. if (!objects && !docActions) {
  6464. await this._destroyScripting();
  6465. return;
  6466. }
  6467. if (pdfDocument !== this._pdfDocument) {
  6468. return;
  6469. }
  6470. this._scripting = this._createScripting();
  6471. this._internalEvents.set("updatefromsandbox", event => {
  6472. if (event?.source !== window) {
  6473. return;
  6474. }
  6475. this._updateFromSandbox(event.detail);
  6476. });
  6477. this._internalEvents.set("dispatcheventinsandbox", event => {
  6478. this._scripting?.dispatchEventInSandbox(event.detail);
  6479. });
  6480. this._internalEvents.set("pagechanging", ({
  6481. pageNumber,
  6482. previous
  6483. }) => {
  6484. if (pageNumber === previous) {
  6485. return;
  6486. }
  6487. this._dispatchPageClose(previous);
  6488. this._dispatchPageOpen(pageNumber);
  6489. });
  6490. this._internalEvents.set("pagerendered", ({
  6491. pageNumber
  6492. }) => {
  6493. if (!this._pageOpenPending.has(pageNumber)) {
  6494. return;
  6495. }
  6496. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6497. return;
  6498. }
  6499. this._dispatchPageOpen(pageNumber);
  6500. });
  6501. this._internalEvents.set("pagesdestroy", async event => {
  6502. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6503. await this._scripting?.dispatchEventInSandbox({
  6504. id: "doc",
  6505. name: "WillClose"
  6506. });
  6507. this._closeCapability?.resolve();
  6508. });
  6509. this._domEvents.set("mousedown", event => {
  6510. this._mouseState.isDown = true;
  6511. });
  6512. this._domEvents.set("mouseup", event => {
  6513. this._mouseState.isDown = false;
  6514. });
  6515. for (const [name, listener] of this._internalEvents) {
  6516. this._eventBus._on(name, listener);
  6517. }
  6518. for (const [name, listener] of this._domEvents) {
  6519. window.addEventListener(name, listener);
  6520. }
  6521. try {
  6522. const docProperties = await this._getDocProperties();
  6523. if (pdfDocument !== this._pdfDocument) {
  6524. return;
  6525. }
  6526. await this._scripting.createSandbox({
  6527. objects,
  6528. calculationOrder,
  6529. appInfo: {
  6530. platform: navigator.platform,
  6531. language: navigator.language
  6532. },
  6533. docInfo: { ...docProperties,
  6534. actions: docActions
  6535. }
  6536. });
  6537. this._eventBus.dispatch("sandboxcreated", {
  6538. source: this
  6539. });
  6540. } catch (error) {
  6541. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6542. await this._destroyScripting();
  6543. return;
  6544. }
  6545. await this._scripting?.dispatchEventInSandbox({
  6546. id: "doc",
  6547. name: "Open"
  6548. });
  6549. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6550. Promise.resolve().then(() => {
  6551. if (pdfDocument === this._pdfDocument) {
  6552. this._ready = true;
  6553. }
  6554. });
  6555. }
  6556. async dispatchWillSave(detail) {
  6557. return this._scripting?.dispatchEventInSandbox({
  6558. id: "doc",
  6559. name: "WillSave"
  6560. });
  6561. }
  6562. async dispatchDidSave(detail) {
  6563. return this._scripting?.dispatchEventInSandbox({
  6564. id: "doc",
  6565. name: "DidSave"
  6566. });
  6567. }
  6568. async dispatchWillPrint(detail) {
  6569. return this._scripting?.dispatchEventInSandbox({
  6570. id: "doc",
  6571. name: "WillPrint"
  6572. });
  6573. }
  6574. async dispatchDidPrint(detail) {
  6575. return this._scripting?.dispatchEventInSandbox({
  6576. id: "doc",
  6577. name: "DidPrint"
  6578. });
  6579. }
  6580. get mouseState() {
  6581. return this._mouseState;
  6582. }
  6583. get destroyPromise() {
  6584. return this._destroyCapability?.promise || null;
  6585. }
  6586. get ready() {
  6587. return this._ready;
  6588. }
  6589. get _internalEvents() {
  6590. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6591. }
  6592. get _domEvents() {
  6593. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6594. }
  6595. get _pageOpenPending() {
  6596. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6597. }
  6598. get _visitedPages() {
  6599. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6600. }
  6601. async _updateFromSandbox(detail) {
  6602. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6603. const {
  6604. id,
  6605. siblings,
  6606. command,
  6607. value
  6608. } = detail;
  6609. if (!id) {
  6610. switch (command) {
  6611. case "clear":
  6612. console.clear();
  6613. break;
  6614. case "error":
  6615. console.error(value);
  6616. break;
  6617. case "layout":
  6618. this._pdfViewer.spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(value);
  6619. break;
  6620. case "page-num":
  6621. this._pdfViewer.currentPageNumber = value + 1;
  6622. break;
  6623. case "print":
  6624. await this._pdfViewer.pagesPromise;
  6625. this._eventBus.dispatch("print", {
  6626. source: this
  6627. });
  6628. break;
  6629. case "println":
  6630. console.log(value);
  6631. break;
  6632. case "zoom":
  6633. if (isInPresentationMode) {
  6634. return;
  6635. }
  6636. this._pdfViewer.currentScaleValue = value;
  6637. break;
  6638. }
  6639. return;
  6640. }
  6641. if (isInPresentationMode) {
  6642. if (detail.focus) {
  6643. return;
  6644. }
  6645. }
  6646. delete detail.id;
  6647. delete detail.siblings;
  6648. const ids = siblings ? [id, ...siblings] : [id];
  6649. for (const elementId of ids) {
  6650. const element = document.getElementById(elementId);
  6651. if (element) {
  6652. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6653. detail
  6654. }));
  6655. } else {
  6656. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6657. }
  6658. }
  6659. }
  6660. async _dispatchPageOpen(pageNumber, initialize = false) {
  6661. const pdfDocument = this._pdfDocument,
  6662. visitedPages = this._visitedPages;
  6663. if (initialize) {
  6664. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6665. this._pageEventsReady = true;
  6666. }
  6667. if (!this._pageEventsReady) {
  6668. return;
  6669. }
  6670. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6671. if (pageView?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  6672. this._pageOpenPending.add(pageNumber);
  6673. return;
  6674. }
  6675. this._pageOpenPending.delete(pageNumber);
  6676. const actionsPromise = (async () => {
  6677. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6678. if (pdfDocument !== this._pdfDocument) {
  6679. return;
  6680. }
  6681. await this._scripting?.dispatchEventInSandbox({
  6682. id: "page",
  6683. name: "PageOpen",
  6684. pageNumber,
  6685. actions
  6686. });
  6687. })();
  6688. visitedPages.set(pageNumber, actionsPromise);
  6689. }
  6690. async _dispatchPageClose(pageNumber) {
  6691. const pdfDocument = this._pdfDocument,
  6692. visitedPages = this._visitedPages;
  6693. if (!this._pageEventsReady) {
  6694. return;
  6695. }
  6696. if (this._pageOpenPending.has(pageNumber)) {
  6697. return;
  6698. }
  6699. const actionsPromise = visitedPages.get(pageNumber);
  6700. if (!actionsPromise) {
  6701. return;
  6702. }
  6703. visitedPages.set(pageNumber, null);
  6704. await actionsPromise;
  6705. if (pdfDocument !== this._pdfDocument) {
  6706. return;
  6707. }
  6708. await this._scripting?.dispatchEventInSandbox({
  6709. id: "page",
  6710. name: "PageClose",
  6711. pageNumber
  6712. });
  6713. }
  6714. async _getDocProperties() {
  6715. if (this._docPropertiesLookup) {
  6716. return this._docPropertiesLookup(this._pdfDocument);
  6717. }
  6718. throw new Error("_getDocProperties: Unable to lookup properties.");
  6719. }
  6720. _createScripting() {
  6721. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  6722. if (this._scripting) {
  6723. throw new Error("_createScripting: Scripting already exists.");
  6724. }
  6725. if (this._scriptingFactory) {
  6726. return this._scriptingFactory.createScripting({
  6727. sandboxBundleSrc: this._sandboxBundleSrc
  6728. });
  6729. }
  6730. throw new Error("_createScripting: Cannot create scripting.");
  6731. }
  6732. async _destroyScripting() {
  6733. if (!this._scripting) {
  6734. this._pdfDocument = null;
  6735. this._destroyCapability?.resolve();
  6736. return;
  6737. }
  6738. if (this._closeCapability) {
  6739. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  6740. setTimeout(resolve, 1000);
  6741. })]).catch(reason => {});
  6742. this._closeCapability = null;
  6743. }
  6744. this._pdfDocument = null;
  6745. try {
  6746. await this._scripting.destroySandbox();
  6747. } catch (ex) {}
  6748. for (const [name, listener] of this._internalEvents) {
  6749. this._eventBus._off(name, listener);
  6750. }
  6751. this._internalEvents.clear();
  6752. for (const [name, listener] of this._domEvents) {
  6753. window.removeEventListener(name, listener);
  6754. }
  6755. this._domEvents.clear();
  6756. this._pageOpenPending.clear();
  6757. this._visitedPages.clear();
  6758. this._scripting = null;
  6759. delete this._mouseState.isDown;
  6760. this._pageEventsReady = false;
  6761. this._ready = false;
  6762. this._destroyCapability?.resolve();
  6763. }
  6764. }
  6765. exports.PDFScriptingManager = PDFScriptingManager;
  6766. /***/ }),
  6767. /* 23 */
  6768. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6769. Object.defineProperty(exports, "__esModule", ({
  6770. value: true
  6771. }));
  6772. exports.PDFSidebar = void 0;
  6773. var _ui_utils = __webpack_require__(4);
  6774. var _pdf_rendering_queue = __webpack_require__(8);
  6775. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  6776. class PDFSidebar {
  6777. constructor({
  6778. elements,
  6779. pdfViewer,
  6780. pdfThumbnailViewer,
  6781. eventBus,
  6782. l10n
  6783. }) {
  6784. this.isOpen = false;
  6785. this.active = _ui_utils.SidebarView.THUMBS;
  6786. this.isInitialViewSet = false;
  6787. this.onToggled = null;
  6788. this.pdfViewer = pdfViewer;
  6789. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6790. this.outerContainer = elements.outerContainer;
  6791. this.viewerContainer = elements.viewerContainer;
  6792. this.toggleButton = elements.toggleButton;
  6793. this.thumbnailButton = elements.thumbnailButton;
  6794. this.outlineButton = elements.outlineButton;
  6795. this.attachmentsButton = elements.attachmentsButton;
  6796. this.layersButton = elements.layersButton;
  6797. this.thumbnailView = elements.thumbnailView;
  6798. this.outlineView = elements.outlineView;
  6799. this.attachmentsView = elements.attachmentsView;
  6800. this.layersView = elements.layersView;
  6801. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  6802. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  6803. this.eventBus = eventBus;
  6804. this.l10n = l10n;
  6805. this._addEventListeners();
  6806. }
  6807. reset() {
  6808. this.isInitialViewSet = false;
  6809. this._hideUINotification(true);
  6810. this.switchView(_ui_utils.SidebarView.THUMBS);
  6811. this.outlineButton.disabled = false;
  6812. this.attachmentsButton.disabled = false;
  6813. this.layersButton.disabled = false;
  6814. this._currentOutlineItemButton.disabled = true;
  6815. }
  6816. get visibleView() {
  6817. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  6818. }
  6819. get isThumbnailViewVisible() {
  6820. return this.isOpen && this.active === _ui_utils.SidebarView.THUMBS;
  6821. }
  6822. get isOutlineViewVisible() {
  6823. return this.isOpen && this.active === _ui_utils.SidebarView.OUTLINE;
  6824. }
  6825. get isAttachmentsViewVisible() {
  6826. return this.isOpen && this.active === _ui_utils.SidebarView.ATTACHMENTS;
  6827. }
  6828. get isLayersViewVisible() {
  6829. return this.isOpen && this.active === _ui_utils.SidebarView.LAYERS;
  6830. }
  6831. setInitialView(view = _ui_utils.SidebarView.NONE) {
  6832. if (this.isInitialViewSet) {
  6833. return;
  6834. }
  6835. this.isInitialViewSet = true;
  6836. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  6837. this._dispatchEvent();
  6838. return;
  6839. }
  6840. if (!this._switchView(view, true)) {
  6841. this._dispatchEvent();
  6842. }
  6843. }
  6844. switchView(view, forceOpen = false) {
  6845. this._switchView(view, forceOpen);
  6846. }
  6847. _switchView(view, forceOpen = false) {
  6848. const isViewChanged = view !== this.active;
  6849. let shouldForceRendering = false;
  6850. switch (view) {
  6851. case _ui_utils.SidebarView.NONE:
  6852. if (this.isOpen) {
  6853. this.close();
  6854. return true;
  6855. }
  6856. return false;
  6857. case _ui_utils.SidebarView.THUMBS:
  6858. if (this.isOpen && isViewChanged) {
  6859. shouldForceRendering = true;
  6860. }
  6861. break;
  6862. case _ui_utils.SidebarView.OUTLINE:
  6863. if (this.outlineButton.disabled) {
  6864. return false;
  6865. }
  6866. break;
  6867. case _ui_utils.SidebarView.ATTACHMENTS:
  6868. if (this.attachmentsButton.disabled) {
  6869. return false;
  6870. }
  6871. break;
  6872. case _ui_utils.SidebarView.LAYERS:
  6873. if (this.layersButton.disabled) {
  6874. return false;
  6875. }
  6876. break;
  6877. default:
  6878. console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
  6879. return false;
  6880. }
  6881. this.active = view;
  6882. this.thumbnailButton.classList.toggle("toggled", view === _ui_utils.SidebarView.THUMBS);
  6883. this.outlineButton.classList.toggle("toggled", view === _ui_utils.SidebarView.OUTLINE);
  6884. this.attachmentsButton.classList.toggle("toggled", view === _ui_utils.SidebarView.ATTACHMENTS);
  6885. this.layersButton.classList.toggle("toggled", view === _ui_utils.SidebarView.LAYERS);
  6886. this.thumbnailView.classList.toggle("hidden", view !== _ui_utils.SidebarView.THUMBS);
  6887. this.outlineView.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6888. this.attachmentsView.classList.toggle("hidden", view !== _ui_utils.SidebarView.ATTACHMENTS);
  6889. this.layersView.classList.toggle("hidden", view !== _ui_utils.SidebarView.LAYERS);
  6890. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6891. if (forceOpen && !this.isOpen) {
  6892. this.open();
  6893. return true;
  6894. }
  6895. if (shouldForceRendering) {
  6896. this._updateThumbnailViewer();
  6897. this._forceRendering();
  6898. }
  6899. if (isViewChanged) {
  6900. this._dispatchEvent();
  6901. }
  6902. return isViewChanged;
  6903. }
  6904. open() {
  6905. if (this.isOpen) {
  6906. return;
  6907. }
  6908. this.isOpen = true;
  6909. this.toggleButton.classList.add("toggled");
  6910. this.toggleButton.setAttribute("aria-expanded", "true");
  6911. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  6912. if (this.active === _ui_utils.SidebarView.THUMBS) {
  6913. this._updateThumbnailViewer();
  6914. }
  6915. this._forceRendering();
  6916. this._dispatchEvent();
  6917. this._hideUINotification();
  6918. }
  6919. close() {
  6920. if (!this.isOpen) {
  6921. return;
  6922. }
  6923. this.isOpen = false;
  6924. this.toggleButton.classList.remove("toggled");
  6925. this.toggleButton.setAttribute("aria-expanded", "false");
  6926. this.outerContainer.classList.add("sidebarMoving");
  6927. this.outerContainer.classList.remove("sidebarOpen");
  6928. this._forceRendering();
  6929. this._dispatchEvent();
  6930. }
  6931. toggle() {
  6932. if (this.isOpen) {
  6933. this.close();
  6934. } else {
  6935. this.open();
  6936. }
  6937. }
  6938. _dispatchEvent() {
  6939. this.eventBus.dispatch("sidebarviewchanged", {
  6940. source: this,
  6941. view: this.visibleView
  6942. });
  6943. }
  6944. _forceRendering() {
  6945. if (this.onToggled) {
  6946. this.onToggled();
  6947. } else {
  6948. this.pdfViewer.forceRendering();
  6949. this.pdfThumbnailViewer.forceRendering();
  6950. }
  6951. }
  6952. _updateThumbnailViewer() {
  6953. const {
  6954. pdfViewer,
  6955. pdfThumbnailViewer
  6956. } = this;
  6957. const pagesCount = pdfViewer.pagesCount;
  6958. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  6959. const pageView = pdfViewer.getPageView(pageIndex);
  6960. if (pageView?.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
  6961. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  6962. thumbnailView.setImage(pageView);
  6963. }
  6964. }
  6965. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  6966. }
  6967. _showUINotification() {
  6968. this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
  6969. this.toggleButton.title = msg;
  6970. });
  6971. if (!this.isOpen) {
  6972. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  6973. }
  6974. }
  6975. _hideUINotification(reset = false) {
  6976. if (this.isOpen || reset) {
  6977. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  6978. }
  6979. if (reset) {
  6980. this.l10n.get("toggle_sidebar.title").then(msg => {
  6981. this.toggleButton.title = msg;
  6982. });
  6983. }
  6984. }
  6985. _addEventListeners() {
  6986. this.viewerContainer.addEventListener("transitionend", evt => {
  6987. if (evt.target === this.viewerContainer) {
  6988. this.outerContainer.classList.remove("sidebarMoving");
  6989. }
  6990. });
  6991. this.toggleButton.addEventListener("click", () => {
  6992. this.toggle();
  6993. });
  6994. this.thumbnailButton.addEventListener("click", () => {
  6995. this.switchView(_ui_utils.SidebarView.THUMBS);
  6996. });
  6997. this.outlineButton.addEventListener("click", () => {
  6998. this.switchView(_ui_utils.SidebarView.OUTLINE);
  6999. });
  7000. this.outlineButton.addEventListener("dblclick", () => {
  7001. this.eventBus.dispatch("toggleoutlinetree", {
  7002. source: this
  7003. });
  7004. });
  7005. this.attachmentsButton.addEventListener("click", () => {
  7006. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7007. });
  7008. this.layersButton.addEventListener("click", () => {
  7009. this.switchView(_ui_utils.SidebarView.LAYERS);
  7010. });
  7011. this.layersButton.addEventListener("dblclick", () => {
  7012. this.eventBus.dispatch("resetlayers", {
  7013. source: this
  7014. });
  7015. });
  7016. this._currentOutlineItemButton.addEventListener("click", () => {
  7017. this.eventBus.dispatch("currentoutlineitem", {
  7018. source: this
  7019. });
  7020. });
  7021. const onTreeLoaded = (count, button, view) => {
  7022. button.disabled = !count;
  7023. if (count) {
  7024. this._showUINotification();
  7025. } else if (this.active === view) {
  7026. this.switchView(_ui_utils.SidebarView.THUMBS);
  7027. }
  7028. };
  7029. this.eventBus._on("outlineloaded", evt => {
  7030. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7031. evt.currentOutlineItemPromise.then(enabled => {
  7032. if (!this.isInitialViewSet) {
  7033. return;
  7034. }
  7035. this._currentOutlineItemButton.disabled = !enabled;
  7036. });
  7037. });
  7038. this.eventBus._on("attachmentsloaded", evt => {
  7039. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7040. });
  7041. this.eventBus._on("layersloaded", evt => {
  7042. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7043. });
  7044. this.eventBus._on("presentationmodechanged", evt => {
  7045. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.isThumbnailViewVisible) {
  7046. this._updateThumbnailViewer();
  7047. }
  7048. });
  7049. }
  7050. }
  7051. exports.PDFSidebar = PDFSidebar;
  7052. /***/ }),
  7053. /* 24 */
  7054. /***/ ((__unused_webpack_module, exports) => {
  7055. Object.defineProperty(exports, "__esModule", ({
  7056. value: true
  7057. }));
  7058. exports.PDFSidebarResizer = void 0;
  7059. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7060. const SIDEBAR_MIN_WIDTH = 200;
  7061. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7062. class PDFSidebarResizer {
  7063. constructor(options, eventBus, l10n) {
  7064. this.isRTL = false;
  7065. this.sidebarOpen = false;
  7066. this.doc = document.documentElement;
  7067. this._width = null;
  7068. this._outerContainerWidth = null;
  7069. this._boundEvents = Object.create(null);
  7070. this.outerContainer = options.outerContainer;
  7071. this.resizer = options.resizer;
  7072. this.eventBus = eventBus;
  7073. l10n.getDirection().then(dir => {
  7074. this.isRTL = dir === "rtl";
  7075. });
  7076. this._addEventListeners();
  7077. }
  7078. get outerContainerWidth() {
  7079. return this._outerContainerWidth || (this._outerContainerWidth = this.outerContainer.clientWidth);
  7080. }
  7081. _updateWidth(width = 0) {
  7082. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7083. if (width > maxWidth) {
  7084. width = maxWidth;
  7085. }
  7086. if (width < SIDEBAR_MIN_WIDTH) {
  7087. width = SIDEBAR_MIN_WIDTH;
  7088. }
  7089. if (width === this._width) {
  7090. return false;
  7091. }
  7092. this._width = width;
  7093. this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7094. return true;
  7095. }
  7096. _mouseMove(evt) {
  7097. let width = evt.clientX;
  7098. if (this.isRTL) {
  7099. width = this.outerContainerWidth - width;
  7100. }
  7101. this._updateWidth(width);
  7102. }
  7103. _mouseUp(evt) {
  7104. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7105. this.eventBus.dispatch("resize", {
  7106. source: this
  7107. });
  7108. const _boundEvents = this._boundEvents;
  7109. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7110. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7111. }
  7112. _addEventListeners() {
  7113. const _boundEvents = this._boundEvents;
  7114. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7115. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7116. this.resizer.addEventListener("mousedown", evt => {
  7117. if (evt.button !== 0) {
  7118. return;
  7119. }
  7120. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7121. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7122. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7123. });
  7124. this.eventBus._on("sidebarviewchanged", evt => {
  7125. this.sidebarOpen = !!evt?.view;
  7126. });
  7127. this.eventBus._on("resize", evt => {
  7128. if (evt?.source !== window) {
  7129. return;
  7130. }
  7131. this._outerContainerWidth = null;
  7132. if (!this._width) {
  7133. return;
  7134. }
  7135. if (!this.sidebarOpen) {
  7136. this._updateWidth(this._width);
  7137. return;
  7138. }
  7139. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7140. const updated = this._updateWidth(this._width);
  7141. Promise.resolve().then(() => {
  7142. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7143. if (updated) {
  7144. this.eventBus.dispatch("resize", {
  7145. source: this
  7146. });
  7147. }
  7148. });
  7149. });
  7150. }
  7151. }
  7152. exports.PDFSidebarResizer = PDFSidebarResizer;
  7153. /***/ }),
  7154. /* 25 */
  7155. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7156. Object.defineProperty(exports, "__esModule", ({
  7157. value: true
  7158. }));
  7159. exports.PDFThumbnailViewer = void 0;
  7160. var _ui_utils = __webpack_require__(4);
  7161. var _pdf_thumbnail_view = __webpack_require__(26);
  7162. var _pdf_rendering_queue = __webpack_require__(8);
  7163. const THUMBNAIL_SCROLL_MARGIN = -19;
  7164. const THUMBNAIL_SELECTED_CLASS = "selected";
  7165. class PDFThumbnailViewer {
  7166. constructor({
  7167. container,
  7168. eventBus,
  7169. linkService,
  7170. renderingQueue,
  7171. l10n
  7172. }) {
  7173. this.container = container;
  7174. this.linkService = linkService;
  7175. this.renderingQueue = renderingQueue;
  7176. this.l10n = l10n;
  7177. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7178. this._resetView();
  7179. eventBus._on("optionalcontentconfigchanged", () => {
  7180. this._setImageDisabled = true;
  7181. });
  7182. }
  7183. _scrollUpdated() {
  7184. this.renderingQueue.renderHighestPriority();
  7185. }
  7186. getThumbnail(index) {
  7187. return this._thumbnails[index];
  7188. }
  7189. _getVisibleThumbs() {
  7190. return (0, _ui_utils.getVisibleElements)({
  7191. scrollEl: this.container,
  7192. views: this._thumbnails
  7193. });
  7194. }
  7195. scrollThumbnailIntoView(pageNumber) {
  7196. if (!this.pdfDocument) {
  7197. return;
  7198. }
  7199. const thumbnailView = this._thumbnails[pageNumber - 1];
  7200. if (!thumbnailView) {
  7201. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7202. return;
  7203. }
  7204. if (pageNumber !== this._currentPageNumber) {
  7205. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7206. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7207. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7208. }
  7209. const visibleThumbs = this._getVisibleThumbs();
  7210. const numVisibleThumbs = visibleThumbs.views.length;
  7211. if (numVisibleThumbs > 0) {
  7212. const first = visibleThumbs.first.id;
  7213. const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
  7214. let shouldScroll = false;
  7215. if (pageNumber <= first || pageNumber >= last) {
  7216. shouldScroll = true;
  7217. } else {
  7218. visibleThumbs.views.some(function (view) {
  7219. if (view.id !== pageNumber) {
  7220. return false;
  7221. }
  7222. shouldScroll = view.percent < 100;
  7223. return true;
  7224. });
  7225. }
  7226. if (shouldScroll) {
  7227. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7228. top: THUMBNAIL_SCROLL_MARGIN
  7229. });
  7230. }
  7231. }
  7232. this._currentPageNumber = pageNumber;
  7233. }
  7234. get pagesRotation() {
  7235. return this._pagesRotation;
  7236. }
  7237. set pagesRotation(rotation) {
  7238. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7239. throw new Error("Invalid thumbnails rotation angle.");
  7240. }
  7241. if (!this.pdfDocument) {
  7242. return;
  7243. }
  7244. if (this._pagesRotation === rotation) {
  7245. return;
  7246. }
  7247. this._pagesRotation = rotation;
  7248. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7249. this._thumbnails[i].update(rotation);
  7250. }
  7251. }
  7252. cleanup() {
  7253. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7254. if (this._thumbnails[i] && this._thumbnails[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7255. this._thumbnails[i].reset();
  7256. }
  7257. }
  7258. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7259. }
  7260. _resetView() {
  7261. this._thumbnails = [];
  7262. this._currentPageNumber = 1;
  7263. this._pageLabels = null;
  7264. this._pagesRotation = 0;
  7265. this._optionalContentConfigPromise = null;
  7266. this._pagesRequests = new WeakMap();
  7267. this._setImageDisabled = false;
  7268. this.container.textContent = "";
  7269. }
  7270. setDocument(pdfDocument) {
  7271. if (this.pdfDocument) {
  7272. this._cancelRendering();
  7273. this._resetView();
  7274. }
  7275. this.pdfDocument = pdfDocument;
  7276. if (!pdfDocument) {
  7277. return;
  7278. }
  7279. const firstPagePromise = pdfDocument.getPage(1);
  7280. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7281. firstPagePromise.then(firstPdfPage => {
  7282. this._optionalContentConfigPromise = optionalContentConfigPromise;
  7283. const pagesCount = pdfDocument.numPages;
  7284. const viewport = firstPdfPage.getViewport({
  7285. scale: 1
  7286. });
  7287. const checkSetImageDisabled = () => {
  7288. return this._setImageDisabled;
  7289. };
  7290. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7291. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7292. container: this.container,
  7293. id: pageNum,
  7294. defaultViewport: viewport.clone(),
  7295. optionalContentConfigPromise,
  7296. linkService: this.linkService,
  7297. renderingQueue: this.renderingQueue,
  7298. checkSetImageDisabled,
  7299. l10n: this.l10n
  7300. });
  7301. this._thumbnails.push(thumbnail);
  7302. }
  7303. const firstThumbnailView = this._thumbnails[0];
  7304. if (firstThumbnailView) {
  7305. firstThumbnailView.setPdfPage(firstPdfPage);
  7306. }
  7307. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7308. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7309. }).catch(reason => {
  7310. console.error("Unable to initialize thumbnail viewer", reason);
  7311. });
  7312. }
  7313. _cancelRendering() {
  7314. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7315. if (this._thumbnails[i]) {
  7316. this._thumbnails[i].cancelRendering();
  7317. }
  7318. }
  7319. }
  7320. setPageLabels(labels) {
  7321. if (!this.pdfDocument) {
  7322. return;
  7323. }
  7324. if (!labels) {
  7325. this._pageLabels = null;
  7326. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7327. this._pageLabels = null;
  7328. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7329. } else {
  7330. this._pageLabels = labels;
  7331. }
  7332. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7333. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7334. }
  7335. }
  7336. _ensurePdfPageLoaded(thumbView) {
  7337. if (thumbView.pdfPage) {
  7338. return Promise.resolve(thumbView.pdfPage);
  7339. }
  7340. if (this._pagesRequests.has(thumbView)) {
  7341. return this._pagesRequests.get(thumbView);
  7342. }
  7343. const promise = this.pdfDocument.getPage(thumbView.id).then(pdfPage => {
  7344. if (!thumbView.pdfPage) {
  7345. thumbView.setPdfPage(pdfPage);
  7346. }
  7347. this._pagesRequests.delete(thumbView);
  7348. return pdfPage;
  7349. }).catch(reason => {
  7350. console.error("Unable to get page for thumb view", reason);
  7351. this._pagesRequests.delete(thumbView);
  7352. });
  7353. this._pagesRequests.set(thumbView, promise);
  7354. return promise;
  7355. }
  7356. forceRendering() {
  7357. const visibleThumbs = this._getVisibleThumbs();
  7358. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
  7359. if (thumbView) {
  7360. this._ensurePdfPageLoaded(thumbView).then(() => {
  7361. this.renderingQueue.renderView(thumbView);
  7362. });
  7363. return true;
  7364. }
  7365. return false;
  7366. }
  7367. }
  7368. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7369. /***/ }),
  7370. /* 26 */
  7371. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7372. Object.defineProperty(exports, "__esModule", ({
  7373. value: true
  7374. }));
  7375. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7376. var _ui_utils = __webpack_require__(4);
  7377. var _pdfjsLib = __webpack_require__(5);
  7378. var _pdf_rendering_queue = __webpack_require__(8);
  7379. const DRAW_UPSCALE_FACTOR = 2;
  7380. const MAX_NUM_SCALING_STEPS = 3;
  7381. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7382. const THUMBNAIL_WIDTH = 98;
  7383. const TempImageFactory = function TempImageFactoryClosure() {
  7384. let tempCanvasCache = null;
  7385. return {
  7386. getCanvas(width, height) {
  7387. let tempCanvas = tempCanvasCache;
  7388. if (!tempCanvas) {
  7389. tempCanvas = document.createElement("canvas");
  7390. tempCanvasCache = tempCanvas;
  7391. }
  7392. tempCanvas.width = width;
  7393. tempCanvas.height = height;
  7394. tempCanvas.mozOpaque = true;
  7395. const ctx = tempCanvas.getContext("2d", {
  7396. alpha: false
  7397. });
  7398. ctx.save();
  7399. ctx.fillStyle = "rgb(255, 255, 255)";
  7400. ctx.fillRect(0, 0, width, height);
  7401. ctx.restore();
  7402. return [tempCanvas, tempCanvas.getContext("2d")];
  7403. },
  7404. destroyCanvas() {
  7405. const tempCanvas = tempCanvasCache;
  7406. if (tempCanvas) {
  7407. tempCanvas.width = 0;
  7408. tempCanvas.height = 0;
  7409. }
  7410. tempCanvasCache = null;
  7411. }
  7412. };
  7413. }();
  7414. exports.TempImageFactory = TempImageFactory;
  7415. class PDFThumbnailView {
  7416. constructor({
  7417. container,
  7418. id,
  7419. defaultViewport,
  7420. optionalContentConfigPromise,
  7421. linkService,
  7422. renderingQueue,
  7423. checkSetImageDisabled,
  7424. l10n
  7425. }) {
  7426. this.id = id;
  7427. this.renderingId = "thumbnail" + id;
  7428. this.pageLabel = null;
  7429. this.pdfPage = null;
  7430. this.rotation = 0;
  7431. this.viewport = defaultViewport;
  7432. this.pdfPageRotate = defaultViewport.rotation;
  7433. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7434. this.linkService = linkService;
  7435. this.renderingQueue = renderingQueue;
  7436. this.renderTask = null;
  7437. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7438. this.resume = null;
  7439. this._checkSetImageDisabled = checkSetImageDisabled || function () {
  7440. return false;
  7441. };
  7442. const pageWidth = this.viewport.width,
  7443. pageHeight = this.viewport.height,
  7444. pageRatio = pageWidth / pageHeight;
  7445. this.canvasWidth = THUMBNAIL_WIDTH;
  7446. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7447. this.scale = this.canvasWidth / pageWidth;
  7448. this.l10n = l10n;
  7449. const anchor = document.createElement("a");
  7450. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7451. this._thumbPageTitle.then(msg => {
  7452. anchor.title = msg;
  7453. });
  7454. anchor.onclick = function () {
  7455. linkService.goToPage(id);
  7456. return false;
  7457. };
  7458. this.anchor = anchor;
  7459. const div = document.createElement("div");
  7460. div.className = "thumbnail";
  7461. div.setAttribute("data-page-number", this.id);
  7462. this.div = div;
  7463. const ring = document.createElement("div");
  7464. ring.className = "thumbnailSelectionRing";
  7465. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7466. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7467. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7468. this.ring = ring;
  7469. div.appendChild(ring);
  7470. anchor.appendChild(div);
  7471. container.appendChild(anchor);
  7472. }
  7473. setPdfPage(pdfPage) {
  7474. this.pdfPage = pdfPage;
  7475. this.pdfPageRotate = pdfPage.rotate;
  7476. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7477. this.viewport = pdfPage.getViewport({
  7478. scale: 1,
  7479. rotation: totalRotation
  7480. });
  7481. this.reset();
  7482. }
  7483. reset() {
  7484. this.cancelRendering();
  7485. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7486. const pageWidth = this.viewport.width,
  7487. pageHeight = this.viewport.height,
  7488. pageRatio = pageWidth / pageHeight;
  7489. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7490. this.scale = this.canvasWidth / pageWidth;
  7491. this.div.removeAttribute("data-loaded");
  7492. const ring = this.ring;
  7493. ring.textContent = "";
  7494. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7495. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7496. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7497. if (this.canvas) {
  7498. this.canvas.width = 0;
  7499. this.canvas.height = 0;
  7500. delete this.canvas;
  7501. }
  7502. if (this.image) {
  7503. this.image.removeAttribute("src");
  7504. delete this.image;
  7505. }
  7506. }
  7507. update(rotation) {
  7508. if (typeof rotation !== "undefined") {
  7509. this.rotation = rotation;
  7510. }
  7511. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7512. this.viewport = this.viewport.clone({
  7513. scale: 1,
  7514. rotation: totalRotation
  7515. });
  7516. this.reset();
  7517. }
  7518. cancelRendering() {
  7519. if (this.renderTask) {
  7520. this.renderTask.cancel();
  7521. this.renderTask = null;
  7522. }
  7523. this.resume = null;
  7524. }
  7525. _getPageDrawContext(upscaleFactor = 1) {
  7526. const canvas = document.createElement("canvas");
  7527. canvas.mozOpaque = true;
  7528. const ctx = canvas.getContext("2d", {
  7529. alpha: false
  7530. });
  7531. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  7532. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7533. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7534. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7535. return {
  7536. ctx,
  7537. canvas,
  7538. transform
  7539. };
  7540. }
  7541. _convertCanvasToImage(canvas) {
  7542. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7543. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  7544. }
  7545. const reducedCanvas = this._reduceImage(canvas);
  7546. const image = document.createElement("img");
  7547. image.className = "thumbnailImage";
  7548. this._thumbPageCanvas.then(msg => {
  7549. image.setAttribute("aria-label", msg);
  7550. });
  7551. image.style.width = this.canvasWidth + "px";
  7552. image.style.height = this.canvasHeight + "px";
  7553. image.src = reducedCanvas.toDataURL();
  7554. this.image = image;
  7555. this.div.setAttribute("data-loaded", true);
  7556. this.ring.appendChild(image);
  7557. reducedCanvas.width = 0;
  7558. reducedCanvas.height = 0;
  7559. }
  7560. draw() {
  7561. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7562. console.error("Must be in new state before drawing");
  7563. return Promise.resolve(undefined);
  7564. }
  7565. const {
  7566. pdfPage
  7567. } = this;
  7568. if (!pdfPage) {
  7569. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7570. return Promise.reject(new Error("pdfPage is not loaded"));
  7571. }
  7572. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7573. const finishRenderTask = async (error = null) => {
  7574. if (renderTask === this.renderTask) {
  7575. this.renderTask = null;
  7576. }
  7577. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7578. return;
  7579. }
  7580. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7581. this._convertCanvasToImage(canvas);
  7582. if (error) {
  7583. throw error;
  7584. }
  7585. };
  7586. const {
  7587. ctx,
  7588. canvas,
  7589. transform
  7590. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7591. const drawViewport = this.viewport.clone({
  7592. scale: DRAW_UPSCALE_FACTOR * this.scale
  7593. });
  7594. const renderContinueCallback = cont => {
  7595. if (!this.renderingQueue.isHighestPriority(this)) {
  7596. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  7597. this.resume = () => {
  7598. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7599. cont();
  7600. };
  7601. return;
  7602. }
  7603. cont();
  7604. };
  7605. const renderContext = {
  7606. canvasContext: ctx,
  7607. transform,
  7608. viewport: drawViewport,
  7609. optionalContentConfigPromise: this._optionalContentConfigPromise
  7610. };
  7611. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7612. renderTask.onContinue = renderContinueCallback;
  7613. const resultPromise = renderTask.promise.then(function () {
  7614. return finishRenderTask(null);
  7615. }, function (error) {
  7616. return finishRenderTask(error);
  7617. });
  7618. resultPromise.finally(() => {
  7619. canvas.width = 0;
  7620. canvas.height = 0;
  7621. const pageCached = this.linkService.isPageCached(this.id);
  7622. if (!pageCached) {
  7623. this.pdfPage?.cleanup();
  7624. }
  7625. });
  7626. return resultPromise;
  7627. }
  7628. setImage(pageView) {
  7629. if (this._checkSetImageDisabled()) {
  7630. return;
  7631. }
  7632. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7633. return;
  7634. }
  7635. const {
  7636. canvas,
  7637. pdfPage
  7638. } = pageView;
  7639. if (!canvas) {
  7640. return;
  7641. }
  7642. if (!this.pdfPage) {
  7643. this.setPdfPage(pdfPage);
  7644. }
  7645. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7646. this._convertCanvasToImage(canvas);
  7647. }
  7648. _reduceImage(img) {
  7649. const {
  7650. ctx,
  7651. canvas
  7652. } = this._getPageDrawContext();
  7653. if (img.width <= 2 * canvas.width) {
  7654. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7655. return canvas;
  7656. }
  7657. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7658. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7659. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7660. while (reducedWidth > img.width || reducedHeight > img.height) {
  7661. reducedWidth >>= 1;
  7662. reducedHeight >>= 1;
  7663. }
  7664. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7665. while (reducedWidth > 2 * canvas.width) {
  7666. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7667. reducedWidth >>= 1;
  7668. reducedHeight >>= 1;
  7669. }
  7670. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7671. return canvas;
  7672. }
  7673. get _thumbPageTitle() {
  7674. return this.l10n.get("thumb_page_title", {
  7675. page: this.pageLabel ?? this.id
  7676. });
  7677. }
  7678. get _thumbPageCanvas() {
  7679. return this.l10n.get("thumb_page_canvas", {
  7680. page: this.pageLabel ?? this.id
  7681. });
  7682. }
  7683. setPageLabel(label) {
  7684. this.pageLabel = typeof label === "string" ? label : null;
  7685. this._thumbPageTitle.then(msg => {
  7686. this.anchor.title = msg;
  7687. });
  7688. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7689. return;
  7690. }
  7691. this._thumbPageCanvas.then(msg => {
  7692. this.image?.setAttribute("aria-label", msg);
  7693. });
  7694. }
  7695. }
  7696. exports.PDFThumbnailView = PDFThumbnailView;
  7697. /***/ }),
  7698. /* 27 */
  7699. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7700. Object.defineProperty(exports, "__esModule", ({
  7701. value: true
  7702. }));
  7703. exports.PDFViewer = void 0;
  7704. var _ui_utils = __webpack_require__(4);
  7705. var _base_viewer = __webpack_require__(28);
  7706. var _pdfjsLib = __webpack_require__(5);
  7707. class PDFViewer extends _base_viewer.BaseViewer {
  7708. get _viewerElement() {
  7709. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this.viewer);
  7710. }
  7711. _scrollIntoView({
  7712. pageDiv,
  7713. pageSpot = null,
  7714. pageNumber = null
  7715. }) {
  7716. if (!pageSpot && !this.isInPresentationMode) {
  7717. const left = pageDiv.offsetLeft + pageDiv.clientLeft;
  7718. const right = left + pageDiv.clientWidth;
  7719. const {
  7720. scrollLeft,
  7721. clientWidth
  7722. } = this.container;
  7723. if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
  7724. pageSpot = {
  7725. left: 0,
  7726. top: 0
  7727. };
  7728. }
  7729. }
  7730. super._scrollIntoView({
  7731. pageDiv,
  7732. pageSpot,
  7733. pageNumber
  7734. });
  7735. }
  7736. _getVisiblePages() {
  7737. if (this.isInPresentationMode) {
  7738. return this._getCurrentVisiblePage();
  7739. }
  7740. return super._getVisiblePages();
  7741. }
  7742. _updateHelper(visiblePages) {
  7743. if (this.isInPresentationMode) {
  7744. return;
  7745. }
  7746. let currentId = this._currentPageNumber;
  7747. let stillFullyVisible = false;
  7748. for (const page of visiblePages) {
  7749. if (page.percent < 100) {
  7750. break;
  7751. }
  7752. if (page.id === currentId && this._scrollMode === _ui_utils.ScrollMode.VERTICAL && this._spreadMode === _ui_utils.SpreadMode.NONE) {
  7753. stillFullyVisible = true;
  7754. break;
  7755. }
  7756. }
  7757. if (!stillFullyVisible) {
  7758. currentId = visiblePages[0].id;
  7759. }
  7760. this._setCurrentPageNumber(currentId);
  7761. }
  7762. }
  7763. exports.PDFViewer = PDFViewer;
  7764. /***/ }),
  7765. /* 28 */
  7766. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7767. Object.defineProperty(exports, "__esModule", ({
  7768. value: true
  7769. }));
  7770. exports.BaseViewer = void 0;
  7771. var _pdfjsLib = __webpack_require__(5);
  7772. var _ui_utils = __webpack_require__(4);
  7773. var _pdf_rendering_queue = __webpack_require__(8);
  7774. var _annotation_layer_builder = __webpack_require__(29);
  7775. var _l10n_utils = __webpack_require__(30);
  7776. var _pdf_page_view = __webpack_require__(31);
  7777. var _pdf_link_service = __webpack_require__(19);
  7778. var _struct_tree_layer_builder = __webpack_require__(32);
  7779. var _text_layer_builder = __webpack_require__(33);
  7780. var _xfa_layer_builder = __webpack_require__(34);
  7781. const DEFAULT_CACHE_SIZE = 10;
  7782. function PDFPageViewBuffer(size) {
  7783. const data = [];
  7784. this.push = function (view) {
  7785. const i = data.indexOf(view);
  7786. if (i >= 0) {
  7787. data.splice(i, 1);
  7788. }
  7789. data.push(view);
  7790. if (data.length > size) {
  7791. data.shift().destroy();
  7792. }
  7793. };
  7794. this.resize = function (newSize, pagesToKeep) {
  7795. size = newSize;
  7796. if (pagesToKeep) {
  7797. const pageIdsToKeep = new Set();
  7798. for (let i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
  7799. pageIdsToKeep.add(pagesToKeep[i].id);
  7800. }
  7801. (0, _ui_utils.moveToEndOfArray)(data, function (page) {
  7802. return pageIdsToKeep.has(page.id);
  7803. });
  7804. }
  7805. while (data.length > size) {
  7806. data.shift().destroy();
  7807. }
  7808. };
  7809. this.has = function (view) {
  7810. return data.includes(view);
  7811. };
  7812. }
  7813. function isSameScale(oldScale, newScale) {
  7814. if (newScale === oldScale) {
  7815. return true;
  7816. }
  7817. if (Math.abs(newScale - oldScale) < 1e-15) {
  7818. return true;
  7819. }
  7820. return false;
  7821. }
  7822. class BaseViewer {
  7823. constructor(options) {
  7824. if (this.constructor === BaseViewer) {
  7825. throw new Error("Cannot initialize BaseViewer.");
  7826. }
  7827. const viewerVersion = '2.9.359';
  7828. if (_pdfjsLib.version !== viewerVersion) {
  7829. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  7830. }
  7831. this._name = this.constructor.name;
  7832. this.container = options.container;
  7833. this.viewer = options.viewer || options.container.firstElementChild;
  7834. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  7835. throw new Error("Invalid `container` and/or `viewer` option.");
  7836. }
  7837. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  7838. throw new Error("The `container` must be absolutely positioned.");
  7839. }
  7840. this.eventBus = options.eventBus;
  7841. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  7842. this.downloadManager = options.downloadManager || null;
  7843. this.findController = options.findController || null;
  7844. this._scriptingManager = options.scriptingManager || null;
  7845. this.removePageBorders = options.removePageBorders || false;
  7846. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  7847. this.imageResourcesPath = options.imageResourcesPath || "";
  7848. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  7849. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  7850. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7851. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  7852. this.maxCanvasPixels = options.maxCanvasPixels;
  7853. this.l10n = options.l10n || _l10n_utils.NullL10n;
  7854. this.enableScripting = options.enableScripting === true && !!this._scriptingManager;
  7855. this.defaultRenderingQueue = !options.renderingQueue;
  7856. if (this.defaultRenderingQueue) {
  7857. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  7858. this.renderingQueue.setViewer(this);
  7859. } else {
  7860. this.renderingQueue = options.renderingQueue;
  7861. }
  7862. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  7863. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  7864. this._onBeforeDraw = this._onAfterDraw = null;
  7865. this._resetView();
  7866. if (this.removePageBorders) {
  7867. this.viewer.classList.add("removePageBorders");
  7868. }
  7869. Promise.resolve().then(() => {
  7870. this.eventBus.dispatch("baseviewerinit", {
  7871. source: this
  7872. });
  7873. });
  7874. }
  7875. get pagesCount() {
  7876. return this._pages.length;
  7877. }
  7878. getPageView(index) {
  7879. return this._pages[index];
  7880. }
  7881. get pageViewsReady() {
  7882. if (!this._pagesCapability.settled) {
  7883. return false;
  7884. }
  7885. return this._pages.every(function (pageView) {
  7886. return pageView?.pdfPage;
  7887. });
  7888. }
  7889. get currentPageNumber() {
  7890. return this._currentPageNumber;
  7891. }
  7892. set currentPageNumber(val) {
  7893. if (!Number.isInteger(val)) {
  7894. throw new Error("Invalid page number.");
  7895. }
  7896. if (!this.pdfDocument) {
  7897. return;
  7898. }
  7899. if (!this._setCurrentPageNumber(val, true)) {
  7900. console.error(`${this._name}.currentPageNumber: "${val}" is not a valid page.`);
  7901. }
  7902. }
  7903. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  7904. if (this._currentPageNumber === val) {
  7905. if (resetCurrentPageView) {
  7906. this._resetCurrentPageView();
  7907. }
  7908. return true;
  7909. }
  7910. if (!(0 < val && val <= this.pagesCount)) {
  7911. return false;
  7912. }
  7913. const previous = this._currentPageNumber;
  7914. this._currentPageNumber = val;
  7915. this.eventBus.dispatch("pagechanging", {
  7916. source: this,
  7917. pageNumber: val,
  7918. pageLabel: this._pageLabels?.[val - 1] ?? null,
  7919. previous
  7920. });
  7921. if (resetCurrentPageView) {
  7922. this._resetCurrentPageView();
  7923. }
  7924. return true;
  7925. }
  7926. get currentPageLabel() {
  7927. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  7928. }
  7929. set currentPageLabel(val) {
  7930. if (!this.pdfDocument) {
  7931. return;
  7932. }
  7933. let page = val | 0;
  7934. if (this._pageLabels) {
  7935. const i = this._pageLabels.indexOf(val);
  7936. if (i >= 0) {
  7937. page = i + 1;
  7938. }
  7939. }
  7940. if (!this._setCurrentPageNumber(page, true)) {
  7941. console.error(`${this._name}.currentPageLabel: "${val}" is not a valid page.`);
  7942. }
  7943. }
  7944. get currentScale() {
  7945. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  7946. }
  7947. set currentScale(val) {
  7948. if (isNaN(val)) {
  7949. throw new Error("Invalid numeric scale.");
  7950. }
  7951. if (!this.pdfDocument) {
  7952. return;
  7953. }
  7954. this._setScale(val, false);
  7955. }
  7956. get currentScaleValue() {
  7957. return this._currentScaleValue;
  7958. }
  7959. set currentScaleValue(val) {
  7960. if (!this.pdfDocument) {
  7961. return;
  7962. }
  7963. this._setScale(val, false);
  7964. }
  7965. get pagesRotation() {
  7966. return this._pagesRotation;
  7967. }
  7968. set pagesRotation(rotation) {
  7969. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7970. throw new Error("Invalid pages rotation angle.");
  7971. }
  7972. if (!this.pdfDocument) {
  7973. return;
  7974. }
  7975. rotation %= 360;
  7976. if (rotation < 0) {
  7977. rotation += 360;
  7978. }
  7979. if (this._pagesRotation === rotation) {
  7980. return;
  7981. }
  7982. this._pagesRotation = rotation;
  7983. const pageNumber = this._currentPageNumber;
  7984. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  7985. const pageView = this._pages[i];
  7986. pageView.update(pageView.scale, rotation);
  7987. }
  7988. if (this._currentScaleValue) {
  7989. this._setScale(this._currentScaleValue, true);
  7990. }
  7991. this.eventBus.dispatch("rotationchanging", {
  7992. source: this,
  7993. pagesRotation: rotation,
  7994. pageNumber
  7995. });
  7996. if (this.defaultRenderingQueue) {
  7997. this.update();
  7998. }
  7999. }
  8000. get firstPagePromise() {
  8001. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8002. }
  8003. get onePageRendered() {
  8004. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8005. }
  8006. get pagesPromise() {
  8007. return this.pdfDocument ? this._pagesCapability.promise : null;
  8008. }
  8009. get _viewerElement() {
  8010. throw new Error("Not implemented: _viewerElement");
  8011. }
  8012. _onePageRenderedOrForceFetch() {
  8013. if (!this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8014. return Promise.resolve();
  8015. }
  8016. return this._onePageRenderedCapability.promise;
  8017. }
  8018. setDocument(pdfDocument) {
  8019. if (this.pdfDocument) {
  8020. this.eventBus.dispatch("pagesdestroy", {
  8021. source: this
  8022. });
  8023. this._cancelRendering();
  8024. this._resetView();
  8025. if (this.findController) {
  8026. this.findController.setDocument(null);
  8027. }
  8028. if (this._scriptingManager) {
  8029. this._scriptingManager.setDocument(null);
  8030. }
  8031. }
  8032. this.pdfDocument = pdfDocument;
  8033. if (!pdfDocument) {
  8034. return;
  8035. }
  8036. const isPureXfa = pdfDocument.isPureXfa;
  8037. const pagesCount = pdfDocument.numPages;
  8038. const firstPagePromise = pdfDocument.getPage(1);
  8039. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8040. this._pagesCapability.promise.then(() => {
  8041. this.eventBus.dispatch("pagesloaded", {
  8042. source: this,
  8043. pagesCount
  8044. });
  8045. });
  8046. this._onBeforeDraw = evt => {
  8047. const pageView = this._pages[evt.pageNumber - 1];
  8048. if (!pageView) {
  8049. return;
  8050. }
  8051. this._buffer.push(pageView);
  8052. };
  8053. this.eventBus._on("pagerender", this._onBeforeDraw);
  8054. this._onAfterDraw = evt => {
  8055. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8056. return;
  8057. }
  8058. this._onePageRenderedCapability.resolve();
  8059. this.eventBus._off("pagerendered", this._onAfterDraw);
  8060. this._onAfterDraw = null;
  8061. };
  8062. this.eventBus._on("pagerendered", this._onAfterDraw);
  8063. firstPagePromise.then(firstPdfPage => {
  8064. this._firstPageCapability.resolve(firstPdfPage);
  8065. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8066. const scale = this.currentScale;
  8067. const viewport = firstPdfPage.getViewport({
  8068. scale: scale * _ui_utils.CSS_UNITS
  8069. });
  8070. const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE ? this : null;
  8071. const xfaLayerFactory = isPureXfa ? this : null;
  8072. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8073. const pageView = new _pdf_page_view.PDFPageView({
  8074. container: this._viewerElement,
  8075. eventBus: this.eventBus,
  8076. id: pageNum,
  8077. scale,
  8078. defaultViewport: viewport.clone(),
  8079. optionalContentConfigPromise,
  8080. renderingQueue: this.renderingQueue,
  8081. textLayerFactory,
  8082. textLayerMode: this.textLayerMode,
  8083. annotationLayerFactory: this,
  8084. xfaLayerFactory,
  8085. structTreeLayerFactory: this,
  8086. imageResourcesPath: this.imageResourcesPath,
  8087. renderInteractiveForms: this.renderInteractiveForms,
  8088. renderer: this.renderer,
  8089. useOnlyCssZoom: this.useOnlyCssZoom,
  8090. maxCanvasPixels: this.maxCanvasPixels,
  8091. l10n: this.l10n
  8092. });
  8093. this._pages.push(pageView);
  8094. }
  8095. const firstPageView = this._pages[0];
  8096. if (firstPageView) {
  8097. firstPageView.setPdfPage(firstPdfPage);
  8098. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8099. }
  8100. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8101. this._updateSpreadMode();
  8102. }
  8103. this._onePageRenderedOrForceFetch().then(() => {
  8104. if (this.findController) {
  8105. this.findController.setDocument(pdfDocument);
  8106. }
  8107. if (this.enableScripting) {
  8108. this._scriptingManager.setDocument(pdfDocument);
  8109. }
  8110. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > 7500) {
  8111. this._pagesCapability.resolve();
  8112. return;
  8113. }
  8114. let getPagesLeft = pagesCount - 1;
  8115. if (getPagesLeft <= 0) {
  8116. this._pagesCapability.resolve();
  8117. return;
  8118. }
  8119. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8120. pdfDocument.getPage(pageNum).then(pdfPage => {
  8121. const pageView = this._pages[pageNum - 1];
  8122. if (!pageView.pdfPage) {
  8123. pageView.setPdfPage(pdfPage);
  8124. }
  8125. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8126. if (--getPagesLeft === 0) {
  8127. this._pagesCapability.resolve();
  8128. }
  8129. }, reason => {
  8130. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8131. if (--getPagesLeft === 0) {
  8132. this._pagesCapability.resolve();
  8133. }
  8134. });
  8135. }
  8136. });
  8137. this.eventBus.dispatch("pagesinit", {
  8138. source: this
  8139. });
  8140. if (this.defaultRenderingQueue) {
  8141. this.update();
  8142. }
  8143. }).catch(reason => {
  8144. console.error("Unable to initialize viewer", reason);
  8145. });
  8146. }
  8147. setPageLabels(labels) {
  8148. if (!this.pdfDocument) {
  8149. return;
  8150. }
  8151. if (!labels) {
  8152. this._pageLabels = null;
  8153. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8154. this._pageLabels = null;
  8155. console.error(`${this._name}.setPageLabels: Invalid page labels.`);
  8156. } else {
  8157. this._pageLabels = labels;
  8158. }
  8159. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8160. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8161. }
  8162. }
  8163. _resetView() {
  8164. this._pages = [];
  8165. this._currentPageNumber = 1;
  8166. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8167. this._currentScaleValue = null;
  8168. this._pageLabels = null;
  8169. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8170. this._location = null;
  8171. this._pagesRotation = 0;
  8172. this._optionalContentConfigPromise = null;
  8173. this._pagesRequests = new WeakMap();
  8174. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8175. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8176. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8177. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8178. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8179. if (this._onBeforeDraw) {
  8180. this.eventBus._off("pagerender", this._onBeforeDraw);
  8181. this._onBeforeDraw = null;
  8182. }
  8183. if (this._onAfterDraw) {
  8184. this.eventBus._off("pagerendered", this._onAfterDraw);
  8185. this._onAfterDraw = null;
  8186. }
  8187. this.viewer.textContent = "";
  8188. this._updateScrollMode();
  8189. }
  8190. _scrollUpdate() {
  8191. if (this.pagesCount === 0) {
  8192. return;
  8193. }
  8194. this.update();
  8195. }
  8196. _scrollIntoView({
  8197. pageDiv,
  8198. pageSpot = null,
  8199. pageNumber = null
  8200. }) {
  8201. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  8202. }
  8203. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8204. this._currentScaleValue = newValue.toString();
  8205. if (isSameScale(this._currentScale, newScale)) {
  8206. if (preset) {
  8207. this.eventBus.dispatch("scalechanging", {
  8208. source: this,
  8209. scale: newScale,
  8210. presetValue: newValue
  8211. });
  8212. }
  8213. return;
  8214. }
  8215. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8216. this._pages[i].update(newScale);
  8217. }
  8218. this._currentScale = newScale;
  8219. if (!noScroll) {
  8220. let page = this._currentPageNumber,
  8221. dest;
  8222. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8223. page = this._location.pageNumber;
  8224. dest = [null, {
  8225. name: "XYZ"
  8226. }, this._location.left, this._location.top, null];
  8227. }
  8228. this.scrollPageIntoView({
  8229. pageNumber: page,
  8230. destArray: dest,
  8231. allowNegativeOffset: true
  8232. });
  8233. }
  8234. this.eventBus.dispatch("scalechanging", {
  8235. source: this,
  8236. scale: newScale,
  8237. presetValue: preset ? newValue : undefined
  8238. });
  8239. if (this.defaultRenderingQueue) {
  8240. this.update();
  8241. }
  8242. }
  8243. get _pageWidthScaleFactor() {
  8244. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL && !this.isInPresentationMode) {
  8245. return 2;
  8246. }
  8247. return 1;
  8248. }
  8249. _setScale(value, noScroll = false) {
  8250. let scale = parseFloat(value);
  8251. if (scale > 0) {
  8252. this._setScaleUpdatePages(scale, value, noScroll, false);
  8253. } else {
  8254. const currentPage = this._pages[this._currentPageNumber - 1];
  8255. if (!currentPage) {
  8256. return;
  8257. }
  8258. const noPadding = this.isInPresentationMode || this.removePageBorders;
  8259. let hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8260. let vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
  8261. if (!noPadding && this._isScrollModeHorizontal) {
  8262. [hPadding, vPadding] = [vPadding, hPadding];
  8263. }
  8264. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8265. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8266. switch (value) {
  8267. case "page-actual":
  8268. scale = 1;
  8269. break;
  8270. case "page-width":
  8271. scale = pageWidthScale;
  8272. break;
  8273. case "page-height":
  8274. scale = pageHeightScale;
  8275. break;
  8276. case "page-fit":
  8277. scale = Math.min(pageWidthScale, pageHeightScale);
  8278. break;
  8279. case "auto":
  8280. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8281. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8282. break;
  8283. default:
  8284. console.error(`${this._name}._setScale: "${value}" is an unknown zoom value.`);
  8285. return;
  8286. }
  8287. this._setScaleUpdatePages(scale, value, noScroll, true);
  8288. }
  8289. }
  8290. _resetCurrentPageView() {
  8291. if (this.isInPresentationMode) {
  8292. this._setScale(this._currentScaleValue, true);
  8293. }
  8294. const pageView = this._pages[this._currentPageNumber - 1];
  8295. this._scrollIntoView({
  8296. pageDiv: pageView.div
  8297. });
  8298. }
  8299. pageLabelToPageNumber(label) {
  8300. if (!this._pageLabels) {
  8301. return null;
  8302. }
  8303. const i = this._pageLabels.indexOf(label);
  8304. if (i < 0) {
  8305. return null;
  8306. }
  8307. return i + 1;
  8308. }
  8309. scrollPageIntoView({
  8310. pageNumber,
  8311. destArray = null,
  8312. allowNegativeOffset = false,
  8313. ignoreDestinationZoom = false
  8314. }) {
  8315. if (!this.pdfDocument) {
  8316. return;
  8317. }
  8318. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8319. if (!pageView) {
  8320. console.error(`${this._name}.scrollPageIntoView: ` + `"${pageNumber}" is not a valid pageNumber parameter.`);
  8321. return;
  8322. }
  8323. if (this.isInPresentationMode || !destArray) {
  8324. this._setCurrentPageNumber(pageNumber, true);
  8325. return;
  8326. }
  8327. let x = 0,
  8328. y = 0;
  8329. let width = 0,
  8330. height = 0,
  8331. widthScale,
  8332. heightScale;
  8333. const changeOrientation = pageView.rotation % 180 !== 0;
  8334. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  8335. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  8336. let scale = 0;
  8337. switch (destArray[1].name) {
  8338. case "XYZ":
  8339. x = destArray[2];
  8340. y = destArray[3];
  8341. scale = destArray[4];
  8342. x = x !== null ? x : 0;
  8343. y = y !== null ? y : pageHeight;
  8344. break;
  8345. case "Fit":
  8346. case "FitB":
  8347. scale = "page-fit";
  8348. break;
  8349. case "FitH":
  8350. case "FitBH":
  8351. y = destArray[2];
  8352. scale = "page-width";
  8353. if (y === null && this._location) {
  8354. x = this._location.left;
  8355. y = this._location.top;
  8356. } else if (typeof y !== "number") {
  8357. y = pageHeight;
  8358. }
  8359. break;
  8360. case "FitV":
  8361. case "FitBV":
  8362. x = destArray[2];
  8363. width = pageWidth;
  8364. height = pageHeight;
  8365. scale = "page-height";
  8366. break;
  8367. case "FitR":
  8368. x = destArray[2];
  8369. y = destArray[3];
  8370. width = destArray[4] - x;
  8371. height = destArray[5] - y;
  8372. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8373. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8374. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  8375. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  8376. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8377. break;
  8378. default:
  8379. console.error(`${this._name}.scrollPageIntoView: ` + `"${destArray[1].name}" is not a valid destination type.`);
  8380. return;
  8381. }
  8382. if (!ignoreDestinationZoom) {
  8383. if (scale && scale !== this._currentScale) {
  8384. this.currentScaleValue = scale;
  8385. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8386. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8387. }
  8388. }
  8389. if (scale === "page-fit" && !destArray[4]) {
  8390. this._scrollIntoView({
  8391. pageDiv: pageView.div,
  8392. pageNumber
  8393. });
  8394. return;
  8395. }
  8396. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8397. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8398. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8399. if (!allowNegativeOffset) {
  8400. left = Math.max(left, 0);
  8401. top = Math.max(top, 0);
  8402. }
  8403. this._scrollIntoView({
  8404. pageDiv: pageView.div,
  8405. pageSpot: {
  8406. left,
  8407. top
  8408. },
  8409. pageNumber
  8410. });
  8411. }
  8412. _updateLocation(firstPage) {
  8413. const currentScale = this._currentScale;
  8414. const currentScaleValue = this._currentScaleValue;
  8415. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8416. const pageNumber = firstPage.id;
  8417. let pdfOpenParams = "#page=" + pageNumber;
  8418. pdfOpenParams += "&zoom=" + normalizedScaleValue;
  8419. const currentPageView = this._pages[pageNumber - 1];
  8420. const container = this.container;
  8421. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8422. const intLeft = Math.round(topLeft[0]);
  8423. const intTop = Math.round(topLeft[1]);
  8424. pdfOpenParams += "," + intLeft + "," + intTop;
  8425. this._location = {
  8426. pageNumber,
  8427. scale: normalizedScaleValue,
  8428. top: intTop,
  8429. left: intLeft,
  8430. rotation: this._pagesRotation,
  8431. pdfOpenParams
  8432. };
  8433. }
  8434. _updateHelper(visiblePages) {
  8435. throw new Error("Not implemented: _updateHelper");
  8436. }
  8437. update() {
  8438. const visible = this._getVisiblePages();
  8439. const visiblePages = visible.views,
  8440. numVisiblePages = visiblePages.length;
  8441. if (numVisiblePages === 0) {
  8442. return;
  8443. }
  8444. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8445. this._buffer.resize(newCacheSize, visiblePages);
  8446. this.renderingQueue.renderHighestPriority(visible);
  8447. this._updateHelper(visiblePages);
  8448. this._updateLocation(visible.first);
  8449. this.eventBus.dispatch("updateviewarea", {
  8450. source: this,
  8451. location: this._location
  8452. });
  8453. }
  8454. containsElement(element) {
  8455. return this.container.contains(element);
  8456. }
  8457. focus() {
  8458. this.container.focus();
  8459. }
  8460. get _isScrollModeHorizontal() {
  8461. return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
  8462. }
  8463. get _isContainerRtl() {
  8464. return getComputedStyle(this.container).direction === "rtl";
  8465. }
  8466. get isInPresentationMode() {
  8467. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8468. }
  8469. get isChangingPresentationMode() {
  8470. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8471. }
  8472. get isHorizontalScrollbarEnabled() {
  8473. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8474. }
  8475. get isVerticalScrollbarEnabled() {
  8476. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8477. }
  8478. _getCurrentVisiblePage() {
  8479. if (!this.pagesCount) {
  8480. return {
  8481. views: []
  8482. };
  8483. }
  8484. const pageView = this._pages[this._currentPageNumber - 1];
  8485. const element = pageView.div;
  8486. const view = {
  8487. id: pageView.id,
  8488. x: element.offsetLeft + element.clientLeft,
  8489. y: element.offsetTop + element.clientTop,
  8490. view: pageView
  8491. };
  8492. return {
  8493. first: view,
  8494. last: view,
  8495. views: [view]
  8496. };
  8497. }
  8498. _getVisiblePages() {
  8499. return (0, _ui_utils.getVisibleElements)({
  8500. scrollEl: this.container,
  8501. views: this._pages,
  8502. sortByVisibility: true,
  8503. horizontal: this._isScrollModeHorizontal,
  8504. rtl: this._isScrollModeHorizontal && this._isContainerRtl
  8505. });
  8506. }
  8507. isPageVisible(pageNumber) {
  8508. if (!this.pdfDocument) {
  8509. return false;
  8510. }
  8511. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8512. console.error(`${this._name}.isPageVisible: "${pageNumber}" is not a valid page.`);
  8513. return false;
  8514. }
  8515. return this._getVisiblePages().views.some(function (view) {
  8516. return view.id === pageNumber;
  8517. });
  8518. }
  8519. isPageCached(pageNumber) {
  8520. if (!this.pdfDocument || !this._buffer) {
  8521. return false;
  8522. }
  8523. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8524. console.error(`${this._name}.isPageCached: "${pageNumber}" is not a valid page.`);
  8525. return false;
  8526. }
  8527. const pageView = this._pages[pageNumber - 1];
  8528. if (!pageView) {
  8529. return false;
  8530. }
  8531. return this._buffer.has(pageView);
  8532. }
  8533. cleanup() {
  8534. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8535. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  8536. this._pages[i].reset();
  8537. }
  8538. }
  8539. }
  8540. _cancelRendering() {
  8541. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8542. if (this._pages[i]) {
  8543. this._pages[i].cancelRendering();
  8544. }
  8545. }
  8546. }
  8547. _ensurePdfPageLoaded(pageView) {
  8548. if (pageView.pdfPage) {
  8549. return Promise.resolve(pageView.pdfPage);
  8550. }
  8551. if (this._pagesRequests.has(pageView)) {
  8552. return this._pagesRequests.get(pageView);
  8553. }
  8554. const promise = this.pdfDocument.getPage(pageView.id).then(pdfPage => {
  8555. if (!pageView.pdfPage) {
  8556. pageView.setPdfPage(pdfPage);
  8557. }
  8558. this._pagesRequests.delete(pageView);
  8559. return pdfPage;
  8560. }).catch(reason => {
  8561. console.error("Unable to get page for page view", reason);
  8562. this._pagesRequests.delete(pageView);
  8563. });
  8564. this._pagesRequests.set(pageView, promise);
  8565. return promise;
  8566. }
  8567. forceRendering(currentlyVisiblePages) {
  8568. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  8569. const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
  8570. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
  8571. if (pageView) {
  8572. this._ensurePdfPageLoaded(pageView).then(() => {
  8573. this.renderingQueue.renderView(pageView);
  8574. });
  8575. return true;
  8576. }
  8577. return false;
  8578. }
  8579. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  8580. return new _text_layer_builder.TextLayerBuilder({
  8581. textLayerDiv,
  8582. eventBus,
  8583. pageIndex,
  8584. viewport,
  8585. findController: this.isInPresentationMode ? null : this.findController,
  8586. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  8587. });
  8588. }
  8589. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = false, l10n = _l10n_utils.NullL10n, enableScripting = null, hasJSActionsPromise = null, mouseState = null) {
  8590. return new _annotation_layer_builder.AnnotationLayerBuilder({
  8591. pageDiv,
  8592. pdfPage,
  8593. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8594. imageResourcesPath,
  8595. renderInteractiveForms,
  8596. linkService: this.linkService,
  8597. downloadManager: this.downloadManager,
  8598. l10n,
  8599. enableScripting: enableScripting ?? this.enableScripting,
  8600. hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
  8601. mouseState: mouseState || this._scriptingManager?.mouseState
  8602. });
  8603. }
  8604. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null) {
  8605. return new _xfa_layer_builder.XfaLayerBuilder({
  8606. pageDiv,
  8607. pdfPage,
  8608. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage
  8609. });
  8610. }
  8611. createStructTreeLayerBuilder(pdfPage) {
  8612. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  8613. pdfPage
  8614. });
  8615. }
  8616. get hasEqualPageSizes() {
  8617. const firstPageView = this._pages[0];
  8618. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  8619. const pageView = this._pages[i];
  8620. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  8621. return false;
  8622. }
  8623. }
  8624. return true;
  8625. }
  8626. getPagesOverview() {
  8627. return this._pages.map(pageView => {
  8628. const viewport = pageView.pdfPage.getViewport({
  8629. scale: 1
  8630. });
  8631. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  8632. return {
  8633. width: viewport.width,
  8634. height: viewport.height,
  8635. rotation: viewport.rotation
  8636. };
  8637. }
  8638. return {
  8639. width: viewport.height,
  8640. height: viewport.width,
  8641. rotation: (viewport.rotation - 90) % 360
  8642. };
  8643. });
  8644. }
  8645. get optionalContentConfigPromise() {
  8646. if (!this.pdfDocument) {
  8647. return Promise.resolve(null);
  8648. }
  8649. if (!this._optionalContentConfigPromise) {
  8650. return this.pdfDocument.getOptionalContentConfig();
  8651. }
  8652. return this._optionalContentConfigPromise;
  8653. }
  8654. set optionalContentConfigPromise(promise) {
  8655. if (!(promise instanceof Promise)) {
  8656. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  8657. }
  8658. if (!this.pdfDocument) {
  8659. return;
  8660. }
  8661. if (!this._optionalContentConfigPromise) {
  8662. return;
  8663. }
  8664. this._optionalContentConfigPromise = promise;
  8665. for (const pageView of this._pages) {
  8666. pageView.update(pageView.scale, pageView.rotation, promise);
  8667. }
  8668. this.update();
  8669. this.eventBus.dispatch("optionalcontentconfigchanged", {
  8670. source: this,
  8671. promise
  8672. });
  8673. }
  8674. get scrollMode() {
  8675. return this._scrollMode;
  8676. }
  8677. set scrollMode(mode) {
  8678. if (this._scrollMode === mode) {
  8679. return;
  8680. }
  8681. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  8682. throw new Error(`Invalid scroll mode: ${mode}`);
  8683. }
  8684. this._scrollMode = mode;
  8685. this.eventBus.dispatch("scrollmodechanged", {
  8686. source: this,
  8687. mode
  8688. });
  8689. this._updateScrollMode(this._currentPageNumber);
  8690. }
  8691. _updateScrollMode(pageNumber = null) {
  8692. const scrollMode = this._scrollMode,
  8693. viewer = this.viewer;
  8694. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  8695. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  8696. if (!this.pdfDocument || !pageNumber) {
  8697. return;
  8698. }
  8699. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8700. this._setScale(this._currentScaleValue, true);
  8701. }
  8702. this._setCurrentPageNumber(pageNumber, true);
  8703. this.update();
  8704. }
  8705. get spreadMode() {
  8706. return this._spreadMode;
  8707. }
  8708. set spreadMode(mode) {
  8709. if (this._spreadMode === mode) {
  8710. return;
  8711. }
  8712. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  8713. throw new Error(`Invalid spread mode: ${mode}`);
  8714. }
  8715. this._spreadMode = mode;
  8716. this.eventBus.dispatch("spreadmodechanged", {
  8717. source: this,
  8718. mode
  8719. });
  8720. this._updateSpreadMode(this._currentPageNumber);
  8721. }
  8722. _updateSpreadMode(pageNumber = null) {
  8723. if (!this.pdfDocument) {
  8724. return;
  8725. }
  8726. const viewer = this.viewer,
  8727. pages = this._pages;
  8728. viewer.textContent = "";
  8729. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8730. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  8731. viewer.appendChild(pages[i].div);
  8732. }
  8733. } else {
  8734. const parity = this._spreadMode - 1;
  8735. let spread = null;
  8736. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  8737. if (spread === null) {
  8738. spread = document.createElement("div");
  8739. spread.className = "spread";
  8740. viewer.appendChild(spread);
  8741. } else if (i % 2 === parity) {
  8742. spread = spread.cloneNode(false);
  8743. viewer.appendChild(spread);
  8744. }
  8745. spread.appendChild(pages[i].div);
  8746. }
  8747. }
  8748. if (!pageNumber) {
  8749. return;
  8750. }
  8751. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8752. this._setScale(this._currentScaleValue, true);
  8753. }
  8754. this._setCurrentPageNumber(pageNumber, true);
  8755. this.update();
  8756. }
  8757. _getPageAdvance(currentPageNumber, previous = false) {
  8758. if (this.isInPresentationMode) {
  8759. return 1;
  8760. }
  8761. switch (this._scrollMode) {
  8762. case _ui_utils.ScrollMode.WRAPPED:
  8763. {
  8764. const {
  8765. views
  8766. } = this._getVisiblePages(),
  8767. pageLayout = new Map();
  8768. for (const {
  8769. id,
  8770. y,
  8771. percent,
  8772. widthPercent
  8773. } of views) {
  8774. if (percent === 0 || widthPercent < 100) {
  8775. continue;
  8776. }
  8777. let yArray = pageLayout.get(y);
  8778. if (!yArray) {
  8779. pageLayout.set(y, yArray || (yArray = []));
  8780. }
  8781. yArray.push(id);
  8782. }
  8783. for (const yArray of pageLayout.values()) {
  8784. const currentIndex = yArray.indexOf(currentPageNumber);
  8785. if (currentIndex === -1) {
  8786. continue;
  8787. }
  8788. const numPages = yArray.length;
  8789. if (numPages === 1) {
  8790. break;
  8791. }
  8792. if (previous) {
  8793. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  8794. const currentId = yArray[i],
  8795. expectedId = yArray[i + 1] - 1;
  8796. if (currentId < expectedId) {
  8797. return currentPageNumber - expectedId;
  8798. }
  8799. }
  8800. } else {
  8801. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  8802. const currentId = yArray[i],
  8803. expectedId = yArray[i - 1] + 1;
  8804. if (currentId > expectedId) {
  8805. return expectedId - currentPageNumber;
  8806. }
  8807. }
  8808. }
  8809. if (previous) {
  8810. const firstId = yArray[0];
  8811. if (firstId < currentPageNumber) {
  8812. return currentPageNumber - firstId + 1;
  8813. }
  8814. } else {
  8815. const lastId = yArray[numPages - 1];
  8816. if (lastId > currentPageNumber) {
  8817. return lastId - currentPageNumber + 1;
  8818. }
  8819. }
  8820. break;
  8821. }
  8822. break;
  8823. }
  8824. case _ui_utils.ScrollMode.HORIZONTAL:
  8825. {
  8826. break;
  8827. }
  8828. case _ui_utils.ScrollMode.VERTICAL:
  8829. {
  8830. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8831. break;
  8832. }
  8833. const parity = this._spreadMode - 1;
  8834. if (previous && currentPageNumber % 2 !== parity) {
  8835. break;
  8836. } else if (!previous && currentPageNumber % 2 === parity) {
  8837. break;
  8838. }
  8839. const {
  8840. views
  8841. } = this._getVisiblePages(),
  8842. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  8843. for (const {
  8844. id,
  8845. percent,
  8846. widthPercent
  8847. } of views) {
  8848. if (id !== expectedId) {
  8849. continue;
  8850. }
  8851. if (percent > 0 && widthPercent === 100) {
  8852. return 2;
  8853. }
  8854. break;
  8855. }
  8856. break;
  8857. }
  8858. }
  8859. return 1;
  8860. }
  8861. nextPage() {
  8862. const currentPageNumber = this._currentPageNumber,
  8863. pagesCount = this.pagesCount;
  8864. if (currentPageNumber >= pagesCount) {
  8865. return false;
  8866. }
  8867. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  8868. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  8869. return true;
  8870. }
  8871. previousPage() {
  8872. const currentPageNumber = this._currentPageNumber;
  8873. if (currentPageNumber <= 1) {
  8874. return false;
  8875. }
  8876. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  8877. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  8878. return true;
  8879. }
  8880. }
  8881. exports.BaseViewer = BaseViewer;
  8882. /***/ }),
  8883. /* 29 */
  8884. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8885. Object.defineProperty(exports, "__esModule", ({
  8886. value: true
  8887. }));
  8888. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
  8889. var _pdfjsLib = __webpack_require__(5);
  8890. var _l10n_utils = __webpack_require__(30);
  8891. var _pdf_link_service = __webpack_require__(19);
  8892. class AnnotationLayerBuilder {
  8893. constructor({
  8894. pageDiv,
  8895. pdfPage,
  8896. linkService,
  8897. downloadManager,
  8898. annotationStorage = null,
  8899. imageResourcesPath = "",
  8900. renderInteractiveForms = true,
  8901. l10n = _l10n_utils.NullL10n,
  8902. enableScripting = false,
  8903. hasJSActionsPromise = null,
  8904. mouseState = null
  8905. }) {
  8906. this.pageDiv = pageDiv;
  8907. this.pdfPage = pdfPage;
  8908. this.linkService = linkService;
  8909. this.downloadManager = downloadManager;
  8910. this.imageResourcesPath = imageResourcesPath;
  8911. this.renderInteractiveForms = renderInteractiveForms;
  8912. this.l10n = l10n;
  8913. this.annotationStorage = annotationStorage;
  8914. this.enableScripting = enableScripting;
  8915. this._hasJSActionsPromise = hasJSActionsPromise;
  8916. this._mouseState = mouseState;
  8917. this.div = null;
  8918. this._cancelled = false;
  8919. }
  8920. render(viewport, intent = "display") {
  8921. return Promise.all([this.pdfPage.getAnnotations({
  8922. intent
  8923. }), this._hasJSActionsPromise]).then(([annotations, hasJSActions = false]) => {
  8924. if (this._cancelled) {
  8925. return;
  8926. }
  8927. if (annotations.length === 0) {
  8928. return;
  8929. }
  8930. const parameters = {
  8931. viewport: viewport.clone({
  8932. dontFlip: true
  8933. }),
  8934. div: this.div,
  8935. annotations,
  8936. page: this.pdfPage,
  8937. imageResourcesPath: this.imageResourcesPath,
  8938. renderInteractiveForms: this.renderInteractiveForms,
  8939. linkService: this.linkService,
  8940. downloadManager: this.downloadManager,
  8941. annotationStorage: this.annotationStorage,
  8942. enableScripting: this.enableScripting,
  8943. hasJSActions,
  8944. mouseState: this._mouseState
  8945. };
  8946. if (this.div) {
  8947. _pdfjsLib.AnnotationLayer.update(parameters);
  8948. } else {
  8949. this.div = document.createElement("div");
  8950. this.div.className = "annotationLayer";
  8951. this.pageDiv.appendChild(this.div);
  8952. parameters.div = this.div;
  8953. _pdfjsLib.AnnotationLayer.render(parameters);
  8954. this.l10n.translate(this.div);
  8955. }
  8956. });
  8957. }
  8958. cancel() {
  8959. this._cancelled = true;
  8960. }
  8961. hide() {
  8962. if (!this.div) {
  8963. return;
  8964. }
  8965. this.div.hidden = true;
  8966. }
  8967. }
  8968. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  8969. class DefaultAnnotationLayerFactory {
  8970. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = true, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
  8971. return new AnnotationLayerBuilder({
  8972. pageDiv,
  8973. pdfPage,
  8974. imageResourcesPath,
  8975. renderInteractiveForms,
  8976. linkService: new _pdf_link_service.SimpleLinkService(),
  8977. l10n,
  8978. annotationStorage,
  8979. enableScripting,
  8980. hasJSActionsPromise,
  8981. mouseState
  8982. });
  8983. }
  8984. }
  8985. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  8986. /***/ }),
  8987. /* 30 */
  8988. /***/ ((__unused_webpack_module, exports) => {
  8989. Object.defineProperty(exports, "__esModule", ({
  8990. value: true
  8991. }));
  8992. exports.getL10nFallback = getL10nFallback;
  8993. exports.NullL10n = void 0;
  8994. const DEFAULT_L10N_STRINGS = {
  8995. of_pages: "of {{pagesCount}}",
  8996. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  8997. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  8998. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  8999. document_properties_date_string: "{{date}}, {{time}}",
  9000. document_properties_page_size_unit_inches: "in",
  9001. document_properties_page_size_unit_millimeters: "mm",
  9002. document_properties_page_size_orientation_portrait: "portrait",
  9003. document_properties_page_size_orientation_landscape: "landscape",
  9004. document_properties_page_size_name_a3: "A3",
  9005. document_properties_page_size_name_a4: "A4",
  9006. document_properties_page_size_name_letter: "Letter",
  9007. document_properties_page_size_name_legal: "Legal",
  9008. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9009. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9010. document_properties_linearized_yes: "Yes",
  9011. document_properties_linearized_no: "No",
  9012. print_progress_percent: "{{progress}}%",
  9013. "toggle_sidebar.title": "Toggle Sidebar",
  9014. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  9015. additional_layers: "Additional Layers",
  9016. page_landmark: "Page {{page}}",
  9017. thumb_page_title: "Page {{page}}",
  9018. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9019. find_reached_top: "Reached top of document, continued from bottom",
  9020. find_reached_bottom: "Reached end of document, continued from top",
  9021. "find_match_count[one]": "{{current}} of {{total}} match",
  9022. "find_match_count[other]": "{{current}} of {{total}} matches",
  9023. "find_match_count_limit[one]": "More than {{limit}} match",
  9024. "find_match_count_limit[other]": "More than {{limit}} matches",
  9025. find_not_found: "Phrase not found",
  9026. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  9027. error_message: "Message: {{message}}",
  9028. error_stack: "Stack: {{stack}}",
  9029. error_file: "File: {{file}}",
  9030. error_line: "Line: {{line}}",
  9031. rendering_error: "An error occurred while rendering the page.",
  9032. page_scale_width: "Page Width",
  9033. page_scale_fit: "Page Fit",
  9034. page_scale_auto: "Automatic Zoom",
  9035. page_scale_actual: "Actual Size",
  9036. page_scale_percent: "{{scale}}%",
  9037. loading: "Loading…",
  9038. loading_error: "An error occurred while loading the PDF.",
  9039. invalid_file_error: "Invalid or corrupted PDF file.",
  9040. missing_file_error: "Missing PDF file.",
  9041. unexpected_response_error: "Unexpected server response.",
  9042. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9043. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9044. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
  9045. };
  9046. function getL10nFallback(key, args) {
  9047. switch (key) {
  9048. case "find_match_count":
  9049. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9050. break;
  9051. case "find_match_count_limit":
  9052. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9053. break;
  9054. }
  9055. return DEFAULT_L10N_STRINGS[key] || "";
  9056. }
  9057. function formatL10nValue(text, args) {
  9058. if (!args) {
  9059. return text;
  9060. }
  9061. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9062. return name in args ? args[name] : "{{" + name + "}}";
  9063. });
  9064. }
  9065. const NullL10n = {
  9066. async getLanguage() {
  9067. return "en-us";
  9068. },
  9069. async getDirection() {
  9070. return "ltr";
  9071. },
  9072. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9073. return formatL10nValue(fallback, args);
  9074. },
  9075. async translate(element) {}
  9076. };
  9077. exports.NullL10n = NullL10n;
  9078. /***/ }),
  9079. /* 31 */
  9080. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9081. Object.defineProperty(exports, "__esModule", ({
  9082. value: true
  9083. }));
  9084. exports.PDFPageView = void 0;
  9085. var _ui_utils = __webpack_require__(4);
  9086. var _pdfjsLib = __webpack_require__(5);
  9087. var _l10n_utils = __webpack_require__(30);
  9088. var _pdf_rendering_queue = __webpack_require__(8);
  9089. var _viewer_compatibility = __webpack_require__(2);
  9090. const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
  9091. class PDFPageView {
  9092. constructor(options) {
  9093. const container = options.container;
  9094. const defaultViewport = options.defaultViewport;
  9095. this.id = options.id;
  9096. this.renderingId = "page" + this.id;
  9097. this.pdfPage = null;
  9098. this.pageLabel = null;
  9099. this.rotation = 0;
  9100. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9101. this.viewport = defaultViewport;
  9102. this.pdfPageRotate = defaultViewport.rotation;
  9103. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9104. this.hasRestrictedScaling = false;
  9105. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  9106. this.imageResourcesPath = options.imageResourcesPath || "";
  9107. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  9108. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9109. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9110. this.eventBus = options.eventBus;
  9111. this.renderingQueue = options.renderingQueue;
  9112. this.textLayerFactory = options.textLayerFactory;
  9113. this.annotationLayerFactory = options.annotationLayerFactory;
  9114. this.xfaLayerFactory = options.xfaLayerFactory;
  9115. this.structTreeLayerFactory = options.structTreeLayerFactory;
  9116. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9117. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9118. this.paintTask = null;
  9119. this.paintedViewportMap = new WeakMap();
  9120. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9121. this.resume = null;
  9122. this._renderError = null;
  9123. this.annotationLayer = null;
  9124. this.textLayer = null;
  9125. this.zoomLayer = null;
  9126. this.xfaLayer = null;
  9127. this.structTreeLayer = null;
  9128. const div = document.createElement("div");
  9129. div.className = "page";
  9130. div.style.width = Math.floor(this.viewport.width) + "px";
  9131. div.style.height = Math.floor(this.viewport.height) + "px";
  9132. div.setAttribute("data-page-number", this.id);
  9133. div.setAttribute("role", "region");
  9134. this.l10n.get("page_landmark", {
  9135. page: this.id
  9136. }).then(msg => {
  9137. div.setAttribute("aria-label", msg);
  9138. });
  9139. this.div = div;
  9140. container.appendChild(div);
  9141. }
  9142. setPdfPage(pdfPage) {
  9143. this.pdfPage = pdfPage;
  9144. this.pdfPageRotate = pdfPage.rotate;
  9145. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9146. this.viewport = pdfPage.getViewport({
  9147. scale: this.scale * _ui_utils.CSS_UNITS,
  9148. rotation: totalRotation
  9149. });
  9150. this.reset();
  9151. }
  9152. destroy() {
  9153. this.reset();
  9154. if (this.pdfPage) {
  9155. this.pdfPage.cleanup();
  9156. }
  9157. }
  9158. async _renderAnnotationLayer() {
  9159. let error = null;
  9160. try {
  9161. await this.annotationLayer.render(this.viewport, "display");
  9162. } catch (ex) {
  9163. error = ex;
  9164. } finally {
  9165. this.eventBus.dispatch("annotationlayerrendered", {
  9166. source: this,
  9167. pageNumber: this.id,
  9168. error
  9169. });
  9170. }
  9171. }
  9172. async _renderXfaLayer() {
  9173. let error = null;
  9174. try {
  9175. await this.xfaLayer.render(this.viewport, "display");
  9176. } catch (ex) {
  9177. error = ex;
  9178. } finally {
  9179. this.eventBus.dispatch("xfalayerrendered", {
  9180. source: this,
  9181. pageNumber: this.id,
  9182. error
  9183. });
  9184. }
  9185. }
  9186. _resetZoomLayer(removeFromDOM = false) {
  9187. if (!this.zoomLayer) {
  9188. return;
  9189. }
  9190. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9191. this.paintedViewportMap.delete(zoomLayerCanvas);
  9192. zoomLayerCanvas.width = 0;
  9193. zoomLayerCanvas.height = 0;
  9194. if (removeFromDOM) {
  9195. this.zoomLayer.remove();
  9196. }
  9197. this.zoomLayer = null;
  9198. }
  9199. reset(keepZoomLayer = false, keepAnnotations = false) {
  9200. this.cancelRendering(keepAnnotations);
  9201. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9202. const div = this.div;
  9203. div.style.width = Math.floor(this.viewport.width) + "px";
  9204. div.style.height = Math.floor(this.viewport.height) + "px";
  9205. const childNodes = div.childNodes;
  9206. const currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  9207. const currentAnnotationNode = keepAnnotations && this.annotationLayer?.div || null;
  9208. const currentXfaLayerNode = this.xfaLayer?.div || null;
  9209. for (let i = childNodes.length - 1; i >= 0; i--) {
  9210. const node = childNodes[i];
  9211. if (currentZoomLayerNode === node || currentAnnotationNode === node || currentXfaLayerNode === node) {
  9212. continue;
  9213. }
  9214. div.removeChild(node);
  9215. }
  9216. div.removeAttribute("data-loaded");
  9217. if (currentAnnotationNode) {
  9218. this.annotationLayer.hide();
  9219. } else if (this.annotationLayer) {
  9220. this.annotationLayer.cancel();
  9221. this.annotationLayer = null;
  9222. }
  9223. if (!currentZoomLayerNode) {
  9224. if (this.canvas) {
  9225. this.paintedViewportMap.delete(this.canvas);
  9226. this.canvas.width = 0;
  9227. this.canvas.height = 0;
  9228. delete this.canvas;
  9229. }
  9230. this._resetZoomLayer();
  9231. }
  9232. if (this.svg) {
  9233. this.paintedViewportMap.delete(this.svg);
  9234. delete this.svg;
  9235. }
  9236. this.loadingIconDiv = document.createElement("div");
  9237. this.loadingIconDiv.className = "loadingIcon";
  9238. this.loadingIconDiv.setAttribute("role", "img");
  9239. this.l10n.get("loading").then(msg => {
  9240. this.loadingIconDiv?.setAttribute("aria-label", msg);
  9241. });
  9242. div.appendChild(this.loadingIconDiv);
  9243. }
  9244. update(scale, rotation, optionalContentConfigPromise = null) {
  9245. this.scale = scale || this.scale;
  9246. if (typeof rotation !== "undefined") {
  9247. this.rotation = rotation;
  9248. }
  9249. if (optionalContentConfigPromise instanceof Promise) {
  9250. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9251. }
  9252. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9253. this.viewport = this.viewport.clone({
  9254. scale: this.scale * _ui_utils.CSS_UNITS,
  9255. rotation: totalRotation
  9256. });
  9257. if (this.svg) {
  9258. this.cssTransform(this.svg, true);
  9259. this.eventBus.dispatch("pagerendered", {
  9260. source: this,
  9261. pageNumber: this.id,
  9262. cssTransform: true,
  9263. timestamp: performance.now(),
  9264. error: this._renderError
  9265. });
  9266. return;
  9267. }
  9268. let isScalingRestricted = false;
  9269. if (this.canvas && this.maxCanvasPixels > 0) {
  9270. const outputScale = this.outputScale;
  9271. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  9272. isScalingRestricted = true;
  9273. }
  9274. }
  9275. if (this.canvas) {
  9276. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  9277. this.cssTransform(this.canvas, true);
  9278. this.eventBus.dispatch("pagerendered", {
  9279. source: this,
  9280. pageNumber: this.id,
  9281. cssTransform: true,
  9282. timestamp: performance.now(),
  9283. error: this._renderError
  9284. });
  9285. return;
  9286. }
  9287. if (!this.zoomLayer && !this.canvas.hidden) {
  9288. this.zoomLayer = this.canvas.parentNode;
  9289. this.zoomLayer.style.position = "absolute";
  9290. }
  9291. }
  9292. if (this.zoomLayer) {
  9293. this.cssTransform(this.zoomLayer.firstChild);
  9294. }
  9295. this.reset(true, true);
  9296. }
  9297. cancelRendering(keepAnnotations = false) {
  9298. if (this.paintTask) {
  9299. this.paintTask.cancel();
  9300. this.paintTask = null;
  9301. }
  9302. this.resume = null;
  9303. if (this.textLayer) {
  9304. this.textLayer.cancel();
  9305. this.textLayer = null;
  9306. }
  9307. if (!keepAnnotations && this.annotationLayer) {
  9308. this.annotationLayer.cancel();
  9309. this.annotationLayer = null;
  9310. }
  9311. if (this._onTextLayerRendered) {
  9312. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9313. this._onTextLayerRendered = null;
  9314. }
  9315. }
  9316. cssTransform(target, redrawAnnotations = false) {
  9317. const width = this.viewport.width;
  9318. const height = this.viewport.height;
  9319. const div = this.div;
  9320. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  9321. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  9322. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  9323. const absRotation = Math.abs(relativeRotation);
  9324. let scaleX = 1,
  9325. scaleY = 1;
  9326. if (absRotation === 90 || absRotation === 270) {
  9327. scaleX = height / width;
  9328. scaleY = width / height;
  9329. }
  9330. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  9331. if (this.textLayer) {
  9332. const textLayerViewport = this.textLayer.viewport;
  9333. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  9334. const textAbsRotation = Math.abs(textRelativeRotation);
  9335. let scale = width / textLayerViewport.width;
  9336. if (textAbsRotation === 90 || textAbsRotation === 270) {
  9337. scale = width / textLayerViewport.height;
  9338. }
  9339. const textLayerDiv = this.textLayer.textLayerDiv;
  9340. let transX, transY;
  9341. switch (textAbsRotation) {
  9342. case 0:
  9343. transX = transY = 0;
  9344. break;
  9345. case 90:
  9346. transX = 0;
  9347. transY = "-" + textLayerDiv.style.height;
  9348. break;
  9349. case 180:
  9350. transX = "-" + textLayerDiv.style.width;
  9351. transY = "-" + textLayerDiv.style.height;
  9352. break;
  9353. case 270:
  9354. transX = "-" + textLayerDiv.style.width;
  9355. transY = 0;
  9356. break;
  9357. default:
  9358. console.error("Bad rotation value.");
  9359. break;
  9360. }
  9361. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  9362. textLayerDiv.style.transformOrigin = "0% 0%";
  9363. }
  9364. if (redrawAnnotations && this.annotationLayer) {
  9365. this._renderAnnotationLayer();
  9366. }
  9367. if (this.xfaLayer) {
  9368. this._renderXfaLayer();
  9369. }
  9370. }
  9371. get width() {
  9372. return this.viewport.width;
  9373. }
  9374. get height() {
  9375. return this.viewport.height;
  9376. }
  9377. getPagePoint(x, y) {
  9378. return this.viewport.convertToPdfPoint(x, y);
  9379. }
  9380. draw() {
  9381. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  9382. console.error("Must be in new state before drawing");
  9383. this.reset();
  9384. }
  9385. const {
  9386. div,
  9387. pdfPage
  9388. } = this;
  9389. if (!pdfPage) {
  9390. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9391. if (this.loadingIconDiv) {
  9392. div.removeChild(this.loadingIconDiv);
  9393. delete this.loadingIconDiv;
  9394. }
  9395. return Promise.reject(new Error("pdfPage is not loaded"));
  9396. }
  9397. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9398. const canvasWrapper = document.createElement("div");
  9399. canvasWrapper.style.width = div.style.width;
  9400. canvasWrapper.style.height = div.style.height;
  9401. canvasWrapper.classList.add("canvasWrapper");
  9402. if (this.annotationLayer?.div) {
  9403. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  9404. } else {
  9405. div.appendChild(canvasWrapper);
  9406. }
  9407. let textLayer = null;
  9408. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  9409. const textLayerDiv = document.createElement("div");
  9410. textLayerDiv.className = "textLayer";
  9411. textLayerDiv.style.width = canvasWrapper.style.width;
  9412. textLayerDiv.style.height = canvasWrapper.style.height;
  9413. if (this.annotationLayer?.div) {
  9414. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  9415. } else {
  9416. div.appendChild(textLayerDiv);
  9417. }
  9418. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
  9419. }
  9420. this.textLayer = textLayer;
  9421. let renderContinueCallback = null;
  9422. if (this.renderingQueue) {
  9423. renderContinueCallback = cont => {
  9424. if (!this.renderingQueue.isHighestPriority(this)) {
  9425. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  9426. this.resume = () => {
  9427. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9428. cont();
  9429. };
  9430. return;
  9431. }
  9432. cont();
  9433. };
  9434. }
  9435. const finishPaintTask = async (error = null) => {
  9436. if (paintTask === this.paintTask) {
  9437. this.paintTask = null;
  9438. }
  9439. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  9440. this._renderError = null;
  9441. return;
  9442. }
  9443. this._renderError = error;
  9444. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9445. if (this.loadingIconDiv) {
  9446. div.removeChild(this.loadingIconDiv);
  9447. delete this.loadingIconDiv;
  9448. }
  9449. this._resetZoomLayer(true);
  9450. this.eventBus.dispatch("pagerendered", {
  9451. source: this,
  9452. pageNumber: this.id,
  9453. cssTransform: false,
  9454. timestamp: performance.now(),
  9455. error: this._renderError
  9456. });
  9457. if (error) {
  9458. throw error;
  9459. }
  9460. };
  9461. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  9462. paintTask.onRenderContinue = renderContinueCallback;
  9463. this.paintTask = paintTask;
  9464. const resultPromise = paintTask.promise.then(() => {
  9465. return finishPaintTask(null).then(() => {
  9466. if (textLayer) {
  9467. const readableStream = pdfPage.streamTextContent({
  9468. normalizeWhitespace: true,
  9469. includeMarkedContent: true
  9470. });
  9471. textLayer.setTextContentStream(readableStream);
  9472. textLayer.render();
  9473. }
  9474. });
  9475. }, function (reason) {
  9476. return finishPaintTask(reason);
  9477. });
  9478. if (this.annotationLayerFactory) {
  9479. if (!this.annotationLayer) {
  9480. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.renderInteractiveForms, this.l10n, null, null, null);
  9481. }
  9482. this._renderAnnotationLayer();
  9483. }
  9484. if (this.xfaLayerFactory) {
  9485. if (!this.xfaLayer) {
  9486. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage, null);
  9487. }
  9488. this._renderXfaLayer();
  9489. }
  9490. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  9491. this._onTextLayerRendered = event => {
  9492. if (event.pageNumber !== this.id) {
  9493. return;
  9494. }
  9495. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9496. this._onTextLayerRendered = null;
  9497. if (!this.canvas) {
  9498. return;
  9499. }
  9500. this.pdfPage.getStructTree().then(tree => {
  9501. if (!tree) {
  9502. return;
  9503. }
  9504. if (!this.canvas) {
  9505. return;
  9506. }
  9507. const treeDom = this.structTreeLayer.render(tree);
  9508. treeDom.classList.add("structTree");
  9509. this.canvas.appendChild(treeDom);
  9510. });
  9511. };
  9512. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  9513. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder(pdfPage);
  9514. }
  9515. div.setAttribute("data-loaded", true);
  9516. this.eventBus.dispatch("pagerender", {
  9517. source: this,
  9518. pageNumber: this.id
  9519. });
  9520. return resultPromise;
  9521. }
  9522. paintOnCanvas(canvasWrapper) {
  9523. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  9524. const result = {
  9525. promise: renderCapability.promise,
  9526. onRenderContinue(cont) {
  9527. cont();
  9528. },
  9529. cancel() {
  9530. renderTask.cancel();
  9531. }
  9532. };
  9533. const viewport = this.viewport;
  9534. const canvas = document.createElement("canvas");
  9535. canvas.hidden = true;
  9536. let isCanvasHidden = true;
  9537. const showCanvas = function () {
  9538. if (isCanvasHidden) {
  9539. canvas.hidden = false;
  9540. isCanvasHidden = false;
  9541. }
  9542. };
  9543. canvasWrapper.appendChild(canvas);
  9544. this.canvas = canvas;
  9545. canvas.mozOpaque = true;
  9546. const ctx = canvas.getContext("2d", {
  9547. alpha: false
  9548. });
  9549. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  9550. this.outputScale = outputScale;
  9551. if (this.useOnlyCssZoom) {
  9552. const actualSizeViewport = viewport.clone({
  9553. scale: _ui_utils.CSS_UNITS
  9554. });
  9555. outputScale.sx *= actualSizeViewport.width / viewport.width;
  9556. outputScale.sy *= actualSizeViewport.height / viewport.height;
  9557. outputScale.scaled = true;
  9558. }
  9559. if (this.maxCanvasPixels > 0) {
  9560. const pixelsInViewport = viewport.width * viewport.height;
  9561. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  9562. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  9563. outputScale.sx = maxScale;
  9564. outputScale.sy = maxScale;
  9565. outputScale.scaled = true;
  9566. this.hasRestrictedScaling = true;
  9567. } else {
  9568. this.hasRestrictedScaling = false;
  9569. }
  9570. }
  9571. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  9572. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  9573. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  9574. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  9575. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  9576. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  9577. this.paintedViewportMap.set(canvas, viewport);
  9578. const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  9579. const renderContext = {
  9580. canvasContext: ctx,
  9581. transform,
  9582. viewport: this.viewport,
  9583. renderInteractiveForms: this.renderInteractiveForms,
  9584. optionalContentConfigPromise: this._optionalContentConfigPromise
  9585. };
  9586. const renderTask = this.pdfPage.render(renderContext);
  9587. renderTask.onContinue = function (cont) {
  9588. showCanvas();
  9589. if (result.onRenderContinue) {
  9590. result.onRenderContinue(cont);
  9591. } else {
  9592. cont();
  9593. }
  9594. };
  9595. renderTask.promise.then(function () {
  9596. showCanvas();
  9597. renderCapability.resolve(undefined);
  9598. }, function (error) {
  9599. showCanvas();
  9600. renderCapability.reject(error);
  9601. });
  9602. return result;
  9603. }
  9604. paintOnSvg(wrapper) {
  9605. let cancelled = false;
  9606. const ensureNotCancelled = () => {
  9607. if (cancelled) {
  9608. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  9609. }
  9610. };
  9611. const pdfPage = this.pdfPage;
  9612. const actualSizeViewport = this.viewport.clone({
  9613. scale: _ui_utils.CSS_UNITS
  9614. });
  9615. const promise = pdfPage.getOperatorList().then(opList => {
  9616. ensureNotCancelled();
  9617. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  9618. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  9619. ensureNotCancelled();
  9620. this.svg = svg;
  9621. this.paintedViewportMap.set(svg, actualSizeViewport);
  9622. svg.style.width = wrapper.style.width;
  9623. svg.style.height = wrapper.style.height;
  9624. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9625. wrapper.appendChild(svg);
  9626. });
  9627. });
  9628. return {
  9629. promise,
  9630. onRenderContinue(cont) {
  9631. cont();
  9632. },
  9633. cancel() {
  9634. cancelled = true;
  9635. }
  9636. };
  9637. }
  9638. setPageLabel(label) {
  9639. this.pageLabel = typeof label === "string" ? label : null;
  9640. if (this.pageLabel !== null) {
  9641. this.div.setAttribute("data-page-label", this.pageLabel);
  9642. } else {
  9643. this.div.removeAttribute("data-page-label");
  9644. }
  9645. }
  9646. }
  9647. exports.PDFPageView = PDFPageView;
  9648. /***/ }),
  9649. /* 32 */
  9650. /***/ ((__unused_webpack_module, exports) => {
  9651. Object.defineProperty(exports, "__esModule", ({
  9652. value: true
  9653. }));
  9654. exports.StructTreeLayerBuilder = exports.DefaultStructTreeLayerFactory = void 0;
  9655. const PDF_ROLE_TO_HTML_ROLE = {
  9656. Document: null,
  9657. DocumentFragment: null,
  9658. Part: "group",
  9659. Sect: "group",
  9660. Div: "group",
  9661. Aside: "note",
  9662. NonStruct: "none",
  9663. P: null,
  9664. H: "heading",
  9665. Title: null,
  9666. FENote: "note",
  9667. Sub: "group",
  9668. Lbl: null,
  9669. Span: null,
  9670. Em: null,
  9671. Strong: null,
  9672. Link: "link",
  9673. Annot: "note",
  9674. Form: "form",
  9675. Ruby: null,
  9676. RB: null,
  9677. RT: null,
  9678. RP: null,
  9679. Warichu: null,
  9680. WT: null,
  9681. WP: null,
  9682. L: "list",
  9683. LI: "listitem",
  9684. LBody: null,
  9685. Table: "table",
  9686. TR: "row",
  9687. TH: "columnheader",
  9688. TD: "cell",
  9689. THead: "columnheader",
  9690. TBody: null,
  9691. TFoot: null,
  9692. Caption: null,
  9693. Figure: "figure",
  9694. Formula: null,
  9695. Artifact: null
  9696. };
  9697. const HEADING_PATTERN = /^H(\d+)$/;
  9698. class StructTreeLayerBuilder {
  9699. constructor({
  9700. pdfPage
  9701. }) {
  9702. this.pdfPage = pdfPage;
  9703. }
  9704. render(structTree) {
  9705. return this._walk(structTree);
  9706. }
  9707. _setAttributes(structElement, htmlElement) {
  9708. if (structElement.alt !== undefined) {
  9709. htmlElement.setAttribute("aria-label", structElement.alt);
  9710. }
  9711. if (structElement.id !== undefined) {
  9712. htmlElement.setAttribute("aria-owns", structElement.id);
  9713. }
  9714. }
  9715. _walk(node) {
  9716. if (!node) {
  9717. return null;
  9718. }
  9719. const element = document.createElement("span");
  9720. if ("role" in node) {
  9721. const {
  9722. role
  9723. } = node;
  9724. const match = role.match(HEADING_PATTERN);
  9725. if (match) {
  9726. element.setAttribute("role", "heading");
  9727. element.setAttribute("aria-level", match[1]);
  9728. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  9729. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  9730. }
  9731. }
  9732. this._setAttributes(node, element);
  9733. if (node.children) {
  9734. if (node.children.length === 1 && "id" in node.children[0]) {
  9735. this._setAttributes(node.children[0], element);
  9736. } else {
  9737. for (const kid of node.children) {
  9738. element.appendChild(this._walk(kid));
  9739. }
  9740. }
  9741. }
  9742. return element;
  9743. }
  9744. }
  9745. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  9746. class DefaultStructTreeLayerFactory {
  9747. createStructTreeLayerBuilder(pdfPage) {
  9748. return new StructTreeLayerBuilder({
  9749. pdfPage
  9750. });
  9751. }
  9752. }
  9753. exports.DefaultStructTreeLayerFactory = DefaultStructTreeLayerFactory;
  9754. /***/ }),
  9755. /* 33 */
  9756. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9757. Object.defineProperty(exports, "__esModule", ({
  9758. value: true
  9759. }));
  9760. exports.TextLayerBuilder = exports.DefaultTextLayerFactory = void 0;
  9761. var _pdfjsLib = __webpack_require__(5);
  9762. const EXPAND_DIVS_TIMEOUT = 300;
  9763. class TextLayerBuilder {
  9764. constructor({
  9765. textLayerDiv,
  9766. eventBus,
  9767. pageIndex,
  9768. viewport,
  9769. findController = null,
  9770. enhanceTextSelection = false
  9771. }) {
  9772. this.textLayerDiv = textLayerDiv;
  9773. this.eventBus = eventBus;
  9774. this.textContent = null;
  9775. this.textContentItemsStr = [];
  9776. this.textContentStream = null;
  9777. this.renderingDone = false;
  9778. this.pageIdx = pageIndex;
  9779. this.pageNumber = this.pageIdx + 1;
  9780. this.matches = [];
  9781. this.viewport = viewport;
  9782. this.textDivs = [];
  9783. this.findController = findController;
  9784. this.textLayerRenderTask = null;
  9785. this.enhanceTextSelection = enhanceTextSelection;
  9786. this._onUpdateTextLayerMatches = null;
  9787. this._bindMouse();
  9788. }
  9789. _finishRendering() {
  9790. this.renderingDone = true;
  9791. if (!this.enhanceTextSelection) {
  9792. const endOfContent = document.createElement("div");
  9793. endOfContent.className = "endOfContent";
  9794. this.textLayerDiv.appendChild(endOfContent);
  9795. }
  9796. this.eventBus.dispatch("textlayerrendered", {
  9797. source: this,
  9798. pageNumber: this.pageNumber,
  9799. numTextDivs: this.textDivs.length
  9800. });
  9801. }
  9802. render(timeout = 0) {
  9803. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  9804. return;
  9805. }
  9806. this.cancel();
  9807. this.textDivs = [];
  9808. const textLayerFrag = document.createDocumentFragment();
  9809. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  9810. textContent: this.textContent,
  9811. textContentStream: this.textContentStream,
  9812. container: textLayerFrag,
  9813. viewport: this.viewport,
  9814. textDivs: this.textDivs,
  9815. textContentItemsStr: this.textContentItemsStr,
  9816. timeout,
  9817. enhanceTextSelection: this.enhanceTextSelection
  9818. });
  9819. this.textLayerRenderTask.promise.then(() => {
  9820. this.textLayerDiv.appendChild(textLayerFrag);
  9821. this._finishRendering();
  9822. this._updateMatches();
  9823. }, function (reason) {});
  9824. if (!this._onUpdateTextLayerMatches) {
  9825. this._onUpdateTextLayerMatches = evt => {
  9826. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  9827. this._updateMatches();
  9828. }
  9829. };
  9830. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  9831. }
  9832. }
  9833. cancel() {
  9834. if (this.textLayerRenderTask) {
  9835. this.textLayerRenderTask.cancel();
  9836. this.textLayerRenderTask = null;
  9837. }
  9838. if (this._onUpdateTextLayerMatches) {
  9839. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  9840. this._onUpdateTextLayerMatches = null;
  9841. }
  9842. }
  9843. setTextContentStream(readableStream) {
  9844. this.cancel();
  9845. this.textContentStream = readableStream;
  9846. }
  9847. setTextContent(textContent) {
  9848. this.cancel();
  9849. this.textContent = textContent;
  9850. }
  9851. _convertMatches(matches, matchesLength) {
  9852. if (!matches) {
  9853. return [];
  9854. }
  9855. const {
  9856. textContentItemsStr
  9857. } = this;
  9858. let i = 0,
  9859. iIndex = 0;
  9860. const end = textContentItemsStr.length - 1;
  9861. const result = [];
  9862. for (let m = 0, mm = matches.length; m < mm; m++) {
  9863. let matchIdx = matches[m];
  9864. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  9865. iIndex += textContentItemsStr[i].length;
  9866. i++;
  9867. }
  9868. if (i === textContentItemsStr.length) {
  9869. console.error("Could not find a matching mapping");
  9870. }
  9871. const match = {
  9872. begin: {
  9873. divIdx: i,
  9874. offset: matchIdx - iIndex
  9875. }
  9876. };
  9877. matchIdx += matchesLength[m];
  9878. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  9879. iIndex += textContentItemsStr[i].length;
  9880. i++;
  9881. }
  9882. match.end = {
  9883. divIdx: i,
  9884. offset: matchIdx - iIndex
  9885. };
  9886. result.push(match);
  9887. }
  9888. return result;
  9889. }
  9890. _renderMatches(matches) {
  9891. if (matches.length === 0) {
  9892. return;
  9893. }
  9894. const {
  9895. findController,
  9896. pageIdx,
  9897. textContentItemsStr,
  9898. textDivs
  9899. } = this;
  9900. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  9901. const selectedMatchIdx = findController.selected.matchIdx;
  9902. const highlightAll = findController.state.highlightAll;
  9903. let prevEnd = null;
  9904. const infinity = {
  9905. divIdx: -1,
  9906. offset: undefined
  9907. };
  9908. function beginText(begin, className) {
  9909. const divIdx = begin.divIdx;
  9910. textDivs[divIdx].textContent = "";
  9911. appendTextToDiv(divIdx, 0, begin.offset, className);
  9912. }
  9913. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  9914. const div = textDivs[divIdx];
  9915. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  9916. const node = document.createTextNode(content);
  9917. if (className) {
  9918. const span = document.createElement("span");
  9919. span.className = className;
  9920. span.appendChild(node);
  9921. div.appendChild(span);
  9922. return;
  9923. }
  9924. div.appendChild(node);
  9925. }
  9926. let i0 = selectedMatchIdx,
  9927. i1 = i0 + 1;
  9928. if (highlightAll) {
  9929. i0 = 0;
  9930. i1 = matches.length;
  9931. } else if (!isSelectedPage) {
  9932. return;
  9933. }
  9934. for (let i = i0; i < i1; i++) {
  9935. const match = matches[i];
  9936. const begin = match.begin;
  9937. const end = match.end;
  9938. const isSelected = isSelectedPage && i === selectedMatchIdx;
  9939. const highlightSuffix = isSelected ? " selected" : "";
  9940. if (isSelected) {
  9941. findController.scrollMatchIntoView({
  9942. element: textDivs[begin.divIdx],
  9943. pageIndex: pageIdx,
  9944. matchIndex: selectedMatchIdx
  9945. });
  9946. }
  9947. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  9948. if (prevEnd !== null) {
  9949. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  9950. }
  9951. beginText(begin);
  9952. } else {
  9953. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  9954. }
  9955. if (begin.divIdx === end.divIdx) {
  9956. appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  9957. } else {
  9958. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  9959. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  9960. textDivs[n0].className = "highlight middle" + highlightSuffix;
  9961. }
  9962. beginText(end, "highlight end" + highlightSuffix);
  9963. }
  9964. prevEnd = end;
  9965. }
  9966. if (prevEnd) {
  9967. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  9968. }
  9969. }
  9970. _updateMatches() {
  9971. if (!this.renderingDone) {
  9972. return;
  9973. }
  9974. const {
  9975. findController,
  9976. matches,
  9977. pageIdx,
  9978. textContentItemsStr,
  9979. textDivs
  9980. } = this;
  9981. let clearedUntilDivIdx = -1;
  9982. for (let i = 0, ii = matches.length; i < ii; i++) {
  9983. const match = matches[i];
  9984. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  9985. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  9986. const div = textDivs[n];
  9987. div.textContent = textContentItemsStr[n];
  9988. div.className = "";
  9989. }
  9990. clearedUntilDivIdx = match.end.divIdx + 1;
  9991. }
  9992. if (!findController?.highlightMatches) {
  9993. return;
  9994. }
  9995. const pageMatches = findController.pageMatches[pageIdx] || null;
  9996. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  9997. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  9998. this._renderMatches(this.matches);
  9999. }
  10000. _bindMouse() {
  10001. const div = this.textLayerDiv;
  10002. let expandDivsTimer = null;
  10003. div.addEventListener("mousedown", evt => {
  10004. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10005. this.textLayerRenderTask.expandTextDivs(true);
  10006. if (expandDivsTimer) {
  10007. clearTimeout(expandDivsTimer);
  10008. expandDivsTimer = null;
  10009. }
  10010. return;
  10011. }
  10012. const end = div.querySelector(".endOfContent");
  10013. if (!end) {
  10014. return;
  10015. }
  10016. let adjustTop = evt.target !== div;
  10017. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  10018. if (adjustTop) {
  10019. const divBounds = div.getBoundingClientRect();
  10020. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  10021. end.style.top = (r * 100).toFixed(2) + "%";
  10022. }
  10023. end.classList.add("active");
  10024. });
  10025. div.addEventListener("mouseup", () => {
  10026. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10027. expandDivsTimer = setTimeout(() => {
  10028. if (this.textLayerRenderTask) {
  10029. this.textLayerRenderTask.expandTextDivs(false);
  10030. }
  10031. expandDivsTimer = null;
  10032. }, EXPAND_DIVS_TIMEOUT);
  10033. return;
  10034. }
  10035. const end = div.querySelector(".endOfContent");
  10036. if (!end) {
  10037. return;
  10038. }
  10039. end.style.top = "";
  10040. end.classList.remove("active");
  10041. });
  10042. }
  10043. }
  10044. exports.TextLayerBuilder = TextLayerBuilder;
  10045. class DefaultTextLayerFactory {
  10046. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  10047. return new TextLayerBuilder({
  10048. textLayerDiv,
  10049. pageIndex,
  10050. viewport,
  10051. enhanceTextSelection,
  10052. eventBus
  10053. });
  10054. }
  10055. }
  10056. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  10057. /***/ }),
  10058. /* 34 */
  10059. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10060. Object.defineProperty(exports, "__esModule", ({
  10061. value: true
  10062. }));
  10063. exports.XfaLayerBuilder = exports.DefaultXfaLayerFactory = void 0;
  10064. var _pdfjsLib = __webpack_require__(5);
  10065. class XfaLayerBuilder {
  10066. constructor({
  10067. pageDiv,
  10068. pdfPage,
  10069. annotationStorage
  10070. }) {
  10071. this.pageDiv = pageDiv;
  10072. this.pdfPage = pdfPage;
  10073. this.annotationStorage = annotationStorage;
  10074. this.div = null;
  10075. this._cancelled = false;
  10076. }
  10077. render(viewport, intent = "display") {
  10078. return this.pdfPage.getXfa().then(xfa => {
  10079. if (this._cancelled) {
  10080. return;
  10081. }
  10082. const parameters = {
  10083. viewport: viewport.clone({
  10084. dontFlip: true
  10085. }),
  10086. div: this.div,
  10087. xfa,
  10088. page: this.pdfPage,
  10089. annotationStorage: this.annotationStorage
  10090. };
  10091. if (this.div) {
  10092. _pdfjsLib.XfaLayer.update(parameters);
  10093. } else {
  10094. this.div = document.createElement("div");
  10095. this.pageDiv.appendChild(this.div);
  10096. parameters.div = this.div;
  10097. _pdfjsLib.XfaLayer.render(parameters);
  10098. }
  10099. }).catch(error => {
  10100. console.error(error);
  10101. });
  10102. }
  10103. cancel() {
  10104. this._cancelled = true;
  10105. }
  10106. hide() {
  10107. if (!this.div) {
  10108. return;
  10109. }
  10110. this.div.hidden = true;
  10111. }
  10112. }
  10113. exports.XfaLayerBuilder = XfaLayerBuilder;
  10114. class DefaultXfaLayerFactory {
  10115. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null) {
  10116. return new XfaLayerBuilder({
  10117. pageDiv,
  10118. pdfPage,
  10119. annotationStorage
  10120. });
  10121. }
  10122. }
  10123. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;
  10124. /***/ }),
  10125. /* 35 */
  10126. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10127. Object.defineProperty(exports, "__esModule", ({
  10128. value: true
  10129. }));
  10130. exports.SecondaryToolbar = void 0;
  10131. var _ui_utils = __webpack_require__(4);
  10132. var _pdf_cursor_tools = __webpack_require__(6);
  10133. var _pdf_single_page_viewer = __webpack_require__(36);
  10134. class SecondaryToolbar {
  10135. constructor(options, mainContainer, eventBus) {
  10136. this.toolbar = options.toolbar;
  10137. this.toggleButton = options.toggleButton;
  10138. this.toolbarButtonContainer = options.toolbarButtonContainer;
  10139. this.buttons = [{
  10140. element: options.presentationModeButton,
  10141. eventName: "presentationmode",
  10142. close: true
  10143. }, {
  10144. element: options.openFileButton,
  10145. eventName: "openfile",
  10146. close: true
  10147. }, {
  10148. element: options.printButton,
  10149. eventName: "print",
  10150. close: true
  10151. }, {
  10152. element: options.downloadButton,
  10153. eventName: "download",
  10154. close: true
  10155. }, {
  10156. element: options.viewBookmarkButton,
  10157. eventName: null,
  10158. close: true
  10159. }, {
  10160. element: options.firstPageButton,
  10161. eventName: "firstpage",
  10162. close: true
  10163. }, {
  10164. element: options.lastPageButton,
  10165. eventName: "lastpage",
  10166. close: true
  10167. }, {
  10168. element: options.pageRotateCwButton,
  10169. eventName: "rotatecw",
  10170. close: false
  10171. }, {
  10172. element: options.pageRotateCcwButton,
  10173. eventName: "rotateccw",
  10174. close: false
  10175. }, {
  10176. element: options.cursorSelectToolButton,
  10177. eventName: "switchcursortool",
  10178. eventDetails: {
  10179. tool: _pdf_cursor_tools.CursorTool.SELECT
  10180. },
  10181. close: true
  10182. }, {
  10183. element: options.cursorHandToolButton,
  10184. eventName: "switchcursortool",
  10185. eventDetails: {
  10186. tool: _pdf_cursor_tools.CursorTool.HAND
  10187. },
  10188. close: true
  10189. }, {
  10190. element: options.scrollVerticalButton,
  10191. eventName: "switchscrollmode",
  10192. eventDetails: {
  10193. mode: _ui_utils.ScrollMode.VERTICAL
  10194. },
  10195. close: true
  10196. }, {
  10197. element: options.scrollHorizontalButton,
  10198. eventName: "switchscrollmode",
  10199. eventDetails: {
  10200. mode: _ui_utils.ScrollMode.HORIZONTAL
  10201. },
  10202. close: true
  10203. }, {
  10204. element: options.scrollWrappedButton,
  10205. eventName: "switchscrollmode",
  10206. eventDetails: {
  10207. mode: _ui_utils.ScrollMode.WRAPPED
  10208. },
  10209. close: true
  10210. }, {
  10211. element: options.spreadNoneButton,
  10212. eventName: "switchspreadmode",
  10213. eventDetails: {
  10214. mode: _ui_utils.SpreadMode.NONE
  10215. },
  10216. close: true
  10217. }, {
  10218. element: options.spreadOddButton,
  10219. eventName: "switchspreadmode",
  10220. eventDetails: {
  10221. mode: _ui_utils.SpreadMode.ODD
  10222. },
  10223. close: true
  10224. }, {
  10225. element: options.spreadEvenButton,
  10226. eventName: "switchspreadmode",
  10227. eventDetails: {
  10228. mode: _ui_utils.SpreadMode.EVEN
  10229. },
  10230. close: true
  10231. }, {
  10232. element: options.documentPropertiesButton,
  10233. eventName: "documentproperties",
  10234. close: true
  10235. }];
  10236. this.items = {
  10237. firstPage: options.firstPageButton,
  10238. lastPage: options.lastPageButton,
  10239. pageRotateCw: options.pageRotateCwButton,
  10240. pageRotateCcw: options.pageRotateCcwButton
  10241. };
  10242. this.mainContainer = mainContainer;
  10243. this.eventBus = eventBus;
  10244. this.opened = false;
  10245. this.containerHeight = null;
  10246. this.previousContainerHeight = null;
  10247. this.reset();
  10248. this._bindClickListeners();
  10249. this._bindCursorToolsListener(options);
  10250. this._bindScrollModeListener(options);
  10251. this._bindSpreadModeListener(options);
  10252. this.eventBus._on("resize", this._setMaxHeight.bind(this));
  10253. this.eventBus._on("baseviewerinit", evt => {
  10254. if (evt.source instanceof _pdf_single_page_viewer.PDFSinglePageViewer) {
  10255. this.toolbarButtonContainer.classList.add("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  10256. } else {
  10257. this.toolbarButtonContainer.classList.remove("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  10258. }
  10259. });
  10260. }
  10261. get isOpen() {
  10262. return this.opened;
  10263. }
  10264. setPageNumber(pageNumber) {
  10265. this.pageNumber = pageNumber;
  10266. this._updateUIState();
  10267. }
  10268. setPagesCount(pagesCount) {
  10269. this.pagesCount = pagesCount;
  10270. this._updateUIState();
  10271. }
  10272. reset() {
  10273. this.pageNumber = 0;
  10274. this.pagesCount = 0;
  10275. this._updateUIState();
  10276. this.eventBus.dispatch("secondarytoolbarreset", {
  10277. source: this
  10278. });
  10279. }
  10280. _updateUIState() {
  10281. this.items.firstPage.disabled = this.pageNumber <= 1;
  10282. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  10283. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  10284. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  10285. }
  10286. _bindClickListeners() {
  10287. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  10288. for (const {
  10289. element,
  10290. eventName,
  10291. close,
  10292. eventDetails
  10293. } of this.buttons) {
  10294. element.addEventListener("click", evt => {
  10295. if (eventName !== null) {
  10296. const details = {
  10297. source: this
  10298. };
  10299. for (const property in eventDetails) {
  10300. details[property] = eventDetails[property];
  10301. }
  10302. this.eventBus.dispatch(eventName, details);
  10303. }
  10304. if (close) {
  10305. this.close();
  10306. }
  10307. });
  10308. }
  10309. }
  10310. _bindCursorToolsListener(buttons) {
  10311. this.eventBus._on("cursortoolchanged", function ({
  10312. tool
  10313. }) {
  10314. buttons.cursorSelectToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.SELECT);
  10315. buttons.cursorHandToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.HAND);
  10316. });
  10317. }
  10318. _bindScrollModeListener(buttons) {
  10319. function scrollModeChanged({
  10320. mode
  10321. }) {
  10322. buttons.scrollVerticalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.VERTICAL);
  10323. buttons.scrollHorizontalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.HORIZONTAL);
  10324. buttons.scrollWrappedButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.WRAPPED);
  10325. const isScrollModeHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  10326. buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
  10327. buttons.spreadOddButton.disabled = isScrollModeHorizontal;
  10328. buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
  10329. }
  10330. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  10331. this.eventBus._on("secondarytoolbarreset", evt => {
  10332. if (evt.source === this) {
  10333. scrollModeChanged({
  10334. mode: _ui_utils.ScrollMode.VERTICAL
  10335. });
  10336. }
  10337. });
  10338. }
  10339. _bindSpreadModeListener(buttons) {
  10340. function spreadModeChanged({
  10341. mode
  10342. }) {
  10343. buttons.spreadNoneButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.NONE);
  10344. buttons.spreadOddButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.ODD);
  10345. buttons.spreadEvenButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.EVEN);
  10346. }
  10347. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  10348. this.eventBus._on("secondarytoolbarreset", evt => {
  10349. if (evt.source === this) {
  10350. spreadModeChanged({
  10351. mode: _ui_utils.SpreadMode.NONE
  10352. });
  10353. }
  10354. });
  10355. }
  10356. open() {
  10357. if (this.opened) {
  10358. return;
  10359. }
  10360. this.opened = true;
  10361. this._setMaxHeight();
  10362. this.toggleButton.classList.add("toggled");
  10363. this.toggleButton.setAttribute("aria-expanded", "true");
  10364. this.toolbar.classList.remove("hidden");
  10365. }
  10366. close() {
  10367. if (!this.opened) {
  10368. return;
  10369. }
  10370. this.opened = false;
  10371. this.toolbar.classList.add("hidden");
  10372. this.toggleButton.classList.remove("toggled");
  10373. this.toggleButton.setAttribute("aria-expanded", "false");
  10374. }
  10375. toggle() {
  10376. if (this.opened) {
  10377. this.close();
  10378. } else {
  10379. this.open();
  10380. }
  10381. }
  10382. _setMaxHeight() {
  10383. if (!this.opened) {
  10384. return;
  10385. }
  10386. this.containerHeight = this.mainContainer.clientHeight;
  10387. if (this.containerHeight === this.previousContainerHeight) {
  10388. return;
  10389. }
  10390. this.toolbarButtonContainer.style.maxHeight = `${this.containerHeight - _ui_utils.SCROLLBAR_PADDING}px`;
  10391. this.previousContainerHeight = this.containerHeight;
  10392. }
  10393. }
  10394. exports.SecondaryToolbar = SecondaryToolbar;
  10395. /***/ }),
  10396. /* 36 */
  10397. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10398. Object.defineProperty(exports, "__esModule", ({
  10399. value: true
  10400. }));
  10401. exports.PDFSinglePageViewer = void 0;
  10402. var _base_viewer = __webpack_require__(28);
  10403. var _pdfjsLib = __webpack_require__(5);
  10404. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  10405. constructor(options) {
  10406. super(options);
  10407. this.eventBus._on("pagesinit", evt => {
  10408. this._ensurePageViewVisible();
  10409. });
  10410. }
  10411. get _viewerElement() {
  10412. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this._shadowViewer);
  10413. }
  10414. get _pageWidthScaleFactor() {
  10415. return 1;
  10416. }
  10417. _resetView() {
  10418. super._resetView();
  10419. this._previousPageNumber = 1;
  10420. this._shadowViewer = document.createDocumentFragment();
  10421. this._updateScrollDown = null;
  10422. }
  10423. _ensurePageViewVisible() {
  10424. const pageView = this._pages[this._currentPageNumber - 1];
  10425. const previousPageView = this._pages[this._previousPageNumber - 1];
  10426. const viewerNodes = this.viewer.childNodes;
  10427. switch (viewerNodes.length) {
  10428. case 0:
  10429. this.viewer.appendChild(pageView.div);
  10430. break;
  10431. case 1:
  10432. if (viewerNodes[0] !== previousPageView.div) {
  10433. throw new Error("_ensurePageViewVisible: Unexpected previously visible page.");
  10434. }
  10435. if (pageView === previousPageView) {
  10436. break;
  10437. }
  10438. this._shadowViewer.appendChild(previousPageView.div);
  10439. this.viewer.appendChild(pageView.div);
  10440. this.container.scrollTop = 0;
  10441. break;
  10442. default:
  10443. throw new Error("_ensurePageViewVisible: Only one page should be visible at a time.");
  10444. }
  10445. this._previousPageNumber = this._currentPageNumber;
  10446. }
  10447. _scrollUpdate() {
  10448. if (this._updateScrollDown) {
  10449. this._updateScrollDown();
  10450. }
  10451. super._scrollUpdate();
  10452. }
  10453. _scrollIntoView({
  10454. pageDiv,
  10455. pageSpot = null,
  10456. pageNumber = null
  10457. }) {
  10458. if (pageNumber) {
  10459. this._setCurrentPageNumber(pageNumber);
  10460. }
  10461. const scrolledDown = this._currentPageNumber >= this._previousPageNumber;
  10462. this._ensurePageViewVisible();
  10463. this.update();
  10464. super._scrollIntoView({
  10465. pageDiv,
  10466. pageSpot,
  10467. pageNumber
  10468. });
  10469. this._updateScrollDown = () => {
  10470. this.scroll.down = scrolledDown;
  10471. this._updateScrollDown = null;
  10472. };
  10473. }
  10474. _getVisiblePages() {
  10475. return this._getCurrentVisiblePage();
  10476. }
  10477. _updateHelper(visiblePages) {}
  10478. get _isScrollModeHorizontal() {
  10479. return (0, _pdfjsLib.shadow)(this, "_isScrollModeHorizontal", false);
  10480. }
  10481. _updateScrollMode() {}
  10482. _updateSpreadMode() {}
  10483. _getPageAdvance() {
  10484. return 1;
  10485. }
  10486. }
  10487. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  10488. /***/ }),
  10489. /* 37 */
  10490. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10491. Object.defineProperty(exports, "__esModule", ({
  10492. value: true
  10493. }));
  10494. exports.Toolbar = void 0;
  10495. var _ui_utils = __webpack_require__(4);
  10496. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  10497. const SCALE_SELECT_CONTAINER_WIDTH = 140;
  10498. const SCALE_SELECT_WIDTH = 162;
  10499. class Toolbar {
  10500. constructor(options, eventBus, l10n) {
  10501. this.toolbar = options.container;
  10502. this.eventBus = eventBus;
  10503. this.l10n = l10n;
  10504. this.buttons = [{
  10505. element: options.previous,
  10506. eventName: "previouspage"
  10507. }, {
  10508. element: options.next,
  10509. eventName: "nextpage"
  10510. }, {
  10511. element: options.zoomIn,
  10512. eventName: "zoomin"
  10513. }, {
  10514. element: options.zoomOut,
  10515. eventName: "zoomout"
  10516. }, {
  10517. element: options.openFile,
  10518. eventName: "openfile"
  10519. }, {
  10520. element: options.print,
  10521. eventName: "print"
  10522. }, {
  10523. element: options.presentationModeButton,
  10524. eventName: "presentationmode"
  10525. }, {
  10526. element: options.download,
  10527. eventName: "download"
  10528. }, {
  10529. element: options.viewBookmark,
  10530. eventName: null
  10531. }];
  10532. this.items = {
  10533. numPages: options.numPages,
  10534. pageNumber: options.pageNumber,
  10535. scaleSelectContainer: options.scaleSelectContainer,
  10536. scaleSelect: options.scaleSelect,
  10537. customScaleOption: options.customScaleOption,
  10538. previous: options.previous,
  10539. next: options.next,
  10540. zoomIn: options.zoomIn,
  10541. zoomOut: options.zoomOut
  10542. };
  10543. this._wasLocalized = false;
  10544. this.reset();
  10545. this._bindListeners();
  10546. }
  10547. setPageNumber(pageNumber, pageLabel) {
  10548. this.pageNumber = pageNumber;
  10549. this.pageLabel = pageLabel;
  10550. this._updateUIState(false);
  10551. }
  10552. setPagesCount(pagesCount, hasPageLabels) {
  10553. this.pagesCount = pagesCount;
  10554. this.hasPageLabels = hasPageLabels;
  10555. this._updateUIState(true);
  10556. }
  10557. setPageScale(pageScaleValue, pageScale) {
  10558. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  10559. this.pageScale = pageScale;
  10560. this._updateUIState(false);
  10561. }
  10562. reset() {
  10563. this.pageNumber = 0;
  10564. this.pageLabel = null;
  10565. this.hasPageLabels = false;
  10566. this.pagesCount = 0;
  10567. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  10568. this.pageScale = _ui_utils.DEFAULT_SCALE;
  10569. this._updateUIState(true);
  10570. this.updateLoadingIndicatorState();
  10571. }
  10572. _bindListeners() {
  10573. const {
  10574. pageNumber,
  10575. scaleSelect
  10576. } = this.items;
  10577. const self = this;
  10578. for (const {
  10579. element,
  10580. eventName
  10581. } of this.buttons) {
  10582. element.addEventListener("click", evt => {
  10583. if (eventName !== null) {
  10584. this.eventBus.dispatch(eventName, {
  10585. source: this
  10586. });
  10587. }
  10588. });
  10589. }
  10590. pageNumber.addEventListener("click", function () {
  10591. this.select();
  10592. });
  10593. pageNumber.addEventListener("change", function () {
  10594. self.eventBus.dispatch("pagenumberchanged", {
  10595. source: self,
  10596. value: this.value
  10597. });
  10598. });
  10599. scaleSelect.addEventListener("change", function () {
  10600. if (this.value === "custom") {
  10601. return;
  10602. }
  10603. self.eventBus.dispatch("scalechanged", {
  10604. source: self,
  10605. value: this.value
  10606. });
  10607. });
  10608. scaleSelect.addEventListener("click", function (evt) {
  10609. const target = evt.target;
  10610. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  10611. this.blur();
  10612. }
  10613. });
  10614. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  10615. this.eventBus._on("localized", () => {
  10616. this._wasLocalized = true;
  10617. this._adjustScaleWidth();
  10618. this._updateUIState(true);
  10619. });
  10620. }
  10621. _updateUIState(resetNumPages = false) {
  10622. if (!this._wasLocalized) {
  10623. return;
  10624. }
  10625. const {
  10626. pageNumber,
  10627. pagesCount,
  10628. pageScaleValue,
  10629. pageScale,
  10630. items
  10631. } = this;
  10632. if (resetNumPages) {
  10633. if (this.hasPageLabels) {
  10634. items.pageNumber.type = "text";
  10635. } else {
  10636. items.pageNumber.type = "number";
  10637. this.l10n.get("of_pages", {
  10638. pagesCount
  10639. }).then(msg => {
  10640. items.numPages.textContent = msg;
  10641. });
  10642. }
  10643. items.pageNumber.max = pagesCount;
  10644. }
  10645. if (this.hasPageLabels) {
  10646. items.pageNumber.value = this.pageLabel;
  10647. this.l10n.get("page_of_pages", {
  10648. pageNumber,
  10649. pagesCount
  10650. }).then(msg => {
  10651. items.numPages.textContent = msg;
  10652. });
  10653. } else {
  10654. items.pageNumber.value = pageNumber;
  10655. }
  10656. items.previous.disabled = pageNumber <= 1;
  10657. items.next.disabled = pageNumber >= pagesCount;
  10658. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  10659. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  10660. this.l10n.get("page_scale_percent", {
  10661. scale: Math.round(pageScale * 10000) / 100
  10662. }).then(msg => {
  10663. let predefinedValueFound = false;
  10664. for (const option of items.scaleSelect.options) {
  10665. if (option.value !== pageScaleValue) {
  10666. option.selected = false;
  10667. continue;
  10668. }
  10669. option.selected = true;
  10670. predefinedValueFound = true;
  10671. }
  10672. if (!predefinedValueFound) {
  10673. items.customScaleOption.textContent = msg;
  10674. items.customScaleOption.selected = true;
  10675. }
  10676. });
  10677. }
  10678. updateLoadingIndicatorState(loading = false) {
  10679. const pageNumberInput = this.items.pageNumber;
  10680. pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  10681. }
  10682. async _adjustScaleWidth() {
  10683. const {
  10684. items,
  10685. l10n
  10686. } = this;
  10687. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  10688. let canvas = document.createElement("canvas");
  10689. canvas.mozOpaque = true;
  10690. let ctx = canvas.getContext("2d", {
  10691. alpha: false
  10692. });
  10693. await _ui_utils.animationStarted;
  10694. const {
  10695. fontSize,
  10696. fontFamily
  10697. } = getComputedStyle(items.scaleSelect);
  10698. ctx.font = `${fontSize} ${fontFamily}`;
  10699. let maxWidth = 0;
  10700. for (const predefinedValue of await predefinedValuesPromise) {
  10701. const {
  10702. width
  10703. } = ctx.measureText(predefinedValue);
  10704. if (width > maxWidth) {
  10705. maxWidth = width;
  10706. }
  10707. }
  10708. const overflow = SCALE_SELECT_WIDTH - SCALE_SELECT_CONTAINER_WIDTH;
  10709. maxWidth += 2 * overflow;
  10710. if (maxWidth > SCALE_SELECT_CONTAINER_WIDTH) {
  10711. items.scaleSelect.style.width = `${maxWidth + overflow}px`;
  10712. items.scaleSelectContainer.style.width = `${maxWidth}px`;
  10713. }
  10714. canvas.width = 0;
  10715. canvas.height = 0;
  10716. canvas = ctx = null;
  10717. }
  10718. }
  10719. exports.Toolbar = Toolbar;
  10720. /***/ }),
  10721. /* 38 */
  10722. /***/ ((__unused_webpack_module, exports) => {
  10723. Object.defineProperty(exports, "__esModule", ({
  10724. value: true
  10725. }));
  10726. exports.ViewHistory = void 0;
  10727. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  10728. class ViewHistory {
  10729. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  10730. this.fingerprint = fingerprint;
  10731. this.cacheSize = cacheSize;
  10732. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  10733. const database = JSON.parse(databaseStr || "{}");
  10734. let index = -1;
  10735. if (!Array.isArray(database.files)) {
  10736. database.files = [];
  10737. } else {
  10738. while (database.files.length >= this.cacheSize) {
  10739. database.files.shift();
  10740. }
  10741. for (let i = 0, ii = database.files.length; i < ii; i++) {
  10742. const branch = database.files[i];
  10743. if (branch.fingerprint === this.fingerprint) {
  10744. index = i;
  10745. break;
  10746. }
  10747. }
  10748. }
  10749. if (index === -1) {
  10750. index = database.files.push({
  10751. fingerprint: this.fingerprint
  10752. }) - 1;
  10753. }
  10754. this.file = database.files[index];
  10755. this.database = database;
  10756. });
  10757. }
  10758. async _writeToStorage() {
  10759. const databaseStr = JSON.stringify(this.database);
  10760. localStorage.setItem("pdfjs.history", databaseStr);
  10761. }
  10762. async _readFromStorage() {
  10763. return localStorage.getItem("pdfjs.history");
  10764. }
  10765. async set(name, val) {
  10766. await this._initializedPromise;
  10767. this.file[name] = val;
  10768. return this._writeToStorage();
  10769. }
  10770. async setMultiple(properties) {
  10771. await this._initializedPromise;
  10772. for (const name in properties) {
  10773. this.file[name] = properties[name];
  10774. }
  10775. return this._writeToStorage();
  10776. }
  10777. async get(name, defaultValue) {
  10778. await this._initializedPromise;
  10779. const val = this.file[name];
  10780. return val !== undefined ? val : defaultValue;
  10781. }
  10782. async getMultiple(properties) {
  10783. await this._initializedPromise;
  10784. const values = Object.create(null);
  10785. for (const name in properties) {
  10786. const val = this.file[name];
  10787. values[name] = val !== undefined ? val : properties[name];
  10788. }
  10789. return values;
  10790. }
  10791. }
  10792. exports.ViewHistory = ViewHistory;
  10793. /***/ }),
  10794. /* 39 */
  10795. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10796. Object.defineProperty(exports, "__esModule", ({
  10797. value: true
  10798. }));
  10799. exports.GenericCom = void 0;
  10800. var _app = __webpack_require__(3);
  10801. var _preferences = __webpack_require__(40);
  10802. var _download_manager = __webpack_require__(41);
  10803. var _genericl10n = __webpack_require__(42);
  10804. var _generic_scripting = __webpack_require__(44);
  10805. ;
  10806. const GenericCom = {};
  10807. exports.GenericCom = GenericCom;
  10808. class GenericPreferences extends _preferences.BasePreferences {
  10809. async _writeToStorage(prefObj) {
  10810. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  10811. }
  10812. async _readFromStorage(prefObj) {
  10813. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  10814. }
  10815. }
  10816. class GenericExternalServices extends _app.DefaultExternalServices {
  10817. static createDownloadManager(options) {
  10818. return new _download_manager.DownloadManager();
  10819. }
  10820. static createPreferences() {
  10821. return new GenericPreferences();
  10822. }
  10823. static createL10n({
  10824. locale = "en-US"
  10825. }) {
  10826. return new _genericl10n.GenericL10n(locale);
  10827. }
  10828. static createScripting({
  10829. sandboxBundleSrc
  10830. }) {
  10831. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  10832. }
  10833. }
  10834. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  10835. /***/ }),
  10836. /* 40 */
  10837. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10838. Object.defineProperty(exports, "__esModule", ({
  10839. value: true
  10840. }));
  10841. exports.BasePreferences = void 0;
  10842. var _app_options = __webpack_require__(1);
  10843. class BasePreferences {
  10844. constructor() {
  10845. if (this.constructor === BasePreferences) {
  10846. throw new Error("Cannot initialize BasePreferences.");
  10847. }
  10848. Object.defineProperty(this, "defaults", {
  10849. value: Object.freeze({
  10850. "cursorToolOnLoad": 0,
  10851. "defaultZoomValue": "",
  10852. "disablePageLabels": false,
  10853. "enablePermissions": false,
  10854. "enablePrintAutoRotate": true,
  10855. "enableScripting": true,
  10856. "externalLinkTarget": 0,
  10857. "historyUpdateUrl": false,
  10858. "ignoreDestinationZoom": false,
  10859. "pdfBugEnabled": false,
  10860. "renderer": "canvas",
  10861. "renderInteractiveForms": true,
  10862. "sidebarViewOnLoad": -1,
  10863. "scrollModeOnLoad": -1,
  10864. "spreadModeOnLoad": -1,
  10865. "textLayerMode": 1,
  10866. "useOnlyCssZoom": false,
  10867. "viewerCssTheme": 0,
  10868. "viewOnLoad": 0,
  10869. "disableAutoFetch": false,
  10870. "disableFontFace": false,
  10871. "disableRange": false,
  10872. "disableStream": false,
  10873. "enableXfa": false
  10874. }),
  10875. writable: false,
  10876. enumerable: true,
  10877. configurable: false
  10878. });
  10879. this.prefs = Object.create(null);
  10880. this._initializedPromise = this._readFromStorage(this.defaults).then(prefs => {
  10881. for (const name in this.defaults) {
  10882. const prefValue = prefs?.[name];
  10883. if (typeof prefValue === typeof this.defaults[name]) {
  10884. this.prefs[name] = prefValue;
  10885. }
  10886. }
  10887. });
  10888. }
  10889. async _writeToStorage(prefObj) {
  10890. throw new Error("Not implemented: _writeToStorage");
  10891. }
  10892. async _readFromStorage(prefObj) {
  10893. throw new Error("Not implemented: _readFromStorage");
  10894. }
  10895. async reset() {
  10896. await this._initializedPromise;
  10897. this.prefs = Object.create(null);
  10898. return this._writeToStorage(this.defaults);
  10899. }
  10900. async set(name, value) {
  10901. await this._initializedPromise;
  10902. const defaultValue = this.defaults[name];
  10903. if (defaultValue === undefined) {
  10904. throw new Error(`Set preference: "${name}" is undefined.`);
  10905. } else if (value === undefined) {
  10906. throw new Error("Set preference: no value is specified.");
  10907. }
  10908. const valueType = typeof value;
  10909. const defaultType = typeof defaultValue;
  10910. if (valueType !== defaultType) {
  10911. if (valueType === "number" && defaultType === "string") {
  10912. value = value.toString();
  10913. } else {
  10914. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  10915. }
  10916. } else {
  10917. if (valueType === "number" && !Number.isInteger(value)) {
  10918. throw new Error(`Set preference: "${value}" must be an integer.`);
  10919. }
  10920. }
  10921. this.prefs[name] = value;
  10922. return this._writeToStorage(this.prefs);
  10923. }
  10924. async get(name) {
  10925. await this._initializedPromise;
  10926. const defaultValue = this.defaults[name],
  10927. prefValue = this.prefs[name];
  10928. if (defaultValue === undefined) {
  10929. throw new Error(`Get preference: "${name}" is undefined.`);
  10930. }
  10931. return prefValue !== undefined ? prefValue : defaultValue;
  10932. }
  10933. async getAll() {
  10934. await this._initializedPromise;
  10935. const obj = Object.create(null);
  10936. for (const name in this.defaults) {
  10937. const prefValue = this.prefs[name];
  10938. obj[name] = prefValue !== undefined ? prefValue : this.defaults[name];
  10939. }
  10940. return obj;
  10941. }
  10942. }
  10943. exports.BasePreferences = BasePreferences;
  10944. /***/ }),
  10945. /* 41 */
  10946. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10947. Object.defineProperty(exports, "__esModule", ({
  10948. value: true
  10949. }));
  10950. exports.DownloadManager = void 0;
  10951. var _pdfjsLib = __webpack_require__(5);
  10952. var _viewer_compatibility = __webpack_require__(2);
  10953. ;
  10954. function download(blobUrl, filename) {
  10955. const a = document.createElement("a");
  10956. if (!a.click) {
  10957. throw new Error('DownloadManager: "a.click()" is not supported.');
  10958. }
  10959. a.href = blobUrl;
  10960. a.target = "_parent";
  10961. if ("download" in a) {
  10962. a.download = filename;
  10963. }
  10964. (document.body || document.documentElement).appendChild(a);
  10965. a.click();
  10966. a.remove();
  10967. }
  10968. class DownloadManager {
  10969. constructor() {
  10970. this._openBlobUrls = new WeakMap();
  10971. }
  10972. downloadUrl(url, filename) {
  10973. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  10974. return;
  10975. }
  10976. download(url + "#pdfjs.action=download", filename);
  10977. }
  10978. downloadData(data, filename, contentType) {
  10979. const blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  10980. download(blobUrl, filename);
  10981. }
  10982. openOrDownloadData(element, data, filename) {
  10983. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  10984. const contentType = isPdfData ? "application/pdf" : "";
  10985. if (isPdfData && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  10986. let blobUrl = this._openBlobUrls.get(element);
  10987. if (!blobUrl) {
  10988. blobUrl = URL.createObjectURL(new Blob([data], {
  10989. type: contentType
  10990. }));
  10991. this._openBlobUrls.set(element, blobUrl);
  10992. }
  10993. let viewerUrl;
  10994. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  10995. try {
  10996. window.open(viewerUrl);
  10997. return true;
  10998. } catch (ex) {
  10999. console.error(`openOrDownloadData: ${ex}`);
  11000. URL.revokeObjectURL(blobUrl);
  11001. this._openBlobUrls.delete(element);
  11002. }
  11003. }
  11004. this.downloadData(data, filename, contentType);
  11005. return false;
  11006. }
  11007. download(blob, url, filename, sourceEventType = "download") {
  11008. if (_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  11009. this.downloadUrl(url, filename);
  11010. return;
  11011. }
  11012. const blobUrl = URL.createObjectURL(blob);
  11013. download(blobUrl, filename);
  11014. }
  11015. }
  11016. exports.DownloadManager = DownloadManager;
  11017. /***/ }),
  11018. /* 42 */
  11019. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11020. Object.defineProperty(exports, "__esModule", ({
  11021. value: true
  11022. }));
  11023. exports.GenericL10n = void 0;
  11024. __webpack_require__(43);
  11025. var _l10n_utils = __webpack_require__(30);
  11026. const webL10n = document.webL10n;
  11027. class GenericL10n {
  11028. constructor(lang) {
  11029. this._lang = lang;
  11030. this._ready = new Promise((resolve, reject) => {
  11031. webL10n.setLanguage(lang, () => {
  11032. resolve(webL10n);
  11033. });
  11034. });
  11035. }
  11036. async getLanguage() {
  11037. const l10n = await this._ready;
  11038. return l10n.getLanguage();
  11039. }
  11040. async getDirection() {
  11041. const l10n = await this._ready;
  11042. return l10n.getDirection();
  11043. }
  11044. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  11045. const l10n = await this._ready;
  11046. return l10n.get(key, args, fallback);
  11047. }
  11048. async translate(element) {
  11049. const l10n = await this._ready;
  11050. return l10n.translate(element);
  11051. }
  11052. }
  11053. exports.GenericL10n = GenericL10n;
  11054. /***/ }),
  11055. /* 43 */
  11056. /***/ (() => {
  11057. document.webL10n = function (window, document, undefined) {
  11058. var gL10nData = {};
  11059. var gTextData = '';
  11060. var gTextProp = 'textContent';
  11061. var gLanguage = '';
  11062. var gMacros = {};
  11063. var gReadyState = 'loading';
  11064. var gAsyncResourceLoading = true;
  11065. function getL10nResourceLinks() {
  11066. return document.querySelectorAll('link[type="application/l10n"]');
  11067. }
  11068. function getL10nDictionary() {
  11069. var script = document.querySelector('script[type="application/l10n"]');
  11070. return script ? JSON.parse(script.innerHTML) : null;
  11071. }
  11072. function getTranslatableChildren(element) {
  11073. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  11074. }
  11075. function getL10nAttributes(element) {
  11076. if (!element) return {};
  11077. var l10nId = element.getAttribute('data-l10n-id');
  11078. var l10nArgs = element.getAttribute('data-l10n-args');
  11079. var args = {};
  11080. if (l10nArgs) {
  11081. try {
  11082. args = JSON.parse(l10nArgs);
  11083. } catch (e) {
  11084. console.warn('could not parse arguments for #' + l10nId);
  11085. }
  11086. }
  11087. return {
  11088. id: l10nId,
  11089. args: args
  11090. };
  11091. }
  11092. function xhrLoadText(url, onSuccess, onFailure) {
  11093. onSuccess = onSuccess || function _onSuccess(data) {};
  11094. onFailure = onFailure || function _onFailure() {};
  11095. var xhr = new XMLHttpRequest();
  11096. xhr.open('GET', url, gAsyncResourceLoading);
  11097. if (xhr.overrideMimeType) {
  11098. xhr.overrideMimeType('text/plain; charset=utf-8');
  11099. }
  11100. xhr.onreadystatechange = function () {
  11101. if (xhr.readyState == 4) {
  11102. if (xhr.status == 200 || xhr.status === 0) {
  11103. onSuccess(xhr.responseText);
  11104. } else {
  11105. onFailure();
  11106. }
  11107. }
  11108. };
  11109. xhr.onerror = onFailure;
  11110. xhr.ontimeout = onFailure;
  11111. try {
  11112. xhr.send(null);
  11113. } catch (e) {
  11114. onFailure();
  11115. }
  11116. }
  11117. function parseResource(href, lang, successCallback, failureCallback) {
  11118. var baseURL = href.replace(/[^\/]*$/, '') || './';
  11119. function evalString(text) {
  11120. if (text.lastIndexOf('\\') < 0) return text;
  11121. 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, "'");
  11122. }
  11123. function parseProperties(text, parsedPropertiesCallback) {
  11124. var dictionary = {};
  11125. var reBlank = /^\s*|\s*$/;
  11126. var reComment = /^\s*#|^\s*$/;
  11127. var reSection = /^\s*\[(.*)\]\s*$/;
  11128. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  11129. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  11130. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  11131. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  11132. var currentLang = '*';
  11133. var genericLang = lang.split('-', 1)[0];
  11134. var skipLang = false;
  11135. var match = '';
  11136. function nextEntry() {
  11137. while (true) {
  11138. if (!entries.length) {
  11139. parsedRawLinesCallback();
  11140. return;
  11141. }
  11142. var line = entries.shift();
  11143. if (reComment.test(line)) continue;
  11144. if (extendedSyntax) {
  11145. match = reSection.exec(line);
  11146. if (match) {
  11147. currentLang = match[1].toLowerCase();
  11148. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  11149. continue;
  11150. } else if (skipLang) {
  11151. continue;
  11152. }
  11153. match = reImport.exec(line);
  11154. if (match) {
  11155. loadImport(baseURL + match[1], nextEntry);
  11156. return;
  11157. }
  11158. }
  11159. var tmp = line.match(reSplit);
  11160. if (tmp && tmp.length == 3) {
  11161. dictionary[tmp[1]] = evalString(tmp[2]);
  11162. }
  11163. }
  11164. }
  11165. nextEntry();
  11166. }
  11167. function loadImport(url, callback) {
  11168. xhrLoadText(url, function (content) {
  11169. parseRawLines(content, false, callback);
  11170. }, function () {
  11171. console.warn(url + ' not found.');
  11172. callback();
  11173. });
  11174. }
  11175. parseRawLines(text, true, function () {
  11176. parsedPropertiesCallback(dictionary);
  11177. });
  11178. }
  11179. xhrLoadText(href, function (response) {
  11180. gTextData += response;
  11181. parseProperties(response, function (data) {
  11182. for (var key in data) {
  11183. var id,
  11184. prop,
  11185. index = key.lastIndexOf('.');
  11186. if (index > 0) {
  11187. id = key.substring(0, index);
  11188. prop = key.substring(index + 1);
  11189. } else {
  11190. id = key;
  11191. prop = gTextProp;
  11192. }
  11193. if (!gL10nData[id]) {
  11194. gL10nData[id] = {};
  11195. }
  11196. gL10nData[id][prop] = data[key];
  11197. }
  11198. if (successCallback) {
  11199. successCallback();
  11200. }
  11201. });
  11202. }, failureCallback);
  11203. }
  11204. function loadLocale(lang, callback) {
  11205. if (lang) {
  11206. lang = lang.toLowerCase();
  11207. }
  11208. callback = callback || function _callback() {};
  11209. clear();
  11210. gLanguage = lang;
  11211. var langLinks = getL10nResourceLinks();
  11212. var langCount = langLinks.length;
  11213. if (langCount === 0) {
  11214. var dict = getL10nDictionary();
  11215. if (dict && dict.locales && dict.default_locale) {
  11216. console.log('using the embedded JSON directory, early way out');
  11217. gL10nData = dict.locales[lang];
  11218. if (!gL10nData) {
  11219. var defaultLocale = dict.default_locale.toLowerCase();
  11220. for (var anyCaseLang in dict.locales) {
  11221. anyCaseLang = anyCaseLang.toLowerCase();
  11222. if (anyCaseLang === lang) {
  11223. gL10nData = dict.locales[lang];
  11224. break;
  11225. } else if (anyCaseLang === defaultLocale) {
  11226. gL10nData = dict.locales[defaultLocale];
  11227. }
  11228. }
  11229. }
  11230. callback();
  11231. } else {
  11232. console.log('no resource to load, early way out');
  11233. }
  11234. gReadyState = 'complete';
  11235. return;
  11236. }
  11237. var onResourceLoaded = null;
  11238. var gResourceCount = 0;
  11239. onResourceLoaded = function () {
  11240. gResourceCount++;
  11241. if (gResourceCount >= langCount) {
  11242. callback();
  11243. gReadyState = 'complete';
  11244. }
  11245. };
  11246. function L10nResourceLink(link) {
  11247. var href = link.href;
  11248. this.load = function (lang, callback) {
  11249. parseResource(href, lang, callback, function () {
  11250. console.warn(href + ' not found.');
  11251. console.warn('"' + lang + '" resource not found');
  11252. gLanguage = '';
  11253. callback();
  11254. });
  11255. };
  11256. }
  11257. for (var i = 0; i < langCount; i++) {
  11258. var resource = new L10nResourceLink(langLinks[i]);
  11259. resource.load(lang, onResourceLoaded);
  11260. }
  11261. }
  11262. function clear() {
  11263. gL10nData = {};
  11264. gTextData = '';
  11265. gLanguage = '';
  11266. }
  11267. function getPluralRules(lang) {
  11268. var locales2rules = {
  11269. 'af': 3,
  11270. 'ak': 4,
  11271. 'am': 4,
  11272. 'ar': 1,
  11273. 'asa': 3,
  11274. 'az': 0,
  11275. 'be': 11,
  11276. 'bem': 3,
  11277. 'bez': 3,
  11278. 'bg': 3,
  11279. 'bh': 4,
  11280. 'bm': 0,
  11281. 'bn': 3,
  11282. 'bo': 0,
  11283. 'br': 20,
  11284. 'brx': 3,
  11285. 'bs': 11,
  11286. 'ca': 3,
  11287. 'cgg': 3,
  11288. 'chr': 3,
  11289. 'cs': 12,
  11290. 'cy': 17,
  11291. 'da': 3,
  11292. 'de': 3,
  11293. 'dv': 3,
  11294. 'dz': 0,
  11295. 'ee': 3,
  11296. 'el': 3,
  11297. 'en': 3,
  11298. 'eo': 3,
  11299. 'es': 3,
  11300. 'et': 3,
  11301. 'eu': 3,
  11302. 'fa': 0,
  11303. 'ff': 5,
  11304. 'fi': 3,
  11305. 'fil': 4,
  11306. 'fo': 3,
  11307. 'fr': 5,
  11308. 'fur': 3,
  11309. 'fy': 3,
  11310. 'ga': 8,
  11311. 'gd': 24,
  11312. 'gl': 3,
  11313. 'gsw': 3,
  11314. 'gu': 3,
  11315. 'guw': 4,
  11316. 'gv': 23,
  11317. 'ha': 3,
  11318. 'haw': 3,
  11319. 'he': 2,
  11320. 'hi': 4,
  11321. 'hr': 11,
  11322. 'hu': 0,
  11323. 'id': 0,
  11324. 'ig': 0,
  11325. 'ii': 0,
  11326. 'is': 3,
  11327. 'it': 3,
  11328. 'iu': 7,
  11329. 'ja': 0,
  11330. 'jmc': 3,
  11331. 'jv': 0,
  11332. 'ka': 0,
  11333. 'kab': 5,
  11334. 'kaj': 3,
  11335. 'kcg': 3,
  11336. 'kde': 0,
  11337. 'kea': 0,
  11338. 'kk': 3,
  11339. 'kl': 3,
  11340. 'km': 0,
  11341. 'kn': 0,
  11342. 'ko': 0,
  11343. 'ksb': 3,
  11344. 'ksh': 21,
  11345. 'ku': 3,
  11346. 'kw': 7,
  11347. 'lag': 18,
  11348. 'lb': 3,
  11349. 'lg': 3,
  11350. 'ln': 4,
  11351. 'lo': 0,
  11352. 'lt': 10,
  11353. 'lv': 6,
  11354. 'mas': 3,
  11355. 'mg': 4,
  11356. 'mk': 16,
  11357. 'ml': 3,
  11358. 'mn': 3,
  11359. 'mo': 9,
  11360. 'mr': 3,
  11361. 'ms': 0,
  11362. 'mt': 15,
  11363. 'my': 0,
  11364. 'nah': 3,
  11365. 'naq': 7,
  11366. 'nb': 3,
  11367. 'nd': 3,
  11368. 'ne': 3,
  11369. 'nl': 3,
  11370. 'nn': 3,
  11371. 'no': 3,
  11372. 'nr': 3,
  11373. 'nso': 4,
  11374. 'ny': 3,
  11375. 'nyn': 3,
  11376. 'om': 3,
  11377. 'or': 3,
  11378. 'pa': 3,
  11379. 'pap': 3,
  11380. 'pl': 13,
  11381. 'ps': 3,
  11382. 'pt': 3,
  11383. 'rm': 3,
  11384. 'ro': 9,
  11385. 'rof': 3,
  11386. 'ru': 11,
  11387. 'rwk': 3,
  11388. 'sah': 0,
  11389. 'saq': 3,
  11390. 'se': 7,
  11391. 'seh': 3,
  11392. 'ses': 0,
  11393. 'sg': 0,
  11394. 'sh': 11,
  11395. 'shi': 19,
  11396. 'sk': 12,
  11397. 'sl': 14,
  11398. 'sma': 7,
  11399. 'smi': 7,
  11400. 'smj': 7,
  11401. 'smn': 7,
  11402. 'sms': 7,
  11403. 'sn': 3,
  11404. 'so': 3,
  11405. 'sq': 3,
  11406. 'sr': 11,
  11407. 'ss': 3,
  11408. 'ssy': 3,
  11409. 'st': 3,
  11410. 'sv': 3,
  11411. 'sw': 3,
  11412. 'syr': 3,
  11413. 'ta': 3,
  11414. 'te': 3,
  11415. 'teo': 3,
  11416. 'th': 0,
  11417. 'ti': 4,
  11418. 'tig': 3,
  11419. 'tk': 3,
  11420. 'tl': 4,
  11421. 'tn': 3,
  11422. 'to': 0,
  11423. 'tr': 0,
  11424. 'ts': 3,
  11425. 'tzm': 22,
  11426. 'uk': 11,
  11427. 'ur': 3,
  11428. 've': 3,
  11429. 'vi': 0,
  11430. 'vun': 3,
  11431. 'wa': 4,
  11432. 'wae': 3,
  11433. 'wo': 0,
  11434. 'xh': 3,
  11435. 'xog': 3,
  11436. 'yo': 0,
  11437. 'zh': 0,
  11438. 'zu': 3
  11439. };
  11440. function isIn(n, list) {
  11441. return list.indexOf(n) !== -1;
  11442. }
  11443. function isBetween(n, start, end) {
  11444. return start <= n && n <= end;
  11445. }
  11446. var pluralRules = {
  11447. '0': function (n) {
  11448. return 'other';
  11449. },
  11450. '1': function (n) {
  11451. if (isBetween(n % 100, 3, 10)) return 'few';
  11452. if (n === 0) return 'zero';
  11453. if (isBetween(n % 100, 11, 99)) return 'many';
  11454. if (n == 2) return 'two';
  11455. if (n == 1) return 'one';
  11456. return 'other';
  11457. },
  11458. '2': function (n) {
  11459. if (n !== 0 && n % 10 === 0) return 'many';
  11460. if (n == 2) return 'two';
  11461. if (n == 1) return 'one';
  11462. return 'other';
  11463. },
  11464. '3': function (n) {
  11465. if (n == 1) return 'one';
  11466. return 'other';
  11467. },
  11468. '4': function (n) {
  11469. if (isBetween(n, 0, 1)) return 'one';
  11470. return 'other';
  11471. },
  11472. '5': function (n) {
  11473. if (isBetween(n, 0, 2) && n != 2) return 'one';
  11474. return 'other';
  11475. },
  11476. '6': function (n) {
  11477. if (n === 0) return 'zero';
  11478. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11479. return 'other';
  11480. },
  11481. '7': function (n) {
  11482. if (n == 2) return 'two';
  11483. if (n == 1) return 'one';
  11484. return 'other';
  11485. },
  11486. '8': function (n) {
  11487. if (isBetween(n, 3, 6)) return 'few';
  11488. if (isBetween(n, 7, 10)) return 'many';
  11489. if (n == 2) return 'two';
  11490. if (n == 1) return 'one';
  11491. return 'other';
  11492. },
  11493. '9': function (n) {
  11494. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  11495. if (n == 1) return 'one';
  11496. return 'other';
  11497. },
  11498. '10': function (n) {
  11499. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  11500. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  11501. return 'other';
  11502. },
  11503. '11': function (n) {
  11504. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11505. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  11506. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11507. return 'other';
  11508. },
  11509. '12': function (n) {
  11510. if (isBetween(n, 2, 4)) return 'few';
  11511. if (n == 1) return 'one';
  11512. return 'other';
  11513. },
  11514. '13': function (n) {
  11515. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11516. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  11517. if (n == 1) return 'one';
  11518. return 'other';
  11519. },
  11520. '14': function (n) {
  11521. if (isBetween(n % 100, 3, 4)) return 'few';
  11522. if (n % 100 == 2) return 'two';
  11523. if (n % 100 == 1) return 'one';
  11524. return 'other';
  11525. },
  11526. '15': function (n) {
  11527. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  11528. if (isBetween(n % 100, 11, 19)) return 'many';
  11529. if (n == 1) return 'one';
  11530. return 'other';
  11531. },
  11532. '16': function (n) {
  11533. if (n % 10 == 1 && n != 11) return 'one';
  11534. return 'other';
  11535. },
  11536. '17': function (n) {
  11537. if (n == 3) return 'few';
  11538. if (n === 0) return 'zero';
  11539. if (n == 6) return 'many';
  11540. if (n == 2) return 'two';
  11541. if (n == 1) return 'one';
  11542. return 'other';
  11543. },
  11544. '18': function (n) {
  11545. if (n === 0) return 'zero';
  11546. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  11547. return 'other';
  11548. },
  11549. '19': function (n) {
  11550. if (isBetween(n, 2, 10)) return 'few';
  11551. if (isBetween(n, 0, 1)) return 'one';
  11552. return 'other';
  11553. },
  11554. '20': function (n) {
  11555. 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';
  11556. if (n % 1000000 === 0 && n !== 0) return 'many';
  11557. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  11558. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  11559. return 'other';
  11560. },
  11561. '21': function (n) {
  11562. if (n === 0) return 'zero';
  11563. if (n == 1) return 'one';
  11564. return 'other';
  11565. },
  11566. '22': function (n) {
  11567. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  11568. return 'other';
  11569. },
  11570. '23': function (n) {
  11571. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  11572. return 'other';
  11573. },
  11574. '24': function (n) {
  11575. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  11576. if (isIn(n, [2, 12])) return 'two';
  11577. if (isIn(n, [1, 11])) return 'one';
  11578. return 'other';
  11579. }
  11580. };
  11581. var index = locales2rules[lang.replace(/-.*$/, '')];
  11582. if (!(index in pluralRules)) {
  11583. console.warn('plural form unknown for [' + lang + ']');
  11584. return function () {
  11585. return 'other';
  11586. };
  11587. }
  11588. return pluralRules[index];
  11589. }
  11590. gMacros.plural = function (str, param, key, prop) {
  11591. var n = parseFloat(param);
  11592. if (isNaN(n)) return str;
  11593. if (prop != gTextProp) return str;
  11594. if (!gMacros._pluralRules) {
  11595. gMacros._pluralRules = getPluralRules(gLanguage);
  11596. }
  11597. var index = '[' + gMacros._pluralRules(n) + ']';
  11598. if (n === 0 && key + '[zero]' in gL10nData) {
  11599. str = gL10nData[key + '[zero]'][prop];
  11600. } else if (n == 1 && key + '[one]' in gL10nData) {
  11601. str = gL10nData[key + '[one]'][prop];
  11602. } else if (n == 2 && key + '[two]' in gL10nData) {
  11603. str = gL10nData[key + '[two]'][prop];
  11604. } else if (key + index in gL10nData) {
  11605. str = gL10nData[key + index][prop];
  11606. } else if (key + '[other]' in gL10nData) {
  11607. str = gL10nData[key + '[other]'][prop];
  11608. }
  11609. return str;
  11610. };
  11611. function getL10nData(key, args, fallback) {
  11612. var data = gL10nData[key];
  11613. if (!data) {
  11614. console.warn('#' + key + ' is undefined.');
  11615. if (!fallback) {
  11616. return null;
  11617. }
  11618. data = fallback;
  11619. }
  11620. var rv = {};
  11621. for (var prop in data) {
  11622. var str = data[prop];
  11623. str = substIndexes(str, args, key, prop);
  11624. str = substArguments(str, args, key);
  11625. rv[prop] = str;
  11626. }
  11627. return rv;
  11628. }
  11629. function substIndexes(str, args, key, prop) {
  11630. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  11631. var reMatch = reIndex.exec(str);
  11632. if (!reMatch || !reMatch.length) return str;
  11633. var macroName = reMatch[1];
  11634. var paramName = reMatch[2];
  11635. var param;
  11636. if (args && paramName in args) {
  11637. param = args[paramName];
  11638. } else if (paramName in gL10nData) {
  11639. param = gL10nData[paramName];
  11640. }
  11641. if (macroName in gMacros) {
  11642. var macro = gMacros[macroName];
  11643. str = macro(str, param, key, prop);
  11644. }
  11645. return str;
  11646. }
  11647. function substArguments(str, args, key) {
  11648. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  11649. return str.replace(reArgs, function (matched_text, arg) {
  11650. if (args && arg in args) {
  11651. return args[arg];
  11652. }
  11653. if (arg in gL10nData) {
  11654. return gL10nData[arg];
  11655. }
  11656. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  11657. return matched_text;
  11658. });
  11659. }
  11660. function translateElement(element) {
  11661. var l10n = getL10nAttributes(element);
  11662. if (!l10n.id) return;
  11663. var data = getL10nData(l10n.id, l10n.args);
  11664. if (!data) {
  11665. console.warn('#' + l10n.id + ' is undefined.');
  11666. return;
  11667. }
  11668. if (data[gTextProp]) {
  11669. if (getChildElementCount(element) === 0) {
  11670. element[gTextProp] = data[gTextProp];
  11671. } else {
  11672. var children = element.childNodes;
  11673. var found = false;
  11674. for (var i = 0, l = children.length; i < l; i++) {
  11675. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  11676. if (found) {
  11677. children[i].nodeValue = '';
  11678. } else {
  11679. children[i].nodeValue = data[gTextProp];
  11680. found = true;
  11681. }
  11682. }
  11683. }
  11684. if (!found) {
  11685. var textNode = document.createTextNode(data[gTextProp]);
  11686. element.insertBefore(textNode, element.firstChild);
  11687. }
  11688. }
  11689. delete data[gTextProp];
  11690. }
  11691. for (var k in data) {
  11692. element[k] = data[k];
  11693. }
  11694. }
  11695. function getChildElementCount(element) {
  11696. if (element.children) {
  11697. return element.children.length;
  11698. }
  11699. if (typeof element.childElementCount !== 'undefined') {
  11700. return element.childElementCount;
  11701. }
  11702. var count = 0;
  11703. for (var i = 0; i < element.childNodes.length; i++) {
  11704. count += element.nodeType === 1 ? 1 : 0;
  11705. }
  11706. return count;
  11707. }
  11708. function translateFragment(element) {
  11709. element = element || document.documentElement;
  11710. var children = getTranslatableChildren(element);
  11711. var elementCount = children.length;
  11712. for (var i = 0; i < elementCount; i++) {
  11713. translateElement(children[i]);
  11714. }
  11715. translateElement(element);
  11716. }
  11717. return {
  11718. get: function (key, args, fallbackString) {
  11719. var index = key.lastIndexOf('.');
  11720. var prop = gTextProp;
  11721. if (index > 0) {
  11722. prop = key.substring(index + 1);
  11723. key = key.substring(0, index);
  11724. }
  11725. var fallback;
  11726. if (fallbackString) {
  11727. fallback = {};
  11728. fallback[prop] = fallbackString;
  11729. }
  11730. var data = getL10nData(key, args, fallback);
  11731. if (data && prop in data) {
  11732. return data[prop];
  11733. }
  11734. return '{{' + key + '}}';
  11735. },
  11736. getData: function () {
  11737. return gL10nData;
  11738. },
  11739. getText: function () {
  11740. return gTextData;
  11741. },
  11742. getLanguage: function () {
  11743. return gLanguage;
  11744. },
  11745. setLanguage: function (lang, callback) {
  11746. loadLocale(lang, function () {
  11747. if (callback) callback();
  11748. });
  11749. },
  11750. getDirection: function () {
  11751. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  11752. var shortCode = gLanguage.split('-', 1)[0];
  11753. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  11754. },
  11755. translate: translateFragment,
  11756. getReadyState: function () {
  11757. return gReadyState;
  11758. },
  11759. ready: function (callback) {
  11760. if (!callback) {
  11761. return;
  11762. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  11763. window.setTimeout(function () {
  11764. callback();
  11765. });
  11766. } else if (document.addEventListener) {
  11767. document.addEventListener('localized', function once() {
  11768. document.removeEventListener('localized', once);
  11769. callback();
  11770. });
  11771. }
  11772. }
  11773. };
  11774. }(window, document);
  11775. /***/ }),
  11776. /* 44 */
  11777. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11778. Object.defineProperty(exports, "__esModule", ({
  11779. value: true
  11780. }));
  11781. exports.docPropertiesLookup = docPropertiesLookup;
  11782. exports.GenericScripting = void 0;
  11783. var _pdfjsLib = __webpack_require__(5);
  11784. async function docPropertiesLookup(pdfDocument) {
  11785. const url = "",
  11786. baseUrl = url.split("#")[0];
  11787. let {
  11788. info,
  11789. metadata,
  11790. contentDispositionFilename,
  11791. contentLength
  11792. } = await pdfDocument.getMetadata();
  11793. if (!contentLength) {
  11794. const {
  11795. length
  11796. } = await pdfDocument.getDownloadInfo();
  11797. contentLength = length;
  11798. }
  11799. return { ...info,
  11800. baseURL: baseUrl,
  11801. filesize: contentLength,
  11802. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  11803. metadata: metadata?.getRaw(),
  11804. authors: metadata?.get("dc:creator"),
  11805. numPages: pdfDocument.numPages,
  11806. URL: url
  11807. };
  11808. }
  11809. class GenericScripting {
  11810. constructor(sandboxBundleSrc) {
  11811. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  11812. return window.pdfjsSandbox.QuickJSSandbox();
  11813. });
  11814. }
  11815. async createSandbox(data) {
  11816. const sandbox = await this._ready;
  11817. sandbox.create(data);
  11818. }
  11819. async dispatchEventInSandbox(event) {
  11820. const sandbox = await this._ready;
  11821. sandbox.dispatchEvent(event);
  11822. }
  11823. async destroySandbox() {
  11824. const sandbox = await this._ready;
  11825. sandbox.nukeSandbox();
  11826. }
  11827. }
  11828. exports.GenericScripting = GenericScripting;
  11829. /***/ }),
  11830. /* 45 */
  11831. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11832. Object.defineProperty(exports, "__esModule", ({
  11833. value: true
  11834. }));
  11835. exports.PDFPrintService = PDFPrintService;
  11836. var _app = __webpack_require__(3);
  11837. var _viewer_compatibility = __webpack_require__(2);
  11838. let activeService = null;
  11839. let overlayManager = null;
  11840. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise) {
  11841. const scratchCanvas = activeService.scratchCanvas;
  11842. const PRINT_UNITS = printResolution / 72.0;
  11843. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  11844. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  11845. const ctx = scratchCanvas.getContext("2d");
  11846. ctx.save();
  11847. ctx.fillStyle = "rgb(255, 255, 255)";
  11848. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  11849. ctx.restore();
  11850. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  11851. const renderContext = {
  11852. canvasContext: ctx,
  11853. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  11854. viewport: pdfPage.getViewport({
  11855. scale: 1,
  11856. rotation: size.rotation
  11857. }),
  11858. intent: "print",
  11859. includeAnnotationStorage: true,
  11860. optionalContentConfigPromise
  11861. };
  11862. return pdfPage.render(renderContext).promise;
  11863. });
  11864. }
  11865. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, l10n) {
  11866. this.pdfDocument = pdfDocument;
  11867. this.pagesOverview = pagesOverview;
  11868. this.printContainer = printContainer;
  11869. this._printResolution = printResolution || 150;
  11870. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  11871. this.l10n = l10n;
  11872. this.currentPage = -1;
  11873. this.scratchCanvas = document.createElement("canvas");
  11874. }
  11875. PDFPrintService.prototype = {
  11876. layout() {
  11877. this.throwIfInactive();
  11878. const body = document.querySelector("body");
  11879. body.setAttribute("data-pdfjsprinting", true);
  11880. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  11881. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  11882. }, this);
  11883. if (!hasEqualPageSizes) {
  11884. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  11885. }
  11886. this.pageStyleSheet = document.createElement("style");
  11887. const pageSize = this.pagesOverview[0];
  11888. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  11889. body.appendChild(this.pageStyleSheet);
  11890. },
  11891. destroy() {
  11892. if (activeService !== this) {
  11893. return;
  11894. }
  11895. this.printContainer.textContent = "";
  11896. const body = document.querySelector("body");
  11897. body.removeAttribute("data-pdfjsprinting");
  11898. if (this.pageStyleSheet) {
  11899. this.pageStyleSheet.remove();
  11900. this.pageStyleSheet = null;
  11901. }
  11902. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  11903. this.scratchCanvas = null;
  11904. activeService = null;
  11905. ensureOverlay().then(function () {
  11906. if (overlayManager.active !== "printServiceOverlay") {
  11907. return;
  11908. }
  11909. overlayManager.close("printServiceOverlay");
  11910. });
  11911. },
  11912. renderPages() {
  11913. const pageCount = this.pagesOverview.length;
  11914. const renderNextPage = (resolve, reject) => {
  11915. this.throwIfInactive();
  11916. if (++this.currentPage >= pageCount) {
  11917. renderProgress(pageCount, pageCount, this.l10n);
  11918. resolve();
  11919. return;
  11920. }
  11921. const index = this.currentPage;
  11922. renderProgress(index, pageCount, this.l10n);
  11923. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise).then(this.useRenderedPage.bind(this)).then(function () {
  11924. renderNextPage(resolve, reject);
  11925. }, reject);
  11926. };
  11927. return new Promise(renderNextPage);
  11928. },
  11929. useRenderedPage() {
  11930. this.throwIfInactive();
  11931. const img = document.createElement("img");
  11932. const scratchCanvas = this.scratchCanvas;
  11933. if ("toBlob" in scratchCanvas && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  11934. scratchCanvas.toBlob(function (blob) {
  11935. img.src = URL.createObjectURL(blob);
  11936. });
  11937. } else {
  11938. img.src = scratchCanvas.toDataURL();
  11939. }
  11940. const wrapper = document.createElement("div");
  11941. wrapper.appendChild(img);
  11942. this.printContainer.appendChild(wrapper);
  11943. return new Promise(function (resolve, reject) {
  11944. img.onload = resolve;
  11945. img.onerror = reject;
  11946. });
  11947. },
  11948. performPrint() {
  11949. this.throwIfInactive();
  11950. return new Promise(resolve => {
  11951. setTimeout(() => {
  11952. if (!this.active) {
  11953. resolve();
  11954. return;
  11955. }
  11956. print.call(window);
  11957. setTimeout(resolve, 20);
  11958. }, 0);
  11959. });
  11960. },
  11961. get active() {
  11962. return this === activeService;
  11963. },
  11964. throwIfInactive() {
  11965. if (!this.active) {
  11966. throw new Error("This print request was cancelled or completed.");
  11967. }
  11968. }
  11969. };
  11970. const print = window.print;
  11971. window.print = function () {
  11972. if (activeService) {
  11973. console.warn("Ignored window.print() because of a pending print job.");
  11974. return;
  11975. }
  11976. ensureOverlay().then(function () {
  11977. if (activeService) {
  11978. overlayManager.open("printServiceOverlay");
  11979. }
  11980. });
  11981. try {
  11982. dispatchEvent("beforeprint");
  11983. } finally {
  11984. if (!activeService) {
  11985. console.error("Expected print service to be initialized.");
  11986. ensureOverlay().then(function () {
  11987. if (overlayManager.active === "printServiceOverlay") {
  11988. overlayManager.close("printServiceOverlay");
  11989. }
  11990. });
  11991. return;
  11992. }
  11993. const activeServiceOnEntry = activeService;
  11994. activeService.renderPages().then(function () {
  11995. return activeServiceOnEntry.performPrint();
  11996. }).catch(function () {}).then(function () {
  11997. if (activeServiceOnEntry.active) {
  11998. abort();
  11999. }
  12000. });
  12001. }
  12002. };
  12003. function dispatchEvent(eventType) {
  12004. const event = document.createEvent("CustomEvent");
  12005. event.initCustomEvent(eventType, false, false, "custom");
  12006. window.dispatchEvent(event);
  12007. }
  12008. function abort() {
  12009. if (activeService) {
  12010. activeService.destroy();
  12011. dispatchEvent("afterprint");
  12012. }
  12013. }
  12014. function renderProgress(index, total, l10n) {
  12015. const progressContainer = document.getElementById("printServiceOverlay");
  12016. const progress = Math.round(100 * index / total);
  12017. const progressBar = progressContainer.querySelector("progress");
  12018. const progressPerc = progressContainer.querySelector(".relative-progress");
  12019. progressBar.value = progress;
  12020. l10n.get("print_progress_percent", {
  12021. progress
  12022. }).then(msg => {
  12023. progressPerc.textContent = msg;
  12024. });
  12025. }
  12026. window.addEventListener("keydown", function (event) {
  12027. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  12028. window.print();
  12029. event.preventDefault();
  12030. if (event.stopImmediatePropagation) {
  12031. event.stopImmediatePropagation();
  12032. } else {
  12033. event.stopPropagation();
  12034. }
  12035. }
  12036. }, true);
  12037. if ("onbeforeprint" in window) {
  12038. const stopPropagationIfNeeded = function (event) {
  12039. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  12040. event.stopImmediatePropagation();
  12041. }
  12042. };
  12043. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  12044. window.addEventListener("afterprint", stopPropagationIfNeeded);
  12045. }
  12046. let overlayPromise;
  12047. function ensureOverlay() {
  12048. if (!overlayPromise) {
  12049. overlayManager = _app.PDFViewerApplication.overlayManager;
  12050. if (!overlayManager) {
  12051. throw new Error("The overlay manager has not yet been initialized.");
  12052. }
  12053. overlayPromise = overlayManager.register("printServiceOverlay", document.getElementById("printServiceOverlay"), abort, true);
  12054. document.getElementById("printCancel").onclick = abort;
  12055. }
  12056. return overlayPromise;
  12057. }
  12058. _app.PDFPrintServiceFactory.instance = {
  12059. supportsPrinting: true,
  12060. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n) {
  12061. if (activeService) {
  12062. throw new Error("The print service is created and active.");
  12063. }
  12064. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n);
  12065. return activeService;
  12066. }
  12067. };
  12068. /***/ })
  12069. /******/ ]);
  12070. /************************************************************************/
  12071. /******/ // The module cache
  12072. /******/ var __webpack_module_cache__ = {};
  12073. /******/
  12074. /******/ // The require function
  12075. /******/ function __webpack_require__(moduleId) {
  12076. /******/ // Check if module is in cache
  12077. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  12078. /******/ if (cachedModule !== undefined) {
  12079. /******/ return cachedModule.exports;
  12080. /******/ }
  12081. /******/ // Create a new module (and put it into the cache)
  12082. /******/ var module = __webpack_module_cache__[moduleId] = {
  12083. /******/ // no module.id needed
  12084. /******/ // no module.loaded needed
  12085. /******/ exports: {}
  12086. /******/ };
  12087. /******/
  12088. /******/ // Execute the module function
  12089. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  12090. /******/
  12091. /******/ // Return the exports of the module
  12092. /******/ return module.exports;
  12093. /******/ }
  12094. /******/
  12095. /************************************************************************/
  12096. var __webpack_exports__ = {};
  12097. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  12098. (() => {
  12099. var exports = __webpack_exports__;
  12100. Object.defineProperty(exports, "__esModule", ({
  12101. value: true
  12102. }));
  12103. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  12104. enumerable: true,
  12105. get: function () {
  12106. return _app_options.AppOptions;
  12107. }
  12108. }));
  12109. Object.defineProperty(exports, "PDFViewerApplication", ({
  12110. enumerable: true,
  12111. get: function () {
  12112. return _app.PDFViewerApplication;
  12113. }
  12114. }));
  12115. var _app_options = __webpack_require__(1);
  12116. var _app = __webpack_require__(3);
  12117. const pdfjsVersion = '2.9.359';
  12118. const pdfjsBuild = 'e667c8cbc';
  12119. window.PDFViewerApplication = _app.PDFViewerApplication;
  12120. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  12121. ;
  12122. ;
  12123. {
  12124. __webpack_require__(39);
  12125. }
  12126. ;
  12127. {
  12128. __webpack_require__(45);
  12129. }
  12130. function getViewerConfiguration() {
  12131. let errorWrapper = null;
  12132. errorWrapper = {
  12133. container: document.getElementById("errorWrapper"),
  12134. errorMessage: document.getElementById("errorMessage"),
  12135. closeButton: document.getElementById("errorClose"),
  12136. errorMoreInfo: document.getElementById("errorMoreInfo"),
  12137. moreInfoButton: document.getElementById("errorShowMore"),
  12138. lessInfoButton: document.getElementById("errorShowLess")
  12139. };
  12140. return {
  12141. appContainer: document.body,
  12142. mainContainer: document.getElementById("viewerContainer"),
  12143. viewerContainer: document.getElementById("viewer"),
  12144. eventBus: null,
  12145. toolbar: {
  12146. container: document.getElementById("toolbarViewer"),
  12147. numPages: document.getElementById("numPages"),
  12148. pageNumber: document.getElementById("pageNumber"),
  12149. scaleSelectContainer: document.getElementById("scaleSelectContainer"),
  12150. scaleSelect: document.getElementById("scaleSelect"),
  12151. customScaleOption: document.getElementById("customScaleOption"),
  12152. previous: document.getElementById("previous"),
  12153. next: document.getElementById("next"),
  12154. zoomIn: document.getElementById("zoomIn"),
  12155. zoomOut: document.getElementById("zoomOut"),
  12156. viewFind: document.getElementById("viewFind"),
  12157. openFile: document.getElementById("openFile"),
  12158. print: document.getElementById("print"),
  12159. presentationModeButton: document.getElementById("presentationMode"),
  12160. download: document.getElementById("download"),
  12161. viewBookmark: document.getElementById("viewBookmark")
  12162. },
  12163. secondaryToolbar: {
  12164. toolbar: document.getElementById("secondaryToolbar"),
  12165. toggleButton: document.getElementById("secondaryToolbarToggle"),
  12166. toolbarButtonContainer: document.getElementById("secondaryToolbarButtonContainer"),
  12167. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  12168. openFileButton: document.getElementById("secondaryOpenFile"),
  12169. printButton: document.getElementById("secondaryPrint"),
  12170. downloadButton: document.getElementById("secondaryDownload"),
  12171. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  12172. firstPageButton: document.getElementById("firstPage"),
  12173. lastPageButton: document.getElementById("lastPage"),
  12174. pageRotateCwButton: document.getElementById("pageRotateCw"),
  12175. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  12176. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  12177. cursorHandToolButton: document.getElementById("cursorHandTool"),
  12178. scrollVerticalButton: document.getElementById("scrollVertical"),
  12179. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  12180. scrollWrappedButton: document.getElementById("scrollWrapped"),
  12181. spreadNoneButton: document.getElementById("spreadNone"),
  12182. spreadOddButton: document.getElementById("spreadOdd"),
  12183. spreadEvenButton: document.getElementById("spreadEven"),
  12184. documentPropertiesButton: document.getElementById("documentProperties")
  12185. },
  12186. sidebar: {
  12187. outerContainer: document.getElementById("outerContainer"),
  12188. viewerContainer: document.getElementById("viewerContainer"),
  12189. toggleButton: document.getElementById("sidebarToggle"),
  12190. thumbnailButton: document.getElementById("viewThumbnail"),
  12191. outlineButton: document.getElementById("viewOutline"),
  12192. attachmentsButton: document.getElementById("viewAttachments"),
  12193. layersButton: document.getElementById("viewLayers"),
  12194. thumbnailView: document.getElementById("thumbnailView"),
  12195. outlineView: document.getElementById("outlineView"),
  12196. attachmentsView: document.getElementById("attachmentsView"),
  12197. layersView: document.getElementById("layersView"),
  12198. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  12199. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  12200. },
  12201. sidebarResizer: {
  12202. outerContainer: document.getElementById("outerContainer"),
  12203. resizer: document.getElementById("sidebarResizer")
  12204. },
  12205. findBar: {
  12206. bar: document.getElementById("findbar"),
  12207. toggleButton: document.getElementById("viewFind"),
  12208. findField: document.getElementById("findInput"),
  12209. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  12210. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  12211. entireWordCheckbox: document.getElementById("findEntireWord"),
  12212. findMsg: document.getElementById("findMsg"),
  12213. findResultsCount: document.getElementById("findResultsCount"),
  12214. findPreviousButton: document.getElementById("findPrevious"),
  12215. findNextButton: document.getElementById("findNext")
  12216. },
  12217. passwordOverlay: {
  12218. overlayName: "passwordOverlay",
  12219. container: document.getElementById("passwordOverlay"),
  12220. label: document.getElementById("passwordText"),
  12221. input: document.getElementById("password"),
  12222. submitButton: document.getElementById("passwordSubmit"),
  12223. cancelButton: document.getElementById("passwordCancel")
  12224. },
  12225. documentProperties: {
  12226. overlayName: "documentPropertiesOverlay",
  12227. container: document.getElementById("documentPropertiesOverlay"),
  12228. closeButton: document.getElementById("documentPropertiesClose"),
  12229. fields: {
  12230. fileName: document.getElementById("fileNameField"),
  12231. fileSize: document.getElementById("fileSizeField"),
  12232. title: document.getElementById("titleField"),
  12233. author: document.getElementById("authorField"),
  12234. subject: document.getElementById("subjectField"),
  12235. keywords: document.getElementById("keywordsField"),
  12236. creationDate: document.getElementById("creationDateField"),
  12237. modificationDate: document.getElementById("modificationDateField"),
  12238. creator: document.getElementById("creatorField"),
  12239. producer: document.getElementById("producerField"),
  12240. version: document.getElementById("versionField"),
  12241. pageCount: document.getElementById("pageCountField"),
  12242. pageSize: document.getElementById("pageSizeField"),
  12243. linearized: document.getElementById("linearizedField")
  12244. }
  12245. },
  12246. errorWrapper,
  12247. printContainer: document.getElementById("printContainer"),
  12248. openFileInputName: "fileInput",
  12249. debuggerScriptPath: "./debugger.js"
  12250. };
  12251. }
  12252. function webViewerLoad() {
  12253. const config = getViewerConfiguration();
  12254. const event = document.createEvent("CustomEvent");
  12255. event.initCustomEvent("webviewerloaded", true, true, {
  12256. source: window
  12257. });
  12258. try {
  12259. parent.document.dispatchEvent(event);
  12260. } catch (ex) {
  12261. console.error(`webviewerloaded: ${ex}`);
  12262. document.dispatchEvent(event);
  12263. }
  12264. _app.PDFViewerApplication.run(config);
  12265. }
  12266. if (document.blockUnblockOnload) {
  12267. document.blockUnblockOnload(true);
  12268. }
  12269. if (document.readyState === "interactive" || document.readyState === "complete") {
  12270. webViewerLoad();
  12271. } else {
  12272. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  12273. }
  12274. })();
  12275. /******/ })()
  12276. ;
  12277. //# sourceMappingURL=viewer.js.map