viewer.js 497 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2023 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.GenericCom = void 0;
  32. var _app = __webpack_require__(2);
  33. var _preferences = __webpack_require__(41);
  34. var _download_manager = __webpack_require__(42);
  35. var _genericl10n = __webpack_require__(43);
  36. var _generic_scripting = __webpack_require__(45);
  37. ;
  38. const GenericCom = {};
  39. exports.GenericCom = GenericCom;
  40. class GenericPreferences extends _preferences.BasePreferences {
  41. async _writeToStorage(prefObj) {
  42. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  43. }
  44. async _readFromStorage(prefObj) {
  45. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  46. }
  47. }
  48. class GenericExternalServices extends _app.DefaultExternalServices {
  49. static createDownloadManager() {
  50. return new _download_manager.DownloadManager();
  51. }
  52. static createPreferences() {
  53. return new GenericPreferences();
  54. }
  55. static createL10n({
  56. locale = "en-US"
  57. }) {
  58. return new _genericl10n.GenericL10n(locale);
  59. }
  60. static createScripting({
  61. sandboxBundleSrc
  62. }) {
  63. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  64. }
  65. }
  66. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  67. /***/
  68. }),
  69. /* 2 */
  70. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  71. Object.defineProperty(exports, "__esModule", ({
  72. value: true
  73. }));
  74. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  75. var _ui_utils = __webpack_require__(3);
  76. var _pdfjsLib = __webpack_require__(4);
  77. var _app_options = __webpack_require__(5);
  78. var _event_utils = __webpack_require__(6);
  79. var _pdf_link_service = __webpack_require__(7);
  80. var _webAnnotation_editor_params = __webpack_require__(8);
  81. var _overlay_manager = __webpack_require__(9);
  82. var _password_prompt = __webpack_require__(10);
  83. var _webPdf_attachment_viewer = __webpack_require__(11);
  84. var _webPdf_cursor_tools = __webpack_require__(13);
  85. var _webPdf_document_properties = __webpack_require__(15);
  86. var _webPdf_find_bar = __webpack_require__(16);
  87. var _pdf_find_controller = __webpack_require__(17);
  88. var _pdf_history = __webpack_require__(19);
  89. var _webPdf_layer_viewer = __webpack_require__(20);
  90. var _webPdf_outline_viewer = __webpack_require__(21);
  91. var _webPdf_presentation_mode = __webpack_require__(22);
  92. var _pdf_rendering_queue = __webpack_require__(23);
  93. var _pdf_scripting_manager = __webpack_require__(24);
  94. var _webPdf_sidebar = __webpack_require__(25);
  95. var _webPdf_thumbnail_viewer = __webpack_require__(26);
  96. var _pdf_viewer = __webpack_require__(28);
  97. var _webSecondary_toolbar = __webpack_require__(38);
  98. var _webToolbar = __webpack_require__(39);
  99. var _view_history = __webpack_require__(40);
  100. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  101. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  102. const ViewOnLoad = {
  103. UNKNOWN: -1,
  104. PREVIOUS: 0,
  105. INITIAL: 1
  106. };
  107. const ViewerCssTheme = {
  108. AUTOMATIC: 0,
  109. LIGHT: 1,
  110. DARK: 2
  111. };
  112. class DefaultExternalServices {
  113. constructor() {
  114. throw new Error("Cannot initialize DefaultExternalServices.");
  115. }
  116. static updateFindControlState(data) { }
  117. static updateFindMatchesCount(data) { }
  118. static initPassiveLoading(callbacks) { }
  119. static reportTelemetry(data) { }
  120. static createDownloadManager() {
  121. throw new Error("Not implemented: createDownloadManager");
  122. }
  123. static createPreferences() {
  124. throw new Error("Not implemented: createPreferences");
  125. }
  126. static createL10n(options) {
  127. throw new Error("Not implemented: createL10n");
  128. }
  129. static createScripting(options) {
  130. throw new Error("Not implemented: createScripting");
  131. }
  132. static get supportsPinchToZoom() {
  133. return (0, _pdfjsLib.shadow)(this, "supportsPinchToZoom", true);
  134. }
  135. static get supportsIntegratedFind() {
  136. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  137. }
  138. static get supportsDocumentFonts() {
  139. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  140. }
  141. static get supportedMouseWheelZoomModifierKeys() {
  142. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  143. ctrlKey: true,
  144. metaKey: true
  145. });
  146. }
  147. static get isInAutomation() {
  148. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  149. }
  150. static updateEditorStates(data) {
  151. throw new Error("Not implemented: updateEditorStates");
  152. }
  153. static get canvasMaxAreaInBytes() {
  154. return (0, _pdfjsLib.shadow)(this, "canvasMaxAreaInBytes", -1);
  155. }
  156. static getNimbusExperimentData() {
  157. return (0, _pdfjsLib.shadow)(this, "getNimbusExperimentData", Promise.resolve(null));
  158. }
  159. }
  160. exports.DefaultExternalServices = DefaultExternalServices;
  161. const PDFViewerApplication = {
  162. initialBookmark: document.location.hash.substring(1),
  163. _initializedCapability: new _pdfjsLib.PromiseCapability(),
  164. appConfig: null,
  165. pdfDocument: null,
  166. pdfLoadingTask: null,
  167. printService: null,
  168. pdfViewer: null,
  169. pdfThumbnailViewer: null,
  170. pdfRenderingQueue: null,
  171. pdfPresentationMode: null,
  172. pdfDocumentProperties: null,
  173. pdfLinkService: null,
  174. pdfHistory: null,
  175. pdfSidebar: null,
  176. pdfOutlineViewer: null,
  177. pdfAttachmentViewer: null,
  178. pdfLayerViewer: null,
  179. pdfCursorTools: null,
  180. pdfScriptingManager: null,
  181. store: null,
  182. downloadManager: null,
  183. overlayManager: null,
  184. preferences: null,
  185. toolbar: null,
  186. secondaryToolbar: null,
  187. eventBus: null,
  188. l10n: null,
  189. annotationEditorParams: null,
  190. isInitialViewSet: false,
  191. downloadComplete: false,
  192. isViewerEmbedded: window.parent !== window,
  193. url: "",
  194. baseUrl: "",
  195. _downloadUrl: "",
  196. externalServices: DefaultExternalServices,
  197. _boundEvents: Object.create(null),
  198. documentInfo: null,
  199. metadata: null,
  200. _contentDispositionFilename: null,
  201. _contentLength: null,
  202. _saveInProgress: false,
  203. _wheelUnusedTicks: 0,
  204. _wheelUnusedFactor: 1,
  205. _touchUnusedTicks: 0,
  206. _touchUnusedFactor: 1,
  207. _PDFBug: null,
  208. _hasAnnotationEditors: false,
  209. _title: document.title,
  210. _printAnnotationStoragePromise: null,
  211. _touchInfo: null,
  212. _isCtrlKeyDown: false,
  213. _nimbusDataPromise: null,
  214. async initialize(appConfig) {
  215. this.preferences = this.externalServices.createPreferences();
  216. this.appConfig = appConfig;
  217. await this._initializeOptions();
  218. this._forceCssTheme();
  219. await this._initializeL10n();
  220. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  221. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  222. }
  223. await this._initializeViewerComponents();
  224. this.bindEvents();
  225. this.bindWindowEvents();
  226. const appContainer = appConfig.appContainer || document.documentElement;
  227. this.l10n.translate(appContainer).then(() => {
  228. this.eventBus.dispatch("localized", {
  229. source: this
  230. });
  231. });
  232. this._initializedCapability.resolve();
  233. },
  234. async _initializeOptions() {
  235. if (_app_options.AppOptions.get("disablePreferences")) {
  236. if (_app_options.AppOptions.get("pdfBugEnabled")) {
  237. await this._parseHashParams();
  238. }
  239. return;
  240. }
  241. if (_app_options.AppOptions._hasUserOptions()) {
  242. console.warn("_initializeOptions: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  243. }
  244. try {
  245. _app_options.AppOptions.setAll(await this.preferences.getAll());
  246. } catch (reason) {
  247. console.error(`_initializeOptions: "${reason.message}".`);
  248. }
  249. if (_app_options.AppOptions.get("pdfBugEnabled")) {
  250. await this._parseHashParams();
  251. }
  252. },
  253. async _parseHashParams() {
  254. const hash = document.location.hash.substring(1);
  255. if (!hash) {
  256. return;
  257. }
  258. const {
  259. mainContainer,
  260. viewerContainer
  261. } = this.appConfig,
  262. params = (0, _ui_utils.parseQueryString)(hash);
  263. if (params.get("disableworker") === "true") {
  264. try {
  265. await loadFakeWorker();
  266. } catch (ex) {
  267. console.error(`_parseHashParams: "${ex.message}".`);
  268. }
  269. }
  270. if (params.has("disablerange")) {
  271. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  272. }
  273. if (params.has("disablestream")) {
  274. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  275. }
  276. if (params.has("disableautofetch")) {
  277. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  278. }
  279. if (params.has("disablefontface")) {
  280. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  281. }
  282. if (params.has("disablehistory")) {
  283. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  284. }
  285. if (params.has("verbosity")) {
  286. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  287. }
  288. if (params.has("textlayer")) {
  289. switch (params.get("textlayer")) {
  290. case "off":
  291. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  292. break;
  293. case "visible":
  294. case "shadow":
  295. case "hover":
  296. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  297. try {
  298. await loadPDFBug(this);
  299. this._PDFBug.loadCSS();
  300. } catch (ex) {
  301. console.error(`_parseHashParams: "${ex.message}".`);
  302. }
  303. break;
  304. }
  305. }
  306. if (params.has("pdfbug")) {
  307. _app_options.AppOptions.set("pdfBug", true);
  308. _app_options.AppOptions.set("fontExtraProperties", true);
  309. const enabled = params.get("pdfbug").split(",");
  310. try {
  311. await loadPDFBug(this);
  312. this._PDFBug.init(mainContainer, enabled);
  313. } catch (ex) {
  314. console.error(`_parseHashParams: "${ex.message}".`);
  315. }
  316. }
  317. if (params.has("locale")) {
  318. _app_options.AppOptions.set("locale", params.get("locale"));
  319. }
  320. },
  321. async _initializeL10n() {
  322. this.l10n = this.externalServices.createL10n({
  323. locale: _app_options.AppOptions.get("locale")
  324. });
  325. const dir = await this.l10n.getDirection();
  326. document.getElementsByTagName("html")[0].dir = dir;
  327. },
  328. _forceCssTheme() {
  329. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  330. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  331. return;
  332. }
  333. try {
  334. const styleSheet = document.styleSheets[0];
  335. const cssRules = styleSheet?.cssRules || [];
  336. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  337. const rule = cssRules[i];
  338. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  339. if (cssTheme === ViewerCssTheme.LIGHT) {
  340. styleSheet.deleteRule(i);
  341. return;
  342. }
  343. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  344. if (darkRules?.[1]) {
  345. styleSheet.deleteRule(i);
  346. styleSheet.insertRule(darkRules[1], i);
  347. }
  348. return;
  349. }
  350. }
  351. } catch (reason) {
  352. console.error(`_forceCssTheme: "${reason?.message}".`);
  353. }
  354. },
  355. async _initializeViewerComponents() {
  356. const {
  357. appConfig,
  358. externalServices,
  359. l10n
  360. } = this;
  361. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  362. this.eventBus = eventBus;
  363. this.overlayManager = new _overlay_manager.OverlayManager();
  364. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  365. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  366. this.pdfRenderingQueue = pdfRenderingQueue;
  367. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  368. eventBus,
  369. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  370. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  371. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  372. });
  373. this.pdfLinkService = pdfLinkService;
  374. const downloadManager = externalServices.createDownloadManager();
  375. this.downloadManager = downloadManager;
  376. const findController = new _pdf_find_controller.PDFFindController({
  377. linkService: pdfLinkService,
  378. eventBus,
  379. updateMatchesCountOnProgress: true
  380. });
  381. this.findController = findController;
  382. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  383. eventBus,
  384. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  385. externalServices,
  386. docProperties: this._scriptingDocProperties.bind(this)
  387. });
  388. this.pdfScriptingManager = pdfScriptingManager;
  389. const container = appConfig.mainContainer,
  390. viewer = appConfig.viewerContainer;
  391. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  392. const isOffscreenCanvasSupported = _app_options.AppOptions.get("isOffscreenCanvasSupported") && _pdfjsLib.FeatureTest.isOffscreenCanvasSupported;
  393. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  394. background: _app_options.AppOptions.get("pageColorsBackground"),
  395. foreground: _app_options.AppOptions.get("pageColorsForeground")
  396. } : null;
  397. const pdfViewer = new _pdf_viewer.PDFViewer({
  398. container,
  399. viewer,
  400. eventBus,
  401. renderingQueue: pdfRenderingQueue,
  402. linkService: pdfLinkService,
  403. downloadManager,
  404. findController,
  405. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  406. l10n,
  407. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  408. annotationMode: _app_options.AppOptions.get("annotationMode"),
  409. annotationEditorMode,
  410. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  411. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  412. isOffscreenCanvasSupported,
  413. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  414. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  415. pageColors
  416. });
  417. this.pdfViewer = pdfViewer;
  418. pdfRenderingQueue.setViewer(pdfViewer);
  419. pdfLinkService.setViewer(pdfViewer);
  420. pdfScriptingManager.setViewer(pdfViewer);
  421. if (appConfig.sidebar?.thumbnailView) {
  422. this.pdfThumbnailViewer = new _webPdf_thumbnail_viewer.PDFThumbnailViewer({
  423. container: appConfig.sidebar.thumbnailView,
  424. eventBus,
  425. renderingQueue: pdfRenderingQueue,
  426. linkService: pdfLinkService,
  427. l10n,
  428. pageColors
  429. });
  430. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  431. }
  432. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  433. this.pdfHistory = new _pdf_history.PDFHistory({
  434. linkService: pdfLinkService,
  435. eventBus
  436. });
  437. pdfLinkService.setHistory(this.pdfHistory);
  438. }
  439. if (!this.supportsIntegratedFind && appConfig.findBar) {
  440. this.findBar = new _webPdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, l10n);
  441. }
  442. if (appConfig.annotationEditorParams) {
  443. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  444. if (_app_options.AppOptions.get("enableStampEditor") && isOffscreenCanvasSupported) {
  445. appConfig.toolbar?.editorStampButton?.classList.remove("hidden");
  446. }
  447. this.annotationEditorParams = new _webAnnotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  448. } else {
  449. for (const id of ["editorModeButtons", "editorModeSeparator"]) {
  450. document.getElementById(id)?.classList.add("hidden");
  451. }
  452. }
  453. }
  454. if (appConfig.documentProperties) {
  455. this.pdfDocumentProperties = new _webPdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, l10n, () => this._docFilename);
  456. }
  457. if (appConfig.secondaryToolbar?.cursorHandToolButton) {
  458. this.pdfCursorTools = new _webPdf_cursor_tools.PDFCursorTools({
  459. container,
  460. eventBus,
  461. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  462. });
  463. }
  464. if (appConfig.toolbar) {
  465. this.toolbar = new _webToolbar.Toolbar(appConfig.toolbar, eventBus, l10n);
  466. }
  467. if (appConfig.secondaryToolbar) {
  468. this.secondaryToolbar = new _webSecondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, externalServices);
  469. }
  470. if (this.supportsFullscreen && appConfig.secondaryToolbar?.presentationModeButton) {
  471. this.pdfPresentationMode = new _webPdf_presentation_mode.PDFPresentationMode({
  472. container,
  473. pdfViewer,
  474. eventBus
  475. });
  476. }
  477. if (appConfig.passwordOverlay) {
  478. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, l10n, this.isViewerEmbedded);
  479. }
  480. if (appConfig.sidebar?.outlineView) {
  481. this.pdfOutlineViewer = new _webPdf_outline_viewer.PDFOutlineViewer({
  482. container: appConfig.sidebar.outlineView,
  483. eventBus,
  484. linkService: pdfLinkService,
  485. downloadManager
  486. });
  487. }
  488. if (appConfig.sidebar?.attachmentsView) {
  489. this.pdfAttachmentViewer = new _webPdf_attachment_viewer.PDFAttachmentViewer({
  490. container: appConfig.sidebar.attachmentsView,
  491. eventBus,
  492. downloadManager
  493. });
  494. }
  495. if (appConfig.sidebar?.layersView) {
  496. this.pdfLayerViewer = new _webPdf_layer_viewer.PDFLayerViewer({
  497. container: appConfig.sidebar.layersView,
  498. eventBus,
  499. l10n
  500. });
  501. }
  502. if (appConfig.sidebar) {
  503. this.pdfSidebar = new _webPdf_sidebar.PDFSidebar({
  504. elements: appConfig.sidebar,
  505. eventBus,
  506. l10n
  507. });
  508. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  509. this.pdfSidebar.onUpdateThumbnails = () => {
  510. for (const pageView of pdfViewer.getCachedPageViews()) {
  511. if (pageView.renderingState === _ui_utils.RenderingStates.FINISHED) {
  512. this.pdfThumbnailViewer.getThumbnail(pageView.id - 1)?.setImage(pageView);
  513. }
  514. }
  515. this.pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  516. };
  517. }
  518. },
  519. async run(config) {
  520. await this.initialize(config);
  521. const {
  522. appConfig,
  523. eventBus
  524. } = this;
  525. let file;
  526. const queryString = document.location.search.substring(1);
  527. const params = (0, _ui_utils.parseQueryString)(queryString);
  528. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  529. validateFileURL(file);
  530. const fileInput = appConfig.openFileInput;
  531. fileInput.value = null;
  532. fileInput.addEventListener("change", function (evt) {
  533. const {
  534. files
  535. } = evt.target;
  536. if (!files || files.length === 0) {
  537. return;
  538. }
  539. eventBus.dispatch("fileinputchange", {
  540. source: this,
  541. fileInput: evt.target
  542. });
  543. });
  544. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  545. evt.preventDefault();
  546. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  547. });
  548. appConfig.mainContainer.addEventListener("drop", function (evt) {
  549. evt.preventDefault();
  550. const {
  551. files
  552. } = evt.dataTransfer;
  553. if (!files || files.length === 0) {
  554. return;
  555. }
  556. eventBus.dispatch("fileinputchange", {
  557. source: this,
  558. fileInput: evt.dataTransfer
  559. });
  560. });
  561. if (!this.supportsDocumentFonts) {
  562. _app_options.AppOptions.set("disableFontFace", true);
  563. this.l10n.get("web_fonts_disabled").then(msg => {
  564. console.warn(msg);
  565. });
  566. }
  567. if (!this.supportsPrinting) {
  568. appConfig.toolbar?.print?.classList.add("hidden");
  569. appConfig.secondaryToolbar?.printButton.classList.add("hidden");
  570. }
  571. if (!this.supportsFullscreen) {
  572. appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
  573. }
  574. if (this.supportsIntegratedFind) {
  575. appConfig.toolbar?.viewFind?.classList.add("hidden");
  576. }
  577. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  578. if (evt.target === this) {
  579. eventBus.dispatch("resize", {
  580. source: this
  581. });
  582. }
  583. }, true);
  584. if (file) {
  585. this.open({
  586. url: file
  587. });
  588. } else {
  589. this._hideViewBookmark();
  590. }
  591. },
  592. get initialized() {
  593. return this._initializedCapability.settled;
  594. },
  595. get initializedPromise() {
  596. return this._initializedCapability.promise;
  597. },
  598. zoomIn(steps, scaleFactor) {
  599. if (this.pdfViewer.isInPresentationMode) {
  600. return;
  601. }
  602. this.pdfViewer.increaseScale({
  603. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  604. steps,
  605. scaleFactor
  606. });
  607. },
  608. zoomOut(steps, scaleFactor) {
  609. if (this.pdfViewer.isInPresentationMode) {
  610. return;
  611. }
  612. this.pdfViewer.decreaseScale({
  613. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  614. steps,
  615. scaleFactor
  616. });
  617. },
  618. zoomReset() {
  619. if (this.pdfViewer.isInPresentationMode) {
  620. return;
  621. }
  622. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  623. },
  624. get pagesCount() {
  625. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  626. },
  627. get page() {
  628. return this.pdfViewer.currentPageNumber;
  629. },
  630. set page(val) {
  631. this.pdfViewer.currentPageNumber = val;
  632. },
  633. get supportsPrinting() {
  634. return PDFPrintServiceFactory.instance.supportsPrinting;
  635. },
  636. get supportsFullscreen() {
  637. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  638. },
  639. get supportsPinchToZoom() {
  640. return this.externalServices.supportsPinchToZoom;
  641. },
  642. get supportsIntegratedFind() {
  643. return this.externalServices.supportsIntegratedFind;
  644. },
  645. get supportsDocumentFonts() {
  646. return this.externalServices.supportsDocumentFonts;
  647. },
  648. get loadingBar() {
  649. const barElement = document.getElementById("loadingBar");
  650. const bar = barElement ? new _ui_utils.ProgressBar(barElement) : null;
  651. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  652. },
  653. get supportedMouseWheelZoomModifierKeys() {
  654. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  655. },
  656. initPassiveLoading(file) {
  657. throw new Error("Not implemented: initPassiveLoading");
  658. },
  659. setTitleUsingUrl(url = "", downloadUrl = null) {
  660. this.url = url;
  661. this.baseUrl = url.split("#")[0];
  662. if (downloadUrl) {
  663. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  664. }
  665. if ((0, _pdfjsLib.isDataScheme)(url)) {
  666. this._hideViewBookmark();
  667. }
  668. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  669. if (!title) {
  670. try {
  671. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  672. } catch {
  673. title = url;
  674. }
  675. }
  676. this.setTitle(title);
  677. },
  678. setTitle(title = this._title) {
  679. this._title = title;
  680. if (this.isViewerEmbedded) {
  681. return;
  682. }
  683. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  684. document.title = `${editorIndicator ? "* " : ""}${title}`;
  685. },
  686. get _docFilename() {
  687. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  688. },
  689. _hideViewBookmark() {
  690. const {
  691. secondaryToolbar
  692. } = this.appConfig;
  693. secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
  694. if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) {
  695. document.getElementById("viewBookmarkSeparator")?.classList.add("hidden");
  696. }
  697. },
  698. async close() {
  699. this._unblockDocumentLoadEvent();
  700. this._hideViewBookmark();
  701. if (!this.pdfLoadingTask) {
  702. return;
  703. }
  704. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  705. try {
  706. await this.save();
  707. } catch { }
  708. }
  709. const promises = [];
  710. promises.push(this.pdfLoadingTask.destroy());
  711. this.pdfLoadingTask = null;
  712. if (this.pdfDocument) {
  713. this.pdfDocument = null;
  714. this.pdfThumbnailViewer?.setDocument(null);
  715. this.pdfViewer.setDocument(null);
  716. this.pdfLinkService.setDocument(null);
  717. this.pdfDocumentProperties?.setDocument(null);
  718. }
  719. this.pdfLinkService.externalLinkEnabled = true;
  720. this.store = null;
  721. this.isInitialViewSet = false;
  722. this.downloadComplete = false;
  723. this.url = "";
  724. this.baseUrl = "";
  725. this._downloadUrl = "";
  726. this.documentInfo = null;
  727. this.metadata = null;
  728. this._contentDispositionFilename = null;
  729. this._contentLength = null;
  730. this._saveInProgress = false;
  731. this._hasAnnotationEditors = false;
  732. promises.push(this.pdfScriptingManager.destroyPromise, this.passwordPrompt.close());
  733. this.setTitle();
  734. this.pdfSidebar?.reset();
  735. this.pdfOutlineViewer?.reset();
  736. this.pdfAttachmentViewer?.reset();
  737. this.pdfLayerViewer?.reset();
  738. this.pdfHistory?.reset();
  739. this.findBar?.reset();
  740. this.toolbar?.reset();
  741. this.secondaryToolbar?.reset();
  742. this._PDFBug?.cleanup();
  743. await Promise.all(promises);
  744. },
  745. async open(args) {
  746. let deprecatedArgs = false;
  747. if (typeof args === "string") {
  748. args = {
  749. url: args
  750. };
  751. deprecatedArgs = true;
  752. } else if (args?.byteLength) {
  753. args = {
  754. data: args
  755. };
  756. deprecatedArgs = true;
  757. }
  758. if (deprecatedArgs) {
  759. console.error("The `PDFViewerApplication.open` signature was updated, please use an object instead.");
  760. }
  761. if (this.pdfLoadingTask) {
  762. await this.close();
  763. }
  764. const workerParams = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  765. Object.assign(_pdfjsLib.GlobalWorkerOptions, workerParams);
  766. if (args.url) {
  767. this.setTitleUsingUrl(args.originalUrl || args.url, args.url);
  768. }
  769. const apiParams = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  770. const params = {
  771. canvasMaxAreaInBytes: this.externalServices.canvasMaxAreaInBytes,
  772. ...apiParams,
  773. ...args
  774. };
  775. const loadingTask = (0, _pdfjsLib.getDocument)(params);
  776. this.pdfLoadingTask = loadingTask;
  777. loadingTask.onPassword = (updateCallback, reason) => {
  778. if (this.isViewerEmbedded) {
  779. this._unblockDocumentLoadEvent();
  780. }
  781. this.pdfLinkService.externalLinkEnabled = false;
  782. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  783. this.passwordPrompt.open();
  784. };
  785. loadingTask.onProgress = ({
  786. loaded,
  787. total
  788. }) => {
  789. this.progress(loaded / total);
  790. };
  791. return loadingTask.promise.then(pdfDocument => {
  792. this.load(pdfDocument);
  793. }, reason => {
  794. if (loadingTask !== this.pdfLoadingTask) {
  795. return undefined;
  796. }
  797. let key = "loading_error";
  798. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  799. key = "invalid_file_error";
  800. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  801. key = "missing_file_error";
  802. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  803. key = "unexpected_response_error";
  804. }
  805. return this.l10n.get(key).then(msg => {
  806. this._documentError(msg, {
  807. message: reason?.message
  808. });
  809. throw reason;
  810. });
  811. });
  812. },
  813. _ensureDownloadComplete() {
  814. if (this.pdfDocument && this.downloadComplete) {
  815. return;
  816. }
  817. throw new Error("PDF document not downloaded.");
  818. },
  819. async download(options = {}) {
  820. const url = this._downloadUrl,
  821. filename = this._docFilename;
  822. try {
  823. this._ensureDownloadComplete();
  824. const data = await this.pdfDocument.getData();
  825. const blob = new Blob([data], {
  826. type: "application/pdf"
  827. });
  828. await this.downloadManager.download(blob, url, filename, options);
  829. } catch {
  830. await this.downloadManager.downloadUrl(url, filename, options);
  831. }
  832. },
  833. async save(options = {}) {
  834. if (this._saveInProgress) {
  835. return;
  836. }
  837. this._saveInProgress = true;
  838. await this.pdfScriptingManager.dispatchWillSave();
  839. const url = this._downloadUrl,
  840. filename = this._docFilename;
  841. try {
  842. this._ensureDownloadComplete();
  843. const data = await this.pdfDocument.saveDocument();
  844. const blob = new Blob([data], {
  845. type: "application/pdf"
  846. });
  847. await this.downloadManager.download(blob, url, filename, options);
  848. } catch (reason) {
  849. console.error(`Error when saving the document: ${reason.message}`);
  850. await this.download(options);
  851. } finally {
  852. await this.pdfScriptingManager.dispatchDidSave();
  853. this._saveInProgress = false;
  854. }
  855. if (this._hasAnnotationEditors) {
  856. this.externalServices.reportTelemetry({
  857. type: "editing",
  858. data: {
  859. type: "save"
  860. }
  861. });
  862. }
  863. },
  864. downloadOrSave(options = {}) {
  865. if (this.pdfDocument?.annotationStorage.size > 0) {
  866. this.save(options);
  867. } else {
  868. this.download(options);
  869. }
  870. },
  871. openInExternalApp() {
  872. this.downloadOrSave({
  873. openInExternalApp: true
  874. });
  875. },
  876. _documentError(message, moreInfo = null) {
  877. this._unblockDocumentLoadEvent();
  878. this._otherError(message, moreInfo);
  879. this.eventBus.dispatch("documenterror", {
  880. source: this,
  881. message,
  882. reason: moreInfo?.message ?? null
  883. });
  884. },
  885. _otherError(message, moreInfo = null) {
  886. const moreInfoText = [`PDF.js v${_pdfjsLib.version || "?"} (build: ${_pdfjsLib.build || "?"})`];
  887. if (moreInfo) {
  888. moreInfoText.push(`Message: ${moreInfo.message}`);
  889. if (moreInfo.stack) {
  890. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  891. } else {
  892. if (moreInfo.filename) {
  893. moreInfoText.push(`File: ${moreInfo.filename}`);
  894. }
  895. if (moreInfo.lineNumber) {
  896. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  897. }
  898. }
  899. }
  900. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  901. },
  902. progress(level) {
  903. if (!this.loadingBar || this.downloadComplete) {
  904. return;
  905. }
  906. const percent = Math.round(level * 100);
  907. if (percent <= this.loadingBar.percent) {
  908. return;
  909. }
  910. this.loadingBar.percent = percent;
  911. if (this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch")) {
  912. this.loadingBar.setDisableAutoFetch();
  913. }
  914. },
  915. load(pdfDocument) {
  916. this.pdfDocument = pdfDocument;
  917. pdfDocument.getDownloadInfo().then(({
  918. length
  919. }) => {
  920. this._contentLength = length;
  921. this.downloadComplete = true;
  922. this.loadingBar?.hide();
  923. firstPagePromise.then(() => {
  924. this.eventBus.dispatch("documentloaded", {
  925. source: this
  926. });
  927. });
  928. });
  929. const pageLayoutPromise = pdfDocument.getPageLayout().catch(() => { });
  930. const pageModePromise = pdfDocument.getPageMode().catch(() => { });
  931. const openActionPromise = pdfDocument.getOpenAction().catch(() => { });
  932. this.toolbar?.setPagesCount(pdfDocument.numPages, false);
  933. this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
  934. this.pdfLinkService.setDocument(pdfDocument);
  935. this.pdfDocumentProperties?.setDocument(pdfDocument);
  936. const pdfViewer = this.pdfViewer;
  937. pdfViewer.setDocument(pdfDocument);
  938. const {
  939. firstPagePromise,
  940. onePageRendered,
  941. pagesPromise
  942. } = pdfViewer;
  943. this.pdfThumbnailViewer?.setDocument(pdfDocument);
  944. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  945. page: null,
  946. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  947. scrollLeft: "0",
  948. scrollTop: "0",
  949. rotation: null,
  950. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  951. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  952. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  953. }).catch(() => { });
  954. firstPagePromise.then(pdfPage => {
  955. this.loadingBar?.setWidth(this.appConfig.viewerContainer);
  956. this._initializeAnnotationStorageCallbacks(pdfDocument);
  957. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  958. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  959. this._initializePdfHistory({
  960. fingerprint: pdfDocument.fingerprints[0],
  961. viewOnLoad,
  962. initialDest: openAction?.dest
  963. });
  964. const initialBookmark = this.initialBookmark;
  965. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  966. let hash = zoom ? `zoom=${zoom}` : null;
  967. let rotation = null;
  968. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  969. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  970. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  971. if (stored?.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  972. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  973. rotation = parseInt(stored.rotation, 10);
  974. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  975. sidebarView = stored.sidebarView | 0;
  976. }
  977. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  978. scrollMode = stored.scrollMode | 0;
  979. }
  980. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  981. spreadMode = stored.spreadMode | 0;
  982. }
  983. }
  984. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  985. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  986. }
  987. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  988. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  989. spreadMode = modes.spreadMode;
  990. }
  991. this.setInitialView(hash, {
  992. rotation,
  993. sidebarView,
  994. scrollMode,
  995. spreadMode
  996. });
  997. this.eventBus.dispatch("documentinit", {
  998. source: this
  999. });
  1000. if (!this.isViewerEmbedded) {
  1001. pdfViewer.focus();
  1002. }
  1003. await Promise.race([pagesPromise, new Promise(resolve => {
  1004. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1005. })]);
  1006. if (!initialBookmark && !hash) {
  1007. return;
  1008. }
  1009. if (pdfViewer.hasEqualPageSizes) {
  1010. return;
  1011. }
  1012. this.initialBookmark = initialBookmark;
  1013. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1014. this.setInitialView(hash);
  1015. }).catch(() => {
  1016. this.setInitialView();
  1017. }).then(function () {
  1018. pdfViewer.update();
  1019. });
  1020. });
  1021. pagesPromise.then(() => {
  1022. this._unblockDocumentLoadEvent();
  1023. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1024. }, reason => {
  1025. this.l10n.get("loading_error").then(msg => {
  1026. this._documentError(msg, {
  1027. message: reason?.message
  1028. });
  1029. });
  1030. });
  1031. onePageRendered.then(data => {
  1032. this.externalServices.reportTelemetry({
  1033. type: "pageInfo",
  1034. timestamp: data.timestamp
  1035. });
  1036. if (this.pdfOutlineViewer) {
  1037. pdfDocument.getOutline().then(outline => {
  1038. if (pdfDocument !== this.pdfDocument) {
  1039. return;
  1040. }
  1041. this.pdfOutlineViewer.render({
  1042. outline,
  1043. pdfDocument
  1044. });
  1045. });
  1046. }
  1047. if (this.pdfAttachmentViewer) {
  1048. pdfDocument.getAttachments().then(attachments => {
  1049. if (pdfDocument !== this.pdfDocument) {
  1050. return;
  1051. }
  1052. this.pdfAttachmentViewer.render({
  1053. attachments
  1054. });
  1055. });
  1056. }
  1057. if (this.pdfLayerViewer) {
  1058. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1059. if (pdfDocument !== this.pdfDocument) {
  1060. return;
  1061. }
  1062. this.pdfLayerViewer.render({
  1063. optionalContentConfig,
  1064. pdfDocument
  1065. });
  1066. });
  1067. }
  1068. });
  1069. this._initializePageLabels(pdfDocument);
  1070. this._initializeMetadata(pdfDocument);
  1071. },
  1072. async _scriptingDocProperties(pdfDocument) {
  1073. if (!this.documentInfo) {
  1074. await new Promise(resolve => {
  1075. this.eventBus._on("metadataloaded", resolve, {
  1076. once: true
  1077. });
  1078. });
  1079. if (pdfDocument !== this.pdfDocument) {
  1080. return null;
  1081. }
  1082. }
  1083. if (!this._contentLength) {
  1084. await new Promise(resolve => {
  1085. this.eventBus._on("documentloaded", resolve, {
  1086. once: true
  1087. });
  1088. });
  1089. if (pdfDocument !== this.pdfDocument) {
  1090. return null;
  1091. }
  1092. }
  1093. return {
  1094. ...this.documentInfo,
  1095. baseURL: this.baseUrl,
  1096. filesize: this._contentLength,
  1097. filename: this._docFilename,
  1098. metadata: this.metadata?.getRaw(),
  1099. authors: this.metadata?.get("dc:creator"),
  1100. numPages: this.pagesCount,
  1101. URL: this.url
  1102. };
  1103. },
  1104. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1105. const [openAction, jsActions] = await Promise.all([openActionPromise, this.pdfViewer.enableScripting ? null : pdfDocument.getJSActions()]);
  1106. if (pdfDocument !== this.pdfDocument) {
  1107. return;
  1108. }
  1109. let triggerAutoPrint = openAction?.action === "Print";
  1110. if (jsActions) {
  1111. console.warn("Warning: JavaScript support is not enabled");
  1112. for (const name in jsActions) {
  1113. if (triggerAutoPrint) {
  1114. break;
  1115. }
  1116. switch (name) {
  1117. case "WillClose":
  1118. case "WillSave":
  1119. case "DidSave":
  1120. case "WillPrint":
  1121. case "DidPrint":
  1122. continue;
  1123. }
  1124. triggerAutoPrint = jsActions[name].some(js => _ui_utils.AutoPrintRegExp.test(js));
  1125. }
  1126. }
  1127. if (triggerAutoPrint) {
  1128. this.triggerPrinting();
  1129. }
  1130. },
  1131. async _initializeMetadata(pdfDocument) {
  1132. const {
  1133. info,
  1134. metadata,
  1135. contentDispositionFilename,
  1136. contentLength
  1137. } = await pdfDocument.getMetadata();
  1138. if (pdfDocument !== this.pdfDocument) {
  1139. return;
  1140. }
  1141. this.documentInfo = info;
  1142. this.metadata = metadata;
  1143. this._contentDispositionFilename ??= contentDispositionFilename;
  1144. this._contentLength ??= contentLength;
  1145. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`);
  1146. let pdfTitle = info.Title;
  1147. const metadataTitle = metadata?.get("dc:title");
  1148. if (metadataTitle) {
  1149. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1150. pdfTitle = metadataTitle;
  1151. }
  1152. }
  1153. if (pdfTitle) {
  1154. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  1155. } else if (this._contentDispositionFilename) {
  1156. this.setTitle(this._contentDispositionFilename);
  1157. }
  1158. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1159. if (pdfDocument.loadingParams.enableXfa) {
  1160. console.warn("Warning: XFA Foreground documents are not supported");
  1161. } else {
  1162. console.warn("Warning: XFA support is not enabled");
  1163. }
  1164. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  1165. console.warn("Warning: Interactive form support is not enabled");
  1166. }
  1167. if (info.IsSignaturesPresent) {
  1168. console.warn("Warning: Digital signatures validation is not supported");
  1169. }
  1170. this.eventBus.dispatch("metadataloaded", {
  1171. source: this
  1172. });
  1173. },
  1174. async _initializePageLabels(pdfDocument) {
  1175. const labels = await pdfDocument.getPageLabels();
  1176. if (pdfDocument !== this.pdfDocument) {
  1177. return;
  1178. }
  1179. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1180. return;
  1181. }
  1182. const numLabels = labels.length;
  1183. let standardLabels = 0,
  1184. emptyLabels = 0;
  1185. for (let i = 0; i < numLabels; i++) {
  1186. const label = labels[i];
  1187. if (label === (i + 1).toString()) {
  1188. standardLabels++;
  1189. } else if (label === "") {
  1190. emptyLabels++;
  1191. } else {
  1192. break;
  1193. }
  1194. }
  1195. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  1196. return;
  1197. }
  1198. const {
  1199. pdfViewer,
  1200. pdfThumbnailViewer,
  1201. toolbar
  1202. } = this;
  1203. pdfViewer.setPageLabels(labels);
  1204. pdfThumbnailViewer?.setPageLabels(labels);
  1205. toolbar?.setPagesCount(numLabels, true);
  1206. toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1207. },
  1208. _initializePdfHistory({
  1209. fingerprint,
  1210. viewOnLoad,
  1211. initialDest = null
  1212. }) {
  1213. if (!this.pdfHistory) {
  1214. return;
  1215. }
  1216. this.pdfHistory.initialize({
  1217. fingerprint,
  1218. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1219. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1220. });
  1221. if (this.pdfHistory.initialBookmark) {
  1222. this.initialBookmark = this.pdfHistory.initialBookmark;
  1223. this.initialRotation = this.pdfHistory.initialRotation;
  1224. }
  1225. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1226. this.initialBookmark = JSON.stringify(initialDest);
  1227. this.pdfHistory.push({
  1228. explicitDest: initialDest,
  1229. pageNumber: null
  1230. });
  1231. }
  1232. },
  1233. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1234. if (pdfDocument !== this.pdfDocument) {
  1235. return;
  1236. }
  1237. const {
  1238. annotationStorage
  1239. } = pdfDocument;
  1240. annotationStorage.onSetModified = () => {
  1241. window.addEventListener("beforeunload", beforeUnload);
  1242. this._annotationStorageModified = true;
  1243. };
  1244. annotationStorage.onResetModified = () => {
  1245. window.removeEventListener("beforeunload", beforeUnload);
  1246. delete this._annotationStorageModified;
  1247. };
  1248. annotationStorage.onAnnotationEditor = typeStr => {
  1249. this._hasAnnotationEditors = !!typeStr;
  1250. this.setTitle();
  1251. if (typeStr) {
  1252. this.externalServices.reportTelemetry({
  1253. type: "editing",
  1254. data: {
  1255. type: typeStr
  1256. }
  1257. });
  1258. }
  1259. };
  1260. },
  1261. setInitialView(storedHash, {
  1262. rotation,
  1263. sidebarView,
  1264. scrollMode,
  1265. spreadMode
  1266. } = {}) {
  1267. const setRotation = angle => {
  1268. if ((0, _ui_utils.isValidRotation)(angle)) {
  1269. this.pdfViewer.pagesRotation = angle;
  1270. }
  1271. };
  1272. const setViewerModes = (scroll, spread) => {
  1273. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1274. this.pdfViewer.scrollMode = scroll;
  1275. }
  1276. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1277. this.pdfViewer.spreadMode = spread;
  1278. }
  1279. };
  1280. this.isInitialViewSet = true;
  1281. this.pdfSidebar?.setInitialView(sidebarView);
  1282. setViewerModes(scrollMode, spreadMode);
  1283. if (this.initialBookmark) {
  1284. setRotation(this.initialRotation);
  1285. delete this.initialRotation;
  1286. this.pdfLinkService.setHash(this.initialBookmark);
  1287. this.initialBookmark = null;
  1288. } else if (storedHash) {
  1289. setRotation(rotation);
  1290. this.pdfLinkService.setHash(storedHash);
  1291. }
  1292. this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1293. this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
  1294. if (!this.pdfViewer.currentScaleValue) {
  1295. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1296. }
  1297. },
  1298. _cleanup() {
  1299. if (!this.pdfDocument) {
  1300. return;
  1301. }
  1302. this.pdfViewer.cleanup();
  1303. this.pdfThumbnailViewer?.cleanup();
  1304. this.pdfDocument.cleanup();
  1305. },
  1306. forceRendering() {
  1307. this.pdfRenderingQueue.printing = !!this.printService;
  1308. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS;
  1309. this.pdfRenderingQueue.renderHighestPriority();
  1310. },
  1311. beforePrint() {
  1312. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => { }).then(() => {
  1313. return this.pdfDocument?.annotationStorage.print;
  1314. });
  1315. if (this.printService) {
  1316. return;
  1317. }
  1318. if (!this.supportsPrinting) {
  1319. this.l10n.get("printing_not_supported").then(msg => {
  1320. this._otherError(msg);
  1321. });
  1322. return;
  1323. }
  1324. if (!this.pdfViewer.pageViewsReady) {
  1325. this.l10n.get("printing_not_ready").then(msg => {
  1326. window.alert(msg);
  1327. });
  1328. return;
  1329. }
  1330. const pagesOverview = this.pdfViewer.getPagesOverview();
  1331. const printContainer = this.appConfig.printContainer;
  1332. const printResolution = _app_options.AppOptions.get("printResolution");
  1333. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1334. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  1335. this.printService = printService;
  1336. this.forceRendering();
  1337. this.setTitle();
  1338. printService.layout();
  1339. if (this._hasAnnotationEditors) {
  1340. this.externalServices.reportTelemetry({
  1341. type: "editing",
  1342. data: {
  1343. type: "print"
  1344. }
  1345. });
  1346. }
  1347. },
  1348. afterPrint() {
  1349. if (this._printAnnotationStoragePromise) {
  1350. this._printAnnotationStoragePromise.then(() => {
  1351. this.pdfScriptingManager.dispatchDidPrint();
  1352. });
  1353. this._printAnnotationStoragePromise = null;
  1354. }
  1355. if (this.printService) {
  1356. this.printService.destroy();
  1357. this.printService = null;
  1358. this.pdfDocument?.annotationStorage.resetModified();
  1359. }
  1360. this.forceRendering();
  1361. this.setTitle();
  1362. },
  1363. rotatePages(delta) {
  1364. this.pdfViewer.pagesRotation += delta;
  1365. },
  1366. requestPresentationMode() {
  1367. this.pdfPresentationMode?.request();
  1368. },
  1369. triggerPrinting() {
  1370. if (!this.supportsPrinting) {
  1371. return;
  1372. }
  1373. window.print();
  1374. },
  1375. bindEvents() {
  1376. const {
  1377. eventBus,
  1378. _boundEvents
  1379. } = this;
  1380. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1381. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1382. eventBus._on("resize", webViewerResize);
  1383. eventBus._on("hashchange", webViewerHashchange);
  1384. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1385. eventBus._on("afterprint", _boundEvents.afterPrint);
  1386. eventBus._on("pagerender", webViewerPageRender);
  1387. eventBus._on("pagerendered", webViewerPageRendered);
  1388. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1389. eventBus._on("pagechanging", webViewerPageChanging);
  1390. eventBus._on("scalechanging", webViewerScaleChanging);
  1391. eventBus._on("rotationchanging", webViewerRotationChanging);
  1392. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1393. eventBus._on("pagemode", webViewerPageMode);
  1394. eventBus._on("namedaction", webViewerNamedAction);
  1395. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1396. eventBus._on("presentationmode", webViewerPresentationMode);
  1397. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  1398. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  1399. eventBus._on("print", webViewerPrint);
  1400. eventBus._on("download", webViewerDownload);
  1401. eventBus._on("openinexternalapp", webViewerOpenInExternalApp);
  1402. eventBus._on("firstpage", webViewerFirstPage);
  1403. eventBus._on("lastpage", webViewerLastPage);
  1404. eventBus._on("nextpage", webViewerNextPage);
  1405. eventBus._on("previouspage", webViewerPreviousPage);
  1406. eventBus._on("zoomin", webViewerZoomIn);
  1407. eventBus._on("zoomout", webViewerZoomOut);
  1408. eventBus._on("zoomreset", webViewerZoomReset);
  1409. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1410. eventBus._on("scalechanged", webViewerScaleChanged);
  1411. eventBus._on("rotatecw", webViewerRotateCw);
  1412. eventBus._on("rotateccw", webViewerRotateCcw);
  1413. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1414. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1415. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1416. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1417. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1418. eventBus._on("documentproperties", webViewerDocumentProperties);
  1419. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1420. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1421. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1422. if (_app_options.AppOptions.get("pdfBug")) {
  1423. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1424. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1425. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1426. }
  1427. eventBus._on("fileinputchange", webViewerFileInputChange);
  1428. eventBus._on("openfile", webViewerOpenFile);
  1429. },
  1430. bindWindowEvents() {
  1431. const {
  1432. eventBus,
  1433. _boundEvents
  1434. } = this;
  1435. function addWindowResolutionChange(evt = null) {
  1436. if (evt) {
  1437. webViewerResolutionChange(evt);
  1438. }
  1439. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  1440. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  1441. once: true
  1442. });
  1443. _boundEvents.removeWindowResolutionChange ||= function () {
  1444. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  1445. _boundEvents.removeWindowResolutionChange = null;
  1446. };
  1447. }
  1448. addWindowResolutionChange();
  1449. _boundEvents.windowResize = () => {
  1450. eventBus.dispatch("resize", {
  1451. source: window
  1452. });
  1453. };
  1454. _boundEvents.windowHashChange = () => {
  1455. eventBus.dispatch("hashchange", {
  1456. source: window,
  1457. hash: document.location.hash.substring(1)
  1458. });
  1459. };
  1460. _boundEvents.windowBeforePrint = () => {
  1461. eventBus.dispatch("beforeprint", {
  1462. source: window
  1463. });
  1464. };
  1465. _boundEvents.windowAfterPrint = () => {
  1466. eventBus.dispatch("afterprint", {
  1467. source: window
  1468. });
  1469. };
  1470. _boundEvents.windowUpdateFromSandbox = event => {
  1471. eventBus.dispatch("updatefromsandbox", {
  1472. source: window,
  1473. detail: event.detail
  1474. });
  1475. };
  1476. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1477. window.addEventListener("wheel", webViewerWheel, {
  1478. passive: false
  1479. });
  1480. window.addEventListener("touchstart", webViewerTouchStart, {
  1481. passive: false
  1482. });
  1483. window.addEventListener("touchmove", webViewerTouchMove, {
  1484. passive: false
  1485. });
  1486. window.addEventListener("touchend", webViewerTouchEnd, {
  1487. passive: false
  1488. });
  1489. window.addEventListener("click", webViewerClick);
  1490. window.addEventListener("keydown", webViewerKeyDown);
  1491. window.addEventListener("keyup", webViewerKeyUp);
  1492. window.addEventListener("resize", _boundEvents.windowResize);
  1493. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1494. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1495. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1496. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1497. },
  1498. unbindEvents() {
  1499. const {
  1500. eventBus,
  1501. _boundEvents
  1502. } = this;
  1503. eventBus._off("resize", webViewerResize);
  1504. eventBus._off("hashchange", webViewerHashchange);
  1505. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1506. eventBus._off("afterprint", _boundEvents.afterPrint);
  1507. eventBus._off("pagerender", webViewerPageRender);
  1508. eventBus._off("pagerendered", webViewerPageRendered);
  1509. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1510. eventBus._off("pagechanging", webViewerPageChanging);
  1511. eventBus._off("scalechanging", webViewerScaleChanging);
  1512. eventBus._off("rotationchanging", webViewerRotationChanging);
  1513. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1514. eventBus._off("pagemode", webViewerPageMode);
  1515. eventBus._off("namedaction", webViewerNamedAction);
  1516. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1517. eventBus._off("presentationmode", webViewerPresentationMode);
  1518. eventBus._off("print", webViewerPrint);
  1519. eventBus._off("download", webViewerDownload);
  1520. eventBus._off("openinexternalapp", webViewerOpenInExternalApp);
  1521. eventBus._off("firstpage", webViewerFirstPage);
  1522. eventBus._off("lastpage", webViewerLastPage);
  1523. eventBus._off("nextpage", webViewerNextPage);
  1524. eventBus._off("previouspage", webViewerPreviousPage);
  1525. eventBus._off("zoomin", webViewerZoomIn);
  1526. eventBus._off("zoomout", webViewerZoomOut);
  1527. eventBus._off("zoomreset", webViewerZoomReset);
  1528. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1529. eventBus._off("scalechanged", webViewerScaleChanged);
  1530. eventBus._off("rotatecw", webViewerRotateCw);
  1531. eventBus._off("rotateccw", webViewerRotateCcw);
  1532. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1533. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1534. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1535. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1536. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1537. eventBus._off("documentproperties", webViewerDocumentProperties);
  1538. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1539. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1540. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1541. if (_boundEvents.reportPageStatsPDFBug) {
  1542. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1543. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1544. _boundEvents.reportPageStatsPDFBug = null;
  1545. }
  1546. eventBus._off("fileinputchange", webViewerFileInputChange);
  1547. eventBus._off("openfile", webViewerOpenFile);
  1548. _boundEvents.beforePrint = null;
  1549. _boundEvents.afterPrint = null;
  1550. },
  1551. unbindWindowEvents() {
  1552. const {
  1553. _boundEvents
  1554. } = this;
  1555. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1556. window.removeEventListener("wheel", webViewerWheel, {
  1557. passive: false
  1558. });
  1559. window.removeEventListener("touchstart", webViewerTouchStart, {
  1560. passive: false
  1561. });
  1562. window.removeEventListener("touchmove", webViewerTouchMove, {
  1563. passive: false
  1564. });
  1565. window.removeEventListener("touchend", webViewerTouchEnd, {
  1566. passive: false
  1567. });
  1568. window.removeEventListener("click", webViewerClick);
  1569. window.removeEventListener("keydown", webViewerKeyDown);
  1570. window.removeEventListener("keyup", webViewerKeyUp);
  1571. window.removeEventListener("resize", _boundEvents.windowResize);
  1572. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1573. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1574. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1575. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1576. _boundEvents.removeWindowResolutionChange?.();
  1577. _boundEvents.windowResize = null;
  1578. _boundEvents.windowHashChange = null;
  1579. _boundEvents.windowBeforePrint = null;
  1580. _boundEvents.windowAfterPrint = null;
  1581. _boundEvents.windowUpdateFromSandbox = null;
  1582. },
  1583. _accumulateTicks(ticks, prop) {
  1584. if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) {
  1585. this[prop] = 0;
  1586. }
  1587. this[prop] += ticks;
  1588. const wholeTicks = Math.trunc(this[prop]);
  1589. this[prop] -= wholeTicks;
  1590. return wholeTicks;
  1591. },
  1592. _accumulateFactor(previousScale, factor, prop) {
  1593. if (factor === 1) {
  1594. return 1;
  1595. }
  1596. if (this[prop] > 1 && factor < 1 || this[prop] < 1 && factor > 1) {
  1597. this[prop] = 1;
  1598. }
  1599. const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale);
  1600. this[prop] = factor / newFactor;
  1601. return newFactor;
  1602. },
  1603. _centerAtPos(previousScale, x, y) {
  1604. const {
  1605. pdfViewer
  1606. } = this;
  1607. const scaleDiff = pdfViewer.currentScale / previousScale - 1;
  1608. if (scaleDiff !== 0) {
  1609. const [top, left] = pdfViewer.containerTopLeft;
  1610. pdfViewer.container.scrollLeft += (x - left) * scaleDiff;
  1611. pdfViewer.container.scrollTop += (y - top) * scaleDiff;
  1612. }
  1613. },
  1614. _unblockDocumentLoadEvent() {
  1615. document.blockUnblockOnload?.(false);
  1616. this._unblockDocumentLoadEvent = () => { };
  1617. },
  1618. get scriptingReady() {
  1619. return this.pdfScriptingManager.ready;
  1620. }
  1621. };
  1622. exports.PDFViewerApplication = PDFViewerApplication;
  1623. {
  1624. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1625. var validateFileURL = function (file) {
  1626. if (!file) {
  1627. return;
  1628. }
  1629. try {
  1630. const viewerOrigin = new URL(window.location.href).origin || "null";
  1631. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1632. return;
  1633. }
  1634. const fileOrigin = new URL(file, window.location.href).origin;
  1635. //注销,使得文件可以跨域
  1636. // if (fileOrigin !== viewerOrigin) {
  1637. // throw new Error("file origin does not match viewer's");
  1638. // }
  1639. } catch (ex) {
  1640. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1641. PDFViewerApplication._documentError(msg, {
  1642. message: ex?.message
  1643. });
  1644. });
  1645. throw ex;
  1646. }
  1647. };
  1648. }
  1649. async function loadFakeWorker() {
  1650. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  1651. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  1652. }
  1653. async function loadPDFBug(self) {
  1654. const {
  1655. debuggerScriptPath
  1656. } = self.appConfig;
  1657. const {
  1658. PDFBug
  1659. } = await import(debuggerScriptPath);
  1660. self._PDFBug = PDFBug;
  1661. }
  1662. function reportPageStatsPDFBug({
  1663. pageNumber
  1664. }) {
  1665. if (!globalThis.Stats?.enabled) {
  1666. return;
  1667. }
  1668. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1669. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  1670. }
  1671. function webViewerPageRender({
  1672. pageNumber
  1673. }) {
  1674. if (pageNumber === PDFViewerApplication.page) {
  1675. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
  1676. }
  1677. }
  1678. function webViewerPageRendered({
  1679. pageNumber,
  1680. error
  1681. }) {
  1682. if (pageNumber === PDFViewerApplication.page) {
  1683. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
  1684. }
  1685. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  1686. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1687. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
  1688. if (pageView) {
  1689. thumbnailView?.setImage(pageView);
  1690. }
  1691. }
  1692. if (error) {
  1693. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1694. PDFViewerApplication._otherError(msg, error);
  1695. });
  1696. }
  1697. }
  1698. function webViewerPageMode({
  1699. mode
  1700. }) {
  1701. let view;
  1702. switch (mode) {
  1703. case "thumbs":
  1704. view = _ui_utils.SidebarView.THUMBS;
  1705. break;
  1706. case "bookmarks":
  1707. case "outline":
  1708. view = _ui_utils.SidebarView.OUTLINE;
  1709. break;
  1710. case "attachments":
  1711. view = _ui_utils.SidebarView.ATTACHMENTS;
  1712. break;
  1713. case "layers":
  1714. view = _ui_utils.SidebarView.LAYERS;
  1715. break;
  1716. case "none":
  1717. view = _ui_utils.SidebarView.NONE;
  1718. break;
  1719. default:
  1720. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1721. return;
  1722. }
  1723. PDFViewerApplication.pdfSidebar?.switchView(view, true);
  1724. }
  1725. function webViewerNamedAction(evt) {
  1726. switch (evt.action) {
  1727. case "GoToPage":
  1728. PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
  1729. break;
  1730. case "Find":
  1731. if (!PDFViewerApplication.supportsIntegratedFind) {
  1732. PDFViewerApplication?.findBar.toggle();
  1733. }
  1734. break;
  1735. case "Print":
  1736. PDFViewerApplication.triggerPrinting();
  1737. break;
  1738. case "SaveAs":
  1739. PDFViewerApplication.downloadOrSave();
  1740. break;
  1741. }
  1742. }
  1743. function webViewerPresentationModeChanged(evt) {
  1744. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1745. }
  1746. function webViewerSidebarViewChanged({
  1747. view
  1748. }) {
  1749. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  1750. if (PDFViewerApplication.isInitialViewSet) {
  1751. PDFViewerApplication.store?.set("sidebarView", view).catch(() => { });
  1752. }
  1753. }
  1754. function webViewerUpdateViewarea({
  1755. location
  1756. }) {
  1757. if (PDFViewerApplication.isInitialViewSet) {
  1758. PDFViewerApplication.store?.setMultiple({
  1759. page: location.pageNumber,
  1760. zoom: location.scale,
  1761. scrollLeft: location.left,
  1762. scrollTop: location.top,
  1763. rotation: location.rotation
  1764. }).catch(() => { });
  1765. }
  1766. if (PDFViewerApplication.appConfig.secondaryToolbar) {
  1767. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1768. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1769. }
  1770. }
  1771. function webViewerScrollModeChanged(evt) {
  1772. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1773. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => { });
  1774. }
  1775. }
  1776. function webViewerSpreadModeChanged(evt) {
  1777. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1778. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => { });
  1779. }
  1780. }
  1781. function webViewerResize() {
  1782. const {
  1783. pdfDocument,
  1784. pdfViewer,
  1785. pdfRenderingQueue
  1786. } = PDFViewerApplication;
  1787. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  1788. return;
  1789. }
  1790. if (!pdfDocument) {
  1791. return;
  1792. }
  1793. const currentScaleValue = pdfViewer.currentScaleValue;
  1794. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  1795. pdfViewer.currentScaleValue = currentScaleValue;
  1796. }
  1797. pdfViewer.update();
  1798. }
  1799. function webViewerHashchange(evt) {
  1800. const hash = evt.hash;
  1801. if (!hash) {
  1802. return;
  1803. }
  1804. if (!PDFViewerApplication.isInitialViewSet) {
  1805. PDFViewerApplication.initialBookmark = hash;
  1806. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  1807. PDFViewerApplication.pdfLinkService.setHash(hash);
  1808. }
  1809. }
  1810. {
  1811. var webViewerFileInputChange = function (evt) {
  1812. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  1813. return;
  1814. }
  1815. const file = evt.fileInput.files[0];
  1816. PDFViewerApplication.open({
  1817. url: URL.createObjectURL(file),
  1818. originalUrl: file.name
  1819. });
  1820. };
  1821. var webViewerOpenFile = function (evt) {
  1822. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  1823. fileInput.click();
  1824. };
  1825. }
  1826. function webViewerPresentationMode() {
  1827. PDFViewerApplication.requestPresentationMode();
  1828. }
  1829. function webViewerSwitchAnnotationEditorMode(evt) {
  1830. PDFViewerApplication.pdfViewer.annotationEditorMode = evt;
  1831. }
  1832. function webViewerSwitchAnnotationEditorParams(evt) {
  1833. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  1834. }
  1835. function webViewerPrint() {
  1836. PDFViewerApplication.triggerPrinting();
  1837. }
  1838. function webViewerDownload() {
  1839. PDFViewerApplication.downloadOrSave();
  1840. }
  1841. function webViewerOpenInExternalApp() {
  1842. PDFViewerApplication.openInExternalApp();
  1843. }
  1844. function webViewerFirstPage() {
  1845. PDFViewerApplication.page = 1;
  1846. }
  1847. function webViewerLastPage() {
  1848. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1849. }
  1850. function webViewerNextPage() {
  1851. PDFViewerApplication.pdfViewer.nextPage();
  1852. }
  1853. function webViewerPreviousPage() {
  1854. PDFViewerApplication.pdfViewer.previousPage();
  1855. }
  1856. function webViewerZoomIn() {
  1857. PDFViewerApplication.zoomIn();
  1858. }
  1859. function webViewerZoomOut() {
  1860. PDFViewerApplication.zoomOut();
  1861. }
  1862. function webViewerZoomReset() {
  1863. PDFViewerApplication.zoomReset();
  1864. }
  1865. function webViewerPageNumberChanged(evt) {
  1866. const pdfViewer = PDFViewerApplication.pdfViewer;
  1867. if (evt.value !== "") {
  1868. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  1869. }
  1870. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1871. PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1872. }
  1873. }
  1874. function webViewerScaleChanged(evt) {
  1875. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1876. }
  1877. function webViewerRotateCw() {
  1878. PDFViewerApplication.rotatePages(90);
  1879. }
  1880. function webViewerRotateCcw() {
  1881. PDFViewerApplication.rotatePages(-90);
  1882. }
  1883. function webViewerOptionalContentConfig(evt) {
  1884. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  1885. }
  1886. function webViewerSwitchScrollMode(evt) {
  1887. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  1888. }
  1889. function webViewerSwitchSpreadMode(evt) {
  1890. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  1891. }
  1892. function webViewerDocumentProperties() {
  1893. PDFViewerApplication.pdfDocumentProperties?.open();
  1894. }
  1895. function webViewerFindFromUrlHash(evt) {
  1896. PDFViewerApplication.eventBus.dispatch("find", {
  1897. source: evt.source,
  1898. type: "",
  1899. query: evt.query,
  1900. caseSensitive: false,
  1901. entireWord: false,
  1902. highlightAll: true,
  1903. findPrevious: false,
  1904. matchDiacritics: true
  1905. });
  1906. }
  1907. function webViewerUpdateFindMatchesCount({
  1908. matchesCount
  1909. }) {
  1910. if (PDFViewerApplication.supportsIntegratedFind) {
  1911. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  1912. } else {
  1913. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  1914. }
  1915. }
  1916. function webViewerUpdateFindControlState({
  1917. state,
  1918. previous,
  1919. matchesCount,
  1920. rawQuery
  1921. }) {
  1922. if (PDFViewerApplication.supportsIntegratedFind) {
  1923. PDFViewerApplication.externalServices.updateFindControlState({
  1924. result: state,
  1925. findPrevious: previous,
  1926. matchesCount,
  1927. rawQuery
  1928. });
  1929. } else {
  1930. PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount);
  1931. }
  1932. }
  1933. function webViewerScaleChanging(evt) {
  1934. PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
  1935. PDFViewerApplication.pdfViewer.update();
  1936. }
  1937. function webViewerRotationChanging(evt) {
  1938. if (PDFViewerApplication.pdfThumbnailViewer) {
  1939. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  1940. }
  1941. PDFViewerApplication.forceRendering();
  1942. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  1943. }
  1944. function webViewerPageChanging({
  1945. pageNumber,
  1946. pageLabel
  1947. }) {
  1948. PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
  1949. PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
  1950. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  1951. PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
  1952. }
  1953. const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1954. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING);
  1955. }
  1956. function webViewerResolutionChange(evt) {
  1957. PDFViewerApplication.pdfViewer.refresh();
  1958. }
  1959. function webViewerVisibilityChange(evt) {
  1960. if (document.visibilityState === "visible") {
  1961. setZoomDisabledTimeout();
  1962. }
  1963. }
  1964. let zoomDisabledTimeout = null;
  1965. function setZoomDisabledTimeout() {
  1966. if (zoomDisabledTimeout) {
  1967. clearTimeout(zoomDisabledTimeout);
  1968. }
  1969. zoomDisabledTimeout = setTimeout(function () {
  1970. zoomDisabledTimeout = null;
  1971. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  1972. }
  1973. function webViewerWheel(evt) {
  1974. const {
  1975. pdfViewer,
  1976. supportedMouseWheelZoomModifierKeys,
  1977. supportsPinchToZoom
  1978. } = PDFViewerApplication;
  1979. if (pdfViewer.isInPresentationMode) {
  1980. return;
  1981. }
  1982. const deltaMode = evt.deltaMode;
  1983. let scaleFactor = Math.exp(-evt.deltaY / 100);
  1984. const isBuiltInMac = false;
  1985. const isPinchToZoom = evt.ctrlKey && !PDFViewerApplication._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && (Math.abs(scaleFactor - 1) < 0.05 || isBuiltInMac) && evt.deltaZ === 0;
  1986. if (isPinchToZoom || evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  1987. evt.preventDefault();
  1988. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  1989. return;
  1990. }
  1991. const previousScale = pdfViewer.currentScale;
  1992. if (isPinchToZoom && supportsPinchToZoom) {
  1993. scaleFactor = PDFViewerApplication._accumulateFactor(previousScale, scaleFactor, "_wheelUnusedFactor");
  1994. if (scaleFactor < 1) {
  1995. PDFViewerApplication.zoomOut(null, scaleFactor);
  1996. } else if (scaleFactor > 1) {
  1997. PDFViewerApplication.zoomIn(null, scaleFactor);
  1998. } else {
  1999. return;
  2000. }
  2001. } else {
  2002. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2003. let ticks = 0;
  2004. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2005. if (Math.abs(delta) >= 1) {
  2006. ticks = Math.sign(delta);
  2007. } else {
  2008. ticks = PDFViewerApplication._accumulateTicks(delta, "_wheelUnusedTicks");
  2009. }
  2010. } else {
  2011. const PIXELS_PER_LINE_SCALE = 30;
  2012. ticks = PDFViewerApplication._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks");
  2013. }
  2014. if (ticks < 0) {
  2015. PDFViewerApplication.zoomOut(-ticks);
  2016. } else if (ticks > 0) {
  2017. PDFViewerApplication.zoomIn(ticks);
  2018. } else {
  2019. return;
  2020. }
  2021. }
  2022. PDFViewerApplication._centerAtPos(previousScale, evt.clientX, evt.clientY);
  2023. } else {
  2024. setZoomDisabledTimeout();
  2025. }
  2026. }
  2027. function webViewerTouchStart(evt) {
  2028. if (PDFViewerApplication.pdfViewer.isInPresentationMode || evt.touches.length < 2) {
  2029. return;
  2030. }
  2031. evt.preventDefault();
  2032. if (evt.touches.length !== 2) {
  2033. PDFViewerApplication._touchInfo = null;
  2034. return;
  2035. }
  2036. let [touch0, touch1] = evt.touches;
  2037. if (touch0.identifier > touch1.identifier) {
  2038. [touch0, touch1] = [touch1, touch0];
  2039. }
  2040. PDFViewerApplication._touchInfo = {
  2041. touch0X: touch0.pageX,
  2042. touch0Y: touch0.pageY,
  2043. touch1X: touch1.pageX,
  2044. touch1Y: touch1.pageY
  2045. };
  2046. }
  2047. function webViewerTouchMove(evt) {
  2048. if (!PDFViewerApplication._touchInfo || evt.touches.length !== 2) {
  2049. return;
  2050. }
  2051. const {
  2052. pdfViewer,
  2053. _touchInfo,
  2054. supportsPinchToZoom
  2055. } = PDFViewerApplication;
  2056. let [touch0, touch1] = evt.touches;
  2057. if (touch0.identifier > touch1.identifier) {
  2058. [touch0, touch1] = [touch1, touch0];
  2059. }
  2060. const {
  2061. pageX: page0X,
  2062. pageY: page0Y
  2063. } = touch0;
  2064. const {
  2065. pageX: page1X,
  2066. pageY: page1Y
  2067. } = touch1;
  2068. const {
  2069. touch0X: pTouch0X,
  2070. touch0Y: pTouch0Y,
  2071. touch1X: pTouch1X,
  2072. touch1Y: pTouch1Y
  2073. } = _touchInfo;
  2074. if (Math.abs(pTouch0X - page0X) <= 1 && Math.abs(pTouch0Y - page0Y) <= 1 && Math.abs(pTouch1X - page1X) <= 1 && Math.abs(pTouch1Y - page1Y) <= 1) {
  2075. return;
  2076. }
  2077. _touchInfo.touch0X = page0X;
  2078. _touchInfo.touch0Y = page0Y;
  2079. _touchInfo.touch1X = page1X;
  2080. _touchInfo.touch1Y = page1Y;
  2081. if (pTouch0X === page0X && pTouch0Y === page0Y) {
  2082. const v1X = pTouch1X - page0X;
  2083. const v1Y = pTouch1Y - page0Y;
  2084. const v2X = page1X - page0X;
  2085. const v2Y = page1Y - page0Y;
  2086. const det = v1X * v2Y - v1Y * v2X;
  2087. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  2088. return;
  2089. }
  2090. } else if (pTouch1X === page1X && pTouch1Y === page1Y) {
  2091. const v1X = pTouch0X - page1X;
  2092. const v1Y = pTouch0Y - page1Y;
  2093. const v2X = page0X - page1X;
  2094. const v2Y = page0Y - page1Y;
  2095. const det = v1X * v2Y - v1Y * v2X;
  2096. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  2097. return;
  2098. }
  2099. } else {
  2100. const diff0X = page0X - pTouch0X;
  2101. const diff1X = page1X - pTouch1X;
  2102. const diff0Y = page0Y - pTouch0Y;
  2103. const diff1Y = page1Y - pTouch1Y;
  2104. const dotProduct = diff0X * diff1X + diff0Y * diff1Y;
  2105. if (dotProduct >= 0) {
  2106. return;
  2107. }
  2108. }
  2109. evt.preventDefault();
  2110. const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1;
  2111. const pDistance = Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1;
  2112. const previousScale = pdfViewer.currentScale;
  2113. if (supportsPinchToZoom) {
  2114. const newScaleFactor = PDFViewerApplication._accumulateFactor(previousScale, distance / pDistance, "_touchUnusedFactor");
  2115. if (newScaleFactor < 1) {
  2116. PDFViewerApplication.zoomOut(null, newScaleFactor);
  2117. } else if (newScaleFactor > 1) {
  2118. PDFViewerApplication.zoomIn(null, newScaleFactor);
  2119. } else {
  2120. return;
  2121. }
  2122. } else {
  2123. const PIXELS_PER_LINE_SCALE = 30;
  2124. const ticks = PDFViewerApplication._accumulateTicks((distance - pDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks");
  2125. if (ticks < 0) {
  2126. PDFViewerApplication.zoomOut(-ticks);
  2127. } else if (ticks > 0) {
  2128. PDFViewerApplication.zoomIn(ticks);
  2129. } else {
  2130. return;
  2131. }
  2132. }
  2133. PDFViewerApplication._centerAtPos(previousScale, (page0X + page1X) / 2, (page0Y + page1Y) / 2);
  2134. }
  2135. function webViewerTouchEnd(evt) {
  2136. if (!PDFViewerApplication._touchInfo) {
  2137. return;
  2138. }
  2139. evt.preventDefault();
  2140. PDFViewerApplication._touchInfo = null;
  2141. PDFViewerApplication._touchUnusedTicks = 0;
  2142. PDFViewerApplication._touchUnusedFactor = 1;
  2143. }
  2144. function webViewerClick(evt) {
  2145. if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
  2146. return;
  2147. }
  2148. const appConfig = PDFViewerApplication.appConfig;
  2149. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) {
  2150. PDFViewerApplication.secondaryToolbar.close();
  2151. }
  2152. }
  2153. function webViewerKeyUp(evt) {
  2154. if (evt.key === "Control") {
  2155. PDFViewerApplication._isCtrlKeyDown = false;
  2156. }
  2157. }
  2158. function webViewerKeyDown(evt) {
  2159. PDFViewerApplication._isCtrlKeyDown = evt.key === "Control";
  2160. if (PDFViewerApplication.overlayManager.active) {
  2161. return;
  2162. }
  2163. const {
  2164. eventBus,
  2165. pdfViewer
  2166. } = PDFViewerApplication;
  2167. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  2168. let handled = false,
  2169. ensureViewerFocused = false;
  2170. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2171. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2172. switch (evt.keyCode) {
  2173. case 70:
  2174. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2175. PDFViewerApplication.findBar?.open();
  2176. handled = true;
  2177. }
  2178. break;
  2179. case 71:
  2180. if (!PDFViewerApplication.supportsIntegratedFind) {
  2181. const {
  2182. state
  2183. } = PDFViewerApplication.findController;
  2184. if (state) {
  2185. const newState = {
  2186. source: window,
  2187. type: "again",
  2188. findPrevious: cmd === 5 || cmd === 12
  2189. };
  2190. eventBus.dispatch("find", {
  2191. ...state,
  2192. ...newState
  2193. });
  2194. }
  2195. handled = true;
  2196. }
  2197. break;
  2198. case 61:
  2199. case 107:
  2200. case 187:
  2201. case 171:
  2202. PDFViewerApplication.zoomIn();
  2203. handled = true;
  2204. break;
  2205. case 173:
  2206. case 109:
  2207. case 189:
  2208. PDFViewerApplication.zoomOut();
  2209. handled = true;
  2210. break;
  2211. case 48:
  2212. case 96:
  2213. if (!isViewerInPresentationMode) {
  2214. setTimeout(function () {
  2215. PDFViewerApplication.zoomReset();
  2216. });
  2217. handled = false;
  2218. }
  2219. break;
  2220. case 38:
  2221. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2222. PDFViewerApplication.page = 1;
  2223. handled = true;
  2224. ensureViewerFocused = true;
  2225. }
  2226. break;
  2227. case 40:
  2228. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2229. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2230. handled = true;
  2231. ensureViewerFocused = true;
  2232. }
  2233. break;
  2234. }
  2235. }
  2236. if (cmd === 1 || cmd === 8) {
  2237. switch (evt.keyCode) {
  2238. case 83:
  2239. eventBus.dispatch("download", {
  2240. source: window
  2241. });
  2242. handled = true;
  2243. break;
  2244. case 79:
  2245. {
  2246. eventBus.dispatch("openfile", {
  2247. source: window
  2248. });
  2249. handled = true;
  2250. }
  2251. break;
  2252. }
  2253. }
  2254. if (cmd === 3 || cmd === 10) {
  2255. switch (evt.keyCode) {
  2256. case 80:
  2257. PDFViewerApplication.requestPresentationMode();
  2258. handled = true;
  2259. PDFViewerApplication.externalServices.reportTelemetry({
  2260. type: "buttons",
  2261. data: {
  2262. id: "presentationModeKeyboard"
  2263. }
  2264. });
  2265. break;
  2266. case 71:
  2267. if (PDFViewerApplication.appConfig.toolbar) {
  2268. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2269. handled = true;
  2270. }
  2271. break;
  2272. }
  2273. }
  2274. if (handled) {
  2275. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2276. pdfViewer.focus();
  2277. }
  2278. evt.preventDefault();
  2279. return;
  2280. }
  2281. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2282. const curElementTagName = curElement?.tagName.toUpperCase();
  2283. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2284. if (evt.keyCode !== 27) {
  2285. return;
  2286. }
  2287. }
  2288. if (cmd === 0) {
  2289. let turnPage = 0,
  2290. turnOnlyIfPageFit = false;
  2291. switch (evt.keyCode) {
  2292. case 38:
  2293. case 33:
  2294. if (pdfViewer.isVerticalScrollbarEnabled) {
  2295. turnOnlyIfPageFit = true;
  2296. }
  2297. turnPage = -1;
  2298. break;
  2299. case 8:
  2300. if (!isViewerInPresentationMode) {
  2301. turnOnlyIfPageFit = true;
  2302. }
  2303. turnPage = -1;
  2304. break;
  2305. case 37:
  2306. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2307. turnOnlyIfPageFit = true;
  2308. }
  2309. case 75:
  2310. case 80:
  2311. turnPage = -1;
  2312. break;
  2313. case 27:
  2314. if (PDFViewerApplication.secondaryToolbar?.isOpen) {
  2315. PDFViewerApplication.secondaryToolbar.close();
  2316. handled = true;
  2317. }
  2318. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) {
  2319. PDFViewerApplication.findBar.close();
  2320. handled = true;
  2321. }
  2322. break;
  2323. case 40:
  2324. case 34:
  2325. if (pdfViewer.isVerticalScrollbarEnabled) {
  2326. turnOnlyIfPageFit = true;
  2327. }
  2328. turnPage = 1;
  2329. break;
  2330. case 13:
  2331. case 32:
  2332. if (!isViewerInPresentationMode) {
  2333. turnOnlyIfPageFit = true;
  2334. }
  2335. turnPage = 1;
  2336. break;
  2337. case 39:
  2338. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2339. turnOnlyIfPageFit = true;
  2340. }
  2341. case 74:
  2342. case 78:
  2343. turnPage = 1;
  2344. break;
  2345. case 36:
  2346. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2347. PDFViewerApplication.page = 1;
  2348. handled = true;
  2349. ensureViewerFocused = true;
  2350. }
  2351. break;
  2352. case 35:
  2353. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2354. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2355. handled = true;
  2356. ensureViewerFocused = true;
  2357. }
  2358. break;
  2359. case 83:
  2360. PDFViewerApplication.pdfCursorTools?.switchTool(_ui_utils.CursorTool.SELECT);
  2361. break;
  2362. case 72:
  2363. PDFViewerApplication.pdfCursorTools?.switchTool(_ui_utils.CursorTool.HAND);
  2364. break;
  2365. case 82:
  2366. PDFViewerApplication.rotatePages(90);
  2367. break;
  2368. case 115:
  2369. PDFViewerApplication.pdfSidebar?.toggle();
  2370. break;
  2371. }
  2372. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2373. if (turnPage > 0) {
  2374. pdfViewer.nextPage();
  2375. } else {
  2376. pdfViewer.previousPage();
  2377. }
  2378. handled = true;
  2379. }
  2380. }
  2381. if (cmd === 4) {
  2382. switch (evt.keyCode) {
  2383. case 13:
  2384. case 32:
  2385. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2386. break;
  2387. }
  2388. pdfViewer.previousPage();
  2389. handled = true;
  2390. break;
  2391. case 82:
  2392. PDFViewerApplication.rotatePages(-90);
  2393. break;
  2394. }
  2395. }
  2396. if (!handled && !isViewerInPresentationMode) {
  2397. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2398. ensureViewerFocused = true;
  2399. }
  2400. }
  2401. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2402. pdfViewer.focus();
  2403. }
  2404. if (handled) {
  2405. evt.preventDefault();
  2406. }
  2407. }
  2408. function beforeUnload(evt) {
  2409. evt.preventDefault();
  2410. evt.returnValue = "";
  2411. return false;
  2412. }
  2413. function webViewerAnnotationEditorStatesChanged(data) {
  2414. PDFViewerApplication.externalServices.updateEditorStates(data);
  2415. }
  2416. const PDFPrintServiceFactory = {
  2417. instance: {
  2418. supportsPrinting: false,
  2419. createPrintService() {
  2420. throw new Error("Not implemented: createPrintService");
  2421. }
  2422. }
  2423. };
  2424. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2425. /***/
  2426. }),
  2427. /* 3 */
  2428. /***/ ((__unused_webpack_module, exports) => {
  2429. Object.defineProperty(exports, "__esModule", ({
  2430. value: true
  2431. }));
  2432. exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = 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.CursorTool = exports.AutoPrintRegExp = void 0;
  2433. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  2434. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2435. exports.approximateFraction = approximateFraction;
  2436. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2437. exports.binarySearchFirstItem = binarySearchFirstItem;
  2438. exports.docStyle = void 0;
  2439. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2440. exports.getPageSizeInches = getPageSizeInches;
  2441. exports.getVisibleElements = getVisibleElements;
  2442. exports.isPortraitOrientation = isPortraitOrientation;
  2443. exports.isValidRotation = isValidRotation;
  2444. exports.isValidScrollMode = isValidScrollMode;
  2445. exports.isValidSpreadMode = isValidSpreadMode;
  2446. exports.noContextMenuHandler = noContextMenuHandler;
  2447. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2448. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2449. exports.parseQueryString = parseQueryString;
  2450. exports.removeNullCharacters = removeNullCharacters;
  2451. exports.roundToDivide = roundToDivide;
  2452. exports.scrollIntoView = scrollIntoView;
  2453. exports.toggleCheckedBtn = toggleCheckedBtn;
  2454. exports.toggleExpandedBtn = toggleExpandedBtn;
  2455. exports.watchScroll = watchScroll;
  2456. const DEFAULT_SCALE_VALUE = "auto";
  2457. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2458. const DEFAULT_SCALE = 1.0;
  2459. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2460. const DEFAULT_SCALE_DELTA = 1.1;
  2461. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  2462. const MIN_SCALE = 0.1;
  2463. exports.MIN_SCALE = MIN_SCALE;
  2464. const MAX_SCALE = 10.0;
  2465. exports.MAX_SCALE = MAX_SCALE;
  2466. const UNKNOWN_SCALE = 0;
  2467. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2468. const MAX_AUTO_SCALE = 1.25;
  2469. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2470. const SCROLLBAR_PADDING = 40;
  2471. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2472. const VERTICAL_PADDING = 5;
  2473. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2474. const RenderingStates = {
  2475. INITIAL: 0,
  2476. RUNNING: 1,
  2477. PAUSED: 2,
  2478. FINISHED: 3
  2479. };
  2480. exports.RenderingStates = RenderingStates;
  2481. const PresentationModeState = {
  2482. UNKNOWN: 0,
  2483. NORMAL: 1,
  2484. CHANGING: 2,
  2485. FULLSCREEN: 3
  2486. };
  2487. exports.PresentationModeState = PresentationModeState;
  2488. const SidebarView = {
  2489. UNKNOWN: -1,
  2490. NONE: 0,
  2491. THUMBS: 1,
  2492. OUTLINE: 2,
  2493. ATTACHMENTS: 3,
  2494. LAYERS: 4
  2495. };
  2496. exports.SidebarView = SidebarView;
  2497. const TextLayerMode = {
  2498. DISABLE: 0,
  2499. ENABLE: 1,
  2500. ENABLE_PERMISSIONS: 2
  2501. };
  2502. exports.TextLayerMode = TextLayerMode;
  2503. const ScrollMode = {
  2504. UNKNOWN: -1,
  2505. VERTICAL: 0,
  2506. HORIZONTAL: 1,
  2507. WRAPPED: 2,
  2508. PAGE: 3
  2509. };
  2510. exports.ScrollMode = ScrollMode;
  2511. const SpreadMode = {
  2512. UNKNOWN: -1,
  2513. NONE: 0,
  2514. ODD: 1,
  2515. EVEN: 2
  2516. };
  2517. exports.SpreadMode = SpreadMode;
  2518. const CursorTool = {
  2519. SELECT: 0,
  2520. HAND: 1,
  2521. ZOOM: 2
  2522. };
  2523. exports.CursorTool = CursorTool;
  2524. const AutoPrintRegExp = /\bprint\s*\(/;
  2525. exports.AutoPrintRegExp = AutoPrintRegExp;
  2526. class OutputScale {
  2527. constructor() {
  2528. const pixelRatio = window.devicePixelRatio || 1;
  2529. this.sx = pixelRatio;
  2530. this.sy = pixelRatio;
  2531. }
  2532. get scaled() {
  2533. return this.sx !== 1 || this.sy !== 1;
  2534. }
  2535. }
  2536. exports.OutputScale = OutputScale;
  2537. function scrollIntoView(element, spot, scrollMatches = false) {
  2538. let parent = element.offsetParent;
  2539. if (!parent) {
  2540. console.error("offsetParent is not set -- cannot scroll");
  2541. return;
  2542. }
  2543. let offsetY = element.offsetTop + element.clientTop;
  2544. let offsetX = element.offsetLeft + element.clientLeft;
  2545. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  2546. offsetY += parent.offsetTop;
  2547. offsetX += parent.offsetLeft;
  2548. parent = parent.offsetParent;
  2549. if (!parent) {
  2550. return;
  2551. }
  2552. }
  2553. if (spot) {
  2554. if (spot.top !== undefined) {
  2555. offsetY += spot.top;
  2556. }
  2557. if (spot.left !== undefined) {
  2558. offsetX += spot.left;
  2559. parent.scrollLeft = offsetX;
  2560. }
  2561. }
  2562. parent.scrollTop = offsetY;
  2563. }
  2564. function watchScroll(viewAreaElement, callback) {
  2565. const debounceScroll = function (evt) {
  2566. if (rAF) {
  2567. return;
  2568. }
  2569. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2570. rAF = null;
  2571. const currentX = viewAreaElement.scrollLeft;
  2572. const lastX = state.lastX;
  2573. if (currentX !== lastX) {
  2574. state.right = currentX > lastX;
  2575. }
  2576. state.lastX = currentX;
  2577. const currentY = viewAreaElement.scrollTop;
  2578. const lastY = state.lastY;
  2579. if (currentY !== lastY) {
  2580. state.down = currentY > lastY;
  2581. }
  2582. state.lastY = currentY;
  2583. callback(state);
  2584. });
  2585. };
  2586. const state = {
  2587. right: true,
  2588. down: true,
  2589. lastX: viewAreaElement.scrollLeft,
  2590. lastY: viewAreaElement.scrollTop,
  2591. _eventHandler: debounceScroll
  2592. };
  2593. let rAF = null;
  2594. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2595. return state;
  2596. }
  2597. function parseQueryString(query) {
  2598. const params = new Map();
  2599. for (const [key, value] of new URLSearchParams(query)) {
  2600. params.set(key.toLowerCase(), value);
  2601. }
  2602. return params;
  2603. }
  2604. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  2605. function removeNullCharacters(str, replaceInvisible = false) {
  2606. if (typeof str !== "string") {
  2607. console.error(`The argument must be a string.`);
  2608. return str;
  2609. }
  2610. if (replaceInvisible) {
  2611. str = str.replaceAll(InvisibleCharactersRegExp, " ");
  2612. }
  2613. return str.replaceAll("\x00", "");
  2614. }
  2615. function binarySearchFirstItem(items, condition, start = 0) {
  2616. let minIndex = start;
  2617. let maxIndex = items.length - 1;
  2618. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2619. return items.length;
  2620. }
  2621. if (condition(items[minIndex])) {
  2622. return minIndex;
  2623. }
  2624. while (minIndex < maxIndex) {
  2625. const currentIndex = minIndex + maxIndex >> 1;
  2626. const currentItem = items[currentIndex];
  2627. if (condition(currentItem)) {
  2628. maxIndex = currentIndex;
  2629. } else {
  2630. minIndex = currentIndex + 1;
  2631. }
  2632. }
  2633. return minIndex;
  2634. }
  2635. function approximateFraction(x) {
  2636. if (Math.floor(x) === x) {
  2637. return [x, 1];
  2638. }
  2639. const xinv = 1 / x;
  2640. const limit = 8;
  2641. if (xinv > limit) {
  2642. return [1, limit];
  2643. } else if (Math.floor(xinv) === xinv) {
  2644. return [1, xinv];
  2645. }
  2646. const x_ = x > 1 ? xinv : x;
  2647. let a = 0,
  2648. b = 1,
  2649. c = 1,
  2650. d = 1;
  2651. while (true) {
  2652. const p = a + c,
  2653. q = b + d;
  2654. if (q > limit) {
  2655. break;
  2656. }
  2657. if (x_ <= p / q) {
  2658. c = p;
  2659. d = q;
  2660. } else {
  2661. a = p;
  2662. b = q;
  2663. }
  2664. }
  2665. let result;
  2666. if (x_ - a / b < c / d - x_) {
  2667. result = x_ === x ? [a, b] : [b, a];
  2668. } else {
  2669. result = x_ === x ? [c, d] : [d, c];
  2670. }
  2671. return result;
  2672. }
  2673. function roundToDivide(x, div) {
  2674. const r = x % div;
  2675. return r === 0 ? x : Math.round(x - r + div);
  2676. }
  2677. function getPageSizeInches({
  2678. view,
  2679. userUnit,
  2680. rotate
  2681. }) {
  2682. const [x1, y1, x2, y2] = view;
  2683. const changeOrientation = rotate % 180 !== 0;
  2684. const width = (x2 - x1) / 72 * userUnit;
  2685. const height = (y2 - y1) / 72 * userUnit;
  2686. return {
  2687. width: changeOrientation ? height : width,
  2688. height: changeOrientation ? width : height
  2689. };
  2690. }
  2691. function backtrackBeforeAllVisibleElements(index, views, top) {
  2692. if (index < 2) {
  2693. return index;
  2694. }
  2695. let elt = views[index].div;
  2696. let pageTop = elt.offsetTop + elt.clientTop;
  2697. if (pageTop >= top) {
  2698. elt = views[index - 1].div;
  2699. pageTop = elt.offsetTop + elt.clientTop;
  2700. }
  2701. for (let i = index - 2; i >= 0; --i) {
  2702. elt = views[i].div;
  2703. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2704. break;
  2705. }
  2706. index = i;
  2707. }
  2708. return index;
  2709. }
  2710. function getVisibleElements({
  2711. scrollEl,
  2712. views,
  2713. sortByVisibility = false,
  2714. horizontal = false,
  2715. rtl = false
  2716. }) {
  2717. const top = scrollEl.scrollTop,
  2718. bottom = top + scrollEl.clientHeight;
  2719. const left = scrollEl.scrollLeft,
  2720. right = left + scrollEl.clientWidth;
  2721. function isElementBottomAfterViewTop(view) {
  2722. const element = view.div;
  2723. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2724. return elementBottom > top;
  2725. }
  2726. function isElementNextAfterViewHorizontally(view) {
  2727. const element = view.div;
  2728. const elementLeft = element.offsetLeft + element.clientLeft;
  2729. const elementRight = elementLeft + element.clientWidth;
  2730. return rtl ? elementLeft < right : elementRight > left;
  2731. }
  2732. const visible = [],
  2733. ids = new Set(),
  2734. numViews = views.length;
  2735. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2736. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2737. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2738. }
  2739. let lastEdge = horizontal ? right : -1;
  2740. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2741. const view = views[i],
  2742. element = view.div;
  2743. const currentWidth = element.offsetLeft + element.clientLeft;
  2744. const currentHeight = element.offsetTop + element.clientTop;
  2745. const viewWidth = element.clientWidth,
  2746. viewHeight = element.clientHeight;
  2747. const viewRight = currentWidth + viewWidth;
  2748. const viewBottom = currentHeight + viewHeight;
  2749. if (lastEdge === -1) {
  2750. if (viewBottom >= bottom) {
  2751. lastEdge = viewBottom;
  2752. }
  2753. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2754. break;
  2755. }
  2756. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2757. continue;
  2758. }
  2759. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2760. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2761. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2762. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2763. const percent = fractionHeight * fractionWidth * 100 | 0;
  2764. visible.push({
  2765. id: view.id,
  2766. x: currentWidth,
  2767. y: currentHeight,
  2768. view,
  2769. percent,
  2770. widthPercent: fractionWidth * 100 | 0
  2771. });
  2772. ids.add(view.id);
  2773. }
  2774. const first = visible[0],
  2775. last = visible.at(-1);
  2776. if (sortByVisibility) {
  2777. visible.sort(function (a, b) {
  2778. const pc = a.percent - b.percent;
  2779. if (Math.abs(pc) > 0.001) {
  2780. return -pc;
  2781. }
  2782. return a.id - b.id;
  2783. });
  2784. }
  2785. return {
  2786. first,
  2787. last,
  2788. views: visible,
  2789. ids
  2790. };
  2791. }
  2792. function noContextMenuHandler(evt) {
  2793. evt.preventDefault();
  2794. }
  2795. function normalizeWheelEventDirection(evt) {
  2796. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2797. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2798. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2799. delta = -delta;
  2800. }
  2801. return delta;
  2802. }
  2803. function normalizeWheelEventDelta(evt) {
  2804. const deltaMode = evt.deltaMode;
  2805. let delta = normalizeWheelEventDirection(evt);
  2806. const MOUSE_PIXELS_PER_LINE = 30;
  2807. const MOUSE_LINES_PER_PAGE = 30;
  2808. if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
  2809. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2810. } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
  2811. delta /= MOUSE_LINES_PER_PAGE;
  2812. }
  2813. return delta;
  2814. }
  2815. function isValidRotation(angle) {
  2816. return Number.isInteger(angle) && angle % 90 === 0;
  2817. }
  2818. function isValidScrollMode(mode) {
  2819. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2820. }
  2821. function isValidSpreadMode(mode) {
  2822. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2823. }
  2824. function isPortraitOrientation(size) {
  2825. return size.width <= size.height;
  2826. }
  2827. const animationStarted = new Promise(function (resolve) {
  2828. window.requestAnimationFrame(resolve);
  2829. });
  2830. exports.animationStarted = animationStarted;
  2831. const docStyle = document.documentElement.style;
  2832. exports.docStyle = docStyle;
  2833. function clamp(v, min, max) {
  2834. return Math.min(Math.max(v, min), max);
  2835. }
  2836. class ProgressBar {
  2837. #classList = null;
  2838. #disableAutoFetchTimeout = null;
  2839. #percent = 0;
  2840. #style = null;
  2841. #visible = true;
  2842. constructor(bar) {
  2843. this.#classList = bar.classList;
  2844. this.#style = bar.style;
  2845. }
  2846. get percent() {
  2847. return this.#percent;
  2848. }
  2849. set percent(val) {
  2850. this.#percent = clamp(val, 0, 100);
  2851. if (isNaN(val)) {
  2852. this.#classList.add("indeterminate");
  2853. return;
  2854. }
  2855. this.#classList.remove("indeterminate");
  2856. this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
  2857. }
  2858. setWidth(viewer) {
  2859. if (!viewer) {
  2860. return;
  2861. }
  2862. const container = viewer.parentNode;
  2863. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  2864. if (scrollbarWidth > 0) {
  2865. this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  2866. }
  2867. }
  2868. setDisableAutoFetch(delay = 5000) {
  2869. if (isNaN(this.#percent)) {
  2870. return;
  2871. }
  2872. if (this.#disableAutoFetchTimeout) {
  2873. clearTimeout(this.#disableAutoFetchTimeout);
  2874. }
  2875. this.show();
  2876. this.#disableAutoFetchTimeout = setTimeout(() => {
  2877. this.#disableAutoFetchTimeout = null;
  2878. this.hide();
  2879. }, delay);
  2880. }
  2881. hide() {
  2882. if (!this.#visible) {
  2883. return;
  2884. }
  2885. this.#visible = false;
  2886. this.#classList.add("hidden");
  2887. }
  2888. show() {
  2889. if (this.#visible) {
  2890. return;
  2891. }
  2892. this.#visible = true;
  2893. this.#classList.remove("hidden");
  2894. }
  2895. }
  2896. exports.ProgressBar = ProgressBar;
  2897. function getActiveOrFocusedElement() {
  2898. let curRoot = document;
  2899. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2900. while (curActiveOrFocused?.shadowRoot) {
  2901. curRoot = curActiveOrFocused.shadowRoot;
  2902. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2903. }
  2904. return curActiveOrFocused;
  2905. }
  2906. function apiPageLayoutToViewerModes(layout) {
  2907. let scrollMode = ScrollMode.VERTICAL,
  2908. spreadMode = SpreadMode.NONE;
  2909. switch (layout) {
  2910. case "SinglePage":
  2911. scrollMode = ScrollMode.PAGE;
  2912. break;
  2913. case "OneColumn":
  2914. break;
  2915. case "TwoPageLeft":
  2916. scrollMode = ScrollMode.PAGE;
  2917. case "TwoColumnLeft":
  2918. spreadMode = SpreadMode.ODD;
  2919. break;
  2920. case "TwoPageRight":
  2921. scrollMode = ScrollMode.PAGE;
  2922. case "TwoColumnRight":
  2923. spreadMode = SpreadMode.EVEN;
  2924. break;
  2925. }
  2926. return {
  2927. scrollMode,
  2928. spreadMode
  2929. };
  2930. }
  2931. function apiPageModeToSidebarView(mode) {
  2932. switch (mode) {
  2933. case "UseNone":
  2934. return SidebarView.NONE;
  2935. case "UseThumbs":
  2936. return SidebarView.THUMBS;
  2937. case "UseOutlines":
  2938. return SidebarView.OUTLINE;
  2939. case "UseAttachments":
  2940. return SidebarView.ATTACHMENTS;
  2941. case "UseOC":
  2942. return SidebarView.LAYERS;
  2943. }
  2944. return SidebarView.NONE;
  2945. }
  2946. function toggleCheckedBtn(button, toggle, view = null) {
  2947. button.classList.toggle("toggled", toggle);
  2948. button.setAttribute("aria-checked", toggle);
  2949. view?.classList.toggle("hidden", !toggle);
  2950. }
  2951. function toggleExpandedBtn(button, toggle, view = null) {
  2952. button.classList.toggle("toggled", toggle);
  2953. button.setAttribute("aria-expanded", toggle);
  2954. view?.classList.toggle("hidden", !toggle);
  2955. }
  2956. /***/
  2957. }),
  2958. /* 4 */
  2959. /***/ ((module) => {
  2960. module.exports = globalThis.pdfjsLib;
  2961. /***/
  2962. }),
  2963. /* 5 */
  2964. /***/ ((__unused_webpack_module, exports) => {
  2965. Object.defineProperty(exports, "__esModule", ({
  2966. value: true
  2967. }));
  2968. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  2969. const compatibilityParams = Object.create(null);
  2970. exports.compatibilityParams = compatibilityParams;
  2971. {
  2972. const userAgent = navigator.userAgent || "";
  2973. const platform = navigator.platform || "";
  2974. const maxTouchPoints = navigator.maxTouchPoints || 1;
  2975. const isAndroid = /Android/.test(userAgent);
  2976. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  2977. (function checkCanvasSizeLimitation() {
  2978. if (isIOS || isAndroid) {
  2979. compatibilityParams.maxCanvasPixels = 5242880;
  2980. }
  2981. })();
  2982. }
  2983. const OptionKind = {
  2984. VIEWER: 0x02,
  2985. API: 0x04,
  2986. WORKER: 0x08,
  2987. PREFERENCE: 0x80
  2988. };
  2989. exports.OptionKind = OptionKind;
  2990. const defaultOptions = {
  2991. annotationEditorMode: {
  2992. value: 0,
  2993. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2994. },
  2995. annotationMode: {
  2996. value: 2,
  2997. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2998. },
  2999. cursorToolOnLoad: {
  3000. value: 0,
  3001. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3002. },
  3003. defaultZoomDelay: {
  3004. value: 400,
  3005. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3006. },
  3007. defaultZoomValue: {
  3008. value: "",
  3009. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3010. },
  3011. disableHistory: {
  3012. value: false,
  3013. kind: OptionKind.VIEWER
  3014. },
  3015. disablePageLabels: {
  3016. value: false,
  3017. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3018. },
  3019. enablePermissions: {
  3020. value: false,
  3021. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3022. },
  3023. enablePrintAutoRotate: {
  3024. value: true,
  3025. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3026. },
  3027. enableScripting: {
  3028. value: true,
  3029. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3030. },
  3031. enableStampEditor: {
  3032. value: true,
  3033. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3034. },
  3035. externalLinkRel: {
  3036. value: "noopener noreferrer nofollow",
  3037. kind: OptionKind.VIEWER
  3038. },
  3039. externalLinkTarget: {
  3040. value: 0,
  3041. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3042. },
  3043. historyUpdateUrl: {
  3044. value: false,
  3045. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3046. },
  3047. ignoreDestinationZoom: {
  3048. value: false,
  3049. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3050. },
  3051. imageResourcesPath: {
  3052. value: "./images/",
  3053. kind: OptionKind.VIEWER
  3054. },
  3055. maxCanvasPixels: {
  3056. value: 16777216,
  3057. kind: OptionKind.VIEWER
  3058. },
  3059. forcePageColors: {
  3060. value: false,
  3061. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3062. },
  3063. pageColorsBackground: {
  3064. value: "Canvas",
  3065. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3066. },
  3067. pageColorsForeground: {
  3068. value: "CanvasText",
  3069. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3070. },
  3071. pdfBugEnabled: {
  3072. value: false,
  3073. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3074. },
  3075. printResolution: {
  3076. value: 150,
  3077. kind: OptionKind.VIEWER
  3078. },
  3079. sidebarViewOnLoad: {
  3080. value: -1,
  3081. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3082. },
  3083. scrollModeOnLoad: {
  3084. value: -1,
  3085. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3086. },
  3087. spreadModeOnLoad: {
  3088. value: -1,
  3089. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3090. },
  3091. textLayerMode: {
  3092. value: 1,
  3093. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3094. },
  3095. viewerCssTheme: {
  3096. value: 0,
  3097. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3098. },
  3099. viewOnLoad: {
  3100. value: 0,
  3101. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3102. },
  3103. cMapPacked: {
  3104. value: true,
  3105. kind: OptionKind.API
  3106. },
  3107. cMapUrl: {
  3108. value: "../web/cmaps/",
  3109. kind: OptionKind.API
  3110. },
  3111. disableAutoFetch: {
  3112. value: false,
  3113. kind: OptionKind.API + OptionKind.PREFERENCE
  3114. },
  3115. disableFontFace: {
  3116. value: false,
  3117. kind: OptionKind.API + OptionKind.PREFERENCE
  3118. },
  3119. disableRange: {
  3120. value: false,
  3121. kind: OptionKind.API + OptionKind.PREFERENCE
  3122. },
  3123. disableStream: {
  3124. value: false,
  3125. kind: OptionKind.API + OptionKind.PREFERENCE
  3126. },
  3127. docBaseUrl: {
  3128. value: "",
  3129. kind: OptionKind.API
  3130. },
  3131. enableXfa: {
  3132. value: true,
  3133. kind: OptionKind.API + OptionKind.PREFERENCE
  3134. },
  3135. fontExtraProperties: {
  3136. value: false,
  3137. kind: OptionKind.API
  3138. },
  3139. isEvalSupported: {
  3140. value: true,
  3141. kind: OptionKind.API
  3142. },
  3143. isOffscreenCanvasSupported: {
  3144. value: true,
  3145. kind: OptionKind.API
  3146. },
  3147. maxImageSize: {
  3148. value: -1,
  3149. kind: OptionKind.API
  3150. },
  3151. pdfBug: {
  3152. value: false,
  3153. kind: OptionKind.API
  3154. },
  3155. standardFontDataUrl: {
  3156. value: "../web/standard_fonts/",
  3157. kind: OptionKind.API
  3158. },
  3159. verbosity: {
  3160. value: 1,
  3161. kind: OptionKind.API
  3162. },
  3163. workerPort: {
  3164. value: null,
  3165. kind: OptionKind.WORKER
  3166. },
  3167. workerSrc: {
  3168. value: "../build/pdf.worker.js",
  3169. kind: OptionKind.WORKER
  3170. }
  3171. };
  3172. {
  3173. defaultOptions.defaultUrl = {
  3174. value: "compressed.tracemonkey-pldi-09.pdf",
  3175. kind: OptionKind.VIEWER
  3176. };
  3177. defaultOptions.disablePreferences = {
  3178. value: false,
  3179. kind: OptionKind.VIEWER
  3180. };
  3181. defaultOptions.locale = {
  3182. value: navigator.language || "en-US",
  3183. kind: OptionKind.VIEWER
  3184. };
  3185. defaultOptions.sandboxBundleSrc = {
  3186. value: "../build/pdf.sandbox.js",
  3187. kind: OptionKind.VIEWER
  3188. };
  3189. }
  3190. const userOptions = Object.create(null);
  3191. class AppOptions {
  3192. constructor() {
  3193. throw new Error("Cannot initialize AppOptions.");
  3194. }
  3195. static get(name) {
  3196. const userOption = userOptions[name];
  3197. if (userOption !== undefined) {
  3198. return userOption;
  3199. }
  3200. const defaultOption = defaultOptions[name];
  3201. if (defaultOption !== undefined) {
  3202. return compatibilityParams[name] ?? defaultOption.value;
  3203. }
  3204. return undefined;
  3205. }
  3206. static getAll(kind = null) {
  3207. const options = Object.create(null);
  3208. for (const name in defaultOptions) {
  3209. const defaultOption = defaultOptions[name];
  3210. if (kind) {
  3211. if ((kind & defaultOption.kind) === 0) {
  3212. continue;
  3213. }
  3214. if (kind === OptionKind.PREFERENCE) {
  3215. const value = defaultOption.value,
  3216. valueType = typeof value;
  3217. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  3218. options[name] = value;
  3219. continue;
  3220. }
  3221. throw new Error(`Invalid type for preference: ${name}`);
  3222. }
  3223. }
  3224. const userOption = userOptions[name];
  3225. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  3226. }
  3227. return options;
  3228. }
  3229. static set(name, value) {
  3230. userOptions[name] = value;
  3231. }
  3232. static setAll(options) {
  3233. for (const name in options) {
  3234. userOptions[name] = options[name];
  3235. }
  3236. }
  3237. static remove(name) {
  3238. delete userOptions[name];
  3239. }
  3240. }
  3241. exports.AppOptions = AppOptions;
  3242. {
  3243. AppOptions._hasUserOptions = function () {
  3244. return Object.keys(userOptions).length > 0;
  3245. };
  3246. }
  3247. /***/
  3248. }),
  3249. /* 6 */
  3250. /***/ ((__unused_webpack_module, exports) => {
  3251. Object.defineProperty(exports, "__esModule", ({
  3252. value: true
  3253. }));
  3254. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3255. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3256. const WaitOnType = {
  3257. EVENT: "event",
  3258. TIMEOUT: "timeout"
  3259. };
  3260. exports.WaitOnType = WaitOnType;
  3261. function waitOnEventOrTimeout({
  3262. target,
  3263. name,
  3264. delay = 0
  3265. }) {
  3266. return new Promise(function (resolve, reject) {
  3267. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3268. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3269. }
  3270. function handler(type) {
  3271. if (target instanceof EventBus) {
  3272. target._off(name, eventHandler);
  3273. } else {
  3274. target.removeEventListener(name, eventHandler);
  3275. }
  3276. if (timeout) {
  3277. clearTimeout(timeout);
  3278. }
  3279. resolve(type);
  3280. }
  3281. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3282. if (target instanceof EventBus) {
  3283. target._on(name, eventHandler);
  3284. } else {
  3285. target.addEventListener(name, eventHandler);
  3286. }
  3287. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3288. const timeout = setTimeout(timeoutHandler, delay);
  3289. });
  3290. }
  3291. class EventBus {
  3292. #listeners = Object.create(null);
  3293. on(eventName, listener, options = null) {
  3294. this._on(eventName, listener, {
  3295. external: true,
  3296. once: options?.once
  3297. });
  3298. }
  3299. off(eventName, listener, options = null) {
  3300. this._off(eventName, listener, {
  3301. external: true,
  3302. once: options?.once
  3303. });
  3304. }
  3305. dispatch(eventName, data) {
  3306. const eventListeners = this.#listeners[eventName];
  3307. if (!eventListeners || eventListeners.length === 0) {
  3308. return;
  3309. }
  3310. let externalListeners;
  3311. for (const {
  3312. listener,
  3313. external,
  3314. once
  3315. } of eventListeners.slice(0)) {
  3316. if (once) {
  3317. this._off(eventName, listener);
  3318. }
  3319. if (external) {
  3320. (externalListeners ||= []).push(listener);
  3321. continue;
  3322. }
  3323. listener(data);
  3324. }
  3325. if (externalListeners) {
  3326. for (const listener of externalListeners) {
  3327. listener(data);
  3328. }
  3329. externalListeners = null;
  3330. }
  3331. }
  3332. _on(eventName, listener, options = null) {
  3333. const eventListeners = this.#listeners[eventName] ||= [];
  3334. eventListeners.push({
  3335. listener,
  3336. external: options?.external === true,
  3337. once: options?.once === true
  3338. });
  3339. }
  3340. _off(eventName, listener, options = null) {
  3341. const eventListeners = this.#listeners[eventName];
  3342. if (!eventListeners) {
  3343. return;
  3344. }
  3345. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3346. if (eventListeners[i].listener === listener) {
  3347. eventListeners.splice(i, 1);
  3348. return;
  3349. }
  3350. }
  3351. }
  3352. }
  3353. exports.EventBus = EventBus;
  3354. class AutomationEventBus extends EventBus {
  3355. dispatch(eventName, data) {
  3356. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3357. }
  3358. }
  3359. exports.AutomationEventBus = AutomationEventBus;
  3360. /***/
  3361. }),
  3362. /* 7 */
  3363. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3364. Object.defineProperty(exports, "__esModule", ({
  3365. value: true
  3366. }));
  3367. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  3368. var _ui_utils = __webpack_require__(3);
  3369. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  3370. const LinkTarget = {
  3371. NONE: 0,
  3372. SELF: 1,
  3373. BLANK: 2,
  3374. PARENT: 3,
  3375. TOP: 4
  3376. };
  3377. exports.LinkTarget = LinkTarget;
  3378. function addLinkAttributes(link, {
  3379. url,
  3380. target,
  3381. rel,
  3382. enabled = true
  3383. } = {}) {
  3384. if (!url || typeof url !== "string") {
  3385. throw new Error('A valid "url" parameter must provided.');
  3386. }
  3387. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  3388. if (enabled) {
  3389. link.href = link.title = urlNullRemoved;
  3390. } else {
  3391. link.href = "";
  3392. link.title = `Disabled: ${urlNullRemoved}`;
  3393. link.onclick = () => {
  3394. return false;
  3395. };
  3396. }
  3397. let targetStr = "";
  3398. switch (target) {
  3399. case LinkTarget.NONE:
  3400. break;
  3401. case LinkTarget.SELF:
  3402. targetStr = "_self";
  3403. break;
  3404. case LinkTarget.BLANK:
  3405. targetStr = "_blank";
  3406. break;
  3407. case LinkTarget.PARENT:
  3408. targetStr = "_parent";
  3409. break;
  3410. case LinkTarget.TOP:
  3411. targetStr = "_top";
  3412. break;
  3413. }
  3414. link.target = targetStr;
  3415. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  3416. }
  3417. class PDFLinkService {
  3418. #pagesRefCache = new Map();
  3419. constructor({
  3420. eventBus,
  3421. externalLinkTarget = null,
  3422. externalLinkRel = null,
  3423. ignoreDestinationZoom = false
  3424. } = {}) {
  3425. this.eventBus = eventBus;
  3426. this.externalLinkTarget = externalLinkTarget;
  3427. this.externalLinkRel = externalLinkRel;
  3428. this.externalLinkEnabled = true;
  3429. this._ignoreDestinationZoom = ignoreDestinationZoom;
  3430. this.baseUrl = null;
  3431. this.pdfDocument = null;
  3432. this.pdfViewer = null;
  3433. this.pdfHistory = null;
  3434. }
  3435. setDocument(pdfDocument, baseUrl = null) {
  3436. this.baseUrl = baseUrl;
  3437. this.pdfDocument = pdfDocument;
  3438. this.#pagesRefCache.clear();
  3439. }
  3440. setViewer(pdfViewer) {
  3441. this.pdfViewer = pdfViewer;
  3442. }
  3443. setHistory(pdfHistory) {
  3444. this.pdfHistory = pdfHistory;
  3445. }
  3446. get pagesCount() {
  3447. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  3448. }
  3449. get page() {
  3450. return this.pdfViewer.currentPageNumber;
  3451. }
  3452. set page(value) {
  3453. this.pdfViewer.currentPageNumber = value;
  3454. }
  3455. get rotation() {
  3456. return this.pdfViewer.pagesRotation;
  3457. }
  3458. set rotation(value) {
  3459. this.pdfViewer.pagesRotation = value;
  3460. }
  3461. get isInPresentationMode() {
  3462. return this.pdfViewer.isInPresentationMode;
  3463. }
  3464. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  3465. const destRef = explicitDest[0];
  3466. let pageNumber;
  3467. if (typeof destRef === "object" && destRef !== null) {
  3468. pageNumber = this._cachedPageNumber(destRef);
  3469. if (!pageNumber) {
  3470. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  3471. this.cachePageRef(pageIndex + 1, destRef);
  3472. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  3473. }).catch(() => {
  3474. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  3475. });
  3476. return;
  3477. }
  3478. } else if (Number.isInteger(destRef)) {
  3479. pageNumber = destRef + 1;
  3480. } else {
  3481. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  3482. return;
  3483. }
  3484. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  3485. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  3486. return;
  3487. }
  3488. if (this.pdfHistory) {
  3489. this.pdfHistory.pushCurrentPosition();
  3490. this.pdfHistory.push({
  3491. namedDest,
  3492. explicitDest,
  3493. pageNumber
  3494. });
  3495. }
  3496. this.pdfViewer.scrollPageIntoView({
  3497. pageNumber,
  3498. destArray: explicitDest,
  3499. ignoreDestinationZoom: this._ignoreDestinationZoom
  3500. });
  3501. }
  3502. async goToDestination(dest) {
  3503. if (!this.pdfDocument) {
  3504. return;
  3505. }
  3506. let namedDest, explicitDest;
  3507. if (typeof dest === "string") {
  3508. namedDest = dest;
  3509. explicitDest = await this.pdfDocument.getDestination(dest);
  3510. } else {
  3511. namedDest = null;
  3512. explicitDest = await dest;
  3513. }
  3514. if (!Array.isArray(explicitDest)) {
  3515. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  3516. return;
  3517. }
  3518. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  3519. }
  3520. goToPage(val) {
  3521. if (!this.pdfDocument) {
  3522. return;
  3523. }
  3524. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  3525. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  3526. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  3527. return;
  3528. }
  3529. if (this.pdfHistory) {
  3530. this.pdfHistory.pushCurrentPosition();
  3531. this.pdfHistory.pushPage(pageNumber);
  3532. }
  3533. this.pdfViewer.scrollPageIntoView({
  3534. pageNumber
  3535. });
  3536. }
  3537. addLinkAttributes(link, url, newWindow = false) {
  3538. addLinkAttributes(link, {
  3539. url,
  3540. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  3541. rel: this.externalLinkRel,
  3542. enabled: this.externalLinkEnabled
  3543. });
  3544. }
  3545. getDestinationHash(dest) {
  3546. if (typeof dest === "string") {
  3547. if (dest.length > 0) {
  3548. return this.getAnchorUrl("#" + escape(dest));
  3549. }
  3550. } else if (Array.isArray(dest)) {
  3551. const str = JSON.stringify(dest);
  3552. if (str.length > 0) {
  3553. return this.getAnchorUrl("#" + escape(str));
  3554. }
  3555. }
  3556. return this.getAnchorUrl("");
  3557. }
  3558. getAnchorUrl(anchor) {
  3559. return this.baseUrl ? this.baseUrl + anchor : anchor;
  3560. }
  3561. setHash(hash) {
  3562. if (!this.pdfDocument) {
  3563. return;
  3564. }
  3565. let pageNumber, dest;
  3566. if (hash.includes("=")) {
  3567. const params = (0, _ui_utils.parseQueryString)(hash);
  3568. if (params.has("search")) {
  3569. const query = params.get("search").replaceAll('"', ""),
  3570. phrase = params.get("phrase") === "true";
  3571. this.eventBus.dispatch("findfromurlhash", {
  3572. source: this,
  3573. query: phrase ? query : query.match(/\S+/g)
  3574. });
  3575. }
  3576. if (params.has("page")) {
  3577. pageNumber = params.get("page") | 0 || 1;
  3578. }
  3579. if (params.has("zoom")) {
  3580. const zoomArgs = params.get("zoom").split(",");
  3581. const zoomArg = zoomArgs[0];
  3582. const zoomArgNumber = parseFloat(zoomArg);
  3583. if (!zoomArg.includes("Fit")) {
  3584. dest = [null, {
  3585. name: "XYZ"
  3586. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  3587. } else if (zoomArg === "Fit" || zoomArg === "FitB") {
  3588. dest = [null, {
  3589. name: zoomArg
  3590. }];
  3591. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  3592. dest = [null, {
  3593. name: zoomArg
  3594. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  3595. } else if (zoomArg === "FitR") {
  3596. if (zoomArgs.length !== 5) {
  3597. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  3598. } else {
  3599. dest = [null, {
  3600. name: zoomArg
  3601. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  3602. }
  3603. } else {
  3604. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  3605. }
  3606. }
  3607. if (dest) {
  3608. this.pdfViewer.scrollPageIntoView({
  3609. pageNumber: pageNumber || this.page,
  3610. destArray: dest,
  3611. allowNegativeOffset: true
  3612. });
  3613. } else if (pageNumber) {
  3614. this.page = pageNumber;
  3615. }
  3616. if (params.has("pagemode")) {
  3617. this.eventBus.dispatch("pagemode", {
  3618. source: this,
  3619. mode: params.get("pagemode")
  3620. });
  3621. }
  3622. if (params.has("nameddest")) {
  3623. this.goToDestination(params.get("nameddest"));
  3624. }
  3625. } else {
  3626. dest = unescape(hash);
  3627. try {
  3628. dest = JSON.parse(dest);
  3629. if (!Array.isArray(dest)) {
  3630. dest = dest.toString();
  3631. }
  3632. } catch { }
  3633. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  3634. this.goToDestination(dest);
  3635. return;
  3636. }
  3637. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  3638. }
  3639. }
  3640. executeNamedAction(action) {
  3641. switch (action) {
  3642. case "GoBack":
  3643. this.pdfHistory?.back();
  3644. break;
  3645. case "GoForward":
  3646. this.pdfHistory?.forward();
  3647. break;
  3648. case "NextPage":
  3649. this.pdfViewer.nextPage();
  3650. break;
  3651. case "PrevPage":
  3652. this.pdfViewer.previousPage();
  3653. break;
  3654. case "LastPage":
  3655. this.page = this.pagesCount;
  3656. break;
  3657. case "FirstPage":
  3658. this.page = 1;
  3659. break;
  3660. default:
  3661. break;
  3662. }
  3663. this.eventBus.dispatch("namedaction", {
  3664. source: this,
  3665. action
  3666. });
  3667. }
  3668. async executeSetOCGState(action) {
  3669. const pdfDocument = this.pdfDocument;
  3670. const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  3671. if (pdfDocument !== this.pdfDocument) {
  3672. return;
  3673. }
  3674. let operator;
  3675. for (const elem of action.state) {
  3676. switch (elem) {
  3677. case "ON":
  3678. case "OFF":
  3679. case "Toggle":
  3680. operator = elem;
  3681. continue;
  3682. }
  3683. switch (operator) {
  3684. case "ON":
  3685. optionalContentConfig.setVisibility(elem, true);
  3686. break;
  3687. case "OFF":
  3688. optionalContentConfig.setVisibility(elem, false);
  3689. break;
  3690. case "Toggle":
  3691. const group = optionalContentConfig.getGroup(elem);
  3692. if (group) {
  3693. optionalContentConfig.setVisibility(elem, !group.visible);
  3694. }
  3695. break;
  3696. }
  3697. }
  3698. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  3699. }
  3700. cachePageRef(pageNum, pageRef) {
  3701. if (!pageRef) {
  3702. return;
  3703. }
  3704. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3705. this.#pagesRefCache.set(refStr, pageNum);
  3706. }
  3707. _cachedPageNumber(pageRef) {
  3708. if (!pageRef) {
  3709. return null;
  3710. }
  3711. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3712. return this.#pagesRefCache.get(refStr) || null;
  3713. }
  3714. static #isValidExplicitDestination(dest) {
  3715. if (!Array.isArray(dest)) {
  3716. return false;
  3717. }
  3718. const destLength = dest.length;
  3719. if (destLength < 2) {
  3720. return false;
  3721. }
  3722. const page = dest[0];
  3723. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  3724. return false;
  3725. }
  3726. const zoom = dest[1];
  3727. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  3728. return false;
  3729. }
  3730. let allowNull = true;
  3731. switch (zoom.name) {
  3732. case "XYZ":
  3733. if (destLength !== 5) {
  3734. return false;
  3735. }
  3736. break;
  3737. case "Fit":
  3738. case "FitB":
  3739. return destLength === 2;
  3740. case "FitH":
  3741. case "FitBH":
  3742. case "FitV":
  3743. case "FitBV":
  3744. if (destLength !== 3) {
  3745. return false;
  3746. }
  3747. break;
  3748. case "FitR":
  3749. if (destLength !== 6) {
  3750. return false;
  3751. }
  3752. allowNull = false;
  3753. break;
  3754. default:
  3755. return false;
  3756. }
  3757. for (let i = 2; i < destLength; i++) {
  3758. const param = dest[i];
  3759. if (!(typeof param === "number" || allowNull && param === null)) {
  3760. return false;
  3761. }
  3762. }
  3763. return true;
  3764. }
  3765. }
  3766. exports.PDFLinkService = PDFLinkService;
  3767. class SimpleLinkService {
  3768. constructor() {
  3769. this.externalLinkEnabled = true;
  3770. }
  3771. get pagesCount() {
  3772. return 0;
  3773. }
  3774. get page() {
  3775. return 0;
  3776. }
  3777. set page(value) { }
  3778. get rotation() {
  3779. return 0;
  3780. }
  3781. set rotation(value) { }
  3782. get isInPresentationMode() {
  3783. return false;
  3784. }
  3785. async goToDestination(dest) { }
  3786. goToPage(val) { }
  3787. addLinkAttributes(link, url, newWindow = false) {
  3788. addLinkAttributes(link, {
  3789. url,
  3790. enabled: this.externalLinkEnabled
  3791. });
  3792. }
  3793. getDestinationHash(dest) {
  3794. return "#";
  3795. }
  3796. getAnchorUrl(hash) {
  3797. return "#";
  3798. }
  3799. setHash(hash) { }
  3800. executeNamedAction(action) { }
  3801. executeSetOCGState(action) { }
  3802. cachePageRef(pageNum, pageRef) { }
  3803. }
  3804. exports.SimpleLinkService = SimpleLinkService;
  3805. /***/
  3806. }),
  3807. /* 8 */
  3808. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3809. Object.defineProperty(exports, "__esModule", ({
  3810. value: true
  3811. }));
  3812. exports.AnnotationEditorParams = void 0;
  3813. var _pdfjsLib = __webpack_require__(4);
  3814. class AnnotationEditorParams {
  3815. constructor(options, eventBus) {
  3816. this.eventBus = eventBus;
  3817. this.#bindListeners(options);
  3818. }
  3819. #bindListeners({
  3820. editorFreeTextFontSize,
  3821. editorFreeTextColor,
  3822. editorInkColor,
  3823. editorInkThickness,
  3824. editorInkOpacity,
  3825. editorStampAddImage
  3826. }) {
  3827. const dispatchEvent = (typeStr, value) => {
  3828. this.eventBus.dispatch("switchannotationeditorparams", {
  3829. source: this,
  3830. type: _pdfjsLib.AnnotationEditorParamsType[typeStr],
  3831. value
  3832. });
  3833. };
  3834. editorFreeTextFontSize.addEventListener("input", function () {
  3835. dispatchEvent("FREETEXT_SIZE", this.valueAsNumber);
  3836. });
  3837. editorFreeTextColor.addEventListener("input", function () {
  3838. dispatchEvent("FREETEXT_COLOR", this.value);
  3839. });
  3840. editorInkColor.addEventListener("input", function () {
  3841. dispatchEvent("INK_COLOR", this.value);
  3842. });
  3843. editorInkThickness.addEventListener("input", function () {
  3844. dispatchEvent("INK_THICKNESS", this.valueAsNumber);
  3845. });
  3846. editorInkOpacity.addEventListener("input", function () {
  3847. dispatchEvent("INK_OPACITY", this.valueAsNumber);
  3848. });
  3849. editorStampAddImage.addEventListener("click", () => {
  3850. dispatchEvent("CREATE");
  3851. });
  3852. this.eventBus._on("annotationeditorparamschanged", evt => {
  3853. for (const [type, value] of evt.details) {
  3854. switch (type) {
  3855. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  3856. editorFreeTextFontSize.value = value;
  3857. break;
  3858. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  3859. editorFreeTextColor.value = value;
  3860. break;
  3861. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  3862. editorInkColor.value = value;
  3863. break;
  3864. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  3865. editorInkThickness.value = value;
  3866. break;
  3867. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  3868. editorInkOpacity.value = value;
  3869. break;
  3870. }
  3871. }
  3872. });
  3873. }
  3874. }
  3875. exports.AnnotationEditorParams = AnnotationEditorParams;
  3876. /***/
  3877. }),
  3878. /* 9 */
  3879. /***/ ((__unused_webpack_module, exports) => {
  3880. Object.defineProperty(exports, "__esModule", ({
  3881. value: true
  3882. }));
  3883. exports.OverlayManager = void 0;
  3884. class OverlayManager {
  3885. #overlays = new WeakMap();
  3886. #active = null;
  3887. get active() {
  3888. return this.#active;
  3889. }
  3890. async register(dialog, canForceClose = false) {
  3891. if (typeof dialog !== "object") {
  3892. throw new Error("Not enough parameters.");
  3893. } else if (this.#overlays.has(dialog)) {
  3894. throw new Error("The overlay is already registered.");
  3895. }
  3896. this.#overlays.set(dialog, {
  3897. canForceClose
  3898. });
  3899. dialog.addEventListener("cancel", evt => {
  3900. this.#active = null;
  3901. });
  3902. }
  3903. async open(dialog) {
  3904. if (!this.#overlays.has(dialog)) {
  3905. throw new Error("The overlay does not exist.");
  3906. } else if (this.#active) {
  3907. if (this.#active === dialog) {
  3908. throw new Error("The overlay is already active.");
  3909. } else if (this.#overlays.get(dialog).canForceClose) {
  3910. await this.close();
  3911. } else {
  3912. throw new Error("Another overlay is currently active.");
  3913. }
  3914. }
  3915. this.#active = dialog;
  3916. dialog.showModal();
  3917. }
  3918. async close(dialog = this.#active) {
  3919. if (!this.#overlays.has(dialog)) {
  3920. throw new Error("The overlay does not exist.");
  3921. } else if (!this.#active) {
  3922. throw new Error("The overlay is currently not active.");
  3923. } else if (this.#active !== dialog) {
  3924. throw new Error("Another overlay is currently active.");
  3925. }
  3926. dialog.close();
  3927. this.#active = null;
  3928. }
  3929. }
  3930. exports.OverlayManager = OverlayManager;
  3931. /***/
  3932. }),
  3933. /* 10 */
  3934. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3935. Object.defineProperty(exports, "__esModule", ({
  3936. value: true
  3937. }));
  3938. exports.PasswordPrompt = void 0;
  3939. var _pdfjsLib = __webpack_require__(4);
  3940. class PasswordPrompt {
  3941. #activeCapability = null;
  3942. #updateCallback = null;
  3943. #reason = null;
  3944. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3945. this.dialog = options.dialog;
  3946. this.label = options.label;
  3947. this.input = options.input;
  3948. this.submitButton = options.submitButton;
  3949. this.cancelButton = options.cancelButton;
  3950. this.overlayManager = overlayManager;
  3951. this.l10n = l10n;
  3952. this._isViewerEmbedded = isViewerEmbedded;
  3953. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3954. this.cancelButton.addEventListener("click", this.close.bind(this));
  3955. this.input.addEventListener("keydown", e => {
  3956. if (e.keyCode === 13) {
  3957. this.#verify();
  3958. }
  3959. });
  3960. this.overlayManager.register(this.dialog, true);
  3961. this.dialog.addEventListener("close", this.#cancel.bind(this));
  3962. }
  3963. async open() {
  3964. if (this.#activeCapability) {
  3965. await this.#activeCapability.promise;
  3966. }
  3967. this.#activeCapability = new _pdfjsLib.PromiseCapability();
  3968. try {
  3969. await this.overlayManager.open(this.dialog);
  3970. } catch (ex) {
  3971. this.#activeCapability.resolve();
  3972. throw ex;
  3973. }
  3974. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3975. if (!this._isViewerEmbedded || passwordIncorrect) {
  3976. this.input.focus();
  3977. }
  3978. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3979. }
  3980. async close() {
  3981. if (this.overlayManager.active === this.dialog) {
  3982. this.overlayManager.close(this.dialog);
  3983. }
  3984. }
  3985. #verify() {
  3986. const password = this.input.value;
  3987. if (password?.length > 0) {
  3988. this.#invokeCallback(password);
  3989. }
  3990. }
  3991. #cancel() {
  3992. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  3993. this.#activeCapability.resolve();
  3994. }
  3995. #invokeCallback(password) {
  3996. if (!this.#updateCallback) {
  3997. return;
  3998. }
  3999. this.close();
  4000. this.input.value = "";
  4001. this.#updateCallback(password);
  4002. this.#updateCallback = null;
  4003. }
  4004. async setUpdateCallback(updateCallback, reason) {
  4005. if (this.#activeCapability) {
  4006. await this.#activeCapability.promise;
  4007. }
  4008. this.#updateCallback = updateCallback;
  4009. this.#reason = reason;
  4010. }
  4011. }
  4012. exports.PasswordPrompt = PasswordPrompt;
  4013. /***/
  4014. }),
  4015. /* 11 */
  4016. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4017. Object.defineProperty(exports, "__esModule", ({
  4018. value: true
  4019. }));
  4020. exports.PDFAttachmentViewer = void 0;
  4021. var _pdfjsLib = __webpack_require__(4);
  4022. var _base_tree_viewer = __webpack_require__(12);
  4023. var _event_utils = __webpack_require__(6);
  4024. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4025. constructor(options) {
  4026. super(options);
  4027. this.downloadManager = options.downloadManager;
  4028. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  4029. }
  4030. reset(keepRenderedCapability = false) {
  4031. super.reset();
  4032. this._attachments = null;
  4033. if (!keepRenderedCapability) {
  4034. this._renderedCapability = new _pdfjsLib.PromiseCapability();
  4035. }
  4036. this._pendingDispatchEvent = false;
  4037. }
  4038. async _dispatchEvent(attachmentsCount) {
  4039. this._renderedCapability.resolve();
  4040. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4041. this._pendingDispatchEvent = true;
  4042. await (0, _event_utils.waitOnEventOrTimeout)({
  4043. target: this.eventBus,
  4044. name: "annotationlayerrendered",
  4045. delay: 1000
  4046. });
  4047. if (!this._pendingDispatchEvent) {
  4048. return;
  4049. }
  4050. }
  4051. this._pendingDispatchEvent = false;
  4052. this.eventBus.dispatch("attachmentsloaded", {
  4053. source: this,
  4054. attachmentsCount
  4055. });
  4056. }
  4057. _bindLink(element, {
  4058. content,
  4059. filename
  4060. }) {
  4061. element.onclick = () => {
  4062. this.downloadManager.openOrDownloadData(element, content, filename);
  4063. return false;
  4064. };
  4065. }
  4066. render({
  4067. attachments,
  4068. keepRenderedCapability = false
  4069. }) {
  4070. if (this._attachments) {
  4071. this.reset(keepRenderedCapability);
  4072. }
  4073. this._attachments = attachments || null;
  4074. if (!attachments) {
  4075. this._dispatchEvent(0);
  4076. return;
  4077. }
  4078. const fragment = document.createDocumentFragment();
  4079. let attachmentsCount = 0;
  4080. for (const name in attachments) {
  4081. const item = attachments[name];
  4082. const content = item.content,
  4083. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true);
  4084. const div = document.createElement("div");
  4085. div.className = "treeItem";
  4086. const element = document.createElement("a");
  4087. this._bindLink(element, {
  4088. content,
  4089. filename
  4090. });
  4091. element.textContent = this._normalizeTextContent(filename);
  4092. div.append(element);
  4093. fragment.append(div);
  4094. attachmentsCount++;
  4095. }
  4096. this._finishRendering(fragment, attachmentsCount);
  4097. }
  4098. #appendAttachment({
  4099. filename,
  4100. content
  4101. }) {
  4102. const renderedPromise = this._renderedCapability.promise;
  4103. renderedPromise.then(() => {
  4104. if (renderedPromise !== this._renderedCapability.promise) {
  4105. return;
  4106. }
  4107. const attachments = this._attachments || Object.create(null);
  4108. for (const name in attachments) {
  4109. if (filename === name) {
  4110. return;
  4111. }
  4112. }
  4113. attachments[filename] = {
  4114. filename,
  4115. content
  4116. };
  4117. this.render({
  4118. attachments,
  4119. keepRenderedCapability: true
  4120. });
  4121. });
  4122. }
  4123. }
  4124. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4125. /***/
  4126. }),
  4127. /* 12 */
  4128. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4129. Object.defineProperty(exports, "__esModule", ({
  4130. value: true
  4131. }));
  4132. exports.BaseTreeViewer = void 0;
  4133. var _ui_utils = __webpack_require__(3);
  4134. const TREEITEM_OFFSET_TOP = -100;
  4135. const TREEITEM_SELECTED_CLASS = "selected";
  4136. class BaseTreeViewer {
  4137. constructor(options) {
  4138. if (this.constructor === BaseTreeViewer) {
  4139. throw new Error("Cannot initialize BaseTreeViewer.");
  4140. }
  4141. this.container = options.container;
  4142. this.eventBus = options.eventBus;
  4143. this.reset();
  4144. }
  4145. reset() {
  4146. this._pdfDocument = null;
  4147. this._lastToggleIsShow = true;
  4148. this._currentTreeItem = null;
  4149. this.container.textContent = "";
  4150. this.container.classList.remove("treeWithDeepNesting");
  4151. }
  4152. _dispatchEvent(count) {
  4153. throw new Error("Not implemented: _dispatchEvent");
  4154. }
  4155. _bindLink(element, params) {
  4156. throw new Error("Not implemented: _bindLink");
  4157. }
  4158. _normalizeTextContent(str) {
  4159. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4160. }
  4161. _addToggleButton(div, hidden = false) {
  4162. const toggler = document.createElement("div");
  4163. toggler.className = "treeItemToggler";
  4164. if (hidden) {
  4165. toggler.classList.add("treeItemsHidden");
  4166. }
  4167. toggler.onclick = evt => {
  4168. evt.stopPropagation();
  4169. toggler.classList.toggle("treeItemsHidden");
  4170. if (evt.shiftKey) {
  4171. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4172. this._toggleTreeItem(div, shouldShowAll);
  4173. }
  4174. };
  4175. div.prepend(toggler);
  4176. }
  4177. _toggleTreeItem(root, show = false) {
  4178. this._lastToggleIsShow = show;
  4179. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4180. toggler.classList.toggle("treeItemsHidden", !show);
  4181. }
  4182. }
  4183. _toggleAllTreeItems() {
  4184. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4185. }
  4186. _finishRendering(fragment, count, hasAnyNesting = false) {
  4187. if (hasAnyNesting) {
  4188. this.container.classList.add("treeWithDeepNesting");
  4189. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4190. }
  4191. this.container.append(fragment);
  4192. this._dispatchEvent(count);
  4193. }
  4194. render(params) {
  4195. throw new Error("Not implemented: render");
  4196. }
  4197. _updateCurrentTreeItem(treeItem = null) {
  4198. if (this._currentTreeItem) {
  4199. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4200. this._currentTreeItem = null;
  4201. }
  4202. if (treeItem) {
  4203. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4204. this._currentTreeItem = treeItem;
  4205. }
  4206. }
  4207. _scrollToCurrentTreeItem(treeItem) {
  4208. if (!treeItem) {
  4209. return;
  4210. }
  4211. let currentNode = treeItem.parentNode;
  4212. while (currentNode && currentNode !== this.container) {
  4213. if (currentNode.classList.contains("treeItem")) {
  4214. const toggler = currentNode.firstElementChild;
  4215. toggler?.classList.remove("treeItemsHidden");
  4216. }
  4217. currentNode = currentNode.parentNode;
  4218. }
  4219. this._updateCurrentTreeItem(treeItem);
  4220. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4221. }
  4222. }
  4223. exports.BaseTreeViewer = BaseTreeViewer;
  4224. /***/
  4225. }),
  4226. /* 13 */
  4227. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4228. Object.defineProperty(exports, "__esModule", ({
  4229. value: true
  4230. }));
  4231. exports.PDFCursorTools = void 0;
  4232. var _pdfjsLib = __webpack_require__(4);
  4233. var _ui_utils = __webpack_require__(3);
  4234. var _grab_to_pan = __webpack_require__(14);
  4235. class PDFCursorTools {
  4236. #active = _ui_utils.CursorTool.SELECT;
  4237. #prevActive = null;
  4238. constructor({
  4239. container,
  4240. eventBus,
  4241. cursorToolOnLoad = _ui_utils.CursorTool.SELECT
  4242. }) {
  4243. this.container = container;
  4244. this.eventBus = eventBus;
  4245. this.#addEventListeners();
  4246. Promise.resolve().then(() => {
  4247. this.switchTool(cursorToolOnLoad);
  4248. });
  4249. }
  4250. get activeTool() {
  4251. return this.#active;
  4252. }
  4253. switchTool(tool) {
  4254. if (this.#prevActive !== null) {
  4255. return;
  4256. }
  4257. if (tool === this.#active) {
  4258. return;
  4259. }
  4260. const disableActiveTool = () => {
  4261. switch (this.#active) {
  4262. case _ui_utils.CursorTool.SELECT:
  4263. break;
  4264. case _ui_utils.CursorTool.HAND:
  4265. this._handTool.deactivate();
  4266. break;
  4267. case _ui_utils.CursorTool.ZOOM:
  4268. }
  4269. };
  4270. switch (tool) {
  4271. case _ui_utils.CursorTool.SELECT:
  4272. disableActiveTool();
  4273. break;
  4274. case _ui_utils.CursorTool.HAND:
  4275. disableActiveTool();
  4276. this._handTool.activate();
  4277. break;
  4278. case _ui_utils.CursorTool.ZOOM:
  4279. default:
  4280. console.error(`switchTool: "${tool}" is an unsupported value.`);
  4281. return;
  4282. }
  4283. this.#active = tool;
  4284. this.eventBus.dispatch("cursortoolchanged", {
  4285. source: this,
  4286. tool
  4287. });
  4288. }
  4289. #addEventListeners() {
  4290. this.eventBus._on("switchcursortool", evt => {
  4291. this.switchTool(evt.tool);
  4292. });
  4293. let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
  4294. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  4295. const disableActive = () => {
  4296. const prevActive = this.#active;
  4297. this.switchTool(_ui_utils.CursorTool.SELECT);
  4298. this.#prevActive ??= prevActive;
  4299. };
  4300. const enableActive = () => {
  4301. const prevActive = this.#prevActive;
  4302. if (prevActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) {
  4303. this.#prevActive = null;
  4304. this.switchTool(prevActive);
  4305. }
  4306. };
  4307. this.eventBus._on("secondarytoolbarreset", evt => {
  4308. if (this.#prevActive !== null) {
  4309. annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  4310. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  4311. enableActive();
  4312. }
  4313. });
  4314. this.eventBus._on("annotationeditormodechanged", ({
  4315. mode
  4316. }) => {
  4317. annotationEditorMode = mode;
  4318. if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
  4319. enableActive();
  4320. } else {
  4321. disableActive();
  4322. }
  4323. });
  4324. this.eventBus._on("presentationmodechanged", ({
  4325. state
  4326. }) => {
  4327. presentationModeState = state;
  4328. if (state === _ui_utils.PresentationModeState.NORMAL) {
  4329. enableActive();
  4330. } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
  4331. disableActive();
  4332. }
  4333. });
  4334. }
  4335. get _handTool() {
  4336. return (0, _pdfjsLib.shadow)(this, "_handTool", new _grab_to_pan.GrabToPan({
  4337. element: this.container
  4338. }));
  4339. }
  4340. }
  4341. exports.PDFCursorTools = PDFCursorTools;
  4342. /***/
  4343. }),
  4344. /* 14 */
  4345. /***/ ((__unused_webpack_module, exports) => {
  4346. Object.defineProperty(exports, "__esModule", ({
  4347. value: true
  4348. }));
  4349. exports.GrabToPan = void 0;
  4350. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  4351. class GrabToPan {
  4352. constructor({
  4353. element
  4354. }) {
  4355. this.element = element;
  4356. this.document = element.ownerDocument;
  4357. this.activate = this.activate.bind(this);
  4358. this.deactivate = this.deactivate.bind(this);
  4359. this.toggle = this.toggle.bind(this);
  4360. this._onMouseDown = this.#onMouseDown.bind(this);
  4361. this._onMouseMove = this.#onMouseMove.bind(this);
  4362. this._endPan = this.#endPan.bind(this);
  4363. const overlay = this.overlay = document.createElement("div");
  4364. overlay.className = "grab-to-pan-grabbing";
  4365. }
  4366. activate() {
  4367. if (!this.active) {
  4368. this.active = true;
  4369. this.element.addEventListener("mousedown", this._onMouseDown, true);
  4370. this.element.classList.add(CSS_CLASS_GRAB);
  4371. }
  4372. }
  4373. deactivate() {
  4374. if (this.active) {
  4375. this.active = false;
  4376. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  4377. this._endPan();
  4378. this.element.classList.remove(CSS_CLASS_GRAB);
  4379. }
  4380. }
  4381. toggle() {
  4382. if (this.active) {
  4383. this.deactivate();
  4384. } else {
  4385. this.activate();
  4386. }
  4387. }
  4388. ignoreTarget(node) {
  4389. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  4390. }
  4391. #onMouseDown(event) {
  4392. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  4393. return;
  4394. }
  4395. if (event.originalTarget) {
  4396. try {
  4397. event.originalTarget.tagName;
  4398. } catch {
  4399. return;
  4400. }
  4401. }
  4402. this.scrollLeftStart = this.element.scrollLeft;
  4403. this.scrollTopStart = this.element.scrollTop;
  4404. this.clientXStart = event.clientX;
  4405. this.clientYStart = event.clientY;
  4406. this.document.addEventListener("mousemove", this._onMouseMove, true);
  4407. this.document.addEventListener("mouseup", this._endPan, true);
  4408. this.element.addEventListener("scroll", this._endPan, true);
  4409. event.preventDefault();
  4410. event.stopPropagation();
  4411. const focusedElement = document.activeElement;
  4412. if (focusedElement && !focusedElement.contains(event.target)) {
  4413. focusedElement.blur();
  4414. }
  4415. }
  4416. #onMouseMove(event) {
  4417. this.element.removeEventListener("scroll", this._endPan, true);
  4418. if (!(event.buttons & 1)) {
  4419. this._endPan();
  4420. return;
  4421. }
  4422. const xDiff = event.clientX - this.clientXStart;
  4423. const yDiff = event.clientY - this.clientYStart;
  4424. this.element.scrollTo({
  4425. top: this.scrollTopStart - yDiff,
  4426. left: this.scrollLeftStart - xDiff,
  4427. behavior: "instant"
  4428. });
  4429. if (!this.overlay.parentNode) {
  4430. document.body.append(this.overlay);
  4431. }
  4432. }
  4433. #endPan() {
  4434. this.element.removeEventListener("scroll", this._endPan, true);
  4435. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  4436. this.document.removeEventListener("mouseup", this._endPan, true);
  4437. this.overlay.remove();
  4438. }
  4439. }
  4440. exports.GrabToPan = GrabToPan;
  4441. /***/
  4442. }),
  4443. /* 15 */
  4444. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4445. Object.defineProperty(exports, "__esModule", ({
  4446. value: true
  4447. }));
  4448. exports.PDFDocumentProperties = void 0;
  4449. var _ui_utils = __webpack_require__(3);
  4450. var _pdfjsLib = __webpack_require__(4);
  4451. const DEFAULT_FIELD_CONTENT = "-";
  4452. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4453. const US_PAGE_NAMES = {
  4454. "8.5x11": "Letter",
  4455. "8.5x14": "Legal"
  4456. };
  4457. const METRIC_PAGE_NAMES = {
  4458. "297x420": "A3",
  4459. "210x297": "A4"
  4460. };
  4461. function getPageName(size, isPortrait, pageNames) {
  4462. const width = isPortrait ? size.width : size.height;
  4463. const height = isPortrait ? size.height : size.width;
  4464. return pageNames[`${width}x${height}`];
  4465. }
  4466. class PDFDocumentProperties {
  4467. #fieldData = null;
  4468. constructor({
  4469. dialog,
  4470. fields,
  4471. closeButton
  4472. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4473. this.dialog = dialog;
  4474. this.fields = fields;
  4475. this.overlayManager = overlayManager;
  4476. this.l10n = l10n;
  4477. this._fileNameLookup = fileNameLookup;
  4478. this.#reset();
  4479. closeButton.addEventListener("click", this.close.bind(this));
  4480. this.overlayManager.register(this.dialog);
  4481. eventBus._on("pagechanging", evt => {
  4482. this._currentPageNumber = evt.pageNumber;
  4483. });
  4484. eventBus._on("rotationchanging", evt => {
  4485. this._pagesRotation = evt.pagesRotation;
  4486. });
  4487. this._isNonMetricLocale = true;
  4488. l10n.getLanguage().then(locale => {
  4489. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4490. });
  4491. }
  4492. async open() {
  4493. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4494. const currentPageNumber = this._currentPageNumber;
  4495. const pagesRotation = this._pagesRotation;
  4496. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4497. this.#updateUI();
  4498. return;
  4499. }
  4500. const {
  4501. info,
  4502. contentLength
  4503. } = await this.pdfDocument.getMetadata();
  4504. 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 => {
  4505. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4506. }), this.#parseLinearization(info.IsLinearized)]);
  4507. this.#fieldData = Object.freeze({
  4508. fileName,
  4509. fileSize,
  4510. title: info.Title,
  4511. author: info.Author,
  4512. subject: info.Subject,
  4513. keywords: info.Keywords,
  4514. creationDate,
  4515. modificationDate,
  4516. creator: info.Creator,
  4517. producer: info.Producer,
  4518. version: info.PDFFormatVersion,
  4519. pageCount: this.pdfDocument.numPages,
  4520. pageSize,
  4521. linearized: isLinearized,
  4522. _currentPageNumber: currentPageNumber,
  4523. _pagesRotation: pagesRotation
  4524. });
  4525. this.#updateUI();
  4526. const {
  4527. length
  4528. } = await this.pdfDocument.getDownloadInfo();
  4529. if (contentLength === length) {
  4530. return;
  4531. }
  4532. const data = Object.assign(Object.create(null), this.#fieldData);
  4533. data.fileSize = await this.#parseFileSize(length);
  4534. this.#fieldData = Object.freeze(data);
  4535. this.#updateUI();
  4536. }
  4537. async close() {
  4538. this.overlayManager.close(this.dialog);
  4539. }
  4540. setDocument(pdfDocument) {
  4541. if (this.pdfDocument) {
  4542. this.#reset();
  4543. this.#updateUI(true);
  4544. }
  4545. if (!pdfDocument) {
  4546. return;
  4547. }
  4548. this.pdfDocument = pdfDocument;
  4549. this._dataAvailableCapability.resolve();
  4550. }
  4551. #reset() {
  4552. this.pdfDocument = null;
  4553. this.#fieldData = null;
  4554. this._dataAvailableCapability = new _pdfjsLib.PromiseCapability();
  4555. this._currentPageNumber = 1;
  4556. this._pagesRotation = 0;
  4557. }
  4558. #updateUI(reset = false) {
  4559. if (reset || !this.#fieldData) {
  4560. for (const id in this.fields) {
  4561. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4562. }
  4563. return;
  4564. }
  4565. if (this.overlayManager.active !== this.dialog) {
  4566. return;
  4567. }
  4568. for (const id in this.fields) {
  4569. const content = this.#fieldData[id];
  4570. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4571. }
  4572. }
  4573. async #parseFileSize(fileSize = 0) {
  4574. const kb = fileSize / 1024,
  4575. mb = kb / 1024;
  4576. if (!kb) {
  4577. return undefined;
  4578. }
  4579. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4580. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4581. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4582. size_b: fileSize.toLocaleString()
  4583. });
  4584. }
  4585. async #parsePageSize(pageSizeInches, pagesRotation) {
  4586. if (!pageSizeInches) {
  4587. return undefined;
  4588. }
  4589. if (pagesRotation % 180 !== 0) {
  4590. pageSizeInches = {
  4591. width: pageSizeInches.height,
  4592. height: pageSizeInches.width
  4593. };
  4594. }
  4595. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4596. let sizeInches = {
  4597. width: Math.round(pageSizeInches.width * 100) / 100,
  4598. height: Math.round(pageSizeInches.height * 100) / 100
  4599. };
  4600. let sizeMillimeters = {
  4601. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4602. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4603. };
  4604. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4605. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4606. const exactMillimeters = {
  4607. width: pageSizeInches.width * 25.4,
  4608. height: pageSizeInches.height * 25.4
  4609. };
  4610. const intMillimeters = {
  4611. width: Math.round(sizeMillimeters.width),
  4612. height: Math.round(sizeMillimeters.height)
  4613. };
  4614. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4615. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4616. if (rawName) {
  4617. sizeInches = {
  4618. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4619. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4620. };
  4621. sizeMillimeters = intMillimeters;
  4622. }
  4623. }
  4624. }
  4625. const [{
  4626. width,
  4627. height
  4628. }, 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"}`)]);
  4629. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4630. width: width.toLocaleString(),
  4631. height: height.toLocaleString(),
  4632. unit,
  4633. name,
  4634. orientation
  4635. });
  4636. }
  4637. async #parseDate(inputDate) {
  4638. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4639. if (!dateObject) {
  4640. return undefined;
  4641. }
  4642. return this.l10n.get("document_properties_date_string", {
  4643. date: dateObject.toLocaleDateString(),
  4644. time: dateObject.toLocaleTimeString()
  4645. });
  4646. }
  4647. #parseLinearization(isLinearized) {
  4648. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4649. }
  4650. }
  4651. exports.PDFDocumentProperties = PDFDocumentProperties;
  4652. /***/
  4653. }),
  4654. /* 16 */
  4655. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4656. Object.defineProperty(exports, "__esModule", ({
  4657. value: true
  4658. }));
  4659. exports.PDFFindBar = void 0;
  4660. var _pdf_find_controller = __webpack_require__(17);
  4661. var _ui_utils = __webpack_require__(3);
  4662. const MATCHES_COUNT_LIMIT = 1000;
  4663. class PDFFindBar {
  4664. constructor(options, eventBus, l10n) {
  4665. this.opened = false;
  4666. this.bar = options.bar;
  4667. this.toggleButton = options.toggleButton;
  4668. this.findField = options.findField;
  4669. this.highlightAll = options.highlightAllCheckbox;
  4670. this.caseSensitive = options.caseSensitiveCheckbox;
  4671. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4672. this.entireWord = options.entireWordCheckbox;
  4673. this.findMsg = options.findMsg;
  4674. this.findResultsCount = options.findResultsCount;
  4675. this.findPreviousButton = options.findPreviousButton;
  4676. this.findNextButton = options.findNextButton;
  4677. this.eventBus = eventBus;
  4678. this.l10n = l10n;
  4679. this.toggleButton.addEventListener("click", () => {
  4680. this.toggle();
  4681. });
  4682. this.findField.addEventListener("input", () => {
  4683. this.dispatchEvent("");
  4684. });
  4685. this.bar.addEventListener("keydown", e => {
  4686. switch (e.keyCode) {
  4687. case 13:
  4688. if (e.target === this.findField) {
  4689. this.dispatchEvent("again", e.shiftKey);
  4690. }
  4691. break;
  4692. case 27:
  4693. this.close();
  4694. break;
  4695. }
  4696. });
  4697. this.findPreviousButton.addEventListener("click", () => {
  4698. this.dispatchEvent("again", true);
  4699. });
  4700. this.findNextButton.addEventListener("click", () => {
  4701. this.dispatchEvent("again", false);
  4702. });
  4703. this.highlightAll.addEventListener("click", () => {
  4704. this.dispatchEvent("highlightallchange");
  4705. });
  4706. this.caseSensitive.addEventListener("click", () => {
  4707. this.dispatchEvent("casesensitivitychange");
  4708. });
  4709. this.entireWord.addEventListener("click", () => {
  4710. this.dispatchEvent("entirewordchange");
  4711. });
  4712. this.matchDiacritics.addEventListener("click", () => {
  4713. this.dispatchEvent("diacriticmatchingchange");
  4714. });
  4715. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4716. }
  4717. reset() {
  4718. this.updateUIState();
  4719. }
  4720. dispatchEvent(type, findPrev = false) {
  4721. this.eventBus.dispatch("find", {
  4722. source: this,
  4723. type,
  4724. query: this.findField.value,
  4725. caseSensitive: this.caseSensitive.checked,
  4726. entireWord: this.entireWord.checked,
  4727. highlightAll: this.highlightAll.checked,
  4728. findPrevious: findPrev,
  4729. matchDiacritics: this.matchDiacritics.checked
  4730. });
  4731. }
  4732. updateUIState(state, previous, matchesCount) {
  4733. let findMsg = Promise.resolve("");
  4734. let status = "";
  4735. switch (state) {
  4736. case _pdf_find_controller.FindState.FOUND:
  4737. break;
  4738. case _pdf_find_controller.FindState.PENDING:
  4739. status = "pending";
  4740. break;
  4741. case _pdf_find_controller.FindState.NOT_FOUND:
  4742. findMsg = this.l10n.get("find_not_found");
  4743. status = "notFound";
  4744. break;
  4745. case _pdf_find_controller.FindState.WRAPPED:
  4746. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4747. break;
  4748. }
  4749. this.findField.setAttribute("data-status", status);
  4750. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4751. findMsg.then(msg => {
  4752. this.findMsg.setAttribute("data-status", status);
  4753. this.findMsg.textContent = msg;
  4754. this.#adjustWidth();
  4755. });
  4756. this.updateResultsCount(matchesCount);
  4757. }
  4758. updateResultsCount({
  4759. current = 0,
  4760. total = 0
  4761. } = {}) {
  4762. const limit = MATCHES_COUNT_LIMIT;
  4763. let matchCountMsg = Promise.resolve("");
  4764. if (total > 0) {
  4765. if (total > limit) {
  4766. let key = "find_match_count_limit";
  4767. matchCountMsg = this.l10n.get(key, {
  4768. limit
  4769. });
  4770. } else {
  4771. let key = "find_match_count";
  4772. matchCountMsg = this.l10n.get(key, {
  4773. current,
  4774. total
  4775. });
  4776. }
  4777. }
  4778. matchCountMsg.then(msg => {
  4779. this.findResultsCount.textContent = msg;
  4780. this.#adjustWidth();
  4781. });
  4782. }
  4783. open() {
  4784. if (!this.opened) {
  4785. this.opened = true;
  4786. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true, this.bar);
  4787. }
  4788. this.findField.select();
  4789. this.findField.focus();
  4790. this.#adjustWidth();
  4791. }
  4792. close() {
  4793. if (!this.opened) {
  4794. return;
  4795. }
  4796. this.opened = false;
  4797. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false, this.bar);
  4798. this.eventBus.dispatch("findbarclose", {
  4799. source: this
  4800. });
  4801. }
  4802. toggle() {
  4803. if (this.opened) {
  4804. this.close();
  4805. } else {
  4806. this.open();
  4807. }
  4808. }
  4809. #adjustWidth() {
  4810. if (!this.opened) {
  4811. return;
  4812. }
  4813. this.bar.classList.remove("wrapContainers");
  4814. const findbarHeight = this.bar.clientHeight;
  4815. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4816. if (findbarHeight > inputContainerHeight) {
  4817. this.bar.classList.add("wrapContainers");
  4818. }
  4819. }
  4820. }
  4821. exports.PDFFindBar = PDFFindBar;
  4822. /***/
  4823. }),
  4824. /* 17 */
  4825. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4826. Object.defineProperty(exports, "__esModule", ({
  4827. value: true
  4828. }));
  4829. exports.PDFFindController = exports.FindState = void 0;
  4830. var _ui_utils = __webpack_require__(3);
  4831. var _pdf_find_utils = __webpack_require__(18);
  4832. var _pdfjsLib = __webpack_require__(4);
  4833. const FindState = {
  4834. FOUND: 0,
  4835. NOT_FOUND: 1,
  4836. WRAPPED: 2,
  4837. PENDING: 3
  4838. };
  4839. exports.FindState = FindState;
  4840. const FIND_TIMEOUT = 250;
  4841. const MATCH_SCROLL_OFFSET_TOP = -50;
  4842. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4843. const CHARACTERS_TO_NORMALIZE = {
  4844. "\u2010": "-",
  4845. "\u2018": "'",
  4846. "\u2019": "'",
  4847. "\u201A": "'",
  4848. "\u201B": "'",
  4849. "\u201C": '"',
  4850. "\u201D": '"',
  4851. "\u201E": '"',
  4852. "\u201F": '"',
  4853. "\u00BC": "1/4",
  4854. "\u00BD": "1/2",
  4855. "\u00BE": "3/4"
  4856. };
  4857. 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]);
  4858. let DIACRITICS_EXCEPTION_STR;
  4859. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4860. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4861. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4862. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4863. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4864. const SYLLABLES_LENGTHS = new Map();
  4865. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4866. const NFKC_CHARS_TO_NORMALIZE = new Map();
  4867. let noSyllablesRegExp = null;
  4868. let withSyllablesRegExp = null;
  4869. function normalize(text) {
  4870. const syllablePositions = [];
  4871. let m;
  4872. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4873. let {
  4874. index
  4875. } = m;
  4876. for (const char of m[0]) {
  4877. let len = SYLLABLES_LENGTHS.get(char);
  4878. if (!len) {
  4879. len = char.normalize("NFD").length;
  4880. SYLLABLES_LENGTHS.set(char, len);
  4881. }
  4882. syllablePositions.push([len, index++]);
  4883. }
  4884. }
  4885. let normalizationRegex;
  4886. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4887. normalizationRegex = noSyllablesRegExp;
  4888. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4889. normalizationRegex = withSyllablesRegExp;
  4890. } else {
  4891. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4892. const toNormalizeWithNFKC = (0, _pdf_find_utils.getNormalizeWithNFKC)();
  4893. const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
  4894. const HKDiacritics = "(?:\u3099|\u309A)";
  4895. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(${HKDiacritics}\\n)|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
  4896. if (syllablePositions.length === 0) {
  4897. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4898. } else {
  4899. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4900. }
  4901. }
  4902. const rawDiacriticsPositions = [];
  4903. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4904. rawDiacriticsPositions.push([m[0].length, m.index]);
  4905. }
  4906. let normalized = text.normalize("NFD");
  4907. const positions = [[0, 0]];
  4908. let rawDiacriticsIndex = 0;
  4909. let syllableIndex = 0;
  4910. let shift = 0;
  4911. let shiftOrigin = 0;
  4912. let eol = 0;
  4913. let hasDiacritics = false;
  4914. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, p8, i) => {
  4915. i -= shiftOrigin;
  4916. if (p1) {
  4917. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  4918. const jj = replacement.length;
  4919. for (let j = 1; j < jj; j++) {
  4920. positions.push([i - shift + j, shift - j]);
  4921. }
  4922. shift -= jj - 1;
  4923. return replacement;
  4924. }
  4925. if (p2) {
  4926. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  4927. if (!replacement) {
  4928. replacement = p2.normalize("NFKC");
  4929. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  4930. }
  4931. const jj = replacement.length;
  4932. for (let j = 1; j < jj; j++) {
  4933. positions.push([i - shift + j, shift - j]);
  4934. }
  4935. shift -= jj - 1;
  4936. return replacement;
  4937. }
  4938. if (p3) {
  4939. hasDiacritics = true;
  4940. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4941. ++rawDiacriticsIndex;
  4942. } else {
  4943. positions.push([i - 1 - shift + 1, shift - 1]);
  4944. shift -= 1;
  4945. shiftOrigin += 1;
  4946. }
  4947. positions.push([i - shift + 1, shift]);
  4948. shiftOrigin += 1;
  4949. eol += 1;
  4950. return p3.charAt(0);
  4951. }
  4952. if (p4) {
  4953. const hasTrailingDashEOL = p4.endsWith("\n");
  4954. const len = hasTrailingDashEOL ? p4.length - 2 : p4.length;
  4955. hasDiacritics = true;
  4956. let jj = len;
  4957. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4958. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4959. ++rawDiacriticsIndex;
  4960. }
  4961. for (let j = 1; j <= jj; j++) {
  4962. positions.push([i - 1 - shift + j, shift - j]);
  4963. }
  4964. shift -= jj;
  4965. shiftOrigin += jj;
  4966. if (hasTrailingDashEOL) {
  4967. i += len - 1;
  4968. positions.push([i - shift + 1, 1 + shift]);
  4969. shift += 1;
  4970. shiftOrigin += 1;
  4971. eol += 1;
  4972. return p4.slice(0, len);
  4973. }
  4974. return p4;
  4975. }
  4976. if (p5) {
  4977. const len = p5.length - 2;
  4978. positions.push([i - shift + len, 1 + shift]);
  4979. shift += 1;
  4980. shiftOrigin += 1;
  4981. eol += 1;
  4982. return p5.slice(0, -2);
  4983. }
  4984. if (p6) {
  4985. const len = p6.length - 1;
  4986. positions.push([i - shift + len, shift]);
  4987. shiftOrigin += 1;
  4988. eol += 1;
  4989. return p6.slice(0, -1);
  4990. }
  4991. if (p7) {
  4992. positions.push([i - shift + 1, shift - 1]);
  4993. shift -= 1;
  4994. shiftOrigin += 1;
  4995. eol += 1;
  4996. return " ";
  4997. }
  4998. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  4999. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  5000. ++syllableIndex;
  5001. for (let j = 1; j <= newCharLen; j++) {
  5002. positions.push([i - (shift - j), shift - j]);
  5003. }
  5004. shift -= newCharLen;
  5005. shiftOrigin += newCharLen;
  5006. }
  5007. return p8;
  5008. });
  5009. positions.push([normalized.length, shift]);
  5010. return [normalized, positions, hasDiacritics];
  5011. }
  5012. function getOriginalIndex(diffs, pos, len) {
  5013. if (!diffs) {
  5014. return [pos, len];
  5015. }
  5016. const start = pos;
  5017. const end = pos + len - 1;
  5018. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  5019. if (diffs[i][0] > start) {
  5020. --i;
  5021. }
  5022. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  5023. if (diffs[j][0] > end) {
  5024. --j;
  5025. }
  5026. const oldStart = start + diffs[i][1];
  5027. const oldEnd = end + diffs[j][1];
  5028. const oldLen = oldEnd + 1 - oldStart;
  5029. return [oldStart, oldLen];
  5030. }
  5031. class PDFFindController {
  5032. #state = null;
  5033. #updateMatchesCountOnProgress = true;
  5034. #visitedPagesCount = 0;
  5035. constructor({
  5036. linkService,
  5037. eventBus,
  5038. updateMatchesCountOnProgress = true
  5039. }) {
  5040. this._linkService = linkService;
  5041. this._eventBus = eventBus;
  5042. this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
  5043. this.onIsPageVisible = null;
  5044. this.#reset();
  5045. eventBus._on("find", this.#onFind.bind(this));
  5046. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  5047. }
  5048. get highlightMatches() {
  5049. return this._highlightMatches;
  5050. }
  5051. get pageMatches() {
  5052. return this._pageMatches;
  5053. }
  5054. get pageMatchesLength() {
  5055. return this._pageMatchesLength;
  5056. }
  5057. get selected() {
  5058. return this._selected;
  5059. }
  5060. get state() {
  5061. return this.#state;
  5062. }
  5063. setDocument(pdfDocument) {
  5064. if (this._pdfDocument) {
  5065. this.#reset();
  5066. }
  5067. if (!pdfDocument) {
  5068. return;
  5069. }
  5070. this._pdfDocument = pdfDocument;
  5071. this._firstPageCapability.resolve();
  5072. }
  5073. #onFind(state) {
  5074. if (!state) {
  5075. return;
  5076. }
  5077. if (state.phraseSearch === false) {
  5078. console.error("The `phraseSearch`-parameter was removed, please provide " + "an Array of strings in the `query`-parameter instead.");
  5079. if (typeof state.query === "string") {
  5080. state.query = state.query.match(/\S+/g);
  5081. }
  5082. }
  5083. const pdfDocument = this._pdfDocument;
  5084. const {
  5085. type
  5086. } = state;
  5087. if (this.#state === null || this.#shouldDirtyMatch(state)) {
  5088. this._dirtyMatch = true;
  5089. }
  5090. this.#state = state;
  5091. if (type !== "highlightallchange") {
  5092. this.#updateUIState(FindState.PENDING);
  5093. }
  5094. this._firstPageCapability.promise.then(() => {
  5095. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5096. return;
  5097. }
  5098. this.#extractText();
  5099. const findbarClosed = !this._highlightMatches;
  5100. const pendingTimeout = !!this._findTimeout;
  5101. if (this._findTimeout) {
  5102. clearTimeout(this._findTimeout);
  5103. this._findTimeout = null;
  5104. }
  5105. if (!type) {
  5106. this._findTimeout = setTimeout(() => {
  5107. this.#nextMatch();
  5108. this._findTimeout = null;
  5109. }, FIND_TIMEOUT);
  5110. } else if (this._dirtyMatch) {
  5111. this.#nextMatch();
  5112. } else if (type === "again") {
  5113. this.#nextMatch();
  5114. if (findbarClosed && this.#state.highlightAll) {
  5115. this.#updateAllPages();
  5116. }
  5117. } else if (type === "highlightallchange") {
  5118. if (pendingTimeout) {
  5119. this.#nextMatch();
  5120. } else {
  5121. this._highlightMatches = true;
  5122. }
  5123. this.#updateAllPages();
  5124. } else {
  5125. this.#nextMatch();
  5126. }
  5127. });
  5128. }
  5129. scrollMatchIntoView({
  5130. element = null,
  5131. selectedLeft = 0,
  5132. pageIndex = -1,
  5133. matchIndex = -1
  5134. }) {
  5135. if (!this._scrollMatches || !element) {
  5136. return;
  5137. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  5138. return;
  5139. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5140. return;
  5141. }
  5142. this._scrollMatches = false;
  5143. const spot = {
  5144. top: MATCH_SCROLL_OFFSET_TOP,
  5145. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  5146. };
  5147. (0, _ui_utils.scrollIntoView)(element, spot, true);
  5148. }
  5149. #reset() {
  5150. this._highlightMatches = false;
  5151. this._scrollMatches = false;
  5152. this._pdfDocument = null;
  5153. this._pageMatches = [];
  5154. this._pageMatchesLength = [];
  5155. this.#visitedPagesCount = 0;
  5156. this.#state = null;
  5157. this._selected = {
  5158. pageIdx: -1,
  5159. matchIdx: -1
  5160. };
  5161. this._offset = {
  5162. pageIdx: null,
  5163. matchIdx: null,
  5164. wrapped: false
  5165. };
  5166. this._extractTextPromises = [];
  5167. this._pageContents = [];
  5168. this._pageDiffs = [];
  5169. this._hasDiacritics = [];
  5170. this._matchesCountTotal = 0;
  5171. this._pagesToSearch = null;
  5172. this._pendingFindMatches = new Set();
  5173. this._resumePageIdx = null;
  5174. this._dirtyMatch = false;
  5175. clearTimeout(this._findTimeout);
  5176. this._findTimeout = null;
  5177. this._firstPageCapability = new _pdfjsLib.PromiseCapability();
  5178. }
  5179. get #query() {
  5180. const {
  5181. query
  5182. } = this.#state;
  5183. if (typeof query === "string") {
  5184. if (query !== this._rawQuery) {
  5185. this._rawQuery = query;
  5186. [this._normalizedQuery] = normalize(query);
  5187. }
  5188. return this._normalizedQuery;
  5189. }
  5190. return (query || []).filter(q => !!q).map(q => normalize(q)[0]);
  5191. }
  5192. #shouldDirtyMatch(state) {
  5193. const newQuery = state.query,
  5194. prevQuery = this.#state.query;
  5195. const newType = typeof newQuery,
  5196. prevType = typeof prevQuery;
  5197. if (newType !== prevType) {
  5198. return true;
  5199. }
  5200. if (newType === "string") {
  5201. if (newQuery !== prevQuery) {
  5202. return true;
  5203. }
  5204. } else if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) {
  5205. return true;
  5206. }
  5207. switch (state.type) {
  5208. case "again":
  5209. const pageNumber = this._selected.pageIdx + 1;
  5210. const linkService = this._linkService;
  5211. return pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !(this.onIsPageVisible?.(pageNumber) ?? true);
  5212. case "highlightallchange":
  5213. return false;
  5214. }
  5215. return true;
  5216. }
  5217. #isEntireWord(content, startIdx, length) {
  5218. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  5219. if (match) {
  5220. const first = content.charCodeAt(startIdx);
  5221. const limit = match[1].charCodeAt(0);
  5222. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5223. return false;
  5224. }
  5225. }
  5226. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  5227. if (match) {
  5228. const last = content.charCodeAt(startIdx + length - 1);
  5229. const limit = match[1].charCodeAt(0);
  5230. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5231. return false;
  5232. }
  5233. }
  5234. return true;
  5235. }
  5236. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  5237. const matches = this._pageMatches[pageIndex] = [];
  5238. const matchesLength = this._pageMatchesLength[pageIndex] = [];
  5239. if (!query) {
  5240. return;
  5241. }
  5242. const diffs = this._pageDiffs[pageIndex];
  5243. let match;
  5244. while ((match = query.exec(pageContent)) !== null) {
  5245. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  5246. continue;
  5247. }
  5248. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  5249. if (matchLen) {
  5250. matches.push(matchPos);
  5251. matchesLength.push(matchLen);
  5252. }
  5253. }
  5254. }
  5255. #convertToRegExpString(query, hasDiacritics) {
  5256. const {
  5257. matchDiacritics
  5258. } = this.#state;
  5259. let isUnicode = false;
  5260. query = query.replaceAll(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5261. if (p1) {
  5262. return `[ ]*\\${p1}[ ]*`;
  5263. }
  5264. if (p2) {
  5265. return `[ ]*${p2}[ ]*`;
  5266. }
  5267. if (p3) {
  5268. return "[ ]+";
  5269. }
  5270. if (matchDiacritics) {
  5271. return p4 || p5;
  5272. }
  5273. if (p4) {
  5274. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5275. }
  5276. if (hasDiacritics) {
  5277. isUnicode = true;
  5278. return `${p5}\\p{M}*`;
  5279. }
  5280. return p5;
  5281. });
  5282. const trailingSpaces = "[ ]*";
  5283. if (query.endsWith(trailingSpaces)) {
  5284. query = query.slice(0, query.length - trailingSpaces.length);
  5285. }
  5286. if (matchDiacritics) {
  5287. if (hasDiacritics) {
  5288. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
  5289. isUnicode = true;
  5290. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5291. }
  5292. }
  5293. return [isUnicode, query];
  5294. }
  5295. #calculateMatch(pageIndex) {
  5296. let query = this.#query;
  5297. if (query.length === 0) {
  5298. return;
  5299. }
  5300. const {
  5301. caseSensitive,
  5302. entireWord
  5303. } = this.#state;
  5304. const pageContent = this._pageContents[pageIndex];
  5305. const hasDiacritics = this._hasDiacritics[pageIndex];
  5306. let isUnicode = false;
  5307. if (typeof query === "string") {
  5308. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5309. } else {
  5310. query = query.sort().reverse().map(q => {
  5311. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5312. isUnicode ||= isUnicodePart;
  5313. return `(${queryPart})`;
  5314. }).join("|");
  5315. }
  5316. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5317. query = query ? new RegExp(query, flags) : null;
  5318. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  5319. if (this.#state.highlightAll) {
  5320. this.#updatePage(pageIndex);
  5321. }
  5322. if (this._resumePageIdx === pageIndex) {
  5323. this._resumePageIdx = null;
  5324. this.#nextPageMatch();
  5325. }
  5326. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5327. this._matchesCountTotal += pageMatchesCount;
  5328. if (this.#updateMatchesCountOnProgress) {
  5329. if (pageMatchesCount > 0) {
  5330. this.#updateUIResultsCount();
  5331. }
  5332. } else if (++this.#visitedPagesCount === this._linkService.pagesCount) {
  5333. this.#updateUIResultsCount();
  5334. }
  5335. }
  5336. #extractText() {
  5337. if (this._extractTextPromises.length > 0) {
  5338. return;
  5339. }
  5340. let promise = Promise.resolve();
  5341. const textOptions = {
  5342. disableNormalization: true
  5343. };
  5344. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5345. const extractTextCapability = new _pdfjsLib.PromiseCapability();
  5346. this._extractTextPromises[i] = extractTextCapability.promise;
  5347. promise = promise.then(() => {
  5348. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5349. return pdfPage.getTextContent(textOptions);
  5350. }).then(textContent => {
  5351. const strBuf = [];
  5352. for (const textItem of textContent.items) {
  5353. strBuf.push(textItem.str);
  5354. if (textItem.hasEOL) {
  5355. strBuf.push("\n");
  5356. }
  5357. }
  5358. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5359. extractTextCapability.resolve();
  5360. }, reason => {
  5361. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5362. this._pageContents[i] = "";
  5363. this._pageDiffs[i] = null;
  5364. this._hasDiacritics[i] = false;
  5365. extractTextCapability.resolve();
  5366. });
  5367. });
  5368. }
  5369. }
  5370. #updatePage(index) {
  5371. if (this._scrollMatches && this._selected.pageIdx === index) {
  5372. this._linkService.page = index + 1;
  5373. }
  5374. this._eventBus.dispatch("updatetextlayermatches", {
  5375. source: this,
  5376. pageIndex: index
  5377. });
  5378. }
  5379. #updateAllPages() {
  5380. this._eventBus.dispatch("updatetextlayermatches", {
  5381. source: this,
  5382. pageIndex: -1
  5383. });
  5384. }
  5385. #nextMatch() {
  5386. const previous = this.#state.findPrevious;
  5387. const currentPageIndex = this._linkService.page - 1;
  5388. const numPages = this._linkService.pagesCount;
  5389. this._highlightMatches = true;
  5390. if (this._dirtyMatch) {
  5391. this._dirtyMatch = false;
  5392. this._selected.pageIdx = this._selected.matchIdx = -1;
  5393. this._offset.pageIdx = currentPageIndex;
  5394. this._offset.matchIdx = null;
  5395. this._offset.wrapped = false;
  5396. this._resumePageIdx = null;
  5397. this._pageMatches.length = 0;
  5398. this._pageMatchesLength.length = 0;
  5399. this.#visitedPagesCount = 0;
  5400. this._matchesCountTotal = 0;
  5401. this.#updateAllPages();
  5402. for (let i = 0; i < numPages; i++) {
  5403. if (this._pendingFindMatches.has(i)) {
  5404. continue;
  5405. }
  5406. this._pendingFindMatches.add(i);
  5407. this._extractTextPromises[i].then(() => {
  5408. this._pendingFindMatches.delete(i);
  5409. this.#calculateMatch(i);
  5410. });
  5411. }
  5412. }
  5413. const query = this.#query;
  5414. if (query.length === 0) {
  5415. this.#updateUIState(FindState.FOUND);
  5416. return;
  5417. }
  5418. if (this._resumePageIdx) {
  5419. return;
  5420. }
  5421. const offset = this._offset;
  5422. this._pagesToSearch = numPages;
  5423. if (offset.matchIdx !== null) {
  5424. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5425. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5426. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5427. this.#updateMatch(true);
  5428. return;
  5429. }
  5430. this.#advanceOffsetPage(previous);
  5431. }
  5432. this.#nextPageMatch();
  5433. }
  5434. #matchesReady(matches) {
  5435. const offset = this._offset;
  5436. const numMatches = matches.length;
  5437. const previous = this.#state.findPrevious;
  5438. if (numMatches) {
  5439. offset.matchIdx = previous ? numMatches - 1 : 0;
  5440. this.#updateMatch(true);
  5441. return true;
  5442. }
  5443. this.#advanceOffsetPage(previous);
  5444. if (offset.wrapped) {
  5445. offset.matchIdx = null;
  5446. if (this._pagesToSearch < 0) {
  5447. this.#updateMatch(false);
  5448. return true;
  5449. }
  5450. }
  5451. return false;
  5452. }
  5453. #nextPageMatch() {
  5454. if (this._resumePageIdx !== null) {
  5455. console.error("There can only be one pending page.");
  5456. }
  5457. let matches = null;
  5458. do {
  5459. const pageIdx = this._offset.pageIdx;
  5460. matches = this._pageMatches[pageIdx];
  5461. if (!matches) {
  5462. this._resumePageIdx = pageIdx;
  5463. break;
  5464. }
  5465. } while (!this.#matchesReady(matches));
  5466. }
  5467. #advanceOffsetPage(previous) {
  5468. const offset = this._offset;
  5469. const numPages = this._linkService.pagesCount;
  5470. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5471. offset.matchIdx = null;
  5472. this._pagesToSearch--;
  5473. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5474. offset.pageIdx = previous ? numPages - 1 : 0;
  5475. offset.wrapped = true;
  5476. }
  5477. }
  5478. #updateMatch(found = false) {
  5479. let state = FindState.NOT_FOUND;
  5480. const wrapped = this._offset.wrapped;
  5481. this._offset.wrapped = false;
  5482. if (found) {
  5483. const previousPage = this._selected.pageIdx;
  5484. this._selected.pageIdx = this._offset.pageIdx;
  5485. this._selected.matchIdx = this._offset.matchIdx;
  5486. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5487. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5488. this.#updatePage(previousPage);
  5489. }
  5490. }
  5491. this.#updateUIState(state, this.#state.findPrevious);
  5492. if (this._selected.pageIdx !== -1) {
  5493. this._scrollMatches = true;
  5494. this.#updatePage(this._selected.pageIdx);
  5495. }
  5496. }
  5497. #onFindBarClose(evt) {
  5498. const pdfDocument = this._pdfDocument;
  5499. this._firstPageCapability.promise.then(() => {
  5500. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5501. return;
  5502. }
  5503. if (this._findTimeout) {
  5504. clearTimeout(this._findTimeout);
  5505. this._findTimeout = null;
  5506. }
  5507. if (this._resumePageIdx) {
  5508. this._resumePageIdx = null;
  5509. this._dirtyMatch = true;
  5510. }
  5511. this.#updateUIState(FindState.FOUND);
  5512. this._highlightMatches = false;
  5513. this.#updateAllPages();
  5514. });
  5515. }
  5516. #requestMatchesCount() {
  5517. const {
  5518. pageIdx,
  5519. matchIdx
  5520. } = this._selected;
  5521. let current = 0,
  5522. total = this._matchesCountTotal;
  5523. if (matchIdx !== -1) {
  5524. for (let i = 0; i < pageIdx; i++) {
  5525. current += this._pageMatches[i]?.length || 0;
  5526. }
  5527. current += matchIdx + 1;
  5528. }
  5529. if (current < 1 || current > total) {
  5530. current = total = 0;
  5531. }
  5532. return {
  5533. current,
  5534. total
  5535. };
  5536. }
  5537. #updateUIResultsCount() {
  5538. this._eventBus.dispatch("updatefindmatchescount", {
  5539. source: this,
  5540. matchesCount: this.#requestMatchesCount()
  5541. });
  5542. }
  5543. #updateUIState(state, previous = false) {
  5544. if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) {
  5545. return;
  5546. }
  5547. this._eventBus.dispatch("updatefindcontrolstate", {
  5548. source: this,
  5549. state,
  5550. previous,
  5551. matchesCount: this.#requestMatchesCount(),
  5552. rawQuery: this.#state?.query ?? null
  5553. });
  5554. }
  5555. }
  5556. exports.PDFFindController = PDFFindController;
  5557. /***/
  5558. }),
  5559. /* 18 */
  5560. /***/ ((__unused_webpack_module, exports) => {
  5561. Object.defineProperty(exports, "__esModule", ({
  5562. value: true
  5563. }));
  5564. exports.CharacterType = void 0;
  5565. exports.getCharacterType = getCharacterType;
  5566. exports.getNormalizeWithNFKC = getNormalizeWithNFKC;
  5567. const CharacterType = {
  5568. SPACE: 0,
  5569. ALPHA_LETTER: 1,
  5570. PUNCT: 2,
  5571. HAN_LETTER: 3,
  5572. KATAKANA_LETTER: 4,
  5573. HIRAGANA_LETTER: 5,
  5574. HALFWIDTH_KATAKANA_LETTER: 6,
  5575. THAI_LETTER: 7
  5576. };
  5577. exports.CharacterType = CharacterType;
  5578. function isAlphabeticalScript(charCode) {
  5579. return charCode < 0x2e80;
  5580. }
  5581. function isAscii(charCode) {
  5582. return (charCode & 0xff80) === 0;
  5583. }
  5584. function isAsciiAlpha(charCode) {
  5585. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5586. }
  5587. function isAsciiDigit(charCode) {
  5588. return charCode >= 0x30 && charCode <= 0x39;
  5589. }
  5590. function isAsciiSpace(charCode) {
  5591. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5592. }
  5593. function isHan(charCode) {
  5594. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5595. }
  5596. function isKatakana(charCode) {
  5597. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5598. }
  5599. function isHiragana(charCode) {
  5600. return charCode >= 0x3040 && charCode <= 0x309f;
  5601. }
  5602. function isHalfwidthKatakana(charCode) {
  5603. return charCode >= 0xff60 && charCode <= 0xff9f;
  5604. }
  5605. function isThai(charCode) {
  5606. return (charCode & 0xff80) === 0x0e00;
  5607. }
  5608. function getCharacterType(charCode) {
  5609. if (isAlphabeticalScript(charCode)) {
  5610. if (isAscii(charCode)) {
  5611. if (isAsciiSpace(charCode)) {
  5612. return CharacterType.SPACE;
  5613. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5614. return CharacterType.ALPHA_LETTER;
  5615. }
  5616. return CharacterType.PUNCT;
  5617. } else if (isThai(charCode)) {
  5618. return CharacterType.THAI_LETTER;
  5619. } else if (charCode === 0xa0) {
  5620. return CharacterType.SPACE;
  5621. }
  5622. return CharacterType.ALPHA_LETTER;
  5623. }
  5624. if (isHan(charCode)) {
  5625. return CharacterType.HAN_LETTER;
  5626. } else if (isKatakana(charCode)) {
  5627. return CharacterType.KATAKANA_LETTER;
  5628. } else if (isHiragana(charCode)) {
  5629. return CharacterType.HIRAGANA_LETTER;
  5630. } else if (isHalfwidthKatakana(charCode)) {
  5631. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5632. }
  5633. return CharacterType.ALPHA_LETTER;
  5634. }
  5635. let NormalizeWithNFKC;
  5636. function getNormalizeWithNFKC() {
  5637. NormalizeWithNFKC ||= ` ¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰꟲ-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`;
  5638. return NormalizeWithNFKC;
  5639. }
  5640. /***/
  5641. }),
  5642. /* 19 */
  5643. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5644. Object.defineProperty(exports, "__esModule", ({
  5645. value: true
  5646. }));
  5647. exports.PDFHistory = void 0;
  5648. exports.isDestArraysEqual = isDestArraysEqual;
  5649. exports.isDestHashesEqual = isDestHashesEqual;
  5650. var _ui_utils = __webpack_require__(3);
  5651. var _event_utils = __webpack_require__(6);
  5652. const HASH_CHANGE_TIMEOUT = 1000;
  5653. const POSITION_UPDATED_THRESHOLD = 50;
  5654. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5655. function getCurrentHash() {
  5656. return document.location.hash;
  5657. }
  5658. class PDFHistory {
  5659. constructor({
  5660. linkService,
  5661. eventBus
  5662. }) {
  5663. this.linkService = linkService;
  5664. this.eventBus = eventBus;
  5665. this._initialized = false;
  5666. this._fingerprint = "";
  5667. this.reset();
  5668. this._boundEvents = null;
  5669. this.eventBus._on("pagesinit", () => {
  5670. this._isPagesLoaded = false;
  5671. this.eventBus._on("pagesloaded", evt => {
  5672. this._isPagesLoaded = !!evt.pagesCount;
  5673. }, {
  5674. once: true
  5675. });
  5676. });
  5677. }
  5678. initialize({
  5679. fingerprint,
  5680. resetHistory = false,
  5681. updateUrl = false
  5682. }) {
  5683. if (!fingerprint || typeof fingerprint !== "string") {
  5684. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5685. return;
  5686. }
  5687. if (this._initialized) {
  5688. this.reset();
  5689. }
  5690. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5691. this._fingerprint = fingerprint;
  5692. this._updateUrl = updateUrl === true;
  5693. this._initialized = true;
  5694. this._bindEvents();
  5695. const state = window.history.state;
  5696. this._popStateInProgress = false;
  5697. this._blockHashChange = 0;
  5698. this._currentHash = getCurrentHash();
  5699. this._numPositionUpdates = 0;
  5700. this._uid = this._maxUid = 0;
  5701. this._destination = null;
  5702. this._position = null;
  5703. if (!this._isValidState(state, true) || resetHistory) {
  5704. const {
  5705. hash,
  5706. page,
  5707. rotation
  5708. } = this._parseCurrentHash(true);
  5709. if (!hash || reInitialized || resetHistory) {
  5710. this._pushOrReplaceState(null, true);
  5711. return;
  5712. }
  5713. this._pushOrReplaceState({
  5714. hash,
  5715. page,
  5716. rotation
  5717. }, true);
  5718. return;
  5719. }
  5720. const destination = state.destination;
  5721. this._updateInternalState(destination, state.uid, true);
  5722. if (destination.rotation !== undefined) {
  5723. this._initialRotation = destination.rotation;
  5724. }
  5725. if (destination.dest) {
  5726. this._initialBookmark = JSON.stringify(destination.dest);
  5727. this._destination.page = null;
  5728. } else if (destination.hash) {
  5729. this._initialBookmark = destination.hash;
  5730. } else if (destination.page) {
  5731. this._initialBookmark = `page=${destination.page}`;
  5732. }
  5733. }
  5734. reset() {
  5735. if (this._initialized) {
  5736. this._pageHide();
  5737. this._initialized = false;
  5738. this._unbindEvents();
  5739. }
  5740. if (this._updateViewareaTimeout) {
  5741. clearTimeout(this._updateViewareaTimeout);
  5742. this._updateViewareaTimeout = null;
  5743. }
  5744. this._initialBookmark = null;
  5745. this._initialRotation = null;
  5746. }
  5747. push({
  5748. namedDest = null,
  5749. explicitDest,
  5750. pageNumber
  5751. }) {
  5752. if (!this._initialized) {
  5753. return;
  5754. }
  5755. if (namedDest && typeof namedDest !== "string") {
  5756. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5757. return;
  5758. } else if (!Array.isArray(explicitDest)) {
  5759. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5760. return;
  5761. } else if (!this._isValidPage(pageNumber)) {
  5762. if (pageNumber !== null || this._destination) {
  5763. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5764. return;
  5765. }
  5766. }
  5767. const hash = namedDest || JSON.stringify(explicitDest);
  5768. if (!hash) {
  5769. return;
  5770. }
  5771. let forceReplace = false;
  5772. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5773. if (this._destination.page) {
  5774. return;
  5775. }
  5776. forceReplace = true;
  5777. }
  5778. if (this._popStateInProgress && !forceReplace) {
  5779. return;
  5780. }
  5781. this._pushOrReplaceState({
  5782. dest: explicitDest,
  5783. hash,
  5784. page: pageNumber,
  5785. rotation: this.linkService.rotation
  5786. }, forceReplace);
  5787. if (!this._popStateInProgress) {
  5788. this._popStateInProgress = true;
  5789. Promise.resolve().then(() => {
  5790. this._popStateInProgress = false;
  5791. });
  5792. }
  5793. }
  5794. pushPage(pageNumber) {
  5795. if (!this._initialized) {
  5796. return;
  5797. }
  5798. if (!this._isValidPage(pageNumber)) {
  5799. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5800. return;
  5801. }
  5802. if (this._destination?.page === pageNumber) {
  5803. return;
  5804. }
  5805. if (this._popStateInProgress) {
  5806. return;
  5807. }
  5808. this._pushOrReplaceState({
  5809. dest: null,
  5810. hash: `page=${pageNumber}`,
  5811. page: pageNumber,
  5812. rotation: this.linkService.rotation
  5813. });
  5814. if (!this._popStateInProgress) {
  5815. this._popStateInProgress = true;
  5816. Promise.resolve().then(() => {
  5817. this._popStateInProgress = false;
  5818. });
  5819. }
  5820. }
  5821. pushCurrentPosition() {
  5822. if (!this._initialized || this._popStateInProgress) {
  5823. return;
  5824. }
  5825. this._tryPushCurrentPosition();
  5826. }
  5827. back() {
  5828. if (!this._initialized || this._popStateInProgress) {
  5829. return;
  5830. }
  5831. const state = window.history.state;
  5832. if (this._isValidState(state) && state.uid > 0) {
  5833. window.history.back();
  5834. }
  5835. }
  5836. forward() {
  5837. if (!this._initialized || this._popStateInProgress) {
  5838. return;
  5839. }
  5840. const state = window.history.state;
  5841. if (this._isValidState(state) && state.uid < this._maxUid) {
  5842. window.history.forward();
  5843. }
  5844. }
  5845. get popStateInProgress() {
  5846. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5847. }
  5848. get initialBookmark() {
  5849. return this._initialized ? this._initialBookmark : null;
  5850. }
  5851. get initialRotation() {
  5852. return this._initialized ? this._initialRotation : null;
  5853. }
  5854. _pushOrReplaceState(destination, forceReplace = false) {
  5855. const shouldReplace = forceReplace || !this._destination;
  5856. const newState = {
  5857. fingerprint: this._fingerprint,
  5858. uid: shouldReplace ? this._uid : this._uid + 1,
  5859. destination
  5860. };
  5861. this._updateInternalState(destination, newState.uid);
  5862. let newUrl;
  5863. if (this._updateUrl && destination?.hash) {
  5864. const baseUrl = document.location.href.split("#")[0];
  5865. if (!baseUrl.startsWith("file://")) {
  5866. newUrl = `${baseUrl}#${destination.hash}`;
  5867. }
  5868. }
  5869. if (shouldReplace) {
  5870. window.history.replaceState(newState, "", newUrl);
  5871. } else {
  5872. window.history.pushState(newState, "", newUrl);
  5873. }
  5874. }
  5875. _tryPushCurrentPosition(temporary = false) {
  5876. if (!this._position) {
  5877. return;
  5878. }
  5879. let position = this._position;
  5880. if (temporary) {
  5881. position = Object.assign(Object.create(null), this._position);
  5882. position.temporary = true;
  5883. }
  5884. if (!this._destination) {
  5885. this._pushOrReplaceState(position);
  5886. return;
  5887. }
  5888. if (this._destination.temporary) {
  5889. this._pushOrReplaceState(position, true);
  5890. return;
  5891. }
  5892. if (this._destination.hash === position.hash) {
  5893. return;
  5894. }
  5895. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5896. return;
  5897. }
  5898. let forceReplace = false;
  5899. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5900. if (this._destination.dest !== undefined || !this._destination.first) {
  5901. return;
  5902. }
  5903. forceReplace = true;
  5904. }
  5905. this._pushOrReplaceState(position, forceReplace);
  5906. }
  5907. _isValidPage(val) {
  5908. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5909. }
  5910. _isValidState(state, checkReload = false) {
  5911. if (!state) {
  5912. return false;
  5913. }
  5914. if (state.fingerprint !== this._fingerprint) {
  5915. if (checkReload) {
  5916. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5917. return false;
  5918. }
  5919. const [perfEntry] = performance.getEntriesByType("navigation");
  5920. if (perfEntry?.type !== "reload") {
  5921. return false;
  5922. }
  5923. } else {
  5924. return false;
  5925. }
  5926. }
  5927. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5928. return false;
  5929. }
  5930. if (state.destination === null || typeof state.destination !== "object") {
  5931. return false;
  5932. }
  5933. return true;
  5934. }
  5935. _updateInternalState(destination, uid, removeTemporary = false) {
  5936. if (this._updateViewareaTimeout) {
  5937. clearTimeout(this._updateViewareaTimeout);
  5938. this._updateViewareaTimeout = null;
  5939. }
  5940. if (removeTemporary && destination?.temporary) {
  5941. delete destination.temporary;
  5942. }
  5943. this._destination = destination;
  5944. this._uid = uid;
  5945. this._maxUid = Math.max(this._maxUid, uid);
  5946. this._numPositionUpdates = 0;
  5947. }
  5948. _parseCurrentHash(checkNameddest = false) {
  5949. const hash = unescape(getCurrentHash()).substring(1);
  5950. const params = (0, _ui_utils.parseQueryString)(hash);
  5951. const nameddest = params.get("nameddest") || "";
  5952. let page = params.get("page") | 0;
  5953. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5954. page = null;
  5955. }
  5956. return {
  5957. hash,
  5958. page,
  5959. rotation: this.linkService.rotation
  5960. };
  5961. }
  5962. _updateViewarea({
  5963. location
  5964. }) {
  5965. if (this._updateViewareaTimeout) {
  5966. clearTimeout(this._updateViewareaTimeout);
  5967. this._updateViewareaTimeout = null;
  5968. }
  5969. this._position = {
  5970. hash: location.pdfOpenParams.substring(1),
  5971. page: this.linkService.page,
  5972. first: location.pageNumber,
  5973. rotation: location.rotation
  5974. };
  5975. if (this._popStateInProgress) {
  5976. return;
  5977. }
  5978. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5979. this._numPositionUpdates++;
  5980. }
  5981. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5982. this._updateViewareaTimeout = setTimeout(() => {
  5983. if (!this._popStateInProgress) {
  5984. this._tryPushCurrentPosition(true);
  5985. }
  5986. this._updateViewareaTimeout = null;
  5987. }, UPDATE_VIEWAREA_TIMEOUT);
  5988. }
  5989. }
  5990. _popState({
  5991. state
  5992. }) {
  5993. const newHash = getCurrentHash(),
  5994. hashChanged = this._currentHash !== newHash;
  5995. this._currentHash = newHash;
  5996. if (!state) {
  5997. this._uid++;
  5998. const {
  5999. hash,
  6000. page,
  6001. rotation
  6002. } = this._parseCurrentHash();
  6003. this._pushOrReplaceState({
  6004. hash,
  6005. page,
  6006. rotation
  6007. }, true);
  6008. return;
  6009. }
  6010. if (!this._isValidState(state)) {
  6011. return;
  6012. }
  6013. this._popStateInProgress = true;
  6014. if (hashChanged) {
  6015. this._blockHashChange++;
  6016. (0, _event_utils.waitOnEventOrTimeout)({
  6017. target: window,
  6018. name: "hashchange",
  6019. delay: HASH_CHANGE_TIMEOUT
  6020. }).then(() => {
  6021. this._blockHashChange--;
  6022. });
  6023. }
  6024. const destination = state.destination;
  6025. this._updateInternalState(destination, state.uid, true);
  6026. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  6027. this.linkService.rotation = destination.rotation;
  6028. }
  6029. if (destination.dest) {
  6030. this.linkService.goToDestination(destination.dest);
  6031. } else if (destination.hash) {
  6032. this.linkService.setHash(destination.hash);
  6033. } else if (destination.page) {
  6034. this.linkService.page = destination.page;
  6035. }
  6036. Promise.resolve().then(() => {
  6037. this._popStateInProgress = false;
  6038. });
  6039. }
  6040. _pageHide() {
  6041. if (!this._destination || this._destination.temporary) {
  6042. this._tryPushCurrentPosition();
  6043. }
  6044. }
  6045. _bindEvents() {
  6046. if (this._boundEvents) {
  6047. return;
  6048. }
  6049. this._boundEvents = {
  6050. updateViewarea: this._updateViewarea.bind(this),
  6051. popState: this._popState.bind(this),
  6052. pageHide: this._pageHide.bind(this)
  6053. };
  6054. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  6055. window.addEventListener("popstate", this._boundEvents.popState);
  6056. window.addEventListener("pagehide", this._boundEvents.pageHide);
  6057. }
  6058. _unbindEvents() {
  6059. if (!this._boundEvents) {
  6060. return;
  6061. }
  6062. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  6063. window.removeEventListener("popstate", this._boundEvents.popState);
  6064. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  6065. this._boundEvents = null;
  6066. }
  6067. }
  6068. exports.PDFHistory = PDFHistory;
  6069. function isDestHashesEqual(destHash, pushHash) {
  6070. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  6071. return false;
  6072. }
  6073. if (destHash === pushHash) {
  6074. return true;
  6075. }
  6076. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  6077. if (nameddest === pushHash) {
  6078. return true;
  6079. }
  6080. return false;
  6081. }
  6082. function isDestArraysEqual(firstDest, secondDest) {
  6083. function isEntryEqual(first, second) {
  6084. if (typeof first !== typeof second) {
  6085. return false;
  6086. }
  6087. if (Array.isArray(first) || Array.isArray(second)) {
  6088. return false;
  6089. }
  6090. if (first !== null && typeof first === "object" && second !== null) {
  6091. if (Object.keys(first).length !== Object.keys(second).length) {
  6092. return false;
  6093. }
  6094. for (const key in first) {
  6095. if (!isEntryEqual(first[key], second[key])) {
  6096. return false;
  6097. }
  6098. }
  6099. return true;
  6100. }
  6101. return first === second || Number.isNaN(first) && Number.isNaN(second);
  6102. }
  6103. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  6104. return false;
  6105. }
  6106. if (firstDest.length !== secondDest.length) {
  6107. return false;
  6108. }
  6109. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  6110. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  6111. return false;
  6112. }
  6113. }
  6114. return true;
  6115. }
  6116. /***/
  6117. }),
  6118. /* 20 */
  6119. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6120. Object.defineProperty(exports, "__esModule", ({
  6121. value: true
  6122. }));
  6123. exports.PDFLayerViewer = void 0;
  6124. var _base_tree_viewer = __webpack_require__(12);
  6125. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  6126. constructor(options) {
  6127. super(options);
  6128. this.l10n = options.l10n;
  6129. this.eventBus._on("optionalcontentconfigchanged", evt => {
  6130. this.#updateLayers(evt.promise);
  6131. });
  6132. this.eventBus._on("resetlayers", () => {
  6133. this.#updateLayers();
  6134. });
  6135. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  6136. }
  6137. reset() {
  6138. super.reset();
  6139. this._optionalContentConfig = null;
  6140. this._optionalContentHash = null;
  6141. }
  6142. _dispatchEvent(layersCount) {
  6143. this.eventBus.dispatch("layersloaded", {
  6144. source: this,
  6145. layersCount
  6146. });
  6147. }
  6148. _bindLink(element, {
  6149. groupId,
  6150. input
  6151. }) {
  6152. const setVisibility = () => {
  6153. this._optionalContentConfig.setVisibility(groupId, input.checked);
  6154. this._optionalContentHash = this._optionalContentConfig.getHash();
  6155. this.eventBus.dispatch("optionalcontentconfig", {
  6156. source: this,
  6157. promise: Promise.resolve(this._optionalContentConfig)
  6158. });
  6159. };
  6160. element.onclick = evt => {
  6161. if (evt.target === input) {
  6162. setVisibility();
  6163. return true;
  6164. } else if (evt.target !== element) {
  6165. return true;
  6166. }
  6167. input.checked = !input.checked;
  6168. setVisibility();
  6169. return false;
  6170. };
  6171. }
  6172. async _setNestedName(element, {
  6173. name = null
  6174. }) {
  6175. if (typeof name === "string") {
  6176. element.textContent = this._normalizeTextContent(name);
  6177. return;
  6178. }
  6179. element.textContent = await this.l10n.get("additional_layers");
  6180. element.style.fontStyle = "italic";
  6181. }
  6182. _addToggleButton(div, {
  6183. name = null
  6184. }) {
  6185. super._addToggleButton(div, name === null);
  6186. }
  6187. _toggleAllTreeItems() {
  6188. if (!this._optionalContentConfig) {
  6189. return;
  6190. }
  6191. super._toggleAllTreeItems();
  6192. }
  6193. render({
  6194. optionalContentConfig,
  6195. pdfDocument
  6196. }) {
  6197. if (this._optionalContentConfig) {
  6198. this.reset();
  6199. }
  6200. this._optionalContentConfig = optionalContentConfig || null;
  6201. this._pdfDocument = pdfDocument || null;
  6202. const groups = optionalContentConfig?.getOrder();
  6203. if (!groups) {
  6204. this._dispatchEvent(0);
  6205. return;
  6206. }
  6207. this._optionalContentHash = optionalContentConfig.getHash();
  6208. const fragment = document.createDocumentFragment(),
  6209. queue = [{
  6210. parent: fragment,
  6211. groups
  6212. }];
  6213. let layersCount = 0,
  6214. hasAnyNesting = false;
  6215. while (queue.length > 0) {
  6216. const levelData = queue.shift();
  6217. for (const groupId of levelData.groups) {
  6218. const div = document.createElement("div");
  6219. div.className = "treeItem";
  6220. const element = document.createElement("a");
  6221. div.append(element);
  6222. if (typeof groupId === "object") {
  6223. hasAnyNesting = true;
  6224. this._addToggleButton(div, groupId);
  6225. this._setNestedName(element, groupId);
  6226. const itemsDiv = document.createElement("div");
  6227. itemsDiv.className = "treeItems";
  6228. div.append(itemsDiv);
  6229. queue.push({
  6230. parent: itemsDiv,
  6231. groups: groupId.order
  6232. });
  6233. } else {
  6234. const group = optionalContentConfig.getGroup(groupId);
  6235. const input = document.createElement("input");
  6236. this._bindLink(element, {
  6237. groupId,
  6238. input
  6239. });
  6240. input.type = "checkbox";
  6241. input.checked = group.visible;
  6242. const label = document.createElement("label");
  6243. label.textContent = this._normalizeTextContent(group.name);
  6244. label.append(input);
  6245. element.append(label);
  6246. layersCount++;
  6247. }
  6248. levelData.parent.append(div);
  6249. }
  6250. }
  6251. this._finishRendering(fragment, layersCount, hasAnyNesting);
  6252. }
  6253. async #updateLayers(promise = null) {
  6254. if (!this._optionalContentConfig) {
  6255. return;
  6256. }
  6257. const pdfDocument = this._pdfDocument;
  6258. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig());
  6259. if (pdfDocument !== this._pdfDocument) {
  6260. return;
  6261. }
  6262. if (promise) {
  6263. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  6264. return;
  6265. }
  6266. } else {
  6267. this.eventBus.dispatch("optionalcontentconfig", {
  6268. source: this,
  6269. promise: Promise.resolve(optionalContentConfig)
  6270. });
  6271. }
  6272. this.render({
  6273. optionalContentConfig,
  6274. pdfDocument: this._pdfDocument
  6275. });
  6276. }
  6277. }
  6278. exports.PDFLayerViewer = PDFLayerViewer;
  6279. /***/
  6280. }),
  6281. /* 21 */
  6282. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6283. Object.defineProperty(exports, "__esModule", ({
  6284. value: true
  6285. }));
  6286. exports.PDFOutlineViewer = void 0;
  6287. var _base_tree_viewer = __webpack_require__(12);
  6288. var _pdfjsLib = __webpack_require__(4);
  6289. var _ui_utils = __webpack_require__(3);
  6290. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  6291. constructor(options) {
  6292. super(options);
  6293. this.linkService = options.linkService;
  6294. this.downloadManager = options.downloadManager;
  6295. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6296. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6297. this.eventBus._on("pagechanging", evt => {
  6298. this._currentPageNumber = evt.pageNumber;
  6299. });
  6300. this.eventBus._on("pagesloaded", evt => {
  6301. this._isPagesLoaded = !!evt.pagesCount;
  6302. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6303. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6304. }
  6305. });
  6306. this.eventBus._on("sidebarviewchanged", evt => {
  6307. this._sidebarView = evt.view;
  6308. });
  6309. }
  6310. reset() {
  6311. super.reset();
  6312. this._outline = null;
  6313. this._pageNumberToDestHashCapability = null;
  6314. this._currentPageNumber = 1;
  6315. this._isPagesLoaded = null;
  6316. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6317. this._currentOutlineItemCapability.resolve(false);
  6318. }
  6319. this._currentOutlineItemCapability = null;
  6320. }
  6321. _dispatchEvent(outlineCount) {
  6322. this._currentOutlineItemCapability = new _pdfjsLib.PromiseCapability();
  6323. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  6324. this._currentOutlineItemCapability.resolve(false);
  6325. } else if (this._isPagesLoaded !== null) {
  6326. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6327. }
  6328. this.eventBus.dispatch("outlineloaded", {
  6329. source: this,
  6330. outlineCount,
  6331. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6332. });
  6333. }
  6334. _bindLink(element, {
  6335. url,
  6336. newWindow,
  6337. action,
  6338. attachment,
  6339. dest,
  6340. setOCGState
  6341. }) {
  6342. const {
  6343. linkService
  6344. } = this;
  6345. if (url) {
  6346. linkService.addLinkAttributes(element, url, newWindow);
  6347. return;
  6348. }
  6349. if (action) {
  6350. element.href = linkService.getAnchorUrl("");
  6351. element.onclick = () => {
  6352. linkService.executeNamedAction(action);
  6353. return false;
  6354. };
  6355. return;
  6356. }
  6357. if (attachment) {
  6358. element.href = linkService.getAnchorUrl("");
  6359. element.onclick = () => {
  6360. this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename);
  6361. return false;
  6362. };
  6363. return;
  6364. }
  6365. if (setOCGState) {
  6366. element.href = linkService.getAnchorUrl("");
  6367. element.onclick = () => {
  6368. linkService.executeSetOCGState(setOCGState);
  6369. return false;
  6370. };
  6371. return;
  6372. }
  6373. element.href = linkService.getDestinationHash(dest);
  6374. element.onclick = evt => {
  6375. this._updateCurrentTreeItem(evt.target.parentNode);
  6376. if (dest) {
  6377. linkService.goToDestination(dest);
  6378. }
  6379. return false;
  6380. };
  6381. }
  6382. _setStyles(element, {
  6383. bold,
  6384. italic
  6385. }) {
  6386. if (bold) {
  6387. element.style.fontWeight = "bold";
  6388. }
  6389. if (italic) {
  6390. element.style.fontStyle = "italic";
  6391. }
  6392. }
  6393. _addToggleButton(div, {
  6394. count,
  6395. items
  6396. }) {
  6397. let hidden = false;
  6398. if (count < 0) {
  6399. let totalCount = items.length;
  6400. if (totalCount > 0) {
  6401. const queue = [...items];
  6402. while (queue.length > 0) {
  6403. const {
  6404. count: nestedCount,
  6405. items: nestedItems
  6406. } = queue.shift();
  6407. if (nestedCount > 0 && nestedItems.length > 0) {
  6408. totalCount += nestedItems.length;
  6409. queue.push(...nestedItems);
  6410. }
  6411. }
  6412. }
  6413. if (Math.abs(count) === totalCount) {
  6414. hidden = true;
  6415. }
  6416. }
  6417. super._addToggleButton(div, hidden);
  6418. }
  6419. _toggleAllTreeItems() {
  6420. if (!this._outline) {
  6421. return;
  6422. }
  6423. super._toggleAllTreeItems();
  6424. }
  6425. render({
  6426. outline,
  6427. pdfDocument
  6428. }) {
  6429. if (this._outline) {
  6430. this.reset();
  6431. }
  6432. this._outline = outline || null;
  6433. this._pdfDocument = pdfDocument || null;
  6434. if (!outline) {
  6435. this._dispatchEvent(0);
  6436. return;
  6437. }
  6438. const fragment = document.createDocumentFragment();
  6439. const queue = [{
  6440. parent: fragment,
  6441. items: outline
  6442. }];
  6443. let outlineCount = 0,
  6444. hasAnyNesting = false;
  6445. while (queue.length > 0) {
  6446. const levelData = queue.shift();
  6447. for (const item of levelData.items) {
  6448. const div = document.createElement("div");
  6449. div.className = "treeItem";
  6450. const element = document.createElement("a");
  6451. this._bindLink(element, item);
  6452. this._setStyles(element, item);
  6453. element.textContent = this._normalizeTextContent(item.title);
  6454. div.append(element);
  6455. if (item.items.length > 0) {
  6456. hasAnyNesting = true;
  6457. this._addToggleButton(div, item);
  6458. const itemsDiv = document.createElement("div");
  6459. itemsDiv.className = "treeItems";
  6460. div.append(itemsDiv);
  6461. queue.push({
  6462. parent: itemsDiv,
  6463. items: item.items
  6464. });
  6465. }
  6466. levelData.parent.append(div);
  6467. outlineCount++;
  6468. }
  6469. }
  6470. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6471. }
  6472. async _currentOutlineItem() {
  6473. if (!this._isPagesLoaded) {
  6474. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6475. }
  6476. if (!this._outline || !this._pdfDocument) {
  6477. return;
  6478. }
  6479. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6480. if (!pageNumberToDestHash) {
  6481. return;
  6482. }
  6483. this._updateCurrentTreeItem(null);
  6484. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6485. return;
  6486. }
  6487. for (let i = this._currentPageNumber; i > 0; i--) {
  6488. const destHash = pageNumberToDestHash.get(i);
  6489. if (!destHash) {
  6490. continue;
  6491. }
  6492. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6493. if (!linkElement) {
  6494. continue;
  6495. }
  6496. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6497. break;
  6498. }
  6499. }
  6500. async _getPageNumberToDestHash(pdfDocument) {
  6501. if (this._pageNumberToDestHashCapability) {
  6502. return this._pageNumberToDestHashCapability.promise;
  6503. }
  6504. this._pageNumberToDestHashCapability = new _pdfjsLib.PromiseCapability();
  6505. const pageNumberToDestHash = new Map(),
  6506. pageNumberNesting = new Map();
  6507. const queue = [{
  6508. nesting: 0,
  6509. items: this._outline
  6510. }];
  6511. while (queue.length > 0) {
  6512. const levelData = queue.shift(),
  6513. currentNesting = levelData.nesting;
  6514. for (const {
  6515. dest,
  6516. items
  6517. } of levelData.items) {
  6518. let explicitDest, pageNumber;
  6519. if (typeof dest === "string") {
  6520. explicitDest = await pdfDocument.getDestination(dest);
  6521. if (pdfDocument !== this._pdfDocument) {
  6522. return null;
  6523. }
  6524. } else {
  6525. explicitDest = dest;
  6526. }
  6527. if (Array.isArray(explicitDest)) {
  6528. const [destRef] = explicitDest;
  6529. if (typeof destRef === "object" && destRef !== null) {
  6530. pageNumber = this.linkService._cachedPageNumber(destRef);
  6531. if (!pageNumber) {
  6532. try {
  6533. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6534. if (pdfDocument !== this._pdfDocument) {
  6535. return null;
  6536. }
  6537. this.linkService.cachePageRef(pageNumber, destRef);
  6538. } catch { }
  6539. }
  6540. } else if (Number.isInteger(destRef)) {
  6541. pageNumber = destRef + 1;
  6542. }
  6543. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6544. const destHash = this.linkService.getDestinationHash(dest);
  6545. pageNumberToDestHash.set(pageNumber, destHash);
  6546. pageNumberNesting.set(pageNumber, currentNesting);
  6547. }
  6548. }
  6549. if (items.length > 0) {
  6550. queue.push({
  6551. nesting: currentNesting + 1,
  6552. items
  6553. });
  6554. }
  6555. }
  6556. }
  6557. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6558. return this._pageNumberToDestHashCapability.promise;
  6559. }
  6560. }
  6561. exports.PDFOutlineViewer = PDFOutlineViewer;
  6562. /***/
  6563. }),
  6564. /* 22 */
  6565. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6566. Object.defineProperty(exports, "__esModule", ({
  6567. value: true
  6568. }));
  6569. exports.PDFPresentationMode = void 0;
  6570. var _ui_utils = __webpack_require__(3);
  6571. var _pdfjsLib = __webpack_require__(4);
  6572. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6573. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6574. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6575. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6576. const PAGE_SWITCH_THRESHOLD = 0.1;
  6577. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6578. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6579. class PDFPresentationMode {
  6580. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6581. #args = null;
  6582. constructor({
  6583. container,
  6584. pdfViewer,
  6585. eventBus
  6586. }) {
  6587. this.container = container;
  6588. this.pdfViewer = pdfViewer;
  6589. this.eventBus = eventBus;
  6590. this.contextMenuOpen = false;
  6591. this.mouseScrollTimeStamp = 0;
  6592. this.mouseScrollDelta = 0;
  6593. this.touchSwipeState = null;
  6594. }
  6595. async request() {
  6596. const {
  6597. container,
  6598. pdfViewer
  6599. } = this;
  6600. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6601. return false;
  6602. }
  6603. this.#addFullscreenChangeListeners();
  6604. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6605. const promise = container.requestFullscreen();
  6606. this.#args = {
  6607. pageNumber: pdfViewer.currentPageNumber,
  6608. scaleValue: pdfViewer.currentScaleValue,
  6609. scrollMode: pdfViewer.scrollMode,
  6610. spreadMode: null,
  6611. annotationEditorMode: null
  6612. };
  6613. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6614. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6615. this.#args.spreadMode = pdfViewer.spreadMode;
  6616. }
  6617. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6618. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6619. }
  6620. try {
  6621. await promise;
  6622. pdfViewer.focus();
  6623. return true;
  6624. } catch {
  6625. this.#removeFullscreenChangeListeners();
  6626. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6627. }
  6628. return false;
  6629. }
  6630. get active() {
  6631. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6632. }
  6633. #mouseWheel(evt) {
  6634. if (!this.active) {
  6635. return;
  6636. }
  6637. evt.preventDefault();
  6638. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6639. const currentTime = Date.now();
  6640. const storedTime = this.mouseScrollTimeStamp;
  6641. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6642. return;
  6643. }
  6644. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6645. this.#resetMouseScrollState();
  6646. }
  6647. this.mouseScrollDelta += delta;
  6648. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6649. const totalDelta = this.mouseScrollDelta;
  6650. this.#resetMouseScrollState();
  6651. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6652. if (success) {
  6653. this.mouseScrollTimeStamp = currentTime;
  6654. }
  6655. }
  6656. }
  6657. #notifyStateChange(state) {
  6658. this.#state = state;
  6659. this.eventBus.dispatch("presentationmodechanged", {
  6660. source: this,
  6661. state
  6662. });
  6663. }
  6664. #enter() {
  6665. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6666. this.container.classList.add(ACTIVE_SELECTOR);
  6667. setTimeout(() => {
  6668. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6669. if (this.#args.spreadMode !== null) {
  6670. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6671. }
  6672. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6673. this.pdfViewer.currentScaleValue = "page-fit";
  6674. if (this.#args.annotationEditorMode !== null) {
  6675. this.pdfViewer.annotationEditorMode = {
  6676. mode: _pdfjsLib.AnnotationEditorType.NONE
  6677. };
  6678. }
  6679. }, 0);
  6680. this.#addWindowListeners();
  6681. this.#showControls();
  6682. this.contextMenuOpen = false;
  6683. window.getSelection().removeAllRanges();
  6684. }
  6685. #exit() {
  6686. const pageNumber = this.pdfViewer.currentPageNumber;
  6687. this.container.classList.remove(ACTIVE_SELECTOR);
  6688. setTimeout(() => {
  6689. this.#removeFullscreenChangeListeners();
  6690. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6691. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6692. if (this.#args.spreadMode !== null) {
  6693. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6694. }
  6695. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6696. this.pdfViewer.currentPageNumber = pageNumber;
  6697. if (this.#args.annotationEditorMode !== null) {
  6698. this.pdfViewer.annotationEditorMode = {
  6699. mode: this.#args.annotationEditorMode
  6700. };
  6701. }
  6702. this.#args = null;
  6703. }, 0);
  6704. this.#removeWindowListeners();
  6705. this.#hideControls();
  6706. this.#resetMouseScrollState();
  6707. this.contextMenuOpen = false;
  6708. }
  6709. #mouseDown(evt) {
  6710. if (this.contextMenuOpen) {
  6711. this.contextMenuOpen = false;
  6712. evt.preventDefault();
  6713. return;
  6714. }
  6715. if (evt.button !== 0) {
  6716. return;
  6717. }
  6718. if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) {
  6719. return;
  6720. }
  6721. evt.preventDefault();
  6722. if (evt.shiftKey) {
  6723. this.pdfViewer.previousPage();
  6724. } else {
  6725. this.pdfViewer.nextPage();
  6726. }
  6727. }
  6728. #contextMenu() {
  6729. this.contextMenuOpen = true;
  6730. }
  6731. #showControls() {
  6732. if (this.controlsTimeout) {
  6733. clearTimeout(this.controlsTimeout);
  6734. } else {
  6735. this.container.classList.add(CONTROLS_SELECTOR);
  6736. }
  6737. this.controlsTimeout = setTimeout(() => {
  6738. this.container.classList.remove(CONTROLS_SELECTOR);
  6739. delete this.controlsTimeout;
  6740. }, DELAY_BEFORE_HIDING_CONTROLS);
  6741. }
  6742. #hideControls() {
  6743. if (!this.controlsTimeout) {
  6744. return;
  6745. }
  6746. clearTimeout(this.controlsTimeout);
  6747. this.container.classList.remove(CONTROLS_SELECTOR);
  6748. delete this.controlsTimeout;
  6749. }
  6750. #resetMouseScrollState() {
  6751. this.mouseScrollTimeStamp = 0;
  6752. this.mouseScrollDelta = 0;
  6753. }
  6754. #touchSwipe(evt) {
  6755. if (!this.active) {
  6756. return;
  6757. }
  6758. if (evt.touches.length > 1) {
  6759. this.touchSwipeState = null;
  6760. return;
  6761. }
  6762. switch (evt.type) {
  6763. case "touchstart":
  6764. this.touchSwipeState = {
  6765. startX: evt.touches[0].pageX,
  6766. startY: evt.touches[0].pageY,
  6767. endX: evt.touches[0].pageX,
  6768. endY: evt.touches[0].pageY
  6769. };
  6770. break;
  6771. case "touchmove":
  6772. if (this.touchSwipeState === null) {
  6773. return;
  6774. }
  6775. this.touchSwipeState.endX = evt.touches[0].pageX;
  6776. this.touchSwipeState.endY = evt.touches[0].pageY;
  6777. evt.preventDefault();
  6778. break;
  6779. case "touchend":
  6780. if (this.touchSwipeState === null) {
  6781. return;
  6782. }
  6783. let delta = 0;
  6784. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6785. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6786. const absAngle = Math.abs(Math.atan2(dy, dx));
  6787. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6788. delta = dx;
  6789. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6790. delta = dy;
  6791. }
  6792. if (delta > 0) {
  6793. this.pdfViewer.previousPage();
  6794. } else if (delta < 0) {
  6795. this.pdfViewer.nextPage();
  6796. }
  6797. break;
  6798. }
  6799. }
  6800. #addWindowListeners() {
  6801. this.showControlsBind = this.#showControls.bind(this);
  6802. this.mouseDownBind = this.#mouseDown.bind(this);
  6803. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6804. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6805. this.contextMenuBind = this.#contextMenu.bind(this);
  6806. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6807. window.addEventListener("mousemove", this.showControlsBind);
  6808. window.addEventListener("mousedown", this.mouseDownBind);
  6809. window.addEventListener("wheel", this.mouseWheelBind, {
  6810. passive: false
  6811. });
  6812. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6813. window.addEventListener("contextmenu", this.contextMenuBind);
  6814. window.addEventListener("touchstart", this.touchSwipeBind);
  6815. window.addEventListener("touchmove", this.touchSwipeBind);
  6816. window.addEventListener("touchend", this.touchSwipeBind);
  6817. }
  6818. #removeWindowListeners() {
  6819. window.removeEventListener("mousemove", this.showControlsBind);
  6820. window.removeEventListener("mousedown", this.mouseDownBind);
  6821. window.removeEventListener("wheel", this.mouseWheelBind, {
  6822. passive: false
  6823. });
  6824. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6825. window.removeEventListener("contextmenu", this.contextMenuBind);
  6826. window.removeEventListener("touchstart", this.touchSwipeBind);
  6827. window.removeEventListener("touchmove", this.touchSwipeBind);
  6828. window.removeEventListener("touchend", this.touchSwipeBind);
  6829. delete this.showControlsBind;
  6830. delete this.mouseDownBind;
  6831. delete this.mouseWheelBind;
  6832. delete this.resetMouseScrollStateBind;
  6833. delete this.contextMenuBind;
  6834. delete this.touchSwipeBind;
  6835. }
  6836. #fullscreenChange() {
  6837. if (document.fullscreenElement) {
  6838. this.#enter();
  6839. } else {
  6840. this.#exit();
  6841. }
  6842. }
  6843. #addFullscreenChangeListeners() {
  6844. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6845. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6846. }
  6847. #removeFullscreenChangeListeners() {
  6848. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6849. delete this.fullscreenChangeBind;
  6850. }
  6851. }
  6852. exports.PDFPresentationMode = PDFPresentationMode;
  6853. /***/
  6854. }),
  6855. /* 23 */
  6856. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6857. Object.defineProperty(exports, "__esModule", ({
  6858. value: true
  6859. }));
  6860. exports.PDFRenderingQueue = void 0;
  6861. var _pdfjsLib = __webpack_require__(4);
  6862. var _ui_utils = __webpack_require__(3);
  6863. const CLEANUP_TIMEOUT = 30000;
  6864. class PDFRenderingQueue {
  6865. constructor() {
  6866. this.pdfViewer = null;
  6867. this.pdfThumbnailViewer = null;
  6868. this.onIdle = null;
  6869. this.highestPriorityPage = null;
  6870. this.idleTimeout = null;
  6871. this.printing = false;
  6872. this.isThumbnailViewEnabled = false;
  6873. Object.defineProperty(this, "hasViewer", {
  6874. value: () => !!this.pdfViewer
  6875. });
  6876. }
  6877. setViewer(pdfViewer) {
  6878. this.pdfViewer = pdfViewer;
  6879. }
  6880. setThumbnailViewer(pdfThumbnailViewer) {
  6881. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6882. }
  6883. isHighestPriority(view) {
  6884. return this.highestPriorityPage === view.renderingId;
  6885. }
  6886. renderHighestPriority(currentlyVisiblePages) {
  6887. if (this.idleTimeout) {
  6888. clearTimeout(this.idleTimeout);
  6889. this.idleTimeout = null;
  6890. }
  6891. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6892. return;
  6893. }
  6894. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6895. return;
  6896. }
  6897. if (this.printing) {
  6898. return;
  6899. }
  6900. if (this.onIdle) {
  6901. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6902. }
  6903. }
  6904. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6905. const visibleViews = visible.views,
  6906. numVisible = visibleViews.length;
  6907. if (numVisible === 0) {
  6908. return null;
  6909. }
  6910. for (let i = 0; i < numVisible; i++) {
  6911. const view = visibleViews[i].view;
  6912. if (!this.isViewFinished(view)) {
  6913. return view;
  6914. }
  6915. }
  6916. const firstId = visible.first.id,
  6917. lastId = visible.last.id;
  6918. if (lastId - firstId + 1 > numVisible) {
  6919. const visibleIds = visible.ids;
  6920. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6921. const holeId = scrolledDown ? firstId + i : lastId - i;
  6922. if (visibleIds.has(holeId)) {
  6923. continue;
  6924. }
  6925. const holeView = views[holeId - 1];
  6926. if (!this.isViewFinished(holeView)) {
  6927. return holeView;
  6928. }
  6929. }
  6930. }
  6931. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6932. let preRenderView = views[preRenderIndex];
  6933. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6934. return preRenderView;
  6935. }
  6936. if (preRenderExtra) {
  6937. preRenderIndex += scrolledDown ? 1 : -1;
  6938. preRenderView = views[preRenderIndex];
  6939. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6940. return preRenderView;
  6941. }
  6942. }
  6943. return null;
  6944. }
  6945. isViewFinished(view) {
  6946. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6947. }
  6948. renderView(view) {
  6949. switch (view.renderingState) {
  6950. case _ui_utils.RenderingStates.FINISHED:
  6951. return false;
  6952. case _ui_utils.RenderingStates.PAUSED:
  6953. this.highestPriorityPage = view.renderingId;
  6954. view.resume();
  6955. break;
  6956. case _ui_utils.RenderingStates.RUNNING:
  6957. this.highestPriorityPage = view.renderingId;
  6958. break;
  6959. case _ui_utils.RenderingStates.INITIAL:
  6960. this.highestPriorityPage = view.renderingId;
  6961. view.draw().finally(() => {
  6962. this.renderHighestPriority();
  6963. }).catch(reason => {
  6964. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6965. return;
  6966. }
  6967. console.error(`renderView: "${reason}"`);
  6968. });
  6969. break;
  6970. }
  6971. return true;
  6972. }
  6973. }
  6974. exports.PDFRenderingQueue = PDFRenderingQueue;
  6975. /***/
  6976. }),
  6977. /* 24 */
  6978. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6979. Object.defineProperty(exports, "__esModule", ({
  6980. value: true
  6981. }));
  6982. exports.PDFScriptingManager = void 0;
  6983. var _ui_utils = __webpack_require__(3);
  6984. var _pdfjsLib = __webpack_require__(4);
  6985. class PDFScriptingManager {
  6986. #closeCapability = null;
  6987. #destroyCapability = null;
  6988. #docProperties = null;
  6989. #eventBus = null;
  6990. #externalServices = null;
  6991. #pdfDocument = null;
  6992. #pdfViewer = null;
  6993. #ready = false;
  6994. #sandboxBundleSrc = null;
  6995. #scripting = null;
  6996. #willPrintCapability = null;
  6997. constructor({
  6998. eventBus,
  6999. sandboxBundleSrc = null,
  7000. externalServices = null,
  7001. docProperties = null
  7002. }) {
  7003. this.#eventBus = eventBus;
  7004. this.#sandboxBundleSrc = sandboxBundleSrc;
  7005. this.#externalServices = externalServices;
  7006. this.#docProperties = docProperties;
  7007. }
  7008. setViewer(pdfViewer) {
  7009. this.#pdfViewer = pdfViewer;
  7010. }
  7011. async setDocument(pdfDocument) {
  7012. if (this.#pdfDocument) {
  7013. await this.#destroyScripting();
  7014. }
  7015. this.#pdfDocument = pdfDocument;
  7016. if (!pdfDocument) {
  7017. return;
  7018. }
  7019. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  7020. if (!objects && !docActions) {
  7021. await this.#destroyScripting();
  7022. return;
  7023. }
  7024. if (pdfDocument !== this.#pdfDocument) {
  7025. return;
  7026. }
  7027. try {
  7028. this.#scripting = this.#initScripting();
  7029. } catch (error) {
  7030. console.error(`setDocument: "${error.message}".`);
  7031. await this.#destroyScripting();
  7032. return;
  7033. }
  7034. this._internalEvents.set("updatefromsandbox", event => {
  7035. if (event?.source === window) {
  7036. this.#updateFromSandbox(event.detail);
  7037. }
  7038. });
  7039. this._internalEvents.set("dispatcheventinsandbox", event => {
  7040. this.#scripting?.dispatchEventInSandbox(event.detail);
  7041. });
  7042. this._internalEvents.set("pagechanging", ({
  7043. pageNumber,
  7044. previous
  7045. }) => {
  7046. if (pageNumber === previous) {
  7047. return;
  7048. }
  7049. this.#dispatchPageClose(previous);
  7050. this.#dispatchPageOpen(pageNumber);
  7051. });
  7052. this._internalEvents.set("pagerendered", ({
  7053. pageNumber
  7054. }) => {
  7055. if (!this._pageOpenPending.has(pageNumber)) {
  7056. return;
  7057. }
  7058. if (pageNumber !== this.#pdfViewer.currentPageNumber) {
  7059. return;
  7060. }
  7061. this.#dispatchPageOpen(pageNumber);
  7062. });
  7063. this._internalEvents.set("pagesdestroy", async () => {
  7064. await this.#dispatchPageClose(this.#pdfViewer.currentPageNumber);
  7065. await this.#scripting?.dispatchEventInSandbox({
  7066. id: "doc",
  7067. name: "WillClose"
  7068. });
  7069. this.#closeCapability?.resolve();
  7070. });
  7071. for (const [name, listener] of this._internalEvents) {
  7072. this.#eventBus._on(name, listener);
  7073. }
  7074. try {
  7075. const docProperties = await this.#docProperties(pdfDocument);
  7076. if (pdfDocument !== this.#pdfDocument) {
  7077. return;
  7078. }
  7079. await this.#scripting.createSandbox({
  7080. objects,
  7081. calculationOrder,
  7082. appInfo: {
  7083. platform: navigator.platform,
  7084. language: navigator.language
  7085. },
  7086. docInfo: {
  7087. ...docProperties,
  7088. actions: docActions
  7089. }
  7090. });
  7091. this.#eventBus.dispatch("sandboxcreated", {
  7092. source: this
  7093. });
  7094. } catch (error) {
  7095. console.error(`setDocument: "${error.message}".`);
  7096. await this.#destroyScripting();
  7097. return;
  7098. }
  7099. await this.#scripting?.dispatchEventInSandbox({
  7100. id: "doc",
  7101. name: "Open"
  7102. });
  7103. await this.#dispatchPageOpen(this.#pdfViewer.currentPageNumber, true);
  7104. Promise.resolve().then(() => {
  7105. if (pdfDocument === this.#pdfDocument) {
  7106. this.#ready = true;
  7107. }
  7108. });
  7109. }
  7110. async dispatchWillSave() {
  7111. return this.#scripting?.dispatchEventInSandbox({
  7112. id: "doc",
  7113. name: "WillSave"
  7114. });
  7115. }
  7116. async dispatchDidSave() {
  7117. return this.#scripting?.dispatchEventInSandbox({
  7118. id: "doc",
  7119. name: "DidSave"
  7120. });
  7121. }
  7122. async dispatchWillPrint() {
  7123. if (!this.#scripting) {
  7124. return;
  7125. }
  7126. await this.#willPrintCapability?.promise;
  7127. this.#willPrintCapability = new _pdfjsLib.PromiseCapability();
  7128. try {
  7129. await this.#scripting.dispatchEventInSandbox({
  7130. id: "doc",
  7131. name: "WillPrint"
  7132. });
  7133. } catch (ex) {
  7134. this.#willPrintCapability.resolve();
  7135. this.#willPrintCapability = null;
  7136. throw ex;
  7137. }
  7138. await this.#willPrintCapability.promise;
  7139. }
  7140. async dispatchDidPrint() {
  7141. return this.#scripting?.dispatchEventInSandbox({
  7142. id: "doc",
  7143. name: "DidPrint"
  7144. });
  7145. }
  7146. get destroyPromise() {
  7147. return this.#destroyCapability?.promise || null;
  7148. }
  7149. get ready() {
  7150. return this.#ready;
  7151. }
  7152. get _internalEvents() {
  7153. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  7154. }
  7155. get _pageOpenPending() {
  7156. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  7157. }
  7158. get _visitedPages() {
  7159. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  7160. }
  7161. async #updateFromSandbox(detail) {
  7162. const pdfViewer = this.#pdfViewer;
  7163. const isInPresentationMode = pdfViewer.isInPresentationMode || pdfViewer.isChangingPresentationMode;
  7164. const {
  7165. id,
  7166. siblings,
  7167. command,
  7168. value
  7169. } = detail;
  7170. if (!id) {
  7171. switch (command) {
  7172. case "clear":
  7173. console.clear();
  7174. break;
  7175. case "error":
  7176. console.error(value);
  7177. break;
  7178. case "layout":
  7179. if (!isInPresentationMode) {
  7180. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  7181. pdfViewer.spreadMode = modes.spreadMode;
  7182. }
  7183. break;
  7184. case "page-num":
  7185. pdfViewer.currentPageNumber = value + 1;
  7186. break;
  7187. case "print":
  7188. await pdfViewer.pagesPromise;
  7189. this.#eventBus.dispatch("print", {
  7190. source: this
  7191. });
  7192. break;
  7193. case "println":
  7194. console.log(value);
  7195. break;
  7196. case "zoom":
  7197. if (!isInPresentationMode) {
  7198. pdfViewer.currentScaleValue = value;
  7199. }
  7200. break;
  7201. case "SaveAs":
  7202. this.#eventBus.dispatch("download", {
  7203. source: this
  7204. });
  7205. break;
  7206. case "FirstPage":
  7207. pdfViewer.currentPageNumber = 1;
  7208. break;
  7209. case "LastPage":
  7210. pdfViewer.currentPageNumber = pdfViewer.pagesCount;
  7211. break;
  7212. case "NextPage":
  7213. pdfViewer.nextPage();
  7214. break;
  7215. case "PrevPage":
  7216. pdfViewer.previousPage();
  7217. break;
  7218. case "ZoomViewIn":
  7219. if (!isInPresentationMode) {
  7220. pdfViewer.increaseScale();
  7221. }
  7222. break;
  7223. case "ZoomViewOut":
  7224. if (!isInPresentationMode) {
  7225. pdfViewer.decreaseScale();
  7226. }
  7227. break;
  7228. case "WillPrintFinished":
  7229. this.#willPrintCapability?.resolve();
  7230. this.#willPrintCapability = null;
  7231. break;
  7232. }
  7233. return;
  7234. }
  7235. if (isInPresentationMode && detail.focus) {
  7236. return;
  7237. }
  7238. delete detail.id;
  7239. delete detail.siblings;
  7240. const ids = siblings ? [id, ...siblings] : [id];
  7241. for (const elementId of ids) {
  7242. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  7243. if (element) {
  7244. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  7245. detail
  7246. }));
  7247. } else {
  7248. this.#pdfDocument?.annotationStorage.setValue(elementId, detail);
  7249. }
  7250. }
  7251. }
  7252. async #dispatchPageOpen(pageNumber, initialize = false) {
  7253. const pdfDocument = this.#pdfDocument,
  7254. visitedPages = this._visitedPages;
  7255. if (initialize) {
  7256. this.#closeCapability = new _pdfjsLib.PromiseCapability();
  7257. }
  7258. if (!this.#closeCapability) {
  7259. return;
  7260. }
  7261. const pageView = this.#pdfViewer.getPageView(pageNumber - 1);
  7262. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7263. this._pageOpenPending.add(pageNumber);
  7264. return;
  7265. }
  7266. this._pageOpenPending.delete(pageNumber);
  7267. const actionsPromise = (async () => {
  7268. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  7269. if (pdfDocument !== this.#pdfDocument) {
  7270. return;
  7271. }
  7272. await this.#scripting?.dispatchEventInSandbox({
  7273. id: "page",
  7274. name: "PageOpen",
  7275. pageNumber,
  7276. actions
  7277. });
  7278. })();
  7279. visitedPages.set(pageNumber, actionsPromise);
  7280. }
  7281. async #dispatchPageClose(pageNumber) {
  7282. const pdfDocument = this.#pdfDocument,
  7283. visitedPages = this._visitedPages;
  7284. if (!this.#closeCapability) {
  7285. return;
  7286. }
  7287. if (this._pageOpenPending.has(pageNumber)) {
  7288. return;
  7289. }
  7290. const actionsPromise = visitedPages.get(pageNumber);
  7291. if (!actionsPromise) {
  7292. return;
  7293. }
  7294. visitedPages.set(pageNumber, null);
  7295. await actionsPromise;
  7296. if (pdfDocument !== this.#pdfDocument) {
  7297. return;
  7298. }
  7299. await this.#scripting?.dispatchEventInSandbox({
  7300. id: "page",
  7301. name: "PageClose",
  7302. pageNumber
  7303. });
  7304. }
  7305. #initScripting() {
  7306. this.#destroyCapability = new _pdfjsLib.PromiseCapability();
  7307. if (this.#scripting) {
  7308. throw new Error("#initScripting: Scripting already exists.");
  7309. }
  7310. return this.#externalServices.createScripting({
  7311. sandboxBundleSrc: this.#sandboxBundleSrc
  7312. });
  7313. }
  7314. async #destroyScripting() {
  7315. if (!this.#scripting) {
  7316. this.#pdfDocument = null;
  7317. this.#destroyCapability?.resolve();
  7318. return;
  7319. }
  7320. if (this.#closeCapability) {
  7321. await Promise.race([this.#closeCapability.promise, new Promise(resolve => {
  7322. setTimeout(resolve, 1000);
  7323. })]).catch(() => { });
  7324. this.#closeCapability = null;
  7325. }
  7326. this.#pdfDocument = null;
  7327. try {
  7328. await this.#scripting.destroySandbox();
  7329. } catch { }
  7330. this.#willPrintCapability?.reject(new Error("Scripting destroyed."));
  7331. this.#willPrintCapability = null;
  7332. for (const [name, listener] of this._internalEvents) {
  7333. this.#eventBus._off(name, listener);
  7334. }
  7335. this._internalEvents.clear();
  7336. this._pageOpenPending.clear();
  7337. this._visitedPages.clear();
  7338. this.#scripting = null;
  7339. this.#ready = false;
  7340. this.#destroyCapability?.resolve();
  7341. }
  7342. }
  7343. exports.PDFScriptingManager = PDFScriptingManager;
  7344. /***/
  7345. }),
  7346. /* 25 */
  7347. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7348. Object.defineProperty(exports, "__esModule", ({
  7349. value: true
  7350. }));
  7351. exports.PDFSidebar = void 0;
  7352. var _ui_utils = __webpack_require__(3);
  7353. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7354. const SIDEBAR_MIN_WIDTH = 200;
  7355. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7356. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7357. class PDFSidebar {
  7358. #isRTL = false;
  7359. #mouseMoveBound = this.#mouseMove.bind(this);
  7360. #mouseUpBound = this.#mouseUp.bind(this);
  7361. #outerContainerWidth = null;
  7362. #width = null;
  7363. constructor({
  7364. elements,
  7365. eventBus,
  7366. l10n
  7367. }) {
  7368. this.isOpen = false;
  7369. this.active = _ui_utils.SidebarView.THUMBS;
  7370. this.isInitialViewSet = false;
  7371. this.isInitialEventDispatched = false;
  7372. this.onToggled = null;
  7373. this.onUpdateThumbnails = null;
  7374. this.outerContainer = elements.outerContainer;
  7375. this.sidebarContainer = elements.sidebarContainer;
  7376. this.toggleButton = elements.toggleButton;
  7377. this.resizer = elements.resizer;
  7378. this.thumbnailButton = elements.thumbnailButton;
  7379. this.outlineButton = elements.outlineButton;
  7380. this.attachmentsButton = elements.attachmentsButton;
  7381. this.layersButton = elements.layersButton;
  7382. this.thumbnailView = elements.thumbnailView;
  7383. this.outlineView = elements.outlineView;
  7384. this.attachmentsView = elements.attachmentsView;
  7385. this.layersView = elements.layersView;
  7386. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  7387. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7388. this.eventBus = eventBus;
  7389. this.l10n = l10n;
  7390. l10n.getDirection().then(dir => {
  7391. this.#isRTL = dir === "rtl";
  7392. });
  7393. this.#addEventListeners();
  7394. }
  7395. reset() {
  7396. this.isInitialViewSet = false;
  7397. this.isInitialEventDispatched = false;
  7398. this.#hideUINotification(true);
  7399. this.switchView(_ui_utils.SidebarView.THUMBS);
  7400. this.outlineButton.disabled = false;
  7401. this.attachmentsButton.disabled = false;
  7402. this.layersButton.disabled = false;
  7403. this._currentOutlineItemButton.disabled = true;
  7404. }
  7405. get visibleView() {
  7406. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  7407. }
  7408. setInitialView(view = _ui_utils.SidebarView.NONE) {
  7409. if (this.isInitialViewSet) {
  7410. return;
  7411. }
  7412. this.isInitialViewSet = true;
  7413. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  7414. this.#dispatchEvent();
  7415. return;
  7416. }
  7417. this.switchView(view, true);
  7418. if (!this.isInitialEventDispatched) {
  7419. this.#dispatchEvent();
  7420. }
  7421. }
  7422. switchView(view, forceOpen = false) {
  7423. const isViewChanged = view !== this.active;
  7424. let forceRendering = false;
  7425. switch (view) {
  7426. case _ui_utils.SidebarView.NONE:
  7427. if (this.isOpen) {
  7428. this.close();
  7429. }
  7430. return;
  7431. case _ui_utils.SidebarView.THUMBS:
  7432. if (this.isOpen && isViewChanged) {
  7433. forceRendering = true;
  7434. }
  7435. break;
  7436. case _ui_utils.SidebarView.OUTLINE:
  7437. if (this.outlineButton.disabled) {
  7438. return;
  7439. }
  7440. break;
  7441. case _ui_utils.SidebarView.ATTACHMENTS:
  7442. if (this.attachmentsButton.disabled) {
  7443. return;
  7444. }
  7445. break;
  7446. case _ui_utils.SidebarView.LAYERS:
  7447. if (this.layersButton.disabled) {
  7448. return;
  7449. }
  7450. break;
  7451. default:
  7452. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7453. return;
  7454. }
  7455. this.active = view;
  7456. (0, _ui_utils.toggleCheckedBtn)(this.thumbnailButton, view === _ui_utils.SidebarView.THUMBS, this.thumbnailView);
  7457. (0, _ui_utils.toggleCheckedBtn)(this.outlineButton, view === _ui_utils.SidebarView.OUTLINE, this.outlineView);
  7458. (0, _ui_utils.toggleCheckedBtn)(this.attachmentsButton, view === _ui_utils.SidebarView.ATTACHMENTS, this.attachmentsView);
  7459. (0, _ui_utils.toggleCheckedBtn)(this.layersButton, view === _ui_utils.SidebarView.LAYERS, this.layersView);
  7460. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  7461. if (forceOpen && !this.isOpen) {
  7462. this.open();
  7463. return;
  7464. }
  7465. if (forceRendering) {
  7466. this.onUpdateThumbnails();
  7467. this.onToggled();
  7468. }
  7469. if (isViewChanged) {
  7470. this.#dispatchEvent();
  7471. }
  7472. }
  7473. open() {
  7474. if (this.isOpen) {
  7475. return;
  7476. }
  7477. this.isOpen = true;
  7478. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true);
  7479. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7480. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7481. this.onUpdateThumbnails();
  7482. }
  7483. this.onToggled();
  7484. this.#dispatchEvent();
  7485. this.#hideUINotification();
  7486. }
  7487. close() {
  7488. if (!this.isOpen) {
  7489. return;
  7490. }
  7491. this.isOpen = false;
  7492. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false);
  7493. this.outerContainer.classList.add("sidebarMoving");
  7494. this.outerContainer.classList.remove("sidebarOpen");
  7495. this.onToggled();
  7496. this.#dispatchEvent();
  7497. }
  7498. toggle() {
  7499. if (this.isOpen) {
  7500. this.close();
  7501. } else {
  7502. this.open();
  7503. }
  7504. }
  7505. #dispatchEvent() {
  7506. if (this.isInitialViewSet) {
  7507. this.isInitialEventDispatched ||= true;
  7508. }
  7509. this.eventBus.dispatch("sidebarviewchanged", {
  7510. source: this,
  7511. view: this.visibleView
  7512. });
  7513. }
  7514. #showUINotification() {
  7515. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2");
  7516. this.l10n.translate(this.toggleButton);
  7517. if (!this.isOpen) {
  7518. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7519. }
  7520. }
  7521. #hideUINotification(reset = false) {
  7522. if (this.isOpen || reset) {
  7523. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7524. }
  7525. if (reset) {
  7526. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
  7527. this.l10n.translate(this.toggleButton);
  7528. }
  7529. }
  7530. #addEventListeners() {
  7531. this.sidebarContainer.addEventListener("transitionend", evt => {
  7532. if (evt.target === this.sidebarContainer) {
  7533. this.outerContainer.classList.remove("sidebarMoving");
  7534. }
  7535. });
  7536. this.toggleButton.addEventListener("click", () => {
  7537. this.toggle();
  7538. });
  7539. this.thumbnailButton.addEventListener("click", () => {
  7540. this.switchView(_ui_utils.SidebarView.THUMBS);
  7541. });
  7542. this.outlineButton.addEventListener("click", () => {
  7543. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7544. });
  7545. this.outlineButton.addEventListener("dblclick", () => {
  7546. this.eventBus.dispatch("toggleoutlinetree", {
  7547. source: this
  7548. });
  7549. });
  7550. this.attachmentsButton.addEventListener("click", () => {
  7551. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7552. });
  7553. this.layersButton.addEventListener("click", () => {
  7554. this.switchView(_ui_utils.SidebarView.LAYERS);
  7555. });
  7556. this.layersButton.addEventListener("dblclick", () => {
  7557. this.eventBus.dispatch("resetlayers", {
  7558. source: this
  7559. });
  7560. });
  7561. this._currentOutlineItemButton.addEventListener("click", () => {
  7562. this.eventBus.dispatch("currentoutlineitem", {
  7563. source: this
  7564. });
  7565. });
  7566. const onTreeLoaded = (count, button, view) => {
  7567. button.disabled = !count;
  7568. if (count) {
  7569. this.#showUINotification();
  7570. } else if (this.active === view) {
  7571. this.switchView(_ui_utils.SidebarView.THUMBS);
  7572. }
  7573. };
  7574. this.eventBus._on("outlineloaded", evt => {
  7575. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7576. evt.currentOutlineItemPromise.then(enabled => {
  7577. if (!this.isInitialViewSet) {
  7578. return;
  7579. }
  7580. this._currentOutlineItemButton.disabled = !enabled;
  7581. });
  7582. });
  7583. this.eventBus._on("attachmentsloaded", evt => {
  7584. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7585. });
  7586. this.eventBus._on("layersloaded", evt => {
  7587. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7588. });
  7589. this.eventBus._on("presentationmodechanged", evt => {
  7590. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  7591. this.onUpdateThumbnails();
  7592. }
  7593. });
  7594. this.resizer.addEventListener("mousedown", evt => {
  7595. if (evt.button !== 0) {
  7596. return;
  7597. }
  7598. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7599. window.addEventListener("mousemove", this.#mouseMoveBound);
  7600. window.addEventListener("mouseup", this.#mouseUpBound);
  7601. });
  7602. this.eventBus._on("resize", evt => {
  7603. if (evt.source !== window) {
  7604. return;
  7605. }
  7606. this.#outerContainerWidth = null;
  7607. if (!this.#width) {
  7608. return;
  7609. }
  7610. if (!this.isOpen) {
  7611. this.#updateWidth(this.#width);
  7612. return;
  7613. }
  7614. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7615. const updated = this.#updateWidth(this.#width);
  7616. Promise.resolve().then(() => {
  7617. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7618. if (updated) {
  7619. this.eventBus.dispatch("resize", {
  7620. source: this
  7621. });
  7622. }
  7623. });
  7624. });
  7625. }
  7626. get outerContainerWidth() {
  7627. return this.#outerContainerWidth ||= this.outerContainer.clientWidth;
  7628. }
  7629. #updateWidth(width = 0) {
  7630. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7631. if (width > maxWidth) {
  7632. width = maxWidth;
  7633. }
  7634. if (width < SIDEBAR_MIN_WIDTH) {
  7635. width = SIDEBAR_MIN_WIDTH;
  7636. }
  7637. if (width === this.#width) {
  7638. return false;
  7639. }
  7640. this.#width = width;
  7641. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7642. return true;
  7643. }
  7644. #mouseMove(evt) {
  7645. let width = evt.clientX;
  7646. if (this.#isRTL) {
  7647. width = this.outerContainerWidth - width;
  7648. }
  7649. this.#updateWidth(width);
  7650. }
  7651. #mouseUp(evt) {
  7652. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7653. this.eventBus.dispatch("resize", {
  7654. source: this
  7655. });
  7656. window.removeEventListener("mousemove", this.#mouseMoveBound);
  7657. window.removeEventListener("mouseup", this.#mouseUpBound);
  7658. }
  7659. }
  7660. exports.PDFSidebar = PDFSidebar;
  7661. /***/
  7662. }),
  7663. /* 26 */
  7664. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7665. Object.defineProperty(exports, "__esModule", ({
  7666. value: true
  7667. }));
  7668. exports.PDFThumbnailViewer = void 0;
  7669. var _ui_utils = __webpack_require__(3);
  7670. var _pdf_thumbnail_view = __webpack_require__(27);
  7671. const THUMBNAIL_SCROLL_MARGIN = -19;
  7672. const THUMBNAIL_SELECTED_CLASS = "selected";
  7673. class PDFThumbnailViewer {
  7674. constructor({
  7675. container,
  7676. eventBus,
  7677. linkService,
  7678. renderingQueue,
  7679. l10n,
  7680. pageColors
  7681. }) {
  7682. this.container = container;
  7683. this.eventBus = eventBus;
  7684. this.linkService = linkService;
  7685. this.renderingQueue = renderingQueue;
  7686. this.l10n = l10n;
  7687. this.pageColors = pageColors || null;
  7688. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7689. this._resetView();
  7690. }
  7691. _scrollUpdated() {
  7692. this.renderingQueue.renderHighestPriority();
  7693. }
  7694. getThumbnail(index) {
  7695. return this._thumbnails[index];
  7696. }
  7697. _getVisibleThumbs() {
  7698. return (0, _ui_utils.getVisibleElements)({
  7699. scrollEl: this.container,
  7700. views: this._thumbnails
  7701. });
  7702. }
  7703. scrollThumbnailIntoView(pageNumber) {
  7704. if (!this.pdfDocument) {
  7705. return;
  7706. }
  7707. const thumbnailView = this._thumbnails[pageNumber - 1];
  7708. if (!thumbnailView) {
  7709. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7710. return;
  7711. }
  7712. if (pageNumber !== this._currentPageNumber) {
  7713. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7714. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7715. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7716. }
  7717. const {
  7718. first,
  7719. last,
  7720. views
  7721. } = this._getVisibleThumbs();
  7722. if (views.length > 0) {
  7723. let shouldScroll = false;
  7724. if (pageNumber <= first.id || pageNumber >= last.id) {
  7725. shouldScroll = true;
  7726. } else {
  7727. for (const {
  7728. id,
  7729. percent
  7730. } of views) {
  7731. if (id !== pageNumber) {
  7732. continue;
  7733. }
  7734. shouldScroll = percent < 100;
  7735. break;
  7736. }
  7737. }
  7738. if (shouldScroll) {
  7739. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7740. top: THUMBNAIL_SCROLL_MARGIN
  7741. });
  7742. }
  7743. }
  7744. this._currentPageNumber = pageNumber;
  7745. }
  7746. get pagesRotation() {
  7747. return this._pagesRotation;
  7748. }
  7749. set pagesRotation(rotation) {
  7750. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7751. throw new Error("Invalid thumbnails rotation angle.");
  7752. }
  7753. if (!this.pdfDocument) {
  7754. return;
  7755. }
  7756. if (this._pagesRotation === rotation) {
  7757. return;
  7758. }
  7759. this._pagesRotation = rotation;
  7760. const updateArgs = {
  7761. rotation
  7762. };
  7763. for (const thumbnail of this._thumbnails) {
  7764. thumbnail.update(updateArgs);
  7765. }
  7766. }
  7767. cleanup() {
  7768. for (const thumbnail of this._thumbnails) {
  7769. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7770. thumbnail.reset();
  7771. }
  7772. }
  7773. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7774. }
  7775. _resetView() {
  7776. this._thumbnails = [];
  7777. this._currentPageNumber = 1;
  7778. this._pageLabels = null;
  7779. this._pagesRotation = 0;
  7780. this.container.textContent = "";
  7781. }
  7782. setDocument(pdfDocument) {
  7783. if (this.pdfDocument) {
  7784. this._cancelRendering();
  7785. this._resetView();
  7786. }
  7787. this.pdfDocument = pdfDocument;
  7788. if (!pdfDocument) {
  7789. return;
  7790. }
  7791. const firstPagePromise = pdfDocument.getPage(1);
  7792. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7793. firstPagePromise.then(firstPdfPage => {
  7794. const pagesCount = pdfDocument.numPages;
  7795. const viewport = firstPdfPage.getViewport({
  7796. scale: 1
  7797. });
  7798. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7799. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7800. container: this.container,
  7801. eventBus: this.eventBus,
  7802. id: pageNum,
  7803. defaultViewport: viewport.clone(),
  7804. optionalContentConfigPromise,
  7805. linkService: this.linkService,
  7806. renderingQueue: this.renderingQueue,
  7807. l10n: this.l10n,
  7808. pageColors: this.pageColors
  7809. });
  7810. this._thumbnails.push(thumbnail);
  7811. }
  7812. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  7813. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7814. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7815. }).catch(reason => {
  7816. console.error("Unable to initialize thumbnail viewer", reason);
  7817. });
  7818. }
  7819. _cancelRendering() {
  7820. for (const thumbnail of this._thumbnails) {
  7821. thumbnail.cancelRendering();
  7822. }
  7823. }
  7824. setPageLabels(labels) {
  7825. if (!this.pdfDocument) {
  7826. return;
  7827. }
  7828. if (!labels) {
  7829. this._pageLabels = null;
  7830. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7831. this._pageLabels = null;
  7832. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7833. } else {
  7834. this._pageLabels = labels;
  7835. }
  7836. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7837. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7838. }
  7839. }
  7840. async #ensurePdfPageLoaded(thumbView) {
  7841. if (thumbView.pdfPage) {
  7842. return thumbView.pdfPage;
  7843. }
  7844. try {
  7845. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7846. if (!thumbView.pdfPage) {
  7847. thumbView.setPdfPage(pdfPage);
  7848. }
  7849. return pdfPage;
  7850. } catch (reason) {
  7851. console.error("Unable to get page for thumb view", reason);
  7852. return null;
  7853. }
  7854. }
  7855. #getScrollAhead(visible) {
  7856. if (visible.first?.id === 1) {
  7857. return true;
  7858. } else if (visible.last?.id === this._thumbnails.length) {
  7859. return false;
  7860. }
  7861. return this.scroll.down;
  7862. }
  7863. forceRendering() {
  7864. const visibleThumbs = this._getVisibleThumbs();
  7865. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7866. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7867. if (thumbView) {
  7868. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7869. this.renderingQueue.renderView(thumbView);
  7870. });
  7871. return true;
  7872. }
  7873. return false;
  7874. }
  7875. }
  7876. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7877. /***/
  7878. }),
  7879. /* 27 */
  7880. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7881. Object.defineProperty(exports, "__esModule", ({
  7882. value: true
  7883. }));
  7884. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7885. var _ui_utils = __webpack_require__(3);
  7886. var _pdfjsLib = __webpack_require__(4);
  7887. const DRAW_UPSCALE_FACTOR = 2;
  7888. const MAX_NUM_SCALING_STEPS = 3;
  7889. const THUMBNAIL_WIDTH = 98;
  7890. class TempImageFactory {
  7891. static #tempCanvas = null;
  7892. static getCanvas(width, height) {
  7893. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7894. tempCanvas.width = width;
  7895. tempCanvas.height = height;
  7896. const ctx = tempCanvas.getContext("2d", {
  7897. alpha: false
  7898. });
  7899. ctx.save();
  7900. ctx.fillStyle = "rgb(255, 255, 255)";
  7901. ctx.fillRect(0, 0, width, height);
  7902. ctx.restore();
  7903. return [tempCanvas, tempCanvas.getContext("2d")];
  7904. }
  7905. static destroyCanvas() {
  7906. const tempCanvas = this.#tempCanvas;
  7907. if (tempCanvas) {
  7908. tempCanvas.width = 0;
  7909. tempCanvas.height = 0;
  7910. }
  7911. this.#tempCanvas = null;
  7912. }
  7913. }
  7914. exports.TempImageFactory = TempImageFactory;
  7915. class PDFThumbnailView {
  7916. constructor({
  7917. container,
  7918. eventBus,
  7919. id,
  7920. defaultViewport,
  7921. optionalContentConfigPromise,
  7922. linkService,
  7923. renderingQueue,
  7924. l10n,
  7925. pageColors
  7926. }) {
  7927. this.id = id;
  7928. this.renderingId = "thumbnail" + id;
  7929. this.pageLabel = null;
  7930. this.pdfPage = null;
  7931. this.rotation = 0;
  7932. this.viewport = defaultViewport;
  7933. this.pdfPageRotate = defaultViewport.rotation;
  7934. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7935. this.pageColors = pageColors || null;
  7936. this.eventBus = eventBus;
  7937. this.linkService = linkService;
  7938. this.renderingQueue = renderingQueue;
  7939. this.renderTask = null;
  7940. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7941. this.resume = null;
  7942. this.l10n = l10n;
  7943. const anchor = document.createElement("a");
  7944. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7945. this._thumbPageTitle.then(msg => {
  7946. anchor.title = msg;
  7947. });
  7948. anchor.onclick = function () {
  7949. linkService.goToPage(id);
  7950. return false;
  7951. };
  7952. this.anchor = anchor;
  7953. const div = document.createElement("div");
  7954. div.className = "thumbnail";
  7955. div.setAttribute("data-page-number", this.id);
  7956. this.div = div;
  7957. this.#updateDims();
  7958. const img = document.createElement("div");
  7959. img.className = "thumbnailImage";
  7960. this._placeholderImg = img;
  7961. div.append(img);
  7962. anchor.append(div);
  7963. container.append(anchor);
  7964. }
  7965. #updateDims() {
  7966. const {
  7967. width,
  7968. height
  7969. } = this.viewport;
  7970. const ratio = width / height;
  7971. this.canvasWidth = THUMBNAIL_WIDTH;
  7972. this.canvasHeight = this.canvasWidth / ratio | 0;
  7973. this.scale = this.canvasWidth / width;
  7974. const {
  7975. style
  7976. } = this.div;
  7977. style.setProperty("--thumbnail-width", `${this.canvasWidth}px`);
  7978. style.setProperty("--thumbnail-height", `${this.canvasHeight}px`);
  7979. }
  7980. setPdfPage(pdfPage) {
  7981. this.pdfPage = pdfPage;
  7982. this.pdfPageRotate = pdfPage.rotate;
  7983. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7984. this.viewport = pdfPage.getViewport({
  7985. scale: 1,
  7986. rotation: totalRotation
  7987. });
  7988. this.reset();
  7989. }
  7990. reset() {
  7991. this.cancelRendering();
  7992. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7993. this.div.removeAttribute("data-loaded");
  7994. this.image?.replaceWith(this._placeholderImg);
  7995. this.#updateDims();
  7996. if (this.image) {
  7997. this.image.removeAttribute("src");
  7998. delete this.image;
  7999. }
  8000. }
  8001. update({
  8002. rotation = null
  8003. }) {
  8004. if (typeof rotation === "number") {
  8005. this.rotation = rotation;
  8006. }
  8007. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8008. this.viewport = this.viewport.clone({
  8009. scale: 1,
  8010. rotation: totalRotation
  8011. });
  8012. this.reset();
  8013. }
  8014. cancelRendering() {
  8015. if (this.renderTask) {
  8016. this.renderTask.cancel();
  8017. this.renderTask = null;
  8018. }
  8019. this.resume = null;
  8020. }
  8021. _getPageDrawContext(upscaleFactor = 1) {
  8022. const canvas = document.createElement("canvas");
  8023. const ctx = canvas.getContext("2d", {
  8024. alpha: false
  8025. });
  8026. const outputScale = new _ui_utils.OutputScale();
  8027. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  8028. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  8029. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  8030. return {
  8031. ctx,
  8032. canvas,
  8033. transform
  8034. };
  8035. }
  8036. _convertCanvasToImage(canvas) {
  8037. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8038. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  8039. }
  8040. const reducedCanvas = this._reduceImage(canvas);
  8041. const image = document.createElement("img");
  8042. image.className = "thumbnailImage";
  8043. this._thumbPageCanvas.then(msg => {
  8044. image.setAttribute("aria-label", msg);
  8045. });
  8046. image.src = reducedCanvas.toDataURL();
  8047. this.image = image;
  8048. this.div.setAttribute("data-loaded", true);
  8049. this._placeholderImg.replaceWith(image);
  8050. reducedCanvas.width = 0;
  8051. reducedCanvas.height = 0;
  8052. }
  8053. async #finishRenderTask(renderTask, canvas, error = null) {
  8054. if (renderTask === this.renderTask) {
  8055. this.renderTask = null;
  8056. }
  8057. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  8058. return;
  8059. }
  8060. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8061. this._convertCanvasToImage(canvas);
  8062. if (error) {
  8063. throw error;
  8064. }
  8065. }
  8066. async draw() {
  8067. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8068. console.error("Must be in new state before drawing");
  8069. return undefined;
  8070. }
  8071. const {
  8072. pdfPage
  8073. } = this;
  8074. if (!pdfPage) {
  8075. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8076. throw new Error("pdfPage is not loaded");
  8077. }
  8078. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8079. const {
  8080. ctx,
  8081. canvas,
  8082. transform
  8083. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  8084. const drawViewport = this.viewport.clone({
  8085. scale: DRAW_UPSCALE_FACTOR * this.scale
  8086. });
  8087. const renderContinueCallback = cont => {
  8088. if (!this.renderingQueue.isHighestPriority(this)) {
  8089. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  8090. this.resume = () => {
  8091. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8092. cont();
  8093. };
  8094. return;
  8095. }
  8096. cont();
  8097. };
  8098. const renderContext = {
  8099. canvasContext: ctx,
  8100. transform,
  8101. viewport: drawViewport,
  8102. optionalContentConfigPromise: this._optionalContentConfigPromise,
  8103. pageColors: this.pageColors
  8104. };
  8105. const renderTask = this.renderTask = pdfPage.render(renderContext);
  8106. renderTask.onContinue = renderContinueCallback;
  8107. const resultPromise = renderTask.promise.then(() => this.#finishRenderTask(renderTask, canvas), error => this.#finishRenderTask(renderTask, canvas, error));
  8108. resultPromise.finally(() => {
  8109. canvas.width = 0;
  8110. canvas.height = 0;
  8111. this.eventBus.dispatch("thumbnailrendered", {
  8112. source: this,
  8113. pageNumber: this.id,
  8114. pdfPage: this.pdfPage
  8115. });
  8116. });
  8117. return resultPromise;
  8118. }
  8119. setImage(pageView) {
  8120. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8121. return;
  8122. }
  8123. const {
  8124. thumbnailCanvas: canvas,
  8125. pdfPage,
  8126. scale
  8127. } = pageView;
  8128. if (!canvas) {
  8129. return;
  8130. }
  8131. if (!this.pdfPage) {
  8132. this.setPdfPage(pdfPage);
  8133. }
  8134. if (scale < this.scale) {
  8135. return;
  8136. }
  8137. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8138. this._convertCanvasToImage(canvas);
  8139. }
  8140. _reduceImage(img) {
  8141. const {
  8142. ctx,
  8143. canvas
  8144. } = this._getPageDrawContext();
  8145. if (img.width <= 2 * canvas.width) {
  8146. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  8147. return canvas;
  8148. }
  8149. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  8150. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  8151. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  8152. while (reducedWidth > img.width || reducedHeight > img.height) {
  8153. reducedWidth >>= 1;
  8154. reducedHeight >>= 1;
  8155. }
  8156. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  8157. while (reducedWidth > 2 * canvas.width) {
  8158. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  8159. reducedWidth >>= 1;
  8160. reducedHeight >>= 1;
  8161. }
  8162. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  8163. return canvas;
  8164. }
  8165. get _thumbPageTitle() {
  8166. return this.l10n.get("thumb_page_title", {
  8167. page: this.pageLabel ?? this.id
  8168. });
  8169. }
  8170. get _thumbPageCanvas() {
  8171. return this.l10n.get("thumb_page_canvas", {
  8172. page: this.pageLabel ?? this.id
  8173. });
  8174. }
  8175. setPageLabel(label) {
  8176. this.pageLabel = typeof label === "string" ? label : null;
  8177. this._thumbPageTitle.then(msg => {
  8178. this.anchor.title = msg;
  8179. });
  8180. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8181. return;
  8182. }
  8183. this._thumbPageCanvas.then(msg => {
  8184. this.image?.setAttribute("aria-label", msg);
  8185. });
  8186. }
  8187. }
  8188. exports.PDFThumbnailView = PDFThumbnailView;
  8189. /***/
  8190. }),
  8191. /* 28 */
  8192. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8193. Object.defineProperty(exports, "__esModule", ({
  8194. value: true
  8195. }));
  8196. exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
  8197. var _pdfjsLib = __webpack_require__(4);
  8198. var _ui_utils = __webpack_require__(3);
  8199. var _l10n_utils = __webpack_require__(29);
  8200. var _pdf_page_view = __webpack_require__(30);
  8201. var _pdf_rendering_queue = __webpack_require__(23);
  8202. var _pdf_link_service = __webpack_require__(7);
  8203. const DEFAULT_CACHE_SIZE = 10;
  8204. const PagesCountLimit = {
  8205. FORCE_SCROLL_MODE_PAGE: 15000,
  8206. FORCE_LAZY_PAGE_INIT: 7500,
  8207. PAUSE_EAGER_PAGE_INIT: 250
  8208. };
  8209. exports.PagesCountLimit = PagesCountLimit;
  8210. function isValidAnnotationEditorMode(mode) {
  8211. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  8212. }
  8213. class PDFPageViewBuffer {
  8214. #buf = new Set();
  8215. #size = 0;
  8216. constructor(size) {
  8217. this.#size = size;
  8218. }
  8219. push(view) {
  8220. const buf = this.#buf;
  8221. if (buf.has(view)) {
  8222. buf.delete(view);
  8223. }
  8224. buf.add(view);
  8225. if (buf.size > this.#size) {
  8226. this.#destroyFirstView();
  8227. }
  8228. }
  8229. resize(newSize, idsToKeep = null) {
  8230. this.#size = newSize;
  8231. const buf = this.#buf;
  8232. if (idsToKeep) {
  8233. const ii = buf.size;
  8234. let i = 1;
  8235. for (const view of buf) {
  8236. if (idsToKeep.has(view.id)) {
  8237. buf.delete(view);
  8238. buf.add(view);
  8239. }
  8240. if (++i > ii) {
  8241. break;
  8242. }
  8243. }
  8244. }
  8245. while (buf.size > this.#size) {
  8246. this.#destroyFirstView();
  8247. }
  8248. }
  8249. has(view) {
  8250. return this.#buf.has(view);
  8251. }
  8252. [Symbol.iterator]() {
  8253. return this.#buf.keys();
  8254. }
  8255. #destroyFirstView() {
  8256. const firstView = this.#buf.keys().next().value;
  8257. firstView?.destroy();
  8258. this.#buf.delete(firstView);
  8259. }
  8260. }
  8261. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  8262. class PDFViewer {
  8263. #buffer = null;
  8264. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  8265. #annotationEditorUIManager = null;
  8266. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8267. #containerTopLeft = null;
  8268. #copyCallbackBound = null;
  8269. #enablePermissions = false;
  8270. #getAllTextInProgress = false;
  8271. #hiddenCopyElement = null;
  8272. #interruptCopyCondition = false;
  8273. #previousContainerHeight = 0;
  8274. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  8275. #scrollModePageState = null;
  8276. #onVisibilityChange = null;
  8277. #scaleTimeoutId = null;
  8278. #textLayerMode = _ui_utils.TextLayerMode.ENABLE;
  8279. constructor(options) {
  8280. const viewerVersion = '3.10.111';
  8281. if (_pdfjsLib.version !== viewerVersion) {
  8282. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  8283. }
  8284. this.container = options.container;
  8285. this.viewer = options.viewer || options.container.firstElementChild;
  8286. if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
  8287. throw new Error("Invalid `container` and/or `viewer` option.");
  8288. }
  8289. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  8290. throw new Error("The `container` must be absolutely positioned.");
  8291. }
  8292. this.#resizeObserver.observe(this.container);
  8293. this.eventBus = options.eventBus;
  8294. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8295. this.downloadManager = options.downloadManager || null;
  8296. this.findController = options.findController || null;
  8297. if (this.findController) {
  8298. this.findController.onIsPageVisible = pageNumber => this._getVisiblePages().ids.has(pageNumber);
  8299. }
  8300. this._scriptingManager = options.scriptingManager || null;
  8301. this.#textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  8302. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8303. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
  8304. this.imageResourcesPath = options.imageResourcesPath || "";
  8305. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8306. this.removePageBorders = options.removePageBorders || false;
  8307. if (options.useOnlyCssZoom) {
  8308. console.error("useOnlyCssZoom was removed, please use `maxCanvasPixels = 0` instead.");
  8309. options.maxCanvasPixels = 0;
  8310. }
  8311. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  8312. this.maxCanvasPixels = options.maxCanvasPixels;
  8313. this.l10n = options.l10n || _l10n_utils.NullL10n;
  8314. this.#enablePermissions = options.enablePermissions || false;
  8315. this.pageColors = options.pageColors || null;
  8316. this.defaultRenderingQueue = !options.renderingQueue;
  8317. if (this.defaultRenderingQueue) {
  8318. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8319. this.renderingQueue.setViewer(this);
  8320. } else {
  8321. this.renderingQueue = options.renderingQueue;
  8322. }
  8323. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8324. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8325. this._onBeforeDraw = this._onAfterDraw = null;
  8326. this._resetView();
  8327. if (this.removePageBorders) {
  8328. this.viewer.classList.add("removePageBorders");
  8329. }
  8330. this.#updateContainerHeightCss();
  8331. this.eventBus._on("thumbnailrendered", ({
  8332. pageNumber,
  8333. pdfPage
  8334. }) => {
  8335. const pageView = this._pages[pageNumber - 1];
  8336. if (!this.#buffer.has(pageView)) {
  8337. pdfPage?.cleanup();
  8338. }
  8339. });
  8340. }
  8341. get pagesCount() {
  8342. return this._pages.length;
  8343. }
  8344. getPageView(index) {
  8345. return this._pages[index];
  8346. }
  8347. getCachedPageViews() {
  8348. return new Set(this.#buffer);
  8349. }
  8350. get pageViewsReady() {
  8351. return this._pagesCapability.settled && this._pages.every(pageView => pageView?.pdfPage);
  8352. }
  8353. get renderForms() {
  8354. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8355. }
  8356. get enableScripting() {
  8357. return !!this._scriptingManager;
  8358. }
  8359. get currentPageNumber() {
  8360. return this._currentPageNumber;
  8361. }
  8362. set currentPageNumber(val) {
  8363. if (!Number.isInteger(val)) {
  8364. throw new Error("Invalid page number.");
  8365. }
  8366. if (!this.pdfDocument) {
  8367. return;
  8368. }
  8369. if (!this._setCurrentPageNumber(val, true)) {
  8370. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  8371. }
  8372. }
  8373. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  8374. if (this._currentPageNumber === val) {
  8375. if (resetCurrentPageView) {
  8376. this.#resetCurrentPageView();
  8377. }
  8378. return true;
  8379. }
  8380. if (!(0 < val && val <= this.pagesCount)) {
  8381. return false;
  8382. }
  8383. const previous = this._currentPageNumber;
  8384. this._currentPageNumber = val;
  8385. this.eventBus.dispatch("pagechanging", {
  8386. source: this,
  8387. pageNumber: val,
  8388. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8389. previous
  8390. });
  8391. if (resetCurrentPageView) {
  8392. this.#resetCurrentPageView();
  8393. }
  8394. return true;
  8395. }
  8396. get currentPageLabel() {
  8397. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8398. }
  8399. set currentPageLabel(val) {
  8400. if (!this.pdfDocument) {
  8401. return;
  8402. }
  8403. let page = val | 0;
  8404. if (this._pageLabels) {
  8405. const i = this._pageLabels.indexOf(val);
  8406. if (i >= 0) {
  8407. page = i + 1;
  8408. }
  8409. }
  8410. if (!this._setCurrentPageNumber(page, true)) {
  8411. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8412. }
  8413. }
  8414. get currentScale() {
  8415. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8416. }
  8417. set currentScale(val) {
  8418. if (isNaN(val)) {
  8419. throw new Error("Invalid numeric scale.");
  8420. }
  8421. if (!this.pdfDocument) {
  8422. return;
  8423. }
  8424. this.#setScale(val, {
  8425. noScroll: false
  8426. });
  8427. }
  8428. get currentScaleValue() {
  8429. return this._currentScaleValue;
  8430. }
  8431. set currentScaleValue(val) {
  8432. if (!this.pdfDocument) {
  8433. return;
  8434. }
  8435. this.#setScale(val, {
  8436. noScroll: false
  8437. });
  8438. }
  8439. get pagesRotation() {
  8440. return this._pagesRotation;
  8441. }
  8442. set pagesRotation(rotation) {
  8443. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8444. throw new Error("Invalid pages rotation angle.");
  8445. }
  8446. if (!this.pdfDocument) {
  8447. return;
  8448. }
  8449. rotation %= 360;
  8450. if (rotation < 0) {
  8451. rotation += 360;
  8452. }
  8453. if (this._pagesRotation === rotation) {
  8454. return;
  8455. }
  8456. this._pagesRotation = rotation;
  8457. const pageNumber = this._currentPageNumber;
  8458. this.refresh(true, {
  8459. rotation
  8460. });
  8461. if (this._currentScaleValue) {
  8462. this.#setScale(this._currentScaleValue, {
  8463. noScroll: true
  8464. });
  8465. }
  8466. this.eventBus.dispatch("rotationchanging", {
  8467. source: this,
  8468. pagesRotation: rotation,
  8469. pageNumber
  8470. });
  8471. if (this.defaultRenderingQueue) {
  8472. this.update();
  8473. }
  8474. }
  8475. get firstPagePromise() {
  8476. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8477. }
  8478. get onePageRendered() {
  8479. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8480. }
  8481. get pagesPromise() {
  8482. return this.pdfDocument ? this._pagesCapability.promise : null;
  8483. }
  8484. #layerProperties() {
  8485. const self = this;
  8486. return {
  8487. get annotationEditorUIManager() {
  8488. return self.#annotationEditorUIManager;
  8489. },
  8490. get annotationStorage() {
  8491. return self.pdfDocument?.annotationStorage;
  8492. },
  8493. get downloadManager() {
  8494. return self.downloadManager;
  8495. },
  8496. get enableScripting() {
  8497. return !!self._scriptingManager;
  8498. },
  8499. get fieldObjectsPromise() {
  8500. return self.pdfDocument?.getFieldObjects();
  8501. },
  8502. get findController() {
  8503. return self.findController;
  8504. },
  8505. get hasJSActionsPromise() {
  8506. return self.pdfDocument?.hasJSActions();
  8507. },
  8508. get linkService() {
  8509. return self.linkService;
  8510. }
  8511. };
  8512. }
  8513. #initializePermissions(permissions) {
  8514. const params = {
  8515. annotationEditorMode: this.#annotationEditorMode,
  8516. annotationMode: this.#annotationMode,
  8517. textLayerMode: this.#textLayerMode
  8518. };
  8519. if (!permissions) {
  8520. return params;
  8521. }
  8522. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY) && this.#textLayerMode === _ui_utils.TextLayerMode.ENABLE) {
  8523. params.textLayerMode = _ui_utils.TextLayerMode.ENABLE_PERMISSIONS;
  8524. }
  8525. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  8526. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8527. }
  8528. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8529. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8530. }
  8531. return params;
  8532. }
  8533. #onePageRenderedOrForceFetch() {
  8534. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8535. return Promise.resolve();
  8536. }
  8537. const visibilityChangePromise = new Promise(resolve => {
  8538. this.#onVisibilityChange = () => {
  8539. if (document.visibilityState !== "hidden") {
  8540. return;
  8541. }
  8542. resolve();
  8543. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8544. this.#onVisibilityChange = null;
  8545. };
  8546. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8547. });
  8548. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8549. }
  8550. async getAllText() {
  8551. const texts = [];
  8552. const buffer = [];
  8553. for (let pageNum = 1, pagesCount = this.pdfDocument.numPages; pageNum <= pagesCount; ++pageNum) {
  8554. if (this.#interruptCopyCondition) {
  8555. return null;
  8556. }
  8557. buffer.length = 0;
  8558. const page = await this.pdfDocument.getPage(pageNum);
  8559. const {
  8560. items
  8561. } = await page.getTextContent();
  8562. for (const item of items) {
  8563. if (item.str) {
  8564. buffer.push(item.str);
  8565. }
  8566. if (item.hasEOL) {
  8567. buffer.push("\n");
  8568. }
  8569. }
  8570. texts.push((0, _ui_utils.removeNullCharacters)(buffer.join("")));
  8571. }
  8572. return texts.join("\n");
  8573. }
  8574. #copyCallback(textLayerMode, event) {
  8575. const selection = document.getSelection();
  8576. const {
  8577. focusNode,
  8578. anchorNode
  8579. } = selection;
  8580. if (anchorNode && focusNode && selection.containsNode(this.#hiddenCopyElement)) {
  8581. if (this.#getAllTextInProgress || textLayerMode === _ui_utils.TextLayerMode.ENABLE_PERMISSIONS) {
  8582. event.preventDefault();
  8583. event.stopPropagation();
  8584. return;
  8585. }
  8586. this.#getAllTextInProgress = true;
  8587. const savedCursor = this.container.style.cursor;
  8588. this.container.style.cursor = "wait";
  8589. const interruptCopy = ev => this.#interruptCopyCondition = ev.key === "Escape";
  8590. window.addEventListener("keydown", interruptCopy);
  8591. this.getAllText().then(async text => {
  8592. if (text !== null) {
  8593. await navigator.clipboard.writeText(text);
  8594. }
  8595. }).catch(reason => {
  8596. console.warn(`Something goes wrong when extracting the text: ${reason.message}`);
  8597. }).finally(() => {
  8598. this.#getAllTextInProgress = false;
  8599. this.#interruptCopyCondition = false;
  8600. window.removeEventListener("keydown", interruptCopy);
  8601. this.container.style.cursor = savedCursor;
  8602. });
  8603. event.preventDefault();
  8604. event.stopPropagation();
  8605. }
  8606. }
  8607. setDocument(pdfDocument) {
  8608. if (this.pdfDocument) {
  8609. this.eventBus.dispatch("pagesdestroy", {
  8610. source: this
  8611. });
  8612. this._cancelRendering();
  8613. this._resetView();
  8614. this.findController?.setDocument(null);
  8615. this._scriptingManager?.setDocument(null);
  8616. if (this.#annotationEditorUIManager) {
  8617. this.#annotationEditorUIManager.destroy();
  8618. this.#annotationEditorUIManager = null;
  8619. }
  8620. }
  8621. this.pdfDocument = pdfDocument;
  8622. if (!pdfDocument) {
  8623. return;
  8624. }
  8625. const pagesCount = pdfDocument.numPages;
  8626. const firstPagePromise = pdfDocument.getPage(1);
  8627. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8628. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8629. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8630. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8631. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8632. this.eventBus.dispatch("scrollmodechanged", {
  8633. source: this,
  8634. mode
  8635. });
  8636. }
  8637. this._pagesCapability.promise.then(() => {
  8638. this.eventBus.dispatch("pagesloaded", {
  8639. source: this,
  8640. pagesCount
  8641. });
  8642. }, () => { });
  8643. this._onBeforeDraw = evt => {
  8644. const pageView = this._pages[evt.pageNumber - 1];
  8645. if (!pageView) {
  8646. return;
  8647. }
  8648. this.#buffer.push(pageView);
  8649. };
  8650. this.eventBus._on("pagerender", this._onBeforeDraw);
  8651. this._onAfterDraw = evt => {
  8652. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8653. return;
  8654. }
  8655. this._onePageRenderedCapability.resolve({
  8656. timestamp: evt.timestamp
  8657. });
  8658. this.eventBus._off("pagerendered", this._onAfterDraw);
  8659. this._onAfterDraw = null;
  8660. if (this.#onVisibilityChange) {
  8661. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8662. this.#onVisibilityChange = null;
  8663. }
  8664. };
  8665. this.eventBus._on("pagerendered", this._onAfterDraw);
  8666. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8667. if (pdfDocument !== this.pdfDocument) {
  8668. return;
  8669. }
  8670. this._firstPageCapability.resolve(firstPdfPage);
  8671. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8672. const {
  8673. annotationEditorMode,
  8674. annotationMode,
  8675. textLayerMode
  8676. } = this.#initializePermissions(permissions);
  8677. if (textLayerMode !== _ui_utils.TextLayerMode.DISABLE) {
  8678. const element = this.#hiddenCopyElement = document.createElement("div");
  8679. element.id = "hiddenCopyElement";
  8680. this.viewer.before(element);
  8681. }
  8682. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  8683. const mode = annotationEditorMode;
  8684. if (pdfDocument.isPureXfa) {
  8685. console.warn("Warning: XFA-editing is not implemented.");
  8686. } else if (isValidAnnotationEditorMode(mode)) {
  8687. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.viewer, this.eventBus, pdfDocument, this.pageColors);
  8688. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  8689. this.#annotationEditorUIManager.updateMode(mode);
  8690. }
  8691. } else {
  8692. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  8693. }
  8694. }
  8695. const layerProperties = this.#layerProperties.bind(this);
  8696. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8697. const scale = this.currentScale;
  8698. const viewport = firstPdfPage.getViewport({
  8699. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8700. });
  8701. this.viewer.style.setProperty("--scale-factor", viewport.scale);
  8702. if (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas") {
  8703. this.viewer.style.setProperty("--hcm-highligh-filter", pdfDocument.filterFactory.addHighlightHCMFilter("CanvasText", "Canvas", "HighlightText", "Highlight"));
  8704. }
  8705. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8706. const pageView = new _pdf_page_view.PDFPageView({
  8707. container: viewerElement,
  8708. eventBus: this.eventBus,
  8709. id: pageNum,
  8710. scale,
  8711. defaultViewport: viewport.clone(),
  8712. optionalContentConfigPromise,
  8713. renderingQueue: this.renderingQueue,
  8714. textLayerMode,
  8715. annotationMode,
  8716. imageResourcesPath: this.imageResourcesPath,
  8717. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  8718. maxCanvasPixels: this.maxCanvasPixels,
  8719. pageColors: this.pageColors,
  8720. l10n: this.l10n,
  8721. layerProperties
  8722. });
  8723. this._pages.push(pageView);
  8724. }
  8725. const firstPageView = this._pages[0];
  8726. if (firstPageView) {
  8727. firstPageView.setPdfPage(firstPdfPage);
  8728. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8729. }
  8730. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8731. this.#ensurePageViewVisible();
  8732. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8733. this._updateSpreadMode();
  8734. }
  8735. this.#onePageRenderedOrForceFetch().then(async () => {
  8736. this.findController?.setDocument(pdfDocument);
  8737. this._scriptingManager?.setDocument(pdfDocument);
  8738. if (this.#hiddenCopyElement) {
  8739. this.#copyCallbackBound = this.#copyCallback.bind(this, textLayerMode);
  8740. document.addEventListener("copy", this.#copyCallbackBound);
  8741. }
  8742. if (this.#annotationEditorUIManager) {
  8743. this.eventBus.dispatch("annotationeditormodechanged", {
  8744. source: this,
  8745. mode: this.#annotationEditorMode
  8746. });
  8747. }
  8748. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8749. this._pagesCapability.resolve();
  8750. return;
  8751. }
  8752. let getPagesLeft = pagesCount - 1;
  8753. if (getPagesLeft <= 0) {
  8754. this._pagesCapability.resolve();
  8755. return;
  8756. }
  8757. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8758. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8759. const pageView = this._pages[pageNum - 1];
  8760. if (!pageView.pdfPage) {
  8761. pageView.setPdfPage(pdfPage);
  8762. }
  8763. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8764. if (--getPagesLeft === 0) {
  8765. this._pagesCapability.resolve();
  8766. }
  8767. }, reason => {
  8768. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8769. if (--getPagesLeft === 0) {
  8770. this._pagesCapability.resolve();
  8771. }
  8772. });
  8773. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8774. await promise;
  8775. }
  8776. }
  8777. });
  8778. this.eventBus.dispatch("pagesinit", {
  8779. source: this
  8780. });
  8781. pdfDocument.getMetadata().then(({
  8782. info
  8783. }) => {
  8784. if (pdfDocument !== this.pdfDocument) {
  8785. return;
  8786. }
  8787. if (info.Language) {
  8788. this.viewer.lang = info.Language;
  8789. }
  8790. });
  8791. if (this.defaultRenderingQueue) {
  8792. this.update();
  8793. }
  8794. }).catch(reason => {
  8795. console.error("Unable to initialize viewer", reason);
  8796. this._pagesCapability.reject(reason);
  8797. });
  8798. }
  8799. setPageLabels(labels) {
  8800. if (!this.pdfDocument) {
  8801. return;
  8802. }
  8803. if (!labels) {
  8804. this._pageLabels = null;
  8805. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8806. this._pageLabels = null;
  8807. console.error(`setPageLabels: Invalid page labels.`);
  8808. } else {
  8809. this._pageLabels = labels;
  8810. }
  8811. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8812. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8813. }
  8814. }
  8815. _resetView() {
  8816. this._pages = [];
  8817. this._currentPageNumber = 1;
  8818. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8819. this._currentScaleValue = null;
  8820. this._pageLabels = null;
  8821. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8822. this._location = null;
  8823. this._pagesRotation = 0;
  8824. this._optionalContentConfigPromise = null;
  8825. this._firstPageCapability = new _pdfjsLib.PromiseCapability();
  8826. this._onePageRenderedCapability = new _pdfjsLib.PromiseCapability();
  8827. this._pagesCapability = new _pdfjsLib.PromiseCapability();
  8828. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8829. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8830. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8831. this.#scrollModePageState = {
  8832. previousPageNumber: 1,
  8833. scrollDown: true,
  8834. pages: []
  8835. };
  8836. if (this._onBeforeDraw) {
  8837. this.eventBus._off("pagerender", this._onBeforeDraw);
  8838. this._onBeforeDraw = null;
  8839. }
  8840. if (this._onAfterDraw) {
  8841. this.eventBus._off("pagerendered", this._onAfterDraw);
  8842. this._onAfterDraw = null;
  8843. }
  8844. if (this.#onVisibilityChange) {
  8845. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8846. this.#onVisibilityChange = null;
  8847. }
  8848. this.viewer.textContent = "";
  8849. this._updateScrollMode();
  8850. this.viewer.removeAttribute("lang");
  8851. if (this.#hiddenCopyElement) {
  8852. document.removeEventListener("copy", this.#copyCallbackBound);
  8853. this.#copyCallbackBound = null;
  8854. this.#hiddenCopyElement.remove();
  8855. this.#hiddenCopyElement = null;
  8856. }
  8857. }
  8858. #ensurePageViewVisible() {
  8859. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8860. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8861. }
  8862. const pageNumber = this._currentPageNumber,
  8863. state = this.#scrollModePageState,
  8864. viewer = this.viewer;
  8865. viewer.textContent = "";
  8866. state.pages.length = 0;
  8867. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8868. const pageView = this._pages[pageNumber - 1];
  8869. viewer.append(pageView.div);
  8870. state.pages.push(pageView);
  8871. } else {
  8872. const pageIndexSet = new Set(),
  8873. parity = this._spreadMode - 1;
  8874. if (parity === -1) {
  8875. pageIndexSet.add(pageNumber - 1);
  8876. } else if (pageNumber % 2 !== parity) {
  8877. pageIndexSet.add(pageNumber - 1);
  8878. pageIndexSet.add(pageNumber);
  8879. } else {
  8880. pageIndexSet.add(pageNumber - 2);
  8881. pageIndexSet.add(pageNumber - 1);
  8882. }
  8883. const spread = document.createElement("div");
  8884. spread.className = "spread";
  8885. if (this.isInPresentationMode) {
  8886. const dummyPage = document.createElement("div");
  8887. dummyPage.className = "dummyPage";
  8888. spread.append(dummyPage);
  8889. }
  8890. for (const i of pageIndexSet) {
  8891. const pageView = this._pages[i];
  8892. if (!pageView) {
  8893. continue;
  8894. }
  8895. spread.append(pageView.div);
  8896. state.pages.push(pageView);
  8897. }
  8898. viewer.append(spread);
  8899. }
  8900. state.scrollDown = pageNumber >= state.previousPageNumber;
  8901. state.previousPageNumber = pageNumber;
  8902. }
  8903. _scrollUpdate() {
  8904. if (this.pagesCount === 0) {
  8905. return;
  8906. }
  8907. this.update();
  8908. }
  8909. #scrollIntoView(pageView, pageSpot = null) {
  8910. const {
  8911. div,
  8912. id
  8913. } = pageView;
  8914. if (this._currentPageNumber !== id) {
  8915. this._setCurrentPageNumber(id);
  8916. }
  8917. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8918. this.#ensurePageViewVisible();
  8919. this.update();
  8920. }
  8921. if (!pageSpot && !this.isInPresentationMode) {
  8922. const left = div.offsetLeft + div.clientLeft,
  8923. right = left + div.clientWidth;
  8924. const {
  8925. scrollLeft,
  8926. clientWidth
  8927. } = this.container;
  8928. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8929. pageSpot = {
  8930. left: 0,
  8931. top: 0
  8932. };
  8933. }
  8934. }
  8935. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8936. if (!this._currentScaleValue && this._location) {
  8937. this._location = null;
  8938. }
  8939. }
  8940. #isSameScale(newScale) {
  8941. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8942. }
  8943. #setScaleUpdatePages(newScale, newValue, {
  8944. noScroll = false,
  8945. preset = false,
  8946. drawingDelay = -1
  8947. }) {
  8948. this._currentScaleValue = newValue.toString();
  8949. if (this.#isSameScale(newScale)) {
  8950. if (preset) {
  8951. this.eventBus.dispatch("scalechanging", {
  8952. source: this,
  8953. scale: newScale,
  8954. presetValue: newValue
  8955. });
  8956. }
  8957. return;
  8958. }
  8959. this.viewer.style.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8960. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  8961. this.refresh(true, {
  8962. scale: newScale,
  8963. drawingDelay: postponeDrawing ? drawingDelay : -1
  8964. });
  8965. if (postponeDrawing) {
  8966. this.#scaleTimeoutId = setTimeout(() => {
  8967. this.#scaleTimeoutId = null;
  8968. this.refresh();
  8969. }, drawingDelay);
  8970. }
  8971. this._currentScale = newScale;
  8972. if (!noScroll) {
  8973. let page = this._currentPageNumber,
  8974. dest;
  8975. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8976. page = this._location.pageNumber;
  8977. dest = [null, {
  8978. name: "XYZ"
  8979. }, this._location.left, this._location.top, null];
  8980. }
  8981. this.scrollPageIntoView({
  8982. pageNumber: page,
  8983. destArray: dest,
  8984. allowNegativeOffset: true
  8985. });
  8986. }
  8987. this.eventBus.dispatch("scalechanging", {
  8988. source: this,
  8989. scale: newScale,
  8990. presetValue: preset ? newValue : undefined
  8991. });
  8992. if (this.defaultRenderingQueue) {
  8993. this.update();
  8994. }
  8995. }
  8996. get #pageWidthScaleFactor() {
  8997. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8998. return 2;
  8999. }
  9000. return 1;
  9001. }
  9002. #setScale(value, options) {
  9003. let scale = parseFloat(value);
  9004. if (scale > 0) {
  9005. options.preset = false;
  9006. this.#setScaleUpdatePages(scale, value, options);
  9007. } else {
  9008. const currentPage = this._pages[this._currentPageNumber - 1];
  9009. if (!currentPage) {
  9010. return;
  9011. }
  9012. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  9013. vPadding = _ui_utils.VERTICAL_PADDING;
  9014. if (this.isInPresentationMode) {
  9015. hPadding = vPadding = 4;
  9016. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  9017. hPadding *= 2;
  9018. }
  9019. } else if (this.removePageBorders) {
  9020. hPadding = vPadding = 0;
  9021. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  9022. [hPadding, vPadding] = [vPadding, hPadding];
  9023. }
  9024. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor;
  9025. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  9026. switch (value) {
  9027. case "page-actual":
  9028. scale = 1;
  9029. break;
  9030. case "page-width":
  9031. scale = pageWidthScale;
  9032. break;
  9033. case "page-height":
  9034. scale = pageHeightScale;
  9035. break;
  9036. case "page-fit":
  9037. scale = Math.min(pageWidthScale, pageHeightScale);
  9038. break;
  9039. case "auto":
  9040. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  9041. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  9042. break;
  9043. default:
  9044. console.error(`#setScale: "${value}" is an unknown zoom value.`);
  9045. return;
  9046. }
  9047. options.preset = true;
  9048. this.#setScaleUpdatePages(scale, value, options);
  9049. }
  9050. }
  9051. #resetCurrentPageView() {
  9052. const pageView = this._pages[this._currentPageNumber - 1];
  9053. if (this.isInPresentationMode) {
  9054. this.#setScale(this._currentScaleValue, {
  9055. noScroll: true
  9056. });
  9057. }
  9058. this.#scrollIntoView(pageView);
  9059. }
  9060. pageLabelToPageNumber(label) {
  9061. if (!this._pageLabels) {
  9062. return null;
  9063. }
  9064. const i = this._pageLabels.indexOf(label);
  9065. if (i < 0) {
  9066. return null;
  9067. }
  9068. return i + 1;
  9069. }
  9070. scrollPageIntoView({
  9071. pageNumber,
  9072. destArray = null,
  9073. allowNegativeOffset = false,
  9074. ignoreDestinationZoom = false
  9075. }) {
  9076. if (!this.pdfDocument) {
  9077. return;
  9078. }
  9079. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  9080. if (!pageView) {
  9081. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  9082. return;
  9083. }
  9084. if (this.isInPresentationMode || !destArray) {
  9085. this._setCurrentPageNumber(pageNumber, true);
  9086. return;
  9087. }
  9088. let x = 0,
  9089. y = 0;
  9090. let width = 0,
  9091. height = 0,
  9092. widthScale,
  9093. heightScale;
  9094. const changeOrientation = pageView.rotation % 180 !== 0;
  9095. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9096. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9097. let scale = 0;
  9098. switch (destArray[1].name) {
  9099. case "XYZ":
  9100. x = destArray[2];
  9101. y = destArray[3];
  9102. scale = destArray[4];
  9103. x = x !== null ? x : 0;
  9104. y = y !== null ? y : pageHeight;
  9105. break;
  9106. case "Fit":
  9107. case "FitB":
  9108. scale = "page-fit";
  9109. break;
  9110. case "FitH":
  9111. case "FitBH":
  9112. y = destArray[2];
  9113. scale = "page-width";
  9114. if (y === null && this._location) {
  9115. x = this._location.left;
  9116. y = this._location.top;
  9117. } else if (typeof y !== "number" || y < 0) {
  9118. y = pageHeight;
  9119. }
  9120. break;
  9121. case "FitV":
  9122. case "FitBV":
  9123. x = destArray[2];
  9124. width = pageWidth;
  9125. height = pageHeight;
  9126. scale = "page-height";
  9127. break;
  9128. case "FitR":
  9129. x = destArray[2];
  9130. y = destArray[3];
  9131. width = destArray[4] - x;
  9132. height = destArray[5] - y;
  9133. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  9134. vPadding = _ui_utils.VERTICAL_PADDING;
  9135. if (this.removePageBorders) {
  9136. hPadding = vPadding = 0;
  9137. }
  9138. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9139. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9140. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  9141. break;
  9142. default:
  9143. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  9144. return;
  9145. }
  9146. if (!ignoreDestinationZoom) {
  9147. if (scale && scale !== this._currentScale) {
  9148. this.currentScaleValue = scale;
  9149. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  9150. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  9151. }
  9152. }
  9153. if (scale === "page-fit" && !destArray[4]) {
  9154. this.#scrollIntoView(pageView);
  9155. return;
  9156. }
  9157. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  9158. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  9159. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  9160. if (!allowNegativeOffset) {
  9161. left = Math.max(left, 0);
  9162. top = Math.max(top, 0);
  9163. }
  9164. this.#scrollIntoView(pageView, {
  9165. left,
  9166. top
  9167. });
  9168. }
  9169. _updateLocation(firstPage) {
  9170. const currentScale = this._currentScale;
  9171. const currentScaleValue = this._currentScaleValue;
  9172. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  9173. const pageNumber = firstPage.id;
  9174. const currentPageView = this._pages[pageNumber - 1];
  9175. const container = this.container;
  9176. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  9177. const intLeft = Math.round(topLeft[0]);
  9178. const intTop = Math.round(topLeft[1]);
  9179. let pdfOpenParams = `#page=${pageNumber}`;
  9180. if (!this.isInPresentationMode) {
  9181. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  9182. }
  9183. this._location = {
  9184. pageNumber,
  9185. scale: normalizedScaleValue,
  9186. top: intTop,
  9187. left: intLeft,
  9188. rotation: this._pagesRotation,
  9189. pdfOpenParams
  9190. };
  9191. }
  9192. update() {
  9193. const visible = this._getVisiblePages();
  9194. const visiblePages = visible.views,
  9195. numVisiblePages = visiblePages.length;
  9196. if (numVisiblePages === 0) {
  9197. return;
  9198. }
  9199. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  9200. this.#buffer.resize(newCacheSize, visible.ids);
  9201. this.renderingQueue.renderHighestPriority(visible);
  9202. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  9203. const currentId = this._currentPageNumber;
  9204. let stillFullyVisible = false;
  9205. for (const page of visiblePages) {
  9206. if (page.percent < 100) {
  9207. break;
  9208. }
  9209. if (page.id === currentId && isSimpleLayout) {
  9210. stillFullyVisible = true;
  9211. break;
  9212. }
  9213. }
  9214. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  9215. this._updateLocation(visible.first);
  9216. this.eventBus.dispatch("updateviewarea", {
  9217. source: this,
  9218. location: this._location
  9219. });
  9220. }
  9221. containsElement(element) {
  9222. return this.container.contains(element);
  9223. }
  9224. focus() {
  9225. this.container.focus();
  9226. }
  9227. get _isContainerRtl() {
  9228. return getComputedStyle(this.container).direction === "rtl";
  9229. }
  9230. get isInPresentationMode() {
  9231. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  9232. }
  9233. get isChangingPresentationMode() {
  9234. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  9235. }
  9236. get isHorizontalScrollbarEnabled() {
  9237. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  9238. }
  9239. get isVerticalScrollbarEnabled() {
  9240. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  9241. }
  9242. _getVisiblePages() {
  9243. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  9244. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  9245. rtl = horizontal && this._isContainerRtl;
  9246. return (0, _ui_utils.getVisibleElements)({
  9247. scrollEl: this.container,
  9248. views,
  9249. sortByVisibility: true,
  9250. horizontal,
  9251. rtl
  9252. });
  9253. }
  9254. cleanup() {
  9255. for (const pageView of this._pages) {
  9256. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  9257. pageView.reset();
  9258. }
  9259. }
  9260. }
  9261. _cancelRendering() {
  9262. for (const pageView of this._pages) {
  9263. pageView.cancelRendering();
  9264. }
  9265. }
  9266. async #ensurePdfPageLoaded(pageView) {
  9267. if (pageView.pdfPage) {
  9268. return pageView.pdfPage;
  9269. }
  9270. try {
  9271. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  9272. if (!pageView.pdfPage) {
  9273. pageView.setPdfPage(pdfPage);
  9274. }
  9275. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  9276. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  9277. }
  9278. return pdfPage;
  9279. } catch (reason) {
  9280. console.error("Unable to get page for page view", reason);
  9281. return null;
  9282. }
  9283. }
  9284. #getScrollAhead(visible) {
  9285. if (visible.first?.id === 1) {
  9286. return true;
  9287. } else if (visible.last?.id === this.pagesCount) {
  9288. return false;
  9289. }
  9290. switch (this._scrollMode) {
  9291. case _ui_utils.ScrollMode.PAGE:
  9292. return this.#scrollModePageState.scrollDown;
  9293. case _ui_utils.ScrollMode.HORIZONTAL:
  9294. return this.scroll.right;
  9295. }
  9296. return this.scroll.down;
  9297. }
  9298. forceRendering(currentlyVisiblePages) {
  9299. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9300. const scrollAhead = this.#getScrollAhead(visiblePages);
  9301. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9302. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9303. if (pageView) {
  9304. this.#ensurePdfPageLoaded(pageView).then(() => {
  9305. this.renderingQueue.renderView(pageView);
  9306. });
  9307. return true;
  9308. }
  9309. return false;
  9310. }
  9311. get hasEqualPageSizes() {
  9312. const firstPageView = this._pages[0];
  9313. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  9314. const pageView = this._pages[i];
  9315. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9316. return false;
  9317. }
  9318. }
  9319. return true;
  9320. }
  9321. getPagesOverview() {
  9322. let initialOrientation;
  9323. return this._pages.map(pageView => {
  9324. const viewport = pageView.pdfPage.getViewport({
  9325. scale: 1
  9326. });
  9327. const orientation = (0, _ui_utils.isPortraitOrientation)(viewport);
  9328. if (initialOrientation === undefined) {
  9329. initialOrientation = orientation;
  9330. } else if (this.enablePrintAutoRotate && orientation !== initialOrientation) {
  9331. return {
  9332. width: viewport.height,
  9333. height: viewport.width,
  9334. rotation: (viewport.rotation - 90) % 360
  9335. };
  9336. }
  9337. return {
  9338. width: viewport.width,
  9339. height: viewport.height,
  9340. rotation: viewport.rotation
  9341. };
  9342. });
  9343. }
  9344. get optionalContentConfigPromise() {
  9345. if (!this.pdfDocument) {
  9346. return Promise.resolve(null);
  9347. }
  9348. if (!this._optionalContentConfigPromise) {
  9349. console.error("optionalContentConfigPromise: Not initialized yet.");
  9350. return this.pdfDocument.getOptionalContentConfig();
  9351. }
  9352. return this._optionalContentConfigPromise;
  9353. }
  9354. set optionalContentConfigPromise(promise) {
  9355. if (!(promise instanceof Promise)) {
  9356. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  9357. }
  9358. if (!this.pdfDocument) {
  9359. return;
  9360. }
  9361. if (!this._optionalContentConfigPromise) {
  9362. return;
  9363. }
  9364. this._optionalContentConfigPromise = promise;
  9365. this.refresh(false, {
  9366. optionalContentConfigPromise: promise
  9367. });
  9368. this.eventBus.dispatch("optionalcontentconfigchanged", {
  9369. source: this,
  9370. promise
  9371. });
  9372. }
  9373. get scrollMode() {
  9374. return this._scrollMode;
  9375. }
  9376. set scrollMode(mode) {
  9377. if (this._scrollMode === mode) {
  9378. return;
  9379. }
  9380. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9381. throw new Error(`Invalid scroll mode: ${mode}`);
  9382. }
  9383. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9384. return;
  9385. }
  9386. this._previousScrollMode = this._scrollMode;
  9387. this._scrollMode = mode;
  9388. this.eventBus.dispatch("scrollmodechanged", {
  9389. source: this,
  9390. mode
  9391. });
  9392. this._updateScrollMode(this._currentPageNumber);
  9393. }
  9394. _updateScrollMode(pageNumber = null) {
  9395. const scrollMode = this._scrollMode,
  9396. viewer = this.viewer;
  9397. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9398. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9399. if (!this.pdfDocument || !pageNumber) {
  9400. return;
  9401. }
  9402. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9403. this.#ensurePageViewVisible();
  9404. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9405. this._updateSpreadMode();
  9406. }
  9407. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9408. this.#setScale(this._currentScaleValue, {
  9409. noScroll: true
  9410. });
  9411. }
  9412. this._setCurrentPageNumber(pageNumber, true);
  9413. this.update();
  9414. }
  9415. get spreadMode() {
  9416. return this._spreadMode;
  9417. }
  9418. set spreadMode(mode) {
  9419. if (this._spreadMode === mode) {
  9420. return;
  9421. }
  9422. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9423. throw new Error(`Invalid spread mode: ${mode}`);
  9424. }
  9425. this._spreadMode = mode;
  9426. this.eventBus.dispatch("spreadmodechanged", {
  9427. source: this,
  9428. mode
  9429. });
  9430. this._updateSpreadMode(this._currentPageNumber);
  9431. }
  9432. _updateSpreadMode(pageNumber = null) {
  9433. if (!this.pdfDocument) {
  9434. return;
  9435. }
  9436. const viewer = this.viewer,
  9437. pages = this._pages;
  9438. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9439. this.#ensurePageViewVisible();
  9440. } else {
  9441. viewer.textContent = "";
  9442. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9443. for (const pageView of this._pages) {
  9444. viewer.append(pageView.div);
  9445. }
  9446. } else {
  9447. const parity = this._spreadMode - 1;
  9448. let spread = null;
  9449. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9450. if (spread === null) {
  9451. spread = document.createElement("div");
  9452. spread.className = "spread";
  9453. viewer.append(spread);
  9454. } else if (i % 2 === parity) {
  9455. spread = spread.cloneNode(false);
  9456. viewer.append(spread);
  9457. }
  9458. spread.append(pages[i].div);
  9459. }
  9460. }
  9461. }
  9462. if (!pageNumber) {
  9463. return;
  9464. }
  9465. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9466. this.#setScale(this._currentScaleValue, {
  9467. noScroll: true
  9468. });
  9469. }
  9470. this._setCurrentPageNumber(pageNumber, true);
  9471. this.update();
  9472. }
  9473. _getPageAdvance(currentPageNumber, previous = false) {
  9474. switch (this._scrollMode) {
  9475. case _ui_utils.ScrollMode.WRAPPED:
  9476. {
  9477. const {
  9478. views
  9479. } = this._getVisiblePages(),
  9480. pageLayout = new Map();
  9481. for (const {
  9482. id,
  9483. y,
  9484. percent,
  9485. widthPercent
  9486. } of views) {
  9487. if (percent === 0 || widthPercent < 100) {
  9488. continue;
  9489. }
  9490. let yArray = pageLayout.get(y);
  9491. if (!yArray) {
  9492. pageLayout.set(y, yArray ||= []);
  9493. }
  9494. yArray.push(id);
  9495. }
  9496. for (const yArray of pageLayout.values()) {
  9497. const currentIndex = yArray.indexOf(currentPageNumber);
  9498. if (currentIndex === -1) {
  9499. continue;
  9500. }
  9501. const numPages = yArray.length;
  9502. if (numPages === 1) {
  9503. break;
  9504. }
  9505. if (previous) {
  9506. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9507. const currentId = yArray[i],
  9508. expectedId = yArray[i + 1] - 1;
  9509. if (currentId < expectedId) {
  9510. return currentPageNumber - expectedId;
  9511. }
  9512. }
  9513. } else {
  9514. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9515. const currentId = yArray[i],
  9516. expectedId = yArray[i - 1] + 1;
  9517. if (currentId > expectedId) {
  9518. return expectedId - currentPageNumber;
  9519. }
  9520. }
  9521. }
  9522. if (previous) {
  9523. const firstId = yArray[0];
  9524. if (firstId < currentPageNumber) {
  9525. return currentPageNumber - firstId + 1;
  9526. }
  9527. } else {
  9528. const lastId = yArray[numPages - 1];
  9529. if (lastId > currentPageNumber) {
  9530. return lastId - currentPageNumber + 1;
  9531. }
  9532. }
  9533. break;
  9534. }
  9535. break;
  9536. }
  9537. case _ui_utils.ScrollMode.HORIZONTAL:
  9538. {
  9539. break;
  9540. }
  9541. case _ui_utils.ScrollMode.PAGE:
  9542. case _ui_utils.ScrollMode.VERTICAL:
  9543. {
  9544. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9545. break;
  9546. }
  9547. const parity = this._spreadMode - 1;
  9548. if (previous && currentPageNumber % 2 !== parity) {
  9549. break;
  9550. } else if (!previous && currentPageNumber % 2 === parity) {
  9551. break;
  9552. }
  9553. const {
  9554. views
  9555. } = this._getVisiblePages(),
  9556. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9557. for (const {
  9558. id,
  9559. percent,
  9560. widthPercent
  9561. } of views) {
  9562. if (id !== expectedId) {
  9563. continue;
  9564. }
  9565. if (percent > 0 && widthPercent === 100) {
  9566. return 2;
  9567. }
  9568. break;
  9569. }
  9570. break;
  9571. }
  9572. }
  9573. return 1;
  9574. }
  9575. nextPage() {
  9576. const currentPageNumber = this._currentPageNumber,
  9577. pagesCount = this.pagesCount;
  9578. if (currentPageNumber >= pagesCount) {
  9579. return false;
  9580. }
  9581. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9582. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9583. return true;
  9584. }
  9585. previousPage() {
  9586. const currentPageNumber = this._currentPageNumber;
  9587. if (currentPageNumber <= 1) {
  9588. return false;
  9589. }
  9590. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9591. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9592. return true;
  9593. }
  9594. increaseScale({
  9595. drawingDelay,
  9596. scaleFactor,
  9597. steps
  9598. } = {}) {
  9599. if (!this.pdfDocument) {
  9600. return;
  9601. }
  9602. let newScale = this._currentScale;
  9603. if (scaleFactor > 1) {
  9604. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  9605. } else {
  9606. steps ??= 1;
  9607. do {
  9608. newScale = Math.ceil((newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
  9609. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9610. }
  9611. this.#setScale(Math.min(_ui_utils.MAX_SCALE, newScale), {
  9612. noScroll: false,
  9613. drawingDelay
  9614. });
  9615. }
  9616. decreaseScale({
  9617. drawingDelay,
  9618. scaleFactor,
  9619. steps
  9620. } = {}) {
  9621. if (!this.pdfDocument) {
  9622. return;
  9623. }
  9624. let newScale = this._currentScale;
  9625. if (scaleFactor > 0 && scaleFactor < 1) {
  9626. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  9627. } else {
  9628. steps ??= 1;
  9629. do {
  9630. newScale = Math.floor((newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
  9631. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9632. }
  9633. this.#setScale(Math.max(_ui_utils.MIN_SCALE, newScale), {
  9634. noScroll: false,
  9635. drawingDelay
  9636. });
  9637. }
  9638. #updateContainerHeightCss(height = this.container.clientHeight) {
  9639. if (height !== this.#previousContainerHeight) {
  9640. this.#previousContainerHeight = height;
  9641. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  9642. }
  9643. }
  9644. #resizeObserverCallback(entries) {
  9645. for (const entry of entries) {
  9646. if (entry.target === this.container) {
  9647. this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
  9648. this.#containerTopLeft = null;
  9649. break;
  9650. }
  9651. }
  9652. }
  9653. get containerTopLeft() {
  9654. return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
  9655. }
  9656. get annotationEditorMode() {
  9657. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  9658. }
  9659. set annotationEditorMode({
  9660. mode,
  9661. editId = null
  9662. }) {
  9663. if (!this.#annotationEditorUIManager) {
  9664. throw new Error(`The AnnotationEditor is not enabled.`);
  9665. }
  9666. if (this.#annotationEditorMode === mode) {
  9667. return;
  9668. }
  9669. if (!isValidAnnotationEditorMode(mode)) {
  9670. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  9671. }
  9672. if (!this.pdfDocument) {
  9673. return;
  9674. }
  9675. this.#annotationEditorMode = mode;
  9676. this.eventBus.dispatch("annotationeditormodechanged", {
  9677. source: this,
  9678. mode
  9679. });
  9680. this.#annotationEditorUIManager.updateMode(mode, editId);
  9681. }
  9682. set annotationEditorParams({
  9683. type,
  9684. value
  9685. }) {
  9686. if (!this.#annotationEditorUIManager) {
  9687. throw new Error(`The AnnotationEditor is not enabled.`);
  9688. }
  9689. this.#annotationEditorUIManager.updateParams(type, value);
  9690. }
  9691. refresh(noUpdate = false, updateArgs = Object.create(null)) {
  9692. if (!this.pdfDocument) {
  9693. return;
  9694. }
  9695. for (const pageView of this._pages) {
  9696. pageView.update(updateArgs);
  9697. }
  9698. if (this.#scaleTimeoutId !== null) {
  9699. clearTimeout(this.#scaleTimeoutId);
  9700. this.#scaleTimeoutId = null;
  9701. }
  9702. if (!noUpdate) {
  9703. this.update();
  9704. }
  9705. }
  9706. }
  9707. exports.PDFViewer = PDFViewer;
  9708. /***/
  9709. }),
  9710. /* 29 */
  9711. /***/ ((__unused_webpack_module, exports) => {
  9712. Object.defineProperty(exports, "__esModule", ({
  9713. value: true
  9714. }));
  9715. exports.NullL10n = void 0;
  9716. exports.getL10nFallback = getL10nFallback;
  9717. const DEFAULT_L10N_STRINGS = {
  9718. of_pages: "of {{pagesCount}}",
  9719. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9720. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9721. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9722. document_properties_date_string: "{{date}}, {{time}}",
  9723. document_properties_page_size_unit_inches: "in",
  9724. document_properties_page_size_unit_millimeters: "mm",
  9725. document_properties_page_size_orientation_portrait: "portrait",
  9726. document_properties_page_size_orientation_landscape: "landscape",
  9727. document_properties_page_size_name_a3: "A3",
  9728. document_properties_page_size_name_a4: "A4",
  9729. document_properties_page_size_name_letter: "Letter",
  9730. document_properties_page_size_name_legal: "Legal",
  9731. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9732. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9733. document_properties_linearized_yes: "Yes",
  9734. document_properties_linearized_no: "No",
  9735. additional_layers: "Additional Layers",
  9736. page_landmark: "Page {{page}}",
  9737. thumb_page_title: "Page {{page}}",
  9738. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9739. find_reached_top: "Reached top of document, continued from bottom",
  9740. find_reached_bottom: "Reached end of document, continued from top",
  9741. "find_match_count[one]": "{{current}} of {{total}} match",
  9742. "find_match_count[other]": "{{current}} of {{total}} matches",
  9743. "find_match_count_limit[one]": "More than {{limit}} match",
  9744. "find_match_count_limit[other]": "More than {{limit}} matches",
  9745. find_not_found: "Phrase not found",
  9746. page_scale_width: "Page Width",
  9747. page_scale_fit: "Page Fit",
  9748. page_scale_auto: "Automatic Zoom",
  9749. page_scale_actual: "Actual Size",
  9750. page_scale_percent: "{{scale}}%",
  9751. loading_error: "An error occurred while loading the PDF.",
  9752. invalid_file_error: "Invalid or corrupted PDF file.",
  9753. missing_file_error: "Missing PDF file.",
  9754. unexpected_response_error: "Unexpected server response.",
  9755. rendering_error: "An error occurred while rendering the page.",
  9756. annotation_date_string: "{{date}}, {{time}}",
  9757. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9758. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9759. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  9760. free_text2_default_content: "Start typing…",
  9761. editor_free_text2_aria_label: "Text Editor",
  9762. editor_ink2_aria_label: "Draw Editor",
  9763. editor_ink_canvas_aria_label: "User-created image"
  9764. };
  9765. {
  9766. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  9767. }
  9768. function getL10nFallback(key, args) {
  9769. switch (key) {
  9770. case "find_match_count":
  9771. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9772. break;
  9773. case "find_match_count_limit":
  9774. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9775. break;
  9776. }
  9777. return DEFAULT_L10N_STRINGS[key] || "";
  9778. }
  9779. function formatL10nValue(text, args) {
  9780. if (!args) {
  9781. return text;
  9782. }
  9783. return text.replaceAll(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9784. return name in args ? args[name] : "{{" + name + "}}";
  9785. });
  9786. }
  9787. const NullL10n = {
  9788. async getLanguage() {
  9789. return "en-us";
  9790. },
  9791. async getDirection() {
  9792. return "ltr";
  9793. },
  9794. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9795. return formatL10nValue(fallback, args);
  9796. },
  9797. async translate(element) { }
  9798. };
  9799. exports.NullL10n = NullL10n;
  9800. /***/
  9801. }),
  9802. /* 30 */
  9803. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9804. Object.defineProperty(exports, "__esModule", ({
  9805. value: true
  9806. }));
  9807. exports.PDFPageView = void 0;
  9808. var _pdfjsLib = __webpack_require__(4);
  9809. var _ui_utils = __webpack_require__(3);
  9810. var _annotation_editor_layer_builder = __webpack_require__(31);
  9811. var _annotation_layer_builder = __webpack_require__(32);
  9812. var _app_options = __webpack_require__(5);
  9813. var _l10n_utils = __webpack_require__(29);
  9814. var _pdf_link_service = __webpack_require__(7);
  9815. var _struct_tree_layer_builder = __webpack_require__(33);
  9816. var _text_accessibility = __webpack_require__(34);
  9817. var _text_highlighter = __webpack_require__(35);
  9818. var _text_layer_builder = __webpack_require__(36);
  9819. var _xfa_layer_builder = __webpack_require__(37);
  9820. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9821. const DEFAULT_LAYER_PROPERTIES = () => {
  9822. return null;
  9823. };
  9824. class PDFPageView {
  9825. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9826. #hasRestrictedScaling = false;
  9827. #layerProperties = null;
  9828. #loadingId = null;
  9829. #previousRotation = null;
  9830. #renderError = null;
  9831. #renderingState = _ui_utils.RenderingStates.INITIAL;
  9832. #textLayerMode = _ui_utils.TextLayerMode.ENABLE;
  9833. #useThumbnailCanvas = {
  9834. directDrawing: true,
  9835. initialOptionalContent: true,
  9836. regularAnnotations: true
  9837. };
  9838. #viewportMap = new WeakMap();
  9839. constructor(options) {
  9840. const container = options.container;
  9841. const defaultViewport = options.defaultViewport;
  9842. this.id = options.id;
  9843. this.renderingId = "page" + this.id;
  9844. this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
  9845. this.pdfPage = null;
  9846. this.pageLabel = null;
  9847. this.rotation = 0;
  9848. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9849. this.viewport = defaultViewport;
  9850. this.pdfPageRotate = defaultViewport.rotation;
  9851. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9852. this.#textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9853. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9854. this.imageResourcesPath = options.imageResourcesPath || "";
  9855. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  9856. this.maxCanvasPixels = options.maxCanvasPixels ?? MAX_CANVAS_PIXELS;
  9857. this.pageColors = options.pageColors || null;
  9858. this.eventBus = options.eventBus;
  9859. this.renderingQueue = options.renderingQueue;
  9860. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9861. this.renderTask = null;
  9862. this.resume = null;
  9863. this._isStandalone = !this.renderingQueue?.hasViewer();
  9864. this._container = container;
  9865. if (options.useOnlyCssZoom) {
  9866. console.error("useOnlyCssZoom was removed, please use `maxCanvasPixels = 0` instead.");
  9867. this.maxCanvasPixels = 0;
  9868. }
  9869. this._annotationCanvasMap = null;
  9870. this.annotationLayer = null;
  9871. this.annotationEditorLayer = null;
  9872. this.textLayer = null;
  9873. this.zoomLayer = null;
  9874. this.xfaLayer = null;
  9875. this.structTreeLayer = null;
  9876. const div = document.createElement("div");
  9877. div.className = "page";
  9878. div.setAttribute("data-page-number", this.id);
  9879. div.setAttribute("role", "region");
  9880. this.l10n.get("page_landmark", {
  9881. page: this.id
  9882. }).then(msg => {
  9883. div.setAttribute("aria-label", msg);
  9884. });
  9885. this.div = div;
  9886. this.#setDimensions();
  9887. container?.append(div);
  9888. if (this._isStandalone) {
  9889. container?.style.setProperty("--scale-factor", this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  9890. const {
  9891. optionalContentConfigPromise
  9892. } = options;
  9893. if (optionalContentConfigPromise) {
  9894. optionalContentConfigPromise.then(optionalContentConfig => {
  9895. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9896. return;
  9897. }
  9898. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9899. });
  9900. }
  9901. }
  9902. }
  9903. get renderingState() {
  9904. return this.#renderingState;
  9905. }
  9906. set renderingState(state) {
  9907. if (state === this.#renderingState) {
  9908. return;
  9909. }
  9910. this.#renderingState = state;
  9911. if (this.#loadingId) {
  9912. clearTimeout(this.#loadingId);
  9913. this.#loadingId = null;
  9914. }
  9915. switch (state) {
  9916. case _ui_utils.RenderingStates.PAUSED:
  9917. this.div.classList.remove("loading");
  9918. break;
  9919. case _ui_utils.RenderingStates.RUNNING:
  9920. this.div.classList.add("loadingIcon");
  9921. this.#loadingId = setTimeout(() => {
  9922. this.div.classList.add("loading");
  9923. this.#loadingId = null;
  9924. }, 0);
  9925. break;
  9926. case _ui_utils.RenderingStates.INITIAL:
  9927. case _ui_utils.RenderingStates.FINISHED:
  9928. this.div.classList.remove("loadingIcon", "loading");
  9929. break;
  9930. }
  9931. }
  9932. #setDimensions() {
  9933. const {
  9934. viewport
  9935. } = this;
  9936. if (this.pdfPage) {
  9937. if (this.#previousRotation === viewport.rotation) {
  9938. return;
  9939. }
  9940. this.#previousRotation = viewport.rotation;
  9941. }
  9942. (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false);
  9943. }
  9944. setPdfPage(pdfPage) {
  9945. if (this._isStandalone && (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas")) {
  9946. this._container?.style.setProperty("--hcm-highligh-filter", pdfPage.filterFactory.addHighlightHCMFilter("CanvasText", "Canvas", "HighlightText", "Highlight"));
  9947. }
  9948. this.pdfPage = pdfPage;
  9949. this.pdfPageRotate = pdfPage.rotate;
  9950. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9951. this.viewport = pdfPage.getViewport({
  9952. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9953. rotation: totalRotation
  9954. });
  9955. this.#setDimensions();
  9956. this.reset();
  9957. }
  9958. destroy() {
  9959. this.reset();
  9960. this.pdfPage?.cleanup();
  9961. }
  9962. get _textHighlighter() {
  9963. return (0, _pdfjsLib.shadow)(this, "_textHighlighter", new _text_highlighter.TextHighlighter({
  9964. pageIndex: this.id - 1,
  9965. eventBus: this.eventBus,
  9966. findController: this.#layerProperties().findController
  9967. }));
  9968. }
  9969. async #renderAnnotationLayer() {
  9970. let error = null;
  9971. try {
  9972. await this.annotationLayer.render(this.viewport, "display");
  9973. } catch (ex) {
  9974. console.error(`#renderAnnotationLayer: "${ex}".`);
  9975. error = ex;
  9976. } finally {
  9977. this.eventBus.dispatch("annotationlayerrendered", {
  9978. source: this,
  9979. pageNumber: this.id,
  9980. error
  9981. });
  9982. }
  9983. }
  9984. async #renderAnnotationEditorLayer() {
  9985. let error = null;
  9986. try {
  9987. await this.annotationEditorLayer.render(this.viewport, "display");
  9988. } catch (ex) {
  9989. console.error(`#renderAnnotationEditorLayer: "${ex}".`);
  9990. error = ex;
  9991. } finally {
  9992. this.eventBus.dispatch("annotationeditorlayerrendered", {
  9993. source: this,
  9994. pageNumber: this.id,
  9995. error
  9996. });
  9997. }
  9998. }
  9999. async #renderXfaLayer() {
  10000. let error = null;
  10001. try {
  10002. const result = await this.xfaLayer.render(this.viewport, "display");
  10003. if (result?.textDivs && this._textHighlighter) {
  10004. this.#buildXfaTextContentItems(result.textDivs);
  10005. }
  10006. } catch (ex) {
  10007. console.error(`#renderXfaLayer: "${ex}".`);
  10008. error = ex;
  10009. } finally {
  10010. this.eventBus.dispatch("xfalayerrendered", {
  10011. source: this,
  10012. pageNumber: this.id,
  10013. error
  10014. });
  10015. }
  10016. }
  10017. async #renderTextLayer() {
  10018. const {
  10019. pdfPage,
  10020. textLayer,
  10021. viewport
  10022. } = this;
  10023. if (!textLayer) {
  10024. return;
  10025. }
  10026. let error = null;
  10027. try {
  10028. if (!textLayer.renderingDone) {
  10029. const readableStream = pdfPage.streamTextContent({
  10030. includeMarkedContent: true,
  10031. disableNormalization: true
  10032. });
  10033. textLayer.setTextContentSource(readableStream);
  10034. }
  10035. await textLayer.render(viewport);
  10036. } catch (ex) {
  10037. if (ex instanceof _pdfjsLib.AbortException) {
  10038. return;
  10039. }
  10040. console.error(`#renderTextLayer: "${ex}".`);
  10041. error = ex;
  10042. }
  10043. this.eventBus.dispatch("textlayerrendered", {
  10044. source: this,
  10045. pageNumber: this.id,
  10046. numTextDivs: textLayer.numTextDivs,
  10047. error
  10048. });
  10049. this.#renderStructTreeLayer();
  10050. }
  10051. async #renderStructTreeLayer() {
  10052. if (!this.textLayer) {
  10053. return;
  10054. }
  10055. this.structTreeLayer ||= new _struct_tree_layer_builder.StructTreeLayerBuilder();
  10056. const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
  10057. const treeDom = this.structTreeLayer?.render(tree);
  10058. if (treeDom) {
  10059. this.canvas?.append(treeDom);
  10060. }
  10061. this.structTreeLayer?.show();
  10062. }
  10063. async #buildXfaTextContentItems(textDivs) {
  10064. const text = await this.pdfPage.getTextContent();
  10065. const items = [];
  10066. for (const item of text.items) {
  10067. items.push(item.str);
  10068. }
  10069. this._textHighlighter.setTextMapping(textDivs, items);
  10070. this._textHighlighter.enable();
  10071. }
  10072. _resetZoomLayer(removeFromDOM = false) {
  10073. if (!this.zoomLayer) {
  10074. return;
  10075. }
  10076. const zoomLayerCanvas = this.zoomLayer.firstChild;
  10077. this.#viewportMap.delete(zoomLayerCanvas);
  10078. zoomLayerCanvas.width = 0;
  10079. zoomLayerCanvas.height = 0;
  10080. if (removeFromDOM) {
  10081. this.zoomLayer.remove();
  10082. }
  10083. this.zoomLayer = null;
  10084. }
  10085. reset({
  10086. keepZoomLayer = false,
  10087. keepAnnotationLayer = false,
  10088. keepAnnotationEditorLayer = false,
  10089. keepXfaLayer = false,
  10090. keepTextLayer = false
  10091. } = {}) {
  10092. this.cancelRendering({
  10093. keepAnnotationLayer,
  10094. keepAnnotationEditorLayer,
  10095. keepXfaLayer,
  10096. keepTextLayer
  10097. });
  10098. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  10099. const div = this.div;
  10100. const childNodes = div.childNodes,
  10101. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  10102. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  10103. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  10104. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
  10105. textLayerNode = keepTextLayer && this.textLayer?.div || null;
  10106. for (let i = childNodes.length - 1; i >= 0; i--) {
  10107. const node = childNodes[i];
  10108. switch (node) {
  10109. case zoomLayerNode:
  10110. case annotationLayerNode:
  10111. case annotationEditorLayerNode:
  10112. case xfaLayerNode:
  10113. case textLayerNode:
  10114. continue;
  10115. }
  10116. node.remove();
  10117. }
  10118. div.removeAttribute("data-loaded");
  10119. if (annotationLayerNode) {
  10120. this.annotationLayer.hide();
  10121. }
  10122. if (annotationEditorLayerNode) {
  10123. this.annotationEditorLayer.hide();
  10124. }
  10125. if (xfaLayerNode) {
  10126. this.xfaLayer.hide();
  10127. }
  10128. if (textLayerNode) {
  10129. this.textLayer.hide();
  10130. }
  10131. this.structTreeLayer?.hide();
  10132. if (!zoomLayerNode) {
  10133. if (this.canvas) {
  10134. this.#viewportMap.delete(this.canvas);
  10135. this.canvas.width = 0;
  10136. this.canvas.height = 0;
  10137. delete this.canvas;
  10138. }
  10139. this._resetZoomLayer();
  10140. }
  10141. }
  10142. update({
  10143. scale = 0,
  10144. rotation = null,
  10145. optionalContentConfigPromise = null,
  10146. drawingDelay = -1
  10147. }) {
  10148. this.scale = scale || this.scale;
  10149. if (typeof rotation === "number") {
  10150. this.rotation = rotation;
  10151. }
  10152. if (optionalContentConfigPromise instanceof Promise) {
  10153. this._optionalContentConfigPromise = optionalContentConfigPromise;
  10154. optionalContentConfigPromise.then(optionalContentConfig => {
  10155. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  10156. return;
  10157. }
  10158. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  10159. });
  10160. }
  10161. this.#useThumbnailCanvas.directDrawing = true;
  10162. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  10163. this.viewport = this.viewport.clone({
  10164. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  10165. rotation: totalRotation
  10166. });
  10167. this.#setDimensions();
  10168. if (this._isStandalone) {
  10169. this._container?.style.setProperty("--scale-factor", this.viewport.scale);
  10170. }
  10171. if (this.canvas) {
  10172. let onlyCssZoom = false;
  10173. if (this.#hasRestrictedScaling) {
  10174. if (this.maxCanvasPixels === 0) {
  10175. onlyCssZoom = true;
  10176. } else if (this.maxCanvasPixels > 0) {
  10177. const {
  10178. width,
  10179. height
  10180. } = this.viewport;
  10181. const {
  10182. sx,
  10183. sy
  10184. } = this.outputScale;
  10185. onlyCssZoom = (Math.floor(width) * sx | 0) * (Math.floor(height) * sy | 0) > this.maxCanvasPixels;
  10186. }
  10187. }
  10188. const postponeDrawing = !onlyCssZoom && drawingDelay >= 0 && drawingDelay < 1000;
  10189. if (postponeDrawing || onlyCssZoom) {
  10190. if (postponeDrawing && this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  10191. this.cancelRendering({
  10192. keepZoomLayer: true,
  10193. keepAnnotationLayer: true,
  10194. keepAnnotationEditorLayer: true,
  10195. keepXfaLayer: true,
  10196. keepTextLayer: true,
  10197. cancelExtraDelay: drawingDelay
  10198. });
  10199. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10200. this.#useThumbnailCanvas.directDrawing = false;
  10201. }
  10202. this.cssTransform({
  10203. target: this.canvas,
  10204. redrawAnnotationLayer: true,
  10205. redrawAnnotationEditorLayer: true,
  10206. redrawXfaLayer: true,
  10207. redrawTextLayer: !postponeDrawing,
  10208. hideTextLayer: postponeDrawing
  10209. });
  10210. if (postponeDrawing) {
  10211. return;
  10212. }
  10213. this.eventBus.dispatch("pagerendered", {
  10214. source: this,
  10215. pageNumber: this.id,
  10216. cssTransform: true,
  10217. timestamp: performance.now(),
  10218. error: this.#renderError
  10219. });
  10220. return;
  10221. }
  10222. if (!this.zoomLayer && !this.canvas.hidden) {
  10223. this.zoomLayer = this.canvas.parentNode;
  10224. this.zoomLayer.style.position = "absolute";
  10225. }
  10226. }
  10227. if (this.zoomLayer) {
  10228. this.cssTransform({
  10229. target: this.zoomLayer.firstChild
  10230. });
  10231. }
  10232. this.reset({
  10233. keepZoomLayer: true,
  10234. keepAnnotationLayer: true,
  10235. keepAnnotationEditorLayer: true,
  10236. keepXfaLayer: true,
  10237. keepTextLayer: true
  10238. });
  10239. }
  10240. cancelRendering({
  10241. keepAnnotationLayer = false,
  10242. keepAnnotationEditorLayer = false,
  10243. keepXfaLayer = false,
  10244. keepTextLayer = false,
  10245. cancelExtraDelay = 0
  10246. } = {}) {
  10247. if (this.renderTask) {
  10248. this.renderTask.cancel(cancelExtraDelay);
  10249. this.renderTask = null;
  10250. }
  10251. this.resume = null;
  10252. if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
  10253. this.textLayer.cancel();
  10254. this.textLayer = null;
  10255. }
  10256. if (this.structTreeLayer && !this.textLayer) {
  10257. this.structTreeLayer = null;
  10258. }
  10259. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  10260. this.annotationLayer.cancel();
  10261. this.annotationLayer = null;
  10262. this._annotationCanvasMap = null;
  10263. }
  10264. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  10265. this.annotationEditorLayer.cancel();
  10266. this.annotationEditorLayer = null;
  10267. }
  10268. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  10269. this.xfaLayer.cancel();
  10270. this.xfaLayer = null;
  10271. this._textHighlighter?.disable();
  10272. }
  10273. }
  10274. cssTransform({
  10275. target,
  10276. redrawAnnotationLayer = false,
  10277. redrawAnnotationEditorLayer = false,
  10278. redrawXfaLayer = false,
  10279. redrawTextLayer = false,
  10280. hideTextLayer = false
  10281. }) {
  10282. if (!target.hasAttribute("zooming")) {
  10283. target.setAttribute("zooming", true);
  10284. const {
  10285. style
  10286. } = target;
  10287. style.width = style.height = "";
  10288. }
  10289. const originalViewport = this.#viewportMap.get(target);
  10290. if (this.viewport !== originalViewport) {
  10291. const relativeRotation = this.viewport.rotation - originalViewport.rotation;
  10292. const absRotation = Math.abs(relativeRotation);
  10293. let scaleX = 1,
  10294. scaleY = 1;
  10295. if (absRotation === 90 || absRotation === 270) {
  10296. const {
  10297. width,
  10298. height
  10299. } = this.viewport;
  10300. scaleX = height / width;
  10301. scaleY = width / height;
  10302. }
  10303. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  10304. }
  10305. if (redrawAnnotationLayer && this.annotationLayer) {
  10306. this.#renderAnnotationLayer();
  10307. }
  10308. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  10309. this.#renderAnnotationEditorLayer();
  10310. }
  10311. if (redrawXfaLayer && this.xfaLayer) {
  10312. this.#renderXfaLayer();
  10313. }
  10314. if (this.textLayer) {
  10315. if (hideTextLayer) {
  10316. this.textLayer.hide();
  10317. this.structTreeLayer?.hide();
  10318. } else if (redrawTextLayer) {
  10319. this.#renderTextLayer();
  10320. }
  10321. }
  10322. }
  10323. get width() {
  10324. return this.viewport.width;
  10325. }
  10326. get height() {
  10327. return this.viewport.height;
  10328. }
  10329. getPagePoint(x, y) {
  10330. return this.viewport.convertToPdfPoint(x, y);
  10331. }
  10332. async #finishRenderTask(renderTask, error = null) {
  10333. if (renderTask === this.renderTask) {
  10334. this.renderTask = null;
  10335. }
  10336. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  10337. this.#renderError = null;
  10338. return;
  10339. }
  10340. this.#renderError = error;
  10341. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10342. this._resetZoomLayer(true);
  10343. this.#useThumbnailCanvas.regularAnnotations = !renderTask.separateAnnots;
  10344. this.eventBus.dispatch("pagerendered", {
  10345. source: this,
  10346. pageNumber: this.id,
  10347. cssTransform: false,
  10348. timestamp: performance.now(),
  10349. error: this.#renderError
  10350. });
  10351. if (error) {
  10352. throw error;
  10353. }
  10354. }
  10355. async draw() {
  10356. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  10357. console.error("Must be in new state before drawing");
  10358. this.reset();
  10359. }
  10360. const {
  10361. div,
  10362. l10n,
  10363. pageColors,
  10364. pdfPage,
  10365. viewport
  10366. } = this;
  10367. if (!pdfPage) {
  10368. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10369. throw new Error("pdfPage is not loaded");
  10370. }
  10371. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10372. const canvasWrapper = document.createElement("div");
  10373. canvasWrapper.classList.add("canvasWrapper");
  10374. div.append(canvasWrapper);
  10375. if (!this.textLayer && this.#textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
  10376. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  10377. this.textLayer = new _text_layer_builder.TextLayerBuilder({
  10378. highlighter: this._textHighlighter,
  10379. accessibilityManager: this._accessibilityManager,
  10380. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  10381. enablePermissions: this.#textLayerMode === _ui_utils.TextLayerMode.ENABLE_PERMISSIONS
  10382. });
  10383. div.append(this.textLayer.div);
  10384. }
  10385. if (!this.annotationLayer && this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE) {
  10386. const {
  10387. annotationStorage,
  10388. downloadManager,
  10389. enableScripting,
  10390. fieldObjectsPromise,
  10391. hasJSActionsPromise,
  10392. linkService
  10393. } = this.#layerProperties();
  10394. this._annotationCanvasMap ||= new Map();
  10395. this.annotationLayer = new _annotation_layer_builder.AnnotationLayerBuilder({
  10396. pageDiv: div,
  10397. pdfPage,
  10398. annotationStorage,
  10399. imageResourcesPath: this.imageResourcesPath,
  10400. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  10401. linkService,
  10402. downloadManager,
  10403. l10n,
  10404. enableScripting,
  10405. hasJSActionsPromise,
  10406. fieldObjectsPromise,
  10407. annotationCanvasMap: this._annotationCanvasMap,
  10408. accessibilityManager: this._accessibilityManager
  10409. });
  10410. }
  10411. const renderContinueCallback = cont => {
  10412. showCanvas?.(false);
  10413. if (this.renderingQueue && !this.renderingQueue.isHighestPriority(this)) {
  10414. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  10415. this.resume = () => {
  10416. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10417. cont();
  10418. };
  10419. return;
  10420. }
  10421. cont();
  10422. };
  10423. const {
  10424. width,
  10425. height
  10426. } = viewport;
  10427. const canvas = document.createElement("canvas");
  10428. canvas.setAttribute("role", "presentation");
  10429. canvas.hidden = true;
  10430. const hasHCM = !!(pageColors?.background && pageColors?.foreground);
  10431. let showCanvas = isLastShow => {
  10432. if (!hasHCM || isLastShow) {
  10433. canvas.hidden = false;
  10434. showCanvas = null;
  10435. }
  10436. };
  10437. canvasWrapper.append(canvas);
  10438. this.canvas = canvas;
  10439. const ctx = canvas.getContext("2d", {
  10440. alpha: false
  10441. });
  10442. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  10443. if (this.maxCanvasPixels === 0) {
  10444. const invScale = 1 / this.scale;
  10445. outputScale.sx *= invScale;
  10446. outputScale.sy *= invScale;
  10447. this.#hasRestrictedScaling = true;
  10448. } else if (this.maxCanvasPixels > 0) {
  10449. const pixelsInViewport = width * height;
  10450. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  10451. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  10452. outputScale.sx = maxScale;
  10453. outputScale.sy = maxScale;
  10454. this.#hasRestrictedScaling = true;
  10455. } else {
  10456. this.#hasRestrictedScaling = false;
  10457. }
  10458. }
  10459. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  10460. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  10461. canvas.width = (0, _ui_utils.roundToDivide)(width * outputScale.sx, sfx[0]);
  10462. canvas.height = (0, _ui_utils.roundToDivide)(height * outputScale.sy, sfy[0]);
  10463. const {
  10464. style
  10465. } = canvas;
  10466. style.width = (0, _ui_utils.roundToDivide)(width, sfx[1]) + "px";
  10467. style.height = (0, _ui_utils.roundToDivide)(height, sfy[1]) + "px";
  10468. this.#viewportMap.set(canvas, viewport);
  10469. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10470. const renderContext = {
  10471. canvasContext: ctx,
  10472. transform,
  10473. viewport,
  10474. annotationMode: this.#annotationMode,
  10475. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10476. annotationCanvasMap: this._annotationCanvasMap,
  10477. pageColors
  10478. };
  10479. const renderTask = this.renderTask = this.pdfPage.render(renderContext);
  10480. renderTask.onContinue = renderContinueCallback;
  10481. const resultPromise = renderTask.promise.then(async () => {
  10482. showCanvas?.(true);
  10483. await this.#finishRenderTask(renderTask);
  10484. this.#renderTextLayer();
  10485. if (this.annotationLayer) {
  10486. await this.#renderAnnotationLayer();
  10487. }
  10488. if (!this.annotationEditorLayer) {
  10489. const {
  10490. annotationEditorUIManager
  10491. } = this.#layerProperties();
  10492. if (!annotationEditorUIManager) {
  10493. return;
  10494. }
  10495. this.annotationEditorLayer = new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  10496. uiManager: annotationEditorUIManager,
  10497. pageDiv: div,
  10498. pdfPage,
  10499. l10n,
  10500. accessibilityManager: this._accessibilityManager,
  10501. annotationLayer: this.annotationLayer?.annotationLayer
  10502. });
  10503. }
  10504. this.#renderAnnotationEditorLayer();
  10505. }, error => {
  10506. if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
  10507. showCanvas?.(true);
  10508. }
  10509. return this.#finishRenderTask(renderTask, error);
  10510. });
  10511. if (pdfPage.isPureXfa) {
  10512. if (!this.xfaLayer) {
  10513. const {
  10514. annotationStorage,
  10515. linkService
  10516. } = this.#layerProperties();
  10517. this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({
  10518. pageDiv: div,
  10519. pdfPage,
  10520. annotationStorage,
  10521. linkService
  10522. });
  10523. } else if (this.xfaLayer.div) {
  10524. div.append(this.xfaLayer.div);
  10525. }
  10526. this.#renderXfaLayer();
  10527. }
  10528. div.setAttribute("data-loaded", true);
  10529. this.eventBus.dispatch("pagerender", {
  10530. source: this,
  10531. pageNumber: this.id
  10532. });
  10533. return resultPromise;
  10534. }
  10535. setPageLabel(label) {
  10536. this.pageLabel = typeof label === "string" ? label : null;
  10537. if (this.pageLabel !== null) {
  10538. this.div.setAttribute("data-page-label", this.pageLabel);
  10539. } else {
  10540. this.div.removeAttribute("data-page-label");
  10541. }
  10542. }
  10543. get thumbnailCanvas() {
  10544. const {
  10545. directDrawing,
  10546. initialOptionalContent,
  10547. regularAnnotations
  10548. } = this.#useThumbnailCanvas;
  10549. return directDrawing && initialOptionalContent && regularAnnotations ? this.canvas : null;
  10550. }
  10551. }
  10552. exports.PDFPageView = PDFPageView;
  10553. /***/
  10554. }),
  10555. /* 31 */
  10556. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10557. Object.defineProperty(exports, "__esModule", ({
  10558. value: true
  10559. }));
  10560. exports.AnnotationEditorLayerBuilder = void 0;
  10561. var _pdfjsLib = __webpack_require__(4);
  10562. var _l10n_utils = __webpack_require__(29);
  10563. class AnnotationEditorLayerBuilder {
  10564. #annotationLayer = null;
  10565. #uiManager;
  10566. constructor(options) {
  10567. this.pageDiv = options.pageDiv;
  10568. this.pdfPage = options.pdfPage;
  10569. this.accessibilityManager = options.accessibilityManager;
  10570. this.l10n = options.l10n || _l10n_utils.NullL10n;
  10571. this.annotationEditorLayer = null;
  10572. this.div = null;
  10573. this._cancelled = false;
  10574. this.#uiManager = options.uiManager;
  10575. this.#annotationLayer = options.annotationLayer || null;
  10576. }
  10577. async render(viewport, intent = "display") {
  10578. if (intent !== "display") {
  10579. return;
  10580. }
  10581. if (this._cancelled) {
  10582. return;
  10583. }
  10584. const clonedViewport = viewport.clone({
  10585. dontFlip: true
  10586. });
  10587. if (this.div) {
  10588. this.annotationEditorLayer.update({
  10589. viewport: clonedViewport
  10590. });
  10591. this.show();
  10592. return;
  10593. }
  10594. const div = this.div = document.createElement("div");
  10595. div.className = "annotationEditorLayer";
  10596. div.tabIndex = 0;
  10597. div.hidden = true;
  10598. this.pageDiv.append(div);
  10599. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  10600. uiManager: this.#uiManager,
  10601. div,
  10602. accessibilityManager: this.accessibilityManager,
  10603. pageIndex: this.pdfPage.pageNumber - 1,
  10604. l10n: this.l10n,
  10605. viewport: clonedViewport,
  10606. annotationLayer: this.#annotationLayer
  10607. });
  10608. const parameters = {
  10609. viewport: clonedViewport,
  10610. div,
  10611. annotations: null,
  10612. intent
  10613. };
  10614. this.annotationEditorLayer.render(parameters);
  10615. this.show();
  10616. }
  10617. cancel() {
  10618. this._cancelled = true;
  10619. if (!this.div) {
  10620. return;
  10621. }
  10622. this.pageDiv = null;
  10623. this.annotationEditorLayer.destroy();
  10624. this.div.remove();
  10625. }
  10626. hide() {
  10627. if (!this.div) {
  10628. return;
  10629. }
  10630. this.div.hidden = true;
  10631. }
  10632. show() {
  10633. if (!this.div || this.annotationEditorLayer.isEmpty) {
  10634. return;
  10635. }
  10636. this.div.hidden = false;
  10637. }
  10638. }
  10639. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  10640. /***/
  10641. }),
  10642. /* 32 */
  10643. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10644. Object.defineProperty(exports, "__esModule", ({
  10645. value: true
  10646. }));
  10647. exports.AnnotationLayerBuilder = void 0;
  10648. var _pdfjsLib = __webpack_require__(4);
  10649. var _l10n_utils = __webpack_require__(29);
  10650. var _ui_utils = __webpack_require__(3);
  10651. class AnnotationLayerBuilder {
  10652. #onPresentationModeChanged = null;
  10653. constructor({
  10654. pageDiv,
  10655. pdfPage,
  10656. linkService,
  10657. downloadManager,
  10658. annotationStorage = null,
  10659. imageResourcesPath = "",
  10660. renderForms = true,
  10661. l10n = _l10n_utils.NullL10n,
  10662. enableScripting = false,
  10663. hasJSActionsPromise = null,
  10664. fieldObjectsPromise = null,
  10665. annotationCanvasMap = null,
  10666. accessibilityManager = null
  10667. }) {
  10668. this.pageDiv = pageDiv;
  10669. this.pdfPage = pdfPage;
  10670. this.linkService = linkService;
  10671. this.downloadManager = downloadManager;
  10672. this.imageResourcesPath = imageResourcesPath;
  10673. this.renderForms = renderForms;
  10674. this.l10n = l10n;
  10675. this.annotationStorage = annotationStorage;
  10676. this.enableScripting = enableScripting;
  10677. this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
  10678. this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
  10679. this._annotationCanvasMap = annotationCanvasMap;
  10680. this._accessibilityManager = accessibilityManager;
  10681. this.annotationLayer = null;
  10682. this.div = null;
  10683. this._cancelled = false;
  10684. this._eventBus = linkService.eventBus;
  10685. }
  10686. async render(viewport, intent = "display") {
  10687. if (this.div) {
  10688. if (this._cancelled || !this.annotationLayer) {
  10689. return;
  10690. }
  10691. this.annotationLayer.update({
  10692. viewport: viewport.clone({
  10693. dontFlip: true
  10694. })
  10695. });
  10696. return;
  10697. }
  10698. const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
  10699. intent
  10700. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  10701. if (this._cancelled) {
  10702. return;
  10703. }
  10704. const div = this.div = document.createElement("div");
  10705. div.className = "annotationLayer";
  10706. this.pageDiv.append(div);
  10707. if (annotations.length === 0) {
  10708. this.hide();
  10709. return;
  10710. }
  10711. this.annotationLayer = new _pdfjsLib.AnnotationLayer({
  10712. div,
  10713. accessibilityManager: this._accessibilityManager,
  10714. annotationCanvasMap: this._annotationCanvasMap,
  10715. l10n: this.l10n,
  10716. page: this.pdfPage,
  10717. viewport: viewport.clone({
  10718. dontFlip: true
  10719. })
  10720. });
  10721. await this.annotationLayer.render({
  10722. annotations,
  10723. imageResourcesPath: this.imageResourcesPath,
  10724. renderForms: this.renderForms,
  10725. linkService: this.linkService,
  10726. downloadManager: this.downloadManager,
  10727. annotationStorage: this.annotationStorage,
  10728. enableScripting: this.enableScripting,
  10729. hasJSActions,
  10730. fieldObjects
  10731. });
  10732. if (this.linkService.isInPresentationMode) {
  10733. this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN);
  10734. }
  10735. if (!this.#onPresentationModeChanged) {
  10736. this.#onPresentationModeChanged = evt => {
  10737. this.#updatePresentationModeState(evt.state);
  10738. };
  10739. this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged);
  10740. }
  10741. }
  10742. cancel() {
  10743. this._cancelled = true;
  10744. if (this.#onPresentationModeChanged) {
  10745. this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged);
  10746. this.#onPresentationModeChanged = null;
  10747. }
  10748. }
  10749. hide() {
  10750. if (!this.div) {
  10751. return;
  10752. }
  10753. this.div.hidden = true;
  10754. }
  10755. #updatePresentationModeState(state) {
  10756. if (!this.div) {
  10757. return;
  10758. }
  10759. let disableFormElements = false;
  10760. switch (state) {
  10761. case _ui_utils.PresentationModeState.FULLSCREEN:
  10762. disableFormElements = true;
  10763. break;
  10764. case _ui_utils.PresentationModeState.NORMAL:
  10765. break;
  10766. default:
  10767. return;
  10768. }
  10769. for (const section of this.div.childNodes) {
  10770. if (section.hasAttribute("data-internal-link")) {
  10771. continue;
  10772. }
  10773. section.inert = disableFormElements;
  10774. }
  10775. }
  10776. }
  10777. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  10778. /***/
  10779. }),
  10780. /* 33 */
  10781. /***/ ((__unused_webpack_module, exports) => {
  10782. Object.defineProperty(exports, "__esModule", ({
  10783. value: true
  10784. }));
  10785. exports.StructTreeLayerBuilder = void 0;
  10786. const PDF_ROLE_TO_HTML_ROLE = {
  10787. Document: null,
  10788. DocumentFragment: null,
  10789. Part: "group",
  10790. Sect: "group",
  10791. Div: "group",
  10792. Aside: "note",
  10793. NonStruct: "none",
  10794. P: null,
  10795. H: "heading",
  10796. Title: null,
  10797. FENote: "note",
  10798. Sub: "group",
  10799. Lbl: null,
  10800. Span: null,
  10801. Em: null,
  10802. Strong: null,
  10803. Link: "link",
  10804. Annot: "note",
  10805. Form: "form",
  10806. Ruby: null,
  10807. RB: null,
  10808. RT: null,
  10809. RP: null,
  10810. Warichu: null,
  10811. WT: null,
  10812. WP: null,
  10813. L: "list",
  10814. LI: "listitem",
  10815. LBody: null,
  10816. Table: "table",
  10817. TR: "row",
  10818. TH: "columnheader",
  10819. TD: "cell",
  10820. THead: "columnheader",
  10821. TBody: null,
  10822. TFoot: null,
  10823. Caption: null,
  10824. Figure: "figure",
  10825. Formula: null,
  10826. Artifact: null
  10827. };
  10828. const HEADING_PATTERN = /^H(\d+)$/;
  10829. class StructTreeLayerBuilder {
  10830. #treeDom = undefined;
  10831. get renderingDone() {
  10832. return this.#treeDom !== undefined;
  10833. }
  10834. render(structTree) {
  10835. if (this.#treeDom !== undefined) {
  10836. return this.#treeDom;
  10837. }
  10838. const treeDom = this.#walk(structTree);
  10839. treeDom?.classList.add("structTree");
  10840. return this.#treeDom = treeDom;
  10841. }
  10842. hide() {
  10843. if (this.#treeDom && !this.#treeDom.hidden) {
  10844. this.#treeDom.hidden = true;
  10845. }
  10846. }
  10847. show() {
  10848. if (this.#treeDom?.hidden) {
  10849. this.#treeDom.hidden = false;
  10850. }
  10851. }
  10852. #setAttributes(structElement, htmlElement) {
  10853. if (structElement.alt !== undefined) {
  10854. htmlElement.setAttribute("aria-label", structElement.alt);
  10855. }
  10856. if (structElement.id !== undefined) {
  10857. htmlElement.setAttribute("aria-owns", structElement.id);
  10858. }
  10859. if (structElement.lang !== undefined) {
  10860. htmlElement.setAttribute("lang", structElement.lang);
  10861. }
  10862. }
  10863. #walk(node) {
  10864. if (!node) {
  10865. return null;
  10866. }
  10867. const element = document.createElement("span");
  10868. if ("role" in node) {
  10869. const {
  10870. role
  10871. } = node;
  10872. const match = role.match(HEADING_PATTERN);
  10873. if (match) {
  10874. element.setAttribute("role", "heading");
  10875. element.setAttribute("aria-level", match[1]);
  10876. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10877. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10878. }
  10879. }
  10880. this.#setAttributes(node, element);
  10881. if (node.children) {
  10882. if (node.children.length === 1 && "id" in node.children[0]) {
  10883. this.#setAttributes(node.children[0], element);
  10884. } else {
  10885. for (const kid of node.children) {
  10886. element.append(this.#walk(kid));
  10887. }
  10888. }
  10889. }
  10890. return element;
  10891. }
  10892. }
  10893. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10894. /***/
  10895. }),
  10896. /* 34 */
  10897. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10898. Object.defineProperty(exports, "__esModule", ({
  10899. value: true
  10900. }));
  10901. exports.TextAccessibilityManager = void 0;
  10902. var _ui_utils = __webpack_require__(3);
  10903. class TextAccessibilityManager {
  10904. #enabled = false;
  10905. #textChildren = null;
  10906. #textNodes = new Map();
  10907. #waitingElements = new Map();
  10908. setTextMapping(textDivs) {
  10909. this.#textChildren = textDivs;
  10910. }
  10911. static #compareElementPositions(e1, e2) {
  10912. const rect1 = e1.getBoundingClientRect();
  10913. const rect2 = e2.getBoundingClientRect();
  10914. if (rect1.width === 0 && rect1.height === 0) {
  10915. return +1;
  10916. }
  10917. if (rect2.width === 0 && rect2.height === 0) {
  10918. return -1;
  10919. }
  10920. const top1 = rect1.y;
  10921. const bot1 = rect1.y + rect1.height;
  10922. const mid1 = rect1.y + rect1.height / 2;
  10923. const top2 = rect2.y;
  10924. const bot2 = rect2.y + rect2.height;
  10925. const mid2 = rect2.y + rect2.height / 2;
  10926. if (mid1 <= top2 && mid2 >= bot1) {
  10927. return -1;
  10928. }
  10929. if (mid2 <= top1 && mid1 >= bot2) {
  10930. return +1;
  10931. }
  10932. const centerX1 = rect1.x + rect1.width / 2;
  10933. const centerX2 = rect2.x + rect2.width / 2;
  10934. return centerX1 - centerX2;
  10935. }
  10936. enable() {
  10937. if (this.#enabled) {
  10938. throw new Error("TextAccessibilityManager is already enabled.");
  10939. }
  10940. if (!this.#textChildren) {
  10941. throw new Error("Text divs and strings have not been set.");
  10942. }
  10943. this.#enabled = true;
  10944. this.#textChildren = this.#textChildren.slice();
  10945. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  10946. if (this.#textNodes.size > 0) {
  10947. const textChildren = this.#textChildren;
  10948. for (const [id, nodeIndex] of this.#textNodes) {
  10949. const element = document.getElementById(id);
  10950. if (!element) {
  10951. this.#textNodes.delete(id);
  10952. continue;
  10953. }
  10954. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  10955. }
  10956. }
  10957. for (const [element, isRemovable] of this.#waitingElements) {
  10958. this.addPointerInTextLayer(element, isRemovable);
  10959. }
  10960. this.#waitingElements.clear();
  10961. }
  10962. disable() {
  10963. if (!this.#enabled) {
  10964. return;
  10965. }
  10966. this.#waitingElements.clear();
  10967. this.#textChildren = null;
  10968. this.#enabled = false;
  10969. }
  10970. removePointerInTextLayer(element) {
  10971. if (!this.#enabled) {
  10972. this.#waitingElements.delete(element);
  10973. return;
  10974. }
  10975. const children = this.#textChildren;
  10976. if (!children || children.length === 0) {
  10977. return;
  10978. }
  10979. const {
  10980. id
  10981. } = element;
  10982. const nodeIndex = this.#textNodes.get(id);
  10983. if (nodeIndex === undefined) {
  10984. return;
  10985. }
  10986. const node = children[nodeIndex];
  10987. this.#textNodes.delete(id);
  10988. let owns = node.getAttribute("aria-owns");
  10989. if (owns?.includes(id)) {
  10990. owns = owns.split(" ").filter(x => x !== id).join(" ");
  10991. if (owns) {
  10992. node.setAttribute("aria-owns", owns);
  10993. } else {
  10994. node.removeAttribute("aria-owns");
  10995. node.setAttribute("role", "presentation");
  10996. }
  10997. }
  10998. }
  10999. #addIdToAriaOwns(id, node) {
  11000. const owns = node.getAttribute("aria-owns");
  11001. if (!owns?.includes(id)) {
  11002. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  11003. }
  11004. node.removeAttribute("role");
  11005. }
  11006. addPointerInTextLayer(element, isRemovable) {
  11007. const {
  11008. id
  11009. } = element;
  11010. if (!id) {
  11011. return;
  11012. }
  11013. if (!this.#enabled) {
  11014. this.#waitingElements.set(element, isRemovable);
  11015. return;
  11016. }
  11017. if (isRemovable) {
  11018. this.removePointerInTextLayer(element);
  11019. }
  11020. const children = this.#textChildren;
  11021. if (!children || children.length === 0) {
  11022. return;
  11023. }
  11024. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  11025. const nodeIndex = Math.max(0, index - 1);
  11026. this.#addIdToAriaOwns(id, children[nodeIndex]);
  11027. this.#textNodes.set(id, nodeIndex);
  11028. }
  11029. moveElementInDOM(container, element, contentElement, isRemovable) {
  11030. this.addPointerInTextLayer(contentElement, isRemovable);
  11031. if (!container.hasChildNodes()) {
  11032. container.append(element);
  11033. return;
  11034. }
  11035. const children = Array.from(container.childNodes).filter(node => node !== element);
  11036. if (children.length === 0) {
  11037. return;
  11038. }
  11039. const elementToCompare = contentElement || element;
  11040. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  11041. if (index === 0) {
  11042. children[0].before(element);
  11043. } else {
  11044. children[index - 1].after(element);
  11045. }
  11046. }
  11047. }
  11048. exports.TextAccessibilityManager = TextAccessibilityManager;
  11049. /***/
  11050. }),
  11051. /* 35 */
  11052. /***/ ((__unused_webpack_module, exports) => {
  11053. Object.defineProperty(exports, "__esModule", ({
  11054. value: true
  11055. }));
  11056. exports.TextHighlighter = void 0;
  11057. class TextHighlighter {
  11058. constructor({
  11059. findController,
  11060. eventBus,
  11061. pageIndex
  11062. }) {
  11063. this.findController = findController;
  11064. this.matches = [];
  11065. this.eventBus = eventBus;
  11066. this.pageIdx = pageIndex;
  11067. this._onUpdateTextLayerMatches = null;
  11068. this.textDivs = null;
  11069. this.textContentItemsStr = null;
  11070. this.enabled = false;
  11071. }
  11072. setTextMapping(divs, texts) {
  11073. this.textDivs = divs;
  11074. this.textContentItemsStr = texts;
  11075. }
  11076. enable() {
  11077. if (!this.textDivs || !this.textContentItemsStr) {
  11078. throw new Error("Text divs and strings have not been set.");
  11079. }
  11080. if (this.enabled) {
  11081. throw new Error("TextHighlighter is already enabled.");
  11082. }
  11083. this.enabled = true;
  11084. if (!this._onUpdateTextLayerMatches) {
  11085. this._onUpdateTextLayerMatches = evt => {
  11086. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  11087. this._updateMatches();
  11088. }
  11089. };
  11090. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11091. }
  11092. this._updateMatches();
  11093. }
  11094. disable() {
  11095. if (!this.enabled) {
  11096. return;
  11097. }
  11098. this.enabled = false;
  11099. if (this._onUpdateTextLayerMatches) {
  11100. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11101. this._onUpdateTextLayerMatches = null;
  11102. }
  11103. this._updateMatches(true);
  11104. }
  11105. _convertMatches(matches, matchesLength) {
  11106. if (!matches) {
  11107. return [];
  11108. }
  11109. const {
  11110. textContentItemsStr
  11111. } = this;
  11112. let i = 0,
  11113. iIndex = 0;
  11114. const end = textContentItemsStr.length - 1;
  11115. const result = [];
  11116. for (let m = 0, mm = matches.length; m < mm; m++) {
  11117. let matchIdx = matches[m];
  11118. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  11119. iIndex += textContentItemsStr[i].length;
  11120. i++;
  11121. }
  11122. if (i === textContentItemsStr.length) {
  11123. console.error("Could not find a matching mapping");
  11124. }
  11125. const match = {
  11126. begin: {
  11127. divIdx: i,
  11128. offset: matchIdx - iIndex
  11129. }
  11130. };
  11131. matchIdx += matchesLength[m];
  11132. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  11133. iIndex += textContentItemsStr[i].length;
  11134. i++;
  11135. }
  11136. match.end = {
  11137. divIdx: i,
  11138. offset: matchIdx - iIndex
  11139. };
  11140. result.push(match);
  11141. }
  11142. return result;
  11143. }
  11144. _renderMatches(matches) {
  11145. if (matches.length === 0) {
  11146. return;
  11147. }
  11148. const {
  11149. findController,
  11150. pageIdx
  11151. } = this;
  11152. const {
  11153. textContentItemsStr,
  11154. textDivs
  11155. } = this;
  11156. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  11157. const selectedMatchIdx = findController.selected.matchIdx;
  11158. const highlightAll = findController.state.highlightAll;
  11159. let prevEnd = null;
  11160. const infinity = {
  11161. divIdx: -1,
  11162. offset: undefined
  11163. };
  11164. function beginText(begin, className) {
  11165. const divIdx = begin.divIdx;
  11166. textDivs[divIdx].textContent = "";
  11167. return appendTextToDiv(divIdx, 0, begin.offset, className);
  11168. }
  11169. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  11170. let div = textDivs[divIdx];
  11171. if (div.nodeType === Node.TEXT_NODE) {
  11172. const span = document.createElement("span");
  11173. div.before(span);
  11174. span.append(div);
  11175. textDivs[divIdx] = span;
  11176. div = span;
  11177. }
  11178. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  11179. const node = document.createTextNode(content);
  11180. if (className) {
  11181. const span = document.createElement("span");
  11182. span.className = `${className} appended`;
  11183. span.append(node);
  11184. div.append(span);
  11185. return className.includes("selected") ? span.offsetLeft : 0;
  11186. }
  11187. div.append(node);
  11188. return 0;
  11189. }
  11190. let i0 = selectedMatchIdx,
  11191. i1 = i0 + 1;
  11192. if (highlightAll) {
  11193. i0 = 0;
  11194. i1 = matches.length;
  11195. } else if (!isSelectedPage) {
  11196. return;
  11197. }
  11198. let lastDivIdx = -1;
  11199. let lastOffset = -1;
  11200. for (let i = i0; i < i1; i++) {
  11201. const match = matches[i];
  11202. const begin = match.begin;
  11203. if (begin.divIdx === lastDivIdx && begin.offset === lastOffset) {
  11204. continue;
  11205. }
  11206. lastDivIdx = begin.divIdx;
  11207. lastOffset = begin.offset;
  11208. const end = match.end;
  11209. const isSelected = isSelectedPage && i === selectedMatchIdx;
  11210. const highlightSuffix = isSelected ? " selected" : "";
  11211. let selectedLeft = 0;
  11212. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  11213. if (prevEnd !== null) {
  11214. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11215. }
  11216. beginText(begin);
  11217. } else {
  11218. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  11219. }
  11220. if (begin.divIdx === end.divIdx) {
  11221. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  11222. } else {
  11223. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  11224. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  11225. textDivs[n0].className = "highlight middle" + highlightSuffix;
  11226. }
  11227. beginText(end, "highlight end" + highlightSuffix);
  11228. }
  11229. prevEnd = end;
  11230. if (isSelected) {
  11231. findController.scrollMatchIntoView({
  11232. element: textDivs[begin.divIdx],
  11233. selectedLeft,
  11234. pageIndex: pageIdx,
  11235. matchIndex: selectedMatchIdx
  11236. });
  11237. }
  11238. }
  11239. if (prevEnd) {
  11240. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11241. }
  11242. }
  11243. _updateMatches(reset = false) {
  11244. if (!this.enabled && !reset) {
  11245. return;
  11246. }
  11247. const {
  11248. findController,
  11249. matches,
  11250. pageIdx
  11251. } = this;
  11252. const {
  11253. textContentItemsStr,
  11254. textDivs
  11255. } = this;
  11256. let clearedUntilDivIdx = -1;
  11257. for (const match of matches) {
  11258. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  11259. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  11260. const div = textDivs[n];
  11261. div.textContent = textContentItemsStr[n];
  11262. div.className = "";
  11263. }
  11264. clearedUntilDivIdx = match.end.divIdx + 1;
  11265. }
  11266. if (!findController?.highlightMatches || reset) {
  11267. return;
  11268. }
  11269. const pageMatches = findController.pageMatches[pageIdx] || null;
  11270. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  11271. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  11272. this._renderMatches(this.matches);
  11273. }
  11274. }
  11275. exports.TextHighlighter = TextHighlighter;
  11276. /***/
  11277. }),
  11278. /* 36 */
  11279. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11280. Object.defineProperty(exports, "__esModule", ({
  11281. value: true
  11282. }));
  11283. exports.TextLayerBuilder = void 0;
  11284. var _pdfjsLib = __webpack_require__(4);
  11285. var _ui_utils = __webpack_require__(3);
  11286. class TextLayerBuilder {
  11287. #enablePermissions = false;
  11288. #rotation = 0;
  11289. #scale = 0;
  11290. #textContentSource = null;
  11291. constructor({
  11292. highlighter = null,
  11293. accessibilityManager = null,
  11294. isOffscreenCanvasSupported = true,
  11295. enablePermissions = false
  11296. }) {
  11297. this.textContentItemsStr = [];
  11298. this.renderingDone = false;
  11299. this.textDivs = [];
  11300. this.textDivProperties = new WeakMap();
  11301. this.textLayerRenderTask = null;
  11302. this.highlighter = highlighter;
  11303. this.accessibilityManager = accessibilityManager;
  11304. this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
  11305. this.#enablePermissions = enablePermissions === true;
  11306. this.div = document.createElement("div");
  11307. this.div.className = "textLayer";
  11308. this.hide();
  11309. }
  11310. #finishRendering() {
  11311. this.renderingDone = true;
  11312. const endOfContent = document.createElement("div");
  11313. endOfContent.className = "endOfContent";
  11314. this.div.append(endOfContent);
  11315. this.#bindMouse();
  11316. }
  11317. get numTextDivs() {
  11318. return this.textDivs.length;
  11319. }
  11320. async render(viewport) {
  11321. if (!this.#textContentSource) {
  11322. throw new Error('No "textContentSource" parameter specified.');
  11323. }
  11324. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  11325. const {
  11326. rotation
  11327. } = viewport;
  11328. if (this.renderingDone) {
  11329. const mustRotate = rotation !== this.#rotation;
  11330. const mustRescale = scale !== this.#scale;
  11331. if (mustRotate || mustRescale) {
  11332. this.hide();
  11333. (0, _pdfjsLib.updateTextLayer)({
  11334. container: this.div,
  11335. viewport,
  11336. textDivs: this.textDivs,
  11337. textDivProperties: this.textDivProperties,
  11338. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  11339. mustRescale,
  11340. mustRotate
  11341. });
  11342. this.#scale = scale;
  11343. this.#rotation = rotation;
  11344. }
  11345. this.show();
  11346. return;
  11347. }
  11348. this.cancel();
  11349. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  11350. this.accessibilityManager?.setTextMapping(this.textDivs);
  11351. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  11352. textContentSource: this.#textContentSource,
  11353. container: this.div,
  11354. viewport,
  11355. textDivs: this.textDivs,
  11356. textDivProperties: this.textDivProperties,
  11357. textContentItemsStr: this.textContentItemsStr,
  11358. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
  11359. });
  11360. await this.textLayerRenderTask.promise;
  11361. this.#finishRendering();
  11362. this.#scale = scale;
  11363. this.#rotation = rotation;
  11364. this.show();
  11365. this.accessibilityManager?.enable();
  11366. }
  11367. hide() {
  11368. if (!this.div.hidden) {
  11369. this.highlighter?.disable();
  11370. this.div.hidden = true;
  11371. }
  11372. }
  11373. show() {
  11374. if (this.div.hidden && this.renderingDone) {
  11375. this.div.hidden = false;
  11376. this.highlighter?.enable();
  11377. }
  11378. }
  11379. cancel() {
  11380. if (this.textLayerRenderTask) {
  11381. this.textLayerRenderTask.cancel();
  11382. this.textLayerRenderTask = null;
  11383. }
  11384. this.highlighter?.disable();
  11385. this.accessibilityManager?.disable();
  11386. this.textContentItemsStr.length = 0;
  11387. this.textDivs.length = 0;
  11388. this.textDivProperties = new WeakMap();
  11389. }
  11390. setTextContentSource(source) {
  11391. this.cancel();
  11392. this.#textContentSource = source;
  11393. }
  11394. #bindMouse() {
  11395. const {
  11396. div
  11397. } = this;
  11398. div.addEventListener("mousedown", evt => {
  11399. const end = div.querySelector(".endOfContent");
  11400. if (!end) {
  11401. return;
  11402. }
  11403. let adjustTop = evt.target !== div;
  11404. adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  11405. if (adjustTop) {
  11406. const divBounds = div.getBoundingClientRect();
  11407. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  11408. end.style.top = (r * 100).toFixed(2) + "%";
  11409. }
  11410. end.classList.add("active");
  11411. });
  11412. div.addEventListener("mouseup", () => {
  11413. const end = div.querySelector(".endOfContent");
  11414. if (!end) {
  11415. return;
  11416. }
  11417. end.style.top = "";
  11418. end.classList.remove("active");
  11419. });
  11420. div.addEventListener("copy", event => {
  11421. if (!this.#enablePermissions) {
  11422. const selection = document.getSelection();
  11423. event.clipboardData.setData("text/plain", (0, _ui_utils.removeNullCharacters)((0, _pdfjsLib.normalizeUnicode)(selection.toString())));
  11424. }
  11425. event.preventDefault();
  11426. event.stopPropagation();
  11427. });
  11428. }
  11429. }
  11430. exports.TextLayerBuilder = TextLayerBuilder;
  11431. /***/
  11432. }),
  11433. /* 37 */
  11434. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11435. Object.defineProperty(exports, "__esModule", ({
  11436. value: true
  11437. }));
  11438. exports.XfaLayerBuilder = void 0;
  11439. var _pdfjsLib = __webpack_require__(4);
  11440. class XfaLayerBuilder {
  11441. constructor({
  11442. pageDiv,
  11443. pdfPage,
  11444. annotationStorage = null,
  11445. linkService,
  11446. xfaHtml = null
  11447. }) {
  11448. this.pageDiv = pageDiv;
  11449. this.pdfPage = pdfPage;
  11450. this.annotationStorage = annotationStorage;
  11451. this.linkService = linkService;
  11452. this.xfaHtml = xfaHtml;
  11453. this.div = null;
  11454. this._cancelled = false;
  11455. }
  11456. async render(viewport, intent = "display") {
  11457. if (intent === "print") {
  11458. const parameters = {
  11459. viewport: viewport.clone({
  11460. dontFlip: true
  11461. }),
  11462. div: this.div,
  11463. xfaHtml: this.xfaHtml,
  11464. annotationStorage: this.annotationStorage,
  11465. linkService: this.linkService,
  11466. intent
  11467. };
  11468. const div = document.createElement("div");
  11469. this.pageDiv.append(div);
  11470. parameters.div = div;
  11471. return _pdfjsLib.XfaLayer.render(parameters);
  11472. }
  11473. const xfaHtml = await this.pdfPage.getXfa();
  11474. if (this._cancelled || !xfaHtml) {
  11475. return {
  11476. textDivs: []
  11477. };
  11478. }
  11479. const parameters = {
  11480. viewport: viewport.clone({
  11481. dontFlip: true
  11482. }),
  11483. div: this.div,
  11484. xfaHtml,
  11485. annotationStorage: this.annotationStorage,
  11486. linkService: this.linkService,
  11487. intent
  11488. };
  11489. if (this.div) {
  11490. return _pdfjsLib.XfaLayer.update(parameters);
  11491. }
  11492. this.div = document.createElement("div");
  11493. this.pageDiv.append(this.div);
  11494. parameters.div = this.div;
  11495. return _pdfjsLib.XfaLayer.render(parameters);
  11496. }
  11497. cancel() {
  11498. this._cancelled = true;
  11499. }
  11500. hide() {
  11501. if (!this.div) {
  11502. return;
  11503. }
  11504. this.div.hidden = true;
  11505. }
  11506. }
  11507. exports.XfaLayerBuilder = XfaLayerBuilder;
  11508. /***/
  11509. }),
  11510. /* 38 */
  11511. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11512. Object.defineProperty(exports, "__esModule", ({
  11513. value: true
  11514. }));
  11515. exports.SecondaryToolbar = void 0;
  11516. var _ui_utils = __webpack_require__(3);
  11517. var _pdf_viewer = __webpack_require__(28);
  11518. class SecondaryToolbar {
  11519. constructor(options, eventBus, externalServices) {
  11520. this.toolbar = options.toolbar;
  11521. this.toggleButton = options.toggleButton;
  11522. this.buttons = [{
  11523. element: options.presentationModeButton,
  11524. eventName: "presentationmode",
  11525. close: true
  11526. }, {
  11527. element: options.printButton,
  11528. eventName: "print",
  11529. close: true
  11530. }, {
  11531. element: options.downloadButton,
  11532. eventName: "download",
  11533. close: true
  11534. }, {
  11535. element: options.viewBookmarkButton,
  11536. eventName: null,
  11537. close: true
  11538. }, {
  11539. element: options.firstPageButton,
  11540. eventName: "firstpage",
  11541. close: true
  11542. }, {
  11543. element: options.lastPageButton,
  11544. eventName: "lastpage",
  11545. close: true
  11546. }, {
  11547. element: options.pageRotateCwButton,
  11548. eventName: "rotatecw",
  11549. close: false
  11550. }, {
  11551. element: options.pageRotateCcwButton,
  11552. eventName: "rotateccw",
  11553. close: false
  11554. }, {
  11555. element: options.cursorSelectToolButton,
  11556. eventName: "switchcursortool",
  11557. eventDetails: {
  11558. tool: _ui_utils.CursorTool.SELECT
  11559. },
  11560. close: true
  11561. }, {
  11562. element: options.cursorHandToolButton,
  11563. eventName: "switchcursortool",
  11564. eventDetails: {
  11565. tool: _ui_utils.CursorTool.HAND
  11566. },
  11567. close: true
  11568. }, {
  11569. element: options.scrollPageButton,
  11570. eventName: "switchscrollmode",
  11571. eventDetails: {
  11572. mode: _ui_utils.ScrollMode.PAGE
  11573. },
  11574. close: true
  11575. }, {
  11576. element: options.scrollVerticalButton,
  11577. eventName: "switchscrollmode",
  11578. eventDetails: {
  11579. mode: _ui_utils.ScrollMode.VERTICAL
  11580. },
  11581. close: true
  11582. }, {
  11583. element: options.scrollHorizontalButton,
  11584. eventName: "switchscrollmode",
  11585. eventDetails: {
  11586. mode: _ui_utils.ScrollMode.HORIZONTAL
  11587. },
  11588. close: true
  11589. }, {
  11590. element: options.scrollWrappedButton,
  11591. eventName: "switchscrollmode",
  11592. eventDetails: {
  11593. mode: _ui_utils.ScrollMode.WRAPPED
  11594. },
  11595. close: true
  11596. }, {
  11597. element: options.spreadNoneButton,
  11598. eventName: "switchspreadmode",
  11599. eventDetails: {
  11600. mode: _ui_utils.SpreadMode.NONE
  11601. },
  11602. close: true
  11603. }, {
  11604. element: options.spreadOddButton,
  11605. eventName: "switchspreadmode",
  11606. eventDetails: {
  11607. mode: _ui_utils.SpreadMode.ODD
  11608. },
  11609. close: true
  11610. }, {
  11611. element: options.spreadEvenButton,
  11612. eventName: "switchspreadmode",
  11613. eventDetails: {
  11614. mode: _ui_utils.SpreadMode.EVEN
  11615. },
  11616. close: true
  11617. }, {
  11618. element: options.documentPropertiesButton,
  11619. eventName: "documentproperties",
  11620. close: true
  11621. }];
  11622. this.buttons.push({
  11623. element: options.openFileButton,
  11624. eventName: "openfile",
  11625. close: true
  11626. });
  11627. this.items = {
  11628. firstPage: options.firstPageButton,
  11629. lastPage: options.lastPageButton,
  11630. pageRotateCw: options.pageRotateCwButton,
  11631. pageRotateCcw: options.pageRotateCcwButton
  11632. };
  11633. this.eventBus = eventBus;
  11634. this.externalServices = externalServices;
  11635. this.opened = false;
  11636. this.#bindClickListeners();
  11637. this.#bindCursorToolsListener(options);
  11638. this.#bindScrollModeListener(options);
  11639. this.#bindSpreadModeListener(options);
  11640. this.reset();
  11641. }
  11642. get isOpen() {
  11643. return this.opened;
  11644. }
  11645. setPageNumber(pageNumber) {
  11646. this.pageNumber = pageNumber;
  11647. this.#updateUIState();
  11648. }
  11649. setPagesCount(pagesCount) {
  11650. this.pagesCount = pagesCount;
  11651. this.#updateUIState();
  11652. }
  11653. reset() {
  11654. this.pageNumber = 0;
  11655. this.pagesCount = 0;
  11656. this.#updateUIState();
  11657. this.eventBus.dispatch("secondarytoolbarreset", {
  11658. source: this
  11659. });
  11660. }
  11661. #updateUIState() {
  11662. this.items.firstPage.disabled = this.pageNumber <= 1;
  11663. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  11664. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  11665. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  11666. }
  11667. #bindClickListeners() {
  11668. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  11669. for (const {
  11670. element,
  11671. eventName,
  11672. close,
  11673. eventDetails
  11674. } of this.buttons) {
  11675. element.addEventListener("click", evt => {
  11676. if (eventName !== null) {
  11677. this.eventBus.dispatch(eventName, {
  11678. source: this,
  11679. ...eventDetails
  11680. });
  11681. }
  11682. if (close) {
  11683. this.close();
  11684. }
  11685. this.externalServices.reportTelemetry({
  11686. type: "buttons",
  11687. data: {
  11688. id: element.id
  11689. }
  11690. });
  11691. });
  11692. }
  11693. }
  11694. #bindCursorToolsListener({
  11695. cursorSelectToolButton,
  11696. cursorHandToolButton
  11697. }) {
  11698. this.eventBus._on("cursortoolchanged", ({
  11699. tool
  11700. }) => {
  11701. (0, _ui_utils.toggleCheckedBtn)(cursorSelectToolButton, tool === _ui_utils.CursorTool.SELECT);
  11702. (0, _ui_utils.toggleCheckedBtn)(cursorHandToolButton, tool === _ui_utils.CursorTool.HAND);
  11703. });
  11704. }
  11705. #bindScrollModeListener({
  11706. scrollPageButton,
  11707. scrollVerticalButton,
  11708. scrollHorizontalButton,
  11709. scrollWrappedButton,
  11710. spreadNoneButton,
  11711. spreadOddButton,
  11712. spreadEvenButton
  11713. }) {
  11714. const scrollModeChanged = ({
  11715. mode
  11716. }) => {
  11717. (0, _ui_utils.toggleCheckedBtn)(scrollPageButton, mode === _ui_utils.ScrollMode.PAGE);
  11718. (0, _ui_utils.toggleCheckedBtn)(scrollVerticalButton, mode === _ui_utils.ScrollMode.VERTICAL);
  11719. (0, _ui_utils.toggleCheckedBtn)(scrollHorizontalButton, mode === _ui_utils.ScrollMode.HORIZONTAL);
  11720. (0, _ui_utils.toggleCheckedBtn)(scrollWrappedButton, mode === _ui_utils.ScrollMode.WRAPPED);
  11721. const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11722. scrollPageButton.disabled = forceScrollModePage;
  11723. scrollVerticalButton.disabled = forceScrollModePage;
  11724. scrollHorizontalButton.disabled = forceScrollModePage;
  11725. scrollWrappedButton.disabled = forceScrollModePage;
  11726. const isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  11727. spreadNoneButton.disabled = isHorizontal;
  11728. spreadOddButton.disabled = isHorizontal;
  11729. spreadEvenButton.disabled = isHorizontal;
  11730. };
  11731. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  11732. this.eventBus._on("secondarytoolbarreset", evt => {
  11733. if (evt.source === this) {
  11734. scrollModeChanged({
  11735. mode: _ui_utils.ScrollMode.VERTICAL
  11736. });
  11737. }
  11738. });
  11739. }
  11740. #bindSpreadModeListener({
  11741. spreadNoneButton,
  11742. spreadOddButton,
  11743. spreadEvenButton
  11744. }) {
  11745. const spreadModeChanged = ({
  11746. mode
  11747. }) => {
  11748. (0, _ui_utils.toggleCheckedBtn)(spreadNoneButton, mode === _ui_utils.SpreadMode.NONE);
  11749. (0, _ui_utils.toggleCheckedBtn)(spreadOddButton, mode === _ui_utils.SpreadMode.ODD);
  11750. (0, _ui_utils.toggleCheckedBtn)(spreadEvenButton, mode === _ui_utils.SpreadMode.EVEN);
  11751. };
  11752. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  11753. this.eventBus._on("secondarytoolbarreset", evt => {
  11754. if (evt.source === this) {
  11755. spreadModeChanged({
  11756. mode: _ui_utils.SpreadMode.NONE
  11757. });
  11758. }
  11759. });
  11760. }
  11761. open() {
  11762. if (this.opened) {
  11763. return;
  11764. }
  11765. this.opened = true;
  11766. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true, this.toolbar);
  11767. }
  11768. close() {
  11769. if (!this.opened) {
  11770. return;
  11771. }
  11772. this.opened = false;
  11773. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false, this.toolbar);
  11774. }
  11775. toggle() {
  11776. if (this.opened) {
  11777. this.close();
  11778. } else {
  11779. this.open();
  11780. }
  11781. }
  11782. }
  11783. exports.SecondaryToolbar = SecondaryToolbar;
  11784. /***/
  11785. }),
  11786. /* 39 */
  11787. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11788. Object.defineProperty(exports, "__esModule", ({
  11789. value: true
  11790. }));
  11791. exports.Toolbar = void 0;
  11792. var _ui_utils = __webpack_require__(3);
  11793. var _pdfjsLib = __webpack_require__(4);
  11794. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  11795. class Toolbar {
  11796. #wasLocalized = false;
  11797. constructor(options, eventBus, l10n) {
  11798. this.toolbar = options.container;
  11799. this.eventBus = eventBus;
  11800. this.l10n = l10n;
  11801. this.buttons = [{
  11802. element: options.previous,
  11803. eventName: "previouspage"
  11804. }, {
  11805. element: options.next,
  11806. eventName: "nextpage"
  11807. }, {
  11808. element: options.zoomIn,
  11809. eventName: "zoomin"
  11810. }, {
  11811. element: options.zoomOut,
  11812. eventName: "zoomout"
  11813. }, {
  11814. element: options.print,
  11815. eventName: "print"
  11816. }, {
  11817. element: options.download,
  11818. eventName: "download"
  11819. }, {
  11820. element: options.editorFreeTextButton,
  11821. eventName: "switchannotationeditormode",
  11822. eventDetails: {
  11823. get mode() {
  11824. const {
  11825. classList
  11826. } = options.editorFreeTextButton;
  11827. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  11828. }
  11829. }
  11830. }, {
  11831. element: options.editorInkButton,
  11832. eventName: "switchannotationeditormode",
  11833. eventDetails: {
  11834. get mode() {
  11835. const {
  11836. classList
  11837. } = options.editorInkButton;
  11838. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  11839. }
  11840. }
  11841. }, {
  11842. element: options.editorStampButton,
  11843. eventName: "switchannotationeditormode",
  11844. eventDetails: {
  11845. get mode() {
  11846. const {
  11847. classList
  11848. } = options.editorStampButton;
  11849. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.STAMP;
  11850. }
  11851. }
  11852. }];
  11853. this.buttons.push({
  11854. element: options.openFile,
  11855. eventName: "openfile"
  11856. });
  11857. this.items = {
  11858. numPages: options.numPages,
  11859. pageNumber: options.pageNumber,
  11860. scaleSelect: options.scaleSelect,
  11861. customScaleOption: options.customScaleOption,
  11862. previous: options.previous,
  11863. next: options.next,
  11864. zoomIn: options.zoomIn,
  11865. zoomOut: options.zoomOut
  11866. };
  11867. this.#bindListeners(options);
  11868. this.reset();
  11869. }
  11870. setPageNumber(pageNumber, pageLabel) {
  11871. this.pageNumber = pageNumber;
  11872. this.pageLabel = pageLabel;
  11873. this.#updateUIState(false);
  11874. }
  11875. setPagesCount(pagesCount, hasPageLabels) {
  11876. this.pagesCount = pagesCount;
  11877. this.hasPageLabels = hasPageLabels;
  11878. this.#updateUIState(true);
  11879. }
  11880. setPageScale(pageScaleValue, pageScale) {
  11881. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11882. this.pageScale = pageScale;
  11883. this.#updateUIState(false);
  11884. }
  11885. reset() {
  11886. this.pageNumber = 0;
  11887. this.pageLabel = null;
  11888. this.hasPageLabels = false;
  11889. this.pagesCount = 0;
  11890. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  11891. this.pageScale = _ui_utils.DEFAULT_SCALE;
  11892. this.#updateUIState(true);
  11893. this.updateLoadingIndicatorState();
  11894. this.eventBus.dispatch("toolbarreset", {
  11895. source: this
  11896. });
  11897. }
  11898. #bindListeners(options) {
  11899. const {
  11900. pageNumber,
  11901. scaleSelect
  11902. } = this.items;
  11903. const self = this;
  11904. for (const {
  11905. element,
  11906. eventName,
  11907. eventDetails
  11908. } of this.buttons) {
  11909. element.addEventListener("click", evt => {
  11910. if (eventName !== null) {
  11911. this.eventBus.dispatch(eventName, {
  11912. source: this,
  11913. ...eventDetails
  11914. });
  11915. }
  11916. });
  11917. }
  11918. pageNumber.addEventListener("click", function () {
  11919. this.select();
  11920. });
  11921. pageNumber.addEventListener("change", function () {
  11922. self.eventBus.dispatch("pagenumberchanged", {
  11923. source: self,
  11924. value: this.value
  11925. });
  11926. });
  11927. scaleSelect.addEventListener("change", function () {
  11928. if (this.value === "custom") {
  11929. return;
  11930. }
  11931. self.eventBus.dispatch("scalechanged", {
  11932. source: self,
  11933. value: this.value
  11934. });
  11935. });
  11936. scaleSelect.addEventListener("click", function (evt) {
  11937. const target = evt.target;
  11938. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11939. this.blur();
  11940. }
  11941. });
  11942. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  11943. this.eventBus._on("localized", () => {
  11944. this.#wasLocalized = true;
  11945. this.#adjustScaleWidth();
  11946. this.#updateUIState(true);
  11947. });
  11948. this.#bindEditorToolsListener(options);
  11949. }
  11950. #bindEditorToolsListener({
  11951. editorFreeTextButton,
  11952. editorFreeTextParamsToolbar,
  11953. editorInkButton,
  11954. editorInkParamsToolbar,
  11955. editorStampButton,
  11956. editorStampParamsToolbar
  11957. }) {
  11958. const editorModeChanged = ({
  11959. mode
  11960. }) => {
  11961. (0, _ui_utils.toggleCheckedBtn)(editorFreeTextButton, mode === _pdfjsLib.AnnotationEditorType.FREETEXT, editorFreeTextParamsToolbar);
  11962. (0, _ui_utils.toggleCheckedBtn)(editorInkButton, mode === _pdfjsLib.AnnotationEditorType.INK, editorInkParamsToolbar);
  11963. (0, _ui_utils.toggleCheckedBtn)(editorStampButton, mode === _pdfjsLib.AnnotationEditorType.STAMP, editorStampParamsToolbar);
  11964. const isDisable = mode === _pdfjsLib.AnnotationEditorType.DISABLE;
  11965. editorFreeTextButton.disabled = isDisable;
  11966. editorInkButton.disabled = isDisable;
  11967. editorStampButton.disabled = isDisable;
  11968. };
  11969. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  11970. this.eventBus._on("toolbarreset", evt => {
  11971. if (evt.source === this) {
  11972. editorModeChanged({
  11973. mode: _pdfjsLib.AnnotationEditorType.DISABLE
  11974. });
  11975. }
  11976. });
  11977. }
  11978. #updateUIState(resetNumPages = false) {
  11979. if (!this.#wasLocalized) {
  11980. return;
  11981. }
  11982. const {
  11983. pageNumber,
  11984. pagesCount,
  11985. pageScaleValue,
  11986. pageScale,
  11987. items
  11988. } = this;
  11989. if (resetNumPages) {
  11990. if (this.hasPageLabels) {
  11991. items.pageNumber.type = "text";
  11992. } else {
  11993. items.pageNumber.type = "number";
  11994. this.l10n.get("of_pages", {
  11995. pagesCount
  11996. }).then(msg => {
  11997. items.numPages.textContent = msg;
  11998. });
  11999. }
  12000. items.pageNumber.max = pagesCount;
  12001. }
  12002. if (this.hasPageLabels) {
  12003. items.pageNumber.value = this.pageLabel;
  12004. this.l10n.get("page_of_pages", {
  12005. pageNumber,
  12006. pagesCount
  12007. }).then(msg => {
  12008. items.numPages.textContent = msg;
  12009. });
  12010. } else {
  12011. items.pageNumber.value = pageNumber;
  12012. }
  12013. items.previous.disabled = pageNumber <= 1;
  12014. items.next.disabled = pageNumber >= pagesCount;
  12015. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  12016. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  12017. this.l10n.get("page_scale_percent", {
  12018. scale: Math.round(pageScale * 10000) / 100
  12019. }).then(msg => {
  12020. let predefinedValueFound = false;
  12021. for (const option of items.scaleSelect.options) {
  12022. if (option.value !== pageScaleValue) {
  12023. option.selected = false;
  12024. continue;
  12025. }
  12026. option.selected = true;
  12027. predefinedValueFound = true;
  12028. }
  12029. if (!predefinedValueFound) {
  12030. items.customScaleOption.textContent = msg;
  12031. items.customScaleOption.selected = true;
  12032. }
  12033. });
  12034. }
  12035. updateLoadingIndicatorState(loading = false) {
  12036. const {
  12037. pageNumber
  12038. } = this.items;
  12039. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  12040. }
  12041. async #adjustScaleWidth() {
  12042. const {
  12043. items,
  12044. l10n
  12045. } = this;
  12046. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  12047. await _ui_utils.animationStarted;
  12048. const style = getComputedStyle(items.scaleSelect);
  12049. const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width"));
  12050. const canvas = document.createElement("canvas");
  12051. const ctx = canvas.getContext("2d", {
  12052. alpha: false
  12053. });
  12054. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  12055. let maxWidth = 0;
  12056. for (const predefinedValue of await predefinedValuesPromise) {
  12057. const {
  12058. width
  12059. } = ctx.measureText(predefinedValue);
  12060. if (width > maxWidth) {
  12061. maxWidth = width;
  12062. }
  12063. }
  12064. maxWidth += 0.3 * scaleSelectWidth;
  12065. if (maxWidth > scaleSelectWidth) {
  12066. const container = items.scaleSelect.parentNode;
  12067. container.style.setProperty("--scale-select-width", `${maxWidth}px`);
  12068. }
  12069. canvas.width = 0;
  12070. canvas.height = 0;
  12071. }
  12072. }
  12073. exports.Toolbar = Toolbar;
  12074. /***/
  12075. }),
  12076. /* 40 */
  12077. /***/ ((__unused_webpack_module, exports) => {
  12078. Object.defineProperty(exports, "__esModule", ({
  12079. value: true
  12080. }));
  12081. exports.ViewHistory = void 0;
  12082. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  12083. class ViewHistory {
  12084. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  12085. this.fingerprint = fingerprint;
  12086. this.cacheSize = cacheSize;
  12087. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  12088. const database = JSON.parse(databaseStr || "{}");
  12089. let index = -1;
  12090. if (!Array.isArray(database.files)) {
  12091. database.files = [];
  12092. } else {
  12093. while (database.files.length >= this.cacheSize) {
  12094. database.files.shift();
  12095. }
  12096. for (let i = 0, ii = database.files.length; i < ii; i++) {
  12097. const branch = database.files[i];
  12098. if (branch.fingerprint === this.fingerprint) {
  12099. index = i;
  12100. break;
  12101. }
  12102. }
  12103. }
  12104. if (index === -1) {
  12105. index = database.files.push({
  12106. fingerprint: this.fingerprint
  12107. }) - 1;
  12108. }
  12109. this.file = database.files[index];
  12110. this.database = database;
  12111. });
  12112. }
  12113. async _writeToStorage() {
  12114. const databaseStr = JSON.stringify(this.database);
  12115. // localStorage.setItem("pdfjs.history", databaseStr);
  12116. }
  12117. async _readFromStorage() {
  12118. // return localStorage.getItem("pdfjs.history");
  12119. }
  12120. async set(name, val) {
  12121. await this._initializedPromise;
  12122. this.file[name] = val;
  12123. return this._writeToStorage();
  12124. }
  12125. async setMultiple(properties) {
  12126. await this._initializedPromise;
  12127. for (const name in properties) {
  12128. this.file[name] = properties[name];
  12129. }
  12130. return this._writeToStorage();
  12131. }
  12132. async get(name, defaultValue) {
  12133. await this._initializedPromise;
  12134. const val = this.file[name];
  12135. return val !== undefined ? val : defaultValue;
  12136. }
  12137. async getMultiple(properties) {
  12138. await this._initializedPromise;
  12139. const values = Object.create(null);
  12140. for (const name in properties) {
  12141. const val = this.file[name];
  12142. values[name] = val !== undefined ? val : properties[name];
  12143. }
  12144. return values;
  12145. }
  12146. }
  12147. exports.ViewHistory = ViewHistory;
  12148. /***/
  12149. }),
  12150. /* 41 */
  12151. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12152. Object.defineProperty(exports, "__esModule", ({
  12153. value: true
  12154. }));
  12155. exports.BasePreferences = void 0;
  12156. var _app_options = __webpack_require__(5);
  12157. class BasePreferences {
  12158. #defaults = Object.freeze({
  12159. "annotationEditorMode": 0,
  12160. "annotationMode": 2,
  12161. "cursorToolOnLoad": 0,
  12162. "defaultZoomDelay": 400,
  12163. "defaultZoomValue": "",
  12164. "disablePageLabels": false,
  12165. "enablePermissions": false,
  12166. "enablePrintAutoRotate": true,
  12167. "enableScripting": true,
  12168. "enableStampEditor": true,
  12169. "externalLinkTarget": 0,
  12170. "historyUpdateUrl": false,
  12171. "ignoreDestinationZoom": false,
  12172. "forcePageColors": false,
  12173. "pageColorsBackground": "Canvas",
  12174. "pageColorsForeground": "CanvasText",
  12175. "pdfBugEnabled": false,
  12176. "sidebarViewOnLoad": -1,
  12177. "scrollModeOnLoad": -1,
  12178. "spreadModeOnLoad": -1,
  12179. "textLayerMode": 1,
  12180. "viewerCssTheme": 0,
  12181. "viewOnLoad": 0,
  12182. "disableAutoFetch": false,
  12183. "disableFontFace": false,
  12184. "disableRange": false,
  12185. "disableStream": false,
  12186. "enableXfa": true
  12187. });
  12188. #prefs = Object.create(null);
  12189. #initializedPromise = null;
  12190. constructor() {
  12191. if (this.constructor === BasePreferences) {
  12192. throw new Error("Cannot initialize BasePreferences.");
  12193. }
  12194. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  12195. for (const name in this.#defaults) {
  12196. const prefValue = prefs?.[name];
  12197. if (typeof prefValue === typeof this.#defaults[name]) {
  12198. this.#prefs[name] = prefValue;
  12199. }
  12200. }
  12201. });
  12202. }
  12203. async _writeToStorage(prefObj) {
  12204. throw new Error("Not implemented: _writeToStorage");
  12205. }
  12206. async _readFromStorage(prefObj) {
  12207. throw new Error("Not implemented: _readFromStorage");
  12208. }
  12209. async reset() {
  12210. await this.#initializedPromise;
  12211. const prefs = this.#prefs;
  12212. this.#prefs = Object.create(null);
  12213. return this._writeToStorage(this.#defaults).catch(reason => {
  12214. this.#prefs = prefs;
  12215. throw reason;
  12216. });
  12217. }
  12218. async set(name, value) {
  12219. await this.#initializedPromise;
  12220. const defaultValue = this.#defaults[name],
  12221. prefs = this.#prefs;
  12222. if (defaultValue === undefined) {
  12223. throw new Error(`Set preference: "${name}" is undefined.`);
  12224. } else if (value === undefined) {
  12225. throw new Error("Set preference: no value is specified.");
  12226. }
  12227. const valueType = typeof value,
  12228. defaultType = typeof defaultValue;
  12229. if (valueType !== defaultType) {
  12230. if (valueType === "number" && defaultType === "string") {
  12231. value = value.toString();
  12232. } else {
  12233. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  12234. }
  12235. } else if (valueType === "number" && !Number.isInteger(value)) {
  12236. throw new Error(`Set preference: "${value}" must be an integer.`);
  12237. }
  12238. this.#prefs[name] = value;
  12239. return this._writeToStorage(this.#prefs).catch(reason => {
  12240. this.#prefs = prefs;
  12241. throw reason;
  12242. });
  12243. }
  12244. async get(name) {
  12245. await this.#initializedPromise;
  12246. const defaultValue = this.#defaults[name];
  12247. if (defaultValue === undefined) {
  12248. throw new Error(`Get preference: "${name}" is undefined.`);
  12249. }
  12250. return this.#prefs[name] ?? defaultValue;
  12251. }
  12252. async getAll() {
  12253. await this.#initializedPromise;
  12254. const obj = Object.create(null);
  12255. for (const name in this.#defaults) {
  12256. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  12257. }
  12258. return obj;
  12259. }
  12260. }
  12261. exports.BasePreferences = BasePreferences;
  12262. /***/
  12263. }),
  12264. /* 42 */
  12265. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12266. Object.defineProperty(exports, "__esModule", ({
  12267. value: true
  12268. }));
  12269. exports.DownloadManager = void 0;
  12270. var _pdfjsLib = __webpack_require__(4);
  12271. ;
  12272. function download(blobUrl, filename) {
  12273. const a = document.createElement("a");
  12274. if (!a.click) {
  12275. throw new Error('DownloadManager: "a.click()" is not supported.');
  12276. }
  12277. a.href = blobUrl;
  12278. a.target = "_parent";
  12279. if ("download" in a) {
  12280. a.download = filename;
  12281. }
  12282. (document.body || document.documentElement).append(a);
  12283. a.click();
  12284. a.remove();
  12285. }
  12286. class DownloadManager {
  12287. #openBlobUrls = new WeakMap();
  12288. downloadUrl(url, filename, _options) {
  12289. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  12290. console.error(`downloadUrl - not a valid URL: ${url}`);
  12291. return;
  12292. }
  12293. download(url + "#pdfjs.action=download", filename);
  12294. }
  12295. downloadData(data, filename, contentType) {
  12296. const blobUrl = URL.createObjectURL(new Blob([data], {
  12297. type: contentType
  12298. }));
  12299. download(blobUrl, filename);
  12300. }
  12301. openOrDownloadData(element, data, filename) {
  12302. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  12303. const contentType = isPdfData ? "application/pdf" : "";
  12304. if (isPdfData) {
  12305. let blobUrl = this.#openBlobUrls.get(element);
  12306. if (!blobUrl) {
  12307. blobUrl = URL.createObjectURL(new Blob([data], {
  12308. type: contentType
  12309. }));
  12310. this.#openBlobUrls.set(element, blobUrl);
  12311. }
  12312. let viewerUrl;
  12313. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  12314. try {
  12315. window.open(viewerUrl);
  12316. return true;
  12317. } catch (ex) {
  12318. console.error(`openOrDownloadData: ${ex}`);
  12319. URL.revokeObjectURL(blobUrl);
  12320. this.#openBlobUrls.delete(element);
  12321. }
  12322. }
  12323. this.downloadData(data, filename, contentType);
  12324. return false;
  12325. }
  12326. download(blob, url, filename, _options) {
  12327. const blobUrl = URL.createObjectURL(blob);
  12328. download(blobUrl, filename);
  12329. }
  12330. }
  12331. exports.DownloadManager = DownloadManager;
  12332. /***/
  12333. }),
  12334. /* 43 */
  12335. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12336. Object.defineProperty(exports, "__esModule", ({
  12337. value: true
  12338. }));
  12339. exports.GenericL10n = void 0;
  12340. __webpack_require__(44);
  12341. var _l10n_utils = __webpack_require__(29);
  12342. const PARTIAL_LANG_CODES = {
  12343. en: "en-US",
  12344. es: "es-ES",
  12345. fy: "fy-NL",
  12346. ga: "ga-IE",
  12347. gu: "gu-IN",
  12348. hi: "hi-IN",
  12349. hy: "hy-AM",
  12350. nb: "nb-NO",
  12351. ne: "ne-NP",
  12352. nn: "nn-NO",
  12353. pa: "pa-IN",
  12354. pt: "pt-PT",
  12355. sv: "sv-SE",
  12356. zh: "zh-CN"
  12357. };
  12358. function fixupLangCode(langCode) {
  12359. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  12360. }
  12361. class GenericL10n {
  12362. constructor(lang) {
  12363. const {
  12364. webL10n
  12365. } = document;
  12366. this._lang = lang;
  12367. this._ready = new Promise((resolve, reject) => {
  12368. webL10n.setLanguage(fixupLangCode(lang), () => {
  12369. resolve(webL10n);
  12370. });
  12371. });
  12372. }
  12373. async getLanguage() {
  12374. const l10n = await this._ready;
  12375. return l10n.getLanguage();
  12376. }
  12377. async getDirection() {
  12378. const l10n = await this._ready;
  12379. return l10n.getDirection();
  12380. }
  12381. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  12382. const l10n = await this._ready;
  12383. return l10n.get(key, args, fallback);
  12384. }
  12385. async translate(element) {
  12386. const l10n = await this._ready;
  12387. return l10n.translate(element);
  12388. }
  12389. }
  12390. exports.GenericL10n = GenericL10n;
  12391. /***/
  12392. }),
  12393. /* 44 */
  12394. /***/ (() => {
  12395. document.webL10n = function (window, document) {
  12396. var gL10nData = {};
  12397. var gTextData = '';
  12398. var gTextProp = 'textContent';
  12399. var gLanguage = '';
  12400. var gMacros = {};
  12401. var gReadyState = 'loading';
  12402. var gAsyncResourceLoading = true;
  12403. function getL10nResourceLinks() {
  12404. return document.querySelectorAll('link[type="application/l10n"]');
  12405. }
  12406. function getL10nDictionary() {
  12407. var script = document.querySelector('script[type="application/l10n"]');
  12408. return script ? JSON.parse(script.innerHTML) : null;
  12409. }
  12410. function getTranslatableChildren(element) {
  12411. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  12412. }
  12413. function getL10nAttributes(element) {
  12414. if (!element) return {};
  12415. var l10nId = element.getAttribute('data-l10n-id');
  12416. var l10nArgs = element.getAttribute('data-l10n-args');
  12417. var args = {};
  12418. if (l10nArgs) {
  12419. try {
  12420. args = JSON.parse(l10nArgs);
  12421. } catch (e) {
  12422. console.warn('could not parse arguments for #' + l10nId);
  12423. }
  12424. }
  12425. return {
  12426. id: l10nId,
  12427. args: args
  12428. };
  12429. }
  12430. function xhrLoadText(url, onSuccess, onFailure) {
  12431. onSuccess = onSuccess || function _onSuccess(data) { };
  12432. onFailure = onFailure || function _onFailure() { };
  12433. var xhr = new XMLHttpRequest();
  12434. xhr.open('GET', url, gAsyncResourceLoading);
  12435. if (xhr.overrideMimeType) {
  12436. xhr.overrideMimeType('text/plain; charset=utf-8');
  12437. }
  12438. xhr.onreadystatechange = function () {
  12439. if (xhr.readyState == 4) {
  12440. if (xhr.status == 200 || xhr.status === 0) {
  12441. onSuccess(xhr.responseText);
  12442. } else {
  12443. onFailure();
  12444. }
  12445. }
  12446. };
  12447. xhr.onerror = onFailure;
  12448. xhr.ontimeout = onFailure;
  12449. try {
  12450. xhr.send(null);
  12451. } catch (e) {
  12452. onFailure();
  12453. }
  12454. }
  12455. function parseResource(href, lang, successCallback, failureCallback) {
  12456. var baseURL = href.replace(/[^\/]*$/, '') || './';
  12457. function evalString(text) {
  12458. if (text.lastIndexOf('\\') < 0) return text;
  12459. 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, "'");
  12460. }
  12461. function parseProperties(text, parsedPropertiesCallback) {
  12462. var dictionary = {};
  12463. var reBlank = /^\s*|\s*$/;
  12464. var reComment = /^\s*#|^\s*$/;
  12465. var reSection = /^\s*\[(.*)\]\s*$/;
  12466. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  12467. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  12468. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  12469. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  12470. var currentLang = '*';
  12471. var genericLang = lang.split('-', 1)[0];
  12472. var skipLang = false;
  12473. var match = '';
  12474. function nextEntry() {
  12475. while (true) {
  12476. if (!entries.length) {
  12477. parsedRawLinesCallback();
  12478. return;
  12479. }
  12480. var line = entries.shift();
  12481. if (reComment.test(line)) continue;
  12482. if (extendedSyntax) {
  12483. match = reSection.exec(line);
  12484. if (match) {
  12485. currentLang = match[1].toLowerCase();
  12486. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  12487. continue;
  12488. } else if (skipLang) {
  12489. continue;
  12490. }
  12491. match = reImport.exec(line);
  12492. if (match) {
  12493. loadImport(baseURL + match[1], nextEntry);
  12494. return;
  12495. }
  12496. }
  12497. var tmp = line.match(reSplit);
  12498. if (tmp && tmp.length == 3) {
  12499. dictionary[tmp[1]] = evalString(tmp[2]);
  12500. }
  12501. }
  12502. }
  12503. nextEntry();
  12504. }
  12505. function loadImport(url, callback) {
  12506. xhrLoadText(url, function (content) {
  12507. parseRawLines(content, false, callback);
  12508. }, function () {
  12509. console.warn(url + ' not found.');
  12510. callback();
  12511. });
  12512. }
  12513. parseRawLines(text, true, function () {
  12514. parsedPropertiesCallback(dictionary);
  12515. });
  12516. }
  12517. xhrLoadText(href, function (response) {
  12518. gTextData += response;
  12519. parseProperties(response, function (data) {
  12520. for (var key in data) {
  12521. var id,
  12522. prop,
  12523. index = key.lastIndexOf('.');
  12524. if (index > 0) {
  12525. id = key.substring(0, index);
  12526. prop = key.substring(index + 1);
  12527. } else {
  12528. id = key;
  12529. prop = gTextProp;
  12530. }
  12531. if (!gL10nData[id]) {
  12532. gL10nData[id] = {};
  12533. }
  12534. gL10nData[id][prop] = data[key];
  12535. }
  12536. if (successCallback) {
  12537. successCallback();
  12538. }
  12539. });
  12540. }, failureCallback);
  12541. }
  12542. function loadLocale(lang, callback) {
  12543. if (lang) {
  12544. lang = lang.toLowerCase();
  12545. }
  12546. callback = callback || function _callback() { };
  12547. clear();
  12548. gLanguage = lang;
  12549. var langLinks = getL10nResourceLinks();
  12550. var langCount = langLinks.length;
  12551. if (langCount === 0) {
  12552. var dict = getL10nDictionary();
  12553. if (dict && dict.locales && dict.default_locale) {
  12554. console.log('using the embedded JSON directory, early way out');
  12555. gL10nData = dict.locales[lang];
  12556. if (!gL10nData) {
  12557. var defaultLocale = dict.default_locale.toLowerCase();
  12558. for (var anyCaseLang in dict.locales) {
  12559. anyCaseLang = anyCaseLang.toLowerCase();
  12560. if (anyCaseLang === lang) {
  12561. gL10nData = dict.locales[lang];
  12562. break;
  12563. } else if (anyCaseLang === defaultLocale) {
  12564. gL10nData = dict.locales[defaultLocale];
  12565. }
  12566. }
  12567. }
  12568. callback();
  12569. } else {
  12570. console.log('no resource to load, early way out');
  12571. }
  12572. gReadyState = 'complete';
  12573. return;
  12574. }
  12575. var onResourceLoaded = null;
  12576. var gResourceCount = 0;
  12577. onResourceLoaded = function () {
  12578. gResourceCount++;
  12579. if (gResourceCount >= langCount) {
  12580. callback();
  12581. gReadyState = 'complete';
  12582. }
  12583. };
  12584. function L10nResourceLink(link) {
  12585. var href = link.href;
  12586. this.load = function (lang, callback) {
  12587. parseResource(href, lang, callback, function () {
  12588. console.warn(href + ' not found.');
  12589. console.warn('"' + lang + '" resource not found');
  12590. gLanguage = '';
  12591. callback();
  12592. });
  12593. };
  12594. }
  12595. for (var i = 0; i < langCount; i++) {
  12596. var resource = new L10nResourceLink(langLinks[i]);
  12597. resource.load(lang, onResourceLoaded);
  12598. }
  12599. }
  12600. function clear() {
  12601. gL10nData = {};
  12602. gTextData = '';
  12603. gLanguage = '';
  12604. }
  12605. function getPluralRules(lang) {
  12606. var locales2rules = {
  12607. 'af': 3,
  12608. 'ak': 4,
  12609. 'am': 4,
  12610. 'ar': 1,
  12611. 'asa': 3,
  12612. 'az': 0,
  12613. 'be': 11,
  12614. 'bem': 3,
  12615. 'bez': 3,
  12616. 'bg': 3,
  12617. 'bh': 4,
  12618. 'bm': 0,
  12619. 'bn': 3,
  12620. 'bo': 0,
  12621. 'br': 20,
  12622. 'brx': 3,
  12623. 'bs': 11,
  12624. 'ca': 3,
  12625. 'cgg': 3,
  12626. 'chr': 3,
  12627. 'cs': 12,
  12628. 'cy': 17,
  12629. 'da': 3,
  12630. 'de': 3,
  12631. 'dv': 3,
  12632. 'dz': 0,
  12633. 'ee': 3,
  12634. 'el': 3,
  12635. 'en': 3,
  12636. 'eo': 3,
  12637. 'es': 3,
  12638. 'et': 3,
  12639. 'eu': 3,
  12640. 'fa': 0,
  12641. 'ff': 5,
  12642. 'fi': 3,
  12643. 'fil': 4,
  12644. 'fo': 3,
  12645. 'fr': 5,
  12646. 'fur': 3,
  12647. 'fy': 3,
  12648. 'ga': 8,
  12649. 'gd': 24,
  12650. 'gl': 3,
  12651. 'gsw': 3,
  12652. 'gu': 3,
  12653. 'guw': 4,
  12654. 'gv': 23,
  12655. 'ha': 3,
  12656. 'haw': 3,
  12657. 'he': 2,
  12658. 'hi': 4,
  12659. 'hr': 11,
  12660. 'hu': 0,
  12661. 'id': 0,
  12662. 'ig': 0,
  12663. 'ii': 0,
  12664. 'is': 3,
  12665. 'it': 3,
  12666. 'iu': 7,
  12667. 'ja': 0,
  12668. 'jmc': 3,
  12669. 'jv': 0,
  12670. 'ka': 0,
  12671. 'kab': 5,
  12672. 'kaj': 3,
  12673. 'kcg': 3,
  12674. 'kde': 0,
  12675. 'kea': 0,
  12676. 'kk': 3,
  12677. 'kl': 3,
  12678. 'km': 0,
  12679. 'kn': 0,
  12680. 'ko': 0,
  12681. 'ksb': 3,
  12682. 'ksh': 21,
  12683. 'ku': 3,
  12684. 'kw': 7,
  12685. 'lag': 18,
  12686. 'lb': 3,
  12687. 'lg': 3,
  12688. 'ln': 4,
  12689. 'lo': 0,
  12690. 'lt': 10,
  12691. 'lv': 6,
  12692. 'mas': 3,
  12693. 'mg': 4,
  12694. 'mk': 16,
  12695. 'ml': 3,
  12696. 'mn': 3,
  12697. 'mo': 9,
  12698. 'mr': 3,
  12699. 'ms': 0,
  12700. 'mt': 15,
  12701. 'my': 0,
  12702. 'nah': 3,
  12703. 'naq': 7,
  12704. 'nb': 3,
  12705. 'nd': 3,
  12706. 'ne': 3,
  12707. 'nl': 3,
  12708. 'nn': 3,
  12709. 'no': 3,
  12710. 'nr': 3,
  12711. 'nso': 4,
  12712. 'ny': 3,
  12713. 'nyn': 3,
  12714. 'om': 3,
  12715. 'or': 3,
  12716. 'pa': 3,
  12717. 'pap': 3,
  12718. 'pl': 13,
  12719. 'ps': 3,
  12720. 'pt': 3,
  12721. 'rm': 3,
  12722. 'ro': 9,
  12723. 'rof': 3,
  12724. 'ru': 11,
  12725. 'rwk': 3,
  12726. 'sah': 0,
  12727. 'saq': 3,
  12728. 'se': 7,
  12729. 'seh': 3,
  12730. 'ses': 0,
  12731. 'sg': 0,
  12732. 'sh': 11,
  12733. 'shi': 19,
  12734. 'sk': 12,
  12735. 'sl': 14,
  12736. 'sma': 7,
  12737. 'smi': 7,
  12738. 'smj': 7,
  12739. 'smn': 7,
  12740. 'sms': 7,
  12741. 'sn': 3,
  12742. 'so': 3,
  12743. 'sq': 3,
  12744. 'sr': 11,
  12745. 'ss': 3,
  12746. 'ssy': 3,
  12747. 'st': 3,
  12748. 'sv': 3,
  12749. 'sw': 3,
  12750. 'syr': 3,
  12751. 'ta': 3,
  12752. 'te': 3,
  12753. 'teo': 3,
  12754. 'th': 0,
  12755. 'ti': 4,
  12756. 'tig': 3,
  12757. 'tk': 3,
  12758. 'tl': 4,
  12759. 'tn': 3,
  12760. 'to': 0,
  12761. 'tr': 0,
  12762. 'ts': 3,
  12763. 'tzm': 22,
  12764. 'uk': 11,
  12765. 'ur': 3,
  12766. 've': 3,
  12767. 'vi': 0,
  12768. 'vun': 3,
  12769. 'wa': 4,
  12770. 'wae': 3,
  12771. 'wo': 0,
  12772. 'xh': 3,
  12773. 'xog': 3,
  12774. 'yo': 0,
  12775. 'zh': 0,
  12776. 'zu': 3
  12777. };
  12778. function isIn(n, list) {
  12779. return list.indexOf(n) !== -1;
  12780. }
  12781. function isBetween(n, start, end) {
  12782. return start <= n && n <= end;
  12783. }
  12784. var pluralRules = {
  12785. '0': function (n) {
  12786. return 'other';
  12787. },
  12788. '1': function (n) {
  12789. if (isBetween(n % 100, 3, 10)) return 'few';
  12790. if (n === 0) return 'zero';
  12791. if (isBetween(n % 100, 11, 99)) return 'many';
  12792. if (n == 2) return 'two';
  12793. if (n == 1) return 'one';
  12794. return 'other';
  12795. },
  12796. '2': function (n) {
  12797. if (n !== 0 && n % 10 === 0) return 'many';
  12798. if (n == 2) return 'two';
  12799. if (n == 1) return 'one';
  12800. return 'other';
  12801. },
  12802. '3': function (n) {
  12803. if (n == 1) return 'one';
  12804. return 'other';
  12805. },
  12806. '4': function (n) {
  12807. if (isBetween(n, 0, 1)) return 'one';
  12808. return 'other';
  12809. },
  12810. '5': function (n) {
  12811. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12812. return 'other';
  12813. },
  12814. '6': function (n) {
  12815. if (n === 0) return 'zero';
  12816. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12817. return 'other';
  12818. },
  12819. '7': function (n) {
  12820. if (n == 2) return 'two';
  12821. if (n == 1) return 'one';
  12822. return 'other';
  12823. },
  12824. '8': function (n) {
  12825. if (isBetween(n, 3, 6)) return 'few';
  12826. if (isBetween(n, 7, 10)) return 'many';
  12827. if (n == 2) return 'two';
  12828. if (n == 1) return 'one';
  12829. return 'other';
  12830. },
  12831. '9': function (n) {
  12832. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12833. if (n == 1) return 'one';
  12834. return 'other';
  12835. },
  12836. '10': function (n) {
  12837. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12838. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12839. return 'other';
  12840. },
  12841. '11': function (n) {
  12842. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12843. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12844. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12845. return 'other';
  12846. },
  12847. '12': function (n) {
  12848. if (isBetween(n, 2, 4)) return 'few';
  12849. if (n == 1) return 'one';
  12850. return 'other';
  12851. },
  12852. '13': function (n) {
  12853. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12854. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12855. if (n == 1) return 'one';
  12856. return 'other';
  12857. },
  12858. '14': function (n) {
  12859. if (isBetween(n % 100, 3, 4)) return 'few';
  12860. if (n % 100 == 2) return 'two';
  12861. if (n % 100 == 1) return 'one';
  12862. return 'other';
  12863. },
  12864. '15': function (n) {
  12865. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12866. if (isBetween(n % 100, 11, 19)) return 'many';
  12867. if (n == 1) return 'one';
  12868. return 'other';
  12869. },
  12870. '16': function (n) {
  12871. if (n % 10 == 1 && n != 11) return 'one';
  12872. return 'other';
  12873. },
  12874. '17': function (n) {
  12875. if (n == 3) return 'few';
  12876. if (n === 0) return 'zero';
  12877. if (n == 6) return 'many';
  12878. if (n == 2) return 'two';
  12879. if (n == 1) return 'one';
  12880. return 'other';
  12881. },
  12882. '18': function (n) {
  12883. if (n === 0) return 'zero';
  12884. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12885. return 'other';
  12886. },
  12887. '19': function (n) {
  12888. if (isBetween(n, 2, 10)) return 'few';
  12889. if (isBetween(n, 0, 1)) return 'one';
  12890. return 'other';
  12891. },
  12892. '20': function (n) {
  12893. 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';
  12894. if (n % 1000000 === 0 && n !== 0) return 'many';
  12895. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12896. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12897. return 'other';
  12898. },
  12899. '21': function (n) {
  12900. if (n === 0) return 'zero';
  12901. if (n == 1) return 'one';
  12902. return 'other';
  12903. },
  12904. '22': function (n) {
  12905. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  12906. return 'other';
  12907. },
  12908. '23': function (n) {
  12909. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  12910. return 'other';
  12911. },
  12912. '24': function (n) {
  12913. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  12914. if (isIn(n, [2, 12])) return 'two';
  12915. if (isIn(n, [1, 11])) return 'one';
  12916. return 'other';
  12917. }
  12918. };
  12919. var index = locales2rules[lang.replace(/-.*$/, '')];
  12920. if (!(index in pluralRules)) {
  12921. console.warn('plural form unknown for [' + lang + ']');
  12922. return function () {
  12923. return 'other';
  12924. };
  12925. }
  12926. return pluralRules[index];
  12927. }
  12928. gMacros.plural = function (str, param, key, prop) {
  12929. var n = parseFloat(param);
  12930. if (isNaN(n)) return str;
  12931. if (prop != gTextProp) return str;
  12932. if (!gMacros._pluralRules) {
  12933. gMacros._pluralRules = getPluralRules(gLanguage);
  12934. }
  12935. var index = '[' + gMacros._pluralRules(n) + ']';
  12936. if (n === 0 && key + '[zero]' in gL10nData) {
  12937. str = gL10nData[key + '[zero]'][prop];
  12938. } else if (n == 1 && key + '[one]' in gL10nData) {
  12939. str = gL10nData[key + '[one]'][prop];
  12940. } else if (n == 2 && key + '[two]' in gL10nData) {
  12941. str = gL10nData[key + '[two]'][prop];
  12942. } else if (key + index in gL10nData) {
  12943. str = gL10nData[key + index][prop];
  12944. } else if (key + '[other]' in gL10nData) {
  12945. str = gL10nData[key + '[other]'][prop];
  12946. }
  12947. return str;
  12948. };
  12949. function getL10nData(key, args, fallback) {
  12950. var data = gL10nData[key];
  12951. if (!data) {
  12952. console.warn('#' + key + ' is undefined.');
  12953. if (!fallback) {
  12954. return null;
  12955. }
  12956. data = fallback;
  12957. }
  12958. var rv = {};
  12959. for (var prop in data) {
  12960. var str = data[prop];
  12961. str = substIndexes(str, args, key, prop);
  12962. str = substArguments(str, args, key);
  12963. rv[prop] = str;
  12964. }
  12965. return rv;
  12966. }
  12967. function substIndexes(str, args, key, prop) {
  12968. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  12969. var reMatch = reIndex.exec(str);
  12970. if (!reMatch || !reMatch.length) return str;
  12971. var macroName = reMatch[1];
  12972. var paramName = reMatch[2];
  12973. var param;
  12974. if (args && paramName in args) {
  12975. param = args[paramName];
  12976. } else if (paramName in gL10nData) {
  12977. param = gL10nData[paramName];
  12978. }
  12979. if (macroName in gMacros) {
  12980. var macro = gMacros[macroName];
  12981. str = macro(str, param, key, prop);
  12982. }
  12983. return str;
  12984. }
  12985. function substArguments(str, args, key) {
  12986. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  12987. return str.replace(reArgs, function (matched_text, arg) {
  12988. if (args && arg in args) {
  12989. return args[arg];
  12990. }
  12991. if (arg in gL10nData) {
  12992. return gL10nData[arg];
  12993. }
  12994. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  12995. return matched_text;
  12996. });
  12997. }
  12998. function translateElement(element) {
  12999. var l10n = getL10nAttributes(element);
  13000. if (!l10n.id) return;
  13001. var data = getL10nData(l10n.id, l10n.args);
  13002. if (!data) {
  13003. console.warn('#' + l10n.id + ' is undefined.');
  13004. return;
  13005. }
  13006. if (data[gTextProp]) {
  13007. if (getChildElementCount(element) === 0) {
  13008. element[gTextProp] = data[gTextProp];
  13009. } else {
  13010. var children = element.childNodes;
  13011. var found = false;
  13012. for (var i = 0, l = children.length; i < l; i++) {
  13013. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  13014. if (found) {
  13015. children[i].nodeValue = '';
  13016. } else {
  13017. children[i].nodeValue = data[gTextProp];
  13018. found = true;
  13019. }
  13020. }
  13021. }
  13022. if (!found) {
  13023. var textNode = document.createTextNode(data[gTextProp]);
  13024. element.prepend(textNode);
  13025. }
  13026. }
  13027. delete data[gTextProp];
  13028. }
  13029. for (var k in data) {
  13030. element[k] = data[k];
  13031. }
  13032. }
  13033. function getChildElementCount(element) {
  13034. if (element.children) {
  13035. return element.children.length;
  13036. }
  13037. if (typeof element.childElementCount !== 'undefined') {
  13038. return element.childElementCount;
  13039. }
  13040. var count = 0;
  13041. for (var i = 0; i < element.childNodes.length; i++) {
  13042. count += element.nodeType === 1 ? 1 : 0;
  13043. }
  13044. return count;
  13045. }
  13046. function translateFragment(element) {
  13047. element = element || document.documentElement;
  13048. var children = getTranslatableChildren(element);
  13049. var elementCount = children.length;
  13050. for (var i = 0; i < elementCount; i++) {
  13051. translateElement(children[i]);
  13052. }
  13053. translateElement(element);
  13054. }
  13055. return {
  13056. get: function (key, args, fallbackString) {
  13057. var index = key.lastIndexOf('.');
  13058. var prop = gTextProp;
  13059. if (index > 0) {
  13060. prop = key.substring(index + 1);
  13061. key = key.substring(0, index);
  13062. }
  13063. var fallback;
  13064. if (fallbackString) {
  13065. fallback = {};
  13066. fallback[prop] = fallbackString;
  13067. }
  13068. var data = getL10nData(key, args, fallback);
  13069. if (data && prop in data) {
  13070. return data[prop];
  13071. }
  13072. return '{{' + key + '}}';
  13073. },
  13074. getData: function () {
  13075. return gL10nData;
  13076. },
  13077. getText: function () {
  13078. return gTextData;
  13079. },
  13080. getLanguage: function () {
  13081. return gLanguage;
  13082. },
  13083. setLanguage: function (lang, callback) {
  13084. loadLocale(lang, function () {
  13085. if (callback) callback();
  13086. });
  13087. },
  13088. getDirection: function () {
  13089. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  13090. var shortCode = gLanguage.split('-', 1)[0];
  13091. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  13092. },
  13093. translate: translateFragment,
  13094. getReadyState: function () {
  13095. return gReadyState;
  13096. },
  13097. ready: function (callback) {
  13098. if (!callback) {
  13099. return;
  13100. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  13101. window.setTimeout(function () {
  13102. callback();
  13103. });
  13104. } else if (document.addEventListener) {
  13105. document.addEventListener('localized', function once() {
  13106. document.removeEventListener('localized', once);
  13107. callback();
  13108. });
  13109. }
  13110. }
  13111. };
  13112. }(window, document);
  13113. /***/
  13114. }),
  13115. /* 45 */
  13116. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13117. Object.defineProperty(exports, "__esModule", ({
  13118. value: true
  13119. }));
  13120. exports.GenericScripting = void 0;
  13121. exports.docProperties = docProperties;
  13122. var _pdfjsLib = __webpack_require__(4);
  13123. async function docProperties(pdfDocument) {
  13124. const url = "",
  13125. baseUrl = url.split("#")[0];
  13126. let {
  13127. info,
  13128. metadata,
  13129. contentDispositionFilename,
  13130. contentLength
  13131. } = await pdfDocument.getMetadata();
  13132. if (!contentLength) {
  13133. const {
  13134. length
  13135. } = await pdfDocument.getDownloadInfo();
  13136. contentLength = length;
  13137. }
  13138. return {
  13139. ...info,
  13140. baseURL: baseUrl,
  13141. filesize: contentLength,
  13142. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  13143. metadata: metadata?.getRaw(),
  13144. authors: metadata?.get("dc:creator"),
  13145. numPages: pdfDocument.numPages,
  13146. URL: url
  13147. };
  13148. }
  13149. class GenericScripting {
  13150. constructor(sandboxBundleSrc) {
  13151. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  13152. return window.pdfjsSandbox.QuickJSSandbox();
  13153. });
  13154. }
  13155. async createSandbox(data) {
  13156. const sandbox = await this._ready;
  13157. sandbox.create(data);
  13158. }
  13159. async dispatchEventInSandbox(event) {
  13160. const sandbox = await this._ready;
  13161. setTimeout(() => sandbox.dispatchEvent(event), 0);
  13162. }
  13163. async destroySandbox() {
  13164. const sandbox = await this._ready;
  13165. sandbox.nukeSandbox();
  13166. }
  13167. }
  13168. exports.GenericScripting = GenericScripting;
  13169. /***/
  13170. }),
  13171. /* 46 */
  13172. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13173. Object.defineProperty(exports, "__esModule", ({
  13174. value: true
  13175. }));
  13176. exports.PDFPrintService = void 0;
  13177. var _pdfjsLib = __webpack_require__(4);
  13178. var _app = __webpack_require__(2);
  13179. var _print_utils = __webpack_require__(47);
  13180. let activeService = null;
  13181. let dialog = null;
  13182. let overlayManager = null;
  13183. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  13184. const scratchCanvas = activeService.scratchCanvas;
  13185. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  13186. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  13187. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  13188. const ctx = scratchCanvas.getContext("2d");
  13189. ctx.save();
  13190. ctx.fillStyle = "rgb(255, 255, 255)";
  13191. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  13192. ctx.restore();
  13193. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  13194. const renderContext = {
  13195. canvasContext: ctx,
  13196. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  13197. viewport: pdfPage.getViewport({
  13198. scale: 1,
  13199. rotation: size.rotation
  13200. }),
  13201. intent: "print",
  13202. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  13203. optionalContentConfigPromise,
  13204. printAnnotationStorage
  13205. };
  13206. return pdfPage.render(renderContext).promise;
  13207. });
  13208. }
  13209. class PDFPrintService {
  13210. constructor(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) {
  13211. this.pdfDocument = pdfDocument;
  13212. this.pagesOverview = pagesOverview;
  13213. this.printContainer = printContainer;
  13214. this._printResolution = printResolution || 150;
  13215. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  13216. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  13217. this.l10n = l10n;
  13218. this.currentPage = -1;
  13219. this.scratchCanvas = document.createElement("canvas");
  13220. }
  13221. layout() {
  13222. this.throwIfInactive();
  13223. const body = document.querySelector("body");
  13224. body.setAttribute("data-pdfjsprinting", true);
  13225. const {
  13226. width,
  13227. height
  13228. } = this.pagesOverview[0];
  13229. const hasEqualPageSizes = this.pagesOverview.every(size => size.width === width && size.height === height);
  13230. if (!hasEqualPageSizes) {
  13231. console.warn("Not all pages have the same size. The printed result may be incorrect!");
  13232. }
  13233. this.pageStyleSheet = document.createElement("style");
  13234. this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`;
  13235. body.append(this.pageStyleSheet);
  13236. }
  13237. destroy() {
  13238. if (activeService !== this) {
  13239. return;
  13240. }
  13241. this.printContainer.textContent = "";
  13242. const body = document.querySelector("body");
  13243. body.removeAttribute("data-pdfjsprinting");
  13244. if (this.pageStyleSheet) {
  13245. this.pageStyleSheet.remove();
  13246. this.pageStyleSheet = null;
  13247. }
  13248. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  13249. this.scratchCanvas = null;
  13250. activeService = null;
  13251. ensureOverlay().then(function () {
  13252. if (overlayManager.active === dialog) {
  13253. overlayManager.close(dialog);
  13254. }
  13255. });
  13256. }
  13257. renderPages() {
  13258. if (this.pdfDocument.isPureXfa) {
  13259. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  13260. return Promise.resolve();
  13261. }
  13262. const pageCount = this.pagesOverview.length;
  13263. const renderNextPage = (resolve, reject) => {
  13264. this.throwIfInactive();
  13265. if (++this.currentPage >= pageCount) {
  13266. renderProgress(pageCount, pageCount, this.l10n);
  13267. resolve();
  13268. return;
  13269. }
  13270. const index = this.currentPage;
  13271. renderProgress(index, pageCount, this.l10n);
  13272. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  13273. renderNextPage(resolve, reject);
  13274. }, reject);
  13275. };
  13276. return new Promise(renderNextPage);
  13277. }
  13278. useRenderedPage() {
  13279. this.throwIfInactive();
  13280. const img = document.createElement("img");
  13281. const scratchCanvas = this.scratchCanvas;
  13282. if ("toBlob" in scratchCanvas) {
  13283. scratchCanvas.toBlob(function (blob) {
  13284. img.src = URL.createObjectURL(blob);
  13285. });
  13286. } else {
  13287. img.src = scratchCanvas.toDataURL();
  13288. }
  13289. const wrapper = document.createElement("div");
  13290. wrapper.className = "printedPage";
  13291. wrapper.append(img);
  13292. this.printContainer.append(wrapper);
  13293. return new Promise(function (resolve, reject) {
  13294. img.onload = resolve;
  13295. img.onerror = reject;
  13296. });
  13297. }
  13298. performPrint() {
  13299. this.throwIfInactive();
  13300. return new Promise(resolve => {
  13301. setTimeout(() => {
  13302. if (!this.active) {
  13303. resolve();
  13304. return;
  13305. }
  13306. print.call(window);
  13307. setTimeout(resolve, 20);
  13308. }, 0);
  13309. });
  13310. }
  13311. get active() {
  13312. return this === activeService;
  13313. }
  13314. throwIfInactive() {
  13315. if (!this.active) {
  13316. throw new Error("This print request was cancelled or completed.");
  13317. }
  13318. }
  13319. }
  13320. exports.PDFPrintService = PDFPrintService;
  13321. const print = window.print;
  13322. window.print = function () {
  13323. if (activeService) {
  13324. console.warn("Ignored window.print() because of a pending print job.");
  13325. return;
  13326. }
  13327. ensureOverlay().then(function () {
  13328. if (activeService) {
  13329. overlayManager.open(dialog);
  13330. }
  13331. });
  13332. try {
  13333. dispatchEvent("beforeprint");
  13334. } finally {
  13335. if (!activeService) {
  13336. console.error("Expected print service to be initialized.");
  13337. ensureOverlay().then(function () {
  13338. if (overlayManager.active === dialog) {
  13339. overlayManager.close(dialog);
  13340. }
  13341. });
  13342. return;
  13343. }
  13344. const activeServiceOnEntry = activeService;
  13345. activeService.renderPages().then(function () {
  13346. return activeServiceOnEntry.performPrint();
  13347. }).catch(function () { }).then(function () {
  13348. if (activeServiceOnEntry.active) {
  13349. abort();
  13350. }
  13351. });
  13352. }
  13353. };
  13354. function dispatchEvent(eventType) {
  13355. const event = new CustomEvent(eventType, {
  13356. bubbles: false,
  13357. cancelable: false,
  13358. detail: "custom"
  13359. });
  13360. window.dispatchEvent(event);
  13361. }
  13362. function abort() {
  13363. if (activeService) {
  13364. activeService.destroy();
  13365. dispatchEvent("afterprint");
  13366. }
  13367. }
  13368. function renderProgress(index, total, l10n) {
  13369. dialog ||= document.getElementById("printServiceDialog");
  13370. const progress = Math.round(100 * index / total);
  13371. const progressBar = dialog.querySelector("progress");
  13372. const progressPerc = dialog.querySelector(".relative-progress");
  13373. progressBar.value = progress;
  13374. l10n.get("print_progress_percent", {
  13375. progress
  13376. }).then(msg => {
  13377. progressPerc.textContent = msg;
  13378. });
  13379. }
  13380. window.addEventListener("keydown", function (event) {
  13381. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  13382. window.print();
  13383. event.preventDefault();
  13384. event.stopImmediatePropagation();
  13385. }
  13386. }, true);
  13387. if ("onbeforeprint" in window) {
  13388. const stopPropagationIfNeeded = function (event) {
  13389. if (event.detail !== "custom") {
  13390. event.stopImmediatePropagation();
  13391. }
  13392. };
  13393. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  13394. window.addEventListener("afterprint", stopPropagationIfNeeded);
  13395. }
  13396. let overlayPromise;
  13397. function ensureOverlay() {
  13398. if (!overlayPromise) {
  13399. overlayManager = _app.PDFViewerApplication.overlayManager;
  13400. if (!overlayManager) {
  13401. throw new Error("The overlay manager has not yet been initialized.");
  13402. }
  13403. dialog ||= document.getElementById("printServiceDialog");
  13404. overlayPromise = overlayManager.register(dialog, true);
  13405. document.getElementById("printCancel").onclick = abort;
  13406. dialog.addEventListener("close", abort);
  13407. }
  13408. return overlayPromise;
  13409. }
  13410. _app.PDFPrintServiceFactory.instance = {
  13411. supportsPrinting: true,
  13412. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  13413. if (activeService) {
  13414. throw new Error("The print service is created and active.");
  13415. }
  13416. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  13417. return activeService;
  13418. }
  13419. };
  13420. /***/
  13421. }),
  13422. /* 47 */
  13423. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13424. Object.defineProperty(exports, "__esModule", ({
  13425. value: true
  13426. }));
  13427. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  13428. var _pdfjsLib = __webpack_require__(4);
  13429. var _pdf_link_service = __webpack_require__(7);
  13430. var _xfa_layer_builder = __webpack_require__(37);
  13431. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  13432. const xfaHtml = pdfDocument.allXfaHtml;
  13433. const linkService = new _pdf_link_service.SimpleLinkService();
  13434. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  13435. for (const xfaPage of xfaHtml.children) {
  13436. const page = document.createElement("div");
  13437. page.className = "xfaPrintedPage";
  13438. printContainer.append(page);
  13439. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  13440. pageDiv: page,
  13441. pdfPage: null,
  13442. annotationStorage: pdfDocument.annotationStorage,
  13443. linkService,
  13444. xfaHtml: xfaPage
  13445. });
  13446. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  13447. scale
  13448. });
  13449. builder.render(viewport, "print");
  13450. }
  13451. }
  13452. /***/
  13453. })
  13454. /******/]);
  13455. /************************************************************************/
  13456. /******/ // The module cache
  13457. /******/ var __webpack_module_cache__ = {};
  13458. /******/
  13459. /******/ // The require function
  13460. /******/ function __webpack_require__(moduleId) {
  13461. /******/ // Check if module is in cache
  13462. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  13463. /******/ if (cachedModule !== undefined) {
  13464. /******/ return cachedModule.exports;
  13465. /******/
  13466. }
  13467. /******/ // Create a new module (and put it into the cache)
  13468. /******/ var module = __webpack_module_cache__[moduleId] = {
  13469. /******/ // no module.id needed
  13470. /******/ // no module.loaded needed
  13471. /******/ exports: {}
  13472. /******/
  13473. };
  13474. /******/
  13475. /******/ // Execute the module function
  13476. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  13477. /******/
  13478. /******/ // Return the exports of the module
  13479. /******/ return module.exports;
  13480. /******/
  13481. }
  13482. /******/
  13483. /************************************************************************/
  13484. var __webpack_exports__ = {};
  13485. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  13486. (() => {
  13487. var exports = __webpack_exports__;
  13488. Object.defineProperty(exports, "__esModule", ({
  13489. value: true
  13490. }));
  13491. Object.defineProperty(exports, "PDFViewerApplication", ({
  13492. enumerable: true,
  13493. get: function () {
  13494. return _app.PDFViewerApplication;
  13495. }
  13496. }));
  13497. exports.PDFViewerApplicationConstants = void 0;
  13498. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  13499. enumerable: true,
  13500. get: function () {
  13501. return _app_options.AppOptions;
  13502. }
  13503. }));
  13504. __webpack_require__(1);
  13505. __webpack_require__(46);
  13506. var _ui_utils = __webpack_require__(3);
  13507. var _app_options = __webpack_require__(5);
  13508. var _pdf_link_service = __webpack_require__(7);
  13509. var _app = __webpack_require__(2);
  13510. const pdfjsVersion = '3.10.111';
  13511. const pdfjsBuild = 'e142baecb';
  13512. const AppConstants = {
  13513. LinkTarget: _pdf_link_service.LinkTarget,
  13514. RenderingStates: _ui_utils.RenderingStates,
  13515. ScrollMode: _ui_utils.ScrollMode,
  13516. SpreadMode: _ui_utils.SpreadMode
  13517. };
  13518. exports.PDFViewerApplicationConstants = AppConstants;
  13519. window.PDFViewerApplication = _app.PDFViewerApplication;
  13520. window.PDFViewerApplicationConstants = AppConstants;
  13521. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  13522. function getViewerConfiguration() {
  13523. return {
  13524. appContainer: document.body,
  13525. mainContainer: document.getElementById("viewerContainer"),
  13526. viewerContainer: document.getElementById("viewer"),
  13527. toolbar: {
  13528. container: document.getElementById("toolbarViewer"),
  13529. numPages: document.getElementById("numPages"),
  13530. pageNumber: document.getElementById("pageNumber"),
  13531. scaleSelect: document.getElementById("scaleSelect"),
  13532. customScaleOption: document.getElementById("customScaleOption"),
  13533. previous: document.getElementById("previous"),
  13534. next: document.getElementById("next"),
  13535. zoomIn: document.getElementById("zoomIn"),
  13536. zoomOut: document.getElementById("zoomOut"),
  13537. viewFind: document.getElementById("viewFind"),
  13538. openFile: document.getElementById("openFile"),
  13539. print: document.getElementById("print"),
  13540. editorFreeTextButton: document.getElementById("editorFreeText"),
  13541. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  13542. editorInkButton: document.getElementById("editorInk"),
  13543. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  13544. editorStampButton: document.getElementById("editorStamp"),
  13545. editorStampParamsToolbar: document.getElementById("editorStampParamsToolbar"),
  13546. download: document.getElementById("download")
  13547. },
  13548. secondaryToolbar: {
  13549. toolbar: document.getElementById("secondaryToolbar"),
  13550. toggleButton: document.getElementById("secondaryToolbarToggle"),
  13551. presentationModeButton: document.getElementById("presentationMode"),
  13552. openFileButton: document.getElementById("secondaryOpenFile"),
  13553. printButton: document.getElementById("secondaryPrint"),
  13554. downloadButton: document.getElementById("secondaryDownload"),
  13555. viewBookmarkButton: document.getElementById("viewBookmark"),
  13556. firstPageButton: document.getElementById("firstPage"),
  13557. lastPageButton: document.getElementById("lastPage"),
  13558. pageRotateCwButton: document.getElementById("pageRotateCw"),
  13559. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  13560. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  13561. cursorHandToolButton: document.getElementById("cursorHandTool"),
  13562. scrollPageButton: document.getElementById("scrollPage"),
  13563. scrollVerticalButton: document.getElementById("scrollVertical"),
  13564. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  13565. scrollWrappedButton: document.getElementById("scrollWrapped"),
  13566. spreadNoneButton: document.getElementById("spreadNone"),
  13567. spreadOddButton: document.getElementById("spreadOdd"),
  13568. spreadEvenButton: document.getElementById("spreadEven"),
  13569. documentPropertiesButton: document.getElementById("documentProperties")
  13570. },
  13571. sidebar: {
  13572. outerContainer: document.getElementById("outerContainer"),
  13573. sidebarContainer: document.getElementById("sidebarContainer"),
  13574. toggleButton: document.getElementById("sidebarToggle"),
  13575. resizer: document.getElementById("sidebarResizer"),
  13576. thumbnailButton: document.getElementById("viewThumbnail"),
  13577. outlineButton: document.getElementById("viewOutline"),
  13578. attachmentsButton: document.getElementById("viewAttachments"),
  13579. layersButton: document.getElementById("viewLayers"),
  13580. thumbnailView: document.getElementById("thumbnailView"),
  13581. outlineView: document.getElementById("outlineView"),
  13582. attachmentsView: document.getElementById("attachmentsView"),
  13583. layersView: document.getElementById("layersView"),
  13584. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  13585. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  13586. },
  13587. findBar: {
  13588. bar: document.getElementById("findbar"),
  13589. toggleButton: document.getElementById("viewFind"),
  13590. findField: document.getElementById("findInput"),
  13591. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  13592. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  13593. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  13594. entireWordCheckbox: document.getElementById("findEntireWord"),
  13595. findMsg: document.getElementById("findMsg"),
  13596. findResultsCount: document.getElementById("findResultsCount"),
  13597. findPreviousButton: document.getElementById("findPrevious"),
  13598. findNextButton: document.getElementById("findNext")
  13599. },
  13600. passwordOverlay: {
  13601. dialog: document.getElementById("passwordDialog"),
  13602. label: document.getElementById("passwordText"),
  13603. input: document.getElementById("password"),
  13604. submitButton: document.getElementById("passwordSubmit"),
  13605. cancelButton: document.getElementById("passwordCancel")
  13606. },
  13607. documentProperties: {
  13608. dialog: document.getElementById("documentPropertiesDialog"),
  13609. closeButton: document.getElementById("documentPropertiesClose"),
  13610. fields: {
  13611. fileName: document.getElementById("fileNameField"),
  13612. fileSize: document.getElementById("fileSizeField"),
  13613. title: document.getElementById("titleField"),
  13614. author: document.getElementById("authorField"),
  13615. subject: document.getElementById("subjectField"),
  13616. keywords: document.getElementById("keywordsField"),
  13617. creationDate: document.getElementById("creationDateField"),
  13618. modificationDate: document.getElementById("modificationDateField"),
  13619. creator: document.getElementById("creatorField"),
  13620. producer: document.getElementById("producerField"),
  13621. version: document.getElementById("versionField"),
  13622. pageCount: document.getElementById("pageCountField"),
  13623. pageSize: document.getElementById("pageSizeField"),
  13624. linearized: document.getElementById("linearizedField")
  13625. }
  13626. },
  13627. annotationEditorParams: {
  13628. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  13629. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  13630. editorInkColor: document.getElementById("editorInkColor"),
  13631. editorInkThickness: document.getElementById("editorInkThickness"),
  13632. editorInkOpacity: document.getElementById("editorInkOpacity"),
  13633. editorStampAddImage: document.getElementById("editorStampAddImage")
  13634. },
  13635. printContainer: document.getElementById("printContainer"),
  13636. openFileInput: document.getElementById("fileInput"),
  13637. debuggerScriptPath: "./debugger.js"
  13638. };
  13639. }
  13640. function webViewerLoad() {
  13641. const config = getViewerConfiguration();
  13642. const event = new CustomEvent("webviewerloaded", {
  13643. bubbles: true,
  13644. cancelable: true,
  13645. detail: {
  13646. source: window
  13647. }
  13648. });
  13649. try {
  13650. parent.document.dispatchEvent(event);
  13651. } catch (ex) {
  13652. console.error(`webviewerloaded: ${ex}`);
  13653. document.dispatchEvent(event);
  13654. }
  13655. _app.PDFViewerApplication.run(config);
  13656. }
  13657. document.blockUnblockOnload?.(true);
  13658. if (document.readyState === "interactive" || document.readyState === "complete") {
  13659. webViewerLoad();
  13660. } else {
  13661. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  13662. }
  13663. })();
  13664. /******/
  13665. })()
  13666. ;
  13667. //# sourceMappingURL=viewer.js.map