viewer.js 383 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269
  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. document.title = title;
  762. },
  763. get _docFilename() {
  764. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  765. },
  766. _cancelIdleCallbacks() {
  767. if (!this._idleCallbacks.size) {
  768. return;
  769. }
  770. for (const callback of this._idleCallbacks) {
  771. window.cancelIdleCallback(callback);
  772. }
  773. this._idleCallbacks.clear();
  774. },
  775. async close() {
  776. this._unblockDocumentLoadEvent();
  777. const {
  778. container
  779. } = this.appConfig.errorWrapper;
  780. container.hidden = true;
  781. if (!this.pdfLoadingTask) {
  782. return;
  783. }
  784. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  785. try {
  786. await this.save({
  787. sourceEventType: "save"
  788. });
  789. } catch (reason) {}
  790. }
  791. const promises = [];
  792. promises.push(this.pdfLoadingTask.destroy());
  793. this.pdfLoadingTask = null;
  794. if (this.pdfDocument) {
  795. this.pdfDocument = null;
  796. this.pdfThumbnailViewer.setDocument(null);
  797. this.pdfViewer.setDocument(null);
  798. this.pdfLinkService.setDocument(null);
  799. this.pdfDocumentProperties.setDocument(null);
  800. }
  801. webViewerResetPermissions();
  802. this._fellback = false;
  803. this.store = null;
  804. this.isInitialViewSet = false;
  805. this.downloadComplete = false;
  806. this.url = "";
  807. this.baseUrl = "";
  808. this.documentInfo = null;
  809. this.metadata = null;
  810. this._contentDispositionFilename = null;
  811. this._contentLength = null;
  812. this._saveInProgress = false;
  813. this._cancelIdleCallbacks();
  814. promises.push(this.pdfScriptingManager.destroyPromise);
  815. this.pdfSidebar.reset();
  816. this.pdfOutlineViewer.reset();
  817. this.pdfAttachmentViewer.reset();
  818. this.pdfLayerViewer.reset();
  819. if (this.pdfHistory) {
  820. this.pdfHistory.reset();
  821. }
  822. if (this.findBar) {
  823. this.findBar.reset();
  824. }
  825. this.toolbar.reset();
  826. this.secondaryToolbar.reset();
  827. if (typeof PDFBug !== "undefined") {
  828. PDFBug.cleanup();
  829. }
  830. await Promise.all(promises);
  831. },
  832. async open(file, args) {
  833. if (this.pdfLoadingTask) {
  834. await this.close();
  835. }
  836. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  837. for (const key in workerParameters) {
  838. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  839. }
  840. const parameters = Object.create(null);
  841. if (typeof file === "string") {
  842. this.setTitleUsingUrl(file);
  843. parameters.url = file;
  844. } else if (file && "byteLength" in file) {
  845. parameters.data = file;
  846. } else if (file.url && file.originalUrl) {
  847. this.setTitleUsingUrl(file.originalUrl);
  848. parameters.url = file.url;
  849. }
  850. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  851. for (const key in apiParameters) {
  852. let value = apiParameters[key];
  853. if (key === "docBaseUrl" && !value) {}
  854. parameters[key] = value;
  855. }
  856. if (args) {
  857. for (const key in args) {
  858. parameters[key] = args[key];
  859. }
  860. }
  861. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  862. this.pdfLoadingTask = loadingTask;
  863. loadingTask.onPassword = (updateCallback, reason) => {
  864. this.pdfLinkService.externalLinkEnabled = false;
  865. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  866. this.passwordPrompt.open();
  867. };
  868. loadingTask.onProgress = ({
  869. loaded,
  870. total
  871. }) => {
  872. this.progress(loaded / total);
  873. };
  874. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  875. return loadingTask.promise.then(pdfDocument => {
  876. this.load(pdfDocument);
  877. }, exception => {
  878. if (loadingTask !== this.pdfLoadingTask) {
  879. return undefined;
  880. }
  881. let key = "loading_error";
  882. if (exception instanceof _pdfjsLib.InvalidPDFException) {
  883. key = "invalid_file_error";
  884. } else if (exception instanceof _pdfjsLib.MissingPDFException) {
  885. key = "missing_file_error";
  886. } else if (exception instanceof _pdfjsLib.UnexpectedResponseException) {
  887. key = "unexpected_response_error";
  888. }
  889. return this.l10n.get(key).then(msg => {
  890. this._documentError(msg, {
  891. message: exception?.message
  892. });
  893. throw exception;
  894. });
  895. });
  896. },
  897. _ensureDownloadComplete() {
  898. if (this.pdfDocument && this.downloadComplete) {
  899. return;
  900. }
  901. throw new Error("PDF document not downloaded.");
  902. },
  903. async download({
  904. sourceEventType = "download"
  905. } = {}) {
  906. const url = this.baseUrl,
  907. filename = this._docFilename;
  908. try {
  909. this._ensureDownloadComplete();
  910. const data = await this.pdfDocument.getData();
  911. const blob = new Blob([data], {
  912. type: "application/pdf"
  913. });
  914. await this.downloadManager.download(blob, url, filename, sourceEventType);
  915. } catch (reason) {
  916. await this.downloadManager.downloadUrl(url, filename);
  917. }
  918. },
  919. async save({
  920. sourceEventType = "download"
  921. } = {}) {
  922. if (this._saveInProgress) {
  923. return;
  924. }
  925. this._saveInProgress = true;
  926. await this.pdfScriptingManager.dispatchWillSave();
  927. const url = this.baseUrl,
  928. filename = this._docFilename;
  929. try {
  930. this._ensureDownloadComplete();
  931. const data = await this.pdfDocument.saveDocument();
  932. const blob = new Blob([data], {
  933. type: "application/pdf"
  934. });
  935. await this.downloadManager.download(blob, url, filename, sourceEventType);
  936. } catch (reason) {
  937. await this.download({
  938. sourceEventType
  939. });
  940. } finally {
  941. await this.pdfScriptingManager.dispatchDidSave();
  942. this._saveInProgress = false;
  943. }
  944. },
  945. downloadOrSave(options) {
  946. if (this.pdfDocument?.annotationStorage.size > 0) {
  947. this.save(options);
  948. } else {
  949. this.download(options);
  950. }
  951. },
  952. fallback(featureId) {
  953. this.externalServices.reportTelemetry({
  954. type: "unsupportedFeature",
  955. featureId
  956. });
  957. if (this._fellback) {
  958. return;
  959. }
  960. this._fellback = true;
  961. this.externalServices.fallback({
  962. featureId,
  963. url: this.baseUrl
  964. }).then(download => {
  965. if (!download) {
  966. return;
  967. }
  968. this.download({
  969. sourceEventType: "download"
  970. });
  971. });
  972. },
  973. _documentError(message, moreInfo = null) {
  974. this._unblockDocumentLoadEvent();
  975. this._otherError(message, moreInfo);
  976. },
  977. _otherError(message, moreInfo = null) {
  978. const moreInfoText = [this.l10n.get("error_version_info", {
  979. version: _pdfjsLib.version || "?",
  980. build: _pdfjsLib.build || "?"
  981. })];
  982. if (moreInfo) {
  983. moreInfoText.push(this.l10n.get("error_message", {
  984. message: moreInfo.message
  985. }));
  986. if (moreInfo.stack) {
  987. moreInfoText.push(this.l10n.get("error_stack", {
  988. stack: moreInfo.stack
  989. }));
  990. } else {
  991. if (moreInfo.filename) {
  992. moreInfoText.push(this.l10n.get("error_file", {
  993. file: moreInfo.filename
  994. }));
  995. }
  996. if (moreInfo.lineNumber) {
  997. moreInfoText.push(this.l10n.get("error_line", {
  998. line: moreInfo.lineNumber
  999. }));
  1000. }
  1001. }
  1002. }
  1003. const errorWrapperConfig = this.appConfig.errorWrapper;
  1004. const errorWrapper = errorWrapperConfig.container;
  1005. errorWrapper.hidden = false;
  1006. const errorMessage = errorWrapperConfig.errorMessage;
  1007. errorMessage.textContent = message;
  1008. const closeButton = errorWrapperConfig.closeButton;
  1009. closeButton.onclick = function () {
  1010. errorWrapper.hidden = true;
  1011. };
  1012. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1013. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1014. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1015. moreInfoButton.onclick = function () {
  1016. errorMoreInfo.hidden = false;
  1017. moreInfoButton.hidden = true;
  1018. lessInfoButton.hidden = false;
  1019. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1020. };
  1021. lessInfoButton.onclick = function () {
  1022. errorMoreInfo.hidden = true;
  1023. moreInfoButton.hidden = false;
  1024. lessInfoButton.hidden = true;
  1025. };
  1026. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1027. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1028. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1029. moreInfoButton.hidden = false;
  1030. lessInfoButton.hidden = true;
  1031. Promise.all(moreInfoText).then(parts => {
  1032. errorMoreInfo.value = parts.join("\n");
  1033. });
  1034. },
  1035. progress(level) {
  1036. if (this.downloadComplete) {
  1037. return;
  1038. }
  1039. const percent = Math.round(level * 100);
  1040. if (percent > this.loadingBar.percent || isNaN(percent)) {
  1041. this.loadingBar.percent = percent;
  1042. const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
  1043. if (disableAutoFetch && percent) {
  1044. if (this.disableAutoFetchLoadingBarTimeout) {
  1045. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1046. this.disableAutoFetchLoadingBarTimeout = null;
  1047. }
  1048. this.loadingBar.show();
  1049. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  1050. this.loadingBar.hide();
  1051. this.disableAutoFetchLoadingBarTimeout = null;
  1052. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1053. }
  1054. }
  1055. },
  1056. load(pdfDocument) {
  1057. this.pdfDocument = pdfDocument;
  1058. pdfDocument.getDownloadInfo().then(({
  1059. length
  1060. }) => {
  1061. this._contentLength = length;
  1062. this.downloadComplete = true;
  1063. this.loadingBar.hide();
  1064. firstPagePromise.then(() => {
  1065. this.eventBus.dispatch("documentloaded", {
  1066. source: this
  1067. });
  1068. });
  1069. });
  1070. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  1071. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1072. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  1073. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1074. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1075. let baseDocumentUrl;
  1076. baseDocumentUrl = null;
  1077. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1078. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1079. const pdfViewer = this.pdfViewer;
  1080. pdfViewer.setDocument(pdfDocument);
  1081. const {
  1082. firstPagePromise,
  1083. onePageRendered,
  1084. pagesPromise
  1085. } = pdfViewer;
  1086. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  1087. pdfThumbnailViewer.setDocument(pdfDocument);
  1088. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprint)).getMultiple({
  1089. page: null,
  1090. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1091. scrollLeft: "0",
  1092. scrollTop: "0",
  1093. rotation: null,
  1094. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  1095. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1096. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  1097. }).catch(() => {
  1098. return Object.create(null);
  1099. });
  1100. firstPagePromise.then(pdfPage => {
  1101. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  1102. this._initializeAnnotationStorageCallbacks(pdfDocument);
  1103. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  1104. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  1105. this._initializePdfHistory({
  1106. fingerprint: pdfDocument.fingerprint,
  1107. viewOnLoad,
  1108. initialDest: openAction?.dest
  1109. });
  1110. const initialBookmark = this.initialBookmark;
  1111. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  1112. let hash = zoom ? `zoom=${zoom}` : null;
  1113. let rotation = null;
  1114. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  1115. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  1116. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  1117. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1118. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  1119. rotation = parseInt(stored.rotation, 10);
  1120. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1121. sidebarView = stored.sidebarView | 0;
  1122. }
  1123. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1124. scrollMode = stored.scrollMode | 0;
  1125. }
  1126. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1127. spreadMode = stored.spreadMode | 0;
  1128. }
  1129. }
  1130. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1131. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  1132. }
  1133. if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1134. spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(pageLayout);
  1135. }
  1136. this.setInitialView(hash, {
  1137. rotation,
  1138. sidebarView,
  1139. scrollMode,
  1140. spreadMode
  1141. });
  1142. this.eventBus.dispatch("documentinit", {
  1143. source: this
  1144. });
  1145. if (!this.isViewerEmbedded) {
  1146. pdfViewer.focus();
  1147. }
  1148. this._initializePermissions(pdfDocument);
  1149. await Promise.race([pagesPromise, new Promise(resolve => {
  1150. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1151. })]);
  1152. if (!initialBookmark && !hash) {
  1153. return;
  1154. }
  1155. if (pdfViewer.hasEqualPageSizes) {
  1156. return;
  1157. }
  1158. this.initialBookmark = initialBookmark;
  1159. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1160. this.setInitialView(hash);
  1161. }).catch(() => {
  1162. this.setInitialView();
  1163. }).then(function () {
  1164. pdfViewer.update();
  1165. });
  1166. });
  1167. pagesPromise.then(() => {
  1168. this._unblockDocumentLoadEvent();
  1169. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1170. });
  1171. onePageRendered.then(() => {
  1172. pdfDocument.getOutline().then(outline => {
  1173. if (pdfDocument !== this.pdfDocument) {
  1174. return;
  1175. }
  1176. this.pdfOutlineViewer.render({
  1177. outline,
  1178. pdfDocument
  1179. });
  1180. });
  1181. pdfDocument.getAttachments().then(attachments => {
  1182. if (pdfDocument !== this.pdfDocument) {
  1183. return;
  1184. }
  1185. this.pdfAttachmentViewer.render({
  1186. attachments
  1187. });
  1188. });
  1189. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1190. if (pdfDocument !== this.pdfDocument) {
  1191. return;
  1192. }
  1193. this.pdfLayerViewer.render({
  1194. optionalContentConfig,
  1195. pdfDocument
  1196. });
  1197. });
  1198. if ("requestIdleCallback" in window) {
  1199. const callback = window.requestIdleCallback(() => {
  1200. this._collectTelemetry(pdfDocument);
  1201. this._idleCallbacks.delete(callback);
  1202. }, {
  1203. timeout: 1000
  1204. });
  1205. this._idleCallbacks.add(callback);
  1206. }
  1207. });
  1208. this._initializePageLabels(pdfDocument);
  1209. this._initializeMetadata(pdfDocument);
  1210. },
  1211. async _scriptingDocProperties(pdfDocument) {
  1212. if (!this.documentInfo) {
  1213. await new Promise(resolve => {
  1214. this.eventBus._on("metadataloaded", resolve, {
  1215. once: true
  1216. });
  1217. });
  1218. if (pdfDocument !== this.pdfDocument) {
  1219. return null;
  1220. }
  1221. }
  1222. if (!this._contentLength) {
  1223. await new Promise(resolve => {
  1224. this.eventBus._on("documentloaded", resolve, {
  1225. once: true
  1226. });
  1227. });
  1228. if (pdfDocument !== this.pdfDocument) {
  1229. return null;
  1230. }
  1231. }
  1232. return { ...this.documentInfo,
  1233. baseURL: this.baseUrl,
  1234. filesize: this._contentLength,
  1235. filename: this._docFilename,
  1236. metadata: this.metadata?.getRaw(),
  1237. authors: this.metadata?.get("dc:creator"),
  1238. numPages: this.pagesCount,
  1239. URL: this.url
  1240. };
  1241. },
  1242. async _collectTelemetry(pdfDocument) {
  1243. const markInfo = await this.pdfDocument.getMarkInfo();
  1244. if (pdfDocument !== this.pdfDocument) {
  1245. return;
  1246. }
  1247. const tagged = markInfo?.Marked || false;
  1248. this.externalServices.reportTelemetry({
  1249. type: "tagged",
  1250. tagged
  1251. });
  1252. },
  1253. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1254. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  1255. if (pdfDocument !== this.pdfDocument) {
  1256. return;
  1257. }
  1258. let triggerAutoPrint = false;
  1259. if (openAction?.action === "Print") {
  1260. triggerAutoPrint = true;
  1261. }
  1262. if (javaScript) {
  1263. javaScript.some(js => {
  1264. if (!js) {
  1265. return false;
  1266. }
  1267. console.warn("Warning: JavaScript support is not enabled");
  1268. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1269. return true;
  1270. });
  1271. if (!triggerAutoPrint) {
  1272. for (const js of javaScript) {
  1273. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1274. triggerAutoPrint = true;
  1275. break;
  1276. }
  1277. }
  1278. }
  1279. }
  1280. if (triggerAutoPrint) {
  1281. this.triggerPrinting();
  1282. }
  1283. },
  1284. async _initializeMetadata(pdfDocument) {
  1285. const {
  1286. info,
  1287. metadata,
  1288. contentDispositionFilename,
  1289. contentLength
  1290. } = await pdfDocument.getMetadata();
  1291. if (pdfDocument !== this.pdfDocument) {
  1292. return;
  1293. }
  1294. this.documentInfo = info;
  1295. this.metadata = metadata;
  1296. this._contentDispositionFilename ?? (this._contentDispositionFilename = contentDispositionFilename);
  1297. this._contentLength ?? (this._contentLength = contentLength);
  1298. console.log(`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"})`);
  1299. let pdfTitle = info?.Title;
  1300. const metadataTitle = metadata?.get("dc:title");
  1301. if (metadataTitle) {
  1302. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1303. pdfTitle = metadataTitle;
  1304. }
  1305. }
  1306. if (pdfTitle) {
  1307. this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  1308. } else if (contentDispositionFilename) {
  1309. this.setTitle(contentDispositionFilename);
  1310. }
  1311. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1312. console.warn("Warning: XFA is not enabled");
  1313. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1314. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderInteractiveForms) {
  1315. console.warn("Warning: Interactive form support is not enabled");
  1316. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1317. }
  1318. if (info.IsSignaturesPresent) {
  1319. console.warn("Warning: Digital signatures validation is not supported");
  1320. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  1321. }
  1322. let versionId = "other";
  1323. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  1324. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  1325. }
  1326. let generatorId = "other";
  1327. if (info.Producer) {
  1328. const producer = info.Producer.toLowerCase();
  1329. KNOWN_GENERATORS.some(function (generator) {
  1330. if (!producer.includes(generator)) {
  1331. return false;
  1332. }
  1333. generatorId = generator.replace(/[ .-]/g, "_");
  1334. return true;
  1335. });
  1336. }
  1337. let formType = null;
  1338. if (info.IsXFAPresent) {
  1339. formType = "xfa";
  1340. } else if (info.IsAcroFormPresent) {
  1341. formType = "acroform";
  1342. }
  1343. this.externalServices.reportTelemetry({
  1344. type: "documentInfo",
  1345. version: versionId,
  1346. generator: generatorId,
  1347. formType
  1348. });
  1349. this.eventBus.dispatch("metadataloaded", {
  1350. source: this
  1351. });
  1352. },
  1353. async _initializePageLabels(pdfDocument) {
  1354. const labels = await pdfDocument.getPageLabels();
  1355. if (pdfDocument !== this.pdfDocument) {
  1356. return;
  1357. }
  1358. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1359. return;
  1360. }
  1361. const numLabels = labels.length;
  1362. if (numLabels !== this.pagesCount) {
  1363. console.error("The number of Page Labels does not match the number of pages in the document.");
  1364. return;
  1365. }
  1366. let i = 0;
  1367. while (i < numLabels && labels[i] === (i + 1).toString()) {
  1368. i++;
  1369. }
  1370. if (i === numLabels) {
  1371. return;
  1372. }
  1373. const {
  1374. pdfViewer,
  1375. pdfThumbnailViewer,
  1376. toolbar
  1377. } = this;
  1378. pdfViewer.setPageLabels(labels);
  1379. pdfThumbnailViewer.setPageLabels(labels);
  1380. toolbar.setPagesCount(numLabels, true);
  1381. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1382. },
  1383. _initializePdfHistory({
  1384. fingerprint,
  1385. viewOnLoad,
  1386. initialDest = null
  1387. }) {
  1388. if (this.isViewerEmbedded || _app_options.AppOptions.get("disableHistory")) {
  1389. return;
  1390. }
  1391. this.pdfHistory.initialize({
  1392. fingerprint,
  1393. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1394. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1395. });
  1396. if (this.pdfHistory.initialBookmark) {
  1397. this.initialBookmark = this.pdfHistory.initialBookmark;
  1398. this.initialRotation = this.pdfHistory.initialRotation;
  1399. }
  1400. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1401. this.initialBookmark = JSON.stringify(initialDest);
  1402. this.pdfHistory.push({
  1403. explicitDest: initialDest,
  1404. pageNumber: null
  1405. });
  1406. }
  1407. },
  1408. async _initializePermissions(pdfDocument) {
  1409. const permissions = await pdfDocument.getPermissions();
  1410. if (pdfDocument !== this.pdfDocument) {
  1411. return;
  1412. }
  1413. if (!permissions || !_app_options.AppOptions.get("enablePermissions")) {
  1414. return;
  1415. }
  1416. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  1417. this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
  1418. }
  1419. },
  1420. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1421. if (pdfDocument !== this.pdfDocument) {
  1422. return;
  1423. }
  1424. const {
  1425. annotationStorage
  1426. } = pdfDocument;
  1427. annotationStorage.onSetModified = () => {
  1428. window.addEventListener("beforeunload", beforeUnload);
  1429. this._annotationStorageModified = true;
  1430. };
  1431. annotationStorage.onResetModified = () => {
  1432. window.removeEventListener("beforeunload", beforeUnload);
  1433. delete this._annotationStorageModified;
  1434. };
  1435. },
  1436. setInitialView(storedHash, {
  1437. rotation,
  1438. sidebarView,
  1439. scrollMode,
  1440. spreadMode
  1441. } = {}) {
  1442. const setRotation = angle => {
  1443. if ((0, _ui_utils.isValidRotation)(angle)) {
  1444. this.pdfViewer.pagesRotation = angle;
  1445. }
  1446. };
  1447. const setViewerModes = (scroll, spread) => {
  1448. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1449. this.pdfViewer.scrollMode = scroll;
  1450. }
  1451. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1452. this.pdfViewer.spreadMode = spread;
  1453. }
  1454. };
  1455. this.isInitialViewSet = true;
  1456. this.pdfSidebar.setInitialView(sidebarView);
  1457. setViewerModes(scrollMode, spreadMode);
  1458. if (this.initialBookmark) {
  1459. setRotation(this.initialRotation);
  1460. delete this.initialRotation;
  1461. this.pdfLinkService.setHash(this.initialBookmark);
  1462. this.initialBookmark = null;
  1463. } else if (storedHash) {
  1464. setRotation(rotation);
  1465. this.pdfLinkService.setHash(storedHash);
  1466. }
  1467. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1468. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1469. if (!this.pdfViewer.currentScaleValue) {
  1470. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1471. }
  1472. },
  1473. _cleanup() {
  1474. if (!this.pdfDocument) {
  1475. return;
  1476. }
  1477. this.pdfViewer.cleanup();
  1478. this.pdfThumbnailViewer.cleanup();
  1479. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  1480. },
  1481. forceRendering() {
  1482. this.pdfRenderingQueue.printing = !!this.printService;
  1483. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1484. this.pdfRenderingQueue.renderHighestPriority();
  1485. },
  1486. beforePrint() {
  1487. this.pdfScriptingManager.dispatchWillPrint();
  1488. if (this.printService) {
  1489. return;
  1490. }
  1491. if (!this.supportsPrinting) {
  1492. this.l10n.get("printing_not_supported").then(msg => {
  1493. this._otherError(msg);
  1494. });
  1495. return;
  1496. }
  1497. if (!this.pdfViewer.pageViewsReady) {
  1498. this.l10n.get("printing_not_ready").then(msg => {
  1499. window.alert(msg);
  1500. });
  1501. return;
  1502. }
  1503. const pagesOverview = this.pdfViewer.getPagesOverview();
  1504. const printContainer = this.appConfig.printContainer;
  1505. const printResolution = _app_options.AppOptions.get("printResolution");
  1506. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1507. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
  1508. this.printService = printService;
  1509. this.forceRendering();
  1510. printService.layout();
  1511. this.externalServices.reportTelemetry({
  1512. type: "print"
  1513. });
  1514. },
  1515. afterPrint() {
  1516. this.pdfScriptingManager.dispatchDidPrint();
  1517. if (this.printService) {
  1518. this.printService.destroy();
  1519. this.printService = null;
  1520. if (this.pdfDocument) {
  1521. this.pdfDocument.annotationStorage.resetModified();
  1522. }
  1523. }
  1524. this.forceRendering();
  1525. },
  1526. rotatePages(delta) {
  1527. this.pdfViewer.pagesRotation += delta;
  1528. },
  1529. requestPresentationMode() {
  1530. if (!this.pdfPresentationMode) {
  1531. return;
  1532. }
  1533. this.pdfPresentationMode.request();
  1534. },
  1535. triggerPrinting() {
  1536. if (!this.supportsPrinting) {
  1537. return;
  1538. }
  1539. window.print();
  1540. },
  1541. bindEvents() {
  1542. const {
  1543. eventBus,
  1544. _boundEvents
  1545. } = this;
  1546. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1547. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1548. eventBus._on("resize", webViewerResize);
  1549. eventBus._on("hashchange", webViewerHashchange);
  1550. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1551. eventBus._on("afterprint", _boundEvents.afterPrint);
  1552. eventBus._on("pagerendered", webViewerPageRendered);
  1553. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1554. eventBus._on("pagechanging", webViewerPageChanging);
  1555. eventBus._on("scalechanging", webViewerScaleChanging);
  1556. eventBus._on("rotationchanging", webViewerRotationChanging);
  1557. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1558. eventBus._on("pagemode", webViewerPageMode);
  1559. eventBus._on("namedaction", webViewerNamedAction);
  1560. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1561. eventBus._on("presentationmode", webViewerPresentationMode);
  1562. eventBus._on("print", webViewerPrint);
  1563. eventBus._on("download", webViewerDownload);
  1564. eventBus._on("save", webViewerSave);
  1565. eventBus._on("firstpage", webViewerFirstPage);
  1566. eventBus._on("lastpage", webViewerLastPage);
  1567. eventBus._on("nextpage", webViewerNextPage);
  1568. eventBus._on("previouspage", webViewerPreviousPage);
  1569. eventBus._on("zoomin", webViewerZoomIn);
  1570. eventBus._on("zoomout", webViewerZoomOut);
  1571. eventBus._on("zoomreset", webViewerZoomReset);
  1572. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1573. eventBus._on("scalechanged", webViewerScaleChanged);
  1574. eventBus._on("rotatecw", webViewerRotateCw);
  1575. eventBus._on("rotateccw", webViewerRotateCcw);
  1576. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1577. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1578. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1579. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1580. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1581. eventBus._on("documentproperties", webViewerDocumentProperties);
  1582. eventBus._on("find", webViewerFind);
  1583. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1584. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1585. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1586. if (_app_options.AppOptions.get("pdfBug")) {
  1587. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1588. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1589. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1590. }
  1591. eventBus._on("fileinputchange", webViewerFileInputChange);
  1592. eventBus._on("openfile", webViewerOpenFile);
  1593. },
  1594. bindWindowEvents() {
  1595. const {
  1596. eventBus,
  1597. _boundEvents
  1598. } = this;
  1599. _boundEvents.windowResize = () => {
  1600. eventBus.dispatch("resize", {
  1601. source: window
  1602. });
  1603. };
  1604. _boundEvents.windowHashChange = () => {
  1605. eventBus.dispatch("hashchange", {
  1606. source: window,
  1607. hash: document.location.hash.substring(1)
  1608. });
  1609. };
  1610. _boundEvents.windowBeforePrint = () => {
  1611. eventBus.dispatch("beforeprint", {
  1612. source: window
  1613. });
  1614. };
  1615. _boundEvents.windowAfterPrint = () => {
  1616. eventBus.dispatch("afterprint", {
  1617. source: window
  1618. });
  1619. };
  1620. _boundEvents.windowUpdateFromSandbox = event => {
  1621. eventBus.dispatch("updatefromsandbox", {
  1622. source: window,
  1623. detail: event.detail
  1624. });
  1625. };
  1626. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1627. window.addEventListener("wheel", webViewerWheel, {
  1628. passive: false
  1629. });
  1630. window.addEventListener("touchstart", webViewerTouchStart, {
  1631. passive: false
  1632. });
  1633. window.addEventListener("click", webViewerClick);
  1634. window.addEventListener("keydown", webViewerKeyDown);
  1635. window.addEventListener("resize", _boundEvents.windowResize);
  1636. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1637. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1638. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1639. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1640. },
  1641. unbindEvents() {
  1642. const {
  1643. eventBus,
  1644. _boundEvents
  1645. } = this;
  1646. eventBus._off("resize", webViewerResize);
  1647. eventBus._off("hashchange", webViewerHashchange);
  1648. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1649. eventBus._off("afterprint", _boundEvents.afterPrint);
  1650. eventBus._off("pagerendered", webViewerPageRendered);
  1651. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1652. eventBus._off("pagechanging", webViewerPageChanging);
  1653. eventBus._off("scalechanging", webViewerScaleChanging);
  1654. eventBus._off("rotationchanging", webViewerRotationChanging);
  1655. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1656. eventBus._off("pagemode", webViewerPageMode);
  1657. eventBus._off("namedaction", webViewerNamedAction);
  1658. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1659. eventBus._off("presentationmode", webViewerPresentationMode);
  1660. eventBus._off("print", webViewerPrint);
  1661. eventBus._off("download", webViewerDownload);
  1662. eventBus._off("save", webViewerSave);
  1663. eventBus._off("firstpage", webViewerFirstPage);
  1664. eventBus._off("lastpage", webViewerLastPage);
  1665. eventBus._off("nextpage", webViewerNextPage);
  1666. eventBus._off("previouspage", webViewerPreviousPage);
  1667. eventBus._off("zoomin", webViewerZoomIn);
  1668. eventBus._off("zoomout", webViewerZoomOut);
  1669. eventBus._off("zoomreset", webViewerZoomReset);
  1670. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1671. eventBus._off("scalechanged", webViewerScaleChanged);
  1672. eventBus._off("rotatecw", webViewerRotateCw);
  1673. eventBus._off("rotateccw", webViewerRotateCcw);
  1674. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1675. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1676. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1677. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1678. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1679. eventBus._off("documentproperties", webViewerDocumentProperties);
  1680. eventBus._off("find", webViewerFind);
  1681. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1682. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1683. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1684. if (_boundEvents.reportPageStatsPDFBug) {
  1685. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1686. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1687. _boundEvents.reportPageStatsPDFBug = null;
  1688. }
  1689. eventBus._off("fileinputchange", webViewerFileInputChange);
  1690. eventBus._off("openfile", webViewerOpenFile);
  1691. _boundEvents.beforePrint = null;
  1692. _boundEvents.afterPrint = null;
  1693. },
  1694. unbindWindowEvents() {
  1695. const {
  1696. _boundEvents
  1697. } = this;
  1698. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1699. window.removeEventListener("wheel", webViewerWheel, {
  1700. passive: false
  1701. });
  1702. window.removeEventListener("touchstart", webViewerTouchStart, {
  1703. passive: false
  1704. });
  1705. window.removeEventListener("click", webViewerClick);
  1706. window.removeEventListener("keydown", webViewerKeyDown);
  1707. window.removeEventListener("resize", _boundEvents.windowResize);
  1708. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1709. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1710. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1711. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1712. _boundEvents.windowResize = null;
  1713. _boundEvents.windowHashChange = null;
  1714. _boundEvents.windowBeforePrint = null;
  1715. _boundEvents.windowAfterPrint = null;
  1716. _boundEvents.windowUpdateFromSandbox = null;
  1717. },
  1718. accumulateWheelTicks(ticks) {
  1719. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  1720. this._wheelUnusedTicks = 0;
  1721. }
  1722. this._wheelUnusedTicks += ticks;
  1723. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  1724. this._wheelUnusedTicks -= wholeTicks;
  1725. return wholeTicks;
  1726. },
  1727. _unblockDocumentLoadEvent() {
  1728. if (document.blockUnblockOnload) {
  1729. document.blockUnblockOnload(false);
  1730. }
  1731. this._unblockDocumentLoadEvent = () => {};
  1732. },
  1733. get scriptingReady() {
  1734. return this.pdfScriptingManager.ready;
  1735. }
  1736. };
  1737. exports.PDFViewerApplication = PDFViewerApplication;
  1738. let validateFileURL;
  1739. {
  1740. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1741. validateFileURL = function (file) {
  1742. if (file === undefined) {
  1743. return;
  1744. }
  1745. try {
  1746. const viewerOrigin = new URL(window.location.href).origin || "null";
  1747. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1748. return;
  1749. }
  1750. const {
  1751. origin,
  1752. protocol
  1753. } = new URL(file, window.location.href);
  1754. // if (origin !== viewerOrigin && protocol !== "blob:") {
  1755. // throw new Error("file origin does not match viewer's");
  1756. // }
  1757. } catch (ex) {
  1758. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1759. PDFViewerApplication._documentError(msg, {
  1760. message: ex?.message
  1761. });
  1762. });
  1763. throw ex;
  1764. }
  1765. };
  1766. }
  1767. async function loadFakeWorker() {
  1768. if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
  1769. _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
  1770. }
  1771. return (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.getWorkerSrc());
  1772. }
  1773. function loadAndEnablePDFBug(enabledTabs) {
  1774. const appConfig = PDFViewerApplication.appConfig;
  1775. return (0, _pdfjsLib.loadScript)(appConfig.debuggerScriptPath).then(function () {
  1776. PDFBug.enable(enabledTabs);
  1777. PDFBug.init({
  1778. OPS: _pdfjsLib.OPS
  1779. }, appConfig.mainContainer);
  1780. });
  1781. }
  1782. function reportPageStatsPDFBug({
  1783. pageNumber
  1784. }) {
  1785. if (typeof Stats === "undefined" || !Stats.enabled) {
  1786. return;
  1787. }
  1788. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1789. const pageStats = pageView?.pdfPage?.stats;
  1790. if (!pageStats) {
  1791. return;
  1792. }
  1793. Stats.add(pageNumber, pageStats);
  1794. }
  1795. function webViewerInitialized() {
  1796. const appConfig = PDFViewerApplication.appConfig;
  1797. let file;
  1798. const queryString = document.location.search.substring(1);
  1799. const params = (0, _ui_utils.parseQueryString)(queryString);
  1800. file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
  1801. validateFileURL(file);
  1802. const fileInput = document.createElement("input");
  1803. fileInput.id = appConfig.openFileInputName;
  1804. fileInput.className = "fileInput";
  1805. fileInput.setAttribute("type", "file");
  1806. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1807. document.body.appendChild(fileInput);
  1808. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1809. appConfig.toolbar.openFile.hidden = true;
  1810. appConfig.secondaryToolbar.openFileButton.hidden = true;
  1811. } else {
  1812. fileInput.value = null;
  1813. }
  1814. fileInput.addEventListener("change", function (evt) {
  1815. const files = evt.target.files;
  1816. if (!files || files.length === 0) {
  1817. return;
  1818. }
  1819. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1820. source: this,
  1821. fileInput: evt.target
  1822. });
  1823. });
  1824. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1825. evt.preventDefault();
  1826. evt.dataTransfer.dropEffect = "move";
  1827. });
  1828. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1829. evt.preventDefault();
  1830. const files = evt.dataTransfer.files;
  1831. if (!files || files.length === 0) {
  1832. return;
  1833. }
  1834. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1835. source: this,
  1836. fileInput: evt.dataTransfer
  1837. });
  1838. });
  1839. if (!PDFViewerApplication.supportsDocumentFonts) {
  1840. _app_options.AppOptions.set("disableFontFace", true);
  1841. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  1842. console.warn(msg);
  1843. });
  1844. }
  1845. if (!PDFViewerApplication.supportsPrinting) {
  1846. appConfig.toolbar.print.classList.add("hidden");
  1847. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  1848. }
  1849. if (!PDFViewerApplication.supportsFullscreen) {
  1850. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  1851. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  1852. }
  1853. if (PDFViewerApplication.supportsIntegratedFind) {
  1854. appConfig.toolbar.viewFind.classList.add("hidden");
  1855. }
  1856. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1857. if (evt.target === this) {
  1858. PDFViewerApplication.eventBus.dispatch("resize", {
  1859. source: this
  1860. });
  1861. }
  1862. }, true);
  1863. try {
  1864. webViewerOpenFileViaURL(file);
  1865. } catch (reason) {
  1866. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1867. PDFViewerApplication._documentError(msg, reason);
  1868. });
  1869. }
  1870. }
  1871. function webViewerOpenFileViaURL(file) {
  1872. if (file) {
  1873. PDFViewerApplication.open(file);
  1874. }
  1875. }
  1876. function webViewerResetPermissions() {
  1877. const {
  1878. appConfig
  1879. } = PDFViewerApplication;
  1880. if (!appConfig) {
  1881. return;
  1882. }
  1883. appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  1884. }
  1885. function webViewerPageRendered({
  1886. pageNumber,
  1887. timestamp,
  1888. error
  1889. }) {
  1890. if (pageNumber === PDFViewerApplication.page) {
  1891. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1892. }
  1893. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1894. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1895. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  1896. if (pageView && thumbnailView) {
  1897. thumbnailView.setImage(pageView);
  1898. }
  1899. }
  1900. if (error) {
  1901. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1902. PDFViewerApplication._otherError(msg, error);
  1903. });
  1904. }
  1905. PDFViewerApplication.externalServices.reportTelemetry({
  1906. type: "pageInfo",
  1907. timestamp
  1908. });
  1909. PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
  1910. PDFViewerApplication.externalServices.reportTelemetry({
  1911. type: "documentStats",
  1912. stats
  1913. });
  1914. });
  1915. }
  1916. function webViewerPageMode({
  1917. mode
  1918. }) {
  1919. let view;
  1920. switch (mode) {
  1921. case "thumbs":
  1922. view = _ui_utils.SidebarView.THUMBS;
  1923. break;
  1924. case "bookmarks":
  1925. case "outline":
  1926. view = _ui_utils.SidebarView.OUTLINE;
  1927. break;
  1928. case "attachments":
  1929. view = _ui_utils.SidebarView.ATTACHMENTS;
  1930. break;
  1931. case "layers":
  1932. view = _ui_utils.SidebarView.LAYERS;
  1933. break;
  1934. case "none":
  1935. view = _ui_utils.SidebarView.NONE;
  1936. break;
  1937. default:
  1938. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1939. return;
  1940. }
  1941. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1942. }
  1943. function webViewerNamedAction(evt) {
  1944. switch (evt.action) {
  1945. case "GoToPage":
  1946. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1947. break;
  1948. case "Find":
  1949. if (!PDFViewerApplication.supportsIntegratedFind) {
  1950. PDFViewerApplication.findBar.toggle();
  1951. }
  1952. break;
  1953. case "Print":
  1954. PDFViewerApplication.triggerPrinting();
  1955. break;
  1956. case "SaveAs":
  1957. webViewerSave();
  1958. break;
  1959. }
  1960. }
  1961. function webViewerPresentationModeChanged(evt) {
  1962. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1963. }
  1964. function webViewerSidebarViewChanged(evt) {
  1965. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1966. const store = PDFViewerApplication.store;
  1967. if (store && PDFViewerApplication.isInitialViewSet) {
  1968. store.set("sidebarView", evt.view).catch(function () {});
  1969. }
  1970. }
  1971. function webViewerUpdateViewarea(evt) {
  1972. const location = evt.location,
  1973. store = PDFViewerApplication.store;
  1974. if (store && PDFViewerApplication.isInitialViewSet) {
  1975. store.setMultiple({
  1976. page: location.pageNumber,
  1977. zoom: location.scale,
  1978. scrollLeft: location.left,
  1979. scrollTop: location.top,
  1980. rotation: location.rotation
  1981. }).catch(function () {});
  1982. }
  1983. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1984. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1985. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1986. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1987. const loading = currentPage?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1988. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1989. }
  1990. function webViewerScrollModeChanged(evt) {
  1991. const store = PDFViewerApplication.store;
  1992. if (store && PDFViewerApplication.isInitialViewSet) {
  1993. store.set("scrollMode", evt.mode).catch(function () {});
  1994. }
  1995. }
  1996. function webViewerSpreadModeChanged(evt) {
  1997. const store = PDFViewerApplication.store;
  1998. if (store && PDFViewerApplication.isInitialViewSet) {
  1999. store.set("spreadMode", evt.mode).catch(function () {});
  2000. }
  2001. }
  2002. function webViewerResize() {
  2003. const {
  2004. pdfDocument,
  2005. pdfViewer
  2006. } = PDFViewerApplication;
  2007. if (!pdfDocument) {
  2008. return;
  2009. }
  2010. const currentScaleValue = pdfViewer.currentScaleValue;
  2011. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  2012. pdfViewer.currentScaleValue = currentScaleValue;
  2013. }
  2014. pdfViewer.update();
  2015. }
  2016. function webViewerHashchange(evt) {
  2017. const hash = evt.hash;
  2018. if (!hash) {
  2019. return;
  2020. }
  2021. if (!PDFViewerApplication.isInitialViewSet) {
  2022. PDFViewerApplication.initialBookmark = hash;
  2023. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  2024. PDFViewerApplication.pdfLinkService.setHash(hash);
  2025. }
  2026. }
  2027. let webViewerFileInputChange, webViewerOpenFile;
  2028. {
  2029. webViewerFileInputChange = function (evt) {
  2030. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2031. return;
  2032. }
  2033. const file = evt.fileInput.files[0];
  2034. if (!_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  2035. let url = URL.createObjectURL(file);
  2036. if (file.name) {
  2037. url = {
  2038. url,
  2039. originalUrl: file.name
  2040. };
  2041. }
  2042. PDFViewerApplication.open(url);
  2043. } else {
  2044. PDFViewerApplication.setTitleUsingUrl(file.name);
  2045. const fileReader = new FileReader();
  2046. fileReader.onload = function webViewerChangeFileReaderOnload(event) {
  2047. const buffer = event.target.result;
  2048. PDFViewerApplication.open(new Uint8Array(buffer));
  2049. };
  2050. fileReader.readAsArrayBuffer(file);
  2051. }
  2052. const appConfig = PDFViewerApplication.appConfig;
  2053. appConfig.toolbar.viewBookmark.hidden = true;
  2054. appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
  2055. appConfig.toolbar.download.hidden = true;
  2056. appConfig.secondaryToolbar.downloadButton.hidden = true;
  2057. };
  2058. webViewerOpenFile = function (evt) {
  2059. const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  2060. document.getElementById(openFileInputName).click();
  2061. };
  2062. }
  2063. function webViewerPresentationMode() {
  2064. PDFViewerApplication.requestPresentationMode();
  2065. }
  2066. function webViewerPrint() {
  2067. PDFViewerApplication.triggerPrinting();
  2068. }
  2069. function webViewerDownload() {
  2070. PDFViewerApplication.downloadOrSave({
  2071. sourceEventType: "download"
  2072. });
  2073. }
  2074. function webViewerSave() {
  2075. PDFViewerApplication.downloadOrSave({
  2076. sourceEventType: "save"
  2077. });
  2078. }
  2079. function webViewerFirstPage() {
  2080. if (PDFViewerApplication.pdfDocument) {
  2081. PDFViewerApplication.page = 1;
  2082. }
  2083. }
  2084. function webViewerLastPage() {
  2085. if (PDFViewerApplication.pdfDocument) {
  2086. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2087. }
  2088. }
  2089. function webViewerNextPage() {
  2090. PDFViewerApplication.pdfViewer.nextPage();
  2091. }
  2092. function webViewerPreviousPage() {
  2093. PDFViewerApplication.pdfViewer.previousPage();
  2094. }
  2095. function webViewerZoomIn() {
  2096. PDFViewerApplication.zoomIn();
  2097. }
  2098. function webViewerZoomOut() {
  2099. PDFViewerApplication.zoomOut();
  2100. }
  2101. function webViewerZoomReset() {
  2102. PDFViewerApplication.zoomReset();
  2103. }
  2104. function webViewerPageNumberChanged(evt) {
  2105. const pdfViewer = PDFViewerApplication.pdfViewer;
  2106. if (evt.value !== "") {
  2107. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  2108. }
  2109. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  2110. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2111. }
  2112. }
  2113. function webViewerScaleChanged(evt) {
  2114. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2115. }
  2116. function webViewerRotateCw() {
  2117. PDFViewerApplication.rotatePages(90);
  2118. }
  2119. function webViewerRotateCcw() {
  2120. PDFViewerApplication.rotatePages(-90);
  2121. }
  2122. function webViewerOptionalContentConfig(evt) {
  2123. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  2124. }
  2125. function webViewerSwitchScrollMode(evt) {
  2126. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  2127. }
  2128. function webViewerSwitchSpreadMode(evt) {
  2129. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  2130. }
  2131. function webViewerDocumentProperties() {
  2132. PDFViewerApplication.pdfDocumentProperties.open();
  2133. }
  2134. function webViewerFind(evt) {
  2135. PDFViewerApplication.findController.executeCommand("find" + evt.type, {
  2136. query: evt.query,
  2137. phraseSearch: evt.phraseSearch,
  2138. caseSensitive: evt.caseSensitive,
  2139. entireWord: evt.entireWord,
  2140. highlightAll: evt.highlightAll,
  2141. findPrevious: evt.findPrevious
  2142. });
  2143. }
  2144. function webViewerFindFromUrlHash(evt) {
  2145. PDFViewerApplication.findController.executeCommand("find", {
  2146. query: evt.query,
  2147. phraseSearch: evt.phraseSearch,
  2148. caseSensitive: false,
  2149. entireWord: false,
  2150. highlightAll: true,
  2151. findPrevious: false
  2152. });
  2153. }
  2154. function webViewerUpdateFindMatchesCount({
  2155. matchesCount
  2156. }) {
  2157. if (PDFViewerApplication.supportsIntegratedFind) {
  2158. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  2159. } else {
  2160. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  2161. }
  2162. }
  2163. function webViewerUpdateFindControlState({
  2164. state,
  2165. previous,
  2166. matchesCount,
  2167. rawQuery
  2168. }) {
  2169. if (PDFViewerApplication.supportsIntegratedFind) {
  2170. PDFViewerApplication.externalServices.updateFindControlState({
  2171. result: state,
  2172. findPrevious: previous,
  2173. matchesCount,
  2174. rawQuery
  2175. });
  2176. } else {
  2177. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  2178. }
  2179. }
  2180. function webViewerScaleChanging(evt) {
  2181. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  2182. PDFViewerApplication.pdfViewer.update();
  2183. }
  2184. function webViewerRotationChanging(evt) {
  2185. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  2186. PDFViewerApplication.forceRendering();
  2187. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2188. }
  2189. function webViewerPageChanging({
  2190. pageNumber,
  2191. pageLabel
  2192. }) {
  2193. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  2194. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  2195. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2196. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  2197. }
  2198. }
  2199. function webViewerVisibilityChange(evt) {
  2200. if (document.visibilityState === "visible") {
  2201. setZoomDisabledTimeout();
  2202. }
  2203. }
  2204. let zoomDisabledTimeout = null;
  2205. function setZoomDisabledTimeout() {
  2206. if (zoomDisabledTimeout) {
  2207. clearTimeout(zoomDisabledTimeout);
  2208. }
  2209. zoomDisabledTimeout = setTimeout(function () {
  2210. zoomDisabledTimeout = null;
  2211. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  2212. }
  2213. function webViewerWheel(evt) {
  2214. const {
  2215. pdfViewer,
  2216. supportedMouseWheelZoomModifierKeys
  2217. } = PDFViewerApplication;
  2218. if (pdfViewer.isInPresentationMode) {
  2219. return;
  2220. }
  2221. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  2222. evt.preventDefault();
  2223. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2224. return;
  2225. }
  2226. const previousScale = pdfViewer.currentScale;
  2227. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2228. let ticks = 0;
  2229. if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE || evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2230. if (Math.abs(delta) >= 1) {
  2231. ticks = Math.sign(delta);
  2232. } else {
  2233. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  2234. }
  2235. } else {
  2236. const PIXELS_PER_LINE_SCALE = 30;
  2237. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  2238. }
  2239. if (ticks < 0) {
  2240. PDFViewerApplication.zoomOut(-ticks);
  2241. } else if (ticks > 0) {
  2242. PDFViewerApplication.zoomIn(ticks);
  2243. }
  2244. const currentScale = pdfViewer.currentScale;
  2245. if (previousScale !== currentScale) {
  2246. const scaleCorrectionFactor = currentScale / previousScale - 1;
  2247. const rect = pdfViewer.container.getBoundingClientRect();
  2248. const dx = evt.clientX - rect.left;
  2249. const dy = evt.clientY - rect.top;
  2250. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  2251. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  2252. }
  2253. } else {
  2254. setZoomDisabledTimeout();
  2255. }
  2256. }
  2257. function webViewerTouchStart(evt) {
  2258. if (evt.touches.length > 1) {
  2259. evt.preventDefault();
  2260. }
  2261. }
  2262. function webViewerClick(evt) {
  2263. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  2264. return;
  2265. }
  2266. const appConfig = PDFViewerApplication.appConfig;
  2267. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  2268. PDFViewerApplication.secondaryToolbar.close();
  2269. }
  2270. }
  2271. function webViewerKeyDown(evt) {
  2272. if (PDFViewerApplication.overlayManager.active) {
  2273. return;
  2274. }
  2275. let handled = false,
  2276. ensureViewerFocused = false;
  2277. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2278. const pdfViewer = PDFViewerApplication.pdfViewer;
  2279. const isViewerInPresentationMode = pdfViewer?.isInPresentationMode;
  2280. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2281. switch (evt.keyCode) {
  2282. case 70:
  2283. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2284. PDFViewerApplication.findBar.open();
  2285. handled = true;
  2286. }
  2287. break;
  2288. case 71:
  2289. if (!PDFViewerApplication.supportsIntegratedFind) {
  2290. const findState = PDFViewerApplication.findController.state;
  2291. if (findState) {
  2292. PDFViewerApplication.findController.executeCommand("findagain", {
  2293. query: findState.query,
  2294. phraseSearch: findState.phraseSearch,
  2295. caseSensitive: findState.caseSensitive,
  2296. entireWord: findState.entireWord,
  2297. highlightAll: findState.highlightAll,
  2298. findPrevious: cmd === 5 || cmd === 12
  2299. });
  2300. }
  2301. handled = true;
  2302. }
  2303. break;
  2304. case 61:
  2305. case 107:
  2306. case 187:
  2307. case 171:
  2308. if (!isViewerInPresentationMode) {
  2309. PDFViewerApplication.zoomIn();
  2310. }
  2311. handled = true;
  2312. break;
  2313. case 173:
  2314. case 109:
  2315. case 189:
  2316. if (!isViewerInPresentationMode) {
  2317. PDFViewerApplication.zoomOut();
  2318. }
  2319. handled = true;
  2320. break;
  2321. case 48:
  2322. case 96:
  2323. if (!isViewerInPresentationMode) {
  2324. setTimeout(function () {
  2325. PDFViewerApplication.zoomReset();
  2326. });
  2327. handled = false;
  2328. }
  2329. break;
  2330. case 38:
  2331. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2332. PDFViewerApplication.page = 1;
  2333. handled = true;
  2334. ensureViewerFocused = true;
  2335. }
  2336. break;
  2337. case 40:
  2338. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2339. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2340. handled = true;
  2341. ensureViewerFocused = true;
  2342. }
  2343. break;
  2344. }
  2345. }
  2346. const {
  2347. eventBus
  2348. } = PDFViewerApplication;
  2349. if (cmd === 1 || cmd === 8) {
  2350. switch (evt.keyCode) {
  2351. case 83:
  2352. eventBus.dispatch("download", {
  2353. source: window
  2354. });
  2355. handled = true;
  2356. break;
  2357. case 79:
  2358. {
  2359. eventBus.dispatch("openfile", {
  2360. source: window
  2361. });
  2362. handled = true;
  2363. }
  2364. break;
  2365. }
  2366. }
  2367. if (cmd === 3 || cmd === 10) {
  2368. switch (evt.keyCode) {
  2369. case 80:
  2370. PDFViewerApplication.requestPresentationMode();
  2371. handled = true;
  2372. break;
  2373. case 71:
  2374. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2375. handled = true;
  2376. break;
  2377. }
  2378. }
  2379. if (handled) {
  2380. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2381. pdfViewer.focus();
  2382. }
  2383. evt.preventDefault();
  2384. return;
  2385. }
  2386. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2387. const curElementTagName = curElement?.tagName.toUpperCase();
  2388. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2389. if (evt.keyCode !== 27) {
  2390. return;
  2391. }
  2392. }
  2393. if (cmd === 0) {
  2394. let turnPage = 0,
  2395. turnOnlyIfPageFit = false;
  2396. switch (evt.keyCode) {
  2397. case 38:
  2398. case 33:
  2399. if (pdfViewer.isVerticalScrollbarEnabled) {
  2400. turnOnlyIfPageFit = true;
  2401. }
  2402. turnPage = -1;
  2403. break;
  2404. case 8:
  2405. if (!isViewerInPresentationMode) {
  2406. turnOnlyIfPageFit = true;
  2407. }
  2408. turnPage = -1;
  2409. break;
  2410. case 37:
  2411. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2412. turnOnlyIfPageFit = true;
  2413. }
  2414. case 75:
  2415. case 80:
  2416. turnPage = -1;
  2417. break;
  2418. case 27:
  2419. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2420. PDFViewerApplication.secondaryToolbar.close();
  2421. handled = true;
  2422. }
  2423. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2424. PDFViewerApplication.findBar.close();
  2425. handled = true;
  2426. }
  2427. break;
  2428. case 40:
  2429. case 34:
  2430. if (pdfViewer.isVerticalScrollbarEnabled) {
  2431. turnOnlyIfPageFit = true;
  2432. }
  2433. turnPage = 1;
  2434. break;
  2435. case 13:
  2436. case 32:
  2437. if (!isViewerInPresentationMode) {
  2438. turnOnlyIfPageFit = true;
  2439. }
  2440. turnPage = 1;
  2441. break;
  2442. case 39:
  2443. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2444. turnOnlyIfPageFit = true;
  2445. }
  2446. case 74:
  2447. case 78:
  2448. turnPage = 1;
  2449. break;
  2450. case 36:
  2451. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2452. PDFViewerApplication.page = 1;
  2453. handled = true;
  2454. ensureViewerFocused = true;
  2455. }
  2456. break;
  2457. case 35:
  2458. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2459. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2460. handled = true;
  2461. ensureViewerFocused = true;
  2462. }
  2463. break;
  2464. case 83:
  2465. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2466. break;
  2467. case 72:
  2468. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2469. break;
  2470. case 82:
  2471. PDFViewerApplication.rotatePages(90);
  2472. break;
  2473. case 115:
  2474. PDFViewerApplication.pdfSidebar.toggle();
  2475. break;
  2476. }
  2477. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2478. if (turnPage > 0) {
  2479. pdfViewer.nextPage();
  2480. } else {
  2481. pdfViewer.previousPage();
  2482. }
  2483. handled = true;
  2484. }
  2485. }
  2486. if (cmd === 4) {
  2487. switch (evt.keyCode) {
  2488. case 13:
  2489. case 32:
  2490. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2491. break;
  2492. }
  2493. if (PDFViewerApplication.page > 1) {
  2494. PDFViewerApplication.page--;
  2495. }
  2496. handled = true;
  2497. break;
  2498. case 82:
  2499. PDFViewerApplication.rotatePages(-90);
  2500. break;
  2501. }
  2502. }
  2503. if (!handled && !isViewerInPresentationMode) {
  2504. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2505. ensureViewerFocused = true;
  2506. }
  2507. }
  2508. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2509. pdfViewer.focus();
  2510. }
  2511. if (handled) {
  2512. evt.preventDefault();
  2513. }
  2514. }
  2515. function beforeUnload(evt) {
  2516. evt.preventDefault();
  2517. evt.returnValue = "";
  2518. return false;
  2519. }
  2520. const PDFPrintServiceFactory = {
  2521. instance: {
  2522. supportsPrinting: false,
  2523. createPrintService() {
  2524. throw new Error("Not implemented: createPrintService");
  2525. }
  2526. }
  2527. };
  2528. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2529. /***/ }),
  2530. /* 4 */
  2531. /***/ ((__unused_webpack_module, exports) => {
  2532. Object.defineProperty(exports, "__esModule", ({
  2533. value: true
  2534. }));
  2535. exports.apiPageLayoutToSpreadMode = apiPageLayoutToSpreadMode;
  2536. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2537. exports.approximateFraction = approximateFraction;
  2538. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2539. exports.binarySearchFirstItem = binarySearchFirstItem;
  2540. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2541. exports.getOutputScale = getOutputScale;
  2542. exports.getPageSizeInches = getPageSizeInches;
  2543. exports.getVisibleElements = getVisibleElements;
  2544. exports.isPortraitOrientation = isPortraitOrientation;
  2545. exports.isValidRotation = isValidRotation;
  2546. exports.isValidScrollMode = isValidScrollMode;
  2547. exports.isValidSpreadMode = isValidSpreadMode;
  2548. exports.moveToEndOfArray = moveToEndOfArray;
  2549. exports.noContextMenuHandler = noContextMenuHandler;
  2550. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2551. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2552. exports.parseQueryString = parseQueryString;
  2553. exports.roundToDivide = roundToDivide;
  2554. exports.scrollIntoView = scrollIntoView;
  2555. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  2556. exports.watchScroll = watchScroll;
  2557. 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;
  2558. const CSS_UNITS = 96.0 / 72.0;
  2559. exports.CSS_UNITS = CSS_UNITS;
  2560. const DEFAULT_SCALE_VALUE = "auto";
  2561. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2562. const DEFAULT_SCALE = 1.0;
  2563. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2564. const MIN_SCALE = 0.1;
  2565. exports.MIN_SCALE = MIN_SCALE;
  2566. const MAX_SCALE = 10.0;
  2567. exports.MAX_SCALE = MAX_SCALE;
  2568. const UNKNOWN_SCALE = 0;
  2569. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2570. const MAX_AUTO_SCALE = 1.25;
  2571. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2572. const SCROLLBAR_PADDING = 40;
  2573. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2574. const VERTICAL_PADDING = 5;
  2575. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2576. const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
  2577. const PresentationModeState = {
  2578. UNKNOWN: 0,
  2579. NORMAL: 1,
  2580. CHANGING: 2,
  2581. FULLSCREEN: 3
  2582. };
  2583. exports.PresentationModeState = PresentationModeState;
  2584. const SidebarView = {
  2585. UNKNOWN: -1,
  2586. NONE: 0,
  2587. THUMBS: 1,
  2588. OUTLINE: 2,
  2589. ATTACHMENTS: 3,
  2590. LAYERS: 4
  2591. };
  2592. exports.SidebarView = SidebarView;
  2593. const RendererType = {
  2594. CANVAS: "canvas",
  2595. SVG: "svg"
  2596. };
  2597. exports.RendererType = RendererType;
  2598. const TextLayerMode = {
  2599. DISABLE: 0,
  2600. ENABLE: 1,
  2601. ENABLE_ENHANCE: 2
  2602. };
  2603. exports.TextLayerMode = TextLayerMode;
  2604. const ScrollMode = {
  2605. UNKNOWN: -1,
  2606. VERTICAL: 0,
  2607. HORIZONTAL: 1,
  2608. WRAPPED: 2
  2609. };
  2610. exports.ScrollMode = ScrollMode;
  2611. const SpreadMode = {
  2612. UNKNOWN: -1,
  2613. NONE: 0,
  2614. ODD: 1,
  2615. EVEN: 2
  2616. };
  2617. exports.SpreadMode = SpreadMode;
  2618. const AutoPrintRegExp = /\bprint\s*\(/;
  2619. exports.AutoPrintRegExp = AutoPrintRegExp;
  2620. function getOutputScale(ctx) {
  2621. const devicePixelRatio = window.devicePixelRatio || 1;
  2622. const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  2623. const pixelRatio = devicePixelRatio / backingStoreRatio;
  2624. return {
  2625. sx: pixelRatio,
  2626. sy: pixelRatio,
  2627. scaled: pixelRatio !== 1
  2628. };
  2629. }
  2630. function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
  2631. let parent = element.offsetParent;
  2632. if (!parent) {
  2633. console.error("offsetParent is not set -- cannot scroll");
  2634. return;
  2635. }
  2636. let offsetY = element.offsetTop + element.clientTop;
  2637. let offsetX = element.offsetLeft + element.clientLeft;
  2638. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === "hidden") {
  2639. if (parent.dataset._scaleY) {
  2640. offsetY /= parent.dataset._scaleY;
  2641. offsetX /= parent.dataset._scaleX;
  2642. }
  2643. offsetY += parent.offsetTop;
  2644. offsetX += parent.offsetLeft;
  2645. parent = parent.offsetParent;
  2646. if (!parent) {
  2647. return;
  2648. }
  2649. }
  2650. if (spot) {
  2651. if (spot.top !== undefined) {
  2652. offsetY += spot.top;
  2653. }
  2654. if (spot.left !== undefined) {
  2655. offsetX += spot.left;
  2656. parent.scrollLeft = offsetX;
  2657. }
  2658. }
  2659. parent.scrollTop = offsetY;
  2660. }
  2661. function watchScroll(viewAreaElement, callback) {
  2662. const debounceScroll = function (evt) {
  2663. if (rAF) {
  2664. return;
  2665. }
  2666. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2667. rAF = null;
  2668. const currentX = viewAreaElement.scrollLeft;
  2669. const lastX = state.lastX;
  2670. if (currentX !== lastX) {
  2671. state.right = currentX > lastX;
  2672. }
  2673. state.lastX = currentX;
  2674. const currentY = viewAreaElement.scrollTop;
  2675. const lastY = state.lastY;
  2676. if (currentY !== lastY) {
  2677. state.down = currentY > lastY;
  2678. }
  2679. state.lastY = currentY;
  2680. callback(state);
  2681. });
  2682. };
  2683. const state = {
  2684. right: true,
  2685. down: true,
  2686. lastX: viewAreaElement.scrollLeft,
  2687. lastY: viewAreaElement.scrollTop,
  2688. _eventHandler: debounceScroll
  2689. };
  2690. let rAF = null;
  2691. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2692. return state;
  2693. }
  2694. function parseQueryString(query) {
  2695. const parts = query.split("&");
  2696. const params = Object.create(null);
  2697. for (let i = 0, ii = parts.length; i < ii; ++i) {
  2698. const param = parts[i].split("=");
  2699. const key = param[0].toLowerCase();
  2700. const value = param.length > 1 ? param[1] : null;
  2701. params[decodeURIComponent(key)] = decodeURIComponent(value);
  2702. }
  2703. return params;
  2704. }
  2705. function binarySearchFirstItem(items, condition) {
  2706. let minIndex = 0;
  2707. let maxIndex = items.length - 1;
  2708. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2709. return items.length;
  2710. }
  2711. if (condition(items[minIndex])) {
  2712. return minIndex;
  2713. }
  2714. while (minIndex < maxIndex) {
  2715. const currentIndex = minIndex + maxIndex >> 1;
  2716. const currentItem = items[currentIndex];
  2717. if (condition(currentItem)) {
  2718. maxIndex = currentIndex;
  2719. } else {
  2720. minIndex = currentIndex + 1;
  2721. }
  2722. }
  2723. return minIndex;
  2724. }
  2725. function approximateFraction(x) {
  2726. if (Math.floor(x) === x) {
  2727. return [x, 1];
  2728. }
  2729. const xinv = 1 / x;
  2730. const limit = 8;
  2731. if (xinv > limit) {
  2732. return [1, limit];
  2733. } else if (Math.floor(xinv) === xinv) {
  2734. return [1, xinv];
  2735. }
  2736. const x_ = x > 1 ? xinv : x;
  2737. let a = 0,
  2738. b = 1,
  2739. c = 1,
  2740. d = 1;
  2741. while (true) {
  2742. const p = a + c,
  2743. q = b + d;
  2744. if (q > limit) {
  2745. break;
  2746. }
  2747. if (x_ <= p / q) {
  2748. c = p;
  2749. d = q;
  2750. } else {
  2751. a = p;
  2752. b = q;
  2753. }
  2754. }
  2755. let result;
  2756. if (x_ - a / b < c / d - x_) {
  2757. result = x_ === x ? [a, b] : [b, a];
  2758. } else {
  2759. result = x_ === x ? [c, d] : [d, c];
  2760. }
  2761. return result;
  2762. }
  2763. function roundToDivide(x, div) {
  2764. const r = x % div;
  2765. return r === 0 ? x : Math.round(x - r + div);
  2766. }
  2767. function getPageSizeInches({
  2768. view,
  2769. userUnit,
  2770. rotate
  2771. }) {
  2772. const [x1, y1, x2, y2] = view;
  2773. const changeOrientation = rotate % 180 !== 0;
  2774. const width = (x2 - x1) / 72 * userUnit;
  2775. const height = (y2 - y1) / 72 * userUnit;
  2776. return {
  2777. width: changeOrientation ? height : width,
  2778. height: changeOrientation ? width : height
  2779. };
  2780. }
  2781. function backtrackBeforeAllVisibleElements(index, views, top) {
  2782. if (index < 2) {
  2783. return index;
  2784. }
  2785. let elt = views[index].div;
  2786. let pageTop = elt.offsetTop + elt.clientTop;
  2787. if (pageTop >= top) {
  2788. elt = views[index - 1].div;
  2789. pageTop = elt.offsetTop + elt.clientTop;
  2790. }
  2791. for (let i = index - 2; i >= 0; --i) {
  2792. elt = views[i].div;
  2793. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2794. break;
  2795. }
  2796. index = i;
  2797. }
  2798. return index;
  2799. }
  2800. function getVisibleElements({
  2801. scrollEl,
  2802. views,
  2803. sortByVisibility = false,
  2804. horizontal = false,
  2805. rtl = false
  2806. }) {
  2807. const top = scrollEl.scrollTop,
  2808. bottom = top + scrollEl.clientHeight;
  2809. const left = scrollEl.scrollLeft,
  2810. right = left + scrollEl.clientWidth;
  2811. function isElementBottomAfterViewTop(view) {
  2812. const element = view.div;
  2813. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2814. return elementBottom > top;
  2815. }
  2816. function isElementNextAfterViewHorizontally(view) {
  2817. const element = view.div;
  2818. const elementLeft = element.offsetLeft + element.clientLeft;
  2819. const elementRight = elementLeft + element.clientWidth;
  2820. return rtl ? elementLeft < right : elementRight > left;
  2821. }
  2822. const visible = [],
  2823. numViews = views.length;
  2824. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2825. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2826. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2827. }
  2828. let lastEdge = horizontal ? right : -1;
  2829. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2830. const view = views[i],
  2831. element = view.div;
  2832. const currentWidth = element.offsetLeft + element.clientLeft;
  2833. const currentHeight = element.offsetTop + element.clientTop;
  2834. const viewWidth = element.clientWidth,
  2835. viewHeight = element.clientHeight;
  2836. const viewRight = currentWidth + viewWidth;
  2837. const viewBottom = currentHeight + viewHeight;
  2838. if (lastEdge === -1) {
  2839. if (viewBottom >= bottom) {
  2840. lastEdge = viewBottom;
  2841. }
  2842. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2843. break;
  2844. }
  2845. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2846. continue;
  2847. }
  2848. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2849. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2850. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2851. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2852. const percent = fractionHeight * fractionWidth * 100 | 0;
  2853. visible.push({
  2854. id: view.id,
  2855. x: currentWidth,
  2856. y: currentHeight,
  2857. view,
  2858. percent,
  2859. widthPercent: fractionWidth * 100 | 0
  2860. });
  2861. }
  2862. const first = visible[0],
  2863. last = visible[visible.length - 1];
  2864. if (sortByVisibility) {
  2865. visible.sort(function (a, b) {
  2866. const pc = a.percent - b.percent;
  2867. if (Math.abs(pc) > 0.001) {
  2868. return -pc;
  2869. }
  2870. return a.id - b.id;
  2871. });
  2872. }
  2873. return {
  2874. first,
  2875. last,
  2876. views: visible
  2877. };
  2878. }
  2879. function noContextMenuHandler(evt) {
  2880. evt.preventDefault();
  2881. }
  2882. function normalizeWheelEventDirection(evt) {
  2883. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2884. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2885. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2886. delta = -delta;
  2887. }
  2888. return delta;
  2889. }
  2890. function normalizeWheelEventDelta(evt) {
  2891. let delta = normalizeWheelEventDirection(evt);
  2892. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  2893. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  2894. const MOUSE_PIXELS_PER_LINE = 30;
  2895. const MOUSE_LINES_PER_PAGE = 30;
  2896. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  2897. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2898. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  2899. delta /= MOUSE_LINES_PER_PAGE;
  2900. }
  2901. return delta;
  2902. }
  2903. function isValidRotation(angle) {
  2904. return Number.isInteger(angle) && angle % 90 === 0;
  2905. }
  2906. function isValidScrollMode(mode) {
  2907. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2908. }
  2909. function isValidSpreadMode(mode) {
  2910. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2911. }
  2912. function isPortraitOrientation(size) {
  2913. return size.width <= size.height;
  2914. }
  2915. const WaitOnType = {
  2916. EVENT: "event",
  2917. TIMEOUT: "timeout"
  2918. };
  2919. exports.WaitOnType = WaitOnType;
  2920. function waitOnEventOrTimeout({
  2921. target,
  2922. name,
  2923. delay = 0
  2924. }) {
  2925. return new Promise(function (resolve, reject) {
  2926. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  2927. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  2928. }
  2929. function handler(type) {
  2930. if (target instanceof EventBus) {
  2931. target._off(name, eventHandler);
  2932. } else {
  2933. target.removeEventListener(name, eventHandler);
  2934. }
  2935. if (timeout) {
  2936. clearTimeout(timeout);
  2937. }
  2938. resolve(type);
  2939. }
  2940. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  2941. if (target instanceof EventBus) {
  2942. target._on(name, eventHandler);
  2943. } else {
  2944. target.addEventListener(name, eventHandler);
  2945. }
  2946. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  2947. const timeout = setTimeout(timeoutHandler, delay);
  2948. });
  2949. }
  2950. const animationStarted = new Promise(function (resolve) {
  2951. window.requestAnimationFrame(resolve);
  2952. });
  2953. exports.animationStarted = animationStarted;
  2954. function dispatchDOMEvent(eventName, args = null) {
  2955. throw new Error("Not implemented: dispatchDOMEvent");
  2956. }
  2957. class EventBus {
  2958. constructor(options) {
  2959. this._listeners = Object.create(null);
  2960. }
  2961. on(eventName, listener, options = null) {
  2962. this._on(eventName, listener, {
  2963. external: true,
  2964. once: options?.once
  2965. });
  2966. }
  2967. off(eventName, listener, options = null) {
  2968. this._off(eventName, listener, {
  2969. external: true,
  2970. once: options?.once
  2971. });
  2972. }
  2973. dispatch(eventName) {
  2974. const eventListeners = this._listeners[eventName];
  2975. if (!eventListeners || eventListeners.length === 0) {
  2976. return;
  2977. }
  2978. const args = Array.prototype.slice.call(arguments, 1);
  2979. let externalListeners;
  2980. for (const {
  2981. listener,
  2982. external,
  2983. once
  2984. } of eventListeners.slice(0)) {
  2985. if (once) {
  2986. this._off(eventName, listener);
  2987. }
  2988. if (external) {
  2989. (externalListeners || (externalListeners = [])).push(listener);
  2990. continue;
  2991. }
  2992. listener.apply(null, args);
  2993. }
  2994. if (externalListeners) {
  2995. for (const listener of externalListeners) {
  2996. listener.apply(null, args);
  2997. }
  2998. externalListeners = null;
  2999. }
  3000. }
  3001. _on(eventName, listener, options = null) {
  3002. var _this$_listeners;
  3003. const eventListeners = (_this$_listeners = this._listeners)[eventName] || (_this$_listeners[eventName] = []);
  3004. eventListeners.push({
  3005. listener,
  3006. external: options?.external === true,
  3007. once: options?.once === true
  3008. });
  3009. }
  3010. _off(eventName, listener, options = null) {
  3011. const eventListeners = this._listeners[eventName];
  3012. if (!eventListeners) {
  3013. return;
  3014. }
  3015. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3016. if (eventListeners[i].listener === listener) {
  3017. eventListeners.splice(i, 1);
  3018. return;
  3019. }
  3020. }
  3021. }
  3022. }
  3023. exports.EventBus = EventBus;
  3024. function clamp(v, min, max) {
  3025. return Math.min(Math.max(v, min), max);
  3026. }
  3027. class ProgressBar {
  3028. constructor(id, {
  3029. height,
  3030. width,
  3031. units
  3032. } = {}) {
  3033. this.visible = true;
  3034. this.div = document.querySelector(id + " .progress");
  3035. this.bar = this.div.parentNode;
  3036. this.height = height || 100;
  3037. this.width = width || 100;
  3038. this.units = units || "%";
  3039. this.div.style.height = this.height + this.units;
  3040. this.percent = 0;
  3041. }
  3042. _updateBar() {
  3043. if (this._indeterminate) {
  3044. this.div.classList.add("indeterminate");
  3045. this.div.style.width = this.width + this.units;
  3046. return;
  3047. }
  3048. this.div.classList.remove("indeterminate");
  3049. const progressSize = this.width * this._percent / 100;
  3050. this.div.style.width = progressSize + this.units;
  3051. }
  3052. get percent() {
  3053. return this._percent;
  3054. }
  3055. set percent(val) {
  3056. this._indeterminate = isNaN(val);
  3057. this._percent = clamp(val, 0, 100);
  3058. this._updateBar();
  3059. }
  3060. setWidth(viewer) {
  3061. if (!viewer) {
  3062. return;
  3063. }
  3064. const container = viewer.parentNode;
  3065. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  3066. if (scrollbarWidth > 0) {
  3067. const doc = document.documentElement;
  3068. doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
  3069. }
  3070. }
  3071. hide() {
  3072. if (!this.visible) {
  3073. return;
  3074. }
  3075. this.visible = false;
  3076. this.bar.classList.add("hidden");
  3077. }
  3078. show() {
  3079. if (this.visible) {
  3080. return;
  3081. }
  3082. this.visible = true;
  3083. this.bar.classList.remove("hidden");
  3084. }
  3085. }
  3086. exports.ProgressBar = ProgressBar;
  3087. function moveToEndOfArray(arr, condition) {
  3088. const moved = [],
  3089. len = arr.length;
  3090. let write = 0;
  3091. for (let read = 0; read < len; ++read) {
  3092. if (condition(arr[read])) {
  3093. moved.push(arr[read]);
  3094. } else {
  3095. arr[write] = arr[read];
  3096. ++write;
  3097. }
  3098. }
  3099. for (let read = 0; write < len; ++read, ++write) {
  3100. arr[write] = moved[read];
  3101. }
  3102. }
  3103. function getActiveOrFocusedElement() {
  3104. let curRoot = document;
  3105. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3106. while (curActiveOrFocused?.shadowRoot) {
  3107. curRoot = curActiveOrFocused.shadowRoot;
  3108. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3109. }
  3110. return curActiveOrFocused;
  3111. }
  3112. function apiPageLayoutToSpreadMode(layout) {
  3113. switch (layout) {
  3114. case "SinglePage":
  3115. case "OneColumn":
  3116. return SpreadMode.NONE;
  3117. case "TwoColumnLeft":
  3118. case "TwoPageLeft":
  3119. return SpreadMode.ODD;
  3120. case "TwoColumnRight":
  3121. case "TwoPageRight":
  3122. return SpreadMode.EVEN;
  3123. }
  3124. return SpreadMode.NONE;
  3125. }
  3126. function apiPageModeToSidebarView(mode) {
  3127. switch (mode) {
  3128. case "UseNone":
  3129. return SidebarView.NONE;
  3130. case "UseThumbs":
  3131. return SidebarView.THUMBS;
  3132. case "UseOutlines":
  3133. return SidebarView.OUTLINE;
  3134. case "UseAttachments":
  3135. return SidebarView.ATTACHMENTS;
  3136. case "UseOC":
  3137. return SidebarView.LAYERS;
  3138. }
  3139. return SidebarView.NONE;
  3140. }
  3141. /***/ }),
  3142. /* 5 */
  3143. /***/ ((module) => {
  3144. let pdfjsLib;
  3145. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3146. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3147. } else {
  3148. pdfjsLib = require("../build/pdf.js");
  3149. }
  3150. module.exports = pdfjsLib;
  3151. /***/ }),
  3152. /* 6 */
  3153. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3154. Object.defineProperty(exports, "__esModule", ({
  3155. value: true
  3156. }));
  3157. exports.PDFCursorTools = exports.CursorTool = void 0;
  3158. var _grab_to_pan = __webpack_require__(7);
  3159. var _ui_utils = __webpack_require__(4);
  3160. const CursorTool = {
  3161. SELECT: 0,
  3162. HAND: 1,
  3163. ZOOM: 2
  3164. };
  3165. exports.CursorTool = CursorTool;
  3166. class PDFCursorTools {
  3167. constructor({
  3168. container,
  3169. eventBus,
  3170. cursorToolOnLoad = CursorTool.SELECT
  3171. }) {
  3172. this.container = container;
  3173. this.eventBus = eventBus;
  3174. this.active = CursorTool.SELECT;
  3175. this.activeBeforePresentationMode = null;
  3176. this.handTool = new _grab_to_pan.GrabToPan({
  3177. element: this.container
  3178. });
  3179. this._addEventListeners();
  3180. Promise.resolve().then(() => {
  3181. this.switchTool(cursorToolOnLoad);
  3182. });
  3183. }
  3184. get activeTool() {
  3185. return this.active;
  3186. }
  3187. switchTool(tool) {
  3188. if (this.activeBeforePresentationMode !== null) {
  3189. return;
  3190. }
  3191. if (tool === this.active) {
  3192. return;
  3193. }
  3194. const disableActiveTool = () => {
  3195. switch (this.active) {
  3196. case CursorTool.SELECT:
  3197. break;
  3198. case CursorTool.HAND:
  3199. this.handTool.deactivate();
  3200. break;
  3201. case CursorTool.ZOOM:
  3202. }
  3203. };
  3204. switch (tool) {
  3205. case CursorTool.SELECT:
  3206. disableActiveTool();
  3207. break;
  3208. case CursorTool.HAND:
  3209. disableActiveTool();
  3210. this.handTool.activate();
  3211. break;
  3212. case CursorTool.ZOOM:
  3213. default:
  3214. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3215. return;
  3216. }
  3217. this.active = tool;
  3218. this._dispatchEvent();
  3219. }
  3220. _dispatchEvent() {
  3221. this.eventBus.dispatch("cursortoolchanged", {
  3222. source: this,
  3223. tool: this.active
  3224. });
  3225. }
  3226. _addEventListeners() {
  3227. this.eventBus._on("switchcursortool", evt => {
  3228. this.switchTool(evt.tool);
  3229. });
  3230. this.eventBus._on("presentationmodechanged", evt => {
  3231. switch (evt.state) {
  3232. case _ui_utils.PresentationModeState.FULLSCREEN:
  3233. {
  3234. const previouslyActive = this.active;
  3235. this.switchTool(CursorTool.SELECT);
  3236. this.activeBeforePresentationMode = previouslyActive;
  3237. break;
  3238. }
  3239. case _ui_utils.PresentationModeState.NORMAL:
  3240. {
  3241. const previouslyActive = this.activeBeforePresentationMode;
  3242. this.activeBeforePresentationMode = null;
  3243. this.switchTool(previouslyActive);
  3244. break;
  3245. }
  3246. }
  3247. });
  3248. }
  3249. }
  3250. exports.PDFCursorTools = PDFCursorTools;
  3251. /***/ }),
  3252. /* 7 */
  3253. /***/ ((__unused_webpack_module, exports) => {
  3254. Object.defineProperty(exports, "__esModule", ({
  3255. value: true
  3256. }));
  3257. exports.GrabToPan = GrabToPan;
  3258. function GrabToPan(options) {
  3259. this.element = options.element;
  3260. this.document = options.element.ownerDocument;
  3261. if (typeof options.ignoreTarget === "function") {
  3262. this.ignoreTarget = options.ignoreTarget;
  3263. }
  3264. this.onActiveChanged = options.onActiveChanged;
  3265. this.activate = this.activate.bind(this);
  3266. this.deactivate = this.deactivate.bind(this);
  3267. this.toggle = this.toggle.bind(this);
  3268. this._onmousedown = this._onmousedown.bind(this);
  3269. this._onmousemove = this._onmousemove.bind(this);
  3270. this._endPan = this._endPan.bind(this);
  3271. const overlay = this.overlay = document.createElement("div");
  3272. overlay.className = "grab-to-pan-grabbing";
  3273. }
  3274. GrabToPan.prototype = {
  3275. CSS_CLASS_GRAB: "grab-to-pan-grab",
  3276. activate: function GrabToPan_activate() {
  3277. if (!this.active) {
  3278. this.active = true;
  3279. this.element.addEventListener("mousedown", this._onmousedown, true);
  3280. this.element.classList.add(this.CSS_CLASS_GRAB);
  3281. if (this.onActiveChanged) {
  3282. this.onActiveChanged(true);
  3283. }
  3284. }
  3285. },
  3286. deactivate: function GrabToPan_deactivate() {
  3287. if (this.active) {
  3288. this.active = false;
  3289. this.element.removeEventListener("mousedown", this._onmousedown, true);
  3290. this._endPan();
  3291. this.element.classList.remove(this.CSS_CLASS_GRAB);
  3292. if (this.onActiveChanged) {
  3293. this.onActiveChanged(false);
  3294. }
  3295. }
  3296. },
  3297. toggle: function GrabToPan_toggle() {
  3298. if (this.active) {
  3299. this.deactivate();
  3300. } else {
  3301. this.activate();
  3302. }
  3303. },
  3304. ignoreTarget: function GrabToPan_ignoreTarget(node) {
  3305. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3306. },
  3307. _onmousedown: function GrabToPan__onmousedown(event) {
  3308. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3309. return;
  3310. }
  3311. if (event.originalTarget) {
  3312. try {
  3313. event.originalTarget.tagName;
  3314. } catch (e) {
  3315. return;
  3316. }
  3317. }
  3318. this.scrollLeftStart = this.element.scrollLeft;
  3319. this.scrollTopStart = this.element.scrollTop;
  3320. this.clientXStart = event.clientX;
  3321. this.clientYStart = event.clientY;
  3322. this.document.addEventListener("mousemove", this._onmousemove, true);
  3323. this.document.addEventListener("mouseup", this._endPan, true);
  3324. this.element.addEventListener("scroll", this._endPan, true);
  3325. event.preventDefault();
  3326. event.stopPropagation();
  3327. const focusedElement = document.activeElement;
  3328. if (focusedElement && !focusedElement.contains(event.target)) {
  3329. focusedElement.blur();
  3330. }
  3331. },
  3332. _onmousemove: function GrabToPan__onmousemove(event) {
  3333. this.element.removeEventListener("scroll", this._endPan, true);
  3334. if (isLeftMouseReleased(event)) {
  3335. this._endPan();
  3336. return;
  3337. }
  3338. const xDiff = event.clientX - this.clientXStart;
  3339. const yDiff = event.clientY - this.clientYStart;
  3340. const scrollTop = this.scrollTopStart - yDiff;
  3341. const scrollLeft = this.scrollLeftStart - xDiff;
  3342. if (this.element.scrollTo) {
  3343. this.element.scrollTo({
  3344. top: scrollTop,
  3345. left: scrollLeft,
  3346. behavior: "instant"
  3347. });
  3348. } else {
  3349. this.element.scrollTop = scrollTop;
  3350. this.element.scrollLeft = scrollLeft;
  3351. }
  3352. if (!this.overlay.parentNode) {
  3353. document.body.appendChild(this.overlay);
  3354. }
  3355. },
  3356. _endPan: function GrabToPan__endPan() {
  3357. this.element.removeEventListener("scroll", this._endPan, true);
  3358. this.document.removeEventListener("mousemove", this._onmousemove, true);
  3359. this.document.removeEventListener("mouseup", this._endPan, true);
  3360. this.overlay.remove();
  3361. }
  3362. };
  3363. function isLeftMouseReleased(event) {
  3364. if ("buttons" in event) {
  3365. return !(event.buttons & 1);
  3366. }
  3367. const chrome = window.chrome;
  3368. const isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
  3369. const isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
  3370. if (isChrome15OrOpera15plus || isSafari6plus) {
  3371. return event.which === 0;
  3372. }
  3373. return false;
  3374. }
  3375. /***/ }),
  3376. /* 8 */
  3377. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3378. Object.defineProperty(exports, "__esModule", ({
  3379. value: true
  3380. }));
  3381. exports.RenderingStates = exports.PDFRenderingQueue = void 0;
  3382. var _pdfjsLib = __webpack_require__(5);
  3383. const CLEANUP_TIMEOUT = 30000;
  3384. const RenderingStates = {
  3385. INITIAL: 0,
  3386. RUNNING: 1,
  3387. PAUSED: 2,
  3388. FINISHED: 3
  3389. };
  3390. exports.RenderingStates = RenderingStates;
  3391. class PDFRenderingQueue {
  3392. constructor() {
  3393. this.pdfViewer = null;
  3394. this.pdfThumbnailViewer = null;
  3395. this.onIdle = null;
  3396. this.highestPriorityPage = null;
  3397. this.idleTimeout = null;
  3398. this.printing = false;
  3399. this.isThumbnailViewEnabled = false;
  3400. }
  3401. setViewer(pdfViewer) {
  3402. this.pdfViewer = pdfViewer;
  3403. }
  3404. setThumbnailViewer(pdfThumbnailViewer) {
  3405. this.pdfThumbnailViewer = pdfThumbnailViewer;
  3406. }
  3407. isHighestPriority(view) {
  3408. return this.highestPriorityPage === view.renderingId;
  3409. }
  3410. renderHighestPriority(currentlyVisiblePages) {
  3411. if (this.idleTimeout) {
  3412. clearTimeout(this.idleTimeout);
  3413. this.idleTimeout = null;
  3414. }
  3415. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  3416. return;
  3417. }
  3418. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  3419. if (this.pdfThumbnailViewer.forceRendering()) {
  3420. return;
  3421. }
  3422. }
  3423. if (this.printing) {
  3424. return;
  3425. }
  3426. if (this.onIdle) {
  3427. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  3428. }
  3429. }
  3430. getHighestPriority(visible, views, scrolledDown) {
  3431. const visibleViews = visible.views;
  3432. const numVisible = visibleViews.length;
  3433. if (numVisible === 0) {
  3434. return null;
  3435. }
  3436. for (let i = 0; i < numVisible; ++i) {
  3437. const view = visibleViews[i].view;
  3438. if (!this.isViewFinished(view)) {
  3439. return view;
  3440. }
  3441. }
  3442. if (scrolledDown) {
  3443. const nextPageIndex = visible.last.id;
  3444. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  3445. return views[nextPageIndex];
  3446. }
  3447. } else {
  3448. const previousPageIndex = visible.first.id - 2;
  3449. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  3450. return views[previousPageIndex];
  3451. }
  3452. }
  3453. return null;
  3454. }
  3455. isViewFinished(view) {
  3456. return view.renderingState === RenderingStates.FINISHED;
  3457. }
  3458. renderView(view) {
  3459. switch (view.renderingState) {
  3460. case RenderingStates.FINISHED:
  3461. return false;
  3462. case RenderingStates.PAUSED:
  3463. this.highestPriorityPage = view.renderingId;
  3464. view.resume();
  3465. break;
  3466. case RenderingStates.RUNNING:
  3467. this.highestPriorityPage = view.renderingId;
  3468. break;
  3469. case RenderingStates.INITIAL:
  3470. this.highestPriorityPage = view.renderingId;
  3471. view.draw().finally(() => {
  3472. this.renderHighestPriority();
  3473. }).catch(reason => {
  3474. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  3475. return;
  3476. }
  3477. console.error(`renderView: "${reason}"`);
  3478. });
  3479. break;
  3480. }
  3481. return true;
  3482. }
  3483. }
  3484. exports.PDFRenderingQueue = PDFRenderingQueue;
  3485. /***/ }),
  3486. /* 9 */
  3487. /***/ ((__unused_webpack_module, exports) => {
  3488. Object.defineProperty(exports, "__esModule", ({
  3489. value: true
  3490. }));
  3491. exports.OverlayManager = void 0;
  3492. class OverlayManager {
  3493. constructor() {
  3494. this._overlays = {};
  3495. this._active = null;
  3496. this._keyDownBound = this._keyDown.bind(this);
  3497. }
  3498. get active() {
  3499. return this._active;
  3500. }
  3501. async register(name, element, callerCloseMethod = null, canForceClose = false) {
  3502. let container;
  3503. if (!name || !element || !(container = element.parentNode)) {
  3504. throw new Error("Not enough parameters.");
  3505. } else if (this._overlays[name]) {
  3506. throw new Error("The overlay is already registered.");
  3507. }
  3508. this._overlays[name] = {
  3509. element,
  3510. container,
  3511. callerCloseMethod,
  3512. canForceClose
  3513. };
  3514. }
  3515. async unregister(name) {
  3516. if (!this._overlays[name]) {
  3517. throw new Error("The overlay does not exist.");
  3518. } else if (this._active === name) {
  3519. throw new Error("The overlay cannot be removed while it is active.");
  3520. }
  3521. delete this._overlays[name];
  3522. }
  3523. async open(name) {
  3524. if (!this._overlays[name]) {
  3525. throw new Error("The overlay does not exist.");
  3526. } else if (this._active) {
  3527. if (this._overlays[name].canForceClose) {
  3528. this._closeThroughCaller();
  3529. } else if (this._active === name) {
  3530. throw new Error("The overlay is already active.");
  3531. } else {
  3532. throw new Error("Another overlay is currently active.");
  3533. }
  3534. }
  3535. this._active = name;
  3536. this._overlays[this._active].element.classList.remove("hidden");
  3537. this._overlays[this._active].container.classList.remove("hidden");
  3538. window.addEventListener("keydown", this._keyDownBound);
  3539. }
  3540. async close(name) {
  3541. if (!this._overlays[name]) {
  3542. throw new Error("The overlay does not exist.");
  3543. } else if (!this._active) {
  3544. throw new Error("The overlay is currently not active.");
  3545. } else if (this._active !== name) {
  3546. throw new Error("Another overlay is currently active.");
  3547. }
  3548. this._overlays[this._active].container.classList.add("hidden");
  3549. this._overlays[this._active].element.classList.add("hidden");
  3550. this._active = null;
  3551. window.removeEventListener("keydown", this._keyDownBound);
  3552. }
  3553. _keyDown(evt) {
  3554. if (this._active && evt.keyCode === 27) {
  3555. this._closeThroughCaller();
  3556. evt.preventDefault();
  3557. }
  3558. }
  3559. _closeThroughCaller() {
  3560. if (this._overlays[this._active].callerCloseMethod) {
  3561. this._overlays[this._active].callerCloseMethod();
  3562. }
  3563. if (this._active) {
  3564. this.close(this._active);
  3565. }
  3566. }
  3567. }
  3568. exports.OverlayManager = OverlayManager;
  3569. /***/ }),
  3570. /* 10 */
  3571. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3572. Object.defineProperty(exports, "__esModule", ({
  3573. value: true
  3574. }));
  3575. exports.PasswordPrompt = void 0;
  3576. var _pdfjsLib = __webpack_require__(5);
  3577. class PasswordPrompt {
  3578. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3579. this.overlayName = options.overlayName;
  3580. this.container = options.container;
  3581. this.label = options.label;
  3582. this.input = options.input;
  3583. this.submitButton = options.submitButton;
  3584. this.cancelButton = options.cancelButton;
  3585. this.overlayManager = overlayManager;
  3586. this.l10n = l10n;
  3587. this._isViewerEmbedded = isViewerEmbedded;
  3588. this.updateCallback = null;
  3589. this.reason = null;
  3590. this.submitButton.addEventListener("click", this.verify.bind(this));
  3591. this.cancelButton.addEventListener("click", this.close.bind(this));
  3592. this.input.addEventListener("keydown", e => {
  3593. if (e.keyCode === 13) {
  3594. this.verify();
  3595. }
  3596. });
  3597. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  3598. }
  3599. async open() {
  3600. await this.overlayManager.open(this.overlayName);
  3601. const passwordIncorrect = this.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3602. if (!this._isViewerEmbedded || passwordIncorrect) {
  3603. this.input.focus();
  3604. }
  3605. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3606. }
  3607. close() {
  3608. this.overlayManager.close(this.overlayName).then(() => {
  3609. this.input.value = "";
  3610. });
  3611. }
  3612. verify() {
  3613. const password = this.input.value;
  3614. if (password?.length > 0) {
  3615. this.close();
  3616. this.updateCallback(password);
  3617. }
  3618. }
  3619. setUpdateCallback(updateCallback, reason) {
  3620. this.updateCallback = updateCallback;
  3621. this.reason = reason;
  3622. }
  3623. }
  3624. exports.PasswordPrompt = PasswordPrompt;
  3625. /***/ }),
  3626. /* 11 */
  3627. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3628. Object.defineProperty(exports, "__esModule", ({
  3629. value: true
  3630. }));
  3631. exports.PDFAttachmentViewer = void 0;
  3632. var _pdfjsLib = __webpack_require__(5);
  3633. var _base_tree_viewer = __webpack_require__(12);
  3634. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  3635. constructor(options) {
  3636. super(options);
  3637. this.downloadManager = options.downloadManager;
  3638. this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
  3639. }
  3640. reset(keepRenderedCapability = false) {
  3641. super.reset();
  3642. this._attachments = null;
  3643. if (!keepRenderedCapability) {
  3644. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  3645. }
  3646. if (this._pendingDispatchEvent) {
  3647. clearTimeout(this._pendingDispatchEvent);
  3648. }
  3649. this._pendingDispatchEvent = null;
  3650. }
  3651. _dispatchEvent(attachmentsCount) {
  3652. this._renderedCapability.resolve();
  3653. if (this._pendingDispatchEvent) {
  3654. clearTimeout(this._pendingDispatchEvent);
  3655. this._pendingDispatchEvent = null;
  3656. }
  3657. if (attachmentsCount === 0) {
  3658. this._pendingDispatchEvent = setTimeout(() => {
  3659. this.eventBus.dispatch("attachmentsloaded", {
  3660. source: this,
  3661. attachmentsCount: 0
  3662. });
  3663. this._pendingDispatchEvent = null;
  3664. });
  3665. return;
  3666. }
  3667. this.eventBus.dispatch("attachmentsloaded", {
  3668. source: this,
  3669. attachmentsCount
  3670. });
  3671. }
  3672. _bindLink(element, {
  3673. content,
  3674. filename
  3675. }) {
  3676. element.onclick = () => {
  3677. this.downloadManager.openOrDownloadData(element, content, filename);
  3678. return false;
  3679. };
  3680. }
  3681. render({
  3682. attachments,
  3683. keepRenderedCapability = false
  3684. }) {
  3685. if (this._attachments) {
  3686. this.reset(keepRenderedCapability);
  3687. }
  3688. this._attachments = attachments || null;
  3689. if (!attachments) {
  3690. this._dispatchEvent(0);
  3691. return;
  3692. }
  3693. const names = Object.keys(attachments).sort(function (a, b) {
  3694. return a.toLowerCase().localeCompare(b.toLowerCase());
  3695. });
  3696. const fragment = document.createDocumentFragment();
  3697. let attachmentsCount = 0;
  3698. for (const name of names) {
  3699. const item = attachments[name];
  3700. const content = item.content,
  3701. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  3702. const div = document.createElement("div");
  3703. div.className = "treeItem";
  3704. const element = document.createElement("a");
  3705. this._bindLink(element, {
  3706. content,
  3707. filename
  3708. });
  3709. element.textContent = this._normalizeTextContent(filename);
  3710. div.appendChild(element);
  3711. fragment.appendChild(div);
  3712. attachmentsCount++;
  3713. }
  3714. this._finishRendering(fragment, attachmentsCount);
  3715. }
  3716. _appendAttachment({
  3717. id,
  3718. filename,
  3719. content
  3720. }) {
  3721. const renderedPromise = this._renderedCapability.promise;
  3722. renderedPromise.then(() => {
  3723. if (renderedPromise !== this._renderedCapability.promise) {
  3724. return;
  3725. }
  3726. let attachments = this._attachments;
  3727. if (!attachments) {
  3728. attachments = Object.create(null);
  3729. } else {
  3730. for (const name in attachments) {
  3731. if (id === name) {
  3732. return;
  3733. }
  3734. }
  3735. }
  3736. attachments[id] = {
  3737. filename,
  3738. content
  3739. };
  3740. this.render({
  3741. attachments,
  3742. keepRenderedCapability: true
  3743. });
  3744. });
  3745. }
  3746. }
  3747. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  3748. /***/ }),
  3749. /* 12 */
  3750. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3751. Object.defineProperty(exports, "__esModule", ({
  3752. value: true
  3753. }));
  3754. exports.BaseTreeViewer = void 0;
  3755. var _pdfjsLib = __webpack_require__(5);
  3756. const TREEITEM_OFFSET_TOP = -100;
  3757. const TREEITEM_SELECTED_CLASS = "selected";
  3758. class BaseTreeViewer {
  3759. constructor(options) {
  3760. if (this.constructor === BaseTreeViewer) {
  3761. throw new Error("Cannot initialize BaseTreeViewer.");
  3762. }
  3763. this.container = options.container;
  3764. this.eventBus = options.eventBus;
  3765. this.reset();
  3766. }
  3767. reset() {
  3768. this._pdfDocument = null;
  3769. this._lastToggleIsShow = true;
  3770. this._currentTreeItem = null;
  3771. this.container.textContent = "";
  3772. this.container.classList.remove("treeWithDeepNesting");
  3773. }
  3774. _dispatchEvent(count) {
  3775. throw new Error("Not implemented: _dispatchEvent");
  3776. }
  3777. _bindLink(element, params) {
  3778. throw new Error("Not implemented: _bindLink");
  3779. }
  3780. _normalizeTextContent(str) {
  3781. return (0, _pdfjsLib.removeNullCharacters)(str) || "\u2013";
  3782. }
  3783. _addToggleButton(div, hidden = false) {
  3784. const toggler = document.createElement("div");
  3785. toggler.className = "treeItemToggler";
  3786. if (hidden) {
  3787. toggler.classList.add("treeItemsHidden");
  3788. }
  3789. toggler.onclick = evt => {
  3790. evt.stopPropagation();
  3791. toggler.classList.toggle("treeItemsHidden");
  3792. if (evt.shiftKey) {
  3793. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  3794. this._toggleTreeItem(div, shouldShowAll);
  3795. }
  3796. };
  3797. div.insertBefore(toggler, div.firstChild);
  3798. }
  3799. _toggleTreeItem(root, show = false) {
  3800. this._lastToggleIsShow = show;
  3801. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  3802. toggler.classList.toggle("treeItemsHidden", !show);
  3803. }
  3804. }
  3805. _toggleAllTreeItems() {
  3806. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  3807. }
  3808. _finishRendering(fragment, count, hasAnyNesting = false) {
  3809. if (hasAnyNesting) {
  3810. this.container.classList.add("treeWithDeepNesting");
  3811. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  3812. }
  3813. this.container.appendChild(fragment);
  3814. this._dispatchEvent(count);
  3815. }
  3816. render(params) {
  3817. throw new Error("Not implemented: render");
  3818. }
  3819. _updateCurrentTreeItem(treeItem = null) {
  3820. if (this._currentTreeItem) {
  3821. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  3822. this._currentTreeItem = null;
  3823. }
  3824. if (treeItem) {
  3825. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  3826. this._currentTreeItem = treeItem;
  3827. }
  3828. }
  3829. _scrollToCurrentTreeItem(treeItem) {
  3830. if (!treeItem) {
  3831. return;
  3832. }
  3833. let currentNode = treeItem.parentNode;
  3834. while (currentNode && currentNode !== this.container) {
  3835. if (currentNode.classList.contains("treeItem")) {
  3836. const toggler = currentNode.firstElementChild;
  3837. toggler?.classList.remove("treeItemsHidden");
  3838. }
  3839. currentNode = currentNode.parentNode;
  3840. }
  3841. this._updateCurrentTreeItem(treeItem);
  3842. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  3843. }
  3844. }
  3845. exports.BaseTreeViewer = BaseTreeViewer;
  3846. /***/ }),
  3847. /* 13 */
  3848. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3849. Object.defineProperty(exports, "__esModule", ({
  3850. value: true
  3851. }));
  3852. exports.PDFDocumentProperties = void 0;
  3853. var _pdfjsLib = __webpack_require__(5);
  3854. var _ui_utils = __webpack_require__(4);
  3855. const DEFAULT_FIELD_CONTENT = "-";
  3856. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  3857. const US_PAGE_NAMES = {
  3858. "8.5x11": "Letter",
  3859. "8.5x14": "Legal"
  3860. };
  3861. const METRIC_PAGE_NAMES = {
  3862. "297x420": "A3",
  3863. "210x297": "A4"
  3864. };
  3865. function getPageName(size, isPortrait, pageNames) {
  3866. const width = isPortrait ? size.width : size.height;
  3867. const height = isPortrait ? size.height : size.width;
  3868. return pageNames[`${width}x${height}`];
  3869. }
  3870. class PDFDocumentProperties {
  3871. constructor({
  3872. overlayName,
  3873. fields,
  3874. container,
  3875. closeButton
  3876. }, overlayManager, eventBus, l10n) {
  3877. this.overlayName = overlayName;
  3878. this.fields = fields;
  3879. this.container = container;
  3880. this.overlayManager = overlayManager;
  3881. this.l10n = l10n;
  3882. this._reset();
  3883. closeButton.addEventListener("click", this.close.bind(this));
  3884. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  3885. eventBus._on("pagechanging", evt => {
  3886. this._currentPageNumber = evt.pageNumber;
  3887. });
  3888. eventBus._on("rotationchanging", evt => {
  3889. this._pagesRotation = evt.pagesRotation;
  3890. });
  3891. this._isNonMetricLocale = true;
  3892. l10n.getLanguage().then(locale => {
  3893. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  3894. });
  3895. }
  3896. async open() {
  3897. const freezeFieldData = data => {
  3898. Object.defineProperty(this, "fieldData", {
  3899. value: Object.freeze(data),
  3900. writable: false,
  3901. enumerable: true,
  3902. configurable: true
  3903. });
  3904. };
  3905. await Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]);
  3906. const currentPageNumber = this._currentPageNumber;
  3907. const pagesRotation = this._pagesRotation;
  3908. if (this.fieldData && currentPageNumber === this.fieldData._currentPageNumber && pagesRotation === this.fieldData._pagesRotation) {
  3909. this._updateUI();
  3910. return;
  3911. }
  3912. const {
  3913. info,
  3914. contentDispositionFilename,
  3915. contentLength
  3916. } = await this.pdfDocument.getMetadata();
  3917. 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 => {
  3918. return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  3919. }), this._parseLinearization(info.IsLinearized)]);
  3920. freezeFieldData({
  3921. fileName,
  3922. fileSize,
  3923. title: info.Title,
  3924. author: info.Author,
  3925. subject: info.Subject,
  3926. keywords: info.Keywords,
  3927. creationDate,
  3928. modificationDate,
  3929. creator: info.Creator,
  3930. producer: info.Producer,
  3931. version: info.PDFFormatVersion,
  3932. pageCount: this.pdfDocument.numPages,
  3933. pageSize,
  3934. linearized: isLinearized,
  3935. _currentPageNumber: currentPageNumber,
  3936. _pagesRotation: pagesRotation
  3937. });
  3938. this._updateUI();
  3939. const {
  3940. length
  3941. } = await this.pdfDocument.getDownloadInfo();
  3942. if (contentLength === length) {
  3943. return;
  3944. }
  3945. const data = Object.assign(Object.create(null), this.fieldData);
  3946. data.fileSize = await this._parseFileSize(length);
  3947. freezeFieldData(data);
  3948. this._updateUI();
  3949. }
  3950. close() {
  3951. this.overlayManager.close(this.overlayName);
  3952. }
  3953. setDocument(pdfDocument, url = null) {
  3954. if (this.pdfDocument) {
  3955. this._reset();
  3956. this._updateUI(true);
  3957. }
  3958. if (!pdfDocument) {
  3959. return;
  3960. }
  3961. this.pdfDocument = pdfDocument;
  3962. this.url = url;
  3963. this._dataAvailableCapability.resolve();
  3964. }
  3965. _reset() {
  3966. this.pdfDocument = null;
  3967. this.url = null;
  3968. delete this.fieldData;
  3969. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  3970. this._currentPageNumber = 1;
  3971. this._pagesRotation = 0;
  3972. }
  3973. _updateUI(reset = false) {
  3974. if (reset || !this.fieldData) {
  3975. for (const id in this.fields) {
  3976. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  3977. }
  3978. return;
  3979. }
  3980. if (this.overlayManager.active !== this.overlayName) {
  3981. return;
  3982. }
  3983. for (const id in this.fields) {
  3984. const content = this.fieldData[id];
  3985. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  3986. }
  3987. }
  3988. async _parseFileSize(fileSize = 0) {
  3989. const kb = fileSize / 1024,
  3990. mb = kb / 1024;
  3991. if (!kb) {
  3992. return undefined;
  3993. }
  3994. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  3995. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  3996. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  3997. size_b: fileSize.toLocaleString()
  3998. });
  3999. }
  4000. async _parsePageSize(pageSizeInches, pagesRotation) {
  4001. if (!pageSizeInches) {
  4002. return undefined;
  4003. }
  4004. if (pagesRotation % 180 !== 0) {
  4005. pageSizeInches = {
  4006. width: pageSizeInches.height,
  4007. height: pageSizeInches.width
  4008. };
  4009. }
  4010. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4011. let sizeInches = {
  4012. width: Math.round(pageSizeInches.width * 100) / 100,
  4013. height: Math.round(pageSizeInches.height * 100) / 100
  4014. };
  4015. let sizeMillimeters = {
  4016. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4017. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4018. };
  4019. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4020. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4021. const exactMillimeters = {
  4022. width: pageSizeInches.width * 25.4,
  4023. height: pageSizeInches.height * 25.4
  4024. };
  4025. const intMillimeters = {
  4026. width: Math.round(sizeMillimeters.width),
  4027. height: Math.round(sizeMillimeters.height)
  4028. };
  4029. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4030. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4031. if (rawName) {
  4032. sizeInches = {
  4033. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4034. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4035. };
  4036. sizeMillimeters = intMillimeters;
  4037. }
  4038. }
  4039. }
  4040. const [{
  4041. width,
  4042. height
  4043. }, 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"}`)]);
  4044. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4045. width: width.toLocaleString(),
  4046. height: height.toLocaleString(),
  4047. unit,
  4048. name,
  4049. orientation
  4050. });
  4051. }
  4052. async _parseDate(inputDate) {
  4053. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4054. if (!dateObject) {
  4055. return undefined;
  4056. }
  4057. return this.l10n.get("document_properties_date_string", {
  4058. date: dateObject.toLocaleDateString(),
  4059. time: dateObject.toLocaleTimeString()
  4060. });
  4061. }
  4062. _parseLinearization(isLinearized) {
  4063. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4064. }
  4065. }
  4066. exports.PDFDocumentProperties = PDFDocumentProperties;
  4067. /***/ }),
  4068. /* 14 */
  4069. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4070. Object.defineProperty(exports, "__esModule", ({
  4071. value: true
  4072. }));
  4073. exports.PDFFindBar = void 0;
  4074. var _pdf_find_controller = __webpack_require__(15);
  4075. const MATCHES_COUNT_LIMIT = 1000;
  4076. class PDFFindBar {
  4077. constructor(options, eventBus, l10n) {
  4078. this.opened = false;
  4079. this.bar = options.bar;
  4080. this.toggleButton = options.toggleButton;
  4081. this.findField = options.findField;
  4082. this.highlightAll = options.highlightAllCheckbox;
  4083. this.caseSensitive = options.caseSensitiveCheckbox;
  4084. this.entireWord = options.entireWordCheckbox;
  4085. this.findMsg = options.findMsg;
  4086. this.findResultsCount = options.findResultsCount;
  4087. this.findPreviousButton = options.findPreviousButton;
  4088. this.findNextButton = options.findNextButton;
  4089. this.eventBus = eventBus;
  4090. this.l10n = l10n;
  4091. this.toggleButton.addEventListener("click", () => {
  4092. this.toggle();
  4093. });
  4094. this.findField.addEventListener("input", () => {
  4095. this.dispatchEvent("");
  4096. });
  4097. this.bar.addEventListener("keydown", e => {
  4098. switch (e.keyCode) {
  4099. case 13:
  4100. if (e.target === this.findField) {
  4101. this.dispatchEvent("again", e.shiftKey);
  4102. }
  4103. break;
  4104. case 27:
  4105. this.close();
  4106. break;
  4107. }
  4108. });
  4109. this.findPreviousButton.addEventListener("click", () => {
  4110. this.dispatchEvent("again", true);
  4111. });
  4112. this.findNextButton.addEventListener("click", () => {
  4113. this.dispatchEvent("again", false);
  4114. });
  4115. this.highlightAll.addEventListener("click", () => {
  4116. this.dispatchEvent("highlightallchange");
  4117. });
  4118. this.caseSensitive.addEventListener("click", () => {
  4119. this.dispatchEvent("casesensitivitychange");
  4120. });
  4121. this.entireWord.addEventListener("click", () => {
  4122. this.dispatchEvent("entirewordchange");
  4123. });
  4124. this.eventBus._on("resize", this._adjustWidth.bind(this));
  4125. }
  4126. reset() {
  4127. this.updateUIState();
  4128. }
  4129. dispatchEvent(type, findPrev) {
  4130. this.eventBus.dispatch("find", {
  4131. source: this,
  4132. type,
  4133. query: this.findField.value,
  4134. phraseSearch: true,
  4135. caseSensitive: this.caseSensitive.checked,
  4136. entireWord: this.entireWord.checked,
  4137. highlightAll: this.highlightAll.checked,
  4138. findPrevious: findPrev
  4139. });
  4140. }
  4141. updateUIState(state, previous, matchesCount) {
  4142. let findMsg = Promise.resolve("");
  4143. let status = "";
  4144. switch (state) {
  4145. case _pdf_find_controller.FindState.FOUND:
  4146. break;
  4147. case _pdf_find_controller.FindState.PENDING:
  4148. status = "pending";
  4149. break;
  4150. case _pdf_find_controller.FindState.NOT_FOUND:
  4151. findMsg = this.l10n.get("find_not_found");
  4152. status = "notFound";
  4153. break;
  4154. case _pdf_find_controller.FindState.WRAPPED:
  4155. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4156. break;
  4157. }
  4158. this.findField.setAttribute("data-status", status);
  4159. findMsg.then(msg => {
  4160. this.findMsg.textContent = msg;
  4161. this._adjustWidth();
  4162. });
  4163. this.updateResultsCount(matchesCount);
  4164. }
  4165. updateResultsCount({
  4166. current = 0,
  4167. total = 0
  4168. } = {}) {
  4169. const limit = MATCHES_COUNT_LIMIT;
  4170. let matchCountMsg = Promise.resolve("");
  4171. if (total > 0) {
  4172. if (total > limit) {
  4173. let key = "find_match_count_limit";
  4174. matchCountMsg = this.l10n.get(key, {
  4175. limit
  4176. });
  4177. } else {
  4178. let key = "find_match_count";
  4179. matchCountMsg = this.l10n.get(key, {
  4180. current,
  4181. total
  4182. });
  4183. }
  4184. }
  4185. matchCountMsg.then(msg => {
  4186. this.findResultsCount.textContent = msg;
  4187. this.findResultsCount.classList.toggle("hidden", !total);
  4188. this._adjustWidth();
  4189. });
  4190. }
  4191. open() {
  4192. if (!this.opened) {
  4193. this.opened = true;
  4194. this.toggleButton.classList.add("toggled");
  4195. this.toggleButton.setAttribute("aria-expanded", "true");
  4196. this.bar.classList.remove("hidden");
  4197. }
  4198. this.findField.select();
  4199. this.findField.focus();
  4200. this._adjustWidth();
  4201. }
  4202. close() {
  4203. if (!this.opened) {
  4204. return;
  4205. }
  4206. this.opened = false;
  4207. this.toggleButton.classList.remove("toggled");
  4208. this.toggleButton.setAttribute("aria-expanded", "false");
  4209. this.bar.classList.add("hidden");
  4210. this.eventBus.dispatch("findbarclose", {
  4211. source: this
  4212. });
  4213. }
  4214. toggle() {
  4215. if (this.opened) {
  4216. this.close();
  4217. } else {
  4218. this.open();
  4219. }
  4220. }
  4221. _adjustWidth() {
  4222. if (!this.opened) {
  4223. return;
  4224. }
  4225. this.bar.classList.remove("wrapContainers");
  4226. const findbarHeight = this.bar.clientHeight;
  4227. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4228. if (findbarHeight > inputContainerHeight) {
  4229. this.bar.classList.add("wrapContainers");
  4230. }
  4231. }
  4232. }
  4233. exports.PDFFindBar = PDFFindBar;
  4234. /***/ }),
  4235. /* 15 */
  4236. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4237. Object.defineProperty(exports, "__esModule", ({
  4238. value: true
  4239. }));
  4240. exports.PDFFindController = exports.FindState = void 0;
  4241. var _pdfjsLib = __webpack_require__(5);
  4242. var _pdf_find_utils = __webpack_require__(16);
  4243. var _ui_utils = __webpack_require__(4);
  4244. const FindState = {
  4245. FOUND: 0,
  4246. NOT_FOUND: 1,
  4247. WRAPPED: 2,
  4248. PENDING: 3
  4249. };
  4250. exports.FindState = FindState;
  4251. const FIND_TIMEOUT = 250;
  4252. const MATCH_SCROLL_OFFSET_TOP = -50;
  4253. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4254. const CHARACTERS_TO_NORMALIZE = {
  4255. "\u2018": "'",
  4256. "\u2019": "'",
  4257. "\u201A": "'",
  4258. "\u201B": "'",
  4259. "\u201C": '"',
  4260. "\u201D": '"',
  4261. "\u201E": '"',
  4262. "\u201F": '"',
  4263. "\u00BC": "1/4",
  4264. "\u00BD": "1/2",
  4265. "\u00BE": "3/4"
  4266. };
  4267. let normalizationRegex = null;
  4268. function normalize(text) {
  4269. if (!normalizationRegex) {
  4270. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4271. normalizationRegex = new RegExp(`[${replace}]`, "g");
  4272. }
  4273. let diffs = null;
  4274. const normalizedText = text.replace(normalizationRegex, function (ch, index) {
  4275. const normalizedCh = CHARACTERS_TO_NORMALIZE[ch],
  4276. diff = normalizedCh.length - ch.length;
  4277. if (diff !== 0) {
  4278. (diffs || (diffs = [])).push([index, diff]);
  4279. }
  4280. return normalizedCh;
  4281. });
  4282. return [normalizedText, diffs];
  4283. }
  4284. function getOriginalIndex(matchIndex, diffs = null) {
  4285. if (!diffs) {
  4286. return matchIndex;
  4287. }
  4288. let totalDiff = 0;
  4289. for (const [index, diff] of diffs) {
  4290. const currentIndex = index + totalDiff;
  4291. if (currentIndex >= matchIndex) {
  4292. break;
  4293. }
  4294. if (currentIndex + diff > matchIndex) {
  4295. totalDiff += matchIndex - currentIndex;
  4296. break;
  4297. }
  4298. totalDiff += diff;
  4299. }
  4300. return matchIndex - totalDiff;
  4301. }
  4302. class PDFFindController {
  4303. constructor({
  4304. linkService,
  4305. eventBus
  4306. }) {
  4307. this._linkService = linkService;
  4308. this._eventBus = eventBus;
  4309. this._reset();
  4310. eventBus._on("findbarclose", this._onFindBarClose.bind(this));
  4311. }
  4312. get highlightMatches() {
  4313. return this._highlightMatches;
  4314. }
  4315. get pageMatches() {
  4316. return this._pageMatches;
  4317. }
  4318. get pageMatchesLength() {
  4319. return this._pageMatchesLength;
  4320. }
  4321. get selected() {
  4322. return this._selected;
  4323. }
  4324. get state() {
  4325. return this._state;
  4326. }
  4327. setDocument(pdfDocument) {
  4328. if (this._pdfDocument) {
  4329. this._reset();
  4330. }
  4331. if (!pdfDocument) {
  4332. return;
  4333. }
  4334. this._pdfDocument = pdfDocument;
  4335. this._firstPageCapability.resolve();
  4336. }
  4337. executeCommand(cmd, state) {
  4338. if (!state) {
  4339. return;
  4340. }
  4341. const pdfDocument = this._pdfDocument;
  4342. if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
  4343. this._dirtyMatch = true;
  4344. }
  4345. this._state = state;
  4346. if (cmd !== "findhighlightallchange") {
  4347. this._updateUIState(FindState.PENDING);
  4348. }
  4349. this._firstPageCapability.promise.then(() => {
  4350. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4351. return;
  4352. }
  4353. this._extractText();
  4354. const findbarClosed = !this._highlightMatches;
  4355. const pendingTimeout = !!this._findTimeout;
  4356. if (this._findTimeout) {
  4357. clearTimeout(this._findTimeout);
  4358. this._findTimeout = null;
  4359. }
  4360. if (cmd === "find") {
  4361. this._findTimeout = setTimeout(() => {
  4362. this._nextMatch();
  4363. this._findTimeout = null;
  4364. }, FIND_TIMEOUT);
  4365. } else if (this._dirtyMatch) {
  4366. this._nextMatch();
  4367. } else if (cmd === "findagain") {
  4368. this._nextMatch();
  4369. if (findbarClosed && this._state.highlightAll) {
  4370. this._updateAllPages();
  4371. }
  4372. } else if (cmd === "findhighlightallchange") {
  4373. if (pendingTimeout) {
  4374. this._nextMatch();
  4375. } else {
  4376. this._highlightMatches = true;
  4377. }
  4378. this._updateAllPages();
  4379. } else {
  4380. this._nextMatch();
  4381. }
  4382. });
  4383. }
  4384. scrollMatchIntoView({
  4385. element = null,
  4386. pageIndex = -1,
  4387. matchIndex = -1
  4388. }) {
  4389. if (!this._scrollMatches || !element) {
  4390. return;
  4391. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4392. return;
  4393. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4394. return;
  4395. }
  4396. this._scrollMatches = false;
  4397. const spot = {
  4398. top: MATCH_SCROLL_OFFSET_TOP,
  4399. left: MATCH_SCROLL_OFFSET_LEFT
  4400. };
  4401. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4402. }
  4403. _reset() {
  4404. this._highlightMatches = false;
  4405. this._scrollMatches = false;
  4406. this._pdfDocument = null;
  4407. this._pageMatches = [];
  4408. this._pageMatchesLength = [];
  4409. this._state = null;
  4410. this._selected = {
  4411. pageIdx: -1,
  4412. matchIdx: -1
  4413. };
  4414. this._offset = {
  4415. pageIdx: null,
  4416. matchIdx: null,
  4417. wrapped: false
  4418. };
  4419. this._extractTextPromises = [];
  4420. this._pageContents = [];
  4421. this._pageDiffs = [];
  4422. this._matchesCountTotal = 0;
  4423. this._pagesToSearch = null;
  4424. this._pendingFindMatches = new Set();
  4425. this._resumePageIdx = null;
  4426. this._dirtyMatch = false;
  4427. clearTimeout(this._findTimeout);
  4428. this._findTimeout = null;
  4429. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4430. }
  4431. get _query() {
  4432. if (this._state.query !== this._rawQuery) {
  4433. this._rawQuery = this._state.query;
  4434. [this._normalizedQuery] = normalize(this._state.query);
  4435. }
  4436. return this._normalizedQuery;
  4437. }
  4438. _shouldDirtyMatch(cmd, state) {
  4439. if (state.query !== this._state.query) {
  4440. return true;
  4441. }
  4442. switch (cmd) {
  4443. case "findagain":
  4444. const pageNumber = this._selected.pageIdx + 1;
  4445. const linkService = this._linkService;
  4446. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4447. return true;
  4448. }
  4449. return false;
  4450. case "findhighlightallchange":
  4451. return false;
  4452. }
  4453. return true;
  4454. }
  4455. _prepareMatches(matchesWithLength, matches, matchesLength) {
  4456. function isSubTerm(currentIndex) {
  4457. const currentElem = matchesWithLength[currentIndex];
  4458. const nextElem = matchesWithLength[currentIndex + 1];
  4459. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  4460. currentElem.skipped = true;
  4461. return true;
  4462. }
  4463. for (let i = currentIndex - 1; i >= 0; i--) {
  4464. const prevElem = matchesWithLength[i];
  4465. if (prevElem.skipped) {
  4466. continue;
  4467. }
  4468. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  4469. break;
  4470. }
  4471. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  4472. currentElem.skipped = true;
  4473. return true;
  4474. }
  4475. }
  4476. return false;
  4477. }
  4478. matchesWithLength.sort(function (a, b) {
  4479. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  4480. });
  4481. for (let i = 0, len = matchesWithLength.length; i < len; i++) {
  4482. if (isSubTerm(i)) {
  4483. continue;
  4484. }
  4485. matches.push(matchesWithLength[i].match);
  4486. matchesLength.push(matchesWithLength[i].matchLength);
  4487. }
  4488. }
  4489. _isEntireWord(content, startIdx, length) {
  4490. if (startIdx > 0) {
  4491. const first = content.charCodeAt(startIdx);
  4492. const limit = content.charCodeAt(startIdx - 1);
  4493. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4494. return false;
  4495. }
  4496. }
  4497. const endIdx = startIdx + length - 1;
  4498. if (endIdx < content.length - 1) {
  4499. const last = content.charCodeAt(endIdx);
  4500. const limit = content.charCodeAt(endIdx + 1);
  4501. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4502. return false;
  4503. }
  4504. }
  4505. return true;
  4506. }
  4507. _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4508. const matches = [],
  4509. matchesLength = [];
  4510. const queryLen = query.length;
  4511. let matchIdx = -queryLen;
  4512. while (true) {
  4513. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  4514. if (matchIdx === -1) {
  4515. break;
  4516. }
  4517. if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
  4518. continue;
  4519. }
  4520. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4521. matchEnd = matchIdx + queryLen - 1,
  4522. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4523. matches.push(originalMatchIdx);
  4524. matchesLength.push(originalQueryLen);
  4525. }
  4526. this._pageMatches[pageIndex] = matches;
  4527. this._pageMatchesLength[pageIndex] = matchesLength;
  4528. }
  4529. _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4530. const matchesWithLength = [];
  4531. const queryArray = query.match(/\S+/g);
  4532. for (let i = 0, len = queryArray.length; i < len; i++) {
  4533. const subquery = queryArray[i];
  4534. const subqueryLen = subquery.length;
  4535. let matchIdx = -subqueryLen;
  4536. while (true) {
  4537. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  4538. if (matchIdx === -1) {
  4539. break;
  4540. }
  4541. if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
  4542. continue;
  4543. }
  4544. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4545. matchEnd = matchIdx + subqueryLen - 1,
  4546. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4547. matchesWithLength.push({
  4548. match: originalMatchIdx,
  4549. matchLength: originalQueryLen,
  4550. skipped: false
  4551. });
  4552. }
  4553. }
  4554. this._pageMatchesLength[pageIndex] = [];
  4555. this._pageMatches[pageIndex] = [];
  4556. this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
  4557. }
  4558. _calculateMatch(pageIndex) {
  4559. let pageContent = this._pageContents[pageIndex];
  4560. const pageDiffs = this._pageDiffs[pageIndex];
  4561. let query = this._query;
  4562. const {
  4563. caseSensitive,
  4564. entireWord,
  4565. phraseSearch
  4566. } = this._state;
  4567. if (query.length === 0) {
  4568. return;
  4569. }
  4570. if (!caseSensitive) {
  4571. pageContent = pageContent.toLowerCase();
  4572. query = query.toLowerCase();
  4573. }
  4574. if (phraseSearch) {
  4575. this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4576. } else {
  4577. this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4578. }
  4579. if (this._state.highlightAll) {
  4580. this._updatePage(pageIndex);
  4581. }
  4582. if (this._resumePageIdx === pageIndex) {
  4583. this._resumePageIdx = null;
  4584. this._nextPageMatch();
  4585. }
  4586. const pageMatchesCount = this._pageMatches[pageIndex].length;
  4587. if (pageMatchesCount > 0) {
  4588. this._matchesCountTotal += pageMatchesCount;
  4589. this._updateUIResultsCount();
  4590. }
  4591. }
  4592. _extractText() {
  4593. if (this._extractTextPromises.length > 0) {
  4594. return;
  4595. }
  4596. let promise = Promise.resolve();
  4597. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  4598. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  4599. this._extractTextPromises[i] = extractTextCapability.promise;
  4600. promise = promise.then(() => {
  4601. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  4602. return pdfPage.getTextContent({
  4603. normalizeWhitespace: true
  4604. });
  4605. }).then(textContent => {
  4606. const textItems = textContent.items;
  4607. const strBuf = [];
  4608. for (let j = 0, jj = textItems.length; j < jj; j++) {
  4609. strBuf.push(textItems[j].str);
  4610. }
  4611. [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""));
  4612. extractTextCapability.resolve(i);
  4613. }, reason => {
  4614. console.error(`Unable to get text content for page ${i + 1}`, reason);
  4615. this._pageContents[i] = "";
  4616. this._pageDiffs[i] = null;
  4617. extractTextCapability.resolve(i);
  4618. });
  4619. });
  4620. }
  4621. }
  4622. _updatePage(index) {
  4623. if (this._scrollMatches && this._selected.pageIdx === index) {
  4624. this._linkService.page = index + 1;
  4625. }
  4626. this._eventBus.dispatch("updatetextlayermatches", {
  4627. source: this,
  4628. pageIndex: index
  4629. });
  4630. }
  4631. _updateAllPages() {
  4632. this._eventBus.dispatch("updatetextlayermatches", {
  4633. source: this,
  4634. pageIndex: -1
  4635. });
  4636. }
  4637. _nextMatch() {
  4638. const previous = this._state.findPrevious;
  4639. const currentPageIndex = this._linkService.page - 1;
  4640. const numPages = this._linkService.pagesCount;
  4641. this._highlightMatches = true;
  4642. if (this._dirtyMatch) {
  4643. this._dirtyMatch = false;
  4644. this._selected.pageIdx = this._selected.matchIdx = -1;
  4645. this._offset.pageIdx = currentPageIndex;
  4646. this._offset.matchIdx = null;
  4647. this._offset.wrapped = false;
  4648. this._resumePageIdx = null;
  4649. this._pageMatches.length = 0;
  4650. this._pageMatchesLength.length = 0;
  4651. this._matchesCountTotal = 0;
  4652. this._updateAllPages();
  4653. for (let i = 0; i < numPages; i++) {
  4654. if (this._pendingFindMatches.has(i)) {
  4655. continue;
  4656. }
  4657. this._pendingFindMatches.add(i);
  4658. this._extractTextPromises[i].then(pageIdx => {
  4659. this._pendingFindMatches.delete(pageIdx);
  4660. this._calculateMatch(pageIdx);
  4661. });
  4662. }
  4663. }
  4664. if (this._query === "") {
  4665. this._updateUIState(FindState.FOUND);
  4666. return;
  4667. }
  4668. if (this._resumePageIdx) {
  4669. return;
  4670. }
  4671. const offset = this._offset;
  4672. this._pagesToSearch = numPages;
  4673. if (offset.matchIdx !== null) {
  4674. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  4675. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  4676. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  4677. this._updateMatch(true);
  4678. return;
  4679. }
  4680. this._advanceOffsetPage(previous);
  4681. }
  4682. this._nextPageMatch();
  4683. }
  4684. _matchesReady(matches) {
  4685. const offset = this._offset;
  4686. const numMatches = matches.length;
  4687. const previous = this._state.findPrevious;
  4688. if (numMatches) {
  4689. offset.matchIdx = previous ? numMatches - 1 : 0;
  4690. this._updateMatch(true);
  4691. return true;
  4692. }
  4693. this._advanceOffsetPage(previous);
  4694. if (offset.wrapped) {
  4695. offset.matchIdx = null;
  4696. if (this._pagesToSearch < 0) {
  4697. this._updateMatch(false);
  4698. return true;
  4699. }
  4700. }
  4701. return false;
  4702. }
  4703. _nextPageMatch() {
  4704. if (this._resumePageIdx !== null) {
  4705. console.error("There can only be one pending page.");
  4706. }
  4707. let matches = null;
  4708. do {
  4709. const pageIdx = this._offset.pageIdx;
  4710. matches = this._pageMatches[pageIdx];
  4711. if (!matches) {
  4712. this._resumePageIdx = pageIdx;
  4713. break;
  4714. }
  4715. } while (!this._matchesReady(matches));
  4716. }
  4717. _advanceOffsetPage(previous) {
  4718. const offset = this._offset;
  4719. const numPages = this._linkService.pagesCount;
  4720. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  4721. offset.matchIdx = null;
  4722. this._pagesToSearch--;
  4723. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  4724. offset.pageIdx = previous ? numPages - 1 : 0;
  4725. offset.wrapped = true;
  4726. }
  4727. }
  4728. _updateMatch(found = false) {
  4729. let state = FindState.NOT_FOUND;
  4730. const wrapped = this._offset.wrapped;
  4731. this._offset.wrapped = false;
  4732. if (found) {
  4733. const previousPage = this._selected.pageIdx;
  4734. this._selected.pageIdx = this._offset.pageIdx;
  4735. this._selected.matchIdx = this._offset.matchIdx;
  4736. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  4737. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  4738. this._updatePage(previousPage);
  4739. }
  4740. }
  4741. this._updateUIState(state, this._state.findPrevious);
  4742. if (this._selected.pageIdx !== -1) {
  4743. this._scrollMatches = true;
  4744. this._updatePage(this._selected.pageIdx);
  4745. }
  4746. }
  4747. _onFindBarClose(evt) {
  4748. const pdfDocument = this._pdfDocument;
  4749. this._firstPageCapability.promise.then(() => {
  4750. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4751. return;
  4752. }
  4753. if (this._findTimeout) {
  4754. clearTimeout(this._findTimeout);
  4755. this._findTimeout = null;
  4756. }
  4757. if (this._resumePageIdx) {
  4758. this._resumePageIdx = null;
  4759. this._dirtyMatch = true;
  4760. }
  4761. this._updateUIState(FindState.FOUND);
  4762. this._highlightMatches = false;
  4763. this._updateAllPages();
  4764. });
  4765. }
  4766. _requestMatchesCount() {
  4767. const {
  4768. pageIdx,
  4769. matchIdx
  4770. } = this._selected;
  4771. let current = 0,
  4772. total = this._matchesCountTotal;
  4773. if (matchIdx !== -1) {
  4774. for (let i = 0; i < pageIdx; i++) {
  4775. current += this._pageMatches[i]?.length || 0;
  4776. }
  4777. current += matchIdx + 1;
  4778. }
  4779. if (current < 1 || current > total) {
  4780. current = total = 0;
  4781. }
  4782. return {
  4783. current,
  4784. total
  4785. };
  4786. }
  4787. _updateUIResultsCount() {
  4788. this._eventBus.dispatch("updatefindmatchescount", {
  4789. source: this,
  4790. matchesCount: this._requestMatchesCount()
  4791. });
  4792. }
  4793. _updateUIState(state, previous) {
  4794. this._eventBus.dispatch("updatefindcontrolstate", {
  4795. source: this,
  4796. state,
  4797. previous,
  4798. matchesCount: this._requestMatchesCount(),
  4799. rawQuery: this._state?.query ?? null
  4800. });
  4801. }
  4802. }
  4803. exports.PDFFindController = PDFFindController;
  4804. /***/ }),
  4805. /* 16 */
  4806. /***/ ((__unused_webpack_module, exports) => {
  4807. Object.defineProperty(exports, "__esModule", ({
  4808. value: true
  4809. }));
  4810. exports.getCharacterType = getCharacterType;
  4811. exports.CharacterType = void 0;
  4812. const CharacterType = {
  4813. SPACE: 0,
  4814. ALPHA_LETTER: 1,
  4815. PUNCT: 2,
  4816. HAN_LETTER: 3,
  4817. KATAKANA_LETTER: 4,
  4818. HIRAGANA_LETTER: 5,
  4819. HALFWIDTH_KATAKANA_LETTER: 6,
  4820. THAI_LETTER: 7
  4821. };
  4822. exports.CharacterType = CharacterType;
  4823. function isAlphabeticalScript(charCode) {
  4824. return charCode < 0x2e80;
  4825. }
  4826. function isAscii(charCode) {
  4827. return (charCode & 0xff80) === 0;
  4828. }
  4829. function isAsciiAlpha(charCode) {
  4830. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  4831. }
  4832. function isAsciiDigit(charCode) {
  4833. return charCode >= 0x30 && charCode <= 0x39;
  4834. }
  4835. function isAsciiSpace(charCode) {
  4836. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  4837. }
  4838. function isHan(charCode) {
  4839. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  4840. }
  4841. function isKatakana(charCode) {
  4842. return charCode >= 0x30a0 && charCode <= 0x30ff;
  4843. }
  4844. function isHiragana(charCode) {
  4845. return charCode >= 0x3040 && charCode <= 0x309f;
  4846. }
  4847. function isHalfwidthKatakana(charCode) {
  4848. return charCode >= 0xff60 && charCode <= 0xff9f;
  4849. }
  4850. function isThai(charCode) {
  4851. return (charCode & 0xff80) === 0x0e00;
  4852. }
  4853. function getCharacterType(charCode) {
  4854. if (isAlphabeticalScript(charCode)) {
  4855. if (isAscii(charCode)) {
  4856. if (isAsciiSpace(charCode)) {
  4857. return CharacterType.SPACE;
  4858. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  4859. return CharacterType.ALPHA_LETTER;
  4860. }
  4861. return CharacterType.PUNCT;
  4862. } else if (isThai(charCode)) {
  4863. return CharacterType.THAI_LETTER;
  4864. } else if (charCode === 0xa0) {
  4865. return CharacterType.SPACE;
  4866. }
  4867. return CharacterType.ALPHA_LETTER;
  4868. }
  4869. if (isHan(charCode)) {
  4870. return CharacterType.HAN_LETTER;
  4871. } else if (isKatakana(charCode)) {
  4872. return CharacterType.KATAKANA_LETTER;
  4873. } else if (isHiragana(charCode)) {
  4874. return CharacterType.HIRAGANA_LETTER;
  4875. } else if (isHalfwidthKatakana(charCode)) {
  4876. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  4877. }
  4878. return CharacterType.ALPHA_LETTER;
  4879. }
  4880. /***/ }),
  4881. /* 17 */
  4882. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4883. Object.defineProperty(exports, "__esModule", ({
  4884. value: true
  4885. }));
  4886. exports.isDestArraysEqual = isDestArraysEqual;
  4887. exports.isDestHashesEqual = isDestHashesEqual;
  4888. exports.PDFHistory = void 0;
  4889. var _ui_utils = __webpack_require__(4);
  4890. const HASH_CHANGE_TIMEOUT = 1000;
  4891. const POSITION_UPDATED_THRESHOLD = 50;
  4892. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  4893. function getCurrentHash() {
  4894. return document.location.hash;
  4895. }
  4896. class PDFHistory {
  4897. constructor({
  4898. linkService,
  4899. eventBus
  4900. }) {
  4901. this.linkService = linkService;
  4902. this.eventBus = eventBus;
  4903. this._initialized = false;
  4904. this._fingerprint = "";
  4905. this.reset();
  4906. this._boundEvents = null;
  4907. this._isViewerInPresentationMode = false;
  4908. this.eventBus._on("presentationmodechanged", evt => {
  4909. this._isViewerInPresentationMode = evt.state !== _ui_utils.PresentationModeState.NORMAL;
  4910. });
  4911. this.eventBus._on("pagesinit", () => {
  4912. this._isPagesLoaded = false;
  4913. this.eventBus._on("pagesloaded", evt => {
  4914. this._isPagesLoaded = !!evt.pagesCount;
  4915. }, {
  4916. once: true
  4917. });
  4918. });
  4919. }
  4920. initialize({
  4921. fingerprint,
  4922. resetHistory = false,
  4923. updateUrl = false
  4924. }) {
  4925. if (!fingerprint || typeof fingerprint !== "string") {
  4926. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  4927. return;
  4928. }
  4929. if (this._initialized) {
  4930. this.reset();
  4931. }
  4932. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  4933. this._fingerprint = fingerprint;
  4934. this._updateUrl = updateUrl === true;
  4935. this._initialized = true;
  4936. this._bindEvents();
  4937. const state = window.history.state;
  4938. this._popStateInProgress = false;
  4939. this._blockHashChange = 0;
  4940. this._currentHash = getCurrentHash();
  4941. this._numPositionUpdates = 0;
  4942. this._uid = this._maxUid = 0;
  4943. this._destination = null;
  4944. this._position = null;
  4945. if (!this._isValidState(state, true) || resetHistory) {
  4946. const {
  4947. hash,
  4948. page,
  4949. rotation
  4950. } = this._parseCurrentHash(true);
  4951. if (!hash || reInitialized || resetHistory) {
  4952. this._pushOrReplaceState(null, true);
  4953. return;
  4954. }
  4955. this._pushOrReplaceState({
  4956. hash,
  4957. page,
  4958. rotation
  4959. }, true);
  4960. return;
  4961. }
  4962. const destination = state.destination;
  4963. this._updateInternalState(destination, state.uid, true);
  4964. if (destination.rotation !== undefined) {
  4965. this._initialRotation = destination.rotation;
  4966. }
  4967. if (destination.dest) {
  4968. this._initialBookmark = JSON.stringify(destination.dest);
  4969. this._destination.page = null;
  4970. } else if (destination.hash) {
  4971. this._initialBookmark = destination.hash;
  4972. } else if (destination.page) {
  4973. this._initialBookmark = `page=${destination.page}`;
  4974. }
  4975. }
  4976. reset() {
  4977. if (this._initialized) {
  4978. this._pageHide();
  4979. this._initialized = false;
  4980. this._unbindEvents();
  4981. }
  4982. if (this._updateViewareaTimeout) {
  4983. clearTimeout(this._updateViewareaTimeout);
  4984. this._updateViewareaTimeout = null;
  4985. }
  4986. this._initialBookmark = null;
  4987. this._initialRotation = null;
  4988. }
  4989. push({
  4990. namedDest = null,
  4991. explicitDest,
  4992. pageNumber
  4993. }) {
  4994. if (!this._initialized) {
  4995. return;
  4996. }
  4997. if (namedDest && typeof namedDest !== "string") {
  4998. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  4999. return;
  5000. } else if (!Array.isArray(explicitDest)) {
  5001. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5002. return;
  5003. } else if (!this._isValidPage(pageNumber)) {
  5004. if (pageNumber !== null || this._destination) {
  5005. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5006. return;
  5007. }
  5008. }
  5009. const hash = namedDest || JSON.stringify(explicitDest);
  5010. if (!hash) {
  5011. return;
  5012. }
  5013. let forceReplace = false;
  5014. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5015. if (this._destination.page) {
  5016. return;
  5017. }
  5018. forceReplace = true;
  5019. }
  5020. if (this._popStateInProgress && !forceReplace) {
  5021. return;
  5022. }
  5023. this._pushOrReplaceState({
  5024. dest: explicitDest,
  5025. hash,
  5026. page: pageNumber,
  5027. rotation: this.linkService.rotation
  5028. }, forceReplace);
  5029. if (!this._popStateInProgress) {
  5030. this._popStateInProgress = true;
  5031. Promise.resolve().then(() => {
  5032. this._popStateInProgress = false;
  5033. });
  5034. }
  5035. }
  5036. pushPage(pageNumber) {
  5037. if (!this._initialized) {
  5038. return;
  5039. }
  5040. if (!this._isValidPage(pageNumber)) {
  5041. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5042. return;
  5043. }
  5044. if (this._destination?.page === pageNumber) {
  5045. return;
  5046. }
  5047. if (this._popStateInProgress) {
  5048. return;
  5049. }
  5050. this._pushOrReplaceState({
  5051. dest: null,
  5052. hash: `page=${pageNumber}`,
  5053. page: pageNumber,
  5054. rotation: this.linkService.rotation
  5055. });
  5056. if (!this._popStateInProgress) {
  5057. this._popStateInProgress = true;
  5058. Promise.resolve().then(() => {
  5059. this._popStateInProgress = false;
  5060. });
  5061. }
  5062. }
  5063. pushCurrentPosition() {
  5064. if (!this._initialized || this._popStateInProgress) {
  5065. return;
  5066. }
  5067. this._tryPushCurrentPosition();
  5068. }
  5069. back() {
  5070. if (!this._initialized || this._popStateInProgress) {
  5071. return;
  5072. }
  5073. const state = window.history.state;
  5074. if (this._isValidState(state) && state.uid > 0) {
  5075. window.history.back();
  5076. }
  5077. }
  5078. forward() {
  5079. if (!this._initialized || this._popStateInProgress) {
  5080. return;
  5081. }
  5082. const state = window.history.state;
  5083. if (this._isValidState(state) && state.uid < this._maxUid) {
  5084. window.history.forward();
  5085. }
  5086. }
  5087. get popStateInProgress() {
  5088. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5089. }
  5090. get initialBookmark() {
  5091. return this._initialized ? this._initialBookmark : null;
  5092. }
  5093. get initialRotation() {
  5094. return this._initialized ? this._initialRotation : null;
  5095. }
  5096. _pushOrReplaceState(destination, forceReplace = false) {
  5097. const shouldReplace = forceReplace || !this._destination;
  5098. const newState = {
  5099. fingerprint: this._fingerprint,
  5100. uid: shouldReplace ? this._uid : this._uid + 1,
  5101. destination
  5102. };
  5103. this._updateInternalState(destination, newState.uid);
  5104. let newUrl;
  5105. if (this._updateUrl && destination?.hash) {
  5106. const baseUrl = document.location.href.split("#")[0];
  5107. if (!baseUrl.startsWith("file://")) {
  5108. newUrl = `${baseUrl}#${destination.hash}`;
  5109. }
  5110. }
  5111. if (shouldReplace) {
  5112. window.history.replaceState(newState, "", newUrl);
  5113. } else {
  5114. window.history.pushState(newState, "", newUrl);
  5115. }
  5116. }
  5117. _tryPushCurrentPosition(temporary = false) {
  5118. if (!this._position) {
  5119. return;
  5120. }
  5121. let position = this._position;
  5122. if (temporary) {
  5123. position = Object.assign(Object.create(null), this._position);
  5124. position.temporary = true;
  5125. }
  5126. if (!this._destination) {
  5127. this._pushOrReplaceState(position);
  5128. return;
  5129. }
  5130. if (this._destination.temporary) {
  5131. this._pushOrReplaceState(position, true);
  5132. return;
  5133. }
  5134. if (this._destination.hash === position.hash) {
  5135. return;
  5136. }
  5137. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5138. return;
  5139. }
  5140. let forceReplace = false;
  5141. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5142. if (this._destination.dest !== undefined || !this._destination.first) {
  5143. return;
  5144. }
  5145. forceReplace = true;
  5146. }
  5147. this._pushOrReplaceState(position, forceReplace);
  5148. }
  5149. _isValidPage(val) {
  5150. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5151. }
  5152. _isValidState(state, checkReload = false) {
  5153. if (!state) {
  5154. return false;
  5155. }
  5156. if (state.fingerprint !== this._fingerprint) {
  5157. if (checkReload) {
  5158. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5159. return false;
  5160. }
  5161. const [perfEntry] = performance.getEntriesByType("navigation");
  5162. if (perfEntry?.type !== "reload") {
  5163. return false;
  5164. }
  5165. } else {
  5166. return false;
  5167. }
  5168. }
  5169. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5170. return false;
  5171. }
  5172. if (state.destination === null || typeof state.destination !== "object") {
  5173. return false;
  5174. }
  5175. return true;
  5176. }
  5177. _updateInternalState(destination, uid, removeTemporary = false) {
  5178. if (this._updateViewareaTimeout) {
  5179. clearTimeout(this._updateViewareaTimeout);
  5180. this._updateViewareaTimeout = null;
  5181. }
  5182. if (removeTemporary && destination?.temporary) {
  5183. delete destination.temporary;
  5184. }
  5185. this._destination = destination;
  5186. this._uid = uid;
  5187. this._maxUid = Math.max(this._maxUid, uid);
  5188. this._numPositionUpdates = 0;
  5189. }
  5190. _parseCurrentHash(checkNameddest = false) {
  5191. const hash = unescape(getCurrentHash()).substring(1);
  5192. const params = (0, _ui_utils.parseQueryString)(hash);
  5193. const nameddest = params.nameddest || "";
  5194. let page = params.page | 0;
  5195. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5196. page = null;
  5197. }
  5198. return {
  5199. hash,
  5200. page,
  5201. rotation: this.linkService.rotation
  5202. };
  5203. }
  5204. _updateViewarea({
  5205. location
  5206. }) {
  5207. if (this._updateViewareaTimeout) {
  5208. clearTimeout(this._updateViewareaTimeout);
  5209. this._updateViewareaTimeout = null;
  5210. }
  5211. this._position = {
  5212. hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
  5213. page: this.linkService.page,
  5214. first: location.pageNumber,
  5215. rotation: location.rotation
  5216. };
  5217. if (this._popStateInProgress) {
  5218. return;
  5219. }
  5220. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5221. this._numPositionUpdates++;
  5222. }
  5223. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5224. this._updateViewareaTimeout = setTimeout(() => {
  5225. if (!this._popStateInProgress) {
  5226. this._tryPushCurrentPosition(true);
  5227. }
  5228. this._updateViewareaTimeout = null;
  5229. }, UPDATE_VIEWAREA_TIMEOUT);
  5230. }
  5231. }
  5232. _popState({
  5233. state
  5234. }) {
  5235. const newHash = getCurrentHash(),
  5236. hashChanged = this._currentHash !== newHash;
  5237. this._currentHash = newHash;
  5238. if (!state) {
  5239. this._uid++;
  5240. const {
  5241. hash,
  5242. page,
  5243. rotation
  5244. } = this._parseCurrentHash();
  5245. this._pushOrReplaceState({
  5246. hash,
  5247. page,
  5248. rotation
  5249. }, true);
  5250. return;
  5251. }
  5252. if (!this._isValidState(state)) {
  5253. return;
  5254. }
  5255. this._popStateInProgress = true;
  5256. if (hashChanged) {
  5257. this._blockHashChange++;
  5258. (0, _ui_utils.waitOnEventOrTimeout)({
  5259. target: window,
  5260. name: "hashchange",
  5261. delay: HASH_CHANGE_TIMEOUT
  5262. }).then(() => {
  5263. this._blockHashChange--;
  5264. });
  5265. }
  5266. const destination = state.destination;
  5267. this._updateInternalState(destination, state.uid, true);
  5268. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5269. this.linkService.rotation = destination.rotation;
  5270. }
  5271. if (destination.dest) {
  5272. this.linkService.goToDestination(destination.dest);
  5273. } else if (destination.hash) {
  5274. this.linkService.setHash(destination.hash);
  5275. } else if (destination.page) {
  5276. this.linkService.page = destination.page;
  5277. }
  5278. Promise.resolve().then(() => {
  5279. this._popStateInProgress = false;
  5280. });
  5281. }
  5282. _pageHide() {
  5283. if (!this._destination || this._destination.temporary) {
  5284. this._tryPushCurrentPosition();
  5285. }
  5286. }
  5287. _bindEvents() {
  5288. if (this._boundEvents) {
  5289. return;
  5290. }
  5291. this._boundEvents = {
  5292. updateViewarea: this._updateViewarea.bind(this),
  5293. popState: this._popState.bind(this),
  5294. pageHide: this._pageHide.bind(this)
  5295. };
  5296. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5297. window.addEventListener("popstate", this._boundEvents.popState);
  5298. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5299. }
  5300. _unbindEvents() {
  5301. if (!this._boundEvents) {
  5302. return;
  5303. }
  5304. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5305. window.removeEventListener("popstate", this._boundEvents.popState);
  5306. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5307. this._boundEvents = null;
  5308. }
  5309. }
  5310. exports.PDFHistory = PDFHistory;
  5311. function isDestHashesEqual(destHash, pushHash) {
  5312. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5313. return false;
  5314. }
  5315. if (destHash === pushHash) {
  5316. return true;
  5317. }
  5318. const {
  5319. nameddest
  5320. } = (0, _ui_utils.parseQueryString)(destHash);
  5321. if (nameddest === pushHash) {
  5322. return true;
  5323. }
  5324. return false;
  5325. }
  5326. function isDestArraysEqual(firstDest, secondDest) {
  5327. function isEntryEqual(first, second) {
  5328. if (typeof first !== typeof second) {
  5329. return false;
  5330. }
  5331. if (Array.isArray(first) || Array.isArray(second)) {
  5332. return false;
  5333. }
  5334. if (first !== null && typeof first === "object" && second !== null) {
  5335. if (Object.keys(first).length !== Object.keys(second).length) {
  5336. return false;
  5337. }
  5338. for (const key in first) {
  5339. if (!isEntryEqual(first[key], second[key])) {
  5340. return false;
  5341. }
  5342. }
  5343. return true;
  5344. }
  5345. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5346. }
  5347. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5348. return false;
  5349. }
  5350. if (firstDest.length !== secondDest.length) {
  5351. return false;
  5352. }
  5353. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5354. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5355. return false;
  5356. }
  5357. }
  5358. return true;
  5359. }
  5360. /***/ }),
  5361. /* 18 */
  5362. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5363. Object.defineProperty(exports, "__esModule", ({
  5364. value: true
  5365. }));
  5366. exports.PDFLayerViewer = void 0;
  5367. var _base_tree_viewer = __webpack_require__(12);
  5368. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5369. constructor(options) {
  5370. super(options);
  5371. this.l10n = options.l10n;
  5372. this.eventBus._on("resetlayers", this._resetLayers.bind(this));
  5373. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5374. }
  5375. reset() {
  5376. super.reset();
  5377. this._optionalContentConfig = null;
  5378. }
  5379. _dispatchEvent(layersCount) {
  5380. this.eventBus.dispatch("layersloaded", {
  5381. source: this,
  5382. layersCount
  5383. });
  5384. }
  5385. _bindLink(element, {
  5386. groupId,
  5387. input
  5388. }) {
  5389. const setVisibility = () => {
  5390. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5391. this.eventBus.dispatch("optionalcontentconfig", {
  5392. source: this,
  5393. promise: Promise.resolve(this._optionalContentConfig)
  5394. });
  5395. };
  5396. element.onclick = evt => {
  5397. if (evt.target === input) {
  5398. setVisibility();
  5399. return true;
  5400. } else if (evt.target !== element) {
  5401. return true;
  5402. }
  5403. input.checked = !input.checked;
  5404. setVisibility();
  5405. return false;
  5406. };
  5407. }
  5408. async _setNestedName(element, {
  5409. name = null
  5410. }) {
  5411. if (typeof name === "string") {
  5412. element.textContent = this._normalizeTextContent(name);
  5413. return;
  5414. }
  5415. element.textContent = await this.l10n.get("additional_layers");
  5416. element.style.fontStyle = "italic";
  5417. }
  5418. _addToggleButton(div, {
  5419. name = null
  5420. }) {
  5421. super._addToggleButton(div, name === null);
  5422. }
  5423. _toggleAllTreeItems() {
  5424. if (!this._optionalContentConfig) {
  5425. return;
  5426. }
  5427. super._toggleAllTreeItems();
  5428. }
  5429. render({
  5430. optionalContentConfig,
  5431. pdfDocument
  5432. }) {
  5433. if (this._optionalContentConfig) {
  5434. this.reset();
  5435. }
  5436. this._optionalContentConfig = optionalContentConfig || null;
  5437. this._pdfDocument = pdfDocument || null;
  5438. const groups = optionalContentConfig?.getOrder();
  5439. if (!groups) {
  5440. this._dispatchEvent(0);
  5441. return;
  5442. }
  5443. const fragment = document.createDocumentFragment(),
  5444. queue = [{
  5445. parent: fragment,
  5446. groups
  5447. }];
  5448. let layersCount = 0,
  5449. hasAnyNesting = false;
  5450. while (queue.length > 0) {
  5451. const levelData = queue.shift();
  5452. for (const groupId of levelData.groups) {
  5453. const div = document.createElement("div");
  5454. div.className = "treeItem";
  5455. const element = document.createElement("a");
  5456. div.appendChild(element);
  5457. if (typeof groupId === "object") {
  5458. hasAnyNesting = true;
  5459. this._addToggleButton(div, groupId);
  5460. this._setNestedName(element, groupId);
  5461. const itemsDiv = document.createElement("div");
  5462. itemsDiv.className = "treeItems";
  5463. div.appendChild(itemsDiv);
  5464. queue.push({
  5465. parent: itemsDiv,
  5466. groups: groupId.order
  5467. });
  5468. } else {
  5469. const group = optionalContentConfig.getGroup(groupId);
  5470. const input = document.createElement("input");
  5471. this._bindLink(element, {
  5472. groupId,
  5473. input
  5474. });
  5475. input.type = "checkbox";
  5476. input.id = groupId;
  5477. input.checked = group.visible;
  5478. const label = document.createElement("label");
  5479. label.setAttribute("for", groupId);
  5480. label.textContent = this._normalizeTextContent(group.name);
  5481. element.appendChild(input);
  5482. element.appendChild(label);
  5483. layersCount++;
  5484. }
  5485. levelData.parent.appendChild(div);
  5486. }
  5487. }
  5488. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5489. }
  5490. async _resetLayers() {
  5491. if (!this._optionalContentConfig) {
  5492. return;
  5493. }
  5494. const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
  5495. this.eventBus.dispatch("optionalcontentconfig", {
  5496. source: this,
  5497. promise: Promise.resolve(optionalContentConfig)
  5498. });
  5499. this.render({
  5500. optionalContentConfig,
  5501. pdfDocument: this._pdfDocument
  5502. });
  5503. }
  5504. }
  5505. exports.PDFLayerViewer = PDFLayerViewer;
  5506. /***/ }),
  5507. /* 19 */
  5508. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5509. Object.defineProperty(exports, "__esModule", ({
  5510. value: true
  5511. }));
  5512. exports.SimpleLinkService = exports.PDFLinkService = void 0;
  5513. var _ui_utils = __webpack_require__(4);
  5514. class PDFLinkService {
  5515. constructor({
  5516. eventBus,
  5517. externalLinkTarget = null,
  5518. externalLinkRel = null,
  5519. externalLinkEnabled = true,
  5520. ignoreDestinationZoom = false
  5521. } = {}) {
  5522. this.eventBus = eventBus;
  5523. this.externalLinkTarget = externalLinkTarget;
  5524. this.externalLinkRel = externalLinkRel;
  5525. this.externalLinkEnabled = externalLinkEnabled;
  5526. this._ignoreDestinationZoom = ignoreDestinationZoom;
  5527. this.baseUrl = null;
  5528. this.pdfDocument = null;
  5529. this.pdfViewer = null;
  5530. this.pdfHistory = null;
  5531. this._pagesRefCache = null;
  5532. }
  5533. setDocument(pdfDocument, baseUrl = null) {
  5534. this.baseUrl = baseUrl;
  5535. this.pdfDocument = pdfDocument;
  5536. this._pagesRefCache = Object.create(null);
  5537. }
  5538. setViewer(pdfViewer) {
  5539. this.pdfViewer = pdfViewer;
  5540. }
  5541. setHistory(pdfHistory) {
  5542. this.pdfHistory = pdfHistory;
  5543. }
  5544. get pagesCount() {
  5545. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  5546. }
  5547. get page() {
  5548. return this.pdfViewer.currentPageNumber;
  5549. }
  5550. set page(value) {
  5551. this.pdfViewer.currentPageNumber = value;
  5552. }
  5553. get rotation() {
  5554. return this.pdfViewer.pagesRotation;
  5555. }
  5556. set rotation(value) {
  5557. this.pdfViewer.pagesRotation = value;
  5558. }
  5559. _goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  5560. const destRef = explicitDest[0];
  5561. let pageNumber;
  5562. if (destRef instanceof Object) {
  5563. pageNumber = this._cachedPageNumber(destRef);
  5564. if (pageNumber === null) {
  5565. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  5566. this.cachePageRef(pageIndex + 1, destRef);
  5567. this._goToDestinationHelper(rawDest, namedDest, explicitDest);
  5568. }).catch(() => {
  5569. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  5570. });
  5571. return;
  5572. }
  5573. } else if (Number.isInteger(destRef)) {
  5574. pageNumber = destRef + 1;
  5575. } else {
  5576. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  5577. return;
  5578. }
  5579. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  5580. console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  5581. return;
  5582. }
  5583. if (this.pdfHistory) {
  5584. this.pdfHistory.pushCurrentPosition();
  5585. this.pdfHistory.push({
  5586. namedDest,
  5587. explicitDest,
  5588. pageNumber
  5589. });
  5590. }
  5591. this.pdfViewer.scrollPageIntoView({
  5592. pageNumber,
  5593. destArray: explicitDest,
  5594. ignoreDestinationZoom: this._ignoreDestinationZoom
  5595. });
  5596. }
  5597. async goToDestination(dest) {
  5598. if (!this.pdfDocument) {
  5599. return;
  5600. }
  5601. let namedDest, explicitDest;
  5602. if (typeof dest === "string") {
  5603. namedDest = dest;
  5604. explicitDest = await this.pdfDocument.getDestination(dest);
  5605. } else {
  5606. namedDest = null;
  5607. explicitDest = await dest;
  5608. }
  5609. if (!Array.isArray(explicitDest)) {
  5610. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  5611. return;
  5612. }
  5613. this._goToDestinationHelper(dest, namedDest, explicitDest);
  5614. }
  5615. goToPage(val) {
  5616. if (!this.pdfDocument) {
  5617. return;
  5618. }
  5619. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  5620. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  5621. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  5622. return;
  5623. }
  5624. if (this.pdfHistory) {
  5625. this.pdfHistory.pushCurrentPosition();
  5626. this.pdfHistory.pushPage(pageNumber);
  5627. }
  5628. this.pdfViewer.scrollPageIntoView({
  5629. pageNumber
  5630. });
  5631. }
  5632. getDestinationHash(dest) {
  5633. if (typeof dest === "string") {
  5634. if (dest.length > 0) {
  5635. return this.getAnchorUrl("#" + escape(dest));
  5636. }
  5637. } else if (Array.isArray(dest)) {
  5638. const str = JSON.stringify(dest);
  5639. if (str.length > 0) {
  5640. return this.getAnchorUrl("#" + escape(str));
  5641. }
  5642. }
  5643. return this.getAnchorUrl("");
  5644. }
  5645. getAnchorUrl(anchor) {
  5646. return (this.baseUrl || "") + anchor;
  5647. }
  5648. setHash(hash) {
  5649. if (!this.pdfDocument) {
  5650. return;
  5651. }
  5652. let pageNumber, dest;
  5653. if (hash.includes("=")) {
  5654. const params = (0, _ui_utils.parseQueryString)(hash);
  5655. if ("search" in params) {
  5656. this.eventBus.dispatch("findfromurlhash", {
  5657. source: this,
  5658. query: params.search.replace(/"/g, ""),
  5659. phraseSearch: params.phrase === "true"
  5660. });
  5661. }
  5662. if ("page" in params) {
  5663. pageNumber = params.page | 0 || 1;
  5664. }
  5665. if ("zoom" in params) {
  5666. const zoomArgs = params.zoom.split(",");
  5667. const zoomArg = zoomArgs[0];
  5668. const zoomArgNumber = parseFloat(zoomArg);
  5669. if (!zoomArg.includes("Fit")) {
  5670. dest = [null, {
  5671. name: "XYZ"
  5672. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  5673. } else {
  5674. if (zoomArg === "Fit" || zoomArg === "FitB") {
  5675. dest = [null, {
  5676. name: zoomArg
  5677. }];
  5678. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  5679. dest = [null, {
  5680. name: zoomArg
  5681. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  5682. } else if (zoomArg === "FitR") {
  5683. if (zoomArgs.length !== 5) {
  5684. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  5685. } else {
  5686. dest = [null, {
  5687. name: zoomArg
  5688. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  5689. }
  5690. } else {
  5691. console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
  5692. }
  5693. }
  5694. }
  5695. if (dest) {
  5696. this.pdfViewer.scrollPageIntoView({
  5697. pageNumber: pageNumber || this.page,
  5698. destArray: dest,
  5699. allowNegativeOffset: true
  5700. });
  5701. } else if (pageNumber) {
  5702. this.page = pageNumber;
  5703. }
  5704. if ("pagemode" in params) {
  5705. this.eventBus.dispatch("pagemode", {
  5706. source: this,
  5707. mode: params.pagemode
  5708. });
  5709. }
  5710. if ("nameddest" in params) {
  5711. this.goToDestination(params.nameddest);
  5712. }
  5713. } else {
  5714. dest = unescape(hash);
  5715. try {
  5716. dest = JSON.parse(dest);
  5717. if (!Array.isArray(dest)) {
  5718. dest = dest.toString();
  5719. }
  5720. } catch (ex) {}
  5721. if (typeof dest === "string" || isValidExplicitDestination(dest)) {
  5722. this.goToDestination(dest);
  5723. return;
  5724. }
  5725. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
  5726. }
  5727. }
  5728. executeNamedAction(action) {
  5729. switch (action) {
  5730. case "GoBack":
  5731. if (this.pdfHistory) {
  5732. this.pdfHistory.back();
  5733. }
  5734. break;
  5735. case "GoForward":
  5736. if (this.pdfHistory) {
  5737. this.pdfHistory.forward();
  5738. }
  5739. break;
  5740. case "NextPage":
  5741. this.pdfViewer.nextPage();
  5742. break;
  5743. case "PrevPage":
  5744. this.pdfViewer.previousPage();
  5745. break;
  5746. case "LastPage":
  5747. this.page = this.pagesCount;
  5748. break;
  5749. case "FirstPage":
  5750. this.page = 1;
  5751. break;
  5752. default:
  5753. break;
  5754. }
  5755. this.eventBus.dispatch("namedaction", {
  5756. source: this,
  5757. action
  5758. });
  5759. }
  5760. cachePageRef(pageNum, pageRef) {
  5761. if (!pageRef) {
  5762. return;
  5763. }
  5764. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5765. this._pagesRefCache[refStr] = pageNum;
  5766. }
  5767. _cachedPageNumber(pageRef) {
  5768. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5769. return this._pagesRefCache?.[refStr] || null;
  5770. }
  5771. isPageVisible(pageNumber) {
  5772. return this.pdfViewer.isPageVisible(pageNumber);
  5773. }
  5774. isPageCached(pageNumber) {
  5775. return this.pdfViewer.isPageCached(pageNumber);
  5776. }
  5777. }
  5778. exports.PDFLinkService = PDFLinkService;
  5779. function isValidExplicitDestination(dest) {
  5780. if (!Array.isArray(dest)) {
  5781. return false;
  5782. }
  5783. const destLength = dest.length;
  5784. if (destLength < 2) {
  5785. return false;
  5786. }
  5787. const page = dest[0];
  5788. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  5789. return false;
  5790. }
  5791. const zoom = dest[1];
  5792. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  5793. return false;
  5794. }
  5795. let allowNull = true;
  5796. switch (zoom.name) {
  5797. case "XYZ":
  5798. if (destLength !== 5) {
  5799. return false;
  5800. }
  5801. break;
  5802. case "Fit":
  5803. case "FitB":
  5804. return destLength === 2;
  5805. case "FitH":
  5806. case "FitBH":
  5807. case "FitV":
  5808. case "FitBV":
  5809. if (destLength !== 3) {
  5810. return false;
  5811. }
  5812. break;
  5813. case "FitR":
  5814. if (destLength !== 6) {
  5815. return false;
  5816. }
  5817. allowNull = false;
  5818. break;
  5819. default:
  5820. return false;
  5821. }
  5822. for (let i = 2; i < destLength; i++) {
  5823. const param = dest[i];
  5824. if (!(typeof param === "number" || allowNull && param === null)) {
  5825. return false;
  5826. }
  5827. }
  5828. return true;
  5829. }
  5830. class SimpleLinkService {
  5831. constructor() {
  5832. this.externalLinkTarget = null;
  5833. this.externalLinkRel = null;
  5834. this.externalLinkEnabled = true;
  5835. this._ignoreDestinationZoom = false;
  5836. }
  5837. get pagesCount() {
  5838. return 0;
  5839. }
  5840. get page() {
  5841. return 0;
  5842. }
  5843. set page(value) {}
  5844. get rotation() {
  5845. return 0;
  5846. }
  5847. set rotation(value) {}
  5848. async goToDestination(dest) {}
  5849. goToPage(val) {}
  5850. getDestinationHash(dest) {
  5851. return "#";
  5852. }
  5853. getAnchorUrl(hash) {
  5854. return "#";
  5855. }
  5856. setHash(hash) {}
  5857. executeNamedAction(action) {}
  5858. cachePageRef(pageNum, pageRef) {}
  5859. isPageVisible(pageNumber) {
  5860. return true;
  5861. }
  5862. isPageCached(pageNumber) {
  5863. return true;
  5864. }
  5865. }
  5866. exports.SimpleLinkService = SimpleLinkService;
  5867. /***/ }),
  5868. /* 20 */
  5869. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5870. Object.defineProperty(exports, "__esModule", ({
  5871. value: true
  5872. }));
  5873. exports.PDFOutlineViewer = void 0;
  5874. var _pdfjsLib = __webpack_require__(5);
  5875. var _base_tree_viewer = __webpack_require__(12);
  5876. var _ui_utils = __webpack_require__(4);
  5877. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  5878. constructor(options) {
  5879. super(options);
  5880. this.linkService = options.linkService;
  5881. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  5882. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  5883. this.eventBus._on("pagechanging", evt => {
  5884. this._currentPageNumber = evt.pageNumber;
  5885. });
  5886. this.eventBus._on("pagesloaded", evt => {
  5887. this._isPagesLoaded = !!evt.pagesCount;
  5888. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5889. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  5890. }
  5891. });
  5892. this.eventBus._on("sidebarviewchanged", evt => {
  5893. this._sidebarView = evt.view;
  5894. });
  5895. }
  5896. reset() {
  5897. super.reset();
  5898. this._outline = null;
  5899. this._pageNumberToDestHashCapability = null;
  5900. this._currentPageNumber = 1;
  5901. this._isPagesLoaded = false;
  5902. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5903. this._currentOutlineItemCapability.resolve(false);
  5904. }
  5905. this._currentOutlineItemCapability = null;
  5906. }
  5907. _dispatchEvent(outlineCount) {
  5908. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  5909. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  5910. this._currentOutlineItemCapability.resolve(false);
  5911. } else if (this._isPagesLoaded) {
  5912. this._currentOutlineItemCapability.resolve(true);
  5913. }
  5914. this.eventBus.dispatch("outlineloaded", {
  5915. source: this,
  5916. outlineCount,
  5917. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  5918. });
  5919. }
  5920. _bindLink(element, {
  5921. url,
  5922. newWindow,
  5923. dest
  5924. }) {
  5925. const {
  5926. linkService
  5927. } = this;
  5928. if (url) {
  5929. (0, _pdfjsLib.addLinkAttributes)(element, {
  5930. url,
  5931. target: newWindow ? _pdfjsLib.LinkTarget.BLANK : linkService.externalLinkTarget,
  5932. rel: linkService.externalLinkRel,
  5933. enabled: linkService.externalLinkEnabled
  5934. });
  5935. return;
  5936. }
  5937. element.href = linkService.getDestinationHash(dest);
  5938. element.onclick = evt => {
  5939. this._updateCurrentTreeItem(evt.target.parentNode);
  5940. if (dest) {
  5941. linkService.goToDestination(dest);
  5942. }
  5943. return false;
  5944. };
  5945. }
  5946. _setStyles(element, {
  5947. bold,
  5948. italic
  5949. }) {
  5950. if (bold) {
  5951. element.style.fontWeight = "bold";
  5952. }
  5953. if (italic) {
  5954. element.style.fontStyle = "italic";
  5955. }
  5956. }
  5957. _addToggleButton(div, {
  5958. count,
  5959. items
  5960. }) {
  5961. let hidden = false;
  5962. if (count < 0) {
  5963. let totalCount = items.length;
  5964. if (totalCount > 0) {
  5965. const queue = [...items];
  5966. while (queue.length > 0) {
  5967. const {
  5968. count: nestedCount,
  5969. items: nestedItems
  5970. } = queue.shift();
  5971. if (nestedCount > 0 && nestedItems.length > 0) {
  5972. totalCount += nestedItems.length;
  5973. queue.push(...nestedItems);
  5974. }
  5975. }
  5976. }
  5977. if (Math.abs(count) === totalCount) {
  5978. hidden = true;
  5979. }
  5980. }
  5981. super._addToggleButton(div, hidden);
  5982. }
  5983. _toggleAllTreeItems() {
  5984. if (!this._outline) {
  5985. return;
  5986. }
  5987. super._toggleAllTreeItems();
  5988. }
  5989. render({
  5990. outline,
  5991. pdfDocument
  5992. }) {
  5993. if (this._outline) {
  5994. this.reset();
  5995. }
  5996. this._outline = outline || null;
  5997. this._pdfDocument = pdfDocument || null;
  5998. if (!outline) {
  5999. this._dispatchEvent(0);
  6000. return;
  6001. }
  6002. const fragment = document.createDocumentFragment();
  6003. const queue = [{
  6004. parent: fragment,
  6005. items: outline
  6006. }];
  6007. let outlineCount = 0,
  6008. hasAnyNesting = false;
  6009. while (queue.length > 0) {
  6010. const levelData = queue.shift();
  6011. for (const item of levelData.items) {
  6012. const div = document.createElement("div");
  6013. div.className = "treeItem";
  6014. const element = document.createElement("a");
  6015. this._bindLink(element, item);
  6016. this._setStyles(element, item);
  6017. element.textContent = this._normalizeTextContent(item.title);
  6018. div.appendChild(element);
  6019. if (item.items.length > 0) {
  6020. hasAnyNesting = true;
  6021. this._addToggleButton(div, item);
  6022. const itemsDiv = document.createElement("div");
  6023. itemsDiv.className = "treeItems";
  6024. div.appendChild(itemsDiv);
  6025. queue.push({
  6026. parent: itemsDiv,
  6027. items: item.items
  6028. });
  6029. }
  6030. levelData.parent.appendChild(div);
  6031. outlineCount++;
  6032. }
  6033. }
  6034. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6035. }
  6036. async _currentOutlineItem() {
  6037. if (!this._isPagesLoaded) {
  6038. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6039. }
  6040. if (!this._outline || !this._pdfDocument) {
  6041. return;
  6042. }
  6043. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6044. if (!pageNumberToDestHash) {
  6045. return;
  6046. }
  6047. this._updateCurrentTreeItem(null);
  6048. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6049. return;
  6050. }
  6051. for (let i = this._currentPageNumber; i > 0; i--) {
  6052. const destHash = pageNumberToDestHash.get(i);
  6053. if (!destHash) {
  6054. continue;
  6055. }
  6056. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6057. if (!linkElement) {
  6058. continue;
  6059. }
  6060. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6061. break;
  6062. }
  6063. }
  6064. async _getPageNumberToDestHash(pdfDocument) {
  6065. if (this._pageNumberToDestHashCapability) {
  6066. return this._pageNumberToDestHashCapability.promise;
  6067. }
  6068. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6069. const pageNumberToDestHash = new Map(),
  6070. pageNumberNesting = new Map();
  6071. const queue = [{
  6072. nesting: 0,
  6073. items: this._outline
  6074. }];
  6075. while (queue.length > 0) {
  6076. const levelData = queue.shift(),
  6077. currentNesting = levelData.nesting;
  6078. for (const {
  6079. dest,
  6080. items
  6081. } of levelData.items) {
  6082. let explicitDest, pageNumber;
  6083. if (typeof dest === "string") {
  6084. explicitDest = await pdfDocument.getDestination(dest);
  6085. if (pdfDocument !== this._pdfDocument) {
  6086. return null;
  6087. }
  6088. } else {
  6089. explicitDest = dest;
  6090. }
  6091. if (Array.isArray(explicitDest)) {
  6092. const [destRef] = explicitDest;
  6093. if (destRef instanceof Object) {
  6094. pageNumber = this.linkService._cachedPageNumber(destRef);
  6095. if (!pageNumber) {
  6096. try {
  6097. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6098. if (pdfDocument !== this._pdfDocument) {
  6099. return null;
  6100. }
  6101. this.linkService.cachePageRef(pageNumber, destRef);
  6102. } catch (ex) {}
  6103. }
  6104. } else if (Number.isInteger(destRef)) {
  6105. pageNumber = destRef + 1;
  6106. }
  6107. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6108. const destHash = this.linkService.getDestinationHash(dest);
  6109. pageNumberToDestHash.set(pageNumber, destHash);
  6110. pageNumberNesting.set(pageNumber, currentNesting);
  6111. }
  6112. }
  6113. if (items.length > 0) {
  6114. queue.push({
  6115. nesting: currentNesting + 1,
  6116. items
  6117. });
  6118. }
  6119. }
  6120. }
  6121. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6122. return this._pageNumberToDestHashCapability.promise;
  6123. }
  6124. }
  6125. exports.PDFOutlineViewer = PDFOutlineViewer;
  6126. /***/ }),
  6127. /* 21 */
  6128. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6129. Object.defineProperty(exports, "__esModule", ({
  6130. value: true
  6131. }));
  6132. exports.PDFPresentationMode = void 0;
  6133. var _ui_utils = __webpack_require__(4);
  6134. const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  6135. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6136. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6137. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6138. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6139. const PAGE_SWITCH_THRESHOLD = 0.1;
  6140. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6141. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6142. class PDFPresentationMode {
  6143. constructor({
  6144. container,
  6145. pdfViewer,
  6146. eventBus
  6147. }) {
  6148. this.container = container;
  6149. this.pdfViewer = pdfViewer;
  6150. this.eventBus = eventBus;
  6151. this.active = false;
  6152. this.args = null;
  6153. this.contextMenuOpen = false;
  6154. this.mouseScrollTimeStamp = 0;
  6155. this.mouseScrollDelta = 0;
  6156. this.touchSwipeState = null;
  6157. }
  6158. request() {
  6159. if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) {
  6160. return false;
  6161. }
  6162. this._addFullscreenChangeListeners();
  6163. this._setSwitchInProgress();
  6164. this._notifyStateChange();
  6165. if (this.container.requestFullscreen) {
  6166. this.container.requestFullscreen();
  6167. } else if (this.container.mozRequestFullScreen) {
  6168. this.container.mozRequestFullScreen();
  6169. } else if (this.container.webkitRequestFullscreen) {
  6170. this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  6171. } else {
  6172. return false;
  6173. }
  6174. this.args = {
  6175. page: this.pdfViewer.currentPageNumber,
  6176. previousScale: this.pdfViewer.currentScaleValue
  6177. };
  6178. return true;
  6179. }
  6180. _mouseWheel(evt) {
  6181. if (!this.active) {
  6182. return;
  6183. }
  6184. evt.preventDefault();
  6185. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6186. const currentTime = Date.now();
  6187. const storedTime = this.mouseScrollTimeStamp;
  6188. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6189. return;
  6190. }
  6191. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6192. this._resetMouseScrollState();
  6193. }
  6194. this.mouseScrollDelta += delta;
  6195. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6196. const totalDelta = this.mouseScrollDelta;
  6197. this._resetMouseScrollState();
  6198. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6199. if (success) {
  6200. this.mouseScrollTimeStamp = currentTime;
  6201. }
  6202. }
  6203. }
  6204. get isFullscreen() {
  6205. return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen);
  6206. }
  6207. _notifyStateChange() {
  6208. let state = _ui_utils.PresentationModeState.NORMAL;
  6209. if (this.switchInProgress) {
  6210. state = _ui_utils.PresentationModeState.CHANGING;
  6211. } else if (this.active) {
  6212. state = _ui_utils.PresentationModeState.FULLSCREEN;
  6213. }
  6214. this.eventBus.dispatch("presentationmodechanged", {
  6215. source: this,
  6216. state
  6217. });
  6218. }
  6219. _setSwitchInProgress() {
  6220. if (this.switchInProgress) {
  6221. clearTimeout(this.switchInProgress);
  6222. }
  6223. this.switchInProgress = setTimeout(() => {
  6224. this._removeFullscreenChangeListeners();
  6225. delete this.switchInProgress;
  6226. this._notifyStateChange();
  6227. }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  6228. }
  6229. _resetSwitchInProgress() {
  6230. if (this.switchInProgress) {
  6231. clearTimeout(this.switchInProgress);
  6232. delete this.switchInProgress;
  6233. }
  6234. }
  6235. _enter() {
  6236. this.active = true;
  6237. this._resetSwitchInProgress();
  6238. this._notifyStateChange();
  6239. this.container.classList.add(ACTIVE_SELECTOR);
  6240. setTimeout(() => {
  6241. this.pdfViewer.currentPageNumber = this.args.page;
  6242. this.pdfViewer.currentScaleValue = "page-fit";
  6243. }, 0);
  6244. this._addWindowListeners();
  6245. this._showControls();
  6246. this.contextMenuOpen = false;
  6247. window.getSelection().removeAllRanges();
  6248. }
  6249. _exit() {
  6250. const page = this.pdfViewer.currentPageNumber;
  6251. this.container.classList.remove(ACTIVE_SELECTOR);
  6252. setTimeout(() => {
  6253. this.active = false;
  6254. this._removeFullscreenChangeListeners();
  6255. this._notifyStateChange();
  6256. this.pdfViewer.currentScaleValue = this.args.previousScale;
  6257. this.pdfViewer.currentPageNumber = page;
  6258. this.args = null;
  6259. }, 0);
  6260. this._removeWindowListeners();
  6261. this._hideControls();
  6262. this._resetMouseScrollState();
  6263. this.contextMenuOpen = false;
  6264. }
  6265. _mouseDown(evt) {
  6266. if (this.contextMenuOpen) {
  6267. this.contextMenuOpen = false;
  6268. evt.preventDefault();
  6269. return;
  6270. }
  6271. if (evt.button === 0) {
  6272. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6273. if (!isInternalLink) {
  6274. evt.preventDefault();
  6275. if (evt.shiftKey) {
  6276. this.pdfViewer.previousPage();
  6277. } else {
  6278. this.pdfViewer.nextPage();
  6279. }
  6280. }
  6281. }
  6282. }
  6283. _contextMenu() {
  6284. this.contextMenuOpen = true;
  6285. }
  6286. _showControls() {
  6287. if (this.controlsTimeout) {
  6288. clearTimeout(this.controlsTimeout);
  6289. } else {
  6290. this.container.classList.add(CONTROLS_SELECTOR);
  6291. }
  6292. this.controlsTimeout = setTimeout(() => {
  6293. this.container.classList.remove(CONTROLS_SELECTOR);
  6294. delete this.controlsTimeout;
  6295. }, DELAY_BEFORE_HIDING_CONTROLS);
  6296. }
  6297. _hideControls() {
  6298. if (!this.controlsTimeout) {
  6299. return;
  6300. }
  6301. clearTimeout(this.controlsTimeout);
  6302. this.container.classList.remove(CONTROLS_SELECTOR);
  6303. delete this.controlsTimeout;
  6304. }
  6305. _resetMouseScrollState() {
  6306. this.mouseScrollTimeStamp = 0;
  6307. this.mouseScrollDelta = 0;
  6308. }
  6309. _touchSwipe(evt) {
  6310. if (!this.active) {
  6311. return;
  6312. }
  6313. if (evt.touches.length > 1) {
  6314. this.touchSwipeState = null;
  6315. return;
  6316. }
  6317. switch (evt.type) {
  6318. case "touchstart":
  6319. this.touchSwipeState = {
  6320. startX: evt.touches[0].pageX,
  6321. startY: evt.touches[0].pageY,
  6322. endX: evt.touches[0].pageX,
  6323. endY: evt.touches[0].pageY
  6324. };
  6325. break;
  6326. case "touchmove":
  6327. if (this.touchSwipeState === null) {
  6328. return;
  6329. }
  6330. this.touchSwipeState.endX = evt.touches[0].pageX;
  6331. this.touchSwipeState.endY = evt.touches[0].pageY;
  6332. evt.preventDefault();
  6333. break;
  6334. case "touchend":
  6335. if (this.touchSwipeState === null) {
  6336. return;
  6337. }
  6338. let delta = 0;
  6339. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6340. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6341. const absAngle = Math.abs(Math.atan2(dy, dx));
  6342. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6343. delta = dx;
  6344. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6345. delta = dy;
  6346. }
  6347. if (delta > 0) {
  6348. this.pdfViewer.previousPage();
  6349. } else if (delta < 0) {
  6350. this.pdfViewer.nextPage();
  6351. }
  6352. break;
  6353. }
  6354. }
  6355. _addWindowListeners() {
  6356. this.showControlsBind = this._showControls.bind(this);
  6357. this.mouseDownBind = this._mouseDown.bind(this);
  6358. this.mouseWheelBind = this._mouseWheel.bind(this);
  6359. this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
  6360. this.contextMenuBind = this._contextMenu.bind(this);
  6361. this.touchSwipeBind = this._touchSwipe.bind(this);
  6362. window.addEventListener("mousemove", this.showControlsBind);
  6363. window.addEventListener("mousedown", this.mouseDownBind);
  6364. window.addEventListener("wheel", this.mouseWheelBind, {
  6365. passive: false
  6366. });
  6367. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6368. window.addEventListener("contextmenu", this.contextMenuBind);
  6369. window.addEventListener("touchstart", this.touchSwipeBind);
  6370. window.addEventListener("touchmove", this.touchSwipeBind);
  6371. window.addEventListener("touchend", this.touchSwipeBind);
  6372. }
  6373. _removeWindowListeners() {
  6374. window.removeEventListener("mousemove", this.showControlsBind);
  6375. window.removeEventListener("mousedown", this.mouseDownBind);
  6376. window.removeEventListener("wheel", this.mouseWheelBind, {
  6377. passive: false
  6378. });
  6379. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6380. window.removeEventListener("contextmenu", this.contextMenuBind);
  6381. window.removeEventListener("touchstart", this.touchSwipeBind);
  6382. window.removeEventListener("touchmove", this.touchSwipeBind);
  6383. window.removeEventListener("touchend", this.touchSwipeBind);
  6384. delete this.showControlsBind;
  6385. delete this.mouseDownBind;
  6386. delete this.mouseWheelBind;
  6387. delete this.resetMouseScrollStateBind;
  6388. delete this.contextMenuBind;
  6389. delete this.touchSwipeBind;
  6390. }
  6391. _fullscreenChange() {
  6392. if (this.isFullscreen) {
  6393. this._enter();
  6394. } else {
  6395. this._exit();
  6396. }
  6397. }
  6398. _addFullscreenChangeListeners() {
  6399. this.fullscreenChangeBind = this._fullscreenChange.bind(this);
  6400. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6401. window.addEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6402. window.addEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6403. }
  6404. _removeFullscreenChangeListeners() {
  6405. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6406. window.removeEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6407. window.removeEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6408. delete this.fullscreenChangeBind;
  6409. }
  6410. }
  6411. exports.PDFPresentationMode = PDFPresentationMode;
  6412. /***/ }),
  6413. /* 22 */
  6414. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6415. Object.defineProperty(exports, "__esModule", ({
  6416. value: true
  6417. }));
  6418. exports.PDFScriptingManager = void 0;
  6419. var _pdfjsLib = __webpack_require__(5);
  6420. var _ui_utils = __webpack_require__(4);
  6421. var _pdf_rendering_queue = __webpack_require__(8);
  6422. class PDFScriptingManager {
  6423. constructor({
  6424. eventBus,
  6425. sandboxBundleSrc = null,
  6426. scriptingFactory = null,
  6427. docPropertiesLookup = null
  6428. }) {
  6429. this._pdfDocument = null;
  6430. this._pdfViewer = null;
  6431. this._closeCapability = null;
  6432. this._destroyCapability = null;
  6433. this._scripting = null;
  6434. this._mouseState = Object.create(null);
  6435. this._pageEventsReady = false;
  6436. this._ready = false;
  6437. this._eventBus = eventBus;
  6438. this._sandboxBundleSrc = sandboxBundleSrc;
  6439. this._scriptingFactory = scriptingFactory;
  6440. this._docPropertiesLookup = docPropertiesLookup;
  6441. }
  6442. setViewer(pdfViewer) {
  6443. this._pdfViewer = pdfViewer;
  6444. }
  6445. async setDocument(pdfDocument) {
  6446. if (this._pdfDocument) {
  6447. await this._destroyScripting();
  6448. }
  6449. this._pdfDocument = pdfDocument;
  6450. if (!pdfDocument) {
  6451. return;
  6452. }
  6453. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6454. if (!objects && !docActions) {
  6455. await this._destroyScripting();
  6456. return;
  6457. }
  6458. if (pdfDocument !== this._pdfDocument) {
  6459. return;
  6460. }
  6461. this._scripting = this._createScripting();
  6462. this._internalEvents.set("updatefromsandbox", event => {
  6463. if (event?.source !== window) {
  6464. return;
  6465. }
  6466. this._updateFromSandbox(event.detail);
  6467. });
  6468. this._internalEvents.set("dispatcheventinsandbox", event => {
  6469. this._scripting?.dispatchEventInSandbox(event.detail);
  6470. });
  6471. this._internalEvents.set("pagechanging", ({
  6472. pageNumber,
  6473. previous
  6474. }) => {
  6475. if (pageNumber === previous) {
  6476. return;
  6477. }
  6478. this._dispatchPageClose(previous);
  6479. this._dispatchPageOpen(pageNumber);
  6480. });
  6481. this._internalEvents.set("pagerendered", ({
  6482. pageNumber
  6483. }) => {
  6484. if (!this._pageOpenPending.has(pageNumber)) {
  6485. return;
  6486. }
  6487. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6488. return;
  6489. }
  6490. this._dispatchPageOpen(pageNumber);
  6491. });
  6492. this._internalEvents.set("pagesdestroy", async event => {
  6493. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6494. await this._scripting?.dispatchEventInSandbox({
  6495. id: "doc",
  6496. name: "WillClose"
  6497. });
  6498. this._closeCapability?.resolve();
  6499. });
  6500. this._domEvents.set("mousedown", event => {
  6501. this._mouseState.isDown = true;
  6502. });
  6503. this._domEvents.set("mouseup", event => {
  6504. this._mouseState.isDown = false;
  6505. });
  6506. for (const [name, listener] of this._internalEvents) {
  6507. this._eventBus._on(name, listener);
  6508. }
  6509. for (const [name, listener] of this._domEvents) {
  6510. window.addEventListener(name, listener);
  6511. }
  6512. try {
  6513. const docProperties = await this._getDocProperties();
  6514. if (pdfDocument !== this._pdfDocument) {
  6515. return;
  6516. }
  6517. await this._scripting.createSandbox({
  6518. objects,
  6519. calculationOrder,
  6520. appInfo: {
  6521. platform: navigator.platform,
  6522. language: navigator.language
  6523. },
  6524. docInfo: { ...docProperties,
  6525. actions: docActions
  6526. }
  6527. });
  6528. this._eventBus.dispatch("sandboxcreated", {
  6529. source: this
  6530. });
  6531. } catch (error) {
  6532. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6533. await this._destroyScripting();
  6534. return;
  6535. }
  6536. await this._scripting?.dispatchEventInSandbox({
  6537. id: "doc",
  6538. name: "Open"
  6539. });
  6540. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6541. Promise.resolve().then(() => {
  6542. if (pdfDocument === this._pdfDocument) {
  6543. this._ready = true;
  6544. }
  6545. });
  6546. }
  6547. async dispatchWillSave(detail) {
  6548. return this._scripting?.dispatchEventInSandbox({
  6549. id: "doc",
  6550. name: "WillSave"
  6551. });
  6552. }
  6553. async dispatchDidSave(detail) {
  6554. return this._scripting?.dispatchEventInSandbox({
  6555. id: "doc",
  6556. name: "DidSave"
  6557. });
  6558. }
  6559. async dispatchWillPrint(detail) {
  6560. return this._scripting?.dispatchEventInSandbox({
  6561. id: "doc",
  6562. name: "WillPrint"
  6563. });
  6564. }
  6565. async dispatchDidPrint(detail) {
  6566. return this._scripting?.dispatchEventInSandbox({
  6567. id: "doc",
  6568. name: "DidPrint"
  6569. });
  6570. }
  6571. get mouseState() {
  6572. return this._mouseState;
  6573. }
  6574. get destroyPromise() {
  6575. return this._destroyCapability?.promise || null;
  6576. }
  6577. get ready() {
  6578. return this._ready;
  6579. }
  6580. get _internalEvents() {
  6581. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6582. }
  6583. get _domEvents() {
  6584. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6585. }
  6586. get _pageOpenPending() {
  6587. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6588. }
  6589. get _visitedPages() {
  6590. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6591. }
  6592. async _updateFromSandbox(detail) {
  6593. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6594. const {
  6595. id,
  6596. siblings,
  6597. command,
  6598. value
  6599. } = detail;
  6600. if (!id) {
  6601. switch (command) {
  6602. case "clear":
  6603. console.clear();
  6604. break;
  6605. case "error":
  6606. console.error(value);
  6607. break;
  6608. case "layout":
  6609. this._pdfViewer.spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(value);
  6610. break;
  6611. case "page-num":
  6612. this._pdfViewer.currentPageNumber = value + 1;
  6613. break;
  6614. case "print":
  6615. await this._pdfViewer.pagesPromise;
  6616. this._eventBus.dispatch("print", {
  6617. source: this
  6618. });
  6619. break;
  6620. case "println":
  6621. console.log(value);
  6622. break;
  6623. case "zoom":
  6624. if (isInPresentationMode) {
  6625. return;
  6626. }
  6627. this._pdfViewer.currentScaleValue = value;
  6628. break;
  6629. }
  6630. return;
  6631. }
  6632. if (isInPresentationMode) {
  6633. if (detail.focus) {
  6634. return;
  6635. }
  6636. }
  6637. delete detail.id;
  6638. delete detail.siblings;
  6639. const ids = siblings ? [id, ...siblings] : [id];
  6640. for (const elementId of ids) {
  6641. const element = document.getElementById(elementId);
  6642. if (element) {
  6643. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6644. detail
  6645. }));
  6646. } else {
  6647. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6648. }
  6649. }
  6650. }
  6651. async _dispatchPageOpen(pageNumber, initialize = false) {
  6652. const pdfDocument = this._pdfDocument,
  6653. visitedPages = this._visitedPages;
  6654. if (initialize) {
  6655. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6656. this._pageEventsReady = true;
  6657. }
  6658. if (!this._pageEventsReady) {
  6659. return;
  6660. }
  6661. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6662. if (pageView?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  6663. this._pageOpenPending.add(pageNumber);
  6664. return;
  6665. }
  6666. this._pageOpenPending.delete(pageNumber);
  6667. const actionsPromise = (async () => {
  6668. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6669. if (pdfDocument !== this._pdfDocument) {
  6670. return;
  6671. }
  6672. await this._scripting?.dispatchEventInSandbox({
  6673. id: "page",
  6674. name: "PageOpen",
  6675. pageNumber,
  6676. actions
  6677. });
  6678. })();
  6679. visitedPages.set(pageNumber, actionsPromise);
  6680. }
  6681. async _dispatchPageClose(pageNumber) {
  6682. const pdfDocument = this._pdfDocument,
  6683. visitedPages = this._visitedPages;
  6684. if (!this._pageEventsReady) {
  6685. return;
  6686. }
  6687. if (this._pageOpenPending.has(pageNumber)) {
  6688. return;
  6689. }
  6690. const actionsPromise = visitedPages.get(pageNumber);
  6691. if (!actionsPromise) {
  6692. return;
  6693. }
  6694. visitedPages.set(pageNumber, null);
  6695. await actionsPromise;
  6696. if (pdfDocument !== this._pdfDocument) {
  6697. return;
  6698. }
  6699. await this._scripting?.dispatchEventInSandbox({
  6700. id: "page",
  6701. name: "PageClose",
  6702. pageNumber
  6703. });
  6704. }
  6705. async _getDocProperties() {
  6706. if (this._docPropertiesLookup) {
  6707. return this._docPropertiesLookup(this._pdfDocument);
  6708. }
  6709. throw new Error("_getDocProperties: Unable to lookup properties.");
  6710. }
  6711. _createScripting() {
  6712. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  6713. if (this._scripting) {
  6714. throw new Error("_createScripting: Scripting already exists.");
  6715. }
  6716. if (this._scriptingFactory) {
  6717. return this._scriptingFactory.createScripting({
  6718. sandboxBundleSrc: this._sandboxBundleSrc
  6719. });
  6720. }
  6721. throw new Error("_createScripting: Cannot create scripting.");
  6722. }
  6723. async _destroyScripting() {
  6724. if (!this._scripting) {
  6725. this._pdfDocument = null;
  6726. this._destroyCapability?.resolve();
  6727. return;
  6728. }
  6729. if (this._closeCapability) {
  6730. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  6731. setTimeout(resolve, 1000);
  6732. })]).catch(reason => {});
  6733. this._closeCapability = null;
  6734. }
  6735. this._pdfDocument = null;
  6736. try {
  6737. await this._scripting.destroySandbox();
  6738. } catch (ex) {}
  6739. for (const [name, listener] of this._internalEvents) {
  6740. this._eventBus._off(name, listener);
  6741. }
  6742. this._internalEvents.clear();
  6743. for (const [name, listener] of this._domEvents) {
  6744. window.removeEventListener(name, listener);
  6745. }
  6746. this._domEvents.clear();
  6747. this._pageOpenPending.clear();
  6748. this._visitedPages.clear();
  6749. this._scripting = null;
  6750. delete this._mouseState.isDown;
  6751. this._pageEventsReady = false;
  6752. this._ready = false;
  6753. this._destroyCapability?.resolve();
  6754. }
  6755. }
  6756. exports.PDFScriptingManager = PDFScriptingManager;
  6757. /***/ }),
  6758. /* 23 */
  6759. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6760. Object.defineProperty(exports, "__esModule", ({
  6761. value: true
  6762. }));
  6763. exports.PDFSidebar = void 0;
  6764. var _ui_utils = __webpack_require__(4);
  6765. var _pdf_rendering_queue = __webpack_require__(8);
  6766. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  6767. class PDFSidebar {
  6768. constructor({
  6769. elements,
  6770. pdfViewer,
  6771. pdfThumbnailViewer,
  6772. eventBus,
  6773. l10n
  6774. }) {
  6775. this.isOpen = false;
  6776. this.active = _ui_utils.SidebarView.THUMBS;
  6777. this.isInitialViewSet = false;
  6778. this.onToggled = null;
  6779. this.pdfViewer = pdfViewer;
  6780. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6781. this.outerContainer = elements.outerContainer;
  6782. this.viewerContainer = elements.viewerContainer;
  6783. this.toggleButton = elements.toggleButton;
  6784. this.thumbnailButton = elements.thumbnailButton;
  6785. this.outlineButton = elements.outlineButton;
  6786. this.attachmentsButton = elements.attachmentsButton;
  6787. this.layersButton = elements.layersButton;
  6788. this.thumbnailView = elements.thumbnailView;
  6789. this.outlineView = elements.outlineView;
  6790. this.attachmentsView = elements.attachmentsView;
  6791. this.layersView = elements.layersView;
  6792. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  6793. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  6794. this.eventBus = eventBus;
  6795. this.l10n = l10n;
  6796. this._addEventListeners();
  6797. }
  6798. reset() {
  6799. this.isInitialViewSet = false;
  6800. this._hideUINotification(true);
  6801. this.switchView(_ui_utils.SidebarView.THUMBS);
  6802. this.outlineButton.disabled = false;
  6803. this.attachmentsButton.disabled = false;
  6804. this.layersButton.disabled = false;
  6805. this._currentOutlineItemButton.disabled = true;
  6806. }
  6807. get visibleView() {
  6808. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  6809. }
  6810. get isThumbnailViewVisible() {
  6811. return this.isOpen && this.active === _ui_utils.SidebarView.THUMBS;
  6812. }
  6813. get isOutlineViewVisible() {
  6814. return this.isOpen && this.active === _ui_utils.SidebarView.OUTLINE;
  6815. }
  6816. get isAttachmentsViewVisible() {
  6817. return this.isOpen && this.active === _ui_utils.SidebarView.ATTACHMENTS;
  6818. }
  6819. get isLayersViewVisible() {
  6820. return this.isOpen && this.active === _ui_utils.SidebarView.LAYERS;
  6821. }
  6822. setInitialView(view = _ui_utils.SidebarView.NONE) {
  6823. if (this.isInitialViewSet) {
  6824. return;
  6825. }
  6826. this.isInitialViewSet = true;
  6827. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  6828. this._dispatchEvent();
  6829. return;
  6830. }
  6831. if (!this._switchView(view, true)) {
  6832. this._dispatchEvent();
  6833. }
  6834. }
  6835. switchView(view, forceOpen = false) {
  6836. this._switchView(view, forceOpen);
  6837. }
  6838. _switchView(view, forceOpen = false) {
  6839. const isViewChanged = view !== this.active;
  6840. let shouldForceRendering = false;
  6841. switch (view) {
  6842. case _ui_utils.SidebarView.NONE:
  6843. if (this.isOpen) {
  6844. this.close();
  6845. return true;
  6846. }
  6847. return false;
  6848. case _ui_utils.SidebarView.THUMBS:
  6849. if (this.isOpen && isViewChanged) {
  6850. shouldForceRendering = true;
  6851. }
  6852. break;
  6853. case _ui_utils.SidebarView.OUTLINE:
  6854. if (this.outlineButton.disabled) {
  6855. return false;
  6856. }
  6857. break;
  6858. case _ui_utils.SidebarView.ATTACHMENTS:
  6859. if (this.attachmentsButton.disabled) {
  6860. return false;
  6861. }
  6862. break;
  6863. case _ui_utils.SidebarView.LAYERS:
  6864. if (this.layersButton.disabled) {
  6865. return false;
  6866. }
  6867. break;
  6868. default:
  6869. console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
  6870. return false;
  6871. }
  6872. this.active = view;
  6873. this.thumbnailButton.classList.toggle("toggled", view === _ui_utils.SidebarView.THUMBS);
  6874. this.outlineButton.classList.toggle("toggled", view === _ui_utils.SidebarView.OUTLINE);
  6875. this.attachmentsButton.classList.toggle("toggled", view === _ui_utils.SidebarView.ATTACHMENTS);
  6876. this.layersButton.classList.toggle("toggled", view === _ui_utils.SidebarView.LAYERS);
  6877. this.thumbnailView.classList.toggle("hidden", view !== _ui_utils.SidebarView.THUMBS);
  6878. this.outlineView.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6879. this.attachmentsView.classList.toggle("hidden", view !== _ui_utils.SidebarView.ATTACHMENTS);
  6880. this.layersView.classList.toggle("hidden", view !== _ui_utils.SidebarView.LAYERS);
  6881. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6882. if (forceOpen && !this.isOpen) {
  6883. this.open();
  6884. return true;
  6885. }
  6886. if (shouldForceRendering) {
  6887. this._updateThumbnailViewer();
  6888. this._forceRendering();
  6889. }
  6890. if (isViewChanged) {
  6891. this._dispatchEvent();
  6892. }
  6893. return isViewChanged;
  6894. }
  6895. open() {
  6896. if (this.isOpen) {
  6897. return;
  6898. }
  6899. this.isOpen = true;
  6900. this.toggleButton.classList.add("toggled");
  6901. this.toggleButton.setAttribute("aria-expanded", "true");
  6902. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  6903. if (this.active === _ui_utils.SidebarView.THUMBS) {
  6904. this._updateThumbnailViewer();
  6905. }
  6906. this._forceRendering();
  6907. this._dispatchEvent();
  6908. this._hideUINotification();
  6909. }
  6910. close() {
  6911. if (!this.isOpen) {
  6912. return;
  6913. }
  6914. this.isOpen = false;
  6915. this.toggleButton.classList.remove("toggled");
  6916. this.toggleButton.setAttribute("aria-expanded", "false");
  6917. this.outerContainer.classList.add("sidebarMoving");
  6918. this.outerContainer.classList.remove("sidebarOpen");
  6919. this._forceRendering();
  6920. this._dispatchEvent();
  6921. }
  6922. toggle() {
  6923. if (this.isOpen) {
  6924. this.close();
  6925. } else {
  6926. this.open();
  6927. }
  6928. }
  6929. _dispatchEvent() {
  6930. this.eventBus.dispatch("sidebarviewchanged", {
  6931. source: this,
  6932. view: this.visibleView
  6933. });
  6934. }
  6935. _forceRendering() {
  6936. if (this.onToggled) {
  6937. this.onToggled();
  6938. } else {
  6939. this.pdfViewer.forceRendering();
  6940. this.pdfThumbnailViewer.forceRendering();
  6941. }
  6942. }
  6943. _updateThumbnailViewer() {
  6944. const {
  6945. pdfViewer,
  6946. pdfThumbnailViewer
  6947. } = this;
  6948. const pagesCount = pdfViewer.pagesCount;
  6949. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  6950. const pageView = pdfViewer.getPageView(pageIndex);
  6951. if (pageView?.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
  6952. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  6953. thumbnailView.setImage(pageView);
  6954. }
  6955. }
  6956. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  6957. }
  6958. _showUINotification() {
  6959. this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
  6960. this.toggleButton.title = msg;
  6961. });
  6962. if (!this.isOpen) {
  6963. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  6964. }
  6965. }
  6966. _hideUINotification(reset = false) {
  6967. if (this.isOpen || reset) {
  6968. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  6969. }
  6970. if (reset) {
  6971. this.l10n.get("toggle_sidebar.title").then(msg => {
  6972. this.toggleButton.title = msg;
  6973. });
  6974. }
  6975. }
  6976. _addEventListeners() {
  6977. this.viewerContainer.addEventListener("transitionend", evt => {
  6978. if (evt.target === this.viewerContainer) {
  6979. this.outerContainer.classList.remove("sidebarMoving");
  6980. }
  6981. });
  6982. this.toggleButton.addEventListener("click", () => {
  6983. this.toggle();
  6984. });
  6985. this.thumbnailButton.addEventListener("click", () => {
  6986. this.switchView(_ui_utils.SidebarView.THUMBS);
  6987. });
  6988. this.outlineButton.addEventListener("click", () => {
  6989. this.switchView(_ui_utils.SidebarView.OUTLINE);
  6990. });
  6991. this.outlineButton.addEventListener("dblclick", () => {
  6992. this.eventBus.dispatch("toggleoutlinetree", {
  6993. source: this
  6994. });
  6995. });
  6996. this.attachmentsButton.addEventListener("click", () => {
  6997. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  6998. });
  6999. this.layersButton.addEventListener("click", () => {
  7000. this.switchView(_ui_utils.SidebarView.LAYERS);
  7001. });
  7002. this.layersButton.addEventListener("dblclick", () => {
  7003. this.eventBus.dispatch("resetlayers", {
  7004. source: this
  7005. });
  7006. });
  7007. this._currentOutlineItemButton.addEventListener("click", () => {
  7008. this.eventBus.dispatch("currentoutlineitem", {
  7009. source: this
  7010. });
  7011. });
  7012. const onTreeLoaded = (count, button, view) => {
  7013. button.disabled = !count;
  7014. if (count) {
  7015. this._showUINotification();
  7016. } else if (this.active === view) {
  7017. this.switchView(_ui_utils.SidebarView.THUMBS);
  7018. }
  7019. };
  7020. this.eventBus._on("outlineloaded", evt => {
  7021. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7022. evt.currentOutlineItemPromise.then(enabled => {
  7023. if (!this.isInitialViewSet) {
  7024. return;
  7025. }
  7026. this._currentOutlineItemButton.disabled = !enabled;
  7027. });
  7028. });
  7029. this.eventBus._on("attachmentsloaded", evt => {
  7030. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7031. });
  7032. this.eventBus._on("layersloaded", evt => {
  7033. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7034. });
  7035. this.eventBus._on("presentationmodechanged", evt => {
  7036. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.isThumbnailViewVisible) {
  7037. this._updateThumbnailViewer();
  7038. }
  7039. });
  7040. }
  7041. }
  7042. exports.PDFSidebar = PDFSidebar;
  7043. /***/ }),
  7044. /* 24 */
  7045. /***/ ((__unused_webpack_module, exports) => {
  7046. Object.defineProperty(exports, "__esModule", ({
  7047. value: true
  7048. }));
  7049. exports.PDFSidebarResizer = void 0;
  7050. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7051. const SIDEBAR_MIN_WIDTH = 200;
  7052. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7053. class PDFSidebarResizer {
  7054. constructor(options, eventBus, l10n) {
  7055. this.isRTL = false;
  7056. this.sidebarOpen = false;
  7057. this.doc = document.documentElement;
  7058. this._width = null;
  7059. this._outerContainerWidth = null;
  7060. this._boundEvents = Object.create(null);
  7061. this.outerContainer = options.outerContainer;
  7062. this.resizer = options.resizer;
  7063. this.eventBus = eventBus;
  7064. l10n.getDirection().then(dir => {
  7065. this.isRTL = dir === "rtl";
  7066. });
  7067. this._addEventListeners();
  7068. }
  7069. get outerContainerWidth() {
  7070. return this._outerContainerWidth || (this._outerContainerWidth = this.outerContainer.clientWidth);
  7071. }
  7072. _updateWidth(width = 0) {
  7073. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7074. if (width > maxWidth) {
  7075. width = maxWidth;
  7076. }
  7077. if (width < SIDEBAR_MIN_WIDTH) {
  7078. width = SIDEBAR_MIN_WIDTH;
  7079. }
  7080. if (width === this._width) {
  7081. return false;
  7082. }
  7083. this._width = width;
  7084. this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7085. return true;
  7086. }
  7087. _mouseMove(evt) {
  7088. let width = evt.clientX;
  7089. if (this.isRTL) {
  7090. width = this.outerContainerWidth - width;
  7091. }
  7092. this._updateWidth(width);
  7093. }
  7094. _mouseUp(evt) {
  7095. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7096. this.eventBus.dispatch("resize", {
  7097. source: this
  7098. });
  7099. const _boundEvents = this._boundEvents;
  7100. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7101. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7102. }
  7103. _addEventListeners() {
  7104. const _boundEvents = this._boundEvents;
  7105. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7106. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7107. this.resizer.addEventListener("mousedown", evt => {
  7108. if (evt.button !== 0) {
  7109. return;
  7110. }
  7111. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7112. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7113. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7114. });
  7115. this.eventBus._on("sidebarviewchanged", evt => {
  7116. this.sidebarOpen = !!evt?.view;
  7117. });
  7118. this.eventBus._on("resize", evt => {
  7119. if (evt?.source !== window) {
  7120. return;
  7121. }
  7122. this._outerContainerWidth = null;
  7123. if (!this._width) {
  7124. return;
  7125. }
  7126. if (!this.sidebarOpen) {
  7127. this._updateWidth(this._width);
  7128. return;
  7129. }
  7130. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7131. const updated = this._updateWidth(this._width);
  7132. Promise.resolve().then(() => {
  7133. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7134. if (updated) {
  7135. this.eventBus.dispatch("resize", {
  7136. source: this
  7137. });
  7138. }
  7139. });
  7140. });
  7141. }
  7142. }
  7143. exports.PDFSidebarResizer = PDFSidebarResizer;
  7144. /***/ }),
  7145. /* 25 */
  7146. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7147. Object.defineProperty(exports, "__esModule", ({
  7148. value: true
  7149. }));
  7150. exports.PDFThumbnailViewer = void 0;
  7151. var _ui_utils = __webpack_require__(4);
  7152. var _pdf_thumbnail_view = __webpack_require__(26);
  7153. var _pdf_rendering_queue = __webpack_require__(8);
  7154. const THUMBNAIL_SCROLL_MARGIN = -19;
  7155. const THUMBNAIL_SELECTED_CLASS = "selected";
  7156. class PDFThumbnailViewer {
  7157. constructor({
  7158. container,
  7159. eventBus,
  7160. linkService,
  7161. renderingQueue,
  7162. l10n
  7163. }) {
  7164. this.container = container;
  7165. this.linkService = linkService;
  7166. this.renderingQueue = renderingQueue;
  7167. this.l10n = l10n;
  7168. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7169. this._resetView();
  7170. eventBus._on("optionalcontentconfigchanged", () => {
  7171. this._setImageDisabled = true;
  7172. });
  7173. }
  7174. _scrollUpdated() {
  7175. this.renderingQueue.renderHighestPriority();
  7176. }
  7177. getThumbnail(index) {
  7178. return this._thumbnails[index];
  7179. }
  7180. _getVisibleThumbs() {
  7181. return (0, _ui_utils.getVisibleElements)({
  7182. scrollEl: this.container,
  7183. views: this._thumbnails
  7184. });
  7185. }
  7186. scrollThumbnailIntoView(pageNumber) {
  7187. if (!this.pdfDocument) {
  7188. return;
  7189. }
  7190. const thumbnailView = this._thumbnails[pageNumber - 1];
  7191. if (!thumbnailView) {
  7192. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7193. return;
  7194. }
  7195. if (pageNumber !== this._currentPageNumber) {
  7196. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7197. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7198. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7199. }
  7200. const visibleThumbs = this._getVisibleThumbs();
  7201. const numVisibleThumbs = visibleThumbs.views.length;
  7202. if (numVisibleThumbs > 0) {
  7203. const first = visibleThumbs.first.id;
  7204. const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
  7205. let shouldScroll = false;
  7206. if (pageNumber <= first || pageNumber >= last) {
  7207. shouldScroll = true;
  7208. } else {
  7209. visibleThumbs.views.some(function (view) {
  7210. if (view.id !== pageNumber) {
  7211. return false;
  7212. }
  7213. shouldScroll = view.percent < 100;
  7214. return true;
  7215. });
  7216. }
  7217. if (shouldScroll) {
  7218. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7219. top: THUMBNAIL_SCROLL_MARGIN
  7220. });
  7221. }
  7222. }
  7223. this._currentPageNumber = pageNumber;
  7224. }
  7225. get pagesRotation() {
  7226. return this._pagesRotation;
  7227. }
  7228. set pagesRotation(rotation) {
  7229. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7230. throw new Error("Invalid thumbnails rotation angle.");
  7231. }
  7232. if (!this.pdfDocument) {
  7233. return;
  7234. }
  7235. if (this._pagesRotation === rotation) {
  7236. return;
  7237. }
  7238. this._pagesRotation = rotation;
  7239. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7240. this._thumbnails[i].update(rotation);
  7241. }
  7242. }
  7243. cleanup() {
  7244. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7245. if (this._thumbnails[i] && this._thumbnails[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7246. this._thumbnails[i].reset();
  7247. }
  7248. }
  7249. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7250. }
  7251. _resetView() {
  7252. this._thumbnails = [];
  7253. this._currentPageNumber = 1;
  7254. this._pageLabels = null;
  7255. this._pagesRotation = 0;
  7256. this._optionalContentConfigPromise = null;
  7257. this._pagesRequests = new WeakMap();
  7258. this._setImageDisabled = false;
  7259. this.container.textContent = "";
  7260. }
  7261. setDocument(pdfDocument) {
  7262. if (this.pdfDocument) {
  7263. this._cancelRendering();
  7264. this._resetView();
  7265. }
  7266. this.pdfDocument = pdfDocument;
  7267. if (!pdfDocument) {
  7268. return;
  7269. }
  7270. const firstPagePromise = pdfDocument.getPage(1);
  7271. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7272. firstPagePromise.then(firstPdfPage => {
  7273. this._optionalContentConfigPromise = optionalContentConfigPromise;
  7274. const pagesCount = pdfDocument.numPages;
  7275. const viewport = firstPdfPage.getViewport({
  7276. scale: 1
  7277. });
  7278. const checkSetImageDisabled = () => {
  7279. return this._setImageDisabled;
  7280. };
  7281. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7282. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7283. container: this.container,
  7284. id: pageNum,
  7285. defaultViewport: viewport.clone(),
  7286. optionalContentConfigPromise,
  7287. linkService: this.linkService,
  7288. renderingQueue: this.renderingQueue,
  7289. checkSetImageDisabled,
  7290. l10n: this.l10n
  7291. });
  7292. this._thumbnails.push(thumbnail);
  7293. }
  7294. const firstThumbnailView = this._thumbnails[0];
  7295. if (firstThumbnailView) {
  7296. firstThumbnailView.setPdfPage(firstPdfPage);
  7297. }
  7298. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7299. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7300. }).catch(reason => {
  7301. console.error("Unable to initialize thumbnail viewer", reason);
  7302. });
  7303. }
  7304. _cancelRendering() {
  7305. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7306. if (this._thumbnails[i]) {
  7307. this._thumbnails[i].cancelRendering();
  7308. }
  7309. }
  7310. }
  7311. setPageLabels(labels) {
  7312. if (!this.pdfDocument) {
  7313. return;
  7314. }
  7315. if (!labels) {
  7316. this._pageLabels = null;
  7317. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7318. this._pageLabels = null;
  7319. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7320. } else {
  7321. this._pageLabels = labels;
  7322. }
  7323. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7324. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7325. }
  7326. }
  7327. _ensurePdfPageLoaded(thumbView) {
  7328. if (thumbView.pdfPage) {
  7329. return Promise.resolve(thumbView.pdfPage);
  7330. }
  7331. if (this._pagesRequests.has(thumbView)) {
  7332. return this._pagesRequests.get(thumbView);
  7333. }
  7334. const promise = this.pdfDocument.getPage(thumbView.id).then(pdfPage => {
  7335. if (!thumbView.pdfPage) {
  7336. thumbView.setPdfPage(pdfPage);
  7337. }
  7338. this._pagesRequests.delete(thumbView);
  7339. return pdfPage;
  7340. }).catch(reason => {
  7341. console.error("Unable to get page for thumb view", reason);
  7342. this._pagesRequests.delete(thumbView);
  7343. });
  7344. this._pagesRequests.set(thumbView, promise);
  7345. return promise;
  7346. }
  7347. forceRendering() {
  7348. const visibleThumbs = this._getVisibleThumbs();
  7349. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
  7350. if (thumbView) {
  7351. this._ensurePdfPageLoaded(thumbView).then(() => {
  7352. this.renderingQueue.renderView(thumbView);
  7353. });
  7354. return true;
  7355. }
  7356. return false;
  7357. }
  7358. }
  7359. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7360. /***/ }),
  7361. /* 26 */
  7362. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7363. Object.defineProperty(exports, "__esModule", ({
  7364. value: true
  7365. }));
  7366. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7367. var _ui_utils = __webpack_require__(4);
  7368. var _pdfjsLib = __webpack_require__(5);
  7369. var _pdf_rendering_queue = __webpack_require__(8);
  7370. const DRAW_UPSCALE_FACTOR = 2;
  7371. const MAX_NUM_SCALING_STEPS = 3;
  7372. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7373. const THUMBNAIL_WIDTH = 98;
  7374. const TempImageFactory = function TempImageFactoryClosure() {
  7375. let tempCanvasCache = null;
  7376. return {
  7377. getCanvas(width, height) {
  7378. let tempCanvas = tempCanvasCache;
  7379. if (!tempCanvas) {
  7380. tempCanvas = document.createElement("canvas");
  7381. tempCanvasCache = tempCanvas;
  7382. }
  7383. tempCanvas.width = width;
  7384. tempCanvas.height = height;
  7385. tempCanvas.mozOpaque = true;
  7386. const ctx = tempCanvas.getContext("2d", {
  7387. alpha: false
  7388. });
  7389. ctx.save();
  7390. ctx.fillStyle = "rgb(255, 255, 255)";
  7391. ctx.fillRect(0, 0, width, height);
  7392. ctx.restore();
  7393. return [tempCanvas, tempCanvas.getContext("2d")];
  7394. },
  7395. destroyCanvas() {
  7396. const tempCanvas = tempCanvasCache;
  7397. if (tempCanvas) {
  7398. tempCanvas.width = 0;
  7399. tempCanvas.height = 0;
  7400. }
  7401. tempCanvasCache = null;
  7402. }
  7403. };
  7404. }();
  7405. exports.TempImageFactory = TempImageFactory;
  7406. class PDFThumbnailView {
  7407. constructor({
  7408. container,
  7409. id,
  7410. defaultViewport,
  7411. optionalContentConfigPromise,
  7412. linkService,
  7413. renderingQueue,
  7414. checkSetImageDisabled,
  7415. l10n
  7416. }) {
  7417. this.id = id;
  7418. this.renderingId = "thumbnail" + id;
  7419. this.pageLabel = null;
  7420. this.pdfPage = null;
  7421. this.rotation = 0;
  7422. this.viewport = defaultViewport;
  7423. this.pdfPageRotate = defaultViewport.rotation;
  7424. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7425. this.linkService = linkService;
  7426. this.renderingQueue = renderingQueue;
  7427. this.renderTask = null;
  7428. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7429. this.resume = null;
  7430. this._checkSetImageDisabled = checkSetImageDisabled || function () {
  7431. return false;
  7432. };
  7433. const pageWidth = this.viewport.width,
  7434. pageHeight = this.viewport.height,
  7435. pageRatio = pageWidth / pageHeight;
  7436. this.canvasWidth = THUMBNAIL_WIDTH;
  7437. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7438. this.scale = this.canvasWidth / pageWidth;
  7439. this.l10n = l10n;
  7440. const anchor = document.createElement("a");
  7441. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7442. this._thumbPageTitle.then(msg => {
  7443. anchor.title = msg;
  7444. });
  7445. anchor.onclick = function () {
  7446. linkService.goToPage(id);
  7447. return false;
  7448. };
  7449. this.anchor = anchor;
  7450. const div = document.createElement("div");
  7451. div.className = "thumbnail";
  7452. div.setAttribute("data-page-number", this.id);
  7453. this.div = div;
  7454. const ring = document.createElement("div");
  7455. ring.className = "thumbnailSelectionRing";
  7456. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7457. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7458. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7459. this.ring = ring;
  7460. div.appendChild(ring);
  7461. anchor.appendChild(div);
  7462. container.appendChild(anchor);
  7463. }
  7464. setPdfPage(pdfPage) {
  7465. this.pdfPage = pdfPage;
  7466. this.pdfPageRotate = pdfPage.rotate;
  7467. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7468. this.viewport = pdfPage.getViewport({
  7469. scale: 1,
  7470. rotation: totalRotation
  7471. });
  7472. this.reset();
  7473. }
  7474. reset() {
  7475. this.cancelRendering();
  7476. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7477. const pageWidth = this.viewport.width,
  7478. pageHeight = this.viewport.height,
  7479. pageRatio = pageWidth / pageHeight;
  7480. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7481. this.scale = this.canvasWidth / pageWidth;
  7482. this.div.removeAttribute("data-loaded");
  7483. const ring = this.ring;
  7484. ring.textContent = "";
  7485. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7486. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7487. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7488. if (this.canvas) {
  7489. this.canvas.width = 0;
  7490. this.canvas.height = 0;
  7491. delete this.canvas;
  7492. }
  7493. if (this.image) {
  7494. this.image.removeAttribute("src");
  7495. delete this.image;
  7496. }
  7497. }
  7498. update(rotation) {
  7499. if (typeof rotation !== "undefined") {
  7500. this.rotation = rotation;
  7501. }
  7502. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7503. this.viewport = this.viewport.clone({
  7504. scale: 1,
  7505. rotation: totalRotation
  7506. });
  7507. this.reset();
  7508. }
  7509. cancelRendering() {
  7510. if (this.renderTask) {
  7511. this.renderTask.cancel();
  7512. this.renderTask = null;
  7513. }
  7514. this.resume = null;
  7515. }
  7516. _getPageDrawContext(upscaleFactor = 1) {
  7517. const canvas = document.createElement("canvas");
  7518. canvas.mozOpaque = true;
  7519. const ctx = canvas.getContext("2d", {
  7520. alpha: false
  7521. });
  7522. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  7523. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7524. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7525. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7526. return {
  7527. ctx,
  7528. canvas,
  7529. transform
  7530. };
  7531. }
  7532. _convertCanvasToImage(canvas) {
  7533. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7534. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  7535. }
  7536. const reducedCanvas = this._reduceImage(canvas);
  7537. const image = document.createElement("img");
  7538. image.className = "thumbnailImage";
  7539. this._thumbPageCanvas.then(msg => {
  7540. image.setAttribute("aria-label", msg);
  7541. });
  7542. image.style.width = this.canvasWidth + "px";
  7543. image.style.height = this.canvasHeight + "px";
  7544. image.src = reducedCanvas.toDataURL();
  7545. this.image = image;
  7546. this.div.setAttribute("data-loaded", true);
  7547. this.ring.appendChild(image);
  7548. reducedCanvas.width = 0;
  7549. reducedCanvas.height = 0;
  7550. }
  7551. draw() {
  7552. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7553. console.error("Must be in new state before drawing");
  7554. return Promise.resolve(undefined);
  7555. }
  7556. const {
  7557. pdfPage
  7558. } = this;
  7559. if (!pdfPage) {
  7560. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7561. return Promise.reject(new Error("pdfPage is not loaded"));
  7562. }
  7563. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7564. const finishRenderTask = async (error = null) => {
  7565. if (renderTask === this.renderTask) {
  7566. this.renderTask = null;
  7567. }
  7568. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7569. return;
  7570. }
  7571. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7572. this._convertCanvasToImage(canvas);
  7573. if (error) {
  7574. throw error;
  7575. }
  7576. };
  7577. const {
  7578. ctx,
  7579. canvas,
  7580. transform
  7581. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7582. const drawViewport = this.viewport.clone({
  7583. scale: DRAW_UPSCALE_FACTOR * this.scale
  7584. });
  7585. const renderContinueCallback = cont => {
  7586. if (!this.renderingQueue.isHighestPriority(this)) {
  7587. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  7588. this.resume = () => {
  7589. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7590. cont();
  7591. };
  7592. return;
  7593. }
  7594. cont();
  7595. };
  7596. const renderContext = {
  7597. canvasContext: ctx,
  7598. transform,
  7599. viewport: drawViewport,
  7600. optionalContentConfigPromise: this._optionalContentConfigPromise
  7601. };
  7602. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7603. renderTask.onContinue = renderContinueCallback;
  7604. const resultPromise = renderTask.promise.then(function () {
  7605. return finishRenderTask(null);
  7606. }, function (error) {
  7607. return finishRenderTask(error);
  7608. });
  7609. resultPromise.finally(() => {
  7610. canvas.width = 0;
  7611. canvas.height = 0;
  7612. const pageCached = this.linkService.isPageCached(this.id);
  7613. if (!pageCached) {
  7614. this.pdfPage?.cleanup();
  7615. }
  7616. });
  7617. return resultPromise;
  7618. }
  7619. setImage(pageView) {
  7620. if (this._checkSetImageDisabled()) {
  7621. return;
  7622. }
  7623. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7624. return;
  7625. }
  7626. const {
  7627. canvas,
  7628. pdfPage
  7629. } = pageView;
  7630. if (!canvas) {
  7631. return;
  7632. }
  7633. if (!this.pdfPage) {
  7634. this.setPdfPage(pdfPage);
  7635. }
  7636. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7637. this._convertCanvasToImage(canvas);
  7638. }
  7639. _reduceImage(img) {
  7640. const {
  7641. ctx,
  7642. canvas
  7643. } = this._getPageDrawContext();
  7644. if (img.width <= 2 * canvas.width) {
  7645. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7646. return canvas;
  7647. }
  7648. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7649. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7650. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7651. while (reducedWidth > img.width || reducedHeight > img.height) {
  7652. reducedWidth >>= 1;
  7653. reducedHeight >>= 1;
  7654. }
  7655. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7656. while (reducedWidth > 2 * canvas.width) {
  7657. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7658. reducedWidth >>= 1;
  7659. reducedHeight >>= 1;
  7660. }
  7661. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7662. return canvas;
  7663. }
  7664. get _thumbPageTitle() {
  7665. return this.l10n.get("thumb_page_title", {
  7666. page: this.pageLabel ?? this.id
  7667. });
  7668. }
  7669. get _thumbPageCanvas() {
  7670. return this.l10n.get("thumb_page_canvas", {
  7671. page: this.pageLabel ?? this.id
  7672. });
  7673. }
  7674. setPageLabel(label) {
  7675. this.pageLabel = typeof label === "string" ? label : null;
  7676. this._thumbPageTitle.then(msg => {
  7677. this.anchor.title = msg;
  7678. });
  7679. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7680. return;
  7681. }
  7682. this._thumbPageCanvas.then(msg => {
  7683. this.image?.setAttribute("aria-label", msg);
  7684. });
  7685. }
  7686. }
  7687. exports.PDFThumbnailView = PDFThumbnailView;
  7688. /***/ }),
  7689. /* 27 */
  7690. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7691. Object.defineProperty(exports, "__esModule", ({
  7692. value: true
  7693. }));
  7694. exports.PDFViewer = void 0;
  7695. var _ui_utils = __webpack_require__(4);
  7696. var _base_viewer = __webpack_require__(28);
  7697. var _pdfjsLib = __webpack_require__(5);
  7698. class PDFViewer extends _base_viewer.BaseViewer {
  7699. get _viewerElement() {
  7700. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this.viewer);
  7701. }
  7702. _scrollIntoView({
  7703. pageDiv,
  7704. pageSpot = null,
  7705. pageNumber = null
  7706. }) {
  7707. if (!pageSpot && !this.isInPresentationMode) {
  7708. const left = pageDiv.offsetLeft + pageDiv.clientLeft;
  7709. const right = left + pageDiv.clientWidth;
  7710. const {
  7711. scrollLeft,
  7712. clientWidth
  7713. } = this.container;
  7714. if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
  7715. pageSpot = {
  7716. left: 0,
  7717. top: 0
  7718. };
  7719. }
  7720. }
  7721. super._scrollIntoView({
  7722. pageDiv,
  7723. pageSpot,
  7724. pageNumber
  7725. });
  7726. }
  7727. _getVisiblePages() {
  7728. if (this.isInPresentationMode) {
  7729. return this._getCurrentVisiblePage();
  7730. }
  7731. return super._getVisiblePages();
  7732. }
  7733. _updateHelper(visiblePages) {
  7734. if (this.isInPresentationMode) {
  7735. return;
  7736. }
  7737. let currentId = this._currentPageNumber;
  7738. let stillFullyVisible = false;
  7739. for (const page of visiblePages) {
  7740. if (page.percent < 100) {
  7741. break;
  7742. }
  7743. if (page.id === currentId && this._scrollMode === _ui_utils.ScrollMode.VERTICAL && this._spreadMode === _ui_utils.SpreadMode.NONE) {
  7744. stillFullyVisible = true;
  7745. break;
  7746. }
  7747. }
  7748. if (!stillFullyVisible) {
  7749. currentId = visiblePages[0].id;
  7750. }
  7751. this._setCurrentPageNumber(currentId);
  7752. }
  7753. }
  7754. exports.PDFViewer = PDFViewer;
  7755. /***/ }),
  7756. /* 28 */
  7757. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7758. Object.defineProperty(exports, "__esModule", ({
  7759. value: true
  7760. }));
  7761. exports.BaseViewer = void 0;
  7762. var _pdfjsLib = __webpack_require__(5);
  7763. var _ui_utils = __webpack_require__(4);
  7764. var _pdf_rendering_queue = __webpack_require__(8);
  7765. var _annotation_layer_builder = __webpack_require__(29);
  7766. var _l10n_utils = __webpack_require__(30);
  7767. var _pdf_page_view = __webpack_require__(31);
  7768. var _pdf_link_service = __webpack_require__(19);
  7769. var _struct_tree_layer_builder = __webpack_require__(32);
  7770. var _text_layer_builder = __webpack_require__(33);
  7771. var _xfa_layer_builder = __webpack_require__(34);
  7772. const DEFAULT_CACHE_SIZE = 10;
  7773. function PDFPageViewBuffer(size) {
  7774. const data = [];
  7775. this.push = function (view) {
  7776. const i = data.indexOf(view);
  7777. if (i >= 0) {
  7778. data.splice(i, 1);
  7779. }
  7780. data.push(view);
  7781. if (data.length > size) {
  7782. data.shift().destroy();
  7783. }
  7784. };
  7785. this.resize = function (newSize, pagesToKeep) {
  7786. size = newSize;
  7787. if (pagesToKeep) {
  7788. const pageIdsToKeep = new Set();
  7789. for (let i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
  7790. pageIdsToKeep.add(pagesToKeep[i].id);
  7791. }
  7792. (0, _ui_utils.moveToEndOfArray)(data, function (page) {
  7793. return pageIdsToKeep.has(page.id);
  7794. });
  7795. }
  7796. while (data.length > size) {
  7797. data.shift().destroy();
  7798. }
  7799. };
  7800. this.has = function (view) {
  7801. return data.includes(view);
  7802. };
  7803. }
  7804. function isSameScale(oldScale, newScale) {
  7805. if (newScale === oldScale) {
  7806. return true;
  7807. }
  7808. if (Math.abs(newScale - oldScale) < 1e-15) {
  7809. return true;
  7810. }
  7811. return false;
  7812. }
  7813. class BaseViewer {
  7814. constructor(options) {
  7815. if (this.constructor === BaseViewer) {
  7816. throw new Error("Cannot initialize BaseViewer.");
  7817. }
  7818. const viewerVersion = '2.9.359';
  7819. if (_pdfjsLib.version !== viewerVersion) {
  7820. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  7821. }
  7822. this._name = this.constructor.name;
  7823. this.container = options.container;
  7824. this.viewer = options.viewer || options.container.firstElementChild;
  7825. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  7826. throw new Error("Invalid `container` and/or `viewer` option.");
  7827. }
  7828. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  7829. throw new Error("The `container` must be absolutely positioned.");
  7830. }
  7831. this.eventBus = options.eventBus;
  7832. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  7833. this.downloadManager = options.downloadManager || null;
  7834. this.findController = options.findController || null;
  7835. this._scriptingManager = options.scriptingManager || null;
  7836. this.removePageBorders = options.removePageBorders || false;
  7837. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  7838. this.imageResourcesPath = options.imageResourcesPath || "";
  7839. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  7840. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  7841. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7842. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  7843. this.maxCanvasPixels = options.maxCanvasPixels;
  7844. this.l10n = options.l10n || _l10n_utils.NullL10n;
  7845. this.enableScripting = options.enableScripting === true && !!this._scriptingManager;
  7846. this.defaultRenderingQueue = !options.renderingQueue;
  7847. if (this.defaultRenderingQueue) {
  7848. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  7849. this.renderingQueue.setViewer(this);
  7850. } else {
  7851. this.renderingQueue = options.renderingQueue;
  7852. }
  7853. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  7854. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  7855. this._onBeforeDraw = this._onAfterDraw = null;
  7856. this._resetView();
  7857. if (this.removePageBorders) {
  7858. this.viewer.classList.add("removePageBorders");
  7859. }
  7860. Promise.resolve().then(() => {
  7861. this.eventBus.dispatch("baseviewerinit", {
  7862. source: this
  7863. });
  7864. });
  7865. }
  7866. get pagesCount() {
  7867. return this._pages.length;
  7868. }
  7869. getPageView(index) {
  7870. return this._pages[index];
  7871. }
  7872. get pageViewsReady() {
  7873. if (!this._pagesCapability.settled) {
  7874. return false;
  7875. }
  7876. return this._pages.every(function (pageView) {
  7877. return pageView?.pdfPage;
  7878. });
  7879. }
  7880. get currentPageNumber() {
  7881. return this._currentPageNumber;
  7882. }
  7883. set currentPageNumber(val) {
  7884. if (!Number.isInteger(val)) {
  7885. throw new Error("Invalid page number.");
  7886. }
  7887. if (!this.pdfDocument) {
  7888. return;
  7889. }
  7890. if (!this._setCurrentPageNumber(val, true)) {
  7891. console.error(`${this._name}.currentPageNumber: "${val}" is not a valid page.`);
  7892. }
  7893. }
  7894. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  7895. if (this._currentPageNumber === val) {
  7896. if (resetCurrentPageView) {
  7897. this._resetCurrentPageView();
  7898. }
  7899. return true;
  7900. }
  7901. if (!(0 < val && val <= this.pagesCount)) {
  7902. return false;
  7903. }
  7904. const previous = this._currentPageNumber;
  7905. this._currentPageNumber = val;
  7906. this.eventBus.dispatch("pagechanging", {
  7907. source: this,
  7908. pageNumber: val,
  7909. pageLabel: this._pageLabels?.[val - 1] ?? null,
  7910. previous
  7911. });
  7912. if (resetCurrentPageView) {
  7913. this._resetCurrentPageView();
  7914. }
  7915. return true;
  7916. }
  7917. get currentPageLabel() {
  7918. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  7919. }
  7920. set currentPageLabel(val) {
  7921. if (!this.pdfDocument) {
  7922. return;
  7923. }
  7924. let page = val | 0;
  7925. if (this._pageLabels) {
  7926. const i = this._pageLabels.indexOf(val);
  7927. if (i >= 0) {
  7928. page = i + 1;
  7929. }
  7930. }
  7931. if (!this._setCurrentPageNumber(page, true)) {
  7932. console.error(`${this._name}.currentPageLabel: "${val}" is not a valid page.`);
  7933. }
  7934. }
  7935. get currentScale() {
  7936. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  7937. }
  7938. set currentScale(val) {
  7939. if (isNaN(val)) {
  7940. throw new Error("Invalid numeric scale.");
  7941. }
  7942. if (!this.pdfDocument) {
  7943. return;
  7944. }
  7945. this._setScale(val, false);
  7946. }
  7947. get currentScaleValue() {
  7948. return this._currentScaleValue;
  7949. }
  7950. set currentScaleValue(val) {
  7951. if (!this.pdfDocument) {
  7952. return;
  7953. }
  7954. this._setScale(val, false);
  7955. }
  7956. get pagesRotation() {
  7957. return this._pagesRotation;
  7958. }
  7959. set pagesRotation(rotation) {
  7960. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7961. throw new Error("Invalid pages rotation angle.");
  7962. }
  7963. if (!this.pdfDocument) {
  7964. return;
  7965. }
  7966. rotation %= 360;
  7967. if (rotation < 0) {
  7968. rotation += 360;
  7969. }
  7970. if (this._pagesRotation === rotation) {
  7971. return;
  7972. }
  7973. this._pagesRotation = rotation;
  7974. const pageNumber = this._currentPageNumber;
  7975. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  7976. const pageView = this._pages[i];
  7977. pageView.update(pageView.scale, rotation);
  7978. }
  7979. if (this._currentScaleValue) {
  7980. this._setScale(this._currentScaleValue, true);
  7981. }
  7982. this.eventBus.dispatch("rotationchanging", {
  7983. source: this,
  7984. pagesRotation: rotation,
  7985. pageNumber
  7986. });
  7987. if (this.defaultRenderingQueue) {
  7988. this.update();
  7989. }
  7990. }
  7991. get firstPagePromise() {
  7992. return this.pdfDocument ? this._firstPageCapability.promise : null;
  7993. }
  7994. get onePageRendered() {
  7995. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  7996. }
  7997. get pagesPromise() {
  7998. return this.pdfDocument ? this._pagesCapability.promise : null;
  7999. }
  8000. get _viewerElement() {
  8001. throw new Error("Not implemented: _viewerElement");
  8002. }
  8003. _onePageRenderedOrForceFetch() {
  8004. if (!this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8005. return Promise.resolve();
  8006. }
  8007. return this._onePageRenderedCapability.promise;
  8008. }
  8009. setDocument(pdfDocument) {
  8010. if (this.pdfDocument) {
  8011. this.eventBus.dispatch("pagesdestroy", {
  8012. source: this
  8013. });
  8014. this._cancelRendering();
  8015. this._resetView();
  8016. if (this.findController) {
  8017. this.findController.setDocument(null);
  8018. }
  8019. if (this._scriptingManager) {
  8020. this._scriptingManager.setDocument(null);
  8021. }
  8022. }
  8023. this.pdfDocument = pdfDocument;
  8024. if (!pdfDocument) {
  8025. return;
  8026. }
  8027. const isPureXfa = pdfDocument.isPureXfa;
  8028. const pagesCount = pdfDocument.numPages;
  8029. const firstPagePromise = pdfDocument.getPage(1);
  8030. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8031. this._pagesCapability.promise.then(() => {
  8032. this.eventBus.dispatch("pagesloaded", {
  8033. source: this,
  8034. pagesCount
  8035. });
  8036. });
  8037. this._onBeforeDraw = evt => {
  8038. const pageView = this._pages[evt.pageNumber - 1];
  8039. if (!pageView) {
  8040. return;
  8041. }
  8042. this._buffer.push(pageView);
  8043. };
  8044. this.eventBus._on("pagerender", this._onBeforeDraw);
  8045. this._onAfterDraw = evt => {
  8046. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8047. return;
  8048. }
  8049. this._onePageRenderedCapability.resolve();
  8050. this.eventBus._off("pagerendered", this._onAfterDraw);
  8051. this._onAfterDraw = null;
  8052. };
  8053. this.eventBus._on("pagerendered", this._onAfterDraw);
  8054. firstPagePromise.then(firstPdfPage => {
  8055. this._firstPageCapability.resolve(firstPdfPage);
  8056. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8057. const scale = this.currentScale;
  8058. const viewport = firstPdfPage.getViewport({
  8059. scale: scale * _ui_utils.CSS_UNITS
  8060. });
  8061. const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE ? this : null;
  8062. const xfaLayerFactory = isPureXfa ? this : null;
  8063. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8064. const pageView = new _pdf_page_view.PDFPageView({
  8065. container: this._viewerElement,
  8066. eventBus: this.eventBus,
  8067. id: pageNum,
  8068. scale,
  8069. defaultViewport: viewport.clone(),
  8070. optionalContentConfigPromise,
  8071. renderingQueue: this.renderingQueue,
  8072. textLayerFactory,
  8073. textLayerMode: this.textLayerMode,
  8074. annotationLayerFactory: this,
  8075. xfaLayerFactory,
  8076. structTreeLayerFactory: this,
  8077. imageResourcesPath: this.imageResourcesPath,
  8078. renderInteractiveForms: this.renderInteractiveForms,
  8079. renderer: this.renderer,
  8080. useOnlyCssZoom: this.useOnlyCssZoom,
  8081. maxCanvasPixels: this.maxCanvasPixels,
  8082. l10n: this.l10n
  8083. });
  8084. this._pages.push(pageView);
  8085. }
  8086. const firstPageView = this._pages[0];
  8087. if (firstPageView) {
  8088. firstPageView.setPdfPage(firstPdfPage);
  8089. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8090. }
  8091. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8092. this._updateSpreadMode();
  8093. }
  8094. this._onePageRenderedOrForceFetch().then(() => {
  8095. if (this.findController) {
  8096. this.findController.setDocument(pdfDocument);
  8097. }
  8098. if (this.enableScripting) {
  8099. this._scriptingManager.setDocument(pdfDocument);
  8100. }
  8101. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > 7500) {
  8102. this._pagesCapability.resolve();
  8103. return;
  8104. }
  8105. let getPagesLeft = pagesCount - 1;
  8106. if (getPagesLeft <= 0) {
  8107. this._pagesCapability.resolve();
  8108. return;
  8109. }
  8110. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8111. pdfDocument.getPage(pageNum).then(pdfPage => {
  8112. const pageView = this._pages[pageNum - 1];
  8113. if (!pageView.pdfPage) {
  8114. pageView.setPdfPage(pdfPage);
  8115. }
  8116. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8117. if (--getPagesLeft === 0) {
  8118. this._pagesCapability.resolve();
  8119. }
  8120. }, reason => {
  8121. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8122. if (--getPagesLeft === 0) {
  8123. this._pagesCapability.resolve();
  8124. }
  8125. });
  8126. }
  8127. });
  8128. this.eventBus.dispatch("pagesinit", {
  8129. source: this
  8130. });
  8131. if (this.defaultRenderingQueue) {
  8132. this.update();
  8133. }
  8134. }).catch(reason => {
  8135. console.error("Unable to initialize viewer", reason);
  8136. });
  8137. }
  8138. setPageLabels(labels) {
  8139. if (!this.pdfDocument) {
  8140. return;
  8141. }
  8142. if (!labels) {
  8143. this._pageLabels = null;
  8144. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8145. this._pageLabels = null;
  8146. console.error(`${this._name}.setPageLabels: Invalid page labels.`);
  8147. } else {
  8148. this._pageLabels = labels;
  8149. }
  8150. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8151. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8152. }
  8153. }
  8154. _resetView() {
  8155. this._pages = [];
  8156. this._currentPageNumber = 1;
  8157. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8158. this._currentScaleValue = null;
  8159. this._pageLabels = null;
  8160. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8161. this._location = null;
  8162. this._pagesRotation = 0;
  8163. this._optionalContentConfigPromise = null;
  8164. this._pagesRequests = new WeakMap();
  8165. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8166. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8167. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8168. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8169. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8170. if (this._onBeforeDraw) {
  8171. this.eventBus._off("pagerender", this._onBeforeDraw);
  8172. this._onBeforeDraw = null;
  8173. }
  8174. if (this._onAfterDraw) {
  8175. this.eventBus._off("pagerendered", this._onAfterDraw);
  8176. this._onAfterDraw = null;
  8177. }
  8178. this.viewer.textContent = "";
  8179. this._updateScrollMode();
  8180. }
  8181. _scrollUpdate() {
  8182. if (this.pagesCount === 0) {
  8183. return;
  8184. }
  8185. this.update();
  8186. }
  8187. _scrollIntoView({
  8188. pageDiv,
  8189. pageSpot = null,
  8190. pageNumber = null
  8191. }) {
  8192. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  8193. }
  8194. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8195. this._currentScaleValue = newValue.toString();
  8196. if (isSameScale(this._currentScale, newScale)) {
  8197. if (preset) {
  8198. this.eventBus.dispatch("scalechanging", {
  8199. source: this,
  8200. scale: newScale,
  8201. presetValue: newValue
  8202. });
  8203. }
  8204. return;
  8205. }
  8206. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8207. this._pages[i].update(newScale);
  8208. }
  8209. this._currentScale = newScale;
  8210. if (!noScroll) {
  8211. let page = this._currentPageNumber,
  8212. dest;
  8213. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8214. page = this._location.pageNumber;
  8215. dest = [null, {
  8216. name: "XYZ"
  8217. }, this._location.left, this._location.top, null];
  8218. }
  8219. this.scrollPageIntoView({
  8220. pageNumber: page,
  8221. destArray: dest,
  8222. allowNegativeOffset: true
  8223. });
  8224. }
  8225. this.eventBus.dispatch("scalechanging", {
  8226. source: this,
  8227. scale: newScale,
  8228. presetValue: preset ? newValue : undefined
  8229. });
  8230. if (this.defaultRenderingQueue) {
  8231. this.update();
  8232. }
  8233. }
  8234. get _pageWidthScaleFactor() {
  8235. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL && !this.isInPresentationMode) {
  8236. return 2;
  8237. }
  8238. return 1;
  8239. }
  8240. _setScale(value, noScroll = false) {
  8241. let scale = parseFloat(value);
  8242. if (scale > 0) {
  8243. this._setScaleUpdatePages(scale, value, noScroll, false);
  8244. } else {
  8245. const currentPage = this._pages[this._currentPageNumber - 1];
  8246. if (!currentPage) {
  8247. return;
  8248. }
  8249. const noPadding = this.isInPresentationMode || this.removePageBorders;
  8250. let hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8251. let vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
  8252. if (!noPadding && this._isScrollModeHorizontal) {
  8253. [hPadding, vPadding] = [vPadding, hPadding];
  8254. }
  8255. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8256. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8257. switch (value) {
  8258. case "page-actual":
  8259. scale = 1;
  8260. break;
  8261. case "page-width":
  8262. scale = pageWidthScale;
  8263. break;
  8264. case "page-height":
  8265. scale = pageHeightScale;
  8266. break;
  8267. case "page-fit":
  8268. scale = Math.min(pageWidthScale, pageHeightScale);
  8269. break;
  8270. case "auto":
  8271. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8272. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8273. break;
  8274. default:
  8275. console.error(`${this._name}._setScale: "${value}" is an unknown zoom value.`);
  8276. return;
  8277. }
  8278. this._setScaleUpdatePages(scale, value, noScroll, true);
  8279. }
  8280. }
  8281. _resetCurrentPageView() {
  8282. if (this.isInPresentationMode) {
  8283. this._setScale(this._currentScaleValue, true);
  8284. }
  8285. const pageView = this._pages[this._currentPageNumber - 1];
  8286. this._scrollIntoView({
  8287. pageDiv: pageView.div
  8288. });
  8289. }
  8290. pageLabelToPageNumber(label) {
  8291. if (!this._pageLabels) {
  8292. return null;
  8293. }
  8294. const i = this._pageLabels.indexOf(label);
  8295. if (i < 0) {
  8296. return null;
  8297. }
  8298. return i + 1;
  8299. }
  8300. scrollPageIntoView({
  8301. pageNumber,
  8302. destArray = null,
  8303. allowNegativeOffset = false,
  8304. ignoreDestinationZoom = false
  8305. }) {
  8306. if (!this.pdfDocument) {
  8307. return;
  8308. }
  8309. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8310. if (!pageView) {
  8311. console.error(`${this._name}.scrollPageIntoView: ` + `"${pageNumber}" is not a valid pageNumber parameter.`);
  8312. return;
  8313. }
  8314. if (this.isInPresentationMode || !destArray) {
  8315. this._setCurrentPageNumber(pageNumber, true);
  8316. return;
  8317. }
  8318. let x = 0,
  8319. y = 0;
  8320. let width = 0,
  8321. height = 0,
  8322. widthScale,
  8323. heightScale;
  8324. const changeOrientation = pageView.rotation % 180 !== 0;
  8325. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  8326. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  8327. let scale = 0;
  8328. switch (destArray[1].name) {
  8329. case "XYZ":
  8330. x = destArray[2];
  8331. y = destArray[3];
  8332. scale = destArray[4];
  8333. x = x !== null ? x : 0;
  8334. y = y !== null ? y : pageHeight;
  8335. break;
  8336. case "Fit":
  8337. case "FitB":
  8338. scale = "page-fit";
  8339. break;
  8340. case "FitH":
  8341. case "FitBH":
  8342. y = destArray[2];
  8343. scale = "page-width";
  8344. if (y === null && this._location) {
  8345. x = this._location.left;
  8346. y = this._location.top;
  8347. } else if (typeof y !== "number") {
  8348. y = pageHeight;
  8349. }
  8350. break;
  8351. case "FitV":
  8352. case "FitBV":
  8353. x = destArray[2];
  8354. width = pageWidth;
  8355. height = pageHeight;
  8356. scale = "page-height";
  8357. break;
  8358. case "FitR":
  8359. x = destArray[2];
  8360. y = destArray[3];
  8361. width = destArray[4] - x;
  8362. height = destArray[5] - y;
  8363. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8364. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8365. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  8366. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  8367. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8368. break;
  8369. default:
  8370. console.error(`${this._name}.scrollPageIntoView: ` + `"${destArray[1].name}" is not a valid destination type.`);
  8371. return;
  8372. }
  8373. if (!ignoreDestinationZoom) {
  8374. if (scale && scale !== this._currentScale) {
  8375. this.currentScaleValue = scale;
  8376. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8377. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8378. }
  8379. }
  8380. if (scale === "page-fit" && !destArray[4]) {
  8381. this._scrollIntoView({
  8382. pageDiv: pageView.div,
  8383. pageNumber
  8384. });
  8385. return;
  8386. }
  8387. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8388. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8389. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8390. if (!allowNegativeOffset) {
  8391. left = Math.max(left, 0);
  8392. top = Math.max(top, 0);
  8393. }
  8394. this._scrollIntoView({
  8395. pageDiv: pageView.div,
  8396. pageSpot: {
  8397. left,
  8398. top
  8399. },
  8400. pageNumber
  8401. });
  8402. }
  8403. _updateLocation(firstPage) {
  8404. const currentScale = this._currentScale;
  8405. const currentScaleValue = this._currentScaleValue;
  8406. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8407. const pageNumber = firstPage.id;
  8408. let pdfOpenParams = "#page=" + pageNumber;
  8409. pdfOpenParams += "&zoom=" + normalizedScaleValue;
  8410. const currentPageView = this._pages[pageNumber - 1];
  8411. const container = this.container;
  8412. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8413. const intLeft = Math.round(topLeft[0]);
  8414. const intTop = Math.round(topLeft[1]);
  8415. pdfOpenParams += "," + intLeft + "," + intTop;
  8416. this._location = {
  8417. pageNumber,
  8418. scale: normalizedScaleValue,
  8419. top: intTop,
  8420. left: intLeft,
  8421. rotation: this._pagesRotation,
  8422. pdfOpenParams
  8423. };
  8424. }
  8425. _updateHelper(visiblePages) {
  8426. throw new Error("Not implemented: _updateHelper");
  8427. }
  8428. update() {
  8429. const visible = this._getVisiblePages();
  8430. const visiblePages = visible.views,
  8431. numVisiblePages = visiblePages.length;
  8432. if (numVisiblePages === 0) {
  8433. return;
  8434. }
  8435. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8436. this._buffer.resize(newCacheSize, visiblePages);
  8437. this.renderingQueue.renderHighestPriority(visible);
  8438. this._updateHelper(visiblePages);
  8439. this._updateLocation(visible.first);
  8440. this.eventBus.dispatch("updateviewarea", {
  8441. source: this,
  8442. location: this._location
  8443. });
  8444. }
  8445. containsElement(element) {
  8446. return this.container.contains(element);
  8447. }
  8448. focus() {
  8449. this.container.focus();
  8450. }
  8451. get _isScrollModeHorizontal() {
  8452. return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
  8453. }
  8454. get _isContainerRtl() {
  8455. return getComputedStyle(this.container).direction === "rtl";
  8456. }
  8457. get isInPresentationMode() {
  8458. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8459. }
  8460. get isChangingPresentationMode() {
  8461. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8462. }
  8463. get isHorizontalScrollbarEnabled() {
  8464. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8465. }
  8466. get isVerticalScrollbarEnabled() {
  8467. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8468. }
  8469. _getCurrentVisiblePage() {
  8470. if (!this.pagesCount) {
  8471. return {
  8472. views: []
  8473. };
  8474. }
  8475. const pageView = this._pages[this._currentPageNumber - 1];
  8476. const element = pageView.div;
  8477. const view = {
  8478. id: pageView.id,
  8479. x: element.offsetLeft + element.clientLeft,
  8480. y: element.offsetTop + element.clientTop,
  8481. view: pageView
  8482. };
  8483. return {
  8484. first: view,
  8485. last: view,
  8486. views: [view]
  8487. };
  8488. }
  8489. _getVisiblePages() {
  8490. return (0, _ui_utils.getVisibleElements)({
  8491. scrollEl: this.container,
  8492. views: this._pages,
  8493. sortByVisibility: true,
  8494. horizontal: this._isScrollModeHorizontal,
  8495. rtl: this._isScrollModeHorizontal && this._isContainerRtl
  8496. });
  8497. }
  8498. isPageVisible(pageNumber) {
  8499. if (!this.pdfDocument) {
  8500. return false;
  8501. }
  8502. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8503. console.error(`${this._name}.isPageVisible: "${pageNumber}" is not a valid page.`);
  8504. return false;
  8505. }
  8506. return this._getVisiblePages().views.some(function (view) {
  8507. return view.id === pageNumber;
  8508. });
  8509. }
  8510. isPageCached(pageNumber) {
  8511. if (!this.pdfDocument || !this._buffer) {
  8512. return false;
  8513. }
  8514. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8515. console.error(`${this._name}.isPageCached: "${pageNumber}" is not a valid page.`);
  8516. return false;
  8517. }
  8518. const pageView = this._pages[pageNumber - 1];
  8519. if (!pageView) {
  8520. return false;
  8521. }
  8522. return this._buffer.has(pageView);
  8523. }
  8524. cleanup() {
  8525. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8526. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  8527. this._pages[i].reset();
  8528. }
  8529. }
  8530. }
  8531. _cancelRendering() {
  8532. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8533. if (this._pages[i]) {
  8534. this._pages[i].cancelRendering();
  8535. }
  8536. }
  8537. }
  8538. _ensurePdfPageLoaded(pageView) {
  8539. if (pageView.pdfPage) {
  8540. return Promise.resolve(pageView.pdfPage);
  8541. }
  8542. if (this._pagesRequests.has(pageView)) {
  8543. return this._pagesRequests.get(pageView);
  8544. }
  8545. const promise = this.pdfDocument.getPage(pageView.id).then(pdfPage => {
  8546. if (!pageView.pdfPage) {
  8547. pageView.setPdfPage(pdfPage);
  8548. }
  8549. this._pagesRequests.delete(pageView);
  8550. return pdfPage;
  8551. }).catch(reason => {
  8552. console.error("Unable to get page for page view", reason);
  8553. this._pagesRequests.delete(pageView);
  8554. });
  8555. this._pagesRequests.set(pageView, promise);
  8556. return promise;
  8557. }
  8558. forceRendering(currentlyVisiblePages) {
  8559. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  8560. const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
  8561. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
  8562. if (pageView) {
  8563. this._ensurePdfPageLoaded(pageView).then(() => {
  8564. this.renderingQueue.renderView(pageView);
  8565. });
  8566. return true;
  8567. }
  8568. return false;
  8569. }
  8570. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  8571. return new _text_layer_builder.TextLayerBuilder({
  8572. textLayerDiv,
  8573. eventBus,
  8574. pageIndex,
  8575. viewport,
  8576. findController: this.isInPresentationMode ? null : this.findController,
  8577. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  8578. });
  8579. }
  8580. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = false, l10n = _l10n_utils.NullL10n, enableScripting = null, hasJSActionsPromise = null, mouseState = null) {
  8581. return new _annotation_layer_builder.AnnotationLayerBuilder({
  8582. pageDiv,
  8583. pdfPage,
  8584. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8585. imageResourcesPath,
  8586. renderInteractiveForms,
  8587. linkService: this.linkService,
  8588. downloadManager: this.downloadManager,
  8589. l10n,
  8590. enableScripting: enableScripting ?? this.enableScripting,
  8591. hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
  8592. mouseState: mouseState || this._scriptingManager?.mouseState
  8593. });
  8594. }
  8595. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null) {
  8596. return new _xfa_layer_builder.XfaLayerBuilder({
  8597. pageDiv,
  8598. pdfPage,
  8599. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage
  8600. });
  8601. }
  8602. createStructTreeLayerBuilder(pdfPage) {
  8603. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  8604. pdfPage
  8605. });
  8606. }
  8607. get hasEqualPageSizes() {
  8608. const firstPageView = this._pages[0];
  8609. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  8610. const pageView = this._pages[i];
  8611. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  8612. return false;
  8613. }
  8614. }
  8615. return true;
  8616. }
  8617. getPagesOverview() {
  8618. return this._pages.map(pageView => {
  8619. const viewport = pageView.pdfPage.getViewport({
  8620. scale: 1
  8621. });
  8622. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  8623. return {
  8624. width: viewport.width,
  8625. height: viewport.height,
  8626. rotation: viewport.rotation
  8627. };
  8628. }
  8629. return {
  8630. width: viewport.height,
  8631. height: viewport.width,
  8632. rotation: (viewport.rotation - 90) % 360
  8633. };
  8634. });
  8635. }
  8636. get optionalContentConfigPromise() {
  8637. if (!this.pdfDocument) {
  8638. return Promise.resolve(null);
  8639. }
  8640. if (!this._optionalContentConfigPromise) {
  8641. return this.pdfDocument.getOptionalContentConfig();
  8642. }
  8643. return this._optionalContentConfigPromise;
  8644. }
  8645. set optionalContentConfigPromise(promise) {
  8646. if (!(promise instanceof Promise)) {
  8647. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  8648. }
  8649. if (!this.pdfDocument) {
  8650. return;
  8651. }
  8652. if (!this._optionalContentConfigPromise) {
  8653. return;
  8654. }
  8655. this._optionalContentConfigPromise = promise;
  8656. for (const pageView of this._pages) {
  8657. pageView.update(pageView.scale, pageView.rotation, promise);
  8658. }
  8659. this.update();
  8660. this.eventBus.dispatch("optionalcontentconfigchanged", {
  8661. source: this,
  8662. promise
  8663. });
  8664. }
  8665. get scrollMode() {
  8666. return this._scrollMode;
  8667. }
  8668. set scrollMode(mode) {
  8669. if (this._scrollMode === mode) {
  8670. return;
  8671. }
  8672. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  8673. throw new Error(`Invalid scroll mode: ${mode}`);
  8674. }
  8675. this._scrollMode = mode;
  8676. this.eventBus.dispatch("scrollmodechanged", {
  8677. source: this,
  8678. mode
  8679. });
  8680. this._updateScrollMode(this._currentPageNumber);
  8681. }
  8682. _updateScrollMode(pageNumber = null) {
  8683. const scrollMode = this._scrollMode,
  8684. viewer = this.viewer;
  8685. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  8686. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  8687. if (!this.pdfDocument || !pageNumber) {
  8688. return;
  8689. }
  8690. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8691. this._setScale(this._currentScaleValue, true);
  8692. }
  8693. this._setCurrentPageNumber(pageNumber, true);
  8694. this.update();
  8695. }
  8696. get spreadMode() {
  8697. return this._spreadMode;
  8698. }
  8699. set spreadMode(mode) {
  8700. if (this._spreadMode === mode) {
  8701. return;
  8702. }
  8703. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  8704. throw new Error(`Invalid spread mode: ${mode}`);
  8705. }
  8706. this._spreadMode = mode;
  8707. this.eventBus.dispatch("spreadmodechanged", {
  8708. source: this,
  8709. mode
  8710. });
  8711. this._updateSpreadMode(this._currentPageNumber);
  8712. }
  8713. _updateSpreadMode(pageNumber = null) {
  8714. if (!this.pdfDocument) {
  8715. return;
  8716. }
  8717. const viewer = this.viewer,
  8718. pages = this._pages;
  8719. viewer.textContent = "";
  8720. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8721. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  8722. viewer.appendChild(pages[i].div);
  8723. }
  8724. } else {
  8725. const parity = this._spreadMode - 1;
  8726. let spread = null;
  8727. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  8728. if (spread === null) {
  8729. spread = document.createElement("div");
  8730. spread.className = "spread";
  8731. viewer.appendChild(spread);
  8732. } else if (i % 2 === parity) {
  8733. spread = spread.cloneNode(false);
  8734. viewer.appendChild(spread);
  8735. }
  8736. spread.appendChild(pages[i].div);
  8737. }
  8738. }
  8739. if (!pageNumber) {
  8740. return;
  8741. }
  8742. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8743. this._setScale(this._currentScaleValue, true);
  8744. }
  8745. this._setCurrentPageNumber(pageNumber, true);
  8746. this.update();
  8747. }
  8748. _getPageAdvance(currentPageNumber, previous = false) {
  8749. if (this.isInPresentationMode) {
  8750. return 1;
  8751. }
  8752. switch (this._scrollMode) {
  8753. case _ui_utils.ScrollMode.WRAPPED:
  8754. {
  8755. const {
  8756. views
  8757. } = this._getVisiblePages(),
  8758. pageLayout = new Map();
  8759. for (const {
  8760. id,
  8761. y,
  8762. percent,
  8763. widthPercent
  8764. } of views) {
  8765. if (percent === 0 || widthPercent < 100) {
  8766. continue;
  8767. }
  8768. let yArray = pageLayout.get(y);
  8769. if (!yArray) {
  8770. pageLayout.set(y, yArray || (yArray = []));
  8771. }
  8772. yArray.push(id);
  8773. }
  8774. for (const yArray of pageLayout.values()) {
  8775. const currentIndex = yArray.indexOf(currentPageNumber);
  8776. if (currentIndex === -1) {
  8777. continue;
  8778. }
  8779. const numPages = yArray.length;
  8780. if (numPages === 1) {
  8781. break;
  8782. }
  8783. if (previous) {
  8784. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  8785. const currentId = yArray[i],
  8786. expectedId = yArray[i + 1] - 1;
  8787. if (currentId < expectedId) {
  8788. return currentPageNumber - expectedId;
  8789. }
  8790. }
  8791. } else {
  8792. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  8793. const currentId = yArray[i],
  8794. expectedId = yArray[i - 1] + 1;
  8795. if (currentId > expectedId) {
  8796. return expectedId - currentPageNumber;
  8797. }
  8798. }
  8799. }
  8800. if (previous) {
  8801. const firstId = yArray[0];
  8802. if (firstId < currentPageNumber) {
  8803. return currentPageNumber - firstId + 1;
  8804. }
  8805. } else {
  8806. const lastId = yArray[numPages - 1];
  8807. if (lastId > currentPageNumber) {
  8808. return lastId - currentPageNumber + 1;
  8809. }
  8810. }
  8811. break;
  8812. }
  8813. break;
  8814. }
  8815. case _ui_utils.ScrollMode.HORIZONTAL:
  8816. {
  8817. break;
  8818. }
  8819. case _ui_utils.ScrollMode.VERTICAL:
  8820. {
  8821. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8822. break;
  8823. }
  8824. const parity = this._spreadMode - 1;
  8825. if (previous && currentPageNumber % 2 !== parity) {
  8826. break;
  8827. } else if (!previous && currentPageNumber % 2 === parity) {
  8828. break;
  8829. }
  8830. const {
  8831. views
  8832. } = this._getVisiblePages(),
  8833. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  8834. for (const {
  8835. id,
  8836. percent,
  8837. widthPercent
  8838. } of views) {
  8839. if (id !== expectedId) {
  8840. continue;
  8841. }
  8842. if (percent > 0 && widthPercent === 100) {
  8843. return 2;
  8844. }
  8845. break;
  8846. }
  8847. break;
  8848. }
  8849. }
  8850. return 1;
  8851. }
  8852. nextPage() {
  8853. const currentPageNumber = this._currentPageNumber,
  8854. pagesCount = this.pagesCount;
  8855. if (currentPageNumber >= pagesCount) {
  8856. return false;
  8857. }
  8858. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  8859. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  8860. return true;
  8861. }
  8862. previousPage() {
  8863. const currentPageNumber = this._currentPageNumber;
  8864. if (currentPageNumber <= 1) {
  8865. return false;
  8866. }
  8867. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  8868. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  8869. return true;
  8870. }
  8871. }
  8872. exports.BaseViewer = BaseViewer;
  8873. /***/ }),
  8874. /* 29 */
  8875. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8876. Object.defineProperty(exports, "__esModule", ({
  8877. value: true
  8878. }));
  8879. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
  8880. var _pdfjsLib = __webpack_require__(5);
  8881. var _l10n_utils = __webpack_require__(30);
  8882. var _pdf_link_service = __webpack_require__(19);
  8883. class AnnotationLayerBuilder {
  8884. constructor({
  8885. pageDiv,
  8886. pdfPage,
  8887. linkService,
  8888. downloadManager,
  8889. annotationStorage = null,
  8890. imageResourcesPath = "",
  8891. renderInteractiveForms = true,
  8892. l10n = _l10n_utils.NullL10n,
  8893. enableScripting = false,
  8894. hasJSActionsPromise = null,
  8895. mouseState = null
  8896. }) {
  8897. this.pageDiv = pageDiv;
  8898. this.pdfPage = pdfPage;
  8899. this.linkService = linkService;
  8900. this.downloadManager = downloadManager;
  8901. this.imageResourcesPath = imageResourcesPath;
  8902. this.renderInteractiveForms = renderInteractiveForms;
  8903. this.l10n = l10n;
  8904. this.annotationStorage = annotationStorage;
  8905. this.enableScripting = enableScripting;
  8906. this._hasJSActionsPromise = hasJSActionsPromise;
  8907. this._mouseState = mouseState;
  8908. this.div = null;
  8909. this._cancelled = false;
  8910. }
  8911. render(viewport, intent = "display") {
  8912. return Promise.all([this.pdfPage.getAnnotations({
  8913. intent
  8914. }), this._hasJSActionsPromise]).then(([annotations, hasJSActions = false]) => {
  8915. if (this._cancelled) {
  8916. return;
  8917. }
  8918. if (annotations.length === 0) {
  8919. return;
  8920. }
  8921. const parameters = {
  8922. viewport: viewport.clone({
  8923. dontFlip: true
  8924. }),
  8925. div: this.div,
  8926. annotations,
  8927. page: this.pdfPage,
  8928. imageResourcesPath: this.imageResourcesPath,
  8929. renderInteractiveForms: this.renderInteractiveForms,
  8930. linkService: this.linkService,
  8931. downloadManager: this.downloadManager,
  8932. annotationStorage: this.annotationStorage,
  8933. enableScripting: this.enableScripting,
  8934. hasJSActions,
  8935. mouseState: this._mouseState
  8936. };
  8937. if (this.div) {
  8938. _pdfjsLib.AnnotationLayer.update(parameters);
  8939. } else {
  8940. this.div = document.createElement("div");
  8941. this.div.className = "annotationLayer";
  8942. this.pageDiv.appendChild(this.div);
  8943. parameters.div = this.div;
  8944. _pdfjsLib.AnnotationLayer.render(parameters);
  8945. this.l10n.translate(this.div);
  8946. }
  8947. });
  8948. }
  8949. cancel() {
  8950. this._cancelled = true;
  8951. }
  8952. hide() {
  8953. if (!this.div) {
  8954. return;
  8955. }
  8956. this.div.hidden = true;
  8957. }
  8958. }
  8959. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  8960. class DefaultAnnotationLayerFactory {
  8961. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = true, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
  8962. return new AnnotationLayerBuilder({
  8963. pageDiv,
  8964. pdfPage,
  8965. imageResourcesPath,
  8966. renderInteractiveForms,
  8967. linkService: new _pdf_link_service.SimpleLinkService(),
  8968. l10n,
  8969. annotationStorage,
  8970. enableScripting,
  8971. hasJSActionsPromise,
  8972. mouseState
  8973. });
  8974. }
  8975. }
  8976. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  8977. /***/ }),
  8978. /* 30 */
  8979. /***/ ((__unused_webpack_module, exports) => {
  8980. Object.defineProperty(exports, "__esModule", ({
  8981. value: true
  8982. }));
  8983. exports.getL10nFallback = getL10nFallback;
  8984. exports.NullL10n = void 0;
  8985. const DEFAULT_L10N_STRINGS = {
  8986. of_pages: "of {{pagesCount}}",
  8987. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  8988. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  8989. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  8990. document_properties_date_string: "{{date}}, {{time}}",
  8991. document_properties_page_size_unit_inches: "in",
  8992. document_properties_page_size_unit_millimeters: "mm",
  8993. document_properties_page_size_orientation_portrait: "portrait",
  8994. document_properties_page_size_orientation_landscape: "landscape",
  8995. document_properties_page_size_name_a3: "A3",
  8996. document_properties_page_size_name_a4: "A4",
  8997. document_properties_page_size_name_letter: "Letter",
  8998. document_properties_page_size_name_legal: "Legal",
  8999. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9000. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9001. document_properties_linearized_yes: "Yes",
  9002. document_properties_linearized_no: "No",
  9003. print_progress_percent: "{{progress}}%",
  9004. "toggle_sidebar.title": "Toggle Sidebar",
  9005. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  9006. additional_layers: "Additional Layers",
  9007. page_landmark: "Page {{page}}",
  9008. thumb_page_title: "Page {{page}}",
  9009. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9010. find_reached_top: "Reached top of document, continued from bottom",
  9011. find_reached_bottom: "Reached end of document, continued from top",
  9012. "find_match_count[one]": "{{current}} of {{total}} match",
  9013. "find_match_count[other]": "{{current}} of {{total}} matches",
  9014. "find_match_count_limit[one]": "More than {{limit}} match",
  9015. "find_match_count_limit[other]": "More than {{limit}} matches",
  9016. find_not_found: "Phrase not found",
  9017. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  9018. error_message: "Message: {{message}}",
  9019. error_stack: "Stack: {{stack}}",
  9020. error_file: "File: {{file}}",
  9021. error_line: "Line: {{line}}",
  9022. rendering_error: "An error occurred while rendering the page.",
  9023. page_scale_width: "Page Width",
  9024. page_scale_fit: "Page Fit",
  9025. page_scale_auto: "Automatic Zoom",
  9026. page_scale_actual: "Actual Size",
  9027. page_scale_percent: "{{scale}}%",
  9028. loading: "Loading…",
  9029. loading_error: "An error occurred while loading the PDF.",
  9030. invalid_file_error: "Invalid or corrupted PDF file.",
  9031. missing_file_error: "Missing PDF file.",
  9032. unexpected_response_error: "Unexpected server response.",
  9033. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9034. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9035. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
  9036. };
  9037. function getL10nFallback(key, args) {
  9038. switch (key) {
  9039. case "find_match_count":
  9040. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9041. break;
  9042. case "find_match_count_limit":
  9043. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9044. break;
  9045. }
  9046. return DEFAULT_L10N_STRINGS[key] || "";
  9047. }
  9048. function formatL10nValue(text, args) {
  9049. if (!args) {
  9050. return text;
  9051. }
  9052. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9053. return name in args ? args[name] : "{{" + name + "}}";
  9054. });
  9055. }
  9056. const NullL10n = {
  9057. async getLanguage() {
  9058. return "en-us";
  9059. },
  9060. async getDirection() {
  9061. return "ltr";
  9062. },
  9063. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9064. return formatL10nValue(fallback, args);
  9065. },
  9066. async translate(element) {}
  9067. };
  9068. exports.NullL10n = NullL10n;
  9069. /***/ }),
  9070. /* 31 */
  9071. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9072. Object.defineProperty(exports, "__esModule", ({
  9073. value: true
  9074. }));
  9075. exports.PDFPageView = void 0;
  9076. var _ui_utils = __webpack_require__(4);
  9077. var _pdfjsLib = __webpack_require__(5);
  9078. var _l10n_utils = __webpack_require__(30);
  9079. var _pdf_rendering_queue = __webpack_require__(8);
  9080. var _viewer_compatibility = __webpack_require__(2);
  9081. const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
  9082. class PDFPageView {
  9083. constructor(options) {
  9084. const container = options.container;
  9085. const defaultViewport = options.defaultViewport;
  9086. this.id = options.id;
  9087. this.renderingId = "page" + this.id;
  9088. this.pdfPage = null;
  9089. this.pageLabel = null;
  9090. this.rotation = 0;
  9091. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9092. this.viewport = defaultViewport;
  9093. this.pdfPageRotate = defaultViewport.rotation;
  9094. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9095. this.hasRestrictedScaling = false;
  9096. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  9097. this.imageResourcesPath = options.imageResourcesPath || "";
  9098. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  9099. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9100. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9101. this.eventBus = options.eventBus;
  9102. this.renderingQueue = options.renderingQueue;
  9103. this.textLayerFactory = options.textLayerFactory;
  9104. this.annotationLayerFactory = options.annotationLayerFactory;
  9105. this.xfaLayerFactory = options.xfaLayerFactory;
  9106. this.structTreeLayerFactory = options.structTreeLayerFactory;
  9107. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9108. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9109. this.paintTask = null;
  9110. this.paintedViewportMap = new WeakMap();
  9111. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9112. this.resume = null;
  9113. this._renderError = null;
  9114. this.annotationLayer = null;
  9115. this.textLayer = null;
  9116. this.zoomLayer = null;
  9117. this.xfaLayer = null;
  9118. this.structTreeLayer = null;
  9119. const div = document.createElement("div");
  9120. div.className = "page";
  9121. div.style.width = Math.floor(this.viewport.width) + "px";
  9122. div.style.height = Math.floor(this.viewport.height) + "px";
  9123. div.setAttribute("data-page-number", this.id);
  9124. div.setAttribute("role", "region");
  9125. this.l10n.get("page_landmark", {
  9126. page: this.id
  9127. }).then(msg => {
  9128. div.setAttribute("aria-label", msg);
  9129. });
  9130. this.div = div;
  9131. container.appendChild(div);
  9132. }
  9133. setPdfPage(pdfPage) {
  9134. this.pdfPage = pdfPage;
  9135. this.pdfPageRotate = pdfPage.rotate;
  9136. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9137. this.viewport = pdfPage.getViewport({
  9138. scale: this.scale * _ui_utils.CSS_UNITS,
  9139. rotation: totalRotation
  9140. });
  9141. this.reset();
  9142. }
  9143. destroy() {
  9144. this.reset();
  9145. if (this.pdfPage) {
  9146. this.pdfPage.cleanup();
  9147. }
  9148. }
  9149. async _renderAnnotationLayer() {
  9150. let error = null;
  9151. try {
  9152. await this.annotationLayer.render(this.viewport, "display");
  9153. } catch (ex) {
  9154. error = ex;
  9155. } finally {
  9156. this.eventBus.dispatch("annotationlayerrendered", {
  9157. source: this,
  9158. pageNumber: this.id,
  9159. error
  9160. });
  9161. }
  9162. }
  9163. async _renderXfaLayer() {
  9164. let error = null;
  9165. try {
  9166. await this.xfaLayer.render(this.viewport, "display");
  9167. } catch (ex) {
  9168. error = ex;
  9169. } finally {
  9170. this.eventBus.dispatch("xfalayerrendered", {
  9171. source: this,
  9172. pageNumber: this.id,
  9173. error
  9174. });
  9175. }
  9176. }
  9177. _resetZoomLayer(removeFromDOM = false) {
  9178. if (!this.zoomLayer) {
  9179. return;
  9180. }
  9181. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9182. this.paintedViewportMap.delete(zoomLayerCanvas);
  9183. zoomLayerCanvas.width = 0;
  9184. zoomLayerCanvas.height = 0;
  9185. if (removeFromDOM) {
  9186. this.zoomLayer.remove();
  9187. }
  9188. this.zoomLayer = null;
  9189. }
  9190. reset(keepZoomLayer = false, keepAnnotations = false) {
  9191. this.cancelRendering(keepAnnotations);
  9192. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9193. const div = this.div;
  9194. div.style.width = Math.floor(this.viewport.width) + "px";
  9195. div.style.height = Math.floor(this.viewport.height) + "px";
  9196. const childNodes = div.childNodes;
  9197. const currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  9198. const currentAnnotationNode = keepAnnotations && this.annotationLayer?.div || null;
  9199. const currentXfaLayerNode = this.xfaLayer?.div || null;
  9200. for (let i = childNodes.length - 1; i >= 0; i--) {
  9201. const node = childNodes[i];
  9202. if (currentZoomLayerNode === node || currentAnnotationNode === node || currentXfaLayerNode === node) {
  9203. continue;
  9204. }
  9205. div.removeChild(node);
  9206. }
  9207. div.removeAttribute("data-loaded");
  9208. if (currentAnnotationNode) {
  9209. this.annotationLayer.hide();
  9210. } else if (this.annotationLayer) {
  9211. this.annotationLayer.cancel();
  9212. this.annotationLayer = null;
  9213. }
  9214. if (!currentZoomLayerNode) {
  9215. if (this.canvas) {
  9216. this.paintedViewportMap.delete(this.canvas);
  9217. this.canvas.width = 0;
  9218. this.canvas.height = 0;
  9219. delete this.canvas;
  9220. }
  9221. this._resetZoomLayer();
  9222. }
  9223. if (this.svg) {
  9224. this.paintedViewportMap.delete(this.svg);
  9225. delete this.svg;
  9226. }
  9227. this.loadingIconDiv = document.createElement("div");
  9228. this.loadingIconDiv.className = "loadingIcon";
  9229. this.loadingIconDiv.setAttribute("role", "img");
  9230. this.l10n.get("loading").then(msg => {
  9231. this.loadingIconDiv?.setAttribute("aria-label", msg);
  9232. });
  9233. div.appendChild(this.loadingIconDiv);
  9234. }
  9235. update(scale, rotation, optionalContentConfigPromise = null) {
  9236. this.scale = scale || this.scale;
  9237. if (typeof rotation !== "undefined") {
  9238. this.rotation = rotation;
  9239. }
  9240. if (optionalContentConfigPromise instanceof Promise) {
  9241. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9242. }
  9243. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9244. this.viewport = this.viewport.clone({
  9245. scale: this.scale * _ui_utils.CSS_UNITS,
  9246. rotation: totalRotation
  9247. });
  9248. if (this.svg) {
  9249. this.cssTransform(this.svg, true);
  9250. this.eventBus.dispatch("pagerendered", {
  9251. source: this,
  9252. pageNumber: this.id,
  9253. cssTransform: true,
  9254. timestamp: performance.now(),
  9255. error: this._renderError
  9256. });
  9257. return;
  9258. }
  9259. let isScalingRestricted = false;
  9260. if (this.canvas && this.maxCanvasPixels > 0) {
  9261. const outputScale = this.outputScale;
  9262. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  9263. isScalingRestricted = true;
  9264. }
  9265. }
  9266. if (this.canvas) {
  9267. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  9268. this.cssTransform(this.canvas, true);
  9269. this.eventBus.dispatch("pagerendered", {
  9270. source: this,
  9271. pageNumber: this.id,
  9272. cssTransform: true,
  9273. timestamp: performance.now(),
  9274. error: this._renderError
  9275. });
  9276. return;
  9277. }
  9278. if (!this.zoomLayer && !this.canvas.hidden) {
  9279. this.zoomLayer = this.canvas.parentNode;
  9280. this.zoomLayer.style.position = "absolute";
  9281. }
  9282. }
  9283. if (this.zoomLayer) {
  9284. this.cssTransform(this.zoomLayer.firstChild);
  9285. }
  9286. this.reset(true, true);
  9287. }
  9288. cancelRendering(keepAnnotations = false) {
  9289. if (this.paintTask) {
  9290. this.paintTask.cancel();
  9291. this.paintTask = null;
  9292. }
  9293. this.resume = null;
  9294. if (this.textLayer) {
  9295. this.textLayer.cancel();
  9296. this.textLayer = null;
  9297. }
  9298. if (!keepAnnotations && this.annotationLayer) {
  9299. this.annotationLayer.cancel();
  9300. this.annotationLayer = null;
  9301. }
  9302. if (this._onTextLayerRendered) {
  9303. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9304. this._onTextLayerRendered = null;
  9305. }
  9306. }
  9307. cssTransform(target, redrawAnnotations = false) {
  9308. const width = this.viewport.width;
  9309. const height = this.viewport.height;
  9310. const div = this.div;
  9311. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  9312. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  9313. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  9314. const absRotation = Math.abs(relativeRotation);
  9315. let scaleX = 1,
  9316. scaleY = 1;
  9317. if (absRotation === 90 || absRotation === 270) {
  9318. scaleX = height / width;
  9319. scaleY = width / height;
  9320. }
  9321. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  9322. if (this.textLayer) {
  9323. const textLayerViewport = this.textLayer.viewport;
  9324. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  9325. const textAbsRotation = Math.abs(textRelativeRotation);
  9326. let scale = width / textLayerViewport.width;
  9327. if (textAbsRotation === 90 || textAbsRotation === 270) {
  9328. scale = width / textLayerViewport.height;
  9329. }
  9330. const textLayerDiv = this.textLayer.textLayerDiv;
  9331. let transX, transY;
  9332. switch (textAbsRotation) {
  9333. case 0:
  9334. transX = transY = 0;
  9335. break;
  9336. case 90:
  9337. transX = 0;
  9338. transY = "-" + textLayerDiv.style.height;
  9339. break;
  9340. case 180:
  9341. transX = "-" + textLayerDiv.style.width;
  9342. transY = "-" + textLayerDiv.style.height;
  9343. break;
  9344. case 270:
  9345. transX = "-" + textLayerDiv.style.width;
  9346. transY = 0;
  9347. break;
  9348. default:
  9349. console.error("Bad rotation value.");
  9350. break;
  9351. }
  9352. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  9353. textLayerDiv.style.transformOrigin = "0% 0%";
  9354. }
  9355. if (redrawAnnotations && this.annotationLayer) {
  9356. this._renderAnnotationLayer();
  9357. }
  9358. if (this.xfaLayer) {
  9359. this._renderXfaLayer();
  9360. }
  9361. }
  9362. get width() {
  9363. return this.viewport.width;
  9364. }
  9365. get height() {
  9366. return this.viewport.height;
  9367. }
  9368. getPagePoint(x, y) {
  9369. return this.viewport.convertToPdfPoint(x, y);
  9370. }
  9371. draw() {
  9372. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  9373. console.error("Must be in new state before drawing");
  9374. this.reset();
  9375. }
  9376. const {
  9377. div,
  9378. pdfPage
  9379. } = this;
  9380. if (!pdfPage) {
  9381. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9382. if (this.loadingIconDiv) {
  9383. div.removeChild(this.loadingIconDiv);
  9384. delete this.loadingIconDiv;
  9385. }
  9386. return Promise.reject(new Error("pdfPage is not loaded"));
  9387. }
  9388. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9389. const canvasWrapper = document.createElement("div");
  9390. canvasWrapper.style.width = div.style.width;
  9391. canvasWrapper.style.height = div.style.height;
  9392. canvasWrapper.classList.add("canvasWrapper");
  9393. if (this.annotationLayer?.div) {
  9394. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  9395. } else {
  9396. div.appendChild(canvasWrapper);
  9397. }
  9398. let textLayer = null;
  9399. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  9400. const textLayerDiv = document.createElement("div");
  9401. textLayerDiv.className = "textLayer";
  9402. textLayerDiv.style.width = canvasWrapper.style.width;
  9403. textLayerDiv.style.height = canvasWrapper.style.height;
  9404. if (this.annotationLayer?.div) {
  9405. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  9406. } else {
  9407. div.appendChild(textLayerDiv);
  9408. }
  9409. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
  9410. }
  9411. this.textLayer = textLayer;
  9412. let renderContinueCallback = null;
  9413. if (this.renderingQueue) {
  9414. renderContinueCallback = cont => {
  9415. if (!this.renderingQueue.isHighestPriority(this)) {
  9416. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  9417. this.resume = () => {
  9418. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9419. cont();
  9420. };
  9421. return;
  9422. }
  9423. cont();
  9424. };
  9425. }
  9426. const finishPaintTask = async (error = null) => {
  9427. if (paintTask === this.paintTask) {
  9428. this.paintTask = null;
  9429. }
  9430. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  9431. this._renderError = null;
  9432. return;
  9433. }
  9434. this._renderError = error;
  9435. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9436. if (this.loadingIconDiv) {
  9437. div.removeChild(this.loadingIconDiv);
  9438. delete this.loadingIconDiv;
  9439. }
  9440. this._resetZoomLayer(true);
  9441. this.eventBus.dispatch("pagerendered", {
  9442. source: this,
  9443. pageNumber: this.id,
  9444. cssTransform: false,
  9445. timestamp: performance.now(),
  9446. error: this._renderError
  9447. });
  9448. if (error) {
  9449. throw error;
  9450. }
  9451. };
  9452. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  9453. paintTask.onRenderContinue = renderContinueCallback;
  9454. this.paintTask = paintTask;
  9455. const resultPromise = paintTask.promise.then(() => {
  9456. return finishPaintTask(null).then(() => {
  9457. if (textLayer) {
  9458. const readableStream = pdfPage.streamTextContent({
  9459. normalizeWhitespace: true,
  9460. includeMarkedContent: true
  9461. });
  9462. textLayer.setTextContentStream(readableStream);
  9463. textLayer.render();
  9464. }
  9465. });
  9466. }, function (reason) {
  9467. return finishPaintTask(reason);
  9468. });
  9469. if (this.annotationLayerFactory) {
  9470. if (!this.annotationLayer) {
  9471. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.renderInteractiveForms, this.l10n, null, null, null);
  9472. }
  9473. this._renderAnnotationLayer();
  9474. }
  9475. if (this.xfaLayerFactory) {
  9476. if (!this.xfaLayer) {
  9477. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage, null);
  9478. }
  9479. this._renderXfaLayer();
  9480. }
  9481. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  9482. this._onTextLayerRendered = event => {
  9483. if (event.pageNumber !== this.id) {
  9484. return;
  9485. }
  9486. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9487. this._onTextLayerRendered = null;
  9488. if (!this.canvas) {
  9489. return;
  9490. }
  9491. this.pdfPage.getStructTree().then(tree => {
  9492. if (!tree) {
  9493. return;
  9494. }
  9495. if (!this.canvas) {
  9496. return;
  9497. }
  9498. const treeDom = this.structTreeLayer.render(tree);
  9499. treeDom.classList.add("structTree");
  9500. this.canvas.appendChild(treeDom);
  9501. });
  9502. };
  9503. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  9504. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder(pdfPage);
  9505. }
  9506. div.setAttribute("data-loaded", true);
  9507. this.eventBus.dispatch("pagerender", {
  9508. source: this,
  9509. pageNumber: this.id
  9510. });
  9511. return resultPromise;
  9512. }
  9513. paintOnCanvas(canvasWrapper) {
  9514. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  9515. const result = {
  9516. promise: renderCapability.promise,
  9517. onRenderContinue(cont) {
  9518. cont();
  9519. },
  9520. cancel() {
  9521. renderTask.cancel();
  9522. }
  9523. };
  9524. const viewport = this.viewport;
  9525. const canvas = document.createElement("canvas");
  9526. canvas.hidden = true;
  9527. let isCanvasHidden = true;
  9528. const showCanvas = function () {
  9529. if (isCanvasHidden) {
  9530. canvas.hidden = false;
  9531. isCanvasHidden = false;
  9532. }
  9533. };
  9534. canvasWrapper.appendChild(canvas);
  9535. this.canvas = canvas;
  9536. canvas.mozOpaque = true;
  9537. const ctx = canvas.getContext("2d", {
  9538. alpha: false
  9539. });
  9540. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  9541. this.outputScale = outputScale;
  9542. if (this.useOnlyCssZoom) {
  9543. const actualSizeViewport = viewport.clone({
  9544. scale: _ui_utils.CSS_UNITS
  9545. });
  9546. outputScale.sx *= actualSizeViewport.width / viewport.width;
  9547. outputScale.sy *= actualSizeViewport.height / viewport.height;
  9548. outputScale.scaled = true;
  9549. }
  9550. if (this.maxCanvasPixels > 0) {
  9551. const pixelsInViewport = viewport.width * viewport.height;
  9552. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  9553. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  9554. outputScale.sx = maxScale;
  9555. outputScale.sy = maxScale;
  9556. outputScale.scaled = true;
  9557. this.hasRestrictedScaling = true;
  9558. } else {
  9559. this.hasRestrictedScaling = false;
  9560. }
  9561. }
  9562. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  9563. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  9564. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  9565. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  9566. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  9567. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  9568. this.paintedViewportMap.set(canvas, viewport);
  9569. const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  9570. const renderContext = {
  9571. canvasContext: ctx,
  9572. transform,
  9573. viewport: this.viewport,
  9574. renderInteractiveForms: this.renderInteractiveForms,
  9575. optionalContentConfigPromise: this._optionalContentConfigPromise
  9576. };
  9577. const renderTask = this.pdfPage.render(renderContext);
  9578. renderTask.onContinue = function (cont) {
  9579. showCanvas();
  9580. if (result.onRenderContinue) {
  9581. result.onRenderContinue(cont);
  9582. } else {
  9583. cont();
  9584. }
  9585. };
  9586. renderTask.promise.then(function () {
  9587. showCanvas();
  9588. renderCapability.resolve(undefined);
  9589. }, function (error) {
  9590. showCanvas();
  9591. renderCapability.reject(error);
  9592. });
  9593. return result;
  9594. }
  9595. paintOnSvg(wrapper) {
  9596. let cancelled = false;
  9597. const ensureNotCancelled = () => {
  9598. if (cancelled) {
  9599. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  9600. }
  9601. };
  9602. const pdfPage = this.pdfPage;
  9603. const actualSizeViewport = this.viewport.clone({
  9604. scale: _ui_utils.CSS_UNITS
  9605. });
  9606. const promise = pdfPage.getOperatorList().then(opList => {
  9607. ensureNotCancelled();
  9608. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  9609. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  9610. ensureNotCancelled();
  9611. this.svg = svg;
  9612. this.paintedViewportMap.set(svg, actualSizeViewport);
  9613. svg.style.width = wrapper.style.width;
  9614. svg.style.height = wrapper.style.height;
  9615. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9616. wrapper.appendChild(svg);
  9617. });
  9618. });
  9619. return {
  9620. promise,
  9621. onRenderContinue(cont) {
  9622. cont();
  9623. },
  9624. cancel() {
  9625. cancelled = true;
  9626. }
  9627. };
  9628. }
  9629. setPageLabel(label) {
  9630. this.pageLabel = typeof label === "string" ? label : null;
  9631. if (this.pageLabel !== null) {
  9632. this.div.setAttribute("data-page-label", this.pageLabel);
  9633. } else {
  9634. this.div.removeAttribute("data-page-label");
  9635. }
  9636. }
  9637. }
  9638. exports.PDFPageView = PDFPageView;
  9639. /***/ }),
  9640. /* 32 */
  9641. /***/ ((__unused_webpack_module, exports) => {
  9642. Object.defineProperty(exports, "__esModule", ({
  9643. value: true
  9644. }));
  9645. exports.StructTreeLayerBuilder = exports.DefaultStructTreeLayerFactory = void 0;
  9646. const PDF_ROLE_TO_HTML_ROLE = {
  9647. Document: null,
  9648. DocumentFragment: null,
  9649. Part: "group",
  9650. Sect: "group",
  9651. Div: "group",
  9652. Aside: "note",
  9653. NonStruct: "none",
  9654. P: null,
  9655. H: "heading",
  9656. Title: null,
  9657. FENote: "note",
  9658. Sub: "group",
  9659. Lbl: null,
  9660. Span: null,
  9661. Em: null,
  9662. Strong: null,
  9663. Link: "link",
  9664. Annot: "note",
  9665. Form: "form",
  9666. Ruby: null,
  9667. RB: null,
  9668. RT: null,
  9669. RP: null,
  9670. Warichu: null,
  9671. WT: null,
  9672. WP: null,
  9673. L: "list",
  9674. LI: "listitem",
  9675. LBody: null,
  9676. Table: "table",
  9677. TR: "row",
  9678. TH: "columnheader",
  9679. TD: "cell",
  9680. THead: "columnheader",
  9681. TBody: null,
  9682. TFoot: null,
  9683. Caption: null,
  9684. Figure: "figure",
  9685. Formula: null,
  9686. Artifact: null
  9687. };
  9688. const HEADING_PATTERN = /^H(\d+)$/;
  9689. class StructTreeLayerBuilder {
  9690. constructor({
  9691. pdfPage
  9692. }) {
  9693. this.pdfPage = pdfPage;
  9694. }
  9695. render(structTree) {
  9696. return this._walk(structTree);
  9697. }
  9698. _setAttributes(structElement, htmlElement) {
  9699. if (structElement.alt !== undefined) {
  9700. htmlElement.setAttribute("aria-label", structElement.alt);
  9701. }
  9702. if (structElement.id !== undefined) {
  9703. htmlElement.setAttribute("aria-owns", structElement.id);
  9704. }
  9705. }
  9706. _walk(node) {
  9707. if (!node) {
  9708. return null;
  9709. }
  9710. const element = document.createElement("span");
  9711. if ("role" in node) {
  9712. const {
  9713. role
  9714. } = node;
  9715. const match = role.match(HEADING_PATTERN);
  9716. if (match) {
  9717. element.setAttribute("role", "heading");
  9718. element.setAttribute("aria-level", match[1]);
  9719. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  9720. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  9721. }
  9722. }
  9723. this._setAttributes(node, element);
  9724. if (node.children) {
  9725. if (node.children.length === 1 && "id" in node.children[0]) {
  9726. this._setAttributes(node.children[0], element);
  9727. } else {
  9728. for (const kid of node.children) {
  9729. element.appendChild(this._walk(kid));
  9730. }
  9731. }
  9732. }
  9733. return element;
  9734. }
  9735. }
  9736. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  9737. class DefaultStructTreeLayerFactory {
  9738. createStructTreeLayerBuilder(pdfPage) {
  9739. return new StructTreeLayerBuilder({
  9740. pdfPage
  9741. });
  9742. }
  9743. }
  9744. exports.DefaultStructTreeLayerFactory = DefaultStructTreeLayerFactory;
  9745. /***/ }),
  9746. /* 33 */
  9747. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9748. Object.defineProperty(exports, "__esModule", ({
  9749. value: true
  9750. }));
  9751. exports.TextLayerBuilder = exports.DefaultTextLayerFactory = void 0;
  9752. var _pdfjsLib = __webpack_require__(5);
  9753. const EXPAND_DIVS_TIMEOUT = 300;
  9754. class TextLayerBuilder {
  9755. constructor({
  9756. textLayerDiv,
  9757. eventBus,
  9758. pageIndex,
  9759. viewport,
  9760. findController = null,
  9761. enhanceTextSelection = false
  9762. }) {
  9763. this.textLayerDiv = textLayerDiv;
  9764. this.eventBus = eventBus;
  9765. this.textContent = null;
  9766. this.textContentItemsStr = [];
  9767. this.textContentStream = null;
  9768. this.renderingDone = false;
  9769. this.pageIdx = pageIndex;
  9770. this.pageNumber = this.pageIdx + 1;
  9771. this.matches = [];
  9772. this.viewport = viewport;
  9773. this.textDivs = [];
  9774. this.findController = findController;
  9775. this.textLayerRenderTask = null;
  9776. this.enhanceTextSelection = enhanceTextSelection;
  9777. this._onUpdateTextLayerMatches = null;
  9778. this._bindMouse();
  9779. }
  9780. _finishRendering() {
  9781. this.renderingDone = true;
  9782. if (!this.enhanceTextSelection) {
  9783. const endOfContent = document.createElement("div");
  9784. endOfContent.className = "endOfContent";
  9785. this.textLayerDiv.appendChild(endOfContent);
  9786. }
  9787. this.eventBus.dispatch("textlayerrendered", {
  9788. source: this,
  9789. pageNumber: this.pageNumber,
  9790. numTextDivs: this.textDivs.length
  9791. });
  9792. }
  9793. render(timeout = 0) {
  9794. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  9795. return;
  9796. }
  9797. this.cancel();
  9798. this.textDivs = [];
  9799. const textLayerFrag = document.createDocumentFragment();
  9800. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  9801. textContent: this.textContent,
  9802. textContentStream: this.textContentStream,
  9803. container: textLayerFrag,
  9804. viewport: this.viewport,
  9805. textDivs: this.textDivs,
  9806. textContentItemsStr: this.textContentItemsStr,
  9807. timeout,
  9808. enhanceTextSelection: this.enhanceTextSelection
  9809. });
  9810. this.textLayerRenderTask.promise.then(() => {
  9811. this.textLayerDiv.appendChild(textLayerFrag);
  9812. this._finishRendering();
  9813. this._updateMatches();
  9814. }, function (reason) {});
  9815. if (!this._onUpdateTextLayerMatches) {
  9816. this._onUpdateTextLayerMatches = evt => {
  9817. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  9818. this._updateMatches();
  9819. }
  9820. };
  9821. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  9822. }
  9823. }
  9824. cancel() {
  9825. if (this.textLayerRenderTask) {
  9826. this.textLayerRenderTask.cancel();
  9827. this.textLayerRenderTask = null;
  9828. }
  9829. if (this._onUpdateTextLayerMatches) {
  9830. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  9831. this._onUpdateTextLayerMatches = null;
  9832. }
  9833. }
  9834. setTextContentStream(readableStream) {
  9835. this.cancel();
  9836. this.textContentStream = readableStream;
  9837. }
  9838. setTextContent(textContent) {
  9839. this.cancel();
  9840. this.textContent = textContent;
  9841. }
  9842. _convertMatches(matches, matchesLength) {
  9843. if (!matches) {
  9844. return [];
  9845. }
  9846. const {
  9847. textContentItemsStr
  9848. } = this;
  9849. let i = 0,
  9850. iIndex = 0;
  9851. const end = textContentItemsStr.length - 1;
  9852. const result = [];
  9853. for (let m = 0, mm = matches.length; m < mm; m++) {
  9854. let matchIdx = matches[m];
  9855. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  9856. iIndex += textContentItemsStr[i].length;
  9857. i++;
  9858. }
  9859. if (i === textContentItemsStr.length) {
  9860. console.error("Could not find a matching mapping");
  9861. }
  9862. const match = {
  9863. begin: {
  9864. divIdx: i,
  9865. offset: matchIdx - iIndex
  9866. }
  9867. };
  9868. matchIdx += matchesLength[m];
  9869. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  9870. iIndex += textContentItemsStr[i].length;
  9871. i++;
  9872. }
  9873. match.end = {
  9874. divIdx: i,
  9875. offset: matchIdx - iIndex
  9876. };
  9877. result.push(match);
  9878. }
  9879. return result;
  9880. }
  9881. _renderMatches(matches) {
  9882. if (matches.length === 0) {
  9883. return;
  9884. }
  9885. const {
  9886. findController,
  9887. pageIdx,
  9888. textContentItemsStr,
  9889. textDivs
  9890. } = this;
  9891. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  9892. const selectedMatchIdx = findController.selected.matchIdx;
  9893. const highlightAll = findController.state.highlightAll;
  9894. let prevEnd = null;
  9895. const infinity = {
  9896. divIdx: -1,
  9897. offset: undefined
  9898. };
  9899. function beginText(begin, className) {
  9900. const divIdx = begin.divIdx;
  9901. textDivs[divIdx].textContent = "";
  9902. appendTextToDiv(divIdx, 0, begin.offset, className);
  9903. }
  9904. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  9905. const div = textDivs[divIdx];
  9906. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  9907. const node = document.createTextNode(content);
  9908. if (className) {
  9909. const span = document.createElement("span");
  9910. span.className = className;
  9911. span.appendChild(node);
  9912. div.appendChild(span);
  9913. return;
  9914. }
  9915. div.appendChild(node);
  9916. }
  9917. let i0 = selectedMatchIdx,
  9918. i1 = i0 + 1;
  9919. if (highlightAll) {
  9920. i0 = 0;
  9921. i1 = matches.length;
  9922. } else if (!isSelectedPage) {
  9923. return;
  9924. }
  9925. for (let i = i0; i < i1; i++) {
  9926. const match = matches[i];
  9927. const begin = match.begin;
  9928. const end = match.end;
  9929. const isSelected = isSelectedPage && i === selectedMatchIdx;
  9930. const highlightSuffix = isSelected ? " selected" : "";
  9931. if (isSelected) {
  9932. findController.scrollMatchIntoView({
  9933. element: textDivs[begin.divIdx],
  9934. pageIndex: pageIdx,
  9935. matchIndex: selectedMatchIdx
  9936. });
  9937. }
  9938. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  9939. if (prevEnd !== null) {
  9940. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  9941. }
  9942. beginText(begin);
  9943. } else {
  9944. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  9945. }
  9946. if (begin.divIdx === end.divIdx) {
  9947. appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  9948. } else {
  9949. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  9950. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  9951. textDivs[n0].className = "highlight middle" + highlightSuffix;
  9952. }
  9953. beginText(end, "highlight end" + highlightSuffix);
  9954. }
  9955. prevEnd = end;
  9956. }
  9957. if (prevEnd) {
  9958. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  9959. }
  9960. }
  9961. _updateMatches() {
  9962. if (!this.renderingDone) {
  9963. return;
  9964. }
  9965. const {
  9966. findController,
  9967. matches,
  9968. pageIdx,
  9969. textContentItemsStr,
  9970. textDivs
  9971. } = this;
  9972. let clearedUntilDivIdx = -1;
  9973. for (let i = 0, ii = matches.length; i < ii; i++) {
  9974. const match = matches[i];
  9975. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  9976. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  9977. const div = textDivs[n];
  9978. div.textContent = textContentItemsStr[n];
  9979. div.className = "";
  9980. }
  9981. clearedUntilDivIdx = match.end.divIdx + 1;
  9982. }
  9983. if (!findController?.highlightMatches) {
  9984. return;
  9985. }
  9986. const pageMatches = findController.pageMatches[pageIdx] || null;
  9987. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  9988. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  9989. this._renderMatches(this.matches);
  9990. }
  9991. _bindMouse() {
  9992. const div = this.textLayerDiv;
  9993. let expandDivsTimer = null;
  9994. div.addEventListener("mousedown", evt => {
  9995. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  9996. this.textLayerRenderTask.expandTextDivs(true);
  9997. if (expandDivsTimer) {
  9998. clearTimeout(expandDivsTimer);
  9999. expandDivsTimer = null;
  10000. }
  10001. return;
  10002. }
  10003. const end = div.querySelector(".endOfContent");
  10004. if (!end) {
  10005. return;
  10006. }
  10007. let adjustTop = evt.target !== div;
  10008. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  10009. if (adjustTop) {
  10010. const divBounds = div.getBoundingClientRect();
  10011. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  10012. end.style.top = (r * 100).toFixed(2) + "%";
  10013. }
  10014. end.classList.add("active");
  10015. });
  10016. div.addEventListener("mouseup", () => {
  10017. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10018. expandDivsTimer = setTimeout(() => {
  10019. if (this.textLayerRenderTask) {
  10020. this.textLayerRenderTask.expandTextDivs(false);
  10021. }
  10022. expandDivsTimer = null;
  10023. }, EXPAND_DIVS_TIMEOUT);
  10024. return;
  10025. }
  10026. const end = div.querySelector(".endOfContent");
  10027. if (!end) {
  10028. return;
  10029. }
  10030. end.style.top = "";
  10031. end.classList.remove("active");
  10032. });
  10033. }
  10034. }
  10035. exports.TextLayerBuilder = TextLayerBuilder;
  10036. class DefaultTextLayerFactory {
  10037. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  10038. return new TextLayerBuilder({
  10039. textLayerDiv,
  10040. pageIndex,
  10041. viewport,
  10042. enhanceTextSelection,
  10043. eventBus
  10044. });
  10045. }
  10046. }
  10047. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  10048. /***/ }),
  10049. /* 34 */
  10050. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10051. Object.defineProperty(exports, "__esModule", ({
  10052. value: true
  10053. }));
  10054. exports.XfaLayerBuilder = exports.DefaultXfaLayerFactory = void 0;
  10055. var _pdfjsLib = __webpack_require__(5);
  10056. class XfaLayerBuilder {
  10057. constructor({
  10058. pageDiv,
  10059. pdfPage,
  10060. annotationStorage
  10061. }) {
  10062. this.pageDiv = pageDiv;
  10063. this.pdfPage = pdfPage;
  10064. this.annotationStorage = annotationStorage;
  10065. this.div = null;
  10066. this._cancelled = false;
  10067. }
  10068. render(viewport, intent = "display") {
  10069. return this.pdfPage.getXfa().then(xfa => {
  10070. if (this._cancelled) {
  10071. return;
  10072. }
  10073. const parameters = {
  10074. viewport: viewport.clone({
  10075. dontFlip: true
  10076. }),
  10077. div: this.div,
  10078. xfa,
  10079. page: this.pdfPage,
  10080. annotationStorage: this.annotationStorage
  10081. };
  10082. if (this.div) {
  10083. _pdfjsLib.XfaLayer.update(parameters);
  10084. } else {
  10085. this.div = document.createElement("div");
  10086. this.pageDiv.appendChild(this.div);
  10087. parameters.div = this.div;
  10088. _pdfjsLib.XfaLayer.render(parameters);
  10089. }
  10090. }).catch(error => {
  10091. console.error(error);
  10092. });
  10093. }
  10094. cancel() {
  10095. this._cancelled = true;
  10096. }
  10097. hide() {
  10098. if (!this.div) {
  10099. return;
  10100. }
  10101. this.div.hidden = true;
  10102. }
  10103. }
  10104. exports.XfaLayerBuilder = XfaLayerBuilder;
  10105. class DefaultXfaLayerFactory {
  10106. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null) {
  10107. return new XfaLayerBuilder({
  10108. pageDiv,
  10109. pdfPage,
  10110. annotationStorage
  10111. });
  10112. }
  10113. }
  10114. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;
  10115. /***/ }),
  10116. /* 35 */
  10117. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10118. Object.defineProperty(exports, "__esModule", ({
  10119. value: true
  10120. }));
  10121. exports.SecondaryToolbar = void 0;
  10122. var _ui_utils = __webpack_require__(4);
  10123. var _pdf_cursor_tools = __webpack_require__(6);
  10124. var _pdf_single_page_viewer = __webpack_require__(36);
  10125. class SecondaryToolbar {
  10126. constructor(options, mainContainer, eventBus) {
  10127. this.toolbar = options.toolbar;
  10128. this.toggleButton = options.toggleButton;
  10129. this.toolbarButtonContainer = options.toolbarButtonContainer;
  10130. this.buttons = [{
  10131. element: options.presentationModeButton,
  10132. eventName: "presentationmode",
  10133. close: true
  10134. }, {
  10135. element: options.openFileButton,
  10136. eventName: "openfile",
  10137. close: true
  10138. }, {
  10139. element: options.printButton,
  10140. eventName: "print",
  10141. close: true
  10142. }, {
  10143. element: options.downloadButton,
  10144. eventName: "download",
  10145. close: true
  10146. }, {
  10147. element: options.viewBookmarkButton,
  10148. eventName: null,
  10149. close: true
  10150. }, {
  10151. element: options.firstPageButton,
  10152. eventName: "firstpage",
  10153. close: true
  10154. }, {
  10155. element: options.lastPageButton,
  10156. eventName: "lastpage",
  10157. close: true
  10158. }, {
  10159. element: options.pageRotateCwButton,
  10160. eventName: "rotatecw",
  10161. close: false
  10162. }, {
  10163. element: options.pageRotateCcwButton,
  10164. eventName: "rotateccw",
  10165. close: false
  10166. }, {
  10167. element: options.cursorSelectToolButton,
  10168. eventName: "switchcursortool",
  10169. eventDetails: {
  10170. tool: _pdf_cursor_tools.CursorTool.SELECT
  10171. },
  10172. close: true
  10173. }, {
  10174. element: options.cursorHandToolButton,
  10175. eventName: "switchcursortool",
  10176. eventDetails: {
  10177. tool: _pdf_cursor_tools.CursorTool.HAND
  10178. },
  10179. close: true
  10180. }, {
  10181. element: options.scrollVerticalButton,
  10182. eventName: "switchscrollmode",
  10183. eventDetails: {
  10184. mode: _ui_utils.ScrollMode.VERTICAL
  10185. },
  10186. close: true
  10187. }, {
  10188. element: options.scrollHorizontalButton,
  10189. eventName: "switchscrollmode",
  10190. eventDetails: {
  10191. mode: _ui_utils.ScrollMode.HORIZONTAL
  10192. },
  10193. close: true
  10194. }, {
  10195. element: options.scrollWrappedButton,
  10196. eventName: "switchscrollmode",
  10197. eventDetails: {
  10198. mode: _ui_utils.ScrollMode.WRAPPED
  10199. },
  10200. close: true
  10201. }, {
  10202. element: options.spreadNoneButton,
  10203. eventName: "switchspreadmode",
  10204. eventDetails: {
  10205. mode: _ui_utils.SpreadMode.NONE
  10206. },
  10207. close: true
  10208. }, {
  10209. element: options.spreadOddButton,
  10210. eventName: "switchspreadmode",
  10211. eventDetails: {
  10212. mode: _ui_utils.SpreadMode.ODD
  10213. },
  10214. close: true
  10215. }, {
  10216. element: options.spreadEvenButton,
  10217. eventName: "switchspreadmode",
  10218. eventDetails: {
  10219. mode: _ui_utils.SpreadMode.EVEN
  10220. },
  10221. close: true
  10222. }, {
  10223. element: options.documentPropertiesButton,
  10224. eventName: "documentproperties",
  10225. close: true
  10226. }];
  10227. this.items = {
  10228. firstPage: options.firstPageButton,
  10229. lastPage: options.lastPageButton,
  10230. pageRotateCw: options.pageRotateCwButton,
  10231. pageRotateCcw: options.pageRotateCcwButton
  10232. };
  10233. this.mainContainer = mainContainer;
  10234. this.eventBus = eventBus;
  10235. this.opened = false;
  10236. this.containerHeight = null;
  10237. this.previousContainerHeight = null;
  10238. this.reset();
  10239. this._bindClickListeners();
  10240. this._bindCursorToolsListener(options);
  10241. this._bindScrollModeListener(options);
  10242. this._bindSpreadModeListener(options);
  10243. this.eventBus._on("resize", this._setMaxHeight.bind(this));
  10244. this.eventBus._on("baseviewerinit", evt => {
  10245. if (evt.source instanceof _pdf_single_page_viewer.PDFSinglePageViewer) {
  10246. this.toolbarButtonContainer.classList.add("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  10247. } else {
  10248. this.toolbarButtonContainer.classList.remove("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  10249. }
  10250. });
  10251. }
  10252. get isOpen() {
  10253. return this.opened;
  10254. }
  10255. setPageNumber(pageNumber) {
  10256. this.pageNumber = pageNumber;
  10257. this._updateUIState();
  10258. }
  10259. setPagesCount(pagesCount) {
  10260. this.pagesCount = pagesCount;
  10261. this._updateUIState();
  10262. }
  10263. reset() {
  10264. this.pageNumber = 0;
  10265. this.pagesCount = 0;
  10266. this._updateUIState();
  10267. this.eventBus.dispatch("secondarytoolbarreset", {
  10268. source: this
  10269. });
  10270. }
  10271. _updateUIState() {
  10272. this.items.firstPage.disabled = this.pageNumber <= 1;
  10273. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  10274. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  10275. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  10276. }
  10277. _bindClickListeners() {
  10278. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  10279. for (const {
  10280. element,
  10281. eventName,
  10282. close,
  10283. eventDetails
  10284. } of this.buttons) {
  10285. element.addEventListener("click", evt => {
  10286. if (eventName !== null) {
  10287. const details = {
  10288. source: this
  10289. };
  10290. for (const property in eventDetails) {
  10291. details[property] = eventDetails[property];
  10292. }
  10293. this.eventBus.dispatch(eventName, details);
  10294. }
  10295. if (close) {
  10296. this.close();
  10297. }
  10298. });
  10299. }
  10300. }
  10301. _bindCursorToolsListener(buttons) {
  10302. this.eventBus._on("cursortoolchanged", function ({
  10303. tool
  10304. }) {
  10305. buttons.cursorSelectToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.SELECT);
  10306. buttons.cursorHandToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.HAND);
  10307. });
  10308. }
  10309. _bindScrollModeListener(buttons) {
  10310. function scrollModeChanged({
  10311. mode
  10312. }) {
  10313. buttons.scrollVerticalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.VERTICAL);
  10314. buttons.scrollHorizontalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.HORIZONTAL);
  10315. buttons.scrollWrappedButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.WRAPPED);
  10316. const isScrollModeHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  10317. buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
  10318. buttons.spreadOddButton.disabled = isScrollModeHorizontal;
  10319. buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
  10320. }
  10321. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  10322. this.eventBus._on("secondarytoolbarreset", evt => {
  10323. if (evt.source === this) {
  10324. scrollModeChanged({
  10325. mode: _ui_utils.ScrollMode.VERTICAL
  10326. });
  10327. }
  10328. });
  10329. }
  10330. _bindSpreadModeListener(buttons) {
  10331. function spreadModeChanged({
  10332. mode
  10333. }) {
  10334. buttons.spreadNoneButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.NONE);
  10335. buttons.spreadOddButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.ODD);
  10336. buttons.spreadEvenButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.EVEN);
  10337. }
  10338. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  10339. this.eventBus._on("secondarytoolbarreset", evt => {
  10340. if (evt.source === this) {
  10341. spreadModeChanged({
  10342. mode: _ui_utils.SpreadMode.NONE
  10343. });
  10344. }
  10345. });
  10346. }
  10347. open() {
  10348. if (this.opened) {
  10349. return;
  10350. }
  10351. this.opened = true;
  10352. this._setMaxHeight();
  10353. this.toggleButton.classList.add("toggled");
  10354. this.toggleButton.setAttribute("aria-expanded", "true");
  10355. this.toolbar.classList.remove("hidden");
  10356. }
  10357. close() {
  10358. if (!this.opened) {
  10359. return;
  10360. }
  10361. this.opened = false;
  10362. this.toolbar.classList.add("hidden");
  10363. this.toggleButton.classList.remove("toggled");
  10364. this.toggleButton.setAttribute("aria-expanded", "false");
  10365. }
  10366. toggle() {
  10367. if (this.opened) {
  10368. this.close();
  10369. } else {
  10370. this.open();
  10371. }
  10372. }
  10373. _setMaxHeight() {
  10374. if (!this.opened) {
  10375. return;
  10376. }
  10377. this.containerHeight = this.mainContainer.clientHeight;
  10378. if (this.containerHeight === this.previousContainerHeight) {
  10379. return;
  10380. }
  10381. this.toolbarButtonContainer.style.maxHeight = `${this.containerHeight - _ui_utils.SCROLLBAR_PADDING}px`;
  10382. this.previousContainerHeight = this.containerHeight;
  10383. }
  10384. }
  10385. exports.SecondaryToolbar = SecondaryToolbar;
  10386. /***/ }),
  10387. /* 36 */
  10388. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10389. Object.defineProperty(exports, "__esModule", ({
  10390. value: true
  10391. }));
  10392. exports.PDFSinglePageViewer = void 0;
  10393. var _base_viewer = __webpack_require__(28);
  10394. var _pdfjsLib = __webpack_require__(5);
  10395. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  10396. constructor(options) {
  10397. super(options);
  10398. this.eventBus._on("pagesinit", evt => {
  10399. this._ensurePageViewVisible();
  10400. });
  10401. }
  10402. get _viewerElement() {
  10403. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this._shadowViewer);
  10404. }
  10405. get _pageWidthScaleFactor() {
  10406. return 1;
  10407. }
  10408. _resetView() {
  10409. super._resetView();
  10410. this._previousPageNumber = 1;
  10411. this._shadowViewer = document.createDocumentFragment();
  10412. this._updateScrollDown = null;
  10413. }
  10414. _ensurePageViewVisible() {
  10415. const pageView = this._pages[this._currentPageNumber - 1];
  10416. const previousPageView = this._pages[this._previousPageNumber - 1];
  10417. const viewerNodes = this.viewer.childNodes;
  10418. switch (viewerNodes.length) {
  10419. case 0:
  10420. this.viewer.appendChild(pageView.div);
  10421. break;
  10422. case 1:
  10423. if (viewerNodes[0] !== previousPageView.div) {
  10424. throw new Error("_ensurePageViewVisible: Unexpected previously visible page.");
  10425. }
  10426. if (pageView === previousPageView) {
  10427. break;
  10428. }
  10429. this._shadowViewer.appendChild(previousPageView.div);
  10430. this.viewer.appendChild(pageView.div);
  10431. this.container.scrollTop = 0;
  10432. break;
  10433. default:
  10434. throw new Error("_ensurePageViewVisible: Only one page should be visible at a time.");
  10435. }
  10436. this._previousPageNumber = this._currentPageNumber;
  10437. }
  10438. _scrollUpdate() {
  10439. if (this._updateScrollDown) {
  10440. this._updateScrollDown();
  10441. }
  10442. super._scrollUpdate();
  10443. }
  10444. _scrollIntoView({
  10445. pageDiv,
  10446. pageSpot = null,
  10447. pageNumber = null
  10448. }) {
  10449. if (pageNumber) {
  10450. this._setCurrentPageNumber(pageNumber);
  10451. }
  10452. const scrolledDown = this._currentPageNumber >= this._previousPageNumber;
  10453. this._ensurePageViewVisible();
  10454. this.update();
  10455. super._scrollIntoView({
  10456. pageDiv,
  10457. pageSpot,
  10458. pageNumber
  10459. });
  10460. this._updateScrollDown = () => {
  10461. this.scroll.down = scrolledDown;
  10462. this._updateScrollDown = null;
  10463. };
  10464. }
  10465. _getVisiblePages() {
  10466. return this._getCurrentVisiblePage();
  10467. }
  10468. _updateHelper(visiblePages) {}
  10469. get _isScrollModeHorizontal() {
  10470. return (0, _pdfjsLib.shadow)(this, "_isScrollModeHorizontal", false);
  10471. }
  10472. _updateScrollMode() {}
  10473. _updateSpreadMode() {}
  10474. _getPageAdvance() {
  10475. return 1;
  10476. }
  10477. }
  10478. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  10479. /***/ }),
  10480. /* 37 */
  10481. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10482. Object.defineProperty(exports, "__esModule", ({
  10483. value: true
  10484. }));
  10485. exports.Toolbar = void 0;
  10486. var _ui_utils = __webpack_require__(4);
  10487. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  10488. const SCALE_SELECT_CONTAINER_WIDTH = 140;
  10489. const SCALE_SELECT_WIDTH = 162;
  10490. class Toolbar {
  10491. constructor(options, eventBus, l10n) {
  10492. this.toolbar = options.container;
  10493. this.eventBus = eventBus;
  10494. this.l10n = l10n;
  10495. this.buttons = [{
  10496. element: options.previous,
  10497. eventName: "previouspage"
  10498. }, {
  10499. element: options.next,
  10500. eventName: "nextpage"
  10501. }, {
  10502. element: options.zoomIn,
  10503. eventName: "zoomin"
  10504. }, {
  10505. element: options.zoomOut,
  10506. eventName: "zoomout"
  10507. }, {
  10508. element: options.openFile,
  10509. eventName: "openfile"
  10510. }, {
  10511. element: options.print,
  10512. eventName: "print"
  10513. }, {
  10514. element: options.presentationModeButton,
  10515. eventName: "presentationmode"
  10516. }, {
  10517. element: options.download,
  10518. eventName: "download"
  10519. }, {
  10520. element: options.viewBookmark,
  10521. eventName: null
  10522. }];
  10523. this.items = {
  10524. numPages: options.numPages,
  10525. pageNumber: options.pageNumber,
  10526. scaleSelectContainer: options.scaleSelectContainer,
  10527. scaleSelect: options.scaleSelect,
  10528. customScaleOption: options.customScaleOption,
  10529. previous: options.previous,
  10530. next: options.next,
  10531. zoomIn: options.zoomIn,
  10532. zoomOut: options.zoomOut
  10533. };
  10534. this._wasLocalized = false;
  10535. this.reset();
  10536. this._bindListeners();
  10537. }
  10538. setPageNumber(pageNumber, pageLabel) {
  10539. this.pageNumber = pageNumber;
  10540. this.pageLabel = pageLabel;
  10541. this._updateUIState(false);
  10542. }
  10543. setPagesCount(pagesCount, hasPageLabels) {
  10544. this.pagesCount = pagesCount;
  10545. this.hasPageLabels = hasPageLabels;
  10546. this._updateUIState(true);
  10547. }
  10548. setPageScale(pageScaleValue, pageScale) {
  10549. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  10550. this.pageScale = pageScale;
  10551. this._updateUIState(false);
  10552. }
  10553. reset() {
  10554. this.pageNumber = 0;
  10555. this.pageLabel = null;
  10556. this.hasPageLabels = false;
  10557. this.pagesCount = 0;
  10558. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  10559. this.pageScale = _ui_utils.DEFAULT_SCALE;
  10560. this._updateUIState(true);
  10561. this.updateLoadingIndicatorState();
  10562. }
  10563. _bindListeners() {
  10564. const {
  10565. pageNumber,
  10566. scaleSelect
  10567. } = this.items;
  10568. const self = this;
  10569. for (const {
  10570. element,
  10571. eventName
  10572. } of this.buttons) {
  10573. element.addEventListener("click", evt => {
  10574. if (eventName !== null) {
  10575. this.eventBus.dispatch(eventName, {
  10576. source: this
  10577. });
  10578. }
  10579. });
  10580. }
  10581. pageNumber.addEventListener("click", function () {
  10582. this.select();
  10583. });
  10584. pageNumber.addEventListener("change", function () {
  10585. self.eventBus.dispatch("pagenumberchanged", {
  10586. source: self,
  10587. value: this.value
  10588. });
  10589. });
  10590. scaleSelect.addEventListener("change", function () {
  10591. if (this.value === "custom") {
  10592. return;
  10593. }
  10594. self.eventBus.dispatch("scalechanged", {
  10595. source: self,
  10596. value: this.value
  10597. });
  10598. });
  10599. scaleSelect.addEventListener("click", function (evt) {
  10600. const target = evt.target;
  10601. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  10602. this.blur();
  10603. }
  10604. });
  10605. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  10606. this.eventBus._on("localized", () => {
  10607. this._wasLocalized = true;
  10608. this._adjustScaleWidth();
  10609. this._updateUIState(true);
  10610. });
  10611. }
  10612. _updateUIState(resetNumPages = false) {
  10613. if (!this._wasLocalized) {
  10614. return;
  10615. }
  10616. const {
  10617. pageNumber,
  10618. pagesCount,
  10619. pageScaleValue,
  10620. pageScale,
  10621. items
  10622. } = this;
  10623. if (resetNumPages) {
  10624. if (this.hasPageLabels) {
  10625. items.pageNumber.type = "text";
  10626. } else {
  10627. items.pageNumber.type = "number";
  10628. this.l10n.get("of_pages", {
  10629. pagesCount
  10630. }).then(msg => {
  10631. items.numPages.textContent = msg;
  10632. });
  10633. }
  10634. items.pageNumber.max = pagesCount;
  10635. }
  10636. if (this.hasPageLabels) {
  10637. items.pageNumber.value = this.pageLabel;
  10638. this.l10n.get("page_of_pages", {
  10639. pageNumber,
  10640. pagesCount
  10641. }).then(msg => {
  10642. items.numPages.textContent = msg;
  10643. });
  10644. } else {
  10645. items.pageNumber.value = pageNumber;
  10646. }
  10647. items.previous.disabled = pageNumber <= 1;
  10648. items.next.disabled = pageNumber >= pagesCount;
  10649. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  10650. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  10651. this.l10n.get("page_scale_percent", {
  10652. scale: Math.round(pageScale * 10000) / 100
  10653. }).then(msg => {
  10654. let predefinedValueFound = false;
  10655. for (const option of items.scaleSelect.options) {
  10656. if (option.value !== pageScaleValue) {
  10657. option.selected = false;
  10658. continue;
  10659. }
  10660. option.selected = true;
  10661. predefinedValueFound = true;
  10662. }
  10663. if (!predefinedValueFound) {
  10664. items.customScaleOption.textContent = msg;
  10665. items.customScaleOption.selected = true;
  10666. }
  10667. });
  10668. }
  10669. updateLoadingIndicatorState(loading = false) {
  10670. const pageNumberInput = this.items.pageNumber;
  10671. pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  10672. }
  10673. async _adjustScaleWidth() {
  10674. const {
  10675. items,
  10676. l10n
  10677. } = this;
  10678. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  10679. let canvas = document.createElement("canvas");
  10680. canvas.mozOpaque = true;
  10681. let ctx = canvas.getContext("2d", {
  10682. alpha: false
  10683. });
  10684. await _ui_utils.animationStarted;
  10685. const {
  10686. fontSize,
  10687. fontFamily
  10688. } = getComputedStyle(items.scaleSelect);
  10689. ctx.font = `${fontSize} ${fontFamily}`;
  10690. let maxWidth = 0;
  10691. for (const predefinedValue of await predefinedValuesPromise) {
  10692. const {
  10693. width
  10694. } = ctx.measureText(predefinedValue);
  10695. if (width > maxWidth) {
  10696. maxWidth = width;
  10697. }
  10698. }
  10699. const overflow = SCALE_SELECT_WIDTH - SCALE_SELECT_CONTAINER_WIDTH;
  10700. maxWidth += 2 * overflow;
  10701. if (maxWidth > SCALE_SELECT_CONTAINER_WIDTH) {
  10702. items.scaleSelect.style.width = `${maxWidth + overflow}px`;
  10703. items.scaleSelectContainer.style.width = `${maxWidth}px`;
  10704. }
  10705. canvas.width = 0;
  10706. canvas.height = 0;
  10707. canvas = ctx = null;
  10708. }
  10709. }
  10710. exports.Toolbar = Toolbar;
  10711. /***/ }),
  10712. /* 38 */
  10713. /***/ ((__unused_webpack_module, exports) => {
  10714. Object.defineProperty(exports, "__esModule", ({
  10715. value: true
  10716. }));
  10717. exports.ViewHistory = void 0;
  10718. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  10719. class ViewHistory {
  10720. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  10721. this.fingerprint = fingerprint;
  10722. this.cacheSize = cacheSize;
  10723. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  10724. const database = JSON.parse(databaseStr || "{}");
  10725. let index = -1;
  10726. if (!Array.isArray(database.files)) {
  10727. database.files = [];
  10728. } else {
  10729. while (database.files.length >= this.cacheSize) {
  10730. database.files.shift();
  10731. }
  10732. for (let i = 0, ii = database.files.length; i < ii; i++) {
  10733. const branch = database.files[i];
  10734. if (branch.fingerprint === this.fingerprint) {
  10735. index = i;
  10736. break;
  10737. }
  10738. }
  10739. }
  10740. if (index === -1) {
  10741. index = database.files.push({
  10742. fingerprint: this.fingerprint
  10743. }) - 1;
  10744. }
  10745. this.file = database.files[index];
  10746. this.database = database;
  10747. });
  10748. }
  10749. async _writeToStorage() {
  10750. const databaseStr = JSON.stringify(this.database);
  10751. localStorage.setItem("pdfjs.history", databaseStr);
  10752. }
  10753. async _readFromStorage() {
  10754. return localStorage.getItem("pdfjs.history");
  10755. }
  10756. async set(name, val) {
  10757. await this._initializedPromise;
  10758. this.file[name] = val;
  10759. return this._writeToStorage();
  10760. }
  10761. async setMultiple(properties) {
  10762. await this._initializedPromise;
  10763. for (const name in properties) {
  10764. this.file[name] = properties[name];
  10765. }
  10766. return this._writeToStorage();
  10767. }
  10768. async get(name, defaultValue) {
  10769. await this._initializedPromise;
  10770. const val = this.file[name];
  10771. return val !== undefined ? val : defaultValue;
  10772. }
  10773. async getMultiple(properties) {
  10774. await this._initializedPromise;
  10775. const values = Object.create(null);
  10776. for (const name in properties) {
  10777. const val = this.file[name];
  10778. values[name] = val !== undefined ? val : properties[name];
  10779. }
  10780. return values;
  10781. }
  10782. }
  10783. exports.ViewHistory = ViewHistory;
  10784. /***/ }),
  10785. /* 39 */
  10786. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10787. Object.defineProperty(exports, "__esModule", ({
  10788. value: true
  10789. }));
  10790. exports.GenericCom = void 0;
  10791. var _app = __webpack_require__(3);
  10792. var _preferences = __webpack_require__(40);
  10793. var _download_manager = __webpack_require__(41);
  10794. var _genericl10n = __webpack_require__(42);
  10795. var _generic_scripting = __webpack_require__(44);
  10796. ;
  10797. const GenericCom = {};
  10798. exports.GenericCom = GenericCom;
  10799. class GenericPreferences extends _preferences.BasePreferences {
  10800. async _writeToStorage(prefObj) {
  10801. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  10802. }
  10803. async _readFromStorage(prefObj) {
  10804. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  10805. }
  10806. }
  10807. class GenericExternalServices extends _app.DefaultExternalServices {
  10808. static createDownloadManager(options) {
  10809. return new _download_manager.DownloadManager();
  10810. }
  10811. static createPreferences() {
  10812. return new GenericPreferences();
  10813. }
  10814. static createL10n({
  10815. locale = "en-US"
  10816. }) {
  10817. return new _genericl10n.GenericL10n(locale);
  10818. }
  10819. static createScripting({
  10820. sandboxBundleSrc
  10821. }) {
  10822. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  10823. }
  10824. }
  10825. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  10826. /***/ }),
  10827. /* 40 */
  10828. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10829. Object.defineProperty(exports, "__esModule", ({
  10830. value: true
  10831. }));
  10832. exports.BasePreferences = void 0;
  10833. var _app_options = __webpack_require__(1);
  10834. class BasePreferences {
  10835. constructor() {
  10836. if (this.constructor === BasePreferences) {
  10837. throw new Error("Cannot initialize BasePreferences.");
  10838. }
  10839. Object.defineProperty(this, "defaults", {
  10840. value: Object.freeze({
  10841. "cursorToolOnLoad": 0,
  10842. "defaultZoomValue": "",
  10843. "disablePageLabels": false,
  10844. "enablePermissions": false,
  10845. "enablePrintAutoRotate": true,
  10846. "enableScripting": true,
  10847. "externalLinkTarget": 0,
  10848. "historyUpdateUrl": false,
  10849. "ignoreDestinationZoom": false,
  10850. "pdfBugEnabled": false,
  10851. "renderer": "canvas",
  10852. "renderInteractiveForms": true,
  10853. "sidebarViewOnLoad": -1,
  10854. "scrollModeOnLoad": -1,
  10855. "spreadModeOnLoad": -1,
  10856. "textLayerMode": 1,
  10857. "useOnlyCssZoom": false,
  10858. "viewerCssTheme": 0,
  10859. "viewOnLoad": 0,
  10860. "disableAutoFetch": false,
  10861. "disableFontFace": false,
  10862. "disableRange": false,
  10863. "disableStream": false,
  10864. "enableXfa": false
  10865. }),
  10866. writable: false,
  10867. enumerable: true,
  10868. configurable: false
  10869. });
  10870. this.prefs = Object.create(null);
  10871. this._initializedPromise = this._readFromStorage(this.defaults).then(prefs => {
  10872. for (const name in this.defaults) {
  10873. const prefValue = prefs?.[name];
  10874. if (typeof prefValue === typeof this.defaults[name]) {
  10875. this.prefs[name] = prefValue;
  10876. }
  10877. }
  10878. });
  10879. }
  10880. async _writeToStorage(prefObj) {
  10881. throw new Error("Not implemented: _writeToStorage");
  10882. }
  10883. async _readFromStorage(prefObj) {
  10884. throw new Error("Not implemented: _readFromStorage");
  10885. }
  10886. async reset() {
  10887. await this._initializedPromise;
  10888. this.prefs = Object.create(null);
  10889. return this._writeToStorage(this.defaults);
  10890. }
  10891. async set(name, value) {
  10892. await this._initializedPromise;
  10893. const defaultValue = this.defaults[name];
  10894. if (defaultValue === undefined) {
  10895. throw new Error(`Set preference: "${name}" is undefined.`);
  10896. } else if (value === undefined) {
  10897. throw new Error("Set preference: no value is specified.");
  10898. }
  10899. const valueType = typeof value;
  10900. const defaultType = typeof defaultValue;
  10901. if (valueType !== defaultType) {
  10902. if (valueType === "number" && defaultType === "string") {
  10903. value = value.toString();
  10904. } else {
  10905. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  10906. }
  10907. } else {
  10908. if (valueType === "number" && !Number.isInteger(value)) {
  10909. throw new Error(`Set preference: "${value}" must be an integer.`);
  10910. }
  10911. }
  10912. this.prefs[name] = value;
  10913. return this._writeToStorage(this.prefs);
  10914. }
  10915. async get(name) {
  10916. await this._initializedPromise;
  10917. const defaultValue = this.defaults[name],
  10918. prefValue = this.prefs[name];
  10919. if (defaultValue === undefined) {
  10920. throw new Error(`Get preference: "${name}" is undefined.`);
  10921. }
  10922. return prefValue !== undefined ? prefValue : defaultValue;
  10923. }
  10924. async getAll() {
  10925. await this._initializedPromise;
  10926. const obj = Object.create(null);
  10927. for (const name in this.defaults) {
  10928. const prefValue = this.prefs[name];
  10929. obj[name] = prefValue !== undefined ? prefValue : this.defaults[name];
  10930. }
  10931. return obj;
  10932. }
  10933. }
  10934. exports.BasePreferences = BasePreferences;
  10935. /***/ }),
  10936. /* 41 */
  10937. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10938. Object.defineProperty(exports, "__esModule", ({
  10939. value: true
  10940. }));
  10941. exports.DownloadManager = void 0;
  10942. var _pdfjsLib = __webpack_require__(5);
  10943. var _viewer_compatibility = __webpack_require__(2);
  10944. ;
  10945. function download(blobUrl, filename) {
  10946. const a = document.createElement("a");
  10947. if (!a.click) {
  10948. throw new Error('DownloadManager: "a.click()" is not supported.');
  10949. }
  10950. a.href = blobUrl;
  10951. a.target = "_parent";
  10952. if ("download" in a) {
  10953. a.download = filename;
  10954. }
  10955. (document.body || document.documentElement).appendChild(a);
  10956. a.click();
  10957. a.remove();
  10958. }
  10959. class DownloadManager {
  10960. constructor() {
  10961. this._openBlobUrls = new WeakMap();
  10962. }
  10963. downloadUrl(url, filename) {
  10964. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  10965. return;
  10966. }
  10967. download(url + "#pdfjs.action=download", filename);
  10968. }
  10969. downloadData(data, filename, contentType) {
  10970. const blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  10971. download(blobUrl, filename);
  10972. }
  10973. openOrDownloadData(element, data, filename) {
  10974. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  10975. const contentType = isPdfData ? "application/pdf" : "";
  10976. if (isPdfData && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  10977. let blobUrl = this._openBlobUrls.get(element);
  10978. if (!blobUrl) {
  10979. blobUrl = URL.createObjectURL(new Blob([data], {
  10980. type: contentType
  10981. }));
  10982. this._openBlobUrls.set(element, blobUrl);
  10983. }
  10984. let viewerUrl;
  10985. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  10986. try {
  10987. window.open(viewerUrl);
  10988. return true;
  10989. } catch (ex) {
  10990. console.error(`openOrDownloadData: ${ex}`);
  10991. URL.revokeObjectURL(blobUrl);
  10992. this._openBlobUrls.delete(element);
  10993. }
  10994. }
  10995. this.downloadData(data, filename, contentType);
  10996. return false;
  10997. }
  10998. download(blob, url, filename, sourceEventType = "download") {
  10999. if (_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  11000. this.downloadUrl(url, filename);
  11001. return;
  11002. }
  11003. const blobUrl = URL.createObjectURL(blob);
  11004. download(blobUrl, filename);
  11005. }
  11006. }
  11007. exports.DownloadManager = DownloadManager;
  11008. /***/ }),
  11009. /* 42 */
  11010. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11011. Object.defineProperty(exports, "__esModule", ({
  11012. value: true
  11013. }));
  11014. exports.GenericL10n = void 0;
  11015. __webpack_require__(43);
  11016. var _l10n_utils = __webpack_require__(30);
  11017. const webL10n = document.webL10n;
  11018. class GenericL10n {
  11019. constructor(lang) {
  11020. this._lang = lang;
  11021. this._ready = new Promise((resolve, reject) => {
  11022. webL10n.setLanguage(lang, () => {
  11023. resolve(webL10n);
  11024. });
  11025. });
  11026. }
  11027. async getLanguage() {
  11028. const l10n = await this._ready;
  11029. return l10n.getLanguage();
  11030. }
  11031. async getDirection() {
  11032. const l10n = await this._ready;
  11033. return l10n.getDirection();
  11034. }
  11035. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  11036. const l10n = await this._ready;
  11037. return l10n.get(key, args, fallback);
  11038. }
  11039. async translate(element) {
  11040. const l10n = await this._ready;
  11041. return l10n.translate(element);
  11042. }
  11043. }
  11044. exports.GenericL10n = GenericL10n;
  11045. /***/ }),
  11046. /* 43 */
  11047. /***/ (() => {
  11048. document.webL10n = function (window, document, undefined) {
  11049. var gL10nData = {};
  11050. var gTextData = '';
  11051. var gTextProp = 'textContent';
  11052. var gLanguage = '';
  11053. var gMacros = {};
  11054. var gReadyState = 'loading';
  11055. var gAsyncResourceLoading = true;
  11056. function getL10nResourceLinks() {
  11057. return document.querySelectorAll('link[type="application/l10n"]');
  11058. }
  11059. function getL10nDictionary() {
  11060. var script = document.querySelector('script[type="application/l10n"]');
  11061. return script ? JSON.parse(script.innerHTML) : null;
  11062. }
  11063. function getTranslatableChildren(element) {
  11064. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  11065. }
  11066. function getL10nAttributes(element) {
  11067. if (!element) return {};
  11068. var l10nId = element.getAttribute('data-l10n-id');
  11069. var l10nArgs = element.getAttribute('data-l10n-args');
  11070. var args = {};
  11071. if (l10nArgs) {
  11072. try {
  11073. args = JSON.parse(l10nArgs);
  11074. } catch (e) {
  11075. console.warn('could not parse arguments for #' + l10nId);
  11076. }
  11077. }
  11078. return {
  11079. id: l10nId,
  11080. args: args
  11081. };
  11082. }
  11083. function xhrLoadText(url, onSuccess, onFailure) {
  11084. onSuccess = onSuccess || function _onSuccess(data) {};
  11085. onFailure = onFailure || function _onFailure() {};
  11086. var xhr = new XMLHttpRequest();
  11087. xhr.open('GET', url, gAsyncResourceLoading);
  11088. if (xhr.overrideMimeType) {
  11089. xhr.overrideMimeType('text/plain; charset=utf-8');
  11090. }
  11091. xhr.onreadystatechange = function () {
  11092. if (xhr.readyState == 4) {
  11093. if (xhr.status == 200 || xhr.status === 0) {
  11094. onSuccess(xhr.responseText);
  11095. } else {
  11096. onFailure();
  11097. }
  11098. }
  11099. };
  11100. xhr.onerror = onFailure;
  11101. xhr.ontimeout = onFailure;
  11102. try {
  11103. xhr.send(null);
  11104. } catch (e) {
  11105. onFailure();
  11106. }
  11107. }
  11108. function parseResource(href, lang, successCallback, failureCallback) {
  11109. var baseURL = href.replace(/[^\/]*$/, '') || './';
  11110. function evalString(text) {
  11111. if (text.lastIndexOf('\\') < 0) return text;
  11112. 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, "'");
  11113. }
  11114. function parseProperties(text, parsedPropertiesCallback) {
  11115. var dictionary = {};
  11116. var reBlank = /^\s*|\s*$/;
  11117. var reComment = /^\s*#|^\s*$/;
  11118. var reSection = /^\s*\[(.*)\]\s*$/;
  11119. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  11120. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  11121. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  11122. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  11123. var currentLang = '*';
  11124. var genericLang = lang.split('-', 1)[0];
  11125. var skipLang = false;
  11126. var match = '';
  11127. function nextEntry() {
  11128. while (true) {
  11129. if (!entries.length) {
  11130. parsedRawLinesCallback();
  11131. return;
  11132. }
  11133. var line = entries.shift();
  11134. if (reComment.test(line)) continue;
  11135. if (extendedSyntax) {
  11136. match = reSection.exec(line);
  11137. if (match) {
  11138. currentLang = match[1].toLowerCase();
  11139. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  11140. continue;
  11141. } else if (skipLang) {
  11142. continue;
  11143. }
  11144. match = reImport.exec(line);
  11145. if (match) {
  11146. loadImport(baseURL + match[1], nextEntry);
  11147. return;
  11148. }
  11149. }
  11150. var tmp = line.match(reSplit);
  11151. if (tmp && tmp.length == 3) {
  11152. dictionary[tmp[1]] = evalString(tmp[2]);
  11153. }
  11154. }
  11155. }
  11156. nextEntry();
  11157. }
  11158. function loadImport(url, callback) {
  11159. xhrLoadText(url, function (content) {
  11160. parseRawLines(content, false, callback);
  11161. }, function () {
  11162. console.warn(url + ' not found.');
  11163. callback();
  11164. });
  11165. }
  11166. parseRawLines(text, true, function () {
  11167. parsedPropertiesCallback(dictionary);
  11168. });
  11169. }
  11170. xhrLoadText(href, function (response) {
  11171. gTextData += response;
  11172. parseProperties(response, function (data) {
  11173. for (var key in data) {
  11174. var id,
  11175. prop,
  11176. index = key.lastIndexOf('.');
  11177. if (index > 0) {
  11178. id = key.substring(0, index);
  11179. prop = key.substring(index + 1);
  11180. } else {
  11181. id = key;
  11182. prop = gTextProp;
  11183. }
  11184. if (!gL10nData[id]) {
  11185. gL10nData[id] = {};
  11186. }
  11187. gL10nData[id][prop] = data[key];
  11188. }
  11189. if (successCallback) {
  11190. successCallback();
  11191. }
  11192. });
  11193. }, failureCallback);
  11194. }
  11195. function loadLocale(lang, callback) {
  11196. if (lang) {
  11197. lang = lang.toLowerCase();
  11198. }
  11199. callback = callback || function _callback() {};
  11200. clear();
  11201. gLanguage = lang;
  11202. var langLinks = getL10nResourceLinks();
  11203. var langCount = langLinks.length;
  11204. if (langCount === 0) {
  11205. var dict = getL10nDictionary();
  11206. if (dict && dict.locales && dict.default_locale) {
  11207. console.log('using the embedded JSON directory, early way out');
  11208. gL10nData = dict.locales[lang];
  11209. if (!gL10nData) {
  11210. var defaultLocale = dict.default_locale.toLowerCase();
  11211. for (var anyCaseLang in dict.locales) {
  11212. anyCaseLang = anyCaseLang.toLowerCase();
  11213. if (anyCaseLang === lang) {
  11214. gL10nData = dict.locales[lang];
  11215. break;
  11216. } else if (anyCaseLang === defaultLocale) {
  11217. gL10nData = dict.locales[defaultLocale];
  11218. }
  11219. }
  11220. }
  11221. callback();
  11222. } else {
  11223. console.log('no resource to load, early way out');
  11224. }
  11225. gReadyState = 'complete';
  11226. return;
  11227. }
  11228. var onResourceLoaded = null;
  11229. var gResourceCount = 0;
  11230. onResourceLoaded = function () {
  11231. gResourceCount++;
  11232. if (gResourceCount >= langCount) {
  11233. callback();
  11234. gReadyState = 'complete';
  11235. }
  11236. };
  11237. function L10nResourceLink(link) {
  11238. var href = link.href;
  11239. this.load = function (lang, callback) {
  11240. parseResource(href, lang, callback, function () {
  11241. console.warn(href + ' not found.');
  11242. console.warn('"' + lang + '" resource not found');
  11243. gLanguage = '';
  11244. callback();
  11245. });
  11246. };
  11247. }
  11248. for (var i = 0; i < langCount; i++) {
  11249. var resource = new L10nResourceLink(langLinks[i]);
  11250. resource.load(lang, onResourceLoaded);
  11251. }
  11252. }
  11253. function clear() {
  11254. gL10nData = {};
  11255. gTextData = '';
  11256. gLanguage = '';
  11257. }
  11258. function getPluralRules(lang) {
  11259. var locales2rules = {
  11260. 'af': 3,
  11261. 'ak': 4,
  11262. 'am': 4,
  11263. 'ar': 1,
  11264. 'asa': 3,
  11265. 'az': 0,
  11266. 'be': 11,
  11267. 'bem': 3,
  11268. 'bez': 3,
  11269. 'bg': 3,
  11270. 'bh': 4,
  11271. 'bm': 0,
  11272. 'bn': 3,
  11273. 'bo': 0,
  11274. 'br': 20,
  11275. 'brx': 3,
  11276. 'bs': 11,
  11277. 'ca': 3,
  11278. 'cgg': 3,
  11279. 'chr': 3,
  11280. 'cs': 12,
  11281. 'cy': 17,
  11282. 'da': 3,
  11283. 'de': 3,
  11284. 'dv': 3,
  11285. 'dz': 0,
  11286. 'ee': 3,
  11287. 'el': 3,
  11288. 'en': 3,
  11289. 'eo': 3,
  11290. 'es': 3,
  11291. 'et': 3,
  11292. 'eu': 3,
  11293. 'fa': 0,
  11294. 'ff': 5,
  11295. 'fi': 3,
  11296. 'fil': 4,
  11297. 'fo': 3,
  11298. 'fr': 5,
  11299. 'fur': 3,
  11300. 'fy': 3,
  11301. 'ga': 8,
  11302. 'gd': 24,
  11303. 'gl': 3,
  11304. 'gsw': 3,
  11305. 'gu': 3,
  11306. 'guw': 4,
  11307. 'gv': 23,
  11308. 'ha': 3,
  11309. 'haw': 3,
  11310. 'he': 2,
  11311. 'hi': 4,
  11312. 'hr': 11,
  11313. 'hu': 0,
  11314. 'id': 0,
  11315. 'ig': 0,
  11316. 'ii': 0,
  11317. 'is': 3,
  11318. 'it': 3,
  11319. 'iu': 7,
  11320. 'ja': 0,
  11321. 'jmc': 3,
  11322. 'jv': 0,
  11323. 'ka': 0,
  11324. 'kab': 5,
  11325. 'kaj': 3,
  11326. 'kcg': 3,
  11327. 'kde': 0,
  11328. 'kea': 0,
  11329. 'kk': 3,
  11330. 'kl': 3,
  11331. 'km': 0,
  11332. 'kn': 0,
  11333. 'ko': 0,
  11334. 'ksb': 3,
  11335. 'ksh': 21,
  11336. 'ku': 3,
  11337. 'kw': 7,
  11338. 'lag': 18,
  11339. 'lb': 3,
  11340. 'lg': 3,
  11341. 'ln': 4,
  11342. 'lo': 0,
  11343. 'lt': 10,
  11344. 'lv': 6,
  11345. 'mas': 3,
  11346. 'mg': 4,
  11347. 'mk': 16,
  11348. 'ml': 3,
  11349. 'mn': 3,
  11350. 'mo': 9,
  11351. 'mr': 3,
  11352. 'ms': 0,
  11353. 'mt': 15,
  11354. 'my': 0,
  11355. 'nah': 3,
  11356. 'naq': 7,
  11357. 'nb': 3,
  11358. 'nd': 3,
  11359. 'ne': 3,
  11360. 'nl': 3,
  11361. 'nn': 3,
  11362. 'no': 3,
  11363. 'nr': 3,
  11364. 'nso': 4,
  11365. 'ny': 3,
  11366. 'nyn': 3,
  11367. 'om': 3,
  11368. 'or': 3,
  11369. 'pa': 3,
  11370. 'pap': 3,
  11371. 'pl': 13,
  11372. 'ps': 3,
  11373. 'pt': 3,
  11374. 'rm': 3,
  11375. 'ro': 9,
  11376. 'rof': 3,
  11377. 'ru': 11,
  11378. 'rwk': 3,
  11379. 'sah': 0,
  11380. 'saq': 3,
  11381. 'se': 7,
  11382. 'seh': 3,
  11383. 'ses': 0,
  11384. 'sg': 0,
  11385. 'sh': 11,
  11386. 'shi': 19,
  11387. 'sk': 12,
  11388. 'sl': 14,
  11389. 'sma': 7,
  11390. 'smi': 7,
  11391. 'smj': 7,
  11392. 'smn': 7,
  11393. 'sms': 7,
  11394. 'sn': 3,
  11395. 'so': 3,
  11396. 'sq': 3,
  11397. 'sr': 11,
  11398. 'ss': 3,
  11399. 'ssy': 3,
  11400. 'st': 3,
  11401. 'sv': 3,
  11402. 'sw': 3,
  11403. 'syr': 3,
  11404. 'ta': 3,
  11405. 'te': 3,
  11406. 'teo': 3,
  11407. 'th': 0,
  11408. 'ti': 4,
  11409. 'tig': 3,
  11410. 'tk': 3,
  11411. 'tl': 4,
  11412. 'tn': 3,
  11413. 'to': 0,
  11414. 'tr': 0,
  11415. 'ts': 3,
  11416. 'tzm': 22,
  11417. 'uk': 11,
  11418. 'ur': 3,
  11419. 've': 3,
  11420. 'vi': 0,
  11421. 'vun': 3,
  11422. 'wa': 4,
  11423. 'wae': 3,
  11424. 'wo': 0,
  11425. 'xh': 3,
  11426. 'xog': 3,
  11427. 'yo': 0,
  11428. 'zh': 0,
  11429. 'zu': 3
  11430. };
  11431. function isIn(n, list) {
  11432. return list.indexOf(n) !== -1;
  11433. }
  11434. function isBetween(n, start, end) {
  11435. return start <= n && n <= end;
  11436. }
  11437. var pluralRules = {
  11438. '0': function (n) {
  11439. return 'other';
  11440. },
  11441. '1': function (n) {
  11442. if (isBetween(n % 100, 3, 10)) return 'few';
  11443. if (n === 0) return 'zero';
  11444. if (isBetween(n % 100, 11, 99)) return 'many';
  11445. if (n == 2) return 'two';
  11446. if (n == 1) return 'one';
  11447. return 'other';
  11448. },
  11449. '2': function (n) {
  11450. if (n !== 0 && n % 10 === 0) return 'many';
  11451. if (n == 2) return 'two';
  11452. if (n == 1) return 'one';
  11453. return 'other';
  11454. },
  11455. '3': function (n) {
  11456. if (n == 1) return 'one';
  11457. return 'other';
  11458. },
  11459. '4': function (n) {
  11460. if (isBetween(n, 0, 1)) return 'one';
  11461. return 'other';
  11462. },
  11463. '5': function (n) {
  11464. if (isBetween(n, 0, 2) && n != 2) return 'one';
  11465. return 'other';
  11466. },
  11467. '6': function (n) {
  11468. if (n === 0) return 'zero';
  11469. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11470. return 'other';
  11471. },
  11472. '7': function (n) {
  11473. if (n == 2) return 'two';
  11474. if (n == 1) return 'one';
  11475. return 'other';
  11476. },
  11477. '8': function (n) {
  11478. if (isBetween(n, 3, 6)) return 'few';
  11479. if (isBetween(n, 7, 10)) return 'many';
  11480. if (n == 2) return 'two';
  11481. if (n == 1) return 'one';
  11482. return 'other';
  11483. },
  11484. '9': function (n) {
  11485. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  11486. if (n == 1) return 'one';
  11487. return 'other';
  11488. },
  11489. '10': function (n) {
  11490. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  11491. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  11492. return 'other';
  11493. },
  11494. '11': function (n) {
  11495. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11496. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  11497. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11498. return 'other';
  11499. },
  11500. '12': function (n) {
  11501. if (isBetween(n, 2, 4)) return 'few';
  11502. if (n == 1) return 'one';
  11503. return 'other';
  11504. },
  11505. '13': function (n) {
  11506. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11507. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  11508. if (n == 1) return 'one';
  11509. return 'other';
  11510. },
  11511. '14': function (n) {
  11512. if (isBetween(n % 100, 3, 4)) return 'few';
  11513. if (n % 100 == 2) return 'two';
  11514. if (n % 100 == 1) return 'one';
  11515. return 'other';
  11516. },
  11517. '15': function (n) {
  11518. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  11519. if (isBetween(n % 100, 11, 19)) return 'many';
  11520. if (n == 1) return 'one';
  11521. return 'other';
  11522. },
  11523. '16': function (n) {
  11524. if (n % 10 == 1 && n != 11) return 'one';
  11525. return 'other';
  11526. },
  11527. '17': function (n) {
  11528. if (n == 3) return 'few';
  11529. if (n === 0) return 'zero';
  11530. if (n == 6) return 'many';
  11531. if (n == 2) return 'two';
  11532. if (n == 1) return 'one';
  11533. return 'other';
  11534. },
  11535. '18': function (n) {
  11536. if (n === 0) return 'zero';
  11537. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  11538. return 'other';
  11539. },
  11540. '19': function (n) {
  11541. if (isBetween(n, 2, 10)) return 'few';
  11542. if (isBetween(n, 0, 1)) return 'one';
  11543. return 'other';
  11544. },
  11545. '20': function (n) {
  11546. 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';
  11547. if (n % 1000000 === 0 && n !== 0) return 'many';
  11548. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  11549. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  11550. return 'other';
  11551. },
  11552. '21': function (n) {
  11553. if (n === 0) return 'zero';
  11554. if (n == 1) return 'one';
  11555. return 'other';
  11556. },
  11557. '22': function (n) {
  11558. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  11559. return 'other';
  11560. },
  11561. '23': function (n) {
  11562. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  11563. return 'other';
  11564. },
  11565. '24': function (n) {
  11566. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  11567. if (isIn(n, [2, 12])) return 'two';
  11568. if (isIn(n, [1, 11])) return 'one';
  11569. return 'other';
  11570. }
  11571. };
  11572. var index = locales2rules[lang.replace(/-.*$/, '')];
  11573. if (!(index in pluralRules)) {
  11574. console.warn('plural form unknown for [' + lang + ']');
  11575. return function () {
  11576. return 'other';
  11577. };
  11578. }
  11579. return pluralRules[index];
  11580. }
  11581. gMacros.plural = function (str, param, key, prop) {
  11582. var n = parseFloat(param);
  11583. if (isNaN(n)) return str;
  11584. if (prop != gTextProp) return str;
  11585. if (!gMacros._pluralRules) {
  11586. gMacros._pluralRules = getPluralRules(gLanguage);
  11587. }
  11588. var index = '[' + gMacros._pluralRules(n) + ']';
  11589. if (n === 0 && key + '[zero]' in gL10nData) {
  11590. str = gL10nData[key + '[zero]'][prop];
  11591. } else if (n == 1 && key + '[one]' in gL10nData) {
  11592. str = gL10nData[key + '[one]'][prop];
  11593. } else if (n == 2 && key + '[two]' in gL10nData) {
  11594. str = gL10nData[key + '[two]'][prop];
  11595. } else if (key + index in gL10nData) {
  11596. str = gL10nData[key + index][prop];
  11597. } else if (key + '[other]' in gL10nData) {
  11598. str = gL10nData[key + '[other]'][prop];
  11599. }
  11600. return str;
  11601. };
  11602. function getL10nData(key, args, fallback) {
  11603. var data = gL10nData[key];
  11604. if (!data) {
  11605. console.warn('#' + key + ' is undefined.');
  11606. if (!fallback) {
  11607. return null;
  11608. }
  11609. data = fallback;
  11610. }
  11611. var rv = {};
  11612. for (var prop in data) {
  11613. var str = data[prop];
  11614. str = substIndexes(str, args, key, prop);
  11615. str = substArguments(str, args, key);
  11616. rv[prop] = str;
  11617. }
  11618. return rv;
  11619. }
  11620. function substIndexes(str, args, key, prop) {
  11621. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  11622. var reMatch = reIndex.exec(str);
  11623. if (!reMatch || !reMatch.length) return str;
  11624. var macroName = reMatch[1];
  11625. var paramName = reMatch[2];
  11626. var param;
  11627. if (args && paramName in args) {
  11628. param = args[paramName];
  11629. } else if (paramName in gL10nData) {
  11630. param = gL10nData[paramName];
  11631. }
  11632. if (macroName in gMacros) {
  11633. var macro = gMacros[macroName];
  11634. str = macro(str, param, key, prop);
  11635. }
  11636. return str;
  11637. }
  11638. function substArguments(str, args, key) {
  11639. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  11640. return str.replace(reArgs, function (matched_text, arg) {
  11641. if (args && arg in args) {
  11642. return args[arg];
  11643. }
  11644. if (arg in gL10nData) {
  11645. return gL10nData[arg];
  11646. }
  11647. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  11648. return matched_text;
  11649. });
  11650. }
  11651. function translateElement(element) {
  11652. var l10n = getL10nAttributes(element);
  11653. if (!l10n.id) return;
  11654. var data = getL10nData(l10n.id, l10n.args);
  11655. if (!data) {
  11656. console.warn('#' + l10n.id + ' is undefined.');
  11657. return;
  11658. }
  11659. if (data[gTextProp]) {
  11660. if (getChildElementCount(element) === 0) {
  11661. element[gTextProp] = data[gTextProp];
  11662. } else {
  11663. var children = element.childNodes;
  11664. var found = false;
  11665. for (var i = 0, l = children.length; i < l; i++) {
  11666. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  11667. if (found) {
  11668. children[i].nodeValue = '';
  11669. } else {
  11670. children[i].nodeValue = data[gTextProp];
  11671. found = true;
  11672. }
  11673. }
  11674. }
  11675. if (!found) {
  11676. var textNode = document.createTextNode(data[gTextProp]);
  11677. element.insertBefore(textNode, element.firstChild);
  11678. }
  11679. }
  11680. delete data[gTextProp];
  11681. }
  11682. for (var k in data) {
  11683. element[k] = data[k];
  11684. }
  11685. }
  11686. function getChildElementCount(element) {
  11687. if (element.children) {
  11688. return element.children.length;
  11689. }
  11690. if (typeof element.childElementCount !== 'undefined') {
  11691. return element.childElementCount;
  11692. }
  11693. var count = 0;
  11694. for (var i = 0; i < element.childNodes.length; i++) {
  11695. count += element.nodeType === 1 ? 1 : 0;
  11696. }
  11697. return count;
  11698. }
  11699. function translateFragment(element) {
  11700. element = element || document.documentElement;
  11701. var children = getTranslatableChildren(element);
  11702. var elementCount = children.length;
  11703. for (var i = 0; i < elementCount; i++) {
  11704. translateElement(children[i]);
  11705. }
  11706. translateElement(element);
  11707. }
  11708. return {
  11709. get: function (key, args, fallbackString) {
  11710. var index = key.lastIndexOf('.');
  11711. var prop = gTextProp;
  11712. if (index > 0) {
  11713. prop = key.substring(index + 1);
  11714. key = key.substring(0, index);
  11715. }
  11716. var fallback;
  11717. if (fallbackString) {
  11718. fallback = {};
  11719. fallback[prop] = fallbackString;
  11720. }
  11721. var data = getL10nData(key, args, fallback);
  11722. if (data && prop in data) {
  11723. return data[prop];
  11724. }
  11725. return '{{' + key + '}}';
  11726. },
  11727. getData: function () {
  11728. return gL10nData;
  11729. },
  11730. getText: function () {
  11731. return gTextData;
  11732. },
  11733. getLanguage: function () {
  11734. return gLanguage;
  11735. },
  11736. setLanguage: function (lang, callback) {
  11737. loadLocale(lang, function () {
  11738. if (callback) callback();
  11739. });
  11740. },
  11741. getDirection: function () {
  11742. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  11743. var shortCode = gLanguage.split('-', 1)[0];
  11744. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  11745. },
  11746. translate: translateFragment,
  11747. getReadyState: function () {
  11748. return gReadyState;
  11749. },
  11750. ready: function (callback) {
  11751. if (!callback) {
  11752. return;
  11753. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  11754. window.setTimeout(function () {
  11755. callback();
  11756. });
  11757. } else if (document.addEventListener) {
  11758. document.addEventListener('localized', function once() {
  11759. document.removeEventListener('localized', once);
  11760. callback();
  11761. });
  11762. }
  11763. }
  11764. };
  11765. }(window, document);
  11766. /***/ }),
  11767. /* 44 */
  11768. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11769. Object.defineProperty(exports, "__esModule", ({
  11770. value: true
  11771. }));
  11772. exports.docPropertiesLookup = docPropertiesLookup;
  11773. exports.GenericScripting = void 0;
  11774. var _pdfjsLib = __webpack_require__(5);
  11775. async function docPropertiesLookup(pdfDocument) {
  11776. const url = "",
  11777. baseUrl = url.split("#")[0];
  11778. let {
  11779. info,
  11780. metadata,
  11781. contentDispositionFilename,
  11782. contentLength
  11783. } = await pdfDocument.getMetadata();
  11784. if (!contentLength) {
  11785. const {
  11786. length
  11787. } = await pdfDocument.getDownloadInfo();
  11788. contentLength = length;
  11789. }
  11790. return { ...info,
  11791. baseURL: baseUrl,
  11792. filesize: contentLength,
  11793. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  11794. metadata: metadata?.getRaw(),
  11795. authors: metadata?.get("dc:creator"),
  11796. numPages: pdfDocument.numPages,
  11797. URL: url
  11798. };
  11799. }
  11800. class GenericScripting {
  11801. constructor(sandboxBundleSrc) {
  11802. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  11803. return window.pdfjsSandbox.QuickJSSandbox();
  11804. });
  11805. }
  11806. async createSandbox(data) {
  11807. const sandbox = await this._ready;
  11808. sandbox.create(data);
  11809. }
  11810. async dispatchEventInSandbox(event) {
  11811. const sandbox = await this._ready;
  11812. sandbox.dispatchEvent(event);
  11813. }
  11814. async destroySandbox() {
  11815. const sandbox = await this._ready;
  11816. sandbox.nukeSandbox();
  11817. }
  11818. }
  11819. exports.GenericScripting = GenericScripting;
  11820. /***/ }),
  11821. /* 45 */
  11822. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11823. Object.defineProperty(exports, "__esModule", ({
  11824. value: true
  11825. }));
  11826. exports.PDFPrintService = PDFPrintService;
  11827. var _app = __webpack_require__(3);
  11828. var _viewer_compatibility = __webpack_require__(2);
  11829. let activeService = null;
  11830. let overlayManager = null;
  11831. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise) {
  11832. const scratchCanvas = activeService.scratchCanvas;
  11833. const PRINT_UNITS = printResolution / 72.0;
  11834. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  11835. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  11836. const ctx = scratchCanvas.getContext("2d");
  11837. ctx.save();
  11838. ctx.fillStyle = "rgb(255, 255, 255)";
  11839. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  11840. ctx.restore();
  11841. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  11842. const renderContext = {
  11843. canvasContext: ctx,
  11844. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  11845. viewport: pdfPage.getViewport({
  11846. scale: 1,
  11847. rotation: size.rotation
  11848. }),
  11849. intent: "print",
  11850. includeAnnotationStorage: true,
  11851. optionalContentConfigPromise
  11852. };
  11853. return pdfPage.render(renderContext).promise;
  11854. });
  11855. }
  11856. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, l10n) {
  11857. this.pdfDocument = pdfDocument;
  11858. this.pagesOverview = pagesOverview;
  11859. this.printContainer = printContainer;
  11860. this._printResolution = printResolution || 150;
  11861. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  11862. this.l10n = l10n;
  11863. this.currentPage = -1;
  11864. this.scratchCanvas = document.createElement("canvas");
  11865. }
  11866. PDFPrintService.prototype = {
  11867. layout() {
  11868. this.throwIfInactive();
  11869. const body = document.querySelector("body");
  11870. body.setAttribute("data-pdfjsprinting", true);
  11871. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  11872. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  11873. }, this);
  11874. if (!hasEqualPageSizes) {
  11875. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  11876. }
  11877. this.pageStyleSheet = document.createElement("style");
  11878. const pageSize = this.pagesOverview[0];
  11879. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  11880. body.appendChild(this.pageStyleSheet);
  11881. },
  11882. destroy() {
  11883. if (activeService !== this) {
  11884. return;
  11885. }
  11886. this.printContainer.textContent = "";
  11887. const body = document.querySelector("body");
  11888. body.removeAttribute("data-pdfjsprinting");
  11889. if (this.pageStyleSheet) {
  11890. this.pageStyleSheet.remove();
  11891. this.pageStyleSheet = null;
  11892. }
  11893. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  11894. this.scratchCanvas = null;
  11895. activeService = null;
  11896. ensureOverlay().then(function () {
  11897. if (overlayManager.active !== "printServiceOverlay") {
  11898. return;
  11899. }
  11900. overlayManager.close("printServiceOverlay");
  11901. });
  11902. },
  11903. renderPages() {
  11904. const pageCount = this.pagesOverview.length;
  11905. const renderNextPage = (resolve, reject) => {
  11906. this.throwIfInactive();
  11907. if (++this.currentPage >= pageCount) {
  11908. renderProgress(pageCount, pageCount, this.l10n);
  11909. resolve();
  11910. return;
  11911. }
  11912. const index = this.currentPage;
  11913. renderProgress(index, pageCount, this.l10n);
  11914. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise).then(this.useRenderedPage.bind(this)).then(function () {
  11915. renderNextPage(resolve, reject);
  11916. }, reject);
  11917. };
  11918. return new Promise(renderNextPage);
  11919. },
  11920. useRenderedPage() {
  11921. this.throwIfInactive();
  11922. const img = document.createElement("img");
  11923. const scratchCanvas = this.scratchCanvas;
  11924. if ("toBlob" in scratchCanvas && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  11925. scratchCanvas.toBlob(function (blob) {
  11926. img.src = URL.createObjectURL(blob);
  11927. });
  11928. } else {
  11929. img.src = scratchCanvas.toDataURL();
  11930. }
  11931. const wrapper = document.createElement("div");
  11932. wrapper.appendChild(img);
  11933. this.printContainer.appendChild(wrapper);
  11934. return new Promise(function (resolve, reject) {
  11935. img.onload = resolve;
  11936. img.onerror = reject;
  11937. });
  11938. },
  11939. performPrint() {
  11940. this.throwIfInactive();
  11941. return new Promise(resolve => {
  11942. setTimeout(() => {
  11943. if (!this.active) {
  11944. resolve();
  11945. return;
  11946. }
  11947. print.call(window);
  11948. setTimeout(resolve, 20);
  11949. }, 0);
  11950. });
  11951. },
  11952. get active() {
  11953. return this === activeService;
  11954. },
  11955. throwIfInactive() {
  11956. if (!this.active) {
  11957. throw new Error("This print request was cancelled or completed.");
  11958. }
  11959. }
  11960. };
  11961. const print = window.print;
  11962. window.print = function () {
  11963. if (activeService) {
  11964. console.warn("Ignored window.print() because of a pending print job.");
  11965. return;
  11966. }
  11967. ensureOverlay().then(function () {
  11968. if (activeService) {
  11969. overlayManager.open("printServiceOverlay");
  11970. }
  11971. });
  11972. try {
  11973. dispatchEvent("beforeprint");
  11974. } finally {
  11975. if (!activeService) {
  11976. console.error("Expected print service to be initialized.");
  11977. ensureOverlay().then(function () {
  11978. if (overlayManager.active === "printServiceOverlay") {
  11979. overlayManager.close("printServiceOverlay");
  11980. }
  11981. });
  11982. return;
  11983. }
  11984. const activeServiceOnEntry = activeService;
  11985. activeService.renderPages().then(function () {
  11986. return activeServiceOnEntry.performPrint();
  11987. }).catch(function () {}).then(function () {
  11988. if (activeServiceOnEntry.active) {
  11989. abort();
  11990. }
  11991. });
  11992. }
  11993. };
  11994. function dispatchEvent(eventType) {
  11995. const event = document.createEvent("CustomEvent");
  11996. event.initCustomEvent(eventType, false, false, "custom");
  11997. window.dispatchEvent(event);
  11998. }
  11999. function abort() {
  12000. if (activeService) {
  12001. activeService.destroy();
  12002. dispatchEvent("afterprint");
  12003. }
  12004. }
  12005. function renderProgress(index, total, l10n) {
  12006. const progressContainer = document.getElementById("printServiceOverlay");
  12007. const progress = Math.round(100 * index / total);
  12008. const progressBar = progressContainer.querySelector("progress");
  12009. const progressPerc = progressContainer.querySelector(".relative-progress");
  12010. progressBar.value = progress;
  12011. l10n.get("print_progress_percent", {
  12012. progress
  12013. }).then(msg => {
  12014. progressPerc.textContent = msg;
  12015. });
  12016. }
  12017. window.addEventListener("keydown", function (event) {
  12018. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  12019. window.print();
  12020. event.preventDefault();
  12021. if (event.stopImmediatePropagation) {
  12022. event.stopImmediatePropagation();
  12023. } else {
  12024. event.stopPropagation();
  12025. }
  12026. }
  12027. }, true);
  12028. if ("onbeforeprint" in window) {
  12029. const stopPropagationIfNeeded = function (event) {
  12030. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  12031. event.stopImmediatePropagation();
  12032. }
  12033. };
  12034. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  12035. window.addEventListener("afterprint", stopPropagationIfNeeded);
  12036. }
  12037. let overlayPromise;
  12038. function ensureOverlay() {
  12039. if (!overlayPromise) {
  12040. overlayManager = _app.PDFViewerApplication.overlayManager;
  12041. if (!overlayManager) {
  12042. throw new Error("The overlay manager has not yet been initialized.");
  12043. }
  12044. overlayPromise = overlayManager.register("printServiceOverlay", document.getElementById("printServiceOverlay"), abort, true);
  12045. document.getElementById("printCancel").onclick = abort;
  12046. }
  12047. return overlayPromise;
  12048. }
  12049. _app.PDFPrintServiceFactory.instance = {
  12050. supportsPrinting: true,
  12051. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n) {
  12052. if (activeService) {
  12053. throw new Error("The print service is created and active.");
  12054. }
  12055. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n);
  12056. return activeService;
  12057. }
  12058. };
  12059. /***/ })
  12060. /******/ ]);
  12061. /************************************************************************/
  12062. /******/ // The module cache
  12063. /******/ var __webpack_module_cache__ = {};
  12064. /******/
  12065. /******/ // The require function
  12066. /******/ function __webpack_require__(moduleId) {
  12067. /******/ // Check if module is in cache
  12068. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  12069. /******/ if (cachedModule !== undefined) {
  12070. /******/ return cachedModule.exports;
  12071. /******/ }
  12072. /******/ // Create a new module (and put it into the cache)
  12073. /******/ var module = __webpack_module_cache__[moduleId] = {
  12074. /******/ // no module.id needed
  12075. /******/ // no module.loaded needed
  12076. /******/ exports: {}
  12077. /******/ };
  12078. /******/
  12079. /******/ // Execute the module function
  12080. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  12081. /******/
  12082. /******/ // Return the exports of the module
  12083. /******/ return module.exports;
  12084. /******/ }
  12085. /******/
  12086. /************************************************************************/
  12087. var __webpack_exports__ = {};
  12088. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  12089. (() => {
  12090. var exports = __webpack_exports__;
  12091. Object.defineProperty(exports, "__esModule", ({
  12092. value: true
  12093. }));
  12094. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  12095. enumerable: true,
  12096. get: function () {
  12097. return _app_options.AppOptions;
  12098. }
  12099. }));
  12100. Object.defineProperty(exports, "PDFViewerApplication", ({
  12101. enumerable: true,
  12102. get: function () {
  12103. return _app.PDFViewerApplication;
  12104. }
  12105. }));
  12106. var _app_options = __webpack_require__(1);
  12107. var _app = __webpack_require__(3);
  12108. const pdfjsVersion = '2.9.359';
  12109. const pdfjsBuild = 'e667c8cbc';
  12110. window.PDFViewerApplication = _app.PDFViewerApplication;
  12111. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  12112. ;
  12113. ;
  12114. {
  12115. __webpack_require__(39);
  12116. }
  12117. ;
  12118. {
  12119. __webpack_require__(45);
  12120. }
  12121. function getViewerConfiguration() {
  12122. let errorWrapper = null;
  12123. errorWrapper = {
  12124. container: document.getElementById("errorWrapper"),
  12125. errorMessage: document.getElementById("errorMessage"),
  12126. closeButton: document.getElementById("errorClose"),
  12127. errorMoreInfo: document.getElementById("errorMoreInfo"),
  12128. moreInfoButton: document.getElementById("errorShowMore"),
  12129. lessInfoButton: document.getElementById("errorShowLess")
  12130. };
  12131. return {
  12132. appContainer: document.body,
  12133. mainContainer: document.getElementById("viewerContainer"),
  12134. viewerContainer: document.getElementById("viewer"),
  12135. eventBus: null,
  12136. toolbar: {
  12137. container: document.getElementById("toolbarViewer"),
  12138. numPages: document.getElementById("numPages"),
  12139. pageNumber: document.getElementById("pageNumber"),
  12140. scaleSelectContainer: document.getElementById("scaleSelectContainer"),
  12141. scaleSelect: document.getElementById("scaleSelect"),
  12142. customScaleOption: document.getElementById("customScaleOption"),
  12143. previous: document.getElementById("previous"),
  12144. next: document.getElementById("next"),
  12145. zoomIn: document.getElementById("zoomIn"),
  12146. zoomOut: document.getElementById("zoomOut"),
  12147. viewFind: document.getElementById("viewFind"),
  12148. openFile: document.getElementById("openFile"),
  12149. print: document.getElementById("print"),
  12150. presentationModeButton: document.getElementById("presentationMode"),
  12151. download: document.getElementById("download"),
  12152. viewBookmark: document.getElementById("viewBookmark")
  12153. },
  12154. secondaryToolbar: {
  12155. toolbar: document.getElementById("secondaryToolbar"),
  12156. toggleButton: document.getElementById("secondaryToolbarToggle"),
  12157. toolbarButtonContainer: document.getElementById("secondaryToolbarButtonContainer"),
  12158. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  12159. openFileButton: document.getElementById("secondaryOpenFile"),
  12160. printButton: document.getElementById("secondaryPrint"),
  12161. downloadButton: document.getElementById("secondaryDownload"),
  12162. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  12163. firstPageButton: document.getElementById("firstPage"),
  12164. lastPageButton: document.getElementById("lastPage"),
  12165. pageRotateCwButton: document.getElementById("pageRotateCw"),
  12166. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  12167. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  12168. cursorHandToolButton: document.getElementById("cursorHandTool"),
  12169. scrollVerticalButton: document.getElementById("scrollVertical"),
  12170. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  12171. scrollWrappedButton: document.getElementById("scrollWrapped"),
  12172. spreadNoneButton: document.getElementById("spreadNone"),
  12173. spreadOddButton: document.getElementById("spreadOdd"),
  12174. spreadEvenButton: document.getElementById("spreadEven"),
  12175. documentPropertiesButton: document.getElementById("documentProperties")
  12176. },
  12177. sidebar: {
  12178. outerContainer: document.getElementById("outerContainer"),
  12179. viewerContainer: document.getElementById("viewerContainer"),
  12180. toggleButton: document.getElementById("sidebarToggle"),
  12181. thumbnailButton: document.getElementById("viewThumbnail"),
  12182. outlineButton: document.getElementById("viewOutline"),
  12183. attachmentsButton: document.getElementById("viewAttachments"),
  12184. layersButton: document.getElementById("viewLayers"),
  12185. thumbnailView: document.getElementById("thumbnailView"),
  12186. outlineView: document.getElementById("outlineView"),
  12187. attachmentsView: document.getElementById("attachmentsView"),
  12188. layersView: document.getElementById("layersView"),
  12189. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  12190. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  12191. },
  12192. sidebarResizer: {
  12193. outerContainer: document.getElementById("outerContainer"),
  12194. resizer: document.getElementById("sidebarResizer")
  12195. },
  12196. findBar: {
  12197. bar: document.getElementById("findbar"),
  12198. toggleButton: document.getElementById("viewFind"),
  12199. findField: document.getElementById("findInput"),
  12200. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  12201. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  12202. entireWordCheckbox: document.getElementById("findEntireWord"),
  12203. findMsg: document.getElementById("findMsg"),
  12204. findResultsCount: document.getElementById("findResultsCount"),
  12205. findPreviousButton: document.getElementById("findPrevious"),
  12206. findNextButton: document.getElementById("findNext")
  12207. },
  12208. passwordOverlay: {
  12209. overlayName: "passwordOverlay",
  12210. container: document.getElementById("passwordOverlay"),
  12211. label: document.getElementById("passwordText"),
  12212. input: document.getElementById("password"),
  12213. submitButton: document.getElementById("passwordSubmit"),
  12214. cancelButton: document.getElementById("passwordCancel")
  12215. },
  12216. documentProperties: {
  12217. overlayName: "documentPropertiesOverlay",
  12218. container: document.getElementById("documentPropertiesOverlay"),
  12219. closeButton: document.getElementById("documentPropertiesClose"),
  12220. fields: {
  12221. fileName: document.getElementById("fileNameField"),
  12222. fileSize: document.getElementById("fileSizeField"),
  12223. title: document.getElementById("titleField"),
  12224. author: document.getElementById("authorField"),
  12225. subject: document.getElementById("subjectField"),
  12226. keywords: document.getElementById("keywordsField"),
  12227. creationDate: document.getElementById("creationDateField"),
  12228. modificationDate: document.getElementById("modificationDateField"),
  12229. creator: document.getElementById("creatorField"),
  12230. producer: document.getElementById("producerField"),
  12231. version: document.getElementById("versionField"),
  12232. pageCount: document.getElementById("pageCountField"),
  12233. pageSize: document.getElementById("pageSizeField"),
  12234. linearized: document.getElementById("linearizedField")
  12235. }
  12236. },
  12237. errorWrapper,
  12238. printContainer: document.getElementById("printContainer"),
  12239. openFileInputName: "fileInput",
  12240. debuggerScriptPath: "./debugger.js"
  12241. };
  12242. }
  12243. function webViewerLoad() {
  12244. const config = getViewerConfiguration();
  12245. const event = document.createEvent("CustomEvent");
  12246. event.initCustomEvent("webviewerloaded", true, true, {
  12247. source: window
  12248. });
  12249. try {
  12250. parent.document.dispatchEvent(event);
  12251. } catch (ex) {
  12252. console.error(`webviewerloaded: ${ex}`);
  12253. document.dispatchEvent(event);
  12254. }
  12255. _app.PDFViewerApplication.run(config);
  12256. }
  12257. if (document.blockUnblockOnload) {
  12258. document.blockUnblockOnload(true);
  12259. }
  12260. if (document.readyState === "interactive" || document.readyState === "complete") {
  12261. webViewerLoad();
  12262. } else {
  12263. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  12264. }
  12265. })();
  12266. /******/ })()
  12267. ;
  12268. //# sourceMappingURL=viewer.js.map