viewer.js 418 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811
  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({
  312. OPS: _pdfjsLib.OPS
  313. }, mainContainer, enabled);
  314. } catch (ex) {
  315. console.error(`_parseHashParams: "${ex.message}".`);
  316. }
  317. }
  318. if (params.has("locale")) {
  319. _app_options.AppOptions.set("locale", params.get("locale"));
  320. }
  321. },
  322. async _initializeL10n() {
  323. this.l10n = this.externalServices.createL10n({
  324. locale: _app_options.AppOptions.get("locale")
  325. });
  326. const dir = await this.l10n.getDirection();
  327. document.getElementsByTagName("html")[0].dir = dir;
  328. },
  329. _forceCssTheme() {
  330. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  331. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  332. return;
  333. }
  334. try {
  335. const styleSheet = document.styleSheets[0];
  336. const cssRules = styleSheet?.cssRules || [];
  337. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  338. const rule = cssRules[i];
  339. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  340. if (cssTheme === ViewerCssTheme.LIGHT) {
  341. styleSheet.deleteRule(i);
  342. return;
  343. }
  344. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  345. if (darkRules?.[1]) {
  346. styleSheet.deleteRule(i);
  347. styleSheet.insertRule(darkRules[1], i);
  348. }
  349. return;
  350. }
  351. }
  352. } catch (reason) {
  353. console.error(`_forceCssTheme: "${reason?.message}".`);
  354. }
  355. },
  356. async _initializeViewerComponents() {
  357. const {
  358. appConfig,
  359. externalServices,
  360. l10n
  361. } = this;
  362. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  363. this.eventBus = eventBus;
  364. this.overlayManager = new _overlay_manager.OverlayManager();
  365. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  366. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  367. this.pdfRenderingQueue = pdfRenderingQueue;
  368. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  369. eventBus,
  370. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  371. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  372. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  373. });
  374. this.pdfLinkService = pdfLinkService;
  375. const downloadManager = externalServices.createDownloadManager();
  376. this.downloadManager = downloadManager;
  377. const findController = new _pdf_find_controller.PDFFindController({
  378. linkService: pdfLinkService,
  379. eventBus,
  380. updateMatchesCountOnProgress: true
  381. });
  382. this.findController = findController;
  383. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  384. eventBus,
  385. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  386. scriptingFactory: externalServices,
  387. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  388. });
  389. this.pdfScriptingManager = pdfScriptingManager;
  390. const container = appConfig.mainContainer,
  391. viewer = appConfig.viewerContainer;
  392. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  393. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  394. background: _app_options.AppOptions.get("pageColorsBackground"),
  395. foreground: _app_options.AppOptions.get("pageColorsForeground")
  396. } : null;
  397. const pdfViewer = new _pdf_viewer.PDFViewer({
  398. container,
  399. viewer,
  400. eventBus,
  401. renderingQueue: pdfRenderingQueue,
  402. linkService: pdfLinkService,
  403. downloadManager,
  404. findController,
  405. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  406. l10n,
  407. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  408. annotationMode: _app_options.AppOptions.get("annotationMode"),
  409. annotationEditorMode,
  410. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  411. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  412. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  413. isOffscreenCanvasSupported: _app_options.AppOptions.get("isOffscreenCanvasSupported"),
  414. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  415. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  416. pageColors
  417. });
  418. this.pdfViewer = pdfViewer;
  419. pdfRenderingQueue.setViewer(pdfViewer);
  420. pdfLinkService.setViewer(pdfViewer);
  421. pdfScriptingManager.setViewer(pdfViewer);
  422. if (appConfig.sidebar?.thumbnailView) {
  423. this.pdfThumbnailViewer = new _webPdf_thumbnail_viewer.PDFThumbnailViewer({
  424. container: appConfig.sidebar.thumbnailView,
  425. eventBus,
  426. renderingQueue: pdfRenderingQueue,
  427. linkService: pdfLinkService,
  428. l10n,
  429. pageColors
  430. });
  431. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  432. }
  433. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  434. this.pdfHistory = new _pdf_history.PDFHistory({
  435. linkService: pdfLinkService,
  436. eventBus
  437. });
  438. pdfLinkService.setHistory(this.pdfHistory);
  439. }
  440. if (!this.supportsIntegratedFind && appConfig.findBar) {
  441. this.findBar = new _webPdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, l10n);
  442. }
  443. if (appConfig.annotationEditorParams) {
  444. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  445. this.annotationEditorParams = new _webAnnotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  446. } else {
  447. for (const id of ["editorModeButtons", "editorModeSeparator"]) {
  448. document.getElementById(id)?.classList.add("hidden");
  449. }
  450. }
  451. }
  452. if (appConfig.documentProperties) {
  453. this.pdfDocumentProperties = new _webPdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, l10n, () => this._docFilename);
  454. }
  455. if (appConfig.secondaryToolbar?.cursorHandToolButton) {
  456. this.pdfCursorTools = new _webPdf_cursor_tools.PDFCursorTools({
  457. container,
  458. eventBus,
  459. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  460. });
  461. }
  462. if (appConfig.toolbar) {
  463. this.toolbar = new _webToolbar.Toolbar(appConfig.toolbar, eventBus, l10n);
  464. }
  465. if (appConfig.secondaryToolbar) {
  466. this.secondaryToolbar = new _webSecondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, externalServices);
  467. }
  468. if (this.supportsFullscreen && appConfig.secondaryToolbar?.presentationModeButton) {
  469. this.pdfPresentationMode = new _webPdf_presentation_mode.PDFPresentationMode({
  470. container,
  471. pdfViewer,
  472. eventBus
  473. });
  474. }
  475. if (appConfig.passwordOverlay) {
  476. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, l10n, this.isViewerEmbedded);
  477. }
  478. if (appConfig.sidebar?.outlineView) {
  479. this.pdfOutlineViewer = new _webPdf_outline_viewer.PDFOutlineViewer({
  480. container: appConfig.sidebar.outlineView,
  481. eventBus,
  482. linkService: pdfLinkService,
  483. downloadManager
  484. });
  485. }
  486. if (appConfig.sidebar?.attachmentsView) {
  487. this.pdfAttachmentViewer = new _webPdf_attachment_viewer.PDFAttachmentViewer({
  488. container: appConfig.sidebar.attachmentsView,
  489. eventBus,
  490. downloadManager
  491. });
  492. }
  493. if (appConfig.sidebar?.layersView) {
  494. this.pdfLayerViewer = new _webPdf_layer_viewer.PDFLayerViewer({
  495. container: appConfig.sidebar.layersView,
  496. eventBus,
  497. l10n
  498. });
  499. }
  500. if (appConfig.sidebar) {
  501. this.pdfSidebar = new _webPdf_sidebar.PDFSidebar({
  502. elements: appConfig.sidebar,
  503. eventBus,
  504. l10n
  505. });
  506. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  507. this.pdfSidebar.onUpdateThumbnails = () => {
  508. for (const pageView of pdfViewer.getCachedPageViews()) {
  509. if (pageView.renderingState === _ui_utils.RenderingStates.FINISHED) {
  510. this.pdfThumbnailViewer.getThumbnail(pageView.id - 1)?.setImage(pageView);
  511. }
  512. }
  513. this.pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  514. };
  515. }
  516. },
  517. run(config) {
  518. this.initialize(config).then(webViewerInitialized);
  519. },
  520. get initialized() {
  521. return this._initializedCapability.settled;
  522. },
  523. get initializedPromise() {
  524. return this._initializedCapability.promise;
  525. },
  526. zoomIn(steps, scaleFactor) {
  527. if (this.pdfViewer.isInPresentationMode) {
  528. return;
  529. }
  530. this.pdfViewer.increaseScale({
  531. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  532. steps,
  533. scaleFactor
  534. });
  535. },
  536. zoomOut(steps, scaleFactor) {
  537. if (this.pdfViewer.isInPresentationMode) {
  538. return;
  539. }
  540. this.pdfViewer.decreaseScale({
  541. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  542. steps,
  543. scaleFactor
  544. });
  545. },
  546. zoomReset() {
  547. if (this.pdfViewer.isInPresentationMode) {
  548. return;
  549. }
  550. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  551. },
  552. get pagesCount() {
  553. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  554. },
  555. get page() {
  556. return this.pdfViewer.currentPageNumber;
  557. },
  558. set page(val) {
  559. this.pdfViewer.currentPageNumber = val;
  560. },
  561. get supportsPrinting() {
  562. return PDFPrintServiceFactory.instance.supportsPrinting;
  563. },
  564. get supportsFullscreen() {
  565. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  566. },
  567. get supportsPinchToZoom() {
  568. return this.externalServices.supportsPinchToZoom;
  569. },
  570. get supportsIntegratedFind() {
  571. return this.externalServices.supportsIntegratedFind;
  572. },
  573. get supportsDocumentFonts() {
  574. return this.externalServices.supportsDocumentFonts;
  575. },
  576. get loadingBar() {
  577. const barElement = document.getElementById("loadingBar");
  578. const bar = barElement ? new _ui_utils.ProgressBar(barElement) : null;
  579. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  580. },
  581. get supportedMouseWheelZoomModifierKeys() {
  582. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  583. },
  584. initPassiveLoading() {
  585. throw new Error("Not implemented: initPassiveLoading");
  586. },
  587. setTitleUsingUrl(url = "", downloadUrl = null) {
  588. this.url = url;
  589. this.baseUrl = url.split("#")[0];
  590. if (downloadUrl) {
  591. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  592. }
  593. if ((0, _pdfjsLib.isDataScheme)(url)) {
  594. this._hideViewBookmark();
  595. }
  596. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  597. if (!title) {
  598. try {
  599. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  600. } catch (ex) {
  601. title = url;
  602. }
  603. }
  604. this.setTitle(title);
  605. },
  606. setTitle(title = this._title) {
  607. this._title = title;
  608. if (this.isViewerEmbedded) {
  609. return;
  610. }
  611. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  612. document.title = `${editorIndicator ? "* " : ""}${title}`;
  613. },
  614. get _docFilename() {
  615. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  616. },
  617. _hideViewBookmark() {
  618. const {
  619. secondaryToolbar
  620. } = this.appConfig;
  621. secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
  622. if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) {
  623. document.getElementById("viewBookmarkSeparator")?.classList.add("hidden");
  624. }
  625. },
  626. async close() {
  627. this._unblockDocumentLoadEvent();
  628. this._hideViewBookmark();
  629. if (!this.pdfLoadingTask) {
  630. return;
  631. }
  632. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  633. try {
  634. await this.save();
  635. } catch (reason) {}
  636. }
  637. const promises = [];
  638. promises.push(this.pdfLoadingTask.destroy());
  639. this.pdfLoadingTask = null;
  640. if (this.pdfDocument) {
  641. this.pdfDocument = null;
  642. this.pdfThumbnailViewer?.setDocument(null);
  643. this.pdfViewer.setDocument(null);
  644. this.pdfLinkService.setDocument(null);
  645. this.pdfDocumentProperties?.setDocument(null);
  646. }
  647. this.pdfLinkService.externalLinkEnabled = true;
  648. this.store = null;
  649. this.isInitialViewSet = false;
  650. this.downloadComplete = false;
  651. this.url = "";
  652. this.baseUrl = "";
  653. this._downloadUrl = "";
  654. this.documentInfo = null;
  655. this.metadata = null;
  656. this._contentDispositionFilename = null;
  657. this._contentLength = null;
  658. this._saveInProgress = false;
  659. this._hasAnnotationEditors = false;
  660. promises.push(this.pdfScriptingManager.destroyPromise);
  661. this.setTitle();
  662. this.pdfSidebar?.reset();
  663. this.pdfOutlineViewer?.reset();
  664. this.pdfAttachmentViewer?.reset();
  665. this.pdfLayerViewer?.reset();
  666. this.pdfHistory?.reset();
  667. this.findBar?.reset();
  668. this.toolbar?.reset();
  669. this.secondaryToolbar?.reset();
  670. this._PDFBug?.cleanup();
  671. await Promise.all(promises);
  672. },
  673. async open(args) {
  674. let deprecatedArgs = false;
  675. if (typeof args === "string") {
  676. args = {
  677. url: args
  678. };
  679. deprecatedArgs = true;
  680. } else if (args?.byteLength) {
  681. args = {
  682. data: args
  683. };
  684. deprecatedArgs = true;
  685. }
  686. if (deprecatedArgs) {
  687. console.error("The `PDFViewerApplication.open` signature was updated, please use an object instead.");
  688. }
  689. if (this.pdfLoadingTask) {
  690. await this.close();
  691. }
  692. const workerParams = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  693. Object.assign(_pdfjsLib.GlobalWorkerOptions, workerParams);
  694. if (args.url) {
  695. this.setTitleUsingUrl(args.originalUrl || args.url, args.url);
  696. }
  697. const apiParams = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  698. const params = {
  699. canvasMaxAreaInBytes: this.externalServices.canvasMaxAreaInBytes,
  700. ...apiParams,
  701. ...args
  702. };
  703. const loadingTask = (0, _pdfjsLib.getDocument)(params);
  704. this.pdfLoadingTask = loadingTask;
  705. loadingTask.onPassword = (updateCallback, reason) => {
  706. if (this.isViewerEmbedded) {
  707. this._unblockDocumentLoadEvent();
  708. }
  709. this.pdfLinkService.externalLinkEnabled = false;
  710. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  711. this.passwordPrompt.open();
  712. };
  713. loadingTask.onProgress = ({
  714. loaded,
  715. total
  716. }) => {
  717. this.progress(loaded / total);
  718. };
  719. return loadingTask.promise.then(pdfDocument => {
  720. this.load(pdfDocument);
  721. }, reason => {
  722. if (loadingTask !== this.pdfLoadingTask) {
  723. return undefined;
  724. }
  725. let key = "loading_error";
  726. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  727. key = "invalid_file_error";
  728. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  729. key = "missing_file_error";
  730. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  731. key = "unexpected_response_error";
  732. }
  733. return this.l10n.get(key).then(msg => {
  734. this._documentError(msg, {
  735. message: reason?.message
  736. });
  737. throw reason;
  738. });
  739. });
  740. },
  741. _ensureDownloadComplete() {
  742. if (this.pdfDocument && this.downloadComplete) {
  743. return;
  744. }
  745. throw new Error("PDF document not downloaded.");
  746. },
  747. async download(options = {}) {
  748. const url = this._downloadUrl,
  749. filename = this._docFilename;
  750. try {
  751. this._ensureDownloadComplete();
  752. const data = await this.pdfDocument.getData();
  753. const blob = new Blob([data], {
  754. type: "application/pdf"
  755. });
  756. await this.downloadManager.download(blob, url, filename, options);
  757. } catch (reason) {
  758. await this.downloadManager.downloadUrl(url, filename, options);
  759. }
  760. },
  761. async save(options = {}) {
  762. if (this._saveInProgress) {
  763. return;
  764. }
  765. this._saveInProgress = true;
  766. await this.pdfScriptingManager.dispatchWillSave();
  767. const url = this._downloadUrl,
  768. filename = this._docFilename;
  769. try {
  770. this._ensureDownloadComplete();
  771. const data = await this.pdfDocument.saveDocument();
  772. const blob = new Blob([data], {
  773. type: "application/pdf"
  774. });
  775. await this.downloadManager.download(blob, url, filename, options);
  776. } catch (reason) {
  777. console.error(`Error when saving the document: ${reason.message}`);
  778. await this.download(options);
  779. } finally {
  780. await this.pdfScriptingManager.dispatchDidSave();
  781. this._saveInProgress = false;
  782. }
  783. if (this._hasAnnotationEditors) {
  784. this.externalServices.reportTelemetry({
  785. type: "editing",
  786. data: {
  787. type: "save"
  788. }
  789. });
  790. }
  791. },
  792. downloadOrSave(options = {}) {
  793. if (this.pdfDocument?.annotationStorage.size > 0) {
  794. this.save(options);
  795. } else {
  796. this.download(options);
  797. }
  798. },
  799. openInExternalApp() {
  800. this.downloadOrSave({
  801. openInExternalApp: true
  802. });
  803. },
  804. _documentError(message, moreInfo = null) {
  805. this._unblockDocumentLoadEvent();
  806. this._otherError(message, moreInfo);
  807. this.eventBus.dispatch("documenterror", {
  808. source: this,
  809. message,
  810. reason: moreInfo?.message ?? null
  811. });
  812. },
  813. _otherError(message, moreInfo = null) {
  814. const moreInfoText = [`PDF.js v${_pdfjsLib.version || "?"} (build: ${_pdfjsLib.build || "?"})`];
  815. if (moreInfo) {
  816. moreInfoText.push(`Message: ${moreInfo.message}`);
  817. if (moreInfo.stack) {
  818. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  819. } else {
  820. if (moreInfo.filename) {
  821. moreInfoText.push(`File: ${moreInfo.filename}`);
  822. }
  823. if (moreInfo.lineNumber) {
  824. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  825. }
  826. }
  827. }
  828. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  829. },
  830. progress(level) {
  831. if (!this.loadingBar || this.downloadComplete) {
  832. return;
  833. }
  834. const percent = Math.round(level * 100);
  835. if (percent <= this.loadingBar.percent) {
  836. return;
  837. }
  838. this.loadingBar.percent = percent;
  839. if (this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch")) {
  840. this.loadingBar.setDisableAutoFetch();
  841. }
  842. },
  843. load(pdfDocument) {
  844. this.pdfDocument = pdfDocument;
  845. pdfDocument.getDownloadInfo().then(({
  846. length
  847. }) => {
  848. this._contentLength = length;
  849. this.downloadComplete = true;
  850. this.loadingBar?.hide();
  851. firstPagePromise.then(() => {
  852. this.eventBus.dispatch("documentloaded", {
  853. source: this
  854. });
  855. });
  856. });
  857. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  858. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  859. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  860. this.toolbar?.setPagesCount(pdfDocument.numPages, false);
  861. this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
  862. this.pdfLinkService.setDocument(pdfDocument);
  863. this.pdfDocumentProperties?.setDocument(pdfDocument);
  864. const pdfViewer = this.pdfViewer;
  865. pdfViewer.setDocument(pdfDocument);
  866. const {
  867. firstPagePromise,
  868. onePageRendered,
  869. pagesPromise
  870. } = pdfViewer;
  871. this.pdfThumbnailViewer?.setDocument(pdfDocument);
  872. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  873. page: null,
  874. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  875. scrollLeft: "0",
  876. scrollTop: "0",
  877. rotation: null,
  878. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  879. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  880. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  881. }).catch(() => {
  882. return Object.create(null);
  883. });
  884. firstPagePromise.then(pdfPage => {
  885. this.loadingBar?.setWidth(this.appConfig.viewerContainer);
  886. this._initializeAnnotationStorageCallbacks(pdfDocument);
  887. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  888. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  889. this._initializePdfHistory({
  890. fingerprint: pdfDocument.fingerprints[0],
  891. viewOnLoad,
  892. initialDest: openAction?.dest
  893. });
  894. const initialBookmark = this.initialBookmark;
  895. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  896. let hash = zoom ? `zoom=${zoom}` : null;
  897. let rotation = null;
  898. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  899. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  900. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  901. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  902. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  903. rotation = parseInt(stored.rotation, 10);
  904. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  905. sidebarView = stored.sidebarView | 0;
  906. }
  907. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  908. scrollMode = stored.scrollMode | 0;
  909. }
  910. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  911. spreadMode = stored.spreadMode | 0;
  912. }
  913. }
  914. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  915. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  916. }
  917. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  918. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  919. spreadMode = modes.spreadMode;
  920. }
  921. this.setInitialView(hash, {
  922. rotation,
  923. sidebarView,
  924. scrollMode,
  925. spreadMode
  926. });
  927. this.eventBus.dispatch("documentinit", {
  928. source: this
  929. });
  930. if (!this.isViewerEmbedded) {
  931. pdfViewer.focus();
  932. }
  933. await Promise.race([pagesPromise, new Promise(resolve => {
  934. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  935. })]);
  936. if (!initialBookmark && !hash) {
  937. return;
  938. }
  939. if (pdfViewer.hasEqualPageSizes) {
  940. return;
  941. }
  942. this.initialBookmark = initialBookmark;
  943. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  944. this.setInitialView(hash);
  945. }).catch(() => {
  946. this.setInitialView();
  947. }).then(function () {
  948. pdfViewer.update();
  949. });
  950. });
  951. pagesPromise.then(() => {
  952. this._unblockDocumentLoadEvent();
  953. this._initializeAutoPrint(pdfDocument, openActionPromise);
  954. }, reason => {
  955. this.l10n.get("loading_error").then(msg => {
  956. this._documentError(msg, {
  957. message: reason?.message
  958. });
  959. });
  960. });
  961. onePageRendered.then(data => {
  962. this.externalServices.reportTelemetry({
  963. type: "pageInfo",
  964. timestamp: data.timestamp
  965. });
  966. if (this.pdfOutlineViewer) {
  967. pdfDocument.getOutline().then(outline => {
  968. if (pdfDocument !== this.pdfDocument) {
  969. return;
  970. }
  971. this.pdfOutlineViewer.render({
  972. outline,
  973. pdfDocument
  974. });
  975. });
  976. }
  977. if (this.pdfAttachmentViewer) {
  978. pdfDocument.getAttachments().then(attachments => {
  979. if (pdfDocument !== this.pdfDocument) {
  980. return;
  981. }
  982. this.pdfAttachmentViewer.render({
  983. attachments
  984. });
  985. });
  986. }
  987. if (this.pdfLayerViewer) {
  988. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  989. if (pdfDocument !== this.pdfDocument) {
  990. return;
  991. }
  992. this.pdfLayerViewer.render({
  993. optionalContentConfig,
  994. pdfDocument
  995. });
  996. });
  997. }
  998. });
  999. this._initializePageLabels(pdfDocument);
  1000. this._initializeMetadata(pdfDocument);
  1001. },
  1002. async _scriptingDocProperties(pdfDocument) {
  1003. if (!this.documentInfo) {
  1004. await new Promise(resolve => {
  1005. this.eventBus._on("metadataloaded", resolve, {
  1006. once: true
  1007. });
  1008. });
  1009. if (pdfDocument !== this.pdfDocument) {
  1010. return null;
  1011. }
  1012. }
  1013. if (!this._contentLength) {
  1014. await new Promise(resolve => {
  1015. this.eventBus._on("documentloaded", resolve, {
  1016. once: true
  1017. });
  1018. });
  1019. if (pdfDocument !== this.pdfDocument) {
  1020. return null;
  1021. }
  1022. }
  1023. return {
  1024. ...this.documentInfo,
  1025. baseURL: this.baseUrl,
  1026. filesize: this._contentLength,
  1027. filename: this._docFilename,
  1028. metadata: this.metadata?.getRaw(),
  1029. authors: this.metadata?.get("dc:creator"),
  1030. numPages: this.pagesCount,
  1031. URL: this.url
  1032. };
  1033. },
  1034. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1035. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  1036. if (pdfDocument !== this.pdfDocument) {
  1037. return;
  1038. }
  1039. let triggerAutoPrint = false;
  1040. if (openAction?.action === "Print") {
  1041. triggerAutoPrint = true;
  1042. }
  1043. if (javaScript) {
  1044. javaScript.some(js => {
  1045. if (!js) {
  1046. return false;
  1047. }
  1048. console.warn("Warning: JavaScript support is not enabled");
  1049. return true;
  1050. });
  1051. if (!triggerAutoPrint) {
  1052. for (const js of javaScript) {
  1053. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1054. triggerAutoPrint = true;
  1055. break;
  1056. }
  1057. }
  1058. }
  1059. }
  1060. if (triggerAutoPrint) {
  1061. this.triggerPrinting();
  1062. }
  1063. },
  1064. async _initializeMetadata(pdfDocument) {
  1065. const {
  1066. info,
  1067. metadata,
  1068. contentDispositionFilename,
  1069. contentLength
  1070. } = await pdfDocument.getMetadata();
  1071. if (pdfDocument !== this.pdfDocument) {
  1072. return;
  1073. }
  1074. this.documentInfo = info;
  1075. this.metadata = metadata;
  1076. this._contentDispositionFilename ??= contentDispositionFilename;
  1077. this._contentLength ??= contentLength;
  1078. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`);
  1079. let pdfTitle = info.Title;
  1080. const metadataTitle = metadata?.get("dc:title");
  1081. if (metadataTitle) {
  1082. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1083. pdfTitle = metadataTitle;
  1084. }
  1085. }
  1086. if (pdfTitle) {
  1087. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  1088. } else if (this._contentDispositionFilename) {
  1089. this.setTitle(this._contentDispositionFilename);
  1090. }
  1091. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1092. if (pdfDocument.loadingParams.enableXfa) {
  1093. console.warn("Warning: XFA Foreground documents are not supported");
  1094. } else {
  1095. console.warn("Warning: XFA support is not enabled");
  1096. }
  1097. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  1098. console.warn("Warning: Interactive form support is not enabled");
  1099. }
  1100. if (info.IsSignaturesPresent) {
  1101. console.warn("Warning: Digital signatures validation is not supported");
  1102. }
  1103. this.eventBus.dispatch("metadataloaded", {
  1104. source: this
  1105. });
  1106. },
  1107. async _initializePageLabels(pdfDocument) {
  1108. const labels = await pdfDocument.getPageLabels();
  1109. if (pdfDocument !== this.pdfDocument) {
  1110. return;
  1111. }
  1112. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1113. return;
  1114. }
  1115. const numLabels = labels.length;
  1116. let standardLabels = 0,
  1117. emptyLabels = 0;
  1118. for (let i = 0; i < numLabels; i++) {
  1119. const label = labels[i];
  1120. if (label === (i + 1).toString()) {
  1121. standardLabels++;
  1122. } else if (label === "") {
  1123. emptyLabels++;
  1124. } else {
  1125. break;
  1126. }
  1127. }
  1128. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  1129. return;
  1130. }
  1131. const {
  1132. pdfViewer,
  1133. pdfThumbnailViewer,
  1134. toolbar
  1135. } = this;
  1136. pdfViewer.setPageLabels(labels);
  1137. pdfThumbnailViewer?.setPageLabels(labels);
  1138. toolbar?.setPagesCount(numLabels, true);
  1139. toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1140. },
  1141. _initializePdfHistory({
  1142. fingerprint,
  1143. viewOnLoad,
  1144. initialDest = null
  1145. }) {
  1146. if (!this.pdfHistory) {
  1147. return;
  1148. }
  1149. this.pdfHistory.initialize({
  1150. fingerprint,
  1151. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1152. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1153. });
  1154. if (this.pdfHistory.initialBookmark) {
  1155. this.initialBookmark = this.pdfHistory.initialBookmark;
  1156. this.initialRotation = this.pdfHistory.initialRotation;
  1157. }
  1158. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1159. this.initialBookmark = JSON.stringify(initialDest);
  1160. this.pdfHistory.push({
  1161. explicitDest: initialDest,
  1162. pageNumber: null
  1163. });
  1164. }
  1165. },
  1166. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1167. if (pdfDocument !== this.pdfDocument) {
  1168. return;
  1169. }
  1170. const {
  1171. annotationStorage
  1172. } = pdfDocument;
  1173. annotationStorage.onSetModified = () => {
  1174. window.addEventListener("beforeunload", beforeUnload);
  1175. this._annotationStorageModified = true;
  1176. };
  1177. annotationStorage.onResetModified = () => {
  1178. window.removeEventListener("beforeunload", beforeUnload);
  1179. delete this._annotationStorageModified;
  1180. };
  1181. annotationStorage.onAnnotationEditor = typeStr => {
  1182. this._hasAnnotationEditors = !!typeStr;
  1183. this.setTitle();
  1184. if (typeStr) {
  1185. this.externalServices.reportTelemetry({
  1186. type: "editing",
  1187. data: {
  1188. type: typeStr
  1189. }
  1190. });
  1191. }
  1192. };
  1193. },
  1194. setInitialView(storedHash, {
  1195. rotation,
  1196. sidebarView,
  1197. scrollMode,
  1198. spreadMode
  1199. } = {}) {
  1200. const setRotation = angle => {
  1201. if ((0, _ui_utils.isValidRotation)(angle)) {
  1202. this.pdfViewer.pagesRotation = angle;
  1203. }
  1204. };
  1205. const setViewerModes = (scroll, spread) => {
  1206. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1207. this.pdfViewer.scrollMode = scroll;
  1208. }
  1209. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1210. this.pdfViewer.spreadMode = spread;
  1211. }
  1212. };
  1213. this.isInitialViewSet = true;
  1214. this.pdfSidebar?.setInitialView(sidebarView);
  1215. setViewerModes(scrollMode, spreadMode);
  1216. if (this.initialBookmark) {
  1217. setRotation(this.initialRotation);
  1218. delete this.initialRotation;
  1219. this.pdfLinkService.setHash(this.initialBookmark);
  1220. this.initialBookmark = null;
  1221. } else if (storedHash) {
  1222. setRotation(rotation);
  1223. this.pdfLinkService.setHash(storedHash);
  1224. }
  1225. this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1226. this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
  1227. if (!this.pdfViewer.currentScaleValue) {
  1228. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1229. }
  1230. },
  1231. _cleanup() {
  1232. if (!this.pdfDocument) {
  1233. return;
  1234. }
  1235. this.pdfViewer.cleanup();
  1236. this.pdfThumbnailViewer?.cleanup();
  1237. this.pdfDocument.cleanup();
  1238. },
  1239. forceRendering() {
  1240. this.pdfRenderingQueue.printing = !!this.printService;
  1241. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS;
  1242. this.pdfRenderingQueue.renderHighestPriority();
  1243. },
  1244. beforePrint() {
  1245. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => {
  1246. return this.pdfDocument?.annotationStorage.print;
  1247. });
  1248. if (this.printService) {
  1249. return;
  1250. }
  1251. if (!this.supportsPrinting) {
  1252. this.l10n.get("printing_not_supported").then(msg => {
  1253. this._otherError(msg);
  1254. });
  1255. return;
  1256. }
  1257. if (!this.pdfViewer.pageViewsReady) {
  1258. this.l10n.get("printing_not_ready").then(msg => {
  1259. window.alert(msg);
  1260. });
  1261. return;
  1262. }
  1263. const pagesOverview = this.pdfViewer.getPagesOverview();
  1264. const printContainer = this.appConfig.printContainer;
  1265. const printResolution = _app_options.AppOptions.get("printResolution");
  1266. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1267. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  1268. this.printService = printService;
  1269. this.forceRendering();
  1270. this.setTitle();
  1271. printService.layout();
  1272. if (this._hasAnnotationEditors) {
  1273. this.externalServices.reportTelemetry({
  1274. type: "editing",
  1275. data: {
  1276. type: "print"
  1277. }
  1278. });
  1279. }
  1280. },
  1281. afterPrint() {
  1282. if (this._printAnnotationStoragePromise) {
  1283. this._printAnnotationStoragePromise.then(() => {
  1284. this.pdfScriptingManager.dispatchDidPrint();
  1285. });
  1286. this._printAnnotationStoragePromise = null;
  1287. }
  1288. if (this.printService) {
  1289. this.printService.destroy();
  1290. this.printService = null;
  1291. this.pdfDocument?.annotationStorage.resetModified();
  1292. }
  1293. this.forceRendering();
  1294. this.setTitle();
  1295. },
  1296. rotatePages(delta) {
  1297. this.pdfViewer.pagesRotation += delta;
  1298. },
  1299. requestPresentationMode() {
  1300. this.pdfPresentationMode?.request();
  1301. },
  1302. triggerPrinting() {
  1303. if (!this.supportsPrinting) {
  1304. return;
  1305. }
  1306. window.print();
  1307. },
  1308. bindEvents() {
  1309. const {
  1310. eventBus,
  1311. _boundEvents
  1312. } = this;
  1313. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1314. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1315. eventBus._on("resize", webViewerResize);
  1316. eventBus._on("hashchange", webViewerHashchange);
  1317. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1318. eventBus._on("afterprint", _boundEvents.afterPrint);
  1319. eventBus._on("pagerender", webViewerPageRender);
  1320. eventBus._on("pagerendered", webViewerPageRendered);
  1321. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1322. eventBus._on("pagechanging", webViewerPageChanging);
  1323. eventBus._on("scalechanging", webViewerScaleChanging);
  1324. eventBus._on("rotationchanging", webViewerRotationChanging);
  1325. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1326. eventBus._on("pagemode", webViewerPageMode);
  1327. eventBus._on("namedaction", webViewerNamedAction);
  1328. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1329. eventBus._on("presentationmode", webViewerPresentationMode);
  1330. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  1331. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  1332. eventBus._on("print", webViewerPrint);
  1333. eventBus._on("download", webViewerDownload);
  1334. eventBus._on("openinexternalapp", webViewerOpenInExternalApp);
  1335. eventBus._on("firstpage", webViewerFirstPage);
  1336. eventBus._on("lastpage", webViewerLastPage);
  1337. eventBus._on("nextpage", webViewerNextPage);
  1338. eventBus._on("previouspage", webViewerPreviousPage);
  1339. eventBus._on("zoomin", webViewerZoomIn);
  1340. eventBus._on("zoomout", webViewerZoomOut);
  1341. eventBus._on("zoomreset", webViewerZoomReset);
  1342. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1343. eventBus._on("scalechanged", webViewerScaleChanged);
  1344. eventBus._on("rotatecw", webViewerRotateCw);
  1345. eventBus._on("rotateccw", webViewerRotateCcw);
  1346. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1347. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1348. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1349. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1350. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1351. eventBus._on("documentproperties", webViewerDocumentProperties);
  1352. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1353. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1354. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1355. if (_app_options.AppOptions.get("pdfBug")) {
  1356. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1357. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1358. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1359. }
  1360. eventBus._on("fileinputchange", webViewerFileInputChange);
  1361. eventBus._on("openfile", webViewerOpenFile);
  1362. },
  1363. bindWindowEvents() {
  1364. const {
  1365. eventBus,
  1366. _boundEvents
  1367. } = this;
  1368. function addWindowResolutionChange(evt = null) {
  1369. if (evt) {
  1370. webViewerResolutionChange(evt);
  1371. }
  1372. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  1373. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  1374. once: true
  1375. });
  1376. _boundEvents.removeWindowResolutionChange ||= function () {
  1377. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  1378. _boundEvents.removeWindowResolutionChange = null;
  1379. };
  1380. }
  1381. addWindowResolutionChange();
  1382. _boundEvents.windowResize = () => {
  1383. eventBus.dispatch("resize", {
  1384. source: window
  1385. });
  1386. };
  1387. _boundEvents.windowHashChange = () => {
  1388. eventBus.dispatch("hashchange", {
  1389. source: window,
  1390. hash: document.location.hash.substring(1)
  1391. });
  1392. };
  1393. _boundEvents.windowBeforePrint = () => {
  1394. eventBus.dispatch("beforeprint", {
  1395. source: window
  1396. });
  1397. };
  1398. _boundEvents.windowAfterPrint = () => {
  1399. eventBus.dispatch("afterprint", {
  1400. source: window
  1401. });
  1402. };
  1403. _boundEvents.windowUpdateFromSandbox = event => {
  1404. eventBus.dispatch("updatefromsandbox", {
  1405. source: window,
  1406. detail: event.detail
  1407. });
  1408. };
  1409. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1410. window.addEventListener("wheel", webViewerWheel, {
  1411. passive: false
  1412. });
  1413. window.addEventListener("touchstart", webViewerTouchStart, {
  1414. passive: false
  1415. });
  1416. window.addEventListener("touchmove", webViewerTouchMove, {
  1417. passive: false
  1418. });
  1419. window.addEventListener("touchend", webViewerTouchEnd, {
  1420. passive: false
  1421. });
  1422. window.addEventListener("click", webViewerClick);
  1423. window.addEventListener("keydown", webViewerKeyDown);
  1424. window.addEventListener("keyup", webViewerKeyUp);
  1425. window.addEventListener("resize", _boundEvents.windowResize);
  1426. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1427. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1428. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1429. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1430. },
  1431. unbindEvents() {
  1432. const {
  1433. eventBus,
  1434. _boundEvents
  1435. } = this;
  1436. eventBus._off("resize", webViewerResize);
  1437. eventBus._off("hashchange", webViewerHashchange);
  1438. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1439. eventBus._off("afterprint", _boundEvents.afterPrint);
  1440. eventBus._off("pagerender", webViewerPageRender);
  1441. eventBus._off("pagerendered", webViewerPageRendered);
  1442. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1443. eventBus._off("pagechanging", webViewerPageChanging);
  1444. eventBus._off("scalechanging", webViewerScaleChanging);
  1445. eventBus._off("rotationchanging", webViewerRotationChanging);
  1446. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1447. eventBus._off("pagemode", webViewerPageMode);
  1448. eventBus._off("namedaction", webViewerNamedAction);
  1449. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1450. eventBus._off("presentationmode", webViewerPresentationMode);
  1451. eventBus._off("print", webViewerPrint);
  1452. eventBus._off("download", webViewerDownload);
  1453. eventBus._off("openinexternalapp", webViewerOpenInExternalApp);
  1454. eventBus._off("firstpage", webViewerFirstPage);
  1455. eventBus._off("lastpage", webViewerLastPage);
  1456. eventBus._off("nextpage", webViewerNextPage);
  1457. eventBus._off("previouspage", webViewerPreviousPage);
  1458. eventBus._off("zoomin", webViewerZoomIn);
  1459. eventBus._off("zoomout", webViewerZoomOut);
  1460. eventBus._off("zoomreset", webViewerZoomReset);
  1461. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1462. eventBus._off("scalechanged", webViewerScaleChanged);
  1463. eventBus._off("rotatecw", webViewerRotateCw);
  1464. eventBus._off("rotateccw", webViewerRotateCcw);
  1465. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1466. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1467. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1468. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1469. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1470. eventBus._off("documentproperties", webViewerDocumentProperties);
  1471. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1472. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1473. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1474. if (_boundEvents.reportPageStatsPDFBug) {
  1475. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1476. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1477. _boundEvents.reportPageStatsPDFBug = null;
  1478. }
  1479. eventBus._off("fileinputchange", webViewerFileInputChange);
  1480. eventBus._off("openfile", webViewerOpenFile);
  1481. _boundEvents.beforePrint = null;
  1482. _boundEvents.afterPrint = null;
  1483. },
  1484. unbindWindowEvents() {
  1485. const {
  1486. _boundEvents
  1487. } = this;
  1488. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1489. window.removeEventListener("wheel", webViewerWheel, {
  1490. passive: false
  1491. });
  1492. window.removeEventListener("touchstart", webViewerTouchStart, {
  1493. passive: false
  1494. });
  1495. window.removeEventListener("touchmove", webViewerTouchMove, {
  1496. passive: false
  1497. });
  1498. window.removeEventListener("touchend", webViewerTouchEnd, {
  1499. passive: false
  1500. });
  1501. window.removeEventListener("click", webViewerClick);
  1502. window.removeEventListener("keydown", webViewerKeyDown);
  1503. window.removeEventListener("keyup", webViewerKeyUp);
  1504. window.removeEventListener("resize", _boundEvents.windowResize);
  1505. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1506. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1507. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1508. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1509. _boundEvents.removeWindowResolutionChange?.();
  1510. _boundEvents.windowResize = null;
  1511. _boundEvents.windowHashChange = null;
  1512. _boundEvents.windowBeforePrint = null;
  1513. _boundEvents.windowAfterPrint = null;
  1514. _boundEvents.windowUpdateFromSandbox = null;
  1515. },
  1516. _accumulateTicks(ticks, prop) {
  1517. if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) {
  1518. this[prop] = 0;
  1519. }
  1520. this[prop] += ticks;
  1521. const wholeTicks = Math.trunc(this[prop]);
  1522. this[prop] -= wholeTicks;
  1523. return wholeTicks;
  1524. },
  1525. _accumulateFactor(previousScale, factor, prop) {
  1526. if (factor === 1) {
  1527. return 1;
  1528. }
  1529. if (this[prop] > 1 && factor < 1 || this[prop] < 1 && factor > 1) {
  1530. this[prop] = 1;
  1531. }
  1532. const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale);
  1533. this[prop] = factor / newFactor;
  1534. return newFactor;
  1535. },
  1536. _centerAtPos(previousScale, x, y) {
  1537. const {
  1538. pdfViewer
  1539. } = this;
  1540. const scaleDiff = pdfViewer.currentScale / previousScale - 1;
  1541. if (scaleDiff !== 0) {
  1542. const [top, left] = pdfViewer.containerTopLeft;
  1543. pdfViewer.container.scrollLeft += (x - left) * scaleDiff;
  1544. pdfViewer.container.scrollTop += (y - top) * scaleDiff;
  1545. }
  1546. },
  1547. _unblockDocumentLoadEvent() {
  1548. document.blockUnblockOnload?.(false);
  1549. this._unblockDocumentLoadEvent = () => {};
  1550. },
  1551. get scriptingReady() {
  1552. return this.pdfScriptingManager.ready;
  1553. }
  1554. };
  1555. exports.PDFViewerApplication = PDFViewerApplication;
  1556. {
  1557. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1558. var validateFileURL = function (file) {
  1559. if (!file) {
  1560. return;
  1561. }
  1562. try {
  1563. const viewerOrigin = new URL(window.location.href).origin || "null";
  1564. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1565. return;
  1566. }
  1567. const fileOrigin = new URL(file, window.location.href).origin;
  1568. if (fileOrigin !== viewerOrigin) {
  1569. throw new Error("file origin does not match viewer's");
  1570. }
  1571. } catch (ex) {
  1572. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1573. PDFViewerApplication._documentError(msg, {
  1574. message: ex?.message
  1575. });
  1576. });
  1577. throw ex;
  1578. }
  1579. };
  1580. }
  1581. async function loadFakeWorker() {
  1582. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  1583. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  1584. }
  1585. async function loadPDFBug(self) {
  1586. const {
  1587. debuggerScriptPath
  1588. } = self.appConfig;
  1589. const {
  1590. PDFBug
  1591. } = await import(debuggerScriptPath);
  1592. self._PDFBug = PDFBug;
  1593. }
  1594. function reportPageStatsPDFBug({
  1595. pageNumber
  1596. }) {
  1597. if (!globalThis.Stats?.enabled) {
  1598. return;
  1599. }
  1600. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1601. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  1602. }
  1603. function webViewerInitialized() {
  1604. const {
  1605. appConfig,
  1606. eventBus,
  1607. l10n
  1608. } = PDFViewerApplication;
  1609. let file;
  1610. const queryString = document.location.search.substring(1);
  1611. const params = (0, _ui_utils.parseQueryString)(queryString);
  1612. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  1613. validateFileURL(file);
  1614. const fileInput = appConfig.openFileInput;
  1615. fileInput.value = null;
  1616. fileInput.addEventListener("change", function (evt) {
  1617. const {
  1618. files
  1619. } = evt.target;
  1620. if (!files || files.length === 0) {
  1621. return;
  1622. }
  1623. eventBus.dispatch("fileinputchange", {
  1624. source: this,
  1625. fileInput: evt.target
  1626. });
  1627. });
  1628. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1629. evt.preventDefault();
  1630. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  1631. });
  1632. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1633. evt.preventDefault();
  1634. const {
  1635. files
  1636. } = evt.dataTransfer;
  1637. if (!files || files.length === 0) {
  1638. return;
  1639. }
  1640. eventBus.dispatch("fileinputchange", {
  1641. source: this,
  1642. fileInput: evt.dataTransfer
  1643. });
  1644. });
  1645. if (!PDFViewerApplication.supportsDocumentFonts) {
  1646. _app_options.AppOptions.set("disableFontFace", true);
  1647. l10n.get("web_fonts_disabled").then(msg => {
  1648. console.warn(msg);
  1649. });
  1650. }
  1651. if (!PDFViewerApplication.supportsPrinting) {
  1652. appConfig.toolbar?.print?.classList.add("hidden");
  1653. appConfig.secondaryToolbar?.printButton.classList.add("hidden");
  1654. }
  1655. if (!PDFViewerApplication.supportsFullscreen) {
  1656. appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
  1657. }
  1658. if (PDFViewerApplication.supportsIntegratedFind) {
  1659. appConfig.toolbar?.viewFind?.classList.add("hidden");
  1660. }
  1661. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1662. if (evt.target === this) {
  1663. eventBus.dispatch("resize", {
  1664. source: this
  1665. });
  1666. }
  1667. }, true);
  1668. try {
  1669. if (file) {
  1670. PDFViewerApplication.open({
  1671. url: file
  1672. });
  1673. } else {
  1674. PDFViewerApplication._hideViewBookmark();
  1675. }
  1676. } catch (reason) {
  1677. l10n.get("loading_error").then(msg => {
  1678. PDFViewerApplication._documentError(msg, reason);
  1679. });
  1680. }
  1681. }
  1682. function webViewerPageRender({
  1683. pageNumber
  1684. }) {
  1685. if (pageNumber === PDFViewerApplication.page) {
  1686. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
  1687. }
  1688. }
  1689. function webViewerPageRendered({
  1690. pageNumber,
  1691. error
  1692. }) {
  1693. if (pageNumber === PDFViewerApplication.page) {
  1694. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
  1695. }
  1696. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  1697. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1698. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
  1699. if (pageView) {
  1700. thumbnailView?.setImage(pageView);
  1701. }
  1702. }
  1703. if (error) {
  1704. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1705. PDFViewerApplication._otherError(msg, error);
  1706. });
  1707. }
  1708. }
  1709. function webViewerPageMode({
  1710. mode
  1711. }) {
  1712. let view;
  1713. switch (mode) {
  1714. case "thumbs":
  1715. view = _ui_utils.SidebarView.THUMBS;
  1716. break;
  1717. case "bookmarks":
  1718. case "outline":
  1719. view = _ui_utils.SidebarView.OUTLINE;
  1720. break;
  1721. case "attachments":
  1722. view = _ui_utils.SidebarView.ATTACHMENTS;
  1723. break;
  1724. case "layers":
  1725. view = _ui_utils.SidebarView.LAYERS;
  1726. break;
  1727. case "none":
  1728. view = _ui_utils.SidebarView.NONE;
  1729. break;
  1730. default:
  1731. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1732. return;
  1733. }
  1734. PDFViewerApplication.pdfSidebar?.switchView(view, true);
  1735. }
  1736. function webViewerNamedAction(evt) {
  1737. switch (evt.action) {
  1738. case "GoToPage":
  1739. PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
  1740. break;
  1741. case "Find":
  1742. if (!PDFViewerApplication.supportsIntegratedFind) {
  1743. PDFViewerApplication?.findBar.toggle();
  1744. }
  1745. break;
  1746. case "Print":
  1747. PDFViewerApplication.triggerPrinting();
  1748. break;
  1749. case "SaveAs":
  1750. PDFViewerApplication.downloadOrSave();
  1751. break;
  1752. }
  1753. }
  1754. function webViewerPresentationModeChanged(evt) {
  1755. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1756. }
  1757. function webViewerSidebarViewChanged({
  1758. view
  1759. }) {
  1760. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  1761. if (PDFViewerApplication.isInitialViewSet) {
  1762. PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
  1763. }
  1764. }
  1765. function webViewerUpdateViewarea({
  1766. location
  1767. }) {
  1768. if (PDFViewerApplication.isInitialViewSet) {
  1769. PDFViewerApplication.store?.setMultiple({
  1770. page: location.pageNumber,
  1771. zoom: location.scale,
  1772. scrollLeft: location.left,
  1773. scrollTop: location.top,
  1774. rotation: location.rotation
  1775. }).catch(() => {});
  1776. }
  1777. if (PDFViewerApplication.appConfig.secondaryToolbar) {
  1778. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1779. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1780. }
  1781. }
  1782. function webViewerScrollModeChanged(evt) {
  1783. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1784. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  1785. }
  1786. }
  1787. function webViewerSpreadModeChanged(evt) {
  1788. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1789. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  1790. }
  1791. }
  1792. function webViewerResize() {
  1793. const {
  1794. pdfDocument,
  1795. pdfViewer,
  1796. pdfRenderingQueue
  1797. } = PDFViewerApplication;
  1798. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  1799. return;
  1800. }
  1801. if (!pdfDocument) {
  1802. return;
  1803. }
  1804. const currentScaleValue = pdfViewer.currentScaleValue;
  1805. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  1806. pdfViewer.currentScaleValue = currentScaleValue;
  1807. }
  1808. pdfViewer.update();
  1809. }
  1810. function webViewerHashchange(evt) {
  1811. const hash = evt.hash;
  1812. if (!hash) {
  1813. return;
  1814. }
  1815. if (!PDFViewerApplication.isInitialViewSet) {
  1816. PDFViewerApplication.initialBookmark = hash;
  1817. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  1818. PDFViewerApplication.pdfLinkService.setHash(hash);
  1819. }
  1820. }
  1821. {
  1822. var webViewerFileInputChange = function (evt) {
  1823. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  1824. return;
  1825. }
  1826. const file = evt.fileInput.files[0];
  1827. PDFViewerApplication.open({
  1828. url: URL.createObjectURL(file),
  1829. originalUrl: file.name
  1830. });
  1831. };
  1832. var webViewerOpenFile = function (evt) {
  1833. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  1834. fileInput.click();
  1835. };
  1836. }
  1837. function webViewerPresentationMode() {
  1838. PDFViewerApplication.requestPresentationMode();
  1839. }
  1840. function webViewerSwitchAnnotationEditorMode(evt) {
  1841. PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
  1842. }
  1843. function webViewerSwitchAnnotationEditorParams(evt) {
  1844. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  1845. }
  1846. function webViewerPrint() {
  1847. PDFViewerApplication.triggerPrinting();
  1848. }
  1849. function webViewerDownload() {
  1850. PDFViewerApplication.downloadOrSave();
  1851. }
  1852. function webViewerOpenInExternalApp() {
  1853. PDFViewerApplication.openInExternalApp();
  1854. }
  1855. function webViewerFirstPage() {
  1856. PDFViewerApplication.page = 1;
  1857. }
  1858. function webViewerLastPage() {
  1859. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1860. }
  1861. function webViewerNextPage() {
  1862. PDFViewerApplication.pdfViewer.nextPage();
  1863. }
  1864. function webViewerPreviousPage() {
  1865. PDFViewerApplication.pdfViewer.previousPage();
  1866. }
  1867. function webViewerZoomIn() {
  1868. PDFViewerApplication.zoomIn();
  1869. }
  1870. function webViewerZoomOut() {
  1871. PDFViewerApplication.zoomOut();
  1872. }
  1873. function webViewerZoomReset() {
  1874. PDFViewerApplication.zoomReset();
  1875. }
  1876. function webViewerPageNumberChanged(evt) {
  1877. const pdfViewer = PDFViewerApplication.pdfViewer;
  1878. if (evt.value !== "") {
  1879. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  1880. }
  1881. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1882. PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1883. }
  1884. }
  1885. function webViewerScaleChanged(evt) {
  1886. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1887. }
  1888. function webViewerRotateCw() {
  1889. PDFViewerApplication.rotatePages(90);
  1890. }
  1891. function webViewerRotateCcw() {
  1892. PDFViewerApplication.rotatePages(-90);
  1893. }
  1894. function webViewerOptionalContentConfig(evt) {
  1895. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  1896. }
  1897. function webViewerSwitchScrollMode(evt) {
  1898. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  1899. }
  1900. function webViewerSwitchSpreadMode(evt) {
  1901. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  1902. }
  1903. function webViewerDocumentProperties() {
  1904. PDFViewerApplication.pdfDocumentProperties?.open();
  1905. }
  1906. function webViewerFindFromUrlHash(evt) {
  1907. PDFViewerApplication.eventBus.dispatch("find", {
  1908. source: evt.source,
  1909. type: "",
  1910. query: evt.query,
  1911. caseSensitive: false,
  1912. entireWord: false,
  1913. highlightAll: true,
  1914. findPrevious: false,
  1915. matchDiacritics: true
  1916. });
  1917. }
  1918. function webViewerUpdateFindMatchesCount({
  1919. matchesCount
  1920. }) {
  1921. if (PDFViewerApplication.supportsIntegratedFind) {
  1922. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  1923. } else {
  1924. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  1925. }
  1926. }
  1927. function webViewerUpdateFindControlState({
  1928. state,
  1929. previous,
  1930. matchesCount,
  1931. rawQuery
  1932. }) {
  1933. if (PDFViewerApplication.supportsIntegratedFind) {
  1934. PDFViewerApplication.externalServices.updateFindControlState({
  1935. result: state,
  1936. findPrevious: previous,
  1937. matchesCount,
  1938. rawQuery
  1939. });
  1940. } else {
  1941. PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount);
  1942. }
  1943. }
  1944. function webViewerScaleChanging(evt) {
  1945. PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
  1946. PDFViewerApplication.pdfViewer.update();
  1947. }
  1948. function webViewerRotationChanging(evt) {
  1949. if (PDFViewerApplication.pdfThumbnailViewer) {
  1950. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  1951. }
  1952. PDFViewerApplication.forceRendering();
  1953. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  1954. }
  1955. function webViewerPageChanging({
  1956. pageNumber,
  1957. pageLabel
  1958. }) {
  1959. PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
  1960. PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
  1961. if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
  1962. PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
  1963. }
  1964. const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1965. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING);
  1966. }
  1967. function webViewerResolutionChange(evt) {
  1968. PDFViewerApplication.pdfViewer.refresh();
  1969. }
  1970. function webViewerVisibilityChange(evt) {
  1971. if (document.visibilityState === "visible") {
  1972. setZoomDisabledTimeout();
  1973. }
  1974. }
  1975. let zoomDisabledTimeout = null;
  1976. function setZoomDisabledTimeout() {
  1977. if (zoomDisabledTimeout) {
  1978. clearTimeout(zoomDisabledTimeout);
  1979. }
  1980. zoomDisabledTimeout = setTimeout(function () {
  1981. zoomDisabledTimeout = null;
  1982. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  1983. }
  1984. function webViewerWheel(evt) {
  1985. const {
  1986. pdfViewer,
  1987. supportedMouseWheelZoomModifierKeys,
  1988. supportsPinchToZoom
  1989. } = PDFViewerApplication;
  1990. if (pdfViewer.isInPresentationMode) {
  1991. return;
  1992. }
  1993. const deltaMode = evt.deltaMode;
  1994. let scaleFactor = Math.exp(-evt.deltaY / 100);
  1995. const isBuiltInMac = false;
  1996. const isPinchToZoom = evt.ctrlKey && !PDFViewerApplication._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && (Math.abs(scaleFactor - 1) < 0.05 || isBuiltInMac) && evt.deltaZ === 0;
  1997. if (isPinchToZoom || evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  1998. evt.preventDefault();
  1999. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2000. return;
  2001. }
  2002. const previousScale = pdfViewer.currentScale;
  2003. if (isPinchToZoom && supportsPinchToZoom) {
  2004. scaleFactor = PDFViewerApplication._accumulateFactor(previousScale, scaleFactor, "_wheelUnusedFactor");
  2005. if (scaleFactor < 1) {
  2006. PDFViewerApplication.zoomOut(null, scaleFactor);
  2007. } else if (scaleFactor > 1) {
  2008. PDFViewerApplication.zoomIn(null, scaleFactor);
  2009. } else {
  2010. return;
  2011. }
  2012. } else {
  2013. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2014. let ticks = 0;
  2015. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2016. if (Math.abs(delta) >= 1) {
  2017. ticks = Math.sign(delta);
  2018. } else {
  2019. ticks = PDFViewerApplication._accumulateTicks(delta, "_wheelUnusedTicks");
  2020. }
  2021. } else {
  2022. const PIXELS_PER_LINE_SCALE = 30;
  2023. ticks = PDFViewerApplication._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks");
  2024. }
  2025. if (ticks < 0) {
  2026. PDFViewerApplication.zoomOut(-ticks);
  2027. } else if (ticks > 0) {
  2028. PDFViewerApplication.zoomIn(ticks);
  2029. } else {
  2030. return;
  2031. }
  2032. }
  2033. PDFViewerApplication._centerAtPos(previousScale, evt.clientX, evt.clientY);
  2034. } else {
  2035. setZoomDisabledTimeout();
  2036. }
  2037. }
  2038. function webViewerTouchStart(evt) {
  2039. if (PDFViewerApplication.pdfViewer.isInPresentationMode || evt.touches.length < 2) {
  2040. return;
  2041. }
  2042. evt.preventDefault();
  2043. if (evt.touches.length !== 2) {
  2044. PDFViewerApplication._touchInfo = null;
  2045. return;
  2046. }
  2047. let [touch0, touch1] = evt.touches;
  2048. if (touch0.identifier > touch1.identifier) {
  2049. [touch0, touch1] = [touch1, touch0];
  2050. }
  2051. PDFViewerApplication._touchInfo = {
  2052. touch0X: touch0.pageX,
  2053. touch0Y: touch0.pageY,
  2054. touch1X: touch1.pageX,
  2055. touch1Y: touch1.pageY
  2056. };
  2057. }
  2058. function webViewerTouchMove(evt) {
  2059. if (!PDFViewerApplication._touchInfo || evt.touches.length !== 2) {
  2060. return;
  2061. }
  2062. const {
  2063. pdfViewer,
  2064. _touchInfo,
  2065. supportsPinchToZoom
  2066. } = PDFViewerApplication;
  2067. let [touch0, touch1] = evt.touches;
  2068. if (touch0.identifier > touch1.identifier) {
  2069. [touch0, touch1] = [touch1, touch0];
  2070. }
  2071. const {
  2072. pageX: page0X,
  2073. pageY: page0Y
  2074. } = touch0;
  2075. const {
  2076. pageX: page1X,
  2077. pageY: page1Y
  2078. } = touch1;
  2079. const {
  2080. touch0X: pTouch0X,
  2081. touch0Y: pTouch0Y,
  2082. touch1X: pTouch1X,
  2083. touch1Y: pTouch1Y
  2084. } = _touchInfo;
  2085. if (Math.abs(pTouch0X - page0X) <= 1 && Math.abs(pTouch0Y - page0Y) <= 1 && Math.abs(pTouch1X - page1X) <= 1 && Math.abs(pTouch1Y - page1Y) <= 1) {
  2086. return;
  2087. }
  2088. _touchInfo.touch0X = page0X;
  2089. _touchInfo.touch0Y = page0Y;
  2090. _touchInfo.touch1X = page1X;
  2091. _touchInfo.touch1Y = page1Y;
  2092. if (pTouch0X === page0X && pTouch0Y === page0Y) {
  2093. const v1X = pTouch1X - page0X;
  2094. const v1Y = pTouch1Y - page0Y;
  2095. const v2X = page1X - page0X;
  2096. const v2Y = page1Y - page0Y;
  2097. const det = v1X * v2Y - v1Y * v2X;
  2098. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  2099. return;
  2100. }
  2101. } else if (pTouch1X === page1X && pTouch1Y === page1Y) {
  2102. const v1X = pTouch0X - page1X;
  2103. const v1Y = pTouch0Y - page1Y;
  2104. const v2X = page0X - page1X;
  2105. const v2Y = page0Y - page1Y;
  2106. const det = v1X * v2Y - v1Y * v2X;
  2107. if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
  2108. return;
  2109. }
  2110. } else {
  2111. const diff0X = page0X - pTouch0X;
  2112. const diff1X = page1X - pTouch1X;
  2113. const diff0Y = page0Y - pTouch0Y;
  2114. const diff1Y = page1Y - pTouch1Y;
  2115. const dotProduct = diff0X * diff1X + diff0Y * diff1Y;
  2116. if (dotProduct >= 0) {
  2117. return;
  2118. }
  2119. }
  2120. evt.preventDefault();
  2121. const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1;
  2122. const pDistance = Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1;
  2123. const previousScale = pdfViewer.currentScale;
  2124. if (supportsPinchToZoom) {
  2125. const newScaleFactor = PDFViewerApplication._accumulateFactor(previousScale, distance / pDistance, "_touchUnusedFactor");
  2126. if (newScaleFactor < 1) {
  2127. PDFViewerApplication.zoomOut(null, newScaleFactor);
  2128. } else if (newScaleFactor > 1) {
  2129. PDFViewerApplication.zoomIn(null, newScaleFactor);
  2130. } else {
  2131. return;
  2132. }
  2133. } else {
  2134. const PIXELS_PER_LINE_SCALE = 30;
  2135. const ticks = PDFViewerApplication._accumulateTicks((distance - pDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks");
  2136. if (ticks < 0) {
  2137. PDFViewerApplication.zoomOut(-ticks);
  2138. } else if (ticks > 0) {
  2139. PDFViewerApplication.zoomIn(ticks);
  2140. } else {
  2141. return;
  2142. }
  2143. }
  2144. PDFViewerApplication._centerAtPos(previousScale, (page0X + page1X) / 2, (page0Y + page1Y) / 2);
  2145. }
  2146. function webViewerTouchEnd(evt) {
  2147. if (!PDFViewerApplication._touchInfo) {
  2148. return;
  2149. }
  2150. evt.preventDefault();
  2151. PDFViewerApplication._touchInfo = null;
  2152. PDFViewerApplication._touchUnusedTicks = 0;
  2153. PDFViewerApplication._touchUnusedFactor = 1;
  2154. }
  2155. function webViewerClick(evt) {
  2156. if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
  2157. return;
  2158. }
  2159. const appConfig = PDFViewerApplication.appConfig;
  2160. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) {
  2161. PDFViewerApplication.secondaryToolbar.close();
  2162. }
  2163. }
  2164. function webViewerKeyUp(evt) {
  2165. if (evt.key === "Control") {
  2166. PDFViewerApplication._isCtrlKeyDown = false;
  2167. }
  2168. }
  2169. function webViewerKeyDown(evt) {
  2170. PDFViewerApplication._isCtrlKeyDown = evt.key === "Control";
  2171. if (PDFViewerApplication.overlayManager.active) {
  2172. return;
  2173. }
  2174. const {
  2175. eventBus,
  2176. pdfViewer
  2177. } = PDFViewerApplication;
  2178. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  2179. let handled = false,
  2180. ensureViewerFocused = false;
  2181. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2182. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2183. switch (evt.keyCode) {
  2184. case 70:
  2185. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2186. PDFViewerApplication.findBar?.open();
  2187. handled = true;
  2188. }
  2189. break;
  2190. case 71:
  2191. if (!PDFViewerApplication.supportsIntegratedFind) {
  2192. const {
  2193. state
  2194. } = PDFViewerApplication.findController;
  2195. if (state) {
  2196. const newState = {
  2197. source: window,
  2198. type: "again",
  2199. findPrevious: cmd === 5 || cmd === 12
  2200. };
  2201. eventBus.dispatch("find", {
  2202. ...state,
  2203. ...newState
  2204. });
  2205. }
  2206. handled = true;
  2207. }
  2208. break;
  2209. case 61:
  2210. case 107:
  2211. case 187:
  2212. case 171:
  2213. PDFViewerApplication.zoomIn();
  2214. handled = true;
  2215. break;
  2216. case 173:
  2217. case 109:
  2218. case 189:
  2219. PDFViewerApplication.zoomOut();
  2220. handled = true;
  2221. break;
  2222. case 48:
  2223. case 96:
  2224. if (!isViewerInPresentationMode) {
  2225. setTimeout(function () {
  2226. PDFViewerApplication.zoomReset();
  2227. });
  2228. handled = false;
  2229. }
  2230. break;
  2231. case 38:
  2232. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2233. PDFViewerApplication.page = 1;
  2234. handled = true;
  2235. ensureViewerFocused = true;
  2236. }
  2237. break;
  2238. case 40:
  2239. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2240. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2241. handled = true;
  2242. ensureViewerFocused = true;
  2243. }
  2244. break;
  2245. }
  2246. }
  2247. if (cmd === 1 || cmd === 8) {
  2248. switch (evt.keyCode) {
  2249. case 83:
  2250. eventBus.dispatch("download", {
  2251. source: window
  2252. });
  2253. handled = true;
  2254. break;
  2255. case 79:
  2256. {
  2257. eventBus.dispatch("openfile", {
  2258. source: window
  2259. });
  2260. handled = true;
  2261. }
  2262. break;
  2263. }
  2264. }
  2265. if (cmd === 3 || cmd === 10) {
  2266. switch (evt.keyCode) {
  2267. case 80:
  2268. PDFViewerApplication.requestPresentationMode();
  2269. handled = true;
  2270. PDFViewerApplication.externalServices.reportTelemetry({
  2271. type: "buttons",
  2272. data: {
  2273. id: "presentationModeKeyboard"
  2274. }
  2275. });
  2276. break;
  2277. case 71:
  2278. if (PDFViewerApplication.appConfig.toolbar) {
  2279. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2280. handled = true;
  2281. }
  2282. break;
  2283. }
  2284. }
  2285. if (handled) {
  2286. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2287. pdfViewer.focus();
  2288. }
  2289. evt.preventDefault();
  2290. return;
  2291. }
  2292. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2293. const curElementTagName = curElement?.tagName.toUpperCase();
  2294. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2295. if (evt.keyCode !== 27) {
  2296. return;
  2297. }
  2298. }
  2299. if (cmd === 0) {
  2300. let turnPage = 0,
  2301. turnOnlyIfPageFit = false;
  2302. switch (evt.keyCode) {
  2303. case 38:
  2304. case 33:
  2305. if (pdfViewer.isVerticalScrollbarEnabled) {
  2306. turnOnlyIfPageFit = true;
  2307. }
  2308. turnPage = -1;
  2309. break;
  2310. case 8:
  2311. if (!isViewerInPresentationMode) {
  2312. turnOnlyIfPageFit = true;
  2313. }
  2314. turnPage = -1;
  2315. break;
  2316. case 37:
  2317. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2318. turnOnlyIfPageFit = true;
  2319. }
  2320. case 75:
  2321. case 80:
  2322. turnPage = -1;
  2323. break;
  2324. case 27:
  2325. if (PDFViewerApplication.secondaryToolbar?.isOpen) {
  2326. PDFViewerApplication.secondaryToolbar.close();
  2327. handled = true;
  2328. }
  2329. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) {
  2330. PDFViewerApplication.findBar.close();
  2331. handled = true;
  2332. }
  2333. break;
  2334. case 40:
  2335. case 34:
  2336. if (pdfViewer.isVerticalScrollbarEnabled) {
  2337. turnOnlyIfPageFit = true;
  2338. }
  2339. turnPage = 1;
  2340. break;
  2341. case 13:
  2342. case 32:
  2343. if (!isViewerInPresentationMode) {
  2344. turnOnlyIfPageFit = true;
  2345. }
  2346. turnPage = 1;
  2347. break;
  2348. case 39:
  2349. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2350. turnOnlyIfPageFit = true;
  2351. }
  2352. case 74:
  2353. case 78:
  2354. turnPage = 1;
  2355. break;
  2356. case 36:
  2357. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2358. PDFViewerApplication.page = 1;
  2359. handled = true;
  2360. ensureViewerFocused = true;
  2361. }
  2362. break;
  2363. case 35:
  2364. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2365. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2366. handled = true;
  2367. ensureViewerFocused = true;
  2368. }
  2369. break;
  2370. case 83:
  2371. PDFViewerApplication.pdfCursorTools?.switchTool(_ui_utils.CursorTool.SELECT);
  2372. break;
  2373. case 72:
  2374. PDFViewerApplication.pdfCursorTools?.switchTool(_ui_utils.CursorTool.HAND);
  2375. break;
  2376. case 82:
  2377. PDFViewerApplication.rotatePages(90);
  2378. break;
  2379. case 115:
  2380. PDFViewerApplication.pdfSidebar?.toggle();
  2381. break;
  2382. }
  2383. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2384. if (turnPage > 0) {
  2385. pdfViewer.nextPage();
  2386. } else {
  2387. pdfViewer.previousPage();
  2388. }
  2389. handled = true;
  2390. }
  2391. }
  2392. if (cmd === 4) {
  2393. switch (evt.keyCode) {
  2394. case 13:
  2395. case 32:
  2396. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2397. break;
  2398. }
  2399. pdfViewer.previousPage();
  2400. handled = true;
  2401. break;
  2402. case 82:
  2403. PDFViewerApplication.rotatePages(-90);
  2404. break;
  2405. }
  2406. }
  2407. if (!handled && !isViewerInPresentationMode) {
  2408. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2409. ensureViewerFocused = true;
  2410. }
  2411. }
  2412. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2413. pdfViewer.focus();
  2414. }
  2415. if (handled) {
  2416. evt.preventDefault();
  2417. }
  2418. }
  2419. function beforeUnload(evt) {
  2420. evt.preventDefault();
  2421. evt.returnValue = "";
  2422. return false;
  2423. }
  2424. function webViewerAnnotationEditorStatesChanged(data) {
  2425. PDFViewerApplication.externalServices.updateEditorStates(data);
  2426. }
  2427. const PDFPrintServiceFactory = {
  2428. instance: {
  2429. supportsPrinting: false,
  2430. createPrintService() {
  2431. throw new Error("Not implemented: createPrintService");
  2432. }
  2433. }
  2434. };
  2435. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2436. /***/ }),
  2437. /* 3 */
  2438. /***/ ((__unused_webpack_module, exports) => {
  2439. Object.defineProperty(exports, "__esModule", ({
  2440. value: true
  2441. }));
  2442. 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;
  2443. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  2444. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2445. exports.approximateFraction = approximateFraction;
  2446. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2447. exports.binarySearchFirstItem = binarySearchFirstItem;
  2448. exports.docStyle = void 0;
  2449. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2450. exports.getPageSizeInches = getPageSizeInches;
  2451. exports.getVisibleElements = getVisibleElements;
  2452. exports.isPortraitOrientation = isPortraitOrientation;
  2453. exports.isValidRotation = isValidRotation;
  2454. exports.isValidScrollMode = isValidScrollMode;
  2455. exports.isValidSpreadMode = isValidSpreadMode;
  2456. exports.noContextMenuHandler = noContextMenuHandler;
  2457. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2458. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2459. exports.parseQueryString = parseQueryString;
  2460. exports.removeNullCharacters = removeNullCharacters;
  2461. exports.roundToDivide = roundToDivide;
  2462. exports.scrollIntoView = scrollIntoView;
  2463. exports.toggleCheckedBtn = toggleCheckedBtn;
  2464. exports.toggleExpandedBtn = toggleExpandedBtn;
  2465. exports.watchScroll = watchScroll;
  2466. const DEFAULT_SCALE_VALUE = "auto";
  2467. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2468. const DEFAULT_SCALE = 1.0;
  2469. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2470. const DEFAULT_SCALE_DELTA = 1.1;
  2471. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  2472. const MIN_SCALE = 0.1;
  2473. exports.MIN_SCALE = MIN_SCALE;
  2474. const MAX_SCALE = 10.0;
  2475. exports.MAX_SCALE = MAX_SCALE;
  2476. const UNKNOWN_SCALE = 0;
  2477. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2478. const MAX_AUTO_SCALE = 1.25;
  2479. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2480. const SCROLLBAR_PADDING = 40;
  2481. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2482. const VERTICAL_PADDING = 5;
  2483. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2484. const RenderingStates = {
  2485. INITIAL: 0,
  2486. RUNNING: 1,
  2487. PAUSED: 2,
  2488. FINISHED: 3
  2489. };
  2490. exports.RenderingStates = RenderingStates;
  2491. const PresentationModeState = {
  2492. UNKNOWN: 0,
  2493. NORMAL: 1,
  2494. CHANGING: 2,
  2495. FULLSCREEN: 3
  2496. };
  2497. exports.PresentationModeState = PresentationModeState;
  2498. const SidebarView = {
  2499. UNKNOWN: -1,
  2500. NONE: 0,
  2501. THUMBS: 1,
  2502. OUTLINE: 2,
  2503. ATTACHMENTS: 3,
  2504. LAYERS: 4
  2505. };
  2506. exports.SidebarView = SidebarView;
  2507. const TextLayerMode = {
  2508. DISABLE: 0,
  2509. ENABLE: 1,
  2510. ENABLE_PERMISSIONS: 2
  2511. };
  2512. exports.TextLayerMode = TextLayerMode;
  2513. const ScrollMode = {
  2514. UNKNOWN: -1,
  2515. VERTICAL: 0,
  2516. HORIZONTAL: 1,
  2517. WRAPPED: 2,
  2518. PAGE: 3
  2519. };
  2520. exports.ScrollMode = ScrollMode;
  2521. const SpreadMode = {
  2522. UNKNOWN: -1,
  2523. NONE: 0,
  2524. ODD: 1,
  2525. EVEN: 2
  2526. };
  2527. exports.SpreadMode = SpreadMode;
  2528. const CursorTool = {
  2529. SELECT: 0,
  2530. HAND: 1,
  2531. ZOOM: 2
  2532. };
  2533. exports.CursorTool = CursorTool;
  2534. const AutoPrintRegExp = /\bprint\s*\(/;
  2535. exports.AutoPrintRegExp = AutoPrintRegExp;
  2536. class OutputScale {
  2537. constructor() {
  2538. const pixelRatio = window.devicePixelRatio || 1;
  2539. this.sx = pixelRatio;
  2540. this.sy = pixelRatio;
  2541. }
  2542. get scaled() {
  2543. return this.sx !== 1 || this.sy !== 1;
  2544. }
  2545. }
  2546. exports.OutputScale = OutputScale;
  2547. function scrollIntoView(element, spot, scrollMatches = false) {
  2548. let parent = element.offsetParent;
  2549. if (!parent) {
  2550. console.error("offsetParent is not set -- cannot scroll");
  2551. return;
  2552. }
  2553. let offsetY = element.offsetTop + element.clientTop;
  2554. let offsetX = element.offsetLeft + element.clientLeft;
  2555. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  2556. offsetY += parent.offsetTop;
  2557. offsetX += parent.offsetLeft;
  2558. parent = parent.offsetParent;
  2559. if (!parent) {
  2560. return;
  2561. }
  2562. }
  2563. if (spot) {
  2564. if (spot.top !== undefined) {
  2565. offsetY += spot.top;
  2566. }
  2567. if (spot.left !== undefined) {
  2568. offsetX += spot.left;
  2569. parent.scrollLeft = offsetX;
  2570. }
  2571. }
  2572. parent.scrollTop = offsetY;
  2573. }
  2574. function watchScroll(viewAreaElement, callback) {
  2575. const debounceScroll = function (evt) {
  2576. if (rAF) {
  2577. return;
  2578. }
  2579. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2580. rAF = null;
  2581. const currentX = viewAreaElement.scrollLeft;
  2582. const lastX = state.lastX;
  2583. if (currentX !== lastX) {
  2584. state.right = currentX > lastX;
  2585. }
  2586. state.lastX = currentX;
  2587. const currentY = viewAreaElement.scrollTop;
  2588. const lastY = state.lastY;
  2589. if (currentY !== lastY) {
  2590. state.down = currentY > lastY;
  2591. }
  2592. state.lastY = currentY;
  2593. callback(state);
  2594. });
  2595. };
  2596. const state = {
  2597. right: true,
  2598. down: true,
  2599. lastX: viewAreaElement.scrollLeft,
  2600. lastY: viewAreaElement.scrollTop,
  2601. _eventHandler: debounceScroll
  2602. };
  2603. let rAF = null;
  2604. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2605. return state;
  2606. }
  2607. function parseQueryString(query) {
  2608. const params = new Map();
  2609. for (const [key, value] of new URLSearchParams(query)) {
  2610. params.set(key.toLowerCase(), value);
  2611. }
  2612. return params;
  2613. }
  2614. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  2615. function removeNullCharacters(str, replaceInvisible = false) {
  2616. if (typeof str !== "string") {
  2617. console.error(`The argument must be a string.`);
  2618. return str;
  2619. }
  2620. if (replaceInvisible) {
  2621. str = str.replaceAll(InvisibleCharactersRegExp, " ");
  2622. }
  2623. return str.replaceAll("\x00", "");
  2624. }
  2625. function binarySearchFirstItem(items, condition, start = 0) {
  2626. let minIndex = start;
  2627. let maxIndex = items.length - 1;
  2628. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2629. return items.length;
  2630. }
  2631. if (condition(items[minIndex])) {
  2632. return minIndex;
  2633. }
  2634. while (minIndex < maxIndex) {
  2635. const currentIndex = minIndex + maxIndex >> 1;
  2636. const currentItem = items[currentIndex];
  2637. if (condition(currentItem)) {
  2638. maxIndex = currentIndex;
  2639. } else {
  2640. minIndex = currentIndex + 1;
  2641. }
  2642. }
  2643. return minIndex;
  2644. }
  2645. function approximateFraction(x) {
  2646. if (Math.floor(x) === x) {
  2647. return [x, 1];
  2648. }
  2649. const xinv = 1 / x;
  2650. const limit = 8;
  2651. if (xinv > limit) {
  2652. return [1, limit];
  2653. } else if (Math.floor(xinv) === xinv) {
  2654. return [1, xinv];
  2655. }
  2656. const x_ = x > 1 ? xinv : x;
  2657. let a = 0,
  2658. b = 1,
  2659. c = 1,
  2660. d = 1;
  2661. while (true) {
  2662. const p = a + c,
  2663. q = b + d;
  2664. if (q > limit) {
  2665. break;
  2666. }
  2667. if (x_ <= p / q) {
  2668. c = p;
  2669. d = q;
  2670. } else {
  2671. a = p;
  2672. b = q;
  2673. }
  2674. }
  2675. let result;
  2676. if (x_ - a / b < c / d - x_) {
  2677. result = x_ === x ? [a, b] : [b, a];
  2678. } else {
  2679. result = x_ === x ? [c, d] : [d, c];
  2680. }
  2681. return result;
  2682. }
  2683. function roundToDivide(x, div) {
  2684. const r = x % div;
  2685. return r === 0 ? x : Math.round(x - r + div);
  2686. }
  2687. function getPageSizeInches({
  2688. view,
  2689. userUnit,
  2690. rotate
  2691. }) {
  2692. const [x1, y1, x2, y2] = view;
  2693. const changeOrientation = rotate % 180 !== 0;
  2694. const width = (x2 - x1) / 72 * userUnit;
  2695. const height = (y2 - y1) / 72 * userUnit;
  2696. return {
  2697. width: changeOrientation ? height : width,
  2698. height: changeOrientation ? width : height
  2699. };
  2700. }
  2701. function backtrackBeforeAllVisibleElements(index, views, top) {
  2702. if (index < 2) {
  2703. return index;
  2704. }
  2705. let elt = views[index].div;
  2706. let pageTop = elt.offsetTop + elt.clientTop;
  2707. if (pageTop >= top) {
  2708. elt = views[index - 1].div;
  2709. pageTop = elt.offsetTop + elt.clientTop;
  2710. }
  2711. for (let i = index - 2; i >= 0; --i) {
  2712. elt = views[i].div;
  2713. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2714. break;
  2715. }
  2716. index = i;
  2717. }
  2718. return index;
  2719. }
  2720. function getVisibleElements({
  2721. scrollEl,
  2722. views,
  2723. sortByVisibility = false,
  2724. horizontal = false,
  2725. rtl = false
  2726. }) {
  2727. const top = scrollEl.scrollTop,
  2728. bottom = top + scrollEl.clientHeight;
  2729. const left = scrollEl.scrollLeft,
  2730. right = left + scrollEl.clientWidth;
  2731. function isElementBottomAfterViewTop(view) {
  2732. const element = view.div;
  2733. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2734. return elementBottom > top;
  2735. }
  2736. function isElementNextAfterViewHorizontally(view) {
  2737. const element = view.div;
  2738. const elementLeft = element.offsetLeft + element.clientLeft;
  2739. const elementRight = elementLeft + element.clientWidth;
  2740. return rtl ? elementLeft < right : elementRight > left;
  2741. }
  2742. const visible = [],
  2743. ids = new Set(),
  2744. numViews = views.length;
  2745. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2746. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2747. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2748. }
  2749. let lastEdge = horizontal ? right : -1;
  2750. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2751. const view = views[i],
  2752. element = view.div;
  2753. const currentWidth = element.offsetLeft + element.clientLeft;
  2754. const currentHeight = element.offsetTop + element.clientTop;
  2755. const viewWidth = element.clientWidth,
  2756. viewHeight = element.clientHeight;
  2757. const viewRight = currentWidth + viewWidth;
  2758. const viewBottom = currentHeight + viewHeight;
  2759. if (lastEdge === -1) {
  2760. if (viewBottom >= bottom) {
  2761. lastEdge = viewBottom;
  2762. }
  2763. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2764. break;
  2765. }
  2766. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2767. continue;
  2768. }
  2769. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2770. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2771. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2772. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2773. const percent = fractionHeight * fractionWidth * 100 | 0;
  2774. visible.push({
  2775. id: view.id,
  2776. x: currentWidth,
  2777. y: currentHeight,
  2778. view,
  2779. percent,
  2780. widthPercent: fractionWidth * 100 | 0
  2781. });
  2782. ids.add(view.id);
  2783. }
  2784. const first = visible[0],
  2785. last = visible.at(-1);
  2786. if (sortByVisibility) {
  2787. visible.sort(function (a, b) {
  2788. const pc = a.percent - b.percent;
  2789. if (Math.abs(pc) > 0.001) {
  2790. return -pc;
  2791. }
  2792. return a.id - b.id;
  2793. });
  2794. }
  2795. return {
  2796. first,
  2797. last,
  2798. views: visible,
  2799. ids
  2800. };
  2801. }
  2802. function noContextMenuHandler(evt) {
  2803. evt.preventDefault();
  2804. }
  2805. function normalizeWheelEventDirection(evt) {
  2806. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2807. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2808. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2809. delta = -delta;
  2810. }
  2811. return delta;
  2812. }
  2813. function normalizeWheelEventDelta(evt) {
  2814. const deltaMode = evt.deltaMode;
  2815. let delta = normalizeWheelEventDirection(evt);
  2816. const MOUSE_PIXELS_PER_LINE = 30;
  2817. const MOUSE_LINES_PER_PAGE = 30;
  2818. if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
  2819. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2820. } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
  2821. delta /= MOUSE_LINES_PER_PAGE;
  2822. }
  2823. return delta;
  2824. }
  2825. function isValidRotation(angle) {
  2826. return Number.isInteger(angle) && angle % 90 === 0;
  2827. }
  2828. function isValidScrollMode(mode) {
  2829. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2830. }
  2831. function isValidSpreadMode(mode) {
  2832. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2833. }
  2834. function isPortraitOrientation(size) {
  2835. return size.width <= size.height;
  2836. }
  2837. const animationStarted = new Promise(function (resolve) {
  2838. window.requestAnimationFrame(resolve);
  2839. });
  2840. exports.animationStarted = animationStarted;
  2841. const docStyle = document.documentElement.style;
  2842. exports.docStyle = docStyle;
  2843. function clamp(v, min, max) {
  2844. return Math.min(Math.max(v, min), max);
  2845. }
  2846. class ProgressBar {
  2847. #classList = null;
  2848. #disableAutoFetchTimeout = null;
  2849. #percent = 0;
  2850. #style = null;
  2851. #visible = true;
  2852. constructor(bar) {
  2853. this.#classList = bar.classList;
  2854. this.#style = bar.style;
  2855. }
  2856. get percent() {
  2857. return this.#percent;
  2858. }
  2859. set percent(val) {
  2860. this.#percent = clamp(val, 0, 100);
  2861. if (isNaN(val)) {
  2862. this.#classList.add("indeterminate");
  2863. return;
  2864. }
  2865. this.#classList.remove("indeterminate");
  2866. this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
  2867. }
  2868. setWidth(viewer) {
  2869. if (!viewer) {
  2870. return;
  2871. }
  2872. const container = viewer.parentNode;
  2873. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  2874. if (scrollbarWidth > 0) {
  2875. this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  2876. }
  2877. }
  2878. setDisableAutoFetch(delay = 5000) {
  2879. if (isNaN(this.#percent)) {
  2880. return;
  2881. }
  2882. if (this.#disableAutoFetchTimeout) {
  2883. clearTimeout(this.#disableAutoFetchTimeout);
  2884. }
  2885. this.show();
  2886. this.#disableAutoFetchTimeout = setTimeout(() => {
  2887. this.#disableAutoFetchTimeout = null;
  2888. this.hide();
  2889. }, delay);
  2890. }
  2891. hide() {
  2892. if (!this.#visible) {
  2893. return;
  2894. }
  2895. this.#visible = false;
  2896. this.#classList.add("hidden");
  2897. }
  2898. show() {
  2899. if (this.#visible) {
  2900. return;
  2901. }
  2902. this.#visible = true;
  2903. this.#classList.remove("hidden");
  2904. }
  2905. }
  2906. exports.ProgressBar = ProgressBar;
  2907. function getActiveOrFocusedElement() {
  2908. let curRoot = document;
  2909. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2910. while (curActiveOrFocused?.shadowRoot) {
  2911. curRoot = curActiveOrFocused.shadowRoot;
  2912. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  2913. }
  2914. return curActiveOrFocused;
  2915. }
  2916. function apiPageLayoutToViewerModes(layout) {
  2917. let scrollMode = ScrollMode.VERTICAL,
  2918. spreadMode = SpreadMode.NONE;
  2919. switch (layout) {
  2920. case "SinglePage":
  2921. scrollMode = ScrollMode.PAGE;
  2922. break;
  2923. case "OneColumn":
  2924. break;
  2925. case "TwoPageLeft":
  2926. scrollMode = ScrollMode.PAGE;
  2927. case "TwoColumnLeft":
  2928. spreadMode = SpreadMode.ODD;
  2929. break;
  2930. case "TwoPageRight":
  2931. scrollMode = ScrollMode.PAGE;
  2932. case "TwoColumnRight":
  2933. spreadMode = SpreadMode.EVEN;
  2934. break;
  2935. }
  2936. return {
  2937. scrollMode,
  2938. spreadMode
  2939. };
  2940. }
  2941. function apiPageModeToSidebarView(mode) {
  2942. switch (mode) {
  2943. case "UseNone":
  2944. return SidebarView.NONE;
  2945. case "UseThumbs":
  2946. return SidebarView.THUMBS;
  2947. case "UseOutlines":
  2948. return SidebarView.OUTLINE;
  2949. case "UseAttachments":
  2950. return SidebarView.ATTACHMENTS;
  2951. case "UseOC":
  2952. return SidebarView.LAYERS;
  2953. }
  2954. return SidebarView.NONE;
  2955. }
  2956. function toggleCheckedBtn(button, toggle, view = null) {
  2957. button.classList.toggle("toggled", toggle);
  2958. button.setAttribute("aria-checked", toggle);
  2959. view?.classList.toggle("hidden", !toggle);
  2960. }
  2961. function toggleExpandedBtn(button, toggle, view = null) {
  2962. button.classList.toggle("toggled", toggle);
  2963. button.setAttribute("aria-expanded", toggle);
  2964. view?.classList.toggle("hidden", !toggle);
  2965. }
  2966. /***/ }),
  2967. /* 4 */
  2968. /***/ ((module) => {
  2969. let pdfjsLib;
  2970. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  2971. pdfjsLib = window["pdfjs-dist/build/pdf"];
  2972. } else {
  2973. pdfjsLib = require("../build/pdf.js");
  2974. }
  2975. module.exports = pdfjsLib;
  2976. /***/ }),
  2977. /* 5 */
  2978. /***/ ((__unused_webpack_module, exports) => {
  2979. Object.defineProperty(exports, "__esModule", ({
  2980. value: true
  2981. }));
  2982. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  2983. const compatibilityParams = Object.create(null);
  2984. exports.compatibilityParams = compatibilityParams;
  2985. {
  2986. const userAgent = navigator.userAgent || "";
  2987. const platform = navigator.platform || "";
  2988. const maxTouchPoints = navigator.maxTouchPoints || 1;
  2989. const isAndroid = /Android/.test(userAgent);
  2990. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  2991. (function checkCanvasSizeLimitation() {
  2992. if (isIOS || isAndroid) {
  2993. compatibilityParams.maxCanvasPixels = 5242880;
  2994. }
  2995. })();
  2996. }
  2997. const OptionKind = {
  2998. VIEWER: 0x02,
  2999. API: 0x04,
  3000. WORKER: 0x08,
  3001. PREFERENCE: 0x80
  3002. };
  3003. exports.OptionKind = OptionKind;
  3004. const defaultOptions = {
  3005. annotationEditorMode: {
  3006. value: 0,
  3007. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3008. },
  3009. annotationMode: {
  3010. value: 2,
  3011. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3012. },
  3013. cursorToolOnLoad: {
  3014. value: 0,
  3015. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3016. },
  3017. defaultZoomDelay: {
  3018. value: 400,
  3019. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3020. },
  3021. defaultZoomValue: {
  3022. value: "",
  3023. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3024. },
  3025. disableHistory: {
  3026. value: false,
  3027. kind: OptionKind.VIEWER
  3028. },
  3029. disablePageLabels: {
  3030. value: false,
  3031. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3032. },
  3033. enableFloatingToolbar: {
  3034. value: false,
  3035. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3036. },
  3037. enablePermissions: {
  3038. value: false,
  3039. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3040. },
  3041. enablePrintAutoRotate: {
  3042. value: true,
  3043. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3044. },
  3045. enableScripting: {
  3046. value: true,
  3047. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3048. },
  3049. externalLinkRel: {
  3050. value: "noopener noreferrer nofollow",
  3051. kind: OptionKind.VIEWER
  3052. },
  3053. externalLinkTarget: {
  3054. value: 0,
  3055. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3056. },
  3057. historyUpdateUrl: {
  3058. value: false,
  3059. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3060. },
  3061. ignoreDestinationZoom: {
  3062. value: false,
  3063. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3064. },
  3065. imageResourcesPath: {
  3066. value: "./images/",
  3067. kind: OptionKind.VIEWER
  3068. },
  3069. maxCanvasPixels: {
  3070. value: 16777216,
  3071. kind: OptionKind.VIEWER
  3072. },
  3073. forcePageColors: {
  3074. value: false,
  3075. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3076. },
  3077. pageColorsBackground: {
  3078. value: "Canvas",
  3079. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3080. },
  3081. pageColorsForeground: {
  3082. value: "CanvasText",
  3083. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3084. },
  3085. pdfBugEnabled: {
  3086. value: false,
  3087. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3088. },
  3089. printResolution: {
  3090. value: 150,
  3091. kind: OptionKind.VIEWER
  3092. },
  3093. sidebarViewOnLoad: {
  3094. value: -1,
  3095. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3096. },
  3097. scrollModeOnLoad: {
  3098. value: -1,
  3099. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3100. },
  3101. spreadModeOnLoad: {
  3102. value: -1,
  3103. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3104. },
  3105. textLayerMode: {
  3106. value: 1,
  3107. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3108. },
  3109. useOnlyCssZoom: {
  3110. value: false,
  3111. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3112. },
  3113. viewerCssTheme: {
  3114. value: 0,
  3115. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3116. },
  3117. viewOnLoad: {
  3118. value: 0,
  3119. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  3120. },
  3121. cMapPacked: {
  3122. value: true,
  3123. kind: OptionKind.API
  3124. },
  3125. cMapUrl: {
  3126. value: "../web/cmaps/",
  3127. kind: OptionKind.API
  3128. },
  3129. disableAutoFetch: {
  3130. value: false,
  3131. kind: OptionKind.API + OptionKind.PREFERENCE
  3132. },
  3133. disableFontFace: {
  3134. value: false,
  3135. kind: OptionKind.API + OptionKind.PREFERENCE
  3136. },
  3137. disableRange: {
  3138. value: false,
  3139. kind: OptionKind.API + OptionKind.PREFERENCE
  3140. },
  3141. disableStream: {
  3142. value: false,
  3143. kind: OptionKind.API + OptionKind.PREFERENCE
  3144. },
  3145. docBaseUrl: {
  3146. value: "",
  3147. kind: OptionKind.API
  3148. },
  3149. enableXfa: {
  3150. value: true,
  3151. kind: OptionKind.API + OptionKind.PREFERENCE
  3152. },
  3153. fontExtraProperties: {
  3154. value: false,
  3155. kind: OptionKind.API
  3156. },
  3157. isEvalSupported: {
  3158. value: true,
  3159. kind: OptionKind.API
  3160. },
  3161. isOffscreenCanvasSupported: {
  3162. value: true,
  3163. kind: OptionKind.API
  3164. },
  3165. maxImageSize: {
  3166. value: -1,
  3167. kind: OptionKind.API
  3168. },
  3169. pdfBug: {
  3170. value: false,
  3171. kind: OptionKind.API
  3172. },
  3173. standardFontDataUrl: {
  3174. value: "../web/standard_fonts/",
  3175. kind: OptionKind.API
  3176. },
  3177. verbosity: {
  3178. value: 1,
  3179. kind: OptionKind.API
  3180. },
  3181. workerPort: {
  3182. value: null,
  3183. kind: OptionKind.WORKER
  3184. },
  3185. workerSrc: {
  3186. value: "../build/pdf.worker.js",
  3187. kind: OptionKind.WORKER
  3188. }
  3189. };
  3190. {
  3191. defaultOptions.defaultUrl = {
  3192. value: "compressed.tracemonkey-pldi-09.pdf",
  3193. kind: OptionKind.VIEWER
  3194. };
  3195. defaultOptions.disablePreferences = {
  3196. value: false,
  3197. kind: OptionKind.VIEWER
  3198. };
  3199. defaultOptions.locale = {
  3200. value: navigator.language || "en-US",
  3201. kind: OptionKind.VIEWER
  3202. };
  3203. defaultOptions.sandboxBundleSrc = {
  3204. value: "../build/pdf.sandbox.js",
  3205. kind: OptionKind.VIEWER
  3206. };
  3207. }
  3208. const userOptions = Object.create(null);
  3209. class AppOptions {
  3210. constructor() {
  3211. throw new Error("Cannot initialize AppOptions.");
  3212. }
  3213. static get(name) {
  3214. const userOption = userOptions[name];
  3215. if (userOption !== undefined) {
  3216. return userOption;
  3217. }
  3218. const defaultOption = defaultOptions[name];
  3219. if (defaultOption !== undefined) {
  3220. return compatibilityParams[name] ?? defaultOption.value;
  3221. }
  3222. return undefined;
  3223. }
  3224. static getAll(kind = null) {
  3225. const options = Object.create(null);
  3226. for (const name in defaultOptions) {
  3227. const defaultOption = defaultOptions[name];
  3228. if (kind) {
  3229. if ((kind & defaultOption.kind) === 0) {
  3230. continue;
  3231. }
  3232. if (kind === OptionKind.PREFERENCE) {
  3233. const value = defaultOption.value,
  3234. valueType = typeof value;
  3235. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  3236. options[name] = value;
  3237. continue;
  3238. }
  3239. throw new Error(`Invalid type for preference: ${name}`);
  3240. }
  3241. }
  3242. const userOption = userOptions[name];
  3243. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  3244. }
  3245. return options;
  3246. }
  3247. static set(name, value) {
  3248. userOptions[name] = value;
  3249. }
  3250. static setAll(options) {
  3251. for (const name in options) {
  3252. userOptions[name] = options[name];
  3253. }
  3254. }
  3255. static remove(name) {
  3256. delete userOptions[name];
  3257. }
  3258. }
  3259. exports.AppOptions = AppOptions;
  3260. {
  3261. AppOptions._hasUserOptions = function () {
  3262. return Object.keys(userOptions).length > 0;
  3263. };
  3264. }
  3265. /***/ }),
  3266. /* 6 */
  3267. /***/ ((__unused_webpack_module, exports) => {
  3268. Object.defineProperty(exports, "__esModule", ({
  3269. value: true
  3270. }));
  3271. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3272. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3273. const WaitOnType = {
  3274. EVENT: "event",
  3275. TIMEOUT: "timeout"
  3276. };
  3277. exports.WaitOnType = WaitOnType;
  3278. function waitOnEventOrTimeout({
  3279. target,
  3280. name,
  3281. delay = 0
  3282. }) {
  3283. return new Promise(function (resolve, reject) {
  3284. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3285. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3286. }
  3287. function handler(type) {
  3288. if (target instanceof EventBus) {
  3289. target._off(name, eventHandler);
  3290. } else {
  3291. target.removeEventListener(name, eventHandler);
  3292. }
  3293. if (timeout) {
  3294. clearTimeout(timeout);
  3295. }
  3296. resolve(type);
  3297. }
  3298. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3299. if (target instanceof EventBus) {
  3300. target._on(name, eventHandler);
  3301. } else {
  3302. target.addEventListener(name, eventHandler);
  3303. }
  3304. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3305. const timeout = setTimeout(timeoutHandler, delay);
  3306. });
  3307. }
  3308. class EventBus {
  3309. #listeners = Object.create(null);
  3310. on(eventName, listener, options = null) {
  3311. this._on(eventName, listener, {
  3312. external: true,
  3313. once: options?.once
  3314. });
  3315. }
  3316. off(eventName, listener, options = null) {
  3317. this._off(eventName, listener, {
  3318. external: true,
  3319. once: options?.once
  3320. });
  3321. }
  3322. dispatch(eventName, data) {
  3323. const eventListeners = this.#listeners[eventName];
  3324. if (!eventListeners || eventListeners.length === 0) {
  3325. return;
  3326. }
  3327. let externalListeners;
  3328. for (const {
  3329. listener,
  3330. external,
  3331. once
  3332. } of eventListeners.slice(0)) {
  3333. if (once) {
  3334. this._off(eventName, listener);
  3335. }
  3336. if (external) {
  3337. (externalListeners ||= []).push(listener);
  3338. continue;
  3339. }
  3340. listener(data);
  3341. }
  3342. if (externalListeners) {
  3343. for (const listener of externalListeners) {
  3344. listener(data);
  3345. }
  3346. externalListeners = null;
  3347. }
  3348. }
  3349. _on(eventName, listener, options = null) {
  3350. const eventListeners = this.#listeners[eventName] ||= [];
  3351. eventListeners.push({
  3352. listener,
  3353. external: options?.external === true,
  3354. once: options?.once === true
  3355. });
  3356. }
  3357. _off(eventName, listener, options = null) {
  3358. const eventListeners = this.#listeners[eventName];
  3359. if (!eventListeners) {
  3360. return;
  3361. }
  3362. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3363. if (eventListeners[i].listener === listener) {
  3364. eventListeners.splice(i, 1);
  3365. return;
  3366. }
  3367. }
  3368. }
  3369. }
  3370. exports.EventBus = EventBus;
  3371. class AutomationEventBus extends EventBus {
  3372. dispatch(eventName, data) {
  3373. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3374. }
  3375. }
  3376. exports.AutomationEventBus = AutomationEventBus;
  3377. /***/ }),
  3378. /* 7 */
  3379. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3380. Object.defineProperty(exports, "__esModule", ({
  3381. value: true
  3382. }));
  3383. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  3384. var _ui_utils = __webpack_require__(3);
  3385. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  3386. const LinkTarget = {
  3387. NONE: 0,
  3388. SELF: 1,
  3389. BLANK: 2,
  3390. PARENT: 3,
  3391. TOP: 4
  3392. };
  3393. exports.LinkTarget = LinkTarget;
  3394. function addLinkAttributes(link, {
  3395. url,
  3396. target,
  3397. rel,
  3398. enabled = true
  3399. } = {}) {
  3400. if (!url || typeof url !== "string") {
  3401. throw new Error('A valid "url" parameter must provided.');
  3402. }
  3403. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  3404. if (enabled) {
  3405. link.href = link.title = urlNullRemoved;
  3406. } else {
  3407. link.href = "";
  3408. link.title = `Disabled: ${urlNullRemoved}`;
  3409. link.onclick = () => {
  3410. return false;
  3411. };
  3412. }
  3413. let targetStr = "";
  3414. switch (target) {
  3415. case LinkTarget.NONE:
  3416. break;
  3417. case LinkTarget.SELF:
  3418. targetStr = "_self";
  3419. break;
  3420. case LinkTarget.BLANK:
  3421. targetStr = "_blank";
  3422. break;
  3423. case LinkTarget.PARENT:
  3424. targetStr = "_parent";
  3425. break;
  3426. case LinkTarget.TOP:
  3427. targetStr = "_top";
  3428. break;
  3429. }
  3430. link.target = targetStr;
  3431. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  3432. }
  3433. class PDFLinkService {
  3434. #pagesRefCache = new Map();
  3435. constructor({
  3436. eventBus,
  3437. externalLinkTarget = null,
  3438. externalLinkRel = null,
  3439. ignoreDestinationZoom = false
  3440. } = {}) {
  3441. this.eventBus = eventBus;
  3442. this.externalLinkTarget = externalLinkTarget;
  3443. this.externalLinkRel = externalLinkRel;
  3444. this.externalLinkEnabled = true;
  3445. this._ignoreDestinationZoom = ignoreDestinationZoom;
  3446. this.baseUrl = null;
  3447. this.pdfDocument = null;
  3448. this.pdfViewer = null;
  3449. this.pdfHistory = null;
  3450. }
  3451. setDocument(pdfDocument, baseUrl = null) {
  3452. this.baseUrl = baseUrl;
  3453. this.pdfDocument = pdfDocument;
  3454. this.#pagesRefCache.clear();
  3455. }
  3456. setViewer(pdfViewer) {
  3457. this.pdfViewer = pdfViewer;
  3458. }
  3459. setHistory(pdfHistory) {
  3460. this.pdfHistory = pdfHistory;
  3461. }
  3462. get pagesCount() {
  3463. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  3464. }
  3465. get page() {
  3466. return this.pdfViewer.currentPageNumber;
  3467. }
  3468. set page(value) {
  3469. this.pdfViewer.currentPageNumber = value;
  3470. }
  3471. get rotation() {
  3472. return this.pdfViewer.pagesRotation;
  3473. }
  3474. set rotation(value) {
  3475. this.pdfViewer.pagesRotation = value;
  3476. }
  3477. get isInPresentationMode() {
  3478. return this.pdfViewer.isInPresentationMode;
  3479. }
  3480. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  3481. const destRef = explicitDest[0];
  3482. let pageNumber;
  3483. if (typeof destRef === "object" && destRef !== null) {
  3484. pageNumber = this._cachedPageNumber(destRef);
  3485. if (!pageNumber) {
  3486. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  3487. this.cachePageRef(pageIndex + 1, destRef);
  3488. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  3489. }).catch(() => {
  3490. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  3491. });
  3492. return;
  3493. }
  3494. } else if (Number.isInteger(destRef)) {
  3495. pageNumber = destRef + 1;
  3496. } else {
  3497. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  3498. return;
  3499. }
  3500. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  3501. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  3502. return;
  3503. }
  3504. if (this.pdfHistory) {
  3505. this.pdfHistory.pushCurrentPosition();
  3506. this.pdfHistory.push({
  3507. namedDest,
  3508. explicitDest,
  3509. pageNumber
  3510. });
  3511. }
  3512. this.pdfViewer.scrollPageIntoView({
  3513. pageNumber,
  3514. destArray: explicitDest,
  3515. ignoreDestinationZoom: this._ignoreDestinationZoom
  3516. });
  3517. }
  3518. async goToDestination(dest) {
  3519. if (!this.pdfDocument) {
  3520. return;
  3521. }
  3522. let namedDest, explicitDest;
  3523. if (typeof dest === "string") {
  3524. namedDest = dest;
  3525. explicitDest = await this.pdfDocument.getDestination(dest);
  3526. } else {
  3527. namedDest = null;
  3528. explicitDest = await dest;
  3529. }
  3530. if (!Array.isArray(explicitDest)) {
  3531. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  3532. return;
  3533. }
  3534. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  3535. }
  3536. goToPage(val) {
  3537. if (!this.pdfDocument) {
  3538. return;
  3539. }
  3540. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  3541. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  3542. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  3543. return;
  3544. }
  3545. if (this.pdfHistory) {
  3546. this.pdfHistory.pushCurrentPosition();
  3547. this.pdfHistory.pushPage(pageNumber);
  3548. }
  3549. this.pdfViewer.scrollPageIntoView({
  3550. pageNumber
  3551. });
  3552. }
  3553. addLinkAttributes(link, url, newWindow = false) {
  3554. addLinkAttributes(link, {
  3555. url,
  3556. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  3557. rel: this.externalLinkRel,
  3558. enabled: this.externalLinkEnabled
  3559. });
  3560. }
  3561. getDestinationHash(dest) {
  3562. if (typeof dest === "string") {
  3563. if (dest.length > 0) {
  3564. return this.getAnchorUrl("#" + escape(dest));
  3565. }
  3566. } else if (Array.isArray(dest)) {
  3567. const str = JSON.stringify(dest);
  3568. if (str.length > 0) {
  3569. return this.getAnchorUrl("#" + escape(str));
  3570. }
  3571. }
  3572. return this.getAnchorUrl("");
  3573. }
  3574. getAnchorUrl(anchor) {
  3575. return this.baseUrl ? this.baseUrl + anchor : anchor;
  3576. }
  3577. setHash(hash) {
  3578. if (!this.pdfDocument) {
  3579. return;
  3580. }
  3581. let pageNumber, dest;
  3582. if (hash.includes("=")) {
  3583. const params = (0, _ui_utils.parseQueryString)(hash);
  3584. if (params.has("search")) {
  3585. const query = params.get("search").replaceAll('"', ""),
  3586. phrase = params.get("phrase") === "true";
  3587. this.eventBus.dispatch("findfromurlhash", {
  3588. source: this,
  3589. query: phrase ? query : query.match(/\S+/g)
  3590. });
  3591. }
  3592. if (params.has("page")) {
  3593. pageNumber = params.get("page") | 0 || 1;
  3594. }
  3595. if (params.has("zoom")) {
  3596. const zoomArgs = params.get("zoom").split(",");
  3597. const zoomArg = zoomArgs[0];
  3598. const zoomArgNumber = parseFloat(zoomArg);
  3599. if (!zoomArg.includes("Fit")) {
  3600. dest = [null, {
  3601. name: "XYZ"
  3602. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  3603. } else {
  3604. if (zoomArg === "Fit" || zoomArg === "FitB") {
  3605. dest = [null, {
  3606. name: zoomArg
  3607. }];
  3608. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  3609. dest = [null, {
  3610. name: zoomArg
  3611. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  3612. } else if (zoomArg === "FitR") {
  3613. if (zoomArgs.length !== 5) {
  3614. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  3615. } else {
  3616. dest = [null, {
  3617. name: zoomArg
  3618. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  3619. }
  3620. } else {
  3621. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  3622. }
  3623. }
  3624. }
  3625. if (dest) {
  3626. this.pdfViewer.scrollPageIntoView({
  3627. pageNumber: pageNumber || this.page,
  3628. destArray: dest,
  3629. allowNegativeOffset: true
  3630. });
  3631. } else if (pageNumber) {
  3632. this.page = pageNumber;
  3633. }
  3634. if (params.has("pagemode")) {
  3635. this.eventBus.dispatch("pagemode", {
  3636. source: this,
  3637. mode: params.get("pagemode")
  3638. });
  3639. }
  3640. if (params.has("nameddest")) {
  3641. this.goToDestination(params.get("nameddest"));
  3642. }
  3643. } else {
  3644. dest = unescape(hash);
  3645. try {
  3646. dest = JSON.parse(dest);
  3647. if (!Array.isArray(dest)) {
  3648. dest = dest.toString();
  3649. }
  3650. } catch (ex) {}
  3651. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  3652. this.goToDestination(dest);
  3653. return;
  3654. }
  3655. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  3656. }
  3657. }
  3658. executeNamedAction(action) {
  3659. switch (action) {
  3660. case "GoBack":
  3661. this.pdfHistory?.back();
  3662. break;
  3663. case "GoForward":
  3664. this.pdfHistory?.forward();
  3665. break;
  3666. case "NextPage":
  3667. this.pdfViewer.nextPage();
  3668. break;
  3669. case "PrevPage":
  3670. this.pdfViewer.previousPage();
  3671. break;
  3672. case "LastPage":
  3673. this.page = this.pagesCount;
  3674. break;
  3675. case "FirstPage":
  3676. this.page = 1;
  3677. break;
  3678. default:
  3679. break;
  3680. }
  3681. this.eventBus.dispatch("namedaction", {
  3682. source: this,
  3683. action
  3684. });
  3685. }
  3686. async executeSetOCGState(action) {
  3687. const pdfDocument = this.pdfDocument;
  3688. const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  3689. if (pdfDocument !== this.pdfDocument) {
  3690. return;
  3691. }
  3692. let operator;
  3693. for (const elem of action.state) {
  3694. switch (elem) {
  3695. case "ON":
  3696. case "OFF":
  3697. case "Toggle":
  3698. operator = elem;
  3699. continue;
  3700. }
  3701. switch (operator) {
  3702. case "ON":
  3703. optionalContentConfig.setVisibility(elem, true);
  3704. break;
  3705. case "OFF":
  3706. optionalContentConfig.setVisibility(elem, false);
  3707. break;
  3708. case "Toggle":
  3709. const group = optionalContentConfig.getGroup(elem);
  3710. if (group) {
  3711. optionalContentConfig.setVisibility(elem, !group.visible);
  3712. }
  3713. break;
  3714. }
  3715. }
  3716. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  3717. }
  3718. cachePageRef(pageNum, pageRef) {
  3719. if (!pageRef) {
  3720. return;
  3721. }
  3722. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3723. this.#pagesRefCache.set(refStr, pageNum);
  3724. }
  3725. _cachedPageNumber(pageRef) {
  3726. if (!pageRef) {
  3727. return null;
  3728. }
  3729. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  3730. return this.#pagesRefCache.get(refStr) || null;
  3731. }
  3732. static #isValidExplicitDestination(dest) {
  3733. if (!Array.isArray(dest)) {
  3734. return false;
  3735. }
  3736. const destLength = dest.length;
  3737. if (destLength < 2) {
  3738. return false;
  3739. }
  3740. const page = dest[0];
  3741. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  3742. return false;
  3743. }
  3744. const zoom = dest[1];
  3745. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  3746. return false;
  3747. }
  3748. let allowNull = true;
  3749. switch (zoom.name) {
  3750. case "XYZ":
  3751. if (destLength !== 5) {
  3752. return false;
  3753. }
  3754. break;
  3755. case "Fit":
  3756. case "FitB":
  3757. return destLength === 2;
  3758. case "FitH":
  3759. case "FitBH":
  3760. case "FitV":
  3761. case "FitBV":
  3762. if (destLength !== 3) {
  3763. return false;
  3764. }
  3765. break;
  3766. case "FitR":
  3767. if (destLength !== 6) {
  3768. return false;
  3769. }
  3770. allowNull = false;
  3771. break;
  3772. default:
  3773. return false;
  3774. }
  3775. for (let i = 2; i < destLength; i++) {
  3776. const param = dest[i];
  3777. if (!(typeof param === "number" || allowNull && param === null)) {
  3778. return false;
  3779. }
  3780. }
  3781. return true;
  3782. }
  3783. }
  3784. exports.PDFLinkService = PDFLinkService;
  3785. class SimpleLinkService {
  3786. constructor() {
  3787. this.externalLinkEnabled = true;
  3788. }
  3789. get pagesCount() {
  3790. return 0;
  3791. }
  3792. get page() {
  3793. return 0;
  3794. }
  3795. set page(value) {}
  3796. get rotation() {
  3797. return 0;
  3798. }
  3799. set rotation(value) {}
  3800. get isInPresentationMode() {
  3801. return false;
  3802. }
  3803. async goToDestination(dest) {}
  3804. goToPage(val) {}
  3805. addLinkAttributes(link, url, newWindow = false) {
  3806. addLinkAttributes(link, {
  3807. url,
  3808. enabled: this.externalLinkEnabled
  3809. });
  3810. }
  3811. getDestinationHash(dest) {
  3812. return "#";
  3813. }
  3814. getAnchorUrl(hash) {
  3815. return "#";
  3816. }
  3817. setHash(hash) {}
  3818. executeNamedAction(action) {}
  3819. executeSetOCGState(action) {}
  3820. cachePageRef(pageNum, pageRef) {}
  3821. }
  3822. exports.SimpleLinkService = SimpleLinkService;
  3823. /***/ }),
  3824. /* 8 */
  3825. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3826. Object.defineProperty(exports, "__esModule", ({
  3827. value: true
  3828. }));
  3829. exports.AnnotationEditorParams = void 0;
  3830. var _pdfjsLib = __webpack_require__(4);
  3831. class AnnotationEditorParams {
  3832. constructor(options, eventBus) {
  3833. this.eventBus = eventBus;
  3834. this.#bindListeners(options);
  3835. }
  3836. #bindListeners({
  3837. editorFreeTextFontSize,
  3838. editorFreeTextColor,
  3839. editorInkColor,
  3840. editorInkThickness,
  3841. editorInkOpacity
  3842. }) {
  3843. const dispatchEvent = (typeStr, value) => {
  3844. this.eventBus.dispatch("switchannotationeditorparams", {
  3845. source: this,
  3846. type: _pdfjsLib.AnnotationEditorParamsType[typeStr],
  3847. value
  3848. });
  3849. };
  3850. editorFreeTextFontSize.addEventListener("input", function () {
  3851. dispatchEvent("FREETEXT_SIZE", this.valueAsNumber);
  3852. });
  3853. editorFreeTextColor.addEventListener("input", function () {
  3854. dispatchEvent("FREETEXT_COLOR", this.value);
  3855. });
  3856. editorInkColor.addEventListener("input", function () {
  3857. dispatchEvent("INK_COLOR", this.value);
  3858. });
  3859. editorInkThickness.addEventListener("input", function () {
  3860. dispatchEvent("INK_THICKNESS", this.valueAsNumber);
  3861. });
  3862. editorInkOpacity.addEventListener("input", function () {
  3863. dispatchEvent("INK_OPACITY", this.valueAsNumber);
  3864. });
  3865. this.eventBus._on("annotationeditorparamschanged", evt => {
  3866. for (const [type, value] of evt.details) {
  3867. switch (type) {
  3868. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  3869. editorFreeTextFontSize.value = value;
  3870. break;
  3871. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  3872. editorFreeTextColor.value = value;
  3873. break;
  3874. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  3875. editorInkColor.value = value;
  3876. break;
  3877. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  3878. editorInkThickness.value = value;
  3879. break;
  3880. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  3881. editorInkOpacity.value = value;
  3882. break;
  3883. }
  3884. }
  3885. });
  3886. }
  3887. }
  3888. exports.AnnotationEditorParams = AnnotationEditorParams;
  3889. /***/ }),
  3890. /* 9 */
  3891. /***/ ((__unused_webpack_module, exports) => {
  3892. Object.defineProperty(exports, "__esModule", ({
  3893. value: true
  3894. }));
  3895. exports.OverlayManager = void 0;
  3896. class OverlayManager {
  3897. #overlays = new WeakMap();
  3898. #active = null;
  3899. get active() {
  3900. return this.#active;
  3901. }
  3902. async register(dialog, canForceClose = false) {
  3903. if (typeof dialog !== "object") {
  3904. throw new Error("Not enough parameters.");
  3905. } else if (this.#overlays.has(dialog)) {
  3906. throw new Error("The overlay is already registered.");
  3907. }
  3908. this.#overlays.set(dialog, {
  3909. canForceClose
  3910. });
  3911. dialog.addEventListener("cancel", evt => {
  3912. this.#active = null;
  3913. });
  3914. }
  3915. async unregister(dialog) {
  3916. if (!this.#overlays.has(dialog)) {
  3917. throw new Error("The overlay does not exist.");
  3918. } else if (this.#active === dialog) {
  3919. throw new Error("The overlay cannot be removed while it is active.");
  3920. }
  3921. this.#overlays.delete(dialog);
  3922. }
  3923. async open(dialog) {
  3924. if (!this.#overlays.has(dialog)) {
  3925. throw new Error("The overlay does not exist.");
  3926. } else if (this.#active) {
  3927. if (this.#active === dialog) {
  3928. throw new Error("The overlay is already active.");
  3929. } else if (this.#overlays.get(dialog).canForceClose) {
  3930. await this.close();
  3931. } else {
  3932. throw new Error("Another overlay is currently active.");
  3933. }
  3934. }
  3935. this.#active = dialog;
  3936. dialog.showModal();
  3937. }
  3938. async close(dialog = this.#active) {
  3939. if (!this.#overlays.has(dialog)) {
  3940. throw new Error("The overlay does not exist.");
  3941. } else if (!this.#active) {
  3942. throw new Error("The overlay is currently not active.");
  3943. } else if (this.#active !== dialog) {
  3944. throw new Error("Another overlay is currently active.");
  3945. }
  3946. dialog.close();
  3947. this.#active = null;
  3948. }
  3949. }
  3950. exports.OverlayManager = OverlayManager;
  3951. /***/ }),
  3952. /* 10 */
  3953. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3954. Object.defineProperty(exports, "__esModule", ({
  3955. value: true
  3956. }));
  3957. exports.PasswordPrompt = void 0;
  3958. var _pdfjsLib = __webpack_require__(4);
  3959. class PasswordPrompt {
  3960. #activeCapability = null;
  3961. #updateCallback = null;
  3962. #reason = null;
  3963. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3964. this.dialog = options.dialog;
  3965. this.label = options.label;
  3966. this.input = options.input;
  3967. this.submitButton = options.submitButton;
  3968. this.cancelButton = options.cancelButton;
  3969. this.overlayManager = overlayManager;
  3970. this.l10n = l10n;
  3971. this._isViewerEmbedded = isViewerEmbedded;
  3972. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3973. this.cancelButton.addEventListener("click", this.close.bind(this));
  3974. this.input.addEventListener("keydown", e => {
  3975. if (e.keyCode === 13) {
  3976. this.#verify();
  3977. }
  3978. });
  3979. this.overlayManager.register(this.dialog, true);
  3980. this.dialog.addEventListener("close", this.#cancel.bind(this));
  3981. }
  3982. async open() {
  3983. if (this.#activeCapability) {
  3984. await this.#activeCapability.promise;
  3985. }
  3986. this.#activeCapability = new _pdfjsLib.PromiseCapability();
  3987. try {
  3988. await this.overlayManager.open(this.dialog);
  3989. } catch (ex) {
  3990. this.#activeCapability = null;
  3991. throw ex;
  3992. }
  3993. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3994. if (!this._isViewerEmbedded || passwordIncorrect) {
  3995. this.input.focus();
  3996. }
  3997. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3998. }
  3999. async close() {
  4000. if (this.overlayManager.active === this.dialog) {
  4001. this.overlayManager.close(this.dialog);
  4002. }
  4003. }
  4004. #verify() {
  4005. const password = this.input.value;
  4006. if (password?.length > 0) {
  4007. this.#invokeCallback(password);
  4008. }
  4009. }
  4010. #cancel() {
  4011. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  4012. this.#activeCapability.resolve();
  4013. }
  4014. #invokeCallback(password) {
  4015. if (!this.#updateCallback) {
  4016. return;
  4017. }
  4018. this.close();
  4019. this.input.value = "";
  4020. this.#updateCallback(password);
  4021. this.#updateCallback = null;
  4022. }
  4023. async setUpdateCallback(updateCallback, reason) {
  4024. if (this.#activeCapability) {
  4025. await this.#activeCapability.promise;
  4026. }
  4027. this.#updateCallback = updateCallback;
  4028. this.#reason = reason;
  4029. }
  4030. }
  4031. exports.PasswordPrompt = PasswordPrompt;
  4032. /***/ }),
  4033. /* 11 */
  4034. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4035. Object.defineProperty(exports, "__esModule", ({
  4036. value: true
  4037. }));
  4038. exports.PDFAttachmentViewer = void 0;
  4039. var _pdfjsLib = __webpack_require__(4);
  4040. var _base_tree_viewer = __webpack_require__(12);
  4041. var _event_utils = __webpack_require__(6);
  4042. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4043. constructor(options) {
  4044. super(options);
  4045. this.downloadManager = options.downloadManager;
  4046. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  4047. }
  4048. reset(keepRenderedCapability = false) {
  4049. super.reset();
  4050. this._attachments = null;
  4051. if (!keepRenderedCapability) {
  4052. this._renderedCapability = new _pdfjsLib.PromiseCapability();
  4053. }
  4054. this._pendingDispatchEvent = false;
  4055. }
  4056. async _dispatchEvent(attachmentsCount) {
  4057. this._renderedCapability.resolve();
  4058. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4059. this._pendingDispatchEvent = true;
  4060. await (0, _event_utils.waitOnEventOrTimeout)({
  4061. target: this.eventBus,
  4062. name: "annotationlayerrendered",
  4063. delay: 1000
  4064. });
  4065. if (!this._pendingDispatchEvent) {
  4066. return;
  4067. }
  4068. }
  4069. this._pendingDispatchEvent = false;
  4070. this.eventBus.dispatch("attachmentsloaded", {
  4071. source: this,
  4072. attachmentsCount
  4073. });
  4074. }
  4075. _bindLink(element, {
  4076. content,
  4077. filename
  4078. }) {
  4079. element.onclick = () => {
  4080. this.downloadManager.openOrDownloadData(element, content, filename);
  4081. return false;
  4082. };
  4083. }
  4084. render({
  4085. attachments,
  4086. keepRenderedCapability = false
  4087. }) {
  4088. if (this._attachments) {
  4089. this.reset(keepRenderedCapability);
  4090. }
  4091. this._attachments = attachments || null;
  4092. if (!attachments) {
  4093. this._dispatchEvent(0);
  4094. return;
  4095. }
  4096. const fragment = document.createDocumentFragment();
  4097. let attachmentsCount = 0;
  4098. for (const name in attachments) {
  4099. const item = attachments[name];
  4100. const content = item.content,
  4101. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true);
  4102. const div = document.createElement("div");
  4103. div.className = "treeItem";
  4104. const element = document.createElement("a");
  4105. this._bindLink(element, {
  4106. content,
  4107. filename
  4108. });
  4109. element.textContent = this._normalizeTextContent(filename);
  4110. div.append(element);
  4111. fragment.append(div);
  4112. attachmentsCount++;
  4113. }
  4114. this._finishRendering(fragment, attachmentsCount);
  4115. }
  4116. #appendAttachment({
  4117. filename,
  4118. content
  4119. }) {
  4120. const renderedPromise = this._renderedCapability.promise;
  4121. renderedPromise.then(() => {
  4122. if (renderedPromise !== this._renderedCapability.promise) {
  4123. return;
  4124. }
  4125. const attachments = this._attachments || Object.create(null);
  4126. for (const name in attachments) {
  4127. if (filename === name) {
  4128. return;
  4129. }
  4130. }
  4131. attachments[filename] = {
  4132. filename,
  4133. content
  4134. };
  4135. this.render({
  4136. attachments,
  4137. keepRenderedCapability: true
  4138. });
  4139. });
  4140. }
  4141. }
  4142. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4143. /***/ }),
  4144. /* 12 */
  4145. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4146. Object.defineProperty(exports, "__esModule", ({
  4147. value: true
  4148. }));
  4149. exports.BaseTreeViewer = void 0;
  4150. var _ui_utils = __webpack_require__(3);
  4151. const TREEITEM_OFFSET_TOP = -100;
  4152. const TREEITEM_SELECTED_CLASS = "selected";
  4153. class BaseTreeViewer {
  4154. constructor(options) {
  4155. if (this.constructor === BaseTreeViewer) {
  4156. throw new Error("Cannot initialize BaseTreeViewer.");
  4157. }
  4158. this.container = options.container;
  4159. this.eventBus = options.eventBus;
  4160. this.reset();
  4161. }
  4162. reset() {
  4163. this._pdfDocument = null;
  4164. this._lastToggleIsShow = true;
  4165. this._currentTreeItem = null;
  4166. this.container.textContent = "";
  4167. this.container.classList.remove("treeWithDeepNesting");
  4168. }
  4169. _dispatchEvent(count) {
  4170. throw new Error("Not implemented: _dispatchEvent");
  4171. }
  4172. _bindLink(element, params) {
  4173. throw new Error("Not implemented: _bindLink");
  4174. }
  4175. _normalizeTextContent(str) {
  4176. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4177. }
  4178. _addToggleButton(div, hidden = false) {
  4179. const toggler = document.createElement("div");
  4180. toggler.className = "treeItemToggler";
  4181. if (hidden) {
  4182. toggler.classList.add("treeItemsHidden");
  4183. }
  4184. toggler.onclick = evt => {
  4185. evt.stopPropagation();
  4186. toggler.classList.toggle("treeItemsHidden");
  4187. if (evt.shiftKey) {
  4188. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4189. this._toggleTreeItem(div, shouldShowAll);
  4190. }
  4191. };
  4192. div.prepend(toggler);
  4193. }
  4194. _toggleTreeItem(root, show = false) {
  4195. this._lastToggleIsShow = show;
  4196. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4197. toggler.classList.toggle("treeItemsHidden", !show);
  4198. }
  4199. }
  4200. _toggleAllTreeItems() {
  4201. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4202. }
  4203. _finishRendering(fragment, count, hasAnyNesting = false) {
  4204. if (hasAnyNesting) {
  4205. this.container.classList.add("treeWithDeepNesting");
  4206. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4207. }
  4208. this.container.append(fragment);
  4209. this._dispatchEvent(count);
  4210. }
  4211. render(params) {
  4212. throw new Error("Not implemented: render");
  4213. }
  4214. _updateCurrentTreeItem(treeItem = null) {
  4215. if (this._currentTreeItem) {
  4216. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4217. this._currentTreeItem = null;
  4218. }
  4219. if (treeItem) {
  4220. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4221. this._currentTreeItem = treeItem;
  4222. }
  4223. }
  4224. _scrollToCurrentTreeItem(treeItem) {
  4225. if (!treeItem) {
  4226. return;
  4227. }
  4228. let currentNode = treeItem.parentNode;
  4229. while (currentNode && currentNode !== this.container) {
  4230. if (currentNode.classList.contains("treeItem")) {
  4231. const toggler = currentNode.firstElementChild;
  4232. toggler?.classList.remove("treeItemsHidden");
  4233. }
  4234. currentNode = currentNode.parentNode;
  4235. }
  4236. this._updateCurrentTreeItem(treeItem);
  4237. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4238. }
  4239. }
  4240. exports.BaseTreeViewer = BaseTreeViewer;
  4241. /***/ }),
  4242. /* 13 */
  4243. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4244. Object.defineProperty(exports, "__esModule", ({
  4245. value: true
  4246. }));
  4247. exports.PDFCursorTools = void 0;
  4248. var _ui_utils = __webpack_require__(3);
  4249. var _pdfjsLib = __webpack_require__(4);
  4250. var _grab_to_pan = __webpack_require__(14);
  4251. class PDFCursorTools {
  4252. constructor({
  4253. container,
  4254. eventBus,
  4255. cursorToolOnLoad = _ui_utils.CursorTool.SELECT
  4256. }) {
  4257. this.container = container;
  4258. this.eventBus = eventBus;
  4259. this.active = _ui_utils.CursorTool.SELECT;
  4260. this.previouslyActive = null;
  4261. this.handTool = new _grab_to_pan.GrabToPan({
  4262. element: this.container
  4263. });
  4264. this.#addEventListeners();
  4265. Promise.resolve().then(() => {
  4266. this.switchTool(cursorToolOnLoad);
  4267. });
  4268. }
  4269. get activeTool() {
  4270. return this.active;
  4271. }
  4272. switchTool(tool) {
  4273. if (this.previouslyActive !== null) {
  4274. return;
  4275. }
  4276. if (tool === this.active) {
  4277. return;
  4278. }
  4279. const disableActiveTool = () => {
  4280. switch (this.active) {
  4281. case _ui_utils.CursorTool.SELECT:
  4282. break;
  4283. case _ui_utils.CursorTool.HAND:
  4284. this.handTool.deactivate();
  4285. break;
  4286. case _ui_utils.CursorTool.ZOOM:
  4287. }
  4288. };
  4289. switch (tool) {
  4290. case _ui_utils.CursorTool.SELECT:
  4291. disableActiveTool();
  4292. break;
  4293. case _ui_utils.CursorTool.HAND:
  4294. disableActiveTool();
  4295. this.handTool.activate();
  4296. break;
  4297. case _ui_utils.CursorTool.ZOOM:
  4298. default:
  4299. console.error(`switchTool: "${tool}" is an unsupported value.`);
  4300. return;
  4301. }
  4302. this.active = tool;
  4303. this.#dispatchEvent();
  4304. }
  4305. #dispatchEvent() {
  4306. this.eventBus.dispatch("cursortoolchanged", {
  4307. source: this,
  4308. tool: this.active
  4309. });
  4310. }
  4311. #addEventListeners() {
  4312. this.eventBus._on("switchcursortool", evt => {
  4313. this.switchTool(evt.tool);
  4314. });
  4315. let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
  4316. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  4317. const disableActive = () => {
  4318. const previouslyActive = this.active;
  4319. this.switchTool(_ui_utils.CursorTool.SELECT);
  4320. this.previouslyActive ??= previouslyActive;
  4321. };
  4322. const enableActive = () => {
  4323. const previouslyActive = this.previouslyActive;
  4324. if (previouslyActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) {
  4325. this.previouslyActive = null;
  4326. this.switchTool(previouslyActive);
  4327. }
  4328. };
  4329. this.eventBus._on("secondarytoolbarreset", evt => {
  4330. if (this.previouslyActive !== null) {
  4331. annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  4332. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  4333. enableActive();
  4334. }
  4335. });
  4336. this.eventBus._on("annotationeditormodechanged", ({
  4337. mode
  4338. }) => {
  4339. annotationEditorMode = mode;
  4340. if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
  4341. enableActive();
  4342. } else {
  4343. disableActive();
  4344. }
  4345. });
  4346. this.eventBus._on("presentationmodechanged", ({
  4347. state
  4348. }) => {
  4349. presentationModeState = state;
  4350. if (state === _ui_utils.PresentationModeState.NORMAL) {
  4351. enableActive();
  4352. } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
  4353. disableActive();
  4354. }
  4355. });
  4356. }
  4357. }
  4358. exports.PDFCursorTools = PDFCursorTools;
  4359. /***/ }),
  4360. /* 14 */
  4361. /***/ ((__unused_webpack_module, exports) => {
  4362. Object.defineProperty(exports, "__esModule", ({
  4363. value: true
  4364. }));
  4365. exports.GrabToPan = void 0;
  4366. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  4367. class GrabToPan {
  4368. constructor(options) {
  4369. this.element = options.element;
  4370. this.document = options.element.ownerDocument;
  4371. if (typeof options.ignoreTarget === "function") {
  4372. this.ignoreTarget = options.ignoreTarget;
  4373. }
  4374. this.onActiveChanged = options.onActiveChanged;
  4375. this.activate = this.activate.bind(this);
  4376. this.deactivate = this.deactivate.bind(this);
  4377. this.toggle = this.toggle.bind(this);
  4378. this._onMouseDown = this.#onMouseDown.bind(this);
  4379. this._onMouseMove = this.#onMouseMove.bind(this);
  4380. this._endPan = this.#endPan.bind(this);
  4381. const overlay = this.overlay = document.createElement("div");
  4382. overlay.className = "grab-to-pan-grabbing";
  4383. }
  4384. activate() {
  4385. if (!this.active) {
  4386. this.active = true;
  4387. this.element.addEventListener("mousedown", this._onMouseDown, true);
  4388. this.element.classList.add(CSS_CLASS_GRAB);
  4389. this.onActiveChanged?.(true);
  4390. }
  4391. }
  4392. deactivate() {
  4393. if (this.active) {
  4394. this.active = false;
  4395. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  4396. this._endPan();
  4397. this.element.classList.remove(CSS_CLASS_GRAB);
  4398. this.onActiveChanged?.(false);
  4399. }
  4400. }
  4401. toggle() {
  4402. if (this.active) {
  4403. this.deactivate();
  4404. } else {
  4405. this.activate();
  4406. }
  4407. }
  4408. ignoreTarget(node) {
  4409. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  4410. }
  4411. #onMouseDown(event) {
  4412. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  4413. return;
  4414. }
  4415. if (event.originalTarget) {
  4416. try {
  4417. event.originalTarget.tagName;
  4418. } catch (e) {
  4419. return;
  4420. }
  4421. }
  4422. this.scrollLeftStart = this.element.scrollLeft;
  4423. this.scrollTopStart = this.element.scrollTop;
  4424. this.clientXStart = event.clientX;
  4425. this.clientYStart = event.clientY;
  4426. this.document.addEventListener("mousemove", this._onMouseMove, true);
  4427. this.document.addEventListener("mouseup", this._endPan, true);
  4428. this.element.addEventListener("scroll", this._endPan, true);
  4429. event.preventDefault();
  4430. event.stopPropagation();
  4431. const focusedElement = document.activeElement;
  4432. if (focusedElement && !focusedElement.contains(event.target)) {
  4433. focusedElement.blur();
  4434. }
  4435. }
  4436. #onMouseMove(event) {
  4437. this.element.removeEventListener("scroll", this._endPan, true);
  4438. if (!(event.buttons & 1)) {
  4439. this._endPan();
  4440. return;
  4441. }
  4442. const xDiff = event.clientX - this.clientXStart;
  4443. const yDiff = event.clientY - this.clientYStart;
  4444. const scrollTop = this.scrollTopStart - yDiff;
  4445. const scrollLeft = this.scrollLeftStart - xDiff;
  4446. if (this.element.scrollTo) {
  4447. this.element.scrollTo({
  4448. top: scrollTop,
  4449. left: scrollLeft,
  4450. behavior: "instant"
  4451. });
  4452. } else {
  4453. this.element.scrollTop = scrollTop;
  4454. this.element.scrollLeft = scrollLeft;
  4455. }
  4456. if (!this.overlay.parentNode) {
  4457. document.body.append(this.overlay);
  4458. }
  4459. }
  4460. #endPan() {
  4461. this.element.removeEventListener("scroll", this._endPan, true);
  4462. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  4463. this.document.removeEventListener("mouseup", this._endPan, true);
  4464. this.overlay.remove();
  4465. }
  4466. }
  4467. exports.GrabToPan = GrabToPan;
  4468. /***/ }),
  4469. /* 15 */
  4470. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4471. Object.defineProperty(exports, "__esModule", ({
  4472. value: true
  4473. }));
  4474. exports.PDFDocumentProperties = void 0;
  4475. var _ui_utils = __webpack_require__(3);
  4476. var _pdfjsLib = __webpack_require__(4);
  4477. const DEFAULT_FIELD_CONTENT = "-";
  4478. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4479. const US_PAGE_NAMES = {
  4480. "8.5x11": "Letter",
  4481. "8.5x14": "Legal"
  4482. };
  4483. const METRIC_PAGE_NAMES = {
  4484. "297x420": "A3",
  4485. "210x297": "A4"
  4486. };
  4487. function getPageName(size, isPortrait, pageNames) {
  4488. const width = isPortrait ? size.width : size.height;
  4489. const height = isPortrait ? size.height : size.width;
  4490. return pageNames[`${width}x${height}`];
  4491. }
  4492. class PDFDocumentProperties {
  4493. #fieldData = null;
  4494. constructor({
  4495. dialog,
  4496. fields,
  4497. closeButton
  4498. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4499. this.dialog = dialog;
  4500. this.fields = fields;
  4501. this.overlayManager = overlayManager;
  4502. this.l10n = l10n;
  4503. this._fileNameLookup = fileNameLookup;
  4504. this.#reset();
  4505. closeButton.addEventListener("click", this.close.bind(this));
  4506. this.overlayManager.register(this.dialog);
  4507. eventBus._on("pagechanging", evt => {
  4508. this._currentPageNumber = evt.pageNumber;
  4509. });
  4510. eventBus._on("rotationchanging", evt => {
  4511. this._pagesRotation = evt.pagesRotation;
  4512. });
  4513. this._isNonMetricLocale = true;
  4514. l10n.getLanguage().then(locale => {
  4515. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4516. });
  4517. }
  4518. async open() {
  4519. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4520. const currentPageNumber = this._currentPageNumber;
  4521. const pagesRotation = this._pagesRotation;
  4522. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4523. this.#updateUI();
  4524. return;
  4525. }
  4526. const {
  4527. info,
  4528. contentLength
  4529. } = await this.pdfDocument.getMetadata();
  4530. 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 => {
  4531. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4532. }), this.#parseLinearization(info.IsLinearized)]);
  4533. this.#fieldData = Object.freeze({
  4534. fileName,
  4535. fileSize,
  4536. title: info.Title,
  4537. author: info.Author,
  4538. subject: info.Subject,
  4539. keywords: info.Keywords,
  4540. creationDate,
  4541. modificationDate,
  4542. creator: info.Creator,
  4543. producer: info.Producer,
  4544. version: info.PDFFormatVersion,
  4545. pageCount: this.pdfDocument.numPages,
  4546. pageSize,
  4547. linearized: isLinearized,
  4548. _currentPageNumber: currentPageNumber,
  4549. _pagesRotation: pagesRotation
  4550. });
  4551. this.#updateUI();
  4552. const {
  4553. length
  4554. } = await this.pdfDocument.getDownloadInfo();
  4555. if (contentLength === length) {
  4556. return;
  4557. }
  4558. const data = Object.assign(Object.create(null), this.#fieldData);
  4559. data.fileSize = await this.#parseFileSize(length);
  4560. this.#fieldData = Object.freeze(data);
  4561. this.#updateUI();
  4562. }
  4563. async close() {
  4564. this.overlayManager.close(this.dialog);
  4565. }
  4566. setDocument(pdfDocument) {
  4567. if (this.pdfDocument) {
  4568. this.#reset();
  4569. this.#updateUI(true);
  4570. }
  4571. if (!pdfDocument) {
  4572. return;
  4573. }
  4574. this.pdfDocument = pdfDocument;
  4575. this._dataAvailableCapability.resolve();
  4576. }
  4577. #reset() {
  4578. this.pdfDocument = null;
  4579. this.#fieldData = null;
  4580. this._dataAvailableCapability = new _pdfjsLib.PromiseCapability();
  4581. this._currentPageNumber = 1;
  4582. this._pagesRotation = 0;
  4583. }
  4584. #updateUI(reset = false) {
  4585. if (reset || !this.#fieldData) {
  4586. for (const id in this.fields) {
  4587. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4588. }
  4589. return;
  4590. }
  4591. if (this.overlayManager.active !== this.dialog) {
  4592. return;
  4593. }
  4594. for (const id in this.fields) {
  4595. const content = this.#fieldData[id];
  4596. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4597. }
  4598. }
  4599. async #parseFileSize(fileSize = 0) {
  4600. const kb = fileSize / 1024,
  4601. mb = kb / 1024;
  4602. if (!kb) {
  4603. return undefined;
  4604. }
  4605. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4606. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4607. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4608. size_b: fileSize.toLocaleString()
  4609. });
  4610. }
  4611. async #parsePageSize(pageSizeInches, pagesRotation) {
  4612. if (!pageSizeInches) {
  4613. return undefined;
  4614. }
  4615. if (pagesRotation % 180 !== 0) {
  4616. pageSizeInches = {
  4617. width: pageSizeInches.height,
  4618. height: pageSizeInches.width
  4619. };
  4620. }
  4621. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4622. let sizeInches = {
  4623. width: Math.round(pageSizeInches.width * 100) / 100,
  4624. height: Math.round(pageSizeInches.height * 100) / 100
  4625. };
  4626. let sizeMillimeters = {
  4627. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4628. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4629. };
  4630. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4631. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4632. const exactMillimeters = {
  4633. width: pageSizeInches.width * 25.4,
  4634. height: pageSizeInches.height * 25.4
  4635. };
  4636. const intMillimeters = {
  4637. width: Math.round(sizeMillimeters.width),
  4638. height: Math.round(sizeMillimeters.height)
  4639. };
  4640. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4641. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4642. if (rawName) {
  4643. sizeInches = {
  4644. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4645. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4646. };
  4647. sizeMillimeters = intMillimeters;
  4648. }
  4649. }
  4650. }
  4651. const [{
  4652. width,
  4653. height
  4654. }, 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"}`)]);
  4655. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4656. width: width.toLocaleString(),
  4657. height: height.toLocaleString(),
  4658. unit,
  4659. name,
  4660. orientation
  4661. });
  4662. }
  4663. async #parseDate(inputDate) {
  4664. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4665. if (!dateObject) {
  4666. return undefined;
  4667. }
  4668. return this.l10n.get("document_properties_date_string", {
  4669. date: dateObject.toLocaleDateString(),
  4670. time: dateObject.toLocaleTimeString()
  4671. });
  4672. }
  4673. #parseLinearization(isLinearized) {
  4674. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4675. }
  4676. }
  4677. exports.PDFDocumentProperties = PDFDocumentProperties;
  4678. /***/ }),
  4679. /* 16 */
  4680. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4681. Object.defineProperty(exports, "__esModule", ({
  4682. value: true
  4683. }));
  4684. exports.PDFFindBar = void 0;
  4685. var _pdf_find_controller = __webpack_require__(17);
  4686. var _ui_utils = __webpack_require__(3);
  4687. const MATCHES_COUNT_LIMIT = 1000;
  4688. class PDFFindBar {
  4689. constructor(options, eventBus, l10n) {
  4690. this.opened = false;
  4691. this.bar = options.bar;
  4692. this.toggleButton = options.toggleButton;
  4693. this.findField = options.findField;
  4694. this.highlightAll = options.highlightAllCheckbox;
  4695. this.caseSensitive = options.caseSensitiveCheckbox;
  4696. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4697. this.entireWord = options.entireWordCheckbox;
  4698. this.findMsg = options.findMsg;
  4699. this.findResultsCount = options.findResultsCount;
  4700. this.findPreviousButton = options.findPreviousButton;
  4701. this.findNextButton = options.findNextButton;
  4702. this.eventBus = eventBus;
  4703. this.l10n = l10n;
  4704. this.toggleButton.addEventListener("click", () => {
  4705. this.toggle();
  4706. });
  4707. this.findField.addEventListener("input", () => {
  4708. this.dispatchEvent("");
  4709. });
  4710. this.bar.addEventListener("keydown", e => {
  4711. switch (e.keyCode) {
  4712. case 13:
  4713. if (e.target === this.findField) {
  4714. this.dispatchEvent("again", e.shiftKey);
  4715. }
  4716. break;
  4717. case 27:
  4718. this.close();
  4719. break;
  4720. }
  4721. });
  4722. this.findPreviousButton.addEventListener("click", () => {
  4723. this.dispatchEvent("again", true);
  4724. });
  4725. this.findNextButton.addEventListener("click", () => {
  4726. this.dispatchEvent("again", false);
  4727. });
  4728. this.highlightAll.addEventListener("click", () => {
  4729. this.dispatchEvent("highlightallchange");
  4730. });
  4731. this.caseSensitive.addEventListener("click", () => {
  4732. this.dispatchEvent("casesensitivitychange");
  4733. });
  4734. this.entireWord.addEventListener("click", () => {
  4735. this.dispatchEvent("entirewordchange");
  4736. });
  4737. this.matchDiacritics.addEventListener("click", () => {
  4738. this.dispatchEvent("diacriticmatchingchange");
  4739. });
  4740. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4741. }
  4742. reset() {
  4743. this.updateUIState();
  4744. }
  4745. dispatchEvent(type, findPrev = false) {
  4746. this.eventBus.dispatch("find", {
  4747. source: this,
  4748. type,
  4749. query: this.findField.value,
  4750. caseSensitive: this.caseSensitive.checked,
  4751. entireWord: this.entireWord.checked,
  4752. highlightAll: this.highlightAll.checked,
  4753. findPrevious: findPrev,
  4754. matchDiacritics: this.matchDiacritics.checked
  4755. });
  4756. }
  4757. updateUIState(state, previous, matchesCount) {
  4758. let findMsg = Promise.resolve("");
  4759. let status = "";
  4760. switch (state) {
  4761. case _pdf_find_controller.FindState.FOUND:
  4762. break;
  4763. case _pdf_find_controller.FindState.PENDING:
  4764. status = "pending";
  4765. break;
  4766. case _pdf_find_controller.FindState.NOT_FOUND:
  4767. findMsg = this.l10n.get("find_not_found");
  4768. status = "notFound";
  4769. break;
  4770. case _pdf_find_controller.FindState.WRAPPED:
  4771. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4772. break;
  4773. }
  4774. this.findField.setAttribute("data-status", status);
  4775. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4776. findMsg.then(msg => {
  4777. this.findMsg.setAttribute("data-status", status);
  4778. this.findMsg.textContent = msg;
  4779. this.#adjustWidth();
  4780. });
  4781. this.updateResultsCount(matchesCount);
  4782. }
  4783. updateResultsCount({
  4784. current = 0,
  4785. total = 0
  4786. } = {}) {
  4787. const limit = MATCHES_COUNT_LIMIT;
  4788. let matchCountMsg = Promise.resolve("");
  4789. if (total > 0) {
  4790. if (total > limit) {
  4791. let key = "find_match_count_limit";
  4792. matchCountMsg = this.l10n.get(key, {
  4793. limit
  4794. });
  4795. } else {
  4796. let key = "find_match_count";
  4797. matchCountMsg = this.l10n.get(key, {
  4798. current,
  4799. total
  4800. });
  4801. }
  4802. }
  4803. matchCountMsg.then(msg => {
  4804. this.findResultsCount.textContent = msg;
  4805. this.#adjustWidth();
  4806. });
  4807. }
  4808. open() {
  4809. if (!this.opened) {
  4810. this.opened = true;
  4811. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true, this.bar);
  4812. }
  4813. this.findField.select();
  4814. this.findField.focus();
  4815. this.#adjustWidth();
  4816. }
  4817. close() {
  4818. if (!this.opened) {
  4819. return;
  4820. }
  4821. this.opened = false;
  4822. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false, this.bar);
  4823. this.eventBus.dispatch("findbarclose", {
  4824. source: this
  4825. });
  4826. }
  4827. toggle() {
  4828. if (this.opened) {
  4829. this.close();
  4830. } else {
  4831. this.open();
  4832. }
  4833. }
  4834. #adjustWidth() {
  4835. if (!this.opened) {
  4836. return;
  4837. }
  4838. this.bar.classList.remove("wrapContainers");
  4839. const findbarHeight = this.bar.clientHeight;
  4840. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4841. if (findbarHeight > inputContainerHeight) {
  4842. this.bar.classList.add("wrapContainers");
  4843. }
  4844. }
  4845. }
  4846. exports.PDFFindBar = PDFFindBar;
  4847. /***/ }),
  4848. /* 17 */
  4849. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4850. Object.defineProperty(exports, "__esModule", ({
  4851. value: true
  4852. }));
  4853. exports.PDFFindController = exports.FindState = void 0;
  4854. var _ui_utils = __webpack_require__(3);
  4855. var _pdf_find_utils = __webpack_require__(18);
  4856. var _pdfjsLib = __webpack_require__(4);
  4857. const FindState = {
  4858. FOUND: 0,
  4859. NOT_FOUND: 1,
  4860. WRAPPED: 2,
  4861. PENDING: 3
  4862. };
  4863. exports.FindState = FindState;
  4864. const FIND_TIMEOUT = 250;
  4865. const MATCH_SCROLL_OFFSET_TOP = -50;
  4866. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4867. const CHARACTERS_TO_NORMALIZE = {
  4868. "\u2010": "-",
  4869. "\u2018": "'",
  4870. "\u2019": "'",
  4871. "\u201A": "'",
  4872. "\u201B": "'",
  4873. "\u201C": '"',
  4874. "\u201D": '"',
  4875. "\u201E": '"',
  4876. "\u201F": '"',
  4877. "\u00BC": "1/4",
  4878. "\u00BD": "1/2",
  4879. "\u00BE": "3/4"
  4880. };
  4881. 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]);
  4882. let DIACRITICS_EXCEPTION_STR;
  4883. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4884. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4885. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4886. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4887. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4888. const SYLLABLES_LENGTHS = new Map();
  4889. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4890. const NFKC_CHARS_TO_NORMALIZE = new Map();
  4891. let noSyllablesRegExp = null;
  4892. let withSyllablesRegExp = null;
  4893. function normalize(text) {
  4894. const syllablePositions = [];
  4895. let m;
  4896. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4897. let {
  4898. index
  4899. } = m;
  4900. for (const char of m[0]) {
  4901. let len = SYLLABLES_LENGTHS.get(char);
  4902. if (!len) {
  4903. len = char.normalize("NFD").length;
  4904. SYLLABLES_LENGTHS.set(char, len);
  4905. }
  4906. syllablePositions.push([len, index++]);
  4907. }
  4908. }
  4909. let normalizationRegex;
  4910. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4911. normalizationRegex = noSyllablesRegExp;
  4912. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4913. normalizationRegex = withSyllablesRegExp;
  4914. } else {
  4915. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4916. const toNormalizeWithNFKC = (0, _pdf_find_utils.getNormalizeWithNFKC)();
  4917. const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
  4918. const HKDiacritics = "(?:\u3099|\u309A)";
  4919. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(${HKDiacritics}\\n)|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
  4920. if (syllablePositions.length === 0) {
  4921. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4922. } else {
  4923. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4924. }
  4925. }
  4926. const rawDiacriticsPositions = [];
  4927. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4928. rawDiacriticsPositions.push([m[0].length, m.index]);
  4929. }
  4930. let normalized = text.normalize("NFD");
  4931. const positions = [[0, 0]];
  4932. let rawDiacriticsIndex = 0;
  4933. let syllableIndex = 0;
  4934. let shift = 0;
  4935. let shiftOrigin = 0;
  4936. let eol = 0;
  4937. let hasDiacritics = false;
  4938. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, p8, i) => {
  4939. i -= shiftOrigin;
  4940. if (p1) {
  4941. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  4942. const jj = replacement.length;
  4943. for (let j = 1; j < jj; j++) {
  4944. positions.push([i - shift + j, shift - j]);
  4945. }
  4946. shift -= jj - 1;
  4947. return replacement;
  4948. }
  4949. if (p2) {
  4950. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  4951. if (!replacement) {
  4952. replacement = p2.normalize("NFKC");
  4953. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  4954. }
  4955. const jj = replacement.length;
  4956. for (let j = 1; j < jj; j++) {
  4957. positions.push([i - shift + j, shift - j]);
  4958. }
  4959. shift -= jj - 1;
  4960. return replacement;
  4961. }
  4962. if (p3) {
  4963. hasDiacritics = true;
  4964. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4965. ++rawDiacriticsIndex;
  4966. } else {
  4967. positions.push([i - 1 - shift + 1, shift - 1]);
  4968. shift -= 1;
  4969. shiftOrigin += 1;
  4970. }
  4971. positions.push([i - shift + 1, shift]);
  4972. shiftOrigin += 1;
  4973. eol += 1;
  4974. return p3.charAt(0);
  4975. }
  4976. if (p4) {
  4977. const hasTrailingDashEOL = p4.endsWith("\n");
  4978. const len = hasTrailingDashEOL ? p4.length - 2 : p4.length;
  4979. hasDiacritics = true;
  4980. let jj = len;
  4981. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4982. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4983. ++rawDiacriticsIndex;
  4984. }
  4985. for (let j = 1; j <= jj; j++) {
  4986. positions.push([i - 1 - shift + j, shift - j]);
  4987. }
  4988. shift -= jj;
  4989. shiftOrigin += jj;
  4990. if (hasTrailingDashEOL) {
  4991. i += len - 1;
  4992. positions.push([i - shift + 1, 1 + shift]);
  4993. shift += 1;
  4994. shiftOrigin += 1;
  4995. eol += 1;
  4996. return p4.slice(0, len);
  4997. }
  4998. return p4;
  4999. }
  5000. if (p5) {
  5001. const len = p5.length - 2;
  5002. positions.push([i - shift + len, 1 + shift]);
  5003. shift += 1;
  5004. shiftOrigin += 1;
  5005. eol += 1;
  5006. return p5.slice(0, -2);
  5007. }
  5008. if (p6) {
  5009. const len = p6.length - 1;
  5010. positions.push([i - shift + len, shift]);
  5011. shiftOrigin += 1;
  5012. eol += 1;
  5013. return p6.slice(0, -1);
  5014. }
  5015. if (p7) {
  5016. positions.push([i - shift + 1, shift - 1]);
  5017. shift -= 1;
  5018. shiftOrigin += 1;
  5019. eol += 1;
  5020. return " ";
  5021. }
  5022. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  5023. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  5024. ++syllableIndex;
  5025. for (let j = 1; j <= newCharLen; j++) {
  5026. positions.push([i - (shift - j), shift - j]);
  5027. }
  5028. shift -= newCharLen;
  5029. shiftOrigin += newCharLen;
  5030. }
  5031. return p8;
  5032. });
  5033. positions.push([normalized.length, shift]);
  5034. return [normalized, positions, hasDiacritics];
  5035. }
  5036. function getOriginalIndex(diffs, pos, len) {
  5037. if (!diffs) {
  5038. return [pos, len];
  5039. }
  5040. const start = pos;
  5041. const end = pos + len - 1;
  5042. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  5043. if (diffs[i][0] > start) {
  5044. --i;
  5045. }
  5046. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  5047. if (diffs[j][0] > end) {
  5048. --j;
  5049. }
  5050. const oldStart = start + diffs[i][1];
  5051. const oldEnd = end + diffs[j][1];
  5052. const oldLen = oldEnd + 1 - oldStart;
  5053. return [oldStart, oldLen];
  5054. }
  5055. class PDFFindController {
  5056. #state = null;
  5057. #updateMatchesCountOnProgress = true;
  5058. #visitedPagesCount = 0;
  5059. constructor({
  5060. linkService,
  5061. eventBus,
  5062. updateMatchesCountOnProgress = true
  5063. }) {
  5064. this._linkService = linkService;
  5065. this._eventBus = eventBus;
  5066. this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
  5067. this.onIsPageVisible = null;
  5068. this.#reset();
  5069. eventBus._on("find", this.#onFind.bind(this));
  5070. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  5071. }
  5072. get highlightMatches() {
  5073. return this._highlightMatches;
  5074. }
  5075. get pageMatches() {
  5076. return this._pageMatches;
  5077. }
  5078. get pageMatchesLength() {
  5079. return this._pageMatchesLength;
  5080. }
  5081. get selected() {
  5082. return this._selected;
  5083. }
  5084. get state() {
  5085. return this.#state;
  5086. }
  5087. setDocument(pdfDocument) {
  5088. if (this._pdfDocument) {
  5089. this.#reset();
  5090. }
  5091. if (!pdfDocument) {
  5092. return;
  5093. }
  5094. this._pdfDocument = pdfDocument;
  5095. this._firstPageCapability.resolve();
  5096. }
  5097. #onFind(state) {
  5098. if (!state) {
  5099. return;
  5100. }
  5101. if (state.phraseSearch === false) {
  5102. console.error("The `phraseSearch`-parameter was removed, please provide " + "an Array of strings in the `query`-parameter instead.");
  5103. if (typeof state.query === "string") {
  5104. state.query = state.query.match(/\S+/g);
  5105. }
  5106. }
  5107. const pdfDocument = this._pdfDocument;
  5108. const {
  5109. type
  5110. } = state;
  5111. if (this.#state === null || this.#shouldDirtyMatch(state)) {
  5112. this._dirtyMatch = true;
  5113. }
  5114. this.#state = state;
  5115. if (type !== "highlightallchange") {
  5116. this.#updateUIState(FindState.PENDING);
  5117. }
  5118. this._firstPageCapability.promise.then(() => {
  5119. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5120. return;
  5121. }
  5122. this.#extractText();
  5123. const findbarClosed = !this._highlightMatches;
  5124. const pendingTimeout = !!this._findTimeout;
  5125. if (this._findTimeout) {
  5126. clearTimeout(this._findTimeout);
  5127. this._findTimeout = null;
  5128. }
  5129. if (!type) {
  5130. this._findTimeout = setTimeout(() => {
  5131. this.#nextMatch();
  5132. this._findTimeout = null;
  5133. }, FIND_TIMEOUT);
  5134. } else if (this._dirtyMatch) {
  5135. this.#nextMatch();
  5136. } else if (type === "again") {
  5137. this.#nextMatch();
  5138. if (findbarClosed && this.#state.highlightAll) {
  5139. this.#updateAllPages();
  5140. }
  5141. } else if (type === "highlightallchange") {
  5142. if (pendingTimeout) {
  5143. this.#nextMatch();
  5144. } else {
  5145. this._highlightMatches = true;
  5146. }
  5147. this.#updateAllPages();
  5148. } else {
  5149. this.#nextMatch();
  5150. }
  5151. });
  5152. }
  5153. scrollMatchIntoView({
  5154. element = null,
  5155. selectedLeft = 0,
  5156. pageIndex = -1,
  5157. matchIndex = -1
  5158. }) {
  5159. if (!this._scrollMatches || !element) {
  5160. return;
  5161. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  5162. return;
  5163. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5164. return;
  5165. }
  5166. this._scrollMatches = false;
  5167. const spot = {
  5168. top: MATCH_SCROLL_OFFSET_TOP,
  5169. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  5170. };
  5171. (0, _ui_utils.scrollIntoView)(element, spot, true);
  5172. }
  5173. #reset() {
  5174. this._highlightMatches = false;
  5175. this._scrollMatches = false;
  5176. this._pdfDocument = null;
  5177. this._pageMatches = [];
  5178. this._pageMatchesLength = [];
  5179. this.#visitedPagesCount = 0;
  5180. this.#state = null;
  5181. this._selected = {
  5182. pageIdx: -1,
  5183. matchIdx: -1
  5184. };
  5185. this._offset = {
  5186. pageIdx: null,
  5187. matchIdx: null,
  5188. wrapped: false
  5189. };
  5190. this._extractTextPromises = [];
  5191. this._pageContents = [];
  5192. this._pageDiffs = [];
  5193. this._hasDiacritics = [];
  5194. this._matchesCountTotal = 0;
  5195. this._pagesToSearch = null;
  5196. this._pendingFindMatches = new Set();
  5197. this._resumePageIdx = null;
  5198. this._dirtyMatch = false;
  5199. clearTimeout(this._findTimeout);
  5200. this._findTimeout = null;
  5201. this._firstPageCapability = new _pdfjsLib.PromiseCapability();
  5202. }
  5203. get #query() {
  5204. const {
  5205. query
  5206. } = this.#state;
  5207. if (typeof query === "string") {
  5208. if (query !== this._rawQuery) {
  5209. this._rawQuery = query;
  5210. [this._normalizedQuery] = normalize(query);
  5211. }
  5212. return this._normalizedQuery;
  5213. }
  5214. return (query || []).filter(q => !!q).map(q => normalize(q)[0]);
  5215. }
  5216. #shouldDirtyMatch(state) {
  5217. const newQuery = state.query,
  5218. prevQuery = this.#state.query;
  5219. const newType = typeof newQuery,
  5220. prevType = typeof prevQuery;
  5221. if (newType !== prevType) {
  5222. return true;
  5223. }
  5224. if (newType === "string") {
  5225. if (newQuery !== prevQuery) {
  5226. return true;
  5227. }
  5228. } else {
  5229. if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) {
  5230. return true;
  5231. }
  5232. }
  5233. switch (state.type) {
  5234. case "again":
  5235. const pageNumber = this._selected.pageIdx + 1;
  5236. const linkService = this._linkService;
  5237. return pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !(this.onIsPageVisible?.(pageNumber) ?? true);
  5238. case "highlightallchange":
  5239. return false;
  5240. }
  5241. return true;
  5242. }
  5243. #isEntireWord(content, startIdx, length) {
  5244. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  5245. if (match) {
  5246. const first = content.charCodeAt(startIdx);
  5247. const limit = match[1].charCodeAt(0);
  5248. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5249. return false;
  5250. }
  5251. }
  5252. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  5253. if (match) {
  5254. const last = content.charCodeAt(startIdx + length - 1);
  5255. const limit = match[1].charCodeAt(0);
  5256. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5257. return false;
  5258. }
  5259. }
  5260. return true;
  5261. }
  5262. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  5263. const matches = this._pageMatches[pageIndex] = [];
  5264. const matchesLength = this._pageMatchesLength[pageIndex] = [];
  5265. if (!query) {
  5266. return;
  5267. }
  5268. const diffs = this._pageDiffs[pageIndex];
  5269. let match;
  5270. while ((match = query.exec(pageContent)) !== null) {
  5271. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  5272. continue;
  5273. }
  5274. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  5275. if (matchLen) {
  5276. matches.push(matchPos);
  5277. matchesLength.push(matchLen);
  5278. }
  5279. }
  5280. }
  5281. #convertToRegExpString(query, hasDiacritics) {
  5282. const {
  5283. matchDiacritics
  5284. } = this.#state;
  5285. let isUnicode = false;
  5286. query = query.replaceAll(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  5287. if (p1) {
  5288. return `[ ]*\\${p1}[ ]*`;
  5289. }
  5290. if (p2) {
  5291. return `[ ]*${p2}[ ]*`;
  5292. }
  5293. if (p3) {
  5294. return "[ ]+";
  5295. }
  5296. if (matchDiacritics) {
  5297. return p4 || p5;
  5298. }
  5299. if (p4) {
  5300. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5301. }
  5302. if (hasDiacritics) {
  5303. isUnicode = true;
  5304. return `${p5}\\p{M}*`;
  5305. }
  5306. return p5;
  5307. });
  5308. const trailingSpaces = "[ ]*";
  5309. if (query.endsWith(trailingSpaces)) {
  5310. query = query.slice(0, query.length - trailingSpaces.length);
  5311. }
  5312. if (matchDiacritics) {
  5313. if (hasDiacritics) {
  5314. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION);
  5315. isUnicode = true;
  5316. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5317. }
  5318. }
  5319. return [isUnicode, query];
  5320. }
  5321. #calculateMatch(pageIndex) {
  5322. let query = this.#query;
  5323. if (query.length === 0) {
  5324. return;
  5325. }
  5326. const {
  5327. caseSensitive,
  5328. entireWord
  5329. } = this.#state;
  5330. const pageContent = this._pageContents[pageIndex];
  5331. const hasDiacritics = this._hasDiacritics[pageIndex];
  5332. let isUnicode = false;
  5333. if (typeof query === "string") {
  5334. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5335. } else {
  5336. query = query.sort().reverse().map(q => {
  5337. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5338. isUnicode ||= isUnicodePart;
  5339. return `(${queryPart})`;
  5340. }).join("|");
  5341. }
  5342. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5343. query = query ? new RegExp(query, flags) : null;
  5344. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  5345. if (this.#state.highlightAll) {
  5346. this.#updatePage(pageIndex);
  5347. }
  5348. if (this._resumePageIdx === pageIndex) {
  5349. this._resumePageIdx = null;
  5350. this.#nextPageMatch();
  5351. }
  5352. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5353. this._matchesCountTotal += pageMatchesCount;
  5354. if (this.#updateMatchesCountOnProgress) {
  5355. if (pageMatchesCount > 0) {
  5356. this.#updateUIResultsCount();
  5357. }
  5358. } else if (++this.#visitedPagesCount === this._linkService.pagesCount) {
  5359. this.#updateUIResultsCount();
  5360. }
  5361. }
  5362. #extractText() {
  5363. if (this._extractTextPromises.length > 0) {
  5364. return;
  5365. }
  5366. let promise = Promise.resolve();
  5367. const textOptions = {
  5368. disableNormalization: true
  5369. };
  5370. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5371. const extractTextCapability = new _pdfjsLib.PromiseCapability();
  5372. this._extractTextPromises[i] = extractTextCapability.promise;
  5373. promise = promise.then(() => {
  5374. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5375. return pdfPage.getTextContent(textOptions);
  5376. }).then(textContent => {
  5377. const strBuf = [];
  5378. for (const textItem of textContent.items) {
  5379. strBuf.push(textItem.str);
  5380. if (textItem.hasEOL) {
  5381. strBuf.push("\n");
  5382. }
  5383. }
  5384. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5385. extractTextCapability.resolve();
  5386. }, reason => {
  5387. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5388. this._pageContents[i] = "";
  5389. this._pageDiffs[i] = null;
  5390. this._hasDiacritics[i] = false;
  5391. extractTextCapability.resolve();
  5392. });
  5393. });
  5394. }
  5395. }
  5396. #updatePage(index) {
  5397. if (this._scrollMatches && this._selected.pageIdx === index) {
  5398. this._linkService.page = index + 1;
  5399. }
  5400. this._eventBus.dispatch("updatetextlayermatches", {
  5401. source: this,
  5402. pageIndex: index
  5403. });
  5404. }
  5405. #updateAllPages() {
  5406. this._eventBus.dispatch("updatetextlayermatches", {
  5407. source: this,
  5408. pageIndex: -1
  5409. });
  5410. }
  5411. #nextMatch() {
  5412. const previous = this.#state.findPrevious;
  5413. const currentPageIndex = this._linkService.page - 1;
  5414. const numPages = this._linkService.pagesCount;
  5415. this._highlightMatches = true;
  5416. if (this._dirtyMatch) {
  5417. this._dirtyMatch = false;
  5418. this._selected.pageIdx = this._selected.matchIdx = -1;
  5419. this._offset.pageIdx = currentPageIndex;
  5420. this._offset.matchIdx = null;
  5421. this._offset.wrapped = false;
  5422. this._resumePageIdx = null;
  5423. this._pageMatches.length = 0;
  5424. this._pageMatchesLength.length = 0;
  5425. this.#visitedPagesCount = 0;
  5426. this._matchesCountTotal = 0;
  5427. this.#updateAllPages();
  5428. for (let i = 0; i < numPages; i++) {
  5429. if (this._pendingFindMatches.has(i)) {
  5430. continue;
  5431. }
  5432. this._pendingFindMatches.add(i);
  5433. this._extractTextPromises[i].then(() => {
  5434. this._pendingFindMatches.delete(i);
  5435. this.#calculateMatch(i);
  5436. });
  5437. }
  5438. }
  5439. const query = this.#query;
  5440. if (query.length === 0) {
  5441. this.#updateUIState(FindState.FOUND);
  5442. return;
  5443. }
  5444. if (this._resumePageIdx) {
  5445. return;
  5446. }
  5447. const offset = this._offset;
  5448. this._pagesToSearch = numPages;
  5449. if (offset.matchIdx !== null) {
  5450. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5451. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5452. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5453. this.#updateMatch(true);
  5454. return;
  5455. }
  5456. this.#advanceOffsetPage(previous);
  5457. }
  5458. this.#nextPageMatch();
  5459. }
  5460. #matchesReady(matches) {
  5461. const offset = this._offset;
  5462. const numMatches = matches.length;
  5463. const previous = this.#state.findPrevious;
  5464. if (numMatches) {
  5465. offset.matchIdx = previous ? numMatches - 1 : 0;
  5466. this.#updateMatch(true);
  5467. return true;
  5468. }
  5469. this.#advanceOffsetPage(previous);
  5470. if (offset.wrapped) {
  5471. offset.matchIdx = null;
  5472. if (this._pagesToSearch < 0) {
  5473. this.#updateMatch(false);
  5474. return true;
  5475. }
  5476. }
  5477. return false;
  5478. }
  5479. #nextPageMatch() {
  5480. if (this._resumePageIdx !== null) {
  5481. console.error("There can only be one pending page.");
  5482. }
  5483. let matches = null;
  5484. do {
  5485. const pageIdx = this._offset.pageIdx;
  5486. matches = this._pageMatches[pageIdx];
  5487. if (!matches) {
  5488. this._resumePageIdx = pageIdx;
  5489. break;
  5490. }
  5491. } while (!this.#matchesReady(matches));
  5492. }
  5493. #advanceOffsetPage(previous) {
  5494. const offset = this._offset;
  5495. const numPages = this._linkService.pagesCount;
  5496. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5497. offset.matchIdx = null;
  5498. this._pagesToSearch--;
  5499. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5500. offset.pageIdx = previous ? numPages - 1 : 0;
  5501. offset.wrapped = true;
  5502. }
  5503. }
  5504. #updateMatch(found = false) {
  5505. let state = FindState.NOT_FOUND;
  5506. const wrapped = this._offset.wrapped;
  5507. this._offset.wrapped = false;
  5508. if (found) {
  5509. const previousPage = this._selected.pageIdx;
  5510. this._selected.pageIdx = this._offset.pageIdx;
  5511. this._selected.matchIdx = this._offset.matchIdx;
  5512. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5513. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5514. this.#updatePage(previousPage);
  5515. }
  5516. }
  5517. this.#updateUIState(state, this.#state.findPrevious);
  5518. if (this._selected.pageIdx !== -1) {
  5519. this._scrollMatches = true;
  5520. this.#updatePage(this._selected.pageIdx);
  5521. }
  5522. }
  5523. #onFindBarClose(evt) {
  5524. const pdfDocument = this._pdfDocument;
  5525. this._firstPageCapability.promise.then(() => {
  5526. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5527. return;
  5528. }
  5529. if (this._findTimeout) {
  5530. clearTimeout(this._findTimeout);
  5531. this._findTimeout = null;
  5532. }
  5533. if (this._resumePageIdx) {
  5534. this._resumePageIdx = null;
  5535. this._dirtyMatch = true;
  5536. }
  5537. this.#updateUIState(FindState.FOUND);
  5538. this._highlightMatches = false;
  5539. this.#updateAllPages();
  5540. });
  5541. }
  5542. #requestMatchesCount() {
  5543. const {
  5544. pageIdx,
  5545. matchIdx
  5546. } = this._selected;
  5547. let current = 0,
  5548. total = this._matchesCountTotal;
  5549. if (matchIdx !== -1) {
  5550. for (let i = 0; i < pageIdx; i++) {
  5551. current += this._pageMatches[i]?.length || 0;
  5552. }
  5553. current += matchIdx + 1;
  5554. }
  5555. if (current < 1 || current > total) {
  5556. current = total = 0;
  5557. }
  5558. return {
  5559. current,
  5560. total
  5561. };
  5562. }
  5563. #updateUIResultsCount() {
  5564. this._eventBus.dispatch("updatefindmatchescount", {
  5565. source: this,
  5566. matchesCount: this.#requestMatchesCount()
  5567. });
  5568. }
  5569. #updateUIState(state, previous = false) {
  5570. if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) {
  5571. return;
  5572. }
  5573. this._eventBus.dispatch("updatefindcontrolstate", {
  5574. source: this,
  5575. state,
  5576. previous,
  5577. matchesCount: this.#requestMatchesCount(),
  5578. rawQuery: this.#state?.query ?? null
  5579. });
  5580. }
  5581. }
  5582. exports.PDFFindController = PDFFindController;
  5583. /***/ }),
  5584. /* 18 */
  5585. /***/ ((__unused_webpack_module, exports) => {
  5586. Object.defineProperty(exports, "__esModule", ({
  5587. value: true
  5588. }));
  5589. exports.CharacterType = void 0;
  5590. exports.getCharacterType = getCharacterType;
  5591. exports.getNormalizeWithNFKC = getNormalizeWithNFKC;
  5592. const CharacterType = {
  5593. SPACE: 0,
  5594. ALPHA_LETTER: 1,
  5595. PUNCT: 2,
  5596. HAN_LETTER: 3,
  5597. KATAKANA_LETTER: 4,
  5598. HIRAGANA_LETTER: 5,
  5599. HALFWIDTH_KATAKANA_LETTER: 6,
  5600. THAI_LETTER: 7
  5601. };
  5602. exports.CharacterType = CharacterType;
  5603. function isAlphabeticalScript(charCode) {
  5604. return charCode < 0x2e80;
  5605. }
  5606. function isAscii(charCode) {
  5607. return (charCode & 0xff80) === 0;
  5608. }
  5609. function isAsciiAlpha(charCode) {
  5610. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5611. }
  5612. function isAsciiDigit(charCode) {
  5613. return charCode >= 0x30 && charCode <= 0x39;
  5614. }
  5615. function isAsciiSpace(charCode) {
  5616. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5617. }
  5618. function isHan(charCode) {
  5619. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5620. }
  5621. function isKatakana(charCode) {
  5622. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5623. }
  5624. function isHiragana(charCode) {
  5625. return charCode >= 0x3040 && charCode <= 0x309f;
  5626. }
  5627. function isHalfwidthKatakana(charCode) {
  5628. return charCode >= 0xff60 && charCode <= 0xff9f;
  5629. }
  5630. function isThai(charCode) {
  5631. return (charCode & 0xff80) === 0x0e00;
  5632. }
  5633. function getCharacterType(charCode) {
  5634. if (isAlphabeticalScript(charCode)) {
  5635. if (isAscii(charCode)) {
  5636. if (isAsciiSpace(charCode)) {
  5637. return CharacterType.SPACE;
  5638. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5639. return CharacterType.ALPHA_LETTER;
  5640. }
  5641. return CharacterType.PUNCT;
  5642. } else if (isThai(charCode)) {
  5643. return CharacterType.THAI_LETTER;
  5644. } else if (charCode === 0xa0) {
  5645. return CharacterType.SPACE;
  5646. }
  5647. return CharacterType.ALPHA_LETTER;
  5648. }
  5649. if (isHan(charCode)) {
  5650. return CharacterType.HAN_LETTER;
  5651. } else if (isKatakana(charCode)) {
  5652. return CharacterType.KATAKANA_LETTER;
  5653. } else if (isHiragana(charCode)) {
  5654. return CharacterType.HIRAGANA_LETTER;
  5655. } else if (isHalfwidthKatakana(charCode)) {
  5656. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5657. }
  5658. return CharacterType.ALPHA_LETTER;
  5659. }
  5660. let NormalizeWithNFKC;
  5661. function getNormalizeWithNFKC() {
  5662. NormalizeWithNFKC ||= ` ¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰꟲ-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`;
  5663. return NormalizeWithNFKC;
  5664. }
  5665. /***/ }),
  5666. /* 19 */
  5667. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5668. Object.defineProperty(exports, "__esModule", ({
  5669. value: true
  5670. }));
  5671. exports.PDFHistory = void 0;
  5672. exports.isDestArraysEqual = isDestArraysEqual;
  5673. exports.isDestHashesEqual = isDestHashesEqual;
  5674. var _ui_utils = __webpack_require__(3);
  5675. var _event_utils = __webpack_require__(6);
  5676. const HASH_CHANGE_TIMEOUT = 1000;
  5677. const POSITION_UPDATED_THRESHOLD = 50;
  5678. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5679. function getCurrentHash() {
  5680. return document.location.hash;
  5681. }
  5682. class PDFHistory {
  5683. constructor({
  5684. linkService,
  5685. eventBus
  5686. }) {
  5687. this.linkService = linkService;
  5688. this.eventBus = eventBus;
  5689. this._initialized = false;
  5690. this._fingerprint = "";
  5691. this.reset();
  5692. this._boundEvents = null;
  5693. this.eventBus._on("pagesinit", () => {
  5694. this._isPagesLoaded = false;
  5695. this.eventBus._on("pagesloaded", evt => {
  5696. this._isPagesLoaded = !!evt.pagesCount;
  5697. }, {
  5698. once: true
  5699. });
  5700. });
  5701. }
  5702. initialize({
  5703. fingerprint,
  5704. resetHistory = false,
  5705. updateUrl = false
  5706. }) {
  5707. if (!fingerprint || typeof fingerprint !== "string") {
  5708. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5709. return;
  5710. }
  5711. if (this._initialized) {
  5712. this.reset();
  5713. }
  5714. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5715. this._fingerprint = fingerprint;
  5716. this._updateUrl = updateUrl === true;
  5717. this._initialized = true;
  5718. this._bindEvents();
  5719. const state = window.history.state;
  5720. this._popStateInProgress = false;
  5721. this._blockHashChange = 0;
  5722. this._currentHash = getCurrentHash();
  5723. this._numPositionUpdates = 0;
  5724. this._uid = this._maxUid = 0;
  5725. this._destination = null;
  5726. this._position = null;
  5727. if (!this._isValidState(state, true) || resetHistory) {
  5728. const {
  5729. hash,
  5730. page,
  5731. rotation
  5732. } = this._parseCurrentHash(true);
  5733. if (!hash || reInitialized || resetHistory) {
  5734. this._pushOrReplaceState(null, true);
  5735. return;
  5736. }
  5737. this._pushOrReplaceState({
  5738. hash,
  5739. page,
  5740. rotation
  5741. }, true);
  5742. return;
  5743. }
  5744. const destination = state.destination;
  5745. this._updateInternalState(destination, state.uid, true);
  5746. if (destination.rotation !== undefined) {
  5747. this._initialRotation = destination.rotation;
  5748. }
  5749. if (destination.dest) {
  5750. this._initialBookmark = JSON.stringify(destination.dest);
  5751. this._destination.page = null;
  5752. } else if (destination.hash) {
  5753. this._initialBookmark = destination.hash;
  5754. } else if (destination.page) {
  5755. this._initialBookmark = `page=${destination.page}`;
  5756. }
  5757. }
  5758. reset() {
  5759. if (this._initialized) {
  5760. this._pageHide();
  5761. this._initialized = false;
  5762. this._unbindEvents();
  5763. }
  5764. if (this._updateViewareaTimeout) {
  5765. clearTimeout(this._updateViewareaTimeout);
  5766. this._updateViewareaTimeout = null;
  5767. }
  5768. this._initialBookmark = null;
  5769. this._initialRotation = null;
  5770. }
  5771. push({
  5772. namedDest = null,
  5773. explicitDest,
  5774. pageNumber
  5775. }) {
  5776. if (!this._initialized) {
  5777. return;
  5778. }
  5779. if (namedDest && typeof namedDest !== "string") {
  5780. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5781. return;
  5782. } else if (!Array.isArray(explicitDest)) {
  5783. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5784. return;
  5785. } else if (!this._isValidPage(pageNumber)) {
  5786. if (pageNumber !== null || this._destination) {
  5787. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5788. return;
  5789. }
  5790. }
  5791. const hash = namedDest || JSON.stringify(explicitDest);
  5792. if (!hash) {
  5793. return;
  5794. }
  5795. let forceReplace = false;
  5796. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5797. if (this._destination.page) {
  5798. return;
  5799. }
  5800. forceReplace = true;
  5801. }
  5802. if (this._popStateInProgress && !forceReplace) {
  5803. return;
  5804. }
  5805. this._pushOrReplaceState({
  5806. dest: explicitDest,
  5807. hash,
  5808. page: pageNumber,
  5809. rotation: this.linkService.rotation
  5810. }, forceReplace);
  5811. if (!this._popStateInProgress) {
  5812. this._popStateInProgress = true;
  5813. Promise.resolve().then(() => {
  5814. this._popStateInProgress = false;
  5815. });
  5816. }
  5817. }
  5818. pushPage(pageNumber) {
  5819. if (!this._initialized) {
  5820. return;
  5821. }
  5822. if (!this._isValidPage(pageNumber)) {
  5823. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5824. return;
  5825. }
  5826. if (this._destination?.page === pageNumber) {
  5827. return;
  5828. }
  5829. if (this._popStateInProgress) {
  5830. return;
  5831. }
  5832. this._pushOrReplaceState({
  5833. dest: null,
  5834. hash: `page=${pageNumber}`,
  5835. page: pageNumber,
  5836. rotation: this.linkService.rotation
  5837. });
  5838. if (!this._popStateInProgress) {
  5839. this._popStateInProgress = true;
  5840. Promise.resolve().then(() => {
  5841. this._popStateInProgress = false;
  5842. });
  5843. }
  5844. }
  5845. pushCurrentPosition() {
  5846. if (!this._initialized || this._popStateInProgress) {
  5847. return;
  5848. }
  5849. this._tryPushCurrentPosition();
  5850. }
  5851. back() {
  5852. if (!this._initialized || this._popStateInProgress) {
  5853. return;
  5854. }
  5855. const state = window.history.state;
  5856. if (this._isValidState(state) && state.uid > 0) {
  5857. window.history.back();
  5858. }
  5859. }
  5860. forward() {
  5861. if (!this._initialized || this._popStateInProgress) {
  5862. return;
  5863. }
  5864. const state = window.history.state;
  5865. if (this._isValidState(state) && state.uid < this._maxUid) {
  5866. window.history.forward();
  5867. }
  5868. }
  5869. get popStateInProgress() {
  5870. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5871. }
  5872. get initialBookmark() {
  5873. return this._initialized ? this._initialBookmark : null;
  5874. }
  5875. get initialRotation() {
  5876. return this._initialized ? this._initialRotation : null;
  5877. }
  5878. _pushOrReplaceState(destination, forceReplace = false) {
  5879. const shouldReplace = forceReplace || !this._destination;
  5880. const newState = {
  5881. fingerprint: this._fingerprint,
  5882. uid: shouldReplace ? this._uid : this._uid + 1,
  5883. destination
  5884. };
  5885. this._updateInternalState(destination, newState.uid);
  5886. let newUrl;
  5887. if (this._updateUrl && destination?.hash) {
  5888. const baseUrl = document.location.href.split("#")[0];
  5889. if (!baseUrl.startsWith("file://")) {
  5890. newUrl = `${baseUrl}#${destination.hash}`;
  5891. }
  5892. }
  5893. if (shouldReplace) {
  5894. window.history.replaceState(newState, "", newUrl);
  5895. } else {
  5896. window.history.pushState(newState, "", newUrl);
  5897. }
  5898. }
  5899. _tryPushCurrentPosition(temporary = false) {
  5900. if (!this._position) {
  5901. return;
  5902. }
  5903. let position = this._position;
  5904. if (temporary) {
  5905. position = Object.assign(Object.create(null), this._position);
  5906. position.temporary = true;
  5907. }
  5908. if (!this._destination) {
  5909. this._pushOrReplaceState(position);
  5910. return;
  5911. }
  5912. if (this._destination.temporary) {
  5913. this._pushOrReplaceState(position, true);
  5914. return;
  5915. }
  5916. if (this._destination.hash === position.hash) {
  5917. return;
  5918. }
  5919. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5920. return;
  5921. }
  5922. let forceReplace = false;
  5923. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5924. if (this._destination.dest !== undefined || !this._destination.first) {
  5925. return;
  5926. }
  5927. forceReplace = true;
  5928. }
  5929. this._pushOrReplaceState(position, forceReplace);
  5930. }
  5931. _isValidPage(val) {
  5932. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5933. }
  5934. _isValidState(state, checkReload = false) {
  5935. if (!state) {
  5936. return false;
  5937. }
  5938. if (state.fingerprint !== this._fingerprint) {
  5939. if (checkReload) {
  5940. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5941. return false;
  5942. }
  5943. const [perfEntry] = performance.getEntriesByType("navigation");
  5944. if (perfEntry?.type !== "reload") {
  5945. return false;
  5946. }
  5947. } else {
  5948. return false;
  5949. }
  5950. }
  5951. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5952. return false;
  5953. }
  5954. if (state.destination === null || typeof state.destination !== "object") {
  5955. return false;
  5956. }
  5957. return true;
  5958. }
  5959. _updateInternalState(destination, uid, removeTemporary = false) {
  5960. if (this._updateViewareaTimeout) {
  5961. clearTimeout(this._updateViewareaTimeout);
  5962. this._updateViewareaTimeout = null;
  5963. }
  5964. if (removeTemporary && destination?.temporary) {
  5965. delete destination.temporary;
  5966. }
  5967. this._destination = destination;
  5968. this._uid = uid;
  5969. this._maxUid = Math.max(this._maxUid, uid);
  5970. this._numPositionUpdates = 0;
  5971. }
  5972. _parseCurrentHash(checkNameddest = false) {
  5973. const hash = unescape(getCurrentHash()).substring(1);
  5974. const params = (0, _ui_utils.parseQueryString)(hash);
  5975. const nameddest = params.get("nameddest") || "";
  5976. let page = params.get("page") | 0;
  5977. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5978. page = null;
  5979. }
  5980. return {
  5981. hash,
  5982. page,
  5983. rotation: this.linkService.rotation
  5984. };
  5985. }
  5986. _updateViewarea({
  5987. location
  5988. }) {
  5989. if (this._updateViewareaTimeout) {
  5990. clearTimeout(this._updateViewareaTimeout);
  5991. this._updateViewareaTimeout = null;
  5992. }
  5993. this._position = {
  5994. hash: location.pdfOpenParams.substring(1),
  5995. page: this.linkService.page,
  5996. first: location.pageNumber,
  5997. rotation: location.rotation
  5998. };
  5999. if (this._popStateInProgress) {
  6000. return;
  6001. }
  6002. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  6003. this._numPositionUpdates++;
  6004. }
  6005. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  6006. this._updateViewareaTimeout = setTimeout(() => {
  6007. if (!this._popStateInProgress) {
  6008. this._tryPushCurrentPosition(true);
  6009. }
  6010. this._updateViewareaTimeout = null;
  6011. }, UPDATE_VIEWAREA_TIMEOUT);
  6012. }
  6013. }
  6014. _popState({
  6015. state
  6016. }) {
  6017. const newHash = getCurrentHash(),
  6018. hashChanged = this._currentHash !== newHash;
  6019. this._currentHash = newHash;
  6020. if (!state) {
  6021. this._uid++;
  6022. const {
  6023. hash,
  6024. page,
  6025. rotation
  6026. } = this._parseCurrentHash();
  6027. this._pushOrReplaceState({
  6028. hash,
  6029. page,
  6030. rotation
  6031. }, true);
  6032. return;
  6033. }
  6034. if (!this._isValidState(state)) {
  6035. return;
  6036. }
  6037. this._popStateInProgress = true;
  6038. if (hashChanged) {
  6039. this._blockHashChange++;
  6040. (0, _event_utils.waitOnEventOrTimeout)({
  6041. target: window,
  6042. name: "hashchange",
  6043. delay: HASH_CHANGE_TIMEOUT
  6044. }).then(() => {
  6045. this._blockHashChange--;
  6046. });
  6047. }
  6048. const destination = state.destination;
  6049. this._updateInternalState(destination, state.uid, true);
  6050. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  6051. this.linkService.rotation = destination.rotation;
  6052. }
  6053. if (destination.dest) {
  6054. this.linkService.goToDestination(destination.dest);
  6055. } else if (destination.hash) {
  6056. this.linkService.setHash(destination.hash);
  6057. } else if (destination.page) {
  6058. this.linkService.page = destination.page;
  6059. }
  6060. Promise.resolve().then(() => {
  6061. this._popStateInProgress = false;
  6062. });
  6063. }
  6064. _pageHide() {
  6065. if (!this._destination || this._destination.temporary) {
  6066. this._tryPushCurrentPosition();
  6067. }
  6068. }
  6069. _bindEvents() {
  6070. if (this._boundEvents) {
  6071. return;
  6072. }
  6073. this._boundEvents = {
  6074. updateViewarea: this._updateViewarea.bind(this),
  6075. popState: this._popState.bind(this),
  6076. pageHide: this._pageHide.bind(this)
  6077. };
  6078. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  6079. window.addEventListener("popstate", this._boundEvents.popState);
  6080. window.addEventListener("pagehide", this._boundEvents.pageHide);
  6081. }
  6082. _unbindEvents() {
  6083. if (!this._boundEvents) {
  6084. return;
  6085. }
  6086. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  6087. window.removeEventListener("popstate", this._boundEvents.popState);
  6088. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  6089. this._boundEvents = null;
  6090. }
  6091. }
  6092. exports.PDFHistory = PDFHistory;
  6093. function isDestHashesEqual(destHash, pushHash) {
  6094. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  6095. return false;
  6096. }
  6097. if (destHash === pushHash) {
  6098. return true;
  6099. }
  6100. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  6101. if (nameddest === pushHash) {
  6102. return true;
  6103. }
  6104. return false;
  6105. }
  6106. function isDestArraysEqual(firstDest, secondDest) {
  6107. function isEntryEqual(first, second) {
  6108. if (typeof first !== typeof second) {
  6109. return false;
  6110. }
  6111. if (Array.isArray(first) || Array.isArray(second)) {
  6112. return false;
  6113. }
  6114. if (first !== null && typeof first === "object" && second !== null) {
  6115. if (Object.keys(first).length !== Object.keys(second).length) {
  6116. return false;
  6117. }
  6118. for (const key in first) {
  6119. if (!isEntryEqual(first[key], second[key])) {
  6120. return false;
  6121. }
  6122. }
  6123. return true;
  6124. }
  6125. return first === second || Number.isNaN(first) && Number.isNaN(second);
  6126. }
  6127. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  6128. return false;
  6129. }
  6130. if (firstDest.length !== secondDest.length) {
  6131. return false;
  6132. }
  6133. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  6134. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  6135. return false;
  6136. }
  6137. }
  6138. return true;
  6139. }
  6140. /***/ }),
  6141. /* 20 */
  6142. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6143. Object.defineProperty(exports, "__esModule", ({
  6144. value: true
  6145. }));
  6146. exports.PDFLayerViewer = void 0;
  6147. var _base_tree_viewer = __webpack_require__(12);
  6148. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  6149. constructor(options) {
  6150. super(options);
  6151. this.l10n = options.l10n;
  6152. this.eventBus._on("optionalcontentconfigchanged", evt => {
  6153. this.#updateLayers(evt.promise);
  6154. });
  6155. this.eventBus._on("resetlayers", () => {
  6156. this.#updateLayers();
  6157. });
  6158. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  6159. }
  6160. reset() {
  6161. super.reset();
  6162. this._optionalContentConfig = null;
  6163. this._optionalContentHash = null;
  6164. }
  6165. _dispatchEvent(layersCount) {
  6166. this.eventBus.dispatch("layersloaded", {
  6167. source: this,
  6168. layersCount
  6169. });
  6170. }
  6171. _bindLink(element, {
  6172. groupId,
  6173. input
  6174. }) {
  6175. const setVisibility = () => {
  6176. this._optionalContentConfig.setVisibility(groupId, input.checked);
  6177. this._optionalContentHash = this._optionalContentConfig.getHash();
  6178. this.eventBus.dispatch("optionalcontentconfig", {
  6179. source: this,
  6180. promise: Promise.resolve(this._optionalContentConfig)
  6181. });
  6182. };
  6183. element.onclick = evt => {
  6184. if (evt.target === input) {
  6185. setVisibility();
  6186. return true;
  6187. } else if (evt.target !== element) {
  6188. return true;
  6189. }
  6190. input.checked = !input.checked;
  6191. setVisibility();
  6192. return false;
  6193. };
  6194. }
  6195. async _setNestedName(element, {
  6196. name = null
  6197. }) {
  6198. if (typeof name === "string") {
  6199. element.textContent = this._normalizeTextContent(name);
  6200. return;
  6201. }
  6202. element.textContent = await this.l10n.get("additional_layers");
  6203. element.style.fontStyle = "italic";
  6204. }
  6205. _addToggleButton(div, {
  6206. name = null
  6207. }) {
  6208. super._addToggleButton(div, name === null);
  6209. }
  6210. _toggleAllTreeItems() {
  6211. if (!this._optionalContentConfig) {
  6212. return;
  6213. }
  6214. super._toggleAllTreeItems();
  6215. }
  6216. render({
  6217. optionalContentConfig,
  6218. pdfDocument
  6219. }) {
  6220. if (this._optionalContentConfig) {
  6221. this.reset();
  6222. }
  6223. this._optionalContentConfig = optionalContentConfig || null;
  6224. this._pdfDocument = pdfDocument || null;
  6225. const groups = optionalContentConfig?.getOrder();
  6226. if (!groups) {
  6227. this._dispatchEvent(0);
  6228. return;
  6229. }
  6230. this._optionalContentHash = optionalContentConfig.getHash();
  6231. const fragment = document.createDocumentFragment(),
  6232. queue = [{
  6233. parent: fragment,
  6234. groups
  6235. }];
  6236. let layersCount = 0,
  6237. hasAnyNesting = false;
  6238. while (queue.length > 0) {
  6239. const levelData = queue.shift();
  6240. for (const groupId of levelData.groups) {
  6241. const div = document.createElement("div");
  6242. div.className = "treeItem";
  6243. const element = document.createElement("a");
  6244. div.append(element);
  6245. if (typeof groupId === "object") {
  6246. hasAnyNesting = true;
  6247. this._addToggleButton(div, groupId);
  6248. this._setNestedName(element, groupId);
  6249. const itemsDiv = document.createElement("div");
  6250. itemsDiv.className = "treeItems";
  6251. div.append(itemsDiv);
  6252. queue.push({
  6253. parent: itemsDiv,
  6254. groups: groupId.order
  6255. });
  6256. } else {
  6257. const group = optionalContentConfig.getGroup(groupId);
  6258. const input = document.createElement("input");
  6259. this._bindLink(element, {
  6260. groupId,
  6261. input
  6262. });
  6263. input.type = "checkbox";
  6264. input.checked = group.visible;
  6265. const label = document.createElement("label");
  6266. label.textContent = this._normalizeTextContent(group.name);
  6267. label.append(input);
  6268. element.append(label);
  6269. layersCount++;
  6270. }
  6271. levelData.parent.append(div);
  6272. }
  6273. }
  6274. this._finishRendering(fragment, layersCount, hasAnyNesting);
  6275. }
  6276. async #updateLayers(promise = null) {
  6277. if (!this._optionalContentConfig) {
  6278. return;
  6279. }
  6280. const pdfDocument = this._pdfDocument;
  6281. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig());
  6282. if (pdfDocument !== this._pdfDocument) {
  6283. return;
  6284. }
  6285. if (promise) {
  6286. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  6287. return;
  6288. }
  6289. } else {
  6290. this.eventBus.dispatch("optionalcontentconfig", {
  6291. source: this,
  6292. promise: Promise.resolve(optionalContentConfig)
  6293. });
  6294. }
  6295. this.render({
  6296. optionalContentConfig,
  6297. pdfDocument: this._pdfDocument
  6298. });
  6299. }
  6300. }
  6301. exports.PDFLayerViewer = PDFLayerViewer;
  6302. /***/ }),
  6303. /* 21 */
  6304. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6305. Object.defineProperty(exports, "__esModule", ({
  6306. value: true
  6307. }));
  6308. exports.PDFOutlineViewer = void 0;
  6309. var _base_tree_viewer = __webpack_require__(12);
  6310. var _pdfjsLib = __webpack_require__(4);
  6311. var _ui_utils = __webpack_require__(3);
  6312. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  6313. constructor(options) {
  6314. super(options);
  6315. this.linkService = options.linkService;
  6316. this.downloadManager = options.downloadManager;
  6317. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6318. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6319. this.eventBus._on("pagechanging", evt => {
  6320. this._currentPageNumber = evt.pageNumber;
  6321. });
  6322. this.eventBus._on("pagesloaded", evt => {
  6323. this._isPagesLoaded = !!evt.pagesCount;
  6324. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6325. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6326. }
  6327. });
  6328. this.eventBus._on("sidebarviewchanged", evt => {
  6329. this._sidebarView = evt.view;
  6330. });
  6331. }
  6332. reset() {
  6333. super.reset();
  6334. this._outline = null;
  6335. this._pageNumberToDestHashCapability = null;
  6336. this._currentPageNumber = 1;
  6337. this._isPagesLoaded = null;
  6338. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6339. this._currentOutlineItemCapability.resolve(false);
  6340. }
  6341. this._currentOutlineItemCapability = null;
  6342. }
  6343. _dispatchEvent(outlineCount) {
  6344. this._currentOutlineItemCapability = new _pdfjsLib.PromiseCapability();
  6345. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  6346. this._currentOutlineItemCapability.resolve(false);
  6347. } else if (this._isPagesLoaded !== null) {
  6348. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6349. }
  6350. this.eventBus.dispatch("outlineloaded", {
  6351. source: this,
  6352. outlineCount,
  6353. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6354. });
  6355. }
  6356. _bindLink(element, {
  6357. url,
  6358. newWindow,
  6359. action,
  6360. attachment,
  6361. dest,
  6362. setOCGState
  6363. }) {
  6364. const {
  6365. linkService
  6366. } = this;
  6367. if (url) {
  6368. linkService.addLinkAttributes(element, url, newWindow);
  6369. return;
  6370. }
  6371. if (action) {
  6372. element.href = linkService.getAnchorUrl("");
  6373. element.onclick = () => {
  6374. linkService.executeNamedAction(action);
  6375. return false;
  6376. };
  6377. return;
  6378. }
  6379. if (attachment) {
  6380. element.href = linkService.getAnchorUrl("");
  6381. element.onclick = () => {
  6382. this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename);
  6383. return false;
  6384. };
  6385. return;
  6386. }
  6387. if (setOCGState) {
  6388. element.href = linkService.getAnchorUrl("");
  6389. element.onclick = () => {
  6390. linkService.executeSetOCGState(setOCGState);
  6391. return false;
  6392. };
  6393. return;
  6394. }
  6395. element.href = linkService.getDestinationHash(dest);
  6396. element.onclick = evt => {
  6397. this._updateCurrentTreeItem(evt.target.parentNode);
  6398. if (dest) {
  6399. linkService.goToDestination(dest);
  6400. }
  6401. return false;
  6402. };
  6403. }
  6404. _setStyles(element, {
  6405. bold,
  6406. italic
  6407. }) {
  6408. if (bold) {
  6409. element.style.fontWeight = "bold";
  6410. }
  6411. if (italic) {
  6412. element.style.fontStyle = "italic";
  6413. }
  6414. }
  6415. _addToggleButton(div, {
  6416. count,
  6417. items
  6418. }) {
  6419. let hidden = false;
  6420. if (count < 0) {
  6421. let totalCount = items.length;
  6422. if (totalCount > 0) {
  6423. const queue = [...items];
  6424. while (queue.length > 0) {
  6425. const {
  6426. count: nestedCount,
  6427. items: nestedItems
  6428. } = queue.shift();
  6429. if (nestedCount > 0 && nestedItems.length > 0) {
  6430. totalCount += nestedItems.length;
  6431. queue.push(...nestedItems);
  6432. }
  6433. }
  6434. }
  6435. if (Math.abs(count) === totalCount) {
  6436. hidden = true;
  6437. }
  6438. }
  6439. super._addToggleButton(div, hidden);
  6440. }
  6441. _toggleAllTreeItems() {
  6442. if (!this._outline) {
  6443. return;
  6444. }
  6445. super._toggleAllTreeItems();
  6446. }
  6447. render({
  6448. outline,
  6449. pdfDocument
  6450. }) {
  6451. if (this._outline) {
  6452. this.reset();
  6453. }
  6454. this._outline = outline || null;
  6455. this._pdfDocument = pdfDocument || null;
  6456. if (!outline) {
  6457. this._dispatchEvent(0);
  6458. return;
  6459. }
  6460. const fragment = document.createDocumentFragment();
  6461. const queue = [{
  6462. parent: fragment,
  6463. items: outline
  6464. }];
  6465. let outlineCount = 0,
  6466. hasAnyNesting = false;
  6467. while (queue.length > 0) {
  6468. const levelData = queue.shift();
  6469. for (const item of levelData.items) {
  6470. const div = document.createElement("div");
  6471. div.className = "treeItem";
  6472. const element = document.createElement("a");
  6473. this._bindLink(element, item);
  6474. this._setStyles(element, item);
  6475. element.textContent = this._normalizeTextContent(item.title);
  6476. div.append(element);
  6477. if (item.items.length > 0) {
  6478. hasAnyNesting = true;
  6479. this._addToggleButton(div, item);
  6480. const itemsDiv = document.createElement("div");
  6481. itemsDiv.className = "treeItems";
  6482. div.append(itemsDiv);
  6483. queue.push({
  6484. parent: itemsDiv,
  6485. items: item.items
  6486. });
  6487. }
  6488. levelData.parent.append(div);
  6489. outlineCount++;
  6490. }
  6491. }
  6492. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6493. }
  6494. async _currentOutlineItem() {
  6495. if (!this._isPagesLoaded) {
  6496. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6497. }
  6498. if (!this._outline || !this._pdfDocument) {
  6499. return;
  6500. }
  6501. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6502. if (!pageNumberToDestHash) {
  6503. return;
  6504. }
  6505. this._updateCurrentTreeItem(null);
  6506. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6507. return;
  6508. }
  6509. for (let i = this._currentPageNumber; i > 0; i--) {
  6510. const destHash = pageNumberToDestHash.get(i);
  6511. if (!destHash) {
  6512. continue;
  6513. }
  6514. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6515. if (!linkElement) {
  6516. continue;
  6517. }
  6518. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6519. break;
  6520. }
  6521. }
  6522. async _getPageNumberToDestHash(pdfDocument) {
  6523. if (this._pageNumberToDestHashCapability) {
  6524. return this._pageNumberToDestHashCapability.promise;
  6525. }
  6526. this._pageNumberToDestHashCapability = new _pdfjsLib.PromiseCapability();
  6527. const pageNumberToDestHash = new Map(),
  6528. pageNumberNesting = new Map();
  6529. const queue = [{
  6530. nesting: 0,
  6531. items: this._outline
  6532. }];
  6533. while (queue.length > 0) {
  6534. const levelData = queue.shift(),
  6535. currentNesting = levelData.nesting;
  6536. for (const {
  6537. dest,
  6538. items
  6539. } of levelData.items) {
  6540. let explicitDest, pageNumber;
  6541. if (typeof dest === "string") {
  6542. explicitDest = await pdfDocument.getDestination(dest);
  6543. if (pdfDocument !== this._pdfDocument) {
  6544. return null;
  6545. }
  6546. } else {
  6547. explicitDest = dest;
  6548. }
  6549. if (Array.isArray(explicitDest)) {
  6550. const [destRef] = explicitDest;
  6551. if (typeof destRef === "object" && destRef !== null) {
  6552. pageNumber = this.linkService._cachedPageNumber(destRef);
  6553. if (!pageNumber) {
  6554. try {
  6555. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6556. if (pdfDocument !== this._pdfDocument) {
  6557. return null;
  6558. }
  6559. this.linkService.cachePageRef(pageNumber, destRef);
  6560. } catch (ex) {}
  6561. }
  6562. } else if (Number.isInteger(destRef)) {
  6563. pageNumber = destRef + 1;
  6564. }
  6565. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6566. const destHash = this.linkService.getDestinationHash(dest);
  6567. pageNumberToDestHash.set(pageNumber, destHash);
  6568. pageNumberNesting.set(pageNumber, currentNesting);
  6569. }
  6570. }
  6571. if (items.length > 0) {
  6572. queue.push({
  6573. nesting: currentNesting + 1,
  6574. items
  6575. });
  6576. }
  6577. }
  6578. }
  6579. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6580. return this._pageNumberToDestHashCapability.promise;
  6581. }
  6582. }
  6583. exports.PDFOutlineViewer = PDFOutlineViewer;
  6584. /***/ }),
  6585. /* 22 */
  6586. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6587. Object.defineProperty(exports, "__esModule", ({
  6588. value: true
  6589. }));
  6590. exports.PDFPresentationMode = void 0;
  6591. var _ui_utils = __webpack_require__(3);
  6592. var _pdfjsLib = __webpack_require__(4);
  6593. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6594. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6595. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6596. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6597. const PAGE_SWITCH_THRESHOLD = 0.1;
  6598. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6599. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6600. class PDFPresentationMode {
  6601. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6602. #args = null;
  6603. constructor({
  6604. container,
  6605. pdfViewer,
  6606. eventBus
  6607. }) {
  6608. this.container = container;
  6609. this.pdfViewer = pdfViewer;
  6610. this.eventBus = eventBus;
  6611. this.contextMenuOpen = false;
  6612. this.mouseScrollTimeStamp = 0;
  6613. this.mouseScrollDelta = 0;
  6614. this.touchSwipeState = null;
  6615. }
  6616. async request() {
  6617. const {
  6618. container,
  6619. pdfViewer
  6620. } = this;
  6621. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6622. return false;
  6623. }
  6624. this.#addFullscreenChangeListeners();
  6625. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6626. const promise = container.requestFullscreen();
  6627. this.#args = {
  6628. pageNumber: pdfViewer.currentPageNumber,
  6629. scaleValue: pdfViewer.currentScaleValue,
  6630. scrollMode: pdfViewer.scrollMode,
  6631. spreadMode: null,
  6632. annotationEditorMode: null
  6633. };
  6634. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6635. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6636. this.#args.spreadMode = pdfViewer.spreadMode;
  6637. }
  6638. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6639. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6640. }
  6641. try {
  6642. await promise;
  6643. pdfViewer.focus();
  6644. return true;
  6645. } catch (reason) {
  6646. this.#removeFullscreenChangeListeners();
  6647. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6648. }
  6649. return false;
  6650. }
  6651. get active() {
  6652. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6653. }
  6654. #mouseWheel(evt) {
  6655. if (!this.active) {
  6656. return;
  6657. }
  6658. evt.preventDefault();
  6659. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6660. const currentTime = Date.now();
  6661. const storedTime = this.mouseScrollTimeStamp;
  6662. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6663. return;
  6664. }
  6665. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6666. this.#resetMouseScrollState();
  6667. }
  6668. this.mouseScrollDelta += delta;
  6669. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6670. const totalDelta = this.mouseScrollDelta;
  6671. this.#resetMouseScrollState();
  6672. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6673. if (success) {
  6674. this.mouseScrollTimeStamp = currentTime;
  6675. }
  6676. }
  6677. }
  6678. #notifyStateChange(state) {
  6679. this.#state = state;
  6680. this.eventBus.dispatch("presentationmodechanged", {
  6681. source: this,
  6682. state
  6683. });
  6684. }
  6685. #enter() {
  6686. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6687. this.container.classList.add(ACTIVE_SELECTOR);
  6688. setTimeout(() => {
  6689. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6690. if (this.#args.spreadMode !== null) {
  6691. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6692. }
  6693. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6694. this.pdfViewer.currentScaleValue = "page-fit";
  6695. if (this.#args.annotationEditorMode !== null) {
  6696. this.pdfViewer.annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  6697. }
  6698. }, 0);
  6699. this.#addWindowListeners();
  6700. this.#showControls();
  6701. this.contextMenuOpen = false;
  6702. window.getSelection().removeAllRanges();
  6703. }
  6704. #exit() {
  6705. const pageNumber = this.pdfViewer.currentPageNumber;
  6706. this.container.classList.remove(ACTIVE_SELECTOR);
  6707. setTimeout(() => {
  6708. this.#removeFullscreenChangeListeners();
  6709. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6710. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6711. if (this.#args.spreadMode !== null) {
  6712. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6713. }
  6714. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6715. this.pdfViewer.currentPageNumber = pageNumber;
  6716. if (this.#args.annotationEditorMode !== null) {
  6717. this.pdfViewer.annotationEditorMode = this.#args.annotationEditorMode;
  6718. }
  6719. this.#args = null;
  6720. }, 0);
  6721. this.#removeWindowListeners();
  6722. this.#hideControls();
  6723. this.#resetMouseScrollState();
  6724. this.contextMenuOpen = false;
  6725. }
  6726. #mouseDown(evt) {
  6727. if (this.contextMenuOpen) {
  6728. this.contextMenuOpen = false;
  6729. evt.preventDefault();
  6730. return;
  6731. }
  6732. if (evt.button !== 0) {
  6733. return;
  6734. }
  6735. if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) {
  6736. return;
  6737. }
  6738. evt.preventDefault();
  6739. if (evt.shiftKey) {
  6740. this.pdfViewer.previousPage();
  6741. } else {
  6742. this.pdfViewer.nextPage();
  6743. }
  6744. }
  6745. #contextMenu() {
  6746. this.contextMenuOpen = true;
  6747. }
  6748. #showControls() {
  6749. if (this.controlsTimeout) {
  6750. clearTimeout(this.controlsTimeout);
  6751. } else {
  6752. this.container.classList.add(CONTROLS_SELECTOR);
  6753. }
  6754. this.controlsTimeout = setTimeout(() => {
  6755. this.container.classList.remove(CONTROLS_SELECTOR);
  6756. delete this.controlsTimeout;
  6757. }, DELAY_BEFORE_HIDING_CONTROLS);
  6758. }
  6759. #hideControls() {
  6760. if (!this.controlsTimeout) {
  6761. return;
  6762. }
  6763. clearTimeout(this.controlsTimeout);
  6764. this.container.classList.remove(CONTROLS_SELECTOR);
  6765. delete this.controlsTimeout;
  6766. }
  6767. #resetMouseScrollState() {
  6768. this.mouseScrollTimeStamp = 0;
  6769. this.mouseScrollDelta = 0;
  6770. }
  6771. #touchSwipe(evt) {
  6772. if (!this.active) {
  6773. return;
  6774. }
  6775. if (evt.touches.length > 1) {
  6776. this.touchSwipeState = null;
  6777. return;
  6778. }
  6779. switch (evt.type) {
  6780. case "touchstart":
  6781. this.touchSwipeState = {
  6782. startX: evt.touches[0].pageX,
  6783. startY: evt.touches[0].pageY,
  6784. endX: evt.touches[0].pageX,
  6785. endY: evt.touches[0].pageY
  6786. };
  6787. break;
  6788. case "touchmove":
  6789. if (this.touchSwipeState === null) {
  6790. return;
  6791. }
  6792. this.touchSwipeState.endX = evt.touches[0].pageX;
  6793. this.touchSwipeState.endY = evt.touches[0].pageY;
  6794. evt.preventDefault();
  6795. break;
  6796. case "touchend":
  6797. if (this.touchSwipeState === null) {
  6798. return;
  6799. }
  6800. let delta = 0;
  6801. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6802. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6803. const absAngle = Math.abs(Math.atan2(dy, dx));
  6804. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6805. delta = dx;
  6806. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6807. delta = dy;
  6808. }
  6809. if (delta > 0) {
  6810. this.pdfViewer.previousPage();
  6811. } else if (delta < 0) {
  6812. this.pdfViewer.nextPage();
  6813. }
  6814. break;
  6815. }
  6816. }
  6817. #addWindowListeners() {
  6818. this.showControlsBind = this.#showControls.bind(this);
  6819. this.mouseDownBind = this.#mouseDown.bind(this);
  6820. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6821. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6822. this.contextMenuBind = this.#contextMenu.bind(this);
  6823. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6824. window.addEventListener("mousemove", this.showControlsBind);
  6825. window.addEventListener("mousedown", this.mouseDownBind);
  6826. window.addEventListener("wheel", this.mouseWheelBind, {
  6827. passive: false
  6828. });
  6829. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6830. window.addEventListener("contextmenu", this.contextMenuBind);
  6831. window.addEventListener("touchstart", this.touchSwipeBind);
  6832. window.addEventListener("touchmove", this.touchSwipeBind);
  6833. window.addEventListener("touchend", this.touchSwipeBind);
  6834. }
  6835. #removeWindowListeners() {
  6836. window.removeEventListener("mousemove", this.showControlsBind);
  6837. window.removeEventListener("mousedown", this.mouseDownBind);
  6838. window.removeEventListener("wheel", this.mouseWheelBind, {
  6839. passive: false
  6840. });
  6841. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6842. window.removeEventListener("contextmenu", this.contextMenuBind);
  6843. window.removeEventListener("touchstart", this.touchSwipeBind);
  6844. window.removeEventListener("touchmove", this.touchSwipeBind);
  6845. window.removeEventListener("touchend", this.touchSwipeBind);
  6846. delete this.showControlsBind;
  6847. delete this.mouseDownBind;
  6848. delete this.mouseWheelBind;
  6849. delete this.resetMouseScrollStateBind;
  6850. delete this.contextMenuBind;
  6851. delete this.touchSwipeBind;
  6852. }
  6853. #fullscreenChange() {
  6854. if (document.fullscreenElement) {
  6855. this.#enter();
  6856. } else {
  6857. this.#exit();
  6858. }
  6859. }
  6860. #addFullscreenChangeListeners() {
  6861. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6862. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6863. }
  6864. #removeFullscreenChangeListeners() {
  6865. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6866. delete this.fullscreenChangeBind;
  6867. }
  6868. }
  6869. exports.PDFPresentationMode = PDFPresentationMode;
  6870. /***/ }),
  6871. /* 23 */
  6872. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6873. Object.defineProperty(exports, "__esModule", ({
  6874. value: true
  6875. }));
  6876. exports.PDFRenderingQueue = void 0;
  6877. var _pdfjsLib = __webpack_require__(4);
  6878. var _ui_utils = __webpack_require__(3);
  6879. const CLEANUP_TIMEOUT = 30000;
  6880. class PDFRenderingQueue {
  6881. constructor() {
  6882. this.pdfViewer = null;
  6883. this.pdfThumbnailViewer = null;
  6884. this.onIdle = null;
  6885. this.highestPriorityPage = null;
  6886. this.idleTimeout = null;
  6887. this.printing = false;
  6888. this.isThumbnailViewEnabled = false;
  6889. }
  6890. setViewer(pdfViewer) {
  6891. this.pdfViewer = pdfViewer;
  6892. }
  6893. setThumbnailViewer(pdfThumbnailViewer) {
  6894. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6895. }
  6896. isHighestPriority(view) {
  6897. return this.highestPriorityPage === view.renderingId;
  6898. }
  6899. hasViewer() {
  6900. return !!this.pdfViewer;
  6901. }
  6902. renderHighestPriority(currentlyVisiblePages) {
  6903. if (this.idleTimeout) {
  6904. clearTimeout(this.idleTimeout);
  6905. this.idleTimeout = null;
  6906. }
  6907. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6908. return;
  6909. }
  6910. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6911. return;
  6912. }
  6913. if (this.printing) {
  6914. return;
  6915. }
  6916. if (this.onIdle) {
  6917. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6918. }
  6919. }
  6920. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6921. const visibleViews = visible.views,
  6922. numVisible = visibleViews.length;
  6923. if (numVisible === 0) {
  6924. return null;
  6925. }
  6926. for (let i = 0; i < numVisible; i++) {
  6927. const view = visibleViews[i].view;
  6928. if (!this.isViewFinished(view)) {
  6929. return view;
  6930. }
  6931. }
  6932. const firstId = visible.first.id,
  6933. lastId = visible.last.id;
  6934. if (lastId - firstId + 1 > numVisible) {
  6935. const visibleIds = visible.ids;
  6936. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6937. const holeId = scrolledDown ? firstId + i : lastId - i;
  6938. if (visibleIds.has(holeId)) {
  6939. continue;
  6940. }
  6941. const holeView = views[holeId - 1];
  6942. if (!this.isViewFinished(holeView)) {
  6943. return holeView;
  6944. }
  6945. }
  6946. }
  6947. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6948. let preRenderView = views[preRenderIndex];
  6949. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6950. return preRenderView;
  6951. }
  6952. if (preRenderExtra) {
  6953. preRenderIndex += scrolledDown ? 1 : -1;
  6954. preRenderView = views[preRenderIndex];
  6955. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6956. return preRenderView;
  6957. }
  6958. }
  6959. return null;
  6960. }
  6961. isViewFinished(view) {
  6962. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6963. }
  6964. renderView(view) {
  6965. switch (view.renderingState) {
  6966. case _ui_utils.RenderingStates.FINISHED:
  6967. return false;
  6968. case _ui_utils.RenderingStates.PAUSED:
  6969. this.highestPriorityPage = view.renderingId;
  6970. view.resume();
  6971. break;
  6972. case _ui_utils.RenderingStates.RUNNING:
  6973. this.highestPriorityPage = view.renderingId;
  6974. break;
  6975. case _ui_utils.RenderingStates.INITIAL:
  6976. this.highestPriorityPage = view.renderingId;
  6977. view.draw().finally(() => {
  6978. this.renderHighestPriority();
  6979. }).catch(reason => {
  6980. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6981. return;
  6982. }
  6983. console.error(`renderView: "${reason}"`);
  6984. });
  6985. break;
  6986. }
  6987. return true;
  6988. }
  6989. }
  6990. exports.PDFRenderingQueue = PDFRenderingQueue;
  6991. /***/ }),
  6992. /* 24 */
  6993. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6994. Object.defineProperty(exports, "__esModule", ({
  6995. value: true
  6996. }));
  6997. exports.PDFScriptingManager = void 0;
  6998. var _ui_utils = __webpack_require__(3);
  6999. var _pdfjsLib = __webpack_require__(4);
  7000. class PDFScriptingManager {
  7001. constructor({
  7002. eventBus,
  7003. sandboxBundleSrc = null,
  7004. scriptingFactory = null,
  7005. docPropertiesLookup = null
  7006. }) {
  7007. this._pdfDocument = null;
  7008. this._pdfViewer = null;
  7009. this._closeCapability = null;
  7010. this._destroyCapability = null;
  7011. this._scripting = null;
  7012. this._ready = false;
  7013. this._eventBus = eventBus;
  7014. this._sandboxBundleSrc = sandboxBundleSrc;
  7015. this._scriptingFactory = scriptingFactory;
  7016. this._docPropertiesLookup = docPropertiesLookup;
  7017. }
  7018. setViewer(pdfViewer) {
  7019. this._pdfViewer = pdfViewer;
  7020. }
  7021. async setDocument(pdfDocument) {
  7022. if (this._pdfDocument) {
  7023. await this._destroyScripting();
  7024. }
  7025. this._pdfDocument = pdfDocument;
  7026. if (!pdfDocument) {
  7027. return;
  7028. }
  7029. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  7030. if (!objects && !docActions) {
  7031. await this._destroyScripting();
  7032. return;
  7033. }
  7034. if (pdfDocument !== this._pdfDocument) {
  7035. return;
  7036. }
  7037. try {
  7038. this._scripting = this._createScripting();
  7039. } catch (error) {
  7040. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  7041. await this._destroyScripting();
  7042. return;
  7043. }
  7044. this._internalEvents.set("updatefromsandbox", event => {
  7045. if (event?.source !== window) {
  7046. return;
  7047. }
  7048. this._updateFromSandbox(event.detail);
  7049. });
  7050. this._internalEvents.set("dispatcheventinsandbox", event => {
  7051. this._scripting?.dispatchEventInSandbox(event.detail);
  7052. });
  7053. this._internalEvents.set("pagechanging", ({
  7054. pageNumber,
  7055. previous
  7056. }) => {
  7057. if (pageNumber === previous) {
  7058. return;
  7059. }
  7060. this._dispatchPageClose(previous);
  7061. this._dispatchPageOpen(pageNumber);
  7062. });
  7063. this._internalEvents.set("pagerendered", ({
  7064. pageNumber
  7065. }) => {
  7066. if (!this._pageOpenPending.has(pageNumber)) {
  7067. return;
  7068. }
  7069. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  7070. return;
  7071. }
  7072. this._dispatchPageOpen(pageNumber);
  7073. });
  7074. this._internalEvents.set("pagesdestroy", async event => {
  7075. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  7076. await this._scripting?.dispatchEventInSandbox({
  7077. id: "doc",
  7078. name: "WillClose"
  7079. });
  7080. this._closeCapability?.resolve();
  7081. });
  7082. for (const [name, listener] of this._internalEvents) {
  7083. this._eventBus._on(name, listener);
  7084. }
  7085. try {
  7086. const docProperties = await this._getDocProperties();
  7087. if (pdfDocument !== this._pdfDocument) {
  7088. return;
  7089. }
  7090. await this._scripting.createSandbox({
  7091. objects,
  7092. calculationOrder,
  7093. appInfo: {
  7094. platform: navigator.platform,
  7095. language: navigator.language
  7096. },
  7097. docInfo: {
  7098. ...docProperties,
  7099. actions: docActions
  7100. }
  7101. });
  7102. this._eventBus.dispatch("sandboxcreated", {
  7103. source: this
  7104. });
  7105. } catch (error) {
  7106. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  7107. await this._destroyScripting();
  7108. return;
  7109. }
  7110. await this._scripting?.dispatchEventInSandbox({
  7111. id: "doc",
  7112. name: "Open"
  7113. });
  7114. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  7115. Promise.resolve().then(() => {
  7116. if (pdfDocument === this._pdfDocument) {
  7117. this._ready = true;
  7118. }
  7119. });
  7120. }
  7121. async dispatchWillSave(detail) {
  7122. return this._scripting?.dispatchEventInSandbox({
  7123. id: "doc",
  7124. name: "WillSave"
  7125. });
  7126. }
  7127. async dispatchDidSave(detail) {
  7128. return this._scripting?.dispatchEventInSandbox({
  7129. id: "doc",
  7130. name: "DidSave"
  7131. });
  7132. }
  7133. async dispatchWillPrint(detail) {
  7134. return this._scripting?.dispatchEventInSandbox({
  7135. id: "doc",
  7136. name: "WillPrint"
  7137. });
  7138. }
  7139. async dispatchDidPrint(detail) {
  7140. return this._scripting?.dispatchEventInSandbox({
  7141. id: "doc",
  7142. name: "DidPrint"
  7143. });
  7144. }
  7145. get destroyPromise() {
  7146. return this._destroyCapability?.promise || null;
  7147. }
  7148. get ready() {
  7149. return this._ready;
  7150. }
  7151. get _internalEvents() {
  7152. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  7153. }
  7154. get _pageOpenPending() {
  7155. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  7156. }
  7157. get _visitedPages() {
  7158. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  7159. }
  7160. async _updateFromSandbox(detail) {
  7161. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  7162. const {
  7163. id,
  7164. siblings,
  7165. command,
  7166. value
  7167. } = detail;
  7168. if (!id) {
  7169. switch (command) {
  7170. case "clear":
  7171. console.clear();
  7172. break;
  7173. case "error":
  7174. console.error(value);
  7175. break;
  7176. case "layout":
  7177. {
  7178. if (isInPresentationMode) {
  7179. return;
  7180. }
  7181. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  7182. this._pdfViewer.spreadMode = modes.spreadMode;
  7183. break;
  7184. }
  7185. case "page-num":
  7186. this._pdfViewer.currentPageNumber = value + 1;
  7187. break;
  7188. case "print":
  7189. await this._pdfViewer.pagesPromise;
  7190. this._eventBus.dispatch("print", {
  7191. source: this
  7192. });
  7193. break;
  7194. case "println":
  7195. console.log(value);
  7196. break;
  7197. case "zoom":
  7198. if (isInPresentationMode) {
  7199. return;
  7200. }
  7201. this._pdfViewer.currentScaleValue = value;
  7202. break;
  7203. case "SaveAs":
  7204. this._eventBus.dispatch("download", {
  7205. source: this
  7206. });
  7207. break;
  7208. case "FirstPage":
  7209. this._pdfViewer.currentPageNumber = 1;
  7210. break;
  7211. case "LastPage":
  7212. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  7213. break;
  7214. case "NextPage":
  7215. this._pdfViewer.nextPage();
  7216. break;
  7217. case "PrevPage":
  7218. this._pdfViewer.previousPage();
  7219. break;
  7220. case "ZoomViewIn":
  7221. if (isInPresentationMode) {
  7222. return;
  7223. }
  7224. this._pdfViewer.increaseScale();
  7225. break;
  7226. case "ZoomViewOut":
  7227. if (isInPresentationMode) {
  7228. return;
  7229. }
  7230. this._pdfViewer.decreaseScale();
  7231. break;
  7232. }
  7233. return;
  7234. }
  7235. if (isInPresentationMode) {
  7236. if (detail.focus) {
  7237. return;
  7238. }
  7239. }
  7240. delete detail.id;
  7241. delete detail.siblings;
  7242. const ids = siblings ? [id, ...siblings] : [id];
  7243. for (const elementId of ids) {
  7244. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  7245. if (element) {
  7246. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  7247. detail
  7248. }));
  7249. } else {
  7250. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  7251. }
  7252. }
  7253. }
  7254. async _dispatchPageOpen(pageNumber, initialize = false) {
  7255. const pdfDocument = this._pdfDocument,
  7256. visitedPages = this._visitedPages;
  7257. if (initialize) {
  7258. this._closeCapability = new _pdfjsLib.PromiseCapability();
  7259. }
  7260. if (!this._closeCapability) {
  7261. return;
  7262. }
  7263. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  7264. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7265. this._pageOpenPending.add(pageNumber);
  7266. return;
  7267. }
  7268. this._pageOpenPending.delete(pageNumber);
  7269. const actionsPromise = (async () => {
  7270. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  7271. if (pdfDocument !== this._pdfDocument) {
  7272. return;
  7273. }
  7274. await this._scripting?.dispatchEventInSandbox({
  7275. id: "page",
  7276. name: "PageOpen",
  7277. pageNumber,
  7278. actions
  7279. });
  7280. })();
  7281. visitedPages.set(pageNumber, actionsPromise);
  7282. }
  7283. async _dispatchPageClose(pageNumber) {
  7284. const pdfDocument = this._pdfDocument,
  7285. visitedPages = this._visitedPages;
  7286. if (!this._closeCapability) {
  7287. return;
  7288. }
  7289. if (this._pageOpenPending.has(pageNumber)) {
  7290. return;
  7291. }
  7292. const actionsPromise = visitedPages.get(pageNumber);
  7293. if (!actionsPromise) {
  7294. return;
  7295. }
  7296. visitedPages.set(pageNumber, null);
  7297. await actionsPromise;
  7298. if (pdfDocument !== this._pdfDocument) {
  7299. return;
  7300. }
  7301. await this._scripting?.dispatchEventInSandbox({
  7302. id: "page",
  7303. name: "PageClose",
  7304. pageNumber
  7305. });
  7306. }
  7307. async _getDocProperties() {
  7308. if (this._docPropertiesLookup) {
  7309. return this._docPropertiesLookup(this._pdfDocument);
  7310. }
  7311. throw new Error("_getDocProperties: Unable to lookup properties.");
  7312. }
  7313. _createScripting() {
  7314. this._destroyCapability = new _pdfjsLib.PromiseCapability();
  7315. if (this._scripting) {
  7316. throw new Error("_createScripting: Scripting already exists.");
  7317. }
  7318. if (this._scriptingFactory) {
  7319. return this._scriptingFactory.createScripting({
  7320. sandboxBundleSrc: this._sandboxBundleSrc
  7321. });
  7322. }
  7323. throw new Error("_createScripting: Cannot create scripting.");
  7324. }
  7325. async _destroyScripting() {
  7326. if (!this._scripting) {
  7327. this._pdfDocument = null;
  7328. this._destroyCapability?.resolve();
  7329. return;
  7330. }
  7331. if (this._closeCapability) {
  7332. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  7333. setTimeout(resolve, 1000);
  7334. })]).catch(reason => {});
  7335. this._closeCapability = null;
  7336. }
  7337. this._pdfDocument = null;
  7338. try {
  7339. await this._scripting.destroySandbox();
  7340. } catch (ex) {}
  7341. for (const [name, listener] of this._internalEvents) {
  7342. this._eventBus._off(name, listener);
  7343. }
  7344. this._internalEvents.clear();
  7345. this._pageOpenPending.clear();
  7346. this._visitedPages.clear();
  7347. this._scripting = null;
  7348. this._ready = false;
  7349. this._destroyCapability?.resolve();
  7350. }
  7351. }
  7352. exports.PDFScriptingManager = PDFScriptingManager;
  7353. /***/ }),
  7354. /* 25 */
  7355. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7356. Object.defineProperty(exports, "__esModule", ({
  7357. value: true
  7358. }));
  7359. exports.PDFSidebar = void 0;
  7360. var _ui_utils = __webpack_require__(3);
  7361. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7362. const SIDEBAR_MIN_WIDTH = 200;
  7363. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7364. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7365. class PDFSidebar {
  7366. #isRTL = false;
  7367. #mouseMoveBound = this.#mouseMove.bind(this);
  7368. #mouseUpBound = this.#mouseUp.bind(this);
  7369. #outerContainerWidth = null;
  7370. #width = null;
  7371. constructor({
  7372. elements,
  7373. eventBus,
  7374. l10n
  7375. }) {
  7376. this.isOpen = false;
  7377. this.active = _ui_utils.SidebarView.THUMBS;
  7378. this.isInitialViewSet = false;
  7379. this.isInitialEventDispatched = false;
  7380. this.onToggled = null;
  7381. this.onUpdateThumbnails = null;
  7382. this.outerContainer = elements.outerContainer;
  7383. this.sidebarContainer = elements.sidebarContainer;
  7384. this.toggleButton = elements.toggleButton;
  7385. this.resizer = elements.resizer;
  7386. this.thumbnailButton = elements.thumbnailButton;
  7387. this.outlineButton = elements.outlineButton;
  7388. this.attachmentsButton = elements.attachmentsButton;
  7389. this.layersButton = elements.layersButton;
  7390. this.thumbnailView = elements.thumbnailView;
  7391. this.outlineView = elements.outlineView;
  7392. this.attachmentsView = elements.attachmentsView;
  7393. this.layersView = elements.layersView;
  7394. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  7395. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7396. this.eventBus = eventBus;
  7397. this.l10n = l10n;
  7398. l10n.getDirection().then(dir => {
  7399. this.#isRTL = dir === "rtl";
  7400. });
  7401. this.#addEventListeners();
  7402. }
  7403. reset() {
  7404. this.isInitialViewSet = false;
  7405. this.isInitialEventDispatched = false;
  7406. this.#hideUINotification(true);
  7407. this.switchView(_ui_utils.SidebarView.THUMBS);
  7408. this.outlineButton.disabled = false;
  7409. this.attachmentsButton.disabled = false;
  7410. this.layersButton.disabled = false;
  7411. this._currentOutlineItemButton.disabled = true;
  7412. }
  7413. get visibleView() {
  7414. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  7415. }
  7416. setInitialView(view = _ui_utils.SidebarView.NONE) {
  7417. if (this.isInitialViewSet) {
  7418. return;
  7419. }
  7420. this.isInitialViewSet = true;
  7421. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  7422. this.#dispatchEvent();
  7423. return;
  7424. }
  7425. this.switchView(view, true);
  7426. if (!this.isInitialEventDispatched) {
  7427. this.#dispatchEvent();
  7428. }
  7429. }
  7430. switchView(view, forceOpen = false) {
  7431. const isViewChanged = view !== this.active;
  7432. let forceRendering = false;
  7433. switch (view) {
  7434. case _ui_utils.SidebarView.NONE:
  7435. if (this.isOpen) {
  7436. this.close();
  7437. }
  7438. return;
  7439. case _ui_utils.SidebarView.THUMBS:
  7440. if (this.isOpen && isViewChanged) {
  7441. forceRendering = true;
  7442. }
  7443. break;
  7444. case _ui_utils.SidebarView.OUTLINE:
  7445. if (this.outlineButton.disabled) {
  7446. return;
  7447. }
  7448. break;
  7449. case _ui_utils.SidebarView.ATTACHMENTS:
  7450. if (this.attachmentsButton.disabled) {
  7451. return;
  7452. }
  7453. break;
  7454. case _ui_utils.SidebarView.LAYERS:
  7455. if (this.layersButton.disabled) {
  7456. return;
  7457. }
  7458. break;
  7459. default:
  7460. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7461. return;
  7462. }
  7463. this.active = view;
  7464. (0, _ui_utils.toggleCheckedBtn)(this.thumbnailButton, view === _ui_utils.SidebarView.THUMBS, this.thumbnailView);
  7465. (0, _ui_utils.toggleCheckedBtn)(this.outlineButton, view === _ui_utils.SidebarView.OUTLINE, this.outlineView);
  7466. (0, _ui_utils.toggleCheckedBtn)(this.attachmentsButton, view === _ui_utils.SidebarView.ATTACHMENTS, this.attachmentsView);
  7467. (0, _ui_utils.toggleCheckedBtn)(this.layersButton, view === _ui_utils.SidebarView.LAYERS, this.layersView);
  7468. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  7469. if (forceOpen && !this.isOpen) {
  7470. this.open();
  7471. return;
  7472. }
  7473. if (forceRendering) {
  7474. this.onUpdateThumbnails();
  7475. this.onToggled();
  7476. }
  7477. if (isViewChanged) {
  7478. this.#dispatchEvent();
  7479. }
  7480. }
  7481. open() {
  7482. if (this.isOpen) {
  7483. return;
  7484. }
  7485. this.isOpen = true;
  7486. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true);
  7487. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7488. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7489. this.onUpdateThumbnails();
  7490. }
  7491. this.onToggled();
  7492. this.#dispatchEvent();
  7493. this.#hideUINotification();
  7494. }
  7495. close() {
  7496. if (!this.isOpen) {
  7497. return;
  7498. }
  7499. this.isOpen = false;
  7500. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false);
  7501. this.outerContainer.classList.add("sidebarMoving");
  7502. this.outerContainer.classList.remove("sidebarOpen");
  7503. this.onToggled();
  7504. this.#dispatchEvent();
  7505. }
  7506. toggle() {
  7507. if (this.isOpen) {
  7508. this.close();
  7509. } else {
  7510. this.open();
  7511. }
  7512. }
  7513. #dispatchEvent() {
  7514. if (this.isInitialViewSet) {
  7515. this.isInitialEventDispatched ||= true;
  7516. }
  7517. this.eventBus.dispatch("sidebarviewchanged", {
  7518. source: this,
  7519. view: this.visibleView
  7520. });
  7521. }
  7522. #showUINotification() {
  7523. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2");
  7524. this.l10n.translate(this.toggleButton);
  7525. if (!this.isOpen) {
  7526. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7527. }
  7528. }
  7529. #hideUINotification(reset = false) {
  7530. if (this.isOpen || reset) {
  7531. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7532. }
  7533. if (reset) {
  7534. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
  7535. this.l10n.translate(this.toggleButton);
  7536. }
  7537. }
  7538. #addEventListeners() {
  7539. this.sidebarContainer.addEventListener("transitionend", evt => {
  7540. if (evt.target === this.sidebarContainer) {
  7541. this.outerContainer.classList.remove("sidebarMoving");
  7542. }
  7543. });
  7544. this.toggleButton.addEventListener("click", () => {
  7545. this.toggle();
  7546. });
  7547. this.thumbnailButton.addEventListener("click", () => {
  7548. this.switchView(_ui_utils.SidebarView.THUMBS);
  7549. });
  7550. this.outlineButton.addEventListener("click", () => {
  7551. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7552. });
  7553. this.outlineButton.addEventListener("dblclick", () => {
  7554. this.eventBus.dispatch("toggleoutlinetree", {
  7555. source: this
  7556. });
  7557. });
  7558. this.attachmentsButton.addEventListener("click", () => {
  7559. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7560. });
  7561. this.layersButton.addEventListener("click", () => {
  7562. this.switchView(_ui_utils.SidebarView.LAYERS);
  7563. });
  7564. this.layersButton.addEventListener("dblclick", () => {
  7565. this.eventBus.dispatch("resetlayers", {
  7566. source: this
  7567. });
  7568. });
  7569. this._currentOutlineItemButton.addEventListener("click", () => {
  7570. this.eventBus.dispatch("currentoutlineitem", {
  7571. source: this
  7572. });
  7573. });
  7574. const onTreeLoaded = (count, button, view) => {
  7575. button.disabled = !count;
  7576. if (count) {
  7577. this.#showUINotification();
  7578. } else if (this.active === view) {
  7579. this.switchView(_ui_utils.SidebarView.THUMBS);
  7580. }
  7581. };
  7582. this.eventBus._on("outlineloaded", evt => {
  7583. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7584. evt.currentOutlineItemPromise.then(enabled => {
  7585. if (!this.isInitialViewSet) {
  7586. return;
  7587. }
  7588. this._currentOutlineItemButton.disabled = !enabled;
  7589. });
  7590. });
  7591. this.eventBus._on("attachmentsloaded", evt => {
  7592. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7593. });
  7594. this.eventBus._on("layersloaded", evt => {
  7595. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7596. });
  7597. this.eventBus._on("presentationmodechanged", evt => {
  7598. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  7599. this.onUpdateThumbnails();
  7600. }
  7601. });
  7602. this.resizer.addEventListener("mousedown", evt => {
  7603. if (evt.button !== 0) {
  7604. return;
  7605. }
  7606. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7607. window.addEventListener("mousemove", this.#mouseMoveBound);
  7608. window.addEventListener("mouseup", this.#mouseUpBound);
  7609. });
  7610. this.eventBus._on("resize", evt => {
  7611. if (evt.source !== window) {
  7612. return;
  7613. }
  7614. this.#outerContainerWidth = null;
  7615. if (!this.#width) {
  7616. return;
  7617. }
  7618. if (!this.isOpen) {
  7619. this.#updateWidth(this.#width);
  7620. return;
  7621. }
  7622. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7623. const updated = this.#updateWidth(this.#width);
  7624. Promise.resolve().then(() => {
  7625. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7626. if (updated) {
  7627. this.eventBus.dispatch("resize", {
  7628. source: this
  7629. });
  7630. }
  7631. });
  7632. });
  7633. }
  7634. get outerContainerWidth() {
  7635. return this.#outerContainerWidth ||= this.outerContainer.clientWidth;
  7636. }
  7637. #updateWidth(width = 0) {
  7638. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7639. if (width > maxWidth) {
  7640. width = maxWidth;
  7641. }
  7642. if (width < SIDEBAR_MIN_WIDTH) {
  7643. width = SIDEBAR_MIN_WIDTH;
  7644. }
  7645. if (width === this.#width) {
  7646. return false;
  7647. }
  7648. this.#width = width;
  7649. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7650. return true;
  7651. }
  7652. #mouseMove(evt) {
  7653. let width = evt.clientX;
  7654. if (this.#isRTL) {
  7655. width = this.outerContainerWidth - width;
  7656. }
  7657. this.#updateWidth(width);
  7658. }
  7659. #mouseUp(evt) {
  7660. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7661. this.eventBus.dispatch("resize", {
  7662. source: this
  7663. });
  7664. window.removeEventListener("mousemove", this.#mouseMoveBound);
  7665. window.removeEventListener("mouseup", this.#mouseUpBound);
  7666. }
  7667. }
  7668. exports.PDFSidebar = PDFSidebar;
  7669. /***/ }),
  7670. /* 26 */
  7671. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7672. Object.defineProperty(exports, "__esModule", ({
  7673. value: true
  7674. }));
  7675. exports.PDFThumbnailViewer = void 0;
  7676. var _ui_utils = __webpack_require__(3);
  7677. var _pdf_thumbnail_view = __webpack_require__(27);
  7678. const THUMBNAIL_SCROLL_MARGIN = -19;
  7679. const THUMBNAIL_SELECTED_CLASS = "selected";
  7680. class PDFThumbnailViewer {
  7681. constructor({
  7682. container,
  7683. eventBus,
  7684. linkService,
  7685. renderingQueue,
  7686. l10n,
  7687. pageColors
  7688. }) {
  7689. this.container = container;
  7690. this.eventBus = eventBus;
  7691. this.linkService = linkService;
  7692. this.renderingQueue = renderingQueue;
  7693. this.l10n = l10n;
  7694. this.pageColors = pageColors || null;
  7695. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  7696. if (this.pageColors.background || this.pageColors.foreground) {
  7697. console.warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  7698. }
  7699. this.pageColors = null;
  7700. }
  7701. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7702. this._resetView();
  7703. }
  7704. _scrollUpdated() {
  7705. this.renderingQueue.renderHighestPriority();
  7706. }
  7707. getThumbnail(index) {
  7708. return this._thumbnails[index];
  7709. }
  7710. _getVisibleThumbs() {
  7711. return (0, _ui_utils.getVisibleElements)({
  7712. scrollEl: this.container,
  7713. views: this._thumbnails
  7714. });
  7715. }
  7716. scrollThumbnailIntoView(pageNumber) {
  7717. if (!this.pdfDocument) {
  7718. return;
  7719. }
  7720. const thumbnailView = this._thumbnails[pageNumber - 1];
  7721. if (!thumbnailView) {
  7722. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7723. return;
  7724. }
  7725. if (pageNumber !== this._currentPageNumber) {
  7726. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7727. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7728. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7729. }
  7730. const {
  7731. first,
  7732. last,
  7733. views
  7734. } = this._getVisibleThumbs();
  7735. if (views.length > 0) {
  7736. let shouldScroll = false;
  7737. if (pageNumber <= first.id || pageNumber >= last.id) {
  7738. shouldScroll = true;
  7739. } else {
  7740. for (const {
  7741. id,
  7742. percent
  7743. } of views) {
  7744. if (id !== pageNumber) {
  7745. continue;
  7746. }
  7747. shouldScroll = percent < 100;
  7748. break;
  7749. }
  7750. }
  7751. if (shouldScroll) {
  7752. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7753. top: THUMBNAIL_SCROLL_MARGIN
  7754. });
  7755. }
  7756. }
  7757. this._currentPageNumber = pageNumber;
  7758. }
  7759. get pagesRotation() {
  7760. return this._pagesRotation;
  7761. }
  7762. set pagesRotation(rotation) {
  7763. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7764. throw new Error("Invalid thumbnails rotation angle.");
  7765. }
  7766. if (!this.pdfDocument) {
  7767. return;
  7768. }
  7769. if (this._pagesRotation === rotation) {
  7770. return;
  7771. }
  7772. this._pagesRotation = rotation;
  7773. const updateArgs = {
  7774. rotation
  7775. };
  7776. for (const thumbnail of this._thumbnails) {
  7777. thumbnail.update(updateArgs);
  7778. }
  7779. }
  7780. cleanup() {
  7781. for (const thumbnail of this._thumbnails) {
  7782. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7783. thumbnail.reset();
  7784. }
  7785. }
  7786. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7787. }
  7788. _resetView() {
  7789. this._thumbnails = [];
  7790. this._currentPageNumber = 1;
  7791. this._pageLabels = null;
  7792. this._pagesRotation = 0;
  7793. this.container.textContent = "";
  7794. }
  7795. setDocument(pdfDocument) {
  7796. if (this.pdfDocument) {
  7797. this._cancelRendering();
  7798. this._resetView();
  7799. }
  7800. this.pdfDocument = pdfDocument;
  7801. if (!pdfDocument) {
  7802. return;
  7803. }
  7804. const firstPagePromise = pdfDocument.getPage(1);
  7805. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7806. firstPagePromise.then(firstPdfPage => {
  7807. const pagesCount = pdfDocument.numPages;
  7808. const viewport = firstPdfPage.getViewport({
  7809. scale: 1
  7810. });
  7811. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7812. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7813. container: this.container,
  7814. eventBus: this.eventBus,
  7815. id: pageNum,
  7816. defaultViewport: viewport.clone(),
  7817. optionalContentConfigPromise,
  7818. linkService: this.linkService,
  7819. renderingQueue: this.renderingQueue,
  7820. l10n: this.l10n,
  7821. pageColors: this.pageColors
  7822. });
  7823. this._thumbnails.push(thumbnail);
  7824. }
  7825. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  7826. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7827. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7828. }).catch(reason => {
  7829. console.error("Unable to initialize thumbnail viewer", reason);
  7830. });
  7831. }
  7832. _cancelRendering() {
  7833. for (const thumbnail of this._thumbnails) {
  7834. thumbnail.cancelRendering();
  7835. }
  7836. }
  7837. setPageLabels(labels) {
  7838. if (!this.pdfDocument) {
  7839. return;
  7840. }
  7841. if (!labels) {
  7842. this._pageLabels = null;
  7843. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7844. this._pageLabels = null;
  7845. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7846. } else {
  7847. this._pageLabels = labels;
  7848. }
  7849. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7850. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7851. }
  7852. }
  7853. async #ensurePdfPageLoaded(thumbView) {
  7854. if (thumbView.pdfPage) {
  7855. return thumbView.pdfPage;
  7856. }
  7857. try {
  7858. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7859. if (!thumbView.pdfPage) {
  7860. thumbView.setPdfPage(pdfPage);
  7861. }
  7862. return pdfPage;
  7863. } catch (reason) {
  7864. console.error("Unable to get page for thumb view", reason);
  7865. return null;
  7866. }
  7867. }
  7868. #getScrollAhead(visible) {
  7869. if (visible.first?.id === 1) {
  7870. return true;
  7871. } else if (visible.last?.id === this._thumbnails.length) {
  7872. return false;
  7873. }
  7874. return this.scroll.down;
  7875. }
  7876. forceRendering() {
  7877. const visibleThumbs = this._getVisibleThumbs();
  7878. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7879. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7880. if (thumbView) {
  7881. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7882. this.renderingQueue.renderView(thumbView);
  7883. });
  7884. return true;
  7885. }
  7886. return false;
  7887. }
  7888. }
  7889. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7890. /***/ }),
  7891. /* 27 */
  7892. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7893. Object.defineProperty(exports, "__esModule", ({
  7894. value: true
  7895. }));
  7896. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7897. var _ui_utils = __webpack_require__(3);
  7898. var _pdfjsLib = __webpack_require__(4);
  7899. const DRAW_UPSCALE_FACTOR = 2;
  7900. const MAX_NUM_SCALING_STEPS = 3;
  7901. const THUMBNAIL_WIDTH = 98;
  7902. class TempImageFactory {
  7903. static #tempCanvas = null;
  7904. static getCanvas(width, height) {
  7905. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7906. tempCanvas.width = width;
  7907. tempCanvas.height = height;
  7908. const ctx = tempCanvas.getContext("2d", {
  7909. alpha: false
  7910. });
  7911. ctx.save();
  7912. ctx.fillStyle = "rgb(255, 255, 255)";
  7913. ctx.fillRect(0, 0, width, height);
  7914. ctx.restore();
  7915. return [tempCanvas, tempCanvas.getContext("2d")];
  7916. }
  7917. static destroyCanvas() {
  7918. const tempCanvas = this.#tempCanvas;
  7919. if (tempCanvas) {
  7920. tempCanvas.width = 0;
  7921. tempCanvas.height = 0;
  7922. }
  7923. this.#tempCanvas = null;
  7924. }
  7925. }
  7926. exports.TempImageFactory = TempImageFactory;
  7927. class PDFThumbnailView {
  7928. constructor({
  7929. container,
  7930. eventBus,
  7931. id,
  7932. defaultViewport,
  7933. optionalContentConfigPromise,
  7934. linkService,
  7935. renderingQueue,
  7936. l10n,
  7937. pageColors
  7938. }) {
  7939. this.id = id;
  7940. this.renderingId = "thumbnail" + id;
  7941. this.pageLabel = null;
  7942. this.pdfPage = null;
  7943. this.rotation = 0;
  7944. this.viewport = defaultViewport;
  7945. this.pdfPageRotate = defaultViewport.rotation;
  7946. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7947. this.pageColors = pageColors || null;
  7948. this.eventBus = eventBus;
  7949. this.linkService = linkService;
  7950. this.renderingQueue = renderingQueue;
  7951. this.renderTask = null;
  7952. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7953. this.resume = null;
  7954. this.l10n = l10n;
  7955. const anchor = document.createElement("a");
  7956. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7957. this._thumbPageTitle.then(msg => {
  7958. anchor.title = msg;
  7959. });
  7960. anchor.onclick = function () {
  7961. linkService.goToPage(id);
  7962. return false;
  7963. };
  7964. this.anchor = anchor;
  7965. const div = document.createElement("div");
  7966. div.className = "thumbnail";
  7967. div.setAttribute("data-page-number", this.id);
  7968. this.div = div;
  7969. this.#updateDims();
  7970. const img = document.createElement("div");
  7971. img.className = "thumbnailImage";
  7972. this._placeholderImg = img;
  7973. div.append(img);
  7974. anchor.append(div);
  7975. container.append(anchor);
  7976. }
  7977. #updateDims() {
  7978. const {
  7979. width,
  7980. height
  7981. } = this.viewport;
  7982. const ratio = width / height;
  7983. this.canvasWidth = THUMBNAIL_WIDTH;
  7984. this.canvasHeight = this.canvasWidth / ratio | 0;
  7985. this.scale = this.canvasWidth / width;
  7986. const {
  7987. style
  7988. } = this.div;
  7989. style.setProperty("--thumbnail-width", `${this.canvasWidth}px`);
  7990. style.setProperty("--thumbnail-height", `${this.canvasHeight}px`);
  7991. }
  7992. setPdfPage(pdfPage) {
  7993. this.pdfPage = pdfPage;
  7994. this.pdfPageRotate = pdfPage.rotate;
  7995. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7996. this.viewport = pdfPage.getViewport({
  7997. scale: 1,
  7998. rotation: totalRotation
  7999. });
  8000. this.reset();
  8001. }
  8002. reset() {
  8003. this.cancelRendering();
  8004. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  8005. this.div.removeAttribute("data-loaded");
  8006. this.image?.replaceWith(this._placeholderImg);
  8007. this.#updateDims();
  8008. if (this.image) {
  8009. this.image.removeAttribute("src");
  8010. delete this.image;
  8011. }
  8012. }
  8013. update({
  8014. rotation = null
  8015. }) {
  8016. if (typeof rotation === "number") {
  8017. this.rotation = rotation;
  8018. }
  8019. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8020. this.viewport = this.viewport.clone({
  8021. scale: 1,
  8022. rotation: totalRotation
  8023. });
  8024. this.reset();
  8025. }
  8026. cancelRendering() {
  8027. if (this.renderTask) {
  8028. this.renderTask.cancel();
  8029. this.renderTask = null;
  8030. }
  8031. this.resume = null;
  8032. }
  8033. _getPageDrawContext(upscaleFactor = 1) {
  8034. const canvas = document.createElement("canvas");
  8035. const ctx = canvas.getContext("2d", {
  8036. alpha: false
  8037. });
  8038. const outputScale = new _ui_utils.OutputScale();
  8039. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  8040. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  8041. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  8042. return {
  8043. ctx,
  8044. canvas,
  8045. transform
  8046. };
  8047. }
  8048. _convertCanvasToImage(canvas) {
  8049. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8050. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  8051. }
  8052. const reducedCanvas = this._reduceImage(canvas);
  8053. const image = document.createElement("img");
  8054. image.className = "thumbnailImage";
  8055. this._thumbPageCanvas.then(msg => {
  8056. image.setAttribute("aria-label", msg);
  8057. });
  8058. image.src = reducedCanvas.toDataURL();
  8059. this.image = image;
  8060. this.div.setAttribute("data-loaded", true);
  8061. this._placeholderImg.replaceWith(image);
  8062. reducedCanvas.width = 0;
  8063. reducedCanvas.height = 0;
  8064. }
  8065. async #finishRenderTask(renderTask, canvas, error = null) {
  8066. if (renderTask === this.renderTask) {
  8067. this.renderTask = null;
  8068. }
  8069. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  8070. return;
  8071. }
  8072. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8073. this._convertCanvasToImage(canvas);
  8074. if (error) {
  8075. throw error;
  8076. }
  8077. }
  8078. async draw() {
  8079. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8080. console.error("Must be in new state before drawing");
  8081. return undefined;
  8082. }
  8083. const {
  8084. pdfPage
  8085. } = this;
  8086. if (!pdfPage) {
  8087. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8088. throw new Error("pdfPage is not loaded");
  8089. }
  8090. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8091. const {
  8092. ctx,
  8093. canvas,
  8094. transform
  8095. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  8096. const drawViewport = this.viewport.clone({
  8097. scale: DRAW_UPSCALE_FACTOR * this.scale
  8098. });
  8099. const renderContinueCallback = cont => {
  8100. if (!this.renderingQueue.isHighestPriority(this)) {
  8101. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  8102. this.resume = () => {
  8103. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  8104. cont();
  8105. };
  8106. return;
  8107. }
  8108. cont();
  8109. };
  8110. const renderContext = {
  8111. canvasContext: ctx,
  8112. transform,
  8113. viewport: drawViewport,
  8114. optionalContentConfigPromise: this._optionalContentConfigPromise,
  8115. pageColors: this.pageColors
  8116. };
  8117. const renderTask = this.renderTask = pdfPage.render(renderContext);
  8118. renderTask.onContinue = renderContinueCallback;
  8119. const resultPromise = renderTask.promise.then(() => this.#finishRenderTask(renderTask, canvas), error => this.#finishRenderTask(renderTask, canvas, error));
  8120. resultPromise.finally(() => {
  8121. canvas.width = 0;
  8122. canvas.height = 0;
  8123. this.eventBus.dispatch("thumbnailrendered", {
  8124. source: this,
  8125. pageNumber: this.id,
  8126. pdfPage: this.pdfPage
  8127. });
  8128. });
  8129. return resultPromise;
  8130. }
  8131. setImage(pageView) {
  8132. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  8133. return;
  8134. }
  8135. const {
  8136. thumbnailCanvas: canvas,
  8137. pdfPage,
  8138. scale
  8139. } = pageView;
  8140. if (!canvas) {
  8141. return;
  8142. }
  8143. if (!this.pdfPage) {
  8144. this.setPdfPage(pdfPage);
  8145. }
  8146. if (scale < this.scale) {
  8147. return;
  8148. }
  8149. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  8150. this._convertCanvasToImage(canvas);
  8151. }
  8152. _reduceImage(img) {
  8153. const {
  8154. ctx,
  8155. canvas
  8156. } = this._getPageDrawContext();
  8157. if (img.width <= 2 * canvas.width) {
  8158. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  8159. return canvas;
  8160. }
  8161. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  8162. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  8163. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  8164. while (reducedWidth > img.width || reducedHeight > img.height) {
  8165. reducedWidth >>= 1;
  8166. reducedHeight >>= 1;
  8167. }
  8168. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  8169. while (reducedWidth > 2 * canvas.width) {
  8170. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  8171. reducedWidth >>= 1;
  8172. reducedHeight >>= 1;
  8173. }
  8174. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  8175. return canvas;
  8176. }
  8177. get _thumbPageTitle() {
  8178. return this.l10n.get("thumb_page_title", {
  8179. page: this.pageLabel ?? this.id
  8180. });
  8181. }
  8182. get _thumbPageCanvas() {
  8183. return this.l10n.get("thumb_page_canvas", {
  8184. page: this.pageLabel ?? this.id
  8185. });
  8186. }
  8187. setPageLabel(label) {
  8188. this.pageLabel = typeof label === "string" ? label : null;
  8189. this._thumbPageTitle.then(msg => {
  8190. this.anchor.title = msg;
  8191. });
  8192. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8193. return;
  8194. }
  8195. this._thumbPageCanvas.then(msg => {
  8196. this.image?.setAttribute("aria-label", msg);
  8197. });
  8198. }
  8199. }
  8200. exports.PDFThumbnailView = PDFThumbnailView;
  8201. /***/ }),
  8202. /* 28 */
  8203. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8204. Object.defineProperty(exports, "__esModule", ({
  8205. value: true
  8206. }));
  8207. exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
  8208. var _pdfjsLib = __webpack_require__(4);
  8209. var _ui_utils = __webpack_require__(3);
  8210. var _l10n_utils = __webpack_require__(29);
  8211. var _pdf_page_view = __webpack_require__(30);
  8212. var _pdf_rendering_queue = __webpack_require__(23);
  8213. var _pdf_link_service = __webpack_require__(7);
  8214. const DEFAULT_CACHE_SIZE = 10;
  8215. const PagesCountLimit = {
  8216. FORCE_SCROLL_MODE_PAGE: 15000,
  8217. FORCE_LAZY_PAGE_INIT: 7500,
  8218. PAUSE_EAGER_PAGE_INIT: 250
  8219. };
  8220. exports.PagesCountLimit = PagesCountLimit;
  8221. function isValidAnnotationEditorMode(mode) {
  8222. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  8223. }
  8224. class PDFPageViewBuffer {
  8225. #buf = new Set();
  8226. #size = 0;
  8227. constructor(size) {
  8228. this.#size = size;
  8229. }
  8230. push(view) {
  8231. const buf = this.#buf;
  8232. if (buf.has(view)) {
  8233. buf.delete(view);
  8234. }
  8235. buf.add(view);
  8236. if (buf.size > this.#size) {
  8237. this.#destroyFirstView();
  8238. }
  8239. }
  8240. resize(newSize, idsToKeep = null) {
  8241. this.#size = newSize;
  8242. const buf = this.#buf;
  8243. if (idsToKeep) {
  8244. const ii = buf.size;
  8245. let i = 1;
  8246. for (const view of buf) {
  8247. if (idsToKeep.has(view.id)) {
  8248. buf.delete(view);
  8249. buf.add(view);
  8250. }
  8251. if (++i > ii) {
  8252. break;
  8253. }
  8254. }
  8255. }
  8256. while (buf.size > this.#size) {
  8257. this.#destroyFirstView();
  8258. }
  8259. }
  8260. has(view) {
  8261. return this.#buf.has(view);
  8262. }
  8263. [Symbol.iterator]() {
  8264. return this.#buf.keys();
  8265. }
  8266. #destroyFirstView() {
  8267. const firstView = this.#buf.keys().next().value;
  8268. firstView?.destroy();
  8269. this.#buf.delete(firstView);
  8270. }
  8271. }
  8272. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  8273. class PDFViewer {
  8274. #buffer = null;
  8275. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  8276. #annotationEditorUIManager = null;
  8277. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8278. #containerTopLeft = null;
  8279. #copyCallbackBound = null;
  8280. #enablePermissions = false;
  8281. #getAllTextInProgress = false;
  8282. #hiddenCopyElement = null;
  8283. #interruptCopyCondition = false;
  8284. #previousContainerHeight = 0;
  8285. #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
  8286. #scrollModePageState = null;
  8287. #onVisibilityChange = null;
  8288. #scaleTimeoutId = null;
  8289. #textLayerMode = _ui_utils.TextLayerMode.ENABLE;
  8290. constructor(options) {
  8291. const viewerVersion = '3.7.107';
  8292. if (_pdfjsLib.version !== viewerVersion) {
  8293. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  8294. }
  8295. this.container = options.container;
  8296. this.viewer = options.viewer || options.container.firstElementChild;
  8297. if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
  8298. throw new Error("Invalid `container` and/or `viewer` option.");
  8299. }
  8300. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  8301. throw new Error("The `container` must be absolutely positioned.");
  8302. }
  8303. this.#resizeObserver.observe(this.container);
  8304. this.eventBus = options.eventBus;
  8305. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8306. this.downloadManager = options.downloadManager || null;
  8307. this.findController = options.findController || null;
  8308. if (this.findController) {
  8309. this.findController.onIsPageVisible = pageNumber => this._getVisiblePages().ids.has(pageNumber);
  8310. }
  8311. this._scriptingManager = options.scriptingManager || null;
  8312. this.#textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  8313. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8314. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
  8315. this.imageResourcesPath = options.imageResourcesPath || "";
  8316. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8317. this.removePageBorders = options.removePageBorders || false;
  8318. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  8319. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  8320. this.maxCanvasPixels = options.maxCanvasPixels;
  8321. this.l10n = options.l10n || _l10n_utils.NullL10n;
  8322. this.#enablePermissions = options.enablePermissions || false;
  8323. this.pageColors = options.pageColors || null;
  8324. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  8325. if (this.pageColors.background || this.pageColors.foreground) {
  8326. console.warn("PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  8327. }
  8328. this.pageColors = null;
  8329. }
  8330. this.defaultRenderingQueue = !options.renderingQueue;
  8331. if (this.defaultRenderingQueue) {
  8332. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8333. this.renderingQueue.setViewer(this);
  8334. } else {
  8335. this.renderingQueue = options.renderingQueue;
  8336. }
  8337. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8338. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8339. this._onBeforeDraw = this._onAfterDraw = null;
  8340. this._resetView();
  8341. if (this.removePageBorders) {
  8342. this.viewer.classList.add("removePageBorders");
  8343. }
  8344. this.#updateContainerHeightCss();
  8345. this.eventBus._on("thumbnailrendered", ({
  8346. pageNumber,
  8347. pdfPage
  8348. }) => {
  8349. const pageView = this._pages[pageNumber - 1];
  8350. if (!this.#buffer.has(pageView)) {
  8351. pdfPage?.cleanup();
  8352. }
  8353. });
  8354. }
  8355. get pagesCount() {
  8356. return this._pages.length;
  8357. }
  8358. getPageView(index) {
  8359. return this._pages[index];
  8360. }
  8361. getCachedPageViews() {
  8362. return new Set(this.#buffer);
  8363. }
  8364. get pageViewsReady() {
  8365. return this._pagesCapability.settled && this._pages.every(pageView => pageView?.pdfPage);
  8366. }
  8367. get renderForms() {
  8368. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8369. }
  8370. get enableScripting() {
  8371. return !!this._scriptingManager;
  8372. }
  8373. get currentPageNumber() {
  8374. return this._currentPageNumber;
  8375. }
  8376. set currentPageNumber(val) {
  8377. if (!Number.isInteger(val)) {
  8378. throw new Error("Invalid page number.");
  8379. }
  8380. if (!this.pdfDocument) {
  8381. return;
  8382. }
  8383. if (!this._setCurrentPageNumber(val, true)) {
  8384. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  8385. }
  8386. }
  8387. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  8388. if (this._currentPageNumber === val) {
  8389. if (resetCurrentPageView) {
  8390. this.#resetCurrentPageView();
  8391. }
  8392. return true;
  8393. }
  8394. if (!(0 < val && val <= this.pagesCount)) {
  8395. return false;
  8396. }
  8397. const previous = this._currentPageNumber;
  8398. this._currentPageNumber = val;
  8399. this.eventBus.dispatch("pagechanging", {
  8400. source: this,
  8401. pageNumber: val,
  8402. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8403. previous
  8404. });
  8405. if (resetCurrentPageView) {
  8406. this.#resetCurrentPageView();
  8407. }
  8408. return true;
  8409. }
  8410. get currentPageLabel() {
  8411. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8412. }
  8413. set currentPageLabel(val) {
  8414. if (!this.pdfDocument) {
  8415. return;
  8416. }
  8417. let page = val | 0;
  8418. if (this._pageLabels) {
  8419. const i = this._pageLabels.indexOf(val);
  8420. if (i >= 0) {
  8421. page = i + 1;
  8422. }
  8423. }
  8424. if (!this._setCurrentPageNumber(page, true)) {
  8425. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8426. }
  8427. }
  8428. get currentScale() {
  8429. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8430. }
  8431. set currentScale(val) {
  8432. if (isNaN(val)) {
  8433. throw new Error("Invalid numeric scale.");
  8434. }
  8435. if (!this.pdfDocument) {
  8436. return;
  8437. }
  8438. this.#setScale(val, {
  8439. noScroll: false
  8440. });
  8441. }
  8442. get currentScaleValue() {
  8443. return this._currentScaleValue;
  8444. }
  8445. set currentScaleValue(val) {
  8446. if (!this.pdfDocument) {
  8447. return;
  8448. }
  8449. this.#setScale(val, {
  8450. noScroll: false
  8451. });
  8452. }
  8453. get pagesRotation() {
  8454. return this._pagesRotation;
  8455. }
  8456. set pagesRotation(rotation) {
  8457. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8458. throw new Error("Invalid pages rotation angle.");
  8459. }
  8460. if (!this.pdfDocument) {
  8461. return;
  8462. }
  8463. rotation %= 360;
  8464. if (rotation < 0) {
  8465. rotation += 360;
  8466. }
  8467. if (this._pagesRotation === rotation) {
  8468. return;
  8469. }
  8470. this._pagesRotation = rotation;
  8471. const pageNumber = this._currentPageNumber;
  8472. this.refresh(true, {
  8473. rotation
  8474. });
  8475. if (this._currentScaleValue) {
  8476. this.#setScale(this._currentScaleValue, {
  8477. noScroll: true
  8478. });
  8479. }
  8480. this.eventBus.dispatch("rotationchanging", {
  8481. source: this,
  8482. pagesRotation: rotation,
  8483. pageNumber
  8484. });
  8485. if (this.defaultRenderingQueue) {
  8486. this.update();
  8487. }
  8488. }
  8489. get firstPagePromise() {
  8490. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8491. }
  8492. get onePageRendered() {
  8493. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8494. }
  8495. get pagesPromise() {
  8496. return this.pdfDocument ? this._pagesCapability.promise : null;
  8497. }
  8498. #layerProperties() {
  8499. const self = this;
  8500. return {
  8501. get annotationEditorUIManager() {
  8502. return self.#annotationEditorUIManager;
  8503. },
  8504. get annotationStorage() {
  8505. return self.pdfDocument?.annotationStorage;
  8506. },
  8507. get downloadManager() {
  8508. return self.downloadManager;
  8509. },
  8510. get enableScripting() {
  8511. return !!self._scriptingManager;
  8512. },
  8513. get fieldObjectsPromise() {
  8514. return self.pdfDocument?.getFieldObjects();
  8515. },
  8516. get findController() {
  8517. return self.findController;
  8518. },
  8519. get hasJSActionsPromise() {
  8520. return self.pdfDocument?.hasJSActions();
  8521. },
  8522. get linkService() {
  8523. return self.linkService;
  8524. }
  8525. };
  8526. }
  8527. #initializePermissions(permissions) {
  8528. const params = {
  8529. annotationEditorMode: this.#annotationEditorMode,
  8530. annotationMode: this.#annotationMode,
  8531. textLayerMode: this.#textLayerMode
  8532. };
  8533. if (!permissions) {
  8534. return params;
  8535. }
  8536. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY) && this.#textLayerMode === _ui_utils.TextLayerMode.ENABLE) {
  8537. params.textLayerMode = _ui_utils.TextLayerMode.ENABLE_PERMISSIONS;
  8538. }
  8539. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  8540. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8541. }
  8542. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8543. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8544. }
  8545. return params;
  8546. }
  8547. #onePageRenderedOrForceFetch() {
  8548. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8549. return Promise.resolve();
  8550. }
  8551. const visibilityChangePromise = new Promise(resolve => {
  8552. this.#onVisibilityChange = () => {
  8553. if (document.visibilityState !== "hidden") {
  8554. return;
  8555. }
  8556. resolve();
  8557. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8558. this.#onVisibilityChange = null;
  8559. };
  8560. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8561. });
  8562. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8563. }
  8564. async getAllText() {
  8565. const texts = [];
  8566. const buffer = [];
  8567. for (let pageNum = 1, pagesCount = this.pdfDocument.numPages; pageNum <= pagesCount; ++pageNum) {
  8568. if (this.#interruptCopyCondition) {
  8569. return null;
  8570. }
  8571. buffer.length = 0;
  8572. const page = await this.pdfDocument.getPage(pageNum);
  8573. const {
  8574. items
  8575. } = await page.getTextContent();
  8576. for (const item of items) {
  8577. if (item.str) {
  8578. buffer.push(item.str);
  8579. }
  8580. if (item.hasEOL) {
  8581. buffer.push("\n");
  8582. }
  8583. }
  8584. texts.push((0, _ui_utils.removeNullCharacters)(buffer.join("")));
  8585. }
  8586. return texts.join("\n");
  8587. }
  8588. #copyCallback(textLayerMode, event) {
  8589. const selection = document.getSelection();
  8590. const {
  8591. focusNode,
  8592. anchorNode
  8593. } = selection;
  8594. if (anchorNode && focusNode && selection.containsNode(this.#hiddenCopyElement)) {
  8595. if (this.#getAllTextInProgress || textLayerMode === _ui_utils.TextLayerMode.ENABLE_PERMISSIONS) {
  8596. event.preventDefault();
  8597. event.stopPropagation();
  8598. return;
  8599. }
  8600. this.#getAllTextInProgress = true;
  8601. const savedCursor = this.container.style.cursor;
  8602. this.container.style.cursor = "wait";
  8603. const interruptCopy = ev => this.#interruptCopyCondition = ev.key === "Escape";
  8604. window.addEventListener("keydown", interruptCopy);
  8605. this.getAllText().then(async text => {
  8606. if (text !== null) {
  8607. await navigator.clipboard.writeText(text);
  8608. }
  8609. }).catch(reason => {
  8610. console.warn(`Something goes wrong when extracting the text: ${reason.message}`);
  8611. }).finally(() => {
  8612. this.#getAllTextInProgress = false;
  8613. this.#interruptCopyCondition = false;
  8614. window.removeEventListener("keydown", interruptCopy);
  8615. this.container.style.cursor = savedCursor;
  8616. });
  8617. event.preventDefault();
  8618. event.stopPropagation();
  8619. }
  8620. }
  8621. setDocument(pdfDocument) {
  8622. if (this.pdfDocument) {
  8623. this.eventBus.dispatch("pagesdestroy", {
  8624. source: this
  8625. });
  8626. this._cancelRendering();
  8627. this._resetView();
  8628. this.findController?.setDocument(null);
  8629. this._scriptingManager?.setDocument(null);
  8630. if (this.#annotationEditorUIManager) {
  8631. this.#annotationEditorUIManager.destroy();
  8632. this.#annotationEditorUIManager = null;
  8633. }
  8634. }
  8635. this.pdfDocument = pdfDocument;
  8636. if (!pdfDocument) {
  8637. return;
  8638. }
  8639. const pagesCount = pdfDocument.numPages;
  8640. const firstPagePromise = pdfDocument.getPage(1);
  8641. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8642. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8643. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8644. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8645. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8646. this.eventBus.dispatch("scrollmodechanged", {
  8647. source: this,
  8648. mode
  8649. });
  8650. }
  8651. this._pagesCapability.promise.then(() => {
  8652. this.eventBus.dispatch("pagesloaded", {
  8653. source: this,
  8654. pagesCount
  8655. });
  8656. }, () => {});
  8657. this._onBeforeDraw = evt => {
  8658. const pageView = this._pages[evt.pageNumber - 1];
  8659. if (!pageView) {
  8660. return;
  8661. }
  8662. this.#buffer.push(pageView);
  8663. };
  8664. this.eventBus._on("pagerender", this._onBeforeDraw);
  8665. this._onAfterDraw = evt => {
  8666. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8667. return;
  8668. }
  8669. this._onePageRenderedCapability.resolve({
  8670. timestamp: evt.timestamp
  8671. });
  8672. this.eventBus._off("pagerendered", this._onAfterDraw);
  8673. this._onAfterDraw = null;
  8674. if (this.#onVisibilityChange) {
  8675. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8676. this.#onVisibilityChange = null;
  8677. }
  8678. };
  8679. this.eventBus._on("pagerendered", this._onAfterDraw);
  8680. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8681. if (pdfDocument !== this.pdfDocument) {
  8682. return;
  8683. }
  8684. this._firstPageCapability.resolve(firstPdfPage);
  8685. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8686. const {
  8687. annotationEditorMode,
  8688. annotationMode,
  8689. textLayerMode
  8690. } = this.#initializePermissions(permissions);
  8691. if (textLayerMode !== _ui_utils.TextLayerMode.DISABLE) {
  8692. const element = this.#hiddenCopyElement = document.createElement("div");
  8693. element.id = "hiddenCopyElement";
  8694. this.viewer.before(element);
  8695. }
  8696. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  8697. const mode = annotationEditorMode;
  8698. if (pdfDocument.isPureXfa) {
  8699. console.warn("Warning: XFA-editing is not implemented.");
  8700. } else if (isValidAnnotationEditorMode(mode)) {
  8701. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus, pdfDocument?.annotationStorage);
  8702. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  8703. this.#annotationEditorUIManager.updateMode(mode);
  8704. }
  8705. } else {
  8706. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  8707. }
  8708. }
  8709. const layerProperties = this.#layerProperties.bind(this);
  8710. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8711. const scale = this.currentScale;
  8712. const viewport = firstPdfPage.getViewport({
  8713. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8714. });
  8715. this.viewer.style.setProperty("--scale-factor", viewport.scale);
  8716. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8717. const pageView = new _pdf_page_view.PDFPageView({
  8718. container: viewerElement,
  8719. eventBus: this.eventBus,
  8720. id: pageNum,
  8721. scale,
  8722. defaultViewport: viewport.clone(),
  8723. optionalContentConfigPromise,
  8724. renderingQueue: this.renderingQueue,
  8725. textLayerMode,
  8726. annotationMode,
  8727. imageResourcesPath: this.imageResourcesPath,
  8728. useOnlyCssZoom: this.useOnlyCssZoom,
  8729. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  8730. maxCanvasPixels: this.maxCanvasPixels,
  8731. pageColors: this.pageColors,
  8732. l10n: this.l10n,
  8733. layerProperties
  8734. });
  8735. this._pages.push(pageView);
  8736. }
  8737. const firstPageView = this._pages[0];
  8738. if (firstPageView) {
  8739. firstPageView.setPdfPage(firstPdfPage);
  8740. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8741. }
  8742. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8743. this.#ensurePageViewVisible();
  8744. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8745. this._updateSpreadMode();
  8746. }
  8747. this.#onePageRenderedOrForceFetch().then(async () => {
  8748. this.findController?.setDocument(pdfDocument);
  8749. this._scriptingManager?.setDocument(pdfDocument);
  8750. if (this.#hiddenCopyElement) {
  8751. this.#copyCallbackBound = this.#copyCallback.bind(this, textLayerMode);
  8752. document.addEventListener("copy", this.#copyCallbackBound);
  8753. }
  8754. if (this.#annotationEditorUIManager) {
  8755. this.eventBus.dispatch("annotationeditormodechanged", {
  8756. source: this,
  8757. mode: this.#annotationEditorMode
  8758. });
  8759. }
  8760. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8761. this._pagesCapability.resolve();
  8762. return;
  8763. }
  8764. let getPagesLeft = pagesCount - 1;
  8765. if (getPagesLeft <= 0) {
  8766. this._pagesCapability.resolve();
  8767. return;
  8768. }
  8769. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8770. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8771. const pageView = this._pages[pageNum - 1];
  8772. if (!pageView.pdfPage) {
  8773. pageView.setPdfPage(pdfPage);
  8774. }
  8775. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8776. if (--getPagesLeft === 0) {
  8777. this._pagesCapability.resolve();
  8778. }
  8779. }, reason => {
  8780. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8781. if (--getPagesLeft === 0) {
  8782. this._pagesCapability.resolve();
  8783. }
  8784. });
  8785. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8786. await promise;
  8787. }
  8788. }
  8789. });
  8790. this.eventBus.dispatch("pagesinit", {
  8791. source: this
  8792. });
  8793. pdfDocument.getMetadata().then(({
  8794. info
  8795. }) => {
  8796. if (pdfDocument !== this.pdfDocument) {
  8797. return;
  8798. }
  8799. if (info.Language) {
  8800. this.viewer.lang = info.Language;
  8801. }
  8802. });
  8803. if (this.defaultRenderingQueue) {
  8804. this.update();
  8805. }
  8806. }).catch(reason => {
  8807. console.error("Unable to initialize viewer", reason);
  8808. this._pagesCapability.reject(reason);
  8809. });
  8810. }
  8811. setPageLabels(labels) {
  8812. if (!this.pdfDocument) {
  8813. return;
  8814. }
  8815. if (!labels) {
  8816. this._pageLabels = null;
  8817. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8818. this._pageLabels = null;
  8819. console.error(`setPageLabels: Invalid page labels.`);
  8820. } else {
  8821. this._pageLabels = labels;
  8822. }
  8823. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8824. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8825. }
  8826. }
  8827. _resetView() {
  8828. this._pages = [];
  8829. this._currentPageNumber = 1;
  8830. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8831. this._currentScaleValue = null;
  8832. this._pageLabels = null;
  8833. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8834. this._location = null;
  8835. this._pagesRotation = 0;
  8836. this._optionalContentConfigPromise = null;
  8837. this._firstPageCapability = new _pdfjsLib.PromiseCapability();
  8838. this._onePageRenderedCapability = new _pdfjsLib.PromiseCapability();
  8839. this._pagesCapability = new _pdfjsLib.PromiseCapability();
  8840. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8841. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8842. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8843. this.#scrollModePageState = {
  8844. previousPageNumber: 1,
  8845. scrollDown: true,
  8846. pages: []
  8847. };
  8848. if (this._onBeforeDraw) {
  8849. this.eventBus._off("pagerender", this._onBeforeDraw);
  8850. this._onBeforeDraw = null;
  8851. }
  8852. if (this._onAfterDraw) {
  8853. this.eventBus._off("pagerendered", this._onAfterDraw);
  8854. this._onAfterDraw = null;
  8855. }
  8856. if (this.#onVisibilityChange) {
  8857. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8858. this.#onVisibilityChange = null;
  8859. }
  8860. this.viewer.textContent = "";
  8861. this._updateScrollMode();
  8862. this.viewer.removeAttribute("lang");
  8863. if (this.#hiddenCopyElement) {
  8864. document.removeEventListener("copy", this.#copyCallbackBound);
  8865. this.#copyCallbackBound = null;
  8866. this.#hiddenCopyElement.remove();
  8867. this.#hiddenCopyElement = null;
  8868. }
  8869. }
  8870. #ensurePageViewVisible() {
  8871. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8872. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8873. }
  8874. const pageNumber = this._currentPageNumber,
  8875. state = this.#scrollModePageState,
  8876. viewer = this.viewer;
  8877. viewer.textContent = "";
  8878. state.pages.length = 0;
  8879. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8880. const pageView = this._pages[pageNumber - 1];
  8881. viewer.append(pageView.div);
  8882. state.pages.push(pageView);
  8883. } else {
  8884. const pageIndexSet = new Set(),
  8885. parity = this._spreadMode - 1;
  8886. if (parity === -1) {
  8887. pageIndexSet.add(pageNumber - 1);
  8888. } else if (pageNumber % 2 !== parity) {
  8889. pageIndexSet.add(pageNumber - 1);
  8890. pageIndexSet.add(pageNumber);
  8891. } else {
  8892. pageIndexSet.add(pageNumber - 2);
  8893. pageIndexSet.add(pageNumber - 1);
  8894. }
  8895. const spread = document.createElement("div");
  8896. spread.className = "spread";
  8897. if (this.isInPresentationMode) {
  8898. const dummyPage = document.createElement("div");
  8899. dummyPage.className = "dummyPage";
  8900. spread.append(dummyPage);
  8901. }
  8902. for (const i of pageIndexSet) {
  8903. const pageView = this._pages[i];
  8904. if (!pageView) {
  8905. continue;
  8906. }
  8907. spread.append(pageView.div);
  8908. state.pages.push(pageView);
  8909. }
  8910. viewer.append(spread);
  8911. }
  8912. state.scrollDown = pageNumber >= state.previousPageNumber;
  8913. state.previousPageNumber = pageNumber;
  8914. }
  8915. _scrollUpdate() {
  8916. if (this.pagesCount === 0) {
  8917. return;
  8918. }
  8919. this.update();
  8920. }
  8921. #scrollIntoView(pageView, pageSpot = null) {
  8922. const {
  8923. div,
  8924. id
  8925. } = pageView;
  8926. if (this._currentPageNumber !== id) {
  8927. this._setCurrentPageNumber(id);
  8928. }
  8929. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8930. this.#ensurePageViewVisible();
  8931. this.update();
  8932. }
  8933. if (!pageSpot && !this.isInPresentationMode) {
  8934. const left = div.offsetLeft + div.clientLeft,
  8935. right = left + div.clientWidth;
  8936. const {
  8937. scrollLeft,
  8938. clientWidth
  8939. } = this.container;
  8940. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8941. pageSpot = {
  8942. left: 0,
  8943. top: 0
  8944. };
  8945. }
  8946. }
  8947. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8948. if (!this._currentScaleValue && this._location) {
  8949. this._location = null;
  8950. }
  8951. }
  8952. #isSameScale(newScale) {
  8953. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8954. }
  8955. #setScaleUpdatePages(newScale, newValue, {
  8956. noScroll = false,
  8957. preset = false,
  8958. drawingDelay = -1
  8959. }) {
  8960. this._currentScaleValue = newValue.toString();
  8961. if (this.#isSameScale(newScale)) {
  8962. if (preset) {
  8963. this.eventBus.dispatch("scalechanging", {
  8964. source: this,
  8965. scale: newScale,
  8966. presetValue: newValue
  8967. });
  8968. }
  8969. return;
  8970. }
  8971. this.viewer.style.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8972. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  8973. this.refresh(true, {
  8974. scale: newScale,
  8975. drawingDelay: postponeDrawing ? drawingDelay : -1
  8976. });
  8977. if (postponeDrawing) {
  8978. this.#scaleTimeoutId = setTimeout(() => {
  8979. this.#scaleTimeoutId = null;
  8980. this.refresh();
  8981. }, drawingDelay);
  8982. }
  8983. this._currentScale = newScale;
  8984. if (!noScroll) {
  8985. let page = this._currentPageNumber,
  8986. dest;
  8987. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8988. page = this._location.pageNumber;
  8989. dest = [null, {
  8990. name: "XYZ"
  8991. }, this._location.left, this._location.top, null];
  8992. }
  8993. this.scrollPageIntoView({
  8994. pageNumber: page,
  8995. destArray: dest,
  8996. allowNegativeOffset: true
  8997. });
  8998. }
  8999. this.eventBus.dispatch("scalechanging", {
  9000. source: this,
  9001. scale: newScale,
  9002. presetValue: preset ? newValue : undefined
  9003. });
  9004. if (this.defaultRenderingQueue) {
  9005. this.update();
  9006. }
  9007. }
  9008. get #pageWidthScaleFactor() {
  9009. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  9010. return 2;
  9011. }
  9012. return 1;
  9013. }
  9014. #setScale(value, options) {
  9015. let scale = parseFloat(value);
  9016. if (scale > 0) {
  9017. options.preset = false;
  9018. this.#setScaleUpdatePages(scale, value, options);
  9019. } else {
  9020. const currentPage = this._pages[this._currentPageNumber - 1];
  9021. if (!currentPage) {
  9022. return;
  9023. }
  9024. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  9025. vPadding = _ui_utils.VERTICAL_PADDING;
  9026. if (this.isInPresentationMode) {
  9027. hPadding = vPadding = 4;
  9028. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  9029. hPadding *= 2;
  9030. }
  9031. } else if (this.removePageBorders) {
  9032. hPadding = vPadding = 0;
  9033. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  9034. [hPadding, vPadding] = [vPadding, hPadding];
  9035. }
  9036. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor;
  9037. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  9038. switch (value) {
  9039. case "page-actual":
  9040. scale = 1;
  9041. break;
  9042. case "page-width":
  9043. scale = pageWidthScale;
  9044. break;
  9045. case "page-height":
  9046. scale = pageHeightScale;
  9047. break;
  9048. case "page-fit":
  9049. scale = Math.min(pageWidthScale, pageHeightScale);
  9050. break;
  9051. case "auto":
  9052. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  9053. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  9054. break;
  9055. default:
  9056. console.error(`#setScale: "${value}" is an unknown zoom value.`);
  9057. return;
  9058. }
  9059. options.preset = true;
  9060. this.#setScaleUpdatePages(scale, value, options);
  9061. }
  9062. }
  9063. #resetCurrentPageView() {
  9064. const pageView = this._pages[this._currentPageNumber - 1];
  9065. if (this.isInPresentationMode) {
  9066. this.#setScale(this._currentScaleValue, {
  9067. noScroll: true
  9068. });
  9069. }
  9070. this.#scrollIntoView(pageView);
  9071. }
  9072. pageLabelToPageNumber(label) {
  9073. if (!this._pageLabels) {
  9074. return null;
  9075. }
  9076. const i = this._pageLabels.indexOf(label);
  9077. if (i < 0) {
  9078. return null;
  9079. }
  9080. return i + 1;
  9081. }
  9082. scrollPageIntoView({
  9083. pageNumber,
  9084. destArray = null,
  9085. allowNegativeOffset = false,
  9086. ignoreDestinationZoom = false
  9087. }) {
  9088. if (!this.pdfDocument) {
  9089. return;
  9090. }
  9091. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  9092. if (!pageView) {
  9093. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  9094. return;
  9095. }
  9096. if (this.isInPresentationMode || !destArray) {
  9097. this._setCurrentPageNumber(pageNumber, true);
  9098. return;
  9099. }
  9100. let x = 0,
  9101. y = 0;
  9102. let width = 0,
  9103. height = 0,
  9104. widthScale,
  9105. heightScale;
  9106. const changeOrientation = pageView.rotation % 180 !== 0;
  9107. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9108. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9109. let scale = 0;
  9110. switch (destArray[1].name) {
  9111. case "XYZ":
  9112. x = destArray[2];
  9113. y = destArray[3];
  9114. scale = destArray[4];
  9115. x = x !== null ? x : 0;
  9116. y = y !== null ? y : pageHeight;
  9117. break;
  9118. case "Fit":
  9119. case "FitB":
  9120. scale = "page-fit";
  9121. break;
  9122. case "FitH":
  9123. case "FitBH":
  9124. y = destArray[2];
  9125. scale = "page-width";
  9126. if (y === null && this._location) {
  9127. x = this._location.left;
  9128. y = this._location.top;
  9129. } else if (typeof y !== "number" || y < 0) {
  9130. y = pageHeight;
  9131. }
  9132. break;
  9133. case "FitV":
  9134. case "FitBV":
  9135. x = destArray[2];
  9136. width = pageWidth;
  9137. height = pageHeight;
  9138. scale = "page-height";
  9139. break;
  9140. case "FitR":
  9141. x = destArray[2];
  9142. y = destArray[3];
  9143. width = destArray[4] - x;
  9144. height = destArray[5] - y;
  9145. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  9146. vPadding = _ui_utils.VERTICAL_PADDING;
  9147. if (this.removePageBorders) {
  9148. hPadding = vPadding = 0;
  9149. }
  9150. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9151. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  9152. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  9153. break;
  9154. default:
  9155. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  9156. return;
  9157. }
  9158. if (!ignoreDestinationZoom) {
  9159. if (scale && scale !== this._currentScale) {
  9160. this.currentScaleValue = scale;
  9161. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  9162. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  9163. }
  9164. }
  9165. if (scale === "page-fit" && !destArray[4]) {
  9166. this.#scrollIntoView(pageView);
  9167. return;
  9168. }
  9169. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  9170. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  9171. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  9172. if (!allowNegativeOffset) {
  9173. left = Math.max(left, 0);
  9174. top = Math.max(top, 0);
  9175. }
  9176. this.#scrollIntoView(pageView, {
  9177. left,
  9178. top
  9179. });
  9180. }
  9181. _updateLocation(firstPage) {
  9182. const currentScale = this._currentScale;
  9183. const currentScaleValue = this._currentScaleValue;
  9184. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  9185. const pageNumber = firstPage.id;
  9186. const currentPageView = this._pages[pageNumber - 1];
  9187. const container = this.container;
  9188. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  9189. const intLeft = Math.round(topLeft[0]);
  9190. const intTop = Math.round(topLeft[1]);
  9191. let pdfOpenParams = `#page=${pageNumber}`;
  9192. if (!this.isInPresentationMode) {
  9193. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  9194. }
  9195. this._location = {
  9196. pageNumber,
  9197. scale: normalizedScaleValue,
  9198. top: intTop,
  9199. left: intLeft,
  9200. rotation: this._pagesRotation,
  9201. pdfOpenParams
  9202. };
  9203. }
  9204. update() {
  9205. const visible = this._getVisiblePages();
  9206. const visiblePages = visible.views,
  9207. numVisiblePages = visiblePages.length;
  9208. if (numVisiblePages === 0) {
  9209. return;
  9210. }
  9211. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  9212. this.#buffer.resize(newCacheSize, visible.ids);
  9213. this.renderingQueue.renderHighestPriority(visible);
  9214. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  9215. const currentId = this._currentPageNumber;
  9216. let stillFullyVisible = false;
  9217. for (const page of visiblePages) {
  9218. if (page.percent < 100) {
  9219. break;
  9220. }
  9221. if (page.id === currentId && isSimpleLayout) {
  9222. stillFullyVisible = true;
  9223. break;
  9224. }
  9225. }
  9226. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  9227. this._updateLocation(visible.first);
  9228. this.eventBus.dispatch("updateviewarea", {
  9229. source: this,
  9230. location: this._location
  9231. });
  9232. }
  9233. containsElement(element) {
  9234. return this.container.contains(element);
  9235. }
  9236. focus() {
  9237. this.container.focus();
  9238. }
  9239. get _isContainerRtl() {
  9240. return getComputedStyle(this.container).direction === "rtl";
  9241. }
  9242. get isInPresentationMode() {
  9243. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  9244. }
  9245. get isChangingPresentationMode() {
  9246. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  9247. }
  9248. get isHorizontalScrollbarEnabled() {
  9249. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  9250. }
  9251. get isVerticalScrollbarEnabled() {
  9252. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  9253. }
  9254. _getVisiblePages() {
  9255. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  9256. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  9257. rtl = horizontal && this._isContainerRtl;
  9258. return (0, _ui_utils.getVisibleElements)({
  9259. scrollEl: this.container,
  9260. views,
  9261. sortByVisibility: true,
  9262. horizontal,
  9263. rtl
  9264. });
  9265. }
  9266. cleanup() {
  9267. for (const pageView of this._pages) {
  9268. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  9269. pageView.reset();
  9270. }
  9271. }
  9272. }
  9273. _cancelRendering() {
  9274. for (const pageView of this._pages) {
  9275. pageView.cancelRendering();
  9276. }
  9277. }
  9278. async #ensurePdfPageLoaded(pageView) {
  9279. if (pageView.pdfPage) {
  9280. return pageView.pdfPage;
  9281. }
  9282. try {
  9283. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  9284. if (!pageView.pdfPage) {
  9285. pageView.setPdfPage(pdfPage);
  9286. }
  9287. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  9288. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  9289. }
  9290. return pdfPage;
  9291. } catch (reason) {
  9292. console.error("Unable to get page for page view", reason);
  9293. return null;
  9294. }
  9295. }
  9296. #getScrollAhead(visible) {
  9297. if (visible.first?.id === 1) {
  9298. return true;
  9299. } else if (visible.last?.id === this.pagesCount) {
  9300. return false;
  9301. }
  9302. switch (this._scrollMode) {
  9303. case _ui_utils.ScrollMode.PAGE:
  9304. return this.#scrollModePageState.scrollDown;
  9305. case _ui_utils.ScrollMode.HORIZONTAL:
  9306. return this.scroll.right;
  9307. }
  9308. return this.scroll.down;
  9309. }
  9310. forceRendering(currentlyVisiblePages) {
  9311. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9312. const scrollAhead = this.#getScrollAhead(visiblePages);
  9313. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9314. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9315. if (pageView) {
  9316. this.#ensurePdfPageLoaded(pageView).then(() => {
  9317. this.renderingQueue.renderView(pageView);
  9318. });
  9319. return true;
  9320. }
  9321. return false;
  9322. }
  9323. get hasEqualPageSizes() {
  9324. const firstPageView = this._pages[0];
  9325. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  9326. const pageView = this._pages[i];
  9327. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9328. return false;
  9329. }
  9330. }
  9331. return true;
  9332. }
  9333. getPagesOverview() {
  9334. let initialOrientation;
  9335. return this._pages.map(pageView => {
  9336. const viewport = pageView.pdfPage.getViewport({
  9337. scale: 1
  9338. });
  9339. const orientation = (0, _ui_utils.isPortraitOrientation)(viewport);
  9340. if (initialOrientation === undefined) {
  9341. initialOrientation = orientation;
  9342. } else if (this.enablePrintAutoRotate && orientation !== initialOrientation) {
  9343. return {
  9344. width: viewport.height,
  9345. height: viewport.width,
  9346. rotation: (viewport.rotation - 90) % 360
  9347. };
  9348. }
  9349. return {
  9350. width: viewport.width,
  9351. height: viewport.height,
  9352. rotation: viewport.rotation
  9353. };
  9354. });
  9355. }
  9356. get optionalContentConfigPromise() {
  9357. if (!this.pdfDocument) {
  9358. return Promise.resolve(null);
  9359. }
  9360. if (!this._optionalContentConfigPromise) {
  9361. console.error("optionalContentConfigPromise: Not initialized yet.");
  9362. return this.pdfDocument.getOptionalContentConfig();
  9363. }
  9364. return this._optionalContentConfigPromise;
  9365. }
  9366. set optionalContentConfigPromise(promise) {
  9367. if (!(promise instanceof Promise)) {
  9368. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  9369. }
  9370. if (!this.pdfDocument) {
  9371. return;
  9372. }
  9373. if (!this._optionalContentConfigPromise) {
  9374. return;
  9375. }
  9376. this._optionalContentConfigPromise = promise;
  9377. this.refresh(false, {
  9378. optionalContentConfigPromise: promise
  9379. });
  9380. this.eventBus.dispatch("optionalcontentconfigchanged", {
  9381. source: this,
  9382. promise
  9383. });
  9384. }
  9385. get scrollMode() {
  9386. return this._scrollMode;
  9387. }
  9388. set scrollMode(mode) {
  9389. if (this._scrollMode === mode) {
  9390. return;
  9391. }
  9392. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9393. throw new Error(`Invalid scroll mode: ${mode}`);
  9394. }
  9395. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9396. return;
  9397. }
  9398. this._previousScrollMode = this._scrollMode;
  9399. this._scrollMode = mode;
  9400. this.eventBus.dispatch("scrollmodechanged", {
  9401. source: this,
  9402. mode
  9403. });
  9404. this._updateScrollMode(this._currentPageNumber);
  9405. }
  9406. _updateScrollMode(pageNumber = null) {
  9407. const scrollMode = this._scrollMode,
  9408. viewer = this.viewer;
  9409. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9410. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9411. if (!this.pdfDocument || !pageNumber) {
  9412. return;
  9413. }
  9414. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9415. this.#ensurePageViewVisible();
  9416. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9417. this._updateSpreadMode();
  9418. }
  9419. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9420. this.#setScale(this._currentScaleValue, {
  9421. noScroll: true
  9422. });
  9423. }
  9424. this._setCurrentPageNumber(pageNumber, true);
  9425. this.update();
  9426. }
  9427. get spreadMode() {
  9428. return this._spreadMode;
  9429. }
  9430. set spreadMode(mode) {
  9431. if (this._spreadMode === mode) {
  9432. return;
  9433. }
  9434. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9435. throw new Error(`Invalid spread mode: ${mode}`);
  9436. }
  9437. this._spreadMode = mode;
  9438. this.eventBus.dispatch("spreadmodechanged", {
  9439. source: this,
  9440. mode
  9441. });
  9442. this._updateSpreadMode(this._currentPageNumber);
  9443. }
  9444. _updateSpreadMode(pageNumber = null) {
  9445. if (!this.pdfDocument) {
  9446. return;
  9447. }
  9448. const viewer = this.viewer,
  9449. pages = this._pages;
  9450. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9451. this.#ensurePageViewVisible();
  9452. } else {
  9453. viewer.textContent = "";
  9454. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9455. for (const pageView of this._pages) {
  9456. viewer.append(pageView.div);
  9457. }
  9458. } else {
  9459. const parity = this._spreadMode - 1;
  9460. let spread = null;
  9461. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9462. if (spread === null) {
  9463. spread = document.createElement("div");
  9464. spread.className = "spread";
  9465. viewer.append(spread);
  9466. } else if (i % 2 === parity) {
  9467. spread = spread.cloneNode(false);
  9468. viewer.append(spread);
  9469. }
  9470. spread.append(pages[i].div);
  9471. }
  9472. }
  9473. }
  9474. if (!pageNumber) {
  9475. return;
  9476. }
  9477. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9478. this.#setScale(this._currentScaleValue, {
  9479. noScroll: true
  9480. });
  9481. }
  9482. this._setCurrentPageNumber(pageNumber, true);
  9483. this.update();
  9484. }
  9485. _getPageAdvance(currentPageNumber, previous = false) {
  9486. switch (this._scrollMode) {
  9487. case _ui_utils.ScrollMode.WRAPPED:
  9488. {
  9489. const {
  9490. views
  9491. } = this._getVisiblePages(),
  9492. pageLayout = new Map();
  9493. for (const {
  9494. id,
  9495. y,
  9496. percent,
  9497. widthPercent
  9498. } of views) {
  9499. if (percent === 0 || widthPercent < 100) {
  9500. continue;
  9501. }
  9502. let yArray = pageLayout.get(y);
  9503. if (!yArray) {
  9504. pageLayout.set(y, yArray ||= []);
  9505. }
  9506. yArray.push(id);
  9507. }
  9508. for (const yArray of pageLayout.values()) {
  9509. const currentIndex = yArray.indexOf(currentPageNumber);
  9510. if (currentIndex === -1) {
  9511. continue;
  9512. }
  9513. const numPages = yArray.length;
  9514. if (numPages === 1) {
  9515. break;
  9516. }
  9517. if (previous) {
  9518. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9519. const currentId = yArray[i],
  9520. expectedId = yArray[i + 1] - 1;
  9521. if (currentId < expectedId) {
  9522. return currentPageNumber - expectedId;
  9523. }
  9524. }
  9525. } else {
  9526. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9527. const currentId = yArray[i],
  9528. expectedId = yArray[i - 1] + 1;
  9529. if (currentId > expectedId) {
  9530. return expectedId - currentPageNumber;
  9531. }
  9532. }
  9533. }
  9534. if (previous) {
  9535. const firstId = yArray[0];
  9536. if (firstId < currentPageNumber) {
  9537. return currentPageNumber - firstId + 1;
  9538. }
  9539. } else {
  9540. const lastId = yArray[numPages - 1];
  9541. if (lastId > currentPageNumber) {
  9542. return lastId - currentPageNumber + 1;
  9543. }
  9544. }
  9545. break;
  9546. }
  9547. break;
  9548. }
  9549. case _ui_utils.ScrollMode.HORIZONTAL:
  9550. {
  9551. break;
  9552. }
  9553. case _ui_utils.ScrollMode.PAGE:
  9554. case _ui_utils.ScrollMode.VERTICAL:
  9555. {
  9556. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9557. break;
  9558. }
  9559. const parity = this._spreadMode - 1;
  9560. if (previous && currentPageNumber % 2 !== parity) {
  9561. break;
  9562. } else if (!previous && currentPageNumber % 2 === parity) {
  9563. break;
  9564. }
  9565. const {
  9566. views
  9567. } = this._getVisiblePages(),
  9568. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9569. for (const {
  9570. id,
  9571. percent,
  9572. widthPercent
  9573. } of views) {
  9574. if (id !== expectedId) {
  9575. continue;
  9576. }
  9577. if (percent > 0 && widthPercent === 100) {
  9578. return 2;
  9579. }
  9580. break;
  9581. }
  9582. break;
  9583. }
  9584. }
  9585. return 1;
  9586. }
  9587. nextPage() {
  9588. const currentPageNumber = this._currentPageNumber,
  9589. pagesCount = this.pagesCount;
  9590. if (currentPageNumber >= pagesCount) {
  9591. return false;
  9592. }
  9593. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9594. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9595. return true;
  9596. }
  9597. previousPage() {
  9598. const currentPageNumber = this._currentPageNumber;
  9599. if (currentPageNumber <= 1) {
  9600. return false;
  9601. }
  9602. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9603. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9604. return true;
  9605. }
  9606. increaseScale({
  9607. drawingDelay,
  9608. scaleFactor,
  9609. steps
  9610. } = {}) {
  9611. if (!this.pdfDocument) {
  9612. return;
  9613. }
  9614. let newScale = this._currentScale;
  9615. if (scaleFactor > 1) {
  9616. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  9617. } else {
  9618. steps ??= 1;
  9619. do {
  9620. newScale = Math.ceil((newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
  9621. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9622. }
  9623. this.#setScale(Math.min(_ui_utils.MAX_SCALE, newScale), {
  9624. noScroll: false,
  9625. drawingDelay
  9626. });
  9627. }
  9628. decreaseScale({
  9629. drawingDelay,
  9630. scaleFactor,
  9631. steps
  9632. } = {}) {
  9633. if (!this.pdfDocument) {
  9634. return;
  9635. }
  9636. let newScale = this._currentScale;
  9637. if (scaleFactor > 0 && scaleFactor < 1) {
  9638. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  9639. } else {
  9640. steps ??= 1;
  9641. do {
  9642. newScale = Math.floor((newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
  9643. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9644. }
  9645. this.#setScale(Math.max(_ui_utils.MIN_SCALE, newScale), {
  9646. noScroll: false,
  9647. drawingDelay
  9648. });
  9649. }
  9650. #updateContainerHeightCss(height = this.container.clientHeight) {
  9651. if (height !== this.#previousContainerHeight) {
  9652. this.#previousContainerHeight = height;
  9653. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  9654. }
  9655. }
  9656. #resizeObserverCallback(entries) {
  9657. for (const entry of entries) {
  9658. if (entry.target === this.container) {
  9659. this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
  9660. this.#containerTopLeft = null;
  9661. break;
  9662. }
  9663. }
  9664. }
  9665. get containerTopLeft() {
  9666. return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
  9667. }
  9668. get annotationEditorMode() {
  9669. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  9670. }
  9671. set annotationEditorMode(mode) {
  9672. if (!this.#annotationEditorUIManager) {
  9673. throw new Error(`The AnnotationEditor is not enabled.`);
  9674. }
  9675. if (this.#annotationEditorMode === mode) {
  9676. return;
  9677. }
  9678. if (!isValidAnnotationEditorMode(mode)) {
  9679. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  9680. }
  9681. if (!this.pdfDocument) {
  9682. return;
  9683. }
  9684. this.#annotationEditorMode = mode;
  9685. this.eventBus.dispatch("annotationeditormodechanged", {
  9686. source: this,
  9687. mode
  9688. });
  9689. this.#annotationEditorUIManager.updateMode(mode);
  9690. }
  9691. set annotationEditorParams({
  9692. type,
  9693. value
  9694. }) {
  9695. if (!this.#annotationEditorUIManager) {
  9696. throw new Error(`The AnnotationEditor is not enabled.`);
  9697. }
  9698. this.#annotationEditorUIManager.updateParams(type, value);
  9699. }
  9700. refresh(noUpdate = false, updateArgs = Object.create(null)) {
  9701. if (!this.pdfDocument) {
  9702. return;
  9703. }
  9704. for (const pageView of this._pages) {
  9705. pageView.update(updateArgs);
  9706. }
  9707. if (this.#scaleTimeoutId !== null) {
  9708. clearTimeout(this.#scaleTimeoutId);
  9709. this.#scaleTimeoutId = null;
  9710. }
  9711. if (!noUpdate) {
  9712. this.update();
  9713. }
  9714. }
  9715. }
  9716. exports.PDFViewer = PDFViewer;
  9717. /***/ }),
  9718. /* 29 */
  9719. /***/ ((__unused_webpack_module, exports) => {
  9720. Object.defineProperty(exports, "__esModule", ({
  9721. value: true
  9722. }));
  9723. exports.NullL10n = void 0;
  9724. exports.fixupLangCode = fixupLangCode;
  9725. exports.getL10nFallback = getL10nFallback;
  9726. const DEFAULT_L10N_STRINGS = {
  9727. of_pages: "of {{pagesCount}}",
  9728. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9729. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9730. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9731. document_properties_date_string: "{{date}}, {{time}}",
  9732. document_properties_page_size_unit_inches: "in",
  9733. document_properties_page_size_unit_millimeters: "mm",
  9734. document_properties_page_size_orientation_portrait: "portrait",
  9735. document_properties_page_size_orientation_landscape: "landscape",
  9736. document_properties_page_size_name_a3: "A3",
  9737. document_properties_page_size_name_a4: "A4",
  9738. document_properties_page_size_name_letter: "Letter",
  9739. document_properties_page_size_name_legal: "Legal",
  9740. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9741. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9742. document_properties_linearized_yes: "Yes",
  9743. document_properties_linearized_no: "No",
  9744. additional_layers: "Additional Layers",
  9745. page_landmark: "Page {{page}}",
  9746. thumb_page_title: "Page {{page}}",
  9747. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9748. find_reached_top: "Reached top of document, continued from bottom",
  9749. find_reached_bottom: "Reached end of document, continued from top",
  9750. "find_match_count[one]": "{{current}} of {{total}} match",
  9751. "find_match_count[other]": "{{current}} of {{total}} matches",
  9752. "find_match_count_limit[one]": "More than {{limit}} match",
  9753. "find_match_count_limit[other]": "More than {{limit}} matches",
  9754. find_not_found: "Phrase not found",
  9755. page_scale_width: "Page Width",
  9756. page_scale_fit: "Page Fit",
  9757. page_scale_auto: "Automatic Zoom",
  9758. page_scale_actual: "Actual Size",
  9759. page_scale_percent: "{{scale}}%",
  9760. loading_error: "An error occurred while loading the PDF.",
  9761. invalid_file_error: "Invalid or corrupted PDF file.",
  9762. missing_file_error: "Missing PDF file.",
  9763. unexpected_response_error: "Unexpected server response.",
  9764. rendering_error: "An error occurred while rendering the page.",
  9765. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9766. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9767. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  9768. free_text2_default_content: "Start typing…",
  9769. editor_free_text2_aria_label: "Text Editor",
  9770. editor_ink2_aria_label: "Draw Editor",
  9771. editor_ink_canvas_aria_label: "User-created image"
  9772. };
  9773. {
  9774. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  9775. }
  9776. function getL10nFallback(key, args) {
  9777. switch (key) {
  9778. case "find_match_count":
  9779. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9780. break;
  9781. case "find_match_count_limit":
  9782. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9783. break;
  9784. }
  9785. return DEFAULT_L10N_STRINGS[key] || "";
  9786. }
  9787. const PARTIAL_LANG_CODES = {
  9788. en: "en-US",
  9789. es: "es-ES",
  9790. fy: "fy-NL",
  9791. ga: "ga-IE",
  9792. gu: "gu-IN",
  9793. hi: "hi-IN",
  9794. hy: "hy-AM",
  9795. nb: "nb-NO",
  9796. ne: "ne-NP",
  9797. nn: "nn-NO",
  9798. pa: "pa-IN",
  9799. pt: "pt-PT",
  9800. sv: "sv-SE",
  9801. zh: "zh-CN"
  9802. };
  9803. function fixupLangCode(langCode) {
  9804. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9805. }
  9806. function formatL10nValue(text, args) {
  9807. if (!args) {
  9808. return text;
  9809. }
  9810. return text.replaceAll(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9811. return name in args ? args[name] : "{{" + name + "}}";
  9812. });
  9813. }
  9814. const NullL10n = {
  9815. async getLanguage() {
  9816. return "en-us";
  9817. },
  9818. async getDirection() {
  9819. return "ltr";
  9820. },
  9821. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9822. return formatL10nValue(fallback, args);
  9823. },
  9824. async translate(element) {}
  9825. };
  9826. exports.NullL10n = NullL10n;
  9827. /***/ }),
  9828. /* 30 */
  9829. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9830. Object.defineProperty(exports, "__esModule", ({
  9831. value: true
  9832. }));
  9833. exports.PDFPageView = void 0;
  9834. var _pdfjsLib = __webpack_require__(4);
  9835. var _ui_utils = __webpack_require__(3);
  9836. var _annotation_editor_layer_builder = __webpack_require__(31);
  9837. var _annotation_layer_builder = __webpack_require__(32);
  9838. var _app_options = __webpack_require__(5);
  9839. var _l10n_utils = __webpack_require__(29);
  9840. var _pdf_link_service = __webpack_require__(7);
  9841. var _struct_tree_layer_builder = __webpack_require__(33);
  9842. var _text_accessibility = __webpack_require__(34);
  9843. var _text_highlighter = __webpack_require__(35);
  9844. var _text_layer_builder = __webpack_require__(36);
  9845. var _xfa_layer_builder = __webpack_require__(37);
  9846. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9847. const DEFAULT_LAYER_PROPERTIES = () => {
  9848. return null;
  9849. };
  9850. class PDFPageView {
  9851. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9852. #layerProperties = null;
  9853. #loadingId = null;
  9854. #previousRotation = null;
  9855. #renderError = null;
  9856. #renderingState = _ui_utils.RenderingStates.INITIAL;
  9857. #textLayerMode = _ui_utils.TextLayerMode.ENABLE;
  9858. #useThumbnailCanvas = {
  9859. initialOptionalContent: true,
  9860. regularAnnotations: true
  9861. };
  9862. #viewportMap = new WeakMap();
  9863. constructor(options) {
  9864. const container = options.container;
  9865. const defaultViewport = options.defaultViewport;
  9866. this.id = options.id;
  9867. this.renderingId = "page" + this.id;
  9868. this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
  9869. this.pdfPage = null;
  9870. this.pageLabel = null;
  9871. this.rotation = 0;
  9872. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9873. this.viewport = defaultViewport;
  9874. this.pdfPageRotate = defaultViewport.rotation;
  9875. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9876. this.hasRestrictedScaling = false;
  9877. this.#textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9878. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9879. this.imageResourcesPath = options.imageResourcesPath || "";
  9880. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9881. this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
  9882. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9883. this.pageColors = options.pageColors || null;
  9884. this.eventBus = options.eventBus;
  9885. this.renderingQueue = options.renderingQueue;
  9886. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9887. this.renderTask = null;
  9888. this.resume = null;
  9889. this._isStandalone = !this.renderingQueue?.hasViewer();
  9890. this._annotationCanvasMap = null;
  9891. this.annotationLayer = null;
  9892. this.annotationEditorLayer = null;
  9893. this.textLayer = null;
  9894. this.zoomLayer = null;
  9895. this.xfaLayer = null;
  9896. this.structTreeLayer = null;
  9897. const div = document.createElement("div");
  9898. div.className = "page";
  9899. div.setAttribute("data-page-number", this.id);
  9900. div.setAttribute("role", "region");
  9901. this.l10n.get("page_landmark", {
  9902. page: this.id
  9903. }).then(msg => {
  9904. div.setAttribute("aria-label", msg);
  9905. });
  9906. this.div = div;
  9907. this.#setDimensions();
  9908. container?.append(div);
  9909. if (this._isStandalone) {
  9910. container?.style.setProperty("--scale-factor", this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  9911. const {
  9912. optionalContentConfigPromise
  9913. } = options;
  9914. if (optionalContentConfigPromise) {
  9915. optionalContentConfigPromise.then(optionalContentConfig => {
  9916. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9917. return;
  9918. }
  9919. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9920. });
  9921. }
  9922. }
  9923. }
  9924. get renderingState() {
  9925. return this.#renderingState;
  9926. }
  9927. set renderingState(state) {
  9928. if (state === this.#renderingState) {
  9929. return;
  9930. }
  9931. this.#renderingState = state;
  9932. if (this.#loadingId) {
  9933. clearTimeout(this.#loadingId);
  9934. this.#loadingId = null;
  9935. }
  9936. switch (state) {
  9937. case _ui_utils.RenderingStates.PAUSED:
  9938. this.div.classList.remove("loading");
  9939. break;
  9940. case _ui_utils.RenderingStates.RUNNING:
  9941. this.div.classList.add("loadingIcon");
  9942. this.#loadingId = setTimeout(() => {
  9943. this.div.classList.add("loading");
  9944. this.#loadingId = null;
  9945. }, 0);
  9946. break;
  9947. case _ui_utils.RenderingStates.INITIAL:
  9948. case _ui_utils.RenderingStates.FINISHED:
  9949. this.div.classList.remove("loadingIcon", "loading");
  9950. break;
  9951. }
  9952. }
  9953. #setDimensions() {
  9954. const {
  9955. viewport
  9956. } = this;
  9957. if (this.pdfPage) {
  9958. if (this.#previousRotation === viewport.rotation) {
  9959. return;
  9960. }
  9961. this.#previousRotation = viewport.rotation;
  9962. }
  9963. (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false);
  9964. }
  9965. setPdfPage(pdfPage) {
  9966. this.pdfPage = pdfPage;
  9967. this.pdfPageRotate = pdfPage.rotate;
  9968. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9969. this.viewport = pdfPage.getViewport({
  9970. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9971. rotation: totalRotation
  9972. });
  9973. this.#setDimensions();
  9974. this.reset();
  9975. }
  9976. destroy() {
  9977. this.reset();
  9978. this.pdfPage?.cleanup();
  9979. }
  9980. get _textHighlighter() {
  9981. return (0, _pdfjsLib.shadow)(this, "_textHighlighter", new _text_highlighter.TextHighlighter({
  9982. pageIndex: this.id - 1,
  9983. eventBus: this.eventBus,
  9984. findController: this.#layerProperties().findController
  9985. }));
  9986. }
  9987. async #renderAnnotationLayer() {
  9988. let error = null;
  9989. try {
  9990. await this.annotationLayer.render(this.viewport, "display");
  9991. } catch (ex) {
  9992. console.error(`#renderAnnotationLayer: "${ex}".`);
  9993. error = ex;
  9994. } finally {
  9995. this.eventBus.dispatch("annotationlayerrendered", {
  9996. source: this,
  9997. pageNumber: this.id,
  9998. error
  9999. });
  10000. }
  10001. }
  10002. async #renderAnnotationEditorLayer() {
  10003. let error = null;
  10004. try {
  10005. await this.annotationEditorLayer.render(this.viewport, "display");
  10006. } catch (ex) {
  10007. console.error(`#renderAnnotationEditorLayer: "${ex}".`);
  10008. error = ex;
  10009. } finally {
  10010. this.eventBus.dispatch("annotationeditorlayerrendered", {
  10011. source: this,
  10012. pageNumber: this.id,
  10013. error
  10014. });
  10015. }
  10016. }
  10017. async #renderXfaLayer() {
  10018. let error = null;
  10019. try {
  10020. const result = await this.xfaLayer.render(this.viewport, "display");
  10021. if (result?.textDivs && this._textHighlighter) {
  10022. this.#buildXfaTextContentItems(result.textDivs);
  10023. }
  10024. } catch (ex) {
  10025. console.error(`#renderXfaLayer: "${ex}".`);
  10026. error = ex;
  10027. } finally {
  10028. this.eventBus.dispatch("xfalayerrendered", {
  10029. source: this,
  10030. pageNumber: this.id,
  10031. error
  10032. });
  10033. }
  10034. }
  10035. async #renderTextLayer() {
  10036. const {
  10037. pdfPage,
  10038. textLayer,
  10039. viewport
  10040. } = this;
  10041. if (!textLayer) {
  10042. return;
  10043. }
  10044. let error = null;
  10045. try {
  10046. if (!textLayer.renderingDone) {
  10047. const readableStream = pdfPage.streamTextContent({
  10048. includeMarkedContent: true,
  10049. disableNormalization: true
  10050. });
  10051. textLayer.setTextContentSource(readableStream);
  10052. }
  10053. await textLayer.render(viewport);
  10054. } catch (ex) {
  10055. if (ex instanceof _pdfjsLib.AbortException) {
  10056. return;
  10057. }
  10058. console.error(`#renderTextLayer: "${ex}".`);
  10059. error = ex;
  10060. }
  10061. this.eventBus.dispatch("textlayerrendered", {
  10062. source: this,
  10063. pageNumber: this.id,
  10064. numTextDivs: textLayer.numTextDivs,
  10065. error
  10066. });
  10067. this.#renderStructTreeLayer();
  10068. }
  10069. async #renderStructTreeLayer() {
  10070. if (!this.textLayer) {
  10071. return;
  10072. }
  10073. this.structTreeLayer ||= new _struct_tree_layer_builder.StructTreeLayerBuilder();
  10074. const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
  10075. const treeDom = this.structTreeLayer?.render(tree);
  10076. if (treeDom) {
  10077. this.canvas?.append(treeDom);
  10078. }
  10079. this.structTreeLayer?.show();
  10080. }
  10081. async #buildXfaTextContentItems(textDivs) {
  10082. const text = await this.pdfPage.getTextContent();
  10083. const items = [];
  10084. for (const item of text.items) {
  10085. items.push(item.str);
  10086. }
  10087. this._textHighlighter.setTextMapping(textDivs, items);
  10088. this._textHighlighter.enable();
  10089. }
  10090. _resetZoomLayer(removeFromDOM = false) {
  10091. if (!this.zoomLayer) {
  10092. return;
  10093. }
  10094. const zoomLayerCanvas = this.zoomLayer.firstChild;
  10095. this.#viewportMap.delete(zoomLayerCanvas);
  10096. zoomLayerCanvas.width = 0;
  10097. zoomLayerCanvas.height = 0;
  10098. if (removeFromDOM) {
  10099. this.zoomLayer.remove();
  10100. }
  10101. this.zoomLayer = null;
  10102. }
  10103. reset({
  10104. keepZoomLayer = false,
  10105. keepAnnotationLayer = false,
  10106. keepAnnotationEditorLayer = false,
  10107. keepXfaLayer = false,
  10108. keepTextLayer = false
  10109. } = {}) {
  10110. this.cancelRendering({
  10111. keepAnnotationLayer,
  10112. keepAnnotationEditorLayer,
  10113. keepXfaLayer,
  10114. keepTextLayer
  10115. });
  10116. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  10117. const div = this.div;
  10118. const childNodes = div.childNodes,
  10119. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  10120. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  10121. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  10122. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
  10123. textLayerNode = keepTextLayer && this.textLayer?.div || null;
  10124. for (let i = childNodes.length - 1; i >= 0; i--) {
  10125. const node = childNodes[i];
  10126. switch (node) {
  10127. case zoomLayerNode:
  10128. case annotationLayerNode:
  10129. case annotationEditorLayerNode:
  10130. case xfaLayerNode:
  10131. case textLayerNode:
  10132. continue;
  10133. }
  10134. node.remove();
  10135. }
  10136. div.removeAttribute("data-loaded");
  10137. if (annotationLayerNode) {
  10138. this.annotationLayer.hide();
  10139. }
  10140. if (annotationEditorLayerNode) {
  10141. this.annotationEditorLayer.hide();
  10142. }
  10143. if (xfaLayerNode) {
  10144. this.xfaLayer.hide();
  10145. }
  10146. if (textLayerNode) {
  10147. this.textLayer.hide();
  10148. }
  10149. this.structTreeLayer?.hide();
  10150. if (!zoomLayerNode) {
  10151. if (this.canvas) {
  10152. this.#viewportMap.delete(this.canvas);
  10153. this.canvas.width = 0;
  10154. this.canvas.height = 0;
  10155. delete this.canvas;
  10156. }
  10157. this._resetZoomLayer();
  10158. }
  10159. }
  10160. update({
  10161. scale = 0,
  10162. rotation = null,
  10163. optionalContentConfigPromise = null,
  10164. drawingDelay = -1
  10165. }) {
  10166. this.scale = scale || this.scale;
  10167. if (typeof rotation === "number") {
  10168. this.rotation = rotation;
  10169. }
  10170. if (optionalContentConfigPromise instanceof Promise) {
  10171. this._optionalContentConfigPromise = optionalContentConfigPromise;
  10172. optionalContentConfigPromise.then(optionalContentConfig => {
  10173. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  10174. return;
  10175. }
  10176. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  10177. });
  10178. }
  10179. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  10180. this.viewport = this.viewport.clone({
  10181. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  10182. rotation: totalRotation
  10183. });
  10184. this.#setDimensions();
  10185. if (this._isStandalone) {
  10186. this.div.parentNode?.style.setProperty("--scale-factor", this.viewport.scale);
  10187. }
  10188. let isScalingRestricted = false;
  10189. if (this.canvas && this.maxCanvasPixels > 0) {
  10190. const {
  10191. width,
  10192. height
  10193. } = this.viewport;
  10194. const {
  10195. sx,
  10196. sy
  10197. } = this.outputScale;
  10198. if ((Math.floor(width) * sx | 0) * (Math.floor(height) * sy | 0) > this.maxCanvasPixels) {
  10199. isScalingRestricted = true;
  10200. }
  10201. }
  10202. const onlyCssZoom = this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted;
  10203. const postponeDrawing = !onlyCssZoom && drawingDelay >= 0 && drawingDelay < 1000;
  10204. if (this.canvas) {
  10205. if (postponeDrawing || onlyCssZoom) {
  10206. if (postponeDrawing && this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  10207. this.cancelRendering({
  10208. keepZoomLayer: true,
  10209. keepAnnotationLayer: true,
  10210. keepAnnotationEditorLayer: true,
  10211. keepXfaLayer: true,
  10212. keepTextLayer: true,
  10213. cancelExtraDelay: drawingDelay
  10214. });
  10215. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10216. }
  10217. this.cssTransform({
  10218. target: this.canvas,
  10219. redrawAnnotationLayer: true,
  10220. redrawAnnotationEditorLayer: true,
  10221. redrawXfaLayer: true,
  10222. redrawTextLayer: !postponeDrawing,
  10223. hideTextLayer: postponeDrawing
  10224. });
  10225. this.eventBus.dispatch("pagerendered", {
  10226. source: this,
  10227. pageNumber: this.id,
  10228. cssTransform: true,
  10229. timestamp: performance.now(),
  10230. error: this.#renderError
  10231. });
  10232. return;
  10233. }
  10234. if (!this.zoomLayer && !this.canvas.hidden) {
  10235. this.zoomLayer = this.canvas.parentNode;
  10236. this.zoomLayer.style.position = "absolute";
  10237. }
  10238. }
  10239. if (this.zoomLayer) {
  10240. this.cssTransform({
  10241. target: this.zoomLayer.firstChild
  10242. });
  10243. }
  10244. this.reset({
  10245. keepZoomLayer: true,
  10246. keepAnnotationLayer: true,
  10247. keepAnnotationEditorLayer: true,
  10248. keepXfaLayer: true,
  10249. keepTextLayer: true
  10250. });
  10251. }
  10252. cancelRendering({
  10253. keepAnnotationLayer = false,
  10254. keepAnnotationEditorLayer = false,
  10255. keepXfaLayer = false,
  10256. keepTextLayer = false,
  10257. cancelExtraDelay = 0
  10258. } = {}) {
  10259. if (this.renderTask) {
  10260. this.renderTask.cancel(cancelExtraDelay);
  10261. this.renderTask = null;
  10262. }
  10263. this.resume = null;
  10264. if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
  10265. this.textLayer.cancel();
  10266. this.textLayer = null;
  10267. }
  10268. if (this.structTreeLayer && !this.textLayer) {
  10269. this.structTreeLayer = null;
  10270. }
  10271. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  10272. this.annotationLayer.cancel();
  10273. this.annotationLayer = null;
  10274. this._annotationCanvasMap = null;
  10275. }
  10276. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  10277. this.annotationEditorLayer.cancel();
  10278. this.annotationEditorLayer = null;
  10279. }
  10280. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  10281. this.xfaLayer.cancel();
  10282. this.xfaLayer = null;
  10283. this._textHighlighter?.disable();
  10284. }
  10285. }
  10286. cssTransform({
  10287. target,
  10288. redrawAnnotationLayer = false,
  10289. redrawAnnotationEditorLayer = false,
  10290. redrawXfaLayer = false,
  10291. redrawTextLayer = false,
  10292. hideTextLayer = false
  10293. }) {
  10294. if (!target.hasAttribute("zooming")) {
  10295. target.setAttribute("zooming", true);
  10296. const {
  10297. style
  10298. } = target;
  10299. style.width = style.height = "";
  10300. }
  10301. const originalViewport = this.#viewportMap.get(target);
  10302. if (this.viewport !== originalViewport) {
  10303. const relativeRotation = this.viewport.rotation - originalViewport.rotation;
  10304. const absRotation = Math.abs(relativeRotation);
  10305. let scaleX = 1,
  10306. scaleY = 1;
  10307. if (absRotation === 90 || absRotation === 270) {
  10308. const {
  10309. width,
  10310. height
  10311. } = this.viewport;
  10312. scaleX = height / width;
  10313. scaleY = width / height;
  10314. }
  10315. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  10316. }
  10317. if (redrawAnnotationLayer && this.annotationLayer) {
  10318. this.#renderAnnotationLayer();
  10319. }
  10320. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  10321. this.#renderAnnotationEditorLayer();
  10322. }
  10323. if (redrawXfaLayer && this.xfaLayer) {
  10324. this.#renderXfaLayer();
  10325. }
  10326. if (this.textLayer) {
  10327. if (hideTextLayer) {
  10328. this.textLayer.hide();
  10329. this.structTreeLayer?.hide();
  10330. } else if (redrawTextLayer) {
  10331. this.#renderTextLayer();
  10332. }
  10333. }
  10334. }
  10335. get width() {
  10336. return this.viewport.width;
  10337. }
  10338. get height() {
  10339. return this.viewport.height;
  10340. }
  10341. getPagePoint(x, y) {
  10342. return this.viewport.convertToPdfPoint(x, y);
  10343. }
  10344. async #finishRenderTask(renderTask, error = null) {
  10345. if (renderTask === this.renderTask) {
  10346. this.renderTask = null;
  10347. }
  10348. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  10349. this.#renderError = null;
  10350. return;
  10351. }
  10352. this.#renderError = error;
  10353. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10354. this._resetZoomLayer(true);
  10355. this.#useThumbnailCanvas.regularAnnotations = !renderTask.separateAnnots;
  10356. this.eventBus.dispatch("pagerendered", {
  10357. source: this,
  10358. pageNumber: this.id,
  10359. cssTransform: false,
  10360. timestamp: performance.now(),
  10361. error: this.#renderError
  10362. });
  10363. if (error) {
  10364. throw error;
  10365. }
  10366. }
  10367. async draw() {
  10368. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  10369. console.error("Must be in new state before drawing");
  10370. this.reset();
  10371. }
  10372. const {
  10373. div,
  10374. l10n,
  10375. pageColors,
  10376. pdfPage,
  10377. viewport
  10378. } = this;
  10379. if (!pdfPage) {
  10380. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10381. throw new Error("pdfPage is not loaded");
  10382. }
  10383. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10384. const canvasWrapper = document.createElement("div");
  10385. canvasWrapper.classList.add("canvasWrapper");
  10386. div.append(canvasWrapper);
  10387. if (!this.textLayer && this.#textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
  10388. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  10389. this.textLayer = new _text_layer_builder.TextLayerBuilder({
  10390. highlighter: this._textHighlighter,
  10391. accessibilityManager: this._accessibilityManager,
  10392. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  10393. enablePermissions: this.#textLayerMode === _ui_utils.TextLayerMode.ENABLE_PERMISSIONS
  10394. });
  10395. div.append(this.textLayer.div);
  10396. }
  10397. if (!this.annotationLayer && this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE) {
  10398. const {
  10399. annotationStorage,
  10400. downloadManager,
  10401. enableScripting,
  10402. fieldObjectsPromise,
  10403. hasJSActionsPromise,
  10404. linkService
  10405. } = this.#layerProperties();
  10406. this._annotationCanvasMap ||= new Map();
  10407. this.annotationLayer = new _annotation_layer_builder.AnnotationLayerBuilder({
  10408. pageDiv: div,
  10409. pdfPage,
  10410. annotationStorage,
  10411. imageResourcesPath: this.imageResourcesPath,
  10412. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  10413. linkService,
  10414. downloadManager,
  10415. l10n,
  10416. enableScripting,
  10417. hasJSActionsPromise,
  10418. fieldObjectsPromise,
  10419. annotationCanvasMap: this._annotationCanvasMap,
  10420. accessibilityManager: this._accessibilityManager
  10421. });
  10422. }
  10423. const renderContinueCallback = cont => {
  10424. showCanvas?.(false);
  10425. if (this.renderingQueue && !this.renderingQueue.isHighestPriority(this)) {
  10426. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  10427. this.resume = () => {
  10428. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10429. cont();
  10430. };
  10431. return;
  10432. }
  10433. cont();
  10434. };
  10435. const {
  10436. width,
  10437. height
  10438. } = viewport;
  10439. const canvas = document.createElement("canvas");
  10440. canvas.setAttribute("role", "presentation");
  10441. canvas.hidden = true;
  10442. const hasHCM = !!(pageColors?.background && pageColors?.foreground);
  10443. let showCanvas = isLastShow => {
  10444. if (!hasHCM || isLastShow) {
  10445. canvas.hidden = false;
  10446. showCanvas = null;
  10447. }
  10448. };
  10449. canvasWrapper.append(canvas);
  10450. this.canvas = canvas;
  10451. const ctx = canvas.getContext("2d", {
  10452. alpha: false
  10453. });
  10454. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  10455. if (this.useOnlyCssZoom) {
  10456. const actualSizeViewport = viewport.clone({
  10457. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10458. });
  10459. outputScale.sx *= actualSizeViewport.width / width;
  10460. outputScale.sy *= actualSizeViewport.height / height;
  10461. }
  10462. if (this.maxCanvasPixels > 0) {
  10463. const pixelsInViewport = width * height;
  10464. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  10465. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  10466. outputScale.sx = maxScale;
  10467. outputScale.sy = maxScale;
  10468. this.hasRestrictedScaling = true;
  10469. } else {
  10470. this.hasRestrictedScaling = false;
  10471. }
  10472. }
  10473. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  10474. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  10475. canvas.width = (0, _ui_utils.roundToDivide)(width * outputScale.sx, sfx[0]);
  10476. canvas.height = (0, _ui_utils.roundToDivide)(height * outputScale.sy, sfy[0]);
  10477. const {
  10478. style
  10479. } = canvas;
  10480. style.width = (0, _ui_utils.roundToDivide)(width, sfx[1]) + "px";
  10481. style.height = (0, _ui_utils.roundToDivide)(height, sfy[1]) + "px";
  10482. this.#viewportMap.set(canvas, viewport);
  10483. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10484. const renderContext = {
  10485. canvasContext: ctx,
  10486. transform,
  10487. viewport,
  10488. annotationMode: this.#annotationMode,
  10489. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10490. annotationCanvasMap: this._annotationCanvasMap,
  10491. pageColors
  10492. };
  10493. const renderTask = this.renderTask = this.pdfPage.render(renderContext);
  10494. renderTask.onContinue = renderContinueCallback;
  10495. const resultPromise = renderTask.promise.then(async () => {
  10496. showCanvas?.(true);
  10497. await this.#finishRenderTask(renderTask);
  10498. this.#renderTextLayer();
  10499. if (this.annotationLayer) {
  10500. await this.#renderAnnotationLayer();
  10501. }
  10502. if (!this.annotationEditorLayer) {
  10503. const {
  10504. annotationEditorUIManager
  10505. } = this.#layerProperties();
  10506. if (!annotationEditorUIManager) {
  10507. return;
  10508. }
  10509. this.annotationEditorLayer = new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  10510. uiManager: annotationEditorUIManager,
  10511. pageDiv: div,
  10512. pdfPage,
  10513. l10n,
  10514. accessibilityManager: this._accessibilityManager
  10515. });
  10516. }
  10517. this.#renderAnnotationEditorLayer();
  10518. }, error => {
  10519. if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
  10520. showCanvas?.(true);
  10521. }
  10522. return this.#finishRenderTask(renderTask, error);
  10523. });
  10524. if (pdfPage.isPureXfa) {
  10525. if (!this.xfaLayer) {
  10526. const {
  10527. annotationStorage,
  10528. linkService
  10529. } = this.#layerProperties();
  10530. this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({
  10531. pageDiv: div,
  10532. pdfPage,
  10533. annotationStorage,
  10534. linkService
  10535. });
  10536. } else if (this.xfaLayer.div) {
  10537. div.append(this.xfaLayer.div);
  10538. }
  10539. this.#renderXfaLayer();
  10540. }
  10541. div.setAttribute("data-loaded", true);
  10542. this.eventBus.dispatch("pagerender", {
  10543. source: this,
  10544. pageNumber: this.id
  10545. });
  10546. return resultPromise;
  10547. }
  10548. setPageLabel(label) {
  10549. this.pageLabel = typeof label === "string" ? label : null;
  10550. if (this.pageLabel !== null) {
  10551. this.div.setAttribute("data-page-label", this.pageLabel);
  10552. } else {
  10553. this.div.removeAttribute("data-page-label");
  10554. }
  10555. }
  10556. get thumbnailCanvas() {
  10557. const {
  10558. initialOptionalContent,
  10559. regularAnnotations
  10560. } = this.#useThumbnailCanvas;
  10561. return initialOptionalContent && regularAnnotations ? this.canvas : null;
  10562. }
  10563. }
  10564. exports.PDFPageView = PDFPageView;
  10565. /***/ }),
  10566. /* 31 */
  10567. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10568. Object.defineProperty(exports, "__esModule", ({
  10569. value: true
  10570. }));
  10571. exports.AnnotationEditorLayerBuilder = void 0;
  10572. var _pdfjsLib = __webpack_require__(4);
  10573. var _l10n_utils = __webpack_require__(29);
  10574. class AnnotationEditorLayerBuilder {
  10575. #uiManager;
  10576. constructor(options) {
  10577. this.pageDiv = options.pageDiv;
  10578. this.pdfPage = options.pdfPage;
  10579. this.accessibilityManager = options.accessibilityManager;
  10580. this.l10n = options.l10n || _l10n_utils.NullL10n;
  10581. this.annotationEditorLayer = null;
  10582. this.div = null;
  10583. this._cancelled = false;
  10584. this.#uiManager = options.uiManager;
  10585. }
  10586. async render(viewport, intent = "display") {
  10587. if (intent !== "display") {
  10588. return;
  10589. }
  10590. if (this._cancelled) {
  10591. return;
  10592. }
  10593. const clonedViewport = viewport.clone({
  10594. dontFlip: true
  10595. });
  10596. if (this.div) {
  10597. this.annotationEditorLayer.update({
  10598. viewport: clonedViewport
  10599. });
  10600. this.show();
  10601. return;
  10602. }
  10603. const div = this.div = document.createElement("div");
  10604. div.className = "annotationEditorLayer";
  10605. div.tabIndex = 0;
  10606. div.hidden = true;
  10607. this.pageDiv.append(div);
  10608. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  10609. uiManager: this.#uiManager,
  10610. div,
  10611. accessibilityManager: this.accessibilityManager,
  10612. pageIndex: this.pdfPage.pageNumber - 1,
  10613. l10n: this.l10n,
  10614. viewport: clonedViewport
  10615. });
  10616. const parameters = {
  10617. viewport: clonedViewport,
  10618. div,
  10619. annotations: null,
  10620. intent
  10621. };
  10622. this.annotationEditorLayer.render(parameters);
  10623. this.show();
  10624. }
  10625. cancel() {
  10626. this._cancelled = true;
  10627. if (!this.div) {
  10628. return;
  10629. }
  10630. this.pageDiv = null;
  10631. this.annotationEditorLayer.destroy();
  10632. this.div.remove();
  10633. }
  10634. hide() {
  10635. if (!this.div) {
  10636. return;
  10637. }
  10638. this.div.hidden = true;
  10639. }
  10640. show() {
  10641. if (!this.div || this.annotationEditorLayer.isEmpty) {
  10642. return;
  10643. }
  10644. this.div.hidden = false;
  10645. }
  10646. }
  10647. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  10648. /***/ }),
  10649. /* 32 */
  10650. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10651. Object.defineProperty(exports, "__esModule", ({
  10652. value: true
  10653. }));
  10654. exports.AnnotationLayerBuilder = void 0;
  10655. var _pdfjsLib = __webpack_require__(4);
  10656. var _l10n_utils = __webpack_require__(29);
  10657. var _ui_utils = __webpack_require__(3);
  10658. class AnnotationLayerBuilder {
  10659. #numAnnotations = 0;
  10660. #onPresentationModeChanged = null;
  10661. constructor({
  10662. pageDiv,
  10663. pdfPage,
  10664. linkService,
  10665. downloadManager,
  10666. annotationStorage = null,
  10667. imageResourcesPath = "",
  10668. renderForms = true,
  10669. l10n = _l10n_utils.NullL10n,
  10670. enableScripting = false,
  10671. hasJSActionsPromise = null,
  10672. fieldObjectsPromise = null,
  10673. annotationCanvasMap = null,
  10674. accessibilityManager = null
  10675. }) {
  10676. this.pageDiv = pageDiv;
  10677. this.pdfPage = pdfPage;
  10678. this.linkService = linkService;
  10679. this.downloadManager = downloadManager;
  10680. this.imageResourcesPath = imageResourcesPath;
  10681. this.renderForms = renderForms;
  10682. this.l10n = l10n;
  10683. this.annotationStorage = annotationStorage;
  10684. this.enableScripting = enableScripting;
  10685. this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
  10686. this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
  10687. this._annotationCanvasMap = annotationCanvasMap;
  10688. this._accessibilityManager = accessibilityManager;
  10689. this.div = null;
  10690. this._cancelled = false;
  10691. this._eventBus = linkService.eventBus;
  10692. }
  10693. async render(viewport, intent = "display") {
  10694. if (this.div) {
  10695. if (this._cancelled || this.#numAnnotations === 0) {
  10696. return;
  10697. }
  10698. _pdfjsLib.AnnotationLayer.update({
  10699. viewport: viewport.clone({
  10700. dontFlip: true
  10701. }),
  10702. div: this.div,
  10703. annotationCanvasMap: this._annotationCanvasMap
  10704. });
  10705. return;
  10706. }
  10707. const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
  10708. intent
  10709. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  10710. if (this._cancelled) {
  10711. return;
  10712. }
  10713. this.#numAnnotations = annotations.length;
  10714. this.div = document.createElement("div");
  10715. this.div.className = "annotationLayer";
  10716. this.pageDiv.append(this.div);
  10717. if (this.#numAnnotations === 0) {
  10718. this.hide();
  10719. return;
  10720. }
  10721. _pdfjsLib.AnnotationLayer.render({
  10722. viewport: viewport.clone({
  10723. dontFlip: true
  10724. }),
  10725. div: this.div,
  10726. annotations,
  10727. page: this.pdfPage,
  10728. imageResourcesPath: this.imageResourcesPath,
  10729. renderForms: this.renderForms,
  10730. linkService: this.linkService,
  10731. downloadManager: this.downloadManager,
  10732. annotationStorage: this.annotationStorage,
  10733. enableScripting: this.enableScripting,
  10734. hasJSActions,
  10735. fieldObjects,
  10736. annotationCanvasMap: this._annotationCanvasMap,
  10737. accessibilityManager: this._accessibilityManager
  10738. });
  10739. this.l10n.translate(this.div);
  10740. if (this.linkService.isInPresentationMode) {
  10741. this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN);
  10742. }
  10743. if (!this.#onPresentationModeChanged) {
  10744. this.#onPresentationModeChanged = evt => {
  10745. this.#updatePresentationModeState(evt.state);
  10746. };
  10747. this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged);
  10748. }
  10749. }
  10750. cancel() {
  10751. this._cancelled = true;
  10752. if (this.#onPresentationModeChanged) {
  10753. this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged);
  10754. this.#onPresentationModeChanged = null;
  10755. }
  10756. }
  10757. hide() {
  10758. if (!this.div) {
  10759. return;
  10760. }
  10761. this.div.hidden = true;
  10762. }
  10763. #updatePresentationModeState(state) {
  10764. if (!this.div) {
  10765. return;
  10766. }
  10767. let disableFormElements = false;
  10768. switch (state) {
  10769. case _ui_utils.PresentationModeState.FULLSCREEN:
  10770. disableFormElements = true;
  10771. break;
  10772. case _ui_utils.PresentationModeState.NORMAL:
  10773. break;
  10774. default:
  10775. return;
  10776. }
  10777. for (const section of this.div.childNodes) {
  10778. if (section.hasAttribute("data-internal-link")) {
  10779. continue;
  10780. }
  10781. section.inert = disableFormElements;
  10782. }
  10783. }
  10784. }
  10785. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  10786. /***/ }),
  10787. /* 33 */
  10788. /***/ ((__unused_webpack_module, exports) => {
  10789. Object.defineProperty(exports, "__esModule", ({
  10790. value: true
  10791. }));
  10792. exports.StructTreeLayerBuilder = void 0;
  10793. const PDF_ROLE_TO_HTML_ROLE = {
  10794. Document: null,
  10795. DocumentFragment: null,
  10796. Part: "group",
  10797. Sect: "group",
  10798. Div: "group",
  10799. Aside: "note",
  10800. NonStruct: "none",
  10801. P: null,
  10802. H: "heading",
  10803. Title: null,
  10804. FENote: "note",
  10805. Sub: "group",
  10806. Lbl: null,
  10807. Span: null,
  10808. Em: null,
  10809. Strong: null,
  10810. Link: "link",
  10811. Annot: "note",
  10812. Form: "form",
  10813. Ruby: null,
  10814. RB: null,
  10815. RT: null,
  10816. RP: null,
  10817. Warichu: null,
  10818. WT: null,
  10819. WP: null,
  10820. L: "list",
  10821. LI: "listitem",
  10822. LBody: null,
  10823. Table: "table",
  10824. TR: "row",
  10825. TH: "columnheader",
  10826. TD: "cell",
  10827. THead: "columnheader",
  10828. TBody: null,
  10829. TFoot: null,
  10830. Caption: null,
  10831. Figure: "figure",
  10832. Formula: null,
  10833. Artifact: null
  10834. };
  10835. const HEADING_PATTERN = /^H(\d+)$/;
  10836. class StructTreeLayerBuilder {
  10837. #treeDom = undefined;
  10838. get renderingDone() {
  10839. return this.#treeDom !== undefined;
  10840. }
  10841. render(structTree) {
  10842. if (this.#treeDom !== undefined) {
  10843. return this.#treeDom;
  10844. }
  10845. const treeDom = this.#walk(structTree);
  10846. treeDom?.classList.add("structTree");
  10847. return this.#treeDom = treeDom;
  10848. }
  10849. hide() {
  10850. if (this.#treeDom && !this.#treeDom.hidden) {
  10851. this.#treeDom.hidden = true;
  10852. }
  10853. }
  10854. show() {
  10855. if (this.#treeDom?.hidden) {
  10856. this.#treeDom.hidden = false;
  10857. }
  10858. }
  10859. #setAttributes(structElement, htmlElement) {
  10860. if (structElement.alt !== undefined) {
  10861. htmlElement.setAttribute("aria-label", structElement.alt);
  10862. }
  10863. if (structElement.id !== undefined) {
  10864. htmlElement.setAttribute("aria-owns", structElement.id);
  10865. }
  10866. if (structElement.lang !== undefined) {
  10867. htmlElement.setAttribute("lang", structElement.lang);
  10868. }
  10869. }
  10870. #walk(node) {
  10871. if (!node) {
  10872. return null;
  10873. }
  10874. const element = document.createElement("span");
  10875. if ("role" in node) {
  10876. const {
  10877. role
  10878. } = node;
  10879. const match = role.match(HEADING_PATTERN);
  10880. if (match) {
  10881. element.setAttribute("role", "heading");
  10882. element.setAttribute("aria-level", match[1]);
  10883. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10884. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10885. }
  10886. }
  10887. this.#setAttributes(node, element);
  10888. if (node.children) {
  10889. if (node.children.length === 1 && "id" in node.children[0]) {
  10890. this.#setAttributes(node.children[0], element);
  10891. } else {
  10892. for (const kid of node.children) {
  10893. element.append(this.#walk(kid));
  10894. }
  10895. }
  10896. }
  10897. return element;
  10898. }
  10899. }
  10900. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10901. /***/ }),
  10902. /* 34 */
  10903. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10904. Object.defineProperty(exports, "__esModule", ({
  10905. value: true
  10906. }));
  10907. exports.TextAccessibilityManager = void 0;
  10908. var _ui_utils = __webpack_require__(3);
  10909. class TextAccessibilityManager {
  10910. #enabled = false;
  10911. #textChildren = null;
  10912. #textNodes = new Map();
  10913. #waitingElements = new Map();
  10914. setTextMapping(textDivs) {
  10915. this.#textChildren = textDivs;
  10916. }
  10917. static #compareElementPositions(e1, e2) {
  10918. const rect1 = e1.getBoundingClientRect();
  10919. const rect2 = e2.getBoundingClientRect();
  10920. if (rect1.width === 0 && rect1.height === 0) {
  10921. return +1;
  10922. }
  10923. if (rect2.width === 0 && rect2.height === 0) {
  10924. return -1;
  10925. }
  10926. const top1 = rect1.y;
  10927. const bot1 = rect1.y + rect1.height;
  10928. const mid1 = rect1.y + rect1.height / 2;
  10929. const top2 = rect2.y;
  10930. const bot2 = rect2.y + rect2.height;
  10931. const mid2 = rect2.y + rect2.height / 2;
  10932. if (mid1 <= top2 && mid2 >= bot1) {
  10933. return -1;
  10934. }
  10935. if (mid2 <= top1 && mid1 >= bot2) {
  10936. return +1;
  10937. }
  10938. const centerX1 = rect1.x + rect1.width / 2;
  10939. const centerX2 = rect2.x + rect2.width / 2;
  10940. return centerX1 - centerX2;
  10941. }
  10942. enable() {
  10943. if (this.#enabled) {
  10944. throw new Error("TextAccessibilityManager is already enabled.");
  10945. }
  10946. if (!this.#textChildren) {
  10947. throw new Error("Text divs and strings have not been set.");
  10948. }
  10949. this.#enabled = true;
  10950. this.#textChildren = this.#textChildren.slice();
  10951. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  10952. if (this.#textNodes.size > 0) {
  10953. const textChildren = this.#textChildren;
  10954. for (const [id, nodeIndex] of this.#textNodes) {
  10955. const element = document.getElementById(id);
  10956. if (!element) {
  10957. this.#textNodes.delete(id);
  10958. continue;
  10959. }
  10960. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  10961. }
  10962. }
  10963. for (const [element, isRemovable] of this.#waitingElements) {
  10964. this.addPointerInTextLayer(element, isRemovable);
  10965. }
  10966. this.#waitingElements.clear();
  10967. }
  10968. disable() {
  10969. if (!this.#enabled) {
  10970. return;
  10971. }
  10972. this.#waitingElements.clear();
  10973. this.#textChildren = null;
  10974. this.#enabled = false;
  10975. }
  10976. removePointerInTextLayer(element) {
  10977. if (!this.#enabled) {
  10978. this.#waitingElements.delete(element);
  10979. return;
  10980. }
  10981. const children = this.#textChildren;
  10982. if (!children || children.length === 0) {
  10983. return;
  10984. }
  10985. const {
  10986. id
  10987. } = element;
  10988. const nodeIndex = this.#textNodes.get(id);
  10989. if (nodeIndex === undefined) {
  10990. return;
  10991. }
  10992. const node = children[nodeIndex];
  10993. this.#textNodes.delete(id);
  10994. let owns = node.getAttribute("aria-owns");
  10995. if (owns?.includes(id)) {
  10996. owns = owns.split(" ").filter(x => x !== id).join(" ");
  10997. if (owns) {
  10998. node.setAttribute("aria-owns", owns);
  10999. } else {
  11000. node.removeAttribute("aria-owns");
  11001. node.setAttribute("role", "presentation");
  11002. }
  11003. }
  11004. }
  11005. #addIdToAriaOwns(id, node) {
  11006. const owns = node.getAttribute("aria-owns");
  11007. if (!owns?.includes(id)) {
  11008. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  11009. }
  11010. node.removeAttribute("role");
  11011. }
  11012. addPointerInTextLayer(element, isRemovable) {
  11013. const {
  11014. id
  11015. } = element;
  11016. if (!id) {
  11017. return;
  11018. }
  11019. if (!this.#enabled) {
  11020. this.#waitingElements.set(element, isRemovable);
  11021. return;
  11022. }
  11023. if (isRemovable) {
  11024. this.removePointerInTextLayer(element);
  11025. }
  11026. const children = this.#textChildren;
  11027. if (!children || children.length === 0) {
  11028. return;
  11029. }
  11030. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  11031. const nodeIndex = Math.max(0, index - 1);
  11032. this.#addIdToAriaOwns(id, children[nodeIndex]);
  11033. this.#textNodes.set(id, nodeIndex);
  11034. }
  11035. moveElementInDOM(container, element, contentElement, isRemovable) {
  11036. this.addPointerInTextLayer(contentElement, isRemovable);
  11037. if (!container.hasChildNodes()) {
  11038. container.append(element);
  11039. return;
  11040. }
  11041. const children = Array.from(container.childNodes).filter(node => node !== element);
  11042. if (children.length === 0) {
  11043. return;
  11044. }
  11045. const elementToCompare = contentElement || element;
  11046. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  11047. if (index === 0) {
  11048. children[0].before(element);
  11049. } else {
  11050. children[index - 1].after(element);
  11051. }
  11052. }
  11053. }
  11054. exports.TextAccessibilityManager = TextAccessibilityManager;
  11055. /***/ }),
  11056. /* 35 */
  11057. /***/ ((__unused_webpack_module, exports) => {
  11058. Object.defineProperty(exports, "__esModule", ({
  11059. value: true
  11060. }));
  11061. exports.TextHighlighter = void 0;
  11062. class TextHighlighter {
  11063. constructor({
  11064. findController,
  11065. eventBus,
  11066. pageIndex
  11067. }) {
  11068. this.findController = findController;
  11069. this.matches = [];
  11070. this.eventBus = eventBus;
  11071. this.pageIdx = pageIndex;
  11072. this._onUpdateTextLayerMatches = null;
  11073. this.textDivs = null;
  11074. this.textContentItemsStr = null;
  11075. this.enabled = false;
  11076. }
  11077. setTextMapping(divs, texts) {
  11078. this.textDivs = divs;
  11079. this.textContentItemsStr = texts;
  11080. }
  11081. enable() {
  11082. if (!this.textDivs || !this.textContentItemsStr) {
  11083. throw new Error("Text divs and strings have not been set.");
  11084. }
  11085. if (this.enabled) {
  11086. throw new Error("TextHighlighter is already enabled.");
  11087. }
  11088. this.enabled = true;
  11089. if (!this._onUpdateTextLayerMatches) {
  11090. this._onUpdateTextLayerMatches = evt => {
  11091. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  11092. this._updateMatches();
  11093. }
  11094. };
  11095. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11096. }
  11097. this._updateMatches();
  11098. }
  11099. disable() {
  11100. if (!this.enabled) {
  11101. return;
  11102. }
  11103. this.enabled = false;
  11104. if (this._onUpdateTextLayerMatches) {
  11105. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  11106. this._onUpdateTextLayerMatches = null;
  11107. }
  11108. this._updateMatches(true);
  11109. }
  11110. _convertMatches(matches, matchesLength) {
  11111. if (!matches) {
  11112. return [];
  11113. }
  11114. const {
  11115. textContentItemsStr
  11116. } = this;
  11117. let i = 0,
  11118. iIndex = 0;
  11119. const end = textContentItemsStr.length - 1;
  11120. const result = [];
  11121. for (let m = 0, mm = matches.length; m < mm; m++) {
  11122. let matchIdx = matches[m];
  11123. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  11124. iIndex += textContentItemsStr[i].length;
  11125. i++;
  11126. }
  11127. if (i === textContentItemsStr.length) {
  11128. console.error("Could not find a matching mapping");
  11129. }
  11130. const match = {
  11131. begin: {
  11132. divIdx: i,
  11133. offset: matchIdx - iIndex
  11134. }
  11135. };
  11136. matchIdx += matchesLength[m];
  11137. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  11138. iIndex += textContentItemsStr[i].length;
  11139. i++;
  11140. }
  11141. match.end = {
  11142. divIdx: i,
  11143. offset: matchIdx - iIndex
  11144. };
  11145. result.push(match);
  11146. }
  11147. return result;
  11148. }
  11149. _renderMatches(matches) {
  11150. if (matches.length === 0) {
  11151. return;
  11152. }
  11153. const {
  11154. findController,
  11155. pageIdx
  11156. } = this;
  11157. const {
  11158. textContentItemsStr,
  11159. textDivs
  11160. } = this;
  11161. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  11162. const selectedMatchIdx = findController.selected.matchIdx;
  11163. const highlightAll = findController.state.highlightAll;
  11164. let prevEnd = null;
  11165. const infinity = {
  11166. divIdx: -1,
  11167. offset: undefined
  11168. };
  11169. function beginText(begin, className) {
  11170. const divIdx = begin.divIdx;
  11171. textDivs[divIdx].textContent = "";
  11172. return appendTextToDiv(divIdx, 0, begin.offset, className);
  11173. }
  11174. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  11175. let div = textDivs[divIdx];
  11176. if (div.nodeType === Node.TEXT_NODE) {
  11177. const span = document.createElement("span");
  11178. div.before(span);
  11179. span.append(div);
  11180. textDivs[divIdx] = span;
  11181. div = span;
  11182. }
  11183. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  11184. const node = document.createTextNode(content);
  11185. if (className) {
  11186. const span = document.createElement("span");
  11187. span.className = `${className} appended`;
  11188. span.append(node);
  11189. div.append(span);
  11190. return className.includes("selected") ? span.offsetLeft : 0;
  11191. }
  11192. div.append(node);
  11193. return 0;
  11194. }
  11195. let i0 = selectedMatchIdx,
  11196. i1 = i0 + 1;
  11197. if (highlightAll) {
  11198. i0 = 0;
  11199. i1 = matches.length;
  11200. } else if (!isSelectedPage) {
  11201. return;
  11202. }
  11203. let lastDivIdx = -1;
  11204. let lastOffset = -1;
  11205. for (let i = i0; i < i1; i++) {
  11206. const match = matches[i];
  11207. const begin = match.begin;
  11208. if (begin.divIdx === lastDivIdx && begin.offset === lastOffset) {
  11209. continue;
  11210. }
  11211. lastDivIdx = begin.divIdx;
  11212. lastOffset = begin.offset;
  11213. const end = match.end;
  11214. const isSelected = isSelectedPage && i === selectedMatchIdx;
  11215. const highlightSuffix = isSelected ? " selected" : "";
  11216. let selectedLeft = 0;
  11217. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  11218. if (prevEnd !== null) {
  11219. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11220. }
  11221. beginText(begin);
  11222. } else {
  11223. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  11224. }
  11225. if (begin.divIdx === end.divIdx) {
  11226. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  11227. } else {
  11228. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  11229. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  11230. textDivs[n0].className = "highlight middle" + highlightSuffix;
  11231. }
  11232. beginText(end, "highlight end" + highlightSuffix);
  11233. }
  11234. prevEnd = end;
  11235. if (isSelected) {
  11236. findController.scrollMatchIntoView({
  11237. element: textDivs[begin.divIdx],
  11238. selectedLeft,
  11239. pageIndex: pageIdx,
  11240. matchIndex: selectedMatchIdx
  11241. });
  11242. }
  11243. }
  11244. if (prevEnd) {
  11245. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  11246. }
  11247. }
  11248. _updateMatches(reset = false) {
  11249. if (!this.enabled && !reset) {
  11250. return;
  11251. }
  11252. const {
  11253. findController,
  11254. matches,
  11255. pageIdx
  11256. } = this;
  11257. const {
  11258. textContentItemsStr,
  11259. textDivs
  11260. } = this;
  11261. let clearedUntilDivIdx = -1;
  11262. for (const match of matches) {
  11263. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  11264. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  11265. const div = textDivs[n];
  11266. div.textContent = textContentItemsStr[n];
  11267. div.className = "";
  11268. }
  11269. clearedUntilDivIdx = match.end.divIdx + 1;
  11270. }
  11271. if (!findController?.highlightMatches || reset) {
  11272. return;
  11273. }
  11274. const pageMatches = findController.pageMatches[pageIdx] || null;
  11275. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  11276. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  11277. this._renderMatches(this.matches);
  11278. }
  11279. }
  11280. exports.TextHighlighter = TextHighlighter;
  11281. /***/ }),
  11282. /* 36 */
  11283. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11284. Object.defineProperty(exports, "__esModule", ({
  11285. value: true
  11286. }));
  11287. exports.TextLayerBuilder = void 0;
  11288. var _pdfjsLib = __webpack_require__(4);
  11289. var _ui_utils = __webpack_require__(3);
  11290. class TextLayerBuilder {
  11291. #enablePermissions = false;
  11292. #rotation = 0;
  11293. #scale = 0;
  11294. #textContentSource = null;
  11295. constructor({
  11296. highlighter = null,
  11297. accessibilityManager = null,
  11298. isOffscreenCanvasSupported = true,
  11299. enablePermissions = false
  11300. }) {
  11301. this.textContentItemsStr = [];
  11302. this.renderingDone = false;
  11303. this.textDivs = [];
  11304. this.textDivProperties = new WeakMap();
  11305. this.textLayerRenderTask = null;
  11306. this.highlighter = highlighter;
  11307. this.accessibilityManager = accessibilityManager;
  11308. this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
  11309. this.#enablePermissions = enablePermissions === true;
  11310. this.div = document.createElement("div");
  11311. this.div.className = "textLayer";
  11312. this.hide();
  11313. }
  11314. #finishRendering() {
  11315. this.renderingDone = true;
  11316. const endOfContent = document.createElement("div");
  11317. endOfContent.className = "endOfContent";
  11318. this.div.append(endOfContent);
  11319. this.#bindMouse();
  11320. }
  11321. get numTextDivs() {
  11322. return this.textDivs.length;
  11323. }
  11324. async render(viewport) {
  11325. if (!this.#textContentSource) {
  11326. throw new Error('No "textContentSource" parameter specified.');
  11327. }
  11328. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  11329. const {
  11330. rotation
  11331. } = viewport;
  11332. if (this.renderingDone) {
  11333. const mustRotate = rotation !== this.#rotation;
  11334. const mustRescale = scale !== this.#scale;
  11335. if (mustRotate || mustRescale) {
  11336. this.hide();
  11337. (0, _pdfjsLib.updateTextLayer)({
  11338. container: this.div,
  11339. viewport,
  11340. textDivs: this.textDivs,
  11341. textDivProperties: this.textDivProperties,
  11342. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  11343. mustRescale,
  11344. mustRotate
  11345. });
  11346. this.#scale = scale;
  11347. this.#rotation = rotation;
  11348. }
  11349. this.show();
  11350. return;
  11351. }
  11352. this.cancel();
  11353. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  11354. this.accessibilityManager?.setTextMapping(this.textDivs);
  11355. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  11356. textContentSource: this.#textContentSource,
  11357. container: this.div,
  11358. viewport,
  11359. textDivs: this.textDivs,
  11360. textDivProperties: this.textDivProperties,
  11361. textContentItemsStr: this.textContentItemsStr,
  11362. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
  11363. });
  11364. await this.textLayerRenderTask.promise;
  11365. this.#finishRendering();
  11366. this.#scale = scale;
  11367. this.#rotation = rotation;
  11368. this.show();
  11369. this.accessibilityManager?.enable();
  11370. }
  11371. hide() {
  11372. if (!this.div.hidden) {
  11373. this.highlighter?.disable();
  11374. this.div.hidden = true;
  11375. }
  11376. }
  11377. show() {
  11378. if (this.div.hidden && this.renderingDone) {
  11379. this.div.hidden = false;
  11380. this.highlighter?.enable();
  11381. }
  11382. }
  11383. cancel() {
  11384. if (this.textLayerRenderTask) {
  11385. this.textLayerRenderTask.cancel();
  11386. this.textLayerRenderTask = null;
  11387. }
  11388. this.highlighter?.disable();
  11389. this.accessibilityManager?.disable();
  11390. this.textContentItemsStr.length = 0;
  11391. this.textDivs.length = 0;
  11392. this.textDivProperties = new WeakMap();
  11393. }
  11394. setTextContentSource(source) {
  11395. this.cancel();
  11396. this.#textContentSource = source;
  11397. }
  11398. #bindMouse() {
  11399. const {
  11400. div
  11401. } = this;
  11402. div.addEventListener("mousedown", evt => {
  11403. const end = div.querySelector(".endOfContent");
  11404. if (!end) {
  11405. return;
  11406. }
  11407. let adjustTop = evt.target !== div;
  11408. adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  11409. if (adjustTop) {
  11410. const divBounds = div.getBoundingClientRect();
  11411. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  11412. end.style.top = (r * 100).toFixed(2) + "%";
  11413. }
  11414. end.classList.add("active");
  11415. });
  11416. div.addEventListener("mouseup", () => {
  11417. const end = div.querySelector(".endOfContent");
  11418. if (!end) {
  11419. return;
  11420. }
  11421. end.style.top = "";
  11422. end.classList.remove("active");
  11423. });
  11424. div.addEventListener("copy", event => {
  11425. if (!this.#enablePermissions) {
  11426. const selection = document.getSelection();
  11427. event.clipboardData.setData("text/plain", (0, _ui_utils.removeNullCharacters)((0, _pdfjsLib.normalizeUnicode)(selection.toString())));
  11428. }
  11429. event.preventDefault();
  11430. event.stopPropagation();
  11431. });
  11432. }
  11433. }
  11434. exports.TextLayerBuilder = TextLayerBuilder;
  11435. /***/ }),
  11436. /* 37 */
  11437. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11438. Object.defineProperty(exports, "__esModule", ({
  11439. value: true
  11440. }));
  11441. exports.XfaLayerBuilder = void 0;
  11442. var _pdfjsLib = __webpack_require__(4);
  11443. class XfaLayerBuilder {
  11444. constructor({
  11445. pageDiv,
  11446. pdfPage,
  11447. annotationStorage = null,
  11448. linkService,
  11449. xfaHtml = null
  11450. }) {
  11451. this.pageDiv = pageDiv;
  11452. this.pdfPage = pdfPage;
  11453. this.annotationStorage = annotationStorage;
  11454. this.linkService = linkService;
  11455. this.xfaHtml = xfaHtml;
  11456. this.div = null;
  11457. this._cancelled = false;
  11458. }
  11459. async render(viewport, intent = "display") {
  11460. if (intent === "print") {
  11461. const parameters = {
  11462. viewport: viewport.clone({
  11463. dontFlip: true
  11464. }),
  11465. div: this.div,
  11466. xfaHtml: this.xfaHtml,
  11467. annotationStorage: this.annotationStorage,
  11468. linkService: this.linkService,
  11469. intent
  11470. };
  11471. const div = document.createElement("div");
  11472. this.pageDiv.append(div);
  11473. parameters.div = div;
  11474. return _pdfjsLib.XfaLayer.render(parameters);
  11475. }
  11476. const xfaHtml = await this.pdfPage.getXfa();
  11477. if (this._cancelled || !xfaHtml) {
  11478. return {
  11479. textDivs: []
  11480. };
  11481. }
  11482. const parameters = {
  11483. viewport: viewport.clone({
  11484. dontFlip: true
  11485. }),
  11486. div: this.div,
  11487. xfaHtml,
  11488. annotationStorage: this.annotationStorage,
  11489. linkService: this.linkService,
  11490. intent
  11491. };
  11492. if (this.div) {
  11493. return _pdfjsLib.XfaLayer.update(parameters);
  11494. }
  11495. this.div = document.createElement("div");
  11496. this.pageDiv.append(this.div);
  11497. parameters.div = this.div;
  11498. return _pdfjsLib.XfaLayer.render(parameters);
  11499. }
  11500. cancel() {
  11501. this._cancelled = true;
  11502. }
  11503. hide() {
  11504. if (!this.div) {
  11505. return;
  11506. }
  11507. this.div.hidden = true;
  11508. }
  11509. }
  11510. exports.XfaLayerBuilder = XfaLayerBuilder;
  11511. /***/ }),
  11512. /* 38 */
  11513. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11514. Object.defineProperty(exports, "__esModule", ({
  11515. value: true
  11516. }));
  11517. exports.SecondaryToolbar = void 0;
  11518. var _ui_utils = __webpack_require__(3);
  11519. var _pdf_viewer = __webpack_require__(28);
  11520. class SecondaryToolbar {
  11521. constructor(options, eventBus, externalServices) {
  11522. this.toolbar = options.toolbar;
  11523. this.toggleButton = options.toggleButton;
  11524. this.buttons = [{
  11525. element: options.presentationModeButton,
  11526. eventName: "presentationmode",
  11527. close: true
  11528. }, {
  11529. element: options.printButton,
  11530. eventName: "print",
  11531. close: true
  11532. }, {
  11533. element: options.downloadButton,
  11534. eventName: "download",
  11535. close: true
  11536. }, {
  11537. element: options.viewBookmarkButton,
  11538. eventName: null,
  11539. close: true
  11540. }, {
  11541. element: options.firstPageButton,
  11542. eventName: "firstpage",
  11543. close: true
  11544. }, {
  11545. element: options.lastPageButton,
  11546. eventName: "lastpage",
  11547. close: true
  11548. }, {
  11549. element: options.pageRotateCwButton,
  11550. eventName: "rotatecw",
  11551. close: false
  11552. }, {
  11553. element: options.pageRotateCcwButton,
  11554. eventName: "rotateccw",
  11555. close: false
  11556. }, {
  11557. element: options.cursorSelectToolButton,
  11558. eventName: "switchcursortool",
  11559. eventDetails: {
  11560. tool: _ui_utils.CursorTool.SELECT
  11561. },
  11562. close: true
  11563. }, {
  11564. element: options.cursorHandToolButton,
  11565. eventName: "switchcursortool",
  11566. eventDetails: {
  11567. tool: _ui_utils.CursorTool.HAND
  11568. },
  11569. close: true
  11570. }, {
  11571. element: options.scrollPageButton,
  11572. eventName: "switchscrollmode",
  11573. eventDetails: {
  11574. mode: _ui_utils.ScrollMode.PAGE
  11575. },
  11576. close: true
  11577. }, {
  11578. element: options.scrollVerticalButton,
  11579. eventName: "switchscrollmode",
  11580. eventDetails: {
  11581. mode: _ui_utils.ScrollMode.VERTICAL
  11582. },
  11583. close: true
  11584. }, {
  11585. element: options.scrollHorizontalButton,
  11586. eventName: "switchscrollmode",
  11587. eventDetails: {
  11588. mode: _ui_utils.ScrollMode.HORIZONTAL
  11589. },
  11590. close: true
  11591. }, {
  11592. element: options.scrollWrappedButton,
  11593. eventName: "switchscrollmode",
  11594. eventDetails: {
  11595. mode: _ui_utils.ScrollMode.WRAPPED
  11596. },
  11597. close: true
  11598. }, {
  11599. element: options.spreadNoneButton,
  11600. eventName: "switchspreadmode",
  11601. eventDetails: {
  11602. mode: _ui_utils.SpreadMode.NONE
  11603. },
  11604. close: true
  11605. }, {
  11606. element: options.spreadOddButton,
  11607. eventName: "switchspreadmode",
  11608. eventDetails: {
  11609. mode: _ui_utils.SpreadMode.ODD
  11610. },
  11611. close: true
  11612. }, {
  11613. element: options.spreadEvenButton,
  11614. eventName: "switchspreadmode",
  11615. eventDetails: {
  11616. mode: _ui_utils.SpreadMode.EVEN
  11617. },
  11618. close: true
  11619. }, {
  11620. element: options.documentPropertiesButton,
  11621. eventName: "documentproperties",
  11622. close: true
  11623. }];
  11624. this.buttons.push({
  11625. element: options.openFileButton,
  11626. eventName: "openfile",
  11627. close: true
  11628. });
  11629. this.items = {
  11630. firstPage: options.firstPageButton,
  11631. lastPage: options.lastPageButton,
  11632. pageRotateCw: options.pageRotateCwButton,
  11633. pageRotateCcw: options.pageRotateCcwButton
  11634. };
  11635. this.eventBus = eventBus;
  11636. this.externalServices = externalServices;
  11637. this.opened = false;
  11638. this.#bindClickListeners();
  11639. this.#bindCursorToolsListener(options);
  11640. this.#bindScrollModeListener(options);
  11641. this.#bindSpreadModeListener(options);
  11642. this.reset();
  11643. }
  11644. get isOpen() {
  11645. return this.opened;
  11646. }
  11647. setPageNumber(pageNumber) {
  11648. this.pageNumber = pageNumber;
  11649. this.#updateUIState();
  11650. }
  11651. setPagesCount(pagesCount) {
  11652. this.pagesCount = pagesCount;
  11653. this.#updateUIState();
  11654. }
  11655. reset() {
  11656. this.pageNumber = 0;
  11657. this.pagesCount = 0;
  11658. this.#updateUIState();
  11659. this.eventBus.dispatch("secondarytoolbarreset", {
  11660. source: this
  11661. });
  11662. }
  11663. #updateUIState() {
  11664. this.items.firstPage.disabled = this.pageNumber <= 1;
  11665. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  11666. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  11667. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  11668. }
  11669. #bindClickListeners() {
  11670. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  11671. for (const {
  11672. element,
  11673. eventName,
  11674. close,
  11675. eventDetails
  11676. } of this.buttons) {
  11677. element.addEventListener("click", evt => {
  11678. if (eventName !== null) {
  11679. this.eventBus.dispatch(eventName, {
  11680. source: this,
  11681. ...eventDetails
  11682. });
  11683. }
  11684. if (close) {
  11685. this.close();
  11686. }
  11687. this.externalServices.reportTelemetry({
  11688. type: "buttons",
  11689. data: {
  11690. id: element.id
  11691. }
  11692. });
  11693. });
  11694. }
  11695. }
  11696. #bindCursorToolsListener({
  11697. cursorSelectToolButton,
  11698. cursorHandToolButton
  11699. }) {
  11700. this.eventBus._on("cursortoolchanged", ({
  11701. tool
  11702. }) => {
  11703. (0, _ui_utils.toggleCheckedBtn)(cursorSelectToolButton, tool === _ui_utils.CursorTool.SELECT);
  11704. (0, _ui_utils.toggleCheckedBtn)(cursorHandToolButton, tool === _ui_utils.CursorTool.HAND);
  11705. });
  11706. }
  11707. #bindScrollModeListener({
  11708. scrollPageButton,
  11709. scrollVerticalButton,
  11710. scrollHorizontalButton,
  11711. scrollWrappedButton,
  11712. spreadNoneButton,
  11713. spreadOddButton,
  11714. spreadEvenButton
  11715. }) {
  11716. const scrollModeChanged = ({
  11717. mode
  11718. }) => {
  11719. (0, _ui_utils.toggleCheckedBtn)(scrollPageButton, mode === _ui_utils.ScrollMode.PAGE);
  11720. (0, _ui_utils.toggleCheckedBtn)(scrollVerticalButton, mode === _ui_utils.ScrollMode.VERTICAL);
  11721. (0, _ui_utils.toggleCheckedBtn)(scrollHorizontalButton, mode === _ui_utils.ScrollMode.HORIZONTAL);
  11722. (0, _ui_utils.toggleCheckedBtn)(scrollWrappedButton, mode === _ui_utils.ScrollMode.WRAPPED);
  11723. const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11724. scrollPageButton.disabled = forceScrollModePage;
  11725. scrollVerticalButton.disabled = forceScrollModePage;
  11726. scrollHorizontalButton.disabled = forceScrollModePage;
  11727. scrollWrappedButton.disabled = forceScrollModePage;
  11728. const isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  11729. spreadNoneButton.disabled = isHorizontal;
  11730. spreadOddButton.disabled = isHorizontal;
  11731. spreadEvenButton.disabled = isHorizontal;
  11732. };
  11733. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  11734. this.eventBus._on("secondarytoolbarreset", evt => {
  11735. if (evt.source === this) {
  11736. scrollModeChanged({
  11737. mode: _ui_utils.ScrollMode.VERTICAL
  11738. });
  11739. }
  11740. });
  11741. }
  11742. #bindSpreadModeListener({
  11743. spreadNoneButton,
  11744. spreadOddButton,
  11745. spreadEvenButton
  11746. }) {
  11747. const spreadModeChanged = ({
  11748. mode
  11749. }) => {
  11750. (0, _ui_utils.toggleCheckedBtn)(spreadNoneButton, mode === _ui_utils.SpreadMode.NONE);
  11751. (0, _ui_utils.toggleCheckedBtn)(spreadOddButton, mode === _ui_utils.SpreadMode.ODD);
  11752. (0, _ui_utils.toggleCheckedBtn)(spreadEvenButton, mode === _ui_utils.SpreadMode.EVEN);
  11753. };
  11754. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  11755. this.eventBus._on("secondarytoolbarreset", evt => {
  11756. if (evt.source === this) {
  11757. spreadModeChanged({
  11758. mode: _ui_utils.SpreadMode.NONE
  11759. });
  11760. }
  11761. });
  11762. }
  11763. open() {
  11764. if (this.opened) {
  11765. return;
  11766. }
  11767. this.opened = true;
  11768. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, true, this.toolbar);
  11769. }
  11770. close() {
  11771. if (!this.opened) {
  11772. return;
  11773. }
  11774. this.opened = false;
  11775. (0, _ui_utils.toggleExpandedBtn)(this.toggleButton, false, this.toolbar);
  11776. }
  11777. toggle() {
  11778. if (this.opened) {
  11779. this.close();
  11780. } else {
  11781. this.open();
  11782. }
  11783. }
  11784. }
  11785. exports.SecondaryToolbar = SecondaryToolbar;
  11786. /***/ }),
  11787. /* 39 */
  11788. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11789. Object.defineProperty(exports, "__esModule", ({
  11790. value: true
  11791. }));
  11792. exports.Toolbar = void 0;
  11793. var _ui_utils = __webpack_require__(3);
  11794. var _pdfjsLib = __webpack_require__(4);
  11795. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  11796. class Toolbar {
  11797. #wasLocalized = false;
  11798. constructor(options, eventBus, l10n) {
  11799. this.toolbar = options.container;
  11800. this.eventBus = eventBus;
  11801. this.l10n = l10n;
  11802. this.buttons = [{
  11803. element: options.previous,
  11804. eventName: "previouspage"
  11805. }, {
  11806. element: options.next,
  11807. eventName: "nextpage"
  11808. }, {
  11809. element: options.zoomIn,
  11810. eventName: "zoomin"
  11811. }, {
  11812. element: options.zoomOut,
  11813. eventName: "zoomout"
  11814. }, {
  11815. element: options.print,
  11816. eventName: "print"
  11817. }, {
  11818. element: options.download,
  11819. eventName: "download"
  11820. }, {
  11821. element: options.editorFreeTextButton,
  11822. eventName: "switchannotationeditormode",
  11823. eventDetails: {
  11824. get mode() {
  11825. const {
  11826. classList
  11827. } = options.editorFreeTextButton;
  11828. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  11829. }
  11830. }
  11831. }, {
  11832. element: options.editorInkButton,
  11833. eventName: "switchannotationeditormode",
  11834. eventDetails: {
  11835. get mode() {
  11836. const {
  11837. classList
  11838. } = options.editorInkButton;
  11839. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  11840. }
  11841. }
  11842. }];
  11843. this.buttons.push({
  11844. element: options.openFile,
  11845. eventName: "openfile"
  11846. });
  11847. this.items = {
  11848. numPages: options.numPages,
  11849. pageNumber: options.pageNumber,
  11850. scaleSelect: options.scaleSelect,
  11851. customScaleOption: options.customScaleOption,
  11852. previous: options.previous,
  11853. next: options.next,
  11854. zoomIn: options.zoomIn,
  11855. zoomOut: options.zoomOut
  11856. };
  11857. this.#bindListeners(options);
  11858. this.reset();
  11859. }
  11860. setPageNumber(pageNumber, pageLabel) {
  11861. this.pageNumber = pageNumber;
  11862. this.pageLabel = pageLabel;
  11863. this.#updateUIState(false);
  11864. }
  11865. setPagesCount(pagesCount, hasPageLabels) {
  11866. this.pagesCount = pagesCount;
  11867. this.hasPageLabels = hasPageLabels;
  11868. this.#updateUIState(true);
  11869. }
  11870. setPageScale(pageScaleValue, pageScale) {
  11871. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11872. this.pageScale = pageScale;
  11873. this.#updateUIState(false);
  11874. }
  11875. reset() {
  11876. this.pageNumber = 0;
  11877. this.pageLabel = null;
  11878. this.hasPageLabels = false;
  11879. this.pagesCount = 0;
  11880. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  11881. this.pageScale = _ui_utils.DEFAULT_SCALE;
  11882. this.#updateUIState(true);
  11883. this.updateLoadingIndicatorState();
  11884. this.eventBus.dispatch("toolbarreset", {
  11885. source: this
  11886. });
  11887. }
  11888. #bindListeners(options) {
  11889. const {
  11890. pageNumber,
  11891. scaleSelect
  11892. } = this.items;
  11893. const self = this;
  11894. for (const {
  11895. element,
  11896. eventName,
  11897. eventDetails
  11898. } of this.buttons) {
  11899. element.addEventListener("click", evt => {
  11900. if (eventName !== null) {
  11901. this.eventBus.dispatch(eventName, {
  11902. source: this,
  11903. ...eventDetails
  11904. });
  11905. }
  11906. });
  11907. }
  11908. pageNumber.addEventListener("click", function () {
  11909. this.select();
  11910. });
  11911. pageNumber.addEventListener("change", function () {
  11912. self.eventBus.dispatch("pagenumberchanged", {
  11913. source: self,
  11914. value: this.value
  11915. });
  11916. });
  11917. scaleSelect.addEventListener("change", function () {
  11918. if (this.value === "custom") {
  11919. return;
  11920. }
  11921. self.eventBus.dispatch("scalechanged", {
  11922. source: self,
  11923. value: this.value
  11924. });
  11925. });
  11926. scaleSelect.addEventListener("click", function (evt) {
  11927. const target = evt.target;
  11928. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11929. this.blur();
  11930. }
  11931. });
  11932. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  11933. this.eventBus._on("localized", () => {
  11934. this.#wasLocalized = true;
  11935. this.#adjustScaleWidth();
  11936. this.#updateUIState(true);
  11937. });
  11938. this.#bindEditorToolsListener(options);
  11939. }
  11940. #bindEditorToolsListener({
  11941. editorFreeTextButton,
  11942. editorFreeTextParamsToolbar,
  11943. editorInkButton,
  11944. editorInkParamsToolbar
  11945. }) {
  11946. const editorModeChanged = ({
  11947. mode
  11948. }) => {
  11949. (0, _ui_utils.toggleCheckedBtn)(editorFreeTextButton, mode === _pdfjsLib.AnnotationEditorType.FREETEXT, editorFreeTextParamsToolbar);
  11950. (0, _ui_utils.toggleCheckedBtn)(editorInkButton, mode === _pdfjsLib.AnnotationEditorType.INK, editorInkParamsToolbar);
  11951. const isDisable = mode === _pdfjsLib.AnnotationEditorType.DISABLE;
  11952. editorFreeTextButton.disabled = isDisable;
  11953. editorInkButton.disabled = isDisable;
  11954. };
  11955. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  11956. this.eventBus._on("toolbarreset", evt => {
  11957. if (evt.source === this) {
  11958. editorModeChanged({
  11959. mode: _pdfjsLib.AnnotationEditorType.DISABLE
  11960. });
  11961. }
  11962. });
  11963. }
  11964. #updateUIState(resetNumPages = false) {
  11965. if (!this.#wasLocalized) {
  11966. return;
  11967. }
  11968. const {
  11969. pageNumber,
  11970. pagesCount,
  11971. pageScaleValue,
  11972. pageScale,
  11973. items
  11974. } = this;
  11975. if (resetNumPages) {
  11976. if (this.hasPageLabels) {
  11977. items.pageNumber.type = "text";
  11978. } else {
  11979. items.pageNumber.type = "number";
  11980. this.l10n.get("of_pages", {
  11981. pagesCount
  11982. }).then(msg => {
  11983. items.numPages.textContent = msg;
  11984. });
  11985. }
  11986. items.pageNumber.max = pagesCount;
  11987. }
  11988. if (this.hasPageLabels) {
  11989. items.pageNumber.value = this.pageLabel;
  11990. this.l10n.get("page_of_pages", {
  11991. pageNumber,
  11992. pagesCount
  11993. }).then(msg => {
  11994. items.numPages.textContent = msg;
  11995. });
  11996. } else {
  11997. items.pageNumber.value = pageNumber;
  11998. }
  11999. items.previous.disabled = pageNumber <= 1;
  12000. items.next.disabled = pageNumber >= pagesCount;
  12001. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  12002. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  12003. this.l10n.get("page_scale_percent", {
  12004. scale: Math.round(pageScale * 10000) / 100
  12005. }).then(msg => {
  12006. let predefinedValueFound = false;
  12007. for (const option of items.scaleSelect.options) {
  12008. if (option.value !== pageScaleValue) {
  12009. option.selected = false;
  12010. continue;
  12011. }
  12012. option.selected = true;
  12013. predefinedValueFound = true;
  12014. }
  12015. if (!predefinedValueFound) {
  12016. items.customScaleOption.textContent = msg;
  12017. items.customScaleOption.selected = true;
  12018. }
  12019. });
  12020. }
  12021. updateLoadingIndicatorState(loading = false) {
  12022. const {
  12023. pageNumber
  12024. } = this.items;
  12025. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  12026. }
  12027. async #adjustScaleWidth() {
  12028. const {
  12029. items,
  12030. l10n
  12031. } = this;
  12032. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  12033. await _ui_utils.animationStarted;
  12034. const style = getComputedStyle(items.scaleSelect);
  12035. const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width"));
  12036. const canvas = document.createElement("canvas");
  12037. const ctx = canvas.getContext("2d", {
  12038. alpha: false
  12039. });
  12040. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  12041. let maxWidth = 0;
  12042. for (const predefinedValue of await predefinedValuesPromise) {
  12043. const {
  12044. width
  12045. } = ctx.measureText(predefinedValue);
  12046. if (width > maxWidth) {
  12047. maxWidth = width;
  12048. }
  12049. }
  12050. maxWidth += 0.3 * scaleSelectWidth;
  12051. if (maxWidth > scaleSelectWidth) {
  12052. const container = items.scaleSelect.parentNode;
  12053. container.style.setProperty("--scale-select-width", `${maxWidth}px`);
  12054. }
  12055. canvas.width = 0;
  12056. canvas.height = 0;
  12057. }
  12058. }
  12059. exports.Toolbar = Toolbar;
  12060. /***/ }),
  12061. /* 40 */
  12062. /***/ ((__unused_webpack_module, exports) => {
  12063. Object.defineProperty(exports, "__esModule", ({
  12064. value: true
  12065. }));
  12066. exports.ViewHistory = void 0;
  12067. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  12068. class ViewHistory {
  12069. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  12070. this.fingerprint = fingerprint;
  12071. this.cacheSize = cacheSize;
  12072. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  12073. const database = JSON.parse(databaseStr || "{}");
  12074. let index = -1;
  12075. if (!Array.isArray(database.files)) {
  12076. database.files = [];
  12077. } else {
  12078. while (database.files.length >= this.cacheSize) {
  12079. database.files.shift();
  12080. }
  12081. for (let i = 0, ii = database.files.length; i < ii; i++) {
  12082. const branch = database.files[i];
  12083. if (branch.fingerprint === this.fingerprint) {
  12084. index = i;
  12085. break;
  12086. }
  12087. }
  12088. }
  12089. if (index === -1) {
  12090. index = database.files.push({
  12091. fingerprint: this.fingerprint
  12092. }) - 1;
  12093. }
  12094. this.file = database.files[index];
  12095. this.database = database;
  12096. });
  12097. }
  12098. async _writeToStorage() {
  12099. const databaseStr = JSON.stringify(this.database);
  12100. localStorage.setItem("pdfjs.history", databaseStr);
  12101. }
  12102. async _readFromStorage() {
  12103. return localStorage.getItem("pdfjs.history");
  12104. }
  12105. async set(name, val) {
  12106. await this._initializedPromise;
  12107. this.file[name] = val;
  12108. return this._writeToStorage();
  12109. }
  12110. async setMultiple(properties) {
  12111. await this._initializedPromise;
  12112. for (const name in properties) {
  12113. this.file[name] = properties[name];
  12114. }
  12115. return this._writeToStorage();
  12116. }
  12117. async get(name, defaultValue) {
  12118. await this._initializedPromise;
  12119. const val = this.file[name];
  12120. return val !== undefined ? val : defaultValue;
  12121. }
  12122. async getMultiple(properties) {
  12123. await this._initializedPromise;
  12124. const values = Object.create(null);
  12125. for (const name in properties) {
  12126. const val = this.file[name];
  12127. values[name] = val !== undefined ? val : properties[name];
  12128. }
  12129. return values;
  12130. }
  12131. }
  12132. exports.ViewHistory = ViewHistory;
  12133. /***/ }),
  12134. /* 41 */
  12135. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12136. Object.defineProperty(exports, "__esModule", ({
  12137. value: true
  12138. }));
  12139. exports.BasePreferences = void 0;
  12140. var _app_options = __webpack_require__(5);
  12141. class BasePreferences {
  12142. #defaults = Object.freeze({
  12143. "annotationEditorMode": 0,
  12144. "annotationMode": 2,
  12145. "cursorToolOnLoad": 0,
  12146. "defaultZoomDelay": 400,
  12147. "defaultZoomValue": "",
  12148. "disablePageLabels": false,
  12149. "enableFloatingToolbar": false,
  12150. "enablePermissions": false,
  12151. "enablePrintAutoRotate": true,
  12152. "enableScripting": true,
  12153. "externalLinkTarget": 0,
  12154. "historyUpdateUrl": false,
  12155. "ignoreDestinationZoom": false,
  12156. "forcePageColors": false,
  12157. "pageColorsBackground": "Canvas",
  12158. "pageColorsForeground": "CanvasText",
  12159. "pdfBugEnabled": false,
  12160. "sidebarViewOnLoad": -1,
  12161. "scrollModeOnLoad": -1,
  12162. "spreadModeOnLoad": -1,
  12163. "textLayerMode": 1,
  12164. "useOnlyCssZoom": false,
  12165. "viewerCssTheme": 0,
  12166. "viewOnLoad": 0,
  12167. "disableAutoFetch": false,
  12168. "disableFontFace": false,
  12169. "disableRange": false,
  12170. "disableStream": false,
  12171. "enableXfa": true
  12172. });
  12173. #prefs = Object.create(null);
  12174. #initializedPromise = null;
  12175. constructor() {
  12176. if (this.constructor === BasePreferences) {
  12177. throw new Error("Cannot initialize BasePreferences.");
  12178. }
  12179. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  12180. for (const name in this.#defaults) {
  12181. const prefValue = prefs?.[name];
  12182. if (typeof prefValue === typeof this.#defaults[name]) {
  12183. this.#prefs[name] = prefValue;
  12184. }
  12185. }
  12186. });
  12187. }
  12188. async _writeToStorage(prefObj) {
  12189. throw new Error("Not implemented: _writeToStorage");
  12190. }
  12191. async _readFromStorage(prefObj) {
  12192. throw new Error("Not implemented: _readFromStorage");
  12193. }
  12194. async reset() {
  12195. await this.#initializedPromise;
  12196. const prefs = this.#prefs;
  12197. this.#prefs = Object.create(null);
  12198. return this._writeToStorage(this.#defaults).catch(reason => {
  12199. this.#prefs = prefs;
  12200. throw reason;
  12201. });
  12202. }
  12203. async set(name, value) {
  12204. await this.#initializedPromise;
  12205. const defaultValue = this.#defaults[name],
  12206. prefs = this.#prefs;
  12207. if (defaultValue === undefined) {
  12208. throw new Error(`Set preference: "${name}" is undefined.`);
  12209. } else if (value === undefined) {
  12210. throw new Error("Set preference: no value is specified.");
  12211. }
  12212. const valueType = typeof value,
  12213. defaultType = typeof defaultValue;
  12214. if (valueType !== defaultType) {
  12215. if (valueType === "number" && defaultType === "string") {
  12216. value = value.toString();
  12217. } else {
  12218. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  12219. }
  12220. } else {
  12221. if (valueType === "number" && !Number.isInteger(value)) {
  12222. throw new Error(`Set preference: "${value}" must be an integer.`);
  12223. }
  12224. }
  12225. this.#prefs[name] = value;
  12226. return this._writeToStorage(this.#prefs).catch(reason => {
  12227. this.#prefs = prefs;
  12228. throw reason;
  12229. });
  12230. }
  12231. async get(name) {
  12232. await this.#initializedPromise;
  12233. const defaultValue = this.#defaults[name];
  12234. if (defaultValue === undefined) {
  12235. throw new Error(`Get preference: "${name}" is undefined.`);
  12236. }
  12237. return this.#prefs[name] ?? defaultValue;
  12238. }
  12239. async getAll() {
  12240. await this.#initializedPromise;
  12241. const obj = Object.create(null);
  12242. for (const name in this.#defaults) {
  12243. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  12244. }
  12245. return obj;
  12246. }
  12247. }
  12248. exports.BasePreferences = BasePreferences;
  12249. /***/ }),
  12250. /* 42 */
  12251. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12252. Object.defineProperty(exports, "__esModule", ({
  12253. value: true
  12254. }));
  12255. exports.DownloadManager = void 0;
  12256. var _pdfjsLib = __webpack_require__(4);
  12257. ;
  12258. function download(blobUrl, filename) {
  12259. const a = document.createElement("a");
  12260. if (!a.click) {
  12261. throw new Error('DownloadManager: "a.click()" is not supported.');
  12262. }
  12263. a.href = blobUrl;
  12264. a.target = "_parent";
  12265. if ("download" in a) {
  12266. a.download = filename;
  12267. }
  12268. (document.body || document.documentElement).append(a);
  12269. a.click();
  12270. a.remove();
  12271. }
  12272. class DownloadManager {
  12273. #openBlobUrls = new WeakMap();
  12274. downloadUrl(url, filename, _options) {
  12275. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  12276. console.error(`downloadUrl - not a valid URL: ${url}`);
  12277. return;
  12278. }
  12279. download(url + "#pdfjs.action=download", filename);
  12280. }
  12281. downloadData(data, filename, contentType) {
  12282. const blobUrl = URL.createObjectURL(new Blob([data], {
  12283. type: contentType
  12284. }));
  12285. download(blobUrl, filename);
  12286. }
  12287. openOrDownloadData(element, data, filename) {
  12288. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  12289. const contentType = isPdfData ? "application/pdf" : "";
  12290. if (isPdfData) {
  12291. let blobUrl = this.#openBlobUrls.get(element);
  12292. if (!blobUrl) {
  12293. blobUrl = URL.createObjectURL(new Blob([data], {
  12294. type: contentType
  12295. }));
  12296. this.#openBlobUrls.set(element, blobUrl);
  12297. }
  12298. let viewerUrl;
  12299. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  12300. try {
  12301. window.open(viewerUrl);
  12302. return true;
  12303. } catch (ex) {
  12304. console.error(`openOrDownloadData: ${ex}`);
  12305. URL.revokeObjectURL(blobUrl);
  12306. this.#openBlobUrls.delete(element);
  12307. }
  12308. }
  12309. this.downloadData(data, filename, contentType);
  12310. return false;
  12311. }
  12312. download(blob, url, filename, _options) {
  12313. const blobUrl = URL.createObjectURL(blob);
  12314. download(blobUrl, filename);
  12315. }
  12316. }
  12317. exports.DownloadManager = DownloadManager;
  12318. /***/ }),
  12319. /* 43 */
  12320. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12321. Object.defineProperty(exports, "__esModule", ({
  12322. value: true
  12323. }));
  12324. exports.GenericL10n = void 0;
  12325. __webpack_require__(44);
  12326. var _l10n_utils = __webpack_require__(29);
  12327. const webL10n = document.webL10n;
  12328. class GenericL10n {
  12329. constructor(lang) {
  12330. this._lang = lang;
  12331. this._ready = new Promise((resolve, reject) => {
  12332. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  12333. resolve(webL10n);
  12334. });
  12335. });
  12336. }
  12337. async getLanguage() {
  12338. const l10n = await this._ready;
  12339. return l10n.getLanguage();
  12340. }
  12341. async getDirection() {
  12342. const l10n = await this._ready;
  12343. return l10n.getDirection();
  12344. }
  12345. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  12346. const l10n = await this._ready;
  12347. return l10n.get(key, args, fallback);
  12348. }
  12349. async translate(element) {
  12350. const l10n = await this._ready;
  12351. return l10n.translate(element);
  12352. }
  12353. }
  12354. exports.GenericL10n = GenericL10n;
  12355. /***/ }),
  12356. /* 44 */
  12357. /***/ (() => {
  12358. document.webL10n = function (window, document, undefined) {
  12359. var gL10nData = {};
  12360. var gTextData = '';
  12361. var gTextProp = 'textContent';
  12362. var gLanguage = '';
  12363. var gMacros = {};
  12364. var gReadyState = 'loading';
  12365. var gAsyncResourceLoading = true;
  12366. function getL10nResourceLinks() {
  12367. return document.querySelectorAll('link[type="application/l10n"]');
  12368. }
  12369. function getL10nDictionary() {
  12370. var script = document.querySelector('script[type="application/l10n"]');
  12371. return script ? JSON.parse(script.innerHTML) : null;
  12372. }
  12373. function getTranslatableChildren(element) {
  12374. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  12375. }
  12376. function getL10nAttributes(element) {
  12377. if (!element) return {};
  12378. var l10nId = element.getAttribute('data-l10n-id');
  12379. var l10nArgs = element.getAttribute('data-l10n-args');
  12380. var args = {};
  12381. if (l10nArgs) {
  12382. try {
  12383. args = JSON.parse(l10nArgs);
  12384. } catch (e) {
  12385. console.warn('could not parse arguments for #' + l10nId);
  12386. }
  12387. }
  12388. return {
  12389. id: l10nId,
  12390. args: args
  12391. };
  12392. }
  12393. function xhrLoadText(url, onSuccess, onFailure) {
  12394. onSuccess = onSuccess || function _onSuccess(data) {};
  12395. onFailure = onFailure || function _onFailure() {};
  12396. var xhr = new XMLHttpRequest();
  12397. xhr.open('GET', url, gAsyncResourceLoading);
  12398. if (xhr.overrideMimeType) {
  12399. xhr.overrideMimeType('text/plain; charset=utf-8');
  12400. }
  12401. xhr.onreadystatechange = function () {
  12402. if (xhr.readyState == 4) {
  12403. if (xhr.status == 200 || xhr.status === 0) {
  12404. onSuccess(xhr.responseText);
  12405. } else {
  12406. onFailure();
  12407. }
  12408. }
  12409. };
  12410. xhr.onerror = onFailure;
  12411. xhr.ontimeout = onFailure;
  12412. try {
  12413. xhr.send(null);
  12414. } catch (e) {
  12415. onFailure();
  12416. }
  12417. }
  12418. function parseResource(href, lang, successCallback, failureCallback) {
  12419. var baseURL = href.replace(/[^\/]*$/, '') || './';
  12420. function evalString(text) {
  12421. if (text.lastIndexOf('\\') < 0) return text;
  12422. 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, "'");
  12423. }
  12424. function parseProperties(text, parsedPropertiesCallback) {
  12425. var dictionary = {};
  12426. var reBlank = /^\s*|\s*$/;
  12427. var reComment = /^\s*#|^\s*$/;
  12428. var reSection = /^\s*\[(.*)\]\s*$/;
  12429. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  12430. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  12431. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  12432. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  12433. var currentLang = '*';
  12434. var genericLang = lang.split('-', 1)[0];
  12435. var skipLang = false;
  12436. var match = '';
  12437. function nextEntry() {
  12438. while (true) {
  12439. if (!entries.length) {
  12440. parsedRawLinesCallback();
  12441. return;
  12442. }
  12443. var line = entries.shift();
  12444. if (reComment.test(line)) continue;
  12445. if (extendedSyntax) {
  12446. match = reSection.exec(line);
  12447. if (match) {
  12448. currentLang = match[1].toLowerCase();
  12449. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  12450. continue;
  12451. } else if (skipLang) {
  12452. continue;
  12453. }
  12454. match = reImport.exec(line);
  12455. if (match) {
  12456. loadImport(baseURL + match[1], nextEntry);
  12457. return;
  12458. }
  12459. }
  12460. var tmp = line.match(reSplit);
  12461. if (tmp && tmp.length == 3) {
  12462. dictionary[tmp[1]] = evalString(tmp[2]);
  12463. }
  12464. }
  12465. }
  12466. nextEntry();
  12467. }
  12468. function loadImport(url, callback) {
  12469. xhrLoadText(url, function (content) {
  12470. parseRawLines(content, false, callback);
  12471. }, function () {
  12472. console.warn(url + ' not found.');
  12473. callback();
  12474. });
  12475. }
  12476. parseRawLines(text, true, function () {
  12477. parsedPropertiesCallback(dictionary);
  12478. });
  12479. }
  12480. xhrLoadText(href, function (response) {
  12481. gTextData += response;
  12482. parseProperties(response, function (data) {
  12483. for (var key in data) {
  12484. var id,
  12485. prop,
  12486. index = key.lastIndexOf('.');
  12487. if (index > 0) {
  12488. id = key.substring(0, index);
  12489. prop = key.substring(index + 1);
  12490. } else {
  12491. id = key;
  12492. prop = gTextProp;
  12493. }
  12494. if (!gL10nData[id]) {
  12495. gL10nData[id] = {};
  12496. }
  12497. gL10nData[id][prop] = data[key];
  12498. }
  12499. if (successCallback) {
  12500. successCallback();
  12501. }
  12502. });
  12503. }, failureCallback);
  12504. }
  12505. function loadLocale(lang, callback) {
  12506. if (lang) {
  12507. lang = lang.toLowerCase();
  12508. }
  12509. callback = callback || function _callback() {};
  12510. clear();
  12511. gLanguage = lang;
  12512. var langLinks = getL10nResourceLinks();
  12513. var langCount = langLinks.length;
  12514. if (langCount === 0) {
  12515. var dict = getL10nDictionary();
  12516. if (dict && dict.locales && dict.default_locale) {
  12517. console.log('using the embedded JSON directory, early way out');
  12518. gL10nData = dict.locales[lang];
  12519. if (!gL10nData) {
  12520. var defaultLocale = dict.default_locale.toLowerCase();
  12521. for (var anyCaseLang in dict.locales) {
  12522. anyCaseLang = anyCaseLang.toLowerCase();
  12523. if (anyCaseLang === lang) {
  12524. gL10nData = dict.locales[lang];
  12525. break;
  12526. } else if (anyCaseLang === defaultLocale) {
  12527. gL10nData = dict.locales[defaultLocale];
  12528. }
  12529. }
  12530. }
  12531. callback();
  12532. } else {
  12533. console.log('no resource to load, early way out');
  12534. }
  12535. gReadyState = 'complete';
  12536. return;
  12537. }
  12538. var onResourceLoaded = null;
  12539. var gResourceCount = 0;
  12540. onResourceLoaded = function () {
  12541. gResourceCount++;
  12542. if (gResourceCount >= langCount) {
  12543. callback();
  12544. gReadyState = 'complete';
  12545. }
  12546. };
  12547. function L10nResourceLink(link) {
  12548. var href = link.href;
  12549. this.load = function (lang, callback) {
  12550. parseResource(href, lang, callback, function () {
  12551. console.warn(href + ' not found.');
  12552. console.warn('"' + lang + '" resource not found');
  12553. gLanguage = '';
  12554. callback();
  12555. });
  12556. };
  12557. }
  12558. for (var i = 0; i < langCount; i++) {
  12559. var resource = new L10nResourceLink(langLinks[i]);
  12560. resource.load(lang, onResourceLoaded);
  12561. }
  12562. }
  12563. function clear() {
  12564. gL10nData = {};
  12565. gTextData = '';
  12566. gLanguage = '';
  12567. }
  12568. function getPluralRules(lang) {
  12569. var locales2rules = {
  12570. 'af': 3,
  12571. 'ak': 4,
  12572. 'am': 4,
  12573. 'ar': 1,
  12574. 'asa': 3,
  12575. 'az': 0,
  12576. 'be': 11,
  12577. 'bem': 3,
  12578. 'bez': 3,
  12579. 'bg': 3,
  12580. 'bh': 4,
  12581. 'bm': 0,
  12582. 'bn': 3,
  12583. 'bo': 0,
  12584. 'br': 20,
  12585. 'brx': 3,
  12586. 'bs': 11,
  12587. 'ca': 3,
  12588. 'cgg': 3,
  12589. 'chr': 3,
  12590. 'cs': 12,
  12591. 'cy': 17,
  12592. 'da': 3,
  12593. 'de': 3,
  12594. 'dv': 3,
  12595. 'dz': 0,
  12596. 'ee': 3,
  12597. 'el': 3,
  12598. 'en': 3,
  12599. 'eo': 3,
  12600. 'es': 3,
  12601. 'et': 3,
  12602. 'eu': 3,
  12603. 'fa': 0,
  12604. 'ff': 5,
  12605. 'fi': 3,
  12606. 'fil': 4,
  12607. 'fo': 3,
  12608. 'fr': 5,
  12609. 'fur': 3,
  12610. 'fy': 3,
  12611. 'ga': 8,
  12612. 'gd': 24,
  12613. 'gl': 3,
  12614. 'gsw': 3,
  12615. 'gu': 3,
  12616. 'guw': 4,
  12617. 'gv': 23,
  12618. 'ha': 3,
  12619. 'haw': 3,
  12620. 'he': 2,
  12621. 'hi': 4,
  12622. 'hr': 11,
  12623. 'hu': 0,
  12624. 'id': 0,
  12625. 'ig': 0,
  12626. 'ii': 0,
  12627. 'is': 3,
  12628. 'it': 3,
  12629. 'iu': 7,
  12630. 'ja': 0,
  12631. 'jmc': 3,
  12632. 'jv': 0,
  12633. 'ka': 0,
  12634. 'kab': 5,
  12635. 'kaj': 3,
  12636. 'kcg': 3,
  12637. 'kde': 0,
  12638. 'kea': 0,
  12639. 'kk': 3,
  12640. 'kl': 3,
  12641. 'km': 0,
  12642. 'kn': 0,
  12643. 'ko': 0,
  12644. 'ksb': 3,
  12645. 'ksh': 21,
  12646. 'ku': 3,
  12647. 'kw': 7,
  12648. 'lag': 18,
  12649. 'lb': 3,
  12650. 'lg': 3,
  12651. 'ln': 4,
  12652. 'lo': 0,
  12653. 'lt': 10,
  12654. 'lv': 6,
  12655. 'mas': 3,
  12656. 'mg': 4,
  12657. 'mk': 16,
  12658. 'ml': 3,
  12659. 'mn': 3,
  12660. 'mo': 9,
  12661. 'mr': 3,
  12662. 'ms': 0,
  12663. 'mt': 15,
  12664. 'my': 0,
  12665. 'nah': 3,
  12666. 'naq': 7,
  12667. 'nb': 3,
  12668. 'nd': 3,
  12669. 'ne': 3,
  12670. 'nl': 3,
  12671. 'nn': 3,
  12672. 'no': 3,
  12673. 'nr': 3,
  12674. 'nso': 4,
  12675. 'ny': 3,
  12676. 'nyn': 3,
  12677. 'om': 3,
  12678. 'or': 3,
  12679. 'pa': 3,
  12680. 'pap': 3,
  12681. 'pl': 13,
  12682. 'ps': 3,
  12683. 'pt': 3,
  12684. 'rm': 3,
  12685. 'ro': 9,
  12686. 'rof': 3,
  12687. 'ru': 11,
  12688. 'rwk': 3,
  12689. 'sah': 0,
  12690. 'saq': 3,
  12691. 'se': 7,
  12692. 'seh': 3,
  12693. 'ses': 0,
  12694. 'sg': 0,
  12695. 'sh': 11,
  12696. 'shi': 19,
  12697. 'sk': 12,
  12698. 'sl': 14,
  12699. 'sma': 7,
  12700. 'smi': 7,
  12701. 'smj': 7,
  12702. 'smn': 7,
  12703. 'sms': 7,
  12704. 'sn': 3,
  12705. 'so': 3,
  12706. 'sq': 3,
  12707. 'sr': 11,
  12708. 'ss': 3,
  12709. 'ssy': 3,
  12710. 'st': 3,
  12711. 'sv': 3,
  12712. 'sw': 3,
  12713. 'syr': 3,
  12714. 'ta': 3,
  12715. 'te': 3,
  12716. 'teo': 3,
  12717. 'th': 0,
  12718. 'ti': 4,
  12719. 'tig': 3,
  12720. 'tk': 3,
  12721. 'tl': 4,
  12722. 'tn': 3,
  12723. 'to': 0,
  12724. 'tr': 0,
  12725. 'ts': 3,
  12726. 'tzm': 22,
  12727. 'uk': 11,
  12728. 'ur': 3,
  12729. 've': 3,
  12730. 'vi': 0,
  12731. 'vun': 3,
  12732. 'wa': 4,
  12733. 'wae': 3,
  12734. 'wo': 0,
  12735. 'xh': 3,
  12736. 'xog': 3,
  12737. 'yo': 0,
  12738. 'zh': 0,
  12739. 'zu': 3
  12740. };
  12741. function isIn(n, list) {
  12742. return list.indexOf(n) !== -1;
  12743. }
  12744. function isBetween(n, start, end) {
  12745. return start <= n && n <= end;
  12746. }
  12747. var pluralRules = {
  12748. '0': function (n) {
  12749. return 'other';
  12750. },
  12751. '1': function (n) {
  12752. if (isBetween(n % 100, 3, 10)) return 'few';
  12753. if (n === 0) return 'zero';
  12754. if (isBetween(n % 100, 11, 99)) return 'many';
  12755. if (n == 2) return 'two';
  12756. if (n == 1) return 'one';
  12757. return 'other';
  12758. },
  12759. '2': function (n) {
  12760. if (n !== 0 && n % 10 === 0) return 'many';
  12761. if (n == 2) return 'two';
  12762. if (n == 1) return 'one';
  12763. return 'other';
  12764. },
  12765. '3': function (n) {
  12766. if (n == 1) return 'one';
  12767. return 'other';
  12768. },
  12769. '4': function (n) {
  12770. if (isBetween(n, 0, 1)) return 'one';
  12771. return 'other';
  12772. },
  12773. '5': function (n) {
  12774. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12775. return 'other';
  12776. },
  12777. '6': function (n) {
  12778. if (n === 0) return 'zero';
  12779. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12780. return 'other';
  12781. },
  12782. '7': function (n) {
  12783. if (n == 2) return 'two';
  12784. if (n == 1) return 'one';
  12785. return 'other';
  12786. },
  12787. '8': function (n) {
  12788. if (isBetween(n, 3, 6)) return 'few';
  12789. if (isBetween(n, 7, 10)) return 'many';
  12790. if (n == 2) return 'two';
  12791. if (n == 1) return 'one';
  12792. return 'other';
  12793. },
  12794. '9': function (n) {
  12795. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12796. if (n == 1) return 'one';
  12797. return 'other';
  12798. },
  12799. '10': function (n) {
  12800. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12801. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12802. return 'other';
  12803. },
  12804. '11': function (n) {
  12805. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12806. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12807. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12808. return 'other';
  12809. },
  12810. '12': function (n) {
  12811. if (isBetween(n, 2, 4)) return 'few';
  12812. if (n == 1) return 'one';
  12813. return 'other';
  12814. },
  12815. '13': function (n) {
  12816. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12817. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12818. if (n == 1) return 'one';
  12819. return 'other';
  12820. },
  12821. '14': function (n) {
  12822. if (isBetween(n % 100, 3, 4)) return 'few';
  12823. if (n % 100 == 2) return 'two';
  12824. if (n % 100 == 1) return 'one';
  12825. return 'other';
  12826. },
  12827. '15': function (n) {
  12828. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12829. if (isBetween(n % 100, 11, 19)) return 'many';
  12830. if (n == 1) return 'one';
  12831. return 'other';
  12832. },
  12833. '16': function (n) {
  12834. if (n % 10 == 1 && n != 11) return 'one';
  12835. return 'other';
  12836. },
  12837. '17': function (n) {
  12838. if (n == 3) return 'few';
  12839. if (n === 0) return 'zero';
  12840. if (n == 6) return 'many';
  12841. if (n == 2) return 'two';
  12842. if (n == 1) return 'one';
  12843. return 'other';
  12844. },
  12845. '18': function (n) {
  12846. if (n === 0) return 'zero';
  12847. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12848. return 'other';
  12849. },
  12850. '19': function (n) {
  12851. if (isBetween(n, 2, 10)) return 'few';
  12852. if (isBetween(n, 0, 1)) return 'one';
  12853. return 'other';
  12854. },
  12855. '20': function (n) {
  12856. 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';
  12857. if (n % 1000000 === 0 && n !== 0) return 'many';
  12858. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12859. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12860. return 'other';
  12861. },
  12862. '21': function (n) {
  12863. if (n === 0) return 'zero';
  12864. if (n == 1) return 'one';
  12865. return 'other';
  12866. },
  12867. '22': function (n) {
  12868. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  12869. return 'other';
  12870. },
  12871. '23': function (n) {
  12872. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  12873. return 'other';
  12874. },
  12875. '24': function (n) {
  12876. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  12877. if (isIn(n, [2, 12])) return 'two';
  12878. if (isIn(n, [1, 11])) return 'one';
  12879. return 'other';
  12880. }
  12881. };
  12882. var index = locales2rules[lang.replace(/-.*$/, '')];
  12883. if (!(index in pluralRules)) {
  12884. console.warn('plural form unknown for [' + lang + ']');
  12885. return function () {
  12886. return 'other';
  12887. };
  12888. }
  12889. return pluralRules[index];
  12890. }
  12891. gMacros.plural = function (str, param, key, prop) {
  12892. var n = parseFloat(param);
  12893. if (isNaN(n)) return str;
  12894. if (prop != gTextProp) return str;
  12895. if (!gMacros._pluralRules) {
  12896. gMacros._pluralRules = getPluralRules(gLanguage);
  12897. }
  12898. var index = '[' + gMacros._pluralRules(n) + ']';
  12899. if (n === 0 && key + '[zero]' in gL10nData) {
  12900. str = gL10nData[key + '[zero]'][prop];
  12901. } else if (n == 1 && key + '[one]' in gL10nData) {
  12902. str = gL10nData[key + '[one]'][prop];
  12903. } else if (n == 2 && key + '[two]' in gL10nData) {
  12904. str = gL10nData[key + '[two]'][prop];
  12905. } else if (key + index in gL10nData) {
  12906. str = gL10nData[key + index][prop];
  12907. } else if (key + '[other]' in gL10nData) {
  12908. str = gL10nData[key + '[other]'][prop];
  12909. }
  12910. return str;
  12911. };
  12912. function getL10nData(key, args, fallback) {
  12913. var data = gL10nData[key];
  12914. if (!data) {
  12915. console.warn('#' + key + ' is undefined.');
  12916. if (!fallback) {
  12917. return null;
  12918. }
  12919. data = fallback;
  12920. }
  12921. var rv = {};
  12922. for (var prop in data) {
  12923. var str = data[prop];
  12924. str = substIndexes(str, args, key, prop);
  12925. str = substArguments(str, args, key);
  12926. rv[prop] = str;
  12927. }
  12928. return rv;
  12929. }
  12930. function substIndexes(str, args, key, prop) {
  12931. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  12932. var reMatch = reIndex.exec(str);
  12933. if (!reMatch || !reMatch.length) return str;
  12934. var macroName = reMatch[1];
  12935. var paramName = reMatch[2];
  12936. var param;
  12937. if (args && paramName in args) {
  12938. param = args[paramName];
  12939. } else if (paramName in gL10nData) {
  12940. param = gL10nData[paramName];
  12941. }
  12942. if (macroName in gMacros) {
  12943. var macro = gMacros[macroName];
  12944. str = macro(str, param, key, prop);
  12945. }
  12946. return str;
  12947. }
  12948. function substArguments(str, args, key) {
  12949. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  12950. return str.replace(reArgs, function (matched_text, arg) {
  12951. if (args && arg in args) {
  12952. return args[arg];
  12953. }
  12954. if (arg in gL10nData) {
  12955. return gL10nData[arg];
  12956. }
  12957. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  12958. return matched_text;
  12959. });
  12960. }
  12961. function translateElement(element) {
  12962. var l10n = getL10nAttributes(element);
  12963. if (!l10n.id) return;
  12964. var data = getL10nData(l10n.id, l10n.args);
  12965. if (!data) {
  12966. console.warn('#' + l10n.id + ' is undefined.');
  12967. return;
  12968. }
  12969. if (data[gTextProp]) {
  12970. if (getChildElementCount(element) === 0) {
  12971. element[gTextProp] = data[gTextProp];
  12972. } else {
  12973. var children = element.childNodes;
  12974. var found = false;
  12975. for (var i = 0, l = children.length; i < l; i++) {
  12976. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  12977. if (found) {
  12978. children[i].nodeValue = '';
  12979. } else {
  12980. children[i].nodeValue = data[gTextProp];
  12981. found = true;
  12982. }
  12983. }
  12984. }
  12985. if (!found) {
  12986. var textNode = document.createTextNode(data[gTextProp]);
  12987. element.prepend(textNode);
  12988. }
  12989. }
  12990. delete data[gTextProp];
  12991. }
  12992. for (var k in data) {
  12993. element[k] = data[k];
  12994. }
  12995. }
  12996. function getChildElementCount(element) {
  12997. if (element.children) {
  12998. return element.children.length;
  12999. }
  13000. if (typeof element.childElementCount !== 'undefined') {
  13001. return element.childElementCount;
  13002. }
  13003. var count = 0;
  13004. for (var i = 0; i < element.childNodes.length; i++) {
  13005. count += element.nodeType === 1 ? 1 : 0;
  13006. }
  13007. return count;
  13008. }
  13009. function translateFragment(element) {
  13010. element = element || document.documentElement;
  13011. var children = getTranslatableChildren(element);
  13012. var elementCount = children.length;
  13013. for (var i = 0; i < elementCount; i++) {
  13014. translateElement(children[i]);
  13015. }
  13016. translateElement(element);
  13017. }
  13018. return {
  13019. get: function (key, args, fallbackString) {
  13020. var index = key.lastIndexOf('.');
  13021. var prop = gTextProp;
  13022. if (index > 0) {
  13023. prop = key.substring(index + 1);
  13024. key = key.substring(0, index);
  13025. }
  13026. var fallback;
  13027. if (fallbackString) {
  13028. fallback = {};
  13029. fallback[prop] = fallbackString;
  13030. }
  13031. var data = getL10nData(key, args, fallback);
  13032. if (data && prop in data) {
  13033. return data[prop];
  13034. }
  13035. return '{{' + key + '}}';
  13036. },
  13037. getData: function () {
  13038. return gL10nData;
  13039. },
  13040. getText: function () {
  13041. return gTextData;
  13042. },
  13043. getLanguage: function () {
  13044. return gLanguage;
  13045. },
  13046. setLanguage: function (lang, callback) {
  13047. loadLocale(lang, function () {
  13048. if (callback) callback();
  13049. });
  13050. },
  13051. getDirection: function () {
  13052. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  13053. var shortCode = gLanguage.split('-', 1)[0];
  13054. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  13055. },
  13056. translate: translateFragment,
  13057. getReadyState: function () {
  13058. return gReadyState;
  13059. },
  13060. ready: function (callback) {
  13061. if (!callback) {
  13062. return;
  13063. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  13064. window.setTimeout(function () {
  13065. callback();
  13066. });
  13067. } else if (document.addEventListener) {
  13068. document.addEventListener('localized', function once() {
  13069. document.removeEventListener('localized', once);
  13070. callback();
  13071. });
  13072. }
  13073. }
  13074. };
  13075. }(window, document);
  13076. /***/ }),
  13077. /* 45 */
  13078. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13079. Object.defineProperty(exports, "__esModule", ({
  13080. value: true
  13081. }));
  13082. exports.GenericScripting = void 0;
  13083. exports.docPropertiesLookup = docPropertiesLookup;
  13084. var _pdfjsLib = __webpack_require__(4);
  13085. async function docPropertiesLookup(pdfDocument) {
  13086. const url = "",
  13087. baseUrl = url.split("#")[0];
  13088. let {
  13089. info,
  13090. metadata,
  13091. contentDispositionFilename,
  13092. contentLength
  13093. } = await pdfDocument.getMetadata();
  13094. if (!contentLength) {
  13095. const {
  13096. length
  13097. } = await pdfDocument.getDownloadInfo();
  13098. contentLength = length;
  13099. }
  13100. return {
  13101. ...info,
  13102. baseURL: baseUrl,
  13103. filesize: contentLength,
  13104. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  13105. metadata: metadata?.getRaw(),
  13106. authors: metadata?.get("dc:creator"),
  13107. numPages: pdfDocument.numPages,
  13108. URL: url
  13109. };
  13110. }
  13111. class GenericScripting {
  13112. constructor(sandboxBundleSrc) {
  13113. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  13114. return window.pdfjsSandbox.QuickJSSandbox();
  13115. });
  13116. }
  13117. async createSandbox(data) {
  13118. const sandbox = await this._ready;
  13119. sandbox.create(data);
  13120. }
  13121. async dispatchEventInSandbox(event) {
  13122. const sandbox = await this._ready;
  13123. setTimeout(() => sandbox.dispatchEvent(event), 0);
  13124. }
  13125. async destroySandbox() {
  13126. const sandbox = await this._ready;
  13127. sandbox.nukeSandbox();
  13128. }
  13129. }
  13130. exports.GenericScripting = GenericScripting;
  13131. /***/ }),
  13132. /* 46 */
  13133. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13134. Object.defineProperty(exports, "__esModule", ({
  13135. value: true
  13136. }));
  13137. exports.PDFPrintService = void 0;
  13138. var _pdfjsLib = __webpack_require__(4);
  13139. var _app = __webpack_require__(2);
  13140. var _print_utils = __webpack_require__(47);
  13141. let activeService = null;
  13142. let dialog = null;
  13143. let overlayManager = null;
  13144. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  13145. const scratchCanvas = activeService.scratchCanvas;
  13146. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  13147. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  13148. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  13149. const ctx = scratchCanvas.getContext("2d");
  13150. ctx.save();
  13151. ctx.fillStyle = "rgb(255, 255, 255)";
  13152. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  13153. ctx.restore();
  13154. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  13155. const renderContext = {
  13156. canvasContext: ctx,
  13157. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  13158. viewport: pdfPage.getViewport({
  13159. scale: 1,
  13160. rotation: size.rotation
  13161. }),
  13162. intent: "print",
  13163. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  13164. optionalContentConfigPromise,
  13165. printAnnotationStorage
  13166. };
  13167. return pdfPage.render(renderContext).promise;
  13168. });
  13169. }
  13170. class PDFPrintService {
  13171. constructor(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) {
  13172. this.pdfDocument = pdfDocument;
  13173. this.pagesOverview = pagesOverview;
  13174. this.printContainer = printContainer;
  13175. this._printResolution = printResolution || 150;
  13176. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  13177. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  13178. this.l10n = l10n;
  13179. this.currentPage = -1;
  13180. this.scratchCanvas = document.createElement("canvas");
  13181. }
  13182. layout() {
  13183. this.throwIfInactive();
  13184. const body = document.querySelector("body");
  13185. body.setAttribute("data-pdfjsprinting", true);
  13186. const {
  13187. width,
  13188. height
  13189. } = this.pagesOverview[0];
  13190. const hasEqualPageSizes = this.pagesOverview.every(size => size.width === width && size.height === height);
  13191. if (!hasEqualPageSizes) {
  13192. console.warn("Not all pages have the same size. The printed result may be incorrect!");
  13193. }
  13194. this.pageStyleSheet = document.createElement("style");
  13195. this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`;
  13196. body.append(this.pageStyleSheet);
  13197. }
  13198. destroy() {
  13199. if (activeService !== this) {
  13200. return;
  13201. }
  13202. this.printContainer.textContent = "";
  13203. const body = document.querySelector("body");
  13204. body.removeAttribute("data-pdfjsprinting");
  13205. if (this.pageStyleSheet) {
  13206. this.pageStyleSheet.remove();
  13207. this.pageStyleSheet = null;
  13208. }
  13209. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  13210. this.scratchCanvas = null;
  13211. activeService = null;
  13212. ensureOverlay().then(function () {
  13213. if (overlayManager.active === dialog) {
  13214. overlayManager.close(dialog);
  13215. }
  13216. });
  13217. }
  13218. renderPages() {
  13219. if (this.pdfDocument.isPureXfa) {
  13220. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  13221. return Promise.resolve();
  13222. }
  13223. const pageCount = this.pagesOverview.length;
  13224. const renderNextPage = (resolve, reject) => {
  13225. this.throwIfInactive();
  13226. if (++this.currentPage >= pageCount) {
  13227. renderProgress(pageCount, pageCount, this.l10n);
  13228. resolve();
  13229. return;
  13230. }
  13231. const index = this.currentPage;
  13232. renderProgress(index, pageCount, this.l10n);
  13233. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  13234. renderNextPage(resolve, reject);
  13235. }, reject);
  13236. };
  13237. return new Promise(renderNextPage);
  13238. }
  13239. useRenderedPage() {
  13240. this.throwIfInactive();
  13241. const img = document.createElement("img");
  13242. const scratchCanvas = this.scratchCanvas;
  13243. if ("toBlob" in scratchCanvas) {
  13244. scratchCanvas.toBlob(function (blob) {
  13245. img.src = URL.createObjectURL(blob);
  13246. });
  13247. } else {
  13248. img.src = scratchCanvas.toDataURL();
  13249. }
  13250. const wrapper = document.createElement("div");
  13251. wrapper.className = "printedPage";
  13252. wrapper.append(img);
  13253. this.printContainer.append(wrapper);
  13254. return new Promise(function (resolve, reject) {
  13255. img.onload = resolve;
  13256. img.onerror = reject;
  13257. });
  13258. }
  13259. performPrint() {
  13260. this.throwIfInactive();
  13261. return new Promise(resolve => {
  13262. setTimeout(() => {
  13263. if (!this.active) {
  13264. resolve();
  13265. return;
  13266. }
  13267. print.call(window);
  13268. setTimeout(resolve, 20);
  13269. }, 0);
  13270. });
  13271. }
  13272. get active() {
  13273. return this === activeService;
  13274. }
  13275. throwIfInactive() {
  13276. if (!this.active) {
  13277. throw new Error("This print request was cancelled or completed.");
  13278. }
  13279. }
  13280. }
  13281. exports.PDFPrintService = PDFPrintService;
  13282. const print = window.print;
  13283. window.print = function () {
  13284. if (activeService) {
  13285. console.warn("Ignored window.print() because of a pending print job.");
  13286. return;
  13287. }
  13288. ensureOverlay().then(function () {
  13289. if (activeService) {
  13290. overlayManager.open(dialog);
  13291. }
  13292. });
  13293. try {
  13294. dispatchEvent("beforeprint");
  13295. } finally {
  13296. if (!activeService) {
  13297. console.error("Expected print service to be initialized.");
  13298. ensureOverlay().then(function () {
  13299. if (overlayManager.active === dialog) {
  13300. overlayManager.close(dialog);
  13301. }
  13302. });
  13303. return;
  13304. }
  13305. const activeServiceOnEntry = activeService;
  13306. activeService.renderPages().then(function () {
  13307. return activeServiceOnEntry.performPrint();
  13308. }).catch(function () {}).then(function () {
  13309. if (activeServiceOnEntry.active) {
  13310. abort();
  13311. }
  13312. });
  13313. }
  13314. };
  13315. function dispatchEvent(eventType) {
  13316. const event = new CustomEvent(eventType, {
  13317. bubbles: false,
  13318. cancelable: false,
  13319. detail: "custom"
  13320. });
  13321. window.dispatchEvent(event);
  13322. }
  13323. function abort() {
  13324. if (activeService) {
  13325. activeService.destroy();
  13326. dispatchEvent("afterprint");
  13327. }
  13328. }
  13329. function renderProgress(index, total, l10n) {
  13330. dialog ||= document.getElementById("printServiceDialog");
  13331. const progress = Math.round(100 * index / total);
  13332. const progressBar = dialog.querySelector("progress");
  13333. const progressPerc = dialog.querySelector(".relative-progress");
  13334. progressBar.value = progress;
  13335. l10n.get("print_progress_percent", {
  13336. progress
  13337. }).then(msg => {
  13338. progressPerc.textContent = msg;
  13339. });
  13340. }
  13341. window.addEventListener("keydown", function (event) {
  13342. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  13343. window.print();
  13344. event.preventDefault();
  13345. event.stopImmediatePropagation();
  13346. }
  13347. }, true);
  13348. if ("onbeforeprint" in window) {
  13349. const stopPropagationIfNeeded = function (event) {
  13350. if (event.detail !== "custom") {
  13351. event.stopImmediatePropagation();
  13352. }
  13353. };
  13354. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  13355. window.addEventListener("afterprint", stopPropagationIfNeeded);
  13356. }
  13357. let overlayPromise;
  13358. function ensureOverlay() {
  13359. if (!overlayPromise) {
  13360. overlayManager = _app.PDFViewerApplication.overlayManager;
  13361. if (!overlayManager) {
  13362. throw new Error("The overlay manager has not yet been initialized.");
  13363. }
  13364. dialog ||= document.getElementById("printServiceDialog");
  13365. overlayPromise = overlayManager.register(dialog, true);
  13366. document.getElementById("printCancel").onclick = abort;
  13367. dialog.addEventListener("close", abort);
  13368. }
  13369. return overlayPromise;
  13370. }
  13371. _app.PDFPrintServiceFactory.instance = {
  13372. supportsPrinting: true,
  13373. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  13374. if (activeService) {
  13375. throw new Error("The print service is created and active.");
  13376. }
  13377. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  13378. return activeService;
  13379. }
  13380. };
  13381. /***/ }),
  13382. /* 47 */
  13383. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13384. Object.defineProperty(exports, "__esModule", ({
  13385. value: true
  13386. }));
  13387. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  13388. var _pdfjsLib = __webpack_require__(4);
  13389. var _pdf_link_service = __webpack_require__(7);
  13390. var _xfa_layer_builder = __webpack_require__(37);
  13391. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  13392. const xfaHtml = pdfDocument.allXfaHtml;
  13393. const linkService = new _pdf_link_service.SimpleLinkService();
  13394. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  13395. for (const xfaPage of xfaHtml.children) {
  13396. const page = document.createElement("div");
  13397. page.className = "xfaPrintedPage";
  13398. printContainer.append(page);
  13399. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  13400. pageDiv: page,
  13401. pdfPage: null,
  13402. annotationStorage: pdfDocument.annotationStorage,
  13403. linkService,
  13404. xfaHtml: xfaPage
  13405. });
  13406. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  13407. scale
  13408. });
  13409. builder.render(viewport, "print");
  13410. }
  13411. }
  13412. /***/ })
  13413. /******/ ]);
  13414. /************************************************************************/
  13415. /******/ // The module cache
  13416. /******/ var __webpack_module_cache__ = {};
  13417. /******/
  13418. /******/ // The require function
  13419. /******/ function __webpack_require__(moduleId) {
  13420. /******/ // Check if module is in cache
  13421. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  13422. /******/ if (cachedModule !== undefined) {
  13423. /******/ return cachedModule.exports;
  13424. /******/ }
  13425. /******/ // Create a new module (and put it into the cache)
  13426. /******/ var module = __webpack_module_cache__[moduleId] = {
  13427. /******/ // no module.id needed
  13428. /******/ // no module.loaded needed
  13429. /******/ exports: {}
  13430. /******/ };
  13431. /******/
  13432. /******/ // Execute the module function
  13433. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  13434. /******/
  13435. /******/ // Return the exports of the module
  13436. /******/ return module.exports;
  13437. /******/ }
  13438. /******/
  13439. /************************************************************************/
  13440. var __webpack_exports__ = {};
  13441. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  13442. (() => {
  13443. var exports = __webpack_exports__;
  13444. Object.defineProperty(exports, "__esModule", ({
  13445. value: true
  13446. }));
  13447. Object.defineProperty(exports, "PDFViewerApplication", ({
  13448. enumerable: true,
  13449. get: function () {
  13450. return _app.PDFViewerApplication;
  13451. }
  13452. }));
  13453. exports.PDFViewerApplicationConstants = void 0;
  13454. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  13455. enumerable: true,
  13456. get: function () {
  13457. return _app_options.AppOptions;
  13458. }
  13459. }));
  13460. __webpack_require__(1);
  13461. __webpack_require__(46);
  13462. var _ui_utils = __webpack_require__(3);
  13463. var _app_options = __webpack_require__(5);
  13464. var _pdf_link_service = __webpack_require__(7);
  13465. var _app = __webpack_require__(2);
  13466. const pdfjsVersion = '3.7.107';
  13467. const pdfjsBuild = '036f855dc';
  13468. const AppConstants = {
  13469. LinkTarget: _pdf_link_service.LinkTarget,
  13470. RenderingStates: _ui_utils.RenderingStates,
  13471. ScrollMode: _ui_utils.ScrollMode,
  13472. SpreadMode: _ui_utils.SpreadMode
  13473. };
  13474. exports.PDFViewerApplicationConstants = AppConstants;
  13475. window.PDFViewerApplication = _app.PDFViewerApplication;
  13476. window.PDFViewerApplicationConstants = AppConstants;
  13477. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  13478. function getViewerConfiguration() {
  13479. return {
  13480. appContainer: document.body,
  13481. mainContainer: document.getElementById("viewerContainer"),
  13482. viewerContainer: document.getElementById("viewer"),
  13483. toolbar: {
  13484. container: document.getElementById("toolbarViewer"),
  13485. numPages: document.getElementById("numPages"),
  13486. pageNumber: document.getElementById("pageNumber"),
  13487. scaleSelect: document.getElementById("scaleSelect"),
  13488. customScaleOption: document.getElementById("customScaleOption"),
  13489. previous: document.getElementById("previous"),
  13490. next: document.getElementById("next"),
  13491. zoomIn: document.getElementById("zoomIn"),
  13492. zoomOut: document.getElementById("zoomOut"),
  13493. viewFind: document.getElementById("viewFind"),
  13494. openFile: document.getElementById("openFile"),
  13495. print: document.getElementById("print"),
  13496. editorFreeTextButton: document.getElementById("editorFreeText"),
  13497. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  13498. editorInkButton: document.getElementById("editorInk"),
  13499. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  13500. download: document.getElementById("download")
  13501. },
  13502. secondaryToolbar: {
  13503. toolbar: document.getElementById("secondaryToolbar"),
  13504. toggleButton: document.getElementById("secondaryToolbarToggle"),
  13505. presentationModeButton: document.getElementById("presentationMode"),
  13506. openFileButton: document.getElementById("secondaryOpenFile"),
  13507. printButton: document.getElementById("secondaryPrint"),
  13508. downloadButton: document.getElementById("secondaryDownload"),
  13509. viewBookmarkButton: document.getElementById("viewBookmark"),
  13510. firstPageButton: document.getElementById("firstPage"),
  13511. lastPageButton: document.getElementById("lastPage"),
  13512. pageRotateCwButton: document.getElementById("pageRotateCw"),
  13513. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  13514. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  13515. cursorHandToolButton: document.getElementById("cursorHandTool"),
  13516. scrollPageButton: document.getElementById("scrollPage"),
  13517. scrollVerticalButton: document.getElementById("scrollVertical"),
  13518. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  13519. scrollWrappedButton: document.getElementById("scrollWrapped"),
  13520. spreadNoneButton: document.getElementById("spreadNone"),
  13521. spreadOddButton: document.getElementById("spreadOdd"),
  13522. spreadEvenButton: document.getElementById("spreadEven"),
  13523. documentPropertiesButton: document.getElementById("documentProperties")
  13524. },
  13525. sidebar: {
  13526. outerContainer: document.getElementById("outerContainer"),
  13527. sidebarContainer: document.getElementById("sidebarContainer"),
  13528. toggleButton: document.getElementById("sidebarToggle"),
  13529. resizer: document.getElementById("sidebarResizer"),
  13530. thumbnailButton: document.getElementById("viewThumbnail"),
  13531. outlineButton: document.getElementById("viewOutline"),
  13532. attachmentsButton: document.getElementById("viewAttachments"),
  13533. layersButton: document.getElementById("viewLayers"),
  13534. thumbnailView: document.getElementById("thumbnailView"),
  13535. outlineView: document.getElementById("outlineView"),
  13536. attachmentsView: document.getElementById("attachmentsView"),
  13537. layersView: document.getElementById("layersView"),
  13538. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  13539. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  13540. },
  13541. findBar: {
  13542. bar: document.getElementById("findbar"),
  13543. toggleButton: document.getElementById("viewFind"),
  13544. findField: document.getElementById("findInput"),
  13545. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  13546. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  13547. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  13548. entireWordCheckbox: document.getElementById("findEntireWord"),
  13549. findMsg: document.getElementById("findMsg"),
  13550. findResultsCount: document.getElementById("findResultsCount"),
  13551. findPreviousButton: document.getElementById("findPrevious"),
  13552. findNextButton: document.getElementById("findNext")
  13553. },
  13554. passwordOverlay: {
  13555. dialog: document.getElementById("passwordDialog"),
  13556. label: document.getElementById("passwordText"),
  13557. input: document.getElementById("password"),
  13558. submitButton: document.getElementById("passwordSubmit"),
  13559. cancelButton: document.getElementById("passwordCancel")
  13560. },
  13561. documentProperties: {
  13562. dialog: document.getElementById("documentPropertiesDialog"),
  13563. closeButton: document.getElementById("documentPropertiesClose"),
  13564. fields: {
  13565. fileName: document.getElementById("fileNameField"),
  13566. fileSize: document.getElementById("fileSizeField"),
  13567. title: document.getElementById("titleField"),
  13568. author: document.getElementById("authorField"),
  13569. subject: document.getElementById("subjectField"),
  13570. keywords: document.getElementById("keywordsField"),
  13571. creationDate: document.getElementById("creationDateField"),
  13572. modificationDate: document.getElementById("modificationDateField"),
  13573. creator: document.getElementById("creatorField"),
  13574. producer: document.getElementById("producerField"),
  13575. version: document.getElementById("versionField"),
  13576. pageCount: document.getElementById("pageCountField"),
  13577. pageSize: document.getElementById("pageSizeField"),
  13578. linearized: document.getElementById("linearizedField")
  13579. }
  13580. },
  13581. annotationEditorParams: {
  13582. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  13583. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  13584. editorInkColor: document.getElementById("editorInkColor"),
  13585. editorInkThickness: document.getElementById("editorInkThickness"),
  13586. editorInkOpacity: document.getElementById("editorInkOpacity")
  13587. },
  13588. printContainer: document.getElementById("printContainer"),
  13589. openFileInput: document.getElementById("fileInput"),
  13590. debuggerScriptPath: "./debugger.js"
  13591. };
  13592. }
  13593. function webViewerLoad() {
  13594. const config = getViewerConfiguration();
  13595. const event = new CustomEvent("webviewerloaded", {
  13596. bubbles: true,
  13597. cancelable: true,
  13598. detail: {
  13599. source: window
  13600. }
  13601. });
  13602. try {
  13603. parent.document.dispatchEvent(event);
  13604. } catch (ex) {
  13605. console.error(`webviewerloaded: ${ex}`);
  13606. document.dispatchEvent(event);
  13607. }
  13608. _app.PDFViewerApplication.run(config);
  13609. }
  13610. document.blockUnblockOnload?.(true);
  13611. if (document.readyState === "interactive" || document.readyState === "complete") {
  13612. webViewerLoad();
  13613. } else {
  13614. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  13615. }
  13616. })();
  13617. /******/ })()
  13618. ;
  13619. //# sourceMappingURL=viewer.js.map