viewer.js 412 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.AutoPrintRegExp = void 0;
  32. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  33. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  34. exports.approximateFraction = approximateFraction;
  35. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  36. exports.binarySearchFirstItem = binarySearchFirstItem;
  37. exports.docStyle = void 0;
  38. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  39. exports.getPageSizeInches = getPageSizeInches;
  40. exports.getVisibleElements = getVisibleElements;
  41. exports.isPortraitOrientation = isPortraitOrientation;
  42. exports.isValidRotation = isValidRotation;
  43. exports.isValidScrollMode = isValidScrollMode;
  44. exports.isValidSpreadMode = isValidSpreadMode;
  45. exports.noContextMenuHandler = noContextMenuHandler;
  46. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  47. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  48. exports.parseQueryString = parseQueryString;
  49. exports.removeNullCharacters = removeNullCharacters;
  50. exports.roundToDivide = roundToDivide;
  51. exports.scrollIntoView = scrollIntoView;
  52. exports.watchScroll = watchScroll;
  53. const DEFAULT_SCALE_VALUE = "auto";
  54. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  55. const DEFAULT_SCALE = 1.0;
  56. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  57. const DEFAULT_SCALE_DELTA = 1.1;
  58. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  59. const MIN_SCALE = 0.1;
  60. exports.MIN_SCALE = MIN_SCALE;
  61. const MAX_SCALE = 10.0;
  62. exports.MAX_SCALE = MAX_SCALE;
  63. const UNKNOWN_SCALE = 0;
  64. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  65. const MAX_AUTO_SCALE = 1.25;
  66. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  67. const SCROLLBAR_PADDING = 40;
  68. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  69. const VERTICAL_PADDING = 5;
  70. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  71. const RenderingStates = {
  72. INITIAL: 0,
  73. RUNNING: 1,
  74. PAUSED: 2,
  75. FINISHED: 3
  76. };
  77. exports.RenderingStates = RenderingStates;
  78. const PresentationModeState = {
  79. UNKNOWN: 0,
  80. NORMAL: 1,
  81. CHANGING: 2,
  82. FULLSCREEN: 3
  83. };
  84. exports.PresentationModeState = PresentationModeState;
  85. const SidebarView = {
  86. UNKNOWN: -1,
  87. NONE: 0,
  88. THUMBS: 1,
  89. OUTLINE: 2,
  90. ATTACHMENTS: 3,
  91. LAYERS: 4
  92. };
  93. exports.SidebarView = SidebarView;
  94. const RendererType = {
  95. CANVAS: "canvas",
  96. SVG: "svg"
  97. };
  98. exports.RendererType = RendererType;
  99. const TextLayerMode = {
  100. DISABLE: 0,
  101. ENABLE: 1
  102. };
  103. exports.TextLayerMode = TextLayerMode;
  104. const ScrollMode = {
  105. UNKNOWN: -1,
  106. VERTICAL: 0,
  107. HORIZONTAL: 1,
  108. WRAPPED: 2,
  109. PAGE: 3
  110. };
  111. exports.ScrollMode = ScrollMode;
  112. const SpreadMode = {
  113. UNKNOWN: -1,
  114. NONE: 0,
  115. ODD: 1,
  116. EVEN: 2
  117. };
  118. exports.SpreadMode = SpreadMode;
  119. const AutoPrintRegExp = /\bprint\s*\(/;
  120. exports.AutoPrintRegExp = AutoPrintRegExp;
  121. class OutputScale {
  122. constructor() {
  123. const pixelRatio = window.devicePixelRatio || 1;
  124. this.sx = pixelRatio;
  125. this.sy = pixelRatio;
  126. }
  127. get scaled() {
  128. return this.sx !== 1 || this.sy !== 1;
  129. }
  130. }
  131. exports.OutputScale = OutputScale;
  132. function scrollIntoView(element, spot, scrollMatches = false) {
  133. let parent = element.offsetParent;
  134. if (!parent) {
  135. console.error("offsetParent is not set -- cannot scroll");
  136. return;
  137. }
  138. let offsetY = element.offsetTop + element.clientTop;
  139. let offsetX = element.offsetLeft + element.clientLeft;
  140. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  141. offsetY += parent.offsetTop;
  142. offsetX += parent.offsetLeft;
  143. parent = parent.offsetParent;
  144. if (!parent) {
  145. return;
  146. }
  147. }
  148. if (spot) {
  149. if (spot.top !== undefined) {
  150. offsetY += spot.top;
  151. }
  152. if (spot.left !== undefined) {
  153. offsetX += spot.left;
  154. parent.scrollLeft = offsetX;
  155. }
  156. }
  157. parent.scrollTop = offsetY;
  158. }
  159. function watchScroll(viewAreaElement, callback) {
  160. const debounceScroll = function (evt) {
  161. if (rAF) {
  162. return;
  163. }
  164. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  165. rAF = null;
  166. const currentX = viewAreaElement.scrollLeft;
  167. const lastX = state.lastX;
  168. if (currentX !== lastX) {
  169. state.right = currentX > lastX;
  170. }
  171. state.lastX = currentX;
  172. const currentY = viewAreaElement.scrollTop;
  173. const lastY = state.lastY;
  174. if (currentY !== lastY) {
  175. state.down = currentY > lastY;
  176. }
  177. state.lastY = currentY;
  178. callback(state);
  179. });
  180. };
  181. const state = {
  182. right: true,
  183. down: true,
  184. lastX: viewAreaElement.scrollLeft,
  185. lastY: viewAreaElement.scrollTop,
  186. _eventHandler: debounceScroll
  187. };
  188. let rAF = null;
  189. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  190. return state;
  191. }
  192. function parseQueryString(query) {
  193. const params = new Map();
  194. for (const [key, value] of new URLSearchParams(query)) {
  195. params.set(key.toLowerCase(), value);
  196. }
  197. return params;
  198. }
  199. const NullCharactersRegExp = /\x00/g;
  200. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  201. function removeNullCharacters(str, replaceInvisible = false) {
  202. if (typeof str !== "string") {
  203. console.error(`The argument must be a string.`);
  204. return str;
  205. }
  206. if (replaceInvisible) {
  207. str = str.replace(InvisibleCharactersRegExp, " ");
  208. }
  209. return str.replace(NullCharactersRegExp, "");
  210. }
  211. function binarySearchFirstItem(items, condition, start = 0) {
  212. let minIndex = start;
  213. let maxIndex = items.length - 1;
  214. if (maxIndex < 0 || !condition(items[maxIndex])) {
  215. return items.length;
  216. }
  217. if (condition(items[minIndex])) {
  218. return minIndex;
  219. }
  220. while (minIndex < maxIndex) {
  221. const currentIndex = minIndex + maxIndex >> 1;
  222. const currentItem = items[currentIndex];
  223. if (condition(currentItem)) {
  224. maxIndex = currentIndex;
  225. } else {
  226. minIndex = currentIndex + 1;
  227. }
  228. }
  229. return minIndex;
  230. }
  231. function approximateFraction(x) {
  232. if (Math.floor(x) === x) {
  233. return [x, 1];
  234. }
  235. const xinv = 1 / x;
  236. const limit = 8;
  237. if (xinv > limit) {
  238. return [1, limit];
  239. } else if (Math.floor(xinv) === xinv) {
  240. return [1, xinv];
  241. }
  242. const x_ = x > 1 ? xinv : x;
  243. let a = 0,
  244. b = 1,
  245. c = 1,
  246. d = 1;
  247. while (true) {
  248. const p = a + c,
  249. q = b + d;
  250. if (q > limit) {
  251. break;
  252. }
  253. if (x_ <= p / q) {
  254. c = p;
  255. d = q;
  256. } else {
  257. a = p;
  258. b = q;
  259. }
  260. }
  261. let result;
  262. if (x_ - a / b < c / d - x_) {
  263. result = x_ === x ? [a, b] : [b, a];
  264. } else {
  265. result = x_ === x ? [c, d] : [d, c];
  266. }
  267. return result;
  268. }
  269. function roundToDivide(x, div) {
  270. const r = x % div;
  271. return r === 0 ? x : Math.round(x - r + div);
  272. }
  273. function getPageSizeInches({
  274. view,
  275. userUnit,
  276. rotate
  277. }) {
  278. const [x1, y1, x2, y2] = view;
  279. const changeOrientation = rotate % 180 !== 0;
  280. const width = (x2 - x1) / 72 * userUnit;
  281. const height = (y2 - y1) / 72 * userUnit;
  282. return {
  283. width: changeOrientation ? height : width,
  284. height: changeOrientation ? width : height
  285. };
  286. }
  287. function backtrackBeforeAllVisibleElements(index, views, top) {
  288. if (index < 2) {
  289. return index;
  290. }
  291. let elt = views[index].div;
  292. let pageTop = elt.offsetTop + elt.clientTop;
  293. if (pageTop >= top) {
  294. elt = views[index - 1].div;
  295. pageTop = elt.offsetTop + elt.clientTop;
  296. }
  297. for (let i = index - 2; i >= 0; --i) {
  298. elt = views[i].div;
  299. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  300. break;
  301. }
  302. index = i;
  303. }
  304. return index;
  305. }
  306. function getVisibleElements({
  307. scrollEl,
  308. views,
  309. sortByVisibility = false,
  310. horizontal = false,
  311. rtl = false
  312. }) {
  313. const top = scrollEl.scrollTop,
  314. bottom = top + scrollEl.clientHeight;
  315. const left = scrollEl.scrollLeft,
  316. right = left + scrollEl.clientWidth;
  317. function isElementBottomAfterViewTop(view) {
  318. const element = view.div;
  319. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  320. return elementBottom > top;
  321. }
  322. function isElementNextAfterViewHorizontally(view) {
  323. const element = view.div;
  324. const elementLeft = element.offsetLeft + element.clientLeft;
  325. const elementRight = elementLeft + element.clientWidth;
  326. return rtl ? elementLeft < right : elementRight > left;
  327. }
  328. const visible = [],
  329. ids = new Set(),
  330. numViews = views.length;
  331. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  332. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  333. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  334. }
  335. let lastEdge = horizontal ? right : -1;
  336. for (let i = firstVisibleElementInd; i < numViews; i++) {
  337. const view = views[i],
  338. element = view.div;
  339. const currentWidth = element.offsetLeft + element.clientLeft;
  340. const currentHeight = element.offsetTop + element.clientTop;
  341. const viewWidth = element.clientWidth,
  342. viewHeight = element.clientHeight;
  343. const viewRight = currentWidth + viewWidth;
  344. const viewBottom = currentHeight + viewHeight;
  345. if (lastEdge === -1) {
  346. if (viewBottom >= bottom) {
  347. lastEdge = viewBottom;
  348. }
  349. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  350. break;
  351. }
  352. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  353. continue;
  354. }
  355. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  356. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  357. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  358. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  359. const percent = fractionHeight * fractionWidth * 100 | 0;
  360. visible.push({
  361. id: view.id,
  362. x: currentWidth,
  363. y: currentHeight,
  364. view,
  365. percent,
  366. widthPercent: fractionWidth * 100 | 0
  367. });
  368. ids.add(view.id);
  369. }
  370. const first = visible[0],
  371. last = visible.at(-1);
  372. if (sortByVisibility) {
  373. visible.sort(function (a, b) {
  374. const pc = a.percent - b.percent;
  375. if (Math.abs(pc) > 0.001) {
  376. return -pc;
  377. }
  378. return a.id - b.id;
  379. });
  380. }
  381. return {
  382. first,
  383. last,
  384. views: visible,
  385. ids
  386. };
  387. }
  388. function noContextMenuHandler(evt) {
  389. evt.preventDefault();
  390. }
  391. function normalizeWheelEventDirection(evt) {
  392. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  393. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  394. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  395. delta = -delta;
  396. }
  397. return delta;
  398. }
  399. function normalizeWheelEventDelta(evt) {
  400. let delta = normalizeWheelEventDirection(evt);
  401. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  402. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  403. const MOUSE_PIXELS_PER_LINE = 30;
  404. const MOUSE_LINES_PER_PAGE = 30;
  405. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  406. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  407. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  408. delta /= MOUSE_LINES_PER_PAGE;
  409. }
  410. return delta;
  411. }
  412. function isValidRotation(angle) {
  413. return Number.isInteger(angle) && angle % 90 === 0;
  414. }
  415. function isValidScrollMode(mode) {
  416. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  417. }
  418. function isValidSpreadMode(mode) {
  419. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  420. }
  421. function isPortraitOrientation(size) {
  422. return size.width <= size.height;
  423. }
  424. const animationStarted = new Promise(function (resolve) {
  425. window.requestAnimationFrame(resolve);
  426. });
  427. exports.animationStarted = animationStarted;
  428. const docStyle = document.documentElement.style;
  429. exports.docStyle = docStyle;
  430. function clamp(v, min, max) {
  431. return Math.min(Math.max(v, min), max);
  432. }
  433. class ProgressBar {
  434. #classList = null;
  435. #percent = 0;
  436. #visible = true;
  437. constructor(id) {
  438. const bar = document.getElementById(id);
  439. this.#classList = bar.classList;
  440. }
  441. get percent() {
  442. return this.#percent;
  443. }
  444. set percent(val) {
  445. this.#percent = clamp(val, 0, 100);
  446. if (isNaN(val)) {
  447. this.#classList.add("indeterminate");
  448. return;
  449. }
  450. this.#classList.remove("indeterminate");
  451. docStyle.setProperty("--progressBar-percent", `${this.#percent}%`);
  452. }
  453. setWidth(viewer) {
  454. if (!viewer) {
  455. return;
  456. }
  457. const container = viewer.parentNode;
  458. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  459. if (scrollbarWidth > 0) {
  460. docStyle.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
  461. }
  462. }
  463. hide() {
  464. if (!this.#visible) {
  465. return;
  466. }
  467. this.#visible = false;
  468. this.#classList.add("hidden");
  469. }
  470. show() {
  471. if (this.#visible) {
  472. return;
  473. }
  474. this.#visible = true;
  475. this.#classList.remove("hidden");
  476. }
  477. }
  478. exports.ProgressBar = ProgressBar;
  479. function getActiveOrFocusedElement() {
  480. let curRoot = document;
  481. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  482. while (curActiveOrFocused?.shadowRoot) {
  483. curRoot = curActiveOrFocused.shadowRoot;
  484. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  485. }
  486. return curActiveOrFocused;
  487. }
  488. function apiPageLayoutToViewerModes(layout) {
  489. let scrollMode = ScrollMode.VERTICAL,
  490. spreadMode = SpreadMode.NONE;
  491. switch (layout) {
  492. case "SinglePage":
  493. scrollMode = ScrollMode.PAGE;
  494. break;
  495. case "OneColumn":
  496. break;
  497. case "TwoPageLeft":
  498. scrollMode = ScrollMode.PAGE;
  499. case "TwoColumnLeft":
  500. spreadMode = SpreadMode.ODD;
  501. break;
  502. case "TwoPageRight":
  503. scrollMode = ScrollMode.PAGE;
  504. case "TwoColumnRight":
  505. spreadMode = SpreadMode.EVEN;
  506. break;
  507. }
  508. return {
  509. scrollMode,
  510. spreadMode
  511. };
  512. }
  513. function apiPageModeToSidebarView(mode) {
  514. switch (mode) {
  515. case "UseNone":
  516. return SidebarView.NONE;
  517. case "UseThumbs":
  518. return SidebarView.THUMBS;
  519. case "UseOutlines":
  520. return SidebarView.OUTLINE;
  521. case "UseAttachments":
  522. return SidebarView.ATTACHMENTS;
  523. case "UseOC":
  524. return SidebarView.LAYERS;
  525. }
  526. return SidebarView.NONE;
  527. }
  528. /***/ }),
  529. /* 2 */
  530. /***/ ((__unused_webpack_module, exports) => {
  531. Object.defineProperty(exports, "__esModule", ({
  532. value: true
  533. }));
  534. exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
  535. const compatibilityParams = Object.create(null);
  536. exports.compatibilityParams = compatibilityParams;
  537. {
  538. const userAgent = navigator.userAgent || "";
  539. const platform = navigator.platform || "";
  540. const maxTouchPoints = navigator.maxTouchPoints || 1;
  541. const isAndroid = /Android/.test(userAgent);
  542. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  543. (function checkCanvasSizeLimitation() {
  544. if (isIOS || isAndroid) {
  545. compatibilityParams.maxCanvasPixels = 5242880;
  546. }
  547. })();
  548. }
  549. const OptionKind = {
  550. VIEWER: 0x02,
  551. API: 0x04,
  552. WORKER: 0x08,
  553. PREFERENCE: 0x80
  554. };
  555. exports.OptionKind = OptionKind;
  556. const defaultOptions = {
  557. annotationEditorMode: {
  558. value: 0,
  559. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  560. },
  561. annotationMode: {
  562. value: 2,
  563. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  564. },
  565. cursorToolOnLoad: {
  566. value: 0,
  567. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  568. },
  569. defaultZoomValue: {
  570. value: "",
  571. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  572. },
  573. disableHistory: {
  574. value: false,
  575. kind: OptionKind.VIEWER
  576. },
  577. disablePageLabels: {
  578. value: false,
  579. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  580. },
  581. enablePermissions: {
  582. value: false,
  583. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  584. },
  585. enablePrintAutoRotate: {
  586. value: true,
  587. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  588. },
  589. enableScripting: {
  590. value: true,
  591. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  592. },
  593. externalLinkRel: {
  594. value: "noopener noreferrer nofollow",
  595. kind: OptionKind.VIEWER
  596. },
  597. externalLinkTarget: {
  598. value: 0,
  599. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  600. },
  601. historyUpdateUrl: {
  602. value: false,
  603. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  604. },
  605. ignoreDestinationZoom: {
  606. value: false,
  607. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  608. },
  609. imageResourcesPath: {
  610. value: "./images/",
  611. kind: OptionKind.VIEWER
  612. },
  613. maxCanvasPixels: {
  614. value: 16777216,
  615. kind: OptionKind.VIEWER
  616. },
  617. forcePageColors: {
  618. value: false,
  619. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  620. },
  621. pageColorsBackground: {
  622. value: "Canvas",
  623. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  624. },
  625. pageColorsForeground: {
  626. value: "CanvasText",
  627. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  628. },
  629. pdfBugEnabled: {
  630. value: false,
  631. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  632. },
  633. printResolution: {
  634. value: 150,
  635. kind: OptionKind.VIEWER
  636. },
  637. sidebarViewOnLoad: {
  638. value: -1,
  639. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  640. },
  641. scrollModeOnLoad: {
  642. value: -1,
  643. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  644. },
  645. spreadModeOnLoad: {
  646. value: -1,
  647. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  648. },
  649. textLayerMode: {
  650. value: 1,
  651. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  652. },
  653. useOnlyCssZoom: {
  654. value: false,
  655. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  656. },
  657. viewerCssTheme: {
  658. value: 0,
  659. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  660. },
  661. viewOnLoad: {
  662. value: 0,
  663. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  664. },
  665. cMapPacked: {
  666. value: true,
  667. kind: OptionKind.API
  668. },
  669. cMapUrl: {
  670. value: "../web/cmaps/",
  671. kind: OptionKind.API
  672. },
  673. disableAutoFetch: {
  674. value: false,
  675. kind: OptionKind.API + OptionKind.PREFERENCE
  676. },
  677. disableFontFace: {
  678. value: false,
  679. kind: OptionKind.API + OptionKind.PREFERENCE
  680. },
  681. disableRange: {
  682. value: false,
  683. kind: OptionKind.API + OptionKind.PREFERENCE
  684. },
  685. disableStream: {
  686. value: false,
  687. kind: OptionKind.API + OptionKind.PREFERENCE
  688. },
  689. docBaseUrl: {
  690. value: "",
  691. kind: OptionKind.API
  692. },
  693. enableXfa: {
  694. value: true,
  695. kind: OptionKind.API + OptionKind.PREFERENCE
  696. },
  697. fontExtraProperties: {
  698. value: false,
  699. kind: OptionKind.API
  700. },
  701. isEvalSupported: {
  702. value: true,
  703. kind: OptionKind.API
  704. },
  705. isOffscreenCanvasSupported: {
  706. value: true,
  707. kind: OptionKind.API
  708. },
  709. maxImageSize: {
  710. value: -1,
  711. kind: OptionKind.API
  712. },
  713. pdfBug: {
  714. value: false,
  715. kind: OptionKind.API
  716. },
  717. standardFontDataUrl: {
  718. value: "../web/standard_fonts/",
  719. kind: OptionKind.API
  720. },
  721. verbosity: {
  722. value: 1,
  723. kind: OptionKind.API
  724. },
  725. workerPort: {
  726. value: null,
  727. kind: OptionKind.WORKER
  728. },
  729. workerSrc: {
  730. value: "../build/pdf.worker.js",
  731. kind: OptionKind.WORKER
  732. }
  733. };
  734. {
  735. defaultOptions.defaultUrl = {
  736. value: "compressed.tracemonkey-pldi-09.pdf",
  737. kind: OptionKind.VIEWER
  738. };
  739. defaultOptions.disablePreferences = {
  740. value: false,
  741. kind: OptionKind.VIEWER
  742. };
  743. defaultOptions.locale = {
  744. value: navigator.language || "en-US",
  745. kind: OptionKind.VIEWER
  746. };
  747. defaultOptions.renderer = {
  748. value: "canvas",
  749. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  750. };
  751. defaultOptions.sandboxBundleSrc = {
  752. value: "../build/pdf.sandbox.js",
  753. kind: OptionKind.VIEWER
  754. };
  755. }
  756. const userOptions = Object.create(null);
  757. class AppOptions {
  758. constructor() {
  759. throw new Error("Cannot initialize AppOptions.");
  760. }
  761. static get(name) {
  762. const userOption = userOptions[name];
  763. if (userOption !== undefined) {
  764. return userOption;
  765. }
  766. const defaultOption = defaultOptions[name];
  767. if (defaultOption !== undefined) {
  768. return compatibilityParams[name] ?? defaultOption.value;
  769. }
  770. return undefined;
  771. }
  772. static getAll(kind = null) {
  773. const options = Object.create(null);
  774. for (const name in defaultOptions) {
  775. const defaultOption = defaultOptions[name];
  776. if (kind) {
  777. if ((kind & defaultOption.kind) === 0) {
  778. continue;
  779. }
  780. if (kind === OptionKind.PREFERENCE) {
  781. const value = defaultOption.value,
  782. valueType = typeof value;
  783. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  784. options[name] = value;
  785. continue;
  786. }
  787. throw new Error(`Invalid type for preference: ${name}`);
  788. }
  789. }
  790. const userOption = userOptions[name];
  791. options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
  792. }
  793. return options;
  794. }
  795. static set(name, value) {
  796. userOptions[name] = value;
  797. }
  798. static setAll(options) {
  799. for (const name in options) {
  800. userOptions[name] = options[name];
  801. }
  802. }
  803. static remove(name) {
  804. delete userOptions[name];
  805. }
  806. static _hasUserOptions() {
  807. return Object.keys(userOptions).length > 0;
  808. }
  809. }
  810. exports.AppOptions = AppOptions;
  811. /***/ }),
  812. /* 3 */
  813. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  814. Object.defineProperty(exports, "__esModule", ({
  815. value: true
  816. }));
  817. exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
  818. var _ui_utils = __webpack_require__(1);
  819. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  820. const LinkTarget = {
  821. NONE: 0,
  822. SELF: 1,
  823. BLANK: 2,
  824. PARENT: 3,
  825. TOP: 4
  826. };
  827. exports.LinkTarget = LinkTarget;
  828. function addLinkAttributes(link, {
  829. url,
  830. target,
  831. rel,
  832. enabled = true
  833. } = {}) {
  834. if (!url || typeof url !== "string") {
  835. throw new Error('A valid "url" parameter must provided.');
  836. }
  837. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  838. if (enabled) {
  839. link.href = link.title = urlNullRemoved;
  840. } else {
  841. link.href = "";
  842. link.title = `Disabled: ${urlNullRemoved}`;
  843. link.onclick = () => {
  844. return false;
  845. };
  846. }
  847. let targetStr = "";
  848. switch (target) {
  849. case LinkTarget.NONE:
  850. break;
  851. case LinkTarget.SELF:
  852. targetStr = "_self";
  853. break;
  854. case LinkTarget.BLANK:
  855. targetStr = "_blank";
  856. break;
  857. case LinkTarget.PARENT:
  858. targetStr = "_parent";
  859. break;
  860. case LinkTarget.TOP:
  861. targetStr = "_top";
  862. break;
  863. }
  864. link.target = targetStr;
  865. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  866. }
  867. class PDFLinkService {
  868. #pagesRefCache = new Map();
  869. constructor({
  870. eventBus,
  871. externalLinkTarget = null,
  872. externalLinkRel = null,
  873. ignoreDestinationZoom = false
  874. } = {}) {
  875. this.eventBus = eventBus;
  876. this.externalLinkTarget = externalLinkTarget;
  877. this.externalLinkRel = externalLinkRel;
  878. this.externalLinkEnabled = true;
  879. this._ignoreDestinationZoom = ignoreDestinationZoom;
  880. this.baseUrl = null;
  881. this.pdfDocument = null;
  882. this.pdfViewer = null;
  883. this.pdfHistory = null;
  884. }
  885. setDocument(pdfDocument, baseUrl = null) {
  886. this.baseUrl = baseUrl;
  887. this.pdfDocument = pdfDocument;
  888. this.#pagesRefCache.clear();
  889. }
  890. setViewer(pdfViewer) {
  891. this.pdfViewer = pdfViewer;
  892. }
  893. setHistory(pdfHistory) {
  894. this.pdfHistory = pdfHistory;
  895. }
  896. get pagesCount() {
  897. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  898. }
  899. get page() {
  900. return this.pdfViewer.currentPageNumber;
  901. }
  902. set page(value) {
  903. this.pdfViewer.currentPageNumber = value;
  904. }
  905. get rotation() {
  906. return this.pdfViewer.pagesRotation;
  907. }
  908. set rotation(value) {
  909. this.pdfViewer.pagesRotation = value;
  910. }
  911. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  912. const destRef = explicitDest[0];
  913. let pageNumber;
  914. if (typeof destRef === "object" && destRef !== null) {
  915. pageNumber = this._cachedPageNumber(destRef);
  916. if (!pageNumber) {
  917. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  918. this.cachePageRef(pageIndex + 1, destRef);
  919. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  920. }).catch(() => {
  921. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  922. });
  923. return;
  924. }
  925. } else if (Number.isInteger(destRef)) {
  926. pageNumber = destRef + 1;
  927. } else {
  928. console.error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  929. return;
  930. }
  931. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  932. console.error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  933. return;
  934. }
  935. if (this.pdfHistory) {
  936. this.pdfHistory.pushCurrentPosition();
  937. this.pdfHistory.push({
  938. namedDest,
  939. explicitDest,
  940. pageNumber
  941. });
  942. }
  943. this.pdfViewer.scrollPageIntoView({
  944. pageNumber,
  945. destArray: explicitDest,
  946. ignoreDestinationZoom: this._ignoreDestinationZoom
  947. });
  948. }
  949. async goToDestination(dest) {
  950. if (!this.pdfDocument) {
  951. return;
  952. }
  953. let namedDest, explicitDest;
  954. if (typeof dest === "string") {
  955. namedDest = dest;
  956. explicitDest = await this.pdfDocument.getDestination(dest);
  957. } else {
  958. namedDest = null;
  959. explicitDest = await dest;
  960. }
  961. if (!Array.isArray(explicitDest)) {
  962. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  963. return;
  964. }
  965. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  966. }
  967. goToPage(val) {
  968. if (!this.pdfDocument) {
  969. return;
  970. }
  971. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  972. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  973. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  974. return;
  975. }
  976. if (this.pdfHistory) {
  977. this.pdfHistory.pushCurrentPosition();
  978. this.pdfHistory.pushPage(pageNumber);
  979. }
  980. this.pdfViewer.scrollPageIntoView({
  981. pageNumber
  982. });
  983. }
  984. addLinkAttributes(link, url, newWindow = false) {
  985. addLinkAttributes(link, {
  986. url,
  987. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  988. rel: this.externalLinkRel,
  989. enabled: this.externalLinkEnabled
  990. });
  991. }
  992. getDestinationHash(dest) {
  993. if (typeof dest === "string") {
  994. if (dest.length > 0) {
  995. return this.getAnchorUrl("#" + escape(dest));
  996. }
  997. } else if (Array.isArray(dest)) {
  998. const str = JSON.stringify(dest);
  999. if (str.length > 0) {
  1000. return this.getAnchorUrl("#" + escape(str));
  1001. }
  1002. }
  1003. return this.getAnchorUrl("");
  1004. }
  1005. getAnchorUrl(anchor) {
  1006. return (this.baseUrl || "") + anchor;
  1007. }
  1008. setHash(hash) {
  1009. if (!this.pdfDocument) {
  1010. return;
  1011. }
  1012. let pageNumber, dest;
  1013. if (hash.includes("=")) {
  1014. const params = (0, _ui_utils.parseQueryString)(hash);
  1015. if (params.has("search")) {
  1016. this.eventBus.dispatch("findfromurlhash", {
  1017. source: this,
  1018. query: params.get("search").replace(/"/g, ""),
  1019. phraseSearch: params.get("phrase") === "true"
  1020. });
  1021. }
  1022. if (params.has("page")) {
  1023. pageNumber = params.get("page") | 0 || 1;
  1024. }
  1025. if (params.has("zoom")) {
  1026. const zoomArgs = params.get("zoom").split(",");
  1027. const zoomArg = zoomArgs[0];
  1028. const zoomArgNumber = parseFloat(zoomArg);
  1029. if (!zoomArg.includes("Fit")) {
  1030. dest = [null, {
  1031. name: "XYZ"
  1032. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  1033. } else {
  1034. if (zoomArg === "Fit" || zoomArg === "FitB") {
  1035. dest = [null, {
  1036. name: zoomArg
  1037. }];
  1038. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  1039. dest = [null, {
  1040. name: zoomArg
  1041. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  1042. } else if (zoomArg === "FitR") {
  1043. if (zoomArgs.length !== 5) {
  1044. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  1045. } else {
  1046. dest = [null, {
  1047. name: zoomArg
  1048. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  1049. }
  1050. } else {
  1051. console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
  1052. }
  1053. }
  1054. }
  1055. if (dest) {
  1056. this.pdfViewer.scrollPageIntoView({
  1057. pageNumber: pageNumber || this.page,
  1058. destArray: dest,
  1059. allowNegativeOffset: true
  1060. });
  1061. } else if (pageNumber) {
  1062. this.page = pageNumber;
  1063. }
  1064. if (params.has("pagemode")) {
  1065. this.eventBus.dispatch("pagemode", {
  1066. source: this,
  1067. mode: params.get("pagemode")
  1068. });
  1069. }
  1070. if (params.has("nameddest")) {
  1071. this.goToDestination(params.get("nameddest"));
  1072. }
  1073. } else {
  1074. dest = unescape(hash);
  1075. try {
  1076. dest = JSON.parse(dest);
  1077. if (!Array.isArray(dest)) {
  1078. dest = dest.toString();
  1079. }
  1080. } catch (ex) {}
  1081. if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
  1082. this.goToDestination(dest);
  1083. return;
  1084. }
  1085. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
  1086. }
  1087. }
  1088. executeNamedAction(action) {
  1089. switch (action) {
  1090. case "GoBack":
  1091. this.pdfHistory?.back();
  1092. break;
  1093. case "GoForward":
  1094. this.pdfHistory?.forward();
  1095. break;
  1096. case "NextPage":
  1097. this.pdfViewer.nextPage();
  1098. break;
  1099. case "PrevPage":
  1100. this.pdfViewer.previousPage();
  1101. break;
  1102. case "LastPage":
  1103. this.page = this.pagesCount;
  1104. break;
  1105. case "FirstPage":
  1106. this.page = 1;
  1107. break;
  1108. default:
  1109. break;
  1110. }
  1111. this.eventBus.dispatch("namedaction", {
  1112. source: this,
  1113. action
  1114. });
  1115. }
  1116. async executeSetOCGState(action) {
  1117. const pdfDocument = this.pdfDocument;
  1118. const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
  1119. if (pdfDocument !== this.pdfDocument) {
  1120. return;
  1121. }
  1122. let operator;
  1123. for (const elem of action.state) {
  1124. switch (elem) {
  1125. case "ON":
  1126. case "OFF":
  1127. case "Toggle":
  1128. operator = elem;
  1129. continue;
  1130. }
  1131. switch (operator) {
  1132. case "ON":
  1133. optionalContentConfig.setVisibility(elem, true);
  1134. break;
  1135. case "OFF":
  1136. optionalContentConfig.setVisibility(elem, false);
  1137. break;
  1138. case "Toggle":
  1139. const group = optionalContentConfig.getGroup(elem);
  1140. if (group) {
  1141. optionalContentConfig.setVisibility(elem, !group.visible);
  1142. }
  1143. break;
  1144. }
  1145. }
  1146. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
  1147. }
  1148. cachePageRef(pageNum, pageRef) {
  1149. if (!pageRef) {
  1150. return;
  1151. }
  1152. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1153. this.#pagesRefCache.set(refStr, pageNum);
  1154. }
  1155. _cachedPageNumber(pageRef) {
  1156. if (!pageRef) {
  1157. return null;
  1158. }
  1159. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  1160. return this.#pagesRefCache.get(refStr) || null;
  1161. }
  1162. isPageVisible(pageNumber) {
  1163. return this.pdfViewer.isPageVisible(pageNumber);
  1164. }
  1165. isPageCached(pageNumber) {
  1166. return this.pdfViewer.isPageCached(pageNumber);
  1167. }
  1168. static #isValidExplicitDestination(dest) {
  1169. if (!Array.isArray(dest)) {
  1170. return false;
  1171. }
  1172. const destLength = dest.length;
  1173. if (destLength < 2) {
  1174. return false;
  1175. }
  1176. const page = dest[0];
  1177. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  1178. return false;
  1179. }
  1180. const zoom = dest[1];
  1181. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  1182. return false;
  1183. }
  1184. let allowNull = true;
  1185. switch (zoom.name) {
  1186. case "XYZ":
  1187. if (destLength !== 5) {
  1188. return false;
  1189. }
  1190. break;
  1191. case "Fit":
  1192. case "FitB":
  1193. return destLength === 2;
  1194. case "FitH":
  1195. case "FitBH":
  1196. case "FitV":
  1197. case "FitBV":
  1198. if (destLength !== 3) {
  1199. return false;
  1200. }
  1201. break;
  1202. case "FitR":
  1203. if (destLength !== 6) {
  1204. return false;
  1205. }
  1206. allowNull = false;
  1207. break;
  1208. default:
  1209. return false;
  1210. }
  1211. for (let i = 2; i < destLength; i++) {
  1212. const param = dest[i];
  1213. if (!(typeof param === "number" || allowNull && param === null)) {
  1214. return false;
  1215. }
  1216. }
  1217. return true;
  1218. }
  1219. }
  1220. exports.PDFLinkService = PDFLinkService;
  1221. class SimpleLinkService {
  1222. constructor() {
  1223. this.externalLinkEnabled = true;
  1224. }
  1225. get pagesCount() {
  1226. return 0;
  1227. }
  1228. get page() {
  1229. return 0;
  1230. }
  1231. set page(value) {}
  1232. get rotation() {
  1233. return 0;
  1234. }
  1235. set rotation(value) {}
  1236. async goToDestination(dest) {}
  1237. goToPage(val) {}
  1238. addLinkAttributes(link, url, newWindow = false) {
  1239. addLinkAttributes(link, {
  1240. url,
  1241. enabled: this.externalLinkEnabled
  1242. });
  1243. }
  1244. getDestinationHash(dest) {
  1245. return "#";
  1246. }
  1247. getAnchorUrl(hash) {
  1248. return "#";
  1249. }
  1250. setHash(hash) {}
  1251. executeNamedAction(action) {}
  1252. executeSetOCGState(action) {}
  1253. cachePageRef(pageNum, pageRef) {}
  1254. isPageVisible(pageNumber) {
  1255. return true;
  1256. }
  1257. isPageCached(pageNumber) {
  1258. return true;
  1259. }
  1260. }
  1261. exports.SimpleLinkService = SimpleLinkService;
  1262. /***/ }),
  1263. /* 4 */
  1264. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  1265. Object.defineProperty(exports, "__esModule", ({
  1266. value: true
  1267. }));
  1268. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  1269. var _ui_utils = __webpack_require__(1);
  1270. var _pdfjsLib = __webpack_require__(5);
  1271. var _app_options = __webpack_require__(2);
  1272. var _event_utils = __webpack_require__(6);
  1273. var _pdf_cursor_tools = __webpack_require__(7);
  1274. var _pdf_link_service = __webpack_require__(3);
  1275. var _annotation_editor_params = __webpack_require__(9);
  1276. var _overlay_manager = __webpack_require__(10);
  1277. var _password_prompt = __webpack_require__(11);
  1278. var _pdf_attachment_viewer = __webpack_require__(12);
  1279. var _pdf_document_properties = __webpack_require__(14);
  1280. var _pdf_find_bar = __webpack_require__(15);
  1281. var _pdf_find_controller = __webpack_require__(16);
  1282. var _pdf_history = __webpack_require__(18);
  1283. var _pdf_layer_viewer = __webpack_require__(19);
  1284. var _pdf_outline_viewer = __webpack_require__(20);
  1285. var _pdf_presentation_mode = __webpack_require__(21);
  1286. var _pdf_rendering_queue = __webpack_require__(22);
  1287. var _pdf_scripting_manager = __webpack_require__(23);
  1288. var _pdf_sidebar = __webpack_require__(24);
  1289. var _pdf_sidebar_resizer = __webpack_require__(25);
  1290. var _pdf_thumbnail_viewer = __webpack_require__(26);
  1291. var _pdf_viewer = __webpack_require__(28);
  1292. var _secondary_toolbar = __webpack_require__(38);
  1293. var _toolbar = __webpack_require__(39);
  1294. var _view_history = __webpack_require__(40);
  1295. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  1296. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  1297. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  1298. const ViewOnLoad = {
  1299. UNKNOWN: -1,
  1300. PREVIOUS: 0,
  1301. INITIAL: 1
  1302. };
  1303. const ViewerCssTheme = {
  1304. AUTOMATIC: 0,
  1305. LIGHT: 1,
  1306. DARK: 2
  1307. };
  1308. const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
  1309. const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
  1310. class DefaultExternalServices {
  1311. constructor() {
  1312. throw new Error("Cannot initialize DefaultExternalServices.");
  1313. }
  1314. static updateFindControlState(data) {}
  1315. static updateFindMatchesCount(data) {}
  1316. static initPassiveLoading(callbacks) {}
  1317. static reportTelemetry(data) {}
  1318. static createDownloadManager(options) {
  1319. throw new Error("Not implemented: createDownloadManager");
  1320. }
  1321. static createPreferences() {
  1322. throw new Error("Not implemented: createPreferences");
  1323. }
  1324. static createL10n(options) {
  1325. throw new Error("Not implemented: createL10n");
  1326. }
  1327. static createScripting(options) {
  1328. throw new Error("Not implemented: createScripting");
  1329. }
  1330. static get supportsIntegratedFind() {
  1331. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  1332. }
  1333. static get supportsDocumentFonts() {
  1334. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  1335. }
  1336. static get supportedMouseWheelZoomModifierKeys() {
  1337. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  1338. ctrlKey: true,
  1339. metaKey: true
  1340. });
  1341. }
  1342. static get isInAutomation() {
  1343. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  1344. }
  1345. static updateEditorStates(data) {
  1346. throw new Error("Not implemented: updateEditorStates");
  1347. }
  1348. }
  1349. exports.DefaultExternalServices = DefaultExternalServices;
  1350. const PDFViewerApplication = {
  1351. initialBookmark: document.location.hash.substring(1),
  1352. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  1353. appConfig: null,
  1354. pdfDocument: null,
  1355. pdfLoadingTask: null,
  1356. printService: null,
  1357. pdfViewer: null,
  1358. pdfThumbnailViewer: null,
  1359. pdfRenderingQueue: null,
  1360. pdfPresentationMode: null,
  1361. pdfDocumentProperties: null,
  1362. pdfLinkService: null,
  1363. pdfHistory: null,
  1364. pdfSidebar: null,
  1365. pdfSidebarResizer: null,
  1366. pdfOutlineViewer: null,
  1367. pdfAttachmentViewer: null,
  1368. pdfLayerViewer: null,
  1369. pdfCursorTools: null,
  1370. pdfScriptingManager: null,
  1371. store: null,
  1372. downloadManager: null,
  1373. overlayManager: null,
  1374. preferences: null,
  1375. toolbar: null,
  1376. secondaryToolbar: null,
  1377. eventBus: null,
  1378. l10n: null,
  1379. annotationEditorParams: null,
  1380. isInitialViewSet: false,
  1381. downloadComplete: false,
  1382. isViewerEmbedded: window.parent !== window,
  1383. url: "",
  1384. baseUrl: "",
  1385. _downloadUrl: "",
  1386. externalServices: DefaultExternalServices,
  1387. _boundEvents: Object.create(null),
  1388. documentInfo: null,
  1389. metadata: null,
  1390. _contentDispositionFilename: null,
  1391. _contentLength: null,
  1392. _saveInProgress: false,
  1393. _docStats: null,
  1394. _wheelUnusedTicks: 0,
  1395. _PDFBug: null,
  1396. _hasAnnotationEditors: false,
  1397. _title: document.title,
  1398. _printAnnotationStoragePromise: null,
  1399. async initialize(appConfig) {
  1400. this.preferences = this.externalServices.createPreferences();
  1401. this.appConfig = appConfig;
  1402. await this._readPreferences();
  1403. await this._parseHashParameters();
  1404. this._forceCssTheme();
  1405. await this._initializeL10n();
  1406. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
  1407. _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
  1408. }
  1409. await this._initializeViewerComponents();
  1410. this.bindEvents();
  1411. this.bindWindowEvents();
  1412. const appContainer = appConfig.appContainer || document.documentElement;
  1413. this.l10n.translate(appContainer).then(() => {
  1414. this.eventBus.dispatch("localized", {
  1415. source: this
  1416. });
  1417. });
  1418. this._initializedCapability.resolve();
  1419. },
  1420. async _readPreferences() {
  1421. if (_app_options.AppOptions.get("disablePreferences")) {
  1422. return;
  1423. }
  1424. if (_app_options.AppOptions._hasUserOptions()) {
  1425. console.warn("_readPreferences: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
  1426. }
  1427. try {
  1428. _app_options.AppOptions.setAll(await this.preferences.getAll());
  1429. } catch (reason) {
  1430. console.error(`_readPreferences: "${reason?.message}".`);
  1431. }
  1432. },
  1433. async _parseHashParameters() {
  1434. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  1435. return;
  1436. }
  1437. const hash = document.location.hash.substring(1);
  1438. if (!hash) {
  1439. return;
  1440. }
  1441. const {
  1442. mainContainer,
  1443. viewerContainer
  1444. } = this.appConfig,
  1445. params = (0, _ui_utils.parseQueryString)(hash);
  1446. if (params.get("disableworker") === "true") {
  1447. try {
  1448. await loadFakeWorker();
  1449. } catch (ex) {
  1450. console.error(`_parseHashParameters: "${ex.message}".`);
  1451. }
  1452. }
  1453. if (params.has("disablerange")) {
  1454. _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
  1455. }
  1456. if (params.has("disablestream")) {
  1457. _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
  1458. }
  1459. if (params.has("disableautofetch")) {
  1460. _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
  1461. }
  1462. if (params.has("disablefontface")) {
  1463. _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
  1464. }
  1465. if (params.has("disablehistory")) {
  1466. _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
  1467. }
  1468. if (params.has("verbosity")) {
  1469. _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
  1470. }
  1471. if (params.has("textlayer")) {
  1472. switch (params.get("textlayer")) {
  1473. case "off":
  1474. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  1475. break;
  1476. case "visible":
  1477. case "shadow":
  1478. case "hover":
  1479. viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
  1480. try {
  1481. await loadPDFBug(this);
  1482. this._PDFBug.loadCSS();
  1483. } catch (ex) {
  1484. console.error(`_parseHashParameters: "${ex.message}".`);
  1485. }
  1486. break;
  1487. }
  1488. }
  1489. if (params.has("pdfbug")) {
  1490. _app_options.AppOptions.set("pdfBug", true);
  1491. _app_options.AppOptions.set("fontExtraProperties", true);
  1492. const enabled = params.get("pdfbug").split(",");
  1493. try {
  1494. await loadPDFBug(this);
  1495. this._PDFBug.init({
  1496. OPS: _pdfjsLib.OPS
  1497. }, mainContainer, enabled);
  1498. } catch (ex) {
  1499. console.error(`_parseHashParameters: "${ex.message}".`);
  1500. }
  1501. }
  1502. if (params.has("locale")) {
  1503. _app_options.AppOptions.set("locale", params.get("locale"));
  1504. }
  1505. },
  1506. async _initializeL10n() {
  1507. this.l10n = this.externalServices.createL10n({
  1508. locale: _app_options.AppOptions.get("locale")
  1509. });
  1510. const dir = await this.l10n.getDirection();
  1511. document.getElementsByTagName("html")[0].dir = dir;
  1512. },
  1513. _forceCssTheme() {
  1514. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  1515. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  1516. return;
  1517. }
  1518. try {
  1519. const styleSheet = document.styleSheets[0];
  1520. const cssRules = styleSheet?.cssRules || [];
  1521. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  1522. const rule = cssRules[i];
  1523. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  1524. if (cssTheme === ViewerCssTheme.LIGHT) {
  1525. styleSheet.deleteRule(i);
  1526. return;
  1527. }
  1528. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  1529. if (darkRules?.[1]) {
  1530. styleSheet.deleteRule(i);
  1531. styleSheet.insertRule(darkRules[1], i);
  1532. }
  1533. return;
  1534. }
  1535. }
  1536. } catch (reason) {
  1537. console.error(`_forceCssTheme: "${reason?.message}".`);
  1538. }
  1539. },
  1540. async _initializeViewerComponents() {
  1541. const {
  1542. appConfig,
  1543. externalServices
  1544. } = this;
  1545. const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
  1546. this.eventBus = eventBus;
  1547. this.overlayManager = new _overlay_manager.OverlayManager();
  1548. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  1549. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  1550. this.pdfRenderingQueue = pdfRenderingQueue;
  1551. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  1552. eventBus,
  1553. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  1554. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  1555. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  1556. });
  1557. this.pdfLinkService = pdfLinkService;
  1558. const downloadManager = externalServices.createDownloadManager();
  1559. this.downloadManager = downloadManager;
  1560. const findController = new _pdf_find_controller.PDFFindController({
  1561. linkService: pdfLinkService,
  1562. eventBus
  1563. });
  1564. this.findController = findController;
  1565. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  1566. eventBus,
  1567. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  1568. scriptingFactory: externalServices,
  1569. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  1570. });
  1571. this.pdfScriptingManager = pdfScriptingManager;
  1572. const container = appConfig.mainContainer,
  1573. viewer = appConfig.viewerContainer;
  1574. const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
  1575. const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
  1576. background: _app_options.AppOptions.get("pageColorsBackground"),
  1577. foreground: _app_options.AppOptions.get("pageColorsForeground")
  1578. } : null;
  1579. this.pdfViewer = new _pdf_viewer.PDFViewer({
  1580. container,
  1581. viewer,
  1582. eventBus,
  1583. renderingQueue: pdfRenderingQueue,
  1584. linkService: pdfLinkService,
  1585. downloadManager,
  1586. findController,
  1587. scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
  1588. renderer: _app_options.AppOptions.get("renderer"),
  1589. l10n: this.l10n,
  1590. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  1591. annotationMode: _app_options.AppOptions.get("annotationMode"),
  1592. annotationEditorMode,
  1593. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  1594. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  1595. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  1596. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  1597. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  1598. pageColors
  1599. });
  1600. pdfRenderingQueue.setViewer(this.pdfViewer);
  1601. pdfLinkService.setViewer(this.pdfViewer);
  1602. pdfScriptingManager.setViewer(this.pdfViewer);
  1603. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  1604. container: appConfig.sidebar.thumbnailView,
  1605. eventBus,
  1606. renderingQueue: pdfRenderingQueue,
  1607. linkService: pdfLinkService,
  1608. l10n: this.l10n,
  1609. pageColors
  1610. });
  1611. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  1612. if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
  1613. this.pdfHistory = new _pdf_history.PDFHistory({
  1614. linkService: pdfLinkService,
  1615. eventBus
  1616. });
  1617. pdfLinkService.setHistory(this.pdfHistory);
  1618. }
  1619. if (!this.supportsIntegratedFind) {
  1620. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  1621. }
  1622. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  1623. this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
  1624. } else {
  1625. for (const element of [document.getElementById("editorModeButtons"), document.getElementById("editorModeSeparator")]) {
  1626. element.hidden = true;
  1627. }
  1628. }
  1629. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
  1630. return this._docFilename;
  1631. });
  1632. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  1633. container,
  1634. eventBus,
  1635. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  1636. });
  1637. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  1638. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, this.externalServices);
  1639. if (this.supportsFullscreen) {
  1640. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  1641. container,
  1642. pdfViewer: this.pdfViewer,
  1643. eventBus
  1644. });
  1645. }
  1646. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  1647. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  1648. container: appConfig.sidebar.outlineView,
  1649. eventBus,
  1650. linkService: pdfLinkService,
  1651. downloadManager
  1652. });
  1653. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  1654. container: appConfig.sidebar.attachmentsView,
  1655. eventBus,
  1656. downloadManager
  1657. });
  1658. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  1659. container: appConfig.sidebar.layersView,
  1660. eventBus,
  1661. l10n: this.l10n
  1662. });
  1663. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  1664. elements: appConfig.sidebar,
  1665. pdfViewer: this.pdfViewer,
  1666. pdfThumbnailViewer: this.pdfThumbnailViewer,
  1667. eventBus,
  1668. l10n: this.l10n
  1669. });
  1670. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  1671. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  1672. },
  1673. run(config) {
  1674. this.initialize(config).then(webViewerInitialized);
  1675. },
  1676. get initialized() {
  1677. return this._initializedCapability.settled;
  1678. },
  1679. get initializedPromise() {
  1680. return this._initializedCapability.promise;
  1681. },
  1682. zoomIn(steps) {
  1683. if (this.pdfViewer.isInPresentationMode) {
  1684. return;
  1685. }
  1686. this.pdfViewer.increaseScale(steps);
  1687. },
  1688. zoomOut(steps) {
  1689. if (this.pdfViewer.isInPresentationMode) {
  1690. return;
  1691. }
  1692. this.pdfViewer.decreaseScale(steps);
  1693. },
  1694. zoomReset() {
  1695. if (this.pdfViewer.isInPresentationMode) {
  1696. return;
  1697. }
  1698. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1699. },
  1700. get pagesCount() {
  1701. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  1702. },
  1703. get page() {
  1704. return this.pdfViewer.currentPageNumber;
  1705. },
  1706. set page(val) {
  1707. this.pdfViewer.currentPageNumber = val;
  1708. },
  1709. get supportsPrinting() {
  1710. return PDFPrintServiceFactory.instance.supportsPrinting;
  1711. },
  1712. get supportsFullscreen() {
  1713. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
  1714. },
  1715. get supportsIntegratedFind() {
  1716. return this.externalServices.supportsIntegratedFind;
  1717. },
  1718. get supportsDocumentFonts() {
  1719. return this.externalServices.supportsDocumentFonts;
  1720. },
  1721. get loadingBar() {
  1722. const bar = new _ui_utils.ProgressBar("loadingBar");
  1723. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  1724. },
  1725. get supportedMouseWheelZoomModifierKeys() {
  1726. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  1727. },
  1728. initPassiveLoading() {
  1729. throw new Error("Not implemented: initPassiveLoading");
  1730. },
  1731. setTitleUsingUrl(url = "", downloadUrl = null) {
  1732. this.url = url;
  1733. this.baseUrl = url.split("#")[0];
  1734. if (downloadUrl) {
  1735. this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  1736. }
  1737. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  1738. if (!title) {
  1739. try {
  1740. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  1741. } catch (ex) {
  1742. title = url;
  1743. }
  1744. }
  1745. this.setTitle(title);
  1746. },
  1747. setTitle(title = this._title) {
  1748. this._title = title;
  1749. if (this.isViewerEmbedded) {
  1750. return;
  1751. }
  1752. const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  1753. document.title = `${editorIndicator ? "* " : ""}${title}`;
  1754. },
  1755. get _docFilename() {
  1756. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  1757. },
  1758. _hideViewBookmark() {
  1759. this.appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
  1760. },
  1761. async close() {
  1762. this._unblockDocumentLoadEvent();
  1763. this._hideViewBookmark();
  1764. if (!this.pdfLoadingTask) {
  1765. return;
  1766. }
  1767. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  1768. try {
  1769. await this.save();
  1770. } catch (reason) {}
  1771. }
  1772. const promises = [];
  1773. promises.push(this.pdfLoadingTask.destroy());
  1774. this.pdfLoadingTask = null;
  1775. if (this.pdfDocument) {
  1776. this.pdfDocument = null;
  1777. this.pdfThumbnailViewer.setDocument(null);
  1778. this.pdfViewer.setDocument(null);
  1779. this.pdfLinkService.setDocument(null);
  1780. this.pdfDocumentProperties.setDocument(null);
  1781. }
  1782. this.pdfLinkService.externalLinkEnabled = true;
  1783. this.store = null;
  1784. this.isInitialViewSet = false;
  1785. this.downloadComplete = false;
  1786. this.url = "";
  1787. this.baseUrl = "";
  1788. this._downloadUrl = "";
  1789. this.documentInfo = null;
  1790. this.metadata = null;
  1791. this._contentDispositionFilename = null;
  1792. this._contentLength = null;
  1793. this._saveInProgress = false;
  1794. this._docStats = null;
  1795. this._hasAnnotationEditors = false;
  1796. promises.push(this.pdfScriptingManager.destroyPromise);
  1797. this.setTitle();
  1798. this.pdfSidebar.reset();
  1799. this.pdfOutlineViewer.reset();
  1800. this.pdfAttachmentViewer.reset();
  1801. this.pdfLayerViewer.reset();
  1802. this.pdfHistory?.reset();
  1803. this.findBar?.reset();
  1804. this.toolbar.reset();
  1805. this.secondaryToolbar.reset();
  1806. this._PDFBug?.cleanup();
  1807. await Promise.all(promises);
  1808. },
  1809. async open(file, args) {
  1810. if (this.pdfLoadingTask) {
  1811. await this.close();
  1812. }
  1813. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  1814. for (const key in workerParameters) {
  1815. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  1816. }
  1817. const parameters = Object.create(null);
  1818. if (typeof file === "string") {
  1819. this.setTitleUsingUrl(file, file);
  1820. parameters.url = file;
  1821. } else if (file && "byteLength" in file) {
  1822. parameters.data = file;
  1823. } else if (file.url && file.originalUrl) {
  1824. this.setTitleUsingUrl(file.originalUrl, file.url);
  1825. parameters.url = file.url;
  1826. }
  1827. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  1828. for (const key in apiParameters) {
  1829. let value = apiParameters[key];
  1830. if (key === "docBaseUrl" && !value) {}
  1831. parameters[key] = value;
  1832. }
  1833. if (args) {
  1834. for (const key in args) {
  1835. parameters[key] = args[key];
  1836. }
  1837. }
  1838. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  1839. this.pdfLoadingTask = loadingTask;
  1840. loadingTask.onPassword = (updateCallback, reason) => {
  1841. this.pdfLinkService.externalLinkEnabled = false;
  1842. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  1843. this.passwordPrompt.open();
  1844. };
  1845. loadingTask.onProgress = ({
  1846. loaded,
  1847. total
  1848. }) => {
  1849. this.progress(loaded / total);
  1850. };
  1851. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  1852. return loadingTask.promise.then(pdfDocument => {
  1853. this.load(pdfDocument);
  1854. }, reason => {
  1855. if (loadingTask !== this.pdfLoadingTask) {
  1856. return undefined;
  1857. }
  1858. let key = "loading_error";
  1859. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  1860. key = "invalid_file_error";
  1861. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  1862. key = "missing_file_error";
  1863. } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
  1864. key = "unexpected_response_error";
  1865. }
  1866. return this.l10n.get(key).then(msg => {
  1867. this._documentError(msg, {
  1868. message: reason?.message
  1869. });
  1870. throw reason;
  1871. });
  1872. });
  1873. },
  1874. _ensureDownloadComplete() {
  1875. if (this.pdfDocument && this.downloadComplete) {
  1876. return;
  1877. }
  1878. throw new Error("PDF document not downloaded.");
  1879. },
  1880. async download() {
  1881. const url = this._downloadUrl,
  1882. filename = this._docFilename;
  1883. try {
  1884. this._ensureDownloadComplete();
  1885. const data = await this.pdfDocument.getData();
  1886. const blob = new Blob([data], {
  1887. type: "application/pdf"
  1888. });
  1889. await this.downloadManager.download(blob, url, filename);
  1890. } catch (reason) {
  1891. await this.downloadManager.downloadUrl(url, filename);
  1892. }
  1893. },
  1894. async save() {
  1895. if (this._saveInProgress) {
  1896. return;
  1897. }
  1898. this._saveInProgress = true;
  1899. await this.pdfScriptingManager.dispatchWillSave();
  1900. const url = this._downloadUrl,
  1901. filename = this._docFilename;
  1902. try {
  1903. this._ensureDownloadComplete();
  1904. const data = await this.pdfDocument.saveDocument();
  1905. const blob = new Blob([data], {
  1906. type: "application/pdf"
  1907. });
  1908. await this.downloadManager.download(blob, url, filename);
  1909. } catch (reason) {
  1910. console.error(`Error when saving the document: ${reason.message}`);
  1911. await this.download();
  1912. } finally {
  1913. await this.pdfScriptingManager.dispatchDidSave();
  1914. this._saveInProgress = false;
  1915. }
  1916. if (this._hasAnnotationEditors) {
  1917. this.externalServices.reportTelemetry({
  1918. type: "editing",
  1919. data: {
  1920. type: "save"
  1921. }
  1922. });
  1923. }
  1924. },
  1925. downloadOrSave() {
  1926. if (this.pdfDocument?.annotationStorage.size > 0) {
  1927. this.save();
  1928. } else {
  1929. this.download();
  1930. }
  1931. },
  1932. fallback(featureId) {
  1933. this.externalServices.reportTelemetry({
  1934. type: "unsupportedFeature",
  1935. featureId
  1936. });
  1937. },
  1938. _documentError(message, moreInfo = null) {
  1939. this._unblockDocumentLoadEvent();
  1940. this._otherError(message, moreInfo);
  1941. this.eventBus.dispatch("documenterror", {
  1942. source: this,
  1943. message,
  1944. reason: moreInfo?.message ?? null
  1945. });
  1946. },
  1947. _otherError(message, moreInfo = null) {
  1948. const moreInfoText = [`PDF.js v${_pdfjsLib.version || "?"} (build: ${_pdfjsLib.build || "?"})`];
  1949. if (moreInfo) {
  1950. moreInfoText.push(`Message: ${moreInfo.message}`);
  1951. if (moreInfo.stack) {
  1952. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  1953. } else {
  1954. if (moreInfo.filename) {
  1955. moreInfoText.push(`File: ${moreInfo.filename}`);
  1956. }
  1957. if (moreInfo.lineNumber) {
  1958. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  1959. }
  1960. }
  1961. }
  1962. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  1963. this.fallback();
  1964. },
  1965. progress(level) {
  1966. if (this.downloadComplete) {
  1967. return;
  1968. }
  1969. const percent = Math.round(level * 100);
  1970. if (percent <= this.loadingBar.percent) {
  1971. return;
  1972. }
  1973. this.loadingBar.percent = percent;
  1974. const disableAutoFetch = this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch");
  1975. if (!disableAutoFetch || isNaN(percent)) {
  1976. return;
  1977. }
  1978. if (this.disableAutoFetchLoadingBarTimeout) {
  1979. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1980. this.disableAutoFetchLoadingBarTimeout = null;
  1981. }
  1982. this.loadingBar.show();
  1983. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  1984. this.loadingBar.hide();
  1985. this.disableAutoFetchLoadingBarTimeout = null;
  1986. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1987. },
  1988. load(pdfDocument) {
  1989. this.pdfDocument = pdfDocument;
  1990. pdfDocument.getDownloadInfo().then(({
  1991. length
  1992. }) => {
  1993. this._contentLength = length;
  1994. this.downloadComplete = true;
  1995. this.loadingBar.hide();
  1996. firstPagePromise.then(() => {
  1997. this.eventBus.dispatch("documentloaded", {
  1998. source: this
  1999. });
  2000. });
  2001. });
  2002. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  2003. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  2004. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  2005. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  2006. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  2007. let baseDocumentUrl;
  2008. baseDocumentUrl = null;
  2009. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  2010. this.pdfDocumentProperties.setDocument(pdfDocument);
  2011. const pdfViewer = this.pdfViewer;
  2012. pdfViewer.setDocument(pdfDocument);
  2013. const {
  2014. firstPagePromise,
  2015. onePageRendered,
  2016. pagesPromise
  2017. } = pdfViewer;
  2018. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  2019. pdfThumbnailViewer.setDocument(pdfDocument);
  2020. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  2021. page: null,
  2022. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  2023. scrollLeft: "0",
  2024. scrollTop: "0",
  2025. rotation: null,
  2026. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  2027. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  2028. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  2029. }).catch(() => {
  2030. return Object.create(null);
  2031. });
  2032. firstPagePromise.then(pdfPage => {
  2033. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  2034. this._initializeAnnotationStorageCallbacks(pdfDocument);
  2035. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  2036. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  2037. this._initializePdfHistory({
  2038. fingerprint: pdfDocument.fingerprints[0],
  2039. viewOnLoad,
  2040. initialDest: openAction?.dest
  2041. });
  2042. const initialBookmark = this.initialBookmark;
  2043. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  2044. let hash = zoom ? `zoom=${zoom}` : null;
  2045. let rotation = null;
  2046. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  2047. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  2048. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  2049. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  2050. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  2051. rotation = parseInt(stored.rotation, 10);
  2052. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2053. sidebarView = stored.sidebarView | 0;
  2054. }
  2055. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  2056. scrollMode = stored.scrollMode | 0;
  2057. }
  2058. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2059. spreadMode = stored.spreadMode | 0;
  2060. }
  2061. }
  2062. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  2063. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  2064. }
  2065. if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  2066. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
  2067. spreadMode = modes.spreadMode;
  2068. }
  2069. this.setInitialView(hash, {
  2070. rotation,
  2071. sidebarView,
  2072. scrollMode,
  2073. spreadMode
  2074. });
  2075. this.eventBus.dispatch("documentinit", {
  2076. source: this
  2077. });
  2078. if (!this.isViewerEmbedded) {
  2079. pdfViewer.focus();
  2080. }
  2081. await Promise.race([pagesPromise, new Promise(resolve => {
  2082. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  2083. })]);
  2084. if (!initialBookmark && !hash) {
  2085. return;
  2086. }
  2087. if (pdfViewer.hasEqualPageSizes) {
  2088. return;
  2089. }
  2090. this.initialBookmark = initialBookmark;
  2091. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  2092. this.setInitialView(hash);
  2093. }).catch(() => {
  2094. this.setInitialView();
  2095. }).then(function () {
  2096. pdfViewer.update();
  2097. });
  2098. });
  2099. pagesPromise.then(() => {
  2100. this._unblockDocumentLoadEvent();
  2101. this._initializeAutoPrint(pdfDocument, openActionPromise);
  2102. }, reason => {
  2103. this.l10n.get("loading_error").then(msg => {
  2104. this._documentError(msg, {
  2105. message: reason?.message
  2106. });
  2107. });
  2108. });
  2109. onePageRendered.then(data => {
  2110. this.externalServices.reportTelemetry({
  2111. type: "pageInfo",
  2112. timestamp: data.timestamp
  2113. });
  2114. pdfDocument.getOutline().then(outline => {
  2115. if (pdfDocument !== this.pdfDocument) {
  2116. return;
  2117. }
  2118. this.pdfOutlineViewer.render({
  2119. outline,
  2120. pdfDocument
  2121. });
  2122. });
  2123. pdfDocument.getAttachments().then(attachments => {
  2124. if (pdfDocument !== this.pdfDocument) {
  2125. return;
  2126. }
  2127. this.pdfAttachmentViewer.render({
  2128. attachments
  2129. });
  2130. });
  2131. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  2132. if (pdfDocument !== this.pdfDocument) {
  2133. return;
  2134. }
  2135. this.pdfLayerViewer.render({
  2136. optionalContentConfig,
  2137. pdfDocument
  2138. });
  2139. });
  2140. });
  2141. this._initializePageLabels(pdfDocument);
  2142. this._initializeMetadata(pdfDocument);
  2143. },
  2144. async _scriptingDocProperties(pdfDocument) {
  2145. if (!this.documentInfo) {
  2146. await new Promise(resolve => {
  2147. this.eventBus._on("metadataloaded", resolve, {
  2148. once: true
  2149. });
  2150. });
  2151. if (pdfDocument !== this.pdfDocument) {
  2152. return null;
  2153. }
  2154. }
  2155. if (!this._contentLength) {
  2156. await new Promise(resolve => {
  2157. this.eventBus._on("documentloaded", resolve, {
  2158. once: true
  2159. });
  2160. });
  2161. if (pdfDocument !== this.pdfDocument) {
  2162. return null;
  2163. }
  2164. }
  2165. return {
  2166. ...this.documentInfo,
  2167. baseURL: this.baseUrl,
  2168. filesize: this._contentLength,
  2169. filename: this._docFilename,
  2170. metadata: this.metadata?.getRaw(),
  2171. authors: this.metadata?.get("dc:creator"),
  2172. numPages: this.pagesCount,
  2173. URL: this.url
  2174. };
  2175. },
  2176. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  2177. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  2178. if (pdfDocument !== this.pdfDocument) {
  2179. return;
  2180. }
  2181. let triggerAutoPrint = false;
  2182. if (openAction?.action === "Print") {
  2183. triggerAutoPrint = true;
  2184. }
  2185. if (javaScript) {
  2186. javaScript.some(js => {
  2187. if (!js) {
  2188. return false;
  2189. }
  2190. console.warn("Warning: JavaScript support is not enabled");
  2191. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  2192. return true;
  2193. });
  2194. if (!triggerAutoPrint) {
  2195. for (const js of javaScript) {
  2196. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  2197. triggerAutoPrint = true;
  2198. break;
  2199. }
  2200. }
  2201. }
  2202. }
  2203. if (triggerAutoPrint) {
  2204. this.triggerPrinting();
  2205. }
  2206. },
  2207. async _initializeMetadata(pdfDocument) {
  2208. const {
  2209. info,
  2210. metadata,
  2211. contentDispositionFilename,
  2212. contentLength
  2213. } = await pdfDocument.getMetadata();
  2214. if (pdfDocument !== this.pdfDocument) {
  2215. return;
  2216. }
  2217. this.documentInfo = info;
  2218. this.metadata = metadata;
  2219. this._contentDispositionFilename ??= contentDispositionFilename;
  2220. this._contentLength ??= contentLength;
  2221. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`);
  2222. let pdfTitle = info.Title;
  2223. const metadataTitle = metadata?.get("dc:title");
  2224. if (metadataTitle) {
  2225. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  2226. pdfTitle = metadataTitle;
  2227. }
  2228. }
  2229. if (pdfTitle) {
  2230. this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
  2231. } else if (this._contentDispositionFilename) {
  2232. this.setTitle(this._contentDispositionFilename);
  2233. }
  2234. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  2235. if (pdfDocument.loadingParams.enableXfa) {
  2236. console.warn("Warning: XFA Foreground documents are not supported");
  2237. } else {
  2238. console.warn("Warning: XFA support is not enabled");
  2239. }
  2240. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  2241. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
  2242. console.warn("Warning: Interactive form support is not enabled");
  2243. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  2244. }
  2245. if (info.IsSignaturesPresent) {
  2246. console.warn("Warning: Digital signatures validation is not supported");
  2247. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  2248. }
  2249. let versionId = "other";
  2250. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  2251. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  2252. }
  2253. let generatorId = "other";
  2254. if (info.Producer) {
  2255. const producer = info.Producer.toLowerCase();
  2256. KNOWN_GENERATORS.some(function (generator) {
  2257. if (!producer.includes(generator)) {
  2258. return false;
  2259. }
  2260. generatorId = generator.replace(/[ .-]/g, "_");
  2261. return true;
  2262. });
  2263. }
  2264. let formType = null;
  2265. if (info.IsXFAPresent) {
  2266. formType = "xfa";
  2267. } else if (info.IsAcroFormPresent) {
  2268. formType = "acroform";
  2269. }
  2270. this.externalServices.reportTelemetry({
  2271. type: "documentInfo",
  2272. version: versionId,
  2273. generator: generatorId,
  2274. formType
  2275. });
  2276. this.eventBus.dispatch("metadataloaded", {
  2277. source: this
  2278. });
  2279. },
  2280. async _initializePageLabels(pdfDocument) {
  2281. const labels = await pdfDocument.getPageLabels();
  2282. if (pdfDocument !== this.pdfDocument) {
  2283. return;
  2284. }
  2285. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  2286. return;
  2287. }
  2288. const numLabels = labels.length;
  2289. let standardLabels = 0,
  2290. emptyLabels = 0;
  2291. for (let i = 0; i < numLabels; i++) {
  2292. const label = labels[i];
  2293. if (label === (i + 1).toString()) {
  2294. standardLabels++;
  2295. } else if (label === "") {
  2296. emptyLabels++;
  2297. } else {
  2298. break;
  2299. }
  2300. }
  2301. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  2302. return;
  2303. }
  2304. const {
  2305. pdfViewer,
  2306. pdfThumbnailViewer,
  2307. toolbar
  2308. } = this;
  2309. pdfViewer.setPageLabels(labels);
  2310. pdfThumbnailViewer.setPageLabels(labels);
  2311. toolbar.setPagesCount(numLabels, true);
  2312. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2313. },
  2314. _initializePdfHistory({
  2315. fingerprint,
  2316. viewOnLoad,
  2317. initialDest = null
  2318. }) {
  2319. if (!this.pdfHistory) {
  2320. return;
  2321. }
  2322. this.pdfHistory.initialize({
  2323. fingerprint,
  2324. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  2325. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  2326. });
  2327. if (this.pdfHistory.initialBookmark) {
  2328. this.initialBookmark = this.pdfHistory.initialBookmark;
  2329. this.initialRotation = this.pdfHistory.initialRotation;
  2330. }
  2331. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  2332. this.initialBookmark = JSON.stringify(initialDest);
  2333. this.pdfHistory.push({
  2334. explicitDest: initialDest,
  2335. pageNumber: null
  2336. });
  2337. }
  2338. },
  2339. _initializeAnnotationStorageCallbacks(pdfDocument) {
  2340. if (pdfDocument !== this.pdfDocument) {
  2341. return;
  2342. }
  2343. const {
  2344. annotationStorage
  2345. } = pdfDocument;
  2346. annotationStorage.onSetModified = () => {
  2347. window.addEventListener("beforeunload", beforeUnload);
  2348. this._annotationStorageModified = true;
  2349. };
  2350. annotationStorage.onResetModified = () => {
  2351. window.removeEventListener("beforeunload", beforeUnload);
  2352. delete this._annotationStorageModified;
  2353. };
  2354. annotationStorage.onAnnotationEditor = typeStr => {
  2355. this._hasAnnotationEditors = !!typeStr;
  2356. this.setTitle();
  2357. if (typeStr) {
  2358. this.externalServices.reportTelemetry({
  2359. type: "editing",
  2360. data: {
  2361. type: typeStr
  2362. }
  2363. });
  2364. }
  2365. };
  2366. },
  2367. setInitialView(storedHash, {
  2368. rotation,
  2369. sidebarView,
  2370. scrollMode,
  2371. spreadMode
  2372. } = {}) {
  2373. const setRotation = angle => {
  2374. if ((0, _ui_utils.isValidRotation)(angle)) {
  2375. this.pdfViewer.pagesRotation = angle;
  2376. }
  2377. };
  2378. const setViewerModes = (scroll, spread) => {
  2379. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  2380. this.pdfViewer.scrollMode = scroll;
  2381. }
  2382. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  2383. this.pdfViewer.spreadMode = spread;
  2384. }
  2385. };
  2386. this.isInitialViewSet = true;
  2387. this.pdfSidebar.setInitialView(sidebarView);
  2388. setViewerModes(scrollMode, spreadMode);
  2389. if (this.initialBookmark) {
  2390. setRotation(this.initialRotation);
  2391. delete this.initialRotation;
  2392. this.pdfLinkService.setHash(this.initialBookmark);
  2393. this.initialBookmark = null;
  2394. } else if (storedHash) {
  2395. setRotation(rotation);
  2396. this.pdfLinkService.setHash(storedHash);
  2397. }
  2398. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  2399. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  2400. if (!this.pdfViewer.currentScaleValue) {
  2401. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2402. }
  2403. },
  2404. _cleanup() {
  2405. if (!this.pdfDocument) {
  2406. return;
  2407. }
  2408. this.pdfViewer.cleanup();
  2409. this.pdfThumbnailViewer.cleanup();
  2410. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  2411. },
  2412. forceRendering() {
  2413. this.pdfRenderingQueue.printing = !!this.printService;
  2414. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS;
  2415. this.pdfRenderingQueue.renderHighestPriority();
  2416. },
  2417. beforePrint() {
  2418. this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => {
  2419. return this.pdfDocument?.annotationStorage.print;
  2420. });
  2421. if (this.printService) {
  2422. return;
  2423. }
  2424. if (!this.supportsPrinting) {
  2425. this.l10n.get("printing_not_supported").then(msg => {
  2426. this._otherError(msg);
  2427. });
  2428. return;
  2429. }
  2430. if (!this.pdfViewer.pageViewsReady) {
  2431. this.l10n.get("printing_not_ready").then(msg => {
  2432. window.alert(msg);
  2433. });
  2434. return;
  2435. }
  2436. const pagesOverview = this.pdfViewer.getPagesOverview();
  2437. const printContainer = this.appConfig.printContainer;
  2438. const printResolution = _app_options.AppOptions.get("printResolution");
  2439. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  2440. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n);
  2441. this.printService = printService;
  2442. this.forceRendering();
  2443. this.setTitle();
  2444. printService.layout();
  2445. this.externalServices.reportTelemetry({
  2446. type: "print"
  2447. });
  2448. if (this._hasAnnotationEditors) {
  2449. this.externalServices.reportTelemetry({
  2450. type: "editing",
  2451. data: {
  2452. type: "print"
  2453. }
  2454. });
  2455. }
  2456. },
  2457. afterPrint() {
  2458. if (this._printAnnotationStoragePromise) {
  2459. this._printAnnotationStoragePromise.then(() => {
  2460. this.pdfScriptingManager.dispatchDidPrint();
  2461. });
  2462. this._printAnnotationStoragePromise = null;
  2463. }
  2464. if (this.printService) {
  2465. this.printService.destroy();
  2466. this.printService = null;
  2467. this.pdfDocument?.annotationStorage.resetModified();
  2468. }
  2469. this.forceRendering();
  2470. this.setTitle();
  2471. },
  2472. rotatePages(delta) {
  2473. this.pdfViewer.pagesRotation += delta;
  2474. },
  2475. requestPresentationMode() {
  2476. this.pdfPresentationMode?.request();
  2477. },
  2478. triggerPrinting() {
  2479. if (!this.supportsPrinting) {
  2480. return;
  2481. }
  2482. window.print();
  2483. },
  2484. bindEvents() {
  2485. const {
  2486. eventBus,
  2487. _boundEvents
  2488. } = this;
  2489. _boundEvents.beforePrint = this.beforePrint.bind(this);
  2490. _boundEvents.afterPrint = this.afterPrint.bind(this);
  2491. eventBus._on("resize", webViewerResize);
  2492. eventBus._on("hashchange", webViewerHashchange);
  2493. eventBus._on("beforeprint", _boundEvents.beforePrint);
  2494. eventBus._on("afterprint", _boundEvents.afterPrint);
  2495. eventBus._on("pagerendered", webViewerPageRendered);
  2496. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  2497. eventBus._on("pagechanging", webViewerPageChanging);
  2498. eventBus._on("scalechanging", webViewerScaleChanging);
  2499. eventBus._on("rotationchanging", webViewerRotationChanging);
  2500. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  2501. eventBus._on("pagemode", webViewerPageMode);
  2502. eventBus._on("namedaction", webViewerNamedAction);
  2503. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  2504. eventBus._on("presentationmode", webViewerPresentationMode);
  2505. eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
  2506. eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
  2507. eventBus._on("print", webViewerPrint);
  2508. eventBus._on("download", webViewerDownload);
  2509. eventBus._on("firstpage", webViewerFirstPage);
  2510. eventBus._on("lastpage", webViewerLastPage);
  2511. eventBus._on("nextpage", webViewerNextPage);
  2512. eventBus._on("previouspage", webViewerPreviousPage);
  2513. eventBus._on("zoomin", webViewerZoomIn);
  2514. eventBus._on("zoomout", webViewerZoomOut);
  2515. eventBus._on("zoomreset", webViewerZoomReset);
  2516. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  2517. eventBus._on("scalechanged", webViewerScaleChanged);
  2518. eventBus._on("rotatecw", webViewerRotateCw);
  2519. eventBus._on("rotateccw", webViewerRotateCcw);
  2520. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  2521. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  2522. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  2523. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  2524. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  2525. eventBus._on("documentproperties", webViewerDocumentProperties);
  2526. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  2527. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2528. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  2529. if (_app_options.AppOptions.get("pdfBug")) {
  2530. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  2531. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2532. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2533. }
  2534. eventBus._on("fileinputchange", webViewerFileInputChange);
  2535. eventBus._on("openfile", webViewerOpenFile);
  2536. },
  2537. bindWindowEvents() {
  2538. const {
  2539. eventBus,
  2540. _boundEvents
  2541. } = this;
  2542. function addWindowResolutionChange(evt = null) {
  2543. if (evt) {
  2544. webViewerResolutionChange(evt);
  2545. }
  2546. const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
  2547. mediaQueryList.addEventListener("change", addWindowResolutionChange, {
  2548. once: true
  2549. });
  2550. _boundEvents.removeWindowResolutionChange ||= function () {
  2551. mediaQueryList.removeEventListener("change", addWindowResolutionChange);
  2552. _boundEvents.removeWindowResolutionChange = null;
  2553. };
  2554. }
  2555. addWindowResolutionChange();
  2556. _boundEvents.windowResize = () => {
  2557. eventBus.dispatch("resize", {
  2558. source: window
  2559. });
  2560. };
  2561. _boundEvents.windowHashChange = () => {
  2562. eventBus.dispatch("hashchange", {
  2563. source: window,
  2564. hash: document.location.hash.substring(1)
  2565. });
  2566. };
  2567. _boundEvents.windowBeforePrint = () => {
  2568. eventBus.dispatch("beforeprint", {
  2569. source: window
  2570. });
  2571. };
  2572. _boundEvents.windowAfterPrint = () => {
  2573. eventBus.dispatch("afterprint", {
  2574. source: window
  2575. });
  2576. };
  2577. _boundEvents.windowUpdateFromSandbox = event => {
  2578. eventBus.dispatch("updatefromsandbox", {
  2579. source: window,
  2580. detail: event.detail
  2581. });
  2582. };
  2583. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  2584. window.addEventListener("wheel", webViewerWheel, {
  2585. passive: false
  2586. });
  2587. window.addEventListener("touchstart", webViewerTouchStart, {
  2588. passive: false
  2589. });
  2590. window.addEventListener("click", webViewerClick);
  2591. window.addEventListener("keydown", webViewerKeyDown);
  2592. window.addEventListener("resize", _boundEvents.windowResize);
  2593. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  2594. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2595. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  2596. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2597. },
  2598. unbindEvents() {
  2599. const {
  2600. eventBus,
  2601. _boundEvents
  2602. } = this;
  2603. eventBus._off("resize", webViewerResize);
  2604. eventBus._off("hashchange", webViewerHashchange);
  2605. eventBus._off("beforeprint", _boundEvents.beforePrint);
  2606. eventBus._off("afterprint", _boundEvents.afterPrint);
  2607. eventBus._off("pagerendered", webViewerPageRendered);
  2608. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  2609. eventBus._off("pagechanging", webViewerPageChanging);
  2610. eventBus._off("scalechanging", webViewerScaleChanging);
  2611. eventBus._off("rotationchanging", webViewerRotationChanging);
  2612. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  2613. eventBus._off("pagemode", webViewerPageMode);
  2614. eventBus._off("namedaction", webViewerNamedAction);
  2615. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  2616. eventBus._off("presentationmode", webViewerPresentationMode);
  2617. eventBus._off("print", webViewerPrint);
  2618. eventBus._off("download", webViewerDownload);
  2619. eventBus._off("firstpage", webViewerFirstPage);
  2620. eventBus._off("lastpage", webViewerLastPage);
  2621. eventBus._off("nextpage", webViewerNextPage);
  2622. eventBus._off("previouspage", webViewerPreviousPage);
  2623. eventBus._off("zoomin", webViewerZoomIn);
  2624. eventBus._off("zoomout", webViewerZoomOut);
  2625. eventBus._off("zoomreset", webViewerZoomReset);
  2626. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  2627. eventBus._off("scalechanged", webViewerScaleChanged);
  2628. eventBus._off("rotatecw", webViewerRotateCw);
  2629. eventBus._off("rotateccw", webViewerRotateCcw);
  2630. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  2631. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  2632. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  2633. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  2634. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  2635. eventBus._off("documentproperties", webViewerDocumentProperties);
  2636. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  2637. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  2638. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  2639. if (_boundEvents.reportPageStatsPDFBug) {
  2640. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  2641. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  2642. _boundEvents.reportPageStatsPDFBug = null;
  2643. }
  2644. eventBus._off("fileinputchange", webViewerFileInputChange);
  2645. eventBus._off("openfile", webViewerOpenFile);
  2646. _boundEvents.beforePrint = null;
  2647. _boundEvents.afterPrint = null;
  2648. },
  2649. unbindWindowEvents() {
  2650. const {
  2651. _boundEvents
  2652. } = this;
  2653. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  2654. window.removeEventListener("wheel", webViewerWheel, {
  2655. passive: false
  2656. });
  2657. window.removeEventListener("touchstart", webViewerTouchStart, {
  2658. passive: false
  2659. });
  2660. window.removeEventListener("click", webViewerClick);
  2661. window.removeEventListener("keydown", webViewerKeyDown);
  2662. window.removeEventListener("resize", _boundEvents.windowResize);
  2663. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  2664. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  2665. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  2666. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  2667. _boundEvents.removeWindowResolutionChange?.();
  2668. _boundEvents.windowResize = null;
  2669. _boundEvents.windowHashChange = null;
  2670. _boundEvents.windowBeforePrint = null;
  2671. _boundEvents.windowAfterPrint = null;
  2672. _boundEvents.windowUpdateFromSandbox = null;
  2673. },
  2674. accumulateWheelTicks(ticks) {
  2675. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  2676. this._wheelUnusedTicks = 0;
  2677. }
  2678. this._wheelUnusedTicks += ticks;
  2679. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  2680. this._wheelUnusedTicks -= wholeTicks;
  2681. return wholeTicks;
  2682. },
  2683. _unblockDocumentLoadEvent() {
  2684. document.blockUnblockOnload?.(false);
  2685. this._unblockDocumentLoadEvent = () => {};
  2686. },
  2687. _reportDocumentStatsTelemetry() {
  2688. const {
  2689. stats
  2690. } = this.pdfDocument;
  2691. if (stats !== this._docStats) {
  2692. this._docStats = stats;
  2693. this.externalServices.reportTelemetry({
  2694. type: "documentStats",
  2695. stats
  2696. });
  2697. }
  2698. },
  2699. get scriptingReady() {
  2700. return this.pdfScriptingManager.ready;
  2701. }
  2702. };
  2703. exports.PDFViewerApplication = PDFViewerApplication;
  2704. {
  2705. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  2706. var validateFileURL = function (file) {
  2707. if (!file) {
  2708. return;
  2709. }
  2710. try {
  2711. const viewerOrigin = new URL(window.location.href).origin || "null";
  2712. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  2713. return;
  2714. }
  2715. // const fileOrigin = new URL(file, window.location.href).origin;
  2716. // if (fileOrigin !== viewerOrigin) {
  2717. // throw new Error("file origin does not match viewer's");
  2718. // }
  2719. } catch (ex) {
  2720. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2721. PDFViewerApplication._documentError(msg, {
  2722. message: ex?.message
  2723. });
  2724. });
  2725. throw ex;
  2726. }
  2727. };
  2728. }
  2729. async function loadFakeWorker() {
  2730. _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
  2731. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  2732. }
  2733. async function loadPDFBug(self) {
  2734. const {
  2735. debuggerScriptPath
  2736. } = self.appConfig;
  2737. const {
  2738. PDFBug
  2739. } = await import(debuggerScriptPath);
  2740. self._PDFBug = PDFBug;
  2741. }
  2742. function reportPageStatsPDFBug({
  2743. pageNumber
  2744. }) {
  2745. if (!globalThis.Stats?.enabled) {
  2746. return;
  2747. }
  2748. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2749. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  2750. }
  2751. function webViewerInitialized() {
  2752. const {
  2753. appConfig,
  2754. eventBus
  2755. } = PDFViewerApplication;
  2756. let file;
  2757. const queryString = document.location.search.substring(1);
  2758. const params = (0, _ui_utils.parseQueryString)(queryString);
  2759. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  2760. validateFileURL(file);
  2761. const fileInput = appConfig.openFileInput;
  2762. fileInput.value = null;
  2763. fileInput.addEventListener("change", function (evt) {
  2764. const {
  2765. files
  2766. } = evt.target;
  2767. if (!files || files.length === 0) {
  2768. return;
  2769. }
  2770. eventBus.dispatch("fileinputchange", {
  2771. source: this,
  2772. fileInput: evt.target
  2773. });
  2774. });
  2775. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  2776. evt.preventDefault();
  2777. evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  2778. });
  2779. appConfig.mainContainer.addEventListener("drop", function (evt) {
  2780. evt.preventDefault();
  2781. const {
  2782. files
  2783. } = evt.dataTransfer;
  2784. if (!files || files.length === 0) {
  2785. return;
  2786. }
  2787. eventBus.dispatch("fileinputchange", {
  2788. source: this,
  2789. fileInput: evt.dataTransfer
  2790. });
  2791. });
  2792. if (!PDFViewerApplication.supportsDocumentFonts) {
  2793. _app_options.AppOptions.set("disableFontFace", true);
  2794. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  2795. console.warn(msg);
  2796. });
  2797. }
  2798. if (!PDFViewerApplication.supportsPrinting) {
  2799. appConfig.toolbar.print.classList.add("hidden");
  2800. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  2801. }
  2802. if (!PDFViewerApplication.supportsFullscreen) {
  2803. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  2804. }
  2805. if (PDFViewerApplication.supportsIntegratedFind) {
  2806. appConfig.toolbar.viewFind.classList.add("hidden");
  2807. }
  2808. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  2809. if (evt.target === this) {
  2810. eventBus.dispatch("resize", {
  2811. source: this
  2812. });
  2813. }
  2814. }, true);
  2815. try {
  2816. if (file) {
  2817. PDFViewerApplication.open(file);
  2818. } else {
  2819. PDFViewerApplication._hideViewBookmark();
  2820. }
  2821. } catch (reason) {
  2822. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  2823. PDFViewerApplication._documentError(msg, reason);
  2824. });
  2825. }
  2826. }
  2827. function webViewerPageRendered({
  2828. pageNumber,
  2829. error
  2830. }) {
  2831. if (pageNumber === PDFViewerApplication.page) {
  2832. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  2833. }
  2834. if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
  2835. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  2836. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  2837. if (pageView && thumbnailView) {
  2838. thumbnailView.setImage(pageView);
  2839. }
  2840. }
  2841. if (error) {
  2842. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  2843. PDFViewerApplication._otherError(msg, error);
  2844. });
  2845. }
  2846. PDFViewerApplication._reportDocumentStatsTelemetry();
  2847. }
  2848. function webViewerPageMode({
  2849. mode
  2850. }) {
  2851. let view;
  2852. switch (mode) {
  2853. case "thumbs":
  2854. view = _ui_utils.SidebarView.THUMBS;
  2855. break;
  2856. case "bookmarks":
  2857. case "outline":
  2858. view = _ui_utils.SidebarView.OUTLINE;
  2859. break;
  2860. case "attachments":
  2861. view = _ui_utils.SidebarView.ATTACHMENTS;
  2862. break;
  2863. case "layers":
  2864. view = _ui_utils.SidebarView.LAYERS;
  2865. break;
  2866. case "none":
  2867. view = _ui_utils.SidebarView.NONE;
  2868. break;
  2869. default:
  2870. console.error('Invalid "pagemode" hash parameter: ' + mode);
  2871. return;
  2872. }
  2873. PDFViewerApplication.pdfSidebar.switchView(view, true);
  2874. }
  2875. function webViewerNamedAction(evt) {
  2876. switch (evt.action) {
  2877. case "GoToPage":
  2878. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2879. break;
  2880. case "Find":
  2881. if (!PDFViewerApplication.supportsIntegratedFind) {
  2882. PDFViewerApplication.findBar.toggle();
  2883. }
  2884. break;
  2885. case "Print":
  2886. PDFViewerApplication.triggerPrinting();
  2887. break;
  2888. case "SaveAs":
  2889. PDFViewerApplication.downloadOrSave();
  2890. break;
  2891. }
  2892. }
  2893. function webViewerPresentationModeChanged(evt) {
  2894. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  2895. }
  2896. function webViewerSidebarViewChanged({
  2897. view
  2898. }) {
  2899. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
  2900. if (PDFViewerApplication.isInitialViewSet) {
  2901. PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
  2902. }
  2903. }
  2904. function webViewerUpdateViewarea({
  2905. location
  2906. }) {
  2907. if (PDFViewerApplication.isInitialViewSet) {
  2908. PDFViewerApplication.store?.setMultiple({
  2909. page: location.pageNumber,
  2910. zoom: location.scale,
  2911. scrollLeft: location.left,
  2912. scrollTop: location.top,
  2913. rotation: location.rotation
  2914. }).catch(() => {});
  2915. }
  2916. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  2917. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  2918. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  2919. const loading = currentPage?.renderingState !== _ui_utils.RenderingStates.FINISHED;
  2920. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  2921. }
  2922. function webViewerScrollModeChanged(evt) {
  2923. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  2924. PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
  2925. }
  2926. }
  2927. function webViewerSpreadModeChanged(evt) {
  2928. if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
  2929. PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
  2930. }
  2931. }
  2932. function webViewerResize() {
  2933. const {
  2934. pdfDocument,
  2935. pdfViewer,
  2936. pdfRenderingQueue
  2937. } = PDFViewerApplication;
  2938. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  2939. return;
  2940. }
  2941. pdfViewer.updateContainerHeightCss();
  2942. if (!pdfDocument) {
  2943. return;
  2944. }
  2945. const currentScaleValue = pdfViewer.currentScaleValue;
  2946. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  2947. pdfViewer.currentScaleValue = currentScaleValue;
  2948. }
  2949. pdfViewer.update();
  2950. }
  2951. function webViewerHashchange(evt) {
  2952. const hash = evt.hash;
  2953. if (!hash) {
  2954. return;
  2955. }
  2956. if (!PDFViewerApplication.isInitialViewSet) {
  2957. PDFViewerApplication.initialBookmark = hash;
  2958. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  2959. PDFViewerApplication.pdfLinkService.setHash(hash);
  2960. }
  2961. }
  2962. {
  2963. var webViewerFileInputChange = function (evt) {
  2964. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2965. return;
  2966. }
  2967. const file = evt.fileInput.files[0];
  2968. let url = URL.createObjectURL(file);
  2969. if (file.name) {
  2970. url = {
  2971. url,
  2972. originalUrl: file.name
  2973. };
  2974. }
  2975. PDFViewerApplication.open(url);
  2976. };
  2977. var webViewerOpenFile = function (evt) {
  2978. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  2979. fileInput.click();
  2980. };
  2981. }
  2982. function webViewerPresentationMode() {
  2983. PDFViewerApplication.requestPresentationMode();
  2984. }
  2985. function webViewerSwitchAnnotationEditorMode(evt) {
  2986. PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
  2987. }
  2988. function webViewerSwitchAnnotationEditorParams(evt) {
  2989. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  2990. }
  2991. function webViewerPrint() {
  2992. PDFViewerApplication.triggerPrinting();
  2993. }
  2994. function webViewerDownload() {
  2995. PDFViewerApplication.downloadOrSave();
  2996. }
  2997. function webViewerFirstPage() {
  2998. if (PDFViewerApplication.pdfDocument) {
  2999. PDFViewerApplication.page = 1;
  3000. }
  3001. }
  3002. function webViewerLastPage() {
  3003. if (PDFViewerApplication.pdfDocument) {
  3004. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3005. }
  3006. }
  3007. function webViewerNextPage() {
  3008. PDFViewerApplication.pdfViewer.nextPage();
  3009. }
  3010. function webViewerPreviousPage() {
  3011. PDFViewerApplication.pdfViewer.previousPage();
  3012. }
  3013. function webViewerZoomIn() {
  3014. PDFViewerApplication.zoomIn();
  3015. }
  3016. function webViewerZoomOut() {
  3017. PDFViewerApplication.zoomOut();
  3018. }
  3019. function webViewerZoomReset() {
  3020. PDFViewerApplication.zoomReset();
  3021. }
  3022. function webViewerPageNumberChanged(evt) {
  3023. const pdfViewer = PDFViewerApplication.pdfViewer;
  3024. if (evt.value !== "") {
  3025. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  3026. }
  3027. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  3028. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  3029. }
  3030. }
  3031. function webViewerScaleChanged(evt) {
  3032. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  3033. }
  3034. function webViewerRotateCw() {
  3035. PDFViewerApplication.rotatePages(90);
  3036. }
  3037. function webViewerRotateCcw() {
  3038. PDFViewerApplication.rotatePages(-90);
  3039. }
  3040. function webViewerOptionalContentConfig(evt) {
  3041. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  3042. }
  3043. function webViewerSwitchScrollMode(evt) {
  3044. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  3045. }
  3046. function webViewerSwitchSpreadMode(evt) {
  3047. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  3048. }
  3049. function webViewerDocumentProperties() {
  3050. PDFViewerApplication.pdfDocumentProperties.open();
  3051. }
  3052. function webViewerFindFromUrlHash(evt) {
  3053. PDFViewerApplication.eventBus.dispatch("find", {
  3054. source: evt.source,
  3055. type: "",
  3056. query: evt.query,
  3057. phraseSearch: evt.phraseSearch,
  3058. caseSensitive: false,
  3059. entireWord: false,
  3060. highlightAll: true,
  3061. findPrevious: false,
  3062. matchDiacritics: true
  3063. });
  3064. }
  3065. function webViewerUpdateFindMatchesCount({
  3066. matchesCount
  3067. }) {
  3068. if (PDFViewerApplication.supportsIntegratedFind) {
  3069. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  3070. } else {
  3071. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  3072. }
  3073. }
  3074. function webViewerUpdateFindControlState({
  3075. state,
  3076. previous,
  3077. matchesCount,
  3078. rawQuery
  3079. }) {
  3080. if (PDFViewerApplication.supportsIntegratedFind) {
  3081. PDFViewerApplication.externalServices.updateFindControlState({
  3082. result: state,
  3083. findPrevious: previous,
  3084. matchesCount,
  3085. rawQuery
  3086. });
  3087. } else {
  3088. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  3089. }
  3090. }
  3091. function webViewerScaleChanging(evt) {
  3092. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  3093. PDFViewerApplication.pdfViewer.update();
  3094. }
  3095. function webViewerRotationChanging(evt) {
  3096. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  3097. PDFViewerApplication.forceRendering();
  3098. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  3099. }
  3100. function webViewerPageChanging({
  3101. pageNumber,
  3102. pageLabel
  3103. }) {
  3104. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  3105. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  3106. if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
  3107. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  3108. }
  3109. }
  3110. function webViewerResolutionChange(evt) {
  3111. PDFViewerApplication.pdfViewer.refresh();
  3112. }
  3113. function webViewerVisibilityChange(evt) {
  3114. if (document.visibilityState === "visible") {
  3115. setZoomDisabledTimeout();
  3116. }
  3117. }
  3118. let zoomDisabledTimeout = null;
  3119. function setZoomDisabledTimeout() {
  3120. if (zoomDisabledTimeout) {
  3121. clearTimeout(zoomDisabledTimeout);
  3122. }
  3123. zoomDisabledTimeout = setTimeout(function () {
  3124. zoomDisabledTimeout = null;
  3125. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  3126. }
  3127. function webViewerWheel(evt) {
  3128. const {
  3129. pdfViewer,
  3130. supportedMouseWheelZoomModifierKeys
  3131. } = PDFViewerApplication;
  3132. if (pdfViewer.isInPresentationMode) {
  3133. return;
  3134. }
  3135. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  3136. evt.preventDefault();
  3137. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  3138. return;
  3139. }
  3140. const deltaMode = evt.deltaMode;
  3141. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  3142. const previousScale = pdfViewer.currentScale;
  3143. let ticks = 0;
  3144. if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  3145. if (Math.abs(delta) >= 1) {
  3146. ticks = Math.sign(delta);
  3147. } else {
  3148. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  3149. }
  3150. } else {
  3151. const PIXELS_PER_LINE_SCALE = 30;
  3152. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  3153. }
  3154. if (ticks < 0) {
  3155. PDFViewerApplication.zoomOut(-ticks);
  3156. } else if (ticks > 0) {
  3157. PDFViewerApplication.zoomIn(ticks);
  3158. }
  3159. const currentScale = pdfViewer.currentScale;
  3160. if (previousScale !== currentScale) {
  3161. const scaleCorrectionFactor = currentScale / previousScale - 1;
  3162. const rect = pdfViewer.container.getBoundingClientRect();
  3163. const dx = evt.clientX - rect.left;
  3164. const dy = evt.clientY - rect.top;
  3165. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  3166. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  3167. }
  3168. } else {
  3169. setZoomDisabledTimeout();
  3170. }
  3171. }
  3172. function webViewerTouchStart(evt) {
  3173. if (evt.touches.length > 1) {
  3174. evt.preventDefault();
  3175. }
  3176. }
  3177. function webViewerClick(evt) {
  3178. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  3179. return;
  3180. }
  3181. const appConfig = PDFViewerApplication.appConfig;
  3182. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  3183. PDFViewerApplication.secondaryToolbar.close();
  3184. }
  3185. }
  3186. function webViewerKeyDown(evt) {
  3187. if (PDFViewerApplication.overlayManager.active) {
  3188. return;
  3189. }
  3190. const {
  3191. eventBus,
  3192. pdfViewer
  3193. } = PDFViewerApplication;
  3194. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  3195. let handled = false,
  3196. ensureViewerFocused = false;
  3197. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  3198. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  3199. switch (evt.keyCode) {
  3200. case 70:
  3201. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  3202. PDFViewerApplication.findBar.open();
  3203. handled = true;
  3204. }
  3205. break;
  3206. case 71:
  3207. if (!PDFViewerApplication.supportsIntegratedFind) {
  3208. const {
  3209. state
  3210. } = PDFViewerApplication.findController;
  3211. if (state) {
  3212. const eventState = Object.assign(Object.create(null), state, {
  3213. source: window,
  3214. type: "again",
  3215. findPrevious: cmd === 5 || cmd === 12
  3216. });
  3217. eventBus.dispatch("find", eventState);
  3218. }
  3219. handled = true;
  3220. }
  3221. break;
  3222. case 61:
  3223. case 107:
  3224. case 187:
  3225. case 171:
  3226. if (!isViewerInPresentationMode) {
  3227. PDFViewerApplication.zoomIn();
  3228. }
  3229. handled = true;
  3230. break;
  3231. case 173:
  3232. case 109:
  3233. case 189:
  3234. if (!isViewerInPresentationMode) {
  3235. PDFViewerApplication.zoomOut();
  3236. }
  3237. handled = true;
  3238. break;
  3239. case 48:
  3240. case 96:
  3241. if (!isViewerInPresentationMode) {
  3242. setTimeout(function () {
  3243. PDFViewerApplication.zoomReset();
  3244. });
  3245. handled = false;
  3246. }
  3247. break;
  3248. case 38:
  3249. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3250. PDFViewerApplication.page = 1;
  3251. handled = true;
  3252. ensureViewerFocused = true;
  3253. }
  3254. break;
  3255. case 40:
  3256. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3257. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3258. handled = true;
  3259. ensureViewerFocused = true;
  3260. }
  3261. break;
  3262. }
  3263. }
  3264. if (cmd === 1 || cmd === 8) {
  3265. switch (evt.keyCode) {
  3266. case 83:
  3267. eventBus.dispatch("download", {
  3268. source: window
  3269. });
  3270. handled = true;
  3271. break;
  3272. case 79:
  3273. {
  3274. eventBus.dispatch("openfile", {
  3275. source: window
  3276. });
  3277. handled = true;
  3278. }
  3279. break;
  3280. }
  3281. }
  3282. if (cmd === 3 || cmd === 10) {
  3283. switch (evt.keyCode) {
  3284. case 80:
  3285. PDFViewerApplication.requestPresentationMode();
  3286. handled = true;
  3287. PDFViewerApplication.externalServices.reportTelemetry({
  3288. type: "buttons",
  3289. data: {
  3290. id: "presentationModeKeyboard"
  3291. }
  3292. });
  3293. break;
  3294. case 71:
  3295. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  3296. handled = true;
  3297. break;
  3298. }
  3299. }
  3300. if (handled) {
  3301. if (ensureViewerFocused && !isViewerInPresentationMode) {
  3302. pdfViewer.focus();
  3303. }
  3304. evt.preventDefault();
  3305. return;
  3306. }
  3307. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  3308. const curElementTagName = curElement?.tagName.toUpperCase();
  3309. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  3310. if (evt.keyCode !== 27) {
  3311. return;
  3312. }
  3313. }
  3314. if (cmd === 0) {
  3315. let turnPage = 0,
  3316. turnOnlyIfPageFit = false;
  3317. switch (evt.keyCode) {
  3318. case 38:
  3319. case 33:
  3320. if (pdfViewer.isVerticalScrollbarEnabled) {
  3321. turnOnlyIfPageFit = true;
  3322. }
  3323. turnPage = -1;
  3324. break;
  3325. case 8:
  3326. if (!isViewerInPresentationMode) {
  3327. turnOnlyIfPageFit = true;
  3328. }
  3329. turnPage = -1;
  3330. break;
  3331. case 37:
  3332. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3333. turnOnlyIfPageFit = true;
  3334. }
  3335. case 75:
  3336. case 80:
  3337. turnPage = -1;
  3338. break;
  3339. case 27:
  3340. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  3341. PDFViewerApplication.secondaryToolbar.close();
  3342. handled = true;
  3343. }
  3344. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  3345. PDFViewerApplication.findBar.close();
  3346. handled = true;
  3347. }
  3348. break;
  3349. case 40:
  3350. case 34:
  3351. if (pdfViewer.isVerticalScrollbarEnabled) {
  3352. turnOnlyIfPageFit = true;
  3353. }
  3354. turnPage = 1;
  3355. break;
  3356. case 13:
  3357. case 32:
  3358. if (!isViewerInPresentationMode) {
  3359. turnOnlyIfPageFit = true;
  3360. }
  3361. turnPage = 1;
  3362. break;
  3363. case 39:
  3364. if (pdfViewer.isHorizontalScrollbarEnabled) {
  3365. turnOnlyIfPageFit = true;
  3366. }
  3367. case 74:
  3368. case 78:
  3369. turnPage = 1;
  3370. break;
  3371. case 36:
  3372. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  3373. PDFViewerApplication.page = 1;
  3374. handled = true;
  3375. ensureViewerFocused = true;
  3376. }
  3377. break;
  3378. case 35:
  3379. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  3380. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  3381. handled = true;
  3382. ensureViewerFocused = true;
  3383. }
  3384. break;
  3385. case 83:
  3386. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  3387. break;
  3388. case 72:
  3389. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  3390. break;
  3391. case 82:
  3392. PDFViewerApplication.rotatePages(90);
  3393. break;
  3394. case 115:
  3395. PDFViewerApplication.pdfSidebar.toggle();
  3396. break;
  3397. }
  3398. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  3399. if (turnPage > 0) {
  3400. pdfViewer.nextPage();
  3401. } else {
  3402. pdfViewer.previousPage();
  3403. }
  3404. handled = true;
  3405. }
  3406. }
  3407. if (cmd === 4) {
  3408. switch (evt.keyCode) {
  3409. case 13:
  3410. case 32:
  3411. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  3412. break;
  3413. }
  3414. pdfViewer.previousPage();
  3415. handled = true;
  3416. break;
  3417. case 82:
  3418. PDFViewerApplication.rotatePages(-90);
  3419. break;
  3420. }
  3421. }
  3422. if (!handled && !isViewerInPresentationMode) {
  3423. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  3424. ensureViewerFocused = true;
  3425. }
  3426. }
  3427. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  3428. pdfViewer.focus();
  3429. }
  3430. if (handled) {
  3431. evt.preventDefault();
  3432. }
  3433. }
  3434. function beforeUnload(evt) {
  3435. evt.preventDefault();
  3436. evt.returnValue = "";
  3437. return false;
  3438. }
  3439. function webViewerAnnotationEditorStatesChanged(data) {
  3440. PDFViewerApplication.externalServices.updateEditorStates(data);
  3441. }
  3442. const PDFPrintServiceFactory = {
  3443. instance: {
  3444. supportsPrinting: false,
  3445. createPrintService() {
  3446. throw new Error("Not implemented: createPrintService");
  3447. }
  3448. }
  3449. };
  3450. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  3451. /***/ }),
  3452. /* 5 */
  3453. /***/ ((module) => {
  3454. let pdfjsLib;
  3455. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3456. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3457. } else {
  3458. pdfjsLib = require("../build/pdf.js");
  3459. }
  3460. module.exports = pdfjsLib;
  3461. /***/ }),
  3462. /* 6 */
  3463. /***/ ((__unused_webpack_module, exports) => {
  3464. Object.defineProperty(exports, "__esModule", ({
  3465. value: true
  3466. }));
  3467. exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
  3468. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3469. const WaitOnType = {
  3470. EVENT: "event",
  3471. TIMEOUT: "timeout"
  3472. };
  3473. exports.WaitOnType = WaitOnType;
  3474. function waitOnEventOrTimeout({
  3475. target,
  3476. name,
  3477. delay = 0
  3478. }) {
  3479. return new Promise(function (resolve, reject) {
  3480. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  3481. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3482. }
  3483. function handler(type) {
  3484. if (target instanceof EventBus) {
  3485. target._off(name, eventHandler);
  3486. } else {
  3487. target.removeEventListener(name, eventHandler);
  3488. }
  3489. if (timeout) {
  3490. clearTimeout(timeout);
  3491. }
  3492. resolve(type);
  3493. }
  3494. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3495. if (target instanceof EventBus) {
  3496. target._on(name, eventHandler);
  3497. } else {
  3498. target.addEventListener(name, eventHandler);
  3499. }
  3500. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3501. const timeout = setTimeout(timeoutHandler, delay);
  3502. });
  3503. }
  3504. class EventBus {
  3505. constructor() {
  3506. this._listeners = Object.create(null);
  3507. }
  3508. on(eventName, listener, options = null) {
  3509. this._on(eventName, listener, {
  3510. external: true,
  3511. once: options?.once
  3512. });
  3513. }
  3514. off(eventName, listener, options = null) {
  3515. this._off(eventName, listener, {
  3516. external: true,
  3517. once: options?.once
  3518. });
  3519. }
  3520. dispatch(eventName, data) {
  3521. const eventListeners = this._listeners[eventName];
  3522. if (!eventListeners || eventListeners.length === 0) {
  3523. return;
  3524. }
  3525. let externalListeners;
  3526. for (const {
  3527. listener,
  3528. external,
  3529. once
  3530. } of eventListeners.slice(0)) {
  3531. if (once) {
  3532. this._off(eventName, listener);
  3533. }
  3534. if (external) {
  3535. (externalListeners ||= []).push(listener);
  3536. continue;
  3537. }
  3538. listener(data);
  3539. }
  3540. if (externalListeners) {
  3541. for (const listener of externalListeners) {
  3542. listener(data);
  3543. }
  3544. externalListeners = null;
  3545. }
  3546. }
  3547. _on(eventName, listener, options = null) {
  3548. const eventListeners = this._listeners[eventName] ||= [];
  3549. eventListeners.push({
  3550. listener,
  3551. external: options?.external === true,
  3552. once: options?.once === true
  3553. });
  3554. }
  3555. _off(eventName, listener, options = null) {
  3556. const eventListeners = this._listeners[eventName];
  3557. if (!eventListeners) {
  3558. return;
  3559. }
  3560. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3561. if (eventListeners[i].listener === listener) {
  3562. eventListeners.splice(i, 1);
  3563. return;
  3564. }
  3565. }
  3566. }
  3567. }
  3568. exports.EventBus = EventBus;
  3569. class AutomationEventBus extends EventBus {
  3570. dispatch(eventName, data) {
  3571. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3572. }
  3573. }
  3574. exports.AutomationEventBus = AutomationEventBus;
  3575. /***/ }),
  3576. /* 7 */
  3577. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3578. Object.defineProperty(exports, "__esModule", ({
  3579. value: true
  3580. }));
  3581. exports.PDFCursorTools = exports.CursorTool = void 0;
  3582. var _pdfjsLib = __webpack_require__(5);
  3583. var _grab_to_pan = __webpack_require__(8);
  3584. var _ui_utils = __webpack_require__(1);
  3585. const CursorTool = {
  3586. SELECT: 0,
  3587. HAND: 1,
  3588. ZOOM: 2
  3589. };
  3590. exports.CursorTool = CursorTool;
  3591. class PDFCursorTools {
  3592. constructor({
  3593. container,
  3594. eventBus,
  3595. cursorToolOnLoad = CursorTool.SELECT
  3596. }) {
  3597. this.container = container;
  3598. this.eventBus = eventBus;
  3599. this.active = CursorTool.SELECT;
  3600. this.previouslyActive = null;
  3601. this.handTool = new _grab_to_pan.GrabToPan({
  3602. element: this.container
  3603. });
  3604. this.#addEventListeners();
  3605. Promise.resolve().then(() => {
  3606. this.switchTool(cursorToolOnLoad);
  3607. });
  3608. }
  3609. get activeTool() {
  3610. return this.active;
  3611. }
  3612. switchTool(tool) {
  3613. if (this.previouslyActive !== null) {
  3614. return;
  3615. }
  3616. if (tool === this.active) {
  3617. return;
  3618. }
  3619. const disableActiveTool = () => {
  3620. switch (this.active) {
  3621. case CursorTool.SELECT:
  3622. break;
  3623. case CursorTool.HAND:
  3624. this.handTool.deactivate();
  3625. break;
  3626. case CursorTool.ZOOM:
  3627. }
  3628. };
  3629. switch (tool) {
  3630. case CursorTool.SELECT:
  3631. disableActiveTool();
  3632. break;
  3633. case CursorTool.HAND:
  3634. disableActiveTool();
  3635. this.handTool.activate();
  3636. break;
  3637. case CursorTool.ZOOM:
  3638. default:
  3639. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3640. return;
  3641. }
  3642. this.active = tool;
  3643. this.#dispatchEvent();
  3644. }
  3645. #dispatchEvent() {
  3646. this.eventBus.dispatch("cursortoolchanged", {
  3647. source: this,
  3648. tool: this.active
  3649. });
  3650. }
  3651. #addEventListeners() {
  3652. this.eventBus._on("switchcursortool", evt => {
  3653. this.switchTool(evt.tool);
  3654. });
  3655. let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
  3656. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  3657. const disableActive = () => {
  3658. const previouslyActive = this.active;
  3659. this.switchTool(CursorTool.SELECT);
  3660. this.previouslyActive ??= previouslyActive;
  3661. };
  3662. const enableActive = () => {
  3663. const previouslyActive = this.previouslyActive;
  3664. if (previouslyActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) {
  3665. this.previouslyActive = null;
  3666. this.switchTool(previouslyActive);
  3667. }
  3668. };
  3669. this.eventBus._on("secondarytoolbarreset", evt => {
  3670. if (this.previouslyActive !== null) {
  3671. annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  3672. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  3673. enableActive();
  3674. }
  3675. });
  3676. this.eventBus._on("annotationeditormodechanged", ({
  3677. mode
  3678. }) => {
  3679. annotationEditorMode = mode;
  3680. if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
  3681. enableActive();
  3682. } else {
  3683. disableActive();
  3684. }
  3685. });
  3686. this.eventBus._on("presentationmodechanged", ({
  3687. state
  3688. }) => {
  3689. presentationModeState = state;
  3690. if (state === _ui_utils.PresentationModeState.NORMAL) {
  3691. enableActive();
  3692. } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
  3693. disableActive();
  3694. }
  3695. });
  3696. }
  3697. }
  3698. exports.PDFCursorTools = PDFCursorTools;
  3699. /***/ }),
  3700. /* 8 */
  3701. /***/ ((__unused_webpack_module, exports) => {
  3702. Object.defineProperty(exports, "__esModule", ({
  3703. value: true
  3704. }));
  3705. exports.GrabToPan = void 0;
  3706. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  3707. class GrabToPan {
  3708. constructor(options) {
  3709. this.element = options.element;
  3710. this.document = options.element.ownerDocument;
  3711. if (typeof options.ignoreTarget === "function") {
  3712. this.ignoreTarget = options.ignoreTarget;
  3713. }
  3714. this.onActiveChanged = options.onActiveChanged;
  3715. this.activate = this.activate.bind(this);
  3716. this.deactivate = this.deactivate.bind(this);
  3717. this.toggle = this.toggle.bind(this);
  3718. this._onMouseDown = this.#onMouseDown.bind(this);
  3719. this._onMouseMove = this.#onMouseMove.bind(this);
  3720. this._endPan = this.#endPan.bind(this);
  3721. const overlay = this.overlay = document.createElement("div");
  3722. overlay.className = "grab-to-pan-grabbing";
  3723. }
  3724. activate() {
  3725. if (!this.active) {
  3726. this.active = true;
  3727. this.element.addEventListener("mousedown", this._onMouseDown, true);
  3728. this.element.classList.add(CSS_CLASS_GRAB);
  3729. this.onActiveChanged?.(true);
  3730. }
  3731. }
  3732. deactivate() {
  3733. if (this.active) {
  3734. this.active = false;
  3735. this.element.removeEventListener("mousedown", this._onMouseDown, true);
  3736. this._endPan();
  3737. this.element.classList.remove(CSS_CLASS_GRAB);
  3738. this.onActiveChanged?.(false);
  3739. }
  3740. }
  3741. toggle() {
  3742. if (this.active) {
  3743. this.deactivate();
  3744. } else {
  3745. this.activate();
  3746. }
  3747. }
  3748. ignoreTarget(node) {
  3749. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3750. }
  3751. #onMouseDown(event) {
  3752. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3753. return;
  3754. }
  3755. if (event.originalTarget) {
  3756. try {
  3757. event.originalTarget.tagName;
  3758. } catch (e) {
  3759. return;
  3760. }
  3761. }
  3762. this.scrollLeftStart = this.element.scrollLeft;
  3763. this.scrollTopStart = this.element.scrollTop;
  3764. this.clientXStart = event.clientX;
  3765. this.clientYStart = event.clientY;
  3766. this.document.addEventListener("mousemove", this._onMouseMove, true);
  3767. this.document.addEventListener("mouseup", this._endPan, true);
  3768. this.element.addEventListener("scroll", this._endPan, true);
  3769. event.preventDefault();
  3770. event.stopPropagation();
  3771. const focusedElement = document.activeElement;
  3772. if (focusedElement && !focusedElement.contains(event.target)) {
  3773. focusedElement.blur();
  3774. }
  3775. }
  3776. #onMouseMove(event) {
  3777. this.element.removeEventListener("scroll", this._endPan, true);
  3778. if (!(event.buttons & 1)) {
  3779. this._endPan();
  3780. return;
  3781. }
  3782. const xDiff = event.clientX - this.clientXStart;
  3783. const yDiff = event.clientY - this.clientYStart;
  3784. const scrollTop = this.scrollTopStart - yDiff;
  3785. const scrollLeft = this.scrollLeftStart - xDiff;
  3786. if (this.element.scrollTo) {
  3787. this.element.scrollTo({
  3788. top: scrollTop,
  3789. left: scrollLeft,
  3790. behavior: "instant"
  3791. });
  3792. } else {
  3793. this.element.scrollTop = scrollTop;
  3794. this.element.scrollLeft = scrollLeft;
  3795. }
  3796. if (!this.overlay.parentNode) {
  3797. document.body.append(this.overlay);
  3798. }
  3799. }
  3800. #endPan() {
  3801. this.element.removeEventListener("scroll", this._endPan, true);
  3802. this.document.removeEventListener("mousemove", this._onMouseMove, true);
  3803. this.document.removeEventListener("mouseup", this._endPan, true);
  3804. this.overlay.remove();
  3805. }
  3806. }
  3807. exports.GrabToPan = GrabToPan;
  3808. /***/ }),
  3809. /* 9 */
  3810. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3811. Object.defineProperty(exports, "__esModule", ({
  3812. value: true
  3813. }));
  3814. exports.AnnotationEditorParams = void 0;
  3815. var _pdfjsLib = __webpack_require__(5);
  3816. class AnnotationEditorParams {
  3817. constructor(options, eventBus) {
  3818. this.eventBus = eventBus;
  3819. this.#bindListeners(options);
  3820. }
  3821. #bindListeners({
  3822. editorFreeTextFontSize,
  3823. editorFreeTextColor,
  3824. editorInkColor,
  3825. editorInkThickness,
  3826. editorInkOpacity
  3827. }) {
  3828. editorFreeTextFontSize.addEventListener("input", evt => {
  3829. this.eventBus.dispatch("switchannotationeditorparams", {
  3830. source: this,
  3831. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE,
  3832. value: editorFreeTextFontSize.valueAsNumber
  3833. });
  3834. });
  3835. editorFreeTextColor.addEventListener("input", evt => {
  3836. this.eventBus.dispatch("switchannotationeditorparams", {
  3837. source: this,
  3838. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR,
  3839. value: editorFreeTextColor.value
  3840. });
  3841. });
  3842. editorInkColor.addEventListener("input", evt => {
  3843. this.eventBus.dispatch("switchannotationeditorparams", {
  3844. source: this,
  3845. type: _pdfjsLib.AnnotationEditorParamsType.INK_COLOR,
  3846. value: editorInkColor.value
  3847. });
  3848. });
  3849. editorInkThickness.addEventListener("input", evt => {
  3850. this.eventBus.dispatch("switchannotationeditorparams", {
  3851. source: this,
  3852. type: _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS,
  3853. value: editorInkThickness.valueAsNumber
  3854. });
  3855. });
  3856. editorInkOpacity.addEventListener("input", evt => {
  3857. this.eventBus.dispatch("switchannotationeditorparams", {
  3858. source: this,
  3859. type: _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY,
  3860. value: editorInkOpacity.valueAsNumber
  3861. });
  3862. });
  3863. this.eventBus._on("annotationeditorparamschanged", evt => {
  3864. for (const [type, value] of evt.details) {
  3865. switch (type) {
  3866. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  3867. editorFreeTextFontSize.value = value;
  3868. break;
  3869. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  3870. editorFreeTextColor.value = value;
  3871. break;
  3872. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  3873. editorInkColor.value = value;
  3874. break;
  3875. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  3876. editorInkThickness.value = value;
  3877. break;
  3878. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  3879. editorInkOpacity.value = value;
  3880. break;
  3881. }
  3882. }
  3883. });
  3884. }
  3885. }
  3886. exports.AnnotationEditorParams = AnnotationEditorParams;
  3887. /***/ }),
  3888. /* 10 */
  3889. /***/ ((__unused_webpack_module, exports) => {
  3890. Object.defineProperty(exports, "__esModule", ({
  3891. value: true
  3892. }));
  3893. exports.OverlayManager = void 0;
  3894. class OverlayManager {
  3895. #overlays = new WeakMap();
  3896. #active = null;
  3897. get active() {
  3898. return this.#active;
  3899. }
  3900. async register(dialog, canForceClose = false) {
  3901. if (typeof dialog !== "object") {
  3902. throw new Error("Not enough parameters.");
  3903. } else if (this.#overlays.has(dialog)) {
  3904. throw new Error("The overlay is already registered.");
  3905. }
  3906. this.#overlays.set(dialog, {
  3907. canForceClose
  3908. });
  3909. dialog.addEventListener("cancel", evt => {
  3910. this.#active = null;
  3911. });
  3912. }
  3913. async unregister(dialog) {
  3914. if (!this.#overlays.has(dialog)) {
  3915. throw new Error("The overlay does not exist.");
  3916. } else if (this.#active === dialog) {
  3917. throw new Error("The overlay cannot be removed while it is active.");
  3918. }
  3919. this.#overlays.delete(dialog);
  3920. }
  3921. async open(dialog) {
  3922. if (!this.#overlays.has(dialog)) {
  3923. throw new Error("The overlay does not exist.");
  3924. } else if (this.#active) {
  3925. if (this.#active === dialog) {
  3926. throw new Error("The overlay is already active.");
  3927. } else if (this.#overlays.get(dialog).canForceClose) {
  3928. await this.close();
  3929. } else {
  3930. throw new Error("Another overlay is currently active.");
  3931. }
  3932. }
  3933. this.#active = dialog;
  3934. dialog.showModal();
  3935. }
  3936. async close(dialog = this.#active) {
  3937. if (!this.#overlays.has(dialog)) {
  3938. throw new Error("The overlay does not exist.");
  3939. } else if (!this.#active) {
  3940. throw new Error("The overlay is currently not active.");
  3941. } else if (this.#active !== dialog) {
  3942. throw new Error("Another overlay is currently active.");
  3943. }
  3944. dialog.close();
  3945. this.#active = null;
  3946. }
  3947. }
  3948. exports.OverlayManager = OverlayManager;
  3949. /***/ }),
  3950. /* 11 */
  3951. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3952. Object.defineProperty(exports, "__esModule", ({
  3953. value: true
  3954. }));
  3955. exports.PasswordPrompt = void 0;
  3956. var _pdfjsLib = __webpack_require__(5);
  3957. class PasswordPrompt {
  3958. #activeCapability = null;
  3959. #updateCallback = null;
  3960. #reason = null;
  3961. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3962. this.dialog = options.dialog;
  3963. this.label = options.label;
  3964. this.input = options.input;
  3965. this.submitButton = options.submitButton;
  3966. this.cancelButton = options.cancelButton;
  3967. this.overlayManager = overlayManager;
  3968. this.l10n = l10n;
  3969. this._isViewerEmbedded = isViewerEmbedded;
  3970. this.submitButton.addEventListener("click", this.#verify.bind(this));
  3971. this.cancelButton.addEventListener("click", this.close.bind(this));
  3972. this.input.addEventListener("keydown", e => {
  3973. if (e.keyCode === 13) {
  3974. this.#verify();
  3975. }
  3976. });
  3977. this.overlayManager.register(this.dialog, true);
  3978. this.dialog.addEventListener("close", this.#cancel.bind(this));
  3979. }
  3980. async open() {
  3981. if (this.#activeCapability) {
  3982. await this.#activeCapability.promise;
  3983. }
  3984. this.#activeCapability = (0, _pdfjsLib.createPromiseCapability)();
  3985. try {
  3986. await this.overlayManager.open(this.dialog);
  3987. } catch (ex) {
  3988. this.#activeCapability = null;
  3989. throw ex;
  3990. }
  3991. const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3992. if (!this._isViewerEmbedded || passwordIncorrect) {
  3993. this.input.focus();
  3994. }
  3995. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3996. }
  3997. async close() {
  3998. if (this.overlayManager.active === this.dialog) {
  3999. this.overlayManager.close(this.dialog);
  4000. }
  4001. }
  4002. #verify() {
  4003. const password = this.input.value;
  4004. if (password?.length > 0) {
  4005. this.#invokeCallback(password);
  4006. }
  4007. }
  4008. #cancel() {
  4009. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  4010. this.#activeCapability.resolve();
  4011. }
  4012. #invokeCallback(password) {
  4013. if (!this.#updateCallback) {
  4014. return;
  4015. }
  4016. this.close();
  4017. this.input.value = "";
  4018. this.#updateCallback(password);
  4019. this.#updateCallback = null;
  4020. }
  4021. async setUpdateCallback(updateCallback, reason) {
  4022. if (this.#activeCapability) {
  4023. await this.#activeCapability.promise;
  4024. }
  4025. this.#updateCallback = updateCallback;
  4026. this.#reason = reason;
  4027. }
  4028. }
  4029. exports.PasswordPrompt = PasswordPrompt;
  4030. /***/ }),
  4031. /* 12 */
  4032. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4033. Object.defineProperty(exports, "__esModule", ({
  4034. value: true
  4035. }));
  4036. exports.PDFAttachmentViewer = void 0;
  4037. var _pdfjsLib = __webpack_require__(5);
  4038. var _base_tree_viewer = __webpack_require__(13);
  4039. var _event_utils = __webpack_require__(6);
  4040. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4041. constructor(options) {
  4042. super(options);
  4043. this.downloadManager = options.downloadManager;
  4044. this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
  4045. }
  4046. reset(keepRenderedCapability = false) {
  4047. super.reset();
  4048. this._attachments = null;
  4049. if (!keepRenderedCapability) {
  4050. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4051. }
  4052. this._pendingDispatchEvent = false;
  4053. }
  4054. async _dispatchEvent(attachmentsCount) {
  4055. this._renderedCapability.resolve();
  4056. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4057. this._pendingDispatchEvent = true;
  4058. await (0, _event_utils.waitOnEventOrTimeout)({
  4059. target: this.eventBus,
  4060. name: "annotationlayerrendered",
  4061. delay: 1000
  4062. });
  4063. if (!this._pendingDispatchEvent) {
  4064. return;
  4065. }
  4066. }
  4067. this._pendingDispatchEvent = false;
  4068. this.eventBus.dispatch("attachmentsloaded", {
  4069. source: this,
  4070. attachmentsCount
  4071. });
  4072. }
  4073. _bindLink(element, {
  4074. content,
  4075. filename
  4076. }) {
  4077. element.onclick = () => {
  4078. this.downloadManager.openOrDownloadData(element, content, filename);
  4079. return false;
  4080. };
  4081. }
  4082. render({
  4083. attachments,
  4084. keepRenderedCapability = false
  4085. }) {
  4086. if (this._attachments) {
  4087. this.reset(keepRenderedCapability);
  4088. }
  4089. this._attachments = attachments || null;
  4090. if (!attachments) {
  4091. this._dispatchEvent(0);
  4092. return;
  4093. }
  4094. const names = Object.keys(attachments).sort(function (a, b) {
  4095. return a.toLowerCase().localeCompare(b.toLowerCase());
  4096. });
  4097. const fragment = document.createDocumentFragment();
  4098. let attachmentsCount = 0;
  4099. for (const name of names) {
  4100. const item = attachments[name];
  4101. const content = item.content,
  4102. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  4103. const div = document.createElement("div");
  4104. div.className = "treeItem";
  4105. const element = document.createElement("a");
  4106. this._bindLink(element, {
  4107. content,
  4108. filename
  4109. });
  4110. element.textContent = this._normalizeTextContent(filename);
  4111. div.append(element);
  4112. fragment.append(div);
  4113. attachmentsCount++;
  4114. }
  4115. this._finishRendering(fragment, attachmentsCount);
  4116. }
  4117. #appendAttachment({
  4118. filename,
  4119. content
  4120. }) {
  4121. const renderedPromise = this._renderedCapability.promise;
  4122. renderedPromise.then(() => {
  4123. if (renderedPromise !== this._renderedCapability.promise) {
  4124. return;
  4125. }
  4126. const attachments = this._attachments || Object.create(null);
  4127. for (const name in attachments) {
  4128. if (filename === name) {
  4129. return;
  4130. }
  4131. }
  4132. attachments[filename] = {
  4133. filename,
  4134. content
  4135. };
  4136. this.render({
  4137. attachments,
  4138. keepRenderedCapability: true
  4139. });
  4140. });
  4141. }
  4142. }
  4143. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4144. /***/ }),
  4145. /* 13 */
  4146. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4147. Object.defineProperty(exports, "__esModule", ({
  4148. value: true
  4149. }));
  4150. exports.BaseTreeViewer = void 0;
  4151. var _ui_utils = __webpack_require__(1);
  4152. const TREEITEM_OFFSET_TOP = -100;
  4153. const TREEITEM_SELECTED_CLASS = "selected";
  4154. class BaseTreeViewer {
  4155. constructor(options) {
  4156. if (this.constructor === BaseTreeViewer) {
  4157. throw new Error("Cannot initialize BaseTreeViewer.");
  4158. }
  4159. this.container = options.container;
  4160. this.eventBus = options.eventBus;
  4161. this.reset();
  4162. }
  4163. reset() {
  4164. this._pdfDocument = null;
  4165. this._lastToggleIsShow = true;
  4166. this._currentTreeItem = null;
  4167. this.container.textContent = "";
  4168. this.container.classList.remove("treeWithDeepNesting");
  4169. }
  4170. _dispatchEvent(count) {
  4171. throw new Error("Not implemented: _dispatchEvent");
  4172. }
  4173. _bindLink(element, params) {
  4174. throw new Error("Not implemented: _bindLink");
  4175. }
  4176. _normalizeTextContent(str) {
  4177. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4178. }
  4179. _addToggleButton(div, hidden = false) {
  4180. const toggler = document.createElement("div");
  4181. toggler.className = "treeItemToggler";
  4182. if (hidden) {
  4183. toggler.classList.add("treeItemsHidden");
  4184. }
  4185. toggler.onclick = evt => {
  4186. evt.stopPropagation();
  4187. toggler.classList.toggle("treeItemsHidden");
  4188. if (evt.shiftKey) {
  4189. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  4190. this._toggleTreeItem(div, shouldShowAll);
  4191. }
  4192. };
  4193. div.prepend(toggler);
  4194. }
  4195. _toggleTreeItem(root, show = false) {
  4196. this._lastToggleIsShow = show;
  4197. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4198. toggler.classList.toggle("treeItemsHidden", !show);
  4199. }
  4200. }
  4201. _toggleAllTreeItems() {
  4202. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4203. }
  4204. _finishRendering(fragment, count, hasAnyNesting = false) {
  4205. if (hasAnyNesting) {
  4206. this.container.classList.add("treeWithDeepNesting");
  4207. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  4208. }
  4209. this.container.append(fragment);
  4210. this._dispatchEvent(count);
  4211. }
  4212. render(params) {
  4213. throw new Error("Not implemented: render");
  4214. }
  4215. _updateCurrentTreeItem(treeItem = null) {
  4216. if (this._currentTreeItem) {
  4217. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4218. this._currentTreeItem = null;
  4219. }
  4220. if (treeItem) {
  4221. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4222. this._currentTreeItem = treeItem;
  4223. }
  4224. }
  4225. _scrollToCurrentTreeItem(treeItem) {
  4226. if (!treeItem) {
  4227. return;
  4228. }
  4229. let currentNode = treeItem.parentNode;
  4230. while (currentNode && currentNode !== this.container) {
  4231. if (currentNode.classList.contains("treeItem")) {
  4232. const toggler = currentNode.firstElementChild;
  4233. toggler?.classList.remove("treeItemsHidden");
  4234. }
  4235. currentNode = currentNode.parentNode;
  4236. }
  4237. this._updateCurrentTreeItem(treeItem);
  4238. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  4239. }
  4240. }
  4241. exports.BaseTreeViewer = BaseTreeViewer;
  4242. /***/ }),
  4243. /* 14 */
  4244. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4245. Object.defineProperty(exports, "__esModule", ({
  4246. value: true
  4247. }));
  4248. exports.PDFDocumentProperties = void 0;
  4249. var _pdfjsLib = __webpack_require__(5);
  4250. var _ui_utils = __webpack_require__(1);
  4251. const DEFAULT_FIELD_CONTENT = "-";
  4252. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  4253. const US_PAGE_NAMES = {
  4254. "8.5x11": "Letter",
  4255. "8.5x14": "Legal"
  4256. };
  4257. const METRIC_PAGE_NAMES = {
  4258. "297x420": "A3",
  4259. "210x297": "A4"
  4260. };
  4261. function getPageName(size, isPortrait, pageNames) {
  4262. const width = isPortrait ? size.width : size.height;
  4263. const height = isPortrait ? size.height : size.width;
  4264. return pageNames[`${width}x${height}`];
  4265. }
  4266. class PDFDocumentProperties {
  4267. #fieldData = null;
  4268. constructor({
  4269. dialog,
  4270. fields,
  4271. closeButton
  4272. }, overlayManager, eventBus, l10n, fileNameLookup) {
  4273. this.dialog = dialog;
  4274. this.fields = fields;
  4275. this.overlayManager = overlayManager;
  4276. this.l10n = l10n;
  4277. this._fileNameLookup = fileNameLookup;
  4278. this.#reset();
  4279. closeButton.addEventListener("click", this.close.bind(this));
  4280. this.overlayManager.register(this.dialog);
  4281. eventBus._on("pagechanging", evt => {
  4282. this._currentPageNumber = evt.pageNumber;
  4283. });
  4284. eventBus._on("rotationchanging", evt => {
  4285. this._pagesRotation = evt.pagesRotation;
  4286. });
  4287. this._isNonMetricLocale = true;
  4288. l10n.getLanguage().then(locale => {
  4289. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4290. });
  4291. }
  4292. async open() {
  4293. await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
  4294. const currentPageNumber = this._currentPageNumber;
  4295. const pagesRotation = this._pagesRotation;
  4296. if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
  4297. this.#updateUI();
  4298. return;
  4299. }
  4300. const {
  4301. info,
  4302. contentLength
  4303. } = await this.pdfDocument.getMetadata();
  4304. 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 => {
  4305. return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4306. }), this.#parseLinearization(info.IsLinearized)]);
  4307. this.#fieldData = Object.freeze({
  4308. fileName,
  4309. fileSize,
  4310. title: info.Title,
  4311. author: info.Author,
  4312. subject: info.Subject,
  4313. keywords: info.Keywords,
  4314. creationDate,
  4315. modificationDate,
  4316. creator: info.Creator,
  4317. producer: info.Producer,
  4318. version: info.PDFFormatVersion,
  4319. pageCount: this.pdfDocument.numPages,
  4320. pageSize,
  4321. linearized: isLinearized,
  4322. _currentPageNumber: currentPageNumber,
  4323. _pagesRotation: pagesRotation
  4324. });
  4325. this.#updateUI();
  4326. const {
  4327. length
  4328. } = await this.pdfDocument.getDownloadInfo();
  4329. if (contentLength === length) {
  4330. return;
  4331. }
  4332. const data = Object.assign(Object.create(null), this.#fieldData);
  4333. data.fileSize = await this.#parseFileSize(length);
  4334. this.#fieldData = Object.freeze(data);
  4335. this.#updateUI();
  4336. }
  4337. async close() {
  4338. this.overlayManager.close(this.dialog);
  4339. }
  4340. setDocument(pdfDocument) {
  4341. if (this.pdfDocument) {
  4342. this.#reset();
  4343. this.#updateUI(true);
  4344. }
  4345. if (!pdfDocument) {
  4346. return;
  4347. }
  4348. this.pdfDocument = pdfDocument;
  4349. this._dataAvailableCapability.resolve();
  4350. }
  4351. #reset() {
  4352. this.pdfDocument = null;
  4353. this.#fieldData = null;
  4354. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4355. this._currentPageNumber = 1;
  4356. this._pagesRotation = 0;
  4357. }
  4358. #updateUI(reset = false) {
  4359. if (reset || !this.#fieldData) {
  4360. for (const id in this.fields) {
  4361. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4362. }
  4363. return;
  4364. }
  4365. if (this.overlayManager.active !== this.dialog) {
  4366. return;
  4367. }
  4368. for (const id in this.fields) {
  4369. const content = this.#fieldData[id];
  4370. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4371. }
  4372. }
  4373. async #parseFileSize(fileSize = 0) {
  4374. const kb = fileSize / 1024,
  4375. mb = kb / 1024;
  4376. if (!kb) {
  4377. return undefined;
  4378. }
  4379. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4380. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4381. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4382. size_b: fileSize.toLocaleString()
  4383. });
  4384. }
  4385. async #parsePageSize(pageSizeInches, pagesRotation) {
  4386. if (!pageSizeInches) {
  4387. return undefined;
  4388. }
  4389. if (pagesRotation % 180 !== 0) {
  4390. pageSizeInches = {
  4391. width: pageSizeInches.height,
  4392. height: pageSizeInches.width
  4393. };
  4394. }
  4395. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4396. let sizeInches = {
  4397. width: Math.round(pageSizeInches.width * 100) / 100,
  4398. height: Math.round(pageSizeInches.height * 100) / 100
  4399. };
  4400. let sizeMillimeters = {
  4401. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4402. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4403. };
  4404. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4405. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4406. const exactMillimeters = {
  4407. width: pageSizeInches.width * 25.4,
  4408. height: pageSizeInches.height * 25.4
  4409. };
  4410. const intMillimeters = {
  4411. width: Math.round(sizeMillimeters.width),
  4412. height: Math.round(sizeMillimeters.height)
  4413. };
  4414. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4415. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4416. if (rawName) {
  4417. sizeInches = {
  4418. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4419. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4420. };
  4421. sizeMillimeters = intMillimeters;
  4422. }
  4423. }
  4424. }
  4425. const [{
  4426. width,
  4427. height
  4428. }, 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"}`)]);
  4429. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4430. width: width.toLocaleString(),
  4431. height: height.toLocaleString(),
  4432. unit,
  4433. name,
  4434. orientation
  4435. });
  4436. }
  4437. async #parseDate(inputDate) {
  4438. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4439. if (!dateObject) {
  4440. return undefined;
  4441. }
  4442. return this.l10n.get("document_properties_date_string", {
  4443. date: dateObject.toLocaleDateString(),
  4444. time: dateObject.toLocaleTimeString()
  4445. });
  4446. }
  4447. #parseLinearization(isLinearized) {
  4448. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4449. }
  4450. }
  4451. exports.PDFDocumentProperties = PDFDocumentProperties;
  4452. /***/ }),
  4453. /* 15 */
  4454. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4455. Object.defineProperty(exports, "__esModule", ({
  4456. value: true
  4457. }));
  4458. exports.PDFFindBar = void 0;
  4459. var _pdf_find_controller = __webpack_require__(16);
  4460. const MATCHES_COUNT_LIMIT = 1000;
  4461. class PDFFindBar {
  4462. constructor(options, eventBus, l10n) {
  4463. this.opened = false;
  4464. this.bar = options.bar;
  4465. this.toggleButton = options.toggleButton;
  4466. this.findField = options.findField;
  4467. this.highlightAll = options.highlightAllCheckbox;
  4468. this.caseSensitive = options.caseSensitiveCheckbox;
  4469. this.matchDiacritics = options.matchDiacriticsCheckbox;
  4470. this.entireWord = options.entireWordCheckbox;
  4471. this.findMsg = options.findMsg;
  4472. this.findResultsCount = options.findResultsCount;
  4473. this.findPreviousButton = options.findPreviousButton;
  4474. this.findNextButton = options.findNextButton;
  4475. this.eventBus = eventBus;
  4476. this.l10n = l10n;
  4477. this.toggleButton.addEventListener("click", () => {
  4478. this.toggle();
  4479. });
  4480. this.findField.addEventListener("input", () => {
  4481. this.dispatchEvent("");
  4482. });
  4483. this.bar.addEventListener("keydown", e => {
  4484. switch (e.keyCode) {
  4485. case 13:
  4486. if (e.target === this.findField) {
  4487. this.dispatchEvent("again", e.shiftKey);
  4488. }
  4489. break;
  4490. case 27:
  4491. this.close();
  4492. break;
  4493. }
  4494. });
  4495. this.findPreviousButton.addEventListener("click", () => {
  4496. this.dispatchEvent("again", true);
  4497. });
  4498. this.findNextButton.addEventListener("click", () => {
  4499. this.dispatchEvent("again", false);
  4500. });
  4501. this.highlightAll.addEventListener("click", () => {
  4502. this.dispatchEvent("highlightallchange");
  4503. });
  4504. this.caseSensitive.addEventListener("click", () => {
  4505. this.dispatchEvent("casesensitivitychange");
  4506. });
  4507. this.entireWord.addEventListener("click", () => {
  4508. this.dispatchEvent("entirewordchange");
  4509. });
  4510. this.matchDiacritics.addEventListener("click", () => {
  4511. this.dispatchEvent("diacriticmatchingchange");
  4512. });
  4513. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  4514. }
  4515. reset() {
  4516. this.updateUIState();
  4517. }
  4518. dispatchEvent(type, findPrev = false) {
  4519. this.eventBus.dispatch("find", {
  4520. source: this,
  4521. type,
  4522. query: this.findField.value,
  4523. phraseSearch: true,
  4524. caseSensitive: this.caseSensitive.checked,
  4525. entireWord: this.entireWord.checked,
  4526. highlightAll: this.highlightAll.checked,
  4527. findPrevious: findPrev,
  4528. matchDiacritics: this.matchDiacritics.checked
  4529. });
  4530. }
  4531. updateUIState(state, previous, matchesCount) {
  4532. let findMsg = Promise.resolve("");
  4533. let status = "";
  4534. switch (state) {
  4535. case _pdf_find_controller.FindState.FOUND:
  4536. break;
  4537. case _pdf_find_controller.FindState.PENDING:
  4538. status = "pending";
  4539. break;
  4540. case _pdf_find_controller.FindState.NOT_FOUND:
  4541. findMsg = this.l10n.get("find_not_found");
  4542. status = "notFound";
  4543. break;
  4544. case _pdf_find_controller.FindState.WRAPPED:
  4545. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4546. break;
  4547. }
  4548. this.findField.setAttribute("data-status", status);
  4549. this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
  4550. findMsg.then(msg => {
  4551. this.findMsg.textContent = msg;
  4552. this.#adjustWidth();
  4553. });
  4554. this.updateResultsCount(matchesCount);
  4555. }
  4556. updateResultsCount({
  4557. current = 0,
  4558. total = 0
  4559. } = {}) {
  4560. const limit = MATCHES_COUNT_LIMIT;
  4561. let matchCountMsg = Promise.resolve("");
  4562. if (total > 0) {
  4563. if (total > limit) {
  4564. let key = "find_match_count_limit";
  4565. matchCountMsg = this.l10n.get(key, {
  4566. limit
  4567. });
  4568. } else {
  4569. let key = "find_match_count";
  4570. matchCountMsg = this.l10n.get(key, {
  4571. current,
  4572. total
  4573. });
  4574. }
  4575. }
  4576. matchCountMsg.then(msg => {
  4577. this.findResultsCount.textContent = msg;
  4578. this.#adjustWidth();
  4579. });
  4580. }
  4581. open() {
  4582. if (!this.opened) {
  4583. this.opened = true;
  4584. this.toggleButton.classList.add("toggled");
  4585. this.toggleButton.setAttribute("aria-expanded", "true");
  4586. this.bar.classList.remove("hidden");
  4587. }
  4588. this.findField.select();
  4589. this.findField.focus();
  4590. this.#adjustWidth();
  4591. }
  4592. close() {
  4593. if (!this.opened) {
  4594. return;
  4595. }
  4596. this.opened = false;
  4597. this.toggleButton.classList.remove("toggled");
  4598. this.toggleButton.setAttribute("aria-expanded", "false");
  4599. this.bar.classList.add("hidden");
  4600. this.eventBus.dispatch("findbarclose", {
  4601. source: this
  4602. });
  4603. }
  4604. toggle() {
  4605. if (this.opened) {
  4606. this.close();
  4607. } else {
  4608. this.open();
  4609. }
  4610. }
  4611. #adjustWidth() {
  4612. if (!this.opened) {
  4613. return;
  4614. }
  4615. this.bar.classList.remove("wrapContainers");
  4616. const findbarHeight = this.bar.clientHeight;
  4617. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4618. if (findbarHeight > inputContainerHeight) {
  4619. this.bar.classList.add("wrapContainers");
  4620. }
  4621. }
  4622. }
  4623. exports.PDFFindBar = PDFFindBar;
  4624. /***/ }),
  4625. /* 16 */
  4626. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4627. Object.defineProperty(exports, "__esModule", ({
  4628. value: true
  4629. }));
  4630. exports.PDFFindController = exports.FindState = void 0;
  4631. var _ui_utils = __webpack_require__(1);
  4632. var _pdfjsLib = __webpack_require__(5);
  4633. var _pdf_find_utils = __webpack_require__(17);
  4634. const FindState = {
  4635. FOUND: 0,
  4636. NOT_FOUND: 1,
  4637. WRAPPED: 2,
  4638. PENDING: 3
  4639. };
  4640. exports.FindState = FindState;
  4641. const FIND_TIMEOUT = 250;
  4642. const MATCH_SCROLL_OFFSET_TOP = -50;
  4643. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4644. const CHARACTERS_TO_NORMALIZE = {
  4645. "\u2010": "-",
  4646. "\u2018": "'",
  4647. "\u2019": "'",
  4648. "\u201A": "'",
  4649. "\u201B": "'",
  4650. "\u201C": '"',
  4651. "\u201D": '"',
  4652. "\u201E": '"',
  4653. "\u201F": '"',
  4654. "\u00BC": "1/4",
  4655. "\u00BD": "1/2",
  4656. "\u00BE": "3/4"
  4657. };
  4658. 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]);
  4659. const DIACRITICS_EXCEPTION_STR = [...DIACRITICS_EXCEPTION.values()].map(x => String.fromCharCode(x)).join("");
  4660. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  4661. const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  4662. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  4663. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  4664. const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  4665. const SYLLABLES_LENGTHS = new Map();
  4666. const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  4667. let noSyllablesRegExp = null;
  4668. let withSyllablesRegExp = null;
  4669. function normalize(text) {
  4670. const syllablePositions = [];
  4671. let m;
  4672. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  4673. let {
  4674. index
  4675. } = m;
  4676. for (const char of m[0]) {
  4677. let len = SYLLABLES_LENGTHS.get(char);
  4678. if (!len) {
  4679. len = char.normalize("NFD").length;
  4680. SYLLABLES_LENGTHS.set(char, len);
  4681. }
  4682. syllablePositions.push([len, index++]);
  4683. }
  4684. }
  4685. let normalizationRegex;
  4686. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  4687. normalizationRegex = noSyllablesRegExp;
  4688. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  4689. normalizationRegex = withSyllablesRegExp;
  4690. } else {
  4691. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4692. const regexp = `([${replace}])|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(\\p{Ideographic}\\n)|(\\n)`;
  4693. if (syllablePositions.length === 0) {
  4694. normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
  4695. } else {
  4696. normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
  4697. }
  4698. }
  4699. const rawDiacriticsPositions = [];
  4700. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  4701. rawDiacriticsPositions.push([m[0].length, m.index]);
  4702. }
  4703. let normalized = text.normalize("NFD");
  4704. const positions = [[0, 0]];
  4705. let rawDiacriticsIndex = 0;
  4706. let syllableIndex = 0;
  4707. let shift = 0;
  4708. let shiftOrigin = 0;
  4709. let eol = 0;
  4710. let hasDiacritics = false;
  4711. normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, i) => {
  4712. i -= shiftOrigin;
  4713. if (p1) {
  4714. const replacement = CHARACTERS_TO_NORMALIZE[match];
  4715. const jj = replacement.length;
  4716. for (let j = 1; j < jj; j++) {
  4717. positions.push([i - shift + j, shift - j]);
  4718. }
  4719. shift -= jj - 1;
  4720. return replacement;
  4721. }
  4722. if (p2) {
  4723. const hasTrailingDashEOL = p2.endsWith("\n");
  4724. const len = hasTrailingDashEOL ? p2.length - 2 : p2.length;
  4725. hasDiacritics = true;
  4726. let jj = len;
  4727. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  4728. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  4729. ++rawDiacriticsIndex;
  4730. }
  4731. for (let j = 1; j <= jj; j++) {
  4732. positions.push([i - 1 - shift + j, shift - j]);
  4733. }
  4734. shift -= jj;
  4735. shiftOrigin += jj;
  4736. if (hasTrailingDashEOL) {
  4737. i += len - 1;
  4738. positions.push([i - shift + 1, 1 + shift]);
  4739. shift += 1;
  4740. shiftOrigin += 1;
  4741. eol += 1;
  4742. return p2.slice(0, len);
  4743. }
  4744. return p2;
  4745. }
  4746. if (p3) {
  4747. positions.push([i - shift + 1, 1 + shift]);
  4748. shift += 1;
  4749. shiftOrigin += 1;
  4750. eol += 1;
  4751. return p3.charAt(0);
  4752. }
  4753. if (p4) {
  4754. positions.push([i - shift + 1, shift]);
  4755. shiftOrigin += 1;
  4756. eol += 1;
  4757. return p4.charAt(0);
  4758. }
  4759. if (p5) {
  4760. positions.push([i - shift + 1, shift - 1]);
  4761. shift -= 1;
  4762. shiftOrigin += 1;
  4763. eol += 1;
  4764. return " ";
  4765. }
  4766. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  4767. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  4768. ++syllableIndex;
  4769. for (let j = 1; j <= newCharLen; j++) {
  4770. positions.push([i - (shift - j), shift - j]);
  4771. }
  4772. shift -= newCharLen;
  4773. shiftOrigin += newCharLen;
  4774. }
  4775. return p6;
  4776. });
  4777. positions.push([normalized.length, shift]);
  4778. return [normalized, positions, hasDiacritics];
  4779. }
  4780. function getOriginalIndex(diffs, pos, len) {
  4781. if (!diffs) {
  4782. return [pos, len];
  4783. }
  4784. const start = pos;
  4785. const end = pos + len;
  4786. let i = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= start);
  4787. if (diffs[i][0] > start) {
  4788. --i;
  4789. }
  4790. let j = (0, _ui_utils.binarySearchFirstItem)(diffs, x => x[0] >= end, i);
  4791. if (diffs[j][0] > end) {
  4792. --j;
  4793. }
  4794. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  4795. }
  4796. class PDFFindController {
  4797. constructor({
  4798. linkService,
  4799. eventBus
  4800. }) {
  4801. this._linkService = linkService;
  4802. this._eventBus = eventBus;
  4803. this.#reset();
  4804. eventBus._on("find", this.#onFind.bind(this));
  4805. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  4806. }
  4807. get highlightMatches() {
  4808. return this._highlightMatches;
  4809. }
  4810. get pageMatches() {
  4811. return this._pageMatches;
  4812. }
  4813. get pageMatchesLength() {
  4814. return this._pageMatchesLength;
  4815. }
  4816. get selected() {
  4817. return this._selected;
  4818. }
  4819. get state() {
  4820. return this._state;
  4821. }
  4822. setDocument(pdfDocument) {
  4823. if (this._pdfDocument) {
  4824. this.#reset();
  4825. }
  4826. if (!pdfDocument) {
  4827. return;
  4828. }
  4829. this._pdfDocument = pdfDocument;
  4830. this._firstPageCapability.resolve();
  4831. }
  4832. #onFind(state) {
  4833. if (!state) {
  4834. return;
  4835. }
  4836. const pdfDocument = this._pdfDocument;
  4837. const {
  4838. type
  4839. } = state;
  4840. if (this._state === null || this.#shouldDirtyMatch(state)) {
  4841. this._dirtyMatch = true;
  4842. }
  4843. this._state = state;
  4844. if (type !== "highlightallchange") {
  4845. this.#updateUIState(FindState.PENDING);
  4846. }
  4847. this._firstPageCapability.promise.then(() => {
  4848. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4849. return;
  4850. }
  4851. this.#extractText();
  4852. const findbarClosed = !this._highlightMatches;
  4853. const pendingTimeout = !!this._findTimeout;
  4854. if (this._findTimeout) {
  4855. clearTimeout(this._findTimeout);
  4856. this._findTimeout = null;
  4857. }
  4858. if (!type) {
  4859. this._findTimeout = setTimeout(() => {
  4860. this.#nextMatch();
  4861. this._findTimeout = null;
  4862. }, FIND_TIMEOUT);
  4863. } else if (this._dirtyMatch) {
  4864. this.#nextMatch();
  4865. } else if (type === "again") {
  4866. this.#nextMatch();
  4867. if (findbarClosed && this._state.highlightAll) {
  4868. this.#updateAllPages();
  4869. }
  4870. } else if (type === "highlightallchange") {
  4871. if (pendingTimeout) {
  4872. this.#nextMatch();
  4873. } else {
  4874. this._highlightMatches = true;
  4875. }
  4876. this.#updateAllPages();
  4877. } else {
  4878. this.#nextMatch();
  4879. }
  4880. });
  4881. }
  4882. scrollMatchIntoView({
  4883. element = null,
  4884. selectedLeft = 0,
  4885. pageIndex = -1,
  4886. matchIndex = -1
  4887. }) {
  4888. if (!this._scrollMatches || !element) {
  4889. return;
  4890. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4891. return;
  4892. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4893. return;
  4894. }
  4895. this._scrollMatches = false;
  4896. const spot = {
  4897. top: MATCH_SCROLL_OFFSET_TOP,
  4898. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  4899. };
  4900. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4901. }
  4902. #reset() {
  4903. this._highlightMatches = false;
  4904. this._scrollMatches = false;
  4905. this._pdfDocument = null;
  4906. this._pageMatches = [];
  4907. this._pageMatchesLength = [];
  4908. this._state = null;
  4909. this._selected = {
  4910. pageIdx: -1,
  4911. matchIdx: -1
  4912. };
  4913. this._offset = {
  4914. pageIdx: null,
  4915. matchIdx: null,
  4916. wrapped: false
  4917. };
  4918. this._extractTextPromises = [];
  4919. this._pageContents = [];
  4920. this._pageDiffs = [];
  4921. this._hasDiacritics = [];
  4922. this._matchesCountTotal = 0;
  4923. this._pagesToSearch = null;
  4924. this._pendingFindMatches = new Set();
  4925. this._resumePageIdx = null;
  4926. this._dirtyMatch = false;
  4927. clearTimeout(this._findTimeout);
  4928. this._findTimeout = null;
  4929. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4930. }
  4931. get #query() {
  4932. if (this._state.query !== this._rawQuery) {
  4933. this._rawQuery = this._state.query;
  4934. [this._normalizedQuery] = normalize(this._state.query);
  4935. }
  4936. return this._normalizedQuery;
  4937. }
  4938. #shouldDirtyMatch(state) {
  4939. if (state.query !== this._state.query) {
  4940. return true;
  4941. }
  4942. switch (state.type) {
  4943. case "again":
  4944. const pageNumber = this._selected.pageIdx + 1;
  4945. const linkService = this._linkService;
  4946. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4947. return true;
  4948. }
  4949. return false;
  4950. case "highlightallchange":
  4951. return false;
  4952. }
  4953. return true;
  4954. }
  4955. #isEntireWord(content, startIdx, length) {
  4956. let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP);
  4957. if (match) {
  4958. const first = content.charCodeAt(startIdx);
  4959. const limit = match[1].charCodeAt(0);
  4960. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4961. return false;
  4962. }
  4963. }
  4964. match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP);
  4965. if (match) {
  4966. const last = content.charCodeAt(startIdx + length - 1);
  4967. const limit = match[1].charCodeAt(0);
  4968. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4969. return false;
  4970. }
  4971. }
  4972. return true;
  4973. }
  4974. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  4975. const matches = [],
  4976. matchesLength = [];
  4977. const diffs = this._pageDiffs[pageIndex];
  4978. let match;
  4979. while ((match = query.exec(pageContent)) !== null) {
  4980. if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) {
  4981. continue;
  4982. }
  4983. const [matchPos, matchLen] = getOriginalIndex(diffs, match.index, match[0].length);
  4984. if (matchLen) {
  4985. matches.push(matchPos);
  4986. matchesLength.push(matchLen);
  4987. }
  4988. }
  4989. this._pageMatches[pageIndex] = matches;
  4990. this._pageMatchesLength[pageIndex] = matchesLength;
  4991. }
  4992. #convertToRegExpString(query, hasDiacritics) {
  4993. const {
  4994. matchDiacritics
  4995. } = this._state;
  4996. let isUnicode = false;
  4997. query = query.replace(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => {
  4998. if (p1) {
  4999. return `[ ]*\\${p1}[ ]*`;
  5000. }
  5001. if (p2) {
  5002. return `[ ]*${p2}[ ]*`;
  5003. }
  5004. if (p3) {
  5005. return "[ ]+";
  5006. }
  5007. if (matchDiacritics) {
  5008. return p4 || p5;
  5009. }
  5010. if (p4) {
  5011. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5012. }
  5013. if (hasDiacritics) {
  5014. isUnicode = true;
  5015. return `${p5}\\p{M}*`;
  5016. }
  5017. return p5;
  5018. });
  5019. const trailingSpaces = "[ ]*";
  5020. if (query.endsWith(trailingSpaces)) {
  5021. query = query.slice(0, query.length - trailingSpaces.length);
  5022. }
  5023. if (matchDiacritics) {
  5024. if (hasDiacritics) {
  5025. isUnicode = true;
  5026. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5027. }
  5028. }
  5029. return [isUnicode, query];
  5030. }
  5031. #calculateMatch(pageIndex) {
  5032. let query = this.#query;
  5033. if (query.length === 0) {
  5034. return;
  5035. }
  5036. const {
  5037. caseSensitive,
  5038. entireWord,
  5039. phraseSearch
  5040. } = this._state;
  5041. const pageContent = this._pageContents[pageIndex];
  5042. const hasDiacritics = this._hasDiacritics[pageIndex];
  5043. let isUnicode = false;
  5044. if (phraseSearch) {
  5045. [isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics);
  5046. } else {
  5047. const match = query.match(/\S+/g);
  5048. if (match) {
  5049. query = match.sort().reverse().map(q => {
  5050. const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics);
  5051. isUnicode ||= isUnicodePart;
  5052. return `(${queryPart})`;
  5053. }).join("|");
  5054. }
  5055. }
  5056. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  5057. query = new RegExp(query, flags);
  5058. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  5059. if (this._state.highlightAll) {
  5060. this.#updatePage(pageIndex);
  5061. }
  5062. if (this._resumePageIdx === pageIndex) {
  5063. this._resumePageIdx = null;
  5064. this.#nextPageMatch();
  5065. }
  5066. const pageMatchesCount = this._pageMatches[pageIndex].length;
  5067. if (pageMatchesCount > 0) {
  5068. this._matchesCountTotal += pageMatchesCount;
  5069. this.#updateUIResultsCount();
  5070. }
  5071. }
  5072. #extractText() {
  5073. if (this._extractTextPromises.length > 0) {
  5074. return;
  5075. }
  5076. let promise = Promise.resolve();
  5077. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5078. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  5079. this._extractTextPromises[i] = extractTextCapability.promise;
  5080. promise = promise.then(() => {
  5081. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  5082. return pdfPage.getTextContent();
  5083. }).then(textContent => {
  5084. const strBuf = [];
  5085. for (const textItem of textContent.items) {
  5086. strBuf.push(textItem.str);
  5087. if (textItem.hasEOL) {
  5088. strBuf.push("\n");
  5089. }
  5090. }
  5091. [this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join(""));
  5092. extractTextCapability.resolve();
  5093. }, reason => {
  5094. console.error(`Unable to get text content for page ${i + 1}`, reason);
  5095. this._pageContents[i] = "";
  5096. this._pageDiffs[i] = null;
  5097. this._hasDiacritics[i] = false;
  5098. extractTextCapability.resolve();
  5099. });
  5100. });
  5101. }
  5102. }
  5103. #updatePage(index) {
  5104. if (this._scrollMatches && this._selected.pageIdx === index) {
  5105. this._linkService.page = index + 1;
  5106. }
  5107. this._eventBus.dispatch("updatetextlayermatches", {
  5108. source: this,
  5109. pageIndex: index
  5110. });
  5111. }
  5112. #updateAllPages() {
  5113. this._eventBus.dispatch("updatetextlayermatches", {
  5114. source: this,
  5115. pageIndex: -1
  5116. });
  5117. }
  5118. #nextMatch() {
  5119. const previous = this._state.findPrevious;
  5120. const currentPageIndex = this._linkService.page - 1;
  5121. const numPages = this._linkService.pagesCount;
  5122. this._highlightMatches = true;
  5123. if (this._dirtyMatch) {
  5124. this._dirtyMatch = false;
  5125. this._selected.pageIdx = this._selected.matchIdx = -1;
  5126. this._offset.pageIdx = currentPageIndex;
  5127. this._offset.matchIdx = null;
  5128. this._offset.wrapped = false;
  5129. this._resumePageIdx = null;
  5130. this._pageMatches.length = 0;
  5131. this._pageMatchesLength.length = 0;
  5132. this._matchesCountTotal = 0;
  5133. this.#updateAllPages();
  5134. for (let i = 0; i < numPages; i++) {
  5135. if (this._pendingFindMatches.has(i)) {
  5136. continue;
  5137. }
  5138. this._pendingFindMatches.add(i);
  5139. this._extractTextPromises[i].then(() => {
  5140. this._pendingFindMatches.delete(i);
  5141. this.#calculateMatch(i);
  5142. });
  5143. }
  5144. }
  5145. if (this.#query === "") {
  5146. this.#updateUIState(FindState.FOUND);
  5147. return;
  5148. }
  5149. if (this._resumePageIdx) {
  5150. return;
  5151. }
  5152. const offset = this._offset;
  5153. this._pagesToSearch = numPages;
  5154. if (offset.matchIdx !== null) {
  5155. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  5156. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5157. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5158. this.#updateMatch(true);
  5159. return;
  5160. }
  5161. this.#advanceOffsetPage(previous);
  5162. }
  5163. this.#nextPageMatch();
  5164. }
  5165. #matchesReady(matches) {
  5166. const offset = this._offset;
  5167. const numMatches = matches.length;
  5168. const previous = this._state.findPrevious;
  5169. if (numMatches) {
  5170. offset.matchIdx = previous ? numMatches - 1 : 0;
  5171. this.#updateMatch(true);
  5172. return true;
  5173. }
  5174. this.#advanceOffsetPage(previous);
  5175. if (offset.wrapped) {
  5176. offset.matchIdx = null;
  5177. if (this._pagesToSearch < 0) {
  5178. this.#updateMatch(false);
  5179. return true;
  5180. }
  5181. }
  5182. return false;
  5183. }
  5184. #nextPageMatch() {
  5185. if (this._resumePageIdx !== null) {
  5186. console.error("There can only be one pending page.");
  5187. }
  5188. let matches = null;
  5189. do {
  5190. const pageIdx = this._offset.pageIdx;
  5191. matches = this._pageMatches[pageIdx];
  5192. if (!matches) {
  5193. this._resumePageIdx = pageIdx;
  5194. break;
  5195. }
  5196. } while (!this.#matchesReady(matches));
  5197. }
  5198. #advanceOffsetPage(previous) {
  5199. const offset = this._offset;
  5200. const numPages = this._linkService.pagesCount;
  5201. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5202. offset.matchIdx = null;
  5203. this._pagesToSearch--;
  5204. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5205. offset.pageIdx = previous ? numPages - 1 : 0;
  5206. offset.wrapped = true;
  5207. }
  5208. }
  5209. #updateMatch(found = false) {
  5210. let state = FindState.NOT_FOUND;
  5211. const wrapped = this._offset.wrapped;
  5212. this._offset.wrapped = false;
  5213. if (found) {
  5214. const previousPage = this._selected.pageIdx;
  5215. this._selected.pageIdx = this._offset.pageIdx;
  5216. this._selected.matchIdx = this._offset.matchIdx;
  5217. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5218. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5219. this.#updatePage(previousPage);
  5220. }
  5221. }
  5222. this.#updateUIState(state, this._state.findPrevious);
  5223. if (this._selected.pageIdx !== -1) {
  5224. this._scrollMatches = true;
  5225. this.#updatePage(this._selected.pageIdx);
  5226. }
  5227. }
  5228. #onFindBarClose(evt) {
  5229. const pdfDocument = this._pdfDocument;
  5230. this._firstPageCapability.promise.then(() => {
  5231. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  5232. return;
  5233. }
  5234. if (this._findTimeout) {
  5235. clearTimeout(this._findTimeout);
  5236. this._findTimeout = null;
  5237. }
  5238. if (this._resumePageIdx) {
  5239. this._resumePageIdx = null;
  5240. this._dirtyMatch = true;
  5241. }
  5242. this.#updateUIState(FindState.FOUND);
  5243. this._highlightMatches = false;
  5244. this.#updateAllPages();
  5245. });
  5246. }
  5247. #requestMatchesCount() {
  5248. const {
  5249. pageIdx,
  5250. matchIdx
  5251. } = this._selected;
  5252. let current = 0,
  5253. total = this._matchesCountTotal;
  5254. if (matchIdx !== -1) {
  5255. for (let i = 0; i < pageIdx; i++) {
  5256. current += this._pageMatches[i]?.length || 0;
  5257. }
  5258. current += matchIdx + 1;
  5259. }
  5260. if (current < 1 || current > total) {
  5261. current = total = 0;
  5262. }
  5263. return {
  5264. current,
  5265. total
  5266. };
  5267. }
  5268. #updateUIResultsCount() {
  5269. this._eventBus.dispatch("updatefindmatchescount", {
  5270. source: this,
  5271. matchesCount: this.#requestMatchesCount()
  5272. });
  5273. }
  5274. #updateUIState(state, previous = false) {
  5275. this._eventBus.dispatch("updatefindcontrolstate", {
  5276. source: this,
  5277. state,
  5278. previous,
  5279. matchesCount: this.#requestMatchesCount(),
  5280. rawQuery: this._state?.query ?? null
  5281. });
  5282. }
  5283. }
  5284. exports.PDFFindController = PDFFindController;
  5285. /***/ }),
  5286. /* 17 */
  5287. /***/ ((__unused_webpack_module, exports) => {
  5288. Object.defineProperty(exports, "__esModule", ({
  5289. value: true
  5290. }));
  5291. exports.CharacterType = void 0;
  5292. exports.getCharacterType = getCharacterType;
  5293. const CharacterType = {
  5294. SPACE: 0,
  5295. ALPHA_LETTER: 1,
  5296. PUNCT: 2,
  5297. HAN_LETTER: 3,
  5298. KATAKANA_LETTER: 4,
  5299. HIRAGANA_LETTER: 5,
  5300. HALFWIDTH_KATAKANA_LETTER: 6,
  5301. THAI_LETTER: 7
  5302. };
  5303. exports.CharacterType = CharacterType;
  5304. function isAlphabeticalScript(charCode) {
  5305. return charCode < 0x2e80;
  5306. }
  5307. function isAscii(charCode) {
  5308. return (charCode & 0xff80) === 0;
  5309. }
  5310. function isAsciiAlpha(charCode) {
  5311. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  5312. }
  5313. function isAsciiDigit(charCode) {
  5314. return charCode >= 0x30 && charCode <= 0x39;
  5315. }
  5316. function isAsciiSpace(charCode) {
  5317. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  5318. }
  5319. function isHan(charCode) {
  5320. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  5321. }
  5322. function isKatakana(charCode) {
  5323. return charCode >= 0x30a0 && charCode <= 0x30ff;
  5324. }
  5325. function isHiragana(charCode) {
  5326. return charCode >= 0x3040 && charCode <= 0x309f;
  5327. }
  5328. function isHalfwidthKatakana(charCode) {
  5329. return charCode >= 0xff60 && charCode <= 0xff9f;
  5330. }
  5331. function isThai(charCode) {
  5332. return (charCode & 0xff80) === 0x0e00;
  5333. }
  5334. function getCharacterType(charCode) {
  5335. if (isAlphabeticalScript(charCode)) {
  5336. if (isAscii(charCode)) {
  5337. if (isAsciiSpace(charCode)) {
  5338. return CharacterType.SPACE;
  5339. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  5340. return CharacterType.ALPHA_LETTER;
  5341. }
  5342. return CharacterType.PUNCT;
  5343. } else if (isThai(charCode)) {
  5344. return CharacterType.THAI_LETTER;
  5345. } else if (charCode === 0xa0) {
  5346. return CharacterType.SPACE;
  5347. }
  5348. return CharacterType.ALPHA_LETTER;
  5349. }
  5350. if (isHan(charCode)) {
  5351. return CharacterType.HAN_LETTER;
  5352. } else if (isKatakana(charCode)) {
  5353. return CharacterType.KATAKANA_LETTER;
  5354. } else if (isHiragana(charCode)) {
  5355. return CharacterType.HIRAGANA_LETTER;
  5356. } else if (isHalfwidthKatakana(charCode)) {
  5357. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5358. }
  5359. return CharacterType.ALPHA_LETTER;
  5360. }
  5361. /***/ }),
  5362. /* 18 */
  5363. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5364. Object.defineProperty(exports, "__esModule", ({
  5365. value: true
  5366. }));
  5367. exports.PDFHistory = void 0;
  5368. exports.isDestArraysEqual = isDestArraysEqual;
  5369. exports.isDestHashesEqual = isDestHashesEqual;
  5370. var _ui_utils = __webpack_require__(1);
  5371. var _event_utils = __webpack_require__(6);
  5372. const HASH_CHANGE_TIMEOUT = 1000;
  5373. const POSITION_UPDATED_THRESHOLD = 50;
  5374. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5375. function getCurrentHash() {
  5376. return document.location.hash;
  5377. }
  5378. class PDFHistory {
  5379. constructor({
  5380. linkService,
  5381. eventBus
  5382. }) {
  5383. this.linkService = linkService;
  5384. this.eventBus = eventBus;
  5385. this._initialized = false;
  5386. this._fingerprint = "";
  5387. this.reset();
  5388. this._boundEvents = null;
  5389. this.eventBus._on("pagesinit", () => {
  5390. this._isPagesLoaded = false;
  5391. this.eventBus._on("pagesloaded", evt => {
  5392. this._isPagesLoaded = !!evt.pagesCount;
  5393. }, {
  5394. once: true
  5395. });
  5396. });
  5397. }
  5398. initialize({
  5399. fingerprint,
  5400. resetHistory = false,
  5401. updateUrl = false
  5402. }) {
  5403. if (!fingerprint || typeof fingerprint !== "string") {
  5404. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5405. return;
  5406. }
  5407. if (this._initialized) {
  5408. this.reset();
  5409. }
  5410. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5411. this._fingerprint = fingerprint;
  5412. this._updateUrl = updateUrl === true;
  5413. this._initialized = true;
  5414. this._bindEvents();
  5415. const state = window.history.state;
  5416. this._popStateInProgress = false;
  5417. this._blockHashChange = 0;
  5418. this._currentHash = getCurrentHash();
  5419. this._numPositionUpdates = 0;
  5420. this._uid = this._maxUid = 0;
  5421. this._destination = null;
  5422. this._position = null;
  5423. if (!this._isValidState(state, true) || resetHistory) {
  5424. const {
  5425. hash,
  5426. page,
  5427. rotation
  5428. } = this._parseCurrentHash(true);
  5429. if (!hash || reInitialized || resetHistory) {
  5430. this._pushOrReplaceState(null, true);
  5431. return;
  5432. }
  5433. this._pushOrReplaceState({
  5434. hash,
  5435. page,
  5436. rotation
  5437. }, true);
  5438. return;
  5439. }
  5440. const destination = state.destination;
  5441. this._updateInternalState(destination, state.uid, true);
  5442. if (destination.rotation !== undefined) {
  5443. this._initialRotation = destination.rotation;
  5444. }
  5445. if (destination.dest) {
  5446. this._initialBookmark = JSON.stringify(destination.dest);
  5447. this._destination.page = null;
  5448. } else if (destination.hash) {
  5449. this._initialBookmark = destination.hash;
  5450. } else if (destination.page) {
  5451. this._initialBookmark = `page=${destination.page}`;
  5452. }
  5453. }
  5454. reset() {
  5455. if (this._initialized) {
  5456. this._pageHide();
  5457. this._initialized = false;
  5458. this._unbindEvents();
  5459. }
  5460. if (this._updateViewareaTimeout) {
  5461. clearTimeout(this._updateViewareaTimeout);
  5462. this._updateViewareaTimeout = null;
  5463. }
  5464. this._initialBookmark = null;
  5465. this._initialRotation = null;
  5466. }
  5467. push({
  5468. namedDest = null,
  5469. explicitDest,
  5470. pageNumber
  5471. }) {
  5472. if (!this._initialized) {
  5473. return;
  5474. }
  5475. if (namedDest && typeof namedDest !== "string") {
  5476. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5477. return;
  5478. } else if (!Array.isArray(explicitDest)) {
  5479. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5480. return;
  5481. } else if (!this._isValidPage(pageNumber)) {
  5482. if (pageNumber !== null || this._destination) {
  5483. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5484. return;
  5485. }
  5486. }
  5487. const hash = namedDest || JSON.stringify(explicitDest);
  5488. if (!hash) {
  5489. return;
  5490. }
  5491. let forceReplace = false;
  5492. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5493. if (this._destination.page) {
  5494. return;
  5495. }
  5496. forceReplace = true;
  5497. }
  5498. if (this._popStateInProgress && !forceReplace) {
  5499. return;
  5500. }
  5501. this._pushOrReplaceState({
  5502. dest: explicitDest,
  5503. hash,
  5504. page: pageNumber,
  5505. rotation: this.linkService.rotation
  5506. }, forceReplace);
  5507. if (!this._popStateInProgress) {
  5508. this._popStateInProgress = true;
  5509. Promise.resolve().then(() => {
  5510. this._popStateInProgress = false;
  5511. });
  5512. }
  5513. }
  5514. pushPage(pageNumber) {
  5515. if (!this._initialized) {
  5516. return;
  5517. }
  5518. if (!this._isValidPage(pageNumber)) {
  5519. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5520. return;
  5521. }
  5522. if (this._destination?.page === pageNumber) {
  5523. return;
  5524. }
  5525. if (this._popStateInProgress) {
  5526. return;
  5527. }
  5528. this._pushOrReplaceState({
  5529. dest: null,
  5530. hash: `page=${pageNumber}`,
  5531. page: pageNumber,
  5532. rotation: this.linkService.rotation
  5533. });
  5534. if (!this._popStateInProgress) {
  5535. this._popStateInProgress = true;
  5536. Promise.resolve().then(() => {
  5537. this._popStateInProgress = false;
  5538. });
  5539. }
  5540. }
  5541. pushCurrentPosition() {
  5542. if (!this._initialized || this._popStateInProgress) {
  5543. return;
  5544. }
  5545. this._tryPushCurrentPosition();
  5546. }
  5547. back() {
  5548. if (!this._initialized || this._popStateInProgress) {
  5549. return;
  5550. }
  5551. const state = window.history.state;
  5552. if (this._isValidState(state) && state.uid > 0) {
  5553. window.history.back();
  5554. }
  5555. }
  5556. forward() {
  5557. if (!this._initialized || this._popStateInProgress) {
  5558. return;
  5559. }
  5560. const state = window.history.state;
  5561. if (this._isValidState(state) && state.uid < this._maxUid) {
  5562. window.history.forward();
  5563. }
  5564. }
  5565. get popStateInProgress() {
  5566. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5567. }
  5568. get initialBookmark() {
  5569. return this._initialized ? this._initialBookmark : null;
  5570. }
  5571. get initialRotation() {
  5572. return this._initialized ? this._initialRotation : null;
  5573. }
  5574. _pushOrReplaceState(destination, forceReplace = false) {
  5575. const shouldReplace = forceReplace || !this._destination;
  5576. const newState = {
  5577. fingerprint: this._fingerprint,
  5578. uid: shouldReplace ? this._uid : this._uid + 1,
  5579. destination
  5580. };
  5581. this._updateInternalState(destination, newState.uid);
  5582. let newUrl;
  5583. if (this._updateUrl && destination?.hash) {
  5584. const baseUrl = document.location.href.split("#")[0];
  5585. if (!baseUrl.startsWith("file://")) {
  5586. newUrl = `${baseUrl}#${destination.hash}`;
  5587. }
  5588. }
  5589. if (shouldReplace) {
  5590. window.history.replaceState(newState, "", newUrl);
  5591. } else {
  5592. window.history.pushState(newState, "", newUrl);
  5593. }
  5594. }
  5595. _tryPushCurrentPosition(temporary = false) {
  5596. if (!this._position) {
  5597. return;
  5598. }
  5599. let position = this._position;
  5600. if (temporary) {
  5601. position = Object.assign(Object.create(null), this._position);
  5602. position.temporary = true;
  5603. }
  5604. if (!this._destination) {
  5605. this._pushOrReplaceState(position);
  5606. return;
  5607. }
  5608. if (this._destination.temporary) {
  5609. this._pushOrReplaceState(position, true);
  5610. return;
  5611. }
  5612. if (this._destination.hash === position.hash) {
  5613. return;
  5614. }
  5615. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5616. return;
  5617. }
  5618. let forceReplace = false;
  5619. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5620. if (this._destination.dest !== undefined || !this._destination.first) {
  5621. return;
  5622. }
  5623. forceReplace = true;
  5624. }
  5625. this._pushOrReplaceState(position, forceReplace);
  5626. }
  5627. _isValidPage(val) {
  5628. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5629. }
  5630. _isValidState(state, checkReload = false) {
  5631. if (!state) {
  5632. return false;
  5633. }
  5634. if (state.fingerprint !== this._fingerprint) {
  5635. if (checkReload) {
  5636. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5637. return false;
  5638. }
  5639. const [perfEntry] = performance.getEntriesByType("navigation");
  5640. if (perfEntry?.type !== "reload") {
  5641. return false;
  5642. }
  5643. } else {
  5644. return false;
  5645. }
  5646. }
  5647. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5648. return false;
  5649. }
  5650. if (state.destination === null || typeof state.destination !== "object") {
  5651. return false;
  5652. }
  5653. return true;
  5654. }
  5655. _updateInternalState(destination, uid, removeTemporary = false) {
  5656. if (this._updateViewareaTimeout) {
  5657. clearTimeout(this._updateViewareaTimeout);
  5658. this._updateViewareaTimeout = null;
  5659. }
  5660. if (removeTemporary && destination?.temporary) {
  5661. delete destination.temporary;
  5662. }
  5663. this._destination = destination;
  5664. this._uid = uid;
  5665. this._maxUid = Math.max(this._maxUid, uid);
  5666. this._numPositionUpdates = 0;
  5667. }
  5668. _parseCurrentHash(checkNameddest = false) {
  5669. const hash = unescape(getCurrentHash()).substring(1);
  5670. const params = (0, _ui_utils.parseQueryString)(hash);
  5671. const nameddest = params.get("nameddest") || "";
  5672. let page = params.get("page") | 0;
  5673. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5674. page = null;
  5675. }
  5676. return {
  5677. hash,
  5678. page,
  5679. rotation: this.linkService.rotation
  5680. };
  5681. }
  5682. _updateViewarea({
  5683. location
  5684. }) {
  5685. if (this._updateViewareaTimeout) {
  5686. clearTimeout(this._updateViewareaTimeout);
  5687. this._updateViewareaTimeout = null;
  5688. }
  5689. this._position = {
  5690. hash: location.pdfOpenParams.substring(1),
  5691. page: this.linkService.page,
  5692. first: location.pageNumber,
  5693. rotation: location.rotation
  5694. };
  5695. if (this._popStateInProgress) {
  5696. return;
  5697. }
  5698. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5699. this._numPositionUpdates++;
  5700. }
  5701. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5702. this._updateViewareaTimeout = setTimeout(() => {
  5703. if (!this._popStateInProgress) {
  5704. this._tryPushCurrentPosition(true);
  5705. }
  5706. this._updateViewareaTimeout = null;
  5707. }, UPDATE_VIEWAREA_TIMEOUT);
  5708. }
  5709. }
  5710. _popState({
  5711. state
  5712. }) {
  5713. const newHash = getCurrentHash(),
  5714. hashChanged = this._currentHash !== newHash;
  5715. this._currentHash = newHash;
  5716. if (!state) {
  5717. this._uid++;
  5718. const {
  5719. hash,
  5720. page,
  5721. rotation
  5722. } = this._parseCurrentHash();
  5723. this._pushOrReplaceState({
  5724. hash,
  5725. page,
  5726. rotation
  5727. }, true);
  5728. return;
  5729. }
  5730. if (!this._isValidState(state)) {
  5731. return;
  5732. }
  5733. this._popStateInProgress = true;
  5734. if (hashChanged) {
  5735. this._blockHashChange++;
  5736. (0, _event_utils.waitOnEventOrTimeout)({
  5737. target: window,
  5738. name: "hashchange",
  5739. delay: HASH_CHANGE_TIMEOUT
  5740. }).then(() => {
  5741. this._blockHashChange--;
  5742. });
  5743. }
  5744. const destination = state.destination;
  5745. this._updateInternalState(destination, state.uid, true);
  5746. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5747. this.linkService.rotation = destination.rotation;
  5748. }
  5749. if (destination.dest) {
  5750. this.linkService.goToDestination(destination.dest);
  5751. } else if (destination.hash) {
  5752. this.linkService.setHash(destination.hash);
  5753. } else if (destination.page) {
  5754. this.linkService.page = destination.page;
  5755. }
  5756. Promise.resolve().then(() => {
  5757. this._popStateInProgress = false;
  5758. });
  5759. }
  5760. _pageHide() {
  5761. if (!this._destination || this._destination.temporary) {
  5762. this._tryPushCurrentPosition();
  5763. }
  5764. }
  5765. _bindEvents() {
  5766. if (this._boundEvents) {
  5767. return;
  5768. }
  5769. this._boundEvents = {
  5770. updateViewarea: this._updateViewarea.bind(this),
  5771. popState: this._popState.bind(this),
  5772. pageHide: this._pageHide.bind(this)
  5773. };
  5774. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5775. window.addEventListener("popstate", this._boundEvents.popState);
  5776. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5777. }
  5778. _unbindEvents() {
  5779. if (!this._boundEvents) {
  5780. return;
  5781. }
  5782. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5783. window.removeEventListener("popstate", this._boundEvents.popState);
  5784. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5785. this._boundEvents = null;
  5786. }
  5787. }
  5788. exports.PDFHistory = PDFHistory;
  5789. function isDestHashesEqual(destHash, pushHash) {
  5790. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5791. return false;
  5792. }
  5793. if (destHash === pushHash) {
  5794. return true;
  5795. }
  5796. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
  5797. if (nameddest === pushHash) {
  5798. return true;
  5799. }
  5800. return false;
  5801. }
  5802. function isDestArraysEqual(firstDest, secondDest) {
  5803. function isEntryEqual(first, second) {
  5804. if (typeof first !== typeof second) {
  5805. return false;
  5806. }
  5807. if (Array.isArray(first) || Array.isArray(second)) {
  5808. return false;
  5809. }
  5810. if (first !== null && typeof first === "object" && second !== null) {
  5811. if (Object.keys(first).length !== Object.keys(second).length) {
  5812. return false;
  5813. }
  5814. for (const key in first) {
  5815. if (!isEntryEqual(first[key], second[key])) {
  5816. return false;
  5817. }
  5818. }
  5819. return true;
  5820. }
  5821. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5822. }
  5823. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5824. return false;
  5825. }
  5826. if (firstDest.length !== secondDest.length) {
  5827. return false;
  5828. }
  5829. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5830. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5831. return false;
  5832. }
  5833. }
  5834. return true;
  5835. }
  5836. /***/ }),
  5837. /* 19 */
  5838. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5839. Object.defineProperty(exports, "__esModule", ({
  5840. value: true
  5841. }));
  5842. exports.PDFLayerViewer = void 0;
  5843. var _base_tree_viewer = __webpack_require__(13);
  5844. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5845. constructor(options) {
  5846. super(options);
  5847. this.l10n = options.l10n;
  5848. this.eventBus._on("optionalcontentconfigchanged", evt => {
  5849. this.#updateLayers(evt.promise);
  5850. });
  5851. this.eventBus._on("resetlayers", () => {
  5852. this.#updateLayers();
  5853. });
  5854. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5855. }
  5856. reset() {
  5857. super.reset();
  5858. this._optionalContentConfig = null;
  5859. this._optionalContentHash = null;
  5860. }
  5861. _dispatchEvent(layersCount) {
  5862. this.eventBus.dispatch("layersloaded", {
  5863. source: this,
  5864. layersCount
  5865. });
  5866. }
  5867. _bindLink(element, {
  5868. groupId,
  5869. input
  5870. }) {
  5871. const setVisibility = () => {
  5872. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5873. this._optionalContentHash = this._optionalContentConfig.getHash();
  5874. this.eventBus.dispatch("optionalcontentconfig", {
  5875. source: this,
  5876. promise: Promise.resolve(this._optionalContentConfig)
  5877. });
  5878. };
  5879. element.onclick = evt => {
  5880. if (evt.target === input) {
  5881. setVisibility();
  5882. return true;
  5883. } else if (evt.target !== element) {
  5884. return true;
  5885. }
  5886. input.checked = !input.checked;
  5887. setVisibility();
  5888. return false;
  5889. };
  5890. }
  5891. async _setNestedName(element, {
  5892. name = null
  5893. }) {
  5894. if (typeof name === "string") {
  5895. element.textContent = this._normalizeTextContent(name);
  5896. return;
  5897. }
  5898. element.textContent = await this.l10n.get("additional_layers");
  5899. element.style.fontStyle = "italic";
  5900. }
  5901. _addToggleButton(div, {
  5902. name = null
  5903. }) {
  5904. super._addToggleButton(div, name === null);
  5905. }
  5906. _toggleAllTreeItems() {
  5907. if (!this._optionalContentConfig) {
  5908. return;
  5909. }
  5910. super._toggleAllTreeItems();
  5911. }
  5912. render({
  5913. optionalContentConfig,
  5914. pdfDocument
  5915. }) {
  5916. if (this._optionalContentConfig) {
  5917. this.reset();
  5918. }
  5919. this._optionalContentConfig = optionalContentConfig || null;
  5920. this._pdfDocument = pdfDocument || null;
  5921. const groups = optionalContentConfig?.getOrder();
  5922. if (!groups) {
  5923. this._dispatchEvent(0);
  5924. return;
  5925. }
  5926. this._optionalContentHash = optionalContentConfig.getHash();
  5927. const fragment = document.createDocumentFragment(),
  5928. queue = [{
  5929. parent: fragment,
  5930. groups
  5931. }];
  5932. let layersCount = 0,
  5933. hasAnyNesting = false;
  5934. while (queue.length > 0) {
  5935. const levelData = queue.shift();
  5936. for (const groupId of levelData.groups) {
  5937. const div = document.createElement("div");
  5938. div.className = "treeItem";
  5939. const element = document.createElement("a");
  5940. div.append(element);
  5941. if (typeof groupId === "object") {
  5942. hasAnyNesting = true;
  5943. this._addToggleButton(div, groupId);
  5944. this._setNestedName(element, groupId);
  5945. const itemsDiv = document.createElement("div");
  5946. itemsDiv.className = "treeItems";
  5947. div.append(itemsDiv);
  5948. queue.push({
  5949. parent: itemsDiv,
  5950. groups: groupId.order
  5951. });
  5952. } else {
  5953. const group = optionalContentConfig.getGroup(groupId);
  5954. const input = document.createElement("input");
  5955. this._bindLink(element, {
  5956. groupId,
  5957. input
  5958. });
  5959. input.type = "checkbox";
  5960. input.checked = group.visible;
  5961. const label = document.createElement("label");
  5962. label.textContent = this._normalizeTextContent(group.name);
  5963. label.append(input);
  5964. element.append(label);
  5965. layersCount++;
  5966. }
  5967. levelData.parent.append(div);
  5968. }
  5969. }
  5970. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5971. }
  5972. async #updateLayers(promise = null) {
  5973. if (!this._optionalContentConfig) {
  5974. return;
  5975. }
  5976. const pdfDocument = this._pdfDocument;
  5977. const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig());
  5978. if (pdfDocument !== this._pdfDocument) {
  5979. return;
  5980. }
  5981. if (promise) {
  5982. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  5983. return;
  5984. }
  5985. } else {
  5986. this.eventBus.dispatch("optionalcontentconfig", {
  5987. source: this,
  5988. promise: Promise.resolve(optionalContentConfig)
  5989. });
  5990. }
  5991. this.render({
  5992. optionalContentConfig,
  5993. pdfDocument: this._pdfDocument
  5994. });
  5995. }
  5996. }
  5997. exports.PDFLayerViewer = PDFLayerViewer;
  5998. /***/ }),
  5999. /* 20 */
  6000. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6001. Object.defineProperty(exports, "__esModule", ({
  6002. value: true
  6003. }));
  6004. exports.PDFOutlineViewer = void 0;
  6005. var _base_tree_viewer = __webpack_require__(13);
  6006. var _pdfjsLib = __webpack_require__(5);
  6007. var _ui_utils = __webpack_require__(1);
  6008. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  6009. constructor(options) {
  6010. super(options);
  6011. this.linkService = options.linkService;
  6012. this.downloadManager = options.downloadManager;
  6013. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  6014. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  6015. this.eventBus._on("pagechanging", evt => {
  6016. this._currentPageNumber = evt.pageNumber;
  6017. });
  6018. this.eventBus._on("pagesloaded", evt => {
  6019. this._isPagesLoaded = !!evt.pagesCount;
  6020. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6021. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6022. }
  6023. });
  6024. this.eventBus._on("sidebarviewchanged", evt => {
  6025. this._sidebarView = evt.view;
  6026. });
  6027. }
  6028. reset() {
  6029. super.reset();
  6030. this._outline = null;
  6031. this._pageNumberToDestHashCapability = null;
  6032. this._currentPageNumber = 1;
  6033. this._isPagesLoaded = null;
  6034. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  6035. this._currentOutlineItemCapability.resolve(false);
  6036. }
  6037. this._currentOutlineItemCapability = null;
  6038. }
  6039. _dispatchEvent(outlineCount) {
  6040. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  6041. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  6042. this._currentOutlineItemCapability.resolve(false);
  6043. } else if (this._isPagesLoaded !== null) {
  6044. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  6045. }
  6046. this.eventBus.dispatch("outlineloaded", {
  6047. source: this,
  6048. outlineCount,
  6049. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  6050. });
  6051. }
  6052. _bindLink(element, {
  6053. url,
  6054. newWindow,
  6055. action,
  6056. attachment,
  6057. dest,
  6058. setOCGState
  6059. }) {
  6060. const {
  6061. linkService
  6062. } = this;
  6063. if (url) {
  6064. linkService.addLinkAttributes(element, url, newWindow);
  6065. return;
  6066. }
  6067. if (action) {
  6068. element.href = linkService.getAnchorUrl("");
  6069. element.onclick = () => {
  6070. linkService.executeNamedAction(action);
  6071. return false;
  6072. };
  6073. return;
  6074. }
  6075. if (attachment) {
  6076. element.href = linkService.getAnchorUrl("");
  6077. element.onclick = () => {
  6078. this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename);
  6079. return false;
  6080. };
  6081. return;
  6082. }
  6083. if (setOCGState) {
  6084. element.href = linkService.getAnchorUrl("");
  6085. element.onclick = () => {
  6086. linkService.executeSetOCGState(setOCGState);
  6087. return false;
  6088. };
  6089. return;
  6090. }
  6091. element.href = linkService.getDestinationHash(dest);
  6092. element.onclick = evt => {
  6093. this._updateCurrentTreeItem(evt.target.parentNode);
  6094. if (dest) {
  6095. linkService.goToDestination(dest);
  6096. }
  6097. return false;
  6098. };
  6099. }
  6100. _setStyles(element, {
  6101. bold,
  6102. italic
  6103. }) {
  6104. if (bold) {
  6105. element.style.fontWeight = "bold";
  6106. }
  6107. if (italic) {
  6108. element.style.fontStyle = "italic";
  6109. }
  6110. }
  6111. _addToggleButton(div, {
  6112. count,
  6113. items
  6114. }) {
  6115. let hidden = false;
  6116. if (count < 0) {
  6117. let totalCount = items.length;
  6118. if (totalCount > 0) {
  6119. const queue = [...items];
  6120. while (queue.length > 0) {
  6121. const {
  6122. count: nestedCount,
  6123. items: nestedItems
  6124. } = queue.shift();
  6125. if (nestedCount > 0 && nestedItems.length > 0) {
  6126. totalCount += nestedItems.length;
  6127. queue.push(...nestedItems);
  6128. }
  6129. }
  6130. }
  6131. if (Math.abs(count) === totalCount) {
  6132. hidden = true;
  6133. }
  6134. }
  6135. super._addToggleButton(div, hidden);
  6136. }
  6137. _toggleAllTreeItems() {
  6138. if (!this._outline) {
  6139. return;
  6140. }
  6141. super._toggleAllTreeItems();
  6142. }
  6143. render({
  6144. outline,
  6145. pdfDocument
  6146. }) {
  6147. if (this._outline) {
  6148. this.reset();
  6149. }
  6150. this._outline = outline || null;
  6151. this._pdfDocument = pdfDocument || null;
  6152. if (!outline) {
  6153. this._dispatchEvent(0);
  6154. return;
  6155. }
  6156. const fragment = document.createDocumentFragment();
  6157. const queue = [{
  6158. parent: fragment,
  6159. items: outline
  6160. }];
  6161. let outlineCount = 0,
  6162. hasAnyNesting = false;
  6163. while (queue.length > 0) {
  6164. const levelData = queue.shift();
  6165. for (const item of levelData.items) {
  6166. const div = document.createElement("div");
  6167. div.className = "treeItem";
  6168. const element = document.createElement("a");
  6169. this._bindLink(element, item);
  6170. this._setStyles(element, item);
  6171. element.textContent = this._normalizeTextContent(item.title);
  6172. div.append(element);
  6173. if (item.items.length > 0) {
  6174. hasAnyNesting = true;
  6175. this._addToggleButton(div, item);
  6176. const itemsDiv = document.createElement("div");
  6177. itemsDiv.className = "treeItems";
  6178. div.append(itemsDiv);
  6179. queue.push({
  6180. parent: itemsDiv,
  6181. items: item.items
  6182. });
  6183. }
  6184. levelData.parent.append(div);
  6185. outlineCount++;
  6186. }
  6187. }
  6188. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6189. }
  6190. async _currentOutlineItem() {
  6191. if (!this._isPagesLoaded) {
  6192. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6193. }
  6194. if (!this._outline || !this._pdfDocument) {
  6195. return;
  6196. }
  6197. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6198. if (!pageNumberToDestHash) {
  6199. return;
  6200. }
  6201. this._updateCurrentTreeItem(null);
  6202. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6203. return;
  6204. }
  6205. for (let i = this._currentPageNumber; i > 0; i--) {
  6206. const destHash = pageNumberToDestHash.get(i);
  6207. if (!destHash) {
  6208. continue;
  6209. }
  6210. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6211. if (!linkElement) {
  6212. continue;
  6213. }
  6214. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6215. break;
  6216. }
  6217. }
  6218. async _getPageNumberToDestHash(pdfDocument) {
  6219. if (this._pageNumberToDestHashCapability) {
  6220. return this._pageNumberToDestHashCapability.promise;
  6221. }
  6222. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6223. const pageNumberToDestHash = new Map(),
  6224. pageNumberNesting = new Map();
  6225. const queue = [{
  6226. nesting: 0,
  6227. items: this._outline
  6228. }];
  6229. while (queue.length > 0) {
  6230. const levelData = queue.shift(),
  6231. currentNesting = levelData.nesting;
  6232. for (const {
  6233. dest,
  6234. items
  6235. } of levelData.items) {
  6236. let explicitDest, pageNumber;
  6237. if (typeof dest === "string") {
  6238. explicitDest = await pdfDocument.getDestination(dest);
  6239. if (pdfDocument !== this._pdfDocument) {
  6240. return null;
  6241. }
  6242. } else {
  6243. explicitDest = dest;
  6244. }
  6245. if (Array.isArray(explicitDest)) {
  6246. const [destRef] = explicitDest;
  6247. if (typeof destRef === "object" && destRef !== null) {
  6248. pageNumber = this.linkService._cachedPageNumber(destRef);
  6249. if (!pageNumber) {
  6250. try {
  6251. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6252. if (pdfDocument !== this._pdfDocument) {
  6253. return null;
  6254. }
  6255. this.linkService.cachePageRef(pageNumber, destRef);
  6256. } catch (ex) {}
  6257. }
  6258. } else if (Number.isInteger(destRef)) {
  6259. pageNumber = destRef + 1;
  6260. }
  6261. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6262. const destHash = this.linkService.getDestinationHash(dest);
  6263. pageNumberToDestHash.set(pageNumber, destHash);
  6264. pageNumberNesting.set(pageNumber, currentNesting);
  6265. }
  6266. }
  6267. if (items.length > 0) {
  6268. queue.push({
  6269. nesting: currentNesting + 1,
  6270. items
  6271. });
  6272. }
  6273. }
  6274. }
  6275. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6276. return this._pageNumberToDestHashCapability.promise;
  6277. }
  6278. }
  6279. exports.PDFOutlineViewer = PDFOutlineViewer;
  6280. /***/ }),
  6281. /* 21 */
  6282. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6283. Object.defineProperty(exports, "__esModule", ({
  6284. value: true
  6285. }));
  6286. exports.PDFPresentationMode = void 0;
  6287. var _ui_utils = __webpack_require__(1);
  6288. var _pdfjsLib = __webpack_require__(5);
  6289. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6290. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6291. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6292. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6293. const PAGE_SWITCH_THRESHOLD = 0.1;
  6294. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6295. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6296. class PDFPresentationMode {
  6297. #state = _ui_utils.PresentationModeState.UNKNOWN;
  6298. #args = null;
  6299. constructor({
  6300. container,
  6301. pdfViewer,
  6302. eventBus
  6303. }) {
  6304. this.container = container;
  6305. this.pdfViewer = pdfViewer;
  6306. this.eventBus = eventBus;
  6307. this.contextMenuOpen = false;
  6308. this.mouseScrollTimeStamp = 0;
  6309. this.mouseScrollDelta = 0;
  6310. this.touchSwipeState = null;
  6311. }
  6312. async request() {
  6313. const {
  6314. container,
  6315. pdfViewer
  6316. } = this;
  6317. if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
  6318. return false;
  6319. }
  6320. this.#addFullscreenChangeListeners();
  6321. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  6322. const promise = container.requestFullscreen();
  6323. this.#args = {
  6324. pageNumber: pdfViewer.currentPageNumber,
  6325. scaleValue: pdfViewer.currentScaleValue,
  6326. scrollMode: pdfViewer.scrollMode,
  6327. spreadMode: null,
  6328. annotationEditorMode: null
  6329. };
  6330. if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
  6331. console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
  6332. this.#args.spreadMode = pdfViewer.spreadMode;
  6333. }
  6334. if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  6335. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  6336. }
  6337. try {
  6338. await promise;
  6339. pdfViewer.focus();
  6340. return true;
  6341. } catch (reason) {
  6342. this.#removeFullscreenChangeListeners();
  6343. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6344. }
  6345. return false;
  6346. }
  6347. get active() {
  6348. return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
  6349. }
  6350. #mouseWheel(evt) {
  6351. if (!this.active) {
  6352. return;
  6353. }
  6354. evt.preventDefault();
  6355. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6356. const currentTime = Date.now();
  6357. const storedTime = this.mouseScrollTimeStamp;
  6358. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6359. return;
  6360. }
  6361. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6362. this.#resetMouseScrollState();
  6363. }
  6364. this.mouseScrollDelta += delta;
  6365. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6366. const totalDelta = this.mouseScrollDelta;
  6367. this.#resetMouseScrollState();
  6368. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6369. if (success) {
  6370. this.mouseScrollTimeStamp = currentTime;
  6371. }
  6372. }
  6373. }
  6374. #notifyStateChange(state) {
  6375. this.#state = state;
  6376. this.eventBus.dispatch("presentationmodechanged", {
  6377. source: this,
  6378. state
  6379. });
  6380. }
  6381. #enter() {
  6382. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  6383. this.container.classList.add(ACTIVE_SELECTOR);
  6384. setTimeout(() => {
  6385. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  6386. if (this.#args.spreadMode !== null) {
  6387. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  6388. }
  6389. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  6390. this.pdfViewer.currentScaleValue = "page-fit";
  6391. if (this.#args.annotationEditorMode !== null) {
  6392. this.pdfViewer.annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  6393. }
  6394. }, 0);
  6395. this.#addWindowListeners();
  6396. this.#showControls();
  6397. this.contextMenuOpen = false;
  6398. window.getSelection().removeAllRanges();
  6399. }
  6400. #exit() {
  6401. const pageNumber = this.pdfViewer.currentPageNumber;
  6402. this.container.classList.remove(ACTIVE_SELECTOR);
  6403. setTimeout(() => {
  6404. this.#removeFullscreenChangeListeners();
  6405. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  6406. this.pdfViewer.scrollMode = this.#args.scrollMode;
  6407. if (this.#args.spreadMode !== null) {
  6408. this.pdfViewer.spreadMode = this.#args.spreadMode;
  6409. }
  6410. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  6411. this.pdfViewer.currentPageNumber = pageNumber;
  6412. if (this.#args.annotationEditorMode !== null) {
  6413. this.pdfViewer.annotationEditorMode = this.#args.annotationEditorMode;
  6414. }
  6415. this.#args = null;
  6416. }, 0);
  6417. this.#removeWindowListeners();
  6418. this.#hideControls();
  6419. this.#resetMouseScrollState();
  6420. this.contextMenuOpen = false;
  6421. }
  6422. #mouseDown(evt) {
  6423. if (this.contextMenuOpen) {
  6424. this.contextMenuOpen = false;
  6425. evt.preventDefault();
  6426. return;
  6427. }
  6428. if (evt.button === 0) {
  6429. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6430. if (!isInternalLink) {
  6431. evt.preventDefault();
  6432. if (evt.shiftKey) {
  6433. this.pdfViewer.previousPage();
  6434. } else {
  6435. this.pdfViewer.nextPage();
  6436. }
  6437. }
  6438. }
  6439. }
  6440. #contextMenu() {
  6441. this.contextMenuOpen = true;
  6442. }
  6443. #showControls() {
  6444. if (this.controlsTimeout) {
  6445. clearTimeout(this.controlsTimeout);
  6446. } else {
  6447. this.container.classList.add(CONTROLS_SELECTOR);
  6448. }
  6449. this.controlsTimeout = setTimeout(() => {
  6450. this.container.classList.remove(CONTROLS_SELECTOR);
  6451. delete this.controlsTimeout;
  6452. }, DELAY_BEFORE_HIDING_CONTROLS);
  6453. }
  6454. #hideControls() {
  6455. if (!this.controlsTimeout) {
  6456. return;
  6457. }
  6458. clearTimeout(this.controlsTimeout);
  6459. this.container.classList.remove(CONTROLS_SELECTOR);
  6460. delete this.controlsTimeout;
  6461. }
  6462. #resetMouseScrollState() {
  6463. this.mouseScrollTimeStamp = 0;
  6464. this.mouseScrollDelta = 0;
  6465. }
  6466. #touchSwipe(evt) {
  6467. if (!this.active) {
  6468. return;
  6469. }
  6470. if (evt.touches.length > 1) {
  6471. this.touchSwipeState = null;
  6472. return;
  6473. }
  6474. switch (evt.type) {
  6475. case "touchstart":
  6476. this.touchSwipeState = {
  6477. startX: evt.touches[0].pageX,
  6478. startY: evt.touches[0].pageY,
  6479. endX: evt.touches[0].pageX,
  6480. endY: evt.touches[0].pageY
  6481. };
  6482. break;
  6483. case "touchmove":
  6484. if (this.touchSwipeState === null) {
  6485. return;
  6486. }
  6487. this.touchSwipeState.endX = evt.touches[0].pageX;
  6488. this.touchSwipeState.endY = evt.touches[0].pageY;
  6489. evt.preventDefault();
  6490. break;
  6491. case "touchend":
  6492. if (this.touchSwipeState === null) {
  6493. return;
  6494. }
  6495. let delta = 0;
  6496. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6497. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6498. const absAngle = Math.abs(Math.atan2(dy, dx));
  6499. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6500. delta = dx;
  6501. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6502. delta = dy;
  6503. }
  6504. if (delta > 0) {
  6505. this.pdfViewer.previousPage();
  6506. } else if (delta < 0) {
  6507. this.pdfViewer.nextPage();
  6508. }
  6509. break;
  6510. }
  6511. }
  6512. #addWindowListeners() {
  6513. this.showControlsBind = this.#showControls.bind(this);
  6514. this.mouseDownBind = this.#mouseDown.bind(this);
  6515. this.mouseWheelBind = this.#mouseWheel.bind(this);
  6516. this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
  6517. this.contextMenuBind = this.#contextMenu.bind(this);
  6518. this.touchSwipeBind = this.#touchSwipe.bind(this);
  6519. window.addEventListener("mousemove", this.showControlsBind);
  6520. window.addEventListener("mousedown", this.mouseDownBind);
  6521. window.addEventListener("wheel", this.mouseWheelBind, {
  6522. passive: false
  6523. });
  6524. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6525. window.addEventListener("contextmenu", this.contextMenuBind);
  6526. window.addEventListener("touchstart", this.touchSwipeBind);
  6527. window.addEventListener("touchmove", this.touchSwipeBind);
  6528. window.addEventListener("touchend", this.touchSwipeBind);
  6529. }
  6530. #removeWindowListeners() {
  6531. window.removeEventListener("mousemove", this.showControlsBind);
  6532. window.removeEventListener("mousedown", this.mouseDownBind);
  6533. window.removeEventListener("wheel", this.mouseWheelBind, {
  6534. passive: false
  6535. });
  6536. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6537. window.removeEventListener("contextmenu", this.contextMenuBind);
  6538. window.removeEventListener("touchstart", this.touchSwipeBind);
  6539. window.removeEventListener("touchmove", this.touchSwipeBind);
  6540. window.removeEventListener("touchend", this.touchSwipeBind);
  6541. delete this.showControlsBind;
  6542. delete this.mouseDownBind;
  6543. delete this.mouseWheelBind;
  6544. delete this.resetMouseScrollStateBind;
  6545. delete this.contextMenuBind;
  6546. delete this.touchSwipeBind;
  6547. }
  6548. #fullscreenChange() {
  6549. if (document.fullscreenElement) {
  6550. this.#enter();
  6551. } else {
  6552. this.#exit();
  6553. }
  6554. }
  6555. #addFullscreenChangeListeners() {
  6556. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  6557. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6558. }
  6559. #removeFullscreenChangeListeners() {
  6560. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6561. delete this.fullscreenChangeBind;
  6562. }
  6563. }
  6564. exports.PDFPresentationMode = PDFPresentationMode;
  6565. /***/ }),
  6566. /* 22 */
  6567. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6568. Object.defineProperty(exports, "__esModule", ({
  6569. value: true
  6570. }));
  6571. exports.PDFRenderingQueue = void 0;
  6572. var _pdfjsLib = __webpack_require__(5);
  6573. var _ui_utils = __webpack_require__(1);
  6574. const CLEANUP_TIMEOUT = 30000;
  6575. class PDFRenderingQueue {
  6576. constructor() {
  6577. this.pdfViewer = null;
  6578. this.pdfThumbnailViewer = null;
  6579. this.onIdle = null;
  6580. this.highestPriorityPage = null;
  6581. this.idleTimeout = null;
  6582. this.printing = false;
  6583. this.isThumbnailViewEnabled = false;
  6584. }
  6585. setViewer(pdfViewer) {
  6586. this.pdfViewer = pdfViewer;
  6587. }
  6588. setThumbnailViewer(pdfThumbnailViewer) {
  6589. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6590. }
  6591. isHighestPriority(view) {
  6592. return this.highestPriorityPage === view.renderingId;
  6593. }
  6594. hasViewer() {
  6595. return !!this.pdfViewer;
  6596. }
  6597. renderHighestPriority(currentlyVisiblePages) {
  6598. if (this.idleTimeout) {
  6599. clearTimeout(this.idleTimeout);
  6600. this.idleTimeout = null;
  6601. }
  6602. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  6603. return;
  6604. }
  6605. if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
  6606. return;
  6607. }
  6608. if (this.printing) {
  6609. return;
  6610. }
  6611. if (this.onIdle) {
  6612. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  6613. }
  6614. }
  6615. getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
  6616. const visibleViews = visible.views,
  6617. numVisible = visibleViews.length;
  6618. if (numVisible === 0) {
  6619. return null;
  6620. }
  6621. for (let i = 0; i < numVisible; i++) {
  6622. const view = visibleViews[i].view;
  6623. if (!this.isViewFinished(view)) {
  6624. return view;
  6625. }
  6626. }
  6627. const firstId = visible.first.id,
  6628. lastId = visible.last.id;
  6629. if (lastId - firstId + 1 > numVisible) {
  6630. const visibleIds = visible.ids;
  6631. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  6632. const holeId = scrolledDown ? firstId + i : lastId - i;
  6633. if (visibleIds.has(holeId)) {
  6634. continue;
  6635. }
  6636. const holeView = views[holeId - 1];
  6637. if (!this.isViewFinished(holeView)) {
  6638. return holeView;
  6639. }
  6640. }
  6641. }
  6642. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  6643. let preRenderView = views[preRenderIndex];
  6644. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6645. return preRenderView;
  6646. }
  6647. if (preRenderExtra) {
  6648. preRenderIndex += scrolledDown ? 1 : -1;
  6649. preRenderView = views[preRenderIndex];
  6650. if (preRenderView && !this.isViewFinished(preRenderView)) {
  6651. return preRenderView;
  6652. }
  6653. }
  6654. return null;
  6655. }
  6656. isViewFinished(view) {
  6657. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  6658. }
  6659. renderView(view) {
  6660. switch (view.renderingState) {
  6661. case _ui_utils.RenderingStates.FINISHED:
  6662. return false;
  6663. case _ui_utils.RenderingStates.PAUSED:
  6664. this.highestPriorityPage = view.renderingId;
  6665. view.resume();
  6666. break;
  6667. case _ui_utils.RenderingStates.RUNNING:
  6668. this.highestPriorityPage = view.renderingId;
  6669. break;
  6670. case _ui_utils.RenderingStates.INITIAL:
  6671. this.highestPriorityPage = view.renderingId;
  6672. view.draw().finally(() => {
  6673. this.renderHighestPriority();
  6674. }).catch(reason => {
  6675. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  6676. return;
  6677. }
  6678. console.error(`renderView: "${reason}"`);
  6679. });
  6680. break;
  6681. }
  6682. return true;
  6683. }
  6684. }
  6685. exports.PDFRenderingQueue = PDFRenderingQueue;
  6686. /***/ }),
  6687. /* 23 */
  6688. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6689. Object.defineProperty(exports, "__esModule", ({
  6690. value: true
  6691. }));
  6692. exports.PDFScriptingManager = void 0;
  6693. var _ui_utils = __webpack_require__(1);
  6694. var _pdfjsLib = __webpack_require__(5);
  6695. class PDFScriptingManager {
  6696. constructor({
  6697. eventBus,
  6698. sandboxBundleSrc = null,
  6699. scriptingFactory = null,
  6700. docPropertiesLookup = null
  6701. }) {
  6702. this._pdfDocument = null;
  6703. this._pdfViewer = null;
  6704. this._closeCapability = null;
  6705. this._destroyCapability = null;
  6706. this._scripting = null;
  6707. this._mouseState = Object.create(null);
  6708. this._ready = false;
  6709. this._eventBus = eventBus;
  6710. this._sandboxBundleSrc = sandboxBundleSrc;
  6711. this._scriptingFactory = scriptingFactory;
  6712. this._docPropertiesLookup = docPropertiesLookup;
  6713. }
  6714. setViewer(pdfViewer) {
  6715. this._pdfViewer = pdfViewer;
  6716. }
  6717. async setDocument(pdfDocument) {
  6718. if (this._pdfDocument) {
  6719. await this._destroyScripting();
  6720. }
  6721. this._pdfDocument = pdfDocument;
  6722. if (!pdfDocument) {
  6723. return;
  6724. }
  6725. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6726. if (!objects && !docActions) {
  6727. await this._destroyScripting();
  6728. return;
  6729. }
  6730. if (pdfDocument !== this._pdfDocument) {
  6731. return;
  6732. }
  6733. try {
  6734. this._scripting = this._createScripting();
  6735. } catch (error) {
  6736. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6737. await this._destroyScripting();
  6738. return;
  6739. }
  6740. this._internalEvents.set("updatefromsandbox", event => {
  6741. if (event?.source !== window) {
  6742. return;
  6743. }
  6744. this._updateFromSandbox(event.detail);
  6745. });
  6746. this._internalEvents.set("dispatcheventinsandbox", event => {
  6747. this._scripting?.dispatchEventInSandbox(event.detail);
  6748. });
  6749. this._internalEvents.set("pagechanging", ({
  6750. pageNumber,
  6751. previous
  6752. }) => {
  6753. if (pageNumber === previous) {
  6754. return;
  6755. }
  6756. this._dispatchPageClose(previous);
  6757. this._dispatchPageOpen(pageNumber);
  6758. });
  6759. this._internalEvents.set("pagerendered", ({
  6760. pageNumber
  6761. }) => {
  6762. if (!this._pageOpenPending.has(pageNumber)) {
  6763. return;
  6764. }
  6765. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6766. return;
  6767. }
  6768. this._dispatchPageOpen(pageNumber);
  6769. });
  6770. this._internalEvents.set("pagesdestroy", async event => {
  6771. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6772. await this._scripting?.dispatchEventInSandbox({
  6773. id: "doc",
  6774. name: "WillClose"
  6775. });
  6776. this._closeCapability?.resolve();
  6777. });
  6778. this._domEvents.set("mousedown", event => {
  6779. this._mouseState.isDown = true;
  6780. });
  6781. this._domEvents.set("mouseup", event => {
  6782. this._mouseState.isDown = false;
  6783. });
  6784. for (const [name, listener] of this._internalEvents) {
  6785. this._eventBus._on(name, listener);
  6786. }
  6787. for (const [name, listener] of this._domEvents) {
  6788. window.addEventListener(name, listener, true);
  6789. }
  6790. try {
  6791. const docProperties = await this._getDocProperties();
  6792. if (pdfDocument !== this._pdfDocument) {
  6793. return;
  6794. }
  6795. await this._scripting.createSandbox({
  6796. objects,
  6797. calculationOrder,
  6798. appInfo: {
  6799. platform: navigator.platform,
  6800. language: navigator.language
  6801. },
  6802. docInfo: {
  6803. ...docProperties,
  6804. actions: docActions
  6805. }
  6806. });
  6807. this._eventBus.dispatch("sandboxcreated", {
  6808. source: this
  6809. });
  6810. } catch (error) {
  6811. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6812. await this._destroyScripting();
  6813. return;
  6814. }
  6815. await this._scripting?.dispatchEventInSandbox({
  6816. id: "doc",
  6817. name: "Open"
  6818. });
  6819. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6820. Promise.resolve().then(() => {
  6821. if (pdfDocument === this._pdfDocument) {
  6822. this._ready = true;
  6823. }
  6824. });
  6825. }
  6826. async dispatchWillSave(detail) {
  6827. return this._scripting?.dispatchEventInSandbox({
  6828. id: "doc",
  6829. name: "WillSave"
  6830. });
  6831. }
  6832. async dispatchDidSave(detail) {
  6833. return this._scripting?.dispatchEventInSandbox({
  6834. id: "doc",
  6835. name: "DidSave"
  6836. });
  6837. }
  6838. async dispatchWillPrint(detail) {
  6839. return this._scripting?.dispatchEventInSandbox({
  6840. id: "doc",
  6841. name: "WillPrint"
  6842. });
  6843. }
  6844. async dispatchDidPrint(detail) {
  6845. return this._scripting?.dispatchEventInSandbox({
  6846. id: "doc",
  6847. name: "DidPrint"
  6848. });
  6849. }
  6850. get mouseState() {
  6851. return this._mouseState;
  6852. }
  6853. get destroyPromise() {
  6854. return this._destroyCapability?.promise || null;
  6855. }
  6856. get ready() {
  6857. return this._ready;
  6858. }
  6859. get _internalEvents() {
  6860. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6861. }
  6862. get _domEvents() {
  6863. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6864. }
  6865. get _pageOpenPending() {
  6866. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6867. }
  6868. get _visitedPages() {
  6869. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6870. }
  6871. async _updateFromSandbox(detail) {
  6872. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6873. const {
  6874. id,
  6875. siblings,
  6876. command,
  6877. value
  6878. } = detail;
  6879. if (!id) {
  6880. switch (command) {
  6881. case "clear":
  6882. console.clear();
  6883. break;
  6884. case "error":
  6885. console.error(value);
  6886. break;
  6887. case "layout":
  6888. if (isInPresentationMode) {
  6889. return;
  6890. }
  6891. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  6892. this._pdfViewer.spreadMode = modes.spreadMode;
  6893. break;
  6894. case "page-num":
  6895. this._pdfViewer.currentPageNumber = value + 1;
  6896. break;
  6897. case "print":
  6898. await this._pdfViewer.pagesPromise;
  6899. this._eventBus.dispatch("print", {
  6900. source: this
  6901. });
  6902. break;
  6903. case "println":
  6904. console.log(value);
  6905. break;
  6906. case "zoom":
  6907. if (isInPresentationMode) {
  6908. return;
  6909. }
  6910. this._pdfViewer.currentScaleValue = value;
  6911. break;
  6912. case "SaveAs":
  6913. this._eventBus.dispatch("download", {
  6914. source: this
  6915. });
  6916. break;
  6917. case "FirstPage":
  6918. this._pdfViewer.currentPageNumber = 1;
  6919. break;
  6920. case "LastPage":
  6921. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  6922. break;
  6923. case "NextPage":
  6924. this._pdfViewer.nextPage();
  6925. break;
  6926. case "PrevPage":
  6927. this._pdfViewer.previousPage();
  6928. break;
  6929. case "ZoomViewIn":
  6930. if (isInPresentationMode) {
  6931. return;
  6932. }
  6933. this._pdfViewer.increaseScale();
  6934. break;
  6935. case "ZoomViewOut":
  6936. if (isInPresentationMode) {
  6937. return;
  6938. }
  6939. this._pdfViewer.decreaseScale();
  6940. break;
  6941. }
  6942. return;
  6943. }
  6944. if (isInPresentationMode) {
  6945. if (detail.focus) {
  6946. return;
  6947. }
  6948. }
  6949. delete detail.id;
  6950. delete detail.siblings;
  6951. const ids = siblings ? [id, ...siblings] : [id];
  6952. for (const elementId of ids) {
  6953. const element = document.querySelector(`[data-element-id="${elementId}"]`);
  6954. if (element) {
  6955. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6956. detail
  6957. }));
  6958. } else {
  6959. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6960. }
  6961. }
  6962. }
  6963. async _dispatchPageOpen(pageNumber, initialize = false) {
  6964. const pdfDocument = this._pdfDocument,
  6965. visitedPages = this._visitedPages;
  6966. if (initialize) {
  6967. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6968. }
  6969. if (!this._closeCapability) {
  6970. return;
  6971. }
  6972. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6973. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  6974. this._pageOpenPending.add(pageNumber);
  6975. return;
  6976. }
  6977. this._pageOpenPending.delete(pageNumber);
  6978. const actionsPromise = (async () => {
  6979. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6980. if (pdfDocument !== this._pdfDocument) {
  6981. return;
  6982. }
  6983. await this._scripting?.dispatchEventInSandbox({
  6984. id: "page",
  6985. name: "PageOpen",
  6986. pageNumber,
  6987. actions
  6988. });
  6989. })();
  6990. visitedPages.set(pageNumber, actionsPromise);
  6991. }
  6992. async _dispatchPageClose(pageNumber) {
  6993. const pdfDocument = this._pdfDocument,
  6994. visitedPages = this._visitedPages;
  6995. if (!this._closeCapability) {
  6996. return;
  6997. }
  6998. if (this._pageOpenPending.has(pageNumber)) {
  6999. return;
  7000. }
  7001. const actionsPromise = visitedPages.get(pageNumber);
  7002. if (!actionsPromise) {
  7003. return;
  7004. }
  7005. visitedPages.set(pageNumber, null);
  7006. await actionsPromise;
  7007. if (pdfDocument !== this._pdfDocument) {
  7008. return;
  7009. }
  7010. await this._scripting?.dispatchEventInSandbox({
  7011. id: "page",
  7012. name: "PageClose",
  7013. pageNumber
  7014. });
  7015. }
  7016. async _getDocProperties() {
  7017. if (this._docPropertiesLookup) {
  7018. return this._docPropertiesLookup(this._pdfDocument);
  7019. }
  7020. throw new Error("_getDocProperties: Unable to lookup properties.");
  7021. }
  7022. _createScripting() {
  7023. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  7024. if (this._scripting) {
  7025. throw new Error("_createScripting: Scripting already exists.");
  7026. }
  7027. if (this._scriptingFactory) {
  7028. return this._scriptingFactory.createScripting({
  7029. sandboxBundleSrc: this._sandboxBundleSrc
  7030. });
  7031. }
  7032. throw new Error("_createScripting: Cannot create scripting.");
  7033. }
  7034. async _destroyScripting() {
  7035. if (!this._scripting) {
  7036. this._pdfDocument = null;
  7037. this._destroyCapability?.resolve();
  7038. return;
  7039. }
  7040. if (this._closeCapability) {
  7041. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  7042. setTimeout(resolve, 1000);
  7043. })]).catch(reason => {});
  7044. this._closeCapability = null;
  7045. }
  7046. this._pdfDocument = null;
  7047. try {
  7048. await this._scripting.destroySandbox();
  7049. } catch (ex) {}
  7050. for (const [name, listener] of this._internalEvents) {
  7051. this._eventBus._off(name, listener);
  7052. }
  7053. this._internalEvents.clear();
  7054. for (const [name, listener] of this._domEvents) {
  7055. window.removeEventListener(name, listener, true);
  7056. }
  7057. this._domEvents.clear();
  7058. this._pageOpenPending.clear();
  7059. this._visitedPages.clear();
  7060. this._scripting = null;
  7061. delete this._mouseState.isDown;
  7062. this._ready = false;
  7063. this._destroyCapability?.resolve();
  7064. }
  7065. }
  7066. exports.PDFScriptingManager = PDFScriptingManager;
  7067. /***/ }),
  7068. /* 24 */
  7069. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7070. Object.defineProperty(exports, "__esModule", ({
  7071. value: true
  7072. }));
  7073. exports.PDFSidebar = void 0;
  7074. var _ui_utils = __webpack_require__(1);
  7075. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  7076. class PDFSidebar {
  7077. constructor({
  7078. elements,
  7079. pdfViewer,
  7080. pdfThumbnailViewer,
  7081. eventBus,
  7082. l10n
  7083. }) {
  7084. this.isOpen = false;
  7085. this.active = _ui_utils.SidebarView.THUMBS;
  7086. this.isInitialViewSet = false;
  7087. this.isInitialEventDispatched = false;
  7088. this.onToggled = null;
  7089. this.pdfViewer = pdfViewer;
  7090. this.pdfThumbnailViewer = pdfThumbnailViewer;
  7091. this.outerContainer = elements.outerContainer;
  7092. this.sidebarContainer = elements.sidebarContainer;
  7093. this.toggleButton = elements.toggleButton;
  7094. this.thumbnailButton = elements.thumbnailButton;
  7095. this.outlineButton = elements.outlineButton;
  7096. this.attachmentsButton = elements.attachmentsButton;
  7097. this.layersButton = elements.layersButton;
  7098. this.thumbnailView = elements.thumbnailView;
  7099. this.outlineView = elements.outlineView;
  7100. this.attachmentsView = elements.attachmentsView;
  7101. this.layersView = elements.layersView;
  7102. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  7103. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  7104. this.eventBus = eventBus;
  7105. this.l10n = l10n;
  7106. this.#addEventListeners();
  7107. }
  7108. reset() {
  7109. this.isInitialViewSet = false;
  7110. this.isInitialEventDispatched = false;
  7111. this.#hideUINotification(true);
  7112. this.switchView(_ui_utils.SidebarView.THUMBS);
  7113. this.outlineButton.disabled = false;
  7114. this.attachmentsButton.disabled = false;
  7115. this.layersButton.disabled = false;
  7116. this._currentOutlineItemButton.disabled = true;
  7117. }
  7118. get visibleView() {
  7119. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  7120. }
  7121. setInitialView(view = _ui_utils.SidebarView.NONE) {
  7122. if (this.isInitialViewSet) {
  7123. return;
  7124. }
  7125. this.isInitialViewSet = true;
  7126. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  7127. this.#dispatchEvent();
  7128. return;
  7129. }
  7130. this.switchView(view, true);
  7131. if (!this.isInitialEventDispatched) {
  7132. this.#dispatchEvent();
  7133. }
  7134. }
  7135. switchView(view, forceOpen = false) {
  7136. const isViewChanged = view !== this.active;
  7137. let shouldForceRendering = false;
  7138. switch (view) {
  7139. case _ui_utils.SidebarView.NONE:
  7140. if (this.isOpen) {
  7141. this.close();
  7142. }
  7143. return;
  7144. case _ui_utils.SidebarView.THUMBS:
  7145. if (this.isOpen && isViewChanged) {
  7146. shouldForceRendering = true;
  7147. }
  7148. break;
  7149. case _ui_utils.SidebarView.OUTLINE:
  7150. if (this.outlineButton.disabled) {
  7151. return;
  7152. }
  7153. break;
  7154. case _ui_utils.SidebarView.ATTACHMENTS:
  7155. if (this.attachmentsButton.disabled) {
  7156. return;
  7157. }
  7158. break;
  7159. case _ui_utils.SidebarView.LAYERS:
  7160. if (this.layersButton.disabled) {
  7161. return;
  7162. }
  7163. break;
  7164. default:
  7165. console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
  7166. return;
  7167. }
  7168. this.active = view;
  7169. const isThumbs = view === _ui_utils.SidebarView.THUMBS,
  7170. isOutline = view === _ui_utils.SidebarView.OUTLINE,
  7171. isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS,
  7172. isLayers = view === _ui_utils.SidebarView.LAYERS;
  7173. this.thumbnailButton.classList.toggle("toggled", isThumbs);
  7174. this.outlineButton.classList.toggle("toggled", isOutline);
  7175. this.attachmentsButton.classList.toggle("toggled", isAttachments);
  7176. this.layersButton.classList.toggle("toggled", isLayers);
  7177. this.thumbnailButton.setAttribute("aria-checked", isThumbs);
  7178. this.outlineButton.setAttribute("aria-checked", isOutline);
  7179. this.attachmentsButton.setAttribute("aria-checked", isAttachments);
  7180. this.layersButton.setAttribute("aria-checked", isLayers);
  7181. this.thumbnailView.classList.toggle("hidden", !isThumbs);
  7182. this.outlineView.classList.toggle("hidden", !isOutline);
  7183. this.attachmentsView.classList.toggle("hidden", !isAttachments);
  7184. this.layersView.classList.toggle("hidden", !isLayers);
  7185. this._outlineOptionsContainer.classList.toggle("hidden", !isOutline);
  7186. if (forceOpen && !this.isOpen) {
  7187. this.open();
  7188. return;
  7189. }
  7190. if (shouldForceRendering) {
  7191. this.#updateThumbnailViewer();
  7192. this.#forceRendering();
  7193. }
  7194. if (isViewChanged) {
  7195. this.#dispatchEvent();
  7196. }
  7197. }
  7198. open() {
  7199. if (this.isOpen) {
  7200. return;
  7201. }
  7202. this.isOpen = true;
  7203. this.toggleButton.classList.add("toggled");
  7204. this.toggleButton.setAttribute("aria-expanded", "true");
  7205. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  7206. if (this.active === _ui_utils.SidebarView.THUMBS) {
  7207. this.#updateThumbnailViewer();
  7208. }
  7209. this.#forceRendering();
  7210. this.#dispatchEvent();
  7211. this.#hideUINotification();
  7212. }
  7213. close() {
  7214. if (!this.isOpen) {
  7215. return;
  7216. }
  7217. this.isOpen = false;
  7218. this.toggleButton.classList.remove("toggled");
  7219. this.toggleButton.setAttribute("aria-expanded", "false");
  7220. this.outerContainer.classList.add("sidebarMoving");
  7221. this.outerContainer.classList.remove("sidebarOpen");
  7222. this.#forceRendering();
  7223. this.#dispatchEvent();
  7224. }
  7225. toggle() {
  7226. if (this.isOpen) {
  7227. this.close();
  7228. } else {
  7229. this.open();
  7230. }
  7231. }
  7232. #dispatchEvent() {
  7233. if (this.isInitialViewSet && !this.isInitialEventDispatched) {
  7234. this.isInitialEventDispatched = true;
  7235. }
  7236. this.eventBus.dispatch("sidebarviewchanged", {
  7237. source: this,
  7238. view: this.visibleView
  7239. });
  7240. }
  7241. #forceRendering() {
  7242. if (this.onToggled) {
  7243. this.onToggled();
  7244. } else {
  7245. this.pdfViewer.forceRendering();
  7246. this.pdfThumbnailViewer.forceRendering();
  7247. }
  7248. }
  7249. #updateThumbnailViewer() {
  7250. const {
  7251. pdfViewer,
  7252. pdfThumbnailViewer
  7253. } = this;
  7254. const pagesCount = pdfViewer.pagesCount;
  7255. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  7256. const pageView = pdfViewer.getPageView(pageIndex);
  7257. if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) {
  7258. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  7259. thumbnailView.setImage(pageView);
  7260. }
  7261. }
  7262. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  7263. }
  7264. #showUINotification() {
  7265. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2");
  7266. this.l10n.translate(this.toggleButton);
  7267. if (!this.isOpen) {
  7268. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  7269. }
  7270. }
  7271. #hideUINotification(reset = false) {
  7272. if (this.isOpen || reset) {
  7273. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  7274. }
  7275. if (reset) {
  7276. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
  7277. this.l10n.translate(this.toggleButton);
  7278. }
  7279. }
  7280. #addEventListeners() {
  7281. this.sidebarContainer.addEventListener("transitionend", evt => {
  7282. if (evt.target === this.sidebarContainer) {
  7283. this.outerContainer.classList.remove("sidebarMoving");
  7284. }
  7285. });
  7286. this.toggleButton.addEventListener("click", () => {
  7287. this.toggle();
  7288. });
  7289. this.thumbnailButton.addEventListener("click", () => {
  7290. this.switchView(_ui_utils.SidebarView.THUMBS);
  7291. });
  7292. this.outlineButton.addEventListener("click", () => {
  7293. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7294. });
  7295. this.outlineButton.addEventListener("dblclick", () => {
  7296. this.eventBus.dispatch("toggleoutlinetree", {
  7297. source: this
  7298. });
  7299. });
  7300. this.attachmentsButton.addEventListener("click", () => {
  7301. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7302. });
  7303. this.layersButton.addEventListener("click", () => {
  7304. this.switchView(_ui_utils.SidebarView.LAYERS);
  7305. });
  7306. this.layersButton.addEventListener("dblclick", () => {
  7307. this.eventBus.dispatch("resetlayers", {
  7308. source: this
  7309. });
  7310. });
  7311. this._currentOutlineItemButton.addEventListener("click", () => {
  7312. this.eventBus.dispatch("currentoutlineitem", {
  7313. source: this
  7314. });
  7315. });
  7316. const onTreeLoaded = (count, button, view) => {
  7317. button.disabled = !count;
  7318. if (count) {
  7319. this.#showUINotification();
  7320. } else if (this.active === view) {
  7321. this.switchView(_ui_utils.SidebarView.THUMBS);
  7322. }
  7323. };
  7324. this.eventBus._on("outlineloaded", evt => {
  7325. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7326. evt.currentOutlineItemPromise.then(enabled => {
  7327. if (!this.isInitialViewSet) {
  7328. return;
  7329. }
  7330. this._currentOutlineItemButton.disabled = !enabled;
  7331. });
  7332. });
  7333. this.eventBus._on("attachmentsloaded", evt => {
  7334. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7335. });
  7336. this.eventBus._on("layersloaded", evt => {
  7337. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7338. });
  7339. this.eventBus._on("presentationmodechanged", evt => {
  7340. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
  7341. this.#updateThumbnailViewer();
  7342. }
  7343. });
  7344. }
  7345. }
  7346. exports.PDFSidebar = PDFSidebar;
  7347. /***/ }),
  7348. /* 25 */
  7349. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7350. Object.defineProperty(exports, "__esModule", ({
  7351. value: true
  7352. }));
  7353. exports.PDFSidebarResizer = void 0;
  7354. var _ui_utils = __webpack_require__(1);
  7355. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7356. const SIDEBAR_MIN_WIDTH = 200;
  7357. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7358. class PDFSidebarResizer {
  7359. constructor(options, eventBus, l10n) {
  7360. this.isRTL = false;
  7361. this.sidebarOpen = false;
  7362. this._width = null;
  7363. this._outerContainerWidth = null;
  7364. this._boundEvents = Object.create(null);
  7365. this.outerContainer = options.outerContainer;
  7366. this.resizer = options.resizer;
  7367. this.eventBus = eventBus;
  7368. l10n.getDirection().then(dir => {
  7369. this.isRTL = dir === "rtl";
  7370. });
  7371. this._addEventListeners();
  7372. }
  7373. get outerContainerWidth() {
  7374. return this._outerContainerWidth ||= this.outerContainer.clientWidth;
  7375. }
  7376. _updateWidth(width = 0) {
  7377. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7378. if (width > maxWidth) {
  7379. width = maxWidth;
  7380. }
  7381. if (width < SIDEBAR_MIN_WIDTH) {
  7382. width = SIDEBAR_MIN_WIDTH;
  7383. }
  7384. if (width === this._width) {
  7385. return false;
  7386. }
  7387. this._width = width;
  7388. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7389. return true;
  7390. }
  7391. _mouseMove(evt) {
  7392. let width = evt.clientX;
  7393. if (this.isRTL) {
  7394. width = this.outerContainerWidth - width;
  7395. }
  7396. this._updateWidth(width);
  7397. }
  7398. _mouseUp(evt) {
  7399. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7400. this.eventBus.dispatch("resize", {
  7401. source: this
  7402. });
  7403. const _boundEvents = this._boundEvents;
  7404. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7405. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7406. }
  7407. _addEventListeners() {
  7408. const _boundEvents = this._boundEvents;
  7409. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7410. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7411. this.resizer.addEventListener("mousedown", evt => {
  7412. if (evt.button !== 0) {
  7413. return;
  7414. }
  7415. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7416. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7417. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7418. });
  7419. this.eventBus._on("sidebarviewchanged", evt => {
  7420. this.sidebarOpen = !!evt?.view;
  7421. });
  7422. this.eventBus._on("resize", evt => {
  7423. if (evt?.source !== window) {
  7424. return;
  7425. }
  7426. this._outerContainerWidth = null;
  7427. if (!this._width) {
  7428. return;
  7429. }
  7430. if (!this.sidebarOpen) {
  7431. this._updateWidth(this._width);
  7432. return;
  7433. }
  7434. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7435. const updated = this._updateWidth(this._width);
  7436. Promise.resolve().then(() => {
  7437. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7438. if (updated) {
  7439. this.eventBus.dispatch("resize", {
  7440. source: this
  7441. });
  7442. }
  7443. });
  7444. });
  7445. }
  7446. }
  7447. exports.PDFSidebarResizer = PDFSidebarResizer;
  7448. /***/ }),
  7449. /* 26 */
  7450. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7451. Object.defineProperty(exports, "__esModule", ({
  7452. value: true
  7453. }));
  7454. exports.PDFThumbnailViewer = void 0;
  7455. var _ui_utils = __webpack_require__(1);
  7456. var _pdf_thumbnail_view = __webpack_require__(27);
  7457. const THUMBNAIL_SCROLL_MARGIN = -19;
  7458. const THUMBNAIL_SELECTED_CLASS = "selected";
  7459. class PDFThumbnailViewer {
  7460. constructor({
  7461. container,
  7462. eventBus,
  7463. linkService,
  7464. renderingQueue,
  7465. l10n,
  7466. pageColors
  7467. }) {
  7468. this.container = container;
  7469. this.linkService = linkService;
  7470. this.renderingQueue = renderingQueue;
  7471. this.l10n = l10n;
  7472. this.pageColors = pageColors || null;
  7473. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  7474. if (this.pageColors.background || this.pageColors.foreground) {
  7475. console.warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  7476. }
  7477. this.pageColors = null;
  7478. }
  7479. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7480. this._resetView();
  7481. }
  7482. _scrollUpdated() {
  7483. this.renderingQueue.renderHighestPriority();
  7484. }
  7485. getThumbnail(index) {
  7486. return this._thumbnails[index];
  7487. }
  7488. _getVisibleThumbs() {
  7489. return (0, _ui_utils.getVisibleElements)({
  7490. scrollEl: this.container,
  7491. views: this._thumbnails
  7492. });
  7493. }
  7494. scrollThumbnailIntoView(pageNumber) {
  7495. if (!this.pdfDocument) {
  7496. return;
  7497. }
  7498. const thumbnailView = this._thumbnails[pageNumber - 1];
  7499. if (!thumbnailView) {
  7500. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7501. return;
  7502. }
  7503. if (pageNumber !== this._currentPageNumber) {
  7504. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7505. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7506. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7507. }
  7508. const {
  7509. first,
  7510. last,
  7511. views
  7512. } = this._getVisibleThumbs();
  7513. if (views.length > 0) {
  7514. let shouldScroll = false;
  7515. if (pageNumber <= first.id || pageNumber >= last.id) {
  7516. shouldScroll = true;
  7517. } else {
  7518. for (const {
  7519. id,
  7520. percent
  7521. } of views) {
  7522. if (id !== pageNumber) {
  7523. continue;
  7524. }
  7525. shouldScroll = percent < 100;
  7526. break;
  7527. }
  7528. }
  7529. if (shouldScroll) {
  7530. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7531. top: THUMBNAIL_SCROLL_MARGIN
  7532. });
  7533. }
  7534. }
  7535. this._currentPageNumber = pageNumber;
  7536. }
  7537. get pagesRotation() {
  7538. return this._pagesRotation;
  7539. }
  7540. set pagesRotation(rotation) {
  7541. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7542. throw new Error("Invalid thumbnails rotation angle.");
  7543. }
  7544. if (!this.pdfDocument) {
  7545. return;
  7546. }
  7547. if (this._pagesRotation === rotation) {
  7548. return;
  7549. }
  7550. this._pagesRotation = rotation;
  7551. const updateArgs = {
  7552. rotation
  7553. };
  7554. for (const thumbnail of this._thumbnails) {
  7555. thumbnail.update(updateArgs);
  7556. }
  7557. }
  7558. cleanup() {
  7559. for (const thumbnail of this._thumbnails) {
  7560. if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7561. thumbnail.reset();
  7562. }
  7563. }
  7564. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7565. }
  7566. _resetView() {
  7567. this._thumbnails = [];
  7568. this._currentPageNumber = 1;
  7569. this._pageLabels = null;
  7570. this._pagesRotation = 0;
  7571. this.container.textContent = "";
  7572. }
  7573. setDocument(pdfDocument) {
  7574. if (this.pdfDocument) {
  7575. this._cancelRendering();
  7576. this._resetView();
  7577. }
  7578. this.pdfDocument = pdfDocument;
  7579. if (!pdfDocument) {
  7580. return;
  7581. }
  7582. const firstPagePromise = pdfDocument.getPage(1);
  7583. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7584. firstPagePromise.then(firstPdfPage => {
  7585. const pagesCount = pdfDocument.numPages;
  7586. const viewport = firstPdfPage.getViewport({
  7587. scale: 1
  7588. });
  7589. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7590. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7591. container: this.container,
  7592. id: pageNum,
  7593. defaultViewport: viewport.clone(),
  7594. optionalContentConfigPromise,
  7595. linkService: this.linkService,
  7596. renderingQueue: this.renderingQueue,
  7597. l10n: this.l10n,
  7598. pageColors: this.pageColors
  7599. });
  7600. this._thumbnails.push(thumbnail);
  7601. }
  7602. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  7603. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7604. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7605. }).catch(reason => {
  7606. console.error("Unable to initialize thumbnail viewer", reason);
  7607. });
  7608. }
  7609. _cancelRendering() {
  7610. for (const thumbnail of this._thumbnails) {
  7611. thumbnail.cancelRendering();
  7612. }
  7613. }
  7614. setPageLabels(labels) {
  7615. if (!this.pdfDocument) {
  7616. return;
  7617. }
  7618. if (!labels) {
  7619. this._pageLabels = null;
  7620. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7621. this._pageLabels = null;
  7622. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7623. } else {
  7624. this._pageLabels = labels;
  7625. }
  7626. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7627. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7628. }
  7629. }
  7630. async #ensurePdfPageLoaded(thumbView) {
  7631. if (thumbView.pdfPage) {
  7632. return thumbView.pdfPage;
  7633. }
  7634. try {
  7635. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  7636. if (!thumbView.pdfPage) {
  7637. thumbView.setPdfPage(pdfPage);
  7638. }
  7639. return pdfPage;
  7640. } catch (reason) {
  7641. console.error("Unable to get page for thumb view", reason);
  7642. return null;
  7643. }
  7644. }
  7645. #getScrollAhead(visible) {
  7646. if (visible.first?.id === 1) {
  7647. return true;
  7648. } else if (visible.last?.id === this._thumbnails.length) {
  7649. return false;
  7650. }
  7651. return this.scroll.down;
  7652. }
  7653. forceRendering() {
  7654. const visibleThumbs = this._getVisibleThumbs();
  7655. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  7656. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
  7657. if (thumbView) {
  7658. this.#ensurePdfPageLoaded(thumbView).then(() => {
  7659. this.renderingQueue.renderView(thumbView);
  7660. });
  7661. return true;
  7662. }
  7663. return false;
  7664. }
  7665. }
  7666. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7667. /***/ }),
  7668. /* 27 */
  7669. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7670. Object.defineProperty(exports, "__esModule", ({
  7671. value: true
  7672. }));
  7673. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7674. var _ui_utils = __webpack_require__(1);
  7675. var _pdfjsLib = __webpack_require__(5);
  7676. const DRAW_UPSCALE_FACTOR = 2;
  7677. const MAX_NUM_SCALING_STEPS = 3;
  7678. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7679. const THUMBNAIL_WIDTH = 98;
  7680. class TempImageFactory {
  7681. static #tempCanvas = null;
  7682. static getCanvas(width, height) {
  7683. const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
  7684. tempCanvas.width = width;
  7685. tempCanvas.height = height;
  7686. const ctx = tempCanvas.getContext("2d", {
  7687. alpha: false
  7688. });
  7689. ctx.save();
  7690. ctx.fillStyle = "rgb(255, 255, 255)";
  7691. ctx.fillRect(0, 0, width, height);
  7692. ctx.restore();
  7693. return [tempCanvas, tempCanvas.getContext("2d")];
  7694. }
  7695. static destroyCanvas() {
  7696. const tempCanvas = this.#tempCanvas;
  7697. if (tempCanvas) {
  7698. tempCanvas.width = 0;
  7699. tempCanvas.height = 0;
  7700. }
  7701. this.#tempCanvas = null;
  7702. }
  7703. }
  7704. exports.TempImageFactory = TempImageFactory;
  7705. class PDFThumbnailView {
  7706. constructor({
  7707. container,
  7708. id,
  7709. defaultViewport,
  7710. optionalContentConfigPromise,
  7711. linkService,
  7712. renderingQueue,
  7713. l10n,
  7714. pageColors
  7715. }) {
  7716. this.id = id;
  7717. this.renderingId = "thumbnail" + id;
  7718. this.pageLabel = null;
  7719. this.pdfPage = null;
  7720. this.rotation = 0;
  7721. this.viewport = defaultViewport;
  7722. this.pdfPageRotate = defaultViewport.rotation;
  7723. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7724. this.pageColors = pageColors || null;
  7725. this.linkService = linkService;
  7726. this.renderingQueue = renderingQueue;
  7727. this.renderTask = null;
  7728. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7729. this.resume = null;
  7730. const pageWidth = this.viewport.width,
  7731. pageHeight = this.viewport.height,
  7732. pageRatio = pageWidth / pageHeight;
  7733. this.canvasWidth = THUMBNAIL_WIDTH;
  7734. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7735. this.scale = this.canvasWidth / pageWidth;
  7736. this.l10n = l10n;
  7737. const anchor = document.createElement("a");
  7738. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7739. this._thumbPageTitle.then(msg => {
  7740. anchor.title = msg;
  7741. });
  7742. anchor.onclick = function () {
  7743. linkService.goToPage(id);
  7744. return false;
  7745. };
  7746. this.anchor = anchor;
  7747. const div = document.createElement("div");
  7748. div.className = "thumbnail";
  7749. div.setAttribute("data-page-number", this.id);
  7750. this.div = div;
  7751. const ring = document.createElement("div");
  7752. ring.className = "thumbnailSelectionRing";
  7753. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7754. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7755. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7756. this.ring = ring;
  7757. div.append(ring);
  7758. anchor.append(div);
  7759. container.append(anchor);
  7760. }
  7761. setPdfPage(pdfPage) {
  7762. this.pdfPage = pdfPage;
  7763. this.pdfPageRotate = pdfPage.rotate;
  7764. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7765. this.viewport = pdfPage.getViewport({
  7766. scale: 1,
  7767. rotation: totalRotation
  7768. });
  7769. this.reset();
  7770. }
  7771. reset() {
  7772. this.cancelRendering();
  7773. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  7774. const pageWidth = this.viewport.width,
  7775. pageHeight = this.viewport.height,
  7776. pageRatio = pageWidth / pageHeight;
  7777. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7778. this.scale = this.canvasWidth / pageWidth;
  7779. this.div.removeAttribute("data-loaded");
  7780. const ring = this.ring;
  7781. ring.textContent = "";
  7782. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7783. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7784. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7785. if (this.canvas) {
  7786. this.canvas.width = 0;
  7787. this.canvas.height = 0;
  7788. delete this.canvas;
  7789. }
  7790. if (this.image) {
  7791. this.image.removeAttribute("src");
  7792. delete this.image;
  7793. }
  7794. }
  7795. update({
  7796. rotation = null
  7797. }) {
  7798. if (typeof rotation === "number") {
  7799. this.rotation = rotation;
  7800. }
  7801. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7802. this.viewport = this.viewport.clone({
  7803. scale: 1,
  7804. rotation: totalRotation
  7805. });
  7806. this.reset();
  7807. }
  7808. cancelRendering() {
  7809. if (this.renderTask) {
  7810. this.renderTask.cancel();
  7811. this.renderTask = null;
  7812. }
  7813. this.resume = null;
  7814. }
  7815. _getPageDrawContext(upscaleFactor = 1) {
  7816. const canvas = document.createElement("canvas");
  7817. const ctx = canvas.getContext("2d", {
  7818. alpha: false
  7819. });
  7820. const outputScale = new _ui_utils.OutputScale();
  7821. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7822. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7823. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7824. return {
  7825. ctx,
  7826. canvas,
  7827. transform
  7828. };
  7829. }
  7830. _convertCanvasToImage(canvas) {
  7831. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7832. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  7833. }
  7834. const reducedCanvas = this._reduceImage(canvas);
  7835. const image = document.createElement("img");
  7836. image.className = "thumbnailImage";
  7837. this._thumbPageCanvas.then(msg => {
  7838. image.setAttribute("aria-label", msg);
  7839. });
  7840. image.style.width = this.canvasWidth + "px";
  7841. image.style.height = this.canvasHeight + "px";
  7842. image.src = reducedCanvas.toDataURL();
  7843. this.image = image;
  7844. this.div.setAttribute("data-loaded", true);
  7845. this.ring.append(image);
  7846. reducedCanvas.width = 0;
  7847. reducedCanvas.height = 0;
  7848. }
  7849. draw() {
  7850. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7851. console.error("Must be in new state before drawing");
  7852. return Promise.resolve();
  7853. }
  7854. const {
  7855. pdfPage
  7856. } = this;
  7857. if (!pdfPage) {
  7858. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7859. return Promise.reject(new Error("pdfPage is not loaded"));
  7860. }
  7861. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7862. const finishRenderTask = async (error = null) => {
  7863. if (renderTask === this.renderTask) {
  7864. this.renderTask = null;
  7865. }
  7866. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7867. return;
  7868. }
  7869. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7870. this._convertCanvasToImage(canvas);
  7871. if (error) {
  7872. throw error;
  7873. }
  7874. };
  7875. const {
  7876. ctx,
  7877. canvas,
  7878. transform
  7879. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7880. const drawViewport = this.viewport.clone({
  7881. scale: DRAW_UPSCALE_FACTOR * this.scale
  7882. });
  7883. const renderContinueCallback = cont => {
  7884. if (!this.renderingQueue.isHighestPriority(this)) {
  7885. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  7886. this.resume = () => {
  7887. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  7888. cont();
  7889. };
  7890. return;
  7891. }
  7892. cont();
  7893. };
  7894. const renderContext = {
  7895. canvasContext: ctx,
  7896. transform,
  7897. viewport: drawViewport,
  7898. optionalContentConfigPromise: this._optionalContentConfigPromise,
  7899. pageColors: this.pageColors
  7900. };
  7901. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7902. renderTask.onContinue = renderContinueCallback;
  7903. const resultPromise = renderTask.promise.then(function () {
  7904. return finishRenderTask(null);
  7905. }, function (error) {
  7906. return finishRenderTask(error);
  7907. });
  7908. resultPromise.finally(() => {
  7909. canvas.width = 0;
  7910. canvas.height = 0;
  7911. const pageCached = this.linkService.isPageCached(this.id);
  7912. if (!pageCached) {
  7913. this.pdfPage?.cleanup();
  7914. }
  7915. });
  7916. return resultPromise;
  7917. }
  7918. setImage(pageView) {
  7919. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  7920. return;
  7921. }
  7922. const {
  7923. thumbnailCanvas: canvas,
  7924. pdfPage,
  7925. scale
  7926. } = pageView;
  7927. if (!canvas) {
  7928. return;
  7929. }
  7930. if (!this.pdfPage) {
  7931. this.setPdfPage(pdfPage);
  7932. }
  7933. if (scale < this.scale) {
  7934. return;
  7935. }
  7936. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  7937. this._convertCanvasToImage(canvas);
  7938. }
  7939. _reduceImage(img) {
  7940. const {
  7941. ctx,
  7942. canvas
  7943. } = this._getPageDrawContext();
  7944. if (img.width <= 2 * canvas.width) {
  7945. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7946. return canvas;
  7947. }
  7948. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7949. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7950. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7951. while (reducedWidth > img.width || reducedHeight > img.height) {
  7952. reducedWidth >>= 1;
  7953. reducedHeight >>= 1;
  7954. }
  7955. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7956. while (reducedWidth > 2 * canvas.width) {
  7957. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7958. reducedWidth >>= 1;
  7959. reducedHeight >>= 1;
  7960. }
  7961. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7962. return canvas;
  7963. }
  7964. get _thumbPageTitle() {
  7965. return this.l10n.get("thumb_page_title", {
  7966. page: this.pageLabel ?? this.id
  7967. });
  7968. }
  7969. get _thumbPageCanvas() {
  7970. return this.l10n.get("thumb_page_canvas", {
  7971. page: this.pageLabel ?? this.id
  7972. });
  7973. }
  7974. setPageLabel(label) {
  7975. this.pageLabel = typeof label === "string" ? label : null;
  7976. this._thumbPageTitle.then(msg => {
  7977. this.anchor.title = msg;
  7978. });
  7979. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  7980. return;
  7981. }
  7982. this._thumbPageCanvas.then(msg => {
  7983. this.image?.setAttribute("aria-label", msg);
  7984. });
  7985. }
  7986. }
  7987. exports.PDFThumbnailView = PDFThumbnailView;
  7988. /***/ }),
  7989. /* 28 */
  7990. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7991. Object.defineProperty(exports, "__esModule", ({
  7992. value: true
  7993. }));
  7994. exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
  7995. var _pdfjsLib = __webpack_require__(5);
  7996. var _ui_utils = __webpack_require__(1);
  7997. var _annotation_editor_layer_builder = __webpack_require__(29);
  7998. var _annotation_layer_builder = __webpack_require__(31);
  7999. var _l10n_utils = __webpack_require__(30);
  8000. var _pdf_page_view = __webpack_require__(32);
  8001. var _pdf_rendering_queue = __webpack_require__(22);
  8002. var _pdf_link_service = __webpack_require__(3);
  8003. var _struct_tree_layer_builder = __webpack_require__(34);
  8004. var _text_highlighter = __webpack_require__(35);
  8005. var _text_layer_builder = __webpack_require__(36);
  8006. var _xfa_layer_builder = __webpack_require__(37);
  8007. const DEFAULT_CACHE_SIZE = 10;
  8008. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  8009. const PagesCountLimit = {
  8010. FORCE_SCROLL_MODE_PAGE: 15000,
  8011. FORCE_LAZY_PAGE_INIT: 7500,
  8012. PAUSE_EAGER_PAGE_INIT: 250
  8013. };
  8014. exports.PagesCountLimit = PagesCountLimit;
  8015. function isValidAnnotationEditorMode(mode) {
  8016. return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
  8017. }
  8018. class PDFPageViewBuffer {
  8019. #buf = new Set();
  8020. #size = 0;
  8021. constructor(size) {
  8022. this.#size = size;
  8023. }
  8024. push(view) {
  8025. const buf = this.#buf;
  8026. if (buf.has(view)) {
  8027. buf.delete(view);
  8028. }
  8029. buf.add(view);
  8030. if (buf.size > this.#size) {
  8031. this.#destroyFirstView();
  8032. }
  8033. }
  8034. resize(newSize, idsToKeep = null) {
  8035. this.#size = newSize;
  8036. const buf = this.#buf;
  8037. if (idsToKeep) {
  8038. const ii = buf.size;
  8039. let i = 1;
  8040. for (const view of buf) {
  8041. if (idsToKeep.has(view.id)) {
  8042. buf.delete(view);
  8043. buf.add(view);
  8044. }
  8045. if (++i > ii) {
  8046. break;
  8047. }
  8048. }
  8049. }
  8050. while (buf.size > this.#size) {
  8051. this.#destroyFirstView();
  8052. }
  8053. }
  8054. has(view) {
  8055. return this.#buf.has(view);
  8056. }
  8057. [Symbol.iterator]() {
  8058. return this.#buf.keys();
  8059. }
  8060. #destroyFirstView() {
  8061. const firstView = this.#buf.keys().next().value;
  8062. firstView?.destroy();
  8063. this.#buf.delete(firstView);
  8064. }
  8065. }
  8066. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  8067. class PDFViewer {
  8068. #buffer = null;
  8069. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  8070. #annotationEditorUIManager = null;
  8071. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8072. #enablePermissions = false;
  8073. #previousContainerHeight = 0;
  8074. #scrollModePageState = null;
  8075. #onVisibilityChange = null;
  8076. constructor(options) {
  8077. const viewerVersion = '3.0.279';
  8078. if (_pdfjsLib.version !== viewerVersion) {
  8079. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  8080. }
  8081. this.container = options.container;
  8082. this.viewer = options.viewer || options.container.firstElementChild;
  8083. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  8084. throw new Error("Invalid `container` and/or `viewer` option.");
  8085. }
  8086. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  8087. throw new Error("The `container` must be absolutely positioned.");
  8088. }
  8089. this.eventBus = options.eventBus;
  8090. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8091. this.downloadManager = options.downloadManager || null;
  8092. this.findController = options.findController || null;
  8093. this._scriptingManager = options.scriptingManager || null;
  8094. this.removePageBorders = options.removePageBorders || false;
  8095. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  8096. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8097. this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
  8098. this.imageResourcesPath = options.imageResourcesPath || "";
  8099. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8100. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  8101. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  8102. this.maxCanvasPixels = options.maxCanvasPixels;
  8103. this.l10n = options.l10n || _l10n_utils.NullL10n;
  8104. this.#enablePermissions = options.enablePermissions || false;
  8105. this.pageColors = options.pageColors || null;
  8106. if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
  8107. if (this.pageColors.background || this.pageColors.foreground) {
  8108. console.warn("PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
  8109. }
  8110. this.pageColors = null;
  8111. }
  8112. this.defaultRenderingQueue = !options.renderingQueue;
  8113. if (this.defaultRenderingQueue) {
  8114. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8115. this.renderingQueue.setViewer(this);
  8116. } else {
  8117. this.renderingQueue = options.renderingQueue;
  8118. }
  8119. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8120. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8121. this._onBeforeDraw = this._onAfterDraw = null;
  8122. this._resetView();
  8123. if (this.removePageBorders) {
  8124. this.viewer.classList.add("removePageBorders");
  8125. }
  8126. this.updateContainerHeightCss();
  8127. }
  8128. get pagesCount() {
  8129. return this._pages.length;
  8130. }
  8131. getPageView(index) {
  8132. return this._pages[index];
  8133. }
  8134. get pageViewsReady() {
  8135. if (!this._pagesCapability.settled) {
  8136. return false;
  8137. }
  8138. return this._pages.every(function (pageView) {
  8139. return pageView?.pdfPage;
  8140. });
  8141. }
  8142. get renderForms() {
  8143. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  8144. }
  8145. get enableScripting() {
  8146. return !!this._scriptingManager;
  8147. }
  8148. get currentPageNumber() {
  8149. return this._currentPageNumber;
  8150. }
  8151. set currentPageNumber(val) {
  8152. if (!Number.isInteger(val)) {
  8153. throw new Error("Invalid page number.");
  8154. }
  8155. if (!this.pdfDocument) {
  8156. return;
  8157. }
  8158. if (!this._setCurrentPageNumber(val, true)) {
  8159. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  8160. }
  8161. }
  8162. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  8163. if (this._currentPageNumber === val) {
  8164. if (resetCurrentPageView) {
  8165. this.#resetCurrentPageView();
  8166. }
  8167. return true;
  8168. }
  8169. if (!(0 < val && val <= this.pagesCount)) {
  8170. return false;
  8171. }
  8172. const previous = this._currentPageNumber;
  8173. this._currentPageNumber = val;
  8174. this.eventBus.dispatch("pagechanging", {
  8175. source: this,
  8176. pageNumber: val,
  8177. pageLabel: this._pageLabels?.[val - 1] ?? null,
  8178. previous
  8179. });
  8180. if (resetCurrentPageView) {
  8181. this.#resetCurrentPageView();
  8182. }
  8183. return true;
  8184. }
  8185. get currentPageLabel() {
  8186. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  8187. }
  8188. set currentPageLabel(val) {
  8189. if (!this.pdfDocument) {
  8190. return;
  8191. }
  8192. let page = val | 0;
  8193. if (this._pageLabels) {
  8194. const i = this._pageLabels.indexOf(val);
  8195. if (i >= 0) {
  8196. page = i + 1;
  8197. }
  8198. }
  8199. if (!this._setCurrentPageNumber(page, true)) {
  8200. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  8201. }
  8202. }
  8203. get currentScale() {
  8204. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  8205. }
  8206. set currentScale(val) {
  8207. if (isNaN(val)) {
  8208. throw new Error("Invalid numeric scale.");
  8209. }
  8210. if (!this.pdfDocument) {
  8211. return;
  8212. }
  8213. this._setScale(val, false);
  8214. }
  8215. get currentScaleValue() {
  8216. return this._currentScaleValue;
  8217. }
  8218. set currentScaleValue(val) {
  8219. if (!this.pdfDocument) {
  8220. return;
  8221. }
  8222. this._setScale(val, false);
  8223. }
  8224. get pagesRotation() {
  8225. return this._pagesRotation;
  8226. }
  8227. set pagesRotation(rotation) {
  8228. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8229. throw new Error("Invalid pages rotation angle.");
  8230. }
  8231. if (!this.pdfDocument) {
  8232. return;
  8233. }
  8234. rotation %= 360;
  8235. if (rotation < 0) {
  8236. rotation += 360;
  8237. }
  8238. if (this._pagesRotation === rotation) {
  8239. return;
  8240. }
  8241. this._pagesRotation = rotation;
  8242. const pageNumber = this._currentPageNumber;
  8243. const updateArgs = {
  8244. rotation
  8245. };
  8246. for (const pageView of this._pages) {
  8247. pageView.update(updateArgs);
  8248. }
  8249. if (this._currentScaleValue) {
  8250. this._setScale(this._currentScaleValue, true);
  8251. }
  8252. this.eventBus.dispatch("rotationchanging", {
  8253. source: this,
  8254. pagesRotation: rotation,
  8255. pageNumber
  8256. });
  8257. if (this.defaultRenderingQueue) {
  8258. this.update();
  8259. }
  8260. }
  8261. get firstPagePromise() {
  8262. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8263. }
  8264. get onePageRendered() {
  8265. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8266. }
  8267. get pagesPromise() {
  8268. return this.pdfDocument ? this._pagesCapability.promise : null;
  8269. }
  8270. #initializePermissions(permissions) {
  8271. const params = {
  8272. annotationEditorMode: this.#annotationEditorMode,
  8273. annotationMode: this.#annotationMode,
  8274. textLayerMode: this.textLayerMode
  8275. };
  8276. if (!permissions) {
  8277. return params;
  8278. }
  8279. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  8280. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  8281. }
  8282. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  8283. params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
  8284. }
  8285. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
  8286. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  8287. }
  8288. return params;
  8289. }
  8290. #onePageRenderedOrForceFetch() {
  8291. if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8292. return Promise.resolve();
  8293. }
  8294. const visibilityChangePromise = new Promise(resolve => {
  8295. this.#onVisibilityChange = () => {
  8296. if (document.visibilityState !== "hidden") {
  8297. return;
  8298. }
  8299. resolve();
  8300. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8301. this.#onVisibilityChange = null;
  8302. };
  8303. document.addEventListener("visibilitychange", this.#onVisibilityChange);
  8304. });
  8305. return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
  8306. }
  8307. setDocument(pdfDocument) {
  8308. if (this.pdfDocument) {
  8309. this.eventBus.dispatch("pagesdestroy", {
  8310. source: this
  8311. });
  8312. this._cancelRendering();
  8313. this._resetView();
  8314. this.findController?.setDocument(null);
  8315. this._scriptingManager?.setDocument(null);
  8316. if (this.#annotationEditorUIManager) {
  8317. this.#annotationEditorUIManager.destroy();
  8318. this.#annotationEditorUIManager = null;
  8319. }
  8320. }
  8321. this.pdfDocument = pdfDocument;
  8322. if (!pdfDocument) {
  8323. return;
  8324. }
  8325. const isPureXfa = pdfDocument.isPureXfa;
  8326. const pagesCount = pdfDocument.numPages;
  8327. const firstPagePromise = pdfDocument.getPage(1);
  8328. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8329. const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
  8330. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  8331. console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
  8332. const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
  8333. this.eventBus.dispatch("scrollmodechanged", {
  8334. source: this,
  8335. mode
  8336. });
  8337. }
  8338. this._pagesCapability.promise.then(() => {
  8339. this.eventBus.dispatch("pagesloaded", {
  8340. source: this,
  8341. pagesCount
  8342. });
  8343. }, () => {});
  8344. this._onBeforeDraw = evt => {
  8345. const pageView = this._pages[evt.pageNumber - 1];
  8346. if (!pageView) {
  8347. return;
  8348. }
  8349. this.#buffer.push(pageView);
  8350. };
  8351. this.eventBus._on("pagerender", this._onBeforeDraw);
  8352. this._onAfterDraw = evt => {
  8353. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8354. return;
  8355. }
  8356. this._onePageRenderedCapability.resolve({
  8357. timestamp: evt.timestamp
  8358. });
  8359. this.eventBus._off("pagerendered", this._onAfterDraw);
  8360. this._onAfterDraw = null;
  8361. if (this.#onVisibilityChange) {
  8362. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8363. this.#onVisibilityChange = null;
  8364. }
  8365. };
  8366. this.eventBus._on("pagerendered", this._onAfterDraw);
  8367. Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
  8368. if (pdfDocument !== this.pdfDocument) {
  8369. return;
  8370. }
  8371. this._firstPageCapability.resolve(firstPdfPage);
  8372. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8373. const {
  8374. annotationEditorMode,
  8375. annotationMode,
  8376. textLayerMode
  8377. } = this.#initializePermissions(permissions);
  8378. if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
  8379. const mode = annotationEditorMode;
  8380. if (isPureXfa) {
  8381. console.warn("Warning: XFA-editing is not implemented.");
  8382. } else if (isValidAnnotationEditorMode(mode)) {
  8383. this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus);
  8384. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  8385. this.#annotationEditorUIManager.updateMode(mode);
  8386. }
  8387. } else {
  8388. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  8389. }
  8390. }
  8391. const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
  8392. const scale = this.currentScale;
  8393. const viewport = firstPdfPage.getViewport({
  8394. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  8395. });
  8396. const textLayerFactory = textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !isPureXfa ? this : null;
  8397. const annotationLayerFactory = annotationMode !== _pdfjsLib.AnnotationMode.DISABLE ? this : null;
  8398. const xfaLayerFactory = isPureXfa ? this : null;
  8399. const annotationEditorLayerFactory = this.#annotationEditorUIManager ? this : null;
  8400. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8401. const pageView = new _pdf_page_view.PDFPageView({
  8402. container: viewerElement,
  8403. eventBus: this.eventBus,
  8404. id: pageNum,
  8405. scale,
  8406. defaultViewport: viewport.clone(),
  8407. optionalContentConfigPromise,
  8408. renderingQueue: this.renderingQueue,
  8409. textLayerFactory,
  8410. textLayerMode,
  8411. annotationLayerFactory,
  8412. annotationMode,
  8413. xfaLayerFactory,
  8414. annotationEditorLayerFactory,
  8415. textHighlighterFactory: this,
  8416. structTreeLayerFactory: this,
  8417. imageResourcesPath: this.imageResourcesPath,
  8418. renderer: this.renderer,
  8419. useOnlyCssZoom: this.useOnlyCssZoom,
  8420. maxCanvasPixels: this.maxCanvasPixels,
  8421. pageColors: this.pageColors,
  8422. l10n: this.l10n
  8423. });
  8424. this._pages.push(pageView);
  8425. }
  8426. const firstPageView = this._pages[0];
  8427. if (firstPageView) {
  8428. firstPageView.setPdfPage(firstPdfPage);
  8429. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8430. }
  8431. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8432. this.#ensurePageViewVisible();
  8433. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8434. this._updateSpreadMode();
  8435. }
  8436. this.#onePageRenderedOrForceFetch().then(async () => {
  8437. this.findController?.setDocument(pdfDocument);
  8438. this._scriptingManager?.setDocument(pdfDocument);
  8439. if (this.#annotationEditorUIManager) {
  8440. this.eventBus.dispatch("annotationeditormodechanged", {
  8441. source: this,
  8442. mode: this.#annotationEditorMode
  8443. });
  8444. }
  8445. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
  8446. this._pagesCapability.resolve();
  8447. return;
  8448. }
  8449. let getPagesLeft = pagesCount - 1;
  8450. if (getPagesLeft <= 0) {
  8451. this._pagesCapability.resolve();
  8452. return;
  8453. }
  8454. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8455. const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
  8456. const pageView = this._pages[pageNum - 1];
  8457. if (!pageView.pdfPage) {
  8458. pageView.setPdfPage(pdfPage);
  8459. }
  8460. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8461. if (--getPagesLeft === 0) {
  8462. this._pagesCapability.resolve();
  8463. }
  8464. }, reason => {
  8465. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8466. if (--getPagesLeft === 0) {
  8467. this._pagesCapability.resolve();
  8468. }
  8469. });
  8470. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  8471. await promise;
  8472. }
  8473. }
  8474. });
  8475. this.eventBus.dispatch("pagesinit", {
  8476. source: this
  8477. });
  8478. pdfDocument.getMetadata().then(({
  8479. info
  8480. }) => {
  8481. if (pdfDocument !== this.pdfDocument) {
  8482. return;
  8483. }
  8484. if (info.Language) {
  8485. this.viewer.lang = info.Language;
  8486. }
  8487. });
  8488. if (this.defaultRenderingQueue) {
  8489. this.update();
  8490. }
  8491. }).catch(reason => {
  8492. console.error("Unable to initialize viewer", reason);
  8493. this._pagesCapability.reject(reason);
  8494. });
  8495. }
  8496. setPageLabels(labels) {
  8497. if (!this.pdfDocument) {
  8498. return;
  8499. }
  8500. if (!labels) {
  8501. this._pageLabels = null;
  8502. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8503. this._pageLabels = null;
  8504. console.error(`setPageLabels: Invalid page labels.`);
  8505. } else {
  8506. this._pageLabels = labels;
  8507. }
  8508. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8509. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8510. }
  8511. }
  8512. _resetView() {
  8513. this._pages = [];
  8514. this._currentPageNumber = 1;
  8515. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8516. this._currentScaleValue = null;
  8517. this._pageLabels = null;
  8518. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8519. this._location = null;
  8520. this._pagesRotation = 0;
  8521. this._optionalContentConfigPromise = null;
  8522. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8523. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8524. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8525. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8526. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  8527. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8528. this.#scrollModePageState = {
  8529. previousPageNumber: 1,
  8530. scrollDown: true,
  8531. pages: []
  8532. };
  8533. if (this._onBeforeDraw) {
  8534. this.eventBus._off("pagerender", this._onBeforeDraw);
  8535. this._onBeforeDraw = null;
  8536. }
  8537. if (this._onAfterDraw) {
  8538. this.eventBus._off("pagerendered", this._onAfterDraw);
  8539. this._onAfterDraw = null;
  8540. }
  8541. if (this.#onVisibilityChange) {
  8542. document.removeEventListener("visibilitychange", this.#onVisibilityChange);
  8543. this.#onVisibilityChange = null;
  8544. }
  8545. this.viewer.textContent = "";
  8546. this._updateScrollMode();
  8547. this.viewer.removeAttribute("lang");
  8548. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  8549. }
  8550. #ensurePageViewVisible() {
  8551. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  8552. throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
  8553. }
  8554. const pageNumber = this._currentPageNumber,
  8555. state = this.#scrollModePageState,
  8556. viewer = this.viewer;
  8557. viewer.textContent = "";
  8558. state.pages.length = 0;
  8559. if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
  8560. const pageView = this._pages[pageNumber - 1];
  8561. viewer.append(pageView.div);
  8562. state.pages.push(pageView);
  8563. } else {
  8564. const pageIndexSet = new Set(),
  8565. parity = this._spreadMode - 1;
  8566. if (parity === -1) {
  8567. pageIndexSet.add(pageNumber - 1);
  8568. } else if (pageNumber % 2 !== parity) {
  8569. pageIndexSet.add(pageNumber - 1);
  8570. pageIndexSet.add(pageNumber);
  8571. } else {
  8572. pageIndexSet.add(pageNumber - 2);
  8573. pageIndexSet.add(pageNumber - 1);
  8574. }
  8575. const spread = document.createElement("div");
  8576. spread.className = "spread";
  8577. if (this.isInPresentationMode) {
  8578. const dummyPage = document.createElement("div");
  8579. dummyPage.className = "dummyPage";
  8580. spread.append(dummyPage);
  8581. }
  8582. for (const i of pageIndexSet) {
  8583. const pageView = this._pages[i];
  8584. if (!pageView) {
  8585. continue;
  8586. }
  8587. spread.append(pageView.div);
  8588. state.pages.push(pageView);
  8589. }
  8590. viewer.append(spread);
  8591. }
  8592. state.scrollDown = pageNumber >= state.previousPageNumber;
  8593. state.previousPageNumber = pageNumber;
  8594. }
  8595. _scrollUpdate() {
  8596. if (this.pagesCount === 0) {
  8597. return;
  8598. }
  8599. this.update();
  8600. }
  8601. #scrollIntoView(pageView, pageSpot = null) {
  8602. const {
  8603. div,
  8604. id
  8605. } = pageView;
  8606. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  8607. this._setCurrentPageNumber(id);
  8608. this.#ensurePageViewVisible();
  8609. this.update();
  8610. }
  8611. if (!pageSpot && !this.isInPresentationMode) {
  8612. const left = div.offsetLeft + div.clientLeft,
  8613. right = left + div.clientWidth;
  8614. const {
  8615. scrollLeft,
  8616. clientWidth
  8617. } = this.container;
  8618. if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
  8619. pageSpot = {
  8620. left: 0,
  8621. top: 0
  8622. };
  8623. }
  8624. }
  8625. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  8626. }
  8627. #isSameScale(newScale) {
  8628. return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
  8629. }
  8630. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8631. this._currentScaleValue = newValue.toString();
  8632. if (this.#isSameScale(newScale)) {
  8633. if (preset) {
  8634. this.eventBus.dispatch("scalechanging", {
  8635. source: this,
  8636. scale: newScale,
  8637. presetValue: newValue
  8638. });
  8639. }
  8640. return;
  8641. }
  8642. _ui_utils.docStyle.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
  8643. const updateArgs = {
  8644. scale: newScale
  8645. };
  8646. for (const pageView of this._pages) {
  8647. pageView.update(updateArgs);
  8648. }
  8649. this._currentScale = newScale;
  8650. if (!noScroll) {
  8651. let page = this._currentPageNumber,
  8652. dest;
  8653. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8654. page = this._location.pageNumber;
  8655. dest = [null, {
  8656. name: "XYZ"
  8657. }, this._location.left, this._location.top, null];
  8658. }
  8659. this.scrollPageIntoView({
  8660. pageNumber: page,
  8661. destArray: dest,
  8662. allowNegativeOffset: true
  8663. });
  8664. }
  8665. this.eventBus.dispatch("scalechanging", {
  8666. source: this,
  8667. scale: newScale,
  8668. presetValue: preset ? newValue : undefined
  8669. });
  8670. if (this.defaultRenderingQueue) {
  8671. this.update();
  8672. }
  8673. this.updateContainerHeightCss();
  8674. }
  8675. get _pageWidthScaleFactor() {
  8676. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
  8677. return 2;
  8678. }
  8679. return 1;
  8680. }
  8681. _setScale(value, noScroll = false) {
  8682. let scale = parseFloat(value);
  8683. if (scale > 0) {
  8684. this._setScaleUpdatePages(scale, value, noScroll, false);
  8685. } else {
  8686. const currentPage = this._pages[this._currentPageNumber - 1];
  8687. if (!currentPage) {
  8688. return;
  8689. }
  8690. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  8691. vPadding = _ui_utils.VERTICAL_PADDING;
  8692. if (this.isInPresentationMode) {
  8693. hPadding = vPadding = 4;
  8694. } else if (this.removePageBorders) {
  8695. hPadding = vPadding = 0;
  8696. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  8697. [hPadding, vPadding] = [vPadding, hPadding];
  8698. }
  8699. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8700. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8701. switch (value) {
  8702. case "page-actual":
  8703. scale = 1;
  8704. break;
  8705. case "page-width":
  8706. scale = pageWidthScale;
  8707. break;
  8708. case "page-height":
  8709. scale = pageHeightScale;
  8710. break;
  8711. case "page-fit":
  8712. scale = Math.min(pageWidthScale, pageHeightScale);
  8713. break;
  8714. case "auto":
  8715. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8716. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8717. break;
  8718. default:
  8719. console.error(`_setScale: "${value}" is an unknown zoom value.`);
  8720. return;
  8721. }
  8722. this._setScaleUpdatePages(scale, value, noScroll, true);
  8723. }
  8724. }
  8725. #resetCurrentPageView() {
  8726. const pageView = this._pages[this._currentPageNumber - 1];
  8727. if (this.isInPresentationMode) {
  8728. this._setScale(this._currentScaleValue, true);
  8729. }
  8730. this.#scrollIntoView(pageView);
  8731. }
  8732. pageLabelToPageNumber(label) {
  8733. if (!this._pageLabels) {
  8734. return null;
  8735. }
  8736. const i = this._pageLabels.indexOf(label);
  8737. if (i < 0) {
  8738. return null;
  8739. }
  8740. return i + 1;
  8741. }
  8742. scrollPageIntoView({
  8743. pageNumber,
  8744. destArray = null,
  8745. allowNegativeOffset = false,
  8746. ignoreDestinationZoom = false
  8747. }) {
  8748. if (!this.pdfDocument) {
  8749. return;
  8750. }
  8751. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8752. if (!pageView) {
  8753. console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
  8754. return;
  8755. }
  8756. if (this.isInPresentationMode || !destArray) {
  8757. this._setCurrentPageNumber(pageNumber, true);
  8758. return;
  8759. }
  8760. let x = 0,
  8761. y = 0;
  8762. let width = 0,
  8763. height = 0,
  8764. widthScale,
  8765. heightScale;
  8766. const changeOrientation = pageView.rotation % 180 !== 0;
  8767. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8768. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8769. let scale = 0;
  8770. switch (destArray[1].name) {
  8771. case "XYZ":
  8772. x = destArray[2];
  8773. y = destArray[3];
  8774. scale = destArray[4];
  8775. x = x !== null ? x : 0;
  8776. y = y !== null ? y : pageHeight;
  8777. break;
  8778. case "Fit":
  8779. case "FitB":
  8780. scale = "page-fit";
  8781. break;
  8782. case "FitH":
  8783. case "FitBH":
  8784. y = destArray[2];
  8785. scale = "page-width";
  8786. if (y === null && this._location) {
  8787. x = this._location.left;
  8788. y = this._location.top;
  8789. } else if (typeof y !== "number" || y < 0) {
  8790. y = pageHeight;
  8791. }
  8792. break;
  8793. case "FitV":
  8794. case "FitBV":
  8795. x = destArray[2];
  8796. width = pageWidth;
  8797. height = pageHeight;
  8798. scale = "page-height";
  8799. break;
  8800. case "FitR":
  8801. x = destArray[2];
  8802. y = destArray[3];
  8803. width = destArray[4] - x;
  8804. height = destArray[5] - y;
  8805. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8806. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8807. widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8808. heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  8809. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8810. break;
  8811. default:
  8812. console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
  8813. return;
  8814. }
  8815. if (!ignoreDestinationZoom) {
  8816. if (scale && scale !== this._currentScale) {
  8817. this.currentScaleValue = scale;
  8818. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8819. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8820. }
  8821. }
  8822. if (scale === "page-fit" && !destArray[4]) {
  8823. this.#scrollIntoView(pageView);
  8824. return;
  8825. }
  8826. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8827. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8828. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8829. if (!allowNegativeOffset) {
  8830. left = Math.max(left, 0);
  8831. top = Math.max(top, 0);
  8832. }
  8833. this.#scrollIntoView(pageView, {
  8834. left,
  8835. top
  8836. });
  8837. }
  8838. _updateLocation(firstPage) {
  8839. const currentScale = this._currentScale;
  8840. const currentScaleValue = this._currentScaleValue;
  8841. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8842. const pageNumber = firstPage.id;
  8843. const currentPageView = this._pages[pageNumber - 1];
  8844. const container = this.container;
  8845. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8846. const intLeft = Math.round(topLeft[0]);
  8847. const intTop = Math.round(topLeft[1]);
  8848. let pdfOpenParams = `#page=${pageNumber}`;
  8849. if (!this.isInPresentationMode) {
  8850. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  8851. }
  8852. this._location = {
  8853. pageNumber,
  8854. scale: normalizedScaleValue,
  8855. top: intTop,
  8856. left: intLeft,
  8857. rotation: this._pagesRotation,
  8858. pdfOpenParams
  8859. };
  8860. }
  8861. update() {
  8862. const visible = this._getVisiblePages();
  8863. const visiblePages = visible.views,
  8864. numVisiblePages = visiblePages.length;
  8865. if (numVisiblePages === 0) {
  8866. return;
  8867. }
  8868. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8869. this.#buffer.resize(newCacheSize, visible.ids);
  8870. this.renderingQueue.renderHighestPriority(visible);
  8871. const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  8872. const currentId = this._currentPageNumber;
  8873. let stillFullyVisible = false;
  8874. for (const page of visiblePages) {
  8875. if (page.percent < 100) {
  8876. break;
  8877. }
  8878. if (page.id === currentId && isSimpleLayout) {
  8879. stillFullyVisible = true;
  8880. break;
  8881. }
  8882. }
  8883. this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
  8884. this._updateLocation(visible.first);
  8885. this.eventBus.dispatch("updateviewarea", {
  8886. source: this,
  8887. location: this._location
  8888. });
  8889. }
  8890. containsElement(element) {
  8891. return this.container.contains(element);
  8892. }
  8893. focus() {
  8894. this.container.focus();
  8895. }
  8896. get _isContainerRtl() {
  8897. return getComputedStyle(this.container).direction === "rtl";
  8898. }
  8899. get isInPresentationMode() {
  8900. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8901. }
  8902. get isChangingPresentationMode() {
  8903. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8904. }
  8905. get isHorizontalScrollbarEnabled() {
  8906. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8907. }
  8908. get isVerticalScrollbarEnabled() {
  8909. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8910. }
  8911. _getVisiblePages() {
  8912. const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
  8913. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  8914. rtl = horizontal && this._isContainerRtl;
  8915. return (0, _ui_utils.getVisibleElements)({
  8916. scrollEl: this.container,
  8917. views,
  8918. sortByVisibility: true,
  8919. horizontal,
  8920. rtl
  8921. });
  8922. }
  8923. isPageVisible(pageNumber) {
  8924. if (!this.pdfDocument) {
  8925. return false;
  8926. }
  8927. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8928. console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
  8929. return false;
  8930. }
  8931. return this._getVisiblePages().ids.has(pageNumber);
  8932. }
  8933. isPageCached(pageNumber) {
  8934. if (!this.pdfDocument) {
  8935. return false;
  8936. }
  8937. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8938. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  8939. return false;
  8940. }
  8941. const pageView = this._pages[pageNumber - 1];
  8942. return this.#buffer.has(pageView);
  8943. }
  8944. cleanup() {
  8945. for (const pageView of this._pages) {
  8946. if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8947. pageView.reset();
  8948. }
  8949. }
  8950. }
  8951. _cancelRendering() {
  8952. for (const pageView of this._pages) {
  8953. pageView.cancelRendering();
  8954. }
  8955. }
  8956. async #ensurePdfPageLoaded(pageView) {
  8957. if (pageView.pdfPage) {
  8958. return pageView.pdfPage;
  8959. }
  8960. try {
  8961. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  8962. if (!pageView.pdfPage) {
  8963. pageView.setPdfPage(pdfPage);
  8964. }
  8965. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  8966. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  8967. }
  8968. return pdfPage;
  8969. } catch (reason) {
  8970. console.error("Unable to get page for page view", reason);
  8971. return null;
  8972. }
  8973. }
  8974. #getScrollAhead(visible) {
  8975. if (visible.first?.id === 1) {
  8976. return true;
  8977. } else if (visible.last?.id === this.pagesCount) {
  8978. return false;
  8979. }
  8980. switch (this._scrollMode) {
  8981. case _ui_utils.ScrollMode.PAGE:
  8982. return this.#scrollModePageState.scrollDown;
  8983. case _ui_utils.ScrollMode.HORIZONTAL:
  8984. return this.scroll.right;
  8985. }
  8986. return this.scroll.down;
  8987. }
  8988. #toggleLoadingIconSpinner(visibleIds) {
  8989. for (const id of visibleIds) {
  8990. const pageView = this._pages[id - 1];
  8991. pageView?.toggleLoadingIconSpinner(true);
  8992. }
  8993. for (const pageView of this.#buffer) {
  8994. if (visibleIds.has(pageView.id)) {
  8995. continue;
  8996. }
  8997. pageView.toggleLoadingIconSpinner(false);
  8998. }
  8999. }
  9000. forceRendering(currentlyVisiblePages) {
  9001. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9002. const scrollAhead = this.#getScrollAhead(visiblePages);
  9003. const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  9004. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
  9005. this.#toggleLoadingIconSpinner(visiblePages.ids);
  9006. if (pageView) {
  9007. this.#ensurePdfPageLoaded(pageView).then(() => {
  9008. this.renderingQueue.renderView(pageView);
  9009. });
  9010. return true;
  9011. }
  9012. return false;
  9013. }
  9014. createTextLayerBuilder({
  9015. textLayerDiv,
  9016. pageIndex,
  9017. viewport,
  9018. eventBus,
  9019. highlighter,
  9020. accessibilityManager = null
  9021. }) {
  9022. return new _text_layer_builder.TextLayerBuilder({
  9023. textLayerDiv,
  9024. eventBus,
  9025. pageIndex,
  9026. viewport,
  9027. highlighter,
  9028. accessibilityManager
  9029. });
  9030. }
  9031. createTextHighlighter({
  9032. pageIndex,
  9033. eventBus
  9034. }) {
  9035. return new _text_highlighter.TextHighlighter({
  9036. eventBus,
  9037. pageIndex,
  9038. findController: this.isInPresentationMode ? null : this.findController
  9039. });
  9040. }
  9041. createAnnotationLayerBuilder({
  9042. pageDiv,
  9043. pdfPage,
  9044. annotationStorage = this.pdfDocument?.annotationStorage,
  9045. imageResourcesPath = "",
  9046. renderForms = true,
  9047. l10n = _l10n_utils.NullL10n,
  9048. enableScripting = this.enableScripting,
  9049. hasJSActionsPromise = this.pdfDocument?.hasJSActions(),
  9050. mouseState = this._scriptingManager?.mouseState,
  9051. fieldObjectsPromise = this.pdfDocument?.getFieldObjects(),
  9052. annotationCanvasMap = null,
  9053. accessibilityManager = null
  9054. }) {
  9055. return new _annotation_layer_builder.AnnotationLayerBuilder({
  9056. pageDiv,
  9057. pdfPage,
  9058. annotationStorage,
  9059. imageResourcesPath,
  9060. renderForms,
  9061. linkService: this.linkService,
  9062. downloadManager: this.downloadManager,
  9063. l10n,
  9064. enableScripting,
  9065. hasJSActionsPromise,
  9066. mouseState,
  9067. fieldObjectsPromise,
  9068. annotationCanvasMap,
  9069. accessibilityManager
  9070. });
  9071. }
  9072. createAnnotationEditorLayerBuilder({
  9073. uiManager = this.#annotationEditorUIManager,
  9074. pageDiv,
  9075. pdfPage,
  9076. accessibilityManager = null,
  9077. l10n,
  9078. annotationStorage = this.pdfDocument?.annotationStorage
  9079. }) {
  9080. return new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
  9081. uiManager,
  9082. pageDiv,
  9083. pdfPage,
  9084. annotationStorage,
  9085. accessibilityManager,
  9086. l10n
  9087. });
  9088. }
  9089. createXfaLayerBuilder({
  9090. pageDiv,
  9091. pdfPage,
  9092. annotationStorage = this.pdfDocument?.annotationStorage
  9093. }) {
  9094. return new _xfa_layer_builder.XfaLayerBuilder({
  9095. pageDiv,
  9096. pdfPage,
  9097. annotationStorage,
  9098. linkService: this.linkService
  9099. });
  9100. }
  9101. createStructTreeLayerBuilder({
  9102. pdfPage
  9103. }) {
  9104. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  9105. pdfPage
  9106. });
  9107. }
  9108. get hasEqualPageSizes() {
  9109. const firstPageView = this._pages[0];
  9110. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  9111. const pageView = this._pages[i];
  9112. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9113. return false;
  9114. }
  9115. }
  9116. return true;
  9117. }
  9118. getPagesOverview() {
  9119. return this._pages.map(pageView => {
  9120. const viewport = pageView.pdfPage.getViewport({
  9121. scale: 1
  9122. });
  9123. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  9124. return {
  9125. width: viewport.width,
  9126. height: viewport.height,
  9127. rotation: viewport.rotation
  9128. };
  9129. }
  9130. return {
  9131. width: viewport.height,
  9132. height: viewport.width,
  9133. rotation: (viewport.rotation - 90) % 360
  9134. };
  9135. });
  9136. }
  9137. get optionalContentConfigPromise() {
  9138. if (!this.pdfDocument) {
  9139. return Promise.resolve(null);
  9140. }
  9141. if (!this._optionalContentConfigPromise) {
  9142. console.error("optionalContentConfigPromise: Not initialized yet.");
  9143. return this.pdfDocument.getOptionalContentConfig();
  9144. }
  9145. return this._optionalContentConfigPromise;
  9146. }
  9147. set optionalContentConfigPromise(promise) {
  9148. if (!(promise instanceof Promise)) {
  9149. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  9150. }
  9151. if (!this.pdfDocument) {
  9152. return;
  9153. }
  9154. if (!this._optionalContentConfigPromise) {
  9155. return;
  9156. }
  9157. this._optionalContentConfigPromise = promise;
  9158. const updateArgs = {
  9159. optionalContentConfigPromise: promise
  9160. };
  9161. for (const pageView of this._pages) {
  9162. pageView.update(updateArgs);
  9163. }
  9164. this.update();
  9165. this.eventBus.dispatch("optionalcontentconfigchanged", {
  9166. source: this,
  9167. promise
  9168. });
  9169. }
  9170. get scrollMode() {
  9171. return this._scrollMode;
  9172. }
  9173. set scrollMode(mode) {
  9174. if (this._scrollMode === mode) {
  9175. return;
  9176. }
  9177. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9178. throw new Error(`Invalid scroll mode: ${mode}`);
  9179. }
  9180. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9181. return;
  9182. }
  9183. this._previousScrollMode = this._scrollMode;
  9184. this._scrollMode = mode;
  9185. this.eventBus.dispatch("scrollmodechanged", {
  9186. source: this,
  9187. mode
  9188. });
  9189. this._updateScrollMode(this._currentPageNumber);
  9190. }
  9191. _updateScrollMode(pageNumber = null) {
  9192. const scrollMode = this._scrollMode,
  9193. viewer = this.viewer;
  9194. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9195. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9196. if (!this.pdfDocument || !pageNumber) {
  9197. return;
  9198. }
  9199. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  9200. this.#ensurePageViewVisible();
  9201. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  9202. this._updateSpreadMode();
  9203. }
  9204. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9205. this._setScale(this._currentScaleValue, true);
  9206. }
  9207. this._setCurrentPageNumber(pageNumber, true);
  9208. this.update();
  9209. }
  9210. get spreadMode() {
  9211. return this._spreadMode;
  9212. }
  9213. set spreadMode(mode) {
  9214. if (this._spreadMode === mode) {
  9215. return;
  9216. }
  9217. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9218. throw new Error(`Invalid spread mode: ${mode}`);
  9219. }
  9220. this._spreadMode = mode;
  9221. this.eventBus.dispatch("spreadmodechanged", {
  9222. source: this,
  9223. mode
  9224. });
  9225. this._updateSpreadMode(this._currentPageNumber);
  9226. }
  9227. _updateSpreadMode(pageNumber = null) {
  9228. if (!this.pdfDocument) {
  9229. return;
  9230. }
  9231. const viewer = this.viewer,
  9232. pages = this._pages;
  9233. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9234. this.#ensurePageViewVisible();
  9235. } else {
  9236. viewer.textContent = "";
  9237. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9238. for (const pageView of this._pages) {
  9239. viewer.append(pageView.div);
  9240. }
  9241. } else {
  9242. const parity = this._spreadMode - 1;
  9243. let spread = null;
  9244. for (let i = 0, ii = pages.length; i < ii; ++i) {
  9245. if (spread === null) {
  9246. spread = document.createElement("div");
  9247. spread.className = "spread";
  9248. viewer.append(spread);
  9249. } else if (i % 2 === parity) {
  9250. spread = spread.cloneNode(false);
  9251. viewer.append(spread);
  9252. }
  9253. spread.append(pages[i].div);
  9254. }
  9255. }
  9256. }
  9257. if (!pageNumber) {
  9258. return;
  9259. }
  9260. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9261. this._setScale(this._currentScaleValue, true);
  9262. }
  9263. this._setCurrentPageNumber(pageNumber, true);
  9264. this.update();
  9265. }
  9266. _getPageAdvance(currentPageNumber, previous = false) {
  9267. switch (this._scrollMode) {
  9268. case _ui_utils.ScrollMode.WRAPPED:
  9269. {
  9270. const {
  9271. views
  9272. } = this._getVisiblePages(),
  9273. pageLayout = new Map();
  9274. for (const {
  9275. id,
  9276. y,
  9277. percent,
  9278. widthPercent
  9279. } of views) {
  9280. if (percent === 0 || widthPercent < 100) {
  9281. continue;
  9282. }
  9283. let yArray = pageLayout.get(y);
  9284. if (!yArray) {
  9285. pageLayout.set(y, yArray ||= []);
  9286. }
  9287. yArray.push(id);
  9288. }
  9289. for (const yArray of pageLayout.values()) {
  9290. const currentIndex = yArray.indexOf(currentPageNumber);
  9291. if (currentIndex === -1) {
  9292. continue;
  9293. }
  9294. const numPages = yArray.length;
  9295. if (numPages === 1) {
  9296. break;
  9297. }
  9298. if (previous) {
  9299. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  9300. const currentId = yArray[i],
  9301. expectedId = yArray[i + 1] - 1;
  9302. if (currentId < expectedId) {
  9303. return currentPageNumber - expectedId;
  9304. }
  9305. }
  9306. } else {
  9307. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  9308. const currentId = yArray[i],
  9309. expectedId = yArray[i - 1] + 1;
  9310. if (currentId > expectedId) {
  9311. return expectedId - currentPageNumber;
  9312. }
  9313. }
  9314. }
  9315. if (previous) {
  9316. const firstId = yArray[0];
  9317. if (firstId < currentPageNumber) {
  9318. return currentPageNumber - firstId + 1;
  9319. }
  9320. } else {
  9321. const lastId = yArray[numPages - 1];
  9322. if (lastId > currentPageNumber) {
  9323. return lastId - currentPageNumber + 1;
  9324. }
  9325. }
  9326. break;
  9327. }
  9328. break;
  9329. }
  9330. case _ui_utils.ScrollMode.HORIZONTAL:
  9331. {
  9332. break;
  9333. }
  9334. case _ui_utils.ScrollMode.PAGE:
  9335. case _ui_utils.ScrollMode.VERTICAL:
  9336. {
  9337. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9338. break;
  9339. }
  9340. const parity = this._spreadMode - 1;
  9341. if (previous && currentPageNumber % 2 !== parity) {
  9342. break;
  9343. } else if (!previous && currentPageNumber % 2 === parity) {
  9344. break;
  9345. }
  9346. const {
  9347. views
  9348. } = this._getVisiblePages(),
  9349. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  9350. for (const {
  9351. id,
  9352. percent,
  9353. widthPercent
  9354. } of views) {
  9355. if (id !== expectedId) {
  9356. continue;
  9357. }
  9358. if (percent > 0 && widthPercent === 100) {
  9359. return 2;
  9360. }
  9361. break;
  9362. }
  9363. break;
  9364. }
  9365. }
  9366. return 1;
  9367. }
  9368. nextPage() {
  9369. const currentPageNumber = this._currentPageNumber,
  9370. pagesCount = this.pagesCount;
  9371. if (currentPageNumber >= pagesCount) {
  9372. return false;
  9373. }
  9374. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  9375. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  9376. return true;
  9377. }
  9378. previousPage() {
  9379. const currentPageNumber = this._currentPageNumber;
  9380. if (currentPageNumber <= 1) {
  9381. return false;
  9382. }
  9383. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  9384. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  9385. return true;
  9386. }
  9387. increaseScale(steps = 1) {
  9388. let newScale = this._currentScale;
  9389. do {
  9390. newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9391. newScale = Math.ceil(newScale * 10) / 10;
  9392. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  9393. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  9394. this.currentScaleValue = newScale;
  9395. }
  9396. decreaseScale(steps = 1) {
  9397. let newScale = this._currentScale;
  9398. do {
  9399. newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
  9400. newScale = Math.floor(newScale * 10) / 10;
  9401. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  9402. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  9403. this.currentScaleValue = newScale;
  9404. }
  9405. updateContainerHeightCss() {
  9406. const height = this.container.clientHeight;
  9407. if (height !== this.#previousContainerHeight) {
  9408. this.#previousContainerHeight = height;
  9409. _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
  9410. }
  9411. }
  9412. get annotationEditorMode() {
  9413. return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
  9414. }
  9415. set annotationEditorMode(mode) {
  9416. if (!this.#annotationEditorUIManager) {
  9417. throw new Error(`The AnnotationEditor is not enabled.`);
  9418. }
  9419. if (this.#annotationEditorMode === mode) {
  9420. return;
  9421. }
  9422. if (!isValidAnnotationEditorMode(mode)) {
  9423. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  9424. }
  9425. if (!this.pdfDocument) {
  9426. return;
  9427. }
  9428. this.#annotationEditorMode = mode;
  9429. this.eventBus.dispatch("annotationeditormodechanged", {
  9430. source: this,
  9431. mode
  9432. });
  9433. this.#annotationEditorUIManager.updateMode(mode);
  9434. }
  9435. set annotationEditorParams({
  9436. type,
  9437. value
  9438. }) {
  9439. if (!this.#annotationEditorUIManager) {
  9440. throw new Error(`The AnnotationEditor is not enabled.`);
  9441. }
  9442. this.#annotationEditorUIManager.updateParams(type, value);
  9443. }
  9444. refresh() {
  9445. if (!this.pdfDocument) {
  9446. return;
  9447. }
  9448. const updateArgs = {};
  9449. for (const pageView of this._pages) {
  9450. pageView.update(updateArgs);
  9451. }
  9452. this.update();
  9453. }
  9454. }
  9455. exports.PDFViewer = PDFViewer;
  9456. /***/ }),
  9457. /* 29 */
  9458. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9459. Object.defineProperty(exports, "__esModule", ({
  9460. value: true
  9461. }));
  9462. exports.AnnotationEditorLayerBuilder = void 0;
  9463. var _pdfjsLib = __webpack_require__(5);
  9464. var _l10n_utils = __webpack_require__(30);
  9465. class AnnotationEditorLayerBuilder {
  9466. #uiManager;
  9467. constructor(options) {
  9468. this.pageDiv = options.pageDiv;
  9469. this.pdfPage = options.pdfPage;
  9470. this.annotationStorage = options.annotationStorage || null;
  9471. this.accessibilityManager = options.accessibilityManager;
  9472. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9473. this.annotationEditorLayer = null;
  9474. this.div = null;
  9475. this._cancelled = false;
  9476. this.#uiManager = options.uiManager;
  9477. }
  9478. async render(viewport, intent = "display") {
  9479. if (intent !== "display") {
  9480. return;
  9481. }
  9482. if (this._cancelled) {
  9483. return;
  9484. }
  9485. const clonedViewport = viewport.clone({
  9486. dontFlip: true
  9487. });
  9488. if (this.div) {
  9489. this.annotationEditorLayer.update({
  9490. viewport: clonedViewport
  9491. });
  9492. this.show();
  9493. return;
  9494. }
  9495. this.div = document.createElement("div");
  9496. this.div.className = "annotationEditorLayer";
  9497. this.div.tabIndex = 0;
  9498. this.pageDiv.append(this.div);
  9499. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  9500. uiManager: this.#uiManager,
  9501. div: this.div,
  9502. annotationStorage: this.annotationStorage,
  9503. accessibilityManager: this.accessibilityManager,
  9504. pageIndex: this.pdfPage._pageIndex,
  9505. l10n: this.l10n,
  9506. viewport: clonedViewport
  9507. });
  9508. const parameters = {
  9509. viewport: clonedViewport,
  9510. div: this.div,
  9511. annotations: null,
  9512. intent
  9513. };
  9514. this.annotationEditorLayer.render(parameters);
  9515. }
  9516. cancel() {
  9517. this._cancelled = true;
  9518. this.destroy();
  9519. }
  9520. hide() {
  9521. if (!this.div) {
  9522. return;
  9523. }
  9524. this.div.hidden = true;
  9525. }
  9526. show() {
  9527. if (!this.div) {
  9528. return;
  9529. }
  9530. this.div.hidden = false;
  9531. }
  9532. destroy() {
  9533. if (!this.div) {
  9534. return;
  9535. }
  9536. this.pageDiv = null;
  9537. this.annotationEditorLayer.destroy();
  9538. this.div.remove();
  9539. }
  9540. }
  9541. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  9542. /***/ }),
  9543. /* 30 */
  9544. /***/ ((__unused_webpack_module, exports) => {
  9545. Object.defineProperty(exports, "__esModule", ({
  9546. value: true
  9547. }));
  9548. exports.NullL10n = void 0;
  9549. exports.fixupLangCode = fixupLangCode;
  9550. exports.getL10nFallback = getL10nFallback;
  9551. const DEFAULT_L10N_STRINGS = {
  9552. of_pages: "of {{pagesCount}}",
  9553. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9554. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9555. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9556. document_properties_date_string: "{{date}}, {{time}}",
  9557. document_properties_page_size_unit_inches: "in",
  9558. document_properties_page_size_unit_millimeters: "mm",
  9559. document_properties_page_size_orientation_portrait: "portrait",
  9560. document_properties_page_size_orientation_landscape: "landscape",
  9561. document_properties_page_size_name_a3: "A3",
  9562. document_properties_page_size_name_a4: "A4",
  9563. document_properties_page_size_name_letter: "Letter",
  9564. document_properties_page_size_name_legal: "Legal",
  9565. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9566. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9567. document_properties_linearized_yes: "Yes",
  9568. document_properties_linearized_no: "No",
  9569. additional_layers: "Additional Layers",
  9570. page_landmark: "Page {{page}}",
  9571. thumb_page_title: "Page {{page}}",
  9572. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9573. find_reached_top: "Reached top of document, continued from bottom",
  9574. find_reached_bottom: "Reached end of document, continued from top",
  9575. "find_match_count[one]": "{{current}} of {{total}} match",
  9576. "find_match_count[other]": "{{current}} of {{total}} matches",
  9577. "find_match_count_limit[one]": "More than {{limit}} match",
  9578. "find_match_count_limit[other]": "More than {{limit}} matches",
  9579. find_not_found: "Phrase not found",
  9580. page_scale_width: "Page Width",
  9581. page_scale_fit: "Page Fit",
  9582. page_scale_auto: "Automatic Zoom",
  9583. page_scale_actual: "Actual Size",
  9584. page_scale_percent: "{{scale}}%",
  9585. loading: "Loading…",
  9586. loading_error: "An error occurred while loading the PDF.",
  9587. invalid_file_error: "Invalid or corrupted PDF file.",
  9588. missing_file_error: "Missing PDF file.",
  9589. unexpected_response_error: "Unexpected server response.",
  9590. rendering_error: "An error occurred while rendering the page.",
  9591. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9592. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9593. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
  9594. free_text2_default_content: "Start typing…",
  9595. editor_free_text2_aria_label: "Text Editor",
  9596. editor_ink2_aria_label: "Draw Editor",
  9597. editor_ink_canvas_aria_label: "User-created image"
  9598. };
  9599. {
  9600. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  9601. }
  9602. function getL10nFallback(key, args) {
  9603. switch (key) {
  9604. case "find_match_count":
  9605. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9606. break;
  9607. case "find_match_count_limit":
  9608. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9609. break;
  9610. }
  9611. return DEFAULT_L10N_STRINGS[key] || "";
  9612. }
  9613. const PARTIAL_LANG_CODES = {
  9614. en: "en-US",
  9615. es: "es-ES",
  9616. fy: "fy-NL",
  9617. ga: "ga-IE",
  9618. gu: "gu-IN",
  9619. hi: "hi-IN",
  9620. hy: "hy-AM",
  9621. nb: "nb-NO",
  9622. ne: "ne-NP",
  9623. nn: "nn-NO",
  9624. pa: "pa-IN",
  9625. pt: "pt-PT",
  9626. sv: "sv-SE",
  9627. zh: "zh-CN"
  9628. };
  9629. function fixupLangCode(langCode) {
  9630. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9631. }
  9632. function formatL10nValue(text, args) {
  9633. if (!args) {
  9634. return text;
  9635. }
  9636. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9637. return name in args ? args[name] : "{{" + name + "}}";
  9638. });
  9639. }
  9640. const NullL10n = {
  9641. async getLanguage() {
  9642. return "en-us";
  9643. },
  9644. async getDirection() {
  9645. return "ltr";
  9646. },
  9647. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9648. return formatL10nValue(fallback, args);
  9649. },
  9650. async translate(element) {}
  9651. };
  9652. exports.NullL10n = NullL10n;
  9653. /***/ }),
  9654. /* 31 */
  9655. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9656. Object.defineProperty(exports, "__esModule", ({
  9657. value: true
  9658. }));
  9659. exports.AnnotationLayerBuilder = void 0;
  9660. var _pdfjsLib = __webpack_require__(5);
  9661. var _l10n_utils = __webpack_require__(30);
  9662. class AnnotationLayerBuilder {
  9663. constructor({
  9664. pageDiv,
  9665. pdfPage,
  9666. linkService,
  9667. downloadManager,
  9668. annotationStorage = null,
  9669. imageResourcesPath = "",
  9670. renderForms = true,
  9671. l10n = _l10n_utils.NullL10n,
  9672. enableScripting = false,
  9673. hasJSActionsPromise = null,
  9674. fieldObjectsPromise = null,
  9675. mouseState = null,
  9676. annotationCanvasMap = null,
  9677. accessibilityManager = null
  9678. }) {
  9679. this.pageDiv = pageDiv;
  9680. this.pdfPage = pdfPage;
  9681. this.linkService = linkService;
  9682. this.downloadManager = downloadManager;
  9683. this.imageResourcesPath = imageResourcesPath;
  9684. this.renderForms = renderForms;
  9685. this.l10n = l10n;
  9686. this.annotationStorage = annotationStorage;
  9687. this.enableScripting = enableScripting;
  9688. this._hasJSActionsPromise = hasJSActionsPromise;
  9689. this._fieldObjectsPromise = fieldObjectsPromise;
  9690. this._mouseState = mouseState;
  9691. this._annotationCanvasMap = annotationCanvasMap;
  9692. this._accessibilityManager = accessibilityManager;
  9693. this.div = null;
  9694. this._cancelled = false;
  9695. }
  9696. async render(viewport, intent = "display") {
  9697. const [annotations, hasJSActions = false, fieldObjects = null] = await Promise.all([this.pdfPage.getAnnotations({
  9698. intent
  9699. }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
  9700. if (this._cancelled || annotations.length === 0) {
  9701. return;
  9702. }
  9703. const parameters = {
  9704. viewport: viewport.clone({
  9705. dontFlip: true
  9706. }),
  9707. div: this.div,
  9708. annotations,
  9709. page: this.pdfPage,
  9710. imageResourcesPath: this.imageResourcesPath,
  9711. renderForms: this.renderForms,
  9712. linkService: this.linkService,
  9713. downloadManager: this.downloadManager,
  9714. annotationStorage: this.annotationStorage,
  9715. enableScripting: this.enableScripting,
  9716. hasJSActions,
  9717. fieldObjects,
  9718. mouseState: this._mouseState,
  9719. annotationCanvasMap: this._annotationCanvasMap,
  9720. accessibilityManager: this._accessibilityManager
  9721. };
  9722. if (this.div) {
  9723. _pdfjsLib.AnnotationLayer.update(parameters);
  9724. } else {
  9725. this.div = document.createElement("div");
  9726. this.div.className = "annotationLayer";
  9727. this.pageDiv.append(this.div);
  9728. parameters.div = this.div;
  9729. _pdfjsLib.AnnotationLayer.render(parameters);
  9730. this.l10n.translate(this.div);
  9731. }
  9732. }
  9733. cancel() {
  9734. this._cancelled = true;
  9735. }
  9736. hide() {
  9737. if (!this.div) {
  9738. return;
  9739. }
  9740. this.div.hidden = true;
  9741. }
  9742. }
  9743. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  9744. /***/ }),
  9745. /* 32 */
  9746. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9747. Object.defineProperty(exports, "__esModule", ({
  9748. value: true
  9749. }));
  9750. exports.PDFPageView = void 0;
  9751. var _pdfjsLib = __webpack_require__(5);
  9752. var _ui_utils = __webpack_require__(1);
  9753. var _app_options = __webpack_require__(2);
  9754. var _l10n_utils = __webpack_require__(30);
  9755. var _text_accessibility = __webpack_require__(33);
  9756. const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  9757. class PDFPageView {
  9758. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9759. #useThumbnailCanvas = {
  9760. initialOptionalContent: true,
  9761. regularAnnotations: true
  9762. };
  9763. constructor(options) {
  9764. const container = options.container;
  9765. const defaultViewport = options.defaultViewport;
  9766. this.id = options.id;
  9767. this.renderingId = "page" + this.id;
  9768. this.pdfPage = null;
  9769. this.pageLabel = null;
  9770. this.rotation = 0;
  9771. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9772. this.viewport = defaultViewport;
  9773. this.pdfPageRotate = defaultViewport.rotation;
  9774. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9775. this.hasRestrictedScaling = false;
  9776. this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9777. this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9778. this.imageResourcesPath = options.imageResourcesPath || "";
  9779. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9780. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9781. this.pageColors = options.pageColors || null;
  9782. this.eventBus = options.eventBus;
  9783. this.renderingQueue = options.renderingQueue;
  9784. this.textLayerFactory = options.textLayerFactory;
  9785. this.annotationLayerFactory = options.annotationLayerFactory;
  9786. this.annotationEditorLayerFactory = options.annotationEditorLayerFactory;
  9787. this.xfaLayerFactory = options.xfaLayerFactory;
  9788. this.textHighlighter = options.textHighlighterFactory?.createTextHighlighter({
  9789. pageIndex: this.id - 1,
  9790. eventBus: this.eventBus
  9791. });
  9792. this.structTreeLayerFactory = options.structTreeLayerFactory;
  9793. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9794. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9795. this.paintTask = null;
  9796. this.paintedViewportMap = new WeakMap();
  9797. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9798. this.resume = null;
  9799. this._renderError = null;
  9800. this._isStandalone = !this.renderingQueue?.hasViewer();
  9801. this._annotationCanvasMap = null;
  9802. this.annotationLayer = null;
  9803. this.annotationEditorLayer = null;
  9804. this.textLayer = null;
  9805. this.zoomLayer = null;
  9806. this.xfaLayer = null;
  9807. this.structTreeLayer = null;
  9808. const div = document.createElement("div");
  9809. div.className = "page";
  9810. div.style.width = Math.floor(this.viewport.width) + "px";
  9811. div.style.height = Math.floor(this.viewport.height) + "px";
  9812. div.setAttribute("data-page-number", this.id);
  9813. div.setAttribute("role", "region");
  9814. this.l10n.get("page_landmark", {
  9815. page: this.id
  9816. }).then(msg => {
  9817. div.setAttribute("aria-label", msg);
  9818. });
  9819. this.div = div;
  9820. container?.append(div);
  9821. if (this._isStandalone) {
  9822. const {
  9823. optionalContentConfigPromise
  9824. } = options;
  9825. if (optionalContentConfigPromise) {
  9826. optionalContentConfigPromise.then(optionalContentConfig => {
  9827. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9828. return;
  9829. }
  9830. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  9831. });
  9832. }
  9833. }
  9834. }
  9835. setPdfPage(pdfPage) {
  9836. this.pdfPage = pdfPage;
  9837. this.pdfPageRotate = pdfPage.rotate;
  9838. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9839. this.viewport = pdfPage.getViewport({
  9840. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9841. rotation: totalRotation
  9842. });
  9843. this.reset();
  9844. }
  9845. destroy() {
  9846. this.reset();
  9847. this.pdfPage?.cleanup();
  9848. }
  9849. async _renderAnnotationLayer() {
  9850. let error = null;
  9851. try {
  9852. await this.annotationLayer.render(this.viewport, "display");
  9853. } catch (ex) {
  9854. console.error(`_renderAnnotationLayer: "${ex}".`);
  9855. error = ex;
  9856. } finally {
  9857. this.eventBus.dispatch("annotationlayerrendered", {
  9858. source: this,
  9859. pageNumber: this.id,
  9860. error
  9861. });
  9862. }
  9863. }
  9864. async _renderAnnotationEditorLayer() {
  9865. let error = null;
  9866. try {
  9867. await this.annotationEditorLayer.render(this.viewport, "display");
  9868. } catch (ex) {
  9869. console.error(`_renderAnnotationEditorLayer: "${ex}".`);
  9870. error = ex;
  9871. } finally {
  9872. this.eventBus.dispatch("annotationeditorlayerrendered", {
  9873. source: this,
  9874. pageNumber: this.id,
  9875. error
  9876. });
  9877. }
  9878. }
  9879. async _renderXfaLayer() {
  9880. let error = null;
  9881. try {
  9882. const result = await this.xfaLayer.render(this.viewport, "display");
  9883. if (result?.textDivs && this.textHighlighter) {
  9884. this._buildXfaTextContentItems(result.textDivs);
  9885. }
  9886. } catch (ex) {
  9887. console.error(`_renderXfaLayer: "${ex}".`);
  9888. error = ex;
  9889. } finally {
  9890. this.eventBus.dispatch("xfalayerrendered", {
  9891. source: this,
  9892. pageNumber: this.id,
  9893. error
  9894. });
  9895. }
  9896. }
  9897. async _buildXfaTextContentItems(textDivs) {
  9898. const text = await this.pdfPage.getTextContent();
  9899. const items = [];
  9900. for (const item of text.items) {
  9901. items.push(item.str);
  9902. }
  9903. this.textHighlighter.setTextMapping(textDivs, items);
  9904. this.textHighlighter.enable();
  9905. }
  9906. _resetZoomLayer(removeFromDOM = false) {
  9907. if (!this.zoomLayer) {
  9908. return;
  9909. }
  9910. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9911. this.paintedViewportMap.delete(zoomLayerCanvas);
  9912. zoomLayerCanvas.width = 0;
  9913. zoomLayerCanvas.height = 0;
  9914. if (removeFromDOM) {
  9915. this.zoomLayer.remove();
  9916. }
  9917. this.zoomLayer = null;
  9918. }
  9919. reset({
  9920. keepZoomLayer = false,
  9921. keepAnnotationLayer = false,
  9922. keepAnnotationEditorLayer = false,
  9923. keepXfaLayer = false
  9924. } = {}) {
  9925. this.cancelRendering({
  9926. keepAnnotationLayer,
  9927. keepAnnotationEditorLayer,
  9928. keepXfaLayer
  9929. });
  9930. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  9931. const div = this.div;
  9932. div.style.width = Math.floor(this.viewport.width) + "px";
  9933. div.style.height = Math.floor(this.viewport.height) + "px";
  9934. const childNodes = div.childNodes,
  9935. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  9936. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  9937. annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
  9938. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null;
  9939. for (let i = childNodes.length - 1; i >= 0; i--) {
  9940. const node = childNodes[i];
  9941. switch (node) {
  9942. case zoomLayerNode:
  9943. case annotationLayerNode:
  9944. case annotationEditorLayerNode:
  9945. case xfaLayerNode:
  9946. continue;
  9947. }
  9948. node.remove();
  9949. }
  9950. div.removeAttribute("data-loaded");
  9951. if (annotationLayerNode) {
  9952. this.annotationLayer.hide();
  9953. }
  9954. if (annotationEditorLayerNode) {
  9955. this.annotationEditorLayer.hide();
  9956. } else {
  9957. this.annotationEditorLayer?.destroy();
  9958. }
  9959. if (xfaLayerNode) {
  9960. this.xfaLayer.hide();
  9961. }
  9962. if (!zoomLayerNode) {
  9963. if (this.canvas) {
  9964. this.paintedViewportMap.delete(this.canvas);
  9965. this.canvas.width = 0;
  9966. this.canvas.height = 0;
  9967. delete this.canvas;
  9968. }
  9969. this._resetZoomLayer();
  9970. }
  9971. if (this.svg) {
  9972. this.paintedViewportMap.delete(this.svg);
  9973. delete this.svg;
  9974. }
  9975. this.loadingIconDiv = document.createElement("div");
  9976. this.loadingIconDiv.className = "loadingIcon notVisible";
  9977. if (this._isStandalone) {
  9978. this.toggleLoadingIconSpinner(true);
  9979. }
  9980. this.loadingIconDiv.setAttribute("role", "img");
  9981. this.l10n.get("loading").then(msg => {
  9982. this.loadingIconDiv?.setAttribute("aria-label", msg);
  9983. });
  9984. div.append(this.loadingIconDiv);
  9985. }
  9986. update({
  9987. scale = 0,
  9988. rotation = null,
  9989. optionalContentConfigPromise = null
  9990. }) {
  9991. this.scale = scale || this.scale;
  9992. if (typeof rotation === "number") {
  9993. this.rotation = rotation;
  9994. }
  9995. if (optionalContentConfigPromise instanceof Promise) {
  9996. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9997. optionalContentConfigPromise.then(optionalContentConfig => {
  9998. if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
  9999. return;
  10000. }
  10001. this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
  10002. });
  10003. }
  10004. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  10005. this.viewport = this.viewport.clone({
  10006. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  10007. rotation: totalRotation
  10008. });
  10009. if (this._isStandalone) {
  10010. _ui_utils.docStyle.setProperty("--scale-factor", this.viewport.scale);
  10011. }
  10012. if (this.svg) {
  10013. this.cssTransform({
  10014. target: this.svg,
  10015. redrawAnnotationLayer: true,
  10016. redrawAnnotationEditorLayer: true,
  10017. redrawXfaLayer: true
  10018. });
  10019. this.eventBus.dispatch("pagerendered", {
  10020. source: this,
  10021. pageNumber: this.id,
  10022. cssTransform: true,
  10023. timestamp: performance.now(),
  10024. error: this._renderError
  10025. });
  10026. return;
  10027. }
  10028. let isScalingRestricted = false;
  10029. if (this.canvas && this.maxCanvasPixels > 0) {
  10030. const outputScale = this.outputScale;
  10031. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  10032. isScalingRestricted = true;
  10033. }
  10034. }
  10035. if (this.canvas) {
  10036. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  10037. this.cssTransform({
  10038. target: this.canvas,
  10039. redrawAnnotationLayer: true,
  10040. redrawAnnotationEditorLayer: true,
  10041. redrawXfaLayer: true
  10042. });
  10043. this.eventBus.dispatch("pagerendered", {
  10044. source: this,
  10045. pageNumber: this.id,
  10046. cssTransform: true,
  10047. timestamp: performance.now(),
  10048. error: this._renderError
  10049. });
  10050. return;
  10051. }
  10052. if (!this.zoomLayer && !this.canvas.hidden) {
  10053. this.zoomLayer = this.canvas.parentNode;
  10054. this.zoomLayer.style.position = "absolute";
  10055. }
  10056. }
  10057. if (this.zoomLayer) {
  10058. this.cssTransform({
  10059. target: this.zoomLayer.firstChild
  10060. });
  10061. }
  10062. this.reset({
  10063. keepZoomLayer: true,
  10064. keepAnnotationLayer: true,
  10065. keepAnnotationEditorLayer: true,
  10066. keepXfaLayer: true
  10067. });
  10068. }
  10069. cancelRendering({
  10070. keepAnnotationLayer = false,
  10071. keepAnnotationEditorLayer = false,
  10072. keepXfaLayer = false
  10073. } = {}) {
  10074. if (this.paintTask) {
  10075. this.paintTask.cancel();
  10076. this.paintTask = null;
  10077. }
  10078. this.resume = null;
  10079. if (this.textLayer) {
  10080. this.textLayer.cancel();
  10081. this.textLayer = null;
  10082. }
  10083. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  10084. this.annotationLayer.cancel();
  10085. this.annotationLayer = null;
  10086. this._annotationCanvasMap = null;
  10087. }
  10088. if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
  10089. this.annotationEditorLayer.cancel();
  10090. this.annotationEditorLayer = null;
  10091. }
  10092. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  10093. this.xfaLayer.cancel();
  10094. this.xfaLayer = null;
  10095. this.textHighlighter?.disable();
  10096. }
  10097. if (this._onTextLayerRendered) {
  10098. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  10099. this._onTextLayerRendered = null;
  10100. }
  10101. }
  10102. cssTransform({
  10103. target,
  10104. redrawAnnotationLayer = false,
  10105. redrawAnnotationEditorLayer = false,
  10106. redrawXfaLayer = false
  10107. }) {
  10108. const width = this.viewport.width;
  10109. const height = this.viewport.height;
  10110. const div = this.div;
  10111. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  10112. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  10113. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  10114. const absRotation = Math.abs(relativeRotation);
  10115. let scaleX = 1,
  10116. scaleY = 1;
  10117. if (absRotation === 90 || absRotation === 270) {
  10118. scaleX = height / width;
  10119. scaleY = width / height;
  10120. }
  10121. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  10122. if (this.textLayer) {
  10123. const textLayerViewport = this.textLayer.viewport;
  10124. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  10125. const textAbsRotation = Math.abs(textRelativeRotation);
  10126. let scale = width / textLayerViewport.width;
  10127. if (textAbsRotation === 90 || textAbsRotation === 270) {
  10128. scale = width / textLayerViewport.height;
  10129. }
  10130. const textLayerDiv = this.textLayer.textLayerDiv;
  10131. let transX, transY;
  10132. switch (textAbsRotation) {
  10133. case 0:
  10134. transX = transY = 0;
  10135. break;
  10136. case 90:
  10137. transX = 0;
  10138. transY = "-" + textLayerDiv.style.height;
  10139. break;
  10140. case 180:
  10141. transX = "-" + textLayerDiv.style.width;
  10142. transY = "-" + textLayerDiv.style.height;
  10143. break;
  10144. case 270:
  10145. transX = "-" + textLayerDiv.style.width;
  10146. transY = 0;
  10147. break;
  10148. default:
  10149. console.error("Bad rotation value.");
  10150. break;
  10151. }
  10152. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  10153. textLayerDiv.style.transformOrigin = "0% 0%";
  10154. }
  10155. if (redrawAnnotationLayer && this.annotationLayer) {
  10156. this._renderAnnotationLayer();
  10157. }
  10158. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  10159. this._renderAnnotationEditorLayer();
  10160. }
  10161. if (redrawXfaLayer && this.xfaLayer) {
  10162. this._renderXfaLayer();
  10163. }
  10164. }
  10165. get width() {
  10166. return this.viewport.width;
  10167. }
  10168. get height() {
  10169. return this.viewport.height;
  10170. }
  10171. getPagePoint(x, y) {
  10172. return this.viewport.convertToPdfPoint(x, y);
  10173. }
  10174. toggleLoadingIconSpinner(viewVisible = false) {
  10175. this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
  10176. }
  10177. draw() {
  10178. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  10179. console.error("Must be in new state before drawing");
  10180. this.reset();
  10181. }
  10182. const {
  10183. div,
  10184. pdfPage
  10185. } = this;
  10186. if (!pdfPage) {
  10187. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10188. if (this.loadingIconDiv) {
  10189. this.loadingIconDiv.remove();
  10190. delete this.loadingIconDiv;
  10191. }
  10192. return Promise.reject(new Error("pdfPage is not loaded"));
  10193. }
  10194. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10195. const canvasWrapper = document.createElement("div");
  10196. canvasWrapper.style.width = div.style.width;
  10197. canvasWrapper.style.height = div.style.height;
  10198. canvasWrapper.classList.add("canvasWrapper");
  10199. const lastDivBeforeTextDiv = this.annotationLayer?.div || this.annotationEditorLayer?.div;
  10200. if (lastDivBeforeTextDiv) {
  10201. lastDivBeforeTextDiv.before(canvasWrapper);
  10202. } else {
  10203. div.append(canvasWrapper);
  10204. }
  10205. let textLayer = null;
  10206. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  10207. this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
  10208. const textLayerDiv = document.createElement("div");
  10209. textLayerDiv.className = "textLayer";
  10210. textLayerDiv.style.width = canvasWrapper.style.width;
  10211. textLayerDiv.style.height = canvasWrapper.style.height;
  10212. if (lastDivBeforeTextDiv) {
  10213. lastDivBeforeTextDiv.before(textLayerDiv);
  10214. } else {
  10215. div.append(textLayerDiv);
  10216. }
  10217. textLayer = this.textLayerFactory.createTextLayerBuilder({
  10218. textLayerDiv,
  10219. pageIndex: this.id - 1,
  10220. viewport: this.viewport,
  10221. eventBus: this.eventBus,
  10222. highlighter: this.textHighlighter,
  10223. accessibilityManager: this._accessibilityManager
  10224. });
  10225. }
  10226. this.textLayer = textLayer;
  10227. if (this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE && this.annotationLayerFactory) {
  10228. this._annotationCanvasMap ||= new Map();
  10229. this.annotationLayer ||= this.annotationLayerFactory.createAnnotationLayerBuilder({
  10230. pageDiv: div,
  10231. pdfPage,
  10232. imageResourcesPath: this.imageResourcesPath,
  10233. renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  10234. l10n: this.l10n,
  10235. annotationCanvasMap: this._annotationCanvasMap,
  10236. accessibilityManager: this._accessibilityManager
  10237. });
  10238. }
  10239. if (this.xfaLayer?.div) {
  10240. div.append(this.xfaLayer.div);
  10241. }
  10242. let renderContinueCallback = null;
  10243. if (this.renderingQueue) {
  10244. renderContinueCallback = cont => {
  10245. if (!this.renderingQueue.isHighestPriority(this)) {
  10246. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  10247. this.resume = () => {
  10248. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  10249. cont();
  10250. };
  10251. return;
  10252. }
  10253. cont();
  10254. };
  10255. }
  10256. const finishPaintTask = async (error = null) => {
  10257. if (paintTask === this.paintTask) {
  10258. this.paintTask = null;
  10259. }
  10260. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  10261. this._renderError = null;
  10262. return;
  10263. }
  10264. this._renderError = error;
  10265. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10266. if (this.loadingIconDiv) {
  10267. this.loadingIconDiv.remove();
  10268. delete this.loadingIconDiv;
  10269. }
  10270. this._resetZoomLayer(true);
  10271. this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
  10272. this.eventBus.dispatch("pagerendered", {
  10273. source: this,
  10274. pageNumber: this.id,
  10275. cssTransform: false,
  10276. timestamp: performance.now(),
  10277. error: this._renderError
  10278. });
  10279. if (error) {
  10280. throw error;
  10281. }
  10282. };
  10283. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  10284. paintTask.onRenderContinue = renderContinueCallback;
  10285. this.paintTask = paintTask;
  10286. const resultPromise = paintTask.promise.then(() => {
  10287. return finishPaintTask(null).then(() => {
  10288. if (textLayer) {
  10289. const readableStream = pdfPage.streamTextContent({
  10290. includeMarkedContent: true
  10291. });
  10292. textLayer.setTextContentStream(readableStream);
  10293. textLayer.render();
  10294. }
  10295. if (this.annotationLayer) {
  10296. this._renderAnnotationLayer().then(() => {
  10297. if (this.annotationEditorLayerFactory) {
  10298. this.annotationEditorLayer ||= this.annotationEditorLayerFactory.createAnnotationEditorLayerBuilder({
  10299. pageDiv: div,
  10300. pdfPage,
  10301. l10n: this.l10n,
  10302. accessibilityManager: this._accessibilityManager
  10303. });
  10304. this._renderAnnotationEditorLayer();
  10305. }
  10306. });
  10307. }
  10308. });
  10309. }, function (reason) {
  10310. return finishPaintTask(reason);
  10311. });
  10312. if (this.xfaLayerFactory) {
  10313. this.xfaLayer ||= this.xfaLayerFactory.createXfaLayerBuilder({
  10314. pageDiv: div,
  10315. pdfPage
  10316. });
  10317. this._renderXfaLayer();
  10318. }
  10319. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  10320. this._onTextLayerRendered = event => {
  10321. if (event.pageNumber !== this.id) {
  10322. return;
  10323. }
  10324. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  10325. this._onTextLayerRendered = null;
  10326. if (!this.canvas) {
  10327. return;
  10328. }
  10329. this.pdfPage.getStructTree().then(tree => {
  10330. if (!tree) {
  10331. return;
  10332. }
  10333. if (!this.canvas) {
  10334. return;
  10335. }
  10336. const treeDom = this.structTreeLayer.render(tree);
  10337. treeDom.classList.add("structTree");
  10338. this.canvas.append(treeDom);
  10339. });
  10340. };
  10341. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  10342. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder({
  10343. pdfPage
  10344. });
  10345. }
  10346. div.setAttribute("data-loaded", true);
  10347. this.eventBus.dispatch("pagerender", {
  10348. source: this,
  10349. pageNumber: this.id
  10350. });
  10351. return resultPromise;
  10352. }
  10353. paintOnCanvas(canvasWrapper) {
  10354. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  10355. const result = {
  10356. promise: renderCapability.promise,
  10357. onRenderContinue(cont) {
  10358. cont();
  10359. },
  10360. cancel() {
  10361. renderTask.cancel();
  10362. },
  10363. get separateAnnots() {
  10364. return renderTask.separateAnnots;
  10365. }
  10366. };
  10367. const viewport = this.viewport;
  10368. const canvas = document.createElement("canvas");
  10369. canvas.setAttribute("role", "presentation");
  10370. canvas.hidden = true;
  10371. let isCanvasHidden = true;
  10372. const showCanvas = function () {
  10373. if (isCanvasHidden) {
  10374. canvas.hidden = false;
  10375. isCanvasHidden = false;
  10376. }
  10377. };
  10378. canvasWrapper.append(canvas);
  10379. this.canvas = canvas;
  10380. const ctx = canvas.getContext("2d", {
  10381. alpha: false
  10382. });
  10383. const outputScale = this.outputScale = new _ui_utils.OutputScale();
  10384. if (this.useOnlyCssZoom) {
  10385. const actualSizeViewport = viewport.clone({
  10386. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10387. });
  10388. outputScale.sx *= actualSizeViewport.width / viewport.width;
  10389. outputScale.sy *= actualSizeViewport.height / viewport.height;
  10390. }
  10391. if (this.maxCanvasPixels > 0) {
  10392. const pixelsInViewport = viewport.width * viewport.height;
  10393. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  10394. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  10395. outputScale.sx = maxScale;
  10396. outputScale.sy = maxScale;
  10397. this.hasRestrictedScaling = true;
  10398. } else {
  10399. this.hasRestrictedScaling = false;
  10400. }
  10401. }
  10402. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  10403. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  10404. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  10405. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  10406. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  10407. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  10408. this.paintedViewportMap.set(canvas, viewport);
  10409. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  10410. const renderContext = {
  10411. canvasContext: ctx,
  10412. transform,
  10413. viewport: this.viewport,
  10414. annotationMode: this.#annotationMode,
  10415. optionalContentConfigPromise: this._optionalContentConfigPromise,
  10416. annotationCanvasMap: this._annotationCanvasMap,
  10417. pageColors: this.pageColors
  10418. };
  10419. const renderTask = this.pdfPage.render(renderContext);
  10420. renderTask.onContinue = function (cont) {
  10421. showCanvas();
  10422. if (result.onRenderContinue) {
  10423. result.onRenderContinue(cont);
  10424. } else {
  10425. cont();
  10426. }
  10427. };
  10428. renderTask.promise.then(function () {
  10429. showCanvas();
  10430. renderCapability.resolve();
  10431. }, function (error) {
  10432. showCanvas();
  10433. renderCapability.reject(error);
  10434. });
  10435. return result;
  10436. }
  10437. paintOnSvg(wrapper) {
  10438. let cancelled = false;
  10439. const ensureNotCancelled = () => {
  10440. if (cancelled) {
  10441. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  10442. }
  10443. };
  10444. const pdfPage = this.pdfPage;
  10445. const actualSizeViewport = this.viewport.clone({
  10446. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10447. });
  10448. const promise = pdfPage.getOperatorList({
  10449. annotationMode: this.#annotationMode
  10450. }).then(opList => {
  10451. ensureNotCancelled();
  10452. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  10453. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  10454. ensureNotCancelled();
  10455. this.svg = svg;
  10456. this.paintedViewportMap.set(svg, actualSizeViewport);
  10457. svg.style.width = wrapper.style.width;
  10458. svg.style.height = wrapper.style.height;
  10459. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  10460. wrapper.append(svg);
  10461. });
  10462. });
  10463. return {
  10464. promise,
  10465. onRenderContinue(cont) {
  10466. cont();
  10467. },
  10468. cancel() {
  10469. cancelled = true;
  10470. },
  10471. get separateAnnots() {
  10472. return false;
  10473. }
  10474. };
  10475. }
  10476. setPageLabel(label) {
  10477. this.pageLabel = typeof label === "string" ? label : null;
  10478. if (this.pageLabel !== null) {
  10479. this.div.setAttribute("data-page-label", this.pageLabel);
  10480. } else {
  10481. this.div.removeAttribute("data-page-label");
  10482. }
  10483. }
  10484. get thumbnailCanvas() {
  10485. const {
  10486. initialOptionalContent,
  10487. regularAnnotations
  10488. } = this.#useThumbnailCanvas;
  10489. return initialOptionalContent && regularAnnotations ? this.canvas : null;
  10490. }
  10491. }
  10492. exports.PDFPageView = PDFPageView;
  10493. /***/ }),
  10494. /* 33 */
  10495. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10496. Object.defineProperty(exports, "__esModule", ({
  10497. value: true
  10498. }));
  10499. exports.TextAccessibilityManager = void 0;
  10500. var _ui_utils = __webpack_require__(1);
  10501. class TextAccessibilityManager {
  10502. #enabled = false;
  10503. #textChildren = null;
  10504. #textNodes = new Map();
  10505. #waitingElements = new Map();
  10506. setTextMapping(textDivs) {
  10507. this.#textChildren = textDivs;
  10508. }
  10509. static #compareElementPositions(e1, e2) {
  10510. const rect1 = e1.getBoundingClientRect();
  10511. const rect2 = e2.getBoundingClientRect();
  10512. if (rect1.width === 0 && rect1.height === 0) {
  10513. return +1;
  10514. }
  10515. if (rect2.width === 0 && rect2.height === 0) {
  10516. return -1;
  10517. }
  10518. const top1 = rect1.y;
  10519. const bot1 = rect1.y + rect1.height;
  10520. const mid1 = rect1.y + rect1.height / 2;
  10521. const top2 = rect2.y;
  10522. const bot2 = rect2.y + rect2.height;
  10523. const mid2 = rect2.y + rect2.height / 2;
  10524. if (mid1 <= top2 && mid2 >= bot1) {
  10525. return -1;
  10526. }
  10527. if (mid2 <= top1 && mid1 >= bot2) {
  10528. return +1;
  10529. }
  10530. const centerX1 = rect1.x + rect1.width / 2;
  10531. const centerX2 = rect2.x + rect2.width / 2;
  10532. return centerX1 - centerX2;
  10533. }
  10534. enable() {
  10535. if (this.#enabled) {
  10536. throw new Error("TextAccessibilityManager is already enabled.");
  10537. }
  10538. if (!this.#textChildren) {
  10539. throw new Error("Text divs and strings have not been set.");
  10540. }
  10541. this.#enabled = true;
  10542. this.#textChildren = this.#textChildren.slice();
  10543. this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
  10544. if (this.#textNodes.size > 0) {
  10545. const textChildren = this.#textChildren;
  10546. for (const [id, nodeIndex] of this.#textNodes) {
  10547. const element = document.getElementById(id);
  10548. if (!element) {
  10549. this.#textNodes.delete(id);
  10550. continue;
  10551. }
  10552. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  10553. }
  10554. }
  10555. for (const [element, isRemovable] of this.#waitingElements) {
  10556. this.addPointerInTextLayer(element, isRemovable);
  10557. }
  10558. this.#waitingElements.clear();
  10559. }
  10560. disable() {
  10561. if (!this.#enabled) {
  10562. return;
  10563. }
  10564. this.#waitingElements.clear();
  10565. this.#textChildren = null;
  10566. this.#enabled = false;
  10567. }
  10568. removePointerInTextLayer(element) {
  10569. if (!this.#enabled) {
  10570. this.#waitingElements.delete(element);
  10571. return;
  10572. }
  10573. const children = this.#textChildren;
  10574. if (!children || children.length === 0) {
  10575. return;
  10576. }
  10577. const {
  10578. id
  10579. } = element;
  10580. const nodeIndex = this.#textNodes.get(id);
  10581. if (nodeIndex === undefined) {
  10582. return;
  10583. }
  10584. const node = children[nodeIndex];
  10585. this.#textNodes.delete(id);
  10586. let owns = node.getAttribute("aria-owns");
  10587. if (owns?.includes(id)) {
  10588. owns = owns.split(" ").filter(x => x !== id).join(" ");
  10589. if (owns) {
  10590. node.setAttribute("aria-owns", owns);
  10591. } else {
  10592. node.removeAttribute("aria-owns");
  10593. node.setAttribute("role", "presentation");
  10594. }
  10595. }
  10596. }
  10597. #addIdToAriaOwns(id, node) {
  10598. const owns = node.getAttribute("aria-owns");
  10599. if (!owns?.includes(id)) {
  10600. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  10601. }
  10602. node.removeAttribute("role");
  10603. }
  10604. addPointerInTextLayer(element, isRemovable) {
  10605. const {
  10606. id
  10607. } = element;
  10608. if (!id) {
  10609. return;
  10610. }
  10611. if (!this.#enabled) {
  10612. this.#waitingElements.set(element, isRemovable);
  10613. return;
  10614. }
  10615. if (isRemovable) {
  10616. this.removePointerInTextLayer(element);
  10617. }
  10618. const children = this.#textChildren;
  10619. if (!children || children.length === 0) {
  10620. return;
  10621. }
  10622. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
  10623. const nodeIndex = Math.max(0, index - 1);
  10624. this.#addIdToAriaOwns(id, children[nodeIndex]);
  10625. this.#textNodes.set(id, nodeIndex);
  10626. }
  10627. moveElementInDOM(container, element, contentElement, isRemovable) {
  10628. this.addPointerInTextLayer(contentElement, isRemovable);
  10629. if (!container.hasChildNodes()) {
  10630. container.append(element);
  10631. return;
  10632. }
  10633. const children = Array.from(container.childNodes).filter(node => node !== element);
  10634. if (children.length === 0) {
  10635. return;
  10636. }
  10637. const elementToCompare = contentElement || element;
  10638. const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
  10639. if (index === 0) {
  10640. children[0].before(element);
  10641. } else {
  10642. children[index - 1].after(element);
  10643. }
  10644. }
  10645. }
  10646. exports.TextAccessibilityManager = TextAccessibilityManager;
  10647. /***/ }),
  10648. /* 34 */
  10649. /***/ ((__unused_webpack_module, exports) => {
  10650. Object.defineProperty(exports, "__esModule", ({
  10651. value: true
  10652. }));
  10653. exports.StructTreeLayerBuilder = void 0;
  10654. const PDF_ROLE_TO_HTML_ROLE = {
  10655. Document: null,
  10656. DocumentFragment: null,
  10657. Part: "group",
  10658. Sect: "group",
  10659. Div: "group",
  10660. Aside: "note",
  10661. NonStruct: "none",
  10662. P: null,
  10663. H: "heading",
  10664. Title: null,
  10665. FENote: "note",
  10666. Sub: "group",
  10667. Lbl: null,
  10668. Span: null,
  10669. Em: null,
  10670. Strong: null,
  10671. Link: "link",
  10672. Annot: "note",
  10673. Form: "form",
  10674. Ruby: null,
  10675. RB: null,
  10676. RT: null,
  10677. RP: null,
  10678. Warichu: null,
  10679. WT: null,
  10680. WP: null,
  10681. L: "list",
  10682. LI: "listitem",
  10683. LBody: null,
  10684. Table: "table",
  10685. TR: "row",
  10686. TH: "columnheader",
  10687. TD: "cell",
  10688. THead: "columnheader",
  10689. TBody: null,
  10690. TFoot: null,
  10691. Caption: null,
  10692. Figure: "figure",
  10693. Formula: null,
  10694. Artifact: null
  10695. };
  10696. const HEADING_PATTERN = /^H(\d+)$/;
  10697. class StructTreeLayerBuilder {
  10698. constructor({
  10699. pdfPage
  10700. }) {
  10701. this.pdfPage = pdfPage;
  10702. }
  10703. render(structTree) {
  10704. return this._walk(structTree);
  10705. }
  10706. _setAttributes(structElement, htmlElement) {
  10707. if (structElement.alt !== undefined) {
  10708. htmlElement.setAttribute("aria-label", structElement.alt);
  10709. }
  10710. if (structElement.id !== undefined) {
  10711. htmlElement.setAttribute("aria-owns", structElement.id);
  10712. }
  10713. if (structElement.lang !== undefined) {
  10714. htmlElement.setAttribute("lang", structElement.lang);
  10715. }
  10716. }
  10717. _walk(node) {
  10718. if (!node) {
  10719. return null;
  10720. }
  10721. const element = document.createElement("span");
  10722. if ("role" in node) {
  10723. const {
  10724. role
  10725. } = node;
  10726. const match = role.match(HEADING_PATTERN);
  10727. if (match) {
  10728. element.setAttribute("role", "heading");
  10729. element.setAttribute("aria-level", match[1]);
  10730. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  10731. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  10732. }
  10733. }
  10734. this._setAttributes(node, element);
  10735. if (node.children) {
  10736. if (node.children.length === 1 && "id" in node.children[0]) {
  10737. this._setAttributes(node.children[0], element);
  10738. } else {
  10739. for (const kid of node.children) {
  10740. element.append(this._walk(kid));
  10741. }
  10742. }
  10743. }
  10744. return element;
  10745. }
  10746. }
  10747. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  10748. /***/ }),
  10749. /* 35 */
  10750. /***/ ((__unused_webpack_module, exports) => {
  10751. Object.defineProperty(exports, "__esModule", ({
  10752. value: true
  10753. }));
  10754. exports.TextHighlighter = void 0;
  10755. class TextHighlighter {
  10756. constructor({
  10757. findController,
  10758. eventBus,
  10759. pageIndex
  10760. }) {
  10761. this.findController = findController;
  10762. this.matches = [];
  10763. this.eventBus = eventBus;
  10764. this.pageIdx = pageIndex;
  10765. this._onUpdateTextLayerMatches = null;
  10766. this.textDivs = null;
  10767. this.textContentItemsStr = null;
  10768. this.enabled = false;
  10769. }
  10770. setTextMapping(divs, texts) {
  10771. this.textDivs = divs;
  10772. this.textContentItemsStr = texts;
  10773. }
  10774. enable() {
  10775. if (!this.textDivs || !this.textContentItemsStr) {
  10776. throw new Error("Text divs and strings have not been set.");
  10777. }
  10778. if (this.enabled) {
  10779. throw new Error("TextHighlighter is already enabled.");
  10780. }
  10781. this.enabled = true;
  10782. if (!this._onUpdateTextLayerMatches) {
  10783. this._onUpdateTextLayerMatches = evt => {
  10784. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  10785. this._updateMatches();
  10786. }
  10787. };
  10788. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10789. }
  10790. this._updateMatches();
  10791. }
  10792. disable() {
  10793. if (!this.enabled) {
  10794. return;
  10795. }
  10796. this.enabled = false;
  10797. if (this._onUpdateTextLayerMatches) {
  10798. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  10799. this._onUpdateTextLayerMatches = null;
  10800. }
  10801. }
  10802. _convertMatches(matches, matchesLength) {
  10803. if (!matches) {
  10804. return [];
  10805. }
  10806. const {
  10807. textContentItemsStr
  10808. } = this;
  10809. let i = 0,
  10810. iIndex = 0;
  10811. const end = textContentItemsStr.length - 1;
  10812. const result = [];
  10813. for (let m = 0, mm = matches.length; m < mm; m++) {
  10814. let matchIdx = matches[m];
  10815. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  10816. iIndex += textContentItemsStr[i].length;
  10817. i++;
  10818. }
  10819. if (i === textContentItemsStr.length) {
  10820. console.error("Could not find a matching mapping");
  10821. }
  10822. const match = {
  10823. begin: {
  10824. divIdx: i,
  10825. offset: matchIdx - iIndex
  10826. }
  10827. };
  10828. matchIdx += matchesLength[m];
  10829. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  10830. iIndex += textContentItemsStr[i].length;
  10831. i++;
  10832. }
  10833. match.end = {
  10834. divIdx: i,
  10835. offset: matchIdx - iIndex
  10836. };
  10837. result.push(match);
  10838. }
  10839. return result;
  10840. }
  10841. _renderMatches(matches) {
  10842. if (matches.length === 0) {
  10843. return;
  10844. }
  10845. const {
  10846. findController,
  10847. pageIdx
  10848. } = this;
  10849. const {
  10850. textContentItemsStr,
  10851. textDivs
  10852. } = this;
  10853. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  10854. const selectedMatchIdx = findController.selected.matchIdx;
  10855. const highlightAll = findController.state.highlightAll;
  10856. let prevEnd = null;
  10857. const infinity = {
  10858. divIdx: -1,
  10859. offset: undefined
  10860. };
  10861. function beginText(begin, className) {
  10862. const divIdx = begin.divIdx;
  10863. textDivs[divIdx].textContent = "";
  10864. return appendTextToDiv(divIdx, 0, begin.offset, className);
  10865. }
  10866. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  10867. let div = textDivs[divIdx];
  10868. if (div.nodeType === Node.TEXT_NODE) {
  10869. const span = document.createElement("span");
  10870. div.before(span);
  10871. span.append(div);
  10872. textDivs[divIdx] = span;
  10873. div = span;
  10874. }
  10875. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  10876. const node = document.createTextNode(content);
  10877. if (className) {
  10878. const span = document.createElement("span");
  10879. span.className = `${className} appended`;
  10880. span.append(node);
  10881. div.append(span);
  10882. return className.includes("selected") ? span.offsetLeft : 0;
  10883. }
  10884. div.append(node);
  10885. return 0;
  10886. }
  10887. let i0 = selectedMatchIdx,
  10888. i1 = i0 + 1;
  10889. if (highlightAll) {
  10890. i0 = 0;
  10891. i1 = matches.length;
  10892. } else if (!isSelectedPage) {
  10893. return;
  10894. }
  10895. for (let i = i0; i < i1; i++) {
  10896. const match = matches[i];
  10897. const begin = match.begin;
  10898. const end = match.end;
  10899. const isSelected = isSelectedPage && i === selectedMatchIdx;
  10900. const highlightSuffix = isSelected ? " selected" : "";
  10901. let selectedLeft = 0;
  10902. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  10903. if (prevEnd !== null) {
  10904. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10905. }
  10906. beginText(begin);
  10907. } else {
  10908. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  10909. }
  10910. if (begin.divIdx === end.divIdx) {
  10911. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  10912. } else {
  10913. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  10914. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  10915. textDivs[n0].className = "highlight middle" + highlightSuffix;
  10916. }
  10917. beginText(end, "highlight end" + highlightSuffix);
  10918. }
  10919. prevEnd = end;
  10920. if (isSelected) {
  10921. findController.scrollMatchIntoView({
  10922. element: textDivs[begin.divIdx],
  10923. selectedLeft,
  10924. pageIndex: pageIdx,
  10925. matchIndex: selectedMatchIdx
  10926. });
  10927. }
  10928. }
  10929. if (prevEnd) {
  10930. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10931. }
  10932. }
  10933. _updateMatches() {
  10934. if (!this.enabled) {
  10935. return;
  10936. }
  10937. const {
  10938. findController,
  10939. matches,
  10940. pageIdx
  10941. } = this;
  10942. const {
  10943. textContentItemsStr,
  10944. textDivs
  10945. } = this;
  10946. let clearedUntilDivIdx = -1;
  10947. for (const match of matches) {
  10948. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  10949. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  10950. const div = textDivs[n];
  10951. div.textContent = textContentItemsStr[n];
  10952. div.className = "";
  10953. }
  10954. clearedUntilDivIdx = match.end.divIdx + 1;
  10955. }
  10956. if (!findController?.highlightMatches) {
  10957. return;
  10958. }
  10959. const pageMatches = findController.pageMatches[pageIdx] || null;
  10960. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  10961. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  10962. this._renderMatches(this.matches);
  10963. }
  10964. }
  10965. exports.TextHighlighter = TextHighlighter;
  10966. /***/ }),
  10967. /* 36 */
  10968. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10969. Object.defineProperty(exports, "__esModule", ({
  10970. value: true
  10971. }));
  10972. exports.TextLayerBuilder = void 0;
  10973. var _pdfjsLib = __webpack_require__(5);
  10974. class TextLayerBuilder {
  10975. constructor({
  10976. textLayerDiv,
  10977. eventBus,
  10978. pageIndex,
  10979. viewport,
  10980. highlighter = null,
  10981. accessibilityManager = null
  10982. }) {
  10983. this.textLayerDiv = textLayerDiv;
  10984. this.eventBus = eventBus;
  10985. this.textContent = null;
  10986. this.textContentItemsStr = [];
  10987. this.textContentStream = null;
  10988. this.renderingDone = false;
  10989. this.pageNumber = pageIndex + 1;
  10990. this.viewport = viewport;
  10991. this.textDivs = [];
  10992. this.textLayerRenderTask = null;
  10993. this.highlighter = highlighter;
  10994. this.accessibilityManager = accessibilityManager;
  10995. this.#bindMouse();
  10996. }
  10997. #finishRendering() {
  10998. this.renderingDone = true;
  10999. const endOfContent = document.createElement("div");
  11000. endOfContent.className = "endOfContent";
  11001. this.textLayerDiv.append(endOfContent);
  11002. this.eventBus.dispatch("textlayerrendered", {
  11003. source: this,
  11004. pageNumber: this.pageNumber,
  11005. numTextDivs: this.textDivs.length
  11006. });
  11007. }
  11008. render(timeout = 0) {
  11009. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  11010. return;
  11011. }
  11012. this.cancel();
  11013. this.textDivs.length = 0;
  11014. this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
  11015. this.accessibilityManager?.setTextMapping(this.textDivs);
  11016. const textLayerFrag = document.createDocumentFragment();
  11017. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  11018. textContent: this.textContent,
  11019. textContentStream: this.textContentStream,
  11020. container: textLayerFrag,
  11021. viewport: this.viewport,
  11022. textDivs: this.textDivs,
  11023. textContentItemsStr: this.textContentItemsStr,
  11024. timeout
  11025. });
  11026. this.textLayerRenderTask.promise.then(() => {
  11027. this.textLayerDiv.append(textLayerFrag);
  11028. this.#finishRendering();
  11029. this.highlighter?.enable();
  11030. this.accessibilityManager?.enable();
  11031. }, function (reason) {});
  11032. }
  11033. cancel() {
  11034. if (this.textLayerRenderTask) {
  11035. this.textLayerRenderTask.cancel();
  11036. this.textLayerRenderTask = null;
  11037. }
  11038. this.highlighter?.disable();
  11039. this.accessibilityManager?.disable();
  11040. }
  11041. setTextContentStream(readableStream) {
  11042. this.cancel();
  11043. this.textContentStream = readableStream;
  11044. }
  11045. setTextContent(textContent) {
  11046. this.cancel();
  11047. this.textContent = textContent;
  11048. }
  11049. #bindMouse() {
  11050. const div = this.textLayerDiv;
  11051. div.addEventListener("mousedown", evt => {
  11052. const end = div.querySelector(".endOfContent");
  11053. if (!end) {
  11054. return;
  11055. }
  11056. let adjustTop = evt.target !== div;
  11057. adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  11058. if (adjustTop) {
  11059. const divBounds = div.getBoundingClientRect();
  11060. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  11061. end.style.top = (r * 100).toFixed(2) + "%";
  11062. }
  11063. end.classList.add("active");
  11064. });
  11065. div.addEventListener("mouseup", () => {
  11066. const end = div.querySelector(".endOfContent");
  11067. if (!end) {
  11068. return;
  11069. }
  11070. end.style.top = "";
  11071. end.classList.remove("active");
  11072. });
  11073. }
  11074. }
  11075. exports.TextLayerBuilder = TextLayerBuilder;
  11076. /***/ }),
  11077. /* 37 */
  11078. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11079. Object.defineProperty(exports, "__esModule", ({
  11080. value: true
  11081. }));
  11082. exports.XfaLayerBuilder = void 0;
  11083. var _pdfjsLib = __webpack_require__(5);
  11084. class XfaLayerBuilder {
  11085. constructor({
  11086. pageDiv,
  11087. pdfPage,
  11088. annotationStorage = null,
  11089. linkService,
  11090. xfaHtml = null
  11091. }) {
  11092. this.pageDiv = pageDiv;
  11093. this.pdfPage = pdfPage;
  11094. this.annotationStorage = annotationStorage;
  11095. this.linkService = linkService;
  11096. this.xfaHtml = xfaHtml;
  11097. this.div = null;
  11098. this._cancelled = false;
  11099. }
  11100. render(viewport, intent = "display") {
  11101. if (intent === "print") {
  11102. const parameters = {
  11103. viewport: viewport.clone({
  11104. dontFlip: true
  11105. }),
  11106. div: this.div,
  11107. xfaHtml: this.xfaHtml,
  11108. annotationStorage: this.annotationStorage,
  11109. linkService: this.linkService,
  11110. intent
  11111. };
  11112. const div = document.createElement("div");
  11113. this.pageDiv.append(div);
  11114. parameters.div = div;
  11115. const result = _pdfjsLib.XfaLayer.render(parameters);
  11116. return Promise.resolve(result);
  11117. }
  11118. return this.pdfPage.getXfa().then(xfaHtml => {
  11119. if (this._cancelled || !xfaHtml) {
  11120. return {
  11121. textDivs: []
  11122. };
  11123. }
  11124. const parameters = {
  11125. viewport: viewport.clone({
  11126. dontFlip: true
  11127. }),
  11128. div: this.div,
  11129. xfaHtml,
  11130. annotationStorage: this.annotationStorage,
  11131. linkService: this.linkService,
  11132. intent
  11133. };
  11134. if (this.div) {
  11135. return _pdfjsLib.XfaLayer.update(parameters);
  11136. }
  11137. this.div = document.createElement("div");
  11138. this.pageDiv.append(this.div);
  11139. parameters.div = this.div;
  11140. return _pdfjsLib.XfaLayer.render(parameters);
  11141. }).catch(error => {
  11142. console.error(error);
  11143. });
  11144. }
  11145. cancel() {
  11146. this._cancelled = true;
  11147. }
  11148. hide() {
  11149. if (!this.div) {
  11150. return;
  11151. }
  11152. this.div.hidden = true;
  11153. }
  11154. }
  11155. exports.XfaLayerBuilder = XfaLayerBuilder;
  11156. /***/ }),
  11157. /* 38 */
  11158. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11159. Object.defineProperty(exports, "__esModule", ({
  11160. value: true
  11161. }));
  11162. exports.SecondaryToolbar = void 0;
  11163. var _ui_utils = __webpack_require__(1);
  11164. var _pdf_cursor_tools = __webpack_require__(7);
  11165. var _pdf_viewer = __webpack_require__(28);
  11166. class SecondaryToolbar {
  11167. constructor(options, eventBus, externalServices) {
  11168. this.toolbar = options.toolbar;
  11169. this.toggleButton = options.toggleButton;
  11170. this.buttons = [{
  11171. element: options.presentationModeButton,
  11172. eventName: "presentationmode",
  11173. close: true
  11174. }, {
  11175. element: options.printButton,
  11176. eventName: "print",
  11177. close: true
  11178. }, {
  11179. element: options.downloadButton,
  11180. eventName: "download",
  11181. close: true
  11182. }, {
  11183. element: options.viewBookmarkButton,
  11184. eventName: null,
  11185. close: true
  11186. }, {
  11187. element: options.firstPageButton,
  11188. eventName: "firstpage",
  11189. close: true
  11190. }, {
  11191. element: options.lastPageButton,
  11192. eventName: "lastpage",
  11193. close: true
  11194. }, {
  11195. element: options.pageRotateCwButton,
  11196. eventName: "rotatecw",
  11197. close: false
  11198. }, {
  11199. element: options.pageRotateCcwButton,
  11200. eventName: "rotateccw",
  11201. close: false
  11202. }, {
  11203. element: options.cursorSelectToolButton,
  11204. eventName: "switchcursortool",
  11205. eventDetails: {
  11206. tool: _pdf_cursor_tools.CursorTool.SELECT
  11207. },
  11208. close: true
  11209. }, {
  11210. element: options.cursorHandToolButton,
  11211. eventName: "switchcursortool",
  11212. eventDetails: {
  11213. tool: _pdf_cursor_tools.CursorTool.HAND
  11214. },
  11215. close: true
  11216. }, {
  11217. element: options.scrollPageButton,
  11218. eventName: "switchscrollmode",
  11219. eventDetails: {
  11220. mode: _ui_utils.ScrollMode.PAGE
  11221. },
  11222. close: true
  11223. }, {
  11224. element: options.scrollVerticalButton,
  11225. eventName: "switchscrollmode",
  11226. eventDetails: {
  11227. mode: _ui_utils.ScrollMode.VERTICAL
  11228. },
  11229. close: true
  11230. }, {
  11231. element: options.scrollHorizontalButton,
  11232. eventName: "switchscrollmode",
  11233. eventDetails: {
  11234. mode: _ui_utils.ScrollMode.HORIZONTAL
  11235. },
  11236. close: true
  11237. }, {
  11238. element: options.scrollWrappedButton,
  11239. eventName: "switchscrollmode",
  11240. eventDetails: {
  11241. mode: _ui_utils.ScrollMode.WRAPPED
  11242. },
  11243. close: true
  11244. }, {
  11245. element: options.spreadNoneButton,
  11246. eventName: "switchspreadmode",
  11247. eventDetails: {
  11248. mode: _ui_utils.SpreadMode.NONE
  11249. },
  11250. close: true
  11251. }, {
  11252. element: options.spreadOddButton,
  11253. eventName: "switchspreadmode",
  11254. eventDetails: {
  11255. mode: _ui_utils.SpreadMode.ODD
  11256. },
  11257. close: true
  11258. }, {
  11259. element: options.spreadEvenButton,
  11260. eventName: "switchspreadmode",
  11261. eventDetails: {
  11262. mode: _ui_utils.SpreadMode.EVEN
  11263. },
  11264. close: true
  11265. }, {
  11266. element: options.documentPropertiesButton,
  11267. eventName: "documentproperties",
  11268. close: true
  11269. }];
  11270. this.buttons.push({
  11271. element: options.openFileButton,
  11272. eventName: "openfile",
  11273. close: true
  11274. });
  11275. this.items = {
  11276. firstPage: options.firstPageButton,
  11277. lastPage: options.lastPageButton,
  11278. pageRotateCw: options.pageRotateCwButton,
  11279. pageRotateCcw: options.pageRotateCcwButton
  11280. };
  11281. this.eventBus = eventBus;
  11282. this.externalServices = externalServices;
  11283. this.opened = false;
  11284. this.#bindClickListeners();
  11285. this.#bindCursorToolsListener(options);
  11286. this.#bindScrollModeListener(options);
  11287. this.#bindSpreadModeListener(options);
  11288. this.reset();
  11289. }
  11290. get isOpen() {
  11291. return this.opened;
  11292. }
  11293. setPageNumber(pageNumber) {
  11294. this.pageNumber = pageNumber;
  11295. this.#updateUIState();
  11296. }
  11297. setPagesCount(pagesCount) {
  11298. this.pagesCount = pagesCount;
  11299. this.#updateUIState();
  11300. }
  11301. reset() {
  11302. this.pageNumber = 0;
  11303. this.pagesCount = 0;
  11304. this.#updateUIState();
  11305. this.eventBus.dispatch("secondarytoolbarreset", {
  11306. source: this
  11307. });
  11308. }
  11309. #updateUIState() {
  11310. this.items.firstPage.disabled = this.pageNumber <= 1;
  11311. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  11312. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  11313. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  11314. }
  11315. #bindClickListeners() {
  11316. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  11317. for (const {
  11318. element,
  11319. eventName,
  11320. close,
  11321. eventDetails
  11322. } of this.buttons) {
  11323. element.addEventListener("click", evt => {
  11324. if (eventName !== null) {
  11325. const details = {
  11326. source: this
  11327. };
  11328. for (const property in eventDetails) {
  11329. details[property] = eventDetails[property];
  11330. }
  11331. this.eventBus.dispatch(eventName, details);
  11332. }
  11333. if (close) {
  11334. this.close();
  11335. }
  11336. this.externalServices.reportTelemetry({
  11337. type: "buttons",
  11338. data: {
  11339. id: element.id
  11340. }
  11341. });
  11342. });
  11343. }
  11344. }
  11345. #bindCursorToolsListener({
  11346. cursorSelectToolButton,
  11347. cursorHandToolButton
  11348. }) {
  11349. this.eventBus._on("cursortoolchanged", function ({
  11350. tool
  11351. }) {
  11352. const isSelect = tool === _pdf_cursor_tools.CursorTool.SELECT,
  11353. isHand = tool === _pdf_cursor_tools.CursorTool.HAND;
  11354. cursorSelectToolButton.classList.toggle("toggled", isSelect);
  11355. cursorHandToolButton.classList.toggle("toggled", isHand);
  11356. cursorSelectToolButton.setAttribute("aria-checked", isSelect);
  11357. cursorHandToolButton.setAttribute("aria-checked", isHand);
  11358. });
  11359. }
  11360. #bindScrollModeListener({
  11361. scrollPageButton,
  11362. scrollVerticalButton,
  11363. scrollHorizontalButton,
  11364. scrollWrappedButton,
  11365. spreadNoneButton,
  11366. spreadOddButton,
  11367. spreadEvenButton
  11368. }) {
  11369. const scrollModeChanged = ({
  11370. mode
  11371. }) => {
  11372. const isPage = mode === _ui_utils.ScrollMode.PAGE,
  11373. isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
  11374. isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
  11375. isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
  11376. scrollPageButton.classList.toggle("toggled", isPage);
  11377. scrollVerticalButton.classList.toggle("toggled", isVertical);
  11378. scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
  11379. scrollWrappedButton.classList.toggle("toggled", isWrapped);
  11380. scrollPageButton.setAttribute("aria-checked", isPage);
  11381. scrollVerticalButton.setAttribute("aria-checked", isVertical);
  11382. scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
  11383. scrollWrappedButton.setAttribute("aria-checked", isWrapped);
  11384. const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  11385. scrollPageButton.disabled = forceScrollModePage;
  11386. scrollVerticalButton.disabled = forceScrollModePage;
  11387. scrollHorizontalButton.disabled = forceScrollModePage;
  11388. scrollWrappedButton.disabled = forceScrollModePage;
  11389. spreadNoneButton.disabled = isHorizontal;
  11390. spreadOddButton.disabled = isHorizontal;
  11391. spreadEvenButton.disabled = isHorizontal;
  11392. };
  11393. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  11394. this.eventBus._on("secondarytoolbarreset", evt => {
  11395. if (evt.source === this) {
  11396. scrollModeChanged({
  11397. mode: _ui_utils.ScrollMode.VERTICAL
  11398. });
  11399. }
  11400. });
  11401. }
  11402. #bindSpreadModeListener({
  11403. spreadNoneButton,
  11404. spreadOddButton,
  11405. spreadEvenButton
  11406. }) {
  11407. function spreadModeChanged({
  11408. mode
  11409. }) {
  11410. const isNone = mode === _ui_utils.SpreadMode.NONE,
  11411. isOdd = mode === _ui_utils.SpreadMode.ODD,
  11412. isEven = mode === _ui_utils.SpreadMode.EVEN;
  11413. spreadNoneButton.classList.toggle("toggled", isNone);
  11414. spreadOddButton.classList.toggle("toggled", isOdd);
  11415. spreadEvenButton.classList.toggle("toggled", isEven);
  11416. spreadNoneButton.setAttribute("aria-checked", isNone);
  11417. spreadOddButton.setAttribute("aria-checked", isOdd);
  11418. spreadEvenButton.setAttribute("aria-checked", isEven);
  11419. }
  11420. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  11421. this.eventBus._on("secondarytoolbarreset", evt => {
  11422. if (evt.source === this) {
  11423. spreadModeChanged({
  11424. mode: _ui_utils.SpreadMode.NONE
  11425. });
  11426. }
  11427. });
  11428. }
  11429. open() {
  11430. if (this.opened) {
  11431. return;
  11432. }
  11433. this.opened = true;
  11434. this.toggleButton.classList.add("toggled");
  11435. this.toggleButton.setAttribute("aria-expanded", "true");
  11436. this.toolbar.classList.remove("hidden");
  11437. }
  11438. close() {
  11439. if (!this.opened) {
  11440. return;
  11441. }
  11442. this.opened = false;
  11443. this.toolbar.classList.add("hidden");
  11444. this.toggleButton.classList.remove("toggled");
  11445. this.toggleButton.setAttribute("aria-expanded", "false");
  11446. }
  11447. toggle() {
  11448. if (this.opened) {
  11449. this.close();
  11450. } else {
  11451. this.open();
  11452. }
  11453. }
  11454. }
  11455. exports.SecondaryToolbar = SecondaryToolbar;
  11456. /***/ }),
  11457. /* 39 */
  11458. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11459. Object.defineProperty(exports, "__esModule", ({
  11460. value: true
  11461. }));
  11462. exports.Toolbar = void 0;
  11463. var _ui_utils = __webpack_require__(1);
  11464. var _pdfjsLib = __webpack_require__(5);
  11465. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  11466. class Toolbar {
  11467. #wasLocalized = false;
  11468. constructor(options, eventBus, l10n) {
  11469. this.toolbar = options.container;
  11470. this.eventBus = eventBus;
  11471. this.l10n = l10n;
  11472. this.buttons = [{
  11473. element: options.previous,
  11474. eventName: "previouspage"
  11475. }, {
  11476. element: options.next,
  11477. eventName: "nextpage"
  11478. }, {
  11479. element: options.zoomIn,
  11480. eventName: "zoomin"
  11481. }, {
  11482. element: options.zoomOut,
  11483. eventName: "zoomout"
  11484. }, {
  11485. element: options.print,
  11486. eventName: "print"
  11487. }, {
  11488. element: options.download,
  11489. eventName: "download"
  11490. }, {
  11491. element: options.editorFreeTextButton,
  11492. eventName: "switchannotationeditormode",
  11493. eventDetails: {
  11494. get mode() {
  11495. const {
  11496. classList
  11497. } = options.editorFreeTextButton;
  11498. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
  11499. }
  11500. }
  11501. }, {
  11502. element: options.editorInkButton,
  11503. eventName: "switchannotationeditormode",
  11504. eventDetails: {
  11505. get mode() {
  11506. const {
  11507. classList
  11508. } = options.editorInkButton;
  11509. return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
  11510. }
  11511. }
  11512. }];
  11513. this.buttons.push({
  11514. element: options.openFile,
  11515. eventName: "openfile"
  11516. });
  11517. this.items = {
  11518. numPages: options.numPages,
  11519. pageNumber: options.pageNumber,
  11520. scaleSelect: options.scaleSelect,
  11521. customScaleOption: options.customScaleOption,
  11522. previous: options.previous,
  11523. next: options.next,
  11524. zoomIn: options.zoomIn,
  11525. zoomOut: options.zoomOut
  11526. };
  11527. this.#bindListeners(options);
  11528. this.reset();
  11529. }
  11530. setPageNumber(pageNumber, pageLabel) {
  11531. this.pageNumber = pageNumber;
  11532. this.pageLabel = pageLabel;
  11533. this.#updateUIState(false);
  11534. }
  11535. setPagesCount(pagesCount, hasPageLabels) {
  11536. this.pagesCount = pagesCount;
  11537. this.hasPageLabels = hasPageLabels;
  11538. this.#updateUIState(true);
  11539. }
  11540. setPageScale(pageScaleValue, pageScale) {
  11541. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  11542. this.pageScale = pageScale;
  11543. this.#updateUIState(false);
  11544. }
  11545. reset() {
  11546. this.pageNumber = 0;
  11547. this.pageLabel = null;
  11548. this.hasPageLabels = false;
  11549. this.pagesCount = 0;
  11550. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  11551. this.pageScale = _ui_utils.DEFAULT_SCALE;
  11552. this.#updateUIState(true);
  11553. this.updateLoadingIndicatorState();
  11554. this.eventBus.dispatch("toolbarreset", {
  11555. source: this
  11556. });
  11557. }
  11558. #bindListeners(options) {
  11559. const {
  11560. pageNumber,
  11561. scaleSelect
  11562. } = this.items;
  11563. const self = this;
  11564. for (const {
  11565. element,
  11566. eventName,
  11567. eventDetails
  11568. } of this.buttons) {
  11569. element.addEventListener("click", evt => {
  11570. if (eventName !== null) {
  11571. const details = {
  11572. source: this
  11573. };
  11574. if (eventDetails) {
  11575. for (const property in eventDetails) {
  11576. details[property] = eventDetails[property];
  11577. }
  11578. }
  11579. this.eventBus.dispatch(eventName, details);
  11580. }
  11581. });
  11582. }
  11583. pageNumber.addEventListener("click", function () {
  11584. this.select();
  11585. });
  11586. pageNumber.addEventListener("change", function () {
  11587. self.eventBus.dispatch("pagenumberchanged", {
  11588. source: self,
  11589. value: this.value
  11590. });
  11591. });
  11592. scaleSelect.addEventListener("change", function () {
  11593. if (this.value === "custom") {
  11594. return;
  11595. }
  11596. self.eventBus.dispatch("scalechanged", {
  11597. source: self,
  11598. value: this.value
  11599. });
  11600. });
  11601. scaleSelect.addEventListener("click", function (evt) {
  11602. const target = evt.target;
  11603. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  11604. this.blur();
  11605. }
  11606. });
  11607. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  11608. this.eventBus._on("localized", () => {
  11609. this.#wasLocalized = true;
  11610. this.#adjustScaleWidth();
  11611. this.#updateUIState(true);
  11612. });
  11613. this.#bindEditorToolsListener(options);
  11614. }
  11615. #bindEditorToolsListener({
  11616. editorFreeTextButton,
  11617. editorFreeTextParamsToolbar,
  11618. editorInkButton,
  11619. editorInkParamsToolbar
  11620. }) {
  11621. const editorModeChanged = (evt, disableButtons = false) => {
  11622. const editorButtons = [{
  11623. mode: _pdfjsLib.AnnotationEditorType.FREETEXT,
  11624. button: editorFreeTextButton,
  11625. toolbar: editorFreeTextParamsToolbar
  11626. }, {
  11627. mode: _pdfjsLib.AnnotationEditorType.INK,
  11628. button: editorInkButton,
  11629. toolbar: editorInkParamsToolbar
  11630. }];
  11631. for (const {
  11632. mode,
  11633. button,
  11634. toolbar
  11635. } of editorButtons) {
  11636. const checked = mode === evt.mode;
  11637. button.classList.toggle("toggled", checked);
  11638. button.setAttribute("aria-checked", checked);
  11639. button.disabled = disableButtons;
  11640. toolbar?.classList.toggle("hidden", !checked);
  11641. }
  11642. };
  11643. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  11644. this.eventBus._on("toolbarreset", evt => {
  11645. if (evt.source === this) {
  11646. editorModeChanged({
  11647. mode: _pdfjsLib.AnnotationEditorType.NONE
  11648. }, true);
  11649. }
  11650. });
  11651. }
  11652. #updateUIState(resetNumPages = false) {
  11653. if (!this.#wasLocalized) {
  11654. return;
  11655. }
  11656. const {
  11657. pageNumber,
  11658. pagesCount,
  11659. pageScaleValue,
  11660. pageScale,
  11661. items
  11662. } = this;
  11663. if (resetNumPages) {
  11664. if (this.hasPageLabels) {
  11665. items.pageNumber.type = "text";
  11666. } else {
  11667. items.pageNumber.type = "number";
  11668. this.l10n.get("of_pages", {
  11669. pagesCount
  11670. }).then(msg => {
  11671. items.numPages.textContent = msg;
  11672. });
  11673. }
  11674. items.pageNumber.max = pagesCount;
  11675. }
  11676. if (this.hasPageLabels) {
  11677. items.pageNumber.value = this.pageLabel;
  11678. this.l10n.get("page_of_pages", {
  11679. pageNumber,
  11680. pagesCount
  11681. }).then(msg => {
  11682. items.numPages.textContent = msg;
  11683. });
  11684. } else {
  11685. items.pageNumber.value = pageNumber;
  11686. }
  11687. items.previous.disabled = pageNumber <= 1;
  11688. items.next.disabled = pageNumber >= pagesCount;
  11689. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  11690. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  11691. this.l10n.get("page_scale_percent", {
  11692. scale: Math.round(pageScale * 10000) / 100
  11693. }).then(msg => {
  11694. let predefinedValueFound = false;
  11695. for (const option of items.scaleSelect.options) {
  11696. if (option.value !== pageScaleValue) {
  11697. option.selected = false;
  11698. continue;
  11699. }
  11700. option.selected = true;
  11701. predefinedValueFound = true;
  11702. }
  11703. if (!predefinedValueFound) {
  11704. items.customScaleOption.textContent = msg;
  11705. items.customScaleOption.selected = true;
  11706. }
  11707. });
  11708. }
  11709. updateLoadingIndicatorState(loading = false) {
  11710. const {
  11711. pageNumber
  11712. } = this.items;
  11713. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  11714. }
  11715. async #adjustScaleWidth() {
  11716. const {
  11717. items,
  11718. l10n
  11719. } = this;
  11720. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  11721. await _ui_utils.animationStarted;
  11722. const style = getComputedStyle(items.scaleSelect);
  11723. const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width"));
  11724. const canvas = document.createElement("canvas");
  11725. const ctx = canvas.getContext("2d", {
  11726. alpha: false
  11727. });
  11728. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  11729. let maxWidth = 0;
  11730. for (const predefinedValue of await predefinedValuesPromise) {
  11731. const {
  11732. width
  11733. } = ctx.measureText(predefinedValue);
  11734. if (width > maxWidth) {
  11735. maxWidth = width;
  11736. }
  11737. }
  11738. maxWidth += 0.3 * scaleSelectWidth;
  11739. if (maxWidth > scaleSelectWidth) {
  11740. _ui_utils.docStyle.setProperty("--scale-select-width", `${maxWidth}px`);
  11741. }
  11742. canvas.width = 0;
  11743. canvas.height = 0;
  11744. }
  11745. }
  11746. exports.Toolbar = Toolbar;
  11747. /***/ }),
  11748. /* 40 */
  11749. /***/ ((__unused_webpack_module, exports) => {
  11750. Object.defineProperty(exports, "__esModule", ({
  11751. value: true
  11752. }));
  11753. exports.ViewHistory = void 0;
  11754. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  11755. class ViewHistory {
  11756. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  11757. this.fingerprint = fingerprint;
  11758. this.cacheSize = cacheSize;
  11759. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  11760. const database = JSON.parse(databaseStr || "{}");
  11761. let index = -1;
  11762. if (!Array.isArray(database.files)) {
  11763. database.files = [];
  11764. } else {
  11765. while (database.files.length >= this.cacheSize) {
  11766. database.files.shift();
  11767. }
  11768. for (let i = 0, ii = database.files.length; i < ii; i++) {
  11769. const branch = database.files[i];
  11770. if (branch.fingerprint === this.fingerprint) {
  11771. index = i;
  11772. break;
  11773. }
  11774. }
  11775. }
  11776. if (index === -1) {
  11777. index = database.files.push({
  11778. fingerprint: this.fingerprint
  11779. }) - 1;
  11780. }
  11781. this.file = database.files[index];
  11782. this.database = database;
  11783. });
  11784. }
  11785. async _writeToStorage() {
  11786. const databaseStr = JSON.stringify(this.database);
  11787. localStorage.setItem("pdfjs.history", databaseStr);
  11788. }
  11789. async _readFromStorage() {
  11790. return localStorage.getItem("pdfjs.history");
  11791. }
  11792. async set(name, val) {
  11793. await this._initializedPromise;
  11794. this.file[name] = val;
  11795. return this._writeToStorage();
  11796. }
  11797. async setMultiple(properties) {
  11798. await this._initializedPromise;
  11799. for (const name in properties) {
  11800. this.file[name] = properties[name];
  11801. }
  11802. return this._writeToStorage();
  11803. }
  11804. async get(name, defaultValue) {
  11805. await this._initializedPromise;
  11806. const val = this.file[name];
  11807. return val !== undefined ? val : defaultValue;
  11808. }
  11809. async getMultiple(properties) {
  11810. await this._initializedPromise;
  11811. const values = Object.create(null);
  11812. for (const name in properties) {
  11813. const val = this.file[name];
  11814. values[name] = val !== undefined ? val : properties[name];
  11815. }
  11816. return values;
  11817. }
  11818. }
  11819. exports.ViewHistory = ViewHistory;
  11820. /***/ }),
  11821. /* 41 */
  11822. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11823. Object.defineProperty(exports, "__esModule", ({
  11824. value: true
  11825. }));
  11826. exports.GenericCom = void 0;
  11827. var _app = __webpack_require__(4);
  11828. var _preferences = __webpack_require__(42);
  11829. var _download_manager = __webpack_require__(43);
  11830. var _genericl10n = __webpack_require__(44);
  11831. var _generic_scripting = __webpack_require__(46);
  11832. ;
  11833. const GenericCom = {};
  11834. exports.GenericCom = GenericCom;
  11835. class GenericPreferences extends _preferences.BasePreferences {
  11836. async _writeToStorage(prefObj) {
  11837. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  11838. }
  11839. async _readFromStorage(prefObj) {
  11840. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  11841. }
  11842. }
  11843. class GenericExternalServices extends _app.DefaultExternalServices {
  11844. static createDownloadManager(options) {
  11845. return new _download_manager.DownloadManager();
  11846. }
  11847. static createPreferences() {
  11848. return new GenericPreferences();
  11849. }
  11850. static createL10n({
  11851. locale = "en-US"
  11852. }) {
  11853. return new _genericl10n.GenericL10n(locale);
  11854. }
  11855. static createScripting({
  11856. sandboxBundleSrc
  11857. }) {
  11858. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  11859. }
  11860. }
  11861. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  11862. /***/ }),
  11863. /* 42 */
  11864. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11865. Object.defineProperty(exports, "__esModule", ({
  11866. value: true
  11867. }));
  11868. exports.BasePreferences = void 0;
  11869. var _app_options = __webpack_require__(2);
  11870. class BasePreferences {
  11871. #defaults = Object.freeze({
  11872. "annotationEditorMode": 0,
  11873. "annotationMode": 2,
  11874. "cursorToolOnLoad": 0,
  11875. "defaultZoomValue": "",
  11876. "disablePageLabels": false,
  11877. "enablePermissions": false,
  11878. "enablePrintAutoRotate": true,
  11879. "enableScripting": true,
  11880. "externalLinkTarget": 0,
  11881. "historyUpdateUrl": false,
  11882. "ignoreDestinationZoom": false,
  11883. "forcePageColors": false,
  11884. "pageColorsBackground": "Canvas",
  11885. "pageColorsForeground": "CanvasText",
  11886. "pdfBugEnabled": false,
  11887. "sidebarViewOnLoad": -1,
  11888. "scrollModeOnLoad": -1,
  11889. "spreadModeOnLoad": -1,
  11890. "textLayerMode": 1,
  11891. "useOnlyCssZoom": false,
  11892. "viewerCssTheme": 0,
  11893. "viewOnLoad": 0,
  11894. "disableAutoFetch": false,
  11895. "disableFontFace": false,
  11896. "disableRange": false,
  11897. "disableStream": false,
  11898. "enableXfa": true,
  11899. "renderer": "canvas"
  11900. });
  11901. #prefs = Object.create(null);
  11902. #initializedPromise = null;
  11903. constructor() {
  11904. if (this.constructor === BasePreferences) {
  11905. throw new Error("Cannot initialize BasePreferences.");
  11906. }
  11907. this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
  11908. for (const name in this.#defaults) {
  11909. const prefValue = prefs?.[name];
  11910. if (typeof prefValue === typeof this.#defaults[name]) {
  11911. this.#prefs[name] = prefValue;
  11912. }
  11913. }
  11914. });
  11915. }
  11916. async _writeToStorage(prefObj) {
  11917. throw new Error("Not implemented: _writeToStorage");
  11918. }
  11919. async _readFromStorage(prefObj) {
  11920. throw new Error("Not implemented: _readFromStorage");
  11921. }
  11922. async reset() {
  11923. await this.#initializedPromise;
  11924. const prefs = this.#prefs;
  11925. this.#prefs = Object.create(null);
  11926. return this._writeToStorage(this.#defaults).catch(reason => {
  11927. this.#prefs = prefs;
  11928. throw reason;
  11929. });
  11930. }
  11931. async set(name, value) {
  11932. await this.#initializedPromise;
  11933. const defaultValue = this.#defaults[name],
  11934. prefs = this.#prefs;
  11935. if (defaultValue === undefined) {
  11936. throw new Error(`Set preference: "${name}" is undefined.`);
  11937. } else if (value === undefined) {
  11938. throw new Error("Set preference: no value is specified.");
  11939. }
  11940. const valueType = typeof value,
  11941. defaultType = typeof defaultValue;
  11942. if (valueType !== defaultType) {
  11943. if (valueType === "number" && defaultType === "string") {
  11944. value = value.toString();
  11945. } else {
  11946. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  11947. }
  11948. } else {
  11949. if (valueType === "number" && !Number.isInteger(value)) {
  11950. throw new Error(`Set preference: "${value}" must be an integer.`);
  11951. }
  11952. }
  11953. this.#prefs[name] = value;
  11954. return this._writeToStorage(this.#prefs).catch(reason => {
  11955. this.#prefs = prefs;
  11956. throw reason;
  11957. });
  11958. }
  11959. async get(name) {
  11960. await this.#initializedPromise;
  11961. const defaultValue = this.#defaults[name];
  11962. if (defaultValue === undefined) {
  11963. throw new Error(`Get preference: "${name}" is undefined.`);
  11964. }
  11965. return this.#prefs[name] ?? defaultValue;
  11966. }
  11967. async getAll() {
  11968. await this.#initializedPromise;
  11969. const obj = Object.create(null);
  11970. for (const name in this.#defaults) {
  11971. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  11972. }
  11973. return obj;
  11974. }
  11975. }
  11976. exports.BasePreferences = BasePreferences;
  11977. /***/ }),
  11978. /* 43 */
  11979. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11980. Object.defineProperty(exports, "__esModule", ({
  11981. value: true
  11982. }));
  11983. exports.DownloadManager = void 0;
  11984. var _pdfjsLib = __webpack_require__(5);
  11985. ;
  11986. function download(blobUrl, filename) {
  11987. const a = document.createElement("a");
  11988. if (!a.click) {
  11989. throw new Error('DownloadManager: "a.click()" is not supported.');
  11990. }
  11991. a.href = blobUrl;
  11992. a.target = "_parent";
  11993. if ("download" in a) {
  11994. a.download = filename;
  11995. }
  11996. (document.body || document.documentElement).append(a);
  11997. a.click();
  11998. a.remove();
  11999. }
  12000. class DownloadManager {
  12001. constructor() {
  12002. this._openBlobUrls = new WeakMap();
  12003. }
  12004. downloadUrl(url, filename) {
  12005. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  12006. console.error(`downloadUrl - not a valid URL: ${url}`);
  12007. return;
  12008. }
  12009. download(url + "#pdfjs.action=download", filename);
  12010. }
  12011. downloadData(data, filename, contentType) {
  12012. const blobUrl = URL.createObjectURL(new Blob([data], {
  12013. type: contentType
  12014. }));
  12015. download(blobUrl, filename);
  12016. }
  12017. openOrDownloadData(element, data, filename) {
  12018. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  12019. const contentType = isPdfData ? "application/pdf" : "";
  12020. if (isPdfData) {
  12021. let blobUrl = this._openBlobUrls.get(element);
  12022. if (!blobUrl) {
  12023. blobUrl = URL.createObjectURL(new Blob([data], {
  12024. type: contentType
  12025. }));
  12026. this._openBlobUrls.set(element, blobUrl);
  12027. }
  12028. let viewerUrl;
  12029. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  12030. try {
  12031. window.open(viewerUrl);
  12032. return true;
  12033. } catch (ex) {
  12034. console.error(`openOrDownloadData: ${ex}`);
  12035. URL.revokeObjectURL(blobUrl);
  12036. this._openBlobUrls.delete(element);
  12037. }
  12038. }
  12039. this.downloadData(data, filename, contentType);
  12040. return false;
  12041. }
  12042. download(blob, url, filename) {
  12043. const blobUrl = URL.createObjectURL(blob);
  12044. download(blobUrl, filename);
  12045. }
  12046. }
  12047. exports.DownloadManager = DownloadManager;
  12048. /***/ }),
  12049. /* 44 */
  12050. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12051. Object.defineProperty(exports, "__esModule", ({
  12052. value: true
  12053. }));
  12054. exports.GenericL10n = void 0;
  12055. __webpack_require__(45);
  12056. var _l10n_utils = __webpack_require__(30);
  12057. const webL10n = document.webL10n;
  12058. class GenericL10n {
  12059. constructor(lang) {
  12060. this._lang = lang;
  12061. this._ready = new Promise((resolve, reject) => {
  12062. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  12063. resolve(webL10n);
  12064. });
  12065. });
  12066. }
  12067. async getLanguage() {
  12068. const l10n = await this._ready;
  12069. return l10n.getLanguage();
  12070. }
  12071. async getDirection() {
  12072. const l10n = await this._ready;
  12073. return l10n.getDirection();
  12074. }
  12075. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  12076. const l10n = await this._ready;
  12077. return l10n.get(key, args, fallback);
  12078. }
  12079. async translate(element) {
  12080. const l10n = await this._ready;
  12081. return l10n.translate(element);
  12082. }
  12083. }
  12084. exports.GenericL10n = GenericL10n;
  12085. /***/ }),
  12086. /* 45 */
  12087. /***/ (() => {
  12088. document.webL10n = function (window, document, undefined) {
  12089. var gL10nData = {};
  12090. var gTextData = '';
  12091. var gTextProp = 'textContent';
  12092. var gLanguage = '';
  12093. var gMacros = {};
  12094. var gReadyState = 'loading';
  12095. var gAsyncResourceLoading = true;
  12096. function getL10nResourceLinks() {
  12097. return document.querySelectorAll('link[type="application/l10n"]');
  12098. }
  12099. function getL10nDictionary() {
  12100. var script = document.querySelector('script[type="application/l10n"]');
  12101. return script ? JSON.parse(script.innerHTML) : null;
  12102. }
  12103. function getTranslatableChildren(element) {
  12104. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  12105. }
  12106. function getL10nAttributes(element) {
  12107. if (!element) return {};
  12108. var l10nId = element.getAttribute('data-l10n-id');
  12109. var l10nArgs = element.getAttribute('data-l10n-args');
  12110. var args = {};
  12111. if (l10nArgs) {
  12112. try {
  12113. args = JSON.parse(l10nArgs);
  12114. } catch (e) {
  12115. console.warn('could not parse arguments for #' + l10nId);
  12116. }
  12117. }
  12118. return {
  12119. id: l10nId,
  12120. args: args
  12121. };
  12122. }
  12123. function xhrLoadText(url, onSuccess, onFailure) {
  12124. onSuccess = onSuccess || function _onSuccess(data) {};
  12125. onFailure = onFailure || function _onFailure() {};
  12126. var xhr = new XMLHttpRequest();
  12127. xhr.open('GET', url, gAsyncResourceLoading);
  12128. if (xhr.overrideMimeType) {
  12129. xhr.overrideMimeType('text/plain; charset=utf-8');
  12130. }
  12131. xhr.onreadystatechange = function () {
  12132. if (xhr.readyState == 4) {
  12133. if (xhr.status == 200 || xhr.status === 0) {
  12134. onSuccess(xhr.responseText);
  12135. } else {
  12136. onFailure();
  12137. }
  12138. }
  12139. };
  12140. xhr.onerror = onFailure;
  12141. xhr.ontimeout = onFailure;
  12142. try {
  12143. xhr.send(null);
  12144. } catch (e) {
  12145. onFailure();
  12146. }
  12147. }
  12148. function parseResource(href, lang, successCallback, failureCallback) {
  12149. var baseURL = href.replace(/[^\/]*$/, '') || './';
  12150. function evalString(text) {
  12151. if (text.lastIndexOf('\\') < 0) return text;
  12152. 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, "'");
  12153. }
  12154. function parseProperties(text, parsedPropertiesCallback) {
  12155. var dictionary = {};
  12156. var reBlank = /^\s*|\s*$/;
  12157. var reComment = /^\s*#|^\s*$/;
  12158. var reSection = /^\s*\[(.*)\]\s*$/;
  12159. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  12160. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  12161. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  12162. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  12163. var currentLang = '*';
  12164. var genericLang = lang.split('-', 1)[0];
  12165. var skipLang = false;
  12166. var match = '';
  12167. function nextEntry() {
  12168. while (true) {
  12169. if (!entries.length) {
  12170. parsedRawLinesCallback();
  12171. return;
  12172. }
  12173. var line = entries.shift();
  12174. if (reComment.test(line)) continue;
  12175. if (extendedSyntax) {
  12176. match = reSection.exec(line);
  12177. if (match) {
  12178. currentLang = match[1].toLowerCase();
  12179. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  12180. continue;
  12181. } else if (skipLang) {
  12182. continue;
  12183. }
  12184. match = reImport.exec(line);
  12185. if (match) {
  12186. loadImport(baseURL + match[1], nextEntry);
  12187. return;
  12188. }
  12189. }
  12190. var tmp = line.match(reSplit);
  12191. if (tmp && tmp.length == 3) {
  12192. dictionary[tmp[1]] = evalString(tmp[2]);
  12193. }
  12194. }
  12195. }
  12196. nextEntry();
  12197. }
  12198. function loadImport(url, callback) {
  12199. xhrLoadText(url, function (content) {
  12200. parseRawLines(content, false, callback);
  12201. }, function () {
  12202. console.warn(url + ' not found.');
  12203. callback();
  12204. });
  12205. }
  12206. parseRawLines(text, true, function () {
  12207. parsedPropertiesCallback(dictionary);
  12208. });
  12209. }
  12210. xhrLoadText(href, function (response) {
  12211. gTextData += response;
  12212. parseProperties(response, function (data) {
  12213. for (var key in data) {
  12214. var id,
  12215. prop,
  12216. index = key.lastIndexOf('.');
  12217. if (index > 0) {
  12218. id = key.substring(0, index);
  12219. prop = key.substring(index + 1);
  12220. } else {
  12221. id = key;
  12222. prop = gTextProp;
  12223. }
  12224. if (!gL10nData[id]) {
  12225. gL10nData[id] = {};
  12226. }
  12227. gL10nData[id][prop] = data[key];
  12228. }
  12229. if (successCallback) {
  12230. successCallback();
  12231. }
  12232. });
  12233. }, failureCallback);
  12234. }
  12235. function loadLocale(lang, callback) {
  12236. if (lang) {
  12237. lang = lang.toLowerCase();
  12238. }
  12239. callback = callback || function _callback() {};
  12240. clear();
  12241. gLanguage = lang;
  12242. var langLinks = getL10nResourceLinks();
  12243. var langCount = langLinks.length;
  12244. if (langCount === 0) {
  12245. var dict = getL10nDictionary();
  12246. if (dict && dict.locales && dict.default_locale) {
  12247. console.log('using the embedded JSON directory, early way out');
  12248. gL10nData = dict.locales[lang];
  12249. if (!gL10nData) {
  12250. var defaultLocale = dict.default_locale.toLowerCase();
  12251. for (var anyCaseLang in dict.locales) {
  12252. anyCaseLang = anyCaseLang.toLowerCase();
  12253. if (anyCaseLang === lang) {
  12254. gL10nData = dict.locales[lang];
  12255. break;
  12256. } else if (anyCaseLang === defaultLocale) {
  12257. gL10nData = dict.locales[defaultLocale];
  12258. }
  12259. }
  12260. }
  12261. callback();
  12262. } else {
  12263. console.log('no resource to load, early way out');
  12264. }
  12265. gReadyState = 'complete';
  12266. return;
  12267. }
  12268. var onResourceLoaded = null;
  12269. var gResourceCount = 0;
  12270. onResourceLoaded = function () {
  12271. gResourceCount++;
  12272. if (gResourceCount >= langCount) {
  12273. callback();
  12274. gReadyState = 'complete';
  12275. }
  12276. };
  12277. function L10nResourceLink(link) {
  12278. var href = link.href;
  12279. this.load = function (lang, callback) {
  12280. parseResource(href, lang, callback, function () {
  12281. console.warn(href + ' not found.');
  12282. console.warn('"' + lang + '" resource not found');
  12283. gLanguage = '';
  12284. callback();
  12285. });
  12286. };
  12287. }
  12288. for (var i = 0; i < langCount; i++) {
  12289. var resource = new L10nResourceLink(langLinks[i]);
  12290. resource.load(lang, onResourceLoaded);
  12291. }
  12292. }
  12293. function clear() {
  12294. gL10nData = {};
  12295. gTextData = '';
  12296. gLanguage = '';
  12297. }
  12298. function getPluralRules(lang) {
  12299. var locales2rules = {
  12300. 'af': 3,
  12301. 'ak': 4,
  12302. 'am': 4,
  12303. 'ar': 1,
  12304. 'asa': 3,
  12305. 'az': 0,
  12306. 'be': 11,
  12307. 'bem': 3,
  12308. 'bez': 3,
  12309. 'bg': 3,
  12310. 'bh': 4,
  12311. 'bm': 0,
  12312. 'bn': 3,
  12313. 'bo': 0,
  12314. 'br': 20,
  12315. 'brx': 3,
  12316. 'bs': 11,
  12317. 'ca': 3,
  12318. 'cgg': 3,
  12319. 'chr': 3,
  12320. 'cs': 12,
  12321. 'cy': 17,
  12322. 'da': 3,
  12323. 'de': 3,
  12324. 'dv': 3,
  12325. 'dz': 0,
  12326. 'ee': 3,
  12327. 'el': 3,
  12328. 'en': 3,
  12329. 'eo': 3,
  12330. 'es': 3,
  12331. 'et': 3,
  12332. 'eu': 3,
  12333. 'fa': 0,
  12334. 'ff': 5,
  12335. 'fi': 3,
  12336. 'fil': 4,
  12337. 'fo': 3,
  12338. 'fr': 5,
  12339. 'fur': 3,
  12340. 'fy': 3,
  12341. 'ga': 8,
  12342. 'gd': 24,
  12343. 'gl': 3,
  12344. 'gsw': 3,
  12345. 'gu': 3,
  12346. 'guw': 4,
  12347. 'gv': 23,
  12348. 'ha': 3,
  12349. 'haw': 3,
  12350. 'he': 2,
  12351. 'hi': 4,
  12352. 'hr': 11,
  12353. 'hu': 0,
  12354. 'id': 0,
  12355. 'ig': 0,
  12356. 'ii': 0,
  12357. 'is': 3,
  12358. 'it': 3,
  12359. 'iu': 7,
  12360. 'ja': 0,
  12361. 'jmc': 3,
  12362. 'jv': 0,
  12363. 'ka': 0,
  12364. 'kab': 5,
  12365. 'kaj': 3,
  12366. 'kcg': 3,
  12367. 'kde': 0,
  12368. 'kea': 0,
  12369. 'kk': 3,
  12370. 'kl': 3,
  12371. 'km': 0,
  12372. 'kn': 0,
  12373. 'ko': 0,
  12374. 'ksb': 3,
  12375. 'ksh': 21,
  12376. 'ku': 3,
  12377. 'kw': 7,
  12378. 'lag': 18,
  12379. 'lb': 3,
  12380. 'lg': 3,
  12381. 'ln': 4,
  12382. 'lo': 0,
  12383. 'lt': 10,
  12384. 'lv': 6,
  12385. 'mas': 3,
  12386. 'mg': 4,
  12387. 'mk': 16,
  12388. 'ml': 3,
  12389. 'mn': 3,
  12390. 'mo': 9,
  12391. 'mr': 3,
  12392. 'ms': 0,
  12393. 'mt': 15,
  12394. 'my': 0,
  12395. 'nah': 3,
  12396. 'naq': 7,
  12397. 'nb': 3,
  12398. 'nd': 3,
  12399. 'ne': 3,
  12400. 'nl': 3,
  12401. 'nn': 3,
  12402. 'no': 3,
  12403. 'nr': 3,
  12404. 'nso': 4,
  12405. 'ny': 3,
  12406. 'nyn': 3,
  12407. 'om': 3,
  12408. 'or': 3,
  12409. 'pa': 3,
  12410. 'pap': 3,
  12411. 'pl': 13,
  12412. 'ps': 3,
  12413. 'pt': 3,
  12414. 'rm': 3,
  12415. 'ro': 9,
  12416. 'rof': 3,
  12417. 'ru': 11,
  12418. 'rwk': 3,
  12419. 'sah': 0,
  12420. 'saq': 3,
  12421. 'se': 7,
  12422. 'seh': 3,
  12423. 'ses': 0,
  12424. 'sg': 0,
  12425. 'sh': 11,
  12426. 'shi': 19,
  12427. 'sk': 12,
  12428. 'sl': 14,
  12429. 'sma': 7,
  12430. 'smi': 7,
  12431. 'smj': 7,
  12432. 'smn': 7,
  12433. 'sms': 7,
  12434. 'sn': 3,
  12435. 'so': 3,
  12436. 'sq': 3,
  12437. 'sr': 11,
  12438. 'ss': 3,
  12439. 'ssy': 3,
  12440. 'st': 3,
  12441. 'sv': 3,
  12442. 'sw': 3,
  12443. 'syr': 3,
  12444. 'ta': 3,
  12445. 'te': 3,
  12446. 'teo': 3,
  12447. 'th': 0,
  12448. 'ti': 4,
  12449. 'tig': 3,
  12450. 'tk': 3,
  12451. 'tl': 4,
  12452. 'tn': 3,
  12453. 'to': 0,
  12454. 'tr': 0,
  12455. 'ts': 3,
  12456. 'tzm': 22,
  12457. 'uk': 11,
  12458. 'ur': 3,
  12459. 've': 3,
  12460. 'vi': 0,
  12461. 'vun': 3,
  12462. 'wa': 4,
  12463. 'wae': 3,
  12464. 'wo': 0,
  12465. 'xh': 3,
  12466. 'xog': 3,
  12467. 'yo': 0,
  12468. 'zh': 0,
  12469. 'zu': 3
  12470. };
  12471. function isIn(n, list) {
  12472. return list.indexOf(n) !== -1;
  12473. }
  12474. function isBetween(n, start, end) {
  12475. return start <= n && n <= end;
  12476. }
  12477. var pluralRules = {
  12478. '0': function (n) {
  12479. return 'other';
  12480. },
  12481. '1': function (n) {
  12482. if (isBetween(n % 100, 3, 10)) return 'few';
  12483. if (n === 0) return 'zero';
  12484. if (isBetween(n % 100, 11, 99)) return 'many';
  12485. if (n == 2) return 'two';
  12486. if (n == 1) return 'one';
  12487. return 'other';
  12488. },
  12489. '2': function (n) {
  12490. if (n !== 0 && n % 10 === 0) return 'many';
  12491. if (n == 2) return 'two';
  12492. if (n == 1) return 'one';
  12493. return 'other';
  12494. },
  12495. '3': function (n) {
  12496. if (n == 1) return 'one';
  12497. return 'other';
  12498. },
  12499. '4': function (n) {
  12500. if (isBetween(n, 0, 1)) return 'one';
  12501. return 'other';
  12502. },
  12503. '5': function (n) {
  12504. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12505. return 'other';
  12506. },
  12507. '6': function (n) {
  12508. if (n === 0) return 'zero';
  12509. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12510. return 'other';
  12511. },
  12512. '7': function (n) {
  12513. if (n == 2) return 'two';
  12514. if (n == 1) return 'one';
  12515. return 'other';
  12516. },
  12517. '8': function (n) {
  12518. if (isBetween(n, 3, 6)) return 'few';
  12519. if (isBetween(n, 7, 10)) return 'many';
  12520. if (n == 2) return 'two';
  12521. if (n == 1) return 'one';
  12522. return 'other';
  12523. },
  12524. '9': function (n) {
  12525. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12526. if (n == 1) return 'one';
  12527. return 'other';
  12528. },
  12529. '10': function (n) {
  12530. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12531. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12532. return 'other';
  12533. },
  12534. '11': function (n) {
  12535. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12536. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12537. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12538. return 'other';
  12539. },
  12540. '12': function (n) {
  12541. if (isBetween(n, 2, 4)) return 'few';
  12542. if (n == 1) return 'one';
  12543. return 'other';
  12544. },
  12545. '13': function (n) {
  12546. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12547. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12548. if (n == 1) return 'one';
  12549. return 'other';
  12550. },
  12551. '14': function (n) {
  12552. if (isBetween(n % 100, 3, 4)) return 'few';
  12553. if (n % 100 == 2) return 'two';
  12554. if (n % 100 == 1) return 'one';
  12555. return 'other';
  12556. },
  12557. '15': function (n) {
  12558. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12559. if (isBetween(n % 100, 11, 19)) return 'many';
  12560. if (n == 1) return 'one';
  12561. return 'other';
  12562. },
  12563. '16': function (n) {
  12564. if (n % 10 == 1 && n != 11) return 'one';
  12565. return 'other';
  12566. },
  12567. '17': function (n) {
  12568. if (n == 3) return 'few';
  12569. if (n === 0) return 'zero';
  12570. if (n == 6) return 'many';
  12571. if (n == 2) return 'two';
  12572. if (n == 1) return 'one';
  12573. return 'other';
  12574. },
  12575. '18': function (n) {
  12576. if (n === 0) return 'zero';
  12577. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12578. return 'other';
  12579. },
  12580. '19': function (n) {
  12581. if (isBetween(n, 2, 10)) return 'few';
  12582. if (isBetween(n, 0, 1)) return 'one';
  12583. return 'other';
  12584. },
  12585. '20': function (n) {
  12586. 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';
  12587. if (n % 1000000 === 0 && n !== 0) return 'many';
  12588. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12589. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12590. return 'other';
  12591. },
  12592. '21': function (n) {
  12593. if (n === 0) return 'zero';
  12594. if (n == 1) return 'one';
  12595. return 'other';
  12596. },
  12597. '22': function (n) {
  12598. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  12599. return 'other';
  12600. },
  12601. '23': function (n) {
  12602. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  12603. return 'other';
  12604. },
  12605. '24': function (n) {
  12606. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  12607. if (isIn(n, [2, 12])) return 'two';
  12608. if (isIn(n, [1, 11])) return 'one';
  12609. return 'other';
  12610. }
  12611. };
  12612. var index = locales2rules[lang.replace(/-.*$/, '')];
  12613. if (!(index in pluralRules)) {
  12614. console.warn('plural form unknown for [' + lang + ']');
  12615. return function () {
  12616. return 'other';
  12617. };
  12618. }
  12619. return pluralRules[index];
  12620. }
  12621. gMacros.plural = function (str, param, key, prop) {
  12622. var n = parseFloat(param);
  12623. if (isNaN(n)) return str;
  12624. if (prop != gTextProp) return str;
  12625. if (!gMacros._pluralRules) {
  12626. gMacros._pluralRules = getPluralRules(gLanguage);
  12627. }
  12628. var index = '[' + gMacros._pluralRules(n) + ']';
  12629. if (n === 0 && key + '[zero]' in gL10nData) {
  12630. str = gL10nData[key + '[zero]'][prop];
  12631. } else if (n == 1 && key + '[one]' in gL10nData) {
  12632. str = gL10nData[key + '[one]'][prop];
  12633. } else if (n == 2 && key + '[two]' in gL10nData) {
  12634. str = gL10nData[key + '[two]'][prop];
  12635. } else if (key + index in gL10nData) {
  12636. str = gL10nData[key + index][prop];
  12637. } else if (key + '[other]' in gL10nData) {
  12638. str = gL10nData[key + '[other]'][prop];
  12639. }
  12640. return str;
  12641. };
  12642. function getL10nData(key, args, fallback) {
  12643. var data = gL10nData[key];
  12644. if (!data) {
  12645. console.warn('#' + key + ' is undefined.');
  12646. if (!fallback) {
  12647. return null;
  12648. }
  12649. data = fallback;
  12650. }
  12651. var rv = {};
  12652. for (var prop in data) {
  12653. var str = data[prop];
  12654. str = substIndexes(str, args, key, prop);
  12655. str = substArguments(str, args, key);
  12656. rv[prop] = str;
  12657. }
  12658. return rv;
  12659. }
  12660. function substIndexes(str, args, key, prop) {
  12661. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  12662. var reMatch = reIndex.exec(str);
  12663. if (!reMatch || !reMatch.length) return str;
  12664. var macroName = reMatch[1];
  12665. var paramName = reMatch[2];
  12666. var param;
  12667. if (args && paramName in args) {
  12668. param = args[paramName];
  12669. } else if (paramName in gL10nData) {
  12670. param = gL10nData[paramName];
  12671. }
  12672. if (macroName in gMacros) {
  12673. var macro = gMacros[macroName];
  12674. str = macro(str, param, key, prop);
  12675. }
  12676. return str;
  12677. }
  12678. function substArguments(str, args, key) {
  12679. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  12680. return str.replace(reArgs, function (matched_text, arg) {
  12681. if (args && arg in args) {
  12682. return args[arg];
  12683. }
  12684. if (arg in gL10nData) {
  12685. return gL10nData[arg];
  12686. }
  12687. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  12688. return matched_text;
  12689. });
  12690. }
  12691. function translateElement(element) {
  12692. var l10n = getL10nAttributes(element);
  12693. if (!l10n.id) return;
  12694. var data = getL10nData(l10n.id, l10n.args);
  12695. if (!data) {
  12696. console.warn('#' + l10n.id + ' is undefined.');
  12697. return;
  12698. }
  12699. if (data[gTextProp]) {
  12700. if (getChildElementCount(element) === 0) {
  12701. element[gTextProp] = data[gTextProp];
  12702. } else {
  12703. var children = element.childNodes;
  12704. var found = false;
  12705. for (var i = 0, l = children.length; i < l; i++) {
  12706. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  12707. if (found) {
  12708. children[i].nodeValue = '';
  12709. } else {
  12710. children[i].nodeValue = data[gTextProp];
  12711. found = true;
  12712. }
  12713. }
  12714. }
  12715. if (!found) {
  12716. var textNode = document.createTextNode(data[gTextProp]);
  12717. element.prepend(textNode);
  12718. }
  12719. }
  12720. delete data[gTextProp];
  12721. }
  12722. for (var k in data) {
  12723. element[k] = data[k];
  12724. }
  12725. }
  12726. function getChildElementCount(element) {
  12727. if (element.children) {
  12728. return element.children.length;
  12729. }
  12730. if (typeof element.childElementCount !== 'undefined') {
  12731. return element.childElementCount;
  12732. }
  12733. var count = 0;
  12734. for (var i = 0; i < element.childNodes.length; i++) {
  12735. count += element.nodeType === 1 ? 1 : 0;
  12736. }
  12737. return count;
  12738. }
  12739. function translateFragment(element) {
  12740. element = element || document.documentElement;
  12741. var children = getTranslatableChildren(element);
  12742. var elementCount = children.length;
  12743. for (var i = 0; i < elementCount; i++) {
  12744. translateElement(children[i]);
  12745. }
  12746. translateElement(element);
  12747. }
  12748. return {
  12749. get: function (key, args, fallbackString) {
  12750. var index = key.lastIndexOf('.');
  12751. var prop = gTextProp;
  12752. if (index > 0) {
  12753. prop = key.substring(index + 1);
  12754. key = key.substring(0, index);
  12755. }
  12756. var fallback;
  12757. if (fallbackString) {
  12758. fallback = {};
  12759. fallback[prop] = fallbackString;
  12760. }
  12761. var data = getL10nData(key, args, fallback);
  12762. if (data && prop in data) {
  12763. return data[prop];
  12764. }
  12765. return '{{' + key + '}}';
  12766. },
  12767. getData: function () {
  12768. return gL10nData;
  12769. },
  12770. getText: function () {
  12771. return gTextData;
  12772. },
  12773. getLanguage: function () {
  12774. return gLanguage;
  12775. },
  12776. setLanguage: function (lang, callback) {
  12777. loadLocale(lang, function () {
  12778. if (callback) callback();
  12779. });
  12780. },
  12781. getDirection: function () {
  12782. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  12783. var shortCode = gLanguage.split('-', 1)[0];
  12784. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  12785. },
  12786. translate: translateFragment,
  12787. getReadyState: function () {
  12788. return gReadyState;
  12789. },
  12790. ready: function (callback) {
  12791. if (!callback) {
  12792. return;
  12793. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  12794. window.setTimeout(function () {
  12795. callback();
  12796. });
  12797. } else if (document.addEventListener) {
  12798. document.addEventListener('localized', function once() {
  12799. document.removeEventListener('localized', once);
  12800. callback();
  12801. });
  12802. }
  12803. }
  12804. };
  12805. }(window, document);
  12806. /***/ }),
  12807. /* 46 */
  12808. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12809. Object.defineProperty(exports, "__esModule", ({
  12810. value: true
  12811. }));
  12812. exports.GenericScripting = void 0;
  12813. exports.docPropertiesLookup = docPropertiesLookup;
  12814. var _pdfjsLib = __webpack_require__(5);
  12815. async function docPropertiesLookup(pdfDocument) {
  12816. const url = "",
  12817. baseUrl = url.split("#")[0];
  12818. let {
  12819. info,
  12820. metadata,
  12821. contentDispositionFilename,
  12822. contentLength
  12823. } = await pdfDocument.getMetadata();
  12824. if (!contentLength) {
  12825. const {
  12826. length
  12827. } = await pdfDocument.getDownloadInfo();
  12828. contentLength = length;
  12829. }
  12830. return {
  12831. ...info,
  12832. baseURL: baseUrl,
  12833. filesize: contentLength,
  12834. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  12835. metadata: metadata?.getRaw(),
  12836. authors: metadata?.get("dc:creator"),
  12837. numPages: pdfDocument.numPages,
  12838. URL: url
  12839. };
  12840. }
  12841. class GenericScripting {
  12842. constructor(sandboxBundleSrc) {
  12843. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  12844. return window.pdfjsSandbox.QuickJSSandbox();
  12845. });
  12846. }
  12847. async createSandbox(data) {
  12848. const sandbox = await this._ready;
  12849. sandbox.create(data);
  12850. }
  12851. async dispatchEventInSandbox(event) {
  12852. const sandbox = await this._ready;
  12853. setTimeout(() => sandbox.dispatchEvent(event), 0);
  12854. }
  12855. async destroySandbox() {
  12856. const sandbox = await this._ready;
  12857. sandbox.nukeSandbox();
  12858. }
  12859. }
  12860. exports.GenericScripting = GenericScripting;
  12861. /***/ }),
  12862. /* 47 */
  12863. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12864. Object.defineProperty(exports, "__esModule", ({
  12865. value: true
  12866. }));
  12867. exports.PDFPrintService = PDFPrintService;
  12868. var _pdfjsLib = __webpack_require__(5);
  12869. var _app = __webpack_require__(4);
  12870. var _print_utils = __webpack_require__(48);
  12871. let activeService = null;
  12872. let dialog = null;
  12873. let overlayManager = null;
  12874. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
  12875. const scratchCanvas = activeService.scratchCanvas;
  12876. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  12877. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  12878. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  12879. const ctx = scratchCanvas.getContext("2d");
  12880. ctx.save();
  12881. ctx.fillStyle = "rgb(255, 255, 255)";
  12882. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  12883. ctx.restore();
  12884. return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
  12885. const renderContext = {
  12886. canvasContext: ctx,
  12887. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  12888. viewport: pdfPage.getViewport({
  12889. scale: 1,
  12890. rotation: size.rotation
  12891. }),
  12892. intent: "print",
  12893. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  12894. optionalContentConfigPromise,
  12895. printAnnotationStorage
  12896. };
  12897. return pdfPage.render(renderContext).promise;
  12898. });
  12899. }
  12900. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n) {
  12901. this.pdfDocument = pdfDocument;
  12902. this.pagesOverview = pagesOverview;
  12903. this.printContainer = printContainer;
  12904. this._printResolution = printResolution || 150;
  12905. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  12906. this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
  12907. this.l10n = l10n;
  12908. this.currentPage = -1;
  12909. this.scratchCanvas = document.createElement("canvas");
  12910. }
  12911. PDFPrintService.prototype = {
  12912. layout() {
  12913. this.throwIfInactive();
  12914. const body = document.querySelector("body");
  12915. body.setAttribute("data-pdfjsprinting", true);
  12916. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  12917. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  12918. }, this);
  12919. if (!hasEqualPageSizes) {
  12920. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  12921. }
  12922. this.pageStyleSheet = document.createElement("style");
  12923. const pageSize = this.pagesOverview[0];
  12924. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  12925. body.append(this.pageStyleSheet);
  12926. },
  12927. destroy() {
  12928. if (activeService !== this) {
  12929. return;
  12930. }
  12931. this.printContainer.textContent = "";
  12932. const body = document.querySelector("body");
  12933. body.removeAttribute("data-pdfjsprinting");
  12934. if (this.pageStyleSheet) {
  12935. this.pageStyleSheet.remove();
  12936. this.pageStyleSheet = null;
  12937. }
  12938. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  12939. this.scratchCanvas = null;
  12940. activeService = null;
  12941. ensureOverlay().then(function () {
  12942. if (overlayManager.active === dialog) {
  12943. overlayManager.close(dialog);
  12944. }
  12945. });
  12946. },
  12947. renderPages() {
  12948. if (this.pdfDocument.isPureXfa) {
  12949. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  12950. return Promise.resolve();
  12951. }
  12952. const pageCount = this.pagesOverview.length;
  12953. const renderNextPage = (resolve, reject) => {
  12954. this.throwIfInactive();
  12955. if (++this.currentPage >= pageCount) {
  12956. renderProgress(pageCount, pageCount, this.l10n);
  12957. resolve();
  12958. return;
  12959. }
  12960. const index = this.currentPage;
  12961. renderProgress(index, pageCount, this.l10n);
  12962. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
  12963. renderNextPage(resolve, reject);
  12964. }, reject);
  12965. };
  12966. return new Promise(renderNextPage);
  12967. },
  12968. useRenderedPage() {
  12969. this.throwIfInactive();
  12970. const img = document.createElement("img");
  12971. const scratchCanvas = this.scratchCanvas;
  12972. if ("toBlob" in scratchCanvas) {
  12973. scratchCanvas.toBlob(function (blob) {
  12974. img.src = URL.createObjectURL(blob);
  12975. });
  12976. } else {
  12977. img.src = scratchCanvas.toDataURL();
  12978. }
  12979. const wrapper = document.createElement("div");
  12980. wrapper.className = "printedPage";
  12981. wrapper.append(img);
  12982. this.printContainer.append(wrapper);
  12983. return new Promise(function (resolve, reject) {
  12984. img.onload = resolve;
  12985. img.onerror = reject;
  12986. });
  12987. },
  12988. performPrint() {
  12989. this.throwIfInactive();
  12990. return new Promise(resolve => {
  12991. setTimeout(() => {
  12992. if (!this.active) {
  12993. resolve();
  12994. return;
  12995. }
  12996. print.call(window);
  12997. setTimeout(resolve, 20);
  12998. }, 0);
  12999. });
  13000. },
  13001. get active() {
  13002. return this === activeService;
  13003. },
  13004. throwIfInactive() {
  13005. if (!this.active) {
  13006. throw new Error("This print request was cancelled or completed.");
  13007. }
  13008. }
  13009. };
  13010. const print = window.print;
  13011. window.print = function () {
  13012. if (activeService) {
  13013. console.warn("Ignored window.print() because of a pending print job.");
  13014. return;
  13015. }
  13016. ensureOverlay().then(function () {
  13017. if (activeService) {
  13018. overlayManager.open(dialog);
  13019. }
  13020. });
  13021. try {
  13022. dispatchEvent("beforeprint");
  13023. } finally {
  13024. if (!activeService) {
  13025. console.error("Expected print service to be initialized.");
  13026. ensureOverlay().then(function () {
  13027. if (overlayManager.active === dialog) {
  13028. overlayManager.close(dialog);
  13029. }
  13030. });
  13031. return;
  13032. }
  13033. const activeServiceOnEntry = activeService;
  13034. activeService.renderPages().then(function () {
  13035. return activeServiceOnEntry.performPrint();
  13036. }).catch(function () {}).then(function () {
  13037. if (activeServiceOnEntry.active) {
  13038. abort();
  13039. }
  13040. });
  13041. }
  13042. };
  13043. function dispatchEvent(eventType) {
  13044. const event = document.createEvent("CustomEvent");
  13045. event.initCustomEvent(eventType, false, false, "custom");
  13046. window.dispatchEvent(event);
  13047. }
  13048. function abort() {
  13049. if (activeService) {
  13050. activeService.destroy();
  13051. dispatchEvent("afterprint");
  13052. }
  13053. }
  13054. function renderProgress(index, total, l10n) {
  13055. dialog ||= document.getElementById("printServiceDialog");
  13056. const progress = Math.round(100 * index / total);
  13057. const progressBar = dialog.querySelector("progress");
  13058. const progressPerc = dialog.querySelector(".relative-progress");
  13059. progressBar.value = progress;
  13060. l10n.get("print_progress_percent", {
  13061. progress
  13062. }).then(msg => {
  13063. progressPerc.textContent = msg;
  13064. });
  13065. }
  13066. window.addEventListener("keydown", function (event) {
  13067. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  13068. window.print();
  13069. event.preventDefault();
  13070. event.stopImmediatePropagation();
  13071. }
  13072. }, true);
  13073. if ("onbeforeprint" in window) {
  13074. const stopPropagationIfNeeded = function (event) {
  13075. if (event.detail !== "custom") {
  13076. event.stopImmediatePropagation();
  13077. }
  13078. };
  13079. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  13080. window.addEventListener("afterprint", stopPropagationIfNeeded);
  13081. }
  13082. let overlayPromise;
  13083. function ensureOverlay() {
  13084. if (!overlayPromise) {
  13085. overlayManager = _app.PDFViewerApplication.overlayManager;
  13086. if (!overlayManager) {
  13087. throw new Error("The overlay manager has not yet been initialized.");
  13088. }
  13089. dialog ||= document.getElementById("printServiceDialog");
  13090. overlayPromise = overlayManager.register(dialog, true);
  13091. document.getElementById("printCancel").onclick = abort;
  13092. dialog.addEventListener("close", abort);
  13093. }
  13094. return overlayPromise;
  13095. }
  13096. _app.PDFPrintServiceFactory.instance = {
  13097. supportsPrinting: true,
  13098. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n) {
  13099. if (activeService) {
  13100. throw new Error("The print service is created and active.");
  13101. }
  13102. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n);
  13103. return activeService;
  13104. }
  13105. };
  13106. /***/ }),
  13107. /* 48 */
  13108. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  13109. Object.defineProperty(exports, "__esModule", ({
  13110. value: true
  13111. }));
  13112. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  13113. var _pdfjsLib = __webpack_require__(5);
  13114. var _pdf_link_service = __webpack_require__(3);
  13115. var _xfa_layer_builder = __webpack_require__(37);
  13116. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  13117. const xfaHtml = pdfDocument.allXfaHtml;
  13118. const linkService = new _pdf_link_service.SimpleLinkService();
  13119. const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  13120. for (const xfaPage of xfaHtml.children) {
  13121. const page = document.createElement("div");
  13122. page.className = "xfaPrintedPage";
  13123. printContainer.append(page);
  13124. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  13125. pageDiv: page,
  13126. pdfPage: null,
  13127. annotationStorage: pdfDocument.annotationStorage,
  13128. linkService,
  13129. xfaHtml: xfaPage
  13130. });
  13131. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  13132. scale
  13133. });
  13134. builder.render(viewport, "print");
  13135. }
  13136. }
  13137. /***/ })
  13138. /******/ ]);
  13139. /************************************************************************/
  13140. /******/ // The module cache
  13141. /******/ var __webpack_module_cache__ = {};
  13142. /******/
  13143. /******/ // The require function
  13144. /******/ function __webpack_require__(moduleId) {
  13145. /******/ // Check if module is in cache
  13146. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  13147. /******/ if (cachedModule !== undefined) {
  13148. /******/ return cachedModule.exports;
  13149. /******/ }
  13150. /******/ // Create a new module (and put it into the cache)
  13151. /******/ var module = __webpack_module_cache__[moduleId] = {
  13152. /******/ // no module.id needed
  13153. /******/ // no module.loaded needed
  13154. /******/ exports: {}
  13155. /******/ };
  13156. /******/
  13157. /******/ // Execute the module function
  13158. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  13159. /******/
  13160. /******/ // Return the exports of the module
  13161. /******/ return module.exports;
  13162. /******/ }
  13163. /******/
  13164. /************************************************************************/
  13165. var __webpack_exports__ = {};
  13166. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  13167. (() => {
  13168. var exports = __webpack_exports__;
  13169. Object.defineProperty(exports, "__esModule", ({
  13170. value: true
  13171. }));
  13172. Object.defineProperty(exports, "PDFViewerApplication", ({
  13173. enumerable: true,
  13174. get: function () {
  13175. return _app.PDFViewerApplication;
  13176. }
  13177. }));
  13178. exports.PDFViewerApplicationConstants = void 0;
  13179. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  13180. enumerable: true,
  13181. get: function () {
  13182. return _app_options.AppOptions;
  13183. }
  13184. }));
  13185. var _ui_utils = __webpack_require__(1);
  13186. var _app_options = __webpack_require__(2);
  13187. var _pdf_link_service = __webpack_require__(3);
  13188. var _app = __webpack_require__(4);
  13189. const pdfjsVersion = '3.0.279';
  13190. const pdfjsBuild = 'd0823066c';
  13191. const AppConstants = {
  13192. LinkTarget: _pdf_link_service.LinkTarget,
  13193. RenderingStates: _ui_utils.RenderingStates,
  13194. ScrollMode: _ui_utils.ScrollMode,
  13195. SpreadMode: _ui_utils.SpreadMode
  13196. };
  13197. exports.PDFViewerApplicationConstants = AppConstants;
  13198. window.PDFViewerApplication = _app.PDFViewerApplication;
  13199. window.PDFViewerApplicationConstants = AppConstants;
  13200. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  13201. ;
  13202. ;
  13203. {
  13204. __webpack_require__(41);
  13205. }
  13206. ;
  13207. {
  13208. __webpack_require__(47);
  13209. }
  13210. function getViewerConfiguration() {
  13211. return {
  13212. appContainer: document.body,
  13213. mainContainer: document.getElementById("viewerContainer"),
  13214. viewerContainer: document.getElementById("viewer"),
  13215. toolbar: {
  13216. container: document.getElementById("toolbarViewer"),
  13217. numPages: document.getElementById("numPages"),
  13218. pageNumber: document.getElementById("pageNumber"),
  13219. scaleSelect: document.getElementById("scaleSelect"),
  13220. customScaleOption: document.getElementById("customScaleOption"),
  13221. previous: document.getElementById("previous"),
  13222. next: document.getElementById("next"),
  13223. zoomIn: document.getElementById("zoomIn"),
  13224. zoomOut: document.getElementById("zoomOut"),
  13225. viewFind: document.getElementById("viewFind"),
  13226. openFile: document.getElementById("openFile"),
  13227. print: document.getElementById("print"),
  13228. editorFreeTextButton: document.getElementById("editorFreeText"),
  13229. editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
  13230. editorInkButton: document.getElementById("editorInk"),
  13231. editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
  13232. download: document.getElementById("download")
  13233. },
  13234. secondaryToolbar: {
  13235. toolbar: document.getElementById("secondaryToolbar"),
  13236. toggleButton: document.getElementById("secondaryToolbarToggle"),
  13237. presentationModeButton: document.getElementById("presentationMode"),
  13238. openFileButton: document.getElementById("secondaryOpenFile"),
  13239. printButton: document.getElementById("secondaryPrint"),
  13240. downloadButton: document.getElementById("secondaryDownload"),
  13241. viewBookmarkButton: document.getElementById("viewBookmark"),
  13242. firstPageButton: document.getElementById("firstPage"),
  13243. lastPageButton: document.getElementById("lastPage"),
  13244. pageRotateCwButton: document.getElementById("pageRotateCw"),
  13245. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  13246. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  13247. cursorHandToolButton: document.getElementById("cursorHandTool"),
  13248. scrollPageButton: document.getElementById("scrollPage"),
  13249. scrollVerticalButton: document.getElementById("scrollVertical"),
  13250. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  13251. scrollWrappedButton: document.getElementById("scrollWrapped"),
  13252. spreadNoneButton: document.getElementById("spreadNone"),
  13253. spreadOddButton: document.getElementById("spreadOdd"),
  13254. spreadEvenButton: document.getElementById("spreadEven"),
  13255. documentPropertiesButton: document.getElementById("documentProperties")
  13256. },
  13257. sidebar: {
  13258. outerContainer: document.getElementById("outerContainer"),
  13259. sidebarContainer: document.getElementById("sidebarContainer"),
  13260. toggleButton: document.getElementById("sidebarToggle"),
  13261. thumbnailButton: document.getElementById("viewThumbnail"),
  13262. outlineButton: document.getElementById("viewOutline"),
  13263. attachmentsButton: document.getElementById("viewAttachments"),
  13264. layersButton: document.getElementById("viewLayers"),
  13265. thumbnailView: document.getElementById("thumbnailView"),
  13266. outlineView: document.getElementById("outlineView"),
  13267. attachmentsView: document.getElementById("attachmentsView"),
  13268. layersView: document.getElementById("layersView"),
  13269. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  13270. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  13271. },
  13272. sidebarResizer: {
  13273. outerContainer: document.getElementById("outerContainer"),
  13274. resizer: document.getElementById("sidebarResizer")
  13275. },
  13276. findBar: {
  13277. bar: document.getElementById("findbar"),
  13278. toggleButton: document.getElementById("viewFind"),
  13279. findField: document.getElementById("findInput"),
  13280. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  13281. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  13282. matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
  13283. entireWordCheckbox: document.getElementById("findEntireWord"),
  13284. findMsg: document.getElementById("findMsg"),
  13285. findResultsCount: document.getElementById("findResultsCount"),
  13286. findPreviousButton: document.getElementById("findPrevious"),
  13287. findNextButton: document.getElementById("findNext")
  13288. },
  13289. passwordOverlay: {
  13290. dialog: document.getElementById("passwordDialog"),
  13291. label: document.getElementById("passwordText"),
  13292. input: document.getElementById("password"),
  13293. submitButton: document.getElementById("passwordSubmit"),
  13294. cancelButton: document.getElementById("passwordCancel")
  13295. },
  13296. documentProperties: {
  13297. dialog: document.getElementById("documentPropertiesDialog"),
  13298. closeButton: document.getElementById("documentPropertiesClose"),
  13299. fields: {
  13300. fileName: document.getElementById("fileNameField"),
  13301. fileSize: document.getElementById("fileSizeField"),
  13302. title: document.getElementById("titleField"),
  13303. author: document.getElementById("authorField"),
  13304. subject: document.getElementById("subjectField"),
  13305. keywords: document.getElementById("keywordsField"),
  13306. creationDate: document.getElementById("creationDateField"),
  13307. modificationDate: document.getElementById("modificationDateField"),
  13308. creator: document.getElementById("creatorField"),
  13309. producer: document.getElementById("producerField"),
  13310. version: document.getElementById("versionField"),
  13311. pageCount: document.getElementById("pageCountField"),
  13312. pageSize: document.getElementById("pageSizeField"),
  13313. linearized: document.getElementById("linearizedField")
  13314. }
  13315. },
  13316. annotationEditorParams: {
  13317. editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
  13318. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  13319. editorInkColor: document.getElementById("editorInkColor"),
  13320. editorInkThickness: document.getElementById("editorInkThickness"),
  13321. editorInkOpacity: document.getElementById("editorInkOpacity")
  13322. },
  13323. printContainer: document.getElementById("printContainer"),
  13324. openFileInput: document.getElementById("fileInput"),
  13325. debuggerScriptPath: "./debugger.js"
  13326. };
  13327. }
  13328. function webViewerLoad() {
  13329. const config = getViewerConfiguration();
  13330. const event = document.createEvent("CustomEvent");
  13331. event.initCustomEvent("webviewerloaded", true, true, {
  13332. source: window
  13333. });
  13334. try {
  13335. parent.document.dispatchEvent(event);
  13336. } catch (ex) {
  13337. console.error(`webviewerloaded: ${ex}`);
  13338. document.dispatchEvent(event);
  13339. }
  13340. _app.PDFViewerApplication.run(config);
  13341. }
  13342. document.blockUnblockOnload?.(true);
  13343. if (document.readyState === "interactive" || document.readyState === "complete") {
  13344. webViewerLoad();
  13345. } else {
  13346. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  13347. }
  13348. })();
  13349. /******/ })()
  13350. ;
  13351. //# sourceMappingURL=viewer.js.map