viewer.js 417 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550
  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. /* 2 */
  534. /***/ ((__unused_webpack_module, exports) => {
  535. Object.defineProperty(exports, "__esModule", ({
  536. value: true
  537. }));
  538. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  539. const compatibilityParams = Object.create(null);
  540. exports.compatibilityParams = compatibilityParams;
  541. {
  542. const userAgent = navigator.userAgent || "";
  543. const platform = navigator.platform || "";
  544. const maxTouchPoints = navigator.maxTouchPoints || 1;
  545. const isAndroid = /Android/.test(userAgent);
  546. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  547. (function checkCanvasSizeLimitation() {
  548. if (isIOS || isAndroid) {
  549. compatibilityParams.maxCanvasPixels = 5242880;
  550. }
  551. })();
  552. }
  553. const OptionKind = {
  554. VIEWER: 0x02,
  555. API: 0x04,
  556. WORKER: 0x08,
  557. PREFERENCE: 0x80
  558. };
  559. exports.OptionKind = OptionKind;
  560. const defaultOptions = {
  561. annotationEditorMode: {
  562. value: -1,
  563. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  564. },
  565. annotationMode: {
  566. value: 2,
  567. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  568. },
  569. cursorToolOnLoad: {
  570. value: 0,
  571. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  572. },
  573. defaultZoomValue: {
  574. value: "",
  575. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  576. },
  577. disableHistory: {
  578. value: false,
  579. kind: OptionKind.VIEWER
  580. },
  581. disablePageLabels: {
  582. value: false,
  583. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  584. },
  585. enablePermissions: {
  586. value: false,
  587. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  588. },
  589. enablePrintAutoRotate: {
  590. value: true,
  591. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  592. },
  593. enableScripting: {
  594. value: true,
  595. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  596. },
  597. externalLinkRel: {
  598. value: "noopener noreferrer nofollow",
  599. kind: OptionKind.VIEWER
  600. },
  601. externalLinkTarget: {
  602. value: 0,
  603. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  604. },
  605. historyUpdateUrl: {
  606. value: false,
  607. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  608. },
  609. ignoreDestinationZoom: {
  610. value: false,
  611. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  612. },
  613. imageResourcesPath: {
  614. value: "./images/",
  615. kind: OptionKind.VIEWER
  616. },
  617. maxCanvasPixels: {
  618. value: 16777216,
  619. kind: OptionKind.VIEWER
  620. },
  621. forcePageColors: {
  622. value: false,
  623. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  624. },
  625. pageColorsBackground: {
  626. value: "Canvas",
  627. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  628. },
  629. pageColorsForeground: {
  630. value: "CanvasText",
  631. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  632. },
  633. pdfBugEnabled: {
  634. value: false,
  635. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  636. },
  637. printResolution: {
  638. value: 150,
  639. kind: OptionKind.VIEWER
  640. },
  641. sidebarViewOnLoad: {
  642. value: -1,
  643. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  644. },
  645. scrollModeOnLoad: {
  646. value: -1,
  647. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  648. },
  649. spreadModeOnLoad: {
  650. value: -1,
  651. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  652. },
  653. textLayerMode: {
  654. value: 1,
  655. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  656. },
  657. useOnlyCssZoom: {
  658. value: false,
  659. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  660. },
  661. viewerCssTheme: {
  662. value: 0,
  663. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  664. },
  665. viewOnLoad: {
  666. value: 0,
  667. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  668. },
  669. cMapPacked: {
  670. value: true,
  671. kind: OptionKind.API
  672. },
  673. cMapUrl: {
  674. value: "../web/cmaps/",
  675. kind: OptionKind.API
  676. },
  677. disableAutoFetch: {
  678. value: false,
  679. kind: OptionKind.API + OptionKind.PREFERENCE
  680. },
  681. disableFontFace: {
  682. value: false,
  683. kind: OptionKind.API + OptionKind.PREFERENCE
  684. },
  685. disableRange: {
  686. value: false,
  687. kind: OptionKind.API + OptionKind.PREFERENCE
  688. },
  689. disableStream: {
  690. value: false,
  691. kind: OptionKind.API + OptionKind.PREFERENCE
  692. },
  693. docBaseUrl: {
  694. value: "",
  695. kind: OptionKind.API
  696. },
  697. enableXfa: {
  698. value: true,
  699. kind: OptionKind.API + OptionKind.PREFERENCE
  700. },
  701. fontExtraProperties: {
  702. value: false,
  703. kind: OptionKind.API
  704. },
  705. isEvalSupported: {
  706. value: true,
  707. kind: OptionKind.API
  708. },
  709. maxImageSize: {
  710. value: -1,
  711. kind: OptionKind.API
  712. },
  713. pdfBug: {
  714. value: false,
  715. kind: OptionKind.API
  716. },
  717. standardFontDataUrl: {
  718. value: "../web/standard_fonts/",
  719. kind: OptionKind.API
  720. },
  721. verbosity: {
  722. value: 1,
  723. kind: OptionKind.API
  724. },
  725. workerPort: {
  726. value: null,
  727. kind: OptionKind.WORKER
  728. },
  729. workerSrc: {
  730. value: "../build/pdf.worker.js",
  731. kind: OptionKind.WORKER
  732. }
  733. };
  734. {
  735. defaultOptions.defaultUrl = {
  736. value: "compressed.tracemonkey-pldi-09.pdf",
  737. kind: OptionKind.VIEWER
  738. };
  739. defaultOptions.disablePreferences = {
  740. value: false,
  741. kind: OptionKind.VIEWER
  742. };
  743. defaultOptions.locale = {
  744. value: navigator.language || "en-US",
  745. kind: OptionKind.VIEWER
  746. };
  747. defaultOptions.renderer = {
  748. value: "canvas",
  749. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  750. };
  751. defaultOptions.sandboxBundleSrc = {
  752. value: "../build/pdf.sandbox.js",
  753. kind: OptionKind.VIEWER
  754. };
  755. }
  756. const userOptions = Object.create(null);
  757. class AppOptions {
  758. constructor() {
  759. throw new Error("Cannot initialize AppOptions.");
  760. }
  761. static get(name) {
  762. const userOption = userOptions[name];
  763. if (userOption !== undefined) {
  764. return userOption;
  765. }
  766. const defaultOption = defaultOptions[name];
  767. if (defaultOption !== undefined) {
  768. return compatibilityParams[name] ?? defaultOption.value;
  769. }
  770. return undefined;
  771. }
  772. static getAll(kind = null) {
  773. const options = Object.create(null);
  774. for (const name in defaultOptions) {
  775. const defaultOption = defaultOptions[name];
  776. if (kind) {
  777. if ((kind & defaultOption.kind) === 0) {
  778. continue;
  779. }
  780. if (kind === OptionKind.PREFERENCE) {
  781. const value = defaultOption.value,
  782. valueType = typeof value;
  783. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  784. options[name] = value;
  785. continue;
  786. }
  787. throw new Error(`Invalid type for preference: ${name}`);
  788. }
  789. }
  790. const userOption = userOptions[name];
  791. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  792. }
  793. return options;
  794. }
  795. static set(name, value) {
  796. userOptions[name] = value;
  797. }
  798. static setAll(options) {
  799. for (const name in options) {
  800. userOptions[name] = options[name];
  801. }
  802. }
  803. static remove(name) {
  804. delete userOptions[name];
  805. }
  806. static _hasUserOptions() {
  807. return Object.keys(userOptions).length > 0;
  808. }
  809. }
  810. exports.AppOptions = AppOptions;
  811. /***/ }),
  812. /* 3 */
  813. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  814. Object.defineProperty(exports, "__esModule", ({
  815. value: true
  816. }));
  817. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  818. var _ui_utils = __webpack_require__(1);
  819. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  820. const LinkTarget = {
  821. NONE: 0,
  822. SELF: 1,
  823. BLANK: 2,
  824. PARENT: 3,
  825. TOP: 4
  826. };
  827. exports.LinkTarget = LinkTarget;
  828. function addLinkAttributes(link, {
  829. url,
  830. target,
  831. rel,
  832. enabled = true
  833. } = {}) {
  834. if (!url || typeof url !== "string") {
  835. throw new Error('A valid "url" parameter must provided.');
  836. }
  837. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  838. if (enabled) {
  839. link.href = link.title = urlNullRemoved;
  840. } else {
  841. link.href = "";
  842. link.title = `Disabled: ${urlNullRemoved}`;
  843. link.onclick = () => {
  844. return false;
  845. };
  846. }
  847. let targetStr = "";
  848. switch (target) {
  849. case LinkTarget.NONE:
  850. break;
  851. case LinkTarget.SELF:
  852. targetStr = "_self";
  853. break;
  854. case LinkTarget.BLANK:
  855. targetStr = "_blank";
  856. break;
  857. case LinkTarget.PARENT:
  858. targetStr = "_parent";
  859. break;
  860. case LinkTarget.TOP:
  861. targetStr = "_top";
  862. break;
  863. }
  864. link.target = targetStr;
  865. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  866. }
  867. class PDFLinkService {
  868. #pagesRefCache = new Map();
  869. constructor({
  870. eventBus,
  871. externalLinkTarget = null,
  872. externalLinkRel = null,
  873. ignoreDestinationZoom = false
  874. } = {}) {
  875. this.eventBus = eventBus;
  876. this.externalLinkTarget = externalLinkTarget;
  877. this.externalLinkRel = externalLinkRel;
  878. this.externalLinkEnabled = true;
  879. this._ignoreDestinationZoom = ignoreDestinationZoom;
  880. this.baseUrl = null;
  881. this.pdfDocument = null;
  882. this.pdfViewer = null;
  883. this.pdfHistory = null;
  884. }
  885. setDocument(pdfDocument, baseUrl = null) {
  886. this.baseUrl = baseUrl;
  887. this.pdfDocument = pdfDocument;
  888. this.#pagesRefCache.clear();
  889. }
  890. setViewer(pdfViewer) {
  891. this.pdfViewer = pdfViewer;
  892. }
  893. setHistory(pdfHistory) {
  894. this.pdfHistory = pdfHistory;
  895. }
  896. get pagesCount() {
  897. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  898. }
  899. get page() {
  900. return this.pdfViewer.currentPageNumber;
  901. }
  902. set page(value) {
  903. this.pdfViewer.currentPageNumber = value;
  904. }
  905. get rotation() {
  906. return this.pdfViewer.pagesRotation;
  907. }
  908. set rotation(value) {
  909. this.pdfViewer.pagesRotation = value;
  910. }
  911. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  912. const destRef = explicitDest[0];
  913. let pageNumber;
  914. if (typeof destRef === "object" && destRef !== null) {
  915. pageNumber = this._cachedPageNumber(destRef);
  916. if (!pageNumber) {
  917. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  918. this.cachePageRef(pageIndex + 1, destRef);
  919. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  920. }).catch(() => {
  921. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  922. });
  923. return;
  924. }
  925. } else if (Number.isInteger(destRef)) {
  926. pageNumber = destRef + 1;
  927. } else {
  928. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  929. return;
  930. }
  931. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  932. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  933. return;
  934. }
  935. if (this.pdfHistory) {
  936. this.pdfHistory.pushCurrentPosition();
  937. this.pdfHistory.push({
  938. namedDest,
  939. explicitDest,
  940. pageNumber
  941. });
  942. }
  943. this.pdfViewer.scrollPageIntoView({
  944. pageNumber,
  945. destArray: explicitDest,
  946. ignoreDestinationZoom: this._ignoreDestinationZoom
  947. });
  948. }
  949. async goToDestination(dest) {
  950. if (!this.pdfDocument) {
  951. return;
  952. }
  953. let namedDest, explicitDest;
  954. if (typeof dest === "string") {
  955. namedDest = dest;
  956. explicitDest = await this.pdfDocument.getDestination(dest);
  957. } else {
  958. namedDest = null;
  959. explicitDest = await dest;
  960. }
  961. if (!Array.isArray(explicitDest)) {
  962. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  963. return;
  964. }
  965. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  966. }
  967. goToPage(val) {
  968. if (!this.pdfDocument) {
  969. return;
  970. }
  971. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  972. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  973. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  974. return;
  975. }
  976. if (this.pdfHistory) {
  977. this.pdfHistory.pushCurrentPosition();
  978. this.pdfHistory.pushPage(pageNumber);
  979. }
  980. this.pdfViewer.scrollPageIntoView({
  981. pageNumber
  982. });
  983. }
  984. addLinkAttributes(link, url, newWindow = false) {
  985. addLinkAttributes(link, {
  986. url,
  987. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  988. rel: this.externalLinkRel,
  989. enabled: this.externalLinkEnabled
  990. });
  991. }
  992. getDestinationHash(dest) {
  993. if (typeof dest === "string") {
  994. if (dest.length > 0) {
  995. return this.getAnchorUrl("#" + escape(dest));
  996. }
  997. } else if (Array.isArray(dest)) {
  998. const str = JSON.stringify(dest);
  999. if (str.length > 0) {
  1000. return this.getAnchorUrl("#" + escape(str));
  1001. }
  1002. }
  1003. return this.getAnchorUrl("");
  1004. }
  1005. getAnchorUrl(anchor) {
  1006. return (this.baseUrl || "") + anchor;
  1007. }
  1008. setHash(hash) {
  1009. if (!this.pdfDocument) {
  1010. return;
  1011. }
  1012. let pageNumber, dest;
  1013. if (hash.includes("=")) {
  1014. const params = (0, _ui_utils.parseQueryString)(hash);
  1015. if (params.has("search")) {
  1016. this.eventBus.dispatch("findfromurlhash", {
  1017. source: this,
  1018. query: params.get("search").replace(/"/g, ""),
  1019. phraseSearch: params.get("phrase") === "true"
  1020. });
  1021. }
  1022. if (params.has("page")) {
  1023. pageNumber = params.get("page") | 0 || 1;
  1024. }
  1025. if (params.has("zoom")) {
  1026. const zoomArgs = params.get("zoom").split(",");
  1027. const zoomArg = zoomArgs[0];
  1028. const zoomArgNumber = parseFloat(zoomArg);
  1029. if (!zoomArg.includes("Fit")) {
  1030. dest = [null, {
  1031. name: "XYZ"
  1032. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  1033. } else {
  1034. if (zoomArg === "Fit" || zoomArg === "FitB") {
  1035. dest = [null, {
  1036. name: zoomArg
  1037. }];
  1038. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  1039. dest = [null, {
  1040. name: zoomArg
  1041. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  1042. } else if (zoomArg === "FitR") {
  1043. if (zoomArgs.length !== 5) {
  1044. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  1045. } else {
  1046. dest = [null, {
  1047. name: zoomArg
  1048. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  1049. }
  1050. } else {
  1051. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  1052. }
  1053. }
  1054. }
  1055. if (dest) {
  1056. this.pdfViewer.scrollPageIntoView({
  1057. pageNumber: pageNumber || this.page,
  1058. destArray: dest,
  1059. allowNegativeOffset: true
  1060. });
  1061. } else if (pageNumber) {
  1062. this.page = pageNumber;
  1063. }
  1064. if (params.has("pagemode")) {
  1065. this.eventBus.dispatch("pagemode", {
  1066. source: this,
  1067. mode: params.get("pagemode")
  1068. });
  1069. }
  1070. if (params.has("nameddest")) {
  1071. this.goToDestination(params.get("nameddest"));
  1072. }
  1073. } else {
  1074. dest = unescape(hash);
  1075. try {
  1076. dest = JSON.parse(dest);
  1077. if (!Array.isArray(dest)) {
  1078. dest = dest.toString();
  1079. }
  1080. } catch (ex) {}
  1081. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  1082. this.goToDestination(dest);
  1083. return;
  1084. }
  1085. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  1086. }
  1087. }
  1088. executeNamedAction(action) {
  1089. switch (action) {
  1090. case "GoBack":
  1091. this.pdfHistory?.back();
  1092. break;
  1093. case "GoForward":
  1094. this.pdfHistory?.forward();
  1095. break;
  1096. case "NextPage":
  1097. this.pdfViewer.nextPage();
  1098. break;
  1099. case "PrevPage":
  1100. this.pdfViewer.previousPage();
  1101. break;
  1102. case "LastPage":
  1103. this.page = this.pagesCount;
  1104. break;
  1105. case "FirstPage":
  1106. this.page = 1;
  1107. break;
  1108. default:
  1109. break;
  1110. }
  1111. this.eventBus.dispatch("namedaction", {
  1112. source: this,
  1113. action
  1114. });
  1115. }
  1116. cachePageRef(pageNum, pageRef) {
  1117. if (!pageRef) {
  1118. return;
  1119. }
  1120. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1121. this.#pagesRefCache.set(refStr, pageNum);
  1122. }
  1123. _cachedPageNumber(pageRef) {
  1124. if (!pageRef) {
  1125. return null;
  1126. }
  1127. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1128. return this.#pagesRefCache.get(refStr) || null;
  1129. }
  1130. isPageVisible(pageNumber) {
  1131. return this.pdfViewer.isPageVisible(pageNumber);
  1132. }
  1133. isPageCached(pageNumber) {
  1134. return this.pdfViewer.isPageCached(pageNumber);
  1135. }
  1136. static #isValidExplicitDestination(dest) {
  1137. if (!Array.isArray(dest)) {
  1138. return false;
  1139. }
  1140. const destLength = dest.length;
  1141. if (destLength < 2) {
  1142. return false;
  1143. }
  1144. const page = dest[0];
  1145. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  1146. return false;
  1147. }
  1148. const zoom = dest[1];
  1149. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  1150. return false;
  1151. }
  1152. let allowNull = true;
  1153. switch (zoom.name) {
  1154. case "XYZ":
  1155. if (destLength !== 5) {
  1156. return false;
  1157. }
  1158. break;
  1159. case "Fit":
  1160. case "FitB":
  1161. return destLength === 2;
  1162. case "FitH":
  1163. case "FitBH":
  1164. case "FitV":
  1165. case "FitBV":
  1166. if (destLength !== 3) {
  1167. return false;
  1168. }
  1169. break;
  1170. case "FitR":
  1171. if (destLength !== 6) {
  1172. return false;
  1173. }
  1174. allowNull = false;
  1175. break;
  1176. default:
  1177. return false;
  1178. }
  1179. for (let i = 2; i < destLength; i++) {
  1180. const param = dest[i];
  1181. if (!(typeof param === "number" || allowNull && param === null)) {
  1182. return false;
  1183. }
  1184. }
  1185. return true;
  1186. }
  1187. }
  1188. exports.PDFLinkService = PDFLinkService;
  1189. class SimpleLinkService {
  1190. constructor() {
  1191. this.externalLinkEnabled = true;
  1192. }
  1193. get pagesCount() {
  1194. return 0;
  1195. }
  1196. get page() {
  1197. return 0;
  1198. }
  1199. set page(value) {}
  1200. get rotation() {
  1201. return 0;
  1202. }
  1203. set rotation(value) {}
  1204. async goToDestination(dest) {}
  1205. goToPage(val) {}
  1206. addLinkAttributes(link, url, newWindow = false) {
  1207. addLinkAttributes(link, {
  1208. url,
  1209. enabled: this.externalLinkEnabled
  1210. });
  1211. }
  1212. getDestinationHash(dest) {
  1213. return "#";
  1214. }
  1215. getAnchorUrl(hash) {
  1216. return "#";
  1217. }
  1218. setHash(hash) {}
  1219. executeNamedAction(action) {}
  1220. cachePageRef(pageNum, pageRef) {}
  1221. isPageVisible(pageNumber) {
  1222. return true;
  1223. }
  1224. isPageCached(pageNumber) {
  1225. return true;
  1226. }
  1227. }
  1228. exports.SimpleLinkService = SimpleLinkService;
  1229. /***/ }),
  1230. /* 4 */
  1231. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1232. Object.defineProperty(exports, "__esModule", ({
  1233. value: true
  1234. }));
  1235. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  1236. var _ui_utils = __webpack_require__(1);
  1237. var _pdfjsLib = __webpack_require__(5);
  1238. var _app_options = __webpack_require__(2);
  1239. var _event_utils = __webpack_require__(6);
  1240. var _pdf_cursor_tools = __webpack_require__(7);
  1241. var _pdf_link_service = __webpack_require__(3);
  1242. var _annotation_editor_params = __webpack_require__(9);
  1243. var _overlay_manager = __webpack_require__(10);
  1244. var _password_prompt = __webpack_require__(11);
  1245. var _pdf_attachment_viewer = __webpack_require__(12);
  1246. var _pdf_document_properties = __webpack_require__(14);
  1247. var _pdf_find_bar = __webpack_require__(15);
  1248. var _pdf_find_controller = __webpack_require__(16);
  1249. var _pdf_history = __webpack_require__(18);
  1250. var _pdf_layer_viewer = __webpack_require__(19);
  1251. var _pdf_outline_viewer = __webpack_require__(20);
  1252. var _pdf_presentation_mode = __webpack_require__(21);
  1253. var _pdf_rendering_queue = __webpack_require__(22);
  1254. var _pdf_scripting_manager = __webpack_require__(23);
  1255. var _pdf_sidebar = __webpack_require__(24);
  1256. var _pdf_sidebar_resizer = __webpack_require__(25);
  1257. var _pdf_thumbnail_viewer = __webpack_require__(26);
  1258. var _pdf_viewer = __webpack_require__(28);
  1259. var _secondary_toolbar = __webpack_require__(39);
  1260. var _toolbar = __webpack_require__(40);
  1261. var _view_history = __webpack_require__(41);
  1262. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  1263. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  1264. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  1265. const ViewOnLoad = {
  1266. UNKNOWN: -1,
  1267. PREVIOUS: 0,
  1268. INITIAL: 1
  1269. };
  1270. const ViewerCssTheme = {
  1271. AUTOMATIC: 0,
  1272. LIGHT: 1,
  1273. DARK: 2
  1274. };
  1275. 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"];
  1276. 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"];
  1277. class DefaultExternalServices {
  1278. constructor() {
  1279. throw new Error("Cannot initialize DefaultExternalServices.");
  1280. }
  1281. static updateFindControlState(data) {}
  1282. static updateFindMatchesCount(data) {}
  1283. static initPassiveLoading(callbacks) {}
  1284. static reportTelemetry(data) {}
  1285. static createDownloadManager(options) {
  1286. throw new Error("Not implemented: createDownloadManager");
  1287. }
  1288. static createPreferences() {
  1289. throw new Error("Not implemented: createPreferences");
  1290. }
  1291. static createL10n(options) {
  1292. throw new Error("Not implemented: createL10n");
  1293. }
  1294. static createScripting(options) {
  1295. throw new Error("Not implemented: createScripting");
  1296. }
  1297. static get supportsIntegratedFind() {
  1298. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  1299. }
  1300. static get supportsDocumentFonts() {
  1301. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  1302. }
  1303. static get supportedMouseWheelZoomModifierKeys() {
  1304. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  1305. ctrlKey: true,
  1306. metaKey: true
  1307. });
  1308. }
  1309. static get isInAutomation() {
  1310. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  1311. }
  1312. static updateEditorStates(data) {
  1313. throw new Error("Not implemented: updateEditorStates");
  1314. }
  1315. }
  1316. exports.DefaultExternalServices = DefaultExternalServices;
  1317. const PDFViewerApplication = {
  1318. initialBookmark: document.location.hash.substring(1),
  1319. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  1320. appConfig: null,
  1321. pdfDocument: null,
  1322. pdfLoadingTask: null,
  1323. printService: null,
  1324. pdfViewer: null,
  1325. pdfThumbnailViewer: null,
  1326. pdfRenderingQueue: null,
  1327. pdfPresentationMode: null,
  1328. pdfDocumentProperties: null,
  1329. pdfLinkService: null,
  1330. pdfHistory: null,
  1331. pdfSidebar: null,
  1332. pdfSidebarResizer: null,
  1333. pdfOutlineViewer: null,
  1334. pdfAttachmentViewer: null,
  1335. pdfLayerViewer: null,
  1336. pdfCursorTools: null,
  1337. pdfScriptingManager: null,
  1338. store: null,
  1339. downloadManager: null,
  1340. overlayManager: null,
  1341. preferences: null,
  1342. toolbar: null,
  1343. secondaryToolbar: null,
  1344. eventBus: null,
  1345. l10n: null,
  1346. annotationEditorParams: null,
  1347. isInitialViewSet: false,
  1348. downloadComplete: false,
  1349. isViewerEmbedded: window.parent !== window,
  1350. url: "",
  1351. baseUrl: "",
  1352. _downloadUrl: "",
  1353. externalServices: DefaultExternalServices,
  1354. _boundEvents: Object.create(null),
  1355. documentInfo: null,
  1356. metadata: null,
  1357. _contentDispositionFilename: null,
  1358. _contentLength: null,
  1359. _saveInProgress: false,
  1360. _docStats: null,
  1361. _wheelUnusedTicks: 0,
  1362. _idleCallbacks: new Set(),
  1363. _PDFBug: null,
  1364. _hasAnnotationEditors: false,
  1365. _title: document.title,
  1366. _printAnnotationStoragePromise: null,
  1367. async initialize(appConfig) {
  1368. this.preferences = this.externalServices.createPreferences();
  1369. this.appConfig = appConfig;
  1370. await this._readPreferences();
  1371. await this._parseHashParameters();
  1372. this._forceCssTheme();
  1373. await this._initializeL10n();
  1374. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  1375. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  1376. }
  1377. await this._initializeViewerComponents();
  1378. this.bindEvents();
  1379. this.bindWindowEvents();
  1380. const appContainer = appConfig.appContainer || document.documentElement;
  1381. this.l10n.translate(appContainer).then(() => {
  1382. this.eventBus.dispatch("localized", {
  1383. source: this
  1384. });
  1385. });
  1386. this._initializedCapability.resolve();
  1387. },
  1388. async _readPreferences() {
  1389. if (_app_options.AppOptions.get("disablePreferences")) {
  1390. return;
  1391. }
  1392. if (_app_options.AppOptions._hasUserOptions()) {
  1393. console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  1394. }
  1395. try {
  1396. _app_options.AppOptions.setAll(await this.preferences.getAll());
  1397. } catch (reason) {
  1398. console.error(`_readPreferences: "${reason?.message}".`);
  1399. }
  1400. },
  1401. async _parseHashParameters() {
  1402. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  1403. return;
  1404. }
  1405. const hash = document.location.hash.substring(1);
  1406. if (!hash) {
  1407. return;
  1408. }
  1409. const {
  1410. mainContainer,
  1411. viewerContainer
  1412. } = this.appConfig,
  1413. params = (0, _ui_utils.parseQueryString)(hash);
  1414. if (params.get("disableworker") === "true") {
  1415. try {
  1416. await loadFakeWorker();
  1417. } catch (ex) {
  1418. console.error(`_parseHashParameters: "${ex.message}".`);
  1419. }
  1420. }
  1421. if (params.has("disablerange")) {
  1422. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  1423. }
  1424. if (params.has("disablestream")) {
  1425. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  1426. }
  1427. if (params.has("disableautofetch")) {
  1428. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  1429. }
  1430. if (params.has("disablefontface")) {
  1431. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  1432. }
  1433. if (params.has("disablehistory")) {
  1434. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  1435. }
  1436. if (params.has("verbosity")) {
  1437. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  1438. }
  1439. if (params.has("textlayer")) {
  1440. switch (params.get("textlayer")) {
  1441. case "off":
  1442. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  1443. break;
  1444. case "visible":
  1445. case "shadow":
  1446. case "hover":
  1447. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  1448. try {
  1449. await loadPDFBug(this);
  1450. this._PDFBug.loadCSS();
  1451. } catch (ex) {
  1452. console.error(`_parseHashParameters: "${ex.message}".`);
  1453. }
  1454. break;
  1455. }
  1456. }
  1457. if (params.has("pdfbug")) {
  1458. _app_options.AppOptions.set("pdfBug", true);
  1459. _app_options.AppOptions.set("fontExtraProperties", true);
  1460. const enabled = params.get("pdfbug").split(",");
  1461. try {
  1462. await loadPDFBug(this);
  1463. this._PDFBug.init({
  1464. OPS: _pdfjsLib.OPS
  1465. }, mainContainer, enabled);
  1466. } catch (ex) {
  1467. console.error(`_parseHashParameters: "${ex.message}".`);
  1468. }
  1469. }
  1470. if (params.has("locale")) {
  1471. _app_options.AppOptions.set("locale", params.get("locale"));
  1472. }
  1473. },
  1474. async _initializeL10n() {
  1475. this.l10n = this.externalServices.createL10n({
  1476. locale: _app_options.AppOptions.get("locale")
  1477. });
  1478. const dir = await this.l10n.getDirection();
  1479. document.getElementsByTagName("html")[0].dir = dir;
  1480. },
  1481. _forceCssTheme() {
  1482. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  1483. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  1484. return;
  1485. }
  1486. try {
  1487. const styleSheet = document.styleSheets[0];
  1488. const cssRules = styleSheet?.cssRules || [];
  1489. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  1490. const rule = cssRules[i];
  1491. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  1492. if (cssTheme === ViewerCssTheme.LIGHT) {
  1493. styleSheet.deleteRule(i);
  1494. return;
  1495. }
  1496. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  1497. if (darkRules?.[1]) {
  1498. styleSheet.deleteRule(i);
  1499. styleSheet.insertRule(darkRules[1], i);
  1500. }
  1501. return;
  1502. }
  1503. }
  1504. } catch (reason) {
  1505. console.error(`_forceCssTheme: "${reason?.message}".`);
  1506. }
  1507. },
  1508. async _initializeViewerComponents() {
  1509. const {
  1510. appConfig,
  1511. externalServices
  1512. } = this;
  1513. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  1514. this.eventBus = eventBus;
  1515. this.overlayManager = new _overlay_manager.OverlayManager();
  1516. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  1517. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  1518. this.pdfRenderingQueue = pdfRenderingQueue;
  1519. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  1520. eventBus,
  1521. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  1522. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  1523. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  1524. });
  1525. this.pdfLinkService = pdfLinkService;
  1526. const downloadManager = externalServices.createDownloadManager();
  1527. this.downloadManager = downloadManager;
  1528. const findController = new _pdf_find_controller.PDFFindController({
  1529. linkService: pdfLinkService,
  1530. eventBus
  1531. });
  1532. this.findController = findController;
  1533. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  1534. eventBus,
  1535. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  1536. scriptingFactory: externalServices,
  1537. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  1538. });
  1539. this.pdfScriptingManager = pdfScriptingManager;
  1540. const container = appConfig.mainContainer,
  1541. viewer = appConfig.viewerContainer;
  1542. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  1543. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  1544. background: _app_options.AppOptions.get("pageColorsBackground"),
  1545. foreground: _app_options.AppOptions.get("pageColorsForeground")
  1546. } : null;
  1547. this.pdfViewer = new _pdf_viewer.PDFViewer({
  1548. container,
  1549. viewer,
  1550. eventBus,
  1551. renderingQueue: pdfRenderingQueue,
  1552. linkService: pdfLinkService,
  1553. downloadManager,
  1554. findController,
  1555. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  1556. renderer: _app_options.AppOptions.get("renderer"),
  1557. l10n: this.l10n,
  1558. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  1559. annotationMode: _app_options.AppOptions.get("annotationMode"),
  1560. annotationEditorMode,
  1561. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  1562. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  1563. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  1564. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  1565. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  1566. pageColors
  1567. });
  1568. pdfRenderingQueue.setViewer(this.pdfViewer);
  1569. pdfLinkService.setViewer(this.pdfViewer);
  1570. pdfScriptingManager.setViewer(this.pdfViewer);
  1571. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  1572. container: appConfig.sidebar.thumbnailView,
  1573. eventBus,
  1574. renderingQueue: pdfRenderingQueue,
  1575. linkService: pdfLinkService,
  1576. l10n: this.l10n,
  1577. pageColors
  1578. });
  1579. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  1580. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  1581. this.pdfHistory = new _pdf_history.PDFHistory({
  1582. linkService: pdfLinkService,
  1583. eventBus
  1584. });
  1585. pdfLinkService.setHistory(this.pdfHistory);
  1586. }
  1587. if (!this.supportsIntegratedFind) {
  1588. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  1589. }
  1590. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  1591. this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  1592. for (const element of [document.getElementById("editorModeButtons"), document.getElementById("editorModeSeparator")]) {
  1593. element.classList.remove("hidden");
  1594. }
  1595. }
  1596. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
  1597. return this._docFilename;
  1598. });
  1599. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  1600. container,
  1601. eventBus,
  1602. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  1603. });
  1604. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  1605. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus);
  1606. if (this.supportsFullscreen) {
  1607. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  1608. container,
  1609. pdfViewer: this.pdfViewer,
  1610. eventBus
  1611. });
  1612. }
  1613. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  1614. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  1615. container: appConfig.sidebar.outlineView,
  1616. eventBus,
  1617. linkService: pdfLinkService
  1618. });
  1619. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  1620. container: appConfig.sidebar.attachmentsView,
  1621. eventBus,
  1622. downloadManager
  1623. });
  1624. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  1625. container: appConfig.sidebar.layersView,
  1626. eventBus,
  1627. l10n: this.l10n
  1628. });
  1629. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  1630. elements: appConfig.sidebar,
  1631. pdfViewer: this.pdfViewer,
  1632. pdfThumbnailViewer: this.pdfThumbnailViewer,
  1633. eventBus,
  1634. l10n: this.l10n
  1635. });
  1636. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  1637. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  1638. },
  1639. run(config) {
  1640. this.initialize(config).then(webViewerInitialized);
  1641. },
  1642. get initialized() {
  1643. return this._initializedCapability.settled;
  1644. },
  1645. get initializedPromise() {
  1646. return this._initializedCapability.promise;
  1647. },
  1648. zoomIn(steps) {
  1649. if (this.pdfViewer.isInPresentationMode) {
  1650. return;
  1651. }
  1652. this.pdfViewer.increaseScale(steps);
  1653. },
  1654. zoomOut(steps) {
  1655. if (this.pdfViewer.isInPresentationMode) {
  1656. return;
  1657. }
  1658. this.pdfViewer.decreaseScale(steps);
  1659. },
  1660. zoomReset() {
  1661. if (this.pdfViewer.isInPresentationMode) {
  1662. return;
  1663. }
  1664. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1665. },
  1666. get pagesCount() {
  1667. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  1668. },
  1669. get page() {
  1670. return this.pdfViewer.currentPageNumber;
  1671. },
  1672. set page(val) {
  1673. this.pdfViewer.currentPageNumber = val;
  1674. },
  1675. get supportsPrinting() {
  1676. return PDFPrintServiceFactory.instance.supportsPrinting;
  1677. },
  1678. get supportsFullscreen() {
  1679. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  1680. },
  1681. get supportsIntegratedFind() {
  1682. return this.externalServices.supportsIntegratedFind;
  1683. },
  1684. get supportsDocumentFonts() {
  1685. return this.externalServices.supportsDocumentFonts;
  1686. },
  1687. get loadingBar() {
  1688. const bar = new _ui_utils.ProgressBar("loadingBar");
  1689. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  1690. },
  1691. get supportedMouseWheelZoomModifierKeys() {
  1692. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  1693. },
  1694. initPassiveLoading() {
  1695. throw new Error("Not implemented: initPassiveLoading");
  1696. },
  1697. setTitleUsingUrl(url = "", downloadUrl = null) {
  1698. this.url = url;
  1699. this.baseUrl = url.split("#")[0];
  1700. if (downloadUrl) {
  1701. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  1702. }
  1703. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  1704. if (!title) {
  1705. try {
  1706. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  1707. } catch (ex) {
  1708. title = url;
  1709. }
  1710. }
  1711. this.setTitle(title);
  1712. },
  1713. setTitle(title = this._title) {
  1714. this._title = title;
  1715. if (this.isViewerEmbedded) {
  1716. return;
  1717. }
  1718. document.title = `${this._hasAnnotationEditors ? "* " : ""}${title}`;
  1719. },
  1720. get _docFilename() {
  1721. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  1722. },
  1723. _hideViewBookmark() {
  1724. const {
  1725. toolbar,
  1726. secondaryToolbar
  1727. } = this.appConfig;
  1728. toolbar.viewBookmark.hidden = true;
  1729. secondaryToolbar.viewBookmarkButton.hidden = true;
  1730. },
  1731. _cancelIdleCallbacks() {
  1732. if (!this._idleCallbacks.size) {
  1733. return;
  1734. }
  1735. for (const callback of this._idleCallbacks) {
  1736. window.cancelIdleCallback(callback);
  1737. }
  1738. this._idleCallbacks.clear();
  1739. },
  1740. async close() {
  1741. this._unblockDocumentLoadEvent();
  1742. this._hideViewBookmark();
  1743. const {
  1744. container
  1745. } = this.appConfig.errorWrapper;
  1746. container.hidden = true;
  1747. if (!this.pdfLoadingTask) {
  1748. return;
  1749. }
  1750. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  1751. try {
  1752. await this.save();
  1753. } catch (reason) {}
  1754. }
  1755. const promises = [];
  1756. promises.push(this.pdfLoadingTask.destroy());
  1757. this.pdfLoadingTask = null;
  1758. if (this.pdfDocument) {
  1759. this.pdfDocument = null;
  1760. this.pdfThumbnailViewer.setDocument(null);
  1761. this.pdfViewer.setDocument(null);
  1762. this.pdfLinkService.setDocument(null);
  1763. this.pdfDocumentProperties.setDocument(null);
  1764. }
  1765. this.pdfLinkService.externalLinkEnabled = true;
  1766. this.store = null;
  1767. this.isInitialViewSet = false;
  1768. this.downloadComplete = false;
  1769. this.url = "";
  1770. this.baseUrl = "";
  1771. this._downloadUrl = "";
  1772. this.documentInfo = null;
  1773. this.metadata = null;
  1774. this._contentDispositionFilename = null;
  1775. this._contentLength = null;
  1776. this._saveInProgress = false;
  1777. this._docStats = null;
  1778. this._hasAnnotationEditors = false;
  1779. this._cancelIdleCallbacks();
  1780. promises.push(this.pdfScriptingManager.destroyPromise);
  1781. this.setTitle();
  1782. this.pdfSidebar.reset();
  1783. this.pdfOutlineViewer.reset();
  1784. this.pdfAttachmentViewer.reset();
  1785. this.pdfLayerViewer.reset();
  1786. this.pdfHistory?.reset();
  1787. this.findBar?.reset();
  1788. this.toolbar.reset();
  1789. this.secondaryToolbar.reset();
  1790. this._PDFBug?.cleanup();
  1791. await Promise.all(promises);
  1792. },
  1793. async open(file, args) {
  1794. if (this.pdfLoadingTask) {
  1795. await this.close();
  1796. }
  1797. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  1798. for (const key in workerParameters) {
  1799. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  1800. }
  1801. const parameters = Object.create(null);
  1802. if (typeof file === "string") {
  1803. this.setTitleUsingUrl(file, file);
  1804. parameters.url = file;
  1805. } else if (file && "byteLength" in file) {
  1806. parameters.data = file;
  1807. } else if (file.url && file.originalUrl) {
  1808. this.setTitleUsingUrl(file.originalUrl, file.url);
  1809. parameters.url = file.url;
  1810. }
  1811. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  1812. for (const key in apiParameters) {
  1813. let value = apiParameters[key];
  1814. if (key === "docBaseUrl" && !value) {}
  1815. parameters[key] = value;
  1816. }
  1817. if (args) {
  1818. for (const key in args) {
  1819. parameters[key] = args[key];
  1820. }
  1821. }
  1822. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  1823. this.pdfLoadingTask = loadingTask;
  1824. loadingTask.onPassword = (updateCallback, reason) => {
  1825. this.pdfLinkService.externalLinkEnabled = false;
  1826. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  1827. this.passwordPrompt.open();
  1828. };
  1829. loadingTask.onProgress = ({
  1830. loaded,
  1831. total
  1832. }) => {
  1833. this.progress(loaded / total);
  1834. };
  1835. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  1836. return loadingTask.promise.then(pdfDocument => {
  1837. this.load(pdfDocument);
  1838. }, reason => {
  1839. if (loadingTask !== this.pdfLoadingTask) {
  1840. return undefined;
  1841. }
  1842. let key = "loading_error";
  1843. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  1844. key = "invalid_file_error";
  1845. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  1846. key = "missing_file_error";
  1847. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  1848. key = "unexpected_response_error";
  1849. }
  1850. return this.l10n.get(key).then(msg => {
  1851. this._documentError(msg, {
  1852. message: reason?.message
  1853. });
  1854. throw reason;
  1855. });
  1856. });
  1857. },
  1858. _ensureDownloadComplete() {
  1859. if (this.pdfDocument && this.downloadComplete) {
  1860. return;
  1861. }
  1862. throw new Error("PDF document not downloaded.");
  1863. },
  1864. async download() {
  1865. const url = this._downloadUrl,
  1866. filename = this._docFilename;
  1867. try {
  1868. this._ensureDownloadComplete();
  1869. const data = await this.pdfDocument.getData();
  1870. const blob = new Blob([data], {
  1871. type: "application/pdf"
  1872. });
  1873. await this.downloadManager.download(blob, url, filename);
  1874. } catch (reason) {
  1875. await this.downloadManager.downloadUrl(url, filename);
  1876. }
  1877. },
  1878. async save() {
  1879. if (this._saveInProgress) {
  1880. return;
  1881. }
  1882. this._saveInProgress = true;
  1883. await this.pdfScriptingManager.dispatchWillSave();
  1884. const url = this._downloadUrl,
  1885. filename = this._docFilename;
  1886. try {
  1887. this._ensureDownloadComplete();
  1888. const data = await this.pdfDocument.saveDocument();
  1889. const blob = new Blob([data], {
  1890. type: "application/pdf"
  1891. });
  1892. await this.downloadManager.download(blob, url, filename);
  1893. } catch (reason) {
  1894. console.error(`Error when saving the document: ${reason.message}`);
  1895. await this.download();
  1896. } finally {
  1897. await this.pdfScriptingManager.dispatchDidSave();
  1898. this._saveInProgress = false;
  1899. }
  1900. if (this._hasAnnotationEditors) {
  1901. this.externalServices.reportTelemetry({
  1902. type: "editing",
  1903. data: {
  1904. type: "save"
  1905. }
  1906. });
  1907. }
  1908. },
  1909. downloadOrSave() {
  1910. if (this.pdfDocument?.annotationStorage.size > 0) {
  1911. this.save();
  1912. } else {
  1913. this.download();
  1914. }
  1915. },
  1916. fallback(featureId) {
  1917. this.externalServices.reportTelemetry({
  1918. type: "unsupportedFeature",
  1919. featureId
  1920. });
  1921. },
  1922. _documentError(message, moreInfo = null) {
  1923. this._unblockDocumentLoadEvent();
  1924. this._otherError(message, moreInfo);
  1925. this.eventBus.dispatch("documenterror", {
  1926. source: this,
  1927. message,
  1928. reason: moreInfo?.message ?? null
  1929. });
  1930. },
  1931. _otherError(message, moreInfo = null) {
  1932. const moreInfoText = [this.l10n.get("error_version_info", {
  1933. version: _pdfjsLib.version || "?",
  1934. build: _pdfjsLib.build || "?"
  1935. })];
  1936. if (moreInfo) {
  1937. moreInfoText.push(this.l10n.get("error_message", {
  1938. message: moreInfo.message
  1939. }));
  1940. if (moreInfo.stack) {
  1941. moreInfoText.push(this.l10n.get("error_stack", {
  1942. stack: moreInfo.stack
  1943. }));
  1944. } else {
  1945. if (moreInfo.filename) {
  1946. moreInfoText.push(this.l10n.get("error_file", {
  1947. file: moreInfo.filename
  1948. }));
  1949. }
  1950. if (moreInfo.lineNumber) {
  1951. moreInfoText.push(this.l10n.get("error_line", {
  1952. line: moreInfo.lineNumber
  1953. }));
  1954. }
  1955. }
  1956. }
  1957. const errorWrapperConfig = this.appConfig.errorWrapper;
  1958. const errorWrapper = errorWrapperConfig.container;
  1959. errorWrapper.hidden = false;
  1960. const errorMessage = errorWrapperConfig.errorMessage;
  1961. errorMessage.textContent = message;
  1962. const closeButton = errorWrapperConfig.closeButton;
  1963. closeButton.onclick = function () {
  1964. errorWrapper.hidden = true;
  1965. };
  1966. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1967. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1968. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1969. moreInfoButton.onclick = function () {
  1970. errorMoreInfo.hidden = false;
  1971. moreInfoButton.hidden = true;
  1972. lessInfoButton.hidden = false;
  1973. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1974. };
  1975. lessInfoButton.onclick = function () {
  1976. errorMoreInfo.hidden = true;
  1977. moreInfoButton.hidden = false;
  1978. lessInfoButton.hidden = true;
  1979. };
  1980. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1981. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1982. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1983. moreInfoButton.hidden = false;
  1984. lessInfoButton.hidden = true;
  1985. Promise.all(moreInfoText).then(parts => {
  1986. errorMoreInfo.value = parts.join("\n");
  1987. });
  1988. },
  1989. progress(level) {
  1990. if (this.downloadComplete) {
  1991. return;
  1992. }
  1993. const percent = Math.round(level * 100);
  1994. if (percent <= this.loadingBar.percent) {
  1995. return;
  1996. }
  1997. this.loadingBar.percent = percent;
  1998. const disableAutoFetch = this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch");
  1999. if (!disableAutoFetch || isNaN(percent)) {
  2000. return;
  2001. }
  2002. if (this.disableAutoFetchLoadingBarTimeout) {
  2003. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  2004. this.disableAutoFetchLoadingBarTimeout = null;
  2005. }
  2006. this.loadingBar.show();
  2007. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  2008. this.loadingBar.hide();
  2009. this.disableAutoFetchLoadingBarTimeout = null;
  2010. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  2011. },
  2012. load(pdfDocument) {
  2013. this.pdfDocument = pdfDocument;
  2014. pdfDocument.getDownloadInfo().then(({
  2015. length
  2016. }) => {
  2017. this._contentLength = length;
  2018. this.downloadComplete = true;
  2019. this.loadingBar.hide();
  2020. firstPagePromise.then(() => {
  2021. this.eventBus.dispatch("documentloaded", {
  2022. source: this
  2023. });
  2024. });
  2025. });
  2026. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  2027. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  2028. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  2029. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  2030. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  2031. let baseDocumentUrl;
  2032. baseDocumentUrl = null;
  2033. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  2034. this.pdfDocumentProperties.setDocument(pdfDocument);
  2035. const pdfViewer = this.pdfViewer;
  2036. pdfViewer.setDocument(pdfDocument);
  2037. const {
  2038. firstPagePromise,
  2039. onePageRendered,
  2040. pagesPromise
  2041. } = pdfViewer;
  2042. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  2043. pdfThumbnailViewer.setDocument(pdfDocument);
  2044. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  2045. page: null,
  2046. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  2047. scrollLeft: "0",
  2048. scrollTop: "0",
  2049. rotation: null,
  2050. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  2051. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  2052. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  2053. }).catch(() => {
  2054. return Object.create(null);
  2055. });
  2056. firstPagePromise.then(pdfPage => {
  2057. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  2058. this._initializeAnnotationStorageCallbacks(pdfDocument);
  2059. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  2060. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  2061. this._initializePdfHistory({
  2062. fingerprint: pdfDocument.fingerprints[0],
  2063. viewOnLoad,
  2064. initialDest: openAction?.dest
  2065. });
  2066. const initialBookmark = this.initialBookmark;
  2067. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  2068. let hash = zoom ? `zoom=${zoom}` : null;
  2069. let rotation = null;
  2070. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  2071. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  2072. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  2073. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  2074. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  2075. rotation = parseInt(stored.rotation, 10);
  2076. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2077. sidebarView = stored.sidebarView | 0;
  2078. }
  2079. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  2080. scrollMode = stored.scrollMode | 0;
  2081. }
  2082. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2083. spreadMode = stored.spreadMode | 0;
  2084. }
  2085. }
  2086. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2087. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  2088. }
  2089. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2090. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  2091. spreadMode = modes.spreadMode;
  2092. }
  2093. this.setInitialView(hash, {
  2094. rotation,
  2095. sidebarView,
  2096. scrollMode,
  2097. spreadMode
  2098. });
  2099. this.eventBus.dispatch("documentinit", {
  2100. source: this
  2101. });
  2102. if (!this.isViewerEmbedded) {
  2103. pdfViewer.focus();
  2104. }
  2105. await Promise.race([pagesPromise, new Promise(resolve => {
  2106. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  2107. })]);
  2108. if (!initialBookmark && !hash) {
  2109. return;
  2110. }
  2111. if (pdfViewer.hasEqualPageSizes) {
  2112. return;
  2113. }
  2114. this.initialBookmark = initialBookmark;
  2115. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  2116. this.setInitialView(hash);
  2117. }).catch(() => {
  2118. this.setInitialView();
  2119. }).then(function () {
  2120. pdfViewer.update();
  2121. });
  2122. });
  2123. pagesPromise.then(() => {
  2124. this._unblockDocumentLoadEvent();
  2125. this._initializeAutoPrint(pdfDocument, openActionPromise);
  2126. }, reason => {
  2127. this.l10n.get("loading_error").then(msg => {
  2128. this._documentError(msg, {
  2129. message: reason?.message
  2130. });
  2131. });
  2132. });
  2133. onePageRendered.then(data => {
  2134. this.externalServices.reportTelemetry({
  2135. type: "pageInfo",
  2136. timestamp: data.timestamp
  2137. });
  2138. pdfDocument.getOutline().then(outline => {
  2139. if (pdfDocument !== this.pdfDocument) {
  2140. return;
  2141. }
  2142. this.pdfOutlineViewer.render({
  2143. outline,
  2144. pdfDocument
  2145. });
  2146. });
  2147. pdfDocument.getAttachments().then(attachments => {
  2148. if (pdfDocument !== this.pdfDocument) {
  2149. return;
  2150. }
  2151. this.pdfAttachmentViewer.render({
  2152. attachments
  2153. });
  2154. });
  2155. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  2156. if (pdfDocument !== this.pdfDocument) {
  2157. return;
  2158. }
  2159. this.pdfLayerViewer.render({
  2160. optionalContentConfig,
  2161. pdfDocument
  2162. });
  2163. });
  2164. if ("requestIdleCallback" in window) {
  2165. const callback = window.requestIdleCallback(() => {
  2166. this._collectTelemetry(pdfDocument);
  2167. this._idleCallbacks.delete(callback);
  2168. }, {
  2169. timeout: 1000
  2170. });
  2171. this._idleCallbacks.add(callback);
  2172. }
  2173. });
  2174. this._initializePageLabels(pdfDocument);
  2175. this._initializeMetadata(pdfDocument);
  2176. },
  2177. async _scriptingDocProperties(pdfDocument) {
  2178. if (!this.documentInfo) {
  2179. await new Promise(resolve => {
  2180. this.eventBus._on("metadataloaded", resolve, {
  2181. once: true
  2182. });
  2183. });
  2184. if (pdfDocument !== this.pdfDocument) {
  2185. return null;
  2186. }
  2187. }
  2188. if (!this._contentLength) {
  2189. await new Promise(resolve => {
  2190. this.eventBus._on("documentloaded", resolve, {
  2191. once: true
  2192. });
  2193. });
  2194. if (pdfDocument !== this.pdfDocument) {
  2195. return null;
  2196. }
  2197. }
  2198. return { ...this.documentInfo,
  2199. baseURL: this.baseUrl,
  2200. filesize: this._contentLength,
  2201. filename: this._docFilename,
  2202. metadata: this.metadata?.getRaw(),
  2203. authors: this.metadata?.get("dc:creator"),
  2204. numPages: this.pagesCount,
  2205. URL: this.url
  2206. };
  2207. },
  2208. async _collectTelemetry(pdfDocument) {
  2209. const markInfo = await this.pdfDocument.getMarkInfo();
  2210. if (pdfDocument !== this.pdfDocument) {
  2211. return;
  2212. }
  2213. const tagged = markInfo?.Marked || false;
  2214. this.externalServices.reportTelemetry({
  2215. type: "tagged",
  2216. tagged
  2217. });
  2218. },
  2219. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  2220. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  2221. if (pdfDocument !== this.pdfDocument) {
  2222. return;
  2223. }
  2224. let triggerAutoPrint = false;
  2225. if (openAction?.action === "Print") {
  2226. triggerAutoPrint = true;
  2227. }
  2228. if (javaScript) {
  2229. javaScript.some(js => {
  2230. if (!js) {
  2231. return false;
  2232. }
  2233. console.warn("Warning: JavaScript support is not enabled");
  2234. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  2235. return true;
  2236. });
  2237. if (!triggerAutoPrint) {
  2238. for (const js of javaScript) {
  2239. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  2240. triggerAutoPrint = true;
  2241. break;
  2242. }
  2243. }
  2244. }
  2245. }
  2246. if (triggerAutoPrint) {
  2247. this.triggerPrinting();
  2248. }
  2249. },
  2250. async _initializeMetadata(pdfDocument) {
  2251. const {
  2252. info,
  2253. metadata,
  2254. contentDispositionFilename,
  2255. contentLength
  2256. } = await pdfDocument.getMetadata();
  2257. if (pdfDocument !== this.pdfDocument) {
  2258. return;
  2259. }
  2260. this.documentInfo = info;
  2261. this.metadata = metadata;
  2262. this._contentDispositionFilename ??= contentDispositionFilename;
  2263. this._contentLength ??= contentLength;
  2264. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"})`);
  2265. let pdfTitle = info.Title;
  2266. const metadataTitle = metadata?.get("dc:title");
  2267. if (metadataTitle) {
  2268. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  2269. pdfTitle = metadataTitle;
  2270. }
  2271. }
  2272. if (pdfTitle) {
  2273. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  2274. } else if (this._contentDispositionFilename) {
  2275. this.setTitle(this._contentDispositionFilename);
  2276. }
  2277. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  2278. if (pdfDocument.loadingParams.enableXfa) {
  2279. console.warn("Warning: XFA Foreground documents are not supported");
  2280. } else {
  2281. console.warn("Warning: XFA support is not enabled");
  2282. }
  2283. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  2284. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  2285. console.warn("Warning: Interactive form support is not enabled");
  2286. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  2287. }
  2288. if (info.IsSignaturesPresent) {
  2289. console.warn("Warning: Digital signatures validation is not supported");
  2290. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  2291. }
  2292. let versionId = "other";
  2293. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  2294. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  2295. }
  2296. let generatorId = "other";
  2297. if (info.Producer) {
  2298. const producer = info.Producer.toLowerCase();
  2299. KNOWN_GENERATORS.some(function (generator) {
  2300. if (!producer.includes(generator)) {
  2301. return false;
  2302. }
  2303. generatorId = generator.replace(/[ .-]/g, "_");
  2304. return true;
  2305. });
  2306. }
  2307. let formType = null;
  2308. if (info.IsXFAPresent) {
  2309. formType = "xfa";
  2310. } else if (info.IsAcroFormPresent) {
  2311. formType = "acroform";
  2312. }
  2313. this.externalServices.reportTelemetry({
  2314. type: "documentInfo",
  2315. version: versionId,
  2316. generator: generatorId,
  2317. formType
  2318. });
  2319. this.eventBus.dispatch("metadataloaded", {
  2320. source: this
  2321. });
  2322. },
  2323. async _initializePageLabels(pdfDocument) {
  2324. const labels = await pdfDocument.getPageLabels();
  2325. if (pdfDocument !== this.pdfDocument) {
  2326. return;
  2327. }
  2328. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  2329. return;
  2330. }
  2331. const numLabels = labels.length;
  2332. let standardLabels = 0,
  2333. emptyLabels = 0;
  2334. for (let i = 0; i < numLabels; i++) {
  2335. const label = labels[i];
  2336. if (label === (i + 1).toString()) {
  2337. standardLabels++;
  2338. } else if (label === "") {
  2339. emptyLabels++;
  2340. } else {
  2341. break;
  2342. }
  2343. }
  2344. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  2345. return;
  2346. }
  2347. const {
  2348. pdfViewer,
  2349. pdfThumbnailViewer,
  2350. toolbar
  2351. } = this;
  2352. pdfViewer.setPageLabels(labels);
  2353. pdfThumbnailViewer.setPageLabels(labels);
  2354. toolbar.setPagesCount(numLabels, true);
  2355. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2356. },
  2357. _initializePdfHistory({
  2358. fingerprint,
  2359. viewOnLoad,
  2360. initialDest = null
  2361. }) {
  2362. if (!this.pdfHistory) {
  2363. return;
  2364. }
  2365. this.pdfHistory.initialize({
  2366. fingerprint,
  2367. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  2368. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  2369. });
  2370. if (this.pdfHistory.initialBookmark) {
  2371. this.initialBookmark = this.pdfHistory.initialBookmark;
  2372. this.initialRotation = this.pdfHistory.initialRotation;
  2373. }
  2374. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  2375. this.initialBookmark = JSON.stringify(initialDest);
  2376. this.pdfHistory.push({
  2377. explicitDest: initialDest,
  2378. pageNumber: null
  2379. });
  2380. }
  2381. },
  2382. _initializeAnnotationStorageCallbacks(pdfDocument) {
  2383. if (pdfDocument !== this.pdfDocument) {
  2384. return;
  2385. }
  2386. const {
  2387. annotationStorage
  2388. } = pdfDocument;
  2389. annotationStorage.onSetModified = () => {
  2390. window.addEventListener("beforeunload", beforeUnload);
  2391. this._annotationStorageModified = true;
  2392. };
  2393. annotationStorage.onResetModified = () => {
  2394. window.removeEventListener("beforeunload", beforeUnload);
  2395. delete this._annotationStorageModified;
  2396. };
  2397. annotationStorage.onAnnotationEditor = typeStr => {
  2398. this._hasAnnotationEditors = !!typeStr;
  2399. this.setTitle();
  2400. if (typeStr) {
  2401. this.externalServices.reportTelemetry({
  2402. type: "editing",
  2403. data: {
  2404. type: typeStr
  2405. }
  2406. });
  2407. }
  2408. };
  2409. },
  2410. setInitialView(storedHash, {
  2411. rotation,
  2412. sidebarView,
  2413. scrollMode,
  2414. spreadMode
  2415. } = {}) {
  2416. const setRotation = angle => {
  2417. if ((0, _ui_utils.isValidRotation)(angle)) {
  2418. this.pdfViewer.pagesRotation = angle;
  2419. }
  2420. };
  2421. const setViewerModes = (scroll, spread) => {
  2422. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  2423. this.pdfViewer.scrollMode = scroll;
  2424. }
  2425. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  2426. this.pdfViewer.spreadMode = spread;
  2427. }
  2428. };
  2429. this.isInitialViewSet = true;
  2430. this.pdfSidebar.setInitialView(sidebarView);
  2431. setViewerModes(scrollMode, spreadMode);
  2432. if (this.initialBookmark) {
  2433. setRotation(this.initialRotation);
  2434. delete this.initialRotation;
  2435. this.pdfLinkService.setHash(this.initialBookmark);
  2436. this.initialBookmark = null;
  2437. } else if (storedHash) {
  2438. setRotation(rotation);
  2439. this.pdfLinkService.setHash(storedHash);
  2440. }
  2441. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  2442. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  2443. if (!this.pdfViewer.currentScaleValue) {
  2444. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2445. }
  2446. },
  2447. _cleanup() {
  2448. if (!this.pdfDocument) {
  2449. return;
  2450. }
  2451. this.pdfViewer.cleanup();
  2452. this.pdfThumbnailViewer.cleanup();
  2453. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  2454. },
  2455. forceRendering() {
  2456. this.pdfRenderingQueue.printing = !!this.printService;
  2457. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS;
  2458. this.pdfRenderingQueue.renderHighestPriority();
  2459. },
  2460. beforePrint() {
  2461. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => {
  2462. return this.pdfDocument?.annotationStorage.print;
  2463. });
  2464. if (this.printService) {
  2465. return;
  2466. }
  2467. if (!this.supportsPrinting) {
  2468. this.l10n.get("printing_not_supported").then(msg => {
  2469. this._otherError(msg);
  2470. });
  2471. return;
  2472. }
  2473. if (!this.pdfViewer.pageViewsReady) {
  2474. this.l10n.get("printing_not_ready").then(msg => {
  2475. window.alert(msg);
  2476. });
  2477. return;
  2478. }
  2479. const pagesOverview = this.pdfViewer.getPagesOverview();
  2480. const printContainer = this.appConfig.printContainer;
  2481. const printResolution = _app_options.AppOptions.get("printResolution");
  2482. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  2483. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  2484. this.printService = printService;
  2485. this.forceRendering();
  2486. printService.layout();
  2487. this.externalServices.reportTelemetry({
  2488. type: "print"
  2489. });
  2490. if (this._hasAnnotationEditors) {
  2491. this.externalServices.reportTelemetry({
  2492. type: "editing",
  2493. data: {
  2494. type: "print"
  2495. }
  2496. });
  2497. }
  2498. },
  2499. afterPrint() {
  2500. if (this._printAnnotationStoragePromise) {
  2501. this._printAnnotationStoragePromise.then(() => {
  2502. this.pdfScriptingManager.dispatchDidPrint();
  2503. });
  2504. this._printAnnotationStoragePromise = null;
  2505. }
  2506. if (this.printService) {
  2507. this.printService.destroy();
  2508. this.printService = null;
  2509. this.pdfDocument?.annotationStorage.resetModified();
  2510. }
  2511. this.forceRendering();
  2512. },
  2513. rotatePages(delta) {
  2514. this.pdfViewer.pagesRotation += delta;
  2515. },
  2516. requestPresentationMode() {
  2517. this.pdfPresentationMode?.request();
  2518. },
  2519. triggerPrinting() {
  2520. if (!this.supportsPrinting) {
  2521. return;
  2522. }
  2523. window.print();
  2524. },
  2525. bindEvents() {
  2526. const {
  2527. eventBus,
  2528. _boundEvents
  2529. } = this;
  2530. _boundEvents.beforePrint = this.beforePrint.bind(this);
  2531. _boundEvents.afterPrint = this.afterPrint.bind(this);
  2532. eventBus._on("resize", webViewerResize);
  2533. eventBus._on("hashchange", webViewerHashchange);
  2534. eventBus._on("beforeprint", _boundEvents.beforePrint);
  2535. eventBus._on("afterprint", _boundEvents.afterPrint);
  2536. eventBus._on("pagerendered", webViewerPageRendered);
  2537. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  2538. eventBus._on("pagechanging", webViewerPageChanging);
  2539. eventBus._on("scalechanging", webViewerScaleChanging);
  2540. eventBus._on("rotationchanging", webViewerRotationChanging);
  2541. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  2542. eventBus._on("pagemode", webViewerPageMode);
  2543. eventBus._on("namedaction", webViewerNamedAction);
  2544. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  2545. eventBus._on("presentationmode", webViewerPresentationMode);
  2546. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  2547. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  2548. eventBus._on("print", webViewerPrint);
  2549. eventBus._on("download", webViewerDownload);
  2550. eventBus._on("firstpage", webViewerFirstPage);
  2551. eventBus._on("lastpage", webViewerLastPage);
  2552. eventBus._on("nextpage", webViewerNextPage);
  2553. eventBus._on("previouspage", webViewerPreviousPage);
  2554. eventBus._on("zoomin", webViewerZoomIn);
  2555. eventBus._on("zoomout", webViewerZoomOut);
  2556. eventBus._on("zoomreset", webViewerZoomReset);
  2557. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  2558. eventBus._on("scalechanged", webViewerScaleChanged);
  2559. eventBus._on("rotatecw", webViewerRotateCw);
  2560. eventBus._on("rotateccw", webViewerRotateCcw);
  2561. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  2562. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  2563. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  2564. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  2565. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  2566. eventBus._on("documentproperties", webViewerDocumentProperties);
  2567. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  2568. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2569. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  2570. if (_app_options.AppOptions.get("pdfBug")) {
  2571. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  2572. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2573. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2574. }
  2575. eventBus._on("fileinputchange", webViewerFileInputChange);
  2576. eventBus._on("openfile", webViewerOpenFile);
  2577. },
  2578. bindWindowEvents() {
  2579. const {
  2580. eventBus,
  2581. _boundEvents
  2582. } = this;
  2583. function addWindowResolutionChange(evt = null) {
  2584. if (evt) {
  2585. webViewerResolutionChange(evt);
  2586. }
  2587. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  2588. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  2589. once: true
  2590. });
  2591. _boundEvents.removeWindowResolutionChange ||= function () {
  2592. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  2593. _boundEvents.removeWindowResolutionChange = null;
  2594. };
  2595. }
  2596. addWindowResolutionChange();
  2597. _boundEvents.windowResize = () => {
  2598. eventBus.dispatch("resize", {
  2599. source: window
  2600. });
  2601. };
  2602. _boundEvents.windowHashChange = () => {
  2603. eventBus.dispatch("hashchange", {
  2604. source: window,
  2605. hash: document.location.hash.substring(1)
  2606. });
  2607. };
  2608. _boundEvents.windowBeforePrint = () => {
  2609. eventBus.dispatch("beforeprint", {
  2610. source: window
  2611. });
  2612. };
  2613. _boundEvents.windowAfterPrint = () => {
  2614. eventBus.dispatch("afterprint", {
  2615. source: window
  2616. });
  2617. };
  2618. _boundEvents.windowUpdateFromSandbox = event => {
  2619. eventBus.dispatch("updatefromsandbox", {
  2620. source: window,
  2621. detail: event.detail
  2622. });
  2623. };
  2624. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  2625. window.addEventListener("wheel", webViewerWheel, {
  2626. passive: false
  2627. });
  2628. window.addEventListener("touchstart", webViewerTouchStart, {
  2629. passive: false
  2630. });
  2631. window.addEventListener("click", webViewerClick);
  2632. window.addEventListener("keydown", webViewerKeyDown);
  2633. window.addEventListener("resize", _boundEvents.windowResize);
  2634. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  2635. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2636. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  2637. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2638. },
  2639. unbindEvents() {
  2640. const {
  2641. eventBus,
  2642. _boundEvents
  2643. } = this;
  2644. eventBus._off("resize", webViewerResize);
  2645. eventBus._off("hashchange", webViewerHashchange);
  2646. eventBus._off("beforeprint", _boundEvents.beforePrint);
  2647. eventBus._off("afterprint", _boundEvents.afterPrint);
  2648. eventBus._off("pagerendered", webViewerPageRendered);
  2649. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  2650. eventBus._off("pagechanging", webViewerPageChanging);
  2651. eventBus._off("scalechanging", webViewerScaleChanging);
  2652. eventBus._off("rotationchanging", webViewerRotationChanging);
  2653. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  2654. eventBus._off("pagemode", webViewerPageMode);
  2655. eventBus._off("namedaction", webViewerNamedAction);
  2656. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  2657. eventBus._off("presentationmode", webViewerPresentationMode);
  2658. eventBus._off("print", webViewerPrint);
  2659. eventBus._off("download", webViewerDownload);
  2660. eventBus._off("firstpage", webViewerFirstPage);
  2661. eventBus._off("lastpage", webViewerLastPage);
  2662. eventBus._off("nextpage", webViewerNextPage);
  2663. eventBus._off("previouspage", webViewerPreviousPage);
  2664. eventBus._off("zoomin", webViewerZoomIn);
  2665. eventBus._off("zoomout", webViewerZoomOut);
  2666. eventBus._off("zoomreset", webViewerZoomReset);
  2667. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  2668. eventBus._off("scalechanged", webViewerScaleChanged);
  2669. eventBus._off("rotatecw", webViewerRotateCw);
  2670. eventBus._off("rotateccw", webViewerRotateCcw);
  2671. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  2672. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  2673. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  2674. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  2675. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  2676. eventBus._off("documentproperties", webViewerDocumentProperties);
  2677. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  2678. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2679. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  2680. if (_boundEvents.reportPageStatsPDFBug) {
  2681. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2682. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2683. _boundEvents.reportPageStatsPDFBug = null;
  2684. }
  2685. eventBus._off("fileinputchange", webViewerFileInputChange);
  2686. eventBus._off("openfile", webViewerOpenFile);
  2687. _boundEvents.beforePrint = null;
  2688. _boundEvents.afterPrint = null;
  2689. },
  2690. unbindWindowEvents() {
  2691. const {
  2692. _boundEvents
  2693. } = this;
  2694. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  2695. window.removeEventListener("wheel", webViewerWheel, {
  2696. passive: false
  2697. });
  2698. window.removeEventListener("touchstart", webViewerTouchStart, {
  2699. passive: false
  2700. });
  2701. window.removeEventListener("click", webViewerClick);
  2702. window.removeEventListener("keydown", webViewerKeyDown);
  2703. window.removeEventListener("resize", _boundEvents.windowResize);
  2704. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  2705. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2706. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  2707. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2708. _boundEvents.removeWindowResolutionChange?.();
  2709. _boundEvents.windowResize = null;
  2710. _boundEvents.windowHashChange = null;
  2711. _boundEvents.windowBeforePrint = null;
  2712. _boundEvents.windowAfterPrint = null;
  2713. _boundEvents.windowUpdateFromSandbox = null;
  2714. },
  2715. accumulateWheelTicks(ticks) {
  2716. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  2717. this._wheelUnusedTicks = 0;
  2718. }
  2719. this._wheelUnusedTicks += ticks;
  2720. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  2721. this._wheelUnusedTicks -= wholeTicks;
  2722. return wholeTicks;
  2723. },
  2724. _unblockDocumentLoadEvent() {
  2725. document.blockUnblockOnload?.(false);
  2726. this._unblockDocumentLoadEvent = () => {};
  2727. },
  2728. _reportDocumentStatsTelemetry() {
  2729. const {
  2730. stats
  2731. } = this.pdfDocument;
  2732. if (stats !== this._docStats) {
  2733. this._docStats = stats;
  2734. this.externalServices.reportTelemetry({
  2735. type: "documentStats",
  2736. stats
  2737. });
  2738. }
  2739. },
  2740. get scriptingReady() {
  2741. return this.pdfScriptingManager.ready;
  2742. }
  2743. };
  2744. exports.PDFViewerApplication = PDFViewerApplication;
  2745. let validateFileURL;
  2746. {
  2747. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  2748. validateFileURL = function (file) {
  2749. if (!file) {
  2750. return;
  2751. }
  2752. try {
  2753. const viewerOrigin = new URL(window.location.href).origin || "null";
  2754. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  2755. return;
  2756. }
  2757. const fileOrigin = new URL(file, window.location.href).origin;
  2758. if (fileOrigin !== viewerOrigin) {
  2759. throw new Error("file origin does not match viewer's");
  2760. }
  2761. } catch (ex) {
  2762. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2763. PDFViewerApplication._documentError(msg, {
  2764. message: ex?.message
  2765. });
  2766. });
  2767. throw ex;
  2768. }
  2769. };
  2770. }
  2771. async function loadFakeWorker() {
  2772. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  2773. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  2774. }
  2775. async function loadPDFBug(self) {
  2776. const {
  2777. debuggerScriptPath
  2778. } = self.appConfig;
  2779. const {
  2780. PDFBug
  2781. } = await import(debuggerScriptPath);
  2782. self._PDFBug = PDFBug;
  2783. }
  2784. function reportPageStatsPDFBug({
  2785. pageNumber
  2786. }) {
  2787. if (!globalThis.Stats?.enabled) {
  2788. return;
  2789. }
  2790. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2791. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  2792. }
  2793. function webViewerInitialized() {
  2794. const {
  2795. appConfig,
  2796. eventBus
  2797. } = PDFViewerApplication;
  2798. let file;
  2799. const queryString = document.location.search.substring(1);
  2800. const params = (0, _ui_utils.parseQueryString)(queryString);
  2801. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  2802. validateFileURL(file);
  2803. const fileInput = appConfig.openFileInput;
  2804. fileInput.value = null;
  2805. fileInput.addEventListener("change", function (evt) {
  2806. const {
  2807. files
  2808. } = evt.target;
  2809. if (!files || files.length === 0) {
  2810. return;
  2811. }
  2812. eventBus.dispatch("fileinputchange", {
  2813. source: this,
  2814. fileInput: evt.target
  2815. });
  2816. });
  2817. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  2818. evt.preventDefault();
  2819. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  2820. });
  2821. appConfig.mainContainer.addEventListener("drop", function (evt) {
  2822. evt.preventDefault();
  2823. const {
  2824. files
  2825. } = evt.dataTransfer;
  2826. if (!files || files.length === 0) {
  2827. return;
  2828. }
  2829. eventBus.dispatch("fileinputchange", {
  2830. source: this,
  2831. fileInput: evt.dataTransfer
  2832. });
  2833. });
  2834. if (!PDFViewerApplication.supportsDocumentFonts) {
  2835. _app_options.AppOptions.set("disableFontFace", true);
  2836. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  2837. console.warn(msg);
  2838. });
  2839. }
  2840. if (!PDFViewerApplication.supportsPrinting) {
  2841. appConfig.toolbar.print.classList.add("hidden");
  2842. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  2843. }
  2844. if (!PDFViewerApplication.supportsFullscreen) {
  2845. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  2846. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  2847. }
  2848. if (PDFViewerApplication.supportsIntegratedFind) {
  2849. appConfig.toolbar.viewFind.classList.add("hidden");
  2850. }
  2851. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  2852. if (evt.target === this) {
  2853. eventBus.dispatch("resize", {
  2854. source: this
  2855. });
  2856. }
  2857. }, true);
  2858. try {
  2859. if (file) {
  2860. PDFViewerApplication.open(file);
  2861. } else {
  2862. PDFViewerApplication._hideViewBookmark();
  2863. }
  2864. } catch (reason) {
  2865. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2866. PDFViewerApplication._documentError(msg, reason);
  2867. });
  2868. }
  2869. }
  2870. function webViewerPageRendered({
  2871. pageNumber,
  2872. error
  2873. }) {
  2874. if (pageNumber === PDFViewerApplication.page) {
  2875. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  2876. }
  2877. if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
  2878. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2879. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  2880. if (pageView && thumbnailView) {
  2881. thumbnailView.setImage(pageView);
  2882. }
  2883. }
  2884. if (error) {
  2885. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  2886. PDFViewerApplication._otherError(msg, error);
  2887. });
  2888. }
  2889. PDFViewerApplication._reportDocumentStatsTelemetry();
  2890. }
  2891. function webViewerPageMode({
  2892. mode
  2893. }) {
  2894. let view;
  2895. switch (mode) {
  2896. case "thumbs":
  2897. view = _ui_utils.SidebarView.THUMBS;
  2898. break;
  2899. case "bookmarks":
  2900. case "outline":
  2901. view = _ui_utils.SidebarView.OUTLINE;
  2902. break;
  2903. case "attachments":
  2904. view = _ui_utils.SidebarView.ATTACHMENTS;
  2905. break;
  2906. case "layers":
  2907. view = _ui_utils.SidebarView.LAYERS;
  2908. break;
  2909. case "none":
  2910. view = _ui_utils.SidebarView.NONE;
  2911. break;
  2912. default:
  2913. console.error('Invalid "pagemode" hash parameter: ' + mode);
  2914. return;
  2915. }
  2916. PDFViewerApplication.pdfSidebar.switchView(view, true);
  2917. }
  2918. function webViewerNamedAction(evt) {
  2919. switch (evt.action) {
  2920. case "GoToPage":
  2921. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2922. break;
  2923. case "Find":
  2924. if (!PDFViewerApplication.supportsIntegratedFind) {
  2925. PDFViewerApplication.findBar.toggle();
  2926. }
  2927. break;
  2928. case "Print":
  2929. PDFViewerApplication.triggerPrinting();
  2930. break;
  2931. case "SaveAs":
  2932. PDFViewerApplication.downloadOrSave();
  2933. break;
  2934. }
  2935. }
  2936. function webViewerPresentationModeChanged(evt) {
  2937. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  2938. }
  2939. function webViewerSidebarViewChanged({
  2940. view
  2941. }) {
  2942. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  2943. if (PDFViewerApplication.isInitialViewSet) {
  2944. PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
  2945. }
  2946. }
  2947. function webViewerUpdateViewarea({
  2948. location
  2949. }) {
  2950. if (PDFViewerApplication.isInitialViewSet) {
  2951. PDFViewerApplication.store?.setMultiple({
  2952. page: location.pageNumber,
  2953. zoom: location.scale,
  2954. scrollLeft: location.left,
  2955. scrollTop: location.top,
  2956. rotation: location.rotation
  2957. }).catch(() => {});
  2958. }
  2959. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  2960. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  2961. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  2962. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  2963. const loading = currentPage?.renderingState !== _ui_utils.RenderingStates.FINISHED;
  2964. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  2965. }
  2966. function webViewerScrollModeChanged(evt) {
  2967. if (PDFViewerApplication.isInitialViewSet) {
  2968. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  2969. }
  2970. }
  2971. function webViewerSpreadModeChanged(evt) {
  2972. if (PDFViewerApplication.isInitialViewSet) {
  2973. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  2974. }
  2975. }
  2976. function webViewerResize() {
  2977. const {
  2978. pdfDocument,
  2979. pdfViewer,
  2980. pdfRenderingQueue
  2981. } = PDFViewerApplication;
  2982. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  2983. return;
  2984. }
  2985. pdfViewer.updateContainerHeightCss();
  2986. if (!pdfDocument) {
  2987. return;
  2988. }
  2989. const currentScaleValue = pdfViewer.currentScaleValue;
  2990. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  2991. pdfViewer.currentScaleValue = currentScaleValue;
  2992. }
  2993. pdfViewer.update();
  2994. }
  2995. function webViewerHashchange(evt) {
  2996. const hash = evt.hash;
  2997. if (!hash) {
  2998. return;
  2999. }
  3000. if (!PDFViewerApplication.isInitialViewSet) {
  3001. PDFViewerApplication.initialBookmark = hash;
  3002. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  3003. PDFViewerApplication.pdfLinkService.setHash(hash);
  3004. }
  3005. }
  3006. {
  3007. var webViewerFileInputChange = function (evt) {
  3008. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  3009. return;
  3010. }
  3011. const file = evt.fileInput.files[0];
  3012. let url = URL.createObjectURL(file);
  3013. if (file.name) {
  3014. url = {
  3015. url,
  3016. originalUrl: file.name
  3017. };
  3018. }
  3019. PDFViewerApplication.open(url);
  3020. };
  3021. var webViewerOpenFile = function (evt) {
  3022. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  3023. fileInput.click();
  3024. };
  3025. }
  3026. function webViewerPresentationMode() {
  3027. PDFViewerApplication.requestPresentationMode();
  3028. }
  3029. function webViewerSwitchAnnotationEditorMode(evt) {
  3030. PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
  3031. }
  3032. function webViewerSwitchAnnotationEditorParams(evt) {
  3033. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  3034. }
  3035. function webViewerPrint() {
  3036. PDFViewerApplication.triggerPrinting();
  3037. }
  3038. function webViewerDownload() {
  3039. PDFViewerApplication.downloadOrSave();
  3040. }
  3041. function webViewerFirstPage() {
  3042. if (PDFViewerApplication.pdfDocument) {
  3043. PDFViewerApplication.page = 1;
  3044. }
  3045. }
  3046. function webViewerLastPage() {
  3047. if (PDFViewerApplication.pdfDocument) {
  3048. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3049. }
  3050. }
  3051. function webViewerNextPage() {
  3052. PDFViewerApplication.pdfViewer.nextPage();
  3053. }
  3054. function webViewerPreviousPage() {
  3055. PDFViewerApplication.pdfViewer.previousPage();
  3056. }
  3057. function webViewerZoomIn() {
  3058. PDFViewerApplication.zoomIn();
  3059. }
  3060. function webViewerZoomOut() {
  3061. PDFViewerApplication.zoomOut();
  3062. }
  3063. function webViewerZoomReset() {
  3064. PDFViewerApplication.zoomReset();
  3065. }
  3066. function webViewerPageNumberChanged(evt) {
  3067. const pdfViewer = PDFViewerApplication.pdfViewer;
  3068. if (evt.value !== "") {
  3069. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  3070. }
  3071. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  3072. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  3073. }
  3074. }
  3075. function webViewerScaleChanged(evt) {
  3076. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  3077. }
  3078. function webViewerRotateCw() {
  3079. PDFViewerApplication.rotatePages(90);
  3080. }
  3081. function webViewerRotateCcw() {
  3082. PDFViewerApplication.rotatePages(-90);
  3083. }
  3084. function webViewerOptionalContentConfig(evt) {
  3085. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  3086. }
  3087. function webViewerSwitchScrollMode(evt) {
  3088. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  3089. }
  3090. function webViewerSwitchSpreadMode(evt) {
  3091. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  3092. }
  3093. function webViewerDocumentProperties() {
  3094. PDFViewerApplication.pdfDocumentProperties.open();
  3095. }
  3096. function webViewerFindFromUrlHash(evt) {
  3097. PDFViewerApplication.eventBus.dispatch("find", {
  3098. source: evt.source,
  3099. type: "",
  3100. query: evt.query,
  3101. phraseSearch: evt.phraseSearch,
  3102. caseSensitive: false,
  3103. entireWord: false,
  3104. highlightAll: true,
  3105. findPrevious: false,
  3106. matchDiacritics: true
  3107. });
  3108. }
  3109. function webViewerUpdateFindMatchesCount({
  3110. matchesCount
  3111. }) {
  3112. if (PDFViewerApplication.supportsIntegratedFind) {
  3113. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  3114. } else {
  3115. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  3116. }
  3117. }
  3118. function webViewerUpdateFindControlState({
  3119. state,
  3120. previous,
  3121. matchesCount,
  3122. rawQuery
  3123. }) {
  3124. if (PDFViewerApplication.supportsIntegratedFind) {
  3125. PDFViewerApplication.externalServices.updateFindControlState({
  3126. result: state,
  3127. findPrevious: previous,
  3128. matchesCount,
  3129. rawQuery
  3130. });
  3131. } else {
  3132. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  3133. }
  3134. }
  3135. function webViewerScaleChanging(evt) {
  3136. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  3137. PDFViewerApplication.pdfViewer.update();
  3138. }
  3139. function webViewerRotationChanging(evt) {
  3140. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  3141. PDFViewerApplication.forceRendering();
  3142. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  3143. }
  3144. function webViewerPageChanging({
  3145. pageNumber,
  3146. pageLabel
  3147. }) {
  3148. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  3149. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  3150. if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
  3151. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  3152. }
  3153. }
  3154. function webViewerResolutionChange(evt) {
  3155. PDFViewerApplication.pdfViewer.refresh();
  3156. }
  3157. function webViewerVisibilityChange(evt) {
  3158. if (document.visibilityState === "visible") {
  3159. setZoomDisabledTimeout();
  3160. }
  3161. }
  3162. let zoomDisabledTimeout = null;
  3163. function setZoomDisabledTimeout() {
  3164. if (zoomDisabledTimeout) {
  3165. clearTimeout(zoomDisabledTimeout);
  3166. }
  3167. zoomDisabledTimeout = setTimeout(function () {
  3168. zoomDisabledTimeout = null;
  3169. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  3170. }
  3171. function webViewerWheel(evt) {
  3172. const {
  3173. pdfViewer,
  3174. supportedMouseWheelZoomModifierKeys
  3175. } = PDFViewerApplication;
  3176. if (pdfViewer.isInPresentationMode) {
  3177. return;
  3178. }
  3179. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  3180. evt.preventDefault();
  3181. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  3182. return;
  3183. }
  3184. const deltaMode = evt.deltaMode;
  3185. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  3186. const previousScale = pdfViewer.currentScale;
  3187. let ticks = 0;
  3188. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  3189. if (Math.abs(delta) >= 1) {
  3190. ticks = Math.sign(delta);
  3191. } else {
  3192. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  3193. }
  3194. } else {
  3195. const PIXELS_PER_LINE_SCALE = 30;
  3196. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  3197. }
  3198. if (ticks < 0) {
  3199. PDFViewerApplication.zoomOut(-ticks);
  3200. } else if (ticks > 0) {
  3201. PDFViewerApplication.zoomIn(ticks);
  3202. }
  3203. const currentScale = pdfViewer.currentScale;
  3204. if (previousScale !== currentScale) {
  3205. const scaleCorrectionFactor = currentScale / previousScale - 1;
  3206. const rect = pdfViewer.container.getBoundingClientRect();
  3207. const dx = evt.clientX - rect.left;
  3208. const dy = evt.clientY - rect.top;
  3209. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  3210. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  3211. }
  3212. } else {
  3213. setZoomDisabledTimeout();
  3214. }
  3215. }
  3216. function webViewerTouchStart(evt) {
  3217. if (evt.touches.length > 1) {
  3218. evt.preventDefault();
  3219. }
  3220. }
  3221. function webViewerClick(evt) {
  3222. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  3223. return;
  3224. }
  3225. const appConfig = PDFViewerApplication.appConfig;
  3226. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  3227. PDFViewerApplication.secondaryToolbar.close();
  3228. }
  3229. }
  3230. function webViewerKeyDown(evt) {
  3231. if (PDFViewerApplication.overlayManager.active) {
  3232. return;
  3233. }
  3234. const {
  3235. eventBus,
  3236. pdfViewer
  3237. } = PDFViewerApplication;
  3238. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  3239. let handled = false,
  3240. ensureViewerFocused = false;
  3241. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  3242. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  3243. switch (evt.keyCode) {
  3244. case 70:
  3245. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  3246. PDFViewerApplication.findBar.open();
  3247. handled = true;
  3248. }
  3249. break;
  3250. case 71:
  3251. if (!PDFViewerApplication.supportsIntegratedFind) {
  3252. const {
  3253. state
  3254. } = PDFViewerApplication.findController;
  3255. if (state) {
  3256. const eventState = Object.assign(Object.create(null), state, {
  3257. source: window,
  3258. type: "again",
  3259. findPrevious: cmd === 5 || cmd === 12
  3260. });
  3261. eventBus.dispatch("find", eventState);
  3262. }
  3263. handled = true;
  3264. }
  3265. break;
  3266. case 61:
  3267. case 107:
  3268. case 187:
  3269. case 171:
  3270. if (!isViewerInPresentationMode) {
  3271. PDFViewerApplication.zoomIn();
  3272. }
  3273. handled = true;
  3274. break;
  3275. case 173:
  3276. case 109:
  3277. case 189:
  3278. if (!isViewerInPresentationMode) {
  3279. PDFViewerApplication.zoomOut();
  3280. }
  3281. handled = true;
  3282. break;
  3283. case 48:
  3284. case 96:
  3285. if (!isViewerInPresentationMode) {
  3286. setTimeout(function () {
  3287. PDFViewerApplication.zoomReset();
  3288. });
  3289. handled = false;
  3290. }
  3291. break;
  3292. case 38:
  3293. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3294. PDFViewerApplication.page = 1;
  3295. handled = true;
  3296. ensureViewerFocused = true;
  3297. }
  3298. break;
  3299. case 40:
  3300. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3301. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3302. handled = true;
  3303. ensureViewerFocused = true;
  3304. }
  3305. break;
  3306. }
  3307. }
  3308. if (cmd === 1 || cmd === 8) {
  3309. switch (evt.keyCode) {
  3310. case 83:
  3311. eventBus.dispatch("download", {
  3312. source: window
  3313. });
  3314. handled = true;
  3315. break;
  3316. case 79:
  3317. {
  3318. eventBus.dispatch("openfile", {
  3319. source: window
  3320. });
  3321. handled = true;
  3322. }
  3323. break;
  3324. }
  3325. }
  3326. if (cmd === 3 || cmd === 10) {
  3327. switch (evt.keyCode) {
  3328. case 80:
  3329. PDFViewerApplication.requestPresentationMode();
  3330. handled = true;
  3331. break;
  3332. case 71:
  3333. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  3334. handled = true;
  3335. break;
  3336. }
  3337. }
  3338. if (handled) {
  3339. if (ensureViewerFocused && !isViewerInPresentationMode) {
  3340. pdfViewer.focus();
  3341. }
  3342. evt.preventDefault();
  3343. return;
  3344. }
  3345. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  3346. const curElementTagName = curElement?.tagName.toUpperCase();
  3347. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  3348. if (evt.keyCode !== 27) {
  3349. return;
  3350. }
  3351. }
  3352. if (cmd === 0) {
  3353. let turnPage = 0,
  3354. turnOnlyIfPageFit = false;
  3355. switch (evt.keyCode) {
  3356. case 38:
  3357. case 33:
  3358. if (pdfViewer.isVerticalScrollbarEnabled) {
  3359. turnOnlyIfPageFit = true;
  3360. }
  3361. turnPage = -1;
  3362. break;
  3363. case 8:
  3364. if (!isViewerInPresentationMode) {
  3365. turnOnlyIfPageFit = true;
  3366. }
  3367. turnPage = -1;
  3368. break;
  3369. case 37:
  3370. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3371. turnOnlyIfPageFit = true;
  3372. }
  3373. case 75:
  3374. case 80:
  3375. turnPage = -1;
  3376. break;
  3377. case 27:
  3378. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  3379. PDFViewerApplication.secondaryToolbar.close();
  3380. handled = true;
  3381. }
  3382. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  3383. PDFViewerApplication.findBar.close();
  3384. handled = true;
  3385. }
  3386. break;
  3387. case 40:
  3388. case 34:
  3389. if (pdfViewer.isVerticalScrollbarEnabled) {
  3390. turnOnlyIfPageFit = true;
  3391. }
  3392. turnPage = 1;
  3393. break;
  3394. case 13:
  3395. case 32:
  3396. if (!isViewerInPresentationMode) {
  3397. turnOnlyIfPageFit = true;
  3398. }
  3399. turnPage = 1;
  3400. break;
  3401. case 39:
  3402. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3403. turnOnlyIfPageFit = true;
  3404. }
  3405. case 74:
  3406. case 78:
  3407. turnPage = 1;
  3408. break;
  3409. case 36:
  3410. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3411. PDFViewerApplication.page = 1;
  3412. handled = true;
  3413. ensureViewerFocused = true;
  3414. }
  3415. break;
  3416. case 35:
  3417. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3418. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3419. handled = true;
  3420. ensureViewerFocused = true;
  3421. }
  3422. break;
  3423. case 83:
  3424. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  3425. break;
  3426. case 72:
  3427. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  3428. break;
  3429. case 82:
  3430. PDFViewerApplication.rotatePages(90);
  3431. break;
  3432. case 115:
  3433. PDFViewerApplication.pdfSidebar.toggle();
  3434. break;
  3435. }
  3436. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  3437. if (turnPage > 0) {
  3438. pdfViewer.nextPage();
  3439. } else {
  3440. pdfViewer.previousPage();
  3441. }
  3442. handled = true;
  3443. }
  3444. }
  3445. if (cmd === 4) {
  3446. switch (evt.keyCode) {
  3447. case 13:
  3448. case 32:
  3449. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  3450. break;
  3451. }
  3452. pdfViewer.previousPage();
  3453. handled = true;
  3454. break;
  3455. case 82:
  3456. PDFViewerApplication.rotatePages(-90);
  3457. break;
  3458. }
  3459. }
  3460. if (!handled && !isViewerInPresentationMode) {
  3461. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  3462. ensureViewerFocused = true;
  3463. }
  3464. }
  3465. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  3466. pdfViewer.focus();
  3467. }
  3468. if (handled) {
  3469. evt.preventDefault();
  3470. }
  3471. }
  3472. function beforeUnload(evt) {
  3473. evt.preventDefault();
  3474. evt.returnValue = "";
  3475. return false;
  3476. }
  3477. function webViewerAnnotationEditorStatesChanged(data) {
  3478. PDFViewerApplication.externalServices.updateEditorStates(data);
  3479. }
  3480. const PDFPrintServiceFactory = {
  3481. instance: {
  3482. supportsPrinting: false,
  3483. createPrintService() {
  3484. throw new Error("Not implemented: createPrintService");
  3485. }
  3486. }
  3487. };
  3488. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  3489. /***/ }),
  3490. /* 5 */
  3491. /***/ ((module) => {
  3492. let pdfjsLib;
  3493. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3494. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3495. } else {
  3496. pdfjsLib = require("../build/pdf.js");
  3497. }
  3498. module.exports = pdfjsLib;
  3499. /***/ }),
  3500. /* 6 */
  3501. /***/ ((__unused_webpack_module, exports) => {
  3502. Object.defineProperty(exports, "__esModule", ({
  3503. value: true
  3504. }));
  3505. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3506. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3507. const WaitOnType = {
  3508. EVENT: "event",
  3509. TIMEOUT: "timeout"
  3510. };
  3511. exports.WaitOnType = WaitOnType;
  3512. function waitOnEventOrTimeout({
  3513. target,
  3514. name,
  3515. delay = 0
  3516. }) {
  3517. return new Promise(function (resolve, reject) {
  3518. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3519. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3520. }
  3521. function handler(type) {
  3522. if (target instanceof EventBus) {
  3523. target._off(name, eventHandler);
  3524. } else {
  3525. target.removeEventListener(name, eventHandler);
  3526. }
  3527. if (timeout) {
  3528. clearTimeout(timeout);
  3529. }
  3530. resolve(type);
  3531. }
  3532. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3533. if (target instanceof EventBus) {
  3534. target._on(name, eventHandler);
  3535. } else {
  3536. target.addEventListener(name, eventHandler);
  3537. }
  3538. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3539. const timeout = setTimeout(timeoutHandler, delay);
  3540. });
  3541. }
  3542. class EventBus {
  3543. constructor() {
  3544. this._listeners = Object.create(null);
  3545. }
  3546. on(eventName, listener, options = null) {
  3547. this._on(eventName, listener, {
  3548. external: true,
  3549. once: options?.once
  3550. });
  3551. }
  3552. off(eventName, listener, options = null) {
  3553. this._off(eventName, listener, {
  3554. external: true,
  3555. once: options?.once
  3556. });
  3557. }
  3558. dispatch(eventName, data) {
  3559. const eventListeners = this._listeners[eventName];
  3560. if (!eventListeners || eventListeners.length === 0) {
  3561. return;
  3562. }
  3563. let externalListeners;
  3564. for (const {
  3565. listener,
  3566. external,
  3567. once
  3568. } of eventListeners.slice(0)) {
  3569. if (once) {
  3570. this._off(eventName, listener);
  3571. }
  3572. if (external) {
  3573. (externalListeners ||= []).push(listener);
  3574. continue;
  3575. }
  3576. listener(data);
  3577. }
  3578. if (externalListeners) {
  3579. for (const listener of externalListeners) {
  3580. listener(data);
  3581. }
  3582. externalListeners = null;
  3583. }
  3584. }
  3585. _on(eventName, listener, options = null) {
  3586. const eventListeners = this._listeners[eventName] ||= [];
  3587. eventListeners.push({
  3588. listener,
  3589. external: options?.external === true,
  3590. once: options?.once === true
  3591. });
  3592. }
  3593. _off(eventName, listener, options = null) {
  3594. const eventListeners = this._listeners[eventName];
  3595. if (!eventListeners) {
  3596. return;
  3597. }
  3598. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3599. if (eventListeners[i].listener === listener) {
  3600. eventListeners.splice(i, 1);
  3601. return;
  3602. }
  3603. }
  3604. }
  3605. }
  3606. exports.EventBus = EventBus;
  3607. class AutomationEventBus extends EventBus {
  3608. dispatch(eventName, data) {
  3609. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3610. }
  3611. }
  3612. exports.AutomationEventBus = AutomationEventBus;
  3613. /***/ }),
  3614. /* 7 */
  3615. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3616. Object.defineProperty(exports, "__esModule", ({
  3617. value: true
  3618. }));
  3619. exports.PDFCursorTools = exports.CursorTool = void 0;
  3620. var _grab_to_pan = __webpack_require__(8);
  3621. var _ui_utils = __webpack_require__(1);
  3622. const CursorTool = {
  3623. SELECT: 0,
  3624. HAND: 1,
  3625. ZOOM: 2
  3626. };
  3627. exports.CursorTool = CursorTool;
  3628. class PDFCursorTools {
  3629. constructor({
  3630. container,
  3631. eventBus,
  3632. cursorToolOnLoad = CursorTool.SELECT
  3633. }) {
  3634. this.container = container;
  3635. this.eventBus = eventBus;
  3636. this.active = CursorTool.SELECT;
  3637. this.activeBeforePresentationMode = null;
  3638. this.handTool = new _grab_to_pan.GrabToPan({
  3639. element: this.container
  3640. });
  3641. this.#addEventListeners();
  3642. Promise.resolve().then(() => {
  3643. this.switchTool(cursorToolOnLoad);
  3644. });
  3645. }
  3646. get activeTool() {
  3647. return this.active;
  3648. }
  3649. switchTool(tool) {
  3650. if (this.activeBeforePresentationMode !== null) {
  3651. return;
  3652. }
  3653. if (tool === this.active) {
  3654. return;
  3655. }
  3656. const disableActiveTool = () => {
  3657. switch (this.active) {
  3658. case CursorTool.SELECT:
  3659. break;
  3660. case CursorTool.HAND:
  3661. this.handTool.deactivate();
  3662. break;
  3663. case CursorTool.ZOOM:
  3664. }
  3665. };
  3666. switch (tool) {
  3667. case CursorTool.SELECT:
  3668. disableActiveTool();
  3669. break;
  3670. case CursorTool.HAND:
  3671. disableActiveTool();
  3672. this.handTool.activate();
  3673. break;
  3674. case CursorTool.ZOOM:
  3675. default:
  3676. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3677. return;
  3678. }
  3679. this.active = tool;
  3680. this.#dispatchEvent();
  3681. }
  3682. #dispatchEvent() {
  3683. this.eventBus.dispatch("cursortoolchanged", {
  3684. source: this,
  3685. tool: this.active
  3686. });
  3687. }
  3688. #addEventListeners() {
  3689. this.eventBus._on("switchcursortool", evt => {
  3690. this.switchTool(evt.tool);
  3691. });
  3692. this.eventBus._on("presentationmodechanged", evt => {
  3693. switch (evt.state) {
  3694. case _ui_utils.PresentationModeState.FULLSCREEN:
  3695. {
  3696. const previouslyActive = this.active;
  3697. this.switchTool(CursorTool.SELECT);
  3698. this.activeBeforePresentationMode = previouslyActive;
  3699. break;
  3700. }
  3701. case _ui_utils.PresentationModeState.NORMAL:
  3702. {
  3703. const previouslyActive = this.activeBeforePresentationMode;
  3704. this.activeBeforePresentationMode = null;
  3705. this.switchTool(previouslyActive);
  3706. break;
  3707. }
  3708. }
  3709. });
  3710. }
  3711. }
  3712. exports.PDFCursorTools = PDFCursorTools;
  3713. /***/ }),
  3714. /* 8 */
  3715. /***/ ((__unused_webpack_module, exports) => {
  3716. Object.defineProperty(exports, "__esModule", ({
  3717. value: true
  3718. }));
  3719. exports.GrabToPan = void 0;
  3720. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3721. class GrabToPan {
  3722. constructor(options) {
  3723. this.element = options.element;
  3724. this.document = options.element.ownerDocument;
  3725. if (typeof options.ignoreTarget === "function") {
  3726. this.ignoreTarget = options.ignoreTarget;
  3727. }
  3728. this.onActiveChanged = options.onActiveChanged;
  3729. this.activate = this.activate.bind(this);
  3730. this.deactivate = this.deactivate.bind(this);
  3731. this.toggle = this.toggle.bind(this);
  3732. this._onMouseDown = this.#onMouseDown.bind(this);
  3733. this._onMouseMove = this.#onMouseMove.bind(this);
  3734. this._endPan = this.#endPan.bind(this);
  3735. const overlay = this.overlay = document.createElement("div");
  3736. overlay.className = "grab-to-pan-grabbing";
  3737. }
  3738. activate() {
  3739. if (!this.active) {
  3740. this.active = true;
  3741. this.element.addEventListener("mousedown", this._onMouseDown, true);
  3742. this.element.classList.add(CSS_CLASS_GRAB);
  3743. this.onActiveChanged?.(true);
  3744. }
  3745. }
  3746. deactivate() {
  3747. if (this.active) {
  3748. this.active = false;
  3749. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  3750. this._endPan();
  3751. this.element.classList.remove(CSS_CLASS_GRAB);
  3752. this.onActiveChanged?.(false);
  3753. }
  3754. }
  3755. toggle() {
  3756. if (this.active) {
  3757. this.deactivate();
  3758. } else {
  3759. this.activate();
  3760. }
  3761. }
  3762. ignoreTarget(node) {
  3763. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3764. }
  3765. #onMouseDown(event) {
  3766. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3767. return;
  3768. }
  3769. if (event.originalTarget) {
  3770. try {
  3771. event.originalTarget.tagName;
  3772. } catch (e) {
  3773. return;
  3774. }
  3775. }
  3776. this.scrollLeftStart = this.element.scrollLeft;
  3777. this.scrollTopStart = this.element.scrollTop;
  3778. this.clientXStart = event.clientX;
  3779. this.clientYStart = event.clientY;
  3780. this.document.addEventListener("mousemove", this._onMouseMove, true);
  3781. this.document.addEventListener("mouseup", this._endPan, true);
  3782. this.element.addEventListener("scroll", this._endPan, true);
  3783. event.preventDefault();
  3784. event.stopPropagation();
  3785. const focusedElement = document.activeElement;
  3786. if (focusedElement && !focusedElement.contains(event.target)) {
  3787. focusedElement.blur();
  3788. }
  3789. }
  3790. #onMouseMove(event) {
  3791. this.element.removeEventListener("scroll", this._endPan, true);
  3792. if (!(event.buttons & 1)) {
  3793. this._endPan();
  3794. return;
  3795. }
  3796. const xDiff = event.clientX - this.clientXStart;
  3797. const yDiff = event.clientY - this.clientYStart;
  3798. const scrollTop = this.scrollTopStart - yDiff;
  3799. const scrollLeft = this.scrollLeftStart - xDiff;
  3800. if (this.element.scrollTo) {
  3801. this.element.scrollTo({
  3802. top: scrollTop,
  3803. left: scrollLeft,
  3804. behavior: "instant"
  3805. });
  3806. } else {
  3807. this.element.scrollTop = scrollTop;
  3808. this.element.scrollLeft = scrollLeft;
  3809. }
  3810. if (!this.overlay.parentNode) {
  3811. document.body.append(this.overlay);
  3812. }
  3813. }
  3814. #endPan() {
  3815. this.element.removeEventListener("scroll", this._endPan, true);
  3816. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  3817. this.document.removeEventListener("mouseup", this._endPan, true);
  3818. this.overlay.remove();
  3819. }
  3820. }
  3821. exports.GrabToPan = GrabToPan;
  3822. /***/ }),
  3823. /* 9 */
  3824. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3825. Object.defineProperty(exports, "__esModule", ({
  3826. value: true
  3827. }));
  3828. exports.AnnotationEditorParams = void 0;
  3829. var _pdfjsLib = __webpack_require__(5);
  3830. class AnnotationEditorParams {
  3831. constructor(options, eventBus) {
  3832. this.eventBus = eventBus;
  3833. this.#bindListeners(options);
  3834. }
  3835. #bindListeners({
  3836. editorFreeTextFontSize,
  3837. editorFreeTextColor,
  3838. editorInkColor,
  3839. editorInkThickness,
  3840. editorInkOpacity
  3841. }) {
  3842. editorFreeTextFontSize.addEventListener("input", evt => {
  3843. this.eventBus.dispatch("switchannotationeditorparams", {
  3844. source: this,
  3845. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE,
  3846. value: editorFreeTextFontSize.valueAsNumber
  3847. });
  3848. });
  3849. editorFreeTextColor.addEventListener("input", evt => {
  3850. this.eventBus.dispatch("switchannotationeditorparams", {
  3851. source: this,
  3852. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR,
  3853. value: editorFreeTextColor.value
  3854. });
  3855. });
  3856. editorInkColor.addEventListener("input", evt => {
  3857. this.eventBus.dispatch("switchannotationeditorparams", {
  3858. source: this,
  3859. type: _pdfjsLib.AnnotationEditorParamsType.INK_COLOR,
  3860. value: editorInkColor.value
  3861. });
  3862. });
  3863. editorInkThickness.addEventListener("input", evt => {
  3864. this.eventBus.dispatch("switchannotationeditorparams", {
  3865. source: this,
  3866. type: _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS,
  3867. value: editorInkThickness.valueAsNumber
  3868. });
  3869. });
  3870. editorInkOpacity.addEventListener("input", evt => {
  3871. this.eventBus.dispatch("switchannotationeditorparams", {
  3872. source: this,
  3873. type: _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY,
  3874. value: editorInkOpacity.valueAsNumber
  3875. });
  3876. });
  3877. this.eventBus._on("annotationeditorparamschanged", evt => {
  3878. for (const [type, value] of evt.details) {
  3879. switch (type) {
  3880. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  3881. editorFreeTextFontSize.value = value;
  3882. break;
  3883. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  3884. editorFreeTextColor.value = value;
  3885. break;
  3886. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  3887. editorInkColor.value = value;
  3888. break;
  3889. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  3890. editorInkThickness.value = value;
  3891. break;
  3892. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  3893. editorInkOpacity.value = value;
  3894. break;
  3895. }
  3896. }
  3897. });
  3898. }
  3899. }
  3900. exports.AnnotationEditorParams = AnnotationEditorParams;
  3901. /***/ }),
  3902. /* 10 */
  3903. /***/ ((__unused_webpack_module, exports) => {
  3904. Object.defineProperty(exports, "__esModule", ({
  3905. value: true
  3906. }));
  3907. exports.OverlayManager = void 0;
  3908. class OverlayManager {
  3909. #overlays = new WeakMap();
  3910. #active = null;
  3911. get active() {
  3912. return this.#active;
  3913. }
  3914. async register(dialog, canForceClose = false) {
  3915. if (typeof dialog !== "object") {
  3916. throw new Error("Not enough parameters.");
  3917. } else if (this.#overlays.has(dialog)) {
  3918. throw new Error("The overlay is already registered.");
  3919. }
  3920. this.#overlays.set(dialog, {
  3921. canForceClose
  3922. });
  3923. dialog.addEventListener("cancel", evt => {
  3924. this.#active = null;
  3925. });
  3926. }
  3927. async unregister(dialog) {
  3928. if (!this.#overlays.has(dialog)) {
  3929. throw new Error("The overlay does not exist.");
  3930. } else if (this.#active === dialog) {
  3931. throw new Error("The overlay cannot be removed while it is active.");
  3932. }
  3933. this.#overlays.delete(dialog);
  3934. }
  3935. async open(dialog) {
  3936. if (!this.#overlays.has(dialog)) {
  3937. throw new Error("The overlay does not exist.");
  3938. } else if (this.#active) {
  3939. if (this.#active === dialog) {
  3940. throw new Error("The overlay is already active.");
  3941. } else if (this.#overlays.get(dialog).canForceClose) {
  3942. await this.close();
  3943. } else {
  3944. throw new Error("Another overlay is currently active.");
  3945. }
  3946. }
  3947. this.#active = dialog;
  3948. dialog.showModal();
  3949. }
  3950. async close(dialog = this.#active) {
  3951. if (!this.#overlays.has(dialog)) {
  3952. throw new Error("The overlay does not exist.");
  3953. } else if (!this.#active) {
  3954. throw new Error("The overlay is currently not active.");
  3955. } else if (this.#active !== dialog) {
  3956. throw new Error("Another overlay is currently active.");
  3957. }
  3958. dialog.close();
  3959. this.#active = null;
  3960. }
  3961. }
  3962. exports.OverlayManager = OverlayManager;
  3963. /***/ }),
  3964. /* 11 */
  3965. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3966. Object.defineProperty(exports, "__esModule", ({
  3967. value: true
  3968. }));
  3969. exports.PasswordPrompt = void 0;
  3970. var _pdfjsLib = __webpack_require__(5);
  3971. class PasswordPrompt {
  3972. #activeCapability = null;
  3973. #updateCallback = null;
  3974. #reason = null;
  3975. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3976. this.dialog = options.dialog;
  3977. this.label = options.label;
  3978. this.input = options.input;
  3979. this.submitButton = options.submitButton;
  3980. this.cancelButton = options.cancelButton;
  3981. this.overlayManager = overlayManager;
  3982. this.l10n = l10n;
  3983. this._isViewerEmbedded = isViewerEmbedded;
  3984. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3985. this.cancelButton.addEventListener("click", this.close.bind(this));
  3986. this.input.addEventListener("keydown", e => {
  3987. if (e.keyCode === 13) {
  3988. this.#verify();
  3989. }
  3990. });
  3991. this.overlayManager.register(this.dialog, true);
  3992. this.dialog.addEventListener("close", this.#cancel.bind(this));
  3993. }
  3994. async open() {
  3995. if (this.#activeCapability) {
  3996. await this.#activeCapability.promise;
  3997. }
  3998. this.#activeCapability = (0, _pdfjsLib.createPromiseCapability)();
  3999. try {
  4000. await this.overlayManager.open(this.dialog);
  4001. } catch (ex) {
  4002. this.#activeCapability = null;
  4003. throw ex;
  4004. }
  4005. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  4006. if (!this._isViewerEmbedded || passwordIncorrect) {
  4007. this.input.focus();
  4008. }
  4009. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  4010. }
  4011. async close() {
  4012. if (this.overlayManager.active === this.dialog) {
  4013. this.overlayManager.close(this.dialog);
  4014. }
  4015. }
  4016. #verify() {
  4017. const password = this.input.value;
  4018. if (password?.length > 0) {
  4019. this.#invokeCallback(password);
  4020. }
  4021. }
  4022. #cancel() {
  4023. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  4024. this.#activeCapability.resolve();
  4025. }
  4026. #invokeCallback(password) {
  4027. if (!this.#updateCallback) {
  4028. return;
  4029. }
  4030. this.close();
  4031. this.input.value = "";
  4032. this.#updateCallback(password);
  4033. this.#updateCallback = null;
  4034. }
  4035. async setUpdateCallback(updateCallback, reason) {
  4036. if (this.#activeCapability) {
  4037. await this.#activeCapability.promise;
  4038. }
  4039. this.#updateCallback = updateCallback;
  4040. this.#reason = reason;
  4041. }
  4042. }
  4043. exports.PasswordPrompt = PasswordPrompt;
  4044. /***/ }),
  4045. /* 12 */
  4046. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4047. Object.defineProperty(exports, "__esModule", ({
  4048. value: true
  4049. }));
  4050. exports.PDFAttachmentViewer = void 0;
  4051. var _pdfjsLib = __webpack_require__(5);
  4052. var _base_tree_viewer = __webpack_require__(13);
  4053. var _event_utils = __webpack_require__(6);
  4054. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4055. constructor(options) {
  4056. super(options);
  4057. this.downloadManager = options.downloadManager;
  4058. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  4059. }
  4060. reset(keepRenderedCapability = false) {
  4061. super.reset();
  4062. this._attachments = null;
  4063. if (!keepRenderedCapability) {
  4064. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4065. }
  4066. this._pendingDispatchEvent = false;
  4067. }
  4068. async _dispatchEvent(attachmentsCount) {
  4069. this._renderedCapability.resolve();
  4070. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4071. this._pendingDispatchEvent = true;
  4072. await (0, _event_utils.waitOnEventOrTimeout)({
  4073. target: this.eventBus,
  4074. name: "annotationlayerrendered",
  4075. delay: 1000
  4076. });
  4077. if (!this._pendingDispatchEvent) {
  4078. return;
  4079. }
  4080. }
  4081. this._pendingDispatchEvent = false;
  4082. this.eventBus.dispatch("attachmentsloaded", {
  4083. source: this,
  4084. attachmentsCount
  4085. });
  4086. }
  4087. _bindLink(element, {
  4088. content,
  4089. filename
  4090. }) {
  4091. element.onclick = () => {
  4092. this.downloadManager.openOrDownloadData(element, content, filename);
  4093. return false;
  4094. };
  4095. }
  4096. render({
  4097. attachments,
  4098. keepRenderedCapability = false
  4099. }) {
  4100. if (this._attachments) {
  4101. this.reset(keepRenderedCapability);
  4102. }
  4103. this._attachments = attachments || null;
  4104. if (!attachments) {
  4105. this._dispatchEvent(0);
  4106. return;
  4107. }
  4108. const names = Object.keys(attachments).sort(function (a, b) {
  4109. return a.toLowerCase().localeCompare(b.toLowerCase());
  4110. });
  4111. const fragment = document.createDocumentFragment();
  4112. let attachmentsCount = 0;
  4113. for (const name of names) {
  4114. const item = attachments[name];
  4115. const content = item.content,
  4116. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  4117. const div = document.createElement("div");
  4118. div.className = "treeItem";
  4119. const element = document.createElement("a");
  4120. this._bindLink(element, {
  4121. content,
  4122. filename
  4123. });
  4124. element.textContent = this._normalizeTextContent(filename);
  4125. div.append(element);
  4126. fragment.append(div);
  4127. attachmentsCount++;
  4128. }
  4129. this._finishRendering(fragment, attachmentsCount);
  4130. }
  4131. #appendAttachment({
  4132. filename,
  4133. content
  4134. }) {
  4135. const renderedPromise = this._renderedCapability.promise;
  4136. renderedPromise.then(() => {
  4137. if (renderedPromise !== this._renderedCapability.promise) {
  4138. return;
  4139. }
  4140. const attachments = this._attachments || Object.create(null);
  4141. for (const name in attachments) {
  4142. if (filename === name) {
  4143. return;
  4144. }
  4145. }
  4146. attachments[filename] = {
  4147. filename,
  4148. content
  4149. };
  4150. this.render({
  4151. attachments,
  4152. keepRenderedCapability: true
  4153. });
  4154. });
  4155. }
  4156. }
  4157. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4158. /***/ }),
  4159. /* 13 */
  4160. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4161. Object.defineProperty(exports, "__esModule", ({
  4162. value: true
  4163. }));
  4164. exports.BaseTreeViewer = void 0;
  4165. var _ui_utils = __webpack_require__(1);
  4166. const TREEITEM_OFFSET_TOP = -100;
  4167. const TREEITEM_SELECTED_CLASS = "selected";
  4168. class BaseTreeViewer {
  4169. constructor(options) {
  4170. if (this.constructor === BaseTreeViewer) {
  4171. throw new Error("Cannot initialize BaseTreeViewer.");
  4172. }
  4173. this.container = options.container;
  4174. this.eventBus = options.eventBus;
  4175. this.reset();
  4176. }
  4177. reset() {
  4178. this._pdfDocument = null;
  4179. this._lastToggleIsShow = true;
  4180. this._currentTreeItem = null;
  4181. this.container.textContent = "";
  4182. this.container.classList.remove("treeWithDeepNesting");
  4183. }
  4184. _dispatchEvent(count) {
  4185. throw new Error("Not implemented: _dispatchEvent");
  4186. }
  4187. _bindLink(element, params) {
  4188. throw new Error("Not implemented: _bindLink");
  4189. }
  4190. _normalizeTextContent(str) {
  4191. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4192. }
  4193. _addToggleButton(div, hidden = false) {
  4194. const toggler = document.createElement("div");
  4195. toggler.className = "treeItemToggler";
  4196. if (hidden) {
  4197. toggler.classList.add("treeItemsHidden");
  4198. }
  4199. toggler.onclick = evt => {
  4200. evt.stopPropagation();
  4201. toggler.classList.toggle("treeItemsHidden");
  4202. if (evt.shiftKey) {
  4203. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4204. this._toggleTreeItem(div, shouldShowAll);
  4205. }
  4206. };
  4207. div.prepend(toggler);
  4208. }
  4209. _toggleTreeItem(root, show = false) {
  4210. this._lastToggleIsShow = show;
  4211. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4212. toggler.classList.toggle("treeItemsHidden", !show);
  4213. }
  4214. }
  4215. _toggleAllTreeItems() {
  4216. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4217. }
  4218. _finishRendering(fragment, count, hasAnyNesting = false) {
  4219. if (hasAnyNesting) {
  4220. this.container.classList.add("treeWithDeepNesting");
  4221. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4222. }
  4223. this.container.append(fragment);
  4224. this._dispatchEvent(count);
  4225. }
  4226. render(params) {
  4227. throw new Error("Not implemented: render");
  4228. }
  4229. _updateCurrentTreeItem(treeItem = null) {
  4230. if (this._currentTreeItem) {
  4231. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4232. this._currentTreeItem = null;
  4233. }
  4234. if (treeItem) {
  4235. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4236. this._currentTreeItem = treeItem;
  4237. }
  4238. }
  4239. _scrollToCurrentTreeItem(treeItem) {
  4240. if (!treeItem) {
  4241. return;
  4242. }
  4243. let currentNode = treeItem.parentNode;
  4244. while (currentNode && currentNode !== this.container) {
  4245. if (currentNode.classList.contains("treeItem")) {
  4246. const toggler = currentNode.firstElementChild;
  4247. toggler?.classList.remove("treeItemsHidden");
  4248. }
  4249. currentNode = currentNode.parentNode;
  4250. }
  4251. this._updateCurrentTreeItem(treeItem);
  4252. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4253. }
  4254. }
  4255. exports.BaseTreeViewer = BaseTreeViewer;
  4256. /***/ }),
  4257. /* 14 */
  4258. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4259. Object.defineProperty(exports, "__esModule", ({
  4260. value: true
  4261. }));
  4262. exports.PDFDocumentProperties = void 0;
  4263. var _pdfjsLib = __webpack_require__(5);
  4264. var _ui_utils = __webpack_require__(1);
  4265. const DEFAULT_FIELD_CONTENT = "-";
  4266. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4267. const US_PAGE_NAMES = {
  4268. "8.5x11": "Letter",
  4269. "8.5x14": "Legal"
  4270. };
  4271. const METRIC_PAGE_NAMES = {
  4272. "297x420": "A3",
  4273. "210x297": "A4"
  4274. };
  4275. function getPageName(size, isPortrait, pageNames) {
  4276. const width = isPortrait ? size.width : size.height;
  4277. const height = isPortrait ? size.height : size.width;
  4278. return pageNames[`${width}x${height}`];
  4279. }
  4280. class PDFDocumentProperties {
  4281. #fieldData = null;
  4282. constructor({
  4283. dialog,
  4284. fields,
  4285. closeButton
  4286. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4287. this.dialog = dialog;
  4288. this.fields = fields;
  4289. this.overlayManager = overlayManager;
  4290. this.l10n = l10n;
  4291. this._fileNameLookup = fileNameLookup;
  4292. this.#reset();
  4293. closeButton.addEventListener("click", this.close.bind(this));
  4294. this.overlayManager.register(this.dialog);
  4295. eventBus._on("pagechanging", evt => {
  4296. this._currentPageNumber = evt.pageNumber;
  4297. });
  4298. eventBus._on("rotationchanging", evt => {
  4299. this._pagesRotation = evt.pagesRotation;
  4300. });
  4301. this._isNonMetricLocale = true;
  4302. l10n.getLanguage().then(locale => {
  4303. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4304. });
  4305. }
  4306. async open() {
  4307. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4308. const currentPageNumber = this._currentPageNumber;
  4309. const pagesRotation = this._pagesRotation;
  4310. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4311. this.#updateUI();
  4312. return;
  4313. }
  4314. const {
  4315. info,
  4316. contentLength
  4317. } = await this.pdfDocument.getMetadata();
  4318. 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 => {
  4319. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4320. }), this.#parseLinearization(info.IsLinearized)]);
  4321. this.#fieldData = Object.freeze({
  4322. fileName,
  4323. fileSize,
  4324. title: info.Title,
  4325. author: info.Author,
  4326. subject: info.Subject,
  4327. keywords: info.Keywords,
  4328. creationDate,
  4329. modificationDate,
  4330. creator: info.Creator,
  4331. producer: info.Producer,
  4332. version: info.PDFFormatVersion,
  4333. pageCount: this.pdfDocument.numPages,
  4334. pageSize,
  4335. linearized: isLinearized,
  4336. _currentPageNumber: currentPageNumber,
  4337. _pagesRotation: pagesRotation
  4338. });
  4339. this.#updateUI();
  4340. const {
  4341. length
  4342. } = await this.pdfDocument.getDownloadInfo();
  4343. if (contentLength === length) {
  4344. return;
  4345. }
  4346. const data = Object.assign(Object.create(null), this.#fieldData);
  4347. data.fileSize = await this.#parseFileSize(length);
  4348. this.#fieldData = Object.freeze(data);
  4349. this.#updateUI();
  4350. }
  4351. async close() {
  4352. this.overlayManager.close(this.dialog);
  4353. }
  4354. setDocument(pdfDocument) {
  4355. if (this.pdfDocument) {
  4356. this.#reset();
  4357. this.#updateUI(true);
  4358. }
  4359. if (!pdfDocument) {
  4360. return;
  4361. }
  4362. this.pdfDocument = pdfDocument;
  4363. this._dataAvailableCapability.resolve();
  4364. }
  4365. #reset() {
  4366. this.pdfDocument = null;
  4367. this.#fieldData = null;
  4368. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4369. this._currentPageNumber = 1;
  4370. this._pagesRotation = 0;
  4371. }
  4372. #updateUI(reset = false) {
  4373. if (reset || !this.#fieldData) {
  4374. for (const id in this.fields) {
  4375. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4376. }
  4377. return;
  4378. }
  4379. if (this.overlayManager.active !== this.dialog) {
  4380. return;
  4381. }
  4382. for (const id in this.fields) {
  4383. const content = this.#fieldData[id];
  4384. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4385. }
  4386. }
  4387. async #parseFileSize(fileSize = 0) {
  4388. const kb = fileSize / 1024,
  4389. mb = kb / 1024;
  4390. if (!kb) {
  4391. return undefined;
  4392. }
  4393. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4394. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4395. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4396. size_b: fileSize.toLocaleString()
  4397. });
  4398. }
  4399. async #parsePageSize(pageSizeInches, pagesRotation) {
  4400. if (!pageSizeInches) {
  4401. return undefined;
  4402. }
  4403. if (pagesRotation % 180 !== 0) {
  4404. pageSizeInches = {
  4405. width: pageSizeInches.height,
  4406. height: pageSizeInches.width
  4407. };
  4408. }
  4409. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4410. let sizeInches = {
  4411. width: Math.round(pageSizeInches.width * 100) / 100,
  4412. height: Math.round(pageSizeInches.height * 100) / 100
  4413. };
  4414. let sizeMillimeters = {
  4415. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4416. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4417. };
  4418. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4419. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4420. const exactMillimeters = {
  4421. width: pageSizeInches.width * 25.4,
  4422. height: pageSizeInches.height * 25.4
  4423. };
  4424. const intMillimeters = {
  4425. width: Math.round(sizeMillimeters.width),
  4426. height: Math.round(sizeMillimeters.height)
  4427. };
  4428. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4429. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4430. if (rawName) {
  4431. sizeInches = {
  4432. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4433. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4434. };
  4435. sizeMillimeters = intMillimeters;
  4436. }
  4437. }
  4438. }
  4439. const [{
  4440. width,
  4441. height
  4442. }, 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"}`)]);
  4443. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4444. width: width.toLocaleString(),
  4445. height: height.toLocaleString(),
  4446. unit,
  4447. name,
  4448. orientation
  4449. });
  4450. }
  4451. async #parseDate(inputDate) {
  4452. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4453. if (!dateObject) {
  4454. return undefined;
  4455. }
  4456. return this.l10n.get("document_properties_date_string", {
  4457. date: dateObject.toLocaleDateString(),
  4458. time: dateObject.toLocaleTimeString()
  4459. });
  4460. }
  4461. #parseLinearization(isLinearized) {
  4462. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4463. }
  4464. }
  4465. exports.PDFDocumentProperties = PDFDocumentProperties;
  4466. /***/ }),
  4467. /* 15 */
  4468. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4469. Object.defineProperty(exports, "__esModule", ({
  4470. value: true
  4471. }));
  4472. exports.PDFFindBar = void 0;
  4473. var _pdf_find_controller = __webpack_require__(16);
  4474. const MATCHES_COUNT_LIMIT = 1000;
  4475. class PDFFindBar {
  4476. constructor(options, eventBus, l10n) {
  4477. this.opened = false;
  4478. this.bar = options.bar;
  4479. this.toggleButton = options.toggleButton;
  4480. this.findField = options.findField;
  4481. this.highlightAll = options.highlightAllCheckbox;
  4482. this.caseSensitive = options.caseSensitiveCheckbox;
  4483. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4484. this.entireWord = options.entireWordCheckbox;
  4485. this.findMsg = options.findMsg;
  4486. this.findResultsCount = options.findResultsCount;
  4487. this.findPreviousButton = options.findPreviousButton;
  4488. this.findNextButton = options.findNextButton;
  4489. this.eventBus = eventBus;
  4490. this.l10n = l10n;
  4491. this.toggleButton.addEventListener("click", () => {
  4492. this.toggle();
  4493. });
  4494. this.findField.addEventListener("input", () => {
  4495. this.dispatchEvent("");
  4496. });
  4497. this.bar.addEventListener("keydown", e => {
  4498. switch (e.keyCode) {
  4499. case 13:
  4500. if (e.target === this.findField) {
  4501. this.dispatchEvent("again", e.shiftKey);
  4502. }
  4503. break;
  4504. case 27:
  4505. this.close();
  4506. break;
  4507. }
  4508. });
  4509. this.findPreviousButton.addEventListener("click", () => {
  4510. this.dispatchEvent("again", true);
  4511. });
  4512. this.findNextButton.addEventListener("click", () => {
  4513. this.dispatchEvent("again", false);
  4514. });
  4515. this.highlightAll.addEventListener("click", () => {
  4516. this.dispatchEvent("highlightallchange");
  4517. });
  4518. this.caseSensitive.addEventListener("click", () => {
  4519. this.dispatchEvent("casesensitivitychange");
  4520. });
  4521. this.entireWord.addEventListener("click", () => {
  4522. this.dispatchEvent("entirewordchange");
  4523. });
  4524. this.matchDiacritics.addEventListener("click", () => {
  4525. this.dispatchEvent("diacriticmatchingchange");
  4526. });
  4527. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4528. }
  4529. reset() {
  4530. this.updateUIState();
  4531. }
  4532. dispatchEvent(type, findPrev = false) {
  4533. this.eventBus.dispatch("find", {
  4534. source: this,
  4535. type,
  4536. query: this.findField.value,
  4537. phraseSearch: true,
  4538. caseSensitive: this.caseSensitive.checked,
  4539. entireWord: this.entireWord.checked,
  4540. highlightAll: this.highlightAll.checked,
  4541. findPrevious: findPrev,
  4542. matchDiacritics: this.matchDiacritics.checked
  4543. });
  4544. }
  4545. updateUIState(state, previous, matchesCount) {
  4546. let findMsg = Promise.resolve("");
  4547. let status = "";
  4548. switch (state) {
  4549. case _pdf_find_controller.FindState.FOUND:
  4550. break;
  4551. case _pdf_find_controller.FindState.PENDING:
  4552. status = "pending";
  4553. break;
  4554. case _pdf_find_controller.FindState.NOT_FOUND:
  4555. findMsg = this.l10n.get("find_not_found");
  4556. status = "notFound";
  4557. break;
  4558. case _pdf_find_controller.FindState.WRAPPED:
  4559. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4560. break;
  4561. }
  4562. this.findField.setAttribute("data-status", status);
  4563. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4564. findMsg.then(msg => {
  4565. this.findMsg.textContent = msg;
  4566. this.#adjustWidth();
  4567. });
  4568. this.updateResultsCount(matchesCount);
  4569. }
  4570. updateResultsCount({
  4571. current = 0,
  4572. total = 0
  4573. } = {}) {
  4574. const limit = MATCHES_COUNT_LIMIT;
  4575. let matchCountMsg = Promise.resolve("");
  4576. if (total > 0) {
  4577. if (total > limit) {
  4578. let key = "find_match_count_limit";
  4579. matchCountMsg = this.l10n.get(key, {
  4580. limit
  4581. });
  4582. } else {
  4583. let key = "find_match_count";
  4584. matchCountMsg = this.l10n.get(key, {
  4585. current,
  4586. total
  4587. });
  4588. }
  4589. }
  4590. matchCountMsg.then(msg => {
  4591. this.findResultsCount.textContent = msg;
  4592. this.#adjustWidth();
  4593. });
  4594. }
  4595. open() {
  4596. if (!this.opened) {
  4597. this.opened = true;
  4598. this.toggleButton.classList.add("toggled");
  4599. this.toggleButton.setAttribute("aria-expanded", "true");
  4600. this.bar.classList.remove("hidden");
  4601. }
  4602. this.findField.select();
  4603. this.findField.focus();
  4604. this.#adjustWidth();
  4605. }
  4606. close() {
  4607. if (!this.opened) {
  4608. return;
  4609. }
  4610. this.opened = false;
  4611. this.toggleButton.classList.remove("toggled");
  4612. this.toggleButton.setAttribute("aria-expanded", "false");
  4613. this.bar.classList.add("hidden");
  4614. this.eventBus.dispatch("findbarclose", {
  4615. source: this
  4616. });
  4617. }
  4618. toggle() {
  4619. if (this.opened) {
  4620. this.close();
  4621. } else {
  4622. this.open();
  4623. }
  4624. }
  4625. #adjustWidth() {
  4626. if (!this.opened) {
  4627. return;
  4628. }
  4629. this.bar.classList.remove("wrapContainers");
  4630. const findbarHeight = this.bar.clientHeight;
  4631. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4632. if (findbarHeight > inputContainerHeight) {
  4633. this.bar.classList.add("wrapContainers");
  4634. }
  4635. }
  4636. }
  4637. exports.PDFFindBar = PDFFindBar;
  4638. /***/ }),
  4639. /* 16 */
  4640. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4641. Object.defineProperty(exports, "__esModule", ({
  4642. value: true
  4643. }));
  4644. exports.PDFFindController = exports.FindState = void 0;
  4645. var _ui_utils = __webpack_require__(1);
  4646. var _pdfjsLib = __webpack_require__(5);
  4647. var _pdf_find_utils = __webpack_require__(17);
  4648. const FindState = {
  4649. FOUND: 0,
  4650. NOT_FOUND: 1,
  4651. WRAPPED: 2,
  4652. PENDING: 3
  4653. };
  4654. exports.FindState = FindState;
  4655. const FIND_TIMEOUT = 250;
  4656. const MATCH_SCROLL_OFFSET_TOP = -50;
  4657. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4658. const CHARACTERS_TO_NORMALIZE = {
  4659. "\u2010": "-",
  4660. "\u2018": "'",
  4661. "\u2019": "'",
  4662. "\u201A": "'",
  4663. "\u201B": "'",
  4664. "\u201C": '"',
  4665. "\u201D": '"',
  4666. "\u201E": '"',
  4667. "\u201F": '"',
  4668. "\u00BC": "1/4",
  4669. "\u00BD": "1/2",
  4670. "\u00BE": "3/4"
  4671. };
  4672. 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]);
  4673. const DIACRITICS_EXCEPTION_STR = [...DIACRITICS_EXCEPTION.values()].map(x => String.fromCharCode(x)).join("");
  4674. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4675. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4676. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4677. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4678. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4679. const SYLLABLES_LENGTHS = new Map();
  4680. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4681. let noSyllablesRegExp = null;
  4682. let withSyllablesRegExp = null;
  4683. function normalize(text) {
  4684. const syllablePositions = [];
  4685. let m;
  4686. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4687. let {
  4688. index
  4689. } = m;
  4690. for (const char of m[0]) {
  4691. let len = SYLLABLES_LENGTHS.get(char);
  4692. if (!len) {
  4693. len = char.normalize("NFD").length;
  4694. SYLLABLES_LENGTHS.set(char, len);
  4695. }
  4696. syllablePositions.push([len, index++]);
  4697. }
  4698. }
  4699. let normalizationRegex;
  4700. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4701. normalizationRegex = noSyllablesRegExp;
  4702. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4703. normalizationRegex = withSyllablesRegExp;
  4704. } else {
  4705. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4706. const regexp = `([${replace}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(\\n)`;
  4707. if (syllablePositions.length === 0) {
  4708. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4709. } else {
  4710. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4711. }
  4712. }
  4713. const rawDiacriticsPositions = [];
  4714. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4715. rawDiacriticsPositions.push([m[0].length, m.index]);
  4716. }
  4717. let normalized = text.normalize("NFD");
  4718. const positions = [[0, 0]];
  4719. let rawDiacriticsIndex = 0;
  4720. let syllableIndex = 0;
  4721. let shift = 0;
  4722. let shiftOrigin = 0;
  4723. let eol = 0;
  4724. let hasDiacritics = false;
  4725. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, i) => {
  4726. i -= shiftOrigin;
  4727. if (p1) {
  4728. const replacement = CHARACTERS_TO_NORMALIZE[match];
  4729. const jj = replacement.length;
  4730. for (let j = 1; j < jj; j++) {
  4731. positions.push([i - shift + j, shift - j]);
  4732. }
  4733. shift -= jj - 1;
  4734. return replacement;
  4735. }
  4736. if (p2) {
  4737. const hasTrailingDashEOL = p2.endsWith("\n");
  4738. const len = hasTrailingDashEOL ? p2.length - 2 : p2.length;
  4739. hasDiacritics = true;
  4740. let jj = len;
  4741. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4742. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4743. ++rawDiacriticsIndex;
  4744. }
  4745. for (let j = 1; j <= jj; j++) {
  4746. positions.push([i - 1 - shift + j, shift - j]);
  4747. }
  4748. shift -= jj;
  4749. shiftOrigin += jj;
  4750. if (hasTrailingDashEOL) {
  4751. i += len - 1;
  4752. positions.push([i - shift + 1, 1 + shift]);
  4753. shift += 1;
  4754. shiftOrigin += 1;
  4755. eol += 1;
  4756. return p2.slice(0, len);
  4757. }
  4758. return p2;
  4759. }
  4760. if (p3) {
  4761. positions.push([i - shift + 1, 1 + shift]);
  4762. shift += 1;
  4763. shiftOrigin += 1;
  4764. eol += 1;
  4765. return p3.charAt(0);
  4766. }
  4767. if (p4) {
  4768. positions.push([i - shift + 1, shift - 1]);
  4769. shift -= 1;
  4770. shiftOrigin += 1;
  4771. eol += 1;
  4772. return " ";
  4773. }
  4774. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  4775. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  4776. ++syllableIndex;
  4777. for (let j = 1; j <= newCharLen; j++) {
  4778. positions.push([i - (shift - j), shift - j]);
  4779. }
  4780. shift -= newCharLen;
  4781. shiftOrigin += newCharLen;
  4782. }
  4783. return p5;
  4784. });
  4785. positions.push([normalized.length, shift]);
  4786. return [normalized, positions, hasDiacritics];
  4787. }
  4788. function getOriginalIndex(diffs, pos, len) {
  4789. if (!diffs) {
  4790. return [pos, len];
  4791. }
  4792. const start = pos;
  4793. const end = pos + len;
  4794. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  4795. if (diffs[i][0] > start) {
  4796. --i;
  4797. }
  4798. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  4799. if (diffs[j][0] > end) {
  4800. --j;
  4801. }
  4802. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  4803. }
  4804. class PDFFindController {
  4805. constructor({
  4806. linkService,
  4807. eventBus
  4808. }) {
  4809. this._linkService = linkService;
  4810. this._eventBus = eventBus;
  4811. this.#reset();
  4812. eventBus._on("find", this.#onFind.bind(this));
  4813. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  4814. }
  4815. get highlightMatches() {
  4816. return this._highlightMatches;
  4817. }
  4818. get pageMatches() {
  4819. return this._pageMatches;
  4820. }
  4821. get pageMatchesLength() {
  4822. return this._pageMatchesLength;
  4823. }
  4824. get selected() {
  4825. return this._selected;
  4826. }
  4827. get state() {
  4828. return this._state;
  4829. }
  4830. setDocument(pdfDocument) {
  4831. if (this._pdfDocument) {
  4832. this.#reset();
  4833. }
  4834. if (!pdfDocument) {
  4835. return;
  4836. }
  4837. this._pdfDocument = pdfDocument;
  4838. this._firstPageCapability.resolve();
  4839. }
  4840. #onFind(state) {
  4841. if (!state) {
  4842. return;
  4843. }
  4844. const pdfDocument = this._pdfDocument;
  4845. const {
  4846. type
  4847. } = state;
  4848. if (this._state === null || this.#shouldDirtyMatch(state)) {
  4849. this._dirtyMatch = true;
  4850. }
  4851. this._state = state;
  4852. if (type !== "highlightallchange") {
  4853. this.#updateUIState(FindState.PENDING);
  4854. }
  4855. this._firstPageCapability.promise.then(() => {
  4856. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4857. return;
  4858. }
  4859. this.#extractText();
  4860. const findbarClosed = !this._highlightMatches;
  4861. const pendingTimeout = !!this._findTimeout;
  4862. if (this._findTimeout) {
  4863. clearTimeout(this._findTimeout);
  4864. this._findTimeout = null;
  4865. }
  4866. if (!type) {
  4867. this._findTimeout = setTimeout(() => {
  4868. this.#nextMatch();
  4869. this._findTimeout = null;
  4870. }, FIND_TIMEOUT);
  4871. } else if (this._dirtyMatch) {
  4872. this.#nextMatch();
  4873. } else if (type === "again") {
  4874. this.#nextMatch();
  4875. if (findbarClosed && this._state.highlightAll) {
  4876. this.#updateAllPages();
  4877. }
  4878. } else if (type === "highlightallchange") {
  4879. if (pendingTimeout) {
  4880. this.#nextMatch();
  4881. } else {
  4882. this._highlightMatches = true;
  4883. }
  4884. this.#updateAllPages();
  4885. } else {
  4886. this.#nextMatch();
  4887. }
  4888. });
  4889. }
  4890. scrollMatchIntoView({
  4891. element = null,
  4892. selectedLeft = 0,
  4893. pageIndex = -1,
  4894. matchIndex = -1
  4895. }) {
  4896. if (!this._scrollMatches || !element) {
  4897. return;
  4898. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4899. return;
  4900. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4901. return;
  4902. }
  4903. this._scrollMatches = false;
  4904. const spot = {
  4905. top: MATCH_SCROLL_OFFSET_TOP,
  4906. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  4907. };
  4908. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4909. }
  4910. #reset() {
  4911. this._highlightMatches = false;
  4912. this._scrollMatches = false;
  4913. this._pdfDocument = null;
  4914. this._pageMatches = [];
  4915. this._pageMatchesLength = [];
  4916. this._state = null;
  4917. this._selected = {
  4918. pageIdx: -1,
  4919. matchIdx: -1
  4920. };
  4921. this._offset = {
  4922. pageIdx: null,
  4923. matchIdx: null,
  4924. wrapped: false
  4925. };
  4926. this._extractTextPromises = [];
  4927. this._pageContents = [];
  4928. this._pageDiffs = [];
  4929. this._hasDiacritics = [];
  4930. this._matchesCountTotal = 0;
  4931. this._pagesToSearch = null;
  4932. this._pendingFindMatches = new Set();
  4933. this._resumePageIdx = null;
  4934. this._dirtyMatch = false;
  4935. clearTimeout(this._findTimeout);
  4936. this._findTimeout = null;
  4937. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4938. }
  4939. get #query() {
  4940. if (this._state.query !== this._rawQuery) {
  4941. this._rawQuery = this._state.query;
  4942. [this._normalizedQuery] = normalize(this._state.query);
  4943. }
  4944. return this._normalizedQuery;
  4945. }
  4946. #shouldDirtyMatch(state) {
  4947. if (state.query !== this._state.query) {
  4948. return true;
  4949. }
  4950. switch (state.type) {
  4951. case "again":
  4952. const pageNumber = this._selected.pageIdx + 1;
  4953. const linkService = this._linkService;
  4954. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4955. return true;
  4956. }
  4957. return false;
  4958. case "highlightallchange":
  4959. return false;
  4960. }
  4961. return true;
  4962. }
  4963. #isEntireWord(content, startIdx, length) {
  4964. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  4965. if (match) {
  4966. const first = content.charCodeAt(startIdx);
  4967. const limit = match[1].charCodeAt(0);
  4968. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4969. return false;
  4970. }
  4971. }
  4972. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  4973. if (match) {
  4974. const last = content.charCodeAt(startIdx + length - 1);
  4975. const limit = match[1].charCodeAt(0);
  4976. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4977. return false;
  4978. }
  4979. }
  4980. return true;
  4981. }
  4982. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  4983. const matches = [],
  4984. matchesLength = [];
  4985. const diffs = this._pageDiffs[pageIndex];
  4986. let match;
  4987. while ((match = query.exec(pageContent)) !== null) {
  4988. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  4989. continue;
  4990. }
  4991. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  4992. if (matchLen) {
  4993. matches.push(matchPos);
  4994. matchesLength.push(matchLen);
  4995. }
  4996. }
  4997. this._pageMatches[pageIndex] = matches;
  4998. this._pageMatchesLength[pageIndex] = matchesLength;
  4999. }
  5000. #convertToRegExpString(query, hasDiacritics) {
  5001. const {
  5002. matchDiacritics
  5003. } = this._state;
  5004. let isUnicode = false;
  5005. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5006. if (p1) {
  5007. return `[ ]*\\${p1}[ ]*`;
  5008. }
  5009. if (p2) {
  5010. return `[ ]*${p2}[ ]*`;
  5011. }
  5012. if (p3) {
  5013. return "[ ]+";
  5014. }
  5015. if (matchDiacritics) {
  5016. return p4 || p5;
  5017. }
  5018. if (p4) {
  5019. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5020. }
  5021. if (hasDiacritics) {
  5022. isUnicode = true;
  5023. return `${p5}\\p{M}*`;
  5024. }
  5025. return p5;
  5026. });
  5027. const trailingSpaces = "[ ]*";
  5028. if (query.endsWith(trailingSpaces)) {
  5029. query = query.slice(0, query.length - trailingSpaces.length);
  5030. }
  5031. if (matchDiacritics) {
  5032. if (hasDiacritics) {
  5033. isUnicode = true;
  5034. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5035. }
  5036. }
  5037. return [isUnicode, query];
  5038. }
  5039. #calculateMatch(pageIndex) {
  5040. let query = this.#query;
  5041. if (query.length === 0) {
  5042. return;
  5043. }
  5044. const {
  5045. caseSensitive,
  5046. entireWord,
  5047. phraseSearch
  5048. } = this._state;
  5049. const pageContent = this._pageContents[pageIndex];
  5050. const hasDiacritics = this._hasDiacritics[pageIndex];
  5051. let isUnicode = false;
  5052. if (phraseSearch) {
  5053. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5054. } else {
  5055. const match = query.match(/\S+/g);
  5056. if (match) {
  5057. query = match.sort().reverse().map(q => {
  5058. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5059. isUnicode ||= isUnicodePart;
  5060. return `(${queryPart})`;
  5061. }).join("|");
  5062. }
  5063. }
  5064. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5065. query = new RegExp(query, flags);
  5066. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  5067. if (this._state.highlightAll) {
  5068. this.#updatePage(pageIndex);
  5069. }
  5070. if (this._resumePageIdx === pageIndex) {
  5071. this._resumePageIdx = null;
  5072. this.#nextPageMatch();
  5073. }
  5074. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5075. if (pageMatchesCount > 0) {
  5076. this._matchesCountTotal += pageMatchesCount;
  5077. this.#updateUIResultsCount();
  5078. }
  5079. }
  5080. #extractText() {
  5081. if (this._extractTextPromises.length > 0) {
  5082. return;
  5083. }
  5084. let promise = Promise.resolve();
  5085. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5086. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  5087. this._extractTextPromises[i] = extractTextCapability.promise;
  5088. promise = promise.then(() => {
  5089. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5090. return pdfPage.getTextContent();
  5091. }).then(textContent => {
  5092. const strBuf = [];
  5093. for (const textItem of textContent.items) {
  5094. strBuf.push(textItem.str);
  5095. if (textItem.hasEOL) {
  5096. strBuf.push("\n");
  5097. }
  5098. }
  5099. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5100. extractTextCapability.resolve();
  5101. }, reason => {
  5102. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5103. this._pageContents[i] = "";
  5104. this._pageDiffs[i] = null;
  5105. this._hasDiacritics[i] = false;
  5106. extractTextCapability.resolve();
  5107. });
  5108. });
  5109. }
  5110. }
  5111. #updatePage(index) {
  5112. if (this._scrollMatches && this._selected.pageIdx === index) {
  5113. this._linkService.page = index + 1;
  5114. }
  5115. this._eventBus.dispatch("updatetextlayermatches", {
  5116. source: this,
  5117. pageIndex: index
  5118. });
  5119. }
  5120. #updateAllPages() {
  5121. this._eventBus.dispatch("updatetextlayermatches", {
  5122. source: this,
  5123. pageIndex: -1
  5124. });
  5125. }
  5126. #nextMatch() {
  5127. const previous = this._state.findPrevious;
  5128. const currentPageIndex = this._linkService.page - 1;
  5129. const numPages = this._linkService.pagesCount;
  5130. this._highlightMatches = true;
  5131. if (this._dirtyMatch) {
  5132. this._dirtyMatch = false;
  5133. this._selected.pageIdx = this._selected.matchIdx = -1;
  5134. this._offset.pageIdx = currentPageIndex;
  5135. this._offset.matchIdx = null;
  5136. this._offset.wrapped = false;
  5137. this._resumePageIdx = null;
  5138. this._pageMatches.length = 0;
  5139. this._pageMatchesLength.length = 0;
  5140. this._matchesCountTotal = 0;
  5141. this.#updateAllPages();
  5142. for (let i = 0; i < numPages; i++) {
  5143. if (this._pendingFindMatches.has(i)) {
  5144. continue;
  5145. }
  5146. this._pendingFindMatches.add(i);
  5147. this._extractTextPromises[i].then(() => {
  5148. this._pendingFindMatches.delete(i);
  5149. this.#calculateMatch(i);
  5150. });
  5151. }
  5152. }
  5153. if (this.#query === "") {
  5154. this.#updateUIState(FindState.FOUND);
  5155. return;
  5156. }
  5157. if (this._resumePageIdx) {
  5158. return;
  5159. }
  5160. const offset = this._offset;
  5161. this._pagesToSearch = numPages;
  5162. if (offset.matchIdx !== null) {
  5163. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5164. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5165. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5166. this.#updateMatch(true);
  5167. return;
  5168. }
  5169. this.#advanceOffsetPage(previous);
  5170. }
  5171. this.#nextPageMatch();
  5172. }
  5173. #matchesReady(matches) {
  5174. const offset = this._offset;
  5175. const numMatches = matches.length;
  5176. const previous = this._state.findPrevious;
  5177. if (numMatches) {
  5178. offset.matchIdx = previous ? numMatches - 1 : 0;
  5179. this.#updateMatch(true);
  5180. return true;
  5181. }
  5182. this.#advanceOffsetPage(previous);
  5183. if (offset.wrapped) {
  5184. offset.matchIdx = null;
  5185. if (this._pagesToSearch < 0) {
  5186. this.#updateMatch(false);
  5187. return true;
  5188. }
  5189. }
  5190. return false;
  5191. }
  5192. #nextPageMatch() {
  5193. if (this._resumePageIdx !== null) {
  5194. console.error("There can only be one pending page.");
  5195. }
  5196. let matches = null;
  5197. do {
  5198. const pageIdx = this._offset.pageIdx;
  5199. matches = this._pageMatches[pageIdx];
  5200. if (!matches) {
  5201. this._resumePageIdx = pageIdx;
  5202. break;
  5203. }
  5204. } while (!this.#matchesReady(matches));
  5205. }
  5206. #advanceOffsetPage(previous) {
  5207. const offset = this._offset;
  5208. const numPages = this._linkService.pagesCount;
  5209. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5210. offset.matchIdx = null;
  5211. this._pagesToSearch--;
  5212. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5213. offset.pageIdx = previous ? numPages - 1 : 0;
  5214. offset.wrapped = true;
  5215. }
  5216. }
  5217. #updateMatch(found = false) {
  5218. let state = FindState.NOT_FOUND;
  5219. const wrapped = this._offset.wrapped;
  5220. this._offset.wrapped = false;
  5221. if (found) {
  5222. const previousPage = this._selected.pageIdx;
  5223. this._selected.pageIdx = this._offset.pageIdx;
  5224. this._selected.matchIdx = this._offset.matchIdx;
  5225. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5226. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5227. this.#updatePage(previousPage);
  5228. }
  5229. }
  5230. this.#updateUIState(state, this._state.findPrevious);
  5231. if (this._selected.pageIdx !== -1) {
  5232. this._scrollMatches = true;
  5233. this.#updatePage(this._selected.pageIdx);
  5234. }
  5235. }
  5236. #onFindBarClose(evt) {
  5237. const pdfDocument = this._pdfDocument;
  5238. this._firstPageCapability.promise.then(() => {
  5239. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5240. return;
  5241. }
  5242. if (this._findTimeout) {
  5243. clearTimeout(this._findTimeout);
  5244. this._findTimeout = null;
  5245. }
  5246. if (this._resumePageIdx) {
  5247. this._resumePageIdx = null;
  5248. this._dirtyMatch = true;
  5249. }
  5250. this.#updateUIState(FindState.FOUND);
  5251. this._highlightMatches = false;
  5252. this.#updateAllPages();
  5253. });
  5254. }
  5255. #requestMatchesCount() {
  5256. const {
  5257. pageIdx,
  5258. matchIdx
  5259. } = this._selected;
  5260. let current = 0,
  5261. total = this._matchesCountTotal;
  5262. if (matchIdx !== -1) {
  5263. for (let i = 0; i < pageIdx; i++) {
  5264. current += this._pageMatches[i]?.length || 0;
  5265. }
  5266. current += matchIdx + 1;
  5267. }
  5268. if (current < 1 || current > total) {
  5269. current = total = 0;
  5270. }
  5271. return {
  5272. current,
  5273. total
  5274. };
  5275. }
  5276. #updateUIResultsCount() {
  5277. this._eventBus.dispatch("updatefindmatchescount", {
  5278. source: this,
  5279. matchesCount: this.#requestMatchesCount()
  5280. });
  5281. }
  5282. #updateUIState(state, previous = false) {
  5283. this._eventBus.dispatch("updatefindcontrolstate", {
  5284. source: this,
  5285. state,
  5286. previous,
  5287. matchesCount: this.#requestMatchesCount(),
  5288. rawQuery: this._state?.query ?? null
  5289. });
  5290. }
  5291. }
  5292. exports.PDFFindController = PDFFindController;
  5293. /***/ }),
  5294. /* 17 */
  5295. /***/ ((__unused_webpack_module, exports) => {
  5296. Object.defineProperty(exports, "__esModule", ({
  5297. value: true
  5298. }));
  5299. exports.CharacterType = void 0;
  5300. exports.getCharacterType = getCharacterType;
  5301. const CharacterType = {
  5302. SPACE: 0,
  5303. ALPHA_LETTER: 1,
  5304. PUNCT: 2,
  5305. HAN_LETTER: 3,
  5306. KATAKANA_LETTER: 4,
  5307. HIRAGANA_LETTER: 5,
  5308. HALFWIDTH_KATAKANA_LETTER: 6,
  5309. THAI_LETTER: 7
  5310. };
  5311. exports.CharacterType = CharacterType;
  5312. function isAlphabeticalScript(charCode) {
  5313. return charCode < 0x2e80;
  5314. }
  5315. function isAscii(charCode) {
  5316. return (charCode & 0xff80) === 0;
  5317. }
  5318. function isAsciiAlpha(charCode) {
  5319. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5320. }
  5321. function isAsciiDigit(charCode) {
  5322. return charCode >= 0x30 && charCode <= 0x39;
  5323. }
  5324. function isAsciiSpace(charCode) {
  5325. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5326. }
  5327. function isHan(charCode) {
  5328. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5329. }
  5330. function isKatakana(charCode) {
  5331. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5332. }
  5333. function isHiragana(charCode) {
  5334. return charCode >= 0x3040 && charCode <= 0x309f;
  5335. }
  5336. function isHalfwidthKatakana(charCode) {
  5337. return charCode >= 0xff60 && charCode <= 0xff9f;
  5338. }
  5339. function isThai(charCode) {
  5340. return (charCode & 0xff80) === 0x0e00;
  5341. }
  5342. function getCharacterType(charCode) {
  5343. if (isAlphabeticalScript(charCode)) {
  5344. if (isAscii(charCode)) {
  5345. if (isAsciiSpace(charCode)) {
  5346. return CharacterType.SPACE;
  5347. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5348. return CharacterType.ALPHA_LETTER;
  5349. }
  5350. return CharacterType.PUNCT;
  5351. } else if (isThai(charCode)) {
  5352. return CharacterType.THAI_LETTER;
  5353. } else if (charCode === 0xa0) {
  5354. return CharacterType.SPACE;
  5355. }
  5356. return CharacterType.ALPHA_LETTER;
  5357. }
  5358. if (isHan(charCode)) {
  5359. return CharacterType.HAN_LETTER;
  5360. } else if (isKatakana(charCode)) {
  5361. return CharacterType.KATAKANA_LETTER;
  5362. } else if (isHiragana(charCode)) {
  5363. return CharacterType.HIRAGANA_LETTER;
  5364. } else if (isHalfwidthKatakana(charCode)) {
  5365. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5366. }
  5367. return CharacterType.ALPHA_LETTER;
  5368. }
  5369. /***/ }),
  5370. /* 18 */
  5371. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5372. Object.defineProperty(exports, "__esModule", ({
  5373. value: true
  5374. }));
  5375. exports.PDFHistory = void 0;
  5376. exports.isDestArraysEqual = isDestArraysEqual;
  5377. exports.isDestHashesEqual = isDestHashesEqual;
  5378. var _ui_utils = __webpack_require__(1);
  5379. var _event_utils = __webpack_require__(6);
  5380. const HASH_CHANGE_TIMEOUT = 1000;
  5381. const POSITION_UPDATED_THRESHOLD = 50;
  5382. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5383. function getCurrentHash() {
  5384. return document.location.hash;
  5385. }
  5386. class PDFHistory {
  5387. constructor({
  5388. linkService,
  5389. eventBus
  5390. }) {
  5391. this.linkService = linkService;
  5392. this.eventBus = eventBus;
  5393. this._initialized = false;
  5394. this._fingerprint = "";
  5395. this.reset();
  5396. this._boundEvents = null;
  5397. this.eventBus._on("pagesinit", () => {
  5398. this._isPagesLoaded = false;
  5399. this.eventBus._on("pagesloaded", evt => {
  5400. this._isPagesLoaded = !!evt.pagesCount;
  5401. }, {
  5402. once: true
  5403. });
  5404. });
  5405. }
  5406. initialize({
  5407. fingerprint,
  5408. resetHistory = false,
  5409. updateUrl = false
  5410. }) {
  5411. if (!fingerprint || typeof fingerprint !== "string") {
  5412. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5413. return;
  5414. }
  5415. if (this._initialized) {
  5416. this.reset();
  5417. }
  5418. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5419. this._fingerprint = fingerprint;
  5420. this._updateUrl = updateUrl === true;
  5421. this._initialized = true;
  5422. this._bindEvents();
  5423. const state = window.history.state;
  5424. this._popStateInProgress = false;
  5425. this._blockHashChange = 0;
  5426. this._currentHash = getCurrentHash();
  5427. this._numPositionUpdates = 0;
  5428. this._uid = this._maxUid = 0;
  5429. this._destination = null;
  5430. this._position = null;
  5431. if (!this._isValidState(state, true) || resetHistory) {
  5432. const {
  5433. hash,
  5434. page,
  5435. rotation
  5436. } = this._parseCurrentHash(true);
  5437. if (!hash || reInitialized || resetHistory) {
  5438. this._pushOrReplaceState(null, true);
  5439. return;
  5440. }
  5441. this._pushOrReplaceState({
  5442. hash,
  5443. page,
  5444. rotation
  5445. }, true);
  5446. return;
  5447. }
  5448. const destination = state.destination;
  5449. this._updateInternalState(destination, state.uid, true);
  5450. if (destination.rotation !== undefined) {
  5451. this._initialRotation = destination.rotation;
  5452. }
  5453. if (destination.dest) {
  5454. this._initialBookmark = JSON.stringify(destination.dest);
  5455. this._destination.page = null;
  5456. } else if (destination.hash) {
  5457. this._initialBookmark = destination.hash;
  5458. } else if (destination.page) {
  5459. this._initialBookmark = `page=${destination.page}`;
  5460. }
  5461. }
  5462. reset() {
  5463. if (this._initialized) {
  5464. this._pageHide();
  5465. this._initialized = false;
  5466. this._unbindEvents();
  5467. }
  5468. if (this._updateViewareaTimeout) {
  5469. clearTimeout(this._updateViewareaTimeout);
  5470. this._updateViewareaTimeout = null;
  5471. }
  5472. this._initialBookmark = null;
  5473. this._initialRotation = null;
  5474. }
  5475. push({
  5476. namedDest = null,
  5477. explicitDest,
  5478. pageNumber
  5479. }) {
  5480. if (!this._initialized) {
  5481. return;
  5482. }
  5483. if (namedDest && typeof namedDest !== "string") {
  5484. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5485. return;
  5486. } else if (!Array.isArray(explicitDest)) {
  5487. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5488. return;
  5489. } else if (!this._isValidPage(pageNumber)) {
  5490. if (pageNumber !== null || this._destination) {
  5491. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5492. return;
  5493. }
  5494. }
  5495. const hash = namedDest || JSON.stringify(explicitDest);
  5496. if (!hash) {
  5497. return;
  5498. }
  5499. let forceReplace = false;
  5500. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5501. if (this._destination.page) {
  5502. return;
  5503. }
  5504. forceReplace = true;
  5505. }
  5506. if (this._popStateInProgress && !forceReplace) {
  5507. return;
  5508. }
  5509. this._pushOrReplaceState({
  5510. dest: explicitDest,
  5511. hash,
  5512. page: pageNumber,
  5513. rotation: this.linkService.rotation
  5514. }, forceReplace);
  5515. if (!this._popStateInProgress) {
  5516. this._popStateInProgress = true;
  5517. Promise.resolve().then(() => {
  5518. this._popStateInProgress = false;
  5519. });
  5520. }
  5521. }
  5522. pushPage(pageNumber) {
  5523. if (!this._initialized) {
  5524. return;
  5525. }
  5526. if (!this._isValidPage(pageNumber)) {
  5527. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5528. return;
  5529. }
  5530. if (this._destination?.page === pageNumber) {
  5531. return;
  5532. }
  5533. if (this._popStateInProgress) {
  5534. return;
  5535. }
  5536. this._pushOrReplaceState({
  5537. dest: null,
  5538. hash: `page=${pageNumber}`,
  5539. page: pageNumber,
  5540. rotation: this.linkService.rotation
  5541. });
  5542. if (!this._popStateInProgress) {
  5543. this._popStateInProgress = true;
  5544. Promise.resolve().then(() => {
  5545. this._popStateInProgress = false;
  5546. });
  5547. }
  5548. }
  5549. pushCurrentPosition() {
  5550. if (!this._initialized || this._popStateInProgress) {
  5551. return;
  5552. }
  5553. this._tryPushCurrentPosition();
  5554. }
  5555. back() {
  5556. if (!this._initialized || this._popStateInProgress) {
  5557. return;
  5558. }
  5559. const state = window.history.state;
  5560. if (this._isValidState(state) && state.uid > 0) {
  5561. window.history.back();
  5562. }
  5563. }
  5564. forward() {
  5565. if (!this._initialized || this._popStateInProgress) {
  5566. return;
  5567. }
  5568. const state = window.history.state;
  5569. if (this._isValidState(state) && state.uid < this._maxUid) {
  5570. window.history.forward();
  5571. }
  5572. }
  5573. get popStateInProgress() {
  5574. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5575. }
  5576. get initialBookmark() {
  5577. return this._initialized ? this._initialBookmark : null;
  5578. }
  5579. get initialRotation() {
  5580. return this._initialized ? this._initialRotation : null;
  5581. }
  5582. _pushOrReplaceState(destination, forceReplace = false) {
  5583. const shouldReplace = forceReplace || !this._destination;
  5584. const newState = {
  5585. fingerprint: this._fingerprint,
  5586. uid: shouldReplace ? this._uid : this._uid + 1,
  5587. destination
  5588. };
  5589. this._updateInternalState(destination, newState.uid);
  5590. let newUrl;
  5591. if (this._updateUrl && destination?.hash) {
  5592. const baseUrl = document.location.href.split("#")[0];
  5593. if (!baseUrl.startsWith("file://")) {
  5594. newUrl = `${baseUrl}#${destination.hash}`;
  5595. }
  5596. }
  5597. if (shouldReplace) {
  5598. window.history.replaceState(newState, "", newUrl);
  5599. } else {
  5600. window.history.pushState(newState, "", newUrl);
  5601. }
  5602. }
  5603. _tryPushCurrentPosition(temporary = false) {
  5604. if (!this._position) {
  5605. return;
  5606. }
  5607. let position = this._position;
  5608. if (temporary) {
  5609. position = Object.assign(Object.create(null), this._position);
  5610. position.temporary = true;
  5611. }
  5612. if (!this._destination) {
  5613. this._pushOrReplaceState(position);
  5614. return;
  5615. }
  5616. if (this._destination.temporary) {
  5617. this._pushOrReplaceState(position, true);
  5618. return;
  5619. }
  5620. if (this._destination.hash === position.hash) {
  5621. return;
  5622. }
  5623. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5624. return;
  5625. }
  5626. let forceReplace = false;
  5627. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5628. if (this._destination.dest !== undefined || !this._destination.first) {
  5629. return;
  5630. }
  5631. forceReplace = true;
  5632. }
  5633. this._pushOrReplaceState(position, forceReplace);
  5634. }
  5635. _isValidPage(val) {
  5636. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5637. }
  5638. _isValidState(state, checkReload = false) {
  5639. if (!state) {
  5640. return false;
  5641. }
  5642. if (state.fingerprint !== this._fingerprint) {
  5643. if (checkReload) {
  5644. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5645. return false;
  5646. }
  5647. const [perfEntry] = performance.getEntriesByType("navigation");
  5648. if (perfEntry?.type !== "reload") {
  5649. return false;
  5650. }
  5651. } else {
  5652. return false;
  5653. }
  5654. }
  5655. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5656. return false;
  5657. }
  5658. if (state.destination === null || typeof state.destination !== "object") {
  5659. return false;
  5660. }
  5661. return true;
  5662. }
  5663. _updateInternalState(destination, uid, removeTemporary = false) {
  5664. if (this._updateViewareaTimeout) {
  5665. clearTimeout(this._updateViewareaTimeout);
  5666. this._updateViewareaTimeout = null;
  5667. }
  5668. if (removeTemporary && destination?.temporary) {
  5669. delete destination.temporary;
  5670. }
  5671. this._destination = destination;
  5672. this._uid = uid;
  5673. this._maxUid = Math.max(this._maxUid, uid);
  5674. this._numPositionUpdates = 0;
  5675. }
  5676. _parseCurrentHash(checkNameddest = false) {
  5677. const hash = unescape(getCurrentHash()).substring(1);
  5678. const params = (0, _ui_utils.parseQueryString)(hash);
  5679. const nameddest = params.get("nameddest") || "";
  5680. let page = params.get("page") | 0;
  5681. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5682. page = null;
  5683. }
  5684. return {
  5685. hash,
  5686. page,
  5687. rotation: this.linkService.rotation
  5688. };
  5689. }
  5690. _updateViewarea({
  5691. location
  5692. }) {
  5693. if (this._updateViewareaTimeout) {
  5694. clearTimeout(this._updateViewareaTimeout);
  5695. this._updateViewareaTimeout = null;
  5696. }
  5697. this._position = {
  5698. hash: location.pdfOpenParams.substring(1),
  5699. page: this.linkService.page,
  5700. first: location.pageNumber,
  5701. rotation: location.rotation
  5702. };
  5703. if (this._popStateInProgress) {
  5704. return;
  5705. }
  5706. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5707. this._numPositionUpdates++;
  5708. }
  5709. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5710. this._updateViewareaTimeout = setTimeout(() => {
  5711. if (!this._popStateInProgress) {
  5712. this._tryPushCurrentPosition(true);
  5713. }
  5714. this._updateViewareaTimeout = null;
  5715. }, UPDATE_VIEWAREA_TIMEOUT);
  5716. }
  5717. }
  5718. _popState({
  5719. state
  5720. }) {
  5721. const newHash = getCurrentHash(),
  5722. hashChanged = this._currentHash !== newHash;
  5723. this._currentHash = newHash;
  5724. if (!state) {
  5725. this._uid++;
  5726. const {
  5727. hash,
  5728. page,
  5729. rotation
  5730. } = this._parseCurrentHash();
  5731. this._pushOrReplaceState({
  5732. hash,
  5733. page,
  5734. rotation
  5735. }, true);
  5736. return;
  5737. }
  5738. if (!this._isValidState(state)) {
  5739. return;
  5740. }
  5741. this._popStateInProgress = true;
  5742. if (hashChanged) {
  5743. this._blockHashChange++;
  5744. (0, _event_utils.waitOnEventOrTimeout)({
  5745. target: window,
  5746. name: "hashchange",
  5747. delay: HASH_CHANGE_TIMEOUT
  5748. }).then(() => {
  5749. this._blockHashChange--;
  5750. });
  5751. }
  5752. const destination = state.destination;
  5753. this._updateInternalState(destination, state.uid, true);
  5754. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5755. this.linkService.rotation = destination.rotation;
  5756. }
  5757. if (destination.dest) {
  5758. this.linkService.goToDestination(destination.dest);
  5759. } else if (destination.hash) {
  5760. this.linkService.setHash(destination.hash);
  5761. } else if (destination.page) {
  5762. this.linkService.page = destination.page;
  5763. }
  5764. Promise.resolve().then(() => {
  5765. this._popStateInProgress = false;
  5766. });
  5767. }
  5768. _pageHide() {
  5769. if (!this._destination || this._destination.temporary) {
  5770. this._tryPushCurrentPosition();
  5771. }
  5772. }
  5773. _bindEvents() {
  5774. if (this._boundEvents) {
  5775. return;
  5776. }
  5777. this._boundEvents = {
  5778. updateViewarea: this._updateViewarea.bind(this),
  5779. popState: this._popState.bind(this),
  5780. pageHide: this._pageHide.bind(this)
  5781. };
  5782. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5783. window.addEventListener("popstate", this._boundEvents.popState);
  5784. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5785. }
  5786. _unbindEvents() {
  5787. if (!this._boundEvents) {
  5788. return;
  5789. }
  5790. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5791. window.removeEventListener("popstate", this._boundEvents.popState);
  5792. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5793. this._boundEvents = null;
  5794. }
  5795. }
  5796. exports.PDFHistory = PDFHistory;
  5797. function isDestHashesEqual(destHash, pushHash) {
  5798. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5799. return false;
  5800. }
  5801. if (destHash === pushHash) {
  5802. return true;
  5803. }
  5804. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  5805. if (nameddest === pushHash) {
  5806. return true;
  5807. }
  5808. return false;
  5809. }
  5810. function isDestArraysEqual(firstDest, secondDest) {
  5811. function isEntryEqual(first, second) {
  5812. if (typeof first !== typeof second) {
  5813. return false;
  5814. }
  5815. if (Array.isArray(first) || Array.isArray(second)) {
  5816. return false;
  5817. }
  5818. if (first !== null && typeof first === "object" && second !== null) {
  5819. if (Object.keys(first).length !== Object.keys(second).length) {
  5820. return false;
  5821. }
  5822. for (const key in first) {
  5823. if (!isEntryEqual(first[key], second[key])) {
  5824. return false;
  5825. }
  5826. }
  5827. return true;
  5828. }
  5829. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5830. }
  5831. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5832. return false;
  5833. }
  5834. if (firstDest.length !== secondDest.length) {
  5835. return false;
  5836. }
  5837. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5838. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5839. return false;
  5840. }
  5841. }
  5842. return true;
  5843. }
  5844. /***/ }),
  5845. /* 19 */
  5846. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5847. Object.defineProperty(exports, "__esModule", ({
  5848. value: true
  5849. }));
  5850. exports.PDFLayerViewer = void 0;
  5851. var _base_tree_viewer = __webpack_require__(13);
  5852. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5853. constructor(options) {
  5854. super(options);
  5855. this.l10n = options.l10n;
  5856. this.eventBus._on("resetlayers", this._resetLayers.bind(this));
  5857. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5858. }
  5859. reset() {
  5860. super.reset();
  5861. this._optionalContentConfig = null;
  5862. }
  5863. _dispatchEvent(layersCount) {
  5864. this.eventBus.dispatch("layersloaded", {
  5865. source: this,
  5866. layersCount
  5867. });
  5868. }
  5869. _bindLink(element, {
  5870. groupId,
  5871. input
  5872. }) {
  5873. const setVisibility = () => {
  5874. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5875. this.eventBus.dispatch("optionalcontentconfig", {
  5876. source: this,
  5877. promise: Promise.resolve(this._optionalContentConfig)
  5878. });
  5879. };
  5880. element.onclick = evt => {
  5881. if (evt.target === input) {
  5882. setVisibility();
  5883. return true;
  5884. } else if (evt.target !== element) {
  5885. return true;
  5886. }
  5887. input.checked = !input.checked;
  5888. setVisibility();
  5889. return false;
  5890. };
  5891. }
  5892. async _setNestedName(element, {
  5893. name = null
  5894. }) {
  5895. if (typeof name === "string") {
  5896. element.textContent = this._normalizeTextContent(name);
  5897. return;
  5898. }
  5899. element.textContent = await this.l10n.get("additional_layers");
  5900. element.style.fontStyle = "italic";
  5901. }
  5902. _addToggleButton(div, {
  5903. name = null
  5904. }) {
  5905. super._addToggleButton(div, name === null);
  5906. }
  5907. _toggleAllTreeItems() {
  5908. if (!this._optionalContentConfig) {
  5909. return;
  5910. }
  5911. super._toggleAllTreeItems();
  5912. }
  5913. render({
  5914. optionalContentConfig,
  5915. pdfDocument
  5916. }) {
  5917. if (this._optionalContentConfig) {
  5918. this.reset();
  5919. }
  5920. this._optionalContentConfig = optionalContentConfig || null;
  5921. this._pdfDocument = pdfDocument || null;
  5922. const groups = optionalContentConfig?.getOrder();
  5923. if (!groups) {
  5924. this._dispatchEvent(0);
  5925. return;
  5926. }
  5927. const fragment = document.createDocumentFragment(),
  5928. queue = [{
  5929. parent: fragment,
  5930. groups
  5931. }];
  5932. let layersCount = 0,
  5933. hasAnyNesting = false;
  5934. while (queue.length > 0) {
  5935. const levelData = queue.shift();
  5936. for (const groupId of levelData.groups) {
  5937. const div = document.createElement("div");
  5938. div.className = "treeItem";
  5939. const element = document.createElement("a");
  5940. div.append(element);
  5941. if (typeof groupId === "object") {
  5942. hasAnyNesting = true;
  5943. this._addToggleButton(div, groupId);
  5944. this._setNestedName(element, groupId);
  5945. const itemsDiv = document.createElement("div");
  5946. itemsDiv.className = "treeItems";
  5947. div.append(itemsDiv);
  5948. queue.push({
  5949. parent: itemsDiv,
  5950. groups: groupId.order
  5951. });
  5952. } else {
  5953. const group = optionalContentConfig.getGroup(groupId);
  5954. const input = document.createElement("input");
  5955. this._bindLink(element, {
  5956. groupId,
  5957. input
  5958. });
  5959. input.type = "checkbox";
  5960. input.checked = group.visible;
  5961. const label = document.createElement("label");
  5962. label.textContent = this._normalizeTextContent(group.name);
  5963. label.append(input);
  5964. element.append(label);
  5965. layersCount++;
  5966. }
  5967. levelData.parent.append(div);
  5968. }
  5969. }
  5970. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5971. }
  5972. async _resetLayers() {
  5973. if (!this._optionalContentConfig) {
  5974. return;
  5975. }
  5976. const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
  5977. this.eventBus.dispatch("optionalcontentconfig", {
  5978. source: this,
  5979. promise: Promise.resolve(optionalContentConfig)
  5980. });
  5981. this.render({
  5982. optionalContentConfig,
  5983. pdfDocument: this._pdfDocument
  5984. });
  5985. }
  5986. }
  5987. exports.PDFLayerViewer = PDFLayerViewer;
  5988. /***/ }),
  5989. /* 20 */
  5990. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5991. Object.defineProperty(exports, "__esModule", ({
  5992. value: true
  5993. }));
  5994. exports.PDFOutlineViewer = void 0;
  5995. var _base_tree_viewer = __webpack_require__(13);
  5996. var _pdfjsLib = __webpack_require__(5);
  5997. var _ui_utils = __webpack_require__(1);
  5998. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  5999. constructor(options) {
  6000. super(options);
  6001. this.linkService = options.linkService;
  6002. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6003. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6004. this.eventBus._on("pagechanging", evt => {
  6005. this._currentPageNumber = evt.pageNumber;
  6006. });
  6007. this.eventBus._on("pagesloaded", evt => {
  6008. this._isPagesLoaded = !!evt.pagesCount;
  6009. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6010. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6011. }
  6012. });
  6013. this.eventBus._on("sidebarviewchanged", evt => {
  6014. this._sidebarView = evt.view;
  6015. });
  6016. }
  6017. reset() {
  6018. super.reset();
  6019. this._outline = null;
  6020. this._pageNumberToDestHashCapability = null;
  6021. this._currentPageNumber = 1;
  6022. this._isPagesLoaded = null;
  6023. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6024. this._currentOutlineItemCapability.resolve(false);
  6025. }
  6026. this._currentOutlineItemCapability = null;
  6027. }
  6028. _dispatchEvent(outlineCount) {
  6029. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  6030. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  6031. this._currentOutlineItemCapability.resolve(false);
  6032. } else if (this._isPagesLoaded !== null) {
  6033. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6034. }
  6035. this.eventBus.dispatch("outlineloaded", {
  6036. source: this,
  6037. outlineCount,
  6038. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6039. });
  6040. }
  6041. _bindLink(element, {
  6042. url,
  6043. newWindow,
  6044. dest
  6045. }) {
  6046. const {
  6047. linkService
  6048. } = this;
  6049. if (url) {
  6050. linkService.addLinkAttributes(element, url, newWindow);
  6051. return;
  6052. }
  6053. element.href = linkService.getDestinationHash(dest);
  6054. element.onclick = evt => {
  6055. this._updateCurrentTreeItem(evt.target.parentNode);
  6056. if (dest) {
  6057. linkService.goToDestination(dest);
  6058. }
  6059. return false;
  6060. };
  6061. }
  6062. _setStyles(element, {
  6063. bold,
  6064. italic
  6065. }) {
  6066. if (bold) {
  6067. element.style.fontWeight = "bold";
  6068. }
  6069. if (italic) {
  6070. element.style.fontStyle = "italic";
  6071. }
  6072. }
  6073. _addToggleButton(div, {
  6074. count,
  6075. items
  6076. }) {
  6077. let hidden = false;
  6078. if (count < 0) {
  6079. let totalCount = items.length;
  6080. if (totalCount > 0) {
  6081. const queue = [...items];
  6082. while (queue.length > 0) {
  6083. const {
  6084. count: nestedCount,
  6085. items: nestedItems
  6086. } = queue.shift();
  6087. if (nestedCount > 0 && nestedItems.length > 0) {
  6088. totalCount += nestedItems.length;
  6089. queue.push(...nestedItems);
  6090. }
  6091. }
  6092. }
  6093. if (Math.abs(count) === totalCount) {
  6094. hidden = true;
  6095. }
  6096. }
  6097. super._addToggleButton(div, hidden);
  6098. }
  6099. _toggleAllTreeItems() {
  6100. if (!this._outline) {
  6101. return;
  6102. }
  6103. super._toggleAllTreeItems();
  6104. }
  6105. render({
  6106. outline,
  6107. pdfDocument
  6108. }) {
  6109. if (this._outline) {
  6110. this.reset();
  6111. }
  6112. this._outline = outline || null;
  6113. this._pdfDocument = pdfDocument || null;
  6114. if (!outline) {
  6115. this._dispatchEvent(0);
  6116. return;
  6117. }
  6118. const fragment = document.createDocumentFragment();
  6119. const queue = [{
  6120. parent: fragment,
  6121. items: outline
  6122. }];
  6123. let outlineCount = 0,
  6124. hasAnyNesting = false;
  6125. while (queue.length > 0) {
  6126. const levelData = queue.shift();
  6127. for (const item of levelData.items) {
  6128. const div = document.createElement("div");
  6129. div.className = "treeItem";
  6130. const element = document.createElement("a");
  6131. this._bindLink(element, item);
  6132. this._setStyles(element, item);
  6133. element.textContent = this._normalizeTextContent(item.title);
  6134. div.append(element);
  6135. if (item.items.length > 0) {
  6136. hasAnyNesting = true;
  6137. this._addToggleButton(div, item);
  6138. const itemsDiv = document.createElement("div");
  6139. itemsDiv.className = "treeItems";
  6140. div.append(itemsDiv);
  6141. queue.push({
  6142. parent: itemsDiv,
  6143. items: item.items
  6144. });
  6145. }
  6146. levelData.parent.append(div);
  6147. outlineCount++;
  6148. }
  6149. }
  6150. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6151. }
  6152. async _currentOutlineItem() {
  6153. if (!this._isPagesLoaded) {
  6154. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6155. }
  6156. if (!this._outline || !this._pdfDocument) {
  6157. return;
  6158. }
  6159. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6160. if (!pageNumberToDestHash) {
  6161. return;
  6162. }
  6163. this._updateCurrentTreeItem(null);
  6164. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6165. return;
  6166. }
  6167. for (let i = this._currentPageNumber; i > 0; i--) {
  6168. const destHash = pageNumberToDestHash.get(i);
  6169. if (!destHash) {
  6170. continue;
  6171. }
  6172. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6173. if (!linkElement) {
  6174. continue;
  6175. }
  6176. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6177. break;
  6178. }
  6179. }
  6180. async _getPageNumberToDestHash(pdfDocument) {
  6181. if (this._pageNumberToDestHashCapability) {
  6182. return this._pageNumberToDestHashCapability.promise;
  6183. }
  6184. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6185. const pageNumberToDestHash = new Map(),
  6186. pageNumberNesting = new Map();
  6187. const queue = [{
  6188. nesting: 0,
  6189. items: this._outline
  6190. }];
  6191. while (queue.length > 0) {
  6192. const levelData = queue.shift(),
  6193. currentNesting = levelData.nesting;
  6194. for (const {
  6195. dest,
  6196. items
  6197. } of levelData.items) {
  6198. let explicitDest, pageNumber;
  6199. if (typeof dest === "string") {
  6200. explicitDest = await pdfDocument.getDestination(dest);
  6201. if (pdfDocument !== this._pdfDocument) {
  6202. return null;
  6203. }
  6204. } else {
  6205. explicitDest = dest;
  6206. }
  6207. if (Array.isArray(explicitDest)) {
  6208. const [destRef] = explicitDest;
  6209. if (typeof destRef === "object" && destRef !== null) {
  6210. pageNumber = this.linkService._cachedPageNumber(destRef);
  6211. if (!pageNumber) {
  6212. try {
  6213. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6214. if (pdfDocument !== this._pdfDocument) {
  6215. return null;
  6216. }
  6217. this.linkService.cachePageRef(pageNumber, destRef);
  6218. } catch (ex) {}
  6219. }
  6220. } else if (Number.isInteger(destRef)) {
  6221. pageNumber = destRef + 1;
  6222. }
  6223. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6224. const destHash = this.linkService.getDestinationHash(dest);
  6225. pageNumberToDestHash.set(pageNumber, destHash);
  6226. pageNumberNesting.set(pageNumber, currentNesting);
  6227. }
  6228. }
  6229. if (items.length > 0) {
  6230. queue.push({
  6231. nesting: currentNesting + 1,
  6232. items
  6233. });
  6234. }
  6235. }
  6236. }
  6237. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6238. return this._pageNumberToDestHashCapability.promise;
  6239. }
  6240. }
  6241. exports.PDFOutlineViewer = PDFOutlineViewer;
  6242. /***/ }),
  6243. /* 21 */
  6244. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6245. Object.defineProperty(exports, "__esModule", ({
  6246. value: true
  6247. }));
  6248. exports.PDFPresentationMode = void 0;
  6249. var _ui_utils = __webpack_require__(1);
  6250. var _pdfjsLib = __webpack_require__(5);
  6251. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6252. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6253. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6254. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6255. const PAGE_SWITCH_THRESHOLD = 0.1;
  6256. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6257. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6258. class PDFPresentationMode {
  6259. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6260. #args = null;
  6261. constructor({
  6262. container,
  6263. pdfViewer,
  6264. eventBus
  6265. }) {
  6266. this.container = container;
  6267. this.pdfViewer = pdfViewer;
  6268. this.eventBus = eventBus;
  6269. this.contextMenuOpen = false;
  6270. this.mouseScrollTimeStamp = 0;
  6271. this.mouseScrollDelta = 0;
  6272. this.touchSwipeState = null;
  6273. }
  6274. async request() {
  6275. const {
  6276. container,
  6277. pdfViewer
  6278. } = this;
  6279. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6280. return false;
  6281. }
  6282. this.#addFullscreenChangeListeners();
  6283. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6284. const promise = container.requestFullscreen();
  6285. this.#args = {
  6286. pageNumber: pdfViewer.currentPageNumber,
  6287. scaleValue: pdfViewer.currentScaleValue,
  6288. scrollMode: pdfViewer.scrollMode,
  6289. spreadMode: null,
  6290. annotationEditorMode: null
  6291. };
  6292. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6293. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6294. this.#args.spreadMode = pdfViewer.spreadMode;
  6295. }
  6296. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6297. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6298. }
  6299. try {
  6300. await promise;
  6301. pdfViewer.focus();
  6302. return true;
  6303. } catch (reason) {
  6304. this.#removeFullscreenChangeListeners();
  6305. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6306. }
  6307. return false;
  6308. }
  6309. get active() {
  6310. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6311. }
  6312. #mouseWheel(evt) {
  6313. if (!this.active) {
  6314. return;
  6315. }
  6316. evt.preventDefault();
  6317. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6318. const currentTime = Date.now();
  6319. const storedTime = this.mouseScrollTimeStamp;
  6320. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6321. return;
  6322. }
  6323. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6324. this.#resetMouseScrollState();
  6325. }
  6326. this.mouseScrollDelta += delta;
  6327. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6328. const totalDelta = this.mouseScrollDelta;
  6329. this.#resetMouseScrollState();
  6330. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6331. if (success) {
  6332. this.mouseScrollTimeStamp = currentTime;
  6333. }
  6334. }
  6335. }
  6336. #notifyStateChange(state) {
  6337. this.#state = state;
  6338. this.eventBus.dispatch("presentationmodechanged", {
  6339. source: this,
  6340. state
  6341. });
  6342. }
  6343. #enter() {
  6344. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6345. this.container.classList.add(ACTIVE_SELECTOR);
  6346. setTimeout(() => {
  6347. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6348. if (this.#args.spreadMode !== null) {
  6349. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6350. }
  6351. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6352. this.pdfViewer.currentScaleValue = "page-fit";
  6353. if (this.#args.annotationEditorMode !== null) {
  6354. this.pdfViewer.annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  6355. }
  6356. }, 0);
  6357. this.#addWindowListeners();
  6358. this.#showControls();
  6359. this.contextMenuOpen = false;
  6360. window.getSelection().removeAllRanges();
  6361. }
  6362. #exit() {
  6363. const pageNumber = this.pdfViewer.currentPageNumber;
  6364. this.container.classList.remove(ACTIVE_SELECTOR);
  6365. setTimeout(() => {
  6366. this.#removeFullscreenChangeListeners();
  6367. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6368. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6369. if (this.#args.spreadMode !== null) {
  6370. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6371. }
  6372. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6373. this.pdfViewer.currentPageNumber = pageNumber;
  6374. if (this.#args.annotationEditorMode !== null) {
  6375. this.pdfViewer.annotationEditorMode = this.#args.annotationEditorMode;
  6376. }
  6377. this.#args = null;
  6378. }, 0);
  6379. this.#removeWindowListeners();
  6380. this.#hideControls();
  6381. this.#resetMouseScrollState();
  6382. this.contextMenuOpen = false;
  6383. }
  6384. #mouseDown(evt) {
  6385. if (this.contextMenuOpen) {
  6386. this.contextMenuOpen = false;
  6387. evt.preventDefault();
  6388. return;
  6389. }
  6390. if (evt.button === 0) {
  6391. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6392. if (!isInternalLink) {
  6393. evt.preventDefault();
  6394. if (evt.shiftKey) {
  6395. this.pdfViewer.previousPage();
  6396. } else {
  6397. this.pdfViewer.nextPage();
  6398. }
  6399. }
  6400. }
  6401. }
  6402. #contextMenu() {
  6403. this.contextMenuOpen = true;
  6404. }
  6405. #showControls() {
  6406. if (this.controlsTimeout) {
  6407. clearTimeout(this.controlsTimeout);
  6408. } else {
  6409. this.container.classList.add(CONTROLS_SELECTOR);
  6410. }
  6411. this.controlsTimeout = setTimeout(() => {
  6412. this.container.classList.remove(CONTROLS_SELECTOR);
  6413. delete this.controlsTimeout;
  6414. }, DELAY_BEFORE_HIDING_CONTROLS);
  6415. }
  6416. #hideControls() {
  6417. if (!this.controlsTimeout) {
  6418. return;
  6419. }
  6420. clearTimeout(this.controlsTimeout);
  6421. this.container.classList.remove(CONTROLS_SELECTOR);
  6422. delete this.controlsTimeout;
  6423. }
  6424. #resetMouseScrollState() {
  6425. this.mouseScrollTimeStamp = 0;
  6426. this.mouseScrollDelta = 0;
  6427. }
  6428. #touchSwipe(evt) {
  6429. if (!this.active) {
  6430. return;
  6431. }
  6432. if (evt.touches.length > 1) {
  6433. this.touchSwipeState = null;
  6434. return;
  6435. }
  6436. switch (evt.type) {
  6437. case "touchstart":
  6438. this.touchSwipeState = {
  6439. startX: evt.touches[0].pageX,
  6440. startY: evt.touches[0].pageY,
  6441. endX: evt.touches[0].pageX,
  6442. endY: evt.touches[0].pageY
  6443. };
  6444. break;
  6445. case "touchmove":
  6446. if (this.touchSwipeState === null) {
  6447. return;
  6448. }
  6449. this.touchSwipeState.endX = evt.touches[0].pageX;
  6450. this.touchSwipeState.endY = evt.touches[0].pageY;
  6451. evt.preventDefault();
  6452. break;
  6453. case "touchend":
  6454. if (this.touchSwipeState === null) {
  6455. return;
  6456. }
  6457. let delta = 0;
  6458. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6459. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6460. const absAngle = Math.abs(Math.atan2(dy, dx));
  6461. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6462. delta = dx;
  6463. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6464. delta = dy;
  6465. }
  6466. if (delta > 0) {
  6467. this.pdfViewer.previousPage();
  6468. } else if (delta < 0) {
  6469. this.pdfViewer.nextPage();
  6470. }
  6471. break;
  6472. }
  6473. }
  6474. #addWindowListeners() {
  6475. this.showControlsBind = this.#showControls.bind(this);
  6476. this.mouseDownBind = this.#mouseDown.bind(this);
  6477. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6478. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6479. this.contextMenuBind = this.#contextMenu.bind(this);
  6480. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6481. window.addEventListener("mousemove", this.showControlsBind);
  6482. window.addEventListener("mousedown", this.mouseDownBind);
  6483. window.addEventListener("wheel", this.mouseWheelBind, {
  6484. passive: false
  6485. });
  6486. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6487. window.addEventListener("contextmenu", this.contextMenuBind);
  6488. window.addEventListener("touchstart", this.touchSwipeBind);
  6489. window.addEventListener("touchmove", this.touchSwipeBind);
  6490. window.addEventListener("touchend", this.touchSwipeBind);
  6491. }
  6492. #removeWindowListeners() {
  6493. window.removeEventListener("mousemove", this.showControlsBind);
  6494. window.removeEventListener("mousedown", this.mouseDownBind);
  6495. window.removeEventListener("wheel", this.mouseWheelBind, {
  6496. passive: false
  6497. });
  6498. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6499. window.removeEventListener("contextmenu", this.contextMenuBind);
  6500. window.removeEventListener("touchstart", this.touchSwipeBind);
  6501. window.removeEventListener("touchmove", this.touchSwipeBind);
  6502. window.removeEventListener("touchend", this.touchSwipeBind);
  6503. delete this.showControlsBind;
  6504. delete this.mouseDownBind;
  6505. delete this.mouseWheelBind;
  6506. delete this.resetMouseScrollStateBind;
  6507. delete this.contextMenuBind;
  6508. delete this.touchSwipeBind;
  6509. }
  6510. #fullscreenChange() {
  6511. if (document.fullscreenElement) {
  6512. this.#enter();
  6513. } else {
  6514. this.#exit();
  6515. }
  6516. }
  6517. #addFullscreenChangeListeners() {
  6518. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6519. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6520. }
  6521. #removeFullscreenChangeListeners() {
  6522. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6523. delete this.fullscreenChangeBind;
  6524. }
  6525. }
  6526. exports.PDFPresentationMode = PDFPresentationMode;
  6527. /***/ }),
  6528. /* 22 */
  6529. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6530. Object.defineProperty(exports, "__esModule", ({
  6531. value: true
  6532. }));
  6533. exports.PDFRenderingQueue = void 0;
  6534. var _pdfjsLib = __webpack_require__(5);
  6535. var _ui_utils = __webpack_require__(1);
  6536. const CLEANUP_TIMEOUT = 30000;
  6537. class PDFRenderingQueue {
  6538. constructor() {
  6539. this.pdfViewer = null;
  6540. this.pdfThumbnailViewer = null;
  6541. this.onIdle = null;
  6542. this.highestPriorityPage = null;
  6543. this.idleTimeout = null;
  6544. this.printing = false;
  6545. this.isThumbnailViewEnabled = false;
  6546. }
  6547. setViewer(pdfViewer) {
  6548. this.pdfViewer = pdfViewer;
  6549. }
  6550. setThumbnailViewer(pdfThumbnailViewer) {
  6551. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6552. }
  6553. isHighestPriority(view) {
  6554. return this.highestPriorityPage === view.renderingId;
  6555. }
  6556. hasViewer() {
  6557. return !!this.pdfViewer;
  6558. }
  6559. renderHighestPriority(currentlyVisiblePages) {
  6560. if (this.idleTimeout) {
  6561. clearTimeout(this.idleTimeout);
  6562. this.idleTimeout = null;
  6563. }
  6564. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6565. return;
  6566. }
  6567. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6568. return;
  6569. }
  6570. if (this.printing) {
  6571. return;
  6572. }
  6573. if (this.onIdle) {
  6574. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6575. }
  6576. }
  6577. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6578. const visibleViews = visible.views,
  6579. numVisible = visibleViews.length;
  6580. if (numVisible === 0) {
  6581. return null;
  6582. }
  6583. for (let i = 0; i < numVisible; i++) {
  6584. const view = visibleViews[i].view;
  6585. if (!this.isViewFinished(view)) {
  6586. return view;
  6587. }
  6588. }
  6589. const firstId = visible.first.id,
  6590. lastId = visible.last.id;
  6591. if (lastId - firstId + 1 > numVisible) {
  6592. const visibleIds = visible.ids;
  6593. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6594. const holeId = scrolledDown ? firstId + i : lastId - i;
  6595. if (visibleIds.has(holeId)) {
  6596. continue;
  6597. }
  6598. const holeView = views[holeId - 1];
  6599. if (!this.isViewFinished(holeView)) {
  6600. return holeView;
  6601. }
  6602. }
  6603. }
  6604. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6605. let preRenderView = views[preRenderIndex];
  6606. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6607. return preRenderView;
  6608. }
  6609. if (preRenderExtra) {
  6610. preRenderIndex += scrolledDown ? 1 : -1;
  6611. preRenderView = views[preRenderIndex];
  6612. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6613. return preRenderView;
  6614. }
  6615. }
  6616. return null;
  6617. }
  6618. isViewFinished(view) {
  6619. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6620. }
  6621. renderView(view) {
  6622. switch (view.renderingState) {
  6623. case _ui_utils.RenderingStates.FINISHED:
  6624. return false;
  6625. case _ui_utils.RenderingStates.PAUSED:
  6626. this.highestPriorityPage = view.renderingId;
  6627. view.resume();
  6628. break;
  6629. case _ui_utils.RenderingStates.RUNNING:
  6630. this.highestPriorityPage = view.renderingId;
  6631. break;
  6632. case _ui_utils.RenderingStates.INITIAL:
  6633. this.highestPriorityPage = view.renderingId;
  6634. view.draw().finally(() => {
  6635. this.renderHighestPriority();
  6636. }).catch(reason => {
  6637. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6638. return;
  6639. }
  6640. console.error(`renderView: "${reason}"`);
  6641. });
  6642. break;
  6643. }
  6644. return true;
  6645. }
  6646. }
  6647. exports.PDFRenderingQueue = PDFRenderingQueue;
  6648. /***/ }),
  6649. /* 23 */
  6650. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6651. Object.defineProperty(exports, "__esModule", ({
  6652. value: true
  6653. }));
  6654. exports.PDFScriptingManager = void 0;
  6655. var _ui_utils = __webpack_require__(1);
  6656. var _pdfjsLib = __webpack_require__(5);
  6657. class PDFScriptingManager {
  6658. constructor({
  6659. eventBus,
  6660. sandboxBundleSrc = null,
  6661. scriptingFactory = null,
  6662. docPropertiesLookup = null
  6663. }) {
  6664. this._pdfDocument = null;
  6665. this._pdfViewer = null;
  6666. this._closeCapability = null;
  6667. this._destroyCapability = null;
  6668. this._scripting = null;
  6669. this._mouseState = Object.create(null);
  6670. this._ready = false;
  6671. this._eventBus = eventBus;
  6672. this._sandboxBundleSrc = sandboxBundleSrc;
  6673. this._scriptingFactory = scriptingFactory;
  6674. this._docPropertiesLookup = docPropertiesLookup;
  6675. }
  6676. setViewer(pdfViewer) {
  6677. this._pdfViewer = pdfViewer;
  6678. }
  6679. async setDocument(pdfDocument) {
  6680. if (this._pdfDocument) {
  6681. await this._destroyScripting();
  6682. }
  6683. this._pdfDocument = pdfDocument;
  6684. if (!pdfDocument) {
  6685. return;
  6686. }
  6687. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6688. if (!objects && !docActions) {
  6689. await this._destroyScripting();
  6690. return;
  6691. }
  6692. if (pdfDocument !== this._pdfDocument) {
  6693. return;
  6694. }
  6695. try {
  6696. this._scripting = this._createScripting();
  6697. } catch (error) {
  6698. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6699. await this._destroyScripting();
  6700. return;
  6701. }
  6702. this._internalEvents.set("updatefromsandbox", event => {
  6703. if (event?.source !== window) {
  6704. return;
  6705. }
  6706. this._updateFromSandbox(event.detail);
  6707. });
  6708. this._internalEvents.set("dispatcheventinsandbox", event => {
  6709. this._scripting?.dispatchEventInSandbox(event.detail);
  6710. });
  6711. this._internalEvents.set("pagechanging", ({
  6712. pageNumber,
  6713. previous
  6714. }) => {
  6715. if (pageNumber === previous) {
  6716. return;
  6717. }
  6718. this._dispatchPageClose(previous);
  6719. this._dispatchPageOpen(pageNumber);
  6720. });
  6721. this._internalEvents.set("pagerendered", ({
  6722. pageNumber
  6723. }) => {
  6724. if (!this._pageOpenPending.has(pageNumber)) {
  6725. return;
  6726. }
  6727. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6728. return;
  6729. }
  6730. this._dispatchPageOpen(pageNumber);
  6731. });
  6732. this._internalEvents.set("pagesdestroy", async event => {
  6733. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6734. await this._scripting?.dispatchEventInSandbox({
  6735. id: "doc",
  6736. name: "WillClose"
  6737. });
  6738. this._closeCapability?.resolve();
  6739. });
  6740. this._domEvents.set("mousedown", event => {
  6741. this._mouseState.isDown = true;
  6742. });
  6743. this._domEvents.set("mouseup", event => {
  6744. this._mouseState.isDown = false;
  6745. });
  6746. for (const [name, listener] of this._internalEvents) {
  6747. this._eventBus._on(name, listener);
  6748. }
  6749. for (const [name, listener] of this._domEvents) {
  6750. window.addEventListener(name, listener, true);
  6751. }
  6752. try {
  6753. const docProperties = await this._getDocProperties();
  6754. if (pdfDocument !== this._pdfDocument) {
  6755. return;
  6756. }
  6757. await this._scripting.createSandbox({
  6758. objects,
  6759. calculationOrder,
  6760. appInfo: {
  6761. platform: navigator.platform,
  6762. language: navigator.language
  6763. },
  6764. docInfo: { ...docProperties,
  6765. actions: docActions
  6766. }
  6767. });
  6768. this._eventBus.dispatch("sandboxcreated", {
  6769. source: this
  6770. });
  6771. } catch (error) {
  6772. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6773. await this._destroyScripting();
  6774. return;
  6775. }
  6776. await this._scripting?.dispatchEventInSandbox({
  6777. id: "doc",
  6778. name: "Open"
  6779. });
  6780. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6781. Promise.resolve().then(() => {
  6782. if (pdfDocument === this._pdfDocument) {
  6783. this._ready = true;
  6784. }
  6785. });
  6786. }
  6787. async dispatchWillSave(detail) {
  6788. return this._scripting?.dispatchEventInSandbox({
  6789. id: "doc",
  6790. name: "WillSave"
  6791. });
  6792. }
  6793. async dispatchDidSave(detail) {
  6794. return this._scripting?.dispatchEventInSandbox({
  6795. id: "doc",
  6796. name: "DidSave"
  6797. });
  6798. }
  6799. async dispatchWillPrint(detail) {
  6800. return this._scripting?.dispatchEventInSandbox({
  6801. id: "doc",
  6802. name: "WillPrint"
  6803. });
  6804. }
  6805. async dispatchDidPrint(detail) {
  6806. return this._scripting?.dispatchEventInSandbox({
  6807. id: "doc",
  6808. name: "DidPrint"
  6809. });
  6810. }
  6811. get mouseState() {
  6812. return this._mouseState;
  6813. }
  6814. get destroyPromise() {
  6815. return this._destroyCapability?.promise || null;
  6816. }
  6817. get ready() {
  6818. return this._ready;
  6819. }
  6820. get _internalEvents() {
  6821. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6822. }
  6823. get _domEvents() {
  6824. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6825. }
  6826. get _pageOpenPending() {
  6827. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6828. }
  6829. get _visitedPages() {
  6830. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6831. }
  6832. async _updateFromSandbox(detail) {
  6833. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6834. const {
  6835. id,
  6836. siblings,
  6837. command,
  6838. value
  6839. } = detail;
  6840. if (!id) {
  6841. switch (command) {
  6842. case "clear":
  6843. console.clear();
  6844. break;
  6845. case "error":
  6846. console.error(value);
  6847. break;
  6848. case "layout":
  6849. if (isInPresentationMode) {
  6850. return;
  6851. }
  6852. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  6853. this._pdfViewer.spreadMode = modes.spreadMode;
  6854. break;
  6855. case "page-num":
  6856. this._pdfViewer.currentPageNumber = value + 1;
  6857. break;
  6858. case "print":
  6859. await this._pdfViewer.pagesPromise;
  6860. this._eventBus.dispatch("print", {
  6861. source: this
  6862. });
  6863. break;
  6864. case "println":
  6865. console.log(value);
  6866. break;
  6867. case "zoom":
  6868. if (isInPresentationMode) {
  6869. return;
  6870. }
  6871. this._pdfViewer.currentScaleValue = value;
  6872. break;
  6873. case "SaveAs":
  6874. this._eventBus.dispatch("download", {
  6875. source: this
  6876. });
  6877. break;
  6878. case "FirstPage":
  6879. this._pdfViewer.currentPageNumber = 1;
  6880. break;
  6881. case "LastPage":
  6882. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  6883. break;
  6884. case "NextPage":
  6885. this._pdfViewer.nextPage();
  6886. break;
  6887. case "PrevPage":
  6888. this._pdfViewer.previousPage();
  6889. break;
  6890. case "ZoomViewIn":
  6891. if (isInPresentationMode) {
  6892. return;
  6893. }
  6894. this._pdfViewer.increaseScale();
  6895. break;
  6896. case "ZoomViewOut":
  6897. if (isInPresentationMode) {
  6898. return;
  6899. }
  6900. this._pdfViewer.decreaseScale();
  6901. break;
  6902. }
  6903. return;
  6904. }
  6905. if (isInPresentationMode) {
  6906. if (detail.focus) {
  6907. return;
  6908. }
  6909. }
  6910. delete detail.id;
  6911. delete detail.siblings;
  6912. const ids = siblings ? [id, ...siblings] : [id];
  6913. for (const elementId of ids) {
  6914. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  6915. if (element) {
  6916. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6917. detail
  6918. }));
  6919. } else {
  6920. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6921. }
  6922. }
  6923. }
  6924. async _dispatchPageOpen(pageNumber, initialize = false) {
  6925. const pdfDocument = this._pdfDocument,
  6926. visitedPages = this._visitedPages;
  6927. if (initialize) {
  6928. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6929. }
  6930. if (!this._closeCapability) {
  6931. return;
  6932. }
  6933. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6934. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  6935. this._pageOpenPending.add(pageNumber);
  6936. return;
  6937. }
  6938. this._pageOpenPending.delete(pageNumber);
  6939. const actionsPromise = (async () => {
  6940. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6941. if (pdfDocument !== this._pdfDocument) {
  6942. return;
  6943. }
  6944. await this._scripting?.dispatchEventInSandbox({
  6945. id: "page",
  6946. name: "PageOpen",
  6947. pageNumber,
  6948. actions
  6949. });
  6950. })();
  6951. visitedPages.set(pageNumber, actionsPromise);
  6952. }
  6953. async _dispatchPageClose(pageNumber) {
  6954. const pdfDocument = this._pdfDocument,
  6955. visitedPages = this._visitedPages;
  6956. if (!this._closeCapability) {
  6957. return;
  6958. }
  6959. if (this._pageOpenPending.has(pageNumber)) {
  6960. return;
  6961. }
  6962. const actionsPromise = visitedPages.get(pageNumber);
  6963. if (!actionsPromise) {
  6964. return;
  6965. }
  6966. visitedPages.set(pageNumber, null);
  6967. await actionsPromise;
  6968. if (pdfDocument !== this._pdfDocument) {
  6969. return;
  6970. }
  6971. await this._scripting?.dispatchEventInSandbox({
  6972. id: "page",
  6973. name: "PageClose",
  6974. pageNumber
  6975. });
  6976. }
  6977. async _getDocProperties() {
  6978. if (this._docPropertiesLookup) {
  6979. return this._docPropertiesLookup(this._pdfDocument);
  6980. }
  6981. throw new Error("_getDocProperties: Unable to lookup properties.");
  6982. }
  6983. _createScripting() {
  6984. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  6985. if (this._scripting) {
  6986. throw new Error("_createScripting: Scripting already exists.");
  6987. }
  6988. if (this._scriptingFactory) {
  6989. return this._scriptingFactory.createScripting({
  6990. sandboxBundleSrc: this._sandboxBundleSrc
  6991. });
  6992. }
  6993. throw new Error("_createScripting: Cannot create scripting.");
  6994. }
  6995. async _destroyScripting() {
  6996. if (!this._scripting) {
  6997. this._pdfDocument = null;
  6998. this._destroyCapability?.resolve();
  6999. return;
  7000. }
  7001. if (this._closeCapability) {
  7002. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  7003. setTimeout(resolve, 1000);
  7004. })]).catch(reason => {});
  7005. this._closeCapability = null;
  7006. }
  7007. this._pdfDocument = null;
  7008. try {
  7009. await this._scripting.destroySandbox();
  7010. } catch (ex) {}
  7011. for (const [name, listener] of this._internalEvents) {
  7012. this._eventBus._off(name, listener);
  7013. }
  7014. this._internalEvents.clear();
  7015. for (const [name, listener] of this._domEvents) {
  7016. window.removeEventListener(name, listener, true);
  7017. }
  7018. this._domEvents.clear();
  7019. this._pageOpenPending.clear();
  7020. this._visitedPages.clear();
  7021. this._scripting = null;
  7022. delete this._mouseState.isDown;
  7023. this._ready = false;
  7024. this._destroyCapability?.resolve();
  7025. }
  7026. }
  7027. exports.PDFScriptingManager = PDFScriptingManager;
  7028. /***/ }),
  7029. /* 24 */
  7030. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7031. Object.defineProperty(exports, "__esModule", ({
  7032. value: true
  7033. }));
  7034. exports.PDFSidebar = void 0;
  7035. var _ui_utils = __webpack_require__(1);
  7036. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7037. class PDFSidebar {
  7038. constructor({
  7039. elements,
  7040. pdfViewer,
  7041. pdfThumbnailViewer,
  7042. eventBus,
  7043. l10n
  7044. }) {
  7045. this.isOpen = false;
  7046. this.active = _ui_utils.SidebarView.THUMBS;
  7047. this.isInitialViewSet = false;
  7048. this.isInitialEventDispatched = false;
  7049. this.onToggled = null;
  7050. this.pdfViewer = pdfViewer;
  7051. this.pdfThumbnailViewer = pdfThumbnailViewer;
  7052. this.outerContainer = elements.outerContainer;
  7053. this.sidebarContainer = elements.sidebarContainer;
  7054. this.toggleButton = elements.toggleButton;
  7055. this.thumbnailButton = elements.thumbnailButton;
  7056. this.outlineButton = elements.outlineButton;
  7057. this.attachmentsButton = elements.attachmentsButton;
  7058. this.layersButton = elements.layersButton;
  7059. this.thumbnailView = elements.thumbnailView;
  7060. this.outlineView = elements.outlineView;
  7061. this.attachmentsView = elements.attachmentsView;
  7062. this.layersView = elements.layersView;
  7063. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  7064. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7065. this.eventBus = eventBus;
  7066. this.l10n = l10n;
  7067. this.#addEventListeners();
  7068. }
  7069. reset() {
  7070. this.isInitialViewSet = false;
  7071. this.isInitialEventDispatched = false;
  7072. this.#hideUINotification(true);
  7073. this.switchView(_ui_utils.SidebarView.THUMBS);
  7074. this.outlineButton.disabled = false;
  7075. this.attachmentsButton.disabled = false;
  7076. this.layersButton.disabled = false;
  7077. this._currentOutlineItemButton.disabled = true;
  7078. }
  7079. get visibleView() {
  7080. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  7081. }
  7082. setInitialView(view = _ui_utils.SidebarView.NONE) {
  7083. if (this.isInitialViewSet) {
  7084. return;
  7085. }
  7086. this.isInitialViewSet = true;
  7087. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  7088. this.#dispatchEvent();
  7089. return;
  7090. }
  7091. this.switchView(view, true);
  7092. if (!this.isInitialEventDispatched) {
  7093. this.#dispatchEvent();
  7094. }
  7095. }
  7096. switchView(view, forceOpen = false) {
  7097. const isViewChanged = view !== this.active;
  7098. let shouldForceRendering = false;
  7099. switch (view) {
  7100. case _ui_utils.SidebarView.NONE:
  7101. if (this.isOpen) {
  7102. this.close();
  7103. }
  7104. return;
  7105. case _ui_utils.SidebarView.THUMBS:
  7106. if (this.isOpen && isViewChanged) {
  7107. shouldForceRendering = true;
  7108. }
  7109. break;
  7110. case _ui_utils.SidebarView.OUTLINE:
  7111. if (this.outlineButton.disabled) {
  7112. return;
  7113. }
  7114. break;
  7115. case _ui_utils.SidebarView.ATTACHMENTS:
  7116. if (this.attachmentsButton.disabled) {
  7117. return;
  7118. }
  7119. break;
  7120. case _ui_utils.SidebarView.LAYERS:
  7121. if (this.layersButton.disabled) {
  7122. return;
  7123. }
  7124. break;
  7125. default:
  7126. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7127. return;
  7128. }
  7129. this.active = view;
  7130. const isThumbs = view === _ui_utils.SidebarView.THUMBS,
  7131. isOutline = view === _ui_utils.SidebarView.OUTLINE,
  7132. isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS,
  7133. isLayers = view === _ui_utils.SidebarView.LAYERS;
  7134. this.thumbnailButton.classList.toggle("toggled", isThumbs);
  7135. this.outlineButton.classList.toggle("toggled", isOutline);
  7136. this.attachmentsButton.classList.toggle("toggled", isAttachments);
  7137. this.layersButton.classList.toggle("toggled", isLayers);
  7138. this.thumbnailButton.setAttribute("aria-checked", isThumbs);
  7139. this.outlineButton.setAttribute("aria-checked", isOutline);
  7140. this.attachmentsButton.setAttribute("aria-checked", isAttachments);
  7141. this.layersButton.setAttribute("aria-checked", isLayers);
  7142. this.thumbnailView.classList.toggle("hidden", !isThumbs);
  7143. this.outlineView.classList.toggle("hidden", !isOutline);
  7144. this.attachmentsView.classList.toggle("hidden", !isAttachments);
  7145. this.layersView.classList.toggle("hidden", !isLayers);
  7146. this._outlineOptionsContainer.classList.toggle("hidden", !isOutline);
  7147. if (forceOpen && !this.isOpen) {
  7148. this.open();
  7149. return;
  7150. }
  7151. if (shouldForceRendering) {
  7152. this.#updateThumbnailViewer();
  7153. this.#forceRendering();
  7154. }
  7155. if (isViewChanged) {
  7156. this.#dispatchEvent();
  7157. }
  7158. }
  7159. open() {
  7160. if (this.isOpen) {
  7161. return;
  7162. }
  7163. this.isOpen = true;
  7164. this.toggleButton.classList.add("toggled");
  7165. this.toggleButton.setAttribute("aria-expanded", "true");
  7166. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7167. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7168. this.#updateThumbnailViewer();
  7169. }
  7170. this.#forceRendering();
  7171. this.#dispatchEvent();
  7172. this.#hideUINotification();
  7173. }
  7174. close() {
  7175. if (!this.isOpen) {
  7176. return;
  7177. }
  7178. this.isOpen = false;
  7179. this.toggleButton.classList.remove("toggled");
  7180. this.toggleButton.setAttribute("aria-expanded", "false");
  7181. this.outerContainer.classList.add("sidebarMoving");
  7182. this.outerContainer.classList.remove("sidebarOpen");
  7183. this.#forceRendering();
  7184. this.#dispatchEvent();
  7185. }
  7186. toggle() {
  7187. if (this.isOpen) {
  7188. this.close();
  7189. } else {
  7190. this.open();
  7191. }
  7192. }
  7193. #dispatchEvent() {
  7194. if (this.isInitialViewSet && !this.isInitialEventDispatched) {
  7195. this.isInitialEventDispatched = true;
  7196. }
  7197. this.eventBus.dispatch("sidebarviewchanged", {
  7198. source: this,
  7199. view: this.visibleView
  7200. });
  7201. }
  7202. #forceRendering() {
  7203. if (this.onToggled) {
  7204. this.onToggled();
  7205. } else {
  7206. this.pdfViewer.forceRendering();
  7207. this.pdfThumbnailViewer.forceRendering();
  7208. }
  7209. }
  7210. #updateThumbnailViewer() {
  7211. const {
  7212. pdfViewer,
  7213. pdfThumbnailViewer
  7214. } = this;
  7215. const pagesCount = pdfViewer.pagesCount;
  7216. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  7217. const pageView = pdfViewer.getPageView(pageIndex);
  7218. if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) {
  7219. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  7220. thumbnailView.setImage(pageView);
  7221. }
  7222. }
  7223. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  7224. }
  7225. #showUINotification() {
  7226. this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
  7227. this.toggleButton.title = msg;
  7228. });
  7229. if (!this.isOpen) {
  7230. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7231. }
  7232. }
  7233. #hideUINotification(reset = false) {
  7234. if (this.isOpen || reset) {
  7235. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7236. }
  7237. if (reset) {
  7238. this.l10n.get("toggle_sidebar.title").then(msg => {
  7239. this.toggleButton.title = msg;
  7240. });
  7241. }
  7242. }
  7243. #addEventListeners() {
  7244. this.sidebarContainer.addEventListener("transitionend", evt => {
  7245. if (evt.target === this.sidebarContainer) {
  7246. this.outerContainer.classList.remove("sidebarMoving");
  7247. }
  7248. });
  7249. this.toggleButton.addEventListener("click", () => {
  7250. this.toggle();
  7251. });
  7252. this.thumbnailButton.addEventListener("click", () => {
  7253. this.switchView(_ui_utils.SidebarView.THUMBS);
  7254. });
  7255. this.outlineButton.addEventListener("click", () => {
  7256. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7257. });
  7258. this.outlineButton.addEventListener("dblclick", () => {
  7259. this.eventBus.dispatch("toggleoutlinetree", {
  7260. source: this
  7261. });
  7262. });
  7263. this.attachmentsButton.addEventListener("click", () => {
  7264. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7265. });
  7266. this.layersButton.addEventListener("click", () => {
  7267. this.switchView(_ui_utils.SidebarView.LAYERS);
  7268. });
  7269. this.layersButton.addEventListener("dblclick", () => {
  7270. this.eventBus.dispatch("resetlayers", {
  7271. source: this
  7272. });
  7273. });
  7274. this._currentOutlineItemButton.addEventListener("click", () => {
  7275. this.eventBus.dispatch("currentoutlineitem", {
  7276. source: this
  7277. });
  7278. });
  7279. const onTreeLoaded = (count, button, view) => {
  7280. button.disabled = !count;
  7281. if (count) {
  7282. this.#showUINotification();
  7283. } else if (this.active === view) {
  7284. this.switchView(_ui_utils.SidebarView.THUMBS);
  7285. }
  7286. };
  7287. this.eventBus._on("outlineloaded", evt => {
  7288. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7289. evt.currentOutlineItemPromise.then(enabled => {
  7290. if (!this.isInitialViewSet) {
  7291. return;
  7292. }
  7293. this._currentOutlineItemButton.disabled = !enabled;
  7294. });
  7295. });
  7296. this.eventBus._on("attachmentsloaded", evt => {
  7297. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7298. });
  7299. this.eventBus._on("layersloaded", evt => {
  7300. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7301. });
  7302. this.eventBus._on("presentationmodechanged", evt => {
  7303. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  7304. this.#updateThumbnailViewer();
  7305. }
  7306. });
  7307. }
  7308. }
  7309. exports.PDFSidebar = PDFSidebar;
  7310. /***/ }),
  7311. /* 25 */
  7312. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7313. Object.defineProperty(exports, "__esModule", ({
  7314. value: true
  7315. }));
  7316. exports.PDFSidebarResizer = void 0;
  7317. var _ui_utils = __webpack_require__(1);
  7318. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7319. const SIDEBAR_MIN_WIDTH = 200;
  7320. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7321. class PDFSidebarResizer {
  7322. constructor(options, eventBus, l10n) {
  7323. this.isRTL = false;
  7324. this.sidebarOpen = false;
  7325. this._width = null;
  7326. this._outerContainerWidth = null;
  7327. this._boundEvents = Object.create(null);
  7328. this.outerContainer = options.outerContainer;
  7329. this.resizer = options.resizer;
  7330. this.eventBus = eventBus;
  7331. l10n.getDirection().then(dir => {
  7332. this.isRTL = dir === "rtl";
  7333. });
  7334. this._addEventListeners();
  7335. }
  7336. get outerContainerWidth() {
  7337. return this._outerContainerWidth ||= this.outerContainer.clientWidth;
  7338. }
  7339. _updateWidth(width = 0) {
  7340. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7341. if (width > maxWidth) {
  7342. width = maxWidth;
  7343. }
  7344. if (width < SIDEBAR_MIN_WIDTH) {
  7345. width = SIDEBAR_MIN_WIDTH;
  7346. }
  7347. if (width === this._width) {
  7348. return false;
  7349. }
  7350. this._width = width;
  7351. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7352. return true;
  7353. }
  7354. _mouseMove(evt) {
  7355. let width = evt.clientX;
  7356. if (this.isRTL) {
  7357. width = this.outerContainerWidth - width;
  7358. }
  7359. this._updateWidth(width);
  7360. }
  7361. _mouseUp(evt) {
  7362. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7363. this.eventBus.dispatch("resize", {
  7364. source: this
  7365. });
  7366. const _boundEvents = this._boundEvents;
  7367. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7368. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7369. }
  7370. _addEventListeners() {
  7371. const _boundEvents = this._boundEvents;
  7372. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7373. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7374. this.resizer.addEventListener("mousedown", evt => {
  7375. if (evt.button !== 0) {
  7376. return;
  7377. }
  7378. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7379. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7380. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7381. });
  7382. this.eventBus._on("sidebarviewchanged", evt => {
  7383. this.sidebarOpen = !!evt?.view;
  7384. });
  7385. this.eventBus._on("resize", evt => {
  7386. if (evt?.source !== window) {
  7387. return;
  7388. }
  7389. this._outerContainerWidth = null;
  7390. if (!this._width) {
  7391. return;
  7392. }
  7393. if (!this.sidebarOpen) {
  7394. this._updateWidth(this._width);
  7395. return;
  7396. }
  7397. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7398. const updated = this._updateWidth(this._width);
  7399. Promise.resolve().then(() => {
  7400. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7401. if (updated) {
  7402. this.eventBus.dispatch("resize", {
  7403. source: this
  7404. });
  7405. }
  7406. });
  7407. });
  7408. }
  7409. }
  7410. exports.PDFSidebarResizer = PDFSidebarResizer;
  7411. /***/ }),
  7412. /* 26 */
  7413. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7414. Object.defineProperty(exports, "__esModule", ({
  7415. value: true
  7416. }));
  7417. exports.PDFThumbnailViewer = void 0;
  7418. var _ui_utils = __webpack_require__(1);
  7419. var _pdf_thumbnail_view = __webpack_require__(27);
  7420. const THUMBNAIL_SCROLL_MARGIN = -19;
  7421. const THUMBNAIL_SELECTED_CLASS = "selected";
  7422. class PDFThumbnailViewer {
  7423. constructor({
  7424. container,
  7425. eventBus,
  7426. linkService,
  7427. renderingQueue,
  7428. l10n,
  7429. pageColors
  7430. }) {
  7431. this.container = container;
  7432. this.linkService = linkService;
  7433. this.renderingQueue = renderingQueue;
  7434. this.l10n = l10n;
  7435. this.pageColors = pageColors || null;
  7436. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  7437. if (this.pageColors.background || this.pageColors.foreground) {
  7438. console.warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  7439. }
  7440. this.pageColors = null;
  7441. }
  7442. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7443. this._resetView();
  7444. }
  7445. _scrollUpdated() {
  7446. this.renderingQueue.renderHighestPriority();
  7447. }
  7448. getThumbnail(index) {
  7449. return this._thumbnails[index];
  7450. }
  7451. _getVisibleThumbs() {
  7452. return (0, _ui_utils.getVisibleElements)({
  7453. scrollEl: this.container,
  7454. views: this._thumbnails
  7455. });
  7456. }
  7457. scrollThumbnailIntoView(pageNumber) {
  7458. if (!this.pdfDocument) {
  7459. return;
  7460. }
  7461. const thumbnailView = this._thumbnails[pageNumber - 1];
  7462. if (!thumbnailView) {
  7463. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7464. return;
  7465. }
  7466. if (pageNumber !== this._currentPageNumber) {
  7467. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7468. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7469. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7470. }
  7471. const {
  7472. first,
  7473. last,
  7474. views
  7475. } = this._getVisibleThumbs();
  7476. if (views.length > 0) {
  7477. let shouldScroll = false;
  7478. if (pageNumber <= first.id || pageNumber >= last.id) {
  7479. shouldScroll = true;
  7480. } else {
  7481. for (const {
  7482. id,
  7483. percent
  7484. } of views) {
  7485. if (id !== pageNumber) {
  7486. continue;
  7487. }
  7488. shouldScroll = percent < 100;
  7489. break;
  7490. }
  7491. }
  7492. if (shouldScroll) {
  7493. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7494. top: THUMBNAIL_SCROLL_MARGIN
  7495. });
  7496. }
  7497. }
  7498. this._currentPageNumber = pageNumber;
  7499. }
  7500. get pagesRotation() {
  7501. return this._pagesRotation;
  7502. }
  7503. set pagesRotation(rotation) {
  7504. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7505. throw new Error("Invalid thumbnails rotation angle.");
  7506. }
  7507. if (!this.pdfDocument) {
  7508. return;
  7509. }
  7510. if (this._pagesRotation === rotation) {
  7511. return;
  7512. }
  7513. this._pagesRotation = rotation;
  7514. const updateArgs = {
  7515. rotation
  7516. };
  7517. for (const thumbnail of this._thumbnails) {
  7518. thumbnail.update(updateArgs);
  7519. }
  7520. }
  7521. cleanup() {
  7522. for (const thumbnail of this._thumbnails) {
  7523. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7524. thumbnail.reset();
  7525. }
  7526. }
  7527. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7528. }
  7529. _resetView() {
  7530. this._thumbnails = [];
  7531. this._currentPageNumber = 1;
  7532. this._pageLabels = null;
  7533. this._pagesRotation = 0;
  7534. this.container.textContent = "";
  7535. }
  7536. setDocument(pdfDocument) {
  7537. if (this.pdfDocument) {
  7538. this._cancelRendering();
  7539. this._resetView();
  7540. }
  7541. this.pdfDocument = pdfDocument;
  7542. if (!pdfDocument) {
  7543. return;
  7544. }
  7545. const firstPagePromise = pdfDocument.getPage(1);
  7546. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7547. firstPagePromise.then(firstPdfPage => {
  7548. const pagesCount = pdfDocument.numPages;
  7549. const viewport = firstPdfPage.getViewport({
  7550. scale: 1
  7551. });
  7552. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7553. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7554. container: this.container,
  7555. id: pageNum,
  7556. defaultViewport: viewport.clone(),
  7557. optionalContentConfigPromise,
  7558. linkService: this.linkService,
  7559. renderingQueue: this.renderingQueue,
  7560. l10n: this.l10n,
  7561. pageColors: this.pageColors
  7562. });
  7563. this._thumbnails.push(thumbnail);
  7564. }
  7565. const firstThumbnailView = this._thumbnails[0];
  7566. if (firstThumbnailView) {
  7567. firstThumbnailView.setPdfPage(firstPdfPage);
  7568. }
  7569. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7570. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7571. }).catch(reason => {
  7572. console.error("Unable to initialize thumbnail viewer", reason);
  7573. });
  7574. }
  7575. _cancelRendering() {
  7576. for (const thumbnail of this._thumbnails) {
  7577. thumbnail.cancelRendering();
  7578. }
  7579. }
  7580. setPageLabels(labels) {
  7581. if (!this.pdfDocument) {
  7582. return;
  7583. }
  7584. if (!labels) {
  7585. this._pageLabels = null;
  7586. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7587. this._pageLabels = null;
  7588. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7589. } else {
  7590. this._pageLabels = labels;
  7591. }
  7592. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7593. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7594. }
  7595. }
  7596. async #ensurePdfPageLoaded(thumbView) {
  7597. if (thumbView.pdfPage) {
  7598. return thumbView.pdfPage;
  7599. }
  7600. try {
  7601. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7602. if (!thumbView.pdfPage) {
  7603. thumbView.setPdfPage(pdfPage);
  7604. }
  7605. return pdfPage;
  7606. } catch (reason) {
  7607. console.error("Unable to get page for thumb view", reason);
  7608. return null;
  7609. }
  7610. }
  7611. #getScrollAhead(visible) {
  7612. if (visible.first?.id === 1) {
  7613. return true;
  7614. } else if (visible.last?.id === this._thumbnails.length) {
  7615. return false;
  7616. }
  7617. return this.scroll.down;
  7618. }
  7619. forceRendering() {
  7620. const visibleThumbs = this._getVisibleThumbs();
  7621. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7622. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7623. if (thumbView) {
  7624. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7625. this.renderingQueue.renderView(thumbView);
  7626. });
  7627. return true;
  7628. }
  7629. return false;
  7630. }
  7631. }
  7632. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7633. /***/ }),
  7634. /* 27 */
  7635. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7636. Object.defineProperty(exports, "__esModule", ({
  7637. value: true
  7638. }));
  7639. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7640. var _ui_utils = __webpack_require__(1);
  7641. var _pdfjsLib = __webpack_require__(5);
  7642. const DRAW_UPSCALE_FACTOR = 2;
  7643. const MAX_NUM_SCALING_STEPS = 3;
  7644. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7645. const THUMBNAIL_WIDTH = 98;
  7646. class TempImageFactory {
  7647. static #tempCanvas = null;
  7648. static getCanvas(width, height) {
  7649. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7650. tempCanvas.width = width;
  7651. tempCanvas.height = height;
  7652. const ctx = tempCanvas.getContext("2d", {
  7653. alpha: false
  7654. });
  7655. ctx.save();
  7656. ctx.fillStyle = "rgb(255, 255, 255)";
  7657. ctx.fillRect(0, 0, width, height);
  7658. ctx.restore();
  7659. return [tempCanvas, tempCanvas.getContext("2d")];
  7660. }
  7661. static destroyCanvas() {
  7662. const tempCanvas = this.#tempCanvas;
  7663. if (tempCanvas) {
  7664. tempCanvas.width = 0;
  7665. tempCanvas.height = 0;
  7666. }
  7667. this.#tempCanvas = null;
  7668. }
  7669. }
  7670. exports.TempImageFactory = TempImageFactory;
  7671. class PDFThumbnailView {
  7672. constructor({
  7673. container,
  7674. id,
  7675. defaultViewport,
  7676. optionalContentConfigPromise,
  7677. linkService,
  7678. renderingQueue,
  7679. l10n,
  7680. pageColors
  7681. }) {
  7682. this.id = id;
  7683. this.renderingId = "thumbnail" + id;
  7684. this.pageLabel = null;
  7685. this.pdfPage = null;
  7686. this.rotation = 0;
  7687. this.viewport = defaultViewport;
  7688. this.pdfPageRotate = defaultViewport.rotation;
  7689. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7690. this.pageColors = pageColors || null;
  7691. this.linkService = linkService;
  7692. this.renderingQueue = renderingQueue;
  7693. this.renderTask = null;
  7694. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7695. this.resume = null;
  7696. const pageWidth = this.viewport.width,
  7697. pageHeight = this.viewport.height,
  7698. pageRatio = pageWidth / pageHeight;
  7699. this.canvasWidth = THUMBNAIL_WIDTH;
  7700. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7701. this.scale = this.canvasWidth / pageWidth;
  7702. this.l10n = l10n;
  7703. const anchor = document.createElement("a");
  7704. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7705. this._thumbPageTitle.then(msg => {
  7706. anchor.title = msg;
  7707. });
  7708. anchor.onclick = function () {
  7709. linkService.goToPage(id);
  7710. return false;
  7711. };
  7712. this.anchor = anchor;
  7713. const div = document.createElement("div");
  7714. div.className = "thumbnail";
  7715. div.setAttribute("data-page-number", this.id);
  7716. this.div = div;
  7717. const ring = document.createElement("div");
  7718. ring.className = "thumbnailSelectionRing";
  7719. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7720. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7721. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7722. this.ring = ring;
  7723. div.append(ring);
  7724. anchor.append(div);
  7725. container.append(anchor);
  7726. }
  7727. setPdfPage(pdfPage) {
  7728. this.pdfPage = pdfPage;
  7729. this.pdfPageRotate = pdfPage.rotate;
  7730. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7731. this.viewport = pdfPage.getViewport({
  7732. scale: 1,
  7733. rotation: totalRotation
  7734. });
  7735. this.reset();
  7736. }
  7737. reset() {
  7738. this.cancelRendering();
  7739. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7740. const pageWidth = this.viewport.width,
  7741. pageHeight = this.viewport.height,
  7742. pageRatio = pageWidth / pageHeight;
  7743. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7744. this.scale = this.canvasWidth / pageWidth;
  7745. this.div.removeAttribute("data-loaded");
  7746. const ring = this.ring;
  7747. ring.textContent = "";
  7748. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7749. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7750. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7751. if (this.canvas) {
  7752. this.canvas.width = 0;
  7753. this.canvas.height = 0;
  7754. delete this.canvas;
  7755. }
  7756. if (this.image) {
  7757. this.image.removeAttribute("src");
  7758. delete this.image;
  7759. }
  7760. }
  7761. update({
  7762. rotation = null
  7763. }) {
  7764. if (typeof rotation === "number") {
  7765. this.rotation = rotation;
  7766. }
  7767. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7768. this.viewport = this.viewport.clone({
  7769. scale: 1,
  7770. rotation: totalRotation
  7771. });
  7772. this.reset();
  7773. }
  7774. cancelRendering() {
  7775. if (this.renderTask) {
  7776. this.renderTask.cancel();
  7777. this.renderTask = null;
  7778. }
  7779. this.resume = null;
  7780. }
  7781. _getPageDrawContext(upscaleFactor = 1) {
  7782. const canvas = document.createElement("canvas");
  7783. const ctx = canvas.getContext("2d", {
  7784. alpha: false
  7785. });
  7786. const outputScale = new _ui_utils.OutputScale();
  7787. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7788. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7789. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7790. return {
  7791. ctx,
  7792. canvas,
  7793. transform
  7794. };
  7795. }
  7796. _convertCanvasToImage(canvas) {
  7797. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7798. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  7799. }
  7800. const reducedCanvas = this._reduceImage(canvas);
  7801. const image = document.createElement("img");
  7802. image.className = "thumbnailImage";
  7803. this._thumbPageCanvas.then(msg => {
  7804. image.setAttribute("aria-label", msg);
  7805. });
  7806. image.style.width = this.canvasWidth + "px";
  7807. image.style.height = this.canvasHeight + "px";
  7808. image.src = reducedCanvas.toDataURL();
  7809. this.image = image;
  7810. this.div.setAttribute("data-loaded", true);
  7811. this.ring.append(image);
  7812. reducedCanvas.width = 0;
  7813. reducedCanvas.height = 0;
  7814. }
  7815. draw() {
  7816. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7817. console.error("Must be in new state before drawing");
  7818. return Promise.resolve();
  7819. }
  7820. const {
  7821. pdfPage
  7822. } = this;
  7823. if (!pdfPage) {
  7824. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7825. return Promise.reject(new Error("pdfPage is not loaded"));
  7826. }
  7827. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7828. const finishRenderTask = async (error = null) => {
  7829. if (renderTask === this.renderTask) {
  7830. this.renderTask = null;
  7831. }
  7832. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7833. return;
  7834. }
  7835. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7836. this._convertCanvasToImage(canvas);
  7837. if (error) {
  7838. throw error;
  7839. }
  7840. };
  7841. const {
  7842. ctx,
  7843. canvas,
  7844. transform
  7845. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7846. const drawViewport = this.viewport.clone({
  7847. scale: DRAW_UPSCALE_FACTOR * this.scale
  7848. });
  7849. const renderContinueCallback = cont => {
  7850. if (!this.renderingQueue.isHighestPriority(this)) {
  7851. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  7852. this.resume = () => {
  7853. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7854. cont();
  7855. };
  7856. return;
  7857. }
  7858. cont();
  7859. };
  7860. const renderContext = {
  7861. canvasContext: ctx,
  7862. transform,
  7863. viewport: drawViewport,
  7864. optionalContentConfigPromise: this._optionalContentConfigPromise,
  7865. pageColors: this.pageColors
  7866. };
  7867. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7868. renderTask.onContinue = renderContinueCallback;
  7869. const resultPromise = renderTask.promise.then(function () {
  7870. return finishRenderTask(null);
  7871. }, function (error) {
  7872. return finishRenderTask(error);
  7873. });
  7874. resultPromise.finally(() => {
  7875. canvas.width = 0;
  7876. canvas.height = 0;
  7877. const pageCached = this.linkService.isPageCached(this.id);
  7878. if (!pageCached) {
  7879. this.pdfPage?.cleanup();
  7880. }
  7881. });
  7882. return resultPromise;
  7883. }
  7884. setImage(pageView) {
  7885. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7886. return;
  7887. }
  7888. const {
  7889. thumbnailCanvas: canvas,
  7890. pdfPage,
  7891. scale
  7892. } = pageView;
  7893. if (!canvas) {
  7894. return;
  7895. }
  7896. if (!this.pdfPage) {
  7897. this.setPdfPage(pdfPage);
  7898. }
  7899. if (scale < this.scale) {
  7900. return;
  7901. }
  7902. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7903. this._convertCanvasToImage(canvas);
  7904. }
  7905. _reduceImage(img) {
  7906. const {
  7907. ctx,
  7908. canvas
  7909. } = this._getPageDrawContext();
  7910. if (img.width <= 2 * canvas.width) {
  7911. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7912. return canvas;
  7913. }
  7914. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7915. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7916. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7917. while (reducedWidth > img.width || reducedHeight > img.height) {
  7918. reducedWidth >>= 1;
  7919. reducedHeight >>= 1;
  7920. }
  7921. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7922. while (reducedWidth > 2 * canvas.width) {
  7923. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7924. reducedWidth >>= 1;
  7925. reducedHeight >>= 1;
  7926. }
  7927. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7928. return canvas;
  7929. }
  7930. get _thumbPageTitle() {
  7931. return this.l10n.get("thumb_page_title", {
  7932. page: this.pageLabel ?? this.id
  7933. });
  7934. }
  7935. get _thumbPageCanvas() {
  7936. return this.l10n.get("thumb_page_canvas", {
  7937. page: this.pageLabel ?? this.id
  7938. });
  7939. }
  7940. setPageLabel(label) {
  7941. this.pageLabel = typeof label === "string" ? label : null;
  7942. this._thumbPageTitle.then(msg => {
  7943. this.anchor.title = msg;
  7944. });
  7945. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7946. return;
  7947. }
  7948. this._thumbPageCanvas.then(msg => {
  7949. this.image?.setAttribute("aria-label", msg);
  7950. });
  7951. }
  7952. }
  7953. exports.PDFThumbnailView = PDFThumbnailView;
  7954. /***/ }),
  7955. /* 28 */
  7956. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7957. Object.defineProperty(exports, "__esModule", ({
  7958. value: true
  7959. }));
  7960. exports.PDFViewer = exports.PDFSinglePageViewer = void 0;
  7961. var _ui_utils = __webpack_require__(1);
  7962. var _base_viewer = __webpack_require__(29);
  7963. class PDFViewer extends _base_viewer.BaseViewer {}
  7964. exports.PDFViewer = PDFViewer;
  7965. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  7966. _resetView() {
  7967. super._resetView();
  7968. this._scrollMode = _ui_utils.ScrollMode.PAGE;
  7969. this._spreadMode = _ui_utils.SpreadMode.NONE;
  7970. }
  7971. set scrollMode(mode) {}
  7972. _updateScrollMode() {}
  7973. set spreadMode(mode) {}
  7974. _updateSpreadMode() {}
  7975. }
  7976. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  7977. /***/ }),
  7978. /* 29 */
  7979. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7980. Object.defineProperty(exports, "__esModule", ({
  7981. value: true
  7982. }));
  7983. exports.PagesCountLimit = exports.PDFPageViewBuffer = exports.BaseViewer = void 0;
  7984. var _pdfjsLib = __webpack_require__(5);
  7985. var _ui_utils = __webpack_require__(1);
  7986. var _annotation_editor_layer_builder = __webpack_require__(30);
  7987. var _annotation_layer_builder = __webpack_require__(32);
  7988. var _l10n_utils = __webpack_require__(31);
  7989. var _pdf_page_view = __webpack_require__(33);
  7990. var _pdf_rendering_queue = __webpack_require__(22);
  7991. var _pdf_link_service = __webpack_require__(3);
  7992. var _struct_tree_layer_builder = __webpack_require__(35);
  7993. var _text_highlighter = __webpack_require__(36);
  7994. var _text_layer_builder = __webpack_require__(37);
  7995. var _xfa_layer_builder = __webpack_require__(38);
  7996. const DEFAULT_CACHE_SIZE = 10;
  7997. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  7998. const PagesCountLimit = {
  7999. FORCE_SCROLL_MODE_PAGE: 15000,
  8000. FORCE_LAZY_PAGE_INIT: 7500,
  8001. PAUSE_EAGER_PAGE_INIT: 250
  8002. };
  8003. exports.PagesCountLimit = PagesCountLimit;
  8004. function isValidAnnotationEditorMode(mode) {
  8005. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  8006. }
  8007. class PDFPageViewBuffer {
  8008. #buf = new Set();
  8009. #size = 0;
  8010. constructor(size) {
  8011. this.#size = size;
  8012. }
  8013. push(view) {
  8014. const buf = this.#buf;
  8015. if (buf.has(view)) {
  8016. buf.delete(view);
  8017. }
  8018. buf.add(view);
  8019. if (buf.size > this.#size) {
  8020. this.#destroyFirstView();
  8021. }
  8022. }
  8023. resize(newSize, idsToKeep = null) {
  8024. this.#size = newSize;
  8025. const buf = this.#buf;
  8026. if (idsToKeep) {
  8027. const ii = buf.size;
  8028. let i = 1;
  8029. for (const view of buf) {
  8030. if (idsToKeep.has(view.id)) {
  8031. buf.delete(view);
  8032. buf.add(view);
  8033. }
  8034. if (++i > ii) {
  8035. break;
  8036. }
  8037. }
  8038. }
  8039. while (buf.size > this.#size) {
  8040. this.#destroyFirstView();
  8041. }
  8042. }
  8043. has(view) {
  8044. return this.#buf.has(view);
  8045. }
  8046. [Symbol.iterator]() {
  8047. return this.#buf.keys();
  8048. }
  8049. #destroyFirstView() {
  8050. const firstView = this.#buf.keys().next().value;
  8051. firstView?.destroy();
  8052. this.#buf.delete(firstView);
  8053. }
  8054. }
  8055. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  8056. class BaseViewer {
  8057. #buffer = null;
  8058. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8059. #annotationEditorUIManager = null;
  8060. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8061. #enablePermissions = false;
  8062. #previousContainerHeight = 0;
  8063. #scrollModePageState = null;
  8064. #onVisibilityChange = null;
  8065. constructor(options) {
  8066. if (this.constructor === BaseViewer) {
  8067. throw new Error("Cannot initialize BaseViewer.");
  8068. }
  8069. const viewerVersion = '2.16.105';
  8070. if (_pdfjsLib.version !== viewerVersion) {
  8071. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  8072. }
  8073. this.container = options.container;
  8074. this.viewer = options.viewer || options.container.firstElementChild;
  8075. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  8076. throw new Error("Invalid `container` and/or `viewer` option.");
  8077. }
  8078. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  8079. throw new Error("The `container` must be absolutely positioned.");
  8080. }
  8081. this.eventBus = options.eventBus;
  8082. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8083. this.downloadManager = options.downloadManager || null;
  8084. this.findController = options.findController || null;
  8085. this._scriptingManager = options.scriptingManager || null;
  8086. this.removePageBorders = options.removePageBorders || false;
  8087. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  8088. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8089. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.DISABLE;
  8090. this.imageResourcesPath = options.imageResourcesPath || "";
  8091. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8092. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  8093. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  8094. this.maxCanvasPixels = options.maxCanvasPixels;
  8095. this.l10n = options.l10n || _l10n_utils.NullL10n;
  8096. this.#enablePermissions = options.enablePermissions || false;
  8097. this.pageColors = options.pageColors || null;
  8098. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  8099. if (this.pageColors.background || this.pageColors.foreground) {
  8100. console.warn("BaseViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  8101. }
  8102. this.pageColors = null;
  8103. }
  8104. this.defaultRenderingQueue = !options.renderingQueue;
  8105. if (this.defaultRenderingQueue) {
  8106. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8107. this.renderingQueue.setViewer(this);
  8108. } else {
  8109. this.renderingQueue = options.renderingQueue;
  8110. }
  8111. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8112. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8113. this._onBeforeDraw = this._onAfterDraw = null;
  8114. this._resetView();
  8115. if (this.removePageBorders) {
  8116. this.viewer.classList.add("removePageBorders");
  8117. }
  8118. this.updateContainerHeightCss();
  8119. }
  8120. get pagesCount() {
  8121. return this._pages.length;
  8122. }
  8123. getPageView(index) {
  8124. return this._pages[index];
  8125. }
  8126. get pageViewsReady() {
  8127. if (!this._pagesCapability.settled) {
  8128. return false;
  8129. }
  8130. return this._pages.every(function (pageView) {
  8131. return pageView?.pdfPage;
  8132. });
  8133. }
  8134. get renderForms() {
  8135. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8136. }
  8137. get enableScripting() {
  8138. return !!this._scriptingManager;
  8139. }
  8140. get currentPageNumber() {
  8141. return this._currentPageNumber;
  8142. }
  8143. set currentPageNumber(val) {
  8144. if (!Number.isInteger(val)) {
  8145. throw new Error("Invalid page number.");
  8146. }
  8147. if (!this.pdfDocument) {
  8148. return;
  8149. }
  8150. if (!this._setCurrentPageNumber(val, true)) {
  8151. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  8152. }
  8153. }
  8154. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  8155. if (this._currentPageNumber === val) {
  8156. if (resetCurrentPageView) {
  8157. this.#resetCurrentPageView();
  8158. }
  8159. return true;
  8160. }
  8161. if (!(0 < val && val <= this.pagesCount)) {
  8162. return false;
  8163. }
  8164. const previous = this._currentPageNumber;
  8165. this._currentPageNumber = val;
  8166. this.eventBus.dispatch("pagechanging", {
  8167. source: this,
  8168. pageNumber: val,
  8169. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8170. previous
  8171. });
  8172. if (resetCurrentPageView) {
  8173. this.#resetCurrentPageView();
  8174. }
  8175. return true;
  8176. }
  8177. get currentPageLabel() {
  8178. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8179. }
  8180. set currentPageLabel(val) {
  8181. if (!this.pdfDocument) {
  8182. return;
  8183. }
  8184. let page = val | 0;
  8185. if (this._pageLabels) {
  8186. const i = this._pageLabels.indexOf(val);
  8187. if (i >= 0) {
  8188. page = i + 1;
  8189. }
  8190. }
  8191. if (!this._setCurrentPageNumber(page, true)) {
  8192. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8193. }
  8194. }
  8195. get currentScale() {
  8196. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8197. }
  8198. set currentScale(val) {
  8199. if (isNaN(val)) {
  8200. throw new Error("Invalid numeric scale.");
  8201. }
  8202. if (!this.pdfDocument) {
  8203. return;
  8204. }
  8205. this._setScale(val, false);
  8206. }
  8207. get currentScaleValue() {
  8208. return this._currentScaleValue;
  8209. }
  8210. set currentScaleValue(val) {
  8211. if (!this.pdfDocument) {
  8212. return;
  8213. }
  8214. this._setScale(val, false);
  8215. }
  8216. get pagesRotation() {
  8217. return this._pagesRotation;
  8218. }
  8219. set pagesRotation(rotation) {
  8220. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8221. throw new Error("Invalid pages rotation angle.");
  8222. }
  8223. if (!this.pdfDocument) {
  8224. return;
  8225. }
  8226. rotation %= 360;
  8227. if (rotation < 0) {
  8228. rotation += 360;
  8229. }
  8230. if (this._pagesRotation === rotation) {
  8231. return;
  8232. }
  8233. this._pagesRotation = rotation;
  8234. const pageNumber = this._currentPageNumber;
  8235. const updateArgs = {
  8236. rotation
  8237. };
  8238. for (const pageView of this._pages) {
  8239. pageView.update(updateArgs);
  8240. }
  8241. if (this._currentScaleValue) {
  8242. this._setScale(this._currentScaleValue, true);
  8243. }
  8244. this.eventBus.dispatch("rotationchanging", {
  8245. source: this,
  8246. pagesRotation: rotation,
  8247. pageNumber
  8248. });
  8249. if (this.defaultRenderingQueue) {
  8250. this.update();
  8251. }
  8252. }
  8253. get firstPagePromise() {
  8254. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8255. }
  8256. get onePageRendered() {
  8257. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8258. }
  8259. get pagesPromise() {
  8260. return this.pdfDocument ? this._pagesCapability.promise : null;
  8261. }
  8262. #initializePermissions(permissions) {
  8263. const params = {
  8264. annotationEditorMode: this.#annotationEditorMode,
  8265. annotationMode: this.#annotationMode,
  8266. textLayerMode: this.textLayerMode
  8267. };
  8268. if (!permissions) {
  8269. return params;
  8270. }
  8271. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  8272. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  8273. }
  8274. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  8275. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8276. }
  8277. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8278. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8279. }
  8280. return params;
  8281. }
  8282. #onePageRenderedOrForceFetch() {
  8283. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8284. return Promise.resolve();
  8285. }
  8286. const visibilityChangePromise = new Promise(resolve => {
  8287. this.#onVisibilityChange = () => {
  8288. if (document.visibilityState !== "hidden") {
  8289. return;
  8290. }
  8291. resolve();
  8292. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8293. this.#onVisibilityChange = null;
  8294. };
  8295. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8296. });
  8297. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8298. }
  8299. setDocument(pdfDocument) {
  8300. if (this.pdfDocument) {
  8301. this.eventBus.dispatch("pagesdestroy", {
  8302. source: this
  8303. });
  8304. this._cancelRendering();
  8305. this._resetView();
  8306. if (this.findController) {
  8307. this.findController.setDocument(null);
  8308. }
  8309. if (this._scriptingManager) {
  8310. this._scriptingManager.setDocument(null);
  8311. }
  8312. if (this.#annotationEditorUIManager) {
  8313. this.#annotationEditorUIManager.destroy();
  8314. this.#annotationEditorUIManager = null;
  8315. }
  8316. }
  8317. this.pdfDocument = pdfDocument;
  8318. if (!pdfDocument) {
  8319. return;
  8320. }
  8321. const isPureXfa = pdfDocument.isPureXfa;
  8322. const pagesCount = pdfDocument.numPages;
  8323. const firstPagePromise = pdfDocument.getPage(1);
  8324. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8325. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8326. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8327. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8328. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8329. this.eventBus.dispatch("scrollmodechanged", {
  8330. source: this,
  8331. mode
  8332. });
  8333. }
  8334. this._pagesCapability.promise.then(() => {
  8335. this.eventBus.dispatch("pagesloaded", {
  8336. source: this,
  8337. pagesCount
  8338. });
  8339. }, () => {});
  8340. this._onBeforeDraw = evt => {
  8341. const pageView = this._pages[evt.pageNumber - 1];
  8342. if (!pageView) {
  8343. return;
  8344. }
  8345. this.#buffer.push(pageView);
  8346. };
  8347. this.eventBus._on("pagerender", this._onBeforeDraw);
  8348. this._onAfterDraw = evt => {
  8349. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8350. return;
  8351. }
  8352. this._onePageRenderedCapability.resolve({
  8353. timestamp: evt.timestamp
  8354. });
  8355. this.eventBus._off("pagerendered", this._onAfterDraw);
  8356. this._onAfterDraw = null;
  8357. if (this.#onVisibilityChange) {
  8358. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8359. this.#onVisibilityChange = null;
  8360. }
  8361. };
  8362. this.eventBus._on("pagerendered", this._onAfterDraw);
  8363. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8364. if (pdfDocument !== this.pdfDocument) {
  8365. return;
  8366. }
  8367. this._firstPageCapability.resolve(firstPdfPage);
  8368. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8369. const {
  8370. annotationEditorMode,
  8371. annotationMode,
  8372. textLayerMode
  8373. } = this.#initializePermissions(permissions);
  8374. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  8375. const mode = annotationEditorMode;
  8376. if (isPureXfa) {
  8377. console.warn("Warning: XFA-editing is not implemented.");
  8378. } else if (isValidAnnotationEditorMode(mode)) {
  8379. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus);
  8380. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  8381. this.#annotationEditorUIManager.updateMode(mode);
  8382. }
  8383. } else {
  8384. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  8385. }
  8386. }
  8387. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8388. const scale = this.currentScale;
  8389. const viewport = firstPdfPage.getViewport({
  8390. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8391. });
  8392. const textLayerFactory = textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !isPureXfa ? this : null;
  8393. const annotationLayerFactory = annotationMode !== _pdfjsLib.AnnotationMode.DISABLE ? this : null;
  8394. const xfaLayerFactory = isPureXfa ? this : null;
  8395. const annotationEditorLayerFactory = this.#annotationEditorUIManager ? this : null;
  8396. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8397. const pageView = new _pdf_page_view.PDFPageView({
  8398. container: viewerElement,
  8399. eventBus: this.eventBus,
  8400. id: pageNum,
  8401. scale,
  8402. defaultViewport: viewport.clone(),
  8403. optionalContentConfigPromise,
  8404. renderingQueue: this.renderingQueue,
  8405. textLayerFactory,
  8406. textLayerMode,
  8407. annotationLayerFactory,
  8408. annotationMode,
  8409. xfaLayerFactory,
  8410. annotationEditorLayerFactory,
  8411. textHighlighterFactory: this,
  8412. structTreeLayerFactory: this,
  8413. imageResourcesPath: this.imageResourcesPath,
  8414. renderer: this.renderer,
  8415. useOnlyCssZoom: this.useOnlyCssZoom,
  8416. maxCanvasPixels: this.maxCanvasPixels,
  8417. pageColors: this.pageColors,
  8418. l10n: this.l10n
  8419. });
  8420. this._pages.push(pageView);
  8421. }
  8422. const firstPageView = this._pages[0];
  8423. if (firstPageView) {
  8424. firstPageView.setPdfPage(firstPdfPage);
  8425. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8426. }
  8427. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8428. this.#ensurePageViewVisible();
  8429. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8430. this._updateSpreadMode();
  8431. }
  8432. this.#onePageRenderedOrForceFetch().then(async () => {
  8433. if (this.findController) {
  8434. this.findController.setDocument(pdfDocument);
  8435. }
  8436. if (this._scriptingManager) {
  8437. this._scriptingManager.setDocument(pdfDocument);
  8438. }
  8439. if (this.#annotationEditorUIManager) {
  8440. this.eventBus.dispatch("annotationeditormodechanged", {
  8441. source: this,
  8442. mode: this.#annotationEditorMode
  8443. });
  8444. }
  8445. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8446. this._pagesCapability.resolve();
  8447. return;
  8448. }
  8449. let getPagesLeft = pagesCount - 1;
  8450. if (getPagesLeft <= 0) {
  8451. this._pagesCapability.resolve();
  8452. return;
  8453. }
  8454. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8455. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8456. const pageView = this._pages[pageNum - 1];
  8457. if (!pageView.pdfPage) {
  8458. pageView.setPdfPage(pdfPage);
  8459. }
  8460. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8461. if (--getPagesLeft === 0) {
  8462. this._pagesCapability.resolve();
  8463. }
  8464. }, reason => {
  8465. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8466. if (--getPagesLeft === 0) {
  8467. this._pagesCapability.resolve();
  8468. }
  8469. });
  8470. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8471. await promise;
  8472. }
  8473. }
  8474. });
  8475. this.eventBus.dispatch("pagesinit", {
  8476. source: this
  8477. });
  8478. pdfDocument.getMetadata().then(({
  8479. info
  8480. }) => {
  8481. if (pdfDocument !== this.pdfDocument) {
  8482. return;
  8483. }
  8484. if (info.Language) {
  8485. this.viewer.lang = info.Language;
  8486. }
  8487. });
  8488. if (this.defaultRenderingQueue) {
  8489. this.update();
  8490. }
  8491. }).catch(reason => {
  8492. console.error("Unable to initialize viewer", reason);
  8493. this._pagesCapability.reject(reason);
  8494. });
  8495. }
  8496. setPageLabels(labels) {
  8497. if (!this.pdfDocument) {
  8498. return;
  8499. }
  8500. if (!labels) {
  8501. this._pageLabels = null;
  8502. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8503. this._pageLabels = null;
  8504. console.error(`setPageLabels: Invalid page labels.`);
  8505. } else {
  8506. this._pageLabels = labels;
  8507. }
  8508. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8509. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8510. }
  8511. }
  8512. _resetView() {
  8513. this._pages = [];
  8514. this._currentPageNumber = 1;
  8515. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8516. this._currentScaleValue = null;
  8517. this._pageLabels = null;
  8518. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8519. this._location = null;
  8520. this._pagesRotation = 0;
  8521. this._optionalContentConfigPromise = null;
  8522. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8523. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8524. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8525. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8526. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8527. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8528. this.#scrollModePageState = {
  8529. previousPageNumber: 1,
  8530. scrollDown: true,
  8531. pages: []
  8532. };
  8533. if (this._onBeforeDraw) {
  8534. this.eventBus._off("pagerender", this._onBeforeDraw);
  8535. this._onBeforeDraw = null;
  8536. }
  8537. if (this._onAfterDraw) {
  8538. this.eventBus._off("pagerendered", this._onAfterDraw);
  8539. this._onAfterDraw = null;
  8540. }
  8541. if (this.#onVisibilityChange) {
  8542. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8543. this.#onVisibilityChange = null;
  8544. }
  8545. this.viewer.textContent = "";
  8546. this._updateScrollMode();
  8547. this.viewer.removeAttribute("lang");
  8548. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  8549. }
  8550. #ensurePageViewVisible() {
  8551. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8552. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8553. }
  8554. const pageNumber = this._currentPageNumber,
  8555. state = this.#scrollModePageState,
  8556. viewer = this.viewer;
  8557. viewer.textContent = "";
  8558. state.pages.length = 0;
  8559. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8560. const pageView = this._pages[pageNumber - 1];
  8561. viewer.append(pageView.div);
  8562. state.pages.push(pageView);
  8563. } else {
  8564. const pageIndexSet = new Set(),
  8565. parity = this._spreadMode - 1;
  8566. if (parity === -1) {
  8567. pageIndexSet.add(pageNumber - 1);
  8568. } else if (pageNumber % 2 !== parity) {
  8569. pageIndexSet.add(pageNumber - 1);
  8570. pageIndexSet.add(pageNumber);
  8571. } else {
  8572. pageIndexSet.add(pageNumber - 2);
  8573. pageIndexSet.add(pageNumber - 1);
  8574. }
  8575. const spread = document.createElement("div");
  8576. spread.className = "spread";
  8577. if (this.isInPresentationMode) {
  8578. const dummyPage = document.createElement("div");
  8579. dummyPage.className = "dummyPage";
  8580. spread.append(dummyPage);
  8581. }
  8582. for (const i of pageIndexSet) {
  8583. const pageView = this._pages[i];
  8584. if (!pageView) {
  8585. continue;
  8586. }
  8587. spread.append(pageView.div);
  8588. state.pages.push(pageView);
  8589. }
  8590. viewer.append(spread);
  8591. }
  8592. state.scrollDown = pageNumber >= state.previousPageNumber;
  8593. state.previousPageNumber = pageNumber;
  8594. }
  8595. _scrollUpdate() {
  8596. if (this.pagesCount === 0) {
  8597. return;
  8598. }
  8599. this.update();
  8600. }
  8601. #scrollIntoView(pageView, pageSpot = null) {
  8602. const {
  8603. div,
  8604. id
  8605. } = pageView;
  8606. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8607. this._setCurrentPageNumber(id);
  8608. this.#ensurePageViewVisible();
  8609. this.update();
  8610. }
  8611. if (!pageSpot && !this.isInPresentationMode) {
  8612. const left = div.offsetLeft + div.clientLeft,
  8613. right = left + div.clientWidth;
  8614. const {
  8615. scrollLeft,
  8616. clientWidth
  8617. } = this.container;
  8618. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8619. pageSpot = {
  8620. left: 0,
  8621. top: 0
  8622. };
  8623. }
  8624. }
  8625. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8626. }
  8627. #isSameScale(newScale) {
  8628. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8629. }
  8630. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8631. this._currentScaleValue = newValue.toString();
  8632. if (this.#isSameScale(newScale)) {
  8633. if (preset) {
  8634. this.eventBus.dispatch("scalechanging", {
  8635. source: this,
  8636. scale: newScale,
  8637. presetValue: newValue
  8638. });
  8639. }
  8640. return;
  8641. }
  8642. _ui_utils.docStyle.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8643. const updateArgs = {
  8644. scale: newScale
  8645. };
  8646. for (const pageView of this._pages) {
  8647. pageView.update(updateArgs);
  8648. }
  8649. this._currentScale = newScale;
  8650. if (!noScroll) {
  8651. let page = this._currentPageNumber,
  8652. dest;
  8653. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8654. page = this._location.pageNumber;
  8655. dest = [null, {
  8656. name: "XYZ"
  8657. }, this._location.left, this._location.top, null];
  8658. }
  8659. this.scrollPageIntoView({
  8660. pageNumber: page,
  8661. destArray: dest,
  8662. allowNegativeOffset: true
  8663. });
  8664. }
  8665. this.eventBus.dispatch("scalechanging", {
  8666. source: this,
  8667. scale: newScale,
  8668. presetValue: preset ? newValue : undefined
  8669. });
  8670. if (this.defaultRenderingQueue) {
  8671. this.update();
  8672. }
  8673. this.updateContainerHeightCss();
  8674. }
  8675. get _pageWidthScaleFactor() {
  8676. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8677. return 2;
  8678. }
  8679. return 1;
  8680. }
  8681. _setScale(value, noScroll = false) {
  8682. let scale = parseFloat(value);
  8683. if (scale > 0) {
  8684. this._setScaleUpdatePages(scale, value, noScroll, false);
  8685. } else {
  8686. const currentPage = this._pages[this._currentPageNumber - 1];
  8687. if (!currentPage) {
  8688. return;
  8689. }
  8690. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8691. vPadding = _ui_utils.VERTICAL_PADDING;
  8692. if (this.isInPresentationMode) {
  8693. hPadding = vPadding = 4;
  8694. } else if (this.removePageBorders) {
  8695. hPadding = vPadding = 0;
  8696. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8697. [hPadding, vPadding] = [vPadding, hPadding];
  8698. }
  8699. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8700. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8701. switch (value) {
  8702. case "page-actual":
  8703. scale = 1;
  8704. break;
  8705. case "page-width":
  8706. scale = pageWidthScale;
  8707. break;
  8708. case "page-height":
  8709. scale = pageHeightScale;
  8710. break;
  8711. case "page-fit":
  8712. scale = Math.min(pageWidthScale, pageHeightScale);
  8713. break;
  8714. case "auto":
  8715. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8716. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8717. break;
  8718. default:
  8719. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  8720. return;
  8721. }
  8722. this._setScaleUpdatePages(scale, value, noScroll, true);
  8723. }
  8724. }
  8725. #resetCurrentPageView() {
  8726. const pageView = this._pages[this._currentPageNumber - 1];
  8727. if (this.isInPresentationMode) {
  8728. this._setScale(this._currentScaleValue, true);
  8729. }
  8730. this.#scrollIntoView(pageView);
  8731. }
  8732. pageLabelToPageNumber(label) {
  8733. if (!this._pageLabels) {
  8734. return null;
  8735. }
  8736. const i = this._pageLabels.indexOf(label);
  8737. if (i < 0) {
  8738. return null;
  8739. }
  8740. return i + 1;
  8741. }
  8742. scrollPageIntoView({
  8743. pageNumber,
  8744. destArray = null,
  8745. allowNegativeOffset = false,
  8746. ignoreDestinationZoom = false
  8747. }) {
  8748. if (!this.pdfDocument) {
  8749. return;
  8750. }
  8751. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8752. if (!pageView) {
  8753. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  8754. return;
  8755. }
  8756. if (this.isInPresentationMode || !destArray) {
  8757. this._setCurrentPageNumber(pageNumber, true);
  8758. return;
  8759. }
  8760. let x = 0,
  8761. y = 0;
  8762. let width = 0,
  8763. height = 0,
  8764. widthScale,
  8765. heightScale;
  8766. const changeOrientation = pageView.rotation % 180 !== 0;
  8767. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8768. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8769. let scale = 0;
  8770. switch (destArray[1].name) {
  8771. case "XYZ":
  8772. x = destArray[2];
  8773. y = destArray[3];
  8774. scale = destArray[4];
  8775. x = x !== null ? x : 0;
  8776. y = y !== null ? y : pageHeight;
  8777. break;
  8778. case "Fit":
  8779. case "FitB":
  8780. scale = "page-fit";
  8781. break;
  8782. case "FitH":
  8783. case "FitBH":
  8784. y = destArray[2];
  8785. scale = "page-width";
  8786. if (y === null && this._location) {
  8787. x = this._location.left;
  8788. y = this._location.top;
  8789. } else if (typeof y !== "number" || y < 0) {
  8790. y = pageHeight;
  8791. }
  8792. break;
  8793. case "FitV":
  8794. case "FitBV":
  8795. x = destArray[2];
  8796. width = pageWidth;
  8797. height = pageHeight;
  8798. scale = "page-height";
  8799. break;
  8800. case "FitR":
  8801. x = destArray[2];
  8802. y = destArray[3];
  8803. width = destArray[4] - x;
  8804. height = destArray[5] - y;
  8805. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8806. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8807. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8808. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8809. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8810. break;
  8811. default:
  8812. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  8813. return;
  8814. }
  8815. if (!ignoreDestinationZoom) {
  8816. if (scale && scale !== this._currentScale) {
  8817. this.currentScaleValue = scale;
  8818. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8819. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8820. }
  8821. }
  8822. if (scale === "page-fit" && !destArray[4]) {
  8823. this.#scrollIntoView(pageView);
  8824. return;
  8825. }
  8826. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8827. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8828. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8829. if (!allowNegativeOffset) {
  8830. left = Math.max(left, 0);
  8831. top = Math.max(top, 0);
  8832. }
  8833. this.#scrollIntoView(pageView, {
  8834. left,
  8835. top
  8836. });
  8837. }
  8838. _updateLocation(firstPage) {
  8839. const currentScale = this._currentScale;
  8840. const currentScaleValue = this._currentScaleValue;
  8841. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8842. const pageNumber = firstPage.id;
  8843. const currentPageView = this._pages[pageNumber - 1];
  8844. const container = this.container;
  8845. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8846. const intLeft = Math.round(topLeft[0]);
  8847. const intTop = Math.round(topLeft[1]);
  8848. let pdfOpenParams = `#page=${pageNumber}`;
  8849. if (!this.isInPresentationMode) {
  8850. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  8851. }
  8852. this._location = {
  8853. pageNumber,
  8854. scale: normalizedScaleValue,
  8855. top: intTop,
  8856. left: intLeft,
  8857. rotation: this._pagesRotation,
  8858. pdfOpenParams
  8859. };
  8860. }
  8861. update() {
  8862. const visible = this._getVisiblePages();
  8863. const visiblePages = visible.views,
  8864. numVisiblePages = visiblePages.length;
  8865. if (numVisiblePages === 0) {
  8866. return;
  8867. }
  8868. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8869. this.#buffer.resize(newCacheSize, visible.ids);
  8870. this.renderingQueue.renderHighestPriority(visible);
  8871. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  8872. const currentId = this._currentPageNumber;
  8873. let stillFullyVisible = false;
  8874. for (const page of visiblePages) {
  8875. if (page.percent < 100) {
  8876. break;
  8877. }
  8878. if (page.id === currentId && isSimpleLayout) {
  8879. stillFullyVisible = true;
  8880. break;
  8881. }
  8882. }
  8883. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  8884. this._updateLocation(visible.first);
  8885. this.eventBus.dispatch("updateviewarea", {
  8886. source: this,
  8887. location: this._location
  8888. });
  8889. }
  8890. containsElement(element) {
  8891. return this.container.contains(element);
  8892. }
  8893. focus() {
  8894. this.container.focus();
  8895. }
  8896. get _isContainerRtl() {
  8897. return getComputedStyle(this.container).direction === "rtl";
  8898. }
  8899. get isInPresentationMode() {
  8900. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8901. }
  8902. get isChangingPresentationMode() {
  8903. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8904. }
  8905. get isHorizontalScrollbarEnabled() {
  8906. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8907. }
  8908. get isVerticalScrollbarEnabled() {
  8909. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8910. }
  8911. _getVisiblePages() {
  8912. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  8913. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  8914. rtl = horizontal && this._isContainerRtl;
  8915. return (0, _ui_utils.getVisibleElements)({
  8916. scrollEl: this.container,
  8917. views,
  8918. sortByVisibility: true,
  8919. horizontal,
  8920. rtl
  8921. });
  8922. }
  8923. isPageVisible(pageNumber) {
  8924. if (!this.pdfDocument) {
  8925. return false;
  8926. }
  8927. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8928. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  8929. return false;
  8930. }
  8931. return this._getVisiblePages().ids.has(pageNumber);
  8932. }
  8933. isPageCached(pageNumber) {
  8934. if (!this.pdfDocument) {
  8935. return false;
  8936. }
  8937. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8938. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  8939. return false;
  8940. }
  8941. const pageView = this._pages[pageNumber - 1];
  8942. return this.#buffer.has(pageView);
  8943. }
  8944. cleanup() {
  8945. for (const pageView of this._pages) {
  8946. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8947. pageView.reset();
  8948. }
  8949. }
  8950. }
  8951. _cancelRendering() {
  8952. for (const pageView of this._pages) {
  8953. pageView.cancelRendering();
  8954. }
  8955. }
  8956. async #ensurePdfPageLoaded(pageView) {
  8957. if (pageView.pdfPage) {
  8958. return pageView.pdfPage;
  8959. }
  8960. try {
  8961. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  8962. if (!pageView.pdfPage) {
  8963. pageView.setPdfPage(pdfPage);
  8964. }
  8965. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  8966. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  8967. }
  8968. return pdfPage;
  8969. } catch (reason) {
  8970. console.error("Unable to get page for page view", reason);
  8971. return null;
  8972. }
  8973. }
  8974. #getScrollAhead(visible) {
  8975. if (visible.first?.id === 1) {
  8976. return true;
  8977. } else if (visible.last?.id === this.pagesCount) {
  8978. return false;
  8979. }
  8980. switch (this._scrollMode) {
  8981. case _ui_utils.ScrollMode.PAGE:
  8982. return this.#scrollModePageState.scrollDown;
  8983. case _ui_utils.ScrollMode.HORIZONTAL:
  8984. return this.scroll.right;
  8985. }
  8986. return this.scroll.down;
  8987. }
  8988. #toggleLoadingIconSpinner(visibleIds) {
  8989. for (const id of visibleIds) {
  8990. const pageView = this._pages[id - 1];
  8991. pageView?.toggleLoadingIconSpinner(true);
  8992. }
  8993. for (const pageView of this.#buffer) {
  8994. if (visibleIds.has(pageView.id)) {
  8995. continue;
  8996. }
  8997. pageView.toggleLoadingIconSpinner(false);
  8998. }
  8999. }
  9000. forceRendering(currentlyVisiblePages) {
  9001. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9002. const scrollAhead = this.#getScrollAhead(visiblePages);
  9003. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9004. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9005. this.#toggleLoadingIconSpinner(visiblePages.ids);
  9006. if (pageView) {
  9007. this.#ensurePdfPageLoaded(pageView).then(() => {
  9008. this.renderingQueue.renderView(pageView);
  9009. });
  9010. return true;
  9011. }
  9012. return false;
  9013. }
  9014. createTextLayerBuilder({
  9015. textLayerDiv,
  9016. pageIndex,
  9017. viewport,
  9018. enhanceTextSelection = false,
  9019. eventBus,
  9020. highlighter,
  9021. accessibilityManager = null
  9022. }) {
  9023. return new _text_layer_builder.TextLayerBuilder({
  9024. textLayerDiv,
  9025. eventBus,
  9026. pageIndex,
  9027. viewport,
  9028. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection,
  9029. highlighter,
  9030. accessibilityManager
  9031. });
  9032. }
  9033. createTextHighlighter({
  9034. pageIndex,
  9035. eventBus
  9036. }) {
  9037. return new _text_highlighter.TextHighlighter({
  9038. eventBus,
  9039. pageIndex,
  9040. findController: this.isInPresentationMode ? null : this.findController
  9041. });
  9042. }
  9043. createAnnotationLayerBuilder({
  9044. pageDiv,
  9045. pdfPage,
  9046. annotationStorage = this.pdfDocument?.annotationStorage,
  9047. imageResourcesPath = "",
  9048. renderForms = true,
  9049. l10n = _l10n_utils.NullL10n,
  9050. enableScripting = this.enableScripting,
  9051. hasJSActionsPromise = this.pdfDocument?.hasJSActions(),
  9052. mouseState = this._scriptingManager?.mouseState,
  9053. fieldObjectsPromise = this.pdfDocument?.getFieldObjects(),
  9054. annotationCanvasMap = null,
  9055. accessibilityManager = null
  9056. }) {
  9057. return new _annotation_layer_builder.AnnotationLayerBuilder({
  9058. pageDiv,
  9059. pdfPage,
  9060. annotationStorage,
  9061. imageResourcesPath,
  9062. renderForms,
  9063. linkService: this.linkService,
  9064. downloadManager: this.downloadManager,
  9065. l10n,
  9066. enableScripting,
  9067. hasJSActionsPromise,
  9068. mouseState,
  9069. fieldObjectsPromise,
  9070. annotationCanvasMap,
  9071. accessibilityManager
  9072. });
  9073. }
  9074. createAnnotationEditorLayerBuilder({
  9075. uiManager = this.#annotationEditorUIManager,
  9076. pageDiv,
  9077. pdfPage,
  9078. accessibilityManager = null,
  9079. l10n,
  9080. annotationStorage = this.pdfDocument?.annotationStorage
  9081. }) {
  9082. return new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  9083. uiManager,
  9084. pageDiv,
  9085. pdfPage,
  9086. annotationStorage,
  9087. accessibilityManager,
  9088. l10n
  9089. });
  9090. }
  9091. createXfaLayerBuilder({
  9092. pageDiv,
  9093. pdfPage,
  9094. annotationStorage = this.pdfDocument?.annotationStorage
  9095. }) {
  9096. return new _xfa_layer_builder.XfaLayerBuilder({
  9097. pageDiv,
  9098. pdfPage,
  9099. annotationStorage,
  9100. linkService: this.linkService
  9101. });
  9102. }
  9103. createStructTreeLayerBuilder({
  9104. pdfPage
  9105. }) {
  9106. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  9107. pdfPage
  9108. });
  9109. }
  9110. get hasEqualPageSizes() {
  9111. const firstPageView = this._pages[0];
  9112. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  9113. const pageView = this._pages[i];
  9114. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9115. return false;
  9116. }
  9117. }
  9118. return true;
  9119. }
  9120. getPagesOverview() {
  9121. return this._pages.map(pageView => {
  9122. const viewport = pageView.pdfPage.getViewport({
  9123. scale: 1
  9124. });
  9125. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  9126. return {
  9127. width: viewport.width,
  9128. height: viewport.height,
  9129. rotation: viewport.rotation
  9130. };
  9131. }
  9132. return {
  9133. width: viewport.height,
  9134. height: viewport.width,
  9135. rotation: (viewport.rotation - 90) % 360
  9136. };
  9137. });
  9138. }
  9139. get optionalContentConfigPromise() {
  9140. if (!this.pdfDocument) {
  9141. return Promise.resolve(null);
  9142. }
  9143. if (!this._optionalContentConfigPromise) {
  9144. console.error("optionalContentConfigPromise: Not initialized yet.");
  9145. return this.pdfDocument.getOptionalContentConfig();
  9146. }
  9147. return this._optionalContentConfigPromise;
  9148. }
  9149. set optionalContentConfigPromise(promise) {
  9150. if (!(promise instanceof Promise)) {
  9151. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  9152. }
  9153. if (!this.pdfDocument) {
  9154. return;
  9155. }
  9156. if (!this._optionalContentConfigPromise) {
  9157. return;
  9158. }
  9159. this._optionalContentConfigPromise = promise;
  9160. const updateArgs = {
  9161. optionalContentConfigPromise: promise
  9162. };
  9163. for (const pageView of this._pages) {
  9164. pageView.update(updateArgs);
  9165. }
  9166. this.update();
  9167. this.eventBus.dispatch("optionalcontentconfigchanged", {
  9168. source: this,
  9169. promise
  9170. });
  9171. }
  9172. get scrollMode() {
  9173. return this._scrollMode;
  9174. }
  9175. set scrollMode(mode) {
  9176. if (this._scrollMode === mode) {
  9177. return;
  9178. }
  9179. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9180. throw new Error(`Invalid scroll mode: ${mode}`);
  9181. }
  9182. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9183. return;
  9184. }
  9185. this._previousScrollMode = this._scrollMode;
  9186. this._scrollMode = mode;
  9187. this.eventBus.dispatch("scrollmodechanged", {
  9188. source: this,
  9189. mode
  9190. });
  9191. this._updateScrollMode(this._currentPageNumber);
  9192. }
  9193. _updateScrollMode(pageNumber = null) {
  9194. const scrollMode = this._scrollMode,
  9195. viewer = this.viewer;
  9196. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9197. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9198. if (!this.pdfDocument || !pageNumber) {
  9199. return;
  9200. }
  9201. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9202. this.#ensurePageViewVisible();
  9203. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9204. this._updateSpreadMode();
  9205. }
  9206. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9207. this._setScale(this._currentScaleValue, true);
  9208. }
  9209. this._setCurrentPageNumber(pageNumber, true);
  9210. this.update();
  9211. }
  9212. get spreadMode() {
  9213. return this._spreadMode;
  9214. }
  9215. set spreadMode(mode) {
  9216. if (this._spreadMode === mode) {
  9217. return;
  9218. }
  9219. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9220. throw new Error(`Invalid spread mode: ${mode}`);
  9221. }
  9222. this._spreadMode = mode;
  9223. this.eventBus.dispatch("spreadmodechanged", {
  9224. source: this,
  9225. mode
  9226. });
  9227. this._updateSpreadMode(this._currentPageNumber);
  9228. }
  9229. _updateSpreadMode(pageNumber = null) {
  9230. if (!this.pdfDocument) {
  9231. return;
  9232. }
  9233. const viewer = this.viewer,
  9234. pages = this._pages;
  9235. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9236. this.#ensurePageViewVisible();
  9237. } else {
  9238. viewer.textContent = "";
  9239. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9240. for (const pageView of this._pages) {
  9241. viewer.append(pageView.div);
  9242. }
  9243. } else {
  9244. const parity = this._spreadMode - 1;
  9245. let spread = null;
  9246. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9247. if (spread === null) {
  9248. spread = document.createElement("div");
  9249. spread.className = "spread";
  9250. viewer.append(spread);
  9251. } else if (i % 2 === parity) {
  9252. spread = spread.cloneNode(false);
  9253. viewer.append(spread);
  9254. }
  9255. spread.append(pages[i].div);
  9256. }
  9257. }
  9258. }
  9259. if (!pageNumber) {
  9260. return;
  9261. }
  9262. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9263. this._setScale(this._currentScaleValue, true);
  9264. }
  9265. this._setCurrentPageNumber(pageNumber, true);
  9266. this.update();
  9267. }
  9268. _getPageAdvance(currentPageNumber, previous = false) {
  9269. switch (this._scrollMode) {
  9270. case _ui_utils.ScrollMode.WRAPPED:
  9271. {
  9272. const {
  9273. views
  9274. } = this._getVisiblePages(),
  9275. pageLayout = new Map();
  9276. for (const {
  9277. id,
  9278. y,
  9279. percent,
  9280. widthPercent
  9281. } of views) {
  9282. if (percent === 0 || widthPercent < 100) {
  9283. continue;
  9284. }
  9285. let yArray = pageLayout.get(y);
  9286. if (!yArray) {
  9287. pageLayout.set(y, yArray ||= []);
  9288. }
  9289. yArray.push(id);
  9290. }
  9291. for (const yArray of pageLayout.values()) {
  9292. const currentIndex = yArray.indexOf(currentPageNumber);
  9293. if (currentIndex === -1) {
  9294. continue;
  9295. }
  9296. const numPages = yArray.length;
  9297. if (numPages === 1) {
  9298. break;
  9299. }
  9300. if (previous) {
  9301. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9302. const currentId = yArray[i],
  9303. expectedId = yArray[i + 1] - 1;
  9304. if (currentId < expectedId) {
  9305. return currentPageNumber - expectedId;
  9306. }
  9307. }
  9308. } else {
  9309. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9310. const currentId = yArray[i],
  9311. expectedId = yArray[i - 1] + 1;
  9312. if (currentId > expectedId) {
  9313. return expectedId - currentPageNumber;
  9314. }
  9315. }
  9316. }
  9317. if (previous) {
  9318. const firstId = yArray[0];
  9319. if (firstId < currentPageNumber) {
  9320. return currentPageNumber - firstId + 1;
  9321. }
  9322. } else {
  9323. const lastId = yArray[numPages - 1];
  9324. if (lastId > currentPageNumber) {
  9325. return lastId - currentPageNumber + 1;
  9326. }
  9327. }
  9328. break;
  9329. }
  9330. break;
  9331. }
  9332. case _ui_utils.ScrollMode.HORIZONTAL:
  9333. {
  9334. break;
  9335. }
  9336. case _ui_utils.ScrollMode.PAGE:
  9337. case _ui_utils.ScrollMode.VERTICAL:
  9338. {
  9339. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9340. break;
  9341. }
  9342. const parity = this._spreadMode - 1;
  9343. if (previous && currentPageNumber % 2 !== parity) {
  9344. break;
  9345. } else if (!previous && currentPageNumber % 2 === parity) {
  9346. break;
  9347. }
  9348. const {
  9349. views
  9350. } = this._getVisiblePages(),
  9351. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9352. for (const {
  9353. id,
  9354. percent,
  9355. widthPercent
  9356. } of views) {
  9357. if (id !== expectedId) {
  9358. continue;
  9359. }
  9360. if (percent > 0 && widthPercent === 100) {
  9361. return 2;
  9362. }
  9363. break;
  9364. }
  9365. break;
  9366. }
  9367. }
  9368. return 1;
  9369. }
  9370. nextPage() {
  9371. const currentPageNumber = this._currentPageNumber,
  9372. pagesCount = this.pagesCount;
  9373. if (currentPageNumber >= pagesCount) {
  9374. return false;
  9375. }
  9376. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9377. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9378. return true;
  9379. }
  9380. previousPage() {
  9381. const currentPageNumber = this._currentPageNumber;
  9382. if (currentPageNumber <= 1) {
  9383. return false;
  9384. }
  9385. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9386. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9387. return true;
  9388. }
  9389. increaseScale(steps = 1) {
  9390. let newScale = this._currentScale;
  9391. do {
  9392. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9393. newScale = Math.ceil(newScale * 10) / 10;
  9394. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  9395. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9396. this.currentScaleValue = newScale;
  9397. }
  9398. decreaseScale(steps = 1) {
  9399. let newScale = this._currentScale;
  9400. do {
  9401. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9402. newScale = Math.floor(newScale * 10) / 10;
  9403. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  9404. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9405. this.currentScaleValue = newScale;
  9406. }
  9407. updateContainerHeightCss() {
  9408. const height = this.container.clientHeight;
  9409. if (height !== this.#previousContainerHeight) {
  9410. this.#previousContainerHeight = height;
  9411. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  9412. }
  9413. }
  9414. get annotationEditorMode() {
  9415. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  9416. }
  9417. set annotationEditorMode(mode) {
  9418. if (!this.#annotationEditorUIManager) {
  9419. throw new Error(`The AnnotationEditor is not enabled.`);
  9420. }
  9421. if (this.#annotationEditorMode === mode) {
  9422. return;
  9423. }
  9424. if (!isValidAnnotationEditorMode(mode)) {
  9425. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  9426. }
  9427. if (!this.pdfDocument) {
  9428. return;
  9429. }
  9430. this.#annotationEditorMode = mode;
  9431. this.eventBus.dispatch("annotationeditormodechanged", {
  9432. source: this,
  9433. mode
  9434. });
  9435. this.#annotationEditorUIManager.updateMode(mode);
  9436. }
  9437. set annotationEditorParams({
  9438. type,
  9439. value
  9440. }) {
  9441. if (!this.#annotationEditorUIManager) {
  9442. throw new Error(`The AnnotationEditor is not enabled.`);
  9443. }
  9444. this.#annotationEditorUIManager.updateParams(type, value);
  9445. }
  9446. refresh() {
  9447. if (!this.pdfDocument) {
  9448. return;
  9449. }
  9450. const updateArgs = {};
  9451. for (const pageView of this._pages) {
  9452. pageView.update(updateArgs);
  9453. }
  9454. this.update();
  9455. }
  9456. }
  9457. exports.BaseViewer = BaseViewer;
  9458. /***/ }),
  9459. /* 30 */
  9460. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9461. Object.defineProperty(exports, "__esModule", ({
  9462. value: true
  9463. }));
  9464. exports.AnnotationEditorLayerBuilder = void 0;
  9465. var _pdfjsLib = __webpack_require__(5);
  9466. var _l10n_utils = __webpack_require__(31);
  9467. class AnnotationEditorLayerBuilder {
  9468. #uiManager;
  9469. constructor(options) {
  9470. this.pageDiv = options.pageDiv;
  9471. this.pdfPage = options.pdfPage;
  9472. this.annotationStorage = options.annotationStorage || null;
  9473. this.accessibilityManager = options.accessibilityManager;
  9474. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9475. this.annotationEditorLayer = null;
  9476. this.div = null;
  9477. this._cancelled = false;
  9478. this.#uiManager = options.uiManager;
  9479. }
  9480. async render(viewport, intent = "display") {
  9481. if (intent !== "display") {
  9482. return;
  9483. }
  9484. if (this._cancelled) {
  9485. return;
  9486. }
  9487. const clonedViewport = viewport.clone({
  9488. dontFlip: true
  9489. });
  9490. if (this.div) {
  9491. this.annotationEditorLayer.update({
  9492. viewport: clonedViewport
  9493. });
  9494. this.show();
  9495. return;
  9496. }
  9497. this.div = document.createElement("div");
  9498. this.div.className = "annotationEditorLayer";
  9499. this.div.tabIndex = 0;
  9500. this.pageDiv.append(this.div);
  9501. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  9502. uiManager: this.#uiManager,
  9503. div: this.div,
  9504. annotationStorage: this.annotationStorage,
  9505. accessibilityManager: this.accessibilityManager,
  9506. pageIndex: this.pdfPage._pageIndex,
  9507. l10n: this.l10n,
  9508. viewport: clonedViewport
  9509. });
  9510. const parameters = {
  9511. viewport: clonedViewport,
  9512. div: this.div,
  9513. annotations: null,
  9514. intent
  9515. };
  9516. this.annotationEditorLayer.render(parameters);
  9517. }
  9518. cancel() {
  9519. this._cancelled = true;
  9520. this.destroy();
  9521. }
  9522. hide() {
  9523. if (!this.div) {
  9524. return;
  9525. }
  9526. this.div.hidden = true;
  9527. }
  9528. show() {
  9529. if (!this.div) {
  9530. return;
  9531. }
  9532. this.div.hidden = false;
  9533. }
  9534. destroy() {
  9535. if (!this.div) {
  9536. return;
  9537. }
  9538. this.pageDiv = null;
  9539. this.annotationEditorLayer.destroy();
  9540. this.div.remove();
  9541. }
  9542. }
  9543. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  9544. /***/ }),
  9545. /* 31 */
  9546. /***/ ((__unused_webpack_module, exports) => {
  9547. Object.defineProperty(exports, "__esModule", ({
  9548. value: true
  9549. }));
  9550. exports.NullL10n = void 0;
  9551. exports.fixupLangCode = fixupLangCode;
  9552. exports.getL10nFallback = getL10nFallback;
  9553. const DEFAULT_L10N_STRINGS = {
  9554. of_pages: "of {{pagesCount}}",
  9555. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9556. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9557. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9558. document_properties_date_string: "{{date}}, {{time}}",
  9559. document_properties_page_size_unit_inches: "in",
  9560. document_properties_page_size_unit_millimeters: "mm",
  9561. document_properties_page_size_orientation_portrait: "portrait",
  9562. document_properties_page_size_orientation_landscape: "landscape",
  9563. document_properties_page_size_name_a3: "A3",
  9564. document_properties_page_size_name_a4: "A4",
  9565. document_properties_page_size_name_letter: "Letter",
  9566. document_properties_page_size_name_legal: "Legal",
  9567. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9568. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9569. document_properties_linearized_yes: "Yes",
  9570. document_properties_linearized_no: "No",
  9571. print_progress_percent: "{{progress}}%",
  9572. "toggle_sidebar.title": "Toggle Sidebar",
  9573. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  9574. additional_layers: "Additional Layers",
  9575. page_landmark: "Page {{page}}",
  9576. thumb_page_title: "Page {{page}}",
  9577. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9578. find_reached_top: "Reached top of document, continued from bottom",
  9579. find_reached_bottom: "Reached end of document, continued from top",
  9580. "find_match_count[one]": "{{current}} of {{total}} match",
  9581. "find_match_count[other]": "{{current}} of {{total}} matches",
  9582. "find_match_count_limit[one]": "More than {{limit}} match",
  9583. "find_match_count_limit[other]": "More than {{limit}} matches",
  9584. find_not_found: "Phrase not found",
  9585. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  9586. error_message: "Message: {{message}}",
  9587. error_stack: "Stack: {{stack}}",
  9588. error_file: "File: {{file}}",
  9589. error_line: "Line: {{line}}",
  9590. rendering_error: "An error occurred while rendering the page.",
  9591. page_scale_width: "Page Width",
  9592. page_scale_fit: "Page Fit",
  9593. page_scale_auto: "Automatic Zoom",
  9594. page_scale_actual: "Actual Size",
  9595. page_scale_percent: "{{scale}}%",
  9596. loading: "Loading…",
  9597. loading_error: "An error occurred while loading the PDF.",
  9598. invalid_file_error: "Invalid or corrupted PDF file.",
  9599. missing_file_error: "Missing PDF file.",
  9600. unexpected_response_error: "Unexpected server response.",
  9601. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9602. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9603. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  9604. free_text_default_content: "Enter text…",
  9605. editor_free_text_aria_label: "FreeText Editor",
  9606. editor_ink_aria_label: "Ink Editor",
  9607. editor_ink_canvas_aria_label: "User-created image"
  9608. };
  9609. function getL10nFallback(key, args) {
  9610. switch (key) {
  9611. case "find_match_count":
  9612. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9613. break;
  9614. case "find_match_count_limit":
  9615. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9616. break;
  9617. }
  9618. return DEFAULT_L10N_STRINGS[key] || "";
  9619. }
  9620. const PARTIAL_LANG_CODES = {
  9621. en: "en-US",
  9622. es: "es-ES",
  9623. fy: "fy-NL",
  9624. ga: "ga-IE",
  9625. gu: "gu-IN",
  9626. hi: "hi-IN",
  9627. hy: "hy-AM",
  9628. nb: "nb-NO",
  9629. ne: "ne-NP",
  9630. nn: "nn-NO",
  9631. pa: "pa-IN",
  9632. pt: "pt-PT",
  9633. sv: "sv-SE",
  9634. zh: "zh-CN"
  9635. };
  9636. function fixupLangCode(langCode) {
  9637. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9638. }
  9639. function formatL10nValue(text, args) {
  9640. if (!args) {
  9641. return text;
  9642. }
  9643. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9644. return name in args ? args[name] : "{{" + name + "}}";
  9645. });
  9646. }
  9647. const NullL10n = {
  9648. async getLanguage() {
  9649. return "en-us";
  9650. },
  9651. async getDirection() {
  9652. return "ltr";
  9653. },
  9654. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9655. return formatL10nValue(fallback, args);
  9656. },
  9657. async translate(element) {}
  9658. };
  9659. exports.NullL10n = NullL10n;
  9660. /***/ }),
  9661. /* 32 */
  9662. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9663. Object.defineProperty(exports, "__esModule", ({
  9664. value: true
  9665. }));
  9666. exports.AnnotationLayerBuilder = void 0;
  9667. var _pdfjsLib = __webpack_require__(5);
  9668. var _l10n_utils = __webpack_require__(31);
  9669. class AnnotationLayerBuilder {
  9670. constructor({
  9671. pageDiv,
  9672. pdfPage,
  9673. linkService,
  9674. downloadManager,
  9675. annotationStorage = null,
  9676. imageResourcesPath = "",
  9677. renderForms = true,
  9678. l10n = _l10n_utils.NullL10n,
  9679. enableScripting = false,
  9680. hasJSActionsPromise = null,
  9681. fieldObjectsPromise = null,
  9682. mouseState = null,
  9683. annotationCanvasMap = null,
  9684. accessibilityManager = null
  9685. }) {
  9686. this.pageDiv = pageDiv;
  9687. this.pdfPage = pdfPage;
  9688. this.linkService = linkService;
  9689. this.downloadManager = downloadManager;
  9690. this.imageResourcesPath = imageResourcesPath;
  9691. this.renderForms = renderForms;
  9692. this.l10n = l10n;
  9693. this.annotationStorage = annotationStorage;
  9694. this.enableScripting = enableScripting;
  9695. this._hasJSActionsPromise = hasJSActionsPromise;
  9696. this._fieldObjectsPromise = fieldObjectsPromise;
  9697. this._mouseState = mouseState;
  9698. this._annotationCanvasMap = annotationCanvasMap;
  9699. this._accessibilityManager = accessibilityManager;
  9700. this.div = null;
  9701. this._cancelled = false;
  9702. }
  9703. async render(viewport, intent = "display") {
  9704. const [annotations, hasJSActions = false, fieldObjects = null] = await Promise.all([this.pdfPage.getAnnotations({
  9705. intent
  9706. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  9707. if (this._cancelled || annotations.length === 0) {
  9708. return;
  9709. }
  9710. const parameters = {
  9711. viewport: viewport.clone({
  9712. dontFlip: true
  9713. }),
  9714. div: this.div,
  9715. annotations,
  9716. page: this.pdfPage,
  9717. imageResourcesPath: this.imageResourcesPath,
  9718. renderForms: this.renderForms,
  9719. linkService: this.linkService,
  9720. downloadManager: this.downloadManager,
  9721. annotationStorage: this.annotationStorage,
  9722. enableScripting: this.enableScripting,
  9723. hasJSActions,
  9724. fieldObjects,
  9725. mouseState: this._mouseState,
  9726. annotationCanvasMap: this._annotationCanvasMap,
  9727. accessibilityManager: this._accessibilityManager
  9728. };
  9729. if (this.div) {
  9730. _pdfjsLib.AnnotationLayer.update(parameters);
  9731. } else {
  9732. this.div = document.createElement("div");
  9733. this.div.className = "annotationLayer";
  9734. this.pageDiv.append(this.div);
  9735. parameters.div = this.div;
  9736. _pdfjsLib.AnnotationLayer.render(parameters);
  9737. this.l10n.translate(this.div);
  9738. }
  9739. }
  9740. cancel() {
  9741. this._cancelled = true;
  9742. }
  9743. hide() {
  9744. if (!this.div) {
  9745. return;
  9746. }
  9747. this.div.hidden = true;
  9748. }
  9749. }
  9750. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  9751. /***/ }),
  9752. /* 33 */
  9753. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9754. Object.defineProperty(exports, "__esModule", ({
  9755. value: true
  9756. }));
  9757. exports.PDFPageView = void 0;
  9758. var _pdfjsLib = __webpack_require__(5);
  9759. var _ui_utils = __webpack_require__(1);
  9760. var _app_options = __webpack_require__(2);
  9761. var _l10n_utils = __webpack_require__(31);
  9762. var _text_accessibility = __webpack_require__(34);
  9763. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9764. class PDFPageView {
  9765. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9766. #useThumbnailCanvas = {
  9767. initialOptionalContent: true,
  9768. regularAnnotations: true
  9769. };
  9770. constructor(options) {
  9771. const container = options.container;
  9772. const defaultViewport = options.defaultViewport;
  9773. this.id = options.id;
  9774. this.renderingId = "page" + this.id;
  9775. this.pdfPage = null;
  9776. this.pageLabel = null;
  9777. this.rotation = 0;
  9778. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9779. this.viewport = defaultViewport;
  9780. this.pdfPageRotate = defaultViewport.rotation;
  9781. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9782. this.hasRestrictedScaling = false;
  9783. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9784. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9785. this.imageResourcesPath = options.imageResourcesPath || "";
  9786. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9787. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9788. this.pageColors = options.pageColors || null;
  9789. this.eventBus = options.eventBus;
  9790. this.renderingQueue = options.renderingQueue;
  9791. this.textLayerFactory = options.textLayerFactory;
  9792. this.annotationLayerFactory = options.annotationLayerFactory;
  9793. this.annotationEditorLayerFactory = options.annotationEditorLayerFactory;
  9794. this.xfaLayerFactory = options.xfaLayerFactory;
  9795. this.textHighlighter = options.textHighlighterFactory?.createTextHighlighter({
  9796. pageIndex: this.id - 1,
  9797. eventBus: this.eventBus
  9798. });
  9799. this.structTreeLayerFactory = options.structTreeLayerFactory;
  9800. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9801. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9802. this.paintTask = null;
  9803. this.paintedViewportMap = new WeakMap();
  9804. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9805. this.resume = null;
  9806. this._renderError = null;
  9807. this._isStandalone = !this.renderingQueue?.hasViewer();
  9808. this._annotationCanvasMap = null;
  9809. this.annotationLayer = null;
  9810. this.annotationEditorLayer = null;
  9811. this.textLayer = null;
  9812. this.zoomLayer = null;
  9813. this.xfaLayer = null;
  9814. this.structTreeLayer = null;
  9815. const div = document.createElement("div");
  9816. div.className = "page";
  9817. div.style.width = Math.floor(this.viewport.width) + "px";
  9818. div.style.height = Math.floor(this.viewport.height) + "px";
  9819. div.setAttribute("data-page-number", this.id);
  9820. div.setAttribute("role", "region");
  9821. this.l10n.get("page_landmark", {
  9822. page: this.id
  9823. }).then(msg => {
  9824. div.setAttribute("aria-label", msg);
  9825. });
  9826. this.div = div;
  9827. container?.append(div);
  9828. if (this._isStandalone) {
  9829. const {
  9830. optionalContentConfigPromise
  9831. } = options;
  9832. if (optionalContentConfigPromise) {
  9833. optionalContentConfigPromise.then(optionalContentConfig => {
  9834. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9835. return;
  9836. }
  9837. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9838. });
  9839. }
  9840. }
  9841. }
  9842. setPdfPage(pdfPage) {
  9843. this.pdfPage = pdfPage;
  9844. this.pdfPageRotate = pdfPage.rotate;
  9845. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9846. this.viewport = pdfPage.getViewport({
  9847. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9848. rotation: totalRotation
  9849. });
  9850. this.reset();
  9851. }
  9852. destroy() {
  9853. this.reset();
  9854. if (this.pdfPage) {
  9855. this.pdfPage.cleanup();
  9856. }
  9857. }
  9858. async _renderAnnotationLayer() {
  9859. let error = null;
  9860. try {
  9861. await this.annotationLayer.render(this.viewport, "display");
  9862. } catch (ex) {
  9863. console.error(`_renderAnnotationLayer: "${ex}".`);
  9864. error = ex;
  9865. } finally {
  9866. this.eventBus.dispatch("annotationlayerrendered", {
  9867. source: this,
  9868. pageNumber: this.id,
  9869. error
  9870. });
  9871. }
  9872. }
  9873. async _renderAnnotationEditorLayer() {
  9874. let error = null;
  9875. try {
  9876. await this.annotationEditorLayer.render(this.viewport, "display");
  9877. } catch (ex) {
  9878. console.error(`_renderAnnotationEditorLayer: "${ex}".`);
  9879. error = ex;
  9880. } finally {
  9881. this.eventBus.dispatch("annotationeditorlayerrendered", {
  9882. source: this,
  9883. pageNumber: this.id,
  9884. error
  9885. });
  9886. }
  9887. }
  9888. async _renderXfaLayer() {
  9889. let error = null;
  9890. try {
  9891. const result = await this.xfaLayer.render(this.viewport, "display");
  9892. if (this.textHighlighter) {
  9893. this._buildXfaTextContentItems(result.textDivs);
  9894. }
  9895. } catch (ex) {
  9896. console.error(`_renderXfaLayer: "${ex}".`);
  9897. error = ex;
  9898. } finally {
  9899. this.eventBus.dispatch("xfalayerrendered", {
  9900. source: this,
  9901. pageNumber: this.id,
  9902. error
  9903. });
  9904. }
  9905. }
  9906. async _buildXfaTextContentItems(textDivs) {
  9907. const text = await this.pdfPage.getTextContent();
  9908. const items = [];
  9909. for (const item of text.items) {
  9910. items.push(item.str);
  9911. }
  9912. this.textHighlighter.setTextMapping(textDivs, items);
  9913. this.textHighlighter.enable();
  9914. }
  9915. _resetZoomLayer(removeFromDOM = false) {
  9916. if (!this.zoomLayer) {
  9917. return;
  9918. }
  9919. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9920. this.paintedViewportMap.delete(zoomLayerCanvas);
  9921. zoomLayerCanvas.width = 0;
  9922. zoomLayerCanvas.height = 0;
  9923. if (removeFromDOM) {
  9924. this.zoomLayer.remove();
  9925. }
  9926. this.zoomLayer = null;
  9927. }
  9928. reset({
  9929. keepZoomLayer = false,
  9930. keepAnnotationLayer = false,
  9931. keepAnnotationEditorLayer = false,
  9932. keepXfaLayer = false
  9933. } = {}) {
  9934. this.cancelRendering({
  9935. keepAnnotationLayer,
  9936. keepAnnotationEditorLayer,
  9937. keepXfaLayer
  9938. });
  9939. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9940. const div = this.div;
  9941. div.style.width = Math.floor(this.viewport.width) + "px";
  9942. div.style.height = Math.floor(this.viewport.height) + "px";
  9943. const childNodes = div.childNodes,
  9944. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  9945. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  9946. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  9947. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null;
  9948. for (let i = childNodes.length - 1; i >= 0; i--) {
  9949. const node = childNodes[i];
  9950. switch (node) {
  9951. case zoomLayerNode:
  9952. case annotationLayerNode:
  9953. case annotationEditorLayerNode:
  9954. case xfaLayerNode:
  9955. continue;
  9956. }
  9957. node.remove();
  9958. }
  9959. div.removeAttribute("data-loaded");
  9960. if (annotationLayerNode) {
  9961. this.annotationLayer.hide();
  9962. }
  9963. if (annotationEditorLayerNode) {
  9964. this.annotationEditorLayer.hide();
  9965. } else {
  9966. this.annotationEditorLayer?.destroy();
  9967. }
  9968. if (xfaLayerNode) {
  9969. this.xfaLayer.hide();
  9970. }
  9971. if (!zoomLayerNode) {
  9972. if (this.canvas) {
  9973. this.paintedViewportMap.delete(this.canvas);
  9974. this.canvas.width = 0;
  9975. this.canvas.height = 0;
  9976. delete this.canvas;
  9977. }
  9978. this._resetZoomLayer();
  9979. }
  9980. if (this.svg) {
  9981. this.paintedViewportMap.delete(this.svg);
  9982. delete this.svg;
  9983. }
  9984. this.loadingIconDiv = document.createElement("div");
  9985. this.loadingIconDiv.className = "loadingIcon notVisible";
  9986. if (this._isStandalone) {
  9987. this.toggleLoadingIconSpinner(true);
  9988. }
  9989. this.loadingIconDiv.setAttribute("role", "img");
  9990. this.l10n.get("loading").then(msg => {
  9991. this.loadingIconDiv?.setAttribute("aria-label", msg);
  9992. });
  9993. div.append(this.loadingIconDiv);
  9994. }
  9995. update({
  9996. scale = 0,
  9997. rotation = null,
  9998. optionalContentConfigPromise = null
  9999. }) {
  10000. this.scale = scale || this.scale;
  10001. if (typeof rotation === "number") {
  10002. this.rotation = rotation;
  10003. }
  10004. if (optionalContentConfigPromise instanceof Promise) {
  10005. this._optionalContentConfigPromise = optionalContentConfigPromise;
  10006. optionalContentConfigPromise.then(optionalContentConfig => {
  10007. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  10008. return;
  10009. }
  10010. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  10011. });
  10012. }
  10013. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  10014. this.viewport = this.viewport.clone({
  10015. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  10016. rotation: totalRotation
  10017. });
  10018. if (this._isStandalone) {
  10019. _ui_utils.docStyle.setProperty("--scale-factor", this.viewport.scale);
  10020. }
  10021. if (this.svg) {
  10022. this.cssTransform({
  10023. target: this.svg,
  10024. redrawAnnotationLayer: true,
  10025. redrawAnnotationEditorLayer: true,
  10026. redrawXfaLayer: true
  10027. });
  10028. this.eventBus.dispatch("pagerendered", {
  10029. source: this,
  10030. pageNumber: this.id,
  10031. cssTransform: true,
  10032. timestamp: performance.now(),
  10033. error: this._renderError
  10034. });
  10035. return;
  10036. }
  10037. let isScalingRestricted = false;
  10038. if (this.canvas && this.maxCanvasPixels > 0) {
  10039. const outputScale = this.outputScale;
  10040. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  10041. isScalingRestricted = true;
  10042. }
  10043. }
  10044. if (this.canvas) {
  10045. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  10046. this.cssTransform({
  10047. target: this.canvas,
  10048. redrawAnnotationLayer: true,
  10049. redrawAnnotationEditorLayer: true,
  10050. redrawXfaLayer: true
  10051. });
  10052. this.eventBus.dispatch("pagerendered", {
  10053. source: this,
  10054. pageNumber: this.id,
  10055. cssTransform: true,
  10056. timestamp: performance.now(),
  10057. error: this._renderError
  10058. });
  10059. return;
  10060. }
  10061. if (!this.zoomLayer && !this.canvas.hidden) {
  10062. this.zoomLayer = this.canvas.parentNode;
  10063. this.zoomLayer.style.position = "absolute";
  10064. }
  10065. }
  10066. if (this.zoomLayer) {
  10067. this.cssTransform({
  10068. target: this.zoomLayer.firstChild
  10069. });
  10070. }
  10071. this.reset({
  10072. keepZoomLayer: true,
  10073. keepAnnotationLayer: true,
  10074. keepAnnotationEditorLayer: true,
  10075. keepXfaLayer: true
  10076. });
  10077. }
  10078. cancelRendering({
  10079. keepAnnotationLayer = false,
  10080. keepAnnotationEditorLayer = false,
  10081. keepXfaLayer = false
  10082. } = {}) {
  10083. if (this.paintTask) {
  10084. this.paintTask.cancel();
  10085. this.paintTask = null;
  10086. }
  10087. this.resume = null;
  10088. if (this.textLayer) {
  10089. this.textLayer.cancel();
  10090. this.textLayer = null;
  10091. }
  10092. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  10093. this.annotationLayer.cancel();
  10094. this.annotationLayer = null;
  10095. this._annotationCanvasMap = null;
  10096. }
  10097. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  10098. this.annotationEditorLayer.cancel();
  10099. this.annotationEditorLayer = null;
  10100. }
  10101. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  10102. this.xfaLayer.cancel();
  10103. this.xfaLayer = null;
  10104. this.textHighlighter?.disable();
  10105. }
  10106. if (this._onTextLayerRendered) {
  10107. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  10108. this._onTextLayerRendered = null;
  10109. }
  10110. }
  10111. cssTransform({
  10112. target,
  10113. redrawAnnotationLayer = false,
  10114. redrawAnnotationEditorLayer = false,
  10115. redrawXfaLayer = false
  10116. }) {
  10117. const width = this.viewport.width;
  10118. const height = this.viewport.height;
  10119. const div = this.div;
  10120. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  10121. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  10122. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  10123. const absRotation = Math.abs(relativeRotation);
  10124. let scaleX = 1,
  10125. scaleY = 1;
  10126. if (absRotation === 90 || absRotation === 270) {
  10127. scaleX = height / width;
  10128. scaleY = width / height;
  10129. }
  10130. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  10131. if (this.textLayer) {
  10132. const textLayerViewport = this.textLayer.viewport;
  10133. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  10134. const textAbsRotation = Math.abs(textRelativeRotation);
  10135. let scale = width / textLayerViewport.width;
  10136. if (textAbsRotation === 90 || textAbsRotation === 270) {
  10137. scale = width / textLayerViewport.height;
  10138. }
  10139. const textLayerDiv = this.textLayer.textLayerDiv;
  10140. let transX, transY;
  10141. switch (textAbsRotation) {
  10142. case 0:
  10143. transX = transY = 0;
  10144. break;
  10145. case 90:
  10146. transX = 0;
  10147. transY = "-" + textLayerDiv.style.height;
  10148. break;
  10149. case 180:
  10150. transX = "-" + textLayerDiv.style.width;
  10151. transY = "-" + textLayerDiv.style.height;
  10152. break;
  10153. case 270:
  10154. transX = "-" + textLayerDiv.style.width;
  10155. transY = 0;
  10156. break;
  10157. default:
  10158. console.error("Bad rotation value.");
  10159. break;
  10160. }
  10161. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  10162. textLayerDiv.style.transformOrigin = "0% 0%";
  10163. }
  10164. if (redrawAnnotationLayer && this.annotationLayer) {
  10165. this._renderAnnotationLayer();
  10166. }
  10167. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  10168. this._renderAnnotationEditorLayer();
  10169. }
  10170. if (redrawXfaLayer && this.xfaLayer) {
  10171. this._renderXfaLayer();
  10172. }
  10173. }
  10174. get width() {
  10175. return this.viewport.width;
  10176. }
  10177. get height() {
  10178. return this.viewport.height;
  10179. }
  10180. getPagePoint(x, y) {
  10181. return this.viewport.convertToPdfPoint(x, y);
  10182. }
  10183. toggleLoadingIconSpinner(viewVisible = false) {
  10184. this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
  10185. }
  10186. draw() {
  10187. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  10188. console.error("Must be in new state before drawing");
  10189. this.reset();
  10190. }
  10191. const {
  10192. div,
  10193. pdfPage
  10194. } = this;
  10195. if (!pdfPage) {
  10196. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10197. if (this.loadingIconDiv) {
  10198. this.loadingIconDiv.remove();
  10199. delete this.loadingIconDiv;
  10200. }
  10201. return Promise.reject(new Error("pdfPage is not loaded"));
  10202. }
  10203. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10204. const canvasWrapper = document.createElement("div");
  10205. canvasWrapper.style.width = div.style.width;
  10206. canvasWrapper.style.height = div.style.height;
  10207. canvasWrapper.classList.add("canvasWrapper");
  10208. const lastDivBeforeTextDiv = this.annotationLayer?.div || this.annotationEditorLayer?.div;
  10209. if (lastDivBeforeTextDiv) {
  10210. lastDivBeforeTextDiv.before(canvasWrapper);
  10211. } else {
  10212. div.append(canvasWrapper);
  10213. }
  10214. let textLayer = null;
  10215. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  10216. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  10217. const textLayerDiv = document.createElement("div");
  10218. textLayerDiv.className = "textLayer";
  10219. textLayerDiv.style.width = canvasWrapper.style.width;
  10220. textLayerDiv.style.height = canvasWrapper.style.height;
  10221. if (lastDivBeforeTextDiv) {
  10222. lastDivBeforeTextDiv.before(textLayerDiv);
  10223. } else {
  10224. div.append(textLayerDiv);
  10225. }
  10226. textLayer = this.textLayerFactory.createTextLayerBuilder({
  10227. textLayerDiv,
  10228. pageIndex: this.id - 1,
  10229. viewport: this.viewport,
  10230. enhanceTextSelection: this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE,
  10231. eventBus: this.eventBus,
  10232. highlighter: this.textHighlighter,
  10233. accessibilityManager: this._accessibilityManager
  10234. });
  10235. }
  10236. this.textLayer = textLayer;
  10237. if (this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE && this.annotationLayerFactory) {
  10238. this._annotationCanvasMap ||= new Map();
  10239. this.annotationLayer ||= this.annotationLayerFactory.createAnnotationLayerBuilder({
  10240. pageDiv: div,
  10241. pdfPage,
  10242. imageResourcesPath: this.imageResourcesPath,
  10243. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  10244. l10n: this.l10n,
  10245. annotationCanvasMap: this._annotationCanvasMap,
  10246. accessibilityManager: this._accessibilityManager
  10247. });
  10248. }
  10249. if (this.xfaLayer?.div) {
  10250. div.append(this.xfaLayer.div);
  10251. }
  10252. let renderContinueCallback = null;
  10253. if (this.renderingQueue) {
  10254. renderContinueCallback = cont => {
  10255. if (!this.renderingQueue.isHighestPriority(this)) {
  10256. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  10257. this.resume = () => {
  10258. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10259. cont();
  10260. };
  10261. return;
  10262. }
  10263. cont();
  10264. };
  10265. }
  10266. const finishPaintTask = async (error = null) => {
  10267. if (paintTask === this.paintTask) {
  10268. this.paintTask = null;
  10269. }
  10270. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  10271. this._renderError = null;
  10272. return;
  10273. }
  10274. this._renderError = error;
  10275. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10276. if (this.loadingIconDiv) {
  10277. this.loadingIconDiv.remove();
  10278. delete this.loadingIconDiv;
  10279. }
  10280. this._resetZoomLayer(true);
  10281. this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
  10282. this.eventBus.dispatch("pagerendered", {
  10283. source: this,
  10284. pageNumber: this.id,
  10285. cssTransform: false,
  10286. timestamp: performance.now(),
  10287. error: this._renderError
  10288. });
  10289. if (error) {
  10290. throw error;
  10291. }
  10292. };
  10293. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  10294. paintTask.onRenderContinue = renderContinueCallback;
  10295. this.paintTask = paintTask;
  10296. const resultPromise = paintTask.promise.then(() => {
  10297. return finishPaintTask(null).then(() => {
  10298. if (textLayer) {
  10299. const readableStream = pdfPage.streamTextContent({
  10300. includeMarkedContent: true
  10301. });
  10302. textLayer.setTextContentStream(readableStream);
  10303. textLayer.render();
  10304. }
  10305. if (this.annotationLayer) {
  10306. this._renderAnnotationLayer().then(() => {
  10307. if (this.annotationEditorLayerFactory) {
  10308. this.annotationEditorLayer ||= this.annotationEditorLayerFactory.createAnnotationEditorLayerBuilder({
  10309. pageDiv: div,
  10310. pdfPage,
  10311. l10n: this.l10n,
  10312. accessibilityManager: this._accessibilityManager
  10313. });
  10314. this._renderAnnotationEditorLayer();
  10315. }
  10316. });
  10317. }
  10318. });
  10319. }, function (reason) {
  10320. return finishPaintTask(reason);
  10321. });
  10322. if (this.xfaLayerFactory) {
  10323. this.xfaLayer ||= this.xfaLayerFactory.createXfaLayerBuilder({
  10324. pageDiv: div,
  10325. pdfPage
  10326. });
  10327. this._renderXfaLayer();
  10328. }
  10329. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  10330. this._onTextLayerRendered = event => {
  10331. if (event.pageNumber !== this.id) {
  10332. return;
  10333. }
  10334. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  10335. this._onTextLayerRendered = null;
  10336. if (!this.canvas) {
  10337. return;
  10338. }
  10339. this.pdfPage.getStructTree().then(tree => {
  10340. if (!tree) {
  10341. return;
  10342. }
  10343. if (!this.canvas) {
  10344. return;
  10345. }
  10346. const treeDom = this.structTreeLayer.render(tree);
  10347. treeDom.classList.add("structTree");
  10348. this.canvas.append(treeDom);
  10349. });
  10350. };
  10351. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  10352. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder({
  10353. pdfPage
  10354. });
  10355. }
  10356. div.setAttribute("data-loaded", true);
  10357. this.eventBus.dispatch("pagerender", {
  10358. source: this,
  10359. pageNumber: this.id
  10360. });
  10361. return resultPromise;
  10362. }
  10363. paintOnCanvas(canvasWrapper) {
  10364. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  10365. const result = {
  10366. promise: renderCapability.promise,
  10367. onRenderContinue(cont) {
  10368. cont();
  10369. },
  10370. cancel() {
  10371. renderTask.cancel();
  10372. },
  10373. get separateAnnots() {
  10374. return renderTask.separateAnnots;
  10375. }
  10376. };
  10377. const viewport = this.viewport;
  10378. const canvas = document.createElement("canvas");
  10379. canvas.setAttribute("role", "presentation");
  10380. canvas.hidden = true;
  10381. let isCanvasHidden = true;
  10382. const showCanvas = function () {
  10383. if (isCanvasHidden) {
  10384. canvas.hidden = false;
  10385. isCanvasHidden = false;
  10386. }
  10387. };
  10388. canvasWrapper.append(canvas);
  10389. this.canvas = canvas;
  10390. const ctx = canvas.getContext("2d", {
  10391. alpha: false
  10392. });
  10393. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  10394. if (this.useOnlyCssZoom) {
  10395. const actualSizeViewport = viewport.clone({
  10396. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10397. });
  10398. outputScale.sx *= actualSizeViewport.width / viewport.width;
  10399. outputScale.sy *= actualSizeViewport.height / viewport.height;
  10400. }
  10401. if (this.maxCanvasPixels > 0) {
  10402. const pixelsInViewport = viewport.width * viewport.height;
  10403. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  10404. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  10405. outputScale.sx = maxScale;
  10406. outputScale.sy = maxScale;
  10407. this.hasRestrictedScaling = true;
  10408. } else {
  10409. this.hasRestrictedScaling = false;
  10410. }
  10411. }
  10412. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  10413. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  10414. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  10415. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  10416. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  10417. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  10418. this.paintedViewportMap.set(canvas, viewport);
  10419. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10420. const renderContext = {
  10421. canvasContext: ctx,
  10422. transform,
  10423. viewport: this.viewport,
  10424. annotationMode: this.#annotationMode,
  10425. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10426. annotationCanvasMap: this._annotationCanvasMap,
  10427. pageColors: this.pageColors
  10428. };
  10429. const renderTask = this.pdfPage.render(renderContext);
  10430. renderTask.onContinue = function (cont) {
  10431. showCanvas();
  10432. if (result.onRenderContinue) {
  10433. result.onRenderContinue(cont);
  10434. } else {
  10435. cont();
  10436. }
  10437. };
  10438. renderTask.promise.then(function () {
  10439. showCanvas();
  10440. renderCapability.resolve();
  10441. }, function (error) {
  10442. showCanvas();
  10443. renderCapability.reject(error);
  10444. });
  10445. return result;
  10446. }
  10447. paintOnSvg(wrapper) {
  10448. let cancelled = false;
  10449. const ensureNotCancelled = () => {
  10450. if (cancelled) {
  10451. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  10452. }
  10453. };
  10454. const pdfPage = this.pdfPage;
  10455. const actualSizeViewport = this.viewport.clone({
  10456. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10457. });
  10458. const promise = pdfPage.getOperatorList({
  10459. annotationMode: this.#annotationMode
  10460. }).then(opList => {
  10461. ensureNotCancelled();
  10462. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  10463. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  10464. ensureNotCancelled();
  10465. this.svg = svg;
  10466. this.paintedViewportMap.set(svg, actualSizeViewport);
  10467. svg.style.width = wrapper.style.width;
  10468. svg.style.height = wrapper.style.height;
  10469. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10470. wrapper.append(svg);
  10471. });
  10472. });
  10473. return {
  10474. promise,
  10475. onRenderContinue(cont) {
  10476. cont();
  10477. },
  10478. cancel() {
  10479. cancelled = true;
  10480. },
  10481. get separateAnnots() {
  10482. return false;
  10483. }
  10484. };
  10485. }
  10486. setPageLabel(label) {
  10487. this.pageLabel = typeof label === "string" ? label : null;
  10488. if (this.pageLabel !== null) {
  10489. this.div.setAttribute("data-page-label", this.pageLabel);
  10490. } else {
  10491. this.div.removeAttribute("data-page-label");
  10492. }
  10493. }
  10494. get thumbnailCanvas() {
  10495. const {
  10496. initialOptionalContent,
  10497. regularAnnotations
  10498. } = this.#useThumbnailCanvas;
  10499. return initialOptionalContent && regularAnnotations ? this.canvas : null;
  10500. }
  10501. }
  10502. exports.PDFPageView = PDFPageView;
  10503. /***/ }),
  10504. /* 34 */
  10505. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10506. Object.defineProperty(exports, "__esModule", ({
  10507. value: true
  10508. }));
  10509. exports.TextAccessibilityManager = void 0;
  10510. var _ui_utils = __webpack_require__(1);
  10511. class TextAccessibilityManager {
  10512. #enabled = false;
  10513. #textChildren = null;
  10514. #textNodes = new Map();
  10515. #waitingElements = new Map();
  10516. setTextMapping(textDivs) {
  10517. this.#textChildren = textDivs;
  10518. }
  10519. static #compareElementPositions(e1, e2) {
  10520. const rect1 = e1.getBoundingClientRect();
  10521. const rect2 = e2.getBoundingClientRect();
  10522. if (rect1.width === 0 && rect1.height === 0) {
  10523. return +1;
  10524. }
  10525. if (rect2.width === 0 && rect2.height === 0) {
  10526. return -1;
  10527. }
  10528. const top1 = rect1.y;
  10529. const bot1 = rect1.y + rect1.height;
  10530. const mid1 = rect1.y + rect1.height / 2;
  10531. const top2 = rect2.y;
  10532. const bot2 = rect2.y + rect2.height;
  10533. const mid2 = rect2.y + rect2.height / 2;
  10534. if (mid1 <= top2 && mid2 >= bot1) {
  10535. return -1;
  10536. }
  10537. if (mid2 <= top1 && mid1 >= bot2) {
  10538. return +1;
  10539. }
  10540. const centerX1 = rect1.x + rect1.width / 2;
  10541. const centerX2 = rect2.x + rect2.width / 2;
  10542. return centerX1 - centerX2;
  10543. }
  10544. enable() {
  10545. if (this.#enabled) {
  10546. throw new Error("TextAccessibilityManager is already enabled.");
  10547. }
  10548. if (!this.#textChildren) {
  10549. throw new Error("Text divs and strings have not been set.");
  10550. }
  10551. this.#enabled = true;
  10552. this.#textChildren = this.#textChildren.slice();
  10553. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  10554. if (this.#textNodes.size > 0) {
  10555. const textChildren = this.#textChildren;
  10556. for (const [id, nodeIndex] of this.#textNodes) {
  10557. const element = document.getElementById(id);
  10558. if (!element) {
  10559. this.#textNodes.delete(id);
  10560. continue;
  10561. }
  10562. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  10563. }
  10564. }
  10565. for (const [element, isRemovable] of this.#waitingElements) {
  10566. this.addPointerInTextLayer(element, isRemovable);
  10567. }
  10568. this.#waitingElements.clear();
  10569. }
  10570. disable() {
  10571. if (!this.#enabled) {
  10572. return;
  10573. }
  10574. this.#waitingElements.clear();
  10575. this.#textChildren = null;
  10576. this.#enabled = false;
  10577. }
  10578. removePointerInTextLayer(element) {
  10579. if (!this.#enabled) {
  10580. this.#waitingElements.delete(element);
  10581. return;
  10582. }
  10583. const children = this.#textChildren;
  10584. if (!children || children.length === 0) {
  10585. return;
  10586. }
  10587. const {
  10588. id
  10589. } = element;
  10590. const nodeIndex = this.#textNodes.get(id);
  10591. if (nodeIndex === undefined) {
  10592. return;
  10593. }
  10594. const node = children[nodeIndex];
  10595. this.#textNodes.delete(id);
  10596. let owns = node.getAttribute("aria-owns");
  10597. if (owns?.includes(id)) {
  10598. owns = owns.split(" ").filter(x => x !== id).join(" ");
  10599. if (owns) {
  10600. node.setAttribute("aria-owns", owns);
  10601. } else {
  10602. node.removeAttribute("aria-owns");
  10603. node.setAttribute("role", "presentation");
  10604. }
  10605. }
  10606. }
  10607. #addIdToAriaOwns(id, node) {
  10608. const owns = node.getAttribute("aria-owns");
  10609. if (!owns?.includes(id)) {
  10610. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  10611. }
  10612. node.removeAttribute("role");
  10613. }
  10614. addPointerInTextLayer(element, isRemovable) {
  10615. const {
  10616. id
  10617. } = element;
  10618. if (!id) {
  10619. return;
  10620. }
  10621. if (!this.#enabled) {
  10622. this.#waitingElements.set(element, isRemovable);
  10623. return;
  10624. }
  10625. if (isRemovable) {
  10626. this.removePointerInTextLayer(element);
  10627. }
  10628. const children = this.#textChildren;
  10629. if (!children || children.length === 0) {
  10630. return;
  10631. }
  10632. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  10633. const nodeIndex = Math.max(0, index - 1);
  10634. this.#addIdToAriaOwns(id, children[nodeIndex]);
  10635. this.#textNodes.set(id, nodeIndex);
  10636. }
  10637. moveElementInDOM(container, element, contentElement, isRemovable) {
  10638. this.addPointerInTextLayer(contentElement, isRemovable);
  10639. if (!container.hasChildNodes()) {
  10640. container.append(element);
  10641. return;
  10642. }
  10643. const children = Array.from(container.childNodes).filter(node => node !== element);
  10644. if (children.length === 0) {
  10645. return;
  10646. }
  10647. const elementToCompare = contentElement || element;
  10648. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  10649. if (index === 0) {
  10650. children[0].before(element);
  10651. } else {
  10652. children[index - 1].after(element);
  10653. }
  10654. }
  10655. }
  10656. exports.TextAccessibilityManager = TextAccessibilityManager;
  10657. /***/ }),
  10658. /* 35 */
  10659. /***/ ((__unused_webpack_module, exports) => {
  10660. Object.defineProperty(exports, "__esModule", ({
  10661. value: true
  10662. }));
  10663. exports.StructTreeLayerBuilder = void 0;
  10664. const PDF_ROLE_TO_HTML_ROLE = {
  10665. Document: null,
  10666. DocumentFragment: null,
  10667. Part: "group",
  10668. Sect: "group",
  10669. Div: "group",
  10670. Aside: "note",
  10671. NonStruct: "none",
  10672. P: null,
  10673. H: "heading",
  10674. Title: null,
  10675. FENote: "note",
  10676. Sub: "group",
  10677. Lbl: null,
  10678. Span: null,
  10679. Em: null,
  10680. Strong: null,
  10681. Link: "link",
  10682. Annot: "note",
  10683. Form: "form",
  10684. Ruby: null,
  10685. RB: null,
  10686. RT: null,
  10687. RP: null,
  10688. Warichu: null,
  10689. WT: null,
  10690. WP: null,
  10691. L: "list",
  10692. LI: "listitem",
  10693. LBody: null,
  10694. Table: "table",
  10695. TR: "row",
  10696. TH: "columnheader",
  10697. TD: "cell",
  10698. THead: "columnheader",
  10699. TBody: null,
  10700. TFoot: null,
  10701. Caption: null,
  10702. Figure: "figure",
  10703. Formula: null,
  10704. Artifact: null
  10705. };
  10706. const HEADING_PATTERN = /^H(\d+)$/;
  10707. class StructTreeLayerBuilder {
  10708. constructor({
  10709. pdfPage
  10710. }) {
  10711. this.pdfPage = pdfPage;
  10712. }
  10713. render(structTree) {
  10714. return this._walk(structTree);
  10715. }
  10716. _setAttributes(structElement, htmlElement) {
  10717. if (structElement.alt !== undefined) {
  10718. htmlElement.setAttribute("aria-label", structElement.alt);
  10719. }
  10720. if (structElement.id !== undefined) {
  10721. htmlElement.setAttribute("aria-owns", structElement.id);
  10722. }
  10723. if (structElement.lang !== undefined) {
  10724. htmlElement.setAttribute("lang", structElement.lang);
  10725. }
  10726. }
  10727. _walk(node) {
  10728. if (!node) {
  10729. return null;
  10730. }
  10731. const element = document.createElement("span");
  10732. if ("role" in node) {
  10733. const {
  10734. role
  10735. } = node;
  10736. const match = role.match(HEADING_PATTERN);
  10737. if (match) {
  10738. element.setAttribute("role", "heading");
  10739. element.setAttribute("aria-level", match[1]);
  10740. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10741. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10742. }
  10743. }
  10744. this._setAttributes(node, element);
  10745. if (node.children) {
  10746. if (node.children.length === 1 && "id" in node.children[0]) {
  10747. this._setAttributes(node.children[0], element);
  10748. } else {
  10749. for (const kid of node.children) {
  10750. element.append(this._walk(kid));
  10751. }
  10752. }
  10753. }
  10754. return element;
  10755. }
  10756. }
  10757. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10758. /***/ }),
  10759. /* 36 */
  10760. /***/ ((__unused_webpack_module, exports) => {
  10761. Object.defineProperty(exports, "__esModule", ({
  10762. value: true
  10763. }));
  10764. exports.TextHighlighter = void 0;
  10765. class TextHighlighter {
  10766. constructor({
  10767. findController,
  10768. eventBus,
  10769. pageIndex
  10770. }) {
  10771. this.findController = findController;
  10772. this.matches = [];
  10773. this.eventBus = eventBus;
  10774. this.pageIdx = pageIndex;
  10775. this._onUpdateTextLayerMatches = null;
  10776. this.textDivs = null;
  10777. this.textContentItemsStr = null;
  10778. this.enabled = false;
  10779. }
  10780. setTextMapping(divs, texts) {
  10781. this.textDivs = divs;
  10782. this.textContentItemsStr = texts;
  10783. }
  10784. enable() {
  10785. if (!this.textDivs || !this.textContentItemsStr) {
  10786. throw new Error("Text divs and strings have not been set.");
  10787. }
  10788. if (this.enabled) {
  10789. throw new Error("TextHighlighter is already enabled.");
  10790. }
  10791. this.enabled = true;
  10792. if (!this._onUpdateTextLayerMatches) {
  10793. this._onUpdateTextLayerMatches = evt => {
  10794. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  10795. this._updateMatches();
  10796. }
  10797. };
  10798. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10799. }
  10800. this._updateMatches();
  10801. }
  10802. disable() {
  10803. if (!this.enabled) {
  10804. return;
  10805. }
  10806. this.enabled = false;
  10807. if (this._onUpdateTextLayerMatches) {
  10808. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10809. this._onUpdateTextLayerMatches = null;
  10810. }
  10811. }
  10812. _convertMatches(matches, matchesLength) {
  10813. if (!matches) {
  10814. return [];
  10815. }
  10816. const {
  10817. textContentItemsStr
  10818. } = this;
  10819. let i = 0,
  10820. iIndex = 0;
  10821. const end = textContentItemsStr.length - 1;
  10822. const result = [];
  10823. for (let m = 0, mm = matches.length; m < mm; m++) {
  10824. let matchIdx = matches[m];
  10825. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  10826. iIndex += textContentItemsStr[i].length;
  10827. i++;
  10828. }
  10829. if (i === textContentItemsStr.length) {
  10830. console.error("Could not find a matching mapping");
  10831. }
  10832. const match = {
  10833. begin: {
  10834. divIdx: i,
  10835. offset: matchIdx - iIndex
  10836. }
  10837. };
  10838. matchIdx += matchesLength[m];
  10839. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  10840. iIndex += textContentItemsStr[i].length;
  10841. i++;
  10842. }
  10843. match.end = {
  10844. divIdx: i,
  10845. offset: matchIdx - iIndex
  10846. };
  10847. result.push(match);
  10848. }
  10849. return result;
  10850. }
  10851. _renderMatches(matches) {
  10852. if (matches.length === 0) {
  10853. return;
  10854. }
  10855. const {
  10856. findController,
  10857. pageIdx
  10858. } = this;
  10859. const {
  10860. textContentItemsStr,
  10861. textDivs
  10862. } = this;
  10863. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  10864. const selectedMatchIdx = findController.selected.matchIdx;
  10865. const highlightAll = findController.state.highlightAll;
  10866. let prevEnd = null;
  10867. const infinity = {
  10868. divIdx: -1,
  10869. offset: undefined
  10870. };
  10871. function beginText(begin, className) {
  10872. const divIdx = begin.divIdx;
  10873. textDivs[divIdx].textContent = "";
  10874. return appendTextToDiv(divIdx, 0, begin.offset, className);
  10875. }
  10876. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  10877. let div = textDivs[divIdx];
  10878. if (div.nodeType === Node.TEXT_NODE) {
  10879. const span = document.createElement("span");
  10880. div.before(span);
  10881. span.append(div);
  10882. textDivs[divIdx] = span;
  10883. div = span;
  10884. }
  10885. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  10886. const node = document.createTextNode(content);
  10887. if (className) {
  10888. const span = document.createElement("span");
  10889. span.className = `${className} appended`;
  10890. span.append(node);
  10891. div.append(span);
  10892. return className.includes("selected") ? span.offsetLeft : 0;
  10893. }
  10894. div.append(node);
  10895. return 0;
  10896. }
  10897. let i0 = selectedMatchIdx,
  10898. i1 = i0 + 1;
  10899. if (highlightAll) {
  10900. i0 = 0;
  10901. i1 = matches.length;
  10902. } else if (!isSelectedPage) {
  10903. return;
  10904. }
  10905. for (let i = i0; i < i1; i++) {
  10906. const match = matches[i];
  10907. const begin = match.begin;
  10908. const end = match.end;
  10909. const isSelected = isSelectedPage && i === selectedMatchIdx;
  10910. const highlightSuffix = isSelected ? " selected" : "";
  10911. let selectedLeft = 0;
  10912. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  10913. if (prevEnd !== null) {
  10914. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10915. }
  10916. beginText(begin);
  10917. } else {
  10918. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  10919. }
  10920. if (begin.divIdx === end.divIdx) {
  10921. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  10922. } else {
  10923. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  10924. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  10925. textDivs[n0].className = "highlight middle" + highlightSuffix;
  10926. }
  10927. beginText(end, "highlight end" + highlightSuffix);
  10928. }
  10929. prevEnd = end;
  10930. if (isSelected) {
  10931. findController.scrollMatchIntoView({
  10932. element: textDivs[begin.divIdx],
  10933. selectedLeft,
  10934. pageIndex: pageIdx,
  10935. matchIndex: selectedMatchIdx
  10936. });
  10937. }
  10938. }
  10939. if (prevEnd) {
  10940. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10941. }
  10942. }
  10943. _updateMatches() {
  10944. if (!this.enabled) {
  10945. return;
  10946. }
  10947. const {
  10948. findController,
  10949. matches,
  10950. pageIdx
  10951. } = this;
  10952. const {
  10953. textContentItemsStr,
  10954. textDivs
  10955. } = this;
  10956. let clearedUntilDivIdx = -1;
  10957. for (let i = 0, ii = matches.length; i < ii; i++) {
  10958. const match = matches[i];
  10959. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  10960. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  10961. const div = textDivs[n];
  10962. div.textContent = textContentItemsStr[n];
  10963. div.className = "";
  10964. }
  10965. clearedUntilDivIdx = match.end.divIdx + 1;
  10966. }
  10967. if (!findController?.highlightMatches) {
  10968. return;
  10969. }
  10970. const pageMatches = findController.pageMatches[pageIdx] || null;
  10971. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  10972. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  10973. this._renderMatches(this.matches);
  10974. }
  10975. }
  10976. exports.TextHighlighter = TextHighlighter;
  10977. /***/ }),
  10978. /* 37 */
  10979. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10980. Object.defineProperty(exports, "__esModule", ({
  10981. value: true
  10982. }));
  10983. exports.TextLayerBuilder = void 0;
  10984. var _pdfjsLib = __webpack_require__(5);
  10985. const EXPAND_DIVS_TIMEOUT = 300;
  10986. class TextLayerBuilder {
  10987. constructor({
  10988. textLayerDiv,
  10989. eventBus,
  10990. pageIndex,
  10991. viewport,
  10992. highlighter = null,
  10993. enhanceTextSelection = false,
  10994. accessibilityManager = null
  10995. }) {
  10996. this.textLayerDiv = textLayerDiv;
  10997. this.eventBus = eventBus;
  10998. this.textContent = null;
  10999. this.textContentItemsStr = [];
  11000. this.textContentStream = null;
  11001. this.renderingDone = false;
  11002. this.pageNumber = pageIndex + 1;
  11003. this.viewport = viewport;
  11004. this.textDivs = [];
  11005. this.textLayerRenderTask = null;
  11006. this.highlighter = highlighter;
  11007. this.enhanceTextSelection = enhanceTextSelection;
  11008. this.accessibilityManager = accessibilityManager;
  11009. this._bindMouse();
  11010. }
  11011. _finishRendering() {
  11012. this.renderingDone = true;
  11013. if (!this.enhanceTextSelection) {
  11014. const endOfContent = document.createElement("div");
  11015. endOfContent.className = "endOfContent";
  11016. this.textLayerDiv.append(endOfContent);
  11017. }
  11018. this.eventBus.dispatch("textlayerrendered", {
  11019. source: this,
  11020. pageNumber: this.pageNumber,
  11021. numTextDivs: this.textDivs.length
  11022. });
  11023. }
  11024. render(timeout = 0) {
  11025. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  11026. return;
  11027. }
  11028. this.cancel();
  11029. this.textDivs.length = 0;
  11030. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  11031. this.accessibilityManager?.setTextMapping(this.textDivs);
  11032. const textLayerFrag = document.createDocumentFragment();
  11033. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  11034. textContent: this.textContent,
  11035. textContentStream: this.textContentStream,
  11036. container: textLayerFrag,
  11037. viewport: this.viewport,
  11038. textDivs: this.textDivs,
  11039. textContentItemsStr: this.textContentItemsStr,
  11040. timeout,
  11041. enhanceTextSelection: this.enhanceTextSelection
  11042. });
  11043. this.textLayerRenderTask.promise.then(() => {
  11044. this.textLayerDiv.append(textLayerFrag);
  11045. this._finishRendering();
  11046. this.highlighter?.enable();
  11047. this.accessibilityManager?.enable();
  11048. }, function (reason) {});
  11049. }
  11050. cancel() {
  11051. if (this.textLayerRenderTask) {
  11052. this.textLayerRenderTask.cancel();
  11053. this.textLayerRenderTask = null;
  11054. }
  11055. this.highlighter?.disable();
  11056. this.accessibilityManager?.disable();
  11057. }
  11058. setTextContentStream(readableStream) {
  11059. this.cancel();
  11060. this.textContentStream = readableStream;
  11061. }
  11062. setTextContent(textContent) {
  11063. this.cancel();
  11064. this.textContent = textContent;
  11065. }
  11066. _bindMouse() {
  11067. const div = this.textLayerDiv;
  11068. let expandDivsTimer = null;
  11069. div.addEventListener("mousedown", evt => {
  11070. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  11071. this.textLayerRenderTask.expandTextDivs(true);
  11072. if (expandDivsTimer) {
  11073. clearTimeout(expandDivsTimer);
  11074. expandDivsTimer = null;
  11075. }
  11076. return;
  11077. }
  11078. const end = div.querySelector(".endOfContent");
  11079. if (!end) {
  11080. return;
  11081. }
  11082. let adjustTop = evt.target !== div;
  11083. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  11084. if (adjustTop) {
  11085. const divBounds = div.getBoundingClientRect();
  11086. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  11087. end.style.top = (r * 100).toFixed(2) + "%";
  11088. }
  11089. end.classList.add("active");
  11090. });
  11091. div.addEventListener("mouseup", () => {
  11092. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  11093. expandDivsTimer = setTimeout(() => {
  11094. if (this.textLayerRenderTask) {
  11095. this.textLayerRenderTask.expandTextDivs(false);
  11096. }
  11097. expandDivsTimer = null;
  11098. }, EXPAND_DIVS_TIMEOUT);
  11099. return;
  11100. }
  11101. const end = div.querySelector(".endOfContent");
  11102. if (!end) {
  11103. return;
  11104. }
  11105. end.style.top = "";
  11106. end.classList.remove("active");
  11107. });
  11108. }
  11109. }
  11110. exports.TextLayerBuilder = TextLayerBuilder;
  11111. /***/ }),
  11112. /* 38 */
  11113. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11114. Object.defineProperty(exports, "__esModule", ({
  11115. value: true
  11116. }));
  11117. exports.XfaLayerBuilder = void 0;
  11118. var _pdfjsLib = __webpack_require__(5);
  11119. class XfaLayerBuilder {
  11120. constructor({
  11121. pageDiv,
  11122. pdfPage,
  11123. annotationStorage = null,
  11124. linkService,
  11125. xfaHtml = null
  11126. }) {
  11127. this.pageDiv = pageDiv;
  11128. this.pdfPage = pdfPage;
  11129. this.annotationStorage = annotationStorage;
  11130. this.linkService = linkService;
  11131. this.xfaHtml = xfaHtml;
  11132. this.div = null;
  11133. this._cancelled = false;
  11134. }
  11135. render(viewport, intent = "display") {
  11136. if (intent === "print") {
  11137. const parameters = {
  11138. viewport: viewport.clone({
  11139. dontFlip: true
  11140. }),
  11141. div: this.div,
  11142. xfaHtml: this.xfaHtml,
  11143. annotationStorage: this.annotationStorage,
  11144. linkService: this.linkService,
  11145. intent
  11146. };
  11147. const div = document.createElement("div");
  11148. this.pageDiv.append(div);
  11149. parameters.div = div;
  11150. const result = _pdfjsLib.XfaLayer.render(parameters);
  11151. return Promise.resolve(result);
  11152. }
  11153. return this.pdfPage.getXfa().then(xfaHtml => {
  11154. if (this._cancelled || !xfaHtml) {
  11155. return {
  11156. textDivs: []
  11157. };
  11158. }
  11159. const parameters = {
  11160. viewport: viewport.clone({
  11161. dontFlip: true
  11162. }),
  11163. div: this.div,
  11164. xfaHtml,
  11165. annotationStorage: this.annotationStorage,
  11166. linkService: this.linkService,
  11167. intent
  11168. };
  11169. if (this.div) {
  11170. return _pdfjsLib.XfaLayer.update(parameters);
  11171. }
  11172. this.div = document.createElement("div");
  11173. this.pageDiv.append(this.div);
  11174. parameters.div = this.div;
  11175. return _pdfjsLib.XfaLayer.render(parameters);
  11176. }).catch(error => {
  11177. console.error(error);
  11178. });
  11179. }
  11180. cancel() {
  11181. this._cancelled = true;
  11182. }
  11183. hide() {
  11184. if (!this.div) {
  11185. return;
  11186. }
  11187. this.div.hidden = true;
  11188. }
  11189. }
  11190. exports.XfaLayerBuilder = XfaLayerBuilder;
  11191. /***/ }),
  11192. /* 39 */
  11193. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11194. Object.defineProperty(exports, "__esModule", ({
  11195. value: true
  11196. }));
  11197. exports.SecondaryToolbar = void 0;
  11198. var _ui_utils = __webpack_require__(1);
  11199. var _pdf_cursor_tools = __webpack_require__(7);
  11200. var _base_viewer = __webpack_require__(29);
  11201. class SecondaryToolbar {
  11202. constructor(options, eventBus) {
  11203. this.toolbar = options.toolbar;
  11204. this.toggleButton = options.toggleButton;
  11205. this.buttons = [{
  11206. element: options.presentationModeButton,
  11207. eventName: "presentationmode",
  11208. close: true
  11209. }, {
  11210. element: options.printButton,
  11211. eventName: "print",
  11212. close: true
  11213. }, {
  11214. element: options.downloadButton,
  11215. eventName: "download",
  11216. close: true
  11217. }, {
  11218. element: options.viewBookmarkButton,
  11219. eventName: null,
  11220. close: true
  11221. }, {
  11222. element: options.firstPageButton,
  11223. eventName: "firstpage",
  11224. close: true
  11225. }, {
  11226. element: options.lastPageButton,
  11227. eventName: "lastpage",
  11228. close: true
  11229. }, {
  11230. element: options.pageRotateCwButton,
  11231. eventName: "rotatecw",
  11232. close: false
  11233. }, {
  11234. element: options.pageRotateCcwButton,
  11235. eventName: "rotateccw",
  11236. close: false
  11237. }, {
  11238. element: options.cursorSelectToolButton,
  11239. eventName: "switchcursortool",
  11240. eventDetails: {
  11241. tool: _pdf_cursor_tools.CursorTool.SELECT
  11242. },
  11243. close: true
  11244. }, {
  11245. element: options.cursorHandToolButton,
  11246. eventName: "switchcursortool",
  11247. eventDetails: {
  11248. tool: _pdf_cursor_tools.CursorTool.HAND
  11249. },
  11250. close: true
  11251. }, {
  11252. element: options.scrollPageButton,
  11253. eventName: "switchscrollmode",
  11254. eventDetails: {
  11255. mode: _ui_utils.ScrollMode.PAGE
  11256. },
  11257. close: true
  11258. }, {
  11259. element: options.scrollVerticalButton,
  11260. eventName: "switchscrollmode",
  11261. eventDetails: {
  11262. mode: _ui_utils.ScrollMode.VERTICAL
  11263. },
  11264. close: true
  11265. }, {
  11266. element: options.scrollHorizontalButton,
  11267. eventName: "switchscrollmode",
  11268. eventDetails: {
  11269. mode: _ui_utils.ScrollMode.HORIZONTAL
  11270. },
  11271. close: true
  11272. }, {
  11273. element: options.scrollWrappedButton,
  11274. eventName: "switchscrollmode",
  11275. eventDetails: {
  11276. mode: _ui_utils.ScrollMode.WRAPPED
  11277. },
  11278. close: true
  11279. }, {
  11280. element: options.spreadNoneButton,
  11281. eventName: "switchspreadmode",
  11282. eventDetails: {
  11283. mode: _ui_utils.SpreadMode.NONE
  11284. },
  11285. close: true
  11286. }, {
  11287. element: options.spreadOddButton,
  11288. eventName: "switchspreadmode",
  11289. eventDetails: {
  11290. mode: _ui_utils.SpreadMode.ODD
  11291. },
  11292. close: true
  11293. }, {
  11294. element: options.spreadEvenButton,
  11295. eventName: "switchspreadmode",
  11296. eventDetails: {
  11297. mode: _ui_utils.SpreadMode.EVEN
  11298. },
  11299. close: true
  11300. }, {
  11301. element: options.documentPropertiesButton,
  11302. eventName: "documentproperties",
  11303. close: true
  11304. }];
  11305. this.buttons.push({
  11306. element: options.openFileButton,
  11307. eventName: "openfile",
  11308. close: true
  11309. });
  11310. this.items = {
  11311. firstPage: options.firstPageButton,
  11312. lastPage: options.lastPageButton,
  11313. pageRotateCw: options.pageRotateCwButton,
  11314. pageRotateCcw: options.pageRotateCcwButton
  11315. };
  11316. this.eventBus = eventBus;
  11317. this.opened = false;
  11318. this.#bindClickListeners();
  11319. this.#bindCursorToolsListener(options);
  11320. this.#bindScrollModeListener(options);
  11321. this.#bindSpreadModeListener(options);
  11322. this.reset();
  11323. }
  11324. get isOpen() {
  11325. return this.opened;
  11326. }
  11327. setPageNumber(pageNumber) {
  11328. this.pageNumber = pageNumber;
  11329. this.#updateUIState();
  11330. }
  11331. setPagesCount(pagesCount) {
  11332. this.pagesCount = pagesCount;
  11333. this.#updateUIState();
  11334. }
  11335. reset() {
  11336. this.pageNumber = 0;
  11337. this.pagesCount = 0;
  11338. this.#updateUIState();
  11339. this.eventBus.dispatch("secondarytoolbarreset", {
  11340. source: this
  11341. });
  11342. }
  11343. #updateUIState() {
  11344. this.items.firstPage.disabled = this.pageNumber <= 1;
  11345. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  11346. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  11347. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  11348. }
  11349. #bindClickListeners() {
  11350. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  11351. for (const {
  11352. element,
  11353. eventName,
  11354. close,
  11355. eventDetails
  11356. } of this.buttons) {
  11357. element.addEventListener("click", evt => {
  11358. if (eventName !== null) {
  11359. const details = {
  11360. source: this
  11361. };
  11362. for (const property in eventDetails) {
  11363. details[property] = eventDetails[property];
  11364. }
  11365. this.eventBus.dispatch(eventName, details);
  11366. }
  11367. if (close) {
  11368. this.close();
  11369. }
  11370. });
  11371. }
  11372. }
  11373. #bindCursorToolsListener({
  11374. cursorSelectToolButton,
  11375. cursorHandToolButton
  11376. }) {
  11377. this.eventBus._on("cursortoolchanged", function ({
  11378. tool
  11379. }) {
  11380. const isSelect = tool === _pdf_cursor_tools.CursorTool.SELECT,
  11381. isHand = tool === _pdf_cursor_tools.CursorTool.HAND;
  11382. cursorSelectToolButton.classList.toggle("toggled", isSelect);
  11383. cursorHandToolButton.classList.toggle("toggled", isHand);
  11384. cursorSelectToolButton.setAttribute("aria-checked", isSelect);
  11385. cursorHandToolButton.setAttribute("aria-checked", isHand);
  11386. });
  11387. }
  11388. #bindScrollModeListener({
  11389. scrollPageButton,
  11390. scrollVerticalButton,
  11391. scrollHorizontalButton,
  11392. scrollWrappedButton,
  11393. spreadNoneButton,
  11394. spreadOddButton,
  11395. spreadEvenButton
  11396. }) {
  11397. const scrollModeChanged = ({
  11398. mode
  11399. }) => {
  11400. const isPage = mode === _ui_utils.ScrollMode.PAGE,
  11401. isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
  11402. isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
  11403. isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
  11404. scrollPageButton.classList.toggle("toggled", isPage);
  11405. scrollVerticalButton.classList.toggle("toggled", isVertical);
  11406. scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
  11407. scrollWrappedButton.classList.toggle("toggled", isWrapped);
  11408. scrollPageButton.setAttribute("aria-checked", isPage);
  11409. scrollVerticalButton.setAttribute("aria-checked", isVertical);
  11410. scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
  11411. scrollWrappedButton.setAttribute("aria-checked", isWrapped);
  11412. const forceScrollModePage = this.pagesCount > _base_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11413. scrollPageButton.disabled = forceScrollModePage;
  11414. scrollVerticalButton.disabled = forceScrollModePage;
  11415. scrollHorizontalButton.disabled = forceScrollModePage;
  11416. scrollWrappedButton.disabled = forceScrollModePage;
  11417. spreadNoneButton.disabled = isHorizontal;
  11418. spreadOddButton.disabled = isHorizontal;
  11419. spreadEvenButton.disabled = isHorizontal;
  11420. };
  11421. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  11422. this.eventBus._on("secondarytoolbarreset", evt => {
  11423. if (evt.source === this) {
  11424. scrollModeChanged({
  11425. mode: _ui_utils.ScrollMode.VERTICAL
  11426. });
  11427. }
  11428. });
  11429. }
  11430. #bindSpreadModeListener({
  11431. spreadNoneButton,
  11432. spreadOddButton,
  11433. spreadEvenButton
  11434. }) {
  11435. function spreadModeChanged({
  11436. mode
  11437. }) {
  11438. const isNone = mode === _ui_utils.SpreadMode.NONE,
  11439. isOdd = mode === _ui_utils.SpreadMode.ODD,
  11440. isEven = mode === _ui_utils.SpreadMode.EVEN;
  11441. spreadNoneButton.classList.toggle("toggled", isNone);
  11442. spreadOddButton.classList.toggle("toggled", isOdd);
  11443. spreadEvenButton.classList.toggle("toggled", isEven);
  11444. spreadNoneButton.setAttribute("aria-checked", isNone);
  11445. spreadOddButton.setAttribute("aria-checked", isOdd);
  11446. spreadEvenButton.setAttribute("aria-checked", isEven);
  11447. }
  11448. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  11449. this.eventBus._on("secondarytoolbarreset", evt => {
  11450. if (evt.source === this) {
  11451. spreadModeChanged({
  11452. mode: _ui_utils.SpreadMode.NONE
  11453. });
  11454. }
  11455. });
  11456. }
  11457. open() {
  11458. if (this.opened) {
  11459. return;
  11460. }
  11461. this.opened = true;
  11462. this.toggleButton.classList.add("toggled");
  11463. this.toggleButton.setAttribute("aria-expanded", "true");
  11464. this.toolbar.classList.remove("hidden");
  11465. }
  11466. close() {
  11467. if (!this.opened) {
  11468. return;
  11469. }
  11470. this.opened = false;
  11471. this.toolbar.classList.add("hidden");
  11472. this.toggleButton.classList.remove("toggled");
  11473. this.toggleButton.setAttribute("aria-expanded", "false");
  11474. }
  11475. toggle() {
  11476. if (this.opened) {
  11477. this.close();
  11478. } else {
  11479. this.open();
  11480. }
  11481. }
  11482. }
  11483. exports.SecondaryToolbar = SecondaryToolbar;
  11484. /***/ }),
  11485. /* 40 */
  11486. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11487. Object.defineProperty(exports, "__esModule", ({
  11488. value: true
  11489. }));
  11490. exports.Toolbar = void 0;
  11491. var _ui_utils = __webpack_require__(1);
  11492. var _pdfjsLib = __webpack_require__(5);
  11493. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  11494. class Toolbar {
  11495. #wasLocalized = false;
  11496. constructor(options, eventBus, l10n) {
  11497. this.toolbar = options.container;
  11498. this.eventBus = eventBus;
  11499. this.l10n = l10n;
  11500. this.buttons = [{
  11501. element: options.previous,
  11502. eventName: "previouspage"
  11503. }, {
  11504. element: options.next,
  11505. eventName: "nextpage"
  11506. }, {
  11507. element: options.zoomIn,
  11508. eventName: "zoomin"
  11509. }, {
  11510. element: options.zoomOut,
  11511. eventName: "zoomout"
  11512. }, {
  11513. element: options.print,
  11514. eventName: "print"
  11515. }, {
  11516. element: options.presentationModeButton,
  11517. eventName: "presentationmode"
  11518. }, {
  11519. element: options.download,
  11520. eventName: "download"
  11521. }, {
  11522. element: options.viewBookmark,
  11523. eventName: null
  11524. }, {
  11525. element: options.editorFreeTextButton,
  11526. eventName: "switchannotationeditormode",
  11527. eventDetails: {
  11528. get mode() {
  11529. const {
  11530. classList
  11531. } = options.editorFreeTextButton;
  11532. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  11533. }
  11534. }
  11535. }, {
  11536. element: options.editorInkButton,
  11537. eventName: "switchannotationeditormode",
  11538. eventDetails: {
  11539. get mode() {
  11540. const {
  11541. classList
  11542. } = options.editorInkButton;
  11543. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  11544. }
  11545. }
  11546. }];
  11547. this.buttons.push({
  11548. element: options.openFile,
  11549. eventName: "openfile"
  11550. });
  11551. this.items = {
  11552. numPages: options.numPages,
  11553. pageNumber: options.pageNumber,
  11554. scaleSelect: options.scaleSelect,
  11555. customScaleOption: options.customScaleOption,
  11556. previous: options.previous,
  11557. next: options.next,
  11558. zoomIn: options.zoomIn,
  11559. zoomOut: options.zoomOut
  11560. };
  11561. this.#bindListeners(options);
  11562. this.reset();
  11563. }
  11564. setPageNumber(pageNumber, pageLabel) {
  11565. this.pageNumber = pageNumber;
  11566. this.pageLabel = pageLabel;
  11567. this.#updateUIState(false);
  11568. }
  11569. setPagesCount(pagesCount, hasPageLabels) {
  11570. this.pagesCount = pagesCount;
  11571. this.hasPageLabels = hasPageLabels;
  11572. this.#updateUIState(true);
  11573. }
  11574. setPageScale(pageScaleValue, pageScale) {
  11575. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11576. this.pageScale = pageScale;
  11577. this.#updateUIState(false);
  11578. }
  11579. reset() {
  11580. this.pageNumber = 0;
  11581. this.pageLabel = null;
  11582. this.hasPageLabels = false;
  11583. this.pagesCount = 0;
  11584. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  11585. this.pageScale = _ui_utils.DEFAULT_SCALE;
  11586. this.#updateUIState(true);
  11587. this.updateLoadingIndicatorState();
  11588. this.eventBus.dispatch("toolbarreset", {
  11589. source: this
  11590. });
  11591. }
  11592. #bindListeners(options) {
  11593. const {
  11594. pageNumber,
  11595. scaleSelect
  11596. } = this.items;
  11597. const self = this;
  11598. for (const {
  11599. element,
  11600. eventName,
  11601. eventDetails
  11602. } of this.buttons) {
  11603. element.addEventListener("click", evt => {
  11604. if (eventName !== null) {
  11605. const details = {
  11606. source: this
  11607. };
  11608. if (eventDetails) {
  11609. for (const property in eventDetails) {
  11610. details[property] = eventDetails[property];
  11611. }
  11612. }
  11613. this.eventBus.dispatch(eventName, details);
  11614. }
  11615. });
  11616. }
  11617. pageNumber.addEventListener("click", function () {
  11618. this.select();
  11619. });
  11620. pageNumber.addEventListener("change", function () {
  11621. self.eventBus.dispatch("pagenumberchanged", {
  11622. source: self,
  11623. value: this.value
  11624. });
  11625. });
  11626. scaleSelect.addEventListener("change", function () {
  11627. if (this.value === "custom") {
  11628. return;
  11629. }
  11630. self.eventBus.dispatch("scalechanged", {
  11631. source: self,
  11632. value: this.value
  11633. });
  11634. });
  11635. scaleSelect.addEventListener("click", function (evt) {
  11636. const target = evt.target;
  11637. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11638. this.blur();
  11639. }
  11640. });
  11641. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  11642. this.eventBus._on("localized", () => {
  11643. this.#wasLocalized = true;
  11644. this.#adjustScaleWidth();
  11645. this.#updateUIState(true);
  11646. });
  11647. this.#bindEditorToolsListener(options);
  11648. }
  11649. #bindEditorToolsListener({
  11650. editorFreeTextButton,
  11651. editorFreeTextParamsToolbar,
  11652. editorInkButton,
  11653. editorInkParamsToolbar
  11654. }) {
  11655. const editorModeChanged = (evt, disableButtons = false) => {
  11656. const editorButtons = [{
  11657. mode: _pdfjsLib.AnnotationEditorType.FREETEXT,
  11658. button: editorFreeTextButton,
  11659. toolbar: editorFreeTextParamsToolbar
  11660. }, {
  11661. mode: _pdfjsLib.AnnotationEditorType.INK,
  11662. button: editorInkButton,
  11663. toolbar: editorInkParamsToolbar
  11664. }];
  11665. for (const {
  11666. mode,
  11667. button,
  11668. toolbar
  11669. } of editorButtons) {
  11670. const checked = mode === evt.mode;
  11671. button.classList.toggle("toggled", checked);
  11672. button.setAttribute("aria-checked", checked);
  11673. button.disabled = disableButtons;
  11674. toolbar?.classList.toggle("hidden", !checked);
  11675. }
  11676. };
  11677. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  11678. this.eventBus._on("toolbarreset", evt => {
  11679. if (evt.source === this) {
  11680. editorModeChanged({
  11681. mode: _pdfjsLib.AnnotationEditorType.NONE
  11682. }, true);
  11683. }
  11684. });
  11685. }
  11686. #updateUIState(resetNumPages = false) {
  11687. if (!this.#wasLocalized) {
  11688. return;
  11689. }
  11690. const {
  11691. pageNumber,
  11692. pagesCount,
  11693. pageScaleValue,
  11694. pageScale,
  11695. items
  11696. } = this;
  11697. if (resetNumPages) {
  11698. if (this.hasPageLabels) {
  11699. items.pageNumber.type = "text";
  11700. } else {
  11701. items.pageNumber.type = "number";
  11702. this.l10n.get("of_pages", {
  11703. pagesCount
  11704. }).then(msg => {
  11705. items.numPages.textContent = msg;
  11706. });
  11707. }
  11708. items.pageNumber.max = pagesCount;
  11709. }
  11710. if (this.hasPageLabels) {
  11711. items.pageNumber.value = this.pageLabel;
  11712. this.l10n.get("page_of_pages", {
  11713. pageNumber,
  11714. pagesCount
  11715. }).then(msg => {
  11716. items.numPages.textContent = msg;
  11717. });
  11718. } else {
  11719. items.pageNumber.value = pageNumber;
  11720. }
  11721. items.previous.disabled = pageNumber <= 1;
  11722. items.next.disabled = pageNumber >= pagesCount;
  11723. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  11724. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  11725. this.l10n.get("page_scale_percent", {
  11726. scale: Math.round(pageScale * 10000) / 100
  11727. }).then(msg => {
  11728. let predefinedValueFound = false;
  11729. for (const option of items.scaleSelect.options) {
  11730. if (option.value !== pageScaleValue) {
  11731. option.selected = false;
  11732. continue;
  11733. }
  11734. option.selected = true;
  11735. predefinedValueFound = true;
  11736. }
  11737. if (!predefinedValueFound) {
  11738. items.customScaleOption.textContent = msg;
  11739. items.customScaleOption.selected = true;
  11740. }
  11741. });
  11742. }
  11743. updateLoadingIndicatorState(loading = false) {
  11744. const {
  11745. pageNumber
  11746. } = this.items;
  11747. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  11748. }
  11749. async #adjustScaleWidth() {
  11750. const {
  11751. items,
  11752. l10n
  11753. } = this;
  11754. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  11755. await _ui_utils.animationStarted;
  11756. const style = getComputedStyle(items.scaleSelect),
  11757. scaleSelectContainerWidth = parseInt(style.getPropertyValue("--scale-select-container-width"), 10),
  11758. scaleSelectOverflow = parseInt(style.getPropertyValue("--scale-select-overflow"), 10);
  11759. const canvas = document.createElement("canvas");
  11760. const ctx = canvas.getContext("2d", {
  11761. alpha: false
  11762. });
  11763. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  11764. let maxWidth = 0;
  11765. for (const predefinedValue of await predefinedValuesPromise) {
  11766. const {
  11767. width
  11768. } = ctx.measureText(predefinedValue);
  11769. if (width > maxWidth) {
  11770. maxWidth = width;
  11771. }
  11772. }
  11773. maxWidth += 2 * scaleSelectOverflow;
  11774. if (maxWidth > scaleSelectContainerWidth) {
  11775. _ui_utils.docStyle.setProperty("--scale-select-container-width", `${maxWidth}px`);
  11776. }
  11777. canvas.width = 0;
  11778. canvas.height = 0;
  11779. }
  11780. }
  11781. exports.Toolbar = Toolbar;
  11782. /***/ }),
  11783. /* 41 */
  11784. /***/ ((__unused_webpack_module, exports) => {
  11785. Object.defineProperty(exports, "__esModule", ({
  11786. value: true
  11787. }));
  11788. exports.ViewHistory = void 0;
  11789. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  11790. class ViewHistory {
  11791. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  11792. this.fingerprint = fingerprint;
  11793. this.cacheSize = cacheSize;
  11794. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  11795. const database = JSON.parse(databaseStr || "{}");
  11796. let index = -1;
  11797. if (!Array.isArray(database.files)) {
  11798. database.files = [];
  11799. } else {
  11800. while (database.files.length >= this.cacheSize) {
  11801. database.files.shift();
  11802. }
  11803. for (let i = 0, ii = database.files.length; i < ii; i++) {
  11804. const branch = database.files[i];
  11805. if (branch.fingerprint === this.fingerprint) {
  11806. index = i;
  11807. break;
  11808. }
  11809. }
  11810. }
  11811. if (index === -1) {
  11812. index = database.files.push({
  11813. fingerprint: this.fingerprint
  11814. }) - 1;
  11815. }
  11816. this.file = database.files[index];
  11817. this.database = database;
  11818. });
  11819. }
  11820. async _writeToStorage() {
  11821. const databaseStr = JSON.stringify(this.database);
  11822. localStorage.setItem("pdfjs.history", databaseStr);
  11823. }
  11824. async _readFromStorage() {
  11825. return localStorage.getItem("pdfjs.history");
  11826. }
  11827. async set(name, val) {
  11828. await this._initializedPromise;
  11829. this.file[name] = val;
  11830. return this._writeToStorage();
  11831. }
  11832. async setMultiple(properties) {
  11833. await this._initializedPromise;
  11834. for (const name in properties) {
  11835. this.file[name] = properties[name];
  11836. }
  11837. return this._writeToStorage();
  11838. }
  11839. async get(name, defaultValue) {
  11840. await this._initializedPromise;
  11841. const val = this.file[name];
  11842. return val !== undefined ? val : defaultValue;
  11843. }
  11844. async getMultiple(properties) {
  11845. await this._initializedPromise;
  11846. const values = Object.create(null);
  11847. for (const name in properties) {
  11848. const val = this.file[name];
  11849. values[name] = val !== undefined ? val : properties[name];
  11850. }
  11851. return values;
  11852. }
  11853. }
  11854. exports.ViewHistory = ViewHistory;
  11855. /***/ }),
  11856. /* 42 */
  11857. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11858. Object.defineProperty(exports, "__esModule", ({
  11859. value: true
  11860. }));
  11861. exports.GenericCom = void 0;
  11862. var _app = __webpack_require__(4);
  11863. var _preferences = __webpack_require__(43);
  11864. var _download_manager = __webpack_require__(44);
  11865. var _genericl10n = __webpack_require__(45);
  11866. var _generic_scripting = __webpack_require__(47);
  11867. ;
  11868. const GenericCom = {};
  11869. exports.GenericCom = GenericCom;
  11870. class GenericPreferences extends _preferences.BasePreferences {
  11871. async _writeToStorage(prefObj) {
  11872. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  11873. }
  11874. async _readFromStorage(prefObj) {
  11875. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  11876. }
  11877. }
  11878. class GenericExternalServices extends _app.DefaultExternalServices {
  11879. static createDownloadManager(options) {
  11880. return new _download_manager.DownloadManager();
  11881. }
  11882. static createPreferences() {
  11883. return new GenericPreferences();
  11884. }
  11885. static createL10n({
  11886. locale = "en-US"
  11887. }) {
  11888. return new _genericl10n.GenericL10n(locale);
  11889. }
  11890. static createScripting({
  11891. sandboxBundleSrc
  11892. }) {
  11893. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  11894. }
  11895. }
  11896. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  11897. /***/ }),
  11898. /* 43 */
  11899. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11900. Object.defineProperty(exports, "__esModule", ({
  11901. value: true
  11902. }));
  11903. exports.BasePreferences = void 0;
  11904. var _app_options = __webpack_require__(2);
  11905. class BasePreferences {
  11906. #defaults = Object.freeze({
  11907. "annotationEditorMode": -1,
  11908. "annotationMode": 2,
  11909. "cursorToolOnLoad": 0,
  11910. "defaultZoomValue": "",
  11911. "disablePageLabels": false,
  11912. "enablePermissions": false,
  11913. "enablePrintAutoRotate": true,
  11914. "enableScripting": true,
  11915. "externalLinkTarget": 0,
  11916. "historyUpdateUrl": false,
  11917. "ignoreDestinationZoom": false,
  11918. "forcePageColors": false,
  11919. "pageColorsBackground": "Canvas",
  11920. "pageColorsForeground": "CanvasText",
  11921. "pdfBugEnabled": false,
  11922. "sidebarViewOnLoad": -1,
  11923. "scrollModeOnLoad": -1,
  11924. "spreadModeOnLoad": -1,
  11925. "textLayerMode": 1,
  11926. "useOnlyCssZoom": false,
  11927. "viewerCssTheme": 0,
  11928. "viewOnLoad": 0,
  11929. "disableAutoFetch": false,
  11930. "disableFontFace": false,
  11931. "disableRange": false,
  11932. "disableStream": false,
  11933. "enableXfa": true,
  11934. "renderer": "canvas"
  11935. });
  11936. #prefs = Object.create(null);
  11937. #initializedPromise = null;
  11938. constructor() {
  11939. if (this.constructor === BasePreferences) {
  11940. throw new Error("Cannot initialize BasePreferences.");
  11941. }
  11942. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  11943. for (const name in this.#defaults) {
  11944. const prefValue = prefs?.[name];
  11945. if (typeof prefValue === typeof this.#defaults[name]) {
  11946. this.#prefs[name] = prefValue;
  11947. }
  11948. }
  11949. });
  11950. }
  11951. async _writeToStorage(prefObj) {
  11952. throw new Error("Not implemented: _writeToStorage");
  11953. }
  11954. async _readFromStorage(prefObj) {
  11955. throw new Error("Not implemented: _readFromStorage");
  11956. }
  11957. async reset() {
  11958. await this.#initializedPromise;
  11959. const prefs = this.#prefs;
  11960. this.#prefs = Object.create(null);
  11961. return this._writeToStorage(this.#defaults).catch(reason => {
  11962. this.#prefs = prefs;
  11963. throw reason;
  11964. });
  11965. }
  11966. async set(name, value) {
  11967. await this.#initializedPromise;
  11968. const defaultValue = this.#defaults[name],
  11969. prefs = this.#prefs;
  11970. if (defaultValue === undefined) {
  11971. throw new Error(`Set preference: "${name}" is undefined.`);
  11972. } else if (value === undefined) {
  11973. throw new Error("Set preference: no value is specified.");
  11974. }
  11975. const valueType = typeof value,
  11976. defaultType = typeof defaultValue;
  11977. if (valueType !== defaultType) {
  11978. if (valueType === "number" && defaultType === "string") {
  11979. value = value.toString();
  11980. } else {
  11981. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  11982. }
  11983. } else {
  11984. if (valueType === "number" && !Number.isInteger(value)) {
  11985. throw new Error(`Set preference: "${value}" must be an integer.`);
  11986. }
  11987. }
  11988. this.#prefs[name] = value;
  11989. return this._writeToStorage(this.#prefs).catch(reason => {
  11990. this.#prefs = prefs;
  11991. throw reason;
  11992. });
  11993. }
  11994. async get(name) {
  11995. await this.#initializedPromise;
  11996. const defaultValue = this.#defaults[name];
  11997. if (defaultValue === undefined) {
  11998. throw new Error(`Get preference: "${name}" is undefined.`);
  11999. }
  12000. return this.#prefs[name] ?? defaultValue;
  12001. }
  12002. async getAll() {
  12003. await this.#initializedPromise;
  12004. const obj = Object.create(null);
  12005. for (const name in this.#defaults) {
  12006. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  12007. }
  12008. return obj;
  12009. }
  12010. }
  12011. exports.BasePreferences = BasePreferences;
  12012. /***/ }),
  12013. /* 44 */
  12014. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12015. Object.defineProperty(exports, "__esModule", ({
  12016. value: true
  12017. }));
  12018. exports.DownloadManager = void 0;
  12019. var _pdfjsLib = __webpack_require__(5);
  12020. ;
  12021. function download(blobUrl, filename) {
  12022. const a = document.createElement("a");
  12023. if (!a.click) {
  12024. throw new Error('DownloadManager: "a.click()" is not supported.');
  12025. }
  12026. a.href = blobUrl;
  12027. a.target = "_parent";
  12028. if ("download" in a) {
  12029. a.download = filename;
  12030. }
  12031. (document.body || document.documentElement).append(a);
  12032. a.click();
  12033. a.remove();
  12034. }
  12035. class DownloadManager {
  12036. constructor() {
  12037. this._openBlobUrls = new WeakMap();
  12038. }
  12039. downloadUrl(url, filename) {
  12040. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  12041. console.error(`downloadUrl - not a valid URL: ${url}`);
  12042. return;
  12043. }
  12044. download(url + "#pdfjs.action=download", filename);
  12045. }
  12046. downloadData(data, filename, contentType) {
  12047. const blobUrl = URL.createObjectURL(new Blob([data], {
  12048. type: contentType
  12049. }));
  12050. download(blobUrl, filename);
  12051. }
  12052. openOrDownloadData(element, data, filename) {
  12053. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  12054. const contentType = isPdfData ? "application/pdf" : "";
  12055. if (isPdfData) {
  12056. let blobUrl = this._openBlobUrls.get(element);
  12057. if (!blobUrl) {
  12058. blobUrl = URL.createObjectURL(new Blob([data], {
  12059. type: contentType
  12060. }));
  12061. this._openBlobUrls.set(element, blobUrl);
  12062. }
  12063. let viewerUrl;
  12064. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  12065. try {
  12066. window.open(viewerUrl);
  12067. return true;
  12068. } catch (ex) {
  12069. console.error(`openOrDownloadData: ${ex}`);
  12070. URL.revokeObjectURL(blobUrl);
  12071. this._openBlobUrls.delete(element);
  12072. }
  12073. }
  12074. this.downloadData(data, filename, contentType);
  12075. return false;
  12076. }
  12077. download(blob, url, filename) {
  12078. const blobUrl = URL.createObjectURL(blob);
  12079. download(blobUrl, filename);
  12080. }
  12081. }
  12082. exports.DownloadManager = DownloadManager;
  12083. /***/ }),
  12084. /* 45 */
  12085. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12086. Object.defineProperty(exports, "__esModule", ({
  12087. value: true
  12088. }));
  12089. exports.GenericL10n = void 0;
  12090. __webpack_require__(46);
  12091. var _l10n_utils = __webpack_require__(31);
  12092. const webL10n = document.webL10n;
  12093. class GenericL10n {
  12094. constructor(lang) {
  12095. this._lang = lang;
  12096. this._ready = new Promise((resolve, reject) => {
  12097. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  12098. resolve(webL10n);
  12099. });
  12100. });
  12101. }
  12102. async getLanguage() {
  12103. const l10n = await this._ready;
  12104. return l10n.getLanguage();
  12105. }
  12106. async getDirection() {
  12107. const l10n = await this._ready;
  12108. return l10n.getDirection();
  12109. }
  12110. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  12111. const l10n = await this._ready;
  12112. return l10n.get(key, args, fallback);
  12113. }
  12114. async translate(element) {
  12115. const l10n = await this._ready;
  12116. return l10n.translate(element);
  12117. }
  12118. }
  12119. exports.GenericL10n = GenericL10n;
  12120. /***/ }),
  12121. /* 46 */
  12122. /***/ (() => {
  12123. document.webL10n = function (window, document, undefined) {
  12124. var gL10nData = {};
  12125. var gTextData = '';
  12126. var gTextProp = 'textContent';
  12127. var gLanguage = '';
  12128. var gMacros = {};
  12129. var gReadyState = 'loading';
  12130. var gAsyncResourceLoading = true;
  12131. function getL10nResourceLinks() {
  12132. return document.querySelectorAll('link[type="application/l10n"]');
  12133. }
  12134. function getL10nDictionary() {
  12135. var script = document.querySelector('script[type="application/l10n"]');
  12136. return script ? JSON.parse(script.innerHTML) : null;
  12137. }
  12138. function getTranslatableChildren(element) {
  12139. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  12140. }
  12141. function getL10nAttributes(element) {
  12142. if (!element) return {};
  12143. var l10nId = element.getAttribute('data-l10n-id');
  12144. var l10nArgs = element.getAttribute('data-l10n-args');
  12145. var args = {};
  12146. if (l10nArgs) {
  12147. try {
  12148. args = JSON.parse(l10nArgs);
  12149. } catch (e) {
  12150. console.warn('could not parse arguments for #' + l10nId);
  12151. }
  12152. }
  12153. return {
  12154. id: l10nId,
  12155. args: args
  12156. };
  12157. }
  12158. function xhrLoadText(url, onSuccess, onFailure) {
  12159. onSuccess = onSuccess || function _onSuccess(data) {};
  12160. onFailure = onFailure || function _onFailure() {};
  12161. var xhr = new XMLHttpRequest();
  12162. xhr.open('GET', url, gAsyncResourceLoading);
  12163. if (xhr.overrideMimeType) {
  12164. xhr.overrideMimeType('text/plain; charset=utf-8');
  12165. }
  12166. xhr.onreadystatechange = function () {
  12167. if (xhr.readyState == 4) {
  12168. if (xhr.status == 200 || xhr.status === 0) {
  12169. onSuccess(xhr.responseText);
  12170. } else {
  12171. onFailure();
  12172. }
  12173. }
  12174. };
  12175. xhr.onerror = onFailure;
  12176. xhr.ontimeout = onFailure;
  12177. try {
  12178. xhr.send(null);
  12179. } catch (e) {
  12180. onFailure();
  12181. }
  12182. }
  12183. function parseResource(href, lang, successCallback, failureCallback) {
  12184. var baseURL = href.replace(/[^\/]*$/, '') || './';
  12185. function evalString(text) {
  12186. if (text.lastIndexOf('\\') < 0) return text;
  12187. 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, "'");
  12188. }
  12189. function parseProperties(text, parsedPropertiesCallback) {
  12190. var dictionary = {};
  12191. var reBlank = /^\s*|\s*$/;
  12192. var reComment = /^\s*#|^\s*$/;
  12193. var reSection = /^\s*\[(.*)\]\s*$/;
  12194. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  12195. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  12196. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  12197. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  12198. var currentLang = '*';
  12199. var genericLang = lang.split('-', 1)[0];
  12200. var skipLang = false;
  12201. var match = '';
  12202. function nextEntry() {
  12203. while (true) {
  12204. if (!entries.length) {
  12205. parsedRawLinesCallback();
  12206. return;
  12207. }
  12208. var line = entries.shift();
  12209. if (reComment.test(line)) continue;
  12210. if (extendedSyntax) {
  12211. match = reSection.exec(line);
  12212. if (match) {
  12213. currentLang = match[1].toLowerCase();
  12214. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  12215. continue;
  12216. } else if (skipLang) {
  12217. continue;
  12218. }
  12219. match = reImport.exec(line);
  12220. if (match) {
  12221. loadImport(baseURL + match[1], nextEntry);
  12222. return;
  12223. }
  12224. }
  12225. var tmp = line.match(reSplit);
  12226. if (tmp && tmp.length == 3) {
  12227. dictionary[tmp[1]] = evalString(tmp[2]);
  12228. }
  12229. }
  12230. }
  12231. nextEntry();
  12232. }
  12233. function loadImport(url, callback) {
  12234. xhrLoadText(url, function (content) {
  12235. parseRawLines(content, false, callback);
  12236. }, function () {
  12237. console.warn(url + ' not found.');
  12238. callback();
  12239. });
  12240. }
  12241. parseRawLines(text, true, function () {
  12242. parsedPropertiesCallback(dictionary);
  12243. });
  12244. }
  12245. xhrLoadText(href, function (response) {
  12246. gTextData += response;
  12247. parseProperties(response, function (data) {
  12248. for (var key in data) {
  12249. var id,
  12250. prop,
  12251. index = key.lastIndexOf('.');
  12252. if (index > 0) {
  12253. id = key.substring(0, index);
  12254. prop = key.substring(index + 1);
  12255. } else {
  12256. id = key;
  12257. prop = gTextProp;
  12258. }
  12259. if (!gL10nData[id]) {
  12260. gL10nData[id] = {};
  12261. }
  12262. gL10nData[id][prop] = data[key];
  12263. }
  12264. if (successCallback) {
  12265. successCallback();
  12266. }
  12267. });
  12268. }, failureCallback);
  12269. }
  12270. function loadLocale(lang, callback) {
  12271. if (lang) {
  12272. lang = lang.toLowerCase();
  12273. }
  12274. callback = callback || function _callback() {};
  12275. clear();
  12276. gLanguage = lang;
  12277. var langLinks = getL10nResourceLinks();
  12278. var langCount = langLinks.length;
  12279. if (langCount === 0) {
  12280. var dict = getL10nDictionary();
  12281. if (dict && dict.locales && dict.default_locale) {
  12282. console.log('using the embedded JSON directory, early way out');
  12283. gL10nData = dict.locales[lang];
  12284. if (!gL10nData) {
  12285. var defaultLocale = dict.default_locale.toLowerCase();
  12286. for (var anyCaseLang in dict.locales) {
  12287. anyCaseLang = anyCaseLang.toLowerCase();
  12288. if (anyCaseLang === lang) {
  12289. gL10nData = dict.locales[lang];
  12290. break;
  12291. } else if (anyCaseLang === defaultLocale) {
  12292. gL10nData = dict.locales[defaultLocale];
  12293. }
  12294. }
  12295. }
  12296. callback();
  12297. } else {
  12298. console.log('no resource to load, early way out');
  12299. }
  12300. gReadyState = 'complete';
  12301. return;
  12302. }
  12303. var onResourceLoaded = null;
  12304. var gResourceCount = 0;
  12305. onResourceLoaded = function () {
  12306. gResourceCount++;
  12307. if (gResourceCount >= langCount) {
  12308. callback();
  12309. gReadyState = 'complete';
  12310. }
  12311. };
  12312. function L10nResourceLink(link) {
  12313. var href = link.href;
  12314. this.load = function (lang, callback) {
  12315. parseResource(href, lang, callback, function () {
  12316. console.warn(href + ' not found.');
  12317. console.warn('"' + lang + '" resource not found');
  12318. gLanguage = '';
  12319. callback();
  12320. });
  12321. };
  12322. }
  12323. for (var i = 0; i < langCount; i++) {
  12324. var resource = new L10nResourceLink(langLinks[i]);
  12325. resource.load(lang, onResourceLoaded);
  12326. }
  12327. }
  12328. function clear() {
  12329. gL10nData = {};
  12330. gTextData = '';
  12331. gLanguage = '';
  12332. }
  12333. function getPluralRules(lang) {
  12334. var locales2rules = {
  12335. 'af': 3,
  12336. 'ak': 4,
  12337. 'am': 4,
  12338. 'ar': 1,
  12339. 'asa': 3,
  12340. 'az': 0,
  12341. 'be': 11,
  12342. 'bem': 3,
  12343. 'bez': 3,
  12344. 'bg': 3,
  12345. 'bh': 4,
  12346. 'bm': 0,
  12347. 'bn': 3,
  12348. 'bo': 0,
  12349. 'br': 20,
  12350. 'brx': 3,
  12351. 'bs': 11,
  12352. 'ca': 3,
  12353. 'cgg': 3,
  12354. 'chr': 3,
  12355. 'cs': 12,
  12356. 'cy': 17,
  12357. 'da': 3,
  12358. 'de': 3,
  12359. 'dv': 3,
  12360. 'dz': 0,
  12361. 'ee': 3,
  12362. 'el': 3,
  12363. 'en': 3,
  12364. 'eo': 3,
  12365. 'es': 3,
  12366. 'et': 3,
  12367. 'eu': 3,
  12368. 'fa': 0,
  12369. 'ff': 5,
  12370. 'fi': 3,
  12371. 'fil': 4,
  12372. 'fo': 3,
  12373. 'fr': 5,
  12374. 'fur': 3,
  12375. 'fy': 3,
  12376. 'ga': 8,
  12377. 'gd': 24,
  12378. 'gl': 3,
  12379. 'gsw': 3,
  12380. 'gu': 3,
  12381. 'guw': 4,
  12382. 'gv': 23,
  12383. 'ha': 3,
  12384. 'haw': 3,
  12385. 'he': 2,
  12386. 'hi': 4,
  12387. 'hr': 11,
  12388. 'hu': 0,
  12389. 'id': 0,
  12390. 'ig': 0,
  12391. 'ii': 0,
  12392. 'is': 3,
  12393. 'it': 3,
  12394. 'iu': 7,
  12395. 'ja': 0,
  12396. 'jmc': 3,
  12397. 'jv': 0,
  12398. 'ka': 0,
  12399. 'kab': 5,
  12400. 'kaj': 3,
  12401. 'kcg': 3,
  12402. 'kde': 0,
  12403. 'kea': 0,
  12404. 'kk': 3,
  12405. 'kl': 3,
  12406. 'km': 0,
  12407. 'kn': 0,
  12408. 'ko': 0,
  12409. 'ksb': 3,
  12410. 'ksh': 21,
  12411. 'ku': 3,
  12412. 'kw': 7,
  12413. 'lag': 18,
  12414. 'lb': 3,
  12415. 'lg': 3,
  12416. 'ln': 4,
  12417. 'lo': 0,
  12418. 'lt': 10,
  12419. 'lv': 6,
  12420. 'mas': 3,
  12421. 'mg': 4,
  12422. 'mk': 16,
  12423. 'ml': 3,
  12424. 'mn': 3,
  12425. 'mo': 9,
  12426. 'mr': 3,
  12427. 'ms': 0,
  12428. 'mt': 15,
  12429. 'my': 0,
  12430. 'nah': 3,
  12431. 'naq': 7,
  12432. 'nb': 3,
  12433. 'nd': 3,
  12434. 'ne': 3,
  12435. 'nl': 3,
  12436. 'nn': 3,
  12437. 'no': 3,
  12438. 'nr': 3,
  12439. 'nso': 4,
  12440. 'ny': 3,
  12441. 'nyn': 3,
  12442. 'om': 3,
  12443. 'or': 3,
  12444. 'pa': 3,
  12445. 'pap': 3,
  12446. 'pl': 13,
  12447. 'ps': 3,
  12448. 'pt': 3,
  12449. 'rm': 3,
  12450. 'ro': 9,
  12451. 'rof': 3,
  12452. 'ru': 11,
  12453. 'rwk': 3,
  12454. 'sah': 0,
  12455. 'saq': 3,
  12456. 'se': 7,
  12457. 'seh': 3,
  12458. 'ses': 0,
  12459. 'sg': 0,
  12460. 'sh': 11,
  12461. 'shi': 19,
  12462. 'sk': 12,
  12463. 'sl': 14,
  12464. 'sma': 7,
  12465. 'smi': 7,
  12466. 'smj': 7,
  12467. 'smn': 7,
  12468. 'sms': 7,
  12469. 'sn': 3,
  12470. 'so': 3,
  12471. 'sq': 3,
  12472. 'sr': 11,
  12473. 'ss': 3,
  12474. 'ssy': 3,
  12475. 'st': 3,
  12476. 'sv': 3,
  12477. 'sw': 3,
  12478. 'syr': 3,
  12479. 'ta': 3,
  12480. 'te': 3,
  12481. 'teo': 3,
  12482. 'th': 0,
  12483. 'ti': 4,
  12484. 'tig': 3,
  12485. 'tk': 3,
  12486. 'tl': 4,
  12487. 'tn': 3,
  12488. 'to': 0,
  12489. 'tr': 0,
  12490. 'ts': 3,
  12491. 'tzm': 22,
  12492. 'uk': 11,
  12493. 'ur': 3,
  12494. 've': 3,
  12495. 'vi': 0,
  12496. 'vun': 3,
  12497. 'wa': 4,
  12498. 'wae': 3,
  12499. 'wo': 0,
  12500. 'xh': 3,
  12501. 'xog': 3,
  12502. 'yo': 0,
  12503. 'zh': 0,
  12504. 'zu': 3
  12505. };
  12506. function isIn(n, list) {
  12507. return list.indexOf(n) !== -1;
  12508. }
  12509. function isBetween(n, start, end) {
  12510. return start <= n && n <= end;
  12511. }
  12512. var pluralRules = {
  12513. '0': function (n) {
  12514. return 'other';
  12515. },
  12516. '1': function (n) {
  12517. if (isBetween(n % 100, 3, 10)) return 'few';
  12518. if (n === 0) return 'zero';
  12519. if (isBetween(n % 100, 11, 99)) return 'many';
  12520. if (n == 2) return 'two';
  12521. if (n == 1) return 'one';
  12522. return 'other';
  12523. },
  12524. '2': function (n) {
  12525. if (n !== 0 && n % 10 === 0) return 'many';
  12526. if (n == 2) return 'two';
  12527. if (n == 1) return 'one';
  12528. return 'other';
  12529. },
  12530. '3': function (n) {
  12531. if (n == 1) return 'one';
  12532. return 'other';
  12533. },
  12534. '4': function (n) {
  12535. if (isBetween(n, 0, 1)) return 'one';
  12536. return 'other';
  12537. },
  12538. '5': function (n) {
  12539. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12540. return 'other';
  12541. },
  12542. '6': function (n) {
  12543. if (n === 0) return 'zero';
  12544. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12545. return 'other';
  12546. },
  12547. '7': function (n) {
  12548. if (n == 2) return 'two';
  12549. if (n == 1) return 'one';
  12550. return 'other';
  12551. },
  12552. '8': function (n) {
  12553. if (isBetween(n, 3, 6)) return 'few';
  12554. if (isBetween(n, 7, 10)) return 'many';
  12555. if (n == 2) return 'two';
  12556. if (n == 1) return 'one';
  12557. return 'other';
  12558. },
  12559. '9': function (n) {
  12560. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12561. if (n == 1) return 'one';
  12562. return 'other';
  12563. },
  12564. '10': function (n) {
  12565. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12566. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12567. return 'other';
  12568. },
  12569. '11': function (n) {
  12570. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12571. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12572. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12573. return 'other';
  12574. },
  12575. '12': function (n) {
  12576. if (isBetween(n, 2, 4)) return 'few';
  12577. if (n == 1) return 'one';
  12578. return 'other';
  12579. },
  12580. '13': function (n) {
  12581. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12582. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12583. if (n == 1) return 'one';
  12584. return 'other';
  12585. },
  12586. '14': function (n) {
  12587. if (isBetween(n % 100, 3, 4)) return 'few';
  12588. if (n % 100 == 2) return 'two';
  12589. if (n % 100 == 1) return 'one';
  12590. return 'other';
  12591. },
  12592. '15': function (n) {
  12593. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12594. if (isBetween(n % 100, 11, 19)) return 'many';
  12595. if (n == 1) return 'one';
  12596. return 'other';
  12597. },
  12598. '16': function (n) {
  12599. if (n % 10 == 1 && n != 11) return 'one';
  12600. return 'other';
  12601. },
  12602. '17': function (n) {
  12603. if (n == 3) return 'few';
  12604. if (n === 0) return 'zero';
  12605. if (n == 6) return 'many';
  12606. if (n == 2) return 'two';
  12607. if (n == 1) return 'one';
  12608. return 'other';
  12609. },
  12610. '18': function (n) {
  12611. if (n === 0) return 'zero';
  12612. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12613. return 'other';
  12614. },
  12615. '19': function (n) {
  12616. if (isBetween(n, 2, 10)) return 'few';
  12617. if (isBetween(n, 0, 1)) return 'one';
  12618. return 'other';
  12619. },
  12620. '20': function (n) {
  12621. 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';
  12622. if (n % 1000000 === 0 && n !== 0) return 'many';
  12623. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12624. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12625. return 'other';
  12626. },
  12627. '21': function (n) {
  12628. if (n === 0) return 'zero';
  12629. if (n == 1) return 'one';
  12630. return 'other';
  12631. },
  12632. '22': function (n) {
  12633. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  12634. return 'other';
  12635. },
  12636. '23': function (n) {
  12637. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  12638. return 'other';
  12639. },
  12640. '24': function (n) {
  12641. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  12642. if (isIn(n, [2, 12])) return 'two';
  12643. if (isIn(n, [1, 11])) return 'one';
  12644. return 'other';
  12645. }
  12646. };
  12647. var index = locales2rules[lang.replace(/-.*$/, '')];
  12648. if (!(index in pluralRules)) {
  12649. console.warn('plural form unknown for [' + lang + ']');
  12650. return function () {
  12651. return 'other';
  12652. };
  12653. }
  12654. return pluralRules[index];
  12655. }
  12656. gMacros.plural = function (str, param, key, prop) {
  12657. var n = parseFloat(param);
  12658. if (isNaN(n)) return str;
  12659. if (prop != gTextProp) return str;
  12660. if (!gMacros._pluralRules) {
  12661. gMacros._pluralRules = getPluralRules(gLanguage);
  12662. }
  12663. var index = '[' + gMacros._pluralRules(n) + ']';
  12664. if (n === 0 && key + '[zero]' in gL10nData) {
  12665. str = gL10nData[key + '[zero]'][prop];
  12666. } else if (n == 1 && key + '[one]' in gL10nData) {
  12667. str = gL10nData[key + '[one]'][prop];
  12668. } else if (n == 2 && key + '[two]' in gL10nData) {
  12669. str = gL10nData[key + '[two]'][prop];
  12670. } else if (key + index in gL10nData) {
  12671. str = gL10nData[key + index][prop];
  12672. } else if (key + '[other]' in gL10nData) {
  12673. str = gL10nData[key + '[other]'][prop];
  12674. }
  12675. return str;
  12676. };
  12677. function getL10nData(key, args, fallback) {
  12678. var data = gL10nData[key];
  12679. if (!data) {
  12680. console.warn('#' + key + ' is undefined.');
  12681. if (!fallback) {
  12682. return null;
  12683. }
  12684. data = fallback;
  12685. }
  12686. var rv = {};
  12687. for (var prop in data) {
  12688. var str = data[prop];
  12689. str = substIndexes(str, args, key, prop);
  12690. str = substArguments(str, args, key);
  12691. rv[prop] = str;
  12692. }
  12693. return rv;
  12694. }
  12695. function substIndexes(str, args, key, prop) {
  12696. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  12697. var reMatch = reIndex.exec(str);
  12698. if (!reMatch || !reMatch.length) return str;
  12699. var macroName = reMatch[1];
  12700. var paramName = reMatch[2];
  12701. var param;
  12702. if (args && paramName in args) {
  12703. param = args[paramName];
  12704. } else if (paramName in gL10nData) {
  12705. param = gL10nData[paramName];
  12706. }
  12707. if (macroName in gMacros) {
  12708. var macro = gMacros[macroName];
  12709. str = macro(str, param, key, prop);
  12710. }
  12711. return str;
  12712. }
  12713. function substArguments(str, args, key) {
  12714. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  12715. return str.replace(reArgs, function (matched_text, arg) {
  12716. if (args && arg in args) {
  12717. return args[arg];
  12718. }
  12719. if (arg in gL10nData) {
  12720. return gL10nData[arg];
  12721. }
  12722. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  12723. return matched_text;
  12724. });
  12725. }
  12726. function translateElement(element) {
  12727. var l10n = getL10nAttributes(element);
  12728. if (!l10n.id) return;
  12729. var data = getL10nData(l10n.id, l10n.args);
  12730. if (!data) {
  12731. console.warn('#' + l10n.id + ' is undefined.');
  12732. return;
  12733. }
  12734. if (data[gTextProp]) {
  12735. if (getChildElementCount(element) === 0) {
  12736. element[gTextProp] = data[gTextProp];
  12737. } else {
  12738. var children = element.childNodes;
  12739. var found = false;
  12740. for (var i = 0, l = children.length; i < l; i++) {
  12741. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  12742. if (found) {
  12743. children[i].nodeValue = '';
  12744. } else {
  12745. children[i].nodeValue = data[gTextProp];
  12746. found = true;
  12747. }
  12748. }
  12749. }
  12750. if (!found) {
  12751. var textNode = document.createTextNode(data[gTextProp]);
  12752. element.prepend(textNode);
  12753. }
  12754. }
  12755. delete data[gTextProp];
  12756. }
  12757. for (var k in data) {
  12758. element[k] = data[k];
  12759. }
  12760. }
  12761. function getChildElementCount(element) {
  12762. if (element.children) {
  12763. return element.children.length;
  12764. }
  12765. if (typeof element.childElementCount !== 'undefined') {
  12766. return element.childElementCount;
  12767. }
  12768. var count = 0;
  12769. for (var i = 0; i < element.childNodes.length; i++) {
  12770. count += element.nodeType === 1 ? 1 : 0;
  12771. }
  12772. return count;
  12773. }
  12774. function translateFragment(element) {
  12775. element = element || document.documentElement;
  12776. var children = getTranslatableChildren(element);
  12777. var elementCount = children.length;
  12778. for (var i = 0; i < elementCount; i++) {
  12779. translateElement(children[i]);
  12780. }
  12781. translateElement(element);
  12782. }
  12783. return {
  12784. get: function (key, args, fallbackString) {
  12785. var index = key.lastIndexOf('.');
  12786. var prop = gTextProp;
  12787. if (index > 0) {
  12788. prop = key.substring(index + 1);
  12789. key = key.substring(0, index);
  12790. }
  12791. var fallback;
  12792. if (fallbackString) {
  12793. fallback = {};
  12794. fallback[prop] = fallbackString;
  12795. }
  12796. var data = getL10nData(key, args, fallback);
  12797. if (data && prop in data) {
  12798. return data[prop];
  12799. }
  12800. return '{{' + key + '}}';
  12801. },
  12802. getData: function () {
  12803. return gL10nData;
  12804. },
  12805. getText: function () {
  12806. return gTextData;
  12807. },
  12808. getLanguage: function () {
  12809. return gLanguage;
  12810. },
  12811. setLanguage: function (lang, callback) {
  12812. loadLocale(lang, function () {
  12813. if (callback) callback();
  12814. });
  12815. },
  12816. getDirection: function () {
  12817. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  12818. var shortCode = gLanguage.split('-', 1)[0];
  12819. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  12820. },
  12821. translate: translateFragment,
  12822. getReadyState: function () {
  12823. return gReadyState;
  12824. },
  12825. ready: function (callback) {
  12826. if (!callback) {
  12827. return;
  12828. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  12829. window.setTimeout(function () {
  12830. callback();
  12831. });
  12832. } else if (document.addEventListener) {
  12833. document.addEventListener('localized', function once() {
  12834. document.removeEventListener('localized', once);
  12835. callback();
  12836. });
  12837. }
  12838. }
  12839. };
  12840. }(window, document);
  12841. /***/ }),
  12842. /* 47 */
  12843. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12844. Object.defineProperty(exports, "__esModule", ({
  12845. value: true
  12846. }));
  12847. exports.GenericScripting = void 0;
  12848. exports.docPropertiesLookup = docPropertiesLookup;
  12849. var _pdfjsLib = __webpack_require__(5);
  12850. async function docPropertiesLookup(pdfDocument) {
  12851. const url = "",
  12852. baseUrl = url.split("#")[0];
  12853. let {
  12854. info,
  12855. metadata,
  12856. contentDispositionFilename,
  12857. contentLength
  12858. } = await pdfDocument.getMetadata();
  12859. if (!contentLength) {
  12860. const {
  12861. length
  12862. } = await pdfDocument.getDownloadInfo();
  12863. contentLength = length;
  12864. }
  12865. return { ...info,
  12866. baseURL: baseUrl,
  12867. filesize: contentLength,
  12868. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  12869. metadata: metadata?.getRaw(),
  12870. authors: metadata?.get("dc:creator"),
  12871. numPages: pdfDocument.numPages,
  12872. URL: url
  12873. };
  12874. }
  12875. class GenericScripting {
  12876. constructor(sandboxBundleSrc) {
  12877. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  12878. return window.pdfjsSandbox.QuickJSSandbox();
  12879. });
  12880. }
  12881. async createSandbox(data) {
  12882. const sandbox = await this._ready;
  12883. sandbox.create(data);
  12884. }
  12885. async dispatchEventInSandbox(event) {
  12886. const sandbox = await this._ready;
  12887. setTimeout(() => sandbox.dispatchEvent(event), 0);
  12888. }
  12889. async destroySandbox() {
  12890. const sandbox = await this._ready;
  12891. sandbox.nukeSandbox();
  12892. }
  12893. }
  12894. exports.GenericScripting = GenericScripting;
  12895. /***/ }),
  12896. /* 48 */
  12897. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12898. Object.defineProperty(exports, "__esModule", ({
  12899. value: true
  12900. }));
  12901. exports.PDFPrintService = PDFPrintService;
  12902. var _pdfjsLib = __webpack_require__(5);
  12903. var _app = __webpack_require__(4);
  12904. var _print_utils = __webpack_require__(49);
  12905. let activeService = null;
  12906. let dialog = null;
  12907. let overlayManager = null;
  12908. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  12909. const scratchCanvas = activeService.scratchCanvas;
  12910. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  12911. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  12912. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  12913. const ctx = scratchCanvas.getContext("2d");
  12914. ctx.save();
  12915. ctx.fillStyle = "rgb(255, 255, 255)";
  12916. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  12917. ctx.restore();
  12918. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  12919. const renderContext = {
  12920. canvasContext: ctx,
  12921. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  12922. viewport: pdfPage.getViewport({
  12923. scale: 1,
  12924. rotation: size.rotation
  12925. }),
  12926. intent: "print",
  12927. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  12928. optionalContentConfigPromise,
  12929. printAnnotationStorage
  12930. };
  12931. return pdfPage.render(renderContext).promise;
  12932. });
  12933. }
  12934. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) {
  12935. this.pdfDocument = pdfDocument;
  12936. this.pagesOverview = pagesOverview;
  12937. this.printContainer = printContainer;
  12938. this._printResolution = printResolution || 150;
  12939. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  12940. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  12941. this.l10n = l10n;
  12942. this.currentPage = -1;
  12943. this.scratchCanvas = document.createElement("canvas");
  12944. }
  12945. PDFPrintService.prototype = {
  12946. layout() {
  12947. this.throwIfInactive();
  12948. const body = document.querySelector("body");
  12949. body.setAttribute("data-pdfjsprinting", true);
  12950. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  12951. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  12952. }, this);
  12953. if (!hasEqualPageSizes) {
  12954. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  12955. }
  12956. this.pageStyleSheet = document.createElement("style");
  12957. const pageSize = this.pagesOverview[0];
  12958. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  12959. body.append(this.pageStyleSheet);
  12960. },
  12961. destroy() {
  12962. if (activeService !== this) {
  12963. return;
  12964. }
  12965. this.printContainer.textContent = "";
  12966. const body = document.querySelector("body");
  12967. body.removeAttribute("data-pdfjsprinting");
  12968. if (this.pageStyleSheet) {
  12969. this.pageStyleSheet.remove();
  12970. this.pageStyleSheet = null;
  12971. }
  12972. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  12973. this.scratchCanvas = null;
  12974. activeService = null;
  12975. ensureOverlay().then(function () {
  12976. if (overlayManager.active === dialog) {
  12977. overlayManager.close(dialog);
  12978. }
  12979. });
  12980. },
  12981. renderPages() {
  12982. if (this.pdfDocument.isPureXfa) {
  12983. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  12984. return Promise.resolve();
  12985. }
  12986. const pageCount = this.pagesOverview.length;
  12987. const renderNextPage = (resolve, reject) => {
  12988. this.throwIfInactive();
  12989. if (++this.currentPage >= pageCount) {
  12990. renderProgress(pageCount, pageCount, this.l10n);
  12991. resolve();
  12992. return;
  12993. }
  12994. const index = this.currentPage;
  12995. renderProgress(index, pageCount, this.l10n);
  12996. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  12997. renderNextPage(resolve, reject);
  12998. }, reject);
  12999. };
  13000. return new Promise(renderNextPage);
  13001. },
  13002. useRenderedPage() {
  13003. this.throwIfInactive();
  13004. const img = document.createElement("img");
  13005. const scratchCanvas = this.scratchCanvas;
  13006. if ("toBlob" in scratchCanvas) {
  13007. scratchCanvas.toBlob(function (blob) {
  13008. img.src = URL.createObjectURL(blob);
  13009. });
  13010. } else {
  13011. img.src = scratchCanvas.toDataURL();
  13012. }
  13013. const wrapper = document.createElement("div");
  13014. wrapper.className = "printedPage";
  13015. wrapper.append(img);
  13016. this.printContainer.append(wrapper);
  13017. return new Promise(function (resolve, reject) {
  13018. img.onload = resolve;
  13019. img.onerror = reject;
  13020. });
  13021. },
  13022. performPrint() {
  13023. this.throwIfInactive();
  13024. return new Promise(resolve => {
  13025. setTimeout(() => {
  13026. if (!this.active) {
  13027. resolve();
  13028. return;
  13029. }
  13030. print.call(window);
  13031. setTimeout(resolve, 20);
  13032. }, 0);
  13033. });
  13034. },
  13035. get active() {
  13036. return this === activeService;
  13037. },
  13038. throwIfInactive() {
  13039. if (!this.active) {
  13040. throw new Error("This print request was cancelled or completed.");
  13041. }
  13042. }
  13043. };
  13044. const print = window.print;
  13045. window.print = function () {
  13046. if (activeService) {
  13047. console.warn("Ignored window.print() because of a pending print job.");
  13048. return;
  13049. }
  13050. ensureOverlay().then(function () {
  13051. if (activeService) {
  13052. overlayManager.open(dialog);
  13053. }
  13054. });
  13055. try {
  13056. dispatchEvent("beforeprint");
  13057. } finally {
  13058. if (!activeService) {
  13059. console.error("Expected print service to be initialized.");
  13060. ensureOverlay().then(function () {
  13061. if (overlayManager.active === dialog) {
  13062. overlayManager.close(dialog);
  13063. }
  13064. });
  13065. return;
  13066. }
  13067. const activeServiceOnEntry = activeService;
  13068. activeService.renderPages().then(function () {
  13069. return activeServiceOnEntry.performPrint();
  13070. }).catch(function () {}).then(function () {
  13071. if (activeServiceOnEntry.active) {
  13072. abort();
  13073. }
  13074. });
  13075. }
  13076. };
  13077. function dispatchEvent(eventType) {
  13078. const event = document.createEvent("CustomEvent");
  13079. event.initCustomEvent(eventType, false, false, "custom");
  13080. window.dispatchEvent(event);
  13081. }
  13082. function abort() {
  13083. if (activeService) {
  13084. activeService.destroy();
  13085. dispatchEvent("afterprint");
  13086. }
  13087. }
  13088. function renderProgress(index, total, l10n) {
  13089. dialog ||= document.getElementById("printServiceDialog");
  13090. const progress = Math.round(100 * index / total);
  13091. const progressBar = dialog.querySelector("progress");
  13092. const progressPerc = dialog.querySelector(".relative-progress");
  13093. progressBar.value = progress;
  13094. l10n.get("print_progress_percent", {
  13095. progress
  13096. }).then(msg => {
  13097. progressPerc.textContent = msg;
  13098. });
  13099. }
  13100. window.addEventListener("keydown", function (event) {
  13101. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  13102. window.print();
  13103. event.preventDefault();
  13104. if (event.stopImmediatePropagation) {
  13105. event.stopImmediatePropagation();
  13106. } else {
  13107. event.stopPropagation();
  13108. }
  13109. }
  13110. }, true);
  13111. if ("onbeforeprint" in window) {
  13112. const stopPropagationIfNeeded = function (event) {
  13113. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  13114. event.stopImmediatePropagation();
  13115. }
  13116. };
  13117. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  13118. window.addEventListener("afterprint", stopPropagationIfNeeded);
  13119. }
  13120. let overlayPromise;
  13121. function ensureOverlay() {
  13122. if (!overlayPromise) {
  13123. overlayManager = _app.PDFViewerApplication.overlayManager;
  13124. if (!overlayManager) {
  13125. throw new Error("The overlay manager has not yet been initialized.");
  13126. }
  13127. dialog ||= document.getElementById("printServiceDialog");
  13128. overlayPromise = overlayManager.register(dialog, true);
  13129. document.getElementById("printCancel").onclick = abort;
  13130. dialog.addEventListener("close", abort);
  13131. }
  13132. return overlayPromise;
  13133. }
  13134. _app.PDFPrintServiceFactory.instance = {
  13135. supportsPrinting: true,
  13136. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  13137. if (activeService) {
  13138. throw new Error("The print service is created and active.");
  13139. }
  13140. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  13141. return activeService;
  13142. }
  13143. };
  13144. /***/ }),
  13145. /* 49 */
  13146. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13147. Object.defineProperty(exports, "__esModule", ({
  13148. value: true
  13149. }));
  13150. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  13151. var _pdfjsLib = __webpack_require__(5);
  13152. var _pdf_link_service = __webpack_require__(3);
  13153. var _xfa_layer_builder = __webpack_require__(38);
  13154. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  13155. const xfaHtml = pdfDocument.allXfaHtml;
  13156. const linkService = new _pdf_link_service.SimpleLinkService();
  13157. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  13158. for (const xfaPage of xfaHtml.children) {
  13159. const page = document.createElement("div");
  13160. page.className = "xfaPrintedPage";
  13161. printContainer.append(page);
  13162. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  13163. pageDiv: page,
  13164. pdfPage: null,
  13165. annotationStorage: pdfDocument.annotationStorage,
  13166. linkService,
  13167. xfaHtml: xfaPage
  13168. });
  13169. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  13170. scale
  13171. });
  13172. builder.render(viewport, "print");
  13173. }
  13174. }
  13175. /***/ })
  13176. /******/ ]);
  13177. /************************************************************************/
  13178. /******/ // The module cache
  13179. /******/ var __webpack_module_cache__ = {};
  13180. /******/
  13181. /******/ // The require function
  13182. /******/ function __webpack_require__(moduleId) {
  13183. /******/ // Check if module is in cache
  13184. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  13185. /******/ if (cachedModule !== undefined) {
  13186. /******/ return cachedModule.exports;
  13187. /******/ }
  13188. /******/ // Create a new module (and put it into the cache)
  13189. /******/ var module = __webpack_module_cache__[moduleId] = {
  13190. /******/ // no module.id needed
  13191. /******/ // no module.loaded needed
  13192. /******/ exports: {}
  13193. /******/ };
  13194. /******/
  13195. /******/ // Execute the module function
  13196. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  13197. /******/
  13198. /******/ // Return the exports of the module
  13199. /******/ return module.exports;
  13200. /******/ }
  13201. /******/
  13202. /************************************************************************/
  13203. var __webpack_exports__ = {};
  13204. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  13205. (() => {
  13206. var exports = __webpack_exports__;
  13207. Object.defineProperty(exports, "__esModule", ({
  13208. value: true
  13209. }));
  13210. Object.defineProperty(exports, "PDFViewerApplication", ({
  13211. enumerable: true,
  13212. get: function () {
  13213. return _app.PDFViewerApplication;
  13214. }
  13215. }));
  13216. exports.PDFViewerApplicationConstants = void 0;
  13217. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  13218. enumerable: true,
  13219. get: function () {
  13220. return _app_options.AppOptions;
  13221. }
  13222. }));
  13223. var _ui_utils = __webpack_require__(1);
  13224. var _app_options = __webpack_require__(2);
  13225. var _pdf_link_service = __webpack_require__(3);
  13226. var _app = __webpack_require__(4);
  13227. const pdfjsVersion = '2.16.105';
  13228. const pdfjsBuild = '172ccdbe5';
  13229. const AppConstants = {
  13230. LinkTarget: _pdf_link_service.LinkTarget,
  13231. RenderingStates: _ui_utils.RenderingStates,
  13232. ScrollMode: _ui_utils.ScrollMode,
  13233. SpreadMode: _ui_utils.SpreadMode
  13234. };
  13235. exports.PDFViewerApplicationConstants = AppConstants;
  13236. window.PDFViewerApplication = _app.PDFViewerApplication;
  13237. window.PDFViewerApplicationConstants = AppConstants;
  13238. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  13239. ;
  13240. ;
  13241. {
  13242. __webpack_require__(42);
  13243. }
  13244. ;
  13245. {
  13246. __webpack_require__(48);
  13247. }
  13248. function getViewerConfiguration() {
  13249. let errorWrapper = null;
  13250. errorWrapper = {
  13251. container: document.getElementById("errorWrapper"),
  13252. errorMessage: document.getElementById("errorMessage"),
  13253. closeButton: document.getElementById("errorClose"),
  13254. errorMoreInfo: document.getElementById("errorMoreInfo"),
  13255. moreInfoButton: document.getElementById("errorShowMore"),
  13256. lessInfoButton: document.getElementById("errorShowLess")
  13257. };
  13258. return {
  13259. appContainer: document.body,
  13260. mainContainer: document.getElementById("viewerContainer"),
  13261. viewerContainer: document.getElementById("viewer"),
  13262. toolbar: {
  13263. container: document.getElementById("toolbarViewer"),
  13264. numPages: document.getElementById("numPages"),
  13265. pageNumber: document.getElementById("pageNumber"),
  13266. scaleSelect: document.getElementById("scaleSelect"),
  13267. customScaleOption: document.getElementById("customScaleOption"),
  13268. previous: document.getElementById("previous"),
  13269. next: document.getElementById("next"),
  13270. zoomIn: document.getElementById("zoomIn"),
  13271. zoomOut: document.getElementById("zoomOut"),
  13272. viewFind: document.getElementById("viewFind"),
  13273. openFile: document.getElementById("openFile"),
  13274. print: document.getElementById("print"),
  13275. editorFreeTextButton: document.getElementById("editorFreeText"),
  13276. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  13277. editorInkButton: document.getElementById("editorInk"),
  13278. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  13279. presentationModeButton: document.getElementById("presentationMode"),
  13280. download: document.getElementById("download"),
  13281. viewBookmark: document.getElementById("viewBookmark")
  13282. },
  13283. secondaryToolbar: {
  13284. toolbar: document.getElementById("secondaryToolbar"),
  13285. toggleButton: document.getElementById("secondaryToolbarToggle"),
  13286. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  13287. openFileButton: document.getElementById("secondaryOpenFile"),
  13288. printButton: document.getElementById("secondaryPrint"),
  13289. downloadButton: document.getElementById("secondaryDownload"),
  13290. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  13291. firstPageButton: document.getElementById("firstPage"),
  13292. lastPageButton: document.getElementById("lastPage"),
  13293. pageRotateCwButton: document.getElementById("pageRotateCw"),
  13294. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  13295. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  13296. cursorHandToolButton: document.getElementById("cursorHandTool"),
  13297. scrollPageButton: document.getElementById("scrollPage"),
  13298. scrollVerticalButton: document.getElementById("scrollVertical"),
  13299. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  13300. scrollWrappedButton: document.getElementById("scrollWrapped"),
  13301. spreadNoneButton: document.getElementById("spreadNone"),
  13302. spreadOddButton: document.getElementById("spreadOdd"),
  13303. spreadEvenButton: document.getElementById("spreadEven"),
  13304. documentPropertiesButton: document.getElementById("documentProperties")
  13305. },
  13306. sidebar: {
  13307. outerContainer: document.getElementById("outerContainer"),
  13308. sidebarContainer: document.getElementById("sidebarContainer"),
  13309. toggleButton: document.getElementById("sidebarToggle"),
  13310. thumbnailButton: document.getElementById("viewThumbnail"),
  13311. outlineButton: document.getElementById("viewOutline"),
  13312. attachmentsButton: document.getElementById("viewAttachments"),
  13313. layersButton: document.getElementById("viewLayers"),
  13314. thumbnailView: document.getElementById("thumbnailView"),
  13315. outlineView: document.getElementById("outlineView"),
  13316. attachmentsView: document.getElementById("attachmentsView"),
  13317. layersView: document.getElementById("layersView"),
  13318. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  13319. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  13320. },
  13321. sidebarResizer: {
  13322. outerContainer: document.getElementById("outerContainer"),
  13323. resizer: document.getElementById("sidebarResizer")
  13324. },
  13325. findBar: {
  13326. bar: document.getElementById("findbar"),
  13327. toggleButton: document.getElementById("viewFind"),
  13328. findField: document.getElementById("findInput"),
  13329. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  13330. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  13331. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  13332. entireWordCheckbox: document.getElementById("findEntireWord"),
  13333. findMsg: document.getElementById("findMsg"),
  13334. findResultsCount: document.getElementById("findResultsCount"),
  13335. findPreviousButton: document.getElementById("findPrevious"),
  13336. findNextButton: document.getElementById("findNext")
  13337. },
  13338. passwordOverlay: {
  13339. dialog: document.getElementById("passwordDialog"),
  13340. label: document.getElementById("passwordText"),
  13341. input: document.getElementById("password"),
  13342. submitButton: document.getElementById("passwordSubmit"),
  13343. cancelButton: document.getElementById("passwordCancel")
  13344. },
  13345. documentProperties: {
  13346. dialog: document.getElementById("documentPropertiesDialog"),
  13347. closeButton: document.getElementById("documentPropertiesClose"),
  13348. fields: {
  13349. fileName: document.getElementById("fileNameField"),
  13350. fileSize: document.getElementById("fileSizeField"),
  13351. title: document.getElementById("titleField"),
  13352. author: document.getElementById("authorField"),
  13353. subject: document.getElementById("subjectField"),
  13354. keywords: document.getElementById("keywordsField"),
  13355. creationDate: document.getElementById("creationDateField"),
  13356. modificationDate: document.getElementById("modificationDateField"),
  13357. creator: document.getElementById("creatorField"),
  13358. producer: document.getElementById("producerField"),
  13359. version: document.getElementById("versionField"),
  13360. pageCount: document.getElementById("pageCountField"),
  13361. pageSize: document.getElementById("pageSizeField"),
  13362. linearized: document.getElementById("linearizedField")
  13363. }
  13364. },
  13365. annotationEditorParams: {
  13366. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  13367. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  13368. editorInkColor: document.getElementById("editorInkColor"),
  13369. editorInkThickness: document.getElementById("editorInkThickness"),
  13370. editorInkOpacity: document.getElementById("editorInkOpacity")
  13371. },
  13372. errorWrapper,
  13373. printContainer: document.getElementById("printContainer"),
  13374. openFileInput: document.getElementById("fileInput"),
  13375. debuggerScriptPath: "./debugger.js"
  13376. };
  13377. }
  13378. function webViewerLoad() {
  13379. const config = getViewerConfiguration();
  13380. const event = document.createEvent("CustomEvent");
  13381. event.initCustomEvent("webviewerloaded", true, true, {
  13382. source: window
  13383. });
  13384. try {
  13385. parent.document.dispatchEvent(event);
  13386. } catch (ex) {
  13387. console.error(`webviewerloaded: ${ex}`);
  13388. document.dispatchEvent(event);
  13389. }
  13390. _app.PDFViewerApplication.run(config);
  13391. }
  13392. document.blockUnblockOnload?.(true);
  13393. if (document.readyState === "interactive" || document.readyState === "complete") {
  13394. webViewerLoad();
  13395. } else {
  13396. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  13397. }
  13398. })();
  13399. /******/ })()
  13400. ;
  13401. //# sourceMappingURL=viewer.js.map