viewer.js 419 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808
  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. /* 2 */
  69. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  70. Object.defineProperty(exports, "__esModule", ({
  71. value: true
  72. }));
  73. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  74. var _ui_utils = __webpack_require__(3);
  75. var _pdfjsLib = __webpack_require__(4);
  76. var _app_options = __webpack_require__(5);
  77. var _event_utils = __webpack_require__(6);
  78. var _pdf_link_service = __webpack_require__(7);
  79. var _webAnnotation_editor_params = __webpack_require__(8);
  80. var _overlay_manager = __webpack_require__(9);
  81. var _password_prompt = __webpack_require__(10);
  82. var _webPdf_attachment_viewer = __webpack_require__(11);
  83. var _webPdf_cursor_tools = __webpack_require__(13);
  84. var _webPdf_document_properties = __webpack_require__(15);
  85. var _webPdf_find_bar = __webpack_require__(16);
  86. var _pdf_find_controller = __webpack_require__(17);
  87. var _pdf_history = __webpack_require__(19);
  88. var _webPdf_layer_viewer = __webpack_require__(20);
  89. var _webPdf_outline_viewer = __webpack_require__(21);
  90. var _webPdf_presentation_mode = __webpack_require__(22);
  91. var _pdf_rendering_queue = __webpack_require__(23);
  92. var _pdf_scripting_manager = __webpack_require__(24);
  93. var _webPdf_sidebar = __webpack_require__(25);
  94. var _webPdf_thumbnail_viewer = __webpack_require__(26);
  95. var _pdf_viewer = __webpack_require__(28);
  96. var _webSecondary_toolbar = __webpack_require__(38);
  97. var _webToolbar = __webpack_require__(39);
  98. var _view_history = __webpack_require__(40);
  99. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  100. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  101. const ViewOnLoad = {
  102. UNKNOWN: -1,
  103. PREVIOUS: 0,
  104. INITIAL: 1
  105. };
  106. const ViewerCssTheme = {
  107. AUTOMATIC: 0,
  108. LIGHT: 1,
  109. DARK: 2
  110. };
  111. class DefaultExternalServices {
  112. constructor() {
  113. throw new Error("Cannot initialize DefaultExternalServices.");
  114. }
  115. static updateFindControlState(data) {}
  116. static updateFindMatchesCount(data) {}
  117. static initPassiveLoading(callbacks) {}
  118. static reportTelemetry(data) {}
  119. static createDownloadManager() {
  120. throw new Error("Not implemented: createDownloadManager");
  121. }
  122. static createPreferences() {
  123. throw new Error("Not implemented: createPreferences");
  124. }
  125. static createL10n(options) {
  126. throw new Error("Not implemented: createL10n");
  127. }
  128. static createScripting(options) {
  129. throw new Error("Not implemented: createScripting");
  130. }
  131. static get supportsPinchToZoom() {
  132. return (0, _pdfjsLib.shadow)(this, "supportsPinchToZoom", true);
  133. }
  134. static get supportsIntegratedFind() {
  135. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  136. }
  137. static get supportsDocumentFonts() {
  138. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  139. }
  140. static get supportedMouseWheelZoomModifierKeys() {
  141. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  142. ctrlKey: true,
  143. metaKey: true
  144. });
  145. }
  146. static get isInAutomation() {
  147. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  148. }
  149. static updateEditorStates(data) {
  150. throw new Error("Not implemented: updateEditorStates");
  151. }
  152. static get canvasMaxAreaInBytes() {
  153. return (0, _pdfjsLib.shadow)(this, "canvasMaxAreaInBytes", -1);
  154. }
  155. static getNimbusExperimentData() {
  156. return (0, _pdfjsLib.shadow)(this, "getNimbusExperimentData", Promise.resolve(null));
  157. }
  158. }
  159. exports.DefaultExternalServices = DefaultExternalServices;
  160. const PDFViewerApplication = {
  161. initialBookmark: document.location.hash.substring(1),
  162. _initializedCapability: new _pdfjsLib.PromiseCapability(),
  163. appConfig: null,
  164. pdfDocument: null,
  165. pdfLoadingTask: null,
  166. printService: null,
  167. pdfViewer: null,
  168. pdfThumbnailViewer: null,
  169. pdfRenderingQueue: null,
  170. pdfPresentationMode: null,
  171. pdfDocumentProperties: null,
  172. pdfLinkService: null,
  173. pdfHistory: null,
  174. pdfSidebar: null,
  175. pdfOutlineViewer: null,
  176. pdfAttachmentViewer: null,
  177. pdfLayerViewer: null,
  178. pdfCursorTools: null,
  179. pdfScriptingManager: null,
  180. store: null,
  181. downloadManager: null,
  182. overlayManager: null,
  183. preferences: null,
  184. toolbar: null,
  185. secondaryToolbar: null,
  186. eventBus: null,
  187. l10n: null,
  188. annotationEditorParams: null,
  189. isInitialViewSet: false,
  190. downloadComplete: false,
  191. isViewerEmbedded: window.parent !== window,
  192. url: "",
  193. baseUrl: "",
  194. _downloadUrl: "",
  195. externalServices: DefaultExternalServices,
  196. _boundEvents: Object.create(null),
  197. documentInfo: null,
  198. metadata: null,
  199. _contentDispositionFilename: null,
  200. _contentLength: null,
  201. _saveInProgress: false,
  202. _wheelUnusedTicks: 0,
  203. _wheelUnusedFactor: 1,
  204. _touchUnusedTicks: 0,
  205. _touchUnusedFactor: 1,
  206. _PDFBug: null,
  207. _hasAnnotationEditors: false,
  208. _title: document.title,
  209. _printAnnotationStoragePromise: null,
  210. _touchInfo: null,
  211. _isCtrlKeyDown: false,
  212. _nimbusDataPromise: null,
  213. async initialize(appConfig) {
  214. this.preferences = this.externalServices.createPreferences();
  215. this.appConfig = appConfig;
  216. await this._initializeOptions();
  217. this._forceCssTheme();
  218. await this._initializeL10n();
  219. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  220. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  221. }
  222. await this._initializeViewerComponents();
  223. this.bindEvents();
  224. this.bindWindowEvents();
  225. const appContainer = appConfig.appContainer || document.documentElement;
  226. this.l10n.translate(appContainer).then(() => {
  227. this.eventBus.dispatch("localized", {
  228. source: this
  229. });
  230. });
  231. this._initializedCapability.resolve();
  232. },
  233. async _initializeOptions() {
  234. if (_app_options.AppOptions.get("disablePreferences")) {
  235. if (_app_options.AppOptions.get("pdfBugEnabled")) {
  236. await this._parseHashParams();
  237. }
  238. return;
  239. }
  240. if (_app_options.AppOptions._hasUserOptions()) {
  241. console.warn("_initializeOptions: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  242. }
  243. try {
  244. _app_options.AppOptions.setAll(await this.preferences.getAll());
  245. } catch (reason) {
  246. console.error(`_initializeOptions: "${reason.message}".`);
  247. }
  248. if (_app_options.AppOptions.get("pdfBugEnabled")) {
  249. await this._parseHashParams();
  250. }
  251. },
  252. async _parseHashParams() {
  253. const hash = document.location.hash.substring(1);
  254. if (!hash) {
  255. return;
  256. }
  257. const {
  258. mainContainer,
  259. viewerContainer
  260. } = this.appConfig,
  261. params = (0, _ui_utils.parseQueryString)(hash);
  262. if (params.get("disableworker") === "true") {
  263. try {
  264. await loadFakeWorker();
  265. } catch (ex) {
  266. console.error(`_parseHashParams: "${ex.message}".`);
  267. }
  268. }
  269. if (params.has("disablerange")) {
  270. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  271. }
  272. if (params.has("disablestream")) {
  273. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  274. }
  275. if (params.has("disableautofetch")) {
  276. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  277. }
  278. if (params.has("disablefontface")) {
  279. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  280. }
  281. if (params.has("disablehistory")) {
  282. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  283. }
  284. if (params.has("verbosity")) {
  285. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  286. }
  287. if (params.has("textlayer")) {
  288. switch (params.get("textlayer")) {
  289. case "off":
  290. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  291. break;
  292. case "visible":
  293. case "shadow":
  294. case "hover":
  295. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  296. try {
  297. await loadPDFBug(this);
  298. this._PDFBug.loadCSS();
  299. } catch (ex) {
  300. console.error(`_parseHashParams: "${ex.message}".`);
  301. }
  302. break;
  303. }
  304. }
  305. if (params.has("pdfbug")) {
  306. _app_options.AppOptions.set("pdfBug", true);
  307. _app_options.AppOptions.set("fontExtraProperties", true);
  308. const enabled = params.get("pdfbug").split(",");
  309. try {
  310. await loadPDFBug(this);
  311. this._PDFBug.init(mainContainer, enabled);
  312. } catch (ex) {
  313. console.error(`_parseHashParams: "${ex.message}".`);
  314. }
  315. }
  316. if (params.has("locale")) {
  317. _app_options.AppOptions.set("locale", params.get("locale"));
  318. }
  319. },
  320. async _initializeL10n() {
  321. this.l10n = this.externalServices.createL10n({
  322. locale: _app_options.AppOptions.get("locale")
  323. });
  324. const dir = await this.l10n.getDirection();
  325. document.getElementsByTagName("html")[0].dir = dir;
  326. },
  327. _forceCssTheme() {
  328. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  329. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  330. return;
  331. }
  332. try {
  333. const styleSheet = document.styleSheets[0];
  334. const cssRules = styleSheet?.cssRules || [];
  335. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  336. const rule = cssRules[i];
  337. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  338. if (cssTheme === ViewerCssTheme.LIGHT) {
  339. styleSheet.deleteRule(i);
  340. return;
  341. }
  342. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  343. if (darkRules?.[1]) {
  344. styleSheet.deleteRule(i);
  345. styleSheet.insertRule(darkRules[1], i);
  346. }
  347. return;
  348. }
  349. }
  350. } catch (reason) {
  351. console.error(`_forceCssTheme: "${reason?.message}".`);
  352. }
  353. },
  354. async _initializeViewerComponents() {
  355. const {
  356. appConfig,
  357. externalServices,
  358. l10n
  359. } = this;
  360. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  361. this.eventBus = eventBus;
  362. this.overlayManager = new _overlay_manager.OverlayManager();
  363. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  364. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  365. this.pdfRenderingQueue = pdfRenderingQueue;
  366. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  367. eventBus,
  368. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  369. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  370. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  371. });
  372. this.pdfLinkService = pdfLinkService;
  373. const downloadManager = externalServices.createDownloadManager();
  374. this.downloadManager = downloadManager;
  375. const findController = new _pdf_find_controller.PDFFindController({
  376. linkService: pdfLinkService,
  377. eventBus,
  378. updateMatchesCountOnProgress: true
  379. });
  380. this.findController = findController;
  381. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  382. eventBus,
  383. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  384. externalServices,
  385. docProperties: this._scriptingDocProperties.bind(this)
  386. });
  387. this.pdfScriptingManager = pdfScriptingManager;
  388. const container = appConfig.mainContainer,
  389. viewer = appConfig.viewerContainer;
  390. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  391. const isOffscreenCanvasSupported = _app_options.AppOptions.get("isOffscreenCanvasSupported") && _pdfjsLib.FeatureTest.isOffscreenCanvasSupported;
  392. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  393. background: _app_options.AppOptions.get("pageColorsBackground"),
  394. foreground: _app_options.AppOptions.get("pageColorsForeground")
  395. } : null;
  396. const pdfViewer = new _pdf_viewer.PDFViewer({
  397. container,
  398. viewer,
  399. eventBus,
  400. renderingQueue: pdfRenderingQueue,
  401. linkService: pdfLinkService,
  402. downloadManager,
  403. findController,
  404. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  405. l10n,
  406. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  407. annotationMode: _app_options.AppOptions.get("annotationMode"),
  408. annotationEditorMode,
  409. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  410. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  411. isOffscreenCanvasSupported,
  412. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  413. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  414. pageColors
  415. });
  416. this.pdfViewer = pdfViewer;
  417. pdfRenderingQueue.setViewer(pdfViewer);
  418. pdfLinkService.setViewer(pdfViewer);
  419. pdfScriptingManager.setViewer(pdfViewer);
  420. if (appConfig.sidebar?.thumbnailView) {
  421. this.pdfThumbnailViewer = new _webPdf_thumbnail_viewer.PDFThumbnailViewer({
  422. container: appConfig.sidebar.thumbnailView,
  423. eventBus,
  424. renderingQueue: pdfRenderingQueue,
  425. linkService: pdfLinkService,
  426. l10n,
  427. pageColors
  428. });
  429. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  430. }
  431. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  432. this.pdfHistory = new _pdf_history.PDFHistory({
  433. linkService: pdfLinkService,
  434. eventBus
  435. });
  436. pdfLinkService.setHistory(this.pdfHistory);
  437. }
  438. if (!this.supportsIntegratedFind && appConfig.findBar) {
  439. this.findBar = new _webPdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, l10n);
  440. }
  441. if (appConfig.annotationEditorParams) {
  442. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  443. if (_app_options.AppOptions.get("enableStampEditor") && isOffscreenCanvasSupported) {
  444. appConfig.toolbar?.editorStampButton?.classList.remove("hidden");
  445. }
  446. this.annotationEditorParams = new _webAnnotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  447. } else {
  448. for (const id of ["editorModeButtons", "editorModeSeparator"]) {
  449. document.getElementById(id)?.classList.add("hidden");
  450. }
  451. }
  452. }
  453. if (appConfig.documentProperties) {
  454. this.pdfDocumentProperties = new _webPdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, l10n, () => this._docFilename);
  455. }
  456. if (appConfig.secondaryToolbar?.cursorHandToolButton) {
  457. this.pdfCursorTools = new _webPdf_cursor_tools.PDFCursorTools({
  458. container,
  459. eventBus,
  460. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  461. });
  462. }
  463. if (appConfig.toolbar) {
  464. this.toolbar = new _webToolbar.Toolbar(appConfig.toolbar, eventBus, l10n);
  465. }
  466. if (appConfig.secondaryToolbar) {
  467. this.secondaryToolbar = new _webSecondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, externalServices);
  468. }
  469. if (this.supportsFullscreen && appConfig.secondaryToolbar?.presentationModeButton) {
  470. this.pdfPresentationMode = new _webPdf_presentation_mode.PDFPresentationMode({
  471. container,
  472. pdfViewer,
  473. eventBus
  474. });
  475. }
  476. if (appConfig.passwordOverlay) {
  477. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, l10n, this.isViewerEmbedded);
  478. }
  479. if (appConfig.sidebar?.outlineView) {
  480. this.pdfOutlineViewer = new _webPdf_outline_viewer.PDFOutlineViewer({
  481. container: appConfig.sidebar.outlineView,
  482. eventBus,
  483. linkService: pdfLinkService,
  484. downloadManager
  485. });
  486. }
  487. if (appConfig.sidebar?.attachmentsView) {
  488. this.pdfAttachmentViewer = new _webPdf_attachment_viewer.PDFAttachmentViewer({
  489. container: appConfig.sidebar.attachmentsView,
  490. eventBus,
  491. downloadManager
  492. });
  493. }
  494. if (appConfig.sidebar?.layersView) {
  495. this.pdfLayerViewer = new _webPdf_layer_viewer.PDFLayerViewer({
  496. container: appConfig.sidebar.layersView,
  497. eventBus,
  498. l10n
  499. });
  500. }
  501. if (appConfig.sidebar) {
  502. this.pdfSidebar = new _webPdf_sidebar.PDFSidebar({
  503. elements: appConfig.sidebar,
  504. eventBus,
  505. l10n
  506. });
  507. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  508. this.pdfSidebar.onUpdateThumbnails = () => {
  509. for (const pageView of pdfViewer.getCachedPageViews()) {
  510. if (pageView.renderingState === _ui_utils.RenderingStates.FINISHED) {
  511. this.pdfThumbnailViewer.getThumbnail(pageView.id - 1)?.setImage(pageView);
  512. }
  513. }
  514. this.pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  515. };
  516. }
  517. },
  518. async run(config) {
  519. await this.initialize(config);
  520. const {
  521. appConfig,
  522. eventBus
  523. } = this;
  524. let file;
  525. const queryString = document.location.search.substring(1);
  526. const params = (0, _ui_utils.parseQueryString)(queryString);
  527. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  528. file = file.replace("+", "%2B").replace("#", "%23")
  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. if (fileOrigin !== viewerOrigin) {
  1636. throw new Error("file origin does not match viewer's");
  1637. }*/
  1638. } catch (ex) {
  1639. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1640. PDFViewerApplication._documentError(msg, {
  1641. message: ex?.message
  1642. });
  1643. });
  1644. throw ex;
  1645. }
  1646. };
  1647. }
  1648. async function loadFakeWorker() {
  1649. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  1650. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  1651. }
  1652. async function loadPDFBug(self) {
  1653. const {
  1654. debuggerScriptPath
  1655. } = self.appConfig;
  1656. const {
  1657. PDFBug
  1658. } = await import(debuggerScriptPath);
  1659. self._PDFBug = PDFBug;
  1660. }
  1661. function reportPageStatsPDFBug({
  1662. pageNumber
  1663. }) {
  1664. if (!globalThis.Stats?.enabled) {
  1665. return;
  1666. }
  1667. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1668. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  1669. }
  1670. function webViewerPageRender({
  1671. pageNumber
  1672. }) {
  1673. if (pageNumber === PDFViewerApplication.page) {
  1674. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
  1675. }
  1676. }
  1677. function webViewerPageRendered({
  1678. pageNumber,
  1679. error
  1680. }) {
  1681. if (pageNumber === PDFViewerApplication.page) {
  1682. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
  1683. }
  1684. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  1685. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1686. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
  1687. if (pageView) {
  1688. thumbnailView?.setImage(pageView);
  1689. }
  1690. }
  1691. if (error) {
  1692. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1693. PDFViewerApplication._otherError(msg, error);
  1694. });
  1695. }
  1696. }
  1697. function webViewerPageMode({
  1698. mode
  1699. }) {
  1700. let view;
  1701. switch (mode) {
  1702. case "thumbs":
  1703. view = _ui_utils.SidebarView.THUMBS;
  1704. break;
  1705. case "bookmarks":
  1706. case "outline":
  1707. view = _ui_utils.SidebarView.OUTLINE;
  1708. break;
  1709. case "attachments":
  1710. view = _ui_utils.SidebarView.ATTACHMENTS;
  1711. break;
  1712. case "layers":
  1713. view = _ui_utils.SidebarView.LAYERS;
  1714. break;
  1715. case "none":
  1716. view = _ui_utils.SidebarView.NONE;
  1717. break;
  1718. default:
  1719. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1720. return;
  1721. }
  1722. PDFViewerApplication.pdfSidebar?.switchView(view, true);
  1723. }
  1724. function webViewerNamedAction(evt) {
  1725. switch (evt.action) {
  1726. case "GoToPage":
  1727. PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
  1728. break;
  1729. case "Find":
  1730. if (!PDFViewerApplication.supportsIntegratedFind) {
  1731. PDFViewerApplication?.findBar.toggle();
  1732. }
  1733. break;
  1734. case "Print":
  1735. PDFViewerApplication.triggerPrinting();
  1736. break;
  1737. case "SaveAs":
  1738. PDFViewerApplication.downloadOrSave();
  1739. break;
  1740. }
  1741. }
  1742. function webViewerPresentationModeChanged(evt) {
  1743. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1744. }
  1745. function webViewerSidebarViewChanged({
  1746. view
  1747. }) {
  1748. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  1749. if (PDFViewerApplication.isInitialViewSet) {
  1750. PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
  1751. }
  1752. }
  1753. function webViewerUpdateViewarea({
  1754. location
  1755. }) {
  1756. if (PDFViewerApplication.isInitialViewSet) {
  1757. PDFViewerApplication.store?.setMultiple({
  1758. page: location.pageNumber,
  1759. zoom: location.scale,
  1760. scrollLeft: location.left,
  1761. scrollTop: location.top,
  1762. rotation: location.rotation
  1763. }).catch(() => {});
  1764. }
  1765. if (PDFViewerApplication.appConfig.secondaryToolbar) {
  1766. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1767. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1768. }
  1769. }
  1770. function webViewerScrollModeChanged(evt) {
  1771. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1772. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  1773. }
  1774. }
  1775. function webViewerSpreadModeChanged(evt) {
  1776. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1777. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  1778. }
  1779. }
  1780. function webViewerResize() {
  1781. const {
  1782. pdfDocument,
  1783. pdfViewer,
  1784. pdfRenderingQueue
  1785. } = PDFViewerApplication;
  1786. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  1787. return;
  1788. }
  1789. if (!pdfDocument) {
  1790. return;
  1791. }
  1792. const currentScaleValue = pdfViewer.currentScaleValue;
  1793. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  1794. pdfViewer.currentScaleValue = currentScaleValue;
  1795. }
  1796. pdfViewer.update();
  1797. }
  1798. function webViewerHashchange(evt) {
  1799. const hash = evt.hash;
  1800. if (!hash) {
  1801. return;
  1802. }
  1803. if (!PDFViewerApplication.isInitialViewSet) {
  1804. PDFViewerApplication.initialBookmark = hash;
  1805. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  1806. PDFViewerApplication.pdfLinkService.setHash(hash);
  1807. }
  1808. }
  1809. {
  1810. var webViewerFileInputChange = function (evt) {
  1811. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  1812. return;
  1813. }
  1814. const file = evt.fileInput.files[0];
  1815. PDFViewerApplication.open({
  1816. url: URL.createObjectURL(file),
  1817. originalUrl: file.name
  1818. });
  1819. };
  1820. var webViewerOpenFile = function (evt) {
  1821. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  1822. fileInput.click();
  1823. };
  1824. }
  1825. function webViewerPresentationMode() {
  1826. PDFViewerApplication.requestPresentationMode();
  1827. }
  1828. function webViewerSwitchAnnotationEditorMode(evt) {
  1829. PDFViewerApplication.pdfViewer.annotationEditorMode = evt;
  1830. }
  1831. function webViewerSwitchAnnotationEditorParams(evt) {
  1832. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  1833. }
  1834. function webViewerPrint() {
  1835. PDFViewerApplication.triggerPrinting();
  1836. }
  1837. function webViewerDownload() {
  1838. PDFViewerApplication.downloadOrSave();
  1839. }
  1840. function webViewerOpenInExternalApp() {
  1841. PDFViewerApplication.openInExternalApp();
  1842. }
  1843. function webViewerFirstPage() {
  1844. PDFViewerApplication.page = 1;
  1845. }
  1846. function webViewerLastPage() {
  1847. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1848. }
  1849. function webViewerNextPage() {
  1850. PDFViewerApplication.pdfViewer.nextPage();
  1851. }
  1852. function webViewerPreviousPage() {
  1853. PDFViewerApplication.pdfViewer.previousPage();
  1854. }
  1855. function webViewerZoomIn() {
  1856. PDFViewerApplication.zoomIn();
  1857. }
  1858. function webViewerZoomOut() {
  1859. PDFViewerApplication.zoomOut();
  1860. }
  1861. function webViewerZoomReset() {
  1862. PDFViewerApplication.zoomReset();
  1863. }
  1864. function webViewerPageNumberChanged(evt) {
  1865. const pdfViewer = PDFViewerApplication.pdfViewer;
  1866. if (evt.value !== "") {
  1867. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  1868. }
  1869. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1870. PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1871. }
  1872. }
  1873. function webViewerScaleChanged(evt) {
  1874. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1875. }
  1876. function webViewerRotateCw() {
  1877. PDFViewerApplication.rotatePages(90);
  1878. }
  1879. function webViewerRotateCcw() {
  1880. PDFViewerApplication.rotatePages(-90);
  1881. }
  1882. function webViewerOptionalContentConfig(evt) {
  1883. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  1884. }
  1885. function webViewerSwitchScrollMode(evt) {
  1886. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  1887. }
  1888. function webViewerSwitchSpreadMode(evt) {
  1889. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  1890. }
  1891. function webViewerDocumentProperties() {
  1892. PDFViewerApplication.pdfDocumentProperties?.open();
  1893. }
  1894. function webViewerFindFromUrlHash(evt) {
  1895. PDFViewerApplication.eventBus.dispatch("find", {
  1896. source: evt.source,
  1897. type: "",
  1898. query: evt.query,
  1899. caseSensitive: false,
  1900. entireWord: false,
  1901. highlightAll: true,
  1902. findPrevious: false,
  1903. matchDiacritics: true
  1904. });
  1905. }
  1906. function webViewerUpdateFindMatchesCount({
  1907. matchesCount
  1908. }) {
  1909. if (PDFViewerApplication.supportsIntegratedFind) {
  1910. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  1911. } else {
  1912. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  1913. }
  1914. }
  1915. function webViewerUpdateFindControlState({
  1916. state,
  1917. previous,
  1918. matchesCount,
  1919. rawQuery
  1920. }) {
  1921. if (PDFViewerApplication.supportsIntegratedFind) {
  1922. PDFViewerApplication.externalServices.updateFindControlState({
  1923. result: state,
  1924. findPrevious: previous,
  1925. matchesCount,
  1926. rawQuery
  1927. });
  1928. } else {
  1929. PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount);
  1930. }
  1931. }
  1932. function webViewerScaleChanging(evt) {
  1933. PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
  1934. PDFViewerApplication.pdfViewer.update();
  1935. }
  1936. function webViewerRotationChanging(evt) {
  1937. if (PDFViewerApplication.pdfThumbnailViewer) {
  1938. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  1939. }
  1940. PDFViewerApplication.forceRendering();
  1941. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  1942. }
  1943. function webViewerPageChanging({
  1944. pageNumber,
  1945. pageLabel
  1946. }) {
  1947. PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
  1948. PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
  1949. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  1950. PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
  1951. }
  1952. const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1953. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING);
  1954. }
  1955. function webViewerResolutionChange(evt) {
  1956. PDFViewerApplication.pdfViewer.refresh();
  1957. }
  1958. function webViewerVisibilityChange(evt) {
  1959. if (document.visibilityState === "visible") {
  1960. setZoomDisabledTimeout();
  1961. }
  1962. }
  1963. let zoomDisabledTimeout = null;
  1964. function setZoomDisabledTimeout() {
  1965. if (zoomDisabledTimeout) {
  1966. clearTimeout(zoomDisabledTimeout);
  1967. }
  1968. zoomDisabledTimeout = setTimeout(function () {
  1969. zoomDisabledTimeout = null;
  1970. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  1971. }
  1972. function webViewerWheel(evt) {
  1973. const {
  1974. pdfViewer,
  1975. supportedMouseWheelZoomModifierKeys,
  1976. supportsPinchToZoom
  1977. } = PDFViewerApplication;
  1978. if (pdfViewer.isInPresentationMode) {
  1979. return;
  1980. }
  1981. const deltaMode = evt.deltaMode;
  1982. let scaleFactor = Math.exp(-evt.deltaY / 100);
  1983. const isBuiltInMac = false;
  1984. const isPinchToZoom = evt.ctrlKey && !PDFViewerApplication._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && (Math.abs(scaleFactor - 1) < 0.05 || isBuiltInMac) && evt.deltaZ === 0;
  1985. if (isPinchToZoom || evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  1986. evt.preventDefault();
  1987. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  1988. return;
  1989. }
  1990. const previousScale = pdfViewer.currentScale;
  1991. if (isPinchToZoom && supportsPinchToZoom) {
  1992. scaleFactor = PDFViewerApplication._accumulateFactor(previousScale, scaleFactor, "_wheelUnusedFactor");
  1993. if (scaleFactor < 1) {
  1994. PDFViewerApplication.zoomOut(null, scaleFactor);
  1995. } else if (scaleFactor > 1) {
  1996. PDFViewerApplication.zoomIn(null, scaleFactor);
  1997. } else {
  1998. return;
  1999. }
  2000. } else {
  2001. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2002. let ticks = 0;
  2003. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2004. if (Math.abs(delta) >= 1) {
  2005. ticks = Math.sign(delta);
  2006. } else {
  2007. ticks = PDFViewerApplication._accumulateTicks(delta, "_wheelUnusedTicks");
  2008. }
  2009. } else {
  2010. const PIXELS_PER_LINE_SCALE = 30;
  2011. ticks = PDFViewerApplication._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks");
  2012. }
  2013. if (ticks < 0) {
  2014. PDFViewerApplication.zoomOut(-ticks);
  2015. } else if (ticks > 0) {
  2016. PDFViewerApplication.zoomIn(ticks);
  2017. } else {
  2018. return;
  2019. }
  2020. }
  2021. PDFViewerApplication._centerAtPos(previousScale, evt.clientX, evt.clientY);
  2022. } else {
  2023. setZoomDisabledTimeout();
  2024. }
  2025. }
  2026. function webViewerTouchStart(evt) {
  2027. if (PDFViewerApplication.pdfViewer.isInPresentationMode || evt.touches.length < 2) {
  2028. return;
  2029. }
  2030. evt.preventDefault();
  2031. if (evt.touches.length !== 2) {
  2032. PDFViewerApplication._touchInfo = null;
  2033. return;
  2034. }
  2035. let [touch0, touch1] = evt.touches;
  2036. if (touch0.identifier > touch1.identifier) {
  2037. [touch0, touch1] = [touch1, touch0];
  2038. }
  2039. PDFViewerApplication._touchInfo = {
  2040. touch0X: touch0.pageX,
  2041. touch0Y: touch0.pageY,
  2042. touch1X: touch1.pageX,
  2043. touch1Y: touch1.pageY
  2044. };
  2045. }
  2046. function webViewerTouchMove(evt) {
  2047. if (!PDFViewerApplication._touchInfo || evt.touches.length !== 2) {
  2048. return;
  2049. }
  2050. const {
  2051. pdfViewer,
  2052. _touchInfo,
  2053. supportsPinchToZoom
  2054. } = PDFViewerApplication;
  2055. let [touch0, touch1] = evt.touches;
  2056. if (touch0.identifier > touch1.identifier) {
  2057. [touch0, touch1] = [touch1, touch0];
  2058. }
  2059. const {
  2060. pageX: page0X,
  2061. pageY: page0Y
  2062. } = touch0;
  2063. const {
  2064. pageX: page1X,
  2065. pageY: page1Y
  2066. } = touch1;
  2067. const {
  2068. touch0X: pTouch0X,
  2069. touch0Y: pTouch0Y,
  2070. touch1X: pTouch1X,
  2071. touch1Y: pTouch1Y
  2072. } = _touchInfo;
  2073. if (Math.abs(pTouch0X - page0X) <= 1 && Math.abs(pTouch0Y - page0Y) <= 1 && Math.abs(pTouch1X - page1X) <= 1 && Math.abs(pTouch1Y - page1Y) <= 1) {
  2074. return;
  2075. }
  2076. _touchInfo.touch0X = page0X;
  2077. _touchInfo.touch0Y = page0Y;
  2078. _touchInfo.touch1X = page1X;
  2079. _touchInfo.touch1Y = page1Y;
  2080. if (pTouch0X === page0X && pTouch0Y === page0Y) {
  2081. const v1X = pTouch1X - page0X;
  2082. const v1Y = pTouch1Y - page0Y;
  2083. const v2X = page1X - page0X;
  2084. const v2Y = page1Y - page0Y;
  2085. const det = v1X * v2Y - v1Y * v2X;
  2086. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  2087. return;
  2088. }
  2089. } else if (pTouch1X === page1X && pTouch1Y === page1Y) {
  2090. const v1X = pTouch0X - page1X;
  2091. const v1Y = pTouch0Y - page1Y;
  2092. const v2X = page0X - page1X;
  2093. const v2Y = page0Y - page1Y;
  2094. const det = v1X * v2Y - v1Y * v2X;
  2095. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  2096. return;
  2097. }
  2098. } else {
  2099. const diff0X = page0X - pTouch0X;
  2100. const diff1X = page1X - pTouch1X;
  2101. const diff0Y = page0Y - pTouch0Y;
  2102. const diff1Y = page1Y - pTouch1Y;
  2103. const dotProduct = diff0X * diff1X + diff0Y * diff1Y;
  2104. if (dotProduct >= 0) {
  2105. return;
  2106. }
  2107. }
  2108. evt.preventDefault();
  2109. const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1;
  2110. const pDistance = Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1;
  2111. const previousScale = pdfViewer.currentScale;
  2112. if (supportsPinchToZoom) {
  2113. const newScaleFactor = PDFViewerApplication._accumulateFactor(previousScale, distance / pDistance, "_touchUnusedFactor");
  2114. if (newScaleFactor < 1) {
  2115. PDFViewerApplication.zoomOut(null, newScaleFactor);
  2116. } else if (newScaleFactor > 1) {
  2117. PDFViewerApplication.zoomIn(null, newScaleFactor);
  2118. } else {
  2119. return;
  2120. }
  2121. } else {
  2122. const PIXELS_PER_LINE_SCALE = 30;
  2123. const ticks = PDFViewerApplication._accumulateTicks((distance - pDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks");
  2124. if (ticks < 0) {
  2125. PDFViewerApplication.zoomOut(-ticks);
  2126. } else if (ticks > 0) {
  2127. PDFViewerApplication.zoomIn(ticks);
  2128. } else {
  2129. return;
  2130. }
  2131. }
  2132. PDFViewerApplication._centerAtPos(previousScale, (page0X + page1X) / 2, (page0Y + page1Y) / 2);
  2133. }
  2134. function webViewerTouchEnd(evt) {
  2135. if (!PDFViewerApplication._touchInfo) {
  2136. return;
  2137. }
  2138. evt.preventDefault();
  2139. PDFViewerApplication._touchInfo = null;
  2140. PDFViewerApplication._touchUnusedTicks = 0;
  2141. PDFViewerApplication._touchUnusedFactor = 1;
  2142. }
  2143. function webViewerClick(evt) {
  2144. if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
  2145. return;
  2146. }
  2147. const appConfig = PDFViewerApplication.appConfig;
  2148. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) {
  2149. PDFViewerApplication.secondaryToolbar.close();
  2150. }
  2151. }
  2152. function webViewerKeyUp(evt) {
  2153. if (evt.key === "Control") {
  2154. PDFViewerApplication._isCtrlKeyDown = false;
  2155. }
  2156. }
  2157. function webViewerKeyDown(evt) {
  2158. PDFViewerApplication._isCtrlKeyDown = evt.key === "Control";
  2159. if (PDFViewerApplication.overlayManager.active) {
  2160. return;
  2161. }
  2162. const {
  2163. eventBus,
  2164. pdfViewer
  2165. } = PDFViewerApplication;
  2166. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  2167. let handled = false,
  2168. ensureViewerFocused = false;
  2169. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2170. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2171. switch (evt.keyCode) {
  2172. case 70:
  2173. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2174. PDFViewerApplication.findBar?.open();
  2175. handled = true;
  2176. }
  2177. break;
  2178. case 71:
  2179. if (!PDFViewerApplication.supportsIntegratedFind) {
  2180. const {
  2181. state
  2182. } = PDFViewerApplication.findController;
  2183. if (state) {
  2184. const newState = {
  2185. source: window,
  2186. type: "again",
  2187. findPrevious: cmd === 5 || cmd === 12
  2188. };
  2189. eventBus.dispatch("find", {
  2190. ...state,
  2191. ...newState
  2192. });
  2193. }
  2194. handled = true;
  2195. }
  2196. break;
  2197. case 61:
  2198. case 107:
  2199. case 187:
  2200. case 171:
  2201. PDFViewerApplication.zoomIn();
  2202. handled = true;
  2203. break;
  2204. case 173:
  2205. case 109:
  2206. case 189:
  2207. PDFViewerApplication.zoomOut();
  2208. handled = true;
  2209. break;
  2210. case 48:
  2211. case 96:
  2212. if (!isViewerInPresentationMode) {
  2213. setTimeout(function () {
  2214. PDFViewerApplication.zoomReset();
  2215. });
  2216. handled = false;
  2217. }
  2218. break;
  2219. case 38:
  2220. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2221. PDFViewerApplication.page = 1;
  2222. handled = true;
  2223. ensureViewerFocused = true;
  2224. }
  2225. break;
  2226. case 40:
  2227. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2228. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2229. handled = true;
  2230. ensureViewerFocused = true;
  2231. }
  2232. break;
  2233. }
  2234. }
  2235. if (cmd === 1 || cmd === 8) {
  2236. switch (evt.keyCode) {
  2237. case 83:
  2238. eventBus.dispatch("download", {
  2239. source: window
  2240. });
  2241. handled = true;
  2242. break;
  2243. case 79:
  2244. {
  2245. eventBus.dispatch("openfile", {
  2246. source: window
  2247. });
  2248. handled = true;
  2249. }
  2250. break;
  2251. }
  2252. }
  2253. if (cmd === 3 || cmd === 10) {
  2254. switch (evt.keyCode) {
  2255. case 80:
  2256. PDFViewerApplication.requestPresentationMode();
  2257. handled = true;
  2258. PDFViewerApplication.externalServices.reportTelemetry({
  2259. type: "buttons",
  2260. data: {
  2261. id: "presentationModeKeyboard"
  2262. }
  2263. });
  2264. break;
  2265. case 71:
  2266. if (PDFViewerApplication.appConfig.toolbar) {
  2267. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2268. handled = true;
  2269. }
  2270. break;
  2271. }
  2272. }
  2273. if (handled) {
  2274. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2275. pdfViewer.focus();
  2276. }
  2277. evt.preventDefault();
  2278. return;
  2279. }
  2280. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2281. const curElementTagName = curElement?.tagName.toUpperCase();
  2282. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2283. if (evt.keyCode !== 27) {
  2284. return;
  2285. }
  2286. }
  2287. if (cmd === 0) {
  2288. let turnPage = 0,
  2289. turnOnlyIfPageFit = false;
  2290. switch (evt.keyCode) {
  2291. case 38:
  2292. case 33:
  2293. if (pdfViewer.isVerticalScrollbarEnabled) {
  2294. turnOnlyIfPageFit = true;
  2295. }
  2296. turnPage = -1;
  2297. break;
  2298. case 8:
  2299. if (!isViewerInPresentationMode) {
  2300. turnOnlyIfPageFit = true;
  2301. }
  2302. turnPage = -1;
  2303. break;
  2304. case 37:
  2305. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2306. turnOnlyIfPageFit = true;
  2307. }
  2308. case 75:
  2309. case 80:
  2310. turnPage = -1;
  2311. break;
  2312. case 27:
  2313. if (PDFViewerApplication.secondaryToolbar?.isOpen) {
  2314. PDFViewerApplication.secondaryToolbar.close();
  2315. handled = true;
  2316. }
  2317. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) {
  2318. PDFViewerApplication.findBar.close();
  2319. handled = true;
  2320. }
  2321. break;
  2322. case 40:
  2323. case 34:
  2324. if (pdfViewer.isVerticalScrollbarEnabled) {
  2325. turnOnlyIfPageFit = true;
  2326. }
  2327. turnPage = 1;
  2328. break;
  2329. case 13:
  2330. case 32:
  2331. if (!isViewerInPresentationMode) {
  2332. turnOnlyIfPageFit = true;
  2333. }
  2334. turnPage = 1;
  2335. break;
  2336. case 39:
  2337. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2338. turnOnlyIfPageFit = true;
  2339. }
  2340. case 74:
  2341. case 78:
  2342. turnPage = 1;
  2343. break;
  2344. case 36:
  2345. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2346. PDFViewerApplication.page = 1;
  2347. handled = true;
  2348. ensureViewerFocused = true;
  2349. }
  2350. break;
  2351. case 35:
  2352. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2353. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2354. handled = true;
  2355. ensureViewerFocused = true;
  2356. }
  2357. break;
  2358. case 83:
  2359. PDFViewerApplication.pdfCursorTools?.switchTool(_ui_utils.CursorTool.SELECT);
  2360. break;
  2361. case 72:
  2362. PDFViewerApplication.pdfCursorTools?.switchTool(_ui_utils.CursorTool.HAND);
  2363. break;
  2364. case 82:
  2365. PDFViewerApplication.rotatePages(90);
  2366. break;
  2367. case 115:
  2368. PDFViewerApplication.pdfSidebar?.toggle();
  2369. break;
  2370. }
  2371. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2372. if (turnPage > 0) {
  2373. pdfViewer.nextPage();
  2374. } else {
  2375. pdfViewer.previousPage();
  2376. }
  2377. handled = true;
  2378. }
  2379. }
  2380. if (cmd === 4) {
  2381. switch (evt.keyCode) {
  2382. case 13:
  2383. case 32:
  2384. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2385. break;
  2386. }
  2387. pdfViewer.previousPage();
  2388. handled = true;
  2389. break;
  2390. case 82:
  2391. PDFViewerApplication.rotatePages(-90);
  2392. break;
  2393. }
  2394. }
  2395. if (!handled && !isViewerInPresentationMode) {
  2396. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2397. ensureViewerFocused = true;
  2398. }
  2399. }
  2400. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2401. pdfViewer.focus();
  2402. }
  2403. if (handled) {
  2404. evt.preventDefault();
  2405. }
  2406. }
  2407. function beforeUnload(evt) {
  2408. evt.preventDefault();
  2409. evt.returnValue = "";
  2410. return false;
  2411. }
  2412. function webViewerAnnotationEditorStatesChanged(data) {
  2413. PDFViewerApplication.externalServices.updateEditorStates(data);
  2414. }
  2415. const PDFPrintServiceFactory = {
  2416. instance: {
  2417. supportsPrinting: false,
  2418. createPrintService() {
  2419. throw new Error("Not implemented: createPrintService");
  2420. }
  2421. }
  2422. };
  2423. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2424. /***/ }),
  2425. /* 3 */
  2426. /***/ ((__unused_webpack_module, exports) => {
  2427. Object.defineProperty(exports, "__esModule", ({
  2428. value: true
  2429. }));
  2430. 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;
  2431. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  2432. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2433. exports.approximateFraction = approximateFraction;
  2434. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2435. exports.binarySearchFirstItem = binarySearchFirstItem;
  2436. exports.docStyle = void 0;
  2437. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2438. exports.getPageSizeInches = getPageSizeInches;
  2439. exports.getVisibleElements = getVisibleElements;
  2440. exports.isPortraitOrientation = isPortraitOrientation;
  2441. exports.isValidRotation = isValidRotation;
  2442. exports.isValidScrollMode = isValidScrollMode;
  2443. exports.isValidSpreadMode = isValidSpreadMode;
  2444. exports.noContextMenuHandler = noContextMenuHandler;
  2445. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2446. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2447. exports.parseQueryString = parseQueryString;
  2448. exports.removeNullCharacters = removeNullCharacters;
  2449. exports.roundToDivide = roundToDivide;
  2450. exports.scrollIntoView = scrollIntoView;
  2451. exports.toggleCheckedBtn = toggleCheckedBtn;
  2452. exports.toggleExpandedBtn = toggleExpandedBtn;
  2453. exports.watchScroll = watchScroll;
  2454. const DEFAULT_SCALE_VALUE = "auto";
  2455. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2456. const DEFAULT_SCALE = 1.0;
  2457. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2458. const DEFAULT_SCALE_DELTA = 1.1;
  2459. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  2460. const MIN_SCALE = 0.1;
  2461. exports.MIN_SCALE = MIN_SCALE;
  2462. const MAX_SCALE = 10.0;
  2463. exports.MAX_SCALE = MAX_SCALE;
  2464. const UNKNOWN_SCALE = 0;
  2465. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2466. const MAX_AUTO_SCALE = 1.25;
  2467. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2468. const SCROLLBAR_PADDING = 40;
  2469. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2470. const VERTICAL_PADDING = 5;
  2471. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2472. const RenderingStates = {
  2473. INITIAL: 0,
  2474. RUNNING: 1,
  2475. PAUSED: 2,
  2476. FINISHED: 3
  2477. };
  2478. exports.RenderingStates = RenderingStates;
  2479. const PresentationModeState = {
  2480. UNKNOWN: 0,
  2481. NORMAL: 1,
  2482. CHANGING: 2,
  2483. FULLSCREEN: 3
  2484. };
  2485. exports.PresentationModeState = PresentationModeState;
  2486. const SidebarView = {
  2487. UNKNOWN: -1,
  2488. NONE: 0,
  2489. THUMBS: 1,
  2490. OUTLINE: 2,
  2491. ATTACHMENTS: 3,
  2492. LAYERS: 4
  2493. };
  2494. exports.SidebarView = SidebarView;
  2495. const TextLayerMode = {
  2496. DISABLE: 0,
  2497. ENABLE: 1,
  2498. ENABLE_PERMISSIONS: 2
  2499. };
  2500. exports.TextLayerMode = TextLayerMode;
  2501. const ScrollMode = {
  2502. UNKNOWN: -1,
  2503. VERTICAL: 0,
  2504. HORIZONTAL: 1,
  2505. WRAPPED: 2,
  2506. PAGE: 3
  2507. };
  2508. exports.ScrollMode = ScrollMode;
  2509. const SpreadMode = {
  2510. UNKNOWN: -1,
  2511. NONE: 0,
  2512. ODD: 1,
  2513. EVEN: 2
  2514. };
  2515. exports.SpreadMode = SpreadMode;
  2516. const CursorTool = {
  2517. SELECT: 0,
  2518. HAND: 1,
  2519. ZOOM: 2
  2520. };
  2521. exports.CursorTool = CursorTool;
  2522. const AutoPrintRegExp = /\bprint\s*\(/;
  2523. exports.AutoPrintRegExp = AutoPrintRegExp;
  2524. class OutputScale {
  2525. constructor() {
  2526. const pixelRatio = window.devicePixelRatio || 1;
  2527. this.sx = pixelRatio;
  2528. this.sy = pixelRatio;
  2529. }
  2530. get scaled() {
  2531. return this.sx !== 1 || this.sy !== 1;
  2532. }
  2533. }
  2534. exports.OutputScale = OutputScale;
  2535. function scrollIntoView(element, spot, scrollMatches = false) {
  2536. let parent = element.offsetParent;
  2537. if (!parent) {
  2538. console.error("offsetParent is not set -- cannot scroll");
  2539. return;
  2540. }
  2541. let offsetY = element.offsetTop + element.clientTop;
  2542. let offsetX = element.offsetLeft + element.clientLeft;
  2543. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  2544. offsetY += parent.offsetTop;
  2545. offsetX += parent.offsetLeft;
  2546. parent = parent.offsetParent;
  2547. if (!parent) {
  2548. return;
  2549. }
  2550. }
  2551. if (spot) {
  2552. if (spot.top !== undefined) {
  2553. offsetY += spot.top;
  2554. }
  2555. if (spot.left !== undefined) {
  2556. offsetX += spot.left;
  2557. parent.scrollLeft = offsetX;
  2558. }
  2559. }
  2560. parent.scrollTop = offsetY;
  2561. }
  2562. function watchScroll(viewAreaElement, callback) {
  2563. const debounceScroll = function (evt) {
  2564. if (rAF) {
  2565. return;
  2566. }
  2567. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2568. rAF = null;
  2569. const currentX = viewAreaElement.scrollLeft;
  2570. const lastX = state.lastX;
  2571. if (currentX !== lastX) {
  2572. state.right = currentX > lastX;
  2573. }
  2574. state.lastX = currentX;
  2575. const currentY = viewAreaElement.scrollTop;
  2576. const lastY = state.lastY;
  2577. if (currentY !== lastY) {
  2578. state.down = currentY > lastY;
  2579. }
  2580. state.lastY = currentY;
  2581. callback(state);
  2582. });
  2583. };
  2584. const state = {
  2585. right: true,
  2586. down: true,
  2587. lastX: viewAreaElement.scrollLeft,
  2588. lastY: viewAreaElement.scrollTop,
  2589. _eventHandler: debounceScroll
  2590. };
  2591. let rAF = null;
  2592. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2593. return state;
  2594. }
  2595. function parseQueryString(query) {
  2596. const params = new Map();
  2597. for (const [key, value] of new URLSearchParams(query)) {
  2598. params.set(key.toLowerCase(), value);
  2599. }
  2600. return params;
  2601. }
  2602. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  2603. function removeNullCharacters(str, replaceInvisible = false) {
  2604. if (typeof str !== "string") {
  2605. console.error(`The argument must be a string.`);
  2606. return str;
  2607. }
  2608. if (replaceInvisible) {
  2609. str = str.replaceAll(InvisibleCharactersRegExp, " ");
  2610. }
  2611. return str.replaceAll("\x00", "");
  2612. }
  2613. function binarySearchFirstItem(items, condition, start = 0) {
  2614. let minIndex = start;
  2615. let maxIndex = items.length - 1;
  2616. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2617. return items.length;
  2618. }
  2619. if (condition(items[minIndex])) {
  2620. return minIndex;
  2621. }
  2622. while (minIndex < maxIndex) {
  2623. const currentIndex = minIndex + maxIndex >> 1;
  2624. const currentItem = items[currentIndex];
  2625. if (condition(currentItem)) {
  2626. maxIndex = currentIndex;
  2627. } else {
  2628. minIndex = currentIndex + 1;
  2629. }
  2630. }
  2631. return minIndex;
  2632. }
  2633. function approximateFraction(x) {
  2634. if (Math.floor(x) === x) {
  2635. return [x, 1];
  2636. }
  2637. const xinv = 1 / x;
  2638. const limit = 8;
  2639. if (xinv > limit) {
  2640. return [1, limit];
  2641. } else if (Math.floor(xinv) === xinv) {
  2642. return [1, xinv];
  2643. }
  2644. const x_ = x > 1 ? xinv : x;
  2645. let a = 0,
  2646. b = 1,
  2647. c = 1,
  2648. d = 1;
  2649. while (true) {
  2650. const p = a + c,
  2651. q = b + d;
  2652. if (q > limit) {
  2653. break;
  2654. }
  2655. if (x_ <= p / q) {
  2656. c = p;
  2657. d = q;
  2658. } else {
  2659. a = p;
  2660. b = q;
  2661. }
  2662. }
  2663. let result;
  2664. if (x_ - a / b < c / d - x_) {
  2665. result = x_ === x ? [a, b] : [b, a];
  2666. } else {
  2667. result = x_ === x ? [c, d] : [d, c];
  2668. }
  2669. return result;
  2670. }
  2671. function roundToDivide(x, div) {
  2672. const r = x % div;
  2673. return r === 0 ? x : Math.round(x - r + div);
  2674. }
  2675. function getPageSizeInches({
  2676. view,
  2677. userUnit,
  2678. rotate
  2679. }) {
  2680. const [x1, y1, x2, y2] = view;
  2681. const changeOrientation = rotate % 180 !== 0;
  2682. const width = (x2 - x1) / 72 * userUnit;
  2683. const height = (y2 - y1) / 72 * userUnit;
  2684. return {
  2685. width: changeOrientation ? height : width,
  2686. height: changeOrientation ? width : height
  2687. };
  2688. }
  2689. function backtrackBeforeAllVisibleElements(index, views, top) {
  2690. if (index < 2) {
  2691. return index;
  2692. }
  2693. let elt = views[index].div;
  2694. let pageTop = elt.offsetTop + elt.clientTop;
  2695. if (pageTop >= top) {
  2696. elt = views[index - 1].div;
  2697. pageTop = elt.offsetTop + elt.clientTop;
  2698. }
  2699. for (let i = index - 2; i >= 0; --i) {
  2700. elt = views[i].div;
  2701. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2702. break;
  2703. }
  2704. index = i;
  2705. }
  2706. return index;
  2707. }
  2708. function getVisibleElements({
  2709. scrollEl,
  2710. views,
  2711. sortByVisibility = false,
  2712. horizontal = false,
  2713. rtl = false
  2714. }) {
  2715. const top = scrollEl.scrollTop,
  2716. bottom = top + scrollEl.clientHeight;
  2717. const left = scrollEl.scrollLeft,
  2718. right = left + scrollEl.clientWidth;
  2719. function isElementBottomAfterViewTop(view) {
  2720. const element = view.div;
  2721. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2722. return elementBottom > top;
  2723. }
  2724. function isElementNextAfterViewHorizontally(view) {
  2725. const element = view.div;
  2726. const elementLeft = element.offsetLeft + element.clientLeft;
  2727. const elementRight = elementLeft + element.clientWidth;
  2728. return rtl ? elementLeft < right : elementRight > left;
  2729. }
  2730. const visible = [],
  2731. ids = new Set(),
  2732. numViews = views.length;
  2733. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2734. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2735. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2736. }
  2737. let lastEdge = horizontal ? right : -1;
  2738. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2739. const view = views[i],
  2740. element = view.div;
  2741. const currentWidth = element.offsetLeft + element.clientLeft;
  2742. const currentHeight = element.offsetTop + element.clientTop;
  2743. const viewWidth = element.clientWidth,
  2744. viewHeight = element.clientHeight;
  2745. const viewRight = currentWidth + viewWidth;
  2746. const viewBottom = currentHeight + viewHeight;
  2747. if (lastEdge === -1) {
  2748. if (viewBottom >= bottom) {
  2749. lastEdge = viewBottom;
  2750. }
  2751. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2752. break;
  2753. }
  2754. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2755. continue;
  2756. }
  2757. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2758. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2759. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2760. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2761. const percent = fractionHeight * fractionWidth * 100 | 0;
  2762. visible.push({
  2763. id: view.id,
  2764. x: currentWidth,
  2765. y: currentHeight,
  2766. view,
  2767. percent,
  2768. widthPercent: fractionWidth * 100 | 0
  2769. });
  2770. ids.add(view.id);
  2771. }
  2772. const first = visible[0],
  2773. last = visible.at(-1);
  2774. if (sortByVisibility) {
  2775. visible.sort(function (a, b) {
  2776. const pc = a.percent - b.percent;
  2777. if (Math.abs(pc) > 0.001) {
  2778. return -pc;
  2779. }
  2780. return a.id - b.id;
  2781. });
  2782. }
  2783. return {
  2784. first,
  2785. last,
  2786. views: visible,
  2787. ids
  2788. };
  2789. }
  2790. function noContextMenuHandler(evt) {
  2791. evt.preventDefault();
  2792. }
  2793. function normalizeWheelEventDirection(evt) {
  2794. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2795. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2796. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2797. delta = -delta;
  2798. }
  2799. return delta;
  2800. }
  2801. function normalizeWheelEventDelta(evt) {
  2802. const deltaMode = evt.deltaMode;
  2803. let delta = normalizeWheelEventDirection(evt);
  2804. const MOUSE_PIXELS_PER_LINE = 30;
  2805. const MOUSE_LINES_PER_PAGE = 30;
  2806. if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
  2807. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2808. } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
  2809. delta /= MOUSE_LINES_PER_PAGE;
  2810. }
  2811. return delta;
  2812. }
  2813. function isValidRotation(angle) {
  2814. return Number.isInteger(angle) && angle % 90 === 0;
  2815. }
  2816. function isValidScrollMode(mode) {
  2817. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2818. }
  2819. function isValidSpreadMode(mode) {
  2820. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2821. }
  2822. function isPortraitOrientation(size) {
  2823. return size.width <= size.height;
  2824. }
  2825. const animationStarted = new Promise(function (resolve) {
  2826. window.requestAnimationFrame(resolve);
  2827. });
  2828. exports.animationStarted = animationStarted;
  2829. const docStyle = document.documentElement.style;
  2830. exports.docStyle = docStyle;
  2831. function clamp(v, min, max) {
  2832. return Math.min(Math.max(v, min), max);
  2833. }
  2834. class ProgressBar {
  2835. #classList = null;
  2836. #disableAutoFetchTimeout = null;
  2837. #percent = 0;
  2838. #style = null;
  2839. #visible = true;
  2840. constructor(bar) {
  2841. this.#classList = bar.classList;
  2842. this.#style = bar.style;
  2843. }
  2844. get percent() {
  2845. return this.#percent;
  2846. }
  2847. set percent(val) {
  2848. this.#percent = clamp(val, 0, 100);
  2849. if (isNaN(val)) {
  2850. this.#classList.add("indeterminate");
  2851. return;
  2852. }
  2853. this.#classList.remove("indeterminate");
  2854. this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
  2855. }
  2856. setWidth(viewer) {
  2857. if (!viewer) {
  2858. return;
  2859. }
  2860. const container = viewer.parentNode;
  2861. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  2862. if (scrollbarWidth > 0) {
  2863. this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  2864. }
  2865. }
  2866. setDisableAutoFetch(delay = 5000) {
  2867. if (isNaN(this.#percent)) {
  2868. return;
  2869. }
  2870. if (this.#disableAutoFetchTimeout) {
  2871. clearTimeout(this.#disableAutoFetchTimeout);
  2872. }
  2873. this.show();
  2874. this.#disableAutoFetchTimeout = setTimeout(() => {
  2875. this.#disableAutoFetchTimeout = null;
  2876. this.hide();
  2877. }, delay);
  2878. }
  2879. hide() {
  2880. if (!this.#visible) {
  2881. return;
  2882. }
  2883. this.#visible = false;
  2884. this.#classList.add("hidden");
  2885. }
  2886. show() {
  2887. if (this.#visible) {
  2888. return;
  2889. }
  2890. this.#visible = true;
  2891. this.#classList.remove("hidden");
  2892. }
  2893. }
  2894. exports.ProgressBar = ProgressBar;
  2895. function getActiveOrFocusedElement() {
  2896. let curRoot = document;
  2897. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2898. while (curActiveOrFocused?.shadowRoot) {
  2899. curRoot = curActiveOrFocused.shadowRoot;
  2900. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2901. }
  2902. return curActiveOrFocused;
  2903. }
  2904. function apiPageLayoutToViewerModes(layout) {
  2905. let scrollMode = ScrollMode.VERTICAL,
  2906. spreadMode = SpreadMode.NONE;
  2907. switch (layout) {
  2908. case "SinglePage":
  2909. scrollMode = ScrollMode.PAGE;
  2910. break;
  2911. case "OneColumn":
  2912. break;
  2913. case "TwoPageLeft":
  2914. scrollMode = ScrollMode.PAGE;
  2915. case "TwoColumnLeft":
  2916. spreadMode = SpreadMode.ODD;
  2917. break;
  2918. case "TwoPageRight":
  2919. scrollMode = ScrollMode.PAGE;
  2920. case "TwoColumnRight":
  2921. spreadMode = SpreadMode.EVEN;
  2922. break;
  2923. }
  2924. return {
  2925. scrollMode,
  2926. spreadMode
  2927. };
  2928. }
  2929. function apiPageModeToSidebarView(mode) {
  2930. switch (mode) {
  2931. case "UseNone":
  2932. return SidebarView.NONE;
  2933. case "UseThumbs":
  2934. return SidebarView.THUMBS;
  2935. case "UseOutlines":
  2936. return SidebarView.OUTLINE;
  2937. case "UseAttachments":
  2938. return SidebarView.ATTACHMENTS;
  2939. case "UseOC":
  2940. return SidebarView.LAYERS;
  2941. }
  2942. return SidebarView.NONE;
  2943. }
  2944. function toggleCheckedBtn(button, toggle, view = null) {
  2945. button.classList.toggle("toggled", toggle);
  2946. button.setAttribute("aria-checked", toggle);
  2947. view?.classList.toggle("hidden", !toggle);
  2948. }
  2949. function toggleExpandedBtn(button, toggle, view = null) {
  2950. button.classList.toggle("toggled", toggle);
  2951. button.setAttribute("aria-expanded", toggle);
  2952. view?.classList.toggle("hidden", !toggle);
  2953. }
  2954. /***/ }),
  2955. /* 4 */
  2956. /***/ ((module) => {
  2957. module.exports = globalThis.pdfjsLib;
  2958. /***/ }),
  2959. /* 5 */
  2960. /***/ ((__unused_webpack_module, exports) => {
  2961. Object.defineProperty(exports, "__esModule", ({
  2962. value: true
  2963. }));
  2964. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  2965. const compatibilityParams = Object.create(null);
  2966. exports.compatibilityParams = compatibilityParams;
  2967. {
  2968. const userAgent = navigator.userAgent || "";
  2969. const platform = navigator.platform || "";
  2970. const maxTouchPoints = navigator.maxTouchPoints || 1;
  2971. const isAndroid = /Android/.test(userAgent);
  2972. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  2973. (function checkCanvasSizeLimitation() {
  2974. if (isIOS || isAndroid) {
  2975. compatibilityParams.maxCanvasPixels = 5242880;
  2976. }
  2977. })();
  2978. }
  2979. const OptionKind = {
  2980. VIEWER: 0x02,
  2981. API: 0x04,
  2982. WORKER: 0x08,
  2983. PREFERENCE: 0x80
  2984. };
  2985. exports.OptionKind = OptionKind;
  2986. const defaultOptions = {
  2987. annotationEditorMode: {
  2988. value: 0,
  2989. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2990. },
  2991. annotationMode: {
  2992. value: 2,
  2993. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2994. },
  2995. cursorToolOnLoad: {
  2996. value: 0,
  2997. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2998. },
  2999. defaultZoomDelay: {
  3000. value: 400,
  3001. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3002. },
  3003. defaultZoomValue: {
  3004. value: "",
  3005. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3006. },
  3007. disableHistory: {
  3008. value: false,
  3009. kind: OptionKind.VIEWER
  3010. },
  3011. disablePageLabels: {
  3012. value: false,
  3013. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3014. },
  3015. enablePermissions: {
  3016. value: false,
  3017. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3018. },
  3019. enablePrintAutoRotate: {
  3020. value: true,
  3021. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3022. },
  3023. enableScripting: {
  3024. value: true,
  3025. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3026. },
  3027. enableStampEditor: {
  3028. value: true,
  3029. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3030. },
  3031. externalLinkRel: {
  3032. value: "noopener noreferrer nofollow",
  3033. kind: OptionKind.VIEWER
  3034. },
  3035. externalLinkTarget: {
  3036. value: 0,
  3037. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3038. },
  3039. historyUpdateUrl: {
  3040. value: false,
  3041. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3042. },
  3043. ignoreDestinationZoom: {
  3044. value: false,
  3045. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3046. },
  3047. imageResourcesPath: {
  3048. value: "./images/",
  3049. kind: OptionKind.VIEWER
  3050. },
  3051. maxCanvasPixels: {
  3052. value: 16777216,
  3053. kind: OptionKind.VIEWER
  3054. },
  3055. forcePageColors: {
  3056. value: false,
  3057. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3058. },
  3059. pageColorsBackground: {
  3060. value: "Canvas",
  3061. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3062. },
  3063. pageColorsForeground: {
  3064. value: "CanvasText",
  3065. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3066. },
  3067. pdfBugEnabled: {
  3068. value: false,
  3069. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3070. },
  3071. printResolution: {
  3072. value: 150,
  3073. kind: OptionKind.VIEWER
  3074. },
  3075. sidebarViewOnLoad: {
  3076. value: -1,
  3077. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3078. },
  3079. scrollModeOnLoad: {
  3080. value: -1,
  3081. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3082. },
  3083. spreadModeOnLoad: {
  3084. value: -1,
  3085. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3086. },
  3087. textLayerMode: {
  3088. value: 1,
  3089. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3090. },
  3091. viewerCssTheme: {
  3092. value: 0,
  3093. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3094. },
  3095. viewOnLoad: {
  3096. value: 0,
  3097. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3098. },
  3099. cMapPacked: {
  3100. value: true,
  3101. kind: OptionKind.API
  3102. },
  3103. cMapUrl: {
  3104. value: "../web/cmaps/",
  3105. kind: OptionKind.API
  3106. },
  3107. disableAutoFetch: {
  3108. value: false,
  3109. kind: OptionKind.API + OptionKind.PREFERENCE
  3110. },
  3111. disableFontFace: {
  3112. value: false,
  3113. kind: OptionKind.API + OptionKind.PREFERENCE
  3114. },
  3115. disableRange: {
  3116. value: false,
  3117. kind: OptionKind.API + OptionKind.PREFERENCE
  3118. },
  3119. disableStream: {
  3120. value: false,
  3121. kind: OptionKind.API + OptionKind.PREFERENCE
  3122. },
  3123. docBaseUrl: {
  3124. value: "",
  3125. kind: OptionKind.API
  3126. },
  3127. enableXfa: {
  3128. value: true,
  3129. kind: OptionKind.API + OptionKind.PREFERENCE
  3130. },
  3131. fontExtraProperties: {
  3132. value: false,
  3133. kind: OptionKind.API
  3134. },
  3135. isEvalSupported: {
  3136. value: true,
  3137. kind: OptionKind.API
  3138. },
  3139. isOffscreenCanvasSupported: {
  3140. value: true,
  3141. kind: OptionKind.API
  3142. },
  3143. maxImageSize: {
  3144. value: -1,
  3145. kind: OptionKind.API
  3146. },
  3147. pdfBug: {
  3148. value: false,
  3149. kind: OptionKind.API
  3150. },
  3151. standardFontDataUrl: {
  3152. value: "../web/standard_fonts/",
  3153. kind: OptionKind.API
  3154. },
  3155. verbosity: {
  3156. value: 1,
  3157. kind: OptionKind.API
  3158. },
  3159. workerPort: {
  3160. value: null,
  3161. kind: OptionKind.WORKER
  3162. },
  3163. workerSrc: {
  3164. value: "../build/pdf.worker.js",
  3165. kind: OptionKind.WORKER
  3166. }
  3167. };
  3168. {
  3169. defaultOptions.defaultUrl = {
  3170. value: "compressed.tracemonkey-pldi-09.pdf",
  3171. kind: OptionKind.VIEWER
  3172. };
  3173. defaultOptions.disablePreferences = {
  3174. value: false,
  3175. kind: OptionKind.VIEWER
  3176. };
  3177. defaultOptions.locale = {
  3178. value: navigator.language || "en-US",
  3179. kind: OptionKind.VIEWER
  3180. };
  3181. defaultOptions.sandboxBundleSrc = {
  3182. value: "../build/pdf.sandbox.js",
  3183. kind: OptionKind.VIEWER
  3184. };
  3185. }
  3186. const userOptions = Object.create(null);
  3187. class AppOptions {
  3188. constructor() {
  3189. throw new Error("Cannot initialize AppOptions.");
  3190. }
  3191. static get(name) {
  3192. const userOption = userOptions[name];
  3193. if (userOption !== undefined) {
  3194. return userOption;
  3195. }
  3196. const defaultOption = defaultOptions[name];
  3197. if (defaultOption !== undefined) {
  3198. return compatibilityParams[name] ?? defaultOption.value;
  3199. }
  3200. return undefined;
  3201. }
  3202. static getAll(kind = null) {
  3203. const options = Object.create(null);
  3204. for (const name in defaultOptions) {
  3205. const defaultOption = defaultOptions[name];
  3206. if (kind) {
  3207. if ((kind & defaultOption.kind) === 0) {
  3208. continue;
  3209. }
  3210. if (kind === OptionKind.PREFERENCE) {
  3211. const value = defaultOption.value,
  3212. valueType = typeof value;
  3213. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  3214. options[name] = value;
  3215. continue;
  3216. }
  3217. throw new Error(`Invalid type for preference: ${name}`);
  3218. }
  3219. }
  3220. const userOption = userOptions[name];
  3221. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  3222. }
  3223. return options;
  3224. }
  3225. static set(name, value) {
  3226. userOptions[name] = value;
  3227. }
  3228. static setAll(options) {
  3229. for (const name in options) {
  3230. userOptions[name] = options[name];
  3231. }
  3232. }
  3233. static remove(name) {
  3234. delete userOptions[name];
  3235. }
  3236. }
  3237. exports.AppOptions = AppOptions;
  3238. {
  3239. AppOptions._hasUserOptions = function () {
  3240. return Object.keys(userOptions).length > 0;
  3241. };
  3242. }
  3243. /***/ }),
  3244. /* 6 */
  3245. /***/ ((__unused_webpack_module, exports) => {
  3246. Object.defineProperty(exports, "__esModule", ({
  3247. value: true
  3248. }));
  3249. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3250. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3251. const WaitOnType = {
  3252. EVENT: "event",
  3253. TIMEOUT: "timeout"
  3254. };
  3255. exports.WaitOnType = WaitOnType;
  3256. function waitOnEventOrTimeout({
  3257. target,
  3258. name,
  3259. delay = 0
  3260. }) {
  3261. return new Promise(function (resolve, reject) {
  3262. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3263. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3264. }
  3265. function handler(type) {
  3266. if (target instanceof EventBus) {
  3267. target._off(name, eventHandler);
  3268. } else {
  3269. target.removeEventListener(name, eventHandler);
  3270. }
  3271. if (timeout) {
  3272. clearTimeout(timeout);
  3273. }
  3274. resolve(type);
  3275. }
  3276. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3277. if (target instanceof EventBus) {
  3278. target._on(name, eventHandler);
  3279. } else {
  3280. target.addEventListener(name, eventHandler);
  3281. }
  3282. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3283. const timeout = setTimeout(timeoutHandler, delay);
  3284. });
  3285. }
  3286. class EventBus {
  3287. #listeners = Object.create(null);
  3288. on(eventName, listener, options = null) {
  3289. this._on(eventName, listener, {
  3290. external: true,
  3291. once: options?.once
  3292. });
  3293. }
  3294. off(eventName, listener, options = null) {
  3295. this._off(eventName, listener, {
  3296. external: true,
  3297. once: options?.once
  3298. });
  3299. }
  3300. dispatch(eventName, data) {
  3301. const eventListeners = this.#listeners[eventName];
  3302. if (!eventListeners || eventListeners.length === 0) {
  3303. return;
  3304. }
  3305. let externalListeners;
  3306. for (const {
  3307. listener,
  3308. external,
  3309. once
  3310. } of eventListeners.slice(0)) {
  3311. if (once) {
  3312. this._off(eventName, listener);
  3313. }
  3314. if (external) {
  3315. (externalListeners ||= []).push(listener);
  3316. continue;
  3317. }
  3318. listener(data);
  3319. }
  3320. if (externalListeners) {
  3321. for (const listener of externalListeners) {
  3322. listener(data);
  3323. }
  3324. externalListeners = null;
  3325. }
  3326. }
  3327. _on(eventName, listener, options = null) {
  3328. const eventListeners = this.#listeners[eventName] ||= [];
  3329. eventListeners.push({
  3330. listener,
  3331. external: options?.external === true,
  3332. once: options?.once === true
  3333. });
  3334. }
  3335. _off(eventName, listener, options = null) {
  3336. const eventListeners = this.#listeners[eventName];
  3337. if (!eventListeners) {
  3338. return;
  3339. }
  3340. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3341. if (eventListeners[i].listener === listener) {
  3342. eventListeners.splice(i, 1);
  3343. return;
  3344. }
  3345. }
  3346. }
  3347. }
  3348. exports.EventBus = EventBus;
  3349. class AutomationEventBus extends EventBus {
  3350. dispatch(eventName, data) {
  3351. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3352. }
  3353. }
  3354. exports.AutomationEventBus = AutomationEventBus;
  3355. /***/ }),
  3356. /* 7 */
  3357. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3358. Object.defineProperty(exports, "__esModule", ({
  3359. value: true
  3360. }));
  3361. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  3362. var _ui_utils = __webpack_require__(3);
  3363. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  3364. const LinkTarget = {
  3365. NONE: 0,
  3366. SELF: 1,
  3367. BLANK: 2,
  3368. PARENT: 3,
  3369. TOP: 4
  3370. };
  3371. exports.LinkTarget = LinkTarget;
  3372. function addLinkAttributes(link, {
  3373. url,
  3374. target,
  3375. rel,
  3376. enabled = true
  3377. } = {}) {
  3378. if (!url || typeof url !== "string") {
  3379. throw new Error('A valid "url" parameter must provided.');
  3380. }
  3381. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  3382. if (enabled) {
  3383. link.href = link.title = urlNullRemoved;
  3384. } else {
  3385. link.href = "";
  3386. link.title = `Disabled: ${urlNullRemoved}`;
  3387. link.onclick = () => {
  3388. return false;
  3389. };
  3390. }
  3391. let targetStr = "";
  3392. switch (target) {
  3393. case LinkTarget.NONE:
  3394. break;
  3395. case LinkTarget.SELF:
  3396. targetStr = "_self";
  3397. break;
  3398. case LinkTarget.BLANK:
  3399. targetStr = "_blank";
  3400. break;
  3401. case LinkTarget.PARENT:
  3402. targetStr = "_parent";
  3403. break;
  3404. case LinkTarget.TOP:
  3405. targetStr = "_top";
  3406. break;
  3407. }
  3408. link.target = targetStr;
  3409. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  3410. }
  3411. class PDFLinkService {
  3412. #pagesRefCache = new Map();
  3413. constructor({
  3414. eventBus,
  3415. externalLinkTarget = null,
  3416. externalLinkRel = null,
  3417. ignoreDestinationZoom = false
  3418. } = {}) {
  3419. this.eventBus = eventBus;
  3420. this.externalLinkTarget = externalLinkTarget;
  3421. this.externalLinkRel = externalLinkRel;
  3422. this.externalLinkEnabled = true;
  3423. this._ignoreDestinationZoom = ignoreDestinationZoom;
  3424. this.baseUrl = null;
  3425. this.pdfDocument = null;
  3426. this.pdfViewer = null;
  3427. this.pdfHistory = null;
  3428. }
  3429. setDocument(pdfDocument, baseUrl = null) {
  3430. this.baseUrl = baseUrl;
  3431. this.pdfDocument = pdfDocument;
  3432. this.#pagesRefCache.clear();
  3433. }
  3434. setViewer(pdfViewer) {
  3435. this.pdfViewer = pdfViewer;
  3436. }
  3437. setHistory(pdfHistory) {
  3438. this.pdfHistory = pdfHistory;
  3439. }
  3440. get pagesCount() {
  3441. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  3442. }
  3443. get page() {
  3444. return this.pdfViewer.currentPageNumber;
  3445. }
  3446. set page(value) {
  3447. this.pdfViewer.currentPageNumber = value;
  3448. }
  3449. get rotation() {
  3450. return this.pdfViewer.pagesRotation;
  3451. }
  3452. set rotation(value) {
  3453. this.pdfViewer.pagesRotation = value;
  3454. }
  3455. get isInPresentationMode() {
  3456. return this.pdfViewer.isInPresentationMode;
  3457. }
  3458. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  3459. const destRef = explicitDest[0];
  3460. let pageNumber;
  3461. if (typeof destRef === "object" && destRef !== null) {
  3462. pageNumber = this._cachedPageNumber(destRef);
  3463. if (!pageNumber) {
  3464. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  3465. this.cachePageRef(pageIndex + 1, destRef);
  3466. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  3467. }).catch(() => {
  3468. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  3469. });
  3470. return;
  3471. }
  3472. } else if (Number.isInteger(destRef)) {
  3473. pageNumber = destRef + 1;
  3474. } else {
  3475. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  3476. return;
  3477. }
  3478. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  3479. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  3480. return;
  3481. }
  3482. if (this.pdfHistory) {
  3483. this.pdfHistory.pushCurrentPosition();
  3484. this.pdfHistory.push({
  3485. namedDest,
  3486. explicitDest,
  3487. pageNumber
  3488. });
  3489. }
  3490. this.pdfViewer.scrollPageIntoView({
  3491. pageNumber,
  3492. destArray: explicitDest,
  3493. ignoreDestinationZoom: this._ignoreDestinationZoom
  3494. });
  3495. }
  3496. async goToDestination(dest) {
  3497. if (!this.pdfDocument) {
  3498. return;
  3499. }
  3500. let namedDest, explicitDest;
  3501. if (typeof dest === "string") {
  3502. namedDest = dest;
  3503. explicitDest = await this.pdfDocument.getDestination(dest);
  3504. } else {
  3505. namedDest = null;
  3506. explicitDest = await dest;
  3507. }
  3508. if (!Array.isArray(explicitDest)) {
  3509. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  3510. return;
  3511. }
  3512. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  3513. }
  3514. goToPage(val) {
  3515. if (!this.pdfDocument) {
  3516. return;
  3517. }
  3518. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  3519. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  3520. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  3521. return;
  3522. }
  3523. if (this.pdfHistory) {
  3524. this.pdfHistory.pushCurrentPosition();
  3525. this.pdfHistory.pushPage(pageNumber);
  3526. }
  3527. this.pdfViewer.scrollPageIntoView({
  3528. pageNumber
  3529. });
  3530. }
  3531. addLinkAttributes(link, url, newWindow = false) {
  3532. addLinkAttributes(link, {
  3533. url,
  3534. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  3535. rel: this.externalLinkRel,
  3536. enabled: this.externalLinkEnabled
  3537. });
  3538. }
  3539. getDestinationHash(dest) {
  3540. if (typeof dest === "string") {
  3541. if (dest.length > 0) {
  3542. return this.getAnchorUrl("#" + escape(dest));
  3543. }
  3544. } else if (Array.isArray(dest)) {
  3545. const str = JSON.stringify(dest);
  3546. if (str.length > 0) {
  3547. return this.getAnchorUrl("#" + escape(str));
  3548. }
  3549. }
  3550. return this.getAnchorUrl("");
  3551. }
  3552. getAnchorUrl(anchor) {
  3553. return this.baseUrl ? this.baseUrl + anchor : anchor;
  3554. }
  3555. setHash(hash) {
  3556. if (!this.pdfDocument) {
  3557. return;
  3558. }
  3559. let pageNumber, dest;
  3560. if (hash.includes("=")) {
  3561. const params = (0, _ui_utils.parseQueryString)(hash);
  3562. if (params.has("search")) {
  3563. const query = params.get("search").replaceAll('"', ""),
  3564. phrase = params.get("phrase") === "true";
  3565. this.eventBus.dispatch("findfromurlhash", {
  3566. source: this,
  3567. query: phrase ? query : query.match(/\S+/g)
  3568. });
  3569. }
  3570. if (params.has("page")) {
  3571. pageNumber = params.get("page") | 0 || 1;
  3572. }
  3573. if (params.has("zoom")) {
  3574. const zoomArgs = params.get("zoom").split(",");
  3575. const zoomArg = zoomArgs[0];
  3576. const zoomArgNumber = parseFloat(zoomArg);
  3577. if (!zoomArg.includes("Fit")) {
  3578. dest = [null, {
  3579. name: "XYZ"
  3580. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  3581. } else if (zoomArg === "Fit" || zoomArg === "FitB") {
  3582. dest = [null, {
  3583. name: zoomArg
  3584. }];
  3585. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  3586. dest = [null, {
  3587. name: zoomArg
  3588. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  3589. } else if (zoomArg === "FitR") {
  3590. if (zoomArgs.length !== 5) {
  3591. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  3592. } else {
  3593. dest = [null, {
  3594. name: zoomArg
  3595. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  3596. }
  3597. } else {
  3598. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  3599. }
  3600. }
  3601. if (dest) {
  3602. this.pdfViewer.scrollPageIntoView({
  3603. pageNumber: pageNumber || this.page,
  3604. destArray: dest,
  3605. allowNegativeOffset: true
  3606. });
  3607. } else if (pageNumber) {
  3608. this.page = pageNumber;
  3609. }
  3610. if (params.has("pagemode")) {
  3611. this.eventBus.dispatch("pagemode", {
  3612. source: this,
  3613. mode: params.get("pagemode")
  3614. });
  3615. }
  3616. if (params.has("nameddest")) {
  3617. this.goToDestination(params.get("nameddest"));
  3618. }
  3619. } else {
  3620. dest = unescape(hash);
  3621. try {
  3622. dest = JSON.parse(dest);
  3623. if (!Array.isArray(dest)) {
  3624. dest = dest.toString();
  3625. }
  3626. } catch {}
  3627. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  3628. this.goToDestination(dest);
  3629. return;
  3630. }
  3631. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  3632. }
  3633. }
  3634. executeNamedAction(action) {
  3635. switch (action) {
  3636. case "GoBack":
  3637. this.pdfHistory?.back();
  3638. break;
  3639. case "GoForward":
  3640. this.pdfHistory?.forward();
  3641. break;
  3642. case "NextPage":
  3643. this.pdfViewer.nextPage();
  3644. break;
  3645. case "PrevPage":
  3646. this.pdfViewer.previousPage();
  3647. break;
  3648. case "LastPage":
  3649. this.page = this.pagesCount;
  3650. break;
  3651. case "FirstPage":
  3652. this.page = 1;
  3653. break;
  3654. default:
  3655. break;
  3656. }
  3657. this.eventBus.dispatch("namedaction", {
  3658. source: this,
  3659. action
  3660. });
  3661. }
  3662. async executeSetOCGState(action) {
  3663. const pdfDocument = this.pdfDocument;
  3664. const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  3665. if (pdfDocument !== this.pdfDocument) {
  3666. return;
  3667. }
  3668. let operator;
  3669. for (const elem of action.state) {
  3670. switch (elem) {
  3671. case "ON":
  3672. case "OFF":
  3673. case "Toggle":
  3674. operator = elem;
  3675. continue;
  3676. }
  3677. switch (operator) {
  3678. case "ON":
  3679. optionalContentConfig.setVisibility(elem, true);
  3680. break;
  3681. case "OFF":
  3682. optionalContentConfig.setVisibility(elem, false);
  3683. break;
  3684. case "Toggle":
  3685. const group = optionalContentConfig.getGroup(elem);
  3686. if (group) {
  3687. optionalContentConfig.setVisibility(elem, !group.visible);
  3688. }
  3689. break;
  3690. }
  3691. }
  3692. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  3693. }
  3694. cachePageRef(pageNum, pageRef) {
  3695. if (!pageRef) {
  3696. return;
  3697. }
  3698. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3699. this.#pagesRefCache.set(refStr, pageNum);
  3700. }
  3701. _cachedPageNumber(pageRef) {
  3702. if (!pageRef) {
  3703. return null;
  3704. }
  3705. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3706. return this.#pagesRefCache.get(refStr) || null;
  3707. }
  3708. static #isValidExplicitDestination(dest) {
  3709. if (!Array.isArray(dest)) {
  3710. return false;
  3711. }
  3712. const destLength = dest.length;
  3713. if (destLength < 2) {
  3714. return false;
  3715. }
  3716. const page = dest[0];
  3717. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  3718. return false;
  3719. }
  3720. const zoom = dest[1];
  3721. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  3722. return false;
  3723. }
  3724. let allowNull = true;
  3725. switch (zoom.name) {
  3726. case "XYZ":
  3727. if (destLength !== 5) {
  3728. return false;
  3729. }
  3730. break;
  3731. case "Fit":
  3732. case "FitB":
  3733. return destLength === 2;
  3734. case "FitH":
  3735. case "FitBH":
  3736. case "FitV":
  3737. case "FitBV":
  3738. if (destLength !== 3) {
  3739. return false;
  3740. }
  3741. break;
  3742. case "FitR":
  3743. if (destLength !== 6) {
  3744. return false;
  3745. }
  3746. allowNull = false;
  3747. break;
  3748. default:
  3749. return false;
  3750. }
  3751. for (let i = 2; i < destLength; i++) {
  3752. const param = dest[i];
  3753. if (!(typeof param === "number" || allowNull && param === null)) {
  3754. return false;
  3755. }
  3756. }
  3757. return true;
  3758. }
  3759. }
  3760. exports.PDFLinkService = PDFLinkService;
  3761. class SimpleLinkService {
  3762. constructor() {
  3763. this.externalLinkEnabled = true;
  3764. }
  3765. get pagesCount() {
  3766. return 0;
  3767. }
  3768. get page() {
  3769. return 0;
  3770. }
  3771. set page(value) {}
  3772. get rotation() {
  3773. return 0;
  3774. }
  3775. set rotation(value) {}
  3776. get isInPresentationMode() {
  3777. return false;
  3778. }
  3779. async goToDestination(dest) {}
  3780. goToPage(val) {}
  3781. addLinkAttributes(link, url, newWindow = false) {
  3782. addLinkAttributes(link, {
  3783. url,
  3784. enabled: this.externalLinkEnabled
  3785. });
  3786. }
  3787. getDestinationHash(dest) {
  3788. return "#";
  3789. }
  3790. getAnchorUrl(hash) {
  3791. return "#";
  3792. }
  3793. setHash(hash) {}
  3794. executeNamedAction(action) {}
  3795. executeSetOCGState(action) {}
  3796. cachePageRef(pageNum, pageRef) {}
  3797. }
  3798. exports.SimpleLinkService = SimpleLinkService;
  3799. /***/ }),
  3800. /* 8 */
  3801. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3802. Object.defineProperty(exports, "__esModule", ({
  3803. value: true
  3804. }));
  3805. exports.AnnotationEditorParams = void 0;
  3806. var _pdfjsLib = __webpack_require__(4);
  3807. class AnnotationEditorParams {
  3808. constructor(options, eventBus) {
  3809. this.eventBus = eventBus;
  3810. this.#bindListeners(options);
  3811. }
  3812. #bindListeners({
  3813. editorFreeTextFontSize,
  3814. editorFreeTextColor,
  3815. editorInkColor,
  3816. editorInkThickness,
  3817. editorInkOpacity,
  3818. editorStampAddImage
  3819. }) {
  3820. const dispatchEvent = (typeStr, value) => {
  3821. this.eventBus.dispatch("switchannotationeditorparams", {
  3822. source: this,
  3823. type: _pdfjsLib.AnnotationEditorParamsType[typeStr],
  3824. value
  3825. });
  3826. };
  3827. editorFreeTextFontSize.addEventListener("input", function () {
  3828. dispatchEvent("FREETEXT_SIZE", this.valueAsNumber);
  3829. });
  3830. editorFreeTextColor.addEventListener("input", function () {
  3831. dispatchEvent("FREETEXT_COLOR", this.value);
  3832. });
  3833. editorInkColor.addEventListener("input", function () {
  3834. dispatchEvent("INK_COLOR", this.value);
  3835. });
  3836. editorInkThickness.addEventListener("input", function () {
  3837. dispatchEvent("INK_THICKNESS", this.valueAsNumber);
  3838. });
  3839. editorInkOpacity.addEventListener("input", function () {
  3840. dispatchEvent("INK_OPACITY", this.valueAsNumber);
  3841. });
  3842. editorStampAddImage.addEventListener("click", () => {
  3843. dispatchEvent("CREATE");
  3844. });
  3845. this.eventBus._on("annotationeditorparamschanged", evt => {
  3846. for (const [type, value] of evt.details) {
  3847. switch (type) {
  3848. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  3849. editorFreeTextFontSize.value = value;
  3850. break;
  3851. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  3852. editorFreeTextColor.value = value;
  3853. break;
  3854. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  3855. editorInkColor.value = value;
  3856. break;
  3857. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  3858. editorInkThickness.value = value;
  3859. break;
  3860. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  3861. editorInkOpacity.value = value;
  3862. break;
  3863. }
  3864. }
  3865. });
  3866. }
  3867. }
  3868. exports.AnnotationEditorParams = AnnotationEditorParams;
  3869. /***/ }),
  3870. /* 9 */
  3871. /***/ ((__unused_webpack_module, exports) => {
  3872. Object.defineProperty(exports, "__esModule", ({
  3873. value: true
  3874. }));
  3875. exports.OverlayManager = void 0;
  3876. class OverlayManager {
  3877. #overlays = new WeakMap();
  3878. #active = null;
  3879. get active() {
  3880. return this.#active;
  3881. }
  3882. async register(dialog, canForceClose = false) {
  3883. if (typeof dialog !== "object") {
  3884. throw new Error("Not enough parameters.");
  3885. } else if (this.#overlays.has(dialog)) {
  3886. throw new Error("The overlay is already registered.");
  3887. }
  3888. this.#overlays.set(dialog, {
  3889. canForceClose
  3890. });
  3891. dialog.addEventListener("cancel", evt => {
  3892. this.#active = null;
  3893. });
  3894. }
  3895. async open(dialog) {
  3896. if (!this.#overlays.has(dialog)) {
  3897. throw new Error("The overlay does not exist.");
  3898. } else if (this.#active) {
  3899. if (this.#active === dialog) {
  3900. throw new Error("The overlay is already active.");
  3901. } else if (this.#overlays.get(dialog).canForceClose) {
  3902. await this.close();
  3903. } else {
  3904. throw new Error("Another overlay is currently active.");
  3905. }
  3906. }
  3907. this.#active = dialog;
  3908. dialog.showModal();
  3909. }
  3910. async close(dialog = this.#active) {
  3911. if (!this.#overlays.has(dialog)) {
  3912. throw new Error("The overlay does not exist.");
  3913. } else if (!this.#active) {
  3914. throw new Error("The overlay is currently not active.");
  3915. } else if (this.#active !== dialog) {
  3916. throw new Error("Another overlay is currently active.");
  3917. }
  3918. dialog.close();
  3919. this.#active = null;
  3920. }
  3921. }
  3922. exports.OverlayManager = OverlayManager;
  3923. /***/ }),
  3924. /* 10 */
  3925. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3926. Object.defineProperty(exports, "__esModule", ({
  3927. value: true
  3928. }));
  3929. exports.PasswordPrompt = void 0;
  3930. var _pdfjsLib = __webpack_require__(4);
  3931. class PasswordPrompt {
  3932. #activeCapability = null;
  3933. #updateCallback = null;
  3934. #reason = null;
  3935. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3936. this.dialog = options.dialog;
  3937. this.label = options.label;
  3938. this.input = options.input;
  3939. this.submitButton = options.submitButton;
  3940. this.cancelButton = options.cancelButton;
  3941. this.overlayManager = overlayManager;
  3942. this.l10n = l10n;
  3943. this._isViewerEmbedded = isViewerEmbedded;
  3944. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3945. this.cancelButton.addEventListener("click", this.close.bind(this));
  3946. this.input.addEventListener("keydown", e => {
  3947. if (e.keyCode === 13) {
  3948. this.#verify();
  3949. }
  3950. });
  3951. this.overlayManager.register(this.dialog, true);
  3952. this.dialog.addEventListener("close", this.#cancel.bind(this));
  3953. }
  3954. async open() {
  3955. if (this.#activeCapability) {
  3956. await this.#activeCapability.promise;
  3957. }
  3958. this.#activeCapability = new _pdfjsLib.PromiseCapability();
  3959. try {
  3960. await this.overlayManager.open(this.dialog);
  3961. } catch (ex) {
  3962. this.#activeCapability.resolve();
  3963. throw ex;
  3964. }
  3965. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3966. if (!this._isViewerEmbedded || passwordIncorrect) {
  3967. this.input.focus();
  3968. }
  3969. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3970. }
  3971. async close() {
  3972. if (this.overlayManager.active === this.dialog) {
  3973. this.overlayManager.close(this.dialog);
  3974. }
  3975. }
  3976. #verify() {
  3977. const password = this.input.value;
  3978. if (password?.length > 0) {
  3979. this.#invokeCallback(password);
  3980. }
  3981. }
  3982. #cancel() {
  3983. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  3984. this.#activeCapability.resolve();
  3985. }
  3986. #invokeCallback(password) {
  3987. if (!this.#updateCallback) {
  3988. return;
  3989. }
  3990. this.close();
  3991. this.input.value = "";
  3992. this.#updateCallback(password);
  3993. this.#updateCallback = null;
  3994. }
  3995. async setUpdateCallback(updateCallback, reason) {
  3996. if (this.#activeCapability) {
  3997. await this.#activeCapability.promise;
  3998. }
  3999. this.#updateCallback = updateCallback;
  4000. this.#reason = reason;
  4001. }
  4002. }
  4003. exports.PasswordPrompt = PasswordPrompt;
  4004. /***/ }),
  4005. /* 11 */
  4006. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4007. Object.defineProperty(exports, "__esModule", ({
  4008. value: true
  4009. }));
  4010. exports.PDFAttachmentViewer = void 0;
  4011. var _pdfjsLib = __webpack_require__(4);
  4012. var _base_tree_viewer = __webpack_require__(12);
  4013. var _event_utils = __webpack_require__(6);
  4014. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4015. constructor(options) {
  4016. super(options);
  4017. this.downloadManager = options.downloadManager;
  4018. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  4019. }
  4020. reset(keepRenderedCapability = false) {
  4021. super.reset();
  4022. this._attachments = null;
  4023. if (!keepRenderedCapability) {
  4024. this._renderedCapability = new _pdfjsLib.PromiseCapability();
  4025. }
  4026. this._pendingDispatchEvent = false;
  4027. }
  4028. async _dispatchEvent(attachmentsCount) {
  4029. this._renderedCapability.resolve();
  4030. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4031. this._pendingDispatchEvent = true;
  4032. await (0, _event_utils.waitOnEventOrTimeout)({
  4033. target: this.eventBus,
  4034. name: "annotationlayerrendered",
  4035. delay: 1000
  4036. });
  4037. if (!this._pendingDispatchEvent) {
  4038. return;
  4039. }
  4040. }
  4041. this._pendingDispatchEvent = false;
  4042. this.eventBus.dispatch("attachmentsloaded", {
  4043. source: this,
  4044. attachmentsCount
  4045. });
  4046. }
  4047. _bindLink(element, {
  4048. content,
  4049. filename
  4050. }) {
  4051. element.onclick = () => {
  4052. this.downloadManager.openOrDownloadData(element, content, filename);
  4053. return false;
  4054. };
  4055. }
  4056. render({
  4057. attachments,
  4058. keepRenderedCapability = false
  4059. }) {
  4060. if (this._attachments) {
  4061. this.reset(keepRenderedCapability);
  4062. }
  4063. this._attachments = attachments || null;
  4064. if (!attachments) {
  4065. this._dispatchEvent(0);
  4066. return;
  4067. }
  4068. const fragment = document.createDocumentFragment();
  4069. let attachmentsCount = 0;
  4070. for (const name in attachments) {
  4071. const item = attachments[name];
  4072. const content = item.content,
  4073. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true);
  4074. const div = document.createElement("div");
  4075. div.className = "treeItem";
  4076. const element = document.createElement("a");
  4077. this._bindLink(element, {
  4078. content,
  4079. filename
  4080. });
  4081. element.textContent = this._normalizeTextContent(filename);
  4082. div.append(element);
  4083. fragment.append(div);
  4084. attachmentsCount++;
  4085. }
  4086. this._finishRendering(fragment, attachmentsCount);
  4087. }
  4088. #appendAttachment({
  4089. filename,
  4090. content
  4091. }) {
  4092. const renderedPromise = this._renderedCapability.promise;
  4093. renderedPromise.then(() => {
  4094. if (renderedPromise !== this._renderedCapability.promise) {
  4095. return;
  4096. }
  4097. const attachments = this._attachments || Object.create(null);
  4098. for (const name in attachments) {
  4099. if (filename === name) {
  4100. return;
  4101. }
  4102. }
  4103. attachments[filename] = {
  4104. filename,
  4105. content
  4106. };
  4107. this.render({
  4108. attachments,
  4109. keepRenderedCapability: true
  4110. });
  4111. });
  4112. }
  4113. }
  4114. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4115. /***/ }),
  4116. /* 12 */
  4117. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4118. Object.defineProperty(exports, "__esModule", ({
  4119. value: true
  4120. }));
  4121. exports.BaseTreeViewer = void 0;
  4122. var _ui_utils = __webpack_require__(3);
  4123. const TREEITEM_OFFSET_TOP = -100;
  4124. const TREEITEM_SELECTED_CLASS = "selected";
  4125. class BaseTreeViewer {
  4126. constructor(options) {
  4127. if (this.constructor === BaseTreeViewer) {
  4128. throw new Error("Cannot initialize BaseTreeViewer.");
  4129. }
  4130. this.container = options.container;
  4131. this.eventBus = options.eventBus;
  4132. this.reset();
  4133. }
  4134. reset() {
  4135. this._pdfDocument = null;
  4136. this._lastToggleIsShow = true;
  4137. this._currentTreeItem = null;
  4138. this.container.textContent = "";
  4139. this.container.classList.remove("treeWithDeepNesting");
  4140. }
  4141. _dispatchEvent(count) {
  4142. throw new Error("Not implemented: _dispatchEvent");
  4143. }
  4144. _bindLink(element, params) {
  4145. throw new Error("Not implemented: _bindLink");
  4146. }
  4147. _normalizeTextContent(str) {
  4148. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4149. }
  4150. _addToggleButton(div, hidden = false) {
  4151. const toggler = document.createElement("div");
  4152. toggler.className = "treeItemToggler";
  4153. if (hidden) {
  4154. toggler.classList.add("treeItemsHidden");
  4155. }
  4156. toggler.onclick = evt => {
  4157. evt.stopPropagation();
  4158. toggler.classList.toggle("treeItemsHidden");
  4159. if (evt.shiftKey) {
  4160. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4161. this._toggleTreeItem(div, shouldShowAll);
  4162. }
  4163. };
  4164. div.prepend(toggler);
  4165. }
  4166. _toggleTreeItem(root, show = false) {
  4167. this._lastToggleIsShow = show;
  4168. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4169. toggler.classList.toggle("treeItemsHidden", !show);
  4170. }
  4171. }
  4172. _toggleAllTreeItems() {
  4173. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4174. }
  4175. _finishRendering(fragment, count, hasAnyNesting = false) {
  4176. if (hasAnyNesting) {
  4177. this.container.classList.add("treeWithDeepNesting");
  4178. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4179. }
  4180. this.container.append(fragment);
  4181. this._dispatchEvent(count);
  4182. }
  4183. render(params) {
  4184. throw new Error("Not implemented: render");
  4185. }
  4186. _updateCurrentTreeItem(treeItem = null) {
  4187. if (this._currentTreeItem) {
  4188. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4189. this._currentTreeItem = null;
  4190. }
  4191. if (treeItem) {
  4192. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4193. this._currentTreeItem = treeItem;
  4194. }
  4195. }
  4196. _scrollToCurrentTreeItem(treeItem) {
  4197. if (!treeItem) {
  4198. return;
  4199. }
  4200. let currentNode = treeItem.parentNode;
  4201. while (currentNode && currentNode !== this.container) {
  4202. if (currentNode.classList.contains("treeItem")) {
  4203. const toggler = currentNode.firstElementChild;
  4204. toggler?.classList.remove("treeItemsHidden");
  4205. }
  4206. currentNode = currentNode.parentNode;
  4207. }
  4208. this._updateCurrentTreeItem(treeItem);
  4209. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4210. }
  4211. }
  4212. exports.BaseTreeViewer = BaseTreeViewer;
  4213. /***/ }),
  4214. /* 13 */
  4215. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4216. Object.defineProperty(exports, "__esModule", ({
  4217. value: true
  4218. }));
  4219. exports.PDFCursorTools = void 0;
  4220. var _pdfjsLib = __webpack_require__(4);
  4221. var _ui_utils = __webpack_require__(3);
  4222. var _grab_to_pan = __webpack_require__(14);
  4223. class PDFCursorTools {
  4224. #active = _ui_utils.CursorTool.SELECT;
  4225. #prevActive = null;
  4226. constructor({
  4227. container,
  4228. eventBus,
  4229. cursorToolOnLoad = _ui_utils.CursorTool.SELECT
  4230. }) {
  4231. this.container = container;
  4232. this.eventBus = eventBus;
  4233. this.#addEventListeners();
  4234. Promise.resolve().then(() => {
  4235. this.switchTool(cursorToolOnLoad);
  4236. });
  4237. }
  4238. get activeTool() {
  4239. return this.#active;
  4240. }
  4241. switchTool(tool) {
  4242. if (this.#prevActive !== null) {
  4243. return;
  4244. }
  4245. if (tool === this.#active) {
  4246. return;
  4247. }
  4248. const disableActiveTool = () => {
  4249. switch (this.#active) {
  4250. case _ui_utils.CursorTool.SELECT:
  4251. break;
  4252. case _ui_utils.CursorTool.HAND:
  4253. this._handTool.deactivate();
  4254. break;
  4255. case _ui_utils.CursorTool.ZOOM:
  4256. }
  4257. };
  4258. switch (tool) {
  4259. case _ui_utils.CursorTool.SELECT:
  4260. disableActiveTool();
  4261. break;
  4262. case _ui_utils.CursorTool.HAND:
  4263. disableActiveTool();
  4264. this._handTool.activate();
  4265. break;
  4266. case _ui_utils.CursorTool.ZOOM:
  4267. default:
  4268. console.error(`switchTool: "${tool}" is an unsupported value.`);
  4269. return;
  4270. }
  4271. this.#active = tool;
  4272. this.eventBus.dispatch("cursortoolchanged", {
  4273. source: this,
  4274. tool
  4275. });
  4276. }
  4277. #addEventListeners() {
  4278. this.eventBus._on("switchcursortool", evt => {
  4279. this.switchTool(evt.tool);
  4280. });
  4281. let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
  4282. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  4283. const disableActive = () => {
  4284. const prevActive = this.#active;
  4285. this.switchTool(_ui_utils.CursorTool.SELECT);
  4286. this.#prevActive ??= prevActive;
  4287. };
  4288. const enableActive = () => {
  4289. const prevActive = this.#prevActive;
  4290. if (prevActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) {
  4291. this.#prevActive = null;
  4292. this.switchTool(prevActive);
  4293. }
  4294. };
  4295. this.eventBus._on("secondarytoolbarreset", evt => {
  4296. if (this.#prevActive !== null) {
  4297. annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  4298. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  4299. enableActive();
  4300. }
  4301. });
  4302. this.eventBus._on("annotationeditormodechanged", ({
  4303. mode
  4304. }) => {
  4305. annotationEditorMode = mode;
  4306. if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
  4307. enableActive();
  4308. } else {
  4309. disableActive();
  4310. }
  4311. });
  4312. this.eventBus._on("presentationmodechanged", ({
  4313. state
  4314. }) => {
  4315. presentationModeState = state;
  4316. if (state === _ui_utils.PresentationModeState.NORMAL) {
  4317. enableActive();
  4318. } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
  4319. disableActive();
  4320. }
  4321. });
  4322. }
  4323. get _handTool() {
  4324. return (0, _pdfjsLib.shadow)(this, "_handTool", new _grab_to_pan.GrabToPan({
  4325. element: this.container
  4326. }));
  4327. }
  4328. }
  4329. exports.PDFCursorTools = PDFCursorTools;
  4330. /***/ }),
  4331. /* 14 */
  4332. /***/ ((__unused_webpack_module, exports) => {
  4333. Object.defineProperty(exports, "__esModule", ({
  4334. value: true
  4335. }));
  4336. exports.GrabToPan = void 0;
  4337. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  4338. class GrabToPan {
  4339. constructor({
  4340. element
  4341. }) {
  4342. this.element = element;
  4343. this.document = element.ownerDocument;
  4344. this.activate = this.activate.bind(this);
  4345. this.deactivate = this.deactivate.bind(this);
  4346. this.toggle = this.toggle.bind(this);
  4347. this._onMouseDown = this.#onMouseDown.bind(this);
  4348. this._onMouseMove = this.#onMouseMove.bind(this);
  4349. this._endPan = this.#endPan.bind(this);
  4350. const overlay = this.overlay = document.createElement("div");
  4351. overlay.className = "grab-to-pan-grabbing";
  4352. }
  4353. activate() {
  4354. if (!this.active) {
  4355. this.active = true;
  4356. this.element.addEventListener("mousedown", this._onMouseDown, true);
  4357. this.element.classList.add(CSS_CLASS_GRAB);
  4358. }
  4359. }
  4360. deactivate() {
  4361. if (this.active) {
  4362. this.active = false;
  4363. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  4364. this._endPan();
  4365. this.element.classList.remove(CSS_CLASS_GRAB);
  4366. }
  4367. }
  4368. toggle() {
  4369. if (this.active) {
  4370. this.deactivate();
  4371. } else {
  4372. this.activate();
  4373. }
  4374. }
  4375. ignoreTarget(node) {
  4376. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  4377. }
  4378. #onMouseDown(event) {
  4379. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  4380. return;
  4381. }
  4382. if (event.originalTarget) {
  4383. try {
  4384. event.originalTarget.tagName;
  4385. } catch {
  4386. return;
  4387. }
  4388. }
  4389. this.scrollLeftStart = this.element.scrollLeft;
  4390. this.scrollTopStart = this.element.scrollTop;
  4391. this.clientXStart = event.clientX;
  4392. this.clientYStart = event.clientY;
  4393. this.document.addEventListener("mousemove", this._onMouseMove, true);
  4394. this.document.addEventListener("mouseup", this._endPan, true);
  4395. this.element.addEventListener("scroll", this._endPan, true);
  4396. event.preventDefault();
  4397. event.stopPropagation();
  4398. const focusedElement = document.activeElement;
  4399. if (focusedElement && !focusedElement.contains(event.target)) {
  4400. focusedElement.blur();
  4401. }
  4402. }
  4403. #onMouseMove(event) {
  4404. this.element.removeEventListener("scroll", this._endPan, true);
  4405. if (!(event.buttons & 1)) {
  4406. this._endPan();
  4407. return;
  4408. }
  4409. const xDiff = event.clientX - this.clientXStart;
  4410. const yDiff = event.clientY - this.clientYStart;
  4411. this.element.scrollTo({
  4412. top: this.scrollTopStart - yDiff,
  4413. left: this.scrollLeftStart - xDiff,
  4414. behavior: "instant"
  4415. });
  4416. if (!this.overlay.parentNode) {
  4417. document.body.append(this.overlay);
  4418. }
  4419. }
  4420. #endPan() {
  4421. this.element.removeEventListener("scroll", this._endPan, true);
  4422. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  4423. this.document.removeEventListener("mouseup", this._endPan, true);
  4424. this.overlay.remove();
  4425. }
  4426. }
  4427. exports.GrabToPan = GrabToPan;
  4428. /***/ }),
  4429. /* 15 */
  4430. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4431. Object.defineProperty(exports, "__esModule", ({
  4432. value: true
  4433. }));
  4434. exports.PDFDocumentProperties = void 0;
  4435. var _ui_utils = __webpack_require__(3);
  4436. var _pdfjsLib = __webpack_require__(4);
  4437. const DEFAULT_FIELD_CONTENT = "-";
  4438. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4439. const US_PAGE_NAMES = {
  4440. "8.5x11": "Letter",
  4441. "8.5x14": "Legal"
  4442. };
  4443. const METRIC_PAGE_NAMES = {
  4444. "297x420": "A3",
  4445. "210x297": "A4"
  4446. };
  4447. function getPageName(size, isPortrait, pageNames) {
  4448. const width = isPortrait ? size.width : size.height;
  4449. const height = isPortrait ? size.height : size.width;
  4450. return pageNames[`${width}x${height}`];
  4451. }
  4452. class PDFDocumentProperties {
  4453. #fieldData = null;
  4454. constructor({
  4455. dialog,
  4456. fields,
  4457. closeButton
  4458. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4459. this.dialog = dialog;
  4460. this.fields = fields;
  4461. this.overlayManager = overlayManager;
  4462. this.l10n = l10n;
  4463. this._fileNameLookup = fileNameLookup;
  4464. this.#reset();
  4465. closeButton.addEventListener("click", this.close.bind(this));
  4466. this.overlayManager.register(this.dialog);
  4467. eventBus._on("pagechanging", evt => {
  4468. this._currentPageNumber = evt.pageNumber;
  4469. });
  4470. eventBus._on("rotationchanging", evt => {
  4471. this._pagesRotation = evt.pagesRotation;
  4472. });
  4473. this._isNonMetricLocale = true;
  4474. l10n.getLanguage().then(locale => {
  4475. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4476. });
  4477. }
  4478. async open() {
  4479. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4480. const currentPageNumber = this._currentPageNumber;
  4481. const pagesRotation = this._pagesRotation;
  4482. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4483. this.#updateUI();
  4484. return;
  4485. }
  4486. const {
  4487. info,
  4488. contentLength
  4489. } = await this.pdfDocument.getMetadata();
  4490. 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 => {
  4491. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4492. }), this.#parseLinearization(info.IsLinearized)]);
  4493. this.#fieldData = Object.freeze({
  4494. fileName,
  4495. fileSize,
  4496. title: info.Title,
  4497. author: info.Author,
  4498. subject: info.Subject,
  4499. keywords: info.Keywords,
  4500. creationDate,
  4501. modificationDate,
  4502. creator: info.Creator,
  4503. producer: info.Producer,
  4504. version: info.PDFFormatVersion,
  4505. pageCount: this.pdfDocument.numPages,
  4506. pageSize,
  4507. linearized: isLinearized,
  4508. _currentPageNumber: currentPageNumber,
  4509. _pagesRotation: pagesRotation
  4510. });
  4511. this.#updateUI();
  4512. const {
  4513. length
  4514. } = await this.pdfDocument.getDownloadInfo();
  4515. if (contentLength === length) {
  4516. return;
  4517. }
  4518. const data = Object.assign(Object.create(null), this.#fieldData);
  4519. data.fileSize = await this.#parseFileSize(length);
  4520. this.#fieldData = Object.freeze(data);
  4521. this.#updateUI();
  4522. }
  4523. async close() {
  4524. this.overlayManager.close(this.dialog);
  4525. }
  4526. setDocument(pdfDocument) {
  4527. if (this.pdfDocument) {
  4528. this.#reset();
  4529. this.#updateUI(true);
  4530. }
  4531. if (!pdfDocument) {
  4532. return;
  4533. }
  4534. this.pdfDocument = pdfDocument;
  4535. this._dataAvailableCapability.resolve();
  4536. }
  4537. #reset() {
  4538. this.pdfDocument = null;
  4539. this.#fieldData = null;
  4540. this._dataAvailableCapability = new _pdfjsLib.PromiseCapability();
  4541. this._currentPageNumber = 1;
  4542. this._pagesRotation = 0;
  4543. }
  4544. #updateUI(reset = false) {
  4545. if (reset || !this.#fieldData) {
  4546. for (const id in this.fields) {
  4547. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4548. }
  4549. return;
  4550. }
  4551. if (this.overlayManager.active !== this.dialog) {
  4552. return;
  4553. }
  4554. for (const id in this.fields) {
  4555. const content = this.#fieldData[id];
  4556. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4557. }
  4558. }
  4559. async #parseFileSize(fileSize = 0) {
  4560. const kb = fileSize / 1024,
  4561. mb = kb / 1024;
  4562. if (!kb) {
  4563. return undefined;
  4564. }
  4565. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4566. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4567. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4568. size_b: fileSize.toLocaleString()
  4569. });
  4570. }
  4571. async #parsePageSize(pageSizeInches, pagesRotation) {
  4572. if (!pageSizeInches) {
  4573. return undefined;
  4574. }
  4575. if (pagesRotation % 180 !== 0) {
  4576. pageSizeInches = {
  4577. width: pageSizeInches.height,
  4578. height: pageSizeInches.width
  4579. };
  4580. }
  4581. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4582. let sizeInches = {
  4583. width: Math.round(pageSizeInches.width * 100) / 100,
  4584. height: Math.round(pageSizeInches.height * 100) / 100
  4585. };
  4586. let sizeMillimeters = {
  4587. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4588. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4589. };
  4590. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4591. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4592. const exactMillimeters = {
  4593. width: pageSizeInches.width * 25.4,
  4594. height: pageSizeInches.height * 25.4
  4595. };
  4596. const intMillimeters = {
  4597. width: Math.round(sizeMillimeters.width),
  4598. height: Math.round(sizeMillimeters.height)
  4599. };
  4600. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4601. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4602. if (rawName) {
  4603. sizeInches = {
  4604. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4605. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4606. };
  4607. sizeMillimeters = intMillimeters;
  4608. }
  4609. }
  4610. }
  4611. const [{
  4612. width,
  4613. height
  4614. }, 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"}`)]);
  4615. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4616. width: width.toLocaleString(),
  4617. height: height.toLocaleString(),
  4618. unit,
  4619. name,
  4620. orientation
  4621. });
  4622. }
  4623. async #parseDate(inputDate) {
  4624. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4625. if (!dateObject) {
  4626. return undefined;
  4627. }
  4628. return this.l10n.get("document_properties_date_string", {
  4629. date: dateObject.toLocaleDateString(),
  4630. time: dateObject.toLocaleTimeString()
  4631. });
  4632. }
  4633. #parseLinearization(isLinearized) {
  4634. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4635. }
  4636. }
  4637. exports.PDFDocumentProperties = PDFDocumentProperties;
  4638. /***/ }),
  4639. /* 16 */
  4640. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4641. Object.defineProperty(exports, "__esModule", ({
  4642. value: true
  4643. }));
  4644. exports.PDFFindBar = void 0;
  4645. var _pdf_find_controller = __webpack_require__(17);
  4646. var _ui_utils = __webpack_require__(3);
  4647. const MATCHES_COUNT_LIMIT = 1000;
  4648. class PDFFindBar {
  4649. constructor(options, eventBus, l10n) {
  4650. this.opened = false;
  4651. this.bar = options.bar;
  4652. this.toggleButton = options.toggleButton;
  4653. this.findField = options.findField;
  4654. this.highlightAll = options.highlightAllCheckbox;
  4655. this.caseSensitive = options.caseSensitiveCheckbox;
  4656. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4657. this.entireWord = options.entireWordCheckbox;
  4658. this.findMsg = options.findMsg;
  4659. this.findResultsCount = options.findResultsCount;
  4660. this.findPreviousButton = options.findPreviousButton;
  4661. this.findNextButton = options.findNextButton;
  4662. this.eventBus = eventBus;
  4663. this.l10n = l10n;
  4664. this.toggleButton.addEventListener("click", () => {
  4665. this.toggle();
  4666. });
  4667. this.findField.addEventListener("input", () => {
  4668. this.dispatchEvent("");
  4669. });
  4670. this.bar.addEventListener("keydown", e => {
  4671. switch (e.keyCode) {
  4672. case 13:
  4673. if (e.target === this.findField) {
  4674. this.dispatchEvent("again", e.shiftKey);
  4675. }
  4676. break;
  4677. case 27:
  4678. this.close();
  4679. break;
  4680. }
  4681. });
  4682. this.findPreviousButton.addEventListener("click", () => {
  4683. this.dispatchEvent("again", true);
  4684. });
  4685. this.findNextButton.addEventListener("click", () => {
  4686. this.dispatchEvent("again", false);
  4687. });
  4688. this.highlightAll.addEventListener("click", () => {
  4689. this.dispatchEvent("highlightallchange");
  4690. });
  4691. this.caseSensitive.addEventListener("click", () => {
  4692. this.dispatchEvent("casesensitivitychange");
  4693. });
  4694. this.entireWord.addEventListener("click", () => {
  4695. this.dispatchEvent("entirewordchange");
  4696. });
  4697. this.matchDiacritics.addEventListener("click", () => {
  4698. this.dispatchEvent("diacriticmatchingchange");
  4699. });
  4700. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4701. }
  4702. reset() {
  4703. this.updateUIState();
  4704. }
  4705. dispatchEvent(type, findPrev = false) {
  4706. this.eventBus.dispatch("find", {
  4707. source: this,
  4708. type,
  4709. query: this.findField.value,
  4710. caseSensitive: this.caseSensitive.checked,
  4711. entireWord: this.entireWord.checked,
  4712. highlightAll: this.highlightAll.checked,
  4713. findPrevious: findPrev,
  4714. matchDiacritics: this.matchDiacritics.checked
  4715. });
  4716. }
  4717. updateUIState(state, previous, matchesCount) {
  4718. let findMsg = Promise.resolve("");
  4719. let status = "";
  4720. switch (state) {
  4721. case _pdf_find_controller.FindState.FOUND:
  4722. break;
  4723. case _pdf_find_controller.FindState.PENDING:
  4724. status = "pending";
  4725. break;
  4726. case _pdf_find_controller.FindState.NOT_FOUND:
  4727. findMsg = this.l10n.get("find_not_found");
  4728. status = "notFound";
  4729. break;
  4730. case _pdf_find_controller.FindState.WRAPPED:
  4731. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4732. break;
  4733. }
  4734. this.findField.setAttribute("data-status", status);
  4735. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4736. findMsg.then(msg => {
  4737. this.findMsg.setAttribute("data-status", status);
  4738. this.findMsg.textContent = msg;
  4739. this.#adjustWidth();
  4740. });
  4741. this.updateResultsCount(matchesCount);
  4742. }
  4743. updateResultsCount({
  4744. current = 0,
  4745. total = 0
  4746. } = {}) {
  4747. const limit = MATCHES_COUNT_LIMIT;
  4748. let matchCountMsg = Promise.resolve("");
  4749. if (total > 0) {
  4750. if (total > limit) {
  4751. let key = "find_match_count_limit";
  4752. matchCountMsg = this.l10n.get(key, {
  4753. limit
  4754. });
  4755. } else {
  4756. let key = "find_match_count";
  4757. matchCountMsg = this.l10n.get(key, {
  4758. current,
  4759. total
  4760. });
  4761. }
  4762. }
  4763. matchCountMsg.then(msg => {
  4764. this.findResultsCount.textContent = msg;
  4765. this.#adjustWidth();
  4766. });
  4767. }
  4768. open() {
  4769. if (!this.opened) {
  4770. this.opened = true;
  4771. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true, this.bar);
  4772. }
  4773. this.findField.select();
  4774. this.findField.focus();
  4775. this.#adjustWidth();
  4776. }
  4777. close() {
  4778. if (!this.opened) {
  4779. return;
  4780. }
  4781. this.opened = false;
  4782. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false, this.bar);
  4783. this.eventBus.dispatch("findbarclose", {
  4784. source: this
  4785. });
  4786. }
  4787. toggle() {
  4788. if (this.opened) {
  4789. this.close();
  4790. } else {
  4791. this.open();
  4792. }
  4793. }
  4794. #adjustWidth() {
  4795. if (!this.opened) {
  4796. return;
  4797. }
  4798. this.bar.classList.remove("wrapContainers");
  4799. const findbarHeight = this.bar.clientHeight;
  4800. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4801. if (findbarHeight > inputContainerHeight) {
  4802. this.bar.classList.add("wrapContainers");
  4803. }
  4804. }
  4805. }
  4806. exports.PDFFindBar = PDFFindBar;
  4807. /***/ }),
  4808. /* 17 */
  4809. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4810. Object.defineProperty(exports, "__esModule", ({
  4811. value: true
  4812. }));
  4813. exports.PDFFindController = exports.FindState = void 0;
  4814. var _ui_utils = __webpack_require__(3);
  4815. var _pdf_find_utils = __webpack_require__(18);
  4816. var _pdfjsLib = __webpack_require__(4);
  4817. const FindState = {
  4818. FOUND: 0,
  4819. NOT_FOUND: 1,
  4820. WRAPPED: 2,
  4821. PENDING: 3
  4822. };
  4823. exports.FindState = FindState;
  4824. const FIND_TIMEOUT = 250;
  4825. const MATCH_SCROLL_OFFSET_TOP = -50;
  4826. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4827. const CHARACTERS_TO_NORMALIZE = {
  4828. "\u2010": "-",
  4829. "\u2018": "'",
  4830. "\u2019": "'",
  4831. "\u201A": "'",
  4832. "\u201B": "'",
  4833. "\u201C": '"',
  4834. "\u201D": '"',
  4835. "\u201E": '"',
  4836. "\u201F": '"',
  4837. "\u00BC": "1/4",
  4838. "\u00BD": "1/2",
  4839. "\u00BE": "3/4"
  4840. };
  4841. 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]);
  4842. let DIACRITICS_EXCEPTION_STR;
  4843. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4844. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4845. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4846. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4847. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4848. const SYLLABLES_LENGTHS = new Map();
  4849. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4850. const NFKC_CHARS_TO_NORMALIZE = new Map();
  4851. let noSyllablesRegExp = null;
  4852. let withSyllablesRegExp = null;
  4853. function normalize(text) {
  4854. const syllablePositions = [];
  4855. let m;
  4856. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4857. let {
  4858. index
  4859. } = m;
  4860. for (const char of m[0]) {
  4861. let len = SYLLABLES_LENGTHS.get(char);
  4862. if (!len) {
  4863. len = char.normalize("NFD").length;
  4864. SYLLABLES_LENGTHS.set(char, len);
  4865. }
  4866. syllablePositions.push([len, index++]);
  4867. }
  4868. }
  4869. let normalizationRegex;
  4870. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4871. normalizationRegex = noSyllablesRegExp;
  4872. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4873. normalizationRegex = withSyllablesRegExp;
  4874. } else {
  4875. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4876. const toNormalizeWithNFKC = (0, _pdf_find_utils.getNormalizeWithNFKC)();
  4877. const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
  4878. const HKDiacritics = "(?:\u3099|\u309A)";
  4879. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(${HKDiacritics}\\n)|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
  4880. if (syllablePositions.length === 0) {
  4881. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4882. } else {
  4883. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4884. }
  4885. }
  4886. const rawDiacriticsPositions = [];
  4887. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4888. rawDiacriticsPositions.push([m[0].length, m.index]);
  4889. }
  4890. let normalized = text.normalize("NFD");
  4891. const positions = [[0, 0]];
  4892. let rawDiacriticsIndex = 0;
  4893. let syllableIndex = 0;
  4894. let shift = 0;
  4895. let shiftOrigin = 0;
  4896. let eol = 0;
  4897. let hasDiacritics = false;
  4898. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, p8, i) => {
  4899. i -= shiftOrigin;
  4900. if (p1) {
  4901. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  4902. const jj = replacement.length;
  4903. for (let j = 1; j < jj; j++) {
  4904. positions.push([i - shift + j, shift - j]);
  4905. }
  4906. shift -= jj - 1;
  4907. return replacement;
  4908. }
  4909. if (p2) {
  4910. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  4911. if (!replacement) {
  4912. replacement = p2.normalize("NFKC");
  4913. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  4914. }
  4915. const jj = replacement.length;
  4916. for (let j = 1; j < jj; j++) {
  4917. positions.push([i - shift + j, shift - j]);
  4918. }
  4919. shift -= jj - 1;
  4920. return replacement;
  4921. }
  4922. if (p3) {
  4923. hasDiacritics = true;
  4924. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4925. ++rawDiacriticsIndex;
  4926. } else {
  4927. positions.push([i - 1 - shift + 1, shift - 1]);
  4928. shift -= 1;
  4929. shiftOrigin += 1;
  4930. }
  4931. positions.push([i - shift + 1, shift]);
  4932. shiftOrigin += 1;
  4933. eol += 1;
  4934. return p3.charAt(0);
  4935. }
  4936. if (p4) {
  4937. const hasTrailingDashEOL = p4.endsWith("\n");
  4938. const len = hasTrailingDashEOL ? p4.length - 2 : p4.length;
  4939. hasDiacritics = true;
  4940. let jj = len;
  4941. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4942. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4943. ++rawDiacriticsIndex;
  4944. }
  4945. for (let j = 1; j <= jj; j++) {
  4946. positions.push([i - 1 - shift + j, shift - j]);
  4947. }
  4948. shift -= jj;
  4949. shiftOrigin += jj;
  4950. if (hasTrailingDashEOL) {
  4951. i += len - 1;
  4952. positions.push([i - shift + 1, 1 + shift]);
  4953. shift += 1;
  4954. shiftOrigin += 1;
  4955. eol += 1;
  4956. return p4.slice(0, len);
  4957. }
  4958. return p4;
  4959. }
  4960. if (p5) {
  4961. const len = p5.length - 2;
  4962. positions.push([i - shift + len, 1 + shift]);
  4963. shift += 1;
  4964. shiftOrigin += 1;
  4965. eol += 1;
  4966. return p5.slice(0, -2);
  4967. }
  4968. if (p6) {
  4969. const len = p6.length - 1;
  4970. positions.push([i - shift + len, shift]);
  4971. shiftOrigin += 1;
  4972. eol += 1;
  4973. return p6.slice(0, -1);
  4974. }
  4975. if (p7) {
  4976. positions.push([i - shift + 1, shift - 1]);
  4977. shift -= 1;
  4978. shiftOrigin += 1;
  4979. eol += 1;
  4980. return " ";
  4981. }
  4982. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  4983. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  4984. ++syllableIndex;
  4985. for (let j = 1; j <= newCharLen; j++) {
  4986. positions.push([i - (shift - j), shift - j]);
  4987. }
  4988. shift -= newCharLen;
  4989. shiftOrigin += newCharLen;
  4990. }
  4991. return p8;
  4992. });
  4993. positions.push([normalized.length, shift]);
  4994. return [normalized, positions, hasDiacritics];
  4995. }
  4996. function getOriginalIndex(diffs, pos, len) {
  4997. if (!diffs) {
  4998. return [pos, len];
  4999. }
  5000. const start = pos;
  5001. const end = pos + len - 1;
  5002. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  5003. if (diffs[i][0] > start) {
  5004. --i;
  5005. }
  5006. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  5007. if (diffs[j][0] > end) {
  5008. --j;
  5009. }
  5010. const oldStart = start + diffs[i][1];
  5011. const oldEnd = end + diffs[j][1];
  5012. const oldLen = oldEnd + 1 - oldStart;
  5013. return [oldStart, oldLen];
  5014. }
  5015. class PDFFindController {
  5016. #state = null;
  5017. #updateMatchesCountOnProgress = true;
  5018. #visitedPagesCount = 0;
  5019. constructor({
  5020. linkService,
  5021. eventBus,
  5022. updateMatchesCountOnProgress = true
  5023. }) {
  5024. this._linkService = linkService;
  5025. this._eventBus = eventBus;
  5026. this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
  5027. this.onIsPageVisible = null;
  5028. this.#reset();
  5029. eventBus._on("find", this.#onFind.bind(this));
  5030. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  5031. }
  5032. get highlightMatches() {
  5033. return this._highlightMatches;
  5034. }
  5035. get pageMatches() {
  5036. return this._pageMatches;
  5037. }
  5038. get pageMatchesLength() {
  5039. return this._pageMatchesLength;
  5040. }
  5041. get selected() {
  5042. return this._selected;
  5043. }
  5044. get state() {
  5045. return this.#state;
  5046. }
  5047. setDocument(pdfDocument) {
  5048. if (this._pdfDocument) {
  5049. this.#reset();
  5050. }
  5051. if (!pdfDocument) {
  5052. return;
  5053. }
  5054. this._pdfDocument = pdfDocument;
  5055. this._firstPageCapability.resolve();
  5056. }
  5057. #onFind(state) {
  5058. if (!state) {
  5059. return;
  5060. }
  5061. if (state.phraseSearch === false) {
  5062. console.error("The `phraseSearch`-parameter was removed, please provide " + "an Array of strings in the `query`-parameter instead.");
  5063. if (typeof state.query === "string") {
  5064. state.query = state.query.match(/\S+/g);
  5065. }
  5066. }
  5067. const pdfDocument = this._pdfDocument;
  5068. const {
  5069. type
  5070. } = state;
  5071. if (this.#state === null || this.#shouldDirtyMatch(state)) {
  5072. this._dirtyMatch = true;
  5073. }
  5074. this.#state = state;
  5075. if (type !== "highlightallchange") {
  5076. this.#updateUIState(FindState.PENDING);
  5077. }
  5078. this._firstPageCapability.promise.then(() => {
  5079. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5080. return;
  5081. }
  5082. this.#extractText();
  5083. const findbarClosed = !this._highlightMatches;
  5084. const pendingTimeout = !!this._findTimeout;
  5085. if (this._findTimeout) {
  5086. clearTimeout(this._findTimeout);
  5087. this._findTimeout = null;
  5088. }
  5089. if (!type) {
  5090. this._findTimeout = setTimeout(() => {
  5091. this.#nextMatch();
  5092. this._findTimeout = null;
  5093. }, FIND_TIMEOUT);
  5094. } else if (this._dirtyMatch) {
  5095. this.#nextMatch();
  5096. } else if (type === "again") {
  5097. this.#nextMatch();
  5098. if (findbarClosed && this.#state.highlightAll) {
  5099. this.#updateAllPages();
  5100. }
  5101. } else if (type === "highlightallchange") {
  5102. if (pendingTimeout) {
  5103. this.#nextMatch();
  5104. } else {
  5105. this._highlightMatches = true;
  5106. }
  5107. this.#updateAllPages();
  5108. } else {
  5109. this.#nextMatch();
  5110. }
  5111. });
  5112. }
  5113. scrollMatchIntoView({
  5114. element = null,
  5115. selectedLeft = 0,
  5116. pageIndex = -1,
  5117. matchIndex = -1
  5118. }) {
  5119. if (!this._scrollMatches || !element) {
  5120. return;
  5121. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  5122. return;
  5123. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5124. return;
  5125. }
  5126. this._scrollMatches = false;
  5127. const spot = {
  5128. top: MATCH_SCROLL_OFFSET_TOP,
  5129. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  5130. };
  5131. (0, _ui_utils.scrollIntoView)(element, spot, true);
  5132. }
  5133. #reset() {
  5134. this._highlightMatches = false;
  5135. this._scrollMatches = false;
  5136. this._pdfDocument = null;
  5137. this._pageMatches = [];
  5138. this._pageMatchesLength = [];
  5139. this.#visitedPagesCount = 0;
  5140. this.#state = null;
  5141. this._selected = {
  5142. pageIdx: -1,
  5143. matchIdx: -1
  5144. };
  5145. this._offset = {
  5146. pageIdx: null,
  5147. matchIdx: null,
  5148. wrapped: false
  5149. };
  5150. this._extractTextPromises = [];
  5151. this._pageContents = [];
  5152. this._pageDiffs = [];
  5153. this._hasDiacritics = [];
  5154. this._matchesCountTotal = 0;
  5155. this._pagesToSearch = null;
  5156. this._pendingFindMatches = new Set();
  5157. this._resumePageIdx = null;
  5158. this._dirtyMatch = false;
  5159. clearTimeout(this._findTimeout);
  5160. this._findTimeout = null;
  5161. this._firstPageCapability = new _pdfjsLib.PromiseCapability();
  5162. }
  5163. get #query() {
  5164. const {
  5165. query
  5166. } = this.#state;
  5167. if (typeof query === "string") {
  5168. if (query !== this._rawQuery) {
  5169. this._rawQuery = query;
  5170. [this._normalizedQuery] = normalize(query);
  5171. }
  5172. return this._normalizedQuery;
  5173. }
  5174. return (query || []).filter(q => !!q).map(q => normalize(q)[0]);
  5175. }
  5176. #shouldDirtyMatch(state) {
  5177. const newQuery = state.query,
  5178. prevQuery = this.#state.query;
  5179. const newType = typeof newQuery,
  5180. prevType = typeof prevQuery;
  5181. if (newType !== prevType) {
  5182. return true;
  5183. }
  5184. if (newType === "string") {
  5185. if (newQuery !== prevQuery) {
  5186. return true;
  5187. }
  5188. } else if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) {
  5189. return true;
  5190. }
  5191. switch (state.type) {
  5192. case "again":
  5193. const pageNumber = this._selected.pageIdx + 1;
  5194. const linkService = this._linkService;
  5195. return pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !(this.onIsPageVisible?.(pageNumber) ?? true);
  5196. case "highlightallchange":
  5197. return false;
  5198. }
  5199. return true;
  5200. }
  5201. #isEntireWord(content, startIdx, length) {
  5202. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  5203. if (match) {
  5204. const first = content.charCodeAt(startIdx);
  5205. const limit = match[1].charCodeAt(0);
  5206. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5207. return false;
  5208. }
  5209. }
  5210. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  5211. if (match) {
  5212. const last = content.charCodeAt(startIdx + length - 1);
  5213. const limit = match[1].charCodeAt(0);
  5214. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5215. return false;
  5216. }
  5217. }
  5218. return true;
  5219. }
  5220. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  5221. const matches = this._pageMatches[pageIndex] = [];
  5222. const matchesLength = this._pageMatchesLength[pageIndex] = [];
  5223. if (!query) {
  5224. return;
  5225. }
  5226. const diffs = this._pageDiffs[pageIndex];
  5227. let match;
  5228. while ((match = query.exec(pageContent)) !== null) {
  5229. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  5230. continue;
  5231. }
  5232. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  5233. if (matchLen) {
  5234. matches.push(matchPos);
  5235. matchesLength.push(matchLen);
  5236. }
  5237. }
  5238. }
  5239. #convertToRegExpString(query, hasDiacritics) {
  5240. const {
  5241. matchDiacritics
  5242. } = this.#state;
  5243. let isUnicode = false;
  5244. query = query.replaceAll(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5245. if (p1) {
  5246. return `[ ]*\\${p1}[ ]*`;
  5247. }
  5248. if (p2) {
  5249. return `[ ]*${p2}[ ]*`;
  5250. }
  5251. if (p3) {
  5252. return "[ ]+";
  5253. }
  5254. if (matchDiacritics) {
  5255. return p4 || p5;
  5256. }
  5257. if (p4) {
  5258. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5259. }
  5260. if (hasDiacritics) {
  5261. isUnicode = true;
  5262. return `${p5}\\p{M}*`;
  5263. }
  5264. return p5;
  5265. });
  5266. const trailingSpaces = "[ ]*";
  5267. if (query.endsWith(trailingSpaces)) {
  5268. query = query.slice(0, query.length - trailingSpaces.length);
  5269. }
  5270. if (matchDiacritics) {
  5271. if (hasDiacritics) {
  5272. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
  5273. isUnicode = true;
  5274. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5275. }
  5276. }
  5277. return [isUnicode, query];
  5278. }
  5279. #calculateMatch(pageIndex) {
  5280. let query = this.#query;
  5281. if (query.length === 0) {
  5282. return;
  5283. }
  5284. const {
  5285. caseSensitive,
  5286. entireWord
  5287. } = this.#state;
  5288. const pageContent = this._pageContents[pageIndex];
  5289. const hasDiacritics = this._hasDiacritics[pageIndex];
  5290. let isUnicode = false;
  5291. if (typeof query === "string") {
  5292. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5293. } else {
  5294. query = query.sort().reverse().map(q => {
  5295. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5296. isUnicode ||= isUnicodePart;
  5297. return `(${queryPart})`;
  5298. }).join("|");
  5299. }
  5300. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5301. query = query ? new RegExp(query, flags) : null;
  5302. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  5303. if (this.#state.highlightAll) {
  5304. this.#updatePage(pageIndex);
  5305. }
  5306. if (this._resumePageIdx === pageIndex) {
  5307. this._resumePageIdx = null;
  5308. this.#nextPageMatch();
  5309. }
  5310. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5311. this._matchesCountTotal += pageMatchesCount;
  5312. if (this.#updateMatchesCountOnProgress) {
  5313. if (pageMatchesCount > 0) {
  5314. this.#updateUIResultsCount();
  5315. }
  5316. } else if (++this.#visitedPagesCount === this._linkService.pagesCount) {
  5317. this.#updateUIResultsCount();
  5318. }
  5319. }
  5320. #extractText() {
  5321. if (this._extractTextPromises.length > 0) {
  5322. return;
  5323. }
  5324. let promise = Promise.resolve();
  5325. const textOptions = {
  5326. disableNormalization: true
  5327. };
  5328. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5329. const extractTextCapability = new _pdfjsLib.PromiseCapability();
  5330. this._extractTextPromises[i] = extractTextCapability.promise;
  5331. promise = promise.then(() => {
  5332. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5333. return pdfPage.getTextContent(textOptions);
  5334. }).then(textContent => {
  5335. const strBuf = [];
  5336. for (const textItem of textContent.items) {
  5337. strBuf.push(textItem.str);
  5338. if (textItem.hasEOL) {
  5339. strBuf.push("\n");
  5340. }
  5341. }
  5342. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5343. extractTextCapability.resolve();
  5344. }, reason => {
  5345. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5346. this._pageContents[i] = "";
  5347. this._pageDiffs[i] = null;
  5348. this._hasDiacritics[i] = false;
  5349. extractTextCapability.resolve();
  5350. });
  5351. });
  5352. }
  5353. }
  5354. #updatePage(index) {
  5355. if (this._scrollMatches && this._selected.pageIdx === index) {
  5356. this._linkService.page = index + 1;
  5357. }
  5358. this._eventBus.dispatch("updatetextlayermatches", {
  5359. source: this,
  5360. pageIndex: index
  5361. });
  5362. }
  5363. #updateAllPages() {
  5364. this._eventBus.dispatch("updatetextlayermatches", {
  5365. source: this,
  5366. pageIndex: -1
  5367. });
  5368. }
  5369. #nextMatch() {
  5370. const previous = this.#state.findPrevious;
  5371. const currentPageIndex = this._linkService.page - 1;
  5372. const numPages = this._linkService.pagesCount;
  5373. this._highlightMatches = true;
  5374. if (this._dirtyMatch) {
  5375. this._dirtyMatch = false;
  5376. this._selected.pageIdx = this._selected.matchIdx = -1;
  5377. this._offset.pageIdx = currentPageIndex;
  5378. this._offset.matchIdx = null;
  5379. this._offset.wrapped = false;
  5380. this._resumePageIdx = null;
  5381. this._pageMatches.length = 0;
  5382. this._pageMatchesLength.length = 0;
  5383. this.#visitedPagesCount = 0;
  5384. this._matchesCountTotal = 0;
  5385. this.#updateAllPages();
  5386. for (let i = 0; i < numPages; i++) {
  5387. if (this._pendingFindMatches.has(i)) {
  5388. continue;
  5389. }
  5390. this._pendingFindMatches.add(i);
  5391. this._extractTextPromises[i].then(() => {
  5392. this._pendingFindMatches.delete(i);
  5393. this.#calculateMatch(i);
  5394. });
  5395. }
  5396. }
  5397. const query = this.#query;
  5398. if (query.length === 0) {
  5399. this.#updateUIState(FindState.FOUND);
  5400. return;
  5401. }
  5402. if (this._resumePageIdx) {
  5403. return;
  5404. }
  5405. const offset = this._offset;
  5406. this._pagesToSearch = numPages;
  5407. if (offset.matchIdx !== null) {
  5408. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5409. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5410. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5411. this.#updateMatch(true);
  5412. return;
  5413. }
  5414. this.#advanceOffsetPage(previous);
  5415. }
  5416. this.#nextPageMatch();
  5417. }
  5418. #matchesReady(matches) {
  5419. const offset = this._offset;
  5420. const numMatches = matches.length;
  5421. const previous = this.#state.findPrevious;
  5422. if (numMatches) {
  5423. offset.matchIdx = previous ? numMatches - 1 : 0;
  5424. this.#updateMatch(true);
  5425. return true;
  5426. }
  5427. this.#advanceOffsetPage(previous);
  5428. if (offset.wrapped) {
  5429. offset.matchIdx = null;
  5430. if (this._pagesToSearch < 0) {
  5431. this.#updateMatch(false);
  5432. return true;
  5433. }
  5434. }
  5435. return false;
  5436. }
  5437. #nextPageMatch() {
  5438. if (this._resumePageIdx !== null) {
  5439. console.error("There can only be one pending page.");
  5440. }
  5441. let matches = null;
  5442. do {
  5443. const pageIdx = this._offset.pageIdx;
  5444. matches = this._pageMatches[pageIdx];
  5445. if (!matches) {
  5446. this._resumePageIdx = pageIdx;
  5447. break;
  5448. }
  5449. } while (!this.#matchesReady(matches));
  5450. }
  5451. #advanceOffsetPage(previous) {
  5452. const offset = this._offset;
  5453. const numPages = this._linkService.pagesCount;
  5454. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5455. offset.matchIdx = null;
  5456. this._pagesToSearch--;
  5457. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5458. offset.pageIdx = previous ? numPages - 1 : 0;
  5459. offset.wrapped = true;
  5460. }
  5461. }
  5462. #updateMatch(found = false) {
  5463. let state = FindState.NOT_FOUND;
  5464. const wrapped = this._offset.wrapped;
  5465. this._offset.wrapped = false;
  5466. if (found) {
  5467. const previousPage = this._selected.pageIdx;
  5468. this._selected.pageIdx = this._offset.pageIdx;
  5469. this._selected.matchIdx = this._offset.matchIdx;
  5470. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5471. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5472. this.#updatePage(previousPage);
  5473. }
  5474. }
  5475. this.#updateUIState(state, this.#state.findPrevious);
  5476. if (this._selected.pageIdx !== -1) {
  5477. this._scrollMatches = true;
  5478. this.#updatePage(this._selected.pageIdx);
  5479. }
  5480. }
  5481. #onFindBarClose(evt) {
  5482. const pdfDocument = this._pdfDocument;
  5483. this._firstPageCapability.promise.then(() => {
  5484. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5485. return;
  5486. }
  5487. if (this._findTimeout) {
  5488. clearTimeout(this._findTimeout);
  5489. this._findTimeout = null;
  5490. }
  5491. if (this._resumePageIdx) {
  5492. this._resumePageIdx = null;
  5493. this._dirtyMatch = true;
  5494. }
  5495. this.#updateUIState(FindState.FOUND);
  5496. this._highlightMatches = false;
  5497. this.#updateAllPages();
  5498. });
  5499. }
  5500. #requestMatchesCount() {
  5501. const {
  5502. pageIdx,
  5503. matchIdx
  5504. } = this._selected;
  5505. let current = 0,
  5506. total = this._matchesCountTotal;
  5507. if (matchIdx !== -1) {
  5508. for (let i = 0; i < pageIdx; i++) {
  5509. current += this._pageMatches[i]?.length || 0;
  5510. }
  5511. current += matchIdx + 1;
  5512. }
  5513. if (current < 1 || current > total) {
  5514. current = total = 0;
  5515. }
  5516. return {
  5517. current,
  5518. total
  5519. };
  5520. }
  5521. #updateUIResultsCount() {
  5522. this._eventBus.dispatch("updatefindmatchescount", {
  5523. source: this,
  5524. matchesCount: this.#requestMatchesCount()
  5525. });
  5526. }
  5527. #updateUIState(state, previous = false) {
  5528. if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) {
  5529. return;
  5530. }
  5531. this._eventBus.dispatch("updatefindcontrolstate", {
  5532. source: this,
  5533. state,
  5534. previous,
  5535. matchesCount: this.#requestMatchesCount(),
  5536. rawQuery: this.#state?.query ?? null
  5537. });
  5538. }
  5539. }
  5540. exports.PDFFindController = PDFFindController;
  5541. /***/ }),
  5542. /* 18 */
  5543. /***/ ((__unused_webpack_module, exports) => {
  5544. Object.defineProperty(exports, "__esModule", ({
  5545. value: true
  5546. }));
  5547. exports.CharacterType = void 0;
  5548. exports.getCharacterType = getCharacterType;
  5549. exports.getNormalizeWithNFKC = getNormalizeWithNFKC;
  5550. const CharacterType = {
  5551. SPACE: 0,
  5552. ALPHA_LETTER: 1,
  5553. PUNCT: 2,
  5554. HAN_LETTER: 3,
  5555. KATAKANA_LETTER: 4,
  5556. HIRAGANA_LETTER: 5,
  5557. HALFWIDTH_KATAKANA_LETTER: 6,
  5558. THAI_LETTER: 7
  5559. };
  5560. exports.CharacterType = CharacterType;
  5561. function isAlphabeticalScript(charCode) {
  5562. return charCode < 0x2e80;
  5563. }
  5564. function isAscii(charCode) {
  5565. return (charCode & 0xff80) === 0;
  5566. }
  5567. function isAsciiAlpha(charCode) {
  5568. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5569. }
  5570. function isAsciiDigit(charCode) {
  5571. return charCode >= 0x30 && charCode <= 0x39;
  5572. }
  5573. function isAsciiSpace(charCode) {
  5574. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5575. }
  5576. function isHan(charCode) {
  5577. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5578. }
  5579. function isKatakana(charCode) {
  5580. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5581. }
  5582. function isHiragana(charCode) {
  5583. return charCode >= 0x3040 && charCode <= 0x309f;
  5584. }
  5585. function isHalfwidthKatakana(charCode) {
  5586. return charCode >= 0xff60 && charCode <= 0xff9f;
  5587. }
  5588. function isThai(charCode) {
  5589. return (charCode & 0xff80) === 0x0e00;
  5590. }
  5591. function getCharacterType(charCode) {
  5592. if (isAlphabeticalScript(charCode)) {
  5593. if (isAscii(charCode)) {
  5594. if (isAsciiSpace(charCode)) {
  5595. return CharacterType.SPACE;
  5596. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5597. return CharacterType.ALPHA_LETTER;
  5598. }
  5599. return CharacterType.PUNCT;
  5600. } else if (isThai(charCode)) {
  5601. return CharacterType.THAI_LETTER;
  5602. } else if (charCode === 0xa0) {
  5603. return CharacterType.SPACE;
  5604. }
  5605. return CharacterType.ALPHA_LETTER;
  5606. }
  5607. if (isHan(charCode)) {
  5608. return CharacterType.HAN_LETTER;
  5609. } else if (isKatakana(charCode)) {
  5610. return CharacterType.KATAKANA_LETTER;
  5611. } else if (isHiragana(charCode)) {
  5612. return CharacterType.HIRAGANA_LETTER;
  5613. } else if (isHalfwidthKatakana(charCode)) {
  5614. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5615. }
  5616. return CharacterType.ALPHA_LETTER;
  5617. }
  5618. let NormalizeWithNFKC;
  5619. function getNormalizeWithNFKC() {
  5620. NormalizeWithNFKC ||= ` ¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰꟲ-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`;
  5621. return NormalizeWithNFKC;
  5622. }
  5623. /***/ }),
  5624. /* 19 */
  5625. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5626. Object.defineProperty(exports, "__esModule", ({
  5627. value: true
  5628. }));
  5629. exports.PDFHistory = void 0;
  5630. exports.isDestArraysEqual = isDestArraysEqual;
  5631. exports.isDestHashesEqual = isDestHashesEqual;
  5632. var _ui_utils = __webpack_require__(3);
  5633. var _event_utils = __webpack_require__(6);
  5634. const HASH_CHANGE_TIMEOUT = 1000;
  5635. const POSITION_UPDATED_THRESHOLD = 50;
  5636. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5637. function getCurrentHash() {
  5638. return document.location.hash;
  5639. }
  5640. class PDFHistory {
  5641. constructor({
  5642. linkService,
  5643. eventBus
  5644. }) {
  5645. this.linkService = linkService;
  5646. this.eventBus = eventBus;
  5647. this._initialized = false;
  5648. this._fingerprint = "";
  5649. this.reset();
  5650. this._boundEvents = null;
  5651. this.eventBus._on("pagesinit", () => {
  5652. this._isPagesLoaded = false;
  5653. this.eventBus._on("pagesloaded", evt => {
  5654. this._isPagesLoaded = !!evt.pagesCount;
  5655. }, {
  5656. once: true
  5657. });
  5658. });
  5659. }
  5660. initialize({
  5661. fingerprint,
  5662. resetHistory = false,
  5663. updateUrl = false
  5664. }) {
  5665. if (!fingerprint || typeof fingerprint !== "string") {
  5666. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5667. return;
  5668. }
  5669. if (this._initialized) {
  5670. this.reset();
  5671. }
  5672. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5673. this._fingerprint = fingerprint;
  5674. this._updateUrl = updateUrl === true;
  5675. this._initialized = true;
  5676. this._bindEvents();
  5677. const state = window.history.state;
  5678. this._popStateInProgress = false;
  5679. this._blockHashChange = 0;
  5680. this._currentHash = getCurrentHash();
  5681. this._numPositionUpdates = 0;
  5682. this._uid = this._maxUid = 0;
  5683. this._destination = null;
  5684. this._position = null;
  5685. if (!this._isValidState(state, true) || resetHistory) {
  5686. const {
  5687. hash,
  5688. page,
  5689. rotation
  5690. } = this._parseCurrentHash(true);
  5691. if (!hash || reInitialized || resetHistory) {
  5692. this._pushOrReplaceState(null, true);
  5693. return;
  5694. }
  5695. this._pushOrReplaceState({
  5696. hash,
  5697. page,
  5698. rotation
  5699. }, true);
  5700. return;
  5701. }
  5702. const destination = state.destination;
  5703. this._updateInternalState(destination, state.uid, true);
  5704. if (destination.rotation !== undefined) {
  5705. this._initialRotation = destination.rotation;
  5706. }
  5707. if (destination.dest) {
  5708. this._initialBookmark = JSON.stringify(destination.dest);
  5709. this._destination.page = null;
  5710. } else if (destination.hash) {
  5711. this._initialBookmark = destination.hash;
  5712. } else if (destination.page) {
  5713. this._initialBookmark = `page=${destination.page}`;
  5714. }
  5715. }
  5716. reset() {
  5717. if (this._initialized) {
  5718. this._pageHide();
  5719. this._initialized = false;
  5720. this._unbindEvents();
  5721. }
  5722. if (this._updateViewareaTimeout) {
  5723. clearTimeout(this._updateViewareaTimeout);
  5724. this._updateViewareaTimeout = null;
  5725. }
  5726. this._initialBookmark = null;
  5727. this._initialRotation = null;
  5728. }
  5729. push({
  5730. namedDest = null,
  5731. explicitDest,
  5732. pageNumber
  5733. }) {
  5734. if (!this._initialized) {
  5735. return;
  5736. }
  5737. if (namedDest && typeof namedDest !== "string") {
  5738. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5739. return;
  5740. } else if (!Array.isArray(explicitDest)) {
  5741. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5742. return;
  5743. } else if (!this._isValidPage(pageNumber)) {
  5744. if (pageNumber !== null || this._destination) {
  5745. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5746. return;
  5747. }
  5748. }
  5749. const hash = namedDest || JSON.stringify(explicitDest);
  5750. if (!hash) {
  5751. return;
  5752. }
  5753. let forceReplace = false;
  5754. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5755. if (this._destination.page) {
  5756. return;
  5757. }
  5758. forceReplace = true;
  5759. }
  5760. if (this._popStateInProgress && !forceReplace) {
  5761. return;
  5762. }
  5763. this._pushOrReplaceState({
  5764. dest: explicitDest,
  5765. hash,
  5766. page: pageNumber,
  5767. rotation: this.linkService.rotation
  5768. }, forceReplace);
  5769. if (!this._popStateInProgress) {
  5770. this._popStateInProgress = true;
  5771. Promise.resolve().then(() => {
  5772. this._popStateInProgress = false;
  5773. });
  5774. }
  5775. }
  5776. pushPage(pageNumber) {
  5777. if (!this._initialized) {
  5778. return;
  5779. }
  5780. if (!this._isValidPage(pageNumber)) {
  5781. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5782. return;
  5783. }
  5784. if (this._destination?.page === pageNumber) {
  5785. return;
  5786. }
  5787. if (this._popStateInProgress) {
  5788. return;
  5789. }
  5790. this._pushOrReplaceState({
  5791. dest: null,
  5792. hash: `page=${pageNumber}`,
  5793. page: pageNumber,
  5794. rotation: this.linkService.rotation
  5795. });
  5796. if (!this._popStateInProgress) {
  5797. this._popStateInProgress = true;
  5798. Promise.resolve().then(() => {
  5799. this._popStateInProgress = false;
  5800. });
  5801. }
  5802. }
  5803. pushCurrentPosition() {
  5804. if (!this._initialized || this._popStateInProgress) {
  5805. return;
  5806. }
  5807. this._tryPushCurrentPosition();
  5808. }
  5809. back() {
  5810. if (!this._initialized || this._popStateInProgress) {
  5811. return;
  5812. }
  5813. const state = window.history.state;
  5814. if (this._isValidState(state) && state.uid > 0) {
  5815. window.history.back();
  5816. }
  5817. }
  5818. forward() {
  5819. if (!this._initialized || this._popStateInProgress) {
  5820. return;
  5821. }
  5822. const state = window.history.state;
  5823. if (this._isValidState(state) && state.uid < this._maxUid) {
  5824. window.history.forward();
  5825. }
  5826. }
  5827. get popStateInProgress() {
  5828. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5829. }
  5830. get initialBookmark() {
  5831. return this._initialized ? this._initialBookmark : null;
  5832. }
  5833. get initialRotation() {
  5834. return this._initialized ? this._initialRotation : null;
  5835. }
  5836. _pushOrReplaceState(destination, forceReplace = false) {
  5837. const shouldReplace = forceReplace || !this._destination;
  5838. const newState = {
  5839. fingerprint: this._fingerprint,
  5840. uid: shouldReplace ? this._uid : this._uid + 1,
  5841. destination
  5842. };
  5843. this._updateInternalState(destination, newState.uid);
  5844. let newUrl;
  5845. if (this._updateUrl && destination?.hash) {
  5846. const baseUrl = document.location.href.split("#")[0];
  5847. if (!baseUrl.startsWith("file://")) {
  5848. newUrl = `${baseUrl}#${destination.hash}`;
  5849. }
  5850. }
  5851. if (shouldReplace) {
  5852. window.history.replaceState(newState, "", newUrl);
  5853. } else {
  5854. window.history.pushState(newState, "", newUrl);
  5855. }
  5856. }
  5857. _tryPushCurrentPosition(temporary = false) {
  5858. if (!this._position) {
  5859. return;
  5860. }
  5861. let position = this._position;
  5862. if (temporary) {
  5863. position = Object.assign(Object.create(null), this._position);
  5864. position.temporary = true;
  5865. }
  5866. if (!this._destination) {
  5867. this._pushOrReplaceState(position);
  5868. return;
  5869. }
  5870. if (this._destination.temporary) {
  5871. this._pushOrReplaceState(position, true);
  5872. return;
  5873. }
  5874. if (this._destination.hash === position.hash) {
  5875. return;
  5876. }
  5877. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5878. return;
  5879. }
  5880. let forceReplace = false;
  5881. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5882. if (this._destination.dest !== undefined || !this._destination.first) {
  5883. return;
  5884. }
  5885. forceReplace = true;
  5886. }
  5887. this._pushOrReplaceState(position, forceReplace);
  5888. }
  5889. _isValidPage(val) {
  5890. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5891. }
  5892. _isValidState(state, checkReload = false) {
  5893. if (!state) {
  5894. return false;
  5895. }
  5896. if (state.fingerprint !== this._fingerprint) {
  5897. if (checkReload) {
  5898. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5899. return false;
  5900. }
  5901. const [perfEntry] = performance.getEntriesByType("navigation");
  5902. if (perfEntry?.type !== "reload") {
  5903. return false;
  5904. }
  5905. } else {
  5906. return false;
  5907. }
  5908. }
  5909. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5910. return false;
  5911. }
  5912. if (state.destination === null || typeof state.destination !== "object") {
  5913. return false;
  5914. }
  5915. return true;
  5916. }
  5917. _updateInternalState(destination, uid, removeTemporary = false) {
  5918. if (this._updateViewareaTimeout) {
  5919. clearTimeout(this._updateViewareaTimeout);
  5920. this._updateViewareaTimeout = null;
  5921. }
  5922. if (removeTemporary && destination?.temporary) {
  5923. delete destination.temporary;
  5924. }
  5925. this._destination = destination;
  5926. this._uid = uid;
  5927. this._maxUid = Math.max(this._maxUid, uid);
  5928. this._numPositionUpdates = 0;
  5929. }
  5930. _parseCurrentHash(checkNameddest = false) {
  5931. const hash = unescape(getCurrentHash()).substring(1);
  5932. const params = (0, _ui_utils.parseQueryString)(hash);
  5933. const nameddest = params.get("nameddest") || "";
  5934. let page = params.get("page") | 0;
  5935. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5936. page = null;
  5937. }
  5938. return {
  5939. hash,
  5940. page,
  5941. rotation: this.linkService.rotation
  5942. };
  5943. }
  5944. _updateViewarea({
  5945. location
  5946. }) {
  5947. if (this._updateViewareaTimeout) {
  5948. clearTimeout(this._updateViewareaTimeout);
  5949. this._updateViewareaTimeout = null;
  5950. }
  5951. this._position = {
  5952. hash: location.pdfOpenParams.substring(1),
  5953. page: this.linkService.page,
  5954. first: location.pageNumber,
  5955. rotation: location.rotation
  5956. };
  5957. if (this._popStateInProgress) {
  5958. return;
  5959. }
  5960. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5961. this._numPositionUpdates++;
  5962. }
  5963. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5964. this._updateViewareaTimeout = setTimeout(() => {
  5965. if (!this._popStateInProgress) {
  5966. this._tryPushCurrentPosition(true);
  5967. }
  5968. this._updateViewareaTimeout = null;
  5969. }, UPDATE_VIEWAREA_TIMEOUT);
  5970. }
  5971. }
  5972. _popState({
  5973. state
  5974. }) {
  5975. const newHash = getCurrentHash(),
  5976. hashChanged = this._currentHash !== newHash;
  5977. this._currentHash = newHash;
  5978. if (!state) {
  5979. this._uid++;
  5980. const {
  5981. hash,
  5982. page,
  5983. rotation
  5984. } = this._parseCurrentHash();
  5985. this._pushOrReplaceState({
  5986. hash,
  5987. page,
  5988. rotation
  5989. }, true);
  5990. return;
  5991. }
  5992. if (!this._isValidState(state)) {
  5993. return;
  5994. }
  5995. this._popStateInProgress = true;
  5996. if (hashChanged) {
  5997. this._blockHashChange++;
  5998. (0, _event_utils.waitOnEventOrTimeout)({
  5999. target: window,
  6000. name: "hashchange",
  6001. delay: HASH_CHANGE_TIMEOUT
  6002. }).then(() => {
  6003. this._blockHashChange--;
  6004. });
  6005. }
  6006. const destination = state.destination;
  6007. this._updateInternalState(destination, state.uid, true);
  6008. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  6009. this.linkService.rotation = destination.rotation;
  6010. }
  6011. if (destination.dest) {
  6012. this.linkService.goToDestination(destination.dest);
  6013. } else if (destination.hash) {
  6014. this.linkService.setHash(destination.hash);
  6015. } else if (destination.page) {
  6016. this.linkService.page = destination.page;
  6017. }
  6018. Promise.resolve().then(() => {
  6019. this._popStateInProgress = false;
  6020. });
  6021. }
  6022. _pageHide() {
  6023. if (!this._destination || this._destination.temporary) {
  6024. this._tryPushCurrentPosition();
  6025. }
  6026. }
  6027. _bindEvents() {
  6028. if (this._boundEvents) {
  6029. return;
  6030. }
  6031. this._boundEvents = {
  6032. updateViewarea: this._updateViewarea.bind(this),
  6033. popState: this._popState.bind(this),
  6034. pageHide: this._pageHide.bind(this)
  6035. };
  6036. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  6037. window.addEventListener("popstate", this._boundEvents.popState);
  6038. window.addEventListener("pagehide", this._boundEvents.pageHide);
  6039. }
  6040. _unbindEvents() {
  6041. if (!this._boundEvents) {
  6042. return;
  6043. }
  6044. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  6045. window.removeEventListener("popstate", this._boundEvents.popState);
  6046. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  6047. this._boundEvents = null;
  6048. }
  6049. }
  6050. exports.PDFHistory = PDFHistory;
  6051. function isDestHashesEqual(destHash, pushHash) {
  6052. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  6053. return false;
  6054. }
  6055. if (destHash === pushHash) {
  6056. return true;
  6057. }
  6058. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  6059. if (nameddest === pushHash) {
  6060. return true;
  6061. }
  6062. return false;
  6063. }
  6064. function isDestArraysEqual(firstDest, secondDest) {
  6065. function isEntryEqual(first, second) {
  6066. if (typeof first !== typeof second) {
  6067. return false;
  6068. }
  6069. if (Array.isArray(first) || Array.isArray(second)) {
  6070. return false;
  6071. }
  6072. if (first !== null && typeof first === "object" && second !== null) {
  6073. if (Object.keys(first).length !== Object.keys(second).length) {
  6074. return false;
  6075. }
  6076. for (const key in first) {
  6077. if (!isEntryEqual(first[key], second[key])) {
  6078. return false;
  6079. }
  6080. }
  6081. return true;
  6082. }
  6083. return first === second || Number.isNaN(first) && Number.isNaN(second);
  6084. }
  6085. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  6086. return false;
  6087. }
  6088. if (firstDest.length !== secondDest.length) {
  6089. return false;
  6090. }
  6091. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  6092. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  6093. return false;
  6094. }
  6095. }
  6096. return true;
  6097. }
  6098. /***/ }),
  6099. /* 20 */
  6100. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6101. Object.defineProperty(exports, "__esModule", ({
  6102. value: true
  6103. }));
  6104. exports.PDFLayerViewer = void 0;
  6105. var _base_tree_viewer = __webpack_require__(12);
  6106. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  6107. constructor(options) {
  6108. super(options);
  6109. this.l10n = options.l10n;
  6110. this.eventBus._on("optionalcontentconfigchanged", evt => {
  6111. this.#updateLayers(evt.promise);
  6112. });
  6113. this.eventBus._on("resetlayers", () => {
  6114. this.#updateLayers();
  6115. });
  6116. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  6117. }
  6118. reset() {
  6119. super.reset();
  6120. this._optionalContentConfig = null;
  6121. this._optionalContentHash = null;
  6122. }
  6123. _dispatchEvent(layersCount) {
  6124. this.eventBus.dispatch("layersloaded", {
  6125. source: this,
  6126. layersCount
  6127. });
  6128. }
  6129. _bindLink(element, {
  6130. groupId,
  6131. input
  6132. }) {
  6133. const setVisibility = () => {
  6134. this._optionalContentConfig.setVisibility(groupId, input.checked);
  6135. this._optionalContentHash = this._optionalContentConfig.getHash();
  6136. this.eventBus.dispatch("optionalcontentconfig", {
  6137. source: this,
  6138. promise: Promise.resolve(this._optionalContentConfig)
  6139. });
  6140. };
  6141. element.onclick = evt => {
  6142. if (evt.target === input) {
  6143. setVisibility();
  6144. return true;
  6145. } else if (evt.target !== element) {
  6146. return true;
  6147. }
  6148. input.checked = !input.checked;
  6149. setVisibility();
  6150. return false;
  6151. };
  6152. }
  6153. async _setNestedName(element, {
  6154. name = null
  6155. }) {
  6156. if (typeof name === "string") {
  6157. element.textContent = this._normalizeTextContent(name);
  6158. return;
  6159. }
  6160. element.textContent = await this.l10n.get("additional_layers");
  6161. element.style.fontStyle = "italic";
  6162. }
  6163. _addToggleButton(div, {
  6164. name = null
  6165. }) {
  6166. super._addToggleButton(div, name === null);
  6167. }
  6168. _toggleAllTreeItems() {
  6169. if (!this._optionalContentConfig) {
  6170. return;
  6171. }
  6172. super._toggleAllTreeItems();
  6173. }
  6174. render({
  6175. optionalContentConfig,
  6176. pdfDocument
  6177. }) {
  6178. if (this._optionalContentConfig) {
  6179. this.reset();
  6180. }
  6181. this._optionalContentConfig = optionalContentConfig || null;
  6182. this._pdfDocument = pdfDocument || null;
  6183. const groups = optionalContentConfig?.getOrder();
  6184. if (!groups) {
  6185. this._dispatchEvent(0);
  6186. return;
  6187. }
  6188. this._optionalContentHash = optionalContentConfig.getHash();
  6189. const fragment = document.createDocumentFragment(),
  6190. queue = [{
  6191. parent: fragment,
  6192. groups
  6193. }];
  6194. let layersCount = 0,
  6195. hasAnyNesting = false;
  6196. while (queue.length > 0) {
  6197. const levelData = queue.shift();
  6198. for (const groupId of levelData.groups) {
  6199. const div = document.createElement("div");
  6200. div.className = "treeItem";
  6201. const element = document.createElement("a");
  6202. div.append(element);
  6203. if (typeof groupId === "object") {
  6204. hasAnyNesting = true;
  6205. this._addToggleButton(div, groupId);
  6206. this._setNestedName(element, groupId);
  6207. const itemsDiv = document.createElement("div");
  6208. itemsDiv.className = "treeItems";
  6209. div.append(itemsDiv);
  6210. queue.push({
  6211. parent: itemsDiv,
  6212. groups: groupId.order
  6213. });
  6214. } else {
  6215. const group = optionalContentConfig.getGroup(groupId);
  6216. const input = document.createElement("input");
  6217. this._bindLink(element, {
  6218. groupId,
  6219. input
  6220. });
  6221. input.type = "checkbox";
  6222. input.checked = group.visible;
  6223. const label = document.createElement("label");
  6224. label.textContent = this._normalizeTextContent(group.name);
  6225. label.append(input);
  6226. element.append(label);
  6227. layersCount++;
  6228. }
  6229. levelData.parent.append(div);
  6230. }
  6231. }
  6232. this._finishRendering(fragment, layersCount, hasAnyNesting);
  6233. }
  6234. async #updateLayers(promise = null) {
  6235. if (!this._optionalContentConfig) {
  6236. return;
  6237. }
  6238. const pdfDocument = this._pdfDocument;
  6239. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig());
  6240. if (pdfDocument !== this._pdfDocument) {
  6241. return;
  6242. }
  6243. if (promise) {
  6244. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  6245. return;
  6246. }
  6247. } else {
  6248. this.eventBus.dispatch("optionalcontentconfig", {
  6249. source: this,
  6250. promise: Promise.resolve(optionalContentConfig)
  6251. });
  6252. }
  6253. this.render({
  6254. optionalContentConfig,
  6255. pdfDocument: this._pdfDocument
  6256. });
  6257. }
  6258. }
  6259. exports.PDFLayerViewer = PDFLayerViewer;
  6260. /***/ }),
  6261. /* 21 */
  6262. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6263. Object.defineProperty(exports, "__esModule", ({
  6264. value: true
  6265. }));
  6266. exports.PDFOutlineViewer = void 0;
  6267. var _base_tree_viewer = __webpack_require__(12);
  6268. var _pdfjsLib = __webpack_require__(4);
  6269. var _ui_utils = __webpack_require__(3);
  6270. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  6271. constructor(options) {
  6272. super(options);
  6273. this.linkService = options.linkService;
  6274. this.downloadManager = options.downloadManager;
  6275. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6276. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6277. this.eventBus._on("pagechanging", evt => {
  6278. this._currentPageNumber = evt.pageNumber;
  6279. });
  6280. this.eventBus._on("pagesloaded", evt => {
  6281. this._isPagesLoaded = !!evt.pagesCount;
  6282. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6283. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6284. }
  6285. });
  6286. this.eventBus._on("sidebarviewchanged", evt => {
  6287. this._sidebarView = evt.view;
  6288. });
  6289. }
  6290. reset() {
  6291. super.reset();
  6292. this._outline = null;
  6293. this._pageNumberToDestHashCapability = null;
  6294. this._currentPageNumber = 1;
  6295. this._isPagesLoaded = null;
  6296. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6297. this._currentOutlineItemCapability.resolve(false);
  6298. }
  6299. this._currentOutlineItemCapability = null;
  6300. }
  6301. _dispatchEvent(outlineCount) {
  6302. this._currentOutlineItemCapability = new _pdfjsLib.PromiseCapability();
  6303. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  6304. this._currentOutlineItemCapability.resolve(false);
  6305. } else if (this._isPagesLoaded !== null) {
  6306. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6307. }
  6308. this.eventBus.dispatch("outlineloaded", {
  6309. source: this,
  6310. outlineCount,
  6311. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6312. });
  6313. }
  6314. _bindLink(element, {
  6315. url,
  6316. newWindow,
  6317. action,
  6318. attachment,
  6319. dest,
  6320. setOCGState
  6321. }) {
  6322. const {
  6323. linkService
  6324. } = this;
  6325. if (url) {
  6326. linkService.addLinkAttributes(element, url, newWindow);
  6327. return;
  6328. }
  6329. if (action) {
  6330. element.href = linkService.getAnchorUrl("");
  6331. element.onclick = () => {
  6332. linkService.executeNamedAction(action);
  6333. return false;
  6334. };
  6335. return;
  6336. }
  6337. if (attachment) {
  6338. element.href = linkService.getAnchorUrl("");
  6339. element.onclick = () => {
  6340. this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename);
  6341. return false;
  6342. };
  6343. return;
  6344. }
  6345. if (setOCGState) {
  6346. element.href = linkService.getAnchorUrl("");
  6347. element.onclick = () => {
  6348. linkService.executeSetOCGState(setOCGState);
  6349. return false;
  6350. };
  6351. return;
  6352. }
  6353. element.href = linkService.getDestinationHash(dest);
  6354. element.onclick = evt => {
  6355. this._updateCurrentTreeItem(evt.target.parentNode);
  6356. if (dest) {
  6357. linkService.goToDestination(dest);
  6358. }
  6359. return false;
  6360. };
  6361. }
  6362. _setStyles(element, {
  6363. bold,
  6364. italic
  6365. }) {
  6366. if (bold) {
  6367. element.style.fontWeight = "bold";
  6368. }
  6369. if (italic) {
  6370. element.style.fontStyle = "italic";
  6371. }
  6372. }
  6373. _addToggleButton(div, {
  6374. count,
  6375. items
  6376. }) {
  6377. let hidden = false;
  6378. if (count < 0) {
  6379. let totalCount = items.length;
  6380. if (totalCount > 0) {
  6381. const queue = [...items];
  6382. while (queue.length > 0) {
  6383. const {
  6384. count: nestedCount,
  6385. items: nestedItems
  6386. } = queue.shift();
  6387. if (nestedCount > 0 && nestedItems.length > 0) {
  6388. totalCount += nestedItems.length;
  6389. queue.push(...nestedItems);
  6390. }
  6391. }
  6392. }
  6393. if (Math.abs(count) === totalCount) {
  6394. hidden = true;
  6395. }
  6396. }
  6397. super._addToggleButton(div, hidden);
  6398. }
  6399. _toggleAllTreeItems() {
  6400. if (!this._outline) {
  6401. return;
  6402. }
  6403. super._toggleAllTreeItems();
  6404. }
  6405. render({
  6406. outline,
  6407. pdfDocument
  6408. }) {
  6409. if (this._outline) {
  6410. this.reset();
  6411. }
  6412. this._outline = outline || null;
  6413. this._pdfDocument = pdfDocument || null;
  6414. if (!outline) {
  6415. this._dispatchEvent(0);
  6416. return;
  6417. }
  6418. const fragment = document.createDocumentFragment();
  6419. const queue = [{
  6420. parent: fragment,
  6421. items: outline
  6422. }];
  6423. let outlineCount = 0,
  6424. hasAnyNesting = false;
  6425. while (queue.length > 0) {
  6426. const levelData = queue.shift();
  6427. for (const item of levelData.items) {
  6428. const div = document.createElement("div");
  6429. div.className = "treeItem";
  6430. const element = document.createElement("a");
  6431. this._bindLink(element, item);
  6432. this._setStyles(element, item);
  6433. element.textContent = this._normalizeTextContent(item.title);
  6434. div.append(element);
  6435. if (item.items.length > 0) {
  6436. hasAnyNesting = true;
  6437. this._addToggleButton(div, item);
  6438. const itemsDiv = document.createElement("div");
  6439. itemsDiv.className = "treeItems";
  6440. div.append(itemsDiv);
  6441. queue.push({
  6442. parent: itemsDiv,
  6443. items: item.items
  6444. });
  6445. }
  6446. levelData.parent.append(div);
  6447. outlineCount++;
  6448. }
  6449. }
  6450. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6451. }
  6452. async _currentOutlineItem() {
  6453. if (!this._isPagesLoaded) {
  6454. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6455. }
  6456. if (!this._outline || !this._pdfDocument) {
  6457. return;
  6458. }
  6459. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6460. if (!pageNumberToDestHash) {
  6461. return;
  6462. }
  6463. this._updateCurrentTreeItem(null);
  6464. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6465. return;
  6466. }
  6467. for (let i = this._currentPageNumber; i > 0; i--) {
  6468. const destHash = pageNumberToDestHash.get(i);
  6469. if (!destHash) {
  6470. continue;
  6471. }
  6472. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6473. if (!linkElement) {
  6474. continue;
  6475. }
  6476. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6477. break;
  6478. }
  6479. }
  6480. async _getPageNumberToDestHash(pdfDocument) {
  6481. if (this._pageNumberToDestHashCapability) {
  6482. return this._pageNumberToDestHashCapability.promise;
  6483. }
  6484. this._pageNumberToDestHashCapability = new _pdfjsLib.PromiseCapability();
  6485. const pageNumberToDestHash = new Map(),
  6486. pageNumberNesting = new Map();
  6487. const queue = [{
  6488. nesting: 0,
  6489. items: this._outline
  6490. }];
  6491. while (queue.length > 0) {
  6492. const levelData = queue.shift(),
  6493. currentNesting = levelData.nesting;
  6494. for (const {
  6495. dest,
  6496. items
  6497. } of levelData.items) {
  6498. let explicitDest, pageNumber;
  6499. if (typeof dest === "string") {
  6500. explicitDest = await pdfDocument.getDestination(dest);
  6501. if (pdfDocument !== this._pdfDocument) {
  6502. return null;
  6503. }
  6504. } else {
  6505. explicitDest = dest;
  6506. }
  6507. if (Array.isArray(explicitDest)) {
  6508. const [destRef] = explicitDest;
  6509. if (typeof destRef === "object" && destRef !== null) {
  6510. pageNumber = this.linkService._cachedPageNumber(destRef);
  6511. if (!pageNumber) {
  6512. try {
  6513. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6514. if (pdfDocument !== this._pdfDocument) {
  6515. return null;
  6516. }
  6517. this.linkService.cachePageRef(pageNumber, destRef);
  6518. } catch {}
  6519. }
  6520. } else if (Number.isInteger(destRef)) {
  6521. pageNumber = destRef + 1;
  6522. }
  6523. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6524. const destHash = this.linkService.getDestinationHash(dest);
  6525. pageNumberToDestHash.set(pageNumber, destHash);
  6526. pageNumberNesting.set(pageNumber, currentNesting);
  6527. }
  6528. }
  6529. if (items.length > 0) {
  6530. queue.push({
  6531. nesting: currentNesting + 1,
  6532. items
  6533. });
  6534. }
  6535. }
  6536. }
  6537. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6538. return this._pageNumberToDestHashCapability.promise;
  6539. }
  6540. }
  6541. exports.PDFOutlineViewer = PDFOutlineViewer;
  6542. /***/ }),
  6543. /* 22 */
  6544. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6545. Object.defineProperty(exports, "__esModule", ({
  6546. value: true
  6547. }));
  6548. exports.PDFPresentationMode = void 0;
  6549. var _ui_utils = __webpack_require__(3);
  6550. var _pdfjsLib = __webpack_require__(4);
  6551. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6552. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6553. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6554. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6555. const PAGE_SWITCH_THRESHOLD = 0.1;
  6556. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6557. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6558. class PDFPresentationMode {
  6559. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6560. #args = null;
  6561. constructor({
  6562. container,
  6563. pdfViewer,
  6564. eventBus
  6565. }) {
  6566. this.container = container;
  6567. this.pdfViewer = pdfViewer;
  6568. this.eventBus = eventBus;
  6569. this.contextMenuOpen = false;
  6570. this.mouseScrollTimeStamp = 0;
  6571. this.mouseScrollDelta = 0;
  6572. this.touchSwipeState = null;
  6573. }
  6574. async request() {
  6575. const {
  6576. container,
  6577. pdfViewer
  6578. } = this;
  6579. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6580. return false;
  6581. }
  6582. this.#addFullscreenChangeListeners();
  6583. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6584. const promise = container.requestFullscreen();
  6585. this.#args = {
  6586. pageNumber: pdfViewer.currentPageNumber,
  6587. scaleValue: pdfViewer.currentScaleValue,
  6588. scrollMode: pdfViewer.scrollMode,
  6589. spreadMode: null,
  6590. annotationEditorMode: null
  6591. };
  6592. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6593. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6594. this.#args.spreadMode = pdfViewer.spreadMode;
  6595. }
  6596. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6597. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6598. }
  6599. try {
  6600. await promise;
  6601. pdfViewer.focus();
  6602. return true;
  6603. } catch {
  6604. this.#removeFullscreenChangeListeners();
  6605. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6606. }
  6607. return false;
  6608. }
  6609. get active() {
  6610. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6611. }
  6612. #mouseWheel(evt) {
  6613. if (!this.active) {
  6614. return;
  6615. }
  6616. evt.preventDefault();
  6617. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6618. const currentTime = Date.now();
  6619. const storedTime = this.mouseScrollTimeStamp;
  6620. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6621. return;
  6622. }
  6623. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6624. this.#resetMouseScrollState();
  6625. }
  6626. this.mouseScrollDelta += delta;
  6627. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6628. const totalDelta = this.mouseScrollDelta;
  6629. this.#resetMouseScrollState();
  6630. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6631. if (success) {
  6632. this.mouseScrollTimeStamp = currentTime;
  6633. }
  6634. }
  6635. }
  6636. #notifyStateChange(state) {
  6637. this.#state = state;
  6638. this.eventBus.dispatch("presentationmodechanged", {
  6639. source: this,
  6640. state
  6641. });
  6642. }
  6643. #enter() {
  6644. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6645. this.container.classList.add(ACTIVE_SELECTOR);
  6646. setTimeout(() => {
  6647. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6648. if (this.#args.spreadMode !== null) {
  6649. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6650. }
  6651. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6652. this.pdfViewer.currentScaleValue = "page-fit";
  6653. if (this.#args.annotationEditorMode !== null) {
  6654. this.pdfViewer.annotationEditorMode = {
  6655. mode: _pdfjsLib.AnnotationEditorType.NONE
  6656. };
  6657. }
  6658. }, 0);
  6659. this.#addWindowListeners();
  6660. this.#showControls();
  6661. this.contextMenuOpen = false;
  6662. window.getSelection().removeAllRanges();
  6663. }
  6664. #exit() {
  6665. const pageNumber = this.pdfViewer.currentPageNumber;
  6666. this.container.classList.remove(ACTIVE_SELECTOR);
  6667. setTimeout(() => {
  6668. this.#removeFullscreenChangeListeners();
  6669. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6670. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6671. if (this.#args.spreadMode !== null) {
  6672. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6673. }
  6674. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6675. this.pdfViewer.currentPageNumber = pageNumber;
  6676. if (this.#args.annotationEditorMode !== null) {
  6677. this.pdfViewer.annotationEditorMode = {
  6678. mode: this.#args.annotationEditorMode
  6679. };
  6680. }
  6681. this.#args = null;
  6682. }, 0);
  6683. this.#removeWindowListeners();
  6684. this.#hideControls();
  6685. this.#resetMouseScrollState();
  6686. this.contextMenuOpen = false;
  6687. }
  6688. #mouseDown(evt) {
  6689. if (this.contextMenuOpen) {
  6690. this.contextMenuOpen = false;
  6691. evt.preventDefault();
  6692. return;
  6693. }
  6694. if (evt.button !== 0) {
  6695. return;
  6696. }
  6697. if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) {
  6698. return;
  6699. }
  6700. evt.preventDefault();
  6701. if (evt.shiftKey) {
  6702. this.pdfViewer.previousPage();
  6703. } else {
  6704. this.pdfViewer.nextPage();
  6705. }
  6706. }
  6707. #contextMenu() {
  6708. this.contextMenuOpen = true;
  6709. }
  6710. #showControls() {
  6711. if (this.controlsTimeout) {
  6712. clearTimeout(this.controlsTimeout);
  6713. } else {
  6714. this.container.classList.add(CONTROLS_SELECTOR);
  6715. }
  6716. this.controlsTimeout = setTimeout(() => {
  6717. this.container.classList.remove(CONTROLS_SELECTOR);
  6718. delete this.controlsTimeout;
  6719. }, DELAY_BEFORE_HIDING_CONTROLS);
  6720. }
  6721. #hideControls() {
  6722. if (!this.controlsTimeout) {
  6723. return;
  6724. }
  6725. clearTimeout(this.controlsTimeout);
  6726. this.container.classList.remove(CONTROLS_SELECTOR);
  6727. delete this.controlsTimeout;
  6728. }
  6729. #resetMouseScrollState() {
  6730. this.mouseScrollTimeStamp = 0;
  6731. this.mouseScrollDelta = 0;
  6732. }
  6733. #touchSwipe(evt) {
  6734. if (!this.active) {
  6735. return;
  6736. }
  6737. if (evt.touches.length > 1) {
  6738. this.touchSwipeState = null;
  6739. return;
  6740. }
  6741. switch (evt.type) {
  6742. case "touchstart":
  6743. this.touchSwipeState = {
  6744. startX: evt.touches[0].pageX,
  6745. startY: evt.touches[0].pageY,
  6746. endX: evt.touches[0].pageX,
  6747. endY: evt.touches[0].pageY
  6748. };
  6749. break;
  6750. case "touchmove":
  6751. if (this.touchSwipeState === null) {
  6752. return;
  6753. }
  6754. this.touchSwipeState.endX = evt.touches[0].pageX;
  6755. this.touchSwipeState.endY = evt.touches[0].pageY;
  6756. evt.preventDefault();
  6757. break;
  6758. case "touchend":
  6759. if (this.touchSwipeState === null) {
  6760. return;
  6761. }
  6762. let delta = 0;
  6763. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6764. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6765. const absAngle = Math.abs(Math.atan2(dy, dx));
  6766. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6767. delta = dx;
  6768. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6769. delta = dy;
  6770. }
  6771. if (delta > 0) {
  6772. this.pdfViewer.previousPage();
  6773. } else if (delta < 0) {
  6774. this.pdfViewer.nextPage();
  6775. }
  6776. break;
  6777. }
  6778. }
  6779. #addWindowListeners() {
  6780. this.showControlsBind = this.#showControls.bind(this);
  6781. this.mouseDownBind = this.#mouseDown.bind(this);
  6782. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6783. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6784. this.contextMenuBind = this.#contextMenu.bind(this);
  6785. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6786. window.addEventListener("mousemove", this.showControlsBind);
  6787. window.addEventListener("mousedown", this.mouseDownBind);
  6788. window.addEventListener("wheel", this.mouseWheelBind, {
  6789. passive: false
  6790. });
  6791. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6792. window.addEventListener("contextmenu", this.contextMenuBind);
  6793. window.addEventListener("touchstart", this.touchSwipeBind);
  6794. window.addEventListener("touchmove", this.touchSwipeBind);
  6795. window.addEventListener("touchend", this.touchSwipeBind);
  6796. }
  6797. #removeWindowListeners() {
  6798. window.removeEventListener("mousemove", this.showControlsBind);
  6799. window.removeEventListener("mousedown", this.mouseDownBind);
  6800. window.removeEventListener("wheel", this.mouseWheelBind, {
  6801. passive: false
  6802. });
  6803. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6804. window.removeEventListener("contextmenu", this.contextMenuBind);
  6805. window.removeEventListener("touchstart", this.touchSwipeBind);
  6806. window.removeEventListener("touchmove", this.touchSwipeBind);
  6807. window.removeEventListener("touchend", this.touchSwipeBind);
  6808. delete this.showControlsBind;
  6809. delete this.mouseDownBind;
  6810. delete this.mouseWheelBind;
  6811. delete this.resetMouseScrollStateBind;
  6812. delete this.contextMenuBind;
  6813. delete this.touchSwipeBind;
  6814. }
  6815. #fullscreenChange() {
  6816. if (document.fullscreenElement) {
  6817. this.#enter();
  6818. } else {
  6819. this.#exit();
  6820. }
  6821. }
  6822. #addFullscreenChangeListeners() {
  6823. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6824. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6825. }
  6826. #removeFullscreenChangeListeners() {
  6827. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6828. delete this.fullscreenChangeBind;
  6829. }
  6830. }
  6831. exports.PDFPresentationMode = PDFPresentationMode;
  6832. /***/ }),
  6833. /* 23 */
  6834. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6835. Object.defineProperty(exports, "__esModule", ({
  6836. value: true
  6837. }));
  6838. exports.PDFRenderingQueue = void 0;
  6839. var _pdfjsLib = __webpack_require__(4);
  6840. var _ui_utils = __webpack_require__(3);
  6841. const CLEANUP_TIMEOUT = 30000;
  6842. class PDFRenderingQueue {
  6843. constructor() {
  6844. this.pdfViewer = null;
  6845. this.pdfThumbnailViewer = null;
  6846. this.onIdle = null;
  6847. this.highestPriorityPage = null;
  6848. this.idleTimeout = null;
  6849. this.printing = false;
  6850. this.isThumbnailViewEnabled = false;
  6851. Object.defineProperty(this, "hasViewer", {
  6852. value: () => !!this.pdfViewer
  6853. });
  6854. }
  6855. setViewer(pdfViewer) {
  6856. this.pdfViewer = pdfViewer;
  6857. }
  6858. setThumbnailViewer(pdfThumbnailViewer) {
  6859. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6860. }
  6861. isHighestPriority(view) {
  6862. return this.highestPriorityPage === view.renderingId;
  6863. }
  6864. renderHighestPriority(currentlyVisiblePages) {
  6865. if (this.idleTimeout) {
  6866. clearTimeout(this.idleTimeout);
  6867. this.idleTimeout = null;
  6868. }
  6869. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6870. return;
  6871. }
  6872. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6873. return;
  6874. }
  6875. if (this.printing) {
  6876. return;
  6877. }
  6878. if (this.onIdle) {
  6879. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6880. }
  6881. }
  6882. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6883. const visibleViews = visible.views,
  6884. numVisible = visibleViews.length;
  6885. if (numVisible === 0) {
  6886. return null;
  6887. }
  6888. for (let i = 0; i < numVisible; i++) {
  6889. const view = visibleViews[i].view;
  6890. if (!this.isViewFinished(view)) {
  6891. return view;
  6892. }
  6893. }
  6894. const firstId = visible.first.id,
  6895. lastId = visible.last.id;
  6896. if (lastId - firstId + 1 > numVisible) {
  6897. const visibleIds = visible.ids;
  6898. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6899. const holeId = scrolledDown ? firstId + i : lastId - i;
  6900. if (visibleIds.has(holeId)) {
  6901. continue;
  6902. }
  6903. const holeView = views[holeId - 1];
  6904. if (!this.isViewFinished(holeView)) {
  6905. return holeView;
  6906. }
  6907. }
  6908. }
  6909. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6910. let preRenderView = views[preRenderIndex];
  6911. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6912. return preRenderView;
  6913. }
  6914. if (preRenderExtra) {
  6915. preRenderIndex += scrolledDown ? 1 : -1;
  6916. preRenderView = views[preRenderIndex];
  6917. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6918. return preRenderView;
  6919. }
  6920. }
  6921. return null;
  6922. }
  6923. isViewFinished(view) {
  6924. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6925. }
  6926. renderView(view) {
  6927. switch (view.renderingState) {
  6928. case _ui_utils.RenderingStates.FINISHED:
  6929. return false;
  6930. case _ui_utils.RenderingStates.PAUSED:
  6931. this.highestPriorityPage = view.renderingId;
  6932. view.resume();
  6933. break;
  6934. case _ui_utils.RenderingStates.RUNNING:
  6935. this.highestPriorityPage = view.renderingId;
  6936. break;
  6937. case _ui_utils.RenderingStates.INITIAL:
  6938. this.highestPriorityPage = view.renderingId;
  6939. view.draw().finally(() => {
  6940. this.renderHighestPriority();
  6941. }).catch(reason => {
  6942. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6943. return;
  6944. }
  6945. console.error(`renderView: "${reason}"`);
  6946. });
  6947. break;
  6948. }
  6949. return true;
  6950. }
  6951. }
  6952. exports.PDFRenderingQueue = PDFRenderingQueue;
  6953. /***/ }),
  6954. /* 24 */
  6955. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6956. Object.defineProperty(exports, "__esModule", ({
  6957. value: true
  6958. }));
  6959. exports.PDFScriptingManager = void 0;
  6960. var _ui_utils = __webpack_require__(3);
  6961. var _pdfjsLib = __webpack_require__(4);
  6962. class PDFScriptingManager {
  6963. #closeCapability = null;
  6964. #destroyCapability = null;
  6965. #docProperties = null;
  6966. #eventBus = null;
  6967. #externalServices = null;
  6968. #pdfDocument = null;
  6969. #pdfViewer = null;
  6970. #ready = false;
  6971. #sandboxBundleSrc = null;
  6972. #scripting = null;
  6973. #willPrintCapability = null;
  6974. constructor({
  6975. eventBus,
  6976. sandboxBundleSrc = null,
  6977. externalServices = null,
  6978. docProperties = null
  6979. }) {
  6980. this.#eventBus = eventBus;
  6981. this.#sandboxBundleSrc = sandboxBundleSrc;
  6982. this.#externalServices = externalServices;
  6983. this.#docProperties = docProperties;
  6984. }
  6985. setViewer(pdfViewer) {
  6986. this.#pdfViewer = pdfViewer;
  6987. }
  6988. async setDocument(pdfDocument) {
  6989. if (this.#pdfDocument) {
  6990. await this.#destroyScripting();
  6991. }
  6992. this.#pdfDocument = pdfDocument;
  6993. if (!pdfDocument) {
  6994. return;
  6995. }
  6996. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6997. if (!objects && !docActions) {
  6998. await this.#destroyScripting();
  6999. return;
  7000. }
  7001. if (pdfDocument !== this.#pdfDocument) {
  7002. return;
  7003. }
  7004. try {
  7005. this.#scripting = this.#initScripting();
  7006. } catch (error) {
  7007. console.error(`setDocument: "${error.message}".`);
  7008. await this.#destroyScripting();
  7009. return;
  7010. }
  7011. this._internalEvents.set("updatefromsandbox", event => {
  7012. if (event?.source === window) {
  7013. this.#updateFromSandbox(event.detail);
  7014. }
  7015. });
  7016. this._internalEvents.set("dispatcheventinsandbox", event => {
  7017. this.#scripting?.dispatchEventInSandbox(event.detail);
  7018. });
  7019. this._internalEvents.set("pagechanging", ({
  7020. pageNumber,
  7021. previous
  7022. }) => {
  7023. if (pageNumber === previous) {
  7024. return;
  7025. }
  7026. this.#dispatchPageClose(previous);
  7027. this.#dispatchPageOpen(pageNumber);
  7028. });
  7029. this._internalEvents.set("pagerendered", ({
  7030. pageNumber
  7031. }) => {
  7032. if (!this._pageOpenPending.has(pageNumber)) {
  7033. return;
  7034. }
  7035. if (pageNumber !== this.#pdfViewer.currentPageNumber) {
  7036. return;
  7037. }
  7038. this.#dispatchPageOpen(pageNumber);
  7039. });
  7040. this._internalEvents.set("pagesdestroy", async () => {
  7041. await this.#dispatchPageClose(this.#pdfViewer.currentPageNumber);
  7042. await this.#scripting?.dispatchEventInSandbox({
  7043. id: "doc",
  7044. name: "WillClose"
  7045. });
  7046. this.#closeCapability?.resolve();
  7047. });
  7048. for (const [name, listener] of this._internalEvents) {
  7049. this.#eventBus._on(name, listener);
  7050. }
  7051. try {
  7052. const docProperties = await this.#docProperties(pdfDocument);
  7053. if (pdfDocument !== this.#pdfDocument) {
  7054. return;
  7055. }
  7056. await this.#scripting.createSandbox({
  7057. objects,
  7058. calculationOrder,
  7059. appInfo: {
  7060. platform: navigator.platform,
  7061. language: navigator.language
  7062. },
  7063. docInfo: {
  7064. ...docProperties,
  7065. actions: docActions
  7066. }
  7067. });
  7068. this.#eventBus.dispatch("sandboxcreated", {
  7069. source: this
  7070. });
  7071. } catch (error) {
  7072. console.error(`setDocument: "${error.message}".`);
  7073. await this.#destroyScripting();
  7074. return;
  7075. }
  7076. await this.#scripting?.dispatchEventInSandbox({
  7077. id: "doc",
  7078. name: "Open"
  7079. });
  7080. await this.#dispatchPageOpen(this.#pdfViewer.currentPageNumber, true);
  7081. Promise.resolve().then(() => {
  7082. if (pdfDocument === this.#pdfDocument) {
  7083. this.#ready = true;
  7084. }
  7085. });
  7086. }
  7087. async dispatchWillSave() {
  7088. return this.#scripting?.dispatchEventInSandbox({
  7089. id: "doc",
  7090. name: "WillSave"
  7091. });
  7092. }
  7093. async dispatchDidSave() {
  7094. return this.#scripting?.dispatchEventInSandbox({
  7095. id: "doc",
  7096. name: "DidSave"
  7097. });
  7098. }
  7099. async dispatchWillPrint() {
  7100. if (!this.#scripting) {
  7101. return;
  7102. }
  7103. await this.#willPrintCapability?.promise;
  7104. this.#willPrintCapability = new _pdfjsLib.PromiseCapability();
  7105. try {
  7106. await this.#scripting.dispatchEventInSandbox({
  7107. id: "doc",
  7108. name: "WillPrint"
  7109. });
  7110. } catch (ex) {
  7111. this.#willPrintCapability.resolve();
  7112. this.#willPrintCapability = null;
  7113. throw ex;
  7114. }
  7115. await this.#willPrintCapability.promise;
  7116. }
  7117. async dispatchDidPrint() {
  7118. return this.#scripting?.dispatchEventInSandbox({
  7119. id: "doc",
  7120. name: "DidPrint"
  7121. });
  7122. }
  7123. get destroyPromise() {
  7124. return this.#destroyCapability?.promise || null;
  7125. }
  7126. get ready() {
  7127. return this.#ready;
  7128. }
  7129. get _internalEvents() {
  7130. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  7131. }
  7132. get _pageOpenPending() {
  7133. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  7134. }
  7135. get _visitedPages() {
  7136. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  7137. }
  7138. async #updateFromSandbox(detail) {
  7139. const pdfViewer = this.#pdfViewer;
  7140. const isInPresentationMode = pdfViewer.isInPresentationMode || pdfViewer.isChangingPresentationMode;
  7141. const {
  7142. id,
  7143. siblings,
  7144. command,
  7145. value
  7146. } = detail;
  7147. if (!id) {
  7148. switch (command) {
  7149. case "clear":
  7150. console.clear();
  7151. break;
  7152. case "error":
  7153. console.error(value);
  7154. break;
  7155. case "layout":
  7156. if (!isInPresentationMode) {
  7157. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  7158. pdfViewer.spreadMode = modes.spreadMode;
  7159. }
  7160. break;
  7161. case "page-num":
  7162. pdfViewer.currentPageNumber = value + 1;
  7163. break;
  7164. case "print":
  7165. await pdfViewer.pagesPromise;
  7166. this.#eventBus.dispatch("print", {
  7167. source: this
  7168. });
  7169. break;
  7170. case "println":
  7171. console.log(value);
  7172. break;
  7173. case "zoom":
  7174. if (!isInPresentationMode) {
  7175. pdfViewer.currentScaleValue = value;
  7176. }
  7177. break;
  7178. case "SaveAs":
  7179. this.#eventBus.dispatch("download", {
  7180. source: this
  7181. });
  7182. break;
  7183. case "FirstPage":
  7184. pdfViewer.currentPageNumber = 1;
  7185. break;
  7186. case "LastPage":
  7187. pdfViewer.currentPageNumber = pdfViewer.pagesCount;
  7188. break;
  7189. case "NextPage":
  7190. pdfViewer.nextPage();
  7191. break;
  7192. case "PrevPage":
  7193. pdfViewer.previousPage();
  7194. break;
  7195. case "ZoomViewIn":
  7196. if (!isInPresentationMode) {
  7197. pdfViewer.increaseScale();
  7198. }
  7199. break;
  7200. case "ZoomViewOut":
  7201. if (!isInPresentationMode) {
  7202. pdfViewer.decreaseScale();
  7203. }
  7204. break;
  7205. case "WillPrintFinished":
  7206. this.#willPrintCapability?.resolve();
  7207. this.#willPrintCapability = null;
  7208. break;
  7209. }
  7210. return;
  7211. }
  7212. if (isInPresentationMode && detail.focus) {
  7213. return;
  7214. }
  7215. delete detail.id;
  7216. delete detail.siblings;
  7217. const ids = siblings ? [id, ...siblings] : [id];
  7218. for (const elementId of ids) {
  7219. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  7220. if (element) {
  7221. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  7222. detail
  7223. }));
  7224. } else {
  7225. this.#pdfDocument?.annotationStorage.setValue(elementId, detail);
  7226. }
  7227. }
  7228. }
  7229. async #dispatchPageOpen(pageNumber, initialize = false) {
  7230. const pdfDocument = this.#pdfDocument,
  7231. visitedPages = this._visitedPages;
  7232. if (initialize) {
  7233. this.#closeCapability = new _pdfjsLib.PromiseCapability();
  7234. }
  7235. if (!this.#closeCapability) {
  7236. return;
  7237. }
  7238. const pageView = this.#pdfViewer.getPageView(pageNumber - 1);
  7239. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7240. this._pageOpenPending.add(pageNumber);
  7241. return;
  7242. }
  7243. this._pageOpenPending.delete(pageNumber);
  7244. const actionsPromise = (async () => {
  7245. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  7246. if (pdfDocument !== this.#pdfDocument) {
  7247. return;
  7248. }
  7249. await this.#scripting?.dispatchEventInSandbox({
  7250. id: "page",
  7251. name: "PageOpen",
  7252. pageNumber,
  7253. actions
  7254. });
  7255. })();
  7256. visitedPages.set(pageNumber, actionsPromise);
  7257. }
  7258. async #dispatchPageClose(pageNumber) {
  7259. const pdfDocument = this.#pdfDocument,
  7260. visitedPages = this._visitedPages;
  7261. if (!this.#closeCapability) {
  7262. return;
  7263. }
  7264. if (this._pageOpenPending.has(pageNumber)) {
  7265. return;
  7266. }
  7267. const actionsPromise = visitedPages.get(pageNumber);
  7268. if (!actionsPromise) {
  7269. return;
  7270. }
  7271. visitedPages.set(pageNumber, null);
  7272. await actionsPromise;
  7273. if (pdfDocument !== this.#pdfDocument) {
  7274. return;
  7275. }
  7276. await this.#scripting?.dispatchEventInSandbox({
  7277. id: "page",
  7278. name: "PageClose",
  7279. pageNumber
  7280. });
  7281. }
  7282. #initScripting() {
  7283. this.#destroyCapability = new _pdfjsLib.PromiseCapability();
  7284. if (this.#scripting) {
  7285. throw new Error("#initScripting: Scripting already exists.");
  7286. }
  7287. return this.#externalServices.createScripting({
  7288. sandboxBundleSrc: this.#sandboxBundleSrc
  7289. });
  7290. }
  7291. async #destroyScripting() {
  7292. if (!this.#scripting) {
  7293. this.#pdfDocument = null;
  7294. this.#destroyCapability?.resolve();
  7295. return;
  7296. }
  7297. if (this.#closeCapability) {
  7298. await Promise.race([this.#closeCapability.promise, new Promise(resolve => {
  7299. setTimeout(resolve, 1000);
  7300. })]).catch(() => {});
  7301. this.#closeCapability = null;
  7302. }
  7303. this.#pdfDocument = null;
  7304. try {
  7305. await this.#scripting.destroySandbox();
  7306. } catch {}
  7307. this.#willPrintCapability?.reject(new Error("Scripting destroyed."));
  7308. this.#willPrintCapability = null;
  7309. for (const [name, listener] of this._internalEvents) {
  7310. this.#eventBus._off(name, listener);
  7311. }
  7312. this._internalEvents.clear();
  7313. this._pageOpenPending.clear();
  7314. this._visitedPages.clear();
  7315. this.#scripting = null;
  7316. this.#ready = false;
  7317. this.#destroyCapability?.resolve();
  7318. }
  7319. }
  7320. exports.PDFScriptingManager = PDFScriptingManager;
  7321. /***/ }),
  7322. /* 25 */
  7323. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7324. Object.defineProperty(exports, "__esModule", ({
  7325. value: true
  7326. }));
  7327. exports.PDFSidebar = void 0;
  7328. var _ui_utils = __webpack_require__(3);
  7329. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7330. const SIDEBAR_MIN_WIDTH = 200;
  7331. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7332. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7333. class PDFSidebar {
  7334. #isRTL = false;
  7335. #mouseMoveBound = this.#mouseMove.bind(this);
  7336. #mouseUpBound = this.#mouseUp.bind(this);
  7337. #outerContainerWidth = null;
  7338. #width = null;
  7339. constructor({
  7340. elements,
  7341. eventBus,
  7342. l10n
  7343. }) {
  7344. this.isOpen = false;
  7345. this.active = _ui_utils.SidebarView.THUMBS;
  7346. this.isInitialViewSet = false;
  7347. this.isInitialEventDispatched = false;
  7348. this.onToggled = null;
  7349. this.onUpdateThumbnails = null;
  7350. this.outerContainer = elements.outerContainer;
  7351. this.sidebarContainer = elements.sidebarContainer;
  7352. this.toggleButton = elements.toggleButton;
  7353. this.resizer = elements.resizer;
  7354. this.thumbnailButton = elements.thumbnailButton;
  7355. this.outlineButton = elements.outlineButton;
  7356. this.attachmentsButton = elements.attachmentsButton;
  7357. this.layersButton = elements.layersButton;
  7358. this.thumbnailView = elements.thumbnailView;
  7359. this.outlineView = elements.outlineView;
  7360. this.attachmentsView = elements.attachmentsView;
  7361. this.layersView = elements.layersView;
  7362. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  7363. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7364. this.eventBus = eventBus;
  7365. this.l10n = l10n;
  7366. l10n.getDirection().then(dir => {
  7367. this.#isRTL = dir === "rtl";
  7368. });
  7369. this.#addEventListeners();
  7370. }
  7371. reset() {
  7372. this.isInitialViewSet = false;
  7373. this.isInitialEventDispatched = false;
  7374. this.#hideUINotification(true);
  7375. this.switchView(_ui_utils.SidebarView.THUMBS);
  7376. this.outlineButton.disabled = false;
  7377. this.attachmentsButton.disabled = false;
  7378. this.layersButton.disabled = false;
  7379. this._currentOutlineItemButton.disabled = true;
  7380. }
  7381. get visibleView() {
  7382. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  7383. }
  7384. setInitialView(view = _ui_utils.SidebarView.NONE) {
  7385. if (this.isInitialViewSet) {
  7386. return;
  7387. }
  7388. this.isInitialViewSet = true;
  7389. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  7390. this.#dispatchEvent();
  7391. return;
  7392. }
  7393. this.switchView(view, true);
  7394. if (!this.isInitialEventDispatched) {
  7395. this.#dispatchEvent();
  7396. }
  7397. }
  7398. switchView(view, forceOpen = false) {
  7399. const isViewChanged = view !== this.active;
  7400. let forceRendering = false;
  7401. switch (view) {
  7402. case _ui_utils.SidebarView.NONE:
  7403. if (this.isOpen) {
  7404. this.close();
  7405. }
  7406. return;
  7407. case _ui_utils.SidebarView.THUMBS:
  7408. if (this.isOpen && isViewChanged) {
  7409. forceRendering = true;
  7410. }
  7411. break;
  7412. case _ui_utils.SidebarView.OUTLINE:
  7413. if (this.outlineButton.disabled) {
  7414. return;
  7415. }
  7416. break;
  7417. case _ui_utils.SidebarView.ATTACHMENTS:
  7418. if (this.attachmentsButton.disabled) {
  7419. return;
  7420. }
  7421. break;
  7422. case _ui_utils.SidebarView.LAYERS:
  7423. if (this.layersButton.disabled) {
  7424. return;
  7425. }
  7426. break;
  7427. default:
  7428. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7429. return;
  7430. }
  7431. this.active = view;
  7432. (0, _ui_utils.toggleCheckedBtn)(this.thumbnailButton, view === _ui_utils.SidebarView.THUMBS, this.thumbnailView);
  7433. (0, _ui_utils.toggleCheckedBtn)(this.outlineButton, view === _ui_utils.SidebarView.OUTLINE, this.outlineView);
  7434. (0, _ui_utils.toggleCheckedBtn)(this.attachmentsButton, view === _ui_utils.SidebarView.ATTACHMENTS, this.attachmentsView);
  7435. (0, _ui_utils.toggleCheckedBtn)(this.layersButton, view === _ui_utils.SidebarView.LAYERS, this.layersView);
  7436. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  7437. if (forceOpen && !this.isOpen) {
  7438. this.open();
  7439. return;
  7440. }
  7441. if (forceRendering) {
  7442. this.onUpdateThumbnails();
  7443. this.onToggled();
  7444. }
  7445. if (isViewChanged) {
  7446. this.#dispatchEvent();
  7447. }
  7448. }
  7449. open() {
  7450. if (this.isOpen) {
  7451. return;
  7452. }
  7453. this.isOpen = true;
  7454. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true);
  7455. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7456. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7457. this.onUpdateThumbnails();
  7458. }
  7459. this.onToggled();
  7460. this.#dispatchEvent();
  7461. this.#hideUINotification();
  7462. }
  7463. close() {
  7464. if (!this.isOpen) {
  7465. return;
  7466. }
  7467. this.isOpen = false;
  7468. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false);
  7469. this.outerContainer.classList.add("sidebarMoving");
  7470. this.outerContainer.classList.remove("sidebarOpen");
  7471. this.onToggled();
  7472. this.#dispatchEvent();
  7473. }
  7474. toggle() {
  7475. if (this.isOpen) {
  7476. this.close();
  7477. } else {
  7478. this.open();
  7479. }
  7480. }
  7481. #dispatchEvent() {
  7482. if (this.isInitialViewSet) {
  7483. this.isInitialEventDispatched ||= true;
  7484. }
  7485. this.eventBus.dispatch("sidebarviewchanged", {
  7486. source: this,
  7487. view: this.visibleView
  7488. });
  7489. }
  7490. #showUINotification() {
  7491. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2");
  7492. this.l10n.translate(this.toggleButton);
  7493. if (!this.isOpen) {
  7494. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7495. }
  7496. }
  7497. #hideUINotification(reset = false) {
  7498. if (this.isOpen || reset) {
  7499. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7500. }
  7501. if (reset) {
  7502. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
  7503. this.l10n.translate(this.toggleButton);
  7504. }
  7505. }
  7506. #addEventListeners() {
  7507. this.sidebarContainer.addEventListener("transitionend", evt => {
  7508. if (evt.target === this.sidebarContainer) {
  7509. this.outerContainer.classList.remove("sidebarMoving");
  7510. }
  7511. });
  7512. this.toggleButton.addEventListener("click", () => {
  7513. this.toggle();
  7514. });
  7515. this.thumbnailButton.addEventListener("click", () => {
  7516. this.switchView(_ui_utils.SidebarView.THUMBS);
  7517. });
  7518. this.outlineButton.addEventListener("click", () => {
  7519. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7520. });
  7521. this.outlineButton.addEventListener("dblclick", () => {
  7522. this.eventBus.dispatch("toggleoutlinetree", {
  7523. source: this
  7524. });
  7525. });
  7526. this.attachmentsButton.addEventListener("click", () => {
  7527. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7528. });
  7529. this.layersButton.addEventListener("click", () => {
  7530. this.switchView(_ui_utils.SidebarView.LAYERS);
  7531. });
  7532. this.layersButton.addEventListener("dblclick", () => {
  7533. this.eventBus.dispatch("resetlayers", {
  7534. source: this
  7535. });
  7536. });
  7537. this._currentOutlineItemButton.addEventListener("click", () => {
  7538. this.eventBus.dispatch("currentoutlineitem", {
  7539. source: this
  7540. });
  7541. });
  7542. const onTreeLoaded = (count, button, view) => {
  7543. button.disabled = !count;
  7544. if (count) {
  7545. this.#showUINotification();
  7546. } else if (this.active === view) {
  7547. this.switchView(_ui_utils.SidebarView.THUMBS);
  7548. }
  7549. };
  7550. this.eventBus._on("outlineloaded", evt => {
  7551. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7552. evt.currentOutlineItemPromise.then(enabled => {
  7553. if (!this.isInitialViewSet) {
  7554. return;
  7555. }
  7556. this._currentOutlineItemButton.disabled = !enabled;
  7557. });
  7558. });
  7559. this.eventBus._on("attachmentsloaded", evt => {
  7560. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7561. });
  7562. this.eventBus._on("layersloaded", evt => {
  7563. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7564. });
  7565. this.eventBus._on("presentationmodechanged", evt => {
  7566. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  7567. this.onUpdateThumbnails();
  7568. }
  7569. });
  7570. this.resizer.addEventListener("mousedown", evt => {
  7571. if (evt.button !== 0) {
  7572. return;
  7573. }
  7574. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7575. window.addEventListener("mousemove", this.#mouseMoveBound);
  7576. window.addEventListener("mouseup", this.#mouseUpBound);
  7577. });
  7578. this.eventBus._on("resize", evt => {
  7579. if (evt.source !== window) {
  7580. return;
  7581. }
  7582. this.#outerContainerWidth = null;
  7583. if (!this.#width) {
  7584. return;
  7585. }
  7586. if (!this.isOpen) {
  7587. this.#updateWidth(this.#width);
  7588. return;
  7589. }
  7590. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7591. const updated = this.#updateWidth(this.#width);
  7592. Promise.resolve().then(() => {
  7593. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7594. if (updated) {
  7595. this.eventBus.dispatch("resize", {
  7596. source: this
  7597. });
  7598. }
  7599. });
  7600. });
  7601. }
  7602. get outerContainerWidth() {
  7603. return this.#outerContainerWidth ||= this.outerContainer.clientWidth;
  7604. }
  7605. #updateWidth(width = 0) {
  7606. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7607. if (width > maxWidth) {
  7608. width = maxWidth;
  7609. }
  7610. if (width < SIDEBAR_MIN_WIDTH) {
  7611. width = SIDEBAR_MIN_WIDTH;
  7612. }
  7613. if (width === this.#width) {
  7614. return false;
  7615. }
  7616. this.#width = width;
  7617. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7618. return true;
  7619. }
  7620. #mouseMove(evt) {
  7621. let width = evt.clientX;
  7622. if (this.#isRTL) {
  7623. width = this.outerContainerWidth - width;
  7624. }
  7625. this.#updateWidth(width);
  7626. }
  7627. #mouseUp(evt) {
  7628. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7629. this.eventBus.dispatch("resize", {
  7630. source: this
  7631. });
  7632. window.removeEventListener("mousemove", this.#mouseMoveBound);
  7633. window.removeEventListener("mouseup", this.#mouseUpBound);
  7634. }
  7635. }
  7636. exports.PDFSidebar = PDFSidebar;
  7637. /***/ }),
  7638. /* 26 */
  7639. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7640. Object.defineProperty(exports, "__esModule", ({
  7641. value: true
  7642. }));
  7643. exports.PDFThumbnailViewer = void 0;
  7644. var _ui_utils = __webpack_require__(3);
  7645. var _pdf_thumbnail_view = __webpack_require__(27);
  7646. const THUMBNAIL_SCROLL_MARGIN = -19;
  7647. const THUMBNAIL_SELECTED_CLASS = "selected";
  7648. class PDFThumbnailViewer {
  7649. constructor({
  7650. container,
  7651. eventBus,
  7652. linkService,
  7653. renderingQueue,
  7654. l10n,
  7655. pageColors
  7656. }) {
  7657. this.container = container;
  7658. this.eventBus = eventBus;
  7659. this.linkService = linkService;
  7660. this.renderingQueue = renderingQueue;
  7661. this.l10n = l10n;
  7662. this.pageColors = pageColors || null;
  7663. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7664. this._resetView();
  7665. }
  7666. _scrollUpdated() {
  7667. this.renderingQueue.renderHighestPriority();
  7668. }
  7669. getThumbnail(index) {
  7670. return this._thumbnails[index];
  7671. }
  7672. _getVisibleThumbs() {
  7673. return (0, _ui_utils.getVisibleElements)({
  7674. scrollEl: this.container,
  7675. views: this._thumbnails
  7676. });
  7677. }
  7678. scrollThumbnailIntoView(pageNumber) {
  7679. if (!this.pdfDocument) {
  7680. return;
  7681. }
  7682. const thumbnailView = this._thumbnails[pageNumber - 1];
  7683. if (!thumbnailView) {
  7684. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7685. return;
  7686. }
  7687. if (pageNumber !== this._currentPageNumber) {
  7688. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7689. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7690. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7691. }
  7692. const {
  7693. first,
  7694. last,
  7695. views
  7696. } = this._getVisibleThumbs();
  7697. if (views.length > 0) {
  7698. let shouldScroll = false;
  7699. if (pageNumber <= first.id || pageNumber >= last.id) {
  7700. shouldScroll = true;
  7701. } else {
  7702. for (const {
  7703. id,
  7704. percent
  7705. } of views) {
  7706. if (id !== pageNumber) {
  7707. continue;
  7708. }
  7709. shouldScroll = percent < 100;
  7710. break;
  7711. }
  7712. }
  7713. if (shouldScroll) {
  7714. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7715. top: THUMBNAIL_SCROLL_MARGIN
  7716. });
  7717. }
  7718. }
  7719. this._currentPageNumber = pageNumber;
  7720. }
  7721. get pagesRotation() {
  7722. return this._pagesRotation;
  7723. }
  7724. set pagesRotation(rotation) {
  7725. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7726. throw new Error("Invalid thumbnails rotation angle.");
  7727. }
  7728. if (!this.pdfDocument) {
  7729. return;
  7730. }
  7731. if (this._pagesRotation === rotation) {
  7732. return;
  7733. }
  7734. this._pagesRotation = rotation;
  7735. const updateArgs = {
  7736. rotation
  7737. };
  7738. for (const thumbnail of this._thumbnails) {
  7739. thumbnail.update(updateArgs);
  7740. }
  7741. }
  7742. cleanup() {
  7743. for (const thumbnail of this._thumbnails) {
  7744. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7745. thumbnail.reset();
  7746. }
  7747. }
  7748. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7749. }
  7750. _resetView() {
  7751. this._thumbnails = [];
  7752. this._currentPageNumber = 1;
  7753. this._pageLabels = null;
  7754. this._pagesRotation = 0;
  7755. this.container.textContent = "";
  7756. }
  7757. setDocument(pdfDocument) {
  7758. if (this.pdfDocument) {
  7759. this._cancelRendering();
  7760. this._resetView();
  7761. }
  7762. this.pdfDocument = pdfDocument;
  7763. if (!pdfDocument) {
  7764. return;
  7765. }
  7766. const firstPagePromise = pdfDocument.getPage(1);
  7767. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7768. firstPagePromise.then(firstPdfPage => {
  7769. const pagesCount = pdfDocument.numPages;
  7770. const viewport = firstPdfPage.getViewport({
  7771. scale: 1
  7772. });
  7773. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7774. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7775. container: this.container,
  7776. eventBus: this.eventBus,
  7777. id: pageNum,
  7778. defaultViewport: viewport.clone(),
  7779. optionalContentConfigPromise,
  7780. linkService: this.linkService,
  7781. renderingQueue: this.renderingQueue,
  7782. l10n: this.l10n,
  7783. pageColors: this.pageColors
  7784. });
  7785. this._thumbnails.push(thumbnail);
  7786. }
  7787. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  7788. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7789. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7790. }).catch(reason => {
  7791. console.error("Unable to initialize thumbnail viewer", reason);
  7792. });
  7793. }
  7794. _cancelRendering() {
  7795. for (const thumbnail of this._thumbnails) {
  7796. thumbnail.cancelRendering();
  7797. }
  7798. }
  7799. setPageLabels(labels) {
  7800. if (!this.pdfDocument) {
  7801. return;
  7802. }
  7803. if (!labels) {
  7804. this._pageLabels = null;
  7805. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7806. this._pageLabels = null;
  7807. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7808. } else {
  7809. this._pageLabels = labels;
  7810. }
  7811. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7812. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7813. }
  7814. }
  7815. async #ensurePdfPageLoaded(thumbView) {
  7816. if (thumbView.pdfPage) {
  7817. return thumbView.pdfPage;
  7818. }
  7819. try {
  7820. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7821. if (!thumbView.pdfPage) {
  7822. thumbView.setPdfPage(pdfPage);
  7823. }
  7824. return pdfPage;
  7825. } catch (reason) {
  7826. console.error("Unable to get page for thumb view", reason);
  7827. return null;
  7828. }
  7829. }
  7830. #getScrollAhead(visible) {
  7831. if (visible.first?.id === 1) {
  7832. return true;
  7833. } else if (visible.last?.id === this._thumbnails.length) {
  7834. return false;
  7835. }
  7836. return this.scroll.down;
  7837. }
  7838. forceRendering() {
  7839. const visibleThumbs = this._getVisibleThumbs();
  7840. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7841. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7842. if (thumbView) {
  7843. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7844. this.renderingQueue.renderView(thumbView);
  7845. });
  7846. return true;
  7847. }
  7848. return false;
  7849. }
  7850. }
  7851. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7852. /***/ }),
  7853. /* 27 */
  7854. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7855. Object.defineProperty(exports, "__esModule", ({
  7856. value: true
  7857. }));
  7858. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7859. var _ui_utils = __webpack_require__(3);
  7860. var _pdfjsLib = __webpack_require__(4);
  7861. const DRAW_UPSCALE_FACTOR = 2;
  7862. const MAX_NUM_SCALING_STEPS = 3;
  7863. const THUMBNAIL_WIDTH = 98;
  7864. class TempImageFactory {
  7865. static #tempCanvas = null;
  7866. static getCanvas(width, height) {
  7867. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7868. tempCanvas.width = width;
  7869. tempCanvas.height = height;
  7870. const ctx = tempCanvas.getContext("2d", {
  7871. alpha: false
  7872. });
  7873. ctx.save();
  7874. ctx.fillStyle = "rgb(255, 255, 255)";
  7875. ctx.fillRect(0, 0, width, height);
  7876. ctx.restore();
  7877. return [tempCanvas, tempCanvas.getContext("2d")];
  7878. }
  7879. static destroyCanvas() {
  7880. const tempCanvas = this.#tempCanvas;
  7881. if (tempCanvas) {
  7882. tempCanvas.width = 0;
  7883. tempCanvas.height = 0;
  7884. }
  7885. this.#tempCanvas = null;
  7886. }
  7887. }
  7888. exports.TempImageFactory = TempImageFactory;
  7889. class PDFThumbnailView {
  7890. constructor({
  7891. container,
  7892. eventBus,
  7893. id,
  7894. defaultViewport,
  7895. optionalContentConfigPromise,
  7896. linkService,
  7897. renderingQueue,
  7898. l10n,
  7899. pageColors
  7900. }) {
  7901. this.id = id;
  7902. this.renderingId = "thumbnail" + id;
  7903. this.pageLabel = null;
  7904. this.pdfPage = null;
  7905. this.rotation = 0;
  7906. this.viewport = defaultViewport;
  7907. this.pdfPageRotate = defaultViewport.rotation;
  7908. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7909. this.pageColors = pageColors || null;
  7910. this.eventBus = eventBus;
  7911. this.linkService = linkService;
  7912. this.renderingQueue = renderingQueue;
  7913. this.renderTask = null;
  7914. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7915. this.resume = null;
  7916. this.l10n = l10n;
  7917. const anchor = document.createElement("a");
  7918. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7919. this._thumbPageTitle.then(msg => {
  7920. anchor.title = msg;
  7921. });
  7922. anchor.onclick = function () {
  7923. linkService.goToPage(id);
  7924. return false;
  7925. };
  7926. this.anchor = anchor;
  7927. const div = document.createElement("div");
  7928. div.className = "thumbnail";
  7929. div.setAttribute("data-page-number", this.id);
  7930. this.div = div;
  7931. this.#updateDims();
  7932. const img = document.createElement("div");
  7933. img.className = "thumbnailImage";
  7934. this._placeholderImg = img;
  7935. div.append(img);
  7936. anchor.append(div);
  7937. container.append(anchor);
  7938. }
  7939. #updateDims() {
  7940. const {
  7941. width,
  7942. height
  7943. } = this.viewport;
  7944. const ratio = width / height;
  7945. this.canvasWidth = THUMBNAIL_WIDTH;
  7946. this.canvasHeight = this.canvasWidth / ratio | 0;
  7947. this.scale = this.canvasWidth / width;
  7948. const {
  7949. style
  7950. } = this.div;
  7951. style.setProperty("--thumbnail-width", `${this.canvasWidth}px`);
  7952. style.setProperty("--thumbnail-height", `${this.canvasHeight}px`);
  7953. }
  7954. setPdfPage(pdfPage) {
  7955. this.pdfPage = pdfPage;
  7956. this.pdfPageRotate = pdfPage.rotate;
  7957. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7958. this.viewport = pdfPage.getViewport({
  7959. scale: 1,
  7960. rotation: totalRotation
  7961. });
  7962. this.reset();
  7963. }
  7964. reset() {
  7965. this.cancelRendering();
  7966. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7967. this.div.removeAttribute("data-loaded");
  7968. this.image?.replaceWith(this._placeholderImg);
  7969. this.#updateDims();
  7970. if (this.image) {
  7971. this.image.removeAttribute("src");
  7972. delete this.image;
  7973. }
  7974. }
  7975. update({
  7976. rotation = null
  7977. }) {
  7978. if (typeof rotation === "number") {
  7979. this.rotation = rotation;
  7980. }
  7981. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7982. this.viewport = this.viewport.clone({
  7983. scale: 1,
  7984. rotation: totalRotation
  7985. });
  7986. this.reset();
  7987. }
  7988. cancelRendering() {
  7989. if (this.renderTask) {
  7990. this.renderTask.cancel();
  7991. this.renderTask = null;
  7992. }
  7993. this.resume = null;
  7994. }
  7995. _getPageDrawContext(upscaleFactor = 1) {
  7996. const canvas = document.createElement("canvas");
  7997. const ctx = canvas.getContext("2d", {
  7998. alpha: false
  7999. });
  8000. const outputScale = new _ui_utils.OutputScale();
  8001. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  8002. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  8003. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  8004. return {
  8005. ctx,
  8006. canvas,
  8007. transform
  8008. };
  8009. }
  8010. _convertCanvasToImage(canvas) {
  8011. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8012. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  8013. }
  8014. const reducedCanvas = this._reduceImage(canvas);
  8015. const image = document.createElement("img");
  8016. image.className = "thumbnailImage";
  8017. this._thumbPageCanvas.then(msg => {
  8018. image.setAttribute("aria-label", msg);
  8019. });
  8020. image.src = reducedCanvas.toDataURL();
  8021. this.image = image;
  8022. this.div.setAttribute("data-loaded", true);
  8023. this._placeholderImg.replaceWith(image);
  8024. reducedCanvas.width = 0;
  8025. reducedCanvas.height = 0;
  8026. }
  8027. async #finishRenderTask(renderTask, canvas, error = null) {
  8028. if (renderTask === this.renderTask) {
  8029. this.renderTask = null;
  8030. }
  8031. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  8032. return;
  8033. }
  8034. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8035. this._convertCanvasToImage(canvas);
  8036. if (error) {
  8037. throw error;
  8038. }
  8039. }
  8040. async draw() {
  8041. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8042. console.error("Must be in new state before drawing");
  8043. return undefined;
  8044. }
  8045. const {
  8046. pdfPage
  8047. } = this;
  8048. if (!pdfPage) {
  8049. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8050. throw new Error("pdfPage is not loaded");
  8051. }
  8052. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8053. const {
  8054. ctx,
  8055. canvas,
  8056. transform
  8057. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  8058. const drawViewport = this.viewport.clone({
  8059. scale: DRAW_UPSCALE_FACTOR * this.scale
  8060. });
  8061. const renderContinueCallback = cont => {
  8062. if (!this.renderingQueue.isHighestPriority(this)) {
  8063. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  8064. this.resume = () => {
  8065. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8066. cont();
  8067. };
  8068. return;
  8069. }
  8070. cont();
  8071. };
  8072. const renderContext = {
  8073. canvasContext: ctx,
  8074. transform,
  8075. viewport: drawViewport,
  8076. optionalContentConfigPromise: this._optionalContentConfigPromise,
  8077. pageColors: this.pageColors
  8078. };
  8079. const renderTask = this.renderTask = pdfPage.render(renderContext);
  8080. renderTask.onContinue = renderContinueCallback;
  8081. const resultPromise = renderTask.promise.then(() => this.#finishRenderTask(renderTask, canvas), error => this.#finishRenderTask(renderTask, canvas, error));
  8082. resultPromise.finally(() => {
  8083. canvas.width = 0;
  8084. canvas.height = 0;
  8085. this.eventBus.dispatch("thumbnailrendered", {
  8086. source: this,
  8087. pageNumber: this.id,
  8088. pdfPage: this.pdfPage
  8089. });
  8090. });
  8091. return resultPromise;
  8092. }
  8093. setImage(pageView) {
  8094. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8095. return;
  8096. }
  8097. const {
  8098. thumbnailCanvas: canvas,
  8099. pdfPage,
  8100. scale
  8101. } = pageView;
  8102. if (!canvas) {
  8103. return;
  8104. }
  8105. if (!this.pdfPage) {
  8106. this.setPdfPage(pdfPage);
  8107. }
  8108. if (scale < this.scale) {
  8109. return;
  8110. }
  8111. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8112. this._convertCanvasToImage(canvas);
  8113. }
  8114. _reduceImage(img) {
  8115. const {
  8116. ctx,
  8117. canvas
  8118. } = this._getPageDrawContext();
  8119. if (img.width <= 2 * canvas.width) {
  8120. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  8121. return canvas;
  8122. }
  8123. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  8124. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  8125. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  8126. while (reducedWidth > img.width || reducedHeight > img.height) {
  8127. reducedWidth >>= 1;
  8128. reducedHeight >>= 1;
  8129. }
  8130. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  8131. while (reducedWidth > 2 * canvas.width) {
  8132. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  8133. reducedWidth >>= 1;
  8134. reducedHeight >>= 1;
  8135. }
  8136. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  8137. return canvas;
  8138. }
  8139. get _thumbPageTitle() {
  8140. return this.l10n.get("thumb_page_title", {
  8141. page: this.pageLabel ?? this.id
  8142. });
  8143. }
  8144. get _thumbPageCanvas() {
  8145. return this.l10n.get("thumb_page_canvas", {
  8146. page: this.pageLabel ?? this.id
  8147. });
  8148. }
  8149. setPageLabel(label) {
  8150. this.pageLabel = typeof label === "string" ? label : null;
  8151. this._thumbPageTitle.then(msg => {
  8152. this.anchor.title = msg;
  8153. });
  8154. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8155. return;
  8156. }
  8157. this._thumbPageCanvas.then(msg => {
  8158. this.image?.setAttribute("aria-label", msg);
  8159. });
  8160. }
  8161. }
  8162. exports.PDFThumbnailView = PDFThumbnailView;
  8163. /***/ }),
  8164. /* 28 */
  8165. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8166. Object.defineProperty(exports, "__esModule", ({
  8167. value: true
  8168. }));
  8169. exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
  8170. var _pdfjsLib = __webpack_require__(4);
  8171. var _ui_utils = __webpack_require__(3);
  8172. var _l10n_utils = __webpack_require__(29);
  8173. var _pdf_page_view = __webpack_require__(30);
  8174. var _pdf_rendering_queue = __webpack_require__(23);
  8175. var _pdf_link_service = __webpack_require__(7);
  8176. const DEFAULT_CACHE_SIZE = 10;
  8177. const PagesCountLimit = {
  8178. FORCE_SCROLL_MODE_PAGE: 15000,
  8179. FORCE_LAZY_PAGE_INIT: 7500,
  8180. PAUSE_EAGER_PAGE_INIT: 250
  8181. };
  8182. exports.PagesCountLimit = PagesCountLimit;
  8183. function isValidAnnotationEditorMode(mode) {
  8184. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  8185. }
  8186. class PDFPageViewBuffer {
  8187. #buf = new Set();
  8188. #size = 0;
  8189. constructor(size) {
  8190. this.#size = size;
  8191. }
  8192. push(view) {
  8193. const buf = this.#buf;
  8194. if (buf.has(view)) {
  8195. buf.delete(view);
  8196. }
  8197. buf.add(view);
  8198. if (buf.size > this.#size) {
  8199. this.#destroyFirstView();
  8200. }
  8201. }
  8202. resize(newSize, idsToKeep = null) {
  8203. this.#size = newSize;
  8204. const buf = this.#buf;
  8205. if (idsToKeep) {
  8206. const ii = buf.size;
  8207. let i = 1;
  8208. for (const view of buf) {
  8209. if (idsToKeep.has(view.id)) {
  8210. buf.delete(view);
  8211. buf.add(view);
  8212. }
  8213. if (++i > ii) {
  8214. break;
  8215. }
  8216. }
  8217. }
  8218. while (buf.size > this.#size) {
  8219. this.#destroyFirstView();
  8220. }
  8221. }
  8222. has(view) {
  8223. return this.#buf.has(view);
  8224. }
  8225. [Symbol.iterator]() {
  8226. return this.#buf.keys();
  8227. }
  8228. #destroyFirstView() {
  8229. const firstView = this.#buf.keys().next().value;
  8230. firstView?.destroy();
  8231. this.#buf.delete(firstView);
  8232. }
  8233. }
  8234. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  8235. class PDFViewer {
  8236. #buffer = null;
  8237. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  8238. #annotationEditorUIManager = null;
  8239. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8240. #containerTopLeft = null;
  8241. #copyCallbackBound = null;
  8242. #enablePermissions = false;
  8243. #getAllTextInProgress = false;
  8244. #hiddenCopyElement = null;
  8245. #interruptCopyCondition = false;
  8246. #previousContainerHeight = 0;
  8247. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  8248. #scrollModePageState = null;
  8249. #onVisibilityChange = null;
  8250. #scaleTimeoutId = null;
  8251. #textLayerMode = _ui_utils.TextLayerMode.ENABLE;
  8252. constructor(options) {
  8253. const viewerVersion = '3.10.111';
  8254. if (_pdfjsLib.version !== viewerVersion) {
  8255. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  8256. }
  8257. this.container = options.container;
  8258. this.viewer = options.viewer || options.container.firstElementChild;
  8259. if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
  8260. throw new Error("Invalid `container` and/or `viewer` option.");
  8261. }
  8262. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  8263. throw new Error("The `container` must be absolutely positioned.");
  8264. }
  8265. this.#resizeObserver.observe(this.container);
  8266. this.eventBus = options.eventBus;
  8267. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8268. this.downloadManager = options.downloadManager || null;
  8269. this.findController = options.findController || null;
  8270. if (this.findController) {
  8271. this.findController.onIsPageVisible = pageNumber => this._getVisiblePages().ids.has(pageNumber);
  8272. }
  8273. this._scriptingManager = options.scriptingManager || null;
  8274. this.#textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  8275. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8276. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
  8277. this.imageResourcesPath = options.imageResourcesPath || "";
  8278. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8279. this.removePageBorders = options.removePageBorders || false;
  8280. if (options.useOnlyCssZoom) {
  8281. console.error("useOnlyCssZoom was removed, please use `maxCanvasPixels = 0` instead.");
  8282. options.maxCanvasPixels = 0;
  8283. }
  8284. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  8285. this.maxCanvasPixels = options.maxCanvasPixels;
  8286. this.l10n = options.l10n || _l10n_utils.NullL10n;
  8287. this.#enablePermissions = options.enablePermissions || false;
  8288. this.pageColors = options.pageColors || null;
  8289. this.defaultRenderingQueue = !options.renderingQueue;
  8290. if (this.defaultRenderingQueue) {
  8291. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8292. this.renderingQueue.setViewer(this);
  8293. } else {
  8294. this.renderingQueue = options.renderingQueue;
  8295. }
  8296. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8297. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8298. this._onBeforeDraw = this._onAfterDraw = null;
  8299. this._resetView();
  8300. if (this.removePageBorders) {
  8301. this.viewer.classList.add("removePageBorders");
  8302. }
  8303. this.#updateContainerHeightCss();
  8304. this.eventBus._on("thumbnailrendered", ({
  8305. pageNumber,
  8306. pdfPage
  8307. }) => {
  8308. const pageView = this._pages[pageNumber - 1];
  8309. if (!this.#buffer.has(pageView)) {
  8310. pdfPage?.cleanup();
  8311. }
  8312. });
  8313. }
  8314. get pagesCount() {
  8315. return this._pages.length;
  8316. }
  8317. getPageView(index) {
  8318. return this._pages[index];
  8319. }
  8320. getCachedPageViews() {
  8321. return new Set(this.#buffer);
  8322. }
  8323. get pageViewsReady() {
  8324. return this._pagesCapability.settled && this._pages.every(pageView => pageView?.pdfPage);
  8325. }
  8326. get renderForms() {
  8327. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8328. }
  8329. get enableScripting() {
  8330. return !!this._scriptingManager;
  8331. }
  8332. get currentPageNumber() {
  8333. return this._currentPageNumber;
  8334. }
  8335. set currentPageNumber(val) {
  8336. if (!Number.isInteger(val)) {
  8337. throw new Error("Invalid page number.");
  8338. }
  8339. if (!this.pdfDocument) {
  8340. return;
  8341. }
  8342. if (!this._setCurrentPageNumber(val, true)) {
  8343. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  8344. }
  8345. }
  8346. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  8347. if (this._currentPageNumber === val) {
  8348. if (resetCurrentPageView) {
  8349. this.#resetCurrentPageView();
  8350. }
  8351. return true;
  8352. }
  8353. if (!(0 < val && val <= this.pagesCount)) {
  8354. return false;
  8355. }
  8356. const previous = this._currentPageNumber;
  8357. this._currentPageNumber = val;
  8358. this.eventBus.dispatch("pagechanging", {
  8359. source: this,
  8360. pageNumber: val,
  8361. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8362. previous
  8363. });
  8364. if (resetCurrentPageView) {
  8365. this.#resetCurrentPageView();
  8366. }
  8367. return true;
  8368. }
  8369. get currentPageLabel() {
  8370. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8371. }
  8372. set currentPageLabel(val) {
  8373. if (!this.pdfDocument) {
  8374. return;
  8375. }
  8376. let page = val | 0;
  8377. if (this._pageLabels) {
  8378. const i = this._pageLabels.indexOf(val);
  8379. if (i >= 0) {
  8380. page = i + 1;
  8381. }
  8382. }
  8383. if (!this._setCurrentPageNumber(page, true)) {
  8384. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8385. }
  8386. }
  8387. get currentScale() {
  8388. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8389. }
  8390. set currentScale(val) {
  8391. if (isNaN(val)) {
  8392. throw new Error("Invalid numeric scale.");
  8393. }
  8394. if (!this.pdfDocument) {
  8395. return;
  8396. }
  8397. this.#setScale(val, {
  8398. noScroll: false
  8399. });
  8400. }
  8401. get currentScaleValue() {
  8402. return this._currentScaleValue;
  8403. }
  8404. set currentScaleValue(val) {
  8405. if (!this.pdfDocument) {
  8406. return;
  8407. }
  8408. this.#setScale(val, {
  8409. noScroll: false
  8410. });
  8411. }
  8412. get pagesRotation() {
  8413. return this._pagesRotation;
  8414. }
  8415. set pagesRotation(rotation) {
  8416. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8417. throw new Error("Invalid pages rotation angle.");
  8418. }
  8419. if (!this.pdfDocument) {
  8420. return;
  8421. }
  8422. rotation %= 360;
  8423. if (rotation < 0) {
  8424. rotation += 360;
  8425. }
  8426. if (this._pagesRotation === rotation) {
  8427. return;
  8428. }
  8429. this._pagesRotation = rotation;
  8430. const pageNumber = this._currentPageNumber;
  8431. this.refresh(true, {
  8432. rotation
  8433. });
  8434. if (this._currentScaleValue) {
  8435. this.#setScale(this._currentScaleValue, {
  8436. noScroll: true
  8437. });
  8438. }
  8439. this.eventBus.dispatch("rotationchanging", {
  8440. source: this,
  8441. pagesRotation: rotation,
  8442. pageNumber
  8443. });
  8444. if (this.defaultRenderingQueue) {
  8445. this.update();
  8446. }
  8447. }
  8448. get firstPagePromise() {
  8449. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8450. }
  8451. get onePageRendered() {
  8452. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8453. }
  8454. get pagesPromise() {
  8455. return this.pdfDocument ? this._pagesCapability.promise : null;
  8456. }
  8457. #layerProperties() {
  8458. const self = this;
  8459. return {
  8460. get annotationEditorUIManager() {
  8461. return self.#annotationEditorUIManager;
  8462. },
  8463. get annotationStorage() {
  8464. return self.pdfDocument?.annotationStorage;
  8465. },
  8466. get downloadManager() {
  8467. return self.downloadManager;
  8468. },
  8469. get enableScripting() {
  8470. return !!self._scriptingManager;
  8471. },
  8472. get fieldObjectsPromise() {
  8473. return self.pdfDocument?.getFieldObjects();
  8474. },
  8475. get findController() {
  8476. return self.findController;
  8477. },
  8478. get hasJSActionsPromise() {
  8479. return self.pdfDocument?.hasJSActions();
  8480. },
  8481. get linkService() {
  8482. return self.linkService;
  8483. }
  8484. };
  8485. }
  8486. #initializePermissions(permissions) {
  8487. const params = {
  8488. annotationEditorMode: this.#annotationEditorMode,
  8489. annotationMode: this.#annotationMode,
  8490. textLayerMode: this.#textLayerMode
  8491. };
  8492. if (!permissions) {
  8493. return params;
  8494. }
  8495. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY) && this.#textLayerMode === _ui_utils.TextLayerMode.ENABLE) {
  8496. params.textLayerMode = _ui_utils.TextLayerMode.ENABLE_PERMISSIONS;
  8497. }
  8498. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  8499. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8500. }
  8501. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8502. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8503. }
  8504. return params;
  8505. }
  8506. #onePageRenderedOrForceFetch() {
  8507. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8508. return Promise.resolve();
  8509. }
  8510. const visibilityChangePromise = new Promise(resolve => {
  8511. this.#onVisibilityChange = () => {
  8512. if (document.visibilityState !== "hidden") {
  8513. return;
  8514. }
  8515. resolve();
  8516. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8517. this.#onVisibilityChange = null;
  8518. };
  8519. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8520. });
  8521. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8522. }
  8523. async getAllText() {
  8524. const texts = [];
  8525. const buffer = [];
  8526. for (let pageNum = 1, pagesCount = this.pdfDocument.numPages; pageNum <= pagesCount; ++pageNum) {
  8527. if (this.#interruptCopyCondition) {
  8528. return null;
  8529. }
  8530. buffer.length = 0;
  8531. const page = await this.pdfDocument.getPage(pageNum);
  8532. const {
  8533. items
  8534. } = await page.getTextContent();
  8535. for (const item of items) {
  8536. if (item.str) {
  8537. buffer.push(item.str);
  8538. }
  8539. if (item.hasEOL) {
  8540. buffer.push("\n");
  8541. }
  8542. }
  8543. texts.push((0, _ui_utils.removeNullCharacters)(buffer.join("")));
  8544. }
  8545. return texts.join("\n");
  8546. }
  8547. #copyCallback(textLayerMode, event) {
  8548. const selection = document.getSelection();
  8549. const {
  8550. focusNode,
  8551. anchorNode
  8552. } = selection;
  8553. if (anchorNode && focusNode && selection.containsNode(this.#hiddenCopyElement)) {
  8554. if (this.#getAllTextInProgress || textLayerMode === _ui_utils.TextLayerMode.ENABLE_PERMISSIONS) {
  8555. event.preventDefault();
  8556. event.stopPropagation();
  8557. return;
  8558. }
  8559. this.#getAllTextInProgress = true;
  8560. const savedCursor = this.container.style.cursor;
  8561. this.container.style.cursor = "wait";
  8562. const interruptCopy = ev => this.#interruptCopyCondition = ev.key === "Escape";
  8563. window.addEventListener("keydown", interruptCopy);
  8564. this.getAllText().then(async text => {
  8565. if (text !== null) {
  8566. await navigator.clipboard.writeText(text);
  8567. }
  8568. }).catch(reason => {
  8569. console.warn(`Something goes wrong when extracting the text: ${reason.message}`);
  8570. }).finally(() => {
  8571. this.#getAllTextInProgress = false;
  8572. this.#interruptCopyCondition = false;
  8573. window.removeEventListener("keydown", interruptCopy);
  8574. this.container.style.cursor = savedCursor;
  8575. });
  8576. event.preventDefault();
  8577. event.stopPropagation();
  8578. }
  8579. }
  8580. setDocument(pdfDocument) {
  8581. if (this.pdfDocument) {
  8582. this.eventBus.dispatch("pagesdestroy", {
  8583. source: this
  8584. });
  8585. this._cancelRendering();
  8586. this._resetView();
  8587. this.findController?.setDocument(null);
  8588. this._scriptingManager?.setDocument(null);
  8589. if (this.#annotationEditorUIManager) {
  8590. this.#annotationEditorUIManager.destroy();
  8591. this.#annotationEditorUIManager = null;
  8592. }
  8593. }
  8594. this.pdfDocument = pdfDocument;
  8595. if (!pdfDocument) {
  8596. return;
  8597. }
  8598. const pagesCount = pdfDocument.numPages;
  8599. const firstPagePromise = pdfDocument.getPage(1);
  8600. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8601. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8602. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8603. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8604. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8605. this.eventBus.dispatch("scrollmodechanged", {
  8606. source: this,
  8607. mode
  8608. });
  8609. }
  8610. this._pagesCapability.promise.then(() => {
  8611. this.eventBus.dispatch("pagesloaded", {
  8612. source: this,
  8613. pagesCount
  8614. });
  8615. }, () => {});
  8616. this._onBeforeDraw = evt => {
  8617. const pageView = this._pages[evt.pageNumber - 1];
  8618. if (!pageView) {
  8619. return;
  8620. }
  8621. this.#buffer.push(pageView);
  8622. };
  8623. this.eventBus._on("pagerender", this._onBeforeDraw);
  8624. this._onAfterDraw = evt => {
  8625. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8626. return;
  8627. }
  8628. this._onePageRenderedCapability.resolve({
  8629. timestamp: evt.timestamp
  8630. });
  8631. this.eventBus._off("pagerendered", this._onAfterDraw);
  8632. this._onAfterDraw = null;
  8633. if (this.#onVisibilityChange) {
  8634. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8635. this.#onVisibilityChange = null;
  8636. }
  8637. };
  8638. this.eventBus._on("pagerendered", this._onAfterDraw);
  8639. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8640. if (pdfDocument !== this.pdfDocument) {
  8641. return;
  8642. }
  8643. this._firstPageCapability.resolve(firstPdfPage);
  8644. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8645. const {
  8646. annotationEditorMode,
  8647. annotationMode,
  8648. textLayerMode
  8649. } = this.#initializePermissions(permissions);
  8650. if (textLayerMode !== _ui_utils.TextLayerMode.DISABLE) {
  8651. const element = this.#hiddenCopyElement = document.createElement("div");
  8652. element.id = "hiddenCopyElement";
  8653. this.viewer.before(element);
  8654. }
  8655. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  8656. const mode = annotationEditorMode;
  8657. if (pdfDocument.isPureXfa) {
  8658. console.warn("Warning: XFA-editing is not implemented.");
  8659. } else if (isValidAnnotationEditorMode(mode)) {
  8660. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.viewer, this.eventBus, pdfDocument, this.pageColors);
  8661. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  8662. this.#annotationEditorUIManager.updateMode(mode);
  8663. }
  8664. } else {
  8665. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  8666. }
  8667. }
  8668. const layerProperties = this.#layerProperties.bind(this);
  8669. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8670. const scale = this.currentScale;
  8671. const viewport = firstPdfPage.getViewport({
  8672. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8673. });
  8674. this.viewer.style.setProperty("--scale-factor", viewport.scale);
  8675. if (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas") {
  8676. this.viewer.style.setProperty("--hcm-highligh-filter", pdfDocument.filterFactory.addHighlightHCMFilter("CanvasText", "Canvas", "HighlightText", "Highlight"));
  8677. }
  8678. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8679. const pageView = new _pdf_page_view.PDFPageView({
  8680. container: viewerElement,
  8681. eventBus: this.eventBus,
  8682. id: pageNum,
  8683. scale,
  8684. defaultViewport: viewport.clone(),
  8685. optionalContentConfigPromise,
  8686. renderingQueue: this.renderingQueue,
  8687. textLayerMode,
  8688. annotationMode,
  8689. imageResourcesPath: this.imageResourcesPath,
  8690. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  8691. maxCanvasPixels: this.maxCanvasPixels,
  8692. pageColors: this.pageColors,
  8693. l10n: this.l10n,
  8694. layerProperties
  8695. });
  8696. this._pages.push(pageView);
  8697. }
  8698. const firstPageView = this._pages[0];
  8699. if (firstPageView) {
  8700. firstPageView.setPdfPage(firstPdfPage);
  8701. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8702. }
  8703. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8704. this.#ensurePageViewVisible();
  8705. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8706. this._updateSpreadMode();
  8707. }
  8708. this.#onePageRenderedOrForceFetch().then(async () => {
  8709. this.findController?.setDocument(pdfDocument);
  8710. this._scriptingManager?.setDocument(pdfDocument);
  8711. if (this.#hiddenCopyElement) {
  8712. this.#copyCallbackBound = this.#copyCallback.bind(this, textLayerMode);
  8713. document.addEventListener("copy", this.#copyCallbackBound);
  8714. }
  8715. if (this.#annotationEditorUIManager) {
  8716. this.eventBus.dispatch("annotationeditormodechanged", {
  8717. source: this,
  8718. mode: this.#annotationEditorMode
  8719. });
  8720. }
  8721. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8722. this._pagesCapability.resolve();
  8723. return;
  8724. }
  8725. let getPagesLeft = pagesCount - 1;
  8726. if (getPagesLeft <= 0) {
  8727. this._pagesCapability.resolve();
  8728. return;
  8729. }
  8730. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8731. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8732. const pageView = this._pages[pageNum - 1];
  8733. if (!pageView.pdfPage) {
  8734. pageView.setPdfPage(pdfPage);
  8735. }
  8736. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8737. if (--getPagesLeft === 0) {
  8738. this._pagesCapability.resolve();
  8739. }
  8740. }, reason => {
  8741. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8742. if (--getPagesLeft === 0) {
  8743. this._pagesCapability.resolve();
  8744. }
  8745. });
  8746. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8747. await promise;
  8748. }
  8749. }
  8750. });
  8751. this.eventBus.dispatch("pagesinit", {
  8752. source: this
  8753. });
  8754. pdfDocument.getMetadata().then(({
  8755. info
  8756. }) => {
  8757. if (pdfDocument !== this.pdfDocument) {
  8758. return;
  8759. }
  8760. if (info.Language) {
  8761. this.viewer.lang = info.Language;
  8762. }
  8763. });
  8764. if (this.defaultRenderingQueue) {
  8765. this.update();
  8766. }
  8767. }).catch(reason => {
  8768. console.error("Unable to initialize viewer", reason);
  8769. this._pagesCapability.reject(reason);
  8770. });
  8771. }
  8772. setPageLabels(labels) {
  8773. if (!this.pdfDocument) {
  8774. return;
  8775. }
  8776. if (!labels) {
  8777. this._pageLabels = null;
  8778. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8779. this._pageLabels = null;
  8780. console.error(`setPageLabels: Invalid page labels.`);
  8781. } else {
  8782. this._pageLabels = labels;
  8783. }
  8784. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8785. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8786. }
  8787. }
  8788. _resetView() {
  8789. this._pages = [];
  8790. this._currentPageNumber = 1;
  8791. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8792. this._currentScaleValue = null;
  8793. this._pageLabels = null;
  8794. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8795. this._location = null;
  8796. this._pagesRotation = 0;
  8797. this._optionalContentConfigPromise = null;
  8798. this._firstPageCapability = new _pdfjsLib.PromiseCapability();
  8799. this._onePageRenderedCapability = new _pdfjsLib.PromiseCapability();
  8800. this._pagesCapability = new _pdfjsLib.PromiseCapability();
  8801. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8802. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8803. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8804. this.#scrollModePageState = {
  8805. previousPageNumber: 1,
  8806. scrollDown: true,
  8807. pages: []
  8808. };
  8809. if (this._onBeforeDraw) {
  8810. this.eventBus._off("pagerender", this._onBeforeDraw);
  8811. this._onBeforeDraw = null;
  8812. }
  8813. if (this._onAfterDraw) {
  8814. this.eventBus._off("pagerendered", this._onAfterDraw);
  8815. this._onAfterDraw = null;
  8816. }
  8817. if (this.#onVisibilityChange) {
  8818. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8819. this.#onVisibilityChange = null;
  8820. }
  8821. this.viewer.textContent = "";
  8822. this._updateScrollMode();
  8823. this.viewer.removeAttribute("lang");
  8824. if (this.#hiddenCopyElement) {
  8825. document.removeEventListener("copy", this.#copyCallbackBound);
  8826. this.#copyCallbackBound = null;
  8827. this.#hiddenCopyElement.remove();
  8828. this.#hiddenCopyElement = null;
  8829. }
  8830. }
  8831. #ensurePageViewVisible() {
  8832. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8833. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8834. }
  8835. const pageNumber = this._currentPageNumber,
  8836. state = this.#scrollModePageState,
  8837. viewer = this.viewer;
  8838. viewer.textContent = "";
  8839. state.pages.length = 0;
  8840. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8841. const pageView = this._pages[pageNumber - 1];
  8842. viewer.append(pageView.div);
  8843. state.pages.push(pageView);
  8844. } else {
  8845. const pageIndexSet = new Set(),
  8846. parity = this._spreadMode - 1;
  8847. if (parity === -1) {
  8848. pageIndexSet.add(pageNumber - 1);
  8849. } else if (pageNumber % 2 !== parity) {
  8850. pageIndexSet.add(pageNumber - 1);
  8851. pageIndexSet.add(pageNumber);
  8852. } else {
  8853. pageIndexSet.add(pageNumber - 2);
  8854. pageIndexSet.add(pageNumber - 1);
  8855. }
  8856. const spread = document.createElement("div");
  8857. spread.className = "spread";
  8858. if (this.isInPresentationMode) {
  8859. const dummyPage = document.createElement("div");
  8860. dummyPage.className = "dummyPage";
  8861. spread.append(dummyPage);
  8862. }
  8863. for (const i of pageIndexSet) {
  8864. const pageView = this._pages[i];
  8865. if (!pageView) {
  8866. continue;
  8867. }
  8868. spread.append(pageView.div);
  8869. state.pages.push(pageView);
  8870. }
  8871. viewer.append(spread);
  8872. }
  8873. state.scrollDown = pageNumber >= state.previousPageNumber;
  8874. state.previousPageNumber = pageNumber;
  8875. }
  8876. _scrollUpdate() {
  8877. if (this.pagesCount === 0) {
  8878. return;
  8879. }
  8880. this.update();
  8881. }
  8882. #scrollIntoView(pageView, pageSpot = null) {
  8883. const {
  8884. div,
  8885. id
  8886. } = pageView;
  8887. if (this._currentPageNumber !== id) {
  8888. this._setCurrentPageNumber(id);
  8889. }
  8890. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8891. this.#ensurePageViewVisible();
  8892. this.update();
  8893. }
  8894. if (!pageSpot && !this.isInPresentationMode) {
  8895. const left = div.offsetLeft + div.clientLeft,
  8896. right = left + div.clientWidth;
  8897. const {
  8898. scrollLeft,
  8899. clientWidth
  8900. } = this.container;
  8901. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8902. pageSpot = {
  8903. left: 0,
  8904. top: 0
  8905. };
  8906. }
  8907. }
  8908. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8909. if (!this._currentScaleValue && this._location) {
  8910. this._location = null;
  8911. }
  8912. }
  8913. #isSameScale(newScale) {
  8914. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8915. }
  8916. #setScaleUpdatePages(newScale, newValue, {
  8917. noScroll = false,
  8918. preset = false,
  8919. drawingDelay = -1
  8920. }) {
  8921. this._currentScaleValue = newValue.toString();
  8922. if (this.#isSameScale(newScale)) {
  8923. if (preset) {
  8924. this.eventBus.dispatch("scalechanging", {
  8925. source: this,
  8926. scale: newScale,
  8927. presetValue: newValue
  8928. });
  8929. }
  8930. return;
  8931. }
  8932. this.viewer.style.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8933. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  8934. this.refresh(true, {
  8935. scale: newScale,
  8936. drawingDelay: postponeDrawing ? drawingDelay : -1
  8937. });
  8938. if (postponeDrawing) {
  8939. this.#scaleTimeoutId = setTimeout(() => {
  8940. this.#scaleTimeoutId = null;
  8941. this.refresh();
  8942. }, drawingDelay);
  8943. }
  8944. this._currentScale = newScale;
  8945. if (!noScroll) {
  8946. let page = this._currentPageNumber,
  8947. dest;
  8948. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8949. page = this._location.pageNumber;
  8950. dest = [null, {
  8951. name: "XYZ"
  8952. }, this._location.left, this._location.top, null];
  8953. }
  8954. this.scrollPageIntoView({
  8955. pageNumber: page,
  8956. destArray: dest,
  8957. allowNegativeOffset: true
  8958. });
  8959. }
  8960. this.eventBus.dispatch("scalechanging", {
  8961. source: this,
  8962. scale: newScale,
  8963. presetValue: preset ? newValue : undefined
  8964. });
  8965. if (this.defaultRenderingQueue) {
  8966. this.update();
  8967. }
  8968. }
  8969. get #pageWidthScaleFactor() {
  8970. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8971. return 2;
  8972. }
  8973. return 1;
  8974. }
  8975. #setScale(value, options) {
  8976. let scale = parseFloat(value);
  8977. if (scale > 0) {
  8978. options.preset = false;
  8979. this.#setScaleUpdatePages(scale, value, options);
  8980. } else {
  8981. const currentPage = this._pages[this._currentPageNumber - 1];
  8982. if (!currentPage) {
  8983. return;
  8984. }
  8985. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8986. vPadding = _ui_utils.VERTICAL_PADDING;
  8987. if (this.isInPresentationMode) {
  8988. hPadding = vPadding = 4;
  8989. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8990. hPadding *= 2;
  8991. }
  8992. } else if (this.removePageBorders) {
  8993. hPadding = vPadding = 0;
  8994. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8995. [hPadding, vPadding] = [vPadding, hPadding];
  8996. }
  8997. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor;
  8998. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8999. switch (value) {
  9000. case "page-actual":
  9001. scale = 1;
  9002. break;
  9003. case "page-width":
  9004. scale = pageWidthScale;
  9005. break;
  9006. case "page-height":
  9007. scale = pageHeightScale;
  9008. break;
  9009. case "page-fit":
  9010. scale = Math.min(pageWidthScale, pageHeightScale);
  9011. break;
  9012. case "auto":
  9013. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  9014. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  9015. break;
  9016. default:
  9017. console.error(`#setScale: "${value}" is an unknown zoom value.`);
  9018. return;
  9019. }
  9020. options.preset = true;
  9021. this.#setScaleUpdatePages(scale, value, options);
  9022. }
  9023. }
  9024. #resetCurrentPageView() {
  9025. const pageView = this._pages[this._currentPageNumber - 1];
  9026. if (this.isInPresentationMode) {
  9027. this.#setScale(this._currentScaleValue, {
  9028. noScroll: true
  9029. });
  9030. }
  9031. this.#scrollIntoView(pageView);
  9032. }
  9033. pageLabelToPageNumber(label) {
  9034. if (!this._pageLabels) {
  9035. return null;
  9036. }
  9037. const i = this._pageLabels.indexOf(label);
  9038. if (i < 0) {
  9039. return null;
  9040. }
  9041. return i + 1;
  9042. }
  9043. scrollPageIntoView({
  9044. pageNumber,
  9045. destArray = null,
  9046. allowNegativeOffset = false,
  9047. ignoreDestinationZoom = false
  9048. }) {
  9049. if (!this.pdfDocument) {
  9050. return;
  9051. }
  9052. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  9053. if (!pageView) {
  9054. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  9055. return;
  9056. }
  9057. if (this.isInPresentationMode || !destArray) {
  9058. this._setCurrentPageNumber(pageNumber, true);
  9059. return;
  9060. }
  9061. let x = 0,
  9062. y = 0;
  9063. let width = 0,
  9064. height = 0,
  9065. widthScale,
  9066. heightScale;
  9067. const changeOrientation = pageView.rotation % 180 !== 0;
  9068. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9069. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9070. let scale = 0;
  9071. switch (destArray[1].name) {
  9072. case "XYZ":
  9073. x = destArray[2];
  9074. y = destArray[3];
  9075. scale = destArray[4];
  9076. x = x !== null ? x : 0;
  9077. y = y !== null ? y : pageHeight;
  9078. break;
  9079. case "Fit":
  9080. case "FitB":
  9081. scale = "page-fit";
  9082. break;
  9083. case "FitH":
  9084. case "FitBH":
  9085. y = destArray[2];
  9086. scale = "page-width";
  9087. if (y === null && this._location) {
  9088. x = this._location.left;
  9089. y = this._location.top;
  9090. } else if (typeof y !== "number" || y < 0) {
  9091. y = pageHeight;
  9092. }
  9093. break;
  9094. case "FitV":
  9095. case "FitBV":
  9096. x = destArray[2];
  9097. width = pageWidth;
  9098. height = pageHeight;
  9099. scale = "page-height";
  9100. break;
  9101. case "FitR":
  9102. x = destArray[2];
  9103. y = destArray[3];
  9104. width = destArray[4] - x;
  9105. height = destArray[5] - y;
  9106. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  9107. vPadding = _ui_utils.VERTICAL_PADDING;
  9108. if (this.removePageBorders) {
  9109. hPadding = vPadding = 0;
  9110. }
  9111. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9112. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9113. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  9114. break;
  9115. default:
  9116. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  9117. return;
  9118. }
  9119. if (!ignoreDestinationZoom) {
  9120. if (scale && scale !== this._currentScale) {
  9121. this.currentScaleValue = scale;
  9122. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  9123. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  9124. }
  9125. }
  9126. if (scale === "page-fit" && !destArray[4]) {
  9127. this.#scrollIntoView(pageView);
  9128. return;
  9129. }
  9130. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  9131. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  9132. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  9133. if (!allowNegativeOffset) {
  9134. left = Math.max(left, 0);
  9135. top = Math.max(top, 0);
  9136. }
  9137. this.#scrollIntoView(pageView, {
  9138. left,
  9139. top
  9140. });
  9141. }
  9142. _updateLocation(firstPage) {
  9143. const currentScale = this._currentScale;
  9144. const currentScaleValue = this._currentScaleValue;
  9145. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  9146. const pageNumber = firstPage.id;
  9147. const currentPageView = this._pages[pageNumber - 1];
  9148. const container = this.container;
  9149. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  9150. const intLeft = Math.round(topLeft[0]);
  9151. const intTop = Math.round(topLeft[1]);
  9152. let pdfOpenParams = `#page=${pageNumber}`;
  9153. if (!this.isInPresentationMode) {
  9154. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  9155. }
  9156. this._location = {
  9157. pageNumber,
  9158. scale: normalizedScaleValue,
  9159. top: intTop,
  9160. left: intLeft,
  9161. rotation: this._pagesRotation,
  9162. pdfOpenParams
  9163. };
  9164. }
  9165. update() {
  9166. const visible = this._getVisiblePages();
  9167. const visiblePages = visible.views,
  9168. numVisiblePages = visiblePages.length;
  9169. if (numVisiblePages === 0) {
  9170. return;
  9171. }
  9172. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  9173. this.#buffer.resize(newCacheSize, visible.ids);
  9174. this.renderingQueue.renderHighestPriority(visible);
  9175. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  9176. const currentId = this._currentPageNumber;
  9177. let stillFullyVisible = false;
  9178. for (const page of visiblePages) {
  9179. if (page.percent < 100) {
  9180. break;
  9181. }
  9182. if (page.id === currentId && isSimpleLayout) {
  9183. stillFullyVisible = true;
  9184. break;
  9185. }
  9186. }
  9187. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  9188. this._updateLocation(visible.first);
  9189. this.eventBus.dispatch("updateviewarea", {
  9190. source: this,
  9191. location: this._location
  9192. });
  9193. }
  9194. containsElement(element) {
  9195. return this.container.contains(element);
  9196. }
  9197. focus() {
  9198. this.container.focus();
  9199. }
  9200. get _isContainerRtl() {
  9201. return getComputedStyle(this.container).direction === "rtl";
  9202. }
  9203. get isInPresentationMode() {
  9204. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  9205. }
  9206. get isChangingPresentationMode() {
  9207. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  9208. }
  9209. get isHorizontalScrollbarEnabled() {
  9210. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  9211. }
  9212. get isVerticalScrollbarEnabled() {
  9213. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  9214. }
  9215. _getVisiblePages() {
  9216. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  9217. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  9218. rtl = horizontal && this._isContainerRtl;
  9219. return (0, _ui_utils.getVisibleElements)({
  9220. scrollEl: this.container,
  9221. views,
  9222. sortByVisibility: true,
  9223. horizontal,
  9224. rtl
  9225. });
  9226. }
  9227. cleanup() {
  9228. for (const pageView of this._pages) {
  9229. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  9230. pageView.reset();
  9231. }
  9232. }
  9233. }
  9234. _cancelRendering() {
  9235. for (const pageView of this._pages) {
  9236. pageView.cancelRendering();
  9237. }
  9238. }
  9239. async #ensurePdfPageLoaded(pageView) {
  9240. if (pageView.pdfPage) {
  9241. return pageView.pdfPage;
  9242. }
  9243. try {
  9244. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  9245. if (!pageView.pdfPage) {
  9246. pageView.setPdfPage(pdfPage);
  9247. }
  9248. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  9249. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  9250. }
  9251. return pdfPage;
  9252. } catch (reason) {
  9253. console.error("Unable to get page for page view", reason);
  9254. return null;
  9255. }
  9256. }
  9257. #getScrollAhead(visible) {
  9258. if (visible.first?.id === 1) {
  9259. return true;
  9260. } else if (visible.last?.id === this.pagesCount) {
  9261. return false;
  9262. }
  9263. switch (this._scrollMode) {
  9264. case _ui_utils.ScrollMode.PAGE:
  9265. return this.#scrollModePageState.scrollDown;
  9266. case _ui_utils.ScrollMode.HORIZONTAL:
  9267. return this.scroll.right;
  9268. }
  9269. return this.scroll.down;
  9270. }
  9271. forceRendering(currentlyVisiblePages) {
  9272. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9273. const scrollAhead = this.#getScrollAhead(visiblePages);
  9274. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9275. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9276. if (pageView) {
  9277. this.#ensurePdfPageLoaded(pageView).then(() => {
  9278. this.renderingQueue.renderView(pageView);
  9279. });
  9280. return true;
  9281. }
  9282. return false;
  9283. }
  9284. get hasEqualPageSizes() {
  9285. const firstPageView = this._pages[0];
  9286. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  9287. const pageView = this._pages[i];
  9288. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9289. return false;
  9290. }
  9291. }
  9292. return true;
  9293. }
  9294. getPagesOverview() {
  9295. let initialOrientation;
  9296. return this._pages.map(pageView => {
  9297. const viewport = pageView.pdfPage.getViewport({
  9298. scale: 1
  9299. });
  9300. const orientation = (0, _ui_utils.isPortraitOrientation)(viewport);
  9301. if (initialOrientation === undefined) {
  9302. initialOrientation = orientation;
  9303. } else if (this.enablePrintAutoRotate && orientation !== initialOrientation) {
  9304. return {
  9305. width: viewport.height,
  9306. height: viewport.width,
  9307. rotation: (viewport.rotation - 90) % 360
  9308. };
  9309. }
  9310. return {
  9311. width: viewport.width,
  9312. height: viewport.height,
  9313. rotation: viewport.rotation
  9314. };
  9315. });
  9316. }
  9317. get optionalContentConfigPromise() {
  9318. if (!this.pdfDocument) {
  9319. return Promise.resolve(null);
  9320. }
  9321. if (!this._optionalContentConfigPromise) {
  9322. console.error("optionalContentConfigPromise: Not initialized yet.");
  9323. return this.pdfDocument.getOptionalContentConfig();
  9324. }
  9325. return this._optionalContentConfigPromise;
  9326. }
  9327. set optionalContentConfigPromise(promise) {
  9328. if (!(promise instanceof Promise)) {
  9329. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  9330. }
  9331. if (!this.pdfDocument) {
  9332. return;
  9333. }
  9334. if (!this._optionalContentConfigPromise) {
  9335. return;
  9336. }
  9337. this._optionalContentConfigPromise = promise;
  9338. this.refresh(false, {
  9339. optionalContentConfigPromise: promise
  9340. });
  9341. this.eventBus.dispatch("optionalcontentconfigchanged", {
  9342. source: this,
  9343. promise
  9344. });
  9345. }
  9346. get scrollMode() {
  9347. return this._scrollMode;
  9348. }
  9349. set scrollMode(mode) {
  9350. if (this._scrollMode === mode) {
  9351. return;
  9352. }
  9353. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9354. throw new Error(`Invalid scroll mode: ${mode}`);
  9355. }
  9356. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9357. return;
  9358. }
  9359. this._previousScrollMode = this._scrollMode;
  9360. this._scrollMode = mode;
  9361. this.eventBus.dispatch("scrollmodechanged", {
  9362. source: this,
  9363. mode
  9364. });
  9365. this._updateScrollMode(this._currentPageNumber);
  9366. }
  9367. _updateScrollMode(pageNumber = null) {
  9368. const scrollMode = this._scrollMode,
  9369. viewer = this.viewer;
  9370. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9371. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9372. if (!this.pdfDocument || !pageNumber) {
  9373. return;
  9374. }
  9375. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9376. this.#ensurePageViewVisible();
  9377. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9378. this._updateSpreadMode();
  9379. }
  9380. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9381. this.#setScale(this._currentScaleValue, {
  9382. noScroll: true
  9383. });
  9384. }
  9385. this._setCurrentPageNumber(pageNumber, true);
  9386. this.update();
  9387. }
  9388. get spreadMode() {
  9389. return this._spreadMode;
  9390. }
  9391. set spreadMode(mode) {
  9392. if (this._spreadMode === mode) {
  9393. return;
  9394. }
  9395. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9396. throw new Error(`Invalid spread mode: ${mode}`);
  9397. }
  9398. this._spreadMode = mode;
  9399. this.eventBus.dispatch("spreadmodechanged", {
  9400. source: this,
  9401. mode
  9402. });
  9403. this._updateSpreadMode(this._currentPageNumber);
  9404. }
  9405. _updateSpreadMode(pageNumber = null) {
  9406. if (!this.pdfDocument) {
  9407. return;
  9408. }
  9409. const viewer = this.viewer,
  9410. pages = this._pages;
  9411. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9412. this.#ensurePageViewVisible();
  9413. } else {
  9414. viewer.textContent = "";
  9415. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9416. for (const pageView of this._pages) {
  9417. viewer.append(pageView.div);
  9418. }
  9419. } else {
  9420. const parity = this._spreadMode - 1;
  9421. let spread = null;
  9422. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9423. if (spread === null) {
  9424. spread = document.createElement("div");
  9425. spread.className = "spread";
  9426. viewer.append(spread);
  9427. } else if (i % 2 === parity) {
  9428. spread = spread.cloneNode(false);
  9429. viewer.append(spread);
  9430. }
  9431. spread.append(pages[i].div);
  9432. }
  9433. }
  9434. }
  9435. if (!pageNumber) {
  9436. return;
  9437. }
  9438. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9439. this.#setScale(this._currentScaleValue, {
  9440. noScroll: true
  9441. });
  9442. }
  9443. this._setCurrentPageNumber(pageNumber, true);
  9444. this.update();
  9445. }
  9446. _getPageAdvance(currentPageNumber, previous = false) {
  9447. switch (this._scrollMode) {
  9448. case _ui_utils.ScrollMode.WRAPPED:
  9449. {
  9450. const {
  9451. views
  9452. } = this._getVisiblePages(),
  9453. pageLayout = new Map();
  9454. for (const {
  9455. id,
  9456. y,
  9457. percent,
  9458. widthPercent
  9459. } of views) {
  9460. if (percent === 0 || widthPercent < 100) {
  9461. continue;
  9462. }
  9463. let yArray = pageLayout.get(y);
  9464. if (!yArray) {
  9465. pageLayout.set(y, yArray ||= []);
  9466. }
  9467. yArray.push(id);
  9468. }
  9469. for (const yArray of pageLayout.values()) {
  9470. const currentIndex = yArray.indexOf(currentPageNumber);
  9471. if (currentIndex === -1) {
  9472. continue;
  9473. }
  9474. const numPages = yArray.length;
  9475. if (numPages === 1) {
  9476. break;
  9477. }
  9478. if (previous) {
  9479. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9480. const currentId = yArray[i],
  9481. expectedId = yArray[i + 1] - 1;
  9482. if (currentId < expectedId) {
  9483. return currentPageNumber - expectedId;
  9484. }
  9485. }
  9486. } else {
  9487. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9488. const currentId = yArray[i],
  9489. expectedId = yArray[i - 1] + 1;
  9490. if (currentId > expectedId) {
  9491. return expectedId - currentPageNumber;
  9492. }
  9493. }
  9494. }
  9495. if (previous) {
  9496. const firstId = yArray[0];
  9497. if (firstId < currentPageNumber) {
  9498. return currentPageNumber - firstId + 1;
  9499. }
  9500. } else {
  9501. const lastId = yArray[numPages - 1];
  9502. if (lastId > currentPageNumber) {
  9503. return lastId - currentPageNumber + 1;
  9504. }
  9505. }
  9506. break;
  9507. }
  9508. break;
  9509. }
  9510. case _ui_utils.ScrollMode.HORIZONTAL:
  9511. {
  9512. break;
  9513. }
  9514. case _ui_utils.ScrollMode.PAGE:
  9515. case _ui_utils.ScrollMode.VERTICAL:
  9516. {
  9517. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9518. break;
  9519. }
  9520. const parity = this._spreadMode - 1;
  9521. if (previous && currentPageNumber % 2 !== parity) {
  9522. break;
  9523. } else if (!previous && currentPageNumber % 2 === parity) {
  9524. break;
  9525. }
  9526. const {
  9527. views
  9528. } = this._getVisiblePages(),
  9529. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9530. for (const {
  9531. id,
  9532. percent,
  9533. widthPercent
  9534. } of views) {
  9535. if (id !== expectedId) {
  9536. continue;
  9537. }
  9538. if (percent > 0 && widthPercent === 100) {
  9539. return 2;
  9540. }
  9541. break;
  9542. }
  9543. break;
  9544. }
  9545. }
  9546. return 1;
  9547. }
  9548. nextPage() {
  9549. const currentPageNumber = this._currentPageNumber,
  9550. pagesCount = this.pagesCount;
  9551. if (currentPageNumber >= pagesCount) {
  9552. return false;
  9553. }
  9554. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9555. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9556. return true;
  9557. }
  9558. previousPage() {
  9559. const currentPageNumber = this._currentPageNumber;
  9560. if (currentPageNumber <= 1) {
  9561. return false;
  9562. }
  9563. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9564. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9565. return true;
  9566. }
  9567. increaseScale({
  9568. drawingDelay,
  9569. scaleFactor,
  9570. steps
  9571. } = {}) {
  9572. if (!this.pdfDocument) {
  9573. return;
  9574. }
  9575. let newScale = this._currentScale;
  9576. if (scaleFactor > 1) {
  9577. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  9578. } else {
  9579. steps ??= 1;
  9580. do {
  9581. newScale = Math.ceil((newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
  9582. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9583. }
  9584. this.#setScale(Math.min(_ui_utils.MAX_SCALE, newScale), {
  9585. noScroll: false,
  9586. drawingDelay
  9587. });
  9588. }
  9589. decreaseScale({
  9590. drawingDelay,
  9591. scaleFactor,
  9592. steps
  9593. } = {}) {
  9594. if (!this.pdfDocument) {
  9595. return;
  9596. }
  9597. let newScale = this._currentScale;
  9598. if (scaleFactor > 0 && scaleFactor < 1) {
  9599. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  9600. } else {
  9601. steps ??= 1;
  9602. do {
  9603. newScale = Math.floor((newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
  9604. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9605. }
  9606. this.#setScale(Math.max(_ui_utils.MIN_SCALE, newScale), {
  9607. noScroll: false,
  9608. drawingDelay
  9609. });
  9610. }
  9611. #updateContainerHeightCss(height = this.container.clientHeight) {
  9612. if (height !== this.#previousContainerHeight) {
  9613. this.#previousContainerHeight = height;
  9614. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  9615. }
  9616. }
  9617. #resizeObserverCallback(entries) {
  9618. for (const entry of entries) {
  9619. if (entry.target === this.container) {
  9620. this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
  9621. this.#containerTopLeft = null;
  9622. break;
  9623. }
  9624. }
  9625. }
  9626. get containerTopLeft() {
  9627. return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
  9628. }
  9629. get annotationEditorMode() {
  9630. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  9631. }
  9632. set annotationEditorMode({
  9633. mode,
  9634. editId = null
  9635. }) {
  9636. if (!this.#annotationEditorUIManager) {
  9637. throw new Error(`The AnnotationEditor is not enabled.`);
  9638. }
  9639. if (this.#annotationEditorMode === mode) {
  9640. return;
  9641. }
  9642. if (!isValidAnnotationEditorMode(mode)) {
  9643. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  9644. }
  9645. if (!this.pdfDocument) {
  9646. return;
  9647. }
  9648. this.#annotationEditorMode = mode;
  9649. this.eventBus.dispatch("annotationeditormodechanged", {
  9650. source: this,
  9651. mode
  9652. });
  9653. this.#annotationEditorUIManager.updateMode(mode, editId);
  9654. }
  9655. set annotationEditorParams({
  9656. type,
  9657. value
  9658. }) {
  9659. if (!this.#annotationEditorUIManager) {
  9660. throw new Error(`The AnnotationEditor is not enabled.`);
  9661. }
  9662. this.#annotationEditorUIManager.updateParams(type, value);
  9663. }
  9664. refresh(noUpdate = false, updateArgs = Object.create(null)) {
  9665. if (!this.pdfDocument) {
  9666. return;
  9667. }
  9668. for (const pageView of this._pages) {
  9669. pageView.update(updateArgs);
  9670. }
  9671. if (this.#scaleTimeoutId !== null) {
  9672. clearTimeout(this.#scaleTimeoutId);
  9673. this.#scaleTimeoutId = null;
  9674. }
  9675. if (!noUpdate) {
  9676. this.update();
  9677. }
  9678. }
  9679. }
  9680. exports.PDFViewer = PDFViewer;
  9681. /***/ }),
  9682. /* 29 */
  9683. /***/ ((__unused_webpack_module, exports) => {
  9684. Object.defineProperty(exports, "__esModule", ({
  9685. value: true
  9686. }));
  9687. exports.NullL10n = void 0;
  9688. exports.getL10nFallback = getL10nFallback;
  9689. const DEFAULT_L10N_STRINGS = {
  9690. of_pages: "of {{pagesCount}}",
  9691. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9692. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9693. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9694. document_properties_date_string: "{{date}}, {{time}}",
  9695. document_properties_page_size_unit_inches: "in",
  9696. document_properties_page_size_unit_millimeters: "mm",
  9697. document_properties_page_size_orientation_portrait: "portrait",
  9698. document_properties_page_size_orientation_landscape: "landscape",
  9699. document_properties_page_size_name_a3: "A3",
  9700. document_properties_page_size_name_a4: "A4",
  9701. document_properties_page_size_name_letter: "Letter",
  9702. document_properties_page_size_name_legal: "Legal",
  9703. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9704. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9705. document_properties_linearized_yes: "Yes",
  9706. document_properties_linearized_no: "No",
  9707. additional_layers: "Additional Layers",
  9708. page_landmark: "Page {{page}}",
  9709. thumb_page_title: "Page {{page}}",
  9710. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9711. find_reached_top: "Reached top of document, continued from bottom",
  9712. find_reached_bottom: "Reached end of document, continued from top",
  9713. "find_match_count[one]": "{{current}} of {{total}} match",
  9714. "find_match_count[other]": "{{current}} of {{total}} matches",
  9715. "find_match_count_limit[one]": "More than {{limit}} match",
  9716. "find_match_count_limit[other]": "More than {{limit}} matches",
  9717. find_not_found: "Phrase not found",
  9718. page_scale_width: "Page Width",
  9719. page_scale_fit: "Page Fit",
  9720. page_scale_auto: "Automatic Zoom",
  9721. page_scale_actual: "Actual Size",
  9722. page_scale_percent: "{{scale}}%",
  9723. loading_error: "An error occurred while loading the PDF.",
  9724. invalid_file_error: "Invalid or corrupted PDF file.",
  9725. missing_file_error: "Missing PDF file.",
  9726. unexpected_response_error: "Unexpected server response.",
  9727. rendering_error: "An error occurred while rendering the page.",
  9728. annotation_date_string: "{{date}}, {{time}}",
  9729. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9730. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9731. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  9732. free_text2_default_content: "Start typing…",
  9733. editor_free_text2_aria_label: "Text Editor",
  9734. editor_ink2_aria_label: "Draw Editor",
  9735. editor_ink_canvas_aria_label: "User-created image"
  9736. };
  9737. {
  9738. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  9739. }
  9740. function getL10nFallback(key, args) {
  9741. switch (key) {
  9742. case "find_match_count":
  9743. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9744. break;
  9745. case "find_match_count_limit":
  9746. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9747. break;
  9748. }
  9749. return DEFAULT_L10N_STRINGS[key] || "";
  9750. }
  9751. function formatL10nValue(text, args) {
  9752. if (!args) {
  9753. return text;
  9754. }
  9755. return text.replaceAll(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9756. return name in args ? args[name] : "{{" + name + "}}";
  9757. });
  9758. }
  9759. const NullL10n = {
  9760. async getLanguage() {
  9761. return "en-us";
  9762. },
  9763. async getDirection() {
  9764. return "ltr";
  9765. },
  9766. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9767. return formatL10nValue(fallback, args);
  9768. },
  9769. async translate(element) {}
  9770. };
  9771. exports.NullL10n = NullL10n;
  9772. /***/ }),
  9773. /* 30 */
  9774. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9775. Object.defineProperty(exports, "__esModule", ({
  9776. value: true
  9777. }));
  9778. exports.PDFPageView = void 0;
  9779. var _pdfjsLib = __webpack_require__(4);
  9780. var _ui_utils = __webpack_require__(3);
  9781. var _annotation_editor_layer_builder = __webpack_require__(31);
  9782. var _annotation_layer_builder = __webpack_require__(32);
  9783. var _app_options = __webpack_require__(5);
  9784. var _l10n_utils = __webpack_require__(29);
  9785. var _pdf_link_service = __webpack_require__(7);
  9786. var _struct_tree_layer_builder = __webpack_require__(33);
  9787. var _text_accessibility = __webpack_require__(34);
  9788. var _text_highlighter = __webpack_require__(35);
  9789. var _text_layer_builder = __webpack_require__(36);
  9790. var _xfa_layer_builder = __webpack_require__(37);
  9791. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9792. const DEFAULT_LAYER_PROPERTIES = () => {
  9793. return null;
  9794. };
  9795. class PDFPageView {
  9796. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9797. #hasRestrictedScaling = false;
  9798. #layerProperties = null;
  9799. #loadingId = null;
  9800. #previousRotation = null;
  9801. #renderError = null;
  9802. #renderingState = _ui_utils.RenderingStates.INITIAL;
  9803. #textLayerMode = _ui_utils.TextLayerMode.ENABLE;
  9804. #useThumbnailCanvas = {
  9805. directDrawing: true,
  9806. initialOptionalContent: true,
  9807. regularAnnotations: true
  9808. };
  9809. #viewportMap = new WeakMap();
  9810. constructor(options) {
  9811. const container = options.container;
  9812. const defaultViewport = options.defaultViewport;
  9813. this.id = options.id;
  9814. this.renderingId = "page" + this.id;
  9815. this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
  9816. this.pdfPage = null;
  9817. this.pageLabel = null;
  9818. this.rotation = 0;
  9819. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9820. this.viewport = defaultViewport;
  9821. this.pdfPageRotate = defaultViewport.rotation;
  9822. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9823. this.#textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9824. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9825. this.imageResourcesPath = options.imageResourcesPath || "";
  9826. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  9827. this.maxCanvasPixels = options.maxCanvasPixels ?? MAX_CANVAS_PIXELS;
  9828. this.pageColors = options.pageColors || null;
  9829. this.eventBus = options.eventBus;
  9830. this.renderingQueue = options.renderingQueue;
  9831. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9832. this.renderTask = null;
  9833. this.resume = null;
  9834. this._isStandalone = !this.renderingQueue?.hasViewer();
  9835. this._container = container;
  9836. if (options.useOnlyCssZoom) {
  9837. console.error("useOnlyCssZoom was removed, please use `maxCanvasPixels = 0` instead.");
  9838. this.maxCanvasPixels = 0;
  9839. }
  9840. this._annotationCanvasMap = null;
  9841. this.annotationLayer = null;
  9842. this.annotationEditorLayer = null;
  9843. this.textLayer = null;
  9844. this.zoomLayer = null;
  9845. this.xfaLayer = null;
  9846. this.structTreeLayer = null;
  9847. const div = document.createElement("div");
  9848. div.className = "page";
  9849. div.setAttribute("data-page-number", this.id);
  9850. div.setAttribute("role", "region");
  9851. this.l10n.get("page_landmark", {
  9852. page: this.id
  9853. }).then(msg => {
  9854. div.setAttribute("aria-label", msg);
  9855. });
  9856. this.div = div;
  9857. this.#setDimensions();
  9858. container?.append(div);
  9859. if (this._isStandalone) {
  9860. container?.style.setProperty("--scale-factor", this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  9861. const {
  9862. optionalContentConfigPromise
  9863. } = options;
  9864. if (optionalContentConfigPromise) {
  9865. optionalContentConfigPromise.then(optionalContentConfig => {
  9866. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9867. return;
  9868. }
  9869. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9870. });
  9871. }
  9872. }
  9873. }
  9874. get renderingState() {
  9875. return this.#renderingState;
  9876. }
  9877. set renderingState(state) {
  9878. if (state === this.#renderingState) {
  9879. return;
  9880. }
  9881. this.#renderingState = state;
  9882. if (this.#loadingId) {
  9883. clearTimeout(this.#loadingId);
  9884. this.#loadingId = null;
  9885. }
  9886. switch (state) {
  9887. case _ui_utils.RenderingStates.PAUSED:
  9888. this.div.classList.remove("loading");
  9889. break;
  9890. case _ui_utils.RenderingStates.RUNNING:
  9891. this.div.classList.add("loadingIcon");
  9892. this.#loadingId = setTimeout(() => {
  9893. this.div.classList.add("loading");
  9894. this.#loadingId = null;
  9895. }, 0);
  9896. break;
  9897. case _ui_utils.RenderingStates.INITIAL:
  9898. case _ui_utils.RenderingStates.FINISHED:
  9899. this.div.classList.remove("loadingIcon", "loading");
  9900. break;
  9901. }
  9902. }
  9903. #setDimensions() {
  9904. const {
  9905. viewport
  9906. } = this;
  9907. if (this.pdfPage) {
  9908. if (this.#previousRotation === viewport.rotation) {
  9909. return;
  9910. }
  9911. this.#previousRotation = viewport.rotation;
  9912. }
  9913. (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false);
  9914. }
  9915. setPdfPage(pdfPage) {
  9916. if (this._isStandalone && (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas")) {
  9917. this._container?.style.setProperty("--hcm-highligh-filter", pdfPage.filterFactory.addHighlightHCMFilter("CanvasText", "Canvas", "HighlightText", "Highlight"));
  9918. }
  9919. this.pdfPage = pdfPage;
  9920. this.pdfPageRotate = pdfPage.rotate;
  9921. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9922. this.viewport = pdfPage.getViewport({
  9923. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9924. rotation: totalRotation
  9925. });
  9926. this.#setDimensions();
  9927. this.reset();
  9928. }
  9929. destroy() {
  9930. this.reset();
  9931. this.pdfPage?.cleanup();
  9932. }
  9933. get _textHighlighter() {
  9934. return (0, _pdfjsLib.shadow)(this, "_textHighlighter", new _text_highlighter.TextHighlighter({
  9935. pageIndex: this.id - 1,
  9936. eventBus: this.eventBus,
  9937. findController: this.#layerProperties().findController
  9938. }));
  9939. }
  9940. async #renderAnnotationLayer() {
  9941. let error = null;
  9942. try {
  9943. await this.annotationLayer.render(this.viewport, "display");
  9944. } catch (ex) {
  9945. console.error(`#renderAnnotationLayer: "${ex}".`);
  9946. error = ex;
  9947. } finally {
  9948. this.eventBus.dispatch("annotationlayerrendered", {
  9949. source: this,
  9950. pageNumber: this.id,
  9951. error
  9952. });
  9953. }
  9954. }
  9955. async #renderAnnotationEditorLayer() {
  9956. let error = null;
  9957. try {
  9958. await this.annotationEditorLayer.render(this.viewport, "display");
  9959. } catch (ex) {
  9960. console.error(`#renderAnnotationEditorLayer: "${ex}".`);
  9961. error = ex;
  9962. } finally {
  9963. this.eventBus.dispatch("annotationeditorlayerrendered", {
  9964. source: this,
  9965. pageNumber: this.id,
  9966. error
  9967. });
  9968. }
  9969. }
  9970. async #renderXfaLayer() {
  9971. let error = null;
  9972. try {
  9973. const result = await this.xfaLayer.render(this.viewport, "display");
  9974. if (result?.textDivs && this._textHighlighter) {
  9975. this.#buildXfaTextContentItems(result.textDivs);
  9976. }
  9977. } catch (ex) {
  9978. console.error(`#renderXfaLayer: "${ex}".`);
  9979. error = ex;
  9980. } finally {
  9981. this.eventBus.dispatch("xfalayerrendered", {
  9982. source: this,
  9983. pageNumber: this.id,
  9984. error
  9985. });
  9986. }
  9987. }
  9988. async #renderTextLayer() {
  9989. const {
  9990. pdfPage,
  9991. textLayer,
  9992. viewport
  9993. } = this;
  9994. if (!textLayer) {
  9995. return;
  9996. }
  9997. let error = null;
  9998. try {
  9999. if (!textLayer.renderingDone) {
  10000. const readableStream = pdfPage.streamTextContent({
  10001. includeMarkedContent: true,
  10002. disableNormalization: true
  10003. });
  10004. textLayer.setTextContentSource(readableStream);
  10005. }
  10006. await textLayer.render(viewport);
  10007. } catch (ex) {
  10008. if (ex instanceof _pdfjsLib.AbortException) {
  10009. return;
  10010. }
  10011. console.error(`#renderTextLayer: "${ex}".`);
  10012. error = ex;
  10013. }
  10014. this.eventBus.dispatch("textlayerrendered", {
  10015. source: this,
  10016. pageNumber: this.id,
  10017. numTextDivs: textLayer.numTextDivs,
  10018. error
  10019. });
  10020. this.#renderStructTreeLayer();
  10021. }
  10022. async #renderStructTreeLayer() {
  10023. if (!this.textLayer) {
  10024. return;
  10025. }
  10026. this.structTreeLayer ||= new _struct_tree_layer_builder.StructTreeLayerBuilder();
  10027. const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
  10028. const treeDom = this.structTreeLayer?.render(tree);
  10029. if (treeDom) {
  10030. this.canvas?.append(treeDom);
  10031. }
  10032. this.structTreeLayer?.show();
  10033. }
  10034. async #buildXfaTextContentItems(textDivs) {
  10035. const text = await this.pdfPage.getTextContent();
  10036. const items = [];
  10037. for (const item of text.items) {
  10038. items.push(item.str);
  10039. }
  10040. this._textHighlighter.setTextMapping(textDivs, items);
  10041. this._textHighlighter.enable();
  10042. }
  10043. _resetZoomLayer(removeFromDOM = false) {
  10044. if (!this.zoomLayer) {
  10045. return;
  10046. }
  10047. const zoomLayerCanvas = this.zoomLayer.firstChild;
  10048. this.#viewportMap.delete(zoomLayerCanvas);
  10049. zoomLayerCanvas.width = 0;
  10050. zoomLayerCanvas.height = 0;
  10051. if (removeFromDOM) {
  10052. this.zoomLayer.remove();
  10053. }
  10054. this.zoomLayer = null;
  10055. }
  10056. reset({
  10057. keepZoomLayer = false,
  10058. keepAnnotationLayer = false,
  10059. keepAnnotationEditorLayer = false,
  10060. keepXfaLayer = false,
  10061. keepTextLayer = false
  10062. } = {}) {
  10063. this.cancelRendering({
  10064. keepAnnotationLayer,
  10065. keepAnnotationEditorLayer,
  10066. keepXfaLayer,
  10067. keepTextLayer
  10068. });
  10069. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  10070. const div = this.div;
  10071. const childNodes = div.childNodes,
  10072. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  10073. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  10074. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  10075. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
  10076. textLayerNode = keepTextLayer && this.textLayer?.div || null;
  10077. for (let i = childNodes.length - 1; i >= 0; i--) {
  10078. const node = childNodes[i];
  10079. switch (node) {
  10080. case zoomLayerNode:
  10081. case annotationLayerNode:
  10082. case annotationEditorLayerNode:
  10083. case xfaLayerNode:
  10084. case textLayerNode:
  10085. continue;
  10086. }
  10087. node.remove();
  10088. }
  10089. div.removeAttribute("data-loaded");
  10090. if (annotationLayerNode) {
  10091. this.annotationLayer.hide();
  10092. }
  10093. if (annotationEditorLayerNode) {
  10094. this.annotationEditorLayer.hide();
  10095. }
  10096. if (xfaLayerNode) {
  10097. this.xfaLayer.hide();
  10098. }
  10099. if (textLayerNode) {
  10100. this.textLayer.hide();
  10101. }
  10102. this.structTreeLayer?.hide();
  10103. if (!zoomLayerNode) {
  10104. if (this.canvas) {
  10105. this.#viewportMap.delete(this.canvas);
  10106. this.canvas.width = 0;
  10107. this.canvas.height = 0;
  10108. delete this.canvas;
  10109. }
  10110. this._resetZoomLayer();
  10111. }
  10112. }
  10113. update({
  10114. scale = 0,
  10115. rotation = null,
  10116. optionalContentConfigPromise = null,
  10117. drawingDelay = -1
  10118. }) {
  10119. this.scale = scale || this.scale;
  10120. if (typeof rotation === "number") {
  10121. this.rotation = rotation;
  10122. }
  10123. if (optionalContentConfigPromise instanceof Promise) {
  10124. this._optionalContentConfigPromise = optionalContentConfigPromise;
  10125. optionalContentConfigPromise.then(optionalContentConfig => {
  10126. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  10127. return;
  10128. }
  10129. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  10130. });
  10131. }
  10132. this.#useThumbnailCanvas.directDrawing = true;
  10133. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  10134. this.viewport = this.viewport.clone({
  10135. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  10136. rotation: totalRotation
  10137. });
  10138. this.#setDimensions();
  10139. if (this._isStandalone) {
  10140. this._container?.style.setProperty("--scale-factor", this.viewport.scale);
  10141. }
  10142. if (this.canvas) {
  10143. let onlyCssZoom = false;
  10144. if (this.#hasRestrictedScaling) {
  10145. if (this.maxCanvasPixels === 0) {
  10146. onlyCssZoom = true;
  10147. } else if (this.maxCanvasPixels > 0) {
  10148. const {
  10149. width,
  10150. height
  10151. } = this.viewport;
  10152. const {
  10153. sx,
  10154. sy
  10155. } = this.outputScale;
  10156. onlyCssZoom = (Math.floor(width) * sx | 0) * (Math.floor(height) * sy | 0) > this.maxCanvasPixels;
  10157. }
  10158. }
  10159. const postponeDrawing = !onlyCssZoom && drawingDelay >= 0 && drawingDelay < 1000;
  10160. if (postponeDrawing || onlyCssZoom) {
  10161. if (postponeDrawing && this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  10162. this.cancelRendering({
  10163. keepZoomLayer: true,
  10164. keepAnnotationLayer: true,
  10165. keepAnnotationEditorLayer: true,
  10166. keepXfaLayer: true,
  10167. keepTextLayer: true,
  10168. cancelExtraDelay: drawingDelay
  10169. });
  10170. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10171. this.#useThumbnailCanvas.directDrawing = false;
  10172. }
  10173. this.cssTransform({
  10174. target: this.canvas,
  10175. redrawAnnotationLayer: true,
  10176. redrawAnnotationEditorLayer: true,
  10177. redrawXfaLayer: true,
  10178. redrawTextLayer: !postponeDrawing,
  10179. hideTextLayer: postponeDrawing
  10180. });
  10181. if (postponeDrawing) {
  10182. return;
  10183. }
  10184. this.eventBus.dispatch("pagerendered", {
  10185. source: this,
  10186. pageNumber: this.id,
  10187. cssTransform: true,
  10188. timestamp: performance.now(),
  10189. error: this.#renderError
  10190. });
  10191. return;
  10192. }
  10193. if (!this.zoomLayer && !this.canvas.hidden) {
  10194. this.zoomLayer = this.canvas.parentNode;
  10195. this.zoomLayer.style.position = "absolute";
  10196. }
  10197. }
  10198. if (this.zoomLayer) {
  10199. this.cssTransform({
  10200. target: this.zoomLayer.firstChild
  10201. });
  10202. }
  10203. this.reset({
  10204. keepZoomLayer: true,
  10205. keepAnnotationLayer: true,
  10206. keepAnnotationEditorLayer: true,
  10207. keepXfaLayer: true,
  10208. keepTextLayer: true
  10209. });
  10210. }
  10211. cancelRendering({
  10212. keepAnnotationLayer = false,
  10213. keepAnnotationEditorLayer = false,
  10214. keepXfaLayer = false,
  10215. keepTextLayer = false,
  10216. cancelExtraDelay = 0
  10217. } = {}) {
  10218. if (this.renderTask) {
  10219. this.renderTask.cancel(cancelExtraDelay);
  10220. this.renderTask = null;
  10221. }
  10222. this.resume = null;
  10223. if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
  10224. this.textLayer.cancel();
  10225. this.textLayer = null;
  10226. }
  10227. if (this.structTreeLayer && !this.textLayer) {
  10228. this.structTreeLayer = null;
  10229. }
  10230. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  10231. this.annotationLayer.cancel();
  10232. this.annotationLayer = null;
  10233. this._annotationCanvasMap = null;
  10234. }
  10235. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  10236. this.annotationEditorLayer.cancel();
  10237. this.annotationEditorLayer = null;
  10238. }
  10239. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  10240. this.xfaLayer.cancel();
  10241. this.xfaLayer = null;
  10242. this._textHighlighter?.disable();
  10243. }
  10244. }
  10245. cssTransform({
  10246. target,
  10247. redrawAnnotationLayer = false,
  10248. redrawAnnotationEditorLayer = false,
  10249. redrawXfaLayer = false,
  10250. redrawTextLayer = false,
  10251. hideTextLayer = false
  10252. }) {
  10253. if (!target.hasAttribute("zooming")) {
  10254. target.setAttribute("zooming", true);
  10255. const {
  10256. style
  10257. } = target;
  10258. style.width = style.height = "";
  10259. }
  10260. const originalViewport = this.#viewportMap.get(target);
  10261. if (this.viewport !== originalViewport) {
  10262. const relativeRotation = this.viewport.rotation - originalViewport.rotation;
  10263. const absRotation = Math.abs(relativeRotation);
  10264. let scaleX = 1,
  10265. scaleY = 1;
  10266. if (absRotation === 90 || absRotation === 270) {
  10267. const {
  10268. width,
  10269. height
  10270. } = this.viewport;
  10271. scaleX = height / width;
  10272. scaleY = width / height;
  10273. }
  10274. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  10275. }
  10276. if (redrawAnnotationLayer && this.annotationLayer) {
  10277. this.#renderAnnotationLayer();
  10278. }
  10279. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  10280. this.#renderAnnotationEditorLayer();
  10281. }
  10282. if (redrawXfaLayer && this.xfaLayer) {
  10283. this.#renderXfaLayer();
  10284. }
  10285. if (this.textLayer) {
  10286. if (hideTextLayer) {
  10287. this.textLayer.hide();
  10288. this.structTreeLayer?.hide();
  10289. } else if (redrawTextLayer) {
  10290. this.#renderTextLayer();
  10291. }
  10292. }
  10293. }
  10294. get width() {
  10295. return this.viewport.width;
  10296. }
  10297. get height() {
  10298. return this.viewport.height;
  10299. }
  10300. getPagePoint(x, y) {
  10301. return this.viewport.convertToPdfPoint(x, y);
  10302. }
  10303. async #finishRenderTask(renderTask, error = null) {
  10304. if (renderTask === this.renderTask) {
  10305. this.renderTask = null;
  10306. }
  10307. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  10308. this.#renderError = null;
  10309. return;
  10310. }
  10311. this.#renderError = error;
  10312. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10313. this._resetZoomLayer(true);
  10314. this.#useThumbnailCanvas.regularAnnotations = !renderTask.separateAnnots;
  10315. this.eventBus.dispatch("pagerendered", {
  10316. source: this,
  10317. pageNumber: this.id,
  10318. cssTransform: false,
  10319. timestamp: performance.now(),
  10320. error: this.#renderError
  10321. });
  10322. if (error) {
  10323. throw error;
  10324. }
  10325. }
  10326. async draw() {
  10327. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  10328. console.error("Must be in new state before drawing");
  10329. this.reset();
  10330. }
  10331. const {
  10332. div,
  10333. l10n,
  10334. pageColors,
  10335. pdfPage,
  10336. viewport
  10337. } = this;
  10338. if (!pdfPage) {
  10339. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10340. throw new Error("pdfPage is not loaded");
  10341. }
  10342. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10343. const canvasWrapper = document.createElement("div");
  10344. canvasWrapper.classList.add("canvasWrapper");
  10345. div.append(canvasWrapper);
  10346. if (!this.textLayer && this.#textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
  10347. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  10348. this.textLayer = new _text_layer_builder.TextLayerBuilder({
  10349. highlighter: this._textHighlighter,
  10350. accessibilityManager: this._accessibilityManager,
  10351. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  10352. enablePermissions: this.#textLayerMode === _ui_utils.TextLayerMode.ENABLE_PERMISSIONS
  10353. });
  10354. div.append(this.textLayer.div);
  10355. }
  10356. if (!this.annotationLayer && this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE) {
  10357. const {
  10358. annotationStorage,
  10359. downloadManager,
  10360. enableScripting,
  10361. fieldObjectsPromise,
  10362. hasJSActionsPromise,
  10363. linkService
  10364. } = this.#layerProperties();
  10365. this._annotationCanvasMap ||= new Map();
  10366. this.annotationLayer = new _annotation_layer_builder.AnnotationLayerBuilder({
  10367. pageDiv: div,
  10368. pdfPage,
  10369. annotationStorage,
  10370. imageResourcesPath: this.imageResourcesPath,
  10371. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  10372. linkService,
  10373. downloadManager,
  10374. l10n,
  10375. enableScripting,
  10376. hasJSActionsPromise,
  10377. fieldObjectsPromise,
  10378. annotationCanvasMap: this._annotationCanvasMap,
  10379. accessibilityManager: this._accessibilityManager
  10380. });
  10381. }
  10382. const renderContinueCallback = cont => {
  10383. showCanvas?.(false);
  10384. if (this.renderingQueue && !this.renderingQueue.isHighestPriority(this)) {
  10385. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  10386. this.resume = () => {
  10387. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10388. cont();
  10389. };
  10390. return;
  10391. }
  10392. cont();
  10393. };
  10394. const {
  10395. width,
  10396. height
  10397. } = viewport;
  10398. const canvas = document.createElement("canvas");
  10399. canvas.setAttribute("role", "presentation");
  10400. canvas.hidden = true;
  10401. const hasHCM = !!(pageColors?.background && pageColors?.foreground);
  10402. let showCanvas = isLastShow => {
  10403. if (!hasHCM || isLastShow) {
  10404. canvas.hidden = false;
  10405. showCanvas = null;
  10406. }
  10407. };
  10408. canvasWrapper.append(canvas);
  10409. this.canvas = canvas;
  10410. const ctx = canvas.getContext("2d", {
  10411. alpha: false
  10412. });
  10413. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  10414. if (this.maxCanvasPixels === 0) {
  10415. const invScale = 1 / this.scale;
  10416. outputScale.sx *= invScale;
  10417. outputScale.sy *= invScale;
  10418. this.#hasRestrictedScaling = true;
  10419. } else if (this.maxCanvasPixels > 0) {
  10420. const pixelsInViewport = width * height;
  10421. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  10422. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  10423. outputScale.sx = maxScale;
  10424. outputScale.sy = maxScale;
  10425. this.#hasRestrictedScaling = true;
  10426. } else {
  10427. this.#hasRestrictedScaling = false;
  10428. }
  10429. }
  10430. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  10431. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  10432. canvas.width = (0, _ui_utils.roundToDivide)(width * outputScale.sx, sfx[0]);
  10433. canvas.height = (0, _ui_utils.roundToDivide)(height * outputScale.sy, sfy[0]);
  10434. const {
  10435. style
  10436. } = canvas;
  10437. style.width = (0, _ui_utils.roundToDivide)(width, sfx[1]) + "px";
  10438. style.height = (0, _ui_utils.roundToDivide)(height, sfy[1]) + "px";
  10439. this.#viewportMap.set(canvas, viewport);
  10440. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10441. const renderContext = {
  10442. canvasContext: ctx,
  10443. transform,
  10444. viewport,
  10445. annotationMode: this.#annotationMode,
  10446. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10447. annotationCanvasMap: this._annotationCanvasMap,
  10448. pageColors
  10449. };
  10450. const renderTask = this.renderTask = this.pdfPage.render(renderContext);
  10451. renderTask.onContinue = renderContinueCallback;
  10452. const resultPromise = renderTask.promise.then(async () => {
  10453. showCanvas?.(true);
  10454. await this.#finishRenderTask(renderTask);
  10455. this.#renderTextLayer();
  10456. if (this.annotationLayer) {
  10457. await this.#renderAnnotationLayer();
  10458. }
  10459. if (!this.annotationEditorLayer) {
  10460. const {
  10461. annotationEditorUIManager
  10462. } = this.#layerProperties();
  10463. if (!annotationEditorUIManager) {
  10464. return;
  10465. }
  10466. this.annotationEditorLayer = new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  10467. uiManager: annotationEditorUIManager,
  10468. pageDiv: div,
  10469. pdfPage,
  10470. l10n,
  10471. accessibilityManager: this._accessibilityManager,
  10472. annotationLayer: this.annotationLayer?.annotationLayer
  10473. });
  10474. }
  10475. this.#renderAnnotationEditorLayer();
  10476. }, error => {
  10477. if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
  10478. showCanvas?.(true);
  10479. }
  10480. return this.#finishRenderTask(renderTask, error);
  10481. });
  10482. if (pdfPage.isPureXfa) {
  10483. if (!this.xfaLayer) {
  10484. const {
  10485. annotationStorage,
  10486. linkService
  10487. } = this.#layerProperties();
  10488. this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({
  10489. pageDiv: div,
  10490. pdfPage,
  10491. annotationStorage,
  10492. linkService
  10493. });
  10494. } else if (this.xfaLayer.div) {
  10495. div.append(this.xfaLayer.div);
  10496. }
  10497. this.#renderXfaLayer();
  10498. }
  10499. div.setAttribute("data-loaded", true);
  10500. this.eventBus.dispatch("pagerender", {
  10501. source: this,
  10502. pageNumber: this.id
  10503. });
  10504. return resultPromise;
  10505. }
  10506. setPageLabel(label) {
  10507. this.pageLabel = typeof label === "string" ? label : null;
  10508. if (this.pageLabel !== null) {
  10509. this.div.setAttribute("data-page-label", this.pageLabel);
  10510. } else {
  10511. this.div.removeAttribute("data-page-label");
  10512. }
  10513. }
  10514. get thumbnailCanvas() {
  10515. const {
  10516. directDrawing,
  10517. initialOptionalContent,
  10518. regularAnnotations
  10519. } = this.#useThumbnailCanvas;
  10520. return directDrawing && initialOptionalContent && regularAnnotations ? this.canvas : null;
  10521. }
  10522. }
  10523. exports.PDFPageView = PDFPageView;
  10524. /***/ }),
  10525. /* 31 */
  10526. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10527. Object.defineProperty(exports, "__esModule", ({
  10528. value: true
  10529. }));
  10530. exports.AnnotationEditorLayerBuilder = void 0;
  10531. var _pdfjsLib = __webpack_require__(4);
  10532. var _l10n_utils = __webpack_require__(29);
  10533. class AnnotationEditorLayerBuilder {
  10534. #annotationLayer = null;
  10535. #uiManager;
  10536. constructor(options) {
  10537. this.pageDiv = options.pageDiv;
  10538. this.pdfPage = options.pdfPage;
  10539. this.accessibilityManager = options.accessibilityManager;
  10540. this.l10n = options.l10n || _l10n_utils.NullL10n;
  10541. this.annotationEditorLayer = null;
  10542. this.div = null;
  10543. this._cancelled = false;
  10544. this.#uiManager = options.uiManager;
  10545. this.#annotationLayer = options.annotationLayer || null;
  10546. }
  10547. async render(viewport, intent = "display") {
  10548. if (intent !== "display") {
  10549. return;
  10550. }
  10551. if (this._cancelled) {
  10552. return;
  10553. }
  10554. const clonedViewport = viewport.clone({
  10555. dontFlip: true
  10556. });
  10557. if (this.div) {
  10558. this.annotationEditorLayer.update({
  10559. viewport: clonedViewport
  10560. });
  10561. this.show();
  10562. return;
  10563. }
  10564. const div = this.div = document.createElement("div");
  10565. div.className = "annotationEditorLayer";
  10566. div.tabIndex = 0;
  10567. div.hidden = true;
  10568. this.pageDiv.append(div);
  10569. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  10570. uiManager: this.#uiManager,
  10571. div,
  10572. accessibilityManager: this.accessibilityManager,
  10573. pageIndex: this.pdfPage.pageNumber - 1,
  10574. l10n: this.l10n,
  10575. viewport: clonedViewport,
  10576. annotationLayer: this.#annotationLayer
  10577. });
  10578. const parameters = {
  10579. viewport: clonedViewport,
  10580. div,
  10581. annotations: null,
  10582. intent
  10583. };
  10584. this.annotationEditorLayer.render(parameters);
  10585. this.show();
  10586. }
  10587. cancel() {
  10588. this._cancelled = true;
  10589. if (!this.div) {
  10590. return;
  10591. }
  10592. this.pageDiv = null;
  10593. this.annotationEditorLayer.destroy();
  10594. this.div.remove();
  10595. }
  10596. hide() {
  10597. if (!this.div) {
  10598. return;
  10599. }
  10600. this.div.hidden = true;
  10601. }
  10602. show() {
  10603. if (!this.div || this.annotationEditorLayer.isEmpty) {
  10604. return;
  10605. }
  10606. this.div.hidden = false;
  10607. }
  10608. }
  10609. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  10610. /***/ }),
  10611. /* 32 */
  10612. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10613. Object.defineProperty(exports, "__esModule", ({
  10614. value: true
  10615. }));
  10616. exports.AnnotationLayerBuilder = void 0;
  10617. var _pdfjsLib = __webpack_require__(4);
  10618. var _l10n_utils = __webpack_require__(29);
  10619. var _ui_utils = __webpack_require__(3);
  10620. class AnnotationLayerBuilder {
  10621. #onPresentationModeChanged = null;
  10622. constructor({
  10623. pageDiv,
  10624. pdfPage,
  10625. linkService,
  10626. downloadManager,
  10627. annotationStorage = null,
  10628. imageResourcesPath = "",
  10629. renderForms = true,
  10630. l10n = _l10n_utils.NullL10n,
  10631. enableScripting = false,
  10632. hasJSActionsPromise = null,
  10633. fieldObjectsPromise = null,
  10634. annotationCanvasMap = null,
  10635. accessibilityManager = null
  10636. }) {
  10637. this.pageDiv = pageDiv;
  10638. this.pdfPage = pdfPage;
  10639. this.linkService = linkService;
  10640. this.downloadManager = downloadManager;
  10641. this.imageResourcesPath = imageResourcesPath;
  10642. this.renderForms = renderForms;
  10643. this.l10n = l10n;
  10644. this.annotationStorage = annotationStorage;
  10645. this.enableScripting = enableScripting;
  10646. this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
  10647. this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
  10648. this._annotationCanvasMap = annotationCanvasMap;
  10649. this._accessibilityManager = accessibilityManager;
  10650. this.annotationLayer = null;
  10651. this.div = null;
  10652. this._cancelled = false;
  10653. this._eventBus = linkService.eventBus;
  10654. }
  10655. async render(viewport, intent = "display") {
  10656. if (this.div) {
  10657. if (this._cancelled || !this.annotationLayer) {
  10658. return;
  10659. }
  10660. this.annotationLayer.update({
  10661. viewport: viewport.clone({
  10662. dontFlip: true
  10663. })
  10664. });
  10665. return;
  10666. }
  10667. const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
  10668. intent
  10669. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  10670. if (this._cancelled) {
  10671. return;
  10672. }
  10673. const div = this.div = document.createElement("div");
  10674. div.className = "annotationLayer";
  10675. this.pageDiv.append(div);
  10676. if (annotations.length === 0) {
  10677. this.hide();
  10678. return;
  10679. }
  10680. this.annotationLayer = new _pdfjsLib.AnnotationLayer({
  10681. div,
  10682. accessibilityManager: this._accessibilityManager,
  10683. annotationCanvasMap: this._annotationCanvasMap,
  10684. l10n: this.l10n,
  10685. page: this.pdfPage,
  10686. viewport: viewport.clone({
  10687. dontFlip: true
  10688. })
  10689. });
  10690. await this.annotationLayer.render({
  10691. annotations,
  10692. imageResourcesPath: this.imageResourcesPath,
  10693. renderForms: this.renderForms,
  10694. linkService: this.linkService,
  10695. downloadManager: this.downloadManager,
  10696. annotationStorage: this.annotationStorage,
  10697. enableScripting: this.enableScripting,
  10698. hasJSActions,
  10699. fieldObjects
  10700. });
  10701. if (this.linkService.isInPresentationMode) {
  10702. this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN);
  10703. }
  10704. if (!this.#onPresentationModeChanged) {
  10705. this.#onPresentationModeChanged = evt => {
  10706. this.#updatePresentationModeState(evt.state);
  10707. };
  10708. this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged);
  10709. }
  10710. }
  10711. cancel() {
  10712. this._cancelled = true;
  10713. if (this.#onPresentationModeChanged) {
  10714. this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged);
  10715. this.#onPresentationModeChanged = null;
  10716. }
  10717. }
  10718. hide() {
  10719. if (!this.div) {
  10720. return;
  10721. }
  10722. this.div.hidden = true;
  10723. }
  10724. #updatePresentationModeState(state) {
  10725. if (!this.div) {
  10726. return;
  10727. }
  10728. let disableFormElements = false;
  10729. switch (state) {
  10730. case _ui_utils.PresentationModeState.FULLSCREEN:
  10731. disableFormElements = true;
  10732. break;
  10733. case _ui_utils.PresentationModeState.NORMAL:
  10734. break;
  10735. default:
  10736. return;
  10737. }
  10738. for (const section of this.div.childNodes) {
  10739. if (section.hasAttribute("data-internal-link")) {
  10740. continue;
  10741. }
  10742. section.inert = disableFormElements;
  10743. }
  10744. }
  10745. }
  10746. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  10747. /***/ }),
  10748. /* 33 */
  10749. /***/ ((__unused_webpack_module, exports) => {
  10750. Object.defineProperty(exports, "__esModule", ({
  10751. value: true
  10752. }));
  10753. exports.StructTreeLayerBuilder = void 0;
  10754. const PDF_ROLE_TO_HTML_ROLE = {
  10755. Document: null,
  10756. DocumentFragment: null,
  10757. Part: "group",
  10758. Sect: "group",
  10759. Div: "group",
  10760. Aside: "note",
  10761. NonStruct: "none",
  10762. P: null,
  10763. H: "heading",
  10764. Title: null,
  10765. FENote: "note",
  10766. Sub: "group",
  10767. Lbl: null,
  10768. Span: null,
  10769. Em: null,
  10770. Strong: null,
  10771. Link: "link",
  10772. Annot: "note",
  10773. Form: "form",
  10774. Ruby: null,
  10775. RB: null,
  10776. RT: null,
  10777. RP: null,
  10778. Warichu: null,
  10779. WT: null,
  10780. WP: null,
  10781. L: "list",
  10782. LI: "listitem",
  10783. LBody: null,
  10784. Table: "table",
  10785. TR: "row",
  10786. TH: "columnheader",
  10787. TD: "cell",
  10788. THead: "columnheader",
  10789. TBody: null,
  10790. TFoot: null,
  10791. Caption: null,
  10792. Figure: "figure",
  10793. Formula: null,
  10794. Artifact: null
  10795. };
  10796. const HEADING_PATTERN = /^H(\d+)$/;
  10797. class StructTreeLayerBuilder {
  10798. #treeDom = undefined;
  10799. get renderingDone() {
  10800. return this.#treeDom !== undefined;
  10801. }
  10802. render(structTree) {
  10803. if (this.#treeDom !== undefined) {
  10804. return this.#treeDom;
  10805. }
  10806. const treeDom = this.#walk(structTree);
  10807. treeDom?.classList.add("structTree");
  10808. return this.#treeDom = treeDom;
  10809. }
  10810. hide() {
  10811. if (this.#treeDom && !this.#treeDom.hidden) {
  10812. this.#treeDom.hidden = true;
  10813. }
  10814. }
  10815. show() {
  10816. if (this.#treeDom?.hidden) {
  10817. this.#treeDom.hidden = false;
  10818. }
  10819. }
  10820. #setAttributes(structElement, htmlElement) {
  10821. if (structElement.alt !== undefined) {
  10822. htmlElement.setAttribute("aria-label", structElement.alt);
  10823. }
  10824. if (structElement.id !== undefined) {
  10825. htmlElement.setAttribute("aria-owns", structElement.id);
  10826. }
  10827. if (structElement.lang !== undefined) {
  10828. htmlElement.setAttribute("lang", structElement.lang);
  10829. }
  10830. }
  10831. #walk(node) {
  10832. if (!node) {
  10833. return null;
  10834. }
  10835. const element = document.createElement("span");
  10836. if ("role" in node) {
  10837. const {
  10838. role
  10839. } = node;
  10840. const match = role.match(HEADING_PATTERN);
  10841. if (match) {
  10842. element.setAttribute("role", "heading");
  10843. element.setAttribute("aria-level", match[1]);
  10844. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10845. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10846. }
  10847. }
  10848. this.#setAttributes(node, element);
  10849. if (node.children) {
  10850. if (node.children.length === 1 && "id" in node.children[0]) {
  10851. this.#setAttributes(node.children[0], element);
  10852. } else {
  10853. for (const kid of node.children) {
  10854. element.append(this.#walk(kid));
  10855. }
  10856. }
  10857. }
  10858. return element;
  10859. }
  10860. }
  10861. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10862. /***/ }),
  10863. /* 34 */
  10864. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10865. Object.defineProperty(exports, "__esModule", ({
  10866. value: true
  10867. }));
  10868. exports.TextAccessibilityManager = void 0;
  10869. var _ui_utils = __webpack_require__(3);
  10870. class TextAccessibilityManager {
  10871. #enabled = false;
  10872. #textChildren = null;
  10873. #textNodes = new Map();
  10874. #waitingElements = new Map();
  10875. setTextMapping(textDivs) {
  10876. this.#textChildren = textDivs;
  10877. }
  10878. static #compareElementPositions(e1, e2) {
  10879. const rect1 = e1.getBoundingClientRect();
  10880. const rect2 = e2.getBoundingClientRect();
  10881. if (rect1.width === 0 && rect1.height === 0) {
  10882. return +1;
  10883. }
  10884. if (rect2.width === 0 && rect2.height === 0) {
  10885. return -1;
  10886. }
  10887. const top1 = rect1.y;
  10888. const bot1 = rect1.y + rect1.height;
  10889. const mid1 = rect1.y + rect1.height / 2;
  10890. const top2 = rect2.y;
  10891. const bot2 = rect2.y + rect2.height;
  10892. const mid2 = rect2.y + rect2.height / 2;
  10893. if (mid1 <= top2 && mid2 >= bot1) {
  10894. return -1;
  10895. }
  10896. if (mid2 <= top1 && mid1 >= bot2) {
  10897. return +1;
  10898. }
  10899. const centerX1 = rect1.x + rect1.width / 2;
  10900. const centerX2 = rect2.x + rect2.width / 2;
  10901. return centerX1 - centerX2;
  10902. }
  10903. enable() {
  10904. if (this.#enabled) {
  10905. throw new Error("TextAccessibilityManager is already enabled.");
  10906. }
  10907. if (!this.#textChildren) {
  10908. throw new Error("Text divs and strings have not been set.");
  10909. }
  10910. this.#enabled = true;
  10911. this.#textChildren = this.#textChildren.slice();
  10912. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  10913. if (this.#textNodes.size > 0) {
  10914. const textChildren = this.#textChildren;
  10915. for (const [id, nodeIndex] of this.#textNodes) {
  10916. const element = document.getElementById(id);
  10917. if (!element) {
  10918. this.#textNodes.delete(id);
  10919. continue;
  10920. }
  10921. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  10922. }
  10923. }
  10924. for (const [element, isRemovable] of this.#waitingElements) {
  10925. this.addPointerInTextLayer(element, isRemovable);
  10926. }
  10927. this.#waitingElements.clear();
  10928. }
  10929. disable() {
  10930. if (!this.#enabled) {
  10931. return;
  10932. }
  10933. this.#waitingElements.clear();
  10934. this.#textChildren = null;
  10935. this.#enabled = false;
  10936. }
  10937. removePointerInTextLayer(element) {
  10938. if (!this.#enabled) {
  10939. this.#waitingElements.delete(element);
  10940. return;
  10941. }
  10942. const children = this.#textChildren;
  10943. if (!children || children.length === 0) {
  10944. return;
  10945. }
  10946. const {
  10947. id
  10948. } = element;
  10949. const nodeIndex = this.#textNodes.get(id);
  10950. if (nodeIndex === undefined) {
  10951. return;
  10952. }
  10953. const node = children[nodeIndex];
  10954. this.#textNodes.delete(id);
  10955. let owns = node.getAttribute("aria-owns");
  10956. if (owns?.includes(id)) {
  10957. owns = owns.split(" ").filter(x => x !== id).join(" ");
  10958. if (owns) {
  10959. node.setAttribute("aria-owns", owns);
  10960. } else {
  10961. node.removeAttribute("aria-owns");
  10962. node.setAttribute("role", "presentation");
  10963. }
  10964. }
  10965. }
  10966. #addIdToAriaOwns(id, node) {
  10967. const owns = node.getAttribute("aria-owns");
  10968. if (!owns?.includes(id)) {
  10969. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  10970. }
  10971. node.removeAttribute("role");
  10972. }
  10973. addPointerInTextLayer(element, isRemovable) {
  10974. const {
  10975. id
  10976. } = element;
  10977. if (!id) {
  10978. return;
  10979. }
  10980. if (!this.#enabled) {
  10981. this.#waitingElements.set(element, isRemovable);
  10982. return;
  10983. }
  10984. if (isRemovable) {
  10985. this.removePointerInTextLayer(element);
  10986. }
  10987. const children = this.#textChildren;
  10988. if (!children || children.length === 0) {
  10989. return;
  10990. }
  10991. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  10992. const nodeIndex = Math.max(0, index - 1);
  10993. this.#addIdToAriaOwns(id, children[nodeIndex]);
  10994. this.#textNodes.set(id, nodeIndex);
  10995. }
  10996. moveElementInDOM(container, element, contentElement, isRemovable) {
  10997. this.addPointerInTextLayer(contentElement, isRemovable);
  10998. if (!container.hasChildNodes()) {
  10999. container.append(element);
  11000. return;
  11001. }
  11002. const children = Array.from(container.childNodes).filter(node => node !== element);
  11003. if (children.length === 0) {
  11004. return;
  11005. }
  11006. const elementToCompare = contentElement || element;
  11007. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  11008. if (index === 0) {
  11009. children[0].before(element);
  11010. } else {
  11011. children[index - 1].after(element);
  11012. }
  11013. }
  11014. }
  11015. exports.TextAccessibilityManager = TextAccessibilityManager;
  11016. /***/ }),
  11017. /* 35 */
  11018. /***/ ((__unused_webpack_module, exports) => {
  11019. Object.defineProperty(exports, "__esModule", ({
  11020. value: true
  11021. }));
  11022. exports.TextHighlighter = void 0;
  11023. class TextHighlighter {
  11024. constructor({
  11025. findController,
  11026. eventBus,
  11027. pageIndex
  11028. }) {
  11029. this.findController = findController;
  11030. this.matches = [];
  11031. this.eventBus = eventBus;
  11032. this.pageIdx = pageIndex;
  11033. this._onUpdateTextLayerMatches = null;
  11034. this.textDivs = null;
  11035. this.textContentItemsStr = null;
  11036. this.enabled = false;
  11037. }
  11038. setTextMapping(divs, texts) {
  11039. this.textDivs = divs;
  11040. this.textContentItemsStr = texts;
  11041. }
  11042. enable() {
  11043. if (!this.textDivs || !this.textContentItemsStr) {
  11044. throw new Error("Text divs and strings have not been set.");
  11045. }
  11046. if (this.enabled) {
  11047. throw new Error("TextHighlighter is already enabled.");
  11048. }
  11049. this.enabled = true;
  11050. if (!this._onUpdateTextLayerMatches) {
  11051. this._onUpdateTextLayerMatches = evt => {
  11052. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  11053. this._updateMatches();
  11054. }
  11055. };
  11056. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11057. }
  11058. this._updateMatches();
  11059. }
  11060. disable() {
  11061. if (!this.enabled) {
  11062. return;
  11063. }
  11064. this.enabled = false;
  11065. if (this._onUpdateTextLayerMatches) {
  11066. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11067. this._onUpdateTextLayerMatches = null;
  11068. }
  11069. this._updateMatches(true);
  11070. }
  11071. _convertMatches(matches, matchesLength) {
  11072. if (!matches) {
  11073. return [];
  11074. }
  11075. const {
  11076. textContentItemsStr
  11077. } = this;
  11078. let i = 0,
  11079. iIndex = 0;
  11080. const end = textContentItemsStr.length - 1;
  11081. const result = [];
  11082. for (let m = 0, mm = matches.length; m < mm; m++) {
  11083. let matchIdx = matches[m];
  11084. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  11085. iIndex += textContentItemsStr[i].length;
  11086. i++;
  11087. }
  11088. if (i === textContentItemsStr.length) {
  11089. console.error("Could not find a matching mapping");
  11090. }
  11091. const match = {
  11092. begin: {
  11093. divIdx: i,
  11094. offset: matchIdx - iIndex
  11095. }
  11096. };
  11097. matchIdx += matchesLength[m];
  11098. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  11099. iIndex += textContentItemsStr[i].length;
  11100. i++;
  11101. }
  11102. match.end = {
  11103. divIdx: i,
  11104. offset: matchIdx - iIndex
  11105. };
  11106. result.push(match);
  11107. }
  11108. return result;
  11109. }
  11110. _renderMatches(matches) {
  11111. if (matches.length === 0) {
  11112. return;
  11113. }
  11114. const {
  11115. findController,
  11116. pageIdx
  11117. } = this;
  11118. const {
  11119. textContentItemsStr,
  11120. textDivs
  11121. } = this;
  11122. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  11123. const selectedMatchIdx = findController.selected.matchIdx;
  11124. const highlightAll = findController.state.highlightAll;
  11125. let prevEnd = null;
  11126. const infinity = {
  11127. divIdx: -1,
  11128. offset: undefined
  11129. };
  11130. function beginText(begin, className) {
  11131. const divIdx = begin.divIdx;
  11132. textDivs[divIdx].textContent = "";
  11133. return appendTextToDiv(divIdx, 0, begin.offset, className);
  11134. }
  11135. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  11136. let div = textDivs[divIdx];
  11137. if (div.nodeType === Node.TEXT_NODE) {
  11138. const span = document.createElement("span");
  11139. div.before(span);
  11140. span.append(div);
  11141. textDivs[divIdx] = span;
  11142. div = span;
  11143. }
  11144. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  11145. const node = document.createTextNode(content);
  11146. if (className) {
  11147. const span = document.createElement("span");
  11148. span.className = `${className} appended`;
  11149. span.append(node);
  11150. div.append(span);
  11151. return className.includes("selected") ? span.offsetLeft : 0;
  11152. }
  11153. div.append(node);
  11154. return 0;
  11155. }
  11156. let i0 = selectedMatchIdx,
  11157. i1 = i0 + 1;
  11158. if (highlightAll) {
  11159. i0 = 0;
  11160. i1 = matches.length;
  11161. } else if (!isSelectedPage) {
  11162. return;
  11163. }
  11164. let lastDivIdx = -1;
  11165. let lastOffset = -1;
  11166. for (let i = i0; i < i1; i++) {
  11167. const match = matches[i];
  11168. const begin = match.begin;
  11169. if (begin.divIdx === lastDivIdx && begin.offset === lastOffset) {
  11170. continue;
  11171. }
  11172. lastDivIdx = begin.divIdx;
  11173. lastOffset = begin.offset;
  11174. const end = match.end;
  11175. const isSelected = isSelectedPage && i === selectedMatchIdx;
  11176. const highlightSuffix = isSelected ? " selected" : "";
  11177. let selectedLeft = 0;
  11178. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  11179. if (prevEnd !== null) {
  11180. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11181. }
  11182. beginText(begin);
  11183. } else {
  11184. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  11185. }
  11186. if (begin.divIdx === end.divIdx) {
  11187. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  11188. } else {
  11189. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  11190. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  11191. textDivs[n0].className = "highlight middle" + highlightSuffix;
  11192. }
  11193. beginText(end, "highlight end" + highlightSuffix);
  11194. }
  11195. prevEnd = end;
  11196. if (isSelected) {
  11197. findController.scrollMatchIntoView({
  11198. element: textDivs[begin.divIdx],
  11199. selectedLeft,
  11200. pageIndex: pageIdx,
  11201. matchIndex: selectedMatchIdx
  11202. });
  11203. }
  11204. }
  11205. if (prevEnd) {
  11206. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11207. }
  11208. }
  11209. _updateMatches(reset = false) {
  11210. if (!this.enabled && !reset) {
  11211. return;
  11212. }
  11213. const {
  11214. findController,
  11215. matches,
  11216. pageIdx
  11217. } = this;
  11218. const {
  11219. textContentItemsStr,
  11220. textDivs
  11221. } = this;
  11222. let clearedUntilDivIdx = -1;
  11223. for (const match of matches) {
  11224. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  11225. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  11226. const div = textDivs[n];
  11227. div.textContent = textContentItemsStr[n];
  11228. div.className = "";
  11229. }
  11230. clearedUntilDivIdx = match.end.divIdx + 1;
  11231. }
  11232. if (!findController?.highlightMatches || reset) {
  11233. return;
  11234. }
  11235. const pageMatches = findController.pageMatches[pageIdx] || null;
  11236. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  11237. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  11238. this._renderMatches(this.matches);
  11239. }
  11240. }
  11241. exports.TextHighlighter = TextHighlighter;
  11242. /***/ }),
  11243. /* 36 */
  11244. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11245. Object.defineProperty(exports, "__esModule", ({
  11246. value: true
  11247. }));
  11248. exports.TextLayerBuilder = void 0;
  11249. var _pdfjsLib = __webpack_require__(4);
  11250. var _ui_utils = __webpack_require__(3);
  11251. class TextLayerBuilder {
  11252. #enablePermissions = false;
  11253. #rotation = 0;
  11254. #scale = 0;
  11255. #textContentSource = null;
  11256. constructor({
  11257. highlighter = null,
  11258. accessibilityManager = null,
  11259. isOffscreenCanvasSupported = true,
  11260. enablePermissions = false
  11261. }) {
  11262. this.textContentItemsStr = [];
  11263. this.renderingDone = false;
  11264. this.textDivs = [];
  11265. this.textDivProperties = new WeakMap();
  11266. this.textLayerRenderTask = null;
  11267. this.highlighter = highlighter;
  11268. this.accessibilityManager = accessibilityManager;
  11269. this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
  11270. this.#enablePermissions = enablePermissions === true;
  11271. this.div = document.createElement("div");
  11272. this.div.className = "textLayer";
  11273. this.hide();
  11274. }
  11275. #finishRendering() {
  11276. this.renderingDone = true;
  11277. const endOfContent = document.createElement("div");
  11278. endOfContent.className = "endOfContent";
  11279. this.div.append(endOfContent);
  11280. this.#bindMouse();
  11281. }
  11282. get numTextDivs() {
  11283. return this.textDivs.length;
  11284. }
  11285. async render(viewport) {
  11286. if (!this.#textContentSource) {
  11287. throw new Error('No "textContentSource" parameter specified.');
  11288. }
  11289. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  11290. const {
  11291. rotation
  11292. } = viewport;
  11293. if (this.renderingDone) {
  11294. const mustRotate = rotation !== this.#rotation;
  11295. const mustRescale = scale !== this.#scale;
  11296. if (mustRotate || mustRescale) {
  11297. this.hide();
  11298. (0, _pdfjsLib.updateTextLayer)({
  11299. container: this.div,
  11300. viewport,
  11301. textDivs: this.textDivs,
  11302. textDivProperties: this.textDivProperties,
  11303. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  11304. mustRescale,
  11305. mustRotate
  11306. });
  11307. this.#scale = scale;
  11308. this.#rotation = rotation;
  11309. }
  11310. this.show();
  11311. return;
  11312. }
  11313. this.cancel();
  11314. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  11315. this.accessibilityManager?.setTextMapping(this.textDivs);
  11316. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  11317. textContentSource: this.#textContentSource,
  11318. container: this.div,
  11319. viewport,
  11320. textDivs: this.textDivs,
  11321. textDivProperties: this.textDivProperties,
  11322. textContentItemsStr: this.textContentItemsStr,
  11323. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
  11324. });
  11325. await this.textLayerRenderTask.promise;
  11326. this.#finishRendering();
  11327. this.#scale = scale;
  11328. this.#rotation = rotation;
  11329. this.show();
  11330. this.accessibilityManager?.enable();
  11331. }
  11332. hide() {
  11333. if (!this.div.hidden) {
  11334. this.highlighter?.disable();
  11335. this.div.hidden = true;
  11336. }
  11337. }
  11338. show() {
  11339. if (this.div.hidden && this.renderingDone) {
  11340. this.div.hidden = false;
  11341. this.highlighter?.enable();
  11342. }
  11343. }
  11344. cancel() {
  11345. if (this.textLayerRenderTask) {
  11346. this.textLayerRenderTask.cancel();
  11347. this.textLayerRenderTask = null;
  11348. }
  11349. this.highlighter?.disable();
  11350. this.accessibilityManager?.disable();
  11351. this.textContentItemsStr.length = 0;
  11352. this.textDivs.length = 0;
  11353. this.textDivProperties = new WeakMap();
  11354. }
  11355. setTextContentSource(source) {
  11356. this.cancel();
  11357. this.#textContentSource = source;
  11358. }
  11359. #bindMouse() {
  11360. const {
  11361. div
  11362. } = this;
  11363. div.addEventListener("mousedown", evt => {
  11364. const end = div.querySelector(".endOfContent");
  11365. if (!end) {
  11366. return;
  11367. }
  11368. let adjustTop = evt.target !== div;
  11369. adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  11370. if (adjustTop) {
  11371. const divBounds = div.getBoundingClientRect();
  11372. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  11373. end.style.top = (r * 100).toFixed(2) + "%";
  11374. }
  11375. end.classList.add("active");
  11376. });
  11377. div.addEventListener("mouseup", () => {
  11378. const end = div.querySelector(".endOfContent");
  11379. if (!end) {
  11380. return;
  11381. }
  11382. end.style.top = "";
  11383. end.classList.remove("active");
  11384. });
  11385. div.addEventListener("copy", event => {
  11386. if (!this.#enablePermissions) {
  11387. const selection = document.getSelection();
  11388. event.clipboardData.setData("text/plain", (0, _ui_utils.removeNullCharacters)((0, _pdfjsLib.normalizeUnicode)(selection.toString())));
  11389. }
  11390. event.preventDefault();
  11391. event.stopPropagation();
  11392. });
  11393. }
  11394. }
  11395. exports.TextLayerBuilder = TextLayerBuilder;
  11396. /***/ }),
  11397. /* 37 */
  11398. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11399. Object.defineProperty(exports, "__esModule", ({
  11400. value: true
  11401. }));
  11402. exports.XfaLayerBuilder = void 0;
  11403. var _pdfjsLib = __webpack_require__(4);
  11404. class XfaLayerBuilder {
  11405. constructor({
  11406. pageDiv,
  11407. pdfPage,
  11408. annotationStorage = null,
  11409. linkService,
  11410. xfaHtml = null
  11411. }) {
  11412. this.pageDiv = pageDiv;
  11413. this.pdfPage = pdfPage;
  11414. this.annotationStorage = annotationStorage;
  11415. this.linkService = linkService;
  11416. this.xfaHtml = xfaHtml;
  11417. this.div = null;
  11418. this._cancelled = false;
  11419. }
  11420. async render(viewport, intent = "display") {
  11421. if (intent === "print") {
  11422. const parameters = {
  11423. viewport: viewport.clone({
  11424. dontFlip: true
  11425. }),
  11426. div: this.div,
  11427. xfaHtml: this.xfaHtml,
  11428. annotationStorage: this.annotationStorage,
  11429. linkService: this.linkService,
  11430. intent
  11431. };
  11432. const div = document.createElement("div");
  11433. this.pageDiv.append(div);
  11434. parameters.div = div;
  11435. return _pdfjsLib.XfaLayer.render(parameters);
  11436. }
  11437. const xfaHtml = await this.pdfPage.getXfa();
  11438. if (this._cancelled || !xfaHtml) {
  11439. return {
  11440. textDivs: []
  11441. };
  11442. }
  11443. const parameters = {
  11444. viewport: viewport.clone({
  11445. dontFlip: true
  11446. }),
  11447. div: this.div,
  11448. xfaHtml,
  11449. annotationStorage: this.annotationStorage,
  11450. linkService: this.linkService,
  11451. intent
  11452. };
  11453. if (this.div) {
  11454. return _pdfjsLib.XfaLayer.update(parameters);
  11455. }
  11456. this.div = document.createElement("div");
  11457. this.pageDiv.append(this.div);
  11458. parameters.div = this.div;
  11459. return _pdfjsLib.XfaLayer.render(parameters);
  11460. }
  11461. cancel() {
  11462. this._cancelled = true;
  11463. }
  11464. hide() {
  11465. if (!this.div) {
  11466. return;
  11467. }
  11468. this.div.hidden = true;
  11469. }
  11470. }
  11471. exports.XfaLayerBuilder = XfaLayerBuilder;
  11472. /***/ }),
  11473. /* 38 */
  11474. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11475. Object.defineProperty(exports, "__esModule", ({
  11476. value: true
  11477. }));
  11478. exports.SecondaryToolbar = void 0;
  11479. var _ui_utils = __webpack_require__(3);
  11480. var _pdf_viewer = __webpack_require__(28);
  11481. class SecondaryToolbar {
  11482. constructor(options, eventBus, externalServices) {
  11483. this.toolbar = options.toolbar;
  11484. this.toggleButton = options.toggleButton;
  11485. this.buttons = [{
  11486. element: options.presentationModeButton,
  11487. eventName: "presentationmode",
  11488. close: true
  11489. }, {
  11490. element: options.printButton,
  11491. eventName: "print",
  11492. close: true
  11493. }, {
  11494. element: options.downloadButton,
  11495. eventName: "download",
  11496. close: true
  11497. }, {
  11498. element: options.viewBookmarkButton,
  11499. eventName: null,
  11500. close: true
  11501. }, {
  11502. element: options.firstPageButton,
  11503. eventName: "firstpage",
  11504. close: true
  11505. }, {
  11506. element: options.lastPageButton,
  11507. eventName: "lastpage",
  11508. close: true
  11509. }, {
  11510. element: options.pageRotateCwButton,
  11511. eventName: "rotatecw",
  11512. close: false
  11513. }, {
  11514. element: options.pageRotateCcwButton,
  11515. eventName: "rotateccw",
  11516. close: false
  11517. }, {
  11518. element: options.cursorSelectToolButton,
  11519. eventName: "switchcursortool",
  11520. eventDetails: {
  11521. tool: _ui_utils.CursorTool.SELECT
  11522. },
  11523. close: true
  11524. }, {
  11525. element: options.cursorHandToolButton,
  11526. eventName: "switchcursortool",
  11527. eventDetails: {
  11528. tool: _ui_utils.CursorTool.HAND
  11529. },
  11530. close: true
  11531. }, {
  11532. element: options.scrollPageButton,
  11533. eventName: "switchscrollmode",
  11534. eventDetails: {
  11535. mode: _ui_utils.ScrollMode.PAGE
  11536. },
  11537. close: true
  11538. }, {
  11539. element: options.scrollVerticalButton,
  11540. eventName: "switchscrollmode",
  11541. eventDetails: {
  11542. mode: _ui_utils.ScrollMode.VERTICAL
  11543. },
  11544. close: true
  11545. }, {
  11546. element: options.scrollHorizontalButton,
  11547. eventName: "switchscrollmode",
  11548. eventDetails: {
  11549. mode: _ui_utils.ScrollMode.HORIZONTAL
  11550. },
  11551. close: true
  11552. }, {
  11553. element: options.scrollWrappedButton,
  11554. eventName: "switchscrollmode",
  11555. eventDetails: {
  11556. mode: _ui_utils.ScrollMode.WRAPPED
  11557. },
  11558. close: true
  11559. }, {
  11560. element: options.spreadNoneButton,
  11561. eventName: "switchspreadmode",
  11562. eventDetails: {
  11563. mode: _ui_utils.SpreadMode.NONE
  11564. },
  11565. close: true
  11566. }, {
  11567. element: options.spreadOddButton,
  11568. eventName: "switchspreadmode",
  11569. eventDetails: {
  11570. mode: _ui_utils.SpreadMode.ODD
  11571. },
  11572. close: true
  11573. }, {
  11574. element: options.spreadEvenButton,
  11575. eventName: "switchspreadmode",
  11576. eventDetails: {
  11577. mode: _ui_utils.SpreadMode.EVEN
  11578. },
  11579. close: true
  11580. }, {
  11581. element: options.documentPropertiesButton,
  11582. eventName: "documentproperties",
  11583. close: true
  11584. }];
  11585. this.buttons.push({
  11586. element: options.openFileButton,
  11587. eventName: "openfile",
  11588. close: true
  11589. });
  11590. this.items = {
  11591. firstPage: options.firstPageButton,
  11592. lastPage: options.lastPageButton,
  11593. pageRotateCw: options.pageRotateCwButton,
  11594. pageRotateCcw: options.pageRotateCcwButton
  11595. };
  11596. this.eventBus = eventBus;
  11597. this.externalServices = externalServices;
  11598. this.opened = false;
  11599. this.#bindClickListeners();
  11600. this.#bindCursorToolsListener(options);
  11601. this.#bindScrollModeListener(options);
  11602. this.#bindSpreadModeListener(options);
  11603. this.reset();
  11604. }
  11605. get isOpen() {
  11606. return this.opened;
  11607. }
  11608. setPageNumber(pageNumber) {
  11609. this.pageNumber = pageNumber;
  11610. this.#updateUIState();
  11611. }
  11612. setPagesCount(pagesCount) {
  11613. this.pagesCount = pagesCount;
  11614. this.#updateUIState();
  11615. }
  11616. reset() {
  11617. this.pageNumber = 0;
  11618. this.pagesCount = 0;
  11619. this.#updateUIState();
  11620. this.eventBus.dispatch("secondarytoolbarreset", {
  11621. source: this
  11622. });
  11623. }
  11624. #updateUIState() {
  11625. this.items.firstPage.disabled = this.pageNumber <= 1;
  11626. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  11627. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  11628. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  11629. }
  11630. #bindClickListeners() {
  11631. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  11632. for (const {
  11633. element,
  11634. eventName,
  11635. close,
  11636. eventDetails
  11637. } of this.buttons) {
  11638. element.addEventListener("click", evt => {
  11639. if (eventName !== null) {
  11640. this.eventBus.dispatch(eventName, {
  11641. source: this,
  11642. ...eventDetails
  11643. });
  11644. }
  11645. if (close) {
  11646. this.close();
  11647. }
  11648. this.externalServices.reportTelemetry({
  11649. type: "buttons",
  11650. data: {
  11651. id: element.id
  11652. }
  11653. });
  11654. });
  11655. }
  11656. }
  11657. #bindCursorToolsListener({
  11658. cursorSelectToolButton,
  11659. cursorHandToolButton
  11660. }) {
  11661. this.eventBus._on("cursortoolchanged", ({
  11662. tool
  11663. }) => {
  11664. (0, _ui_utils.toggleCheckedBtn)(cursorSelectToolButton, tool === _ui_utils.CursorTool.SELECT);
  11665. (0, _ui_utils.toggleCheckedBtn)(cursorHandToolButton, tool === _ui_utils.CursorTool.HAND);
  11666. });
  11667. }
  11668. #bindScrollModeListener({
  11669. scrollPageButton,
  11670. scrollVerticalButton,
  11671. scrollHorizontalButton,
  11672. scrollWrappedButton,
  11673. spreadNoneButton,
  11674. spreadOddButton,
  11675. spreadEvenButton
  11676. }) {
  11677. const scrollModeChanged = ({
  11678. mode
  11679. }) => {
  11680. (0, _ui_utils.toggleCheckedBtn)(scrollPageButton, mode === _ui_utils.ScrollMode.PAGE);
  11681. (0, _ui_utils.toggleCheckedBtn)(scrollVerticalButton, mode === _ui_utils.ScrollMode.VERTICAL);
  11682. (0, _ui_utils.toggleCheckedBtn)(scrollHorizontalButton, mode === _ui_utils.ScrollMode.HORIZONTAL);
  11683. (0, _ui_utils.toggleCheckedBtn)(scrollWrappedButton, mode === _ui_utils.ScrollMode.WRAPPED);
  11684. const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11685. scrollPageButton.disabled = forceScrollModePage;
  11686. scrollVerticalButton.disabled = forceScrollModePage;
  11687. scrollHorizontalButton.disabled = forceScrollModePage;
  11688. scrollWrappedButton.disabled = forceScrollModePage;
  11689. const isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  11690. spreadNoneButton.disabled = isHorizontal;
  11691. spreadOddButton.disabled = isHorizontal;
  11692. spreadEvenButton.disabled = isHorizontal;
  11693. };
  11694. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  11695. this.eventBus._on("secondarytoolbarreset", evt => {
  11696. if (evt.source === this) {
  11697. scrollModeChanged({
  11698. mode: _ui_utils.ScrollMode.VERTICAL
  11699. });
  11700. }
  11701. });
  11702. }
  11703. #bindSpreadModeListener({
  11704. spreadNoneButton,
  11705. spreadOddButton,
  11706. spreadEvenButton
  11707. }) {
  11708. const spreadModeChanged = ({
  11709. mode
  11710. }) => {
  11711. (0, _ui_utils.toggleCheckedBtn)(spreadNoneButton, mode === _ui_utils.SpreadMode.NONE);
  11712. (0, _ui_utils.toggleCheckedBtn)(spreadOddButton, mode === _ui_utils.SpreadMode.ODD);
  11713. (0, _ui_utils.toggleCheckedBtn)(spreadEvenButton, mode === _ui_utils.SpreadMode.EVEN);
  11714. };
  11715. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  11716. this.eventBus._on("secondarytoolbarreset", evt => {
  11717. if (evt.source === this) {
  11718. spreadModeChanged({
  11719. mode: _ui_utils.SpreadMode.NONE
  11720. });
  11721. }
  11722. });
  11723. }
  11724. open() {
  11725. if (this.opened) {
  11726. return;
  11727. }
  11728. this.opened = true;
  11729. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true, this.toolbar);
  11730. }
  11731. close() {
  11732. if (!this.opened) {
  11733. return;
  11734. }
  11735. this.opened = false;
  11736. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false, this.toolbar);
  11737. }
  11738. toggle() {
  11739. if (this.opened) {
  11740. this.close();
  11741. } else {
  11742. this.open();
  11743. }
  11744. }
  11745. }
  11746. exports.SecondaryToolbar = SecondaryToolbar;
  11747. /***/ }),
  11748. /* 39 */
  11749. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11750. Object.defineProperty(exports, "__esModule", ({
  11751. value: true
  11752. }));
  11753. exports.Toolbar = void 0;
  11754. var _ui_utils = __webpack_require__(3);
  11755. var _pdfjsLib = __webpack_require__(4);
  11756. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  11757. class Toolbar {
  11758. #wasLocalized = false;
  11759. constructor(options, eventBus, l10n) {
  11760. this.toolbar = options.container;
  11761. this.eventBus = eventBus;
  11762. this.l10n = l10n;
  11763. this.buttons = [{
  11764. element: options.previous,
  11765. eventName: "previouspage"
  11766. }, {
  11767. element: options.next,
  11768. eventName: "nextpage"
  11769. }, {
  11770. element: options.zoomIn,
  11771. eventName: "zoomin"
  11772. }, {
  11773. element: options.zoomOut,
  11774. eventName: "zoomout"
  11775. }, {
  11776. element: options.print,
  11777. eventName: "print"
  11778. }, {
  11779. element: options.download,
  11780. eventName: "download"
  11781. }, {
  11782. element: options.editorFreeTextButton,
  11783. eventName: "switchannotationeditormode",
  11784. eventDetails: {
  11785. get mode() {
  11786. const {
  11787. classList
  11788. } = options.editorFreeTextButton;
  11789. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  11790. }
  11791. }
  11792. }, {
  11793. element: options.editorInkButton,
  11794. eventName: "switchannotationeditormode",
  11795. eventDetails: {
  11796. get mode() {
  11797. const {
  11798. classList
  11799. } = options.editorInkButton;
  11800. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  11801. }
  11802. }
  11803. }, {
  11804. element: options.editorStampButton,
  11805. eventName: "switchannotationeditormode",
  11806. eventDetails: {
  11807. get mode() {
  11808. const {
  11809. classList
  11810. } = options.editorStampButton;
  11811. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.STAMP;
  11812. }
  11813. }
  11814. }];
  11815. this.buttons.push({
  11816. element: options.openFile,
  11817. eventName: "openfile"
  11818. });
  11819. this.items = {
  11820. numPages: options.numPages,
  11821. pageNumber: options.pageNumber,
  11822. scaleSelect: options.scaleSelect,
  11823. customScaleOption: options.customScaleOption,
  11824. previous: options.previous,
  11825. next: options.next,
  11826. zoomIn: options.zoomIn,
  11827. zoomOut: options.zoomOut
  11828. };
  11829. this.#bindListeners(options);
  11830. this.reset();
  11831. }
  11832. setPageNumber(pageNumber, pageLabel) {
  11833. this.pageNumber = pageNumber;
  11834. this.pageLabel = pageLabel;
  11835. this.#updateUIState(false);
  11836. }
  11837. setPagesCount(pagesCount, hasPageLabels) {
  11838. this.pagesCount = pagesCount;
  11839. this.hasPageLabels = hasPageLabels;
  11840. this.#updateUIState(true);
  11841. }
  11842. setPageScale(pageScaleValue, pageScale) {
  11843. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11844. this.pageScale = pageScale;
  11845. this.#updateUIState(false);
  11846. }
  11847. reset() {
  11848. this.pageNumber = 0;
  11849. this.pageLabel = null;
  11850. this.hasPageLabels = false;
  11851. this.pagesCount = 0;
  11852. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  11853. this.pageScale = _ui_utils.DEFAULT_SCALE;
  11854. this.#updateUIState(true);
  11855. this.updateLoadingIndicatorState();
  11856. this.eventBus.dispatch("toolbarreset", {
  11857. source: this
  11858. });
  11859. }
  11860. #bindListeners(options) {
  11861. const {
  11862. pageNumber,
  11863. scaleSelect
  11864. } = this.items;
  11865. const self = this;
  11866. for (const {
  11867. element,
  11868. eventName,
  11869. eventDetails
  11870. } of this.buttons) {
  11871. element.addEventListener("click", evt => {
  11872. if (eventName !== null) {
  11873. this.eventBus.dispatch(eventName, {
  11874. source: this,
  11875. ...eventDetails
  11876. });
  11877. }
  11878. });
  11879. }
  11880. pageNumber.addEventListener("click", function () {
  11881. this.select();
  11882. });
  11883. pageNumber.addEventListener("change", function () {
  11884. self.eventBus.dispatch("pagenumberchanged", {
  11885. source: self,
  11886. value: this.value
  11887. });
  11888. });
  11889. scaleSelect.addEventListener("change", function () {
  11890. if (this.value === "custom") {
  11891. return;
  11892. }
  11893. self.eventBus.dispatch("scalechanged", {
  11894. source: self,
  11895. value: this.value
  11896. });
  11897. });
  11898. scaleSelect.addEventListener("click", function (evt) {
  11899. const target = evt.target;
  11900. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11901. this.blur();
  11902. }
  11903. });
  11904. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  11905. this.eventBus._on("localized", () => {
  11906. this.#wasLocalized = true;
  11907. this.#adjustScaleWidth();
  11908. this.#updateUIState(true);
  11909. });
  11910. this.#bindEditorToolsListener(options);
  11911. }
  11912. #bindEditorToolsListener({
  11913. editorFreeTextButton,
  11914. editorFreeTextParamsToolbar,
  11915. editorInkButton,
  11916. editorInkParamsToolbar,
  11917. editorStampButton,
  11918. editorStampParamsToolbar
  11919. }) {
  11920. const editorModeChanged = ({
  11921. mode
  11922. }) => {
  11923. (0, _ui_utils.toggleCheckedBtn)(editorFreeTextButton, mode === _pdfjsLib.AnnotationEditorType.FREETEXT, editorFreeTextParamsToolbar);
  11924. (0, _ui_utils.toggleCheckedBtn)(editorInkButton, mode === _pdfjsLib.AnnotationEditorType.INK, editorInkParamsToolbar);
  11925. (0, _ui_utils.toggleCheckedBtn)(editorStampButton, mode === _pdfjsLib.AnnotationEditorType.STAMP, editorStampParamsToolbar);
  11926. const isDisable = mode === _pdfjsLib.AnnotationEditorType.DISABLE;
  11927. editorFreeTextButton.disabled = isDisable;
  11928. editorInkButton.disabled = isDisable;
  11929. editorStampButton.disabled = isDisable;
  11930. };
  11931. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  11932. this.eventBus._on("toolbarreset", evt => {
  11933. if (evt.source === this) {
  11934. editorModeChanged({
  11935. mode: _pdfjsLib.AnnotationEditorType.DISABLE
  11936. });
  11937. }
  11938. });
  11939. }
  11940. #updateUIState(resetNumPages = false) {
  11941. if (!this.#wasLocalized) {
  11942. return;
  11943. }
  11944. const {
  11945. pageNumber,
  11946. pagesCount,
  11947. pageScaleValue,
  11948. pageScale,
  11949. items
  11950. } = this;
  11951. if (resetNumPages) {
  11952. if (this.hasPageLabels) {
  11953. items.pageNumber.type = "text";
  11954. } else {
  11955. items.pageNumber.type = "number";
  11956. this.l10n.get("of_pages", {
  11957. pagesCount
  11958. }).then(msg => {
  11959. items.numPages.textContent = msg;
  11960. });
  11961. }
  11962. items.pageNumber.max = pagesCount;
  11963. }
  11964. if (this.hasPageLabels) {
  11965. items.pageNumber.value = this.pageLabel;
  11966. this.l10n.get("page_of_pages", {
  11967. pageNumber,
  11968. pagesCount
  11969. }).then(msg => {
  11970. items.numPages.textContent = msg;
  11971. });
  11972. } else {
  11973. items.pageNumber.value = pageNumber;
  11974. }
  11975. items.previous.disabled = pageNumber <= 1;
  11976. items.next.disabled = pageNumber >= pagesCount;
  11977. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  11978. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  11979. this.l10n.get("page_scale_percent", {
  11980. scale: Math.round(pageScale * 10000) / 100
  11981. }).then(msg => {
  11982. let predefinedValueFound = false;
  11983. for (const option of items.scaleSelect.options) {
  11984. if (option.value !== pageScaleValue) {
  11985. option.selected = false;
  11986. continue;
  11987. }
  11988. option.selected = true;
  11989. predefinedValueFound = true;
  11990. }
  11991. if (!predefinedValueFound) {
  11992. items.customScaleOption.textContent = msg;
  11993. items.customScaleOption.selected = true;
  11994. }
  11995. });
  11996. }
  11997. updateLoadingIndicatorState(loading = false) {
  11998. const {
  11999. pageNumber
  12000. } = this.items;
  12001. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  12002. }
  12003. async #adjustScaleWidth() {
  12004. const {
  12005. items,
  12006. l10n
  12007. } = this;
  12008. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  12009. await _ui_utils.animationStarted;
  12010. const style = getComputedStyle(items.scaleSelect);
  12011. const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width"));
  12012. const canvas = document.createElement("canvas");
  12013. const ctx = canvas.getContext("2d", {
  12014. alpha: false
  12015. });
  12016. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  12017. let maxWidth = 0;
  12018. for (const predefinedValue of await predefinedValuesPromise) {
  12019. const {
  12020. width
  12021. } = ctx.measureText(predefinedValue);
  12022. if (width > maxWidth) {
  12023. maxWidth = width;
  12024. }
  12025. }
  12026. maxWidth += 0.3 * scaleSelectWidth;
  12027. if (maxWidth > scaleSelectWidth) {
  12028. const container = items.scaleSelect.parentNode;
  12029. container.style.setProperty("--scale-select-width", `${maxWidth}px`);
  12030. }
  12031. canvas.width = 0;
  12032. canvas.height = 0;
  12033. }
  12034. }
  12035. exports.Toolbar = Toolbar;
  12036. /***/ }),
  12037. /* 40 */
  12038. /***/ ((__unused_webpack_module, exports) => {
  12039. Object.defineProperty(exports, "__esModule", ({
  12040. value: true
  12041. }));
  12042. exports.ViewHistory = void 0;
  12043. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  12044. class ViewHistory {
  12045. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  12046. this.fingerprint = fingerprint;
  12047. this.cacheSize = cacheSize;
  12048. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  12049. const database = JSON.parse(databaseStr || "{}");
  12050. let index = -1;
  12051. if (!Array.isArray(database.files)) {
  12052. database.files = [];
  12053. } else {
  12054. while (database.files.length >= this.cacheSize) {
  12055. database.files.shift();
  12056. }
  12057. for (let i = 0, ii = database.files.length; i < ii; i++) {
  12058. const branch = database.files[i];
  12059. if (branch.fingerprint === this.fingerprint) {
  12060. index = i;
  12061. break;
  12062. }
  12063. }
  12064. }
  12065. if (index === -1) {
  12066. index = database.files.push({
  12067. fingerprint: this.fingerprint
  12068. }) - 1;
  12069. }
  12070. this.file = database.files[index];
  12071. this.database = database;
  12072. });
  12073. }
  12074. async _writeToStorage() {
  12075. const databaseStr = JSON.stringify(this.database);
  12076. localStorage.setItem("pdfjs.history", databaseStr);
  12077. }
  12078. async _readFromStorage() {
  12079. return localStorage.getItem("pdfjs.history");
  12080. }
  12081. async set(name, val) {
  12082. await this._initializedPromise;
  12083. this.file[name] = val;
  12084. return this._writeToStorage();
  12085. }
  12086. async setMultiple(properties) {
  12087. await this._initializedPromise;
  12088. for (const name in properties) {
  12089. this.file[name] = properties[name];
  12090. }
  12091. return this._writeToStorage();
  12092. }
  12093. async get(name, defaultValue) {
  12094. await this._initializedPromise;
  12095. const val = this.file[name];
  12096. return val !== undefined ? val : defaultValue;
  12097. }
  12098. async getMultiple(properties) {
  12099. await this._initializedPromise;
  12100. const values = Object.create(null);
  12101. for (const name in properties) {
  12102. const val = this.file[name];
  12103. values[name] = val !== undefined ? val : properties[name];
  12104. }
  12105. return values;
  12106. }
  12107. }
  12108. exports.ViewHistory = ViewHistory;
  12109. /***/ }),
  12110. /* 41 */
  12111. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12112. Object.defineProperty(exports, "__esModule", ({
  12113. value: true
  12114. }));
  12115. exports.BasePreferences = void 0;
  12116. var _app_options = __webpack_require__(5);
  12117. class BasePreferences {
  12118. #defaults = Object.freeze({
  12119. "annotationEditorMode": 0,
  12120. "annotationMode": 2,
  12121. "cursorToolOnLoad": 0,
  12122. "defaultZoomDelay": 400,
  12123. "defaultZoomValue": "",
  12124. "disablePageLabels": false,
  12125. "enablePermissions": false,
  12126. "enablePrintAutoRotate": true,
  12127. "enableScripting": true,
  12128. "enableStampEditor": true,
  12129. "externalLinkTarget": 0,
  12130. "historyUpdateUrl": false,
  12131. "ignoreDestinationZoom": false,
  12132. "forcePageColors": false,
  12133. "pageColorsBackground": "Canvas",
  12134. "pageColorsForeground": "CanvasText",
  12135. "pdfBugEnabled": false,
  12136. "sidebarViewOnLoad": -1,
  12137. "scrollModeOnLoad": -1,
  12138. "spreadModeOnLoad": -1,
  12139. "textLayerMode": 1,
  12140. "viewerCssTheme": 0,
  12141. "viewOnLoad": 0,
  12142. "disableAutoFetch": false,
  12143. "disableFontFace": false,
  12144. "disableRange": false,
  12145. "disableStream": false,
  12146. "enableXfa": true
  12147. });
  12148. #prefs = Object.create(null);
  12149. #initializedPromise = null;
  12150. constructor() {
  12151. if (this.constructor === BasePreferences) {
  12152. throw new Error("Cannot initialize BasePreferences.");
  12153. }
  12154. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  12155. for (const name in this.#defaults) {
  12156. const prefValue = prefs?.[name];
  12157. if (typeof prefValue === typeof this.#defaults[name]) {
  12158. this.#prefs[name] = prefValue;
  12159. }
  12160. }
  12161. });
  12162. }
  12163. async _writeToStorage(prefObj) {
  12164. throw new Error("Not implemented: _writeToStorage");
  12165. }
  12166. async _readFromStorage(prefObj) {
  12167. throw new Error("Not implemented: _readFromStorage");
  12168. }
  12169. async reset() {
  12170. await this.#initializedPromise;
  12171. const prefs = this.#prefs;
  12172. this.#prefs = Object.create(null);
  12173. return this._writeToStorage(this.#defaults).catch(reason => {
  12174. this.#prefs = prefs;
  12175. throw reason;
  12176. });
  12177. }
  12178. async set(name, value) {
  12179. await this.#initializedPromise;
  12180. const defaultValue = this.#defaults[name],
  12181. prefs = this.#prefs;
  12182. if (defaultValue === undefined) {
  12183. throw new Error(`Set preference: "${name}" is undefined.`);
  12184. } else if (value === undefined) {
  12185. throw new Error("Set preference: no value is specified.");
  12186. }
  12187. const valueType = typeof value,
  12188. defaultType = typeof defaultValue;
  12189. if (valueType !== defaultType) {
  12190. if (valueType === "number" && defaultType === "string") {
  12191. value = value.toString();
  12192. } else {
  12193. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  12194. }
  12195. } else if (valueType === "number" && !Number.isInteger(value)) {
  12196. throw new Error(`Set preference: "${value}" must be an integer.`);
  12197. }
  12198. this.#prefs[name] = value;
  12199. return this._writeToStorage(this.#prefs).catch(reason => {
  12200. this.#prefs = prefs;
  12201. throw reason;
  12202. });
  12203. }
  12204. async get(name) {
  12205. await this.#initializedPromise;
  12206. const defaultValue = this.#defaults[name];
  12207. if (defaultValue === undefined) {
  12208. throw new Error(`Get preference: "${name}" is undefined.`);
  12209. }
  12210. return this.#prefs[name] ?? defaultValue;
  12211. }
  12212. async getAll() {
  12213. await this.#initializedPromise;
  12214. const obj = Object.create(null);
  12215. for (const name in this.#defaults) {
  12216. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  12217. }
  12218. return obj;
  12219. }
  12220. }
  12221. exports.BasePreferences = BasePreferences;
  12222. /***/ }),
  12223. /* 42 */
  12224. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12225. Object.defineProperty(exports, "__esModule", ({
  12226. value: true
  12227. }));
  12228. exports.DownloadManager = void 0;
  12229. var _pdfjsLib = __webpack_require__(4);
  12230. ;
  12231. function download(blobUrl, filename) {
  12232. const a = document.createElement("a");
  12233. if (!a.click) {
  12234. throw new Error('DownloadManager: "a.click()" is not supported.');
  12235. }
  12236. a.href = blobUrl;
  12237. a.target = "_parent";
  12238. if ("download" in a) {
  12239. a.download = filename;
  12240. }
  12241. (document.body || document.documentElement).append(a);
  12242. a.click();
  12243. a.remove();
  12244. }
  12245. class DownloadManager {
  12246. #openBlobUrls = new WeakMap();
  12247. downloadUrl(url, filename, _options) {
  12248. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  12249. console.error(`downloadUrl - not a valid URL: ${url}`);
  12250. return;
  12251. }
  12252. download(url + "#pdfjs.action=download", filename);
  12253. }
  12254. downloadData(data, filename, contentType) {
  12255. const blobUrl = URL.createObjectURL(new Blob([data], {
  12256. type: contentType
  12257. }));
  12258. download(blobUrl, filename);
  12259. }
  12260. openOrDownloadData(element, data, filename) {
  12261. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  12262. const contentType = isPdfData ? "application/pdf" : "";
  12263. if (isPdfData) {
  12264. let blobUrl = this.#openBlobUrls.get(element);
  12265. if (!blobUrl) {
  12266. blobUrl = URL.createObjectURL(new Blob([data], {
  12267. type: contentType
  12268. }));
  12269. this.#openBlobUrls.set(element, blobUrl);
  12270. }
  12271. let viewerUrl;
  12272. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  12273. try {
  12274. window.open(viewerUrl);
  12275. return true;
  12276. } catch (ex) {
  12277. console.error(`openOrDownloadData: ${ex}`);
  12278. URL.revokeObjectURL(blobUrl);
  12279. this.#openBlobUrls.delete(element);
  12280. }
  12281. }
  12282. this.downloadData(data, filename, contentType);
  12283. return false;
  12284. }
  12285. download(blob, url, filename, _options) {
  12286. const blobUrl = URL.createObjectURL(blob);
  12287. download(blobUrl, filename);
  12288. }
  12289. }
  12290. exports.DownloadManager = DownloadManager;
  12291. /***/ }),
  12292. /* 43 */
  12293. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12294. Object.defineProperty(exports, "__esModule", ({
  12295. value: true
  12296. }));
  12297. exports.GenericL10n = void 0;
  12298. __webpack_require__(44);
  12299. var _l10n_utils = __webpack_require__(29);
  12300. const PARTIAL_LANG_CODES = {
  12301. en: "en-US",
  12302. es: "es-ES",
  12303. fy: "fy-NL",
  12304. ga: "ga-IE",
  12305. gu: "gu-IN",
  12306. hi: "hi-IN",
  12307. hy: "hy-AM",
  12308. nb: "nb-NO",
  12309. ne: "ne-NP",
  12310. nn: "nn-NO",
  12311. pa: "pa-IN",
  12312. pt: "pt-PT",
  12313. sv: "sv-SE",
  12314. zh: "zh-CN"
  12315. };
  12316. function fixupLangCode(langCode) {
  12317. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  12318. }
  12319. class GenericL10n {
  12320. constructor(lang) {
  12321. const {
  12322. webL10n
  12323. } = document;
  12324. this._lang = lang;
  12325. this._ready = new Promise((resolve, reject) => {
  12326. webL10n.setLanguage(fixupLangCode(lang), () => {
  12327. resolve(webL10n);
  12328. });
  12329. });
  12330. }
  12331. async getLanguage() {
  12332. const l10n = await this._ready;
  12333. return l10n.getLanguage();
  12334. }
  12335. async getDirection() {
  12336. const l10n = await this._ready;
  12337. return l10n.getDirection();
  12338. }
  12339. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  12340. const l10n = await this._ready;
  12341. return l10n.get(key, args, fallback);
  12342. }
  12343. async translate(element) {
  12344. const l10n = await this._ready;
  12345. return l10n.translate(element);
  12346. }
  12347. }
  12348. exports.GenericL10n = GenericL10n;
  12349. /***/ }),
  12350. /* 44 */
  12351. /***/ (() => {
  12352. document.webL10n = function (window, document) {
  12353. var gL10nData = {};
  12354. var gTextData = '';
  12355. var gTextProp = 'textContent';
  12356. var gLanguage = '';
  12357. var gMacros = {};
  12358. var gReadyState = 'loading';
  12359. var gAsyncResourceLoading = true;
  12360. function getL10nResourceLinks() {
  12361. return document.querySelectorAll('link[type="application/l10n"]');
  12362. }
  12363. function getL10nDictionary() {
  12364. var script = document.querySelector('script[type="application/l10n"]');
  12365. return script ? JSON.parse(script.innerHTML) : null;
  12366. }
  12367. function getTranslatableChildren(element) {
  12368. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  12369. }
  12370. function getL10nAttributes(element) {
  12371. if (!element) return {};
  12372. var l10nId = element.getAttribute('data-l10n-id');
  12373. var l10nArgs = element.getAttribute('data-l10n-args');
  12374. var args = {};
  12375. if (l10nArgs) {
  12376. try {
  12377. args = JSON.parse(l10nArgs);
  12378. } catch (e) {
  12379. console.warn('could not parse arguments for #' + l10nId);
  12380. }
  12381. }
  12382. return {
  12383. id: l10nId,
  12384. args: args
  12385. };
  12386. }
  12387. function xhrLoadText(url, onSuccess, onFailure) {
  12388. onSuccess = onSuccess || function _onSuccess(data) {};
  12389. onFailure = onFailure || function _onFailure() {};
  12390. var xhr = new XMLHttpRequest();
  12391. xhr.open('GET', url, gAsyncResourceLoading);
  12392. if (xhr.overrideMimeType) {
  12393. xhr.overrideMimeType('text/plain; charset=utf-8');
  12394. }
  12395. xhr.onreadystatechange = function () {
  12396. if (xhr.readyState == 4) {
  12397. if (xhr.status == 200 || xhr.status === 0) {
  12398. onSuccess(xhr.responseText);
  12399. } else {
  12400. onFailure();
  12401. }
  12402. }
  12403. };
  12404. xhr.onerror = onFailure;
  12405. xhr.ontimeout = onFailure;
  12406. try {
  12407. xhr.send(null);
  12408. } catch (e) {
  12409. onFailure();
  12410. }
  12411. }
  12412. function parseResource(href, lang, successCallback, failureCallback) {
  12413. var baseURL = href.replace(/[^\/]*$/, '') || './';
  12414. function evalString(text) {
  12415. if (text.lastIndexOf('\\') < 0) return text;
  12416. 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, "'");
  12417. }
  12418. function parseProperties(text, parsedPropertiesCallback) {
  12419. var dictionary = {};
  12420. var reBlank = /^\s*|\s*$/;
  12421. var reComment = /^\s*#|^\s*$/;
  12422. var reSection = /^\s*\[(.*)\]\s*$/;
  12423. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  12424. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  12425. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  12426. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  12427. var currentLang = '*';
  12428. var genericLang = lang.split('-', 1)[0];
  12429. var skipLang = false;
  12430. var match = '';
  12431. function nextEntry() {
  12432. while (true) {
  12433. if (!entries.length) {
  12434. parsedRawLinesCallback();
  12435. return;
  12436. }
  12437. var line = entries.shift();
  12438. if (reComment.test(line)) continue;
  12439. if (extendedSyntax) {
  12440. match = reSection.exec(line);
  12441. if (match) {
  12442. currentLang = match[1].toLowerCase();
  12443. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  12444. continue;
  12445. } else if (skipLang) {
  12446. continue;
  12447. }
  12448. match = reImport.exec(line);
  12449. if (match) {
  12450. loadImport(baseURL + match[1], nextEntry);
  12451. return;
  12452. }
  12453. }
  12454. var tmp = line.match(reSplit);
  12455. if (tmp && tmp.length == 3) {
  12456. dictionary[tmp[1]] = evalString(tmp[2]);
  12457. }
  12458. }
  12459. }
  12460. nextEntry();
  12461. }
  12462. function loadImport(url, callback) {
  12463. xhrLoadText(url, function (content) {
  12464. parseRawLines(content, false, callback);
  12465. }, function () {
  12466. console.warn(url + ' not found.');
  12467. callback();
  12468. });
  12469. }
  12470. parseRawLines(text, true, function () {
  12471. parsedPropertiesCallback(dictionary);
  12472. });
  12473. }
  12474. xhrLoadText(href, function (response) {
  12475. gTextData += response;
  12476. parseProperties(response, function (data) {
  12477. for (var key in data) {
  12478. var id,
  12479. prop,
  12480. index = key.lastIndexOf('.');
  12481. if (index > 0) {
  12482. id = key.substring(0, index);
  12483. prop = key.substring(index + 1);
  12484. } else {
  12485. id = key;
  12486. prop = gTextProp;
  12487. }
  12488. if (!gL10nData[id]) {
  12489. gL10nData[id] = {};
  12490. }
  12491. gL10nData[id][prop] = data[key];
  12492. }
  12493. if (successCallback) {
  12494. successCallback();
  12495. }
  12496. });
  12497. }, failureCallback);
  12498. }
  12499. function loadLocale(lang, callback) {
  12500. if (lang) {
  12501. lang = lang.toLowerCase();
  12502. }
  12503. callback = callback || function _callback() {};
  12504. clear();
  12505. gLanguage = lang;
  12506. var langLinks = getL10nResourceLinks();
  12507. var langCount = langLinks.length;
  12508. if (langCount === 0) {
  12509. var dict = getL10nDictionary();
  12510. if (dict && dict.locales && dict.default_locale) {
  12511. console.log('using the embedded JSON directory, early way out');
  12512. gL10nData = dict.locales[lang];
  12513. if (!gL10nData) {
  12514. var defaultLocale = dict.default_locale.toLowerCase();
  12515. for (var anyCaseLang in dict.locales) {
  12516. anyCaseLang = anyCaseLang.toLowerCase();
  12517. if (anyCaseLang === lang) {
  12518. gL10nData = dict.locales[lang];
  12519. break;
  12520. } else if (anyCaseLang === defaultLocale) {
  12521. gL10nData = dict.locales[defaultLocale];
  12522. }
  12523. }
  12524. }
  12525. callback();
  12526. } else {
  12527. console.log('no resource to load, early way out');
  12528. }
  12529. gReadyState = 'complete';
  12530. return;
  12531. }
  12532. var onResourceLoaded = null;
  12533. var gResourceCount = 0;
  12534. onResourceLoaded = function () {
  12535. gResourceCount++;
  12536. if (gResourceCount >= langCount) {
  12537. callback();
  12538. gReadyState = 'complete';
  12539. }
  12540. };
  12541. function L10nResourceLink(link) {
  12542. var href = link.href;
  12543. this.load = function (lang, callback) {
  12544. parseResource(href, lang, callback, function () {
  12545. console.warn(href + ' not found.');
  12546. console.warn('"' + lang + '" resource not found');
  12547. gLanguage = '';
  12548. callback();
  12549. });
  12550. };
  12551. }
  12552. for (var i = 0; i < langCount; i++) {
  12553. var resource = new L10nResourceLink(langLinks[i]);
  12554. resource.load(lang, onResourceLoaded);
  12555. }
  12556. }
  12557. function clear() {
  12558. gL10nData = {};
  12559. gTextData = '';
  12560. gLanguage = '';
  12561. }
  12562. function getPluralRules(lang) {
  12563. var locales2rules = {
  12564. 'af': 3,
  12565. 'ak': 4,
  12566. 'am': 4,
  12567. 'ar': 1,
  12568. 'asa': 3,
  12569. 'az': 0,
  12570. 'be': 11,
  12571. 'bem': 3,
  12572. 'bez': 3,
  12573. 'bg': 3,
  12574. 'bh': 4,
  12575. 'bm': 0,
  12576. 'bn': 3,
  12577. 'bo': 0,
  12578. 'br': 20,
  12579. 'brx': 3,
  12580. 'bs': 11,
  12581. 'ca': 3,
  12582. 'cgg': 3,
  12583. 'chr': 3,
  12584. 'cs': 12,
  12585. 'cy': 17,
  12586. 'da': 3,
  12587. 'de': 3,
  12588. 'dv': 3,
  12589. 'dz': 0,
  12590. 'ee': 3,
  12591. 'el': 3,
  12592. 'en': 3,
  12593. 'eo': 3,
  12594. 'es': 3,
  12595. 'et': 3,
  12596. 'eu': 3,
  12597. 'fa': 0,
  12598. 'ff': 5,
  12599. 'fi': 3,
  12600. 'fil': 4,
  12601. 'fo': 3,
  12602. 'fr': 5,
  12603. 'fur': 3,
  12604. 'fy': 3,
  12605. 'ga': 8,
  12606. 'gd': 24,
  12607. 'gl': 3,
  12608. 'gsw': 3,
  12609. 'gu': 3,
  12610. 'guw': 4,
  12611. 'gv': 23,
  12612. 'ha': 3,
  12613. 'haw': 3,
  12614. 'he': 2,
  12615. 'hi': 4,
  12616. 'hr': 11,
  12617. 'hu': 0,
  12618. 'id': 0,
  12619. 'ig': 0,
  12620. 'ii': 0,
  12621. 'is': 3,
  12622. 'it': 3,
  12623. 'iu': 7,
  12624. 'ja': 0,
  12625. 'jmc': 3,
  12626. 'jv': 0,
  12627. 'ka': 0,
  12628. 'kab': 5,
  12629. 'kaj': 3,
  12630. 'kcg': 3,
  12631. 'kde': 0,
  12632. 'kea': 0,
  12633. 'kk': 3,
  12634. 'kl': 3,
  12635. 'km': 0,
  12636. 'kn': 0,
  12637. 'ko': 0,
  12638. 'ksb': 3,
  12639. 'ksh': 21,
  12640. 'ku': 3,
  12641. 'kw': 7,
  12642. 'lag': 18,
  12643. 'lb': 3,
  12644. 'lg': 3,
  12645. 'ln': 4,
  12646. 'lo': 0,
  12647. 'lt': 10,
  12648. 'lv': 6,
  12649. 'mas': 3,
  12650. 'mg': 4,
  12651. 'mk': 16,
  12652. 'ml': 3,
  12653. 'mn': 3,
  12654. 'mo': 9,
  12655. 'mr': 3,
  12656. 'ms': 0,
  12657. 'mt': 15,
  12658. 'my': 0,
  12659. 'nah': 3,
  12660. 'naq': 7,
  12661. 'nb': 3,
  12662. 'nd': 3,
  12663. 'ne': 3,
  12664. 'nl': 3,
  12665. 'nn': 3,
  12666. 'no': 3,
  12667. 'nr': 3,
  12668. 'nso': 4,
  12669. 'ny': 3,
  12670. 'nyn': 3,
  12671. 'om': 3,
  12672. 'or': 3,
  12673. 'pa': 3,
  12674. 'pap': 3,
  12675. 'pl': 13,
  12676. 'ps': 3,
  12677. 'pt': 3,
  12678. 'rm': 3,
  12679. 'ro': 9,
  12680. 'rof': 3,
  12681. 'ru': 11,
  12682. 'rwk': 3,
  12683. 'sah': 0,
  12684. 'saq': 3,
  12685. 'se': 7,
  12686. 'seh': 3,
  12687. 'ses': 0,
  12688. 'sg': 0,
  12689. 'sh': 11,
  12690. 'shi': 19,
  12691. 'sk': 12,
  12692. 'sl': 14,
  12693. 'sma': 7,
  12694. 'smi': 7,
  12695. 'smj': 7,
  12696. 'smn': 7,
  12697. 'sms': 7,
  12698. 'sn': 3,
  12699. 'so': 3,
  12700. 'sq': 3,
  12701. 'sr': 11,
  12702. 'ss': 3,
  12703. 'ssy': 3,
  12704. 'st': 3,
  12705. 'sv': 3,
  12706. 'sw': 3,
  12707. 'syr': 3,
  12708. 'ta': 3,
  12709. 'te': 3,
  12710. 'teo': 3,
  12711. 'th': 0,
  12712. 'ti': 4,
  12713. 'tig': 3,
  12714. 'tk': 3,
  12715. 'tl': 4,
  12716. 'tn': 3,
  12717. 'to': 0,
  12718. 'tr': 0,
  12719. 'ts': 3,
  12720. 'tzm': 22,
  12721. 'uk': 11,
  12722. 'ur': 3,
  12723. 've': 3,
  12724. 'vi': 0,
  12725. 'vun': 3,
  12726. 'wa': 4,
  12727. 'wae': 3,
  12728. 'wo': 0,
  12729. 'xh': 3,
  12730. 'xog': 3,
  12731. 'yo': 0,
  12732. 'zh': 0,
  12733. 'zu': 3
  12734. };
  12735. function isIn(n, list) {
  12736. return list.indexOf(n) !== -1;
  12737. }
  12738. function isBetween(n, start, end) {
  12739. return start <= n && n <= end;
  12740. }
  12741. var pluralRules = {
  12742. '0': function (n) {
  12743. return 'other';
  12744. },
  12745. '1': function (n) {
  12746. if (isBetween(n % 100, 3, 10)) return 'few';
  12747. if (n === 0) return 'zero';
  12748. if (isBetween(n % 100, 11, 99)) return 'many';
  12749. if (n == 2) return 'two';
  12750. if (n == 1) return 'one';
  12751. return 'other';
  12752. },
  12753. '2': function (n) {
  12754. if (n !== 0 && n % 10 === 0) return 'many';
  12755. if (n == 2) return 'two';
  12756. if (n == 1) return 'one';
  12757. return 'other';
  12758. },
  12759. '3': function (n) {
  12760. if (n == 1) return 'one';
  12761. return 'other';
  12762. },
  12763. '4': function (n) {
  12764. if (isBetween(n, 0, 1)) return 'one';
  12765. return 'other';
  12766. },
  12767. '5': function (n) {
  12768. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12769. return 'other';
  12770. },
  12771. '6': function (n) {
  12772. if (n === 0) return 'zero';
  12773. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12774. return 'other';
  12775. },
  12776. '7': function (n) {
  12777. if (n == 2) return 'two';
  12778. if (n == 1) return 'one';
  12779. return 'other';
  12780. },
  12781. '8': function (n) {
  12782. if (isBetween(n, 3, 6)) return 'few';
  12783. if (isBetween(n, 7, 10)) return 'many';
  12784. if (n == 2) return 'two';
  12785. if (n == 1) return 'one';
  12786. return 'other';
  12787. },
  12788. '9': function (n) {
  12789. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12790. if (n == 1) return 'one';
  12791. return 'other';
  12792. },
  12793. '10': function (n) {
  12794. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12795. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12796. return 'other';
  12797. },
  12798. '11': function (n) {
  12799. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12800. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12801. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12802. return 'other';
  12803. },
  12804. '12': function (n) {
  12805. if (isBetween(n, 2, 4)) return 'few';
  12806. if (n == 1) return 'one';
  12807. return 'other';
  12808. },
  12809. '13': function (n) {
  12810. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12811. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12812. if (n == 1) return 'one';
  12813. return 'other';
  12814. },
  12815. '14': function (n) {
  12816. if (isBetween(n % 100, 3, 4)) return 'few';
  12817. if (n % 100 == 2) return 'two';
  12818. if (n % 100 == 1) return 'one';
  12819. return 'other';
  12820. },
  12821. '15': function (n) {
  12822. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12823. if (isBetween(n % 100, 11, 19)) return 'many';
  12824. if (n == 1) return 'one';
  12825. return 'other';
  12826. },
  12827. '16': function (n) {
  12828. if (n % 10 == 1 && n != 11) return 'one';
  12829. return 'other';
  12830. },
  12831. '17': function (n) {
  12832. if (n == 3) return 'few';
  12833. if (n === 0) return 'zero';
  12834. if (n == 6) return 'many';
  12835. if (n == 2) return 'two';
  12836. if (n == 1) return 'one';
  12837. return 'other';
  12838. },
  12839. '18': function (n) {
  12840. if (n === 0) return 'zero';
  12841. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12842. return 'other';
  12843. },
  12844. '19': function (n) {
  12845. if (isBetween(n, 2, 10)) return 'few';
  12846. if (isBetween(n, 0, 1)) return 'one';
  12847. return 'other';
  12848. },
  12849. '20': function (n) {
  12850. 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';
  12851. if (n % 1000000 === 0 && n !== 0) return 'many';
  12852. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12853. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12854. return 'other';
  12855. },
  12856. '21': function (n) {
  12857. if (n === 0) return 'zero';
  12858. if (n == 1) return 'one';
  12859. return 'other';
  12860. },
  12861. '22': function (n) {
  12862. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  12863. return 'other';
  12864. },
  12865. '23': function (n) {
  12866. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  12867. return 'other';
  12868. },
  12869. '24': function (n) {
  12870. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  12871. if (isIn(n, [2, 12])) return 'two';
  12872. if (isIn(n, [1, 11])) return 'one';
  12873. return 'other';
  12874. }
  12875. };
  12876. var index = locales2rules[lang.replace(/-.*$/, '')];
  12877. if (!(index in pluralRules)) {
  12878. console.warn('plural form unknown for [' + lang + ']');
  12879. return function () {
  12880. return 'other';
  12881. };
  12882. }
  12883. return pluralRules[index];
  12884. }
  12885. gMacros.plural = function (str, param, key, prop) {
  12886. var n = parseFloat(param);
  12887. if (isNaN(n)) return str;
  12888. if (prop != gTextProp) return str;
  12889. if (!gMacros._pluralRules) {
  12890. gMacros._pluralRules = getPluralRules(gLanguage);
  12891. }
  12892. var index = '[' + gMacros._pluralRules(n) + ']';
  12893. if (n === 0 && key + '[zero]' in gL10nData) {
  12894. str = gL10nData[key + '[zero]'][prop];
  12895. } else if (n == 1 && key + '[one]' in gL10nData) {
  12896. str = gL10nData[key + '[one]'][prop];
  12897. } else if (n == 2 && key + '[two]' in gL10nData) {
  12898. str = gL10nData[key + '[two]'][prop];
  12899. } else if (key + index in gL10nData) {
  12900. str = gL10nData[key + index][prop];
  12901. } else if (key + '[other]' in gL10nData) {
  12902. str = gL10nData[key + '[other]'][prop];
  12903. }
  12904. return str;
  12905. };
  12906. function getL10nData(key, args, fallback) {
  12907. var data = gL10nData[key];
  12908. if (!data) {
  12909. console.warn('#' + key + ' is undefined.');
  12910. if (!fallback) {
  12911. return null;
  12912. }
  12913. data = fallback;
  12914. }
  12915. var rv = {};
  12916. for (var prop in data) {
  12917. var str = data[prop];
  12918. str = substIndexes(str, args, key, prop);
  12919. str = substArguments(str, args, key);
  12920. rv[prop] = str;
  12921. }
  12922. return rv;
  12923. }
  12924. function substIndexes(str, args, key, prop) {
  12925. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  12926. var reMatch = reIndex.exec(str);
  12927. if (!reMatch || !reMatch.length) return str;
  12928. var macroName = reMatch[1];
  12929. var paramName = reMatch[2];
  12930. var param;
  12931. if (args && paramName in args) {
  12932. param = args[paramName];
  12933. } else if (paramName in gL10nData) {
  12934. param = gL10nData[paramName];
  12935. }
  12936. if (macroName in gMacros) {
  12937. var macro = gMacros[macroName];
  12938. str = macro(str, param, key, prop);
  12939. }
  12940. return str;
  12941. }
  12942. function substArguments(str, args, key) {
  12943. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  12944. return str.replace(reArgs, function (matched_text, arg) {
  12945. if (args && arg in args) {
  12946. return args[arg];
  12947. }
  12948. if (arg in gL10nData) {
  12949. return gL10nData[arg];
  12950. }
  12951. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  12952. return matched_text;
  12953. });
  12954. }
  12955. function translateElement(element) {
  12956. var l10n = getL10nAttributes(element);
  12957. if (!l10n.id) return;
  12958. var data = getL10nData(l10n.id, l10n.args);
  12959. if (!data) {
  12960. console.warn('#' + l10n.id + ' is undefined.');
  12961. return;
  12962. }
  12963. if (data[gTextProp]) {
  12964. if (getChildElementCount(element) === 0) {
  12965. element[gTextProp] = data[gTextProp];
  12966. } else {
  12967. var children = element.childNodes;
  12968. var found = false;
  12969. for (var i = 0, l = children.length; i < l; i++) {
  12970. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  12971. if (found) {
  12972. children[i].nodeValue = '';
  12973. } else {
  12974. children[i].nodeValue = data[gTextProp];
  12975. found = true;
  12976. }
  12977. }
  12978. }
  12979. if (!found) {
  12980. var textNode = document.createTextNode(data[gTextProp]);
  12981. element.prepend(textNode);
  12982. }
  12983. }
  12984. delete data[gTextProp];
  12985. }
  12986. for (var k in data) {
  12987. element[k] = data[k];
  12988. }
  12989. }
  12990. function getChildElementCount(element) {
  12991. if (element.children) {
  12992. return element.children.length;
  12993. }
  12994. if (typeof element.childElementCount !== 'undefined') {
  12995. return element.childElementCount;
  12996. }
  12997. var count = 0;
  12998. for (var i = 0; i < element.childNodes.length; i++) {
  12999. count += element.nodeType === 1 ? 1 : 0;
  13000. }
  13001. return count;
  13002. }
  13003. function translateFragment(element) {
  13004. element = element || document.documentElement;
  13005. var children = getTranslatableChildren(element);
  13006. var elementCount = children.length;
  13007. for (var i = 0; i < elementCount; i++) {
  13008. translateElement(children[i]);
  13009. }
  13010. translateElement(element);
  13011. }
  13012. return {
  13013. get: function (key, args, fallbackString) {
  13014. var index = key.lastIndexOf('.');
  13015. var prop = gTextProp;
  13016. if (index > 0) {
  13017. prop = key.substring(index + 1);
  13018. key = key.substring(0, index);
  13019. }
  13020. var fallback;
  13021. if (fallbackString) {
  13022. fallback = {};
  13023. fallback[prop] = fallbackString;
  13024. }
  13025. var data = getL10nData(key, args, fallback);
  13026. if (data && prop in data) {
  13027. return data[prop];
  13028. }
  13029. return '{{' + key + '}}';
  13030. },
  13031. getData: function () {
  13032. return gL10nData;
  13033. },
  13034. getText: function () {
  13035. return gTextData;
  13036. },
  13037. getLanguage: function () {
  13038. return gLanguage;
  13039. },
  13040. setLanguage: function (lang, callback) {
  13041. loadLocale(lang, function () {
  13042. if (callback) callback();
  13043. });
  13044. },
  13045. getDirection: function () {
  13046. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  13047. var shortCode = gLanguage.split('-', 1)[0];
  13048. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  13049. },
  13050. translate: translateFragment,
  13051. getReadyState: function () {
  13052. return gReadyState;
  13053. },
  13054. ready: function (callback) {
  13055. if (!callback) {
  13056. return;
  13057. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  13058. window.setTimeout(function () {
  13059. callback();
  13060. });
  13061. } else if (document.addEventListener) {
  13062. document.addEventListener('localized', function once() {
  13063. document.removeEventListener('localized', once);
  13064. callback();
  13065. });
  13066. }
  13067. }
  13068. };
  13069. }(window, document);
  13070. /***/ }),
  13071. /* 45 */
  13072. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13073. Object.defineProperty(exports, "__esModule", ({
  13074. value: true
  13075. }));
  13076. exports.GenericScripting = void 0;
  13077. exports.docProperties = docProperties;
  13078. var _pdfjsLib = __webpack_require__(4);
  13079. async function docProperties(pdfDocument) {
  13080. const url = "",
  13081. baseUrl = url.split("#")[0];
  13082. let {
  13083. info,
  13084. metadata,
  13085. contentDispositionFilename,
  13086. contentLength
  13087. } = await pdfDocument.getMetadata();
  13088. if (!contentLength) {
  13089. const {
  13090. length
  13091. } = await pdfDocument.getDownloadInfo();
  13092. contentLength = length;
  13093. }
  13094. return {
  13095. ...info,
  13096. baseURL: baseUrl,
  13097. filesize: contentLength,
  13098. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  13099. metadata: metadata?.getRaw(),
  13100. authors: metadata?.get("dc:creator"),
  13101. numPages: pdfDocument.numPages,
  13102. URL: url
  13103. };
  13104. }
  13105. class GenericScripting {
  13106. constructor(sandboxBundleSrc) {
  13107. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  13108. return window.pdfjsSandbox.QuickJSSandbox();
  13109. });
  13110. }
  13111. async createSandbox(data) {
  13112. const sandbox = await this._ready;
  13113. sandbox.create(data);
  13114. }
  13115. async dispatchEventInSandbox(event) {
  13116. const sandbox = await this._ready;
  13117. setTimeout(() => sandbox.dispatchEvent(event), 0);
  13118. }
  13119. async destroySandbox() {
  13120. const sandbox = await this._ready;
  13121. sandbox.nukeSandbox();
  13122. }
  13123. }
  13124. exports.GenericScripting = GenericScripting;
  13125. /***/ }),
  13126. /* 46 */
  13127. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13128. Object.defineProperty(exports, "__esModule", ({
  13129. value: true
  13130. }));
  13131. exports.PDFPrintService = void 0;
  13132. var _pdfjsLib = __webpack_require__(4);
  13133. var _app = __webpack_require__(2);
  13134. var _print_utils = __webpack_require__(47);
  13135. let activeService = null;
  13136. let dialog = null;
  13137. let overlayManager = null;
  13138. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  13139. const scratchCanvas = activeService.scratchCanvas;
  13140. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  13141. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  13142. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  13143. const ctx = scratchCanvas.getContext("2d");
  13144. ctx.save();
  13145. ctx.fillStyle = "rgb(255, 255, 255)";
  13146. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  13147. ctx.restore();
  13148. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  13149. const renderContext = {
  13150. canvasContext: ctx,
  13151. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  13152. viewport: pdfPage.getViewport({
  13153. scale: 1,
  13154. rotation: size.rotation
  13155. }),
  13156. intent: "print",
  13157. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  13158. optionalContentConfigPromise,
  13159. printAnnotationStorage
  13160. };
  13161. return pdfPage.render(renderContext).promise;
  13162. });
  13163. }
  13164. class PDFPrintService {
  13165. constructor(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) {
  13166. this.pdfDocument = pdfDocument;
  13167. this.pagesOverview = pagesOverview;
  13168. this.printContainer = printContainer;
  13169. this._printResolution = printResolution || 150;
  13170. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  13171. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  13172. this.l10n = l10n;
  13173. this.currentPage = -1;
  13174. this.scratchCanvas = document.createElement("canvas");
  13175. }
  13176. layout() {
  13177. this.throwIfInactive();
  13178. const body = document.querySelector("body");
  13179. body.setAttribute("data-pdfjsprinting", true);
  13180. const {
  13181. width,
  13182. height
  13183. } = this.pagesOverview[0];
  13184. const hasEqualPageSizes = this.pagesOverview.every(size => size.width === width && size.height === height);
  13185. if (!hasEqualPageSizes) {
  13186. console.warn("Not all pages have the same size. The printed result may be incorrect!");
  13187. }
  13188. this.pageStyleSheet = document.createElement("style");
  13189. this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`;
  13190. body.append(this.pageStyleSheet);
  13191. }
  13192. destroy() {
  13193. if (activeService !== this) {
  13194. return;
  13195. }
  13196. this.printContainer.textContent = "";
  13197. const body = document.querySelector("body");
  13198. body.removeAttribute("data-pdfjsprinting");
  13199. if (this.pageStyleSheet) {
  13200. this.pageStyleSheet.remove();
  13201. this.pageStyleSheet = null;
  13202. }
  13203. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  13204. this.scratchCanvas = null;
  13205. activeService = null;
  13206. ensureOverlay().then(function () {
  13207. if (overlayManager.active === dialog) {
  13208. overlayManager.close(dialog);
  13209. }
  13210. });
  13211. }
  13212. renderPages() {
  13213. if (this.pdfDocument.isPureXfa) {
  13214. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  13215. return Promise.resolve();
  13216. }
  13217. const pageCount = this.pagesOverview.length;
  13218. const renderNextPage = (resolve, reject) => {
  13219. this.throwIfInactive();
  13220. if (++this.currentPage >= pageCount) {
  13221. renderProgress(pageCount, pageCount, this.l10n);
  13222. resolve();
  13223. return;
  13224. }
  13225. const index = this.currentPage;
  13226. renderProgress(index, pageCount, this.l10n);
  13227. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  13228. renderNextPage(resolve, reject);
  13229. }, reject);
  13230. };
  13231. return new Promise(renderNextPage);
  13232. }
  13233. useRenderedPage() {
  13234. this.throwIfInactive();
  13235. const img = document.createElement("img");
  13236. const scratchCanvas = this.scratchCanvas;
  13237. if ("toBlob" in scratchCanvas) {
  13238. scratchCanvas.toBlob(function (blob) {
  13239. img.src = URL.createObjectURL(blob);
  13240. });
  13241. } else {
  13242. img.src = scratchCanvas.toDataURL();
  13243. }
  13244. const wrapper = document.createElement("div");
  13245. wrapper.className = "printedPage";
  13246. wrapper.append(img);
  13247. this.printContainer.append(wrapper);
  13248. return new Promise(function (resolve, reject) {
  13249. img.onload = resolve;
  13250. img.onerror = reject;
  13251. });
  13252. }
  13253. performPrint() {
  13254. this.throwIfInactive();
  13255. return new Promise(resolve => {
  13256. setTimeout(() => {
  13257. if (!this.active) {
  13258. resolve();
  13259. return;
  13260. }
  13261. print.call(window);
  13262. setTimeout(resolve, 20);
  13263. }, 0);
  13264. });
  13265. }
  13266. get active() {
  13267. return this === activeService;
  13268. }
  13269. throwIfInactive() {
  13270. if (!this.active) {
  13271. throw new Error("This print request was cancelled or completed.");
  13272. }
  13273. }
  13274. }
  13275. exports.PDFPrintService = PDFPrintService;
  13276. const print = window.print;
  13277. window.print = function () {
  13278. if (activeService) {
  13279. console.warn("Ignored window.print() because of a pending print job.");
  13280. return;
  13281. }
  13282. ensureOverlay().then(function () {
  13283. if (activeService) {
  13284. overlayManager.open(dialog);
  13285. }
  13286. });
  13287. try {
  13288. dispatchEvent("beforeprint");
  13289. } finally {
  13290. if (!activeService) {
  13291. console.error("Expected print service to be initialized.");
  13292. ensureOverlay().then(function () {
  13293. if (overlayManager.active === dialog) {
  13294. overlayManager.close(dialog);
  13295. }
  13296. });
  13297. return;
  13298. }
  13299. const activeServiceOnEntry = activeService;
  13300. activeService.renderPages().then(function () {
  13301. return activeServiceOnEntry.performPrint();
  13302. }).catch(function () {}).then(function () {
  13303. if (activeServiceOnEntry.active) {
  13304. abort();
  13305. }
  13306. });
  13307. }
  13308. };
  13309. function dispatchEvent(eventType) {
  13310. const event = new CustomEvent(eventType, {
  13311. bubbles: false,
  13312. cancelable: false,
  13313. detail: "custom"
  13314. });
  13315. window.dispatchEvent(event);
  13316. }
  13317. function abort() {
  13318. if (activeService) {
  13319. activeService.destroy();
  13320. dispatchEvent("afterprint");
  13321. }
  13322. }
  13323. function renderProgress(index, total, l10n) {
  13324. dialog ||= document.getElementById("printServiceDialog");
  13325. const progress = Math.round(100 * index / total);
  13326. const progressBar = dialog.querySelector("progress");
  13327. const progressPerc = dialog.querySelector(".relative-progress");
  13328. progressBar.value = progress;
  13329. l10n.get("print_progress_percent", {
  13330. progress
  13331. }).then(msg => {
  13332. progressPerc.textContent = msg;
  13333. });
  13334. }
  13335. window.addEventListener("keydown", function (event) {
  13336. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  13337. window.print();
  13338. event.preventDefault();
  13339. event.stopImmediatePropagation();
  13340. }
  13341. }, true);
  13342. if ("onbeforeprint" in window) {
  13343. const stopPropagationIfNeeded = function (event) {
  13344. if (event.detail !== "custom") {
  13345. event.stopImmediatePropagation();
  13346. }
  13347. };
  13348. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  13349. window.addEventListener("afterprint", stopPropagationIfNeeded);
  13350. }
  13351. let overlayPromise;
  13352. function ensureOverlay() {
  13353. if (!overlayPromise) {
  13354. overlayManager = _app.PDFViewerApplication.overlayManager;
  13355. if (!overlayManager) {
  13356. throw new Error("The overlay manager has not yet been initialized.");
  13357. }
  13358. dialog ||= document.getElementById("printServiceDialog");
  13359. overlayPromise = overlayManager.register(dialog, true);
  13360. document.getElementById("printCancel").onclick = abort;
  13361. dialog.addEventListener("close", abort);
  13362. }
  13363. return overlayPromise;
  13364. }
  13365. _app.PDFPrintServiceFactory.instance = {
  13366. supportsPrinting: true,
  13367. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  13368. if (activeService) {
  13369. throw new Error("The print service is created and active.");
  13370. }
  13371. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  13372. return activeService;
  13373. }
  13374. };
  13375. /***/ }),
  13376. /* 47 */
  13377. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13378. Object.defineProperty(exports, "__esModule", ({
  13379. value: true
  13380. }));
  13381. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  13382. var _pdfjsLib = __webpack_require__(4);
  13383. var _pdf_link_service = __webpack_require__(7);
  13384. var _xfa_layer_builder = __webpack_require__(37);
  13385. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  13386. const xfaHtml = pdfDocument.allXfaHtml;
  13387. const linkService = new _pdf_link_service.SimpleLinkService();
  13388. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  13389. for (const xfaPage of xfaHtml.children) {
  13390. const page = document.createElement("div");
  13391. page.className = "xfaPrintedPage";
  13392. printContainer.append(page);
  13393. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  13394. pageDiv: page,
  13395. pdfPage: null,
  13396. annotationStorage: pdfDocument.annotationStorage,
  13397. linkService,
  13398. xfaHtml: xfaPage
  13399. });
  13400. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  13401. scale
  13402. });
  13403. builder.render(viewport, "print");
  13404. }
  13405. }
  13406. /***/ })
  13407. /******/ ]);
  13408. /************************************************************************/
  13409. /******/ // The module cache
  13410. /******/ var __webpack_module_cache__ = {};
  13411. /******/
  13412. /******/ // The require function
  13413. /******/ function __webpack_require__(moduleId) {
  13414. /******/ // Check if module is in cache
  13415. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  13416. /******/ if (cachedModule !== undefined) {
  13417. /******/ return cachedModule.exports;
  13418. /******/ }
  13419. /******/ // Create a new module (and put it into the cache)
  13420. /******/ var module = __webpack_module_cache__[moduleId] = {
  13421. /******/ // no module.id needed
  13422. /******/ // no module.loaded needed
  13423. /******/ exports: {}
  13424. /******/ };
  13425. /******/
  13426. /******/ // Execute the module function
  13427. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  13428. /******/
  13429. /******/ // Return the exports of the module
  13430. /******/ return module.exports;
  13431. /******/ }
  13432. /******/
  13433. /************************************************************************/
  13434. var __webpack_exports__ = {};
  13435. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  13436. (() => {
  13437. var exports = __webpack_exports__;
  13438. Object.defineProperty(exports, "__esModule", ({
  13439. value: true
  13440. }));
  13441. Object.defineProperty(exports, "PDFViewerApplication", ({
  13442. enumerable: true,
  13443. get: function () {
  13444. return _app.PDFViewerApplication;
  13445. }
  13446. }));
  13447. exports.PDFViewerApplicationConstants = void 0;
  13448. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  13449. enumerable: true,
  13450. get: function () {
  13451. return _app_options.AppOptions;
  13452. }
  13453. }));
  13454. __webpack_require__(1);
  13455. __webpack_require__(46);
  13456. var _ui_utils = __webpack_require__(3);
  13457. var _app_options = __webpack_require__(5);
  13458. var _pdf_link_service = __webpack_require__(7);
  13459. var _app = __webpack_require__(2);
  13460. const pdfjsVersion = '3.10.111';
  13461. const pdfjsBuild = 'e142baecb';
  13462. const AppConstants = {
  13463. LinkTarget: _pdf_link_service.LinkTarget,
  13464. RenderingStates: _ui_utils.RenderingStates,
  13465. ScrollMode: _ui_utils.ScrollMode,
  13466. SpreadMode: _ui_utils.SpreadMode
  13467. };
  13468. exports.PDFViewerApplicationConstants = AppConstants;
  13469. window.PDFViewerApplication = _app.PDFViewerApplication;
  13470. window.PDFViewerApplicationConstants = AppConstants;
  13471. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  13472. function getViewerConfiguration() {
  13473. return {
  13474. appContainer: document.body,
  13475. mainContainer: document.getElementById("viewerContainer"),
  13476. viewerContainer: document.getElementById("viewer"),
  13477. toolbar: {
  13478. container: document.getElementById("toolbarViewer"),
  13479. numPages: document.getElementById("numPages"),
  13480. pageNumber: document.getElementById("pageNumber"),
  13481. scaleSelect: document.getElementById("scaleSelect"),
  13482. customScaleOption: document.getElementById("customScaleOption"),
  13483. previous: document.getElementById("previous"),
  13484. next: document.getElementById("next"),
  13485. zoomIn: document.getElementById("zoomIn"),
  13486. zoomOut: document.getElementById("zoomOut"),
  13487. viewFind: document.getElementById("viewFind"),
  13488. openFile: document.getElementById("openFile"),
  13489. print: document.getElementById("print"),
  13490. editorFreeTextButton: document.getElementById("editorFreeText"),
  13491. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  13492. editorInkButton: document.getElementById("editorInk"),
  13493. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  13494. editorStampButton: document.getElementById("editorStamp"),
  13495. editorStampParamsToolbar: document.getElementById("editorStampParamsToolbar"),
  13496. download: document.getElementById("download")
  13497. },
  13498. secondaryToolbar: {
  13499. toolbar: document.getElementById("secondaryToolbar"),
  13500. toggleButton: document.getElementById("secondaryToolbarToggle"),
  13501. presentationModeButton: document.getElementById("presentationMode"),
  13502. openFileButton: document.getElementById("secondaryOpenFile"),
  13503. printButton: document.getElementById("secondaryPrint"),
  13504. downloadButton: document.getElementById("secondaryDownload"),
  13505. viewBookmarkButton: document.getElementById("viewBookmark"),
  13506. firstPageButton: document.getElementById("firstPage"),
  13507. lastPageButton: document.getElementById("lastPage"),
  13508. pageRotateCwButton: document.getElementById("pageRotateCw"),
  13509. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  13510. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  13511. cursorHandToolButton: document.getElementById("cursorHandTool"),
  13512. scrollPageButton: document.getElementById("scrollPage"),
  13513. scrollVerticalButton: document.getElementById("scrollVertical"),
  13514. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  13515. scrollWrappedButton: document.getElementById("scrollWrapped"),
  13516. spreadNoneButton: document.getElementById("spreadNone"),
  13517. spreadOddButton: document.getElementById("spreadOdd"),
  13518. spreadEvenButton: document.getElementById("spreadEven"),
  13519. documentPropertiesButton: document.getElementById("documentProperties")
  13520. },
  13521. sidebar: {
  13522. outerContainer: document.getElementById("outerContainer"),
  13523. sidebarContainer: document.getElementById("sidebarContainer"),
  13524. toggleButton: document.getElementById("sidebarToggle"),
  13525. resizer: document.getElementById("sidebarResizer"),
  13526. thumbnailButton: document.getElementById("viewThumbnail"),
  13527. outlineButton: document.getElementById("viewOutline"),
  13528. attachmentsButton: document.getElementById("viewAttachments"),
  13529. layersButton: document.getElementById("viewLayers"),
  13530. thumbnailView: document.getElementById("thumbnailView"),
  13531. outlineView: document.getElementById("outlineView"),
  13532. attachmentsView: document.getElementById("attachmentsView"),
  13533. layersView: document.getElementById("layersView"),
  13534. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  13535. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  13536. },
  13537. findBar: {
  13538. bar: document.getElementById("findbar"),
  13539. toggleButton: document.getElementById("viewFind"),
  13540. findField: document.getElementById("findInput"),
  13541. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  13542. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  13543. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  13544. entireWordCheckbox: document.getElementById("findEntireWord"),
  13545. findMsg: document.getElementById("findMsg"),
  13546. findResultsCount: document.getElementById("findResultsCount"),
  13547. findPreviousButton: document.getElementById("findPrevious"),
  13548. findNextButton: document.getElementById("findNext")
  13549. },
  13550. passwordOverlay: {
  13551. dialog: document.getElementById("passwordDialog"),
  13552. label: document.getElementById("passwordText"),
  13553. input: document.getElementById("password"),
  13554. submitButton: document.getElementById("passwordSubmit"),
  13555. cancelButton: document.getElementById("passwordCancel")
  13556. },
  13557. documentProperties: {
  13558. dialog: document.getElementById("documentPropertiesDialog"),
  13559. closeButton: document.getElementById("documentPropertiesClose"),
  13560. fields: {
  13561. fileName: document.getElementById("fileNameField"),
  13562. fileSize: document.getElementById("fileSizeField"),
  13563. title: document.getElementById("titleField"),
  13564. author: document.getElementById("authorField"),
  13565. subject: document.getElementById("subjectField"),
  13566. keywords: document.getElementById("keywordsField"),
  13567. creationDate: document.getElementById("creationDateField"),
  13568. modificationDate: document.getElementById("modificationDateField"),
  13569. creator: document.getElementById("creatorField"),
  13570. producer: document.getElementById("producerField"),
  13571. version: document.getElementById("versionField"),
  13572. pageCount: document.getElementById("pageCountField"),
  13573. pageSize: document.getElementById("pageSizeField"),
  13574. linearized: document.getElementById("linearizedField")
  13575. }
  13576. },
  13577. annotationEditorParams: {
  13578. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  13579. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  13580. editorInkColor: document.getElementById("editorInkColor"),
  13581. editorInkThickness: document.getElementById("editorInkThickness"),
  13582. editorInkOpacity: document.getElementById("editorInkOpacity"),
  13583. editorStampAddImage: document.getElementById("editorStampAddImage")
  13584. },
  13585. printContainer: document.getElementById("printContainer"),
  13586. openFileInput: document.getElementById("fileInput"),
  13587. debuggerScriptPath: "./debugger.js"
  13588. };
  13589. }
  13590. function webViewerLoad() {
  13591. const config = getViewerConfiguration();
  13592. const event = new CustomEvent("webviewerloaded", {
  13593. bubbles: true,
  13594. cancelable: true,
  13595. detail: {
  13596. source: window
  13597. }
  13598. });
  13599. try {
  13600. parent.document.dispatchEvent(event);
  13601. } catch (ex) {
  13602. console.error(`webviewerloaded: ${ex}`);
  13603. document.dispatchEvent(event);
  13604. }
  13605. _app.PDFViewerApplication.run(config);
  13606. }
  13607. document.blockUnblockOnload?.(true);
  13608. if (document.readyState === "interactive" || document.readyState === "complete") {
  13609. webViewerLoad();
  13610. } else {
  13611. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  13612. }
  13613. })();
  13614. /******/ })()
  13615. ;
  13616. //# sourceMappingURL=viewer.js.map