viewer.js 494 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = void 0;
  32. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  33. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  34. exports.approximateFraction = approximateFraction;
  35. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  36. exports.binarySearchFirstItem = binarySearchFirstItem;
  37. exports.docStyle = void 0;
  38. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  39. exports.getPageSizeInches = getPageSizeInches;
  40. exports.getVisibleElements = getVisibleElements;
  41. exports.isPortraitOrientation = isPortraitOrientation;
  42. exports.isValidRotation = isValidRotation;
  43. exports.isValidScrollMode = isValidScrollMode;
  44. exports.isValidSpreadMode = isValidSpreadMode;
  45. exports.noContextMenuHandler = noContextMenuHandler;
  46. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  47. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  48. exports.parseQueryString = parseQueryString;
  49. exports.removeNullCharacters = removeNullCharacters;
  50. exports.roundToDivide = roundToDivide;
  51. exports.scrollIntoView = scrollIntoView;
  52. exports.watchScroll = watchScroll;
  53. const DEFAULT_SCALE_VALUE = "auto";
  54. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  55. const DEFAULT_SCALE = 1.0;
  56. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  57. const DEFAULT_SCALE_DELTA = 1.1;
  58. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  59. const MIN_SCALE = 0.1;
  60. exports.MIN_SCALE = MIN_SCALE;
  61. const MAX_SCALE = 10.0;
  62. exports.MAX_SCALE = MAX_SCALE;
  63. const UNKNOWN_SCALE = 0;
  64. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  65. const MAX_AUTO_SCALE = 1.25;
  66. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  67. const SCROLLBAR_PADDING = 40;
  68. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  69. const VERTICAL_PADDING = 5;
  70. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  71. const RenderingStates = {
  72. INITIAL: 0,
  73. RUNNING: 1,
  74. PAUSED: 2,
  75. FINISHED: 3
  76. };
  77. exports.RenderingStates = RenderingStates;
  78. const PresentationModeState = {
  79. UNKNOWN: 0,
  80. NORMAL: 1,
  81. CHANGING: 2,
  82. FULLSCREEN: 3
  83. };
  84. exports.PresentationModeState = PresentationModeState;
  85. const SidebarView = {
  86. UNKNOWN: -1,
  87. NONE: 0,
  88. THUMBS: 1,
  89. OUTLINE: 2,
  90. ATTACHMENTS: 3,
  91. LAYERS: 4
  92. };
  93. exports.SidebarView = SidebarView;
  94. const RendererType = {
  95. CANVAS: "canvas",
  96. SVG: "svg"
  97. };
  98. exports.RendererType = RendererType;
  99. const TextLayerMode = {
  100. DISABLE: 0,
  101. ENABLE: 1,
  102. ENABLE_ENHANCE: 2
  103. };
  104. exports.TextLayerMode = TextLayerMode;
  105. const ScrollMode = {
  106. UNKNOWN: -1,
  107. VERTICAL: 0,
  108. HORIZONTAL: 1,
  109. WRAPPED: 2,
  110. PAGE: 3
  111. };
  112. exports.ScrollMode = ScrollMode;
  113. const SpreadMode = {
  114. UNKNOWN: -1,
  115. NONE: 0,
  116. ODD: 1,
  117. EVEN: 2
  118. };
  119. exports.SpreadMode = SpreadMode;
  120. const AutoPrintRegExp = /\bprint\s*\(/;
  121. exports.AutoPrintRegExp = AutoPrintRegExp;
  122. class OutputScale {
  123. constructor() {
  124. const pixelRatio = window.devicePixelRatio || 1;
  125. this.sx = pixelRatio;
  126. this.sy = pixelRatio;
  127. }
  128. get scaled() {
  129. return this.sx !== 1 || this.sy !== 1;
  130. }
  131. }
  132. exports.OutputScale = OutputScale;
  133. function scrollIntoView(element, spot, scrollMatches = false) {
  134. let parent = element.offsetParent;
  135. if (!parent) {
  136. console.error("offsetParent is not set -- cannot scroll");
  137. return;
  138. }
  139. let offsetY = element.offsetTop + element.clientTop;
  140. let offsetX = element.offsetLeft + element.clientLeft;
  141. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  142. offsetY += parent.offsetTop;
  143. offsetX += parent.offsetLeft;
  144. parent = parent.offsetParent;
  145. if (!parent) {
  146. return;
  147. }
  148. }
  149. if (spot) {
  150. if (spot.top !== undefined) {
  151. offsetY += spot.top;
  152. }
  153. if (spot.left !== undefined) {
  154. offsetX += spot.left;
  155. parent.scrollLeft = offsetX;
  156. }
  157. }
  158. parent.scrollTop = offsetY;
  159. }
  160. function watchScroll(viewAreaElement, callback) {
  161. const debounceScroll = function (evt) {
  162. if (rAF) {
  163. return;
  164. }
  165. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  166. rAF = null;
  167. const currentX = viewAreaElement.scrollLeft;
  168. const lastX = state.lastX;
  169. if (currentX !== lastX) {
  170. state.right = currentX > lastX;
  171. }
  172. state.lastX = currentX;
  173. const currentY = viewAreaElement.scrollTop;
  174. const lastY = state.lastY;
  175. if (currentY !== lastY) {
  176. state.down = currentY > lastY;
  177. }
  178. state.lastY = currentY;
  179. callback(state);
  180. });
  181. };
  182. const state = {
  183. right: true,
  184. down: true,
  185. lastX: viewAreaElement.scrollLeft,
  186. lastY: viewAreaElement.scrollTop,
  187. _eventHandler: debounceScroll
  188. };
  189. let rAF = null;
  190. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  191. return state;
  192. }
  193. function parseQueryString(query) {
  194. const params = new Map();
  195. for (const [key, value] of new URLSearchParams(query)) {
  196. params.set(key.toLowerCase(), value);
  197. }
  198. return params;
  199. }
  200. const NullCharactersRegExp = /\x00/g;
  201. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  202. function removeNullCharacters(str, replaceInvisible = false) {
  203. if (typeof str !== "string") {
  204. console.error(`The argument must be a string.`);
  205. return str;
  206. }
  207. if (replaceInvisible) {
  208. str = str.replace(InvisibleCharactersRegExp, " ");
  209. }
  210. return str.replace(NullCharactersRegExp, "");
  211. }
  212. function binarySearchFirstItem(items, condition, start = 0) {
  213. let minIndex = start;
  214. let maxIndex = items.length - 1;
  215. if (maxIndex < 0 || !condition(items[maxIndex])) {
  216. return items.length;
  217. }
  218. if (condition(items[minIndex])) {
  219. return minIndex;
  220. }
  221. while (minIndex < maxIndex) {
  222. const currentIndex = minIndex + maxIndex >> 1;
  223. const currentItem = items[currentIndex];
  224. if (condition(currentItem)) {
  225. maxIndex = currentIndex;
  226. } else {
  227. minIndex = currentIndex + 1;
  228. }
  229. }
  230. return minIndex;
  231. }
  232. function approximateFraction(x) {
  233. if (Math.floor(x) === x) {
  234. return [x, 1];
  235. }
  236. const xinv = 1 / x;
  237. const limit = 8;
  238. if (xinv > limit) {
  239. return [1, limit];
  240. } else if (Math.floor(xinv) === xinv) {
  241. return [1, xinv];
  242. }
  243. const x_ = x > 1 ? xinv : x;
  244. let a = 0,
  245. b = 1,
  246. c = 1,
  247. d = 1;
  248. while (true) {
  249. const p = a + c,
  250. q = b + d;
  251. if (q > limit) {
  252. break;
  253. }
  254. if (x_ <= p / q) {
  255. c = p;
  256. d = q;
  257. } else {
  258. a = p;
  259. b = q;
  260. }
  261. }
  262. let result;
  263. if (x_ - a / b < c / d - x_) {
  264. result = x_ === x ? [a, b] : [b, a];
  265. } else {
  266. result = x_ === x ? [c, d] : [d, c];
  267. }
  268. return result;
  269. }
  270. function roundToDivide(x, div) {
  271. const r = x % div;
  272. return r === 0 ? x : Math.round(x - r + div);
  273. }
  274. function getPageSizeInches({
  275. view,
  276. userUnit,
  277. rotate
  278. }) {
  279. const [x1, y1, x2, y2] = view;
  280. const changeOrientation = rotate % 180 !== 0;
  281. const width = (x2 - x1) / 72 * userUnit;
  282. const height = (y2 - y1) / 72 * userUnit;
  283. return {
  284. width: changeOrientation ? height : width,
  285. height: changeOrientation ? width : height
  286. };
  287. }
  288. function backtrackBeforeAllVisibleElements(index, views, top) {
  289. if (index < 2) {
  290. return index;
  291. }
  292. let elt = views[index].div;
  293. let pageTop = elt.offsetTop + elt.clientTop;
  294. if (pageTop >= top) {
  295. elt = views[index - 1].div;
  296. pageTop = elt.offsetTop + elt.clientTop;
  297. }
  298. for (let i = index - 2; i >= 0; --i) {
  299. elt = views[i].div;
  300. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  301. break;
  302. }
  303. index = i;
  304. }
  305. return index;
  306. }
  307. function getVisibleElements({
  308. scrollEl,
  309. views,
  310. sortByVisibility = false,
  311. horizontal = false,
  312. rtl = false
  313. }) {
  314. const top = scrollEl.scrollTop,
  315. bottom = top + scrollEl.clientHeight;
  316. const left = scrollEl.scrollLeft,
  317. right = left + scrollEl.clientWidth;
  318. function isElementBottomAfterViewTop(view) {
  319. const element = view.div;
  320. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  321. return elementBottom > top;
  322. }
  323. function isElementNextAfterViewHorizontally(view) {
  324. const element = view.div;
  325. const elementLeft = element.offsetLeft + element.clientLeft;
  326. const elementRight = elementLeft + element.clientWidth;
  327. return rtl ? elementLeft < right : elementRight > left;
  328. }
  329. const visible = [],
  330. ids = new Set(),
  331. numViews = views.length;
  332. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  333. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  334. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  335. }
  336. let lastEdge = horizontal ? right : -1;
  337. for (let i = firstVisibleElementInd; i < numViews; i++) {
  338. const view = views[i],
  339. element = view.div;
  340. const currentWidth = element.offsetLeft + element.clientLeft;
  341. const currentHeight = element.offsetTop + element.clientTop;
  342. const viewWidth = element.clientWidth,
  343. viewHeight = element.clientHeight;
  344. const viewRight = currentWidth + viewWidth;
  345. const viewBottom = currentHeight + viewHeight;
  346. if (lastEdge === -1) {
  347. if (viewBottom >= bottom) {
  348. lastEdge = viewBottom;
  349. }
  350. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  351. break;
  352. }
  353. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  354. continue;
  355. }
  356. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  357. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  358. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  359. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  360. const percent = fractionHeight * fractionWidth * 100 | 0;
  361. visible.push({
  362. id: view.id,
  363. x: currentWidth,
  364. y: currentHeight,
  365. view,
  366. percent,
  367. widthPercent: fractionWidth * 100 | 0
  368. });
  369. ids.add(view.id);
  370. }
  371. const first = visible[0],
  372. last = visible.at(-1);
  373. if (sortByVisibility) {
  374. visible.sort(function (a, b) {
  375. const pc = a.percent - b.percent;
  376. if (Math.abs(pc) > 0.001) {
  377. return -pc;
  378. }
  379. return a.id - b.id;
  380. });
  381. }
  382. return {
  383. first,
  384. last,
  385. views: visible,
  386. ids
  387. };
  388. }
  389. function noContextMenuHandler(evt) {
  390. evt.preventDefault();
  391. }
  392. function normalizeWheelEventDirection(evt) {
  393. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  394. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  395. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  396. delta = -delta;
  397. }
  398. return delta;
  399. }
  400. function normalizeWheelEventDelta(evt) {
  401. let delta = normalizeWheelEventDirection(evt);
  402. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  403. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  404. const MOUSE_PIXELS_PER_LINE = 30;
  405. const MOUSE_LINES_PER_PAGE = 30;
  406. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  407. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  408. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  409. delta /= MOUSE_LINES_PER_PAGE;
  410. }
  411. return delta;
  412. }
  413. function isValidRotation(angle) {
  414. return Number.isInteger(angle) && angle % 90 === 0;
  415. }
  416. function isValidScrollMode(mode) {
  417. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  418. }
  419. function isValidSpreadMode(mode) {
  420. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  421. }
  422. function isPortraitOrientation(size) {
  423. return size.width <= size.height;
  424. }
  425. const animationStarted = new Promise(function (resolve) {
  426. window.requestAnimationFrame(resolve);
  427. });
  428. exports.animationStarted = animationStarted;
  429. const docStyle = document.documentElement.style;
  430. exports.docStyle = docStyle;
  431. function clamp(v, min, max) {
  432. return Math.min(Math.max(v, min), max);
  433. }
  434. class ProgressBar {
  435. #classList = null;
  436. #percent = 0;
  437. #visible = true;
  438. constructor(id) {
  439. if (arguments.length > 1) {
  440. throw new Error("ProgressBar no longer accepts any additional options, " + "please use CSS rules to modify its appearance instead.");
  441. }
  442. const bar = document.getElementById(id);
  443. this.#classList = bar.classList;
  444. }
  445. get percent() {
  446. return this.#percent;
  447. }
  448. set percent(val) {
  449. this.#percent = clamp(val, 0, 100);
  450. if (isNaN(val)) {
  451. this.#classList.add("indeterminate");
  452. return;
  453. }
  454. this.#classList.remove("indeterminate");
  455. docStyle.setProperty("--progressBar-percent", `${this.#percent}%`);
  456. }
  457. setWidth(viewer) {
  458. if (!viewer) {
  459. return;
  460. }
  461. const container = viewer.parentNode;
  462. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  463. if (scrollbarWidth > 0) {
  464. docStyle.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  465. }
  466. }
  467. hide() {
  468. if (!this.#visible) {
  469. return;
  470. }
  471. this.#visible = false;
  472. this.#classList.add("hidden");
  473. }
  474. show() {
  475. if (this.#visible) {
  476. return;
  477. }
  478. this.#visible = true;
  479. this.#classList.remove("hidden");
  480. }
  481. }
  482. exports.ProgressBar = ProgressBar;
  483. function getActiveOrFocusedElement() {
  484. let curRoot = document;
  485. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  486. while (curActiveOrFocused?.shadowRoot) {
  487. curRoot = curActiveOrFocused.shadowRoot;
  488. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  489. }
  490. return curActiveOrFocused;
  491. }
  492. function apiPageLayoutToViewerModes(layout) {
  493. let scrollMode = ScrollMode.VERTICAL,
  494. spreadMode = SpreadMode.NONE;
  495. switch (layout) {
  496. case "SinglePage":
  497. scrollMode = ScrollMode.PAGE;
  498. break;
  499. case "OneColumn":
  500. break;
  501. case "TwoPageLeft":
  502. scrollMode = ScrollMode.PAGE;
  503. case "TwoColumnLeft":
  504. spreadMode = SpreadMode.ODD;
  505. break;
  506. case "TwoPageRight":
  507. scrollMode = ScrollMode.PAGE;
  508. case "TwoColumnRight":
  509. spreadMode = SpreadMode.EVEN;
  510. break;
  511. }
  512. return {
  513. scrollMode,
  514. spreadMode
  515. };
  516. }
  517. function apiPageModeToSidebarView(mode) {
  518. switch (mode) {
  519. case "UseNone":
  520. return SidebarView.NONE;
  521. case "UseThumbs":
  522. return SidebarView.THUMBS;
  523. case "UseOutlines":
  524. return SidebarView.OUTLINE;
  525. case "UseAttachments":
  526. return SidebarView.ATTACHMENTS;
  527. case "UseOC":
  528. return SidebarView.LAYERS;
  529. }
  530. return SidebarView.NONE;
  531. }
  532. /***/
  533. }),
  534. /* 2 */
  535. /***/ ((__unused_webpack_module, exports) => {
  536. Object.defineProperty(exports, "__esModule", ({
  537. value: true
  538. }));
  539. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  540. const compatibilityParams = Object.create(null);
  541. exports.compatibilityParams = compatibilityParams;
  542. {
  543. const userAgent = navigator.userAgent || "";
  544. const platform = navigator.platform || "";
  545. const maxTouchPoints = navigator.maxTouchPoints || 1;
  546. const isAndroid = /Android/.test(userAgent);
  547. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  548. (function checkCanvasSizeLimitation() {
  549. if (isIOS || isAndroid) {
  550. compatibilityParams.maxCanvasPixels = 5242880;
  551. }
  552. })();
  553. }
  554. const OptionKind = {
  555. VIEWER: 0x02,
  556. API: 0x04,
  557. WORKER: 0x08,
  558. PREFERENCE: 0x80
  559. };
  560. exports.OptionKind = OptionKind;
  561. const defaultOptions = {
  562. annotationEditorMode: {
  563. value: -1,
  564. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  565. },
  566. annotationMode: {
  567. value: 2,
  568. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  569. },
  570. cursorToolOnLoad: {
  571. value: 0,
  572. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  573. },
  574. defaultZoomValue: {
  575. value: "",
  576. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  577. },
  578. disableHistory: {
  579. value: false,
  580. kind: OptionKind.VIEWER
  581. },
  582. disablePageLabels: {
  583. value: false,
  584. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  585. },
  586. enablePermissions: {
  587. value: false,
  588. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  589. },
  590. enablePrintAutoRotate: {
  591. value: true,
  592. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  593. },
  594. enableScripting: {
  595. value: true,
  596. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  597. },
  598. externalLinkRel: {
  599. value: "noopener noreferrer nofollow",
  600. kind: OptionKind.VIEWER
  601. },
  602. externalLinkTarget: {
  603. value: 0,
  604. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  605. },
  606. historyUpdateUrl: {
  607. value: false,
  608. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  609. },
  610. ignoreDestinationZoom: {
  611. value: false,
  612. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  613. },
  614. imageResourcesPath: {
  615. value: "./images/",
  616. kind: OptionKind.VIEWER
  617. },
  618. maxCanvasPixels: {
  619. value: 16777216,
  620. kind: OptionKind.VIEWER
  621. },
  622. forcePageColors: {
  623. value: false,
  624. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  625. },
  626. pageColorsBackground: {
  627. value: "Canvas",
  628. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  629. },
  630. pageColorsForeground: {
  631. value: "CanvasText",
  632. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  633. },
  634. pdfBugEnabled: {
  635. value: false,
  636. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  637. },
  638. printResolution: {
  639. value: 150,
  640. kind: OptionKind.VIEWER
  641. },
  642. sidebarViewOnLoad: {
  643. value: -1,
  644. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  645. },
  646. scrollModeOnLoad: {
  647. value: -1,
  648. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  649. },
  650. spreadModeOnLoad: {
  651. value: -1,
  652. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  653. },
  654. textLayerMode: {
  655. value: 1,
  656. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  657. },
  658. useOnlyCssZoom: {
  659. value: false,
  660. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  661. },
  662. viewerCssTheme: {
  663. value: 0,
  664. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  665. },
  666. viewOnLoad: {
  667. value: 0,
  668. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  669. },
  670. cMapPacked: {
  671. value: true,
  672. kind: OptionKind.API
  673. },
  674. cMapUrl: {
  675. value: "../web/cmaps/",
  676. kind: OptionKind.API
  677. },
  678. disableAutoFetch: {
  679. value: false,
  680. kind: OptionKind.API + OptionKind.PREFERENCE
  681. },
  682. disableFontFace: {
  683. value: false,
  684. kind: OptionKind.API + OptionKind.PREFERENCE
  685. },
  686. disableRange: {
  687. value: false,
  688. kind: OptionKind.API + OptionKind.PREFERENCE
  689. },
  690. disableStream: {
  691. value: false,
  692. kind: OptionKind.API + OptionKind.PREFERENCE
  693. },
  694. docBaseUrl: {
  695. value: "",
  696. kind: OptionKind.API
  697. },
  698. enableXfa: {
  699. value: true,
  700. kind: OptionKind.API + OptionKind.PREFERENCE
  701. },
  702. fontExtraProperties: {
  703. value: false,
  704. kind: OptionKind.API
  705. },
  706. isEvalSupported: {
  707. value: true,
  708. kind: OptionKind.API
  709. },
  710. maxImageSize: {
  711. value: -1,
  712. kind: OptionKind.API
  713. },
  714. pdfBug: {
  715. value: false,
  716. kind: OptionKind.API
  717. },
  718. standardFontDataUrl: {
  719. value: "../web/standard_fonts/",
  720. kind: OptionKind.API
  721. },
  722. verbosity: {
  723. value: 1,
  724. kind: OptionKind.API
  725. },
  726. workerPort: {
  727. value: null,
  728. kind: OptionKind.WORKER
  729. },
  730. workerSrc: {
  731. value: "../build/pdf.worker.js",
  732. kind: OptionKind.WORKER
  733. }
  734. };
  735. {
  736. defaultOptions.defaultUrl = {
  737. value: "compressed.tracemonkey-pldi-09.pdf",
  738. kind: OptionKind.VIEWER
  739. };
  740. defaultOptions.disablePreferences = {
  741. value: false,
  742. kind: OptionKind.VIEWER
  743. };
  744. defaultOptions.locale = {
  745. value: navigator.language || "en-US",
  746. kind: OptionKind.VIEWER
  747. };
  748. defaultOptions.renderer = {
  749. value: "canvas",
  750. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  751. };
  752. defaultOptions.sandboxBundleSrc = {
  753. value: "../build/pdf.sandbox.js",
  754. kind: OptionKind.VIEWER
  755. };
  756. }
  757. const userOptions = Object.create(null);
  758. class AppOptions {
  759. constructor() {
  760. throw new Error("Cannot initialize AppOptions.");
  761. }
  762. static get(name) {
  763. const userOption = userOptions[name];
  764. if (userOption !== undefined) {
  765. return userOption;
  766. }
  767. const defaultOption = defaultOptions[name];
  768. if (defaultOption !== undefined) {
  769. return compatibilityParams[name] ?? defaultOption.value;
  770. }
  771. return undefined;
  772. }
  773. static getAll(kind = null) {
  774. const options = Object.create(null);
  775. for (const name in defaultOptions) {
  776. const defaultOption = defaultOptions[name];
  777. if (kind) {
  778. if ((kind & defaultOption.kind) === 0) {
  779. continue;
  780. }
  781. if (kind === OptionKind.PREFERENCE) {
  782. const value = defaultOption.value,
  783. valueType = typeof value;
  784. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  785. options[name] = value;
  786. continue;
  787. }
  788. throw new Error(`Invalid type for preference: ${name}`);
  789. }
  790. }
  791. const userOption = userOptions[name];
  792. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  793. }
  794. return options;
  795. }
  796. static set(name, value) {
  797. userOptions[name] = value;
  798. }
  799. static setAll(options) {
  800. for (const name in options) {
  801. userOptions[name] = options[name];
  802. }
  803. }
  804. static remove(name) {
  805. delete userOptions[name];
  806. }
  807. static _hasUserOptions() {
  808. return Object.keys(userOptions).length > 0;
  809. }
  810. }
  811. exports.AppOptions = AppOptions;
  812. /***/
  813. }),
  814. /* 3 */
  815. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  816. Object.defineProperty(exports, "__esModule", ({
  817. value: true
  818. }));
  819. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  820. var _ui_utils = __webpack_require__(1);
  821. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  822. const LinkTarget = {
  823. NONE: 0,
  824. SELF: 1,
  825. BLANK: 2,
  826. PARENT: 3,
  827. TOP: 4
  828. };
  829. exports.LinkTarget = LinkTarget;
  830. function addLinkAttributes(link, {
  831. url,
  832. target,
  833. rel,
  834. enabled = true
  835. } = {}) {
  836. if (!url || typeof url !== "string") {
  837. throw new Error('A valid "url" parameter must provided.');
  838. }
  839. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  840. if (enabled) {
  841. link.href = link.title = urlNullRemoved;
  842. } else {
  843. link.href = "";
  844. link.title = `Disabled: ${urlNullRemoved}`;
  845. link.onclick = () => {
  846. return false;
  847. };
  848. }
  849. let targetStr = "";
  850. switch (target) {
  851. case LinkTarget.NONE:
  852. break;
  853. case LinkTarget.SELF:
  854. targetStr = "_self";
  855. break;
  856. case LinkTarget.BLANK:
  857. targetStr = "_blank";
  858. break;
  859. case LinkTarget.PARENT:
  860. targetStr = "_parent";
  861. break;
  862. case LinkTarget.TOP:
  863. targetStr = "_top";
  864. break;
  865. }
  866. link.target = targetStr;
  867. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  868. }
  869. class PDFLinkService {
  870. #pagesRefCache = new Map();
  871. constructor({
  872. eventBus,
  873. externalLinkTarget = null,
  874. externalLinkRel = null,
  875. ignoreDestinationZoom = false
  876. } = {}) {
  877. this.eventBus = eventBus;
  878. this.externalLinkTarget = externalLinkTarget;
  879. this.externalLinkRel = externalLinkRel;
  880. this.externalLinkEnabled = true;
  881. this._ignoreDestinationZoom = ignoreDestinationZoom;
  882. this.baseUrl = null;
  883. this.pdfDocument = null;
  884. this.pdfViewer = null;
  885. this.pdfHistory = null;
  886. }
  887. setDocument(pdfDocument, baseUrl = null) {
  888. this.baseUrl = baseUrl;
  889. this.pdfDocument = pdfDocument;
  890. this.#pagesRefCache.clear();
  891. }
  892. setViewer(pdfViewer) {
  893. this.pdfViewer = pdfViewer;
  894. }
  895. setHistory(pdfHistory) {
  896. this.pdfHistory = pdfHistory;
  897. }
  898. get pagesCount() {
  899. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  900. }
  901. get page() {
  902. return this.pdfViewer.currentPageNumber;
  903. }
  904. set page(value) {
  905. this.pdfViewer.currentPageNumber = value;
  906. }
  907. get rotation() {
  908. return this.pdfViewer.pagesRotation;
  909. }
  910. set rotation(value) {
  911. this.pdfViewer.pagesRotation = value;
  912. }
  913. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  914. const destRef = explicitDest[0];
  915. let pageNumber;
  916. if (typeof destRef === "object" && destRef !== null) {
  917. pageNumber = this._cachedPageNumber(destRef);
  918. if (!pageNumber) {
  919. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  920. this.cachePageRef(pageIndex + 1, destRef);
  921. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  922. }).catch(() => {
  923. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  924. });
  925. return;
  926. }
  927. } else if (Number.isInteger(destRef)) {
  928. pageNumber = destRef + 1;
  929. } else {
  930. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  931. return;
  932. }
  933. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  934. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  935. return;
  936. }
  937. if (this.pdfHistory) {
  938. this.pdfHistory.pushCurrentPosition();
  939. this.pdfHistory.push({
  940. namedDest,
  941. explicitDest,
  942. pageNumber
  943. });
  944. }
  945. this.pdfViewer.scrollPageIntoView({
  946. pageNumber,
  947. destArray: explicitDest,
  948. ignoreDestinationZoom: this._ignoreDestinationZoom
  949. });
  950. }
  951. async goToDestination(dest) {
  952. if (!this.pdfDocument) {
  953. return;
  954. }
  955. let namedDest, explicitDest;
  956. if (typeof dest === "string") {
  957. namedDest = dest;
  958. explicitDest = await this.pdfDocument.getDestination(dest);
  959. } else {
  960. namedDest = null;
  961. explicitDest = await dest;
  962. }
  963. if (!Array.isArray(explicitDest)) {
  964. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  965. return;
  966. }
  967. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  968. }
  969. goToPage(val) {
  970. if (!this.pdfDocument) {
  971. return;
  972. }
  973. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  974. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  975. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  976. return;
  977. }
  978. if (this.pdfHistory) {
  979. this.pdfHistory.pushCurrentPosition();
  980. this.pdfHistory.pushPage(pageNumber);
  981. }
  982. this.pdfViewer.scrollPageIntoView({
  983. pageNumber
  984. });
  985. }
  986. addLinkAttributes(link, url, newWindow = false) {
  987. addLinkAttributes(link, {
  988. url,
  989. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  990. rel: this.externalLinkRel,
  991. enabled: this.externalLinkEnabled
  992. });
  993. }
  994. getDestinationHash(dest) {
  995. if (typeof dest === "string") {
  996. if (dest.length > 0) {
  997. return this.getAnchorUrl("#" + escape(dest));
  998. }
  999. } else if (Array.isArray(dest)) {
  1000. const str = JSON.stringify(dest);
  1001. if (str.length > 0) {
  1002. return this.getAnchorUrl("#" + escape(str));
  1003. }
  1004. }
  1005. return this.getAnchorUrl("");
  1006. }
  1007. getAnchorUrl(anchor) {
  1008. return (this.baseUrl || "") + anchor;
  1009. }
  1010. setHash(hash) {
  1011. if (!this.pdfDocument) {
  1012. return;
  1013. }
  1014. let pageNumber, dest;
  1015. if (hash.includes("=")) {
  1016. const params = (0, _ui_utils.parseQueryString)(hash);
  1017. if (params.has("search")) {
  1018. this.eventBus.dispatch("findfromurlhash", {
  1019. source: this,
  1020. query: params.get("search").replace(/"/g, ""),
  1021. phraseSearch: params.get("phrase") === "true"
  1022. });
  1023. }
  1024. if (params.has("page")) {
  1025. pageNumber = params.get("page") | 0 || 1;
  1026. }
  1027. if (params.has("zoom")) {
  1028. const zoomArgs = params.get("zoom").split(",");
  1029. const zoomArg = zoomArgs[0];
  1030. const zoomArgNumber = parseFloat(zoomArg);
  1031. if (!zoomArg.includes("Fit")) {
  1032. dest = [null, {
  1033. name: "XYZ"
  1034. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  1035. } else {
  1036. if (zoomArg === "Fit" || zoomArg === "FitB") {
  1037. dest = [null, {
  1038. name: zoomArg
  1039. }];
  1040. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  1041. dest = [null, {
  1042. name: zoomArg
  1043. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  1044. } else if (zoomArg === "FitR") {
  1045. if (zoomArgs.length !== 5) {
  1046. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  1047. } else {
  1048. dest = [null, {
  1049. name: zoomArg
  1050. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  1051. }
  1052. } else {
  1053. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  1054. }
  1055. }
  1056. }
  1057. if (dest) {
  1058. this.pdfViewer.scrollPageIntoView({
  1059. pageNumber: pageNumber || this.page,
  1060. destArray: dest,
  1061. allowNegativeOffset: true
  1062. });
  1063. } else if (pageNumber) {
  1064. this.page = pageNumber;
  1065. }
  1066. if (params.has("pagemode")) {
  1067. this.eventBus.dispatch("pagemode", {
  1068. source: this,
  1069. mode: params.get("pagemode")
  1070. });
  1071. }
  1072. if (params.has("nameddest")) {
  1073. this.goToDestination(params.get("nameddest"));
  1074. }
  1075. } else {
  1076. dest = unescape(hash);
  1077. try {
  1078. dest = JSON.parse(dest);
  1079. if (!Array.isArray(dest)) {
  1080. dest = dest.toString();
  1081. }
  1082. } catch (ex) { }
  1083. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  1084. this.goToDestination(dest);
  1085. return;
  1086. }
  1087. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  1088. }
  1089. }
  1090. executeNamedAction(action) {
  1091. switch (action) {
  1092. case "GoBack":
  1093. this.pdfHistory?.back();
  1094. break;
  1095. case "GoForward":
  1096. this.pdfHistory?.forward();
  1097. break;
  1098. case "NextPage":
  1099. this.pdfViewer.nextPage();
  1100. break;
  1101. case "PrevPage":
  1102. this.pdfViewer.previousPage();
  1103. break;
  1104. case "LastPage":
  1105. this.page = this.pagesCount;
  1106. break;
  1107. case "FirstPage":
  1108. this.page = 1;
  1109. break;
  1110. default:
  1111. break;
  1112. }
  1113. this.eventBus.dispatch("namedaction", {
  1114. source: this,
  1115. action
  1116. });
  1117. }
  1118. cachePageRef(pageNum, pageRef) {
  1119. if (!pageRef) {
  1120. return;
  1121. }
  1122. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1123. this.#pagesRefCache.set(refStr, pageNum);
  1124. }
  1125. _cachedPageNumber(pageRef) {
  1126. if (!pageRef) {
  1127. return null;
  1128. }
  1129. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1130. return this.#pagesRefCache.get(refStr) || null;
  1131. }
  1132. isPageVisible(pageNumber) {
  1133. return this.pdfViewer.isPageVisible(pageNumber);
  1134. }
  1135. isPageCached(pageNumber) {
  1136. return this.pdfViewer.isPageCached(pageNumber);
  1137. }
  1138. static #isValidExplicitDestination(dest) {
  1139. if (!Array.isArray(dest)) {
  1140. return false;
  1141. }
  1142. const destLength = dest.length;
  1143. if (destLength < 2) {
  1144. return false;
  1145. }
  1146. const page = dest[0];
  1147. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  1148. return false;
  1149. }
  1150. const zoom = dest[1];
  1151. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  1152. return false;
  1153. }
  1154. let allowNull = true;
  1155. switch (zoom.name) {
  1156. case "XYZ":
  1157. if (destLength !== 5) {
  1158. return false;
  1159. }
  1160. break;
  1161. case "Fit":
  1162. case "FitB":
  1163. return destLength === 2;
  1164. case "FitH":
  1165. case "FitBH":
  1166. case "FitV":
  1167. case "FitBV":
  1168. if (destLength !== 3) {
  1169. return false;
  1170. }
  1171. break;
  1172. case "FitR":
  1173. if (destLength !== 6) {
  1174. return false;
  1175. }
  1176. allowNull = false;
  1177. break;
  1178. default:
  1179. return false;
  1180. }
  1181. for (let i = 2; i < destLength; i++) {
  1182. const param = dest[i];
  1183. if (!(typeof param === "number" || allowNull && param === null)) {
  1184. return false;
  1185. }
  1186. }
  1187. return true;
  1188. }
  1189. }
  1190. exports.PDFLinkService = PDFLinkService;
  1191. class SimpleLinkService {
  1192. constructor() {
  1193. this.externalLinkEnabled = true;
  1194. }
  1195. get pagesCount() {
  1196. return 0;
  1197. }
  1198. get page() {
  1199. return 0;
  1200. }
  1201. set page(value) { }
  1202. get rotation() {
  1203. return 0;
  1204. }
  1205. set rotation(value) { }
  1206. async goToDestination(dest) { }
  1207. goToPage(val) { }
  1208. addLinkAttributes(link, url, newWindow = false) {
  1209. addLinkAttributes(link, {
  1210. url,
  1211. enabled: this.externalLinkEnabled
  1212. });
  1213. }
  1214. getDestinationHash(dest) {
  1215. return "#";
  1216. }
  1217. getAnchorUrl(hash) {
  1218. return "#";
  1219. }
  1220. setHash(hash) { }
  1221. executeNamedAction(action) { }
  1222. cachePageRef(pageNum, pageRef) { }
  1223. isPageVisible(pageNumber) {
  1224. return true;
  1225. }
  1226. isPageCached(pageNumber) {
  1227. return true;
  1228. }
  1229. }
  1230. exports.SimpleLinkService = SimpleLinkService;
  1231. /***/
  1232. }),
  1233. /* 4 */
  1234. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1235. Object.defineProperty(exports, "__esModule", ({
  1236. value: true
  1237. }));
  1238. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  1239. var _ui_utils = __webpack_require__(1);
  1240. var _pdfjsLib = __webpack_require__(5);
  1241. var _app_options = __webpack_require__(2);
  1242. var _event_utils = __webpack_require__(6);
  1243. var _pdf_cursor_tools = __webpack_require__(7);
  1244. var _pdf_link_service = __webpack_require__(3);
  1245. var _annotation_editor_params = __webpack_require__(9);
  1246. var _overlay_manager = __webpack_require__(10);
  1247. var _password_prompt = __webpack_require__(11);
  1248. var _pdf_attachment_viewer = __webpack_require__(12);
  1249. var _pdf_document_properties = __webpack_require__(14);
  1250. var _pdf_find_bar = __webpack_require__(15);
  1251. var _pdf_find_controller = __webpack_require__(16);
  1252. var _pdf_history = __webpack_require__(18);
  1253. var _pdf_layer_viewer = __webpack_require__(19);
  1254. var _pdf_outline_viewer = __webpack_require__(20);
  1255. var _pdf_presentation_mode = __webpack_require__(21);
  1256. var _pdf_rendering_queue = __webpack_require__(22);
  1257. var _pdf_scripting_manager = __webpack_require__(23);
  1258. var _pdf_sidebar = __webpack_require__(24);
  1259. var _pdf_sidebar_resizer = __webpack_require__(25);
  1260. var _pdf_thumbnail_viewer = __webpack_require__(26);
  1261. var _pdf_viewer = __webpack_require__(28);
  1262. var _secondary_toolbar = __webpack_require__(39);
  1263. var _toolbar = __webpack_require__(40);
  1264. var _view_history = __webpack_require__(41);
  1265. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  1266. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  1267. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  1268. const ViewOnLoad = {
  1269. UNKNOWN: -1,
  1270. PREVIOUS: 0,
  1271. INITIAL: 1
  1272. };
  1273. const ViewerCssTheme = {
  1274. AUTOMATIC: 0,
  1275. LIGHT: 1,
  1276. DARK: 2
  1277. };
  1278. 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"];
  1279. 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"];
  1280. class DefaultExternalServices {
  1281. constructor() {
  1282. throw new Error("Cannot initialize DefaultExternalServices.");
  1283. }
  1284. static updateFindControlState(data) { }
  1285. static updateFindMatchesCount(data) { }
  1286. static initPassiveLoading(callbacks) { }
  1287. static reportTelemetry(data) { }
  1288. static createDownloadManager(options) {
  1289. throw new Error("Not implemented: createDownloadManager");
  1290. }
  1291. static createPreferences() {
  1292. throw new Error("Not implemented: createPreferences");
  1293. }
  1294. static createL10n(options) {
  1295. throw new Error("Not implemented: createL10n");
  1296. }
  1297. static createScripting(options) {
  1298. throw new Error("Not implemented: createScripting");
  1299. }
  1300. static get supportsIntegratedFind() {
  1301. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  1302. }
  1303. static get supportsDocumentFonts() {
  1304. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  1305. }
  1306. static get supportedMouseWheelZoomModifierKeys() {
  1307. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  1308. ctrlKey: true,
  1309. metaKey: true
  1310. });
  1311. }
  1312. static get isInAutomation() {
  1313. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  1314. }
  1315. static updateEditorStates(data) {
  1316. throw new Error("Not implemented: updateEditorStates");
  1317. }
  1318. }
  1319. exports.DefaultExternalServices = DefaultExternalServices;
  1320. const PDFViewerApplication = {
  1321. initialBookmark: document.location.hash.substring(1),
  1322. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  1323. appConfig: null,
  1324. pdfDocument: null,
  1325. pdfLoadingTask: null,
  1326. printService: null,
  1327. pdfViewer: null,
  1328. pdfThumbnailViewer: null,
  1329. pdfRenderingQueue: null,
  1330. pdfPresentationMode: null,
  1331. pdfDocumentProperties: null,
  1332. pdfLinkService: null,
  1333. pdfHistory: null,
  1334. pdfSidebar: null,
  1335. pdfSidebarResizer: null,
  1336. pdfOutlineViewer: null,
  1337. pdfAttachmentViewer: null,
  1338. pdfLayerViewer: null,
  1339. pdfCursorTools: null,
  1340. pdfScriptingManager: null,
  1341. store: null,
  1342. downloadManager: null,
  1343. overlayManager: null,
  1344. preferences: null,
  1345. toolbar: null,
  1346. secondaryToolbar: null,
  1347. eventBus: null,
  1348. l10n: null,
  1349. annotationEditorParams: null,
  1350. isInitialViewSet: false,
  1351. downloadComplete: false,
  1352. isViewerEmbedded: window.parent !== window,
  1353. url: "",
  1354. baseUrl: "",
  1355. _downloadUrl: "",
  1356. externalServices: DefaultExternalServices,
  1357. _boundEvents: Object.create(null),
  1358. documentInfo: null,
  1359. metadata: null,
  1360. _contentDispositionFilename: null,
  1361. _contentLength: null,
  1362. _saveInProgress: false,
  1363. _docStats: null,
  1364. _wheelUnusedTicks: 0,
  1365. _idleCallbacks: new Set(),
  1366. _PDFBug: null,
  1367. _hasAnnotationEditors: false,
  1368. _title: document.title,
  1369. _printAnnotationStoragePromise: null,
  1370. async initialize(appConfig) {
  1371. this.preferences = this.externalServices.createPreferences();
  1372. this.appConfig = appConfig;
  1373. await this._readPreferences();
  1374. await this._parseHashParameters();
  1375. this._forceCssTheme();
  1376. await this._initializeL10n();
  1377. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  1378. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  1379. }
  1380. await this._initializeViewerComponents();
  1381. this.bindEvents();
  1382. this.bindWindowEvents();
  1383. const appContainer = appConfig.appContainer || document.documentElement;
  1384. this.l10n.translate(appContainer).then(() => {
  1385. this.eventBus.dispatch("localized", {
  1386. source: this
  1387. });
  1388. });
  1389. this._initializedCapability.resolve();
  1390. },
  1391. async _readPreferences() {
  1392. if (_app_options.AppOptions.get("disablePreferences")) {
  1393. return;
  1394. }
  1395. if (_app_options.AppOptions._hasUserOptions()) {
  1396. console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  1397. }
  1398. try {
  1399. _app_options.AppOptions.setAll(await this.preferences.getAll());
  1400. } catch (reason) {
  1401. console.error(`_readPreferences: "${reason?.message}".`);
  1402. }
  1403. },
  1404. async _parseHashParameters() {
  1405. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  1406. return;
  1407. }
  1408. const hash = document.location.hash.substring(1);
  1409. if (!hash) {
  1410. return;
  1411. }
  1412. const {
  1413. mainContainer,
  1414. viewerContainer
  1415. } = this.appConfig,
  1416. params = (0, _ui_utils.parseQueryString)(hash);
  1417. if (params.get("disableworker") === "true") {
  1418. try {
  1419. await loadFakeWorker();
  1420. } catch (ex) {
  1421. console.error(`_parseHashParameters: "${ex.message}".`);
  1422. }
  1423. }
  1424. if (params.has("disablerange")) {
  1425. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  1426. }
  1427. if (params.has("disablestream")) {
  1428. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  1429. }
  1430. if (params.has("disableautofetch")) {
  1431. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  1432. }
  1433. if (params.has("disablefontface")) {
  1434. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  1435. }
  1436. if (params.has("disablehistory")) {
  1437. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  1438. }
  1439. if (params.has("verbosity")) {
  1440. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  1441. }
  1442. if (params.has("textlayer")) {
  1443. switch (params.get("textlayer")) {
  1444. case "off":
  1445. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  1446. break;
  1447. case "visible":
  1448. case "shadow":
  1449. case "hover":
  1450. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  1451. try {
  1452. await loadPDFBug(this);
  1453. this._PDFBug.loadCSS();
  1454. } catch (ex) {
  1455. console.error(`_parseHashParameters: "${ex.message}".`);
  1456. }
  1457. break;
  1458. }
  1459. }
  1460. if (params.has("pdfbug")) {
  1461. _app_options.AppOptions.set("pdfBug", true);
  1462. _app_options.AppOptions.set("fontExtraProperties", true);
  1463. const enabled = params.get("pdfbug").split(",");
  1464. try {
  1465. await loadPDFBug(this);
  1466. this._PDFBug.init({
  1467. OPS: _pdfjsLib.OPS
  1468. }, mainContainer, enabled);
  1469. } catch (ex) {
  1470. console.error(`_parseHashParameters: "${ex.message}".`);
  1471. }
  1472. }
  1473. if (params.has("locale")) {
  1474. _app_options.AppOptions.set("locale", params.get("locale"));
  1475. }
  1476. },
  1477. async _initializeL10n() {
  1478. this.l10n = this.externalServices.createL10n({
  1479. locale: _app_options.AppOptions.get("locale")
  1480. });
  1481. const dir = await this.l10n.getDirection();
  1482. document.getElementsByTagName("html")[0].dir = dir;
  1483. },
  1484. _forceCssTheme() {
  1485. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  1486. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  1487. return;
  1488. }
  1489. try {
  1490. const styleSheet = document.styleSheets[0];
  1491. const cssRules = styleSheet?.cssRules || [];
  1492. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  1493. const rule = cssRules[i];
  1494. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  1495. if (cssTheme === ViewerCssTheme.LIGHT) {
  1496. styleSheet.deleteRule(i);
  1497. return;
  1498. }
  1499. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  1500. if (darkRules?.[1]) {
  1501. styleSheet.deleteRule(i);
  1502. styleSheet.insertRule(darkRules[1], i);
  1503. }
  1504. return;
  1505. }
  1506. }
  1507. } catch (reason) {
  1508. console.error(`_forceCssTheme: "${reason?.message}".`);
  1509. }
  1510. },
  1511. async _initializeViewerComponents() {
  1512. const {
  1513. appConfig,
  1514. externalServices
  1515. } = this;
  1516. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  1517. this.eventBus = eventBus;
  1518. this.overlayManager = new _overlay_manager.OverlayManager();
  1519. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  1520. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  1521. this.pdfRenderingQueue = pdfRenderingQueue;
  1522. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  1523. eventBus,
  1524. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  1525. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  1526. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  1527. });
  1528. this.pdfLinkService = pdfLinkService;
  1529. const downloadManager = externalServices.createDownloadManager();
  1530. this.downloadManager = downloadManager;
  1531. const findController = new _pdf_find_controller.PDFFindController({
  1532. linkService: pdfLinkService,
  1533. eventBus
  1534. });
  1535. this.findController = findController;
  1536. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  1537. eventBus,
  1538. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  1539. scriptingFactory: externalServices,
  1540. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  1541. });
  1542. this.pdfScriptingManager = pdfScriptingManager;
  1543. const container = appConfig.mainContainer,
  1544. viewer = appConfig.viewerContainer;
  1545. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  1546. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  1547. background: _app_options.AppOptions.get("pageColorsBackground"),
  1548. foreground: _app_options.AppOptions.get("pageColorsForeground")
  1549. } : null;
  1550. this.pdfViewer = new _pdf_viewer.PDFViewer({
  1551. container,
  1552. viewer,
  1553. eventBus,
  1554. renderingQueue: pdfRenderingQueue,
  1555. linkService: pdfLinkService,
  1556. downloadManager,
  1557. findController,
  1558. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  1559. renderer: _app_options.AppOptions.get("renderer"),
  1560. l10n: this.l10n,
  1561. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  1562. annotationMode: _app_options.AppOptions.get("annotationMode"),
  1563. annotationEditorMode,
  1564. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  1565. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  1566. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  1567. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  1568. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  1569. pageColors
  1570. });
  1571. pdfRenderingQueue.setViewer(this.pdfViewer);
  1572. pdfLinkService.setViewer(this.pdfViewer);
  1573. pdfScriptingManager.setViewer(this.pdfViewer);
  1574. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  1575. container: appConfig.sidebar.thumbnailView,
  1576. eventBus,
  1577. renderingQueue: pdfRenderingQueue,
  1578. linkService: pdfLinkService,
  1579. l10n: this.l10n,
  1580. pageColors
  1581. });
  1582. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  1583. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  1584. this.pdfHistory = new _pdf_history.PDFHistory({
  1585. linkService: pdfLinkService,
  1586. eventBus
  1587. });
  1588. pdfLinkService.setHistory(this.pdfHistory);
  1589. }
  1590. if (!this.supportsIntegratedFind) {
  1591. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  1592. }
  1593. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  1594. this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  1595. for (const element of [document.getElementById("editorModeButtons"), document.getElementById("editorModeSeparator")]) {
  1596. element.classList.remove("hidden");
  1597. }
  1598. }
  1599. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
  1600. return this._docFilename;
  1601. });
  1602. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  1603. container,
  1604. eventBus,
  1605. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  1606. });
  1607. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  1608. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus);
  1609. if (this.supportsFullscreen) {
  1610. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  1611. container,
  1612. pdfViewer: this.pdfViewer,
  1613. eventBus
  1614. });
  1615. }
  1616. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  1617. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  1618. container: appConfig.sidebar.outlineView,
  1619. eventBus,
  1620. linkService: pdfLinkService
  1621. });
  1622. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  1623. container: appConfig.sidebar.attachmentsView,
  1624. eventBus,
  1625. downloadManager
  1626. });
  1627. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  1628. container: appConfig.sidebar.layersView,
  1629. eventBus,
  1630. l10n: this.l10n
  1631. });
  1632. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  1633. elements: appConfig.sidebar,
  1634. pdfViewer: this.pdfViewer,
  1635. pdfThumbnailViewer: this.pdfThumbnailViewer,
  1636. eventBus,
  1637. l10n: this.l10n
  1638. });
  1639. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  1640. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  1641. },
  1642. run(config) {
  1643. this.initialize(config).then(webViewerInitialized);
  1644. },
  1645. get initialized() {
  1646. return this._initializedCapability.settled;
  1647. },
  1648. get initializedPromise() {
  1649. return this._initializedCapability.promise;
  1650. },
  1651. zoomIn(steps) {
  1652. if (this.pdfViewer.isInPresentationMode) {
  1653. return;
  1654. }
  1655. this.pdfViewer.increaseScale(steps);
  1656. },
  1657. zoomOut(steps) {
  1658. if (this.pdfViewer.isInPresentationMode) {
  1659. return;
  1660. }
  1661. this.pdfViewer.decreaseScale(steps);
  1662. },
  1663. zoomReset() {
  1664. if (this.pdfViewer.isInPresentationMode) {
  1665. return;
  1666. }
  1667. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1668. },
  1669. get pagesCount() {
  1670. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  1671. },
  1672. get page() {
  1673. return this.pdfViewer.currentPageNumber;
  1674. },
  1675. set page(val) {
  1676. this.pdfViewer.currentPageNumber = val;
  1677. },
  1678. get supportsPrinting() {
  1679. return PDFPrintServiceFactory.instance.supportsPrinting;
  1680. },
  1681. get supportsFullscreen() {
  1682. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  1683. },
  1684. get supportsIntegratedFind() {
  1685. return this.externalServices.supportsIntegratedFind;
  1686. },
  1687. get supportsDocumentFonts() {
  1688. return this.externalServices.supportsDocumentFonts;
  1689. },
  1690. get loadingBar() {
  1691. const bar = new _ui_utils.ProgressBar("loadingBar");
  1692. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  1693. },
  1694. get supportedMouseWheelZoomModifierKeys() {
  1695. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  1696. },
  1697. initPassiveLoading() {
  1698. throw new Error("Not implemented: initPassiveLoading");
  1699. },
  1700. setTitleUsingUrl(url = "", downloadUrl = null) {
  1701. this.url = url;
  1702. this.baseUrl = url.split("#")[0];
  1703. if (downloadUrl) {
  1704. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  1705. }
  1706. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  1707. if (!title) {
  1708. try {
  1709. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  1710. } catch (ex) {
  1711. title = url;
  1712. }
  1713. }
  1714. this.setTitle(title);
  1715. },
  1716. setTitle(title = this._title) {
  1717. this._title = title;
  1718. if (this.isViewerEmbedded) {
  1719. return;
  1720. }
  1721. document.title = `${this._hasAnnotationEditors ? "* " : ""}${title}`;
  1722. },
  1723. get _docFilename() {
  1724. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  1725. },
  1726. _hideViewBookmark() {
  1727. const {
  1728. toolbar,
  1729. secondaryToolbar
  1730. } = this.appConfig;
  1731. toolbar.viewBookmark.hidden = true;
  1732. secondaryToolbar.viewBookmarkButton.hidden = true;
  1733. },
  1734. _cancelIdleCallbacks() {
  1735. if (!this._idleCallbacks.size) {
  1736. return;
  1737. }
  1738. for (const callback of this._idleCallbacks) {
  1739. window.cancelIdleCallback(callback);
  1740. }
  1741. this._idleCallbacks.clear();
  1742. },
  1743. async close() {
  1744. this._unblockDocumentLoadEvent();
  1745. this._hideViewBookmark();
  1746. const {
  1747. container
  1748. } = this.appConfig.errorWrapper;
  1749. container.hidden = true;
  1750. if (!this.pdfLoadingTask) {
  1751. return;
  1752. }
  1753. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  1754. try {
  1755. await this.save();
  1756. } catch (reason) { }
  1757. }
  1758. const promises = [];
  1759. promises.push(this.pdfLoadingTask.destroy());
  1760. this.pdfLoadingTask = null;
  1761. if (this.pdfDocument) {
  1762. this.pdfDocument = null;
  1763. this.pdfThumbnailViewer.setDocument(null);
  1764. this.pdfViewer.setDocument(null);
  1765. this.pdfLinkService.setDocument(null);
  1766. this.pdfDocumentProperties.setDocument(null);
  1767. }
  1768. this.pdfLinkService.externalLinkEnabled = true;
  1769. this.store = null;
  1770. this.isInitialViewSet = false;
  1771. this.downloadComplete = false;
  1772. this.url = "";
  1773. this.baseUrl = "";
  1774. this._downloadUrl = "";
  1775. this.documentInfo = null;
  1776. this.metadata = null;
  1777. this._contentDispositionFilename = null;
  1778. this._contentLength = null;
  1779. this._saveInProgress = false;
  1780. this._docStats = null;
  1781. this._hasAnnotationEditors = false;
  1782. this._cancelIdleCallbacks();
  1783. promises.push(this.pdfScriptingManager.destroyPromise);
  1784. this.setTitle();
  1785. this.pdfSidebar.reset();
  1786. this.pdfOutlineViewer.reset();
  1787. this.pdfAttachmentViewer.reset();
  1788. this.pdfLayerViewer.reset();
  1789. this.pdfHistory?.reset();
  1790. this.findBar?.reset();
  1791. this.toolbar.reset();
  1792. this.secondaryToolbar.reset();
  1793. this._PDFBug?.cleanup();
  1794. await Promise.all(promises);
  1795. },
  1796. async open(file, args) {
  1797. if (this.pdfLoadingTask) {
  1798. await this.close();
  1799. }
  1800. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  1801. for (const key in workerParameters) {
  1802. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  1803. }
  1804. const parameters = Object.create(null);
  1805. if (typeof file === "string") {
  1806. this.setTitleUsingUrl(file, file);
  1807. parameters.url = file;
  1808. } else if (file && "byteLength" in file) {
  1809. parameters.data = file;
  1810. } else if (file.url && file.originalUrl) {
  1811. this.setTitleUsingUrl(file.originalUrl, file.url);
  1812. parameters.url = file.url;
  1813. }
  1814. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  1815. for (const key in apiParameters) {
  1816. let value = apiParameters[key];
  1817. if (key === "docBaseUrl" && !value) { }
  1818. parameters[key] = value;
  1819. }
  1820. if (args) {
  1821. for (const key in args) {
  1822. parameters[key] = args[key];
  1823. }
  1824. }
  1825. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  1826. this.pdfLoadingTask = loadingTask;
  1827. loadingTask.onPassword = (updateCallback, reason) => {
  1828. this.pdfLinkService.externalLinkEnabled = false;
  1829. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  1830. this.passwordPrompt.open();
  1831. };
  1832. loadingTask.onProgress = ({
  1833. loaded,
  1834. total
  1835. }) => {
  1836. this.progress(loaded / total);
  1837. };
  1838. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  1839. return loadingTask.promise.then(pdfDocument => {
  1840. this.load(pdfDocument);
  1841. }, reason => {
  1842. if (loadingTask !== this.pdfLoadingTask) {
  1843. return undefined;
  1844. }
  1845. let key = "loading_error";
  1846. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  1847. key = "invalid_file_error";
  1848. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  1849. key = "missing_file_error";
  1850. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  1851. key = "unexpected_response_error";
  1852. }
  1853. return this.l10n.get(key).then(msg => {
  1854. this._documentError(msg, {
  1855. message: reason?.message
  1856. });
  1857. throw reason;
  1858. });
  1859. });
  1860. },
  1861. _ensureDownloadComplete() {
  1862. if (this.pdfDocument && this.downloadComplete) {
  1863. return;
  1864. }
  1865. throw new Error("PDF document not downloaded.");
  1866. },
  1867. async download() {
  1868. const url = this._downloadUrl,
  1869. filename = this._docFilename;
  1870. try {
  1871. this._ensureDownloadComplete();
  1872. const data = await this.pdfDocument.getData();
  1873. const blob = new Blob([data], {
  1874. type: "application/pdf"
  1875. });
  1876. await this.downloadManager.download(blob, url, filename);
  1877. } catch (reason) {
  1878. await this.downloadManager.downloadUrl(url, filename);
  1879. }
  1880. },
  1881. async save() {
  1882. if (this._saveInProgress) {
  1883. return;
  1884. }
  1885. this._saveInProgress = true;
  1886. await this.pdfScriptingManager.dispatchWillSave();
  1887. const url = this._downloadUrl,
  1888. filename = this._docFilename;
  1889. try {
  1890. this._ensureDownloadComplete();
  1891. const data = await this.pdfDocument.saveDocument();
  1892. const blob = new Blob([data], {
  1893. type: "application/pdf"
  1894. });
  1895. await this.downloadManager.download(blob, url, filename);
  1896. } catch (reason) {
  1897. console.error(`Error when saving the document: ${reason.message}`);
  1898. await this.download();
  1899. } finally {
  1900. await this.pdfScriptingManager.dispatchDidSave();
  1901. this._saveInProgress = false;
  1902. }
  1903. if (this._hasAnnotationEditors) {
  1904. this.externalServices.reportTelemetry({
  1905. type: "editing",
  1906. data: {
  1907. type: "save"
  1908. }
  1909. });
  1910. }
  1911. },
  1912. downloadOrSave() {
  1913. if (this.pdfDocument?.annotationStorage.size > 0) {
  1914. this.save();
  1915. } else {
  1916. this.download();
  1917. }
  1918. },
  1919. fallback(featureId) {
  1920. this.externalServices.reportTelemetry({
  1921. type: "unsupportedFeature",
  1922. featureId
  1923. });
  1924. },
  1925. _documentError(message, moreInfo = null) {
  1926. this._unblockDocumentLoadEvent();
  1927. this._otherError(message, moreInfo);
  1928. this.eventBus.dispatch("documenterror", {
  1929. source: this,
  1930. message,
  1931. reason: moreInfo?.message ?? null
  1932. });
  1933. },
  1934. _otherError(message, moreInfo = null) {
  1935. const moreInfoText = [this.l10n.get("error_version_info", {
  1936. version: _pdfjsLib.version || "?",
  1937. build: _pdfjsLib.build || "?"
  1938. })];
  1939. if (moreInfo) {
  1940. moreInfoText.push(this.l10n.get("error_message", {
  1941. message: moreInfo.message
  1942. }));
  1943. if (moreInfo.stack) {
  1944. moreInfoText.push(this.l10n.get("error_stack", {
  1945. stack: moreInfo.stack
  1946. }));
  1947. } else {
  1948. if (moreInfo.filename) {
  1949. moreInfoText.push(this.l10n.get("error_file", {
  1950. file: moreInfo.filename
  1951. }));
  1952. }
  1953. if (moreInfo.lineNumber) {
  1954. moreInfoText.push(this.l10n.get("error_line", {
  1955. line: moreInfo.lineNumber
  1956. }));
  1957. }
  1958. }
  1959. }
  1960. const errorWrapperConfig = this.appConfig.errorWrapper;
  1961. const errorWrapper = errorWrapperConfig.container;
  1962. errorWrapper.hidden = false;
  1963. const errorMessage = errorWrapperConfig.errorMessage;
  1964. errorMessage.textContent = message;
  1965. const closeButton = errorWrapperConfig.closeButton;
  1966. closeButton.onclick = function () {
  1967. errorWrapper.hidden = true;
  1968. };
  1969. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1970. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1971. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1972. moreInfoButton.onclick = function () {
  1973. errorMoreInfo.hidden = false;
  1974. moreInfoButton.hidden = true;
  1975. lessInfoButton.hidden = false;
  1976. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1977. };
  1978. lessInfoButton.onclick = function () {
  1979. errorMoreInfo.hidden = true;
  1980. moreInfoButton.hidden = false;
  1981. lessInfoButton.hidden = true;
  1982. };
  1983. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1984. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1985. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1986. moreInfoButton.hidden = false;
  1987. lessInfoButton.hidden = true;
  1988. Promise.all(moreInfoText).then(parts => {
  1989. errorMoreInfo.value = parts.join("\n");
  1990. });
  1991. },
  1992. progress(level) {
  1993. if (this.downloadComplete) {
  1994. return;
  1995. }
  1996. const percent = Math.round(level * 100);
  1997. if (percent <= this.loadingBar.percent) {
  1998. return;
  1999. }
  2000. this.loadingBar.percent = percent;
  2001. const disableAutoFetch = this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch");
  2002. if (!disableAutoFetch || isNaN(percent)) {
  2003. return;
  2004. }
  2005. if (this.disableAutoFetchLoadingBarTimeout) {
  2006. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  2007. this.disableAutoFetchLoadingBarTimeout = null;
  2008. }
  2009. this.loadingBar.show();
  2010. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  2011. this.loadingBar.hide();
  2012. this.disableAutoFetchLoadingBarTimeout = null;
  2013. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  2014. },
  2015. load(pdfDocument) {
  2016. this.pdfDocument = pdfDocument;
  2017. pdfDocument.getDownloadInfo().then(({
  2018. length
  2019. }) => {
  2020. this._contentLength = length;
  2021. this.downloadComplete = true;
  2022. this.loadingBar.hide();
  2023. firstPagePromise.then(() => {
  2024. this.eventBus.dispatch("documentloaded", {
  2025. source: this
  2026. });
  2027. });
  2028. });
  2029. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () { });
  2030. const pageModePromise = pdfDocument.getPageMode().catch(function () { });
  2031. const openActionPromise = pdfDocument.getOpenAction().catch(function () { });
  2032. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  2033. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  2034. let baseDocumentUrl;
  2035. baseDocumentUrl = null;
  2036. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  2037. this.pdfDocumentProperties.setDocument(pdfDocument);
  2038. const pdfViewer = this.pdfViewer;
  2039. pdfViewer.setDocument(pdfDocument);
  2040. const {
  2041. firstPagePromise,
  2042. onePageRendered,
  2043. pagesPromise
  2044. } = pdfViewer;
  2045. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  2046. pdfThumbnailViewer.setDocument(pdfDocument);
  2047. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  2048. page: null,
  2049. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  2050. scrollLeft: "0",
  2051. scrollTop: "0",
  2052. rotation: null,
  2053. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  2054. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  2055. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  2056. }).catch(() => {
  2057. return Object.create(null);
  2058. });
  2059. firstPagePromise.then(pdfPage => {
  2060. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  2061. this._initializeAnnotationStorageCallbacks(pdfDocument);
  2062. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  2063. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  2064. this._initializePdfHistory({
  2065. fingerprint: pdfDocument.fingerprints[0],
  2066. viewOnLoad,
  2067. initialDest: openAction?.dest
  2068. });
  2069. const initialBookmark = this.initialBookmark;
  2070. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  2071. let hash = zoom ? `zoom=${zoom}` : null;
  2072. let rotation = null;
  2073. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  2074. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  2075. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  2076. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  2077. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  2078. rotation = parseInt(stored.rotation, 10);
  2079. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2080. sidebarView = stored.sidebarView | 0;
  2081. }
  2082. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  2083. scrollMode = stored.scrollMode | 0;
  2084. }
  2085. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2086. spreadMode = stored.spreadMode | 0;
  2087. }
  2088. }
  2089. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2090. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  2091. }
  2092. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2093. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  2094. spreadMode = modes.spreadMode;
  2095. }
  2096. this.setInitialView(hash, {
  2097. rotation,
  2098. sidebarView,
  2099. scrollMode,
  2100. spreadMode
  2101. });
  2102. this.eventBus.dispatch("documentinit", {
  2103. source: this
  2104. });
  2105. if (!this.isViewerEmbedded) {
  2106. pdfViewer.focus();
  2107. }
  2108. await Promise.race([pagesPromise, new Promise(resolve => {
  2109. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  2110. })]);
  2111. if (!initialBookmark && !hash) {
  2112. return;
  2113. }
  2114. if (pdfViewer.hasEqualPageSizes) {
  2115. return;
  2116. }
  2117. this.initialBookmark = initialBookmark;
  2118. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  2119. this.setInitialView(hash);
  2120. }).catch(() => {
  2121. this.setInitialView();
  2122. }).then(function () {
  2123. pdfViewer.update();
  2124. });
  2125. });
  2126. pagesPromise.then(() => {
  2127. this._unblockDocumentLoadEvent();
  2128. this._initializeAutoPrint(pdfDocument, openActionPromise);
  2129. }, reason => {
  2130. this.l10n.get("loading_error").then(msg => {
  2131. this._documentError(msg, {
  2132. message: reason?.message
  2133. });
  2134. });
  2135. });
  2136. onePageRendered.then(data => {
  2137. this.externalServices.reportTelemetry({
  2138. type: "pageInfo",
  2139. timestamp: data.timestamp
  2140. });
  2141. pdfDocument.getOutline().then(outline => {
  2142. if (pdfDocument !== this.pdfDocument) {
  2143. return;
  2144. }
  2145. this.pdfOutlineViewer.render({
  2146. outline,
  2147. pdfDocument
  2148. });
  2149. });
  2150. pdfDocument.getAttachments().then(attachments => {
  2151. if (pdfDocument !== this.pdfDocument) {
  2152. return;
  2153. }
  2154. this.pdfAttachmentViewer.render({
  2155. attachments
  2156. });
  2157. });
  2158. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  2159. if (pdfDocument !== this.pdfDocument) {
  2160. return;
  2161. }
  2162. this.pdfLayerViewer.render({
  2163. optionalContentConfig,
  2164. pdfDocument
  2165. });
  2166. });
  2167. if ("requestIdleCallback" in window) {
  2168. const callback = window.requestIdleCallback(() => {
  2169. this._collectTelemetry(pdfDocument);
  2170. this._idleCallbacks.delete(callback);
  2171. }, {
  2172. timeout: 1000
  2173. });
  2174. this._idleCallbacks.add(callback);
  2175. }
  2176. });
  2177. this._initializePageLabels(pdfDocument);
  2178. this._initializeMetadata(pdfDocument);
  2179. },
  2180. async _scriptingDocProperties(pdfDocument) {
  2181. if (!this.documentInfo) {
  2182. await new Promise(resolve => {
  2183. this.eventBus._on("metadataloaded", resolve, {
  2184. once: true
  2185. });
  2186. });
  2187. if (pdfDocument !== this.pdfDocument) {
  2188. return null;
  2189. }
  2190. }
  2191. if (!this._contentLength) {
  2192. await new Promise(resolve => {
  2193. this.eventBus._on("documentloaded", resolve, {
  2194. once: true
  2195. });
  2196. });
  2197. if (pdfDocument !== this.pdfDocument) {
  2198. return null;
  2199. }
  2200. }
  2201. return {
  2202. ...this.documentInfo,
  2203. baseURL: this.baseUrl,
  2204. filesize: this._contentLength,
  2205. filename: this._docFilename,
  2206. metadata: this.metadata?.getRaw(),
  2207. authors: this.metadata?.get("dc:creator"),
  2208. numPages: this.pagesCount,
  2209. URL: this.url
  2210. };
  2211. },
  2212. async _collectTelemetry(pdfDocument) {
  2213. const markInfo = await this.pdfDocument.getMarkInfo();
  2214. if (pdfDocument !== this.pdfDocument) {
  2215. return;
  2216. }
  2217. const tagged = markInfo?.Marked || false;
  2218. this.externalServices.reportTelemetry({
  2219. type: "tagged",
  2220. tagged
  2221. });
  2222. },
  2223. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  2224. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  2225. if (pdfDocument !== this.pdfDocument) {
  2226. return;
  2227. }
  2228. let triggerAutoPrint = false;
  2229. if (openAction?.action === "Print") {
  2230. triggerAutoPrint = true;
  2231. }
  2232. if (javaScript) {
  2233. javaScript.some(js => {
  2234. if (!js) {
  2235. return false;
  2236. }
  2237. console.warn("Warning: JavaScript support is not enabled");
  2238. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  2239. return true;
  2240. });
  2241. if (!triggerAutoPrint) {
  2242. for (const js of javaScript) {
  2243. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  2244. triggerAutoPrint = true;
  2245. break;
  2246. }
  2247. }
  2248. }
  2249. }
  2250. if (triggerAutoPrint) {
  2251. this.triggerPrinting();
  2252. }
  2253. },
  2254. async _initializeMetadata(pdfDocument) {
  2255. const {
  2256. info,
  2257. metadata,
  2258. contentDispositionFilename,
  2259. contentLength
  2260. } = await pdfDocument.getMetadata();
  2261. if (pdfDocument !== this.pdfDocument) {
  2262. return;
  2263. }
  2264. this.documentInfo = info;
  2265. this.metadata = metadata;
  2266. this._contentDispositionFilename ??= contentDispositionFilename;
  2267. this._contentLength ??= contentLength;
  2268. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"})`);
  2269. let pdfTitle = info.Title;
  2270. const metadataTitle = metadata?.get("dc:title");
  2271. if (metadataTitle) {
  2272. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  2273. pdfTitle = metadataTitle;
  2274. }
  2275. }
  2276. if (pdfTitle) {
  2277. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  2278. } else if (this._contentDispositionFilename) {
  2279. this.setTitle(this._contentDispositionFilename);
  2280. }
  2281. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  2282. if (pdfDocument.loadingParams.enableXfa) {
  2283. console.warn("Warning: XFA Foreground documents are not supported");
  2284. } else {
  2285. console.warn("Warning: XFA support is not enabled");
  2286. }
  2287. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  2288. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  2289. console.warn("Warning: Interactive form support is not enabled");
  2290. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  2291. }
  2292. if (info.IsSignaturesPresent) {
  2293. console.warn("Warning: Digital signatures validation is not supported");
  2294. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  2295. }
  2296. let versionId = "other";
  2297. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  2298. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  2299. }
  2300. let generatorId = "other";
  2301. if (info.Producer) {
  2302. const producer = info.Producer.toLowerCase();
  2303. KNOWN_GENERATORS.some(function (generator) {
  2304. if (!producer.includes(generator)) {
  2305. return false;
  2306. }
  2307. generatorId = generator.replace(/[ .-]/g, "_");
  2308. return true;
  2309. });
  2310. }
  2311. let formType = null;
  2312. if (info.IsXFAPresent) {
  2313. formType = "xfa";
  2314. } else if (info.IsAcroFormPresent) {
  2315. formType = "acroform";
  2316. }
  2317. this.externalServices.reportTelemetry({
  2318. type: "documentInfo",
  2319. version: versionId,
  2320. generator: generatorId,
  2321. formType
  2322. });
  2323. this.eventBus.dispatch("metadataloaded", {
  2324. source: this
  2325. });
  2326. },
  2327. async _initializePageLabels(pdfDocument) {
  2328. const labels = await pdfDocument.getPageLabels();
  2329. if (pdfDocument !== this.pdfDocument) {
  2330. return;
  2331. }
  2332. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  2333. return;
  2334. }
  2335. const numLabels = labels.length;
  2336. let standardLabels = 0,
  2337. emptyLabels = 0;
  2338. for (let i = 0; i < numLabels; i++) {
  2339. const label = labels[i];
  2340. if (label === (i + 1).toString()) {
  2341. standardLabels++;
  2342. } else if (label === "") {
  2343. emptyLabels++;
  2344. } else {
  2345. break;
  2346. }
  2347. }
  2348. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  2349. return;
  2350. }
  2351. const {
  2352. pdfViewer,
  2353. pdfThumbnailViewer,
  2354. toolbar
  2355. } = this;
  2356. pdfViewer.setPageLabels(labels);
  2357. pdfThumbnailViewer.setPageLabels(labels);
  2358. toolbar.setPagesCount(numLabels, true);
  2359. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2360. },
  2361. _initializePdfHistory({
  2362. fingerprint,
  2363. viewOnLoad,
  2364. initialDest = null
  2365. }) {
  2366. if (!this.pdfHistory) {
  2367. return;
  2368. }
  2369. this.pdfHistory.initialize({
  2370. fingerprint,
  2371. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  2372. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  2373. });
  2374. if (this.pdfHistory.initialBookmark) {
  2375. this.initialBookmark = this.pdfHistory.initialBookmark;
  2376. this.initialRotation = this.pdfHistory.initialRotation;
  2377. }
  2378. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  2379. this.initialBookmark = JSON.stringify(initialDest);
  2380. this.pdfHistory.push({
  2381. explicitDest: initialDest,
  2382. pageNumber: null
  2383. });
  2384. }
  2385. },
  2386. _initializeAnnotationStorageCallbacks(pdfDocument) {
  2387. if (pdfDocument !== this.pdfDocument) {
  2388. return;
  2389. }
  2390. const {
  2391. annotationStorage
  2392. } = pdfDocument;
  2393. annotationStorage.onSetModified = () => {
  2394. window.addEventListener("beforeunload", beforeUnload);
  2395. this._annotationStorageModified = true;
  2396. };
  2397. annotationStorage.onResetModified = () => {
  2398. window.removeEventListener("beforeunload", beforeUnload);
  2399. delete this._annotationStorageModified;
  2400. };
  2401. annotationStorage.onAnnotationEditor = typeStr => {
  2402. this._hasAnnotationEditors = !!typeStr;
  2403. this.setTitle();
  2404. if (typeStr) {
  2405. this.externalServices.reportTelemetry({
  2406. type: "editing",
  2407. data: {
  2408. type: typeStr
  2409. }
  2410. });
  2411. }
  2412. };
  2413. },
  2414. setInitialView(storedHash, {
  2415. rotation,
  2416. sidebarView,
  2417. scrollMode,
  2418. spreadMode
  2419. } = {}) {
  2420. const setRotation = angle => {
  2421. if ((0, _ui_utils.isValidRotation)(angle)) {
  2422. this.pdfViewer.pagesRotation = angle;
  2423. }
  2424. };
  2425. const setViewerModes = (scroll, spread) => {
  2426. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  2427. this.pdfViewer.scrollMode = scroll;
  2428. }
  2429. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  2430. this.pdfViewer.spreadMode = spread;
  2431. }
  2432. };
  2433. this.isInitialViewSet = true;
  2434. this.pdfSidebar.setInitialView(sidebarView);
  2435. setViewerModes(scrollMode, spreadMode);
  2436. if (this.initialBookmark) {
  2437. setRotation(this.initialRotation);
  2438. delete this.initialRotation;
  2439. this.pdfLinkService.setHash(this.initialBookmark);
  2440. this.initialBookmark = null;
  2441. } else if (storedHash) {
  2442. setRotation(rotation);
  2443. this.pdfLinkService.setHash(storedHash);
  2444. }
  2445. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  2446. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  2447. if (!this.pdfViewer.currentScaleValue) {
  2448. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2449. }
  2450. },
  2451. _cleanup() {
  2452. if (!this.pdfDocument) {
  2453. return;
  2454. }
  2455. this.pdfViewer.cleanup();
  2456. this.pdfThumbnailViewer.cleanup();
  2457. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  2458. },
  2459. forceRendering() {
  2460. this.pdfRenderingQueue.printing = !!this.printService;
  2461. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS;
  2462. this.pdfRenderingQueue.renderHighestPriority();
  2463. },
  2464. beforePrint() {
  2465. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => { }).then(() => {
  2466. return this.pdfDocument?.annotationStorage.print;
  2467. });
  2468. if (this.printService) {
  2469. return;
  2470. }
  2471. if (!this.supportsPrinting) {
  2472. this.l10n.get("printing_not_supported").then(msg => {
  2473. this._otherError(msg);
  2474. });
  2475. return;
  2476. }
  2477. if (!this.pdfViewer.pageViewsReady) {
  2478. this.l10n.get("printing_not_ready").then(msg => {
  2479. window.alert(msg);
  2480. });
  2481. return;
  2482. }
  2483. const pagesOverview = this.pdfViewer.getPagesOverview();
  2484. const printContainer = this.appConfig.printContainer;
  2485. const printResolution = _app_options.AppOptions.get("printResolution");
  2486. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  2487. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  2488. this.printService = printService;
  2489. this.forceRendering();
  2490. printService.layout();
  2491. this.externalServices.reportTelemetry({
  2492. type: "print"
  2493. });
  2494. if (this._hasAnnotationEditors) {
  2495. this.externalServices.reportTelemetry({
  2496. type: "editing",
  2497. data: {
  2498. type: "print"
  2499. }
  2500. });
  2501. }
  2502. },
  2503. afterPrint() {
  2504. if (this._printAnnotationStoragePromise) {
  2505. this._printAnnotationStoragePromise.then(() => {
  2506. this.pdfScriptingManager.dispatchDidPrint();
  2507. });
  2508. this._printAnnotationStoragePromise = null;
  2509. }
  2510. if (this.printService) {
  2511. this.printService.destroy();
  2512. this.printService = null;
  2513. this.pdfDocument?.annotationStorage.resetModified();
  2514. }
  2515. this.forceRendering();
  2516. },
  2517. rotatePages(delta) {
  2518. this.pdfViewer.pagesRotation += delta;
  2519. },
  2520. requestPresentationMode() {
  2521. this.pdfPresentationMode?.request();
  2522. },
  2523. triggerPrinting() {
  2524. if (!this.supportsPrinting) {
  2525. return;
  2526. }
  2527. window.print();
  2528. },
  2529. bindEvents() {
  2530. const {
  2531. eventBus,
  2532. _boundEvents
  2533. } = this;
  2534. _boundEvents.beforePrint = this.beforePrint.bind(this);
  2535. _boundEvents.afterPrint = this.afterPrint.bind(this);
  2536. eventBus._on("resize", webViewerResize);
  2537. eventBus._on("hashchange", webViewerHashchange);
  2538. eventBus._on("beforeprint", _boundEvents.beforePrint);
  2539. eventBus._on("afterprint", _boundEvents.afterPrint);
  2540. eventBus._on("pagerendered", webViewerPageRendered);
  2541. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  2542. eventBus._on("pagechanging", webViewerPageChanging);
  2543. eventBus._on("scalechanging", webViewerScaleChanging);
  2544. eventBus._on("rotationchanging", webViewerRotationChanging);
  2545. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  2546. eventBus._on("pagemode", webViewerPageMode);
  2547. eventBus._on("namedaction", webViewerNamedAction);
  2548. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  2549. eventBus._on("presentationmode", webViewerPresentationMode);
  2550. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  2551. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  2552. eventBus._on("print", webViewerPrint);
  2553. eventBus._on("download", webViewerDownload);
  2554. eventBus._on("firstpage", webViewerFirstPage);
  2555. eventBus._on("lastpage", webViewerLastPage);
  2556. eventBus._on("nextpage", webViewerNextPage);
  2557. eventBus._on("previouspage", webViewerPreviousPage);
  2558. eventBus._on("zoomin", webViewerZoomIn);
  2559. eventBus._on("zoomout", webViewerZoomOut);
  2560. eventBus._on("zoomreset", webViewerZoomReset);
  2561. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  2562. eventBus._on("scalechanged", webViewerScaleChanged);
  2563. eventBus._on("rotatecw", webViewerRotateCw);
  2564. eventBus._on("rotateccw", webViewerRotateCcw);
  2565. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  2566. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  2567. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  2568. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  2569. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  2570. eventBus._on("documentproperties", webViewerDocumentProperties);
  2571. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  2572. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2573. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  2574. if (_app_options.AppOptions.get("pdfBug")) {
  2575. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  2576. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2577. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2578. }
  2579. eventBus._on("fileinputchange", webViewerFileInputChange);
  2580. eventBus._on("openfile", webViewerOpenFile);
  2581. },
  2582. bindWindowEvents() {
  2583. const {
  2584. eventBus,
  2585. _boundEvents
  2586. } = this;
  2587. function addWindowResolutionChange(evt = null) {
  2588. if (evt) {
  2589. webViewerResolutionChange(evt);
  2590. }
  2591. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  2592. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  2593. once: true
  2594. });
  2595. _boundEvents.removeWindowResolutionChange ||= function () {
  2596. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  2597. _boundEvents.removeWindowResolutionChange = null;
  2598. };
  2599. }
  2600. addWindowResolutionChange();
  2601. _boundEvents.windowResize = () => {
  2602. eventBus.dispatch("resize", {
  2603. source: window
  2604. });
  2605. };
  2606. _boundEvents.windowHashChange = () => {
  2607. eventBus.dispatch("hashchange", {
  2608. source: window,
  2609. hash: document.location.hash.substring(1)
  2610. });
  2611. };
  2612. _boundEvents.windowBeforePrint = () => {
  2613. eventBus.dispatch("beforeprint", {
  2614. source: window
  2615. });
  2616. };
  2617. _boundEvents.windowAfterPrint = () => {
  2618. eventBus.dispatch("afterprint", {
  2619. source: window
  2620. });
  2621. };
  2622. _boundEvents.windowUpdateFromSandbox = event => {
  2623. eventBus.dispatch("updatefromsandbox", {
  2624. source: window,
  2625. detail: event.detail
  2626. });
  2627. };
  2628. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  2629. window.addEventListener("wheel", webViewerWheel, {
  2630. passive: false
  2631. });
  2632. window.addEventListener("touchstart", webViewerTouchStart, {
  2633. passive: false
  2634. });
  2635. window.addEventListener("click", webViewerClick);
  2636. window.addEventListener("keydown", webViewerKeyDown);
  2637. window.addEventListener("resize", _boundEvents.windowResize);
  2638. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  2639. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2640. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  2641. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2642. },
  2643. unbindEvents() {
  2644. const {
  2645. eventBus,
  2646. _boundEvents
  2647. } = this;
  2648. eventBus._off("resize", webViewerResize);
  2649. eventBus._off("hashchange", webViewerHashchange);
  2650. eventBus._off("beforeprint", _boundEvents.beforePrint);
  2651. eventBus._off("afterprint", _boundEvents.afterPrint);
  2652. eventBus._off("pagerendered", webViewerPageRendered);
  2653. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  2654. eventBus._off("pagechanging", webViewerPageChanging);
  2655. eventBus._off("scalechanging", webViewerScaleChanging);
  2656. eventBus._off("rotationchanging", webViewerRotationChanging);
  2657. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  2658. eventBus._off("pagemode", webViewerPageMode);
  2659. eventBus._off("namedaction", webViewerNamedAction);
  2660. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  2661. eventBus._off("presentationmode", webViewerPresentationMode);
  2662. eventBus._off("print", webViewerPrint);
  2663. eventBus._off("download", webViewerDownload);
  2664. eventBus._off("firstpage", webViewerFirstPage);
  2665. eventBus._off("lastpage", webViewerLastPage);
  2666. eventBus._off("nextpage", webViewerNextPage);
  2667. eventBus._off("previouspage", webViewerPreviousPage);
  2668. eventBus._off("zoomin", webViewerZoomIn);
  2669. eventBus._off("zoomout", webViewerZoomOut);
  2670. eventBus._off("zoomreset", webViewerZoomReset);
  2671. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  2672. eventBus._off("scalechanged", webViewerScaleChanged);
  2673. eventBus._off("rotatecw", webViewerRotateCw);
  2674. eventBus._off("rotateccw", webViewerRotateCcw);
  2675. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  2676. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  2677. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  2678. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  2679. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  2680. eventBus._off("documentproperties", webViewerDocumentProperties);
  2681. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  2682. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2683. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  2684. if (_boundEvents.reportPageStatsPDFBug) {
  2685. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2686. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2687. _boundEvents.reportPageStatsPDFBug = null;
  2688. }
  2689. eventBus._off("fileinputchange", webViewerFileInputChange);
  2690. eventBus._off("openfile", webViewerOpenFile);
  2691. _boundEvents.beforePrint = null;
  2692. _boundEvents.afterPrint = null;
  2693. },
  2694. unbindWindowEvents() {
  2695. const {
  2696. _boundEvents
  2697. } = this;
  2698. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  2699. window.removeEventListener("wheel", webViewerWheel, {
  2700. passive: false
  2701. });
  2702. window.removeEventListener("touchstart", webViewerTouchStart, {
  2703. passive: false
  2704. });
  2705. window.removeEventListener("click", webViewerClick);
  2706. window.removeEventListener("keydown", webViewerKeyDown);
  2707. window.removeEventListener("resize", _boundEvents.windowResize);
  2708. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  2709. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2710. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  2711. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2712. _boundEvents.removeWindowResolutionChange?.();
  2713. _boundEvents.windowResize = null;
  2714. _boundEvents.windowHashChange = null;
  2715. _boundEvents.windowBeforePrint = null;
  2716. _boundEvents.windowAfterPrint = null;
  2717. _boundEvents.windowUpdateFromSandbox = null;
  2718. },
  2719. accumulateWheelTicks(ticks) {
  2720. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  2721. this._wheelUnusedTicks = 0;
  2722. }
  2723. this._wheelUnusedTicks += ticks;
  2724. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  2725. this._wheelUnusedTicks -= wholeTicks;
  2726. return wholeTicks;
  2727. },
  2728. _unblockDocumentLoadEvent() {
  2729. document.blockUnblockOnload?.(false);
  2730. this._unblockDocumentLoadEvent = () => { };
  2731. },
  2732. _reportDocumentStatsTelemetry() {
  2733. const {
  2734. stats
  2735. } = this.pdfDocument;
  2736. if (stats !== this._docStats) {
  2737. this._docStats = stats;
  2738. this.externalServices.reportTelemetry({
  2739. type: "documentStats",
  2740. stats
  2741. });
  2742. }
  2743. },
  2744. get scriptingReady() {
  2745. return this.pdfScriptingManager.ready;
  2746. }
  2747. };
  2748. exports.PDFViewerApplication = PDFViewerApplication;
  2749. let validateFileURL;
  2750. {
  2751. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  2752. validateFileURL = function (file) {
  2753. if (!file) {
  2754. return;
  2755. }
  2756. try {
  2757. const viewerOrigin = new URL(window.location.href).origin || "null";
  2758. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  2759. return;
  2760. }
  2761. const fileOrigin = new URL(file, window.location.href).origin;
  2762. // if (fileOrigin !== viewerOrigin) {
  2763. // throw new Error("file origin does not match viewer's");
  2764. // }
  2765. } catch (ex) {
  2766. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2767. PDFViewerApplication._documentError(msg, {
  2768. message: ex?.message
  2769. });
  2770. });
  2771. throw ex;
  2772. }
  2773. };
  2774. }
  2775. async function loadFakeWorker() {
  2776. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  2777. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  2778. }
  2779. async function loadPDFBug(self) {
  2780. const {
  2781. debuggerScriptPath
  2782. } = self.appConfig;
  2783. const {
  2784. PDFBug
  2785. } = await import(debuggerScriptPath);
  2786. self._PDFBug = PDFBug;
  2787. }
  2788. function reportPageStatsPDFBug({
  2789. pageNumber
  2790. }) {
  2791. if (!globalThis.Stats?.enabled) {
  2792. return;
  2793. }
  2794. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2795. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  2796. }
  2797. function webViewerInitialized() {
  2798. const {
  2799. appConfig,
  2800. eventBus
  2801. } = PDFViewerApplication;
  2802. let file;
  2803. const queryString = document.location.search.substring(1);
  2804. const params = (0, _ui_utils.parseQueryString)(queryString);
  2805. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  2806. validateFileURL(file);
  2807. const fileInput = appConfig.openFileInput;
  2808. fileInput.value = null;
  2809. fileInput.addEventListener("change", function (evt) {
  2810. const {
  2811. files
  2812. } = evt.target;
  2813. if (!files || files.length === 0) {
  2814. return;
  2815. }
  2816. eventBus.dispatch("fileinputchange", {
  2817. source: this,
  2818. fileInput: evt.target
  2819. });
  2820. });
  2821. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  2822. evt.preventDefault();
  2823. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  2824. });
  2825. appConfig.mainContainer.addEventListener("drop", function (evt) {
  2826. evt.preventDefault();
  2827. const {
  2828. files
  2829. } = evt.dataTransfer;
  2830. if (!files || files.length === 0) {
  2831. return;
  2832. }
  2833. eventBus.dispatch("fileinputchange", {
  2834. source: this,
  2835. fileInput: evt.dataTransfer
  2836. });
  2837. });
  2838. if (!PDFViewerApplication.supportsDocumentFonts) {
  2839. _app_options.AppOptions.set("disableFontFace", true);
  2840. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  2841. console.warn(msg);
  2842. });
  2843. }
  2844. if (!PDFViewerApplication.supportsPrinting) {
  2845. appConfig.toolbar.print.classList.add("hidden");
  2846. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  2847. }
  2848. if (!PDFViewerApplication.supportsFullscreen) {
  2849. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  2850. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  2851. }
  2852. if (PDFViewerApplication.supportsIntegratedFind) {
  2853. appConfig.toolbar.viewFind.classList.add("hidden");
  2854. }
  2855. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  2856. if (evt.target === this) {
  2857. eventBus.dispatch("resize", {
  2858. source: this
  2859. });
  2860. }
  2861. }, true);
  2862. try {
  2863. if (file) {
  2864. PDFViewerApplication.open(file);
  2865. } else {
  2866. PDFViewerApplication._hideViewBookmark();
  2867. }
  2868. } catch (reason) {
  2869. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2870. PDFViewerApplication._documentError(msg, reason);
  2871. });
  2872. }
  2873. }
  2874. function webViewerPageRendered({
  2875. pageNumber,
  2876. error
  2877. }) {
  2878. if (pageNumber === PDFViewerApplication.page) {
  2879. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  2880. }
  2881. if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
  2882. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2883. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  2884. if (pageView && thumbnailView) {
  2885. thumbnailView.setImage(pageView);
  2886. }
  2887. }
  2888. if (error) {
  2889. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  2890. PDFViewerApplication._otherError(msg, error);
  2891. });
  2892. }
  2893. PDFViewerApplication._reportDocumentStatsTelemetry();
  2894. }
  2895. function webViewerPageMode({
  2896. mode
  2897. }) {
  2898. let view;
  2899. switch (mode) {
  2900. case "thumbs":
  2901. view = _ui_utils.SidebarView.THUMBS;
  2902. break;
  2903. case "bookmarks":
  2904. case "outline":
  2905. view = _ui_utils.SidebarView.OUTLINE;
  2906. break;
  2907. case "attachments":
  2908. view = _ui_utils.SidebarView.ATTACHMENTS;
  2909. break;
  2910. case "layers":
  2911. view = _ui_utils.SidebarView.LAYERS;
  2912. break;
  2913. case "none":
  2914. view = _ui_utils.SidebarView.NONE;
  2915. break;
  2916. default:
  2917. console.error('Invalid "pagemode" hash parameter: ' + mode);
  2918. return;
  2919. }
  2920. PDFViewerApplication.pdfSidebar.switchView(view, true);
  2921. }
  2922. function webViewerNamedAction(evt) {
  2923. switch (evt.action) {
  2924. case "GoToPage":
  2925. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2926. break;
  2927. case "Find":
  2928. if (!PDFViewerApplication.supportsIntegratedFind) {
  2929. PDFViewerApplication.findBar.toggle();
  2930. }
  2931. break;
  2932. case "Print":
  2933. PDFViewerApplication.triggerPrinting();
  2934. break;
  2935. case "SaveAs":
  2936. PDFViewerApplication.downloadOrSave();
  2937. break;
  2938. }
  2939. }
  2940. function webViewerPresentationModeChanged(evt) {
  2941. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  2942. }
  2943. function webViewerSidebarViewChanged({
  2944. view
  2945. }) {
  2946. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  2947. if (PDFViewerApplication.isInitialViewSet) {
  2948. PDFViewerApplication.store?.set("sidebarView", view).catch(() => { });
  2949. }
  2950. }
  2951. function webViewerUpdateViewarea({
  2952. location
  2953. }) {
  2954. if (PDFViewerApplication.isInitialViewSet) {
  2955. PDFViewerApplication.store?.setMultiple({
  2956. page: location.pageNumber,
  2957. zoom: location.scale,
  2958. scrollLeft: location.left,
  2959. scrollTop: location.top,
  2960. rotation: location.rotation
  2961. }).catch(() => { });
  2962. }
  2963. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  2964. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  2965. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  2966. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  2967. const loading = currentPage?.renderingState !== _ui_utils.RenderingStates.FINISHED;
  2968. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  2969. }
  2970. function webViewerScrollModeChanged(evt) {
  2971. if (PDFViewerApplication.isInitialViewSet) {
  2972. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => { });
  2973. }
  2974. }
  2975. function webViewerSpreadModeChanged(evt) {
  2976. if (PDFViewerApplication.isInitialViewSet) {
  2977. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => { });
  2978. }
  2979. }
  2980. function webViewerResize() {
  2981. const {
  2982. pdfDocument,
  2983. pdfViewer,
  2984. pdfRenderingQueue
  2985. } = PDFViewerApplication;
  2986. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  2987. return;
  2988. }
  2989. pdfViewer.updateContainerHeightCss();
  2990. if (!pdfDocument) {
  2991. return;
  2992. }
  2993. const currentScaleValue = pdfViewer.currentScaleValue;
  2994. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  2995. pdfViewer.currentScaleValue = currentScaleValue;
  2996. }
  2997. pdfViewer.update();
  2998. }
  2999. function webViewerHashchange(evt) {
  3000. const hash = evt.hash;
  3001. if (!hash) {
  3002. return;
  3003. }
  3004. if (!PDFViewerApplication.isInitialViewSet) {
  3005. PDFViewerApplication.initialBookmark = hash;
  3006. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  3007. PDFViewerApplication.pdfLinkService.setHash(hash);
  3008. }
  3009. }
  3010. {
  3011. var webViewerFileInputChange = function (evt) {
  3012. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  3013. return;
  3014. }
  3015. const file = evt.fileInput.files[0];
  3016. let url = URL.createObjectURL(file);
  3017. if (file.name) {
  3018. url = {
  3019. url,
  3020. originalUrl: file.name
  3021. };
  3022. }
  3023. PDFViewerApplication.open(url);
  3024. };
  3025. var webViewerOpenFile = function (evt) {
  3026. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  3027. fileInput.click();
  3028. };
  3029. }
  3030. function webViewerPresentationMode() {
  3031. PDFViewerApplication.requestPresentationMode();
  3032. }
  3033. function webViewerSwitchAnnotationEditorMode(evt) {
  3034. PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
  3035. }
  3036. function webViewerSwitchAnnotationEditorParams(evt) {
  3037. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  3038. }
  3039. function webViewerPrint() {
  3040. PDFViewerApplication.triggerPrinting();
  3041. }
  3042. function webViewerDownload() {
  3043. PDFViewerApplication.downloadOrSave();
  3044. }
  3045. function webViewerFirstPage() {
  3046. if (PDFViewerApplication.pdfDocument) {
  3047. PDFViewerApplication.page = 1;
  3048. }
  3049. }
  3050. function webViewerLastPage() {
  3051. if (PDFViewerApplication.pdfDocument) {
  3052. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3053. }
  3054. }
  3055. function webViewerNextPage() {
  3056. PDFViewerApplication.pdfViewer.nextPage();
  3057. }
  3058. function webViewerPreviousPage() {
  3059. PDFViewerApplication.pdfViewer.previousPage();
  3060. }
  3061. function webViewerZoomIn() {
  3062. PDFViewerApplication.zoomIn();
  3063. }
  3064. function webViewerZoomOut() {
  3065. PDFViewerApplication.zoomOut();
  3066. }
  3067. function webViewerZoomReset() {
  3068. PDFViewerApplication.zoomReset();
  3069. }
  3070. function webViewerPageNumberChanged(evt) {
  3071. const pdfViewer = PDFViewerApplication.pdfViewer;
  3072. if (evt.value !== "") {
  3073. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  3074. }
  3075. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  3076. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  3077. }
  3078. }
  3079. function webViewerScaleChanged(evt) {
  3080. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  3081. }
  3082. function webViewerRotateCw() {
  3083. PDFViewerApplication.rotatePages(90);
  3084. }
  3085. function webViewerRotateCcw() {
  3086. PDFViewerApplication.rotatePages(-90);
  3087. }
  3088. function webViewerOptionalContentConfig(evt) {
  3089. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  3090. }
  3091. function webViewerSwitchScrollMode(evt) {
  3092. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  3093. }
  3094. function webViewerSwitchSpreadMode(evt) {
  3095. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  3096. }
  3097. function webViewerDocumentProperties() {
  3098. PDFViewerApplication.pdfDocumentProperties.open();
  3099. }
  3100. function webViewerFindFromUrlHash(evt) {
  3101. PDFViewerApplication.eventBus.dispatch("find", {
  3102. source: evt.source,
  3103. type: "",
  3104. query: evt.query,
  3105. phraseSearch: evt.phraseSearch,
  3106. caseSensitive: false,
  3107. entireWord: false,
  3108. highlightAll: true,
  3109. findPrevious: false,
  3110. matchDiacritics: true
  3111. });
  3112. }
  3113. function webViewerUpdateFindMatchesCount({
  3114. matchesCount
  3115. }) {
  3116. if (PDFViewerApplication.supportsIntegratedFind) {
  3117. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  3118. } else {
  3119. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  3120. }
  3121. }
  3122. function webViewerUpdateFindControlState({
  3123. state,
  3124. previous,
  3125. matchesCount,
  3126. rawQuery
  3127. }) {
  3128. if (PDFViewerApplication.supportsIntegratedFind) {
  3129. PDFViewerApplication.externalServices.updateFindControlState({
  3130. result: state,
  3131. findPrevious: previous,
  3132. matchesCount,
  3133. rawQuery
  3134. });
  3135. } else {
  3136. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  3137. }
  3138. }
  3139. function webViewerScaleChanging(evt) {
  3140. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  3141. PDFViewerApplication.pdfViewer.update();
  3142. }
  3143. function webViewerRotationChanging(evt) {
  3144. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  3145. PDFViewerApplication.forceRendering();
  3146. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  3147. }
  3148. function webViewerPageChanging({
  3149. pageNumber,
  3150. pageLabel
  3151. }) {
  3152. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  3153. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  3154. if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
  3155. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  3156. }
  3157. }
  3158. function webViewerResolutionChange(evt) {
  3159. PDFViewerApplication.pdfViewer.refresh();
  3160. }
  3161. function webViewerVisibilityChange(evt) {
  3162. if (document.visibilityState === "visible") {
  3163. setZoomDisabledTimeout();
  3164. }
  3165. }
  3166. let zoomDisabledTimeout = null;
  3167. function setZoomDisabledTimeout() {
  3168. if (zoomDisabledTimeout) {
  3169. clearTimeout(zoomDisabledTimeout);
  3170. }
  3171. zoomDisabledTimeout = setTimeout(function () {
  3172. zoomDisabledTimeout = null;
  3173. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  3174. }
  3175. function webViewerWheel(evt) {
  3176. const {
  3177. pdfViewer,
  3178. supportedMouseWheelZoomModifierKeys
  3179. } = PDFViewerApplication;
  3180. if (pdfViewer.isInPresentationMode) {
  3181. return;
  3182. }
  3183. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  3184. evt.preventDefault();
  3185. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  3186. return;
  3187. }
  3188. const deltaMode = evt.deltaMode;
  3189. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  3190. const previousScale = pdfViewer.currentScale;
  3191. let ticks = 0;
  3192. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  3193. if (Math.abs(delta) >= 1) {
  3194. ticks = Math.sign(delta);
  3195. } else {
  3196. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  3197. }
  3198. } else {
  3199. const PIXELS_PER_LINE_SCALE = 30;
  3200. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  3201. }
  3202. if (ticks < 0) {
  3203. PDFViewerApplication.zoomOut(-ticks);
  3204. } else if (ticks > 0) {
  3205. PDFViewerApplication.zoomIn(ticks);
  3206. }
  3207. const currentScale = pdfViewer.currentScale;
  3208. if (previousScale !== currentScale) {
  3209. const scaleCorrectionFactor = currentScale / previousScale - 1;
  3210. const rect = pdfViewer.container.getBoundingClientRect();
  3211. const dx = evt.clientX - rect.left;
  3212. const dy = evt.clientY - rect.top;
  3213. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  3214. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  3215. }
  3216. } else {
  3217. setZoomDisabledTimeout();
  3218. }
  3219. }
  3220. function webViewerTouchStart(evt) {
  3221. if (evt.touches.length > 1) {
  3222. evt.preventDefault();
  3223. }
  3224. }
  3225. function webViewerClick(evt) {
  3226. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  3227. return;
  3228. }
  3229. const appConfig = PDFViewerApplication.appConfig;
  3230. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  3231. PDFViewerApplication.secondaryToolbar.close();
  3232. }
  3233. }
  3234. function webViewerKeyDown(evt) {
  3235. if (PDFViewerApplication.overlayManager.active) {
  3236. return;
  3237. }
  3238. const {
  3239. eventBus,
  3240. pdfViewer
  3241. } = PDFViewerApplication;
  3242. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  3243. let handled = false,
  3244. ensureViewerFocused = false;
  3245. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  3246. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  3247. switch (evt.keyCode) {
  3248. case 70:
  3249. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  3250. PDFViewerApplication.findBar.open();
  3251. handled = true;
  3252. }
  3253. break;
  3254. case 71:
  3255. if (!PDFViewerApplication.supportsIntegratedFind) {
  3256. const {
  3257. state
  3258. } = PDFViewerApplication.findController;
  3259. if (state) {
  3260. const eventState = Object.assign(Object.create(null), state, {
  3261. source: window,
  3262. type: "again",
  3263. findPrevious: cmd === 5 || cmd === 12
  3264. });
  3265. eventBus.dispatch("find", eventState);
  3266. }
  3267. handled = true;
  3268. }
  3269. break;
  3270. case 61:
  3271. case 107:
  3272. case 187:
  3273. case 171:
  3274. if (!isViewerInPresentationMode) {
  3275. PDFViewerApplication.zoomIn();
  3276. }
  3277. handled = true;
  3278. break;
  3279. case 173:
  3280. case 109:
  3281. case 189:
  3282. if (!isViewerInPresentationMode) {
  3283. PDFViewerApplication.zoomOut();
  3284. }
  3285. handled = true;
  3286. break;
  3287. case 48:
  3288. case 96:
  3289. if (!isViewerInPresentationMode) {
  3290. setTimeout(function () {
  3291. PDFViewerApplication.zoomReset();
  3292. });
  3293. handled = false;
  3294. }
  3295. break;
  3296. case 38:
  3297. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3298. PDFViewerApplication.page = 1;
  3299. handled = true;
  3300. ensureViewerFocused = true;
  3301. }
  3302. break;
  3303. case 40:
  3304. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3305. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3306. handled = true;
  3307. ensureViewerFocused = true;
  3308. }
  3309. break;
  3310. }
  3311. }
  3312. if (cmd === 1 || cmd === 8) {
  3313. switch (evt.keyCode) {
  3314. case 83:
  3315. eventBus.dispatch("download", {
  3316. source: window
  3317. });
  3318. handled = true;
  3319. break;
  3320. case 79:
  3321. {
  3322. eventBus.dispatch("openfile", {
  3323. source: window
  3324. });
  3325. handled = true;
  3326. }
  3327. break;
  3328. }
  3329. }
  3330. if (cmd === 3 || cmd === 10) {
  3331. switch (evt.keyCode) {
  3332. case 80:
  3333. PDFViewerApplication.requestPresentationMode();
  3334. handled = true;
  3335. break;
  3336. case 71:
  3337. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  3338. handled = true;
  3339. break;
  3340. }
  3341. }
  3342. if (handled) {
  3343. if (ensureViewerFocused && !isViewerInPresentationMode) {
  3344. pdfViewer.focus();
  3345. }
  3346. evt.preventDefault();
  3347. return;
  3348. }
  3349. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  3350. const curElementTagName = curElement?.tagName.toUpperCase();
  3351. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  3352. if (evt.keyCode !== 27) {
  3353. return;
  3354. }
  3355. }
  3356. if (cmd === 0) {
  3357. let turnPage = 0,
  3358. turnOnlyIfPageFit = false;
  3359. switch (evt.keyCode) {
  3360. case 38:
  3361. case 33:
  3362. if (pdfViewer.isVerticalScrollbarEnabled) {
  3363. turnOnlyIfPageFit = true;
  3364. }
  3365. turnPage = -1;
  3366. break;
  3367. case 8:
  3368. if (!isViewerInPresentationMode) {
  3369. turnOnlyIfPageFit = true;
  3370. }
  3371. turnPage = -1;
  3372. break;
  3373. case 37:
  3374. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3375. turnOnlyIfPageFit = true;
  3376. }
  3377. case 75:
  3378. case 80:
  3379. turnPage = -1;
  3380. break;
  3381. case 27:
  3382. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  3383. PDFViewerApplication.secondaryToolbar.close();
  3384. handled = true;
  3385. }
  3386. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  3387. PDFViewerApplication.findBar.close();
  3388. handled = true;
  3389. }
  3390. break;
  3391. case 40:
  3392. case 34:
  3393. if (pdfViewer.isVerticalScrollbarEnabled) {
  3394. turnOnlyIfPageFit = true;
  3395. }
  3396. turnPage = 1;
  3397. break;
  3398. case 13:
  3399. case 32:
  3400. if (!isViewerInPresentationMode) {
  3401. turnOnlyIfPageFit = true;
  3402. }
  3403. turnPage = 1;
  3404. break;
  3405. case 39:
  3406. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3407. turnOnlyIfPageFit = true;
  3408. }
  3409. case 74:
  3410. case 78:
  3411. turnPage = 1;
  3412. break;
  3413. case 36:
  3414. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3415. PDFViewerApplication.page = 1;
  3416. handled = true;
  3417. ensureViewerFocused = true;
  3418. }
  3419. break;
  3420. case 35:
  3421. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3422. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3423. handled = true;
  3424. ensureViewerFocused = true;
  3425. }
  3426. break;
  3427. case 83:
  3428. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  3429. break;
  3430. case 72:
  3431. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  3432. break;
  3433. case 82:
  3434. PDFViewerApplication.rotatePages(90);
  3435. break;
  3436. case 115:
  3437. PDFViewerApplication.pdfSidebar.toggle();
  3438. break;
  3439. }
  3440. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  3441. if (turnPage > 0) {
  3442. pdfViewer.nextPage();
  3443. } else {
  3444. pdfViewer.previousPage();
  3445. }
  3446. handled = true;
  3447. }
  3448. }
  3449. if (cmd === 4) {
  3450. switch (evt.keyCode) {
  3451. case 13:
  3452. case 32:
  3453. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  3454. break;
  3455. }
  3456. pdfViewer.previousPage();
  3457. handled = true;
  3458. break;
  3459. case 82:
  3460. PDFViewerApplication.rotatePages(-90);
  3461. break;
  3462. }
  3463. }
  3464. if (!handled && !isViewerInPresentationMode) {
  3465. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  3466. ensureViewerFocused = true;
  3467. }
  3468. }
  3469. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  3470. pdfViewer.focus();
  3471. }
  3472. if (handled) {
  3473. evt.preventDefault();
  3474. }
  3475. }
  3476. function beforeUnload(evt) {
  3477. evt.preventDefault();
  3478. evt.returnValue = "";
  3479. return false;
  3480. }
  3481. function webViewerAnnotationEditorStatesChanged(data) {
  3482. PDFViewerApplication.externalServices.updateEditorStates(data);
  3483. }
  3484. const PDFPrintServiceFactory = {
  3485. instance: {
  3486. supportsPrinting: false,
  3487. createPrintService() {
  3488. throw new Error("Not implemented: createPrintService");
  3489. }
  3490. }
  3491. };
  3492. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  3493. /***/
  3494. }),
  3495. /* 5 */
  3496. /***/ ((module) => {
  3497. let pdfjsLib;
  3498. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3499. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3500. } else {
  3501. pdfjsLib = require("../build/pdf.js");
  3502. }
  3503. module.exports = pdfjsLib;
  3504. /***/
  3505. }),
  3506. /* 6 */
  3507. /***/ ((__unused_webpack_module, exports) => {
  3508. Object.defineProperty(exports, "__esModule", ({
  3509. value: true
  3510. }));
  3511. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3512. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3513. const WaitOnType = {
  3514. EVENT: "event",
  3515. TIMEOUT: "timeout"
  3516. };
  3517. exports.WaitOnType = WaitOnType;
  3518. function waitOnEventOrTimeout({
  3519. target,
  3520. name,
  3521. delay = 0
  3522. }) {
  3523. return new Promise(function (resolve, reject) {
  3524. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3525. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3526. }
  3527. function handler(type) {
  3528. if (target instanceof EventBus) {
  3529. target._off(name, eventHandler);
  3530. } else {
  3531. target.removeEventListener(name, eventHandler);
  3532. }
  3533. if (timeout) {
  3534. clearTimeout(timeout);
  3535. }
  3536. resolve(type);
  3537. }
  3538. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3539. if (target instanceof EventBus) {
  3540. target._on(name, eventHandler);
  3541. } else {
  3542. target.addEventListener(name, eventHandler);
  3543. }
  3544. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3545. const timeout = setTimeout(timeoutHandler, delay);
  3546. });
  3547. }
  3548. class EventBus {
  3549. constructor() {
  3550. this._listeners = Object.create(null);
  3551. }
  3552. on(eventName, listener, options = null) {
  3553. this._on(eventName, listener, {
  3554. external: true,
  3555. once: options?.once
  3556. });
  3557. }
  3558. off(eventName, listener, options = null) {
  3559. this._off(eventName, listener, {
  3560. external: true,
  3561. once: options?.once
  3562. });
  3563. }
  3564. dispatch(eventName, data) {
  3565. const eventListeners = this._listeners[eventName];
  3566. if (!eventListeners || eventListeners.length === 0) {
  3567. return;
  3568. }
  3569. let externalListeners;
  3570. for (const {
  3571. listener,
  3572. external,
  3573. once
  3574. } of eventListeners.slice(0)) {
  3575. if (once) {
  3576. this._off(eventName, listener);
  3577. }
  3578. if (external) {
  3579. (externalListeners ||= []).push(listener);
  3580. continue;
  3581. }
  3582. listener(data);
  3583. }
  3584. if (externalListeners) {
  3585. for (const listener of externalListeners) {
  3586. listener(data);
  3587. }
  3588. externalListeners = null;
  3589. }
  3590. }
  3591. _on(eventName, listener, options = null) {
  3592. const eventListeners = this._listeners[eventName] ||= [];
  3593. eventListeners.push({
  3594. listener,
  3595. external: options?.external === true,
  3596. once: options?.once === true
  3597. });
  3598. }
  3599. _off(eventName, listener, options = null) {
  3600. const eventListeners = this._listeners[eventName];
  3601. if (!eventListeners) {
  3602. return;
  3603. }
  3604. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3605. if (eventListeners[i].listener === listener) {
  3606. eventListeners.splice(i, 1);
  3607. return;
  3608. }
  3609. }
  3610. }
  3611. }
  3612. exports.EventBus = EventBus;
  3613. class AutomationEventBus extends EventBus {
  3614. dispatch(eventName, data) {
  3615. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3616. }
  3617. }
  3618. exports.AutomationEventBus = AutomationEventBus;
  3619. /***/
  3620. }),
  3621. /* 7 */
  3622. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3623. Object.defineProperty(exports, "__esModule", ({
  3624. value: true
  3625. }));
  3626. exports.PDFCursorTools = exports.CursorTool = void 0;
  3627. var _grab_to_pan = __webpack_require__(8);
  3628. var _ui_utils = __webpack_require__(1);
  3629. const CursorTool = {
  3630. SELECT: 0,
  3631. HAND: 1,
  3632. ZOOM: 2
  3633. };
  3634. exports.CursorTool = CursorTool;
  3635. class PDFCursorTools {
  3636. constructor({
  3637. container,
  3638. eventBus,
  3639. cursorToolOnLoad = CursorTool.SELECT
  3640. }) {
  3641. this.container = container;
  3642. this.eventBus = eventBus;
  3643. this.active = CursorTool.SELECT;
  3644. this.activeBeforePresentationMode = null;
  3645. this.handTool = new _grab_to_pan.GrabToPan({
  3646. element: this.container
  3647. });
  3648. this.#addEventListeners();
  3649. Promise.resolve().then(() => {
  3650. this.switchTool(cursorToolOnLoad);
  3651. });
  3652. }
  3653. get activeTool() {
  3654. return this.active;
  3655. }
  3656. switchTool(tool) {
  3657. if (this.activeBeforePresentationMode !== null) {
  3658. return;
  3659. }
  3660. if (tool === this.active) {
  3661. return;
  3662. }
  3663. const disableActiveTool = () => {
  3664. switch (this.active) {
  3665. case CursorTool.SELECT:
  3666. break;
  3667. case CursorTool.HAND:
  3668. this.handTool.deactivate();
  3669. break;
  3670. case CursorTool.ZOOM:
  3671. }
  3672. };
  3673. switch (tool) {
  3674. case CursorTool.SELECT:
  3675. disableActiveTool();
  3676. break;
  3677. case CursorTool.HAND:
  3678. disableActiveTool();
  3679. this.handTool.activate();
  3680. break;
  3681. case CursorTool.ZOOM:
  3682. default:
  3683. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3684. return;
  3685. }
  3686. this.active = tool;
  3687. this.#dispatchEvent();
  3688. }
  3689. #dispatchEvent() {
  3690. this.eventBus.dispatch("cursortoolchanged", {
  3691. source: this,
  3692. tool: this.active
  3693. });
  3694. }
  3695. #addEventListeners() {
  3696. this.eventBus._on("switchcursortool", evt => {
  3697. this.switchTool(evt.tool);
  3698. });
  3699. this.eventBus._on("presentationmodechanged", evt => {
  3700. switch (evt.state) {
  3701. case _ui_utils.PresentationModeState.FULLSCREEN:
  3702. {
  3703. const previouslyActive = this.active;
  3704. this.switchTool(CursorTool.SELECT);
  3705. this.activeBeforePresentationMode = previouslyActive;
  3706. break;
  3707. }
  3708. case _ui_utils.PresentationModeState.NORMAL:
  3709. {
  3710. const previouslyActive = this.activeBeforePresentationMode;
  3711. this.activeBeforePresentationMode = null;
  3712. this.switchTool(previouslyActive);
  3713. break;
  3714. }
  3715. }
  3716. });
  3717. }
  3718. }
  3719. exports.PDFCursorTools = PDFCursorTools;
  3720. /***/
  3721. }),
  3722. /* 8 */
  3723. /***/ ((__unused_webpack_module, exports) => {
  3724. Object.defineProperty(exports, "__esModule", ({
  3725. value: true
  3726. }));
  3727. exports.GrabToPan = void 0;
  3728. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3729. class GrabToPan {
  3730. constructor(options) {
  3731. this.element = options.element;
  3732. this.document = options.element.ownerDocument;
  3733. if (typeof options.ignoreTarget === "function") {
  3734. this.ignoreTarget = options.ignoreTarget;
  3735. }
  3736. this.onActiveChanged = options.onActiveChanged;
  3737. this.activate = this.activate.bind(this);
  3738. this.deactivate = this.deactivate.bind(this);
  3739. this.toggle = this.toggle.bind(this);
  3740. this._onMouseDown = this.#onMouseDown.bind(this);
  3741. this._onMouseMove = this.#onMouseMove.bind(this);
  3742. this._endPan = this.#endPan.bind(this);
  3743. const overlay = this.overlay = document.createElement("div");
  3744. overlay.className = "grab-to-pan-grabbing";
  3745. }
  3746. activate() {
  3747. if (!this.active) {
  3748. this.active = true;
  3749. this.element.addEventListener("mousedown", this._onMouseDown, true);
  3750. this.element.classList.add(CSS_CLASS_GRAB);
  3751. this.onActiveChanged?.(true);
  3752. }
  3753. }
  3754. deactivate() {
  3755. if (this.active) {
  3756. this.active = false;
  3757. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  3758. this._endPan();
  3759. this.element.classList.remove(CSS_CLASS_GRAB);
  3760. this.onActiveChanged?.(false);
  3761. }
  3762. }
  3763. toggle() {
  3764. if (this.active) {
  3765. this.deactivate();
  3766. } else {
  3767. this.activate();
  3768. }
  3769. }
  3770. ignoreTarget(node) {
  3771. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3772. }
  3773. #onMouseDown(event) {
  3774. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3775. return;
  3776. }
  3777. if (event.originalTarget) {
  3778. try {
  3779. event.originalTarget.tagName;
  3780. } catch (e) {
  3781. return;
  3782. }
  3783. }
  3784. this.scrollLeftStart = this.element.scrollLeft;
  3785. this.scrollTopStart = this.element.scrollTop;
  3786. this.clientXStart = event.clientX;
  3787. this.clientYStart = event.clientY;
  3788. this.document.addEventListener("mousemove", this._onMouseMove, true);
  3789. this.document.addEventListener("mouseup", this._endPan, true);
  3790. this.element.addEventListener("scroll", this._endPan, true);
  3791. event.preventDefault();
  3792. event.stopPropagation();
  3793. const focusedElement = document.activeElement;
  3794. if (focusedElement && !focusedElement.contains(event.target)) {
  3795. focusedElement.blur();
  3796. }
  3797. }
  3798. #onMouseMove(event) {
  3799. this.element.removeEventListener("scroll", this._endPan, true);
  3800. if (!(event.buttons & 1)) {
  3801. this._endPan();
  3802. return;
  3803. }
  3804. const xDiff = event.clientX - this.clientXStart;
  3805. const yDiff = event.clientY - this.clientYStart;
  3806. const scrollTop = this.scrollTopStart - yDiff;
  3807. const scrollLeft = this.scrollLeftStart - xDiff;
  3808. if (this.element.scrollTo) {
  3809. this.element.scrollTo({
  3810. top: scrollTop,
  3811. left: scrollLeft,
  3812. behavior: "instant"
  3813. });
  3814. } else {
  3815. this.element.scrollTop = scrollTop;
  3816. this.element.scrollLeft = scrollLeft;
  3817. }
  3818. if (!this.overlay.parentNode) {
  3819. document.body.append(this.overlay);
  3820. }
  3821. }
  3822. #endPan() {
  3823. this.element.removeEventListener("scroll", this._endPan, true);
  3824. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  3825. this.document.removeEventListener("mouseup", this._endPan, true);
  3826. this.overlay.remove();
  3827. }
  3828. }
  3829. exports.GrabToPan = GrabToPan;
  3830. /***/
  3831. }),
  3832. /* 9 */
  3833. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3834. Object.defineProperty(exports, "__esModule", ({
  3835. value: true
  3836. }));
  3837. exports.AnnotationEditorParams = void 0;
  3838. var _pdfjsLib = __webpack_require__(5);
  3839. class AnnotationEditorParams {
  3840. constructor(options, eventBus) {
  3841. this.eventBus = eventBus;
  3842. this.#bindListeners(options);
  3843. }
  3844. #bindListeners({
  3845. editorFreeTextFontSize,
  3846. editorFreeTextColor,
  3847. editorInkColor,
  3848. editorInkThickness,
  3849. editorInkOpacity
  3850. }) {
  3851. editorFreeTextFontSize.addEventListener("input", evt => {
  3852. this.eventBus.dispatch("switchannotationeditorparams", {
  3853. source: this,
  3854. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE,
  3855. value: editorFreeTextFontSize.valueAsNumber
  3856. });
  3857. });
  3858. editorFreeTextColor.addEventListener("input", evt => {
  3859. this.eventBus.dispatch("switchannotationeditorparams", {
  3860. source: this,
  3861. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR,
  3862. value: editorFreeTextColor.value
  3863. });
  3864. });
  3865. editorInkColor.addEventListener("input", evt => {
  3866. this.eventBus.dispatch("switchannotationeditorparams", {
  3867. source: this,
  3868. type: _pdfjsLib.AnnotationEditorParamsType.INK_COLOR,
  3869. value: editorInkColor.value
  3870. });
  3871. });
  3872. editorInkThickness.addEventListener("input", evt => {
  3873. this.eventBus.dispatch("switchannotationeditorparams", {
  3874. source: this,
  3875. type: _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS,
  3876. value: editorInkThickness.valueAsNumber
  3877. });
  3878. });
  3879. editorInkOpacity.addEventListener("input", evt => {
  3880. this.eventBus.dispatch("switchannotationeditorparams", {
  3881. source: this,
  3882. type: _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY,
  3883. value: editorInkOpacity.valueAsNumber
  3884. });
  3885. });
  3886. this.eventBus._on("annotationeditorparamschanged", evt => {
  3887. for (const [type, value] of evt.details) {
  3888. switch (type) {
  3889. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  3890. editorFreeTextFontSize.value = value;
  3891. break;
  3892. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  3893. editorFreeTextColor.value = value;
  3894. break;
  3895. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  3896. editorInkColor.value = value;
  3897. break;
  3898. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  3899. editorInkThickness.value = value;
  3900. break;
  3901. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  3902. editorInkOpacity.value = value;
  3903. break;
  3904. }
  3905. }
  3906. });
  3907. }
  3908. }
  3909. exports.AnnotationEditorParams = AnnotationEditorParams;
  3910. /***/
  3911. }),
  3912. /* 10 */
  3913. /***/ ((__unused_webpack_module, exports) => {
  3914. Object.defineProperty(exports, "__esModule", ({
  3915. value: true
  3916. }));
  3917. exports.OverlayManager = void 0;
  3918. class OverlayManager {
  3919. #overlays = new WeakMap();
  3920. #active = null;
  3921. get active() {
  3922. return this.#active;
  3923. }
  3924. async register(dialog, canForceClose = false) {
  3925. if (typeof dialog !== "object") {
  3926. throw new Error("Not enough parameters.");
  3927. } else if (this.#overlays.has(dialog)) {
  3928. throw new Error("The overlay is already registered.");
  3929. }
  3930. this.#overlays.set(dialog, {
  3931. canForceClose
  3932. });
  3933. dialog.addEventListener("cancel", evt => {
  3934. this.#active = null;
  3935. });
  3936. }
  3937. async unregister(dialog) {
  3938. if (!this.#overlays.has(dialog)) {
  3939. throw new Error("The overlay does not exist.");
  3940. } else if (this.#active === dialog) {
  3941. throw new Error("The overlay cannot be removed while it is active.");
  3942. }
  3943. this.#overlays.delete(dialog);
  3944. }
  3945. async open(dialog) {
  3946. if (!this.#overlays.has(dialog)) {
  3947. throw new Error("The overlay does not exist.");
  3948. } else if (this.#active) {
  3949. if (this.#active === dialog) {
  3950. throw new Error("The overlay is already active.");
  3951. } else if (this.#overlays.get(dialog).canForceClose) {
  3952. await this.close();
  3953. } else {
  3954. throw new Error("Another overlay is currently active.");
  3955. }
  3956. }
  3957. this.#active = dialog;
  3958. dialog.showModal();
  3959. }
  3960. async close(dialog = this.#active) {
  3961. if (!this.#overlays.has(dialog)) {
  3962. throw new Error("The overlay does not exist.");
  3963. } else if (!this.#active) {
  3964. throw new Error("The overlay is currently not active.");
  3965. } else if (this.#active !== dialog) {
  3966. throw new Error("Another overlay is currently active.");
  3967. }
  3968. dialog.close();
  3969. this.#active = null;
  3970. }
  3971. }
  3972. exports.OverlayManager = OverlayManager;
  3973. /***/
  3974. }),
  3975. /* 11 */
  3976. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3977. Object.defineProperty(exports, "__esModule", ({
  3978. value: true
  3979. }));
  3980. exports.PasswordPrompt = void 0;
  3981. var _pdfjsLib = __webpack_require__(5);
  3982. class PasswordPrompt {
  3983. #activeCapability = null;
  3984. #updateCallback = null;
  3985. #reason = null;
  3986. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3987. this.dialog = options.dialog;
  3988. this.label = options.label;
  3989. this.input = options.input;
  3990. this.submitButton = options.submitButton;
  3991. this.cancelButton = options.cancelButton;
  3992. this.overlayManager = overlayManager;
  3993. this.l10n = l10n;
  3994. this._isViewerEmbedded = isViewerEmbedded;
  3995. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3996. this.cancelButton.addEventListener("click", this.close.bind(this));
  3997. this.input.addEventListener("keydown", e => {
  3998. if (e.keyCode === 13) {
  3999. this.#verify();
  4000. }
  4001. });
  4002. this.overlayManager.register(this.dialog, true);
  4003. this.dialog.addEventListener("close", this.#cancel.bind(this));
  4004. }
  4005. async open() {
  4006. if (this.#activeCapability) {
  4007. await this.#activeCapability.promise;
  4008. }
  4009. this.#activeCapability = (0, _pdfjsLib.createPromiseCapability)();
  4010. try {
  4011. await this.overlayManager.open(this.dialog);
  4012. } catch (ex) {
  4013. this.#activeCapability = null;
  4014. throw ex;
  4015. }
  4016. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  4017. if (!this._isViewerEmbedded || passwordIncorrect) {
  4018. this.input.focus();
  4019. }
  4020. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  4021. }
  4022. async close() {
  4023. if (this.overlayManager.active === this.dialog) {
  4024. this.overlayManager.close(this.dialog);
  4025. }
  4026. }
  4027. #verify() {
  4028. const password = this.input.value;
  4029. if (password?.length > 0) {
  4030. this.#invokeCallback(password);
  4031. }
  4032. }
  4033. #cancel() {
  4034. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  4035. this.#activeCapability.resolve();
  4036. }
  4037. #invokeCallback(password) {
  4038. if (!this.#updateCallback) {
  4039. return;
  4040. }
  4041. this.close();
  4042. this.input.value = "";
  4043. this.#updateCallback(password);
  4044. this.#updateCallback = null;
  4045. }
  4046. async setUpdateCallback(updateCallback, reason) {
  4047. if (this.#activeCapability) {
  4048. await this.#activeCapability.promise;
  4049. }
  4050. this.#updateCallback = updateCallback;
  4051. this.#reason = reason;
  4052. }
  4053. }
  4054. exports.PasswordPrompt = PasswordPrompt;
  4055. /***/
  4056. }),
  4057. /* 12 */
  4058. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4059. Object.defineProperty(exports, "__esModule", ({
  4060. value: true
  4061. }));
  4062. exports.PDFAttachmentViewer = void 0;
  4063. var _pdfjsLib = __webpack_require__(5);
  4064. var _base_tree_viewer = __webpack_require__(13);
  4065. var _event_utils = __webpack_require__(6);
  4066. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4067. constructor(options) {
  4068. super(options);
  4069. this.downloadManager = options.downloadManager;
  4070. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  4071. }
  4072. reset(keepRenderedCapability = false) {
  4073. super.reset();
  4074. this._attachments = null;
  4075. if (!keepRenderedCapability) {
  4076. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4077. }
  4078. this._pendingDispatchEvent = false;
  4079. }
  4080. async _dispatchEvent(attachmentsCount) {
  4081. this._renderedCapability.resolve();
  4082. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4083. this._pendingDispatchEvent = true;
  4084. await (0, _event_utils.waitOnEventOrTimeout)({
  4085. target: this.eventBus,
  4086. name: "annotationlayerrendered",
  4087. delay: 1000
  4088. });
  4089. if (!this._pendingDispatchEvent) {
  4090. return;
  4091. }
  4092. }
  4093. this._pendingDispatchEvent = false;
  4094. this.eventBus.dispatch("attachmentsloaded", {
  4095. source: this,
  4096. attachmentsCount
  4097. });
  4098. }
  4099. _bindLink(element, {
  4100. content,
  4101. filename
  4102. }) {
  4103. element.onclick = () => {
  4104. this.downloadManager.openOrDownloadData(element, content, filename);
  4105. return false;
  4106. };
  4107. }
  4108. render({
  4109. attachments,
  4110. keepRenderedCapability = false
  4111. }) {
  4112. if (this._attachments) {
  4113. this.reset(keepRenderedCapability);
  4114. }
  4115. this._attachments = attachments || null;
  4116. if (!attachments) {
  4117. this._dispatchEvent(0);
  4118. return;
  4119. }
  4120. const names = Object.keys(attachments).sort(function (a, b) {
  4121. return a.toLowerCase().localeCompare(b.toLowerCase());
  4122. });
  4123. const fragment = document.createDocumentFragment();
  4124. let attachmentsCount = 0;
  4125. for (const name of names) {
  4126. const item = attachments[name];
  4127. const content = item.content,
  4128. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  4129. const div = document.createElement("div");
  4130. div.className = "treeItem";
  4131. const element = document.createElement("a");
  4132. this._bindLink(element, {
  4133. content,
  4134. filename
  4135. });
  4136. element.textContent = this._normalizeTextContent(filename);
  4137. div.append(element);
  4138. fragment.append(div);
  4139. attachmentsCount++;
  4140. }
  4141. this._finishRendering(fragment, attachmentsCount);
  4142. }
  4143. #appendAttachment({
  4144. filename,
  4145. content
  4146. }) {
  4147. const renderedPromise = this._renderedCapability.promise;
  4148. renderedPromise.then(() => {
  4149. if (renderedPromise !== this._renderedCapability.promise) {
  4150. return;
  4151. }
  4152. const attachments = this._attachments || Object.create(null);
  4153. for (const name in attachments) {
  4154. if (filename === name) {
  4155. return;
  4156. }
  4157. }
  4158. attachments[filename] = {
  4159. filename,
  4160. content
  4161. };
  4162. this.render({
  4163. attachments,
  4164. keepRenderedCapability: true
  4165. });
  4166. });
  4167. }
  4168. }
  4169. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4170. /***/
  4171. }),
  4172. /* 13 */
  4173. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4174. Object.defineProperty(exports, "__esModule", ({
  4175. value: true
  4176. }));
  4177. exports.BaseTreeViewer = void 0;
  4178. var _ui_utils = __webpack_require__(1);
  4179. const TREEITEM_OFFSET_TOP = -100;
  4180. const TREEITEM_SELECTED_CLASS = "selected";
  4181. class BaseTreeViewer {
  4182. constructor(options) {
  4183. if (this.constructor === BaseTreeViewer) {
  4184. throw new Error("Cannot initialize BaseTreeViewer.");
  4185. }
  4186. this.container = options.container;
  4187. this.eventBus = options.eventBus;
  4188. this.reset();
  4189. }
  4190. reset() {
  4191. this._pdfDocument = null;
  4192. this._lastToggleIsShow = true;
  4193. this._currentTreeItem = null;
  4194. this.container.textContent = "";
  4195. this.container.classList.remove("treeWithDeepNesting");
  4196. }
  4197. _dispatchEvent(count) {
  4198. throw new Error("Not implemented: _dispatchEvent");
  4199. }
  4200. _bindLink(element, params) {
  4201. throw new Error("Not implemented: _bindLink");
  4202. }
  4203. _normalizeTextContent(str) {
  4204. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4205. }
  4206. _addToggleButton(div, hidden = false) {
  4207. const toggler = document.createElement("div");
  4208. toggler.className = "treeItemToggler";
  4209. if (hidden) {
  4210. toggler.classList.add("treeItemsHidden");
  4211. }
  4212. toggler.onclick = evt => {
  4213. evt.stopPropagation();
  4214. toggler.classList.toggle("treeItemsHidden");
  4215. if (evt.shiftKey) {
  4216. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4217. this._toggleTreeItem(div, shouldShowAll);
  4218. }
  4219. };
  4220. div.prepend(toggler);
  4221. }
  4222. _toggleTreeItem(root, show = false) {
  4223. this._lastToggleIsShow = show;
  4224. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4225. toggler.classList.toggle("treeItemsHidden", !show);
  4226. }
  4227. }
  4228. _toggleAllTreeItems() {
  4229. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4230. }
  4231. _finishRendering(fragment, count, hasAnyNesting = false) {
  4232. if (hasAnyNesting) {
  4233. this.container.classList.add("treeWithDeepNesting");
  4234. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4235. }
  4236. this.container.append(fragment);
  4237. this._dispatchEvent(count);
  4238. }
  4239. render(params) {
  4240. throw new Error("Not implemented: render");
  4241. }
  4242. _updateCurrentTreeItem(treeItem = null) {
  4243. if (this._currentTreeItem) {
  4244. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4245. this._currentTreeItem = null;
  4246. }
  4247. if (treeItem) {
  4248. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4249. this._currentTreeItem = treeItem;
  4250. }
  4251. }
  4252. _scrollToCurrentTreeItem(treeItem) {
  4253. if (!treeItem) {
  4254. return;
  4255. }
  4256. let currentNode = treeItem.parentNode;
  4257. while (currentNode && currentNode !== this.container) {
  4258. if (currentNode.classList.contains("treeItem")) {
  4259. const toggler = currentNode.firstElementChild;
  4260. toggler?.classList.remove("treeItemsHidden");
  4261. }
  4262. currentNode = currentNode.parentNode;
  4263. }
  4264. this._updateCurrentTreeItem(treeItem);
  4265. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4266. }
  4267. }
  4268. exports.BaseTreeViewer = BaseTreeViewer;
  4269. /***/
  4270. }),
  4271. /* 14 */
  4272. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4273. Object.defineProperty(exports, "__esModule", ({
  4274. value: true
  4275. }));
  4276. exports.PDFDocumentProperties = void 0;
  4277. var _pdfjsLib = __webpack_require__(5);
  4278. var _ui_utils = __webpack_require__(1);
  4279. const DEFAULT_FIELD_CONTENT = "-";
  4280. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4281. const US_PAGE_NAMES = {
  4282. "8.5x11": "Letter",
  4283. "8.5x14": "Legal"
  4284. };
  4285. const METRIC_PAGE_NAMES = {
  4286. "297x420": "A3",
  4287. "210x297": "A4"
  4288. };
  4289. function getPageName(size, isPortrait, pageNames) {
  4290. const width = isPortrait ? size.width : size.height;
  4291. const height = isPortrait ? size.height : size.width;
  4292. return pageNames[`${width}x${height}`];
  4293. }
  4294. class PDFDocumentProperties {
  4295. #fieldData = null;
  4296. constructor({
  4297. dialog,
  4298. fields,
  4299. closeButton
  4300. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4301. this.dialog = dialog;
  4302. this.fields = fields;
  4303. this.overlayManager = overlayManager;
  4304. this.l10n = l10n;
  4305. this._fileNameLookup = fileNameLookup;
  4306. this.#reset();
  4307. closeButton.addEventListener("click", this.close.bind(this));
  4308. this.overlayManager.register(this.dialog);
  4309. eventBus._on("pagechanging", evt => {
  4310. this._currentPageNumber = evt.pageNumber;
  4311. });
  4312. eventBus._on("rotationchanging", evt => {
  4313. this._pagesRotation = evt.pagesRotation;
  4314. });
  4315. this._isNonMetricLocale = true;
  4316. l10n.getLanguage().then(locale => {
  4317. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4318. });
  4319. }
  4320. async open() {
  4321. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4322. const currentPageNumber = this._currentPageNumber;
  4323. const pagesRotation = this._pagesRotation;
  4324. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4325. this.#updateUI();
  4326. return;
  4327. }
  4328. const {
  4329. info,
  4330. contentLength
  4331. } = await this.pdfDocument.getMetadata();
  4332. const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([this._fileNameLookup(), this.#parseFileSize(contentLength), this.#parseDate(info.CreationDate), this.#parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
  4333. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4334. }), this.#parseLinearization(info.IsLinearized)]);
  4335. this.#fieldData = Object.freeze({
  4336. fileName,
  4337. fileSize,
  4338. title: info.Title,
  4339. author: info.Author,
  4340. subject: info.Subject,
  4341. keywords: info.Keywords,
  4342. creationDate,
  4343. modificationDate,
  4344. creator: info.Creator,
  4345. producer: info.Producer,
  4346. version: info.PDFFormatVersion,
  4347. pageCount: this.pdfDocument.numPages,
  4348. pageSize,
  4349. linearized: isLinearized,
  4350. _currentPageNumber: currentPageNumber,
  4351. _pagesRotation: pagesRotation
  4352. });
  4353. this.#updateUI();
  4354. const {
  4355. length
  4356. } = await this.pdfDocument.getDownloadInfo();
  4357. if (contentLength === length) {
  4358. return;
  4359. }
  4360. const data = Object.assign(Object.create(null), this.#fieldData);
  4361. data.fileSize = await this.#parseFileSize(length);
  4362. this.#fieldData = Object.freeze(data);
  4363. this.#updateUI();
  4364. }
  4365. async close() {
  4366. this.overlayManager.close(this.dialog);
  4367. }
  4368. setDocument(pdfDocument) {
  4369. if (this.pdfDocument) {
  4370. this.#reset();
  4371. this.#updateUI(true);
  4372. }
  4373. if (!pdfDocument) {
  4374. return;
  4375. }
  4376. this.pdfDocument = pdfDocument;
  4377. this._dataAvailableCapability.resolve();
  4378. }
  4379. #reset() {
  4380. this.pdfDocument = null;
  4381. this.#fieldData = null;
  4382. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4383. this._currentPageNumber = 1;
  4384. this._pagesRotation = 0;
  4385. }
  4386. #updateUI(reset = false) {
  4387. if (reset || !this.#fieldData) {
  4388. for (const id in this.fields) {
  4389. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4390. }
  4391. return;
  4392. }
  4393. if (this.overlayManager.active !== this.dialog) {
  4394. return;
  4395. }
  4396. for (const id in this.fields) {
  4397. const content = this.#fieldData[id];
  4398. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4399. }
  4400. }
  4401. async #parseFileSize(fileSize = 0) {
  4402. const kb = fileSize / 1024,
  4403. mb = kb / 1024;
  4404. if (!kb) {
  4405. return undefined;
  4406. }
  4407. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4408. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4409. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4410. size_b: fileSize.toLocaleString()
  4411. });
  4412. }
  4413. async #parsePageSize(pageSizeInches, pagesRotation) {
  4414. if (!pageSizeInches) {
  4415. return undefined;
  4416. }
  4417. if (pagesRotation % 180 !== 0) {
  4418. pageSizeInches = {
  4419. width: pageSizeInches.height,
  4420. height: pageSizeInches.width
  4421. };
  4422. }
  4423. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4424. let sizeInches = {
  4425. width: Math.round(pageSizeInches.width * 100) / 100,
  4426. height: Math.round(pageSizeInches.height * 100) / 100
  4427. };
  4428. let sizeMillimeters = {
  4429. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4430. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4431. };
  4432. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4433. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4434. const exactMillimeters = {
  4435. width: pageSizeInches.width * 25.4,
  4436. height: pageSizeInches.height * 25.4
  4437. };
  4438. const intMillimeters = {
  4439. width: Math.round(sizeMillimeters.width),
  4440. height: Math.round(sizeMillimeters.height)
  4441. };
  4442. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4443. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4444. if (rawName) {
  4445. sizeInches = {
  4446. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4447. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4448. };
  4449. sizeMillimeters = intMillimeters;
  4450. }
  4451. }
  4452. }
  4453. const [{
  4454. width,
  4455. height
  4456. }, 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"}`)]);
  4457. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4458. width: width.toLocaleString(),
  4459. height: height.toLocaleString(),
  4460. unit,
  4461. name,
  4462. orientation
  4463. });
  4464. }
  4465. async #parseDate(inputDate) {
  4466. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4467. if (!dateObject) {
  4468. return undefined;
  4469. }
  4470. return this.l10n.get("document_properties_date_string", {
  4471. date: dateObject.toLocaleDateString(),
  4472. time: dateObject.toLocaleTimeString()
  4473. });
  4474. }
  4475. #parseLinearization(isLinearized) {
  4476. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4477. }
  4478. }
  4479. exports.PDFDocumentProperties = PDFDocumentProperties;
  4480. /***/
  4481. }),
  4482. /* 15 */
  4483. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4484. Object.defineProperty(exports, "__esModule", ({
  4485. value: true
  4486. }));
  4487. exports.PDFFindBar = void 0;
  4488. var _pdf_find_controller = __webpack_require__(16);
  4489. const MATCHES_COUNT_LIMIT = 1000;
  4490. class PDFFindBar {
  4491. constructor(options, eventBus, l10n) {
  4492. this.opened = false;
  4493. this.bar = options.bar;
  4494. this.toggleButton = options.toggleButton;
  4495. this.findField = options.findField;
  4496. this.highlightAll = options.highlightAllCheckbox;
  4497. this.caseSensitive = options.caseSensitiveCheckbox;
  4498. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4499. this.entireWord = options.entireWordCheckbox;
  4500. this.findMsg = options.findMsg;
  4501. this.findResultsCount = options.findResultsCount;
  4502. this.findPreviousButton = options.findPreviousButton;
  4503. this.findNextButton = options.findNextButton;
  4504. this.eventBus = eventBus;
  4505. this.l10n = l10n;
  4506. this.toggleButton.addEventListener("click", () => {
  4507. this.toggle();
  4508. });
  4509. this.findField.addEventListener("input", () => {
  4510. this.dispatchEvent("");
  4511. });
  4512. this.bar.addEventListener("keydown", e => {
  4513. switch (e.keyCode) {
  4514. case 13:
  4515. if (e.target === this.findField) {
  4516. this.dispatchEvent("again", e.shiftKey);
  4517. }
  4518. break;
  4519. case 27:
  4520. this.close();
  4521. break;
  4522. }
  4523. });
  4524. this.findPreviousButton.addEventListener("click", () => {
  4525. this.dispatchEvent("again", true);
  4526. });
  4527. this.findNextButton.addEventListener("click", () => {
  4528. this.dispatchEvent("again", false);
  4529. });
  4530. this.highlightAll.addEventListener("click", () => {
  4531. this.dispatchEvent("highlightallchange");
  4532. });
  4533. this.caseSensitive.addEventListener("click", () => {
  4534. this.dispatchEvent("casesensitivitychange");
  4535. });
  4536. this.entireWord.addEventListener("click", () => {
  4537. this.dispatchEvent("entirewordchange");
  4538. });
  4539. this.matchDiacritics.addEventListener("click", () => {
  4540. this.dispatchEvent("diacriticmatchingchange");
  4541. });
  4542. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4543. }
  4544. reset() {
  4545. this.updateUIState();
  4546. }
  4547. dispatchEvent(type, findPrev = false) {
  4548. this.eventBus.dispatch("find", {
  4549. source: this,
  4550. type,
  4551. query: this.findField.value,
  4552. phraseSearch: true,
  4553. caseSensitive: this.caseSensitive.checked,
  4554. entireWord: this.entireWord.checked,
  4555. highlightAll: this.highlightAll.checked,
  4556. findPrevious: findPrev,
  4557. matchDiacritics: this.matchDiacritics.checked
  4558. });
  4559. }
  4560. updateUIState(state, previous, matchesCount) {
  4561. let findMsg = Promise.resolve("");
  4562. let status = "";
  4563. switch (state) {
  4564. case _pdf_find_controller.FindState.FOUND:
  4565. break;
  4566. case _pdf_find_controller.FindState.PENDING:
  4567. status = "pending";
  4568. break;
  4569. case _pdf_find_controller.FindState.NOT_FOUND:
  4570. findMsg = this.l10n.get("find_not_found");
  4571. status = "notFound";
  4572. break;
  4573. case _pdf_find_controller.FindState.WRAPPED:
  4574. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4575. break;
  4576. }
  4577. this.findField.setAttribute("data-status", status);
  4578. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4579. findMsg.then(msg => {
  4580. this.findMsg.textContent = msg;
  4581. this.#adjustWidth();
  4582. });
  4583. this.updateResultsCount(matchesCount);
  4584. }
  4585. updateResultsCount({
  4586. current = 0,
  4587. total = 0
  4588. } = {}) {
  4589. const limit = MATCHES_COUNT_LIMIT;
  4590. let matchCountMsg = Promise.resolve("");
  4591. if (total > 0) {
  4592. if (total > limit) {
  4593. let key = "find_match_count_limit";
  4594. matchCountMsg = this.l10n.get(key, {
  4595. limit
  4596. });
  4597. } else {
  4598. let key = "find_match_count";
  4599. matchCountMsg = this.l10n.get(key, {
  4600. current,
  4601. total
  4602. });
  4603. }
  4604. }
  4605. matchCountMsg.then(msg => {
  4606. this.findResultsCount.textContent = msg;
  4607. this.#adjustWidth();
  4608. });
  4609. }
  4610. open() {
  4611. if (!this.opened) {
  4612. this.opened = true;
  4613. this.toggleButton.classList.add("toggled");
  4614. this.toggleButton.setAttribute("aria-expanded", "true");
  4615. this.bar.classList.remove("hidden");
  4616. }
  4617. this.findField.select();
  4618. this.findField.focus();
  4619. this.#adjustWidth();
  4620. }
  4621. close() {
  4622. if (!this.opened) {
  4623. return;
  4624. }
  4625. this.opened = false;
  4626. this.toggleButton.classList.remove("toggled");
  4627. this.toggleButton.setAttribute("aria-expanded", "false");
  4628. this.bar.classList.add("hidden");
  4629. this.eventBus.dispatch("findbarclose", {
  4630. source: this
  4631. });
  4632. }
  4633. toggle() {
  4634. if (this.opened) {
  4635. this.close();
  4636. } else {
  4637. this.open();
  4638. }
  4639. }
  4640. #adjustWidth() {
  4641. if (!this.opened) {
  4642. return;
  4643. }
  4644. this.bar.classList.remove("wrapContainers");
  4645. const findbarHeight = this.bar.clientHeight;
  4646. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4647. if (findbarHeight > inputContainerHeight) {
  4648. this.bar.classList.add("wrapContainers");
  4649. }
  4650. }
  4651. }
  4652. exports.PDFFindBar = PDFFindBar;
  4653. /***/
  4654. }),
  4655. /* 16 */
  4656. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4657. Object.defineProperty(exports, "__esModule", ({
  4658. value: true
  4659. }));
  4660. exports.PDFFindController = exports.FindState = void 0;
  4661. var _ui_utils = __webpack_require__(1);
  4662. var _pdfjsLib = __webpack_require__(5);
  4663. var _pdf_find_utils = __webpack_require__(17);
  4664. const FindState = {
  4665. FOUND: 0,
  4666. NOT_FOUND: 1,
  4667. WRAPPED: 2,
  4668. PENDING: 3
  4669. };
  4670. exports.FindState = FindState;
  4671. const FIND_TIMEOUT = 250;
  4672. const MATCH_SCROLL_OFFSET_TOP = -50;
  4673. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4674. const CHARACTERS_TO_NORMALIZE = {
  4675. "\u2010": "-",
  4676. "\u2018": "'",
  4677. "\u2019": "'",
  4678. "\u201A": "'",
  4679. "\u201B": "'",
  4680. "\u201C": '"',
  4681. "\u201D": '"',
  4682. "\u201E": '"',
  4683. "\u201F": '"',
  4684. "\u00BC": "1/4",
  4685. "\u00BD": "1/2",
  4686. "\u00BE": "3/4"
  4687. };
  4688. const DIACRITICS_EXCEPTION = new Set([0x3099, 0x309a, 0x094d, 0x09cd, 0x0a4d, 0x0acd, 0x0b4d, 0x0bcd, 0x0c4d, 0x0ccd, 0x0d3b, 0x0d3c, 0x0d4d, 0x0dca, 0x0e3a, 0x0eba, 0x0f84, 0x1039, 0x103a, 0x1714, 0x1734, 0x17d2, 0x1a60, 0x1b44, 0x1baa, 0x1bab, 0x1bf2, 0x1bf3, 0x2d7f, 0xa806, 0xa82c, 0xa8c4, 0xa953, 0xa9c0, 0xaaf6, 0xabed, 0x0c56, 0x0f71, 0x0f72, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f80, 0x0f74]);
  4689. const DIACRITICS_EXCEPTION_STR = [...DIACRITICS_EXCEPTION.values()].map(x => String.fromCharCode(x)).join("");
  4690. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4691. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4692. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4693. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4694. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4695. const SYLLABLES_LENGTHS = new Map();
  4696. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4697. let noSyllablesRegExp = null;
  4698. let withSyllablesRegExp = null;
  4699. function normalize(text) {
  4700. const syllablePositions = [];
  4701. let m;
  4702. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4703. let {
  4704. index
  4705. } = m;
  4706. for (const char of m[0]) {
  4707. let len = SYLLABLES_LENGTHS.get(char);
  4708. if (!len) {
  4709. len = char.normalize("NFD").length;
  4710. SYLLABLES_LENGTHS.set(char, len);
  4711. }
  4712. syllablePositions.push([len, index++]);
  4713. }
  4714. }
  4715. let normalizationRegex;
  4716. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4717. normalizationRegex = noSyllablesRegExp;
  4718. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4719. normalizationRegex = withSyllablesRegExp;
  4720. } else {
  4721. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4722. const regexp = `([${replace}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(\\n)`;
  4723. if (syllablePositions.length === 0) {
  4724. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4725. } else {
  4726. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4727. }
  4728. }
  4729. const rawDiacriticsPositions = [];
  4730. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4731. rawDiacriticsPositions.push([m[0].length, m.index]);
  4732. }
  4733. let normalized = text.normalize("NFD");
  4734. const positions = [[0, 0]];
  4735. let rawDiacriticsIndex = 0;
  4736. let syllableIndex = 0;
  4737. let shift = 0;
  4738. let shiftOrigin = 0;
  4739. let eol = 0;
  4740. let hasDiacritics = false;
  4741. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, i) => {
  4742. i -= shiftOrigin;
  4743. if (p1) {
  4744. const replacement = CHARACTERS_TO_NORMALIZE[match];
  4745. const jj = replacement.length;
  4746. for (let j = 1; j < jj; j++) {
  4747. positions.push([i - shift + j, shift - j]);
  4748. }
  4749. shift -= jj - 1;
  4750. return replacement;
  4751. }
  4752. if (p2) {
  4753. const hasTrailingDashEOL = p2.endsWith("\n");
  4754. const len = hasTrailingDashEOL ? p2.length - 2 : p2.length;
  4755. hasDiacritics = true;
  4756. let jj = len;
  4757. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4758. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4759. ++rawDiacriticsIndex;
  4760. }
  4761. for (let j = 1; j <= jj; j++) {
  4762. positions.push([i - 1 - shift + j, shift - j]);
  4763. }
  4764. shift -= jj;
  4765. shiftOrigin += jj;
  4766. if (hasTrailingDashEOL) {
  4767. i += len - 1;
  4768. positions.push([i - shift + 1, 1 + shift]);
  4769. shift += 1;
  4770. shiftOrigin += 1;
  4771. eol += 1;
  4772. return p2.slice(0, len);
  4773. }
  4774. return p2;
  4775. }
  4776. if (p3) {
  4777. positions.push([i - shift + 1, 1 + shift]);
  4778. shift += 1;
  4779. shiftOrigin += 1;
  4780. eol += 1;
  4781. return p3.charAt(0);
  4782. }
  4783. if (p4) {
  4784. positions.push([i - shift + 1, shift - 1]);
  4785. shift -= 1;
  4786. shiftOrigin += 1;
  4787. eol += 1;
  4788. return " ";
  4789. }
  4790. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  4791. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  4792. ++syllableIndex;
  4793. for (let j = 1; j <= newCharLen; j++) {
  4794. positions.push([i - (shift - j), shift - j]);
  4795. }
  4796. shift -= newCharLen;
  4797. shiftOrigin += newCharLen;
  4798. }
  4799. return p5;
  4800. });
  4801. positions.push([normalized.length, shift]);
  4802. return [normalized, positions, hasDiacritics];
  4803. }
  4804. function getOriginalIndex(diffs, pos, len) {
  4805. if (!diffs) {
  4806. return [pos, len];
  4807. }
  4808. const start = pos;
  4809. const end = pos + len;
  4810. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  4811. if (diffs[i][0] > start) {
  4812. --i;
  4813. }
  4814. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  4815. if (diffs[j][0] > end) {
  4816. --j;
  4817. }
  4818. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  4819. }
  4820. class PDFFindController {
  4821. constructor({
  4822. linkService,
  4823. eventBus
  4824. }) {
  4825. this._linkService = linkService;
  4826. this._eventBus = eventBus;
  4827. this.#reset();
  4828. eventBus._on("find", this.#onFind.bind(this));
  4829. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  4830. }
  4831. get highlightMatches() {
  4832. return this._highlightMatches;
  4833. }
  4834. get pageMatches() {
  4835. return this._pageMatches;
  4836. }
  4837. get pageMatchesLength() {
  4838. return this._pageMatchesLength;
  4839. }
  4840. get selected() {
  4841. return this._selected;
  4842. }
  4843. get state() {
  4844. return this._state;
  4845. }
  4846. setDocument(pdfDocument) {
  4847. if (this._pdfDocument) {
  4848. this.#reset();
  4849. }
  4850. if (!pdfDocument) {
  4851. return;
  4852. }
  4853. this._pdfDocument = pdfDocument;
  4854. this._firstPageCapability.resolve();
  4855. }
  4856. #onFind(state) {
  4857. if (!state) {
  4858. return;
  4859. }
  4860. const pdfDocument = this._pdfDocument;
  4861. const {
  4862. type
  4863. } = state;
  4864. if (this._state === null || this.#shouldDirtyMatch(state)) {
  4865. this._dirtyMatch = true;
  4866. }
  4867. this._state = state;
  4868. if (type !== "highlightallchange") {
  4869. this.#updateUIState(FindState.PENDING);
  4870. }
  4871. this._firstPageCapability.promise.then(() => {
  4872. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4873. return;
  4874. }
  4875. this.#extractText();
  4876. const findbarClosed = !this._highlightMatches;
  4877. const pendingTimeout = !!this._findTimeout;
  4878. if (this._findTimeout) {
  4879. clearTimeout(this._findTimeout);
  4880. this._findTimeout = null;
  4881. }
  4882. if (!type) {
  4883. this._findTimeout = setTimeout(() => {
  4884. this.#nextMatch();
  4885. this._findTimeout = null;
  4886. }, FIND_TIMEOUT);
  4887. } else if (this._dirtyMatch) {
  4888. this.#nextMatch();
  4889. } else if (type === "again") {
  4890. this.#nextMatch();
  4891. if (findbarClosed && this._state.highlightAll) {
  4892. this.#updateAllPages();
  4893. }
  4894. } else if (type === "highlightallchange") {
  4895. if (pendingTimeout) {
  4896. this.#nextMatch();
  4897. } else {
  4898. this._highlightMatches = true;
  4899. }
  4900. this.#updateAllPages();
  4901. } else {
  4902. this.#nextMatch();
  4903. }
  4904. });
  4905. }
  4906. scrollMatchIntoView({
  4907. element = null,
  4908. selectedLeft = 0,
  4909. pageIndex = -1,
  4910. matchIndex = -1
  4911. }) {
  4912. if (!this._scrollMatches || !element) {
  4913. return;
  4914. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4915. return;
  4916. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4917. return;
  4918. }
  4919. this._scrollMatches = false;
  4920. const spot = {
  4921. top: MATCH_SCROLL_OFFSET_TOP,
  4922. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  4923. };
  4924. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4925. }
  4926. #reset() {
  4927. this._highlightMatches = false;
  4928. this._scrollMatches = false;
  4929. this._pdfDocument = null;
  4930. this._pageMatches = [];
  4931. this._pageMatchesLength = [];
  4932. this._state = null;
  4933. this._selected = {
  4934. pageIdx: -1,
  4935. matchIdx: -1
  4936. };
  4937. this._offset = {
  4938. pageIdx: null,
  4939. matchIdx: null,
  4940. wrapped: false
  4941. };
  4942. this._extractTextPromises = [];
  4943. this._pageContents = [];
  4944. this._pageDiffs = [];
  4945. this._hasDiacritics = [];
  4946. this._matchesCountTotal = 0;
  4947. this._pagesToSearch = null;
  4948. this._pendingFindMatches = new Set();
  4949. this._resumePageIdx = null;
  4950. this._dirtyMatch = false;
  4951. clearTimeout(this._findTimeout);
  4952. this._findTimeout = null;
  4953. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4954. }
  4955. get #query() {
  4956. if (this._state.query !== this._rawQuery) {
  4957. this._rawQuery = this._state.query;
  4958. [this._normalizedQuery] = normalize(this._state.query);
  4959. }
  4960. return this._normalizedQuery;
  4961. }
  4962. #shouldDirtyMatch(state) {
  4963. if (state.query !== this._state.query) {
  4964. return true;
  4965. }
  4966. switch (state.type) {
  4967. case "again":
  4968. const pageNumber = this._selected.pageIdx + 1;
  4969. const linkService = this._linkService;
  4970. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4971. return true;
  4972. }
  4973. return false;
  4974. case "highlightallchange":
  4975. return false;
  4976. }
  4977. return true;
  4978. }
  4979. #isEntireWord(content, startIdx, length) {
  4980. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  4981. if (match) {
  4982. const first = content.charCodeAt(startIdx);
  4983. const limit = match[1].charCodeAt(0);
  4984. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4985. return false;
  4986. }
  4987. }
  4988. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  4989. if (match) {
  4990. const last = content.charCodeAt(startIdx + length - 1);
  4991. const limit = match[1].charCodeAt(0);
  4992. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4993. return false;
  4994. }
  4995. }
  4996. return true;
  4997. }
  4998. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  4999. const matches = [],
  5000. matchesLength = [];
  5001. const diffs = this._pageDiffs[pageIndex];
  5002. let match;
  5003. while ((match = query.exec(pageContent)) !== null) {
  5004. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  5005. continue;
  5006. }
  5007. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  5008. if (matchLen) {
  5009. matches.push(matchPos);
  5010. matchesLength.push(matchLen);
  5011. }
  5012. }
  5013. this._pageMatches[pageIndex] = matches;
  5014. this._pageMatchesLength[pageIndex] = matchesLength;
  5015. }
  5016. #convertToRegExpString(query, hasDiacritics) {
  5017. const {
  5018. matchDiacritics
  5019. } = this._state;
  5020. let isUnicode = false;
  5021. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5022. if (p1) {
  5023. return `[ ]*\\${p1}[ ]*`;
  5024. }
  5025. if (p2) {
  5026. return `[ ]*${p2}[ ]*`;
  5027. }
  5028. if (p3) {
  5029. return "[ ]+";
  5030. }
  5031. if (matchDiacritics) {
  5032. return p4 || p5;
  5033. }
  5034. if (p4) {
  5035. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5036. }
  5037. if (hasDiacritics) {
  5038. isUnicode = true;
  5039. return `${p5}\\p{M}*`;
  5040. }
  5041. return p5;
  5042. });
  5043. const trailingSpaces = "[ ]*";
  5044. if (query.endsWith(trailingSpaces)) {
  5045. query = query.slice(0, query.length - trailingSpaces.length);
  5046. }
  5047. if (matchDiacritics) {
  5048. if (hasDiacritics) {
  5049. isUnicode = true;
  5050. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5051. }
  5052. }
  5053. return [isUnicode, query];
  5054. }
  5055. #calculateMatch(pageIndex) {
  5056. let query = this.#query;
  5057. if (query.length === 0) {
  5058. return;
  5059. }
  5060. const {
  5061. caseSensitive,
  5062. entireWord,
  5063. phraseSearch
  5064. } = this._state;
  5065. const pageContent = this._pageContents[pageIndex];
  5066. const hasDiacritics = this._hasDiacritics[pageIndex];
  5067. let isUnicode = false;
  5068. if (phraseSearch) {
  5069. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5070. } else {
  5071. const match = query.match(/\S+/g);
  5072. if (match) {
  5073. query = match.sort().reverse().map(q => {
  5074. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5075. isUnicode ||= isUnicodePart;
  5076. return `(${queryPart})`;
  5077. }).join("|");
  5078. }
  5079. }
  5080. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5081. query = new RegExp(query, flags);
  5082. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  5083. if (this._state.highlightAll) {
  5084. this.#updatePage(pageIndex);
  5085. }
  5086. if (this._resumePageIdx === pageIndex) {
  5087. this._resumePageIdx = null;
  5088. this.#nextPageMatch();
  5089. }
  5090. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5091. if (pageMatchesCount > 0) {
  5092. this._matchesCountTotal += pageMatchesCount;
  5093. this.#updateUIResultsCount();
  5094. }
  5095. }
  5096. #extractText() {
  5097. if (this._extractTextPromises.length > 0) {
  5098. return;
  5099. }
  5100. let promise = Promise.resolve();
  5101. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5102. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  5103. this._extractTextPromises[i] = extractTextCapability.promise;
  5104. promise = promise.then(() => {
  5105. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5106. return pdfPage.getTextContent();
  5107. }).then(textContent => {
  5108. const strBuf = [];
  5109. for (const textItem of textContent.items) {
  5110. strBuf.push(textItem.str);
  5111. if (textItem.hasEOL) {
  5112. strBuf.push("\n");
  5113. }
  5114. }
  5115. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5116. extractTextCapability.resolve();
  5117. }, reason => {
  5118. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5119. this._pageContents[i] = "";
  5120. this._pageDiffs[i] = null;
  5121. this._hasDiacritics[i] = false;
  5122. extractTextCapability.resolve();
  5123. });
  5124. });
  5125. }
  5126. }
  5127. #updatePage(index) {
  5128. if (this._scrollMatches && this._selected.pageIdx === index) {
  5129. this._linkService.page = index + 1;
  5130. }
  5131. this._eventBus.dispatch("updatetextlayermatches", {
  5132. source: this,
  5133. pageIndex: index
  5134. });
  5135. }
  5136. #updateAllPages() {
  5137. this._eventBus.dispatch("updatetextlayermatches", {
  5138. source: this,
  5139. pageIndex: -1
  5140. });
  5141. }
  5142. #nextMatch() {
  5143. const previous = this._state.findPrevious;
  5144. const currentPageIndex = this._linkService.page - 1;
  5145. const numPages = this._linkService.pagesCount;
  5146. this._highlightMatches = true;
  5147. if (this._dirtyMatch) {
  5148. this._dirtyMatch = false;
  5149. this._selected.pageIdx = this._selected.matchIdx = -1;
  5150. this._offset.pageIdx = currentPageIndex;
  5151. this._offset.matchIdx = null;
  5152. this._offset.wrapped = false;
  5153. this._resumePageIdx = null;
  5154. this._pageMatches.length = 0;
  5155. this._pageMatchesLength.length = 0;
  5156. this._matchesCountTotal = 0;
  5157. this.#updateAllPages();
  5158. for (let i = 0; i < numPages; i++) {
  5159. if (this._pendingFindMatches.has(i)) {
  5160. continue;
  5161. }
  5162. this._pendingFindMatches.add(i);
  5163. this._extractTextPromises[i].then(() => {
  5164. this._pendingFindMatches.delete(i);
  5165. this.#calculateMatch(i);
  5166. });
  5167. }
  5168. }
  5169. if (this.#query === "") {
  5170. this.#updateUIState(FindState.FOUND);
  5171. return;
  5172. }
  5173. if (this._resumePageIdx) {
  5174. return;
  5175. }
  5176. const offset = this._offset;
  5177. this._pagesToSearch = numPages;
  5178. if (offset.matchIdx !== null) {
  5179. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5180. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5181. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5182. this.#updateMatch(true);
  5183. return;
  5184. }
  5185. this.#advanceOffsetPage(previous);
  5186. }
  5187. this.#nextPageMatch();
  5188. }
  5189. #matchesReady(matches) {
  5190. const offset = this._offset;
  5191. const numMatches = matches.length;
  5192. const previous = this._state.findPrevious;
  5193. if (numMatches) {
  5194. offset.matchIdx = previous ? numMatches - 1 : 0;
  5195. this.#updateMatch(true);
  5196. return true;
  5197. }
  5198. this.#advanceOffsetPage(previous);
  5199. if (offset.wrapped) {
  5200. offset.matchIdx = null;
  5201. if (this._pagesToSearch < 0) {
  5202. this.#updateMatch(false);
  5203. return true;
  5204. }
  5205. }
  5206. return false;
  5207. }
  5208. #nextPageMatch() {
  5209. if (this._resumePageIdx !== null) {
  5210. console.error("There can only be one pending page.");
  5211. }
  5212. let matches = null;
  5213. do {
  5214. const pageIdx = this._offset.pageIdx;
  5215. matches = this._pageMatches[pageIdx];
  5216. if (!matches) {
  5217. this._resumePageIdx = pageIdx;
  5218. break;
  5219. }
  5220. } while (!this.#matchesReady(matches));
  5221. }
  5222. #advanceOffsetPage(previous) {
  5223. const offset = this._offset;
  5224. const numPages = this._linkService.pagesCount;
  5225. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5226. offset.matchIdx = null;
  5227. this._pagesToSearch--;
  5228. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5229. offset.pageIdx = previous ? numPages - 1 : 0;
  5230. offset.wrapped = true;
  5231. }
  5232. }
  5233. #updateMatch(found = false) {
  5234. let state = FindState.NOT_FOUND;
  5235. const wrapped = this._offset.wrapped;
  5236. this._offset.wrapped = false;
  5237. if (found) {
  5238. const previousPage = this._selected.pageIdx;
  5239. this._selected.pageIdx = this._offset.pageIdx;
  5240. this._selected.matchIdx = this._offset.matchIdx;
  5241. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5242. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5243. this.#updatePage(previousPage);
  5244. }
  5245. }
  5246. this.#updateUIState(state, this._state.findPrevious);
  5247. if (this._selected.pageIdx !== -1) {
  5248. this._scrollMatches = true;
  5249. this.#updatePage(this._selected.pageIdx);
  5250. }
  5251. }
  5252. #onFindBarClose(evt) {
  5253. const pdfDocument = this._pdfDocument;
  5254. this._firstPageCapability.promise.then(() => {
  5255. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5256. return;
  5257. }
  5258. if (this._findTimeout) {
  5259. clearTimeout(this._findTimeout);
  5260. this._findTimeout = null;
  5261. }
  5262. if (this._resumePageIdx) {
  5263. this._resumePageIdx = null;
  5264. this._dirtyMatch = true;
  5265. }
  5266. this.#updateUIState(FindState.FOUND);
  5267. this._highlightMatches = false;
  5268. this.#updateAllPages();
  5269. });
  5270. }
  5271. #requestMatchesCount() {
  5272. const {
  5273. pageIdx,
  5274. matchIdx
  5275. } = this._selected;
  5276. let current = 0,
  5277. total = this._matchesCountTotal;
  5278. if (matchIdx !== -1) {
  5279. for (let i = 0; i < pageIdx; i++) {
  5280. current += this._pageMatches[i]?.length || 0;
  5281. }
  5282. current += matchIdx + 1;
  5283. }
  5284. if (current < 1 || current > total) {
  5285. current = total = 0;
  5286. }
  5287. return {
  5288. current,
  5289. total
  5290. };
  5291. }
  5292. #updateUIResultsCount() {
  5293. this._eventBus.dispatch("updatefindmatchescount", {
  5294. source: this,
  5295. matchesCount: this.#requestMatchesCount()
  5296. });
  5297. }
  5298. #updateUIState(state, previous = false) {
  5299. this._eventBus.dispatch("updatefindcontrolstate", {
  5300. source: this,
  5301. state,
  5302. previous,
  5303. matchesCount: this.#requestMatchesCount(),
  5304. rawQuery: this._state?.query ?? null
  5305. });
  5306. }
  5307. }
  5308. exports.PDFFindController = PDFFindController;
  5309. /***/
  5310. }),
  5311. /* 17 */
  5312. /***/ ((__unused_webpack_module, exports) => {
  5313. Object.defineProperty(exports, "__esModule", ({
  5314. value: true
  5315. }));
  5316. exports.CharacterType = void 0;
  5317. exports.getCharacterType = getCharacterType;
  5318. const CharacterType = {
  5319. SPACE: 0,
  5320. ALPHA_LETTER: 1,
  5321. PUNCT: 2,
  5322. HAN_LETTER: 3,
  5323. KATAKANA_LETTER: 4,
  5324. HIRAGANA_LETTER: 5,
  5325. HALFWIDTH_KATAKANA_LETTER: 6,
  5326. THAI_LETTER: 7
  5327. };
  5328. exports.CharacterType = CharacterType;
  5329. function isAlphabeticalScript(charCode) {
  5330. return charCode < 0x2e80;
  5331. }
  5332. function isAscii(charCode) {
  5333. return (charCode & 0xff80) === 0;
  5334. }
  5335. function isAsciiAlpha(charCode) {
  5336. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5337. }
  5338. function isAsciiDigit(charCode) {
  5339. return charCode >= 0x30 && charCode <= 0x39;
  5340. }
  5341. function isAsciiSpace(charCode) {
  5342. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5343. }
  5344. function isHan(charCode) {
  5345. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5346. }
  5347. function isKatakana(charCode) {
  5348. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5349. }
  5350. function isHiragana(charCode) {
  5351. return charCode >= 0x3040 && charCode <= 0x309f;
  5352. }
  5353. function isHalfwidthKatakana(charCode) {
  5354. return charCode >= 0xff60 && charCode <= 0xff9f;
  5355. }
  5356. function isThai(charCode) {
  5357. return (charCode & 0xff80) === 0x0e00;
  5358. }
  5359. function getCharacterType(charCode) {
  5360. if (isAlphabeticalScript(charCode)) {
  5361. if (isAscii(charCode)) {
  5362. if (isAsciiSpace(charCode)) {
  5363. return CharacterType.SPACE;
  5364. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5365. return CharacterType.ALPHA_LETTER;
  5366. }
  5367. return CharacterType.PUNCT;
  5368. } else if (isThai(charCode)) {
  5369. return CharacterType.THAI_LETTER;
  5370. } else if (charCode === 0xa0) {
  5371. return CharacterType.SPACE;
  5372. }
  5373. return CharacterType.ALPHA_LETTER;
  5374. }
  5375. if (isHan(charCode)) {
  5376. return CharacterType.HAN_LETTER;
  5377. } else if (isKatakana(charCode)) {
  5378. return CharacterType.KATAKANA_LETTER;
  5379. } else if (isHiragana(charCode)) {
  5380. return CharacterType.HIRAGANA_LETTER;
  5381. } else if (isHalfwidthKatakana(charCode)) {
  5382. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5383. }
  5384. return CharacterType.ALPHA_LETTER;
  5385. }
  5386. /***/
  5387. }),
  5388. /* 18 */
  5389. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5390. Object.defineProperty(exports, "__esModule", ({
  5391. value: true
  5392. }));
  5393. exports.PDFHistory = void 0;
  5394. exports.isDestArraysEqual = isDestArraysEqual;
  5395. exports.isDestHashesEqual = isDestHashesEqual;
  5396. var _ui_utils = __webpack_require__(1);
  5397. var _event_utils = __webpack_require__(6);
  5398. const HASH_CHANGE_TIMEOUT = 1000;
  5399. const POSITION_UPDATED_THRESHOLD = 50;
  5400. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5401. function getCurrentHash() {
  5402. return document.location.hash;
  5403. }
  5404. class PDFHistory {
  5405. constructor({
  5406. linkService,
  5407. eventBus
  5408. }) {
  5409. this.linkService = linkService;
  5410. this.eventBus = eventBus;
  5411. this._initialized = false;
  5412. this._fingerprint = "";
  5413. this.reset();
  5414. this._boundEvents = null;
  5415. this.eventBus._on("pagesinit", () => {
  5416. this._isPagesLoaded = false;
  5417. this.eventBus._on("pagesloaded", evt => {
  5418. this._isPagesLoaded = !!evt.pagesCount;
  5419. }, {
  5420. once: true
  5421. });
  5422. });
  5423. }
  5424. initialize({
  5425. fingerprint,
  5426. resetHistory = false,
  5427. updateUrl = false
  5428. }) {
  5429. if (!fingerprint || typeof fingerprint !== "string") {
  5430. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5431. return;
  5432. }
  5433. if (this._initialized) {
  5434. this.reset();
  5435. }
  5436. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5437. this._fingerprint = fingerprint;
  5438. this._updateUrl = updateUrl === true;
  5439. this._initialized = true;
  5440. this._bindEvents();
  5441. const state = window.history.state;
  5442. this._popStateInProgress = false;
  5443. this._blockHashChange = 0;
  5444. this._currentHash = getCurrentHash();
  5445. this._numPositionUpdates = 0;
  5446. this._uid = this._maxUid = 0;
  5447. this._destination = null;
  5448. this._position = null;
  5449. if (!this._isValidState(state, true) || resetHistory) {
  5450. const {
  5451. hash,
  5452. page,
  5453. rotation
  5454. } = this._parseCurrentHash(true);
  5455. if (!hash || reInitialized || resetHistory) {
  5456. this._pushOrReplaceState(null, true);
  5457. return;
  5458. }
  5459. this._pushOrReplaceState({
  5460. hash,
  5461. page,
  5462. rotation
  5463. }, true);
  5464. return;
  5465. }
  5466. const destination = state.destination;
  5467. this._updateInternalState(destination, state.uid, true);
  5468. if (destination.rotation !== undefined) {
  5469. this._initialRotation = destination.rotation;
  5470. }
  5471. if (destination.dest) {
  5472. this._initialBookmark = JSON.stringify(destination.dest);
  5473. this._destination.page = null;
  5474. } else if (destination.hash) {
  5475. this._initialBookmark = destination.hash;
  5476. } else if (destination.page) {
  5477. this._initialBookmark = `page=${destination.page}`;
  5478. }
  5479. }
  5480. reset() {
  5481. if (this._initialized) {
  5482. this._pageHide();
  5483. this._initialized = false;
  5484. this._unbindEvents();
  5485. }
  5486. if (this._updateViewareaTimeout) {
  5487. clearTimeout(this._updateViewareaTimeout);
  5488. this._updateViewareaTimeout = null;
  5489. }
  5490. this._initialBookmark = null;
  5491. this._initialRotation = null;
  5492. }
  5493. push({
  5494. namedDest = null,
  5495. explicitDest,
  5496. pageNumber
  5497. }) {
  5498. if (!this._initialized) {
  5499. return;
  5500. }
  5501. if (namedDest && typeof namedDest !== "string") {
  5502. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5503. return;
  5504. } else if (!Array.isArray(explicitDest)) {
  5505. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5506. return;
  5507. } else if (!this._isValidPage(pageNumber)) {
  5508. if (pageNumber !== null || this._destination) {
  5509. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5510. return;
  5511. }
  5512. }
  5513. const hash = namedDest || JSON.stringify(explicitDest);
  5514. if (!hash) {
  5515. return;
  5516. }
  5517. let forceReplace = false;
  5518. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5519. if (this._destination.page) {
  5520. return;
  5521. }
  5522. forceReplace = true;
  5523. }
  5524. if (this._popStateInProgress && !forceReplace) {
  5525. return;
  5526. }
  5527. this._pushOrReplaceState({
  5528. dest: explicitDest,
  5529. hash,
  5530. page: pageNumber,
  5531. rotation: this.linkService.rotation
  5532. }, forceReplace);
  5533. if (!this._popStateInProgress) {
  5534. this._popStateInProgress = true;
  5535. Promise.resolve().then(() => {
  5536. this._popStateInProgress = false;
  5537. });
  5538. }
  5539. }
  5540. pushPage(pageNumber) {
  5541. if (!this._initialized) {
  5542. return;
  5543. }
  5544. if (!this._isValidPage(pageNumber)) {
  5545. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5546. return;
  5547. }
  5548. if (this._destination?.page === pageNumber) {
  5549. return;
  5550. }
  5551. if (this._popStateInProgress) {
  5552. return;
  5553. }
  5554. this._pushOrReplaceState({
  5555. dest: null,
  5556. hash: `page=${pageNumber}`,
  5557. page: pageNumber,
  5558. rotation: this.linkService.rotation
  5559. });
  5560. if (!this._popStateInProgress) {
  5561. this._popStateInProgress = true;
  5562. Promise.resolve().then(() => {
  5563. this._popStateInProgress = false;
  5564. });
  5565. }
  5566. }
  5567. pushCurrentPosition() {
  5568. if (!this._initialized || this._popStateInProgress) {
  5569. return;
  5570. }
  5571. this._tryPushCurrentPosition();
  5572. }
  5573. back() {
  5574. if (!this._initialized || this._popStateInProgress) {
  5575. return;
  5576. }
  5577. const state = window.history.state;
  5578. if (this._isValidState(state) && state.uid > 0) {
  5579. window.history.back();
  5580. }
  5581. }
  5582. forward() {
  5583. if (!this._initialized || this._popStateInProgress) {
  5584. return;
  5585. }
  5586. const state = window.history.state;
  5587. if (this._isValidState(state) && state.uid < this._maxUid) {
  5588. window.history.forward();
  5589. }
  5590. }
  5591. get popStateInProgress() {
  5592. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5593. }
  5594. get initialBookmark() {
  5595. return this._initialized ? this._initialBookmark : null;
  5596. }
  5597. get initialRotation() {
  5598. return this._initialized ? this._initialRotation : null;
  5599. }
  5600. _pushOrReplaceState(destination, forceReplace = false) {
  5601. const shouldReplace = forceReplace || !this._destination;
  5602. const newState = {
  5603. fingerprint: this._fingerprint,
  5604. uid: shouldReplace ? this._uid : this._uid + 1,
  5605. destination
  5606. };
  5607. this._updateInternalState(destination, newState.uid);
  5608. let newUrl;
  5609. if (this._updateUrl && destination?.hash) {
  5610. const baseUrl = document.location.href.split("#")[0];
  5611. if (!baseUrl.startsWith("file://")) {
  5612. newUrl = `${baseUrl}#${destination.hash}`;
  5613. }
  5614. }
  5615. if (shouldReplace) {
  5616. window.history.replaceState(newState, "", newUrl);
  5617. } else {
  5618. window.history.pushState(newState, "", newUrl);
  5619. }
  5620. }
  5621. _tryPushCurrentPosition(temporary = false) {
  5622. if (!this._position) {
  5623. return;
  5624. }
  5625. let position = this._position;
  5626. if (temporary) {
  5627. position = Object.assign(Object.create(null), this._position);
  5628. position.temporary = true;
  5629. }
  5630. if (!this._destination) {
  5631. this._pushOrReplaceState(position);
  5632. return;
  5633. }
  5634. if (this._destination.temporary) {
  5635. this._pushOrReplaceState(position, true);
  5636. return;
  5637. }
  5638. if (this._destination.hash === position.hash) {
  5639. return;
  5640. }
  5641. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5642. return;
  5643. }
  5644. let forceReplace = false;
  5645. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5646. if (this._destination.dest !== undefined || !this._destination.first) {
  5647. return;
  5648. }
  5649. forceReplace = true;
  5650. }
  5651. this._pushOrReplaceState(position, forceReplace);
  5652. }
  5653. _isValidPage(val) {
  5654. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5655. }
  5656. _isValidState(state, checkReload = false) {
  5657. if (!state) {
  5658. return false;
  5659. }
  5660. if (state.fingerprint !== this._fingerprint) {
  5661. if (checkReload) {
  5662. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5663. return false;
  5664. }
  5665. const [perfEntry] = performance.getEntriesByType("navigation");
  5666. if (perfEntry?.type !== "reload") {
  5667. return false;
  5668. }
  5669. } else {
  5670. return false;
  5671. }
  5672. }
  5673. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5674. return false;
  5675. }
  5676. if (state.destination === null || typeof state.destination !== "object") {
  5677. return false;
  5678. }
  5679. return true;
  5680. }
  5681. _updateInternalState(destination, uid, removeTemporary = false) {
  5682. if (this._updateViewareaTimeout) {
  5683. clearTimeout(this._updateViewareaTimeout);
  5684. this._updateViewareaTimeout = null;
  5685. }
  5686. if (removeTemporary && destination?.temporary) {
  5687. delete destination.temporary;
  5688. }
  5689. this._destination = destination;
  5690. this._uid = uid;
  5691. this._maxUid = Math.max(this._maxUid, uid);
  5692. this._numPositionUpdates = 0;
  5693. }
  5694. _parseCurrentHash(checkNameddest = false) {
  5695. const hash = unescape(getCurrentHash()).substring(1);
  5696. const params = (0, _ui_utils.parseQueryString)(hash);
  5697. const nameddest = params.get("nameddest") || "";
  5698. let page = params.get("page") | 0;
  5699. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5700. page = null;
  5701. }
  5702. return {
  5703. hash,
  5704. page,
  5705. rotation: this.linkService.rotation
  5706. };
  5707. }
  5708. _updateViewarea({
  5709. location
  5710. }) {
  5711. if (this._updateViewareaTimeout) {
  5712. clearTimeout(this._updateViewareaTimeout);
  5713. this._updateViewareaTimeout = null;
  5714. }
  5715. this._position = {
  5716. hash: location.pdfOpenParams.substring(1),
  5717. page: this.linkService.page,
  5718. first: location.pageNumber,
  5719. rotation: location.rotation
  5720. };
  5721. if (this._popStateInProgress) {
  5722. return;
  5723. }
  5724. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5725. this._numPositionUpdates++;
  5726. }
  5727. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5728. this._updateViewareaTimeout = setTimeout(() => {
  5729. if (!this._popStateInProgress) {
  5730. this._tryPushCurrentPosition(true);
  5731. }
  5732. this._updateViewareaTimeout = null;
  5733. }, UPDATE_VIEWAREA_TIMEOUT);
  5734. }
  5735. }
  5736. _popState({
  5737. state
  5738. }) {
  5739. const newHash = getCurrentHash(),
  5740. hashChanged = this._currentHash !== newHash;
  5741. this._currentHash = newHash;
  5742. if (!state) {
  5743. this._uid++;
  5744. const {
  5745. hash,
  5746. page,
  5747. rotation
  5748. } = this._parseCurrentHash();
  5749. this._pushOrReplaceState({
  5750. hash,
  5751. page,
  5752. rotation
  5753. }, true);
  5754. return;
  5755. }
  5756. if (!this._isValidState(state)) {
  5757. return;
  5758. }
  5759. this._popStateInProgress = true;
  5760. if (hashChanged) {
  5761. this._blockHashChange++;
  5762. (0, _event_utils.waitOnEventOrTimeout)({
  5763. target: window,
  5764. name: "hashchange",
  5765. delay: HASH_CHANGE_TIMEOUT
  5766. }).then(() => {
  5767. this._blockHashChange--;
  5768. });
  5769. }
  5770. const destination = state.destination;
  5771. this._updateInternalState(destination, state.uid, true);
  5772. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5773. this.linkService.rotation = destination.rotation;
  5774. }
  5775. if (destination.dest) {
  5776. this.linkService.goToDestination(destination.dest);
  5777. } else if (destination.hash) {
  5778. this.linkService.setHash(destination.hash);
  5779. } else if (destination.page) {
  5780. this.linkService.page = destination.page;
  5781. }
  5782. Promise.resolve().then(() => {
  5783. this._popStateInProgress = false;
  5784. });
  5785. }
  5786. _pageHide() {
  5787. if (!this._destination || this._destination.temporary) {
  5788. this._tryPushCurrentPosition();
  5789. }
  5790. }
  5791. _bindEvents() {
  5792. if (this._boundEvents) {
  5793. return;
  5794. }
  5795. this._boundEvents = {
  5796. updateViewarea: this._updateViewarea.bind(this),
  5797. popState: this._popState.bind(this),
  5798. pageHide: this._pageHide.bind(this)
  5799. };
  5800. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5801. window.addEventListener("popstate", this._boundEvents.popState);
  5802. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5803. }
  5804. _unbindEvents() {
  5805. if (!this._boundEvents) {
  5806. return;
  5807. }
  5808. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5809. window.removeEventListener("popstate", this._boundEvents.popState);
  5810. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5811. this._boundEvents = null;
  5812. }
  5813. }
  5814. exports.PDFHistory = PDFHistory;
  5815. function isDestHashesEqual(destHash, pushHash) {
  5816. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5817. return false;
  5818. }
  5819. if (destHash === pushHash) {
  5820. return true;
  5821. }
  5822. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  5823. if (nameddest === pushHash) {
  5824. return true;
  5825. }
  5826. return false;
  5827. }
  5828. function isDestArraysEqual(firstDest, secondDest) {
  5829. function isEntryEqual(first, second) {
  5830. if (typeof first !== typeof second) {
  5831. return false;
  5832. }
  5833. if (Array.isArray(first) || Array.isArray(second)) {
  5834. return false;
  5835. }
  5836. if (first !== null && typeof first === "object" && second !== null) {
  5837. if (Object.keys(first).length !== Object.keys(second).length) {
  5838. return false;
  5839. }
  5840. for (const key in first) {
  5841. if (!isEntryEqual(first[key], second[key])) {
  5842. return false;
  5843. }
  5844. }
  5845. return true;
  5846. }
  5847. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5848. }
  5849. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5850. return false;
  5851. }
  5852. if (firstDest.length !== secondDest.length) {
  5853. return false;
  5854. }
  5855. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5856. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5857. return false;
  5858. }
  5859. }
  5860. return true;
  5861. }
  5862. /***/
  5863. }),
  5864. /* 19 */
  5865. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5866. Object.defineProperty(exports, "__esModule", ({
  5867. value: true
  5868. }));
  5869. exports.PDFLayerViewer = void 0;
  5870. var _base_tree_viewer = __webpack_require__(13);
  5871. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5872. constructor(options) {
  5873. super(options);
  5874. this.l10n = options.l10n;
  5875. this.eventBus._on("resetlayers", this._resetLayers.bind(this));
  5876. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5877. }
  5878. reset() {
  5879. super.reset();
  5880. this._optionalContentConfig = null;
  5881. }
  5882. _dispatchEvent(layersCount) {
  5883. this.eventBus.dispatch("layersloaded", {
  5884. source: this,
  5885. layersCount
  5886. });
  5887. }
  5888. _bindLink(element, {
  5889. groupId,
  5890. input
  5891. }) {
  5892. const setVisibility = () => {
  5893. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5894. this.eventBus.dispatch("optionalcontentconfig", {
  5895. source: this,
  5896. promise: Promise.resolve(this._optionalContentConfig)
  5897. });
  5898. };
  5899. element.onclick = evt => {
  5900. if (evt.target === input) {
  5901. setVisibility();
  5902. return true;
  5903. } else if (evt.target !== element) {
  5904. return true;
  5905. }
  5906. input.checked = !input.checked;
  5907. setVisibility();
  5908. return false;
  5909. };
  5910. }
  5911. async _setNestedName(element, {
  5912. name = null
  5913. }) {
  5914. if (typeof name === "string") {
  5915. element.textContent = this._normalizeTextContent(name);
  5916. return;
  5917. }
  5918. element.textContent = await this.l10n.get("additional_layers");
  5919. element.style.fontStyle = "italic";
  5920. }
  5921. _addToggleButton(div, {
  5922. name = null
  5923. }) {
  5924. super._addToggleButton(div, name === null);
  5925. }
  5926. _toggleAllTreeItems() {
  5927. if (!this._optionalContentConfig) {
  5928. return;
  5929. }
  5930. super._toggleAllTreeItems();
  5931. }
  5932. render({
  5933. optionalContentConfig,
  5934. pdfDocument
  5935. }) {
  5936. if (this._optionalContentConfig) {
  5937. this.reset();
  5938. }
  5939. this._optionalContentConfig = optionalContentConfig || null;
  5940. this._pdfDocument = pdfDocument || null;
  5941. const groups = optionalContentConfig?.getOrder();
  5942. if (!groups) {
  5943. this._dispatchEvent(0);
  5944. return;
  5945. }
  5946. const fragment = document.createDocumentFragment(),
  5947. queue = [{
  5948. parent: fragment,
  5949. groups
  5950. }];
  5951. let layersCount = 0,
  5952. hasAnyNesting = false;
  5953. while (queue.length > 0) {
  5954. const levelData = queue.shift();
  5955. for (const groupId of levelData.groups) {
  5956. const div = document.createElement("div");
  5957. div.className = "treeItem";
  5958. const element = document.createElement("a");
  5959. div.append(element);
  5960. if (typeof groupId === "object") {
  5961. hasAnyNesting = true;
  5962. this._addToggleButton(div, groupId);
  5963. this._setNestedName(element, groupId);
  5964. const itemsDiv = document.createElement("div");
  5965. itemsDiv.className = "treeItems";
  5966. div.append(itemsDiv);
  5967. queue.push({
  5968. parent: itemsDiv,
  5969. groups: groupId.order
  5970. });
  5971. } else {
  5972. const group = optionalContentConfig.getGroup(groupId);
  5973. const input = document.createElement("input");
  5974. this._bindLink(element, {
  5975. groupId,
  5976. input
  5977. });
  5978. input.type = "checkbox";
  5979. input.checked = group.visible;
  5980. const label = document.createElement("label");
  5981. label.textContent = this._normalizeTextContent(group.name);
  5982. label.append(input);
  5983. element.append(label);
  5984. layersCount++;
  5985. }
  5986. levelData.parent.append(div);
  5987. }
  5988. }
  5989. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5990. }
  5991. async _resetLayers() {
  5992. if (!this._optionalContentConfig) {
  5993. return;
  5994. }
  5995. const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
  5996. this.eventBus.dispatch("optionalcontentconfig", {
  5997. source: this,
  5998. promise: Promise.resolve(optionalContentConfig)
  5999. });
  6000. this.render({
  6001. optionalContentConfig,
  6002. pdfDocument: this._pdfDocument
  6003. });
  6004. }
  6005. }
  6006. exports.PDFLayerViewer = PDFLayerViewer;
  6007. /***/
  6008. }),
  6009. /* 20 */
  6010. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6011. Object.defineProperty(exports, "__esModule", ({
  6012. value: true
  6013. }));
  6014. exports.PDFOutlineViewer = void 0;
  6015. var _base_tree_viewer = __webpack_require__(13);
  6016. var _pdfjsLib = __webpack_require__(5);
  6017. var _ui_utils = __webpack_require__(1);
  6018. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  6019. constructor(options) {
  6020. super(options);
  6021. this.linkService = options.linkService;
  6022. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6023. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6024. this.eventBus._on("pagechanging", evt => {
  6025. this._currentPageNumber = evt.pageNumber;
  6026. });
  6027. this.eventBus._on("pagesloaded", evt => {
  6028. this._isPagesLoaded = !!evt.pagesCount;
  6029. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6030. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6031. }
  6032. });
  6033. this.eventBus._on("sidebarviewchanged", evt => {
  6034. this._sidebarView = evt.view;
  6035. });
  6036. }
  6037. reset() {
  6038. super.reset();
  6039. this._outline = null;
  6040. this._pageNumberToDestHashCapability = null;
  6041. this._currentPageNumber = 1;
  6042. this._isPagesLoaded = null;
  6043. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6044. this._currentOutlineItemCapability.resolve(false);
  6045. }
  6046. this._currentOutlineItemCapability = null;
  6047. }
  6048. _dispatchEvent(outlineCount) {
  6049. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  6050. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  6051. this._currentOutlineItemCapability.resolve(false);
  6052. } else if (this._isPagesLoaded !== null) {
  6053. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6054. }
  6055. this.eventBus.dispatch("outlineloaded", {
  6056. source: this,
  6057. outlineCount,
  6058. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6059. });
  6060. }
  6061. _bindLink(element, {
  6062. url,
  6063. newWindow,
  6064. dest
  6065. }) {
  6066. const {
  6067. linkService
  6068. } = this;
  6069. if (url) {
  6070. linkService.addLinkAttributes(element, url, newWindow);
  6071. return;
  6072. }
  6073. element.href = linkService.getDestinationHash(dest);
  6074. element.onclick = evt => {
  6075. this._updateCurrentTreeItem(evt.target.parentNode);
  6076. if (dest) {
  6077. linkService.goToDestination(dest);
  6078. }
  6079. return false;
  6080. };
  6081. }
  6082. _setStyles(element, {
  6083. bold,
  6084. italic
  6085. }) {
  6086. if (bold) {
  6087. element.style.fontWeight = "bold";
  6088. }
  6089. if (italic) {
  6090. element.style.fontStyle = "italic";
  6091. }
  6092. }
  6093. _addToggleButton(div, {
  6094. count,
  6095. items
  6096. }) {
  6097. let hidden = false;
  6098. if (count < 0) {
  6099. let totalCount = items.length;
  6100. if (totalCount > 0) {
  6101. const queue = [...items];
  6102. while (queue.length > 0) {
  6103. const {
  6104. count: nestedCount,
  6105. items: nestedItems
  6106. } = queue.shift();
  6107. if (nestedCount > 0 && nestedItems.length > 0) {
  6108. totalCount += nestedItems.length;
  6109. queue.push(...nestedItems);
  6110. }
  6111. }
  6112. }
  6113. if (Math.abs(count) === totalCount) {
  6114. hidden = true;
  6115. }
  6116. }
  6117. super._addToggleButton(div, hidden);
  6118. }
  6119. _toggleAllTreeItems() {
  6120. if (!this._outline) {
  6121. return;
  6122. }
  6123. super._toggleAllTreeItems();
  6124. }
  6125. render({
  6126. outline,
  6127. pdfDocument
  6128. }) {
  6129. if (this._outline) {
  6130. this.reset();
  6131. }
  6132. this._outline = outline || null;
  6133. this._pdfDocument = pdfDocument || null;
  6134. if (!outline) {
  6135. this._dispatchEvent(0);
  6136. return;
  6137. }
  6138. const fragment = document.createDocumentFragment();
  6139. const queue = [{
  6140. parent: fragment,
  6141. items: outline
  6142. }];
  6143. let outlineCount = 0,
  6144. hasAnyNesting = false;
  6145. while (queue.length > 0) {
  6146. const levelData = queue.shift();
  6147. for (const item of levelData.items) {
  6148. const div = document.createElement("div");
  6149. div.className = "treeItem";
  6150. const element = document.createElement("a");
  6151. this._bindLink(element, item);
  6152. this._setStyles(element, item);
  6153. element.textContent = this._normalizeTextContent(item.title);
  6154. div.append(element);
  6155. if (item.items.length > 0) {
  6156. hasAnyNesting = true;
  6157. this._addToggleButton(div, item);
  6158. const itemsDiv = document.createElement("div");
  6159. itemsDiv.className = "treeItems";
  6160. div.append(itemsDiv);
  6161. queue.push({
  6162. parent: itemsDiv,
  6163. items: item.items
  6164. });
  6165. }
  6166. levelData.parent.append(div);
  6167. outlineCount++;
  6168. }
  6169. }
  6170. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6171. }
  6172. async _currentOutlineItem() {
  6173. if (!this._isPagesLoaded) {
  6174. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6175. }
  6176. if (!this._outline || !this._pdfDocument) {
  6177. return;
  6178. }
  6179. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6180. if (!pageNumberToDestHash) {
  6181. return;
  6182. }
  6183. this._updateCurrentTreeItem(null);
  6184. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6185. return;
  6186. }
  6187. for (let i = this._currentPageNumber; i > 0; i--) {
  6188. const destHash = pageNumberToDestHash.get(i);
  6189. if (!destHash) {
  6190. continue;
  6191. }
  6192. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6193. if (!linkElement) {
  6194. continue;
  6195. }
  6196. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6197. break;
  6198. }
  6199. }
  6200. async _getPageNumberToDestHash(pdfDocument) {
  6201. if (this._pageNumberToDestHashCapability) {
  6202. return this._pageNumberToDestHashCapability.promise;
  6203. }
  6204. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6205. const pageNumberToDestHash = new Map(),
  6206. pageNumberNesting = new Map();
  6207. const queue = [{
  6208. nesting: 0,
  6209. items: this._outline
  6210. }];
  6211. while (queue.length > 0) {
  6212. const levelData = queue.shift(),
  6213. currentNesting = levelData.nesting;
  6214. for (const {
  6215. dest,
  6216. items
  6217. } of levelData.items) {
  6218. let explicitDest, pageNumber;
  6219. if (typeof dest === "string") {
  6220. explicitDest = await pdfDocument.getDestination(dest);
  6221. if (pdfDocument !== this._pdfDocument) {
  6222. return null;
  6223. }
  6224. } else {
  6225. explicitDest = dest;
  6226. }
  6227. if (Array.isArray(explicitDest)) {
  6228. const [destRef] = explicitDest;
  6229. if (typeof destRef === "object" && destRef !== null) {
  6230. pageNumber = this.linkService._cachedPageNumber(destRef);
  6231. if (!pageNumber) {
  6232. try {
  6233. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6234. if (pdfDocument !== this._pdfDocument) {
  6235. return null;
  6236. }
  6237. this.linkService.cachePageRef(pageNumber, destRef);
  6238. } catch (ex) { }
  6239. }
  6240. } else if (Number.isInteger(destRef)) {
  6241. pageNumber = destRef + 1;
  6242. }
  6243. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6244. const destHash = this.linkService.getDestinationHash(dest);
  6245. pageNumberToDestHash.set(pageNumber, destHash);
  6246. pageNumberNesting.set(pageNumber, currentNesting);
  6247. }
  6248. }
  6249. if (items.length > 0) {
  6250. queue.push({
  6251. nesting: currentNesting + 1,
  6252. items
  6253. });
  6254. }
  6255. }
  6256. }
  6257. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6258. return this._pageNumberToDestHashCapability.promise;
  6259. }
  6260. }
  6261. exports.PDFOutlineViewer = PDFOutlineViewer;
  6262. /***/
  6263. }),
  6264. /* 21 */
  6265. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6266. Object.defineProperty(exports, "__esModule", ({
  6267. value: true
  6268. }));
  6269. exports.PDFPresentationMode = void 0;
  6270. var _ui_utils = __webpack_require__(1);
  6271. var _pdfjsLib = __webpack_require__(5);
  6272. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6273. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6274. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6275. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6276. const PAGE_SWITCH_THRESHOLD = 0.1;
  6277. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6278. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6279. class PDFPresentationMode {
  6280. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6281. #args = null;
  6282. constructor({
  6283. container,
  6284. pdfViewer,
  6285. eventBus
  6286. }) {
  6287. this.container = container;
  6288. this.pdfViewer = pdfViewer;
  6289. this.eventBus = eventBus;
  6290. this.contextMenuOpen = false;
  6291. this.mouseScrollTimeStamp = 0;
  6292. this.mouseScrollDelta = 0;
  6293. this.touchSwipeState = null;
  6294. }
  6295. async request() {
  6296. const {
  6297. container,
  6298. pdfViewer
  6299. } = this;
  6300. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6301. return false;
  6302. }
  6303. this.#addFullscreenChangeListeners();
  6304. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6305. const promise = container.requestFullscreen();
  6306. this.#args = {
  6307. pageNumber: pdfViewer.currentPageNumber,
  6308. scaleValue: pdfViewer.currentScaleValue,
  6309. scrollMode: pdfViewer.scrollMode,
  6310. spreadMode: null,
  6311. annotationEditorMode: null
  6312. };
  6313. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6314. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6315. this.#args.spreadMode = pdfViewer.spreadMode;
  6316. }
  6317. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6318. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6319. }
  6320. try {
  6321. await promise;
  6322. pdfViewer.focus();
  6323. return true;
  6324. } catch (reason) {
  6325. this.#removeFullscreenChangeListeners();
  6326. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6327. }
  6328. return false;
  6329. }
  6330. get active() {
  6331. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6332. }
  6333. #mouseWheel(evt) {
  6334. if (!this.active) {
  6335. return;
  6336. }
  6337. evt.preventDefault();
  6338. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6339. const currentTime = Date.now();
  6340. const storedTime = this.mouseScrollTimeStamp;
  6341. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6342. return;
  6343. }
  6344. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6345. this.#resetMouseScrollState();
  6346. }
  6347. this.mouseScrollDelta += delta;
  6348. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6349. const totalDelta = this.mouseScrollDelta;
  6350. this.#resetMouseScrollState();
  6351. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6352. if (success) {
  6353. this.mouseScrollTimeStamp = currentTime;
  6354. }
  6355. }
  6356. }
  6357. #notifyStateChange(state) {
  6358. this.#state = state;
  6359. this.eventBus.dispatch("presentationmodechanged", {
  6360. source: this,
  6361. state
  6362. });
  6363. }
  6364. #enter() {
  6365. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6366. this.container.classList.add(ACTIVE_SELECTOR);
  6367. setTimeout(() => {
  6368. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6369. if (this.#args.spreadMode !== null) {
  6370. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6371. }
  6372. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6373. this.pdfViewer.currentScaleValue = "page-fit";
  6374. if (this.#args.annotationEditorMode !== null) {
  6375. this.pdfViewer.annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  6376. }
  6377. }, 0);
  6378. this.#addWindowListeners();
  6379. this.#showControls();
  6380. this.contextMenuOpen = false;
  6381. window.getSelection().removeAllRanges();
  6382. }
  6383. #exit() {
  6384. const pageNumber = this.pdfViewer.currentPageNumber;
  6385. this.container.classList.remove(ACTIVE_SELECTOR);
  6386. setTimeout(() => {
  6387. this.#removeFullscreenChangeListeners();
  6388. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6389. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6390. if (this.#args.spreadMode !== null) {
  6391. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6392. }
  6393. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6394. this.pdfViewer.currentPageNumber = pageNumber;
  6395. if (this.#args.annotationEditorMode !== null) {
  6396. this.pdfViewer.annotationEditorMode = this.#args.annotationEditorMode;
  6397. }
  6398. this.#args = null;
  6399. }, 0);
  6400. this.#removeWindowListeners();
  6401. this.#hideControls();
  6402. this.#resetMouseScrollState();
  6403. this.contextMenuOpen = false;
  6404. }
  6405. #mouseDown(evt) {
  6406. if (this.contextMenuOpen) {
  6407. this.contextMenuOpen = false;
  6408. evt.preventDefault();
  6409. return;
  6410. }
  6411. if (evt.button === 0) {
  6412. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6413. if (!isInternalLink) {
  6414. evt.preventDefault();
  6415. if (evt.shiftKey) {
  6416. this.pdfViewer.previousPage();
  6417. } else {
  6418. this.pdfViewer.nextPage();
  6419. }
  6420. }
  6421. }
  6422. }
  6423. #contextMenu() {
  6424. this.contextMenuOpen = true;
  6425. }
  6426. #showControls() {
  6427. if (this.controlsTimeout) {
  6428. clearTimeout(this.controlsTimeout);
  6429. } else {
  6430. this.container.classList.add(CONTROLS_SELECTOR);
  6431. }
  6432. this.controlsTimeout = setTimeout(() => {
  6433. this.container.classList.remove(CONTROLS_SELECTOR);
  6434. delete this.controlsTimeout;
  6435. }, DELAY_BEFORE_HIDING_CONTROLS);
  6436. }
  6437. #hideControls() {
  6438. if (!this.controlsTimeout) {
  6439. return;
  6440. }
  6441. clearTimeout(this.controlsTimeout);
  6442. this.container.classList.remove(CONTROLS_SELECTOR);
  6443. delete this.controlsTimeout;
  6444. }
  6445. #resetMouseScrollState() {
  6446. this.mouseScrollTimeStamp = 0;
  6447. this.mouseScrollDelta = 0;
  6448. }
  6449. #touchSwipe(evt) {
  6450. if (!this.active) {
  6451. return;
  6452. }
  6453. if (evt.touches.length > 1) {
  6454. this.touchSwipeState = null;
  6455. return;
  6456. }
  6457. switch (evt.type) {
  6458. case "touchstart":
  6459. this.touchSwipeState = {
  6460. startX: evt.touches[0].pageX,
  6461. startY: evt.touches[0].pageY,
  6462. endX: evt.touches[0].pageX,
  6463. endY: evt.touches[0].pageY
  6464. };
  6465. break;
  6466. case "touchmove":
  6467. if (this.touchSwipeState === null) {
  6468. return;
  6469. }
  6470. this.touchSwipeState.endX = evt.touches[0].pageX;
  6471. this.touchSwipeState.endY = evt.touches[0].pageY;
  6472. evt.preventDefault();
  6473. break;
  6474. case "touchend":
  6475. if (this.touchSwipeState === null) {
  6476. return;
  6477. }
  6478. let delta = 0;
  6479. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6480. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6481. const absAngle = Math.abs(Math.atan2(dy, dx));
  6482. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6483. delta = dx;
  6484. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6485. delta = dy;
  6486. }
  6487. if (delta > 0) {
  6488. this.pdfViewer.previousPage();
  6489. } else if (delta < 0) {
  6490. this.pdfViewer.nextPage();
  6491. }
  6492. break;
  6493. }
  6494. }
  6495. #addWindowListeners() {
  6496. this.showControlsBind = this.#showControls.bind(this);
  6497. this.mouseDownBind = this.#mouseDown.bind(this);
  6498. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6499. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6500. this.contextMenuBind = this.#contextMenu.bind(this);
  6501. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6502. window.addEventListener("mousemove", this.showControlsBind);
  6503. window.addEventListener("mousedown", this.mouseDownBind);
  6504. window.addEventListener("wheel", this.mouseWheelBind, {
  6505. passive: false
  6506. });
  6507. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6508. window.addEventListener("contextmenu", this.contextMenuBind);
  6509. window.addEventListener("touchstart", this.touchSwipeBind);
  6510. window.addEventListener("touchmove", this.touchSwipeBind);
  6511. window.addEventListener("touchend", this.touchSwipeBind);
  6512. }
  6513. #removeWindowListeners() {
  6514. window.removeEventListener("mousemove", this.showControlsBind);
  6515. window.removeEventListener("mousedown", this.mouseDownBind);
  6516. window.removeEventListener("wheel", this.mouseWheelBind, {
  6517. passive: false
  6518. });
  6519. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6520. window.removeEventListener("contextmenu", this.contextMenuBind);
  6521. window.removeEventListener("touchstart", this.touchSwipeBind);
  6522. window.removeEventListener("touchmove", this.touchSwipeBind);
  6523. window.removeEventListener("touchend", this.touchSwipeBind);
  6524. delete this.showControlsBind;
  6525. delete this.mouseDownBind;
  6526. delete this.mouseWheelBind;
  6527. delete this.resetMouseScrollStateBind;
  6528. delete this.contextMenuBind;
  6529. delete this.touchSwipeBind;
  6530. }
  6531. #fullscreenChange() {
  6532. if (document.fullscreenElement) {
  6533. this.#enter();
  6534. } else {
  6535. this.#exit();
  6536. }
  6537. }
  6538. #addFullscreenChangeListeners() {
  6539. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6540. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6541. }
  6542. #removeFullscreenChangeListeners() {
  6543. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6544. delete this.fullscreenChangeBind;
  6545. }
  6546. }
  6547. exports.PDFPresentationMode = PDFPresentationMode;
  6548. /***/
  6549. }),
  6550. /* 22 */
  6551. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6552. Object.defineProperty(exports, "__esModule", ({
  6553. value: true
  6554. }));
  6555. exports.PDFRenderingQueue = void 0;
  6556. var _pdfjsLib = __webpack_require__(5);
  6557. var _ui_utils = __webpack_require__(1);
  6558. const CLEANUP_TIMEOUT = 30000;
  6559. class PDFRenderingQueue {
  6560. constructor() {
  6561. this.pdfViewer = null;
  6562. this.pdfThumbnailViewer = null;
  6563. this.onIdle = null;
  6564. this.highestPriorityPage = null;
  6565. this.idleTimeout = null;
  6566. this.printing = false;
  6567. this.isThumbnailViewEnabled = false;
  6568. }
  6569. setViewer(pdfViewer) {
  6570. this.pdfViewer = pdfViewer;
  6571. }
  6572. setThumbnailViewer(pdfThumbnailViewer) {
  6573. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6574. }
  6575. isHighestPriority(view) {
  6576. return this.highestPriorityPage === view.renderingId;
  6577. }
  6578. hasViewer() {
  6579. return !!this.pdfViewer;
  6580. }
  6581. renderHighestPriority(currentlyVisiblePages) {
  6582. if (this.idleTimeout) {
  6583. clearTimeout(this.idleTimeout);
  6584. this.idleTimeout = null;
  6585. }
  6586. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6587. return;
  6588. }
  6589. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6590. return;
  6591. }
  6592. if (this.printing) {
  6593. return;
  6594. }
  6595. if (this.onIdle) {
  6596. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6597. }
  6598. }
  6599. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6600. const visibleViews = visible.views,
  6601. numVisible = visibleViews.length;
  6602. if (numVisible === 0) {
  6603. return null;
  6604. }
  6605. for (let i = 0; i < numVisible; i++) {
  6606. const view = visibleViews[i].view;
  6607. if (!this.isViewFinished(view)) {
  6608. return view;
  6609. }
  6610. }
  6611. const firstId = visible.first.id,
  6612. lastId = visible.last.id;
  6613. if (lastId - firstId + 1 > numVisible) {
  6614. const visibleIds = visible.ids;
  6615. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6616. const holeId = scrolledDown ? firstId + i : lastId - i;
  6617. if (visibleIds.has(holeId)) {
  6618. continue;
  6619. }
  6620. const holeView = views[holeId - 1];
  6621. if (!this.isViewFinished(holeView)) {
  6622. return holeView;
  6623. }
  6624. }
  6625. }
  6626. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6627. let preRenderView = views[preRenderIndex];
  6628. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6629. return preRenderView;
  6630. }
  6631. if (preRenderExtra) {
  6632. preRenderIndex += scrolledDown ? 1 : -1;
  6633. preRenderView = views[preRenderIndex];
  6634. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6635. return preRenderView;
  6636. }
  6637. }
  6638. return null;
  6639. }
  6640. isViewFinished(view) {
  6641. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6642. }
  6643. renderView(view) {
  6644. switch (view.renderingState) {
  6645. case _ui_utils.RenderingStates.FINISHED:
  6646. return false;
  6647. case _ui_utils.RenderingStates.PAUSED:
  6648. this.highestPriorityPage = view.renderingId;
  6649. view.resume();
  6650. break;
  6651. case _ui_utils.RenderingStates.RUNNING:
  6652. this.highestPriorityPage = view.renderingId;
  6653. break;
  6654. case _ui_utils.RenderingStates.INITIAL:
  6655. this.highestPriorityPage = view.renderingId;
  6656. view.draw().finally(() => {
  6657. this.renderHighestPriority();
  6658. }).catch(reason => {
  6659. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6660. return;
  6661. }
  6662. console.error(`renderView: "${reason}"`);
  6663. });
  6664. break;
  6665. }
  6666. return true;
  6667. }
  6668. }
  6669. exports.PDFRenderingQueue = PDFRenderingQueue;
  6670. /***/
  6671. }),
  6672. /* 23 */
  6673. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6674. Object.defineProperty(exports, "__esModule", ({
  6675. value: true
  6676. }));
  6677. exports.PDFScriptingManager = void 0;
  6678. var _ui_utils = __webpack_require__(1);
  6679. var _pdfjsLib = __webpack_require__(5);
  6680. class PDFScriptingManager {
  6681. constructor({
  6682. eventBus,
  6683. sandboxBundleSrc = null,
  6684. scriptingFactory = null,
  6685. docPropertiesLookup = null
  6686. }) {
  6687. this._pdfDocument = null;
  6688. this._pdfViewer = null;
  6689. this._closeCapability = null;
  6690. this._destroyCapability = null;
  6691. this._scripting = null;
  6692. this._mouseState = Object.create(null);
  6693. this._ready = false;
  6694. this._eventBus = eventBus;
  6695. this._sandboxBundleSrc = sandboxBundleSrc;
  6696. this._scriptingFactory = scriptingFactory;
  6697. this._docPropertiesLookup = docPropertiesLookup;
  6698. }
  6699. setViewer(pdfViewer) {
  6700. this._pdfViewer = pdfViewer;
  6701. }
  6702. async setDocument(pdfDocument) {
  6703. if (this._pdfDocument) {
  6704. await this._destroyScripting();
  6705. }
  6706. this._pdfDocument = pdfDocument;
  6707. if (!pdfDocument) {
  6708. return;
  6709. }
  6710. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6711. if (!objects && !docActions) {
  6712. await this._destroyScripting();
  6713. return;
  6714. }
  6715. if (pdfDocument !== this._pdfDocument) {
  6716. return;
  6717. }
  6718. try {
  6719. this._scripting = this._createScripting();
  6720. } catch (error) {
  6721. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6722. await this._destroyScripting();
  6723. return;
  6724. }
  6725. this._internalEvents.set("updatefromsandbox", event => {
  6726. if (event?.source !== window) {
  6727. return;
  6728. }
  6729. this._updateFromSandbox(event.detail);
  6730. });
  6731. this._internalEvents.set("dispatcheventinsandbox", event => {
  6732. this._scripting?.dispatchEventInSandbox(event.detail);
  6733. });
  6734. this._internalEvents.set("pagechanging", ({
  6735. pageNumber,
  6736. previous
  6737. }) => {
  6738. if (pageNumber === previous) {
  6739. return;
  6740. }
  6741. this._dispatchPageClose(previous);
  6742. this._dispatchPageOpen(pageNumber);
  6743. });
  6744. this._internalEvents.set("pagerendered", ({
  6745. pageNumber
  6746. }) => {
  6747. if (!this._pageOpenPending.has(pageNumber)) {
  6748. return;
  6749. }
  6750. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6751. return;
  6752. }
  6753. this._dispatchPageOpen(pageNumber);
  6754. });
  6755. this._internalEvents.set("pagesdestroy", async event => {
  6756. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6757. await this._scripting?.dispatchEventInSandbox({
  6758. id: "doc",
  6759. name: "WillClose"
  6760. });
  6761. this._closeCapability?.resolve();
  6762. });
  6763. this._domEvents.set("mousedown", event => {
  6764. this._mouseState.isDown = true;
  6765. });
  6766. this._domEvents.set("mouseup", event => {
  6767. this._mouseState.isDown = false;
  6768. });
  6769. for (const [name, listener] of this._internalEvents) {
  6770. this._eventBus._on(name, listener);
  6771. }
  6772. for (const [name, listener] of this._domEvents) {
  6773. window.addEventListener(name, listener, true);
  6774. }
  6775. try {
  6776. const docProperties = await this._getDocProperties();
  6777. if (pdfDocument !== this._pdfDocument) {
  6778. return;
  6779. }
  6780. await this._scripting.createSandbox({
  6781. objects,
  6782. calculationOrder,
  6783. appInfo: {
  6784. platform: navigator.platform,
  6785. language: navigator.language
  6786. },
  6787. docInfo: {
  6788. ...docProperties,
  6789. actions: docActions
  6790. }
  6791. });
  6792. this._eventBus.dispatch("sandboxcreated", {
  6793. source: this
  6794. });
  6795. } catch (error) {
  6796. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6797. await this._destroyScripting();
  6798. return;
  6799. }
  6800. await this._scripting?.dispatchEventInSandbox({
  6801. id: "doc",
  6802. name: "Open"
  6803. });
  6804. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6805. Promise.resolve().then(() => {
  6806. if (pdfDocument === this._pdfDocument) {
  6807. this._ready = true;
  6808. }
  6809. });
  6810. }
  6811. async dispatchWillSave(detail) {
  6812. return this._scripting?.dispatchEventInSandbox({
  6813. id: "doc",
  6814. name: "WillSave"
  6815. });
  6816. }
  6817. async dispatchDidSave(detail) {
  6818. return this._scripting?.dispatchEventInSandbox({
  6819. id: "doc",
  6820. name: "DidSave"
  6821. });
  6822. }
  6823. async dispatchWillPrint(detail) {
  6824. return this._scripting?.dispatchEventInSandbox({
  6825. id: "doc",
  6826. name: "WillPrint"
  6827. });
  6828. }
  6829. async dispatchDidPrint(detail) {
  6830. return this._scripting?.dispatchEventInSandbox({
  6831. id: "doc",
  6832. name: "DidPrint"
  6833. });
  6834. }
  6835. get mouseState() {
  6836. return this._mouseState;
  6837. }
  6838. get destroyPromise() {
  6839. return this._destroyCapability?.promise || null;
  6840. }
  6841. get ready() {
  6842. return this._ready;
  6843. }
  6844. get _internalEvents() {
  6845. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6846. }
  6847. get _domEvents() {
  6848. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6849. }
  6850. get _pageOpenPending() {
  6851. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6852. }
  6853. get _visitedPages() {
  6854. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6855. }
  6856. async _updateFromSandbox(detail) {
  6857. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6858. const {
  6859. id,
  6860. siblings,
  6861. command,
  6862. value
  6863. } = detail;
  6864. if (!id) {
  6865. switch (command) {
  6866. case "clear":
  6867. console.clear();
  6868. break;
  6869. case "error":
  6870. console.error(value);
  6871. break;
  6872. case "layout":
  6873. if (isInPresentationMode) {
  6874. return;
  6875. }
  6876. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  6877. this._pdfViewer.spreadMode = modes.spreadMode;
  6878. break;
  6879. case "page-num":
  6880. this._pdfViewer.currentPageNumber = value + 1;
  6881. break;
  6882. case "print":
  6883. await this._pdfViewer.pagesPromise;
  6884. this._eventBus.dispatch("print", {
  6885. source: this
  6886. });
  6887. break;
  6888. case "println":
  6889. console.log(value);
  6890. break;
  6891. case "zoom":
  6892. if (isInPresentationMode) {
  6893. return;
  6894. }
  6895. this._pdfViewer.currentScaleValue = value;
  6896. break;
  6897. case "SaveAs":
  6898. this._eventBus.dispatch("download", {
  6899. source: this
  6900. });
  6901. break;
  6902. case "FirstPage":
  6903. this._pdfViewer.currentPageNumber = 1;
  6904. break;
  6905. case "LastPage":
  6906. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  6907. break;
  6908. case "NextPage":
  6909. this._pdfViewer.nextPage();
  6910. break;
  6911. case "PrevPage":
  6912. this._pdfViewer.previousPage();
  6913. break;
  6914. case "ZoomViewIn":
  6915. if (isInPresentationMode) {
  6916. return;
  6917. }
  6918. this._pdfViewer.increaseScale();
  6919. break;
  6920. case "ZoomViewOut":
  6921. if (isInPresentationMode) {
  6922. return;
  6923. }
  6924. this._pdfViewer.decreaseScale();
  6925. break;
  6926. }
  6927. return;
  6928. }
  6929. if (isInPresentationMode) {
  6930. if (detail.focus) {
  6931. return;
  6932. }
  6933. }
  6934. delete detail.id;
  6935. delete detail.siblings;
  6936. const ids = siblings ? [id, ...siblings] : [id];
  6937. for (const elementId of ids) {
  6938. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  6939. if (element) {
  6940. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6941. detail
  6942. }));
  6943. } else {
  6944. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6945. }
  6946. }
  6947. }
  6948. async _dispatchPageOpen(pageNumber, initialize = false) {
  6949. const pdfDocument = this._pdfDocument,
  6950. visitedPages = this._visitedPages;
  6951. if (initialize) {
  6952. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6953. }
  6954. if (!this._closeCapability) {
  6955. return;
  6956. }
  6957. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6958. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  6959. this._pageOpenPending.add(pageNumber);
  6960. return;
  6961. }
  6962. this._pageOpenPending.delete(pageNumber);
  6963. const actionsPromise = (async () => {
  6964. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6965. if (pdfDocument !== this._pdfDocument) {
  6966. return;
  6967. }
  6968. await this._scripting?.dispatchEventInSandbox({
  6969. id: "page",
  6970. name: "PageOpen",
  6971. pageNumber,
  6972. actions
  6973. });
  6974. })();
  6975. visitedPages.set(pageNumber, actionsPromise);
  6976. }
  6977. async _dispatchPageClose(pageNumber) {
  6978. const pdfDocument = this._pdfDocument,
  6979. visitedPages = this._visitedPages;
  6980. if (!this._closeCapability) {
  6981. return;
  6982. }
  6983. if (this._pageOpenPending.has(pageNumber)) {
  6984. return;
  6985. }
  6986. const actionsPromise = visitedPages.get(pageNumber);
  6987. if (!actionsPromise) {
  6988. return;
  6989. }
  6990. visitedPages.set(pageNumber, null);
  6991. await actionsPromise;
  6992. if (pdfDocument !== this._pdfDocument) {
  6993. return;
  6994. }
  6995. await this._scripting?.dispatchEventInSandbox({
  6996. id: "page",
  6997. name: "PageClose",
  6998. pageNumber
  6999. });
  7000. }
  7001. async _getDocProperties() {
  7002. if (this._docPropertiesLookup) {
  7003. return this._docPropertiesLookup(this._pdfDocument);
  7004. }
  7005. throw new Error("_getDocProperties: Unable to lookup properties.");
  7006. }
  7007. _createScripting() {
  7008. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  7009. if (this._scripting) {
  7010. throw new Error("_createScripting: Scripting already exists.");
  7011. }
  7012. if (this._scriptingFactory) {
  7013. return this._scriptingFactory.createScripting({
  7014. sandboxBundleSrc: this._sandboxBundleSrc
  7015. });
  7016. }
  7017. throw new Error("_createScripting: Cannot create scripting.");
  7018. }
  7019. async _destroyScripting() {
  7020. if (!this._scripting) {
  7021. this._pdfDocument = null;
  7022. this._destroyCapability?.resolve();
  7023. return;
  7024. }
  7025. if (this._closeCapability) {
  7026. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  7027. setTimeout(resolve, 1000);
  7028. })]).catch(reason => { });
  7029. this._closeCapability = null;
  7030. }
  7031. this._pdfDocument = null;
  7032. try {
  7033. await this._scripting.destroySandbox();
  7034. } catch (ex) { }
  7035. for (const [name, listener] of this._internalEvents) {
  7036. this._eventBus._off(name, listener);
  7037. }
  7038. this._internalEvents.clear();
  7039. for (const [name, listener] of this._domEvents) {
  7040. window.removeEventListener(name, listener, true);
  7041. }
  7042. this._domEvents.clear();
  7043. this._pageOpenPending.clear();
  7044. this._visitedPages.clear();
  7045. this._scripting = null;
  7046. delete this._mouseState.isDown;
  7047. this._ready = false;
  7048. this._destroyCapability?.resolve();
  7049. }
  7050. }
  7051. exports.PDFScriptingManager = PDFScriptingManager;
  7052. /***/
  7053. }),
  7054. /* 24 */
  7055. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7056. Object.defineProperty(exports, "__esModule", ({
  7057. value: true
  7058. }));
  7059. exports.PDFSidebar = void 0;
  7060. var _ui_utils = __webpack_require__(1);
  7061. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7062. class PDFSidebar {
  7063. constructor({
  7064. elements,
  7065. pdfViewer,
  7066. pdfThumbnailViewer,
  7067. eventBus,
  7068. l10n
  7069. }) {
  7070. this.isOpen = false;
  7071. this.active = _ui_utils.SidebarView.THUMBS;
  7072. this.isInitialViewSet = false;
  7073. this.isInitialEventDispatched = false;
  7074. this.onToggled = null;
  7075. this.pdfViewer = pdfViewer;
  7076. this.pdfThumbnailViewer = pdfThumbnailViewer;
  7077. this.outerContainer = elements.outerContainer;
  7078. this.sidebarContainer = elements.sidebarContainer;
  7079. this.toggleButton = elements.toggleButton;
  7080. this.thumbnailButton = elements.thumbnailButton;
  7081. this.outlineButton = elements.outlineButton;
  7082. this.attachmentsButton = elements.attachmentsButton;
  7083. this.layersButton = elements.layersButton;
  7084. this.thumbnailView = elements.thumbnailView;
  7085. this.outlineView = elements.outlineView;
  7086. this.attachmentsView = elements.attachmentsView;
  7087. this.layersView = elements.layersView;
  7088. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  7089. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7090. this.eventBus = eventBus;
  7091. this.l10n = l10n;
  7092. this.#addEventListeners();
  7093. }
  7094. reset() {
  7095. this.isInitialViewSet = false;
  7096. this.isInitialEventDispatched = false;
  7097. this.#hideUINotification(true);
  7098. this.switchView(_ui_utils.SidebarView.THUMBS);
  7099. this.outlineButton.disabled = false;
  7100. this.attachmentsButton.disabled = false;
  7101. this.layersButton.disabled = false;
  7102. this._currentOutlineItemButton.disabled = true;
  7103. }
  7104. get visibleView() {
  7105. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  7106. }
  7107. setInitialView(view = _ui_utils.SidebarView.NONE) {
  7108. if (this.isInitialViewSet) {
  7109. return;
  7110. }
  7111. this.isInitialViewSet = true;
  7112. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  7113. this.#dispatchEvent();
  7114. return;
  7115. }
  7116. this.switchView(view, true);
  7117. if (!this.isInitialEventDispatched) {
  7118. this.#dispatchEvent();
  7119. }
  7120. }
  7121. switchView(view, forceOpen = false) {
  7122. const isViewChanged = view !== this.active;
  7123. let shouldForceRendering = false;
  7124. switch (view) {
  7125. case _ui_utils.SidebarView.NONE:
  7126. if (this.isOpen) {
  7127. this.close();
  7128. }
  7129. return;
  7130. case _ui_utils.SidebarView.THUMBS:
  7131. if (this.isOpen && isViewChanged) {
  7132. shouldForceRendering = true;
  7133. }
  7134. break;
  7135. case _ui_utils.SidebarView.OUTLINE:
  7136. if (this.outlineButton.disabled) {
  7137. return;
  7138. }
  7139. break;
  7140. case _ui_utils.SidebarView.ATTACHMENTS:
  7141. if (this.attachmentsButton.disabled) {
  7142. return;
  7143. }
  7144. break;
  7145. case _ui_utils.SidebarView.LAYERS:
  7146. if (this.layersButton.disabled) {
  7147. return;
  7148. }
  7149. break;
  7150. default:
  7151. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7152. return;
  7153. }
  7154. this.active = view;
  7155. const isThumbs = view === _ui_utils.SidebarView.THUMBS,
  7156. isOutline = view === _ui_utils.SidebarView.OUTLINE,
  7157. isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS,
  7158. isLayers = view === _ui_utils.SidebarView.LAYERS;
  7159. this.thumbnailButton.classList.toggle("toggled", isThumbs);
  7160. this.outlineButton.classList.toggle("toggled", isOutline);
  7161. this.attachmentsButton.classList.toggle("toggled", isAttachments);
  7162. this.layersButton.classList.toggle("toggled", isLayers);
  7163. this.thumbnailButton.setAttribute("aria-checked", isThumbs);
  7164. this.outlineButton.setAttribute("aria-checked", isOutline);
  7165. this.attachmentsButton.setAttribute("aria-checked", isAttachments);
  7166. this.layersButton.setAttribute("aria-checked", isLayers);
  7167. this.thumbnailView.classList.toggle("hidden", !isThumbs);
  7168. this.outlineView.classList.toggle("hidden", !isOutline);
  7169. this.attachmentsView.classList.toggle("hidden", !isAttachments);
  7170. this.layersView.classList.toggle("hidden", !isLayers);
  7171. this._outlineOptionsContainer.classList.toggle("hidden", !isOutline);
  7172. if (forceOpen && !this.isOpen) {
  7173. this.open();
  7174. return;
  7175. }
  7176. if (shouldForceRendering) {
  7177. this.#updateThumbnailViewer();
  7178. this.#forceRendering();
  7179. }
  7180. if (isViewChanged) {
  7181. this.#dispatchEvent();
  7182. }
  7183. }
  7184. open() {
  7185. if (this.isOpen) {
  7186. return;
  7187. }
  7188. this.isOpen = true;
  7189. this.toggleButton.classList.add("toggled");
  7190. this.toggleButton.setAttribute("aria-expanded", "true");
  7191. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7192. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7193. this.#updateThumbnailViewer();
  7194. }
  7195. this.#forceRendering();
  7196. this.#dispatchEvent();
  7197. this.#hideUINotification();
  7198. }
  7199. close() {
  7200. if (!this.isOpen) {
  7201. return;
  7202. }
  7203. this.isOpen = false;
  7204. this.toggleButton.classList.remove("toggled");
  7205. this.toggleButton.setAttribute("aria-expanded", "false");
  7206. this.outerContainer.classList.add("sidebarMoving");
  7207. this.outerContainer.classList.remove("sidebarOpen");
  7208. this.#forceRendering();
  7209. this.#dispatchEvent();
  7210. }
  7211. toggle() {
  7212. if (this.isOpen) {
  7213. this.close();
  7214. } else {
  7215. this.open();
  7216. }
  7217. }
  7218. #dispatchEvent() {
  7219. if (this.isInitialViewSet && !this.isInitialEventDispatched) {
  7220. this.isInitialEventDispatched = true;
  7221. }
  7222. this.eventBus.dispatch("sidebarviewchanged", {
  7223. source: this,
  7224. view: this.visibleView
  7225. });
  7226. }
  7227. #forceRendering() {
  7228. if (this.onToggled) {
  7229. this.onToggled();
  7230. } else {
  7231. this.pdfViewer.forceRendering();
  7232. this.pdfThumbnailViewer.forceRendering();
  7233. }
  7234. }
  7235. #updateThumbnailViewer() {
  7236. const {
  7237. pdfViewer,
  7238. pdfThumbnailViewer
  7239. } = this;
  7240. const pagesCount = pdfViewer.pagesCount;
  7241. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  7242. const pageView = pdfViewer.getPageView(pageIndex);
  7243. if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) {
  7244. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  7245. thumbnailView.setImage(pageView);
  7246. }
  7247. }
  7248. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  7249. }
  7250. #showUINotification() {
  7251. this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
  7252. this.toggleButton.title = msg;
  7253. });
  7254. if (!this.isOpen) {
  7255. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7256. }
  7257. }
  7258. #hideUINotification(reset = false) {
  7259. if (this.isOpen || reset) {
  7260. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7261. }
  7262. if (reset) {
  7263. this.l10n.get("toggle_sidebar.title").then(msg => {
  7264. this.toggleButton.title = msg;
  7265. });
  7266. }
  7267. }
  7268. #addEventListeners() {
  7269. this.sidebarContainer.addEventListener("transitionend", evt => {
  7270. if (evt.target === this.sidebarContainer) {
  7271. this.outerContainer.classList.remove("sidebarMoving");
  7272. }
  7273. });
  7274. this.toggleButton.addEventListener("click", () => {
  7275. this.toggle();
  7276. });
  7277. this.thumbnailButton.addEventListener("click", () => {
  7278. this.switchView(_ui_utils.SidebarView.THUMBS);
  7279. });
  7280. this.outlineButton.addEventListener("click", () => {
  7281. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7282. });
  7283. this.outlineButton.addEventListener("dblclick", () => {
  7284. this.eventBus.dispatch("toggleoutlinetree", {
  7285. source: this
  7286. });
  7287. });
  7288. this.attachmentsButton.addEventListener("click", () => {
  7289. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7290. });
  7291. this.layersButton.addEventListener("click", () => {
  7292. this.switchView(_ui_utils.SidebarView.LAYERS);
  7293. });
  7294. this.layersButton.addEventListener("dblclick", () => {
  7295. this.eventBus.dispatch("resetlayers", {
  7296. source: this
  7297. });
  7298. });
  7299. this._currentOutlineItemButton.addEventListener("click", () => {
  7300. this.eventBus.dispatch("currentoutlineitem", {
  7301. source: this
  7302. });
  7303. });
  7304. const onTreeLoaded = (count, button, view) => {
  7305. button.disabled = !count;
  7306. if (count) {
  7307. this.#showUINotification();
  7308. } else if (this.active === view) {
  7309. this.switchView(_ui_utils.SidebarView.THUMBS);
  7310. }
  7311. };
  7312. this.eventBus._on("outlineloaded", evt => {
  7313. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7314. evt.currentOutlineItemPromise.then(enabled => {
  7315. if (!this.isInitialViewSet) {
  7316. return;
  7317. }
  7318. this._currentOutlineItemButton.disabled = !enabled;
  7319. });
  7320. });
  7321. this.eventBus._on("attachmentsloaded", evt => {
  7322. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7323. });
  7324. this.eventBus._on("layersloaded", evt => {
  7325. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7326. });
  7327. this.eventBus._on("presentationmodechanged", evt => {
  7328. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  7329. this.#updateThumbnailViewer();
  7330. }
  7331. });
  7332. }
  7333. }
  7334. exports.PDFSidebar = PDFSidebar;
  7335. /***/
  7336. }),
  7337. /* 25 */
  7338. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7339. Object.defineProperty(exports, "__esModule", ({
  7340. value: true
  7341. }));
  7342. exports.PDFSidebarResizer = void 0;
  7343. var _ui_utils = __webpack_require__(1);
  7344. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7345. const SIDEBAR_MIN_WIDTH = 200;
  7346. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7347. class PDFSidebarResizer {
  7348. constructor(options, eventBus, l10n) {
  7349. this.isRTL = false;
  7350. this.sidebarOpen = false;
  7351. this._width = null;
  7352. this._outerContainerWidth = null;
  7353. this._boundEvents = Object.create(null);
  7354. this.outerContainer = options.outerContainer;
  7355. this.resizer = options.resizer;
  7356. this.eventBus = eventBus;
  7357. l10n.getDirection().then(dir => {
  7358. this.isRTL = dir === "rtl";
  7359. });
  7360. this._addEventListeners();
  7361. }
  7362. get outerContainerWidth() {
  7363. return this._outerContainerWidth ||= this.outerContainer.clientWidth;
  7364. }
  7365. _updateWidth(width = 0) {
  7366. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7367. if (width > maxWidth) {
  7368. width = maxWidth;
  7369. }
  7370. if (width < SIDEBAR_MIN_WIDTH) {
  7371. width = SIDEBAR_MIN_WIDTH;
  7372. }
  7373. if (width === this._width) {
  7374. return false;
  7375. }
  7376. this._width = width;
  7377. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7378. return true;
  7379. }
  7380. _mouseMove(evt) {
  7381. let width = evt.clientX;
  7382. if (this.isRTL) {
  7383. width = this.outerContainerWidth - width;
  7384. }
  7385. this._updateWidth(width);
  7386. }
  7387. _mouseUp(evt) {
  7388. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7389. this.eventBus.dispatch("resize", {
  7390. source: this
  7391. });
  7392. const _boundEvents = this._boundEvents;
  7393. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7394. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7395. }
  7396. _addEventListeners() {
  7397. const _boundEvents = this._boundEvents;
  7398. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7399. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7400. this.resizer.addEventListener("mousedown", evt => {
  7401. if (evt.button !== 0) {
  7402. return;
  7403. }
  7404. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7405. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7406. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7407. });
  7408. this.eventBus._on("sidebarviewchanged", evt => {
  7409. this.sidebarOpen = !!evt?.view;
  7410. });
  7411. this.eventBus._on("resize", evt => {
  7412. if (evt?.source !== window) {
  7413. return;
  7414. }
  7415. this._outerContainerWidth = null;
  7416. if (!this._width) {
  7417. return;
  7418. }
  7419. if (!this.sidebarOpen) {
  7420. this._updateWidth(this._width);
  7421. return;
  7422. }
  7423. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7424. const updated = this._updateWidth(this._width);
  7425. Promise.resolve().then(() => {
  7426. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7427. if (updated) {
  7428. this.eventBus.dispatch("resize", {
  7429. source: this
  7430. });
  7431. }
  7432. });
  7433. });
  7434. }
  7435. }
  7436. exports.PDFSidebarResizer = PDFSidebarResizer;
  7437. /***/
  7438. }),
  7439. /* 26 */
  7440. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7441. Object.defineProperty(exports, "__esModule", ({
  7442. value: true
  7443. }));
  7444. exports.PDFThumbnailViewer = void 0;
  7445. var _ui_utils = __webpack_require__(1);
  7446. var _pdf_thumbnail_view = __webpack_require__(27);
  7447. const THUMBNAIL_SCROLL_MARGIN = -19;
  7448. const THUMBNAIL_SELECTED_CLASS = "selected";
  7449. class PDFThumbnailViewer {
  7450. constructor({
  7451. container,
  7452. eventBus,
  7453. linkService,
  7454. renderingQueue,
  7455. l10n,
  7456. pageColors
  7457. }) {
  7458. this.container = container;
  7459. this.linkService = linkService;
  7460. this.renderingQueue = renderingQueue;
  7461. this.l10n = l10n;
  7462. this.pageColors = pageColors || null;
  7463. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  7464. if (this.pageColors.background || this.pageColors.foreground) {
  7465. console.warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  7466. }
  7467. this.pageColors = null;
  7468. }
  7469. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7470. this._resetView();
  7471. }
  7472. _scrollUpdated() {
  7473. this.renderingQueue.renderHighestPriority();
  7474. }
  7475. getThumbnail(index) {
  7476. return this._thumbnails[index];
  7477. }
  7478. _getVisibleThumbs() {
  7479. return (0, _ui_utils.getVisibleElements)({
  7480. scrollEl: this.container,
  7481. views: this._thumbnails
  7482. });
  7483. }
  7484. scrollThumbnailIntoView(pageNumber) {
  7485. if (!this.pdfDocument) {
  7486. return;
  7487. }
  7488. const thumbnailView = this._thumbnails[pageNumber - 1];
  7489. if (!thumbnailView) {
  7490. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7491. return;
  7492. }
  7493. if (pageNumber !== this._currentPageNumber) {
  7494. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7495. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7496. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7497. }
  7498. const {
  7499. first,
  7500. last,
  7501. views
  7502. } = this._getVisibleThumbs();
  7503. if (views.length > 0) {
  7504. let shouldScroll = false;
  7505. if (pageNumber <= first.id || pageNumber >= last.id) {
  7506. shouldScroll = true;
  7507. } else {
  7508. for (const {
  7509. id,
  7510. percent
  7511. } of views) {
  7512. if (id !== pageNumber) {
  7513. continue;
  7514. }
  7515. shouldScroll = percent < 100;
  7516. break;
  7517. }
  7518. }
  7519. if (shouldScroll) {
  7520. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7521. top: THUMBNAIL_SCROLL_MARGIN
  7522. });
  7523. }
  7524. }
  7525. this._currentPageNumber = pageNumber;
  7526. }
  7527. get pagesRotation() {
  7528. return this._pagesRotation;
  7529. }
  7530. set pagesRotation(rotation) {
  7531. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7532. throw new Error("Invalid thumbnails rotation angle.");
  7533. }
  7534. if (!this.pdfDocument) {
  7535. return;
  7536. }
  7537. if (this._pagesRotation === rotation) {
  7538. return;
  7539. }
  7540. this._pagesRotation = rotation;
  7541. const updateArgs = {
  7542. rotation
  7543. };
  7544. for (const thumbnail of this._thumbnails) {
  7545. thumbnail.update(updateArgs);
  7546. }
  7547. }
  7548. cleanup() {
  7549. for (const thumbnail of this._thumbnails) {
  7550. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7551. thumbnail.reset();
  7552. }
  7553. }
  7554. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7555. }
  7556. _resetView() {
  7557. this._thumbnails = [];
  7558. this._currentPageNumber = 1;
  7559. this._pageLabels = null;
  7560. this._pagesRotation = 0;
  7561. this.container.textContent = "";
  7562. }
  7563. setDocument(pdfDocument) {
  7564. if (this.pdfDocument) {
  7565. this._cancelRendering();
  7566. this._resetView();
  7567. }
  7568. this.pdfDocument = pdfDocument;
  7569. if (!pdfDocument) {
  7570. return;
  7571. }
  7572. const firstPagePromise = pdfDocument.getPage(1);
  7573. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7574. firstPagePromise.then(firstPdfPage => {
  7575. const pagesCount = pdfDocument.numPages;
  7576. const viewport = firstPdfPage.getViewport({
  7577. scale: 1
  7578. });
  7579. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7580. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7581. container: this.container,
  7582. id: pageNum,
  7583. defaultViewport: viewport.clone(),
  7584. optionalContentConfigPromise,
  7585. linkService: this.linkService,
  7586. renderingQueue: this.renderingQueue,
  7587. l10n: this.l10n,
  7588. pageColors: this.pageColors
  7589. });
  7590. this._thumbnails.push(thumbnail);
  7591. }
  7592. const firstThumbnailView = this._thumbnails[0];
  7593. if (firstThumbnailView) {
  7594. firstThumbnailView.setPdfPage(firstPdfPage);
  7595. }
  7596. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7597. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7598. }).catch(reason => {
  7599. console.error("Unable to initialize thumbnail viewer", reason);
  7600. });
  7601. }
  7602. _cancelRendering() {
  7603. for (const thumbnail of this._thumbnails) {
  7604. thumbnail.cancelRendering();
  7605. }
  7606. }
  7607. setPageLabels(labels) {
  7608. if (!this.pdfDocument) {
  7609. return;
  7610. }
  7611. if (!labels) {
  7612. this._pageLabels = null;
  7613. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7614. this._pageLabels = null;
  7615. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7616. } else {
  7617. this._pageLabels = labels;
  7618. }
  7619. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7620. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7621. }
  7622. }
  7623. async #ensurePdfPageLoaded(thumbView) {
  7624. if (thumbView.pdfPage) {
  7625. return thumbView.pdfPage;
  7626. }
  7627. try {
  7628. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7629. if (!thumbView.pdfPage) {
  7630. thumbView.setPdfPage(pdfPage);
  7631. }
  7632. return pdfPage;
  7633. } catch (reason) {
  7634. console.error("Unable to get page for thumb view", reason);
  7635. return null;
  7636. }
  7637. }
  7638. #getScrollAhead(visible) {
  7639. if (visible.first?.id === 1) {
  7640. return true;
  7641. } else if (visible.last?.id === this._thumbnails.length) {
  7642. return false;
  7643. }
  7644. return this.scroll.down;
  7645. }
  7646. forceRendering() {
  7647. const visibleThumbs = this._getVisibleThumbs();
  7648. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7649. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7650. if (thumbView) {
  7651. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7652. this.renderingQueue.renderView(thumbView);
  7653. });
  7654. return true;
  7655. }
  7656. return false;
  7657. }
  7658. }
  7659. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7660. /***/
  7661. }),
  7662. /* 27 */
  7663. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7664. Object.defineProperty(exports, "__esModule", ({
  7665. value: true
  7666. }));
  7667. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7668. var _ui_utils = __webpack_require__(1);
  7669. var _pdfjsLib = __webpack_require__(5);
  7670. const DRAW_UPSCALE_FACTOR = 2;
  7671. const MAX_NUM_SCALING_STEPS = 3;
  7672. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7673. const THUMBNAIL_WIDTH = 98;
  7674. class TempImageFactory {
  7675. static #tempCanvas = null;
  7676. static getCanvas(width, height) {
  7677. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7678. tempCanvas.width = width;
  7679. tempCanvas.height = height;
  7680. const ctx = tempCanvas.getContext("2d", {
  7681. alpha: false
  7682. });
  7683. ctx.save();
  7684. ctx.fillStyle = "rgb(255, 255, 255)";
  7685. ctx.fillRect(0, 0, width, height);
  7686. ctx.restore();
  7687. return [tempCanvas, tempCanvas.getContext("2d")];
  7688. }
  7689. static destroyCanvas() {
  7690. const tempCanvas = this.#tempCanvas;
  7691. if (tempCanvas) {
  7692. tempCanvas.width = 0;
  7693. tempCanvas.height = 0;
  7694. }
  7695. this.#tempCanvas = null;
  7696. }
  7697. }
  7698. exports.TempImageFactory = TempImageFactory;
  7699. class PDFThumbnailView {
  7700. constructor({
  7701. container,
  7702. id,
  7703. defaultViewport,
  7704. optionalContentConfigPromise,
  7705. linkService,
  7706. renderingQueue,
  7707. l10n,
  7708. pageColors
  7709. }) {
  7710. this.id = id;
  7711. this.renderingId = "thumbnail" + id;
  7712. this.pageLabel = null;
  7713. this.pdfPage = null;
  7714. this.rotation = 0;
  7715. this.viewport = defaultViewport;
  7716. this.pdfPageRotate = defaultViewport.rotation;
  7717. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7718. this.pageColors = pageColors || null;
  7719. this.linkService = linkService;
  7720. this.renderingQueue = renderingQueue;
  7721. this.renderTask = null;
  7722. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7723. this.resume = null;
  7724. const pageWidth = this.viewport.width,
  7725. pageHeight = this.viewport.height,
  7726. pageRatio = pageWidth / pageHeight;
  7727. this.canvasWidth = THUMBNAIL_WIDTH;
  7728. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7729. this.scale = this.canvasWidth / pageWidth;
  7730. this.l10n = l10n;
  7731. const anchor = document.createElement("a");
  7732. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7733. this._thumbPageTitle.then(msg => {
  7734. anchor.title = msg;
  7735. });
  7736. anchor.onclick = function () {
  7737. linkService.goToPage(id);
  7738. return false;
  7739. };
  7740. this.anchor = anchor;
  7741. const div = document.createElement("div");
  7742. div.className = "thumbnail";
  7743. div.setAttribute("data-page-number", this.id);
  7744. this.div = div;
  7745. const ring = document.createElement("div");
  7746. ring.className = "thumbnailSelectionRing";
  7747. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7748. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7749. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7750. this.ring = ring;
  7751. div.append(ring);
  7752. anchor.append(div);
  7753. container.append(anchor);
  7754. }
  7755. setPdfPage(pdfPage) {
  7756. this.pdfPage = pdfPage;
  7757. this.pdfPageRotate = pdfPage.rotate;
  7758. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7759. this.viewport = pdfPage.getViewport({
  7760. scale: 1,
  7761. rotation: totalRotation
  7762. });
  7763. this.reset();
  7764. }
  7765. reset() {
  7766. this.cancelRendering();
  7767. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7768. const pageWidth = this.viewport.width,
  7769. pageHeight = this.viewport.height,
  7770. pageRatio = pageWidth / pageHeight;
  7771. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7772. this.scale = this.canvasWidth / pageWidth;
  7773. this.div.removeAttribute("data-loaded");
  7774. const ring = this.ring;
  7775. ring.textContent = "";
  7776. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7777. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7778. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7779. if (this.canvas) {
  7780. this.canvas.width = 0;
  7781. this.canvas.height = 0;
  7782. delete this.canvas;
  7783. }
  7784. if (this.image) {
  7785. this.image.removeAttribute("src");
  7786. delete this.image;
  7787. }
  7788. }
  7789. update({
  7790. rotation = null
  7791. }) {
  7792. if (typeof rotation === "number") {
  7793. this.rotation = rotation;
  7794. }
  7795. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7796. this.viewport = this.viewport.clone({
  7797. scale: 1,
  7798. rotation: totalRotation
  7799. });
  7800. this.reset();
  7801. }
  7802. cancelRendering() {
  7803. if (this.renderTask) {
  7804. this.renderTask.cancel();
  7805. this.renderTask = null;
  7806. }
  7807. this.resume = null;
  7808. }
  7809. _getPageDrawContext(upscaleFactor = 1) {
  7810. const canvas = document.createElement("canvas");
  7811. const ctx = canvas.getContext("2d", {
  7812. alpha: false
  7813. });
  7814. const outputScale = new _ui_utils.OutputScale();
  7815. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7816. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7817. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7818. return {
  7819. ctx,
  7820. canvas,
  7821. transform
  7822. };
  7823. }
  7824. _convertCanvasToImage(canvas) {
  7825. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7826. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  7827. }
  7828. const reducedCanvas = this._reduceImage(canvas);
  7829. const image = document.createElement("img");
  7830. image.className = "thumbnailImage";
  7831. this._thumbPageCanvas.then(msg => {
  7832. image.setAttribute("aria-label", msg);
  7833. });
  7834. image.style.width = this.canvasWidth + "px";
  7835. image.style.height = this.canvasHeight + "px";
  7836. image.src = reducedCanvas.toDataURL();
  7837. this.image = image;
  7838. this.div.setAttribute("data-loaded", true);
  7839. this.ring.append(image);
  7840. reducedCanvas.width = 0;
  7841. reducedCanvas.height = 0;
  7842. }
  7843. draw() {
  7844. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7845. console.error("Must be in new state before drawing");
  7846. return Promise.resolve();
  7847. }
  7848. const {
  7849. pdfPage
  7850. } = this;
  7851. if (!pdfPage) {
  7852. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7853. return Promise.reject(new Error("pdfPage is not loaded"));
  7854. }
  7855. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7856. const finishRenderTask = async (error = null) => {
  7857. if (renderTask === this.renderTask) {
  7858. this.renderTask = null;
  7859. }
  7860. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7861. return;
  7862. }
  7863. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7864. this._convertCanvasToImage(canvas);
  7865. if (error) {
  7866. throw error;
  7867. }
  7868. };
  7869. const {
  7870. ctx,
  7871. canvas,
  7872. transform
  7873. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7874. const drawViewport = this.viewport.clone({
  7875. scale: DRAW_UPSCALE_FACTOR * this.scale
  7876. });
  7877. const renderContinueCallback = cont => {
  7878. if (!this.renderingQueue.isHighestPriority(this)) {
  7879. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  7880. this.resume = () => {
  7881. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7882. cont();
  7883. };
  7884. return;
  7885. }
  7886. cont();
  7887. };
  7888. const renderContext = {
  7889. canvasContext: ctx,
  7890. transform,
  7891. viewport: drawViewport,
  7892. optionalContentConfigPromise: this._optionalContentConfigPromise,
  7893. pageColors: this.pageColors
  7894. };
  7895. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7896. renderTask.onContinue = renderContinueCallback;
  7897. const resultPromise = renderTask.promise.then(function () {
  7898. return finishRenderTask(null);
  7899. }, function (error) {
  7900. return finishRenderTask(error);
  7901. });
  7902. resultPromise.finally(() => {
  7903. canvas.width = 0;
  7904. canvas.height = 0;
  7905. const pageCached = this.linkService.isPageCached(this.id);
  7906. if (!pageCached) {
  7907. this.pdfPage?.cleanup();
  7908. }
  7909. });
  7910. return resultPromise;
  7911. }
  7912. setImage(pageView) {
  7913. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7914. return;
  7915. }
  7916. const {
  7917. thumbnailCanvas: canvas,
  7918. pdfPage,
  7919. scale
  7920. } = pageView;
  7921. if (!canvas) {
  7922. return;
  7923. }
  7924. if (!this.pdfPage) {
  7925. this.setPdfPage(pdfPage);
  7926. }
  7927. if (scale < this.scale) {
  7928. return;
  7929. }
  7930. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7931. this._convertCanvasToImage(canvas);
  7932. }
  7933. _reduceImage(img) {
  7934. const {
  7935. ctx,
  7936. canvas
  7937. } = this._getPageDrawContext();
  7938. if (img.width <= 2 * canvas.width) {
  7939. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7940. return canvas;
  7941. }
  7942. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7943. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7944. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7945. while (reducedWidth > img.width || reducedHeight > img.height) {
  7946. reducedWidth >>= 1;
  7947. reducedHeight >>= 1;
  7948. }
  7949. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7950. while (reducedWidth > 2 * canvas.width) {
  7951. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7952. reducedWidth >>= 1;
  7953. reducedHeight >>= 1;
  7954. }
  7955. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7956. return canvas;
  7957. }
  7958. get _thumbPageTitle() {
  7959. return this.l10n.get("thumb_page_title", {
  7960. page: this.pageLabel ?? this.id
  7961. });
  7962. }
  7963. get _thumbPageCanvas() {
  7964. return this.l10n.get("thumb_page_canvas", {
  7965. page: this.pageLabel ?? this.id
  7966. });
  7967. }
  7968. setPageLabel(label) {
  7969. this.pageLabel = typeof label === "string" ? label : null;
  7970. this._thumbPageTitle.then(msg => {
  7971. this.anchor.title = msg;
  7972. });
  7973. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7974. return;
  7975. }
  7976. this._thumbPageCanvas.then(msg => {
  7977. this.image?.setAttribute("aria-label", msg);
  7978. });
  7979. }
  7980. }
  7981. exports.PDFThumbnailView = PDFThumbnailView;
  7982. /***/
  7983. }),
  7984. /* 28 */
  7985. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7986. Object.defineProperty(exports, "__esModule", ({
  7987. value: true
  7988. }));
  7989. exports.PDFViewer = exports.PDFSinglePageViewer = void 0;
  7990. var _ui_utils = __webpack_require__(1);
  7991. var _base_viewer = __webpack_require__(29);
  7992. class PDFViewer extends _base_viewer.BaseViewer { }
  7993. exports.PDFViewer = PDFViewer;
  7994. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  7995. _resetView() {
  7996. super._resetView();
  7997. this._scrollMode = _ui_utils.ScrollMode.PAGE;
  7998. this._spreadMode = _ui_utils.SpreadMode.NONE;
  7999. }
  8000. set scrollMode(mode) { }
  8001. _updateScrollMode() { }
  8002. set spreadMode(mode) { }
  8003. _updateSpreadMode() { }
  8004. }
  8005. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  8006. /***/
  8007. }),
  8008. /* 29 */
  8009. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8010. Object.defineProperty(exports, "__esModule", ({
  8011. value: true
  8012. }));
  8013. exports.PagesCountLimit = exports.PDFPageViewBuffer = exports.BaseViewer = void 0;
  8014. var _pdfjsLib = __webpack_require__(5);
  8015. var _ui_utils = __webpack_require__(1);
  8016. var _annotation_editor_layer_builder = __webpack_require__(30);
  8017. var _annotation_layer_builder = __webpack_require__(32);
  8018. var _l10n_utils = __webpack_require__(31);
  8019. var _pdf_page_view = __webpack_require__(33);
  8020. var _pdf_rendering_queue = __webpack_require__(22);
  8021. var _pdf_link_service = __webpack_require__(3);
  8022. var _struct_tree_layer_builder = __webpack_require__(35);
  8023. var _text_highlighter = __webpack_require__(36);
  8024. var _text_layer_builder = __webpack_require__(37);
  8025. var _xfa_layer_builder = __webpack_require__(38);
  8026. const DEFAULT_CACHE_SIZE = 10;
  8027. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  8028. const PagesCountLimit = {
  8029. FORCE_SCROLL_MODE_PAGE: 15000,
  8030. FORCE_LAZY_PAGE_INIT: 7500,
  8031. PAUSE_EAGER_PAGE_INIT: 250
  8032. };
  8033. exports.PagesCountLimit = PagesCountLimit;
  8034. function isValidAnnotationEditorMode(mode) {
  8035. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  8036. }
  8037. class PDFPageViewBuffer {
  8038. #buf = new Set();
  8039. #size = 0;
  8040. constructor(size) {
  8041. this.#size = size;
  8042. }
  8043. push(view) {
  8044. const buf = this.#buf;
  8045. if (buf.has(view)) {
  8046. buf.delete(view);
  8047. }
  8048. buf.add(view);
  8049. if (buf.size > this.#size) {
  8050. this.#destroyFirstView();
  8051. }
  8052. }
  8053. resize(newSize, idsToKeep = null) {
  8054. this.#size = newSize;
  8055. const buf = this.#buf;
  8056. if (idsToKeep) {
  8057. const ii = buf.size;
  8058. let i = 1;
  8059. for (const view of buf) {
  8060. if (idsToKeep.has(view.id)) {
  8061. buf.delete(view);
  8062. buf.add(view);
  8063. }
  8064. if (++i > ii) {
  8065. break;
  8066. }
  8067. }
  8068. }
  8069. while (buf.size > this.#size) {
  8070. this.#destroyFirstView();
  8071. }
  8072. }
  8073. has(view) {
  8074. return this.#buf.has(view);
  8075. }
  8076. [Symbol.iterator]() {
  8077. return this.#buf.keys();
  8078. }
  8079. #destroyFirstView() {
  8080. const firstView = this.#buf.keys().next().value;
  8081. firstView?.destroy();
  8082. this.#buf.delete(firstView);
  8083. }
  8084. }
  8085. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  8086. class BaseViewer {
  8087. #buffer = null;
  8088. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8089. #annotationEditorUIManager = null;
  8090. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8091. #enablePermissions = false;
  8092. #previousContainerHeight = 0;
  8093. #scrollModePageState = null;
  8094. #onVisibilityChange = null;
  8095. constructor(options) {
  8096. if (this.constructor === BaseViewer) {
  8097. throw new Error("Cannot initialize BaseViewer.");
  8098. }
  8099. const viewerVersion = '2.16.105';
  8100. if (_pdfjsLib.version !== viewerVersion) {
  8101. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  8102. }
  8103. this.container = options.container;
  8104. this.viewer = options.viewer || options.container.firstElementChild;
  8105. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  8106. throw new Error("Invalid `container` and/or `viewer` option.");
  8107. }
  8108. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  8109. throw new Error("The `container` must be absolutely positioned.");
  8110. }
  8111. this.eventBus = options.eventBus;
  8112. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8113. this.downloadManager = options.downloadManager || null;
  8114. this.findController = options.findController || null;
  8115. this._scriptingManager = options.scriptingManager || null;
  8116. this.removePageBorders = options.removePageBorders || false;
  8117. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  8118. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8119. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.DISABLE;
  8120. this.imageResourcesPath = options.imageResourcesPath || "";
  8121. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8122. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  8123. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  8124. this.maxCanvasPixels = options.maxCanvasPixels;
  8125. this.l10n = options.l10n || _l10n_utils.NullL10n;
  8126. this.#enablePermissions = options.enablePermissions || false;
  8127. this.pageColors = options.pageColors || null;
  8128. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  8129. if (this.pageColors.background || this.pageColors.foreground) {
  8130. console.warn("BaseViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  8131. }
  8132. this.pageColors = null;
  8133. }
  8134. this.defaultRenderingQueue = !options.renderingQueue;
  8135. if (this.defaultRenderingQueue) {
  8136. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8137. this.renderingQueue.setViewer(this);
  8138. } else {
  8139. this.renderingQueue = options.renderingQueue;
  8140. }
  8141. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8142. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8143. this._onBeforeDraw = this._onAfterDraw = null;
  8144. this._resetView();
  8145. if (this.removePageBorders) {
  8146. this.viewer.classList.add("removePageBorders");
  8147. }
  8148. this.updateContainerHeightCss();
  8149. }
  8150. get pagesCount() {
  8151. return this._pages.length;
  8152. }
  8153. getPageView(index) {
  8154. return this._pages[index];
  8155. }
  8156. get pageViewsReady() {
  8157. if (!this._pagesCapability.settled) {
  8158. return false;
  8159. }
  8160. return this._pages.every(function (pageView) {
  8161. return pageView?.pdfPage;
  8162. });
  8163. }
  8164. get renderForms() {
  8165. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8166. }
  8167. get enableScripting() {
  8168. return !!this._scriptingManager;
  8169. }
  8170. get currentPageNumber() {
  8171. return this._currentPageNumber;
  8172. }
  8173. set currentPageNumber(val) {
  8174. if (!Number.isInteger(val)) {
  8175. throw new Error("Invalid page number.");
  8176. }
  8177. if (!this.pdfDocument) {
  8178. return;
  8179. }
  8180. if (!this._setCurrentPageNumber(val, true)) {
  8181. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  8182. }
  8183. }
  8184. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  8185. if (this._currentPageNumber === val) {
  8186. if (resetCurrentPageView) {
  8187. this.#resetCurrentPageView();
  8188. }
  8189. return true;
  8190. }
  8191. if (!(0 < val && val <= this.pagesCount)) {
  8192. return false;
  8193. }
  8194. const previous = this._currentPageNumber;
  8195. this._currentPageNumber = val;
  8196. this.eventBus.dispatch("pagechanging", {
  8197. source: this,
  8198. pageNumber: val,
  8199. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8200. previous
  8201. });
  8202. if (resetCurrentPageView) {
  8203. this.#resetCurrentPageView();
  8204. }
  8205. return true;
  8206. }
  8207. get currentPageLabel() {
  8208. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8209. }
  8210. set currentPageLabel(val) {
  8211. if (!this.pdfDocument) {
  8212. return;
  8213. }
  8214. let page = val | 0;
  8215. if (this._pageLabels) {
  8216. const i = this._pageLabels.indexOf(val);
  8217. if (i >= 0) {
  8218. page = i + 1;
  8219. }
  8220. }
  8221. if (!this._setCurrentPageNumber(page, true)) {
  8222. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8223. }
  8224. }
  8225. get currentScale() {
  8226. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8227. }
  8228. set currentScale(val) {
  8229. if (isNaN(val)) {
  8230. throw new Error("Invalid numeric scale.");
  8231. }
  8232. if (!this.pdfDocument) {
  8233. return;
  8234. }
  8235. this._setScale(val, false);
  8236. }
  8237. get currentScaleValue() {
  8238. return this._currentScaleValue;
  8239. }
  8240. set currentScaleValue(val) {
  8241. if (!this.pdfDocument) {
  8242. return;
  8243. }
  8244. this._setScale(val, false);
  8245. }
  8246. get pagesRotation() {
  8247. return this._pagesRotation;
  8248. }
  8249. set pagesRotation(rotation) {
  8250. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8251. throw new Error("Invalid pages rotation angle.");
  8252. }
  8253. if (!this.pdfDocument) {
  8254. return;
  8255. }
  8256. rotation %= 360;
  8257. if (rotation < 0) {
  8258. rotation += 360;
  8259. }
  8260. if (this._pagesRotation === rotation) {
  8261. return;
  8262. }
  8263. this._pagesRotation = rotation;
  8264. const pageNumber = this._currentPageNumber;
  8265. const updateArgs = {
  8266. rotation
  8267. };
  8268. for (const pageView of this._pages) {
  8269. pageView.update(updateArgs);
  8270. }
  8271. if (this._currentScaleValue) {
  8272. this._setScale(this._currentScaleValue, true);
  8273. }
  8274. this.eventBus.dispatch("rotationchanging", {
  8275. source: this,
  8276. pagesRotation: rotation,
  8277. pageNumber
  8278. });
  8279. if (this.defaultRenderingQueue) {
  8280. this.update();
  8281. }
  8282. }
  8283. get firstPagePromise() {
  8284. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8285. }
  8286. get onePageRendered() {
  8287. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8288. }
  8289. get pagesPromise() {
  8290. return this.pdfDocument ? this._pagesCapability.promise : null;
  8291. }
  8292. #initializePermissions(permissions) {
  8293. const params = {
  8294. annotationEditorMode: this.#annotationEditorMode,
  8295. annotationMode: this.#annotationMode,
  8296. textLayerMode: this.textLayerMode
  8297. };
  8298. if (!permissions) {
  8299. return params;
  8300. }
  8301. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  8302. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  8303. }
  8304. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  8305. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8306. }
  8307. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8308. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8309. }
  8310. return params;
  8311. }
  8312. #onePageRenderedOrForceFetch() {
  8313. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8314. return Promise.resolve();
  8315. }
  8316. const visibilityChangePromise = new Promise(resolve => {
  8317. this.#onVisibilityChange = () => {
  8318. if (document.visibilityState !== "hidden") {
  8319. return;
  8320. }
  8321. resolve();
  8322. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8323. this.#onVisibilityChange = null;
  8324. };
  8325. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8326. });
  8327. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8328. }
  8329. setDocument(pdfDocument) {
  8330. if (this.pdfDocument) {
  8331. this.eventBus.dispatch("pagesdestroy", {
  8332. source: this
  8333. });
  8334. this._cancelRendering();
  8335. this._resetView();
  8336. if (this.findController) {
  8337. this.findController.setDocument(null);
  8338. }
  8339. if (this._scriptingManager) {
  8340. this._scriptingManager.setDocument(null);
  8341. }
  8342. if (this.#annotationEditorUIManager) {
  8343. this.#annotationEditorUIManager.destroy();
  8344. this.#annotationEditorUIManager = null;
  8345. }
  8346. }
  8347. this.pdfDocument = pdfDocument;
  8348. if (!pdfDocument) {
  8349. return;
  8350. }
  8351. const isPureXfa = pdfDocument.isPureXfa;
  8352. const pagesCount = pdfDocument.numPages;
  8353. const firstPagePromise = pdfDocument.getPage(1);
  8354. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8355. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8356. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8357. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8358. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8359. this.eventBus.dispatch("scrollmodechanged", {
  8360. source: this,
  8361. mode
  8362. });
  8363. }
  8364. this._pagesCapability.promise.then(() => {
  8365. this.eventBus.dispatch("pagesloaded", {
  8366. source: this,
  8367. pagesCount
  8368. });
  8369. }, () => { });
  8370. this._onBeforeDraw = evt => {
  8371. const pageView = this._pages[evt.pageNumber - 1];
  8372. if (!pageView) {
  8373. return;
  8374. }
  8375. this.#buffer.push(pageView);
  8376. };
  8377. this.eventBus._on("pagerender", this._onBeforeDraw);
  8378. this._onAfterDraw = evt => {
  8379. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8380. return;
  8381. }
  8382. this._onePageRenderedCapability.resolve({
  8383. timestamp: evt.timestamp
  8384. });
  8385. this.eventBus._off("pagerendered", this._onAfterDraw);
  8386. this._onAfterDraw = null;
  8387. if (this.#onVisibilityChange) {
  8388. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8389. this.#onVisibilityChange = null;
  8390. }
  8391. };
  8392. this.eventBus._on("pagerendered", this._onAfterDraw);
  8393. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8394. if (pdfDocument !== this.pdfDocument) {
  8395. return;
  8396. }
  8397. this._firstPageCapability.resolve(firstPdfPage);
  8398. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8399. const {
  8400. annotationEditorMode,
  8401. annotationMode,
  8402. textLayerMode
  8403. } = this.#initializePermissions(permissions);
  8404. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  8405. const mode = annotationEditorMode;
  8406. if (isPureXfa) {
  8407. console.warn("Warning: XFA-editing is not implemented.");
  8408. } else if (isValidAnnotationEditorMode(mode)) {
  8409. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus);
  8410. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  8411. this.#annotationEditorUIManager.updateMode(mode);
  8412. }
  8413. } else {
  8414. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  8415. }
  8416. }
  8417. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8418. const scale = this.currentScale;
  8419. const viewport = firstPdfPage.getViewport({
  8420. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8421. });
  8422. const textLayerFactory = textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !isPureXfa ? this : null;
  8423. const annotationLayerFactory = annotationMode !== _pdfjsLib.AnnotationMode.DISABLE ? this : null;
  8424. const xfaLayerFactory = isPureXfa ? this : null;
  8425. const annotationEditorLayerFactory = this.#annotationEditorUIManager ? this : null;
  8426. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8427. const pageView = new _pdf_page_view.PDFPageView({
  8428. container: viewerElement,
  8429. eventBus: this.eventBus,
  8430. id: pageNum,
  8431. scale,
  8432. defaultViewport: viewport.clone(),
  8433. optionalContentConfigPromise,
  8434. renderingQueue: this.renderingQueue,
  8435. textLayerFactory,
  8436. textLayerMode,
  8437. annotationLayerFactory,
  8438. annotationMode,
  8439. xfaLayerFactory,
  8440. annotationEditorLayerFactory,
  8441. textHighlighterFactory: this,
  8442. structTreeLayerFactory: this,
  8443. imageResourcesPath: this.imageResourcesPath,
  8444. renderer: this.renderer,
  8445. useOnlyCssZoom: this.useOnlyCssZoom,
  8446. maxCanvasPixels: this.maxCanvasPixels,
  8447. pageColors: this.pageColors,
  8448. l10n: this.l10n
  8449. });
  8450. this._pages.push(pageView);
  8451. }
  8452. const firstPageView = this._pages[0];
  8453. if (firstPageView) {
  8454. firstPageView.setPdfPage(firstPdfPage);
  8455. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8456. }
  8457. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8458. this.#ensurePageViewVisible();
  8459. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8460. this._updateSpreadMode();
  8461. }
  8462. this.#onePageRenderedOrForceFetch().then(async () => {
  8463. if (this.findController) {
  8464. this.findController.setDocument(pdfDocument);
  8465. }
  8466. if (this._scriptingManager) {
  8467. this._scriptingManager.setDocument(pdfDocument);
  8468. }
  8469. if (this.#annotationEditorUIManager) {
  8470. this.eventBus.dispatch("annotationeditormodechanged", {
  8471. source: this,
  8472. mode: this.#annotationEditorMode
  8473. });
  8474. }
  8475. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8476. this._pagesCapability.resolve();
  8477. return;
  8478. }
  8479. let getPagesLeft = pagesCount - 1;
  8480. if (getPagesLeft <= 0) {
  8481. this._pagesCapability.resolve();
  8482. return;
  8483. }
  8484. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8485. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8486. const pageView = this._pages[pageNum - 1];
  8487. if (!pageView.pdfPage) {
  8488. pageView.setPdfPage(pdfPage);
  8489. }
  8490. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8491. if (--getPagesLeft === 0) {
  8492. this._pagesCapability.resolve();
  8493. }
  8494. }, reason => {
  8495. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8496. if (--getPagesLeft === 0) {
  8497. this._pagesCapability.resolve();
  8498. }
  8499. });
  8500. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8501. await promise;
  8502. }
  8503. }
  8504. });
  8505. this.eventBus.dispatch("pagesinit", {
  8506. source: this
  8507. });
  8508. pdfDocument.getMetadata().then(({
  8509. info
  8510. }) => {
  8511. if (pdfDocument !== this.pdfDocument) {
  8512. return;
  8513. }
  8514. if (info.Language) {
  8515. this.viewer.lang = info.Language;
  8516. }
  8517. });
  8518. if (this.defaultRenderingQueue) {
  8519. this.update();
  8520. }
  8521. }).catch(reason => {
  8522. console.error("Unable to initialize viewer", reason);
  8523. this._pagesCapability.reject(reason);
  8524. });
  8525. }
  8526. setPageLabels(labels) {
  8527. if (!this.pdfDocument) {
  8528. return;
  8529. }
  8530. if (!labels) {
  8531. this._pageLabels = null;
  8532. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8533. this._pageLabels = null;
  8534. console.error(`setPageLabels: Invalid page labels.`);
  8535. } else {
  8536. this._pageLabels = labels;
  8537. }
  8538. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8539. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8540. }
  8541. }
  8542. _resetView() {
  8543. this._pages = [];
  8544. this._currentPageNumber = 1;
  8545. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8546. this._currentScaleValue = null;
  8547. this._pageLabels = null;
  8548. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8549. this._location = null;
  8550. this._pagesRotation = 0;
  8551. this._optionalContentConfigPromise = null;
  8552. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8553. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8554. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8555. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8556. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8557. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8558. this.#scrollModePageState = {
  8559. previousPageNumber: 1,
  8560. scrollDown: true,
  8561. pages: []
  8562. };
  8563. if (this._onBeforeDraw) {
  8564. this.eventBus._off("pagerender", this._onBeforeDraw);
  8565. this._onBeforeDraw = null;
  8566. }
  8567. if (this._onAfterDraw) {
  8568. this.eventBus._off("pagerendered", this._onAfterDraw);
  8569. this._onAfterDraw = null;
  8570. }
  8571. if (this.#onVisibilityChange) {
  8572. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8573. this.#onVisibilityChange = null;
  8574. }
  8575. this.viewer.textContent = "";
  8576. this._updateScrollMode();
  8577. this.viewer.removeAttribute("lang");
  8578. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  8579. }
  8580. #ensurePageViewVisible() {
  8581. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8582. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8583. }
  8584. const pageNumber = this._currentPageNumber,
  8585. state = this.#scrollModePageState,
  8586. viewer = this.viewer;
  8587. viewer.textContent = "";
  8588. state.pages.length = 0;
  8589. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8590. const pageView = this._pages[pageNumber - 1];
  8591. viewer.append(pageView.div);
  8592. state.pages.push(pageView);
  8593. } else {
  8594. const pageIndexSet = new Set(),
  8595. parity = this._spreadMode - 1;
  8596. if (parity === -1) {
  8597. pageIndexSet.add(pageNumber - 1);
  8598. } else if (pageNumber % 2 !== parity) {
  8599. pageIndexSet.add(pageNumber - 1);
  8600. pageIndexSet.add(pageNumber);
  8601. } else {
  8602. pageIndexSet.add(pageNumber - 2);
  8603. pageIndexSet.add(pageNumber - 1);
  8604. }
  8605. const spread = document.createElement("div");
  8606. spread.className = "spread";
  8607. if (this.isInPresentationMode) {
  8608. const dummyPage = document.createElement("div");
  8609. dummyPage.className = "dummyPage";
  8610. spread.append(dummyPage);
  8611. }
  8612. for (const i of pageIndexSet) {
  8613. const pageView = this._pages[i];
  8614. if (!pageView) {
  8615. continue;
  8616. }
  8617. spread.append(pageView.div);
  8618. state.pages.push(pageView);
  8619. }
  8620. viewer.append(spread);
  8621. }
  8622. state.scrollDown = pageNumber >= state.previousPageNumber;
  8623. state.previousPageNumber = pageNumber;
  8624. }
  8625. _scrollUpdate() {
  8626. if (this.pagesCount === 0) {
  8627. return;
  8628. }
  8629. this.update();
  8630. }
  8631. #scrollIntoView(pageView, pageSpot = null) {
  8632. const {
  8633. div,
  8634. id
  8635. } = pageView;
  8636. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8637. this._setCurrentPageNumber(id);
  8638. this.#ensurePageViewVisible();
  8639. this.update();
  8640. }
  8641. if (!pageSpot && !this.isInPresentationMode) {
  8642. const left = div.offsetLeft + div.clientLeft,
  8643. right = left + div.clientWidth;
  8644. const {
  8645. scrollLeft,
  8646. clientWidth
  8647. } = this.container;
  8648. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8649. pageSpot = {
  8650. left: 0,
  8651. top: 0
  8652. };
  8653. }
  8654. }
  8655. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8656. }
  8657. #isSameScale(newScale) {
  8658. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8659. }
  8660. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8661. this._currentScaleValue = newValue.toString();
  8662. if (this.#isSameScale(newScale)) {
  8663. if (preset) {
  8664. this.eventBus.dispatch("scalechanging", {
  8665. source: this,
  8666. scale: newScale,
  8667. presetValue: newValue
  8668. });
  8669. }
  8670. return;
  8671. }
  8672. _ui_utils.docStyle.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8673. const updateArgs = {
  8674. scale: newScale
  8675. };
  8676. for (const pageView of this._pages) {
  8677. pageView.update(updateArgs);
  8678. }
  8679. this._currentScale = newScale;
  8680. if (!noScroll) {
  8681. let page = this._currentPageNumber,
  8682. dest;
  8683. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8684. page = this._location.pageNumber;
  8685. dest = [null, {
  8686. name: "XYZ"
  8687. }, this._location.left, this._location.top, null];
  8688. }
  8689. this.scrollPageIntoView({
  8690. pageNumber: page,
  8691. destArray: dest,
  8692. allowNegativeOffset: true
  8693. });
  8694. }
  8695. this.eventBus.dispatch("scalechanging", {
  8696. source: this,
  8697. scale: newScale,
  8698. presetValue: preset ? newValue : undefined
  8699. });
  8700. if (this.defaultRenderingQueue) {
  8701. this.update();
  8702. }
  8703. this.updateContainerHeightCss();
  8704. }
  8705. get _pageWidthScaleFactor() {
  8706. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8707. return 2;
  8708. }
  8709. return 1;
  8710. }
  8711. _setScale(value, noScroll = false) {
  8712. let scale = parseFloat(value);
  8713. if (scale > 0) {
  8714. this._setScaleUpdatePages(scale, value, noScroll, false);
  8715. } else {
  8716. const currentPage = this._pages[this._currentPageNumber - 1];
  8717. if (!currentPage) {
  8718. return;
  8719. }
  8720. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8721. vPadding = _ui_utils.VERTICAL_PADDING;
  8722. if (this.isInPresentationMode) {
  8723. hPadding = vPadding = 4;
  8724. } else if (this.removePageBorders) {
  8725. hPadding = vPadding = 0;
  8726. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8727. [hPadding, vPadding] = [vPadding, hPadding];
  8728. }
  8729. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8730. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8731. switch (value) {
  8732. case "page-actual":
  8733. scale = 1;
  8734. break;
  8735. case "page-width":
  8736. scale = pageWidthScale;
  8737. break;
  8738. case "page-height":
  8739. scale = pageHeightScale;
  8740. break;
  8741. case "page-fit":
  8742. scale = Math.min(pageWidthScale, pageHeightScale);
  8743. break;
  8744. case "auto":
  8745. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8746. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8747. break;
  8748. default:
  8749. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  8750. return;
  8751. }
  8752. this._setScaleUpdatePages(scale, value, noScroll, true);
  8753. }
  8754. }
  8755. #resetCurrentPageView() {
  8756. const pageView = this._pages[this._currentPageNumber - 1];
  8757. if (this.isInPresentationMode) {
  8758. this._setScale(this._currentScaleValue, true);
  8759. }
  8760. this.#scrollIntoView(pageView);
  8761. }
  8762. pageLabelToPageNumber(label) {
  8763. if (!this._pageLabels) {
  8764. return null;
  8765. }
  8766. const i = this._pageLabels.indexOf(label);
  8767. if (i < 0) {
  8768. return null;
  8769. }
  8770. return i + 1;
  8771. }
  8772. scrollPageIntoView({
  8773. pageNumber,
  8774. destArray = null,
  8775. allowNegativeOffset = false,
  8776. ignoreDestinationZoom = false
  8777. }) {
  8778. if (!this.pdfDocument) {
  8779. return;
  8780. }
  8781. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8782. if (!pageView) {
  8783. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  8784. return;
  8785. }
  8786. if (this.isInPresentationMode || !destArray) {
  8787. this._setCurrentPageNumber(pageNumber, true);
  8788. return;
  8789. }
  8790. let x = 0,
  8791. y = 0;
  8792. let width = 0,
  8793. height = 0,
  8794. widthScale,
  8795. heightScale;
  8796. const changeOrientation = pageView.rotation % 180 !== 0;
  8797. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8798. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8799. let scale = 0;
  8800. switch (destArray[1].name) {
  8801. case "XYZ":
  8802. x = destArray[2];
  8803. y = destArray[3];
  8804. scale = destArray[4];
  8805. x = x !== null ? x : 0;
  8806. y = y !== null ? y : pageHeight;
  8807. break;
  8808. case "Fit":
  8809. case "FitB":
  8810. scale = "page-fit";
  8811. break;
  8812. case "FitH":
  8813. case "FitBH":
  8814. y = destArray[2];
  8815. scale = "page-width";
  8816. if (y === null && this._location) {
  8817. x = this._location.left;
  8818. y = this._location.top;
  8819. } else if (typeof y !== "number" || y < 0) {
  8820. y = pageHeight;
  8821. }
  8822. break;
  8823. case "FitV":
  8824. case "FitBV":
  8825. x = destArray[2];
  8826. width = pageWidth;
  8827. height = pageHeight;
  8828. scale = "page-height";
  8829. break;
  8830. case "FitR":
  8831. x = destArray[2];
  8832. y = destArray[3];
  8833. width = destArray[4] - x;
  8834. height = destArray[5] - y;
  8835. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8836. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8837. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8838. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8839. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8840. break;
  8841. default:
  8842. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  8843. return;
  8844. }
  8845. if (!ignoreDestinationZoom) {
  8846. if (scale && scale !== this._currentScale) {
  8847. this.currentScaleValue = scale;
  8848. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8849. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8850. }
  8851. }
  8852. if (scale === "page-fit" && !destArray[4]) {
  8853. this.#scrollIntoView(pageView);
  8854. return;
  8855. }
  8856. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8857. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8858. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8859. if (!allowNegativeOffset) {
  8860. left = Math.max(left, 0);
  8861. top = Math.max(top, 0);
  8862. }
  8863. this.#scrollIntoView(pageView, {
  8864. left,
  8865. top
  8866. });
  8867. }
  8868. _updateLocation(firstPage) {
  8869. const currentScale = this._currentScale;
  8870. const currentScaleValue = this._currentScaleValue;
  8871. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8872. const pageNumber = firstPage.id;
  8873. const currentPageView = this._pages[pageNumber - 1];
  8874. const container = this.container;
  8875. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8876. const intLeft = Math.round(topLeft[0]);
  8877. const intTop = Math.round(topLeft[1]);
  8878. let pdfOpenParams = `#page=${pageNumber}`;
  8879. if (!this.isInPresentationMode) {
  8880. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  8881. }
  8882. this._location = {
  8883. pageNumber,
  8884. scale: normalizedScaleValue,
  8885. top: intTop,
  8886. left: intLeft,
  8887. rotation: this._pagesRotation,
  8888. pdfOpenParams
  8889. };
  8890. }
  8891. update() {
  8892. const visible = this._getVisiblePages();
  8893. const visiblePages = visible.views,
  8894. numVisiblePages = visiblePages.length;
  8895. if (numVisiblePages === 0) {
  8896. return;
  8897. }
  8898. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8899. this.#buffer.resize(newCacheSize, visible.ids);
  8900. this.renderingQueue.renderHighestPriority(visible);
  8901. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  8902. const currentId = this._currentPageNumber;
  8903. let stillFullyVisible = false;
  8904. for (const page of visiblePages) {
  8905. if (page.percent < 100) {
  8906. break;
  8907. }
  8908. if (page.id === currentId && isSimpleLayout) {
  8909. stillFullyVisible = true;
  8910. break;
  8911. }
  8912. }
  8913. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  8914. this._updateLocation(visible.first);
  8915. this.eventBus.dispatch("updateviewarea", {
  8916. source: this,
  8917. location: this._location
  8918. });
  8919. }
  8920. containsElement(element) {
  8921. return this.container.contains(element);
  8922. }
  8923. focus() {
  8924. this.container.focus();
  8925. }
  8926. get _isContainerRtl() {
  8927. return getComputedStyle(this.container).direction === "rtl";
  8928. }
  8929. get isInPresentationMode() {
  8930. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8931. }
  8932. get isChangingPresentationMode() {
  8933. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8934. }
  8935. get isHorizontalScrollbarEnabled() {
  8936. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8937. }
  8938. get isVerticalScrollbarEnabled() {
  8939. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8940. }
  8941. _getVisiblePages() {
  8942. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  8943. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  8944. rtl = horizontal && this._isContainerRtl;
  8945. return (0, _ui_utils.getVisibleElements)({
  8946. scrollEl: this.container,
  8947. views,
  8948. sortByVisibility: true,
  8949. horizontal,
  8950. rtl
  8951. });
  8952. }
  8953. isPageVisible(pageNumber) {
  8954. if (!this.pdfDocument) {
  8955. return false;
  8956. }
  8957. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8958. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  8959. return false;
  8960. }
  8961. return this._getVisiblePages().ids.has(pageNumber);
  8962. }
  8963. isPageCached(pageNumber) {
  8964. if (!this.pdfDocument) {
  8965. return false;
  8966. }
  8967. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8968. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  8969. return false;
  8970. }
  8971. const pageView = this._pages[pageNumber - 1];
  8972. return this.#buffer.has(pageView);
  8973. }
  8974. cleanup() {
  8975. for (const pageView of this._pages) {
  8976. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8977. pageView.reset();
  8978. }
  8979. }
  8980. }
  8981. _cancelRendering() {
  8982. for (const pageView of this._pages) {
  8983. pageView.cancelRendering();
  8984. }
  8985. }
  8986. async #ensurePdfPageLoaded(pageView) {
  8987. if (pageView.pdfPage) {
  8988. return pageView.pdfPage;
  8989. }
  8990. try {
  8991. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  8992. if (!pageView.pdfPage) {
  8993. pageView.setPdfPage(pdfPage);
  8994. }
  8995. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  8996. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  8997. }
  8998. return pdfPage;
  8999. } catch (reason) {
  9000. console.error("Unable to get page for page view", reason);
  9001. return null;
  9002. }
  9003. }
  9004. #getScrollAhead(visible) {
  9005. if (visible.first?.id === 1) {
  9006. return true;
  9007. } else if (visible.last?.id === this.pagesCount) {
  9008. return false;
  9009. }
  9010. switch (this._scrollMode) {
  9011. case _ui_utils.ScrollMode.PAGE:
  9012. return this.#scrollModePageState.scrollDown;
  9013. case _ui_utils.ScrollMode.HORIZONTAL:
  9014. return this.scroll.right;
  9015. }
  9016. return this.scroll.down;
  9017. }
  9018. #toggleLoadingIconSpinner(visibleIds) {
  9019. for (const id of visibleIds) {
  9020. const pageView = this._pages[id - 1];
  9021. pageView?.toggleLoadingIconSpinner(true);
  9022. }
  9023. for (const pageView of this.#buffer) {
  9024. if (visibleIds.has(pageView.id)) {
  9025. continue;
  9026. }
  9027. pageView.toggleLoadingIconSpinner(false);
  9028. }
  9029. }
  9030. forceRendering(currentlyVisiblePages) {
  9031. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9032. const scrollAhead = this.#getScrollAhead(visiblePages);
  9033. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9034. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9035. this.#toggleLoadingIconSpinner(visiblePages.ids);
  9036. if (pageView) {
  9037. this.#ensurePdfPageLoaded(pageView).then(() => {
  9038. this.renderingQueue.renderView(pageView);
  9039. });
  9040. return true;
  9041. }
  9042. return false;
  9043. }
  9044. createTextLayerBuilder({
  9045. textLayerDiv,
  9046. pageIndex,
  9047. viewport,
  9048. enhanceTextSelection = false,
  9049. eventBus,
  9050. highlighter,
  9051. accessibilityManager = null
  9052. }) {
  9053. return new _text_layer_builder.TextLayerBuilder({
  9054. textLayerDiv,
  9055. eventBus,
  9056. pageIndex,
  9057. viewport,
  9058. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection,
  9059. highlighter,
  9060. accessibilityManager
  9061. });
  9062. }
  9063. createTextHighlighter({
  9064. pageIndex,
  9065. eventBus
  9066. }) {
  9067. return new _text_highlighter.TextHighlighter({
  9068. eventBus,
  9069. pageIndex,
  9070. findController: this.isInPresentationMode ? null : this.findController
  9071. });
  9072. }
  9073. createAnnotationLayerBuilder({
  9074. pageDiv,
  9075. pdfPage,
  9076. annotationStorage = this.pdfDocument?.annotationStorage,
  9077. imageResourcesPath = "",
  9078. renderForms = true,
  9079. l10n = _l10n_utils.NullL10n,
  9080. enableScripting = this.enableScripting,
  9081. hasJSActionsPromise = this.pdfDocument?.hasJSActions(),
  9082. mouseState = this._scriptingManager?.mouseState,
  9083. fieldObjectsPromise = this.pdfDocument?.getFieldObjects(),
  9084. annotationCanvasMap = null,
  9085. accessibilityManager = null
  9086. }) {
  9087. return new _annotation_layer_builder.AnnotationLayerBuilder({
  9088. pageDiv,
  9089. pdfPage,
  9090. annotationStorage,
  9091. imageResourcesPath,
  9092. renderForms,
  9093. linkService: this.linkService,
  9094. downloadManager: this.downloadManager,
  9095. l10n,
  9096. enableScripting,
  9097. hasJSActionsPromise,
  9098. mouseState,
  9099. fieldObjectsPromise,
  9100. annotationCanvasMap,
  9101. accessibilityManager
  9102. });
  9103. }
  9104. createAnnotationEditorLayerBuilder({
  9105. uiManager = this.#annotationEditorUIManager,
  9106. pageDiv,
  9107. pdfPage,
  9108. accessibilityManager = null,
  9109. l10n,
  9110. annotationStorage = this.pdfDocument?.annotationStorage
  9111. }) {
  9112. return new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  9113. uiManager,
  9114. pageDiv,
  9115. pdfPage,
  9116. annotationStorage,
  9117. accessibilityManager,
  9118. l10n
  9119. });
  9120. }
  9121. createXfaLayerBuilder({
  9122. pageDiv,
  9123. pdfPage,
  9124. annotationStorage = this.pdfDocument?.annotationStorage
  9125. }) {
  9126. return new _xfa_layer_builder.XfaLayerBuilder({
  9127. pageDiv,
  9128. pdfPage,
  9129. annotationStorage,
  9130. linkService: this.linkService
  9131. });
  9132. }
  9133. createStructTreeLayerBuilder({
  9134. pdfPage
  9135. }) {
  9136. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  9137. pdfPage
  9138. });
  9139. }
  9140. get hasEqualPageSizes() {
  9141. const firstPageView = this._pages[0];
  9142. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  9143. const pageView = this._pages[i];
  9144. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9145. return false;
  9146. }
  9147. }
  9148. return true;
  9149. }
  9150. getPagesOverview() {
  9151. return this._pages.map(pageView => {
  9152. const viewport = pageView.pdfPage.getViewport({
  9153. scale: 1
  9154. });
  9155. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  9156. return {
  9157. width: viewport.width,
  9158. height: viewport.height,
  9159. rotation: viewport.rotation
  9160. };
  9161. }
  9162. return {
  9163. width: viewport.height,
  9164. height: viewport.width,
  9165. rotation: (viewport.rotation - 90) % 360
  9166. };
  9167. });
  9168. }
  9169. get optionalContentConfigPromise() {
  9170. if (!this.pdfDocument) {
  9171. return Promise.resolve(null);
  9172. }
  9173. if (!this._optionalContentConfigPromise) {
  9174. console.error("optionalContentConfigPromise: Not initialized yet.");
  9175. return this.pdfDocument.getOptionalContentConfig();
  9176. }
  9177. return this._optionalContentConfigPromise;
  9178. }
  9179. set optionalContentConfigPromise(promise) {
  9180. if (!(promise instanceof Promise)) {
  9181. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  9182. }
  9183. if (!this.pdfDocument) {
  9184. return;
  9185. }
  9186. if (!this._optionalContentConfigPromise) {
  9187. return;
  9188. }
  9189. this._optionalContentConfigPromise = promise;
  9190. const updateArgs = {
  9191. optionalContentConfigPromise: promise
  9192. };
  9193. for (const pageView of this._pages) {
  9194. pageView.update(updateArgs);
  9195. }
  9196. this.update();
  9197. this.eventBus.dispatch("optionalcontentconfigchanged", {
  9198. source: this,
  9199. promise
  9200. });
  9201. }
  9202. get scrollMode() {
  9203. return this._scrollMode;
  9204. }
  9205. set scrollMode(mode) {
  9206. if (this._scrollMode === mode) {
  9207. return;
  9208. }
  9209. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9210. throw new Error(`Invalid scroll mode: ${mode}`);
  9211. }
  9212. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9213. return;
  9214. }
  9215. this._previousScrollMode = this._scrollMode;
  9216. this._scrollMode = mode;
  9217. this.eventBus.dispatch("scrollmodechanged", {
  9218. source: this,
  9219. mode
  9220. });
  9221. this._updateScrollMode(this._currentPageNumber);
  9222. }
  9223. _updateScrollMode(pageNumber = null) {
  9224. const scrollMode = this._scrollMode,
  9225. viewer = this.viewer;
  9226. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9227. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9228. if (!this.pdfDocument || !pageNumber) {
  9229. return;
  9230. }
  9231. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9232. this.#ensurePageViewVisible();
  9233. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9234. this._updateSpreadMode();
  9235. }
  9236. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9237. this._setScale(this._currentScaleValue, true);
  9238. }
  9239. this._setCurrentPageNumber(pageNumber, true);
  9240. this.update();
  9241. }
  9242. get spreadMode() {
  9243. return this._spreadMode;
  9244. }
  9245. set spreadMode(mode) {
  9246. if (this._spreadMode === mode) {
  9247. return;
  9248. }
  9249. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9250. throw new Error(`Invalid spread mode: ${mode}`);
  9251. }
  9252. this._spreadMode = mode;
  9253. this.eventBus.dispatch("spreadmodechanged", {
  9254. source: this,
  9255. mode
  9256. });
  9257. this._updateSpreadMode(this._currentPageNumber);
  9258. }
  9259. _updateSpreadMode(pageNumber = null) {
  9260. if (!this.pdfDocument) {
  9261. return;
  9262. }
  9263. const viewer = this.viewer,
  9264. pages = this._pages;
  9265. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9266. this.#ensurePageViewVisible();
  9267. } else {
  9268. viewer.textContent = "";
  9269. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9270. for (const pageView of this._pages) {
  9271. viewer.append(pageView.div);
  9272. }
  9273. } else {
  9274. const parity = this._spreadMode - 1;
  9275. let spread = null;
  9276. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9277. if (spread === null) {
  9278. spread = document.createElement("div");
  9279. spread.className = "spread";
  9280. viewer.append(spread);
  9281. } else if (i % 2 === parity) {
  9282. spread = spread.cloneNode(false);
  9283. viewer.append(spread);
  9284. }
  9285. spread.append(pages[i].div);
  9286. }
  9287. }
  9288. }
  9289. if (!pageNumber) {
  9290. return;
  9291. }
  9292. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9293. this._setScale(this._currentScaleValue, true);
  9294. }
  9295. this._setCurrentPageNumber(pageNumber, true);
  9296. this.update();
  9297. }
  9298. _getPageAdvance(currentPageNumber, previous = false) {
  9299. switch (this._scrollMode) {
  9300. case _ui_utils.ScrollMode.WRAPPED:
  9301. {
  9302. const {
  9303. views
  9304. } = this._getVisiblePages(),
  9305. pageLayout = new Map();
  9306. for (const {
  9307. id,
  9308. y,
  9309. percent,
  9310. widthPercent
  9311. } of views) {
  9312. if (percent === 0 || widthPercent < 100) {
  9313. continue;
  9314. }
  9315. let yArray = pageLayout.get(y);
  9316. if (!yArray) {
  9317. pageLayout.set(y, yArray ||= []);
  9318. }
  9319. yArray.push(id);
  9320. }
  9321. for (const yArray of pageLayout.values()) {
  9322. const currentIndex = yArray.indexOf(currentPageNumber);
  9323. if (currentIndex === -1) {
  9324. continue;
  9325. }
  9326. const numPages = yArray.length;
  9327. if (numPages === 1) {
  9328. break;
  9329. }
  9330. if (previous) {
  9331. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9332. const currentId = yArray[i],
  9333. expectedId = yArray[i + 1] - 1;
  9334. if (currentId < expectedId) {
  9335. return currentPageNumber - expectedId;
  9336. }
  9337. }
  9338. } else {
  9339. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9340. const currentId = yArray[i],
  9341. expectedId = yArray[i - 1] + 1;
  9342. if (currentId > expectedId) {
  9343. return expectedId - currentPageNumber;
  9344. }
  9345. }
  9346. }
  9347. if (previous) {
  9348. const firstId = yArray[0];
  9349. if (firstId < currentPageNumber) {
  9350. return currentPageNumber - firstId + 1;
  9351. }
  9352. } else {
  9353. const lastId = yArray[numPages - 1];
  9354. if (lastId > currentPageNumber) {
  9355. return lastId - currentPageNumber + 1;
  9356. }
  9357. }
  9358. break;
  9359. }
  9360. break;
  9361. }
  9362. case _ui_utils.ScrollMode.HORIZONTAL:
  9363. {
  9364. break;
  9365. }
  9366. case _ui_utils.ScrollMode.PAGE:
  9367. case _ui_utils.ScrollMode.VERTICAL:
  9368. {
  9369. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9370. break;
  9371. }
  9372. const parity = this._spreadMode - 1;
  9373. if (previous && currentPageNumber % 2 !== parity) {
  9374. break;
  9375. } else if (!previous && currentPageNumber % 2 === parity) {
  9376. break;
  9377. }
  9378. const {
  9379. views
  9380. } = this._getVisiblePages(),
  9381. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9382. for (const {
  9383. id,
  9384. percent,
  9385. widthPercent
  9386. } of views) {
  9387. if (id !== expectedId) {
  9388. continue;
  9389. }
  9390. if (percent > 0 && widthPercent === 100) {
  9391. return 2;
  9392. }
  9393. break;
  9394. }
  9395. break;
  9396. }
  9397. }
  9398. return 1;
  9399. }
  9400. nextPage() {
  9401. const currentPageNumber = this._currentPageNumber,
  9402. pagesCount = this.pagesCount;
  9403. if (currentPageNumber >= pagesCount) {
  9404. return false;
  9405. }
  9406. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9407. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9408. return true;
  9409. }
  9410. previousPage() {
  9411. const currentPageNumber = this._currentPageNumber;
  9412. if (currentPageNumber <= 1) {
  9413. return false;
  9414. }
  9415. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9416. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9417. return true;
  9418. }
  9419. increaseScale(steps = 1) {
  9420. let newScale = this._currentScale;
  9421. do {
  9422. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9423. newScale = Math.ceil(newScale * 10) / 10;
  9424. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  9425. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9426. this.currentScaleValue = newScale;
  9427. }
  9428. decreaseScale(steps = 1) {
  9429. let newScale = this._currentScale;
  9430. do {
  9431. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9432. newScale = Math.floor(newScale * 10) / 10;
  9433. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  9434. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9435. this.currentScaleValue = newScale;
  9436. }
  9437. updateContainerHeightCss() {
  9438. const height = this.container.clientHeight;
  9439. if (height !== this.#previousContainerHeight) {
  9440. this.#previousContainerHeight = height;
  9441. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  9442. }
  9443. }
  9444. get annotationEditorMode() {
  9445. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  9446. }
  9447. set annotationEditorMode(mode) {
  9448. if (!this.#annotationEditorUIManager) {
  9449. throw new Error(`The AnnotationEditor is not enabled.`);
  9450. }
  9451. if (this.#annotationEditorMode === mode) {
  9452. return;
  9453. }
  9454. if (!isValidAnnotationEditorMode(mode)) {
  9455. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  9456. }
  9457. if (!this.pdfDocument) {
  9458. return;
  9459. }
  9460. this.#annotationEditorMode = mode;
  9461. this.eventBus.dispatch("annotationeditormodechanged", {
  9462. source: this,
  9463. mode
  9464. });
  9465. this.#annotationEditorUIManager.updateMode(mode);
  9466. }
  9467. set annotationEditorParams({
  9468. type,
  9469. value
  9470. }) {
  9471. if (!this.#annotationEditorUIManager) {
  9472. throw new Error(`The AnnotationEditor is not enabled.`);
  9473. }
  9474. this.#annotationEditorUIManager.updateParams(type, value);
  9475. }
  9476. refresh() {
  9477. if (!this.pdfDocument) {
  9478. return;
  9479. }
  9480. const updateArgs = {};
  9481. for (const pageView of this._pages) {
  9482. pageView.update(updateArgs);
  9483. }
  9484. this.update();
  9485. }
  9486. }
  9487. exports.BaseViewer = BaseViewer;
  9488. /***/
  9489. }),
  9490. /* 30 */
  9491. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9492. Object.defineProperty(exports, "__esModule", ({
  9493. value: true
  9494. }));
  9495. exports.AnnotationEditorLayerBuilder = void 0;
  9496. var _pdfjsLib = __webpack_require__(5);
  9497. var _l10n_utils = __webpack_require__(31);
  9498. class AnnotationEditorLayerBuilder {
  9499. #uiManager;
  9500. constructor(options) {
  9501. this.pageDiv = options.pageDiv;
  9502. this.pdfPage = options.pdfPage;
  9503. this.annotationStorage = options.annotationStorage || null;
  9504. this.accessibilityManager = options.accessibilityManager;
  9505. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9506. this.annotationEditorLayer = null;
  9507. this.div = null;
  9508. this._cancelled = false;
  9509. this.#uiManager = options.uiManager;
  9510. }
  9511. async render(viewport, intent = "display") {
  9512. if (intent !== "display") {
  9513. return;
  9514. }
  9515. if (this._cancelled) {
  9516. return;
  9517. }
  9518. const clonedViewport = viewport.clone({
  9519. dontFlip: true
  9520. });
  9521. if (this.div) {
  9522. this.annotationEditorLayer.update({
  9523. viewport: clonedViewport
  9524. });
  9525. this.show();
  9526. return;
  9527. }
  9528. this.div = document.createElement("div");
  9529. this.div.className = "annotationEditorLayer";
  9530. this.div.tabIndex = 0;
  9531. this.pageDiv.append(this.div);
  9532. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  9533. uiManager: this.#uiManager,
  9534. div: this.div,
  9535. annotationStorage: this.annotationStorage,
  9536. accessibilityManager: this.accessibilityManager,
  9537. pageIndex: this.pdfPage._pageIndex,
  9538. l10n: this.l10n,
  9539. viewport: clonedViewport
  9540. });
  9541. const parameters = {
  9542. viewport: clonedViewport,
  9543. div: this.div,
  9544. annotations: null,
  9545. intent
  9546. };
  9547. this.annotationEditorLayer.render(parameters);
  9548. }
  9549. cancel() {
  9550. this._cancelled = true;
  9551. this.destroy();
  9552. }
  9553. hide() {
  9554. if (!this.div) {
  9555. return;
  9556. }
  9557. this.div.hidden = true;
  9558. }
  9559. show() {
  9560. if (!this.div) {
  9561. return;
  9562. }
  9563. this.div.hidden = false;
  9564. }
  9565. destroy() {
  9566. if (!this.div) {
  9567. return;
  9568. }
  9569. this.pageDiv = null;
  9570. this.annotationEditorLayer.destroy();
  9571. this.div.remove();
  9572. }
  9573. }
  9574. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  9575. /***/
  9576. }),
  9577. /* 31 */
  9578. /***/ ((__unused_webpack_module, exports) => {
  9579. Object.defineProperty(exports, "__esModule", ({
  9580. value: true
  9581. }));
  9582. exports.NullL10n = void 0;
  9583. exports.fixupLangCode = fixupLangCode;
  9584. exports.getL10nFallback = getL10nFallback;
  9585. const DEFAULT_L10N_STRINGS = {
  9586. of_pages: "of {{pagesCount}}",
  9587. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9588. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9589. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9590. document_properties_date_string: "{{date}}, {{time}}",
  9591. document_properties_page_size_unit_inches: "in",
  9592. document_properties_page_size_unit_millimeters: "mm",
  9593. document_properties_page_size_orientation_portrait: "portrait",
  9594. document_properties_page_size_orientation_landscape: "landscape",
  9595. document_properties_page_size_name_a3: "A3",
  9596. document_properties_page_size_name_a4: "A4",
  9597. document_properties_page_size_name_letter: "Letter",
  9598. document_properties_page_size_name_legal: "Legal",
  9599. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9600. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9601. document_properties_linearized_yes: "Yes",
  9602. document_properties_linearized_no: "No",
  9603. print_progress_percent: "{{progress}}%",
  9604. "toggle_sidebar.title": "Toggle Sidebar",
  9605. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  9606. additional_layers: "Additional Layers",
  9607. page_landmark: "Page {{page}}",
  9608. thumb_page_title: "Page {{page}}",
  9609. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9610. find_reached_top: "Reached top of document, continued from bottom",
  9611. find_reached_bottom: "Reached end of document, continued from top",
  9612. "find_match_count[one]": "{{current}} of {{total}} match",
  9613. "find_match_count[other]": "{{current}} of {{total}} matches",
  9614. "find_match_count_limit[one]": "More than {{limit}} match",
  9615. "find_match_count_limit[other]": "More than {{limit}} matches",
  9616. find_not_found: "Phrase not found",
  9617. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  9618. error_message: "Message: {{message}}",
  9619. error_stack: "Stack: {{stack}}",
  9620. error_file: "File: {{file}}",
  9621. error_line: "Line: {{line}}",
  9622. rendering_error: "An error occurred while rendering the page.",
  9623. page_scale_width: "Page Width",
  9624. page_scale_fit: "Page Fit",
  9625. page_scale_auto: "Automatic Zoom",
  9626. page_scale_actual: "Actual Size",
  9627. page_scale_percent: "{{scale}}%",
  9628. loading: "Loading…",
  9629. loading_error: "An error occurred while loading the PDF.",
  9630. invalid_file_error: "Invalid or corrupted PDF file.",
  9631. missing_file_error: "Missing PDF file.",
  9632. unexpected_response_error: "Unexpected server response.",
  9633. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9634. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9635. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  9636. free_text_default_content: "Enter text…",
  9637. editor_free_text_aria_label: "FreeText Editor",
  9638. editor_ink_aria_label: "Ink Editor",
  9639. editor_ink_canvas_aria_label: "User-created image"
  9640. };
  9641. function getL10nFallback(key, args) {
  9642. switch (key) {
  9643. case "find_match_count":
  9644. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9645. break;
  9646. case "find_match_count_limit":
  9647. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9648. break;
  9649. }
  9650. return DEFAULT_L10N_STRINGS[key] || "";
  9651. }
  9652. const PARTIAL_LANG_CODES = {
  9653. en: "en-US",
  9654. es: "es-ES",
  9655. fy: "fy-NL",
  9656. ga: "ga-IE",
  9657. gu: "gu-IN",
  9658. hi: "hi-IN",
  9659. hy: "hy-AM",
  9660. nb: "nb-NO",
  9661. ne: "ne-NP",
  9662. nn: "nn-NO",
  9663. pa: "pa-IN",
  9664. pt: "pt-PT",
  9665. sv: "sv-SE",
  9666. zh: "zh-CN"
  9667. };
  9668. function fixupLangCode(langCode) {
  9669. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9670. }
  9671. function formatL10nValue(text, args) {
  9672. if (!args) {
  9673. return text;
  9674. }
  9675. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9676. return name in args ? args[name] : "{{" + name + "}}";
  9677. });
  9678. }
  9679. const NullL10n = {
  9680. async getLanguage() {
  9681. return "en-us";
  9682. },
  9683. async getDirection() {
  9684. return "ltr";
  9685. },
  9686. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9687. return formatL10nValue(fallback, args);
  9688. },
  9689. async translate(element) { }
  9690. };
  9691. exports.NullL10n = NullL10n;
  9692. /***/
  9693. }),
  9694. /* 32 */
  9695. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9696. Object.defineProperty(exports, "__esModule", ({
  9697. value: true
  9698. }));
  9699. exports.AnnotationLayerBuilder = void 0;
  9700. var _pdfjsLib = __webpack_require__(5);
  9701. var _l10n_utils = __webpack_require__(31);
  9702. class AnnotationLayerBuilder {
  9703. constructor({
  9704. pageDiv,
  9705. pdfPage,
  9706. linkService,
  9707. downloadManager,
  9708. annotationStorage = null,
  9709. imageResourcesPath = "",
  9710. renderForms = true,
  9711. l10n = _l10n_utils.NullL10n,
  9712. enableScripting = false,
  9713. hasJSActionsPromise = null,
  9714. fieldObjectsPromise = null,
  9715. mouseState = null,
  9716. annotationCanvasMap = null,
  9717. accessibilityManager = null
  9718. }) {
  9719. this.pageDiv = pageDiv;
  9720. this.pdfPage = pdfPage;
  9721. this.linkService = linkService;
  9722. this.downloadManager = downloadManager;
  9723. this.imageResourcesPath = imageResourcesPath;
  9724. this.renderForms = renderForms;
  9725. this.l10n = l10n;
  9726. this.annotationStorage = annotationStorage;
  9727. this.enableScripting = enableScripting;
  9728. this._hasJSActionsPromise = hasJSActionsPromise;
  9729. this._fieldObjectsPromise = fieldObjectsPromise;
  9730. this._mouseState = mouseState;
  9731. this._annotationCanvasMap = annotationCanvasMap;
  9732. this._accessibilityManager = accessibilityManager;
  9733. this.div = null;
  9734. this._cancelled = false;
  9735. }
  9736. async render(viewport, intent = "display") {
  9737. const [annotations, hasJSActions = false, fieldObjects = null] = await Promise.all([this.pdfPage.getAnnotations({
  9738. intent
  9739. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  9740. if (this._cancelled || annotations.length === 0) {
  9741. return;
  9742. }
  9743. const parameters = {
  9744. viewport: viewport.clone({
  9745. dontFlip: true
  9746. }),
  9747. div: this.div,
  9748. annotations,
  9749. page: this.pdfPage,
  9750. imageResourcesPath: this.imageResourcesPath,
  9751. renderForms: this.renderForms,
  9752. linkService: this.linkService,
  9753. downloadManager: this.downloadManager,
  9754. annotationStorage: this.annotationStorage,
  9755. enableScripting: this.enableScripting,
  9756. hasJSActions,
  9757. fieldObjects,
  9758. mouseState: this._mouseState,
  9759. annotationCanvasMap: this._annotationCanvasMap,
  9760. accessibilityManager: this._accessibilityManager
  9761. };
  9762. if (this.div) {
  9763. _pdfjsLib.AnnotationLayer.update(parameters);
  9764. } else {
  9765. this.div = document.createElement("div");
  9766. this.div.className = "annotationLayer";
  9767. this.pageDiv.append(this.div);
  9768. parameters.div = this.div;
  9769. _pdfjsLib.AnnotationLayer.render(parameters);
  9770. this.l10n.translate(this.div);
  9771. }
  9772. }
  9773. cancel() {
  9774. this._cancelled = true;
  9775. }
  9776. hide() {
  9777. if (!this.div) {
  9778. return;
  9779. }
  9780. this.div.hidden = true;
  9781. }
  9782. }
  9783. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  9784. /***/
  9785. }),
  9786. /* 33 */
  9787. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9788. Object.defineProperty(exports, "__esModule", ({
  9789. value: true
  9790. }));
  9791. exports.PDFPageView = void 0;
  9792. var _pdfjsLib = __webpack_require__(5);
  9793. var _ui_utils = __webpack_require__(1);
  9794. var _app_options = __webpack_require__(2);
  9795. var _l10n_utils = __webpack_require__(31);
  9796. var _text_accessibility = __webpack_require__(34);
  9797. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9798. class PDFPageView {
  9799. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9800. #useThumbnailCanvas = {
  9801. initialOptionalContent: true,
  9802. regularAnnotations: true
  9803. };
  9804. constructor(options) {
  9805. const container = options.container;
  9806. const defaultViewport = options.defaultViewport;
  9807. this.id = options.id;
  9808. this.renderingId = "page" + this.id;
  9809. this.pdfPage = null;
  9810. this.pageLabel = null;
  9811. this.rotation = 0;
  9812. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9813. this.viewport = defaultViewport;
  9814. this.pdfPageRotate = defaultViewport.rotation;
  9815. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9816. this.hasRestrictedScaling = false;
  9817. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9818. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9819. this.imageResourcesPath = options.imageResourcesPath || "";
  9820. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9821. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9822. this.pageColors = options.pageColors || null;
  9823. this.eventBus = options.eventBus;
  9824. this.renderingQueue = options.renderingQueue;
  9825. this.textLayerFactory = options.textLayerFactory;
  9826. this.annotationLayerFactory = options.annotationLayerFactory;
  9827. this.annotationEditorLayerFactory = options.annotationEditorLayerFactory;
  9828. this.xfaLayerFactory = options.xfaLayerFactory;
  9829. this.textHighlighter = options.textHighlighterFactory?.createTextHighlighter({
  9830. pageIndex: this.id - 1,
  9831. eventBus: this.eventBus
  9832. });
  9833. this.structTreeLayerFactory = options.structTreeLayerFactory;
  9834. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9835. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9836. this.paintTask = null;
  9837. this.paintedViewportMap = new WeakMap();
  9838. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9839. this.resume = null;
  9840. this._renderError = null;
  9841. this._isStandalone = !this.renderingQueue?.hasViewer();
  9842. this._annotationCanvasMap = null;
  9843. this.annotationLayer = null;
  9844. this.annotationEditorLayer = null;
  9845. this.textLayer = null;
  9846. this.zoomLayer = null;
  9847. this.xfaLayer = null;
  9848. this.structTreeLayer = null;
  9849. const div = document.createElement("div");
  9850. div.className = "page";
  9851. div.style.width = Math.floor(this.viewport.width) + "px";
  9852. div.style.height = Math.floor(this.viewport.height) + "px";
  9853. div.setAttribute("data-page-number", this.id);
  9854. div.setAttribute("role", "region");
  9855. this.l10n.get("page_landmark", {
  9856. page: this.id
  9857. }).then(msg => {
  9858. div.setAttribute("aria-label", msg);
  9859. });
  9860. this.div = div;
  9861. container?.append(div);
  9862. if (this._isStandalone) {
  9863. const {
  9864. optionalContentConfigPromise
  9865. } = options;
  9866. if (optionalContentConfigPromise) {
  9867. optionalContentConfigPromise.then(optionalContentConfig => {
  9868. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9869. return;
  9870. }
  9871. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9872. });
  9873. }
  9874. }
  9875. }
  9876. setPdfPage(pdfPage) {
  9877. this.pdfPage = pdfPage;
  9878. this.pdfPageRotate = pdfPage.rotate;
  9879. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9880. this.viewport = pdfPage.getViewport({
  9881. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9882. rotation: totalRotation
  9883. });
  9884. this.reset();
  9885. }
  9886. destroy() {
  9887. this.reset();
  9888. if (this.pdfPage) {
  9889. this.pdfPage.cleanup();
  9890. }
  9891. }
  9892. async _renderAnnotationLayer() {
  9893. let error = null;
  9894. try {
  9895. await this.annotationLayer.render(this.viewport, "display");
  9896. } catch (ex) {
  9897. console.error(`_renderAnnotationLayer: "${ex}".`);
  9898. error = ex;
  9899. } finally {
  9900. this.eventBus.dispatch("annotationlayerrendered", {
  9901. source: this,
  9902. pageNumber: this.id,
  9903. error
  9904. });
  9905. }
  9906. }
  9907. async _renderAnnotationEditorLayer() {
  9908. let error = null;
  9909. try {
  9910. await this.annotationEditorLayer.render(this.viewport, "display");
  9911. } catch (ex) {
  9912. console.error(`_renderAnnotationEditorLayer: "${ex}".`);
  9913. error = ex;
  9914. } finally {
  9915. this.eventBus.dispatch("annotationeditorlayerrendered", {
  9916. source: this,
  9917. pageNumber: this.id,
  9918. error
  9919. });
  9920. }
  9921. }
  9922. async _renderXfaLayer() {
  9923. let error = null;
  9924. try {
  9925. const result = await this.xfaLayer.render(this.viewport, "display");
  9926. if (this.textHighlighter) {
  9927. this._buildXfaTextContentItems(result.textDivs);
  9928. }
  9929. } catch (ex) {
  9930. console.error(`_renderXfaLayer: "${ex}".`);
  9931. error = ex;
  9932. } finally {
  9933. this.eventBus.dispatch("xfalayerrendered", {
  9934. source: this,
  9935. pageNumber: this.id,
  9936. error
  9937. });
  9938. }
  9939. }
  9940. async _buildXfaTextContentItems(textDivs) {
  9941. const text = await this.pdfPage.getTextContent();
  9942. const items = [];
  9943. for (const item of text.items) {
  9944. items.push(item.str);
  9945. }
  9946. this.textHighlighter.setTextMapping(textDivs, items);
  9947. this.textHighlighter.enable();
  9948. }
  9949. _resetZoomLayer(removeFromDOM = false) {
  9950. if (!this.zoomLayer) {
  9951. return;
  9952. }
  9953. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9954. this.paintedViewportMap.delete(zoomLayerCanvas);
  9955. zoomLayerCanvas.width = 0;
  9956. zoomLayerCanvas.height = 0;
  9957. if (removeFromDOM) {
  9958. this.zoomLayer.remove();
  9959. }
  9960. this.zoomLayer = null;
  9961. }
  9962. reset({
  9963. keepZoomLayer = false,
  9964. keepAnnotationLayer = false,
  9965. keepAnnotationEditorLayer = false,
  9966. keepXfaLayer = false
  9967. } = {}) {
  9968. this.cancelRendering({
  9969. keepAnnotationLayer,
  9970. keepAnnotationEditorLayer,
  9971. keepXfaLayer
  9972. });
  9973. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9974. const div = this.div;
  9975. div.style.width = Math.floor(this.viewport.width) + "px";
  9976. div.style.height = Math.floor(this.viewport.height) + "px";
  9977. const childNodes = div.childNodes,
  9978. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  9979. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  9980. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  9981. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null;
  9982. for (let i = childNodes.length - 1; i >= 0; i--) {
  9983. const node = childNodes[i];
  9984. switch (node) {
  9985. case zoomLayerNode:
  9986. case annotationLayerNode:
  9987. case annotationEditorLayerNode:
  9988. case xfaLayerNode:
  9989. continue;
  9990. }
  9991. node.remove();
  9992. }
  9993. div.removeAttribute("data-loaded");
  9994. if (annotationLayerNode) {
  9995. this.annotationLayer.hide();
  9996. }
  9997. if (annotationEditorLayerNode) {
  9998. this.annotationEditorLayer.hide();
  9999. } else {
  10000. this.annotationEditorLayer?.destroy();
  10001. }
  10002. if (xfaLayerNode) {
  10003. this.xfaLayer.hide();
  10004. }
  10005. if (!zoomLayerNode) {
  10006. if (this.canvas) {
  10007. this.paintedViewportMap.delete(this.canvas);
  10008. this.canvas.width = 0;
  10009. this.canvas.height = 0;
  10010. delete this.canvas;
  10011. }
  10012. this._resetZoomLayer();
  10013. }
  10014. if (this.svg) {
  10015. this.paintedViewportMap.delete(this.svg);
  10016. delete this.svg;
  10017. }
  10018. this.loadingIconDiv = document.createElement("div");
  10019. this.loadingIconDiv.className = "loadingIcon notVisible";
  10020. if (this._isStandalone) {
  10021. this.toggleLoadingIconSpinner(true);
  10022. }
  10023. this.loadingIconDiv.setAttribute("role", "img");
  10024. this.l10n.get("loading").then(msg => {
  10025. this.loadingIconDiv?.setAttribute("aria-label", msg);
  10026. });
  10027. div.append(this.loadingIconDiv);
  10028. }
  10029. update({
  10030. scale = 0,
  10031. rotation = null,
  10032. optionalContentConfigPromise = null
  10033. }) {
  10034. this.scale = scale || this.scale;
  10035. if (typeof rotation === "number") {
  10036. this.rotation = rotation;
  10037. }
  10038. if (optionalContentConfigPromise instanceof Promise) {
  10039. this._optionalContentConfigPromise = optionalContentConfigPromise;
  10040. optionalContentConfigPromise.then(optionalContentConfig => {
  10041. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  10042. return;
  10043. }
  10044. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  10045. });
  10046. }
  10047. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  10048. this.viewport = this.viewport.clone({
  10049. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  10050. rotation: totalRotation
  10051. });
  10052. if (this._isStandalone) {
  10053. _ui_utils.docStyle.setProperty("--scale-factor", this.viewport.scale);
  10054. }
  10055. if (this.svg) {
  10056. this.cssTransform({
  10057. target: this.svg,
  10058. redrawAnnotationLayer: true,
  10059. redrawAnnotationEditorLayer: true,
  10060. redrawXfaLayer: true
  10061. });
  10062. this.eventBus.dispatch("pagerendered", {
  10063. source: this,
  10064. pageNumber: this.id,
  10065. cssTransform: true,
  10066. timestamp: performance.now(),
  10067. error: this._renderError
  10068. });
  10069. return;
  10070. }
  10071. let isScalingRestricted = false;
  10072. if (this.canvas && this.maxCanvasPixels > 0) {
  10073. const outputScale = this.outputScale;
  10074. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  10075. isScalingRestricted = true;
  10076. }
  10077. }
  10078. if (this.canvas) {
  10079. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  10080. this.cssTransform({
  10081. target: this.canvas,
  10082. redrawAnnotationLayer: true,
  10083. redrawAnnotationEditorLayer: true,
  10084. redrawXfaLayer: true
  10085. });
  10086. this.eventBus.dispatch("pagerendered", {
  10087. source: this,
  10088. pageNumber: this.id,
  10089. cssTransform: true,
  10090. timestamp: performance.now(),
  10091. error: this._renderError
  10092. });
  10093. return;
  10094. }
  10095. if (!this.zoomLayer && !this.canvas.hidden) {
  10096. this.zoomLayer = this.canvas.parentNode;
  10097. this.zoomLayer.style.position = "absolute";
  10098. }
  10099. }
  10100. if (this.zoomLayer) {
  10101. this.cssTransform({
  10102. target: this.zoomLayer.firstChild
  10103. });
  10104. }
  10105. this.reset({
  10106. keepZoomLayer: true,
  10107. keepAnnotationLayer: true,
  10108. keepAnnotationEditorLayer: true,
  10109. keepXfaLayer: true
  10110. });
  10111. }
  10112. cancelRendering({
  10113. keepAnnotationLayer = false,
  10114. keepAnnotationEditorLayer = false,
  10115. keepXfaLayer = false
  10116. } = {}) {
  10117. if (this.paintTask) {
  10118. this.paintTask.cancel();
  10119. this.paintTask = null;
  10120. }
  10121. this.resume = null;
  10122. if (this.textLayer) {
  10123. this.textLayer.cancel();
  10124. this.textLayer = null;
  10125. }
  10126. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  10127. this.annotationLayer.cancel();
  10128. this.annotationLayer = null;
  10129. this._annotationCanvasMap = null;
  10130. }
  10131. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  10132. this.annotationEditorLayer.cancel();
  10133. this.annotationEditorLayer = null;
  10134. }
  10135. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  10136. this.xfaLayer.cancel();
  10137. this.xfaLayer = null;
  10138. this.textHighlighter?.disable();
  10139. }
  10140. if (this._onTextLayerRendered) {
  10141. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  10142. this._onTextLayerRendered = null;
  10143. }
  10144. }
  10145. cssTransform({
  10146. target,
  10147. redrawAnnotationLayer = false,
  10148. redrawAnnotationEditorLayer = false,
  10149. redrawXfaLayer = false
  10150. }) {
  10151. const width = this.viewport.width;
  10152. const height = this.viewport.height;
  10153. const div = this.div;
  10154. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  10155. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  10156. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  10157. const absRotation = Math.abs(relativeRotation);
  10158. let scaleX = 1,
  10159. scaleY = 1;
  10160. if (absRotation === 90 || absRotation === 270) {
  10161. scaleX = height / width;
  10162. scaleY = width / height;
  10163. }
  10164. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  10165. if (this.textLayer) {
  10166. const textLayerViewport = this.textLayer.viewport;
  10167. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  10168. const textAbsRotation = Math.abs(textRelativeRotation);
  10169. let scale = width / textLayerViewport.width;
  10170. if (textAbsRotation === 90 || textAbsRotation === 270) {
  10171. scale = width / textLayerViewport.height;
  10172. }
  10173. const textLayerDiv = this.textLayer.textLayerDiv;
  10174. let transX, transY;
  10175. switch (textAbsRotation) {
  10176. case 0:
  10177. transX = transY = 0;
  10178. break;
  10179. case 90:
  10180. transX = 0;
  10181. transY = "-" + textLayerDiv.style.height;
  10182. break;
  10183. case 180:
  10184. transX = "-" + textLayerDiv.style.width;
  10185. transY = "-" + textLayerDiv.style.height;
  10186. break;
  10187. case 270:
  10188. transX = "-" + textLayerDiv.style.width;
  10189. transY = 0;
  10190. break;
  10191. default:
  10192. console.error("Bad rotation value.");
  10193. break;
  10194. }
  10195. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  10196. textLayerDiv.style.transformOrigin = "0% 0%";
  10197. }
  10198. if (redrawAnnotationLayer && this.annotationLayer) {
  10199. this._renderAnnotationLayer();
  10200. }
  10201. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  10202. this._renderAnnotationEditorLayer();
  10203. }
  10204. if (redrawXfaLayer && this.xfaLayer) {
  10205. this._renderXfaLayer();
  10206. }
  10207. }
  10208. get width() {
  10209. return this.viewport.width;
  10210. }
  10211. get height() {
  10212. return this.viewport.height;
  10213. }
  10214. getPagePoint(x, y) {
  10215. return this.viewport.convertToPdfPoint(x, y);
  10216. }
  10217. toggleLoadingIconSpinner(viewVisible = false) {
  10218. this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
  10219. }
  10220. draw() {
  10221. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  10222. console.error("Must be in new state before drawing");
  10223. this.reset();
  10224. }
  10225. const {
  10226. div,
  10227. pdfPage
  10228. } = this;
  10229. if (!pdfPage) {
  10230. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10231. if (this.loadingIconDiv) {
  10232. this.loadingIconDiv.remove();
  10233. delete this.loadingIconDiv;
  10234. }
  10235. return Promise.reject(new Error("pdfPage is not loaded"));
  10236. }
  10237. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10238. const canvasWrapper = document.createElement("div");
  10239. canvasWrapper.style.width = div.style.width;
  10240. canvasWrapper.style.height = div.style.height;
  10241. canvasWrapper.classList.add("canvasWrapper");
  10242. const lastDivBeforeTextDiv = this.annotationLayer?.div || this.annotationEditorLayer?.div;
  10243. if (lastDivBeforeTextDiv) {
  10244. lastDivBeforeTextDiv.before(canvasWrapper);
  10245. } else {
  10246. div.append(canvasWrapper);
  10247. }
  10248. let textLayer = null;
  10249. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  10250. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  10251. const textLayerDiv = document.createElement("div");
  10252. textLayerDiv.className = "textLayer";
  10253. textLayerDiv.style.width = canvasWrapper.style.width;
  10254. textLayerDiv.style.height = canvasWrapper.style.height;
  10255. if (lastDivBeforeTextDiv) {
  10256. lastDivBeforeTextDiv.before(textLayerDiv);
  10257. } else {
  10258. div.append(textLayerDiv);
  10259. }
  10260. textLayer = this.textLayerFactory.createTextLayerBuilder({
  10261. textLayerDiv,
  10262. pageIndex: this.id - 1,
  10263. viewport: this.viewport,
  10264. enhanceTextSelection: this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE,
  10265. eventBus: this.eventBus,
  10266. highlighter: this.textHighlighter,
  10267. accessibilityManager: this._accessibilityManager
  10268. });
  10269. }
  10270. this.textLayer = textLayer;
  10271. if (this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE && this.annotationLayerFactory) {
  10272. this._annotationCanvasMap ||= new Map();
  10273. this.annotationLayer ||= this.annotationLayerFactory.createAnnotationLayerBuilder({
  10274. pageDiv: div,
  10275. pdfPage,
  10276. imageResourcesPath: this.imageResourcesPath,
  10277. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  10278. l10n: this.l10n,
  10279. annotationCanvasMap: this._annotationCanvasMap,
  10280. accessibilityManager: this._accessibilityManager
  10281. });
  10282. }
  10283. if (this.xfaLayer?.div) {
  10284. div.append(this.xfaLayer.div);
  10285. }
  10286. let renderContinueCallback = null;
  10287. if (this.renderingQueue) {
  10288. renderContinueCallback = cont => {
  10289. if (!this.renderingQueue.isHighestPriority(this)) {
  10290. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  10291. this.resume = () => {
  10292. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10293. cont();
  10294. };
  10295. return;
  10296. }
  10297. cont();
  10298. };
  10299. }
  10300. const finishPaintTask = async (error = null) => {
  10301. if (paintTask === this.paintTask) {
  10302. this.paintTask = null;
  10303. }
  10304. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  10305. this._renderError = null;
  10306. return;
  10307. }
  10308. this._renderError = error;
  10309. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10310. if (this.loadingIconDiv) {
  10311. this.loadingIconDiv.remove();
  10312. delete this.loadingIconDiv;
  10313. }
  10314. this._resetZoomLayer(true);
  10315. this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
  10316. this.eventBus.dispatch("pagerendered", {
  10317. source: this,
  10318. pageNumber: this.id,
  10319. cssTransform: false,
  10320. timestamp: performance.now(),
  10321. error: this._renderError
  10322. });
  10323. if (error) {
  10324. throw error;
  10325. }
  10326. };
  10327. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  10328. paintTask.onRenderContinue = renderContinueCallback;
  10329. this.paintTask = paintTask;
  10330. const resultPromise = paintTask.promise.then(() => {
  10331. return finishPaintTask(null).then(() => {
  10332. if (textLayer) {
  10333. const readableStream = pdfPage.streamTextContent({
  10334. includeMarkedContent: true
  10335. });
  10336. textLayer.setTextContentStream(readableStream);
  10337. textLayer.render();
  10338. }
  10339. if (this.annotationLayer) {
  10340. this._renderAnnotationLayer().then(() => {
  10341. if (this.annotationEditorLayerFactory) {
  10342. this.annotationEditorLayer ||= this.annotationEditorLayerFactory.createAnnotationEditorLayerBuilder({
  10343. pageDiv: div,
  10344. pdfPage,
  10345. l10n: this.l10n,
  10346. accessibilityManager: this._accessibilityManager
  10347. });
  10348. this._renderAnnotationEditorLayer();
  10349. }
  10350. });
  10351. }
  10352. });
  10353. }, function (reason) {
  10354. return finishPaintTask(reason);
  10355. });
  10356. if (this.xfaLayerFactory) {
  10357. this.xfaLayer ||= this.xfaLayerFactory.createXfaLayerBuilder({
  10358. pageDiv: div,
  10359. pdfPage
  10360. });
  10361. this._renderXfaLayer();
  10362. }
  10363. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  10364. this._onTextLayerRendered = event => {
  10365. if (event.pageNumber !== this.id) {
  10366. return;
  10367. }
  10368. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  10369. this._onTextLayerRendered = null;
  10370. if (!this.canvas) {
  10371. return;
  10372. }
  10373. this.pdfPage.getStructTree().then(tree => {
  10374. if (!tree) {
  10375. return;
  10376. }
  10377. if (!this.canvas) {
  10378. return;
  10379. }
  10380. const treeDom = this.structTreeLayer.render(tree);
  10381. treeDom.classList.add("structTree");
  10382. this.canvas.append(treeDom);
  10383. });
  10384. };
  10385. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  10386. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder({
  10387. pdfPage
  10388. });
  10389. }
  10390. div.setAttribute("data-loaded", true);
  10391. this.eventBus.dispatch("pagerender", {
  10392. source: this,
  10393. pageNumber: this.id
  10394. });
  10395. return resultPromise;
  10396. }
  10397. paintOnCanvas(canvasWrapper) {
  10398. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  10399. const result = {
  10400. promise: renderCapability.promise,
  10401. onRenderContinue(cont) {
  10402. cont();
  10403. },
  10404. cancel() {
  10405. renderTask.cancel();
  10406. },
  10407. get separateAnnots() {
  10408. return renderTask.separateAnnots;
  10409. }
  10410. };
  10411. const viewport = this.viewport;
  10412. const canvas = document.createElement("canvas");
  10413. canvas.setAttribute("role", "presentation");
  10414. canvas.hidden = true;
  10415. let isCanvasHidden = true;
  10416. const showCanvas = function () {
  10417. if (isCanvasHidden) {
  10418. canvas.hidden = false;
  10419. isCanvasHidden = false;
  10420. }
  10421. };
  10422. canvasWrapper.append(canvas);
  10423. this.canvas = canvas;
  10424. const ctx = canvas.getContext("2d", {
  10425. alpha: false
  10426. });
  10427. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  10428. if (this.useOnlyCssZoom) {
  10429. const actualSizeViewport = viewport.clone({
  10430. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10431. });
  10432. outputScale.sx *= actualSizeViewport.width / viewport.width;
  10433. outputScale.sy *= actualSizeViewport.height / viewport.height;
  10434. }
  10435. if (this.maxCanvasPixels > 0) {
  10436. const pixelsInViewport = viewport.width * viewport.height;
  10437. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  10438. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  10439. outputScale.sx = maxScale;
  10440. outputScale.sy = maxScale;
  10441. this.hasRestrictedScaling = true;
  10442. } else {
  10443. this.hasRestrictedScaling = false;
  10444. }
  10445. }
  10446. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  10447. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  10448. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  10449. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  10450. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  10451. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  10452. this.paintedViewportMap.set(canvas, viewport);
  10453. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10454. const renderContext = {
  10455. canvasContext: ctx,
  10456. transform,
  10457. viewport: this.viewport,
  10458. annotationMode: this.#annotationMode,
  10459. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10460. annotationCanvasMap: this._annotationCanvasMap,
  10461. pageColors: this.pageColors
  10462. };
  10463. const renderTask = this.pdfPage.render(renderContext);
  10464. renderTask.onContinue = function (cont) {
  10465. showCanvas();
  10466. if (result.onRenderContinue) {
  10467. result.onRenderContinue(cont);
  10468. } else {
  10469. cont();
  10470. }
  10471. };
  10472. renderTask.promise.then(function () {
  10473. showCanvas();
  10474. renderCapability.resolve();
  10475. }, function (error) {
  10476. showCanvas();
  10477. renderCapability.reject(error);
  10478. });
  10479. return result;
  10480. }
  10481. paintOnSvg(wrapper) {
  10482. let cancelled = false;
  10483. const ensureNotCancelled = () => {
  10484. if (cancelled) {
  10485. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  10486. }
  10487. };
  10488. const pdfPage = this.pdfPage;
  10489. const actualSizeViewport = this.viewport.clone({
  10490. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10491. });
  10492. const promise = pdfPage.getOperatorList({
  10493. annotationMode: this.#annotationMode
  10494. }).then(opList => {
  10495. ensureNotCancelled();
  10496. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  10497. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  10498. ensureNotCancelled();
  10499. this.svg = svg;
  10500. this.paintedViewportMap.set(svg, actualSizeViewport);
  10501. svg.style.width = wrapper.style.width;
  10502. svg.style.height = wrapper.style.height;
  10503. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10504. wrapper.append(svg);
  10505. });
  10506. });
  10507. return {
  10508. promise,
  10509. onRenderContinue(cont) {
  10510. cont();
  10511. },
  10512. cancel() {
  10513. cancelled = true;
  10514. },
  10515. get separateAnnots() {
  10516. return false;
  10517. }
  10518. };
  10519. }
  10520. setPageLabel(label) {
  10521. this.pageLabel = typeof label === "string" ? label : null;
  10522. if (this.pageLabel !== null) {
  10523. this.div.setAttribute("data-page-label", this.pageLabel);
  10524. } else {
  10525. this.div.removeAttribute("data-page-label");
  10526. }
  10527. }
  10528. get thumbnailCanvas() {
  10529. const {
  10530. initialOptionalContent,
  10531. regularAnnotations
  10532. } = this.#useThumbnailCanvas;
  10533. return initialOptionalContent && regularAnnotations ? this.canvas : null;
  10534. }
  10535. }
  10536. exports.PDFPageView = PDFPageView;
  10537. /***/
  10538. }),
  10539. /* 34 */
  10540. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10541. Object.defineProperty(exports, "__esModule", ({
  10542. value: true
  10543. }));
  10544. exports.TextAccessibilityManager = void 0;
  10545. var _ui_utils = __webpack_require__(1);
  10546. class TextAccessibilityManager {
  10547. #enabled = false;
  10548. #textChildren = null;
  10549. #textNodes = new Map();
  10550. #waitingElements = new Map();
  10551. setTextMapping(textDivs) {
  10552. this.#textChildren = textDivs;
  10553. }
  10554. static #compareElementPositions(e1, e2) {
  10555. const rect1 = e1.getBoundingClientRect();
  10556. const rect2 = e2.getBoundingClientRect();
  10557. if (rect1.width === 0 && rect1.height === 0) {
  10558. return +1;
  10559. }
  10560. if (rect2.width === 0 && rect2.height === 0) {
  10561. return -1;
  10562. }
  10563. const top1 = rect1.y;
  10564. const bot1 = rect1.y + rect1.height;
  10565. const mid1 = rect1.y + rect1.height / 2;
  10566. const top2 = rect2.y;
  10567. const bot2 = rect2.y + rect2.height;
  10568. const mid2 = rect2.y + rect2.height / 2;
  10569. if (mid1 <= top2 && mid2 >= bot1) {
  10570. return -1;
  10571. }
  10572. if (mid2 <= top1 && mid1 >= bot2) {
  10573. return +1;
  10574. }
  10575. const centerX1 = rect1.x + rect1.width / 2;
  10576. const centerX2 = rect2.x + rect2.width / 2;
  10577. return centerX1 - centerX2;
  10578. }
  10579. enable() {
  10580. if (this.#enabled) {
  10581. throw new Error("TextAccessibilityManager is already enabled.");
  10582. }
  10583. if (!this.#textChildren) {
  10584. throw new Error("Text divs and strings have not been set.");
  10585. }
  10586. this.#enabled = true;
  10587. this.#textChildren = this.#textChildren.slice();
  10588. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  10589. if (this.#textNodes.size > 0) {
  10590. const textChildren = this.#textChildren;
  10591. for (const [id, nodeIndex] of this.#textNodes) {
  10592. const element = document.getElementById(id);
  10593. if (!element) {
  10594. this.#textNodes.delete(id);
  10595. continue;
  10596. }
  10597. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  10598. }
  10599. }
  10600. for (const [element, isRemovable] of this.#waitingElements) {
  10601. this.addPointerInTextLayer(element, isRemovable);
  10602. }
  10603. this.#waitingElements.clear();
  10604. }
  10605. disable() {
  10606. if (!this.#enabled) {
  10607. return;
  10608. }
  10609. this.#waitingElements.clear();
  10610. this.#textChildren = null;
  10611. this.#enabled = false;
  10612. }
  10613. removePointerInTextLayer(element) {
  10614. if (!this.#enabled) {
  10615. this.#waitingElements.delete(element);
  10616. return;
  10617. }
  10618. const children = this.#textChildren;
  10619. if (!children || children.length === 0) {
  10620. return;
  10621. }
  10622. const {
  10623. id
  10624. } = element;
  10625. const nodeIndex = this.#textNodes.get(id);
  10626. if (nodeIndex === undefined) {
  10627. return;
  10628. }
  10629. const node = children[nodeIndex];
  10630. this.#textNodes.delete(id);
  10631. let owns = node.getAttribute("aria-owns");
  10632. if (owns?.includes(id)) {
  10633. owns = owns.split(" ").filter(x => x !== id).join(" ");
  10634. if (owns) {
  10635. node.setAttribute("aria-owns", owns);
  10636. } else {
  10637. node.removeAttribute("aria-owns");
  10638. node.setAttribute("role", "presentation");
  10639. }
  10640. }
  10641. }
  10642. #addIdToAriaOwns(id, node) {
  10643. const owns = node.getAttribute("aria-owns");
  10644. if (!owns?.includes(id)) {
  10645. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  10646. }
  10647. node.removeAttribute("role");
  10648. }
  10649. addPointerInTextLayer(element, isRemovable) {
  10650. const {
  10651. id
  10652. } = element;
  10653. if (!id) {
  10654. return;
  10655. }
  10656. if (!this.#enabled) {
  10657. this.#waitingElements.set(element, isRemovable);
  10658. return;
  10659. }
  10660. if (isRemovable) {
  10661. this.removePointerInTextLayer(element);
  10662. }
  10663. const children = this.#textChildren;
  10664. if (!children || children.length === 0) {
  10665. return;
  10666. }
  10667. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  10668. const nodeIndex = Math.max(0, index - 1);
  10669. this.#addIdToAriaOwns(id, children[nodeIndex]);
  10670. this.#textNodes.set(id, nodeIndex);
  10671. }
  10672. moveElementInDOM(container, element, contentElement, isRemovable) {
  10673. this.addPointerInTextLayer(contentElement, isRemovable);
  10674. if (!container.hasChildNodes()) {
  10675. container.append(element);
  10676. return;
  10677. }
  10678. const children = Array.from(container.childNodes).filter(node => node !== element);
  10679. if (children.length === 0) {
  10680. return;
  10681. }
  10682. const elementToCompare = contentElement || element;
  10683. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  10684. if (index === 0) {
  10685. children[0].before(element);
  10686. } else {
  10687. children[index - 1].after(element);
  10688. }
  10689. }
  10690. }
  10691. exports.TextAccessibilityManager = TextAccessibilityManager;
  10692. /***/
  10693. }),
  10694. /* 35 */
  10695. /***/ ((__unused_webpack_module, exports) => {
  10696. Object.defineProperty(exports, "__esModule", ({
  10697. value: true
  10698. }));
  10699. exports.StructTreeLayerBuilder = void 0;
  10700. const PDF_ROLE_TO_HTML_ROLE = {
  10701. Document: null,
  10702. DocumentFragment: null,
  10703. Part: "group",
  10704. Sect: "group",
  10705. Div: "group",
  10706. Aside: "note",
  10707. NonStruct: "none",
  10708. P: null,
  10709. H: "heading",
  10710. Title: null,
  10711. FENote: "note",
  10712. Sub: "group",
  10713. Lbl: null,
  10714. Span: null,
  10715. Em: null,
  10716. Strong: null,
  10717. Link: "link",
  10718. Annot: "note",
  10719. Form: "form",
  10720. Ruby: null,
  10721. RB: null,
  10722. RT: null,
  10723. RP: null,
  10724. Warichu: null,
  10725. WT: null,
  10726. WP: null,
  10727. L: "list",
  10728. LI: "listitem",
  10729. LBody: null,
  10730. Table: "table",
  10731. TR: "row",
  10732. TH: "columnheader",
  10733. TD: "cell",
  10734. THead: "columnheader",
  10735. TBody: null,
  10736. TFoot: null,
  10737. Caption: null,
  10738. Figure: "figure",
  10739. Formula: null,
  10740. Artifact: null
  10741. };
  10742. const HEADING_PATTERN = /^H(\d+)$/;
  10743. class StructTreeLayerBuilder {
  10744. constructor({
  10745. pdfPage
  10746. }) {
  10747. this.pdfPage = pdfPage;
  10748. }
  10749. render(structTree) {
  10750. return this._walk(structTree);
  10751. }
  10752. _setAttributes(structElement, htmlElement) {
  10753. if (structElement.alt !== undefined) {
  10754. htmlElement.setAttribute("aria-label", structElement.alt);
  10755. }
  10756. if (structElement.id !== undefined) {
  10757. htmlElement.setAttribute("aria-owns", structElement.id);
  10758. }
  10759. if (structElement.lang !== undefined) {
  10760. htmlElement.setAttribute("lang", structElement.lang);
  10761. }
  10762. }
  10763. _walk(node) {
  10764. if (!node) {
  10765. return null;
  10766. }
  10767. const element = document.createElement("span");
  10768. if ("role" in node) {
  10769. const {
  10770. role
  10771. } = node;
  10772. const match = role.match(HEADING_PATTERN);
  10773. if (match) {
  10774. element.setAttribute("role", "heading");
  10775. element.setAttribute("aria-level", match[1]);
  10776. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10777. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10778. }
  10779. }
  10780. this._setAttributes(node, element);
  10781. if (node.children) {
  10782. if (node.children.length === 1 && "id" in node.children[0]) {
  10783. this._setAttributes(node.children[0], element);
  10784. } else {
  10785. for (const kid of node.children) {
  10786. element.append(this._walk(kid));
  10787. }
  10788. }
  10789. }
  10790. return element;
  10791. }
  10792. }
  10793. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10794. /***/
  10795. }),
  10796. /* 36 */
  10797. /***/ ((__unused_webpack_module, exports) => {
  10798. Object.defineProperty(exports, "__esModule", ({
  10799. value: true
  10800. }));
  10801. exports.TextHighlighter = void 0;
  10802. class TextHighlighter {
  10803. constructor({
  10804. findController,
  10805. eventBus,
  10806. pageIndex
  10807. }) {
  10808. this.findController = findController;
  10809. this.matches = [];
  10810. this.eventBus = eventBus;
  10811. this.pageIdx = pageIndex;
  10812. this._onUpdateTextLayerMatches = null;
  10813. this.textDivs = null;
  10814. this.textContentItemsStr = null;
  10815. this.enabled = false;
  10816. }
  10817. setTextMapping(divs, texts) {
  10818. this.textDivs = divs;
  10819. this.textContentItemsStr = texts;
  10820. }
  10821. enable() {
  10822. if (!this.textDivs || !this.textContentItemsStr) {
  10823. throw new Error("Text divs and strings have not been set.");
  10824. }
  10825. if (this.enabled) {
  10826. throw new Error("TextHighlighter is already enabled.");
  10827. }
  10828. this.enabled = true;
  10829. if (!this._onUpdateTextLayerMatches) {
  10830. this._onUpdateTextLayerMatches = evt => {
  10831. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  10832. this._updateMatches();
  10833. }
  10834. };
  10835. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10836. }
  10837. this._updateMatches();
  10838. }
  10839. disable() {
  10840. if (!this.enabled) {
  10841. return;
  10842. }
  10843. this.enabled = false;
  10844. if (this._onUpdateTextLayerMatches) {
  10845. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10846. this._onUpdateTextLayerMatches = null;
  10847. }
  10848. }
  10849. _convertMatches(matches, matchesLength) {
  10850. if (!matches) {
  10851. return [];
  10852. }
  10853. const {
  10854. textContentItemsStr
  10855. } = this;
  10856. let i = 0,
  10857. iIndex = 0;
  10858. const end = textContentItemsStr.length - 1;
  10859. const result = [];
  10860. for (let m = 0, mm = matches.length; m < mm; m++) {
  10861. let matchIdx = matches[m];
  10862. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  10863. iIndex += textContentItemsStr[i].length;
  10864. i++;
  10865. }
  10866. if (i === textContentItemsStr.length) {
  10867. console.error("Could not find a matching mapping");
  10868. }
  10869. const match = {
  10870. begin: {
  10871. divIdx: i,
  10872. offset: matchIdx - iIndex
  10873. }
  10874. };
  10875. matchIdx += matchesLength[m];
  10876. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  10877. iIndex += textContentItemsStr[i].length;
  10878. i++;
  10879. }
  10880. match.end = {
  10881. divIdx: i,
  10882. offset: matchIdx - iIndex
  10883. };
  10884. result.push(match);
  10885. }
  10886. return result;
  10887. }
  10888. _renderMatches(matches) {
  10889. if (matches.length === 0) {
  10890. return;
  10891. }
  10892. const {
  10893. findController,
  10894. pageIdx
  10895. } = this;
  10896. const {
  10897. textContentItemsStr,
  10898. textDivs
  10899. } = this;
  10900. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  10901. const selectedMatchIdx = findController.selected.matchIdx;
  10902. const highlightAll = findController.state.highlightAll;
  10903. let prevEnd = null;
  10904. const infinity = {
  10905. divIdx: -1,
  10906. offset: undefined
  10907. };
  10908. function beginText(begin, className) {
  10909. const divIdx = begin.divIdx;
  10910. textDivs[divIdx].textContent = "";
  10911. return appendTextToDiv(divIdx, 0, begin.offset, className);
  10912. }
  10913. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  10914. let div = textDivs[divIdx];
  10915. if (div.nodeType === Node.TEXT_NODE) {
  10916. const span = document.createElement("span");
  10917. div.before(span);
  10918. span.append(div);
  10919. textDivs[divIdx] = span;
  10920. div = span;
  10921. }
  10922. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  10923. const node = document.createTextNode(content);
  10924. if (className) {
  10925. const span = document.createElement("span");
  10926. span.className = `${className} appended`;
  10927. span.append(node);
  10928. div.append(span);
  10929. return className.includes("selected") ? span.offsetLeft : 0;
  10930. }
  10931. div.append(node);
  10932. return 0;
  10933. }
  10934. let i0 = selectedMatchIdx,
  10935. i1 = i0 + 1;
  10936. if (highlightAll) {
  10937. i0 = 0;
  10938. i1 = matches.length;
  10939. } else if (!isSelectedPage) {
  10940. return;
  10941. }
  10942. for (let i = i0; i < i1; i++) {
  10943. const match = matches[i];
  10944. const begin = match.begin;
  10945. const end = match.end;
  10946. const isSelected = isSelectedPage && i === selectedMatchIdx;
  10947. const highlightSuffix = isSelected ? " selected" : "";
  10948. let selectedLeft = 0;
  10949. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  10950. if (prevEnd !== null) {
  10951. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10952. }
  10953. beginText(begin);
  10954. } else {
  10955. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  10956. }
  10957. if (begin.divIdx === end.divIdx) {
  10958. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  10959. } else {
  10960. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  10961. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  10962. textDivs[n0].className = "highlight middle" + highlightSuffix;
  10963. }
  10964. beginText(end, "highlight end" + highlightSuffix);
  10965. }
  10966. prevEnd = end;
  10967. if (isSelected) {
  10968. findController.scrollMatchIntoView({
  10969. element: textDivs[begin.divIdx],
  10970. selectedLeft,
  10971. pageIndex: pageIdx,
  10972. matchIndex: selectedMatchIdx
  10973. });
  10974. }
  10975. }
  10976. if (prevEnd) {
  10977. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10978. }
  10979. }
  10980. _updateMatches() {
  10981. if (!this.enabled) {
  10982. return;
  10983. }
  10984. const {
  10985. findController,
  10986. matches,
  10987. pageIdx
  10988. } = this;
  10989. const {
  10990. textContentItemsStr,
  10991. textDivs
  10992. } = this;
  10993. let clearedUntilDivIdx = -1;
  10994. for (let i = 0, ii = matches.length; i < ii; i++) {
  10995. const match = matches[i];
  10996. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  10997. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  10998. const div = textDivs[n];
  10999. div.textContent = textContentItemsStr[n];
  11000. div.className = "";
  11001. }
  11002. clearedUntilDivIdx = match.end.divIdx + 1;
  11003. }
  11004. if (!findController?.highlightMatches) {
  11005. return;
  11006. }
  11007. const pageMatches = findController.pageMatches[pageIdx] || null;
  11008. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  11009. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  11010. this._renderMatches(this.matches);
  11011. }
  11012. }
  11013. exports.TextHighlighter = TextHighlighter;
  11014. /***/
  11015. }),
  11016. /* 37 */
  11017. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11018. Object.defineProperty(exports, "__esModule", ({
  11019. value: true
  11020. }));
  11021. exports.TextLayerBuilder = void 0;
  11022. var _pdfjsLib = __webpack_require__(5);
  11023. const EXPAND_DIVS_TIMEOUT = 300;
  11024. class TextLayerBuilder {
  11025. constructor({
  11026. textLayerDiv,
  11027. eventBus,
  11028. pageIndex,
  11029. viewport,
  11030. highlighter = null,
  11031. enhanceTextSelection = false,
  11032. accessibilityManager = null
  11033. }) {
  11034. this.textLayerDiv = textLayerDiv;
  11035. this.eventBus = eventBus;
  11036. this.textContent = null;
  11037. this.textContentItemsStr = [];
  11038. this.textContentStream = null;
  11039. this.renderingDone = false;
  11040. this.pageNumber = pageIndex + 1;
  11041. this.viewport = viewport;
  11042. this.textDivs = [];
  11043. this.textLayerRenderTask = null;
  11044. this.highlighter = highlighter;
  11045. this.enhanceTextSelection = enhanceTextSelection;
  11046. this.accessibilityManager = accessibilityManager;
  11047. this._bindMouse();
  11048. }
  11049. _finishRendering() {
  11050. this.renderingDone = true;
  11051. if (!this.enhanceTextSelection) {
  11052. const endOfContent = document.createElement("div");
  11053. endOfContent.className = "endOfContent";
  11054. this.textLayerDiv.append(endOfContent);
  11055. }
  11056. this.eventBus.dispatch("textlayerrendered", {
  11057. source: this,
  11058. pageNumber: this.pageNumber,
  11059. numTextDivs: this.textDivs.length
  11060. });
  11061. }
  11062. render(timeout = 0) {
  11063. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  11064. return;
  11065. }
  11066. this.cancel();
  11067. this.textDivs.length = 0;
  11068. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  11069. this.accessibilityManager?.setTextMapping(this.textDivs);
  11070. const textLayerFrag = document.createDocumentFragment();
  11071. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  11072. textContent: this.textContent,
  11073. textContentStream: this.textContentStream,
  11074. container: textLayerFrag,
  11075. viewport: this.viewport,
  11076. textDivs: this.textDivs,
  11077. textContentItemsStr: this.textContentItemsStr,
  11078. timeout,
  11079. enhanceTextSelection: this.enhanceTextSelection
  11080. });
  11081. this.textLayerRenderTask.promise.then(() => {
  11082. this.textLayerDiv.append(textLayerFrag);
  11083. this._finishRendering();
  11084. this.highlighter?.enable();
  11085. this.accessibilityManager?.enable();
  11086. }, function (reason) { });
  11087. }
  11088. cancel() {
  11089. if (this.textLayerRenderTask) {
  11090. this.textLayerRenderTask.cancel();
  11091. this.textLayerRenderTask = null;
  11092. }
  11093. this.highlighter?.disable();
  11094. this.accessibilityManager?.disable();
  11095. }
  11096. setTextContentStream(readableStream) {
  11097. this.cancel();
  11098. this.textContentStream = readableStream;
  11099. }
  11100. setTextContent(textContent) {
  11101. this.cancel();
  11102. this.textContent = textContent;
  11103. }
  11104. _bindMouse() {
  11105. const div = this.textLayerDiv;
  11106. let expandDivsTimer = null;
  11107. div.addEventListener("mousedown", evt => {
  11108. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  11109. this.textLayerRenderTask.expandTextDivs(true);
  11110. if (expandDivsTimer) {
  11111. clearTimeout(expandDivsTimer);
  11112. expandDivsTimer = null;
  11113. }
  11114. return;
  11115. }
  11116. const end = div.querySelector(".endOfContent");
  11117. if (!end) {
  11118. return;
  11119. }
  11120. let adjustTop = evt.target !== div;
  11121. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  11122. if (adjustTop) {
  11123. const divBounds = div.getBoundingClientRect();
  11124. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  11125. end.style.top = (r * 100).toFixed(2) + "%";
  11126. }
  11127. end.classList.add("active");
  11128. });
  11129. div.addEventListener("mouseup", () => {
  11130. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  11131. expandDivsTimer = setTimeout(() => {
  11132. if (this.textLayerRenderTask) {
  11133. this.textLayerRenderTask.expandTextDivs(false);
  11134. }
  11135. expandDivsTimer = null;
  11136. }, EXPAND_DIVS_TIMEOUT);
  11137. return;
  11138. }
  11139. const end = div.querySelector(".endOfContent");
  11140. if (!end) {
  11141. return;
  11142. }
  11143. end.style.top = "";
  11144. end.classList.remove("active");
  11145. });
  11146. }
  11147. }
  11148. exports.TextLayerBuilder = TextLayerBuilder;
  11149. /***/
  11150. }),
  11151. /* 38 */
  11152. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11153. Object.defineProperty(exports, "__esModule", ({
  11154. value: true
  11155. }));
  11156. exports.XfaLayerBuilder = void 0;
  11157. var _pdfjsLib = __webpack_require__(5);
  11158. class XfaLayerBuilder {
  11159. constructor({
  11160. pageDiv,
  11161. pdfPage,
  11162. annotationStorage = null,
  11163. linkService,
  11164. xfaHtml = null
  11165. }) {
  11166. this.pageDiv = pageDiv;
  11167. this.pdfPage = pdfPage;
  11168. this.annotationStorage = annotationStorage;
  11169. this.linkService = linkService;
  11170. this.xfaHtml = xfaHtml;
  11171. this.div = null;
  11172. this._cancelled = false;
  11173. }
  11174. render(viewport, intent = "display") {
  11175. if (intent === "print") {
  11176. const parameters = {
  11177. viewport: viewport.clone({
  11178. dontFlip: true
  11179. }),
  11180. div: this.div,
  11181. xfaHtml: this.xfaHtml,
  11182. annotationStorage: this.annotationStorage,
  11183. linkService: this.linkService,
  11184. intent
  11185. };
  11186. const div = document.createElement("div");
  11187. this.pageDiv.append(div);
  11188. parameters.div = div;
  11189. const result = _pdfjsLib.XfaLayer.render(parameters);
  11190. return Promise.resolve(result);
  11191. }
  11192. return this.pdfPage.getXfa().then(xfaHtml => {
  11193. if (this._cancelled || !xfaHtml) {
  11194. return {
  11195. textDivs: []
  11196. };
  11197. }
  11198. const parameters = {
  11199. viewport: viewport.clone({
  11200. dontFlip: true
  11201. }),
  11202. div: this.div,
  11203. xfaHtml,
  11204. annotationStorage: this.annotationStorage,
  11205. linkService: this.linkService,
  11206. intent
  11207. };
  11208. if (this.div) {
  11209. return _pdfjsLib.XfaLayer.update(parameters);
  11210. }
  11211. this.div = document.createElement("div");
  11212. this.pageDiv.append(this.div);
  11213. parameters.div = this.div;
  11214. return _pdfjsLib.XfaLayer.render(parameters);
  11215. }).catch(error => {
  11216. console.error(error);
  11217. });
  11218. }
  11219. cancel() {
  11220. this._cancelled = true;
  11221. }
  11222. hide() {
  11223. if (!this.div) {
  11224. return;
  11225. }
  11226. this.div.hidden = true;
  11227. }
  11228. }
  11229. exports.XfaLayerBuilder = XfaLayerBuilder;
  11230. /***/
  11231. }),
  11232. /* 39 */
  11233. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11234. Object.defineProperty(exports, "__esModule", ({
  11235. value: true
  11236. }));
  11237. exports.SecondaryToolbar = void 0;
  11238. var _ui_utils = __webpack_require__(1);
  11239. var _pdf_cursor_tools = __webpack_require__(7);
  11240. var _base_viewer = __webpack_require__(29);
  11241. class SecondaryToolbar {
  11242. constructor(options, eventBus) {
  11243. this.toolbar = options.toolbar;
  11244. this.toggleButton = options.toggleButton;
  11245. this.buttons = [{
  11246. element: options.presentationModeButton,
  11247. eventName: "presentationmode",
  11248. close: true
  11249. }, {
  11250. element: options.printButton,
  11251. eventName: "print",
  11252. close: true
  11253. }, {
  11254. element: options.downloadButton,
  11255. eventName: "download",
  11256. close: true
  11257. }, {
  11258. element: options.viewBookmarkButton,
  11259. eventName: null,
  11260. close: true
  11261. }, {
  11262. element: options.firstPageButton,
  11263. eventName: "firstpage",
  11264. close: true
  11265. }, {
  11266. element: options.lastPageButton,
  11267. eventName: "lastpage",
  11268. close: true
  11269. }, {
  11270. element: options.pageRotateCwButton,
  11271. eventName: "rotatecw",
  11272. close: false
  11273. }, {
  11274. element: options.pageRotateCcwButton,
  11275. eventName: "rotateccw",
  11276. close: false
  11277. }, {
  11278. element: options.cursorSelectToolButton,
  11279. eventName: "switchcursortool",
  11280. eventDetails: {
  11281. tool: _pdf_cursor_tools.CursorTool.SELECT
  11282. },
  11283. close: true
  11284. }, {
  11285. element: options.cursorHandToolButton,
  11286. eventName: "switchcursortool",
  11287. eventDetails: {
  11288. tool: _pdf_cursor_tools.CursorTool.HAND
  11289. },
  11290. close: true
  11291. }, {
  11292. element: options.scrollPageButton,
  11293. eventName: "switchscrollmode",
  11294. eventDetails: {
  11295. mode: _ui_utils.ScrollMode.PAGE
  11296. },
  11297. close: true
  11298. }, {
  11299. element: options.scrollVerticalButton,
  11300. eventName: "switchscrollmode",
  11301. eventDetails: {
  11302. mode: _ui_utils.ScrollMode.VERTICAL
  11303. },
  11304. close: true
  11305. }, {
  11306. element: options.scrollHorizontalButton,
  11307. eventName: "switchscrollmode",
  11308. eventDetails: {
  11309. mode: _ui_utils.ScrollMode.HORIZONTAL
  11310. },
  11311. close: true
  11312. }, {
  11313. element: options.scrollWrappedButton,
  11314. eventName: "switchscrollmode",
  11315. eventDetails: {
  11316. mode: _ui_utils.ScrollMode.WRAPPED
  11317. },
  11318. close: true
  11319. }, {
  11320. element: options.spreadNoneButton,
  11321. eventName: "switchspreadmode",
  11322. eventDetails: {
  11323. mode: _ui_utils.SpreadMode.NONE
  11324. },
  11325. close: true
  11326. }, {
  11327. element: options.spreadOddButton,
  11328. eventName: "switchspreadmode",
  11329. eventDetails: {
  11330. mode: _ui_utils.SpreadMode.ODD
  11331. },
  11332. close: true
  11333. }, {
  11334. element: options.spreadEvenButton,
  11335. eventName: "switchspreadmode",
  11336. eventDetails: {
  11337. mode: _ui_utils.SpreadMode.EVEN
  11338. },
  11339. close: true
  11340. }, {
  11341. element: options.documentPropertiesButton,
  11342. eventName: "documentproperties",
  11343. close: true
  11344. }];
  11345. this.buttons.push({
  11346. element: options.openFileButton,
  11347. eventName: "openfile",
  11348. close: true
  11349. });
  11350. this.items = {
  11351. firstPage: options.firstPageButton,
  11352. lastPage: options.lastPageButton,
  11353. pageRotateCw: options.pageRotateCwButton,
  11354. pageRotateCcw: options.pageRotateCcwButton
  11355. };
  11356. this.eventBus = eventBus;
  11357. this.opened = false;
  11358. this.#bindClickListeners();
  11359. this.#bindCursorToolsListener(options);
  11360. this.#bindScrollModeListener(options);
  11361. this.#bindSpreadModeListener(options);
  11362. this.reset();
  11363. }
  11364. get isOpen() {
  11365. return this.opened;
  11366. }
  11367. setPageNumber(pageNumber) {
  11368. this.pageNumber = pageNumber;
  11369. this.#updateUIState();
  11370. }
  11371. setPagesCount(pagesCount) {
  11372. this.pagesCount = pagesCount;
  11373. this.#updateUIState();
  11374. }
  11375. reset() {
  11376. this.pageNumber = 0;
  11377. this.pagesCount = 0;
  11378. this.#updateUIState();
  11379. this.eventBus.dispatch("secondarytoolbarreset", {
  11380. source: this
  11381. });
  11382. }
  11383. #updateUIState() {
  11384. this.items.firstPage.disabled = this.pageNumber <= 1;
  11385. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  11386. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  11387. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  11388. }
  11389. #bindClickListeners() {
  11390. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  11391. for (const {
  11392. element,
  11393. eventName,
  11394. close,
  11395. eventDetails
  11396. } of this.buttons) {
  11397. element.addEventListener("click", evt => {
  11398. if (eventName !== null) {
  11399. const details = {
  11400. source: this
  11401. };
  11402. for (const property in eventDetails) {
  11403. details[property] = eventDetails[property];
  11404. }
  11405. this.eventBus.dispatch(eventName, details);
  11406. }
  11407. if (close) {
  11408. this.close();
  11409. }
  11410. });
  11411. }
  11412. }
  11413. #bindCursorToolsListener({
  11414. cursorSelectToolButton,
  11415. cursorHandToolButton
  11416. }) {
  11417. this.eventBus._on("cursortoolchanged", function ({
  11418. tool
  11419. }) {
  11420. const isSelect = tool === _pdf_cursor_tools.CursorTool.SELECT,
  11421. isHand = tool === _pdf_cursor_tools.CursorTool.HAND;
  11422. cursorSelectToolButton.classList.toggle("toggled", isSelect);
  11423. cursorHandToolButton.classList.toggle("toggled", isHand);
  11424. cursorSelectToolButton.setAttribute("aria-checked", isSelect);
  11425. cursorHandToolButton.setAttribute("aria-checked", isHand);
  11426. });
  11427. }
  11428. #bindScrollModeListener({
  11429. scrollPageButton,
  11430. scrollVerticalButton,
  11431. scrollHorizontalButton,
  11432. scrollWrappedButton,
  11433. spreadNoneButton,
  11434. spreadOddButton,
  11435. spreadEvenButton
  11436. }) {
  11437. const scrollModeChanged = ({
  11438. mode
  11439. }) => {
  11440. const isPage = mode === _ui_utils.ScrollMode.PAGE,
  11441. isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
  11442. isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
  11443. isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
  11444. scrollPageButton.classList.toggle("toggled", isPage);
  11445. scrollVerticalButton.classList.toggle("toggled", isVertical);
  11446. scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
  11447. scrollWrappedButton.classList.toggle("toggled", isWrapped);
  11448. scrollPageButton.setAttribute("aria-checked", isPage);
  11449. scrollVerticalButton.setAttribute("aria-checked", isVertical);
  11450. scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
  11451. scrollWrappedButton.setAttribute("aria-checked", isWrapped);
  11452. const forceScrollModePage = this.pagesCount > _base_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11453. scrollPageButton.disabled = forceScrollModePage;
  11454. scrollVerticalButton.disabled = forceScrollModePage;
  11455. scrollHorizontalButton.disabled = forceScrollModePage;
  11456. scrollWrappedButton.disabled = forceScrollModePage;
  11457. spreadNoneButton.disabled = isHorizontal;
  11458. spreadOddButton.disabled = isHorizontal;
  11459. spreadEvenButton.disabled = isHorizontal;
  11460. };
  11461. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  11462. this.eventBus._on("secondarytoolbarreset", evt => {
  11463. if (evt.source === this) {
  11464. scrollModeChanged({
  11465. mode: _ui_utils.ScrollMode.VERTICAL
  11466. });
  11467. }
  11468. });
  11469. }
  11470. #bindSpreadModeListener({
  11471. spreadNoneButton,
  11472. spreadOddButton,
  11473. spreadEvenButton
  11474. }) {
  11475. function spreadModeChanged({
  11476. mode
  11477. }) {
  11478. const isNone = mode === _ui_utils.SpreadMode.NONE,
  11479. isOdd = mode === _ui_utils.SpreadMode.ODD,
  11480. isEven = mode === _ui_utils.SpreadMode.EVEN;
  11481. spreadNoneButton.classList.toggle("toggled", isNone);
  11482. spreadOddButton.classList.toggle("toggled", isOdd);
  11483. spreadEvenButton.classList.toggle("toggled", isEven);
  11484. spreadNoneButton.setAttribute("aria-checked", isNone);
  11485. spreadOddButton.setAttribute("aria-checked", isOdd);
  11486. spreadEvenButton.setAttribute("aria-checked", isEven);
  11487. }
  11488. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  11489. this.eventBus._on("secondarytoolbarreset", evt => {
  11490. if (evt.source === this) {
  11491. spreadModeChanged({
  11492. mode: _ui_utils.SpreadMode.NONE
  11493. });
  11494. }
  11495. });
  11496. }
  11497. open() {
  11498. if (this.opened) {
  11499. return;
  11500. }
  11501. this.opened = true;
  11502. this.toggleButton.classList.add("toggled");
  11503. this.toggleButton.setAttribute("aria-expanded", "true");
  11504. this.toolbar.classList.remove("hidden");
  11505. }
  11506. close() {
  11507. if (!this.opened) {
  11508. return;
  11509. }
  11510. this.opened = false;
  11511. this.toolbar.classList.add("hidden");
  11512. this.toggleButton.classList.remove("toggled");
  11513. this.toggleButton.setAttribute("aria-expanded", "false");
  11514. }
  11515. toggle() {
  11516. if (this.opened) {
  11517. this.close();
  11518. } else {
  11519. this.open();
  11520. }
  11521. }
  11522. }
  11523. exports.SecondaryToolbar = SecondaryToolbar;
  11524. /***/
  11525. }),
  11526. /* 40 */
  11527. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11528. Object.defineProperty(exports, "__esModule", ({
  11529. value: true
  11530. }));
  11531. exports.Toolbar = void 0;
  11532. var _ui_utils = __webpack_require__(1);
  11533. var _pdfjsLib = __webpack_require__(5);
  11534. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  11535. class Toolbar {
  11536. #wasLocalized = false;
  11537. constructor(options, eventBus, l10n) {
  11538. this.toolbar = options.container;
  11539. this.eventBus = eventBus;
  11540. this.l10n = l10n;
  11541. this.buttons = [{
  11542. element: options.previous,
  11543. eventName: "previouspage"
  11544. }, {
  11545. element: options.next,
  11546. eventName: "nextpage"
  11547. }, {
  11548. element: options.zoomIn,
  11549. eventName: "zoomin"
  11550. }, {
  11551. element: options.zoomOut,
  11552. eventName: "zoomout"
  11553. }, {
  11554. element: options.print,
  11555. eventName: "print"
  11556. }, {
  11557. element: options.presentationModeButton,
  11558. eventName: "presentationmode"
  11559. }, {
  11560. element: options.download,
  11561. eventName: "download"
  11562. }, {
  11563. element: options.viewBookmark,
  11564. eventName: null
  11565. }, {
  11566. element: options.editorFreeTextButton,
  11567. eventName: "switchannotationeditormode",
  11568. eventDetails: {
  11569. get mode() {
  11570. const {
  11571. classList
  11572. } = options.editorFreeTextButton;
  11573. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  11574. }
  11575. }
  11576. }, {
  11577. element: options.editorInkButton,
  11578. eventName: "switchannotationeditormode",
  11579. eventDetails: {
  11580. get mode() {
  11581. const {
  11582. classList
  11583. } = options.editorInkButton;
  11584. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  11585. }
  11586. }
  11587. }];
  11588. this.buttons.push({
  11589. element: options.openFile,
  11590. eventName: "openfile"
  11591. });
  11592. this.items = {
  11593. numPages: options.numPages,
  11594. pageNumber: options.pageNumber,
  11595. scaleSelect: options.scaleSelect,
  11596. customScaleOption: options.customScaleOption,
  11597. previous: options.previous,
  11598. next: options.next,
  11599. zoomIn: options.zoomIn,
  11600. zoomOut: options.zoomOut
  11601. };
  11602. this.#bindListeners(options);
  11603. this.reset();
  11604. }
  11605. setPageNumber(pageNumber, pageLabel) {
  11606. this.pageNumber = pageNumber;
  11607. this.pageLabel = pageLabel;
  11608. this.#updateUIState(false);
  11609. }
  11610. setPagesCount(pagesCount, hasPageLabels) {
  11611. this.pagesCount = pagesCount;
  11612. this.hasPageLabels = hasPageLabels;
  11613. this.#updateUIState(true);
  11614. }
  11615. setPageScale(pageScaleValue, pageScale) {
  11616. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11617. this.pageScale = pageScale;
  11618. this.#updateUIState(false);
  11619. }
  11620. reset() {
  11621. this.pageNumber = 0;
  11622. this.pageLabel = null;
  11623. this.hasPageLabels = false;
  11624. this.pagesCount = 0;
  11625. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  11626. this.pageScale = _ui_utils.DEFAULT_SCALE;
  11627. this.#updateUIState(true);
  11628. this.updateLoadingIndicatorState();
  11629. this.eventBus.dispatch("toolbarreset", {
  11630. source: this
  11631. });
  11632. }
  11633. #bindListeners(options) {
  11634. const {
  11635. pageNumber,
  11636. scaleSelect
  11637. } = this.items;
  11638. const self = this;
  11639. for (const {
  11640. element,
  11641. eventName,
  11642. eventDetails
  11643. } of this.buttons) {
  11644. element.addEventListener("click", evt => {
  11645. if (eventName !== null) {
  11646. const details = {
  11647. source: this
  11648. };
  11649. if (eventDetails) {
  11650. for (const property in eventDetails) {
  11651. details[property] = eventDetails[property];
  11652. }
  11653. }
  11654. this.eventBus.dispatch(eventName, details);
  11655. }
  11656. });
  11657. }
  11658. pageNumber.addEventListener("click", function () {
  11659. this.select();
  11660. });
  11661. pageNumber.addEventListener("change", function () {
  11662. self.eventBus.dispatch("pagenumberchanged", {
  11663. source: self,
  11664. value: this.value
  11665. });
  11666. });
  11667. scaleSelect.addEventListener("change", function () {
  11668. if (this.value === "custom") {
  11669. return;
  11670. }
  11671. self.eventBus.dispatch("scalechanged", {
  11672. source: self,
  11673. value: this.value
  11674. });
  11675. });
  11676. scaleSelect.addEventListener("click", function (evt) {
  11677. const target = evt.target;
  11678. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11679. this.blur();
  11680. }
  11681. });
  11682. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  11683. this.eventBus._on("localized", () => {
  11684. this.#wasLocalized = true;
  11685. this.#adjustScaleWidth();
  11686. this.#updateUIState(true);
  11687. });
  11688. this.#bindEditorToolsListener(options);
  11689. }
  11690. #bindEditorToolsListener({
  11691. editorFreeTextButton,
  11692. editorFreeTextParamsToolbar,
  11693. editorInkButton,
  11694. editorInkParamsToolbar
  11695. }) {
  11696. const editorModeChanged = (evt, disableButtons = false) => {
  11697. const editorButtons = [{
  11698. mode: _pdfjsLib.AnnotationEditorType.FREETEXT,
  11699. button: editorFreeTextButton,
  11700. toolbar: editorFreeTextParamsToolbar
  11701. }, {
  11702. mode: _pdfjsLib.AnnotationEditorType.INK,
  11703. button: editorInkButton,
  11704. toolbar: editorInkParamsToolbar
  11705. }];
  11706. for (const {
  11707. mode,
  11708. button,
  11709. toolbar
  11710. } of editorButtons) {
  11711. const checked = mode === evt.mode;
  11712. button.classList.toggle("toggled", checked);
  11713. button.setAttribute("aria-checked", checked);
  11714. button.disabled = disableButtons;
  11715. toolbar?.classList.toggle("hidden", !checked);
  11716. }
  11717. };
  11718. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  11719. this.eventBus._on("toolbarreset", evt => {
  11720. if (evt.source === this) {
  11721. editorModeChanged({
  11722. mode: _pdfjsLib.AnnotationEditorType.NONE
  11723. }, true);
  11724. }
  11725. });
  11726. }
  11727. #updateUIState(resetNumPages = false) {
  11728. if (!this.#wasLocalized) {
  11729. return;
  11730. }
  11731. const {
  11732. pageNumber,
  11733. pagesCount,
  11734. pageScaleValue,
  11735. pageScale,
  11736. items
  11737. } = this;
  11738. if (resetNumPages) {
  11739. if (this.hasPageLabels) {
  11740. items.pageNumber.type = "text";
  11741. } else {
  11742. items.pageNumber.type = "number";
  11743. this.l10n.get("of_pages", {
  11744. pagesCount
  11745. }).then(msg => {
  11746. items.numPages.textContent = msg;
  11747. });
  11748. }
  11749. items.pageNumber.max = pagesCount;
  11750. }
  11751. if (this.hasPageLabels) {
  11752. items.pageNumber.value = this.pageLabel;
  11753. this.l10n.get("page_of_pages", {
  11754. pageNumber,
  11755. pagesCount
  11756. }).then(msg => {
  11757. items.numPages.textContent = msg;
  11758. });
  11759. } else {
  11760. items.pageNumber.value = pageNumber;
  11761. }
  11762. items.previous.disabled = pageNumber <= 1;
  11763. items.next.disabled = pageNumber >= pagesCount;
  11764. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  11765. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  11766. this.l10n.get("page_scale_percent", {
  11767. scale: Math.round(pageScale * 10000) / 100
  11768. }).then(msg => {
  11769. let predefinedValueFound = false;
  11770. for (const option of items.scaleSelect.options) {
  11771. if (option.value !== pageScaleValue) {
  11772. option.selected = false;
  11773. continue;
  11774. }
  11775. option.selected = true;
  11776. predefinedValueFound = true;
  11777. }
  11778. if (!predefinedValueFound) {
  11779. items.customScaleOption.textContent = msg;
  11780. items.customScaleOption.selected = true;
  11781. }
  11782. });
  11783. }
  11784. updateLoadingIndicatorState(loading = false) {
  11785. const {
  11786. pageNumber
  11787. } = this.items;
  11788. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  11789. }
  11790. async #adjustScaleWidth() {
  11791. const {
  11792. items,
  11793. l10n
  11794. } = this;
  11795. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  11796. await _ui_utils.animationStarted;
  11797. const style = getComputedStyle(items.scaleSelect),
  11798. scaleSelectContainerWidth = parseInt(style.getPropertyValue("--scale-select-container-width"), 10),
  11799. scaleSelectOverflow = parseInt(style.getPropertyValue("--scale-select-overflow"), 10);
  11800. const canvas = document.createElement("canvas");
  11801. const ctx = canvas.getContext("2d", {
  11802. alpha: false
  11803. });
  11804. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  11805. let maxWidth = 0;
  11806. for (const predefinedValue of await predefinedValuesPromise) {
  11807. const {
  11808. width
  11809. } = ctx.measureText(predefinedValue);
  11810. if (width > maxWidth) {
  11811. maxWidth = width;
  11812. }
  11813. }
  11814. maxWidth += 2 * scaleSelectOverflow;
  11815. if (maxWidth > scaleSelectContainerWidth) {
  11816. _ui_utils.docStyle.setProperty("--scale-select-container-width", `${maxWidth}px`);
  11817. }
  11818. canvas.width = 0;
  11819. canvas.height = 0;
  11820. }
  11821. }
  11822. exports.Toolbar = Toolbar;
  11823. /***/
  11824. }),
  11825. /* 41 */
  11826. /***/ ((__unused_webpack_module, exports) => {
  11827. Object.defineProperty(exports, "__esModule", ({
  11828. value: true
  11829. }));
  11830. exports.ViewHistory = void 0;
  11831. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  11832. class ViewHistory {
  11833. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  11834. this.fingerprint = fingerprint;
  11835. this.cacheSize = cacheSize;
  11836. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  11837. const database = JSON.parse(databaseStr || "{}");
  11838. let index = -1;
  11839. if (!Array.isArray(database.files)) {
  11840. database.files = [];
  11841. } else {
  11842. while (database.files.length >= this.cacheSize) {
  11843. database.files.shift();
  11844. }
  11845. for (let i = 0, ii = database.files.length; i < ii; i++) {
  11846. const branch = database.files[i];
  11847. if (branch.fingerprint === this.fingerprint) {
  11848. index = i;
  11849. break;
  11850. }
  11851. }
  11852. }
  11853. if (index === -1) {
  11854. index = database.files.push({
  11855. fingerprint: this.fingerprint
  11856. }) - 1;
  11857. }
  11858. this.file = database.files[index];
  11859. this.database = database;
  11860. });
  11861. }
  11862. async _writeToStorage() {
  11863. const databaseStr = JSON.stringify(this.database);
  11864. // localStorage.setItem("pdfjs.history", databaseStr);
  11865. }
  11866. async _readFromStorage() {
  11867. // return localStorage.getItem("pdfjs.history");
  11868. }
  11869. async set(name, val) {
  11870. await this._initializedPromise;
  11871. this.file[name] = val;
  11872. return this._writeToStorage();
  11873. }
  11874. async setMultiple(properties) {
  11875. await this._initializedPromise;
  11876. for (const name in properties) {
  11877. this.file[name] = properties[name];
  11878. }
  11879. return this._writeToStorage();
  11880. }
  11881. async get(name, defaultValue) {
  11882. await this._initializedPromise;
  11883. const val = this.file[name];
  11884. return val !== undefined ? val : defaultValue;
  11885. }
  11886. async getMultiple(properties) {
  11887. await this._initializedPromise;
  11888. const values = Object.create(null);
  11889. for (const name in properties) {
  11890. const val = this.file[name];
  11891. values[name] = val !== undefined ? val : properties[name];
  11892. }
  11893. return values;
  11894. }
  11895. }
  11896. exports.ViewHistory = ViewHistory;
  11897. /***/
  11898. }),
  11899. /* 42 */
  11900. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11901. Object.defineProperty(exports, "__esModule", ({
  11902. value: true
  11903. }));
  11904. exports.GenericCom = void 0;
  11905. var _app = __webpack_require__(4);
  11906. var _preferences = __webpack_require__(43);
  11907. var _download_manager = __webpack_require__(44);
  11908. var _genericl10n = __webpack_require__(45);
  11909. var _generic_scripting = __webpack_require__(47);
  11910. ;
  11911. const GenericCom = {};
  11912. exports.GenericCom = GenericCom;
  11913. class GenericPreferences extends _preferences.BasePreferences {
  11914. async _writeToStorage(prefObj) {
  11915. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  11916. }
  11917. async _readFromStorage(prefObj) {
  11918. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  11919. }
  11920. }
  11921. class GenericExternalServices extends _app.DefaultExternalServices {
  11922. static createDownloadManager(options) {
  11923. return new _download_manager.DownloadManager();
  11924. }
  11925. static createPreferences() {
  11926. return new GenericPreferences();
  11927. }
  11928. static createL10n({
  11929. locale = "en-US"
  11930. }) {
  11931. return new _genericl10n.GenericL10n(locale);
  11932. }
  11933. static createScripting({
  11934. sandboxBundleSrc
  11935. }) {
  11936. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  11937. }
  11938. }
  11939. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  11940. /***/
  11941. }),
  11942. /* 43 */
  11943. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11944. Object.defineProperty(exports, "__esModule", ({
  11945. value: true
  11946. }));
  11947. exports.BasePreferences = void 0;
  11948. var _app_options = __webpack_require__(2);
  11949. class BasePreferences {
  11950. #defaults = Object.freeze({
  11951. "annotationEditorMode": -1,
  11952. "annotationMode": 2,
  11953. "cursorToolOnLoad": 0,
  11954. "defaultZoomValue": "",
  11955. "disablePageLabels": false,
  11956. "enablePermissions": false,
  11957. "enablePrintAutoRotate": true,
  11958. "enableScripting": true,
  11959. "externalLinkTarget": 0,
  11960. "historyUpdateUrl": false,
  11961. "ignoreDestinationZoom": false,
  11962. "forcePageColors": false,
  11963. "pageColorsBackground": "Canvas",
  11964. "pageColorsForeground": "CanvasText",
  11965. "pdfBugEnabled": false,
  11966. "sidebarViewOnLoad": -1,
  11967. "scrollModeOnLoad": -1,
  11968. "spreadModeOnLoad": -1,
  11969. "textLayerMode": 1,
  11970. "useOnlyCssZoom": false,
  11971. "viewerCssTheme": 0,
  11972. "viewOnLoad": 0,
  11973. "disableAutoFetch": false,
  11974. "disableFontFace": false,
  11975. "disableRange": false,
  11976. "disableStream": false,
  11977. "enableXfa": true,
  11978. "renderer": "canvas"
  11979. });
  11980. #prefs = Object.create(null);
  11981. #initializedPromise = null;
  11982. constructor() {
  11983. if (this.constructor === BasePreferences) {
  11984. throw new Error("Cannot initialize BasePreferences.");
  11985. }
  11986. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  11987. for (const name in this.#defaults) {
  11988. const prefValue = prefs?.[name];
  11989. if (typeof prefValue === typeof this.#defaults[name]) {
  11990. this.#prefs[name] = prefValue;
  11991. }
  11992. }
  11993. });
  11994. }
  11995. async _writeToStorage(prefObj) {
  11996. throw new Error("Not implemented: _writeToStorage");
  11997. }
  11998. async _readFromStorage(prefObj) {
  11999. throw new Error("Not implemented: _readFromStorage");
  12000. }
  12001. async reset() {
  12002. await this.#initializedPromise;
  12003. const prefs = this.#prefs;
  12004. this.#prefs = Object.create(null);
  12005. return this._writeToStorage(this.#defaults).catch(reason => {
  12006. this.#prefs = prefs;
  12007. throw reason;
  12008. });
  12009. }
  12010. async set(name, value) {
  12011. await this.#initializedPromise;
  12012. const defaultValue = this.#defaults[name],
  12013. prefs = this.#prefs;
  12014. if (defaultValue === undefined) {
  12015. throw new Error(`Set preference: "${name}" is undefined.`);
  12016. } else if (value === undefined) {
  12017. throw new Error("Set preference: no value is specified.");
  12018. }
  12019. const valueType = typeof value,
  12020. defaultType = typeof defaultValue;
  12021. if (valueType !== defaultType) {
  12022. if (valueType === "number" && defaultType === "string") {
  12023. value = value.toString();
  12024. } else {
  12025. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  12026. }
  12027. } else {
  12028. if (valueType === "number" && !Number.isInteger(value)) {
  12029. throw new Error(`Set preference: "${value}" must be an integer.`);
  12030. }
  12031. }
  12032. this.#prefs[name] = value;
  12033. return this._writeToStorage(this.#prefs).catch(reason => {
  12034. this.#prefs = prefs;
  12035. throw reason;
  12036. });
  12037. }
  12038. async get(name) {
  12039. await this.#initializedPromise;
  12040. const defaultValue = this.#defaults[name];
  12041. if (defaultValue === undefined) {
  12042. throw new Error(`Get preference: "${name}" is undefined.`);
  12043. }
  12044. return this.#prefs[name] ?? defaultValue;
  12045. }
  12046. async getAll() {
  12047. await this.#initializedPromise;
  12048. const obj = Object.create(null);
  12049. for (const name in this.#defaults) {
  12050. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  12051. }
  12052. return obj;
  12053. }
  12054. }
  12055. exports.BasePreferences = BasePreferences;
  12056. /***/
  12057. }),
  12058. /* 44 */
  12059. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12060. Object.defineProperty(exports, "__esModule", ({
  12061. value: true
  12062. }));
  12063. exports.DownloadManager = void 0;
  12064. var _pdfjsLib = __webpack_require__(5);
  12065. ;
  12066. function download(blobUrl, filename) {
  12067. const a = document.createElement("a");
  12068. if (!a.click) {
  12069. throw new Error('DownloadManager: "a.click()" is not supported.');
  12070. }
  12071. a.href = blobUrl;
  12072. a.target = "_parent";
  12073. if ("download" in a) {
  12074. a.download = filename;
  12075. }
  12076. (document.body || document.documentElement).append(a);
  12077. a.click();
  12078. a.remove();
  12079. }
  12080. class DownloadManager {
  12081. constructor() {
  12082. this._openBlobUrls = new WeakMap();
  12083. }
  12084. downloadUrl(url, filename) {
  12085. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  12086. console.error(`downloadUrl - not a valid URL: ${url}`);
  12087. return;
  12088. }
  12089. download(url + "#pdfjs.action=download", filename);
  12090. }
  12091. downloadData(data, filename, contentType) {
  12092. const blobUrl = URL.createObjectURL(new Blob([data], {
  12093. type: contentType
  12094. }));
  12095. download(blobUrl, filename);
  12096. }
  12097. openOrDownloadData(element, data, filename) {
  12098. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  12099. const contentType = isPdfData ? "application/pdf" : "";
  12100. if (isPdfData) {
  12101. let blobUrl = this._openBlobUrls.get(element);
  12102. if (!blobUrl) {
  12103. blobUrl = URL.createObjectURL(new Blob([data], {
  12104. type: contentType
  12105. }));
  12106. this._openBlobUrls.set(element, blobUrl);
  12107. }
  12108. let viewerUrl;
  12109. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  12110. try {
  12111. window.open(viewerUrl);
  12112. return true;
  12113. } catch (ex) {
  12114. console.error(`openOrDownloadData: ${ex}`);
  12115. URL.revokeObjectURL(blobUrl);
  12116. this._openBlobUrls.delete(element);
  12117. }
  12118. }
  12119. this.downloadData(data, filename, contentType);
  12120. return false;
  12121. }
  12122. download(blob, url, filename) {
  12123. const blobUrl = URL.createObjectURL(blob);
  12124. download(blobUrl, filename);
  12125. }
  12126. }
  12127. exports.DownloadManager = DownloadManager;
  12128. /***/
  12129. }),
  12130. /* 45 */
  12131. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12132. Object.defineProperty(exports, "__esModule", ({
  12133. value: true
  12134. }));
  12135. exports.GenericL10n = void 0;
  12136. __webpack_require__(46);
  12137. var _l10n_utils = __webpack_require__(31);
  12138. const webL10n = document.webL10n;
  12139. class GenericL10n {
  12140. constructor(lang) {
  12141. this._lang = lang;
  12142. this._ready = new Promise((resolve, reject) => {
  12143. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  12144. resolve(webL10n);
  12145. });
  12146. });
  12147. }
  12148. async getLanguage() {
  12149. const l10n = await this._ready;
  12150. return l10n.getLanguage();
  12151. }
  12152. async getDirection() {
  12153. const l10n = await this._ready;
  12154. return l10n.getDirection();
  12155. }
  12156. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  12157. const l10n = await this._ready;
  12158. return l10n.get(key, args, fallback);
  12159. }
  12160. async translate(element) {
  12161. const l10n = await this._ready;
  12162. return l10n.translate(element);
  12163. }
  12164. }
  12165. exports.GenericL10n = GenericL10n;
  12166. /***/
  12167. }),
  12168. /* 46 */
  12169. /***/ (() => {
  12170. document.webL10n = function (window, document, undefined) {
  12171. var gL10nData = {};
  12172. var gTextData = '';
  12173. var gTextProp = 'textContent';
  12174. var gLanguage = '';
  12175. var gMacros = {};
  12176. var gReadyState = 'loading';
  12177. var gAsyncResourceLoading = true;
  12178. function getL10nResourceLinks() {
  12179. return document.querySelectorAll('link[type="application/l10n"]');
  12180. }
  12181. function getL10nDictionary() {
  12182. var script = document.querySelector('script[type="application/l10n"]');
  12183. return script ? JSON.parse(script.innerHTML) : null;
  12184. }
  12185. function getTranslatableChildren(element) {
  12186. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  12187. }
  12188. function getL10nAttributes(element) {
  12189. if (!element) return {};
  12190. var l10nId = element.getAttribute('data-l10n-id');
  12191. var l10nArgs = element.getAttribute('data-l10n-args');
  12192. var args = {};
  12193. if (l10nArgs) {
  12194. try {
  12195. args = JSON.parse(l10nArgs);
  12196. } catch (e) {
  12197. console.warn('could not parse arguments for #' + l10nId);
  12198. }
  12199. }
  12200. return {
  12201. id: l10nId,
  12202. args: args
  12203. };
  12204. }
  12205. function xhrLoadText(url, onSuccess, onFailure) {
  12206. onSuccess = onSuccess || function _onSuccess(data) { };
  12207. onFailure = onFailure || function _onFailure() { };
  12208. var xhr = new XMLHttpRequest();
  12209. xhr.open('GET', url, gAsyncResourceLoading);
  12210. if (xhr.overrideMimeType) {
  12211. xhr.overrideMimeType('text/plain; charset=utf-8');
  12212. }
  12213. xhr.onreadystatechange = function () {
  12214. if (xhr.readyState == 4) {
  12215. if (xhr.status == 200 || xhr.status === 0) {
  12216. onSuccess(xhr.responseText);
  12217. } else {
  12218. onFailure();
  12219. }
  12220. }
  12221. };
  12222. xhr.onerror = onFailure;
  12223. xhr.ontimeout = onFailure;
  12224. try {
  12225. xhr.send(null);
  12226. } catch (e) {
  12227. onFailure();
  12228. }
  12229. }
  12230. function parseResource(href, lang, successCallback, failureCallback) {
  12231. var baseURL = href.replace(/[^\/]*$/, '') || './';
  12232. function evalString(text) {
  12233. if (text.lastIndexOf('\\') < 0) return text;
  12234. 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, "'");
  12235. }
  12236. function parseProperties(text, parsedPropertiesCallback) {
  12237. var dictionary = {};
  12238. var reBlank = /^\s*|\s*$/;
  12239. var reComment = /^\s*#|^\s*$/;
  12240. var reSection = /^\s*\[(.*)\]\s*$/;
  12241. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  12242. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  12243. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  12244. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  12245. var currentLang = '*';
  12246. var genericLang = lang.split('-', 1)[0];
  12247. var skipLang = false;
  12248. var match = '';
  12249. function nextEntry() {
  12250. while (true) {
  12251. if (!entries.length) {
  12252. parsedRawLinesCallback();
  12253. return;
  12254. }
  12255. var line = entries.shift();
  12256. if (reComment.test(line)) continue;
  12257. if (extendedSyntax) {
  12258. match = reSection.exec(line);
  12259. if (match) {
  12260. currentLang = match[1].toLowerCase();
  12261. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  12262. continue;
  12263. } else if (skipLang) {
  12264. continue;
  12265. }
  12266. match = reImport.exec(line);
  12267. if (match) {
  12268. loadImport(baseURL + match[1], nextEntry);
  12269. return;
  12270. }
  12271. }
  12272. var tmp = line.match(reSplit);
  12273. if (tmp && tmp.length == 3) {
  12274. dictionary[tmp[1]] = evalString(tmp[2]);
  12275. }
  12276. }
  12277. }
  12278. nextEntry();
  12279. }
  12280. function loadImport(url, callback) {
  12281. xhrLoadText(url, function (content) {
  12282. parseRawLines(content, false, callback);
  12283. }, function () {
  12284. console.warn(url + ' not found.');
  12285. callback();
  12286. });
  12287. }
  12288. parseRawLines(text, true, function () {
  12289. parsedPropertiesCallback(dictionary);
  12290. });
  12291. }
  12292. xhrLoadText(href, function (response) {
  12293. gTextData += response;
  12294. parseProperties(response, function (data) {
  12295. for (var key in data) {
  12296. var id,
  12297. prop,
  12298. index = key.lastIndexOf('.');
  12299. if (index > 0) {
  12300. id = key.substring(0, index);
  12301. prop = key.substring(index + 1);
  12302. } else {
  12303. id = key;
  12304. prop = gTextProp;
  12305. }
  12306. if (!gL10nData[id]) {
  12307. gL10nData[id] = {};
  12308. }
  12309. gL10nData[id][prop] = data[key];
  12310. }
  12311. if (successCallback) {
  12312. successCallback();
  12313. }
  12314. });
  12315. }, failureCallback);
  12316. }
  12317. function loadLocale(lang, callback) {
  12318. if (lang) {
  12319. lang = lang.toLowerCase();
  12320. }
  12321. callback = callback || function _callback() { };
  12322. clear();
  12323. gLanguage = lang;
  12324. var langLinks = getL10nResourceLinks();
  12325. var langCount = langLinks.length;
  12326. if (langCount === 0) {
  12327. var dict = getL10nDictionary();
  12328. if (dict && dict.locales && dict.default_locale) {
  12329. console.log('using the embedded JSON directory, early way out');
  12330. gL10nData = dict.locales[lang];
  12331. if (!gL10nData) {
  12332. var defaultLocale = dict.default_locale.toLowerCase();
  12333. for (var anyCaseLang in dict.locales) {
  12334. anyCaseLang = anyCaseLang.toLowerCase();
  12335. if (anyCaseLang === lang) {
  12336. gL10nData = dict.locales[lang];
  12337. break;
  12338. } else if (anyCaseLang === defaultLocale) {
  12339. gL10nData = dict.locales[defaultLocale];
  12340. }
  12341. }
  12342. }
  12343. callback();
  12344. } else {
  12345. console.log('no resource to load, early way out');
  12346. }
  12347. gReadyState = 'complete';
  12348. return;
  12349. }
  12350. var onResourceLoaded = null;
  12351. var gResourceCount = 0;
  12352. onResourceLoaded = function () {
  12353. gResourceCount++;
  12354. if (gResourceCount >= langCount) {
  12355. callback();
  12356. gReadyState = 'complete';
  12357. }
  12358. };
  12359. function L10nResourceLink(link) {
  12360. var href = link.href;
  12361. this.load = function (lang, callback) {
  12362. parseResource(href, lang, callback, function () {
  12363. console.warn(href + ' not found.');
  12364. console.warn('"' + lang + '" resource not found');
  12365. gLanguage = '';
  12366. callback();
  12367. });
  12368. };
  12369. }
  12370. for (var i = 0; i < langCount; i++) {
  12371. var resource = new L10nResourceLink(langLinks[i]);
  12372. resource.load(lang, onResourceLoaded);
  12373. }
  12374. }
  12375. function clear() {
  12376. gL10nData = {};
  12377. gTextData = '';
  12378. gLanguage = '';
  12379. }
  12380. function getPluralRules(lang) {
  12381. var locales2rules = {
  12382. 'af': 3,
  12383. 'ak': 4,
  12384. 'am': 4,
  12385. 'ar': 1,
  12386. 'asa': 3,
  12387. 'az': 0,
  12388. 'be': 11,
  12389. 'bem': 3,
  12390. 'bez': 3,
  12391. 'bg': 3,
  12392. 'bh': 4,
  12393. 'bm': 0,
  12394. 'bn': 3,
  12395. 'bo': 0,
  12396. 'br': 20,
  12397. 'brx': 3,
  12398. 'bs': 11,
  12399. 'ca': 3,
  12400. 'cgg': 3,
  12401. 'chr': 3,
  12402. 'cs': 12,
  12403. 'cy': 17,
  12404. 'da': 3,
  12405. 'de': 3,
  12406. 'dv': 3,
  12407. 'dz': 0,
  12408. 'ee': 3,
  12409. 'el': 3,
  12410. 'en': 3,
  12411. 'eo': 3,
  12412. 'es': 3,
  12413. 'et': 3,
  12414. 'eu': 3,
  12415. 'fa': 0,
  12416. 'ff': 5,
  12417. 'fi': 3,
  12418. 'fil': 4,
  12419. 'fo': 3,
  12420. 'fr': 5,
  12421. 'fur': 3,
  12422. 'fy': 3,
  12423. 'ga': 8,
  12424. 'gd': 24,
  12425. 'gl': 3,
  12426. 'gsw': 3,
  12427. 'gu': 3,
  12428. 'guw': 4,
  12429. 'gv': 23,
  12430. 'ha': 3,
  12431. 'haw': 3,
  12432. 'he': 2,
  12433. 'hi': 4,
  12434. 'hr': 11,
  12435. 'hu': 0,
  12436. 'id': 0,
  12437. 'ig': 0,
  12438. 'ii': 0,
  12439. 'is': 3,
  12440. 'it': 3,
  12441. 'iu': 7,
  12442. 'ja': 0,
  12443. 'jmc': 3,
  12444. 'jv': 0,
  12445. 'ka': 0,
  12446. 'kab': 5,
  12447. 'kaj': 3,
  12448. 'kcg': 3,
  12449. 'kde': 0,
  12450. 'kea': 0,
  12451. 'kk': 3,
  12452. 'kl': 3,
  12453. 'km': 0,
  12454. 'kn': 0,
  12455. 'ko': 0,
  12456. 'ksb': 3,
  12457. 'ksh': 21,
  12458. 'ku': 3,
  12459. 'kw': 7,
  12460. 'lag': 18,
  12461. 'lb': 3,
  12462. 'lg': 3,
  12463. 'ln': 4,
  12464. 'lo': 0,
  12465. 'lt': 10,
  12466. 'lv': 6,
  12467. 'mas': 3,
  12468. 'mg': 4,
  12469. 'mk': 16,
  12470. 'ml': 3,
  12471. 'mn': 3,
  12472. 'mo': 9,
  12473. 'mr': 3,
  12474. 'ms': 0,
  12475. 'mt': 15,
  12476. 'my': 0,
  12477. 'nah': 3,
  12478. 'naq': 7,
  12479. 'nb': 3,
  12480. 'nd': 3,
  12481. 'ne': 3,
  12482. 'nl': 3,
  12483. 'nn': 3,
  12484. 'no': 3,
  12485. 'nr': 3,
  12486. 'nso': 4,
  12487. 'ny': 3,
  12488. 'nyn': 3,
  12489. 'om': 3,
  12490. 'or': 3,
  12491. 'pa': 3,
  12492. 'pap': 3,
  12493. 'pl': 13,
  12494. 'ps': 3,
  12495. 'pt': 3,
  12496. 'rm': 3,
  12497. 'ro': 9,
  12498. 'rof': 3,
  12499. 'ru': 11,
  12500. 'rwk': 3,
  12501. 'sah': 0,
  12502. 'saq': 3,
  12503. 'se': 7,
  12504. 'seh': 3,
  12505. 'ses': 0,
  12506. 'sg': 0,
  12507. 'sh': 11,
  12508. 'shi': 19,
  12509. 'sk': 12,
  12510. 'sl': 14,
  12511. 'sma': 7,
  12512. 'smi': 7,
  12513. 'smj': 7,
  12514. 'smn': 7,
  12515. 'sms': 7,
  12516. 'sn': 3,
  12517. 'so': 3,
  12518. 'sq': 3,
  12519. 'sr': 11,
  12520. 'ss': 3,
  12521. 'ssy': 3,
  12522. 'st': 3,
  12523. 'sv': 3,
  12524. 'sw': 3,
  12525. 'syr': 3,
  12526. 'ta': 3,
  12527. 'te': 3,
  12528. 'teo': 3,
  12529. 'th': 0,
  12530. 'ti': 4,
  12531. 'tig': 3,
  12532. 'tk': 3,
  12533. 'tl': 4,
  12534. 'tn': 3,
  12535. 'to': 0,
  12536. 'tr': 0,
  12537. 'ts': 3,
  12538. 'tzm': 22,
  12539. 'uk': 11,
  12540. 'ur': 3,
  12541. 've': 3,
  12542. 'vi': 0,
  12543. 'vun': 3,
  12544. 'wa': 4,
  12545. 'wae': 3,
  12546. 'wo': 0,
  12547. 'xh': 3,
  12548. 'xog': 3,
  12549. 'yo': 0,
  12550. 'zh': 0,
  12551. 'zu': 3
  12552. };
  12553. function isIn(n, list) {
  12554. return list.indexOf(n) !== -1;
  12555. }
  12556. function isBetween(n, start, end) {
  12557. return start <= n && n <= end;
  12558. }
  12559. var pluralRules = {
  12560. '0': function (n) {
  12561. return 'other';
  12562. },
  12563. '1': function (n) {
  12564. if (isBetween(n % 100, 3, 10)) return 'few';
  12565. if (n === 0) return 'zero';
  12566. if (isBetween(n % 100, 11, 99)) return 'many';
  12567. if (n == 2) return 'two';
  12568. if (n == 1) return 'one';
  12569. return 'other';
  12570. },
  12571. '2': function (n) {
  12572. if (n !== 0 && n % 10 === 0) return 'many';
  12573. if (n == 2) return 'two';
  12574. if (n == 1) return 'one';
  12575. return 'other';
  12576. },
  12577. '3': function (n) {
  12578. if (n == 1) return 'one';
  12579. return 'other';
  12580. },
  12581. '4': function (n) {
  12582. if (isBetween(n, 0, 1)) return 'one';
  12583. return 'other';
  12584. },
  12585. '5': function (n) {
  12586. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12587. return 'other';
  12588. },
  12589. '6': function (n) {
  12590. if (n === 0) return 'zero';
  12591. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12592. return 'other';
  12593. },
  12594. '7': function (n) {
  12595. if (n == 2) return 'two';
  12596. if (n == 1) return 'one';
  12597. return 'other';
  12598. },
  12599. '8': function (n) {
  12600. if (isBetween(n, 3, 6)) return 'few';
  12601. if (isBetween(n, 7, 10)) return 'many';
  12602. if (n == 2) return 'two';
  12603. if (n == 1) return 'one';
  12604. return 'other';
  12605. },
  12606. '9': function (n) {
  12607. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12608. if (n == 1) return 'one';
  12609. return 'other';
  12610. },
  12611. '10': function (n) {
  12612. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12613. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12614. return 'other';
  12615. },
  12616. '11': function (n) {
  12617. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12618. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12619. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12620. return 'other';
  12621. },
  12622. '12': function (n) {
  12623. if (isBetween(n, 2, 4)) return 'few';
  12624. if (n == 1) return 'one';
  12625. return 'other';
  12626. },
  12627. '13': function (n) {
  12628. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12629. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12630. if (n == 1) return 'one';
  12631. return 'other';
  12632. },
  12633. '14': function (n) {
  12634. if (isBetween(n % 100, 3, 4)) return 'few';
  12635. if (n % 100 == 2) return 'two';
  12636. if (n % 100 == 1) return 'one';
  12637. return 'other';
  12638. },
  12639. '15': function (n) {
  12640. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12641. if (isBetween(n % 100, 11, 19)) return 'many';
  12642. if (n == 1) return 'one';
  12643. return 'other';
  12644. },
  12645. '16': function (n) {
  12646. if (n % 10 == 1 && n != 11) return 'one';
  12647. return 'other';
  12648. },
  12649. '17': function (n) {
  12650. if (n == 3) return 'few';
  12651. if (n === 0) return 'zero';
  12652. if (n == 6) return 'many';
  12653. if (n == 2) return 'two';
  12654. if (n == 1) return 'one';
  12655. return 'other';
  12656. },
  12657. '18': function (n) {
  12658. if (n === 0) return 'zero';
  12659. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12660. return 'other';
  12661. },
  12662. '19': function (n) {
  12663. if (isBetween(n, 2, 10)) return 'few';
  12664. if (isBetween(n, 0, 1)) return 'one';
  12665. return 'other';
  12666. },
  12667. '20': function (n) {
  12668. 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';
  12669. if (n % 1000000 === 0 && n !== 0) return 'many';
  12670. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12671. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12672. return 'other';
  12673. },
  12674. '21': function (n) {
  12675. if (n === 0) return 'zero';
  12676. if (n == 1) return 'one';
  12677. return 'other';
  12678. },
  12679. '22': function (n) {
  12680. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  12681. return 'other';
  12682. },
  12683. '23': function (n) {
  12684. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  12685. return 'other';
  12686. },
  12687. '24': function (n) {
  12688. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  12689. if (isIn(n, [2, 12])) return 'two';
  12690. if (isIn(n, [1, 11])) return 'one';
  12691. return 'other';
  12692. }
  12693. };
  12694. var index = locales2rules[lang.replace(/-.*$/, '')];
  12695. if (!(index in pluralRules)) {
  12696. console.warn('plural form unknown for [' + lang + ']');
  12697. return function () {
  12698. return 'other';
  12699. };
  12700. }
  12701. return pluralRules[index];
  12702. }
  12703. gMacros.plural = function (str, param, key, prop) {
  12704. var n = parseFloat(param);
  12705. if (isNaN(n)) return str;
  12706. if (prop != gTextProp) return str;
  12707. if (!gMacros._pluralRules) {
  12708. gMacros._pluralRules = getPluralRules(gLanguage);
  12709. }
  12710. var index = '[' + gMacros._pluralRules(n) + ']';
  12711. if (n === 0 && key + '[zero]' in gL10nData) {
  12712. str = gL10nData[key + '[zero]'][prop];
  12713. } else if (n == 1 && key + '[one]' in gL10nData) {
  12714. str = gL10nData[key + '[one]'][prop];
  12715. } else if (n == 2 && key + '[two]' in gL10nData) {
  12716. str = gL10nData[key + '[two]'][prop];
  12717. } else if (key + index in gL10nData) {
  12718. str = gL10nData[key + index][prop];
  12719. } else if (key + '[other]' in gL10nData) {
  12720. str = gL10nData[key + '[other]'][prop];
  12721. }
  12722. return str;
  12723. };
  12724. function getL10nData(key, args, fallback) {
  12725. var data = gL10nData[key];
  12726. if (!data) {
  12727. console.warn('#' + key + ' is undefined.');
  12728. if (!fallback) {
  12729. return null;
  12730. }
  12731. data = fallback;
  12732. }
  12733. var rv = {};
  12734. for (var prop in data) {
  12735. var str = data[prop];
  12736. str = substIndexes(str, args, key, prop);
  12737. str = substArguments(str, args, key);
  12738. rv[prop] = str;
  12739. }
  12740. return rv;
  12741. }
  12742. function substIndexes(str, args, key, prop) {
  12743. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  12744. var reMatch = reIndex.exec(str);
  12745. if (!reMatch || !reMatch.length) return str;
  12746. var macroName = reMatch[1];
  12747. var paramName = reMatch[2];
  12748. var param;
  12749. if (args && paramName in args) {
  12750. param = args[paramName];
  12751. } else if (paramName in gL10nData) {
  12752. param = gL10nData[paramName];
  12753. }
  12754. if (macroName in gMacros) {
  12755. var macro = gMacros[macroName];
  12756. str = macro(str, param, key, prop);
  12757. }
  12758. return str;
  12759. }
  12760. function substArguments(str, args, key) {
  12761. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  12762. return str.replace(reArgs, function (matched_text, arg) {
  12763. if (args && arg in args) {
  12764. return args[arg];
  12765. }
  12766. if (arg in gL10nData) {
  12767. return gL10nData[arg];
  12768. }
  12769. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  12770. return matched_text;
  12771. });
  12772. }
  12773. function translateElement(element) {
  12774. var l10n = getL10nAttributes(element);
  12775. if (!l10n.id) return;
  12776. var data = getL10nData(l10n.id, l10n.args);
  12777. if (!data) {
  12778. console.warn('#' + l10n.id + ' is undefined.');
  12779. return;
  12780. }
  12781. if (data[gTextProp]) {
  12782. if (getChildElementCount(element) === 0) {
  12783. element[gTextProp] = data[gTextProp];
  12784. } else {
  12785. var children = element.childNodes;
  12786. var found = false;
  12787. for (var i = 0, l = children.length; i < l; i++) {
  12788. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  12789. if (found) {
  12790. children[i].nodeValue = '';
  12791. } else {
  12792. children[i].nodeValue = data[gTextProp];
  12793. found = true;
  12794. }
  12795. }
  12796. }
  12797. if (!found) {
  12798. var textNode = document.createTextNode(data[gTextProp]);
  12799. element.prepend(textNode);
  12800. }
  12801. }
  12802. delete data[gTextProp];
  12803. }
  12804. for (var k in data) {
  12805. element[k] = data[k];
  12806. }
  12807. }
  12808. function getChildElementCount(element) {
  12809. if (element.children) {
  12810. return element.children.length;
  12811. }
  12812. if (typeof element.childElementCount !== 'undefined') {
  12813. return element.childElementCount;
  12814. }
  12815. var count = 0;
  12816. for (var i = 0; i < element.childNodes.length; i++) {
  12817. count += element.nodeType === 1 ? 1 : 0;
  12818. }
  12819. return count;
  12820. }
  12821. function translateFragment(element) {
  12822. element = element || document.documentElement;
  12823. var children = getTranslatableChildren(element);
  12824. var elementCount = children.length;
  12825. for (var i = 0; i < elementCount; i++) {
  12826. translateElement(children[i]);
  12827. }
  12828. translateElement(element);
  12829. }
  12830. return {
  12831. get: function (key, args, fallbackString) {
  12832. var index = key.lastIndexOf('.');
  12833. var prop = gTextProp;
  12834. if (index > 0) {
  12835. prop = key.substring(index + 1);
  12836. key = key.substring(0, index);
  12837. }
  12838. var fallback;
  12839. if (fallbackString) {
  12840. fallback = {};
  12841. fallback[prop] = fallbackString;
  12842. }
  12843. var data = getL10nData(key, args, fallback);
  12844. if (data && prop in data) {
  12845. return data[prop];
  12846. }
  12847. return '{{' + key + '}}';
  12848. },
  12849. getData: function () {
  12850. return gL10nData;
  12851. },
  12852. getText: function () {
  12853. return gTextData;
  12854. },
  12855. getLanguage: function () {
  12856. return gLanguage;
  12857. },
  12858. setLanguage: function (lang, callback) {
  12859. loadLocale(lang, function () {
  12860. if (callback) callback();
  12861. });
  12862. },
  12863. getDirection: function () {
  12864. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  12865. var shortCode = gLanguage.split('-', 1)[0];
  12866. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  12867. },
  12868. translate: translateFragment,
  12869. getReadyState: function () {
  12870. return gReadyState;
  12871. },
  12872. ready: function (callback) {
  12873. if (!callback) {
  12874. return;
  12875. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  12876. window.setTimeout(function () {
  12877. callback();
  12878. });
  12879. } else if (document.addEventListener) {
  12880. document.addEventListener('localized', function once() {
  12881. document.removeEventListener('localized', once);
  12882. callback();
  12883. });
  12884. }
  12885. }
  12886. };
  12887. }(window, document);
  12888. /***/
  12889. }),
  12890. /* 47 */
  12891. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12892. Object.defineProperty(exports, "__esModule", ({
  12893. value: true
  12894. }));
  12895. exports.GenericScripting = void 0;
  12896. exports.docPropertiesLookup = docPropertiesLookup;
  12897. var _pdfjsLib = __webpack_require__(5);
  12898. async function docPropertiesLookup(pdfDocument) {
  12899. const url = "",
  12900. baseUrl = url.split("#")[0];
  12901. let {
  12902. info,
  12903. metadata,
  12904. contentDispositionFilename,
  12905. contentLength
  12906. } = await pdfDocument.getMetadata();
  12907. if (!contentLength) {
  12908. const {
  12909. length
  12910. } = await pdfDocument.getDownloadInfo();
  12911. contentLength = length;
  12912. }
  12913. return {
  12914. ...info,
  12915. baseURL: baseUrl,
  12916. filesize: contentLength,
  12917. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  12918. metadata: metadata?.getRaw(),
  12919. authors: metadata?.get("dc:creator"),
  12920. numPages: pdfDocument.numPages,
  12921. URL: url
  12922. };
  12923. }
  12924. class GenericScripting {
  12925. constructor(sandboxBundleSrc) {
  12926. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  12927. return window.pdfjsSandbox.QuickJSSandbox();
  12928. });
  12929. }
  12930. async createSandbox(data) {
  12931. const sandbox = await this._ready;
  12932. sandbox.create(data);
  12933. }
  12934. async dispatchEventInSandbox(event) {
  12935. const sandbox = await this._ready;
  12936. setTimeout(() => sandbox.dispatchEvent(event), 0);
  12937. }
  12938. async destroySandbox() {
  12939. const sandbox = await this._ready;
  12940. sandbox.nukeSandbox();
  12941. }
  12942. }
  12943. exports.GenericScripting = GenericScripting;
  12944. /***/
  12945. }),
  12946. /* 48 */
  12947. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12948. Object.defineProperty(exports, "__esModule", ({
  12949. value: true
  12950. }));
  12951. exports.PDFPrintService = PDFPrintService;
  12952. var _pdfjsLib = __webpack_require__(5);
  12953. var _app = __webpack_require__(4);
  12954. var _print_utils = __webpack_require__(49);
  12955. let activeService = null;
  12956. let dialog = null;
  12957. let overlayManager = null;
  12958. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  12959. const scratchCanvas = activeService.scratchCanvas;
  12960. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  12961. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  12962. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  12963. const ctx = scratchCanvas.getContext("2d");
  12964. ctx.save();
  12965. ctx.fillStyle = "rgb(255, 255, 255)";
  12966. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  12967. ctx.restore();
  12968. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  12969. const renderContext = {
  12970. canvasContext: ctx,
  12971. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  12972. viewport: pdfPage.getViewport({
  12973. scale: 1,
  12974. rotation: size.rotation
  12975. }),
  12976. intent: "print",
  12977. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  12978. optionalContentConfigPromise,
  12979. printAnnotationStorage
  12980. };
  12981. return pdfPage.render(renderContext).promise;
  12982. });
  12983. }
  12984. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) {
  12985. this.pdfDocument = pdfDocument;
  12986. this.pagesOverview = pagesOverview;
  12987. this.printContainer = printContainer;
  12988. this._printResolution = printResolution || 150;
  12989. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  12990. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  12991. this.l10n = l10n;
  12992. this.currentPage = -1;
  12993. this.scratchCanvas = document.createElement("canvas");
  12994. }
  12995. PDFPrintService.prototype = {
  12996. layout() {
  12997. this.throwIfInactive();
  12998. const body = document.querySelector("body");
  12999. body.setAttribute("data-pdfjsprinting", true);
  13000. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  13001. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  13002. }, this);
  13003. if (!hasEqualPageSizes) {
  13004. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  13005. }
  13006. this.pageStyleSheet = document.createElement("style");
  13007. const pageSize = this.pagesOverview[0];
  13008. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  13009. body.append(this.pageStyleSheet);
  13010. },
  13011. destroy() {
  13012. if (activeService !== this) {
  13013. return;
  13014. }
  13015. this.printContainer.textContent = "";
  13016. const body = document.querySelector("body");
  13017. body.removeAttribute("data-pdfjsprinting");
  13018. if (this.pageStyleSheet) {
  13019. this.pageStyleSheet.remove();
  13020. this.pageStyleSheet = null;
  13021. }
  13022. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  13023. this.scratchCanvas = null;
  13024. activeService = null;
  13025. ensureOverlay().then(function () {
  13026. if (overlayManager.active === dialog) {
  13027. overlayManager.close(dialog);
  13028. }
  13029. });
  13030. },
  13031. renderPages() {
  13032. if (this.pdfDocument.isPureXfa) {
  13033. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  13034. return Promise.resolve();
  13035. }
  13036. const pageCount = this.pagesOverview.length;
  13037. const renderNextPage = (resolve, reject) => {
  13038. this.throwIfInactive();
  13039. if (++this.currentPage >= pageCount) {
  13040. renderProgress(pageCount, pageCount, this.l10n);
  13041. resolve();
  13042. return;
  13043. }
  13044. const index = this.currentPage;
  13045. renderProgress(index, pageCount, this.l10n);
  13046. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  13047. renderNextPage(resolve, reject);
  13048. }, reject);
  13049. };
  13050. return new Promise(renderNextPage);
  13051. },
  13052. useRenderedPage() {
  13053. this.throwIfInactive();
  13054. const img = document.createElement("img");
  13055. const scratchCanvas = this.scratchCanvas;
  13056. if ("toBlob" in scratchCanvas) {
  13057. scratchCanvas.toBlob(function (blob) {
  13058. img.src = URL.createObjectURL(blob);
  13059. });
  13060. } else {
  13061. img.src = scratchCanvas.toDataURL();
  13062. }
  13063. const wrapper = document.createElement("div");
  13064. wrapper.className = "printedPage";
  13065. wrapper.append(img);
  13066. this.printContainer.append(wrapper);
  13067. return new Promise(function (resolve, reject) {
  13068. img.onload = resolve;
  13069. img.onerror = reject;
  13070. });
  13071. },
  13072. performPrint() {
  13073. this.throwIfInactive();
  13074. return new Promise(resolve => {
  13075. setTimeout(() => {
  13076. if (!this.active) {
  13077. resolve();
  13078. return;
  13079. }
  13080. print.call(window);
  13081. setTimeout(resolve, 20);
  13082. }, 0);
  13083. });
  13084. },
  13085. get active() {
  13086. return this === activeService;
  13087. },
  13088. throwIfInactive() {
  13089. if (!this.active) {
  13090. throw new Error("This print request was cancelled or completed.");
  13091. }
  13092. }
  13093. };
  13094. const print = window.print;
  13095. window.print = function () {
  13096. if (activeService) {
  13097. console.warn("Ignored window.print() because of a pending print job.");
  13098. return;
  13099. }
  13100. ensureOverlay().then(function () {
  13101. if (activeService) {
  13102. overlayManager.open(dialog);
  13103. }
  13104. });
  13105. try {
  13106. dispatchEvent("beforeprint");
  13107. } finally {
  13108. if (!activeService) {
  13109. console.error("Expected print service to be initialized.");
  13110. ensureOverlay().then(function () {
  13111. if (overlayManager.active === dialog) {
  13112. overlayManager.close(dialog);
  13113. }
  13114. });
  13115. return;
  13116. }
  13117. const activeServiceOnEntry = activeService;
  13118. activeService.renderPages().then(function () {
  13119. return activeServiceOnEntry.performPrint();
  13120. }).catch(function () { }).then(function () {
  13121. if (activeServiceOnEntry.active) {
  13122. abort();
  13123. }
  13124. });
  13125. }
  13126. };
  13127. function dispatchEvent(eventType) {
  13128. const event = document.createEvent("CustomEvent");
  13129. event.initCustomEvent(eventType, false, false, "custom");
  13130. window.dispatchEvent(event);
  13131. }
  13132. function abort() {
  13133. if (activeService) {
  13134. activeService.destroy();
  13135. dispatchEvent("afterprint");
  13136. }
  13137. }
  13138. function renderProgress(index, total, l10n) {
  13139. dialog ||= document.getElementById("printServiceDialog");
  13140. const progress = Math.round(100 * index / total);
  13141. const progressBar = dialog.querySelector("progress");
  13142. const progressPerc = dialog.querySelector(".relative-progress");
  13143. progressBar.value = progress;
  13144. l10n.get("print_progress_percent", {
  13145. progress
  13146. }).then(msg => {
  13147. progressPerc.textContent = msg;
  13148. });
  13149. }
  13150. window.addEventListener("keydown", function (event) {
  13151. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  13152. window.print();
  13153. event.preventDefault();
  13154. if (event.stopImmediatePropagation) {
  13155. event.stopImmediatePropagation();
  13156. } else {
  13157. event.stopPropagation();
  13158. }
  13159. }
  13160. }, true);
  13161. if ("onbeforeprint" in window) {
  13162. const stopPropagationIfNeeded = function (event) {
  13163. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  13164. event.stopImmediatePropagation();
  13165. }
  13166. };
  13167. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  13168. window.addEventListener("afterprint", stopPropagationIfNeeded);
  13169. }
  13170. let overlayPromise;
  13171. function ensureOverlay() {
  13172. if (!overlayPromise) {
  13173. overlayManager = _app.PDFViewerApplication.overlayManager;
  13174. if (!overlayManager) {
  13175. throw new Error("The overlay manager has not yet been initialized.");
  13176. }
  13177. dialog ||= document.getElementById("printServiceDialog");
  13178. overlayPromise = overlayManager.register(dialog, true);
  13179. document.getElementById("printCancel").onclick = abort;
  13180. dialog.addEventListener("close", abort);
  13181. }
  13182. return overlayPromise;
  13183. }
  13184. _app.PDFPrintServiceFactory.instance = {
  13185. supportsPrinting: true,
  13186. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  13187. if (activeService) {
  13188. throw new Error("The print service is created and active.");
  13189. }
  13190. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  13191. return activeService;
  13192. }
  13193. };
  13194. /***/
  13195. }),
  13196. /* 49 */
  13197. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13198. Object.defineProperty(exports, "__esModule", ({
  13199. value: true
  13200. }));
  13201. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  13202. var _pdfjsLib = __webpack_require__(5);
  13203. var _pdf_link_service = __webpack_require__(3);
  13204. var _xfa_layer_builder = __webpack_require__(38);
  13205. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  13206. const xfaHtml = pdfDocument.allXfaHtml;
  13207. const linkService = new _pdf_link_service.SimpleLinkService();
  13208. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  13209. for (const xfaPage of xfaHtml.children) {
  13210. const page = document.createElement("div");
  13211. page.className = "xfaPrintedPage";
  13212. printContainer.append(page);
  13213. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  13214. pageDiv: page,
  13215. pdfPage: null,
  13216. annotationStorage: pdfDocument.annotationStorage,
  13217. linkService,
  13218. xfaHtml: xfaPage
  13219. });
  13220. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  13221. scale
  13222. });
  13223. builder.render(viewport, "print");
  13224. }
  13225. }
  13226. /***/
  13227. })
  13228. /******/]);
  13229. /************************************************************************/
  13230. /******/ // The module cache
  13231. /******/ var __webpack_module_cache__ = {};
  13232. /******/
  13233. /******/ // The require function
  13234. /******/ function __webpack_require__(moduleId) {
  13235. /******/ // Check if module is in cache
  13236. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  13237. /******/ if (cachedModule !== undefined) {
  13238. /******/ return cachedModule.exports;
  13239. /******/
  13240. }
  13241. /******/ // Create a new module (and put it into the cache)
  13242. /******/ var module = __webpack_module_cache__[moduleId] = {
  13243. /******/ // no module.id needed
  13244. /******/ // no module.loaded needed
  13245. /******/ exports: {}
  13246. /******/
  13247. };
  13248. /******/
  13249. /******/ // Execute the module function
  13250. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  13251. /******/
  13252. /******/ // Return the exports of the module
  13253. /******/ return module.exports;
  13254. /******/
  13255. }
  13256. /******/
  13257. /************************************************************************/
  13258. var __webpack_exports__ = {};
  13259. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  13260. (() => {
  13261. var exports = __webpack_exports__;
  13262. Object.defineProperty(exports, "__esModule", ({
  13263. value: true
  13264. }));
  13265. Object.defineProperty(exports, "PDFViewerApplication", ({
  13266. enumerable: true,
  13267. get: function () {
  13268. return _app.PDFViewerApplication;
  13269. }
  13270. }));
  13271. exports.PDFViewerApplicationConstants = void 0;
  13272. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  13273. enumerable: true,
  13274. get: function () {
  13275. return _app_options.AppOptions;
  13276. }
  13277. }));
  13278. var _ui_utils = __webpack_require__(1);
  13279. var _app_options = __webpack_require__(2);
  13280. var _pdf_link_service = __webpack_require__(3);
  13281. var _app = __webpack_require__(4);
  13282. const pdfjsVersion = '2.16.105';
  13283. const pdfjsBuild = '172ccdbe5';
  13284. const AppConstants = {
  13285. LinkTarget: _pdf_link_service.LinkTarget,
  13286. RenderingStates: _ui_utils.RenderingStates,
  13287. ScrollMode: _ui_utils.ScrollMode,
  13288. SpreadMode: _ui_utils.SpreadMode
  13289. };
  13290. exports.PDFViewerApplicationConstants = AppConstants;
  13291. window.PDFViewerApplication = _app.PDFViewerApplication;
  13292. window.PDFViewerApplicationConstants = AppConstants;
  13293. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  13294. ;
  13295. ;
  13296. {
  13297. __webpack_require__(42);
  13298. }
  13299. ;
  13300. {
  13301. __webpack_require__(48);
  13302. }
  13303. function getViewerConfiguration() {
  13304. let errorWrapper = null;
  13305. errorWrapper = {
  13306. container: document.getElementById("errorWrapper"),
  13307. errorMessage: document.getElementById("errorMessage"),
  13308. closeButton: document.getElementById("errorClose"),
  13309. errorMoreInfo: document.getElementById("errorMoreInfo"),
  13310. moreInfoButton: document.getElementById("errorShowMore"),
  13311. lessInfoButton: document.getElementById("errorShowLess")
  13312. };
  13313. return {
  13314. appContainer: document.body,
  13315. mainContainer: document.getElementById("viewerContainer"),
  13316. viewerContainer: document.getElementById("viewer"),
  13317. toolbar: {
  13318. container: document.getElementById("toolbarViewer"),
  13319. numPages: document.getElementById("numPages"),
  13320. pageNumber: document.getElementById("pageNumber"),
  13321. scaleSelect: document.getElementById("scaleSelect"),
  13322. customScaleOption: document.getElementById("customScaleOption"),
  13323. previous: document.getElementById("previous"),
  13324. next: document.getElementById("next"),
  13325. zoomIn: document.getElementById("zoomIn"),
  13326. zoomOut: document.getElementById("zoomOut"),
  13327. viewFind: document.getElementById("viewFind"),
  13328. openFile: document.getElementById("openFile"),
  13329. print: document.getElementById("print"),
  13330. editorFreeTextButton: document.getElementById("editorFreeText"),
  13331. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  13332. editorInkButton: document.getElementById("editorInk"),
  13333. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  13334. presentationModeButton: document.getElementById("presentationMode"),
  13335. download: document.getElementById("download"),
  13336. viewBookmark: document.getElementById("viewBookmark")
  13337. },
  13338. secondaryToolbar: {
  13339. toolbar: document.getElementById("secondaryToolbar"),
  13340. toggleButton: document.getElementById("secondaryToolbarToggle"),
  13341. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  13342. openFileButton: document.getElementById("secondaryOpenFile"),
  13343. printButton: document.getElementById("secondaryPrint"),
  13344. downloadButton: document.getElementById("secondaryDownload"),
  13345. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  13346. firstPageButton: document.getElementById("firstPage"),
  13347. lastPageButton: document.getElementById("lastPage"),
  13348. pageRotateCwButton: document.getElementById("pageRotateCw"),
  13349. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  13350. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  13351. cursorHandToolButton: document.getElementById("cursorHandTool"),
  13352. scrollPageButton: document.getElementById("scrollPage"),
  13353. scrollVerticalButton: document.getElementById("scrollVertical"),
  13354. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  13355. scrollWrappedButton: document.getElementById("scrollWrapped"),
  13356. spreadNoneButton: document.getElementById("spreadNone"),
  13357. spreadOddButton: document.getElementById("spreadOdd"),
  13358. spreadEvenButton: document.getElementById("spreadEven"),
  13359. documentPropertiesButton: document.getElementById("documentProperties")
  13360. },
  13361. sidebar: {
  13362. outerContainer: document.getElementById("outerContainer"),
  13363. sidebarContainer: document.getElementById("sidebarContainer"),
  13364. toggleButton: document.getElementById("sidebarToggle"),
  13365. thumbnailButton: document.getElementById("viewThumbnail"),
  13366. outlineButton: document.getElementById("viewOutline"),
  13367. attachmentsButton: document.getElementById("viewAttachments"),
  13368. layersButton: document.getElementById("viewLayers"),
  13369. thumbnailView: document.getElementById("thumbnailView"),
  13370. outlineView: document.getElementById("outlineView"),
  13371. attachmentsView: document.getElementById("attachmentsView"),
  13372. layersView: document.getElementById("layersView"),
  13373. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  13374. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  13375. },
  13376. sidebarResizer: {
  13377. outerContainer: document.getElementById("outerContainer"),
  13378. resizer: document.getElementById("sidebarResizer")
  13379. },
  13380. findBar: {
  13381. bar: document.getElementById("findbar"),
  13382. toggleButton: document.getElementById("viewFind"),
  13383. findField: document.getElementById("findInput"),
  13384. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  13385. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  13386. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  13387. entireWordCheckbox: document.getElementById("findEntireWord"),
  13388. findMsg: document.getElementById("findMsg"),
  13389. findResultsCount: document.getElementById("findResultsCount"),
  13390. findPreviousButton: document.getElementById("findPrevious"),
  13391. findNextButton: document.getElementById("findNext")
  13392. },
  13393. passwordOverlay: {
  13394. dialog: document.getElementById("passwordDialog"),
  13395. label: document.getElementById("passwordText"),
  13396. input: document.getElementById("password"),
  13397. submitButton: document.getElementById("passwordSubmit"),
  13398. cancelButton: document.getElementById("passwordCancel")
  13399. },
  13400. documentProperties: {
  13401. dialog: document.getElementById("documentPropertiesDialog"),
  13402. closeButton: document.getElementById("documentPropertiesClose"),
  13403. fields: {
  13404. fileName: document.getElementById("fileNameField"),
  13405. fileSize: document.getElementById("fileSizeField"),
  13406. title: document.getElementById("titleField"),
  13407. author: document.getElementById("authorField"),
  13408. subject: document.getElementById("subjectField"),
  13409. keywords: document.getElementById("keywordsField"),
  13410. creationDate: document.getElementById("creationDateField"),
  13411. modificationDate: document.getElementById("modificationDateField"),
  13412. creator: document.getElementById("creatorField"),
  13413. producer: document.getElementById("producerField"),
  13414. version: document.getElementById("versionField"),
  13415. pageCount: document.getElementById("pageCountField"),
  13416. pageSize: document.getElementById("pageSizeField"),
  13417. linearized: document.getElementById("linearizedField")
  13418. }
  13419. },
  13420. annotationEditorParams: {
  13421. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  13422. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  13423. editorInkColor: document.getElementById("editorInkColor"),
  13424. editorInkThickness: document.getElementById("editorInkThickness"),
  13425. editorInkOpacity: document.getElementById("editorInkOpacity")
  13426. },
  13427. errorWrapper,
  13428. printContainer: document.getElementById("printContainer"),
  13429. openFileInput: document.getElementById("fileInput"),
  13430. debuggerScriptPath: "./debugger.js"
  13431. };
  13432. }
  13433. function webViewerLoad() {
  13434. const config = getViewerConfiguration();
  13435. const event = document.createEvent("CustomEvent");
  13436. event.initCustomEvent("webviewerloaded", true, true, {
  13437. source: window
  13438. });
  13439. try {
  13440. parent.document.dispatchEvent(event);
  13441. } catch (ex) {
  13442. console.error(`webviewerloaded: ${ex}`);
  13443. document.dispatchEvent(event);
  13444. }
  13445. _app.PDFViewerApplication.run(config);
  13446. }
  13447. document.blockUnblockOnload?.(true);
  13448. if (document.readyState === "interactive" || document.readyState === "complete") {
  13449. webViewerLoad();
  13450. } else {
  13451. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  13452. }
  13453. })();
  13454. /******/
  13455. })()
  13456. ;
  13457. //# sourceMappingURL=viewer.js.map